@develit-services/bank 5.7.1 → 5.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/base.cjs CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  const backendSdk = require('@develit-io/backend-sdk');
4
4
  const paymentDirection = require('./shared/bank.CQjuudum.cjs');
5
+ const bank = require('./shared/bank.Cy7xa566.cjs');
5
6
  const drizzleOrm = require('drizzle-orm');
6
7
  const cloudflare_workers = require('cloudflare:workers');
7
8
  const d1 = require('drizzle-orm/d1');
8
9
  require('jose');
9
- const bank = require('./shared/bank.B0DNtuUM.cjs');
10
10
  const zod = require('zod');
11
11
  const database_schema = require('./shared/bank.9Yw4KHyl.cjs');
12
12
  const generalCodes = require('@develit-io/general-codes');
@@ -15,21 +15,37 @@ require('node:crypto');
15
15
  require('drizzle-orm/zod');
16
16
  require('drizzle-orm/sqlite-core');
17
17
 
18
+ const STALE_SYNC_INTERVAL_MULTIPLIER = 3;
19
+ function assessSyncStaleness({ syncIntervalS, lastSyncAt, createdAt }, nowMs, minGraceMs) {
20
+ const baseline = lastSyncAt ?? createdAt;
21
+ if (baseline == null) return null;
22
+ return {
23
+ staleForMs: nowMs - baseline.getTime(),
24
+ thresholdMs: Math.max(
25
+ syncIntervalS * STALE_SYNC_INTERVAL_MULTIPLIER * 1e3,
26
+ minGraceMs
27
+ )
28
+ };
29
+ }
30
+
18
31
  const DEAD_STATUSES = /* @__PURE__ */ new Set([
19
32
  "complete",
20
33
  "terminated",
21
34
  "errored",
22
35
  "unknown"
23
36
  ]);
37
+ const STALE_MIN_GRACE_MS = 15 * 60 * 1e3;
24
38
  async function heartbeatSyncWorkflows({
25
39
  entities,
26
40
  resetAfterIterations,
27
41
  getInstance,
28
42
  createInstance,
29
- logger
43
+ logger,
44
+ now = Date.now
30
45
  }) {
31
46
  await Promise.all(
32
- entities.map(async ({ id, iterationCount }) => {
47
+ entities.map(async (entity) => {
48
+ const { id, iterationCount, lastSyncAt } = entity;
33
49
  try {
34
50
  const instance = await getInstance(id);
35
51
  const { status } = await instance.status();
@@ -41,6 +57,24 @@ async function heartbeatSyncWorkflows({
41
57
  });
42
58
  return;
43
59
  }
60
+ const staleness = assessSyncStaleness(entity, now(), STALE_MIN_GRACE_MS);
61
+ if (staleness == null) {
62
+ logger.warn("sync-workflow.heartbeat.sync-age-unknown", {
63
+ id,
64
+ status
65
+ });
66
+ } else if (staleness.staleForMs > staleness.thresholdMs) {
67
+ await instance.restart();
68
+ logger.info("sync-workflow.heartbeat.stale-recovery", {
69
+ id,
70
+ status,
71
+ iterationCount,
72
+ lastSyncAt: lastSyncAt?.toISOString() ?? null,
73
+ staleForS: Math.round(staleness.staleForMs / 1e3),
74
+ thresholdS: Math.round(staleness.thresholdMs / 1e3)
75
+ });
76
+ return;
77
+ }
44
78
  if (iterationCount == null) {
45
79
  logger.warn("sync-workflow.heartbeat.iteration-count-missing", {
46
80
  id,
@@ -73,6 +107,88 @@ async function heartbeatSyncWorkflows({
73
107
  );
74
108
  }
75
109
 
110
+ const DISPATCH_RECOVERY_WINDOW_MS = 5 * 60 * 1e3;
111
+ function buildDispatchInstanceId(accountId, nowMs, recoveryWindowMs = DISPATCH_RECOVERY_WINDOW_MS) {
112
+ return `${accountId}-${Math.floor(nowMs / recoveryWindowMs)}`;
113
+ }
114
+ function buildDispatchCreateOptions(instanceId, accountId, maxIterations) {
115
+ return {
116
+ id: instanceId,
117
+ // Omitted (not undefined) when unresolved: the workflow treats a missing
118
+ // budget as unbounded — degraded but syncing.
119
+ params: maxIterations == null ? { accountId } : { accountId, maxIterations },
120
+ // Dispatch mints ~24 instances per account per day and step outputs carry
121
+ // bank payloads — the default 30-day retention would pile up billable
122
+ // storage for state nobody reads after success.
123
+ retention: {
124
+ successRetention: "1 day",
125
+ errorRetention: "7 days"
126
+ }
127
+ };
128
+ }
129
+ function isAlreadyExists(err) {
130
+ const message = err instanceof Error ? err.message : typeof err === "object" && err !== null && "message" in err ? String(err.message) : "";
131
+ return /already exists/i.test(message);
132
+ }
133
+
134
+ const DEFAULT_MIN_GRACE_MS = 3 * 60 * 1e3;
135
+ async function dispatchSyncWorkflows({
136
+ entities,
137
+ createInstance,
138
+ logger,
139
+ now = Date.now,
140
+ minGraceMs = DEFAULT_MIN_GRACE_MS,
141
+ recoveryWindowMs = DISPATCH_RECOVERY_WINDOW_MS
142
+ }) {
143
+ const at = now();
144
+ await Promise.all(
145
+ entities.map(async (entity) => {
146
+ const { id, lastSyncAt } = entity;
147
+ const staleness = assessSyncStaleness(entity, at, minGraceMs);
148
+ if (staleness == null) {
149
+ logger.warn("sync-workflow.dispatch.sync-age-unknown", { id });
150
+ return;
151
+ }
152
+ if (staleness.staleForMs <= staleness.thresholdMs) return;
153
+ const instanceId = buildDispatchInstanceId(id, at, recoveryWindowMs);
154
+ try {
155
+ await createInstance(instanceId, id);
156
+ logger.info("sync-workflow.dispatch.created", {
157
+ id,
158
+ instanceId,
159
+ lastSyncAt: lastSyncAt?.toISOString() ?? null,
160
+ staleForS: Math.round(staleness.staleForMs / 1e3),
161
+ thresholdS: Math.round(staleness.thresholdMs / 1e3)
162
+ });
163
+ } catch (err) {
164
+ if (isAlreadyExists(err)) {
165
+ logger.info("sync-workflow.dispatch.already-running", {
166
+ id,
167
+ instanceId
168
+ });
169
+ return;
170
+ }
171
+ logger.error("sync-workflow.dispatch.failed", {
172
+ id,
173
+ instanceId,
174
+ error: err instanceof Error ? err.message : String(err)
175
+ });
176
+ }
177
+ })
178
+ );
179
+ }
180
+
181
+ function isDispatchEnabled(accountId, selection) {
182
+ const raw = selection?.trim();
183
+ if (!raw) return false;
184
+ if (raw.toLowerCase() === "all") return true;
185
+ return raw.split(",").map((id) => id.trim()).includes(accountId);
186
+ }
187
+ function isDispatchActive(accountId, selection, dispatchCron) {
188
+ if (!dispatchCron?.trim()) return false;
189
+ return isDispatchEnabled(accountId, selection);
190
+ }
191
+
76
192
  const FINITE_STATUSES = /* @__PURE__ */ new Set([
77
193
  "complete",
78
194
  "errored",
@@ -750,6 +866,11 @@ var __decorateClass = (decorators, target, key, kind) => {
750
866
  if (kind && result) __defProp(target, key, result);
751
867
  return result;
752
868
  };
869
+ const syncEventConsoleLogger = {
870
+ info: (event, data) => console.log(JSON.stringify({ level: "info", event, ...data })),
871
+ warn: (event, data) => console.warn(JSON.stringify({ level: "warn", event, ...data })),
872
+ error: (event, data) => console.error(JSON.stringify({ level: "error", event, ...data }))
873
+ };
753
874
  exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker(cloudflare_workers.WorkerEntrypoint) {
754
875
  constructor(ctx, env, config) {
755
876
  super(ctx, env);
@@ -852,6 +973,29 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
852
973
  { data: input, schema: syncAccountInputSchema },
853
974
  { successMessage: "Account sync workflow started" },
854
975
  async ({ accountId }) => {
976
+ if (isDispatchActive(
977
+ accountId,
978
+ this.env.SYNC_DISPATCH_ACCOUNT_IDS,
979
+ this.env.CRON_SYNC_WORKFLOW_DISPATCH
980
+ )) {
981
+ const instanceId = buildDispatchInstanceId(accountId, Date.now());
982
+ const maxIterations = bank.parseIterationBudgetParam(
983
+ this.env.SYNC_WORKFLOW_MAX_ITERATIONS
984
+ );
985
+ let instance2;
986
+ try {
987
+ instance2 = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.create(
988
+ buildDispatchCreateOptions(instanceId, accountId, maxIterations)
989
+ );
990
+ } catch (err) {
991
+ if (!isAlreadyExists(err)) throw err;
992
+ instance2 = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(instanceId);
993
+ }
994
+ return {
995
+ instanceId: instance2.id,
996
+ details: await instance2.status()
997
+ };
998
+ }
855
999
  const instance = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.create({
856
1000
  id: accountId,
857
1001
  params: {
@@ -870,7 +1014,7 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
870
1014
  { data: input, schema: syncAccountStatusInputSchema },
871
1015
  { successMessage: "Account sync workflow status retrieved" },
872
1016
  async ({ accountId }) => {
873
- const instance = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(accountId);
1017
+ const instance = await this.getCurrentSyncInstance(accountId);
874
1018
  return {
875
1019
  instanceId: instance.id,
876
1020
  details: await instance.status()
@@ -883,7 +1027,7 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
883
1027
  { data: input, schema: syncAccountRestartInputSchema },
884
1028
  { successMessage: "Account sync workflow restarted" },
885
1029
  async ({ accountId }) => {
886
- const instance = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(accountId);
1030
+ const instance = await this.getCurrentSyncInstance(accountId);
887
1031
  await instance.restart();
888
1032
  return {
889
1033
  instanceId: instance.id,
@@ -897,7 +1041,7 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
897
1041
  { data: input, schema: syncAccountTerminateInputSchema },
898
1042
  { successMessage: "Account sync workflow terminated" },
899
1043
  async ({ accountId }) => {
900
- const instance = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(accountId);
1044
+ const instance = await this.getCurrentSyncInstance(accountId);
901
1045
  await terminateSyncWorkflow(instance);
902
1046
  return {
903
1047
  instanceId: instance.id
@@ -1181,17 +1325,62 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
1181
1325
  if (controller.cron === this.env.CRON_PAYMENT_STATUSES) {
1182
1326
  console.log("Scheduled CRON payment request statuses");
1183
1327
  await this.updatePaymentRequestStatuses();
1184
- return;
1328
+ }
1329
+ if (controller.cron === this.env.CRON_SYNC_WORKFLOW_DISPATCH) {
1330
+ await this.dispatchSyncWorkflows();
1185
1331
  }
1186
1332
  if (controller.cron === this.env.CRON_SYNC_WORKFLOW_HEARTBEAT) {
1187
1333
  console.log("Scheduled CRON sync workflow heartbeat");
1188
1334
  await this.heartbeatSyncWorkflows();
1189
1335
  }
1190
1336
  }
1337
+ /**
1338
+ * Lifecycle actions must target the instance that actually syncs the
1339
+ * account — under dispatch that is the windowed instance recorded with the
1340
+ * last sync write, not the legacy canonical id.
1341
+ */
1342
+ async getCurrentSyncInstance(accountId) {
1343
+ const account = await bank.getAccountByIdQuery(this.db, { accountId });
1344
+ return this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(
1345
+ bank.resolveCurrentSyncInstanceId(
1346
+ accountId,
1347
+ account?.lastSyncMetadata?.instanceId
1348
+ )
1349
+ );
1350
+ }
1351
+ async dispatchSyncWorkflows() {
1352
+ const selection = this.env.SYNC_DISPATCH_ACCOUNT_IDS;
1353
+ if (!selection?.trim()) return;
1354
+ const accounts = await this.db.select({
1355
+ id: paymentDirection.tables.account.id,
1356
+ syncIntervalS: paymentDirection.tables.account.syncIntervalS,
1357
+ lastSyncAt: paymentDirection.tables.account.lastSyncAt,
1358
+ createdAt: paymentDirection.tables.account.createdAt
1359
+ }).from(paymentDirection.tables.account).where(drizzleOrm.eq(paymentDirection.tables.account.status, "AUTHORIZED")).all();
1360
+ const maxIterations = bank.parseIterationBudgetParam(
1361
+ this.env.SYNC_WORKFLOW_MAX_ITERATIONS
1362
+ );
1363
+ if (maxIterations == null) {
1364
+ syncEventConsoleLogger.error(
1365
+ "sync-workflow.dispatch.invalid-max-iterations",
1366
+ { value: this.env.SYNC_WORKFLOW_MAX_ITERATIONS }
1367
+ );
1368
+ }
1369
+ await dispatchSyncWorkflows({
1370
+ entities: accounts.filter((a) => isDispatchEnabled(a.id, selection)),
1371
+ createInstance: (instanceId, accountId) => this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.create(
1372
+ buildDispatchCreateOptions(instanceId, accountId, maxIterations)
1373
+ ),
1374
+ logger: syncEventConsoleLogger
1375
+ });
1376
+ }
1191
1377
  async heartbeatSyncWorkflows() {
1192
1378
  const accounts = await this.db.select({
1193
1379
  id: paymentDirection.tables.account.id,
1194
- lastSyncMetadata: paymentDirection.tables.account.lastSyncMetadata
1380
+ lastSyncMetadata: paymentDirection.tables.account.lastSyncMetadata,
1381
+ syncIntervalS: paymentDirection.tables.account.syncIntervalS,
1382
+ lastSyncAt: paymentDirection.tables.account.lastSyncAt,
1383
+ createdAt: paymentDirection.tables.account.createdAt
1195
1384
  }).from(paymentDirection.tables.account).where(drizzleOrm.eq(paymentDirection.tables.account.status, "AUTHORIZED")).all();
1196
1385
  const resetAfterIterations = Number(
1197
1386
  this.env.SYNC_WORKFLOW_RESET_AFTER_ITERATIONS
@@ -1204,9 +1393,18 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
1204
1393
  return;
1205
1394
  }
1206
1395
  await heartbeatSyncWorkflows({
1207
- entities: accounts.map((a) => ({
1396
+ entities: accounts.filter(
1397
+ (a) => !isDispatchActive(
1398
+ a.id,
1399
+ this.env.SYNC_DISPATCH_ACCOUNT_IDS,
1400
+ this.env.CRON_SYNC_WORKFLOW_DISPATCH
1401
+ )
1402
+ ).map((a) => ({
1208
1403
  id: a.id,
1209
- iterationCount: a.lastSyncMetadata?.iterationCount
1404
+ iterationCount: a.lastSyncMetadata?.iterationCount,
1405
+ syncIntervalS: a.syncIntervalS,
1406
+ lastSyncAt: a.lastSyncAt,
1407
+ createdAt: a.createdAt
1210
1408
  })),
1211
1409
  resetAfterIterations,
1212
1410
  getInstance: (id) => this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(id),
@@ -1214,11 +1412,7 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
1214
1412
  id,
1215
1413
  params: { accountId: id }
1216
1414
  }),
1217
- logger: {
1218
- info: (event, data) => console.log(JSON.stringify({ level: "info", event, ...data })),
1219
- warn: (event, data) => console.warn(JSON.stringify({ level: "warn", event, ...data })),
1220
- error: (event, data) => console.error(JSON.stringify({ level: "error", event, ...data }))
1221
- }
1415
+ logger: syncEventConsoleLogger
1222
1416
  });
1223
1417
  }
1224
1418
  async handleAuthorizationCallback(input) {
@@ -1977,7 +2171,12 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
1977
2171
  if (includeWorkflow) {
1978
2172
  let status;
1979
2173
  try {
1980
- const instance = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(a.id);
2174
+ const instance = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(
2175
+ bank.resolveCurrentSyncInstanceId(
2176
+ a.id,
2177
+ a.lastSyncMetadata?.instanceId
2178
+ )
2179
+ );
1981
2180
  status = await instance.status();
1982
2181
  } catch (_) {
1983
2182
  status = null;
@@ -2081,7 +2280,12 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
2081
2280
  });
2082
2281
  }
2083
2282
  try {
2084
- const instance = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(accountId);
2283
+ const instance = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(
2284
+ bank.resolveCurrentSyncInstanceId(
2285
+ accountId,
2286
+ account.lastSyncMetadata?.instanceId
2287
+ )
2288
+ );
2085
2289
  await terminateSyncWorkflow(instance);
2086
2290
  } catch (error) {
2087
2291
  this.log({
package/dist/base.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as BatchSelectType, P as PaymentRequestSelectType, A as AccountSelectType, a as PaymentSelectType, L as LastSyncMetadata, C as ConnectorConfig, t as tables, b as ConnectorKey, c as ConfigEnvironmentBank, I as IBankConnector, d as PaymentType, e as CurrencyCode, H as HandleAuthorizationCallbackInput, f as HandleAuthorizationCallbackOutput } from './shared/bank.BQwwtIR4.cjs';
2
- import { S as SendPaymentInput, a as SendPaymentOutput, b as SendPaymentSyncInput, c as SendPaymentSyncOutput, F as FinbricksSupportedBanksResponse } from './shared/bank.BUzoc8p6.cjs';
1
+ import { B as BatchSelectType, P as PaymentRequestSelectType, A as AccountSelectType, a as PaymentSelectType, L as LastSyncMetadata, C as ConnectorConfig, t as tables, b as ConnectorKey, c as ConfigEnvironmentBank, I as IBankConnector, d as PaymentType, e as CurrencyCode, H as HandleAuthorizationCallbackInput, f as HandleAuthorizationCallbackOutput } from './shared/bank.CefGTNH1.cjs';
2
+ import { S as SendPaymentInput, a as SendPaymentOutput, b as SendPaymentSyncInput, c as SendPaymentSyncOutput, F as FinbricksSupportedBanksResponse } from './shared/bank.CtIkqQG9.cjs';
3
3
  import * as _develit_io_backend_sdk from '@develit-io/backend-sdk';
4
4
  import { WorkflowInstanceStatus, IRPCResponse } from '@develit-io/backend-sdk';
5
5
  import { WorkerEntrypoint } from 'cloudflare:workers';
@@ -2711,15 +2711,15 @@ declare const getBatchesInputSchema: z.ZodObject<{
2711
2711
  filterBatchAccountId: z.ZodOptional<z.ZodUnion<readonly [z.ZodUUID, z.ZodArray<z.ZodUUID>]>>;
2712
2712
  filterBatchStatus: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
2713
2713
  AUTHORIZED: "AUTHORIZED";
2714
+ COMPLETED: "COMPLETED";
2714
2715
  PROCESSING: "PROCESSING";
2715
2716
  READY_TO_SIGN: "READY_TO_SIGN";
2716
- COMPLETED: "COMPLETED";
2717
2717
  FAILED: "FAILED";
2718
2718
  }>, z.ZodArray<z.ZodEnum<{
2719
2719
  AUTHORIZED: "AUTHORIZED";
2720
+ COMPLETED: "COMPLETED";
2720
2721
  PROCESSING: "PROCESSING";
2721
2722
  READY_TO_SIGN: "READY_TO_SIGN";
2722
- COMPLETED: "COMPLETED";
2723
2723
  FAILED: "FAILED";
2724
2724
  }>>]>>;
2725
2725
  }, z.core.$strip>;
@@ -2825,9 +2825,9 @@ declare const getPaymentsInputSchema: z.ZodObject<{
2825
2825
  limit: z.ZodNumber;
2826
2826
  sort: z.ZodObject<{
2827
2827
  column: z.ZodEnum<{
2828
+ amount: "amount";
2828
2829
  createdAt: "createdAt";
2829
2830
  updatedAt: "updatedAt";
2830
- amount: "amount";
2831
2831
  }>;
2832
2832
  direction: z.ZodEnum<{
2833
2833
  asc: "asc";
@@ -2956,20 +2956,20 @@ declare const getPaymentsInputSchema: z.ZodObject<{
2956
2956
  filterPaymentDateFrom: z.ZodOptional<z.ZodDate>;
2957
2957
  filterPaymentDateTo: z.ZodOptional<z.ZodDate>;
2958
2958
  filterPaymentStatus: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
2959
+ BOOKED: "BOOKED";
2960
+ REJECTED: "REJECTED";
2959
2961
  PROCESSING: "PROCESSING";
2960
2962
  PENDING: "PENDING";
2961
- BOOKED: "BOOKED";
2962
2963
  CANCELLED: "CANCELLED";
2963
- REJECTED: "REJECTED";
2964
2964
  SCHEDULED: "SCHEDULED";
2965
2965
  HOLD: "HOLD";
2966
2966
  INFO: "INFO";
2967
2967
  }>, z.ZodArray<z.ZodEnum<{
2968
+ BOOKED: "BOOKED";
2969
+ REJECTED: "REJECTED";
2968
2970
  PROCESSING: "PROCESSING";
2969
2971
  PENDING: "PENDING";
2970
- BOOKED: "BOOKED";
2971
2972
  CANCELLED: "CANCELLED";
2972
- REJECTED: "REJECTED";
2973
2973
  SCHEDULED: "SCHEDULED";
2974
2974
  HOLD: "HOLD";
2975
2975
  INFO: "INFO";
@@ -3875,9 +3875,9 @@ declare const getPaymentRequestsInputSchema: z.ZodObject<{
3875
3875
  limit: z.ZodNumber;
3876
3876
  sort: z.ZodObject<{
3877
3877
  column: z.ZodEnum<{
3878
+ amount: "amount";
3878
3879
  createdAt: "createdAt";
3879
3880
  updatedAt: "updatedAt";
3880
- amount: "amount";
3881
3881
  }>;
3882
3882
  direction: z.ZodEnum<{
3883
3883
  asc: "asc";
@@ -3886,20 +3886,20 @@ declare const getPaymentRequestsInputSchema: z.ZodObject<{
3886
3886
  }, z.core.$strip>;
3887
3887
  filterAccountId: z.ZodOptional<z.ZodUnion<readonly [z.ZodUUID, z.ZodArray<z.ZodUUID>]>>;
3888
3888
  filterStatus: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
3889
+ OPENED: "OPENED";
3889
3890
  AUTHORIZED: "AUTHORIZED";
3890
3891
  COMPLETED: "COMPLETED";
3891
3892
  BOOKED: "BOOKED";
3892
- REJECTED: "REJECTED";
3893
- OPENED: "OPENED";
3894
3893
  SETTLED: "SETTLED";
3894
+ REJECTED: "REJECTED";
3895
3895
  CLOSED: "CLOSED";
3896
3896
  }>, z.ZodArray<z.ZodEnum<{
3897
+ OPENED: "OPENED";
3897
3898
  AUTHORIZED: "AUTHORIZED";
3898
3899
  COMPLETED: "COMPLETED";
3899
3900
  BOOKED: "BOOKED";
3900
- REJECTED: "REJECTED";
3901
- OPENED: "OPENED";
3902
3901
  SETTLED: "SETTLED";
3902
+ REJECTED: "REJECTED";
3903
3903
  CLOSED: "CLOSED";
3904
3904
  }>>]>>;
3905
3905
  filterPaymentType: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
@@ -4193,6 +4193,13 @@ declare class BankServiceBase extends BankServiceBase_base {
4193
4193
  statusChanged: number;
4194
4194
  }>>;
4195
4195
  scheduled(controller: ScheduledController): Promise<void>;
4196
+ /**
4197
+ * Lifecycle actions must target the instance that actually syncs the
4198
+ * account — under dispatch that is the windowed instance recorded with the
4199
+ * last sync write, not the legacy canonical id.
4200
+ */
4201
+ private getCurrentSyncInstance;
4202
+ private dispatchSyncWorkflows;
4196
4203
  private heartbeatSyncWorkflows;
4197
4204
  handleAuthorizationCallback(input: HandleAuthorizationCallbackInput): Promise<IRPCResponse<HandleAuthorizationCallbackOutput>>;
4198
4205
  closePaymentRequest(input: ClosePaymentRequestInput): Promise<IRPCResponse<ClosePaymentRequestOutput>>;
package/dist/base.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as BatchSelectType, P as PaymentRequestSelectType, A as AccountSelectType, a as PaymentSelectType, L as LastSyncMetadata, C as ConnectorConfig, t as tables, b as ConnectorKey, c as ConfigEnvironmentBank, I as IBankConnector, d as PaymentType, e as CurrencyCode, H as HandleAuthorizationCallbackInput, f as HandleAuthorizationCallbackOutput } from './shared/bank.BQwwtIR4.mjs';
2
- import { S as SendPaymentInput, a as SendPaymentOutput, b as SendPaymentSyncInput, c as SendPaymentSyncOutput, F as FinbricksSupportedBanksResponse } from './shared/bank.DZ3Ow4bP.mjs';
1
+ import { B as BatchSelectType, P as PaymentRequestSelectType, A as AccountSelectType, a as PaymentSelectType, L as LastSyncMetadata, C as ConnectorConfig, t as tables, b as ConnectorKey, c as ConfigEnvironmentBank, I as IBankConnector, d as PaymentType, e as CurrencyCode, H as HandleAuthorizationCallbackInput, f as HandleAuthorizationCallbackOutput } from './shared/bank.CefGTNH1.mjs';
2
+ import { S as SendPaymentInput, a as SendPaymentOutput, b as SendPaymentSyncInput, c as SendPaymentSyncOutput, F as FinbricksSupportedBanksResponse } from './shared/bank.oNDZ44du.mjs';
3
3
  import * as _develit_io_backend_sdk from '@develit-io/backend-sdk';
4
4
  import { WorkflowInstanceStatus, IRPCResponse } from '@develit-io/backend-sdk';
5
5
  import { WorkerEntrypoint } from 'cloudflare:workers';
@@ -2711,15 +2711,15 @@ declare const getBatchesInputSchema: z.ZodObject<{
2711
2711
  filterBatchAccountId: z.ZodOptional<z.ZodUnion<readonly [z.ZodUUID, z.ZodArray<z.ZodUUID>]>>;
2712
2712
  filterBatchStatus: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
2713
2713
  AUTHORIZED: "AUTHORIZED";
2714
+ COMPLETED: "COMPLETED";
2714
2715
  PROCESSING: "PROCESSING";
2715
2716
  READY_TO_SIGN: "READY_TO_SIGN";
2716
- COMPLETED: "COMPLETED";
2717
2717
  FAILED: "FAILED";
2718
2718
  }>, z.ZodArray<z.ZodEnum<{
2719
2719
  AUTHORIZED: "AUTHORIZED";
2720
+ COMPLETED: "COMPLETED";
2720
2721
  PROCESSING: "PROCESSING";
2721
2722
  READY_TO_SIGN: "READY_TO_SIGN";
2722
- COMPLETED: "COMPLETED";
2723
2723
  FAILED: "FAILED";
2724
2724
  }>>]>>;
2725
2725
  }, z.core.$strip>;
@@ -2825,9 +2825,9 @@ declare const getPaymentsInputSchema: z.ZodObject<{
2825
2825
  limit: z.ZodNumber;
2826
2826
  sort: z.ZodObject<{
2827
2827
  column: z.ZodEnum<{
2828
+ amount: "amount";
2828
2829
  createdAt: "createdAt";
2829
2830
  updatedAt: "updatedAt";
2830
- amount: "amount";
2831
2831
  }>;
2832
2832
  direction: z.ZodEnum<{
2833
2833
  asc: "asc";
@@ -2956,20 +2956,20 @@ declare const getPaymentsInputSchema: z.ZodObject<{
2956
2956
  filterPaymentDateFrom: z.ZodOptional<z.ZodDate>;
2957
2957
  filterPaymentDateTo: z.ZodOptional<z.ZodDate>;
2958
2958
  filterPaymentStatus: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
2959
+ BOOKED: "BOOKED";
2960
+ REJECTED: "REJECTED";
2959
2961
  PROCESSING: "PROCESSING";
2960
2962
  PENDING: "PENDING";
2961
- BOOKED: "BOOKED";
2962
2963
  CANCELLED: "CANCELLED";
2963
- REJECTED: "REJECTED";
2964
2964
  SCHEDULED: "SCHEDULED";
2965
2965
  HOLD: "HOLD";
2966
2966
  INFO: "INFO";
2967
2967
  }>, z.ZodArray<z.ZodEnum<{
2968
+ BOOKED: "BOOKED";
2969
+ REJECTED: "REJECTED";
2968
2970
  PROCESSING: "PROCESSING";
2969
2971
  PENDING: "PENDING";
2970
- BOOKED: "BOOKED";
2971
2972
  CANCELLED: "CANCELLED";
2972
- REJECTED: "REJECTED";
2973
2973
  SCHEDULED: "SCHEDULED";
2974
2974
  HOLD: "HOLD";
2975
2975
  INFO: "INFO";
@@ -3875,9 +3875,9 @@ declare const getPaymentRequestsInputSchema: z.ZodObject<{
3875
3875
  limit: z.ZodNumber;
3876
3876
  sort: z.ZodObject<{
3877
3877
  column: z.ZodEnum<{
3878
+ amount: "amount";
3878
3879
  createdAt: "createdAt";
3879
3880
  updatedAt: "updatedAt";
3880
- amount: "amount";
3881
3881
  }>;
3882
3882
  direction: z.ZodEnum<{
3883
3883
  asc: "asc";
@@ -3886,20 +3886,20 @@ declare const getPaymentRequestsInputSchema: z.ZodObject<{
3886
3886
  }, z.core.$strip>;
3887
3887
  filterAccountId: z.ZodOptional<z.ZodUnion<readonly [z.ZodUUID, z.ZodArray<z.ZodUUID>]>>;
3888
3888
  filterStatus: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
3889
+ OPENED: "OPENED";
3889
3890
  AUTHORIZED: "AUTHORIZED";
3890
3891
  COMPLETED: "COMPLETED";
3891
3892
  BOOKED: "BOOKED";
3892
- REJECTED: "REJECTED";
3893
- OPENED: "OPENED";
3894
3893
  SETTLED: "SETTLED";
3894
+ REJECTED: "REJECTED";
3895
3895
  CLOSED: "CLOSED";
3896
3896
  }>, z.ZodArray<z.ZodEnum<{
3897
+ OPENED: "OPENED";
3897
3898
  AUTHORIZED: "AUTHORIZED";
3898
3899
  COMPLETED: "COMPLETED";
3899
3900
  BOOKED: "BOOKED";
3900
- REJECTED: "REJECTED";
3901
- OPENED: "OPENED";
3902
3901
  SETTLED: "SETTLED";
3902
+ REJECTED: "REJECTED";
3903
3903
  CLOSED: "CLOSED";
3904
3904
  }>>]>>;
3905
3905
  filterPaymentType: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
@@ -4193,6 +4193,13 @@ declare class BankServiceBase extends BankServiceBase_base {
4193
4193
  statusChanged: number;
4194
4194
  }>>;
4195
4195
  scheduled(controller: ScheduledController): Promise<void>;
4196
+ /**
4197
+ * Lifecycle actions must target the instance that actually syncs the
4198
+ * account — under dispatch that is the windowed instance recorded with the
4199
+ * last sync write, not the legacy canonical id.
4200
+ */
4201
+ private getCurrentSyncInstance;
4202
+ private dispatchSyncWorkflows;
4196
4203
  private heartbeatSyncWorkflows;
4197
4204
  handleAuthorizationCallback(input: HandleAuthorizationCallbackInput): Promise<IRPCResponse<HandleAuthorizationCallbackOutput>>;
4198
4205
  closePaymentRequest(input: ClosePaymentRequestInput): Promise<IRPCResponse<ClosePaymentRequestOutput>>;