[data-reveal]{opacity:1!important;transform:none!important}
AntelopeJS DMS
DocumentationConfiguration

Configuration

Every option of the SaaS module, how registration asks for a card, and which plan a workspace falls back to.

The module reads its options from its entry in antelope.config.ts. Only stripe is required.

Options

OptionTypeDefaultDescription
stripe.secretKeystringrequiredStripe secret key. A key that does not start with sk_, or that contains placeholder (such as sk_test_placeholder), is not usable, and the module then makes no Stripe call.
stripe.publishableKeystringrequiredStripe publishable key, sent to the browser for the card element.
stripe.webhookSecretstringrequiredSigning secret of the webhook endpoint that targets /api/saas/webhooks/stripe. The endpoint answers 404 while the secret key is unusable or this secret contains placeholder.
stripe.readTimeoutMsnumber4000How long, in milliseconds, a Stripe read that a page renders (billing status, next invoice preview, VAT check) waits before the page renders without it. Writes keep the timeout and retries of the Stripe SDK.
stripe.readMaxNetworkRetriesnumber0How many times such a read is retried after a network failure.
scheduledJobsbooleantruefalse leaves the ten scheduled jobs unscheduled. See Scheduled jobs.
admissionMode"open" or "invitation-only""open"invitation-only closes public registration. Invitations keep working. Any other value stops the module at start.
registration.paymentMethod"required", "optional" or "none""required"Whether public registration asks for a card. See Registration. Any other value stops the module at start.
publicScreens.registerbooleantruefalse frees the register slug for your own page.
publicScreens.pricingbooleantruefalse frees the pricing slug for your own page.
allowedRedirectHostsstring[]host of the DMS clientBaseUrlHosts accepted as return URLs of Stripe Checkout and the billing portal, matched on URL.host. Only http and https URLs pass. A set value replaces the default, so list every host you need. In a development runtime, loopback hosts are accepted without an entry.
defaultPlanSlugstringfirst free planThe free plan every workspace falls back to. See Default plan.
upcomingInvoicePreviewCacheTtlSecondsnumber3600How long the upcoming invoice preview of a workspace is cached. 0 prices every request with Stripe. Plan, billing identity and invoice changes clear the cache sooner. A negative or non-finite value stops the module at start.
reportingCurrencystring"EUR"ISO 4217 code the back office reports recurring revenue in, read in upper case. Amounts in other currencies are shown apart and never converted.
requiredPlanChangePolicystringunsetName of the inventory plan change policy that a deferred downgrade requires. While that policy is not registered, such changes fail closed.
invoiceLineRequiredProvidersstring[][]Invoice line provider IDs that every cycle invoice waits for, even when a provider has not registered yet as the invoice is created.
invoiceLineRecoveryDiscoverySincestring (ISO instant)unsetThe instant from which the module may discover and take over cycle renewal drafts of managed subscriptions whose invoice.created never registered a line injection task. Unset, or a value that is not a date, turns discovery off.
billingEmails.enabledbooleanfalsetrue also e-mails the billing notifications to the owners of the workspace and its billing contact. It needs an @antelopejs/interface-email implementation loaded in the project. See Billing e-mails.
billingEmails.enricherTimeoutMsnumber2000How long, in milliseconds, a billing e-mail waits for the block of each enricher. A late enricher is left out of that e-mail. A value that is not a positive number stops the module at start.

Scheduled jobs

By default the module schedules ten jobs, in the server's time zone, once the DMS has registered its database schemas (its DATABASE_INITIALIZED hook). Each later DMS start replaces them:

JobRunsDoes
Guarded downgradesevery minuteLands a deferred downgrade once its deadline passed and reconciles its Stripe effect.
Workspace lifecycleevery 5 minutesRetries durable lifecycle deliveries, including post-payment workspace creation, and failed billing e-mails.
Invoice line injectionsevery 5 minutesSuspends, injects and finalizes cycle invoices whose usage lines are pending.
Billing stateevery 15 minutesRecomputes the billing state of every workspace and publishes its directory row.
Segmentsevery 15 minutesRecomputes the customer segments.
Automatic suspensiondaily at 01:00Suspends a workspace past due for longer than the suspension delay.
Free workspace expirydaily at 02:00Moves complimentary access whose end date passed to past due.
Free workspace warningdaily at 03:00Notifies workspaces whose free period ends soon.
Webhook event cleanupdaily at 04:00Deletes processed Stripe webhook event records.
Retention deletiondaily at 04:30Deletes a workspace and its data once it was cancelled for longer than the data retention.

scheduledJobs: false schedules none of them. A host that loads the module for its interface only, with no workspaces of its own to run, sets it so that the module acts on no data of the host. Nothing else changes: the HTTP routes, the Stripe webhook and the interface implementations stay on.

The module exposes no entry point to run a job by hand. Everything in the table then stops unless another process runs the module against the same database with scheduledJobs left on: deferred downgrades are not landed, lifecycle deliveries, invoice lines and billing e-mails are not retried, billing states and segments go stale, and past-due, expired, warned and cancelled workspaces keep their state. Run exactly one instance with the jobs on for each database.

The module publishes these values to the browser through its frontend module options, under useDmsRuntimeConfig().public.dmsSaas:

  • stripePublishableKey, from stripe.publishableKey.
  • admissionMode.
  • registrationPaymentMethod, from registration.paymentMethod. The registration screens follow it only until the server tells them the policy it applies (see Registration).
  • publicScreens, the IDs of the bundled public screens the deployment serves.

The Stripe secret key and the webhook secret never reach the browser.

The frontend registration of the module declares /api/saas/register/finalize in authEstablishEndpoints, so the frontend server lets its POST /auth/establish route open a session from that endpoint without any environment variable. See Installation.

Registration

Public registration asks for an account (name, e-mail address, password) and the acceptance of the terms, plus a card when the deployment asks for one. The workspace it opens lands on the default plan, under a default name that its owner renames from the workspace settings. Customer type, billing address, VAT number and plan choice belong to the upgrade flow. While the catalogue has no default plan, registration answers 409 saas.errors.plan.no_free_plan.

POST /api/saas/register checks the password against the DMS password policy (isPasswordCompliant from @antelopejs/interface-dms/auth/password) before it looks up the e-mail address or creates anything. A password that fails the policy gets 400 saas.errors.registration.password_policy. The OAuth completion carries no password.

Two module options shape registration:

json
{
  "modules": {
    "dms-saas": {
      "config": {
        "admissionMode": "open",
        "registration": { "paymentMethod": "required" }
      }
    }
  }
}

registration.paymentMethod decides whether registration asks for a card.

ValueBehaviour
required (default)The card step is shown and must be completed. The workspace gets a Stripe customer that holds the card, and a free subscription. While the free plan has no Stripe price, that subscription is local, and the upgrade checkout replaces it on the same customer. The free-workspace-per-card cap applies when it is on.
optionalThe card step is shown, and the visitor may add a card later. Without a card, the workspace is card-less, as under none.
noneThe card step is never shown. GET /api/saas/register/setup-intent answers 400 saas.errors.registration.payment_method_disabled, and Stripe is never called. The workspace gets a local free subscription with no Stripe customer, and the upgrade checkout creates the customer when the owner first pays. A card sent anyway is ignored.

Without a usable Stripe key

Without a usable Stripe secret key, no card can be confirmed. The server then applies none whatever the option says. Registration lands on the free plan without a card or any Stripe call, and GET /api/saas/register/setup-intent answers 400 saas.errors.registration.payment_method_disabled. A free workspace created in the app asks for no card either.

GET /api/saas/register/plan answers the policy the server applies in paymentMethod. The frontend server cannot tell whether the backend holds a usable key, so registrationPaymentMethod stays the configured value, and the registration screens follow it only until that answer arrives. The page renders on the server with the configured card step. Once the answer arrives, a screen without a usable key drops that step, and it never asks for a SetupIntent, because it mounts the card field only after the answer.

When Stripe cannot be used

Stripe can be configured and still unusable: it refuses the key, the key lacks a permission, Stripe is unreachable, or it answers with a 5xx status or a rate limit. The registration, workspace creation, SetupIntent and plan preview routes then answer 503 saas.errors.stripe.unavailable instead of an unhandled 500, and the screens show the translated message. Without a usable key, the SetupIntent route of workspace creation answers 503 saas.errors.stripe.not_configured. Under optional, the visitor can still add the card later.

The operator routes that need Stripe follow the same rule. The credit note preview and issue, the manual upgrade and its preview, and the balance credit answer 503 saas.errors.stripe.not_configured without a usable key, before any Stripe call or journal entry. They answer 503 saas.errors.stripe.unavailable when Stripe cannot be used. Granting complimentary access answers 503 saas.errors.stripe.unavailable when Stripe cannot cancel the paid subscription. Without a usable key, the available credit of a workspace shows nothing.

Free workspaces per card

The free-workspace-per-card cap is the Free workspaces per card billing rule of the back office. Its default is 0, which turns it off. When an operator turns it on, and Stripe has a usable key, every free workspace created in the app asks for a card. Once a card backs that many free workspaces, another workspace with the same card asks for a paid plan.

Under optional and none, a card-less workspace has no card fingerprint, so the cap does not apply to it. The only remaining limit on free workspaces is one account per e-mail address.

Which entry points the options cover

registration.paymentMethod covers both public entry points, POST /api/saas/register and the auth/no-workspace completion, and nothing else. Invitation sign-up never asks for a plan or a card, whatever admissionMode and registration.paymentMethod say. Workspace creation inside the app ignores registration.paymentMethod. There, a paid plan asks for a card, and a free plan asks for one only under the free-workspace-per-card cap.

admissionMode: "invitation-only" closes public registration. Every /api/saas/register route answers 403 saas.errors.registration_closed before it reads the card policy. Workspace creation inside the app answers the same error to every user except a platform owner. The registration screens show a "Registration is closed" state instead of the form, and the login page drops its sign-up link. Invitations keep working.

useSaasRegistration() reads admissionMode and registrationPaymentMethod from useDmsRuntimeConfig().public.dmsSaas.

The SetupIntent behind the card step

The server restricts the Stripe SetupIntent behind the card step to cards, through allowed_payment_method_types: ["card"], because Stripe is retiring payment_method_types on SetupIntent creation. The Payment Element is created from the client secret alone, because Stripe refuses paymentMethodTypes next to a clientSecret.

Registration rate limit

POST /api/saas/register accepts 20 calls per client address in a 60-second window, refused ones included. The 21st answers 429 Too many requests with a Retry-After header, and the module creates nothing for it. The limit is not configurable.

The @RateLimit decorator of @antelopejs/interface-api-util counts in the memory of each backend process, by the socket address of the request. Each replica keeps its own count, so a client spread across N replicas can register up to N × 20 times per window, and a restart resets the count. Behind a reverse proxy, the socket address is the proxy's, so all the visitors that reach one replica through that proxy share its 20 calls.

Billing e-mails

With billingEmails.enabled, the module also e-mails these notifications, on top of the in-app feed:

Notification subjectSent when
saas.trial_ending_soonStripe announces the end of a trial
saas.trial_ended_blockedA trial ends without a way to pay
saas.free_workspace_ending_soonAbout three days before a complimentary access ends
saas.free_workspace_expiredA complimentary access ends
saas.payment_failedAn invoice payment fails and the workspace goes past due
saas.workspace_suspendedThe grace period of an unpaid invoice ends, an operator suspends the workspace, or a downgrade to a free plan is blocked
saas.workspace_reactivatedAn operator reactivates the workspace, or a payment settles a workspace that was past due or suspended
saas.subscription_cancelledStripe ends the subscription, or an owner deletes the workspace
saas.plan_migratedAn operator's plan migration moves the workspace
  • Recipients. The e-mail goes to every owner of the workspace. It also goes to the billing contact, unless an owner has the same address. The billing contact is the billingEmail of the workspace's billing identity, the address Stripe sends invoices to. Members who get a notification in-app only, such as saas.trial_ending_soon, are not e-mailed.
  • Once per event. Before it is sent, each e-mail is claimed in the saas_billing_email_deliveries table. The claim key combines the workspace, the event and the address. The event is the one the in-app notification is keyed on: a Stripe event, an operation or a job intent. When a Stripe webhook arrives again, a job runs again or a second instance handles the same event, it finds the claim and sends nothing.
    • The claim keeps the notification. A send that fails marks it failed, and the workspace lifecycle job sends it again on its next run, to the same address. After 5 attempts in all, it gives the e-mail up.
    • A claim whose send is not recorded, because the process stopped or the record failed, is held for 10 minutes. The job then sends it again: when the mail server had already accepted the first one, that address gets the e-mail twice.
    • The job gives up an e-mail older than 24 hours. While the option is off or no instance runs the jobs, failed e-mails wait, and those older than that are not sent once it resumes.
    • When the address is no longer a recipient of the workspace, because the owner left or changed address or the billing contact changed, the job gives the e-mail up.
    • The table stores a digest of the address, not the address.
  • Language and layout. Each e-mail is written in the recipient's language, English or French. The billing contact gets the first owner's language. The body repeats the title and text of the in-app notification, in the DMS e-mail layout the invitation uses, with a button to the billing page. The subject line names the workspace.
  • No opt-out. These are service messages about a subscription the recipient owns or pays for, not marketing. The GDPR and the e-privacy rules on unsolicited messages require no opt-out for them, so the e-mail is sent whatever the recipient's notification settings. Its footer says why the recipient gets it.
  • Not through the DMS e-mail channel. The subjects do not set email, so the DMS notification e-mail channel never mails them a second time. That channel would not fit for three reasons:
    • It is called once per user, so it cannot reach a billing contact who has no account.
    • It is one registration that every module shares.
    • A channel that skips notifications whose texts are translation keys, as dms-mailing does, would mail these ones nothing.
  • Delivery. The e-mails are rendered and sent after the in-app notification is stored, and the webhook, job or request does not wait for them. If no @antelopejs/interface-email implementation is loaded, the sends wait for one and no e-mail goes out.

A module can add its own lines to these e-mails with an enricher. The recipients still get one e-mail per event.

Default plan

A workspace is never without a plan once the catalogue has a default plan. The default plan is the active, non-deleted plan with a price of 0 or less, open to individuals (audience any or individual), with the lowest order. defaultPlanSlug picks another plan among those candidates:

json
{ "modules": { "dms-saas": { "config": { "defaultPlanSlug": "free" } } } }

A defaultPlanSlug that names no candidate is ignored with a warning, and the lowest-ordered candidate applies.

Registration opens the default plan. The module attaches it, as an active card-less subscription, when a workspace is created by registration, and when the DMS provisions the default tenant of the platform. When a platform owner publishes the first free plan, or a catalogue edit makes another plan the default, the module attaches the new default once to every workspace that has no subscription at all. Nothing replays this at startup or on a cron. The billing page still covers a plan-less workspace on its first read. A workspace that holds any subscription is never touched. While the catalogue has no free plan, nothing is attached and the module logs a warning.

A catalogue written straight into the plan table, by a seed or an import, does not go through the routes of the platform owner. Attach the plan to the workspaces it should cover in the same seed.

Once attached, the permissions of the plan cap the members of the workspace like any other plan. See Tenant owner permissions.