@faasjs/http 0.0.2-beta.395 → 0.0.2-beta.398
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/dist/index.js +70 -14
- package/dist/index.mjs +70 -15
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -76,8 +76,20 @@ var Session = class {
|
|
|
76
76
|
digest: "sha256",
|
|
77
77
|
cipherName: "aes-256-cbc"
|
|
78
78
|
}, config);
|
|
79
|
-
this.secret = (0, import_crypto.pbkdf2Sync)(
|
|
80
|
-
|
|
79
|
+
this.secret = (0, import_crypto.pbkdf2Sync)(
|
|
80
|
+
this.config.secret,
|
|
81
|
+
this.config.salt,
|
|
82
|
+
this.config.iterations,
|
|
83
|
+
this.config.keylen / 2,
|
|
84
|
+
this.config.digest
|
|
85
|
+
);
|
|
86
|
+
this.signedSecret = (0, import_crypto.pbkdf2Sync)(
|
|
87
|
+
this.config.secret,
|
|
88
|
+
this.config.signedSalt,
|
|
89
|
+
this.config.iterations,
|
|
90
|
+
this.config.keylen,
|
|
91
|
+
this.config.digest
|
|
92
|
+
);
|
|
81
93
|
this.content = /* @__PURE__ */ Object.create(null);
|
|
82
94
|
}
|
|
83
95
|
invoke(cookie) {
|
|
@@ -226,13 +238,23 @@ var Validator = class {
|
|
|
226
238
|
this.logger.debug("Valid Cookie");
|
|
227
239
|
if (request.cookie == null)
|
|
228
240
|
throw Error("Not found Cookie");
|
|
229
|
-
this.validContent(
|
|
241
|
+
this.validContent(
|
|
242
|
+
"cookie",
|
|
243
|
+
request.cookie.content,
|
|
244
|
+
"",
|
|
245
|
+
this.cookieConfig
|
|
246
|
+
);
|
|
230
247
|
}
|
|
231
248
|
if (this.sessionConfig && request.session) {
|
|
232
249
|
this.logger.debug("Valid Session");
|
|
233
250
|
if (request.session == null)
|
|
234
251
|
throw Error("Not found Session");
|
|
235
|
-
this.validContent(
|
|
252
|
+
this.validContent(
|
|
253
|
+
"session",
|
|
254
|
+
request.session.content,
|
|
255
|
+
"",
|
|
256
|
+
this.sessionConfig
|
|
257
|
+
);
|
|
236
258
|
}
|
|
237
259
|
}
|
|
238
260
|
validContent(type, params, baseKey, config) {
|
|
@@ -243,7 +265,9 @@ var Validator = class {
|
|
|
243
265
|
if (diff.length > 0) {
|
|
244
266
|
if (config.whitelist === "error") {
|
|
245
267
|
const diffKeys = diff.map((k) => `${baseKey}${k}`);
|
|
246
|
-
const error = Error(
|
|
268
|
+
const error = Error(
|
|
269
|
+
`[${type}] Not permitted keys: ${diffKeys.join(", ")}`
|
|
270
|
+
);
|
|
247
271
|
if (config.onError) {
|
|
248
272
|
const res = config.onError(`${type}.whitelist`, baseKey, diffKeys);
|
|
249
273
|
if (res)
|
|
@@ -272,7 +296,11 @@ var Validator = class {
|
|
|
272
296
|
if (typeof value === "undefined" || value === null) {
|
|
273
297
|
const error = Error(`[${type}] ${baseKey}${key} is required.`);
|
|
274
298
|
if (config.onError) {
|
|
275
|
-
const res = config.onError(
|
|
299
|
+
const res = config.onError(
|
|
300
|
+
`${type}.rule.required`,
|
|
301
|
+
`${baseKey}${key}`,
|
|
302
|
+
value
|
|
303
|
+
);
|
|
276
304
|
if (res)
|
|
277
305
|
throw new HttpError(res);
|
|
278
306
|
}
|
|
@@ -297,9 +325,15 @@ var Validator = class {
|
|
|
297
325
|
break;
|
|
298
326
|
}
|
|
299
327
|
if (!typed) {
|
|
300
|
-
const error = Error(
|
|
328
|
+
const error = Error(
|
|
329
|
+
`[${type}] ${baseKey}${key} must be a ${rule.type}.`
|
|
330
|
+
);
|
|
301
331
|
if (config.onError) {
|
|
302
|
-
const res = config.onError(
|
|
332
|
+
const res = config.onError(
|
|
333
|
+
`${type}.rule.type`,
|
|
334
|
+
`${baseKey}${key}`,
|
|
335
|
+
value
|
|
336
|
+
);
|
|
303
337
|
if (res)
|
|
304
338
|
throw new HttpError(res);
|
|
305
339
|
}
|
|
@@ -307,18 +341,30 @@ var Validator = class {
|
|
|
307
341
|
}
|
|
308
342
|
}
|
|
309
343
|
if (rule.regexp && (rule.type === "string" || !rule.type) && !rule.regexp.test(value)) {
|
|
310
|
-
const error = Error(
|
|
344
|
+
const error = Error(
|
|
345
|
+
`[${type}] ${baseKey}${key} must match ${rule.regexp}.`
|
|
346
|
+
);
|
|
311
347
|
if (config.onError) {
|
|
312
|
-
const res = config.onError(
|
|
348
|
+
const res = config.onError(
|
|
349
|
+
`${type}.rule.regexp`,
|
|
350
|
+
`${baseKey}${key}`,
|
|
351
|
+
value
|
|
352
|
+
);
|
|
313
353
|
if (res)
|
|
314
354
|
throw new HttpError(res);
|
|
315
355
|
}
|
|
316
356
|
throw error;
|
|
317
357
|
}
|
|
318
358
|
if (rule.in && !rule.in.includes(value)) {
|
|
319
|
-
const error = Error(
|
|
359
|
+
const error = Error(
|
|
360
|
+
`[${type}] ${baseKey}${key} must be in ${rule.in.join(", ")}.`
|
|
361
|
+
);
|
|
320
362
|
if (config.onError) {
|
|
321
|
-
const res = config.onError(
|
|
363
|
+
const res = config.onError(
|
|
364
|
+
`${type}.rule.in`,
|
|
365
|
+
`${baseKey}${key}`,
|
|
366
|
+
value
|
|
367
|
+
);
|
|
322
368
|
if (res)
|
|
323
369
|
throw new HttpError(res);
|
|
324
370
|
}
|
|
@@ -329,9 +375,19 @@ var Validator = class {
|
|
|
329
375
|
this.logger.warn("Cookie not support nest rule.");
|
|
330
376
|
else if (Array.isArray(value))
|
|
331
377
|
for (const val of value)
|
|
332
|
-
this.validContent(
|
|
378
|
+
this.validContent(
|
|
379
|
+
type,
|
|
380
|
+
val,
|
|
381
|
+
baseKey ? `${baseKey}.${key}.` : `${key}.`,
|
|
382
|
+
rule.config
|
|
383
|
+
);
|
|
333
384
|
else if (typeof value === "object")
|
|
334
|
-
this.validContent(
|
|
385
|
+
this.validContent(
|
|
386
|
+
type,
|
|
387
|
+
value,
|
|
388
|
+
baseKey ? `${baseKey}.${key}.` : `${key}.`,
|
|
389
|
+
rule.config
|
|
390
|
+
);
|
|
335
391
|
}
|
|
336
392
|
}
|
|
337
393
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
2
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
3
|
}) : x)(function(x) {
|
|
@@ -63,8 +62,20 @@ var Session = class {
|
|
|
63
62
|
digest: "sha256",
|
|
64
63
|
cipherName: "aes-256-cbc"
|
|
65
64
|
}, config);
|
|
66
|
-
this.secret = pbkdf2Sync(
|
|
67
|
-
|
|
65
|
+
this.secret = pbkdf2Sync(
|
|
66
|
+
this.config.secret,
|
|
67
|
+
this.config.salt,
|
|
68
|
+
this.config.iterations,
|
|
69
|
+
this.config.keylen / 2,
|
|
70
|
+
this.config.digest
|
|
71
|
+
);
|
|
72
|
+
this.signedSecret = pbkdf2Sync(
|
|
73
|
+
this.config.secret,
|
|
74
|
+
this.config.signedSalt,
|
|
75
|
+
this.config.iterations,
|
|
76
|
+
this.config.keylen,
|
|
77
|
+
this.config.digest
|
|
78
|
+
);
|
|
68
79
|
this.content = /* @__PURE__ */ Object.create(null);
|
|
69
80
|
}
|
|
70
81
|
invoke(cookie) {
|
|
@@ -213,13 +224,23 @@ var Validator = class {
|
|
|
213
224
|
this.logger.debug("Valid Cookie");
|
|
214
225
|
if (request.cookie == null)
|
|
215
226
|
throw Error("Not found Cookie");
|
|
216
|
-
this.validContent(
|
|
227
|
+
this.validContent(
|
|
228
|
+
"cookie",
|
|
229
|
+
request.cookie.content,
|
|
230
|
+
"",
|
|
231
|
+
this.cookieConfig
|
|
232
|
+
);
|
|
217
233
|
}
|
|
218
234
|
if (this.sessionConfig && request.session) {
|
|
219
235
|
this.logger.debug("Valid Session");
|
|
220
236
|
if (request.session == null)
|
|
221
237
|
throw Error("Not found Session");
|
|
222
|
-
this.validContent(
|
|
238
|
+
this.validContent(
|
|
239
|
+
"session",
|
|
240
|
+
request.session.content,
|
|
241
|
+
"",
|
|
242
|
+
this.sessionConfig
|
|
243
|
+
);
|
|
223
244
|
}
|
|
224
245
|
}
|
|
225
246
|
validContent(type, params, baseKey, config) {
|
|
@@ -230,7 +251,9 @@ var Validator = class {
|
|
|
230
251
|
if (diff.length > 0) {
|
|
231
252
|
if (config.whitelist === "error") {
|
|
232
253
|
const diffKeys = diff.map((k) => `${baseKey}${k}`);
|
|
233
|
-
const error = Error(
|
|
254
|
+
const error = Error(
|
|
255
|
+
`[${type}] Not permitted keys: ${diffKeys.join(", ")}`
|
|
256
|
+
);
|
|
234
257
|
if (config.onError) {
|
|
235
258
|
const res = config.onError(`${type}.whitelist`, baseKey, diffKeys);
|
|
236
259
|
if (res)
|
|
@@ -259,7 +282,11 @@ var Validator = class {
|
|
|
259
282
|
if (typeof value === "undefined" || value === null) {
|
|
260
283
|
const error = Error(`[${type}] ${baseKey}${key} is required.`);
|
|
261
284
|
if (config.onError) {
|
|
262
|
-
const res = config.onError(
|
|
285
|
+
const res = config.onError(
|
|
286
|
+
`${type}.rule.required`,
|
|
287
|
+
`${baseKey}${key}`,
|
|
288
|
+
value
|
|
289
|
+
);
|
|
263
290
|
if (res)
|
|
264
291
|
throw new HttpError(res);
|
|
265
292
|
}
|
|
@@ -284,9 +311,15 @@ var Validator = class {
|
|
|
284
311
|
break;
|
|
285
312
|
}
|
|
286
313
|
if (!typed) {
|
|
287
|
-
const error = Error(
|
|
314
|
+
const error = Error(
|
|
315
|
+
`[${type}] ${baseKey}${key} must be a ${rule.type}.`
|
|
316
|
+
);
|
|
288
317
|
if (config.onError) {
|
|
289
|
-
const res = config.onError(
|
|
318
|
+
const res = config.onError(
|
|
319
|
+
`${type}.rule.type`,
|
|
320
|
+
`${baseKey}${key}`,
|
|
321
|
+
value
|
|
322
|
+
);
|
|
290
323
|
if (res)
|
|
291
324
|
throw new HttpError(res);
|
|
292
325
|
}
|
|
@@ -294,18 +327,30 @@ var Validator = class {
|
|
|
294
327
|
}
|
|
295
328
|
}
|
|
296
329
|
if (rule.regexp && (rule.type === "string" || !rule.type) && !rule.regexp.test(value)) {
|
|
297
|
-
const error = Error(
|
|
330
|
+
const error = Error(
|
|
331
|
+
`[${type}] ${baseKey}${key} must match ${rule.regexp}.`
|
|
332
|
+
);
|
|
298
333
|
if (config.onError) {
|
|
299
|
-
const res = config.onError(
|
|
334
|
+
const res = config.onError(
|
|
335
|
+
`${type}.rule.regexp`,
|
|
336
|
+
`${baseKey}${key}`,
|
|
337
|
+
value
|
|
338
|
+
);
|
|
300
339
|
if (res)
|
|
301
340
|
throw new HttpError(res);
|
|
302
341
|
}
|
|
303
342
|
throw error;
|
|
304
343
|
}
|
|
305
344
|
if (rule.in && !rule.in.includes(value)) {
|
|
306
|
-
const error = Error(
|
|
345
|
+
const error = Error(
|
|
346
|
+
`[${type}] ${baseKey}${key} must be in ${rule.in.join(", ")}.`
|
|
347
|
+
);
|
|
307
348
|
if (config.onError) {
|
|
308
|
-
const res = config.onError(
|
|
349
|
+
const res = config.onError(
|
|
350
|
+
`${type}.rule.in`,
|
|
351
|
+
`${baseKey}${key}`,
|
|
352
|
+
value
|
|
353
|
+
);
|
|
309
354
|
if (res)
|
|
310
355
|
throw new HttpError(res);
|
|
311
356
|
}
|
|
@@ -316,9 +361,19 @@ var Validator = class {
|
|
|
316
361
|
this.logger.warn("Cookie not support nest rule.");
|
|
317
362
|
else if (Array.isArray(value))
|
|
318
363
|
for (const val of value)
|
|
319
|
-
this.validContent(
|
|
364
|
+
this.validContent(
|
|
365
|
+
type,
|
|
366
|
+
val,
|
|
367
|
+
baseKey ? `${baseKey}.${key}.` : `${key}.`,
|
|
368
|
+
rule.config
|
|
369
|
+
);
|
|
320
370
|
else if (typeof value === "object")
|
|
321
|
-
this.validContent(
|
|
371
|
+
this.validContent(
|
|
372
|
+
type,
|
|
373
|
+
value,
|
|
374
|
+
baseKey ? `${baseKey}.${key}.` : `${key}.`,
|
|
375
|
+
rule.config
|
|
376
|
+
);
|
|
322
377
|
}
|
|
323
378
|
}
|
|
324
379
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/http",
|
|
3
|
-
"version": "0.0.2-beta.
|
|
3
|
+
"version": "0.0.2-beta.398",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@faasjs/func": "^0.0.2-beta.
|
|
26
|
-
"@faasjs/logger": "^0.0.2-beta.
|
|
25
|
+
"@faasjs/func": "^0.0.2-beta.398",
|
|
26
|
+
"@faasjs/logger": "^0.0.2-beta.398"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"tsup": "*",
|