@develit-io/backend-sdk 11.0.5 → 11.2.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/index.d.mts +25 -3
- package/dist/index.d.ts +25 -3
- package/dist/index.mjs +44 -16
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -13,9 +13,9 @@ export { createSelectSchema } from 'drizzle-orm/zod';
|
|
|
13
13
|
|
|
14
14
|
declare const ENVIRONMENT: string[];
|
|
15
15
|
|
|
16
|
-
type Environment = string | 'localhost' | 'dev' | '
|
|
16
|
+
type Environment = string | 'localhost' | 'dev' | 'staging' | 'production';
|
|
17
17
|
|
|
18
|
-
type Project = 'creditio' | 'cryptobyte-website' | 'dbu-payments-api' | 'dbu-mdm' | 'dbu-txs' | 'develit-sdk' | 'lrf-website' | 'moneio' | 'stable-labs-emi-processor';
|
|
18
|
+
type Project = 'creditio' | 'cryptobyte-website' | 'dbu-payments-api' | 'dbu-mdm' | 'dbu-txs' | 'develit-sdk' | 'kachlikarna-pridavac' | 'lrf-website' | 'moneio' | 'stable-labs-emi-processor';
|
|
19
19
|
|
|
20
20
|
declare const uuidv4: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
21
21
|
declare const uuidv5: (name: string, namespace: string) => Promise<string>;
|
|
@@ -1223,6 +1223,28 @@ type OptionalToNull<T> = {
|
|
|
1223
1223
|
declare function optionalToNull<T extends object>(obj: T): OptionalToNull<T>;
|
|
1224
1224
|
|
|
1225
1225
|
declare const calculateExponentialBackoff: (attempts: number, baseDelaySeconds: number) => number;
|
|
1226
|
+
/**
|
|
1227
|
+
* Splits messages into chunks that fit Cloudflare Queue sendBatch limits
|
|
1228
|
+
* (100 messages OR 256 KB total per batch). Oversized single messages are
|
|
1229
|
+
* emitted alone — Cloudflare will reject them, but the helper does not loop.
|
|
1230
|
+
*/
|
|
1231
|
+
declare function chunkQueueMessages<T>(messages: T[]): Generator<T[]>;
|
|
1232
|
+
/**
|
|
1233
|
+
* Sends a single message via `queue.send()` or a batch via `queue.sendBatch()`.
|
|
1234
|
+
* Batches are automatically chunked to respect Cloudflare Queue limits.
|
|
1235
|
+
*/
|
|
1236
|
+
declare function pushToQueue<T>(queue: Queue, message: T | T[]): Promise<void>;
|
|
1237
|
+
|
|
1238
|
+
/**
|
|
1239
|
+
* Deep-clones an object and replaces values of sensitive keys with '[REDACTED]'.
|
|
1240
|
+
* Key matching is case-insensitive and ignores underscores/hyphens,
|
|
1241
|
+
* so `password`, `Password`, `access_token`, `accessToken`, `ACCESS_TOKEN` are all matched.
|
|
1242
|
+
*
|
|
1243
|
+
* @param value - The value to redact
|
|
1244
|
+
* @param sensitiveKeys - Additional keys to redact (merged with defaults)
|
|
1245
|
+
* @returns A deep copy with sensitive values replaced
|
|
1246
|
+
*/
|
|
1247
|
+
declare function redact<T>(value: T, sensitiveKeys?: string[]): T;
|
|
1226
1248
|
|
|
1227
1249
|
declare const RPCResponse: {
|
|
1228
1250
|
/**
|
|
@@ -1311,5 +1333,5 @@ interface WithRetryCounterOptions {
|
|
|
1311
1333
|
type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
|
|
1312
1334
|
declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
|
|
1313
1335
|
|
|
1314
|
-
export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInsertSchema, createInternalError, createPatchSchema, createUpdateSchema, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getDrizzleD1Config, getLocalD1DatabaseIdFromWrangler, getSecret, handleAction, ibanSchema, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, resolveColumn, service, structuredAddressSchema, useFetch, useResult, useResultSync, uuidv4, uuidv5, workflowInstanceStatusSchema };
|
|
1336
|
+
export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, chunkQueueMessages, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInsertSchema, createInternalError, createPatchSchema, createUpdateSchema, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getDrizzleD1Config, getLocalD1DatabaseIdFromWrangler, getSecret, handleAction, ibanSchema, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, pushToQueue, redact, resolveColumn, service, structuredAddressSchema, useFetch, useResult, useResultSync, uuidv4, uuidv5, workflowInstanceStatusSchema };
|
|
1315
1337
|
export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, BankAccountMetadata, BaseEvent, BuildSearchOptions, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IdempotencyContextVariables, IdentityContextVariables, InternalError, InternalErrorResponseStatus, Project, RequestLog, ResponseLog, StructuredAddress, UserRole, ValidatedInput, WorkflowInstanceStatus };
|
package/dist/index.d.ts
CHANGED
|
@@ -13,9 +13,9 @@ export { createSelectSchema } from 'drizzle-orm/zod';
|
|
|
13
13
|
|
|
14
14
|
declare const ENVIRONMENT: string[];
|
|
15
15
|
|
|
16
|
-
type Environment = string | 'localhost' | 'dev' | '
|
|
16
|
+
type Environment = string | 'localhost' | 'dev' | 'staging' | 'production';
|
|
17
17
|
|
|
18
|
-
type Project = 'creditio' | 'cryptobyte-website' | 'dbu-payments-api' | 'dbu-mdm' | 'dbu-txs' | 'develit-sdk' | 'lrf-website' | 'moneio' | 'stable-labs-emi-processor';
|
|
18
|
+
type Project = 'creditio' | 'cryptobyte-website' | 'dbu-payments-api' | 'dbu-mdm' | 'dbu-txs' | 'develit-sdk' | 'kachlikarna-pridavac' | 'lrf-website' | 'moneio' | 'stable-labs-emi-processor';
|
|
19
19
|
|
|
20
20
|
declare const uuidv4: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
21
21
|
declare const uuidv5: (name: string, namespace: string) => Promise<string>;
|
|
@@ -1223,6 +1223,28 @@ type OptionalToNull<T> = {
|
|
|
1223
1223
|
declare function optionalToNull<T extends object>(obj: T): OptionalToNull<T>;
|
|
1224
1224
|
|
|
1225
1225
|
declare const calculateExponentialBackoff: (attempts: number, baseDelaySeconds: number) => number;
|
|
1226
|
+
/**
|
|
1227
|
+
* Splits messages into chunks that fit Cloudflare Queue sendBatch limits
|
|
1228
|
+
* (100 messages OR 256 KB total per batch). Oversized single messages are
|
|
1229
|
+
* emitted alone — Cloudflare will reject them, but the helper does not loop.
|
|
1230
|
+
*/
|
|
1231
|
+
declare function chunkQueueMessages<T>(messages: T[]): Generator<T[]>;
|
|
1232
|
+
/**
|
|
1233
|
+
* Sends a single message via `queue.send()` or a batch via `queue.sendBatch()`.
|
|
1234
|
+
* Batches are automatically chunked to respect Cloudflare Queue limits.
|
|
1235
|
+
*/
|
|
1236
|
+
declare function pushToQueue<T>(queue: Queue, message: T | T[]): Promise<void>;
|
|
1237
|
+
|
|
1238
|
+
/**
|
|
1239
|
+
* Deep-clones an object and replaces values of sensitive keys with '[REDACTED]'.
|
|
1240
|
+
* Key matching is case-insensitive and ignores underscores/hyphens,
|
|
1241
|
+
* so `password`, `Password`, `access_token`, `accessToken`, `ACCESS_TOKEN` are all matched.
|
|
1242
|
+
*
|
|
1243
|
+
* @param value - The value to redact
|
|
1244
|
+
* @param sensitiveKeys - Additional keys to redact (merged with defaults)
|
|
1245
|
+
* @returns A deep copy with sensitive values replaced
|
|
1246
|
+
*/
|
|
1247
|
+
declare function redact<T>(value: T, sensitiveKeys?: string[]): T;
|
|
1226
1248
|
|
|
1227
1249
|
declare const RPCResponse: {
|
|
1228
1250
|
/**
|
|
@@ -1311,5 +1333,5 @@ interface WithRetryCounterOptions {
|
|
|
1311
1333
|
type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
|
|
1312
1334
|
declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
|
|
1313
1335
|
|
|
1314
|
-
export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInsertSchema, createInternalError, createPatchSchema, createUpdateSchema, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getDrizzleD1Config, getLocalD1DatabaseIdFromWrangler, getSecret, handleAction, ibanSchema, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, resolveColumn, service, structuredAddressSchema, useFetch, useResult, useResultSync, uuidv4, uuidv5, workflowInstanceStatusSchema };
|
|
1336
|
+
export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, chunkQueueMessages, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInsertSchema, createInternalError, createPatchSchema, createUpdateSchema, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getDrizzleD1Config, getLocalD1DatabaseIdFromWrangler, getSecret, handleAction, ibanSchema, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, pushToQueue, redact, resolveColumn, service, structuredAddressSchema, useFetch, useResult, useResultSync, uuidv4, uuidv5, workflowInstanceStatusSchema };
|
|
1315
1337
|
export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, BankAccountMetadata, BaseEvent, BuildSearchOptions, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IdempotencyContextVariables, IdentityContextVariables, InternalError, InternalErrorResponseStatus, Project, RequestLog, ResponseLog, StructuredAddress, UserRole, ValidatedInput, WorkflowInstanceStatus };
|
package/dist/index.mjs
CHANGED
|
@@ -729,6 +729,48 @@ function optionalToNull(obj) {
|
|
|
729
729
|
const calculateExponentialBackoff = (attempts, baseDelaySeconds) => {
|
|
730
730
|
return baseDelaySeconds ** attempts;
|
|
731
731
|
};
|
|
732
|
+
const MAX_BATCH_MESSAGES = 100;
|
|
733
|
+
const MAX_BATCH_BYTES = 24e4;
|
|
734
|
+
const PER_MESSAGE_OVERHEAD_BYTES = 100;
|
|
735
|
+
function approxMessageSize(message) {
|
|
736
|
+
try {
|
|
737
|
+
return new TextEncoder().encode(JSON.stringify(message)).length + PER_MESSAGE_OVERHEAD_BYTES;
|
|
738
|
+
} catch {
|
|
739
|
+
return 1024;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
function* chunkQueueMessages(messages) {
|
|
743
|
+
let chunk = [];
|
|
744
|
+
let chunkBytes = 0;
|
|
745
|
+
for (const message of messages) {
|
|
746
|
+
const size = approxMessageSize(message);
|
|
747
|
+
const wouldOverflow = chunk.length >= MAX_BATCH_MESSAGES || chunk.length > 0 && chunkBytes + size > MAX_BATCH_BYTES;
|
|
748
|
+
if (wouldOverflow) {
|
|
749
|
+
yield chunk;
|
|
750
|
+
chunk = [];
|
|
751
|
+
chunkBytes = 0;
|
|
752
|
+
}
|
|
753
|
+
chunk.push(message);
|
|
754
|
+
chunkBytes += size;
|
|
755
|
+
}
|
|
756
|
+
if (chunk.length) yield chunk;
|
|
757
|
+
}
|
|
758
|
+
async function pushToQueue(queue, message) {
|
|
759
|
+
if (!queue) {
|
|
760
|
+
throw new Error(
|
|
761
|
+
"[pushToQueue] Queue binding is undefined \u2014 check your wrangler config"
|
|
762
|
+
);
|
|
763
|
+
}
|
|
764
|
+
if (!Array.isArray(message)) {
|
|
765
|
+
await queue.send(message, { contentType: "v8" });
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
for (const chunk of chunkQueueMessages(message)) {
|
|
769
|
+
await queue.sendBatch(
|
|
770
|
+
chunk.map((body) => ({ body, contentType: "v8" }))
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
732
774
|
|
|
733
775
|
const getSecret = async (secretName, env) => {
|
|
734
776
|
const environment = env;
|
|
@@ -864,21 +906,7 @@ function develitWorker(Worker) {
|
|
|
864
906
|
);
|
|
865
907
|
}
|
|
866
908
|
async pushToQueue(queue, message) {
|
|
867
|
-
|
|
868
|
-
throw new Error(
|
|
869
|
-
"[pushToQueue] Queue binding is undefined \u2014 check your wrangler config"
|
|
870
|
-
);
|
|
871
|
-
}
|
|
872
|
-
if (!Array.isArray(message)) {
|
|
873
|
-
await queue.send(message, { contentType: "v8" });
|
|
874
|
-
return;
|
|
875
|
-
}
|
|
876
|
-
await queue.sendBatch(
|
|
877
|
-
message.map((m) => ({
|
|
878
|
-
body: m,
|
|
879
|
-
contentType: "v8"
|
|
880
|
-
}))
|
|
881
|
-
);
|
|
909
|
+
return pushToQueue(queue, message);
|
|
882
910
|
}
|
|
883
911
|
recordAuditLogMessage(queue, message) {
|
|
884
912
|
const msg = { service: this.name, ...message, createdAt: /* @__PURE__ */ new Date() };
|
|
@@ -891,4 +919,4 @@ function develitWorker(Worker) {
|
|
|
891
919
|
return DevelitWorker;
|
|
892
920
|
}
|
|
893
921
|
|
|
894
|
-
export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInsertSchema, createInternalError, createPatchSchema, createUpdateSchema, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getDrizzleD1Config, getLocalD1DatabaseIdFromWrangler, getSecret, handleAction, ibanSchema, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, resolveColumn, service, structuredAddressSchema, useFetch, useResult, useResultSync, workflowInstanceStatusSchema };
|
|
922
|
+
export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, chunkQueueMessages, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInsertSchema, createInternalError, createPatchSchema, createUpdateSchema, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getDrizzleD1Config, getLocalD1DatabaseIdFromWrangler, getSecret, handleAction, ibanSchema, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, pushToQueue, redact, resolveColumn, service, structuredAddressSchema, useFetch, useResult, useResultSync, workflowInstanceStatusSchema };
|