@develit-services/bank 0.3.47 → 0.3.49
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/export/worker.cjs +57 -16
- package/dist/export/worker.d.cts +23 -8
- package/dist/export/worker.d.mts +23 -8
- package/dist/export/worker.d.ts +23 -8
- package/dist/export/worker.mjs +59 -18
- package/package.json +1 -1
package/dist/export/worker.cjs
CHANGED
|
@@ -93,6 +93,27 @@ const deletePaymentsByAccountCommand = (db, { accountId }) => {
|
|
|
93
93
|
};
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
+
const getAccountBatchCountsQuery = async (db, { accountId }) => {
|
|
97
|
+
const result = await db.select({
|
|
98
|
+
totalCount: drizzleOrm.sql`COUNT(*)`.as("totalCount"),
|
|
99
|
+
openCount: drizzleOrm.sql`SUM(CASE WHEN ${drizzle.tables.batch.status} = 'OPEN' THEN 1 ELSE 0 END)`.as(
|
|
100
|
+
"openCount"
|
|
101
|
+
),
|
|
102
|
+
readyToSignCount: drizzleOrm.sql`SUM(CASE WHEN ${drizzle.tables.batch.status} = 'READY_TO_SIGN' THEN 1 ELSE 0 END)`.as(
|
|
103
|
+
"readyToSignCount"
|
|
104
|
+
),
|
|
105
|
+
failedCount: drizzleOrm.sql`SUM(CASE WHEN ${drizzle.tables.batch.status} = 'FAILED' THEN 1 ELSE 0 END)`.as(
|
|
106
|
+
"failedCount"
|
|
107
|
+
)
|
|
108
|
+
}).from(drizzle.tables.batch).where(drizzleOrm.eq(drizzle.tables.batch.accountId, accountId)).then(backendSdk.first);
|
|
109
|
+
return result || {
|
|
110
|
+
totalCount: 0,
|
|
111
|
+
openCount: 0,
|
|
112
|
+
readyToSignCount: 0,
|
|
113
|
+
failedCount: 0
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
|
|
96
117
|
const getAccountByIbanQuery = async (db, { iban }) => {
|
|
97
118
|
return await db.select().from(drizzle.tables.account).where(drizzleOrm.eq(drizzle.tables.account.iban, iban)).get();
|
|
98
119
|
};
|
|
@@ -385,6 +406,13 @@ const updateAccountInputSchema = zod.z.object({
|
|
|
385
406
|
account: database_schema.accountInsertSchema
|
|
386
407
|
});
|
|
387
408
|
|
|
409
|
+
const getBankAccountsInputSchema = zod.z.object({
|
|
410
|
+
includes: zod.z.object({
|
|
411
|
+
workflow: zod.z.boolean().optional(),
|
|
412
|
+
batchCounts: zod.z.boolean().optional()
|
|
413
|
+
}).optional()
|
|
414
|
+
});
|
|
415
|
+
|
|
388
416
|
const disconnectAccountInputSchema = zod.z.object({
|
|
389
417
|
accountId: zod.z.uuid()
|
|
390
418
|
});
|
|
@@ -981,32 +1009,45 @@ let BankServiceBase = class extends backendSdk.develitWorker(cloudflare_workers.
|
|
|
981
1009
|
}
|
|
982
1010
|
);
|
|
983
1011
|
}
|
|
984
|
-
async getBankAccounts() {
|
|
1012
|
+
async getBankAccounts(input) {
|
|
985
1013
|
return this.handleAction(
|
|
986
|
-
|
|
1014
|
+
{ data: input, schema: getBankAccountsInputSchema },
|
|
987
1015
|
{ successMessage: "Bank accounts retrieved successfully" },
|
|
988
|
-
async () => {
|
|
1016
|
+
async ({ includes }) => {
|
|
989
1017
|
const accounts = await this._getAccounts();
|
|
990
|
-
const
|
|
1018
|
+
const includeWorkflow = includes?.workflow ?? true;
|
|
1019
|
+
const includeBatchCounts = includes?.batchCounts ?? false;
|
|
1020
|
+
const accountsWithOptionalFields = await Promise.all(
|
|
991
1021
|
accounts.map(async (a) => {
|
|
992
|
-
|
|
993
|
-
try {
|
|
994
|
-
const instance = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(a.id);
|
|
995
|
-
status = await instance.status();
|
|
996
|
-
} catch (_) {
|
|
997
|
-
status = null;
|
|
998
|
-
}
|
|
999
|
-
return {
|
|
1022
|
+
const result = {
|
|
1000
1023
|
...a,
|
|
1001
|
-
workflow:
|
|
1024
|
+
workflow: null,
|
|
1025
|
+
batches: null
|
|
1026
|
+
};
|
|
1027
|
+
if (includeWorkflow) {
|
|
1028
|
+
let status;
|
|
1029
|
+
try {
|
|
1030
|
+
const instance = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(a.id);
|
|
1031
|
+
status = await instance.status();
|
|
1032
|
+
} catch (_) {
|
|
1033
|
+
status = null;
|
|
1034
|
+
}
|
|
1035
|
+
result.workflow = status ? {
|
|
1002
1036
|
instanceId: a.id,
|
|
1003
1037
|
details: status
|
|
1004
|
-
} : null
|
|
1005
|
-
}
|
|
1038
|
+
} : null;
|
|
1039
|
+
}
|
|
1040
|
+
if (includeBatchCounts) {
|
|
1041
|
+
const batchCounts = await getAccountBatchCountsQuery(this.db, {
|
|
1042
|
+
accountId: a.id
|
|
1043
|
+
});
|
|
1044
|
+
result.batches = batchCounts;
|
|
1045
|
+
}
|
|
1046
|
+
return result;
|
|
1006
1047
|
})
|
|
1007
1048
|
);
|
|
1008
1049
|
return {
|
|
1009
|
-
accounts:
|
|
1050
|
+
accounts: accountsWithOptionalFields,
|
|
1010
1051
|
totalCount: accounts.length
|
|
1011
1052
|
};
|
|
1012
1053
|
}
|
package/dist/export/worker.d.cts
CHANGED
|
@@ -2394,14 +2394,29 @@ declare const updateAccountInputSchema: z.ZodObject<{
|
|
|
2394
2394
|
type UpdateAccountInput = z.infer<typeof updateAccountInputSchema>;
|
|
2395
2395
|
type UpdateAccountOutput = AccountSelectType;
|
|
2396
2396
|
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
}
|
|
2397
|
+
declare const getBankAccountsInputSchema: z.ZodObject<{
|
|
2398
|
+
includes: z.ZodOptional<z.ZodObject<{
|
|
2399
|
+
workflow: z.ZodOptional<z.ZodBoolean>;
|
|
2400
|
+
batchCounts: z.ZodOptional<z.ZodBoolean>;
|
|
2401
|
+
}, z.core.$strip>>;
|
|
2402
|
+
}, z.core.$strip>;
|
|
2403
|
+
type GetBankAccountsInput = z.infer<typeof getBankAccountsInputSchema>;
|
|
2404
|
+
type WorkflowInfo = {
|
|
2405
|
+
instanceId: string;
|
|
2406
|
+
details: WorkflowInstanceStatus;
|
|
2407
|
+
} | null;
|
|
2408
|
+
type BatchCounts = {
|
|
2409
|
+
totalCount: number;
|
|
2410
|
+
openCount: number;
|
|
2411
|
+
readyToSignCount: number;
|
|
2412
|
+
failedCount: number;
|
|
2413
|
+
} | null;
|
|
2414
|
+
type AccountWithOptionalFields = AccountSelectType & {
|
|
2415
|
+
workflow: WorkflowInfo;
|
|
2416
|
+
batches: BatchCounts;
|
|
2402
2417
|
};
|
|
2403
|
-
type
|
|
2404
|
-
accounts:
|
|
2418
|
+
type GetBankAccountsOutput = {
|
|
2419
|
+
accounts: AccountWithOptionalFields[];
|
|
2405
2420
|
totalCount: number;
|
|
2406
2421
|
};
|
|
2407
2422
|
|
|
@@ -2518,7 +2533,7 @@ declare class BankServiceBase extends BankServiceBase_base {
|
|
|
2518
2533
|
authorizeAccount(input: AuthorizeAccountInput): Promise<IRPCResponse<AuthorizeAccountOutput>>;
|
|
2519
2534
|
simulateDeposit(input: SimulateDepositInput): Promise<IRPCResponse<SimulateDepositOutput>>;
|
|
2520
2535
|
sendPayment(input: SendPaymentInput): Promise<IRPCResponse<SendPaymentOutput>>;
|
|
2521
|
-
getBankAccounts(): Promise<IRPCResponse<
|
|
2536
|
+
getBankAccounts(input: GetBankAccountsInput): Promise<IRPCResponse<GetBankAccountsOutput>>;
|
|
2522
2537
|
updateAccount(input: UpdateAccountInput): Promise<IRPCResponse<UpdateAccountOutput>>;
|
|
2523
2538
|
disconnectAccount(input: DisconnectAccountInput): Promise<IRPCResponse<DisconnectAccountOutput>>;
|
|
2524
2539
|
getBatches(input: GetBatchesInput): Promise<IRPCResponse<GetBatchesOutput>>;
|
package/dist/export/worker.d.mts
CHANGED
|
@@ -2394,14 +2394,29 @@ declare const updateAccountInputSchema: z.ZodObject<{
|
|
|
2394
2394
|
type UpdateAccountInput = z.infer<typeof updateAccountInputSchema>;
|
|
2395
2395
|
type UpdateAccountOutput = AccountSelectType;
|
|
2396
2396
|
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
}
|
|
2397
|
+
declare const getBankAccountsInputSchema: z.ZodObject<{
|
|
2398
|
+
includes: z.ZodOptional<z.ZodObject<{
|
|
2399
|
+
workflow: z.ZodOptional<z.ZodBoolean>;
|
|
2400
|
+
batchCounts: z.ZodOptional<z.ZodBoolean>;
|
|
2401
|
+
}, z.core.$strip>>;
|
|
2402
|
+
}, z.core.$strip>;
|
|
2403
|
+
type GetBankAccountsInput = z.infer<typeof getBankAccountsInputSchema>;
|
|
2404
|
+
type WorkflowInfo = {
|
|
2405
|
+
instanceId: string;
|
|
2406
|
+
details: WorkflowInstanceStatus;
|
|
2407
|
+
} | null;
|
|
2408
|
+
type BatchCounts = {
|
|
2409
|
+
totalCount: number;
|
|
2410
|
+
openCount: number;
|
|
2411
|
+
readyToSignCount: number;
|
|
2412
|
+
failedCount: number;
|
|
2413
|
+
} | null;
|
|
2414
|
+
type AccountWithOptionalFields = AccountSelectType & {
|
|
2415
|
+
workflow: WorkflowInfo;
|
|
2416
|
+
batches: BatchCounts;
|
|
2402
2417
|
};
|
|
2403
|
-
type
|
|
2404
|
-
accounts:
|
|
2418
|
+
type GetBankAccountsOutput = {
|
|
2419
|
+
accounts: AccountWithOptionalFields[];
|
|
2405
2420
|
totalCount: number;
|
|
2406
2421
|
};
|
|
2407
2422
|
|
|
@@ -2518,7 +2533,7 @@ declare class BankServiceBase extends BankServiceBase_base {
|
|
|
2518
2533
|
authorizeAccount(input: AuthorizeAccountInput): Promise<IRPCResponse<AuthorizeAccountOutput>>;
|
|
2519
2534
|
simulateDeposit(input: SimulateDepositInput): Promise<IRPCResponse<SimulateDepositOutput>>;
|
|
2520
2535
|
sendPayment(input: SendPaymentInput): Promise<IRPCResponse<SendPaymentOutput>>;
|
|
2521
|
-
getBankAccounts(): Promise<IRPCResponse<
|
|
2536
|
+
getBankAccounts(input: GetBankAccountsInput): Promise<IRPCResponse<GetBankAccountsOutput>>;
|
|
2522
2537
|
updateAccount(input: UpdateAccountInput): Promise<IRPCResponse<UpdateAccountOutput>>;
|
|
2523
2538
|
disconnectAccount(input: DisconnectAccountInput): Promise<IRPCResponse<DisconnectAccountOutput>>;
|
|
2524
2539
|
getBatches(input: GetBatchesInput): Promise<IRPCResponse<GetBatchesOutput>>;
|
package/dist/export/worker.d.ts
CHANGED
|
@@ -2394,14 +2394,29 @@ declare const updateAccountInputSchema: z.ZodObject<{
|
|
|
2394
2394
|
type UpdateAccountInput = z.infer<typeof updateAccountInputSchema>;
|
|
2395
2395
|
type UpdateAccountOutput = AccountSelectType;
|
|
2396
2396
|
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
}
|
|
2397
|
+
declare const getBankAccountsInputSchema: z.ZodObject<{
|
|
2398
|
+
includes: z.ZodOptional<z.ZodObject<{
|
|
2399
|
+
workflow: z.ZodOptional<z.ZodBoolean>;
|
|
2400
|
+
batchCounts: z.ZodOptional<z.ZodBoolean>;
|
|
2401
|
+
}, z.core.$strip>>;
|
|
2402
|
+
}, z.core.$strip>;
|
|
2403
|
+
type GetBankAccountsInput = z.infer<typeof getBankAccountsInputSchema>;
|
|
2404
|
+
type WorkflowInfo = {
|
|
2405
|
+
instanceId: string;
|
|
2406
|
+
details: WorkflowInstanceStatus;
|
|
2407
|
+
} | null;
|
|
2408
|
+
type BatchCounts = {
|
|
2409
|
+
totalCount: number;
|
|
2410
|
+
openCount: number;
|
|
2411
|
+
readyToSignCount: number;
|
|
2412
|
+
failedCount: number;
|
|
2413
|
+
} | null;
|
|
2414
|
+
type AccountWithOptionalFields = AccountSelectType & {
|
|
2415
|
+
workflow: WorkflowInfo;
|
|
2416
|
+
batches: BatchCounts;
|
|
2402
2417
|
};
|
|
2403
|
-
type
|
|
2404
|
-
accounts:
|
|
2418
|
+
type GetBankAccountsOutput = {
|
|
2419
|
+
accounts: AccountWithOptionalFields[];
|
|
2405
2420
|
totalCount: number;
|
|
2406
2421
|
};
|
|
2407
2422
|
|
|
@@ -2518,7 +2533,7 @@ declare class BankServiceBase extends BankServiceBase_base {
|
|
|
2518
2533
|
authorizeAccount(input: AuthorizeAccountInput): Promise<IRPCResponse<AuthorizeAccountOutput>>;
|
|
2519
2534
|
simulateDeposit(input: SimulateDepositInput): Promise<IRPCResponse<SimulateDepositOutput>>;
|
|
2520
2535
|
sendPayment(input: SendPaymentInput): Promise<IRPCResponse<SendPaymentOutput>>;
|
|
2521
|
-
getBankAccounts(): Promise<IRPCResponse<
|
|
2536
|
+
getBankAccounts(input: GetBankAccountsInput): Promise<IRPCResponse<GetBankAccountsOutput>>;
|
|
2522
2537
|
updateAccount(input: UpdateAccountInput): Promise<IRPCResponse<UpdateAccountOutput>>;
|
|
2523
2538
|
disconnectAccount(input: DisconnectAccountInput): Promise<IRPCResponse<DisconnectAccountOutput>>;
|
|
2524
2539
|
getBatches(input: GetBatchesInput): Promise<IRPCResponse<GetBatchesOutput>>;
|
package/dist/export/worker.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { uuidv4, bankAccountMetadataSchema, workflowInstanceStatusSchema, develitWorker, createInternalError,
|
|
1
|
+
import { uuidv4, first, bankAccountMetadataSchema, workflowInstanceStatusSchema, develitWorker, createInternalError, action, service } from '@develit-io/backend-sdk';
|
|
2
2
|
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
3
3
|
import { drizzle } from 'drizzle-orm/d1';
|
|
4
4
|
import { t as tables } from '../shared/bank.D7JSg_d9.mjs';
|
|
@@ -6,7 +6,7 @@ import { z } from 'zod';
|
|
|
6
6
|
import { I as INSTRUCTION_PRIORITIES, C as CHARGE_BEARERS, P as PAYMENT_TYPES, d as CONNECTOR_KEYS, B as BATCH_STATUSES, a as PAYMENT_STATUSES, b as PAYMENT_DIRECTIONS, f as accountInsertSchema } from '../shared/bank.m2X4FSvr.mjs';
|
|
7
7
|
import { CURRENCY_CODES } from '@develit-io/general-codes';
|
|
8
8
|
import 'date-fns';
|
|
9
|
-
import { eq, inArray, and,
|
|
9
|
+
import { eq, sql, inArray, and, asc, desc, gte, lte } from 'drizzle-orm';
|
|
10
10
|
import 'jose';
|
|
11
11
|
import 'node:crypto';
|
|
12
12
|
import { f as encrypt, i as importAesKey, a as getCredentialsByAccountId, b as initiateConnector, u as upsertBatchCommand, d as getBatchByIdQuery, c as createPaymentCommand, g as getAccountByIdQuery } from '../shared/bank.DYJuicD-.mjs';
|
|
@@ -91,6 +91,27 @@ const deletePaymentsByAccountCommand = (db, { accountId }) => {
|
|
|
91
91
|
};
|
|
92
92
|
};
|
|
93
93
|
|
|
94
|
+
const getAccountBatchCountsQuery = async (db, { accountId }) => {
|
|
95
|
+
const result = await db.select({
|
|
96
|
+
totalCount: sql`COUNT(*)`.as("totalCount"),
|
|
97
|
+
openCount: sql`SUM(CASE WHEN ${tables.batch.status} = 'OPEN' THEN 1 ELSE 0 END)`.as(
|
|
98
|
+
"openCount"
|
|
99
|
+
),
|
|
100
|
+
readyToSignCount: sql`SUM(CASE WHEN ${tables.batch.status} = 'READY_TO_SIGN' THEN 1 ELSE 0 END)`.as(
|
|
101
|
+
"readyToSignCount"
|
|
102
|
+
),
|
|
103
|
+
failedCount: sql`SUM(CASE WHEN ${tables.batch.status} = 'FAILED' THEN 1 ELSE 0 END)`.as(
|
|
104
|
+
"failedCount"
|
|
105
|
+
)
|
|
106
|
+
}).from(tables.batch).where(eq(tables.batch.accountId, accountId)).then(first);
|
|
107
|
+
return result || {
|
|
108
|
+
totalCount: 0,
|
|
109
|
+
openCount: 0,
|
|
110
|
+
readyToSignCount: 0,
|
|
111
|
+
failedCount: 0
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
|
|
94
115
|
const getAccountByIbanQuery = async (db, { iban }) => {
|
|
95
116
|
return await db.select().from(tables.account).where(eq(tables.account.iban, iban)).get();
|
|
96
117
|
};
|
|
@@ -383,6 +404,13 @@ const updateAccountInputSchema = z.object({
|
|
|
383
404
|
account: accountInsertSchema
|
|
384
405
|
});
|
|
385
406
|
|
|
407
|
+
const getBankAccountsInputSchema = z.object({
|
|
408
|
+
includes: z.object({
|
|
409
|
+
workflow: z.boolean().optional(),
|
|
410
|
+
batchCounts: z.boolean().optional()
|
|
411
|
+
}).optional()
|
|
412
|
+
});
|
|
413
|
+
|
|
386
414
|
const disconnectAccountInputSchema = z.object({
|
|
387
415
|
accountId: z.uuid()
|
|
388
416
|
});
|
|
@@ -979,32 +1007,45 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
|
|
|
979
1007
|
}
|
|
980
1008
|
);
|
|
981
1009
|
}
|
|
982
|
-
async getBankAccounts() {
|
|
1010
|
+
async getBankAccounts(input) {
|
|
983
1011
|
return this.handleAction(
|
|
984
|
-
|
|
1012
|
+
{ data: input, schema: getBankAccountsInputSchema },
|
|
985
1013
|
{ successMessage: "Bank accounts retrieved successfully" },
|
|
986
|
-
async () => {
|
|
1014
|
+
async ({ includes }) => {
|
|
987
1015
|
const accounts = await this._getAccounts();
|
|
988
|
-
const
|
|
1016
|
+
const includeWorkflow = includes?.workflow ?? true;
|
|
1017
|
+
const includeBatchCounts = includes?.batchCounts ?? false;
|
|
1018
|
+
const accountsWithOptionalFields = await Promise.all(
|
|
989
1019
|
accounts.map(async (a) => {
|
|
990
|
-
|
|
991
|
-
try {
|
|
992
|
-
const instance = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(a.id);
|
|
993
|
-
status = await instance.status();
|
|
994
|
-
} catch (_) {
|
|
995
|
-
status = null;
|
|
996
|
-
}
|
|
997
|
-
return {
|
|
1020
|
+
const result = {
|
|
998
1021
|
...a,
|
|
999
|
-
workflow:
|
|
1022
|
+
workflow: null,
|
|
1023
|
+
batches: null
|
|
1024
|
+
};
|
|
1025
|
+
if (includeWorkflow) {
|
|
1026
|
+
let status;
|
|
1027
|
+
try {
|
|
1028
|
+
const instance = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(a.id);
|
|
1029
|
+
status = await instance.status();
|
|
1030
|
+
} catch (_) {
|
|
1031
|
+
status = null;
|
|
1032
|
+
}
|
|
1033
|
+
result.workflow = status ? {
|
|
1000
1034
|
instanceId: a.id,
|
|
1001
1035
|
details: status
|
|
1002
|
-
} : null
|
|
1003
|
-
}
|
|
1036
|
+
} : null;
|
|
1037
|
+
}
|
|
1038
|
+
if (includeBatchCounts) {
|
|
1039
|
+
const batchCounts = await getAccountBatchCountsQuery(this.db, {
|
|
1040
|
+
accountId: a.id
|
|
1041
|
+
});
|
|
1042
|
+
result.batches = batchCounts;
|
|
1043
|
+
}
|
|
1044
|
+
return result;
|
|
1004
1045
|
})
|
|
1005
1046
|
);
|
|
1006
1047
|
return {
|
|
1007
|
-
accounts:
|
|
1048
|
+
accounts: accountsWithOptionalFields,
|
|
1008
1049
|
totalCount: accounts.length
|
|
1009
1050
|
};
|
|
1010
1051
|
}
|