@develit-services/bank 0.1.2 → 0.1.4

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 (30) hide show
  1. package/dist/database/schema.cjs +1 -1
  2. package/dist/database/schema.d.cts +1 -1
  3. package/dist/database/schema.d.mts +1 -1
  4. package/dist/database/schema.d.ts +1 -1
  5. package/dist/database/schema.mjs +1 -1
  6. package/dist/export/worker.cjs +23 -3
  7. package/dist/export/worker.d.cts +19 -7
  8. package/dist/export/worker.d.mts +19 -7
  9. package/dist/export/worker.d.ts +19 -7
  10. package/dist/export/worker.mjs +24 -4
  11. package/dist/export/workflows.cjs +3 -3
  12. package/dist/export/workflows.mjs +3 -3
  13. package/dist/shared/{bank.DJ9d1yaR.mjs → bank.BVoTAfMF.mjs} +75 -62
  14. package/dist/shared/{bank.RUV2HUFo.mjs → bank.Buq4PwHY.mjs} +28 -28
  15. package/dist/shared/{bank.mub5_S4r.d.cts → bank.CgiMSTo7.d.cts} +4 -4
  16. package/dist/shared/{bank.mub5_S4r.d.mts → bank.CgiMSTo7.d.mts} +4 -4
  17. package/dist/shared/{bank.mub5_S4r.d.ts → bank.CgiMSTo7.d.ts} +4 -4
  18. package/dist/shared/{bank.8lAQLFNI.mjs → bank.DC5Hk4UF.mjs} +1 -1
  19. package/dist/shared/{bank.UfRkUN2y.cjs → bank.DN3pRw5j.cjs} +28 -28
  20. package/dist/shared/{bank.DOJ8gbXQ.cjs → bank.DTMwkDFH.cjs} +75 -62
  21. package/dist/shared/{bank.BQSnGZ-3.d.cts → bank.DV-Kvdzh.d.cts} +3 -3
  22. package/dist/shared/{bank.DW3cHO1u.d.mts → bank._W3dtG8P.d.ts} +3 -3
  23. package/dist/shared/{bank.DISsqBb6.cjs → bank._ilV3SSc.cjs} +1 -1
  24. package/dist/shared/{bank.CouYVuOf.d.ts → bank.b_ehHCuG.d.mts} +3 -3
  25. package/dist/types.cjs +2 -2
  26. package/dist/types.d.cts +6 -5
  27. package/dist/types.d.mts +6 -5
  28. package/dist/types.d.ts +6 -5
  29. package/dist/types.mjs +2 -2
  30. package/package.json +1 -1
@@ -175,26 +175,46 @@ const mapFinbricksTransactionStatus = (status) => {
175
175
  const mapFinbricksBatchStatus = (status) => {
176
176
  return status === "REJECTED" ? "FAILED" : status === "AUTHORIZED" ? "PROCESSING" : "READY_TO_SIGN";
177
177
  };
178
+
179
+ const mapFinbricksAccountInsert = ({
180
+ account,
181
+ connectorKey,
182
+ status
183
+ }) => ({
184
+ id: account.id,
185
+ bankRefId: account.bankRefId,
186
+ connectorKey,
187
+ status,
188
+ currency: account.currency,
189
+ number: account.identification.accountNumber,
190
+ bankCode: account.servicer.bankCode,
191
+ // For now we are using CZE as fallback because finbricks does not provide country code 100% of the time
192
+ countryCode: account.servicer.countryCode || "CZE",
193
+ holderName: account.ownersNames.join(", "),
194
+ iban: account.identification.iban
195
+ });
196
+
178
197
  const mapFinbricksTransactionToPayment = (tx, account) => {
179
198
  const isIncoming = tx.creditDebitIndicator === "CRDT";
180
199
  const related = tx.entryDetails?.transactionDetails?.relatedParties;
181
200
  const base = {
182
201
  id: uuidv4(),
183
202
  correlationId: uuidv4(),
203
+ //TODO(kleinpetr): use real correlationId once available
184
204
  connectorKey: account.connectorKey,
185
205
  accountId: account.id,
186
- bankRefId: tx.entryReference || tx.fbxReference,
206
+ bankRefId: tx.fbxReference || tx.entryReference,
187
207
  amount: tx.amount?.value || 0,
188
208
  currency: tx.amount?.currency || "CZK",
189
209
  paymentType: "DOMESTIC",
190
210
  status: mapFinbricksStatus(tx.status),
191
- message: tx.entryDetails.transactionDetails?.remittanceInformation?.unstructured || tx.entryDetails.transactionDetails?.additionalRemittanceInformation || null,
211
+ message: tx.entryDetails.transactionDetails?.remittanceInformation?.unstructured || tx.entryDetails.transactionDetails?.additionalRemittanceInformation || tx.entryDetails.transactionDetails?.additionalTransactionInformation || null,
192
212
  processedAt: new Date(tx.bookingDate.date),
193
213
  ...mapReferencesToPayment(
194
214
  tx.entryDetails.transactionDetails?.remittanceInformation?.structured?.creditorReferenceInformation?.reference || tx.entryDetails.transactionDetails?.references?.endToEndIdentification
195
215
  ),
196
216
  creditor: {
197
- holderName: isIncoming ? "Unknown" : related?.creditor?.name || "Unknown",
217
+ holderName: related?.creditor?.name || "Unknown",
198
218
  iban: isIncoming ? account.iban || void 0 : related.creditorAccount?.identification?.iban || account.iban || void 0,
199
219
  number: isIncoming ? account.number || void 0 : related.creditorAccount?.identification?.other?.identification ? related.creditorAccount.identification.other.identification.split(
200
220
  "/"
@@ -204,7 +224,7 @@ const mapFinbricksTransactionToPayment = (tx, account) => {
204
224
  )[1] : account.bankCode || void 0
205
225
  },
206
226
  debtor: {
207
- holderName: isIncoming ? related?.debtor?.name || "Unknown" : "Unknown",
227
+ holderName: related?.debtor?.name || "Unknown",
208
228
  iban: isIncoming ? related.debtorAccount?.identification?.iban || account.iban || void 0 : account.iban ?? void 0,
209
229
  number: isIncoming ? related.debtorAccount?.identification?.other?.identification ? related.debtorAccount.identification.other.identification.split(
210
230
  "/"
@@ -213,31 +233,11 @@ const mapFinbricksTransactionToPayment = (tx, account) => {
213
233
  "/"
214
234
  )[1] : account.bankCode || void 0 : account.bankCode || void 0
215
235
  },
216
- direction: "INCOMING"
217
- // přepíšeme správným směrem níže
236
+ direction: isIncoming ? "INCOMING" : "OUTGOING"
218
237
  };
219
- base.direction = isIncoming ? "INCOMING" : "OUTGOING";
220
238
  return base;
221
239
  };
222
240
 
223
- const mapFinbricksAccountInsert = ({
224
- account,
225
- connectorKey,
226
- status
227
- }) => ({
228
- id: account.id,
229
- bankRefId: account.bankRefId,
230
- connectorKey,
231
- status,
232
- currency: account.currency,
233
- number: account.identification.accountNumber,
234
- bankCode: account.servicer.bankCode,
235
- // For now we are using CZE as fallback because finbricks does not provide country code 100% of the time
236
- countryCode: account.servicer.countryCode || "CZE",
237
- holderName: account.ownersNames.join(", "),
238
- iban: account.identification.iban
239
- });
240
-
241
241
  class FinbricksConnector extends IBankConnector {
242
242
  constructor(provider, {
243
243
  BASE_URI,
@@ -1042,9 +1042,9 @@ class MockConnector extends IBankConnector {
1042
1042
  }
1043
1043
  }
1044
1044
 
1045
- const PAYMENT_TYPES = ["SEPA", "SWIFT", "IFSC", "DOMESTIC"];
1045
+ const PAYMENT_TYPES = ["SEPA", "SWIFT", "DOMESTIC", "UNKNOWN"];
1046
1046
  const CHARGE_BEARERS = ["SHA", "OUR", "BEN"];
1047
- const INSTRUCTION_PRIORITIES = ["NORM", "INST"];
1047
+ const INSTRUCTION_PRIORITIES = ["NORM", "HIGH", "INST"];
1048
1048
  const PAYMENT_STATUSES = [
1049
1049
  "PREPARED",
1050
1050
  "INITIALIZED",
@@ -1175,7 +1175,7 @@ const payment = sqliteTable("payment", {
1175
1175
  connectorKey: text("connector_key", { enum: CONNECTOR_KEYS }).$type().notNull(),
1176
1176
  amount: real("amount").notNull(),
1177
1177
  direction: text("direction").$type().notNull(),
1178
- paymentType: text("payment_type").$type(),
1178
+ paymentType: text("payment_type").$type().notNull(),
1179
1179
  currency: text("currency").$type().notNull(),
1180
1180
  status: text("status").$type().notNull(),
1181
1181
  statusReason: text("status_reason"),
@@ -23,8 +23,8 @@ declare const paymentInsertTypeZod: z.ZodObject<{
23
23
  paymentType: z.ZodEnum<{
24
24
  SEPA: "SEPA";
25
25
  SWIFT: "SWIFT";
26
- IFSC: "IFSC";
27
26
  DOMESTIC: "DOMESTIC";
27
+ UNKNOWN: "UNKNOWN";
28
28
  }>;
29
29
  currency: z.ZodEnum<{
30
30
  CZK: "CZK";
@@ -435,9 +435,9 @@ declare const payment: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
435
435
  tableName: "payment";
436
436
  dataType: "string";
437
437
  columnType: "SQLiteText";
438
- data: "SEPA" | "SWIFT" | "IFSC" | "DOMESTIC";
438
+ data: "SEPA" | "SWIFT" | "DOMESTIC" | "UNKNOWN";
439
439
  driverParam: string;
440
- notNull: false;
440
+ notNull: true;
441
441
  hasDefault: false;
442
442
  isPrimaryKey: false;
443
443
  isAutoincrement: false;
@@ -448,7 +448,7 @@ declare const payment: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
448
448
  generated: undefined;
449
449
  }, {}, {
450
450
  length: number | undefined;
451
- $type: "SEPA" | "SWIFT" | "IFSC" | "DOMESTIC";
451
+ $type: "SEPA" | "SWIFT" | "DOMESTIC" | "UNKNOWN";
452
452
  }>;
453
453
  currency: drizzle_orm_sqlite_core.SQLiteColumn<{
454
454
  name: "currency";
@@ -23,8 +23,8 @@ declare const paymentInsertTypeZod: z.ZodObject<{
23
23
  paymentType: z.ZodEnum<{
24
24
  SEPA: "SEPA";
25
25
  SWIFT: "SWIFT";
26
- IFSC: "IFSC";
27
26
  DOMESTIC: "DOMESTIC";
27
+ UNKNOWN: "UNKNOWN";
28
28
  }>;
29
29
  currency: z.ZodEnum<{
30
30
  CZK: "CZK";
@@ -435,9 +435,9 @@ declare const payment: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
435
435
  tableName: "payment";
436
436
  dataType: "string";
437
437
  columnType: "SQLiteText";
438
- data: "SEPA" | "SWIFT" | "IFSC" | "DOMESTIC";
438
+ data: "SEPA" | "SWIFT" | "DOMESTIC" | "UNKNOWN";
439
439
  driverParam: string;
440
- notNull: false;
440
+ notNull: true;
441
441
  hasDefault: false;
442
442
  isPrimaryKey: false;
443
443
  isAutoincrement: false;
@@ -448,7 +448,7 @@ declare const payment: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
448
448
  generated: undefined;
449
449
  }, {}, {
450
450
  length: number | undefined;
451
- $type: "SEPA" | "SWIFT" | "IFSC" | "DOMESTIC";
451
+ $type: "SEPA" | "SWIFT" | "DOMESTIC" | "UNKNOWN";
452
452
  }>;
453
453
  currency: drizzle_orm_sqlite_core.SQLiteColumn<{
454
454
  name: "currency";
@@ -23,8 +23,8 @@ declare const paymentInsertTypeZod: z.ZodObject<{
23
23
  paymentType: z.ZodEnum<{
24
24
  SEPA: "SEPA";
25
25
  SWIFT: "SWIFT";
26
- IFSC: "IFSC";
27
26
  DOMESTIC: "DOMESTIC";
27
+ UNKNOWN: "UNKNOWN";
28
28
  }>;
29
29
  currency: z.ZodEnum<{
30
30
  CZK: "CZK";
@@ -435,9 +435,9 @@ declare const payment: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
435
435
  tableName: "payment";
436
436
  dataType: "string";
437
437
  columnType: "SQLiteText";
438
- data: "SEPA" | "SWIFT" | "IFSC" | "DOMESTIC";
438
+ data: "SEPA" | "SWIFT" | "DOMESTIC" | "UNKNOWN";
439
439
  driverParam: string;
440
- notNull: false;
440
+ notNull: true;
441
441
  hasDefault: false;
442
442
  isPrimaryKey: false;
443
443
  isAutoincrement: false;
@@ -448,7 +448,7 @@ declare const payment: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
448
448
  generated: undefined;
449
449
  }, {}, {
450
450
  length: number | undefined;
451
- $type: "SEPA" | "SWIFT" | "IFSC" | "DOMESTIC";
451
+ $type: "SEPA" | "SWIFT" | "DOMESTIC" | "UNKNOWN";
452
452
  }>;
453
453
  currency: drizzle_orm_sqlite_core.SQLiteColumn<{
454
454
  name: "currency";
@@ -1,4 +1,4 @@
1
- import { F as FinbricksConnector } from './bank.RUV2HUFo.mjs';
1
+ import { F as FinbricksConnector } from './bank.Buq4PwHY.mjs';
2
2
 
3
3
  class MockCobsConnector extends FinbricksConnector {
4
4
  constructor(config) {
@@ -177,26 +177,46 @@ const mapFinbricksTransactionStatus = (status) => {
177
177
  const mapFinbricksBatchStatus = (status) => {
178
178
  return status === "REJECTED" ? "FAILED" : status === "AUTHORIZED" ? "PROCESSING" : "READY_TO_SIGN";
179
179
  };
180
+
181
+ const mapFinbricksAccountInsert = ({
182
+ account,
183
+ connectorKey,
184
+ status
185
+ }) => ({
186
+ id: account.id,
187
+ bankRefId: account.bankRefId,
188
+ connectorKey,
189
+ status,
190
+ currency: account.currency,
191
+ number: account.identification.accountNumber,
192
+ bankCode: account.servicer.bankCode,
193
+ // For now we are using CZE as fallback because finbricks does not provide country code 100% of the time
194
+ countryCode: account.servicer.countryCode || "CZE",
195
+ holderName: account.ownersNames.join(", "),
196
+ iban: account.identification.iban
197
+ });
198
+
180
199
  const mapFinbricksTransactionToPayment = (tx, account) => {
181
200
  const isIncoming = tx.creditDebitIndicator === "CRDT";
182
201
  const related = tx.entryDetails?.transactionDetails?.relatedParties;
183
202
  const base = {
184
203
  id: backendSdk.uuidv4(),
185
204
  correlationId: backendSdk.uuidv4(),
205
+ //TODO(kleinpetr): use real correlationId once available
186
206
  connectorKey: account.connectorKey,
187
207
  accountId: account.id,
188
- bankRefId: tx.entryReference || tx.fbxReference,
208
+ bankRefId: tx.fbxReference || tx.entryReference,
189
209
  amount: tx.amount?.value || 0,
190
210
  currency: tx.amount?.currency || "CZK",
191
211
  paymentType: "DOMESTIC",
192
212
  status: mapFinbricksStatus(tx.status),
193
- message: tx.entryDetails.transactionDetails?.remittanceInformation?.unstructured || tx.entryDetails.transactionDetails?.additionalRemittanceInformation || null,
213
+ message: tx.entryDetails.transactionDetails?.remittanceInformation?.unstructured || tx.entryDetails.transactionDetails?.additionalRemittanceInformation || tx.entryDetails.transactionDetails?.additionalTransactionInformation || null,
194
214
  processedAt: new Date(tx.bookingDate.date),
195
215
  ...mapReferencesToPayment(
196
216
  tx.entryDetails.transactionDetails?.remittanceInformation?.structured?.creditorReferenceInformation?.reference || tx.entryDetails.transactionDetails?.references?.endToEndIdentification
197
217
  ),
198
218
  creditor: {
199
- holderName: isIncoming ? "Unknown" : related?.creditor?.name || "Unknown",
219
+ holderName: related?.creditor?.name || "Unknown",
200
220
  iban: isIncoming ? account.iban || void 0 : related.creditorAccount?.identification?.iban || account.iban || void 0,
201
221
  number: isIncoming ? account.number || void 0 : related.creditorAccount?.identification?.other?.identification ? related.creditorAccount.identification.other.identification.split(
202
222
  "/"
@@ -206,7 +226,7 @@ const mapFinbricksTransactionToPayment = (tx, account) => {
206
226
  )[1] : account.bankCode || void 0
207
227
  },
208
228
  debtor: {
209
- holderName: isIncoming ? related?.debtor?.name || "Unknown" : "Unknown",
229
+ holderName: related?.debtor?.name || "Unknown",
210
230
  iban: isIncoming ? related.debtorAccount?.identification?.iban || account.iban || void 0 : account.iban ?? void 0,
211
231
  number: isIncoming ? related.debtorAccount?.identification?.other?.identification ? related.debtorAccount.identification.other.identification.split(
212
232
  "/"
@@ -215,31 +235,11 @@ const mapFinbricksTransactionToPayment = (tx, account) => {
215
235
  "/"
216
236
  )[1] : account.bankCode || void 0 : account.bankCode || void 0
217
237
  },
218
- direction: "INCOMING"
219
- // přepíšeme správným směrem níže
238
+ direction: isIncoming ? "INCOMING" : "OUTGOING"
220
239
  };
221
- base.direction = isIncoming ? "INCOMING" : "OUTGOING";
222
240
  return base;
223
241
  };
224
242
 
225
- const mapFinbricksAccountInsert = ({
226
- account,
227
- connectorKey,
228
- status
229
- }) => ({
230
- id: account.id,
231
- bankRefId: account.bankRefId,
232
- connectorKey,
233
- status,
234
- currency: account.currency,
235
- number: account.identification.accountNumber,
236
- bankCode: account.servicer.bankCode,
237
- // For now we are using CZE as fallback because finbricks does not provide country code 100% of the time
238
- countryCode: account.servicer.countryCode || "CZE",
239
- holderName: account.ownersNames.join(", "),
240
- iban: account.identification.iban
241
- });
242
-
243
243
  class FinbricksConnector extends IBankConnector {
244
244
  constructor(provider, {
245
245
  BASE_URI,
@@ -1044,9 +1044,9 @@ class MockConnector extends IBankConnector {
1044
1044
  }
1045
1045
  }
1046
1046
 
1047
- const PAYMENT_TYPES = ["SEPA", "SWIFT", "IFSC", "DOMESTIC"];
1047
+ const PAYMENT_TYPES = ["SEPA", "SWIFT", "DOMESTIC", "UNKNOWN"];
1048
1048
  const CHARGE_BEARERS = ["SHA", "OUR", "BEN"];
1049
- const INSTRUCTION_PRIORITIES = ["NORM", "INST"];
1049
+ const INSTRUCTION_PRIORITIES = ["NORM", "HIGH", "INST"];
1050
1050
  const PAYMENT_STATUSES = [
1051
1051
  "PREPARED",
1052
1052
  "INITIALIZED",
@@ -1177,7 +1177,7 @@ const payment = sqliteCore.sqliteTable("payment", {
1177
1177
  connectorKey: sqliteCore.text("connector_key", { enum: CONNECTOR_KEYS }).$type().notNull(),
1178
1178
  amount: sqliteCore.real("amount").notNull(),
1179
1179
  direction: sqliteCore.text("direction").$type().notNull(),
1180
- paymentType: sqliteCore.text("payment_type").$type(),
1180
+ paymentType: sqliteCore.text("payment_type").$type().notNull(),
1181
1181
  currency: sqliteCore.text("currency").$type().notNull(),
1182
1182
  status: sqliteCore.text("status").$type().notNull(),
1183
1183
  statusReason: sqliteCore.text("status_reason"),
@@ -3,16 +3,20 @@
3
3
  const cloudflare_workers = require('cloudflare:workers');
4
4
  const cloudflare_workflows = require('cloudflare:workflows');
5
5
  const d1 = require('drizzle-orm/d1');
6
- const database_schema = require('./bank.UfRkUN2y.cjs');
7
- require('@develit-io/backend-sdk');
6
+ const database_schema = require('./bank.DN3pRw5j.cjs');
7
+ const backendSdk = require('@develit-io/backend-sdk');
8
8
  const drizzleOrm = require('drizzle-orm');
9
- const mockCobs_connector = require('./bank.DISsqBb6.cjs');
9
+ const mockCobs_connector = require('./bank._ilV3SSc.cjs');
10
10
  require('jose');
11
11
  require('@develit-io/general-codes');
12
12
 
13
13
  const createPaymentCommand = (db, { payment }) => {
14
14
  return {
15
- command: db.insert(database_schema.tables.payment).values(payment).returning()
15
+ command: db.insert(database_schema.tables.payment).values({
16
+ ...payment,
17
+ creditorIban: payment.creditor.iban,
18
+ debtorIban: payment.debtor.iban
19
+ }).returning()
16
20
  };
17
21
  };
18
22
 
@@ -154,10 +158,15 @@ class SyncAccountPaymentsWorkflow extends cloudflare_workers.WorkflowEntrypoint
154
158
  return credentials2;
155
159
  }
156
160
  );
157
- const connector = await step.do(
158
- `init ${account.connectorKey} connector`,
161
+ const payments = await step.do(
162
+ "fetch bank payments",
163
+ {
164
+ retries: { limit: 5, delay: 2e3, backoff: "constant" },
165
+ timeout: "30 seconds"
166
+ },
159
167
  async () => {
160
- return initiateConnector({
168
+ console.log("starting connector initiation");
169
+ const connector = initiateConnector({
161
170
  env: this.env,
162
171
  bank: account.connectorKey,
163
172
  connectedAccounts: [
@@ -168,15 +177,7 @@ class SyncAccountPaymentsWorkflow extends cloudflare_workers.WorkflowEntrypoint
168
177
  }
169
178
  ]
170
179
  });
171
- }
172
- );
173
- const payments = await step.do(
174
- "fetch bank payments",
175
- {
176
- retries: { limit: 5, delay: 2e3, backoff: "constant" },
177
- timeout: "30 seconds"
178
- },
179
- async () => {
180
+ console.log("fetching payments from connector");
180
181
  const fetched = await connector.getAllAccountPayments({
181
182
  environment: this.env.ENVIRONMENT,
182
183
  db,
@@ -194,6 +195,7 @@ class SyncAccountPaymentsWorkflow extends cloudflare_workers.WorkflowEntrypoint
194
195
  }
195
196
  const bankRefIds = payments.map((payment) => payment.bankRefId).filter(Boolean);
196
197
  const existing = await step.do("load existing payments", async () => {
198
+ console.log("load existing payments");
197
199
  return await getPaymentsByBankRefIdsQuery(db, {
198
200
  ids: bankRefIds
199
201
  });
@@ -201,59 +203,70 @@ class SyncAccountPaymentsWorkflow extends cloudflare_workers.WorkflowEntrypoint
201
203
  const paymentsToUpdate = payments.filter(
202
204
  (p) => existing.some((e) => e.bankRefId === p.bankRefId)
203
205
  );
204
- if (paymentsToUpdate.length)
205
- await step.do("update existing payments", async () => {
206
- const commands = paymentsToUpdate.map(
207
- (p) => updatePaymentCommand(db, { payment: p }).command
208
- );
209
- await db.batch([commands[0], ...commands.slice(1)]);
210
- await pushToQueue(
211
- this.env.QUEUE_BUS_QUEUE,
212
- paymentsToUpdate.map((p) => ({
213
- eventType: "BANK_PAYMENT",
214
- eventSignal: "paymentUpdated",
215
- bankPayment: p,
216
- metadata: {
217
- correlationId: p.correlationId,
218
- entityId: p.id,
219
- idempotencySuffix: p.status,
220
- timestamp: (/* @__PURE__ */ new Date()).toDateString()
221
- }
222
- }))
223
- );
224
- });
225
206
  const paymentsToCreate = payments.filter(
226
207
  (p) => !existing.some((e) => e.bankRefId === p.bankRefId)
227
208
  );
228
- if (paymentsToCreate.length)
229
- await step.do("create new payments", async () => {
230
- const commands = paymentsToCreate.map(
231
- (p) => createPaymentCommand(db, { payment: p }).command
209
+ await step.do("process payments and update lastSyncAt", async () => {
210
+ const eventsToEmit = [];
211
+ console.log("process payments and update lastSyncAt");
212
+ const updateCommands = paymentsToUpdate.map(
213
+ (p) => updatePaymentCommand(db, { payment: p }).command
214
+ );
215
+ eventsToEmit.push(
216
+ ...paymentsToUpdate.map((p) => ({
217
+ eventType: "BANK_PAYMENT",
218
+ eventSignal: "paymentUpdated",
219
+ bankPayment: p,
220
+ metadata: {
221
+ correlationId: p.correlationId,
222
+ entityId: p.id,
223
+ idempotencySuffix: p.status,
224
+ timestamp: (/* @__PURE__ */ new Date()).toDateString()
225
+ }
226
+ }))
227
+ );
228
+ const createCommands = paymentsToCreate.map(
229
+ (p) => createPaymentCommand(db, { payment: p }).command
230
+ );
231
+ eventsToEmit.push(
232
+ ...paymentsToCreate.map((p) => ({
233
+ eventType: "BANK_PAYMENT",
234
+ eventSignal: "paymentCreated",
235
+ bankPayment: p,
236
+ metadata: {
237
+ correlationId: p.correlationId,
238
+ entityId: p.id,
239
+ timestamp: (/* @__PURE__ */ new Date()).toDateString()
240
+ }
241
+ }))
242
+ );
243
+ const latest = payments.reduce((current, p) => {
244
+ return new Date(p.processedAt).getTime() > new Date(current.processedAt).getTime() ? p : current;
245
+ }, payments[0]);
246
+ const updateLastSyncCommand = updateAccountLastSyncCommand(db, {
247
+ accountId: account.id,
248
+ lastSyncedAt: latest.processedAt
249
+ }).command;
250
+ if (eventsToEmit.length) {
251
+ await db.batch(
252
+ backendSdk.asNonEmpty([
253
+ updateLastSyncCommand,
254
+ ...updateCommands,
255
+ ...createCommands
256
+ ])
232
257
  );
233
- await db.batch([commands[0], ...commands.slice(1)]);
234
258
  await pushToQueue(
235
259
  this.env.QUEUE_BUS_QUEUE,
236
- paymentsToCreate.map((p) => ({
237
- eventType: "BANK_PAYMENT",
238
- eventSignal: "paymentCreated",
239
- bankPayment: p,
240
- metadata: {
241
- correlationId: p.correlationId,
242
- entityId: p.id,
243
- timestamp: (/* @__PURE__ */ new Date()).toDateString()
244
- }
245
- }))
260
+ eventsToEmit
246
261
  );
247
- });
248
- await step.do("determine new lastSyncedAt", async () => {
249
- const latest = payments.reduce((current, p) => {
250
- return new Date(p.createdAt).getTime() > new Date(current.createdAt).getTime() ? p : current;
251
- }, payments[0]);
252
- await updateAccountLastSyncCommand(db, {
253
- accountId: account.id,
254
- lastSyncedAt: latest.createdAt
255
- }).command.execute();
256
- return latest.createdAt;
262
+ }
263
+ return {
264
+ payments: payments.length,
265
+ updated: paymentsToUpdate.length,
266
+ created: paymentsToCreate.length,
267
+ eventsEmitted: eventsToEmit.length,
268
+ lastSyncedAt: latest?.createdAt
269
+ };
257
270
  });
258
271
  await step.sleep(
259
272
  "Sleep for next sync",
@@ -1,6 +1,6 @@
1
1
  import { Environment } from '@develit-io/backend-sdk';
2
2
  import { DrizzleD1Database } from 'drizzle-orm/d1';
3
- import { a as PaymentInsertType, t as tables } from './bank.mub5_S4r.cjs';
3
+ import { a as PaymentInsertType, t as tables } from './bank.CgiMSTo7.cjs';
4
4
  import { CURRENCY_CODES, BANK_CODES, CODES } from '@develit-io/general-codes';
5
5
  import { z } from 'zod';
6
6
  import * as drizzle_zod from 'drizzle-zod';
@@ -19,11 +19,11 @@ interface ConfigEnvironmentBank {
19
19
  allowedProviders: ConnectorKey[];
20
20
  }
21
21
 
22
- declare const PAYMENT_TYPES: readonly ["SEPA", "SWIFT", "IFSC", "DOMESTIC"];
22
+ declare const PAYMENT_TYPES: readonly ["SEPA", "SWIFT", "DOMESTIC", "UNKNOWN"];
23
23
  type PaymentType = (typeof PAYMENT_TYPES)[number];
24
24
  declare const CHARGE_BEARERS: readonly ["SHA", "OUR", "BEN"];
25
25
  type ChargeBearer = (typeof CHARGE_BEARERS)[number];
26
- declare const INSTRUCTION_PRIORITIES: readonly ["NORM", "INST"];
26
+ declare const INSTRUCTION_PRIORITIES: readonly ["NORM", "HIGH", "INST"];
27
27
  type InstructionPriority = (typeof INSTRUCTION_PRIORITIES)[number];
28
28
  declare const PAYMENT_STATUSES: readonly ["PREPARED", "INITIALIZED", "FAILED", "PENDING", "COMPLETED", "CREATED"];
29
29
  type PaymentStatus = (typeof PAYMENT_STATUSES)[number];
@@ -1,6 +1,6 @@
1
1
  import { Environment } from '@develit-io/backend-sdk';
2
2
  import { DrizzleD1Database } from 'drizzle-orm/d1';
3
- import { a as PaymentInsertType, t as tables } from './bank.mub5_S4r.mjs';
3
+ import { a as PaymentInsertType, t as tables } from './bank.CgiMSTo7.js';
4
4
  import { CURRENCY_CODES, BANK_CODES, CODES } from '@develit-io/general-codes';
5
5
  import { z } from 'zod';
6
6
  import * as drizzle_zod from 'drizzle-zod';
@@ -19,11 +19,11 @@ interface ConfigEnvironmentBank {
19
19
  allowedProviders: ConnectorKey[];
20
20
  }
21
21
 
22
- declare const PAYMENT_TYPES: readonly ["SEPA", "SWIFT", "IFSC", "DOMESTIC"];
22
+ declare const PAYMENT_TYPES: readonly ["SEPA", "SWIFT", "DOMESTIC", "UNKNOWN"];
23
23
  type PaymentType = (typeof PAYMENT_TYPES)[number];
24
24
  declare const CHARGE_BEARERS: readonly ["SHA", "OUR", "BEN"];
25
25
  type ChargeBearer = (typeof CHARGE_BEARERS)[number];
26
- declare const INSTRUCTION_PRIORITIES: readonly ["NORM", "INST"];
26
+ declare const INSTRUCTION_PRIORITIES: readonly ["NORM", "HIGH", "INST"];
27
27
  type InstructionPriority = (typeof INSTRUCTION_PRIORITIES)[number];
28
28
  declare const PAYMENT_STATUSES: readonly ["PREPARED", "INITIALIZED", "FAILED", "PENDING", "COMPLETED", "CREATED"];
29
29
  type PaymentStatus = (typeof PAYMENT_STATUSES)[number];
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const database_schema = require('./bank.UfRkUN2y.cjs');
3
+ const database_schema = require('./bank.DN3pRw5j.cjs');
4
4
 
5
5
  class MockCobsConnector extends database_schema.FinbricksConnector {
6
6
  constructor(config) {
@@ -1,6 +1,6 @@
1
1
  import { Environment } from '@develit-io/backend-sdk';
2
2
  import { DrizzleD1Database } from 'drizzle-orm/d1';
3
- import { a as PaymentInsertType, t as tables } from './bank.mub5_S4r.js';
3
+ import { a as PaymentInsertType, t as tables } from './bank.CgiMSTo7.mjs';
4
4
  import { CURRENCY_CODES, BANK_CODES, CODES } from '@develit-io/general-codes';
5
5
  import { z } from 'zod';
6
6
  import * as drizzle_zod from 'drizzle-zod';
@@ -19,11 +19,11 @@ interface ConfigEnvironmentBank {
19
19
  allowedProviders: ConnectorKey[];
20
20
  }
21
21
 
22
- declare const PAYMENT_TYPES: readonly ["SEPA", "SWIFT", "IFSC", "DOMESTIC"];
22
+ declare const PAYMENT_TYPES: readonly ["SEPA", "SWIFT", "DOMESTIC", "UNKNOWN"];
23
23
  type PaymentType = (typeof PAYMENT_TYPES)[number];
24
24
  declare const CHARGE_BEARERS: readonly ["SHA", "OUR", "BEN"];
25
25
  type ChargeBearer = (typeof CHARGE_BEARERS)[number];
26
- declare const INSTRUCTION_PRIORITIES: readonly ["NORM", "INST"];
26
+ declare const INSTRUCTION_PRIORITIES: readonly ["NORM", "HIGH", "INST"];
27
27
  type InstructionPriority = (typeof INSTRUCTION_PRIORITIES)[number];
28
28
  declare const PAYMENT_STATUSES: readonly ["PREPARED", "INITIALIZED", "FAILED", "PENDING", "COMPLETED", "CREATED"];
29
29
  type PaymentStatus = (typeof PAYMENT_STATUSES)[number];
package/dist/types.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- const database_schema = require('./shared/bank.UfRkUN2y.cjs');
4
- const mockCobs_connector = require('./shared/bank.DISsqBb6.cjs');
3
+ const database_schema = require('./shared/bank.DN3pRw5j.cjs');
4
+ const mockCobs_connector = require('./shared/bank._ilV3SSc.cjs');
5
5
  const generalCodes = require('@develit-io/general-codes');
6
6
  require('@develit-io/backend-sdk');
7
7
  require('drizzle-orm/sqlite-core');
package/dist/types.d.cts CHANGED
@@ -1,7 +1,7 @@
1
- import { I as IBankConnector, b as IncomingPaymentMessage, c as InitiatedPayment, a as ConnectorKey, d as ConnectedAccount, e as AccountCredentialsInsertType, f as AccountInsertType, P as PaymentPreparedInsertType, g as InitiatedBatch, B as BatchMetadata, A as AccountSelectType, h as PaymentStatus, i as BatchStatus, j as CurrencyCode, k as BankCode, l as CountryCode, m as AuthInput, n as Currency } from './shared/bank.BQSnGZ-3.cjs';
2
- export { D as ACCOUNT_STATUSES, Y as AccountCredentialsPatchType, Z as AccountCredentialsSelectType, X as AccountCredentialsUpdateType, S as AccountPatchType, E as AccountStatus, R as AccountUpdateType, q as BATCH_STATUES, q as BATCH_STATUSES, G as BankAccountWithLastSync, t as CHARGE_BEARERS, H as CONNECTOR_KEYS, F as COUNTRY_CODES, J as CREDENTIALS_TYPES, u as ChargeBearer, C as ConfigEnvironmentBank, K as CredentialsType, v as INSTRUCTION_PRIORITIES, w as InstructionPriority, O as OutgoingPaymentMessage, y as PAYMENT_DIRECTIONS, x as PAYMENT_STATUSES, r as PAYMENT_TYPES, z as PaymentDirection, o as PaymentFailedInsertType, s as PaymentType, T as TOKEN_TYPES, L as TokenType, U as accountCredentialsInsertSchema, W as accountCredentialsSelectSchema, V as accountCredentialsUpdateSchema, M as accountInsertSchema, Q as accountSelectSchema, N as accountUpdateSchema, p as paymentInitializedInsertType } from './shared/bank.BQSnGZ-3.cjs';
3
- import { a as PaymentInsertType, t as tables, P as PaymentSelectType } from './shared/bank.mub5_S4r.cjs';
4
- export { b as BatchInsertType, B as BatchSelectType, p as paymentInsertTypeZod } from './shared/bank.mub5_S4r.cjs';
1
+ import { I as IBankConnector, b as IncomingPaymentMessage, c as InitiatedPayment, a as ConnectorKey, d as ConnectedAccount, e as AccountCredentialsInsertType, f as AccountInsertType, P as PaymentPreparedInsertType, g as InitiatedBatch, B as BatchMetadata, A as AccountSelectType, h as PaymentStatus, i as BatchStatus, j as CurrencyCode, k as BankCode, l as CountryCode, m as AuthInput, n as Currency } from './shared/bank.DV-Kvdzh.cjs';
2
+ export { D as ACCOUNT_STATUSES, Y as AccountCredentialsPatchType, Z as AccountCredentialsSelectType, X as AccountCredentialsUpdateType, S as AccountPatchType, E as AccountStatus, R as AccountUpdateType, q as BATCH_STATUES, q as BATCH_STATUSES, G as BankAccountWithLastSync, t as CHARGE_BEARERS, H as CONNECTOR_KEYS, F as COUNTRY_CODES, J as CREDENTIALS_TYPES, u as ChargeBearer, C as ConfigEnvironmentBank, K as CredentialsType, v as INSTRUCTION_PRIORITIES, w as InstructionPriority, O as OutgoingPaymentMessage, y as PAYMENT_DIRECTIONS, x as PAYMENT_STATUSES, r as PAYMENT_TYPES, z as PaymentDirection, o as PaymentFailedInsertType, s as PaymentType, T as TOKEN_TYPES, L as TokenType, U as accountCredentialsInsertSchema, W as accountCredentialsSelectSchema, V as accountCredentialsUpdateSchema, M as accountInsertSchema, Q as accountSelectSchema, N as accountUpdateSchema, p as paymentInitializedInsertType } from './shared/bank.DV-Kvdzh.cjs';
3
+ import { a as PaymentInsertType, t as tables, P as PaymentSelectType } from './shared/bank.CgiMSTo7.cjs';
4
+ export { b as BatchInsertType, B as BatchSelectType, p as paymentInsertTypeZod } from './shared/bank.CgiMSTo7.cjs';
5
5
  import { Environment, BaseEvent } from '@develit-io/backend-sdk';
6
6
  import { DrizzleD1Database } from 'drizzle-orm/d1';
7
7
  export { b as BankServiceEnv, a as BankServiceEnvironmentConfig, B as BankServiceWranglerConfig } from './shared/bank.BchnXQDL.cjs';
@@ -220,7 +220,7 @@ type FinbricksAddress = {
220
220
  adressLine: string;
221
221
  };
222
222
  type FinbricksTransaction = {
223
- fbxReference: string;
223
+ fbxReference: string | null;
224
224
  entryReference: string;
225
225
  amount: FinbricksAmount;
226
226
  creditDebitIndicator: string;
@@ -319,6 +319,7 @@ type FinbricksTransaction = {
319
319
  };
320
320
  };
321
321
  additionalRemittanceInformation: string;
322
+ additionalTransactionInformation: string;
322
323
  };
323
324
  };
324
325
  };