@mednours/backon 0.7.0 → 0.8.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/auth-core.d.ts +36 -5
- package/dist/auth-core.d.ts.map +1 -1
- package/dist/cache-control-core.d.ts +17 -0
- package/dist/cache-control-core.d.ts.map +1 -0
- package/dist/cache-control.d.ts +9 -0
- package/dist/cache-control.d.ts.map +1 -0
- package/dist/create-app.d.ts +8 -0
- package/dist/create-app.d.ts.map +1 -1
- package/dist/define-route.d.ts +1 -1
- package/dist/define-route.d.ts.map +1 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/express/cache-control.d.ts +9 -0
- package/dist/express/cache-control.d.ts.map +1 -0
- package/dist/express/create-app.d.ts +5 -0
- package/dist/express/create-app.d.ts.map +1 -1
- package/dist/express/define-route.d.ts +1 -1
- package/dist/express/define-route.d.ts.map +1 -1
- package/dist/express/index.d.ts +4 -1
- package/dist/express/index.d.ts.map +1 -1
- package/dist/express/index.js +118 -17
- package/dist/express/rate-limit.d.ts.map +1 -1
- package/dist/express/require-auth.d.ts +2 -11
- package/dist/express/require-auth.d.ts.map +1 -1
- package/dist/express/stream.d.ts.map +1 -1
- package/dist/express/upload.d.ts.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +120 -15
- package/dist/openapi-core.d.ts +1 -1
- package/dist/openapi-core.d.ts.map +1 -1
- package/dist/openapi.d.ts.map +1 -1
- package/dist/rate-limit-core.d.ts.map +1 -1
- package/dist/rate-limit.d.ts.map +1 -1
- package/dist/require-auth.d.ts +3 -14
- package/dist/require-auth.d.ts.map +1 -1
- package/dist/stream.d.ts.map +1 -1
- package/dist/upload.d.ts.map +1 -1
- package/dist/websocket.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/auth-core.ts +106 -6
- package/src/cache-control-core.ts +32 -0
- package/src/cache-control.ts +18 -0
- package/src/create-app.ts +9 -0
- package/src/define-route.ts +7 -5
- package/src/express/cache-control.ts +18 -0
- package/src/express/create-app.ts +11 -1
- package/src/express/define-route.ts +4 -4
- package/src/express/index.ts +5 -1
- package/src/express/openapi.ts +4 -4
- package/src/express/require-auth.ts +11 -14
- package/src/index.ts +6 -1
- package/src/openapi-core.ts +8 -5
- package/src/openapi.ts +5 -2
- package/src/require-auth.ts +10 -17
package/dist/auth-core.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { JWTPayload } from "hono/utils/jwt/types";
|
|
2
2
|
import type { SignatureAlgorithm } from "hono/utils/jwt/jwa";
|
|
3
3
|
/**
|
|
4
|
-
* Shared by the Hono and Express
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* than a new dependency, since hono is already a hard dependency of backon
|
|
8
|
-
* regardless of which framework (Hono or Express) a project picked.
|
|
4
|
+
* Shared by the Hono and Express auth helpers — JWT signing/verification
|
|
5
|
+
* and cookie token extraction are identical across frameworks, built on
|
|
6
|
+
* hono/jwt and Web Crypto so no extra dependencies are needed.
|
|
9
7
|
*/
|
|
10
8
|
export interface VerifyJwtOptions {
|
|
11
9
|
/** Secret used to verify the token's signature. */
|
|
@@ -17,9 +15,42 @@ export interface VerifyJwtOptions {
|
|
|
17
15
|
* algorithm the server chose, never one the token claims for itself.
|
|
18
16
|
*/
|
|
19
17
|
alg?: SignatureAlgorithm;
|
|
18
|
+
/**
|
|
19
|
+
* Optional cookie name to fall back to when no `Authorization: Bearer`
|
|
20
|
+
* header is present (e.g. `"authToken"`).
|
|
21
|
+
*/
|
|
22
|
+
cookieName?: string;
|
|
23
|
+
/**
|
|
24
|
+
* When set alongside `cookieName`, verifies Hono-style signed cookies
|
|
25
|
+
* (`<value>.<base64-hmac-sha256>`) using this secret before verifying the JWT.
|
|
26
|
+
*/
|
|
27
|
+
cookieSecret?: string;
|
|
20
28
|
}
|
|
29
|
+
export interface SignJwtOptions {
|
|
30
|
+
/** Secret used to sign the token. */
|
|
31
|
+
secret: string;
|
|
32
|
+
/** Algorithm to sign with. Defaults to HS256. */
|
|
33
|
+
alg?: SignatureAlgorithm;
|
|
34
|
+
/**
|
|
35
|
+
* Optional lifetime in seconds. When set and `payload.exp` is omitted,
|
|
36
|
+
* sets `exp = Math.floor(Date.now() / 1000) + expiresInSeconds`.
|
|
37
|
+
*/
|
|
38
|
+
expiresInSeconds?: number;
|
|
39
|
+
}
|
|
40
|
+
/** Signs a JWT payload using HS256 by default (matching requireAuth's default). */
|
|
41
|
+
export declare function signJwt(payload: JWTPayload, options: SignJwtOptions): Promise<string>;
|
|
21
42
|
/** Verifies a JWT's signature and standard claims (exp/nbf/iat), returns its payload. Throws on any failure. */
|
|
22
43
|
export declare function verifyJwt(token: string, options: VerifyJwtOptions): Promise<JWTPayload>;
|
|
23
44
|
/** Pulls the token out of a `Bearer <token>` Authorization header, or undefined if it's missing/malformed. */
|
|
24
45
|
export declare function extractBearerToken(header: string | undefined): string | undefined;
|
|
46
|
+
/** Parses one named cookie from a raw `Cookie` request header, decoding percent-encoding. */
|
|
47
|
+
export declare function parseCookieHeader(cookieHeader: string | undefined, name: string): string | undefined;
|
|
48
|
+
/** Verifies a Hono-compatible signed cookie (`<value>.<base64-hmac-sha256>`) using Web Crypto. */
|
|
49
|
+
export declare function verifySignedCookieValue(signedValue: string, secret: string): Promise<string | undefined>;
|
|
50
|
+
/**
|
|
51
|
+
* Extracts a JWT from `Authorization: Bearer <token>`, or falls back to
|
|
52
|
+
* `options.cookieName` (verifying its HMAC signature if `options.cookieSecret`
|
|
53
|
+
* is configured).
|
|
54
|
+
*/
|
|
55
|
+
export declare function extractAuthToken(authHeader: string | undefined, cookieHeader: string | undefined, options: VerifyJwtOptions): Promise<string | undefined>;
|
|
25
56
|
//# sourceMappingURL=auth-core.d.ts.map
|
package/dist/auth-core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-core.d.ts","sourceRoot":"","sources":["../src/auth-core.ts"],"names":[],"mappings":"A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wBAAsB,uBAAuB,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA0B9G;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAY7B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface CacheControlOptions {
|
|
2
|
+
/** Browser cache lifetime in seconds (`max-age=<n>`). Defaults to 0 when `sMaxAge` is set without `maxAge`. */
|
|
3
|
+
maxAge?: number;
|
|
4
|
+
/** Shared/CDN (e.g. Vercel Edge) cache lifetime in seconds (`s-maxage=<n>`). */
|
|
5
|
+
sMaxAge?: number;
|
|
6
|
+
/** Seconds a CDN may serve stale content while refreshing asynchronously (`stale-while-revalidate=<n>`). */
|
|
7
|
+
staleWhileRevalidate?: number;
|
|
8
|
+
/** Marks the response private to one user (`private`) — never set `sMaxAge` alongside this. */
|
|
9
|
+
private?: boolean;
|
|
10
|
+
/** Disables caching completely (`no-store`). */
|
|
11
|
+
noStore?: boolean;
|
|
12
|
+
/** Marks hashed/versioned responses as immutable (`immutable`). */
|
|
13
|
+
immutable?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** Builds a standardized `Cache-Control` header value from structured options. */
|
|
16
|
+
export declare function buildCacheControlHeader(options: CacheControlOptions): string;
|
|
17
|
+
//# sourceMappingURL=cache-control-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-control-core.d.ts","sourceRoot":"","sources":["../src/cache-control-core.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAClC,+GAA+G;IAC/G,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4GAA4G;IAC5G,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,+FAA+F;IAC/F,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gDAAgD;IAChD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,mEAAmE;IACnE,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,kFAAkF;AAClF,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAe5E"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Context, Next } from "hono";
|
|
2
|
+
import { type CacheControlOptions } from "./cache-control-core";
|
|
3
|
+
export type { CacheControlOptions };
|
|
4
|
+
/**
|
|
5
|
+
* Sets `Cache-Control` headers on public or private routes (e.g. Vercel Edge
|
|
6
|
+
* `s-maxage` + `stale-while-revalidate`) unless the handler already set one.
|
|
7
|
+
*/
|
|
8
|
+
export declare function cacheControl(options: CacheControlOptions): (c: Context, next: Next) => Promise<void>;
|
|
9
|
+
//# sourceMappingURL=cache-control.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-control.d.ts","sourceRoot":"","sources":["../src/cache-control.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,EAA2B,KAAK,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEzF,YAAY,EAAE,mBAAmB,EAAE,CAAC;AAEpC;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,OAEP,OAAO,QAAQ,IAAI,mBAMpE"}
|
package/dist/create-app.d.ts
CHANGED
|
@@ -9,6 +9,14 @@ export interface CreateAppOptions {
|
|
|
9
9
|
allowedOrigins?: string[];
|
|
10
10
|
/** Max request body size in bytes. Defaults to 1mb. */
|
|
11
11
|
bodyLimitBytes?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Allow browsers to send and accept cookies on cross-origin requests
|
|
14
|
+
* (`Access-Control-Allow-Credentials: true`). Off by default — only needed
|
|
15
|
+
* when frontend and API live on different origins (alongside
|
|
16
|
+
* `credentials: "include"` on frontend fetches). Safe with `allowedOrigins`
|
|
17
|
+
* because backon uses an explicit allowlist, never `*`.
|
|
18
|
+
*/
|
|
19
|
+
credentials?: boolean;
|
|
12
20
|
}
|
|
13
21
|
/**
|
|
14
22
|
* Builds a Hono app pre-wired with backon's opinionated defaults: request
|
package/dist/create-app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-app.d.ts","sourceRoot":"","sources":["../src/create-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAO5B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAEnC,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,uDAAuD;IACvD,cAAc,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"create-app.d.ts","sourceRoot":"","sources":["../src/create-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAO5B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAEnC,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,uDAAuD;IACvD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAUD;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB,oDAgDvD"}
|
package/dist/define-route.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ZodType } from "zod";
|
|
2
2
|
import type { BackonContext } from "./types";
|
|
3
3
|
/** Zod schemas for the parts of a request worth validating. All optional — skip whatever isn't needed. */
|
|
4
4
|
export interface RouteSchema<B = undefined, Q = undefined, P = undefined> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-route.d.ts","sourceRoot":"","sources":["../src/define-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"define-route.d.ts","sourceRoot":"","sources":["../src/define-route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAEtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,0GAA0G;AAC1G,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,SAAS;IACtE,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACrB;AAED,MAAM,WAAW,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IAChC,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,CAAC,CAAC;IACT,MAAM,EAAE,CAAC,CAAC;CACX;AAED,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAClC,CAAC,EAAE,aAAa,EAChB,IAAI,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KACrB,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAElC,6GAA6G;AAC7G,MAAM,WAAW,cAAc;IAC7B,CAAC,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACtC,mBAAmB,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;CAC9D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,SAAS,EACrE,MAAM,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC5B,OAAO,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAC7B,cAAc,CAuChB"}
|
package/dist/error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAE3B,YAAY,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAM/E;CACF;AAED,oEAAoE;AACpE,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;CACH"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Request, Response, NextFunction } from "express";
|
|
2
|
+
import { type CacheControlOptions } from "../cache-control-core";
|
|
3
|
+
export type { CacheControlOptions };
|
|
4
|
+
/**
|
|
5
|
+
* Express equivalent of `cacheControl()` — sets `Cache-Control` on the
|
|
6
|
+
* response unless the handler sets its own header later.
|
|
7
|
+
*/
|
|
8
|
+
export declare function cacheControl(options: CacheControlOptions): (_req: Request, res: Response, next: NextFunction) => void;
|
|
9
|
+
//# sourceMappingURL=cache-control.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-control.d.ts","sourceRoot":"","sources":["../../src/express/cache-control.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAA2B,KAAK,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE1F,YAAY,EAAE,mBAAmB,EAAE,CAAC;AAEpC;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,UAEV,OAAO,OAAO,QAAQ,QAAQ,YAAY,KAAG,IAAI,CAM/F"}
|
|
@@ -4,6 +4,11 @@ export interface CreateAppOptions {
|
|
|
4
4
|
allowedOrigins?: string[];
|
|
5
5
|
/** Max request body size in bytes. Defaults to 1mb. */
|
|
6
6
|
bodyLimitBytes?: number;
|
|
7
|
+
/**
|
|
8
|
+
* Allow browsers to send and accept cookies on cross-origin requests
|
|
9
|
+
* (`Access-Control-Allow-Credentials: true`). Off by default.
|
|
10
|
+
*/
|
|
11
|
+
credentials?: boolean;
|
|
7
12
|
}
|
|
8
13
|
/**
|
|
9
14
|
* Builds an Express app pre-wired with the same defaults as the Hono
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-app.d.ts","sourceRoot":"","sources":["../../src/express/create-app.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,KAAK,OAAO,EAAkD,MAAM,SAAS,CAAC;AAShG,MAAM,WAAW,gBAAgB;IAC/B,sGAAsG;IACtG,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,uDAAuD;IACvD,cAAc,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"create-app.d.ts","sourceRoot":"","sources":["../../src/express/create-app.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,KAAK,OAAO,EAAkD,MAAM,SAAS,CAAC;AAShG,MAAM,WAAW,gBAAgB;IAC/B,sGAAsG;IACtG,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,uDAAuD;IACvD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAUD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB,GAAG,OAAO,CA4BjE;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAwBrD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Request, Response, NextFunction } from "express";
|
|
2
|
-
import type
|
|
2
|
+
import { type ZodType } from "zod";
|
|
3
3
|
import { type BackonContext } from "./types";
|
|
4
4
|
export interface RouteSchema<B = undefined, Q = undefined, P = undefined> {
|
|
5
5
|
body?: ZodType<B>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-route.d.ts","sourceRoot":"","sources":["../../src/express/define-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"define-route.d.ts","sourceRoot":"","sources":["../../src/express/define-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAK,KAAK,OAAO,EAAE,MAAM,KAA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ts
CHANGED
|
@@ -8,7 +8,10 @@ export type { ErrorResponseBody } from "../error";
|
|
|
8
8
|
export { logger } from "../logger";
|
|
9
9
|
export { requireEnv } from "../require-env";
|
|
10
10
|
export { requireAuth } from "./require-auth";
|
|
11
|
-
export
|
|
11
|
+
export { signJwt } from "../auth-core";
|
|
12
|
+
export type { VerifyJwtOptions, SignJwtOptions } from "../auth-core";
|
|
13
|
+
export { cacheControl } from "./cache-control";
|
|
14
|
+
export type { CacheControlOptions } from "./cache-control";
|
|
12
15
|
export { rateLimit } from "./rate-limit";
|
|
13
16
|
export type { RateLimitOptions } from "./rate-limit";
|
|
14
17
|
export type { BackonContext } from "./types";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/express/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC7D,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE3E,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/express/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAA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UAAU,CAAC;AACxC,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE7D,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9D,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/express/index.js
CHANGED
|
@@ -103,7 +103,12 @@ function createApp(options = {}) {
|
|
|
103
103
|
app.use(requestLogger);
|
|
104
104
|
app.use(helmet());
|
|
105
105
|
const allowedOrigins = resolveAllowedOrigins(options);
|
|
106
|
-
app.use(
|
|
106
|
+
app.use(
|
|
107
|
+
cors({
|
|
108
|
+
origin: allowedOrigins.length ? allowedOrigins : false,
|
|
109
|
+
credentials: options.credentials ?? false
|
|
110
|
+
})
|
|
111
|
+
);
|
|
107
112
|
app.use(compression());
|
|
108
113
|
app.use(express.json({ limit: options.bodyLimitBytes ?? DEFAULT_BODY_LIMIT_BYTES }));
|
|
109
114
|
app.get("/health", (_req, res) => {
|
|
@@ -169,6 +174,9 @@ function serve(app, port = Number(process.env.PORT) || 3e3) {
|
|
|
169
174
|
return server;
|
|
170
175
|
}
|
|
171
176
|
|
|
177
|
+
// src/express/define-route.ts
|
|
178
|
+
import { z } from "zod";
|
|
179
|
+
|
|
172
180
|
// src/express/types.ts
|
|
173
181
|
function createContext(req, res) {
|
|
174
182
|
return {
|
|
@@ -200,21 +208,21 @@ function defineRoute(schema, handler) {
|
|
|
200
208
|
if (schema.body) {
|
|
201
209
|
const parsed = schema.body.safeParse(req.body ?? {});
|
|
202
210
|
if (!parsed.success) {
|
|
203
|
-
throw new AppError(400, "invalid_body", "Request body failed validation", parsed.error
|
|
211
|
+
throw new AppError(400, "invalid_body", "Request body failed validation", z.flattenError(parsed.error));
|
|
204
212
|
}
|
|
205
213
|
body = parsed.data;
|
|
206
214
|
}
|
|
207
215
|
if (schema.query) {
|
|
208
216
|
const parsed = schema.query.safeParse(req.query);
|
|
209
217
|
if (!parsed.success) {
|
|
210
|
-
throw new AppError(400, "invalid_query", "Query params failed validation", parsed.error
|
|
218
|
+
throw new AppError(400, "invalid_query", "Query params failed validation", z.flattenError(parsed.error));
|
|
211
219
|
}
|
|
212
220
|
query = parsed.data;
|
|
213
221
|
}
|
|
214
222
|
if (schema.params) {
|
|
215
223
|
const parsed = schema.params.safeParse(req.params);
|
|
216
224
|
if (!parsed.success) {
|
|
217
|
-
throw new AppError(400, "invalid_params", "Route params failed validation", parsed.error
|
|
225
|
+
throw new AppError(400, "invalid_params", "Route params failed validation", z.flattenError(parsed.error));
|
|
218
226
|
}
|
|
219
227
|
params = parsed.data;
|
|
220
228
|
}
|
|
@@ -240,8 +248,13 @@ ${issues}`);
|
|
|
240
248
|
}
|
|
241
249
|
|
|
242
250
|
// src/auth-core.ts
|
|
243
|
-
import { verify } from "hono/jwt";
|
|
251
|
+
import { sign, verify } from "hono/jwt";
|
|
244
252
|
var DEFAULT_ALG = "HS256";
|
|
253
|
+
var textEncoder = new TextEncoder();
|
|
254
|
+
function signJwt(payload, options) {
|
|
255
|
+
const finalPayload = options.expiresInSeconds !== void 0 && payload.exp === void 0 ? { ...payload, exp: Math.floor(Date.now() / 1e3) + options.expiresInSeconds } : payload;
|
|
256
|
+
return sign(finalPayload, options.secret, options.alg ?? DEFAULT_ALG);
|
|
257
|
+
}
|
|
245
258
|
function verifyJwt(token, options) {
|
|
246
259
|
return verify(token, options.secret, options.alg ?? DEFAULT_ALG);
|
|
247
260
|
}
|
|
@@ -251,13 +264,70 @@ function extractBearerToken(header) {
|
|
|
251
264
|
if (scheme?.toLowerCase() !== "bearer" || !token) return void 0;
|
|
252
265
|
return token;
|
|
253
266
|
}
|
|
267
|
+
function parseCookieHeader(cookieHeader, name) {
|
|
268
|
+
if (!cookieHeader) return void 0;
|
|
269
|
+
for (const part of cookieHeader.split(";")) {
|
|
270
|
+
const eq = part.indexOf("=");
|
|
271
|
+
if (eq === -1) continue;
|
|
272
|
+
const key = part.slice(0, eq).trim();
|
|
273
|
+
if (key !== name) continue;
|
|
274
|
+
const raw = part.slice(eq + 1).trim();
|
|
275
|
+
try {
|
|
276
|
+
return decodeURIComponent(raw);
|
|
277
|
+
} catch {
|
|
278
|
+
return raw;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return void 0;
|
|
282
|
+
}
|
|
283
|
+
async function verifySignedCookieValue(signedValue, secret) {
|
|
284
|
+
const dot = signedValue.lastIndexOf(".");
|
|
285
|
+
if (dot <= 0) return void 0;
|
|
286
|
+
const value = signedValue.slice(0, dot);
|
|
287
|
+
const sigB64 = signedValue.slice(dot + 1);
|
|
288
|
+
if (sigB64.length !== 44 || !sigB64.endsWith("=")) return void 0;
|
|
289
|
+
let sigBytes;
|
|
290
|
+
try {
|
|
291
|
+
const binary = atob(sigB64);
|
|
292
|
+
sigBytes = new Uint8Array(new ArrayBuffer(binary.length));
|
|
293
|
+
for (let i = 0; i < binary.length; i++) sigBytes[i] = binary.charCodeAt(i);
|
|
294
|
+
} catch {
|
|
295
|
+
return void 0;
|
|
296
|
+
}
|
|
297
|
+
const key = await crypto.subtle.importKey(
|
|
298
|
+
"raw",
|
|
299
|
+
textEncoder.encode(secret),
|
|
300
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
301
|
+
false,
|
|
302
|
+
["verify"]
|
|
303
|
+
);
|
|
304
|
+
const valid = await crypto.subtle.verify("HMAC", key, sigBytes, textEncoder.encode(value));
|
|
305
|
+
return valid ? value : void 0;
|
|
306
|
+
}
|
|
307
|
+
async function extractAuthToken(authHeader, cookieHeader, options) {
|
|
308
|
+
const bearer = extractBearerToken(authHeader);
|
|
309
|
+
if (bearer) return bearer;
|
|
310
|
+
if (!options.cookieName) return void 0;
|
|
311
|
+
const rawCookie = parseCookieHeader(cookieHeader, options.cookieName);
|
|
312
|
+
if (!rawCookie) return void 0;
|
|
313
|
+
if (options.cookieSecret) {
|
|
314
|
+
return verifySignedCookieValue(rawCookie, options.cookieSecret);
|
|
315
|
+
}
|
|
316
|
+
return rawCookie;
|
|
317
|
+
}
|
|
254
318
|
|
|
255
319
|
// src/express/require-auth.ts
|
|
256
320
|
function requireAuth(options) {
|
|
257
321
|
return async function requireAuthMiddleware(req, res, next) {
|
|
258
|
-
const token =
|
|
322
|
+
const token = await extractAuthToken(req.header("authorization"), req.header("cookie"), options);
|
|
259
323
|
if (!token) {
|
|
260
|
-
next(
|
|
324
|
+
next(
|
|
325
|
+
new AppError(
|
|
326
|
+
401,
|
|
327
|
+
"unauthorized",
|
|
328
|
+
options.cookieName ? "Missing authentication token" : "Missing or malformed Authorization header"
|
|
329
|
+
)
|
|
330
|
+
);
|
|
261
331
|
return;
|
|
262
332
|
}
|
|
263
333
|
try {
|
|
@@ -270,6 +340,33 @@ function requireAuth(options) {
|
|
|
270
340
|
};
|
|
271
341
|
}
|
|
272
342
|
|
|
343
|
+
// src/cache-control-core.ts
|
|
344
|
+
function buildCacheControlHeader(options) {
|
|
345
|
+
if (options.noStore) return "no-store";
|
|
346
|
+
const directives = [options.private ? "private" : "public"];
|
|
347
|
+
const maxAge = options.maxAge ?? (options.sMaxAge !== void 0 ? 0 : void 0);
|
|
348
|
+
if (maxAge !== void 0) directives.push(`max-age=${Math.max(0, Math.floor(maxAge))}`);
|
|
349
|
+
if (!options.private && options.sMaxAge !== void 0) {
|
|
350
|
+
directives.push(`s-maxage=${Math.max(0, Math.floor(options.sMaxAge))}`);
|
|
351
|
+
}
|
|
352
|
+
if (options.staleWhileRevalidate !== void 0) {
|
|
353
|
+
directives.push(`stale-while-revalidate=${Math.max(0, Math.floor(options.staleWhileRevalidate))}`);
|
|
354
|
+
}
|
|
355
|
+
if (options.immutable) directives.push("immutable");
|
|
356
|
+
return directives.join(", ");
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// src/express/cache-control.ts
|
|
360
|
+
function cacheControl(options) {
|
|
361
|
+
const headerValue = buildCacheControlHeader(options);
|
|
362
|
+
return function cacheControlMiddleware(_req, res, next) {
|
|
363
|
+
if (!res.getHeader("Cache-Control")) {
|
|
364
|
+
res.setHeader("Cache-Control", headerValue);
|
|
365
|
+
}
|
|
366
|
+
next();
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
|
273
370
|
// src/rate-limit-core.ts
|
|
274
371
|
var RateLimiter = class {
|
|
275
372
|
constructor(windowMs, max) {
|
|
@@ -381,18 +478,21 @@ function defineUpload(options, handler) {
|
|
|
381
478
|
}
|
|
382
479
|
|
|
383
480
|
// src/openapi-core.ts
|
|
384
|
-
import {
|
|
481
|
+
import { z as z2 } from "zod";
|
|
385
482
|
function toOpenApiPath(path) {
|
|
386
483
|
return path.replace(/:([A-Za-z0-9_]+)/g, "{$1}");
|
|
387
484
|
}
|
|
388
485
|
function paramNames(path) {
|
|
389
486
|
return [...path.matchAll(/:([A-Za-z0-9_]+)/g)].map((match) => match[1]).filter((name) => name !== void 0);
|
|
390
487
|
}
|
|
488
|
+
function toOpenApiSchema(schema) {
|
|
489
|
+
return z2.toJSONSchema(schema, { target: "openapi-3.0", unrepresentable: "any" });
|
|
490
|
+
}
|
|
391
491
|
function buildOperation(path, schema) {
|
|
392
492
|
const operation = { responses: { "200": { description: "Success" } } };
|
|
393
493
|
const parameters = [];
|
|
394
494
|
if (schema.params) {
|
|
395
|
-
const jsonSchema =
|
|
495
|
+
const jsonSchema = toOpenApiSchema(schema.params);
|
|
396
496
|
for (const name of paramNames(path)) {
|
|
397
497
|
parameters.push({
|
|
398
498
|
name,
|
|
@@ -403,7 +503,7 @@ function buildOperation(path, schema) {
|
|
|
403
503
|
}
|
|
404
504
|
}
|
|
405
505
|
if (schema.query) {
|
|
406
|
-
const jsonSchema =
|
|
506
|
+
const jsonSchema = toOpenApiSchema(schema.query);
|
|
407
507
|
const required = new Set(jsonSchema.required ?? []);
|
|
408
508
|
for (const [name, propSchema] of Object.entries(jsonSchema.properties ?? {})) {
|
|
409
509
|
parameters.push({ name, in: "query", required: required.has(name), schema: propSchema });
|
|
@@ -413,7 +513,7 @@ function buildOperation(path, schema) {
|
|
|
413
513
|
if (schema.body) {
|
|
414
514
|
operation.requestBody = {
|
|
415
515
|
required: true,
|
|
416
|
-
content: { "application/json": { schema:
|
|
516
|
+
content: { "application/json": { schema: toOpenApiSchema(schema.body) } }
|
|
417
517
|
};
|
|
418
518
|
}
|
|
419
519
|
return operation;
|
|
@@ -469,11 +569,10 @@ function generateOpenApiSpec(app, options = {}) {
|
|
|
469
569
|
}
|
|
470
570
|
function serveApiDocs(app, path = "/docs", options = {}) {
|
|
471
571
|
const specPath = `${path}/openapi.json`;
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
);
|
|
572
|
+
const spec = generateOpenApiSpec(app, options);
|
|
573
|
+
const html = apiReferenceHtmlInline(spec, options.title);
|
|
574
|
+
app.get(specPath, (_req, res) => res.json(spec));
|
|
575
|
+
app.get(path, (_req, res) => res.type("html").send(html));
|
|
477
576
|
}
|
|
478
577
|
export {
|
|
479
578
|
AppError,
|
|
@@ -481,6 +580,7 @@ export {
|
|
|
481
580
|
apiReferenceHtml,
|
|
482
581
|
apiReferenceHtmlInline,
|
|
483
582
|
attachErrorHandler,
|
|
583
|
+
cacheControl,
|
|
484
584
|
createApp,
|
|
485
585
|
defineRoute,
|
|
486
586
|
defineStream,
|
|
@@ -492,5 +592,6 @@ export {
|
|
|
492
592
|
requireAuth,
|
|
493
593
|
requireEnv,
|
|
494
594
|
serve,
|
|
495
|
-
serveApiDocs
|
|
595
|
+
serveApiDocs,
|
|
596
|
+
signJwt
|
|
496
597
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../../src/express/rate-limit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI/D,MAAM,WAAW,gBAAgB;IAC/B,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sEAAsE;IACtE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gFAAgF;IAChF,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,CAAC;CACzC;AAKD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB,
|
|
1
|
+
{"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../../src/express/rate-limit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI/D,MAAM,WAAW,gBAAgB;IAC/B,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sEAAsE;IACtE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gFAAgF;IAChF,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,CAAC;CACzC;AAKD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB,SAIb,OAAO,OAAO,QAAQ,QAAQ,YAAY,UASpF"}
|
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
import type { Request, Response, NextFunction } from "express";
|
|
2
2
|
import { type VerifyJwtOptions } from "../auth-core";
|
|
3
3
|
/**
|
|
4
|
-
* Express equivalent of the Hono requireAuth: verifies a bearer
|
|
5
|
-
* stashes the decoded payload on res.locals.auth
|
|
6
|
-
* `c.get("auth")` in a defineRoute handler (BackonContext.get() reads
|
|
7
|
-
* res.locals) or directly as `res.locals.auth` in plain Express middleware.
|
|
8
|
-
* Calls next(AppError(401, "unauthorized")) on a missing, malformed, or
|
|
9
|
-
* invalid token; requires attachErrorHandler(app) to be registered
|
|
10
|
-
* downstream (serve() does this automatically — see create-app.ts).
|
|
11
|
-
*
|
|
12
|
-
* Verification only, same as the Hono version — issuing tokens is left to
|
|
13
|
-
* the consuming project. Apply per-route or per-router, not necessarily
|
|
14
|
-
* globally.
|
|
4
|
+
* Express equivalent of the Hono requireAuth: verifies a bearer (or optional
|
|
5
|
+
* cookie) JWT and stashes the decoded payload on `res.locals.auth`.
|
|
15
6
|
*/
|
|
16
7
|
export declare function requireAuth(options: VerifyJwtOptions): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
17
8
|
//# sourceMappingURL=require-auth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"require-auth.d.ts","sourceRoot":"","sources":["../../src/express/require-auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE/D,OAAO,
|
|
1
|
+
{"version":3,"file":"require-auth.d.ts","sourceRoot":"","sources":["../../src/express/require-auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE/D,OAAO,EAA+B,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAElF;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,gBAAgB,SACF,OAAO,OAAO,QAAQ,QAAQ,YAAY,mBAsB5F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/express/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAE5D,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,KAAK,IAAI,CAAC;AAEhE;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/express/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAE5D,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,KAAK,IAAI,CAAC;AAEhE;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,SAChF,OAAO,OAAO,QAAQ,QAAQ,YAAY,KAAG,OAAO,CAAC,IAAI,CAAC,CAW9E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/express/upload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG/D,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAO5D,MAAM,WAAW,aAAa;IAC5B,wEAAwE;IACxE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,6FAA6F;IAC7F,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,MAAM,MAAM,aAAa,GAAG,CAC1B,CAAC,EAAE,aAAa,EAChB,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAA;CAAE,KACnD,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhC;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/express/upload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG/D,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAO5D,MAAM,WAAW,aAAa;IAC5B,wEAAwE;IACxE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,6FAA6F;IAC7F,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,MAAM,MAAM,aAAa,GAAG,CAC1B,CAAC,EAAE,aAAa,EAChB,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAA;CAAE,KACnD,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhC;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,SAO5D,OAAO,OAAO,QAAQ,QAAQ,YAAY,KAAG,IAAI,CAwB/D"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,10 @@ export type { ErrorResponseBody } from "./error";
|
|
|
8
8
|
export { logger } from "./logger";
|
|
9
9
|
export { requireEnv } from "./require-env";
|
|
10
10
|
export { requireAuth } from "./require-auth";
|
|
11
|
-
export
|
|
11
|
+
export { signJwt } from "./auth-core";
|
|
12
|
+
export type { VerifyJwtOptions, SignJwtOptions } from "./auth-core";
|
|
13
|
+
export { cacheControl } from "./cache-control";
|
|
14
|
+
export type { CacheControlOptions } from "./cache-control";
|
|
12
15
|
export { rateLimit } from "./rate-limit";
|
|
13
16
|
export type { RateLimitOptions } from "./rate-limit";
|
|
14
17
|
export { defineWebSocket } from "./websocket";
|
|
@@ -29,4 +32,5 @@ export type { BackonContext, Env } from "./types";
|
|
|
29
32
|
*/
|
|
30
33
|
export { Hono } from "hono";
|
|
31
34
|
export type { Next } from "hono";
|
|
35
|
+
export { setCookie, getCookie, deleteCookie, setSignedCookie, getSignedCookie } from "hono/cookie";
|
|
32
36
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE3E,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,MAA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