@classytic/revenue 1.0.6 → 1.1.3

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 (81) hide show
  1. package/README.md +582 -633
  2. package/dist/application/services/index.d.mts +4 -0
  3. package/dist/application/services/index.mjs +3 -0
  4. package/dist/base-CsTlVQJe.d.mts +136 -0
  5. package/dist/base-DCoyIUj6.mjs +152 -0
  6. package/dist/category-resolver-DV83N8ok.mjs +284 -0
  7. package/dist/commission-split-BzB8cd39.mjs +485 -0
  8. package/dist/core/events.d.mts +294 -0
  9. package/dist/core/events.mjs +100 -0
  10. package/dist/core/index.d.mts +9 -0
  11. package/dist/core/index.mjs +8 -0
  12. package/dist/enums/index.d.mts +157 -0
  13. package/dist/enums/index.mjs +56 -0
  14. package/dist/errors-CorrWz7A.d.mts +787 -0
  15. package/dist/escrow.enums-CZGrrdg7.mjs +101 -0
  16. package/dist/escrow.enums-DwdLuuve.d.mts +78 -0
  17. package/dist/idempotency-DaYcUGY1.mjs +172 -0
  18. package/dist/index-Dsp7H5Wb.d.mts +471 -0
  19. package/dist/index.d.mts +9 -0
  20. package/dist/index.mjs +38 -0
  21. package/dist/infrastructure/plugins/index.d.mts +239 -0
  22. package/dist/infrastructure/plugins/index.mjs +345 -0
  23. package/dist/money-CvrDOijQ.mjs +271 -0
  24. package/dist/money-DPG8AtJ8.d.mts +112 -0
  25. package/dist/payment.enums-HAuAS9Pp.d.mts +70 -0
  26. package/dist/payment.enums-tEFVa-Xp.mjs +69 -0
  27. package/dist/plugin-BbK0OVHy.d.mts +327 -0
  28. package/dist/plugin-Cd_V04Em.mjs +210 -0
  29. package/dist/providers/index.d.mts +3 -0
  30. package/dist/providers/index.mjs +3 -0
  31. package/dist/reconciliation/index.d.mts +193 -0
  32. package/dist/reconciliation/index.mjs +192 -0
  33. package/dist/retry-HHCOXYdn.d.mts +186 -0
  34. package/dist/revenue-9scqKSef.mjs +553 -0
  35. package/dist/schemas/index.d.mts +2665 -0
  36. package/dist/schemas/index.mjs +717 -0
  37. package/dist/schemas/validation.d.mts +375 -0
  38. package/dist/schemas/validation.mjs +325 -0
  39. package/dist/settlement.enums-DFhkqZEY.d.mts +132 -0
  40. package/dist/settlement.schema-D5uWB5tP.d.mts +344 -0
  41. package/dist/settlement.service-BxuiHpNC.d.mts +594 -0
  42. package/dist/settlement.service-CUxbUTzT.mjs +2510 -0
  43. package/dist/split.enums-BrjabxIX.mjs +86 -0
  44. package/dist/split.enums-DmskfLOM.d.mts +43 -0
  45. package/dist/tax-BoCt5cEd.d.mts +61 -0
  46. package/dist/tax-EQ15DO81.mjs +162 -0
  47. package/dist/transaction.enums-pCyMFT4Z.mjs +96 -0
  48. package/dist/utils/index.d.mts +428 -0
  49. package/dist/utils/index.mjs +346 -0
  50. package/package.json +48 -33
  51. package/dist/actions-Ctf2XUL-.d.ts +0 -519
  52. package/dist/core/index.d.ts +0 -890
  53. package/dist/core/index.js +0 -3005
  54. package/dist/core/index.js.map +0 -1
  55. package/dist/enums/index.d.ts +0 -138
  56. package/dist/enums/index.js +0 -263
  57. package/dist/enums/index.js.map +0 -1
  58. package/dist/index-BnEXsnLJ.d.ts +0 -378
  59. package/dist/index-C5SsOrV0.d.ts +0 -534
  60. package/dist/index.d.ts +0 -43
  61. package/dist/index.js +0 -4498
  62. package/dist/index.js.map +0 -1
  63. package/dist/payment.enums-B_RwB8iR.d.ts +0 -184
  64. package/dist/providers/index.d.ts +0 -132
  65. package/dist/providers/index.js +0 -122
  66. package/dist/providers/index.js.map +0 -1
  67. package/dist/retry-80lBCmSe.d.ts +0 -234
  68. package/dist/schemas/index.d.ts +0 -1051
  69. package/dist/schemas/index.js +0 -627
  70. package/dist/schemas/index.js.map +0 -1
  71. package/dist/schemas/validation.d.ts +0 -384
  72. package/dist/schemas/validation.js +0 -302
  73. package/dist/schemas/validation.js.map +0 -1
  74. package/dist/services/index.d.ts +0 -3
  75. package/dist/services/index.js +0 -1702
  76. package/dist/services/index.js.map +0 -1
  77. package/dist/split.schema-DLVF3XBI.d.ts +0 -1122
  78. package/dist/transaction.enums-7uBnuswI.d.ts +0 -87
  79. package/dist/utils/index.d.ts +0 -24
  80. package/dist/utils/index.js +0 -1140
  81. package/dist/utils/index.js.map +0 -1
@@ -1,184 +0,0 @@
1
- /**
2
- * Split Payment Enums
3
- * @classytic/revenue
4
- *
5
- * Enums for multi-party commission splits
6
- */
7
- declare const SPLIT_TYPE: {
8
- readonly PLATFORM_COMMISSION: "platform_commission";
9
- readonly AFFILIATE_COMMISSION: "affiliate_commission";
10
- readonly REFERRAL_COMMISSION: "referral_commission";
11
- readonly PARTNER_COMMISSION: "partner_commission";
12
- readonly CUSTOM: "custom";
13
- };
14
- type SplitType = typeof SPLIT_TYPE;
15
- type SplitTypeValue = SplitType[keyof SplitType];
16
- declare const SPLIT_TYPE_VALUES: SplitTypeValue[];
17
- declare const SPLIT_STATUS: {
18
- readonly PENDING: "pending";
19
- readonly DUE: "due";
20
- readonly PAID: "paid";
21
- readonly WAIVED: "waived";
22
- readonly CANCELLED: "cancelled";
23
- };
24
- type SplitStatus = typeof SPLIT_STATUS;
25
- type SplitStatusValue = SplitStatus[keyof SplitStatus];
26
- declare const SPLIT_STATUS_VALUES: SplitStatusValue[];
27
- declare const PAYOUT_METHOD: {
28
- readonly BANK_TRANSFER: "bank_transfer";
29
- readonly MOBILE_WALLET: "mobile_wallet";
30
- readonly PLATFORM_BALANCE: "platform_balance";
31
- readonly CRYPTO: "crypto";
32
- readonly CHECK: "check";
33
- readonly MANUAL: "manual";
34
- };
35
- type PayoutMethod = typeof PAYOUT_METHOD;
36
- type PayoutMethodValue = PayoutMethod[keyof PayoutMethod];
37
- declare const PAYOUT_METHOD_VALUES: PayoutMethodValue[];
38
- declare function isSplitType(value: unknown): value is SplitTypeValue;
39
- declare function isSplitStatus(value: unknown): value is SplitStatusValue;
40
- declare function isPayoutMethod(value: unknown): value is PayoutMethodValue;
41
-
42
- /**
43
- * Escrow/Hold Enums
44
- * @classytic/revenue
45
- *
46
- * Enums for platform-as-intermediary payment flow
47
- */
48
- declare const HOLD_STATUS: {
49
- readonly PENDING: "pending";
50
- readonly HELD: "held";
51
- readonly RELEASED: "released";
52
- readonly CANCELLED: "cancelled";
53
- readonly EXPIRED: "expired";
54
- readonly PARTIALLY_RELEASED: "partially_released";
55
- };
56
- type HoldStatus = typeof HOLD_STATUS;
57
- type HoldStatusValue = HoldStatus[keyof HoldStatus];
58
- declare const HOLD_STATUS_VALUES: HoldStatusValue[];
59
- declare const RELEASE_REASON: {
60
- readonly PAYMENT_VERIFIED: "payment_verified";
61
- readonly MANUAL_RELEASE: "manual_release";
62
- readonly AUTO_RELEASE: "auto_release";
63
- readonly DISPUTE_RESOLVED: "dispute_resolved";
64
- };
65
- type ReleaseReason = typeof RELEASE_REASON;
66
- type ReleaseReasonValue = ReleaseReason[keyof ReleaseReason];
67
- declare const RELEASE_REASON_VALUES: ReleaseReasonValue[];
68
- declare const HOLD_REASON: {
69
- readonly PAYMENT_VERIFICATION: "payment_verification";
70
- readonly FRAUD_CHECK: "fraud_check";
71
- readonly MANUAL_REVIEW: "manual_review";
72
- readonly DISPUTE: "dispute";
73
- readonly COMPLIANCE: "compliance";
74
- };
75
- type HoldReason = typeof HOLD_REASON;
76
- type HoldReasonValue = HoldReason[keyof HoldReason];
77
- declare const HOLD_REASON_VALUES: HoldReasonValue[];
78
- declare function isHoldStatus(value: unknown): value is HoldStatusValue;
79
- declare function isReleaseReason(value: unknown): value is ReleaseReasonValue;
80
- declare function isHoldReason(value: unknown): value is HoldReasonValue;
81
-
82
- /**
83
- * Subscription Enums
84
- * @classytic/revenue
85
- *
86
- * All subscription-related enums and constants
87
- */
88
- /**
89
- * Subscription Status
90
- */
91
- declare const SUBSCRIPTION_STATUS: {
92
- readonly ACTIVE: "active";
93
- readonly PAUSED: "paused";
94
- readonly CANCELLED: "cancelled";
95
- readonly EXPIRED: "expired";
96
- readonly PENDING: "pending";
97
- readonly INACTIVE: "inactive";
98
- };
99
- type SubscriptionStatus = typeof SUBSCRIPTION_STATUS;
100
- type SubscriptionStatusValue = SubscriptionStatus[keyof SubscriptionStatus];
101
- declare const SUBSCRIPTION_STATUS_VALUES: SubscriptionStatusValue[];
102
- /**
103
- * Supported plan intervals
104
- */
105
- declare const PLAN_KEYS: {
106
- readonly MONTHLY: "monthly";
107
- readonly QUARTERLY: "quarterly";
108
- readonly YEARLY: "yearly";
109
- };
110
- type PlanKeys = typeof PLAN_KEYS;
111
- type PlanKeyValue = PlanKeys[keyof PlanKeys];
112
- declare const PLAN_KEY_VALUES: PlanKeyValue[];
113
- declare function isSubscriptionStatus(value: unknown): value is SubscriptionStatusValue;
114
- declare function isPlanKey(value: unknown): value is PlanKeyValue;
115
-
116
- /**
117
- * Payment Enums
118
- * @classytic/revenue
119
- *
120
- * Library-managed payment enums only.
121
- * Users define their own payment methods in their schema.
122
- */
123
- /**
124
- * Payment Status - Library-managed states
125
- */
126
- declare const PAYMENT_STATUS: {
127
- readonly PENDING: "pending";
128
- readonly VERIFIED: "verified";
129
- readonly FAILED: "failed";
130
- readonly REFUNDED: "refunded";
131
- readonly CANCELLED: "cancelled";
132
- };
133
- type PaymentStatus = typeof PAYMENT_STATUS;
134
- type PaymentStatusValue = PaymentStatus[keyof PaymentStatus];
135
- declare const PAYMENT_STATUS_VALUES: PaymentStatusValue[];
136
- /**
137
- * Common gateway type constants for convenience
138
- *
139
- * ⚠️ IMPORTANT: These are NOT restrictions - just common reference values
140
- *
141
- * You can register ANY custom gateway provider by passing it to createRevenue():
142
- *
143
- * @example
144
- * ```typescript
145
- * const revenue = createRevenue({
146
- * providers: {
147
- * manual: new ManualProvider(),
148
- * bkash: new BkashProvider(), // ✅ Custom gateway
149
- * nagad: new NagadProvider(), // ✅ Custom gateway
150
- * stripe: new StripeProvider(), // ✅ Custom gateway
151
- * paypal: new PaypalProvider(), // ✅ Any gateway you want
152
- * }
153
- * });
154
- *
155
- * // Use by name
156
- * await revenue.monetization.create({ gateway: 'bkash', ... });
157
- * ```
158
- *
159
- * Reference values:
160
- * - MANUAL: Built-in manual provider (@classytic/revenue-manual)
161
- * - STRIPE: Stripe provider (build with @classytic/revenue-stripe)
162
- * - SSLCOMMERZ: SSLCommerz provider (build with @classytic/revenue-sslcommerz)
163
- *
164
- * Add your own: bkash, nagad, rocket, paypal, razorpay, flutterwave, etc.
165
- */
166
- declare const PAYMENT_GATEWAY_TYPE: {
167
- readonly MANUAL: "manual";
168
- readonly STRIPE: "stripe";
169
- readonly SSLCOMMERZ: "sslcommerz";
170
- };
171
- type PaymentGatewayType = typeof PAYMENT_GATEWAY_TYPE;
172
- type PaymentGatewayTypeValue = PaymentGatewayType[keyof PaymentGatewayType];
173
- declare const PAYMENT_GATEWAY_TYPE_VALUES: PaymentGatewayTypeValue[];
174
- declare const GATEWAY_TYPES: {
175
- readonly MANUAL: "manual";
176
- readonly STRIPE: "stripe";
177
- readonly SSLCOMMERZ: "sslcommerz";
178
- };
179
- declare const GATEWAY_TYPE_VALUES: PaymentGatewayTypeValue[];
180
- declare function isPaymentStatus(value: unknown): value is PaymentStatusValue;
181
- declare function isPaymentGatewayType(value: unknown): value is PaymentGatewayTypeValue;
182
- declare const isGatewayType: typeof isPaymentGatewayType;
183
-
184
- export { SPLIT_TYPE_VALUES as A, SPLIT_STATUS as B, type SplitStatus as C, SPLIT_STATUS_VALUES as D, PAYOUT_METHOD as E, type PayoutMethod as F, GATEWAY_TYPES as G, HOLD_STATUS as H, PAYOUT_METHOD_VALUES as I, isSplitType as J, isSplitStatus as K, isPayoutMethod as L, type PaymentStatusValue as M, type PaymentGatewayTypeValue as N, type SubscriptionStatusValue as O, PAYMENT_STATUS as P, type PlanKeyValue as Q, RELEASE_REASON as R, SUBSCRIPTION_STATUS as S, type HoldStatusValue as T, type ReleaseReasonValue as U, type HoldReasonValue as V, type SplitTypeValue as W, type SplitStatusValue as X, type PayoutMethodValue as Y, type SubscriptionStatus as Z, type HoldStatus as _, type PaymentStatus as a, PAYMENT_STATUS_VALUES as b, PAYMENT_GATEWAY_TYPE as c, type PaymentGatewayType as d, PAYMENT_GATEWAY_TYPE_VALUES as e, GATEWAY_TYPE_VALUES as f, isPaymentGatewayType as g, isGatewayType as h, isPaymentStatus as i, SUBSCRIPTION_STATUS_VALUES as j, PLAN_KEYS as k, type PlanKeys as l, PLAN_KEY_VALUES as m, isSubscriptionStatus as n, isPlanKey as o, HOLD_STATUS_VALUES as p, type ReleaseReason as q, RELEASE_REASON_VALUES as r, HOLD_REASON as s, type HoldReason as t, HOLD_REASON_VALUES as u, isHoldStatus as v, isReleaseReason as w, isHoldReason as x, SPLIT_TYPE as y, type SplitType as z };
@@ -1,132 +0,0 @@
1
- import { s as CreateIntentParams, t as PaymentIntentData, u as PaymentResultData, v as RefundResultData, w as WebhookEventData, x as ProviderCapabilities } from '../index-C5SsOrV0.js';
2
- import 'mongoose';
3
-
4
- /**
5
- * Payment Provider Base Class
6
- * @classytic/revenue
7
- *
8
- * Abstract base class for all payment providers
9
- * Inspired by: Vercel AI SDK, Stripe SDK
10
- */
11
-
12
- /**
13
- * Payment Intent - standardized response from createIntent
14
- */
15
- declare class PaymentIntent implements PaymentIntentData {
16
- readonly id: string;
17
- readonly sessionId: string | null;
18
- readonly paymentIntentId: string | null;
19
- readonly provider: string;
20
- readonly status: string;
21
- readonly amount: number;
22
- readonly currency: string;
23
- readonly metadata: Record<string, unknown>;
24
- readonly clientSecret?: string;
25
- readonly paymentUrl?: string;
26
- readonly instructions?: string;
27
- readonly raw?: unknown;
28
- constructor(data: PaymentIntentData);
29
- }
30
- /**
31
- * Payment Result - standardized response from verifyPayment
32
- */
33
- declare class PaymentResult implements PaymentResultData {
34
- readonly id: string;
35
- readonly provider: string;
36
- readonly status: 'succeeded' | 'failed' | 'processing';
37
- readonly amount?: number;
38
- readonly currency: string;
39
- readonly paidAt?: Date;
40
- readonly metadata: Record<string, unknown>;
41
- readonly raw?: unknown;
42
- constructor(data: PaymentResultData);
43
- }
44
- /**
45
- * Refund Result - standardized response from refund
46
- */
47
- declare class RefundResult implements RefundResultData {
48
- readonly id: string;
49
- readonly provider: string;
50
- readonly status: 'succeeded' | 'failed' | 'processing';
51
- readonly amount?: number;
52
- readonly currency: string;
53
- readonly refundedAt?: Date;
54
- readonly reason?: string;
55
- readonly metadata: Record<string, unknown>;
56
- readonly raw?: unknown;
57
- constructor(data: RefundResultData);
58
- }
59
- /**
60
- * Webhook Event - standardized webhook event
61
- */
62
- declare class WebhookEvent implements WebhookEventData {
63
- readonly id: string;
64
- readonly provider: string;
65
- readonly type: string;
66
- readonly data: {
67
- sessionId?: string;
68
- paymentIntentId?: string;
69
- [key: string]: unknown;
70
- };
71
- readonly createdAt?: Date;
72
- readonly raw?: unknown;
73
- constructor(data: WebhookEventData);
74
- }
75
- /**
76
- * Base Payment Provider
77
- * All payment providers must extend this class
78
- */
79
- declare abstract class PaymentProvider {
80
- readonly config: Record<string, unknown>;
81
- readonly name: string;
82
- constructor(config?: Record<string, unknown>);
83
- /**
84
- * Create a payment intent
85
- * @param params - Payment parameters
86
- * @returns Promise<PaymentIntent>
87
- */
88
- abstract createIntent(params: CreateIntentParams): Promise<PaymentIntent>;
89
- /**
90
- * Verify a payment
91
- * @param intentId - Payment intent ID
92
- * @returns Promise<PaymentResult>
93
- */
94
- abstract verifyPayment(intentId: string): Promise<PaymentResult>;
95
- /**
96
- * Get payment status
97
- * @param intentId - Payment intent ID
98
- * @returns Promise<PaymentResult>
99
- */
100
- abstract getStatus(intentId: string): Promise<PaymentResult>;
101
- /**
102
- * Refund a payment
103
- * @param paymentId - Payment ID
104
- * @param amount - Amount to refund (optional, full refund if not provided)
105
- * @param options - Refund options
106
- * @returns Promise<RefundResult>
107
- */
108
- abstract refund(paymentId: string, amount?: number | null, options?: {
109
- reason?: string;
110
- }): Promise<RefundResult>;
111
- /**
112
- * Handle webhook from provider
113
- * @param payload - Webhook payload
114
- * @param headers - Request headers (for signature verification)
115
- * @returns Promise<WebhookEvent>
116
- */
117
- abstract handleWebhook(payload: unknown, headers?: Record<string, string>): Promise<WebhookEvent>;
118
- /**
119
- * Verify webhook signature (optional)
120
- * @param payload - Webhook payload
121
- * @param signature - Webhook signature
122
- * @returns boolean
123
- */
124
- verifyWebhookSignature(_payload: unknown, _signature: string): boolean;
125
- /**
126
- * Get provider capabilities
127
- * @returns ProviderCapabilities
128
- */
129
- getCapabilities(): ProviderCapabilities;
130
- }
131
-
132
- export { PaymentIntent, PaymentProvider, PaymentProvider as PaymentProviderDefault, PaymentResult, RefundResult, WebhookEvent };
@@ -1,122 +0,0 @@
1
- // @classytic/revenue - Enterprise Revenue Management System
2
-
3
- // src/providers/base.ts
4
- var PaymentIntent = class {
5
- id;
6
- sessionId;
7
- paymentIntentId;
8
- provider;
9
- status;
10
- amount;
11
- currency;
12
- metadata;
13
- clientSecret;
14
- paymentUrl;
15
- instructions;
16
- raw;
17
- constructor(data) {
18
- this.id = data.id;
19
- this.sessionId = data.sessionId ?? null;
20
- this.paymentIntentId = data.paymentIntentId ?? null;
21
- this.provider = data.provider;
22
- this.status = data.status;
23
- this.amount = data.amount;
24
- this.currency = data.currency ?? "BDT";
25
- this.metadata = data.metadata ?? {};
26
- this.clientSecret = data.clientSecret;
27
- this.paymentUrl = data.paymentUrl;
28
- this.instructions = data.instructions;
29
- this.raw = data.raw;
30
- }
31
- };
32
- var PaymentResult = class {
33
- id;
34
- provider;
35
- status;
36
- amount;
37
- currency;
38
- paidAt;
39
- metadata;
40
- raw;
41
- constructor(data) {
42
- this.id = data.id;
43
- this.provider = data.provider;
44
- this.status = data.status;
45
- this.amount = data.amount;
46
- this.currency = data.currency ?? "BDT";
47
- this.paidAt = data.paidAt;
48
- this.metadata = data.metadata ?? {};
49
- this.raw = data.raw;
50
- }
51
- };
52
- var RefundResult = class {
53
- id;
54
- provider;
55
- status;
56
- amount;
57
- currency;
58
- refundedAt;
59
- reason;
60
- metadata;
61
- raw;
62
- constructor(data) {
63
- this.id = data.id;
64
- this.provider = data.provider;
65
- this.status = data.status;
66
- this.amount = data.amount;
67
- this.currency = data.currency ?? "BDT";
68
- this.refundedAt = data.refundedAt;
69
- this.reason = data.reason;
70
- this.metadata = data.metadata ?? {};
71
- this.raw = data.raw;
72
- }
73
- };
74
- var WebhookEvent = class {
75
- id;
76
- provider;
77
- type;
78
- data;
79
- createdAt;
80
- raw;
81
- constructor(data) {
82
- this.id = data.id;
83
- this.provider = data.provider;
84
- this.type = data.type;
85
- this.data = data.data;
86
- this.createdAt = data.createdAt;
87
- this.raw = data.raw;
88
- }
89
- };
90
- var PaymentProvider = class {
91
- config;
92
- name;
93
- constructor(config = {}) {
94
- this.config = config;
95
- this.name = "base";
96
- }
97
- /**
98
- * Verify webhook signature (optional)
99
- * @param payload - Webhook payload
100
- * @param signature - Webhook signature
101
- * @returns boolean
102
- */
103
- verifyWebhookSignature(_payload, _signature) {
104
- return true;
105
- }
106
- /**
107
- * Get provider capabilities
108
- * @returns ProviderCapabilities
109
- */
110
- getCapabilities() {
111
- return {
112
- supportsWebhooks: false,
113
- supportsRefunds: false,
114
- supportsPartialRefunds: false,
115
- requiresManualVerification: true
116
- };
117
- }
118
- };
119
-
120
- export { PaymentIntent, PaymentProvider, PaymentResult, RefundResult, WebhookEvent };
121
- //# sourceMappingURL=index.js.map
122
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/providers/base.ts"],"names":[],"mappings":";;;AAoBO,IAAM,gBAAN,MAAiD;AAAA,EACtC,EAAA;AAAA,EACA,SAAA;AAAA,EACA,eAAA;AAAA,EACA,QAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,YAAA;AAAA,EACA,UAAA;AAAA,EACA,YAAA;AAAA,EACA,GAAA;AAAA,EAEhB,YAAY,IAAA,EAAyB;AACnC,IAAA,IAAA,CAAK,KAAK,IAAA,CAAK,EAAA;AACf,IAAA,IAAA,CAAK,SAAA,GAAY,K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IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,IAAA,GAAO,MAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqDA,sBAAA,CAAuB,UAAmB,UAAA,EAA6B;AAErE,IAAA,OAAO,IAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,eAAA,GAAwC;AACtC,IAAA,OAAO;AAAA,MACL,gBAAA,EAAkB,KAAA;AAAA,MAClB,eAAA,EAAiB,KAAA;AAAA,MACjB,sBAAA,EAAwB,KAAA;AAAA,MACxB,0BAAA,EAA4B;AAAA,KAC9B;AAAA,EACF;AACF","file":"index.js","sourcesContent":["/**\n * Payment Provider Base Class\n * @classytic/revenue\n *\n * Abstract base class for all payment providers\n * Inspired by: Vercel AI SDK, Stripe SDK\n */\n\nimport type {\n CreateIntentParams,\n PaymentIntentData,\n PaymentResultData,\n RefundResultData,\n WebhookEventData,\n ProviderCapabilities,\n} from '../types/index.js';\n\n/**\n * Payment Intent - standardized response from createIntent\n */\nexport class PaymentIntent implements PaymentIntentData {\n public readonly id: string;\n public readonly sessionId: string | null;\n public readonly paymentIntentId: string | null;\n public readonly provider: string;\n public readonly status: string;\n public readonly amount: number;\n public readonly currency: string;\n public readonly metadata: Record<string, unknown>;\n public readonly clientSecret?: string;\n public readonly paymentUrl?: string;\n public readonly instructions?: string;\n public readonly raw?: unknown;\n\n constructor(data: PaymentIntentData) {\n this.id = data.id;\n this.sessionId = data.sessionId ?? null;\n this.paymentIntentId = data.paymentIntentId ?? null;\n this.provider = data.provider;\n this.status = data.status;\n this.amount = data.amount;\n this.currency = data.currency ?? 'BDT';\n this.metadata = data.metadata ?? {};\n this.clientSecret = data.clientSecret;\n this.paymentUrl = data.paymentUrl;\n this.instructions = data.instructions;\n this.raw = data.raw;\n }\n}\n\n/**\n * Payment Result - standardized response from verifyPayment\n */\nexport class PaymentResult implements PaymentResultData {\n public readonly id: string;\n public readonly provider: string;\n public readonly status: 'succeeded' | 'failed' | 'processing';\n public readonly amount?: number;\n public readonly currency: string;\n public readonly paidAt?: Date;\n public readonly metadata: Record<string, unknown>;\n public readonly raw?: unknown;\n\n constructor(data: PaymentResultData) {\n this.id = data.id;\n this.provider = data.provider;\n this.status = data.status;\n this.amount = data.amount;\n this.currency = data.currency ?? 'BDT';\n this.paidAt = data.paidAt;\n this.metadata = data.metadata ?? {};\n this.raw = data.raw;\n }\n}\n\n/**\n * Refund Result - standardized response from refund\n */\nexport class RefundResult implements RefundResultData {\n public readonly id: string;\n public readonly provider: string;\n public readonly status: 'succeeded' | 'failed' | 'processing';\n public readonly amount?: number;\n public readonly currency: string;\n public readonly refundedAt?: Date;\n public readonly reason?: string;\n public readonly metadata: Record<string, unknown>;\n public readonly raw?: unknown;\n\n constructor(data: RefundResultData) {\n this.id = data.id;\n this.provider = data.provider;\n this.status = data.status;\n this.amount = data.amount;\n this.currency = data.currency ?? 'BDT';\n this.refundedAt = data.refundedAt;\n this.reason = data.reason;\n this.metadata = data.metadata ?? {};\n this.raw = data.raw;\n }\n}\n\n/**\n * Webhook Event - standardized webhook event\n */\nexport class WebhookEvent implements WebhookEventData {\n public readonly id: string;\n public readonly provider: string;\n public readonly type: string;\n public readonly data: { sessionId?: string; paymentIntentId?: string; [key: string]: unknown };\n public readonly createdAt?: Date;\n public readonly raw?: unknown;\n\n constructor(data: WebhookEventData) {\n this.id = data.id;\n this.provider = data.provider;\n this.type = data.type;\n this.data = data.data;\n this.createdAt = data.createdAt;\n this.raw = data.raw;\n }\n}\n\n/**\n * Base Payment Provider\n * All payment providers must extend this class\n */\nexport abstract class PaymentProvider {\n public readonly config: Record<string, unknown>;\n public readonly name: string;\n\n constructor(config: Record<string, unknown> = {}) {\n this.config = config;\n this.name = 'base'; // Override in subclass\n }\n\n /**\n * Create a payment intent\n * @param params - Payment parameters\n * @returns Promise<PaymentIntent>\n */\n abstract createIntent(params: CreateIntentParams): Promise<PaymentIntent>;\n\n /**\n * Verify a payment\n * @param intentId - Payment intent ID\n * @returns Promise<PaymentResult>\n */\n abstract verifyPayment(intentId: string): Promise<PaymentResult>;\n\n /**\n * Get payment status\n * @param intentId - Payment intent ID\n * @returns Promise<PaymentResult>\n */\n abstract getStatus(intentId: string): Promise<PaymentResult>;\n\n /**\n * Refund a payment\n * @param paymentId - Payment ID\n * @param amount - Amount to refund (optional, full refund if not provided)\n * @param options - Refund options\n * @returns Promise<RefundResult>\n */\n abstract refund(\n paymentId: string,\n amount?: number | null,\n options?: { reason?: string }\n ): Promise<RefundResult>;\n\n /**\n * Handle webhook from provider\n * @param payload - Webhook payload\n * @param headers - Request headers (for signature verification)\n * @returns Promise<WebhookEvent>\n */\n abstract handleWebhook(\n payload: unknown,\n headers?: Record<string, string>\n ): Promise<WebhookEvent>;\n\n /**\n * Verify webhook signature (optional)\n * @param payload - Webhook payload\n * @param signature - Webhook signature\n * @returns boolean\n */\n verifyWebhookSignature(_payload: unknown, _signature: string): boolean {\n // Override in subclass if provider supports webhook signatures\n return true;\n }\n\n /**\n * Get provider capabilities\n * @returns ProviderCapabilities\n */\n getCapabilities(): ProviderCapabilities {\n return {\n supportsWebhooks: false,\n supportsRefunds: false,\n supportsPartialRefunds: false,\n requiresManualVerification: true,\n };\n }\n}\n\nexport default PaymentProvider;\n\n"]}
@@ -1,234 +0,0 @@
1
- /**
2
- * Result Type - Rust-inspired error handling
3
- * @classytic/revenue
4
- *
5
- * No more try/catch - explicit, type-safe error handling
6
- * Inspired by: Rust Result<T, E>, neverthrow, Effect-TS
7
- */
8
- /**
9
- * Success result
10
- */
11
- interface Ok<T> {
12
- readonly ok: true;
13
- readonly value: T;
14
- readonly error?: never;
15
- }
16
- /**
17
- * Error result
18
- */
19
- interface Err<E> {
20
- readonly ok: false;
21
- readonly error: E;
22
- readonly value?: never;
23
- }
24
- /**
25
- * Create a success result
26
- */
27
- declare function ok<T>(value: T): Ok<T>;
28
- /**
29
- * Create an error result
30
- */
31
- declare function err<E>(error: E): Err<E>;
32
- /**
33
- * Check if result is Ok
34
- */
35
- declare function isOk<T, E>(result: Result<T, E>): result is Ok<T>;
36
- /**
37
- * Check if result is Err
38
- */
39
- declare function isErr<T, E>(result: Result<T, E>): result is Err<E>;
40
- /**
41
- * Unwrap a result, throwing if it's an error
42
- * Use sparingly - prefer pattern matching
43
- */
44
- declare function unwrap<T, E>(result: Result<T, E>): T;
45
- /**
46
- * Unwrap a result with a default value
47
- */
48
- declare function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T;
49
- /**
50
- * Map over a successful result
51
- */
52
- declare function map<T, U, E>(result: Result<T, E>, fn: (value: T) => U): Result<U, E>;
53
- /**
54
- * Map over an error result
55
- */
56
- declare function mapErr<T, E, F>(result: Result<T, E>, fn: (error: E) => F): Result<T, F>;
57
- /**
58
- * Flat map (chain) results
59
- */
60
- declare function flatMap<T, U, E>(result: Result<T, E>, fn: (value: T) => Result<U, E>): Result<U, E>;
61
- /**
62
- * Try-catch wrapper that returns Result
63
- */
64
- declare function tryCatch<T, E = Error>(fn: () => Promise<T>, mapError?: (e: unknown) => E): Promise<Result<T, E>>;
65
- /**
66
- * Synchronous try-catch wrapper
67
- */
68
- declare function tryCatchSync<T, E = Error>(fn: () => T, mapError?: (e: unknown) => E): Result<T, E>;
69
- /**
70
- * Combine multiple results - all must succeed
71
- */
72
- declare function all<T extends readonly Result<unknown, unknown>[]>(results: T): Result<{
73
- [K in keyof T]: T[K] extends Result<infer U, unknown> ? U : never;
74
- }, T[number] extends Result<unknown, infer E> ? E : never>;
75
- /**
76
- * Pattern match on result
77
- */
78
- declare function match<T, E, U>(result: Result<T, E>, handlers: {
79
- ok: (value: T) => U;
80
- err: (error: E) => U;
81
- }): U;
82
- /**
83
- * Result type - either Ok<T> or Err<E>
84
- */
85
- type Result<T, E = Error> = Ok<T> | Err<E>;
86
- declare const Result: {
87
- readonly ok: typeof ok;
88
- readonly err: typeof err;
89
- readonly isOk: typeof isOk;
90
- readonly isErr: typeof isErr;
91
- readonly unwrap: typeof unwrap;
92
- readonly unwrapOr: typeof unwrapOr;
93
- readonly map: typeof map;
94
- readonly mapErr: typeof mapErr;
95
- readonly flatMap: typeof flatMap;
96
- readonly tryCatch: typeof tryCatch;
97
- readonly tryCatchSync: typeof tryCatchSync;
98
- readonly all: typeof all;
99
- readonly match: typeof match;
100
- };
101
-
102
- /**
103
- * Retry Utilities
104
- * @classytic/revenue
105
- *
106
- * Exponential backoff with jitter for resilient operations
107
- * Inspired by: AWS SDK retry, Netflix Hystrix, resilience4j
108
- */
109
-
110
- interface RetryConfig {
111
- /** Maximum number of retry attempts (default: 3) */
112
- maxAttempts: number;
113
- /** Base delay in milliseconds (default: 1000) */
114
- baseDelay: number;
115
- /** Maximum delay in milliseconds (default: 30000) */
116
- maxDelay: number;
117
- /** Backoff multiplier (default: 2) */
118
- backoffMultiplier: number;
119
- /** Jitter factor 0-1 (default: 0.1) */
120
- jitter: number;
121
- /** Which errors are retryable */
122
- retryIf?: (error: unknown) => boolean;
123
- /** Callback on each retry */
124
- onRetry?: (error: unknown, attempt: number, delay: number) => void;
125
- }
126
- interface RetryState {
127
- attempt: number;
128
- totalDelay: number;
129
- errors: Error[];
130
- }
131
- /**
132
- * Calculate delay with exponential backoff and jitter
133
- */
134
- declare function calculateDelay(attempt: number, config: RetryConfig): number;
135
- /**
136
- * Check if error is retryable by default
137
- */
138
- declare function isRetryableError(error: unknown): boolean;
139
- /**
140
- * Execute operation with retry logic
141
- */
142
- declare function retry<T>(operation: () => Promise<T>, config?: Partial<RetryConfig>): Promise<T>;
143
- /**
144
- * Execute operation with retry, returning Result instead of throwing
145
- */
146
- declare function retryWithResult<T>(operation: () => Promise<T>, config?: Partial<RetryConfig>): Promise<Result<T, RetryExhaustedError>>;
147
- /**
148
- * Error thrown when all retries are exhausted
149
- */
150
- declare class RetryExhaustedError extends Error {
151
- readonly attempts: number;
152
- readonly errors: Error[];
153
- constructor(message: string, errors: Error[]);
154
- /**
155
- * Get the last error
156
- */
157
- get lastError(): Error | undefined;
158
- /**
159
- * Get the first error
160
- */
161
- get firstError(): Error | undefined;
162
- }
163
- type CircuitState = 'closed' | 'open' | 'half-open';
164
- interface CircuitBreakerConfig {
165
- /** Number of failures before opening circuit */
166
- failureThreshold: number;
167
- /** Time in ms to wait before half-opening */
168
- resetTimeout: number;
169
- /** Number of successes in half-open to close circuit */
170
- successThreshold: number;
171
- /** Monitor window in ms */
172
- monitorWindow: number;
173
- }
174
- /**
175
- * Circuit breaker for preventing cascade failures
176
- * Inspired by: Netflix Hystrix, resilience4j
177
- */
178
- declare class CircuitBreaker {
179
- private state;
180
- private failures;
181
- private successes;
182
- private lastFailure?;
183
- private config;
184
- constructor(config?: Partial<CircuitBreakerConfig>);
185
- /**
186
- * Execute operation through circuit breaker
187
- */
188
- execute<T>(operation: () => Promise<T>): Promise<T>;
189
- /**
190
- * Execute with Result type
191
- */
192
- executeWithResult<T>(operation: () => Promise<T>): Promise<Result<T, CircuitOpenError | Error>>;
193
- private onSuccess;
194
- private onFailure;
195
- private shouldAttemptReset;
196
- private cleanOldFailures;
197
- private reset;
198
- /**
199
- * Get current circuit state
200
- */
201
- getState(): CircuitState;
202
- /**
203
- * Manually reset circuit
204
- */
205
- forceReset(): void;
206
- /**
207
- * Get circuit statistics
208
- */
209
- getStats(): {
210
- state: CircuitState;
211
- failures: number;
212
- successes: number;
213
- lastFailure?: Date;
214
- };
215
- }
216
- /**
217
- * Error thrown when circuit is open
218
- */
219
- declare class CircuitOpenError extends Error {
220
- constructor(message: string);
221
- }
222
- /**
223
- * Create a circuit breaker
224
- */
225
- declare function createCircuitBreaker(config?: Partial<CircuitBreakerConfig>): CircuitBreaker;
226
- /**
227
- * Execute with both retry and circuit breaker
228
- */
229
- declare function resilientExecute<T>(operation: () => Promise<T>, options?: {
230
- retry?: Partial<RetryConfig>;
231
- circuitBreaker?: CircuitBreaker;
232
- }): Promise<T>;
233
-
234
- export { CircuitBreaker as C, type Err as E, type Ok as O, Result as R, isErr as a, unwrapOr as b, mapErr as c, tryCatchSync as d, err as e, flatMap as f, all as g, match as h, isOk as i, retryWithResult as j, calculateDelay as k, isRetryableError as l, map as m, RetryExhaustedError as n, ok as o, createCircuitBreaker as p, CircuitOpenError as q, retry as r, resilientExecute as s, tryCatch as t, unwrap as u, type CircuitState as v, type CircuitBreakerConfig as w, type RetryConfig as x, type RetryState as y };