@rexezuge/http 1.10.0 → 1.12.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/README.md +182 -12
- package/dist/ErrorMapper.d.ts +65 -10
- package/dist/ErrorMapper.d.ts.map +1 -1
- package/dist/ErrorMapper.js +1 -1
- package/dist/ErrorMapper.js.map +3 -3
- package/dist/errorClassification.d.ts +44 -0
- package/dist/errorClassification.d.ts.map +1 -0
- package/dist/errorClassification.js +1 -0
- package/dist/errorClassification.js.map +7 -0
- package/dist/hono/FamilyRoute.d.ts +56 -0
- package/dist/hono/FamilyRoute.d.ts.map +1 -0
- package/dist/hono/FamilyRoute.js +1 -0
- package/dist/hono/FamilyRoute.js.map +7 -0
- package/dist/hono/auth.d.ts +91 -0
- package/dist/hono/auth.d.ts.map +1 -0
- package/dist/hono/auth.js +1 -0
- package/dist/hono/auth.js.map +7 -0
- package/dist/hono/bookmarks.d.ts +63 -0
- package/dist/hono/bookmarks.d.ts.map +1 -0
- package/dist/hono/bookmarks.js +1 -0
- package/dist/hono/bookmarks.js.map +7 -0
- package/dist/hono/contracts.d.ts +44 -0
- package/dist/hono/contracts.d.ts.map +1 -0
- package/dist/hono/contracts.js +1 -0
- package/dist/hono/contracts.js.map +7 -0
- package/dist/hono/createApiApp.d.ts +93 -0
- package/dist/hono/createApiApp.d.ts.map +1 -0
- package/dist/hono/createApiApp.js +1 -0
- package/dist/hono/createApiApp.js.map +7 -0
- package/dist/hono/docs.d.ts +41 -0
- package/dist/hono/docs.d.ts.map +1 -0
- package/dist/hono/docs.js +1 -0
- package/dist/hono/docs.js.map +7 -0
- package/dist/hono/errorHandler.d.ts +25 -0
- package/dist/hono/errorHandler.d.ts.map +1 -0
- package/dist/hono/errorHandler.js +1 -0
- package/dist/hono/errorHandler.js.map +7 -0
- package/dist/hono/hardening.d.ts +51 -0
- package/dist/hono/hardening.d.ts.map +1 -0
- package/dist/hono/hardening.js +1 -0
- package/dist/hono/hardening.js.map +7 -0
- package/dist/hono/index.d.ts +37 -0
- package/dist/hono/index.d.ts.map +1 -0
- package/dist/hono/index.js +1 -0
- package/dist/hono/index.js.map +7 -0
- package/dist/hono/rateLimits.d.ts +63 -0
- package/dist/hono/rateLimits.d.ts.map +1 -0
- package/dist/hono/rateLimits.js +1 -0
- package/dist/hono/rateLimits.js.map +7 -0
- package/dist/hono/requestContext.d.ts +28 -0
- package/dist/hono/requestContext.d.ts.map +1 -0
- package/dist/hono/requestContext.js +1 -0
- package/dist/hono/requestContext.js.map +7 -0
- package/dist/hono/types.d.ts +69 -0
- package/dist/hono/types.d.ts.map +1 -0
- package/dist/hono/types.js +1 -0
- package/dist/hono/types.js.map +7 -0
- package/dist/index.d.ts +20 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/dist/openApiErrors.d.ts +63 -0
- package/dist/openApiErrors.d.ts.map +1 -0
- package/dist/openApiErrors.js +1 -0
- package/dist/openApiErrors.js.map +7 -0
- package/dist/requestGuards.d.ts +52 -0
- package/dist/requestGuards.d.ts.map +1 -0
- package/dist/requestGuards.js +1 -0
- package/dist/requestGuards.js.map +7 -0
- package/dist/routeBase.d.ts.map +1 -1
- package/dist/routeBase.js +1 -1
- package/dist/routeBase.js.map +3 -3
- package/package.json +13 -5
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/requestGuards.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Request hardening and the CSRF/origin guard, framework-free.\n *\n * Converged from four shapes of the same idea:\n *\n * - AWS-AccessBridge `apps/api/src/middleware/RequestGuards.ts` — `Sec-Fetch-Site`\n * must be `same-origin`/`none`, and a mutating request with a body must declare\n * `application/json` (the one type a cross-site HTML form cannot send).\n * - Image-Host `apps/api/src/middleware/MiddlewareHandlers.ts` — `Origin`, else\n * `Referer`, must equal the request origin; **both absent is a rejection**.\n * - Pigeongram `packages/backend-services/src/session/origin.ts` — the allow-list\n * is the request origin plus configured origins (`ALLOWED_ORIGINS`,\n * `PAGES_ORIGIN`), and `Sec-Fetch-Site` alone never *admits* a request: a client\n * controls it as much as `Origin`.\n * - The `MAX_JSON_BODY_BYTES` ceilings in the Durable-DAV / Edge-Git route bases.\n *\n * Every check answers a `ServiceError` or `null` rather than a `Response`, so the\n * caller's error boundary renders it in its own dialect — the `/hono` middleware\n * throws it into `app.onError`, a Durable Object maps it itself.\n *\n * ## Why the strict defaults\n *\n * Cloudflare Access cookies are `SameSite=None` by design (they survive the\n * login redirect), so the cookie is not a CSRF defence. A browser always sends\n * `Origin` or `Referer` on a cross-origin mutation, so their joint absence means\n * a non-browser caller — which a cookie-authenticated surface does not serve\n * unless the app opts in with `allowMissingOrigin`.\n */\nimport { ForbiddenError, MethodNotAllowedError, PayloadTooLargeError, UnsupportedMediaTypeError } from '@rexezuge/errors';\nimport type { ServiceError } from '@rexezuge/errors';\n\nconst SAFE_METHODS: ReadonlySet<string> = new Set(['GET', 'HEAD', 'OPTIONS']);\n\n/**\nThe methods a family API answers; anything else is a 405 before routing.\n*/\nconst DEFAULT_ALLOWED_METHODS: readonly string[] = ['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'];\n\n/**\nOne MiB — the ceiling every converged route base used for a JSON body.\n*/\nconst DEFAULT_MAX_BODY_BYTES = 1_048_576;\n\nconst CROSS_SITE_MESSAGE = 'Cross-origin request rejected.';\n\ninterface OriginGuardOptions {\n /**\n * Origins trusted in addition to the request's own (a Pages origin, a custom\n * domain). Entries are normalised through `URL`; an unparseable one is dropped.\n */\n allowedOrigins?: readonly string[];\n /**\n * Admit a mutation that carries neither `Origin` nor `Referer`. Off by default:\n * see the file header. Turn it on only for a surface that also serves\n * non-browser callers with a non-cookie credential.\n */\n allowMissingOrigin?: boolean;\n}\n\nfunction isMutatingMethod(method: string): boolean {\n return !SAFE_METHODS.has(method.toUpperCase());\n}\n\nfunction originOf(value: string | null): string | null {\n const trimmed = value?.trim() ?? '';\n if (trimmed === '') return null;\n try {\n return new URL(trimmed).origin;\n } catch {\n return null;\n }\n}\n\n/**\nThe origin a request claims: `Origin`, else the `Referer`'s origin, else `null`.\n*/\nfunction requestOrigin(request: Request): string | null {\n return originOf(request.headers.get('origin')) ?? originOf(request.headers.get('referer'));\n}\n\n/**\n * The CSRF guard for a cookie-authenticated surface. Safe methods pass; a\n * mutation passes only when it is not declared cross-site and its origin is\n * allow-listed.\n */\nfunction checkOrigin(request: Request, options: OriginGuardOptions = {}): ServiceError | null {\n if (!isMutatingMethod(request.method)) return null;\n\n // A rejection signal only, never an admission: `same-site` is a sibling\n // subdomain, which is exactly the attacker a CSRF guard exists to stop.\n const fetchSite = request.headers.get('sec-fetch-site')?.trim().toLowerCase();\n if (fetchSite !== undefined && fetchSite !== 'same-origin' && fetchSite !== 'none') {\n return new ForbiddenError(CROSS_SITE_MESSAGE);\n }\n\n const origin = requestOrigin(request);\n if (origin === null) return options.allowMissingOrigin ? null : new ForbiddenError(CROSS_SITE_MESSAGE);\n\n const allowed = new Set<string>();\n const own = originOf(request.url);\n if (own !== null) allowed.add(own);\n for (const entry of options.allowedOrigins ?? []) {\n const normalized = originOf(entry);\n if (normalized !== null) allowed.add(normalized);\n }\n return allowed.has(origin) ? null : new ForbiddenError(CROSS_SITE_MESSAGE);\n}\n\n/**\nA method outside the allow-list is a 405, before any route or auth runs.\n*/\nfunction checkMethod(method: string, allowed: readonly string[] = DEFAULT_ALLOWED_METHODS): ServiceError | null {\n const upper = method.toUpperCase();\n return allowed.some((entry) => entry.toUpperCase() === upper) ? null : new MethodNotAllowedError();\n}\n\n/**\n * Whether a request carries a body, answered conservatively: only an explicit\n * `Content-Length: 0` is body-less. A request with neither framing header has an\n * *unknown* body, not an empty one (AWS-AccessBridge's rule).\n */\nfunction hasBody(request: Request): boolean {\n const length = request.headers.get('content-length');\n return length === null || length.trim() !== '0';\n}\n\n/**\n * A mutating request with a body must declare one of `allowed` (default\n * `application/json`). `text/plain` and form encodings are what a cross-site\n * form can send, so refusing them also closes content-type confusion.\n */\nfunction checkContentType(request: Request, allowed: readonly string[] = ['application/json']): ServiceError | null {\n if (!isMutatingMethod(request.method) || request.method.toUpperCase() === 'DELETE' || !hasBody(request)) return null;\n const declared = (request.headers.get('content-type') ?? '').split(';', 1)[0]?.trim().toLowerCase() ?? '';\n return allowed.some((type) => type.toLowerCase() === declared) ? null : new UnsupportedMediaTypeError();\n}\n\n/**\n * A declared `Content-Length` over the ceiling is a 413 before the body is read.\n * This is the cheap half; the `/hono` middleware also caps the stream, because a\n * chunked request declares nothing.\n */\nfunction checkContentLength(request: Request, maxBytes: number = DEFAULT_MAX_BODY_BYTES): ServiceError | null {\n const raw = request.headers.get('content-length');\n if (raw === null) return null;\n const length = Number(raw.trim());\n return Number.isFinite(length) && length > maxBytes ? new PayloadTooLargeError() : null;\n}\n\nexport {\n checkContentLength,\n checkContentType,\n checkMethod,\n checkOrigin,\n isMutatingMethod,\n requestOrigin,\n DEFAULT_ALLOWED_METHODS,\n DEFAULT_MAX_BODY_BYTES,\n};\nexport type { OriginGuardOptions };\n"],
|
|
5
|
+
"mappings": "+EA4BA,OAAS,kBAAAA,EAAgB,yBAAAC,EAAuB,wBAAAC,EAAsB,6BAAAC,MAAiC,mBAGvG,MAAMC,EAAoC,IAAI,IAAI,CAAC,MAAO,OAAQ,SAAS,CAAC,EAKtEC,EAA6C,CAAC,MAAO,OAAQ,OAAQ,MAAO,QAAS,SAAU,SAAS,EAKxGC,EAAyB,QAEzBC,EAAqB,iCAgB3B,SAASC,EAAiBC,EAAc,CACtC,MAAO,CAACL,EAAa,IAAIK,EAAO,YAAW,CAAE,CAC/C,CAFSC,EAAAF,EAAA,oBAIT,SAASG,EAASC,EAAoB,CACpC,MAAMC,EAAUD,GAAO,KAAI,GAAM,GACjC,GAAIC,IAAY,GAAI,OAAO,KAC3B,GAAI,CACF,OAAO,IAAI,IAAIA,CAAO,EAAE,MAC1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A,WAUT,SAASE,EAAiBb,EAAkBK,EAA6B,CAAC,kBAAkB,EAAC,CAC3F,GAAI,CAACZ,EAAiBO,EAAQ,MAAM,GAAKA,EAAQ,OAAO,YAAW,IAAO,UAAY,CAACW,EAAQX,CAAO,EAAG,OAAO,KAChH,MAAMc,GAAYd,EAAQ,QAAQ,IAAI,cAAc,GAAK,IAAI,MAAM,IAAK,CAAC,EAAE,CAAC,GAAG,KAAI,EAAG,YAAW,GAAM,GACvG,OAAOK,EAAQ,KAAMU,GAASA,EAAK,YAAW,IAAOD,CAAQ,EAAI,KAAO,IAAI1B,CAC9E,CAJSO,EAAAkB,EAAA,oBAWT,SAASG,EAAmBhB,EAAkBiB,EAAmB1B,EAAsB,CACrF,MAAM2B,EAAMlB,EAAQ,QAAQ,IAAI,gBAAgB,EAChD,GAAIkB,IAAQ,KAAM,OAAO,KACzB,MAAMN,EAAS,OAAOM,EAAI,KAAI,CAAE,EAChC,OAAO,OAAO,SAASN,CAAM,GAAKA,EAASK,EAAW,IAAI9B,EAAyB,IACrF,CALSQ,EAAAqB,EAAA",
|
|
6
|
+
"names": ["ForbiddenError", "MethodNotAllowedError", "PayloadTooLargeError", "UnsupportedMediaTypeError", "SAFE_METHODS", "DEFAULT_ALLOWED_METHODS", "DEFAULT_MAX_BODY_BYTES", "CROSS_SITE_MESSAGE", "isMutatingMethod", "method", "__name", "originOf", "value", "trimmed", "requestOrigin", "request", "checkOrigin", "options", "fetchSite", "origin", "allowed", "own", "entry", "normalized", "checkMethod", "upper", "hasBody", "length", "checkContentType", "declared", "type", "checkContentLength", "maxBytes", "raw"]
|
|
7
|
+
}
|
package/dist/routeBase.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routeBase.d.ts","sourceRoot":"","sources":["../src/routeBase.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"routeBase.d.ts","sourceRoot":"","sources":["../src/routeBase.ts"],"names":[],"mappings":"AAkCA;;EAEE;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!0});import{BadRequestError as u}from"@rexezuge/errors";import{errorResponseFromUnknown as a}from"./ErrorMapper.js";function o(r,n){return a(r,n.json.bind(n))}e(o,"defaultOnError");const c={async readJson(r){try{return await r.req.json()}catch{return{}}},requireString(r,n){if(typeof r!="string"||r.trim()==="")throw new u(`\`${n}\` is required and must be a non-empty string.`);return r},toErrorResponse(r,n,t){return(t?.onError??o)(r,n)}};function m(r,n={}){return async t=>{try{return await r(t)}catch(s){return(n.onError??o)(s,t)}}}e(m,"createRouteHandler");export{c as BaseRoute,m as createRouteHandler};
|
package/dist/routeBase.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/routeBase.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Shared statics for Hono route handlers.\n *\n * Converged from `endpoints/IBaseRoute.ts` / `endpoints/BaseRoute.ts` in the\n * nine full-framework repos, which hold **two incompatible shapes**: a Hono\n * `Response`-returning base class, and a namespace of statics. Both survive here,\n * because the decision of which to use is genuinely per-repo — but the *parts*\n * they share no longer do.\n *\n * ## Why a namespace and not a base class\n *\n * Durable-DAV's Template Method (`abstract handleRequest` + `handle()` owning the\n * try/catch) had **zero** subclasses — `VolumeScopedRoute` reimplements the same\n * try/catch against the same `toErrorResponse` — so it advertised an inheritance\n * contract nothing was using, while its own doc comment claimed handlers \"stop\n * duplicating\" error mapping.\n *\n * So the shared surface is a namespace of statics. A repo that wants the Template\n * Method takes {@link createRouteHandler}; a repo that does not takes the statics\n * directly. Neither pays for the other's abstraction.\n *\n * ##
|
|
5
|
-
"mappings": "+
|
|
6
|
-
"names": ["BadRequestError", "
|
|
4
|
+
"sourcesContent": ["/**\n * Shared statics for Hono route handlers.\n *\n * Converged from `endpoints/IBaseRoute.ts` / `endpoints/BaseRoute.ts` in the\n * nine full-framework repos, which hold **two incompatible shapes**: a Hono\n * `Response`-returning base class, and a namespace of statics. Both survive here,\n * because the decision of which to use is genuinely per-repo — but the *parts*\n * they share no longer do.\n *\n * ## Why a namespace and not a base class\n *\n * Durable-DAV's Template Method (`abstract handleRequest` + `handle()` owning the\n * try/catch) had **zero** subclasses — `VolumeScopedRoute` reimplements the same\n * try/catch against the same `toErrorResponse` — so it advertised an inheritance\n * contract nothing was using, while its own doc comment claimed handlers \"stop\n * duplicating\" error mapping.\n *\n * So the shared surface is a namespace of statics. A repo that wants the Template\n * Method takes {@link createRouteHandler}; a repo that does not takes the statics\n * directly. Neither pays for the other's abstraction.\n *\n * ## The chanfana half lives in `/hono`\n *\n * Six of the nine repos build routes as chanfana `OpenAPIRoute` subclasses. That\n * shape is converged as `FamilyRoute` in `@rexezuge/http/hono` (from the seven\n * `endpoints/IBaseRoute.ts` copies): the closed `handle()` validates through the\n * route's own chanfana schema, runs `handleRequest`, and maps failures through\n * the same mapper as this module. It lives in the subpath because it imports\n * `chanfana`, and this barrel stays framework-free. The statics here remain for\n * plain-Hono and bare-`Request` handlers.\n */\nimport { BadRequestError } from '@rexezuge/errors';\nimport { errorResponseFromUnknown } from './ErrorMapper.ts';\n\n/**\nThe slice of a Hono context a route handler reads.\n*/\ninterface RouteContext {\n req: { json(): Promise<unknown>; raw: Request };\n env: unknown;\n json(body: unknown, status?: number, headers?: Record<string, string>): Response;\n /**\n Optional request scope, when the repo uses DI.\n */\n get?(key: string): unknown;\n}\n\ntype RouteHandler = (c: RouteContext) => Promise<Response>;\n\ninterface RouteHandlerOptions {\n /**\n A repo-specific mapper. Defaults to the canonical `{Exception:{…}}` dialect.\n */\n onError?(error: unknown, c: RouteContext): Response;\n}\n\nfunction defaultOnError(error: unknown, c: RouteContext): Response {\n return errorResponseFromUnknown(error, c.json.bind(c));\n}\n\n/**\n * The shared statics.\n *\n * `readJson` is deliberately total: a malformed body yields `{}` rather than\n * throwing, because a handler that wants to reject a malformed body validates it\n * and gets a 400 through the normal path. A parse error thrown from here would\n * bypass whatever validation error message the repo has.\n */\nconst BaseRoute = {\n /**\n * Read the JSON body, or `{}`.\n *\n * Bounded by the caller's schema, not here: an unbounded `req.json()` on a\n * worker is a memory ceiling, and each repo's limit is its own\n * `MAX_JSON_BODY_BYTES`.\n */\n async readJson(c: RouteContext): Promise<unknown> {\n try {\n return await c.req.json();\n } catch {\n return {};\n }\n },\n\n /**\n A required string field, or the error that says which field was missing.\n */\n requireString(value: unknown, field: string): string {\n if (typeof value !== 'string' || value.trim() === '') {\n throw new BadRequestError(`\\`${field}\\` is required and must be a non-empty string.`);\n }\n return value;\n },\n\n /**\n Map a caught value to a response, using the repo's dialect if it declared one.\n */\n toErrorResponse(error: unknown, c: RouteContext, options?: RouteHandlerOptions): Response {\n return (options?.onError ?? defaultOnError)(error, c);\n },\n} as const;\n\n/**\n * Build a Template-Method route handler.\n *\n * The shape Edge-Git and Edge-Sonic converged on: the handler owns only its\n * domain work, and the base owns the try/catch so a private repo's existence and\n * a 5xx's message are decided in exactly one place per app.\n */\nfunction createRouteHandler(handle: RouteHandler, options: RouteHandlerOptions = {}): (c: RouteContext) => Promise<Response> {\n return async (c: RouteContext): Promise<Response> => {\n try {\n return await handle(c);\n } catch (error: unknown) {\n return (options.onError ?? defaultOnError)(error, c);\n }\n };\n}\n\nexport { BaseRoute, createRouteHandler };\nexport type { RouteContext, RouteHandler, RouteHandlerOptions };\n"],
|
|
5
|
+
"mappings": "+EA+BA,OAAS,mBAAAA,MAAuB,mBAChC,OAAS,4BAAAC,MAAgC,mBAwBzC,SAASC,EAAeC,EAAgBC,EAAe,CACrD,OAAOH,EAAyBE,EAAOC,EAAE,KAAK,KAAKA,CAAC,CAAC,CACvD,CAFSC,EAAAH,EAAA,kBAYT,MAAMI,EAAY,CAQhB,MAAM,SAASF,EAAe,CAC5B,GAAI,CACF,OAAO,MAAMA,EAAE,IAAI,KAAI,CACzB,MAAQ,CACN,MAAO,CAAA,CACT,CACF,EAKA,cAAcG,EAAgBC,EAAa,CACzC,GAAI,OAAOD,GAAU,UAAYA,EAAM,KAAI,IAAO,GAChD,MAAM,IAAIP,EAAgB,KAAKQ,CAAK,gDAAgD,EAEtF,OAAOD,CACT,EAKA,gBAAgBJ,EAAgBC,EAAiBK,EAA6B,CAC5E,OAAQA,GAAS,SAAWP,GAAgBC,EAAOC,CAAC,CACtD,GAUF,SAASM,EAAmBC,EAAsBF,EAA+B,CAAA,EAAE,CACjF,MAAO,OAAOL,GAAsC,CAClD,GAAI,CACF,OAAO,MAAMO,EAAOP,CAAC,CACvB,OAASD,EAAgB,CACvB,OAAQM,EAAQ,SAAWP,GAAgBC,EAAOC,CAAC,CACrD,CACF,CACF,CARSC,EAAAK,EAAA",
|
|
6
|
+
"names": ["BadRequestError", "errorResponseFromUnknown", "defaultOnError", "error", "c", "__name", "BaseRoute", "value", "field", "options", "createRouteHandler", "handle"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rexezuge/http",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
"types": "./dist/testing.d.ts",
|
|
21
21
|
"default": "./dist/testing.js"
|
|
22
22
|
},
|
|
23
|
+
"./hono": {
|
|
24
|
+
"types": "./dist/hono/index.d.ts",
|
|
25
|
+
"default": "./dist/hono/index.js"
|
|
26
|
+
},
|
|
23
27
|
"./*": {
|
|
24
28
|
"types": "./dist/*.d.ts",
|
|
25
29
|
"default": "./dist/*.js"
|
|
@@ -30,8 +34,9 @@
|
|
|
30
34
|
],
|
|
31
35
|
"dependencies": {
|
|
32
36
|
"jose": "^6.2.12",
|
|
33
|
-
"@rexezuge/
|
|
34
|
-
"@rexezuge/
|
|
37
|
+
"@rexezuge/contracts": "1.12.0",
|
|
38
|
+
"@rexezuge/errors": "1.12.0",
|
|
39
|
+
"@rexezuge/shared": "1.12.0"
|
|
35
40
|
},
|
|
36
41
|
"peerDependencies": {
|
|
37
42
|
"chanfana": "^3.4.0",
|
|
@@ -47,10 +52,13 @@
|
|
|
47
52
|
},
|
|
48
53
|
"devDependencies": {
|
|
49
54
|
"@types/node": "26.6.4",
|
|
55
|
+
"chanfana": "^3.4.0",
|
|
56
|
+
"hono": "^4.13.13",
|
|
50
57
|
"typescript": "6.0.3",
|
|
51
|
-
"vitest": "4.1.11"
|
|
58
|
+
"vitest": "4.1.11",
|
|
59
|
+
"zod": "^4.6.5"
|
|
52
60
|
},
|
|
53
|
-
"description": "
|
|
61
|
+
"description": "Edge HTTP layer for the Rexezuge family: framework-free rate limiter, security headers, request guards, Cloudflare Access auth and error mapper, plus the Hono/chanfana app kernel at @rexezuge/http/hono.",
|
|
54
62
|
"scripts": {
|
|
55
63
|
"build": "tsc -p tsconfig.json && node ../../scripts/minify-dist.mjs",
|
|
56
64
|
"typecheck": "tsc -p tsconfig.test.json --noEmit",
|