@jwn-js/common 1.3.23 → 2.0.2
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/Jwt-e49753f6.js +57 -0
- package/Jwt.d.ts +5 -25
- package/Jwt.js +3 -43
- package/{Server-77093d28.js → Server-dadc1f87.js} +5 -5
- package/Server.js +1 -1
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +36 -0
- package/docs/assets/icons.css +1043 -0
- package/docs/assets/{images/icons.png → icons.png} +0 -0
- package/docs/assets/{images/icons@2x.png → icons@2x.png} +0 -0
- package/docs/assets/main.js +52 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1388 -0
- package/docs/assets/{images/widgets.png → widgets.png} +0 -0
- package/docs/assets/{images/widgets@2x.png → widgets@2x.png} +0 -0
- package/docs/classes/ApiError.html +18 -560
- package/docs/classes/AsyncJwt.html +17 -0
- package/docs/classes/Controller.html +27 -1008
- package/docs/classes/Jwt.html +17 -374
- package/docs/classes/Memcached.html +20 -387
- package/docs/classes/Model.html +7 -667
- package/docs/classes/Server.html +25 -464
- package/docs/classes/Ssr.html +11 -310
- package/docs/classes/Web.html +11 -440
- package/docs/index.html +18 -258
- package/docs/interfaces/ApiErrorMessage.html +1 -222
- package/docs/interfaces/ContextSsr.html +23 -327
- package/docs/interfaces/ContextWeb.html +1 -291
- package/docs/interfaces/OptionsSsr.html +1 -184
- package/docs/interfaces/OptionsWeb.html +1 -212
- package/docs/interfaces/Route.html +1 -194
- package/docs/interfaces/Schema.html +1 -180
- package/docs/interfaces/ServerHandler.html +1 -221
- package/docs/interfaces/ServerOptions.html +1 -236
- package/docs/interfaces/ServerWebsocket.html +1 -194
- package/docs/modules.html +87 -2004
- package/index.d.ts +50 -1
- package/index.js +79 -14
- package/multipartBody.d.ts +22 -0
- package/multipartBody.js +14 -2
- package/package.json +14 -14
- package/readConfig.js +1 -1
- package/readConfigSync.js +2 -2
- package/staticBody.js +1 -1
- package/urlencodedBody.js +1 -1
- package/docs/assets/css/main.css +0 -2660
- package/docs/assets/js/main.js +0 -248
- package/docs/assets/js/search.js +0 -1
package/Jwt-e49753f6.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var crypto = require('crypto');
|
|
4
|
+
|
|
5
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
6
|
+
|
|
7
|
+
var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
|
|
8
|
+
|
|
9
|
+
const urlEncode = (str) => {
|
|
10
|
+
return str.replace(/\+/ig, "-").replace(/\//ig, "_").replace(/=+$/, "");
|
|
11
|
+
};
|
|
12
|
+
const urlDecode = (str) => {
|
|
13
|
+
return str.replace(/-/ig, "+").replace(/_/ig, "/");
|
|
14
|
+
};
|
|
15
|
+
const toBase64url = (params) => {
|
|
16
|
+
return urlEncode(Buffer.from(JSON.stringify(params)).toString("base64"));
|
|
17
|
+
};
|
|
18
|
+
const fromBase64url = (str) => {
|
|
19
|
+
return JSON.parse(Buffer.from(urlDecode(str), "base64").toString());
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
class Jwt {
|
|
23
|
+
constructor(secret, opt) {
|
|
24
|
+
this.algorithm = "SHA256";
|
|
25
|
+
this.secret = secret;
|
|
26
|
+
this.algorithm = opt?.algorithm || this.algorithm;
|
|
27
|
+
this.algorithm = this.algorithm.replace("-", "");
|
|
28
|
+
}
|
|
29
|
+
verify(jwt) {
|
|
30
|
+
if (!jwt) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const parts = jwt.split(".");
|
|
34
|
+
const signature = urlEncode(crypto__default["default"].createHmac(this.algorithm, this.secret).update(`${parts[0]}.${parts[1]}`).digest("base64"));
|
|
35
|
+
return signature === parts[2];
|
|
36
|
+
}
|
|
37
|
+
sign(data) {
|
|
38
|
+
const head = toBase64url({
|
|
39
|
+
alg: this.algorithm.replace("SHA", "HS"),
|
|
40
|
+
typ: "JWT"
|
|
41
|
+
});
|
|
42
|
+
const body = toBase64url(data);
|
|
43
|
+
const signature = urlEncode(crypto__default["default"].createHmac(this.algorithm, this.secret).update(`${head}.${body}`).digest("base64"));
|
|
44
|
+
return `${head}.${body}.${signature}`;
|
|
45
|
+
}
|
|
46
|
+
decode(jwt) {
|
|
47
|
+
const parts = (jwt || "").split(".");
|
|
48
|
+
const head = fromBase64url(parts[0]);
|
|
49
|
+
const body = fromBase64url(parts[1]);
|
|
50
|
+
return { head, body };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
exports.Jwt = Jwt;
|
|
55
|
+
exports.fromBase64url = fromBase64url;
|
|
56
|
+
exports.toBase64url = toBase64url;
|
|
57
|
+
exports.urlEncode = urlEncode;
|
package/Jwt.d.ts
CHANGED
|
@@ -4,11 +4,15 @@
|
|
|
4
4
|
*/
|
|
5
5
|
declare class Jwt {
|
|
6
6
|
private readonly secret;
|
|
7
|
+
private readonly algorithm;
|
|
7
8
|
/**
|
|
8
9
|
* @constructor
|
|
9
10
|
* @param secret
|
|
11
|
+
* @param opt addition options
|
|
10
12
|
*/
|
|
11
|
-
constructor(secret: string
|
|
13
|
+
constructor(secret: string, opt?: {
|
|
14
|
+
algorithm: string;
|
|
15
|
+
});
|
|
12
16
|
/**
|
|
13
17
|
* Verify jwt token
|
|
14
18
|
* @param jwt token
|
|
@@ -30,30 +34,6 @@ declare class Jwt {
|
|
|
30
34
|
head: any;
|
|
31
35
|
body: any;
|
|
32
36
|
};
|
|
33
|
-
/**
|
|
34
|
-
* To JSON stringify to base64 replace == at the end
|
|
35
|
-
* @param params
|
|
36
|
-
* @returns base64url string
|
|
37
|
-
*/
|
|
38
|
-
static toBase64url(params: any): string;
|
|
39
|
-
/**
|
|
40
|
-
* Parse json from jwt string
|
|
41
|
-
* @param str
|
|
42
|
-
* returns parse data
|
|
43
|
-
*/
|
|
44
|
-
static fromBase64url(str: string): any;
|
|
45
|
-
/**
|
|
46
|
-
* Url encode base64 string
|
|
47
|
-
* @param str
|
|
48
|
-
* @returns url encoded string
|
|
49
|
-
*/
|
|
50
|
-
private static urlEncode;
|
|
51
|
-
/**
|
|
52
|
-
* Decode from url encoded base64 to base64
|
|
53
|
-
* @param str
|
|
54
|
-
* @returns base64 string
|
|
55
|
-
*/
|
|
56
|
-
private static urlDecode;
|
|
57
37
|
}
|
|
58
38
|
|
|
59
39
|
export { Jwt };
|
package/Jwt.js
CHANGED
|
@@ -2,49 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
require('crypto');
|
|
6
|
+
var Jwt = require('./Jwt-e49753f6.js');
|
|
6
7
|
|
|
7
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
9
|
-
var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
class Jwt {
|
|
13
|
-
constructor(secret) {
|
|
14
|
-
this.secret = secret;
|
|
15
|
-
}
|
|
16
|
-
verify(jwt) {
|
|
17
|
-
if (!jwt) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
const parts = jwt.split(".");
|
|
21
|
-
const signature = this.constructor.urlEncode(crypto__default['default'].createHmac(algorithm, this.secret).update(`${parts[0]}.${parts[1]}`).digest("base64"));
|
|
22
|
-
return signature === parts[2];
|
|
23
|
-
}
|
|
24
|
-
sign(data) {
|
|
25
|
-
const head = this.constructor.toBase64url({ alg: "HS256", typ: "JWT" });
|
|
26
|
-
const body = this.constructor.toBase64url(data);
|
|
27
|
-
const signature = this.constructor.urlEncode(crypto__default['default'].createHmac(algorithm, this.secret).update(`${head}.${body}`).digest("base64"));
|
|
28
|
-
return `${head}.${body}.${signature}`;
|
|
29
|
-
}
|
|
30
|
-
decode(jwt) {
|
|
31
|
-
const parts = (jwt || "").split(".");
|
|
32
|
-
const head = this.constructor.fromBase64url(parts[0]);
|
|
33
|
-
const body = this.constructor.fromBase64url(parts[1]);
|
|
34
|
-
return { head, body };
|
|
35
|
-
}
|
|
36
|
-
static toBase64url(params) {
|
|
37
|
-
return Jwt.urlEncode(Buffer.from(JSON.stringify(params)).toString("base64"));
|
|
38
|
-
}
|
|
39
|
-
static fromBase64url(str) {
|
|
40
|
-
return JSON.parse(Buffer.from(Jwt.urlDecode(str), "base64").toString());
|
|
41
|
-
}
|
|
42
|
-
static urlEncode(str) {
|
|
43
|
-
return str.replace(/\+/ig, "-").replace(/\//ig, "_").replace(/=+$/, "");
|
|
44
|
-
}
|
|
45
|
-
static urlDecode(str) {
|
|
46
|
-
return str.replace(/-/ig, "+").replace(/_/ig, "/");
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
exports.Jwt = Jwt;
|
|
10
|
+
exports.Jwt = Jwt.Jwt;
|
|
@@ -102,12 +102,12 @@ class Server {
|
|
|
102
102
|
}
|
|
103
103
|
app() {
|
|
104
104
|
this._protocol = "http";
|
|
105
|
-
this._app = uws__default[
|
|
105
|
+
this._app = uws__default["default"].App(this._appOptions);
|
|
106
106
|
return this;
|
|
107
107
|
}
|
|
108
108
|
sslApp() {
|
|
109
109
|
this._protocol = "https";
|
|
110
|
-
this._app = uws__default[
|
|
110
|
+
this._app = uws__default["default"].SSLApp(this._appOptions);
|
|
111
111
|
return this;
|
|
112
112
|
}
|
|
113
113
|
push(route) {
|
|
@@ -170,7 +170,7 @@ class Server {
|
|
|
170
170
|
}
|
|
171
171
|
async close() {
|
|
172
172
|
if (this._socket) {
|
|
173
|
-
await uws__default[
|
|
173
|
+
await uws__default["default"].us_listen_socket_close(this._socket);
|
|
174
174
|
while (true) {
|
|
175
175
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
176
176
|
if (await this.socketPort() < 0) {
|
|
@@ -185,7 +185,7 @@ class Server {
|
|
|
185
185
|
if (!this._socket) {
|
|
186
186
|
return -1;
|
|
187
187
|
}
|
|
188
|
-
return uws__default[
|
|
188
|
+
return uws__default["default"].us_socket_local_port(this._socket);
|
|
189
189
|
}
|
|
190
190
|
_createHandler(res, req, fn) {
|
|
191
191
|
return new Promise(async (resolve) => {
|
|
@@ -241,7 +241,7 @@ class Server {
|
|
|
241
241
|
});
|
|
242
242
|
}
|
|
243
243
|
_lookup(host, resolve) {
|
|
244
|
-
dns__default[
|
|
244
|
+
dns__default["default"].lookup(this._host, (err, addresses) => {
|
|
245
245
|
if (err) {
|
|
246
246
|
console.log(`${this._host} error: ${err.message}`);
|
|
247
247
|
} else {
|
package/Server.js
CHANGED
package/docs/.nojekyll
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--light-hl-0: #000000;
|
|
3
|
+
--dark-hl-0: #D4D4D4;
|
|
4
|
+
--light-hl-1: #001080;
|
|
5
|
+
--dark-hl-1: #9CDCFE;
|
|
6
|
+
--light-code-background: #FFFFFF;
|
|
7
|
+
--dark-code-background: #1E1E1E;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@media (prefers-color-scheme: light) { :root {
|
|
11
|
+
--hl-0: var(--light-hl-0);
|
|
12
|
+
--hl-1: var(--light-hl-1);
|
|
13
|
+
--code-background: var(--light-code-background);
|
|
14
|
+
} }
|
|
15
|
+
|
|
16
|
+
@media (prefers-color-scheme: dark) { :root {
|
|
17
|
+
--hl-0: var(--dark-hl-0);
|
|
18
|
+
--hl-1: var(--dark-hl-1);
|
|
19
|
+
--code-background: var(--dark-code-background);
|
|
20
|
+
} }
|
|
21
|
+
|
|
22
|
+
body.light {
|
|
23
|
+
--hl-0: var(--light-hl-0);
|
|
24
|
+
--hl-1: var(--light-hl-1);
|
|
25
|
+
--code-background: var(--light-code-background);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
body.dark {
|
|
29
|
+
--hl-0: var(--dark-hl-0);
|
|
30
|
+
--hl-1: var(--dark-hl-1);
|
|
31
|
+
--code-background: var(--dark-code-background);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.hl-0 { color: var(--hl-0); }
|
|
35
|
+
.hl-1 { color: var(--hl-1); }
|
|
36
|
+
pre, code { background: var(--code-background); }
|