@classytic/revenue 2.4.0 → 2.5.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.
@@ -1447,6 +1447,7 @@ var SettlementRepository = class extends RevenueRepositoryBase {
1447
1447
  };
1448
1448
  if (options.organizationId) query.organizationId = options.organizationId;
1449
1449
  if (options.payoutMethod) query.payoutMethod = options.payoutMethod;
1450
+ if (options.recipientId) query.recipientId = options.recipientId;
1450
1451
  const pending = (await this.getAll({
1451
1452
  filters: query,
1452
1453
  limit: options.limit ?? 50,
@@ -1562,6 +1563,53 @@ var SettlementRepository = class extends RevenueRepositoryBase {
1562
1563
  }), ctx);
1563
1564
  return updated;
1564
1565
  }
1566
+ async recipientBalance(recipientId, options = {}, ctx = {}) {
1567
+ const match = { recipientId };
1568
+ if (options.recipientType !== void 0) match.recipientType = options.recipientType;
1569
+ if (options.currency !== void 0) match.currency = options.currency;
1570
+ const now = /* @__PURE__ */ new Date();
1571
+ const rows = await this.aggregatePipeline([{ $match: match }, { $group: {
1572
+ _id: {
1573
+ status: "$status",
1574
+ due: { $lte: ["$scheduledAt", now] }
1575
+ },
1576
+ total: { $sum: "$amount" },
1577
+ currency: { $first: "$currency" }
1578
+ } }], this.optsFromCtx(ctx));
1579
+ const balance = {
1580
+ recipientId,
1581
+ currency: options.currency ?? null,
1582
+ pending: 0,
1583
+ held: 0,
1584
+ available: 0,
1585
+ processing: 0,
1586
+ paidOut: 0,
1587
+ failed: 0,
1588
+ lifetime: 0
1589
+ };
1590
+ for (const row of rows) {
1591
+ switch (row._id.status) {
1592
+ case SETTLEMENT_STATUS.PENDING:
1593
+ balance.pending += row.total;
1594
+ if (row._id.due) balance.available += row.total;
1595
+ else balance.held += row.total;
1596
+ break;
1597
+ case SETTLEMENT_STATUS.PROCESSING:
1598
+ balance.processing += row.total;
1599
+ break;
1600
+ case SETTLEMENT_STATUS.COMPLETED:
1601
+ balance.paidOut += row.total;
1602
+ break;
1603
+ case SETTLEMENT_STATUS.FAILED:
1604
+ balance.failed += row.total;
1605
+ break;
1606
+ default: break;
1607
+ }
1608
+ if (row.currency && !balance.currency) balance.currency = row.currency;
1609
+ }
1610
+ balance.lifetime = balance.pending + balance.processing + balance.paidOut;
1611
+ return balance;
1612
+ }
1565
1613
  };
1566
1614
 
1567
1615
  //#endregion
@@ -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-Cklvlywy.mjs";
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-o4qhjOca.mjs";
2
2
  import { z } from "zod";
3
3
 
4
4
  //#region src/validators/bank-feed.schema.d.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classytic/revenue",
3
- "version": "2.4.0",
3
+ "version": "2.5.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,