From 85e86900d0b031713b37df45148c8d12467d0fa3 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 2 Dec 2024 16:14:28 +0000 Subject: [PATCH] Type licensing endpoints --- .../builder/portal/account/upgrade.svelte | 4 +-- .../src/api/{licensing.js => licensing.ts} | 36 +++++++++++++++---- packages/frontend-core/src/api/types.ts | 4 ++- 3 files changed, 35 insertions(+), 9 deletions(-) rename packages/frontend-core/src/api/{licensing.js => licensing.ts} (53%) diff --git a/packages/builder/src/pages/builder/portal/account/upgrade.svelte b/packages/builder/src/pages/builder/portal/account/upgrade.svelte index dbdedb6805..98af01ccf6 100644 --- a/packages/builder/src/pages/builder/portal/account/upgrade.svelte +++ b/packages/builder/src/pages/builder/portal/account/upgrade.svelte @@ -64,7 +64,7 @@ const activateLicenseKey = async () => { try { - await API.activateLicenseKey({ licenseKey }) + await API.activateLicenseKey(licenseKey) await auth.getSelf() await getLicenseKey() notifications.success("Successfully activated") @@ -119,7 +119,7 @@ async function activateOfflineLicense(offlineLicenseToken) { try { - await API.activateOfflineLicense({ offlineLicenseToken }) + await API.activateOfflineLicense(offlineLicenseToken) await auth.getSelf() await getOfflineLicense() notifications.success("Successfully activated") diff --git a/packages/frontend-core/src/api/licensing.js b/packages/frontend-core/src/api/licensing.ts similarity index 53% rename from packages/frontend-core/src/api/licensing.js rename to packages/frontend-core/src/api/licensing.ts index 987fc34cf5..fb87335cc5 100644 --- a/packages/frontend-core/src/api/licensing.js +++ b/packages/frontend-core/src/api/licensing.ts @@ -1,10 +1,34 @@ -export const buildLicensingEndpoints = API => ({ +import { + ActivateLicenseKeyRequest, + ActivateOfflineLicenseTokenRequest, + GetLicenseKeyResponse, + GetOfflineIdentifierResponse, + GetOfflineLicenseTokenResponse, + QuotaUsage, +} from "@budibase/types" +import { BaseAPIClient } from "./types" + +export interface LicensingEndpoints { + activateLicenseKey: (licenseKey: string) => Promise + deleteLicenseKey: () => Promise + getLicenseKey: () => Promise + activateOfflineLicense: (offlineLicenseToken: string) => Promise + deleteOfflineLicense: () => Promise + getOfflineLicense: () => Promise + getOfflineLicenseIdentifier: () => Promise + refreshLicense: () => Promise + getQuotaUsage: () => Promise +} + +export const buildLicensingEndpoints = ( + API: BaseAPIClient +): LicensingEndpoints => ({ // LICENSE KEY - activateLicenseKey: async data => { - return API.post({ + activateLicenseKey: async licenseKey => { + return API.post({ url: `/api/global/license/key`, - body: data, + body: { licenseKey }, }) }, deleteLicenseKey: async () => { @@ -26,8 +50,8 @@ export const buildLicensingEndpoints = API => ({ // OFFLINE LICENSE - activateOfflineLicense: async ({ offlineLicenseToken }) => { - return API.post({ + activateOfflineLicense: async offlineLicenseToken => { + return API.post({ url: "/api/global/license/offline", body: { offlineLicenseToken, diff --git a/packages/frontend-core/src/api/types.ts b/packages/frontend-core/src/api/types.ts index 73f445376d..030b969bd0 100644 --- a/packages/frontend-core/src/api/types.ts +++ b/packages/frontend-core/src/api/types.ts @@ -13,6 +13,7 @@ import { EventEndpoints } from "./events" import { FlagEndpoints } from "./flags" import { GroupEndpoints } from "./groups" import { LayoutEndpoints } from "./layouts" +import { LicensingEndpoints } from "./licensing" export enum HTTPMethod { POST = "POST", @@ -87,4 +88,5 @@ export type APIClient = BaseAPIClient & EventEndpoints & FlagEndpoints & GroupEndpoints & - LayoutEndpoints + LayoutEndpoints & + LicensingEndpoints