securequ 1.0.10 → 1.0.12
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/client/index.d.ts +25 -0
- package/client/index.js +107 -173
- package/client/index.js.map +1 -1
- package/client/index.mjs +107 -173
- package/client/index.mjs.map +1 -1
- package/client/types.d.ts +17 -0
- package/include/lib/base64.js +12 -12
- package/include/lib/base64.js.map +1 -1
- package/include/lib/base64.mjs +12 -12
- package/include/lib/base64.mjs.map +1 -1
- package/include/lib/cache.js +20 -22
- package/include/lib/cache.js.map +1 -1
- package/include/lib/cache.mjs +20 -22
- package/include/lib/cache.mjs.map +1 -1
- package/include/lib/crypto.js +23 -23
- package/include/lib/crypto.js.map +1 -1
- package/include/lib/crypto.mjs +23 -23
- package/include/lib/crypto.mjs.map +1 -1
- package/include/lib/pako.js +5 -5
- package/include/lib/pako.js.map +1 -1
- package/include/lib/pako.mjs +5 -5
- package/include/lib/pako.mjs.map +1 -1
- package/include/lib/reverser.js +11 -11
- package/include/lib/reverser.js.map +1 -1
- package/include/lib/reverser.mjs +11 -11
- package/include/lib/reverser.mjs.map +1 -1
- package/include/lib/urlpath.js +2 -2
- package/include/lib/urlpath.js.map +1 -1
- package/include/lib/urlpath.mjs +2 -2
- package/include/lib/urlpath.mjs.map +1 -1
- package/include/responseValue.js +4 -4
- package/include/responseValue.js.map +1 -1
- package/include/responseValue.mjs +4 -4
- package/include/responseValue.mjs.map +1 -1
- package/include/signeture.js +12 -12
- package/include/signeture.js.map +1 -1
- package/include/signeture.mjs +12 -12
- package/include/signeture.mjs.map +1 -1
- package/index.d.ts +2 -81
- package/package.json +6 -11
- package/server/index.d.ts +18 -0
- package/server/index.js +105 -176
- package/server/index.js.map +1 -1
- package/server/index.mjs +105 -176
- package/server/index.mjs.map +1 -1
- package/server/types.d.ts +28 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseValue.mjs","sources":["../../src/include/responseValue.ts"],"sourcesContent":["import crypto from \"./lib/crypto\";\n\nconst encrypt = (data: any, signerure: string): string => {\n return crypto.encrypt(data, crypto.makeSecret(signerure))\n}\n\nconst decrypt = (value: string, signerure: string) => {\n return crypto.decrypt(value, crypto.makeSecret(signerure))\n}\n\nexport default {\n encrypt,\n decrypt\n}"],"names":[],"mappings":"qCAEA,
|
|
1
|
+
{"version":3,"file":"responseValue.mjs","sources":["../../src/include/responseValue.ts"],"sourcesContent":["import crypto from \"./lib/crypto\";\n\nconst encrypt = (data: any, signerure: string): string => {\n return crypto.encrypt(data, crypto.makeSecret(signerure))\n}\n\nconst decrypt = (value: string, signerure: string) => {\n return crypto.decrypt(value, crypto.makeSecret(signerure))\n}\n\nexport default {\n encrypt,\n decrypt\n}"],"names":[],"mappings":"qCAEA,MAAM,OAAO,GAAG,CAAC,IAAS,EAAE,SAAiB,KAAY;AACtD,IAAA,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,OAAO,GAAG,CAAC,KAAa,EAAE,SAAiB,KAAI;AAClD,IAAA,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;AAC7D,CAAC;AAED,oBAAe;IACZ,OAAO;IACP;CACF"}
|
package/include/signeture.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return
|
|
1
|
+
'use strict';var crypto=require('./lib/crypto.js');const make = (val, secret) => {
|
|
2
|
+
const signeture = crypto.encrypt(val, secret);
|
|
3
|
+
const signetureHash = crypto.hash(signeture);
|
|
4
|
+
const secretEncript = crypto.encrypt(secret, signetureHash);
|
|
5
|
+
return `${signeture}.${secretEncript}`;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const verify = (signerure) => {
|
|
8
|
+
const [signeture, secretEncript] = signerure.split(".");
|
|
9
|
+
const signetureHash = crypto.hash(signeture);
|
|
10
|
+
const secret = crypto.decrypt(secretEncript, signetureHash);
|
|
11
|
+
const secretVal = crypto.decrypt(signeture, secret);
|
|
12
12
|
if (secretVal !== secret)
|
|
13
13
|
throw new Error("Invalid Signeture");
|
|
14
14
|
return secretVal;
|
|
15
15
|
};
|
|
16
16
|
var signeture = {
|
|
17
|
-
make
|
|
18
|
-
verify
|
|
17
|
+
make,
|
|
18
|
+
verify,
|
|
19
19
|
key: "x-signeture"
|
|
20
20
|
};module.exports=signeture;//# sourceMappingURL=signeture.js.map
|
package/include/signeture.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signeture.js","sources":["../../src/include/signeture.ts"],"sourcesContent":["import crypto from \"./lib/crypto\";\n\nconst make = (val: string, secret: string) => {\n const signeture = crypto.encrypt(val, secret);\n const signetureHash = crypto.hash(signeture)\n const secretEncript = crypto.encrypt(secret, signetureHash);\n return `${signeture}.${secretEncript}`;\n}\n\nconst verify = (signerure: string) => {\n const [signeture, secretEncript] = signerure.split(\".\");\n const signetureHash = crypto.hash(signeture);\n const secret = crypto.decrypt(secretEncript, signetureHash);\n const secretVal = crypto.decrypt(signeture, secret);\n if (secretVal !== secret) throw new Error(\"Invalid Signeture\");\n return secretVal;\n}\n\nexport default {\n make,\n verify,\n key: \"x-signeture\"\n}"],"names":[
|
|
1
|
+
{"version":3,"file":"signeture.js","sources":["../../src/include/signeture.ts"],"sourcesContent":["import crypto from \"./lib/crypto\";\n\nconst make = (val: string, secret: string) => {\n const signeture = crypto.encrypt(val, secret);\n const signetureHash = crypto.hash(signeture)\n const secretEncript = crypto.encrypt(secret, signetureHash);\n return `${signeture}.${secretEncript}`;\n}\n\nconst verify = (signerure: string) => {\n const [signeture, secretEncript] = signerure.split(\".\");\n const signetureHash = crypto.hash(signeture);\n const secret = crypto.decrypt(secretEncript, signetureHash);\n const secretVal = crypto.decrypt(signeture, secret);\n if (secretVal !== secret) throw new Error(\"Invalid Signeture\");\n return secretVal;\n}\n\nexport default {\n make,\n verify,\n key: \"x-signeture\"\n}"],"names":[],"mappings":"mDAEA,MAAM,IAAI,GAAG,CAAC,GAAW,EAAE,MAAc,KAAI;IAC1C,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC;IAC7C,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;IAC5C,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,aAAa,CAAC;AAC3D,IAAA,OAAO,CAAA,EAAG,SAAS,CAAA,CAAA,EAAI,aAAa,EAAE;AACzC,CAAC;AAED,MAAM,MAAM,GAAG,CAAC,SAAiB,KAAI;AAClC,IAAA,MAAM,CAAC,SAAS,EAAE,aAAa,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC;IACvD,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;IAC5C,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,aAAa,CAAC;IAC3D,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC;IACnD,IAAI,SAAS,KAAK,MAAM;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC;AAC9D,IAAA,OAAO,SAAS;AACnB,CAAC;AAED,gBAAe;IACZ,IAAI;IACJ,MAAM;AACN,IAAA,GAAG,EAAE;CACP"}
|
package/include/signeture.mjs
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return
|
|
1
|
+
import crypto from'./lib/crypto.mjs';const make = (val, secret) => {
|
|
2
|
+
const signeture = crypto.encrypt(val, secret);
|
|
3
|
+
const signetureHash = crypto.hash(signeture);
|
|
4
|
+
const secretEncript = crypto.encrypt(secret, signetureHash);
|
|
5
|
+
return `${signeture}.${secretEncript}`;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const verify = (signerure) => {
|
|
8
|
+
const [signeture, secretEncript] = signerure.split(".");
|
|
9
|
+
const signetureHash = crypto.hash(signeture);
|
|
10
|
+
const secret = crypto.decrypt(secretEncript, signetureHash);
|
|
11
|
+
const secretVal = crypto.decrypt(signeture, secret);
|
|
12
12
|
if (secretVal !== secret)
|
|
13
13
|
throw new Error("Invalid Signeture");
|
|
14
14
|
return secretVal;
|
|
15
15
|
};
|
|
16
16
|
var signeture = {
|
|
17
|
-
make
|
|
18
|
-
verify
|
|
17
|
+
make,
|
|
18
|
+
verify,
|
|
19
19
|
key: "x-signeture"
|
|
20
20
|
};export{signeture as default};//# sourceMappingURL=signeture.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signeture.mjs","sources":["../../src/include/signeture.ts"],"sourcesContent":["import crypto from \"./lib/crypto\";\n\nconst make = (val: string, secret: string) => {\n const signeture = crypto.encrypt(val, secret);\n const signetureHash = crypto.hash(signeture)\n const secretEncript = crypto.encrypt(secret, signetureHash);\n return `${signeture}.${secretEncript}`;\n}\n\nconst verify = (signerure: string) => {\n const [signeture, secretEncript] = signerure.split(\".\");\n const signetureHash = crypto.hash(signeture);\n const secret = crypto.decrypt(secretEncript, signetureHash);\n const secretVal = crypto.decrypt(signeture, secret);\n if (secretVal !== secret) throw new Error(\"Invalid Signeture\");\n return secretVal;\n}\n\nexport default {\n make,\n verify,\n key: \"x-signeture\"\n}"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signeture.mjs","sources":["../../src/include/signeture.ts"],"sourcesContent":["import crypto from \"./lib/crypto\";\n\nconst make = (val: string, secret: string) => {\n const signeture = crypto.encrypt(val, secret);\n const signetureHash = crypto.hash(signeture)\n const secretEncript = crypto.encrypt(secret, signetureHash);\n return `${signeture}.${secretEncript}`;\n}\n\nconst verify = (signerure: string) => {\n const [signeture, secretEncript] = signerure.split(\".\");\n const signetureHash = crypto.hash(signeture);\n const secret = crypto.decrypt(secretEncript, signetureHash);\n const secretVal = crypto.decrypt(signeture, secret);\n if (secretVal !== secret) throw new Error(\"Invalid Signeture\");\n return secretVal;\n}\n\nexport default {\n make,\n verify,\n key: \"x-signeture\"\n}"],"names":[],"mappings":"qCAEA,MAAM,IAAI,GAAG,CAAC,GAAW,EAAE,MAAc,KAAI;IAC1C,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC;IAC7C,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;IAC5C,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,aAAa,CAAC;AAC3D,IAAA,OAAO,CAAA,EAAG,SAAS,CAAA,CAAA,EAAI,aAAa,EAAE;AACzC,CAAC;AAED,MAAM,MAAM,GAAG,CAAC,SAAiB,KAAI;AAClC,IAAA,MAAM,CAAC,SAAS,EAAE,aAAa,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC;IACvD,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;IAC5C,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,aAAa,CAAC;IAC3D,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC;IACnD,IAAI,SAAS,KAAK,MAAM;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC;AAC9D,IAAA,OAAO,SAAS;AACnB,CAAC;AAED,gBAAe;IACZ,IAAI;IACJ,MAAM;AACN,IAAA,GAAG,EAAE;CACP"}
|
package/index.d.ts
CHANGED
|
@@ -1,81 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
cache?: boolean | {
|
|
4
|
-
get: (key: string) => any;
|
|
5
|
-
set: (key: string, response: Response) => void;
|
|
6
|
-
};
|
|
7
|
-
};
|
|
8
|
-
type HTTPMethods = "GET" | "POST" | "PUT" | "DELETE";
|
|
9
|
-
type ListenerInfo = {
|
|
10
|
-
signeture: string;
|
|
11
|
-
path: string;
|
|
12
|
-
body: any;
|
|
13
|
-
method: HTTPMethods;
|
|
14
|
-
};
|
|
15
|
-
type HandlerInfo = {
|
|
16
|
-
path: string;
|
|
17
|
-
body: object;
|
|
18
|
-
searchParams: Object;
|
|
19
|
-
params: Object;
|
|
20
|
-
method: HTTPMethods;
|
|
21
|
-
};
|
|
22
|
-
type ServerResponse = {
|
|
23
|
-
value: string;
|
|
24
|
-
status: number;
|
|
25
|
-
};
|
|
26
|
-
type HandlerFunction = (info: HandlerInfo, args?: any) => (any | void) | Promise<Partial<any> | void>;
|
|
27
|
-
|
|
28
|
-
declare class SecurequServer {
|
|
29
|
-
private HandlerCache;
|
|
30
|
-
private routes;
|
|
31
|
-
private config;
|
|
32
|
-
private secret;
|
|
33
|
-
constructor(config: SecurequServerConfig);
|
|
34
|
-
addRoute(path: string, method: HTTPMethods, handler: HandlerFunction): Promise<void>;
|
|
35
|
-
get(path: string, handler: HandlerFunction): Promise<void>;
|
|
36
|
-
post(path: string, handler: HandlerFunction): Promise<void>;
|
|
37
|
-
put(path: string, handler: HandlerFunction): Promise<void>;
|
|
38
|
-
delete(path: string, handler: HandlerFunction): Promise<void>;
|
|
39
|
-
handleRequest(info: HandlerInfo, args?: any): Promise<void>;
|
|
40
|
-
listen(listenerInfo: ListenerInfo, args?: any): Promise<ServerResponse>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
type SecurequClientConfig = {
|
|
44
|
-
secret: string;
|
|
45
|
-
path?: string;
|
|
46
|
-
headers?: Record<string, string>;
|
|
47
|
-
cache?: boolean | {
|
|
48
|
-
get: (key: string) => any;
|
|
49
|
-
set: (key: string, response: Response) => void;
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
type RequestBody = {
|
|
53
|
-
[key: string]: any;
|
|
54
|
-
};
|
|
55
|
-
type HttpRequestInit = Omit<RequestInit, 'body'> & {
|
|
56
|
-
body?: RequestBody;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
declare class SecurequClient {
|
|
60
|
-
private config;
|
|
61
|
-
private token;
|
|
62
|
-
private tokenLoading;
|
|
63
|
-
private Cache;
|
|
64
|
-
private secret;
|
|
65
|
-
private secret_length;
|
|
66
|
-
private signerure;
|
|
67
|
-
private reqkey;
|
|
68
|
-
constructor(config: SecurequClientConfig);
|
|
69
|
-
private setCache;
|
|
70
|
-
private getCache;
|
|
71
|
-
private PATH_CACHE;
|
|
72
|
-
private path;
|
|
73
|
-
private handshake;
|
|
74
|
-
send(path: string, init?: HttpRequestInit): Promise<Response>;
|
|
75
|
-
get(path: string, init?: HttpRequestInit): Promise<Response>;
|
|
76
|
-
post(path: string, body: RequestBody, init?: HttpRequestInit): Promise<Response>;
|
|
77
|
-
put(path: string, body: RequestBody, init?: HttpRequestInit): Promise<Response>;
|
|
78
|
-
delete(path: string, init?: HttpRequestInit): Promise<Response>;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export { SecurequClient, SecurequServer };
|
|
1
|
+
export { default as SecurequServer } from './server/index.js';
|
|
2
|
+
export { default as SecurequClient } from './client/index.js';
|
package/package.json
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "securequ",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"main": "./index.js",
|
|
5
|
-
"module": "./index.mjs",
|
|
6
|
-
"types": "./index.d.ts",
|
|
3
|
+
"version": "1.0.12",
|
|
7
4
|
"description": "",
|
|
8
5
|
"keywords": [],
|
|
9
6
|
"dependencies": {
|
|
10
7
|
"pako": "^2.1.0",
|
|
11
8
|
"path-to-regexp": "^8.2.0",
|
|
12
9
|
"tweetnacl": "^1.0.3",
|
|
13
|
-
"xanfetch": "^1.0.
|
|
10
|
+
"xanfetch": "^1.0.7"
|
|
14
11
|
},
|
|
15
12
|
"devDependencies": {
|
|
16
|
-
"@types/pako": "^2.0.3",
|
|
17
13
|
"@types/node": "^22.15.24",
|
|
14
|
+
"@types/pako": "^2.0.3",
|
|
18
15
|
"@types/react": "^19.0.2",
|
|
19
16
|
"@types/react-dom": "^19.0.2",
|
|
20
17
|
"express": "^5.1.0",
|
|
21
|
-
"makepack": "^1.7.
|
|
18
|
+
"makepack": "^1.7.7",
|
|
22
19
|
"react": "^19.0.0",
|
|
23
20
|
"react-dom": "^19.0.0",
|
|
24
21
|
"typescript": "^4.4.2"
|
|
@@ -31,13 +28,11 @@
|
|
|
31
28
|
},
|
|
32
29
|
"./server": {
|
|
33
30
|
"import": "./server/index.mjs",
|
|
34
|
-
"require": "./server/index.js"
|
|
35
|
-
"types": "./server/index.d.ts"
|
|
31
|
+
"require": "./server/index.js"
|
|
36
32
|
},
|
|
37
33
|
"./client": {
|
|
38
34
|
"import": "./client/index.mjs",
|
|
39
|
-
"require": "./client/index.js"
|
|
40
|
-
"types": "./client/index.d.ts"
|
|
35
|
+
"require": "./client/index.js"
|
|
41
36
|
}
|
|
42
37
|
}
|
|
43
38
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SecurequServerConfig, HTTPMethods, HandlerFunction, HandlerInfo, ListenerInfo, ServerResponse } from './types.js';
|
|
2
|
+
|
|
3
|
+
declare class SecurequServer {
|
|
4
|
+
private HandlerCache;
|
|
5
|
+
private routes;
|
|
6
|
+
private config;
|
|
7
|
+
private secret;
|
|
8
|
+
constructor(config: SecurequServerConfig);
|
|
9
|
+
addRoute(path: string, method: HTTPMethods, handler: HandlerFunction): Promise<void>;
|
|
10
|
+
get(path: string, handler: HandlerFunction): Promise<void>;
|
|
11
|
+
post(path: string, handler: HandlerFunction): Promise<void>;
|
|
12
|
+
put(path: string, handler: HandlerFunction): Promise<void>;
|
|
13
|
+
delete(path: string, handler: HandlerFunction): Promise<void>;
|
|
14
|
+
handleRequest(info: HandlerInfo, args?: any): Promise<void>;
|
|
15
|
+
listen(listenerInfo: ListenerInfo, args?: any): Promise<ServerResponse>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { SecurequServer, SecurequServer as default };
|
package/server/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var
|
|
2
|
-
|
|
1
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var pathToRegexp=require('path-to-regexp'),crypto=require('../include/lib/crypto.js'),reverser=require('../include/lib/reverser.js'),responseValue=require('../include/responseValue.js'),signeture=require('../include/signeture.js'),cache=require('../include/lib/cache.js');class SecurequServer {
|
|
2
|
+
constructor(config) {
|
|
3
3
|
this.HandlerCache = new cache({ ttl: 1000 * 60 * 60, limit: 100 });
|
|
4
4
|
this.routes = {
|
|
5
5
|
GET: {},
|
|
@@ -8,180 +8,109 @@
|
|
|
8
8
|
DELETE: {}
|
|
9
9
|
};
|
|
10
10
|
this.secret = crypto.makeSecret(Math.random().toString(36).substring(7));
|
|
11
|
-
this.config =
|
|
11
|
+
this.config = Object.assign({}, config);
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
_b.label = 3;
|
|
75
|
-
case 3:
|
|
76
|
-
_b.trys.push([3, 8, 9, 10]);
|
|
77
|
-
values_1 = tslib_es6.__values(values), values_1_1 = values_1.next();
|
|
78
|
-
_b.label = 4;
|
|
79
|
-
case 4:
|
|
80
|
-
if (!!values_1_1.done) return [3 /*break*/, 7];
|
|
81
|
-
value = values_1_1.value;
|
|
82
|
-
test = value.test, handler = value.handler;
|
|
83
|
-
match_1 = test(path);
|
|
84
|
-
if (!match_1) return [3 /*break*/, 6];
|
|
85
|
-
info.params = match_1.params;
|
|
86
|
-
return [4 /*yield*/, handler(info, args)];
|
|
87
|
-
case 5:
|
|
88
|
-
_b.sent();
|
|
89
|
-
this.HandlerCache.set("".concat(method, ":").concat(path), handler);
|
|
90
|
-
_b.label = 6;
|
|
91
|
-
case 6:
|
|
92
|
-
values_1_1 = values_1.next();
|
|
93
|
-
return [3 /*break*/, 4];
|
|
94
|
-
case 7: return [3 /*break*/, 10];
|
|
95
|
-
case 8:
|
|
96
|
-
e_1_1 = _b.sent();
|
|
97
|
-
e_1 = { error: e_1_1 };
|
|
98
|
-
return [3 /*break*/, 10];
|
|
99
|
-
case 9:
|
|
100
|
-
try {
|
|
101
|
-
if (values_1_1 && !values_1_1.done && (_a = values_1.return)) _a.call(values_1);
|
|
102
|
-
}
|
|
103
|
-
finally { if (e_1) throw e_1.error; }
|
|
104
|
-
return [7 /*endfinally*/];
|
|
105
|
-
case 10: return [2 /*return*/];
|
|
13
|
+
async addRoute(path, method, handler) {
|
|
14
|
+
if (this.routes[method][path])
|
|
15
|
+
return;
|
|
16
|
+
this.routes[method][path] = {
|
|
17
|
+
handler,
|
|
18
|
+
test: pathToRegexp.match(path)
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
async get(path, handler) {
|
|
22
|
+
this.addRoute(path, 'GET', handler);
|
|
23
|
+
}
|
|
24
|
+
async post(path, handler) {
|
|
25
|
+
this.addRoute(path, 'POST', handler);
|
|
26
|
+
}
|
|
27
|
+
async put(path, handler) {
|
|
28
|
+
this.addRoute(path, 'PUT', handler);
|
|
29
|
+
}
|
|
30
|
+
async delete(path, handler) {
|
|
31
|
+
this.addRoute(path, 'DELETE', handler);
|
|
32
|
+
}
|
|
33
|
+
async handleRequest(info, args) {
|
|
34
|
+
const { path, method } = info;
|
|
35
|
+
let cacheHandler = this.HandlerCache.get(`${method}:${path}`);
|
|
36
|
+
if (cacheHandler) {
|
|
37
|
+
await cacheHandler(info, args);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
let values = Object.values(this.routes[method]);
|
|
41
|
+
for (let value of values) {
|
|
42
|
+
let { test, handler } = value;
|
|
43
|
+
const match = test(path);
|
|
44
|
+
if (match) {
|
|
45
|
+
info.params = match.params;
|
|
46
|
+
await handler(info, args);
|
|
47
|
+
this.HandlerCache.set(`${method}:${path}`, handler);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async listen(listenerInfo, args) {
|
|
52
|
+
try {
|
|
53
|
+
if (!listenerInfo.signeture || !listenerInfo.path || !listenerInfo.method)
|
|
54
|
+
throw new Error("Invalid Request");
|
|
55
|
+
const clientSecret = signeture.verify(listenerInfo.signeture);
|
|
56
|
+
const { path, body, method } = listenerInfo;
|
|
57
|
+
const url = new URL(path, "http://localhost");
|
|
58
|
+
// format the path
|
|
59
|
+
url.pathname = url.pathname.replace(this.config.basepath, "/");
|
|
60
|
+
let split = url.pathname.split("/").map((s) => reverser.decrypt(s)).filter((s) => s.length > 0);
|
|
61
|
+
url.pathname = `/${split.join("/")}`;
|
|
62
|
+
// handle handshake
|
|
63
|
+
const handshakeSecret = crypto.makeSecret(this.secret + clientSecret);
|
|
64
|
+
const reqkey = handshakeSecret.substring(0, handshakeSecret.length / 2);
|
|
65
|
+
if (method === 'GET' && url.pathname === "/handshake") {
|
|
66
|
+
throw crypto.encrypt(handshakeSecret, clientSecret);
|
|
67
|
+
}
|
|
68
|
+
let data = {}, searchParams = {};
|
|
69
|
+
if (url.searchParams.has(reqkey)) {
|
|
70
|
+
let decripted = crypto.decrypt(url.searchParams.get(reqkey), handshakeSecret);
|
|
71
|
+
for (let key in decripted) {
|
|
72
|
+
let ukey = reverser.decrypt(key);
|
|
73
|
+
searchParams[ukey] = decripted[key];
|
|
106
74
|
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return tslib_es6.__generator(this, function (_a) {
|
|
114
|
-
switch (_a.label) {
|
|
115
|
-
case 0:
|
|
116
|
-
_a.trys.push([0, 2, , 6]);
|
|
117
|
-
if (!listenerInfo.signeture || !listenerInfo.path || !listenerInfo.method)
|
|
118
|
-
throw new Error("Invalid Request");
|
|
119
|
-
clientSecret = signeture.verify(listenerInfo.signeture);
|
|
120
|
-
path = listenerInfo.path, body = listenerInfo.body, method = listenerInfo.method;
|
|
121
|
-
url = new URL(path, "http://localhost");
|
|
122
|
-
// format the path
|
|
123
|
-
url.pathname = url.pathname.replace(this.config.basepath, "/");
|
|
124
|
-
split = url.pathname.split("/").map(function (s) { return reverser.decrypt(s); }).filter(function (s) { return s.length > 0; });
|
|
125
|
-
url.pathname = "/".concat(split.join("/"));
|
|
126
|
-
handshakeSecret = crypto.makeSecret(this.secret + clientSecret);
|
|
127
|
-
reqkey = handshakeSecret.substring(0, handshakeSecret.length / 2);
|
|
128
|
-
if (method === 'GET' && url.pathname === "/handshake") {
|
|
129
|
-
throw crypto.encrypt(handshakeSecret, clientSecret);
|
|
130
|
-
}
|
|
131
|
-
data = {}, searchParams = {};
|
|
132
|
-
if (url.searchParams.has(reqkey)) {
|
|
133
|
-
decripted = crypto.decrypt(url.searchParams.get(reqkey), handshakeSecret);
|
|
134
|
-
for (key in decripted) {
|
|
135
|
-
ukey = reverser.decrypt(key);
|
|
136
|
-
searchParams[ukey] = decripted[key];
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
if (body[reqkey]) {
|
|
140
|
-
decripted = crypto.decrypt(body[reqkey], handshakeSecret);
|
|
141
|
-
for (key in decripted) {
|
|
142
|
-
ukey = reverser.decrypt(key);
|
|
143
|
-
data[ukey] = decripted[key];
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
// handle the request
|
|
147
|
-
return [4 /*yield*/, this.handleRequest({
|
|
148
|
-
method: method,
|
|
149
|
-
path: url.pathname,
|
|
150
|
-
body: data,
|
|
151
|
-
searchParams: searchParams,
|
|
152
|
-
params: {}
|
|
153
|
-
}, args)];
|
|
154
|
-
case 1:
|
|
155
|
-
// handle the request
|
|
156
|
-
_a.sent();
|
|
157
|
-
return [3 /*break*/, 6];
|
|
158
|
-
case 2:
|
|
159
|
-
info_1 = _a.sent();
|
|
160
|
-
if (!(info_1 instanceof Error)) return [3 /*break*/, 3];
|
|
161
|
-
return [2 /*return*/, {
|
|
162
|
-
status: 404,
|
|
163
|
-
value: responseValue.encrypt(info_1.message, listenerInfo.signeture)
|
|
164
|
-
}];
|
|
165
|
-
case 3:
|
|
166
|
-
if (!(info_1 instanceof Response)) return [3 /*break*/, 5];
|
|
167
|
-
return [4 /*yield*/, info_1.text()];
|
|
168
|
-
case 4:
|
|
169
|
-
text = _a.sent();
|
|
170
|
-
return [2 /*return*/, {
|
|
171
|
-
status: info_1.status,
|
|
172
|
-
value: responseValue.encrypt(text, listenerInfo.signeture)
|
|
173
|
-
}];
|
|
174
|
-
case 5: return [2 /*return*/, {
|
|
175
|
-
status: 200,
|
|
176
|
-
value: responseValue.encrypt(info_1, listenerInfo.signeture)
|
|
177
|
-
}];
|
|
178
|
-
case 6: return [2 /*return*/, {
|
|
179
|
-
status: 404,
|
|
180
|
-
value: 'Not Found'
|
|
181
|
-
}];
|
|
75
|
+
}
|
|
76
|
+
if (body[reqkey]) {
|
|
77
|
+
let decripted = crypto.decrypt(body[reqkey], handshakeSecret);
|
|
78
|
+
for (let key in decripted) {
|
|
79
|
+
let ukey = reverser.decrypt(key);
|
|
80
|
+
data[ukey] = decripted[key];
|
|
182
81
|
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
82
|
+
}
|
|
83
|
+
// handle the request
|
|
84
|
+
await this.handleRequest({
|
|
85
|
+
method,
|
|
86
|
+
path: url.pathname,
|
|
87
|
+
body: data,
|
|
88
|
+
searchParams,
|
|
89
|
+
params: {}
|
|
90
|
+
}, args);
|
|
91
|
+
}
|
|
92
|
+
catch (info) {
|
|
93
|
+
if (info instanceof Error) {
|
|
94
|
+
return {
|
|
95
|
+
status: 404,
|
|
96
|
+
value: responseValue.encrypt(info.message, listenerInfo.signeture)
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
else if (info instanceof Response) {
|
|
100
|
+
let text = await info.text();
|
|
101
|
+
return {
|
|
102
|
+
status: info.status,
|
|
103
|
+
value: responseValue.encrypt(text, listenerInfo.signeture)
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
status: 200,
|
|
108
|
+
value: responseValue.encrypt(info, listenerInfo.signeture)
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
status: 404,
|
|
113
|
+
value: 'Not Found'
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}exports.SecurequServer=SecurequServer;exports.default=SecurequServer;//# sourceMappingURL=index.js.map
|
package/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/server/index.ts"],"sourcesContent":["import { match } from \"path-to-regexp\";\nimport crypto from \"../include/lib/crypto\";\nimport reverser from \"../include/lib/reverser\";\nimport responseValue from \"../include/responseValue\";\nimport signeture from \"../include/signeture\";\nimport { HandlerFunction, HandlerInfo, HTTPMethods, ListenerInfo, RouteFactory, ServerResponse, SecurequServerConfig } from \"./types\";\nimport SecurequCache from \"../include/lib/cache\";\n\nexport class SecurequServer {\n private HandlerCache = new SecurequCache<HandlerFunction>({ ttl: 1000 * 60 * 60, limit: 100 });\n private routes: RouteFactory = {\n GET: {},\n POST: {},\n PUT: {},\n DELETE: {}\n };\n private config: SecurequServerConfig;\n private secret: string = crypto.makeSecret(Math.random().toString(36).substring(7));\n\n constructor(config: SecurequServerConfig) {\n this.config = { ...config }\n }\n\n async addRoute(path: string, method: HTTPMethods, handler: HandlerFunction) {\n if (this.routes[method][path]) return\n this.routes[method][path] = {\n handler,\n test: match(path)\n }\n }\n\n async get(path: string, handler: HandlerFunction) {\n this.addRoute(path, 'GET', handler)\n }\n\n async post(path: string, handler: HandlerFunction) {\n this.addRoute(path, 'POST', handler)\n }\n\n async put(path: string, handler: HandlerFunction) {\n this.addRoute(path, 'PUT', handler)\n }\n\n async delete(path: string, handler: HandlerFunction) {\n this.addRoute(path, 'DELETE', handler)\n }\n\n async handleRequest(info: HandlerInfo, args?: any) {\n const { path, method } = info;\n let cacheHandler = this.HandlerCache.get(`${method}:${path}`);\n if (cacheHandler) {\n await cacheHandler(info, args)\n return\n }\n let values: any = Object.values(this.routes[method]);\n for (let value of values) {\n let { test, handler } = value\n const match = test(path)\n if (match) {\n info.params = match.params;\n await handler(info, args)\n this.HandlerCache.set(`${method}:${path}`, handler)\n }\n }\n }\n\n async listen(listenerInfo: ListenerInfo, args?: any): Promise<ServerResponse> {\n try {\n if (!listenerInfo.signeture || !listenerInfo.path || !listenerInfo.method) throw new Error(\"Invalid Request\");\n\n const clientSecret = signeture.verify(listenerInfo.signeture);\n const { path, body, method } = listenerInfo;\n const url = new URL(path, \"http://localhost\");\n\n // format the path\n url.pathname = url.pathname.replace(this.config.basepath, \"/\")\n let split = url.pathname.split(\"/\").map((s) => reverser.decrypt(s)).filter((s) => s.length > 0);\n url.pathname = `/${split.join(\"/\")}`;\n\n // handle handshake \n const handshakeSecret = crypto.makeSecret(this.secret + clientSecret);\n const reqkey = handshakeSecret.substring(0, handshakeSecret.length / 2);\n\n if (method === 'GET' && url.pathname === \"/handshake\") {\n throw crypto.encrypt(handshakeSecret, clientSecret)\n }\n\n let data: any = {}, searchParams: any = {}\n\n if (url.searchParams.has(reqkey)) {\n let decripted: any = crypto.decrypt(url.searchParams.get(reqkey) as string, handshakeSecret)\n for (let key in decripted) {\n let ukey = reverser.decrypt(key)\n searchParams[ukey] = decripted[key]\n }\n }\n\n if (body[reqkey]) {\n let decripted: any = crypto.decrypt(body[reqkey], handshakeSecret)\n for (let key in decripted) {\n let ukey = reverser.decrypt(key)\n data[ukey] = decripted[key]\n }\n }\n\n // handle the request\n await this.handleRequest({\n method,\n path: url.pathname,\n body: data,\n searchParams,\n params: {}\n }, args);\n } catch (info: any) {\n if (info instanceof Error) {\n return {\n status: 404,\n value: responseValue.encrypt(info.message, listenerInfo.signeture)\n }\n } else if (info instanceof Response) {\n let text = await info.text();\n return {\n status: info.status,\n value: responseValue.encrypt(text, listenerInfo.signeture)\n }\n }\n return {\n status: 200,\n value: responseValue.encrypt(info, listenerInfo.signeture)\n };\n }\n\n return {\n status: 404,\n value: 'Not Found'\n };\n }\n}\n\nexport default SecurequServer;"],"names":["SecurequCache","__assign","match","__values"],"mappings":"8YAQA,IAAA,cAAA,kBAAA,YAAA;AAWG,IAAA,SAAA,cAAA,CAAY,MAA4B,EAAA;AAVhC,QAAA,IAAA,CAAA,YAAY,GAAG,IAAIA,KAAa,CAAkB,EAAE,GAAG,EAAE,IAAI,GAAG,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;AACtF,QAAA,IA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AA,MAAM,EAAE;6BACV,EAAE,IAAI,CAAC,CAAA;;;AANR,wBAAA,EAAA,CAAA,IAAA,EAMQ;;;;AAEJ,wBAAA,IAAA,EAAA,MAAI,YAAY,KAAK,CAAA,EAArB,OAAqB,CAAA,CAAA,YAAA,CAAA,CAAA;wBACtB,OAAO,CAAA,CAAA,aAAA;AACJ,gCAAA,MAAM,EAAE,GAAG;AACX,gCAAA,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,MAAI,CAAC,OAAO,EAAE,YAAY,CAAC,SAAS;6BACnE,CAAA;;AACO,wBAAA,IAAA,EAAA,MAAI,YAAY,QAAQ,CAAA,EAAxB,OAAwB,CAAA,CAAA,YAAA,CAAA,CAAA;AACrB,wBAAA,OAAA,CAAA,CAAA,YAAM,MAAI,CAAC,IAAI,EAAE,CAAA;;AAAxB,wBAAA,IAAI,GAAG,EAAiB,CAAA,IAAA,EAAA;wBAC5B,OAAO,CAAA,CAAA,aAAA;gCACJ,MAAM,EAAE,MAAI,CAAC,MAAM;gCACnB,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,IAAI,EAAE,YAAY,CAAC,SAAS;6BAC3D,CAAA;4BAEJ,OAAO,CAAA,CAAA,aAAA;AACJ,4BAAA,MAAM,EAAE,GAAG;4BACX,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,MAAI,EAAE,YAAY,CAAC,SAAS;yBAC3D,CAAC;4BAGL,OAAO,CAAA,CAAA,aAAA;AACJ,4BAAA,MAAM,EAAE,GAAG;AACX,4BAAA,KAAK,EAAE;yBACT,CAAC;;;;AACJ,KAAA;IACJ,OAAC,cAAA;AAAD,CAAC,EAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/server/index.ts"],"sourcesContent":["import { match } from \"path-to-regexp\";\nimport crypto from \"../include/lib/crypto\";\nimport reverser from \"../include/lib/reverser\";\nimport responseValue from \"../include/responseValue\";\nimport signeture from \"../include/signeture\";\nimport { HandlerFunction, HandlerInfo, HTTPMethods, ListenerInfo, RouteFactory, ServerResponse, SecurequServerConfig } from \"./types\";\nimport SecurequCache from \"../include/lib/cache\";\n\nexport class SecurequServer {\n private HandlerCache = new SecurequCache<HandlerFunction>({ ttl: 1000 * 60 * 60, limit: 100 });\n private routes: RouteFactory = {\n GET: {},\n POST: {},\n PUT: {},\n DELETE: {}\n };\n private config: SecurequServerConfig;\n private secret: string = crypto.makeSecret(Math.random().toString(36).substring(7));\n\n constructor(config: SecurequServerConfig) {\n this.config = { ...config }\n }\n\n async addRoute(path: string, method: HTTPMethods, handler: HandlerFunction) {\n if (this.routes[method][path]) return\n this.routes[method][path] = {\n handler,\n test: match(path)\n }\n }\n\n async get(path: string, handler: HandlerFunction) {\n this.addRoute(path, 'GET', handler)\n }\n\n async post(path: string, handler: HandlerFunction) {\n this.addRoute(path, 'POST', handler)\n }\n\n async put(path: string, handler: HandlerFunction) {\n this.addRoute(path, 'PUT', handler)\n }\n\n async delete(path: string, handler: HandlerFunction) {\n this.addRoute(path, 'DELETE', handler)\n }\n\n async handleRequest(info: HandlerInfo, args?: any) {\n const { path, method } = info;\n let cacheHandler = this.HandlerCache.get(`${method}:${path}`);\n if (cacheHandler) {\n await cacheHandler(info, args)\n return\n }\n let values: any = Object.values(this.routes[method]);\n for (let value of values) {\n let { test, handler } = value\n const match = test(path)\n if (match) {\n info.params = match.params;\n await handler(info, args)\n this.HandlerCache.set(`${method}:${path}`, handler)\n }\n }\n }\n\n async listen(listenerInfo: ListenerInfo, args?: any): Promise<ServerResponse> {\n try {\n if (!listenerInfo.signeture || !listenerInfo.path || !listenerInfo.method) throw new Error(\"Invalid Request\");\n\n const clientSecret = signeture.verify(listenerInfo.signeture);\n const { path, body, method } = listenerInfo;\n const url = new URL(path, \"http://localhost\");\n\n // format the path\n url.pathname = url.pathname.replace(this.config.basepath, \"/\")\n let split = url.pathname.split(\"/\").map((s) => reverser.decrypt(s)).filter((s) => s.length > 0);\n url.pathname = `/${split.join(\"/\")}`;\n\n // handle handshake \n const handshakeSecret = crypto.makeSecret(this.secret + clientSecret);\n const reqkey = handshakeSecret.substring(0, handshakeSecret.length / 2);\n\n if (method === 'GET' && url.pathname === \"/handshake\") {\n throw crypto.encrypt(handshakeSecret, clientSecret)\n }\n\n let data: any = {}, searchParams: any = {}\n\n if (url.searchParams.has(reqkey)) {\n let decripted: any = crypto.decrypt(url.searchParams.get(reqkey) as string, handshakeSecret)\n for (let key in decripted) {\n let ukey = reverser.decrypt(key)\n searchParams[ukey] = decripted[key]\n }\n }\n\n if (body[reqkey]) {\n let decripted: any = crypto.decrypt(body[reqkey], handshakeSecret)\n for (let key in decripted) {\n let ukey = reverser.decrypt(key)\n data[ukey] = decripted[key]\n }\n }\n\n // handle the request\n await this.handleRequest({\n method,\n path: url.pathname,\n body: data,\n searchParams,\n params: {}\n }, args);\n } catch (info: any) {\n if (info instanceof Error) {\n return {\n status: 404,\n value: responseValue.encrypt(info.message, listenerInfo.signeture)\n }\n } else if (info instanceof Response) {\n let text = await info.text();\n return {\n status: info.status,\n value: responseValue.encrypt(text, listenerInfo.signeture)\n }\n }\n return {\n status: 200,\n value: responseValue.encrypt(info, listenerInfo.signeture)\n };\n }\n\n return {\n status: 404,\n value: 'Not Found'\n };\n }\n}\n\nexport default SecurequServer;"],"names":["SecurequCache","match"],"mappings":"4VAQa,cAAc,CAAA;AAWxB,IAAA,WAAA,CAAY,MAA4B,EAAA;AAVhC,QAAA,IAAA,CAAA,YAAY,GAAG,IAAIA,KAAa,CAAkB,EAAE,GAAG,EAAE,IAAI,GAAG,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;AACtF,QAAA,IAAA,CAAA,MAAM,GAAiB;AAC5B,YAAA,GAAG,EAAE,EAAE;AACP,YAAA,IAAI,EAAE,EAAE;AACR,YAAA,GAAG,EAAE,EAAE;AACP,YAAA,MAAM,EAAE;SACV;QAEO,IAAA,CAAA,MAAM,GAAW,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM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