@classytic/revenue 2.1.0 → 2.2.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/CHANGELOG.md +95 -0
- package/README.md +41 -10
- package/dist/{bank-feed-DJtLvz_7.mjs → bank-feed-ClxNob_I.mjs} +1 -1
- package/dist/core/state-machines.mjs +2 -2
- package/dist/{engine-types-txFXOiQS.d.mts → engine-types-ChFPg3kw.d.mts} +230 -80
- package/dist/enums/index.mjs +1 -1
- package/dist/{errors-Dt46UZL_.mjs → errors-Bt5NRVMq.mjs} +19 -2
- package/dist/{escrow.schema-C-b41z_G.mjs → escrow.schema-BcKdzrJ7.mjs} +5 -0
- package/dist/{escrow.schema-9yh4Q-aQ.d.mts → escrow.schema-BdDHuQ8C.d.mts} +80 -20
- package/dist/{event-constants-CTiDNWzc.mjs → event-constants-DM_-A57b.mjs} +7 -0
- package/dist/events/index.d.mts +1 -1
- package/dist/events/index.mjs +2 -2
- package/dist/index.d.mts +38 -7
- package/dist/index.mjs +38 -9
- package/dist/providers/index.mjs +1 -1
- package/dist/repositories/create-repositories.d.mts +1 -1
- package/dist/repositories/create-repositories.mjs +1 -1
- package/dist/{revenue-event-catalog-CgZ57M-f.mjs → revenue-event-catalog-B9aZmNpL.mjs} +90 -2
- package/dist/{revenue-event-catalog-JpJcyK1E.d.mts → revenue-event-catalog-BU_KYN2-.d.mts} +645 -0
- package/dist/{settlement.repository-Ba2U17zY.mjs → settlement.repository-CfvgX3et.mjs} +315 -123
- package/dist/shared/index.mjs +1 -1
- package/dist/validators/index.d.mts +1 -1
- package/dist/validators/index.mjs +1 -1
- package/package.json +7 -7
- /package/dist/{splits-D8XkNWgX.mjs → splits-CNfQj92L.mjs} +0 -0
- /package/dist/{subscription.enums-DoIr56O6.mjs → subscription.enums-95othr0i.mjs} +0 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
//#region src/core/errors.ts
|
|
2
2
|
var RevenueError = class extends Error {
|
|
3
|
-
constructor(message, code, details) {
|
|
3
|
+
constructor(message, code, details, httpStatus) {
|
|
4
4
|
super(message);
|
|
5
5
|
this.code = code;
|
|
6
6
|
this.details = details;
|
|
7
|
+
this.httpStatus = httpStatus;
|
|
7
8
|
this.name = "RevenueError";
|
|
8
9
|
}
|
|
9
10
|
};
|
|
@@ -103,6 +104,22 @@ var WrongTransactionKindError = class extends RevenueError {
|
|
|
103
104
|
this.name = "WrongTransactionKindError";
|
|
104
105
|
}
|
|
105
106
|
};
|
|
107
|
+
/**
|
|
108
|
+
* Thrown by `TransactionRepository.backfillMethodKind` when the existing
|
|
109
|
+
* doc is NOT eligible for backfill (methodKind already specific, or
|
|
110
|
+
* status no longer `'pending'`). 409 because the request is well-formed
|
|
111
|
+
* but conflicts with the current resource state.
|
|
112
|
+
*/
|
|
113
|
+
var MethodKindLockedError = class extends RevenueError {
|
|
114
|
+
constructor(transactionId, currentMethodKind, currentStatus) {
|
|
115
|
+
super(`Transaction '${transactionId}' methodKind is locked (current: '${currentMethodKind}', status: '${currentStatus}'). Backfill is allowed only when methodKind === 'other' AND status === 'pending'.`, "METHOD_KIND_LOCKED", {
|
|
116
|
+
transactionId,
|
|
117
|
+
currentMethodKind,
|
|
118
|
+
currentStatus
|
|
119
|
+
}, 409);
|
|
120
|
+
this.name = "MethodKindLockedError";
|
|
121
|
+
}
|
|
122
|
+
};
|
|
106
123
|
var BankFeedProviderNotFoundError = class extends RevenueError {
|
|
107
124
|
constructor(providerName) {
|
|
108
125
|
super(`Bank-feed provider '${providerName}' not registered. Use \`engine.bankFeedProviders.register(name, provider)\`.`, "BANK_FEED_PROVIDER_NOT_FOUND", { providerName });
|
|
@@ -111,4 +128,4 @@ var BankFeedProviderNotFoundError = class extends RevenueError {
|
|
|
111
128
|
};
|
|
112
129
|
|
|
113
130
|
//#endregion
|
|
114
|
-
export { InvalidStateTransitionError as a,
|
|
131
|
+
export { WrongTransactionKindError as _, InvalidStateTransitionError as a, PaymentVerificationError as c, RefundNotSupportedError as d, RevenueError as f, ValidationError as g, TransactionNotFoundError as h, ConfigurationError as i, ProviderCapabilityError as l, SubscriptionNotFoundError as m, BankFeedImportError as n, MethodKindLockedError as o, SettlementNotFoundError as p, BankFeedProviderNotFoundError as r, PaymentIntentCreationError as s, AlreadyVerifiedError as t, ProviderNotFoundError as u };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { PAYMENT_METHOD_KIND } from "@classytic/primitives/payment-method-kind";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
|
|
3
4
|
//#region src/validators/transaction.schema.ts
|
|
5
|
+
const PAYMENT_METHOD_KIND_VALUES$1 = Object.values(PAYMENT_METHOD_KIND);
|
|
4
6
|
const commissionSchema = z.object({
|
|
5
7
|
rate: z.number().min(0).max(1),
|
|
6
8
|
grossAmount: z.number().int(),
|
|
@@ -78,6 +80,7 @@ const transactionBaseSchema = z.object({
|
|
|
78
80
|
isInclusive: z.boolean().optional()
|
|
79
81
|
}).optional(),
|
|
80
82
|
method: z.string(),
|
|
83
|
+
methodKind: z.enum(PAYMENT_METHOD_KIND_VALUES$1),
|
|
81
84
|
status: z.string().default("pending"),
|
|
82
85
|
gateway: gatewaySchema.optional(),
|
|
83
86
|
paymentDetails: z.record(z.string(), z.unknown()).optional(),
|
|
@@ -265,10 +268,12 @@ const settlementListFilterSchema = z.object({
|
|
|
265
268
|
|
|
266
269
|
//#endregion
|
|
267
270
|
//#region src/validators/payment.schema.ts
|
|
271
|
+
const PAYMENT_METHOD_KIND_VALUES = Object.values(PAYMENT_METHOD_KIND);
|
|
268
272
|
const paymentIntentSchema = z.object({
|
|
269
273
|
amount: z.number().int().min(1),
|
|
270
274
|
currency: z.string().min(3).max(3),
|
|
271
275
|
gateway: z.string(),
|
|
276
|
+
methodKind: z.enum(PAYMENT_METHOD_KIND_VALUES),
|
|
272
277
|
customerId: z.string().optional(),
|
|
273
278
|
sourceId: z.string().optional(),
|
|
274
279
|
sourceModel: z.string().optional(),
|
|
@@ -26,6 +26,21 @@ declare const transactionBaseSchema: z.ZodObject<{
|
|
|
26
26
|
isInclusive: z.ZodOptional<z.ZodBoolean>;
|
|
27
27
|
}, z.core.$strip>>;
|
|
28
28
|
method: z.ZodString;
|
|
29
|
+
methodKind: z.ZodEnum<{
|
|
30
|
+
manual: "manual";
|
|
31
|
+
bank_transfer: "bank_transfer";
|
|
32
|
+
cryptocurrency: "cryptocurrency";
|
|
33
|
+
card: "card";
|
|
34
|
+
instant_bank_transfer: "instant_bank_transfer";
|
|
35
|
+
direct_debit: "direct_debit";
|
|
36
|
+
wallet: "wallet";
|
|
37
|
+
mobile_money: "mobile_money";
|
|
38
|
+
bnpl: "bnpl";
|
|
39
|
+
gift_card: "gift_card";
|
|
40
|
+
cash: "cash";
|
|
41
|
+
cheque: "cheque";
|
|
42
|
+
other: "other";
|
|
43
|
+
}>;
|
|
29
44
|
status: z.ZodDefault<z.ZodString>;
|
|
30
45
|
gateway: z.ZodOptional<z.ZodObject<{
|
|
31
46
|
type: z.ZodString;
|
|
@@ -98,27 +113,13 @@ declare const transactionCreateSchema: z.ZodObject<{
|
|
|
98
113
|
organizationId: z.ZodOptional<z.ZodString>;
|
|
99
114
|
customerId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
100
115
|
type: z.ZodString;
|
|
101
|
-
amount: z.ZodNumber;
|
|
102
|
-
currency: z.ZodString;
|
|
103
|
-
status: z.ZodDefault<z.ZodString>;
|
|
104
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
105
|
-
relatedTransactionId: z.ZodOptional<z.ZodString>;
|
|
106
116
|
flow: z.ZodEnum<{
|
|
107
117
|
inflow: "inflow";
|
|
108
118
|
outflow: "outflow";
|
|
109
119
|
}>;
|
|
110
|
-
gateway: z.ZodOptional<z.ZodObject<{
|
|
111
|
-
type: z.ZodString;
|
|
112
|
-
sessionId: z.ZodOptional<z.ZodString>;
|
|
113
|
-
paymentIntentId: z.ZodOptional<z.ZodString>;
|
|
114
|
-
chargeId: z.ZodOptional<z.ZodString>;
|
|
115
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
116
|
-
verificationData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
117
|
-
}, z.core.$strip>>;
|
|
118
|
-
sourceId: z.ZodOptional<z.ZodString>;
|
|
119
|
-
sourceModel: z.ZodOptional<z.ZodString>;
|
|
120
|
-
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
121
120
|
tags: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
121
|
+
amount: z.ZodNumber;
|
|
122
|
+
currency: z.ZodString;
|
|
122
123
|
fee: z.ZodDefault<z.ZodNumber>;
|
|
123
124
|
tax: z.ZodDefault<z.ZodNumber>;
|
|
124
125
|
net: z.ZodDefault<z.ZodNumber>;
|
|
@@ -132,6 +133,31 @@ declare const transactionCreateSchema: z.ZodObject<{
|
|
|
132
133
|
isInclusive: z.ZodOptional<z.ZodBoolean>;
|
|
133
134
|
}, z.core.$strip>>;
|
|
134
135
|
method: z.ZodString;
|
|
136
|
+
methodKind: z.ZodEnum<{
|
|
137
|
+
manual: "manual";
|
|
138
|
+
bank_transfer: "bank_transfer";
|
|
139
|
+
cryptocurrency: "cryptocurrency";
|
|
140
|
+
card: "card";
|
|
141
|
+
instant_bank_transfer: "instant_bank_transfer";
|
|
142
|
+
direct_debit: "direct_debit";
|
|
143
|
+
wallet: "wallet";
|
|
144
|
+
mobile_money: "mobile_money";
|
|
145
|
+
bnpl: "bnpl";
|
|
146
|
+
gift_card: "gift_card";
|
|
147
|
+
cash: "cash";
|
|
148
|
+
cheque: "cheque";
|
|
149
|
+
other: "other";
|
|
150
|
+
}>;
|
|
151
|
+
status: z.ZodDefault<z.ZodString>;
|
|
152
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
153
|
+
gateway: z.ZodOptional<z.ZodObject<{
|
|
154
|
+
type: z.ZodString;
|
|
155
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
156
|
+
paymentIntentId: z.ZodOptional<z.ZodString>;
|
|
157
|
+
chargeId: z.ZodOptional<z.ZodString>;
|
|
158
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
159
|
+
verificationData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
160
|
+
}, z.core.$strip>>;
|
|
135
161
|
paymentDetails: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
136
162
|
commission: z.ZodOptional<z.ZodObject<{
|
|
137
163
|
rate: z.ZodNumber;
|
|
@@ -172,6 +198,10 @@ declare const transactionCreateSchema: z.ZodObject<{
|
|
|
172
198
|
}, z.core.$strip>>>;
|
|
173
199
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
174
200
|
}, z.core.$strip>>;
|
|
201
|
+
sourceId: z.ZodOptional<z.ZodString>;
|
|
202
|
+
sourceModel: z.ZodOptional<z.ZodString>;
|
|
203
|
+
relatedTransactionId: z.ZodOptional<z.ZodString>;
|
|
204
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
175
205
|
}, z.core.$strip>;
|
|
176
206
|
declare const transactionUpdateSchema: z.ZodObject<{
|
|
177
207
|
publicId: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
@@ -198,6 +228,21 @@ declare const transactionUpdateSchema: z.ZodObject<{
|
|
|
198
228
|
isInclusive: z.ZodOptional<z.ZodBoolean>;
|
|
199
229
|
}, z.core.$strip>>>;
|
|
200
230
|
method: z.ZodOptional<z.ZodString>;
|
|
231
|
+
methodKind: z.ZodOptional<z.ZodEnum<{
|
|
232
|
+
manual: "manual";
|
|
233
|
+
bank_transfer: "bank_transfer";
|
|
234
|
+
cryptocurrency: "cryptocurrency";
|
|
235
|
+
card: "card";
|
|
236
|
+
instant_bank_transfer: "instant_bank_transfer";
|
|
237
|
+
direct_debit: "direct_debit";
|
|
238
|
+
wallet: "wallet";
|
|
239
|
+
mobile_money: "mobile_money";
|
|
240
|
+
bnpl: "bnpl";
|
|
241
|
+
gift_card: "gift_card";
|
|
242
|
+
cash: "cash";
|
|
243
|
+
cheque: "cheque";
|
|
244
|
+
other: "other";
|
|
245
|
+
}>>;
|
|
201
246
|
status: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
202
247
|
gateway: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
203
248
|
type: z.ZodString;
|
|
@@ -317,18 +362,18 @@ declare const subscriptionBaseSchema: z.ZodObject<{
|
|
|
317
362
|
declare const subscriptionCreateSchema: z.ZodObject<{
|
|
318
363
|
organizationId: z.ZodOptional<z.ZodString>;
|
|
319
364
|
customerId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
320
|
-
planKey: z.ZodString;
|
|
321
365
|
amount: z.ZodNumber;
|
|
322
366
|
currency: z.ZodOptional<z.ZodString>;
|
|
323
|
-
transactionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
324
367
|
paymentIntentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
368
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
369
|
+
planKey: z.ZodString;
|
|
370
|
+
transactionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
325
371
|
startDate: z.ZodOptional<z.ZodCoercedDate<unknown>>;
|
|
326
372
|
endDate: z.ZodOptional<z.ZodCoercedDate<unknown>>;
|
|
327
373
|
pauseReason: z.ZodOptional<z.ZodString>;
|
|
328
374
|
cancelAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
|
|
329
375
|
cancellationReason: z.ZodOptional<z.ZodString>;
|
|
330
376
|
renewalTransactionId: z.ZodOptional<z.ZodString>;
|
|
331
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
332
377
|
}, z.core.$strip>;
|
|
333
378
|
declare const subscriptionUpdateSchema: z.ZodObject<{
|
|
334
379
|
publicId: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
@@ -443,7 +488,6 @@ declare const settlementCreateSchema: z.ZodObject<{
|
|
|
443
488
|
amount: z.ZodNumber;
|
|
444
489
|
currency: z.ZodString;
|
|
445
490
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
446
|
-
notes: z.ZodOptional<z.ZodString>;
|
|
447
491
|
recipientId: z.ZodString;
|
|
448
492
|
recipientType: z.ZodEnum<{
|
|
449
493
|
platform: "platform";
|
|
@@ -452,6 +496,7 @@ declare const settlementCreateSchema: z.ZodObject<{
|
|
|
452
496
|
affiliate: "affiliate";
|
|
453
497
|
partner: "partner";
|
|
454
498
|
}>;
|
|
499
|
+
notes: z.ZodOptional<z.ZodString>;
|
|
455
500
|
payoutMethod: z.ZodEnum<{
|
|
456
501
|
manual: "manual";
|
|
457
502
|
bank_transfer: "bank_transfer";
|
|
@@ -572,6 +617,21 @@ declare const paymentIntentSchema: z.ZodObject<{
|
|
|
572
617
|
amount: z.ZodNumber;
|
|
573
618
|
currency: z.ZodString;
|
|
574
619
|
gateway: z.ZodString;
|
|
620
|
+
methodKind: z.ZodEnum<{
|
|
621
|
+
manual: "manual";
|
|
622
|
+
bank_transfer: "bank_transfer";
|
|
623
|
+
cryptocurrency: "cryptocurrency";
|
|
624
|
+
card: "card";
|
|
625
|
+
instant_bank_transfer: "instant_bank_transfer";
|
|
626
|
+
direct_debit: "direct_debit";
|
|
627
|
+
wallet: "wallet";
|
|
628
|
+
mobile_money: "mobile_money";
|
|
629
|
+
bnpl: "bnpl";
|
|
630
|
+
gift_card: "gift_card";
|
|
631
|
+
cash: "cash";
|
|
632
|
+
cheque: "cheque";
|
|
633
|
+
other: "other";
|
|
634
|
+
}>;
|
|
575
635
|
customerId: z.ZodOptional<z.ZodString>;
|
|
576
636
|
sourceId: z.ZodOptional<z.ZodString>;
|
|
577
637
|
sourceModel: z.ZodOptional<z.ZodString>;
|
|
@@ -27,6 +27,13 @@ const REVENUE_EVENTS = {
|
|
|
27
27
|
PAYMENT_REFUNDED: "revenue:payment.refunded",
|
|
28
28
|
PAYMENT_REQUIRES_ACTION: "revenue:payment.requires_action",
|
|
29
29
|
PAYMENT_PROCESSING: "revenue:payment.processing",
|
|
30
|
+
PAYMENT_AUTHORIZED: "revenue:payment.authorized",
|
|
31
|
+
PAYMENT_CAPTURED: "revenue:payment.captured",
|
|
32
|
+
PAYMENT_AUTH_VOIDED: "revenue:payment.auth_voided",
|
|
33
|
+
PAYMENT_DISPUTED: "revenue:payment.disputed",
|
|
34
|
+
PAYMENT_DISPUTE_WON: "revenue:payment.dispute_won",
|
|
35
|
+
PAYMENT_DISPUTE_LOST: "revenue:payment.dispute_lost",
|
|
36
|
+
PAYMENT_SETTLED: "revenue:payment.settled",
|
|
30
37
|
MONETIZATION_CREATED: "revenue:monetization.created",
|
|
31
38
|
PURCHASE_CREATED: "revenue:purchase.created",
|
|
32
39
|
FREE_CREATED: "revenue:free.created",
|
package/dist/events/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { $ as TransactionJournalizedPayload, A as SettlementCreated, B as SubscriptionCancelled, C as PurchaseCreated, D as RevenueEventSchema, E as RevenueEventPayloadOf, F as SettlementProcessingPayload, G as SubscriptionPausedPayload, H as SubscriptionCreated, I as SettlementScheduled, J as SubscriptionResumed, K as SubscriptionRenewed, L as SettlementScheduledPayload, M as SettlementFailed, N as SettlementFailedPayload, O as SettlementCompleted, P as SettlementProcessing, Q as TransactionJournalized, R as SubscriptionActivated, S as PaymentVerifiedPayload, T as RevenueEventDefinition, U as SubscriptionCreatedPayload, V as SubscriptionCancelledPayload, W as SubscriptionPaused, X as TransactionImported, Y as SubscriptionResumedPayload, Z as TransactionImportedPayload, _ as PaymentRefunded, _t as InProcessRevenueBusOptions, a as EscrowReleased, at as TransactionRemovedByFeedPayload, b as PaymentRequiresActionPayload, c as EscrowSplitPayload, ct as TransactionUpdated, d as MonetizationCreated, dt as WebhookProcessedPayload, et as TransactionMatched, f as MonetizationCreatedPayload, ft as revenueEventDefinitions, g as PaymentProcessingPayload, gt as InProcessRevenueBus, h as PaymentProcessing, ht as createEvent, i as EscrowHeldPayload, it as TransactionRemovedByFeed, j as SettlementCreatedPayload, k as SettlementCompletedPayload, l as FreeCreated, lt as TransactionUpdatedPayload, m as PaymentFailedPayload, mt as RevenueEventName, n as EscrowCancelledPayload, nt as TransactionRejected, o as EscrowReleasedPayload, ot as TransactionUnmatched, p as PaymentFailed, pt as REVENUE_EVENTS, q as SubscriptionRenewedPayload, r as EscrowHeld, rt as TransactionRejectedPayload, s as EscrowSplit, st as TransactionUnmatchedPayload, t as EscrowCancelled, tt as TransactionMatchedPayload, u as FreeCreatedPayload, ut as WebhookProcessed, v as PaymentRefundedPayload, w as PurchaseCreatedPayload, x as PaymentVerified, y as PaymentRequiresAction, z as SubscriptionActivatedPayload } from "../revenue-event-catalog-
|
|
1
|
+
import { $ as TransactionJournalizedPayload, A as SettlementCreated, B as SubscriptionCancelled, C as PurchaseCreated, D as RevenueEventSchema, E as RevenueEventPayloadOf, F as SettlementProcessingPayload, G as SubscriptionPausedPayload, H as SubscriptionCreated, I as SettlementScheduled, J as SubscriptionResumed, K as SubscriptionRenewed, L as SettlementScheduledPayload, M as SettlementFailed, N as SettlementFailedPayload, O as SettlementCompleted, P as SettlementProcessing, Q as TransactionJournalized, R as SubscriptionActivated, S as PaymentVerifiedPayload, T as RevenueEventDefinition, U as SubscriptionCreatedPayload, V as SubscriptionCancelledPayload, W as SubscriptionPaused, X as TransactionImported, Y as SubscriptionResumedPayload, Z as TransactionImportedPayload, _ as PaymentRefunded, _t as InProcessRevenueBusOptions, a as EscrowReleased, at as TransactionRemovedByFeedPayload, b as PaymentRequiresActionPayload, c as EscrowSplitPayload, ct as TransactionUpdated, d as MonetizationCreated, dt as WebhookProcessedPayload, et as TransactionMatched, f as MonetizationCreatedPayload, ft as revenueEventDefinitions, g as PaymentProcessingPayload, gt as InProcessRevenueBus, h as PaymentProcessing, ht as createEvent, i as EscrowHeldPayload, it as TransactionRemovedByFeed, j as SettlementCreatedPayload, k as SettlementCompletedPayload, l as FreeCreated, lt as TransactionUpdatedPayload, m as PaymentFailedPayload, mt as RevenueEventName, n as EscrowCancelledPayload, nt as TransactionRejected, o as EscrowReleasedPayload, ot as TransactionUnmatched, p as PaymentFailed, pt as REVENUE_EVENTS, q as SubscriptionRenewedPayload, r as EscrowHeld, rt as TransactionRejectedPayload, s as EscrowSplit, st as TransactionUnmatchedPayload, t as EscrowCancelled, tt as TransactionMatchedPayload, u as FreeCreatedPayload, ut as WebhookProcessed, v as PaymentRefundedPayload, w as PurchaseCreatedPayload, x as PaymentVerified, y as PaymentRequiresAction, z as SubscriptionActivatedPayload } from "../revenue-event-catalog-BU_KYN2-.mjs";
|
|
2
2
|
import { DomainEvent, EventHandler, EventTransport } from "@classytic/primitives/events";
|
|
3
3
|
export { type DomainEvent, EscrowCancelled, type EscrowCancelledPayload, EscrowHeld, type EscrowHeldPayload, EscrowReleased, type EscrowReleasedPayload, EscrowSplit, type EscrowSplitPayload, type EventHandler, type EventTransport, FreeCreated, type FreeCreatedPayload, InProcessRevenueBus, type InProcessRevenueBusOptions, MonetizationCreated, type MonetizationCreatedPayload, PaymentFailed, type PaymentFailedPayload, PaymentProcessing, type PaymentProcessingPayload, PaymentRefunded, type PaymentRefundedPayload, PaymentRequiresAction, type PaymentRequiresActionPayload, PaymentVerified, type PaymentVerifiedPayload, PurchaseCreated, type PurchaseCreatedPayload, REVENUE_EVENTS, type RevenueEventDefinition, type RevenueEventName, type RevenueEventPayloadOf, type RevenueEventSchema, SettlementCompleted, type SettlementCompletedPayload, SettlementCreated, type SettlementCreatedPayload, SettlementFailed, type SettlementFailedPayload, SettlementProcessing, type SettlementProcessingPayload, SettlementScheduled, type SettlementScheduledPayload, SubscriptionActivated, type SubscriptionActivatedPayload, SubscriptionCancelled, type SubscriptionCancelledPayload, SubscriptionCreated, type SubscriptionCreatedPayload, SubscriptionPaused, type SubscriptionPausedPayload, SubscriptionRenewed, type SubscriptionRenewedPayload, SubscriptionResumed, type SubscriptionResumedPayload, TransactionImported, type TransactionImportedPayload, TransactionJournalized, type TransactionJournalizedPayload, TransactionMatched, type TransactionMatchedPayload, TransactionRejected, type TransactionRejectedPayload, TransactionRemovedByFeed, type TransactionRemovedByFeedPayload, TransactionUnmatched, type TransactionUnmatchedPayload, TransactionUpdated, type TransactionUpdatedPayload, WebhookProcessed, type WebhookProcessedPayload, createEvent, revenueEventDefinitions };
|
package/dist/events/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as createEvent, t as REVENUE_EVENTS } from "../event-constants-
|
|
2
|
-
import { A as TransactionUpdated, C as SubscriptionResumed, D as TransactionRejected, E as TransactionMatched, M as revenueEventDefinitions, N as InProcessRevenueBus, O as TransactionRemovedByFeed, S as SubscriptionRenewed, T as TransactionJournalized, _ as SettlementScheduled, a as FreeCreated, b as SubscriptionCreated, c as PaymentProcessing, d as PaymentVerified, f as PurchaseCreated, g as SettlementProcessing, h as SettlementFailed, i as EscrowSplit, j as WebhookProcessed, k as TransactionUnmatched, l as PaymentRefunded, m as SettlementCreated, n as EscrowHeld, o as MonetizationCreated, p as SettlementCompleted, r as EscrowReleased, s as PaymentFailed, t as EscrowCancelled, u as PaymentRequiresAction, v as SubscriptionActivated, w as TransactionImported, x as SubscriptionPaused, y as SubscriptionCancelled } from "../revenue-event-catalog-
|
|
1
|
+
import { n as createEvent, t as REVENUE_EVENTS } from "../event-constants-DM_-A57b.mjs";
|
|
2
|
+
import { A as TransactionUpdated, C as SubscriptionResumed, D as TransactionRejected, E as TransactionMatched, M as revenueEventDefinitions, N as InProcessRevenueBus, O as TransactionRemovedByFeed, S as SubscriptionRenewed, T as TransactionJournalized, _ as SettlementScheduled, a as FreeCreated, b as SubscriptionCreated, c as PaymentProcessing, d as PaymentVerified, f as PurchaseCreated, g as SettlementProcessing, h as SettlementFailed, i as EscrowSplit, j as WebhookProcessed, k as TransactionUnmatched, l as PaymentRefunded, m as SettlementCreated, n as EscrowHeld, o as MonetizationCreated, p as SettlementCompleted, r as EscrowReleased, s as PaymentFailed, t as EscrowCancelled, u as PaymentRequiresAction, v as SubscriptionActivated, w as TransactionImported, x as SubscriptionPaused, y as SubscriptionCancelled } from "../revenue-event-catalog-B9aZmNpL.mjs";
|
|
3
3
|
|
|
4
4
|
export { EscrowCancelled, EscrowHeld, EscrowReleased, EscrowSplit, FreeCreated, InProcessRevenueBus, MonetizationCreated, PaymentFailed, PaymentProcessing, PaymentRefunded, PaymentRequiresAction, PaymentVerified, PurchaseCreated, REVENUE_EVENTS, SettlementCompleted, SettlementCreated, SettlementFailed, SettlementProcessing, SettlementScheduled, SubscriptionActivated, SubscriptionCancelled, SubscriptionCreated, SubscriptionPaused, SubscriptionRenewed, SubscriptionResumed, TransactionImported, TransactionJournalized, TransactionMatched, TransactionRejected, TransactionRemovedByFeed, TransactionUnmatched, TransactionUpdated, WebhookProcessed, createEvent, revenueEventDefinitions };
|
package/dist/index.d.mts
CHANGED
|
@@ -4,15 +4,15 @@ import { A as SettlementStatus, B as HoldReason, C as isPayoutMethod, D as SETTL
|
|
|
4
4
|
import { A as isTransactionFlow, C as TRANSACTION_STATUS, D as TransactionStatus, E as TransactionFlowValue, O as TransactionStatusValue, S as TRANSACTION_FLOW_VALUES, T as TransactionFlow, _ as LIBRARY_CATEGORIES, a as BankFeedSourceValue, b as LibraryCategoryValue, c as TRANSACTION_KIND_VALUES, d as initialStatusFor, f as isBankFeedSource, g as statusesForKind, h as isTransactionKind, i as BANK_FEED_STATUS_VALUES, j as isTransactionStatus, k as isLibraryCategory, l as TransactionKind, m as isStatusValidForKind, n as BANK_FEED_SOURCE_VALUES, o as BankFeedStatusValue, p as isBankFeedStatus, r as BANK_FEED_STATUS, s as TRANSACTION_KIND, t as BANK_FEED_SOURCE, u as TransactionKindValue, v as LIBRARY_CATEGORY_VALUES, w as TRANSACTION_STATUS_VALUES, x as TRANSACTION_FLOW, y as LibraryCategories } from "./bank-feed.enums-BadqNJTC.mjs";
|
|
5
5
|
import { BANK_FEED_STATE_MACHINE, HOLD_STATE_MACHINE, MANUAL_STATE_MACHINE, PAYMENT_FLOW_STATE_MACHINE, SETTLEMENT_STATE_MACHINE, SPLIT_STATE_MACHINE, SUBSCRIPTION_STATE_MACHINE, StateChangeEvent, StateMachine, TRANSACTION_STATE_MACHINE, smFor } from "./core/state-machines.mjs";
|
|
6
6
|
import { a as isMonetizationType, c as PAYMENT_STATUS, d as PaymentGatewayTypeValue, f as PaymentStatus, h as isPaymentStatus, i as MonetizationTypes, l as PAYMENT_STATUS_VALUES, m as isPaymentGatewayType, n as MONETIZATION_TYPE_VALUES, o as PAYMENT_GATEWAY_TYPE, p as PaymentStatusValue, r as MonetizationTypeValue, s as PAYMENT_GATEWAY_TYPE_VALUES, t as MONETIZATION_TYPES, u as PaymentGatewayType } from "./monetization.enums-DzAI4sT7.mjs";
|
|
7
|
-
import { D as RevenueEventSchema, E as RevenueEventPayloadOf, T as RevenueEventDefinition, _t as InProcessRevenueBusOptions, ft as revenueEventDefinitions, gt as InProcessRevenueBus, ht as createEvent, mt as RevenueEventName, pt as REVENUE_EVENTS } from "./revenue-event-catalog-
|
|
7
|
+
import { D as RevenueEventSchema, E as RevenueEventPayloadOf, T as RevenueEventDefinition, _t as InProcessRevenueBusOptions, ft as revenueEventDefinitions, gt as InProcessRevenueBus, ht as createEvent, mt as RevenueEventName, pt as REVENUE_EVENTS } from "./revenue-event-catalog-BU_KYN2-.mjs";
|
|
8
8
|
import { a as BankFeedProviderRegistry, c as ParseUploadParams, d as PaymentProvider, i as BankFeedProviderCapabilities, l as ParseUploadResult, n as createProviderRegistry, o as FetchTransactionsParams, r as BankFeedProvider, s as FetchTransactionsResult, t as ProviderRegistry, u as createBankFeedProviderRegistry } from "./registry-h8sasoLh.mjs";
|
|
9
|
-
import { a as RevenueConfig, c as SubscriptionRepository, d as RevenueSchemaOptions, f as SettlementDocument, i as RetryConfig, l as TransactionRepository, m as TransactionDocument, n as BankFeedModuleConfig, o as RevenueEngine, p as SubscriptionDocument, r as CommissionConfig, s as SettlementRepository, t as BankFeedIndexConfig, u as RevenueModels } from "./engine-types-
|
|
9
|
+
import { a as RevenueConfig, c as SubscriptionRepository, d as RevenueSchemaOptions, f as SettlementDocument, i as RetryConfig, l as TransactionRepository, m as TransactionDocument, n as BankFeedModuleConfig, o as RevenueEngine, p as SubscriptionDocument, r as CommissionConfig, s as SettlementRepository, t as BankFeedIndexConfig, u as RevenueModels } from "./engine-types-ChFPg3kw.mjs";
|
|
10
10
|
import { RepositoryPluginBundle, RevenueRepositories } from "./repositories/create-repositories.mjs";
|
|
11
|
-
import { A as transactionBaseSchema, C as subscriptionBaseSchema, D as TransactionCreateInput, E as subscriptionUpdateSchema, M as transactionListFilterSchema, N as transactionUpdateSchema, O as TransactionListFilter, S as SubscriptionUpdateInput, T as subscriptionListFilterSchema, _ as settlementCreateSchema, a as escrowReleaseSchema, b as SubscriptionCreateInput, c as PaymentVerifyInput, d as paymentVerifySchema, f as refundSchema, g as settlementBaseSchema, h as SettlementUpdateInput, i as escrowHoldSchema, j as transactionCreateSchema, k as TransactionUpdateInput, l as RefundInput, m as SettlementListFilter, n as EscrowReleaseInput, o as splitRuleSchema, p as SettlementCreateInput, r as SplitRuleInput, s as PaymentIntentInput, t as EscrowHoldInput, u as paymentIntentSchema, v as settlementListFilterSchema, w as subscriptionCreateSchema, x as SubscriptionListFilter, y as settlementUpdateSchema } from "./escrow.schema-
|
|
11
|
+
import { A as transactionBaseSchema, C as subscriptionBaseSchema, D as TransactionCreateInput, E as subscriptionUpdateSchema, M as transactionListFilterSchema, N as transactionUpdateSchema, O as TransactionListFilter, S as SubscriptionUpdateInput, T as subscriptionListFilterSchema, _ as settlementCreateSchema, a as escrowReleaseSchema, b as SubscriptionCreateInput, c as PaymentVerifyInput, d as paymentVerifySchema, f as refundSchema, g as settlementBaseSchema, h as SettlementUpdateInput, i as escrowHoldSchema, j as transactionCreateSchema, k as TransactionUpdateInput, l as RefundInput, m as SettlementListFilter, n as EscrowReleaseInput, o as splitRuleSchema, p as SettlementCreateInput, r as SplitRuleInput, s as PaymentIntentInput, t as EscrowHoldInput, u as paymentIntentSchema, v as settlementListFilterSchema, w as subscriptionCreateSchema, x as SubscriptionListFilter, y as settlementUpdateSchema } from "./escrow.schema-BdDHuQ8C.mjs";
|
|
12
12
|
import { A as SplitInfo, B as validateTaxCalculation, C as multiplyMoney, D as toCurrencyCode, E as sumMoney, F as TaxConfig, H as calculateCommission, I as TaxType, L as calculateTax, M as calculateOrganizationPayout, N as calculateSplits, O as toMajor, P as TaxCalculation, R as getTaxType, S as money, T as subtractMoney, U as reverseCommission, V as CommissionInfo, _ as isMoney, a as CurrencyCode, b as isZeroMoney, c as Money, d as addMoney, f as compareMoney, g as isCurrencyCode, h as fromSmallestUnit, i as CURRENCIES, j as SplitRule, k as toSmallestUnit, l as MoneyValue, m as fromMajor, n as getAuditTrail, o as CurrencyMismatchError, p as equalsMoney, r as getLastStateChange, s as MINOR_UNIT_FACTOR, t as appendAuditEvent, u as absMoney, v as isNegativeMoney, w as negateMoney, x as minorUnitFactor, y as isPositiveMoney, z as reverseTax } from "./audit-DRKuLBFO.mjs";
|
|
13
13
|
import { HookHandler, PluginContext, PluginManager, RevenuePluginDefinition } from "./plugins/plugin.interface.mjs";
|
|
14
|
-
import { DomainEvent, EventHandler, EventTransport } from "@classytic/primitives/events";
|
|
15
|
-
import { InvalidOutboxEventError, OutboxAcknowledgeOptions, OutboxClaimOptions, OutboxErrorInfo, OutboxFailOptions, OutboxFailureContext, OutboxFailureDecision, OutboxFailurePolicy, OutboxOwnershipError, OutboxStore, OutboxWriteOptions } from "@classytic/primitives/outbox";
|
|
14
|
+
import { DomainEvent, DomainEvent as DomainEvent$1, EventHandler, EventTransport } from "@classytic/primitives/events";
|
|
15
|
+
import { InvalidOutboxEventError, OutboxAcknowledgeOptions, OutboxAcknowledgeOptions as OutboxAcknowledgeOptions$1, OutboxClaimOptions, OutboxErrorInfo, OutboxFailOptions, OutboxFailureContext, OutboxFailureDecision, OutboxFailurePolicy, OutboxOwnershipError, OutboxStore, OutboxStore as OutboxStore$1, OutboxWriteOptions, OutboxWriteOptions as OutboxWriteOptions$1 } from "@classytic/primitives/outbox";
|
|
16
16
|
import { Result, err, isErr, isOk, ok } from "@classytic/primitives/result";
|
|
17
17
|
|
|
18
18
|
//#region src/engine/create-revenue.d.ts
|
|
@@ -32,11 +32,33 @@ import { Result, err, isErr, isOk, ok } from "@classytic/primitives/result";
|
|
|
32
32
|
*/
|
|
33
33
|
declare function createRevenue(config: RevenueConfig): Promise<RevenueEngine>;
|
|
34
34
|
//#endregion
|
|
35
|
+
//#region src/events/outbox-store.d.ts
|
|
36
|
+
declare class MemoryOutboxStore implements OutboxStore$1 {
|
|
37
|
+
private events;
|
|
38
|
+
save(event: DomainEvent$1, _options?: OutboxWriteOptions$1): Promise<void>;
|
|
39
|
+
getPending(limit: number): Promise<DomainEvent$1[]>;
|
|
40
|
+
acknowledge(eventId: string, _options?: OutboxAcknowledgeOptions$1): Promise<void>;
|
|
41
|
+
purge(olderThanMs: number): Promise<number>;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
35
44
|
//#region src/core/errors.d.ts
|
|
36
45
|
declare class RevenueError extends Error {
|
|
37
46
|
readonly code: string;
|
|
38
47
|
readonly details?: Record<string, unknown> | undefined;
|
|
39
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Suggested HTTP status. Hosts that surface RevenueError over HTTP
|
|
50
|
+
* (Arc, raw Express) read this to set the response code. Optional —
|
|
51
|
+
* defaults to 500 in the host's error mapper when unset.
|
|
52
|
+
*/
|
|
53
|
+
readonly httpStatus?: number | undefined;
|
|
54
|
+
constructor(message: string, code: string, details?: Record<string, unknown> | undefined,
|
|
55
|
+
/**
|
|
56
|
+
* Suggested HTTP status. Hosts that surface RevenueError over HTTP
|
|
57
|
+
* (Arc, raw Express) read this to set the response code. Optional —
|
|
58
|
+
* defaults to 500 in the host's error mapper when unset.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
httpStatus?: number | undefined);
|
|
40
62
|
}
|
|
41
63
|
declare class ValidationError extends RevenueError {
|
|
42
64
|
constructor(message: string, details?: Record<string, unknown>);
|
|
@@ -80,8 +102,17 @@ declare class BankFeedImportError extends RevenueError {
|
|
|
80
102
|
declare class WrongTransactionKindError extends RevenueError {
|
|
81
103
|
constructor(transactionId: string, expected: string, actual: string);
|
|
82
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Thrown by `TransactionRepository.backfillMethodKind` when the existing
|
|
107
|
+
* doc is NOT eligible for backfill (methodKind already specific, or
|
|
108
|
+
* status no longer `'pending'`). 409 because the request is well-formed
|
|
109
|
+
* but conflicts with the current resource state.
|
|
110
|
+
*/
|
|
111
|
+
declare class MethodKindLockedError extends RevenueError {
|
|
112
|
+
constructor(transactionId: string, currentMethodKind: string, currentStatus: string);
|
|
113
|
+
}
|
|
83
114
|
declare class BankFeedProviderNotFoundError extends RevenueError {
|
|
84
115
|
constructor(providerName: string);
|
|
85
116
|
}
|
|
86
117
|
//#endregion
|
|
87
|
-
export { AlreadyVerifiedError, type AnalyticsBridge, BANK_FEED_SOURCE, BANK_FEED_SOURCE_VALUES, BANK_FEED_STATE_MACHINE, BANK_FEED_STATUS, BANK_FEED_STATUS_VALUES, BankFeedImportError, type BankFeedIndexConfig, type BankFeedModuleConfig, BankFeedProvider, type BankFeedProviderCapabilities, BankFeedProviderNotFoundError, BankFeedProviderRegistry, BankFeedSourceValue, BankFeedStatusValue, CURRENCIES, type CommissionConfig, type CommissionInfo, ConfigurationError, type CurrencyBridge, type CurrencyCode, CurrencyMismatchError, type CustomerBridge, type DomainEvent, EscrowHoldInput, EscrowReleaseInput, type EventHandler, type EventTransport, type FetchTransactionsParams, type FetchTransactionsResult, HOLD_REASON, HOLD_REASON_VALUES, HOLD_STATE_MACHINE, HOLD_STATUS, HOLD_STATUS_VALUES, HoldReason, HoldReasonValue, HoldStatus, HoldStatusValue, type HookHandler, InProcessRevenueBus, type InProcessRevenueBusOptions, InvalidOutboxEventError, InvalidStateTransitionError, LIBRARY_CATEGORIES, LIBRARY_CATEGORY_VALUES, type LedgerBridge, LibraryCategories, LibraryCategoryValue, MANUAL_STATE_MACHINE, MINOR_UNIT_FACTOR, MONETIZATION_TYPES, MONETIZATION_TYPE_VALUES, MonetizationTypeValue, MonetizationTypes, type Money, type MoneyValue, type NotificationBridge, type OutboxAcknowledgeOptions, type OutboxClaimOptions, type OutboxErrorInfo, type OutboxFailOptions, type OutboxFailureContext, type OutboxFailureDecision, type OutboxFailurePolicy, OutboxOwnershipError, type OutboxStore, type OutboxWriteOptions, PAYMENT_FLOW_STATE_MACHINE, PAYMENT_GATEWAY_TYPE, PAYMENT_GATEWAY_TYPE_VALUES, PAYMENT_STATUS, PAYMENT_STATUS_VALUES, PAYOUT_METHOD, PAYOUT_METHOD_VALUES, PLAN_KEYS, PLAN_KEY_VALUES, type ParseUploadParams, type ParseUploadResult, PaymentGatewayType, PaymentGatewayTypeValue, PaymentIntentCreationError, PaymentIntentInput, PaymentProvider, PaymentStatus, PaymentStatusValue, PaymentVerificationError, PaymentVerifyInput, PayoutMethod, PayoutMethodValue, PlanKeyValue, PlanKeys, type PluginContext, PluginManager, ProviderCapabilityError, ProviderNotFoundError, ProviderRegistry, RELEASE_REASON, RELEASE_REASON_VALUES, REVENUE_EVENTS, RefundInput, RefundNotSupportedError, ReleaseReason, ReleaseReasonValue, type RepositoryPluginBundle, type Result, type RetryConfig, type RevenueBridges, type RevenueConfig, type RevenueContext, type RevenueEngine, RevenueError, type RevenueEventDefinition, type RevenueEventName, type RevenueEventPayloadOf, type RevenueEventSchema, type RevenueModels, type RevenuePluginDefinition, type RevenueRepositories, type RevenueSchemaOptions, SETTLEMENT_STATE_MACHINE, SETTLEMENT_STATUS, SETTLEMENT_STATUS_VALUES, SETTLEMENT_TYPE, SETTLEMENT_TYPE_VALUES, SPLIT_STATE_MACHINE, SPLIT_STATUS, SPLIT_STATUS_VALUES, SPLIT_TYPE, SPLIT_TYPE_VALUES, SUBSCRIPTION_STATE_MACHINE, SUBSCRIPTION_STATUS, SUBSCRIPTION_STATUS_VALUES, SettlementCreateInput, type SettlementDocument, SettlementListFilter, SettlementNotFoundError, SettlementRepository, SettlementStatus, SettlementStatusValue, SettlementType, SettlementTypeValue, SettlementUpdateInput, type SplitInfo, type SplitRule, SplitRuleInput, SplitStatus, SplitStatusValue, SplitType, SplitTypeValue, type StateChangeEvent, StateMachine, SubscriptionCreateInput, type SubscriptionDocument, SubscriptionListFilter, SubscriptionNotFoundError, SubscriptionRepository, SubscriptionStatus, SubscriptionStatusValue, SubscriptionUpdateInput, TRANSACTION_FLOW, TRANSACTION_FLOW_VALUES, TRANSACTION_KIND, TRANSACTION_KIND_VALUES, TRANSACTION_STATE_MACHINE, TRANSACTION_STATUS, TRANSACTION_STATUS_VALUES, type TaxBridge, type TaxCalculation, type TaxConfig, type TaxType, TransactionCreateInput, type TransactionDocument, TransactionFlow, TransactionFlowValue, TransactionKind, TransactionKindValue, TransactionListFilter, TransactionNotFoundError, TransactionRepository, TransactionStatus, TransactionStatusValue, TransactionUpdateInput, ValidationError, WrongTransactionKindError, absMoney, addMoney, appendAuditEvent, calculateCommission, calculateOrganizationPayout, calculateSplits, calculateTax, compareMoney, createBankFeedProviderRegistry, createEvent, createProviderRegistry, createRevenue, equalsMoney, err, escrowHoldSchema, escrowReleaseSchema, fromMajor, fromSmallestUnit, getAuditTrail, getLastStateChange, getTaxType, initialStatusFor, isBankFeedSource, isBankFeedStatus, isCurrencyCode, isErr, isHoldReason, isHoldStatus, isLibraryCategory, isMonetizationType, isMoney, isNegativeMoney, isOk, isPaymentGatewayType, isPaymentStatus, isPayoutMethod, isPlanKey, isPositiveMoney, isReleaseReason, isSettlementStatus, isSettlementType, isSplitStatus, isSplitType, isStatusValidForKind, isSubscriptionStatus, isTransactionFlow, isTransactionKind, isTransactionStatus, isZeroMoney, minorUnitFactor, money, multiplyMoney, negateMoney, ok, paymentIntentSchema, paymentVerifySchema, refundSchema, revenueEventDefinitions, reverseCommission, reverseTax, settlementBaseSchema, settlementCreateSchema, settlementListFilterSchema, settlementUpdateSchema, smFor, splitRuleSchema, statusesForKind, subscriptionBaseSchema, subscriptionCreateSchema, subscriptionListFilterSchema, subscriptionUpdateSchema, subtractMoney, sumMoney, toCurrencyCode, toMajor, toSmallestUnit, transactionBaseSchema, transactionCreateSchema, transactionListFilterSchema, transactionUpdateSchema, validateTaxCalculation };
|
|
118
|
+
export { AlreadyVerifiedError, type AnalyticsBridge, BANK_FEED_SOURCE, BANK_FEED_SOURCE_VALUES, BANK_FEED_STATE_MACHINE, BANK_FEED_STATUS, BANK_FEED_STATUS_VALUES, BankFeedImportError, type BankFeedIndexConfig, type BankFeedModuleConfig, BankFeedProvider, type BankFeedProviderCapabilities, BankFeedProviderNotFoundError, BankFeedProviderRegistry, BankFeedSourceValue, BankFeedStatusValue, CURRENCIES, type CommissionConfig, type CommissionInfo, ConfigurationError, type CurrencyBridge, type CurrencyCode, CurrencyMismatchError, type CustomerBridge, type DomainEvent, EscrowHoldInput, EscrowReleaseInput, type EventHandler, type EventTransport, type FetchTransactionsParams, type FetchTransactionsResult, HOLD_REASON, HOLD_REASON_VALUES, HOLD_STATE_MACHINE, HOLD_STATUS, HOLD_STATUS_VALUES, HoldReason, HoldReasonValue, HoldStatus, HoldStatusValue, type HookHandler, InProcessRevenueBus, type InProcessRevenueBusOptions, InvalidOutboxEventError, InvalidStateTransitionError, LIBRARY_CATEGORIES, LIBRARY_CATEGORY_VALUES, type LedgerBridge, LibraryCategories, LibraryCategoryValue, MANUAL_STATE_MACHINE, MINOR_UNIT_FACTOR, MONETIZATION_TYPES, MONETIZATION_TYPE_VALUES, MemoryOutboxStore, MethodKindLockedError, MonetizationTypeValue, MonetizationTypes, type Money, type MoneyValue, type NotificationBridge, type OutboxAcknowledgeOptions, type OutboxClaimOptions, type OutboxErrorInfo, type OutboxFailOptions, type OutboxFailureContext, type OutboxFailureDecision, type OutboxFailurePolicy, OutboxOwnershipError, type OutboxStore, type OutboxWriteOptions, PAYMENT_FLOW_STATE_MACHINE, PAYMENT_GATEWAY_TYPE, PAYMENT_GATEWAY_TYPE_VALUES, PAYMENT_STATUS, PAYMENT_STATUS_VALUES, PAYOUT_METHOD, PAYOUT_METHOD_VALUES, PLAN_KEYS, PLAN_KEY_VALUES, type ParseUploadParams, type ParseUploadResult, PaymentGatewayType, PaymentGatewayTypeValue, PaymentIntentCreationError, PaymentIntentInput, PaymentProvider, PaymentStatus, PaymentStatusValue, PaymentVerificationError, PaymentVerifyInput, PayoutMethod, PayoutMethodValue, PlanKeyValue, PlanKeys, type PluginContext, PluginManager, ProviderCapabilityError, ProviderNotFoundError, ProviderRegistry, RELEASE_REASON, RELEASE_REASON_VALUES, REVENUE_EVENTS, RefundInput, RefundNotSupportedError, ReleaseReason, ReleaseReasonValue, type RepositoryPluginBundle, type Result, type RetryConfig, type RevenueBridges, type RevenueConfig, type RevenueContext, type RevenueEngine, RevenueError, type RevenueEventDefinition, type RevenueEventName, type RevenueEventPayloadOf, type RevenueEventSchema, type RevenueModels, type RevenuePluginDefinition, type RevenueRepositories, type RevenueSchemaOptions, SETTLEMENT_STATE_MACHINE, SETTLEMENT_STATUS, SETTLEMENT_STATUS_VALUES, SETTLEMENT_TYPE, SETTLEMENT_TYPE_VALUES, SPLIT_STATE_MACHINE, SPLIT_STATUS, SPLIT_STATUS_VALUES, SPLIT_TYPE, SPLIT_TYPE_VALUES, SUBSCRIPTION_STATE_MACHINE, SUBSCRIPTION_STATUS, SUBSCRIPTION_STATUS_VALUES, SettlementCreateInput, type SettlementDocument, SettlementListFilter, SettlementNotFoundError, SettlementRepository, SettlementStatus, SettlementStatusValue, SettlementType, SettlementTypeValue, SettlementUpdateInput, type SplitInfo, type SplitRule, SplitRuleInput, SplitStatus, SplitStatusValue, SplitType, SplitTypeValue, type StateChangeEvent, StateMachine, SubscriptionCreateInput, type SubscriptionDocument, SubscriptionListFilter, SubscriptionNotFoundError, SubscriptionRepository, SubscriptionStatus, SubscriptionStatusValue, SubscriptionUpdateInput, TRANSACTION_FLOW, TRANSACTION_FLOW_VALUES, TRANSACTION_KIND, TRANSACTION_KIND_VALUES, TRANSACTION_STATE_MACHINE, TRANSACTION_STATUS, TRANSACTION_STATUS_VALUES, type TaxBridge, type TaxCalculation, type TaxConfig, type TaxType, TransactionCreateInput, type TransactionDocument, TransactionFlow, TransactionFlowValue, TransactionKind, TransactionKindValue, TransactionListFilter, TransactionNotFoundError, TransactionRepository, TransactionStatus, TransactionStatusValue, TransactionUpdateInput, ValidationError, WrongTransactionKindError, absMoney, addMoney, appendAuditEvent, calculateCommission, calculateOrganizationPayout, calculateSplits, calculateTax, compareMoney, createBankFeedProviderRegistry, createEvent, createProviderRegistry, createRevenue, equalsMoney, err, escrowHoldSchema, escrowReleaseSchema, fromMajor, fromSmallestUnit, getAuditTrail, getLastStateChange, getTaxType, initialStatusFor, isBankFeedSource, isBankFeedStatus, isCurrencyCode, isErr, isHoldReason, isHoldStatus, isLibraryCategory, isMonetizationType, isMoney, isNegativeMoney, isOk, isPaymentGatewayType, isPaymentStatus, isPayoutMethod, isPlanKey, isPositiveMoney, isReleaseReason, isSettlementStatus, isSettlementType, isSplitStatus, isSplitType, isStatusValidForKind, isSubscriptionStatus, isTransactionFlow, isTransactionKind, isTransactionStatus, isZeroMoney, minorUnitFactor, money, multiplyMoney, negateMoney, ok, paymentIntentSchema, paymentVerifySchema, refundSchema, revenueEventDefinitions, reverseCommission, reverseTax, settlementBaseSchema, settlementCreateSchema, settlementListFilterSchema, settlementUpdateSchema, smFor, splitRuleSchema, statusesForKind, subscriptionBaseSchema, subscriptionCreateSchema, subscriptionListFilterSchema, subscriptionUpdateSchema, subtractMoney, sumMoney, toCurrencyCode, toMajor, toSmallestUnit, transactionBaseSchema, transactionCreateSchema, transactionListFilterSchema, transactionUpdateSchema, validateTaxCalculation };
|
package/dist/index.mjs
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import { _ as TRANSACTION_STATUS, a as TRANSACTION_KIND, b as isTransactionFlow, c as isBankFeedSource, d as isTransactionKind, f as statusesForKind, g as TRANSACTION_FLOW_VALUES, h as TRANSACTION_FLOW, i as BANK_FEED_STATUS_VALUES, l as isBankFeedStatus, m as LIBRARY_CATEGORY_VALUES, n as BANK_FEED_SOURCE_VALUES, o as TRANSACTION_KIND_VALUES, p as LIBRARY_CATEGORIES, r as BANK_FEED_STATUS, s as initialStatusFor, t as BANK_FEED_SOURCE, u as isStatusValidForKind, v as TRANSACTION_STATUS_VALUES, x as isTransactionStatus, y as isLibraryCategory } from "./bank-feed.enums-kYTLTTbe.mjs";
|
|
2
|
-
import { n as
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
2
|
+
import { n as SubscriptionRepository, r as TransactionRepository, t as SettlementRepository } from "./settlement.repository-CfvgX3et.mjs";
|
|
3
|
+
import { n as createEvent, t as REVENUE_EVENTS } from "./event-constants-DM_-A57b.mjs";
|
|
4
|
+
import { A as isReleaseReason, C as HOLD_REASON_VALUES, D as RELEASE_REASON_VALUES, E as RELEASE_REASON, O as isHoldReason, S as HOLD_REASON, T as HOLD_STATUS_VALUES, _ as SETTLEMENT_STATUS_VALUES, a as isPlanKey, b as isSettlementStatus, c as PAYOUT_METHOD_VALUES, d as SPLIT_TYPE, f as SPLIT_TYPE_VALUES, g as SETTLEMENT_STATUS, h as isSplitType, i as SUBSCRIPTION_STATUS_VALUES, k as isHoldStatus, l as SPLIT_STATUS, m as isSplitStatus, n as PLAN_KEY_VALUES, o as isSubscriptionStatus, p as isPayoutMethod, r as SUBSCRIPTION_STATUS, s as PAYOUT_METHOD, t as PLAN_KEYS, u as SPLIT_STATUS_VALUES, v as SETTLEMENT_TYPE, w as HOLD_STATUS, x as isSettlementType, y as SETTLEMENT_TYPE_VALUES } from "./subscription.enums-95othr0i.mjs";
|
|
5
|
+
import { _ as WrongTransactionKindError, a as InvalidStateTransitionError, c as PaymentVerificationError, d as RefundNotSupportedError, f as RevenueError, g as ValidationError, h as TransactionNotFoundError, i as ConfigurationError, l as ProviderCapabilityError, m as SubscriptionNotFoundError, n as BankFeedImportError, o as MethodKindLockedError, p as SettlementNotFoundError, r as BankFeedProviderNotFoundError, s as PaymentIntentCreationError, t as AlreadyVerifiedError, u as ProviderNotFoundError } from "./errors-Bt5NRVMq.mjs";
|
|
5
6
|
import { BANK_FEED_STATE_MACHINE, HOLD_STATE_MACHINE, MANUAL_STATE_MACHINE, PAYMENT_FLOW_STATE_MACHINE, SETTLEMENT_STATE_MACHINE, SPLIT_STATE_MACHINE, SUBSCRIPTION_STATE_MACHINE, StateMachine, TRANSACTION_STATE_MACHINE, smFor } from "./core/state-machines.mjs";
|
|
6
|
-
import { a as reverseTax, c as reverseCommission, i as getTaxType, n as calculateSplits, o as validateTaxCalculation, r as calculateTax, s as calculateCommission, t as calculateOrganizationPayout } from "./splits-
|
|
7
|
-
import { n as SubscriptionRepository, r as TransactionRepository, t as SettlementRepository } from "./settlement.repository-Ba2U17zY.mjs";
|
|
7
|
+
import { a as reverseTax, c as reverseCommission, i as getTaxType, n as calculateSplits, o as validateTaxCalculation, r as calculateTax, s as calculateCommission, t as calculateOrganizationPayout } from "./splits-CNfQj92L.mjs";
|
|
8
8
|
import { createRevenueRepositories } from "./repositories/create-repositories.mjs";
|
|
9
|
-
import { a as createProviderRegistry, i as ProviderRegistry, n as BankFeedProviderRegistry, o as PaymentProvider, r as createBankFeedProviderRegistry, t as BankFeedProvider } from "./bank-feed-
|
|
10
|
-
import { M as revenueEventDefinitions, N as InProcessRevenueBus } from "./revenue-event-catalog-
|
|
9
|
+
import { a as createProviderRegistry, i as ProviderRegistry, n as BankFeedProviderRegistry, o as PaymentProvider, r as createBankFeedProviderRegistry, t as BankFeedProvider } from "./bank-feed-ClxNob_I.mjs";
|
|
10
|
+
import { M as revenueEventDefinitions, N as InProcessRevenueBus } from "./revenue-event-catalog-B9aZmNpL.mjs";
|
|
11
11
|
import { a as PAYMENT_GATEWAY_TYPE_VALUES, c as isPaymentGatewayType, i as PAYMENT_GATEWAY_TYPE, l as isPaymentStatus, n as MONETIZATION_TYPE_VALUES, o as PAYMENT_STATUS, r as isMonetizationType, s as PAYMENT_STATUS_VALUES, t as MONETIZATION_TYPES } from "./monetization.enums-B9HBOecd.mjs";
|
|
12
|
-
import { _ as transactionListFilterSchema, a as paymentVerifySchema, c as settlementCreateSchema, d as subscriptionBaseSchema, f as subscriptionCreateSchema, g as transactionCreateSchema, h as transactionBaseSchema, i as paymentIntentSchema, l as settlementListFilterSchema, m as subscriptionUpdateSchema, n as escrowReleaseSchema, o as refundSchema, p as subscriptionListFilterSchema, r as splitRuleSchema, s as settlementBaseSchema, t as escrowHoldSchema, u as settlementUpdateSchema, v as transactionUpdateSchema } from "./escrow.schema-
|
|
12
|
+
import { _ as transactionListFilterSchema, a as paymentVerifySchema, c as settlementCreateSchema, d as subscriptionBaseSchema, f as subscriptionCreateSchema, g as transactionCreateSchema, h as transactionBaseSchema, i as paymentIntentSchema, l as settlementListFilterSchema, m as subscriptionUpdateSchema, n as escrowReleaseSchema, o as refundSchema, p as subscriptionListFilterSchema, r as splitRuleSchema, s as settlementBaseSchema, t as escrowHoldSchema, u as settlementUpdateSchema, v as transactionUpdateSchema } from "./escrow.schema-BcKdzrJ7.mjs";
|
|
13
13
|
import { C as sumMoney, E as toSmallestUnit, S as subtractMoney, T as toMajor, _ as isZeroMoney, a as CurrencyMismatchError, b as multiplyMoney, c as addMoney, d as fromMajor, f as fromSmallestUnit, g as isPositiveMoney, h as isNegativeMoney, i as CURRENCIES, l as compareMoney, m as isMoney, n as getAuditTrail, o as MINOR_UNIT_FACTOR, p as isCurrencyCode, r as getLastStateChange, s as absMoney, t as appendAuditEvent, u as equalsMoney, v as minorUnitFactor, w as toCurrencyCode, x as negateMoney, y as money } from "./audit-Ba2XB2C4.mjs";
|
|
14
14
|
import { PluginManager } from "./plugins/plugin.interface.mjs";
|
|
15
15
|
import { batchOperationsPlugin, customIdPlugin, methodRegistryPlugin, multiTenantPlugin, prefixedId, softDeletePlugin } from "@classytic/mongokit";
|
|
16
16
|
import { resolveTenantConfig } from "@classytic/repo-core/tenant";
|
|
17
17
|
import mongoose, { Schema } from "mongoose";
|
|
18
|
+
import { PAYMENT_METHOD_KIND } from "@classytic/primitives/payment-method-kind";
|
|
18
19
|
import { InvalidOutboxEventError, OutboxOwnershipError } from "@classytic/primitives/outbox";
|
|
19
20
|
import { err, isErr, isOk, ok } from "@classytic/primitives/result";
|
|
20
21
|
|
|
21
22
|
//#region src/models/transaction.schema.ts
|
|
23
|
+
const PAYMENT_METHOD_KIND_ENUM = Object.values(PAYMENT_METHOD_KIND);
|
|
22
24
|
const NO_BANK_FEED_INDEXES = {
|
|
23
25
|
idempotentImport: false,
|
|
24
26
|
byAccount: false,
|
|
@@ -76,6 +78,11 @@ function buildTransactionSchema(config) {
|
|
|
76
78
|
type: String,
|
|
77
79
|
required: true
|
|
78
80
|
},
|
|
81
|
+
methodKind: {
|
|
82
|
+
type: String,
|
|
83
|
+
enum: PAYMENT_METHOD_KIND_ENUM,
|
|
84
|
+
required: true
|
|
85
|
+
},
|
|
79
86
|
status: {
|
|
80
87
|
type: String,
|
|
81
88
|
default: "pending"
|
|
@@ -572,4 +579,26 @@ async function createRevenue(config) {
|
|
|
572
579
|
}
|
|
573
580
|
|
|
574
581
|
//#endregion
|
|
575
|
-
|
|
582
|
+
//#region src/events/outbox-store.ts
|
|
583
|
+
var MemoryOutboxStore = class {
|
|
584
|
+
events = [];
|
|
585
|
+
async save(event, _options) {
|
|
586
|
+
this.events.push({ event });
|
|
587
|
+
}
|
|
588
|
+
async getPending(limit) {
|
|
589
|
+
return this.events.filter((e) => !e.acknowledgedAt).slice(0, limit).map((e) => e.event);
|
|
590
|
+
}
|
|
591
|
+
async acknowledge(eventId, _options) {
|
|
592
|
+
const entry = this.events.find((e) => e.event.meta.id === eventId);
|
|
593
|
+
if (entry) entry.acknowledgedAt = /* @__PURE__ */ new Date();
|
|
594
|
+
}
|
|
595
|
+
async purge(olderThanMs) {
|
|
596
|
+
const cutoff = Date.now() - olderThanMs;
|
|
597
|
+
const before = this.events.length;
|
|
598
|
+
this.events = this.events.filter((e) => !e.acknowledgedAt || e.acknowledgedAt.getTime() >= cutoff);
|
|
599
|
+
return before - this.events.length;
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
//#endregion
|
|
604
|
+
export { AlreadyVerifiedError, BANK_FEED_SOURCE, BANK_FEED_SOURCE_VALUES, BANK_FEED_STATE_MACHINE, BANK_FEED_STATUS, BANK_FEED_STATUS_VALUES, BankFeedImportError, BankFeedProvider, BankFeedProviderNotFoundError, BankFeedProviderRegistry, CURRENCIES, ConfigurationError, CurrencyMismatchError, HOLD_REASON, HOLD_REASON_VALUES, HOLD_STATE_MACHINE, HOLD_STATUS, HOLD_STATUS_VALUES, InProcessRevenueBus, InvalidOutboxEventError, InvalidStateTransitionError, LIBRARY_CATEGORIES, LIBRARY_CATEGORY_VALUES, MANUAL_STATE_MACHINE, MINOR_UNIT_FACTOR, MONETIZATION_TYPES, MONETIZATION_TYPE_VALUES, MemoryOutboxStore, MethodKindLockedError, OutboxOwnershipError, PAYMENT_FLOW_STATE_MACHINE, PAYMENT_GATEWAY_TYPE, PAYMENT_GATEWAY_TYPE_VALUES, PAYMENT_STATUS, PAYMENT_STATUS_VALUES, PAYOUT_METHOD, PAYOUT_METHOD_VALUES, PLAN_KEYS, PLAN_KEY_VALUES, PaymentIntentCreationError, PaymentProvider, PaymentVerificationError, PluginManager, ProviderCapabilityError, ProviderNotFoundError, ProviderRegistry, RELEASE_REASON, RELEASE_REASON_VALUES, REVENUE_EVENTS, RefundNotSupportedError, RevenueError, SETTLEMENT_STATE_MACHINE, SETTLEMENT_STATUS, SETTLEMENT_STATUS_VALUES, SETTLEMENT_TYPE, SETTLEMENT_TYPE_VALUES, SPLIT_STATE_MACHINE, SPLIT_STATUS, SPLIT_STATUS_VALUES, SPLIT_TYPE, SPLIT_TYPE_VALUES, SUBSCRIPTION_STATE_MACHINE, SUBSCRIPTION_STATUS, SUBSCRIPTION_STATUS_VALUES, SettlementNotFoundError, SettlementRepository, StateMachine, SubscriptionNotFoundError, SubscriptionRepository, TRANSACTION_FLOW, TRANSACTION_FLOW_VALUES, TRANSACTION_KIND, TRANSACTION_KIND_VALUES, TRANSACTION_STATE_MACHINE, TRANSACTION_STATUS, TRANSACTION_STATUS_VALUES, TransactionNotFoundError, TransactionRepository, ValidationError, WrongTransactionKindError, absMoney, addMoney, appendAuditEvent, calculateCommission, calculateOrganizationPayout, calculateSplits, calculateTax, compareMoney, createBankFeedProviderRegistry, createEvent, createProviderRegistry, createRevenue, equalsMoney, err, escrowHoldSchema, escrowReleaseSchema, fromMajor, fromSmallestUnit, getAuditTrail, getLastStateChange, getTaxType, initialStatusFor, isBankFeedSource, isBankFeedStatus, isCurrencyCode, isErr, isHoldReason, isHoldStatus, isLibraryCategory, isMonetizationType, isMoney, isNegativeMoney, isOk, isPaymentGatewayType, isPaymentStatus, isPayoutMethod, isPlanKey, isPositiveMoney, isReleaseReason, isSettlementStatus, isSettlementType, isSplitStatus, isSplitType, isStatusValidForKind, isSubscriptionStatus, isTransactionFlow, isTransactionKind, isTransactionStatus, isZeroMoney, minorUnitFactor, money, multiplyMoney, negateMoney, ok, paymentIntentSchema, paymentVerifySchema, refundSchema, revenueEventDefinitions, reverseCommission, reverseTax, settlementBaseSchema, settlementCreateSchema, settlementListFilterSchema, settlementUpdateSchema, smFor, splitRuleSchema, statusesForKind, subscriptionBaseSchema, subscriptionCreateSchema, subscriptionListFilterSchema, subscriptionUpdateSchema, subtractMoney, sumMoney, toCurrencyCode, toMajor, toSmallestUnit, transactionBaseSchema, transactionCreateSchema, transactionListFilterSchema, transactionUpdateSchema, validateTaxCalculation };
|
package/dist/providers/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as createProviderRegistry, i as ProviderRegistry, n as BankFeedProviderRegistry, o as PaymentProvider, r as createBankFeedProviderRegistry, t as BankFeedProvider } from "../bank-feed-
|
|
1
|
+
import { a as createProviderRegistry, i as ProviderRegistry, n as BankFeedProviderRegistry, o as PaymentProvider, r as createBankFeedProviderRegistry, t as BankFeedProvider } from "../bank-feed-ClxNob_I.mjs";
|
|
2
2
|
|
|
3
3
|
export { BankFeedProvider, BankFeedProviderRegistry, PaymentProvider, ProviderRegistry, createBankFeedProviderRegistry, createProviderRegistry };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as SubscriptionRepository, l as TransactionRepository, s as SettlementRepository, u as RevenueModels } from "../engine-types-
|
|
1
|
+
import { c as SubscriptionRepository, l as TransactionRepository, s as SettlementRepository, u as RevenueModels } from "../engine-types-ChFPg3kw.mjs";
|
|
2
2
|
import { PluginType } from "@classytic/mongokit";
|
|
3
3
|
|
|
4
4
|
//#region src/repositories/create-repositories.d.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as SubscriptionRepository, r as TransactionRepository, t as SettlementRepository } from "../settlement.repository-
|
|
1
|
+
import { n as SubscriptionRepository, r as TransactionRepository, t as SettlementRepository } from "../settlement.repository-CfvgX3et.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/repositories/create-repositories.ts
|
|
4
4
|
function createRevenueRepositories(models, builtInPlugins, hostPlugins = {}) {
|