@jwn-js/common 2.2.3 → 2.2.4
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/ApiError.js +1 -37
- package/ApiError.mjs +1 -35
- package/Jwt-7tQL-rwa.js +1 -0
- package/Jwt-CDdbxwvH.js +1 -0
- package/Jwt.js +1 -8
- package/Jwt.mjs +1 -2
- package/Memcached.js +9 -166
- package/Memcached.mjs +9 -164
- package/Server.js +1 -316
- package/Server.mjs +1 -313
- package/cookieParse.js +1 -25
- package/cookieParse.mjs +1 -23
- package/cookieString.js +1 -22
- package/cookieString.mjs +1 -20
- package/docs/classes/ApiError.html +2 -2
- package/docs/classes/AsyncJwt.html +2 -2
- package/docs/classes/Controller.html +2 -2
- package/docs/classes/Jwt.html +2 -2
- package/docs/classes/Memcached.html +2 -2
- package/docs/classes/Model.html +2 -2
- package/docs/classes/Server.html +2 -2
- package/docs/classes/Ssr.html +2 -2
- package/docs/classes/Web.html +2 -2
- package/docs/functions/action.html +2 -2
- package/docs/functions/body.html +2 -2
- package/docs/functions/codeToStatus.html +2 -2
- package/docs/functions/config.html +2 -2
- package/docs/functions/connection.html +2 -2
- package/docs/functions/context.html +2 -2
- package/docs/functions/controller-1.html +2 -2
- package/docs/functions/cookies.html +2 -2
- package/docs/functions/db.html +2 -2
- package/docs/functions/headers.html +2 -2
- package/docs/functions/home.html +2 -2
- package/docs/functions/hostname.html +2 -2
- package/docs/functions/http.html +2 -2
- package/docs/functions/init.html +2 -2
- package/docs/functions/json.html +2 -2
- package/docs/functions/logerror.html +2 -2
- package/docs/functions/method.html +2 -2
- package/docs/functions/mixin.html +2 -2
- package/docs/functions/mount.html +2 -2
- package/docs/functions/pool.html +2 -2
- package/docs/functions/protocol.html +2 -2
- package/docs/functions/request.html +2 -2
- package/docs/functions/selectControllersSchema.html +1 -1
- package/docs/functions/stream.html +2 -2
- package/docs/functions/subaction.html +2 -2
- package/docs/functions/url.html +2 -2
- package/docs/functions/xml.html +2 -2
- package/docs/index.html +2 -2
- package/docs/interfaces/ApiErrorMessage.html +2 -2
- package/docs/interfaces/ContextSsr.html +2 -2
- package/docs/interfaces/ContextWeb.html +2 -2
- package/docs/interfaces/OptionsSsr.html +2 -2
- package/docs/interfaces/OptionsWeb.html +2 -2
- package/docs/interfaces/ResponseOptions.html +2 -2
- package/docs/interfaces/Route.html +2 -2
- package/docs/interfaces/Schema.html +2 -2
- package/docs/interfaces/ServerHandler.html +2 -2
- package/docs/interfaces/ServerOptions.html +2 -2
- package/docs/interfaces/ServerWebsocket.html +2 -2
- package/docs/modules.html +2 -2
- package/docs/types/ServerRoutes.html +1 -1
- package/docs/variables/helpers.html +2 -2
- package/index.js +4 -1473
- package/index.mjs +4 -1417
- package/jsonBody.js +1 -25
- package/jsonBody.mjs +1 -23
- package/multipartBody.js +1 -42
- package/multipartBody.mjs +1 -40
- package/package.json +2 -2
- package/readConfig.js +1 -11
- package/readConfig.mjs +1 -9
- package/readConfigSync.js +1 -11
- package/readConfigSync.mjs +1 -9
- package/staticBody.js +1 -205
- package/staticBody.mjs +1 -200
- package/urlencodedBody.js +1 -26
- package/urlencodedBody.mjs +1 -24
- package/Jwt-B4QZ2Ypb.js +0 -80
- package/Jwt-Be4GWrIO.js +0 -75
package/urlencodedBody.js
CHANGED
|
@@ -1,26 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var ApiError = require('./ApiError.js');
|
|
4
|
-
var querystring = require('querystring');
|
|
5
|
-
|
|
6
|
-
const urlencodedBody = (res) => new Promise((resolve, reject) => {
|
|
7
|
-
readBody(res, (obj) => resolve(obj), () => {
|
|
8
|
-
reject(new ApiError.ApiError({ message: "Can`t parse body", code: 1, statusCode: 404 }));
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
function readBody(res, cb, err) {
|
|
12
|
-
let buffer = Buffer.from([]);
|
|
13
|
-
res.onData((ab, isLast) => {
|
|
14
|
-
buffer = Buffer.concat([buffer, Buffer.from(ab)]);
|
|
15
|
-
if (isLast) {
|
|
16
|
-
try {
|
|
17
|
-
cb(querystring.parse(buffer.toString()));
|
|
18
|
-
} catch (e) {
|
|
19
|
-
cb({});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
res.onAborted(err);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
exports.urlencodedBody = urlencodedBody;
|
|
1
|
+
"use strict";var c=require("./ApiError.js"),d=require("querystring");const f=e=>new Promise((o,t)=>{s(e,r=>o(r),()=>{t(new c.ApiError({message:"Can`t parse body",code:1,statusCode:404}))})});function s(e,o,t){let r=Buffer.from([]);e.onData((a,n)=>{if(r=Buffer.concat([r,Buffer.from(a)]),n)try{o(d.parse(r.toString()))}catch{o({})}}),e.onAborted(t)}exports.urlencodedBody=f;
|
package/urlencodedBody.mjs
CHANGED
|
@@ -1,24 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import querystring from 'querystring';
|
|
3
|
-
|
|
4
|
-
const urlencodedBody = (res) => new Promise((resolve, reject) => {
|
|
5
|
-
readBody(res, (obj) => resolve(obj), () => {
|
|
6
|
-
reject(new ApiError({ message: "Can`t parse body", code: 1, statusCode: 404 }));
|
|
7
|
-
});
|
|
8
|
-
});
|
|
9
|
-
function readBody(res, cb, err) {
|
|
10
|
-
let buffer = Buffer.from([]);
|
|
11
|
-
res.onData((ab, isLast) => {
|
|
12
|
-
buffer = Buffer.concat([buffer, Buffer.from(ab)]);
|
|
13
|
-
if (isLast) {
|
|
14
|
-
try {
|
|
15
|
-
cb(querystring.parse(buffer.toString()));
|
|
16
|
-
} catch (e) {
|
|
17
|
-
cb({});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
res.onAborted(err);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export { urlencodedBody };
|
|
1
|
+
import{ApiError as a}from"./ApiError.mjs";import c from"querystring";const m=r=>new Promise((e,t)=>{s(r,o=>e(o),()=>{t(new a({message:"Can`t parse body",code:1,statusCode:404}))})});function s(r,e,t){let o=Buffer.from([]);r.onData((f,n)=>{if(o=Buffer.concat([o,Buffer.from(f)]),n)try{e(c.parse(o.toString()))}catch{e({})}}),r.onAborted(t)}export{m as urlencodedBody};
|
package/Jwt-B4QZ2Ypb.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var crypto = require('crypto');
|
|
4
|
-
|
|
5
|
-
const urlEncode = (str) => {
|
|
6
|
-
return str.replace(/\+/ig, "-").replace(/\//ig, "_").replace(/=+$/, "");
|
|
7
|
-
};
|
|
8
|
-
const urlDecode = (str) => {
|
|
9
|
-
return str.replace(/-/ig, "+").replace(/_/ig, "/");
|
|
10
|
-
};
|
|
11
|
-
const toBase64url = (params) => {
|
|
12
|
-
return urlEncode(
|
|
13
|
-
Buffer.from(JSON.stringify(params)).toString("base64")
|
|
14
|
-
);
|
|
15
|
-
};
|
|
16
|
-
const fromBase64url = (str) => {
|
|
17
|
-
return JSON.parse(
|
|
18
|
-
Buffer.from(
|
|
19
|
-
urlDecode(str),
|
|
20
|
-
"base64"
|
|
21
|
-
).toString()
|
|
22
|
-
);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
class Jwt {
|
|
26
|
-
/**
|
|
27
|
-
* @constructor
|
|
28
|
-
* @param secret
|
|
29
|
-
* @param opt addition options
|
|
30
|
-
*/
|
|
31
|
-
constructor(secret, opt) {
|
|
32
|
-
this.algorithm = "SHA256";
|
|
33
|
-
this.secret = secret;
|
|
34
|
-
this.algorithm = opt?.algorithm || this.algorithm;
|
|
35
|
-
this.algorithm = this.algorithm.replace("-", "");
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Verify jwt token
|
|
39
|
-
* @param jwt token
|
|
40
|
-
* @returns is token valid
|
|
41
|
-
*/
|
|
42
|
-
verify(jwt) {
|
|
43
|
-
if (!jwt) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
const parts = jwt.split(".");
|
|
47
|
-
const signature = urlEncode(crypto.createHmac(this.algorithm, this.secret).update(`${parts[0]}.${parts[1]}`).digest("base64"));
|
|
48
|
-
return signature === parts[2];
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Get token
|
|
52
|
-
* @param data - user data
|
|
53
|
-
* @returns jwt
|
|
54
|
-
*/
|
|
55
|
-
sign(data) {
|
|
56
|
-
const head = toBase64url({
|
|
57
|
-
alg: this.algorithm.replace("SHA", "HS"),
|
|
58
|
-
typ: "JWT"
|
|
59
|
-
});
|
|
60
|
-
const body = toBase64url(data);
|
|
61
|
-
const signature = urlEncode(crypto.createHmac(this.algorithm, this.secret).update(`${head}.${body}`).digest("base64"));
|
|
62
|
-
return `${head}.${body}.${signature}`;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Decode token
|
|
66
|
-
* @param jwt - jwt token
|
|
67
|
-
* @returns {head, body}
|
|
68
|
-
*/
|
|
69
|
-
decode(jwt) {
|
|
70
|
-
const parts = (jwt || "").split(".");
|
|
71
|
-
const head = fromBase64url(parts[0]);
|
|
72
|
-
const body = fromBase64url(parts[1]);
|
|
73
|
-
return { head, body };
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
exports.Jwt = Jwt;
|
|
78
|
-
exports.fromBase64url = fromBase64url;
|
|
79
|
-
exports.toBase64url = toBase64url;
|
|
80
|
-
exports.urlEncode = urlEncode;
|
package/Jwt-Be4GWrIO.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
2
|
-
|
|
3
|
-
const urlEncode = (str) => {
|
|
4
|
-
return str.replace(/\+/ig, "-").replace(/\//ig, "_").replace(/=+$/, "");
|
|
5
|
-
};
|
|
6
|
-
const urlDecode = (str) => {
|
|
7
|
-
return str.replace(/-/ig, "+").replace(/_/ig, "/");
|
|
8
|
-
};
|
|
9
|
-
const toBase64url = (params) => {
|
|
10
|
-
return urlEncode(
|
|
11
|
-
Buffer.from(JSON.stringify(params)).toString("base64")
|
|
12
|
-
);
|
|
13
|
-
};
|
|
14
|
-
const fromBase64url = (str) => {
|
|
15
|
-
return JSON.parse(
|
|
16
|
-
Buffer.from(
|
|
17
|
-
urlDecode(str),
|
|
18
|
-
"base64"
|
|
19
|
-
).toString()
|
|
20
|
-
);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
class Jwt {
|
|
24
|
-
/**
|
|
25
|
-
* @constructor
|
|
26
|
-
* @param secret
|
|
27
|
-
* @param opt addition options
|
|
28
|
-
*/
|
|
29
|
-
constructor(secret, opt) {
|
|
30
|
-
this.algorithm = "SHA256";
|
|
31
|
-
this.secret = secret;
|
|
32
|
-
this.algorithm = opt?.algorithm || this.algorithm;
|
|
33
|
-
this.algorithm = this.algorithm.replace("-", "");
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Verify jwt token
|
|
37
|
-
* @param jwt token
|
|
38
|
-
* @returns is token valid
|
|
39
|
-
*/
|
|
40
|
-
verify(jwt) {
|
|
41
|
-
if (!jwt) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
const parts = jwt.split(".");
|
|
45
|
-
const signature = urlEncode(crypto.createHmac(this.algorithm, this.secret).update(`${parts[0]}.${parts[1]}`).digest("base64"));
|
|
46
|
-
return signature === parts[2];
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Get token
|
|
50
|
-
* @param data - user data
|
|
51
|
-
* @returns jwt
|
|
52
|
-
*/
|
|
53
|
-
sign(data) {
|
|
54
|
-
const head = toBase64url({
|
|
55
|
-
alg: this.algorithm.replace("SHA", "HS"),
|
|
56
|
-
typ: "JWT"
|
|
57
|
-
});
|
|
58
|
-
const body = toBase64url(data);
|
|
59
|
-
const signature = urlEncode(crypto.createHmac(this.algorithm, this.secret).update(`${head}.${body}`).digest("base64"));
|
|
60
|
-
return `${head}.${body}.${signature}`;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Decode token
|
|
64
|
-
* @param jwt - jwt token
|
|
65
|
-
* @returns {head, body}
|
|
66
|
-
*/
|
|
67
|
-
decode(jwt) {
|
|
68
|
-
const parts = (jwt || "").split(".");
|
|
69
|
-
const head = fromBase64url(parts[0]);
|
|
70
|
-
const body = fromBase64url(parts[1]);
|
|
71
|
-
return { head, body };
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export { Jwt as J, fromBase64url as f, toBase64url as t, urlEncode as u };
|