@develit-io/backend-sdk 12.5.0 → 12.6.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
@@ -1152,6 +1152,10 @@ type AuditLogWriter<TAuditAction = string> = (logs: AuditLogPayload<TAuditAction
1152
1152
  */
1153
1153
  declare function createAuditLogWriter<TAuditAction = string>(table: AuditLogTable): AuditLogWriter<TAuditAction>;
1154
1154
 
1155
+ declare const validateBearerScheme: (header: string) => boolean;
1156
+ declare const extractBearerToken: (header: string) => string;
1157
+ declare const validateBearerToken: (bearerToken: string) => boolean;
1158
+
1155
1159
  declare function durableObjectNamespaceIdFromName(uniqueKey: string, name: string): string;
1156
1160
  declare const getLocalD1DatabaseIdFromWrangler: () => string | undefined;
1157
1161
  declare const getD1Credentials: () => Promise<{
@@ -1501,5 +1505,5 @@ interface WithRetryCounterOptions {
1501
1505
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
1502
1506
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
1503
1507
 
1504
- export { DLQ_ALERT_DEFAULT_MAX_INTERVAL, DLQ_ALERT_DEFAULT_MIN_SIZE, DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildDlqAlert, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, chunkQueueMessages, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInsertSchema, createInternalError, createPatchSchema, createSelectSchema, createUpdateSchema, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getDrizzleD1Config, getLocalD1DatabaseIdFromWrangler, getSecret, handleAction, handleDlqBatch, ibanSchema, isDlqQueue, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, parseDlqAlertRecipients, pushToQueue, queryInChunks, redact, resolveColumn, service, shouldAlertDlq, structuredAddressSchema, useFetch, useResult, useResultSync, uuidv4, uuidv5, workflowInstanceStatusSchema };
1508
+ export { DLQ_ALERT_DEFAULT_MAX_INTERVAL, DLQ_ALERT_DEFAULT_MIN_SIZE, DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildDlqAlert, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, chunkQueueMessages, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInsertSchema, createInternalError, createPatchSchema, createSelectSchema, createUpdateSchema, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, extractBearerToken, first, firstOrError, getD1Credentials, getDrizzleD1Config, getLocalD1DatabaseIdFromWrangler, getSecret, handleAction, handleDlqBatch, ibanSchema, isDlqQueue, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, parseDlqAlertRecipients, pushToQueue, queryInChunks, redact, resolveColumn, service, shouldAlertDlq, structuredAddressSchema, useFetch, useResult, useResultSync, uuidv4, uuidv5, validateBearerScheme, validateBearerToken, workflowInstanceStatusSchema };
1505
1509
  export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, BankAccountMetadata, BaseEvent, BuildSearchOptions, Command, CommandLogPayload, DevelitWorkerMethods, DlqAlert, DlqMessageInfo, Environment, GatewayResponse, HandleDlqBatchOptions, IRPCResponse, IdempotencyContextVariables, IdentityContextVariables, InternalError, InternalErrorResponseStatus, Project, RequestLog, ResponseLog, ShouldAlertDlqParams, StructuredAddress, UserRole, ValidatedInput, WorkflowInstanceStatus };
package/dist/index.d.ts CHANGED
@@ -1152,6 +1152,10 @@ type AuditLogWriter<TAuditAction = string> = (logs: AuditLogPayload<TAuditAction
1152
1152
  */
1153
1153
  declare function createAuditLogWriter<TAuditAction = string>(table: AuditLogTable): AuditLogWriter<TAuditAction>;
1154
1154
 
1155
+ declare const validateBearerScheme: (header: string) => boolean;
1156
+ declare const extractBearerToken: (header: string) => string;
1157
+ declare const validateBearerToken: (bearerToken: string) => boolean;
1158
+
1155
1159
  declare function durableObjectNamespaceIdFromName(uniqueKey: string, name: string): string;
1156
1160
  declare const getLocalD1DatabaseIdFromWrangler: () => string | undefined;
1157
1161
  declare const getD1Credentials: () => Promise<{
@@ -1501,5 +1505,5 @@ interface WithRetryCounterOptions {
1501
1505
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
1502
1506
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
1503
1507
 
1504
- export { DLQ_ALERT_DEFAULT_MAX_INTERVAL, DLQ_ALERT_DEFAULT_MIN_SIZE, DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildDlqAlert, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, chunkQueueMessages, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInsertSchema, createInternalError, createPatchSchema, createSelectSchema, createUpdateSchema, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getDrizzleD1Config, getLocalD1DatabaseIdFromWrangler, getSecret, handleAction, handleDlqBatch, ibanSchema, isDlqQueue, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, parseDlqAlertRecipients, pushToQueue, queryInChunks, redact, resolveColumn, service, shouldAlertDlq, structuredAddressSchema, useFetch, useResult, useResultSync, uuidv4, uuidv5, workflowInstanceStatusSchema };
1508
+ export { DLQ_ALERT_DEFAULT_MAX_INTERVAL, DLQ_ALERT_DEFAULT_MIN_SIZE, DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, asNonEmpty, bankAccount, bankAccountMetadataSchema, base, bicSchema, buildDlqAlert, buildMultiFilterConditions, buildRangeFilterConditions, buildSearchConditions, calculateExponentialBackoff, chunkQueueMessages, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInsertSchema, createInternalError, createPatchSchema, createSelectSchema, createUpdateSchema, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, extractBearerToken, first, firstOrError, getD1Credentials, getDrizzleD1Config, getLocalD1DatabaseIdFromWrangler, getSecret, handleAction, handleDlqBatch, ibanSchema, isDlqQueue, isInternalError, nullToOptional, optionalToNull, paginationQuerySchema, paginationSchema, parseDlqAlertRecipients, pushToQueue, queryInChunks, redact, resolveColumn, service, shouldAlertDlq, structuredAddressSchema, useFetch, useResult, useResultSync, uuidv4, uuidv5, validateBearerScheme, validateBearerToken, workflowInstanceStatusSchema };
1505
1509
  export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, BankAccountMetadata, BaseEvent, BuildSearchOptions, Command, CommandLogPayload, DevelitWorkerMethods, DlqAlert, DlqMessageInfo, Environment, GatewayResponse, HandleDlqBatchOptions, IRPCResponse, IdempotencyContextVariables, IdentityContextVariables, InternalError, InternalErrorResponseStatus, Project, RequestLog, ResponseLog, ShouldAlertDlqParams, StructuredAddress, UserRole, ValidatedInput, WorkflowInstanceStatus };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { s as summarizeBinary, a as serializeLog } from './shared/backend-sdk.DANN3OYI.mjs';
2
- export { u as uuidv4, b as uuidv5 } from './shared/backend-sdk.DANN3OYI.mjs';
1
+ import { s as summarizeBinary, a as serializeLog } from './shared/backend-sdk.BFjyTkk2.mjs';
2
+ export { e as extractBearerToken, u as uuidv4, b as uuidv5, v as validateBearerScheme, c as validateBearerToken } from './shared/backend-sdk.BFjyTkk2.mjs';
3
3
  import { sql, inArray, eq, gte, lte, and, or } from 'drizzle-orm';
4
4
  import { text, integer } from 'drizzle-orm/sqlite-core';
5
5
  import { COUNTRY_CODES_2, CURRENCY_CODES, BANK_CODES } from '@develit-io/general-codes';
@@ -28,6 +28,7 @@ type AccessRequestResolver<TScope extends string = string> = ScopeCondition<TSco
28
28
  * @param options.errorMessage - Custom 403 error message.
29
29
  * @param Can be disabled by setting `MIDDLEWARE_ACCESS_DISABLED` env var.
30
30
  * @throws {HTTPException} 403 if the user does not have the required access.
31
+ * @throws {HTTPException} 503 if the RBAC service fails to verify the access.
31
32
  */
32
33
  declare const access: <TScope extends string = string>(accessRequests: AccessRequestResolver<TScope>, options?: AccessMiddlewareOptions) => MiddlewareHandler;
33
34
 
@@ -28,6 +28,7 @@ type AccessRequestResolver<TScope extends string = string> = ScopeCondition<TSco
28
28
  * @param options.errorMessage - Custom 403 error message.
29
29
  * @param Can be disabled by setting `MIDDLEWARE_ACCESS_DISABLED` env var.
30
30
  * @throws {HTTPException} 403 if the user does not have the required access.
31
+ * @throws {HTTPException} 503 if the RBAC service fails to verify the access.
31
32
  */
32
33
  declare const access: <TScope extends string = string>(accessRequests: AccessRequestResolver<TScope>, options?: AccessMiddlewareOptions) => MiddlewareHandler;
33
34
 
@@ -1,26 +1,16 @@
1
1
  import { createMiddleware } from 'hono/factory';
2
2
  import { HTTPException } from 'hono/http-exception';
3
- import { z } from 'zod';
3
+ import { v as validateBearerScheme, e as extractBearerToken, c as validateBearerToken, u as uuidv4 } from './shared/backend-sdk.BFjyTkk2.mjs';
4
4
  import 'cloudflare';
5
5
  import 'comment-json';
6
6
  import 'node:crypto';
7
7
  import 'node:fs';
8
8
  import 'node:path';
9
9
  import 'drizzle-orm';
10
- import { u as uuidv4 } from './shared/backend-sdk.DANN3OYI.mjs';
10
+ import 'zod';
11
11
  import { verifyPayloadSignature } from './utils/signature.util.mjs';
12
12
  import 'superjson';
13
13
 
14
- const validateBearerScheme = (header) => {
15
- return header.startsWith("Bearer ") && header.length > 7 && !header.slice(7).includes(" ");
16
- };
17
- const extractBearerToken = (header) => {
18
- return header.slice(7).trim();
19
- };
20
- const validateBearerToken = (bearerToken) => {
21
- return z.jwt().safeParse(bearerToken).success;
22
- };
23
-
24
14
  const logRequest = (log) => {
25
15
  console.log("REQUEST | An incoming request has been recorded.", log);
26
16
  };
@@ -44,7 +34,12 @@ const access = (accessRequests, options = {}) => {
44
34
  accessRequests: requests,
45
35
  jwt: identity
46
36
  });
47
- if (verifyError || !verifyData?.isVerified) {
37
+ if (verifyError || !verifyData) {
38
+ throw new HTTPException(503, {
39
+ message: "Access verification unavailable"
40
+ });
41
+ }
42
+ if (!verifyData.isVerified) {
48
43
  throw new HTTPException(403, {
49
44
  message: options.errorMessage || "Forbidden"
50
45
  });
@@ -1,3 +1,4 @@
1
+ import { z } from 'zod';
1
2
  import superjson from 'superjson';
2
3
 
3
4
  const uuidv4 = () => crypto.randomUUID();
@@ -60,6 +61,16 @@ function summarizeBinary(value) {
60
61
  return void 0;
61
62
  }
62
63
 
64
+ const validateBearerScheme = (header) => {
65
+ return header.startsWith("Bearer ") && header.length > 7 && !header.slice(7).includes(" ");
66
+ };
67
+ const extractBearerToken = (header) => {
68
+ return header.slice(7).trim();
69
+ };
70
+ const validateBearerToken = (bearerToken) => {
71
+ return z.jwt().safeParse(bearerToken).success;
72
+ };
73
+
63
74
  const DEFAULT_LOG_BOUND_LIMITS = {
64
75
  maxStringLength: 2048,
65
76
  maxArrayLength: 100,
@@ -158,4 +169,4 @@ function serializeLog(data, limits = DEFAULT_LOG_BOUND_LIMITS) {
158
169
  }
159
170
  }
160
171
 
161
- export { serializeLog as a, uuidv5 as b, summarizeBinary as s, uuidv4 as u };
172
+ export { serializeLog as a, uuidv5 as b, validateBearerToken as c, extractBearerToken as e, summarizeBinary as s, uuidv4 as u, validateBearerScheme as v };
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@develit-io/backend-sdk",
3
- "version": "12.5.0",
3
+ "version": "12.6.0",
4
4
  "description": "Develit Backend SDK",
5
5
  "author": "Develit.io",
6
6
  "license": "ISC",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/develit-io/develit-sdk.git"
10
+ },
7
11
  "type": "module",
8
12
  "scripts": {
9
13
  "build": "unbuild",
@@ -34,7 +38,7 @@
34
38
  "dist"
35
39
  ],
36
40
  "dependencies": {
37
- "@cloudflare/workers-types": "^4.20260217.0",
41
+ "@cloudflare/workers-types": "^4.20260217.0 || ^5.0.0",
38
42
  "cloudflare": "^5.2.0",
39
43
  "comment-json": "^4.5.1",
40
44
  "superjson": "^2.2.5"