hono 2.1.4 → 2.2.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 +13 -14
- package/dist/cjs/compose.js +48 -0
- package/dist/cjs/context.js +148 -0
- package/dist/cjs/hono.js +154 -0
- package/dist/cjs/index.js +13 -0
- package/dist/cjs/middleware/basic-auth/index.js +48 -0
- package/dist/cjs/middleware/bearer-auth/index.js +57 -0
- package/dist/cjs/middleware/cache/index.js +32 -0
- package/dist/cjs/middleware/compress/index.js +19 -0
- package/dist/cjs/middleware/cors/index.js +75 -0
- package/dist/cjs/middleware/etag/index.js +27 -0
- package/dist/cjs/middleware/html/index.js +36 -0
- package/dist/cjs/middleware/jsx/index.js +193 -0
- package/dist/cjs/middleware/jsx/jsx-dev-runtime.js +10 -0
- package/dist/cjs/middleware/jsx/jsx-runtime.js +7 -0
- package/dist/cjs/middleware/jwt/index.js +63 -0
- package/dist/cjs/middleware/logger/index.js +49 -0
- package/dist/cjs/middleware/powered-by/index.js +10 -0
- package/dist/cjs/middleware/pretty-json/index.js +11 -0
- package/dist/cjs/middleware/serve-static/bun.js +41 -0
- package/dist/cjs/middleware/serve-static/index.js +5 -0
- package/dist/cjs/middleware/serve-static/serve-static.js +40 -0
- package/dist/cjs/middleware/validator/index.js +5 -0
- package/dist/cjs/middleware/validator/middleware.js +56 -0
- package/dist/cjs/middleware/validator/rule.js +66 -0
- package/dist/cjs/middleware/validator/sanitizer.js +6 -0
- package/dist/cjs/middleware/validator/validator.js +195 -0
- package/dist/cjs/request.js +120 -0
- package/dist/cjs/router/reg-exp-router/index.js +5 -0
- package/dist/cjs/router/reg-exp-router/node.js +108 -0
- package/dist/cjs/router/reg-exp-router/router.js +161 -0
- package/dist/cjs/router/reg-exp-router/trie.js +42 -0
- package/dist/cjs/router/smart-router/index.js +5 -0
- package/dist/cjs/router/smart-router/router.js +57 -0
- package/dist/cjs/router/static-router/index.js +5 -0
- package/dist/cjs/router/static-router/router.js +72 -0
- package/dist/cjs/router/trie-router/index.js +5 -0
- package/dist/cjs/router/trie-router/node.js +175 -0
- package/dist/cjs/router/trie-router/router.js +24 -0
- package/dist/cjs/router.js +9 -0
- package/dist/cjs/utils/body.js +18 -0
- package/dist/cjs/utils/buffer.js +39 -0
- package/dist/cjs/utils/cloudflare.js +39 -0
- package/dist/cjs/utils/cookie.js +40 -0
- package/dist/cjs/utils/crypto.js +53 -0
- package/dist/cjs/utils/encode.js +80 -0
- package/dist/cjs/utils/filepath.js +25 -0
- package/dist/cjs/utils/html.js +38 -0
- package/dist/cjs/utils/http-status.js +50 -0
- package/dist/cjs/utils/json.js +22 -0
- package/dist/cjs/utils/jwt/index.js +27 -0
- package/dist/cjs/utils/jwt/jwt.js +101 -0
- package/dist/cjs/utils/jwt/types.js +49 -0
- package/dist/cjs/utils/mime.js +92 -0
- package/dist/cjs/utils/url.js +94 -0
- package/dist/compose.d.ts +2 -2
- package/dist/compose.js +3 -7
- package/dist/context.d.ts +14 -9
- package/dist/context.js +56 -25
- package/dist/hono.d.ts +28 -26
- package/dist/hono.js +23 -22
- package/dist/index.js +3 -6
- package/dist/middleware/basic-auth/index.d.ts +2 -3
- package/dist/middleware/basic-auth/index.js +7 -11
- package/dist/middleware/bearer-auth/index.d.ts +2 -3
- package/dist/middleware/bearer-auth/index.js +4 -12
- package/dist/middleware/cache/index.d.ts +2 -3
- package/dist/middleware/cache/index.js +1 -5
- package/dist/middleware/compress/index.d.ts +2 -3
- package/dist/middleware/compress/index.js +1 -5
- package/dist/middleware/cors/index.d.ts +3 -4
- package/dist/middleware/cors/index.js +16 -6
- package/dist/middleware/etag/index.d.ts +2 -3
- package/dist/middleware/etag/index.js +3 -7
- package/dist/middleware/html/index.js +6 -11
- package/dist/middleware/jsx/index.js +9 -15
- package/dist/middleware/jsx/jsx-dev-runtime.js +3 -7
- package/dist/middleware/jsx/jsx-runtime.js +2 -7
- package/dist/middleware/jwt/index.d.ts +2 -3
- package/dist/middleware/jwt/index.js +3 -7
- package/dist/middleware/logger/index.d.ts +2 -3
- package/dist/middleware/logger/index.js +3 -7
- package/dist/middleware/powered-by/index.d.ts +2 -3
- package/dist/middleware/powered-by/index.js +1 -5
- package/dist/middleware/pretty-json/index.d.ts +2 -3
- package/dist/middleware/pretty-json/index.js +1 -5
- package/dist/middleware/serve-static/bun.d.ts +2 -3
- package/dist/middleware/serve-static/bun.js +18 -19
- package/dist/middleware/serve-static/index.js +1 -5
- package/dist/middleware/serve-static/module.d.mts +1 -1
- package/dist/middleware/serve-static/serve-static.d.ts +2 -3
- package/dist/middleware/serve-static/serve-static.js +7 -11
- package/dist/middleware/validator/index.d.ts +2 -0
- package/dist/middleware/validator/index.js +2 -0
- package/dist/middleware/validator/middleware.d.ts +21 -0
- package/dist/middleware/validator/middleware.js +52 -0
- package/dist/middleware/validator/rule.d.ts +21 -0
- package/dist/middleware/validator/rule.js +63 -0
- package/dist/middleware/validator/sanitizer.d.ts +3 -0
- package/dist/middleware/validator/sanitizer.js +3 -0
- package/dist/middleware/validator/validator.d.ts +75 -0
- package/dist/middleware/validator/validator.js +186 -0
- package/dist/request.d.ts +15 -5
- package/dist/request.js +58 -28
- package/dist/router/reg-exp-router/index.js +1 -5
- package/dist/router/reg-exp-router/node.d.ts +1 -3
- package/dist/router/reg-exp-router/node.js +21 -17
- package/dist/router/reg-exp-router/router.d.ts +3 -27
- package/dist/router/reg-exp-router/router.js +105 -315
- package/dist/router/reg-exp-router/trie.d.ts +0 -4
- package/dist/router/reg-exp-router/trie.js +4 -8
- package/dist/router/smart-router/index.d.ts +1 -0
- package/dist/router/smart-router/index.js +1 -0
- package/dist/router/smart-router/router.d.ts +9 -0
- package/dist/router/smart-router/router.js +53 -0
- package/dist/router/static-router/index.d.ts +1 -0
- package/dist/router/static-router/index.js +1 -0
- package/dist/router/static-router/router.d.ts +8 -0
- package/dist/router/static-router/router.js +68 -0
- package/dist/router/trie-router/index.js +1 -5
- package/dist/router/trie-router/node.js +7 -11
- package/dist/router/trie-router/router.js +11 -7
- package/dist/router.d.ts +3 -0
- package/dist/router.js +5 -5
- package/dist/utils/body.d.ts +2 -1
- package/dist/utils/body.js +1 -5
- package/dist/utils/buffer.d.ts +1 -1
- package/dist/utils/buffer.js +5 -11
- package/dist/utils/cloudflare.d.ts +1 -1
- package/dist/utils/cloudflare.js +1 -5
- package/dist/utils/cookie.js +2 -7
- package/dist/utils/crypto.js +8 -15
- package/dist/utils/encode.js +10 -20
- package/dist/utils/filepath.js +1 -5
- package/dist/utils/html.js +1 -5
- package/dist/utils/http-status.js +1 -5
- package/dist/utils/json.d.ts +1 -0
- package/dist/utils/json.js +18 -0
- package/dist/utils/jwt/index.js +1 -27
- package/dist/utils/jwt/jwt.js +22 -28
- package/dist/utils/jwt/types.js +8 -16
- package/dist/utils/mime.js +1 -5
- package/dist/utils/url.d.ts +1 -1
- package/dist/utils/url.js +18 -22
- package/package.json +122 -35
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Node = void 0;
|
|
4
|
-
const router_1 = require("../../router");
|
|
5
|
-
const url_1 = require("../../utils/url");
|
|
1
|
+
import { METHOD_NAME_ALL } from '../../router';
|
|
2
|
+
import { splitPath, getPattern } from '../../utils/url';
|
|
6
3
|
function findParam(node, name) {
|
|
7
4
|
for (let i = 0, len = node.patterns.length; i < len; i++) {
|
|
8
5
|
if (typeof node.patterns[i] === 'object' && node.patterns[i][1] === name) {
|
|
@@ -17,7 +14,7 @@ function findParam(node, name) {
|
|
|
17
14
|
}
|
|
18
15
|
return false;
|
|
19
16
|
}
|
|
20
|
-
class Node {
|
|
17
|
+
export class Node {
|
|
21
18
|
constructor(method, handler, children) {
|
|
22
19
|
this.order = 0;
|
|
23
20
|
this.children = children || {};
|
|
@@ -36,7 +33,7 @@ class Node {
|
|
|
36
33
|
this.order = ++this.order;
|
|
37
34
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
38
35
|
let curNode = this;
|
|
39
|
-
const parts =
|
|
36
|
+
const parts = splitPath(path);
|
|
40
37
|
const parentPatterns = [];
|
|
41
38
|
const errorMessage = (name) => {
|
|
42
39
|
return `Duplicate param name, use another name instead of '${name}' - ${method} ${path} <--- '${name}'`;
|
|
@@ -49,7 +46,7 @@ class Node {
|
|
|
49
46
|
continue;
|
|
50
47
|
}
|
|
51
48
|
curNode.children[p] = new Node();
|
|
52
|
-
const pattern =
|
|
49
|
+
const pattern = getPattern(p);
|
|
53
50
|
if (pattern) {
|
|
54
51
|
if (typeof pattern === 'object') {
|
|
55
52
|
for (let j = 0, len = parentPatterns.length; j < len; j++) {
|
|
@@ -82,7 +79,7 @@ class Node {
|
|
|
82
79
|
const handlerSets = [];
|
|
83
80
|
for (let i = 0, len = node.methods.length; i < len; i++) {
|
|
84
81
|
const m = node.methods[i];
|
|
85
|
-
const handlerSet = m[method] || m[
|
|
82
|
+
const handlerSet = m[method] || m[METHOD_NAME_ALL];
|
|
86
83
|
if (handlerSet !== undefined) {
|
|
87
84
|
handlerSets.push(handlerSet);
|
|
88
85
|
}
|
|
@@ -96,7 +93,7 @@ class Node {
|
|
|
96
93
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
97
94
|
const curNode = this;
|
|
98
95
|
let curNodes = [curNode];
|
|
99
|
-
const parts =
|
|
96
|
+
const parts = splitPath(path);
|
|
100
97
|
for (let i = 0, len = parts.length; i < len; i++) {
|
|
101
98
|
const part = parts[i];
|
|
102
99
|
const isLast = i === len - 1;
|
|
@@ -172,4 +169,3 @@ class Node {
|
|
|
172
169
|
return { handlers, params };
|
|
173
170
|
}
|
|
174
171
|
}
|
|
175
|
-
exports.Node = Node;
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const node_1 = require("./node");
|
|
5
|
-
class TrieRouter {
|
|
1
|
+
import { checkOptionalParameter } from '../../utils/url';
|
|
2
|
+
import { Node } from './node';
|
|
3
|
+
export class TrieRouter {
|
|
6
4
|
constructor() {
|
|
7
|
-
this.node = new
|
|
5
|
+
this.node = new Node();
|
|
8
6
|
}
|
|
9
7
|
add(method, path, handler) {
|
|
8
|
+
const results = checkOptionalParameter(path);
|
|
9
|
+
if (results) {
|
|
10
|
+
for (const p of results) {
|
|
11
|
+
this.node.insert(method, p, handler);
|
|
12
|
+
}
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
10
15
|
this.node.insert(method, path, handler);
|
|
11
16
|
}
|
|
12
17
|
match(method, path) {
|
|
13
18
|
return this.node.search(method, path);
|
|
14
19
|
}
|
|
15
20
|
}
|
|
16
|
-
exports.TrieRouter = TrieRouter;
|
package/dist/router.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const METHOD_NAME_ALL: "ALL";
|
|
2
2
|
export declare const METHOD_NAME_ALL_LOWERCASE: "all";
|
|
3
|
+
export declare const METHODS: readonly ["get", "post", "put", "delete", "head", "options", "patch"];
|
|
3
4
|
export interface Router<T> {
|
|
4
5
|
add(method: string, path: string, handler: T): void;
|
|
5
6
|
match(method: string, path: string): Result<T> | null;
|
|
@@ -8,3 +9,5 @@ export interface Result<T> {
|
|
|
8
9
|
handlers: T[];
|
|
9
10
|
params: Record<string, string>;
|
|
10
11
|
}
|
|
12
|
+
export declare class UnsupportedPathError extends Error {
|
|
13
|
+
}
|
package/dist/router.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export const METHOD_NAME_ALL = 'ALL';
|
|
2
|
+
export const METHOD_NAME_ALL_LOWERCASE = 'all';
|
|
3
|
+
export const METHODS = ['get', 'post', 'put', 'delete', 'head', 'options', 'patch'];
|
|
4
|
+
export class UnsupportedPathError extends Error {
|
|
5
|
+
}
|
package/dist/utils/body.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare type BodyData = Record<string, string | number | boolean | File>;
|
|
2
|
+
export declare function parseBody<BodyType extends BodyData>(r: Request | Response): Promise<BodyType>;
|
package/dist/utils/body.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseBody = void 0;
|
|
4
|
-
async function parseBody(r) {
|
|
1
|
+
export async function parseBody(r) {
|
|
5
2
|
let body = {};
|
|
6
3
|
const contentType = r.headers.get('Content-Type');
|
|
7
4
|
if (contentType &&
|
|
@@ -15,4 +12,3 @@ async function parseBody(r) {
|
|
|
15
12
|
}
|
|
16
13
|
return body;
|
|
17
14
|
}
|
|
18
|
-
exports.parseBody = parseBody;
|
package/dist/utils/buffer.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const equal: (a: ArrayBuffer, b: ArrayBuffer) => boolean;
|
|
2
|
-
export declare const timingSafeEqual: (a: string | object | boolean, b: string | object | boolean, hashFunction?: Function
|
|
2
|
+
export declare const timingSafeEqual: (a: string | object | boolean, b: string | object | boolean, hashFunction?: Function) => Promise<boolean>;
|
|
3
3
|
export declare const bufferToString: (buffer: ArrayBuffer) => string;
|
package/dist/utils/buffer.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.bufferToString = exports.timingSafeEqual = exports.equal = void 0;
|
|
4
|
-
const crypto_1 = require("./crypto");
|
|
5
|
-
const equal = (a, b) => {
|
|
1
|
+
import { sha256 } from './crypto';
|
|
2
|
+
export const equal = (a, b) => {
|
|
6
3
|
if (a === b) {
|
|
7
4
|
return true;
|
|
8
5
|
}
|
|
@@ -19,21 +16,18 @@ const equal = (a, b) => {
|
|
|
19
16
|
}
|
|
20
17
|
return true;
|
|
21
18
|
};
|
|
22
|
-
|
|
23
|
-
const timingSafeEqual = async (a, b, hashFunction) => {
|
|
19
|
+
export const timingSafeEqual = async (a, b, hashFunction) => {
|
|
24
20
|
if (!hashFunction) {
|
|
25
|
-
hashFunction =
|
|
21
|
+
hashFunction = sha256;
|
|
26
22
|
}
|
|
27
23
|
const sa = await hashFunction(a);
|
|
28
24
|
const sb = await hashFunction(b);
|
|
29
25
|
return sa === sb && a === b;
|
|
30
26
|
};
|
|
31
|
-
|
|
32
|
-
const bufferToString = (buffer) => {
|
|
27
|
+
export const bufferToString = (buffer) => {
|
|
33
28
|
if (buffer instanceof ArrayBuffer) {
|
|
34
29
|
const enc = new TextDecoder('utf-8');
|
|
35
30
|
return enc.decode(buffer);
|
|
36
31
|
}
|
|
37
32
|
return buffer;
|
|
38
33
|
};
|
|
39
|
-
exports.bufferToString = bufferToString;
|
|
@@ -3,4 +3,4 @@ export declare type KVAssetOptions = {
|
|
|
3
3
|
manifest?: object | string;
|
|
4
4
|
namespace?: KVNamespace;
|
|
5
5
|
};
|
|
6
|
-
export declare const getContentFromKVAsset: (path: string, options?: KVAssetOptions
|
|
6
|
+
export declare const getContentFromKVAsset: (path: string, options?: KVAssetOptions) => Promise<ArrayBuffer | null>;
|
package/dist/utils/cloudflare.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getContentFromKVAsset = void 0;
|
|
4
|
-
const getContentFromKVAsset = async (path, options) => {
|
|
1
|
+
export const getContentFromKVAsset = async (path, options) => {
|
|
5
2
|
let ASSET_MANIFEST = {};
|
|
6
3
|
if (options && options.manifest) {
|
|
7
4
|
if (typeof options.manifest === 'string') {
|
|
@@ -36,4 +33,3 @@ const getContentFromKVAsset = async (path, options) => {
|
|
|
36
33
|
}
|
|
37
34
|
return content;
|
|
38
35
|
};
|
|
39
|
-
exports.getContentFromKVAsset = getContentFromKVAsset;
|
package/dist/utils/cookie.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.serialize = exports.parse = void 0;
|
|
4
|
-
const parse = (cookie) => {
|
|
1
|
+
export const parse = (cookie) => {
|
|
5
2
|
const pairs = cookie.split(/;\s*/g);
|
|
6
3
|
const parsedCookie = {};
|
|
7
4
|
for (let i = 0, len = pairs.length; i < len; i++) {
|
|
@@ -10,8 +7,7 @@ const parse = (cookie) => {
|
|
|
10
7
|
}
|
|
11
8
|
return parsedCookie;
|
|
12
9
|
};
|
|
13
|
-
|
|
14
|
-
const serialize = (name, value, opt = {}) => {
|
|
10
|
+
export const serialize = (name, value, opt = {}) => {
|
|
15
11
|
value = encodeURIComponent(value);
|
|
16
12
|
let cookie = `${name}=${value}`;
|
|
17
13
|
if (opt.maxAge) {
|
|
@@ -37,4 +33,3 @@ const serialize = (name, value, opt = {}) => {
|
|
|
37
33
|
}
|
|
38
34
|
return cookie;
|
|
39
35
|
};
|
|
40
|
-
exports.serialize = serialize;
|
package/dist/utils/crypto.js
CHANGED
|
@@ -1,31 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createHash = exports.md5 = exports.sha1 = exports.sha256 = void 0;
|
|
4
|
-
const sha256 = async (data) => {
|
|
1
|
+
export const sha256 = async (data) => {
|
|
5
2
|
const algorithm = { name: 'SHA-256', alias: 'sha256' };
|
|
6
|
-
const hash = await
|
|
3
|
+
const hash = await createHash(data, algorithm);
|
|
7
4
|
return hash;
|
|
8
5
|
};
|
|
9
|
-
|
|
10
|
-
const sha1 = async (data) => {
|
|
6
|
+
export const sha1 = async (data) => {
|
|
11
7
|
const algorithm = { name: 'SHA-1', alias: 'sha1' };
|
|
12
|
-
const hash = await
|
|
8
|
+
const hash = await createHash(data, algorithm);
|
|
13
9
|
return hash;
|
|
14
10
|
};
|
|
15
|
-
|
|
16
|
-
const md5 = async (data) => {
|
|
11
|
+
export const md5 = async (data) => {
|
|
17
12
|
const algorithm = { name: 'MD5', alias: 'md5' };
|
|
18
|
-
const hash = await
|
|
13
|
+
const hash = await createHash(data, algorithm);
|
|
19
14
|
return hash;
|
|
20
15
|
};
|
|
21
|
-
|
|
22
|
-
const createHash = async (data, algorithm) => {
|
|
16
|
+
export const createHash = async (data, algorithm) => {
|
|
23
17
|
let sourceBuffer;
|
|
24
18
|
if (data instanceof ReadableStream) {
|
|
25
19
|
let body = '';
|
|
26
20
|
const reader = data.getReader();
|
|
27
21
|
await reader?.read().then(async (chuck) => {
|
|
28
|
-
const value = await
|
|
22
|
+
const value = await createHash(chuck.value || '', algorithm);
|
|
29
23
|
body += value;
|
|
30
24
|
});
|
|
31
25
|
return body;
|
|
@@ -50,4 +44,3 @@ const createHash = async (data, algorithm) => {
|
|
|
50
44
|
}
|
|
51
45
|
return null;
|
|
52
46
|
};
|
|
53
|
-
exports.createHash = createHash;
|
package/dist/utils/encode.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.arrayBufferToBase64URL = exports.arrayBufferToBase64 = exports.utf8ToUint8Array = exports.decodeBase64URL = exports.encodeBase64URL = exports.decodeBase64 = exports.encodeBase64 = void 0;
|
|
4
|
-
const encodeBase64 = (str) => {
|
|
1
|
+
export const encodeBase64 = (str) => {
|
|
5
2
|
if (str === null) {
|
|
6
3
|
throw new TypeError('1st argument of "encodeBase64" should not be null.');
|
|
7
4
|
}
|
|
@@ -19,8 +16,7 @@ const encodeBase64 = (str) => {
|
|
|
19
16
|
throw e;
|
|
20
17
|
}
|
|
21
18
|
};
|
|
22
|
-
|
|
23
|
-
const decodeBase64 = (str) => {
|
|
19
|
+
export const decodeBase64 = (str) => {
|
|
24
20
|
if (str === null) {
|
|
25
21
|
throw new TypeError('1st argument of "decodeBase64" should not be null.');
|
|
26
22
|
}
|
|
@@ -39,12 +35,10 @@ const decodeBase64 = (str) => {
|
|
|
39
35
|
throw e;
|
|
40
36
|
}
|
|
41
37
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return (0, exports.encodeBase64)(str).replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
|
|
38
|
+
export const encodeBase64URL = (str) => {
|
|
39
|
+
return encodeBase64(str).replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
|
|
45
40
|
};
|
|
46
|
-
|
|
47
|
-
const decodeBase64URL = (str) => {
|
|
41
|
+
export const decodeBase64URL = (str) => {
|
|
48
42
|
const pad = (s) => {
|
|
49
43
|
const diff = s.length % 4;
|
|
50
44
|
if (diff === 2) {
|
|
@@ -55,15 +49,13 @@ const decodeBase64URL = (str) => {
|
|
|
55
49
|
}
|
|
56
50
|
return s;
|
|
57
51
|
};
|
|
58
|
-
return
|
|
52
|
+
return decodeBase64(pad(str).replace(/-/g, '+').replace('_', '/'));
|
|
59
53
|
};
|
|
60
|
-
|
|
61
|
-
const utf8ToUint8Array = (str) => {
|
|
54
|
+
export const utf8ToUint8Array = (str) => {
|
|
62
55
|
const encoder = new TextEncoder();
|
|
63
56
|
return encoder.encode(str);
|
|
64
57
|
};
|
|
65
|
-
|
|
66
|
-
const arrayBufferToBase64 = async (buf) => {
|
|
58
|
+
export const arrayBufferToBase64 = async (buf) => {
|
|
67
59
|
if (typeof btoa === 'function') {
|
|
68
60
|
return btoa(String.fromCharCode(...new Uint8Array(buf)));
|
|
69
61
|
}
|
|
@@ -73,8 +65,6 @@ const arrayBufferToBase64 = async (buf) => {
|
|
|
73
65
|
catch (e) { }
|
|
74
66
|
return '';
|
|
75
67
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return (await (0, exports.arrayBufferToBase64)(buf)).replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
|
|
68
|
+
export const arrayBufferToBase64URL = async (buf) => {
|
|
69
|
+
return (await arrayBufferToBase64(buf)).replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
|
|
79
70
|
};
|
|
80
|
-
exports.arrayBufferToBase64URL = arrayBufferToBase64URL;
|
package/dist/utils/filepath.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFilePath = void 0;
|
|
4
|
-
const getFilePath = (options) => {
|
|
1
|
+
export const getFilePath = (options) => {
|
|
5
2
|
let filename = options.filename;
|
|
6
3
|
let root = options.root || '';
|
|
7
4
|
const defaultDocument = options.defaultDocument || 'index.html';
|
|
@@ -22,4 +19,3 @@ const getFilePath = (options) => {
|
|
|
22
19
|
path = path.replace(/^\.?\//, '');
|
|
23
20
|
return path;
|
|
24
21
|
};
|
|
25
|
-
exports.getFilePath = getFilePath;
|
package/dist/utils/html.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.escapeToBuffer = void 0;
|
|
4
1
|
// The `escapeToBuffer` implementation is based on code from the MIT licensed `react-dom` package.
|
|
5
2
|
// https://github.com/facebook/react/blob/main/packages/react-dom/src/server/escapeTextForBrowser.js
|
|
6
3
|
const escapeRe = /[&<>"]/;
|
|
7
|
-
const escapeToBuffer = (str, buffer) => {
|
|
4
|
+
export const escapeToBuffer = (str, buffer) => {
|
|
8
5
|
const match = str.search(escapeRe);
|
|
9
6
|
if (match === -1) {
|
|
10
7
|
buffer[0] += str;
|
|
@@ -35,4 +32,3 @@ const escapeToBuffer = (str, buffer) => {
|
|
|
35
32
|
}
|
|
36
33
|
buffer[0] += str.substring(lastIndex, index);
|
|
37
34
|
};
|
|
38
|
-
exports.escapeToBuffer = escapeToBuffer;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getStatusText = void 0;
|
|
4
|
-
const getStatusText = (statusCode) => {
|
|
1
|
+
export const getStatusText = (statusCode) => {
|
|
5
2
|
const text = statuses[statusCode];
|
|
6
3
|
return text;
|
|
7
4
|
};
|
|
8
|
-
exports.getStatusText = getStatusText;
|
|
9
5
|
const statuses = {
|
|
10
6
|
100: 'Continue',
|
|
11
7
|
101: 'Switching Protocols',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const JSONPath: (data: object, path: string) => any;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const JSONPath = (data, path) => {
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3
|
+
let val = data;
|
|
4
|
+
const parts = path.split('.');
|
|
5
|
+
const length = parts.length;
|
|
6
|
+
for (let i = 0; i < length && val !== undefined; i++) {
|
|
7
|
+
const p = parts[i];
|
|
8
|
+
if (p !== '') {
|
|
9
|
+
if (typeof val === 'object') {
|
|
10
|
+
val = val[p];
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
val = undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return val;
|
|
18
|
+
};
|
package/dist/utils/jwt/index.js
CHANGED
|
@@ -1,27 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.Jwt = void 0;
|
|
27
|
-
exports.Jwt = __importStar(require("./jwt"));
|
|
1
|
+
export * as Jwt from './jwt';
|
package/dist/utils/jwt/jwt.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const encode_1 = require("../../utils/encode");
|
|
5
|
-
const types_1 = require("./types");
|
|
6
|
-
const types_2 = require("./types");
|
|
1
|
+
import { utf8ToUint8Array, encodeBase64URL, arrayBufferToBase64URL, decodeBase64URL, } from '../../utils/encode';
|
|
2
|
+
import { AlgorithmTypes } from './types';
|
|
3
|
+
import { JwtTokenInvalid, JwtTokenNotBefore, JwtTokenExpired, JwtTokenSignatureMismatched, JwtAlgorithmNotImplemented, } from './types';
|
|
7
4
|
var CryptoKeyFormat;
|
|
8
5
|
(function (CryptoKeyFormat) {
|
|
9
6
|
CryptoKeyFormat["RAW"] = "raw";
|
|
@@ -46,56 +43,53 @@ const param = (name) => {
|
|
|
46
43
|
},
|
|
47
44
|
};
|
|
48
45
|
default:
|
|
49
|
-
throw new
|
|
46
|
+
throw new JwtAlgorithmNotImplemented(name);
|
|
50
47
|
}
|
|
51
48
|
};
|
|
52
|
-
const signing = async (data, secret, alg =
|
|
49
|
+
const signing = async (data, secret, alg = AlgorithmTypes.HS256) => {
|
|
53
50
|
if (!crypto.subtle || !crypto.subtle.importKey) {
|
|
54
51
|
throw new Error('`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.');
|
|
55
52
|
}
|
|
56
|
-
const cryptoKey = await crypto.subtle.importKey(CryptoKeyFormat.RAW,
|
|
57
|
-
return await crypto.subtle.sign(param(alg), cryptoKey,
|
|
53
|
+
const cryptoKey = await crypto.subtle.importKey(CryptoKeyFormat.RAW, utf8ToUint8Array(secret), param(alg), false, [CryptoKeyUsage.Sign]);
|
|
54
|
+
return await crypto.subtle.sign(param(alg), cryptoKey, utf8ToUint8Array(data));
|
|
58
55
|
};
|
|
59
|
-
const sign = async (payload, secret, alg =
|
|
60
|
-
const encodedPayload = await
|
|
61
|
-
const encodedHeader = await
|
|
56
|
+
export const sign = async (payload, secret, alg = AlgorithmTypes.HS256) => {
|
|
57
|
+
const encodedPayload = await encodeBase64URL(JSON.stringify(payload));
|
|
58
|
+
const encodedHeader = await encodeBase64URL(JSON.stringify({ alg, typ: 'JWT' }));
|
|
62
59
|
const partialToken = `${encodedHeader}.${encodedPayload}`;
|
|
63
|
-
const signature = await
|
|
60
|
+
const signature = await arrayBufferToBase64URL(await signing(partialToken, secret, alg));
|
|
64
61
|
return `${partialToken}.${signature}`;
|
|
65
62
|
};
|
|
66
|
-
|
|
67
|
-
const verify = async (token, secret, alg = types_1.AlgorithmTypes.HS256) => {
|
|
63
|
+
export const verify = async (token, secret, alg = AlgorithmTypes.HS256) => {
|
|
68
64
|
const tokenParts = token.split('.');
|
|
69
65
|
if (tokenParts.length !== 3) {
|
|
70
|
-
throw new
|
|
66
|
+
throw new JwtTokenInvalid(token);
|
|
71
67
|
}
|
|
72
|
-
const { payload } =
|
|
68
|
+
const { payload } = decode(token);
|
|
73
69
|
if (payload.nbf && payload.nbf > Math.floor(Date.now() / 1000)) {
|
|
74
|
-
throw new
|
|
70
|
+
throw new JwtTokenNotBefore(token);
|
|
75
71
|
}
|
|
76
72
|
if (payload.exp && payload.exp <= Math.floor(Date.now() / 1000)) {
|
|
77
|
-
throw new
|
|
73
|
+
throw new JwtTokenExpired(token);
|
|
78
74
|
}
|
|
79
|
-
const signature = await
|
|
75
|
+
const signature = await arrayBufferToBase64URL(await signing(tokenParts.slice(0, 2).join('.'), secret, alg));
|
|
80
76
|
if (signature !== tokenParts[2]) {
|
|
81
|
-
throw new
|
|
77
|
+
throw new JwtTokenSignatureMismatched(token);
|
|
82
78
|
}
|
|
83
79
|
return true;
|
|
84
80
|
};
|
|
85
|
-
exports.verify = verify;
|
|
86
81
|
// eslint-disable-next-line
|
|
87
|
-
const decode = (token) => {
|
|
82
|
+
export const decode = (token) => {
|
|
88
83
|
try {
|
|
89
84
|
const [h, p] = token.split('.');
|
|
90
|
-
const header = JSON.parse(
|
|
91
|
-
const payload = JSON.parse(
|
|
85
|
+
const header = JSON.parse(decodeBase64URL(h));
|
|
86
|
+
const payload = JSON.parse(decodeBase64URL(p));
|
|
92
87
|
return {
|
|
93
88
|
header,
|
|
94
89
|
payload,
|
|
95
90
|
};
|
|
96
91
|
}
|
|
97
92
|
catch (e) {
|
|
98
|
-
throw new
|
|
93
|
+
throw new JwtTokenInvalid(token);
|
|
99
94
|
}
|
|
100
95
|
};
|
|
101
|
-
exports.decode = decode;
|
package/dist/utils/jwt/types.js
CHANGED
|
@@ -1,49 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AlgorithmTypes = exports.JwtTokenSignatureMismatched = exports.JwtTokenExpired = exports.JwtTokenNotBefore = exports.JwtTokenInvalid = exports.JwtAlorithmNotImplemented = exports.JwtAlgorithmNotImplemented = void 0;
|
|
4
|
-
class JwtAlgorithmNotImplemented extends Error {
|
|
1
|
+
export class JwtAlgorithmNotImplemented extends Error {
|
|
5
2
|
constructor(token) {
|
|
6
3
|
super(`invalid JWT token: ${token}`);
|
|
7
4
|
this.name = 'JwtAlgorithmNotImplemented';
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
exports.JwtAlgorithmNotImplemented = JwtAlgorithmNotImplemented;
|
|
11
7
|
/**
|
|
12
8
|
* Export for backward compatibility
|
|
13
9
|
* @deprecated Use JwtAlgorithmNotImplemented instead
|
|
14
10
|
**/
|
|
15
|
-
|
|
16
|
-
class JwtTokenInvalid extends Error {
|
|
11
|
+
export const JwtAlorithmNotImplemented = JwtAlgorithmNotImplemented;
|
|
12
|
+
export class JwtTokenInvalid extends Error {
|
|
17
13
|
constructor(token) {
|
|
18
14
|
super(`invalid JWT token: ${token}`);
|
|
19
15
|
this.name = 'JwtTokenInvalid';
|
|
20
16
|
}
|
|
21
17
|
}
|
|
22
|
-
|
|
23
|
-
class JwtTokenNotBefore extends Error {
|
|
18
|
+
export class JwtTokenNotBefore extends Error {
|
|
24
19
|
constructor(token) {
|
|
25
20
|
super(`token (${token}) is being used before it's valid`);
|
|
26
21
|
this.name = 'JwtTokenNotBefore';
|
|
27
22
|
}
|
|
28
23
|
}
|
|
29
|
-
|
|
30
|
-
class JwtTokenExpired extends Error {
|
|
24
|
+
export class JwtTokenExpired extends Error {
|
|
31
25
|
constructor(token) {
|
|
32
26
|
super(`token (${token}) expired`);
|
|
33
27
|
this.name = 'JwtTokenExpired';
|
|
34
28
|
}
|
|
35
29
|
}
|
|
36
|
-
|
|
37
|
-
class JwtTokenSignatureMismatched extends Error {
|
|
30
|
+
export class JwtTokenSignatureMismatched extends Error {
|
|
38
31
|
constructor(token) {
|
|
39
32
|
super(`token(${token}) signature mismatched`);
|
|
40
33
|
this.name = 'JwtTokenSignatureMismatched';
|
|
41
34
|
}
|
|
42
35
|
}
|
|
43
|
-
|
|
44
|
-
var AlgorithmTypes;
|
|
36
|
+
export var AlgorithmTypes;
|
|
45
37
|
(function (AlgorithmTypes) {
|
|
46
38
|
AlgorithmTypes["HS256"] = "HS256";
|
|
47
39
|
AlgorithmTypes["HS384"] = "HS384";
|
|
48
40
|
AlgorithmTypes["HS512"] = "HS512";
|
|
49
|
-
})(AlgorithmTypes
|
|
41
|
+
})(AlgorithmTypes || (AlgorithmTypes = {}));
|
package/dist/utils/mime.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMimeType = void 0;
|
|
4
|
-
const getMimeType = (filename) => {
|
|
1
|
+
export const getMimeType = (filename) => {
|
|
5
2
|
const regexp = /\.([a-zA-Z0-9]+?)$/;
|
|
6
3
|
const match = filename.match(regexp);
|
|
7
4
|
if (!match)
|
|
@@ -12,7 +9,6 @@ const getMimeType = (filename) => {
|
|
|
12
9
|
}
|
|
13
10
|
return mimeType;
|
|
14
11
|
};
|
|
15
|
-
exports.getMimeType = getMimeType;
|
|
16
12
|
const mimes = {
|
|
17
13
|
aac: 'audio/aac',
|
|
18
14
|
abw: 'application/x-abiword',
|
package/dist/utils/url.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export declare const splitPath: (path: string) => string[];
|
|
|
3
3
|
export declare const getPattern: (label: string) => Pattern | null;
|
|
4
4
|
export declare const getPathFromURL: (url: string, strict?: boolean) => string;
|
|
5
5
|
export declare const getQueryStringFromURL: (url: string) => string;
|
|
6
|
-
export declare const isAbsoluteURL: (url: string) => boolean;
|
|
7
6
|
export declare const mergePath: (...paths: string[]) => string;
|
|
7
|
+
export declare const checkOptionalParameter: (path: string) => string[] | null;
|