@antelopejs/dms-saas 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +658 -0
- package/dist/auth/index.d.ts +3 -0
- package/dist/auth/index.js +20 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/oauth-entry.d.ts +5 -0
- package/dist/auth/oauth-entry.js +10 -0
- package/dist/auth/oauth-entry.js.map +1 -0
- package/dist/auth/plan-permissions-resolver.d.ts +1 -0
- package/dist/auth/plan-permissions-resolver.js +44 -0
- package/dist/auth/plan-permissions-resolver.js.map +1 -0
- package/dist/auth/subscription-access-gate.d.ts +8 -0
- package/dist/auth/subscription-access-gate.js +38 -0
- package/dist/auth/subscription-access-gate.js.map +1 -0
- package/dist/automation/index.d.ts +44 -0
- package/dist/automation/index.js +209 -0
- package/dist/automation/index.js.map +1 -0
- package/dist/billing-state/index.d.ts +5 -0
- package/dist/billing-state/index.js +58 -0
- package/dist/billing-state/index.js.map +1 -0
- package/dist/billing-state/recovery.d.ts +22 -0
- package/dist/billing-state/recovery.js +81 -0
- package/dist/billing-state/recovery.js.map +1 -0
- package/dist/config/dev-mode.d.ts +3 -0
- package/dist/config/dev-mode.js +27 -0
- package/dist/config/dev-mode.js.map +1 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +19 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/runtime.d.ts +6 -0
- package/dist/config/runtime.js +54 -0
- package/dist/config/runtime.js.map +1 -0
- package/dist/crons/auto-suspend-past-due.d.ts +2 -0
- package/dist/crons/auto-suspend-past-due.js +43 -0
- package/dist/crons/auto-suspend-past-due.js.map +1 -0
- package/dist/crons/cleanup-stripe-webhook-events.d.ts +2 -0
- package/dist/crons/cleanup-stripe-webhook-events.js +27 -0
- package/dist/crons/cleanup-stripe-webhook-events.js.map +1 -0
- package/dist/crons/expire-free-workspaces.d.ts +2 -0
- package/dist/crons/expire-free-workspaces.js +36 -0
- package/dist/crons/expire-free-workspaces.js.map +1 -0
- package/dist/crons/hard-delete-cancelled.d.ts +2 -0
- package/dist/crons/hard-delete-cancelled.js +55 -0
- package/dist/crons/hard-delete-cancelled.js.map +1 -0
- package/dist/crons/index.d.ts +8 -0
- package/dist/crons/index.js +25 -0
- package/dist/crons/index.js.map +1 -0
- package/dist/crons/notify-free-workspaces-ending-soon.d.ts +2 -0
- package/dist/crons/notify-free-workspaces-ending-soon.js +69 -0
- package/dist/crons/notify-free-workspaces-ending-soon.js.map +1 -0
- package/dist/crons/recompute-billing-state.d.ts +2 -0
- package/dist/crons/recompute-billing-state.js +19 -0
- package/dist/crons/recompute-billing-state.js.map +1 -0
- package/dist/crons/recompute-segments.d.ts +2 -0
- package/dist/crons/recompute-segments.js +19 -0
- package/dist/crons/recompute-segments.js.map +1 -0
- package/dist/crons/reconcile-workspace-lifecycle.d.ts +2 -0
- package/dist/crons/reconcile-workspace-lifecycle.js +19 -0
- package/dist/crons/reconcile-workspace-lifecycle.js.map +1 -0
- package/dist/crons/register.d.ts +2 -0
- package/dist/crons/register.js +24 -0
- package/dist/crons/register.js.map +1 -0
- package/dist/crons/subscription-notifications.d.ts +2 -0
- package/dist/crons/subscription-notifications.js +55 -0
- package/dist/crons/subscription-notifications.js.map +1 -0
- package/dist/data-api/index.d.ts +2 -0
- package/dist/data-api/index.js +19 -0
- package/dist/data-api/index.js.map +1 -0
- package/dist/data-api/platformOwner/admin-user-invoices.d.ts +27 -0
- package/dist/data-api/platformOwner/admin-user-invoices.js +158 -0
- package/dist/data-api/platformOwner/admin-user-invoices.js.map +1 -0
- package/dist/data-api/platformOwner/admin-user-workspaces.d.ts +22 -0
- package/dist/data-api/platformOwner/admin-user-workspaces.js +97 -0
- package/dist/data-api/platformOwner/admin-user-workspaces.js.map +1 -0
- package/dist/data-api/platformOwner/credit-notes.d.ts +24 -0
- package/dist/data-api/platformOwner/credit-notes.js +133 -0
- package/dist/data-api/platformOwner/credit-notes.js.map +1 -0
- package/dist/data-api/platformOwner/features.d.ts +30 -0
- package/dist/data-api/platformOwner/features.js +141 -0
- package/dist/data-api/platformOwner/features.js.map +1 -0
- package/dist/data-api/platformOwner/hidden-filter.d.ts +1 -0
- package/dist/data-api/platformOwner/hidden-filter.js +18 -0
- package/dist/data-api/platformOwner/hidden-filter.js.map +1 -0
- package/dist/data-api/platformOwner/index.d.ts +12 -0
- package/dist/data-api/platformOwner/index.js +29 -0
- package/dist/data-api/platformOwner/index.js.map +1 -0
- package/dist/data-api/platformOwner/invoice-options.d.ts +7 -0
- package/dist/data-api/platformOwner/invoice-options.js +14 -0
- package/dist/data-api/platformOwner/invoice-options.js.map +1 -0
- package/dist/data-api/platformOwner/invoices.d.ts +26 -0
- package/dist/data-api/platformOwner/invoices.js +147 -0
- package/dist/data-api/platformOwner/invoices.js.map +1 -0
- package/dist/data-api/platformOwner/members.d.ts +24 -0
- package/dist/data-api/platformOwner/members.js +125 -0
- package/dist/data-api/platformOwner/members.js.map +1 -0
- package/dist/data-api/platformOwner/plan-migrations.d.ts +24 -0
- package/dist/data-api/platformOwner/plan-migrations.js +138 -0
- package/dist/data-api/platformOwner/plan-migrations.js.map +1 -0
- package/dist/data-api/platformOwner/plans.d.ts +30 -0
- package/dist/data-api/platformOwner/plans.js +228 -0
- package/dist/data-api/platformOwner/plans.js.map +1 -0
- package/dist/data-api/platformOwner/segments.d.ts +29 -0
- package/dist/data-api/platformOwner/segments.js +223 -0
- package/dist/data-api/platformOwner/segments.js.map +1 -0
- package/dist/data-api/platformOwner/support.d.ts +58 -0
- package/dist/data-api/platformOwner/support.js +111 -0
- package/dist/data-api/platformOwner/support.js.map +1 -0
- package/dist/data-api/platformOwner/users.d.ts +22 -0
- package/dist/data-api/platformOwner/users.js +128 -0
- package/dist/data-api/platformOwner/users.js.map +1 -0
- package/dist/data-api/platformOwner/workspaces.d.ts +22 -0
- package/dist/data-api/platformOwner/workspaces.js +153 -0
- package/dist/data-api/platformOwner/workspaces.js.map +1 -0
- package/dist/data-api/support-fields.d.ts +49 -0
- package/dist/data-api/support-fields.js +166 -0
- package/dist/data-api/support-fields.js.map +1 -0
- package/dist/data-api/support-routes.d.ts +10 -0
- package/dist/data-api/support-routes.js +71 -0
- package/dist/data-api/support-routes.js.map +1 -0
- package/dist/data-api/tenant/index.d.ts +2 -0
- package/dist/data-api/tenant/index.js +19 -0
- package/dist/data-api/tenant/index.js.map +1 -0
- package/dist/data-api/tenant/support.d.ts +39 -0
- package/dist/data-api/tenant/support.js +53 -0
- package/dist/data-api/tenant/support.js.map +1 -0
- package/dist/data-api/tenant/tenant-invoices.d.ts +37 -0
- package/dist/data-api/tenant/tenant-invoices.js +242 -0
- package/dist/data-api/tenant/tenant-invoices.js.map +1 -0
- package/dist/db/index.d.ts +1 -0
- package/dist/db/index.js +18 -0
- package/dist/db/index.js.map +1 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.js +20 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/register.d.ts +1 -0
- package/dist/hooks/register.js +57 -0
- package/dist/hooks/register.js.map +1 -0
- package/dist/hooks/tenant-export.d.ts +2 -0
- package/dist/hooks/tenant-export.js +64 -0
- package/dist/hooks/tenant-export.js.map +1 -0
- package/dist/hooks/tenant-provisioning.d.ts +3 -0
- package/dist/hooks/tenant-provisioning.js +12 -0
- package/dist/hooks/tenant-provisioning.js.map +1 -0
- package/dist/implementations/dms-saas/billing.d.ts +2 -0
- package/dist/implementations/dms-saas/billing.js +49 -0
- package/dist/implementations/dms-saas/billing.js.map +1 -0
- package/dist/implementations/dms-saas/invoice-line-items.d.ts +11 -0
- package/dist/implementations/dms-saas/invoice-line-items.js +24 -0
- package/dist/implementations/dms-saas/invoice-line-items.js.map +1 -0
- package/dist/implementations/dms-saas/pages.d.ts +3 -0
- package/dist/implementations/dms-saas/pages.js +12 -0
- package/dist/implementations/dms-saas/pages.js.map +1 -0
- package/dist/implementations/dms-saas/workspace-lifecycle.d.ts +2 -0
- package/dist/implementations/dms-saas/workspace-lifecycle.js +23 -0
- package/dist/implementations/dms-saas/workspace-lifecycle.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -0
- package/dist/invoice-line-items/billing-window.d.ts +3 -0
- package/dist/invoice-line-items/billing-window.js +19 -0
- package/dist/invoice-line-items/billing-window.js.map +1 -0
- package/dist/invoice-line-items/index.d.ts +1 -0
- package/dist/invoice-line-items/index.js +18 -0
- package/dist/invoice-line-items/index.js.map +1 -0
- package/dist/invoice-line-items/injection.d.ts +2 -0
- package/dist/invoice-line-items/injection.js +171 -0
- package/dist/invoice-line-items/injection.js.map +1 -0
- package/dist/notifications/index.d.ts +2 -0
- package/dist/notifications/index.js +19 -0
- package/dist/notifications/index.js.map +1 -0
- package/dist/notifications/recipients.d.ts +14 -0
- package/dist/notifications/recipients.js +87 -0
- package/dist/notifications/recipients.js.map +1 -0
- package/dist/notifications/subjects.d.ts +21 -0
- package/dist/notifications/subjects.js +121 -0
- package/dist/notifications/subjects.js.map +1 -0
- package/dist/operator-actions/commands.d.ts +41 -0
- package/dist/operator-actions/commands.js +233 -0
- package/dist/operator-actions/commands.js.map +1 -0
- package/dist/operator-actions/db/index.d.ts +4 -0
- package/dist/operator-actions/db/index.js +21 -0
- package/dist/operator-actions/db/index.js.map +1 -0
- package/dist/operator-actions/db/lifecycle-delivery.model.d.ts +29 -0
- package/dist/operator-actions/db/lifecycle-delivery.model.js +85 -0
- package/dist/operator-actions/db/lifecycle-delivery.model.js.map +1 -0
- package/dist/operator-actions/db/lifecycle-delivery.table.d.ts +26 -0
- package/dist/operator-actions/db/lifecycle-delivery.table.js +107 -0
- package/dist/operator-actions/db/lifecycle-delivery.table.js.map +1 -0
- package/dist/operator-actions/db/operator-action.model.d.ts +33 -0
- package/dist/operator-actions/db/operator-action.model.js +63 -0
- package/dist/operator-actions/db/operator-action.model.js.map +1 -0
- package/dist/operator-actions/db/operator-action.table.d.ts +21 -0
- package/dist/operator-actions/db/operator-action.table.js +95 -0
- package/dist/operator-actions/db/operator-action.table.js.map +1 -0
- package/dist/operator-actions/index.d.ts +3 -0
- package/dist/operator-actions/index.js +20 -0
- package/dist/operator-actions/index.js.map +1 -0
- package/dist/operator-actions/journal.d.ts +22 -0
- package/dist/operator-actions/journal.js +183 -0
- package/dist/operator-actions/journal.js.map +1 -0
- package/dist/operator-actions/lifecycle-consumers.d.ts +12 -0
- package/dist/operator-actions/lifecycle-consumers.js +28 -0
- package/dist/operator-actions/lifecycle-consumers.js.map +1 -0
- package/dist/operator-actions/lifecycle-outbox.d.ts +19 -0
- package/dist/operator-actions/lifecycle-outbox.js +229 -0
- package/dist/operator-actions/lifecycle-outbox.js.map +1 -0
- package/dist/operator-actions/types.d.ts +11 -0
- package/dist/operator-actions/types.js +3 -0
- package/dist/operator-actions/types.js.map +1 -0
- package/dist/pages/definitions.d.ts +1 -0
- package/dist/pages/definitions.js +18 -0
- package/dist/pages/definitions.js.map +1 -0
- package/dist/pages/index.d.ts +4 -0
- package/dist/pages/index.js +21 -0
- package/dist/pages/index.js.map +1 -0
- package/dist/pages/module.d.ts +5 -0
- package/dist/pages/module.js +15 -0
- package/dist/pages/module.js.map +1 -0
- package/dist/pages/platform/categories.d.ts +6 -0
- package/dist/pages/platform/categories.js +48 -0
- package/dist/pages/platform/categories.js.map +1 -0
- package/dist/pages/platform/credit-notes.d.ts +9 -0
- package/dist/pages/platform/credit-notes.js +40 -0
- package/dist/pages/platform/credit-notes.js.map +1 -0
- package/dist/pages/platform/dashboard.d.ts +10 -0
- package/dist/pages/platform/dashboard.js +95 -0
- package/dist/pages/platform/dashboard.js.map +1 -0
- package/dist/pages/platform/features.d.ts +9 -0
- package/dist/pages/platform/features.js +42 -0
- package/dist/pages/platform/features.js.map +1 -0
- package/dist/pages/platform/index.d.ts +15 -0
- package/dist/pages/platform/index.js +32 -0
- package/dist/pages/platform/index.js.map +1 -0
- package/dist/pages/platform/invoices.d.ts +9 -0
- package/dist/pages/platform/invoices.js +63 -0
- package/dist/pages/platform/invoices.js.map +1 -0
- package/dist/pages/platform/plans/edit.d.ts +17 -0
- package/dist/pages/platform/plans/edit.js +213 -0
- package/dist/pages/platform/plans/edit.js.map +1 -0
- package/dist/pages/platform/plans/index.d.ts +9 -0
- package/dist/pages/platform/plans/index.js +99 -0
- package/dist/pages/platform/plans/index.js.map +1 -0
- package/dist/pages/platform/plans/migrations.d.ts +9 -0
- package/dist/pages/platform/plans/migrations.js +38 -0
- package/dist/pages/platform/plans/migrations.js.map +1 -0
- package/dist/pages/platform/segments/index.d.ts +9 -0
- package/dist/pages/platform/segments/index.js +59 -0
- package/dist/pages/platform/segments/index.js.map +1 -0
- package/dist/pages/platform/settings.d.ts +9 -0
- package/dist/pages/platform/settings.js +147 -0
- package/dist/pages/platform/settings.js.map +1 -0
- package/dist/pages/platform/support.d.ts +9 -0
- package/dist/pages/platform/support.js +29 -0
- package/dist/pages/platform/support.js.map +1 -0
- package/dist/pages/platform/users/detail.d.ts +9 -0
- package/dist/pages/platform/users/detail.js +78 -0
- package/dist/pages/platform/users/detail.js.map +1 -0
- package/dist/pages/platform/users/index.d.ts +9 -0
- package/dist/pages/platform/users/index.js +77 -0
- package/dist/pages/platform/users/index.js.map +1 -0
- package/dist/pages/platform/workspaces/detail.d.ts +9 -0
- package/dist/pages/platform/workspaces/detail.js +120 -0
- package/dist/pages/platform/workspaces/detail.js.map +1 -0
- package/dist/pages/platform/workspaces/index.d.ts +35 -0
- package/dist/pages/platform/workspaces/index.js +300 -0
- package/dist/pages/platform/workspaces/index.js.map +1 -0
- package/dist/pages/public/auth/index.d.ts +1 -0
- package/dist/pages/public/auth/index.js +18 -0
- package/dist/pages/public/auth/index.js.map +1 -0
- package/dist/pages/public/auth/no-workspace.d.ts +9 -0
- package/dist/pages/public/auth/no-workspace.js +26 -0
- package/dist/pages/public/auth/no-workspace.js.map +1 -0
- package/dist/pages/public/index.d.ts +3 -0
- package/dist/pages/public/index.js +20 -0
- package/dist/pages/public/index.js.map +1 -0
- package/dist/pages/public/legal/index.d.ts +3 -0
- package/dist/pages/public/legal/index.js +20 -0
- package/dist/pages/public/legal/index.js.map +1 -0
- package/dist/pages/public/legal/privacy-policy.d.ts +9 -0
- package/dist/pages/public/legal/privacy-policy.js +29 -0
- package/dist/pages/public/legal/privacy-policy.js.map +1 -0
- package/dist/pages/public/legal/terms-and-conditions.d.ts +9 -0
- package/dist/pages/public/legal/terms-and-conditions.js +29 -0
- package/dist/pages/public/legal/terms-and-conditions.js.map +1 -0
- package/dist/pages/public/legal/terms-of-use.d.ts +9 -0
- package/dist/pages/public/legal/terms-of-use.js +29 -0
- package/dist/pages/public/legal/terms-of-use.js.map +1 -0
- package/dist/pages/public/register.d.ts +9 -0
- package/dist/pages/public/register.js +29 -0
- package/dist/pages/public/register.js.map +1 -0
- package/dist/pages/public/screens.d.ts +3 -0
- package/dist/pages/public/screens.js +50 -0
- package/dist/pages/public/screens.js.map +1 -0
- package/dist/pages/tenant/billing.d.ts +15 -0
- package/dist/pages/tenant/billing.js +87 -0
- package/dist/pages/tenant/billing.js.map +1 -0
- package/dist/pages/tenant/data-export.d.ts +10 -0
- package/dist/pages/tenant/data-export.js +32 -0
- package/dist/pages/tenant/data-export.js.map +1 -0
- package/dist/pages/tenant/general.d.ts +10 -0
- package/dist/pages/tenant/general.js +33 -0
- package/dist/pages/tenant/general.js.map +1 -0
- package/dist/pages/tenant/index.d.ts +6 -0
- package/dist/pages/tenant/index.js +23 -0
- package/dist/pages/tenant/index.js.map +1 -0
- package/dist/pages/tenant/members-seat-quota.d.ts +3 -0
- package/dist/pages/tenant/members-seat-quota.js +25 -0
- package/dist/pages/tenant/members-seat-quota.js.map +1 -0
- package/dist/pages/tenant/support.d.ts +9 -0
- package/dist/pages/tenant/support.js +27 -0
- package/dist/pages/tenant/support.js.map +1 -0
- package/dist/pages/tenant/workspace-suspended.d.ts +9 -0
- package/dist/pages/tenant/workspace-suspended.js +26 -0
- package/dist/pages/tenant/workspace-suspended.js.map +1 -0
- package/dist/plan-changes/deferred.d.ts +18 -0
- package/dist/plan-changes/deferred.js +225 -0
- package/dist/plan-changes/deferred.js.map +1 -0
- package/dist/plan-changes/index.d.ts +1 -0
- package/dist/plan-changes/index.js +18 -0
- package/dist/plan-changes/index.js.map +1 -0
- package/dist/plans/index.d.ts +4 -0
- package/dist/plans/index.js +21 -0
- package/dist/plans/index.js.map +1 -0
- package/dist/plans/seat-capacity.d.ts +9 -0
- package/dist/plans/seat-capacity.js +38 -0
- package/dist/plans/seat-capacity.js.map +1 -0
- package/dist/plans/seat-hooks.d.ts +1 -0
- package/dist/plans/seat-hooks.js +80 -0
- package/dist/plans/seat-hooks.js.map +1 -0
- package/dist/plans/seat-sync.d.ts +10 -0
- package/dist/plans/seat-sync.js +23 -0
- package/dist/plans/seat-sync.js.map +1 -0
- package/dist/routes/index.d.ts +3 -0
- package/dist/routes/index.js +20 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/routes/platformOwner/billing-settings.d.ts +20 -0
- package/dist/routes/platformOwner/billing-settings.js +98 -0
- package/dist/routes/platformOwner/billing-settings.js.map +1 -0
- package/dist/routes/platformOwner/credit-notes-issue.d.ts +16 -0
- package/dist/routes/platformOwner/credit-notes-issue.js +56 -0
- package/dist/routes/platformOwner/credit-notes-issue.js.map +1 -0
- package/dist/routes/platformOwner/dashboard.d.ts +62 -0
- package/dist/routes/platformOwner/dashboard.js +310 -0
- package/dist/routes/platformOwner/dashboard.js.map +1 -0
- package/dist/routes/platformOwner/index.d.ts +12 -0
- package/dist/routes/platformOwner/index.js +29 -0
- package/dist/routes/platformOwner/index.js.map +1 -0
- package/dist/routes/platformOwner/plan-deletion.d.ts +30 -0
- package/dist/routes/platformOwner/plan-deletion.js +156 -0
- package/dist/routes/platformOwner/plan-deletion.js.map +1 -0
- package/dist/routes/platformOwner/plans.d.ts +99 -0
- package/dist/routes/platformOwner/plans.js +376 -0
- package/dist/routes/platformOwner/plans.js.map +1 -0
- package/dist/routes/platformOwner/platform-notes.d.ts +36 -0
- package/dist/routes/platformOwner/platform-notes.js +149 -0
- package/dist/routes/platformOwner/platform-notes.js.map +1 -0
- package/dist/routes/platformOwner/platform-owners.d.ts +12 -0
- package/dist/routes/platformOwner/platform-owners.js +77 -0
- package/dist/routes/platformOwner/platform-owners.js.map +1 -0
- package/dist/routes/platformOwner/segments.d.ts +24 -0
- package/dist/routes/platformOwner/segments.js +174 -0
- package/dist/routes/platformOwner/segments.js.map +1 -0
- package/dist/routes/platformOwner/support.d.ts +21 -0
- package/dist/routes/platformOwner/support.js +180 -0
- package/dist/routes/platformOwner/support.js.map +1 -0
- package/dist/routes/platformOwner/users-detail.d.ts +26 -0
- package/dist/routes/platformOwner/users-detail.js +82 -0
- package/dist/routes/platformOwner/users-detail.js.map +1 -0
- package/dist/routes/platformOwner/workspace-operator-actions.d.ts +34 -0
- package/dist/routes/platformOwner/workspace-operator-actions.js +183 -0
- package/dist/routes/platformOwner/workspace-operator-actions.js.map +1 -0
- package/dist/routes/platformOwner/workspaces-admin.d.ts +27 -0
- package/dist/routes/platformOwner/workspaces-admin.js +140 -0
- package/dist/routes/platformOwner/workspaces-admin.js.map +1 -0
- package/dist/routes/public/index.d.ts +3 -0
- package/dist/routes/public/index.js +20 -0
- package/dist/routes/public/index.js.map +1 -0
- package/dist/routes/public/legal-documents.d.ts +15 -0
- package/dist/routes/public/legal-documents.js +72 -0
- package/dist/routes/public/legal-documents.js.map +1 -0
- package/dist/routes/public/register.d.ts +48 -0
- package/dist/routes/public/register.js +193 -0
- package/dist/routes/public/register.js.map +1 -0
- package/dist/routes/public/webhooks/index.d.ts +1 -0
- package/dist/routes/public/webhooks/index.js +18 -0
- package/dist/routes/public/webhooks/index.js.map +1 -0
- package/dist/routes/public/webhooks/stripe.d.ts +7 -0
- package/dist/routes/public/webhooks/stripe.js +41 -0
- package/dist/routes/public/webhooks/stripe.js.map +1 -0
- package/dist/routes/tenant/billing-portal.d.ts +31 -0
- package/dist/routes/tenant/billing-portal.js +117 -0
- package/dist/routes/tenant/billing-portal.js.map +1 -0
- package/dist/routes/tenant/billing-self-refund.d.ts +18 -0
- package/dist/routes/tenant/billing-self-refund.js +199 -0
- package/dist/routes/tenant/billing-self-refund.js.map +1 -0
- package/dist/routes/tenant/data-export.d.ts +16 -0
- package/dist/routes/tenant/data-export.js +102 -0
- package/dist/routes/tenant/data-export.js.map +1 -0
- package/dist/routes/tenant/index.d.ts +9 -0
- package/dist/routes/tenant/index.js +26 -0
- package/dist/routes/tenant/index.js.map +1 -0
- package/dist/routes/tenant/support.d.ts +27 -0
- package/dist/routes/tenant/support.js +185 -0
- package/dist/routes/tenant/support.js.map +1 -0
- package/dist/routes/tenant/tenant-billing.d.ts +26 -0
- package/dist/routes/tenant/tenant-billing.js +148 -0
- package/dist/routes/tenant/tenant-billing.js.map +1 -0
- package/dist/routes/tenant/tenant-plan-ops.d.ts +57 -0
- package/dist/routes/tenant/tenant-plan-ops.js +244 -0
- package/dist/routes/tenant/tenant-plan-ops.js.map +1 -0
- package/dist/routes/tenant/tenant-plan.d.ts +19 -0
- package/dist/routes/tenant/tenant-plan.js +172 -0
- package/dist/routes/tenant/tenant-plan.js.map +1 -0
- package/dist/routes/tenant/tenant-seats.d.ts +17 -0
- package/dist/routes/tenant/tenant-seats.js +58 -0
- package/dist/routes/tenant/tenant-seats.js.map +1 -0
- package/dist/routes/tenant/workspaces.d.ts +78 -0
- package/dist/routes/tenant/workspaces.js +301 -0
- package/dist/routes/tenant/workspaces.js.map +1 -0
- package/dist/stripe/client.d.ts +6 -0
- package/dist/stripe/client.js +44 -0
- package/dist/stripe/client.js.map +1 -0
- package/dist/stripe/customer-balance.d.ts +12 -0
- package/dist/stripe/customer-balance.js +16 -0
- package/dist/stripe/customer-balance.js.map +1 -0
- package/dist/stripe/customer-billing.d.ts +33 -0
- package/dist/stripe/customer-billing.js +140 -0
- package/dist/stripe/customer-billing.js.map +1 -0
- package/dist/stripe/index.d.ts +11 -0
- package/dist/stripe/index.js +28 -0
- package/dist/stripe/index.js.map +1 -0
- package/dist/stripe/plan-schedule.d.ts +9 -0
- package/dist/stripe/plan-schedule.js +83 -0
- package/dist/stripe/plan-schedule.js.map +1 -0
- package/dist/stripe/proration.d.ts +2 -0
- package/dist/stripe/proration.js +19 -0
- package/dist/stripe/proration.js.map +1 -0
- package/dist/stripe/sync-plan.d.ts +2 -0
- package/dist/stripe/sync-plan.js +66 -0
- package/dist/stripe/sync-plan.js.map +1 -0
- package/dist/stripe/webhook-checkout.d.ts +3 -0
- package/dist/stripe/webhook-checkout.js +157 -0
- package/dist/stripe/webhook-checkout.js.map +1 -0
- package/dist/stripe/webhook-credit-notes.d.ts +3 -0
- package/dist/stripe/webhook-credit-notes.js +192 -0
- package/dist/stripe/webhook-credit-notes.js.map +1 -0
- package/dist/stripe/webhook-dispatch.d.ts +2 -0
- package/dist/stripe/webhook-dispatch.js +45 -0
- package/dist/stripe/webhook-dispatch.js.map +1 -0
- package/dist/stripe/webhook-handlers.d.ts +11 -0
- package/dist/stripe/webhook-handlers.js +318 -0
- package/dist/stripe/webhook-handlers.js.map +1 -0
- package/dist/stripe/webhook-shared.d.ts +28 -0
- package/dist/stripe/webhook-shared.js +126 -0
- package/dist/stripe/webhook-shared.js.map +1 -0
- package/dist/stripe/workspace-checkout.d.ts +29 -0
- package/dist/stripe/workspace-checkout.js +106 -0
- package/dist/stripe/workspace-checkout.js.map +1 -0
- package/dist/support/admissions.d.ts +36 -0
- package/dist/support/admissions.js +136 -0
- package/dist/support/admissions.js.map +1 -0
- package/dist/support/attachments.d.ts +12 -0
- package/dist/support/attachments.js +56 -0
- package/dist/support/attachments.js.map +1 -0
- package/dist/support/config.d.ts +19 -0
- package/dist/support/config.js +75 -0
- package/dist/support/config.js.map +1 -0
- package/dist/support/index.d.ts +6 -0
- package/dist/support/index.js +23 -0
- package/dist/support/index.js.map +1 -0
- package/dist/support/operations.d.ts +51 -0
- package/dist/support/operations.js +109 -0
- package/dist/support/operations.js.map +1 -0
- package/dist/support/plans.d.ts +6 -0
- package/dist/support/plans.js +130 -0
- package/dist/support/plans.js.map +1 -0
- package/dist/support/publications.d.ts +8 -0
- package/dist/support/publications.js +106 -0
- package/dist/support/publications.js.map +1 -0
- package/dist/support/recovery.d.ts +7 -0
- package/dist/support/recovery.js +43 -0
- package/dist/support/recovery.js.map +1 -0
- package/dist/support/service.d.ts +51 -0
- package/dist/support/service.js +143 -0
- package/dist/support/service.js.map +1 -0
- package/dist/support/transitions.d.ts +4 -0
- package/dist/support/transitions.js +29 -0
- package/dist/support/transitions.js.map +1 -0
- package/dist/support/uploads.d.ts +39 -0
- package/dist/support/uploads.js +115 -0
- package/dist/support/uploads.js.map +1 -0
- package/dist/support/validation.d.ts +15 -0
- package/dist/support/validation.js +54 -0
- package/dist/support/validation.js.map +1 -0
- package/dist/types/config.d.ts +16 -0
- package/dist/types/config.js +3 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +18 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/billing-document-type.d.ts +3 -0
- package/dist/utils/billing-document-type.js +18 -0
- package/dist/utils/billing-document-type.js.map +1 -0
- package/dist/utils/billing-period-type.d.ts +3 -0
- package/dist/utils/billing-period-type.js +18 -0
- package/dist/utils/billing-period-type.js.map +1 -0
- package/dist/utils/email-hash.d.ts +1 -0
- package/dist/utils/email-hash.js +8 -0
- package/dist/utils/email-hash.js.map +1 -0
- package/dist/utils/export-dataset-stream.d.ts +19 -0
- package/dist/utils/export-dataset-stream.js +40 -0
- package/dist/utils/export-dataset-stream.js.map +1 -0
- package/dist/utils/index.d.ts +15 -0
- package/dist/utils/index.js +32 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/invoice-lines-type.d.ts +27 -0
- package/dist/utils/invoice-lines-type.js +34 -0
- package/dist/utils/invoice-lines-type.js.map +1 -0
- package/dist/utils/money-cents-type.d.ts +3 -0
- package/dist/utils/money-cents-type.js +18 -0
- package/dist/utils/money-cents-type.js.map +1 -0
- package/dist/utils/pagination.d.ts +22 -0
- package/dist/utils/pagination.js +35 -0
- package/dist/utils/pagination.js.map +1 -0
- package/dist/utils/parse-future-date.d.ts +1 -0
- package/dist/utils/parse-future-date.js +15 -0
- package/dist/utils/parse-future-date.js.map +1 -0
- package/dist/utils/row-instance.d.ts +1 -0
- package/dist/utils/row-instance.js +8 -0
- package/dist/utils/row-instance.js.map +1 -0
- package/dist/utils/segment-conditions-type.d.ts +33 -0
- package/dist/utils/segment-conditions-type.js +86 -0
- package/dist/utils/segment-conditions-type.js.map +1 -0
- package/dist/utils/segment-evaluator.d.ts +3 -0
- package/dist/utils/segment-evaluator.js +117 -0
- package/dist/utils/segment-evaluator.js.map +1 -0
- package/dist/utils/segment-fields.d.ts +19 -0
- package/dist/utils/segment-fields.js +212 -0
- package/dist/utils/segment-fields.js.map +1 -0
- package/dist/utils/segment-matching.d.ts +56 -0
- package/dist/utils/segment-matching.js +200 -0
- package/dist/utils/segment-matching.js.map +1 -0
- package/dist/utils/segment-name-cache.d.ts +2 -0
- package/dist/utils/segment-name-cache.js +22 -0
- package/dist/utils/segment-name-cache.js.map +1 -0
- package/dist/utils/time.d.ts +3 -0
- package/dist/utils/time.js +10 -0
- package/dist/utils/time.js.map +1 -0
- package/dist/workers/index.d.ts +1 -0
- package/dist/workers/index.js +18 -0
- package/dist/workers/index.js.map +1 -0
- package/dist/workers/plan-migration.d.ts +4 -0
- package/dist/workers/plan-migration.js +206 -0
- package/dist/workers/plan-migration.js.map +1 -0
- package/dist/workspaces/billing-profile.d.ts +3 -0
- package/dist/workspaces/billing-profile.js +55 -0
- package/dist/workspaces/billing-profile.js.map +1 -0
- package/dist/workspaces/complimentary.d.ts +7 -0
- package/dist/workspaces/complimentary.js +47 -0
- package/dist/workspaces/complimentary.js.map +1 -0
- package/dist/workspaces/db/card-capacity.model.d.ts +30 -0
- package/dist/workspaces/db/card-capacity.model.js +98 -0
- package/dist/workspaces/db/card-capacity.model.js.map +1 -0
- package/dist/workspaces/db/card-capacity.table.d.ts +11 -0
- package/dist/workspaces/db/card-capacity.table.js +34 -0
- package/dist/workspaces/db/card-capacity.table.js.map +1 -0
- package/dist/workspaces/db/provisioning-attempt.model.d.ts +24 -0
- package/dist/workspaces/db/provisioning-attempt.model.js +33 -0
- package/dist/workspaces/db/provisioning-attempt.model.js.map +1 -0
- package/dist/workspaces/db/provisioning-attempt.table.d.ts +18 -0
- package/dist/workspaces/db/provisioning-attempt.table.js +77 -0
- package/dist/workspaces/db/provisioning-attempt.table.js.map +1 -0
- package/dist/workspaces/db/trial-identity.model.d.ts +25 -0
- package/dist/workspaces/db/trial-identity.model.js +62 -0
- package/dist/workspaces/db/trial-identity.model.js.map +1 -0
- package/dist/workspaces/db/trial-identity.table.d.ts +7 -0
- package/dist/workspaces/db/trial-identity.table.js +34 -0
- package/dist/workspaces/db/trial-identity.table.js.map +1 -0
- package/dist/workspaces/deletion.d.ts +8 -0
- package/dist/workspaces/deletion.js +75 -0
- package/dist/workspaces/deletion.js.map +1 -0
- package/dist/workspaces/free-workspace-guard.d.ts +11 -0
- package/dist/workspaces/free-workspace-guard.js +96 -0
- package/dist/workspaces/free-workspace-guard.js.map +1 -0
- package/dist/workspaces/index.d.ts +6 -0
- package/dist/workspaces/index.js +23 -0
- package/dist/workspaces/index.js.map +1 -0
- package/dist/workspaces/provisioning-rollback.d.ts +2 -0
- package/dist/workspaces/provisioning-rollback.js +78 -0
- package/dist/workspaces/provisioning-rollback.js.map +1 -0
- package/dist/workspaces/provisioning-state.d.ts +6 -0
- package/dist/workspaces/provisioning-state.js +91 -0
- package/dist/workspaces/provisioning-state.js.map +1 -0
- package/dist/workspaces/provisioning.d.ts +49 -0
- package/dist/workspaces/provisioning.js +263 -0
- package/dist/workspaces/provisioning.js.map +1 -0
- package/dist/workspaces/registration-extras.d.ts +1 -0
- package/dist/workspaces/registration-extras.js +50 -0
- package/dist/workspaces/registration-extras.js.map +1 -0
- package/dist/workspaces/suspension.d.ts +13 -0
- package/dist/workspaces/suspension.js +124 -0
- package/dist/workspaces/suspension.js.map +1 -0
- package/frontend-vue/.editorconfig +12 -0
- package/frontend-vue/.prettierrc +11 -0
- package/frontend-vue/app/build/.gitkeep +0 -0
- package/frontend-vue/app/components/CardGrid.vue +77 -0
- package/frontend-vue/app/components/CustomerPortalButton.vue +45 -0
- package/frontend-vue/app/components/DataExport.vue +300 -0
- package/frontend-vue/app/components/DeletePlanModal.vue +223 -0
- package/frontend-vue/app/components/FreeAccessBanner.vue +70 -0
- package/frontend-vue/app/components/InvoiceLines.vue +57 -0
- package/frontend-vue/app/components/IssueCreditNoteModal.vue +128 -0
- package/frontend-vue/app/components/LegalLayout.vue +63 -0
- package/frontend-vue/app/components/LoadFailure.vue +25 -0
- package/frontend-vue/app/components/PastDueAlert.vue +96 -0
- package/frontend-vue/app/components/PaymentMethodCard.vue +86 -0
- package/frontend-vue/app/components/PlanCard.vue +294 -0
- package/frontend-vue/app/components/PlanCardPublic.vue +59 -0
- package/frontend-vue/app/components/PlanCardsDisplay.vue +127 -0
- package/frontend-vue/app/components/PlanComparisonModal.vue +213 -0
- package/frontend-vue/app/components/PlanInheritancePicker.vue +329 -0
- package/frontend-vue/app/components/PlatformNotes.vue +281 -0
- package/frontend-vue/app/components/PlatformSupport.vue +461 -0
- package/frontend-vue/app/components/RecentActivity.vue +72 -0
- package/frontend-vue/app/components/RefundButton.vue +126 -0
- package/frontend-vue/app/components/Register.vue +174 -0
- package/frontend-vue/app/components/RegistrationClosed.vue +15 -0
- package/frontend-vue/app/components/SeatQuotaBanner.vue +78 -0
- package/frontend-vue/app/components/SegmentConditionsBuilder.vue +176 -0
- package/frontend-vue/app/components/SegmentConditionsGroup.vue +494 -0
- package/frontend-vue/app/components/SupportAttachmentUpload.vue +140 -0
- package/frontend-vue/app/components/SupportThreadHistory.vue +139 -0
- package/frontend-vue/app/components/TenantBillingForm.vue +208 -0
- package/frontend-vue/app/components/TenantPlanCard.vue +223 -0
- package/frontend-vue/app/components/TenantSupport.vue +415 -0
- package/frontend-vue/app/components/UserSummaryCard.vue +166 -0
- package/frontend-vue/app/components/WorkspaceBillingInfo.vue +68 -0
- package/frontend-vue/app/components/WorkspaceCompAccessButton.vue +198 -0
- package/frontend-vue/app/components/WorkspaceCreateModal.vue +256 -0
- package/frontend-vue/app/components/WorkspaceDangerZone.vue +146 -0
- package/frontend-vue/app/components/WorkspaceDetailHeader.vue +24 -0
- package/frontend-vue/app/components/WorkspaceIdentity.vue +99 -0
- package/frontend-vue/app/components/WorkspaceJoinButton.vue +50 -0
- package/frontend-vue/app/components/WorkspaceOperatorActions.vue +340 -0
- package/frontend-vue/app/components/WorkspaceSummaryCard.vue +161 -0
- package/frontend-vue/app/components/WorkspaceSuspendButton.vue +167 -0
- package/frontend-vue/app/components/WorkspaceSuspended.vue +164 -0
- package/frontend-vue/app/components/WorkspaceSwitcherWidget.vue +247 -0
- package/frontend-vue/app/composables/useApiErrorMessage.ts +35 -0
- package/frontend-vue/app/composables/useBillingCountries.ts +54 -0
- package/frontend-vue/app/composables/useBillingDocumentType.ts +7 -0
- package/frontend-vue/app/composables/useBillingStatus.ts +39 -0
- package/frontend-vue/app/composables/useCurrentWorkspace.ts +43 -0
- package/frontend-vue/app/composables/useDetailRefresh.ts +17 -0
- package/frontend-vue/app/composables/useExportHistory.ts +143 -0
- package/frontend-vue/app/composables/useInvoiceLines.ts +22 -0
- package/frontend-vue/app/composables/useMoneyFormat.ts +49 -0
- package/frontend-vue/app/composables/useMyWorkspaces.ts +47 -0
- package/frontend-vue/app/composables/usePlanFeatureFormat.ts +60 -0
- package/frontend-vue/app/composables/usePlanIntervalLabel.ts +30 -0
- package/frontend-vue/app/composables/useSaasRegistration.ts +522 -0
- package/frontend-vue/app/composables/useSeatQuota.ts +18 -0
- package/frontend-vue/app/composables/useSharedRequest.ts +54 -0
- package/frontend-vue/app/composables/useStripePaymentElement.ts +74 -0
- package/frontend-vue/app/composables/useSubscriptionAccess.ts +12 -0
- package/frontend-vue/app/composables/useSupportRequest.ts +74 -0
- package/frontend-vue/app/composables/useTenantPlan.ts +95 -0
- package/frontend-vue/app/composables/useTenantSwitch.ts +22 -0
- package/frontend-vue/app/composables/useWorkspaceAccessCache.ts +25 -0
- package/frontend-vue/app/custom-pages/auth/no-workspace.vue +495 -0
- package/frontend-vue/app/middleware/workspace-suspended.global.ts +56 -0
- package/frontend-vue/app/plugins/auth-links.ts +24 -0
- package/frontend-vue/app/plugins/billing-data-types.ts +62 -0
- package/frontend-vue/app/plugins/footer-links.ts +36 -0
- package/frontend-vue/app/plugins/plan-cards-display.client.ts +16 -0
- package/frontend-vue/app/plugins/segment-conditions-data-type.client.ts +122 -0
- package/frontend-vue/app/plugins/sidebar-widgets.ts +13 -0
- package/frontend-vue/app/types/support.ts +123 -0
- package/frontend-vue/dms.frontend.ts +68 -0
- package/frontend-vue/eslint.config.mjs +13 -0
- package/frontend-vue/i18n/locales/saas-en-GB.json +1285 -0
- package/frontend-vue/i18n/locales/saas-fr-FR.json +1285 -0
- package/frontend-vue/package.json +27 -0
- package/frontend-vue/pnpm-lock.yaml +4948 -0
- package/frontend-vue/pnpm-workspace.yaml +2 -0
- package/frontend-vue/server/routes/auth/finalize-workspace.post.ts +61 -0
- package/package.json +91 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isFreePlan = isFreePlan;
|
|
4
|
+
exports.resolveMaxFreeWorkspacesPerCard = resolveMaxFreeWorkspacesPerCard;
|
|
5
|
+
exports.findFreeWorkspaceIdsBackedByCard = findFreeWorkspaceIdsBackedByCard;
|
|
6
|
+
exports.assertFreePlanAllowedForCard = assertFreePlanAllowedForCard;
|
|
7
|
+
exports.resolveFreePlanAvailability = resolveFreePlanAvailability;
|
|
8
|
+
exports.resolveFreePlanAvailabilityForUser = resolveFreePlanAvailabilityForUser;
|
|
9
|
+
const interface_api_util_1 = require("@antelopejs/interface-api-util");
|
|
10
|
+
const interface_database_1 = require("@antelopejs/interface-database");
|
|
11
|
+
const interface_database_decorators_1 = require("@antelopejs/interface-database-decorators");
|
|
12
|
+
const db_1 = require("@antelopejs/interface-dms/db");
|
|
13
|
+
const db_2 = require("../db");
|
|
14
|
+
const utils_1 = require("../utils");
|
|
15
|
+
const HTTP_CONFLICT = 409;
|
|
16
|
+
const FREE_PLAN_PRICE = 0;
|
|
17
|
+
function isFreePlan(plan) {
|
|
18
|
+
return plan.price <= FREE_PLAN_PRICE;
|
|
19
|
+
}
|
|
20
|
+
async function resolveMaxFreeWorkspacesPerCard() {
|
|
21
|
+
const settings = await (0, interface_database_decorators_1.GetModel)(db_2.BillingSettingsModel).get(db_2.BILLING_SETTINGS_SINGLETON_ID);
|
|
22
|
+
return (settings?.maxFreeWorkspacesPerCard ?? db_2.DEFAULT_MAX_FREE_WORKSPACES_PER_CARD);
|
|
23
|
+
}
|
|
24
|
+
async function keepFreeSubscriptions(subscriptions) {
|
|
25
|
+
const planIds = [
|
|
26
|
+
...new Set(subscriptions
|
|
27
|
+
.map((sub) => sub.planId)
|
|
28
|
+
.filter((planId) => !!planId)),
|
|
29
|
+
];
|
|
30
|
+
if (planIds.length === 0)
|
|
31
|
+
return [];
|
|
32
|
+
const planModel = (0, interface_database_decorators_1.GetModel)(db_2.PlanModel);
|
|
33
|
+
const plans = await Promise.all(planIds.map((planId) => planModel.get(planId)));
|
|
34
|
+
const freePlanIds = new Set(plans
|
|
35
|
+
.filter((plan) => !!plan && isFreePlan(plan))
|
|
36
|
+
.map((plan) => plan._id));
|
|
37
|
+
return subscriptions.filter((sub) => sub.planId && freePlanIds.has(sub.planId));
|
|
38
|
+
}
|
|
39
|
+
async function resolveWorkspaceNames(subscriptions) {
|
|
40
|
+
const tenantIds = subscriptions.map((sub) => (0, utils_1.getRowInstance)(sub));
|
|
41
|
+
const tenants = await (0, interface_database_decorators_1.GetModel)(db_1.TenantModel).getMany(tenantIds);
|
|
42
|
+
return tenants.map((tenant) => tenant.name);
|
|
43
|
+
}
|
|
44
|
+
async function findFreeWorkspacesBackedByCard(cardFingerprint) {
|
|
45
|
+
const subscriptions = await (0, interface_database_decorators_1.GetModel)(db_2.TenantSubscriptionModel, interface_database_1.CROSS_INSTANCE).findByCardFingerprint(cardFingerprint);
|
|
46
|
+
const freeSubscriptions = await keepFreeSubscriptions(subscriptions);
|
|
47
|
+
if (freeSubscriptions.length === 0)
|
|
48
|
+
return [];
|
|
49
|
+
return resolveWorkspaceNames(freeSubscriptions);
|
|
50
|
+
}
|
|
51
|
+
async function findFreeWorkspaceIdsBackedByCard(cardFingerprint) {
|
|
52
|
+
const subscriptions = await (0, interface_database_decorators_1.GetModel)(db_2.TenantSubscriptionModel, interface_database_1.CROSS_INSTANCE).findByCardFingerprint(cardFingerprint);
|
|
53
|
+
const freeSubscriptions = await keepFreeSubscriptions(subscriptions);
|
|
54
|
+
return [
|
|
55
|
+
...new Set(freeSubscriptions.map((subscription) => (0, utils_1.getRowInstance)(subscription))),
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
async function assertFreePlanAllowedForCard(plan, cardFingerprint) {
|
|
59
|
+
if (!isFreePlan(plan) || !cardFingerprint)
|
|
60
|
+
return;
|
|
61
|
+
const [limit, workspaceNames] = await Promise.all([
|
|
62
|
+
resolveMaxFreeWorkspacesPerCard(),
|
|
63
|
+
findFreeWorkspacesBackedByCard(cardFingerprint),
|
|
64
|
+
]);
|
|
65
|
+
(0, interface_api_util_1.assert)(workspaceNames.length < limit, HTTP_CONFLICT, "saas.errors.workspace.free_limit_reached");
|
|
66
|
+
}
|
|
67
|
+
async function collectUserCardFingerprints(userId) {
|
|
68
|
+
const memberships = await (0, interface_database_decorators_1.GetModel)(db_1.TenantMemberModel, interface_database_1.CROSS_INSTANCE).listByUserWithTenantIds(userId);
|
|
69
|
+
const subscriptions = await Promise.all(memberships.map((membership) => (0, interface_database_decorators_1.GetModel)(db_2.TenantSubscriptionModel, membership.tenantId).findOne()));
|
|
70
|
+
const fingerprints = subscriptions
|
|
71
|
+
.map((subscription) => subscription?.cardFingerprint)
|
|
72
|
+
.filter((fingerprint) => !!fingerprint);
|
|
73
|
+
return new Set(fingerprints);
|
|
74
|
+
}
|
|
75
|
+
function resolveFreePlanAvailability(freeWorkspaceNamesPerCard, limit) {
|
|
76
|
+
if (freeWorkspaceNamesPerCard.length === 0) {
|
|
77
|
+
return { isAvailable: true, blockingWorkspaceName: null };
|
|
78
|
+
}
|
|
79
|
+
const hasCardWithRoom = freeWorkspaceNamesPerCard.some((workspaceNames) => workspaceNames.length < limit);
|
|
80
|
+
if (hasCardWithRoom) {
|
|
81
|
+
return { isAvailable: true, blockingWorkspaceName: null };
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
isAvailable: false,
|
|
85
|
+
blockingWorkspaceName: freeWorkspaceNamesPerCard.flat()[0] ?? null,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
async function resolveFreePlanAvailabilityForUser(userId) {
|
|
89
|
+
const fingerprints = await collectUserCardFingerprints(userId);
|
|
90
|
+
const [limit, usages] = await Promise.all([
|
|
91
|
+
resolveMaxFreeWorkspacesPerCard(),
|
|
92
|
+
Promise.all([...fingerprints].map((fingerprint) => findFreeWorkspacesBackedByCard(fingerprint))),
|
|
93
|
+
]);
|
|
94
|
+
return resolveFreePlanAvailability(usages, limit);
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=free-workspace-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"free-workspace-guard.js","sourceRoot":"","sources":["../../src/workspaces/free-workspace-guard.ts"],"names":[],"mappings":";;AAsBA,gCAEC;AAED,0EAOC;AAgDD,4EAaC;AAOD,oEAcC;AAyBD,kEAiBC;AAED,gFAaC;AA5KD,uEAAwD;AACxD,uEAAgE;AAChE,6FAAqE;AACrE,qDAA8E;AAE9E,8BAMe;AACf,oCAA0C;AAE1C,MAAM,aAAa,GAA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CAAC;IACF,IAAI,eAAe,EAAE,CAAC;QACpB,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,qBAAqB,EAAE,IAAI,EAAE,CAAC;IAC5D,CAAC;IACD,OAAO;QACL,WAAW,EAAE,KAAK;QAClB,qBAAqB,EAAE,yBAAyB,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI;KACnE,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,kCAAkC,CACtD,MAAc;IAEd,MAAM,YAAY,GAAG,MAAM,2BAA2B,CAAC,MAAM,CAAC,CAAC;IAC/D,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACxC,+BAA+B,EAAE;QACjC,OAAO,CAAC,GAAG,CACT,CAAC,GAAG,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CACpC,8BAA8B,CAAC,WAAW,CAAC,CAC5C,CACF;KACF,CAAC,CAAC;IACH,OAAO,2BAA2B,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./billing-profile"), exports);
|
|
18
|
+
__exportStar(require("./deletion"), exports);
|
|
19
|
+
__exportStar(require("./free-workspace-guard"), exports);
|
|
20
|
+
__exportStar(require("./provisioning"), exports);
|
|
21
|
+
__exportStar(require("./registration-extras"), exports);
|
|
22
|
+
__exportStar(require("./suspension"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workspaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,6CAA2B;AAC3B,yDAAuC;AACvC,iDAA+B;AAC/B,wDAAsC;AACtC,+CAA6B"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rollbackWorkspaceProvisioning = rollbackWorkspaceProvisioning;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const logging_1 = require("@antelopejs/interface-core/logging");
|
|
6
|
+
const interface_database_decorators_1 = require("@antelopejs/interface-database-decorators");
|
|
7
|
+
const db_1 = require("@antelopejs/interface-dms/db");
|
|
8
|
+
const hooks_1 = require("@antelopejs/interface-dms/hooks");
|
|
9
|
+
const tenant_lifecycle_1 = require("@antelopejs/interface-dms/tenant-lifecycle");
|
|
10
|
+
const db_2 = require("../db");
|
|
11
|
+
const lifecycle_outbox_1 = require("../operator-actions/lifecycle-outbox");
|
|
12
|
+
const stripe_1 = require("../stripe");
|
|
13
|
+
const deletion_1 = require("./deletion");
|
|
14
|
+
const provisioning_state_1 = require("./provisioning-state");
|
|
15
|
+
async function rollbackWorkspaceProvisioning(handles) {
|
|
16
|
+
if (handles.mustPreserveWorkspace)
|
|
17
|
+
return;
|
|
18
|
+
handles.mustPreserveWorkspace = true;
|
|
19
|
+
try {
|
|
20
|
+
if (handles.tenantId)
|
|
21
|
+
await (0, tenant_lifecycle_1.closeTenantLifecycleAdmission)(handles.tenantId);
|
|
22
|
+
const finishCancellation = await admitRollbackCancellation(handles.tenantId);
|
|
23
|
+
if (handles.tenantId)
|
|
24
|
+
await (0, lifecycle_outbox_1.cancelWorkspaceCreated)(handles.tenantId);
|
|
25
|
+
const stripe = (0, stripe_1.getStripeClient)();
|
|
26
|
+
if (handles.stripeSubscriptionId)
|
|
27
|
+
await stripe.subscriptions.cancel(handles.stripeSubscriptionId);
|
|
28
|
+
if (handles.stripeCustomerId)
|
|
29
|
+
await stripe.customers.del(handles.stripeCustomerId);
|
|
30
|
+
const deletionOperationId = await finishCancellation();
|
|
31
|
+
if (handles.tenantId)
|
|
32
|
+
await deleteTenantRecords(handles.tenantId, deletionOperationId);
|
|
33
|
+
if (handles.trialConsumptionId)
|
|
34
|
+
await (0, interface_database_decorators_1.GetModel)(db_2.TrialConsumptionModel).delete(handles.trialConsumptionId);
|
|
35
|
+
if (handles.tenantId)
|
|
36
|
+
await (0, provisioning_state_1.recordProvisioningState)(handles, "cancelled");
|
|
37
|
+
handles.mustPreserveWorkspace = false;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
logging_1.Logging.Error(`[dms-saas:provisioning-rollback] ${handles.tenantId} requires reconciliation`, error);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function admitRollbackCancellation(tenantId) {
|
|
44
|
+
if (!tenantId)
|
|
45
|
+
return async () => undefined;
|
|
46
|
+
const model = (0, interface_database_decorators_1.GetModel)(db_2.TenantSubscriptionModel, tenantId);
|
|
47
|
+
const subscription = await model.findOne();
|
|
48
|
+
if (!subscription)
|
|
49
|
+
return async () => undefined;
|
|
50
|
+
const operationId = (0, node_crypto_1.randomUUID)();
|
|
51
|
+
await model.beginTransition(subscription, {
|
|
52
|
+
operationId,
|
|
53
|
+
kind: "cancel",
|
|
54
|
+
targetPlanId: null,
|
|
55
|
+
requestedAt: new Date(),
|
|
56
|
+
});
|
|
57
|
+
return async () => {
|
|
58
|
+
const deletionStartedAt = new Date();
|
|
59
|
+
await model.completeTransition(subscription._id, operationId, {
|
|
60
|
+
deletionStartedAt,
|
|
61
|
+
});
|
|
62
|
+
return (0, deletion_1.getWorkspaceDeletionOperationId)(tenantId, {
|
|
63
|
+
_id: subscription._id,
|
|
64
|
+
deletionStartedAt,
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
async function deleteTenantRecords(tenantId, deletionOperationId) {
|
|
69
|
+
const tenantSubscriptionModel = (0, interface_database_decorators_1.GetModel)(db_2.TenantSubscriptionModel, tenantId);
|
|
70
|
+
await (0, hooks_1.ExecuteHooks)(hooks_1.Hook.TENANT_DELETED, tenantId, {
|
|
71
|
+
operationId: deletionOperationId ?? `provisioning-cancel:${tenantId}`,
|
|
72
|
+
});
|
|
73
|
+
const tenantBillingInfoModel = (0, interface_database_decorators_1.GetModel)(db_2.TenantBillingInfoModel, tenantId);
|
|
74
|
+
await (0, interface_database_decorators_1.GetModel)(db_1.TenantModel).delete(tenantId);
|
|
75
|
+
await tenantBillingInfoModel.deleteAll();
|
|
76
|
+
await tenantSubscriptionModel.deleteAll();
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=provisioning-rollback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provisioning-rollback.js","sourceRoot":"","sources":["../../src/workspaces/provisioning-rollback.ts"],"names":[],"mappings":";;AAkBA,sEA6BC;AA/CD,6CAAyC;AACzC,gEAA6D;AAC7D,6FAAqE;AACrE,qDAA2D;AAC3D,2DAAqE;AACrE,iFAA2F;AAC3F,8BAIe;AACf,2EAA8E;AAC9E,sCAA4C;AAC5C,yCAA6D;AAE7D,6DAA+D;AAGxD,KAAK,UAAU,6BAA6B,CACjD,OAAqC;IAErC,IAAI,OAAO,CAAC,qBAAqB;QAAE,OAA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,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC7C,MAAM,sBAAsB,CAAC,SAAS,EAAE,CAAC;IACzC,MAAM,uBAAuB,CAAC,SAAS,EAAE,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Plan } from "../db";
|
|
2
|
+
import type { ProvisioningAttemptState } from "./db/provisioning-attempt.table";
|
|
3
|
+
import type { WorkspaceProvisioningHandles, WorkspaceProvisioningInput } from "./provisioning";
|
|
4
|
+
export declare function beginProvisioningAttempt(input: WorkspaceProvisioningInput, plan: Plan): Promise<void>;
|
|
5
|
+
export declare function recordProvisioningState(handles: WorkspaceProvisioningHandles, state?: ProvisioningAttemptState): Promise<void>;
|
|
6
|
+
export declare function reserveTrialIdentities(handles: WorkspaceProvisioningHandles, emailHash: string, fingerprint: string | null): Promise<boolean>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.beginProvisioningAttempt = beginProvisioningAttempt;
|
|
4
|
+
exports.recordProvisioningState = recordProvisioningState;
|
|
5
|
+
exports.reserveTrialIdentities = reserveTrialIdentities;
|
|
6
|
+
const node_crypto_1 = require("node:crypto");
|
|
7
|
+
const interface_api_util_1 = require("@antelopejs/interface-api-util");
|
|
8
|
+
const interface_database_decorators_1 = require("@antelopejs/interface-database-decorators");
|
|
9
|
+
const card_capacity_model_1 = require("./db/card-capacity.model");
|
|
10
|
+
const provisioning_attempt_model_1 = require("./db/provisioning-attempt.model");
|
|
11
|
+
const trial_identity_model_1 = require("./db/trial-identity.model");
|
|
12
|
+
const free_workspace_guard_1 = require("./free-workspace-guard");
|
|
13
|
+
const HTTP_CONFLICT = 409;
|
|
14
|
+
async function beginProvisioningAttempt(input, plan) {
|
|
15
|
+
const tenantId = (0, node_crypto_1.randomUUID)();
|
|
16
|
+
const fingerprint = input.card.fingerprint;
|
|
17
|
+
const capacityId = fingerprint && (0, free_workspace_guard_1.isFreePlan)(plan) ? (0, card_capacity_model_1.cardCapacityId)(fingerprint) : null;
|
|
18
|
+
input.handles.tenantId = tenantId;
|
|
19
|
+
input.handles.mustPreserveWorkspace = true;
|
|
20
|
+
await (0, interface_database_decorators_1.GetModel)(provisioning_attempt_model_1.ProvisioningAttemptModel).insert({
|
|
21
|
+
_id: tenantId,
|
|
22
|
+
revision: (0, node_crypto_1.randomUUID)(),
|
|
23
|
+
capacityId,
|
|
24
|
+
planId: plan._id,
|
|
25
|
+
userId: input.userId,
|
|
26
|
+
state: "preparing",
|
|
27
|
+
stripeCustomerId: null,
|
|
28
|
+
stripeSubscriptionId: null,
|
|
29
|
+
trialConsumptionId: null,
|
|
30
|
+
trialIdentityIds: [],
|
|
31
|
+
lastError: null,
|
|
32
|
+
});
|
|
33
|
+
if (capacityId && fingerprint) {
|
|
34
|
+
const admitted = await (0, interface_database_decorators_1.GetModel)(card_capacity_model_1.CardCapacityModel).reserve(capacityId, tenantId, await (0, free_workspace_guard_1.resolveMaxFreeWorkspacesPerCard)(), () => (0, free_workspace_guard_1.findFreeWorkspaceIdsBackedByCard)(fingerprint));
|
|
35
|
+
if (!admitted) {
|
|
36
|
+
await recordProvisioningState(input.handles, "cancelled");
|
|
37
|
+
input.handles.mustPreserveWorkspace = false;
|
|
38
|
+
}
|
|
39
|
+
(0, interface_api_util_1.assert)(admitted, HTTP_CONFLICT, "saas.errors.workspace.free_limit_reached");
|
|
40
|
+
}
|
|
41
|
+
input.handles.mustPreserveWorkspace = false;
|
|
42
|
+
}
|
|
43
|
+
async function recordProvisioningState(handles, state = "preparing") {
|
|
44
|
+
if (!handles.tenantId)
|
|
45
|
+
throw new Error("Provisioning identity is missing");
|
|
46
|
+
const model = (0, interface_database_decorators_1.GetModel)(provisioning_attempt_model_1.ProvisioningAttemptModel);
|
|
47
|
+
const current = await model.get(handles.tenantId);
|
|
48
|
+
if (!current)
|
|
49
|
+
throw new Error("Provisioning attempt is missing");
|
|
50
|
+
await model.advance(current, {
|
|
51
|
+
state,
|
|
52
|
+
stripeCustomerId: handles.stripeCustomerId ?? null,
|
|
53
|
+
stripeSubscriptionId: handles.stripeSubscriptionId ?? null,
|
|
54
|
+
trialConsumptionId: handles.trialConsumptionId ?? null,
|
|
55
|
+
trialIdentityIds: handles.trialIdentityIds ?? [],
|
|
56
|
+
});
|
|
57
|
+
if (state === "committed" && current.capacityId)
|
|
58
|
+
await (0, interface_database_decorators_1.GetModel)(card_capacity_model_1.CardCapacityModel).confirm(current.capacityId, current._id);
|
|
59
|
+
if (state === "cancelled") {
|
|
60
|
+
if (current.capacityId)
|
|
61
|
+
await (0, interface_database_decorators_1.GetModel)(card_capacity_model_1.CardCapacityModel).releaseCancelled(current.capacityId, current._id);
|
|
62
|
+
for (const id of current.trialIdentityIds)
|
|
63
|
+
await (0, interface_database_decorators_1.GetModel)(trial_identity_model_1.TrialIdentityModel).releaseUnused(id, current._id);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function reserveTrialIdentities(handles, emailHash, fingerprint) {
|
|
67
|
+
if (!handles.tenantId)
|
|
68
|
+
throw new Error("Provisioning identity is missing");
|
|
69
|
+
const model = (0, interface_database_decorators_1.GetModel)(trial_identity_model_1.TrialIdentityModel);
|
|
70
|
+
const ids = [(0, trial_identity_model_1.trialIdentityId)("email", emailHash)];
|
|
71
|
+
if (fingerprint)
|
|
72
|
+
ids.push((0, trial_identity_model_1.trialIdentityId)("card", fingerprint));
|
|
73
|
+
handles.trialIdentityIds = ids;
|
|
74
|
+
handles.mustPreserveWorkspace = true;
|
|
75
|
+
await recordProvisioningState(handles);
|
|
76
|
+
const reserved = [];
|
|
77
|
+
for (const id of ids) {
|
|
78
|
+
if (!(await model.reserve(id, handles.tenantId))) {
|
|
79
|
+
for (const owned of reserved)
|
|
80
|
+
await model.releaseUnused(owned, handles.tenantId);
|
|
81
|
+
handles.trialIdentityIds = [];
|
|
82
|
+
await recordProvisioningState(handles);
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
reserved.push(id);
|
|
86
|
+
}
|
|
87
|
+
handles.trialIdentityIds = reserved;
|
|
88
|
+
await recordProvisioningState(handles);
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=provisioning-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provisioning-state.js","sourceRoot":"","sources":["../../src/workspaces/provisioning-state.ts"],"names":[],"mappings":";;AAqBA,4DAqCC;AAGD,0DA0BC;AAGD,wDA0BC;AApHD,6CAAyC;AACzC,uEAAwD;AACxD,6FAAqE;AAErE,kEAA6E;AAC7E,gFAA2E;AAE3E,oEAAgF;AAChF,iEAIgC;AAMhC,MAAM,aAAa,GAAG,GAAG,CAAC;AAGnB,KAAK,UAAU,wBAAwB,CAC5C,KAAiC,EACjC,IAAU;IAEV,MAAM,QAAQ,GAAG,IAAA,wBAAU,GAAE,CAAC;IAC9B,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC;IAC3C,MAAM,UAAU,GACd,WAAW,IAAI,IAAA,iCAAU,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,oCAAc,EAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACvE,KAAK,CAAC,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAClC,KAAK,CAAC,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC;IAC3C,MAAM,IAAA,wCAAQ,EAAC,qDAAwB,CAAC,CAAC,MAAM,CAAC;QAC9C,GAAG,EAAE,QAAQ;QACb,QAAQ,EAAE,IAAA,wBAAU,GAAE;QACtB,UAAU;QACV,MAAM,EAAE,IAAI,CAAC,GAAG;QAChB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE,WAAW;QAClB,gBAAgB,EAAE,IAAI;QACtB,oBAAoB,EAAE,IAAI;QAC1B,kBAAkB,EAAE,IAA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AE,IAAI,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;YACjD,KAAK,MAAM,KAAK,IAAI,QAAQ;gBAC1B,MAAM,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;YACrD,OAAO,CAAC,gBAAgB,GAAG,EAAE,CAAC;YAC9B,MAAM,uBAAuB,CAAC,OAAO,CAAC,CAAC;YACvC,OAAO,KAAK,CAAC;QACf,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,CAAC,gBAAgB,GAAG,QAAQ,CAAC;IACpC,MAAM,uBAAuB,CAAC,OAAO,CAAC,CAAC;IACvC,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Plan, TenantBillingAddress } from "../db";
|
|
2
|
+
export { rollbackWorkspaceProvisioning } from "./provisioning-rollback";
|
|
3
|
+
export type WorkspaceCustomerType = "individual" | "business";
|
|
4
|
+
export type WorkspaceAddressInput = Partial<Record<keyof TenantBillingAddress, string>>;
|
|
5
|
+
export interface WorkspaceBillingProfile {
|
|
6
|
+
customerType: WorkspaceCustomerType;
|
|
7
|
+
companyName?: string;
|
|
8
|
+
vatNumber?: string;
|
|
9
|
+
address?: WorkspaceAddressInput;
|
|
10
|
+
}
|
|
11
|
+
export interface WorkspaceProvisioningPayload extends WorkspaceBillingProfile {
|
|
12
|
+
workspaceName: string;
|
|
13
|
+
planId: string;
|
|
14
|
+
paymentMethodId: string;
|
|
15
|
+
extras?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
export interface StripeCustomerProfile extends WorkspaceBillingProfile {
|
|
18
|
+
email: string;
|
|
19
|
+
fallbackName: string;
|
|
20
|
+
paymentMethodId: string;
|
|
21
|
+
}
|
|
22
|
+
export interface WorkspaceProvisioningHandles {
|
|
23
|
+
mustPreserveWorkspace?: boolean;
|
|
24
|
+
userId?: string;
|
|
25
|
+
tenantId?: string;
|
|
26
|
+
stripeCustomerId?: string;
|
|
27
|
+
stripeSubscriptionId?: string;
|
|
28
|
+
trialConsumptionId?: string;
|
|
29
|
+
trialIdentityIds?: string[];
|
|
30
|
+
}
|
|
31
|
+
export interface CardDetails {
|
|
32
|
+
fingerprint: string | null;
|
|
33
|
+
billingAddress: WorkspaceAddressInput | undefined;
|
|
34
|
+
}
|
|
35
|
+
export interface WorkspaceProvisioningInput {
|
|
36
|
+
userId: string;
|
|
37
|
+
payload: WorkspaceProvisioningPayload;
|
|
38
|
+
stripeCustomerProfile: StripeCustomerProfile;
|
|
39
|
+
card: CardDetails;
|
|
40
|
+
handles: WorkspaceProvisioningHandles;
|
|
41
|
+
}
|
|
42
|
+
export interface ProvisionedWorkspace {
|
|
43
|
+
tenantId: string;
|
|
44
|
+
isTrialing: boolean;
|
|
45
|
+
}
|
|
46
|
+
export declare function assertBillingCountry(address: WorkspaceAddressInput | undefined): void;
|
|
47
|
+
export declare function ensurePlanIsAvailableForCustomer(planId: string, customerType: WorkspaceCustomerType): Promise<Plan>;
|
|
48
|
+
export declare function resolveCardDetails(paymentMethodId: string): Promise<CardDetails>;
|
|
49
|
+
export declare function provisionWorkspace(input: WorkspaceProvisioningInput): Promise<ProvisionedWorkspace>;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rollbackWorkspaceProvisioning = void 0;
|
|
4
|
+
exports.assertBillingCountry = assertBillingCountry;
|
|
5
|
+
exports.ensurePlanIsAvailableForCustomer = ensurePlanIsAvailableForCustomer;
|
|
6
|
+
exports.resolveCardDetails = resolveCardDetails;
|
|
7
|
+
exports.provisionWorkspace = provisionWorkspace;
|
|
8
|
+
const interface_api_util_1 = require("@antelopejs/interface-api-util");
|
|
9
|
+
const interface_database_decorators_1 = require("@antelopejs/interface-database-decorators");
|
|
10
|
+
const db_1 = require("@antelopejs/interface-dms/db");
|
|
11
|
+
const tenant_ownership_1 = require("@antelopejs/interface-dms/tenant-ownership");
|
|
12
|
+
const tenant_lifecycle_1 = require("@antelopejs/interface-dms/tenant-lifecycle");
|
|
13
|
+
const db_2 = require("@antelopejs/interface-dms/auth/db");
|
|
14
|
+
const billing_state_1 = require("../billing-state");
|
|
15
|
+
const db_3 = require("../db");
|
|
16
|
+
const tenant_provisioning_1 = require("../hooks/tenant-provisioning");
|
|
17
|
+
const lifecycle_outbox_1 = require("../operator-actions/lifecycle-outbox");
|
|
18
|
+
const stripe_1 = require("../stripe");
|
|
19
|
+
const utils_1 = require("../utils");
|
|
20
|
+
const provisioning_state_1 = require("./provisioning-state");
|
|
21
|
+
var provisioning_rollback_1 = require("./provisioning-rollback");
|
|
22
|
+
Object.defineProperty(exports, "rollbackWorkspaceProvisioning", { enumerable: true, get: function () { return provisioning_rollback_1.rollbackWorkspaceProvisioning; } });
|
|
23
|
+
const HTTP_BAD_REQUEST = 400;
|
|
24
|
+
const HTTP_NOT_FOUND = 404;
|
|
25
|
+
const ACTIVE_STATUS = "active";
|
|
26
|
+
const TRIALING_STATUS = "trialing";
|
|
27
|
+
const SEAT_BILLING_INITIAL_QUANTITY = 1;
|
|
28
|
+
function assertBillingCountry(address) {
|
|
29
|
+
(0, interface_api_util_1.assert)(address?.country, HTTP_BAD_REQUEST, "saas.errors.billing.country_required");
|
|
30
|
+
}
|
|
31
|
+
async function ensurePlanIsAvailableForCustomer(planId, customerType) {
|
|
32
|
+
const plan = await (0, interface_database_decorators_1.GetModel)(db_3.PlanModel).get(planId);
|
|
33
|
+
(0, interface_api_util_1.assert)(plan && !plan.isDeleted && plan.isActive, HTTP_NOT_FOUND, "saas.errors.plan.not_available");
|
|
34
|
+
(0, interface_api_util_1.assert)(plan.audience === "any" || plan.audience === customerType, HTTP_BAD_REQUEST, "saas.errors.plan.not_available_for_customer_type");
|
|
35
|
+
return plan;
|
|
36
|
+
}
|
|
37
|
+
async function resolveCardDetails(paymentMethodId) {
|
|
38
|
+
const stripe = (0, stripe_1.getStripeClient)();
|
|
39
|
+
const paymentMethod = await stripe.paymentMethods.retrieve(paymentMethodId);
|
|
40
|
+
const address = paymentMethod.billing_details?.address;
|
|
41
|
+
return {
|
|
42
|
+
fingerprint: paymentMethod.card?.fingerprint ?? null,
|
|
43
|
+
billingAddress: address
|
|
44
|
+
? {
|
|
45
|
+
line1: address.line1 ?? undefined,
|
|
46
|
+
line2: address.line2 ?? undefined,
|
|
47
|
+
postalCode: address.postal_code ?? undefined,
|
|
48
|
+
city: address.city ?? undefined,
|
|
49
|
+
state: address.state ?? undefined,
|
|
50
|
+
country: address.country ?? undefined,
|
|
51
|
+
}
|
|
52
|
+
: undefined,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
async function createStripeCustomer(profile, handles) {
|
|
56
|
+
const stripe = (0, stripe_1.getStripeClient)();
|
|
57
|
+
const metadata = {
|
|
58
|
+
customerType: profile.customerType,
|
|
59
|
+
};
|
|
60
|
+
if (profile.vatNumber)
|
|
61
|
+
metadata.vatNumber = profile.vatNumber;
|
|
62
|
+
handles.mustPreserveWorkspace = true;
|
|
63
|
+
const customer = await stripe.customers.create({
|
|
64
|
+
email: profile.email,
|
|
65
|
+
name: profile.customerType === "business"
|
|
66
|
+
? profile.companyName
|
|
67
|
+
: profile.fallbackName,
|
|
68
|
+
address: (0, stripe_1.toStripeAddress)(profile.address),
|
|
69
|
+
metadata: { ...metadata, provisioningAttempt: handles.tenantId ?? "" },
|
|
70
|
+
}, { idempotencyKey: `provisioning-customer:${handles.tenantId}` });
|
|
71
|
+
handles.stripeCustomerId = customer.id;
|
|
72
|
+
await (0, provisioning_state_1.recordProvisioningState)(handles);
|
|
73
|
+
await stripe.paymentMethods.attach(profile.paymentMethodId, {
|
|
74
|
+
customer: customer.id,
|
|
75
|
+
});
|
|
76
|
+
await stripe.customers.update(customer.id, {
|
|
77
|
+
invoice_settings: { default_payment_method: profile.paymentMethodId },
|
|
78
|
+
});
|
|
79
|
+
await (0, stripe_1.reconcileStripeTaxId)(customer.id, {
|
|
80
|
+
customerType: profile.customerType,
|
|
81
|
+
vatNumber: profile.vatNumber,
|
|
82
|
+
address: profile.address,
|
|
83
|
+
});
|
|
84
|
+
handles.mustPreserveWorkspace = false;
|
|
85
|
+
return customer.id;
|
|
86
|
+
}
|
|
87
|
+
function buildSubscriptionCreateParams(stripeCustomerId, stripePriceId, plan, grantTrial) {
|
|
88
|
+
const quantity = plan.billingMode === "seat" ? SEAT_BILLING_INITIAL_QUANTITY : undefined;
|
|
89
|
+
return {
|
|
90
|
+
customer: stripeCustomerId,
|
|
91
|
+
items: [{ price: stripePriceId, quantity }],
|
|
92
|
+
trial_period_days: grantTrial ? plan.trialDays : undefined,
|
|
93
|
+
automatic_tax: { enabled: true },
|
|
94
|
+
payment_behavior: "default_incomplete",
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
async function resolveTrialGrant(trialDays, emailHash, cardFingerprint, handles) {
|
|
98
|
+
if (trialDays <= 0)
|
|
99
|
+
return false;
|
|
100
|
+
const alreadyConsumed = await (0, interface_database_decorators_1.GetModel)(db_3.TrialConsumptionModel).existsForIdentity(emailHash, cardFingerprint);
|
|
101
|
+
return (!alreadyConsumed &&
|
|
102
|
+
(0, provisioning_state_1.reserveTrialIdentities)(handles, emailHash, cardFingerprint));
|
|
103
|
+
}
|
|
104
|
+
async function recordTrialConsumption(userId, emailHash, cardFingerprint, planId) {
|
|
105
|
+
const inserted = await (0, interface_database_decorators_1.GetModel)(db_3.TrialConsumptionModel).insert([
|
|
106
|
+
{
|
|
107
|
+
userId,
|
|
108
|
+
emailHash,
|
|
109
|
+
paymentFingerprint: cardFingerprint,
|
|
110
|
+
planId,
|
|
111
|
+
consumedAt: new Date(),
|
|
112
|
+
},
|
|
113
|
+
]);
|
|
114
|
+
return inserted[0];
|
|
115
|
+
}
|
|
116
|
+
async function createSubscription(input) {
|
|
117
|
+
const { plan, handles } = input;
|
|
118
|
+
(0, interface_api_util_1.assert)(plan.paymentProviderRefs?.stripePriceId, HTTP_BAD_REQUEST, "saas.errors.plan.not_synced_with_stripe");
|
|
119
|
+
const emailHash = (0, utils_1.hashEmail)(input.email);
|
|
120
|
+
const grantTrial = await resolveTrialGrant(plan.trialDays, emailHash, input.cardFingerprint, handles);
|
|
121
|
+
handles.mustPreserveWorkspace = true;
|
|
122
|
+
const subscription = await (0, stripe_1.getStripeClient)().subscriptions.create(buildSubscriptionCreateParams(input.stripeCustomerId, plan.paymentProviderRefs.stripePriceId, plan, grantTrial), { idempotencyKey: `provisioning-subscription:${handles.tenantId}` });
|
|
123
|
+
handles.stripeSubscriptionId = subscription.id;
|
|
124
|
+
await (0, provisioning_state_1.recordProvisioningState)(handles);
|
|
125
|
+
if (grantTrial) {
|
|
126
|
+
handles.trialConsumptionId = await recordTrialConsumption(input.userId, emailHash, input.cardFingerprint, plan._id);
|
|
127
|
+
await (0, provisioning_state_1.recordProvisioningState)(handles);
|
|
128
|
+
}
|
|
129
|
+
handles.mustPreserveWorkspace = false;
|
|
130
|
+
return {
|
|
131
|
+
stripeSubscriptionId: subscription.id,
|
|
132
|
+
isTrialing: grantTrial,
|
|
133
|
+
currentPeriodEnd: (0, utils_1.stripeSecondsToDate)(subscription.current_period_end),
|
|
134
|
+
latestInvoiceId: typeof subscription.latest_invoice === "string"
|
|
135
|
+
? subscription.latest_invoice
|
|
136
|
+
: (subscription.latest_invoice?.id ?? null),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
async function settleSubscriptionPayment(subscription, tenantId, handles) {
|
|
140
|
+
const invoiceId = subscription.isTrialing
|
|
141
|
+
? null
|
|
142
|
+
: subscription.latestInvoiceId;
|
|
143
|
+
handles.mustPreserveWorkspace = true;
|
|
144
|
+
await (0, provisioning_state_1.recordProvisioningState)(handles, "awaiting_payment");
|
|
145
|
+
await (0, lifecycle_outbox_1.prepareWorkspaceCreated)(tenantId, invoiceId);
|
|
146
|
+
if (!invoiceId)
|
|
147
|
+
return;
|
|
148
|
+
try {
|
|
149
|
+
const invoice = await (0, stripe_1.getStripeClient)().invoices.retrieve(invoiceId);
|
|
150
|
+
if (invoice.status === "paid")
|
|
151
|
+
return;
|
|
152
|
+
await (0, stripe_1.getStripeClient)().invoices.pay(invoiceId, { off_session: true }, {
|
|
153
|
+
idempotencyKey: `workspace-created:${tenantId}`,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
if (error instanceof Error &&
|
|
158
|
+
"type" in error &&
|
|
159
|
+
error.type === "StripeCardError") {
|
|
160
|
+
await (0, lifecycle_outbox_1.cancelWorkspaceCreated)(tenantId);
|
|
161
|
+
handles.mustPreserveWorkspace = false;
|
|
162
|
+
}
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async function insertTenantRecords(input) {
|
|
167
|
+
const { tenantId, payload, subscription } = input;
|
|
168
|
+
const tenantSubscriptionModel = (0, interface_database_decorators_1.GetModel)(db_3.TenantSubscriptionModel, tenantId);
|
|
169
|
+
const tenantBillingInfoModel = (0, interface_database_decorators_1.GetModel)(db_3.TenantBillingInfoModel, tenantId);
|
|
170
|
+
await tenantSubscriptionModel.insert([
|
|
171
|
+
{
|
|
172
|
+
planId: payload.planId,
|
|
173
|
+
status: subscription.isTrialing ? TRIALING_STATUS : ACTIVE_STATUS,
|
|
174
|
+
stripeCustomerId: input.stripeCustomerId,
|
|
175
|
+
stripeSubscriptionId: subscription.stripeSubscriptionId,
|
|
176
|
+
currentPeriodEnd: subscription.currentPeriodEnd,
|
|
177
|
+
cardFingerprint: input.cardFingerprint,
|
|
178
|
+
createdBy: input.userId,
|
|
179
|
+
createdAt: new Date(),
|
|
180
|
+
updatedAt: new Date(),
|
|
181
|
+
},
|
|
182
|
+
]);
|
|
183
|
+
await tenantBillingInfoModel.insert([
|
|
184
|
+
{
|
|
185
|
+
customerType: payload.customerType,
|
|
186
|
+
companyName: payload.companyName ?? null,
|
|
187
|
+
vatNumber: payload.vatNumber ?? null,
|
|
188
|
+
billingEmail: input.billingEmail,
|
|
189
|
+
address: (0, stripe_1.toTenantBillingAddress)(payload.address),
|
|
190
|
+
updatedAt: new Date(),
|
|
191
|
+
},
|
|
192
|
+
]);
|
|
193
|
+
await (0, billing_state_1.recomputeTenantBillingState)(tenantId);
|
|
194
|
+
}
|
|
195
|
+
async function createOwnedTenant(workspaceName, userId, handles) {
|
|
196
|
+
const tenantId = handles.tenantId;
|
|
197
|
+
if (!tenantId)
|
|
198
|
+
throw new Error("Provisioning intent must precede tenant creation");
|
|
199
|
+
return (0, tenant_lifecycle_1.runTenantLifecycleOperation)(tenantId, async () => {
|
|
200
|
+
await (0, lifecycle_outbox_1.beginWorkspaceCreation)(tenantId);
|
|
201
|
+
await (0, interface_database_decorators_1.GetModel)(db_1.TenantModel).insert([
|
|
202
|
+
{
|
|
203
|
+
_id: tenantId,
|
|
204
|
+
name: workspaceName,
|
|
205
|
+
createdAt: new Date(),
|
|
206
|
+
updatedAt: new Date(),
|
|
207
|
+
},
|
|
208
|
+
]);
|
|
209
|
+
await (0, tenant_ownership_1.applyTenantOwnership)((0, interface_database_decorators_1.GetModel)(db_2.UserModel), userId, tenantId, {
|
|
210
|
+
roleIds: [],
|
|
211
|
+
isTenantOwner: true,
|
|
212
|
+
});
|
|
213
|
+
return tenantId;
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
async function provisionWorkspace(input) {
|
|
217
|
+
const plan = await (0, interface_database_decorators_1.GetModel)(db_3.PlanModel).get(input.payload.planId);
|
|
218
|
+
(0, interface_api_util_1.assert)(plan, HTTP_NOT_FOUND, "saas.errors.plan.not_available");
|
|
219
|
+
await (0, provisioning_state_1.beginProvisioningAttempt)(input, plan);
|
|
220
|
+
try {
|
|
221
|
+
const provisioned = await runProvisioning(input);
|
|
222
|
+
await (0, provisioning_state_1.recordProvisioningState)(input.handles, "committed");
|
|
223
|
+
return provisioned;
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
await (0, provisioning_state_1.recordProvisioningState)(input.handles, "reconciliation_required").catch(() => { });
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
async function runProvisioning(input) {
|
|
231
|
+
const { userId, payload, stripeCustomerProfile, card, handles } = input;
|
|
232
|
+
const plan = await (0, interface_database_decorators_1.GetModel)(db_3.PlanModel).get(payload.planId);
|
|
233
|
+
(0, interface_api_util_1.assert)(plan, HTTP_NOT_FOUND, "saas.errors.plan.not_available");
|
|
234
|
+
const stripeCustomerId = await createStripeCustomer(stripeCustomerProfile, handles);
|
|
235
|
+
const subscription = await createSubscription({
|
|
236
|
+
stripeCustomerId,
|
|
237
|
+
plan,
|
|
238
|
+
userId,
|
|
239
|
+
email: stripeCustomerProfile.email,
|
|
240
|
+
cardFingerprint: card.fingerprint,
|
|
241
|
+
handles,
|
|
242
|
+
});
|
|
243
|
+
handles.stripeSubscriptionId = subscription.stripeSubscriptionId;
|
|
244
|
+
const tenantId = await createOwnedTenant(payload.workspaceName, userId, handles);
|
|
245
|
+
await (0, tenant_lifecycle_1.runTenantLifecycleOperation)(tenantId, () => insertTenantRecords({
|
|
246
|
+
tenantId,
|
|
247
|
+
userId,
|
|
248
|
+
payload,
|
|
249
|
+
stripeCustomerId,
|
|
250
|
+
cardFingerprint: card.fingerprint,
|
|
251
|
+
subscription,
|
|
252
|
+
billingEmail: stripeCustomerProfile.email,
|
|
253
|
+
}));
|
|
254
|
+
await (0, tenant_provisioning_1.emitTenantBeingProvisioned)({
|
|
255
|
+
tenantId,
|
|
256
|
+
userId,
|
|
257
|
+
extras: payload.extras,
|
|
258
|
+
});
|
|
259
|
+
await settleSubscriptionPayment(subscription, tenantId, handles);
|
|
260
|
+
await (0, lifecycle_outbox_1.deliverWorkspaceCreated)(tenantId);
|
|
261
|
+
return { tenantId, isTrialing: subscription.isTrialing };
|
|
262
|
+
}
|
|
263
|
+
//# sourceMappingURL=provisioning.js.map
|