@faasjs/http 0.0.3-beta.12 → 0.0.3-beta.13
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/README.md +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +20 -1
- package/dist/index.mjs +20 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -200,7 +200,7 @@ ___
|
|
|
200
200
|
|
|
201
201
|
### useHttp
|
|
202
202
|
|
|
203
|
-
▸ **useHttp**<`TParams`, `TCookie`, `TSession`\>(`config?`): [`Http`](classes/Http.md)<`TParams`, `TCookie`, `TSession
|
|
203
|
+
▸ **useHttp**<`TParams`, `TCookie`, `TSession`\>(`config?`): `UseifyPlugin`<[`Http`](classes/Http.md)<`TParams`, `TCookie`, `TSession`\>\>
|
|
204
204
|
|
|
205
205
|
#### Type parameters
|
|
206
206
|
|
|
@@ -218,4 +218,4 @@ ___
|
|
|
218
218
|
|
|
219
219
|
#### Returns
|
|
220
220
|
|
|
221
|
-
[`Http`](classes/Http.md)<`TParams`, `TCookie`, `TSession
|
|
221
|
+
`UseifyPlugin`<[`Http`](classes/Http.md)<`TParams`, `TCookie`, `TSession`\>\>
|
package/dist/index.d.ts
CHANGED
|
@@ -204,6 +204,6 @@ declare class Http<TParams extends Record<string, any> = any, TCookie extends Re
|
|
|
204
204
|
*/
|
|
205
205
|
setBody(body: string): Http<TParams, TCookie, TSession>;
|
|
206
206
|
}
|
|
207
|
-
declare function useHttp<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any>(config?: HttpConfig<TParams, TCookie, TSession>): Http<TParams, TCookie, TSession
|
|
207
|
+
declare function useHttp<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any>(config?: HttpConfig<TParams, TCookie, TSession>): UseifyPlugin<Http<TParams, TCookie, TSession>>;
|
|
208
208
|
|
|
209
209
|
export { ContentType, Cookie, CookieOptions, Http, HttpConfig, HttpError, Response, Session, SessionOptions, Validator, ValidatorConfig, ValidatorOptions, ValidatorRuleOptions, useHttp };
|
package/dist/index.js
CHANGED
|
@@ -66,6 +66,8 @@ var import_crypto = require("crypto");
|
|
|
66
66
|
var Session = class {
|
|
67
67
|
constructor(cookie, config) {
|
|
68
68
|
this.cookie = cookie;
|
|
69
|
+
if (!(config == null ? void 0 : config.secret))
|
|
70
|
+
console.warn("Session's secret is missing.");
|
|
69
71
|
this.config = Object.assign({
|
|
70
72
|
key: "key",
|
|
71
73
|
secret: (0, import_crypto.randomBytes)(128).toString("hex"),
|
|
@@ -120,7 +122,7 @@ var Session = class {
|
|
|
120
122
|
hmac.update(signedParts[0]);
|
|
121
123
|
const digest = hmac.digest("hex");
|
|
122
124
|
if (signedParts[1] !== digest)
|
|
123
|
-
throw Error("Not valid");
|
|
125
|
+
throw Error("Session Not valid");
|
|
124
126
|
const message = Buffer.from(signedParts[0], "base64").toString();
|
|
125
127
|
const parts = message.split("--").map(function(part2) {
|
|
126
128
|
return Buffer.from(part2, "base64");
|
|
@@ -459,6 +461,23 @@ var Http = class {
|
|
|
459
461
|
}
|
|
460
462
|
async onMount(data, next) {
|
|
461
463
|
data.logger.debug("[onMount] merge config");
|
|
464
|
+
const prefix = `SECRET_${this.name.toUpperCase()}_`;
|
|
465
|
+
for (let key in process.env)
|
|
466
|
+
if (key.startsWith(prefix)) {
|
|
467
|
+
const value = process.env[key];
|
|
468
|
+
key = key.replace(prefix, "").toLowerCase();
|
|
469
|
+
if (key.includes("_")) {
|
|
470
|
+
let config = this.config;
|
|
471
|
+
const keys = key.split("_");
|
|
472
|
+
keys.slice(0, keys.length - 1).forEach((k) => {
|
|
473
|
+
if (!config[k])
|
|
474
|
+
config[k] = /* @__PURE__ */ Object.create(null);
|
|
475
|
+
config = config[k];
|
|
476
|
+
});
|
|
477
|
+
config[keys[keys.length - 1]] = value;
|
|
478
|
+
} else
|
|
479
|
+
this.config[key] = value;
|
|
480
|
+
}
|
|
462
481
|
if (data.config.plugins && data.config.plugins[this.name || this.type])
|
|
463
482
|
this.config = deepMerge(this.config, data.config.plugins[this.name || this.type].config);
|
|
464
483
|
data.logger.debug("[onMount] prepare cookie & session");
|
package/dist/index.mjs
CHANGED
|
@@ -52,6 +52,8 @@ import {
|
|
|
52
52
|
var Session = class {
|
|
53
53
|
constructor(cookie, config) {
|
|
54
54
|
this.cookie = cookie;
|
|
55
|
+
if (!(config == null ? void 0 : config.secret))
|
|
56
|
+
console.warn("Session's secret is missing.");
|
|
55
57
|
this.config = Object.assign({
|
|
56
58
|
key: "key",
|
|
57
59
|
secret: randomBytes(128).toString("hex"),
|
|
@@ -106,7 +108,7 @@ var Session = class {
|
|
|
106
108
|
hmac.update(signedParts[0]);
|
|
107
109
|
const digest = hmac.digest("hex");
|
|
108
110
|
if (signedParts[1] !== digest)
|
|
109
|
-
throw Error("Not valid");
|
|
111
|
+
throw Error("Session Not valid");
|
|
110
112
|
const message = Buffer.from(signedParts[0], "base64").toString();
|
|
111
113
|
const parts = message.split("--").map(function(part2) {
|
|
112
114
|
return Buffer.from(part2, "base64");
|
|
@@ -449,6 +451,23 @@ var Http = class {
|
|
|
449
451
|
}
|
|
450
452
|
async onMount(data, next) {
|
|
451
453
|
data.logger.debug("[onMount] merge config");
|
|
454
|
+
const prefix = `SECRET_${this.name.toUpperCase()}_`;
|
|
455
|
+
for (let key in process.env)
|
|
456
|
+
if (key.startsWith(prefix)) {
|
|
457
|
+
const value = process.env[key];
|
|
458
|
+
key = key.replace(prefix, "").toLowerCase();
|
|
459
|
+
if (key.includes("_")) {
|
|
460
|
+
let config = this.config;
|
|
461
|
+
const keys = key.split("_");
|
|
462
|
+
keys.slice(0, keys.length - 1).forEach((k) => {
|
|
463
|
+
if (!config[k])
|
|
464
|
+
config[k] = /* @__PURE__ */ Object.create(null);
|
|
465
|
+
config = config[k];
|
|
466
|
+
});
|
|
467
|
+
config[keys[keys.length - 1]] = value;
|
|
468
|
+
} else
|
|
469
|
+
this.config[key] = value;
|
|
470
|
+
}
|
|
452
471
|
if (data.config.plugins && data.config.plugins[this.name || this.type])
|
|
453
472
|
this.config = deepMerge(this.config, data.config.plugins[this.name || this.type].config);
|
|
454
473
|
data.logger.debug("[onMount] prepare cookie & session");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/http",
|
|
3
|
-
"version": "0.0.3-beta.
|
|
3
|
+
"version": "0.0.3-beta.13",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@faasjs/func": "^0.0.3-beta.
|
|
27
|
-
"@faasjs/logger": "^0.0.3-beta.
|
|
26
|
+
"@faasjs/func": "^0.0.3-beta.13",
|
|
27
|
+
"@faasjs/logger": "^0.0.3-beta.13"
|
|
28
28
|
},
|
|
29
29
|
"engines": {
|
|
30
30
|
"npm": ">=8.0.0",
|