@develit-services/ledger 0.3.1 → 0.3.3

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.
@@ -1,9 +1,9 @@
1
1
  import { first, develitWorker, uuidv4, useResult, createInternalError, action, service } from '@develit-io/backend-sdk';
2
2
  import { WorkerEntrypoint } from 'cloudflare:workers';
3
3
  import { drizzle } from 'drizzle-orm/d1';
4
- import { s as schema } from '../shared/ledger.149a0ags.mjs';
4
+ import { s as schema } from '../shared/ledger.B-gGCFFu.mjs';
5
5
  import { eq, and, inArray, or, count, gte, lte, sql, asc, desc } from 'drizzle-orm';
6
- import { j as createTransactionInputSchema, w as matchTransactionInputSchema, l as failTransactionInputSchema, h as cancelTransactionInputSchema, r as getTransactionByIdInputSchema, s as getTransactionsByReferenceIdInputSchema, t as getTransactionsInputSchema, i as createAccountInputSchema, x as updateAccountInputSchema, k as deleteAccountInputSchema, p as getAccountInputSchema, q as getAccountsByOwnerInputSchema, v as listAccountsInputSchema, o as getAccountIdentifierInputSchema, u as listAccountIdentifiersInputSchema, m as findAccountByIdentifierInputSchema, n as getAccountBalanceInputSchema, y as updateTransactionConfirmationSentAtInputSchema } from '../shared/ledger.DkcYdsVZ.mjs';
6
+ import { k as createTransactionInputSchema, x as matchTransactionInputSchema, m as failTransactionInputSchema, i as cancelTransactionInputSchema, y as refundTransactionInputSchema, g as REFUNDABLE_TRANSACTION_STATUSES, s as getTransactionByIdInputSchema, t as getTransactionsByReferenceIdInputSchema, u as getTransactionsInputSchema, j as createAccountInputSchema, z as updateAccountInputSchema, l as deleteAccountInputSchema, q as getAccountInputSchema, r as getAccountsByOwnerInputSchema, w as listAccountsInputSchema, p as getAccountIdentifierInputSchema, v as listAccountIdentifiersInputSchema, n as findAccountByIdentifierInputSchema, o as getAccountBalanceInputSchema, D as updateTransactionConfirmationSentAtInputSchema, F as updateTransactionStatusInputSchema } from '../shared/ledger.DWO4eS7Q.mjs';
7
7
  import '@develit-io/general-codes';
8
8
  import 'drizzle-orm/sqlite-core';
9
9
  import 'zod';
@@ -534,6 +534,142 @@ let LedgerServiceBase = class extends develitWorker(
534
534
  }
535
535
  );
536
536
  }
537
+ async refundTransaction(input) {
538
+ return this.handleAction(
539
+ { data: input, schema: refundTransactionInputSchema },
540
+ { successMessage: "Transaction successfully refunded." },
541
+ async (params) => {
542
+ const { transactionId, amount, reason } = params;
543
+ const originalTx = await getTransactionByIdQuery(this.db, transactionId);
544
+ if (!originalTx) {
545
+ throw createInternalError(null, {
546
+ message: "Transaction not found",
547
+ status: 404,
548
+ code: "DB-L-03"
549
+ });
550
+ }
551
+ if (!REFUNDABLE_TRANSACTION_STATUSES.some(
552
+ (status) => status === originalTx.status
553
+ )) {
554
+ throw createInternalError(null, {
555
+ message: `Transaction with status ${originalTx.status} cannot be refunded`,
556
+ status: 400,
557
+ code: "VALID-L-01"
558
+ });
559
+ }
560
+ const refundAmount = amount || originalTx.value || 0;
561
+ if (refundAmount <= 0) {
562
+ throw createInternalError(null, {
563
+ message: "Invalid refund amount",
564
+ status: 400,
565
+ code: "VALID-L-02"
566
+ });
567
+ }
568
+ if (originalTx.value && refundAmount > originalTx.value) {
569
+ throw createInternalError(null, {
570
+ message: "Refund amount exceeds transaction value",
571
+ status: 400,
572
+ code: "VALID-L-03"
573
+ });
574
+ }
575
+ const originalPayment = originalTx.metadata?.payment;
576
+ if (!originalPayment?.debtor || !originalPayment?.creditor) {
577
+ throw createInternalError(null, {
578
+ message: "Transaction missing payment information for refund",
579
+ status: 400,
580
+ code: "VALID-L-04"
581
+ });
582
+ }
583
+ if (!originalTx.currency) {
584
+ throw createInternalError(null, {
585
+ message: "Transaction missing currency information",
586
+ status: 400,
587
+ code: "VALID-L-05"
588
+ });
589
+ }
590
+ const refundTxId = uuidv4();
591
+ const correlationId = uuidv4();
592
+ const timestamp = /* @__PURE__ */ new Date();
593
+ const isPartialRefund = amount !== void 0 && originalTx.value != null && amount < originalTx.value;
594
+ const refundTransaction = {
595
+ id: refundTxId,
596
+ correlationId,
597
+ referenceType: "TRANSACTION",
598
+ referenceId: transactionId,
599
+ type: "REFUND",
600
+ description: `Refund: ${reason}`,
601
+ status: "WAITING_FOR_PAYMENT",
602
+ value: refundAmount,
603
+ currency: originalTx.currency,
604
+ createdAt: timestamp,
605
+ updatedAt: timestamp,
606
+ completedAt: null,
607
+ metadata: {
608
+ tags: ["refund", `refund-${originalTx.type.toLowerCase()}`],
609
+ note: reason,
610
+ payment: {
611
+ amount: refundAmount,
612
+ currency: originalPayment.currency,
613
+ type: originalPayment.type || "DOMESTIC",
614
+ vs: originalPayment.vs,
615
+ ss: originalPayment.ss,
616
+ ks: originalPayment.ks,
617
+ debtor: originalPayment.creditor,
618
+ creditor: originalPayment.debtor
619
+ },
620
+ refund: {
621
+ isPartialRefund
622
+ }
623
+ }
624
+ };
625
+ const insertRefundCommand = this.db.insert(tables.transaction).values(refundTransaction).returning();
626
+ const { command: updateOriginalCommand } = updateTransactionStatusCommand(this.db, {
627
+ transactionId,
628
+ status: "RETURNING",
629
+ statusReason: `Refund in progress via transaction ${refundTxId}`
630
+ });
631
+ const [refundResult, originalResult] = await this.db.batch([
632
+ insertRefundCommand,
633
+ updateOriginalCommand
634
+ ]);
635
+ const createdRefundTx = first(refundResult);
636
+ const updatedOriginalTx = first(originalResult);
637
+ if (!createdRefundTx || !updatedOriginalTx) {
638
+ throw createInternalError(null, {
639
+ message: "Failed to process refund transaction",
640
+ status: 500,
641
+ code: "DB-L-02"
642
+ });
643
+ }
644
+ await Promise.all([
645
+ this.pushToQueue(this.env.QUEUE_BUS_QUEUE, {
646
+ eventType: "LEDGER_TRANSACTION",
647
+ eventSignal: "created",
648
+ ledgerTransaction: createdRefundTx,
649
+ metadata: {
650
+ correlationId: uuidv4(),
651
+ entityId: createdRefundTx.id,
652
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
653
+ }
654
+ }),
655
+ this.pushToQueue(this.env.QUEUE_BUS_QUEUE, {
656
+ eventType: "LEDGER_TRANSACTION",
657
+ eventSignal: "refunding",
658
+ ledgerTransaction: updatedOriginalTx,
659
+ metadata: {
660
+ correlationId: uuidv4(),
661
+ entityId: updatedOriginalTx.id,
662
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
663
+ }
664
+ })
665
+ ]);
666
+ return {
667
+ refundTransaction: createdRefundTx,
668
+ originalTransaction: updatedOriginalTx
669
+ };
670
+ }
671
+ );
672
+ }
537
673
  async getTransactionById(input) {
538
674
  return this.handleAction(
539
675
  { data: input, schema: getTransactionByIdInputSchema },
@@ -797,6 +933,56 @@ let LedgerServiceBase = class extends develitWorker(
797
933
  }
798
934
  );
799
935
  }
936
+ async updateTransactionStatus(input) {
937
+ return this.handleAction(
938
+ { data: input, schema: updateTransactionStatusInputSchema },
939
+ { successMessage: "Transaction status successfully updated." },
940
+ async (params) => {
941
+ const { transactionId, status, statusReason, paymentId, completedAt } = params;
942
+ const existingTransaction = await getTransactionByIdQuery(
943
+ this.db,
944
+ transactionId
945
+ );
946
+ if (!existingTransaction) {
947
+ throw createInternalError(null, {
948
+ message: "Transaction not found",
949
+ status: 404,
950
+ code: "NOT_FOUND"
951
+ });
952
+ }
953
+ const { command } = updateTransactionStatusCommand(this.db, {
954
+ transactionId,
955
+ status,
956
+ statusReason,
957
+ paymentId,
958
+ completedAt
959
+ });
960
+ const [updatedTransaction] = await this.db.batch([command]);
961
+ if (!updatedTransaction) {
962
+ throw createInternalError(null, {
963
+ message: "Failed to update transaction",
964
+ status: 500,
965
+ code: "INTERNAL_ERROR"
966
+ });
967
+ }
968
+ const transaction = first(updatedTransaction);
969
+ await this.pushToQueue(
970
+ this.env.QUEUE_BUS_QUEUE,
971
+ {
972
+ eventType: "LEDGER_TRANSACTION",
973
+ eventSignal: "updated",
974
+ ledgerTransaction: transaction,
975
+ metadata: {
976
+ correlationId: uuidv4(),
977
+ entityId: transaction.id,
978
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
979
+ }
980
+ }
981
+ );
982
+ return transaction;
983
+ }
984
+ );
985
+ }
800
986
  };
801
987
  __decorateClass([
802
988
  action("create-transaction")
@@ -810,6 +996,9 @@ __decorateClass([
810
996
  __decorateClass([
811
997
  action("cancel-transaction")
812
998
  ], LedgerServiceBase.prototype, "cancelTransaction", 1);
999
+ __decorateClass([
1000
+ action("refund-transaction")
1001
+ ], LedgerServiceBase.prototype, "refundTransaction", 1);
813
1002
  __decorateClass([
814
1003
  action("get-transaction-by-id")
815
1004
  ], LedgerServiceBase.prototype, "getTransactionById", 1);
@@ -852,6 +1041,9 @@ __decorateClass([
852
1041
  __decorateClass([
853
1042
  action("update-transaction-confirmation-sent-at")
854
1043
  ], LedgerServiceBase.prototype, "updateTransactionConfirmationSentAt", 1);
1044
+ __decorateClass([
1045
+ action("update-transaction-status")
1046
+ ], LedgerServiceBase.prototype, "updateTransactionStatus", 1);
855
1047
  LedgerServiceBase = __decorateClass([
856
1048
  service("ledger")
857
1049
  ], LedgerServiceBase);
@@ -1,7 +1,7 @@
1
1
  import { base } from '@develit-io/backend-sdk';
2
2
  import { relations } from 'drizzle-orm';
3
3
  import { sqliteTable, integer, text, real } from 'drizzle-orm/sqlite-core';
4
- import { T as TRANSACTION_STATUSES, g as TRANSACTION_TYPES, R as REFERENCE_TYPES } from './ledger.DkcYdsVZ.mjs';
4
+ import { T as TRANSACTION_STATUSES, h as TRANSACTION_TYPES, R as REFERENCE_TYPES } from './ledger.DWO4eS7Q.mjs';
5
5
  import '@develit-io/general-codes';
6
6
 
7
7
  const account = sqliteTable("account", {
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { D as schema } from './ledger.Ci2NnLFo.cjs';
2
+ import { F as schema } from './ledger.aRF1eJOD.js';
3
3
  import { InferSelectModel, ExtractTablesWithRelations, DBQueryConfig, BuildQueryResult, InferInsertModel } from 'drizzle-orm';
4
4
 
5
5
  interface TSchema extends ExtractTablesWithRelations<typeof tables> {
@@ -415,6 +415,7 @@ declare const createTransactionInputSchema: z.ZodObject<{
415
415
  ORDER: "ORDER";
416
416
  "INTERNAL-TRANSFER": "INTERNAL-TRANSFER";
417
417
  FORWARD: "FORWARD";
418
+ TRANSACTION: "TRANSACTION";
418
419
  }>;
419
420
  referenceId: z.ZodOptional<z.ZodString>;
420
421
  type: z.ZodEnum<{
@@ -423,10 +424,12 @@ declare const createTransactionInputSchema: z.ZodObject<{
423
424
  CLIENT_FUND_OUT: "CLIENT_FUND_OUT";
424
425
  PROVIDER_FUND_IN: "PROVIDER_FUND_IN";
425
426
  PROVIDER_FUND_OUT: "PROVIDER_FUND_OUT";
427
+ COLLATERAL_FUND_IN: "COLLATERAL_FUND_IN";
428
+ COLLATERAL_FUND_OUT: "COLLATERAL_FUND_OUT";
426
429
  UNMATCHED: "UNMATCHED";
427
430
  ADJUSTMENT: "ADJUSTMENT";
428
431
  TRANSFER: "TRANSFER";
429
- COLLATERAL: "COLLATERAL";
432
+ REFUND: "REFUND";
430
433
  }>;
431
434
  description: z.ZodOptional<z.ZodString>;
432
435
  paymentId: z.ZodOptional<z.ZodString>;
@@ -1174,9 +1177,6 @@ declare const createTransactionInputSchema: z.ZodObject<{
1174
1177
  status: z.ZodEnum<{
1175
1178
  FAILED: "FAILED";
1176
1179
  WAITING_FOR_PAYMENT: "WAITING_FOR_PAYMENT";
1177
- WAITING_FOR_COLLATERAL: "WAITING_FOR_COLLATERAL";
1178
- COLLATERAL_PAID: "COLLATERAL_PAID";
1179
- PAUSED: "PAUSED";
1180
1180
  WAITING_FOR_MANUAL_PROCESSING: "WAITING_FOR_MANUAL_PROCESSING";
1181
1181
  MATCHED: "MATCHED";
1182
1182
  RETURNING: "RETURNING";
@@ -1382,6 +1382,7 @@ declare const getTransactionsInputSchema: z.ZodObject<{
1382
1382
  ORDER: "ORDER";
1383
1383
  "INTERNAL-TRANSFER": "INTERNAL-TRANSFER";
1384
1384
  FORWARD: "FORWARD";
1385
+ TRANSACTION: "TRANSACTION";
1385
1386
  }>>;
1386
1387
  filterTransactionReferenceId: z.ZodOptional<z.ZodUUID>;
1387
1388
  filterTransactionType: z.ZodOptional<z.ZodEnum<{
@@ -1390,10 +1391,12 @@ declare const getTransactionsInputSchema: z.ZodObject<{
1390
1391
  CLIENT_FUND_OUT: "CLIENT_FUND_OUT";
1391
1392
  PROVIDER_FUND_IN: "PROVIDER_FUND_IN";
1392
1393
  PROVIDER_FUND_OUT: "PROVIDER_FUND_OUT";
1394
+ COLLATERAL_FUND_IN: "COLLATERAL_FUND_IN";
1395
+ COLLATERAL_FUND_OUT: "COLLATERAL_FUND_OUT";
1393
1396
  UNMATCHED: "UNMATCHED";
1394
1397
  ADJUSTMENT: "ADJUSTMENT";
1395
1398
  TRANSFER: "TRANSFER";
1396
- COLLATERAL: "COLLATERAL";
1399
+ REFUND: "REFUND";
1397
1400
  }>>;
1398
1401
  filterTransactionDescription: z.ZodOptional<z.ZodString>;
1399
1402
  filterTransactionDateFrom: z.ZodOptional<z.ZodDate>;
@@ -1402,9 +1405,6 @@ declare const getTransactionsInputSchema: z.ZodObject<{
1402
1405
  filterTransactionStatus: z.ZodOptional<z.ZodEnum<{
1403
1406
  FAILED: "FAILED";
1404
1407
  WAITING_FOR_PAYMENT: "WAITING_FOR_PAYMENT";
1405
- WAITING_FOR_COLLATERAL: "WAITING_FOR_COLLATERAL";
1406
- COLLATERAL_PAID: "COLLATERAL_PAID";
1407
- PAUSED: "PAUSED";
1408
1408
  WAITING_FOR_MANUAL_PROCESSING: "WAITING_FOR_MANUAL_PROCESSING";
1409
1409
  MATCHED: "MATCHED";
1410
1410
  RETURNING: "RETURNING";
@@ -1428,6 +1428,7 @@ declare const getTransactionsByReferenceIdInputSchema: z.ZodObject<{
1428
1428
  ORDER: "ORDER";
1429
1429
  "INTERNAL-TRANSFER": "INTERNAL-TRANSFER";
1430
1430
  FORWARD: "FORWARD";
1431
+ TRANSACTION: "TRANSACTION";
1431
1432
  }>;
1432
1433
  referenceId: z.ZodUUID;
1433
1434
  }, z.core.$strip>;
@@ -1646,7 +1647,40 @@ interface UpdateTransactionConfirmationSentAtInput extends z.input<typeof update
1646
1647
  }
1647
1648
  type UpdateTransactionConfirmationSentAtOutput = void;
1648
1649
 
1650
+ declare const refundTransactionInputSchema: z.ZodObject<{
1651
+ transactionId: z.ZodUUID;
1652
+ amount: z.ZodOptional<z.ZodNumber>;
1653
+ reason: z.ZodString;
1654
+ }, z.core.$strip>;
1655
+ interface RefundTransactionInput extends z.infer<typeof refundTransactionInputSchema> {
1656
+ }
1657
+ interface RefundTransactionOutput {
1658
+ refundTransaction: TransactionSelectType;
1659
+ originalTransaction: TransactionSelectType;
1660
+ }
1661
+
1662
+ declare const updateTransactionStatusInputSchema: z.ZodObject<{
1663
+ transactionId: z.ZodUUID;
1664
+ status: z.ZodEnum<{
1665
+ FAILED: "FAILED";
1666
+ WAITING_FOR_PAYMENT: "WAITING_FOR_PAYMENT";
1667
+ WAITING_FOR_MANUAL_PROCESSING: "WAITING_FOR_MANUAL_PROCESSING";
1668
+ MATCHED: "MATCHED";
1669
+ RETURNING: "RETURNING";
1670
+ RETURNED: "RETURNED";
1671
+ CANCELLED: "CANCELLED";
1672
+ SETTLED: "SETTLED";
1673
+ }>;
1674
+ statusReason: z.ZodOptional<z.ZodString>;
1675
+ paymentId: z.ZodOptional<z.ZodString>;
1676
+ completedAt: z.ZodOptional<z.ZodDate>;
1677
+ }, z.core.$strip>;
1678
+ interface UpdateTransactionStatusInput extends z.infer<typeof updateTransactionStatusInputSchema> {
1679
+ }
1680
+ interface UpdateTransactionStatusOutput extends TransactionSelectType {
1681
+ }
1682
+
1649
1683
  declare const tables: typeof schema;
1650
1684
 
1651
- export { findAccountByIdentifierInputSchema as $, cancelTransactionInputSchema as W, createAccountInputSchema as X, createTransactionInputSchema as Y, deleteAccountInputSchema as Z, failTransactionInputSchema as _, getAccountBalanceInputSchema as a0, getAccountIdentifierInputSchema as a1, getAccountInputSchema as a2, getAccountsByOwnerInputSchema as a3, getTransactionByIdInputSchema as a4, getTransactionsByReferenceIdInputSchema as a5, getTransactionsInputSchema as a6, listAccountIdentifiersInputSchema as a7, listAccountsInputSchema as a8, matchTransactionInputSchema as a9, updateAccountInputSchema as aa, updateTransactionConfirmationSentAtInputSchema as ab, tables as t };
1652
- export type { GetAccountBalanceInput as A, GetAccountBalanceOutput as B, CreateTransactionInput as C, DeleteAccountInput as D, UpdateTransactionConfirmationSentAtInput as E, FailTransactionInput as F, GetTransactionByIdInput as G, UpdateTransactionConfirmationSentAtOutput as H, AccountIdentifierInsertType as I, AccountIdentifierMappingInsertType as J, AccountIdentifierMappingSelectType as K, ListAccountsInput as L, MatchTransactionInput as M, AccountIdentifierSelectType as N, AccountInsertType as O, AccountSelectType as P, AccountWithIdentifiersSelectType as Q, IncludeRelation as R, InferResultType as S, TransactionSelectType as T, UpdateAccountInput as U, TransactionInsertType as V, CreateTransactionOutput as a, MatchTransactionOutput as b, FailTransactionOutput as c, CancelTransactionInput as d, CancelTransactionOutput as e, GetTransactionByIdOutput as f, GetTransactionsByIdReferenceInput as g, GetTransactionsByReferenceIdOutput as h, GetTransactionsInput as i, GetTransactionsOutput as j, CreateAccountInput as k, CreateAccountOutput as l, UpdateAccountOutput as m, DeleteAccountOutput as n, GetAccountInput as o, GetAccountOutput as p, GetAccountsByOwnerInput as q, GetAccountsByOwnerOutput as r, ListAccountsOutput as s, GetAccountIdentifierInput as u, GetAccountIdentifierOutput as v, ListAccountIdentifiersInput as w, ListAccountIdentifiersOutput as x, FindAccountByIdentifierInput as y, FindAccountByIdentifierOutput as z };
1685
+ export { createAccountInputSchema as $, cancelTransactionInputSchema as _, createTransactionInputSchema as a0, deleteAccountInputSchema as a1, failTransactionInputSchema as a2, findAccountByIdentifierInputSchema as a3, getAccountBalanceInputSchema as a4, getAccountIdentifierInputSchema as a5, getAccountInputSchema as a6, getAccountsByOwnerInputSchema as a7, getTransactionByIdInputSchema as a8, getTransactionsByReferenceIdInputSchema as a9, getTransactionsInputSchema as aa, listAccountIdentifiersInputSchema as ab, listAccountsInputSchema as ac, matchTransactionInputSchema as ad, refundTransactionInputSchema as ae, updateAccountInputSchema as af, updateTransactionConfirmationSentAtInputSchema as ag, updateTransactionStatusInputSchema as ah, tables as t };
1686
+ export type { FindAccountByIdentifierOutput as A, GetAccountBalanceInput as B, CreateTransactionInput as C, DeleteAccountInput as D, GetAccountBalanceOutput as E, FailTransactionInput as F, GetTransactionByIdInput as G, UpdateTransactionConfirmationSentAtInput as H, UpdateTransactionConfirmationSentAtOutput as I, UpdateTransactionStatusInput as J, UpdateTransactionStatusOutput as K, ListAccountsInput as L, MatchTransactionInput as M, AccountIdentifierInsertType as N, AccountIdentifierMappingInsertType as O, AccountIdentifierMappingSelectType as P, AccountIdentifierSelectType as Q, RefundTransactionInput as R, AccountInsertType as S, TransactionSelectType as T, UpdateAccountInput as U, AccountSelectType as V, AccountWithIdentifiersSelectType as W, IncludeRelation as X, InferResultType as Y, TransactionInsertType as Z, CreateTransactionOutput as a, MatchTransactionOutput as b, FailTransactionOutput as c, CancelTransactionInput as d, CancelTransactionOutput as e, RefundTransactionOutput as f, GetTransactionByIdOutput as g, GetTransactionsByIdReferenceInput as h, GetTransactionsByReferenceIdOutput as i, GetTransactionsInput as j, GetTransactionsOutput as k, CreateAccountInput as l, CreateAccountOutput as m, UpdateAccountOutput as n, DeleteAccountOutput as o, GetAccountInput as p, GetAccountOutput as q, GetAccountsByOwnerInput as r, GetAccountsByOwnerOutput as s, ListAccountsOutput as u, GetAccountIdentifierInput as v, GetAccountIdentifierOutput as w, ListAccountIdentifiersInput as x, ListAccountIdentifiersOutput as y, FindAccountByIdentifierInput as z };
@@ -59,9 +59,7 @@ const ENTRY_STATUSES = [
59
59
  ];
60
60
  const TRANSACTION_STATUSES = [
61
61
  "WAITING_FOR_PAYMENT",
62
- "WAITING_FOR_COLLATERAL",
63
- "COLLATERAL_PAID",
64
- "PAUSED",
62
+ // 'PAUSED',
65
63
  "WAITING_FOR_MANUAL_PROCESSING",
66
64
  "MATCHED",
67
65
  "RETURNING",
@@ -69,31 +67,37 @@ const TRANSACTION_STATUSES = [
69
67
  "FAILED",
70
68
  "CANCELLED",
71
69
  "SETTLED"
70
+ // not used for now, but maybe in future when we have settlement process implemented
72
71
  ];
73
72
  const TRANSACTION_TYPES = [
74
73
  "CLIENT_FUND_IN",
75
74
  "CLIENT_FUND_OUT",
76
75
  "PROVIDER_FUND_IN",
77
76
  "PROVIDER_FUND_OUT",
77
+ "COLLATERAL_FUND_IN",
78
+ "COLLATERAL_FUND_OUT",
78
79
  "EXCHANGE",
79
80
  // maybe in future
80
81
  "UNMATCHED",
81
82
  "ADJUSTMENT",
82
- // manual correction
83
+ // manual correction maybe in future
83
84
  "TRANSFER",
84
85
  // internal transfer between accounts
85
- "COLLATERAL"
86
- // forward collateral payment from client
86
+ "REFUND"
87
87
  ];
88
88
  const REFERENCE_TYPES = [
89
89
  "PAYMENT",
90
90
  "EXCHANGE",
91
91
  "ORDER",
92
92
  "INTERNAL-TRANSFER",
93
- "FORWARD"
93
+ "FORWARD",
94
+ "TRANSACTION"
94
95
  ];
95
96
  const PAYMENT_CHARGE_TYPES = ["SHA", "OUR", "BEN"];
96
97
  const PAYMENT_TYPES = ["DOMESTIC", "SEPA", "SWIFT", "UNKNOWN"];
98
+ const REFUNDABLE_TRANSACTION_STATUSES = [
99
+ "WAITING_FOR_MANUAL_PROCESSING"
100
+ ];
97
101
 
98
102
  const ALLOWED_TRANSACTION_FILTERS = {
99
103
  CORRELATION_ID: "filterTransactionCorrelationId",
@@ -309,4 +313,18 @@ const updateTransactionConfirmationSentAtInputSchema = z.object({
309
313
  transactionId: z.uuid()
310
314
  });
311
315
 
312
- export { ACCOUNT_TYPES as A, BALANCE_STRATEGIES as B, COUNTRY_CODES as C, ENTRY_STATUSES as E, IDENTIFIER_KINDS as I, PAYMENT_CHARGE_TYPES as P, REFERENCE_TYPES as R, TRANSACTION_STATUSES as T, ALLOWED_TRANSACTION_FILTERS as a, ASSET_TYPES as b, BATCH_STATUSES as c, PAYMENT_DIRECTIONS as d, PAYMENT_STATUSES as e, PAYMENT_TYPES as f, TRANSACTION_TYPES as g, cancelTransactionInputSchema as h, createAccountInputSchema as i, createTransactionInputSchema as j, deleteAccountInputSchema as k, failTransactionInputSchema as l, findAccountByIdentifierInputSchema as m, getAccountBalanceInputSchema as n, getAccountIdentifierInputSchema as o, getAccountInputSchema as p, getAccountsByOwnerInputSchema as q, getTransactionByIdInputSchema as r, getTransactionsByReferenceIdInputSchema as s, getTransactionsInputSchema as t, listAccountIdentifiersInputSchema as u, listAccountsInputSchema as v, matchTransactionInputSchema as w, updateAccountInputSchema as x, updateTransactionConfirmationSentAtInputSchema as y };
316
+ const refundTransactionInputSchema = z.object({
317
+ transactionId: z.uuid(),
318
+ amount: z.number().positive().optional(),
319
+ reason: z.string().min(1)
320
+ });
321
+
322
+ const updateTransactionStatusInputSchema = z.object({
323
+ transactionId: z.uuid(),
324
+ status: z.enum(TRANSACTION_STATUSES),
325
+ statusReason: z.string().optional(),
326
+ paymentId: z.string().optional(),
327
+ completedAt: z.date().optional()
328
+ });
329
+
330
+ export { ACCOUNT_TYPES as A, BALANCE_STRATEGIES as B, COUNTRY_CODES as C, updateTransactionConfirmationSentAtInputSchema as D, ENTRY_STATUSES as E, updateTransactionStatusInputSchema as F, IDENTIFIER_KINDS as I, PAYMENT_CHARGE_TYPES as P, REFERENCE_TYPES as R, TRANSACTION_STATUSES as T, ALLOWED_TRANSACTION_FILTERS as a, ASSET_TYPES as b, BATCH_STATUSES as c, PAYMENT_DIRECTIONS as d, PAYMENT_STATUSES as e, PAYMENT_TYPES as f, REFUNDABLE_TRANSACTION_STATUSES as g, TRANSACTION_TYPES as h, cancelTransactionInputSchema as i, createAccountInputSchema as j, createTransactionInputSchema as k, deleteAccountInputSchema as l, failTransactionInputSchema as m, findAccountByIdentifierInputSchema as n, getAccountBalanceInputSchema as o, getAccountIdentifierInputSchema as p, getAccountInputSchema as q, getAccountsByOwnerInputSchema as r, getTransactionByIdInputSchema as s, getTransactionsByReferenceIdInputSchema as t, getTransactionsInputSchema as u, listAccountIdentifiersInputSchema as v, listAccountsInputSchema as w, matchTransactionInputSchema as x, refundTransactionInputSchema as y, updateAccountInputSchema as z };
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { D as schema } from './ledger.Ci2NnLFo.js';
2
+ import { F as schema } from './ledger.aRF1eJOD.cjs';
3
3
  import { InferSelectModel, ExtractTablesWithRelations, DBQueryConfig, BuildQueryResult, InferInsertModel } from 'drizzle-orm';
4
4
 
5
5
  interface TSchema extends ExtractTablesWithRelations<typeof tables> {
@@ -415,6 +415,7 @@ declare const createTransactionInputSchema: z.ZodObject<{
415
415
  ORDER: "ORDER";
416
416
  "INTERNAL-TRANSFER": "INTERNAL-TRANSFER";
417
417
  FORWARD: "FORWARD";
418
+ TRANSACTION: "TRANSACTION";
418
419
  }>;
419
420
  referenceId: z.ZodOptional<z.ZodString>;
420
421
  type: z.ZodEnum<{
@@ -423,10 +424,12 @@ declare const createTransactionInputSchema: z.ZodObject<{
423
424
  CLIENT_FUND_OUT: "CLIENT_FUND_OUT";
424
425
  PROVIDER_FUND_IN: "PROVIDER_FUND_IN";
425
426
  PROVIDER_FUND_OUT: "PROVIDER_FUND_OUT";
427
+ COLLATERAL_FUND_IN: "COLLATERAL_FUND_IN";
428
+ COLLATERAL_FUND_OUT: "COLLATERAL_FUND_OUT";
426
429
  UNMATCHED: "UNMATCHED";
427
430
  ADJUSTMENT: "ADJUSTMENT";
428
431
  TRANSFER: "TRANSFER";
429
- COLLATERAL: "COLLATERAL";
432
+ REFUND: "REFUND";
430
433
  }>;
431
434
  description: z.ZodOptional<z.ZodString>;
432
435
  paymentId: z.ZodOptional<z.ZodString>;
@@ -1174,9 +1177,6 @@ declare const createTransactionInputSchema: z.ZodObject<{
1174
1177
  status: z.ZodEnum<{
1175
1178
  FAILED: "FAILED";
1176
1179
  WAITING_FOR_PAYMENT: "WAITING_FOR_PAYMENT";
1177
- WAITING_FOR_COLLATERAL: "WAITING_FOR_COLLATERAL";
1178
- COLLATERAL_PAID: "COLLATERAL_PAID";
1179
- PAUSED: "PAUSED";
1180
1180
  WAITING_FOR_MANUAL_PROCESSING: "WAITING_FOR_MANUAL_PROCESSING";
1181
1181
  MATCHED: "MATCHED";
1182
1182
  RETURNING: "RETURNING";
@@ -1382,6 +1382,7 @@ declare const getTransactionsInputSchema: z.ZodObject<{
1382
1382
  ORDER: "ORDER";
1383
1383
  "INTERNAL-TRANSFER": "INTERNAL-TRANSFER";
1384
1384
  FORWARD: "FORWARD";
1385
+ TRANSACTION: "TRANSACTION";
1385
1386
  }>>;
1386
1387
  filterTransactionReferenceId: z.ZodOptional<z.ZodUUID>;
1387
1388
  filterTransactionType: z.ZodOptional<z.ZodEnum<{
@@ -1390,10 +1391,12 @@ declare const getTransactionsInputSchema: z.ZodObject<{
1390
1391
  CLIENT_FUND_OUT: "CLIENT_FUND_OUT";
1391
1392
  PROVIDER_FUND_IN: "PROVIDER_FUND_IN";
1392
1393
  PROVIDER_FUND_OUT: "PROVIDER_FUND_OUT";
1394
+ COLLATERAL_FUND_IN: "COLLATERAL_FUND_IN";
1395
+ COLLATERAL_FUND_OUT: "COLLATERAL_FUND_OUT";
1393
1396
  UNMATCHED: "UNMATCHED";
1394
1397
  ADJUSTMENT: "ADJUSTMENT";
1395
1398
  TRANSFER: "TRANSFER";
1396
- COLLATERAL: "COLLATERAL";
1399
+ REFUND: "REFUND";
1397
1400
  }>>;
1398
1401
  filterTransactionDescription: z.ZodOptional<z.ZodString>;
1399
1402
  filterTransactionDateFrom: z.ZodOptional<z.ZodDate>;
@@ -1402,9 +1405,6 @@ declare const getTransactionsInputSchema: z.ZodObject<{
1402
1405
  filterTransactionStatus: z.ZodOptional<z.ZodEnum<{
1403
1406
  FAILED: "FAILED";
1404
1407
  WAITING_FOR_PAYMENT: "WAITING_FOR_PAYMENT";
1405
- WAITING_FOR_COLLATERAL: "WAITING_FOR_COLLATERAL";
1406
- COLLATERAL_PAID: "COLLATERAL_PAID";
1407
- PAUSED: "PAUSED";
1408
1408
  WAITING_FOR_MANUAL_PROCESSING: "WAITING_FOR_MANUAL_PROCESSING";
1409
1409
  MATCHED: "MATCHED";
1410
1410
  RETURNING: "RETURNING";
@@ -1428,6 +1428,7 @@ declare const getTransactionsByReferenceIdInputSchema: z.ZodObject<{
1428
1428
  ORDER: "ORDER";
1429
1429
  "INTERNAL-TRANSFER": "INTERNAL-TRANSFER";
1430
1430
  FORWARD: "FORWARD";
1431
+ TRANSACTION: "TRANSACTION";
1431
1432
  }>;
1432
1433
  referenceId: z.ZodUUID;
1433
1434
  }, z.core.$strip>;
@@ -1646,7 +1647,40 @@ interface UpdateTransactionConfirmationSentAtInput extends z.input<typeof update
1646
1647
  }
1647
1648
  type UpdateTransactionConfirmationSentAtOutput = void;
1648
1649
 
1650
+ declare const refundTransactionInputSchema: z.ZodObject<{
1651
+ transactionId: z.ZodUUID;
1652
+ amount: z.ZodOptional<z.ZodNumber>;
1653
+ reason: z.ZodString;
1654
+ }, z.core.$strip>;
1655
+ interface RefundTransactionInput extends z.infer<typeof refundTransactionInputSchema> {
1656
+ }
1657
+ interface RefundTransactionOutput {
1658
+ refundTransaction: TransactionSelectType;
1659
+ originalTransaction: TransactionSelectType;
1660
+ }
1661
+
1662
+ declare const updateTransactionStatusInputSchema: z.ZodObject<{
1663
+ transactionId: z.ZodUUID;
1664
+ status: z.ZodEnum<{
1665
+ FAILED: "FAILED";
1666
+ WAITING_FOR_PAYMENT: "WAITING_FOR_PAYMENT";
1667
+ WAITING_FOR_MANUAL_PROCESSING: "WAITING_FOR_MANUAL_PROCESSING";
1668
+ MATCHED: "MATCHED";
1669
+ RETURNING: "RETURNING";
1670
+ RETURNED: "RETURNED";
1671
+ CANCELLED: "CANCELLED";
1672
+ SETTLED: "SETTLED";
1673
+ }>;
1674
+ statusReason: z.ZodOptional<z.ZodString>;
1675
+ paymentId: z.ZodOptional<z.ZodString>;
1676
+ completedAt: z.ZodOptional<z.ZodDate>;
1677
+ }, z.core.$strip>;
1678
+ interface UpdateTransactionStatusInput extends z.infer<typeof updateTransactionStatusInputSchema> {
1679
+ }
1680
+ interface UpdateTransactionStatusOutput extends TransactionSelectType {
1681
+ }
1682
+
1649
1683
  declare const tables: typeof schema;
1650
1684
 
1651
- export { findAccountByIdentifierInputSchema as $, cancelTransactionInputSchema as W, createAccountInputSchema as X, createTransactionInputSchema as Y, deleteAccountInputSchema as Z, failTransactionInputSchema as _, getAccountBalanceInputSchema as a0, getAccountIdentifierInputSchema as a1, getAccountInputSchema as a2, getAccountsByOwnerInputSchema as a3, getTransactionByIdInputSchema as a4, getTransactionsByReferenceIdInputSchema as a5, getTransactionsInputSchema as a6, listAccountIdentifiersInputSchema as a7, listAccountsInputSchema as a8, matchTransactionInputSchema as a9, updateAccountInputSchema as aa, updateTransactionConfirmationSentAtInputSchema as ab, tables as t };
1652
- export type { GetAccountBalanceInput as A, GetAccountBalanceOutput as B, CreateTransactionInput as C, DeleteAccountInput as D, UpdateTransactionConfirmationSentAtInput as E, FailTransactionInput as F, GetTransactionByIdInput as G, UpdateTransactionConfirmationSentAtOutput as H, AccountIdentifierInsertType as I, AccountIdentifierMappingInsertType as J, AccountIdentifierMappingSelectType as K, ListAccountsInput as L, MatchTransactionInput as M, AccountIdentifierSelectType as N, AccountInsertType as O, AccountSelectType as P, AccountWithIdentifiersSelectType as Q, IncludeRelation as R, InferResultType as S, TransactionSelectType as T, UpdateAccountInput as U, TransactionInsertType as V, CreateTransactionOutput as a, MatchTransactionOutput as b, FailTransactionOutput as c, CancelTransactionInput as d, CancelTransactionOutput as e, GetTransactionByIdOutput as f, GetTransactionsByIdReferenceInput as g, GetTransactionsByReferenceIdOutput as h, GetTransactionsInput as i, GetTransactionsOutput as j, CreateAccountInput as k, CreateAccountOutput as l, UpdateAccountOutput as m, DeleteAccountOutput as n, GetAccountInput as o, GetAccountOutput as p, GetAccountsByOwnerInput as q, GetAccountsByOwnerOutput as r, ListAccountsOutput as s, GetAccountIdentifierInput as u, GetAccountIdentifierOutput as v, ListAccountIdentifiersInput as w, ListAccountIdentifiersOutput as x, FindAccountByIdentifierInput as y, FindAccountByIdentifierOutput as z };
1685
+ export { createAccountInputSchema as $, cancelTransactionInputSchema as _, createTransactionInputSchema as a0, deleteAccountInputSchema as a1, failTransactionInputSchema as a2, findAccountByIdentifierInputSchema as a3, getAccountBalanceInputSchema as a4, getAccountIdentifierInputSchema as a5, getAccountInputSchema as a6, getAccountsByOwnerInputSchema as a7, getTransactionByIdInputSchema as a8, getTransactionsByReferenceIdInputSchema as a9, getTransactionsInputSchema as aa, listAccountIdentifiersInputSchema as ab, listAccountsInputSchema as ac, matchTransactionInputSchema as ad, refundTransactionInputSchema as ae, updateAccountInputSchema as af, updateTransactionConfirmationSentAtInputSchema as ag, updateTransactionStatusInputSchema as ah, tables as t };
1686
+ export type { FindAccountByIdentifierOutput as A, GetAccountBalanceInput as B, CreateTransactionInput as C, DeleteAccountInput as D, GetAccountBalanceOutput as E, FailTransactionInput as F, GetTransactionByIdInput as G, UpdateTransactionConfirmationSentAtInput as H, UpdateTransactionConfirmationSentAtOutput as I, UpdateTransactionStatusInput as J, UpdateTransactionStatusOutput as K, ListAccountsInput as L, MatchTransactionInput as M, AccountIdentifierInsertType as N, AccountIdentifierMappingInsertType as O, AccountIdentifierMappingSelectType as P, AccountIdentifierSelectType as Q, RefundTransactionInput as R, AccountInsertType as S, TransactionSelectType as T, UpdateAccountInput as U, AccountSelectType as V, AccountWithIdentifiersSelectType as W, IncludeRelation as X, InferResultType as Y, TransactionInsertType as Z, CreateTransactionOutput as a, MatchTransactionOutput as b, FailTransactionOutput as c, CancelTransactionInput as d, CancelTransactionOutput as e, RefundTransactionOutput as f, GetTransactionByIdOutput as g, GetTransactionsByIdReferenceInput as h, GetTransactionsByReferenceIdOutput as i, GetTransactionsInput as j, GetTransactionsOutput as k, CreateAccountInput as l, CreateAccountOutput as m, UpdateAccountOutput as n, DeleteAccountOutput as o, GetAccountInput as p, GetAccountOutput as q, GetAccountsByOwnerInput as r, GetAccountsByOwnerOutput as s, ListAccountsOutput as u, GetAccountIdentifierInput as v, GetAccountIdentifierOutput as w, ListAccountIdentifiersInput as x, ListAccountIdentifiersOutput as y, FindAccountByIdentifierInput as z };
@@ -61,9 +61,7 @@ const ENTRY_STATUSES = [
61
61
  ];
62
62
  const TRANSACTION_STATUSES = [
63
63
  "WAITING_FOR_PAYMENT",
64
- "WAITING_FOR_COLLATERAL",
65
- "COLLATERAL_PAID",
66
- "PAUSED",
64
+ // 'PAUSED',
67
65
  "WAITING_FOR_MANUAL_PROCESSING",
68
66
  "MATCHED",
69
67
  "RETURNING",
@@ -71,31 +69,37 @@ const TRANSACTION_STATUSES = [
71
69
  "FAILED",
72
70
  "CANCELLED",
73
71
  "SETTLED"
72
+ // not used for now, but maybe in future when we have settlement process implemented
74
73
  ];
75
74
  const TRANSACTION_TYPES = [
76
75
  "CLIENT_FUND_IN",
77
76
  "CLIENT_FUND_OUT",
78
77
  "PROVIDER_FUND_IN",
79
78
  "PROVIDER_FUND_OUT",
79
+ "COLLATERAL_FUND_IN",
80
+ "COLLATERAL_FUND_OUT",
80
81
  "EXCHANGE",
81
82
  // maybe in future
82
83
  "UNMATCHED",
83
84
  "ADJUSTMENT",
84
- // manual correction
85
+ // manual correction maybe in future
85
86
  "TRANSFER",
86
87
  // internal transfer between accounts
87
- "COLLATERAL"
88
- // forward collateral payment from client
88
+ "REFUND"
89
89
  ];
90
90
  const REFERENCE_TYPES = [
91
91
  "PAYMENT",
92
92
  "EXCHANGE",
93
93
  "ORDER",
94
94
  "INTERNAL-TRANSFER",
95
- "FORWARD"
95
+ "FORWARD",
96
+ "TRANSACTION"
96
97
  ];
97
98
  const PAYMENT_CHARGE_TYPES = ["SHA", "OUR", "BEN"];
98
99
  const PAYMENT_TYPES = ["DOMESTIC", "SEPA", "SWIFT", "UNKNOWN"];
100
+ const REFUNDABLE_TRANSACTION_STATUSES = [
101
+ "WAITING_FOR_MANUAL_PROCESSING"
102
+ ];
99
103
 
100
104
  const ALLOWED_TRANSACTION_FILTERS = {
101
105
  CORRELATION_ID: "filterTransactionCorrelationId",
@@ -311,6 +315,20 @@ const updateTransactionConfirmationSentAtInputSchema = zod.z.object({
311
315
  transactionId: zod.z.uuid()
312
316
  });
313
317
 
318
+ const refundTransactionInputSchema = zod.z.object({
319
+ transactionId: zod.z.uuid(),
320
+ amount: zod.z.number().positive().optional(),
321
+ reason: zod.z.string().min(1)
322
+ });
323
+
324
+ const updateTransactionStatusInputSchema = zod.z.object({
325
+ transactionId: zod.z.uuid(),
326
+ status: zod.z.enum(TRANSACTION_STATUSES),
327
+ statusReason: zod.z.string().optional(),
328
+ paymentId: zod.z.string().optional(),
329
+ completedAt: zod.z.date().optional()
330
+ });
331
+
314
332
  exports.ACCOUNT_TYPES = ACCOUNT_TYPES;
315
333
  exports.ALLOWED_TRANSACTION_FILTERS = ALLOWED_TRANSACTION_FILTERS;
316
334
  exports.ASSET_TYPES = ASSET_TYPES;
@@ -324,6 +342,7 @@ exports.PAYMENT_DIRECTIONS = PAYMENT_DIRECTIONS;
324
342
  exports.PAYMENT_STATUSES = PAYMENT_STATUSES;
325
343
  exports.PAYMENT_TYPES = PAYMENT_TYPES;
326
344
  exports.REFERENCE_TYPES = REFERENCE_TYPES;
345
+ exports.REFUNDABLE_TRANSACTION_STATUSES = REFUNDABLE_TRANSACTION_STATUSES;
327
346
  exports.TRANSACTION_STATUSES = TRANSACTION_STATUSES;
328
347
  exports.TRANSACTION_TYPES = TRANSACTION_TYPES;
329
348
  exports.cancelTransactionInputSchema = cancelTransactionInputSchema;
@@ -342,5 +361,7 @@ exports.getTransactionsInputSchema = getTransactionsInputSchema;
342
361
  exports.listAccountIdentifiersInputSchema = listAccountIdentifiersInputSchema;
343
362
  exports.listAccountsInputSchema = listAccountsInputSchema;
344
363
  exports.matchTransactionInputSchema = matchTransactionInputSchema;
364
+ exports.refundTransactionInputSchema = refundTransactionInputSchema;
345
365
  exports.updateAccountInputSchema = updateAccountInputSchema;
346
366
  exports.updateTransactionConfirmationSentAtInputSchema = updateTransactionConfirmationSentAtInputSchema;
367
+ exports.updateTransactionStatusInputSchema = updateTransactionStatusInputSchema;