@classytic/revenue 1.1.4 → 2.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 (82) hide show
  1. package/CHANGELOG.md +90 -0
  2. package/README.md +638 -632
  3. package/dist/audit-B39B0Sdq.mjs +53 -0
  4. package/dist/audit-DZ0eTr9g.d.mts +89 -0
  5. package/dist/bridges/index.d.mts +2 -0
  6. package/dist/bridges/index.mjs +1 -0
  7. package/dist/context-DRqSeTPM.d.mts +35 -0
  8. package/dist/core/state-machines.d.mts +35 -0
  9. package/dist/core/state-machines.mjs +134 -0
  10. package/dist/engine-types-CcjIb4Fy.d.mts +611 -0
  11. package/dist/enums/index.d.mts +3 -157
  12. package/dist/enums/index.mjs +3 -55
  13. package/dist/errors-DHa8JVQ-.mjs +92 -0
  14. package/dist/escrow.schema-BBv9oVEW.mjs +322 -0
  15. package/dist/escrow.schema-CC8XuD46.d.mts +629 -0
  16. package/dist/event-constants-CEMitnIV.mjs +53 -0
  17. package/dist/events/index.d.mts +3 -0
  18. package/dist/events/index.mjs +4 -0
  19. package/dist/index.d.mts +77 -9
  20. package/dist/index.mjs +465 -29
  21. package/dist/monetization.enums-BtiU3t8o.mjs +39 -0
  22. package/dist/monetization.enums-D2xbxXJM.d.mts +34 -0
  23. package/dist/plugins/plugin.interface.d.mts +28 -0
  24. package/dist/plugins/plugin.interface.mjs +26 -0
  25. package/dist/providers/index.d.mts +2 -3
  26. package/dist/providers/index.mjs +2 -2
  27. package/dist/{base-DCoyIUj6.mjs → registry-DhFMsSn5.mjs} +34 -36
  28. package/dist/{base-CsTlVQJe.d.mts → registry-SvIGPAx_.d.mts} +73 -66
  29. package/dist/repositories/create-repositories.d.mts +21 -0
  30. package/dist/repositories/create-repositories.mjs +12 -0
  31. package/dist/revenue-bridges-sdlrR85c.d.mts +145 -0
  32. package/dist/revenue-event-catalog-BX3g7RUi.d.mts +823 -0
  33. package/dist/revenue-event-catalog-LqxPnsU_.mjs +388 -0
  34. package/dist/settlement.repository-Cy3mMWGH.mjs +771 -0
  35. package/dist/shared/index.d.mts +2 -0
  36. package/dist/shared/index.mjs +4 -0
  37. package/dist/split.enums-CQE3ekH1.mjs +172 -0
  38. package/dist/split.enums-Dw4zCrcZ.d.mts +154 -0
  39. package/dist/splits-BAfY-a9P.mjs +123 -0
  40. package/dist/validators/index.d.mts +2 -0
  41. package/dist/validators/index.mjs +3 -0
  42. package/package.json +33 -37
  43. package/dist/application/services/index.d.mts +0 -4
  44. package/dist/application/services/index.mjs +0 -3
  45. package/dist/category-resolver-DV83N8ok.mjs +0 -284
  46. package/dist/commission-split-BzB8cd39.mjs +0 -485
  47. package/dist/core/events.d.mts +0 -294
  48. package/dist/core/events.mjs +0 -100
  49. package/dist/core/index.d.mts +0 -9
  50. package/dist/core/index.mjs +0 -8
  51. package/dist/errors-rRdOqnWx.d.mts +0 -787
  52. package/dist/escrow.enums-CZGrrdg7.mjs +0 -101
  53. package/dist/escrow.enums-DwdLuuve.d.mts +0 -78
  54. package/dist/idempotency-DaYcUGY1.mjs +0 -172
  55. package/dist/index-Dsp7H5Wb.d.mts +0 -471
  56. package/dist/infrastructure/plugins/index.d.mts +0 -239
  57. package/dist/infrastructure/plugins/index.mjs +0 -345
  58. package/dist/money-CvrDOijQ.mjs +0 -271
  59. package/dist/money-DPG8AtJ8.d.mts +0 -112
  60. package/dist/payment.enums-HAuAS9Pp.d.mts +0 -70
  61. package/dist/payment.enums-tEFVa-Xp.mjs +0 -69
  62. package/dist/plugin-BbK0OVHy.d.mts +0 -327
  63. package/dist/plugin-Cd_V04Em.mjs +0 -210
  64. package/dist/reconciliation/index.d.mts +0 -193
  65. package/dist/reconciliation/index.mjs +0 -192
  66. package/dist/retry-HHCOXYdn.d.mts +0 -186
  67. package/dist/revenue-BhdS7nXh.mjs +0 -553
  68. package/dist/schemas/index.d.mts +0 -2665
  69. package/dist/schemas/index.mjs +0 -717
  70. package/dist/schemas/validation.d.mts +0 -375
  71. package/dist/schemas/validation.mjs +0 -325
  72. package/dist/settlement.enums-DFhkqZEY.d.mts +0 -132
  73. package/dist/settlement.schema-DnNSFpGd.d.mts +0 -344
  74. package/dist/settlement.service-DjzAjezU.d.mts +0 -594
  75. package/dist/settlement.service-DmdKv0Zu.mjs +0 -2511
  76. package/dist/split.enums-BrjabxIX.mjs +0 -86
  77. package/dist/split.enums-DmskfLOM.d.mts +0 -43
  78. package/dist/tax-BoCt5cEd.d.mts +0 -61
  79. package/dist/tax-EQ15DO81.mjs +0 -162
  80. package/dist/transaction.enums-pCyMFT4Z.mjs +0 -96
  81. package/dist/utils/index.d.mts +0 -428
  82. package/dist/utils/index.mjs +0 -346
@@ -0,0 +1,39 @@
1
+ //#region src/enums/payment.enums.ts
2
+ const PAYMENT_STATUS = {
3
+ PENDING: "pending",
4
+ VERIFIED: "verified",
5
+ FAILED: "failed",
6
+ REFUNDED: "refunded",
7
+ CANCELLED: "cancelled"
8
+ };
9
+ const PAYMENT_STATUS_VALUES = Object.values(PAYMENT_STATUS);
10
+ const PAYMENT_GATEWAY_TYPE = {
11
+ MANUAL: "manual",
12
+ STRIPE: "stripe",
13
+ SSLCOMMERZ: "sslcommerz"
14
+ };
15
+ const PAYMENT_GATEWAY_TYPE_VALUES = Object.values(PAYMENT_GATEWAY_TYPE);
16
+ const paymentStatusSet = new Set(PAYMENT_STATUS_VALUES);
17
+ const paymentGatewayTypeSet = new Set(PAYMENT_GATEWAY_TYPE_VALUES);
18
+ function isPaymentStatus(value) {
19
+ return typeof value === "string" && paymentStatusSet.has(value);
20
+ }
21
+ function isPaymentGatewayType(value) {
22
+ return typeof value === "string" && paymentGatewayTypeSet.has(value);
23
+ }
24
+
25
+ //#endregion
26
+ //#region src/enums/monetization.enums.ts
27
+ const MONETIZATION_TYPES = {
28
+ FREE: "free",
29
+ PURCHASE: "purchase",
30
+ SUBSCRIPTION: "subscription"
31
+ };
32
+ const MONETIZATION_TYPE_VALUES = Object.values(MONETIZATION_TYPES);
33
+ const monetizationTypeSet = new Set(MONETIZATION_TYPE_VALUES);
34
+ function isMonetizationType(value) {
35
+ return typeof value === "string" && monetizationTypeSet.has(value);
36
+ }
37
+
38
+ //#endregion
39
+ export { PAYMENT_GATEWAY_TYPE_VALUES as a, isPaymentGatewayType as c, PAYMENT_GATEWAY_TYPE as i, isPaymentStatus as l, MONETIZATION_TYPE_VALUES as n, PAYMENT_STATUS as o, isMonetizationType as r, PAYMENT_STATUS_VALUES as s, MONETIZATION_TYPES as t };
@@ -0,0 +1,34 @@
1
+ //#region src/enums/payment.enums.d.ts
2
+ declare const PAYMENT_STATUS: {
3
+ readonly PENDING: "pending";
4
+ readonly VERIFIED: "verified";
5
+ readonly FAILED: "failed";
6
+ readonly REFUNDED: "refunded";
7
+ readonly CANCELLED: "cancelled";
8
+ };
9
+ type PaymentStatus = typeof PAYMENT_STATUS;
10
+ type PaymentStatusValue = PaymentStatus[keyof PaymentStatus];
11
+ declare const PAYMENT_STATUS_VALUES: PaymentStatusValue[];
12
+ declare const PAYMENT_GATEWAY_TYPE: {
13
+ readonly MANUAL: "manual";
14
+ readonly STRIPE: "stripe";
15
+ readonly SSLCOMMERZ: "sslcommerz";
16
+ };
17
+ type PaymentGatewayType = typeof PAYMENT_GATEWAY_TYPE;
18
+ type PaymentGatewayTypeValue = PaymentGatewayType[keyof PaymentGatewayType];
19
+ declare const PAYMENT_GATEWAY_TYPE_VALUES: PaymentGatewayTypeValue[];
20
+ declare function isPaymentStatus(value: unknown): value is PaymentStatusValue;
21
+ declare function isPaymentGatewayType(value: unknown): value is PaymentGatewayTypeValue;
22
+ //#endregion
23
+ //#region src/enums/monetization.enums.d.ts
24
+ declare const MONETIZATION_TYPES: {
25
+ readonly FREE: "free";
26
+ readonly PURCHASE: "purchase";
27
+ readonly SUBSCRIPTION: "subscription";
28
+ };
29
+ type MonetizationTypes = typeof MONETIZATION_TYPES;
30
+ type MonetizationTypeValue = MonetizationTypes[keyof MonetizationTypes];
31
+ declare const MONETIZATION_TYPE_VALUES: MonetizationTypeValue[];
32
+ declare function isMonetizationType(value: unknown): value is MonetizationTypeValue;
33
+ //#endregion
34
+ export { isMonetizationType as a, PAYMENT_STATUS as c, PaymentGatewayTypeValue as d, PaymentStatus as f, isPaymentStatus as h, MonetizationTypes as i, PAYMENT_STATUS_VALUES as l, isPaymentGatewayType as m, MONETIZATION_TYPE_VALUES as n, PAYMENT_GATEWAY_TYPE as o, PaymentStatusValue as p, MonetizationTypeValue as r, PAYMENT_GATEWAY_TYPE_VALUES as s, MONETIZATION_TYPES as t, PaymentGatewayType as u };
@@ -0,0 +1,28 @@
1
+ //#region src/plugins/plugin.interface.d.ts
2
+ type HookPhase = 'before' | 'after';
3
+ interface PluginContext {
4
+ logger?: {
5
+ info: (...args: unknown[]) => void;
6
+ error: (...args: unknown[]) => void;
7
+ };
8
+ storage: Map<string, unknown>;
9
+ meta: {
10
+ idempotencyKey?: string;
11
+ requestId: string;
12
+ timestamp: Date;
13
+ [key: string]: unknown;
14
+ };
15
+ }
16
+ type HookHandler = (ctx: PluginContext, input: any, next: () => Promise<any>) => Promise<any>;
17
+ interface RevenuePluginDefinition {
18
+ name: string;
19
+ hooks?: Record<string, HookHandler>;
20
+ }
21
+ declare class PluginManager {
22
+ private plugins;
23
+ register(plugin: RevenuePluginDefinition): void;
24
+ getHooks(hookName: string): HookHandler[];
25
+ executeHook(hookName: string, ctx: PluginContext, input: any, execute: () => Promise<any>): Promise<any>;
26
+ }
27
+ //#endregion
28
+ export { HookHandler, HookPhase, PluginContext, PluginManager, RevenuePluginDefinition };
@@ -0,0 +1,26 @@
1
+ //#region src/plugins/plugin.interface.ts
2
+ var PluginManager = class {
3
+ plugins = [];
4
+ register(plugin) {
5
+ this.plugins.push(plugin);
6
+ }
7
+ getHooks(hookName) {
8
+ return this.plugins.filter((p) => p.hooks?.[hookName]).map((p) => p.hooks[hookName]);
9
+ }
10
+ async executeHook(hookName, ctx, input, execute) {
11
+ const hooks = this.getHooks(hookName);
12
+ if (hooks.length === 0) return execute();
13
+ let index = 0;
14
+ const next = async () => {
15
+ if (index < hooks.length) {
16
+ const hook = hooks[index++];
17
+ return hook(ctx, input, next);
18
+ }
19
+ return execute();
20
+ };
21
+ return next();
22
+ }
23
+ };
24
+
25
+ //#endregion
26
+ export { PluginManager };
@@ -1,3 +1,2 @@
1
- import { D as ProviderCapabilities, W as WebhookEventData, _ as PaymentIntentData, a as CreateIntentParams, b as PaymentResultData, k as RefundResultData } from "../index-Dsp7H5Wb.mjs";
2
- import { a as WebhookEvent, i as RefundResult, n as PaymentProvider, r as PaymentResult, t as PaymentIntent } from "../base-CsTlVQJe.mjs";
3
- export { type CreateIntentParams, PaymentIntent, type PaymentIntentData, PaymentProvider, type PaymentProvider as PaymentProviderDefault, PaymentResult, type PaymentResultData, type ProviderCapabilities, RefundResult, type RefundResultData, WebhookEvent, type WebhookEventData };
1
+ import { a as PaymentIntentData, c as PaymentResultData, d as RefundResultData, f as WebhookEvent, i as PaymentIntent, l as ProviderCapabilities, n as createProviderRegistry, o as PaymentProvider, p as WebhookEventData, r as CreateIntentParams, s as PaymentResult, t as ProviderRegistry, u as RefundResult } from "../registry-SvIGPAx_.mjs";
2
+ export { type CreateIntentParams, PaymentIntent, type PaymentIntentData, PaymentProvider, PaymentResult, type PaymentResultData, type ProviderCapabilities, ProviderRegistry, RefundResult, type RefundResultData, WebhookEvent, type WebhookEventData, createProviderRegistry };
@@ -1,3 +1,3 @@
1
- import { a as WebhookEvent, i as RefundResult, n as PaymentProvider, r as PaymentResult, t as PaymentIntent } from "../base-DCoyIUj6.mjs";
1
+ import { a as PaymentResult, i as PaymentProvider, n as createProviderRegistry, o as RefundResult, r as PaymentIntent, s as WebhookEvent, t as ProviderRegistry } from "../registry-DhFMsSn5.mjs";
2
2
 
3
- export { PaymentIntent, PaymentProvider, PaymentResult, RefundResult, WebhookEvent };
3
+ export { PaymentIntent, PaymentProvider, PaymentResult, ProviderRegistry, RefundResult, WebhookEvent, createProviderRegistry };
@@ -1,7 +1,6 @@
1
+ import { s as ProviderNotFoundError } from "./errors-DHa8JVQ-.mjs";
2
+
1
3
  //#region src/providers/base.ts
2
- /**
3
- * Payment Intent - standardized response from createIntent
4
- */
5
4
  var PaymentIntent = class {
6
5
  id;
7
6
  sessionId;
@@ -30,9 +29,6 @@ var PaymentIntent = class {
30
29
  this.raw = data.raw;
31
30
  }
32
31
  };
33
- /**
34
- * Payment Result - standardized response from verifyPayment
35
- */
36
32
  var PaymentResult = class {
37
33
  id;
38
34
  provider;
@@ -53,9 +49,6 @@ var PaymentResult = class {
53
49
  this.raw = data.raw;
54
50
  }
55
51
  };
56
- /**
57
- * Refund Result - standardized response from refund
58
- */
59
52
  var RefundResult = class {
60
53
  id;
61
54
  provider;
@@ -78,9 +71,6 @@ var RefundResult = class {
78
71
  this.raw = data.raw;
79
72
  }
80
73
  };
81
- /**
82
- * Webhook Event - standardized webhook event
83
- */
84
74
  var WebhookEvent = class {
85
75
  id;
86
76
  provider;
@@ -97,47 +87,24 @@ var WebhookEvent = class {
97
87
  this.raw = data.raw;
98
88
  }
99
89
  };
100
- /**
101
- * Base Payment Provider
102
- * All payment providers must extend this class
103
- */
104
90
  var PaymentProvider = class {
105
91
  config;
106
92
  name;
107
- /** Default currency - injected by Revenue when provider is registered */
108
93
  _defaultCurrency = "USD";
109
94
  constructor(config = {}) {
110
95
  this.config = config;
111
96
  this.name = "base";
112
97
  if (config.defaultCurrency && typeof config.defaultCurrency === "string") this._defaultCurrency = config.defaultCurrency;
113
98
  }
114
- /**
115
- * Get the default currency for this provider
116
- * Used when creating PaymentIntent, PaymentResult, RefundResult without explicit currency
117
- */
118
99
  get defaultCurrency() {
119
100
  return this._defaultCurrency;
120
101
  }
121
- /**
122
- * Set the default currency (called by Revenue when registering provider)
123
- * @internal
124
- */
125
102
  setDefaultCurrency(currency) {
126
103
  this._defaultCurrency = currency;
127
104
  }
128
- /**
129
- * Verify webhook signature (optional)
130
- * @param payload - Webhook payload
131
- * @param signature - Webhook signature
132
- * @returns boolean
133
- */
134
105
  verifyWebhookSignature(_payload, _signature) {
135
106
  return true;
136
107
  }
137
- /**
138
- * Get provider capabilities
139
- * @returns ProviderCapabilities
140
- */
141
108
  getCapabilities() {
142
109
  return {
143
110
  supportsWebhooks: false,
@@ -149,4 +116,35 @@ var PaymentProvider = class {
149
116
  };
150
117
 
151
118
  //#endregion
152
- export { WebhookEvent as a, RefundResult as i, PaymentProvider as n, PaymentResult as r, PaymentIntent as t };
119
+ //#region src/providers/registry.ts
120
+ var ProviderRegistry = class {
121
+ providers = /* @__PURE__ */ new Map();
122
+ register(name, provider) {
123
+ this.providers.set(name, provider);
124
+ }
125
+ get(name) {
126
+ const provider = this.providers.get(name);
127
+ if (!provider) throw new ProviderNotFoundError(name);
128
+ return provider;
129
+ }
130
+ has(name) {
131
+ return this.providers.has(name);
132
+ }
133
+ list() {
134
+ return Array.from(this.providers.keys());
135
+ }
136
+ setDefaultCurrency(currency) {
137
+ for (const provider of this.providers.values()) provider.setDefaultCurrency(currency);
138
+ }
139
+ };
140
+ function createProviderRegistry(providers = {}, defaultCurrency) {
141
+ const registry = new ProviderRegistry();
142
+ for (const [name, provider] of Object.entries(providers)) {
143
+ if (defaultCurrency) provider.setDefaultCurrency(defaultCurrency);
144
+ registry.register(name, provider);
145
+ }
146
+ return registry;
147
+ }
148
+
149
+ //#endregion
150
+ export { PaymentResult as a, PaymentProvider as i, createProviderRegistry as n, RefundResult as o, PaymentIntent as r, WebhookEvent as s, ProviderRegistry as t };
@@ -1,9 +1,65 @@
1
- import { D as ProviderCapabilities, W as WebhookEventData, _ as PaymentIntentData, a as CreateIntentParams, b as PaymentResultData, k as RefundResultData } from "./index-Dsp7H5Wb.mjs";
2
-
3
1
  //#region src/providers/base.d.ts
4
- /**
5
- * Payment Intent - standardized response from createIntent
6
- */
2
+ interface CreateIntentParams {
3
+ amount: number;
4
+ currency: string;
5
+ metadata?: Record<string, unknown>;
6
+ customerId?: string;
7
+ returnUrl?: string;
8
+ [key: string]: unknown;
9
+ }
10
+ interface PaymentIntentData {
11
+ id: string;
12
+ sessionId?: string | null;
13
+ paymentIntentId?: string | null;
14
+ provider: string;
15
+ status: string;
16
+ amount: number;
17
+ currency?: string;
18
+ metadata?: Record<string, unknown>;
19
+ clientSecret?: string;
20
+ paymentUrl?: string;
21
+ instructions?: string;
22
+ raw?: unknown;
23
+ }
24
+ interface PaymentResultData {
25
+ id: string;
26
+ provider: string;
27
+ status: 'succeeded' | 'failed' | 'processing' | 'requires_action';
28
+ amount?: number;
29
+ currency?: string;
30
+ paidAt?: Date;
31
+ metadata?: Record<string, unknown>;
32
+ raw?: unknown;
33
+ }
34
+ interface RefundResultData {
35
+ id: string;
36
+ provider: string;
37
+ status: 'succeeded' | 'failed' | 'processing';
38
+ amount?: number;
39
+ currency?: string;
40
+ refundedAt?: Date;
41
+ reason?: string;
42
+ metadata?: Record<string, unknown>;
43
+ raw?: unknown;
44
+ }
45
+ interface WebhookEventData {
46
+ id: string;
47
+ provider: string;
48
+ type: string;
49
+ data: {
50
+ sessionId?: string;
51
+ paymentIntentId?: string;
52
+ [key: string]: unknown;
53
+ };
54
+ createdAt?: Date;
55
+ raw?: unknown;
56
+ }
57
+ interface ProviderCapabilities {
58
+ supportsWebhooks: boolean;
59
+ supportsRefunds: boolean;
60
+ supportsPartialRefunds: boolean;
61
+ requiresManualVerification: boolean;
62
+ }
7
63
  declare class PaymentIntent implements PaymentIntentData {
8
64
  readonly id: string;
9
65
  readonly sessionId: string | null;
@@ -19,9 +75,6 @@ declare class PaymentIntent implements PaymentIntentData {
19
75
  readonly raw?: unknown;
20
76
  constructor(data: PaymentIntentData);
21
77
  }
22
- /**
23
- * Payment Result - standardized response from verifyPayment
24
- */
25
78
  declare class PaymentResult implements PaymentResultData {
26
79
  readonly id: string;
27
80
  readonly provider: string;
@@ -33,9 +86,6 @@ declare class PaymentResult implements PaymentResultData {
33
86
  readonly raw?: unknown;
34
87
  constructor(data: PaymentResultData);
35
88
  }
36
- /**
37
- * Refund Result - standardized response from refund
38
- */
39
89
  declare class RefundResult implements RefundResultData {
40
90
  readonly id: string;
41
91
  readonly provider: string;
@@ -48,9 +98,6 @@ declare class RefundResult implements RefundResultData {
48
98
  readonly raw?: unknown;
49
99
  constructor(data: RefundResultData);
50
100
  }
51
- /**
52
- * Webhook Event - standardized webhook event
53
- */
54
101
  declare class WebhookEvent implements WebhookEventData {
55
102
  readonly id: string;
56
103
  readonly provider: string;
@@ -64,73 +111,33 @@ declare class WebhookEvent implements WebhookEventData {
64
111
  readonly raw?: unknown;
65
112
  constructor(data: WebhookEventData);
66
113
  }
67
- /**
68
- * Base Payment Provider
69
- * All payment providers must extend this class
70
- */
71
114
  declare abstract class PaymentProvider {
72
115
  readonly config: Record<string, unknown>;
73
116
  readonly name: string;
74
- /** Default currency - injected by Revenue when provider is registered */
75
117
  private _defaultCurrency;
76
118
  constructor(config?: Record<string, unknown>);
77
- /**
78
- * Get the default currency for this provider
79
- * Used when creating PaymentIntent, PaymentResult, RefundResult without explicit currency
80
- */
81
119
  get defaultCurrency(): string;
82
- /**
83
- * Set the default currency (called by Revenue when registering provider)
84
- * @internal
85
- */
86
120
  setDefaultCurrency(currency: string): void;
87
- /**
88
- * Create a payment intent
89
- * @param params - Payment parameters
90
- * @returns Promise<PaymentIntent>
91
- */
92
121
  abstract createIntent(params: CreateIntentParams): Promise<PaymentIntent>;
93
- /**
94
- * Verify a payment
95
- * @param intentId - Payment intent ID
96
- * @returns Promise<PaymentResult>
97
- */
98
122
  abstract verifyPayment(intentId: string): Promise<PaymentResult>;
99
- /**
100
- * Get payment status
101
- * @param intentId - Payment intent ID
102
- * @returns Promise<PaymentResult>
103
- */
104
123
  abstract getStatus(intentId: string): Promise<PaymentResult>;
105
- /**
106
- * Refund a payment
107
- * @param paymentId - Payment ID
108
- * @param amount - Amount to refund (optional, full refund if not provided)
109
- * @param options - Refund options
110
- * @returns Promise<RefundResult>
111
- */
112
124
  abstract refund(paymentId: string, amount?: number | null, options?: {
113
125
  reason?: string;
114
126
  }): Promise<RefundResult>;
115
- /**
116
- * Handle webhook from provider
117
- * @param payload - Webhook payload
118
- * @param headers - Request headers (for signature verification)
119
- * @returns Promise<WebhookEvent>
120
- */
121
127
  abstract handleWebhook(payload: unknown, headers?: Record<string, string>): Promise<WebhookEvent>;
122
- /**
123
- * Verify webhook signature (optional)
124
- * @param payload - Webhook payload
125
- * @param signature - Webhook signature
126
- * @returns boolean
127
- */
128
128
  verifyWebhookSignature(_payload: unknown, _signature: string): boolean;
129
- /**
130
- * Get provider capabilities
131
- * @returns ProviderCapabilities
132
- */
133
129
  getCapabilities(): ProviderCapabilities;
134
130
  }
135
131
  //#endregion
136
- export { WebhookEvent as a, RefundResult as i, PaymentProvider as n, PaymentResult as r, PaymentIntent as t };
132
+ //#region src/providers/registry.d.ts
133
+ declare class ProviderRegistry {
134
+ private providers;
135
+ register(name: string, provider: PaymentProvider): void;
136
+ get(name: string): PaymentProvider;
137
+ has(name: string): boolean;
138
+ list(): string[];
139
+ setDefaultCurrency(currency: string): void;
140
+ }
141
+ declare function createProviderRegistry(providers?: Record<string, PaymentProvider>, defaultCurrency?: string): ProviderRegistry;
142
+ //#endregion
143
+ export { PaymentIntentData as a, PaymentResultData as c, RefundResultData as d, WebhookEvent as f, PaymentIntent as i, ProviderCapabilities as l, createProviderRegistry as n, PaymentProvider as o, WebhookEventData as p, CreateIntentParams as r, PaymentResult as s, ProviderRegistry as t, RefundResult as u };
@@ -0,0 +1,21 @@
1
+ import { a as SettlementRepository, c as RevenueModels, o as SubscriptionRepository, s as TransactionRepository } from "../engine-types-CcjIb4Fy.mjs";
2
+ import { PluginType } from "@classytic/mongokit";
3
+
4
+ //#region src/repositories/create-repositories.d.ts
5
+ interface RevenueRepositories {
6
+ transaction: TransactionRepository;
7
+ subscription?: SubscriptionRepository;
8
+ settlement?: SettlementRepository;
9
+ }
10
+ interface RepositoryPluginBundle {
11
+ transaction?: PluginType[];
12
+ subscription?: PluginType[];
13
+ settlement?: PluginType[];
14
+ }
15
+ declare function createRevenueRepositories(models: RevenueModels, builtInPlugins: {
16
+ transaction: PluginType[];
17
+ subscription: PluginType[];
18
+ settlement: PluginType[];
19
+ }, hostPlugins?: RepositoryPluginBundle): RevenueRepositories;
20
+ //#endregion
21
+ export { RepositoryPluginBundle, RevenueRepositories, createRevenueRepositories };
@@ -0,0 +1,12 @@
1
+ import { n as SubscriptionRepository, r as TransactionRepository, t as SettlementRepository } from "../settlement.repository-Cy3mMWGH.mjs";
2
+
3
+ //#region src/repositories/create-repositories.ts
4
+ function createRevenueRepositories(models, builtInPlugins, hostPlugins = {}) {
5
+ const repos = { transaction: new TransactionRepository(models.Transaction, [...builtInPlugins.transaction, ...hostPlugins.transaction ?? []]) };
6
+ if (models.Subscription) repos.subscription = new SubscriptionRepository(models.Subscription, [...builtInPlugins.subscription, ...hostPlugins.subscription ?? []]);
7
+ if (models.Settlement) repos.settlement = new SettlementRepository(models.Settlement, [...builtInPlugins.settlement, ...hostPlugins.settlement ?? []]);
8
+ return repos;
9
+ }
10
+
11
+ //#endregion
12
+ export { createRevenueRepositories };
@@ -0,0 +1,145 @@
1
+ import { t as RevenueContext } from "./context-DRqSeTPM.mjs";
2
+
3
+ //#region src/bridges/ledger.bridge.d.ts
4
+ interface LedgerBridge {
5
+ onPaymentVerified?(transaction: Record<string, unknown>, ctx: RevenueContext): Promise<void>;
6
+ onRefundProcessed?(original: Record<string, unknown>, refund: Record<string, unknown>, ctx: RevenueContext): Promise<void>;
7
+ onSettlementCompleted?(settlement: Record<string, unknown>, ctx: RevenueContext): Promise<void>;
8
+ }
9
+ //#endregion
10
+ //#region src/bridges/tax.bridge.d.ts
11
+ interface TaxBridge {
12
+ computeTax?(amount: number, taxClass: string, ctx: RevenueContext): Promise<{
13
+ rate: number;
14
+ amount: number;
15
+ inclusive: boolean;
16
+ }>;
17
+ }
18
+ //#endregion
19
+ //#region src/bridges/notification.bridge.d.ts
20
+ interface NotificationBridge {
21
+ onPaymentVerified?(transaction: Record<string, unknown>, ctx: RevenueContext): Promise<void>;
22
+ onRefundProcessed?(transaction: Record<string, unknown>, ctx: RevenueContext): Promise<void>;
23
+ onSubscriptionCreated?(subscription: Record<string, unknown>, ctx: RevenueContext): Promise<void>;
24
+ onSubscriptionCancelled?(subscription: Record<string, unknown>, ctx: RevenueContext): Promise<void>;
25
+ onSettlementCompleted?(settlement: Record<string, unknown>, ctx: RevenueContext): Promise<void>;
26
+ }
27
+ //#endregion
28
+ //#region src/bridges/currency.bridge.d.ts
29
+ interface CurrencyBridge {
30
+ convert?(amount: number, from: string, to: string, date?: Date): Promise<{
31
+ amount: number;
32
+ rate: number;
33
+ }>;
34
+ }
35
+ //#endregion
36
+ //#region src/bridges/customer.bridge.d.ts
37
+ interface CustomerBridge {
38
+ getCustomer?(customerId: string): Promise<{
39
+ id: string;
40
+ name?: string;
41
+ email?: string;
42
+ metadata?: Record<string, unknown>;
43
+ } | null>;
44
+ }
45
+ //#endregion
46
+ //#region src/bridges/analytics.bridge.d.ts
47
+ interface AnalyticsBridge {
48
+ trackEvent?(name: string, payload: Record<string, unknown>): Promise<void>;
49
+ }
50
+ //#endregion
51
+ //#region src/bridges/source.bridge.d.ts
52
+ /**
53
+ * SourceBridge — resolve polymorphic source documents (Order, Invoice, Subscription, etc.)
54
+ *
55
+ * Revenue stores `sourceId` as a String to support any ID format:
56
+ * • Mongoose ObjectId hex strings (same MongoDB)
57
+ * • UUIDs (Postgres, external systems)
58
+ * • Stripe IDs (pi_..., ch_..., sub_...)
59
+ * • REST API IDs (any string)
60
+ *
61
+ * The host implements this bridge to teach revenue how to load source documents.
62
+ *
63
+ * @example Same MongoDB, same connection
64
+ * ```typescript
65
+ * const sourceBridge: SourceBridge = {
66
+ * async resolve(sourceId, sourceModel, ctx) {
67
+ * const Model = mongoose.connection.models[sourceModel];
68
+ * return Model ? await Model.findById(sourceId).lean() : null;
69
+ * },
70
+ * };
71
+ * ```
72
+ *
73
+ * @example Microservices (cross-DB Mongoose)
74
+ * ```typescript
75
+ * const sourceBridge: SourceBridge = {
76
+ * async resolve(sourceId, sourceModel, ctx) {
77
+ * if (sourceModel === 'Order') return await ordersDb.collection('orders').findOne({ _id: sourceId });
78
+ * if (sourceModel === 'Invoice') return await invoicesDb.collection('invoices').findOne({ _id: sourceId });
79
+ * return null;
80
+ * },
81
+ * };
82
+ * ```
83
+ *
84
+ * @example External systems (REST/Stripe/Postgres)
85
+ * ```typescript
86
+ * const sourceBridge: SourceBridge = {
87
+ * async resolve(sourceId, sourceModel, ctx) {
88
+ * if (sourceModel === 'StripeCharge') {
89
+ * return await stripe.charges.retrieve(sourceId);
90
+ * }
91
+ * if (sourceModel === 'PostgresOrder') {
92
+ * const { rows } = await pg.query('SELECT * FROM orders WHERE id = $1', [sourceId]);
93
+ * return rows[0];
94
+ * }
95
+ * return null;
96
+ * },
97
+ * };
98
+ * ```
99
+ *
100
+ * @example Batch resolution (perf optimization)
101
+ * ```typescript
102
+ * const sourceBridge: SourceBridge = {
103
+ * async resolve(sourceId, sourceModel, ctx) { ... },
104
+ * async resolveMany(refs, ctx) {
105
+ * // Group by sourceModel, batch fetch, return Map<sourceId, doc>
106
+ * const result = new Map();
107
+ * const byModel = groupBy(refs, r => r.sourceModel);
108
+ * for (const [model, batch] of byModel) {
109
+ * const ids = batch.map(b => b.sourceId);
110
+ * const docs = await mongoose.connection.models[model].find({ _id: { $in: ids } }).lean();
111
+ * docs.forEach(d => result.set(String(d._id), d));
112
+ * }
113
+ * return result;
114
+ * },
115
+ * };
116
+ * ```
117
+ */
118
+ interface SourceBridge {
119
+ /**
120
+ * Resolve a single source document by sourceId + sourceModel.
121
+ * Returns null if not found or if the bridge can't handle this sourceModel.
122
+ */
123
+ resolve?(sourceId: string, sourceModel: string, ctx: RevenueContext): Promise<unknown | null>;
124
+ /**
125
+ * Optional batch resolver for performance (avoids N+1 in list endpoints).
126
+ * Returns a Map keyed by sourceId.
127
+ */
128
+ resolveMany?(refs: Array<{
129
+ sourceId: string;
130
+ sourceModel: string;
131
+ }>, ctx: RevenueContext): Promise<Map<string, unknown>>;
132
+ }
133
+ //#endregion
134
+ //#region src/bridges/revenue-bridges.d.ts
135
+ interface RevenueBridges {
136
+ ledger?: LedgerBridge | undefined;
137
+ tax?: TaxBridge | undefined;
138
+ notification?: NotificationBridge | undefined;
139
+ currency?: CurrencyBridge | undefined;
140
+ customer?: CustomerBridge | undefined;
141
+ analytics?: AnalyticsBridge | undefined;
142
+ source?: SourceBridge | undefined;
143
+ }
144
+ //#endregion
145
+ export { CurrencyBridge as a, LedgerBridge as c, CustomerBridge as i, SourceBridge as n, NotificationBridge as o, AnalyticsBridge as r, TaxBridge as s, RevenueBridges as t };