@develit-io/backend-sdk 5.37.1 → 5.38.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
@@ -61,6 +61,8 @@ declare const idempotency: <T extends {
61
61
  IDEMPOTENCY_KV: KVNamespace;
62
62
  }>() => MiddlewareHandler;
63
63
 
64
+ declare const logger: () => MiddlewareHandler;
65
+
64
66
  declare const ENVIRONMENT: string[];
65
67
 
66
68
  interface AuditLogPayload<T> {
@@ -166,6 +168,12 @@ type InferResultType<Tables extends Record<string, unknown>, TableName extends k
166
168
  with: With;
167
169
  }>;
168
170
 
171
+ interface IdempotencyVariables {
172
+ idempotency: {
173
+ key: string;
174
+ };
175
+ }
176
+
169
177
  declare const paginationQuerySchema: z.$ZodObject<Readonly<Readonly<{
170
178
  [k: string]: z.$ZodType<unknown, unknown, z.$ZodTypeInternals<unknown, unknown>>;
171
179
  }>>, z.$ZodObjectConfig>;
@@ -499,5 +507,5 @@ interface WithRetryCounterOptions {
499
507
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
500
508
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
501
509
 
502
- export { DatabaseTransaction, ENVIRONMENT, RPCResponse, action, bankAccount, bankAccountMetadataSchema, base, bicSchema, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getSecret, handleAction, handleActionResponse, ibanSchema, idempotency, isInternalError, paginationQuerySchema, paginationSchema, service, useFetch, useResult, useResultSync, uuidv4 };
503
- export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, BankAccountMetadata, BaseEvent, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
510
+ export { DatabaseTransaction, ENVIRONMENT, RPCResponse, action, bankAccount, bankAccountMetadataSchema, base, bicSchema, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getSecret, handleAction, handleActionResponse, ibanSchema, idempotency, isInternalError, logger, paginationQuerySchema, paginationSchema, service, useFetch, useResult, useResultSync, uuidv4 };
511
+ export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, BankAccountMetadata, BaseEvent, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IdempotencyVariables, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
package/dist/index.d.ts CHANGED
@@ -61,6 +61,8 @@ declare const idempotency: <T extends {
61
61
  IDEMPOTENCY_KV: KVNamespace;
62
62
  }>() => MiddlewareHandler;
63
63
 
64
+ declare const logger: () => MiddlewareHandler;
65
+
64
66
  declare const ENVIRONMENT: string[];
65
67
 
66
68
  interface AuditLogPayload<T> {
@@ -166,6 +168,12 @@ type InferResultType<Tables extends Record<string, unknown>, TableName extends k
166
168
  with: With;
167
169
  }>;
168
170
 
171
+ interface IdempotencyVariables {
172
+ idempotency: {
173
+ key: string;
174
+ };
175
+ }
176
+
169
177
  declare const paginationQuerySchema: z.$ZodObject<Readonly<Readonly<{
170
178
  [k: string]: z.$ZodType<unknown, unknown, z.$ZodTypeInternals<unknown, unknown>>;
171
179
  }>>, z.$ZodObjectConfig>;
@@ -499,5 +507,5 @@ interface WithRetryCounterOptions {
499
507
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
500
508
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
501
509
 
502
- export { DatabaseTransaction, ENVIRONMENT, RPCResponse, action, bankAccount, bankAccountMetadataSchema, base, bicSchema, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getSecret, handleAction, handleActionResponse, ibanSchema, idempotency, isInternalError, paginationQuerySchema, paginationSchema, service, useFetch, useResult, useResultSync, uuidv4 };
503
- export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, BankAccountMetadata, BaseEvent, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
510
+ export { DatabaseTransaction, ENVIRONMENT, RPCResponse, action, bankAccount, bankAccountMetadataSchema, base, bicSchema, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getSecret, handleAction, handleActionResponse, ibanSchema, idempotency, isInternalError, logger, paginationQuerySchema, paginationSchema, service, useFetch, useResult, useResultSync, uuidv4 };
511
+ export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, BankAccountMetadata, BaseEvent, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IdempotencyVariables, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
package/dist/index.mjs CHANGED
@@ -2,15 +2,15 @@ import { sql } 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 { createMiddleware } from 'hono/factory';
5
- import { z as z$1 } from 'zod';
6
- import * as z from 'zod/v4/core';
7
- import 'http-status-codes';
8
5
  import { createError } from 'h3';
9
6
  import 'cloudflare';
10
7
  import fs from 'node:fs';
11
8
  import crypto$1 from 'node:crypto';
12
9
  import path from 'node:path';
13
10
  import { parse } from 'comment-json';
11
+ import { z as z$1 } from 'zod';
12
+ import * as z from 'zod/v4/core';
13
+ import 'http-status-codes';
14
14
  import superjson from 'superjson';
15
15
 
16
16
  const uuidv4 = () => crypto.randomUUID();
@@ -98,107 +98,25 @@ const idempotency = () => {
98
98
  });
99
99
  };
100
100
 
101
- const ibanSchema = z$1.string().min(1).regex(/^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$/, {
102
- message: "Invalid IBAN format"
103
- });
104
- const bicSchema = z$1.string().min(1).regex(/^[A-Z]{6}[A-Z0-9]{2}([A-Z0-9]{3})?$/, {
105
- message: "Invalid SWIFT/BIC format"
106
- });
107
- const bankAccountMetadataSchema = z$1.object({
108
- id: z$1.string().optional(),
109
- number: z$1.string().optional(),
110
- bankCode: z$1.enum(BANK_CODES).optional(),
111
- holderName: z$1.string().optional(),
112
- iban: ibanSchema.optional(),
113
- address: z$1.string().optional(),
114
- swiftBic: bicSchema.optional(),
115
- bicCor: bicSchema.optional()
116
- });
117
-
118
- const paginationQuerySchema = new z.$ZodObject({
119
- type: "object",
120
- shape: {
121
- page: new z.$ZodDefault({
122
- type: "default",
123
- innerType: new z.$ZodNumber({
124
- type: "number",
125
- coerce: true
126
- }),
127
- defaultValue: () => 1
128
- }),
129
- limit: new z.$ZodDefault({
130
- type: "default",
131
- innerType: new z.$ZodNumber({
132
- type: "number",
133
- coerce: true
134
- }),
135
- defaultValue: () => 20
136
- }),
137
- sort: new z.$ZodDefault({
138
- type: "default",
139
- innerType: new z.$ZodObject({
140
- type: "object",
141
- shape: {
142
- column: new z.$ZodDefault({
143
- type: "default",
144
- innerType: new z.$ZodEnum({
145
- type: "enum",
146
- entries: {
147
- createdAt: "createdAt",
148
- updatedAt: "updatedAt",
149
- deletedAt: "deletedAt"
150
- }
151
- }),
152
- defaultValue: () => "updatedAt"
153
- }),
154
- direction: new z.$ZodDefault({
155
- type: "default",
156
- innerType: new z.$ZodEnum({
157
- type: "enum",
158
- entries: {
159
- asc: "asc",
160
- desc: "desc"
161
- }
162
- }),
163
- defaultValue: () => "desc"
164
- })
165
- }
166
- }),
167
- defaultValue: () => ({ column: "updatedAt", direction: "desc" })
168
- })
169
- }
170
- });
171
- const paginationSchema = new z.$ZodObject({
172
- type: "object",
173
- shape: {
174
- page: new z.$ZodNumber({
175
- type: "number"
176
- }),
177
- limit: new z.$ZodNumber({
178
- type: "number"
179
- }),
180
- sort: new z.$ZodObject({
181
- type: "object",
182
- shape: {
183
- column: new z.$ZodEnum({
184
- type: "enum",
185
- entries: {
186
- createdAt: "createdAt",
187
- updatedAt: "updatedAt",
188
- deletedAt: "deletedAt"
189
- }
190
- }),
191
- direction: new z.$ZodEnum({
192
- type: "enum",
193
- entries: {
194
- asc: "asc",
195
- desc: "desc"
196
- }
197
- })
198
- }
199
- })
200
- }
201
- });
101
+ const composeRequestLog = async (request) => {
102
+ return {
103
+ method: request.method,
104
+ path: request.path,
105
+ query: request.query(),
106
+ headers: request.header(),
107
+ body: await request.json().catch(() => null)
108
+ };
109
+ };
110
+ const composeResponseLog = async (response, method, path) => {
111
+ return {
112
+ method,
113
+ path,
114
+ status: response.status,
115
+ statusText: response.statusText,
116
+ headers: Object.fromEntries(response.headers.entries()),
117
+ body: await response.json().catch(() => null)
118
+ };
119
+ };
202
120
 
203
121
  const handleActionResponse = ({
204
122
  error,
@@ -560,6 +478,13 @@ async function useFetch(url, { parseAs = "json", ...options } = {}) {
560
478
  return [body, null];
561
479
  }
562
480
 
481
+ const logRequest = (log) => {
482
+ console.log("REQUEST | An incoming request has been recorded.", log);
483
+ };
484
+ const logResponse = (log) => {
485
+ console.log(`RESPONSE | An outgoing response has been recorded.`, log);
486
+ };
487
+
563
488
  const calculateExponentialBackoff = (attempts, baseDelaySeconds) => {
564
489
  return baseDelaySeconds ** attempts;
565
490
  };
@@ -576,6 +501,123 @@ const getSecret = async (secretName, env) => {
576
501
  return await secret.get();
577
502
  };
578
503
 
504
+ const logger = () => {
505
+ return createMiddleware(async (context, next) => {
506
+ const requestLog = await composeRequestLog(context.req);
507
+ logRequest(requestLog);
508
+ await next();
509
+ const response = context.res.clone();
510
+ const responseLog = await composeResponseLog(
511
+ response,
512
+ context.req.method,
513
+ context.req.url
514
+ );
515
+ logResponse(responseLog);
516
+ });
517
+ };
518
+
519
+ const ibanSchema = z$1.string().min(1).regex(/^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$/, {
520
+ message: "Invalid IBAN format"
521
+ });
522
+ const bicSchema = z$1.string().min(1).regex(/^[A-Z]{6}[A-Z0-9]{2}([A-Z0-9]{3})?$/, {
523
+ message: "Invalid SWIFT/BIC format"
524
+ });
525
+ const bankAccountMetadataSchema = z$1.object({
526
+ id: z$1.string().optional(),
527
+ number: z$1.string().optional(),
528
+ bankCode: z$1.enum(BANK_CODES).optional(),
529
+ holderName: z$1.string().optional(),
530
+ iban: ibanSchema.optional(),
531
+ address: z$1.string().optional(),
532
+ swiftBic: bicSchema.optional(),
533
+ bicCor: bicSchema.optional()
534
+ });
535
+
536
+ const paginationQuerySchema = new z.$ZodObject({
537
+ type: "object",
538
+ shape: {
539
+ page: new z.$ZodDefault({
540
+ type: "default",
541
+ innerType: new z.$ZodNumber({
542
+ type: "number",
543
+ coerce: true
544
+ }),
545
+ defaultValue: () => 1
546
+ }),
547
+ limit: new z.$ZodDefault({
548
+ type: "default",
549
+ innerType: new z.$ZodNumber({
550
+ type: "number",
551
+ coerce: true
552
+ }),
553
+ defaultValue: () => 20
554
+ }),
555
+ sort: new z.$ZodDefault({
556
+ type: "default",
557
+ innerType: new z.$ZodObject({
558
+ type: "object",
559
+ shape: {
560
+ column: new z.$ZodDefault({
561
+ type: "default",
562
+ innerType: new z.$ZodEnum({
563
+ type: "enum",
564
+ entries: {
565
+ createdAt: "createdAt",
566
+ updatedAt: "updatedAt",
567
+ deletedAt: "deletedAt"
568
+ }
569
+ }),
570
+ defaultValue: () => "updatedAt"
571
+ }),
572
+ direction: new z.$ZodDefault({
573
+ type: "default",
574
+ innerType: new z.$ZodEnum({
575
+ type: "enum",
576
+ entries: {
577
+ asc: "asc",
578
+ desc: "desc"
579
+ }
580
+ }),
581
+ defaultValue: () => "desc"
582
+ })
583
+ }
584
+ }),
585
+ defaultValue: () => ({ column: "updatedAt", direction: "desc" })
586
+ })
587
+ }
588
+ });
589
+ const paginationSchema = new z.$ZodObject({
590
+ type: "object",
591
+ shape: {
592
+ page: new z.$ZodNumber({
593
+ type: "number"
594
+ }),
595
+ limit: new z.$ZodNumber({
596
+ type: "number"
597
+ }),
598
+ sort: new z.$ZodObject({
599
+ type: "object",
600
+ shape: {
601
+ column: new z.$ZodEnum({
602
+ type: "enum",
603
+ entries: {
604
+ createdAt: "createdAt",
605
+ updatedAt: "updatedAt",
606
+ deletedAt: "deletedAt"
607
+ }
608
+ }),
609
+ direction: new z.$ZodEnum({
610
+ type: "enum",
611
+ entries: {
612
+ asc: "asc",
613
+ desc: "desc"
614
+ }
615
+ })
616
+ }
617
+ })
618
+ }
619
+ });
620
+
579
621
  const service = (serviceName) => {
580
622
  return function(constructor) {
581
623
  return class extends constructor {
@@ -716,4 +758,4 @@ function develitWorker(Worker) {
716
758
  return DevelitWorker;
717
759
  }
718
760
 
719
- export { DatabaseTransaction, ENVIRONMENT, RPCResponse, action, bankAccount, bankAccountMetadataSchema, base, bicSchema, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getSecret, handleAction, handleActionResponse, ibanSchema, idempotency, isInternalError, paginationQuerySchema, paginationSchema, service, useFetch, useResult, useResultSync, uuidv4 };
761
+ export { DatabaseTransaction, ENVIRONMENT, RPCResponse, action, bankAccount, bankAccountMetadataSchema, base, bicSchema, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getSecret, handleAction, handleActionResponse, ibanSchema, idempotency, isInternalError, logger, paginationQuerySchema, paginationSchema, service, useFetch, useResult, useResultSync, uuidv4 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@develit-io/backend-sdk",
3
- "version": "5.37.1",
3
+ "version": "5.38.0",
4
4
  "description": "Develit Backend SDK",
5
5
  "author": "Develit.io",
6
6
  "license": "ISC",