@develit-services/bank 0.7.0 → 0.7.1

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.
Files changed (41) hide show
  1. package/README.md +381 -0
  2. package/dist/database/schema.cjs +1 -1
  3. package/dist/database/schema.d.cts +1 -1
  4. package/dist/database/schema.d.mts +1 -1
  5. package/dist/database/schema.d.ts +1 -1
  6. package/dist/database/schema.mjs +1 -1
  7. package/dist/export/worker.cjs +47 -36
  8. package/dist/export/worker.d.cts +378 -77
  9. package/dist/export/worker.d.mts +378 -77
  10. package/dist/export/worker.d.ts +378 -77
  11. package/dist/export/worker.mjs +47 -36
  12. package/dist/export/workflows.cjs +24 -9
  13. package/dist/export/workflows.mjs +24 -9
  14. package/dist/export/wrangler.cjs +7 -0
  15. package/dist/export/wrangler.d.cts +7 -1
  16. package/dist/export/wrangler.d.mts +7 -1
  17. package/dist/export/wrangler.d.ts +7 -1
  18. package/dist/export/wrangler.mjs +7 -0
  19. package/dist/shared/{bank.Coi0lSqK.d.cts → bank.BC06Rbrx.d.cts} +1 -0
  20. package/dist/shared/{bank.Coi0lSqK.d.mts → bank.BC06Rbrx.d.mts} +1 -0
  21. package/dist/shared/{bank.Coi0lSqK.d.ts → bank.BC06Rbrx.d.ts} +1 -0
  22. package/dist/shared/{bank.DLWegh_f.mjs → bank.BnIYdBEF.mjs} +9 -0
  23. package/dist/shared/bank.C6_7Rch8.d.cts +4755 -0
  24. package/dist/shared/bank.C6_7Rch8.d.mts +4755 -0
  25. package/dist/shared/bank.C6_7Rch8.d.ts +4755 -0
  26. package/dist/shared/{bank.DEvSNsEs.cjs → bank.CTqIXnHg.cjs} +2 -2
  27. package/dist/shared/{bank.DFIwAQqg.mjs → bank.CTtFAN03.mjs} +1 -1
  28. package/dist/shared/{bank.Dq27-5wD.mjs → bank.CkUMU1sJ.mjs} +365 -50
  29. package/dist/shared/{bank.BeIpkWR-.cjs → bank.D7kwLMqF.cjs} +9 -0
  30. package/dist/shared/{bank.c38V_FCq.cjs → bank.DlW1XNug.cjs} +1 -1
  31. package/dist/shared/{bank.pd7-Rbo-.mjs → bank.e8T8fQDG.mjs} +2 -2
  32. package/dist/shared/{bank.DNHA-HFP.cjs → bank.iEgK7rge.cjs} +365 -50
  33. package/dist/types.cjs +2 -2
  34. package/dist/types.d.cts +452 -40
  35. package/dist/types.d.mts +452 -40
  36. package/dist/types.d.ts +452 -40
  37. package/dist/types.mjs +2 -2
  38. package/package.json +1 -1
  39. package/dist/shared/bank.Vj1x4v-K.d.cts +0 -2515
  40. package/dist/shared/bank.Vj1x4v-K.d.mts +0 -2515
  41. package/dist/shared/bank.Vj1x4v-K.d.ts +0 -2515
@@ -1,16 +1,16 @@
1
1
  import { uuidv4, first, bankAccountMetadataSchema, workflowInstanceStatusSchema, develitWorker, createInternalError, action, service } from '@develit-io/backend-sdk';
2
- import { t as tables, e as encrypt, i as importAesKey, b as getCredentialsByAccountId, u as upsertBatchCommand, g as getBatchByIdQuery, d as createPaymentCommand, a as getAccountByIdQuery } from '../shared/bank.pd7-Rbo-.mjs';
2
+ import { t as tables, e as encrypt, i as importAesKey, b as getCredentialsByAccountId, u as upsertBatchCommand, g as getBatchByIdQuery, d as createPaymentCommand, a as getAccountByIdQuery } from '../shared/bank.e8T8fQDG.mjs';
3
3
  import { WorkerEntrypoint } from 'cloudflare:workers';
4
4
  import { drizzle } from 'drizzle-orm/d1';
5
5
  import { z } from 'zod';
6
- import { I as INSTRUCTION_PRIORITIES, C as CHARGE_BEARERS, e as PAYMENT_TYPES, a as CONNECTOR_KEYS, B as BATCH_STATUSES, d as PAYMENT_STATUSES, P as PAYMENT_DIRECTIONS, i as accountInsertSchema } from '../shared/bank.DLWegh_f.mjs';
6
+ import { I as INSTRUCTION_PRIORITIES, C as CHARGE_BEARERS, e as PAYMENT_TYPES, a as CONNECTOR_KEYS, B as BATCH_STATUSES, d as PAYMENT_STATUSES, P as PAYMENT_DIRECTIONS, i as accountInsertSchema } from '../shared/bank.BnIYdBEF.mjs';
7
7
  import { CURRENCY_CODES } from '@develit-io/general-codes';
8
8
  import 'date-fns';
9
9
  import 'jose';
10
10
  import { eq, sql, inArray, and, asc, desc, gte, lte } from 'drizzle-orm';
11
11
  import 'node:crypto';
12
- import { i as initiateConnector, g as toIncomingPayment, d as assignAccount, t as toBatchedPayment } from '../shared/bank.Dq27-5wD.mjs';
13
- import '../shared/bank.DFIwAQqg.mjs';
12
+ import { i as initiateConnector, g as toIncomingPayment, d as assignAccount, t as toBatchedPayment } from '../shared/bank.CkUMU1sJ.mjs';
13
+ import '../shared/bank.CTtFAN03.mjs';
14
14
  import 'drizzle-orm/relations';
15
15
  import 'drizzle-orm/sqlite-core';
16
16
  import 'drizzle-zod';
@@ -222,11 +222,12 @@ const getBatchesQuery = async (db, {
222
222
  };
223
223
  };
224
224
 
225
- const getAccountOpenBatchesQuery = async (db, { accountId }) => {
225
+ const getAccountOpenBatchesQuery = async (db, { accountId, paymentType }) => {
226
226
  return await db.select().from(tables.batch).where(
227
227
  and(
228
228
  eq(tables.batch.accountId, accountId),
229
- eq(tables.batch.status, "OPEN")
229
+ eq(tables.batch.status, "OPEN"),
230
+ paymentType ? eq(tables.batch.paymentType, paymentType) : void 0
230
231
  )
231
232
  );
232
233
  };
@@ -483,7 +484,8 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
483
484
  iban: acc.iban,
484
485
  token: credentials.value,
485
486
  id: acc.id,
486
- connectorKey: acc.connectorKey
487
+ connectorKey: acc.connectorKey,
488
+ bankRefId: acc.bankRefId
487
489
  };
488
490
  })
489
491
  );
@@ -725,6 +727,7 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
725
727
  id: uuidv4(),
726
728
  authorizationUrls: [],
727
729
  accountId: acc.id,
730
+ paymentType: singlePayment.paymentType,
728
731
  payments: [batchedPayment],
729
732
  status: "OPEN",
730
733
  metadata: {
@@ -734,40 +737,47 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
734
737
  });
735
738
  await command.execute();
736
739
  this.log({
737
- message: `\u2728 Created single payment batch for account ${acc.id}`
740
+ message: `\u2728 Created single payment batch (${singlePayment.paymentType}) for account ${acc.id}`
738
741
  });
739
742
  }
740
743
  if (regularPayments.length > 0) {
741
- const openBatches = await getAccountOpenBatchesQuery(this.db, {
742
- accountId: acc.id
743
- });
744
- const availableBatch = openBatches.find(
745
- (batch) => batch.payments.length < (batch.metadata?.sizeLimit ?? acc.batchSizeLimit)
744
+ const paymentsByType = Map.groupBy(
745
+ regularPayments,
746
+ (p) => p.paymentType
746
747
  );
747
- this.log({
748
- message: availableBatch ? `\u{1F504} Found existing OPEN batch for account ${acc.id}, merging ${availableBatch.payments.length} existing + ${regularPayments.length} new payments` : `\u2728 Creating new batch for account ${acc.id} with ${regularPayments.length} payments`
749
- });
750
- const batchedPayments = regularPayments.map(toBatchedPayment);
751
- const { command } = upsertBatchCommand(this.db, {
752
- batch: availableBatch ? {
753
- ...availableBatch,
754
- payments: [...availableBatch.payments, ...batchedPayments]
755
- } : {
756
- id: uuidv4(),
757
- authorizationUrls: [],
748
+ for (const [paymentType, paymentsOfType] of paymentsByType) {
749
+ const openBatches = await getAccountOpenBatchesQuery(this.db, {
758
750
  accountId: acc.id,
759
- payments: batchedPayments,
760
- status: "OPEN",
761
- metadata: {
762
- sizeLimit: acc.batchSizeLimit
751
+ paymentType
752
+ });
753
+ const availableBatch = openBatches.find(
754
+ (batch) => batch.payments.length < (batch.metadata?.sizeLimit ?? acc.batchSizeLimit)
755
+ );
756
+ this.log({
757
+ message: availableBatch ? `\u{1F504} Found existing OPEN batch (${paymentType}) for account ${acc.id}, merging ${availableBatch.payments.length} existing + ${paymentsOfType.length} new payments` : `\u2728 Creating new batch (${paymentType}) for account ${acc.id} with ${paymentsOfType.length} payments`
758
+ });
759
+ const batchedPayments = paymentsOfType.map(toBatchedPayment);
760
+ const { command } = upsertBatchCommand(this.db, {
761
+ batch: availableBatch ? {
762
+ ...availableBatch,
763
+ payments: [...availableBatch.payments, ...batchedPayments]
764
+ } : {
765
+ id: uuidv4(),
766
+ authorizationUrls: [],
767
+ accountId: acc.id,
768
+ paymentType,
769
+ payments: batchedPayments,
770
+ status: "OPEN",
771
+ metadata: {
772
+ sizeLimit: acc.batchSizeLimit
773
+ }
763
774
  }
764
- }
765
- });
766
- const upsertedBatch = await command.execute();
767
- this.log({
768
- message: `\u2705 Batch upserted successfully for account ${acc.id}`
769
- });
770
- return upsertedBatch;
775
+ });
776
+ await command.execute();
777
+ this.log({
778
+ message: `\u2705 Batch (${paymentType}) upserted successfully for account ${acc.id}`
779
+ });
780
+ }
771
781
  }
772
782
  }
773
783
  });
@@ -877,7 +887,8 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
877
887
  });
878
888
  }
879
889
  const connector = await this._initiateBankConnector({
880
- connectorKey: ottRow.refId
890
+ connectorKey: ottRow.refId,
891
+ skipAccounts: true
881
892
  });
882
893
  const { credentials, accounts } = await connector.authorizeAccount({
883
894
  urlParams
@@ -1,15 +1,15 @@
1
1
  'use strict';
2
2
 
3
3
  const backendSdk = require('@develit-io/backend-sdk');
4
- const drizzle = require('../shared/bank.DEvSNsEs.cjs');
4
+ const drizzle = require('../shared/bank.CTqIXnHg.cjs');
5
5
  const batchLifecycle = require('../shared/bank.Bg3Pdwm4.cjs');
6
- const mock_connector = require('../shared/bank.DNHA-HFP.cjs');
6
+ const mock_connector = require('../shared/bank.iEgK7rge.cjs');
7
7
  const drizzleOrm = require('drizzle-orm');
8
8
  const cloudflare_workers = require('cloudflare:workers');
9
9
  const cloudflare_workflows = require('cloudflare:workflows');
10
10
  const d1 = require('drizzle-orm/d1');
11
- require('../shared/bank.c38V_FCq.cjs');
12
- require('../shared/bank.BeIpkWR-.cjs');
11
+ require('../shared/bank.DlW1XNug.cjs');
12
+ require('../shared/bank.D7kwLMqF.cjs');
13
13
  require('drizzle-orm/relations');
14
14
  require('drizzle-orm/sqlite-core');
15
15
  require('date-fns');
@@ -127,17 +127,32 @@ class BankProcessBatch extends cloudflare_workers.WorkflowEntrypoint {
127
127
  }
128
128
  ]
129
129
  });
130
- const result = await connector.initiateBatch({
131
- batchId: batch.id,
132
- payments: batch.payments
133
- });
130
+ const initiateBatchByType = () => {
131
+ const args = { batchId: batch.id, payments: batch.payments };
132
+ switch (batch.paymentType) {
133
+ case "SEPA":
134
+ return connector.initiateSEPABatch(args);
135
+ case "SWIFT":
136
+ return connector.initiateForeignBatch(args);
137
+ case "DOMESTIC":
138
+ default:
139
+ return connector.initiateDomesticBatch(args);
140
+ }
141
+ };
142
+ let result;
143
+ try {
144
+ result = await initiateBatchByType();
145
+ } catch (err) {
146
+ const message = err instanceof Error ? err.message : typeof err === "object" && err !== null && "message" in err ? String(err.message) : String(err);
147
+ throw new cloudflare_workflows.NonRetryableError(message);
148
+ }
134
149
  const {
135
150
  authorizationUrls,
136
151
  payments: preparedPayments,
137
152
  metadata
138
153
  } = result;
139
154
  if (!authorizationUrls || authorizationUrls.length === 0) {
140
- throw new Error("Failed to retrieve authorization URLs");
155
+ throw new cloudflare_workflows.NonRetryableError("Failed to retrieve authorization URLs");
141
156
  }
142
157
  return {
143
158
  authorizationUrls,
@@ -1,13 +1,13 @@
1
1
  import { first, uuidv4, asNonEmpty } from '@develit-io/backend-sdk';
2
- import { t as tables, g as getBatchByIdQuery, c as checksum, u as upsertBatchCommand, a as getAccountByIdQuery, i as importAesKey, b as getCredentialsByAccountId, d as createPaymentCommand } from '../shared/bank.pd7-Rbo-.mjs';
2
+ import { t as tables, g as getBatchByIdQuery, c as checksum, u as upsertBatchCommand, a as getAccountByIdQuery, i as importAesKey, b as getCredentialsByAccountId, d as createPaymentCommand } from '../shared/bank.e8T8fQDG.mjs';
3
3
  import { f as isBatchSigned, a as isBatchFailed, c as isBatchOpen, g as isPaymentCompleted } from '../shared/bank.CbAwwIhZ.mjs';
4
- import { h as toPreparedPayment, i as initiateConnector, f as toCompletedPayment } from '../shared/bank.Dq27-5wD.mjs';
4
+ import { h as toPreparedPayment, i as initiateConnector, f as toCompletedPayment } from '../shared/bank.CkUMU1sJ.mjs';
5
5
  import { eq } from 'drizzle-orm';
6
6
  import { WorkflowEntrypoint } from 'cloudflare:workers';
7
7
  import { NonRetryableError } from 'cloudflare:workflows';
8
8
  import { drizzle } from 'drizzle-orm/d1';
9
- import '../shared/bank.DFIwAQqg.mjs';
10
- import '../shared/bank.DLWegh_f.mjs';
9
+ import '../shared/bank.CTtFAN03.mjs';
10
+ import '../shared/bank.BnIYdBEF.mjs';
11
11
  import 'drizzle-orm/relations';
12
12
  import 'drizzle-orm/sqlite-core';
13
13
  import 'date-fns';
@@ -125,17 +125,32 @@ class BankProcessBatch extends WorkflowEntrypoint {
125
125
  }
126
126
  ]
127
127
  });
128
- const result = await connector.initiateBatch({
129
- batchId: batch.id,
130
- payments: batch.payments
131
- });
128
+ const initiateBatchByType = () => {
129
+ const args = { batchId: batch.id, payments: batch.payments };
130
+ switch (batch.paymentType) {
131
+ case "SEPA":
132
+ return connector.initiateSEPABatch(args);
133
+ case "SWIFT":
134
+ return connector.initiateForeignBatch(args);
135
+ case "DOMESTIC":
136
+ default:
137
+ return connector.initiateDomesticBatch(args);
138
+ }
139
+ };
140
+ let result;
141
+ try {
142
+ result = await initiateBatchByType();
143
+ } catch (err) {
144
+ const message = err instanceof Error ? err.message : typeof err === "object" && err !== null && "message" in err ? String(err.message) : String(err);
145
+ throw new NonRetryableError(message);
146
+ }
132
147
  const {
133
148
  authorizationUrls,
134
149
  payments: preparedPayments,
135
150
  metadata
136
151
  } = result;
137
152
  if (!authorizationUrls || authorizationUrls.length === 0) {
138
- throw new Error("Failed to retrieve authorization URLs");
153
+ throw new NonRetryableError("Failed to retrieve authorization URLs");
139
154
  }
140
155
  return {
141
156
  authorizationUrls,
@@ -46,6 +46,13 @@ function defineBankServiceWrangler(config) {
46
46
  class_name: "BankProcessBatch"
47
47
  }
48
48
  ],
49
+ vpc_services: [
50
+ {
51
+ binding: "DBU_CBS_BACKOFFICE_DEV",
52
+ service_id: "019c2962-172c-75a2-a000-b76e246d25d7",
53
+ remote: true
54
+ }
55
+ ],
49
56
  queues: {
50
57
  producers: [
51
58
  {
@@ -1,4 +1,4 @@
1
- import { B as BankServiceWranglerConfig } from '../shared/bank.Coi0lSqK.cjs';
1
+ import { B as BankServiceWranglerConfig } from '../shared/bank.BC06Rbrx.cjs';
2
2
 
3
3
  declare function defineBankServiceWrangler(config: BankServiceWranglerConfig): {
4
4
  vars: {
@@ -13,6 +13,7 @@ declare function defineBankServiceWrangler(config: BankServiceWranglerConfig): {
13
13
  BANK_AUTH_RECIPIENT: string;
14
14
  DBUCS_BASE_URI: string;
15
15
  DBUCS_USERNAME: string;
16
+ DBUCS_TX_AUTH_URI: string;
16
17
  REDIRECT_URI: string;
17
18
  };
18
19
  services: {
@@ -37,6 +38,11 @@ declare function defineBankServiceWrangler(config: BankServiceWranglerConfig): {
37
38
  binding: string;
38
39
  class_name: string;
39
40
  }[];
41
+ vpc_services: {
42
+ binding: string;
43
+ service_id: string;
44
+ remote: boolean;
45
+ }[];
40
46
  queues: {
41
47
  producers: {
42
48
  binding: string;
@@ -1,4 +1,4 @@
1
- import { B as BankServiceWranglerConfig } from '../shared/bank.Coi0lSqK.mjs';
1
+ import { B as BankServiceWranglerConfig } from '../shared/bank.BC06Rbrx.mjs';
2
2
 
3
3
  declare function defineBankServiceWrangler(config: BankServiceWranglerConfig): {
4
4
  vars: {
@@ -13,6 +13,7 @@ declare function defineBankServiceWrangler(config: BankServiceWranglerConfig): {
13
13
  BANK_AUTH_RECIPIENT: string;
14
14
  DBUCS_BASE_URI: string;
15
15
  DBUCS_USERNAME: string;
16
+ DBUCS_TX_AUTH_URI: string;
16
17
  REDIRECT_URI: string;
17
18
  };
18
19
  services: {
@@ -37,6 +38,11 @@ declare function defineBankServiceWrangler(config: BankServiceWranglerConfig): {
37
38
  binding: string;
38
39
  class_name: string;
39
40
  }[];
41
+ vpc_services: {
42
+ binding: string;
43
+ service_id: string;
44
+ remote: boolean;
45
+ }[];
40
46
  queues: {
41
47
  producers: {
42
48
  binding: string;
@@ -1,4 +1,4 @@
1
- import { B as BankServiceWranglerConfig } from '../shared/bank.Coi0lSqK.js';
1
+ import { B as BankServiceWranglerConfig } from '../shared/bank.BC06Rbrx.js';
2
2
 
3
3
  declare function defineBankServiceWrangler(config: BankServiceWranglerConfig): {
4
4
  vars: {
@@ -13,6 +13,7 @@ declare function defineBankServiceWrangler(config: BankServiceWranglerConfig): {
13
13
  BANK_AUTH_RECIPIENT: string;
14
14
  DBUCS_BASE_URI: string;
15
15
  DBUCS_USERNAME: string;
16
+ DBUCS_TX_AUTH_URI: string;
16
17
  REDIRECT_URI: string;
17
18
  };
18
19
  services: {
@@ -37,6 +38,11 @@ declare function defineBankServiceWrangler(config: BankServiceWranglerConfig): {
37
38
  binding: string;
38
39
  class_name: string;
39
40
  }[];
41
+ vpc_services: {
42
+ binding: string;
43
+ service_id: string;
44
+ remote: boolean;
45
+ }[];
40
46
  queues: {
41
47
  producers: {
42
48
  binding: string;
@@ -44,6 +44,13 @@ function defineBankServiceWrangler(config) {
44
44
  class_name: "BankProcessBatch"
45
45
  }
46
46
  ],
47
+ vpc_services: [
48
+ {
49
+ binding: "DBU_CBS_BACKOFFICE_DEV",
50
+ service_id: "019c2962-172c-75a2-a000-b76e246d25d7",
51
+ remote: true
52
+ }
53
+ ],
47
54
  queues: {
48
55
  producers: [
49
56
  {
@@ -31,6 +31,7 @@ interface BankServiceEnvironmentConfig {
31
31
  BANK_AUTH_RECIPIENT: string;
32
32
  DBUCS_BASE_URI: string;
33
33
  DBUCS_USERNAME: string;
34
+ DBUCS_TX_AUTH_URI: string;
34
35
  REDIRECT_URI: string;
35
36
  };
36
37
  }
@@ -31,6 +31,7 @@ interface BankServiceEnvironmentConfig {
31
31
  BANK_AUTH_RECIPIENT: string;
32
32
  DBUCS_BASE_URI: string;
33
33
  DBUCS_USERNAME: string;
34
+ DBUCS_TX_AUTH_URI: string;
34
35
  REDIRECT_URI: string;
35
36
  };
36
37
  }
@@ -31,6 +31,7 @@ interface BankServiceEnvironmentConfig {
31
31
  BANK_AUTH_RECIPIENT: string;
32
32
  DBUCS_BASE_URI: string;
33
33
  DBUCS_USERNAME: string;
34
+ DBUCS_TX_AUTH_URI: string;
34
35
  REDIRECT_URI: string;
35
36
  };
36
37
  }
@@ -122,6 +122,9 @@ const batch = sqliteTable("batch", {
122
122
  statusResponse: text("status_response", { mode: "json" }).$type(),
123
123
  payments: text("payments", { mode: "json" }).$type().notNull(),
124
124
  metadata: text("metadata", { mode: "json" }).$type(),
125
+ paymentType: text("payment_type", {
126
+ enum: PAYMENT_TYPES
127
+ }).$type(),
125
128
  paymentsChecksum: text("payments_checksum")
126
129
  });
127
130
 
@@ -151,6 +154,12 @@ const payment = sqliteTable(
151
154
  ss: text("ss"),
152
155
  ks: text("ks"),
153
156
  message: text("message"),
157
+ chargeBearer: text("charge_bearer", {
158
+ enum: CHARGE_BEARERS
159
+ }).$type(),
160
+ instructionPriority: text("instruction_priority", {
161
+ enum: INSTRUCTION_PRIORITIES
162
+ }).$type(),
154
163
  processedAt: integer("processed_at", {
155
164
  mode: "timestamp_ms"
156
165
  }),