@develit-io/backend-sdk 5.36.1 → 5.37.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
@@ -2,6 +2,7 @@ import * as drizzle_orm from 'drizzle-orm';
2
2
  import { ExtractTablesWithRelations, DBQueryConfig, BuildQueryResult } from 'drizzle-orm';
3
3
  import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
4
4
  import { AnySQLiteTable } from 'drizzle-orm/sqlite-core';
5
+ import { MiddlewareHandler } from 'hono/types';
5
6
  import { z as z$1 } from 'zod';
6
7
  import * as z from 'zod/v4/core';
7
8
  import { StatusCodes, ReasonPhrases } from 'http-status-codes';
@@ -56,6 +57,10 @@ declare const composeWranglerBase: ({ project, name, }: {
56
57
  keep_vars: boolean;
57
58
  };
58
59
 
60
+ declare const idempotency: <T extends {
61
+ IDEMPOTENCY_KV: KVNamespace;
62
+ }>() => MiddlewareHandler;
63
+
59
64
  declare const ENVIRONMENT: string[];
60
65
 
61
66
  interface AuditLogPayload<T> {
@@ -494,5 +499,5 @@ interface WithRetryCounterOptions {
494
499
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
495
500
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
496
501
 
497
- 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, isInternalError, paginationQuerySchema, paginationSchema, service, useFetch, useResult, useResultSync, uuidv4 };
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 };
498
503
  export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, BankAccountMetadata, BaseEvent, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import * as drizzle_orm from 'drizzle-orm';
2
2
  import { ExtractTablesWithRelations, DBQueryConfig, BuildQueryResult } from 'drizzle-orm';
3
3
  import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
4
4
  import { AnySQLiteTable } from 'drizzle-orm/sqlite-core';
5
+ import { MiddlewareHandler } from 'hono/types';
5
6
  import { z as z$1 } from 'zod';
6
7
  import * as z from 'zod/v4/core';
7
8
  import { StatusCodes, ReasonPhrases } from 'http-status-codes';
@@ -56,6 +57,10 @@ declare const composeWranglerBase: ({ project, name, }: {
56
57
  keep_vars: boolean;
57
58
  };
58
59
 
60
+ declare const idempotency: <T extends {
61
+ IDEMPOTENCY_KV: KVNamespace;
62
+ }>() => MiddlewareHandler;
63
+
59
64
  declare const ENVIRONMENT: string[];
60
65
 
61
66
  interface AuditLogPayload<T> {
@@ -494,5 +499,5 @@ interface WithRetryCounterOptions {
494
499
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
495
500
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
496
501
 
497
- 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, isInternalError, paginationQuerySchema, paginationSchema, service, useFetch, useResult, useResultSync, uuidv4 };
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 };
498
503
  export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, BankAccountMetadata, BaseEvent, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  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
+ import { createMiddleware } from 'hono/factory';
4
5
  import { z as z$1 } from 'zod';
5
6
  import * as z from 'zod/v4/core';
6
7
  import 'http-status-codes';
@@ -63,6 +64,40 @@ const composeWranglerBase = ({
63
64
  };
64
65
  };
65
66
 
67
+ const idempotency = () => {
68
+ return createMiddleware(async (context, next) => {
69
+ const idempotencyKeyHeader = context.req.header("X-Idempotency-Key");
70
+ if (!idempotencyKeyHeader) {
71
+ return context.json(
72
+ {
73
+ message: `The 'X-Idempotency-Key' header must exist and must have a value.`
74
+ },
75
+ 401
76
+ );
77
+ }
78
+ const existingIdempotencyRecord = await context.env.IDEMPOTENCY_KV.get(idempotencyKeyHeader);
79
+ if (existingIdempotencyRecord)
80
+ return context.json(
81
+ {
82
+ message: "The identical request has already been processed. The idempotency key is not unique."
83
+ },
84
+ 409
85
+ );
86
+ await context.env.IDEMPOTENCY_KV.put(
87
+ idempotencyKeyHeader,
88
+ idempotencyKeyHeader,
89
+ {
90
+ expirationTtl: 60 * 60 * 24 * 3
91
+ // 3 days
92
+ }
93
+ );
94
+ context.set("idempotency", {
95
+ key: idempotencyKeyHeader
96
+ });
97
+ await next();
98
+ });
99
+ };
100
+
66
101
  const ibanSchema = z$1.string().min(1).regex(/^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$/, {
67
102
  message: "Invalid IBAN format"
68
103
  });
@@ -681,4 +716,4 @@ function develitWorker(Worker) {
681
716
  return DevelitWorker;
682
717
  }
683
718
 
684
- 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, isInternalError, paginationQuerySchema, paginationSchema, service, useFetch, useResult, useResultSync, uuidv4 };
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@develit-io/backend-sdk",
3
- "version": "5.36.1",
3
+ "version": "5.37.1",
4
4
  "description": "Develit Backend SDK",
5
5
  "author": "Develit.io",
6
6
  "license": "ISC",
@@ -40,5 +40,8 @@
40
40
  "@develit-io/general-codes": "^1.14.0",
41
41
  "cloudflare": "^5.2.0",
42
42
  "zod": "^4.1.12"
43
+ },
44
+ "devDependencies": {
45
+ "hono": "^4.10.4"
43
46
  }
44
47
  }