@darraghor/nest-backend-libs 5.7.5 → 6.0.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 (134) hide show
  1. package/README.md +87 -36
  2. package/dist/exports/authorization.d.ts +14 -0
  3. package/dist/exports/authorization.js +12 -0
  4. package/dist/exports/authorization.js.map +1 -0
  5. package/dist/exports/core.d.ts +11 -0
  6. package/dist/exports/core.js +10 -0
  7. package/dist/exports/core.js.map +1 -0
  8. package/dist/exports/database.d.ts +5 -0
  9. package/dist/exports/database.js +6 -0
  10. package/dist/exports/database.js.map +1 -0
  11. package/dist/exports/email.d.ts +4 -0
  12. package/dist/exports/email.js +4 -0
  13. package/dist/exports/email.js.map +1 -0
  14. package/dist/exports/invitations.d.ts +6 -0
  15. package/dist/exports/invitations.js +6 -0
  16. package/dist/exports/invitations.js.map +1 -0
  17. package/dist/exports/organisations.d.ts +11 -0
  18. package/dist/exports/organisations.js +12 -0
  19. package/dist/exports/organisations.js.map +1 -0
  20. package/dist/exports/stripe-legacy.d.ts +6 -0
  21. package/dist/exports/stripe-legacy.js +7 -0
  22. package/dist/exports/stripe-legacy.js.map +1 -0
  23. package/dist/exports/stripe.d.ts +11 -0
  24. package/dist/exports/stripe.js +9 -0
  25. package/dist/exports/stripe.js.map +1 -0
  26. package/dist/exports/twitter.d.ts +5 -0
  27. package/dist/exports/twitter.js +5 -0
  28. package/dist/exports/twitter.js.map +1 -0
  29. package/dist/exports/users.d.ts +10 -0
  30. package/dist/exports/users.js +11 -0
  31. package/dist/exports/users.js.map +1 -0
  32. package/dist/index.d.ts +11 -0
  33. package/dist/index.js +11 -0
  34. package/dist/index.js.map +1 -1
  35. package/dist/organisation-subscriptions/entities/organisation-subscription.entity.js +2 -1
  36. package/dist/organisation-subscriptions/entities/organisation-subscription.entity.js.map +1 -1
  37. package/dist/stripe-client/StripeClientConfigurationService.js +1 -0
  38. package/dist/stripe-client/StripeClientConfigurationService.js.map +1 -1
  39. package/dist/stripe-client/controllers/stripe-checkout-controller.d.ts +1 -0
  40. package/dist/stripe-client/controllers/stripe-checkout-controller.js +1 -0
  41. package/dist/stripe-client/controllers/stripe-checkout-controller.js.map +1 -1
  42. package/dist/stripe-client/controllers/stripe-events-controller.js +1 -0
  43. package/dist/stripe-client/controllers/stripe-events-controller.js.map +1 -1
  44. package/dist/stripe-client/controllers/stripe-unauthenticated-checkout-controller.js +1 -0
  45. package/dist/stripe-client/controllers/stripe-unauthenticated-checkout-controller.js.map +1 -1
  46. package/dist/stripe-client/services/auth-stripe-checkout.service.js +1 -0
  47. package/dist/stripe-client/services/auth-stripe-checkout.service.js.map +1 -1
  48. package/dist/stripe-client/services/queued-payment-event.handler.d.ts +1 -0
  49. package/dist/stripe-client/services/queued-payment-event.handler.js +2 -0
  50. package/dist/stripe-client/services/queued-payment-event.handler.js.map +1 -1
  51. package/dist/stripe-client/services/stripe-checkout.service.d.ts +1 -0
  52. package/dist/stripe-client/services/stripe-checkout.service.js +2 -0
  53. package/dist/stripe-client/services/stripe-checkout.service.js.map +1 -1
  54. package/dist/stripe-client/stripe-account.module.d.ts +1 -0
  55. package/dist/stripe-client/stripe-account.module.js +2 -0
  56. package/dist/stripe-client/stripe-account.module.js.map +1 -1
  57. package/dist/stripe-client/stripe-account.options.d.ts +2 -0
  58. package/dist/stripe-client/stripe-account.options.js.map +1 -1
  59. package/dist/stripe-payments/controllers/secure-stripe-checkout.controller.d.ts +10 -0
  60. package/dist/stripe-payments/controllers/secure-stripe-checkout.controller.js +65 -0
  61. package/dist/stripe-payments/controllers/secure-stripe-checkout.controller.js.map +1 -0
  62. package/dist/stripe-payments/controllers/secure-stripe-events.controller.d.ts +9 -0
  63. package/dist/stripe-payments/controllers/secure-stripe-events.controller.js +65 -0
  64. package/dist/stripe-payments/controllers/secure-stripe-events.controller.js.map +1 -0
  65. package/dist/stripe-payments/controllers/secure-stripe-webhook.controller.d.ts +14 -0
  66. package/dist/stripe-payments/controllers/secure-stripe-webhook.controller.js +112 -0
  67. package/dist/stripe-payments/controllers/secure-stripe-webhook.controller.js.map +1 -0
  68. package/dist/stripe-payments/entities/stripe-checkout-attempt.entity.d.ts +15 -0
  69. package/dist/stripe-payments/entities/stripe-checkout-attempt.entity.js +88 -0
  70. package/dist/stripe-payments/entities/stripe-checkout-attempt.entity.js.map +1 -0
  71. package/dist/stripe-payments/entities/stripe-payment-event.entity.d.ts +16 -0
  72. package/dist/stripe-payments/entities/stripe-payment-event.entity.js +101 -0
  73. package/dist/stripe-payments/entities/stripe-payment-event.entity.js.map +1 -0
  74. package/dist/stripe-payments/entities/stripe-payment-state.entity.d.ts +9 -0
  75. package/dist/stripe-payments/entities/stripe-payment-state.entity.js +53 -0
  76. package/dist/stripe-payments/entities/stripe-payment-state.entity.js.map +1 -0
  77. package/dist/stripe-payments/models/secure-checkout.dto.d.ts +14 -0
  78. package/dist/stripe-payments/models/secure-checkout.dto.js +105 -0
  79. package/dist/stripe-payments/models/secure-checkout.dto.js.map +1 -0
  80. package/dist/stripe-payments/models/secure-payment-response.dto.d.ts +7 -0
  81. package/dist/stripe-payments/models/secure-payment-response.dto.js +30 -0
  82. package/dist/stripe-payments/models/secure-payment-response.dto.js.map +1 -0
  83. package/dist/stripe-payments/services/default-stripe-payments-entitlement-store.d.ts +12 -0
  84. package/dist/stripe-payments/services/default-stripe-payments-entitlement-store.js +49 -0
  85. package/dist/stripe-payments/services/default-stripe-payments-entitlement-store.js.map +1 -0
  86. package/dist/stripe-payments/services/secure-stripe-checkout.service.d.ts +24 -0
  87. package/dist/stripe-payments/services/secure-stripe-checkout.service.js +213 -0
  88. package/dist/stripe-payments/services/secure-stripe-checkout.service.js.map +1 -0
  89. package/dist/stripe-payments/services/secure-stripe-client.provider.d.ts +2 -0
  90. package/dist/stripe-payments/services/secure-stripe-client.provider.js +15 -0
  91. package/dist/stripe-payments/services/secure-stripe-client.provider.js.map +1 -0
  92. package/dist/stripe-payments/services/secure-stripe-product.service.d.ts +9 -0
  93. package/dist/stripe-payments/services/secure-stripe-product.service.js +54 -0
  94. package/dist/stripe-payments/services/secure-stripe-product.service.js.map +1 -0
  95. package/dist/stripe-payments/services/secure-stripe-webhook.service.d.ts +14 -0
  96. package/dist/stripe-payments/services/secure-stripe-webhook.service.js +58 -0
  97. package/dist/stripe-payments/services/secure-stripe-webhook.service.js.map +1 -0
  98. package/dist/stripe-payments/services/secure-subscription.service.d.ts +18 -0
  99. package/dist/stripe-payments/services/secure-subscription.service.js +217 -0
  100. package/dist/stripe-payments/services/secure-subscription.service.js.map +1 -0
  101. package/dist/stripe-payments/services/stripe-payment-event.processor.d.ts +15 -0
  102. package/dist/stripe-payments/services/stripe-payment-event.processor.js +78 -0
  103. package/dist/stripe-payments/services/stripe-payment-event.processor.js.map +1 -0
  104. package/dist/stripe-payments/services/stripe-payment-event.service.d.ts +20 -0
  105. package/dist/stripe-payments/services/stripe-payment-event.service.js +178 -0
  106. package/dist/stripe-payments/services/stripe-payment-event.service.js.map +1 -0
  107. package/dist/stripe-payments/services/stripe-payment-fulfillment.service.d.ts +31 -0
  108. package/dist/stripe-payments/services/stripe-payment-fulfillment.service.js +331 -0
  109. package/dist/stripe-payments/services/stripe-payment-fulfillment.service.js.map +1 -0
  110. package/dist/stripe-payments/services/stripe-payments-operations.service.d.ts +25 -0
  111. package/dist/stripe-payments/services/stripe-payments-operations.service.js +59 -0
  112. package/dist/stripe-payments/services/stripe-payments-operations.service.js.map +1 -0
  113. package/dist/stripe-payments/services/stripe-payments-telemetry.service.d.ts +7 -0
  114. package/dist/stripe-payments/services/stripe-payments-telemetry.service.js +40 -0
  115. package/dist/stripe-payments/services/stripe-payments-telemetry.service.js.map +1 -0
  116. package/dist/stripe-payments/stripe-payment.config.d.ts +19 -0
  117. package/dist/stripe-payments/stripe-payment.config.js +98 -0
  118. package/dist/stripe-payments/stripe-payment.config.js.map +1 -0
  119. package/dist/stripe-payments/stripe-payment.config.test.d.ts +1 -0
  120. package/dist/stripe-payments/stripe-payment.config.test.js +59 -0
  121. package/dist/stripe-payments/stripe-payment.config.test.js.map +1 -0
  122. package/dist/stripe-payments/stripe-payments.extensions.d.ts +69 -0
  123. package/dist/stripe-payments/stripe-payments.extensions.js +30 -0
  124. package/dist/stripe-payments/stripe-payments.extensions.js.map +1 -0
  125. package/dist/stripe-payments/stripe-payments.module.d.ts +12 -0
  126. package/dist/stripe-payments/stripe-payments.module.js +118 -0
  127. package/dist/stripe-payments/stripe-payments.module.js.map +1 -0
  128. package/dist/stripe-payments/stripe-payments.options.d.ts +21 -0
  129. package/dist/stripe-payments/stripe-payments.options.js +2 -0
  130. package/dist/stripe-payments/stripe-payments.options.js.map +1 -0
  131. package/dist/typeorm/entities.d.ts +15 -0
  132. package/dist/typeorm/entities.js +32 -0
  133. package/dist/typeorm/entities.js.map +1 -0
  134. package/package.json +41 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripe-payments-operations.service.js","sourceRoot":"","sources":["../../../src/stripe-payments/services/stripe-payments-operations.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAC,UAAU,EAAC,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAC,KAAK,EAAC,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAC,QAAQ,EAAE,UAAU,EAAC,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAC,mBAAmB,EAAC,MAAM,4CAA4C,CAAC;AAoBxE,IAAM,+BAA+B,GAArC,MAAM,+BAA+B;IAGnB;IAC8B;IAHnD,YAEqB,eAAgD,EAClB,UAAiB;QAD/C,oBAAe,GAAf,eAAe,CAAiC;QAClB,eAAU,GAAV,UAAU,CAAO;IACjE,CAAC;IAEJ,KAAK,CAAC,WAAW;QACb,MAAM,WAAW,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,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,KAAK;GAJ3D,+BAA+B,CAsC3C"}
@@ -0,0 +1,7 @@
1
+ import { StripePaymentsTelemetry, StripePaymentsTelemetryEvent } from "../stripe-payments.extensions.js";
2
+ export declare class StripePaymentsTelemetryService {
3
+ private readonly telemetry;
4
+ private readonly logger;
5
+ constructor(telemetry: StripePaymentsTelemetry);
6
+ record(event: StripePaymentsTelemetryEvent): Promise<void>;
7
+ }
@@ -0,0 +1,40 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ var StripePaymentsTelemetryService_1;
14
+ import { Inject, Injectable, Logger } from "@nestjs/common";
15
+ import { STRIPE_PAYMENTS_TELEMETRY, } from "../stripe-payments.extensions.js";
16
+ let StripePaymentsTelemetryService = StripePaymentsTelemetryService_1 = class StripePaymentsTelemetryService {
17
+ telemetry;
18
+ logger = new Logger(StripePaymentsTelemetryService_1.name);
19
+ constructor(telemetry) {
20
+ this.telemetry = telemetry;
21
+ }
22
+ async record(event) {
23
+ try {
24
+ await this.telemetry.record(event);
25
+ }
26
+ catch (error) {
27
+ this.logger.warn("Stripe payment telemetry sink failed", {
28
+ eventName: event.name,
29
+ error: error instanceof Error ? error.message : String(error),
30
+ });
31
+ }
32
+ }
33
+ };
34
+ StripePaymentsTelemetryService = StripePaymentsTelemetryService_1 = __decorate([
35
+ Injectable(),
36
+ __param(0, Inject(STRIPE_PAYMENTS_TELEMETRY)),
37
+ __metadata("design:paramtypes", [Object])
38
+ ], StripePaymentsTelemetryService);
39
+ export { StripePaymentsTelemetryService };
40
+ //# sourceMappingURL=stripe-payments-telemetry.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripe-payments-telemetry.service.js","sourceRoot":"","sources":["../../../src/stripe-payments/services/stripe-payments-telemetry.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAC,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EACH,yBAAyB,GAG5B,MAAM,kCAAkC,CAAC;AAGnC,IAAM,8BAA8B,sCAApC,MAAM,8BAA8B;IAKlB;IAJJ,MAAM,GAAG,IAAI,MAAM,CAAC,gCAA8B,CAAC,IAAI,CAAC,CAAC;IAE1E,YAEqB,SAAkC;QAAlC,cAAS,GAAT,SAAS,CAAyB;IACpD,CAAC;IAEJ,KAAK,CAAC,MAAM,CAAC,KAAmC;QAC5C,IAAI,CAAC;YACD,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,sCAAsC,EAAE;gBACrD,SAAS,EAAE,KAAK,CAAC,IAAI;gBACrB,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAChE,CAAC,CAAC;QACP,CAAC;IACL,CAAC;CACJ,CAAA;AAlBY,8BAA8B;IAD1C,UAAU,EAAE;IAKJ,WAAA,MAAM,CAAC,yBAAyB,CAAC,CAAA;;GAJ7B,8BAA8B,CAkB1C"}
@@ -0,0 +1,19 @@
1
+ import { Provider } from "@nestjs/common";
2
+ import { StripePaymentsModuleOptions, StripePaymentsMode, StripePaymentsProduct } from "./stripe-payments.options.js";
3
+ export interface SecureStripeProduct {
4
+ key: string;
5
+ priceId: string;
6
+ mode: StripePaymentsMode;
7
+ internalSku: string;
8
+ displayName: string;
9
+ }
10
+ export interface SecureStripeConfiguration {
11
+ accessToken: string;
12
+ webhookVerificationKey: string;
13
+ redirectsBaseUrl: string;
14
+ products: ReadonlyMap<string, SecureStripeProduct>;
15
+ }
16
+ export declare const SECURE_STRIPE_CONFIGURATION = "SecureStripeConfiguration";
17
+ export declare const secureStripeConfigurationProvider: Provider;
18
+ export declare function parseStripeProductCatalog(value: string): StripePaymentsProduct[];
19
+ export declare function createSecureStripeConfiguration(options: StripePaymentsModuleOptions): SecureStripeConfiguration;
@@ -0,0 +1,98 @@
1
+ import { STRIPE_PAYMENTS_OPTIONS, } from "./stripe-payments.options.js";
2
+ export const SECURE_STRIPE_CONFIGURATION = "SecureStripeConfiguration";
3
+ export const secureStripeConfigurationProvider = {
4
+ provide: SECURE_STRIPE_CONFIGURATION,
5
+ inject: [STRIPE_PAYMENTS_OPTIONS],
6
+ useFactory: (options) => createSecureStripeConfiguration(options),
7
+ };
8
+ function parseProduct(product) {
9
+ const mode = product.mode;
10
+ if (!/^[a-z0-9][a-z0-9_-]{0,63}$/.test(product.key) ||
11
+ !/^price_[A-Za-z0-9]+$/.test(product.priceId) ||
12
+ (mode !== "subscription" && mode !== "payment")) {
13
+ throw new Error(`Invalid Stripe product configuration: ${product.key}`);
14
+ }
15
+ return {
16
+ key: product.key,
17
+ priceId: product.priceId,
18
+ mode,
19
+ internalSku: product.internalSku ?? product.key,
20
+ displayName: product.displayName ?? product.key,
21
+ };
22
+ }
23
+ export function parseStripeProductCatalog(value) {
24
+ let parsed;
25
+ try {
26
+ parsed = JSON.parse(value);
27
+ }
28
+ catch (error) {
29
+ throw new Error("Stripe product catalog must contain valid JSON", {
30
+ cause: error,
31
+ });
32
+ }
33
+ if (typeof parsed !== "object" ||
34
+ parsed === null ||
35
+ Array.isArray(parsed)) {
36
+ throw new Error("Stripe product catalog must be an object keyed by product key");
37
+ }
38
+ return Object.entries(parsed).map(([key, product]) => {
39
+ if (typeof product !== "object" || product === null) {
40
+ throw new Error(`Invalid Stripe product configuration: ${key}`);
41
+ }
42
+ const candidate = product;
43
+ return {
44
+ key,
45
+ priceId: candidate.priceId ?? "",
46
+ mode: candidate.mode ?? "payment",
47
+ internalSku: candidate.internalSku,
48
+ displayName: candidate.displayName,
49
+ };
50
+ });
51
+ }
52
+ export function createSecureStripeConfiguration(options) {
53
+ if (!options.accessToken) {
54
+ throw new Error("Stripe accessToken is required");
55
+ }
56
+ if (!options.webhookVerificationKey) {
57
+ throw new Error("Stripe webhookVerificationKey is required");
58
+ }
59
+ if (!Array.isArray(options.products) || options.products.length === 0) {
60
+ throw new Error("Stripe products must contain at least one product");
61
+ }
62
+ const products = options.products;
63
+ let redirectsBaseUrl;
64
+ try {
65
+ redirectsBaseUrl = new URL(options.redirectsBaseUrl);
66
+ }
67
+ catch (error) {
68
+ throw new Error("Stripe redirectsBaseUrl must be a valid URL", {
69
+ cause: error,
70
+ });
71
+ }
72
+ if (!/^https?:$/.test(redirectsBaseUrl.protocol) ||
73
+ redirectsBaseUrl.pathname !== "/" ||
74
+ redirectsBaseUrl.search ||
75
+ redirectsBaseUrl.hash) {
76
+ throw new Error("Stripe redirectsBaseUrl must contain only an HTTP(S) origin");
77
+ }
78
+ const productsByKey = new Map();
79
+ const priceIds = new Set();
80
+ for (const productInput of products) {
81
+ const product = parseProduct(productInput);
82
+ if (productsByKey.has(product.key)) {
83
+ throw new Error(`Duplicate Stripe product key: ${product.key}`);
84
+ }
85
+ if (priceIds.has(product.priceId)) {
86
+ throw new Error(`Duplicate Stripe price ID: ${product.priceId}`);
87
+ }
88
+ productsByKey.set(product.key, product);
89
+ priceIds.add(product.priceId);
90
+ }
91
+ return {
92
+ accessToken: options.accessToken,
93
+ webhookVerificationKey: options.webhookVerificationKey,
94
+ redirectsBaseUrl: redirectsBaseUrl.origin,
95
+ products: productsByKey,
96
+ };
97
+ }
98
+ //# sourceMappingURL=stripe-payment.config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripe-payment.config.js","sourceRoot":"","sources":["../../src/stripe-payments/stripe-payment.config.ts"],"names":[],"mappings":"AACA,OAAO,EACH,uBAAuB,GAI1B,MAAM,8BAA8B,CAAC;AAiBtC,MAAM,CAAC,MAAM,2BAA2B,GAAG,2BAA2B,CAAC;AAEvE,MAAM,CAAC,MAAM,iCAAiC,GAAa;IACvD,OAAO,EAAE,2BAA2B;IACpC,MAAM,EAAE,CAAC,uBAAuB,CAAC;IACjC,UAAU,EAAE,CACR,OAAoC,EACX,EAAE,CAAC,+BAA+B,CAAC,OAAO,CAAC;CAC3E,CAAC;AAEF,SAAS,YAAY,CAAC,OAA8B;IAChD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAc,CAAC;IACpC,IACI,CAAC,4BAA4B,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;QAC/C,CAAC,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;QAC7C,CAAC,IAAI,KAAK,cAAc,IAAI,IAAI,KAAK,SAAS,CAAC,EACjD,CAAC;QACC,MAAM,IAAI,KAAK,CAAC,yCAAyC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC5E,CAAC;IAED,OAAO;QACH,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,IAAI;QACJ,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG;QAC/C,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG;KAClD,CAAC;AACN,CAAC;AAED,MAAM,UAAU,yBAAyB,CACrC,KAAa;IAEb,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACD,MAAM,GAAG,IAAI,CAAC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C,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAED,OAAO;QACH,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,sBAAsB,EAAE,OAAO,CAAC,sBAAsB;QACtD,gBAAgB,EAAE,gBAAgB,CAAC,MAAM;QACzC,QAAQ,EAAE,aAAa;KAC1B,CAAC;AACN,CAAC"}
@@ -0,0 +1,59 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { createSecureStripeConfiguration, parseStripeProductCatalog, } from "./stripe-payment.config.js";
3
+ import { SecureStripeProductService } from "./services/secure-stripe-product.service.js";
4
+ describe("secure Stripe payment configuration", () => {
5
+ it("parses the server-side catalog and normalizes the redirect origin", () => {
6
+ const result = createSecureStripeConfiguration({
7
+ accessToken: "sk_test_secret",
8
+ webhookVerificationKey: "whsec_secret",
9
+ redirectsBaseUrl: "https://app.example.com/",
10
+ products: parseStripeProductCatalog(JSON.stringify({
11
+ starter: {
12
+ priceId: "price_starter",
13
+ mode: "subscription",
14
+ internalSku: "starter",
15
+ displayName: "Starter",
16
+ },
17
+ })),
18
+ });
19
+ expect(result.redirectsBaseUrl).toBe("https://app.example.com");
20
+ expect(result.products.get("starter")).toEqual({
21
+ key: "starter",
22
+ priceId: "price_starter",
23
+ mode: "subscription",
24
+ internalSku: "starter",
25
+ displayName: "Starter",
26
+ });
27
+ });
28
+ it("rejects duplicate price IDs so one price cannot map to two products", () => {
29
+ expect(() => createSecureStripeConfiguration({
30
+ accessToken: "sk_test_secret",
31
+ webhookVerificationKey: "whsec_secret",
32
+ redirectsBaseUrl: "https://app.example.com",
33
+ products: parseStripeProductCatalog(JSON.stringify({
34
+ first: { priceId: "price_same", mode: "payment" },
35
+ second: { priceId: "price_same", mode: "payment" },
36
+ })),
37
+ })).toThrow("Duplicate Stripe price ID");
38
+ });
39
+ it("requires a non-empty server-side catalog", () => {
40
+ expect(() => createSecureStripeConfiguration({
41
+ accessToken: "sk_test_secret",
42
+ webhookVerificationKey: "whsec_secret",
43
+ redirectsBaseUrl: "https://app.example.com",
44
+ products: [],
45
+ })).toThrow("at least one product");
46
+ });
47
+ it("only builds redirects on the configured origin", () => {
48
+ const service = new SecureStripeProductService({
49
+ accessToken: "sk_test_secret",
50
+ webhookVerificationKey: "whsec_secret",
51
+ redirectsBaseUrl: "https://app.example.com",
52
+ products: new Map(),
53
+ });
54
+ expect(service.buildRedirectUrl("/dashboard")).toBe("https://app.example.com/dashboard");
55
+ expect(() => service.buildRedirectUrl("https://evil.example/steal")).toThrow("Redirect path");
56
+ expect(() => service.buildRedirectUrl("//evil.example/steal")).toThrow("Redirect path");
57
+ });
58
+ });
59
+ //# sourceMappingURL=stripe-payment.config.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripe-payment.config.test.js","sourceRoot":"","sources":["../../src/stripe-payments/stripe-payment.config.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAC,MAAM,QAAQ,CAAC;AAC5C,OAAO,EACH,+BAA+B,EAC/B,yBAAyB,GAC5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAC,0BAA0B,EAAC,MAAM,6CAA6C,CAAC;AAEvF,QAAQ,CAAC,qCAAqC,EAAE,GAAG,EAAE;IACjD,EAAE,CAAC,mEAAmE,EAAE,GAAG,EAAE;QACzE,MAAM,MAAM,GAAG,+BAA+B,CAAC;YAC3C,WAAW,EAAE,gBAAgB;YAC7B,sBAAsB,EAAE,cAAc;YACtC,gBAAgB,EAAE,0BAA0B;YAC5C,QAAQ,EAAE,yBAAyB,CAC/B,IAAI,CAAC,SAAS,CAAC;gBACX,OAAO,EAAE;oBACL,OAAO,EAAE,eAAe;oBACxB,IAAI,EAAE,cAAc;oBACpB,WAAW,EAAE,SAAS;oBACtB,WAAW,EAAE,SAAS;iBACzB;aACJ,CAAC,CACL;SACJ,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,gBAAgB,CA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B;YAC3C,QAAQ,EAAE,IAAI,GAAG,EAAE;SACtB,CAAC,CAAC;QAEH,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAC/C,mCAAmC,CACtC,CAAC;QACF,MAAM,CAAC,GAAG,EAAE,CACR,OAAO,CAAC,gBAAgB,CAAC,4BAA4B,CAAC,CACzD,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;QAC3B,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,sBAAsB,CAAC,CAAC,CAAC,OAAO,CAClE,eAAe,CAClB,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,69 @@
1
+ import type { RequestUser } from "../authorization/models/RequestWithUser.js";
2
+ export declare const STRIPE_PAYMENTS_ACCESS_POLICY: unique symbol;
3
+ export declare const STRIPE_PAYMENTS_TELEMETRY: unique symbol;
4
+ export declare const STRIPE_PAYMENTS_ENTITLEMENT_STORE: unique symbol;
5
+ export interface StripePaymentsAccessContext {
6
+ organisationUuid: string;
7
+ user: RequestUser;
8
+ operation: "checkout" | "customer-portal";
9
+ }
10
+ export interface StripePaymentsAccessPolicy {
11
+ assertCanManageOrganisation(context: StripePaymentsAccessContext): void | Promise<void>;
12
+ }
13
+ export interface StripePaymentsEntitlement {
14
+ uuid: string;
15
+ organisationUuid: string;
16
+ paymentSystemTransactionId: string;
17
+ paymentSystemCustomerId: string;
18
+ paymentSystemMode: string;
19
+ }
20
+ export interface StripePaymentsEntitlementInput {
21
+ paymentSystemTransactionId: string;
22
+ paymentSystemProductId: string;
23
+ paymentSystemCustomerId: string;
24
+ paymentSystemCustomerEmail: string;
25
+ paymentSystemMode: "subscription" | "payment";
26
+ paymentSystemName: "stripe";
27
+ validUntil: Date;
28
+ internalSku: string;
29
+ productDisplayName: string;
30
+ organisationUuid?: string;
31
+ stripeEventId: string;
32
+ stripeEventCreatedAt: Date;
33
+ stripeStatus: string;
34
+ }
35
+ export type StripePaymentsRevocationInput = Pick<StripePaymentsEntitlementInput, "stripeEventId" | "stripeEventCreatedAt" | "stripeStatus">;
36
+ export interface StripePaymentsEntitlementStore {
37
+ findByUuid(uuid: string): Promise<StripePaymentsEntitlement>;
38
+ findByTransactionId(paymentSystemTransactionId: string): Promise<StripePaymentsEntitlement | null>;
39
+ save(input: StripePaymentsEntitlementInput): Promise<void>;
40
+ revokeCustomerPayments(customerId: string, input: StripePaymentsRevocationInput): Promise<void>;
41
+ revokePayment(paymentSystemTransactionId: string, input: StripePaymentsRevocationInput): Promise<boolean>;
42
+ }
43
+ export type StripePaymentsTelemetryEvent = {
44
+ name: "checkout.created";
45
+ attemptId: number;
46
+ organisationUuid: string;
47
+ productKey: string;
48
+ stripeSessionId: string;
49
+ } | {
50
+ name: "checkout.failed";
51
+ attemptId: number;
52
+ organisationUuid: string;
53
+ productKey: string;
54
+ error: string;
55
+ } | {
56
+ name: "webhook.received" | "webhook.processed" | "webhook.failed";
57
+ stripeEventId: string;
58
+ eventType: string;
59
+ error?: string;
60
+ };
61
+ export interface StripePaymentsTelemetry {
62
+ record(event: StripePaymentsTelemetryEvent): void | Promise<void>;
63
+ }
64
+ export declare class DefaultStripePaymentsAccessPolicy implements StripePaymentsAccessPolicy {
65
+ assertCanManageOrganisation(context: StripePaymentsAccessContext): void;
66
+ }
67
+ export declare class NoopStripePaymentsTelemetry implements StripePaymentsTelemetry {
68
+ record(): void;
69
+ }
@@ -0,0 +1,30 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { ForbiddenException, Injectable } from "@nestjs/common";
8
+ export const STRIPE_PAYMENTS_ACCESS_POLICY = Symbol("STRIPE_PAYMENTS_ACCESS_POLICY");
9
+ export const STRIPE_PAYMENTS_TELEMETRY = Symbol("STRIPE_PAYMENTS_TELEMETRY");
10
+ export const STRIPE_PAYMENTS_ENTITLEMENT_STORE = Symbol("STRIPE_PAYMENTS_ENTITLEMENT_STORE");
11
+ let DefaultStripePaymentsAccessPolicy = class DefaultStripePaymentsAccessPolicy {
12
+ assertCanManageOrganisation(context) {
13
+ const isOwner = context.user.memberships
14
+ ?.filter((membership) => membership.roles?.some((role) => role.name === "owner"))
15
+ .some((membership) => membership.organisation.uuid === context.organisationUuid);
16
+ if (!isOwner) {
17
+ throw new ForbiddenException("You are not the owner of this organisation");
18
+ }
19
+ }
20
+ };
21
+ DefaultStripePaymentsAccessPolicy = __decorate([
22
+ Injectable()
23
+ ], DefaultStripePaymentsAccessPolicy);
24
+ export { DefaultStripePaymentsAccessPolicy };
25
+ export class NoopStripePaymentsTelemetry {
26
+ record() {
27
+ return;
28
+ }
29
+ }
30
+ //# sourceMappingURL=stripe-payments.extensions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripe-payments.extensions.js","sourceRoot":"","sources":["../../src/stripe-payments/stripe-payments.extensions.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAC,kBAAkB,EAAE,UAAU,EAAC,MAAM,gBAAgB,CAAC;AAG9D,MAAM,CAAC,MAAM,6BAA6B,GAAG,MAAM,CAC/C,+BAA+B,CAClC,CAAC;AACF,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAC7E,MAAM,CAAC,MAAM,iCAAiC,GAAG,MAAM,CACnD,mCAAmC,CACtC,CAAC;AAsFK,IAAM,iCAAiC,GAAvC,MAAM,iCAAiC;IAC1C,2BAA2B,CAAC,OAAoC;QAC5D,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,WAAW;YACpC,EAAE,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CACpB,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,CAC1D;aACA,IAAI,CACD,CAAC,UAAU,EAAE,EAAE,CACX,UAAU,CAAC,YAAY,CAAC,IAAI,KAAK,OAAO,CAAC,gBAAgB,CAChE,CAAC;QACN,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,MAAM,IAAI,kBAAkB,CACxB,4CAA4C,CAC/C,CAAC;QACN,CAAC;IACL,CAAC;CACJ,CAAA;AAhBY,iCAAiC;IAD7C,UAAU,EAAE;GACA,iCAAiC,CAgB7C;;AAED,MAAM,OAAO,2BAA2B;IACpC,MAAM;QACF,OAAO;IACX,CAAC;CACJ"}
@@ -0,0 +1,12 @@
1
+ import { DynamicModule } from "@nestjs/common";
2
+ import { StripePaymentsModuleAsyncOptions } from "./stripe-payments.options.js";
3
+ /**
4
+ * Opinionated Stripe payments for organisation-based applications.
5
+ *
6
+ * The module owns the Stripe boundary, product catalog, idempotency records,
7
+ * durable webhook inbox, retries, replay, and subscription state updates.
8
+ * Applications provide only their server-side Stripe configuration and catalog.
9
+ */
10
+ export declare class StripePaymentsModule {
11
+ static forRootAsync(options: StripePaymentsModuleAsyncOptions): DynamicModule;
12
+ }
@@ -0,0 +1,118 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var StripePaymentsModule_1;
8
+ import { BullModule } from "@nestjs/bullmq";
9
+ import { Module } from "@nestjs/common";
10
+ import { TypeOrmModule } from "@nestjs/typeorm";
11
+ import { Organisation } from "../organisation/entities/organisation.entity.js";
12
+ import { OrganisationSubscriptionsModule } from "../organisation-subscriptions/organisation-subscriptions.module.js";
13
+ import { OrganisationSubscriptionRecord } from "../organisation-subscriptions/entities/organisation-subscription.entity.js";
14
+ import { SubActivationQueueModule } from "../organisation-subscriptions/sub-activation-queue.module.js";
15
+ import { PaymentSessionModule } from "../payment-sessions/payment-session.module.js";
16
+ import { StripeCheckoutAttempt } from "./entities/stripe-checkout-attempt.entity.js";
17
+ import { StripeCheckoutEvent } from "./entities/stripe-payment-event.entity.js";
18
+ import { StripePaymentState } from "./entities/stripe-payment-state.entity.js";
19
+ import { SecureStripeCheckoutController } from "./controllers/secure-stripe-checkout.controller.js";
20
+ import { SecureStripeEventsController } from "./controllers/secure-stripe-events.controller.js";
21
+ import { SecureStripeWebhookController } from "./controllers/secure-stripe-webhook.controller.js";
22
+ import { secureStripeConfigurationProvider } from "./stripe-payment.config.js";
23
+ import { STRIPE_PAYMENTS_OPTIONS, } from "./stripe-payments.options.js";
24
+ import { secureStripeClientProvider } from "./services/secure-stripe-client.provider.js";
25
+ import { SecureStripeCheckoutService } from "./services/secure-stripe-checkout.service.js";
26
+ import { SecureStripeProductService } from "./services/secure-stripe-product.service.js";
27
+ import { SecureStripeWebhookService } from "./services/secure-stripe-webhook.service.js";
28
+ import { SecureSubscriptionService } from "./services/secure-subscription.service.js";
29
+ import { StripePaymentEventProcessor } from "./services/stripe-payment-event.processor.js";
30
+ import { StripePaymentEventService } from "./services/stripe-payment-event.service.js";
31
+ import { StripePaymentFulfillmentService } from "./services/stripe-payment-fulfillment.service.js";
32
+ import { DefaultStripePaymentsAccessPolicy, NoopStripePaymentsTelemetry, STRIPE_PAYMENTS_ACCESS_POLICY, STRIPE_PAYMENTS_ENTITLEMENT_STORE, STRIPE_PAYMENTS_TELEMETRY, } from "./stripe-payments.extensions.js";
33
+ import { StripePaymentsTelemetryService } from "./services/stripe-payments-telemetry.service.js";
34
+ import { StripePaymentsOperationsService } from "./services/stripe-payments-operations.service.js";
35
+ import { DefaultStripePaymentsEntitlementStore } from "./services/default-stripe-payments-entitlement-store.js";
36
+ /**
37
+ * Opinionated Stripe payments for organisation-based applications.
38
+ *
39
+ * The module owns the Stripe boundary, product catalog, idempotency records,
40
+ * durable webhook inbox, retries, replay, and subscription state updates.
41
+ * Applications provide only their server-side Stripe configuration and catalog.
42
+ */
43
+ let StripePaymentsModule = StripePaymentsModule_1 = class StripePaymentsModule {
44
+ static forRootAsync(options) {
45
+ return {
46
+ module: StripePaymentsModule_1,
47
+ global: options.isGlobal ?? false,
48
+ imports: [
49
+ ...(options.imports ?? []),
50
+ BullModule.registerQueue({ name: "stripe-events" }),
51
+ OrganisationSubscriptionsModule,
52
+ SubActivationQueueModule,
53
+ PaymentSessionModule,
54
+ TypeOrmModule.forFeature([
55
+ Organisation,
56
+ OrganisationSubscriptionRecord,
57
+ StripeCheckoutAttempt,
58
+ StripeCheckoutEvent,
59
+ StripePaymentState,
60
+ ]),
61
+ ],
62
+ providers: [
63
+ {
64
+ provide: STRIPE_PAYMENTS_OPTIONS,
65
+ useFactory: options.useFactory,
66
+ inject: options.inject ?? [],
67
+ },
68
+ secureStripeConfigurationProvider,
69
+ secureStripeClientProvider,
70
+ SecureStripeProductService,
71
+ SecureStripeCheckoutService,
72
+ SecureSubscriptionService,
73
+ DefaultStripePaymentsEntitlementStore,
74
+ StripePaymentEventService,
75
+ SecureStripeWebhookService,
76
+ StripePaymentFulfillmentService,
77
+ StripePaymentEventProcessor,
78
+ StripePaymentsTelemetryService,
79
+ StripePaymentsOperationsService,
80
+ {
81
+ provide: STRIPE_PAYMENTS_ACCESS_POLICY,
82
+ useClass: DefaultStripePaymentsAccessPolicy,
83
+ },
84
+ {
85
+ provide: STRIPE_PAYMENTS_TELEMETRY,
86
+ useClass: NoopStripePaymentsTelemetry,
87
+ },
88
+ {
89
+ provide: STRIPE_PAYMENTS_ENTITLEMENT_STORE,
90
+ useExisting: DefaultStripePaymentsEntitlementStore,
91
+ },
92
+ ...(options.providers ?? []),
93
+ ],
94
+ controllers: [
95
+ SecureStripeCheckoutController,
96
+ SecureStripeEventsController,
97
+ SecureStripeWebhookController,
98
+ ],
99
+ exports: [
100
+ BullModule,
101
+ SecureStripeProductService,
102
+ SecureStripeCheckoutService,
103
+ SecureSubscriptionService,
104
+ StripePaymentEventService,
105
+ StripePaymentsOperationsService,
106
+ StripePaymentsTelemetryService,
107
+ STRIPE_PAYMENTS_ACCESS_POLICY,
108
+ STRIPE_PAYMENTS_ENTITLEMENT_STORE,
109
+ STRIPE_PAYMENTS_TELEMETRY,
110
+ ],
111
+ };
112
+ }
113
+ };
114
+ StripePaymentsModule = StripePaymentsModule_1 = __decorate([
115
+ Module({})
116
+ ], StripePaymentsModule);
117
+ export { StripePaymentsModule };
118
+ //# sourceMappingURL=stripe-payments.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripe-payments.module.js","sourceRoot":"","sources":["../../src/stripe-payments/stripe-payments.module.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAgB,MAAM,EAAC,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,YAAY,EAAC,MAAM,iDAAiD,CAAC;AAC7E,OAAO,EAAC,+BAA+B,EAAC,MAAM,oEAAoE,CAAC;AACnH,OAAO,EAAC,8BAA8B,EAAC,MAAM,4EAA4E,CAAC;AAC1H,OAAO,EAAC,wBAAwB,EAAC,MAAM,8DAA8D,CAAC;AACtG,OAAO,EAAC,oBAAoB,EAAC,MAAM,+CAA+C,CAAC;AACnF,OAAO,EAAC,qBAAqB,EAAC,MAAM,8CA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ACN,CAAC;CACJ,CAAA;AAxEY,oBAAoB;IADhC,MAAM,CAAC,EAAE,CAAC;GACE,oBAAoB,CAwEhC"}
@@ -0,0 +1,21 @@
1
+ import type { ModuleMetadata } from "@nestjs/common";
2
+ export declare const STRIPE_PAYMENTS_OPTIONS = "StripePaymentsOptions";
3
+ export type StripePaymentsMode = "subscription" | "payment";
4
+ export interface StripePaymentsProduct {
5
+ key: string;
6
+ priceId: string;
7
+ mode: StripePaymentsMode;
8
+ internalSku?: string;
9
+ displayName?: string;
10
+ }
11
+ export interface StripePaymentsModuleOptions {
12
+ accessToken: string;
13
+ webhookVerificationKey: string;
14
+ redirectsBaseUrl: string;
15
+ products: readonly StripePaymentsProduct[];
16
+ }
17
+ export interface StripePaymentsModuleAsyncOptions extends Pick<ModuleMetadata, "imports" | "providers"> {
18
+ useFactory: (...arguments_: any[]) => Promise<StripePaymentsModuleOptions> | StripePaymentsModuleOptions;
19
+ inject?: any[];
20
+ isGlobal?: boolean;
21
+ }
@@ -0,0 +1,2 @@
1
+ export const STRIPE_PAYMENTS_OPTIONS = "StripePaymentsOptions";
2
+ //# sourceMappingURL=stripe-payments.options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripe-payments.options.js","sourceRoot":"","sources":["../../src/stripe-payments/stripe-payments.options.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,uBAAuB,GAAG,uBAAuB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { Invitation } from "../invitations/entities/invitation.entity.js";
2
+ import { OrganisationMembership } from "../organisation-memberships/entities/organisation-membership.entity.js";
3
+ import { OrganisationSubscriptionRecord } from "../organisation-subscriptions/entities/organisation-subscription.entity.js";
4
+ import { MembershipRole } from "../organisation/entities/member-role.entity.js";
5
+ import { Organisation } from "../organisation/entities/organisation.entity.js";
6
+ import { PaymentSessionReference } from "../payment-sessions/payment-session.entity.js";
7
+ import { Email } from "../smtp-email-client/email.entity.js";
8
+ import { StripeCheckoutEvent as LegacyStripeCheckoutEvent } from "../stripe-client/entities/stripe-checkout-event.entity.js";
9
+ import { StripeCheckoutAttempt } from "../stripe-payments/entities/stripe-checkout-attempt.entity.js";
10
+ import { StripeCheckoutEvent } from "../stripe-payments/entities/stripe-payment-event.entity.js";
11
+ import { StripePaymentState } from "../stripe-payments/entities/stripe-payment-state.entity.js";
12
+ import { UserApiKey } from "../user-api-key/userApiKey.entity.js";
13
+ import { User } from "../user/entities/user.entity.js";
14
+ export declare const STRIPE_PAYMENTS_ENTITIES: readonly [typeof StripeCheckoutAttempt, typeof StripeCheckoutEvent, typeof StripePaymentState];
15
+ export declare const NEST_BACKEND_LIB_ENTITIES: readonly [typeof Invitation, typeof OrganisationMembership, typeof OrganisationSubscriptionRecord, typeof MembershipRole, typeof Organisation, typeof PaymentSessionReference, typeof Email, typeof LegacyStripeCheckoutEvent, typeof StripeCheckoutAttempt, typeof StripeCheckoutEvent, typeof StripePaymentState, typeof UserApiKey, typeof User];
@@ -0,0 +1,32 @@
1
+ import { Invitation } from "../invitations/entities/invitation.entity.js";
2
+ import { OrganisationMembership } from "../organisation-memberships/entities/organisation-membership.entity.js";
3
+ import { OrganisationSubscriptionRecord } from "../organisation-subscriptions/entities/organisation-subscription.entity.js";
4
+ import { MembershipRole } from "../organisation/entities/member-role.entity.js";
5
+ import { Organisation } from "../organisation/entities/organisation.entity.js";
6
+ import { PaymentSessionReference } from "../payment-sessions/payment-session.entity.js";
7
+ import { Email } from "../smtp-email-client/email.entity.js";
8
+ import { StripeCheckoutEvent as LegacyStripeCheckoutEvent } from "../stripe-client/entities/stripe-checkout-event.entity.js";
9
+ import { StripeCheckoutAttempt } from "../stripe-payments/entities/stripe-checkout-attempt.entity.js";
10
+ import { StripeCheckoutEvent } from "../stripe-payments/entities/stripe-payment-event.entity.js";
11
+ import { StripePaymentState } from "../stripe-payments/entities/stripe-payment-state.entity.js";
12
+ import { UserApiKey } from "../user-api-key/userApiKey.entity.js";
13
+ import { User } from "../user/entities/user.entity.js";
14
+ export const STRIPE_PAYMENTS_ENTITIES = [
15
+ StripeCheckoutAttempt,
16
+ StripeCheckoutEvent,
17
+ StripePaymentState,
18
+ ];
19
+ export const NEST_BACKEND_LIB_ENTITIES = [
20
+ Invitation,
21
+ OrganisationMembership,
22
+ OrganisationSubscriptionRecord,
23
+ MembershipRole,
24
+ Organisation,
25
+ PaymentSessionReference,
26
+ Email,
27
+ LegacyStripeCheckoutEvent,
28
+ ...STRIPE_PAYMENTS_ENTITIES,
29
+ UserApiKey,
30
+ User,
31
+ ];
32
+ //# sourceMappingURL=entities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entities.js","sourceRoot":"","sources":["../../src/typeorm/entities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,8CAA8C,CAAC;AACxE,OAAO,EAAC,sBAAsB,EAAC,MAAM,wEAAwE,CAAC;AAC9G,OAAO,EAAC,8BAA8B,EAAC,MAAM,4EAA4E,CAAC;AAC1H,OAAO,EAAC,cAAc,EAAC,MAAM,gDAAgD,CAAC;AAC9E,OAAO,EAAC,YAAY,EAAC,MAAM,iDAAiD,CAAC;AAC7E,OAAO,EAAC,uBAAuB,EAAC,MAAM,+CAA+C,CAAC;AACtF,OAAO,EAAC,KAAK,EAAC,MAAM,sCAAsC,CAAC;AAC3D,OAAO,EAAC,mBAAmB,IAAI,yBAAyB,EAAC,MAAM,2DAA2D,CAAC;AAC3H,OAAO,EAAC,qBAAqB,EAAC,MAAM,+DAA+D,CAAC;AACpG,OAAO,EAAC,mBAAmB,EAAC,MAAM,4DAA4D,CAAC;AAC/F,OAAO,EAAC,kBAAkB,EAAC,MAAM,4DAA4D,CAAC;AAC9F,OAAO,EAAC,UAAU,EAAC,MAAM,sCAAsC,CAAC;AAChE,OAAO,EAAC,IAAI,EAAC,MAAM,iCAAiC,CAAC;AAErD,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACpC,qBAAqB;IACrB,mBAAmB;IACnB,kBAAkB;CACZ,CAAC;AAEX,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACrC,UAAU;IACV,sBAAsB;IACtB,8BAA8B;IAC9B,cAAc;IACd,YAAY;IACZ,uBAAuB;IACvB,KAAK;IACL,yBAAyB;IACzB,GAAG,wBAAwB;IAC3B,UAAU;IACV,IAAI;CACE,CAAC"}