@saasicat/nest 0.7.0 → 0.9.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 (59) hide show
  1. package/dist/admin/index.cjs +262 -7
  2. package/dist/admin/index.d.cts +6 -4
  3. package/dist/admin/index.d.ts +6 -4
  4. package/dist/admin/index.js +12 -4
  5. package/dist/{admin-manifest.service-Cp6uwvmt.d.cts → admin-manifest.service-BMeSLRW4.d.ts} +1 -1
  6. package/dist/{admin-manifest.service-UGgzR1x-.d.ts → admin-manifest.service-StAQe6QO.d.cts} +1 -1
  7. package/dist/admin-resources.module-BybEjZs-.d.cts +40 -0
  8. package/dist/admin-resources.module-CUCLlUAi.d.ts +40 -0
  9. package/dist/billing/index.cjs +3 -1
  10. package/dist/billing/index.d.cts +5 -287
  11. package/dist/billing/index.d.ts +5 -287
  12. package/dist/billing/index.js +5 -8
  13. package/dist/catalog/index.d.cts +4 -101
  14. package/dist/catalog/index.d.ts +4 -101
  15. package/dist/catalog/index.js +12 -10
  16. package/dist/catalog.module-BKObceo0.d.ts +103 -0
  17. package/dist/catalog.module-Dw2Hrbyu.d.cts +103 -0
  18. package/dist/{chunk-U6HT27J7.js → chunk-3M6VLT5N.js} +257 -6
  19. package/dist/chunk-7K5PT2LX.js +211 -0
  20. package/dist/{chunk-RZU4HIAN.js → chunk-GW2I3JZD.js} +25 -22
  21. package/dist/{chunk-6LP7CDS2.js → chunk-HXAWPPFW.js} +10 -5
  22. package/dist/chunk-OFBDEO45.js +755 -0
  23. package/dist/{chunk-5DDCSGZC.js → chunk-PBQRPDO2.js} +142 -354
  24. package/dist/{chunk-SD3TT2BR.js → chunk-WGVTXSYW.js} +1 -1
  25. package/dist/{chunk-A2QBXDJC.js → chunk-ZZMAHX22.js} +343 -16
  26. package/dist/{enforce-quota.interceptor-Dj1Kusr5.d.ts → enforce-quota.interceptor-B3CL5MSw.d.ts} +94 -12
  27. package/dist/{enforce-quota.interceptor-cv7r80VM.d.cts → enforce-quota.interceptor-SqrQVF91.d.cts} +94 -12
  28. package/dist/entitlement/index.cjs +1 -0
  29. package/dist/entitlement/index.d.cts +3 -1
  30. package/dist/entitlement/index.d.ts +3 -1
  31. package/dist/entitlement/index.js +1 -2
  32. package/dist/index.cjs +3503 -2811
  33. package/dist/index.d.cts +9 -6
  34. package/dist/index.d.ts +9 -6
  35. package/dist/index.js +75 -61
  36. package/dist/module-B5m080F0.d.ts +39 -0
  37. package/dist/module-DeH_Jkcq.d.cts +39 -0
  38. package/dist/platform/index.cjs +11113 -971
  39. package/dist/platform/index.d.cts +41 -7
  40. package/dist/platform/index.d.ts +41 -7
  41. package/dist/platform/index.js +26 -6
  42. package/dist/promo/index.cjs +530 -5
  43. package/dist/promo/index.d.cts +47 -30
  44. package/dist/promo/index.d.ts +47 -30
  45. package/dist/promo/index.js +9 -1
  46. package/dist/{service-DX8KbGXl.d.cts → service-DlhMnYjW.d.cts} +1 -1
  47. package/dist/{service-DX8KbGXl.d.ts → service-DlhMnYjW.d.ts} +1 -1
  48. package/dist/subscription-bundles.module-BQmoozm5.d.ts +291 -0
  49. package/dist/subscription-bundles.module-DCpV-Pb5.d.cts +291 -0
  50. package/dist/testing/index.cjs +11101 -973
  51. package/dist/testing/index.d.cts +9 -4
  52. package/dist/testing/index.d.ts +9 -4
  53. package/dist/testing/index.js +10 -4
  54. package/package.json +4 -4
  55. package/dist/admin-manifest.config-DyrQNT7M.d.cts +0 -10
  56. package/dist/admin-manifest.config-DyrQNT7M.d.ts +0 -10
  57. package/dist/chunk-52UTQRD3.js +0 -326
  58. package/dist/chunk-Q53N43LQ.js +0 -13
  59. /package/dist/{chunk-2FR6ZL7R.js → chunk-HWGIMNWR.js} +0 -0
@@ -0,0 +1,291 @@
1
+ import { CanActivate, Type, DynamicModule, ForwardReference, Provider } from '@nestjs/common';
2
+ import { P as ProviderSpec } from './di-CcNeq9v-.cjs';
3
+ import { NewContractLineItemData, BillingCycle, SubscriptionUsagePort, UsageSnapshotPort, TenantSubscriptionWritePort, SubscriptionContractRepository, SubscriptionBundleRepository, BundleRepository } from '@saasicat/types';
4
+
5
+ /**
6
+ * List of all auth guards the platform controller should iterate in order
7
+ * (analogous to `@UseGuards(JwtAuthGuard, TenantGuard, RolesGuard)`).
8
+ * Provided via `forRoot.authGuards` — can be an array of existing instances
9
+ * or a factory provider.
10
+ */
11
+ declare const TENANT_AUTH_GUARDS_TOKEN: unique symbol;
12
+ /**
13
+ * Resolver function `(req) => string` that extracts the `tenantId` from the
14
+ * request. Default: `req.user.tenantId`.
15
+ */
16
+ declare const TENANT_ID_RESOLVER_TOKEN: unique symbol;
17
+ /**
18
+ * Resolver function `(req) => string` that extracts the `userId` from the
19
+ * request. Default: `req.user.sub ?? req.user.id`.
20
+ */
21
+ declare const USER_ID_RESOLVER_TOKEN: unique symbol;
22
+ /**
23
+ * Resolver function `(req) => string` that extracts the user email from the
24
+ * request. Optional — used by the audit-log path to build the AdminActor
25
+ * (`{userId, email, source: 'web', context}`). Default: `req.user.email`.
26
+ * If the consumer's JWT does not carry an email, the resolver can return
27
+ * `null` — the audit-log path then falls back to `'unknown'`.
28
+ */
29
+ declare const USER_EMAIL_RESOLVER_TOKEN: unique symbol;
30
+ /**
31
+ * Resolver function `(req) => string` that extracts an audit context from the
32
+ * request (e.g. session ID, trace ID). Default: `req.headers['x-session-id']`
33
+ * or `'tenant-self-service'`.
34
+ */
35
+ declare const AUDIT_CONTEXT_RESOLVER_TOKEN: unique symbol;
36
+ /** Adapter token: consumer's `SubscriptionUsagePort` implementation. */
37
+ declare const SUBSCRIPTION_USAGE_PORT_TOKEN: unique symbol;
38
+ /** Adapter token: consumer's `UsageSnapshotPort` implementation. */
39
+ declare const USAGE_SNAPSHOT_PORT_TOKEN: unique symbol;
40
+ /** Adapter token: consumer's `TenantSubscriptionWritePort` implementation. */
41
+ declare const SUBSCRIPTION_WRITE_PORT_TOKEN: unique symbol;
42
+ type TenantIdResolver = (req: unknown) => string | null | undefined;
43
+ type UserIdResolver = (req: unknown) => string | null | undefined;
44
+ type UserEmailResolver = (req: unknown) => string | null | undefined;
45
+ type AuditContextResolver = (req: unknown) => string | null | undefined;
46
+ type AuthGuardList = ReadonlyArray<CanActivate>;
47
+ /**
48
+ * Optional adapter token: projects the new trial end of a change
49
+ * (app-specific trial logic, e.g. carry-over of the remaining time). Without a
50
+ * port, `PlanChangePreviewDto.projectedTrialEndsAt` stays `null` and the wizard
51
+ * falls back to the current trial end.
52
+ */
53
+ declare const TRIAL_PROJECTION_PORT_TOKEN: unique symbol;
54
+ interface TrialProjectionInput {
55
+ /** Current plan key of the subscription. */
56
+ currentPlan: string;
57
+ /** Target plan key of the change. */
58
+ targetPlan: string;
59
+ /** Current trial end (null = no trial). */
60
+ currentTrialEndsAt: Date | null;
61
+ /** Subscription status (e.g. 'TRIAL'/'ACTIVE'). */
62
+ status: string;
63
+ now: Date;
64
+ }
65
+ interface TrialProjectionPort {
66
+ /**
67
+ * Projected new trial end after the change. `null` if nothing changes or
68
+ * the target package does not support a trial.
69
+ */
70
+ projectTrialEndsAt(input: TrialProjectionInput): Promise<Date | null>;
71
+ }
72
+ /**
73
+ * Optional adapter token: provides due scheduled plan changes for the
74
+ * `PendingPlanMaterializationService`. Without a port, the service is not
75
+ * registered (materialization is opt-in).
76
+ */
77
+ declare const PENDING_PLAN_QUERY_PORT_TOKEN: unique symbol;
78
+ /** A due scheduled plan change — minimal for materialization. */
79
+ interface DuePendingPlanChange {
80
+ tenantId: string;
81
+ /** Target plan key of the scheduled change (`pendingPlan`). */
82
+ pendingPlan: string;
83
+ /** Target cycle (`pendingBillingCycle`); `null` → default MONTHLY. */
84
+ pendingBillingCycle: string | null;
85
+ }
86
+ interface PendingPlanQueryPort {
87
+ /**
88
+ * Returns all subscriptions with a due scheduled plan change:
89
+ * `pendingPlan != null AND pendingEffectiveAt <= now AND status != 'TRIAL'`.
90
+ * TRIAL is excluded — there the trial lifecycle drives the transition.
91
+ */
92
+ findDuePendingPlanChanges(now: Date): Promise<DuePendingPlanChange[]>;
93
+ }
94
+
95
+ interface SelfServiceBlockedPlans {
96
+ asTarget?: string[];
97
+ asSource?: string[];
98
+ }
99
+ declare const SELF_SERVICE_BLOCKED_PLANS_TOKEN: unique symbol;
100
+ /**
101
+ * Bundle counterpart (#37): `bundleKeys` lists bundles that are not
102
+ * bookable via self-service (only via sales/special contract).
103
+ * Applies in `SubscriptionBundlesService.addBundleToSubscription`
104
+ * (enforcement, 422) and in the bundle preview (blocker indication).
105
+ */
106
+ interface SelfServiceBlockedBundles {
107
+ bundleKeys?: string[];
108
+ }
109
+ declare const SELF_SERVICE_BLOCKED_BUNDLES_TOKEN: unique symbol;
110
+
111
+ /**
112
+ * Optional hook token: the platform `changePlan` path + the
113
+ * `PendingPlanMaterializationService` call the freeze after the plan mutation
114
+ * (analogous to `TrialProjectionPort`). Without a port nothing is frozen — the
115
+ * entitlements then stay catalog-/version-pinned as before.
116
+ */
117
+ declare const CONTRACT_FREEZE_PORT_TOKEN: unique symbol;
118
+ /** Adapter token: consumer-specific bundle/version data access. */
119
+ declare const CONTRACT_FREEZE_SOURCE_PORT_TOKEN: unique symbol;
120
+ /** Config token: the consumer's `projectKey` for the contract. */
121
+ declare const CONTRACT_FREEZE_PROJECT_KEY_TOKEN: unique symbol;
122
+ interface ContractFreezePort {
123
+ /**
124
+ * Freezes the agreed service at `effectiveFrom` as the new active
125
+ * `SubscriptionContract` (supersedes the previous one). Non-fatal for the
126
+ * caller — the plan change is already persisted.
127
+ */
128
+ freezeOnPlanChange(tenantId: string, newPlan: string, billingCycle: BillingCycle, effectiveFrom: Date): Promise<void>;
129
+ }
130
+ /** Frozen bundle line items + their version ids (trace). */
131
+ interface ContractFreezeBundleSnapshot {
132
+ lineItems: NewContractLineItemData[];
133
+ bundleVersionIds: string[];
134
+ }
135
+ /**
136
+ * Consumer-specific data access for the freeze: live PlanVersion id
137
+ * (trace) + booked bundles as contract line items. The generic freeze
138
+ * logic (plan line item from the catalog, snapshot, contract assembly) lives in
139
+ * the platform `SubscriptionContractFreezeService`.
140
+ */
141
+ interface ContractFreezeSourcePort {
142
+ /** Live (published, non-superseded) PlanVersion id of the target plan, or null. */
143
+ findLivePlanVersionId(planId: string): Promise<string | null>;
144
+ /**
145
+ * The tenant's active (non-terminated) bundle bookings as line items.
146
+ * `vatRate` is passed through so the gross price is computed consistently
147
+ * with the catalog VAT. Apps without a bundle schema return empty lists.
148
+ */
149
+ loadBookedBundles(tenantId: string, cycle: 'monthly' | 'yearly', vatRate: number): Promise<ContractFreezeBundleSnapshot>;
150
+ }
151
+
152
+ interface TenantBillingModuleOptions {
153
+ /**
154
+ * App guards in the order in which they should be executed
155
+ * (e.g. `[JwtAuthGuard, TenantGuard]`). The platform combines them via
156
+ * `ComposedTenantAuthGuard`. At least one guard is mandatory —
157
+ * missing configuration leads to 403 (safe default).
158
+ *
159
+ * Variant 1: array of guard instances (e.g. via factory provider).
160
+ * Variant 2: Pick<FactoryProvider, 'useFactory' | 'inject'> — apps
161
+ * pass their guard classes through via `inject` and the factory builds
162
+ * the array.
163
+ */
164
+ authGuards: ProviderSpec<ReadonlyArray<CanActivate>>;
165
+ /** Adapter to the subscription display form (`GET /billing/usage`). */
166
+ subscriptionUsagePort: ProviderSpec<SubscriptionUsagePort>;
167
+ /** Adapter to usage counters of all `quotaKeys`. */
168
+ usageSnapshotPort: ProviderSpec<UsageSnapshotPort>;
169
+ /** Adapter for plan/add-on mutations (phase C). */
170
+ subscriptionWritePort: ProviderSpec<TenantSubscriptionWritePort>;
171
+ /**
172
+ * Optional adapter that provides the projected new trial end of a change
173
+ * (app trial logic, e.g. carry-over). Without a port,
174
+ * `PlanChangePreviewDto.projectedTrialEndsAt` stays `null`.
175
+ */
176
+ trialProjectionPort?: ProviderSpec<TrialProjectionPort>;
177
+ /**
178
+ * Optional adapter that provides due scheduled plan changes (#19). If it is
179
+ * passed, the module registers the `PendingPlanMaterializationService`
180
+ * (exported) — the consumer triggers it via its own cron. Without a
181
+ * port, the materialization stays disabled (lazy resolution as before).
182
+ */
183
+ pendingPlanQueryPort?: ProviderSpec<PendingPlanQueryPort>;
184
+ /**
185
+ * Optional contract freeze hook (#18). If it is configured, the
186
+ * platform `changePlan` path (non-TRIAL) AND the materialization freeze
187
+ * the agreed service after the plan mutation as a `SubscriptionContract`
188
+ * (analogous to `trialProjectionPort`). Consumer-specific are only `projectKey`
189
+ * + bundle/version data access (`sourcePort`); the contract logic is
190
+ * generic. `subscriptionContractRepository` is the same repo that also goes
191
+ * to `EntitlementModule.forRoot` — the freeze needs it in its own scope.
192
+ */
193
+ contractFreeze?: {
194
+ projectKey: string;
195
+ sourcePort: ProviderSpec<ContractFreezeSourcePort>;
196
+ subscriptionContractRepository: ProviderSpec<SubscriptionContractRepository>;
197
+ };
198
+ /**
199
+ * Plans that are not accepted as target/source via self-service
200
+ * (typically ENTERPRISE → special contract). `null`/undefined = no blocks.
201
+ */
202
+ selfServiceBlockedPlans?: SelfServiceBlockedPlans;
203
+ /** Optional tenant ID resolver. Default: `req.user.tenantId`. */
204
+ tenantIdResolver?: TenantIdResolver;
205
+ /** Optional user ID resolver. Default: `req.user.sub ?? req.user.id`. */
206
+ userIdResolver?: UserIdResolver;
207
+ /**
208
+ * Optional email resolver for the audit log path. Default: `req.user.email`.
209
+ * If the consumer JWT does not include the email, the resolver can
210
+ * return `null` — the audit log then uses `'unknown'`.
211
+ */
212
+ userEmailResolver?: UserEmailResolver;
213
+ /**
214
+ * Optional audit context resolver (session ID / trace ID). Default:
215
+ * `req.headers['x-session-id']` or `'tenant-self-service'`.
216
+ */
217
+ auditContextResolver?: AuditContextResolver;
218
+ /**
219
+ * Modules whose providers must be visible within this module.
220
+ * Typical use case: the app's own `AuthModule`, so that the `JwtAuthGuard`
221
+ * is injectable in the `authGuards` factory. Without this entry NestJS throws
222
+ * `UnknownDependenciesException` for JwtAuthGuard.
223
+ */
224
+ imports?: Array<Type<unknown> | DynamicModule | Promise<DynamicModule> | ForwardReference>;
225
+ /**
226
+ * Additional providers that are registered in the DynamicModule itself —
227
+ * typically: the adapter classes referenced in `inject:[Adapter]` lists
228
+ * (e.g. `PrismaSubscriptionUsagePort`). NestJS 11.1.19
229
+ * resolves factory inject tokens only in the DynamicModule's own scope.
230
+ */
231
+ extraProviders?: Provider[];
232
+ /** Additional providers this module makes visible to importing modules. */
233
+ extraExports?: NonNullable<DynamicModule['exports']>;
234
+ /** Register the module globally — default `false`. */
235
+ global?: boolean;
236
+ }
237
+ declare class TenantBillingModule {
238
+ static forRoot(options: TenantBillingModuleOptions): DynamicModule;
239
+ }
240
+
241
+ interface SubscriptionBundleControllerOptions {
242
+ extraGuards?: Array<Type<CanActivate>>;
243
+ /**
244
+ * Auth guard list analogous to `TenantBillingModule.forRoot.authGuards`.
245
+ * Without this list, `ComposedTenantAuthGuard` blocks fail-closed.
246
+ */
247
+ authGuards?: ProviderSpec<ReadonlyArray<CanActivate>>;
248
+ /**
249
+ * Usage port for subscription lookup and current plan compatibility.
250
+ * If not set, an imported module must export the token.
251
+ */
252
+ subscriptionUsagePort?: ProviderSpec<SubscriptionUsagePort>;
253
+ /** Optional tenant-ID resolver. Default: `req.user.tenantId`. */
254
+ tenantIdResolver?: TenantIdResolver;
255
+ }
256
+ interface SubscriptionBundleModuleOptions {
257
+ subscriptionBundleRepository: ProviderSpec<SubscriptionBundleRepository>;
258
+ /**
259
+ * Optional — if omitted, `BUNDLE_REPOSITORY_TOKEN` is expected via
260
+ * default inject from the DI scope (typically via an imported
261
+ * `CatalogModule`).
262
+ */
263
+ bundleRepository?: ProviderSpec<BundleRepository>;
264
+ /** Default minimum term (months). Default = 12. */
265
+ defaultMinimumTermMonths?: number;
266
+ /**
267
+ * Self-service policy (#37): bundles that are only bookable via sales.
268
+ * Applies in `addBundleToSubscription` (422 BUNDLE_NOT_SELF_SERVICE)
269
+ * and in the preview (blocker).
270
+ */
271
+ selfServiceBlockedBundles?: SelfServiceBlockedBundles;
272
+ /**
273
+ * If set: the tenant self-service controller is mounted at
274
+ * `/billing/subscription-bundles` (GET/POST/DELETE). The
275
+ * `extraGuards` are applied in addition to the platform default
276
+ * `ComposedTenantAuthGuard` (role/MFA guards).
277
+ *
278
+ * Prerequisite: the consumer has already registered `TenantBillingModule`
279
+ * — the controller needs `SUBSCRIPTION_USAGE_PORT_TOKEN`
280
+ * + `TENANT_ID_RESOLVER_TOKEN` in the same DI scope.
281
+ */
282
+ controller?: SubscriptionBundleControllerOptions;
283
+ imports?: Array<Type<unknown> | DynamicModule | Promise<DynamicModule> | ForwardReference>;
284
+ extraProviders?: Provider[];
285
+ global?: boolean;
286
+ }
287
+ declare class SubscriptionBundleModule {
288
+ static forRoot(options: SubscriptionBundleModuleOptions): DynamicModule;
289
+ }
290
+
291
+ export { AUDIT_CONTEXT_RESOLVER_TOKEN as A, type UserIdResolver as B, CONTRACT_FREEZE_PORT_TOKEN as C, type DuePendingPlanChange as D, 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 };