diff --git a/packages/server/modules/gatekeeper/domain/types.ts b/packages/server/modules/gatekeeper/domain/types.ts index 82250cd59..044c63c11 100644 --- a/packages/server/modules/gatekeeper/domain/types.ts +++ b/packages/server/modules/gatekeeper/domain/types.ts @@ -1,9 +1,12 @@ import { z } from 'zod' -const EnabledModules = z.object({ - workspaces: z.boolean(), - gatekeeper: z.boolean() -}) +const EnabledModules = z + .object({ + workspaces: z.boolean(), + gatekeeper: z.boolean(), + billing: z.boolean() + }) + .partial() export type EnabledModules = z.infer diff --git a/packages/server/modules/gatekeeper/index.ts b/packages/server/modules/gatekeeper/index.ts index 4dcca0f1d..d90f26979 100644 --- a/packages/server/modules/gatekeeper/index.ts +++ b/packages/server/modules/gatekeeper/index.ts @@ -19,9 +19,19 @@ const gatekeeperModule: SpeckleModule = { ) if (isInitial) { - if (FF_BILLING_INTEGRATION_ENABLED) app.use(billingRouter) // TODO: need to subscribe to the workspaceCreated event and store the workspacePlan as a trial if billing enabled, else store as unlimited - // TODO: create a cron job, that removes unused seats from the subscription at the beginning of each workspace plan's billing cycle + if (FF_BILLING_INTEGRATION_ENABLED) { + app.use(billingRouter) + + const isLicenseValid = await validateModuleLicense({ + requiredModules: ['billing'] + }) + if (!isLicenseValid) + throw new Error( + 'The the billing module needs a valid license to run, contact Speckle to get one.' + ) + // TODO: create a cron job, that removes unused seats from the subscription at the beginning of each workspace plan's billing cycle + } } } } diff --git a/packages/server/modules/gatekeeper/tests/validateLicense.spec.ts b/packages/server/modules/gatekeeper/tests/validateLicense.spec.ts index d0dd49ca8..5d22a8f58 100644 --- a/packages/server/modules/gatekeeper/tests/validateLicense.spec.ts +++ b/packages/server/modules/gatekeeper/tests/validateLicense.spec.ts @@ -123,7 +123,7 @@ describe('validateLicense @gatekeeper', () => { licenseToken, canonicalUrl, publicKey, - requiredModules: ['workspaces'] + requiredModules: ['workspaces', 'gatekeeper'] }) expect(result).to.be.false