hono 1.0.0 → 1.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.
Files changed (43) hide show
  1. package/README.md +189 -125
  2. package/dist/compose.d.ts +2 -2
  3. package/dist/compose.js +20 -8
  4. package/dist/context.d.ts +4 -5
  5. package/dist/context.js +5 -17
  6. package/dist/hono.d.ts +51 -25
  7. package/dist/hono.js +106 -49
  8. package/dist/index.d.ts +2 -2
  9. package/dist/index.js +2 -1
  10. package/dist/middleware/basic-auth/index.js +11 -10
  11. package/dist/middleware/body-parse/index.d.ts +5 -0
  12. package/dist/middleware/cookie/index.d.ts +1 -3
  13. package/dist/middleware/graphql-server/parse-body.d.ts +1 -3
  14. package/dist/middleware/jwt/index.d.ts +6 -0
  15. package/dist/middleware/jwt/index.js +49 -0
  16. package/dist/middleware/logger/index.js +3 -5
  17. package/dist/middleware/mustache/index.js +3 -9
  18. package/dist/router/reg-exp-router/node.d.ts +3 -0
  19. package/dist/router/reg-exp-router/node.js +13 -7
  20. package/dist/router/reg-exp-router/router.d.ts +21 -2
  21. package/dist/router/reg-exp-router/router.js +300 -80
  22. package/dist/router/reg-exp-router/trie.d.ts +4 -0
  23. package/dist/router/reg-exp-router/trie.js +2 -2
  24. package/dist/router/trie-router/node.d.ts +4 -3
  25. package/dist/router/trie-router/node.js +123 -55
  26. package/dist/router/trie-router/router.d.ts +1 -1
  27. package/dist/router.d.ts +4 -3
  28. package/dist/router.js +5 -4
  29. package/dist/utils/body.js +2 -2
  30. package/dist/utils/buffer.d.ts +1 -0
  31. package/dist/utils/buffer.js +9 -1
  32. package/dist/utils/crypto.d.ts +0 -2
  33. package/dist/utils/crypto.js +1 -51
  34. package/dist/utils/encode.d.ts +7 -0
  35. package/dist/utils/encode.js +105 -0
  36. package/dist/utils/jwt/index.d.ts +1 -0
  37. package/dist/utils/jwt/index.js +27 -0
  38. package/dist/utils/jwt/jwt.d.ts +7 -0
  39. package/dist/utils/jwt/jwt.js +98 -0
  40. package/dist/utils/jwt/types.d.ts +20 -0
  41. package/dist/utils/jwt/types.js +44 -0
  42. package/dist/utils/url.js +4 -4
  43. package/package.json +29 -21
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AlgorithmTypes = exports.JwtTokenSignatureMismatched = exports.JwtTokenExpired = exports.JwtTokenNotBefore = exports.JwtTokenInvalid = exports.JwtAlorithmNotImplemented = void 0;
4
+ class JwtAlorithmNotImplemented extends Error {
5
+ constructor(token) {
6
+ super(`invalid JWT token: ${token}`);
7
+ this.name = 'JwtAlorithmNotImplemented';
8
+ }
9
+ }
10
+ exports.JwtAlorithmNotImplemented = JwtAlorithmNotImplemented;
11
+ class JwtTokenInvalid extends Error {
12
+ constructor(token) {
13
+ super(`invalid JWT token: ${token}`);
14
+ this.name = 'JwtTokenInvalid';
15
+ }
16
+ }
17
+ exports.JwtTokenInvalid = JwtTokenInvalid;
18
+ class JwtTokenNotBefore extends Error {
19
+ constructor(token) {
20
+ super(`token (${token}) is being used before it's valid`);
21
+ this.name = 'JwtTokenNotBefore';
22
+ }
23
+ }
24
+ exports.JwtTokenNotBefore = JwtTokenNotBefore;
25
+ class JwtTokenExpired extends Error {
26
+ constructor(token) {
27
+ super(`token (${token}) expired`);
28
+ this.name = 'JwtTokenExpired';
29
+ }
30
+ }
31
+ exports.JwtTokenExpired = JwtTokenExpired;
32
+ class JwtTokenSignatureMismatched extends Error {
33
+ constructor(token) {
34
+ super(`token(${token}) signature mismatched`);
35
+ this.name = 'JwtTokenSignatureMismatched';
36
+ }
37
+ }
38
+ exports.JwtTokenSignatureMismatched = JwtTokenSignatureMismatched;
39
+ var AlgorithmTypes;
40
+ (function (AlgorithmTypes) {
41
+ AlgorithmTypes["HS256"] = "HS256";
42
+ AlgorithmTypes["HS384"] = "HS384";
43
+ AlgorithmTypes["HS512"] = "HS512";
44
+ })(AlgorithmTypes = exports.AlgorithmTypes || (exports.AlgorithmTypes = {}));
package/dist/utils/url.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mergePath = exports.isAbsoluteURL = exports.getPathFromURL = exports.getPattern = exports.splitPath = void 0;
4
- const URL_REGEXP = /^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
4
+ const URL_REGEXP = /^https?:\/\/[a-zA-Z0-9\-\.:]+(\/?[^?#]*)/;
5
5
  const splitPath = (path) => {
6
6
  const paths = path.split(/\//); // faster than path.split('/')
7
7
  if (paths[0] === '') {
@@ -37,19 +37,19 @@ exports.getPattern = getPattern;
37
37
  const getPathFromURL = (url, params = { strict: true }) => {
38
38
  // if strict routing is false => `/hello/hey/` and `/hello/hey` are treated the same
39
39
  // default is true
40
- if (!params.strict && url.endsWith('/')) {
40
+ if (params.strict === false && url.endsWith('/')) {
41
41
  url = url.slice(0, -1);
42
42
  }
43
43
  const match = url.match(URL_REGEXP);
44
44
  if (match) {
45
- return match[5];
45
+ return match[1];
46
46
  }
47
47
  return '';
48
48
  };
49
49
  exports.getPathFromURL = getPathFromURL;
50
50
  const isAbsoluteURL = (url) => {
51
51
  const match = url.match(URL_REGEXP);
52
- if (match && match[1]) {
52
+ if (match) {
53
53
  return true;
54
54
  }
55
55
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Ultrafast web framework for Cloudflare Workers.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,6 +23,7 @@
23
23
  "./cors": "./dist/middleware/cors/index.js",
24
24
  "./etag": "./dist/middleware/etag/index.js",
25
25
  "./graphql-server": "./dist/middleware/graphql-server/index.js",
26
+ "./jwt": "./dist/middleware/jwt/index.js",
26
27
  "./logger": "./dist/middleware/logger/index.js",
27
28
  "./mustache": "./dist/middleware/mustache/index.js",
28
29
  "./powered-by": "./dist/middleware/powered-by/index.js",
@@ -30,6 +31,7 @@
30
31
  "./serve-static": "./dist/middleware/serve-static/index.js",
31
32
  "./router/trie-router": "./dist/router/trie-router/index.js",
32
33
  "./router/reg-exp-router": "./dist/router/reg-exp-router/index.js",
34
+ "./utils/jwt": "./dist/utils/jwt/index.js",
33
35
  "./utils/*": "./dist/utils/*.js"
34
36
  },
35
37
  "typesVersions": {
@@ -52,6 +54,9 @@
52
54
  "graphql-server": [
53
55
  "./dist/middleware/graphql-server"
54
56
  ],
57
+ "jwt": [
58
+ "./dist/middleware/jwt"
59
+ ],
55
60
  "logger": [
56
61
  "./dist/middleware/logger"
57
62
  ],
@@ -73,6 +78,9 @@
73
78
  "router/reg-exp-router": [
74
79
  "./dist/router/reg-exp-router/router.d.ts"
75
80
  ],
81
+ "utils/jwt": [
82
+ "./dist/utils/jwt/index.d.ts"
83
+ ],
76
84
  "utils/*": [
77
85
  "./dist/utils/*"
78
86
  ]
@@ -82,9 +90,9 @@
82
90
  "license": "MIT",
83
91
  "repository": {
84
92
  "type": "git",
85
- "url": "https://github.com/yusukebe/hono.git"
93
+ "url": "https://github.com/honojs/hono.git"
86
94
  },
87
- "homepage": "https://github.com/yusukebe/hono",
95
+ "homepage": "https://github.com/honojs/hono",
88
96
  "keywords": [
89
97
  "web",
90
98
  "app",
@@ -98,33 +106,33 @@
98
106
  "compute@edge"
99
107
  ],
100
108
  "devDependencies": {
101
- "@cloudflare/workers-types": "^3.3.0",
109
+ "@cloudflare/workers-types": "^3.7.1",
102
110
  "@types/crypto-js": "^4.1.1",
103
- "@types/jest": "^27.4.0",
111
+ "@types/jest": "^27.4.1",
104
112
  "@types/mustache": "^4.1.2",
105
- "@types/node": "^17.0.8",
106
- "@typescript-eslint/eslint-plugin": "^5.9.0",
107
- "@typescript-eslint/parser": "^5.9.0",
113
+ "@types/node": "^17.0.29",
114
+ "@typescript-eslint/eslint-plugin": "^5.21.0",
115
+ "@typescript-eslint/parser": "^5.21.0",
108
116
  "crypto-js": "^4.1.1",
109
- "eslint": "^7.26.0",
110
- "eslint-config-prettier": "^8.3.0",
111
- "eslint-define-config": "^1.2.1",
112
- "eslint-import-resolver-typescript": "^2.0.0",
117
+ "eslint": "^8.14.0",
118
+ "eslint-config-prettier": "^8.5.0",
119
+ "eslint-define-config": "^1.4.0",
120
+ "eslint-import-resolver-typescript": "^2.7.1",
113
121
  "eslint-plugin-eslint-comments": "^3.2.0",
114
- "eslint-plugin-flowtype": "^5.7.2",
115
- "eslint-plugin-import": "^2.20.2",
122
+ "eslint-plugin-flowtype": "^8.0.3",
123
+ "eslint-plugin-import": "^2.26.0",
116
124
  "eslint-plugin-node": "^11.1.0",
117
125
  "form-data": "^4.0.0",
118
- "graphql": "^16.3.0",
119
- "jest": "^27.4.5",
120
- "jest-environment-miniflare": "^2.0.0",
126
+ "graphql": "^16.4.0",
127
+ "jest": "27.5.1",
128
+ "jest-environment-miniflare": "^2.4.0",
121
129
  "mustache": "^4.2.0",
122
- "prettier": "^2.5.1",
130
+ "prettier": "^2.6.2",
123
131
  "prettier-plugin-md-nocjsp": "^1.2.0",
124
132
  "rimraf": "^3.0.2",
125
- "ts-jest": "^27.1.2",
126
- "tsc-alias": "^1.6.6",
127
- "typescript": "^4.5.5"
133
+ "ts-jest": "^27.1.4",
134
+ "tsc-alias": "^1.6.7",
135
+ "typescript": "^4.6.3"
128
136
  },
129
137
  "engines": {
130
138
  "node": ">=11.0.0"