@develit-io/backend-sdk 8.6.3 → 9.0.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 CHANGED
@@ -474,6 +474,7 @@ interface InternalError {
474
474
  interface IRPCResponse<T> {
475
475
  status: ContentfulStatusCode;
476
476
  message: string;
477
+ code: string;
477
478
  data: T | null | undefined;
478
479
  error: boolean;
479
480
  }
@@ -529,13 +530,6 @@ declare const workflowInstanceStatusSchema: z$1.ZodObject<{
529
530
  }, z$1.core.$strip>;
530
531
  type WorkflowInstanceStatus = z$1.infer<typeof workflowInstanceStatusSchema>;
531
532
 
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
533
  type Constructor<T = {}> = abstract new (...args: any[]) => T;
540
534
  interface DevelitWorkerMethods {
541
535
  name: string;
@@ -740,20 +734,14 @@ interface UseFetchOptions extends RequestInit {
740
734
  }
741
735
  declare function useFetch<T = unknown>(url: string, { parseAs, ...options }?: UseFetchOptions): Promise<Result<T>>;
742
736
 
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>;
737
+ type NullToOptional<T> = {
738
+ [K in keyof T]: null extends T[K] ? Exclude<T[K], null> | undefined : T[K];
739
+ };
740
+ declare function nullToOptional<T extends object>(obj: T): NullToOptional<T>;
741
+ type OptionalToNull<T> = {
742
+ [K in keyof T]: undefined extends T[K] ? Exclude<T[K], undefined> | null : T[K];
743
+ };
744
+ declare function optionalToNull<T extends object>(obj: T): OptionalToNull<T>;
757
745
 
758
746
  declare const calculateExponentialBackoff: (attempts: number, baseDelaySeconds: number) => number;
759
747
 
@@ -825,14 +813,20 @@ declare const useResultSync: <T>(fn: () => T) => Result<T>;
825
813
 
826
814
  declare const getSecret: (secretName: string, env: unknown) => Promise<string>;
827
815
 
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>;
816
+ declare const createSignatureKeyPair: () => Promise<{
817
+ publicKey: string;
818
+ privateKey: string;
819
+ }>;
820
+ declare const signPayload: ({ payload, privateKey, }: {
821
+ payload: string;
822
+ privateKey: string;
823
+ }) => Promise<string>;
824
+ declare const verifyPayloadSignature: ({ signature, data, publicKey, algorithm, }: {
825
+ signature: string;
826
+ data: string;
827
+ publicKey: string;
828
+ algorithm?: "RSA" | "EC" | "HMAC";
829
+ }) => Promise<boolean>;
836
830
 
837
831
  declare const service: (serviceName: string) => <T extends new (...args: any[]) => object>(constructor: T) => {
838
832
  new (...args: any[]): {
@@ -853,5 +847,5 @@ interface WithRetryCounterOptions {
853
847
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
854
848
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
855
849
 
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 };
850
+ 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 };
857
851
  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 };
package/dist/index.d.ts CHANGED
@@ -474,6 +474,7 @@ interface InternalError {
474
474
  interface IRPCResponse<T> {
475
475
  status: ContentfulStatusCode;
476
476
  message: string;
477
+ code: string;
477
478
  data: T | null | undefined;
478
479
  error: boolean;
479
480
  }
@@ -529,13 +530,6 @@ declare const workflowInstanceStatusSchema: z$1.ZodObject<{
529
530
  }, z$1.core.$strip>;
530
531
  type WorkflowInstanceStatus = z$1.infer<typeof workflowInstanceStatusSchema>;
531
532
 
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
533
  type Constructor<T = {}> = abstract new (...args: any[]) => T;
540
534
  interface DevelitWorkerMethods {
541
535
  name: string;
@@ -740,20 +734,14 @@ interface UseFetchOptions extends RequestInit {
740
734
  }
741
735
  declare function useFetch<T = unknown>(url: string, { parseAs, ...options }?: UseFetchOptions): Promise<Result<T>>;
742
736
 
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>;
737
+ type NullToOptional<T> = {
738
+ [K in keyof T]: null extends T[K] ? Exclude<T[K], null> | undefined : T[K];
739
+ };
740
+ declare function nullToOptional<T extends object>(obj: T): NullToOptional<T>;
741
+ type OptionalToNull<T> = {
742
+ [K in keyof T]: undefined extends T[K] ? Exclude<T[K], undefined> | null : T[K];
743
+ };
744
+ declare function optionalToNull<T extends object>(obj: T): OptionalToNull<T>;
757
745
 
758
746
  declare const calculateExponentialBackoff: (attempts: number, baseDelaySeconds: number) => number;
759
747
 
@@ -825,14 +813,20 @@ declare const useResultSync: <T>(fn: () => T) => Result<T>;
825
813
 
826
814
  declare const getSecret: (secretName: string, env: unknown) => Promise<string>;
827
815
 
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>;
816
+ declare const createSignatureKeyPair: () => Promise<{
817
+ publicKey: string;
818
+ privateKey: string;
819
+ }>;
820
+ declare const signPayload: ({ payload, privateKey, }: {
821
+ payload: string;
822
+ privateKey: string;
823
+ }) => Promise<string>;
824
+ declare const verifyPayloadSignature: ({ signature, data, publicKey, algorithm, }: {
825
+ signature: string;
826
+ data: string;
827
+ publicKey: string;
828
+ algorithm?: "RSA" | "EC" | "HMAC";
829
+ }) => Promise<boolean>;
836
830
 
837
831
  declare const service: (serviceName: string) => <T extends new (...args: any[]) => object>(constructor: T) => {
838
832
  new (...args: any[]): {
@@ -853,5 +847,5 @@ interface WithRetryCounterOptions {
853
847
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
854
848
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
855
849
 
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 };
850
+ 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 };
857
851
  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 };
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';
@@ -212,24 +211,6 @@ const workflowInstanceStatusSchema = z$1.object({
212
211
  output: z$1.unknown().optional()
213
212
  });
214
213
 
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,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';
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.0",
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
  }