@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,101 +0,0 @@
1
- //#region src/enums/monetization.enums.ts
2
- /**
3
- * Monetization Enums
4
- * @classytic/revenue
5
- *
6
- * General monetization enums and constants
7
- */
8
- const MONETIZATION_TYPES = {
9
- FREE: "free",
10
- PURCHASE: "purchase",
11
- SUBSCRIPTION: "subscription"
12
- };
13
- const MONETIZATION_TYPE_VALUES = Object.values(MONETIZATION_TYPES);
14
- const monetizationTypeSet = new Set(MONETIZATION_TYPE_VALUES);
15
- function isMonetizationType(value) {
16
- return typeof value === "string" && monetizationTypeSet.has(value);
17
- }
18
-
19
- //#endregion
20
- //#region src/enums/settlement.enums.ts
21
- /**
22
- * Settlement Enums
23
- * @classytic/revenue
24
- *
25
- * Enums for settlement/payout tracking
26
- */
27
- const SETTLEMENT_STATUS = {
28
- PENDING: "pending",
29
- PROCESSING: "processing",
30
- COMPLETED: "completed",
31
- FAILED: "failed",
32
- CANCELLED: "cancelled"
33
- };
34
- const SETTLEMENT_STATUS_VALUES = Object.values(SETTLEMENT_STATUS);
35
- /**
36
- * Type guard for settlement status
37
- */
38
- function isSettlementStatus(value) {
39
- return typeof value === "string" && SETTLEMENT_STATUS_VALUES.includes(value);
40
- }
41
- const SETTLEMENT_TYPE = {
42
- SPLIT_PAYOUT: "split_payout",
43
- PLATFORM_WITHDRAWAL: "platform_withdrawal",
44
- MANUAL_PAYOUT: "manual_payout",
45
- ESCROW_RELEASE: "escrow_release"
46
- };
47
- const SETTLEMENT_TYPE_VALUES = Object.values(SETTLEMENT_TYPE);
48
- /**
49
- * Type guard for settlement type
50
- */
51
- function isSettlementType(value) {
52
- return typeof value === "string" && SETTLEMENT_TYPE_VALUES.includes(value);
53
- }
54
-
55
- //#endregion
56
- //#region src/enums/escrow.enums.ts
57
- /**
58
- * Escrow/Hold Enums
59
- * @classytic/revenue
60
- *
61
- * Enums for platform-as-intermediary payment flow
62
- */
63
- const HOLD_STATUS = {
64
- PENDING: "pending",
65
- HELD: "held",
66
- RELEASED: "released",
67
- CANCELLED: "cancelled",
68
- EXPIRED: "expired",
69
- PARTIALLY_RELEASED: "partially_released"
70
- };
71
- const HOLD_STATUS_VALUES = Object.values(HOLD_STATUS);
72
- const RELEASE_REASON = {
73
- PAYMENT_VERIFIED: "payment_verified",
74
- MANUAL_RELEASE: "manual_release",
75
- AUTO_RELEASE: "auto_release",
76
- DISPUTE_RESOLVED: "dispute_resolved"
77
- };
78
- const RELEASE_REASON_VALUES = Object.values(RELEASE_REASON);
79
- const HOLD_REASON = {
80
- PAYMENT_VERIFICATION: "payment_verification",
81
- FRAUD_CHECK: "fraud_check",
82
- MANUAL_REVIEW: "manual_review",
83
- DISPUTE: "dispute",
84
- COMPLIANCE: "compliance"
85
- };
86
- const HOLD_REASON_VALUES = Object.values(HOLD_REASON);
87
- const holdStatusSet = new Set(HOLD_STATUS_VALUES);
88
- const releaseReasonSet = new Set(RELEASE_REASON_VALUES);
89
- const holdReasonSet = new Set(HOLD_REASON_VALUES);
90
- function isHoldStatus(value) {
91
- return typeof value === "string" && holdStatusSet.has(value);
92
- }
93
- function isReleaseReason(value) {
94
- return typeof value === "string" && releaseReasonSet.has(value);
95
- }
96
- function isHoldReason(value) {
97
- return typeof value === "string" && holdReasonSet.has(value);
98
- }
99
-
100
- //#endregion
101
- export { MONETIZATION_TYPE_VALUES as _, RELEASE_REASON as a, isHoldStatus as c, SETTLEMENT_STATUS_VALUES as d, SETTLEMENT_TYPE as f, MONETIZATION_TYPES as g, isSettlementType as h, HOLD_STATUS_VALUES as i, isReleaseReason as l, isSettlementStatus as m, HOLD_REASON_VALUES as n, RELEASE_REASON_VALUES as o, SETTLEMENT_TYPE_VALUES as p, HOLD_STATUS as r, isHoldReason as s, HOLD_REASON as t, SETTLEMENT_STATUS as u, isMonetizationType as v };
@@ -1,78 +0,0 @@
1
- //#region src/enums/subscription.enums.d.ts
2
- /**
3
- * Subscription Enums
4
- * @classytic/revenue
5
- *
6
- * All subscription-related enums and constants
7
- */
8
- /**
9
- * Subscription Status
10
- */
11
- declare const SUBSCRIPTION_STATUS: {
12
- readonly ACTIVE: "active";
13
- readonly PAUSED: "paused";
14
- readonly CANCELLED: "cancelled";
15
- readonly EXPIRED: "expired";
16
- readonly PENDING: "pending";
17
- readonly PENDING_RENEWAL: "pending_renewal";
18
- readonly INACTIVE: "inactive";
19
- };
20
- type SubscriptionStatus = typeof SUBSCRIPTION_STATUS;
21
- type SubscriptionStatusValue = SubscriptionStatus[keyof SubscriptionStatus];
22
- declare const SUBSCRIPTION_STATUS_VALUES: SubscriptionStatusValue[];
23
- /**
24
- * Supported plan intervals
25
- */
26
- declare const PLAN_KEYS: {
27
- readonly MONTHLY: "monthly";
28
- readonly QUARTERLY: "quarterly";
29
- readonly YEARLY: "yearly";
30
- };
31
- type PlanKeys = typeof PLAN_KEYS;
32
- type PlanKeyValue = PlanKeys[keyof PlanKeys];
33
- declare const PLAN_KEY_VALUES: PlanKeyValue[];
34
- declare function isSubscriptionStatus(value: unknown): value is SubscriptionStatusValue;
35
- declare function isPlanKey(value: unknown): value is PlanKeyValue;
36
- //#endregion
37
- //#region src/enums/escrow.enums.d.ts
38
- /**
39
- * Escrow/Hold Enums
40
- * @classytic/revenue
41
- *
42
- * Enums for platform-as-intermediary payment flow
43
- */
44
- declare const HOLD_STATUS: {
45
- readonly PENDING: "pending";
46
- readonly HELD: "held";
47
- readonly RELEASED: "released";
48
- readonly CANCELLED: "cancelled";
49
- readonly EXPIRED: "expired";
50
- readonly PARTIALLY_RELEASED: "partially_released";
51
- };
52
- type HoldStatus = typeof HOLD_STATUS;
53
- type HoldStatusValue = HoldStatus[keyof HoldStatus];
54
- declare const HOLD_STATUS_VALUES: HoldStatusValue[];
55
- declare const RELEASE_REASON: {
56
- readonly PAYMENT_VERIFIED: "payment_verified";
57
- readonly MANUAL_RELEASE: "manual_release";
58
- readonly AUTO_RELEASE: "auto_release";
59
- readonly DISPUTE_RESOLVED: "dispute_resolved";
60
- };
61
- type ReleaseReason = typeof RELEASE_REASON;
62
- type ReleaseReasonValue = ReleaseReason[keyof ReleaseReason];
63
- declare const RELEASE_REASON_VALUES: ReleaseReasonValue[];
64
- declare const HOLD_REASON: {
65
- readonly PAYMENT_VERIFICATION: "payment_verification";
66
- readonly FRAUD_CHECK: "fraud_check";
67
- readonly MANUAL_REVIEW: "manual_review";
68
- readonly DISPUTE: "dispute";
69
- readonly COMPLIANCE: "compliance";
70
- };
71
- type HoldReason = typeof HOLD_REASON;
72
- type HoldReasonValue = HoldReason[keyof HoldReason];
73
- declare const HOLD_REASON_VALUES: HoldReasonValue[];
74
- declare function isHoldStatus(value: unknown): value is HoldStatusValue;
75
- declare function isReleaseReason(value: unknown): value is ReleaseReasonValue;
76
- declare function isHoldReason(value: unknown): value is HoldReasonValue;
77
- //#endregion
78
- export { SubscriptionStatusValue as C, SubscriptionStatus as S, isSubscriptionStatus as T, PLAN_KEY_VALUES as _, HoldReason as a, SUBSCRIPTION_STATUS as b, HoldStatusValue as c, ReleaseReason as d, ReleaseReasonValue as f, PLAN_KEYS as g, isReleaseReason as h, HOLD_STATUS_VALUES as i, RELEASE_REASON as l, isHoldStatus as m, HOLD_REASON_VALUES as n, HoldReasonValue as o, isHoldReason as p, HOLD_STATUS as r, HoldStatus as s, HOLD_REASON as t, RELEASE_REASON_VALUES as u, PlanKeyValue as v, isPlanKey as w, SUBSCRIPTION_STATUS_VALUES as x, PlanKeys as y };
@@ -1,172 +0,0 @@
1
- import { d as err, v as ok } from "./commission-split-BzB8cd39.mjs";
2
- import { nanoid } from "nanoid";
3
-
4
- //#region src/shared/utils/resilience/idempotency.ts
5
- /**
6
- * Idempotency Utilities
7
- * @classytic/revenue
8
- *
9
- * Prevent duplicate operations with idempotency keys
10
- * Inspired by: Stripe, Amazon SQS deduplication
11
- */
12
- /**
13
- * Simple in-memory idempotency store
14
- * Use Redis/database store in production
15
- */
16
- var MemoryIdempotencyStore = class {
17
- records = /* @__PURE__ */ new Map();
18
- cleanupInterval = null;
19
- constructor(cleanupIntervalMs = 6e4) {
20
- this.cleanupInterval = setInterval(() => {
21
- this.cleanup();
22
- }, cleanupIntervalMs);
23
- }
24
- async get(key) {
25
- const record = this.records.get(key);
26
- if (!record) return null;
27
- if (record.expiresAt < /* @__PURE__ */ new Date()) {
28
- this.records.delete(key);
29
- return null;
30
- }
31
- return record;
32
- }
33
- async set(key, record) {
34
- this.records.set(key, record);
35
- }
36
- async delete(key) {
37
- this.records.delete(key);
38
- }
39
- async exists(key) {
40
- return await this.get(key) !== null;
41
- }
42
- cleanup() {
43
- const now = /* @__PURE__ */ new Date();
44
- for (const [key, record] of this.records) if (record.expiresAt < now) this.records.delete(key);
45
- }
46
- destroy() {
47
- if (this.cleanupInterval) {
48
- clearInterval(this.cleanupInterval);
49
- this.cleanupInterval = null;
50
- }
51
- this.records.clear();
52
- }
53
- };
54
- var IdempotencyError = class extends Error {
55
- constructor(message, code) {
56
- super(message);
57
- this.code = code;
58
- this.name = "IdempotencyError";
59
- }
60
- };
61
- /**
62
- * Idempotency manager
63
- */
64
- var IdempotencyManager = class {
65
- store;
66
- ttl;
67
- prefix;
68
- constructor(config = {}) {
69
- this.store = config.store ?? new MemoryIdempotencyStore();
70
- this.ttl = config.ttl ?? 1440 * 60 * 1e3;
71
- this.prefix = config.prefix ?? "idem:";
72
- }
73
- /**
74
- * Generate a unique idempotency key
75
- */
76
- generateKey() {
77
- return `${this.prefix}${nanoid(21)}`;
78
- }
79
- /**
80
- * Hash request parameters for validation
81
- * Uses deterministic JSON serialization and simple hash function
82
- */
83
- hashRequest(params) {
84
- let normalized;
85
- if (params === null || params === void 0) normalized = null;
86
- else if (typeof params === "object" && !Array.isArray(params)) normalized = Object.keys(params).sort().reduce((acc, key) => {
87
- acc[key] = params[key];
88
- return acc;
89
- }, {});
90
- else normalized = params;
91
- const json = JSON.stringify(normalized);
92
- let hash = 0;
93
- for (let i = 0; i < json.length; i++) {
94
- const char = json.charCodeAt(i);
95
- hash = (hash << 5) - hash + char;
96
- hash = hash & hash;
97
- }
98
- return Math.abs(hash).toString(36);
99
- }
100
- /**
101
- * Execute operation with idempotency protection
102
- */
103
- async execute(key, params, operation) {
104
- const fullKey = key.startsWith(this.prefix) ? key : `${this.prefix}${key}`;
105
- const requestHash = this.hashRequest(params);
106
- const existing = await this.store.get(fullKey);
107
- if (existing) {
108
- if (existing.requestHash !== requestHash) return err(new IdempotencyError("Idempotency key used with different request parameters", "REQUEST_MISMATCH"));
109
- if (existing.status === "completed" && existing.result !== void 0) return ok(existing.result);
110
- if (existing.status === "pending") return err(new IdempotencyError("Request with this idempotency key is already in progress", "REQUEST_IN_PROGRESS"));
111
- if (existing.status === "failed") await this.store.delete(fullKey);
112
- }
113
- const record = {
114
- key: fullKey,
115
- status: "pending",
116
- createdAt: /* @__PURE__ */ new Date(),
117
- requestHash,
118
- expiresAt: new Date(Date.now() + this.ttl)
119
- };
120
- await this.store.set(fullKey, record);
121
- try {
122
- const result = await operation();
123
- record.status = "completed";
124
- record.result = result;
125
- record.completedAt = /* @__PURE__ */ new Date();
126
- await this.store.set(fullKey, record);
127
- return ok(result);
128
- } catch (error) {
129
- record.status = "failed";
130
- await this.store.set(fullKey, record);
131
- throw error;
132
- }
133
- }
134
- /**
135
- * Check if operation with key was already completed
136
- */
137
- async wasCompleted(key) {
138
- const fullKey = key.startsWith(this.prefix) ? key : `${this.prefix}${key}`;
139
- return (await this.store.get(fullKey))?.status === "completed";
140
- }
141
- /**
142
- * Get cached result for key
143
- */
144
- async getCached(key) {
145
- const fullKey = key.startsWith(this.prefix) ? key : `${this.prefix}${key}`;
146
- const record = await this.store.get(fullKey);
147
- return record?.status === "completed" ? record.result ?? null : null;
148
- }
149
- /**
150
- * Invalidate a key (force re-execution on next call)
151
- */
152
- async invalidate(key) {
153
- const fullKey = key.startsWith(this.prefix) ? key : `${this.prefix}${key}`;
154
- await this.store.delete(fullKey);
155
- }
156
- /**
157
- * Destroy the idempotency manager and cleanup resources
158
- * Call this when shutting down to prevent memory leaks
159
- */
160
- destroy() {
161
- if (this.store instanceof MemoryIdempotencyStore) this.store.destroy();
162
- }
163
- };
164
- /**
165
- * Create idempotency manager
166
- */
167
- function createIdempotencyManager(config) {
168
- return new IdempotencyManager(config);
169
- }
170
-
171
- //#endregion
172
- export { createIdempotencyManager as n, IdempotencyManager as t };