@saasicat/nest 1.0.0-rc.2 → 1.0.0-rc.21

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 (154) hide show
  1. package/README.md +44 -8
  2. package/dist/.build-stamp +1 -1
  3. package/dist/_entries.cjs +10214 -4796
  4. package/dist/admin/index.d.cts +5 -4
  5. package/dist/admin/index.d.ts +5 -4
  6. package/dist/admin/index.js +13 -9
  7. package/dist/{admin-resources.module-CpvzcfCc.d.cts → admin-resources.module-B4XNvdH-.d.cts} +1 -2
  8. package/dist/{admin-resources.module-DF5_Q7RD.d.ts → admin-resources.module-CWqdI9BV.d.ts} +1 -2
  9. package/dist/{admin-stats.service-TYiSUwIR.d.ts → admin-stats.service-CsLNt19Z.d.ts} +11 -7
  10. package/dist/{admin-stats.service-DfKupywR.d.cts → admin-stats.service-DrZrU8IJ.d.cts} +11 -7
  11. package/dist/{aggregation-B3CD0v_d.d.cts → aggregation-ChpZDh0g.d.ts} +39 -6
  12. package/dist/{aggregation-BFzW07DE.d.ts → aggregation-OpnhwzF5.d.cts} +39 -6
  13. package/dist/billing/index.d.cts +448 -108
  14. package/dist/billing/index.d.ts +448 -108
  15. package/dist/billing/index.js +108 -41
  16. package/dist/catalog/index.d.cts +74 -45
  17. package/dist/catalog/index.d.ts +74 -45
  18. package/dist/catalog/index.js +21 -13
  19. package/dist/catalog.module-C9O7BxRq.d.ts +180 -0
  20. package/dist/catalog.module-T-I5Ricz.d.cts +180 -0
  21. package/dist/checkout-offer/index.d.cts +17 -22
  22. package/dist/checkout-offer/index.d.ts +17 -22
  23. package/dist/checkout-offer/index.js +21 -7
  24. package/dist/checkout-offer.module-DFhGy6JO.d.cts +58 -0
  25. package/dist/checkout-offer.module-x7SP_dX4.d.ts +58 -0
  26. package/dist/checkout-offer.service-BeHgYikI.d.ts +242 -0
  27. package/dist/checkout-offer.service-CCVxG9b2.d.cts +242 -0
  28. package/dist/chunk-34XVPR6P.js +222 -0
  29. package/dist/{chunk-AOQJEYOL.js → chunk-3QVGA6JX.js} +3 -1
  30. package/dist/chunk-3RLWML2S.js +896 -0
  31. package/dist/{chunk-TXC3LHHB.js → chunk-4SDSYV4A.js} +21 -13
  32. package/dist/chunk-55QEDAMX.js +946 -0
  33. package/dist/chunk-5CKC7O52.js +140 -0
  34. package/dist/chunk-6PJE7EWO.js +185 -0
  35. package/dist/chunk-7NJKVC5X.js +353 -0
  36. package/dist/{chunk-RUNZ3X4C.js → chunk-AOS2JPDD.js} +1263 -185
  37. package/dist/{chunk-WOVQPXV4.js → chunk-CQ2ZZMTD.js} +702 -725
  38. package/dist/{chunk-NA6O63B7.js → chunk-F5X66HF5.js} +5 -5
  39. package/dist/chunk-FEQZCWUL.js +174 -0
  40. package/dist/{chunk-VIJ5NJWC.js → chunk-G6EZWECL.js} +107 -31
  41. package/dist/chunk-G7RQO2XO.js +0 -0
  42. package/dist/{chunk-N3L3AICU.js → chunk-GPQWGA6B.js} +5 -6
  43. package/dist/chunk-GZTL64QK.js +7 -0
  44. package/dist/{chunk-SABTXESR.js → chunk-J7NJRK3K.js} +17 -1
  45. package/dist/{chunk-SEPN52AD.js → chunk-JBCC6C3M.js} +566 -307
  46. package/dist/{chunk-I7GTA3RX.js → chunk-JQRA724W.js} +1 -1
  47. package/dist/{chunk-WXYJHZCN.js → chunk-JVAEKTJ4.js} +2 -14
  48. package/dist/chunk-KPEMTBOP.js +26 -0
  49. package/dist/chunk-LF6J4YYN.js +301 -0
  50. package/dist/{chunk-LTT736P3.js → chunk-LLYVYRGJ.js} +228 -387
  51. package/dist/{chunk-6Z7JR4EW.js → chunk-M47BNEY2.js} +1897 -633
  52. package/dist/{chunk-KFT5AIIH.js → chunk-NDLC5GYK.js} +206 -24
  53. package/dist/{chunk-O2J2HDXA.js → chunk-OOTEXP47.js} +3 -8
  54. package/dist/chunk-QPVDCKYS.js +702 -0
  55. package/dist/{chunk-NHVDCYK5.js → chunk-R5YCJBHY.js} +71 -106
  56. package/dist/{chunk-XBYAFEOR.js → chunk-S33SO5XX.js} +1 -1
  57. package/dist/chunk-SZ7RFPXA.js +10 -0
  58. package/dist/chunk-TBBZWZQT.js +98 -0
  59. package/dist/chunk-TOEFN7DN.js +295 -0
  60. package/dist/{chunk-7ZEGFL42.js → chunk-WHJSYKNC.js} +6 -6
  61. package/dist/chunk-WOEJ6K7M.js +55 -0
  62. package/dist/{chunk-AU3OOREM.js → chunk-XSSWYPP5.js} +16 -3
  63. package/dist/contract-line-item-money-B0Z3Ogur.d.cts +43 -0
  64. package/dist/contract-line-item-money-B0Z3Ogur.d.ts +43 -0
  65. package/dist/discovery/index.d.cts +2 -2
  66. package/dist/discovery/index.d.ts +2 -2
  67. package/dist/discovery/index.js +6 -6
  68. package/dist/{discovery.scanner-9cMqF95o.d.cts → discovery.scanner-DXKc6JkV.d.cts} +1 -1
  69. package/dist/{discovery.scanner-9cMqF95o.d.ts → discovery.scanner-DXKc6JkV.d.ts} +1 -1
  70. package/dist/{enforce-quota.interceptor-Df0e3OWe.d.cts → enforce-quota.interceptor-BFyVdWe8.d.cts} +6 -6
  71. package/dist/{enforce-quota.interceptor-DW3etVyI.d.ts → enforce-quota.interceptor-GaBXboGx.d.ts} +6 -6
  72. package/dist/entitlement/index.d.cts +27 -4
  73. package/dist/entitlement/index.d.ts +27 -4
  74. package/dist/entitlement/index.js +13 -8
  75. package/dist/index.d.cts +209 -28
  76. package/dist/index.d.ts +209 -28
  77. package/dist/index.js +285 -163
  78. package/dist/issuer-identity.check-CBO0vcsq.d.cts +197 -0
  79. package/dist/issuer-identity.check-Cz9CEMkZ.d.ts +197 -0
  80. package/dist/{module-options-COSEb0VW.d.ts → module-options-DmQ3G4sZ.d.ts} +135 -41
  81. package/dist/{module-options-BG3MzQva.d.cts → module-options-qAOwinHR.d.cts} +135 -41
  82. package/dist/payment-callback.service-CR84Xw1Z.d.cts +125 -0
  83. package/dist/payment-callback.service-CR84Xw1Z.d.ts +125 -0
  84. package/dist/payments/index.cjs +4 -0
  85. package/dist/payments/index.d.cts +187 -0
  86. package/dist/payments/index.d.ts +187 -0
  87. package/dist/payments/index.js +141 -0
  88. package/dist/payments.module-BdUq9ot_.d.cts +57 -0
  89. package/dist/payments.module-CQGv_VG7.d.ts +57 -0
  90. package/dist/plan-catalog-source-DWe-BGY1.d.cts +21 -0
  91. package/dist/plan-catalog-source-DWe-BGY1.d.ts +21 -0
  92. package/dist/{plan-resolution-Cgo_TR1H.d.cts → plan-resolution-CwUy_OqC.d.cts} +14 -0
  93. package/dist/{plan-resolution-Cgo_TR1H.d.ts → plan-resolution-CwUy_OqC.d.ts} +14 -0
  94. package/dist/{plan-versions.service-DChhbK6h.d.ts → plan-versions.service-C0N-Em2W.d.ts} +38 -64
  95. package/dist/{plan-versions.service-TPEtbN0r.d.cts → plan-versions.service-DARLh-qI.d.cts} +38 -64
  96. package/dist/platform/index.d.cts +52 -23
  97. package/dist/platform/index.d.ts +52 -23
  98. package/dist/platform/index.js +57 -36
  99. package/dist/promo/index.d.cts +23 -8
  100. package/dist/promo/index.d.ts +23 -8
  101. package/dist/promo/index.js +15 -7
  102. package/dist/{promo.module-DtvIycpt.d.cts → promo.module-CKkECmU8.d.cts} +9 -3
  103. package/dist/{promo.module-Z8h1PNX-.d.ts → promo.module-DuIJdK3U.d.ts} +9 -3
  104. package/dist/promo.service-BYBu6dy3.d.cts +215 -0
  105. package/dist/promo.service-CFjfF0Xm.d.ts +215 -0
  106. package/dist/registration/index.d.cts +104 -47
  107. package/dist/registration/index.d.ts +104 -47
  108. package/dist/registration/index.js +15 -9
  109. package/dist/subscriber/index.cjs +4 -0
  110. package/dist/subscriber/index.d.cts +28 -0
  111. package/dist/subscriber/index.d.ts +28 -0
  112. package/dist/subscriber/index.js +16 -0
  113. package/dist/subscriber.service-5W6Gi-1B.d.cts +68 -0
  114. package/dist/subscriber.service-5W6Gi-1B.d.ts +68 -0
  115. package/dist/subscription-contract/index.d.cts +4 -2
  116. package/dist/subscription-contract/index.d.ts +4 -2
  117. package/dist/subscription-contract/index.js +13 -5
  118. package/dist/{subscription-contract.module-fDFdQ0jm.d.ts → subscription-contract.module-BfIRpc1o.d.ts} +8 -2
  119. package/dist/{subscription-contract.module-CEK8HS5-.d.cts → subscription-contract.module-DTMuUJYd.d.cts} +8 -2
  120. package/dist/{subscription-contract.service-hD87MKyg.d.cts → subscription-contract.service-CPZrTM9C.d.ts} +32 -3
  121. package/dist/{subscription-contract.service-hD87MKyg.d.ts → subscription-contract.service-CfNApLuP.d.cts} +32 -3
  122. package/dist/tenant-billing.controller-BLqbsONe.d.ts +812 -0
  123. package/dist/tenant-billing.controller-DKbAqTbM.d.cts +812 -0
  124. package/dist/tenant-billing.module-ClbjzocC.d.cts +364 -0
  125. package/dist/tenant-billing.module-DohgJJ2m.d.ts +364 -0
  126. package/dist/tenant-billing.tokens-G-1xOlMr.d.cts +129 -0
  127. package/dist/tenant-billing.tokens-G-1xOlMr.d.ts +129 -0
  128. package/dist/testing/index.d.cts +44 -17
  129. package/dist/testing/index.d.ts +44 -17
  130. package/dist/testing/index.js +189 -40
  131. package/package.json +24 -4
  132. package/dist/catalog.module-BDDO6iwq.d.cts +0 -103
  133. package/dist/catalog.module-BTnMsE6u.d.ts +0 -103
  134. package/dist/checkout-offer.module-CMtiQJTT.d.ts +0 -39
  135. package/dist/checkout-offer.module-CVpWrzbe.d.cts +0 -39
  136. package/dist/checkout-offer.service-BLOv2HOo.d.cts +0 -49
  137. package/dist/checkout-offer.service-BLOv2HOo.d.ts +0 -49
  138. package/dist/chunk-57V6ZTI6.js +0 -22
  139. package/dist/chunk-BSK6YBLI.js +0 -87
  140. package/dist/chunk-DQKCK7DX.js +0 -217
  141. package/dist/chunk-VXEYLNIB.js +0 -632
  142. package/dist/chunk-WUDYIPYH.js +0 -715
  143. package/dist/define-saasicat-DROBe-b1.d.ts +0 -69
  144. package/dist/define-saasicat-vGBCkFys.d.cts +0 -69
  145. package/dist/promo.service-BJbKAmw3.d.cts +0 -112
  146. package/dist/promo.service-BJbKAmw3.d.ts +0 -112
  147. package/dist/tenant-billing.controller-BQ67mlmI.d.ts +0 -438
  148. package/dist/tenant-billing.controller-DS8kB8a7.d.cts +0 -438
  149. package/dist/tenant-billing.module-BznC3XtW.d.cts +0 -299
  150. package/dist/tenant-billing.module-wUbsQSFG.d.ts +0 -299
  151. /package/dist/{chunk-2FR6ZL7R.js → chunk-BHZOH2DY.js} +0 -0
  152. /package/dist/{chunk-2SLTRKXC.js → chunk-DFOW3JVO.js} +0 -0
  153. /package/dist/{chunk-DBZGV3HC.js → chunk-DU56UKEH.js} +0 -0
  154. /package/dist/{chunk-OYNHOY45.js → chunk-GAUEVIAE.js} +0 -0
@@ -1,299 +0,0 @@
1
- import { CanActivate, Type, DynamicModule, ForwardReference, Provider } from '@nestjs/common';
2
- import { NewContractLineItemData, BillingCycle, SubscriptionUsagePort, SubscriptionBundleRepository, BundleRepository, UsageSnapshotPort, TenantSubscriptionWritePort, SubscriptionContractRepository } from '@saasicat/core';
3
- import { P as ProviderSpec } from './di-CcNeq9v-.cjs';
4
-
5
- declare const FEATURE_GUARD_MARKER: unique symbol;
6
- /** A guard class or instance carrying the platform's marker. */
7
- interface MarkedFeatureGuard {
8
- [FEATURE_GUARD_MARKER]: true;
9
- }
10
- /** True when `target` is one of the platform's entitlement guards. */
11
- declare function isPlatformFeatureGuard(target: unknown): boolean;
12
-
13
- /**
14
- * List of all auth guards the platform controller should iterate in order
15
- * (analogous to `@UseGuards(JwtAuthGuard, TenantGuard, RolesGuard)`).
16
- * Provided via `forRoot.authGuards` — can be an array of existing instances
17
- * or a factory provider.
18
- */
19
- declare const TENANT_AUTH_GUARDS_TOKEN: unique symbol;
20
- /**
21
- * Resolver function `(req) => string` that extracts the `tenantId` from the
22
- * request. Default: `req.user.tenantId`.
23
- */
24
- declare const TENANT_ID_RESOLVER_TOKEN: unique symbol;
25
- /**
26
- * Resolver function `(req) => string` that extracts the `userId` from the
27
- * request. Default: `req.user.sub ?? req.user.id`.
28
- */
29
- declare const USER_ID_RESOLVER_TOKEN: unique symbol;
30
- /**
31
- * Resolver function `(req) => string` that extracts the user email from the
32
- * request. Optional — used by the audit-log path to build the AdminActor
33
- * (`{userId, email, source: 'web', context}`). Default: `req.user.email`.
34
- * If the consumer's JWT does not carry an email, the resolver can return
35
- * `null` — the audit-log path then falls back to `'unknown'`.
36
- */
37
- declare const USER_EMAIL_RESOLVER_TOKEN: unique symbol;
38
- /**
39
- * Resolver function `(req) => string` that extracts an audit context from the
40
- * request (e.g. session ID, trace ID). Default: `req.headers['x-session-id']`
41
- * or `'tenant-self-service'`.
42
- */
43
- declare const AUDIT_CONTEXT_RESOLVER_TOKEN: unique symbol;
44
- /** Adapter token: consumer's `SubscriptionUsagePort` implementation. */
45
- declare const SUBSCRIPTION_USAGE_PORT_TOKEN: unique symbol;
46
- /** Adapter token: consumer's `UsageSnapshotPort` implementation. */
47
- declare const USAGE_SNAPSHOT_PORT_TOKEN: unique symbol;
48
- /** Adapter token: consumer's `TenantSubscriptionWritePort` implementation. */
49
- declare const SUBSCRIPTION_WRITE_PORT_TOKEN: unique symbol;
50
- type TenantIdResolver = (req: unknown) => string | null | undefined;
51
- type UserIdResolver = (req: unknown) => string | null | undefined;
52
- type UserEmailResolver = (req: unknown) => string | null | undefined;
53
- type AuditContextResolver = (req: unknown) => string | null | undefined;
54
- type AuthGuardList = ReadonlyArray<CanActivate>;
55
- /**
56
- * Optional adapter token: projects the new trial end of a change
57
- * (app-specific trial logic, e.g. carry-over of the remaining time). Without a
58
- * port, `PlanChangePreviewDto.projectedTrialEndsAt` stays `null` and the wizard
59
- * falls back to the current trial end.
60
- */
61
- declare const TRIAL_PROJECTION_PORT_TOKEN: unique symbol;
62
- interface TrialProjectionInput {
63
- /** Current plan key of the subscription. */
64
- currentPlan: string;
65
- /** Target plan key of the change. */
66
- targetPlan: string;
67
- /** Current trial end (null = no trial). */
68
- currentTrialEndsAt: Date | null;
69
- /** Subscription status (e.g. 'TRIAL'/'ACTIVE'). */
70
- status: string;
71
- now: Date;
72
- }
73
- interface TrialProjectionPort {
74
- /**
75
- * Projected new trial end after the change. `null` if nothing changes or
76
- * the target package does not support a trial.
77
- */
78
- projectTrialEndsAt(input: TrialProjectionInput): Promise<Date | null>;
79
- }
80
- /**
81
- * Optional adapter token: provides due scheduled plan changes for the
82
- * `PendingPlanMaterializationService`. Without a port, the service is not
83
- * registered (materialization is opt-in).
84
- */
85
- declare const PENDING_PLAN_QUERY_PORT_TOKEN: unique symbol;
86
- /** A due scheduled plan change — minimal for materialization. */
87
- interface DuePendingPlanChange {
88
- tenantId: string;
89
- /** Target plan key of the scheduled change (`pendingPlan`). */
90
- pendingPlan: string;
91
- /** Target cycle (`pendingBillingCycle`); `null` → default MONTHLY. */
92
- pendingBillingCycle: string | null;
93
- }
94
- interface PendingPlanQueryPort {
95
- /**
96
- * Returns all subscriptions with a due scheduled plan change:
97
- * `pendingPlan != null AND pendingEffectiveAt <= now AND status != 'TRIAL'`.
98
- * TRIAL is excluded — there the trial lifecycle drives the transition.
99
- */
100
- findDuePendingPlanChanges(now: Date): Promise<DuePendingPlanChange[]>;
101
- }
102
-
103
- interface SelfServiceBlockedPlans {
104
- asTarget?: string[];
105
- asSource?: string[];
106
- }
107
- declare const SELF_SERVICE_BLOCKED_PLANS_TOKEN: unique symbol;
108
- /**
109
- * Bundle counterpart (#37): `bundleKeys` lists bundles that are not
110
- * bookable via self-service (only via sales/special contract).
111
- * Applies in `SubscriptionBundlesService.addBundleToSubscription`
112
- * (enforcement, 422) and in the bundle preview (blocker indication).
113
- */
114
- interface SelfServiceBlockedBundles {
115
- bundleKeys?: string[];
116
- }
117
- declare const SELF_SERVICE_BLOCKED_BUNDLES_TOKEN: unique symbol;
118
-
119
- /**
120
- * Optional hook token: the platform `changePlan` path + the
121
- * `PendingPlanMaterializationService` call the freeze after the plan mutation
122
- * (analogous to `TrialProjectionPort`). Without a port nothing is frozen — the
123
- * entitlements then stay catalog-/version-pinned as before.
124
- */
125
- declare const CONTRACT_FREEZE_PORT_TOKEN: unique symbol;
126
- /** Adapter token: consumer-specific bundle/version data access. */
127
- declare const CONTRACT_FREEZE_SOURCE_PORT_TOKEN: unique symbol;
128
- /** Config token: the consumer's `projectKey` for the contract. */
129
- declare const CONTRACT_FREEZE_PROJECT_KEY_TOKEN: unique symbol;
130
- interface ContractFreezePort {
131
- /**
132
- * Freezes the agreed service at `effectiveFrom` as the new active
133
- * `SubscriptionContract` (supersedes the previous one). Non-fatal for the
134
- * caller — the plan change is already persisted.
135
- */
136
- freezeOnPlanChange(tenantId: string, newPlan: string, billingCycle: BillingCycle, effectiveFrom: Date): Promise<void>;
137
- }
138
- /** Frozen bundle line items + their version ids (trace). */
139
- interface ContractFreezeBundleSnapshot {
140
- lineItems: NewContractLineItemData[];
141
- bundleVersionIds: string[];
142
- }
143
- /**
144
- * Consumer-specific data access for the freeze: live PlanVersion id
145
- * (trace) + booked bundles as contract line items. The generic freeze
146
- * logic (plan line item from the catalog, snapshot, contract assembly) lives in
147
- * the platform `SubscriptionContractFreezeService`.
148
- */
149
- interface ContractFreezeSourcePort {
150
- /** Live (published, non-superseded) PlanVersion id of the target plan, or null. */
151
- findLivePlanVersionId(planId: string): Promise<string | null>;
152
- /**
153
- * The tenant's active (non-terminated) bundle bookings as line items.
154
- * `vatRate` is passed through so the gross price is computed consistently
155
- * with the catalog VAT. Apps without a bundle schema return empty lists.
156
- */
157
- loadBookedBundles(tenantId: string, cycle: 'monthly' | 'yearly', vatRate: number): Promise<ContractFreezeBundleSnapshot>;
158
- }
159
-
160
- interface SubscriptionBundleControllerOptions {
161
- extraGuards?: Array<Type<CanActivate>>;
162
- /**
163
- * Auth guard list analogous to `TenantBillingModule.forRoot.authGuards`.
164
- * Without this list, `ComposedTenantAuthGuard` blocks fail-closed.
165
- */
166
- authGuards?: ProviderSpec<ReadonlyArray<CanActivate>>;
167
- /**
168
- * Usage port for subscription lookup and current plan compatibility.
169
- * If not set, an imported module must export the token.
170
- */
171
- subscriptionUsagePort?: ProviderSpec<SubscriptionUsagePort>;
172
- /** Optional tenant-ID resolver. Default: `req.user.tenantId`. */
173
- tenantIdResolver?: TenantIdResolver;
174
- }
175
- interface SubscriptionBundleModuleOptions {
176
- subscriptionBundleRepository: ProviderSpec<SubscriptionBundleRepository>;
177
- /**
178
- * Optional — if omitted, `BUNDLE_REPOSITORY_TOKEN` is expected via
179
- * default inject from the DI scope (typically via an imported
180
- * `CatalogModule`).
181
- */
182
- bundleRepository?: ProviderSpec<BundleRepository>;
183
- /** Default minimum term (months). Default = 12. */
184
- defaultMinimumTermMonths?: number;
185
- /**
186
- * Self-service policy (#37): bundles that are only bookable via sales.
187
- * Applies in `addBundleToSubscription` (422 BUNDLE_NOT_SELF_SERVICE)
188
- * and in the preview (blocker).
189
- */
190
- selfServiceBlockedBundles?: SelfServiceBlockedBundles;
191
- /**
192
- * If set: the tenant self-service controller is mounted at
193
- * `/billing/subscription-bundles` (GET/POST/DELETE). The
194
- * `extraGuards` are applied in addition to the platform default
195
- * `ComposedTenantAuthGuard` (role/MFA guards).
196
- *
197
- * Prerequisite: the consumer has already registered `TenantBillingModule`
198
- * — the controller needs `SUBSCRIPTION_USAGE_PORT_TOKEN`
199
- * + `TENANT_ID_RESOLVER_TOKEN` in the same DI scope.
200
- */
201
- controller?: SubscriptionBundleControllerOptions;
202
- imports?: Array<Type<unknown> | DynamicModule | Promise<DynamicModule> | ForwardReference>;
203
- extraProviders?: Provider[];
204
- global?: boolean;
205
- }
206
- declare class SubscriptionBundleModule {
207
- static forRoot(options: SubscriptionBundleModuleOptions): DynamicModule;
208
- }
209
-
210
- interface TenantBillingModuleOptions {
211
- /**
212
- * App guards in the order in which they should be executed
213
- * (e.g. `[JwtAuthGuard, TenantGuard]`). The platform combines them via
214
- * `ComposedTenantAuthGuard`. At least one guard is mandatory —
215
- * missing configuration leads to 403 (safe default).
216
- *
217
- * Variant 1: array of guard instances (e.g. via factory provider).
218
- * Variant 2: Pick<FactoryProvider, 'useFactory' | 'inject'> — apps
219
- * pass their guard classes through via `inject` and the factory builds
220
- * the array.
221
- */
222
- authGuards: ProviderSpec<ReadonlyArray<CanActivate>>;
223
- /** Adapter to the subscription display form (`GET /billing/usage`). */
224
- subscriptionUsagePort: ProviderSpec<SubscriptionUsagePort>;
225
- /** Adapter to usage counters of all `quotaKeys`. */
226
- usageSnapshotPort: ProviderSpec<UsageSnapshotPort>;
227
- /** Adapter for plan/add-on mutations (phase C). */
228
- subscriptionWritePort: ProviderSpec<TenantSubscriptionWritePort>;
229
- /**
230
- * Optional adapter that provides the projected new trial end of a change
231
- * (app trial logic, e.g. carry-over). Without a port,
232
- * `PlanChangePreviewDto.projectedTrialEndsAt` stays `null`.
233
- */
234
- trialProjectionPort?: ProviderSpec<TrialProjectionPort>;
235
- /**
236
- * Optional adapter that provides due scheduled plan changes (#19). If it is
237
- * passed, the module registers the `PendingPlanMaterializationService`
238
- * (exported) — the consumer triggers it via its own cron. Without a
239
- * port, the materialization stays disabled (lazy resolution as before).
240
- */
241
- pendingPlanQueryPort?: ProviderSpec<PendingPlanQueryPort>;
242
- /**
243
- * Optional contract freeze hook (#18). If it is configured, the
244
- * platform `changePlan` path (non-TRIAL) AND the materialization freeze
245
- * the agreed service after the plan mutation as a `SubscriptionContract`
246
- * (analogous to `trialProjectionPort`). Consumer-specific are only `projectKey`
247
- * + bundle/version data access (`sourcePort`); the contract logic is
248
- * generic. `subscriptionContractRepository` is the same repo that also goes
249
- * to `EntitlementModule.forRoot` — the freeze needs it in its own scope.
250
- */
251
- contractFreeze?: {
252
- projectKey: string;
253
- sourcePort: ProviderSpec<ContractFreezeSourcePort>;
254
- subscriptionContractRepository: ProviderSpec<SubscriptionContractRepository>;
255
- };
256
- /**
257
- * Plans that are not accepted as target/source via self-service
258
- * (typically ENTERPRISE → special contract). `null`/undefined = no blocks.
259
- */
260
- selfServiceBlockedPlans?: SelfServiceBlockedPlans;
261
- /** Optional tenant ID resolver. Default: `req.user.tenantId`. */
262
- tenantIdResolver?: TenantIdResolver;
263
- /** Optional user ID resolver. Default: `req.user.sub ?? req.user.id`. */
264
- userIdResolver?: UserIdResolver;
265
- /**
266
- * Optional email resolver for the audit log path. Default: `req.user.email`.
267
- * If the consumer JWT does not include the email, the resolver can
268
- * return `null` — the audit log then uses `'unknown'`.
269
- */
270
- userEmailResolver?: UserEmailResolver;
271
- /**
272
- * Optional audit context resolver (session ID / trace ID). Default:
273
- * `req.headers['x-session-id']` or `'tenant-self-service'`.
274
- */
275
- auditContextResolver?: AuditContextResolver;
276
- /**
277
- * Modules whose providers must be visible within this module.
278
- * Typical use case: the app's own `AuthModule`, so that the `JwtAuthGuard`
279
- * is injectable in the `authGuards` factory. Without this entry NestJS throws
280
- * `UnknownDependenciesException` for JwtAuthGuard.
281
- */
282
- imports?: Array<Type<unknown> | DynamicModule | Promise<DynamicModule> | ForwardReference>;
283
- /**
284
- * Additional providers that are registered in the DynamicModule itself —
285
- * typically: the adapter classes referenced in `inject:[Adapter]` lists
286
- * (e.g. `PrismaSubscriptionUsagePort`). NestJS 11.1.19
287
- * resolves factory inject tokens only in the DynamicModule's own scope.
288
- */
289
- extraProviders?: Provider[];
290
- /** Additional providers this module makes visible to importing modules. */
291
- extraExports?: NonNullable<DynamicModule['exports']>;
292
- /** Register the module globally — default `false`. */
293
- global?: boolean;
294
- }
295
- declare class TenantBillingModule {
296
- static forRoot(options: TenantBillingModuleOptions): DynamicModule;
297
- }
298
-
299
- export { AUDIT_CONTEXT_RESOLVER_TOKEN as A, type UserIdResolver as B, CONTRACT_FREEZE_PORT_TOKEN as C, type DuePendingPlanChange as D, isPlatformFeatureGuard as E, FEATURE_GUARD_MARKER as F, type MarkedFeatureGuard as M, PENDING_PLAN_QUERY_PORT_TOKEN as P, SELF_SERVICE_BLOCKED_BUNDLES_TOKEN as S, TENANT_AUTH_GUARDS_TOKEN as T, USAGE_SNAPSHOT_PORT_TOKEN as U, type AuditContextResolver as a, type AuthGuardList as b, CONTRACT_FREEZE_PROJECT_KEY_TOKEN as c, CONTRACT_FREEZE_SOURCE_PORT_TOKEN as d, type ContractFreezeBundleSnapshot as e, type ContractFreezePort as f, type ContractFreezeSourcePort as g, type PendingPlanQueryPort as h, SELF_SERVICE_BLOCKED_PLANS_TOKEN as i, SUBSCRIPTION_USAGE_PORT_TOKEN as j, SUBSCRIPTION_WRITE_PORT_TOKEN as k, type SelfServiceBlockedBundles as l, type SelfServiceBlockedPlans as m, type SubscriptionBundleControllerOptions as n, SubscriptionBundleModule as o, type SubscriptionBundleModuleOptions as p, TENANT_ID_RESOLVER_TOKEN as q, TRIAL_PROJECTION_PORT_TOKEN as r, TenantBillingModule as s, type TenantBillingModuleOptions as t, type TenantIdResolver as u, type TrialProjectionInput as v, type TrialProjectionPort as w, USER_EMAIL_RESOLVER_TOKEN as x, USER_ID_RESOLVER_TOKEN as y, type UserEmailResolver as z };
@@ -1,299 +0,0 @@
1
- import { CanActivate, Type, DynamicModule, ForwardReference, Provider } from '@nestjs/common';
2
- import { NewContractLineItemData, BillingCycle, SubscriptionUsagePort, SubscriptionBundleRepository, BundleRepository, UsageSnapshotPort, TenantSubscriptionWritePort, SubscriptionContractRepository } from '@saasicat/core';
3
- import { P as ProviderSpec } from './di-CcNeq9v-.js';
4
-
5
- declare const FEATURE_GUARD_MARKER: unique symbol;
6
- /** A guard class or instance carrying the platform's marker. */
7
- interface MarkedFeatureGuard {
8
- [FEATURE_GUARD_MARKER]: true;
9
- }
10
- /** True when `target` is one of the platform's entitlement guards. */
11
- declare function isPlatformFeatureGuard(target: unknown): boolean;
12
-
13
- /**
14
- * List of all auth guards the platform controller should iterate in order
15
- * (analogous to `@UseGuards(JwtAuthGuard, TenantGuard, RolesGuard)`).
16
- * Provided via `forRoot.authGuards` — can be an array of existing instances
17
- * or a factory provider.
18
- */
19
- declare const TENANT_AUTH_GUARDS_TOKEN: unique symbol;
20
- /**
21
- * Resolver function `(req) => string` that extracts the `tenantId` from the
22
- * request. Default: `req.user.tenantId`.
23
- */
24
- declare const TENANT_ID_RESOLVER_TOKEN: unique symbol;
25
- /**
26
- * Resolver function `(req) => string` that extracts the `userId` from the
27
- * request. Default: `req.user.sub ?? req.user.id`.
28
- */
29
- declare const USER_ID_RESOLVER_TOKEN: unique symbol;
30
- /**
31
- * Resolver function `(req) => string` that extracts the user email from the
32
- * request. Optional — used by the audit-log path to build the AdminActor
33
- * (`{userId, email, source: 'web', context}`). Default: `req.user.email`.
34
- * If the consumer's JWT does not carry an email, the resolver can return
35
- * `null` — the audit-log path then falls back to `'unknown'`.
36
- */
37
- declare const USER_EMAIL_RESOLVER_TOKEN: unique symbol;
38
- /**
39
- * Resolver function `(req) => string` that extracts an audit context from the
40
- * request (e.g. session ID, trace ID). Default: `req.headers['x-session-id']`
41
- * or `'tenant-self-service'`.
42
- */
43
- declare const AUDIT_CONTEXT_RESOLVER_TOKEN: unique symbol;
44
- /** Adapter token: consumer's `SubscriptionUsagePort` implementation. */
45
- declare const SUBSCRIPTION_USAGE_PORT_TOKEN: unique symbol;
46
- /** Adapter token: consumer's `UsageSnapshotPort` implementation. */
47
- declare const USAGE_SNAPSHOT_PORT_TOKEN: unique symbol;
48
- /** Adapter token: consumer's `TenantSubscriptionWritePort` implementation. */
49
- declare const SUBSCRIPTION_WRITE_PORT_TOKEN: unique symbol;
50
- type TenantIdResolver = (req: unknown) => string | null | undefined;
51
- type UserIdResolver = (req: unknown) => string | null | undefined;
52
- type UserEmailResolver = (req: unknown) => string | null | undefined;
53
- type AuditContextResolver = (req: unknown) => string | null | undefined;
54
- type AuthGuardList = ReadonlyArray<CanActivate>;
55
- /**
56
- * Optional adapter token: projects the new trial end of a change
57
- * (app-specific trial logic, e.g. carry-over of the remaining time). Without a
58
- * port, `PlanChangePreviewDto.projectedTrialEndsAt` stays `null` and the wizard
59
- * falls back to the current trial end.
60
- */
61
- declare const TRIAL_PROJECTION_PORT_TOKEN: unique symbol;
62
- interface TrialProjectionInput {
63
- /** Current plan key of the subscription. */
64
- currentPlan: string;
65
- /** Target plan key of the change. */
66
- targetPlan: string;
67
- /** Current trial end (null = no trial). */
68
- currentTrialEndsAt: Date | null;
69
- /** Subscription status (e.g. 'TRIAL'/'ACTIVE'). */
70
- status: string;
71
- now: Date;
72
- }
73
- interface TrialProjectionPort {
74
- /**
75
- * Projected new trial end after the change. `null` if nothing changes or
76
- * the target package does not support a trial.
77
- */
78
- projectTrialEndsAt(input: TrialProjectionInput): Promise<Date | null>;
79
- }
80
- /**
81
- * Optional adapter token: provides due scheduled plan changes for the
82
- * `PendingPlanMaterializationService`. Without a port, the service is not
83
- * registered (materialization is opt-in).
84
- */
85
- declare const PENDING_PLAN_QUERY_PORT_TOKEN: unique symbol;
86
- /** A due scheduled plan change — minimal for materialization. */
87
- interface DuePendingPlanChange {
88
- tenantId: string;
89
- /** Target plan key of the scheduled change (`pendingPlan`). */
90
- pendingPlan: string;
91
- /** Target cycle (`pendingBillingCycle`); `null` → default MONTHLY. */
92
- pendingBillingCycle: string | null;
93
- }
94
- interface PendingPlanQueryPort {
95
- /**
96
- * Returns all subscriptions with a due scheduled plan change:
97
- * `pendingPlan != null AND pendingEffectiveAt <= now AND status != 'TRIAL'`.
98
- * TRIAL is excluded — there the trial lifecycle drives the transition.
99
- */
100
- findDuePendingPlanChanges(now: Date): Promise<DuePendingPlanChange[]>;
101
- }
102
-
103
- interface SelfServiceBlockedPlans {
104
- asTarget?: string[];
105
- asSource?: string[];
106
- }
107
- declare const SELF_SERVICE_BLOCKED_PLANS_TOKEN: unique symbol;
108
- /**
109
- * Bundle counterpart (#37): `bundleKeys` lists bundles that are not
110
- * bookable via self-service (only via sales/special contract).
111
- * Applies in `SubscriptionBundlesService.addBundleToSubscription`
112
- * (enforcement, 422) and in the bundle preview (blocker indication).
113
- */
114
- interface SelfServiceBlockedBundles {
115
- bundleKeys?: string[];
116
- }
117
- declare const SELF_SERVICE_BLOCKED_BUNDLES_TOKEN: unique symbol;
118
-
119
- /**
120
- * Optional hook token: the platform `changePlan` path + the
121
- * `PendingPlanMaterializationService` call the freeze after the plan mutation
122
- * (analogous to `TrialProjectionPort`). Without a port nothing is frozen — the
123
- * entitlements then stay catalog-/version-pinned as before.
124
- */
125
- declare const CONTRACT_FREEZE_PORT_TOKEN: unique symbol;
126
- /** Adapter token: consumer-specific bundle/version data access. */
127
- declare const CONTRACT_FREEZE_SOURCE_PORT_TOKEN: unique symbol;
128
- /** Config token: the consumer's `projectKey` for the contract. */
129
- declare const CONTRACT_FREEZE_PROJECT_KEY_TOKEN: unique symbol;
130
- interface ContractFreezePort {
131
- /**
132
- * Freezes the agreed service at `effectiveFrom` as the new active
133
- * `SubscriptionContract` (supersedes the previous one). Non-fatal for the
134
- * caller — the plan change is already persisted.
135
- */
136
- freezeOnPlanChange(tenantId: string, newPlan: string, billingCycle: BillingCycle, effectiveFrom: Date): Promise<void>;
137
- }
138
- /** Frozen bundle line items + their version ids (trace). */
139
- interface ContractFreezeBundleSnapshot {
140
- lineItems: NewContractLineItemData[];
141
- bundleVersionIds: string[];
142
- }
143
- /**
144
- * Consumer-specific data access for the freeze: live PlanVersion id
145
- * (trace) + booked bundles as contract line items. The generic freeze
146
- * logic (plan line item from the catalog, snapshot, contract assembly) lives in
147
- * the platform `SubscriptionContractFreezeService`.
148
- */
149
- interface ContractFreezeSourcePort {
150
- /** Live (published, non-superseded) PlanVersion id of the target plan, or null. */
151
- findLivePlanVersionId(planId: string): Promise<string | null>;
152
- /**
153
- * The tenant's active (non-terminated) bundle bookings as line items.
154
- * `vatRate` is passed through so the gross price is computed consistently
155
- * with the catalog VAT. Apps without a bundle schema return empty lists.
156
- */
157
- loadBookedBundles(tenantId: string, cycle: 'monthly' | 'yearly', vatRate: number): Promise<ContractFreezeBundleSnapshot>;
158
- }
159
-
160
- interface SubscriptionBundleControllerOptions {
161
- extraGuards?: Array<Type<CanActivate>>;
162
- /**
163
- * Auth guard list analogous to `TenantBillingModule.forRoot.authGuards`.
164
- * Without this list, `ComposedTenantAuthGuard` blocks fail-closed.
165
- */
166
- authGuards?: ProviderSpec<ReadonlyArray<CanActivate>>;
167
- /**
168
- * Usage port for subscription lookup and current plan compatibility.
169
- * If not set, an imported module must export the token.
170
- */
171
- subscriptionUsagePort?: ProviderSpec<SubscriptionUsagePort>;
172
- /** Optional tenant-ID resolver. Default: `req.user.tenantId`. */
173
- tenantIdResolver?: TenantIdResolver;
174
- }
175
- interface SubscriptionBundleModuleOptions {
176
- subscriptionBundleRepository: ProviderSpec<SubscriptionBundleRepository>;
177
- /**
178
- * Optional — if omitted, `BUNDLE_REPOSITORY_TOKEN` is expected via
179
- * default inject from the DI scope (typically via an imported
180
- * `CatalogModule`).
181
- */
182
- bundleRepository?: ProviderSpec<BundleRepository>;
183
- /** Default minimum term (months). Default = 12. */
184
- defaultMinimumTermMonths?: number;
185
- /**
186
- * Self-service policy (#37): bundles that are only bookable via sales.
187
- * Applies in `addBundleToSubscription` (422 BUNDLE_NOT_SELF_SERVICE)
188
- * and in the preview (blocker).
189
- */
190
- selfServiceBlockedBundles?: SelfServiceBlockedBundles;
191
- /**
192
- * If set: the tenant self-service controller is mounted at
193
- * `/billing/subscription-bundles` (GET/POST/DELETE). The
194
- * `extraGuards` are applied in addition to the platform default
195
- * `ComposedTenantAuthGuard` (role/MFA guards).
196
- *
197
- * Prerequisite: the consumer has already registered `TenantBillingModule`
198
- * — the controller needs `SUBSCRIPTION_USAGE_PORT_TOKEN`
199
- * + `TENANT_ID_RESOLVER_TOKEN` in the same DI scope.
200
- */
201
- controller?: SubscriptionBundleControllerOptions;
202
- imports?: Array<Type<unknown> | DynamicModule | Promise<DynamicModule> | ForwardReference>;
203
- extraProviders?: Provider[];
204
- global?: boolean;
205
- }
206
- declare class SubscriptionBundleModule {
207
- static forRoot(options: SubscriptionBundleModuleOptions): DynamicModule;
208
- }
209
-
210
- interface TenantBillingModuleOptions {
211
- /**
212
- * App guards in the order in which they should be executed
213
- * (e.g. `[JwtAuthGuard, TenantGuard]`). The platform combines them via
214
- * `ComposedTenantAuthGuard`. At least one guard is mandatory —
215
- * missing configuration leads to 403 (safe default).
216
- *
217
- * Variant 1: array of guard instances (e.g. via factory provider).
218
- * Variant 2: Pick<FactoryProvider, 'useFactory' | 'inject'> — apps
219
- * pass their guard classes through via `inject` and the factory builds
220
- * the array.
221
- */
222
- authGuards: ProviderSpec<ReadonlyArray<CanActivate>>;
223
- /** Adapter to the subscription display form (`GET /billing/usage`). */
224
- subscriptionUsagePort: ProviderSpec<SubscriptionUsagePort>;
225
- /** Adapter to usage counters of all `quotaKeys`. */
226
- usageSnapshotPort: ProviderSpec<UsageSnapshotPort>;
227
- /** Adapter for plan/add-on mutations (phase C). */
228
- subscriptionWritePort: ProviderSpec<TenantSubscriptionWritePort>;
229
- /**
230
- * Optional adapter that provides the projected new trial end of a change
231
- * (app trial logic, e.g. carry-over). Without a port,
232
- * `PlanChangePreviewDto.projectedTrialEndsAt` stays `null`.
233
- */
234
- trialProjectionPort?: ProviderSpec<TrialProjectionPort>;
235
- /**
236
- * Optional adapter that provides due scheduled plan changes (#19). If it is
237
- * passed, the module registers the `PendingPlanMaterializationService`
238
- * (exported) — the consumer triggers it via its own cron. Without a
239
- * port, the materialization stays disabled (lazy resolution as before).
240
- */
241
- pendingPlanQueryPort?: ProviderSpec<PendingPlanQueryPort>;
242
- /**
243
- * Optional contract freeze hook (#18). If it is configured, the
244
- * platform `changePlan` path (non-TRIAL) AND the materialization freeze
245
- * the agreed service after the plan mutation as a `SubscriptionContract`
246
- * (analogous to `trialProjectionPort`). Consumer-specific are only `projectKey`
247
- * + bundle/version data access (`sourcePort`); the contract logic is
248
- * generic. `subscriptionContractRepository` is the same repo that also goes
249
- * to `EntitlementModule.forRoot` — the freeze needs it in its own scope.
250
- */
251
- contractFreeze?: {
252
- projectKey: string;
253
- sourcePort: ProviderSpec<ContractFreezeSourcePort>;
254
- subscriptionContractRepository: ProviderSpec<SubscriptionContractRepository>;
255
- };
256
- /**
257
- * Plans that are not accepted as target/source via self-service
258
- * (typically ENTERPRISE → special contract). `null`/undefined = no blocks.
259
- */
260
- selfServiceBlockedPlans?: SelfServiceBlockedPlans;
261
- /** Optional tenant ID resolver. Default: `req.user.tenantId`. */
262
- tenantIdResolver?: TenantIdResolver;
263
- /** Optional user ID resolver. Default: `req.user.sub ?? req.user.id`. */
264
- userIdResolver?: UserIdResolver;
265
- /**
266
- * Optional email resolver for the audit log path. Default: `req.user.email`.
267
- * If the consumer JWT does not include the email, the resolver can
268
- * return `null` — the audit log then uses `'unknown'`.
269
- */
270
- userEmailResolver?: UserEmailResolver;
271
- /**
272
- * Optional audit context resolver (session ID / trace ID). Default:
273
- * `req.headers['x-session-id']` or `'tenant-self-service'`.
274
- */
275
- auditContextResolver?: AuditContextResolver;
276
- /**
277
- * Modules whose providers must be visible within this module.
278
- * Typical use case: the app's own `AuthModule`, so that the `JwtAuthGuard`
279
- * is injectable in the `authGuards` factory. Without this entry NestJS throws
280
- * `UnknownDependenciesException` for JwtAuthGuard.
281
- */
282
- imports?: Array<Type<unknown> | DynamicModule | Promise<DynamicModule> | ForwardReference>;
283
- /**
284
- * Additional providers that are registered in the DynamicModule itself —
285
- * typically: the adapter classes referenced in `inject:[Adapter]` lists
286
- * (e.g. `PrismaSubscriptionUsagePort`). NestJS 11.1.19
287
- * resolves factory inject tokens only in the DynamicModule's own scope.
288
- */
289
- extraProviders?: Provider[];
290
- /** Additional providers this module makes visible to importing modules. */
291
- extraExports?: NonNullable<DynamicModule['exports']>;
292
- /** Register the module globally — default `false`. */
293
- global?: boolean;
294
- }
295
- declare class TenantBillingModule {
296
- static forRoot(options: TenantBillingModuleOptions): DynamicModule;
297
- }
298
-
299
- export { AUDIT_CONTEXT_RESOLVER_TOKEN as A, type UserIdResolver as B, CONTRACT_FREEZE_PORT_TOKEN as C, type DuePendingPlanChange as D, isPlatformFeatureGuard as E, FEATURE_GUARD_MARKER as F, type MarkedFeatureGuard as M, PENDING_PLAN_QUERY_PORT_TOKEN as P, SELF_SERVICE_BLOCKED_BUNDLES_TOKEN as S, TENANT_AUTH_GUARDS_TOKEN as T, USAGE_SNAPSHOT_PORT_TOKEN as U, type AuditContextResolver as a, type AuthGuardList as b, CONTRACT_FREEZE_PROJECT_KEY_TOKEN as c, CONTRACT_FREEZE_SOURCE_PORT_TOKEN as d, type ContractFreezeBundleSnapshot as e, type ContractFreezePort as f, type ContractFreezeSourcePort as g, type PendingPlanQueryPort as h, SELF_SERVICE_BLOCKED_PLANS_TOKEN as i, SUBSCRIPTION_USAGE_PORT_TOKEN as j, SUBSCRIPTION_WRITE_PORT_TOKEN as k, type SelfServiceBlockedBundles as l, type SelfServiceBlockedPlans as m, type SubscriptionBundleControllerOptions as n, SubscriptionBundleModule as o, type SubscriptionBundleModuleOptions as p, TENANT_ID_RESOLVER_TOKEN as q, TRIAL_PROJECTION_PORT_TOKEN as r, TenantBillingModule as s, type TenantBillingModuleOptions as t, type TenantIdResolver as u, type TrialProjectionInput as v, type TrialProjectionPort as w, USER_EMAIL_RESOLVER_TOKEN as x, USER_ID_RESOLVER_TOKEN as y, type UserEmailResolver as z };
File without changes
File without changes
File without changes
File without changes