8cba7eb6f7
* feat(gatekeeper): add gatekeeper module feature flag * feat(gatekeeper): add workspace pricing table domain * feat(gatekeeper): add checkout session creation * feat(gatekeeper): verify stripe signature * wip(gatekeeper): checkout callbacks * feat(gatekeeper): add unlimited and academia plan types * refactor(envHelper): getStringFromEnv helper * chore(gatekeeper): add future todos * feat(gatekeeper): add productId to the subscription domain * feat(gatekeeper): add in memory repositories * feat(gatekeeper): add more errors * feat(gatekeeper): complete checkout session service * feat(gatekeeper): add stripe client implementation * feat(gatekeeper): add checkout session completion webhook callback path * feat(gendo): fix not needing env vars if gendo module is not enabled * feat(gatekeeper): require a license for billing * chore(gatekeeper): cleanup before testing * feat(gatekeeper): subscriptionData parsing model * ci: add billing integration and gatekeeper modules to test config * test(gatekeeper): add checkout service tests * feat(gatekeeper): make completeCheckout callback idempotent properly * feat(gatekeeper): move to knex based repositories * test(gatekeeper): billing repository tests * feat(gatekeeper): add yearly billing cycle toggle * feat(ci): add stripe integration context to test job * feat(billingPage): conditionally render the checkout CTAs * fix(gatekeeper): remove flaky test condition * feat(helm): add billing integration feature flag
42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
import { moduleLogger } from '@/logging/logging'
|
|
import { SpeckleModule } from '@/modules/shared/helpers/typeHelper'
|
|
import { getFeatureFlags } from '@/modules/shared/helpers/envHelper'
|
|
import { validateModuleLicense } from '@/modules/gatekeeper/services/validateLicense'
|
|
import billingRouter from '@/modules/gatekeeper/rest/billing'
|
|
|
|
const { FF_GATEKEEPER_MODULE_ENABLED, FF_BILLING_INTEGRATION_ENABLED } =
|
|
getFeatureFlags()
|
|
|
|
const gatekeeperModule: SpeckleModule = {
|
|
async init(app, isInitial) {
|
|
if (!FF_GATEKEEPER_MODULE_ENABLED) return
|
|
|
|
const isLicenseValid = await validateModuleLicense({
|
|
requiredModules: ['gatekeeper']
|
|
})
|
|
if (!isLicenseValid)
|
|
throw new Error(
|
|
'The gatekeeper module needs a valid license to run, contact Speckle to get one.'
|
|
)
|
|
|
|
moduleLogger.info('🗝️ Init gatekeeper module')
|
|
|
|
if (isInitial) {
|
|
// TODO: need to subscribe to the workspaceCreated event and store the workspacePlan as a trial if billing enabled, else store as unlimited
|
|
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
|
|
}
|
|
}
|
|
}
|
|
}
|
|
export = gatekeeperModule
|