@develit-io/backend-sdk 9.11.12 → 9.11.14
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/middlewares.d.mts +84 -0
- package/dist/middlewares.d.ts +84 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/middlewares.d.mts
CHANGED
|
@@ -15,18 +15,102 @@ interface AccessMiddlewareOptions {
|
|
|
15
15
|
errorMessage?: string;
|
|
16
16
|
}
|
|
17
17
|
type AccessRequestResolver<TScope extends string = string> = ScopeCondition<TScope> | ((context: Context) => ScopeCondition<TScope>);
|
|
18
|
+
/**
|
|
19
|
+
* Middleware that enforces role-based access control (RBAC).
|
|
20
|
+
*
|
|
21
|
+
* Verifies the authenticated user has the required scopes/permissions by calling
|
|
22
|
+
* the `RBAC_SERVICE` binding. Supports static scope definitions or a dynamic
|
|
23
|
+
* resolver function that receives the Hono context.
|
|
24
|
+
*
|
|
25
|
+
* @requires `RBAC_SERVICE` binding.
|
|
26
|
+
* @requires `identity` context variable (set by the `jwt` middleware).
|
|
27
|
+
* @param accessRequests - Scope conditions to verify, or a function that returns them.
|
|
28
|
+
* @param options.errorMessage - Custom 403 error message.
|
|
29
|
+
* @param Can be disabled by setting `MIDDLEWARE_ACCESS_DISABLED` env var.
|
|
30
|
+
* @throws {HTTPException} 403 if the user does not have the required access.
|
|
31
|
+
*/
|
|
18
32
|
declare const access: <TScope extends string = string>(accessRequests: AccessRequestResolver<TScope>, options?: AccessMiddlewareOptions) => MiddlewareHandler;
|
|
19
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Middleware that authenticates requests using an admin API key.
|
|
36
|
+
*
|
|
37
|
+
* Expects a `Bearer <token>` in the `Authorization` header and validates it
|
|
38
|
+
* against the `GATEWAY_ADMIN_API_KEY` secret stored in the Secrets Store binding.
|
|
39
|
+
*
|
|
40
|
+
* @requires `SECRETS_STORE` binding with a `GATEWAY_ADMIN_API_KEY` secret provisioned.
|
|
41
|
+
* @throws {HTTPException} 401 if the token is missing or does not match.
|
|
42
|
+
*/
|
|
20
43
|
declare const adminAuth: MiddlewareHandler;
|
|
21
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Middleware that ensures request idempotency using Cloudflare KV.
|
|
47
|
+
*
|
|
48
|
+
* Expects an `x-idempotency-key` header. If the key already exists in KV,
|
|
49
|
+
* the request is rejected as a duplicate (409). Otherwise the key is stored
|
|
50
|
+
* with a 3-day TTL and the request proceeds. Sets `idempotency.key` in context.
|
|
51
|
+
*
|
|
52
|
+
* @requires `IDEMPOTENCY_KV` KV namespace binding.
|
|
53
|
+
* @param Can be disabled by setting `MIDDLEWARE_IDEMPOTENCY_DISABLED` env var.
|
|
54
|
+
* @throws {HTTPException} 401 if the `x-idempotency-key` header is missing.
|
|
55
|
+
* @throws {HTTPException} 409 if the idempotency key has already been used.
|
|
56
|
+
*/
|
|
22
57
|
declare const idempotency: () => MiddlewareHandler;
|
|
23
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Middleware that authenticates requests using a JWT access token.
|
|
61
|
+
*
|
|
62
|
+
* Extracts the Bearer token from the `Authorization` header, verifies it via
|
|
63
|
+
* the `AUTH_SERVICE` binding, and populates `identity` in the context with user
|
|
64
|
+
* details (id, email, role, organizationId, exchangeOfficeId).
|
|
65
|
+
*
|
|
66
|
+
* @requires `AUTH_SERVICE` binding.
|
|
67
|
+
* @param Can be disabled by setting `MIDDLEWARE_JWT_DISABLED` env var.
|
|
68
|
+
* @throws {HTTPException} 401 if the header is missing, not a Bearer scheme, or token is invalid.
|
|
69
|
+
* @throws {HTTPException} 422 if user metadata is missing organizationId/exchangeOfficeId.
|
|
70
|
+
*/
|
|
24
71
|
declare const jwt: () => MiddlewareHandler;
|
|
25
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Middleware that enforces IP-based access control per organization.
|
|
75
|
+
*
|
|
76
|
+
* Retrieves the caller's IP from request headers and checks it against
|
|
77
|
+
* the organization's authorized IP list via the `ORGANIZATION_SERVICE` binding.
|
|
78
|
+
*
|
|
79
|
+
* @requires `ORGANIZATION_SERVICE` binding.
|
|
80
|
+
* @requires `ENVIRONMENT` binding.
|
|
81
|
+
* @param Can be disabled by setting `MIDDLEWARE_IP_DISABLED` env var.
|
|
82
|
+
* @throws {HTTPException} 401 if the IP address cannot be determined or organization ID is missing.
|
|
83
|
+
* @throws {HTTPException} 404 if the organization is not found or the IP is not authorized.
|
|
84
|
+
*/
|
|
26
85
|
declare const ip: () => MiddlewareHandler;
|
|
27
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Middleware that logs incoming requests and outgoing responses.
|
|
89
|
+
*
|
|
90
|
+
* Logs request/response details to the console and optionally sends audit log
|
|
91
|
+
* entries to the `ACTIVITY_SERVICE` binding. Sets `auditLog.requestId` in context
|
|
92
|
+
* for correlating request/response audit log pairs.
|
|
93
|
+
*
|
|
94
|
+
* @requires `ACTIVITY_SERVICE` binding (when audit logging is enabled).
|
|
95
|
+
* @requires `ENVIRONMENT` binding.
|
|
96
|
+
* @param Can be disabled by setting `MIDDLEWARE_LOGGER_DISABLED` env var.
|
|
97
|
+
* @param Audit logging can be separately disabled via `MIDDLEWARE_LOGGER_AUDITLOG_DISABLED` env var.
|
|
98
|
+
*/
|
|
28
99
|
declare const logger: () => MiddlewareHandler;
|
|
29
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Middleware that verifies the request payload signature.
|
|
103
|
+
*
|
|
104
|
+
* Expects `x-signature` and `x-signature-key` headers. Looks up the corresponding
|
|
105
|
+
* public key from the organization's signature keys via the `ORGANIZATION_SERVICE` binding
|
|
106
|
+
* and verifies the payload against it.
|
|
107
|
+
*
|
|
108
|
+
* @requires `ORGANIZATION_SERVICE` binding.
|
|
109
|
+
* @requires `ENVIRONMENT` binding.
|
|
110
|
+
* @param Can be disabled by setting `MIDDLEWARE_SIGNATURE_DISABLED` env var.
|
|
111
|
+
* @throws {HTTPException} 401 if signature headers are missing or verification fails.
|
|
112
|
+
* @throws {HTTPException} 404 if the organization or signature key is not found.
|
|
113
|
+
*/
|
|
30
114
|
declare const signature: () => MiddlewareHandler;
|
|
31
115
|
|
|
32
116
|
export { access, adminAuth, idempotency, ip, jwt, logger, signature };
|
package/dist/middlewares.d.ts
CHANGED
|
@@ -15,18 +15,102 @@ interface AccessMiddlewareOptions {
|
|
|
15
15
|
errorMessage?: string;
|
|
16
16
|
}
|
|
17
17
|
type AccessRequestResolver<TScope extends string = string> = ScopeCondition<TScope> | ((context: Context) => ScopeCondition<TScope>);
|
|
18
|
+
/**
|
|
19
|
+
* Middleware that enforces role-based access control (RBAC).
|
|
20
|
+
*
|
|
21
|
+
* Verifies the authenticated user has the required scopes/permissions by calling
|
|
22
|
+
* the `RBAC_SERVICE` binding. Supports static scope definitions or a dynamic
|
|
23
|
+
* resolver function that receives the Hono context.
|
|
24
|
+
*
|
|
25
|
+
* @requires `RBAC_SERVICE` binding.
|
|
26
|
+
* @requires `identity` context variable (set by the `jwt` middleware).
|
|
27
|
+
* @param accessRequests - Scope conditions to verify, or a function that returns them.
|
|
28
|
+
* @param options.errorMessage - Custom 403 error message.
|
|
29
|
+
* @param Can be disabled by setting `MIDDLEWARE_ACCESS_DISABLED` env var.
|
|
30
|
+
* @throws {HTTPException} 403 if the user does not have the required access.
|
|
31
|
+
*/
|
|
18
32
|
declare const access: <TScope extends string = string>(accessRequests: AccessRequestResolver<TScope>, options?: AccessMiddlewareOptions) => MiddlewareHandler;
|
|
19
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Middleware that authenticates requests using an admin API key.
|
|
36
|
+
*
|
|
37
|
+
* Expects a `Bearer <token>` in the `Authorization` header and validates it
|
|
38
|
+
* against the `GATEWAY_ADMIN_API_KEY` secret stored in the Secrets Store binding.
|
|
39
|
+
*
|
|
40
|
+
* @requires `SECRETS_STORE` binding with a `GATEWAY_ADMIN_API_KEY` secret provisioned.
|
|
41
|
+
* @throws {HTTPException} 401 if the token is missing or does not match.
|
|
42
|
+
*/
|
|
20
43
|
declare const adminAuth: MiddlewareHandler;
|
|
21
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Middleware that ensures request idempotency using Cloudflare KV.
|
|
47
|
+
*
|
|
48
|
+
* Expects an `x-idempotency-key` header. If the key already exists in KV,
|
|
49
|
+
* the request is rejected as a duplicate (409). Otherwise the key is stored
|
|
50
|
+
* with a 3-day TTL and the request proceeds. Sets `idempotency.key` in context.
|
|
51
|
+
*
|
|
52
|
+
* @requires `IDEMPOTENCY_KV` KV namespace binding.
|
|
53
|
+
* @param Can be disabled by setting `MIDDLEWARE_IDEMPOTENCY_DISABLED` env var.
|
|
54
|
+
* @throws {HTTPException} 401 if the `x-idempotency-key` header is missing.
|
|
55
|
+
* @throws {HTTPException} 409 if the idempotency key has already been used.
|
|
56
|
+
*/
|
|
22
57
|
declare const idempotency: () => MiddlewareHandler;
|
|
23
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Middleware that authenticates requests using a JWT access token.
|
|
61
|
+
*
|
|
62
|
+
* Extracts the Bearer token from the `Authorization` header, verifies it via
|
|
63
|
+
* the `AUTH_SERVICE` binding, and populates `identity` in the context with user
|
|
64
|
+
* details (id, email, role, organizationId, exchangeOfficeId).
|
|
65
|
+
*
|
|
66
|
+
* @requires `AUTH_SERVICE` binding.
|
|
67
|
+
* @param Can be disabled by setting `MIDDLEWARE_JWT_DISABLED` env var.
|
|
68
|
+
* @throws {HTTPException} 401 if the header is missing, not a Bearer scheme, or token is invalid.
|
|
69
|
+
* @throws {HTTPException} 422 if user metadata is missing organizationId/exchangeOfficeId.
|
|
70
|
+
*/
|
|
24
71
|
declare const jwt: () => MiddlewareHandler;
|
|
25
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Middleware that enforces IP-based access control per organization.
|
|
75
|
+
*
|
|
76
|
+
* Retrieves the caller's IP from request headers and checks it against
|
|
77
|
+
* the organization's authorized IP list via the `ORGANIZATION_SERVICE` binding.
|
|
78
|
+
*
|
|
79
|
+
* @requires `ORGANIZATION_SERVICE` binding.
|
|
80
|
+
* @requires `ENVIRONMENT` binding.
|
|
81
|
+
* @param Can be disabled by setting `MIDDLEWARE_IP_DISABLED` env var.
|
|
82
|
+
* @throws {HTTPException} 401 if the IP address cannot be determined or organization ID is missing.
|
|
83
|
+
* @throws {HTTPException} 404 if the organization is not found or the IP is not authorized.
|
|
84
|
+
*/
|
|
26
85
|
declare const ip: () => MiddlewareHandler;
|
|
27
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Middleware that logs incoming requests and outgoing responses.
|
|
89
|
+
*
|
|
90
|
+
* Logs request/response details to the console and optionally sends audit log
|
|
91
|
+
* entries to the `ACTIVITY_SERVICE` binding. Sets `auditLog.requestId` in context
|
|
92
|
+
* for correlating request/response audit log pairs.
|
|
93
|
+
*
|
|
94
|
+
* @requires `ACTIVITY_SERVICE` binding (when audit logging is enabled).
|
|
95
|
+
* @requires `ENVIRONMENT` binding.
|
|
96
|
+
* @param Can be disabled by setting `MIDDLEWARE_LOGGER_DISABLED` env var.
|
|
97
|
+
* @param Audit logging can be separately disabled via `MIDDLEWARE_LOGGER_AUDITLOG_DISABLED` env var.
|
|
98
|
+
*/
|
|
28
99
|
declare const logger: () => MiddlewareHandler;
|
|
29
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Middleware that verifies the request payload signature.
|
|
103
|
+
*
|
|
104
|
+
* Expects `x-signature` and `x-signature-key` headers. Looks up the corresponding
|
|
105
|
+
* public key from the organization's signature keys via the `ORGANIZATION_SERVICE` binding
|
|
106
|
+
* and verifies the payload against it.
|
|
107
|
+
*
|
|
108
|
+
* @requires `ORGANIZATION_SERVICE` binding.
|
|
109
|
+
* @requires `ENVIRONMENT` binding.
|
|
110
|
+
* @param Can be disabled by setting `MIDDLEWARE_SIGNATURE_DISABLED` env var.
|
|
111
|
+
* @throws {HTTPException} 401 if signature headers are missing or verification fails.
|
|
112
|
+
* @throws {HTTPException} 404 if the organization or signature key is not found.
|
|
113
|
+
*/
|
|
30
114
|
declare const signature: () => MiddlewareHandler;
|
|
31
115
|
|
|
32
116
|
export { access, adminAuth, idempotency, ip, jwt, logger, signature };
|