@classytic/revenue 2.3.0 → 2.4.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 +24 -0
- package/dist/{bank-feed.enums-CU38W8dv.mjs → bank-feed.enums-ByS3mjX0.mjs} +8 -4
- package/dist/{bank-feed.enums-BwJbImM6.d.mts → bank-feed.enums-CqTW2Blz.d.mts} +2 -0
- package/dist/core/state-machines.d.mts +1 -1
- package/dist/core/state-machines.mjs +13 -3
- package/dist/{engine-types-34VmC7t6.d.mts → engine-types-BU8kkttr.d.mts} +34 -2
- package/dist/enums/index.d.mts +1 -1
- package/dist/enums/index.mjs +1 -1
- package/dist/{escrow.schema-C_UeLtsC.d.mts → escrow.schema-Cklvlywy.d.mts} +19 -19
- package/dist/events/index.d.mts +1 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +2 -2
- package/dist/providers/index.d.mts +1 -1
- package/dist/{registry-BpEeN8eW.d.mts → registry-DSG7x-Cl.d.mts} +1 -1
- package/dist/repositories/create-repositories.d.mts +1 -1
- package/dist/repositories/create-repositories.mjs +1 -1
- package/dist/{revenue-event-catalog-j8Fh7Yag.d.mts → revenue-event-catalog-BU_KYN2-.d.mts} +126 -126
- package/dist/{settlement.repository-CdM3myTI.mjs → settlement.repository-DtLSBDIk.mjs} +64 -1
- package/dist/validators/index.d.mts +1 -1
- package/dist/validators/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as TRANSACTION_STATUS, a as TRANSACTION_KIND, s as initialStatusFor } from "./bank-feed.enums-
|
|
1
|
+
import { _ as TRANSACTION_STATUS, a as TRANSACTION_KIND, s as initialStatusFor } from "./bank-feed.enums-ByS3mjX0.mjs";
|
|
2
2
|
import { n as createEvent, t as REVENUE_EVENTS } from "./event-constants-DM_-A57b.mjs";
|
|
3
3
|
import { g as SETTLEMENT_STATUS, r as SUBSCRIPTION_STATUS, w as HOLD_STATUS } from "./subscription.enums-95othr0i.mjs";
|
|
4
4
|
import { _ as WrongTransactionKindError, g as ValidationError, h as TransactionNotFoundError, m as SubscriptionNotFoundError, n as BankFeedImportError, o as MethodKindLockedError, p as SettlementNotFoundError } from "./errors-Bt5NRVMq.mjs";
|
|
@@ -979,6 +979,69 @@ var TransactionRepository = class extends RevenueRepositoryBase {
|
|
|
979
979
|
return claimed;
|
|
980
980
|
}
|
|
981
981
|
/**
|
|
982
|
+
* Reconcile a bank-feed / manual row that settled a linked document
|
|
983
|
+
* (invoice/bill) WITHOUT posting a journal entry. The document's payment
|
|
984
|
+
* already owns the cash JE (`Dr Bank / Cr AR`), so the bank line only needs
|
|
985
|
+
* its status moved to `settled` — calling `match()` here would fire
|
|
986
|
+
* `LedgerBridge.onTransactionMatched` and double-count the cash. This is the
|
|
987
|
+
* package's intended path when the JE lives elsewhere (the reachable sibling
|
|
988
|
+
* of the born-`reconciled_external` import).
|
|
989
|
+
*
|
|
990
|
+
* `imported → settled` (bank_feed) / `pending → settled` (manual). Idempotent:
|
|
991
|
+
* a row already `settled` is returned unchanged, so a best-effort caller can
|
|
992
|
+
* safely re-run. The optional `metadata` is shallow-merged onto the document's
|
|
993
|
+
* `metadata` (dotted `$set`, so sibling keys survive) — hosts stamp the link
|
|
994
|
+
* back to the settling document there. No JE bridge call, no domain event:
|
|
995
|
+
* settlement is host-initiated and the host owns the reconcile audit trail.
|
|
996
|
+
*/
|
|
997
|
+
async settle(id, data = {}, ctx = {}) {
|
|
998
|
+
const existing = await this.getById(id, this.optsFromCtx(ctx));
|
|
999
|
+
if (!existing) throw new TransactionNotFoundError(id);
|
|
1000
|
+
if (existing.kind !== TRANSACTION_KIND.BANK_FEED && existing.kind !== TRANSACTION_KIND.MANUAL) throw new WrongTransactionKindError(id, "bank_feed | manual", existing.kind);
|
|
1001
|
+
if (existing.status === TRANSACTION_STATUS.SETTLED) return existing;
|
|
1002
|
+
smFor(existing.kind).validate(existing.status, TRANSACTION_STATUS.SETTLED, id);
|
|
1003
|
+
const set = {
|
|
1004
|
+
verifiedAt: /* @__PURE__ */ new Date(),
|
|
1005
|
+
...data.settledBy !== void 0 ? { verifiedBy: data.settledBy } : {}
|
|
1006
|
+
};
|
|
1007
|
+
if (data.metadata) for (const [k, v] of Object.entries(data.metadata)) set[`metadata.${k}`] = v;
|
|
1008
|
+
const claimed = await this.claim(existing._id, {
|
|
1009
|
+
from: [TRANSACTION_STATUS.IMPORTED, TRANSACTION_STATUS.PENDING],
|
|
1010
|
+
to: TRANSACTION_STATUS.SETTLED,
|
|
1011
|
+
where: { kind: existing.kind }
|
|
1012
|
+
}, { $set: set }, this.optsFromCtx(ctx));
|
|
1013
|
+
if (!claimed) throw new ValidationError(`Transaction ${id} could not be settled (race-loss or illegal state)`);
|
|
1014
|
+
return claimed;
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Reverse a `settle()` — the linked document's payment was undone, so the
|
|
1018
|
+
* bank line returns to its birth status to re-enter the reconcile queue.
|
|
1019
|
+
* `settled → imported` (bank_feed) / `settled → pending` (manual). Clears
|
|
1020
|
+
* `verifiedAt`/`verifiedBy` plus any metadata keys named in `clearMetadata`
|
|
1021
|
+
* (the host-stamped link back to the now-reversed document). Idempotent: a
|
|
1022
|
+
* row not currently `settled` is returned unchanged.
|
|
1023
|
+
*/
|
|
1024
|
+
async unsettle(id, data = {}, ctx = {}) {
|
|
1025
|
+
const existing = await this.getById(id, this.optsFromCtx(ctx));
|
|
1026
|
+
if (!existing) throw new TransactionNotFoundError(id);
|
|
1027
|
+
if (existing.kind !== TRANSACTION_KIND.BANK_FEED && existing.kind !== TRANSACTION_KIND.MANUAL) throw new WrongTransactionKindError(id, "bank_feed | manual", existing.kind);
|
|
1028
|
+
if (existing.status !== TRANSACTION_STATUS.SETTLED) return existing;
|
|
1029
|
+
const target = existing.kind === TRANSACTION_KIND.MANUAL ? TRANSACTION_STATUS.PENDING : TRANSACTION_STATUS.IMPORTED;
|
|
1030
|
+
smFor(existing.kind).validate(TRANSACTION_STATUS.SETTLED, target, id);
|
|
1031
|
+
const unset = {
|
|
1032
|
+
verifiedBy: 1,
|
|
1033
|
+
verifiedAt: 1
|
|
1034
|
+
};
|
|
1035
|
+
for (const k of data.clearMetadata ?? []) unset[`metadata.${k}`] = 1;
|
|
1036
|
+
const claimed = await this.claim(existing._id, {
|
|
1037
|
+
from: TRANSACTION_STATUS.SETTLED,
|
|
1038
|
+
to: target,
|
|
1039
|
+
where: { kind: existing.kind }
|
|
1040
|
+
}, { $unset: unset }, this.optsFromCtx(ctx));
|
|
1041
|
+
if (!claimed) throw new ValidationError(`Transaction ${id} could not be un-settled (current state is not 'settled')`);
|
|
1042
|
+
return claimed;
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
982
1045
|
* Stamp the journal entry reference and transition `matched →
|
|
983
1046
|
* journalized`. Typical caller is the `LedgerBridge.onTransactionMatched`
|
|
984
1047
|
* implementation — after creating a JE, it calls this verb so the row
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
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-
|
|
1
|
+
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-Cklvlywy.mjs";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
4
|
//#region src/validators/bank-feed.schema.d.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as BANK_FEED_SOURCE_VALUES, o as TRANSACTION_KIND_VALUES } from "../bank-feed.enums-
|
|
1
|
+
import { n as BANK_FEED_SOURCE_VALUES, o as TRANSACTION_KIND_VALUES } from "../bank-feed.enums-ByS3mjX0.mjs";
|
|
2
2
|
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";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@classytic/revenue",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Payment lifecycle engine — transactions, subscriptions, escrow, settlements, commissions. MongoKit-powered, Arc-compatible, framework-agnostic.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|