@antelopejs/dms-saas 0.1.8 → 0.2.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.
Files changed (199) hide show
  1. package/README.md +262 -13
  2. package/dist/auth/subscription-access-gate.d.ts +1 -1
  3. package/dist/billing-state/index.d.ts +1 -0
  4. package/dist/billing-state/index.js +1 -0
  5. package/dist/billing-state/index.js.map +1 -1
  6. package/dist/billing-state/past-due-banner.d.ts +4 -0
  7. package/dist/billing-state/past-due-banner.js +25 -0
  8. package/dist/billing-state/past-due-banner.js.map +1 -0
  9. package/dist/config/runtime.d.ts +6 -1
  10. package/dist/config/runtime.js +50 -1
  11. package/dist/config/runtime.js.map +1 -1
  12. package/dist/crons/recompute-billing-state.js +4 -1
  13. package/dist/crons/recompute-billing-state.js.map +1 -1
  14. package/dist/data-api/platformOwner/index.d.ts +1 -0
  15. package/dist/data-api/platformOwner/index.js +1 -0
  16. package/dist/data-api/platformOwner/index.js.map +1 -1
  17. package/dist/data-api/platformOwner/invitations.d.ts +22 -0
  18. package/dist/data-api/platformOwner/invitations.js +121 -0
  19. package/dist/data-api/platformOwner/invitations.js.map +1 -0
  20. package/dist/data-api/platformOwner/workspaces.d.ts +3 -0
  21. package/dist/data-api/platformOwner/workspaces.js +64 -12
  22. package/dist/data-api/platformOwner/workspaces.js.map +1 -1
  23. package/dist/data-api/tenant/tenant-invoices.js +2 -10
  24. package/dist/data-api/tenant/tenant-invoices.js.map +1 -1
  25. package/dist/hooks/register.js +2 -1
  26. package/dist/hooks/register.js.map +1 -1
  27. package/dist/implementations/dms-saas/billing.d.ts +2 -1
  28. package/dist/implementations/dms-saas/billing.js +6 -0
  29. package/dist/implementations/dms-saas/billing.js.map +1 -1
  30. package/dist/index.js +5 -0
  31. package/dist/index.js.map +1 -1
  32. package/dist/invoice-line-items/injection.d.ts +10 -0
  33. package/dist/invoice-line-items/injection.js +7 -3
  34. package/dist/invoice-line-items/injection.js.map +1 -1
  35. package/dist/notifications/subjects.d.ts +19 -19
  36. package/dist/operator-actions/index.d.ts +1 -0
  37. package/dist/operator-actions/index.js +1 -0
  38. package/dist/operator-actions/index.js.map +1 -1
  39. package/dist/operator-actions/invitation-commands.d.ts +12 -0
  40. package/dist/operator-actions/invitation-commands.js +46 -0
  41. package/dist/operator-actions/invitation-commands.js.map +1 -0
  42. package/dist/operator-actions/types.d.ts +1 -1
  43. package/dist/pages/platform/categories.d.ts +6 -6
  44. package/dist/pages/platform/credit-notes.d.ts +1 -1
  45. package/dist/pages/platform/dashboard.d.ts +2 -2
  46. package/dist/pages/platform/dashboard.js +2 -4
  47. package/dist/pages/platform/dashboard.js.map +1 -1
  48. package/dist/pages/platform/features.d.ts +1 -1
  49. package/dist/pages/platform/invoices.d.ts +1 -1
  50. package/dist/pages/platform/plans/edit.d.ts +2 -2
  51. package/dist/pages/platform/plans/index.d.ts +1 -1
  52. package/dist/pages/platform/plans/migrations.d.ts +1 -1
  53. package/dist/pages/platform/segments/index.d.ts +1 -1
  54. package/dist/pages/platform/settings.d.ts +1 -1
  55. package/dist/pages/platform/users/detail.d.ts +1 -1
  56. package/dist/pages/platform/users/index.d.ts +1 -1
  57. package/dist/pages/platform/workspaces/detail.d.ts +1 -1
  58. package/dist/pages/platform/workspaces/detail.js +40 -1
  59. package/dist/pages/platform/workspaces/detail.js.map +1 -1
  60. package/dist/pages/platform/workspaces/index.d.ts +4 -10
  61. package/dist/pages/platform/workspaces/index.js +27 -111
  62. package/dist/pages/platform/workspaces/index.js.map +1 -1
  63. package/dist/pages/public/legal/privacy-policy.js +2 -1
  64. package/dist/pages/public/legal/privacy-policy.js.map +1 -1
  65. package/dist/pages/public/legal/terms-and-conditions.js +2 -1
  66. package/dist/pages/public/legal/terms-and-conditions.js.map +1 -1
  67. package/dist/pages/public/legal/terms-of-use.js +2 -1
  68. package/dist/pages/public/legal/terms-of-use.js.map +1 -1
  69. package/dist/pages/tenant/billing.d.ts +1 -1
  70. package/dist/plans/index.d.ts +1 -0
  71. package/dist/plans/index.js +1 -0
  72. package/dist/plans/index.js.map +1 -1
  73. package/dist/plans/platform-support.d.ts +2 -0
  74. package/dist/plans/platform-support.js +19 -0
  75. package/dist/plans/platform-support.js.map +1 -0
  76. package/dist/plans/seat-capacity.d.ts +9 -2
  77. package/dist/plans/seat-capacity.js +59 -12
  78. package/dist/plans/seat-capacity.js.map +1 -1
  79. package/dist/plans/seat-hooks.js +34 -13
  80. package/dist/plans/seat-hooks.js.map +1 -1
  81. package/dist/routes/platformOwner/billing-settings.d.ts +2 -2
  82. package/dist/routes/platformOwner/dashboard.d.ts +8 -6
  83. package/dist/routes/platformOwner/dashboard.js +31 -17
  84. package/dist/routes/platformOwner/dashboard.js.map +1 -1
  85. package/dist/routes/platformOwner/index.d.ts +1 -0
  86. package/dist/routes/platformOwner/index.js +1 -0
  87. package/dist/routes/platformOwner/index.js.map +1 -1
  88. package/dist/routes/platformOwner/plan-deletion.d.ts +1 -1
  89. package/dist/routes/platformOwner/plans.d.ts +5 -5
  90. package/dist/routes/platformOwner/segments.d.ts +1 -1
  91. package/dist/routes/platformOwner/workspace-invitations.d.ts +13 -0
  92. package/dist/routes/platformOwner/workspace-invitations.js +73 -0
  93. package/dist/routes/platformOwner/workspace-invitations.js.map +1 -0
  94. package/dist/routes/public/legal-documents.d.ts +2 -2
  95. package/dist/routes/public/register.d.ts +7 -3
  96. package/dist/routes/public/register.js +42 -27
  97. package/dist/routes/public/register.js.map +1 -1
  98. package/dist/routes/tenant/tenant-billing.d.ts +7 -11
  99. package/dist/routes/tenant/tenant-billing.js +34 -26
  100. package/dist/routes/tenant/tenant-billing.js.map +1 -1
  101. package/dist/routes/tenant/tenant-plan.d.ts +1 -0
  102. package/dist/routes/tenant/tenant-plan.js +27 -2
  103. package/dist/routes/tenant/tenant-plan.js.map +1 -1
  104. package/dist/routes/tenant/tenant-seats.d.ts +2 -4
  105. package/dist/routes/tenant/tenant-seats.js.map +1 -1
  106. package/dist/routes/tenant/workspaces.d.ts +3 -1
  107. package/dist/routes/tenant/workspaces.js +10 -4
  108. package/dist/routes/tenant/workspaces.js.map +1 -1
  109. package/dist/stripe/upcoming-invoice.d.ts +21 -0
  110. package/dist/stripe/upcoming-invoice.js +42 -0
  111. package/dist/stripe/upcoming-invoice.js.map +1 -0
  112. package/dist/stripe/webhook-dispatch.js +2 -0
  113. package/dist/stripe/webhook-dispatch.js.map +1 -1
  114. package/dist/types/config.d.ts +9 -0
  115. package/dist/types/config.js +7 -0
  116. package/dist/types/config.js.map +1 -1
  117. package/dist/upcoming-invoice/db/preview-cache.model.d.ts +38 -0
  118. package/dist/upcoming-invoice/db/preview-cache.model.js +57 -0
  119. package/dist/upcoming-invoice/db/preview-cache.model.js.map +1 -0
  120. package/dist/upcoming-invoice/db/preview-cache.table.d.ts +10 -0
  121. package/dist/upcoming-invoice/db/preview-cache.table.js +42 -0
  122. package/dist/upcoming-invoice/db/preview-cache.table.js.map +1 -0
  123. package/dist/upcoming-invoice/eligibility.d.ts +17 -0
  124. package/dist/upcoming-invoice/eligibility.js +52 -0
  125. package/dist/upcoming-invoice/eligibility.js.map +1 -0
  126. package/dist/upcoming-invoice/invalidation.d.ts +2 -0
  127. package/dist/upcoming-invoice/invalidation.js +39 -0
  128. package/dist/upcoming-invoice/invalidation.js.map +1 -0
  129. package/dist/upcoming-invoice/mapping.d.ts +8 -0
  130. package/dist/upcoming-invoice/mapping.js +82 -0
  131. package/dist/upcoming-invoice/mapping.js.map +1 -0
  132. package/dist/upcoming-invoice/outcomes.d.ts +13 -0
  133. package/dist/upcoming-invoice/outcomes.js +15 -0
  134. package/dist/upcoming-invoice/outcomes.js.map +1 -0
  135. package/dist/upcoming-invoice/preview.d.ts +3 -0
  136. package/dist/upcoming-invoice/preview.js +80 -0
  137. package/dist/upcoming-invoice/preview.js.map +1 -0
  138. package/dist/upcoming-invoice/pricing.d.ts +3 -0
  139. package/dist/upcoming-invoice/pricing.js +84 -0
  140. package/dist/upcoming-invoice/pricing.js.map +1 -0
  141. package/dist/upcoming-invoice/usage.d.ts +14 -0
  142. package/dist/upcoming-invoice/usage.js +53 -0
  143. package/dist/upcoming-invoice/usage.js.map +1 -0
  144. package/dist/utils/invoice-lines-type.d.ts +1 -1
  145. package/dist/workspaces/billing-identity.d.ts +19 -0
  146. package/dist/workspaces/billing-identity.js +51 -0
  147. package/dist/workspaces/billing-identity.js.map +1 -0
  148. package/dist/workspaces/default-plan.d.ts +5 -0
  149. package/dist/workspaces/default-plan.js +109 -0
  150. package/dist/workspaces/default-plan.js.map +1 -0
  151. package/dist/workspaces/index.d.ts +2 -0
  152. package/dist/workspaces/index.js +2 -0
  153. package/dist/workspaces/index.js.map +1 -1
  154. package/dist/workspaces/invitations.d.ts +26 -0
  155. package/dist/workspaces/invitations.js +112 -0
  156. package/dist/workspaces/invitations.js.map +1 -0
  157. package/dist/workspaces/provisioning.d.ts +3 -3
  158. package/dist/workspaces/provisioning.js +39 -11
  159. package/dist/workspaces/provisioning.js.map +1 -1
  160. package/frontend-vue/app/components/BillingIdentityFields.vue +179 -0
  161. package/frontend-vue/app/components/PastDueBanner.vue +81 -0
  162. package/frontend-vue/app/components/PaymentMethodCard.vue +94 -38
  163. package/frontend-vue/app/components/PlanComparisonModal.vue +62 -26
  164. package/frontend-vue/app/components/PlanUpgradeModal.vue +181 -0
  165. package/frontend-vue/app/components/PlatformNotes.vue +4 -0
  166. package/frontend-vue/app/components/RefundButton.vue +10 -1
  167. package/frontend-vue/app/components/Register.vue +49 -92
  168. package/frontend-vue/app/components/SeatQuotaBanner.vue +28 -0
  169. package/frontend-vue/app/components/TenantBillingForm.vue +52 -128
  170. package/frontend-vue/app/components/TenantPlanCard.vue +68 -10
  171. package/frontend-vue/app/components/UserSummaryCard.vue +12 -10
  172. package/frontend-vue/app/components/WorkspaceAdminCreateModal.vue +202 -0
  173. package/frontend-vue/app/components/WorkspaceCreateModal.vue +46 -9
  174. package/frontend-vue/app/components/WorkspaceInvitationLink.vue +106 -0
  175. package/frontend-vue/app/components/WorkspaceSummaryCard.vue +39 -15
  176. package/frontend-vue/app/components/WorkspaceSuspended.vue +3 -5
  177. package/frontend-vue/app/components/WorkspaceSwitcherWidget.vue +8 -5
  178. package/frontend-vue/app/composables/useBillingCountries.ts +25 -5
  179. package/frontend-vue/app/composables/useBillingIdentity.ts +141 -0
  180. package/frontend-vue/app/composables/useInvitationLink.ts +69 -0
  181. package/frontend-vue/app/composables/usePastDueBannerAction.ts +20 -0
  182. package/frontend-vue/app/composables/usePlanComparison.ts +15 -0
  183. package/frontend-vue/app/composables/usePlanFeatureFormat.ts +312 -20
  184. package/frontend-vue/app/composables/usePlanFeatureLabel.ts +24 -0
  185. package/frontend-vue/app/composables/useSaasRegistration.ts +110 -223
  186. package/frontend-vue/app/composables/useSeatQuota.ts +8 -0
  187. package/frontend-vue/app/composables/useStripePaymentElement.ts +3 -3
  188. package/frontend-vue/app/composables/useWorkspaceAccessCache.ts +29 -2
  189. package/frontend-vue/app/composables/useWorkspaceFinalization.ts +7 -32
  190. package/frontend-vue/app/custom-pages/auth/no-workspace.vue +49 -194
  191. package/frontend-vue/app/plugins/auth-links.ts +0 -4
  192. package/frontend-vue/app/types/runtime-config.ts +13 -0
  193. package/frontend-vue/dms.frontend.ts +10 -4
  194. package/frontend-vue/i18n/locales/saas-en-GB.json +161 -36
  195. package/frontend-vue/i18n/locales/saas-fr-FR.json +162 -37
  196. package/frontend-vue/package.json +0 -1
  197. package/frontend-vue/pnpm-lock.yaml +1 -125
  198. package/package.json +15 -15
  199. package/frontend-vue/app/middleware/workspace-suspended.global.ts +0 -59
@@ -0,0 +1,10 @@
1
+ import { Table } from "@antelopejs/interface-database-decorators";
2
+ import type { UpcomingInvoicePreview } from "@antelopejs/interface-dms-saas/billing";
3
+ export declare const upcomingInvoicePreviewsTableName = "saas_upcoming_invoice_previews";
4
+ export declare class UpcomingInvoicePreviewEntry extends Table {
5
+ _id: string;
6
+ preview: UpcomingInvoicePreview | null;
7
+ sourceVersion: string | null;
8
+ computedAt: Date | null;
9
+ invalidatedAt: Date | null;
10
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.UpcomingInvoicePreviewEntry = exports.upcomingInvoicePreviewsTableName = void 0;
13
+ const interface_database_decorators_1 = require("@antelopejs/interface-database-decorators");
14
+ const constants_1 = require("@antelopejs/interface-dms/constants");
15
+ exports.upcomingInvoicePreviewsTableName = "saas_upcoming_invoice_previews";
16
+ let UpcomingInvoicePreviewEntry = class UpcomingInvoicePreviewEntry extends interface_database_decorators_1.Table {
17
+ };
18
+ exports.UpcomingInvoicePreviewEntry = UpcomingInvoicePreviewEntry;
19
+ __decorate([
20
+ (0, interface_database_decorators_1.Field)("string"),
21
+ __metadata("design:type", String)
22
+ ], UpcomingInvoicePreviewEntry.prototype, "_id", void 0);
23
+ __decorate([
24
+ (0, interface_database_decorators_1.Field)("any"),
25
+ __metadata("design:type", Object)
26
+ ], UpcomingInvoicePreviewEntry.prototype, "preview", void 0);
27
+ __decorate([
28
+ (0, interface_database_decorators_1.Field)("string"),
29
+ __metadata("design:type", Object)
30
+ ], UpcomingInvoicePreviewEntry.prototype, "sourceVersion", void 0);
31
+ __decorate([
32
+ (0, interface_database_decorators_1.Field)("date"),
33
+ __metadata("design:type", Object)
34
+ ], UpcomingInvoicePreviewEntry.prototype, "computedAt", void 0);
35
+ __decorate([
36
+ (0, interface_database_decorators_1.Field)("date"),
37
+ __metadata("design:type", Object)
38
+ ], UpcomingInvoicePreviewEntry.prototype, "invalidatedAt", void 0);
39
+ exports.UpcomingInvoicePreviewEntry = UpcomingInvoicePreviewEntry = __decorate([
40
+ (0, interface_database_decorators_1.RegisterTable)(exports.upcomingInvoicePreviewsTableName, constants_1.CORE_SCHEMA_NAME)
41
+ ], UpcomingInvoicePreviewEntry);
42
+ //# sourceMappingURL=preview-cache.table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview-cache.table.js","sourceRoot":"","sources":["../../../src/upcoming-invoice/db/preview-cache.table.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6FAImD;AACnD,mEAAuE;AAG1D,QAAA,gCAAgC,GAC3C,gCAAgC,CAAC;AAQ5B,IAAM,2BAA2B,GAAjC,MAAM,2BAA4B,SAAQ,qCAAK;CAiBrD,CAAA;AAjBY,kEAA2B;AAE9B;IADP,IAAA,qCAAK,EAAC,QAAQ,CAAC;;wDACI;AAGZ;IADP,IAAA,qCAAK,EAAC,KAAK,CAAC;;4DACkC;AAIvC;IADP,IAAA,qCAAK,EAAC,QAAQ,CAAC;;kEACqB;AAI7B;IADP,IAAA,qCAAK,EAAC,MAAM,CAAC;;+DACkB;AAGxB;IADP,IAAA,qCAAK,EAAC,MAAM,CAAC;;kEACqB;sCAhBxB,2BAA2B;IADvC,IAAA,6CAAa,EAAC,wCAAgC,EAAE,4BAAgB,CAAC;GACrD,2BAA2B,CAiBvC"}
@@ -0,0 +1,17 @@
1
+ import type { Plan, TenantSubscription } from "../db";
2
+ import { type PreviewOutcome } from "./outcomes";
3
+ export interface PreviewableSubscription {
4
+ subscription: TenantSubscription;
5
+ customerId: string;
6
+ subscriptionId: string;
7
+ }
8
+ export interface PreviewableEligibility {
9
+ isPreviewable: true;
10
+ target: PreviewableSubscription;
11
+ }
12
+ export interface SettledEligibility {
13
+ isPreviewable: false;
14
+ outcome: PreviewOutcome;
15
+ }
16
+ export type PreviewEligibility = PreviewableEligibility | SettledEligibility;
17
+ export declare function resolvePreviewEligibility(subscription: TenantSubscription | undefined, plan: Plan | undefined): PreviewEligibility;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolvePreviewEligibility = resolvePreviewEligibility;
4
+ const client_1 = require("../stripe/client");
5
+ const complimentary_1 = require("../workspaces/complimentary");
6
+ const free_workspace_guard_1 = require("../workspaces/free-workspace-guard");
7
+ const outcomes_1 = require("./outcomes");
8
+ const ELIGIBILITY_RULES = [
9
+ {
10
+ outcome: (0, outcomes_1.absent)("complimentary"),
11
+ applies: (subscription) => (0, complimentary_1.isComplimentarySubscription)(subscription),
12
+ },
13
+ {
14
+ outcome: (0, outcomes_1.absent)("subscription_not_configured"),
15
+ applies: (_subscription, plan) => !plan,
16
+ },
17
+ {
18
+ outcome: (0, outcomes_1.absent)("free_plan"),
19
+ applies: (_subscription, plan) => !!plan && (0, free_workspace_guard_1.isFreePlan)(plan),
20
+ },
21
+ {
22
+ outcome: (0, outcomes_1.absent)("customer_not_configured"),
23
+ applies: (subscription) => !subscription.stripeCustomerId,
24
+ },
25
+ ];
26
+ function toPreviewable(subscription) {
27
+ const { stripeCustomerId, stripeSubscriptionId } = subscription;
28
+ if (!stripeCustomerId || !stripeSubscriptionId)
29
+ return null;
30
+ return {
31
+ subscription,
32
+ customerId: stripeCustomerId,
33
+ subscriptionId: stripeSubscriptionId,
34
+ };
35
+ }
36
+ function settled(outcome) {
37
+ return { isPreviewable: false, outcome };
38
+ }
39
+ function resolvePreviewEligibility(subscription, plan) {
40
+ if (!subscription)
41
+ return settled((0, outcomes_1.absent)("subscription_not_configured"));
42
+ const rule = ELIGIBILITY_RULES.find((candidate) => candidate.applies(subscription, plan));
43
+ if (rule)
44
+ return settled(rule.outcome);
45
+ const target = toPreviewable(subscription);
46
+ if (!target)
47
+ return settled((0, outcomes_1.absent)("subscription_not_configured"));
48
+ if (!(0, client_1.isStripeConfigured)())
49
+ return settled((0, outcomes_1.unavailable)("stripe_not_configured"));
50
+ return { isPreviewable: true, target };
51
+ }
52
+ //# sourceMappingURL=eligibility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eligibility.js","sourceRoot":"","sources":["../../src/upcoming-invoice/eligibility.ts"],"names":[],"mappings":";;AA6EA,8DAcC;AA1FD,6CAAsD;AACtD,+DAA0E;AAC1E,6EAAgE;AAChE,yCAAsE;AAkCtE,MAAM,iBAAiB,GAAsB;IAC3C;QACE,OAAO,EAAE,IAAA,iBAAM,EAAC,eAAe,CAAC;QAChC,OAAO,EAAE,CAAC,YAAY,EAAE,EAAE,CAAC,IAAA,2CAA2B,EAAC,YAAY,CAAC;KACrE;IACD;QACE,OAAO,EAAE,IAAA,iBAAM,EAAC,6BAA6B,CAAC;QAC9C,OAAO,EAAE,CAAC,aAAa,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI;KACxC;IACD;QACE,OAAO,EAAE,IAAA,iBAAM,EAAC,WAAW,CAAC;QAC5B,OAAO,EAAE,CAAC,aAAa,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,IAAA,iCAAU,EAAC,IAAI,CAAC;KAC7D;IACD;QACE,OAAO,EAAE,IAAA,iBAAM,EAAC,yBAAyB,CAAC;QAC1C,OAAO,EAAE,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,gBAAgB;KAC1D;CACF,CAAC;AAEF,SAAS,aAAa,CACpB,YAAgC;IAEhC,MAAM,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,GAAG,YAAY,CAAC;IAChE,IAAI,CAAC,gBAAgB,IAAI,CAAC,oBAAoB;QAAE,OAAO,IAAI,CAAC;IAC5D,OAAO;QACL,YAAY;QACZ,UAAU,EAAE,gBAAgB;QAC5B,cAAc,EAAE,oBAAoB;KACrC,CAAC;AACJ,CAAC;AAED,SAAS,OAAO,CAAC,OAAuB;IACtC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC3C,CAAC;AAMD,SAAgB,yBAAyB,CACvC,YAA4C,EAC5C,IAAsB;IAEtB,IAAI,CAAC,YAAY;QAAE,OAAO,OAAO,CAAC,IAAA,iBAAM,EAAC,6BAA6B,CAAC,CAAC,CAAC;IACzE,MAAM,IAAI,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAChD,SAAS,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CACtC,CAAC;IACF,IAAI,IAAI;QAAE,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvC,MAAM,MAAM,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC;IAC3C,IAAI,CAAC,MAAM;QAAE,OAAO,OAAO,CAAC,IAAA,iBAAM,EAAC,6BAA6B,CAAC,CAAC,CAAC;IACnE,IAAI,CAAC,IAAA,2BAAkB,GAAE;QACvB,OAAO,OAAO,CAAC,IAAA,sBAAW,EAAC,uBAAuB,CAAC,CAAC,CAAC;IACvD,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AACzC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type Stripe from "stripe";
2
+ export declare function invalidatePreviewForStripeEvent(event: Stripe.Event): Promise<void>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.invalidatePreviewForStripeEvent = invalidatePreviewForStripeEvent;
4
+ const logging_1 = require("@antelopejs/interface-core/logging");
5
+ const webhook_shared_1 = require("../stripe/webhook-shared");
6
+ const preview_1 = require("./preview");
7
+ const LOG_PREFIX = "[dms-saas:upcoming-invoice]";
8
+ const CUSTOMER_OBJECT = "customer";
9
+ const INVALIDATING_EVENT_TYPES = new Set([
10
+ "invoice.created",
11
+ "invoice.finalized",
12
+ "invoice.paid",
13
+ "invoice.voided",
14
+ "customer.updated",
15
+ "customer.subscription.updated",
16
+ "customer.subscription.deleted",
17
+ ]);
18
+ function eventCustomerId(event) {
19
+ const object = event.data.object;
20
+ if (object.object === CUSTOMER_OBJECT)
21
+ return object.id ?? null;
22
+ return (0, webhook_shared_1.asCustomerId)(object.customer);
23
+ }
24
+ async function invalidatePreviewForStripeEvent(event) {
25
+ if (!INVALIDATING_EVENT_TYPES.has(event.type))
26
+ return;
27
+ const customerId = eventCustomerId(event);
28
+ if (!customerId)
29
+ return;
30
+ try {
31
+ const tenant = await (0, webhook_shared_1.findTenantByCustomerId)(customerId);
32
+ if (tenant)
33
+ await (0, preview_1.invalidateUpcomingInvoicePreview)(tenant._id);
34
+ }
35
+ catch (error) {
36
+ logging_1.Logging.Error(`${LOG_PREFIX} could not invalidate the preview after ${event.type} ${event.id}`, error);
37
+ }
38
+ }
39
+ //# sourceMappingURL=invalidation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invalidation.js","sourceRoot":"","sources":["../../src/upcoming-invoice/invalidation.ts"],"names":[],"mappings":";;AAyCA,0EAeC;AAxDD,gEAA6D;AAE7D,6DAAgF;AAChF,uCAA6D;AAE7D,MAAM,UAAU,GAAG,6BAA6B,CAAC;AACjD,MAAM,eAAe,GAAG,UAAU,CAAC;AAQnC,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAS;IAC/C,iBAAiB;IACjB,mBAAmB;IACnB,cAAc;IACd,gBAAgB;IAChB,kBAAkB;IAClB,+BAA+B;IAC/B,+BAA+B;CAChC,CAAC,CAAC;AAQH,SAAS,eAAe,CAAC,KAAmB;IAC1C,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,MAA6B,CAAC;IACxD,IAAI,MAAM,CAAC,MAAM,KAAK,eAAe;QAAE,OAAO,MAAM,CAAC,EAAE,IAAI,IAAI,CAAC;IAChE,OAAO,IAAA,6BAAY,EAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACvC,CAAC;AAOM,KAAK,UAAU,+BAA+B,CACnD,KAAmB;IAEnB,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC;QAAE,OAAO;IACtD,MAAM,UAAU,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IAC1C,IAAI,CAAC,UAAU;QAAE,OAAO;IACxB,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,IAAA,uCAAsB,EAAC,UAAU,CAAC,CAAC;QACxD,IAAI,MAAM;YAAE,MAAM,IAAA,0CAAgC,EAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,iBAAO,CAAC,KAAK,CACX,GAAG,UAAU,2CAA2C,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,EAAE,EAAE,EAChF,KAAK,CACN,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { AvailableUpcomingInvoicePreview } from "@antelopejs/interface-dms-saas/billing";
2
+ import type Stripe from "stripe";
3
+ export interface PreviewPricingContext {
4
+ billingDate: Date;
5
+ usageThrough: Date | null;
6
+ computedAt: Date;
7
+ }
8
+ export declare function toAvailablePreview(invoice: Stripe.Invoice, pricing: PreviewPricingContext): AvailableUpcomingInvoicePreview;
@@ -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,IAAI,CAAC,IAAI,KAAK,sBAAsB;QAAE,OAAO,cAAc,CAAC;IAChE,OAAO,IAAI,CA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AU,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,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAC7D,wBAAwB,CACzB,CAAC;AACJ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Q,EAAC,cAAS,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC;QACpD,CAAC,CAAC,SAAS,CAAC;IACd,MAAM,WAAW,GAAG,IAAA,uCAAyB,EAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IAClE,IAAI,CAAC,WAAW,CAAC,aAAa;QAAE,OAAO,IAAA,uBAAY,EAAC,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAC9E,MAAM,KAAK,GAAG,IAAA,4CAAmC,GAAE,CAAC;IACpD,MAAM,aAAa,GAAG,eAAe,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IACjE,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACd,MAAM,iBAAiB,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC;QAC1D,MAAM,MAAM,GAAG,MAAM,iBAAiB,CACpC,QAAQ,EACR,aAAa,EACb,iBAAiB,CAClB,CAAC;QACF,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC;IAC5B,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,IAAA,8BAAoB,EAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9E,IAAI,KAAK,GAAG,CAAC;QAAE,MAAM,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,CAAC,CAAC;IACzE,OAAO,OAAO,CAAC;AACjB,CAAC;AAGM,KAAK,UAAU,gCAAgC,CACpD,QAAgB;IAEhB,MAAM,IAAA,wCAAQ,EAAC,sDAAgC,CAAC,CAAC,UAAU,CACzD,QAAQ,EACR,IAAI,IAAI,EAAE,CACX,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { UpcomingInvoicePreview } from "@antelopejs/interface-dms-saas/billing";
2
+ 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":[],"mappings":";;AAyHA,oDAcC;AAvID,gEAA6D;AAM7D,iEAGoC;AAEpC,uCAA+C;AAC/C,yCAK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AAO,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,EAC9C,QAAQ,CAAC,EAAE,EACX,UAAU,CAAC,SAAS,EACpB,IAAI,GAAG,EAAE,CACV,C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AAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC;QAC7C,YAAY,EAAE,OAAO,CAAC,SAAS;KAChC,CAAC;AACJ,CAAC"}
@@ -10,8 +10,8 @@ export declare class InvoiceLinesType extends DataType {
10
10
  periodStart: z.ZodNullable<z.ZodDate>;
11
11
  periodEnd: z.ZodNullable<z.ZodDate>;
12
12
  }, "strip", z.ZodTypeAny, {
13
- currency: string;
14
13
  description: string;
14
+ currency: string;
15
15
  amount: number;
16
16
  periodStart: Date | null;
17
17
  periodEnd: Date | null;
@@ -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;