@classytic/revenue 0.2.4 → 1.0.1

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 (111) hide show
  1. package/README.md +498 -501
  2. package/dist/actions-CwG-b7fR.d.ts +519 -0
  3. package/dist/core/index.d.ts +884 -0
  4. package/dist/core/index.js +2941 -0
  5. package/dist/core/index.js.map +1 -0
  6. package/dist/enums/index.d.ts +130 -0
  7. package/dist/enums/index.js +167 -0
  8. package/dist/enums/index.js.map +1 -0
  9. package/dist/index-BnJWVXuw.d.ts +378 -0
  10. package/dist/index-ChVD3P9k.d.ts +504 -0
  11. package/dist/index.d.ts +42 -0
  12. package/dist/index.js +4362 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/providers/index.d.ts +132 -0
  15. package/dist/providers/index.js +122 -0
  16. package/dist/providers/index.js.map +1 -0
  17. package/dist/retry-80lBCmSe.d.ts +234 -0
  18. package/dist/schemas/index.d.ts +906 -0
  19. package/dist/schemas/index.js +533 -0
  20. package/dist/schemas/index.js.map +1 -0
  21. package/dist/schemas/validation.d.ts +309 -0
  22. package/dist/schemas/validation.js +249 -0
  23. package/dist/schemas/validation.js.map +1 -0
  24. package/dist/services/index.d.ts +3 -0
  25. package/dist/services/index.js +1632 -0
  26. package/dist/services/index.js.map +1 -0
  27. package/dist/split.enums-DHdM1YAV.d.ts +255 -0
  28. package/dist/split.schema-CETjPq10.d.ts +976 -0
  29. package/dist/utils/index.d.ts +24 -0
  30. package/dist/utils/index.js +1067 -0
  31. package/dist/utils/index.js.map +1 -0
  32. package/package.json +48 -32
  33. package/core/builder.js +0 -219
  34. package/core/container.js +0 -119
  35. package/core/errors.js +0 -262
  36. package/dist/types/core/builder.d.ts +0 -97
  37. package/dist/types/core/container.d.ts +0 -57
  38. package/dist/types/core/errors.d.ts +0 -122
  39. package/dist/types/enums/escrow.enums.d.ts +0 -24
  40. package/dist/types/enums/index.d.ts +0 -69
  41. package/dist/types/enums/monetization.enums.d.ts +0 -6
  42. package/dist/types/enums/payment.enums.d.ts +0 -16
  43. package/dist/types/enums/split.enums.d.ts +0 -25
  44. package/dist/types/enums/subscription.enums.d.ts +0 -15
  45. package/dist/types/enums/transaction.enums.d.ts +0 -24
  46. package/dist/types/index.d.ts +0 -22
  47. package/dist/types/providers/base.d.ts +0 -128
  48. package/dist/types/schemas/escrow/hold.schema.d.ts +0 -54
  49. package/dist/types/schemas/escrow/index.d.ts +0 -6
  50. package/dist/types/schemas/index.d.ts +0 -506
  51. package/dist/types/schemas/split/index.d.ts +0 -8
  52. package/dist/types/schemas/split/split.schema.d.ts +0 -142
  53. package/dist/types/schemas/subscription/index.d.ts +0 -152
  54. package/dist/types/schemas/subscription/info.schema.d.ts +0 -128
  55. package/dist/types/schemas/subscription/plan.schema.d.ts +0 -39
  56. package/dist/types/schemas/transaction/common.schema.d.ts +0 -12
  57. package/dist/types/schemas/transaction/gateway.schema.d.ts +0 -86
  58. package/dist/types/schemas/transaction/index.d.ts +0 -202
  59. package/dist/types/schemas/transaction/payment.schema.d.ts +0 -145
  60. package/dist/types/services/escrow.service.d.ts +0 -51
  61. package/dist/types/services/monetization.service.d.ts +0 -193
  62. package/dist/types/services/payment.service.d.ts +0 -117
  63. package/dist/types/services/transaction.service.d.ts +0 -40
  64. package/dist/types/utils/category-resolver.d.ts +0 -46
  65. package/dist/types/utils/commission-split.d.ts +0 -56
  66. package/dist/types/utils/commission.d.ts +0 -29
  67. package/dist/types/utils/hooks.d.ts +0 -17
  68. package/dist/types/utils/index.d.ts +0 -6
  69. package/dist/types/utils/logger.d.ts +0 -12
  70. package/dist/types/utils/subscription/actions.d.ts +0 -28
  71. package/dist/types/utils/subscription/index.d.ts +0 -2
  72. package/dist/types/utils/subscription/period.d.ts +0 -47
  73. package/dist/types/utils/transaction-type.d.ts +0 -102
  74. package/enums/escrow.enums.js +0 -36
  75. package/enums/index.d.ts +0 -116
  76. package/enums/index.js +0 -110
  77. package/enums/monetization.enums.js +0 -15
  78. package/enums/payment.enums.js +0 -64
  79. package/enums/split.enums.js +0 -37
  80. package/enums/subscription.enums.js +0 -33
  81. package/enums/transaction.enums.js +0 -69
  82. package/index.js +0 -76
  83. package/providers/base.js +0 -162
  84. package/schemas/escrow/hold.schema.js +0 -62
  85. package/schemas/escrow/index.js +0 -15
  86. package/schemas/index.d.ts +0 -33
  87. package/schemas/index.js +0 -27
  88. package/schemas/split/index.js +0 -16
  89. package/schemas/split/split.schema.js +0 -86
  90. package/schemas/subscription/index.js +0 -17
  91. package/schemas/subscription/info.schema.js +0 -115
  92. package/schemas/subscription/plan.schema.js +0 -48
  93. package/schemas/transaction/common.schema.js +0 -22
  94. package/schemas/transaction/gateway.schema.js +0 -69
  95. package/schemas/transaction/index.js +0 -20
  96. package/schemas/transaction/payment.schema.js +0 -110
  97. package/services/escrow.service.js +0 -353
  98. package/services/monetization.service.js +0 -675
  99. package/services/payment.service.js +0 -535
  100. package/services/transaction.service.js +0 -142
  101. package/utils/category-resolver.js +0 -74
  102. package/utils/commission-split.js +0 -180
  103. package/utils/commission.js +0 -83
  104. package/utils/hooks.js +0 -44
  105. package/utils/index.d.ts +0 -164
  106. package/utils/index.js +0 -16
  107. package/utils/logger.js +0 -36
  108. package/utils/subscription/actions.js +0 -68
  109. package/utils/subscription/index.js +0 -20
  110. package/utils/subscription/period.js +0 -123
  111. package/utils/transaction-type.js +0 -254
@@ -0,0 +1,378 @@
1
+ import { E as MonetizationCreateParams, F as MonetizationCreateResult, G as ActivateOptions, e as SubscriptionDocument, I as RenewalParams, J as CancelOptions, K as PauseOptions, N as ResumeOptions, Q as ListOptions, U as PaymentVerifyOptions, V as PaymentVerifyResult, X as PaymentStatusResult, Y as RefundOptions, Z as PaymentRefundResult, _ as WebhookResult, d as TransactionDocument, w as PaymentProviderInterface, $ as TransactionListResult, a0 as HoldOptions, a1 as ReleaseOptions, a2 as ReleaseResult, a3 as CancelHoldOptions, o as SplitRule, a4 as SplitResult, a5 as EscrowStatusResult } from './index-ChVD3P9k.js';
2
+
3
+ /**
4
+ * Dependency Injection Container
5
+ * @classytic/revenue
6
+ *
7
+ * Lightweight DI container for managing dependencies
8
+ * Inspired by: Awilix, InversifyJS but much simpler
9
+ */
10
+ declare class Container {
11
+ private _services;
12
+ private _singletons;
13
+ constructor();
14
+ /**
15
+ * Register a service
16
+ * @param name - Service name
17
+ * @param implementation - Service implementation or factory
18
+ * @param options - Registration options
19
+ */
20
+ register<T>(name: string, implementation: T | ((container: Container) => T), options?: {
21
+ singleton?: boolean;
22
+ factory?: boolean;
23
+ }): this;
24
+ /**
25
+ * Register a singleton service
26
+ * @param name - Service name
27
+ * @param implementation - Service implementation
28
+ */
29
+ singleton<T>(name: string, implementation: T): this;
30
+ /**
31
+ * Register a transient service (new instance each time)
32
+ * @param name - Service name
33
+ * @param factory - Factory function
34
+ */
35
+ transient<T>(name: string, factory: (container: Container) => T): this;
36
+ /**
37
+ * Get a service from the container
38
+ * @param name - Service name
39
+ * @returns Service instance
40
+ */
41
+ get<T>(name: string): T;
42
+ /**
43
+ * Check if service is registered
44
+ * @param name - Service name
45
+ */
46
+ has(name: string): boolean;
47
+ /**
48
+ * Get all registered service names
49
+ */
50
+ keys(): string[];
51
+ /**
52
+ * Clear all services (useful for testing)
53
+ */
54
+ clear(): void;
55
+ /**
56
+ * Create a child container (for scoped dependencies)
57
+ */
58
+ createScope(): Container;
59
+ }
60
+
61
+ /**
62
+ * Monetization Service
63
+ * @classytic/revenue
64
+ *
65
+ * Framework-agnostic monetization management service with DI
66
+ * Handles purchases, subscriptions, and free items using provider system
67
+ */
68
+
69
+ /**
70
+ * Monetization Service
71
+ * Uses DI container for all dependencies
72
+ */
73
+ declare class MonetizationService {
74
+ private readonly models;
75
+ private readonly providers;
76
+ private readonly config;
77
+ private readonly hooks;
78
+ private readonly logger;
79
+ constructor(container: Container);
80
+ /**
81
+ * Create a new monetization (purchase, subscription, or free item)
82
+ *
83
+ * @param params - Monetization parameters
84
+ *
85
+ * @example
86
+ * // One-time purchase
87
+ * await revenue.monetization.create({
88
+ * data: {
89
+ * organizationId: '...',
90
+ * customerId: '...',
91
+ * referenceId: order._id,
92
+ * referenceModel: 'Order',
93
+ * },
94
+ * planKey: 'one_time',
95
+ * monetizationType: 'purchase',
96
+ * gateway: 'bkash',
97
+ * amount: 1500,
98
+ * });
99
+ *
100
+ * // Recurring subscription
101
+ * await revenue.monetization.create({
102
+ * data: {
103
+ * organizationId: '...',
104
+ * customerId: '...',
105
+ * referenceId: subscription._id,
106
+ * referenceModel: 'Subscription',
107
+ * },
108
+ * planKey: 'monthly',
109
+ * monetizationType: 'subscription',
110
+ * gateway: 'stripe',
111
+ * amount: 2000,
112
+ * });
113
+ *
114
+ * @returns Result with subscription, transaction, and paymentIntent
115
+ */
116
+ create(params: MonetizationCreateParams): Promise<MonetizationCreateResult>;
117
+ /**
118
+ * Activate subscription after payment verification
119
+ *
120
+ * @param subscriptionId - Subscription ID or transaction ID
121
+ * @param options - Activation options
122
+ * @returns Updated subscription
123
+ */
124
+ activate(subscriptionId: string, options?: ActivateOptions): Promise<SubscriptionDocument>;
125
+ /**
126
+ * Renew subscription
127
+ *
128
+ * @param subscriptionId - Subscription ID
129
+ * @param params - Renewal parameters
130
+ * @returns { subscription, transaction, paymentIntent }
131
+ */
132
+ renew(subscriptionId: string, params?: RenewalParams): Promise<MonetizationCreateResult>;
133
+ /**
134
+ * Cancel subscription
135
+ *
136
+ * @param subscriptionId - Subscription ID
137
+ * @param options - Cancellation options
138
+ * @returns Updated subscription
139
+ */
140
+ cancel(subscriptionId: string, options?: CancelOptions): Promise<SubscriptionDocument>;
141
+ /**
142
+ * Pause subscription
143
+ *
144
+ * @param subscriptionId - Subscription ID
145
+ * @param options - Pause options
146
+ * @returns Updated subscription
147
+ */
148
+ pause(subscriptionId: string, options?: PauseOptions): Promise<SubscriptionDocument>;
149
+ /**
150
+ * Resume subscription
151
+ *
152
+ * @param subscriptionId - Subscription ID
153
+ * @param options - Resume options
154
+ * @returns Updated subscription
155
+ */
156
+ resume(subscriptionId: string, options?: ResumeOptions): Promise<SubscriptionDocument>;
157
+ /**
158
+ * List subscriptions with filters
159
+ *
160
+ * @param filters - Query filters
161
+ * @param options - Query options (limit, skip, sort)
162
+ * @returns Subscriptions
163
+ */
164
+ list(filters?: Record<string, unknown>, options?: ListOptions): Promise<SubscriptionDocument[]>;
165
+ /**
166
+ * Get subscription by ID
167
+ *
168
+ * @param subscriptionId - Subscription ID
169
+ * @returns Subscription
170
+ */
171
+ get(subscriptionId: string): Promise<SubscriptionDocument>;
172
+ /**
173
+ * Calculate period end date based on plan key
174
+ * @private
175
+ */
176
+ private _calculatePeriodEnd;
177
+ /**
178
+ * Trigger event hook (fire-and-forget, non-blocking)
179
+ * @private
180
+ */
181
+ private _triggerHook;
182
+ }
183
+
184
+ /**
185
+ * Payment Service
186
+ * @classytic/revenue
187
+ *
188
+ * Framework-agnostic payment verification and management service with DI
189
+ * Handles payment verification, refunds, and status updates
190
+ */
191
+
192
+ /**
193
+ * Payment Service
194
+ * Uses DI container for all dependencies
195
+ */
196
+ declare class PaymentService {
197
+ private readonly models;
198
+ private readonly providers;
199
+ private readonly config;
200
+ private readonly hooks;
201
+ private readonly logger;
202
+ constructor(container: Container);
203
+ /**
204
+ * Verify a payment
205
+ *
206
+ * @param paymentIntentId - Payment intent ID, session ID, or transaction ID
207
+ * @param options - Verification options
208
+ * @returns { transaction, status }
209
+ */
210
+ verify(paymentIntentId: string, options?: PaymentVerifyOptions): Promise<PaymentVerifyResult>;
211
+ /**
212
+ * Get payment status
213
+ *
214
+ * @param paymentIntentId - Payment intent ID, session ID, or transaction ID
215
+ * @returns { transaction, status }
216
+ */
217
+ getStatus(paymentIntentId: string): Promise<PaymentStatusResult>;
218
+ /**
219
+ * Refund a payment
220
+ *
221
+ * @param paymentId - Payment intent ID, session ID, or transaction ID
222
+ * @param amount - Amount to refund (optional, full refund if not provided)
223
+ * @param options - Refund options
224
+ * @returns { transaction, refundResult }
225
+ */
226
+ refund(paymentId: string, amount?: number | null, options?: RefundOptions): Promise<PaymentRefundResult>;
227
+ /**
228
+ * Handle webhook from payment provider
229
+ *
230
+ * @param provider - Provider name
231
+ * @param payload - Webhook payload
232
+ * @param headers - Request headers
233
+ * @returns { event, transaction }
234
+ */
235
+ handleWebhook(providerName: string, payload: unknown, headers?: Record<string, string>): Promise<WebhookResult>;
236
+ /**
237
+ * List payments/transactions with filters
238
+ *
239
+ * @param filters - Query filters
240
+ * @param options - Query options (limit, skip, sort)
241
+ * @returns Transactions
242
+ */
243
+ list(filters?: Record<string, unknown>, options?: ListOptions): Promise<TransactionDocument[]>;
244
+ /**
245
+ * Get payment/transaction by ID
246
+ *
247
+ * @param transactionId - Transaction ID
248
+ * @returns Transaction
249
+ */
250
+ get(transactionId: string): Promise<TransactionDocument>;
251
+ /**
252
+ * Get provider instance
253
+ *
254
+ * @param providerName - Provider name
255
+ * @returns Provider instance
256
+ */
257
+ getProvider(providerName: string): PaymentProviderInterface;
258
+ /**
259
+ * Trigger event hook (fire-and-forget, non-blocking)
260
+ * @private
261
+ */
262
+ private _triggerHook;
263
+ /**
264
+ * Find transaction by sessionId, paymentIntentId, or transaction ID
265
+ * @private
266
+ */
267
+ private _findTransaction;
268
+ }
269
+
270
+ /**
271
+ * Transaction Service
272
+ * @classytic/revenue
273
+ *
274
+ * Thin, focused transaction service for core operations
275
+ * Users handle their own analytics, exports, and complex queries
276
+ *
277
+ * Works with ANY model implementation:
278
+ * - Plain Mongoose models
279
+ * - @classytic/mongokit Repository instances
280
+ * - Any other abstraction with compatible interface
281
+ */
282
+
283
+ /**
284
+ * Transaction Service
285
+ * Focused on core transaction lifecycle operations
286
+ */
287
+ declare class TransactionService {
288
+ private readonly models;
289
+ private readonly hooks;
290
+ private readonly logger;
291
+ constructor(container: Container);
292
+ /**
293
+ * Get transaction by ID
294
+ *
295
+ * @param transactionId - Transaction ID
296
+ * @returns Transaction
297
+ */
298
+ get(transactionId: string): Promise<TransactionDocument>;
299
+ /**
300
+ * List transactions with filters
301
+ *
302
+ * @param filters - Query filters
303
+ * @param options - Query options (limit, skip, sort, populate)
304
+ * @returns { transactions, total, page, limit }
305
+ */
306
+ list(filters?: Record<string, unknown>, options?: ListOptions): Promise<TransactionListResult>;
307
+ /**
308
+ * Update transaction
309
+ *
310
+ * @param transactionId - Transaction ID
311
+ * @param updates - Fields to update
312
+ * @returns Updated transaction
313
+ */
314
+ update(transactionId: string, updates: Partial<TransactionDocument>): Promise<TransactionDocument>;
315
+ /**
316
+ * Trigger event hook (fire-and-forget, non-blocking)
317
+ * @private
318
+ */
319
+ private _triggerHook;
320
+ }
321
+
322
+ /**
323
+ * Escrow Service
324
+ * @classytic/revenue
325
+ *
326
+ * Platform-as-intermediary payment flow
327
+ * Hold funds → Verify → Split/Deduct → Release to organization
328
+ */
329
+
330
+ declare class EscrowService {
331
+ private readonly models;
332
+ private readonly hooks;
333
+ private readonly logger;
334
+ constructor(container: Container);
335
+ /**
336
+ * Hold funds in escrow
337
+ *
338
+ * @param transactionId - Transaction to hold
339
+ * @param options - Hold options
340
+ * @returns Updated transaction
341
+ */
342
+ hold(transactionId: string, options?: HoldOptions): Promise<TransactionDocument>;
343
+ /**
344
+ * Release funds from escrow to recipient
345
+ *
346
+ * @param transactionId - Transaction to release
347
+ * @param options - Release options
348
+ * @returns { transaction, releaseTransaction }
349
+ */
350
+ release(transactionId: string, options: ReleaseOptions): Promise<ReleaseResult>;
351
+ /**
352
+ * Cancel hold and release back to customer
353
+ *
354
+ * @param transactionId - Transaction to cancel hold
355
+ * @param options - Cancel options
356
+ * @returns Updated transaction
357
+ */
358
+ cancel(transactionId: string, options?: CancelHoldOptions): Promise<TransactionDocument>;
359
+ /**
360
+ * Split payment to multiple recipients
361
+ * Deducts splits from held amount and releases remainder to organization
362
+ *
363
+ * @param transactionId - Transaction to split
364
+ * @param splitRules - Split configuration
365
+ * @returns { transaction, splitTransactions, organizationTransaction }
366
+ */
367
+ split(transactionId: string, splitRules?: SplitRule[]): Promise<SplitResult>;
368
+ /**
369
+ * Get escrow status
370
+ *
371
+ * @param transactionId - Transaction ID
372
+ * @returns Escrow status
373
+ */
374
+ getStatus(transactionId: string): Promise<EscrowStatusResult>;
375
+ private _triggerHook;
376
+ }
377
+
378
+ export { Container as C, EscrowService as E, MonetizationService as M, PaymentService as P, TransactionService as T };