@antelopejs/dms-saas 0.2.0 → 0.3.0

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.
Files changed (195) hide show
  1. package/README.md +307 -33
  2. package/dist/billing-state/index.d.ts +1 -0
  3. package/dist/billing-state/index.js +1 -0
  4. package/dist/billing-state/index.js.map +1 -1
  5. package/dist/billing-state/past-due-banner.d.ts +4 -0
  6. package/dist/billing-state/past-due-banner.js +25 -0
  7. package/dist/billing-state/past-due-banner.js.map +1 -0
  8. package/dist/config/runtime.d.ts +6 -1
  9. package/dist/config/runtime.js +50 -1
  10. package/dist/config/runtime.js.map +1 -1
  11. package/dist/crons/recompute-billing-state.js +4 -1
  12. package/dist/crons/recompute-billing-state.js.map +1 -1
  13. package/dist/data-api/platformOwner/index.d.ts +1 -0
  14. package/dist/data-api/platformOwner/index.js +1 -0
  15. package/dist/data-api/platformOwner/index.js.map +1 -1
  16. package/dist/data-api/platformOwner/invitations.d.ts +22 -0
  17. package/dist/data-api/platformOwner/invitations.js +121 -0
  18. package/dist/data-api/platformOwner/invitations.js.map +1 -0
  19. package/dist/data-api/platformOwner/invoice-options.js +3 -2
  20. package/dist/data-api/platformOwner/invoice-options.js.map +1 -1
  21. package/dist/data-api/platformOwner/workspaces.d.ts +3 -0
  22. package/dist/data-api/platformOwner/workspaces.js +64 -12
  23. package/dist/data-api/platformOwner/workspaces.js.map +1 -1
  24. package/dist/data-api/tenant/tenant-invoices.js +2 -10
  25. package/dist/data-api/tenant/tenant-invoices.js.map +1 -1
  26. package/dist/hooks/register.js +2 -1
  27. package/dist/hooks/register.js.map +1 -1
  28. package/dist/implementations/dms-saas/billing.d.ts +2 -1
  29. package/dist/implementations/dms-saas/billing.js +6 -0
  30. package/dist/implementations/dms-saas/billing.js.map +1 -1
  31. package/dist/index.js +5 -0
  32. package/dist/index.js.map +1 -1
  33. package/dist/invoice-line-items/billing-window.js +2 -2
  34. package/dist/invoice-line-items/billing-window.js.map +1 -1
  35. package/dist/invoice-line-items/injection.d.ts +10 -0
  36. package/dist/invoice-line-items/injection.js +7 -3
  37. package/dist/invoice-line-items/injection.js.map +1 -1
  38. package/dist/operator-actions/db/lifecycle-delivery.model.js +1 -3
  39. package/dist/operator-actions/db/lifecycle-delivery.model.js.map +1 -1
  40. package/dist/operator-actions/db/lifecycle-delivery.table.d.ts +1 -1
  41. package/dist/operator-actions/db/lifecycle-delivery.table.js.map +1 -1
  42. package/dist/operator-actions/db/operator-action.model.js +1 -3
  43. package/dist/operator-actions/db/operator-action.model.js.map +1 -1
  44. package/dist/operator-actions/db/operator-action.table.d.ts +1 -1
  45. package/dist/operator-actions/db/operator-action.table.js.map +1 -1
  46. package/dist/operator-actions/index.d.ts +1 -0
  47. package/dist/operator-actions/index.js +1 -0
  48. package/dist/operator-actions/index.js.map +1 -1
  49. package/dist/operator-actions/invitation-commands.d.ts +12 -0
  50. package/dist/operator-actions/invitation-commands.js +46 -0
  51. package/dist/operator-actions/invitation-commands.js.map +1 -0
  52. package/dist/operator-actions/types.d.ts +1 -1
  53. package/dist/pages/platform/dashboard.js +2 -4
  54. package/dist/pages/platform/dashboard.js.map +1 -1
  55. package/dist/pages/platform/workspaces/detail.js +40 -1
  56. package/dist/pages/platform/workspaces/detail.js.map +1 -1
  57. package/dist/pages/platform/workspaces/index.d.ts +2 -8
  58. package/dist/pages/platform/workspaces/index.js +27 -111
  59. package/dist/pages/platform/workspaces/index.js.map +1 -1
  60. package/dist/pages/public/legal/privacy-policy.js +2 -1
  61. package/dist/pages/public/legal/privacy-policy.js.map +1 -1
  62. package/dist/pages/public/legal/terms-and-conditions.js +2 -1
  63. package/dist/pages/public/legal/terms-and-conditions.js.map +1 -1
  64. package/dist/pages/public/legal/terms-of-use.js +2 -1
  65. package/dist/pages/public/legal/terms-of-use.js.map +1 -1
  66. package/dist/plans/index.d.ts +1 -0
  67. package/dist/plans/index.js +1 -0
  68. package/dist/plans/index.js.map +1 -1
  69. package/dist/plans/platform-support.d.ts +2 -0
  70. package/dist/plans/platform-support.js +19 -0
  71. package/dist/plans/platform-support.js.map +1 -0
  72. package/dist/plans/seat-capacity.d.ts +9 -2
  73. package/dist/plans/seat-capacity.js +59 -12
  74. package/dist/plans/seat-capacity.js.map +1 -1
  75. package/dist/plans/seat-hooks.js +34 -13
  76. package/dist/plans/seat-hooks.js.map +1 -1
  77. package/dist/routes/platformOwner/credit-notes-issue.js +2 -1
  78. package/dist/routes/platformOwner/credit-notes-issue.js.map +1 -1
  79. package/dist/routes/platformOwner/dashboard.d.ts +8 -6
  80. package/dist/routes/platformOwner/dashboard.js +31 -17
  81. package/dist/routes/platformOwner/dashboard.js.map +1 -1
  82. package/dist/routes/platformOwner/index.d.ts +1 -0
  83. package/dist/routes/platformOwner/index.js +1 -0
  84. package/dist/routes/platformOwner/index.js.map +1 -1
  85. package/dist/routes/platformOwner/workspace-invitations.d.ts +13 -0
  86. package/dist/routes/platformOwner/workspace-invitations.js +73 -0
  87. package/dist/routes/platformOwner/workspace-invitations.js.map +1 -0
  88. package/dist/routes/public/register.d.ts +7 -3
  89. package/dist/routes/public/register.js +42 -27
  90. package/dist/routes/public/register.js.map +1 -1
  91. package/dist/routes/tenant/tenant-billing.d.ts +7 -11
  92. package/dist/routes/tenant/tenant-billing.js +34 -26
  93. package/dist/routes/tenant/tenant-billing.js.map +1 -1
  94. package/dist/routes/tenant/tenant-plan-ops.js +2 -2
  95. package/dist/routes/tenant/tenant-plan-ops.js.map +1 -1
  96. package/dist/routes/tenant/tenant-plan.d.ts +1 -0
  97. package/dist/routes/tenant/tenant-plan.js +27 -2
  98. package/dist/routes/tenant/tenant-plan.js.map +1 -1
  99. package/dist/routes/tenant/tenant-seats.d.ts +2 -4
  100. package/dist/routes/tenant/tenant-seats.js.map +1 -1
  101. package/dist/routes/tenant/workspaces.d.ts +2 -0
  102. package/dist/routes/tenant/workspaces.js +10 -4
  103. package/dist/routes/tenant/workspaces.js.map +1 -1
  104. package/dist/stripe/upcoming-invoice.d.ts +21 -0
  105. package/dist/stripe/upcoming-invoice.js +42 -0
  106. package/dist/stripe/upcoming-invoice.js.map +1 -0
  107. package/dist/stripe/webhook-dispatch.js +2 -0
  108. package/dist/stripe/webhook-dispatch.js.map +1 -1
  109. package/dist/types/config.d.ts +9 -0
  110. package/dist/types/config.js +7 -0
  111. package/dist/types/config.js.map +1 -1
  112. package/dist/upcoming-invoice/db/preview-cache.model.d.ts +38 -0
  113. package/dist/upcoming-invoice/db/preview-cache.model.js +57 -0
  114. package/dist/upcoming-invoice/db/preview-cache.model.js.map +1 -0
  115. package/dist/upcoming-invoice/db/preview-cache.table.d.ts +10 -0
  116. package/dist/upcoming-invoice/db/preview-cache.table.js +42 -0
  117. package/dist/upcoming-invoice/db/preview-cache.table.js.map +1 -0
  118. package/dist/upcoming-invoice/eligibility.d.ts +17 -0
  119. package/dist/upcoming-invoice/eligibility.js +52 -0
  120. package/dist/upcoming-invoice/eligibility.js.map +1 -0
  121. package/dist/upcoming-invoice/invalidation.d.ts +2 -0
  122. package/dist/upcoming-invoice/invalidation.js +39 -0
  123. package/dist/upcoming-invoice/invalidation.js.map +1 -0
  124. package/dist/upcoming-invoice/mapping.d.ts +8 -0
  125. package/dist/upcoming-invoice/mapping.js +82 -0
  126. package/dist/upcoming-invoice/mapping.js.map +1 -0
  127. package/dist/upcoming-invoice/outcomes.d.ts +13 -0
  128. package/dist/upcoming-invoice/outcomes.js +15 -0
  129. package/dist/upcoming-invoice/outcomes.js.map +1 -0
  130. package/dist/upcoming-invoice/preview.d.ts +3 -0
  131. package/dist/upcoming-invoice/preview.js +80 -0
  132. package/dist/upcoming-invoice/preview.js.map +1 -0
  133. package/dist/upcoming-invoice/pricing.d.ts +3 -0
  134. package/dist/upcoming-invoice/pricing.js +84 -0
  135. package/dist/upcoming-invoice/pricing.js.map +1 -0
  136. package/dist/upcoming-invoice/usage.d.ts +14 -0
  137. package/dist/upcoming-invoice/usage.js +53 -0
  138. package/dist/upcoming-invoice/usage.js.map +1 -0
  139. package/dist/workspaces/billing-identity.d.ts +19 -0
  140. package/dist/workspaces/billing-identity.js +51 -0
  141. package/dist/workspaces/billing-identity.js.map +1 -0
  142. package/dist/workspaces/default-plan.d.ts +5 -0
  143. package/dist/workspaces/default-plan.js +110 -0
  144. package/dist/workspaces/default-plan.js.map +1 -0
  145. package/dist/workspaces/index.d.ts +2 -0
  146. package/dist/workspaces/index.js +2 -0
  147. package/dist/workspaces/index.js.map +1 -1
  148. package/dist/workspaces/invitations.d.ts +26 -0
  149. package/dist/workspaces/invitations.js +112 -0
  150. package/dist/workspaces/invitations.js.map +1 -0
  151. package/dist/workspaces/provisioning.d.ts +3 -3
  152. package/dist/workspaces/provisioning.js +49 -11
  153. package/dist/workspaces/provisioning.js.map +1 -1
  154. package/frontend-vue/app/components/BillingIdentityFields.vue +179 -0
  155. package/frontend-vue/app/components/PastDueBanner.vue +81 -0
  156. package/frontend-vue/app/components/PaymentMethodCard.vue +94 -38
  157. package/frontend-vue/app/components/PlanComparisonModal.vue +62 -26
  158. package/frontend-vue/app/components/PlanUpgradeModal.vue +181 -0
  159. package/frontend-vue/app/components/PlatformNotes.vue +4 -0
  160. package/frontend-vue/app/components/RefundButton.vue +10 -1
  161. package/frontend-vue/app/components/Register.vue +49 -92
  162. package/frontend-vue/app/components/SeatQuotaBanner.vue +28 -0
  163. package/frontend-vue/app/components/TenantBillingForm.vue +52 -128
  164. package/frontend-vue/app/components/TenantPlanCard.vue +68 -10
  165. package/frontend-vue/app/components/UserSummaryCard.vue +12 -10
  166. package/frontend-vue/app/components/WorkspaceAdminCreateModal.vue +202 -0
  167. package/frontend-vue/app/components/WorkspaceCreateModal.vue +46 -9
  168. package/frontend-vue/app/components/WorkspaceInvitationLink.vue +106 -0
  169. package/frontend-vue/app/components/WorkspaceSummaryCard.vue +39 -15
  170. package/frontend-vue/app/components/WorkspaceSuspended.vue +3 -5
  171. package/frontend-vue/app/components/WorkspaceSwitcherWidget.vue +8 -5
  172. package/frontend-vue/app/composables/useBillingCountries.ts +25 -5
  173. package/frontend-vue/app/composables/useBillingDocumentType.ts +9 -5
  174. package/frontend-vue/app/composables/useBillingIdentity.ts +141 -0
  175. package/frontend-vue/app/composables/useInvitationLink.ts +69 -0
  176. package/frontend-vue/app/composables/usePastDueBannerAction.ts +20 -0
  177. package/frontend-vue/app/composables/usePlanComparison.ts +15 -0
  178. package/frontend-vue/app/composables/usePlanFeatureFormat.ts +312 -20
  179. package/frontend-vue/app/composables/usePlanFeatureLabel.ts +24 -0
  180. package/frontend-vue/app/composables/useSaasRegistration.ts +110 -223
  181. package/frontend-vue/app/composables/useSeatQuota.ts +8 -0
  182. package/frontend-vue/app/composables/useStripePaymentElement.ts +3 -3
  183. package/frontend-vue/app/composables/useWorkspaceAccessCache.ts +29 -2
  184. package/frontend-vue/app/composables/useWorkspaceFinalization.ts +7 -32
  185. package/frontend-vue/app/custom-pages/auth/no-workspace.vue +49 -194
  186. package/frontend-vue/app/plugins/auth-links.ts +0 -4
  187. package/frontend-vue/app/plugins/billing-data-types.ts +4 -2
  188. package/frontend-vue/app/types/runtime-config.ts +13 -0
  189. package/frontend-vue/dms.frontend.ts +10 -4
  190. package/frontend-vue/i18n/locales/saas-en-GB.json +161 -36
  191. package/frontend-vue/i18n/locales/saas-fr-FR.json +162 -37
  192. package/frontend-vue/package.json +0 -1
  193. package/frontend-vue/pnpm-lock.yaml +1 -125
  194. package/package.json +5 -5
  195. package/frontend-vue/app/middleware/workspace-suspended.global.ts +0 -59
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toAvailablePreview = toAvailablePreview;
4
+ const invoice_line_items_1 = require("../invoice-line-items");
5
+ const MS_PER_SECOND = 1000;
6
+ const REVERSE_CHARGE_REASON = "reverse_charge";
7
+ const SUBSCRIPTION_LINE_TYPE = "subscription";
8
+ function toIsoDate(seconds) {
9
+ return new Date(seconds * MS_PER_SECOND).toISOString();
10
+ }
11
+ function sumAmounts(amounts) {
12
+ return (amounts ?? []).reduce((total, entry) => total + entry.amount, 0);
13
+ }
14
+ function toLineKind(line) {
15
+ if (line.type === SUBSCRIPTION_LINE_TYPE)
16
+ return "subscription";
17
+ return line.metadata?.[invoice_line_items_1.LINE_KEY_METADATA] ? "usage" : "invoice_item";
18
+ }
19
+ function toPreviewLine(line) {
20
+ return {
21
+ kind: toLineKind(line),
22
+ description: line.description,
23
+ amountMinorUnits: line.amount_excluding_tax ?? line.amount,
24
+ taxMinorUnits: sumAmounts(line.tax_amounts),
25
+ quantity: line.quantity,
26
+ periodStart: toIsoDate(line.period.start),
27
+ periodEnd: toIsoDate(line.period.end),
28
+ isProration: line.proration,
29
+ usageLineKey: line.metadata?.[invoice_line_items_1.LINE_KEY_METADATA] ?? null,
30
+ };
31
+ }
32
+ function toUppercase(value) {
33
+ return value ? value.toUpperCase() : null;
34
+ }
35
+ function expandedTaxRate(taxRate) {
36
+ return typeof taxRate === "string" ? null : taxRate;
37
+ }
38
+ function toPreviewTax(taxAmount) {
39
+ const rate = expandedTaxRate(taxAmount.tax_rate);
40
+ return {
41
+ amountMinorUnits: taxAmount.amount,
42
+ taxableAmountMinorUnits: taxAmount.taxable_amount,
43
+ isInclusive: taxAmount.inclusive,
44
+ ratePercentage: rate
45
+ ? (rate.effective_percentage ?? rate.percentage)
46
+ : null,
47
+ country: toUppercase(rate?.country),
48
+ taxType: rate?.tax_type ?? null,
49
+ displayName: rate?.display_name ?? null,
50
+ jurisdiction: rate?.jurisdiction ?? null,
51
+ taxabilityReason: taxAmount.taxability_reason,
52
+ isReverseCharge: taxAmount.taxability_reason === REVERSE_CHARGE_REASON,
53
+ };
54
+ }
55
+ function resolveTaxCountry(invoice, taxes) {
56
+ const taxedCountry = taxes.find((tax) => tax.country)?.country;
57
+ return taxedCountry ?? toUppercase(invoice.customer_address?.country);
58
+ }
59
+ function toAvailablePreview(invoice, pricing) {
60
+ const taxes = (invoice.total_tax_amounts ?? []).map(toPreviewTax);
61
+ const taxMinorUnits = sumAmounts(invoice.total_tax_amounts);
62
+ return {
63
+ status: "available",
64
+ currency: invoice.currency.toUpperCase(),
65
+ lines: invoice.lines.data.map(toPreviewLine),
66
+ hasMoreLines: invoice.lines.has_more,
67
+ subtotalMinorUnits: invoice.subtotal_excluding_tax ?? invoice.subtotal,
68
+ totalExcludingTaxMinorUnits: invoice.total_excluding_tax ?? invoice.total - taxMinorUnits,
69
+ taxMinorUnits,
70
+ taxes,
71
+ taxCountry: resolveTaxCountry(invoice, taxes),
72
+ isReverseCharge: taxes.some((tax) => tax.isReverseCharge),
73
+ totalMinorUnits: invoice.total,
74
+ amountDueMinorUnits: invoice.amount_due,
75
+ periodStart: toIsoDate(invoice.period_start),
76
+ periodEnd: toIsoDate(invoice.period_end),
77
+ billingDate: pricing.billingDate.toISOString(),
78
+ usageThrough: pricing.usageThrough?.toISOString() ?? null,
79
+ computedAt: pricing.computedAt.toISOString(),
80
+ };
81
+ }
82
+ //# sourceMappingURL=mapping.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapping.js","sourceRoot":"","sources":["../../src/upcoming-invoice/mapping.ts"],"names":[],"mappings":";;AA8FA,gDA0BC;AAjHD,8DAA0D;AAE1D,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,MAAM,qBAAqB,GAAG,gBAAgB,CAAC;AAC/C,MAAM,sBAAsB,GAAG,cAAc,CAAC;AAa9C,SAAS,SAAS,CAAC,OAAe;IAChC,OAAO,IAAI,IAAI,CAAC,OAAO,GAAG,aAAa,CAAC,CAAC,WAAW,EAAE,CAAC;AACzD,CAAC;AAED,SAAS,UAAU,CAAC,OAAyC;IAC3D,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,UAAU,CAAC,IAA4B;IAC9C,IAAI,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,mBAAmB,IAAI,OAAO,CAAC,KAAK,GAAG,aAAa;QAC9D,aAAa;QACb,KAAK;QACL,UAAU,EAAE,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC;QAC7C,eAAe,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,eAAe,CAAC;QACzD,eAAe,EAAE,OAAO,CAAC,KAAK;QAC9B,mBAAmB,EAAE,OAAO,CAAC,UAAU;QACvC,WAAW,EAAE,SAAS,CAAC,OAAO,CAAC,YAAY,CAAC;QAC5C,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC;QACxC,WAAW,EAAE,OAAO,CAAC,WAAW,CAAC,WAAW,EAAE;QAC9C,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,WAAW,EAAE,IAAI,IAAI;QACzD,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE;KAC7C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { UpcomingInvoicePreview, UpcomingInvoicePreviewAbsenceReason, UpcomingInvoicePreviewUnavailableReason } from "@antelopejs/interface-dms-saas/billing";
2
+ export interface AbsentPreviewOutcome {
3
+ status: "absent";
4
+ reason: UpcomingInvoicePreviewAbsenceReason;
5
+ }
6
+ export interface UnavailablePreviewOutcome {
7
+ status: "unavailable";
8
+ reason: UpcomingInvoicePreviewUnavailableReason;
9
+ }
10
+ export type PreviewOutcome = AbsentPreviewOutcome | UnavailablePreviewOutcome;
11
+ export declare function absent(reason: UpcomingInvoicePreviewAbsenceReason): AbsentPreviewOutcome;
12
+ export declare function unavailable(reason: UpcomingInvoicePreviewUnavailableReason): UnavailablePreviewOutcome;
13
+ export declare function stampOutcome(outcome: PreviewOutcome, computedAt: Date): UpcomingInvoicePreview;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.absent = absent;
4
+ exports.unavailable = unavailable;
5
+ exports.stampOutcome = stampOutcome;
6
+ function absent(reason) {
7
+ return { status: "absent", reason };
8
+ }
9
+ function unavailable(reason) {
10
+ return { status: "unavailable", reason };
11
+ }
12
+ function stampOutcome(outcome, computedAt) {
13
+ return { ...outcome, computedAt: computedAt.toISOString() };
14
+ }
15
+ //# sourceMappingURL=outcomes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outcomes.js","sourceRoot":"","sources":["../../src/upcoming-invoice/outcomes.ts"],"names":[],"mappings":";;AAoBA,wBAIC;AAED,kCAIC;AAED,oCAKC;AAjBD,SAAgB,MAAM,CACpB,MAA2C;IAE3C,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AACtC,CAAC;AAED,SAAgB,WAAW,CACzB,MAA+C;IAE/C,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;AAC3C,CAAC;AAED,SAAgB,YAAY,CAC1B,OAAuB,EACvB,UAAgB;IAEhB,OAAO,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { UpcomingInvoicePreview } from "@antelopejs/interface-dms-saas/billing";
2
+ export declare function getUpcomingInvoicePreview(tenantId: string): Promise<UpcomingInvoicePreview>;
3
+ export declare function invalidateUpcomingInvoicePreview(tenantId: string): Promise<void>;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUpcomingInvoicePreview = getUpcomingInvoicePreview;
4
+ exports.invalidateUpcomingInvoicePreview = invalidateUpcomingInvoicePreview;
5
+ const logging_1 = require("@antelopejs/interface-core/logging");
6
+ const interface_database_decorators_1 = require("@antelopejs/interface-database-decorators");
7
+ const config_1 = require("../config");
8
+ const db_1 = require("../db");
9
+ const preview_cache_model_1 = require("./db/preview-cache.model");
10
+ const eligibility_1 = require("./eligibility");
11
+ const outcomes_1 = require("./outcomes");
12
+ const pricing_1 = require("./pricing");
13
+ const LOG_PREFIX = "[dms-saas:upcoming-invoice]";
14
+ const MISSING_ROW_VERSION = "none";
15
+ const SOURCE_VERSION_SEPARATOR = "|";
16
+ function rowVersion(row) {
17
+ return row?.updatedAt
18
+ ? new Date(row.updatedAt).toISOString()
19
+ : MISSING_ROW_VERSION;
20
+ }
21
+ function toSourceVersion(subscription, billingInfo) {
22
+ return [rowVersion(subscription), rowVersion(billingInfo)].join(SOURCE_VERSION_SEPARATOR);
23
+ }
24
+ async function readCachedPreview(tenantId, sourceVersion, computedNotBefore) {
25
+ try {
26
+ return await (0, interface_database_decorators_1.GetModel)(preview_cache_model_1.UpcomingInvoicePreviewCacheModel).readFresh({
27
+ tenantId,
28
+ sourceVersion,
29
+ computedNotBefore,
30
+ });
31
+ }
32
+ catch (error) {
33
+ logging_1.Logging.Error(`${LOG_PREFIX} cache read failed for ${tenantId}`, error);
34
+ return null;
35
+ }
36
+ }
37
+ async function cachePreview(tenantId, preview, sourceVersion, computedAt) {
38
+ if (preview.status === "unavailable")
39
+ return;
40
+ try {
41
+ await (0, interface_database_decorators_1.GetModel)(preview_cache_model_1.UpcomingInvoicePreviewCacheModel).store({
42
+ tenantId,
43
+ preview,
44
+ sourceVersion,
45
+ computedAt,
46
+ });
47
+ }
48
+ catch (error) {
49
+ logging_1.Logging.Error(`${LOG_PREFIX} cache write failed for ${tenantId}`, error);
50
+ }
51
+ }
52
+ async function getUpcomingInvoicePreview(tenantId) {
53
+ const now = new Date();
54
+ const [subscription, billingInfo] = await Promise.all([
55
+ (0, interface_database_decorators_1.GetModel)(db_1.TenantSubscriptionModel, tenantId).findOne(),
56
+ (0, interface_database_decorators_1.GetModel)(db_1.TenantBillingInfoModel, tenantId).findOne(),
57
+ ]);
58
+ const plan = subscription?.planId
59
+ ? await (0, interface_database_decorators_1.GetModel)(db_1.PlanModel).get(subscription.planId)
60
+ : undefined;
61
+ const eligibility = (0, eligibility_1.resolvePreviewEligibility)(subscription, plan);
62
+ if (!eligibility.isPreviewable)
63
+ return (0, outcomes_1.stampOutcome)(eligibility.outcome, now);
64
+ const ttlMs = (0, config_1.getUpcomingInvoicePreviewCacheTtlMs)();
65
+ const sourceVersion = toSourceVersion(subscription, billingInfo);
66
+ if (ttlMs > 0) {
67
+ const computedNotBefore = new Date(now.getTime() - ttlMs);
68
+ const cached = await readCachedPreview(tenantId, sourceVersion, computedNotBefore);
69
+ if (cached)
70
+ return cached;
71
+ }
72
+ const preview = await (0, pricing_1.priceUpcomingInvoice)(tenantId, eligibility.target, now);
73
+ if (ttlMs > 0)
74
+ await cachePreview(tenantId, preview, sourceVersion, now);
75
+ return preview;
76
+ }
77
+ async function invalidateUpcomingInvoicePreview(tenantId) {
78
+ await (0, interface_database_decorators_1.GetModel)(preview_cache_model_1.UpcomingInvoicePreviewCacheModel).invalidate(tenantId, new Date());
79
+ }
80
+ //# sourceMappingURL=preview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview.js","sourceRoot":"","sources":["../../src/upcoming-invoice/preview.ts"],"names":[],"mappings":";;AAsFA,8DA2BC;AAGD,4EAOC;AA3HD,gEAA6D;AAC7D,6FAAqE;AAErE,sCAAgE;AAChE,8BAMe;AACf,kEAA4E;AAC5E,+CAA0D;AAC1D,yCAA0C;AAC1C,uCAAiD;AAEjD,MAAM,UAAU,GAAG,6BAA6B,CAAC;AACjD,MAAM,mBAAmB,GAAG,MAAM,CAAC;AACnC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAMrC,SAAS,UAAU,CAAC,GAA6B;IAC/C,OAAO,GAAG,EAAE,SAAS;QACnB,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE;QACvC,CAAC,CAAC,mBAAmB,CAAC;AAC1B,CAAC;AAOD,SAAS,eAAe,CACtB,YAA4C,EAC5C,WAA0C;IAE1C,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,EAA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
+ import type { PreviewableSubscription } from "./eligibility";
3
+ export declare function priceUpcomingInvoice(tenantId: string, target: PreviewableSubscription, computedAt: Date): Promise<UpcomingInvoicePreview>;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.priceUpcomingInvoice = priceUpcomingInvoice;
4
+ const logging_1 = require("@antelopejs/interface-core/logging");
5
+ const upcoming_invoice_1 = require("../stripe/upcoming-invoice");
6
+ const mapping_1 = require("./mapping");
7
+ const outcomes_1 = require("./outcomes");
8
+ const usage_1 = require("./usage");
9
+ const LOG_PREFIX = "[dms-saas:upcoming-invoice]";
10
+ const COMPLETE_TAX_STATUS = "complete";
11
+ const STRIPE_ERROR_OUTCOMES = new Map([
12
+ ["invoice_upcoming_none", (0, outcomes_1.absent)("no_upcoming_invoice")],
13
+ ["stripe_tax_inactive", (0, outcomes_1.unavailable)("tax_not_configured")],
14
+ ["customer_tax_location_invalid", (0, outcomes_1.unavailable)("tax_location_invalid")],
15
+ ["invalid_tax_location", (0, outcomes_1.unavailable)("tax_location_invalid")],
16
+ ["taxes_calculation_failed", (0, outcomes_1.unavailable)("tax_calculation_failed")],
17
+ ]);
18
+ const AUTOMATIC_TAX_STATUS_REASONS = {
19
+ requires_location_inputs: "tax_location_required",
20
+ failed: "tax_calculation_failed",
21
+ };
22
+ const PROVIDER_ERROR = (0, outcomes_1.unavailable)("provider_error");
23
+ function stripeErrorCode(error) {
24
+ if (typeof error !== "object" || error === null)
25
+ return null;
26
+ const { code } = error;
27
+ return typeof code === "string" ? code : null;
28
+ }
29
+ function classifyStripeError(error) {
30
+ const code = stripeErrorCode(error);
31
+ return (code && STRIPE_ERROR_OUTCOMES.get(code)) || PROVIDER_ERROR;
32
+ }
33
+ function incompleteTaxReason(invoice) {
34
+ const { enabled, status } = invoice.automatic_tax;
35
+ if (!enabled || status === COMPLETE_TAX_STATUS)
36
+ return null;
37
+ return ((status && AUTOMATIC_TAX_STATUS_REASONS[status]) || "tax_calculation_failed");
38
+ }
39
+ function reportUnavailable(tenantId, reason, cause) {
40
+ logging_1.Logging.Error(`${LOG_PREFIX} no upcoming invoice preview for tenant ${tenantId} (${reason})`, cause);
41
+ }
42
+ async function priceWithStripe(tenantId, target, computedAt) {
43
+ const cycle = await (0, upcoming_invoice_1.retrieveStripeSubscriptionCycle)(target.subscriptionId);
44
+ const usage = await (0, usage_1.quoteRunningCycleUsage)({
45
+ tenantId,
46
+ subscription: target.subscription,
47
+ stripeSubscriptionId: target.subscriptionId,
48
+ cycle,
49
+ now: computedAt,
50
+ });
51
+ if (!usage) {
52
+ reportUnavailable(tenantId, "usage_unavailable");
53
+ return (0, outcomes_1.stampOutcome)((0, outcomes_1.unavailable)("usage_unavailable"), computedAt);
54
+ }
55
+ const invoice = await (0, upcoming_invoice_1.previewStripeUpcomingInvoice)({
56
+ customerId: target.customerId,
57
+ subscriptionId: target.subscriptionId,
58
+ currency: cycle.currency,
59
+ quotedItems: usage.items,
60
+ });
61
+ const taxReason = incompleteTaxReason(invoice);
62
+ if (taxReason) {
63
+ reportUnavailable(tenantId, taxReason);
64
+ return (0, outcomes_1.stampOutcome)((0, outcomes_1.unavailable)(taxReason), computedAt);
65
+ }
66
+ return (0, mapping_1.toAvailablePreview)(invoice, {
67
+ billingDate: cycle.currentPeriodEnd,
68
+ usageThrough: usage.usageThrough,
69
+ computedAt,
70
+ });
71
+ }
72
+ async function priceUpcomingInvoice(tenantId, target, computedAt) {
73
+ try {
74
+ return await priceWithStripe(tenantId, target, computedAt);
75
+ }
76
+ catch (error) {
77
+ const outcome = classifyStripeError(error);
78
+ if (outcome.status === "unavailable") {
79
+ reportUnavailable(tenantId, outcome.reason, error);
80
+ }
81
+ return (0, outcomes_1.stampOutcome)(outcome, computedAt);
82
+ }
83
+ }
84
+ //# sourceMappingURL=pricing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pricing.js","sourceRoot":"","sources":["../../src/upcoming-invoice/pricing.ts"],"names":[],"mapp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,SAAS,EAAE,CAAC;QACd,iBAAiB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QACvC,OAAO,IAAA,uBAAY,EAAC,IAAA,sBAAW,EAAC,SAAS,CAAC,EAAE,UAAU,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,IAAA,4BAAkB,EAAC,OAAO,EAAE;QACjC,WAAW,EAAE,KAAK,CAAC,gBAAgB;QACnC,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,UAAU;KACX,CAAC,CAAC;AACL,CAAC;AAMM,KAAK,UAAU,oBAAoB,CACxC,QAAgB,EAChB,MAA+B,EAC/B,UAAgB;IAEhB,IAAI,CAAC;QACH,OAAO,MAAM,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC7D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;QAC3C,IAAI,OAAO,CAAC,MAAM,KAAK,aAAa,EAAE,CAAC;YACrC,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,IAAA,uBAAY,EAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { TenantSubscription } from "../db";
2
+ import type { QuotedInvoiceItem, StripeSubscriptionCycle } from "../stripe/upcoming-invoice";
3
+ export interface QuotedUsage {
4
+ items: QuotedInvoiceItem[];
5
+ usageThrough: Date | null;
6
+ }
7
+ export interface UsageQuoteRequest {
8
+ tenantId: string;
9
+ subscription: TenantSubscription;
10
+ stripeSubscriptionId: string;
11
+ cycle: StripeSubscriptionCycle;
12
+ now: Date;
13
+ }
14
+ export declare function quoteRunningCycleUsage(request: UsageQuoteRequest): Promise<QuotedUsage | null>;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.quoteRunningCycleUsage = quoteRunningCycleUsage;
4
+ const invoice_line_items_1 = require("@antelopejs/interface-dms-saas/invoice-line-items");
5
+ const invoice_line_items_2 = require("../implementations/dms-saas/invoice-line-items");
6
+ const invoice_line_items_3 = require("../invoice-line-items");
7
+ const billing_window_1 = require("../invoice-line-items/billing-window");
8
+ const PREVIEW_INVOICE_ID_PREFIX = "upcoming_";
9
+ const NO_USAGE = { items: [], usageThrough: null };
10
+ function buildPreviewContext(request) {
11
+ if (request.now <= request.cycle.currentPeriodStart)
12
+ return null;
13
+ return (0, billing_window_1.clipInvoiceUsageWindow)({
14
+ tenantId: request.tenantId,
15
+ invoiceId: `${PREVIEW_INVOICE_ID_PREFIX}${request.stripeSubscriptionId}`,
16
+ currency: request.cycle.currency,
17
+ periodStart: request.cycle.currentPeriodStart,
18
+ periodEnd: request.now,
19
+ isPreview: true,
20
+ }, request.subscription, request.stripeSubscriptionId);
21
+ }
22
+ async function quoteProviderLines(provider, context) {
23
+ const resolution = await (0, invoice_line_items_3.resolveProviderLineItems)(provider, context);
24
+ if (resolution.failures > 0)
25
+ return null;
26
+ const selection = (0, invoice_line_items_1.selectInvoiceLineItemsToCreate)(provider.id, resolution.lineItems, new Set());
27
+ (0, invoice_line_items_3.reportSkippedLineItems)(provider.id, context.invoiceId, selection.skipped);
28
+ if (selection.skipped.some((line) => line.reason === "invalid"))
29
+ return null;
30
+ return selection.accepted.map((prepared) => ({
31
+ amountMinorUnits: prepared.item.amountCents,
32
+ description: prepared.item.description,
33
+ periodStart: context.periodStart,
34
+ periodEnd: context.periodEnd,
35
+ metadata: (0, invoice_line_items_3.buildLineItemMetadata)(provider.id, prepared),
36
+ }));
37
+ }
38
+ async function quoteRunningCycleUsage(request) {
39
+ const providers = (0, invoice_line_items_2.getInvoiceLineItemsProviders)();
40
+ if (providers.length === 0)
41
+ return NO_USAGE;
42
+ const context = buildPreviewContext(request);
43
+ if (!context)
44
+ return NO_USAGE;
45
+ const quotes = await Promise.all(providers.map((provider) => quoteProviderLines(provider, context)));
46
+ if (quotes.some((quote) => quote === null))
47
+ return null;
48
+ return {
49
+ items: quotes.flatMap((quote) => quote ?? []),
50
+ usageThrough: context.periodEnd,
51
+ };
52
+ }
53
+ //# sourceMappingURL=usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.js","sourceRoot":"","sources":["../../src/upcoming-invoice/usage.ts"],"names":[],"mappings":";;AAmFA,wDAeC;AA9FD,0FAAmG;AAEnG,uFAA8F;AAC9F,8DAI+B;AAC/B,yEAA8E;AAM9E,MAAM,yBAAyB,GAAG,WAAW,CAAC;AAiB9C,MAAM,QAAQ,GAAgB,EAAE,KAAK,EAAE,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;AAEhE,SAAS,mBAAmB,CAC1B,OAA0B;IAE1B,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC,kBAAkB;QAAE,OAAO,IAAI,CAAC;IACjE,OAAO,IAAA,uCAAsB,EAC3B;QACE,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,SAAS,EAAE,GAAG,yBAAyB,GAAG,OAAO,CAAC,oBAAoB,EAAE;QACxE,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,QAAQ;QAChC,WAAW,EAAE,OAAO,CAAC,KAAK,CAAC,kBAAkB;QAC7C,SAAS,EAAE,OAAO,CAAC,GAAG;QACtB,SAAS,EAAE,IAAI;KAChB,EACD,OAAO,CAAC,YAAY,EACpB,OAAO,CAAC,oBAAoB,CAC7B,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,kBAAkB,CAC/B,QAAkC,EAClC,OAAgC;IAEhC,MAAM,UAAU,GAAG,MAAM,IAAA,6CAAwB,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACrE,IAAI,UAAU,CAAC,QAAQ,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACzC,MAAM,SAAS,GAAG,IAAA,mDAA8B,EA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AAE,OAAO,IAAI,CAAC;IACxD,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC;QAC7C,YAAY,EAAE,OAAO,CAAC,SAAS;KAChC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { TenantCustomerType } from "../db";
2
+ import type { CustomerBillingAddress } from "../stripe";
3
+ export interface BillingIdentityInput {
4
+ customerType?: string | null;
5
+ companyName?: string | null;
6
+ vatNumber?: string | null;
7
+ billingEmail?: string | null;
8
+ address?: CustomerBillingAddress;
9
+ }
10
+ export interface BillingIdentity {
11
+ customerType: TenantCustomerType;
12
+ companyName: string | null;
13
+ vatNumber: string | null;
14
+ billingEmail: string;
15
+ address: CustomerBillingAddress;
16
+ }
17
+ export type BillingIdentityField = "customerType" | "companyName" | "country" | "line1" | "postalCode" | "city" | "billingEmail";
18
+ export declare function findMissingBillingIdentityFields(identity: BillingIdentityInput): BillingIdentityField[];
19
+ export declare function parseBillingIdentity(identity: BillingIdentityInput): BillingIdentity;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findMissingBillingIdentityFields = findMissingBillingIdentityFields;
4
+ exports.parseBillingIdentity = parseBillingIdentity;
5
+ const interface_api_util_1 = require("@antelopejs/interface-api-util");
6
+ const HTTP_BAD_REQUEST = 400;
7
+ const BUSINESS_CUSTOMER_TYPE = "business";
8
+ const CUSTOMER_TYPES = new Set(["individual", "business"]);
9
+ const COUNTRY_CODE_PATTERN = /^[A-Z]{2}$/;
10
+ const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
11
+ function trimmed(value) {
12
+ const result = value?.trim();
13
+ return result ? result : null;
14
+ }
15
+ function isBusiness(identity) {
16
+ return identity.customerType === BUSINESS_CUSTOMER_TYPE;
17
+ }
18
+ const FIELD_CHECKS = {
19
+ customerType: (identity) => CUSTOMER_TYPES.has(identity.customerType ?? ""),
20
+ companyName: (identity) => !isBusiness(identity) || !!trimmed(identity.companyName),
21
+ country: (identity) => COUNTRY_CODE_PATTERN.test(trimmed(identity.address?.country) ?? ""),
22
+ line1: (identity) => !!trimmed(identity.address?.line1),
23
+ postalCode: (identity) => !!trimmed(identity.address?.postalCode),
24
+ city: (identity) => !!trimmed(identity.address?.city),
25
+ billingEmail: (identity) => EMAIL_PATTERN.test(trimmed(identity.billingEmail) ?? ""),
26
+ };
27
+ function findMissingBillingIdentityFields(identity) {
28
+ return Object.keys(FIELD_CHECKS).filter((field) => !FIELD_CHECKS[field](identity));
29
+ }
30
+ function normalizeAddress(address) {
31
+ return {
32
+ line1: trimmed(address?.line1),
33
+ line2: trimmed(address?.line2),
34
+ postalCode: trimmed(address?.postalCode),
35
+ city: trimmed(address?.city),
36
+ state: trimmed(address?.state),
37
+ country: trimmed(address?.country),
38
+ };
39
+ }
40
+ function parseBillingIdentity(identity) {
41
+ (0, interface_api_util_1.assert)(findMissingBillingIdentityFields(identity).length === 0, HTTP_BAD_REQUEST, "saas.errors.billing.identity_incomplete");
42
+ const business = isBusiness(identity);
43
+ return {
44
+ customerType: identity.customerType,
45
+ companyName: business ? trimmed(identity.companyName) : null,
46
+ vatNumber: business ? trimmed(identity.vatNumber) : null,
47
+ billingEmail: trimmed(identity.billingEmail) ?? "",
48
+ address: normalizeAddress(identity.address),
49
+ };
50
+ }
51
+ //# sourceMappingURL=billing-identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"billing-identity.js","sourceRoot":"","sources":["../../src/workspaces/billing-identity.ts"],"names":[],"mappings":";;AAqEA,4EAMC;AAsBD,oDAgBC;AAjHD,uEAAwD;AAIxD,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,sBAAsB,GAAuB,UAAU,CAAC;AAC9D,MAAM,cAAc,GAAG,IAAI,GAAG,CAAS,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC;AACnE,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@@ -0,0 +1,5 @@
1
+ import { type Plan } from "../db";
2
+ export declare function selectDefaultPlan(plans: Plan[], configuredSlug?: string): Plan | null;
3
+ export declare function resolveDefaultPlan(): Promise<Plan | null>;
4
+ export declare function ensureDefaultSubscription(tenantId: string, plan?: Plan | null): Promise<boolean>;
5
+ export declare function backfillDefaultSubscriptions(): Promise<number>;
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.selectDefaultPlan = selectDefaultPlan;
4
+ exports.resolveDefaultPlan = resolveDefaultPlan;
5
+ exports.ensureDefaultSubscription = ensureDefaultSubscription;
6
+ exports.backfillDefaultSubscriptions = backfillDefaultSubscriptions;
7
+ const logging_1 = require("@antelopejs/interface-core/logging");
8
+ const interface_database_decorators_1 = require("@antelopejs/interface-database-decorators");
9
+ const db_1 = require("@antelopejs/interface-dms/db");
10
+ const tenant_lifecycle_1 = require("@antelopejs/interface-dms/tenant-lifecycle");
11
+ const billing_state_1 = require("../billing-state");
12
+ const config_1 = require("../config");
13
+ const db_2 = require("../db");
14
+ const free_workspace_guard_1 = require("./free-workspace-guard");
15
+ const LOG_PREFIX = "[dms-saas:default-plan]";
16
+ const ACTIVE_STATUS = "active";
17
+ const DEFAULT_PLAN_AUDIENCES = new Set(["any", "individual"]);
18
+ function isDefaultPlanCandidate(plan) {
19
+ return (plan.isActive &&
20
+ !plan.isDeleted &&
21
+ (0, free_workspace_guard_1.isFreePlan)(plan) &&
22
+ DEFAULT_PLAN_AUDIENCES.has(plan.audience));
23
+ }
24
+ function selectDefaultPlan(plans, configuredSlug) {
25
+ const candidates = plans
26
+ .filter(isDefaultPlanCandidate)
27
+ .sort((left, right) => left.order - right.order);
28
+ if (!configuredSlug)
29
+ return candidates[0] ?? null;
30
+ const configured = candidates.find((plan) => plan.slug === configuredSlug);
31
+ if (!configured) {
32
+ logging_1.Logging.Warn(`${LOG_PREFIX} defaultPlanSlug "${configuredSlug}" names no active free plan; falling back to the lowest-ordered one`);
33
+ }
34
+ return configured ?? candidates[0] ?? null;
35
+ }
36
+ let hasWarnedMissingPlan = false;
37
+ async function resolveDefaultPlan() {
38
+ const plans = await (0, interface_database_decorators_1.GetModel)(db_2.PlanModel).findActiveNotDeleted();
39
+ const plan = selectDefaultPlan(plans, (0, config_1.getDefaultPlanSlug)());
40
+ if (plan)
41
+ hasWarnedMissingPlan = false;
42
+ return plan;
43
+ }
44
+ function logMissingDefaultPlan() {
45
+ if (hasWarnedMissingPlan)
46
+ return;
47
+ hasWarnedMissingPlan = true;
48
+ logging_1.Logging.Warn(`${LOG_PREFIX} the catalogue has no active free plan: workspaces without a subscription stay plan-less until one is published`);
49
+ }
50
+ async function insertDefaultSubscription(tenantId, plan) {
51
+ const model = (0, interface_database_decorators_1.GetModel)(db_2.TenantSubscriptionModel, tenantId);
52
+ if (await model.findOne())
53
+ return false;
54
+ const now = new Date();
55
+ await model.insert([
56
+ {
57
+ _id: tenantId,
58
+ planId: plan._id,
59
+ status: ACTIVE_STATUS,
60
+ isComplimentary: false,
61
+ paidUsagePeriods: [],
62
+ stripeCustomerId: null,
63
+ stripeSubscriptionId: null,
64
+ stripeCheckoutSessionId: null,
65
+ createdBy: null,
66
+ createdAt: now,
67
+ updatedAt: now,
68
+ },
69
+ ]);
70
+ return true;
71
+ }
72
+ async function ensureDefaultSubscription(tenantId, plan) {
73
+ const defaultPlan = plan === undefined ? await resolveDefaultPlan() : plan;
74
+ if (!defaultPlan) {
75
+ logMissingDefaultPlan();
76
+ return false;
77
+ }
78
+ const isAttached = await (0, tenant_lifecycle_1.runTenantLifecycleOperation)(tenantId, () => insertDefaultSubscription(tenantId, defaultPlan));
79
+ if (isAttached)
80
+ await (0, billing_state_1.recomputeTenantBillingState)(tenantId);
81
+ return isAttached;
82
+ }
83
+ async function attachToTenant(tenantId, plan) {
84
+ try {
85
+ return await ensureDefaultSubscription(tenantId, plan);
86
+ }
87
+ catch (error) {
88
+ logging_1.Logging.Error(`${LOG_PREFIX} could not cover workspace ${tenantId}`, error);
89
+ return false;
90
+ }
91
+ }
92
+ async function backfillDefaultSubscriptions() {
93
+ const plan = await resolveDefaultPlan();
94
+ if (!plan) {
95
+ logMissingDefaultPlan();
96
+ return 0;
97
+ }
98
+ const tenants = await (0, interface_database_decorators_1.GetModel)(db_1.TenantModel).table.pluck("_id").run();
99
+ let attachedCount = 0;
100
+ for (const tenant of tenants) {
101
+ if (tenant._id && (await attachToTenant(tenant._id, plan))) {
102
+ attachedCount++;
103
+ }
104
+ }
105
+ if (attachedCount > 0) {
106
+ logging_1.Logging.Info(`${LOG_PREFIX} attached plan "${plan.slug}" to ${attachedCount} workspace(s)`);
107
+ }
108
+ return attachedCount;
109
+ }
110
+ //# sourceMappingURL=default-plan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-plan.js","sourceRoot":"","sources":["../../src/workspaces/default-plan.ts"],"names":[],"mappings":";;AAsCA,8CAeC;AAOD,gDAKC;AA6CD,8DAcC;AAmBD,oEAmBC;AAlKD,gEAA6D;AAC7D,6FAAqE;AACrE,qDAA2D;AAC3D,iFAAyF;AACzF,oDAA+D;AAC/D,sCAA+C;AAC/C,8BAKe;AACf,iEAAoD;AAEpD,MAAM,UAAU,GAAG,yBAAyB,CAAC;AAC7C,MAAM,aAAa,GAAG,QAAiB,CAAC;AAGxC,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAe,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC;AAE5E,SAAS,sBAAsB,CAAC,IAAU;IACxC,OAAO,CACL,IAAI,CAAC,QAAQ;QACb,CAAC,IAAI,CAAC,SAAS;QACf,IAAA,iCAAU,EAAC,IAAI,CAAC;QAChB,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAC1C,CAAC;AACJ,CAAC;AAWD,SAAgB,iBAAiB,CAC/B,KAAa,EACb,cAAuB;IAEvB,MAAM,UAAU,GAAG,KAAK;SACrB,MAAM,CAAC,sBAAsB,C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BAA4B;IAChD,MAAM,IAAI,GAAG,MAAM,kBAAkB,EAAE,CAAC;IACxC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,qBAAqB,EAAE,CAAC;QACxB,OAAO,CAAC,CAAC;IACX,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,IAAA,wCAAQ,EAAC,gBAAW,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC;IACrE,IAAI,aAAa,GAAG,CAAC,CAAC;IACtB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,cAAc,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;YAC3D,aAAa,EAAE,CAAC;QAClB,CAAC;IACH,CAAC;IACD,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;QACtB,iBAAO,CAAC,IAAI,CACV,GAAG,UAAU,mBAAmB,IAAI,CAAC,IAAI,QAAQ,aAAa,eAAe,CAC9E,CAAC;IACJ,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -1,6 +1,8 @@
1
1
  export * from "./billing-profile";
2
+ export * from "./default-plan";
2
3
  export * from "./deletion";
3
4
  export * from "./free-workspace-guard";
5
+ export * from "./invitations";
4
6
  export * from "./provisioning";
5
7
  export * from "./registration-extras";
6
8
  export * from "./suspension";
@@ -15,8 +15,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./billing-profile"), exports);
18
+ __exportStar(require("./default-plan"), exports);
18
19
  __exportStar(require("./deletion"), exports);
19
20
  __exportStar(require("./free-workspace-guard"), exports);
21
+ __exportStar(require("./invitations"), exports);
20
22
  __exportStar(require("./provisioning"), exports);
21
23
  __exportStar(require("./registration-extras"), exports);
22
24
  __exportStar(require("./suspension"), exports);
@@ -1 +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"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workspaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,iDAA+B;AAC/B,6CAA2B;AAC3B,yDAAuC;AACvC,gDAA8B;AAC9B,iDAA+B;AAC/B,wDAAsC;AACtC,+CAA6B"}