@classytic/revenue 1.1.3 → 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 +32 -36
  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-CorrWz7A.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-9scqKSef.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-D5uWB5tP.d.mts +0 -344
  74. package/dist/settlement.service-BxuiHpNC.d.mts +0 -594
  75. package/dist/settlement.service-CUxbUTzT.mjs +0 -2510
  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
@@ -1,471 +0,0 @@
1
- import { Types } from "mongoose";
2
- import { HoldInfo, ITransaction, ITransactionCreateInput } from "@classytic/shared-types";
3
-
4
- //#region src/shared/types/index.d.ts
5
- /** ObjectId type from Mongoose */
6
- type ObjectId = Types.ObjectId;
7
- /** Generic Mongoose model interface - simplified for compatibility */
8
- interface MongooseModel<T = unknown> {
9
- findById(id: string | ObjectId): Promise<T | null>;
10
- find(filter?: object): unknown;
11
- findOne(filter?: object): Promise<T | null>;
12
- create(data: Partial<T> | Record<string, unknown>): Promise<T>;
13
- countDocuments?(filter?: object): Promise<number>;
14
- count?(filter?: object): Promise<number>;
15
- findByIdAndUpdate(id: string | ObjectId, update: object, options?: object): Promise<T | null>;
16
- update?(id: string, data: object): Promise<T | null>;
17
- }
18
- /** Transaction status values */
19
- type TransactionStatusValue = 'pending' | 'payment_initiated' | 'processing' | 'requires_action' | 'verified' | 'completed' | 'failed' | 'cancelled' | 'expired' | 'refunded' | 'partially_refunded';
20
- /** Transaction flow values - directional money movement */
21
- type TransactionFlowValue = 'inflow' | 'outflow';
22
- /** Gateway information stored on transaction */
23
- interface TransactionGateway {
24
- type: string;
25
- sessionId?: string | null;
26
- paymentIntentId?: string | null;
27
- provider?: string;
28
- metadata?: Record<string, unknown>;
29
- verificationData?: Record<string, unknown>;
30
- }
31
- /** Commission information */
32
- interface CommissionInfo {
33
- rate: number;
34
- grossAmount: number;
35
- gatewayFeeRate: number;
36
- gatewayFeeAmount: number;
37
- netAmount: number;
38
- status: 'pending' | 'paid' | 'waived';
39
- splits?: SplitInfo[];
40
- affiliate?: {
41
- recipientId: string;
42
- recipientType: string;
43
- rate: number;
44
- grossAmount: number;
45
- netAmount: number;
46
- };
47
- }
48
- /** Webhook information */
49
- interface WebhookInfo {
50
- eventId: string;
51
- eventType: string;
52
- receivedAt: Date;
53
- processedAt?: Date;
54
- data: Record<string, unknown>;
55
- }
56
- /**
57
- * Base transaction document interface
58
- * Note: Implements unified transaction model (compatible with ITransaction but doesn't extend it)
59
- */
60
- interface TransactionDocument {
61
- _id: ObjectId;
62
- organizationId: string | ObjectId;
63
- customerId?: string | ObjectId | null;
64
- type: string;
65
- flow: TransactionFlowValue;
66
- tags?: string[];
67
- status: TransactionStatusValue;
68
- amount: number;
69
- currency: string;
70
- fee?: number;
71
- tax?: number;
72
- net: number;
73
- taxDetails?: {
74
- type?: 'sales_tax' | 'vat' | 'gst' | 'income_tax' | 'withholding_tax' | 'none';
75
- rate?: number;
76
- isInclusive?: boolean;
77
- jurisdiction?: string;
78
- };
79
- method: string;
80
- gateway?: TransactionGateway;
81
- paymentDetails?: Record<string, unknown>;
82
- commission?: CommissionInfo | null;
83
- splits?: SplitInfo[];
84
- hold?: HoldInfo;
85
- escrow?: HoldInfo;
86
- sourceId?: string | ObjectId;
87
- sourceModel?: string;
88
- relatedTransactionId?: ObjectId;
89
- category?: string;
90
- date?: Date;
91
- verifiedAt?: Date;
92
- verifiedBy?: string | ObjectId | null;
93
- failedAt?: Date;
94
- failureReason?: string;
95
- refundedAmount?: number;
96
- refundedAt?: Date;
97
- createdAt: Date;
98
- updatedAt: Date;
99
- webhook?: WebhookInfo;
100
- metadata?: Record<string, unknown>;
101
- idempotencyKey?: string;
102
- save(options?: {
103
- session?: any;
104
- }): Promise<this>;
105
- }
106
- /** Subscription status values */
107
- type SubscriptionStatusValue = 'active' | 'paused' | 'cancelled' | 'expired' | 'pending' | 'inactive' | 'pending_renewal';
108
- /** Plan key values */
109
- type PlanKeyValue = 'monthly' | 'quarterly' | 'yearly' | string;
110
- /** Base subscription document interface */
111
- interface SubscriptionDocument {
112
- _id: ObjectId;
113
- organizationId?: string | ObjectId;
114
- customerId?: string | ObjectId | null;
115
- planKey: PlanKeyValue;
116
- amount: number;
117
- currency: string;
118
- status: SubscriptionStatusValue;
119
- isActive: boolean;
120
- gateway?: string;
121
- transactionId?: ObjectId | null;
122
- paymentIntentId?: string | null;
123
- startDate?: Date;
124
- endDate?: Date;
125
- activatedAt?: Date;
126
- canceledAt?: Date;
127
- cancelAt?: Date;
128
- cancellationReason?: string | null;
129
- pausedAt?: Date | null;
130
- pauseReason?: string | null;
131
- renewalCount?: number;
132
- renewalTransactionId?: ObjectId;
133
- metadata?: Record<string, unknown>;
134
- createdAt: Date;
135
- updatedAt: Date;
136
- save(): Promise<this>;
137
- }
138
- /** Monetization type values */
139
- type MonetizationTypeValue = 'free' | 'purchase' | 'subscription';
140
- /** Hold reason values */
141
- type HoldReasonValue = 'payment_verification' | 'fraud_check' | 'manual_review' | 'dispute' | 'compliance';
142
- /** Release reason values */
143
- type ReleaseReasonValue = 'payment_verified' | 'manual_release' | 'auto_release' | 'dispute_resolved';
144
- /** Split type values */
145
- type SplitTypeValue = 'platform_commission' | 'affiliate_commission' | 'referral_commission' | 'partner_commission' | 'custom';
146
- /** Split status values */
147
- type SplitStatusValue = 'pending' | 'due' | 'paid' | 'waived' | 'cancelled';
148
- /** Split rule configuration */
149
- interface SplitRule {
150
- type?: SplitTypeValue;
151
- recipientId: string;
152
- recipientType: string;
153
- rate: number;
154
- dueDate?: Date | null;
155
- metadata?: Record<string, unknown>;
156
- }
157
- /** Calculated split info */
158
- interface SplitInfo {
159
- _id?: ObjectId;
160
- type: SplitTypeValue;
161
- recipientId: string;
162
- recipientType: string;
163
- rate: number;
164
- grossAmount: number;
165
- gatewayFeeRate: number;
166
- gatewayFeeAmount: number;
167
- netAmount: number;
168
- status: SplitStatusValue;
169
- dueDate?: Date | null;
170
- paidDate?: Date;
171
- payoutTransactionId?: string;
172
- metadata: Record<string, unknown>;
173
- }
174
- /** Payment intent parameters */
175
- interface CreateIntentParams {
176
- amount: number;
177
- currency?: string;
178
- metadata?: Record<string, unknown>;
179
- }
180
- /** Payment intent data */
181
- interface PaymentIntentData {
182
- id: string;
183
- sessionId?: string | null;
184
- paymentIntentId?: string | null;
185
- provider: string;
186
- status: string;
187
- amount: number;
188
- currency?: string;
189
- metadata?: Record<string, unknown>;
190
- clientSecret?: string;
191
- paymentUrl?: string;
192
- instructions?: string;
193
- raw?: unknown;
194
- }
195
- /** Payment result data */
196
- interface PaymentResultData {
197
- id: string;
198
- provider: string;
199
- status: 'succeeded' | 'failed' | 'processing' | 'requires_action';
200
- amount?: number;
201
- currency?: string;
202
- paidAt?: Date;
203
- metadata?: Record<string, unknown>;
204
- raw?: unknown;
205
- }
206
- /** Refund result data */
207
- interface RefundResultData {
208
- id: string;
209
- provider: string;
210
- status: 'succeeded' | 'failed' | 'processing';
211
- amount?: number;
212
- currency?: string;
213
- refundedAt?: Date;
214
- reason?: string;
215
- metadata?: Record<string, unknown>;
216
- raw?: unknown;
217
- }
218
- /** Webhook event data */
219
- interface WebhookEventData {
220
- id: string;
221
- provider: string;
222
- type: string;
223
- data: {
224
- sessionId?: string;
225
- paymentIntentId?: string;
226
- [key: string]: unknown;
227
- };
228
- createdAt?: Date;
229
- raw?: unknown;
230
- }
231
- /** Provider capabilities */
232
- interface ProviderCapabilities {
233
- supportsWebhooks: boolean;
234
- supportsRefunds: boolean;
235
- supportsPartialRefunds: boolean;
236
- requiresManualVerification: boolean;
237
- }
238
- /** Logger interface */
239
- interface Logger {
240
- info(...args: unknown[]): void;
241
- warn(...args: unknown[]): void;
242
- error(...args: unknown[]): void;
243
- debug(...args: unknown[]): void;
244
- log?(...args: unknown[]): void;
245
- }
246
- /** Revenue configuration */
247
- interface RevenueConfig {
248
- targetModels: string[];
249
- categoryMappings: Record<string, string>;
250
- commissionRates?: Record<string, number>;
251
- gatewayFeeRates?: Record<string, number>;
252
- /** Maps transaction categories to flow direction (inflow/outflow) */
253
- transactionTypeMapping?: Record<string, TransactionFlowValue>;
254
- }
255
- /** Payment provider interface */
256
- interface PaymentProviderInterface {
257
- name: string;
258
- config: Record<string, unknown>;
259
- createIntent(params: CreateIntentParams): Promise<PaymentIntentData>;
260
- verifyPayment(intentId: string): Promise<PaymentResultData>;
261
- getStatus(intentId: string): Promise<PaymentResultData>;
262
- refund(paymentId: string, amount?: number | null, options?: {
263
- reason?: string;
264
- }): Promise<RefundResultData>;
265
- handleWebhook(payload: unknown, headers?: Record<string, string>): Promise<WebhookEventData>;
266
- verifyWebhookSignature(payload: unknown, signature: string): boolean;
267
- getCapabilities(): ProviderCapabilities;
268
- }
269
- /** Monetization create data */
270
- interface MonetizationData {
271
- organizationId?: string | ObjectId;
272
- customerId?: string | ObjectId;
273
- sourceId?: string | ObjectId;
274
- sourceModel?: string;
275
- }
276
- /** Monetization create params */
277
- interface MonetizationCreateParams {
278
- data: MonetizationData;
279
- planKey: string;
280
- amount: number;
281
- currency?: string;
282
- gateway?: string;
283
- entity?: string | null;
284
- monetizationType?: MonetizationTypeValue;
285
- paymentData?: Record<string, unknown>;
286
- metadata?: Record<string, unknown>;
287
- idempotencyKey?: string | null;
288
- /** Tax data injected by tax plugin (optional) */
289
- tax?: {
290
- isApplicable: boolean;
291
- rate: number;
292
- baseAmount: number;
293
- taxAmount: number;
294
- totalAmount: number;
295
- pricesIncludeTax: boolean;
296
- type: 'collected' | 'paid' | 'exempt';
297
- };
298
- }
299
- /** Monetization create result */
300
- interface MonetizationCreateResult {
301
- subscription: SubscriptionDocument | null;
302
- transaction: TransactionDocument | null;
303
- paymentIntent: PaymentIntentData | null;
304
- }
305
- /** Activation options */
306
- interface ActivateOptions {
307
- timestamp?: Date;
308
- }
309
- /** Renewal params */
310
- interface RenewalParams {
311
- gateway?: string;
312
- entity?: string | null;
313
- paymentData?: Record<string, unknown>;
314
- metadata?: Record<string, unknown>;
315
- idempotencyKey?: string | null;
316
- }
317
- /** Cancellation options */
318
- interface CancelOptions {
319
- immediate?: boolean;
320
- reason?: string | null;
321
- }
322
- /** Pause options */
323
- interface PauseOptions {
324
- reason?: string | null;
325
- }
326
- /** Resume options */
327
- interface ResumeOptions {
328
- extendPeriod?: boolean;
329
- }
330
- /** List options */
331
- interface ListOptions {
332
- limit?: number;
333
- skip?: number;
334
- page?: number | null;
335
- sort?: Record<string, 1 | -1>;
336
- populate?: string[];
337
- }
338
- /** Payment verify options */
339
- interface PaymentVerifyOptions {
340
- verifiedBy?: string | null;
341
- }
342
- /** Payment verify result */
343
- interface PaymentVerifyResult {
344
- transaction: TransactionDocument;
345
- paymentResult: PaymentResultData | null;
346
- status: TransactionStatusValue;
347
- }
348
- /** Payment status result */
349
- interface PaymentStatusResult {
350
- transaction: TransactionDocument;
351
- paymentResult?: PaymentResultData | null;
352
- status: TransactionStatusValue | string;
353
- provider?: string;
354
- }
355
- /** Refund options */
356
- interface RefundOptions {
357
- reason?: string | null;
358
- }
359
- /** Payment refund result */
360
- interface PaymentRefundResult {
361
- transaction: TransactionDocument;
362
- refundTransaction: TransactionDocument;
363
- refundResult: RefundResultData;
364
- status: TransactionStatusValue;
365
- }
366
- /** Webhook result */
367
- interface WebhookResult {
368
- event: WebhookEventData;
369
- transaction: TransactionDocument;
370
- status: 'processed' | 'already_processed';
371
- }
372
- /** Transaction list result */
373
- interface TransactionListResult {
374
- transactions: TransactionDocument[];
375
- total: number;
376
- page: number;
377
- limit: number;
378
- pages: number;
379
- }
380
- /** Hold options */
381
- interface HoldOptions {
382
- reason?: HoldReasonValue;
383
- holdUntil?: Date | null;
384
- metadata?: Record<string, unknown>;
385
- }
386
- /** Release options */
387
- interface ReleaseOptions {
388
- amount?: number | null;
389
- recipientId: string;
390
- recipientType?: string;
391
- reason?: ReleaseReasonValue;
392
- releasedBy?: string | null;
393
- createTransaction?: boolean;
394
- metadata?: Record<string, unknown>;
395
- }
396
- /** Release result */
397
- interface ReleaseResult {
398
- transaction: TransactionDocument;
399
- releaseTransaction: TransactionDocument | null;
400
- releaseAmount: number;
401
- isFullRelease: boolean;
402
- isPartialRelease: boolean;
403
- }
404
- /** Cancel hold options */
405
- interface CancelHoldOptions {
406
- reason?: string;
407
- metadata?: Record<string, unknown>;
408
- }
409
- /** Split result */
410
- interface SplitResult {
411
- transaction: TransactionDocument;
412
- splits: SplitInfo[];
413
- splitTransactions: TransactionDocument[];
414
- organizationTransaction: TransactionDocument | null;
415
- organizationPayout: number;
416
- }
417
- /** Escrow status result */
418
- interface EscrowStatusResult {
419
- transaction: TransactionDocument;
420
- hold: HoldInfo | null;
421
- splits: SplitInfo[];
422
- hasHold: boolean;
423
- hasSplits: boolean;
424
- }
425
- /** Period range params */
426
- interface PeriodRangeParams {
427
- currentEndDate?: Date | null;
428
- startDate?: Date | null;
429
- duration: number;
430
- unit?: 'days' | 'weeks' | 'months' | 'years';
431
- now?: Date;
432
- }
433
- /** Period range result */
434
- interface PeriodRangeResult {
435
- startDate: Date;
436
- endDate: Date;
437
- }
438
- /** Prorated amount params */
439
- interface ProratedAmountParams {
440
- amountPaid: number;
441
- startDate: Date;
442
- endDate: Date;
443
- asOfDate?: Date;
444
- precision?: number;
445
- }
446
- /** Duration result */
447
- interface DurationResult {
448
- duration: number;
449
- unit: 'days' | 'weeks' | 'months' | 'years';
450
- }
451
- /** Subscription entity for action checks */
452
- interface SubscriptionEntity {
453
- subscription?: {
454
- isActive?: boolean;
455
- endDate?: Date;
456
- canceledAt?: Date;
457
- };
458
- status?: SubscriptionStatusValue;
459
- }
460
- /** Transaction type detection options */
461
- interface TransactionTypeOptions {
462
- targetModels?: string[];
463
- additionalCategories?: string[];
464
- }
465
- /** Field update validation result */
466
- interface FieldUpdateValidationResult {
467
- allowed: boolean;
468
- reason?: string;
469
- }
470
- //#endregion
471
- export { ReleaseOptions as A, TransactionDocument as B, PaymentVerifyResult as C, ProviderCapabilities as D, ProratedAmountParams as E, SplitInfo as F, WebhookResult as G, TransactionListResult as H, SplitResult as I, ITransaction as K, SplitRule as L, RenewalParams as M, ResumeOptions as N, RefundOptions as O, RevenueConfig as P, SubscriptionDocument as R, PaymentVerifyOptions as S, PeriodRangeResult as T, TransactionTypeOptions as U, TransactionFlowValue as V, WebhookEventData as W, PaymentIntentData as _, CreateIntentParams as a, PaymentResultData as b, FieldUpdateValidationResult as c, Logger as d, MonetizationCreateParams as f, PauseOptions as g, MongooseModel as h, CommissionInfo as i, ReleaseResult as j, RefundResultData as k, HoldOptions as l, MonetizationTypeValue as m, CancelHoldOptions as n, DurationResult as o, MonetizationCreateResult as p, ITransactionCreateInput as q, CancelOptions as r, EscrowStatusResult as s, ActivateOptions as t, ListOptions as u, PaymentProviderInterface as v, PeriodRangeParams as w, PaymentStatusResult as x, PaymentRefundResult as y, SubscriptionEntity as z };
@@ -1,239 +0,0 @@
1
- import "../../index-Dsp7H5Wb.mjs";
2
- import "../../settlement.schema-D5uWB5tP.mjs";
3
- import "../../base-CsTlVQJe.mjs";
4
- import { c as definePlugin, o as RevenuePlugin } from "../../plugin-BbK0OVHy.mjs";
5
- import { n as TaxConfig } from "../../tax-BoCt5cEd.mjs";
6
-
7
- //#region src/infrastructure/plugins/business/logging.plugin.d.ts
8
- /**
9
- * Logging plugin options
10
- */
11
- interface LoggingPluginOptions {
12
- /** Log level: 'debug' or 'info' */
13
- level?: 'debug' | 'info';
14
- }
15
- /**
16
- * Logging plugin - logs all operations
17
- *
18
- * Logs payment creation, verification, and refund operations
19
- *
20
- * @param options - Plugin options
21
- * @returns Logging plugin
22
- *
23
- * @example
24
- * ```typescript
25
- * import { Revenue } from '@classytic/revenue';
26
- * import { loggingPlugin } from '@classytic/revenue/plugins';
27
- *
28
- * const revenue = Revenue
29
- * .create()
30
- * .withPlugin(loggingPlugin({ level: 'debug' }))
31
- * .build();
32
- * ```
33
- */
34
- declare function loggingPlugin(options?: LoggingPluginOptions): RevenuePlugin;
35
- //#endregion
36
- //#region src/infrastructure/plugins/business/audit.plugin.d.ts
37
- /**
38
- * Audit entry record
39
- */
40
- interface AuditEntry {
41
- action: string;
42
- requestId: string;
43
- timestamp: Date;
44
- input: Record<string, unknown>;
45
- output: Record<string, unknown>;
46
- idempotencyKey?: string;
47
- }
48
- /**
49
- * Audit plugin options
50
- */
51
- interface AuditPluginOptions {
52
- /** Custom storage function for audit entries */
53
- store?: (entry: AuditEntry) => Promise<void>;
54
- }
55
- /**
56
- * Audit plugin - records all operations for compliance
57
- *
58
- * Records payment creation, refunds, and other operations with sanitized data
59
- *
60
- * @param options - Plugin options
61
- * @returns Audit plugin
62
- *
63
- * @example
64
- * ```typescript
65
- * import { Revenue } from '@classytic/revenue';
66
- * import { auditPlugin } from '@classytic/revenue/plugins';
67
- *
68
- * const revenue = Revenue
69
- * .create()
70
- * .withPlugin(auditPlugin({
71
- * store: async (entry) => {
72
- * await AuditLog.create(entry);
73
- * }
74
- * }))
75
- * .build();
76
- * ```
77
- */
78
- declare function auditPlugin(options?: AuditPluginOptions): RevenuePlugin;
79
- //#endregion
80
- //#region src/infrastructure/plugins/business/metrics.plugin.d.ts
81
- /**
82
- * Metric record
83
- */
84
- interface Metric {
85
- name: string;
86
- duration: number;
87
- success: boolean;
88
- error?: string;
89
- [key: string]: unknown;
90
- }
91
- /**
92
- * Metrics plugin options
93
- */
94
- interface MetricsPluginOptions {
95
- /** Callback for each metric */
96
- onMetric?: (metric: Metric) => void;
97
- }
98
- /**
99
- * Metrics plugin - collects operation metrics
100
- *
101
- * Tracks duration and success/failure of operations
102
- *
103
- * @param options - Plugin options
104
- * @returns Metrics plugin
105
- *
106
- * @example
107
- * ```typescript
108
- * import { Revenue } from '@classytic/revenue';
109
- * import { metricsPlugin } from '@classytic/revenue/plugins';
110
- *
111
- * const revenue = Revenue
112
- * .create()
113
- * .withPlugin(metricsPlugin({
114
- * onMetric: (metric) => {
115
- * // Send to Datadog, Prometheus, etc.
116
- * statsd.timing(metric.name, metric.duration);
117
- * if (!metric.success) {
118
- * statsd.increment(`${metric.name}.error`);
119
- * }
120
- * }
121
- * }))
122
- * .build();
123
- * ```
124
- */
125
- declare function metricsPlugin(options?: MetricsPluginOptions): RevenuePlugin;
126
- //#endregion
127
- //#region src/infrastructure/plugins/business/tax.plugin.d.ts
128
- /**
129
- * Tax Plugin Options
130
- */
131
- interface TaxPluginOptions {
132
- /**
133
- * Function to get tax configuration for an organization
134
- * Apps implement this to return jurisdiction-specific config
135
- *
136
- * @param orgId - Organization ID
137
- * @returns Tax configuration or null if not registered
138
- *
139
- * @example
140
- * ```typescript
141
- * getTaxConfig: async (orgId) => {
142
- * const org = await Organization.findById(orgId);
143
- * if (!org) return null;
144
- *
145
- * return {
146
- * isRegistered: org.country === 'AU',
147
- * defaultRate: org.country === 'AU' ? 0.10 : 0, // 10% GST in Australia
148
- * pricesIncludeTax: org.pricesIncludeTax || false,
149
- * exemptCategories: ['education', 'medical'],
150
- * };
151
- * }
152
- * ```
153
- */
154
- getTaxConfig: (orgId: string) => Promise<TaxConfig | null>;
155
- /**
156
- * Category mappings for resolving transaction categories
157
- * Maps entity names to category strings
158
- *
159
- * @example
160
- * ```typescript
161
- * {
162
- * Order: 'order_subscription',
163
- * PlatformSubscription: 'platform_subscription',
164
- * Membership: 'gym_membership',
165
- * }
166
- * ```
167
- */
168
- categoryMappings?: Record<string, string>;
169
- /**
170
- * Categories that represent income (vs expense)
171
- * Used to determine tax type: 'collected' vs 'paid'
172
- *
173
- * Default: ['subscription', 'purchase', 'course_enrollment']
174
- */
175
- incomeCategories?: string[];
176
- }
177
- /**
178
- * Create Tax Plugin
179
- *
180
- * Automatically calculates and applies tax to transactions during monetization.create()
181
- *
182
- * @param options - Plugin options
183
- * @returns Tax plugin
184
- *
185
- * @example
186
- * ```typescript
187
- * import { Revenue } from '@classytic/revenue';
188
- * import { createTaxPlugin } from '@classytic/revenue/plugins';
189
- *
190
- * const revenue = Revenue
191
- * .create({ defaultCurrency: 'USD' })
192
- * .withModels({ Transaction, Subscription })
193
- * .withProvider('stripe', stripeProvider)
194
- * .withPlugin(createTaxPlugin({
195
- * getTaxConfig: async (orgId) => {
196
- * const org = await Organization.findById(orgId);
197
- * return {
198
- * isRegistered: true,
199
- * defaultRate: 0.15, // 15% tax
200
- * pricesIncludeTax: false,
201
- * exemptCategories: ['education'],
202
- * };
203
- * },
204
- * categoryMappings: {
205
- * Order: 'order_subscription',
206
- * Membership: 'gym_membership',
207
- * },
208
- * }))
209
- * .build();
210
- *
211
- * // Tax is now automatically calculated
212
- * await revenue.monetization.create({
213
- * data: { organizationId: 'org_123', customerId: 'cust_456' },
214
- * planKey: 'monthly',
215
- * amount: 10000, // $100
216
- * entity: 'Order',
217
- * monetizationType: 'subscription',
218
- * });
219
- * // → Creates transaction with tax: {
220
- * // isApplicable: true,
221
- * // rate: 0.15,
222
- * // baseAmount: 10000,
223
- * // taxAmount: 1500,
224
- * // totalAmount: 11500,
225
- * // type: 'collected'
226
- * // }
227
- * ```
228
- */
229
- declare function createTaxPlugin(options: TaxPluginOptions): RevenuePlugin;
230
- //#endregion
231
- //#region src/infrastructure/plugins/index.d.ts
232
- declare const _default: {
233
- loggingPlugin: typeof loggingPlugin;
234
- auditPlugin: typeof auditPlugin;
235
- metricsPlugin: typeof metricsPlugin;
236
- createTaxPlugin: typeof createTaxPlugin;
237
- };
238
- //#endregion
239
- export { type AuditEntry, type AuditPluginOptions, type LoggingPluginOptions, type Metric, type MetricsPluginOptions, type TaxPluginOptions, auditPlugin, createTaxPlugin, _default as default, definePlugin, loggingPlugin, metricsPlugin };