@develit-io/backend-sdk 5.38.0 → 5.39.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 +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.mjs +95 -22
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -36,6 +36,9 @@ declare const bankAccount: {
|
|
|
36
36
|
countryCode: drizzle_orm.NotNull<drizzle_orm_sqlite_core.SQLiteTextBuilderInitial<"country_code", ["AF" | "AL" | "DZ" | "AS" | "AD" | "AO" | "AG" | "AR" | "AM" | "AW" | "AU" | "AT" | "AZ" | "BS" | "BH" | "BD" | "BB" | "BY" | "BE" | "BZ" | "BJ" | "BO" | "BQ" | "BA" | "BW" | "BR" | "IO" | "VG" | "BG" | "BF" | "BI" | "KH" | "CM" | "CA" | "CV" | "CF" | "TD" | "CL" | "CN" | "CO" | "KM" | "CK" | "CR" | "HR" | "CW" | "CY" | "CZ" | "CD" | "DK" | "DJ" | "DM" | "DO" | "TL" | "EC" | "EG" | "SV" | "GQ" | "ER" | "EE" | "ET" | "FO" | "FJ" | "FI" | "FR" | "GF" | "PF" | "GA" | "GM" | "GE" | "DE" | "GH" | "GR" | "GD" | "GP" | "GU" | "GT" | "GN" | "GW" | "GY" | "HT" | "HN" | "HU" | "IS" | "IN" | "ID" | "IR" | "IQ" | "IE" | "IM" | "IL" | "IT" | "CI" | "JM" | "JP" | "JE" | "JO" | "KZ" | "KE" | "KI" | "XK" | "KW" | "KG" | "LA" | "LV" | "LB" | "LS" | "LR" | "LI" | "LT" | "LU" | "MK" | "MG" | "MW" | "MY" | "MV" | "ML" | "MT" | "MQ" | "MR" | "MU" | "MX" | "FM" | "MD" | "MC" | "MN" | "ME" | "MS" | "MA" | "MZ" | "NA" | "NP" | "NL" | "NZ" | "NI" | "NE" | "NG" | "NU" | "NF" | "KP" | "NO" | "OM" | "PK" | "PS" | "PA" | "PG" | "PY" | "PE" | "PH" | "PL" | "PT" | "PR" | "QA" | "CG" | "RE" | "RO" | "RU" | "RW" | "BL" | "KN" | "LC" | "MF" | "VC" | "WS" | "SM" | "SA" | "SN" | "RS" | "SC" | "SL" | "SG" | "SX" | "SK" | "SI" | "SO" | "ZA" | "KR" | "SS" | "ES" | "LK" | "SD" | "SR" | "SJ" | "SZ" | "SE" | "CH" | "TW" | "TJ" | "TZ" | "TH" | "TG" | "TO" | "TT" | "TN" | "TR" | "TM" | "UM" | "VI" | "UG" | "UA" | "AE" | "GB" | "UZ" | "VU" | "VE" | "VN" | "WF" | "EH" | "YE" | "ZM" | "ZW", ...("AF" | "AL" | "DZ" | "AS" | "AD" | "AO" | "AG" | "AR" | "AM" | "AW" | "AU" | "AT" | "AZ" | "BS" | "BH" | "BD" | "BB" | "BY" | "BE" | "BZ" | "BJ" | "BO" | "BQ" | "BA" | "BW" | "BR" | "IO" | "VG" | "BG" | "BF" | "BI" | "KH" | "CM" | "CA" | "CV" | "CF" | "TD" | "CL" | "CN" | "CO" | "KM" | "CK" | "CR" | "HR" | "CW" | "CY" | "CZ" | "CD" | "DK" | "DJ" | "DM" | "DO" | "TL" | "EC" | "EG" | "SV" | "GQ" | "ER" | "EE" | "ET" | "FO" | "FJ" | "FI" | "FR" | "GF" | "PF" | "GA" | "GM" | "GE" | "DE" | "GH" | "GR" | "GD" | "GP" | "GU" | "GT" | "GN" | "GW" | "GY" | "HT" | "HN" | "HU" | "IS" | "IN" | "ID" | "IR" | "IQ" | "IE" | "IM" | "IL" | "IT" | "CI" | "JM" | "JP" | "JE" | "JO" | "KZ" | "KE" | "KI" | "XK" | "KW" | "KG" | "LA" | "LV" | "LB" | "LS" | "LR" | "LI" | "LT" | "LU" | "MK" | "MG" | "MW" | "MY" | "MV" | "ML" | "MT" | "MQ" | "MR" | "MU" | "MX" | "FM" | "MD" | "MC" | "MN" | "ME" | "MS" | "MA" | "MZ" | "NA" | "NP" | "NL" | "NZ" | "NI" | "NE" | "NG" | "NU" | "NF" | "KP" | "NO" | "OM" | "PK" | "PS" | "PA" | "PG" | "PY" | "PE" | "PH" | "PL" | "PT" | "PR" | "QA" | "CG" | "RE" | "RO" | "RU" | "RW" | "BL" | "KN" | "LC" | "MF" | "VC" | "WS" | "SM" | "SA" | "SN" | "RS" | "SC" | "SL" | "SG" | "SX" | "SK" | "SI" | "SO" | "ZA" | "KR" | "SS" | "ES" | "LK" | "SD" | "SR" | "SJ" | "SZ" | "SE" | "CH" | "TW" | "TJ" | "TZ" | "TH" | "TG" | "TO" | "TT" | "TN" | "TR" | "TM" | "UM" | "VI" | "UG" | "UA" | "AE" | "GB" | "UZ" | "VU" | "VE" | "VN" | "WF" | "EH" | "YE" | "ZM" | "ZW")[]], number | undefined>>;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
declare const USER_ROLES: readonly ["OWNER", "ADMIN", "MEMBER"];
|
|
40
|
+
type UserRole = (typeof USER_ROLES)[number];
|
|
41
|
+
|
|
39
42
|
declare const composeWranglerBase: ({ project, name, }: {
|
|
40
43
|
project: string;
|
|
41
44
|
name: string;
|
|
@@ -61,6 +64,8 @@ declare const idempotency: <T extends {
|
|
|
61
64
|
IDEMPOTENCY_KV: KVNamespace;
|
|
62
65
|
}>() => MiddlewareHandler;
|
|
63
66
|
|
|
67
|
+
declare const jwt: <TAuthService, TJwtPayload>() => MiddlewareHandler;
|
|
68
|
+
|
|
64
69
|
declare const logger: () => MiddlewareHandler;
|
|
65
70
|
|
|
66
71
|
declare const ENVIRONMENT: string[];
|
|
@@ -73,6 +78,13 @@ interface AuditLogPayload<T> {
|
|
|
73
78
|
entityId?: string;
|
|
74
79
|
}
|
|
75
80
|
|
|
81
|
+
interface AuthUser {
|
|
82
|
+
id: string;
|
|
83
|
+
organizationId: string;
|
|
84
|
+
email: string;
|
|
85
|
+
role: UserRole;
|
|
86
|
+
}
|
|
87
|
+
|
|
76
88
|
declare const ibanSchema: z$1.ZodString;
|
|
77
89
|
declare const bicSchema: z$1.ZodString;
|
|
78
90
|
declare const bankAccountMetadataSchema: z$1.ZodObject<{
|
|
@@ -173,6 +185,10 @@ interface IdempotencyVariables {
|
|
|
173
185
|
key: string;
|
|
174
186
|
};
|
|
175
187
|
}
|
|
188
|
+
interface UserVariables<T> {
|
|
189
|
+
user: AuthUser;
|
|
190
|
+
jwt: T;
|
|
191
|
+
}
|
|
176
192
|
|
|
177
193
|
declare const paginationQuerySchema: z.$ZodObject<Readonly<Readonly<{
|
|
178
194
|
[k: string]: z.$ZodType<unknown, unknown, z.$ZodTypeInternals<unknown, unknown>>;
|
|
@@ -507,5 +523,5 @@ interface WithRetryCounterOptions {
|
|
|
507
523
|
type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
|
|
508
524
|
declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
|
|
509
525
|
|
|
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 };
|
|
526
|
+
export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, 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, jwt, logger, paginationQuerySchema, paginationSchema, service, useFetch, useResult, useResultSync, uuidv4 };
|
|
527
|
+
export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, AuthUser, BankAccountMetadata, BaseEvent, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IdempotencyVariables, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, UserRole, UserVariables, ValidatedInput };
|
package/dist/index.d.ts
CHANGED
|
@@ -36,6 +36,9 @@ declare const bankAccount: {
|
|
|
36
36
|
countryCode: drizzle_orm.NotNull<drizzle_orm_sqlite_core.SQLiteTextBuilderInitial<"country_code", ["AF" | "AL" | "DZ" | "AS" | "AD" | "AO" | "AG" | "AR" | "AM" | "AW" | "AU" | "AT" | "AZ" | "BS" | "BH" | "BD" | "BB" | "BY" | "BE" | "BZ" | "BJ" | "BO" | "BQ" | "BA" | "BW" | "BR" | "IO" | "VG" | "BG" | "BF" | "BI" | "KH" | "CM" | "CA" | "CV" | "CF" | "TD" | "CL" | "CN" | "CO" | "KM" | "CK" | "CR" | "HR" | "CW" | "CY" | "CZ" | "CD" | "DK" | "DJ" | "DM" | "DO" | "TL" | "EC" | "EG" | "SV" | "GQ" | "ER" | "EE" | "ET" | "FO" | "FJ" | "FI" | "FR" | "GF" | "PF" | "GA" | "GM" | "GE" | "DE" | "GH" | "GR" | "GD" | "GP" | "GU" | "GT" | "GN" | "GW" | "GY" | "HT" | "HN" | "HU" | "IS" | "IN" | "ID" | "IR" | "IQ" | "IE" | "IM" | "IL" | "IT" | "CI" | "JM" | "JP" | "JE" | "JO" | "KZ" | "KE" | "KI" | "XK" | "KW" | "KG" | "LA" | "LV" | "LB" | "LS" | "LR" | "LI" | "LT" | "LU" | "MK" | "MG" | "MW" | "MY" | "MV" | "ML" | "MT" | "MQ" | "MR" | "MU" | "MX" | "FM" | "MD" | "MC" | "MN" | "ME" | "MS" | "MA" | "MZ" | "NA" | "NP" | "NL" | "NZ" | "NI" | "NE" | "NG" | "NU" | "NF" | "KP" | "NO" | "OM" | "PK" | "PS" | "PA" | "PG" | "PY" | "PE" | "PH" | "PL" | "PT" | "PR" | "QA" | "CG" | "RE" | "RO" | "RU" | "RW" | "BL" | "KN" | "LC" | "MF" | "VC" | "WS" | "SM" | "SA" | "SN" | "RS" | "SC" | "SL" | "SG" | "SX" | "SK" | "SI" | "SO" | "ZA" | "KR" | "SS" | "ES" | "LK" | "SD" | "SR" | "SJ" | "SZ" | "SE" | "CH" | "TW" | "TJ" | "TZ" | "TH" | "TG" | "TO" | "TT" | "TN" | "TR" | "TM" | "UM" | "VI" | "UG" | "UA" | "AE" | "GB" | "UZ" | "VU" | "VE" | "VN" | "WF" | "EH" | "YE" | "ZM" | "ZW", ...("AF" | "AL" | "DZ" | "AS" | "AD" | "AO" | "AG" | "AR" | "AM" | "AW" | "AU" | "AT" | "AZ" | "BS" | "BH" | "BD" | "BB" | "BY" | "BE" | "BZ" | "BJ" | "BO" | "BQ" | "BA" | "BW" | "BR" | "IO" | "VG" | "BG" | "BF" | "BI" | "KH" | "CM" | "CA" | "CV" | "CF" | "TD" | "CL" | "CN" | "CO" | "KM" | "CK" | "CR" | "HR" | "CW" | "CY" | "CZ" | "CD" | "DK" | "DJ" | "DM" | "DO" | "TL" | "EC" | "EG" | "SV" | "GQ" | "ER" | "EE" | "ET" | "FO" | "FJ" | "FI" | "FR" | "GF" | "PF" | "GA" | "GM" | "GE" | "DE" | "GH" | "GR" | "GD" | "GP" | "GU" | "GT" | "GN" | "GW" | "GY" | "HT" | "HN" | "HU" | "IS" | "IN" | "ID" | "IR" | "IQ" | "IE" | "IM" | "IL" | "IT" | "CI" | "JM" | "JP" | "JE" | "JO" | "KZ" | "KE" | "KI" | "XK" | "KW" | "KG" | "LA" | "LV" | "LB" | "LS" | "LR" | "LI" | "LT" | "LU" | "MK" | "MG" | "MW" | "MY" | "MV" | "ML" | "MT" | "MQ" | "MR" | "MU" | "MX" | "FM" | "MD" | "MC" | "MN" | "ME" | "MS" | "MA" | "MZ" | "NA" | "NP" | "NL" | "NZ" | "NI" | "NE" | "NG" | "NU" | "NF" | "KP" | "NO" | "OM" | "PK" | "PS" | "PA" | "PG" | "PY" | "PE" | "PH" | "PL" | "PT" | "PR" | "QA" | "CG" | "RE" | "RO" | "RU" | "RW" | "BL" | "KN" | "LC" | "MF" | "VC" | "WS" | "SM" | "SA" | "SN" | "RS" | "SC" | "SL" | "SG" | "SX" | "SK" | "SI" | "SO" | "ZA" | "KR" | "SS" | "ES" | "LK" | "SD" | "SR" | "SJ" | "SZ" | "SE" | "CH" | "TW" | "TJ" | "TZ" | "TH" | "TG" | "TO" | "TT" | "TN" | "TR" | "TM" | "UM" | "VI" | "UG" | "UA" | "AE" | "GB" | "UZ" | "VU" | "VE" | "VN" | "WF" | "EH" | "YE" | "ZM" | "ZW")[]], number | undefined>>;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
declare const USER_ROLES: readonly ["OWNER", "ADMIN", "MEMBER"];
|
|
40
|
+
type UserRole = (typeof USER_ROLES)[number];
|
|
41
|
+
|
|
39
42
|
declare const composeWranglerBase: ({ project, name, }: {
|
|
40
43
|
project: string;
|
|
41
44
|
name: string;
|
|
@@ -61,6 +64,8 @@ declare const idempotency: <T extends {
|
|
|
61
64
|
IDEMPOTENCY_KV: KVNamespace;
|
|
62
65
|
}>() => MiddlewareHandler;
|
|
63
66
|
|
|
67
|
+
declare const jwt: <TAuthService, TJwtPayload>() => MiddlewareHandler;
|
|
68
|
+
|
|
64
69
|
declare const logger: () => MiddlewareHandler;
|
|
65
70
|
|
|
66
71
|
declare const ENVIRONMENT: string[];
|
|
@@ -73,6 +78,13 @@ interface AuditLogPayload<T> {
|
|
|
73
78
|
entityId?: string;
|
|
74
79
|
}
|
|
75
80
|
|
|
81
|
+
interface AuthUser {
|
|
82
|
+
id: string;
|
|
83
|
+
organizationId: string;
|
|
84
|
+
email: string;
|
|
85
|
+
role: UserRole;
|
|
86
|
+
}
|
|
87
|
+
|
|
76
88
|
declare const ibanSchema: z$1.ZodString;
|
|
77
89
|
declare const bicSchema: z$1.ZodString;
|
|
78
90
|
declare const bankAccountMetadataSchema: z$1.ZodObject<{
|
|
@@ -173,6 +185,10 @@ interface IdempotencyVariables {
|
|
|
173
185
|
key: string;
|
|
174
186
|
};
|
|
175
187
|
}
|
|
188
|
+
interface UserVariables<T> {
|
|
189
|
+
user: AuthUser;
|
|
190
|
+
jwt: T;
|
|
191
|
+
}
|
|
176
192
|
|
|
177
193
|
declare const paginationQuerySchema: z.$ZodObject<Readonly<Readonly<{
|
|
178
194
|
[k: string]: z.$ZodType<unknown, unknown, z.$ZodTypeInternals<unknown, unknown>>;
|
|
@@ -507,5 +523,5 @@ interface WithRetryCounterOptions {
|
|
|
507
523
|
type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
|
|
508
524
|
declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
|
|
509
525
|
|
|
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 };
|
|
526
|
+
export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, 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, jwt, logger, paginationQuerySchema, paginationSchema, service, useFetch, useResult, useResultSync, uuidv4 };
|
|
527
|
+
export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, AuthUser, BankAccountMetadata, BaseEvent, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IdempotencyVariables, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, UserRole, UserVariables, ValidatedInput };
|
package/dist/index.mjs
CHANGED
|
@@ -3,12 +3,12 @@ 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
5
|
import { createError } from 'h3';
|
|
6
|
+
import { z as z$1 } from 'zod';
|
|
6
7
|
import 'cloudflare';
|
|
7
8
|
import fs from 'node:fs';
|
|
8
9
|
import crypto$1 from 'node:crypto';
|
|
9
10
|
import path from 'node:path';
|
|
10
11
|
import { parse } from 'comment-json';
|
|
11
|
-
import { z as z$1 } from 'zod';
|
|
12
12
|
import * as z from 'zod/v4/core';
|
|
13
13
|
import 'http-status-codes';
|
|
14
14
|
import superjson from 'superjson';
|
|
@@ -36,6 +36,8 @@ const bankAccount = {
|
|
|
36
36
|
countryCode: text("country_code", { enum: COUNTRY_CODES_2 }).notNull()
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
const USER_ROLES = ["OWNER", "ADMIN", "MEMBER"];
|
|
40
|
+
|
|
39
41
|
const ENVIRONMENT = ["dev", "test", "staging", "production"];
|
|
40
42
|
|
|
41
43
|
const COMPATIBILITY_DATE = "2025-06-04";
|
|
@@ -98,26 +100,6 @@ const idempotency = () => {
|
|
|
98
100
|
});
|
|
99
101
|
};
|
|
100
102
|
|
|
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
|
-
};
|
|
120
|
-
|
|
121
103
|
const handleActionResponse = ({
|
|
122
104
|
error,
|
|
123
105
|
status,
|
|
@@ -270,6 +252,16 @@ function createAuditLogWriter(table) {
|
|
|
270
252
|
};
|
|
271
253
|
}
|
|
272
254
|
|
|
255
|
+
const validateBearerScheme = (header) => {
|
|
256
|
+
return header.startsWith("Bearer ") && header.length > 7 && !header.slice(7).includes(" ");
|
|
257
|
+
};
|
|
258
|
+
const extractBearerToken = (header) => {
|
|
259
|
+
return header.slice(7).trim();
|
|
260
|
+
};
|
|
261
|
+
const validateBearerToken = (bearerToken) => {
|
|
262
|
+
return z$1.jwt().safeParse(bearerToken).success;
|
|
263
|
+
};
|
|
264
|
+
|
|
273
265
|
function first(rows) {
|
|
274
266
|
return rows.length > 0 ? rows[0] : void 0;
|
|
275
267
|
}
|
|
@@ -501,6 +493,87 @@ const getSecret = async (secretName, env) => {
|
|
|
501
493
|
return await secret.get();
|
|
502
494
|
};
|
|
503
495
|
|
|
496
|
+
const jwt = () => {
|
|
497
|
+
return createMiddleware(async (context, next) => {
|
|
498
|
+
const authorizationHeader = context.req.header("Authorization");
|
|
499
|
+
if (!authorizationHeader) {
|
|
500
|
+
return context.json(
|
|
501
|
+
{
|
|
502
|
+
message: `The 'Authorization' header must exist and must have a value.`
|
|
503
|
+
},
|
|
504
|
+
401
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
if (!validateBearerScheme(authorizationHeader)) {
|
|
508
|
+
return context.json(
|
|
509
|
+
{
|
|
510
|
+
message: `The 'Authorization' header value must use the Bearer scheme.`
|
|
511
|
+
},
|
|
512
|
+
401
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
const bearerToken = extractBearerToken(authorizationHeader);
|
|
516
|
+
if (!validateBearerToken(bearerToken)) {
|
|
517
|
+
return context.json(
|
|
518
|
+
{
|
|
519
|
+
message: `The Bearer token in the 'Authorization' header value must be a JWT.`
|
|
520
|
+
},
|
|
521
|
+
401
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
const authService = context.env.AUTH_SERVICE;
|
|
525
|
+
const { data, error } = await authService.verifyAccessToken({
|
|
526
|
+
accessToken: bearerToken
|
|
527
|
+
});
|
|
528
|
+
if (!data || error) {
|
|
529
|
+
return context.json(
|
|
530
|
+
{
|
|
531
|
+
message: "The JWT must contain valid user information."
|
|
532
|
+
},
|
|
533
|
+
401
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
const rawUserMetaDataString = data.payload.user.rawUserMetaData;
|
|
537
|
+
const rawUserMetaData = rawUserMetaDataString ? JSON.parse(rawUserMetaDataString) : null;
|
|
538
|
+
const organizationId = rawUserMetaData?.organizationId ?? null;
|
|
539
|
+
if (!organizationId) {
|
|
540
|
+
return context.json(
|
|
541
|
+
{
|
|
542
|
+
message: "User data integrity check failed."
|
|
543
|
+
},
|
|
544
|
+
422
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
context.set("user", {
|
|
548
|
+
email: data.payload.user.email,
|
|
549
|
+
role: data.payload.user.role,
|
|
550
|
+
organizationId
|
|
551
|
+
});
|
|
552
|
+
context.set("jwt", data.payload);
|
|
553
|
+
await next();
|
|
554
|
+
});
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
const composeRequestLog = async (request) => {
|
|
558
|
+
return {
|
|
559
|
+
method: request.method,
|
|
560
|
+
path: request.path,
|
|
561
|
+
query: request.query(),
|
|
562
|
+
headers: request.header(),
|
|
563
|
+
body: await request.json().catch(() => null)
|
|
564
|
+
};
|
|
565
|
+
};
|
|
566
|
+
const composeResponseLog = async (response, method, path) => {
|
|
567
|
+
return {
|
|
568
|
+
method,
|
|
569
|
+
path,
|
|
570
|
+
status: response.status,
|
|
571
|
+
statusText: response.statusText,
|
|
572
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
573
|
+
body: await response.json().catch(() => null)
|
|
574
|
+
};
|
|
575
|
+
};
|
|
576
|
+
|
|
504
577
|
const logger = () => {
|
|
505
578
|
return createMiddleware(async (context, next) => {
|
|
506
579
|
const requestLog = await composeRequestLog(context.req);
|
|
@@ -758,4 +831,4 @@ function develitWorker(Worker) {
|
|
|
758
831
|
return DevelitWorker;
|
|
759
832
|
}
|
|
760
833
|
|
|
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 };
|
|
834
|
+
export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, 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, jwt, logger, paginationQuerySchema, paginationSchema, service, useFetch, useResult, useResultSync, uuidv4 };
|