@saasicat/nest 0.8.0 → 0.10.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 (95) hide show
  1. package/dist/_entries.cjs +17678 -0
  2. package/dist/admin/index.cjs +4 -1274
  3. package/dist/admin/index.d.cts +10 -171
  4. package/dist/admin/index.d.ts +10 -171
  5. package/dist/admin/index.js +13 -4
  6. package/dist/admin-resources.module-BZN_yBFj.d.cts +40 -0
  7. package/dist/admin-resources.module-Cms8MY6h.d.ts +40 -0
  8. package/dist/admin-stats.module-15ac5KY3.d.ts +201 -0
  9. package/dist/admin-stats.module-v4SVvWzj.d.cts +201 -0
  10. package/dist/billing/index.cjs +4 -5128
  11. package/dist/billing/index.d.cts +8 -719
  12. package/dist/billing/index.d.ts +8 -719
  13. package/dist/billing/index.js +7 -10
  14. package/dist/catalog/index.cjs +4 -5624
  15. package/dist/catalog/index.d.cts +7 -427
  16. package/dist/catalog/index.d.ts +7 -427
  17. package/dist/catalog/index.js +14 -12
  18. package/dist/catalog.module-BKObceo0.d.ts +103 -0
  19. package/dist/catalog.module-Dw2Hrbyu.d.cts +103 -0
  20. package/dist/checkout-offer/index.cjs +4 -807
  21. package/dist/checkout-offer/index.d.cts +5 -84
  22. package/dist/checkout-offer/index.d.ts +5 -84
  23. package/dist/checkout-offer/index.js +3 -2
  24. package/dist/checkout-offer.module-Y0hDOVrq.d.ts +85 -0
  25. package/dist/checkout-offer.module-ZYF5IsDY.d.cts +85 -0
  26. package/dist/{chunk-5DDCSGZC.js → chunk-33TP26MR.js} +144 -356
  27. package/dist/{chunk-CK54YKVK.js → chunk-75JABGZK.js} +16 -16
  28. package/dist/{chunk-HRU3CP57.js → chunk-BOADBIGB.js} +1 -1
  29. package/dist/{chunk-ZLUGQE5D.js → chunk-E7AJ42AB.js} +8 -8
  30. package/dist/{chunk-6LP7CDS2.js → chunk-F3VV6EXG.js} +18 -13
  31. package/dist/{chunk-PLDHI6NA.js → chunk-FVT7KTUI.js} +258 -3
  32. package/dist/{chunk-RZU4HIAN.js → chunk-GBDUH6DO.js} +26 -23
  33. package/dist/{chunk-K3OPNVFR.js → chunk-HBFU5AN3.js} +5 -9
  34. package/dist/chunk-HWGIMNWR.js +0 -0
  35. package/dist/chunk-IRWZC3GC.js +755 -0
  36. package/dist/chunk-L4KTQ6CL.js +20 -0
  37. package/dist/{chunk-T5SXXAKG.js → chunk-LZHLGUQI.js} +1 -1
  38. package/dist/{chunk-YHHE4KDA.js → chunk-PUXLPUVH.js} +351 -21
  39. package/dist/chunk-TXDH4FUA.js +211 -0
  40. package/dist/chunk-UF53DWWR.js +0 -0
  41. package/dist/{chunk-AJ3EPELS.js → chunk-V34AA7C7.js} +1 -1
  42. package/dist/chunk-WJ6BMDL3.js +313 -0
  43. package/dist/{chunk-M6CZQYPY.js → chunk-Z3FWN3HJ.js} +2 -2
  44. package/dist/discovery/index.cjs +4 -588
  45. package/dist/discovery/index.js +3 -3
  46. package/dist/{enforce-quota.interceptor-cv7r80VM.d.cts → enforce-quota.interceptor-BhkX5nq2.d.cts} +127 -12
  47. package/dist/{enforce-quota.interceptor-Dj1Kusr5.d.ts → enforce-quota.interceptor-CcqZc0Yu.d.ts} +127 -12
  48. package/dist/entitlement/index.cjs +4 -780
  49. package/dist/entitlement/index.d.cts +3 -1
  50. package/dist/entitlement/index.d.ts +3 -1
  51. package/dist/entitlement/index.js +2 -3
  52. package/dist/index.cjs +4 -14975
  53. package/dist/index.d.cts +22 -54
  54. package/dist/index.d.ts +22 -54
  55. package/dist/index.js +88 -369
  56. package/dist/module-CSN8j8Tp.d.cts +39 -0
  57. package/dist/module-DgYJur6f.d.ts +39 -0
  58. package/dist/plan-versions.service-BB36Q1bg.d.ts +329 -0
  59. package/dist/plan-versions.service-CUR2Whyr.d.cts +329 -0
  60. package/dist/platform/index.cjs +4 -2779
  61. package/dist/platform/index.d.cts +50 -8
  62. package/dist/platform/index.d.ts +50 -8
  63. package/dist/platform/index.js +116 -12
  64. package/dist/promo/index.cjs +4 -995
  65. package/dist/promo/index.d.cts +48 -46
  66. package/dist/promo/index.d.ts +48 -46
  67. package/dist/promo/index.js +10 -2
  68. package/dist/rate-limit.guard-dntqAlfZ.d.cts +19 -0
  69. package/dist/rate-limit.guard-dntqAlfZ.d.ts +19 -0
  70. package/dist/registration/index.cjs +4 -1655
  71. package/dist/registration/index.js +1 -1
  72. package/dist/setup.service-BPwJ7My_.d.cts +45 -0
  73. package/dist/setup.service-D2mrdDDB.d.ts +45 -0
  74. package/dist/subscription-bundle-preview.service-BkJXHAeP.d.cts +438 -0
  75. package/dist/subscription-bundle-preview.service-DBbrE_cw.d.ts +438 -0
  76. package/dist/subscription-bundles.module-BQmoozm5.d.ts +291 -0
  77. package/dist/subscription-bundles.module-DCpV-Pb5.d.cts +291 -0
  78. package/dist/subscription-contract/index.cjs +4 -471
  79. package/dist/subscription-contract/index.d.cts +5 -13
  80. package/dist/subscription-contract/index.d.ts +5 -13
  81. package/dist/subscription-contract.module-CG9fPKAr.d.cts +14 -0
  82. package/dist/subscription-contract.module-CVebZzHR.d.ts +14 -0
  83. package/dist/testing/index.cjs +4 -3756
  84. package/dist/testing/index.d.cts +9 -4
  85. package/dist/testing/index.d.ts +9 -4
  86. package/dist/testing/index.js +13 -7
  87. package/package.json +5 -5
  88. package/dist/admin-manifest.config-DyrQNT7M.d.cts +0 -10
  89. package/dist/admin-manifest.config-DyrQNT7M.d.ts +0 -10
  90. package/dist/admin-manifest.service-Cp6uwvmt.d.cts +0 -33
  91. package/dist/admin-manifest.service-UGgzR1x-.d.ts +0 -33
  92. package/dist/chunk-52UTQRD3.js +0 -326
  93. package/dist/chunk-N3WANKSA.js +0 -20
  94. package/dist/chunk-Q53N43LQ.js +0 -13
  95. /package/dist/{chunk-2FR6ZL7R.js → chunk-DBZGV3HC.js} +0 -0
@@ -1,12 +1,17 @@
1
1
  import { BundleRepository, BundleRow, BundleVersionRow, BundleListFilter, CreateBundleData, UpdateBundleData, CreateBundleVersionDraftData, UpdateBundleVersionDraftData, VersionChange, MarketingProjectionRepository, MarketingProjectionRow, MarketingProjectionFilter, CreateMarketingProjectionData, UpdateMarketingProjectionData, PlanRepository, PlanRow, PlanVersionRow, PlanListFilter, CreatePlanData, UpdatePlanData, CreatePlanVersionDraftData, UpdatePlanVersionDraftData, PlanVersionRepository, PlanVersionRecord, TransactionContext, SubscriptionBundleRepository, SubscriptionBundleRecord, CreateSubscriptionBundleData, CancelSubscriptionBundleData, SubscriptionContractRepository, SubscriptionContractFilter, SubscriptionContractRecord, CreateSubscriptionContractData, TerminateSubscriptionContractData, SubscriptionRepository, SubscriptionRecord, TransactionRunner, PlanCatalog, QuotaProvider } from '@saasicat/types';
2
2
  import { Type, DynamicModule } from '@nestjs/common';
3
- import { c as SaasPlatformAdapters } from '../enforce-quota.interceptor-cv7r80VM.cjs';
4
- export { E as EnforceQuotaInterceptor, P as PLAN_RESOLVER_PORT_TOKEN, S as StaticEntitlementService, g as StaticFeatureGuard, i as StaticPlanResolver } from '../enforce-quota.interceptor-cv7r80VM.cjs';
3
+ import { S as SaasPlatformAdapters } from '../enforce-quota.interceptor-BhkX5nq2.cjs';
4
+ export { E as EnforceQuotaInterceptor, P as PLAN_RESOLVER_PORT_TOKEN, a as StaticEntitlementService, b as StaticFeatureGuard, c as StaticPlanResolver } from '../enforce-quota.interceptor-BhkX5nq2.cjs';
5
5
  import '../di-CcNeq9v-.cjs';
6
- import '../admin-manifest.config-DyrQNT7M.cjs';
6
+ import '../admin-resources.module-BZN_yBFj.cjs';
7
+ import '../admin-audit.service-9IqXMlZm.cjs';
8
+ import '../plan-resolution-CFCoUkrE.cjs';
9
+ import '../module-CSN8j8Tp.cjs';
10
+ import '../service-DX8KbGXl.cjs';
7
11
  import '../discovery.scanner-DLgEvuoy.cjs';
8
12
  import '@nestjs/core';
9
- import '../plan-resolution-CFCoUkrE.cjs';
13
+ import '../catalog.module-Dw2Hrbyu.cjs';
14
+ import '../subscription-bundles.module-DCpV-Pb5.cjs';
10
15
  import 'rxjs';
11
16
 
12
17
  /**
@@ -1,12 +1,17 @@
1
1
  import { BundleRepository, BundleRow, BundleVersionRow, BundleListFilter, CreateBundleData, UpdateBundleData, CreateBundleVersionDraftData, UpdateBundleVersionDraftData, VersionChange, MarketingProjectionRepository, MarketingProjectionRow, MarketingProjectionFilter, CreateMarketingProjectionData, UpdateMarketingProjectionData, PlanRepository, PlanRow, PlanVersionRow, PlanListFilter, CreatePlanData, UpdatePlanData, CreatePlanVersionDraftData, UpdatePlanVersionDraftData, PlanVersionRepository, PlanVersionRecord, TransactionContext, SubscriptionBundleRepository, SubscriptionBundleRecord, CreateSubscriptionBundleData, CancelSubscriptionBundleData, SubscriptionContractRepository, SubscriptionContractFilter, SubscriptionContractRecord, CreateSubscriptionContractData, TerminateSubscriptionContractData, SubscriptionRepository, SubscriptionRecord, TransactionRunner, PlanCatalog, QuotaProvider } from '@saasicat/types';
2
2
  import { Type, DynamicModule } from '@nestjs/common';
3
- import { c as SaasPlatformAdapters } from '../enforce-quota.interceptor-Dj1Kusr5.js';
4
- export { E as EnforceQuotaInterceptor, P as PLAN_RESOLVER_PORT_TOKEN, S as StaticEntitlementService, g as StaticFeatureGuard, i as StaticPlanResolver } from '../enforce-quota.interceptor-Dj1Kusr5.js';
3
+ import { S as SaasPlatformAdapters } from '../enforce-quota.interceptor-CcqZc0Yu.js';
4
+ export { E as EnforceQuotaInterceptor, P as PLAN_RESOLVER_PORT_TOKEN, a as StaticEntitlementService, b as StaticFeatureGuard, c as StaticPlanResolver } from '../enforce-quota.interceptor-CcqZc0Yu.js';
5
5
  import '../di-CcNeq9v-.js';
6
- import '../admin-manifest.config-DyrQNT7M.js';
6
+ import '../admin-resources.module-Cms8MY6h.js';
7
+ import '../admin-audit.service-9IqXMlZm.js';
8
+ import '../plan-resolution-CFCoUkrE.js';
9
+ import '../module-DgYJur6f.js';
10
+ import '../service-DX8KbGXl.js';
7
11
  import '../discovery.scanner-DLgEvuoy.js';
8
12
  import '@nestjs/core';
9
- import '../plan-resolution-CFCoUkrE.js';
13
+ import '../catalog.module-BKObceo0.js';
14
+ import '../subscription-bundles.module-BQmoozm5.js';
10
15
  import 'rxjs';
11
16
 
12
17
  /**
@@ -5,17 +5,23 @@ import {
5
5
  StaticEntitlementService,
6
6
  StaticFeatureGuard,
7
7
  StaticPlanResolver
8
- } from "../chunk-YHHE4KDA.js";
9
- import "../chunk-PLDHI6NA.js";
10
- import "../chunk-Q53N43LQ.js";
8
+ } from "../chunk-PUXLPUVH.js";
9
+ import "../chunk-IRWZC3GC.js";
10
+ import "../chunk-FVT7KTUI.js";
11
+ import "../chunk-F3VV6EXG.js";
12
+ import "../chunk-E7AJ42AB.js";
13
+ import "../chunk-2PNX2QL2.js";
14
+ import "../chunk-33TP26MR.js";
15
+ import "../chunk-WPUVJRIN.js";
11
16
  import "../chunk-E56W4U2P.js";
12
- import "../chunk-AJ3EPELS.js";
13
- import "../chunk-M6CZQYPY.js";
14
- import "../chunk-RZU4HIAN.js";
17
+ import "../chunk-MDIZUVIK.js";
18
+ import "../chunk-V34AA7C7.js";
19
+ import "../chunk-Z3FWN3HJ.js";
20
+ import "../chunk-GBDUH6DO.js";
15
21
  import "../chunk-R2QOSVAA.js";
16
22
  import "../chunk-NYLON2VC.js";
17
23
  import "../chunk-WKVBNTYC.js";
18
- import "../chunk-N3WANKSA.js";
24
+ import "../chunk-L4KTQ6CL.js";
19
25
  import "../chunk-SABTXESR.js";
20
26
  import "../chunk-L4SUWH5B.js";
21
27
  import {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@saasicat/nest",
3
- "version": "0.8.0",
4
- "description": "NestJS implementation of the SaaS platform: billing, promo codes, admin backend, audit, MFA, adapter ports.",
3
+ "version": "0.10.0",
4
+ "description": "NestJS implementation of SaaSiCat: capability discovery, catalog packaging, contracts, entitlement enforcement, billing and admin APIs.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
@@ -137,8 +137,8 @@
137
137
  "js-yaml": "^4.1.0",
138
138
  "otplib": "^13.4.1",
139
139
  "qrcode": "^1.5.4",
140
- "@saasicat/spec": "^0.8.0",
141
- "@saasicat/types": "^0.8.0"
140
+ "@saasicat/spec": "^0.10.0",
141
+ "@saasicat/types": "^0.10.0"
142
142
  },
143
143
  "peerDependencies": {
144
144
  "@nestjs/common": "^11.0.0",
@@ -180,7 +180,7 @@
180
180
  "access": "public"
181
181
  },
182
182
  "scripts": {
183
- "build": "tsup",
183
+ "build": "tsup && tsup --config tsup.cjs.config.ts && node scripts/build-cjs-stubs.mjs",
184
184
  "pretest": "pnpm run build",
185
185
  "test": "node --test tests/**/*.test.js"
186
186
  }
@@ -1,10 +0,0 @@
1
- import { AdminManifest } from '@saasicat/types';
2
-
3
- declare const ADMIN_MANIFEST_CONFIG: unique symbol;
4
- interface AdminManifestConfig {
5
- project: AdminManifest['project'];
6
- build: Omit<AdminManifest['build'], 'manifestHash'>;
7
- planCatalogSnapshot: AdminManifest['planCatalogSnapshot'];
8
- }
9
-
10
- export { type AdminManifestConfig as A, ADMIN_MANIFEST_CONFIG as a };
@@ -1,10 +0,0 @@
1
- import { AdminManifest } from '@saasicat/types';
2
-
3
- declare const ADMIN_MANIFEST_CONFIG: unique symbol;
4
- interface AdminManifestConfig {
5
- project: AdminManifest['project'];
6
- build: Omit<AdminManifest['build'], 'manifestHash'>;
7
- planCatalogSnapshot: AdminManifest['planCatalogSnapshot'];
8
- }
9
-
10
- export { type AdminManifestConfig as A, ADMIN_MANIFEST_CONFIG as a };
@@ -1,33 +0,0 @@
1
- import { ManifestContribution, AdminManifest } from '@saasicat/types';
2
- import { A as AdminManifestConfig } from './admin-manifest.config-DyrQNT7M.cjs';
3
-
4
- /**
5
- * DI token for the platform core contribution. When `AdminManifestModule` is
6
- * configured with `registerPlatformCore: true` (default), the module provides
7
- * `PLATFORM_CORE_MANIFEST_CONTRIBUTION` under this token. The service
8
- * registers the contribution in the constructor — before all app `register()`
9
- * calls from `onModuleInit`.
10
- */
11
- declare const PLATFORM_CORE_CONTRIBUTION_TOKEN: unique symbol;
12
- declare class AdminManifestService {
13
- private readonly config;
14
- private readonly logger;
15
- private readonly contributions;
16
- private cached;
17
- constructor(config: AdminManifestConfig, platformCore?: ManifestContribution | null);
18
- register(contribution: ManifestContribution): void;
19
- getManifest(): AdminManifest;
20
- rebuild(): AdminManifest;
21
- private build;
22
- private mergeContributions;
23
- /**
24
- * Deterministic SHA-256 hash over the manifest. Uses the insertion
25
- * order of the object keys — so that semantically meaningful reorders (e.g.
26
- * the order of the sidebar items in `navigation.standardPages`) change the
27
- * hash and invalidate the browser ETag cache. The manifest's own
28
- * `manifestHash` field is hidden before serialization.
29
- */
30
- private computeHash;
31
- }
32
-
33
- export { AdminManifestService as A, PLATFORM_CORE_CONTRIBUTION_TOKEN as P };
@@ -1,33 +0,0 @@
1
- import { ManifestContribution, AdminManifest } from '@saasicat/types';
2
- import { A as AdminManifestConfig } from './admin-manifest.config-DyrQNT7M.js';
3
-
4
- /**
5
- * DI token for the platform core contribution. When `AdminManifestModule` is
6
- * configured with `registerPlatformCore: true` (default), the module provides
7
- * `PLATFORM_CORE_MANIFEST_CONTRIBUTION` under this token. The service
8
- * registers the contribution in the constructor — before all app `register()`
9
- * calls from `onModuleInit`.
10
- */
11
- declare const PLATFORM_CORE_CONTRIBUTION_TOKEN: unique symbol;
12
- declare class AdminManifestService {
13
- private readonly config;
14
- private readonly logger;
15
- private readonly contributions;
16
- private cached;
17
- constructor(config: AdminManifestConfig, platformCore?: ManifestContribution | null);
18
- register(contribution: ManifestContribution): void;
19
- getManifest(): AdminManifest;
20
- rebuild(): AdminManifest;
21
- private build;
22
- private mergeContributions;
23
- /**
24
- * Deterministic SHA-256 hash over the manifest. Uses the insertion
25
- * order of the object keys — so that semantically meaningful reorders (e.g.
26
- * the order of the sidebar items in `navigation.standardPages`) change the
27
- * hash and invalidate the browser ETag cache. The manifest's own
28
- * `manifestHash` field is hidden before serialization.
29
- */
30
- private computeHash;
31
- }
32
-
33
- export { AdminManifestService as A, PLATFORM_CORE_CONTRIBUTION_TOKEN as P };
@@ -1,326 +0,0 @@
1
- import {
2
- PROMO_CODE_REDEMPTION_REPOSITORY_TOKEN,
3
- PROMO_CODE_REPOSITORY_TOKEN,
4
- PROMO_CODE_VALIDATION_LOG_REPOSITORY_TOKEN,
5
- PROMO_FIRST_TIME_CUSTOMER_CHECK_TOKEN,
6
- PROMO_REVENUE_DEDUCTION_AGGREGATOR_TOKEN,
7
- PROMO_SERVICE_CONFIG_TOKEN,
8
- PROMO_SUBSCRIPTION_LOOKUP_TOKEN,
9
- PROMO_TRANSACTION_RUNNER_TOKEN,
10
- PromoCodesService
11
- } from "./chunk-ZLUGQE5D.js";
12
- import {
13
- asProvider
14
- } from "./chunk-SABTXESR.js";
15
- import {
16
- __name
17
- } from "./chunk-SHUYVCID.js";
18
-
19
- // src/promo/expirer.ts
20
- import { Inject, Injectable, Logger } from "@nestjs/common";
21
- import { Cron, CronExpression } from "@nestjs/schedule";
22
- function _ts_decorate(decorators, target, key, desc) {
23
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
24
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
25
- 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;
26
- return c > 3 && r && Object.defineProperty(target, key, r), r;
27
- }
28
- __name(_ts_decorate, "_ts_decorate");
29
- function _ts_metadata(k, v) {
30
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
31
- }
32
- __name(_ts_metadata, "_ts_metadata");
33
- function _ts_param(paramIndex, decorator) {
34
- return function(target, key) {
35
- decorator(target, key, paramIndex);
36
- };
37
- }
38
- __name(_ts_param, "_ts_param");
39
- var PromoCodeExpirer = class _PromoCodeExpirer {
40
- static {
41
- __name(this, "PromoCodeExpirer");
42
- }
43
- promoRepo;
44
- redemptionRepo;
45
- logger = new Logger(_PromoCodeExpirer.name);
46
- constructor(promoRepo, redemptionRepo) {
47
- this.promoRepo = promoRepo;
48
- this.redemptionRepo = redemptionRepo;
49
- }
50
- async expirePromoCodes() {
51
- const now = /* @__PURE__ */ new Date();
52
- const codes = await this.promoRepo.expireDueCodes(now);
53
- const redemptions = await this.redemptionRepo.expireDueRedemptions(now);
54
- if (codes > 0 || redemptions > 0) {
55
- this.logger.log(`PromoCodeExpirer: ${codes} Codes, ${redemptions} Redemptions abgelaufen.`);
56
- }
57
- }
58
- };
59
- _ts_decorate([
60
- Cron(CronExpression.EVERY_DAY_AT_3AM, {
61
- name: "promoCodeExpirer",
62
- timeZone: "Europe/Berlin"
63
- }),
64
- _ts_metadata("design:type", Function),
65
- _ts_metadata("design:paramtypes", []),
66
- _ts_metadata("design:returntype", Promise)
67
- ], PromoCodeExpirer.prototype, "expirePromoCodes", null);
68
- PromoCodeExpirer = _ts_decorate([
69
- Injectable(),
70
- _ts_param(0, Inject(PROMO_CODE_REPOSITORY_TOKEN)),
71
- _ts_param(1, Inject(PROMO_CODE_REDEMPTION_REPOSITORY_TOKEN)),
72
- _ts_metadata("design:type", Function),
73
- _ts_metadata("design:paramtypes", [
74
- typeof PromoCodeRepository === "undefined" ? Object : PromoCodeRepository,
75
- typeof PromoCodeRedemptionRepository === "undefined" ? Object : PromoCodeRedemptionRepository
76
- ])
77
- ], PromoCodeExpirer);
78
-
79
- // src/promo/rate-limit.guard.ts
80
- import { HttpException, HttpStatus, Injectable as Injectable2 } from "@nestjs/common";
81
- function _ts_decorate2(decorators, target, key, desc) {
82
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
83
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
84
- 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;
85
- return c > 3 && r && Object.defineProperty(target, key, r), r;
86
- }
87
- __name(_ts_decorate2, "_ts_decorate");
88
- var IP_WINDOW_MS = 6e4;
89
- var IP_LIMIT = 20;
90
- var SESSION_WINDOW_MS = 60 * 6e4;
91
- var SESSION_LIMIT = 50;
92
- var PromoCodeRateLimitGuard = class {
93
- static {
94
- __name(this, "PromoCodeRateLimitGuard");
95
- }
96
- ipBuckets = /* @__PURE__ */ new Map();
97
- sessionBuckets = /* @__PURE__ */ new Map();
98
- canActivate(context) {
99
- const req = context.switchToHttp().getRequest();
100
- const ipKey = ipFingerprint(req);
101
- const sessionKey = req.user?.id ?? null;
102
- if (this.exceeded(this.ipBuckets, ipKey, IP_WINDOW_MS, IP_LIMIT)) {
103
- throw new HttpException({
104
- valid: false,
105
- reason: "RATE_LIMITED"
106
- }, HttpStatus.TOO_MANY_REQUESTS);
107
- }
108
- if (sessionKey && this.exceeded(this.sessionBuckets, sessionKey, SESSION_WINDOW_MS, SESSION_LIMIT)) {
109
- throw new HttpException({
110
- valid: false,
111
- reason: "RATE_LIMITED"
112
- }, HttpStatus.TOO_MANY_REQUESTS);
113
- }
114
- return true;
115
- }
116
- exceeded(map, key, windowMs, limit) {
117
- const now = Date.now();
118
- const b = map.get(key);
119
- if (!b || now - b.windowStart > windowMs) {
120
- map.set(key, {
121
- count: 1,
122
- windowStart: now
123
- });
124
- return false;
125
- }
126
- b.count += 1;
127
- return b.count > limit;
128
- }
129
- };
130
- PromoCodeRateLimitGuard = _ts_decorate2([
131
- Injectable2()
132
- ], PromoCodeRateLimitGuard);
133
- function ipFingerprint(req) {
134
- const fwd = req.headers["x-forwarded-for"];
135
- const first = Array.isArray(fwd) ? fwd[0] : fwd?.split(",")[0]?.trim();
136
- return first || req.ip || "unknown";
137
- }
138
- __name(ipFingerprint, "ipFingerprint");
139
- function hashIp(req) {
140
- const fp = ipFingerprint(req);
141
- let h = 0;
142
- for (let i = 0; i < fp.length; i++) {
143
- h = h * 31 + fp.charCodeAt(i) | 0;
144
- }
145
- return `ip${(h >>> 0).toString(16)}`;
146
- }
147
- __name(hashIp, "hashIp");
148
-
149
- // src/promo/controller.ts
150
- import { Body, Controller, HttpCode, HttpStatus as HttpStatus2, Inject as Inject2, Post, Req, UseGuards } from "@nestjs/common";
151
-
152
- // src/promo/dto/promo-public.dto.ts
153
- import { IsEmail, IsOptional, IsString, Matches, MaxLength } from "class-validator";
154
- function _ts_decorate3(decorators, target, key, desc) {
155
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
156
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
157
- 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;
158
- return c > 3 && r && Object.defineProperty(target, key, r), r;
159
- }
160
- __name(_ts_decorate3, "_ts_decorate");
161
- function _ts_metadata2(k, v) {
162
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
163
- }
164
- __name(_ts_metadata2, "_ts_metadata");
165
- var PLAN_OR_CYCLE_PATTERN = /^[A-Z][A-Z0-9_]*$/;
166
- var CODE_PATTERN = /^[A-Z0-9_-]{4,32}$/i;
167
- var PreviewPromoCodeDto = class {
168
- static {
169
- __name(this, "PreviewPromoCodeDto");
170
- }
171
- code;
172
- plan;
173
- billingCycle;
174
- email;
175
- };
176
- _ts_decorate3([
177
- IsString(),
178
- Matches(CODE_PATTERN, {
179
- message: 'code muss aus A\u2013Z, 0\u20139, "-" und "_" bestehen (4\u201332 Zeichen)'
180
- }),
181
- _ts_metadata2("design:type", String)
182
- ], PreviewPromoCodeDto.prototype, "code", void 0);
183
- _ts_decorate3([
184
- IsString(),
185
- Matches(PLAN_OR_CYCLE_PATTERN, {
186
- message: "plan muss SCREAMING_SNAKE_CASE sein"
187
- }),
188
- _ts_metadata2("design:type", String)
189
- ], PreviewPromoCodeDto.prototype, "plan", void 0);
190
- _ts_decorate3([
191
- IsString(),
192
- Matches(PLAN_OR_CYCLE_PATTERN, {
193
- message: "billingCycle muss SCREAMING_SNAKE_CASE sein (z. B. MONTHLY, YEARLY)"
194
- }),
195
- _ts_metadata2("design:type", String)
196
- ], PreviewPromoCodeDto.prototype, "billingCycle", void 0);
197
- _ts_decorate3([
198
- IsOptional(),
199
- IsEmail(),
200
- MaxLength(254),
201
- _ts_metadata2("design:type", String)
202
- ], PreviewPromoCodeDto.prototype, "email", void 0);
203
-
204
- // src/promo/controller.ts
205
- function _ts_decorate4(decorators, target, key, desc) {
206
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
207
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
208
- 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;
209
- return c > 3 && r && Object.defineProperty(target, key, r), r;
210
- }
211
- __name(_ts_decorate4, "_ts_decorate");
212
- function _ts_metadata3(k, v) {
213
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
214
- }
215
- __name(_ts_metadata3, "_ts_metadata");
216
- function _ts_param2(paramIndex, decorator) {
217
- return function(target, key) {
218
- decorator(target, key, paramIndex);
219
- };
220
- }
221
- __name(_ts_param2, "_ts_param");
222
- var PromoCodePublicController = class {
223
- static {
224
- __name(this, "PromoCodePublicController");
225
- }
226
- promo;
227
- constructor(promo) {
228
- this.promo = promo;
229
- }
230
- async preview(dto, req) {
231
- return this.promo.preview({
232
- code: dto.code,
233
- planId: dto.plan,
234
- billingCycle: dto.billingCycle,
235
- email: dto.email,
236
- ipHash: hashIp(req),
237
- sessionId: req.user?.id ?? req.user?.sub
238
- });
239
- }
240
- };
241
- _ts_decorate4([
242
- Post("preview"),
243
- HttpCode(HttpStatus2.OK),
244
- UseGuards(PromoCodeRateLimitGuard),
245
- _ts_param2(0, Body()),
246
- _ts_param2(1, Req()),
247
- _ts_metadata3("design:type", Function),
248
- _ts_metadata3("design:paramtypes", [
249
- typeof PreviewPromoCodeDto === "undefined" ? Object : PreviewPromoCodeDto,
250
- typeof RequestLike === "undefined" ? Object : RequestLike
251
- ]),
252
- _ts_metadata3("design:returntype", Promise)
253
- ], PromoCodePublicController.prototype, "preview", null);
254
- PromoCodePublicController = _ts_decorate4([
255
- Controller("billing/promo"),
256
- _ts_param2(0, Inject2(PromoCodesService)),
257
- _ts_metadata3("design:type", Function),
258
- _ts_metadata3("design:paramtypes", [
259
- typeof PromoCodesService === "undefined" ? Object : PromoCodesService
260
- ])
261
- ], PromoCodePublicController);
262
-
263
- // src/promo/module.ts
264
- import { Module } from "@nestjs/common";
265
- function _ts_decorate5(decorators, target, key, desc) {
266
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
267
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
268
- 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;
269
- return c > 3 && r && Object.defineProperty(target, key, r), r;
270
- }
271
- __name(_ts_decorate5, "_ts_decorate");
272
- var PromoCodesModule = class _PromoCodesModule {
273
- static {
274
- __name(this, "PromoCodesModule");
275
- }
276
- static forRoot(options) {
277
- const includeCron = options.includeExpirerCron ?? true;
278
- const includePublic = options.includePublicController ?? true;
279
- const providers = [
280
- asProvider(PROMO_CODE_REPOSITORY_TOKEN, options.promoCodeRepository),
281
- asProvider(PROMO_CODE_REDEMPTION_REPOSITORY_TOKEN, options.redemptionRepository),
282
- asProvider(PROMO_CODE_VALIDATION_LOG_REPOSITORY_TOKEN, options.validationLogRepository),
283
- asProvider(PROMO_FIRST_TIME_CUSTOMER_CHECK_TOKEN, options.firstTimeCustomerCheck),
284
- asProvider(PROMO_SUBSCRIPTION_LOOKUP_TOKEN, options.subscriptionLookup),
285
- asProvider(PROMO_REVENUE_DEDUCTION_AGGREGATOR_TOKEN, options.revenueAggregator),
286
- asProvider(PROMO_TRANSACTION_RUNNER_TOKEN, options.transactionRunner),
287
- {
288
- provide: PROMO_SERVICE_CONFIG_TOKEN,
289
- useValue: options.config ?? {}
290
- },
291
- PromoCodesService,
292
- PromoCodeRateLimitGuard
293
- ];
294
- if (includeCron) {
295
- providers.push(PromoCodeExpirer);
296
- }
297
- return {
298
- module: _PromoCodesModule,
299
- global: options.global ?? false,
300
- controllers: includePublic ? [
301
- PromoCodePublicController
302
- ] : [],
303
- providers,
304
- exports: [
305
- PromoCodesService,
306
- PromoCodeRateLimitGuard,
307
- PROMO_CODE_REPOSITORY_TOKEN,
308
- PROMO_CODE_REDEMPTION_REPOSITORY_TOKEN,
309
- PROMO_CODE_VALIDATION_LOG_REPOSITORY_TOKEN
310
- ]
311
- };
312
- }
313
- };
314
- PromoCodesModule = _ts_decorate5([
315
- Module({})
316
- ], PromoCodesModule);
317
-
318
- export {
319
- PromoCodeExpirer,
320
- PromoCodeRateLimitGuard,
321
- ipFingerprint,
322
- hashIp,
323
- PreviewPromoCodeDto,
324
- PromoCodePublicController,
325
- PromoCodesModule
326
- };
@@ -1,20 +0,0 @@
1
- // src/catalog/tokens.ts
2
- var PLAN_REPOSITORY_TOKEN = /* @__PURE__ */ Symbol("PLAN_REPOSITORY");
3
- var BUNDLE_REPOSITORY_TOKEN = /* @__PURE__ */ Symbol("BUNDLE_REPOSITORY");
4
- var MARKETING_PROJECTION_REPOSITORY_TOKEN = /* @__PURE__ */ Symbol("MARKETING_PROJECTION_REPOSITORY");
5
- var CATALOG_ENTRY_REPOSITORY_TOKEN = /* @__PURE__ */ Symbol("CATALOG_ENTRY_REPOSITORY");
6
- var PROMOTION_REPOSITORY_TOKEN = /* @__PURE__ */ Symbol("PROMOTION_REPOSITORY");
7
- var MARKETING_SETTINGS_REPOSITORY_TOKEN = /* @__PURE__ */ Symbol("MARKETING_SETTINGS_REPOSITORY");
8
- var CATALOG_SERVICE_CONFIG_TOKEN = /* @__PURE__ */ Symbol("CATALOG_SERVICE_CONFIG");
9
- var FEATURE_UI_REGISTRY_TOKEN = /* @__PURE__ */ Symbol("FEATURE_UI_REGISTRY");
10
-
11
- export {
12
- PLAN_REPOSITORY_TOKEN,
13
- BUNDLE_REPOSITORY_TOKEN,
14
- MARKETING_PROJECTION_REPOSITORY_TOKEN,
15
- CATALOG_ENTRY_REPOSITORY_TOKEN,
16
- PROMOTION_REPOSITORY_TOKEN,
17
- MARKETING_SETTINGS_REPOSITORY_TOKEN,
18
- CATALOG_SERVICE_CONFIG_TOKEN,
19
- FEATURE_UI_REGISTRY_TOKEN
20
- };
@@ -1,13 +0,0 @@
1
- import {
2
- __name
3
- } from "./chunk-SHUYVCID.js";
4
-
5
- // src/billing/require-feature.decorator.ts
6
- import { SetMetadata } from "@nestjs/common";
7
- var REQUIRE_FEATURE_KEY = "require-feature";
8
- var RequireFeature = /* @__PURE__ */ __name((...features) => SetMetadata(REQUIRE_FEATURE_KEY, features), "RequireFeature");
9
-
10
- export {
11
- REQUIRE_FEATURE_KEY,
12
- RequireFeature
13
- };
File without changes