@saasicat/nest 0.14.0 → 0.15.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 (57) hide show
  1. package/dist/_entries.cjs +1464 -1334
  2. package/dist/admin/index.d.cts +8 -6
  3. package/dist/admin/index.d.ts +8 -6
  4. package/dist/admin/index.js +13 -12
  5. package/dist/{admin-resources.module-Cms8MY6h.d.ts → admin-resources.module-BY5r_1MG.d.ts} +29 -3
  6. package/dist/{admin-resources.module-BZN_yBFj.d.cts → admin-resources.module-DGgGSdzN.d.cts} +29 -3
  7. package/dist/{admin-stats.module-15ac5KY3.d.ts → admin-stats.service-Db2exT_d.d.ts} +2 -23
  8. package/dist/{admin-stats.module-v4SVvWzj.d.cts → admin-stats.service-HUZIU448.d.cts} +2 -23
  9. package/dist/billing/index.d.cts +1 -1
  10. package/dist/billing/index.d.ts +1 -1
  11. package/dist/billing/index.js +3 -2
  12. package/dist/catalog/index.js +3 -2
  13. package/dist/checkout-offer/index.d.cts +2 -1
  14. package/dist/checkout-offer/index.d.ts +2 -1
  15. package/dist/checkout-offer/index.js +2 -1
  16. package/dist/checkout-offer.module-Ca3_TieR.d.ts +39 -0
  17. package/dist/checkout-offer.module-DmlpPevf.d.cts +39 -0
  18. package/dist/{checkout-offer.module-Y0hDOVrq.d.ts → checkout-offer.service-BX51dljL.d.cts} +1 -37
  19. package/dist/{checkout-offer.module-ZYF5IsDY.d.cts → checkout-offer.service-BX51dljL.d.ts} +1 -37
  20. package/dist/{chunk-2PNX2QL2.js → chunk-32EMXPU2.js} +1 -0
  21. package/dist/{chunk-RKVY775D.js → chunk-5KH2O4SF.js} +5 -1
  22. package/dist/{chunk-TXDH4FUA.js → chunk-7RRWI5LH.js} +1 -1
  23. package/dist/chunk-EWPF57AG.js +13 -0
  24. package/dist/{chunk-HBFU5AN3.js → chunk-GJBXOCRZ.js} +4 -0
  25. package/dist/{chunk-IRWZC3GC.js → chunk-GLLCB4BP.js} +4 -0
  26. package/dist/{chunk-33TP26MR.js → chunk-P3DP6GJE.js} +4 -0
  27. package/dist/{chunk-FVT7KTUI.js → chunk-PLJEAUFU.js} +275 -61
  28. package/dist/{chunk-I2EKGQUG.js → chunk-YITTE646.js} +462 -82
  29. package/dist/chunk-YSC46BGM.js +21 -0
  30. package/dist/define-saasicat-CeDBX9ji.d.cts +46 -0
  31. package/dist/define-saasicat-Rc0rXrYG.d.ts +46 -0
  32. package/dist/enforce-quota.interceptor-CmbWX39L.d.ts +60 -0
  33. package/dist/enforce-quota.interceptor-DMw-bPyk.d.cts +60 -0
  34. package/dist/index.d.cts +11 -9
  35. package/dist/index.d.ts +11 -9
  36. package/dist/index.js +33 -18
  37. package/dist/platform/index.d.cts +12 -16
  38. package/dist/platform/index.d.ts +12 -16
  39. package/dist/platform/index.js +24 -25
  40. package/dist/promo/index.js +2 -1
  41. package/dist/{enforce-quota.interceptor-Dse3jSpU.d.cts → saas-platform.module-D3rUTiho.d.cts} +69 -62
  42. package/dist/{enforce-quota.interceptor-DMEvL-bE.d.ts → saas-platform.module-DLhoqKNA.d.ts} +69 -62
  43. package/dist/subscription-contract/index.d.cts +1 -1
  44. package/dist/subscription-contract/index.d.ts +1 -1
  45. package/dist/subscription-contract/index.js +1 -1
  46. package/dist/{subscription-contract.module-CG9fPKAr.d.cts → subscription-contract.module-B2uNvUJL.d.cts} +3 -1
  47. package/dist/{subscription-contract.module-CVebZzHR.d.ts → subscription-contract.module-edyhBr4n.d.ts} +3 -1
  48. package/dist/{subscription-bundle-preview.service-BgQ776mv.d.ts → tenant-billing.controller-BwZRnJ3q.d.ts} +105 -105
  49. package/dist/{subscription-bundle-preview.service-B4Ye8L2F.d.cts → tenant-billing.controller-CG4CaFUP.d.cts} +105 -105
  50. package/dist/testing/index.d.cts +6 -3
  51. package/dist/testing/index.d.ts +6 -3
  52. package/dist/testing/index.js +8 -6
  53. package/package.json +3 -3
  54. package/dist/chunk-LZHLGUQI.js +0 -190
  55. package/dist/chunk-WJ6BMDL3.js +0 -313
  56. package/dist/setup.service-BPwJ7My_.d.cts +0 -45
  57. package/dist/setup.service-D2mrdDDB.d.ts +0 -45
@@ -1,22 +1,33 @@
1
1
  import {
2
2
  PromoCodesModule
3
- } from "./chunk-IRWZC3GC.js";
3
+ } from "./chunk-GLLCB4BP.js";
4
4
  import {
5
5
  AdminManifestModule,
6
6
  AdminManifestService,
7
7
  AdminModule,
8
8
  AdminResourcesModule,
9
+ AdminStatsModule,
10
+ MfaService,
9
11
  SuperAdminGuard
10
- } from "./chunk-FVT7KTUI.js";
12
+ } from "./chunk-PLJEAUFU.js";
11
13
  import {
12
14
  PublicCatalogModule,
13
15
  REQUIRE_FEATURE_KEY,
14
16
  SubscriptionBundleModule,
15
17
  TenantBillingModule
16
- } from "./chunk-RKVY775D.js";
18
+ } from "./chunk-5KH2O4SF.js";
19
+ import {
20
+ SubscriptionContractModule
21
+ } from "./chunk-32EMXPU2.js";
17
22
  import {
18
23
  CatalogModule
19
- } from "./chunk-33TP26MR.js";
24
+ } from "./chunk-P3DP6GJE.js";
25
+ import {
26
+ CheckoutOfferModule
27
+ } from "./chunk-GJBXOCRZ.js";
28
+ import {
29
+ SaaSiCatPublicRoute
30
+ } from "./chunk-YSC46BGM.js";
20
31
  import {
21
32
  DiscoveryModule
22
33
  } from "./chunk-V34AA7C7.js";
@@ -38,6 +49,305 @@ import {
38
49
  __name
39
50
  } from "./chunk-SHUYVCID.js";
40
51
 
52
+ // src/setup/tokens.ts
53
+ var SETUP_PROVISIONING_PORT_TOKEN = /* @__PURE__ */ Symbol.for("saas-platform/SetupProvisioningPort");
54
+ var SETUP_CONFIG_TOKEN = /* @__PURE__ */ Symbol.for("saas-platform/SetupConfig");
55
+
56
+ // src/setup/setup.service.ts
57
+ import { BadRequestException, ConflictException, ForbiddenException, Inject, Injectable, UnauthorizedException } from "@nestjs/common";
58
+ import { isPlatformUserExistsError, SETUP_ERROR_CODES } from "@saasicat/types";
59
+ import { randomBytes, timingSafeEqual } from "crypto";
60
+ import QRCode from "qrcode";
61
+ function _ts_decorate(decorators, target, key, desc) {
62
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
63
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
64
+ 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;
65
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
66
+ }
67
+ __name(_ts_decorate, "_ts_decorate");
68
+ function _ts_metadata(k, v) {
69
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
70
+ }
71
+ __name(_ts_metadata, "_ts_metadata");
72
+ function _ts_param(paramIndex, decorator) {
73
+ return function(target, key) {
74
+ decorator(target, key, paramIndex);
75
+ };
76
+ }
77
+ __name(_ts_param, "_ts_param");
78
+ var GENERATED_PASSWORD_BYTES = 12;
79
+ function timingSafeEqualStr(a, b) {
80
+ const ab = Buffer.from(a, "utf8");
81
+ const bb = Buffer.from(b, "utf8");
82
+ if (ab.length !== bb.length) return false;
83
+ return timingSafeEqual(ab, bb);
84
+ }
85
+ __name(timingSafeEqualStr, "timingSafeEqualStr");
86
+ var SetupService = class {
87
+ static {
88
+ __name(this, "SetupService");
89
+ }
90
+ users;
91
+ config;
92
+ mfa;
93
+ constructor(users, config, mfa) {
94
+ this.users = users;
95
+ this.config = config;
96
+ this.mfa = mfa;
97
+ }
98
+ async status() {
99
+ return {
100
+ needsSetup: await this.users.countSuperAdmins() === 0
101
+ };
102
+ }
103
+ async setup(req) {
104
+ this.assertToken(req.token);
105
+ await this.assertNoSuperAdmin();
106
+ const email = req.email.trim().toLowerCase();
107
+ if (!email.includes("@")) {
108
+ throw new BadRequestException({
109
+ code: SETUP_ERROR_CODES.INVALID_EMAIL
110
+ });
111
+ }
112
+ const generated = !req.password;
113
+ const password = req.password ?? randomBytes(GENERATED_PASSWORD_BYTES).toString("base64url");
114
+ let user;
115
+ try {
116
+ user = await this.users.createSuperAdmin({
117
+ email,
118
+ password
119
+ });
120
+ } catch (err) {
121
+ if (isPlatformUserExistsError(err)) {
122
+ throw new ConflictException({
123
+ code: SETUP_ERROR_CODES.EMAIL_EXISTS,
124
+ message: err.message
125
+ });
126
+ }
127
+ throw err;
128
+ }
129
+ const totp = await this.mfa.setup(user.id, user.email, this.config.mfaIssuer);
130
+ const qrDataUrl = await QRCode.toDataURL(totp.otpauthUri, {
131
+ width: 220,
132
+ margin: 1
133
+ });
134
+ return {
135
+ userId: user.id,
136
+ email: user.email,
137
+ otpauthUri: totp.otpauthUri,
138
+ qrDataUrl,
139
+ secret: totp.secret,
140
+ ...generated ? {
141
+ generatedPassword: password
142
+ } : {}
143
+ };
144
+ }
145
+ async confirmMfa(req) {
146
+ this.assertToken(req.token);
147
+ const ok = await this.mfa.verify({
148
+ userId: req.userId,
149
+ code: req.code
150
+ });
151
+ return {
152
+ ok
153
+ };
154
+ }
155
+ assertToken(token) {
156
+ const expected = process.env[this.config.setupTokenEnvVar]?.trim();
157
+ if (!expected) {
158
+ throw new ForbiddenException({
159
+ code: SETUP_ERROR_CODES.SETUP_DISABLED,
160
+ message: `${this.config.setupTokenEnvVar} ist nicht gesetzt \u2014 Setup ist deaktiviert.`
161
+ });
162
+ }
163
+ if (!token || !timingSafeEqualStr(token, expected)) {
164
+ throw new UnauthorizedException({
165
+ code: SETUP_ERROR_CODES.INVALID_SETUP_TOKEN
166
+ });
167
+ }
168
+ }
169
+ async assertNoSuperAdmin() {
170
+ if (await this.users.countSuperAdmins() > 0) {
171
+ throw new ConflictException({
172
+ code: SETUP_ERROR_CODES.SETUP_ALREADY_DONE
173
+ });
174
+ }
175
+ }
176
+ };
177
+ SetupService = _ts_decorate([
178
+ Injectable(),
179
+ _ts_param(0, Inject(SETUP_PROVISIONING_PORT_TOKEN)),
180
+ _ts_param(1, Inject(SETUP_CONFIG_TOKEN)),
181
+ _ts_metadata("design:type", Function),
182
+ _ts_metadata("design:paramtypes", [
183
+ typeof SuperAdminProvisioningPort === "undefined" ? Object : SuperAdminProvisioningPort,
184
+ typeof SetupConfig === "undefined" ? Object : SetupConfig,
185
+ typeof MfaService === "undefined" ? Object : MfaService
186
+ ])
187
+ ], SetupService);
188
+
189
+ // src/setup/setup.controller.ts
190
+ import { Body, Controller, Get, Post } from "@nestjs/common";
191
+ import { IsEmail, IsNotEmpty, IsOptional, IsString, MinLength } from "class-validator";
192
+ function _ts_decorate2(decorators, target, key, desc) {
193
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
194
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
195
+ 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;
196
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
197
+ }
198
+ __name(_ts_decorate2, "_ts_decorate");
199
+ function _ts_metadata2(k, v) {
200
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
201
+ }
202
+ __name(_ts_metadata2, "_ts_metadata");
203
+ function _ts_param2(paramIndex, decorator) {
204
+ return function(target, key) {
205
+ decorator(target, key, paramIndex);
206
+ };
207
+ }
208
+ __name(_ts_param2, "_ts_param");
209
+ var SetupDto = class SetupDto2 {
210
+ static {
211
+ __name(this, "SetupDto");
212
+ }
213
+ token;
214
+ email;
215
+ password;
216
+ };
217
+ _ts_decorate2([
218
+ IsString(),
219
+ IsNotEmpty(),
220
+ _ts_metadata2("design:type", String)
221
+ ], SetupDto.prototype, "token", void 0);
222
+ _ts_decorate2([
223
+ IsEmail(),
224
+ _ts_metadata2("design:type", String)
225
+ ], SetupDto.prototype, "email", void 0);
226
+ _ts_decorate2([
227
+ IsOptional(),
228
+ IsString(),
229
+ MinLength(8),
230
+ _ts_metadata2("design:type", String)
231
+ ], SetupDto.prototype, "password", void 0);
232
+ var SetupConfirmMfaDto = class SetupConfirmMfaDto2 {
233
+ static {
234
+ __name(this, "SetupConfirmMfaDto");
235
+ }
236
+ token;
237
+ userId;
238
+ code;
239
+ };
240
+ _ts_decorate2([
241
+ IsString(),
242
+ IsNotEmpty(),
243
+ _ts_metadata2("design:type", String)
244
+ ], SetupConfirmMfaDto.prototype, "token", void 0);
245
+ _ts_decorate2([
246
+ IsString(),
247
+ IsNotEmpty(),
248
+ _ts_metadata2("design:type", String)
249
+ ], SetupConfirmMfaDto.prototype, "userId", void 0);
250
+ _ts_decorate2([
251
+ IsString(),
252
+ IsNotEmpty(),
253
+ _ts_metadata2("design:type", String)
254
+ ], SetupConfirmMfaDto.prototype, "code", void 0);
255
+ var SetupController = class {
256
+ static {
257
+ __name(this, "SetupController");
258
+ }
259
+ setup;
260
+ constructor(setup) {
261
+ this.setup = setup;
262
+ }
263
+ status() {
264
+ return this.setup.status();
265
+ }
266
+ run(dto) {
267
+ return this.setup.setup(dto);
268
+ }
269
+ confirm(dto) {
270
+ return this.setup.confirmMfa(dto);
271
+ }
272
+ };
273
+ _ts_decorate2([
274
+ Get("status"),
275
+ _ts_metadata2("design:type", Function),
276
+ _ts_metadata2("design:paramtypes", []),
277
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
278
+ ], SetupController.prototype, "status", null);
279
+ _ts_decorate2([
280
+ Post(),
281
+ _ts_param2(0, Body()),
282
+ _ts_metadata2("design:type", Function),
283
+ _ts_metadata2("design:paramtypes", [
284
+ typeof SetupDto === "undefined" ? Object : SetupDto
285
+ ]),
286
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
287
+ ], SetupController.prototype, "run", null);
288
+ _ts_decorate2([
289
+ Post("confirm-mfa"),
290
+ _ts_param2(0, Body()),
291
+ _ts_metadata2("design:type", Function),
292
+ _ts_metadata2("design:paramtypes", [
293
+ typeof SetupConfirmMfaDto === "undefined" ? Object : SetupConfirmMfaDto
294
+ ]),
295
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
296
+ ], SetupController.prototype, "confirm", null);
297
+ SetupController = _ts_decorate2([
298
+ Controller("admin/setup"),
299
+ SaaSiCatPublicRoute(),
300
+ _ts_metadata2("design:type", Function),
301
+ _ts_metadata2("design:paramtypes", [
302
+ typeof SetupService === "undefined" ? Object : SetupService
303
+ ])
304
+ ], SetupController);
305
+
306
+ // src/setup/setup.module.ts
307
+ import { Module } from "@nestjs/common";
308
+ function _ts_decorate3(decorators, target, key, desc) {
309
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
310
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
311
+ 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;
312
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
313
+ }
314
+ __name(_ts_decorate3, "_ts_decorate");
315
+ var DEFAULT_SETUP_TOKEN_ENV_VAR = "SETUP_TOKEN";
316
+ var DEFAULT_MFA_ISSUER = "SuperAdmin";
317
+ var SetupModule = class _SetupModule {
318
+ static {
319
+ __name(this, "SetupModule");
320
+ }
321
+ static forRoot(options) {
322
+ return {
323
+ module: _SetupModule,
324
+ global: options.global ?? false,
325
+ imports: options.imports ?? [],
326
+ controllers: [
327
+ SetupController
328
+ ],
329
+ providers: [
330
+ asProvider(SETUP_PROVISIONING_PORT_TOKEN, options.provisioningPort),
331
+ {
332
+ provide: SETUP_CONFIG_TOKEN,
333
+ useValue: {
334
+ setupTokenEnvVar: options.setupTokenEnvVar ?? DEFAULT_SETUP_TOKEN_ENV_VAR,
335
+ mfaIssuer: options.mfaIssuer ?? DEFAULT_MFA_ISSUER
336
+ }
337
+ },
338
+ SetupService,
339
+ ...options.extraProviders ?? []
340
+ ],
341
+ exports: [
342
+ SetupService
343
+ ]
344
+ };
345
+ }
346
+ };
347
+ SetupModule = _ts_decorate3([
348
+ Module({})
349
+ ], SetupModule);
350
+
41
351
  // src/platform/plan-resolver.port.ts
42
352
  var PLAN_RESOLVER_PORT_TOKEN = /* @__PURE__ */ Symbol.for("saas-platform-nest/PlanResolverPort");
43
353
  var StaticPlanResolver = class {
@@ -54,24 +364,24 @@ var StaticPlanResolver = class {
54
364
  };
55
365
 
56
366
  // src/platform/static-entitlement.service.ts
57
- import { Inject, Injectable } from "@nestjs/common";
58
- function _ts_decorate(decorators, target, key, desc) {
367
+ import { Inject as Inject2, Injectable as Injectable2 } from "@nestjs/common";
368
+ function _ts_decorate4(decorators, target, key, desc) {
59
369
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
60
370
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
61
371
  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;
62
372
  return c > 3 && r && Object.defineProperty(target, key, r), r;
63
373
  }
64
- __name(_ts_decorate, "_ts_decorate");
65
- function _ts_metadata(k, v) {
374
+ __name(_ts_decorate4, "_ts_decorate");
375
+ function _ts_metadata3(k, v) {
66
376
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
67
377
  }
68
- __name(_ts_metadata, "_ts_metadata");
69
- function _ts_param(paramIndex, decorator) {
378
+ __name(_ts_metadata3, "_ts_metadata");
379
+ function _ts_param3(paramIndex, decorator) {
70
380
  return function(target, key) {
71
381
  decorator(target, key, paramIndex);
72
382
  };
73
383
  }
74
- __name(_ts_param, "_ts_param");
384
+ __name(_ts_param3, "_ts_param");
75
385
  var StaticEntitlementService = class {
76
386
  static {
77
387
  __name(this, "StaticEntitlementService");
@@ -124,37 +434,37 @@ var StaticEntitlementService = class {
124
434
  return (this.catalog.plans ?? []).find((p) => p.id === planId);
125
435
  }
126
436
  };
127
- StaticEntitlementService = _ts_decorate([
128
- Injectable(),
129
- _ts_param(0, Inject(PLAN_CATALOG_TOKEN)),
130
- _ts_param(1, Inject(PLAN_RESOLVER_PORT_TOKEN)),
131
- _ts_metadata("design:type", Function),
132
- _ts_metadata("design:paramtypes", [
437
+ StaticEntitlementService = _ts_decorate4([
438
+ Injectable2(),
439
+ _ts_param3(0, Inject2(PLAN_CATALOG_TOKEN)),
440
+ _ts_param3(1, Inject2(PLAN_RESOLVER_PORT_TOKEN)),
441
+ _ts_metadata3("design:type", Function),
442
+ _ts_metadata3("design:paramtypes", [
133
443
  typeof PlanCatalog === "undefined" ? Object : PlanCatalog,
134
444
  typeof PlanResolverPort === "undefined" ? Object : PlanResolverPort
135
445
  ])
136
446
  ], StaticEntitlementService);
137
447
 
138
448
  // src/platform/static-feature.guard.ts
139
- import { ForbiddenException, Inject as Inject2, Injectable as Injectable2, Optional } from "@nestjs/common";
449
+ import { ForbiddenException as ForbiddenException2, Inject as Inject3, Injectable as Injectable3, Optional } from "@nestjs/common";
140
450
  import { Reflector } from "@nestjs/core";
141
- function _ts_decorate2(decorators, target, key, desc) {
451
+ function _ts_decorate5(decorators, target, key, desc) {
142
452
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
143
453
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
144
454
  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;
145
455
  return c > 3 && r && Object.defineProperty(target, key, r), r;
146
456
  }
147
- __name(_ts_decorate2, "_ts_decorate");
148
- function _ts_metadata2(k, v) {
457
+ __name(_ts_decorate5, "_ts_decorate");
458
+ function _ts_metadata4(k, v) {
149
459
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
150
460
  }
151
- __name(_ts_metadata2, "_ts_metadata");
152
- function _ts_param2(paramIndex, decorator) {
461
+ __name(_ts_metadata4, "_ts_metadata");
462
+ function _ts_param4(paramIndex, decorator) {
153
463
  return function(target, key) {
154
464
  decorator(target, key, paramIndex);
155
465
  };
156
466
  }
157
- __name(_ts_param2, "_ts_param");
467
+ __name(_ts_param4, "_ts_param");
158
468
  var STATIC_FEATURE_GUARD_CONFIG_TOKEN = /* @__PURE__ */ Symbol.for("saas-platform-nest/StaticFeatureGuardConfig");
159
469
  var StaticFeatureGuard = class {
160
470
  static {
@@ -176,27 +486,27 @@ var StaticFeatureGuard = class {
176
486
  if (!required || required.length === 0) return true;
177
487
  const request = context.switchToHttp().getRequest();
178
488
  const user = request.user;
179
- if (!user) throw new ForbiddenException("Nicht authentifiziert");
489
+ if (!user) throw new ForbiddenException2("Nicht authentifiziert");
180
490
  const role = this.config?.userRoleResolver ? this.config.userRoleResolver(user) : user.role ?? user.platformRole;
181
491
  if (role === "SUPER_ADMIN") return true;
182
492
  const tenantId = this.config?.tenantIdResolver ? this.config.tenantIdResolver(request) : request.tenantId ?? user.tenantId;
183
- if (!tenantId) throw new ForbiddenException("Kein Mandant zugeordnet");
493
+ if (!tenantId) throw new ForbiddenException2("Kein Mandant zugeordnet");
184
494
  const snap = await this.entitlements.snapshot(tenantId);
185
495
  const allowed = required.some((f) => snap.features.includes(f));
186
496
  if (!allowed) {
187
- throw new ForbiddenException(`Feature ${required.join(" / ")} nicht im aktuellen Plan enthalten.`);
497
+ throw new ForbiddenException2(`Feature ${required.join(" / ")} nicht im aktuellen Plan enthalten.`);
188
498
  }
189
499
  return true;
190
500
  }
191
501
  };
192
- StaticFeatureGuard = _ts_decorate2([
193
- Injectable2(),
194
- _ts_param2(0, Inject2(Reflector)),
195
- _ts_param2(1, Inject2(StaticEntitlementService)),
196
- _ts_param2(2, Optional()),
197
- _ts_param2(2, Inject2(STATIC_FEATURE_GUARD_CONFIG_TOKEN)),
198
- _ts_metadata2("design:type", Function),
199
- _ts_metadata2("design:paramtypes", [
502
+ StaticFeatureGuard = _ts_decorate5([
503
+ Injectable3(),
504
+ _ts_param4(0, Inject3(Reflector)),
505
+ _ts_param4(1, Inject3(StaticEntitlementService)),
506
+ _ts_param4(2, Optional()),
507
+ _ts_param4(2, Inject3(STATIC_FEATURE_GUARD_CONFIG_TOKEN)),
508
+ _ts_metadata4("design:type", Function),
509
+ _ts_metadata4("design:paramtypes", [
200
510
  typeof Reflector === "undefined" ? Object : Reflector,
201
511
  typeof StaticEntitlementService === "undefined" ? Object : StaticEntitlementService,
202
512
  Object
@@ -204,27 +514,27 @@ StaticFeatureGuard = _ts_decorate2([
204
514
  ], StaticFeatureGuard);
205
515
 
206
516
  // src/platform/enforce-quota.interceptor.ts
207
- import { Inject as Inject3, Injectable as Injectable3, Optional as Optional2 } from "@nestjs/common";
517
+ import { Inject as Inject4, Injectable as Injectable4, Optional as Optional2 } from "@nestjs/common";
208
518
  import { Reflector as Reflector2 } from "@nestjs/core";
209
519
  import { from } from "rxjs";
210
520
  import { switchMap } from "rxjs/operators";
211
- function _ts_decorate3(decorators, target, key, desc) {
521
+ function _ts_decorate6(decorators, target, key, desc) {
212
522
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
213
523
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
214
524
  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;
215
525
  return c > 3 && r && Object.defineProperty(target, key, r), r;
216
526
  }
217
- __name(_ts_decorate3, "_ts_decorate");
218
- function _ts_metadata3(k, v) {
527
+ __name(_ts_decorate6, "_ts_decorate");
528
+ function _ts_metadata5(k, v) {
219
529
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
220
530
  }
221
- __name(_ts_metadata3, "_ts_metadata");
222
- function _ts_param3(paramIndex, decorator) {
531
+ __name(_ts_metadata5, "_ts_metadata");
532
+ function _ts_param5(paramIndex, decorator) {
223
533
  return function(target, key) {
224
534
  decorator(target, key, paramIndex);
225
535
  };
226
536
  }
227
- __name(_ts_param3, "_ts_param");
537
+ __name(_ts_param5, "_ts_param");
228
538
  var QUOTA_PROVIDERS_TOKEN = /* @__PURE__ */ Symbol.for("saas-platform-nest/QuotaProviders");
229
539
  var EnforceQuotaInterceptor = class {
230
540
  static {
@@ -267,14 +577,14 @@ var EnforceQuotaInterceptor = class {
267
577
  }
268
578
  }
269
579
  };
270
- EnforceQuotaInterceptor = _ts_decorate3([
271
- Injectable3(),
272
- _ts_param3(0, Inject3(Reflector2)),
273
- _ts_param3(1, Inject3(StaticEntitlementService)),
274
- _ts_param3(2, Optional2()),
275
- _ts_param3(2, Inject3(QUOTA_PROVIDERS_TOKEN)),
276
- _ts_metadata3("design:type", Function),
277
- _ts_metadata3("design:paramtypes", [
580
+ EnforceQuotaInterceptor = _ts_decorate6([
581
+ Injectable4(),
582
+ _ts_param5(0, Inject4(Reflector2)),
583
+ _ts_param5(1, Inject4(StaticEntitlementService)),
584
+ _ts_param5(2, Optional2()),
585
+ _ts_param5(2, Inject4(QUOTA_PROVIDERS_TOKEN)),
586
+ _ts_metadata5("design:type", Function),
587
+ _ts_metadata5("design:paramtypes", [
278
588
  typeof Reflector2 === "undefined" ? Object : Reflector2,
279
589
  typeof StaticEntitlementService === "undefined" ? Object : StaticEntitlementService,
280
590
  Object
@@ -322,18 +632,18 @@ var SubscriptionPlanResolver = class {
322
632
  };
323
633
 
324
634
  // src/platform/tenant-manifest.service.ts
325
- import { Injectable as Injectable4 } from "@nestjs/common";
326
- function _ts_decorate4(decorators, target, key, desc) {
635
+ import { Injectable as Injectable5 } from "@nestjs/common";
636
+ function _ts_decorate7(decorators, target, key, desc) {
327
637
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
328
638
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
329
639
  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;
330
640
  return c > 3 && r && Object.defineProperty(target, key, r), r;
331
641
  }
332
- __name(_ts_decorate4, "_ts_decorate");
333
- function _ts_metadata4(k, v) {
642
+ __name(_ts_decorate7, "_ts_decorate");
643
+ function _ts_metadata6(k, v) {
334
644
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
335
645
  }
336
- __name(_ts_metadata4, "_ts_metadata");
646
+ __name(_ts_metadata6, "_ts_metadata");
337
647
  var TenantManifestService = class {
338
648
  static {
339
649
  __name(this, "TenantManifestService");
@@ -379,10 +689,10 @@ var TenantManifestService = class {
379
689
  };
380
690
  }
381
691
  };
382
- TenantManifestService = _ts_decorate4([
383
- Injectable4(),
384
- _ts_metadata4("design:type", Function),
385
- _ts_metadata4("design:paramtypes", [
692
+ TenantManifestService = _ts_decorate7([
693
+ Injectable5(),
694
+ _ts_metadata6("design:type", Function),
695
+ _ts_metadata6("design:paramtypes", [
386
696
  typeof StaticEntitlementService === "undefined" ? Object : StaticEntitlementService
387
697
  ])
388
698
  ], TenantManifestService);
@@ -396,24 +706,24 @@ function isVisible(item, features) {
396
706
  __name(isVisible, "isVisible");
397
707
 
398
708
  // src/platform/tenant-manifest.controller.ts
399
- import { Controller, Get, Inject as Inject4, Req, UseGuards } from "@nestjs/common";
400
- function _ts_decorate5(decorators, target, key, desc) {
709
+ import { Controller as Controller2, Get as Get2, Inject as Inject5, Req, UseGuards } from "@nestjs/common";
710
+ function _ts_decorate8(decorators, target, key, desc) {
401
711
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
402
712
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
403
713
  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;
404
714
  return c > 3 && r && Object.defineProperty(target, key, r), r;
405
715
  }
406
- __name(_ts_decorate5, "_ts_decorate");
407
- function _ts_metadata5(k, v) {
716
+ __name(_ts_decorate8, "_ts_decorate");
717
+ function _ts_metadata7(k, v) {
408
718
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
409
719
  }
410
- __name(_ts_metadata5, "_ts_metadata");
411
- function _ts_param4(paramIndex, decorator) {
720
+ __name(_ts_metadata7, "_ts_metadata");
721
+ function _ts_param6(paramIndex, decorator) {
412
722
  return function(target, key) {
413
723
  decorator(target, key, paramIndex);
414
724
  };
415
725
  }
416
- __name(_ts_param4, "_ts_param");
726
+ __name(_ts_param6, "_ts_param");
417
727
  function buildTenantManifestController(options) {
418
728
  const path = options.path ?? "tenant/manifest";
419
729
  let GeneratedTenantManifestController = class GeneratedTenantManifestController {
@@ -432,21 +742,21 @@ function buildTenantManifestController(options) {
432
742
  return this.svc.getManifest(tenantId);
433
743
  }
434
744
  };
435
- _ts_decorate5([
436
- Get(),
437
- _ts_param4(0, Req()),
438
- _ts_metadata5("design:type", Function),
439
- _ts_metadata5("design:paramtypes", [
745
+ _ts_decorate8([
746
+ Get2(),
747
+ _ts_param6(0, Req()),
748
+ _ts_metadata7("design:type", Function),
749
+ _ts_metadata7("design:paramtypes", [
440
750
  typeof RequestWithUser === "undefined" ? Object : RequestWithUser
441
751
  ]),
442
- _ts_metadata5("design:returntype", Promise)
752
+ _ts_metadata7("design:returntype", Promise)
443
753
  ], GeneratedTenantManifestController.prototype, "get", null);
444
- GeneratedTenantManifestController = _ts_decorate5([
445
- Controller(path),
754
+ GeneratedTenantManifestController = _ts_decorate8([
755
+ Controller2(path),
446
756
  UseGuards(...options.guards),
447
- _ts_param4(0, Inject4(TenantManifestService)),
448
- _ts_metadata5("design:type", Function),
449
- _ts_metadata5("design:paramtypes", [
757
+ _ts_param6(0, Inject5(TenantManifestService)),
758
+ _ts_metadata7("design:type", Function),
759
+ _ts_metadata7("design:paramtypes", [
450
760
  typeof TenantManifestService === "undefined" ? Object : TenantManifestService
451
761
  ])
452
762
  ], GeneratedTenantManifestController);
@@ -455,16 +765,16 @@ function buildTenantManifestController(options) {
455
765
  __name(buildTenantManifestController, "buildTenantManifestController");
456
766
 
457
767
  // src/platform/saas-platform.module.ts
458
- import { Module } from "@nestjs/common";
768
+ import { Module as Module2 } from "@nestjs/common";
459
769
  import { APP_GUARD, APP_INTERCEPTOR } from "@nestjs/core";
460
770
  import { assertPersistenceCapabilities } from "@saasicat/types";
461
- function _ts_decorate6(decorators, target, key, desc) {
771
+ function _ts_decorate9(decorators, target, key, desc) {
462
772
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
463
773
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
464
774
  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;
465
775
  return c > 3 && r && Object.defineProperty(target, key, r), r;
466
776
  }
467
- __name(_ts_decorate6, "_ts_decorate");
777
+ __name(_ts_decorate9, "_ts_decorate");
468
778
  var PLATFORM_SUBSCRIPTION_REPOSITORY_TOKEN = /* @__PURE__ */ Symbol.for("saas-platform-nest/PlatformSubscriptionRepository");
469
779
  var STANDARD_MANIFEST_REGISTRATION_TOKEN = /* @__PURE__ */ Symbol.for("saas-platform-nest/StandardManifestRegistration");
470
780
  function buildStandardManifestContribution(catalog, adminResources, promoCodes) {
@@ -578,6 +888,10 @@ var SaasPlatformModule = class _SaasPlatformModule {
578
888
  const subscriptionBundlesConfig = options.subscriptionBundles || null;
579
889
  const adminResourcesConfig = options.adminResources || null;
580
890
  const promoCodesConfig = options.promoCodes || null;
891
+ const setupConfig = options.setup || null;
892
+ const adminStatsConfig = options.adminStats || null;
893
+ const checkoutOfferConfig = options.checkoutOffer || null;
894
+ const subscriptionContractConfig = options.subscriptionContract || null;
581
895
  const requiresFullEntitlement = Boolean(options.entitlement || tenantBillingConfig || subscriptionBundlesConfig);
582
896
  const adapters = {
583
897
  mfa: explicit.mfa ?? persistence?.core.mfa,
@@ -612,6 +926,18 @@ var SaasPlatformModule = class _SaasPlatformModule {
612
926
  if (promoCodesConfig && (!persistence?.promo || !adapters.transactionRunner)) {
613
927
  throw new Error("SaasPlatformModule.forRoot: promoCodes requires `persistence.promo` and a transactionRunner.");
614
928
  }
929
+ if (setupConfig && !((setupConfig === true ? void 0 : setupConfig.provisioningPort) ?? persistence?.core.superAdminProvisioning)) {
930
+ throw new Error("SaasPlatformModule.forRoot: setup is enabled, but no provisioningPort is available (set `setup.provisioningPort` or `persistence.core.superAdminProvisioning`).");
931
+ }
932
+ if (adminStatsConfig && !adminStatsConfig.auditStatsPort && !persistence?.core.auditStats) {
933
+ throw new Error("SaasPlatformModule.forRoot: adminStats is enabled, but no auditStatsPort is available (set `adminStats.auditStatsPort` or `persistence.core.auditStats`).");
934
+ }
935
+ if (subscriptionContractConfig) {
936
+ const explicitRepository = subscriptionContractConfig === true ? void 0 : subscriptionContractConfig.subscriptionContractRepository;
937
+ if (!explicitRepository && !persistence?.entitlement?.subscriptionContractRepository) {
938
+ throw new Error("SaasPlatformModule.forRoot: subscriptionContract is enabled, but no repository is available (set `subscriptionContract.subscriptionContractRepository` or use a compatible persistence bundle).");
939
+ }
940
+ }
615
941
  if (promoCodesConfig && promoCodesConfig !== true && promoCodesConfig.includePublicController !== false && !promoCodesConfig.firstTimeCustomerCheck) {
616
942
  throw new Error("SaasPlatformModule.forRoot: public promo preview requires `firstTimeCustomerCheck`.");
617
943
  }
@@ -695,6 +1021,7 @@ var SaasPlatformModule = class _SaasPlatformModule {
695
1021
  }),
696
1022
  AdminManifestModule.forRoot({
697
1023
  config: options.adminManifestConfig ?? buildMinimalManifestConfig(),
1024
+ extraProviders: options.adminManifestExtraProviders,
698
1025
  includeManifestController: options.includeManifestController,
699
1026
  guards: options.controller.guards,
700
1027
  reloadGuards: options.reloadGuards,
@@ -830,6 +1157,42 @@ var SaasPlatformModule = class _SaasPlatformModule {
830
1157
  extraProviders
831
1158
  }));
832
1159
  }
1160
+ if (setupConfig) {
1161
+ const config = setupConfig === true ? {} : setupConfig;
1162
+ imports.push(SetupModule.forRoot({
1163
+ ...config,
1164
+ provisioningPort: config.provisioningPort ?? persistence?.core.superAdminProvisioning,
1165
+ imports: config.imports ?? options.imports
1166
+ }));
1167
+ }
1168
+ if (adminStatsConfig) {
1169
+ imports.push(AdminStatsModule.forRoot({
1170
+ ...adminStatsConfig,
1171
+ guards: adminStatsConfig.guards ?? [
1172
+ ...options.controller.guards,
1173
+ SuperAdminGuard
1174
+ ],
1175
+ auditStatsPort: adminStatsConfig.auditStatsPort ?? persistence?.core.auditStats,
1176
+ imports: adminStatsConfig.imports ?? options.imports
1177
+ }));
1178
+ }
1179
+ if (checkoutOfferConfig) {
1180
+ imports.push(CheckoutOfferModule.forRoot({
1181
+ ...checkoutOfferConfig,
1182
+ bundleRepository: checkoutOfferConfig.bundleRepository ?? persistence?.catalog?.bundleRepository,
1183
+ planRepository: checkoutOfferConfig.planRepository ?? persistence?.catalog?.planRepository,
1184
+ catalogEntryRepository: checkoutOfferConfig.catalogEntryRepository ?? persistence?.catalog?.catalogEntryRepository,
1185
+ imports: checkoutOfferConfig.imports ?? options.imports
1186
+ }));
1187
+ }
1188
+ if (subscriptionContractConfig) {
1189
+ const config = subscriptionContractConfig === true ? {} : subscriptionContractConfig;
1190
+ imports.push(SubscriptionContractModule.forRoot({
1191
+ ...config,
1192
+ subscriptionContractRepository: config.subscriptionContractRepository ?? persistence?.entitlement?.subscriptionContractRepository,
1193
+ imports: config.imports ?? options.imports
1194
+ }));
1195
+ }
833
1196
  const lightweightProviders = [];
834
1197
  const lightweightExports = [];
835
1198
  if (options.autoManifest !== false) {
@@ -919,17 +1282,34 @@ var SaasPlatformModule = class _SaasPlatformModule {
919
1282
  ...promoCodesConfig ? [
920
1283
  PromoCodesModule
921
1284
  ] : [],
1285
+ ...setupConfig ? [
1286
+ SetupModule
1287
+ ] : [],
1288
+ ...adminStatsConfig ? [
1289
+ AdminStatsModule
1290
+ ] : [],
1291
+ ...checkoutOfferConfig ? [
1292
+ CheckoutOfferModule
1293
+ ] : [],
1294
+ ...subscriptionContractConfig ? [
1295
+ SubscriptionContractModule
1296
+ ] : [],
922
1297
  ...lightweightExports
923
1298
  ],
924
1299
  global: true
925
1300
  };
926
1301
  }
927
1302
  };
928
- SaasPlatformModule = _ts_decorate6([
929
- Module({})
1303
+ SaasPlatformModule = _ts_decorate9([
1304
+ Module2({})
930
1305
  ], SaasPlatformModule);
931
1306
 
932
1307
  export {
1308
+ SETUP_PROVISIONING_PORT_TOKEN,
1309
+ SETUP_CONFIG_TOKEN,
1310
+ SetupService,
1311
+ SetupController,
1312
+ SetupModule,
933
1313
  PLAN_RESOLVER_PORT_TOKEN,
934
1314
  StaticPlanResolver,
935
1315
  StaticEntitlementService,