@develit-io/backend-sdk 8.6.3 → 9.0.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.
package/dist/index.d.mts CHANGED
@@ -74,13 +74,6 @@ interface AuditLogPayload<T> {
74
74
  entityId?: string;
75
75
  }
76
76
 
77
- interface AuthUser {
78
- id: string;
79
- organizationId: string;
80
- email: string;
81
- role: UserRole;
82
- }
83
-
84
77
  declare const ibanSchema: z$1.ZodString;
85
78
  declare const bicSchema: z$1.ZodString;
86
79
  declare const bankAccountMetadataSchema: z$1.ZodObject<{
@@ -415,6 +408,26 @@ declare const bankAccountMetadataSchema: z$1.ZodObject<{
415
408
  interface BankAccountMetadata extends z$1.infer<typeof bankAccountMetadataSchema> {
416
409
  }
417
410
 
411
+ declare const workflowInstanceStatusSchema: z$1.ZodObject<{
412
+ status: z$1.ZodEnum<{
413
+ unknown: "unknown";
414
+ queued: "queued";
415
+ running: "running";
416
+ paused: "paused";
417
+ errored: "errored";
418
+ terminated: "terminated";
419
+ complete: "complete";
420
+ waiting: "waiting";
421
+ waitingForPause: "waitingForPause";
422
+ }>;
423
+ error: z$1.ZodOptional<z$1.ZodObject<{
424
+ message: z$1.ZodString;
425
+ name: z$1.ZodOptional<z$1.ZodString>;
426
+ }, z$1.core.$strip>>;
427
+ output: z$1.ZodOptional<z$1.ZodUnknown>;
428
+ }, z$1.core.$strip>;
429
+ type WorkflowInstanceStatus = z$1.infer<typeof workflowInstanceStatusSchema>;
430
+
418
431
  interface CommandLogPayload<T = string> {
419
432
  action: T;
420
433
  actorId: string;
@@ -448,16 +461,6 @@ type InferResultType<Tables extends Record<string, unknown>, TableName extends k
448
461
  with: With;
449
462
  }>;
450
463
 
451
- interface IdempotencyVariables {
452
- idempotency: {
453
- key: string;
454
- };
455
- }
456
- interface UserVariables {
457
- user: AuthUser;
458
- jwt: unknown;
459
- }
460
-
461
464
  declare const paginationQuerySchema: z.$ZodObject<Readonly<Readonly<{
462
465
  [k: string]: z.$ZodType<unknown, unknown, z.$ZodTypeInternals<unknown, unknown>>;
463
466
  }>>, z.$ZodObjectConfig>;
@@ -465,6 +468,19 @@ declare const paginationSchema: z.$ZodObject<Readonly<Readonly<{
465
468
  [k: string]: z.$ZodType<unknown, unknown, z.$ZodTypeInternals<unknown, unknown>>;
466
469
  }>>, z.$ZodObjectConfig>;
467
470
 
471
+ interface BaseEvent {
472
+ metadata: {
473
+ timestamp: string;
474
+ correlationId: string;
475
+ entityId: string;
476
+ /**
477
+ * Idempotency key is built as
478
+ * `${entityId}-${eventSignal}-${idempotencySuffix}`
479
+ */
480
+ idempotencySuffix?: string;
481
+ };
482
+ }
483
+
468
484
  type InternalErrorResponseStatus = Exclude<ContentfulStatusCode, SuccessStatusCode>;
469
485
  interface InternalError {
470
486
  status: InternalErrorResponseStatus;
@@ -474,6 +490,7 @@ interface InternalError {
474
490
  interface IRPCResponse<T> {
475
491
  status: ContentfulStatusCode;
476
492
  message: string;
493
+ code: string;
477
494
  data: T | null | undefined;
478
495
  error: boolean;
479
496
  }
@@ -496,46 +513,6 @@ interface GatewayResponse<T> {
496
513
  */
497
514
  type Result<T> = [data: T | null, error: InternalError | null];
498
515
 
499
- interface BaseEvent {
500
- metadata: {
501
- timestamp: string;
502
- correlationId: string;
503
- entityId: string;
504
- /**
505
- * Idempotency key is built as
506
- * `${entityId}-${eventSignal}-${idempotencySuffix}`
507
- */
508
- idempotencySuffix?: string;
509
- };
510
- }
511
-
512
- declare const workflowInstanceStatusSchema: z$1.ZodObject<{
513
- status: z$1.ZodEnum<{
514
- unknown: "unknown";
515
- queued: "queued";
516
- running: "running";
517
- paused: "paused";
518
- errored: "errored";
519
- terminated: "terminated";
520
- complete: "complete";
521
- waiting: "waiting";
522
- waitingForPause: "waitingForPause";
523
- }>;
524
- error: z$1.ZodOptional<z$1.ZodObject<{
525
- message: z$1.ZodString;
526
- name: z$1.ZodOptional<z$1.ZodString>;
527
- }, z$1.core.$strip>>;
528
- output: z$1.ZodOptional<z$1.ZodUnknown>;
529
- }, z$1.core.$strip>;
530
- type WorkflowInstanceStatus = z$1.infer<typeof workflowInstanceStatusSchema>;
531
-
532
- declare const handleActionResponse: <T>({ error, status, message, data, }: {
533
- error: boolean;
534
- status: number;
535
- message: string;
536
- data: T;
537
- }) => T & {};
538
-
539
516
  type Constructor<T = {}> = abstract new (...args: any[]) => T;
540
517
  interface DevelitWorkerMethods {
541
518
  name: string;
@@ -740,20 +717,14 @@ interface UseFetchOptions extends RequestInit {
740
717
  }
741
718
  declare function useFetch<T = unknown>(url: string, { parseAs, ...options }?: UseFetchOptions): Promise<Result<T>>;
742
719
 
743
- declare const createSignatureKeyPair: () => Promise<{
744
- publicKey: string;
745
- privateKey: string;
746
- }>;
747
- declare const signPayload: ({ payload, privateKey, }: {
748
- payload: string;
749
- privateKey: string;
750
- }) => Promise<string>;
751
- declare const verifyPayloadSignature: ({ signature, data, publicKey, algorithm, }: {
752
- signature: string;
753
- data: string;
754
- publicKey: string;
755
- algorithm?: "RSA" | "EC" | "HMAC";
756
- }) => Promise<boolean>;
720
+ type NullToOptional<T> = {
721
+ [K in keyof T]: null extends T[K] ? Exclude<T[K], null> | undefined : T[K];
722
+ };
723
+ declare function nullToOptional<T extends object>(obj: T): NullToOptional<T>;
724
+ type OptionalToNull<T> = {
725
+ [K in keyof T]: undefined extends T[K] ? Exclude<T[K], undefined> | null : T[K];
726
+ };
727
+ declare function optionalToNull<T extends object>(obj: T): OptionalToNull<T>;
757
728
 
758
729
  declare const calculateExponentialBackoff: (attempts: number, baseDelaySeconds: number) => number;
759
730
 
@@ -825,14 +796,20 @@ declare const useResultSync: <T>(fn: () => T) => Result<T>;
825
796
 
826
797
  declare const getSecret: (secretName: string, env: unknown) => Promise<string>;
827
798
 
828
- type NullToOptional<T> = {
829
- [K in keyof T]: null extends T[K] ? Exclude<T[K], null> | undefined : T[K];
830
- };
831
- declare function nullToOptional<T extends object>(obj: T): NullToOptional<T>;
832
- type OptionalToNull<T> = {
833
- [K in keyof T]: undefined extends T[K] ? Exclude<T[K], undefined> | null : T[K];
834
- };
835
- declare function optionalToNull<T extends object>(obj: T): OptionalToNull<T>;
799
+ declare const createSignatureKeyPair: () => Promise<{
800
+ publicKey: string;
801
+ privateKey: string;
802
+ }>;
803
+ declare const signPayload: ({ payload, privateKey, }: {
804
+ payload: string;
805
+ privateKey: string;
806
+ }) => Promise<string>;
807
+ declare const verifyPayloadSignature: ({ signature, data, publicKey, algorithm, }: {
808
+ signature: string;
809
+ data: string;
810
+ publicKey: string;
811
+ algorithm?: "RSA" | "EC" | "HMAC";
812
+ }) => Promise<boolean>;
836
813
 
837
814
  declare const service: (serviceName: string) => <T extends new (...args: any[]) => object>(constructor: T) => {
838
815
  new (...args: any[]): {
@@ -853,5 +830,5 @@ interface WithRetryCounterOptions {
853
830
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
854
831
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
855
832
 
856
- export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInternalError, createSignatureKeyPair, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getSecret, handleAction, handleActionResponse, ibanSchema, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, resolveColumn, service, signPayload, useFetch, useResult, useResultSync, uuidv4, verifyPayloadSignature, workflowInstanceStatusSchema };
857
- export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, AuthUser, BankAccountMetadata, BaseEvent, BuildSearchOptions, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IdempotencyVariables, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, UserRole, UserVariables, ValidatedInput, WorkflowInstanceStatus };
833
+ export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInternalError, createSignatureKeyPair, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getSecret, handleAction, ibanSchema, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, resolveColumn, service, signPayload, useFetch, useResult, useResultSync, uuidv4, verifyPayloadSignature, workflowInstanceStatusSchema };
834
+ export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, BankAccountMetadata, BaseEvent, BuildSearchOptions, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, UserRole, ValidatedInput, WorkflowInstanceStatus };
package/dist/index.d.ts CHANGED
@@ -74,13 +74,6 @@ interface AuditLogPayload<T> {
74
74
  entityId?: string;
75
75
  }
76
76
 
77
- interface AuthUser {
78
- id: string;
79
- organizationId: string;
80
- email: string;
81
- role: UserRole;
82
- }
83
-
84
77
  declare const ibanSchema: z$1.ZodString;
85
78
  declare const bicSchema: z$1.ZodString;
86
79
  declare const bankAccountMetadataSchema: z$1.ZodObject<{
@@ -415,6 +408,26 @@ declare const bankAccountMetadataSchema: z$1.ZodObject<{
415
408
  interface BankAccountMetadata extends z$1.infer<typeof bankAccountMetadataSchema> {
416
409
  }
417
410
 
411
+ declare const workflowInstanceStatusSchema: z$1.ZodObject<{
412
+ status: z$1.ZodEnum<{
413
+ unknown: "unknown";
414
+ queued: "queued";
415
+ running: "running";
416
+ paused: "paused";
417
+ errored: "errored";
418
+ terminated: "terminated";
419
+ complete: "complete";
420
+ waiting: "waiting";
421
+ waitingForPause: "waitingForPause";
422
+ }>;
423
+ error: z$1.ZodOptional<z$1.ZodObject<{
424
+ message: z$1.ZodString;
425
+ name: z$1.ZodOptional<z$1.ZodString>;
426
+ }, z$1.core.$strip>>;
427
+ output: z$1.ZodOptional<z$1.ZodUnknown>;
428
+ }, z$1.core.$strip>;
429
+ type WorkflowInstanceStatus = z$1.infer<typeof workflowInstanceStatusSchema>;
430
+
418
431
  interface CommandLogPayload<T = string> {
419
432
  action: T;
420
433
  actorId: string;
@@ -448,16 +461,6 @@ type InferResultType<Tables extends Record<string, unknown>, TableName extends k
448
461
  with: With;
449
462
  }>;
450
463
 
451
- interface IdempotencyVariables {
452
- idempotency: {
453
- key: string;
454
- };
455
- }
456
- interface UserVariables {
457
- user: AuthUser;
458
- jwt: unknown;
459
- }
460
-
461
464
  declare const paginationQuerySchema: z.$ZodObject<Readonly<Readonly<{
462
465
  [k: string]: z.$ZodType<unknown, unknown, z.$ZodTypeInternals<unknown, unknown>>;
463
466
  }>>, z.$ZodObjectConfig>;
@@ -465,6 +468,19 @@ declare const paginationSchema: z.$ZodObject<Readonly<Readonly<{
465
468
  [k: string]: z.$ZodType<unknown, unknown, z.$ZodTypeInternals<unknown, unknown>>;
466
469
  }>>, z.$ZodObjectConfig>;
467
470
 
471
+ interface BaseEvent {
472
+ metadata: {
473
+ timestamp: string;
474
+ correlationId: string;
475
+ entityId: string;
476
+ /**
477
+ * Idempotency key is built as
478
+ * `${entityId}-${eventSignal}-${idempotencySuffix}`
479
+ */
480
+ idempotencySuffix?: string;
481
+ };
482
+ }
483
+
468
484
  type InternalErrorResponseStatus = Exclude<ContentfulStatusCode, SuccessStatusCode>;
469
485
  interface InternalError {
470
486
  status: InternalErrorResponseStatus;
@@ -474,6 +490,7 @@ interface InternalError {
474
490
  interface IRPCResponse<T> {
475
491
  status: ContentfulStatusCode;
476
492
  message: string;
493
+ code: string;
477
494
  data: T | null | undefined;
478
495
  error: boolean;
479
496
  }
@@ -496,46 +513,6 @@ interface GatewayResponse<T> {
496
513
  */
497
514
  type Result<T> = [data: T | null, error: InternalError | null];
498
515
 
499
- interface BaseEvent {
500
- metadata: {
501
- timestamp: string;
502
- correlationId: string;
503
- entityId: string;
504
- /**
505
- * Idempotency key is built as
506
- * `${entityId}-${eventSignal}-${idempotencySuffix}`
507
- */
508
- idempotencySuffix?: string;
509
- };
510
- }
511
-
512
- declare const workflowInstanceStatusSchema: z$1.ZodObject<{
513
- status: z$1.ZodEnum<{
514
- unknown: "unknown";
515
- queued: "queued";
516
- running: "running";
517
- paused: "paused";
518
- errored: "errored";
519
- terminated: "terminated";
520
- complete: "complete";
521
- waiting: "waiting";
522
- waitingForPause: "waitingForPause";
523
- }>;
524
- error: z$1.ZodOptional<z$1.ZodObject<{
525
- message: z$1.ZodString;
526
- name: z$1.ZodOptional<z$1.ZodString>;
527
- }, z$1.core.$strip>>;
528
- output: z$1.ZodOptional<z$1.ZodUnknown>;
529
- }, z$1.core.$strip>;
530
- type WorkflowInstanceStatus = z$1.infer<typeof workflowInstanceStatusSchema>;
531
-
532
- declare const handleActionResponse: <T>({ error, status, message, data, }: {
533
- error: boolean;
534
- status: number;
535
- message: string;
536
- data: T;
537
- }) => T & {};
538
-
539
516
  type Constructor<T = {}> = abstract new (...args: any[]) => T;
540
517
  interface DevelitWorkerMethods {
541
518
  name: string;
@@ -740,20 +717,14 @@ interface UseFetchOptions extends RequestInit {
740
717
  }
741
718
  declare function useFetch<T = unknown>(url: string, { parseAs, ...options }?: UseFetchOptions): Promise<Result<T>>;
742
719
 
743
- declare const createSignatureKeyPair: () => Promise<{
744
- publicKey: string;
745
- privateKey: string;
746
- }>;
747
- declare const signPayload: ({ payload, privateKey, }: {
748
- payload: string;
749
- privateKey: string;
750
- }) => Promise<string>;
751
- declare const verifyPayloadSignature: ({ signature, data, publicKey, algorithm, }: {
752
- signature: string;
753
- data: string;
754
- publicKey: string;
755
- algorithm?: "RSA" | "EC" | "HMAC";
756
- }) => Promise<boolean>;
720
+ type NullToOptional<T> = {
721
+ [K in keyof T]: null extends T[K] ? Exclude<T[K], null> | undefined : T[K];
722
+ };
723
+ declare function nullToOptional<T extends object>(obj: T): NullToOptional<T>;
724
+ type OptionalToNull<T> = {
725
+ [K in keyof T]: undefined extends T[K] ? Exclude<T[K], undefined> | null : T[K];
726
+ };
727
+ declare function optionalToNull<T extends object>(obj: T): OptionalToNull<T>;
757
728
 
758
729
  declare const calculateExponentialBackoff: (attempts: number, baseDelaySeconds: number) => number;
759
730
 
@@ -825,14 +796,20 @@ declare const useResultSync: <T>(fn: () => T) => Result<T>;
825
796
 
826
797
  declare const getSecret: (secretName: string, env: unknown) => Promise<string>;
827
798
 
828
- type NullToOptional<T> = {
829
- [K in keyof T]: null extends T[K] ? Exclude<T[K], null> | undefined : T[K];
830
- };
831
- declare function nullToOptional<T extends object>(obj: T): NullToOptional<T>;
832
- type OptionalToNull<T> = {
833
- [K in keyof T]: undefined extends T[K] ? Exclude<T[K], undefined> | null : T[K];
834
- };
835
- declare function optionalToNull<T extends object>(obj: T): OptionalToNull<T>;
799
+ declare const createSignatureKeyPair: () => Promise<{
800
+ publicKey: string;
801
+ privateKey: string;
802
+ }>;
803
+ declare const signPayload: ({ payload, privateKey, }: {
804
+ payload: string;
805
+ privateKey: string;
806
+ }) => Promise<string>;
807
+ declare const verifyPayloadSignature: ({ signature, data, publicKey, algorithm, }: {
808
+ signature: string;
809
+ data: string;
810
+ publicKey: string;
811
+ algorithm?: "RSA" | "EC" | "HMAC";
812
+ }) => Promise<boolean>;
836
813
 
837
814
  declare const service: (serviceName: string) => <T extends new (...args: any[]) => object>(constructor: T) => {
838
815
  new (...args: any[]): {
@@ -853,5 +830,5 @@ interface WithRetryCounterOptions {
853
830
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
854
831
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
855
832
 
856
- export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInternalError, createSignatureKeyPair, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getSecret, handleAction, handleActionResponse, ibanSchema, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, resolveColumn, service, signPayload, useFetch, useResult, useResultSync, uuidv4, verifyPayloadSignature, workflowInstanceStatusSchema };
857
- export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, AuthUser, BankAccountMetadata, BaseEvent, BuildSearchOptions, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IdempotencyVariables, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, UserRole, UserVariables, ValidatedInput, WorkflowInstanceStatus };
833
+ export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInternalError, createSignatureKeyPair, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getSecret, handleAction, ibanSchema, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, resolveColumn, service, signPayload, useFetch, useResult, useResultSync, uuidv4, verifyPayloadSignature, workflowInstanceStatusSchema };
834
+ export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, BankAccountMetadata, BaseEvent, BuildSearchOptions, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, UserRole, ValidatedInput, WorkflowInstanceStatus };
package/dist/index.mjs CHANGED
@@ -1,9 +1,8 @@
1
- import { sql, or, inArray, eq, gte, lte, and } from 'drizzle-orm';
1
+ import { sql, inArray, eq, gte, lte, and, or } from 'drizzle-orm';
2
2
  import { integer, text } from 'drizzle-orm/sqlite-core';
3
3
  import { COUNTRY_CODES_2, CURRENCY_CODES, BANK_CODES } from '@develit-io/general-codes';
4
4
  import { z as z$1 } from 'zod';
5
5
  import * as z from 'zod/v4/core';
6
- import { createError } from 'h3';
7
6
  import 'cloudflare';
8
7
  import fs from 'node:fs';
9
8
  import crypto$1 from 'node:crypto';
@@ -104,6 +103,29 @@ const bankAccountMetadataSchema = z$1.object({
104
103
  // Brazil
105
104
  });
106
105
 
106
+ const workflowInstanceStatusSchema = z$1.object({
107
+ status: z$1.enum([
108
+ "queued",
109
+ // means that instance is waiting to be started (see concurrency limits)
110
+ "running",
111
+ "paused",
112
+ "errored",
113
+ "terminated",
114
+ // user terminated the instance while it was running
115
+ "complete",
116
+ "waiting",
117
+ // instance is hibernating and waiting for sleep or event to finish
118
+ "waitingForPause",
119
+ // instance is finishing the current work to pause
120
+ "unknown"
121
+ ]),
122
+ error: z$1.object({
123
+ message: z$1.string(),
124
+ name: z$1.string().optional()
125
+ }).optional(),
126
+ output: z$1.unknown().optional()
127
+ });
128
+
107
129
  const paginationQuerySchema = new z.$ZodObject({
108
130
  type: "object",
109
131
  shape: {
@@ -189,47 +211,6 @@ const paginationSchema = new z.$ZodObject({
189
211
  }
190
212
  });
191
213
 
192
- const workflowInstanceStatusSchema = z$1.object({
193
- status: z$1.enum([
194
- "queued",
195
- // means that instance is waiting to be started (see concurrency limits)
196
- "running",
197
- "paused",
198
- "errored",
199
- "terminated",
200
- // user terminated the instance while it was running
201
- "complete",
202
- "waiting",
203
- // instance is hibernating and waiting for sleep or event to finish
204
- "waitingForPause",
205
- // instance is finishing the current work to pause
206
- "unknown"
207
- ]),
208
- error: z$1.object({
209
- message: z$1.string(),
210
- name: z$1.string().optional()
211
- }).optional(),
212
- output: z$1.unknown().optional()
213
- });
214
-
215
- const handleActionResponse = ({
216
- error,
217
- status,
218
- message,
219
- data
220
- }) => {
221
- if (error) {
222
- throw createError({ status, message });
223
- }
224
- if (data === void 0 || data === null) {
225
- throw createError({
226
- statusCode: 500,
227
- message: "Could not process the request. (ACTION_RESPONSE_FAILED)"
228
- });
229
- }
230
- return data;
231
- };
232
-
233
214
  const createInternalError = (error, details) => {
234
215
  return {
235
216
  status: details?.status || 500,
@@ -263,6 +244,7 @@ const RPCResponse = {
263
244
  return {
264
245
  status: detail?.status || 200,
265
246
  data: detail?.data,
247
+ code: "OK",
266
248
  error: false,
267
249
  message
268
250
  };
@@ -280,7 +262,8 @@ const RPCResponse = {
280
262
  console.error(error.message);
281
263
  return {
282
264
  status: error.status,
283
- message: error.code,
265
+ message: error.message,
266
+ code: error.code,
284
267
  data: null,
285
268
  error: true
286
269
  };
@@ -610,6 +593,20 @@ async function useFetch(url, { parseAs = "json", ...options } = {}) {
610
593
  return [body, null];
611
594
  }
612
595
 
596
+ function nullToOptional(obj) {
597
+ return Object.fromEntries(
598
+ Object.entries(obj).map(([k, v]) => [k, v === null ? void 0 : v])
599
+ );
600
+ }
601
+ function optionalToNull(obj) {
602
+ const out = {};
603
+ for (const key of Object.keys(obj)) {
604
+ const value = obj[key];
605
+ out[key] = value === void 0 ? null : value;
606
+ }
607
+ return out;
608
+ }
609
+
613
610
  const calculateExponentialBackoff = (attempts, baseDelaySeconds) => {
614
611
  return baseDelaySeconds ** attempts;
615
612
  };
@@ -626,20 +623,6 @@ const getSecret = async (secretName, env) => {
626
623
  return await secret.get();
627
624
  };
628
625
 
629
- function nullToOptional(obj) {
630
- return Object.fromEntries(
631
- Object.entries(obj).map(([k, v]) => [k, v === null ? void 0 : v])
632
- );
633
- }
634
- function optionalToNull(obj) {
635
- const out = {};
636
- for (const key of Object.keys(obj)) {
637
- const value = obj[key];
638
- out[key] = value === void 0 ? null : value;
639
- }
640
- return out;
641
- }
642
-
643
626
  const service = (serviceName) => {
644
627
  return function(constructor) {
645
628
  return class extends constructor {
@@ -780,4 +763,4 @@ function develitWorker(Worker) {
780
763
  return DevelitWorker;
781
764
  }
782
765
 
783
- export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getSecret, handleAction, handleActionResponse, ibanSchema, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, resolveColumn, service, useFetch, useResult, useResultSync, uuidv4, workflowInstanceStatusSchema };
766
+ export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getSecret, handleAction, ibanSchema, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, resolveColumn, service, useFetch, useResult, useResultSync, uuidv4, workflowInstanceStatusSchema };
@@ -1,13 +1,99 @@
1
- import { MiddlewareHandler } from 'hono/types';
1
+ import * as hono_types from 'hono/types';
2
2
 
3
- declare const idempotency: () => MiddlewareHandler;
3
+ declare const idempotency: () => hono_types.MiddlewareHandler<{
4
+ Variables: {
5
+ idempotency: {
6
+ key: string;
7
+ };
8
+ };
9
+ Bindings: {
10
+ IDEMPOTENCY_KV: KVNamespace;
11
+ };
12
+ }, string, {}, Response>;
4
13
 
5
- declare const jwt: () => MiddlewareHandler;
14
+ type AuthService = {
15
+ verifyAccessToken: (params: {
16
+ accessToken: string;
17
+ }) => Promise<{
18
+ data?: {
19
+ payload: {
20
+ user: {
21
+ email: string;
22
+ role: string;
23
+ rawUserMetaData: string | null;
24
+ };
25
+ };
26
+ };
27
+ error?: unknown;
28
+ }>;
29
+ };
30
+ declare const jwt: () => hono_types.MiddlewareHandler<{
31
+ Variables: {
32
+ user: {
33
+ email: string;
34
+ role: string;
35
+ organizationId: string;
36
+ };
37
+ };
38
+ Bindings: {
39
+ AUTH_SERVICE: AuthService;
40
+ };
41
+ }, string, {}, Response>;
6
42
 
7
- declare const ip: () => MiddlewareHandler;
43
+ type OrganizationService$1 = {
44
+ getOrganization: (params: {
45
+ organizationId: string;
46
+ }) => Promise<{
47
+ data: {
48
+ id: string;
49
+ ipAuthorization: boolean;
50
+ authorizedIps: {
51
+ ip: string;
52
+ }[];
53
+ } | null | undefined;
54
+ error: boolean;
55
+ }>;
56
+ };
57
+ declare const ip: () => hono_types.MiddlewareHandler<{
58
+ Variables: {
59
+ user: {
60
+ organizationId: string;
61
+ };
62
+ };
63
+ Bindings: {
64
+ ENVIRONMENT: string;
65
+ ORGANIZATION_SERVICE: OrganizationService$1;
66
+ };
67
+ }, string, {}, Response>;
8
68
 
9
- declare const logger: () => MiddlewareHandler;
69
+ declare const logger: () => hono_types.MiddlewareHandler<any, string, {}, Response>;
10
70
 
11
- declare const signature: () => MiddlewareHandler;
71
+ type OrganizationService = {
72
+ getOrganization: (params: {
73
+ organizationId: string;
74
+ }) => Promise<{
75
+ data: {
76
+ id: string;
77
+ signatureKeys: {
78
+ name: string;
79
+ publicKey: string;
80
+ }[];
81
+ } | null | undefined;
82
+ error: boolean;
83
+ }>;
84
+ };
85
+ declare const signature: () => hono_types.MiddlewareHandler<{
86
+ Variables: {
87
+ user: {
88
+ email: string;
89
+ role: string;
90
+ organizationId: string;
91
+ };
92
+ };
93
+ Bindings: {
94
+ ENVIRONMENT: string;
95
+ ORGANIZATION_SERVICE: OrganizationService;
96
+ };
97
+ }, string, {}, Response>;
12
98
 
13
99
  export { idempotency, ip, jwt, logger, signature };
@@ -1,13 +1,99 @@
1
- import { MiddlewareHandler } from 'hono/types';
1
+ import * as hono_types from 'hono/types';
2
2
 
3
- declare const idempotency: () => MiddlewareHandler;
3
+ declare const idempotency: () => hono_types.MiddlewareHandler<{
4
+ Variables: {
5
+ idempotency: {
6
+ key: string;
7
+ };
8
+ };
9
+ Bindings: {
10
+ IDEMPOTENCY_KV: KVNamespace;
11
+ };
12
+ }, string, {}, Response>;
4
13
 
5
- declare const jwt: () => MiddlewareHandler;
14
+ type AuthService = {
15
+ verifyAccessToken: (params: {
16
+ accessToken: string;
17
+ }) => Promise<{
18
+ data?: {
19
+ payload: {
20
+ user: {
21
+ email: string;
22
+ role: string;
23
+ rawUserMetaData: string | null;
24
+ };
25
+ };
26
+ };
27
+ error?: unknown;
28
+ }>;
29
+ };
30
+ declare const jwt: () => hono_types.MiddlewareHandler<{
31
+ Variables: {
32
+ user: {
33
+ email: string;
34
+ role: string;
35
+ organizationId: string;
36
+ };
37
+ };
38
+ Bindings: {
39
+ AUTH_SERVICE: AuthService;
40
+ };
41
+ }, string, {}, Response>;
6
42
 
7
- declare const ip: () => MiddlewareHandler;
43
+ type OrganizationService$1 = {
44
+ getOrganization: (params: {
45
+ organizationId: string;
46
+ }) => Promise<{
47
+ data: {
48
+ id: string;
49
+ ipAuthorization: boolean;
50
+ authorizedIps: {
51
+ ip: string;
52
+ }[];
53
+ } | null | undefined;
54
+ error: boolean;
55
+ }>;
56
+ };
57
+ declare const ip: () => hono_types.MiddlewareHandler<{
58
+ Variables: {
59
+ user: {
60
+ organizationId: string;
61
+ };
62
+ };
63
+ Bindings: {
64
+ ENVIRONMENT: string;
65
+ ORGANIZATION_SERVICE: OrganizationService$1;
66
+ };
67
+ }, string, {}, Response>;
8
68
 
9
- declare const logger: () => MiddlewareHandler;
69
+ declare const logger: () => hono_types.MiddlewareHandler<any, string, {}, Response>;
10
70
 
11
- declare const signature: () => MiddlewareHandler;
71
+ type OrganizationService = {
72
+ getOrganization: (params: {
73
+ organizationId: string;
74
+ }) => Promise<{
75
+ data: {
76
+ id: string;
77
+ signatureKeys: {
78
+ name: string;
79
+ publicKey: string;
80
+ }[];
81
+ } | null | undefined;
82
+ error: boolean;
83
+ }>;
84
+ };
85
+ declare const signature: () => hono_types.MiddlewareHandler<{
86
+ Variables: {
87
+ user: {
88
+ email: string;
89
+ role: string;
90
+ organizationId: string;
91
+ };
92
+ };
93
+ Bindings: {
94
+ ENVIRONMENT: string;
95
+ ORGANIZATION_SERVICE: OrganizationService;
96
+ };
97
+ }, string, {}, Response>;
12
98
 
13
99
  export { idempotency, ip, jwt, logger, signature };
@@ -1,6 +1,5 @@
1
1
  import { createMiddleware } from 'hono/factory';
2
2
  import { HTTPException } from 'hono/http-exception';
3
- import 'h3';
4
3
  import { z } from 'zod';
5
4
  import 'cloudflare';
6
5
  import 'node:fs';
@@ -29,10 +28,10 @@ const logResponse = (log) => {
29
28
 
30
29
  const idempotency = () => {
31
30
  return createMiddleware(async (context, next) => {
32
- const idempotencyKeyHeader = context.req.header("X-Idempotency-Key");
31
+ const idempotencyKeyHeader = context.req.header("x-idempotency-key");
33
32
  if (!idempotencyKeyHeader) {
34
33
  throw new HTTPException(401, {
35
- message: `The 'X-Idempotency-Key' header must exist and must have a value.`
34
+ message: `The 'x-idempotency-key' header must exist and must have a value.`
36
35
  });
37
36
  }
38
37
  const existingIdempotencyRecord = await context.env.IDEMPOTENCY_KV.get(idempotencyKeyHeader);
@@ -58,21 +57,21 @@ const idempotency = () => {
58
57
 
59
58
  const jwt = () => {
60
59
  return createMiddleware(async (context, next) => {
61
- const authorizationHeader = context.req.header("Authorization");
60
+ const authorizationHeader = context.req.header("authorization");
62
61
  if (!authorizationHeader) {
63
62
  throw new HTTPException(401, {
64
- message: `The 'Authorization' header must exist and must have a value.`
63
+ message: `The 'authorization' header must exist and must have a value.`
65
64
  });
66
65
  }
67
66
  if (!validateBearerScheme(authorizationHeader)) {
68
67
  throw new HTTPException(401, {
69
- message: `The 'Authorization' header value must use the Bearer scheme.`
68
+ message: `The 'authorization' header value must use the Bearer scheme.`
70
69
  });
71
70
  }
72
71
  const bearerToken = extractBearerToken(authorizationHeader);
73
72
  if (!validateBearerToken(bearerToken)) {
74
73
  throw new HTTPException(401, {
75
- message: `The Bearer token in the 'Authorization' header value must be a JWT.`
74
+ message: `The Bearer token in the 'authorization' header value must be a JWT.`
76
75
  });
77
76
  }
78
77
  const { data, error } = await context.env.AUTH_SERVICE.verifyAccessToken({
@@ -96,7 +95,6 @@ const jwt = () => {
96
95
  role: data.payload.user.role,
97
96
  organizationId
98
97
  });
99
- context.set("jwt", data.payload);
100
98
  await next();
101
99
  });
102
100
  };
@@ -174,16 +172,16 @@ const logger = () => {
174
172
  const signature = () => {
175
173
  return createMiddleware(async (context, next) => {
176
174
  if (!["localhost", "dev"].includes(context.env.ENVIRONMENT)) {
177
- const signatureHeader = context.req.header("X-Signature");
175
+ const signatureHeader = context.req.header("x-signature");
178
176
  if (!signatureHeader) {
179
177
  throw new HTTPException(401, {
180
- message: `The 'X-Signature' header must exist and must have a value.`
178
+ message: `The 'x-signature' header must exist and must have a value.`
181
179
  });
182
180
  }
183
181
  const signatureKeyHeader = context.req.header("X-Signature-Key");
184
182
  if (!signatureKeyHeader) {
185
183
  throw new HTTPException(401, {
186
- message: `The 'X-Signature-Key' header must exist and must have a value.`
184
+ message: `The 'x-signature-key' header must exist and must have a value.`
187
185
  });
188
186
  }
189
187
  const payload = JSON.stringify(await context.req.json().catch(() => null));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@develit-io/backend-sdk",
3
- "version": "8.6.3",
3
+ "version": "9.0.1",
4
4
  "description": "Develit Backend SDK",
5
5
  "author": "Develit.io",
6
6
  "license": "ISC",
@@ -33,15 +33,15 @@
33
33
  "comment-json": "^4.4.1",
34
34
  "drizzle-kit": "^0.31.6",
35
35
  "drizzle-orm": "^0.44.7",
36
- "h3": "^1.15.4",
37
36
  "superjson": "^2.2.5"
38
37
  },
39
38
  "peerDependencies": {
40
39
  "@develit-io/general-codes": "^1.14.0",
41
40
  "cloudflare": "^5.2.0",
42
- "zod": "^4.1.12"
41
+ "zod": "^4.1.13"
43
42
  },
44
43
  "devDependencies": {
45
- "hono": "^4.10.4"
44
+ "hono": "^4.10.4",
45
+ "zod": "^4.1.13"
46
46
  }
47
47
  }