@jwn-js/common 1.3.22 → 2.0.1

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 (60) hide show
  1. package/Jwt-e49753f6.js +57 -0
  2. package/Jwt.js +3 -43
  3. package/{Server-77093d28.js → Server-dadc1f87.js} +5 -5
  4. package/Server.js +1 -1
  5. package/docs/.nojekyll +1 -0
  6. package/docs/assets/highlight.css +36 -0
  7. package/docs/assets/icons.css +1043 -0
  8. package/docs/assets/{images/icons.png → icons.png} +0 -0
  9. package/docs/assets/{images/icons@2x.png → icons@2x.png} +0 -0
  10. package/docs/assets/main.js +52 -0
  11. package/docs/assets/search.js +1 -0
  12. package/docs/assets/style.css +1388 -0
  13. package/docs/assets/{images/widgets.png → widgets.png} +0 -0
  14. package/docs/assets/{images/widgets@2x.png → widgets@2x.png} +0 -0
  15. package/docs/classes/ApiError.html +18 -560
  16. package/docs/classes/AsyncJwt.html +17 -0
  17. package/docs/classes/Controller.html +27 -1008
  18. package/docs/classes/Jwt.html +17 -374
  19. package/docs/classes/Memcached.html +20 -387
  20. package/docs/classes/Model.html +7 -667
  21. package/docs/classes/Server.html +25 -464
  22. package/docs/classes/Ssr.html +11 -310
  23. package/docs/classes/Web.html +11 -440
  24. package/docs/index.html +18 -258
  25. package/docs/interfaces/ApiErrorMessage.html +1 -222
  26. package/docs/interfaces/ContextSsr.html +23 -327
  27. package/docs/interfaces/ContextWeb.html +1 -291
  28. package/docs/interfaces/OptionsSsr.html +1 -184
  29. package/docs/interfaces/OptionsWeb.html +1 -212
  30. package/docs/interfaces/Route.html +1 -194
  31. package/docs/interfaces/Schema.html +1 -180
  32. package/docs/interfaces/ServerHandler.html +1 -221
  33. package/docs/interfaces/ServerOptions.html +1 -236
  34. package/docs/interfaces/ServerWebsocket.html +1 -194
  35. package/docs/modules.html +87 -2004
  36. package/index.js +80 -15
  37. package/multipartBody.js +14 -2
  38. package/package.json +14 -14
  39. package/readConfig.js +1 -1
  40. package/readConfigSync.js +2 -2
  41. package/{ApiError.d.ts → src/ApiError/ApiError.d.ts} +0 -0
  42. package/src/Jwt/Jwt.d.ts +39 -0
  43. package/{Memcached.d.ts → src/Memcached/Memcached.d.ts} +0 -0
  44. package/{Server.d.ts → src/Server/Server.d.ts} +0 -0
  45. package/{cookieParse.d.ts → src/helpers/cookieParse.d.ts} +0 -0
  46. package/{cookieString.d.ts → src/helpers/cookieString.d.ts} +0 -0
  47. package/{jsonBody.d.ts → src/helpers/jsonBody.d.ts} +0 -0
  48. package/src/helpers/multipartBody.d.ts +33 -0
  49. package/{readConfig.d.ts → src/helpers/readConfig.d.ts} +0 -0
  50. package/{readConfigSync.d.ts → src/helpers/readConfigSync.d.ts} +0 -0
  51. package/{staticBody.d.ts → src/helpers/staticBody.d.ts} +0 -0
  52. package/{urlencodedBody.d.ts → src/helpers/urlencodedBody.d.ts} +0 -0
  53. package/{index.d.ts → src/index.d.ts} +54 -5
  54. package/staticBody.js +1 -1
  55. package/urlencodedBody.js +1 -1
  56. package/Jwt.d.ts +0 -59
  57. package/docs/assets/css/main.css +0 -2660
  58. package/docs/assets/js/main.js +0 -248
  59. package/docs/assets/js/search.js +0 -1
  60. package/multipartBody.d.ts +0 -11
@@ -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.js CHANGED
@@ -2,49 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var crypto = require('crypto');
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
- const algorithm = "SHA256";
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['default'].App(this._appOptions);
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['default'].SSLApp(this._appOptions);
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['default'].us_listen_socket_close(this._socket);
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['default'].us_socket_local_port(this._socket);
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['default'].lookup(this._host, (err, addresses) => {
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
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  require('dns');
6
6
  require('uWebSockets.js');
7
- var Server = require('./Server-77093d28.js');
7
+ var Server = require('./Server-dadc1f87.js');
8
8
 
9
9
 
10
10
 
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); }