@classytic/revenue 0.2.4 → 1.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.
- package/README.md +498 -501
- package/dist/actions-CwG-b7fR.d.ts +519 -0
- package/dist/core/index.d.ts +884 -0
- package/dist/core/index.js +2941 -0
- package/dist/core/index.js.map +1 -0
- package/dist/enums/index.d.ts +130 -0
- package/dist/enums/index.js +167 -0
- package/dist/enums/index.js.map +1 -0
- package/dist/index-BnJWVXuw.d.ts +378 -0
- package/dist/index-ChVD3P9k.d.ts +504 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +4353 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/index.d.ts +132 -0
- package/dist/providers/index.js +122 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/retry-80lBCmSe.d.ts +234 -0
- package/dist/schemas/index.d.ts +894 -0
- package/dist/schemas/index.js +524 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/validation.d.ts +309 -0
- package/dist/schemas/validation.js +249 -0
- package/dist/schemas/validation.js.map +1 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.js +1632 -0
- package/dist/services/index.js.map +1 -0
- package/dist/split.enums-DHdM1YAV.d.ts +255 -0
- package/dist/split.schema-BPdFZMbU.d.ts +958 -0
- package/dist/utils/index.d.ts +24 -0
- package/dist/utils/index.js +1067 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +48 -32
- package/core/builder.js +0 -219
- package/core/container.js +0 -119
- package/core/errors.js +0 -262
- package/dist/types/core/builder.d.ts +0 -97
- package/dist/types/core/container.d.ts +0 -57
- package/dist/types/core/errors.d.ts +0 -122
- package/dist/types/enums/escrow.enums.d.ts +0 -24
- package/dist/types/enums/index.d.ts +0 -69
- package/dist/types/enums/monetization.enums.d.ts +0 -6
- package/dist/types/enums/payment.enums.d.ts +0 -16
- package/dist/types/enums/split.enums.d.ts +0 -25
- package/dist/types/enums/subscription.enums.d.ts +0 -15
- package/dist/types/enums/transaction.enums.d.ts +0 -24
- package/dist/types/index.d.ts +0 -22
- package/dist/types/providers/base.d.ts +0 -128
- package/dist/types/schemas/escrow/hold.schema.d.ts +0 -54
- package/dist/types/schemas/escrow/index.d.ts +0 -6
- package/dist/types/schemas/index.d.ts +0 -506
- package/dist/types/schemas/split/index.d.ts +0 -8
- package/dist/types/schemas/split/split.schema.d.ts +0 -142
- package/dist/types/schemas/subscription/index.d.ts +0 -152
- package/dist/types/schemas/subscription/info.schema.d.ts +0 -128
- package/dist/types/schemas/subscription/plan.schema.d.ts +0 -39
- package/dist/types/schemas/transaction/common.schema.d.ts +0 -12
- package/dist/types/schemas/transaction/gateway.schema.d.ts +0 -86
- package/dist/types/schemas/transaction/index.d.ts +0 -202
- package/dist/types/schemas/transaction/payment.schema.d.ts +0 -145
- package/dist/types/services/escrow.service.d.ts +0 -51
- package/dist/types/services/monetization.service.d.ts +0 -193
- package/dist/types/services/payment.service.d.ts +0 -117
- package/dist/types/services/transaction.service.d.ts +0 -40
- package/dist/types/utils/category-resolver.d.ts +0 -46
- package/dist/types/utils/commission-split.d.ts +0 -56
- package/dist/types/utils/commission.d.ts +0 -29
- package/dist/types/utils/hooks.d.ts +0 -17
- package/dist/types/utils/index.d.ts +0 -6
- package/dist/types/utils/logger.d.ts +0 -12
- package/dist/types/utils/subscription/actions.d.ts +0 -28
- package/dist/types/utils/subscription/index.d.ts +0 -2
- package/dist/types/utils/subscription/period.d.ts +0 -47
- package/dist/types/utils/transaction-type.d.ts +0 -102
- package/enums/escrow.enums.js +0 -36
- package/enums/index.d.ts +0 -116
- package/enums/index.js +0 -110
- package/enums/monetization.enums.js +0 -15
- package/enums/payment.enums.js +0 -64
- package/enums/split.enums.js +0 -37
- package/enums/subscription.enums.js +0 -33
- package/enums/transaction.enums.js +0 -69
- package/index.js +0 -76
- package/providers/base.js +0 -162
- package/schemas/escrow/hold.schema.js +0 -62
- package/schemas/escrow/index.js +0 -15
- package/schemas/index.d.ts +0 -33
- package/schemas/index.js +0 -27
- package/schemas/split/index.js +0 -16
- package/schemas/split/split.schema.js +0 -86
- package/schemas/subscription/index.js +0 -17
- package/schemas/subscription/info.schema.js +0 -115
- package/schemas/subscription/plan.schema.js +0 -48
- package/schemas/transaction/common.schema.js +0 -22
- package/schemas/transaction/gateway.schema.js +0 -69
- package/schemas/transaction/index.js +0 -20
- package/schemas/transaction/payment.schema.js +0 -110
- package/services/escrow.service.js +0 -353
- package/services/monetization.service.js +0 -675
- package/services/payment.service.js +0 -535
- package/services/transaction.service.js +0 -142
- package/utils/category-resolver.js +0 -74
- package/utils/commission-split.js +0 -180
- package/utils/commission.js +0 -83
- package/utils/hooks.js +0 -44
- package/utils/index.d.ts +0 -164
- package/utils/index.js +0 -16
- package/utils/logger.js +0 -36
- package/utils/subscription/actions.js +0 -68
- package/utils/subscription/index.js +0 -20
- package/utils/subscription/period.js +0 -123
- package/utils/transaction-type.js +0 -254
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
export { z };
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Zod Validation Schemas
|
|
6
|
+
* @classytic/revenue
|
|
7
|
+
*
|
|
8
|
+
* Runtime validation with TypeScript inference
|
|
9
|
+
* Using Zod v4 - Modern schema validation
|
|
10
|
+
*
|
|
11
|
+
* Inspired by: tRPC, Zod best practices
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* MongoDB ObjectId pattern
|
|
16
|
+
*/
|
|
17
|
+
declare const ObjectIdSchema: z.ZodString;
|
|
18
|
+
/**
|
|
19
|
+
* Currency code (ISO 4217)
|
|
20
|
+
*/
|
|
21
|
+
declare const CurrencySchema: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
|
|
22
|
+
/**
|
|
23
|
+
* Money amount in smallest unit (cents, paisa)
|
|
24
|
+
*/
|
|
25
|
+
declare const MoneyAmountSchema: z.ZodNumber;
|
|
26
|
+
/**
|
|
27
|
+
* Money object
|
|
28
|
+
*/
|
|
29
|
+
declare const MoneySchema: z.ZodObject<{
|
|
30
|
+
amount: z.ZodNumber;
|
|
31
|
+
currency: z.ZodDefault<z.ZodString>;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
/**
|
|
34
|
+
* Email address
|
|
35
|
+
*/
|
|
36
|
+
declare const EmailSchema: z.ZodString;
|
|
37
|
+
/**
|
|
38
|
+
* Idempotency key (optional, auto-generated if not provided)
|
|
39
|
+
*/
|
|
40
|
+
declare const IdempotencyKeySchema: z.ZodOptional<z.ZodString>;
|
|
41
|
+
/**
|
|
42
|
+
* Metadata object - Zod v4 record syntax
|
|
43
|
+
*/
|
|
44
|
+
declare const MetadataSchema: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
45
|
+
/**
|
|
46
|
+
* Create payment intent params
|
|
47
|
+
*/
|
|
48
|
+
declare const CreatePaymentSchema: z.ZodObject<{
|
|
49
|
+
amount: z.ZodNumber;
|
|
50
|
+
currency: z.ZodDefault<z.ZodString>;
|
|
51
|
+
customerId: z.ZodString;
|
|
52
|
+
organizationId: z.ZodString;
|
|
53
|
+
provider: z.ZodString;
|
|
54
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
55
|
+
description: z.ZodOptional<z.ZodString>;
|
|
56
|
+
metadata: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
57
|
+
successUrl: z.ZodOptional<z.ZodString>;
|
|
58
|
+
cancelUrl: z.ZodOptional<z.ZodString>;
|
|
59
|
+
}, z.core.$strip>;
|
|
60
|
+
type CreatePaymentInput = z.infer<typeof CreatePaymentSchema>;
|
|
61
|
+
/**
|
|
62
|
+
* Verify payment params
|
|
63
|
+
*/
|
|
64
|
+
declare const VerifyPaymentSchema: z.ZodObject<{
|
|
65
|
+
id: z.ZodString;
|
|
66
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
67
|
+
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
68
|
+
}, z.core.$strip>;
|
|
69
|
+
type VerifyPaymentInput = z.infer<typeof VerifyPaymentSchema>;
|
|
70
|
+
/**
|
|
71
|
+
* Refund params
|
|
72
|
+
*/
|
|
73
|
+
declare const RefundSchema: z.ZodObject<{
|
|
74
|
+
transactionId: z.ZodString;
|
|
75
|
+
amount: z.ZodOptional<z.ZodNumber>;
|
|
76
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
77
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
78
|
+
metadata: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
79
|
+
}, z.core.$strip>;
|
|
80
|
+
type RefundInput = z.infer<typeof RefundSchema>;
|
|
81
|
+
/**
|
|
82
|
+
* Subscription status
|
|
83
|
+
*/
|
|
84
|
+
declare const SubscriptionStatusSchema: z.ZodEnum<{
|
|
85
|
+
pending: "pending";
|
|
86
|
+
cancelled: "cancelled";
|
|
87
|
+
expired: "expired";
|
|
88
|
+
active: "active";
|
|
89
|
+
paused: "paused";
|
|
90
|
+
past_due: "past_due";
|
|
91
|
+
}>;
|
|
92
|
+
type SubscriptionStatus = z.infer<typeof SubscriptionStatusSchema>;
|
|
93
|
+
/**
|
|
94
|
+
* Subscription interval
|
|
95
|
+
*/
|
|
96
|
+
declare const IntervalSchema: z.ZodEnum<{
|
|
97
|
+
day: "day";
|
|
98
|
+
week: "week";
|
|
99
|
+
month: "month";
|
|
100
|
+
year: "year";
|
|
101
|
+
one_time: "one_time";
|
|
102
|
+
}>;
|
|
103
|
+
type Interval = z.infer<typeof IntervalSchema>;
|
|
104
|
+
/**
|
|
105
|
+
* Create subscription params
|
|
106
|
+
*/
|
|
107
|
+
declare const CreateSubscriptionSchema: z.ZodObject<{
|
|
108
|
+
customerId: z.ZodString;
|
|
109
|
+
organizationId: z.ZodString;
|
|
110
|
+
planKey: z.ZodString;
|
|
111
|
+
amount: z.ZodNumber;
|
|
112
|
+
currency: z.ZodDefault<z.ZodString>;
|
|
113
|
+
interval: z.ZodDefault<z.ZodEnum<{
|
|
114
|
+
day: "day";
|
|
115
|
+
week: "week";
|
|
116
|
+
month: "month";
|
|
117
|
+
year: "year";
|
|
118
|
+
one_time: "one_time";
|
|
119
|
+
}>>;
|
|
120
|
+
intervalCount: z.ZodDefault<z.ZodNumber>;
|
|
121
|
+
provider: z.ZodString;
|
|
122
|
+
referenceId: z.ZodOptional<z.ZodString>;
|
|
123
|
+
referenceModel: z.ZodOptional<z.ZodString>;
|
|
124
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
125
|
+
metadata: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
126
|
+
trialDays: z.ZodOptional<z.ZodNumber>;
|
|
127
|
+
}, z.core.$strip>;
|
|
128
|
+
type CreateSubscriptionInput = z.infer<typeof CreateSubscriptionSchema>;
|
|
129
|
+
/**
|
|
130
|
+
* Cancel subscription params
|
|
131
|
+
*/
|
|
132
|
+
declare const CancelSubscriptionSchema: z.ZodObject<{
|
|
133
|
+
subscriptionId: z.ZodString;
|
|
134
|
+
immediate: z.ZodDefault<z.ZodBoolean>;
|
|
135
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
136
|
+
}, z.core.$strip>;
|
|
137
|
+
type CancelSubscriptionInput = z.infer<typeof CancelSubscriptionSchema>;
|
|
138
|
+
/**
|
|
139
|
+
* Monetization type
|
|
140
|
+
*/
|
|
141
|
+
declare const MonetizationTypeSchema: z.ZodEnum<{
|
|
142
|
+
free: "free";
|
|
143
|
+
purchase: "purchase";
|
|
144
|
+
subscription: "subscription";
|
|
145
|
+
}>;
|
|
146
|
+
type MonetizationType = z.infer<typeof MonetizationTypeSchema>;
|
|
147
|
+
/**
|
|
148
|
+
* Create monetization params (unified API)
|
|
149
|
+
*/
|
|
150
|
+
declare const CreateMonetizationSchema: z.ZodObject<{
|
|
151
|
+
type: z.ZodDefault<z.ZodEnum<{
|
|
152
|
+
free: "free";
|
|
153
|
+
purchase: "purchase";
|
|
154
|
+
subscription: "subscription";
|
|
155
|
+
}>>;
|
|
156
|
+
amount: z.ZodOptional<z.ZodNumber>;
|
|
157
|
+
currency: z.ZodDefault<z.ZodString>;
|
|
158
|
+
customerId: z.ZodString;
|
|
159
|
+
organizationId: z.ZodString;
|
|
160
|
+
provider: z.ZodString;
|
|
161
|
+
planKey: z.ZodOptional<z.ZodString>;
|
|
162
|
+
referenceId: z.ZodOptional<z.ZodString>;
|
|
163
|
+
referenceModel: z.ZodOptional<z.ZodString>;
|
|
164
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
165
|
+
metadata: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
166
|
+
interval: z.ZodOptional<z.ZodEnum<{
|
|
167
|
+
day: "day";
|
|
168
|
+
week: "week";
|
|
169
|
+
month: "month";
|
|
170
|
+
year: "year";
|
|
171
|
+
one_time: "one_time";
|
|
172
|
+
}>>;
|
|
173
|
+
trialDays: z.ZodOptional<z.ZodNumber>;
|
|
174
|
+
}, z.core.$strip>;
|
|
175
|
+
type CreateMonetizationInput = z.infer<typeof CreateMonetizationSchema>;
|
|
176
|
+
/**
|
|
177
|
+
* Commission split recipient
|
|
178
|
+
*/
|
|
179
|
+
declare const SplitRecipientSchema: z.ZodObject<{
|
|
180
|
+
recipientId: z.ZodString;
|
|
181
|
+
recipientType: z.ZodDefault<z.ZodString>;
|
|
182
|
+
percentage: z.ZodNumber;
|
|
183
|
+
role: z.ZodOptional<z.ZodString>;
|
|
184
|
+
}, z.core.$strip>;
|
|
185
|
+
type SplitRecipient = z.infer<typeof SplitRecipientSchema>;
|
|
186
|
+
/**
|
|
187
|
+
* Commission configuration
|
|
188
|
+
*/
|
|
189
|
+
declare const CommissionConfigSchema: z.ZodObject<{
|
|
190
|
+
platformRate: z.ZodDefault<z.ZodNumber>;
|
|
191
|
+
gatewayFeeRate: z.ZodDefault<z.ZodNumber>;
|
|
192
|
+
gatewayFixedFee: z.ZodDefault<z.ZodNumber>;
|
|
193
|
+
splits: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
194
|
+
recipientId: z.ZodString;
|
|
195
|
+
recipientType: z.ZodDefault<z.ZodString>;
|
|
196
|
+
percentage: z.ZodNumber;
|
|
197
|
+
role: z.ZodOptional<z.ZodString>;
|
|
198
|
+
}, z.core.$strip>>>;
|
|
199
|
+
affiliate: z.ZodOptional<z.ZodObject<{
|
|
200
|
+
recipientId: z.ZodString;
|
|
201
|
+
recipientType: z.ZodDefault<z.ZodString>;
|
|
202
|
+
rate: z.ZodNumber;
|
|
203
|
+
}, z.core.$strip>>;
|
|
204
|
+
}, z.core.$strip>;
|
|
205
|
+
type CommissionConfig = z.infer<typeof CommissionConfigSchema>;
|
|
206
|
+
/**
|
|
207
|
+
* Hold status
|
|
208
|
+
*/
|
|
209
|
+
declare const HoldStatusSchema: z.ZodEnum<{
|
|
210
|
+
cancelled: "cancelled";
|
|
211
|
+
held: "held";
|
|
212
|
+
released: "released";
|
|
213
|
+
none: "none";
|
|
214
|
+
partial_release: "partial_release";
|
|
215
|
+
}>;
|
|
216
|
+
type HoldStatus = z.infer<typeof HoldStatusSchema>;
|
|
217
|
+
/**
|
|
218
|
+
* Create hold params
|
|
219
|
+
*/
|
|
220
|
+
declare const CreateHoldSchema: z.ZodObject<{
|
|
221
|
+
transactionId: z.ZodString;
|
|
222
|
+
amount: z.ZodOptional<z.ZodNumber>;
|
|
223
|
+
holdUntil: z.ZodOptional<z.ZodDate>;
|
|
224
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
225
|
+
}, z.core.$strip>;
|
|
226
|
+
type CreateHoldInput = z.infer<typeof CreateHoldSchema>;
|
|
227
|
+
/**
|
|
228
|
+
* Release hold params
|
|
229
|
+
*/
|
|
230
|
+
declare const ReleaseHoldSchema: z.ZodObject<{
|
|
231
|
+
transactionId: z.ZodString;
|
|
232
|
+
amount: z.ZodOptional<z.ZodNumber>;
|
|
233
|
+
recipientId: z.ZodString;
|
|
234
|
+
recipientType: z.ZodDefault<z.ZodString>;
|
|
235
|
+
notes: z.ZodOptional<z.ZodString>;
|
|
236
|
+
}, z.core.$strip>;
|
|
237
|
+
type ReleaseHoldInput = z.infer<typeof ReleaseHoldSchema>;
|
|
238
|
+
/**
|
|
239
|
+
* Provider configuration
|
|
240
|
+
*/
|
|
241
|
+
declare const ProviderConfigSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
242
|
+
/**
|
|
243
|
+
* Retry configuration
|
|
244
|
+
*/
|
|
245
|
+
declare const RetryConfigSchema: z.ZodObject<{
|
|
246
|
+
maxAttempts: z.ZodDefault<z.ZodNumber>;
|
|
247
|
+
baseDelay: z.ZodDefault<z.ZodNumber>;
|
|
248
|
+
maxDelay: z.ZodDefault<z.ZodNumber>;
|
|
249
|
+
backoffMultiplier: z.ZodDefault<z.ZodNumber>;
|
|
250
|
+
jitter: z.ZodDefault<z.ZodNumber>;
|
|
251
|
+
}, z.core.$strip>;
|
|
252
|
+
type RetryConfig = z.infer<typeof RetryConfigSchema>;
|
|
253
|
+
/**
|
|
254
|
+
* Revenue configuration
|
|
255
|
+
*/
|
|
256
|
+
declare const RevenueConfigSchema: z.ZodObject<{
|
|
257
|
+
defaultCurrency: z.ZodDefault<z.ZodString>;
|
|
258
|
+
commission: z.ZodOptional<z.ZodObject<{
|
|
259
|
+
platformRate: z.ZodDefault<z.ZodNumber>;
|
|
260
|
+
gatewayFeeRate: z.ZodDefault<z.ZodNumber>;
|
|
261
|
+
gatewayFixedFee: z.ZodDefault<z.ZodNumber>;
|
|
262
|
+
splits: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
263
|
+
recipientId: z.ZodString;
|
|
264
|
+
recipientType: z.ZodDefault<z.ZodString>;
|
|
265
|
+
percentage: z.ZodNumber;
|
|
266
|
+
role: z.ZodOptional<z.ZodString>;
|
|
267
|
+
}, z.core.$strip>>>;
|
|
268
|
+
affiliate: z.ZodOptional<z.ZodObject<{
|
|
269
|
+
recipientId: z.ZodString;
|
|
270
|
+
recipientType: z.ZodDefault<z.ZodString>;
|
|
271
|
+
rate: z.ZodNumber;
|
|
272
|
+
}, z.core.$strip>>;
|
|
273
|
+
}, z.core.$strip>>;
|
|
274
|
+
retry: z.ZodOptional<z.ZodObject<{
|
|
275
|
+
maxAttempts: z.ZodDefault<z.ZodNumber>;
|
|
276
|
+
baseDelay: z.ZodDefault<z.ZodNumber>;
|
|
277
|
+
maxDelay: z.ZodDefault<z.ZodNumber>;
|
|
278
|
+
backoffMultiplier: z.ZodDefault<z.ZodNumber>;
|
|
279
|
+
jitter: z.ZodDefault<z.ZodNumber>;
|
|
280
|
+
}, z.core.$strip>>;
|
|
281
|
+
debug: z.ZodDefault<z.ZodBoolean>;
|
|
282
|
+
environment: z.ZodDefault<z.ZodEnum<{
|
|
283
|
+
development: "development";
|
|
284
|
+
staging: "staging";
|
|
285
|
+
production: "production";
|
|
286
|
+
}>>;
|
|
287
|
+
}, z.core.$strip>;
|
|
288
|
+
type RevenueConfigInput = z.infer<typeof RevenueConfigSchema>;
|
|
289
|
+
/**
|
|
290
|
+
* Validate input against schema
|
|
291
|
+
*/
|
|
292
|
+
declare function validate<T extends z.ZodType>(schema: T, data: unknown): z.infer<T>;
|
|
293
|
+
/**
|
|
294
|
+
* Safe validate (returns result, doesn't throw)
|
|
295
|
+
*/
|
|
296
|
+
declare function safeValidate<T extends z.ZodType>(schema: T, data: unknown): {
|
|
297
|
+
success: true;
|
|
298
|
+
data: z.infer<T>;
|
|
299
|
+
} | {
|
|
300
|
+
success: false;
|
|
301
|
+
error: z.ZodError;
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* Format Zod error for display
|
|
305
|
+
* Zod v4 uses `issues` property
|
|
306
|
+
*/
|
|
307
|
+
declare function formatZodError(error: z.ZodError): string;
|
|
308
|
+
|
|
309
|
+
export { type CancelSubscriptionInput, CancelSubscriptionSchema, type CommissionConfig, CommissionConfigSchema, type CreateHoldInput, CreateHoldSchema, type CreateMonetizationInput, CreateMonetizationSchema, type CreatePaymentInput, CreatePaymentSchema, type CreateSubscriptionInput, CreateSubscriptionSchema, CurrencySchema, EmailSchema, type HoldStatus, HoldStatusSchema, IdempotencyKeySchema, type Interval, IntervalSchema, MetadataSchema, type MonetizationType, MonetizationTypeSchema, MoneyAmountSchema, MoneySchema, ObjectIdSchema, ProviderConfigSchema, type RefundInput, RefundSchema, type ReleaseHoldInput, ReleaseHoldSchema, type RetryConfig, RetryConfigSchema, type RevenueConfigInput, RevenueConfigSchema, type SplitRecipient, SplitRecipientSchema, type SubscriptionStatus, SubscriptionStatusSchema, type VerifyPaymentInput, VerifyPaymentSchema, formatZodError, safeValidate, validate };
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
export { z };
|
|
3
|
+
|
|
4
|
+
// @classytic/revenue - Enterprise Revenue Management System
|
|
5
|
+
|
|
6
|
+
var ObjectIdSchema = z.string().regex(
|
|
7
|
+
/^[a-fA-F0-9]{24}$/,
|
|
8
|
+
"Invalid ObjectId format"
|
|
9
|
+
);
|
|
10
|
+
var CurrencySchema = z.string().length(3, "Currency must be 3 characters").transform((val) => val.toUpperCase()).default("USD");
|
|
11
|
+
var MoneyAmountSchema = z.number().int("Amount must be integer (smallest unit)").nonnegative("Amount cannot be negative");
|
|
12
|
+
var MoneySchema = z.object({
|
|
13
|
+
amount: MoneyAmountSchema,
|
|
14
|
+
currency: z.string().length(3).default("USD")
|
|
15
|
+
});
|
|
16
|
+
var EmailSchema = z.string().email();
|
|
17
|
+
var IdempotencyKeySchema = z.string().min(1).max(255).optional();
|
|
18
|
+
var MetadataSchema = z.record(z.string(), z.unknown()).optional().default({});
|
|
19
|
+
var CreatePaymentSchema = z.object({
|
|
20
|
+
/** Amount in smallest currency unit (cents) */
|
|
21
|
+
amount: MoneyAmountSchema,
|
|
22
|
+
/** ISO 4217 currency code */
|
|
23
|
+
currency: z.string().length(3).default("USD"),
|
|
24
|
+
/** Customer identifier */
|
|
25
|
+
customerId: z.string().min(1, "Customer ID is required"),
|
|
26
|
+
/** Organization/merchant identifier */
|
|
27
|
+
organizationId: z.string().min(1, "Organization ID is required"),
|
|
28
|
+
/** Payment provider to use */
|
|
29
|
+
provider: z.string().min(1, "Provider is required"),
|
|
30
|
+
/** Idempotency key for safe retries */
|
|
31
|
+
idempotencyKey: IdempotencyKeySchema,
|
|
32
|
+
/** Description of the payment */
|
|
33
|
+
description: z.string().optional(),
|
|
34
|
+
/** Additional metadata */
|
|
35
|
+
metadata: MetadataSchema,
|
|
36
|
+
/** Success redirect URL */
|
|
37
|
+
successUrl: z.string().url().optional(),
|
|
38
|
+
/** Cancel redirect URL */
|
|
39
|
+
cancelUrl: z.string().url().optional()
|
|
40
|
+
});
|
|
41
|
+
var VerifyPaymentSchema = z.object({
|
|
42
|
+
/** Transaction ID or payment intent ID */
|
|
43
|
+
id: z.string().min(1),
|
|
44
|
+
/** Provider name (optional, auto-detected) */
|
|
45
|
+
provider: z.string().optional(),
|
|
46
|
+
/** Additional verification data */
|
|
47
|
+
data: z.record(z.string(), z.unknown()).optional()
|
|
48
|
+
});
|
|
49
|
+
var RefundSchema = z.object({
|
|
50
|
+
/** Transaction ID to refund */
|
|
51
|
+
transactionId: z.string().min(1),
|
|
52
|
+
/** Amount to refund (optional, full refund if not provided) */
|
|
53
|
+
amount: MoneyAmountSchema.optional(),
|
|
54
|
+
/** Reason for refund */
|
|
55
|
+
reason: z.string().optional(),
|
|
56
|
+
/** Idempotency key */
|
|
57
|
+
idempotencyKey: IdempotencyKeySchema,
|
|
58
|
+
/** Additional metadata */
|
|
59
|
+
metadata: MetadataSchema
|
|
60
|
+
});
|
|
61
|
+
var SubscriptionStatusSchema = z.enum([
|
|
62
|
+
"pending",
|
|
63
|
+
"active",
|
|
64
|
+
"paused",
|
|
65
|
+
"cancelled",
|
|
66
|
+
"expired",
|
|
67
|
+
"past_due"
|
|
68
|
+
]);
|
|
69
|
+
var IntervalSchema = z.enum([
|
|
70
|
+
"day",
|
|
71
|
+
"week",
|
|
72
|
+
"month",
|
|
73
|
+
"year",
|
|
74
|
+
"one_time"
|
|
75
|
+
]);
|
|
76
|
+
var CreateSubscriptionSchema = z.object({
|
|
77
|
+
/** Customer ID */
|
|
78
|
+
customerId: z.string().min(1),
|
|
79
|
+
/** Organization ID */
|
|
80
|
+
organizationId: z.string().min(1),
|
|
81
|
+
/** Plan identifier */
|
|
82
|
+
planKey: z.string().min(1),
|
|
83
|
+
/** Amount per period (smallest unit) */
|
|
84
|
+
amount: MoneyAmountSchema,
|
|
85
|
+
/** Currency */
|
|
86
|
+
currency: z.string().length(3).default("USD"),
|
|
87
|
+
/** Billing interval */
|
|
88
|
+
interval: IntervalSchema.default("month"),
|
|
89
|
+
/** Interval count (e.g., 2 for bi-monthly) */
|
|
90
|
+
intervalCount: z.number().int().positive().default(1),
|
|
91
|
+
/** Payment provider */
|
|
92
|
+
provider: z.string().min(1),
|
|
93
|
+
/** Reference to external entity */
|
|
94
|
+
referenceId: z.string().optional(),
|
|
95
|
+
/** Reference model name */
|
|
96
|
+
referenceModel: z.string().optional(),
|
|
97
|
+
/** Idempotency key */
|
|
98
|
+
idempotencyKey: IdempotencyKeySchema,
|
|
99
|
+
/** Metadata */
|
|
100
|
+
metadata: MetadataSchema,
|
|
101
|
+
/** Trial period in days */
|
|
102
|
+
trialDays: z.number().int().nonnegative().optional()
|
|
103
|
+
});
|
|
104
|
+
var CancelSubscriptionSchema = z.object({
|
|
105
|
+
/** Subscription ID */
|
|
106
|
+
subscriptionId: z.string().min(1),
|
|
107
|
+
/** Cancel immediately or at period end */
|
|
108
|
+
immediate: z.boolean().default(false),
|
|
109
|
+
/** Cancellation reason */
|
|
110
|
+
reason: z.string().optional()
|
|
111
|
+
});
|
|
112
|
+
var MonetizationTypeSchema = z.enum([
|
|
113
|
+
"purchase",
|
|
114
|
+
"subscription",
|
|
115
|
+
"free"
|
|
116
|
+
]);
|
|
117
|
+
var CreateMonetizationSchema = z.object({
|
|
118
|
+
/** Type of monetization */
|
|
119
|
+
type: MonetizationTypeSchema.default("purchase"),
|
|
120
|
+
/** Amount (smallest unit) - required for purchase/subscription */
|
|
121
|
+
amount: MoneyAmountSchema.optional(),
|
|
122
|
+
/** Currency */
|
|
123
|
+
currency: z.string().length(3).default("USD"),
|
|
124
|
+
/** Customer ID */
|
|
125
|
+
customerId: z.string().min(1),
|
|
126
|
+
/** Organization ID */
|
|
127
|
+
organizationId: z.string().min(1),
|
|
128
|
+
/** Payment provider */
|
|
129
|
+
provider: z.string().min(1),
|
|
130
|
+
/** Plan key for categorization */
|
|
131
|
+
planKey: z.string().optional(),
|
|
132
|
+
/** Reference ID */
|
|
133
|
+
referenceId: z.string().optional(),
|
|
134
|
+
/** Reference model */
|
|
135
|
+
referenceModel: z.string().optional(),
|
|
136
|
+
/** Idempotency key */
|
|
137
|
+
idempotencyKey: IdempotencyKeySchema,
|
|
138
|
+
/** Metadata */
|
|
139
|
+
metadata: MetadataSchema,
|
|
140
|
+
/** Subscription-specific: interval */
|
|
141
|
+
interval: IntervalSchema.optional(),
|
|
142
|
+
/** Subscription-specific: trial days */
|
|
143
|
+
trialDays: z.number().int().nonnegative().optional()
|
|
144
|
+
}).refine(
|
|
145
|
+
(data) => {
|
|
146
|
+
if (data.type !== "free" && !data.amount) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
},
|
|
151
|
+
{ message: "Amount is required for non-free monetization types" }
|
|
152
|
+
);
|
|
153
|
+
var SplitRecipientSchema = z.object({
|
|
154
|
+
/** Recipient ID */
|
|
155
|
+
recipientId: z.string().min(1),
|
|
156
|
+
/** Recipient type (user, organization, etc.) */
|
|
157
|
+
recipientType: z.string().default("user"),
|
|
158
|
+
/** Percentage of net amount (0-100) */
|
|
159
|
+
percentage: z.number().min(0).max(100),
|
|
160
|
+
/** Role description */
|
|
161
|
+
role: z.string().optional()
|
|
162
|
+
});
|
|
163
|
+
var CommissionConfigSchema = z.object({
|
|
164
|
+
/** Platform commission rate (0-100) */
|
|
165
|
+
platformRate: z.number().min(0).max(100).default(0),
|
|
166
|
+
/** Gateway fee rate (0-100) */
|
|
167
|
+
gatewayFeeRate: z.number().min(0).max(100).default(0),
|
|
168
|
+
/** Fixed gateway fee (smallest unit) */
|
|
169
|
+
gatewayFixedFee: MoneyAmountSchema.default(0),
|
|
170
|
+
/** Split recipients */
|
|
171
|
+
splits: z.array(SplitRecipientSchema).optional(),
|
|
172
|
+
/** Affiliate configuration */
|
|
173
|
+
affiliate: z.object({
|
|
174
|
+
recipientId: z.string(),
|
|
175
|
+
recipientType: z.string().default("user"),
|
|
176
|
+
rate: z.number().min(0).max(100)
|
|
177
|
+
}).optional()
|
|
178
|
+
});
|
|
179
|
+
var HoldStatusSchema = z.enum([
|
|
180
|
+
"none",
|
|
181
|
+
"held",
|
|
182
|
+
"partial_release",
|
|
183
|
+
"released",
|
|
184
|
+
"cancelled"
|
|
185
|
+
]);
|
|
186
|
+
var CreateHoldSchema = z.object({
|
|
187
|
+
/** Transaction ID */
|
|
188
|
+
transactionId: z.string().min(1),
|
|
189
|
+
/** Hold amount (optional, defaults to full transaction amount) */
|
|
190
|
+
amount: MoneyAmountSchema.optional(),
|
|
191
|
+
/** Hold until date */
|
|
192
|
+
holdUntil: z.date().optional(),
|
|
193
|
+
/** Reason for hold */
|
|
194
|
+
reason: z.string().optional()
|
|
195
|
+
});
|
|
196
|
+
var ReleaseHoldSchema = z.object({
|
|
197
|
+
/** Transaction ID */
|
|
198
|
+
transactionId: z.string().min(1),
|
|
199
|
+
/** Amount to release (optional, full release if not provided) */
|
|
200
|
+
amount: MoneyAmountSchema.optional(),
|
|
201
|
+
/** Recipient ID */
|
|
202
|
+
recipientId: z.string().min(1),
|
|
203
|
+
/** Recipient type */
|
|
204
|
+
recipientType: z.string().default("user"),
|
|
205
|
+
/** Release notes */
|
|
206
|
+
notes: z.string().optional()
|
|
207
|
+
});
|
|
208
|
+
var ProviderConfigSchema = z.record(z.string(), z.unknown());
|
|
209
|
+
var RetryConfigSchema = z.object({
|
|
210
|
+
/** Maximum retry attempts */
|
|
211
|
+
maxAttempts: z.number().int().positive().default(3),
|
|
212
|
+
/** Base delay in ms */
|
|
213
|
+
baseDelay: z.number().positive().default(1e3),
|
|
214
|
+
/** Maximum delay in ms */
|
|
215
|
+
maxDelay: z.number().positive().default(3e4),
|
|
216
|
+
/** Backoff multiplier */
|
|
217
|
+
backoffMultiplier: z.number().positive().default(2),
|
|
218
|
+
/** Jitter factor (0-1) */
|
|
219
|
+
jitter: z.number().min(0).max(1).default(0.1)
|
|
220
|
+
});
|
|
221
|
+
var RevenueConfigSchema = z.object({
|
|
222
|
+
/** Default currency */
|
|
223
|
+
defaultCurrency: z.string().length(3).default("USD"),
|
|
224
|
+
/** Commission configuration */
|
|
225
|
+
commission: CommissionConfigSchema.optional(),
|
|
226
|
+
/** Retry configuration */
|
|
227
|
+
retry: RetryConfigSchema.optional(),
|
|
228
|
+
/** Enable debug logging */
|
|
229
|
+
debug: z.boolean().default(false),
|
|
230
|
+
/** Environment */
|
|
231
|
+
environment: z.enum(["development", "staging", "production"]).default("development")
|
|
232
|
+
});
|
|
233
|
+
function validate(schema, data) {
|
|
234
|
+
return schema.parse(data);
|
|
235
|
+
}
|
|
236
|
+
function safeValidate(schema, data) {
|
|
237
|
+
const result = schema.safeParse(data);
|
|
238
|
+
if (result.success) {
|
|
239
|
+
return { success: true, data: result.data };
|
|
240
|
+
}
|
|
241
|
+
return { success: false, error: result.error };
|
|
242
|
+
}
|
|
243
|
+
function formatZodError(error) {
|
|
244
|
+
return error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join(", ");
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export { CancelSubscriptionSchema, CommissionConfigSchema, CreateHoldSchema, CreateMonetizationSchema, CreatePaymentSchema, CreateSubscriptionSchema, CurrencySchema, EmailSchema, HoldStatusSchema, IdempotencyKeySchema, IntervalSchema, MetadataSchema, MonetizationTypeSchema, MoneyAmountSchema, MoneySchema, ObjectIdSchema, ProviderConfigSchema, RefundSchema, ReleaseHoldSchema, RetryConfigSchema, RevenueConfigSchema, SplitRecipientSchema, SubscriptionStatusSchema, VerifyPaymentSchema, formatZodError, safeValidate, validate };
|
|
248
|
+
//# sourceMappingURL=validation.js.map
|
|
249
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/schemas/validation.ts"],"names":[],"mappings":";;;;;AAiBO,IAAM,cAAA,GAAmB,UAAO,CAAE,KAAA;AAAA,EACvC,mBAAA;AAAA,EACA;AACF;AAKO,IAAM,cAAA,GAAmB,CAAA,CAAA,MAAA,EAAO,CACpC,MAAA,CAAO,GAAG,+BAA+B,CAAA,CACzC,SAAA,CAAU,CAAA,GAAA,KAAO,GAAA,CAAI,WAAA,EAAa,CAAA,CAClC,QAAQ,KAAK;AAKT,IAAM,oBAAsB,CAAA,CAAA,MAAA,EAAO,CACvC,IAAI,wCAAwC,CAAA,CAC5C,YAAY,2BAA2B;AAKnC,IAAM,cAAgB,CAAA,CAAA,MAAA,CAAO;AAAA,EAClC,MAAA,EAAQ,iBAAA;AAAA,EACR,UAAY,CAAA,CAAA,MAAA,EAAO,CAAE,OAAO,CAAC,CAAA,CAAE,QAAQ,KAAK;AAC9C,CAAC;AAKM,IAAM,WAAA,GAAgB,CAAA,CAAA,MAAA,EAAO,CAAE,KAAA;AAK/B,IAAM,oBAAA,GAAyB,UAAO,CAC1C,GAAA,CAAI,CAAC,CAAA,CACL,GAAA,CAAI,GAAG,CAAA,CACP,QAAA;AAKI,IAAM,cAAA,GAAmB,CAAA,CAAA,MAAA,CAAS,CAAA,CAAA,MAAA,EAAO,EAAK,CAAA,CAAA,OAAA,EAAS,CAAA,CAAE,Q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S,CAAA,CAAA,OAAA,EAAQ,CAAE,OAAA,CAAQ,KAAK,CAAA;AAAA;AAAA,EAEhC,WAAA,EAAe,OAAK,CAAC,aAAA,EAAe,WAAW,YAAY,CAAC,CAAA,CAAE,OAAA,CAAQ,aAAa;AACrF,CAAC;AASM,SAAS,QAAA,CACd,QACA,IAAA,EACY;AACZ,EAAA,OAAO,MAAA,CAAO,MAAM,IAAI,CAAA;AAC1B;AAKO,SAAS,YAAA,CACd,QACA,IAAA,EAC6E;AAC7E,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,SAAA,CAAU,IAAI,CAAA;AACpC,EAAA,IAAI,OAAO,OAAA,EAAS;AAClB,IAAA,OAAO,EAAE,OAAA,EAAS,IAAA,EAAM,IAAA,EAAM,OAAO,IAAA,EAAK;AAAA,EAC5C;AACA,EAAA,OAAO,EAAE,OAAA,EAAS,KAAA,EAAO,KAAA,EAAO,OAAO,KAAA,EAAM;AAC/C;AAMO,SAAS,eAAe,KAAA,EAA2B;AACxD,EAAA,OAAO,MAAM,MAAA,CACV,GAAA,CAAI,CAAC,KAAA,KAAU,GAAG,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,GAAG,CAAC,CAAA,EAAA,EAAK,KAAA,CAAM,OAAO,CAAA,CAAE,CAAA,CAC1D,KAAK,IAAI,CAAA;AACd","file":"validation.js","sourcesContent":["/**\r\n * Zod Validation Schemas\r\n * @classytic/revenue\r\n *\r\n * Runtime validation with TypeScript inference\r\n * Using Zod v4 - Modern schema validation\r\n *\r\n * Inspired by: tRPC, Zod best practices\r\n */\r\n\r\nimport * as z from 'zod';\r\n\r\n// ============ PRIMITIVE SCHEMAS ============\r\n\r\n/**\r\n * MongoDB ObjectId pattern\r\n */\r\nexport const ObjectIdSchema = z.string().regex(\r\n /^[a-fA-F0-9]{24}$/,\r\n 'Invalid ObjectId format'\r\n);\r\n\r\n/**\r\n * Currency code (ISO 4217)\r\n */\r\nexport const CurrencySchema = z.string()\r\n .length(3, 'Currency must be 3 characters')\r\n .transform(val => val.toUpperCase())\r\n .default('USD');\r\n\r\n/**\r\n * Money amount in smallest unit (cents, paisa)\r\n */\r\nexport const MoneyAmountSchema = z.number()\r\n .int('Amount must be integer (smallest unit)')\r\n .nonnegative('Amount cannot be negative');\r\n\r\n/**\r\n * Money object\r\n */\r\nexport const MoneySchema = z.object({\r\n amount: MoneyAmountSchema,\r\n currency: z.string().length(3).default('USD'),\r\n});\r\n\r\n/**\r\n * Email address\r\n */\r\nexport const EmailSchema = z.string().email();\r\n\r\n/**\r\n * Idempotency key (optional, auto-generated if not provided)\r\n */\r\nexport const IdempotencyKeySchema = z.string()\r\n .min(1)\r\n .max(255)\r\n .optional();\r\n\r\n/**\r\n * Metadata object - Zod v4 record syntax\r\n */\r\nexport const MetadataSchema = z.record(z.string(), z.unknown()).optional().default({});\r\n\r\n// ============ PAYMENT SCHEMAS ============\r\n\r\n/**\r\n * Create payment intent params\r\n */\r\nexport const CreatePaymentSchema = z.object({\r\n /** Amount in smallest currency unit (cents) */\r\n amount: MoneyAmountSchema,\r\n /** ISO 4217 currency code */\r\n currency: z.string().length(3).default('USD'),\r\n /** Customer identifier */\r\n customerId: z.string().min(1, 'Customer ID is required'),\r\n /** Organization/merchant identifier */\r\n organizationId: z.string().min(1, 'Organization ID is required'),\r\n /** Payment provider to use */\r\n provider: z.string().min(1, 'Provider is required'),\r\n /** Idempotency key for safe retries */\r\n idempotencyKey: IdempotencyKeySchema,\r\n /** Description of the payment */\r\n description: z.string().optional(),\r\n /** Additional metadata */\r\n metadata: MetadataSchema,\r\n /** Success redirect URL */\r\n successUrl: z.string().url().optional(),\r\n /** Cancel redirect URL */\r\n cancelUrl: z.string().url().optional(),\r\n});\r\n\r\nexport type CreatePaymentInput = z.infer<typeof CreatePaymentSchema>;\r\n\r\n/**\r\n * Verify payment params\r\n */\r\nexport const VerifyPaymentSchema = z.object({\r\n /** Transaction ID or payment intent ID */\r\n id: z.string().min(1),\r\n /** Provider name (optional, auto-detected) */\r\n provider: z.string().optional(),\r\n /** Additional verification data */\r\n data: z.record(z.string(), z.unknown()).optional(),\r\n});\r\n\r\nexport type VerifyPaymentInput = z.infer<typeof VerifyPaymentSchema>;\r\n\r\n/**\r\n * Refund params\r\n */\r\nexport const RefundSchema = z.object({\r\n /** Transaction ID to refund */\r\n transactionId: z.string().min(1),\r\n /** Amount to refund (optional, full refund if not provided) */\r\n amount: MoneyAmountSchema.optional(),\r\n /** Reason for refund */\r\n reason: z.string().optional(),\r\n /** Idempotency key */\r\n idempotencyKey: IdempotencyKeySchema,\r\n /** Additional metadata */\r\n metadata: MetadataSchema,\r\n});\r\n\r\nexport type RefundInput = z.infer<typeof RefundSchema>;\r\n\r\n// ============ SUBSCRIPTION SCHEMAS ============\r\n\r\n/**\r\n * Subscription status\r\n */\r\nexport const SubscriptionStatusSchema = z.enum([\r\n 'pending',\r\n 'active',\r\n 'paused',\r\n 'cancelled',\r\n 'expired',\r\n 'past_due',\r\n]);\r\n\r\nexport type SubscriptionStatus = z.infer<typeof SubscriptionStatusSchema>;\r\n\r\n/**\r\n * Subscription interval\r\n */\r\nexport const IntervalSchema = z.enum([\r\n 'day',\r\n 'week',\r\n 'month',\r\n 'year',\r\n 'one_time',\r\n]);\r\n\r\nexport type Interval = z.infer<typeof IntervalSchema>;\r\n\r\n/**\r\n * Create subscription params\r\n */\r\nexport const CreateSubscriptionSchema = z.object({\r\n /** Customer ID */\r\n customerId: z.string().min(1),\r\n /** Organization ID */\r\n organizationId: z.string().min(1),\r\n /** Plan identifier */\r\n planKey: z.string().min(1),\r\n /** Amount per period (smallest unit) */\r\n amount: MoneyAmountSchema,\r\n /** Currency */\r\n currency: z.string().length(3).default('USD'),\r\n /** Billing interval */\r\n interval: IntervalSchema.default('month'),\r\n /** Interval count (e.g., 2 for bi-monthly) */\r\n intervalCount: z.number().int().positive().default(1),\r\n /** Payment provider */\r\n provider: z.string().min(1),\r\n /** Reference to external entity */\r\n referenceId: z.string().optional(),\r\n /** Reference model name */\r\n referenceModel: z.string().optional(),\r\n /** Idempotency key */\r\n idempotencyKey: IdempotencyKeySchema,\r\n /** Metadata */\r\n metadata: MetadataSchema,\r\n /** Trial period in days */\r\n trialDays: z.number().int().nonnegative().optional(),\r\n});\r\n\r\nexport type CreateSubscriptionInput = z.infer<typeof CreateSubscriptionSchema>;\r\n\r\n/**\r\n * Cancel subscription params\r\n */\r\nexport const CancelSubscriptionSchema = z.object({\r\n /** Subscription ID */\r\n subscriptionId: z.string().min(1),\r\n /** Cancel immediately or at period end */\r\n immediate: z.boolean().default(false),\r\n /** Cancellation reason */\r\n reason: z.string().optional(),\r\n});\r\n\r\nexport type CancelSubscriptionInput = z.infer<typeof CancelSubscriptionSchema>;\r\n\r\n// ============ MONETIZATION SCHEMAS ============\r\n\r\n/**\r\n * Monetization type\r\n */\r\nexport const MonetizationTypeSchema = z.enum([\r\n 'purchase',\r\n 'subscription',\r\n 'free',\r\n]);\r\n\r\nexport type MonetizationType = z.infer<typeof MonetizationTypeSchema>;\r\n\r\n/**\r\n * Create monetization params (unified API)\r\n */\r\nexport const CreateMonetizationSchema = z.object({\r\n /** Type of monetization */\r\n type: MonetizationTypeSchema.default('purchase'),\r\n /** Amount (smallest unit) - required for purchase/subscription */\r\n amount: MoneyAmountSchema.optional(),\r\n /** Currency */\r\n currency: z.string().length(3).default('USD'),\r\n /** Customer ID */\r\n customerId: z.string().min(1),\r\n /** Organization ID */\r\n organizationId: z.string().min(1),\r\n /** Payment provider */\r\n provider: z.string().min(1),\r\n /** Plan key for categorization */\r\n planKey: z.string().optional(),\r\n /** Reference ID */\r\n referenceId: z.string().optional(),\r\n /** Reference model */\r\n referenceModel: z.string().optional(),\r\n /** Idempotency key */\r\n idempotencyKey: IdempotencyKeySchema,\r\n /** Metadata */\r\n metadata: MetadataSchema,\r\n /** Subscription-specific: interval */\r\n interval: IntervalSchema.optional(),\r\n /** Subscription-specific: trial days */\r\n trialDays: z.number().int().nonnegative().optional(),\r\n}).refine(\r\n (data) => {\r\n if (data.type !== 'free' && !data.amount) {\r\n return false;\r\n }\r\n return true;\r\n },\r\n { message: 'Amount is required for non-free monetization types' }\r\n);\r\n\r\nexport type CreateMonetizationInput = z.infer<typeof CreateMonetizationSchema>;\r\n\r\n// ============ COMMISSION SCHEMAS ============\r\n\r\n/**\r\n * Commission split recipient\r\n */\r\nexport const SplitRecipientSchema = z.object({\r\n /** Recipient ID */\r\n recipientId: z.string().min(1),\r\n /** Recipient type (user, organization, etc.) */\r\n recipientType: z.string().default('user'),\r\n /** Percentage of net amount (0-100) */\r\n percentage: z.number().min(0).max(100),\r\n /** Role description */\r\n role: z.string().optional(),\r\n});\r\n\r\nexport type SplitRecipient = z.infer<typeof SplitRecipientSchema>;\r\n\r\n/**\r\n * Commission configuration\r\n */\r\nexport const CommissionConfigSchema = z.object({\r\n /** Platform commission rate (0-100) */\r\n platformRate: z.number().min(0).max(100).default(0),\r\n /** Gateway fee rate (0-100) */\r\n gatewayFeeRate: z.number().min(0).max(100).default(0),\r\n /** Fixed gateway fee (smallest unit) */\r\n gatewayFixedFee: MoneyAmountSchema.default(0),\r\n /** Split recipients */\r\n splits: z.array(SplitRecipientSchema).optional(),\r\n /** Affiliate configuration */\r\n affiliate: z.object({\r\n recipientId: z.string(),\r\n recipientType: z.string().default('user'),\r\n rate: z.number().min(0).max(100),\r\n }).optional(),\r\n});\r\n\r\nexport type CommissionConfig = z.infer<typeof CommissionConfigSchema>;\r\n\r\n// ============ ESCROW SCHEMAS ============\r\n\r\n/**\r\n * Hold status\r\n */\r\nexport const HoldStatusSchema = z.enum([\r\n 'none',\r\n 'held',\r\n 'partial_release',\r\n 'released',\r\n 'cancelled',\r\n]);\r\n\r\nexport type HoldStatus = z.infer<typeof HoldStatusSchema>;\r\n\r\n/**\r\n * Create hold params\r\n */\r\nexport const CreateHoldSchema = z.object({\r\n /** Transaction ID */\r\n transactionId: z.string().min(1),\r\n /** Hold amount (optional, defaults to full transaction amount) */\r\n amount: MoneyAmountSchema.optional(),\r\n /** Hold until date */\r\n holdUntil: z.date().optional(),\r\n /** Reason for hold */\r\n reason: z.string().optional(),\r\n});\r\n\r\nexport type CreateHoldInput = z.infer<typeof CreateHoldSchema>;\r\n\r\n/**\r\n * Release hold params\r\n */\r\nexport const ReleaseHoldSchema = z.object({\r\n /** Transaction ID */\r\n transactionId: z.string().min(1),\r\n /** Amount to release (optional, full release if not provided) */\r\n amount: MoneyAmountSchema.optional(),\r\n /** Recipient ID */\r\n recipientId: z.string().min(1),\r\n /** Recipient type */\r\n recipientType: z.string().default('user'),\r\n /** Release notes */\r\n notes: z.string().optional(),\r\n});\r\n\r\nexport type ReleaseHoldInput = z.infer<typeof ReleaseHoldSchema>;\r\n\r\n// ============ CONFIG SCHEMAS ============\r\n\r\n/**\r\n * Provider configuration\r\n */\r\nexport const ProviderConfigSchema = z.record(z.string(), z.unknown());\r\n\r\n/**\r\n * Retry configuration\r\n */\r\nexport const RetryConfigSchema = z.object({\r\n /** Maximum retry attempts */\r\n maxAttempts: z.number().int().positive().default(3),\r\n /** Base delay in ms */\r\n baseDelay: z.number().positive().default(1000),\r\n /** Maximum delay in ms */\r\n maxDelay: z.number().positive().default(30000),\r\n /** Backoff multiplier */\r\n backoffMultiplier: z.number().positive().default(2),\r\n /** Jitter factor (0-1) */\r\n jitter: z.number().min(0).max(1).default(0.1),\r\n});\r\n\r\nexport type RetryConfig = z.infer<typeof RetryConfigSchema>;\r\n\r\n/**\r\n * Revenue configuration\r\n */\r\nexport const RevenueConfigSchema = z.object({\r\n /** Default currency */\r\n defaultCurrency: z.string().length(3).default('USD'),\r\n /** Commission configuration */\r\n commission: CommissionConfigSchema.optional(),\r\n /** Retry configuration */\r\n retry: RetryConfigSchema.optional(),\r\n /** Enable debug logging */\r\n debug: z.boolean().default(false),\r\n /** Environment */\r\n environment: z.enum(['development', 'staging', 'production']).default('development'),\r\n});\r\n\r\nexport type RevenueConfigInput = z.infer<typeof RevenueConfigSchema>;\r\n\r\n// ============ VALIDATION HELPERS ============\r\n\r\n/**\r\n * Validate input against schema\r\n */\r\nexport function validate<T extends z.ZodType>(\r\n schema: T,\r\n data: unknown\r\n): z.infer<T> {\r\n return schema.parse(data);\r\n}\r\n\r\n/**\r\n * Safe validate (returns result, doesn't throw)\r\n */\r\nexport function safeValidate<T extends z.ZodType>(\r\n schema: T,\r\n data: unknown\r\n): { success: true; data: z.infer<T> } | { success: false; error: z.ZodError } {\r\n const result = schema.safeParse(data);\r\n if (result.success) {\r\n return { success: true, data: result.data };\r\n }\r\n return { success: false, error: result.error };\r\n}\r\n\r\n/**\r\n * Format Zod error for display\r\n * Zod v4 uses `issues` property\r\n */\r\nexport function formatZodError(error: z.ZodError): string {\r\n return error.issues\r\n .map((issue) => `${issue.path.join('.')}: ${issue.message}`)\r\n .join(', ');\r\n}\r\n\r\nexport { z };\r\n"]}
|