@faasjs/http 2.8.1 → 3.0.0-canary.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.
- package/dist/index.d.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +43 -46
- package/dist/index.mjs +43 -46
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Plugin,
|
|
1
|
+
import { Plugin, MountData, Next, InvokeData, UseifyPlugin } from '@faasjs/func';
|
|
2
2
|
import { Logger } from '@faasjs/logger';
|
|
3
3
|
|
|
4
4
|
type SessionOptions = {
|
|
@@ -79,7 +79,9 @@ declare class Cookie<C extends Record<string, string> = any, S extends Record<st
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
/** @deprecated */
|
|
82
83
|
type ValidatorRuleOptionsType = 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
84
|
+
/** @deprecated */
|
|
83
85
|
type ValidatorRuleOptions = {
|
|
84
86
|
type?: ValidatorRuleOptionsType;
|
|
85
87
|
required?: boolean;
|
|
@@ -88,6 +90,7 @@ type ValidatorRuleOptions = {
|
|
|
88
90
|
config?: Partial<ValidatorOptions>;
|
|
89
91
|
regexp?: RegExp;
|
|
90
92
|
};
|
|
93
|
+
/** @deprecated */
|
|
91
94
|
type ValidatorOptions<Content = Record<string, any>> = {
|
|
92
95
|
whitelist?: 'error' | 'ignore';
|
|
93
96
|
rules: {
|
|
@@ -106,16 +109,19 @@ type Request<TParams extends Record<string, any> = any, TCookie extends Record<s
|
|
|
106
109
|
cookie?: Cookie<TCookie, TSession>;
|
|
107
110
|
session?: Session<TSession, TCookie>;
|
|
108
111
|
};
|
|
112
|
+
/** @deprecated */
|
|
109
113
|
type BeforeOption<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any> = (request: Request<TParams, TCookie, TSession>) => Promise<void | {
|
|
110
114
|
statusCode?: number;
|
|
111
115
|
message: string;
|
|
112
116
|
}>;
|
|
117
|
+
/** @deprecated */
|
|
113
118
|
type ValidatorConfig<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any> = {
|
|
114
119
|
params?: ValidatorOptions<TParams>;
|
|
115
120
|
cookie?: ValidatorOptions<TCookie>;
|
|
116
121
|
session?: ValidatorOptions<TSession>;
|
|
117
122
|
before?: BeforeOption;
|
|
118
123
|
};
|
|
124
|
+
/** @deprecated */
|
|
119
125
|
declare class Validator<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any> {
|
|
120
126
|
before?: BeforeOption<TParams, TCookie, TSession>;
|
|
121
127
|
paramsConfig?: ValidatorOptions<TParams>;
|
|
@@ -161,6 +167,7 @@ type HttpConfig<TParams extends Record<string, any> = any, TCookie extends Recor
|
|
|
161
167
|
functionName?: string;
|
|
162
168
|
cookie?: CookieOptions;
|
|
163
169
|
};
|
|
170
|
+
/** @deprecated */
|
|
164
171
|
validator?: ValidatorConfig<TParams, TCookie, TSession>;
|
|
165
172
|
};
|
|
166
173
|
type Response = {
|
|
@@ -194,7 +201,6 @@ declare class Http<TParams extends Record<string, any> = any, TCookie extends Re
|
|
|
194
201
|
private response?;
|
|
195
202
|
private validator?;
|
|
196
203
|
constructor(config?: HttpConfig<TParams, TCookie, TSession>);
|
|
197
|
-
onDeploy(data: DeployData, next: Next): Promise<void>;
|
|
198
204
|
onMount(data: MountData, next: Next): Promise<void>;
|
|
199
205
|
onInvoke(data: InvokeData, next: Next): Promise<void>;
|
|
200
206
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Plugin,
|
|
1
|
+
import { Plugin, MountData, Next, InvokeData, UseifyPlugin } from '@faasjs/func';
|
|
2
2
|
import { Logger } from '@faasjs/logger';
|
|
3
3
|
|
|
4
4
|
type SessionOptions = {
|
|
@@ -79,7 +79,9 @@ declare class Cookie<C extends Record<string, string> = any, S extends Record<st
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
/** @deprecated */
|
|
82
83
|
type ValidatorRuleOptionsType = 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
84
|
+
/** @deprecated */
|
|
83
85
|
type ValidatorRuleOptions = {
|
|
84
86
|
type?: ValidatorRuleOptionsType;
|
|
85
87
|
required?: boolean;
|
|
@@ -88,6 +90,7 @@ type ValidatorRuleOptions = {
|
|
|
88
90
|
config?: Partial<ValidatorOptions>;
|
|
89
91
|
regexp?: RegExp;
|
|
90
92
|
};
|
|
93
|
+
/** @deprecated */
|
|
91
94
|
type ValidatorOptions<Content = Record<string, any>> = {
|
|
92
95
|
whitelist?: 'error' | 'ignore';
|
|
93
96
|
rules: {
|
|
@@ -106,16 +109,19 @@ type Request<TParams extends Record<string, any> = any, TCookie extends Record<s
|
|
|
106
109
|
cookie?: Cookie<TCookie, TSession>;
|
|
107
110
|
session?: Session<TSession, TCookie>;
|
|
108
111
|
};
|
|
112
|
+
/** @deprecated */
|
|
109
113
|
type BeforeOption<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any> = (request: Request<TParams, TCookie, TSession>) => Promise<void | {
|
|
110
114
|
statusCode?: number;
|
|
111
115
|
message: string;
|
|
112
116
|
}>;
|
|
117
|
+
/** @deprecated */
|
|
113
118
|
type ValidatorConfig<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any> = {
|
|
114
119
|
params?: ValidatorOptions<TParams>;
|
|
115
120
|
cookie?: ValidatorOptions<TCookie>;
|
|
116
121
|
session?: ValidatorOptions<TSession>;
|
|
117
122
|
before?: BeforeOption;
|
|
118
123
|
};
|
|
124
|
+
/** @deprecated */
|
|
119
125
|
declare class Validator<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any> {
|
|
120
126
|
before?: BeforeOption<TParams, TCookie, TSession>;
|
|
121
127
|
paramsConfig?: ValidatorOptions<TParams>;
|
|
@@ -161,6 +167,7 @@ type HttpConfig<TParams extends Record<string, any> = any, TCookie extends Recor
|
|
|
161
167
|
functionName?: string;
|
|
162
168
|
cookie?: CookieOptions;
|
|
163
169
|
};
|
|
170
|
+
/** @deprecated */
|
|
164
171
|
validator?: ValidatorConfig<TParams, TCookie, TSession>;
|
|
165
172
|
};
|
|
166
173
|
type Response = {
|
|
@@ -194,7 +201,6 @@ declare class Http<TParams extends Record<string, any> = any, TCookie extends Re
|
|
|
194
201
|
private response?;
|
|
195
202
|
private validator?;
|
|
196
203
|
constructor(config?: HttpConfig<TParams, TCookie, TSession>);
|
|
197
|
-
onDeploy(data: DeployData, next: Next): Promise<void>;
|
|
198
204
|
onMount(data: MountData, next: Next): Promise<void>;
|
|
199
205
|
onInvoke(data: InvokeData, next: Next): Promise<void>;
|
|
200
206
|
/**
|
package/dist/index.js
CHANGED
|
@@ -6,16 +6,17 @@ var logger = require('@faasjs/logger');
|
|
|
6
6
|
var crypto = require('crypto');
|
|
7
7
|
var zlib = require('zlib');
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
11
|
-
}) : x)(function(x) {
|
|
12
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
13
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
14
|
-
});
|
|
9
|
+
// src/index.ts
|
|
15
10
|
var Session = class {
|
|
11
|
+
content;
|
|
12
|
+
config;
|
|
13
|
+
secret;
|
|
14
|
+
signedSecret;
|
|
15
|
+
cookie;
|
|
16
|
+
changed;
|
|
16
17
|
constructor(cookie, config) {
|
|
17
18
|
this.cookie = cookie;
|
|
18
|
-
if (!
|
|
19
|
+
if (!config?.secret) cookie.logger.warn("Session's secret is missing.");
|
|
19
20
|
this.config = Object.assign(
|
|
20
21
|
{
|
|
21
22
|
key: "key",
|
|
@@ -49,7 +50,7 @@ var Session = class {
|
|
|
49
50
|
try {
|
|
50
51
|
this.content = cookie ? this.decode(cookie) : /* @__PURE__ */ Object.create(null);
|
|
51
52
|
} catch (error) {
|
|
52
|
-
logger
|
|
53
|
+
logger?.error(error);
|
|
53
54
|
this.content = /* @__PURE__ */ Object.create(null);
|
|
54
55
|
}
|
|
55
56
|
this.changed = false;
|
|
@@ -108,6 +109,11 @@ var Session = class {
|
|
|
108
109
|
}
|
|
109
110
|
};
|
|
110
111
|
var Cookie = class {
|
|
112
|
+
session;
|
|
113
|
+
content;
|
|
114
|
+
config;
|
|
115
|
+
logger;
|
|
116
|
+
setCookie;
|
|
111
117
|
constructor(config, logger) {
|
|
112
118
|
this.logger = logger;
|
|
113
119
|
this.config = deep_merge.deepMerge(
|
|
@@ -172,6 +178,11 @@ var Cookie = class {
|
|
|
172
178
|
|
|
173
179
|
// src/validator.ts
|
|
174
180
|
var Validator = class {
|
|
181
|
+
before;
|
|
182
|
+
paramsConfig;
|
|
183
|
+
cookieConfig;
|
|
184
|
+
sessionConfig;
|
|
185
|
+
request;
|
|
175
186
|
constructor(config) {
|
|
176
187
|
this.paramsConfig = config.params;
|
|
177
188
|
this.cookieConfig = config.cookie;
|
|
@@ -352,6 +363,8 @@ var ContentType = {
|
|
|
352
363
|
jsonp: "application/javascript"
|
|
353
364
|
};
|
|
354
365
|
var HttpError = class _HttpError extends Error {
|
|
366
|
+
statusCode;
|
|
367
|
+
message;
|
|
355
368
|
constructor({
|
|
356
369
|
statusCode,
|
|
357
370
|
message
|
|
@@ -378,42 +391,27 @@ function deepClone(obj) {
|
|
|
378
391
|
return clone;
|
|
379
392
|
}
|
|
380
393
|
var Http = class {
|
|
394
|
+
type = Name;
|
|
395
|
+
name = Name;
|
|
396
|
+
headers;
|
|
397
|
+
body;
|
|
398
|
+
params;
|
|
399
|
+
cookie;
|
|
400
|
+
session;
|
|
401
|
+
config;
|
|
402
|
+
validatorOptions;
|
|
403
|
+
response;
|
|
404
|
+
validator;
|
|
381
405
|
constructor(config) {
|
|
382
|
-
this.
|
|
383
|
-
this.
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
}
|
|
388
|
-
async onDeploy(data, next) {
|
|
389
|
-
var _a;
|
|
390
|
-
data.dependencies["@faasjs/http"] = "*";
|
|
391
|
-
await next();
|
|
392
|
-
const logger$1 = new logger.Logger(this.name);
|
|
393
|
-
logger$1.debug("Generate api gateway's config");
|
|
394
|
-
logger$1.debug("%j", data);
|
|
395
|
-
const config = data.config.plugins ? deep_merge.deepMerge(data.config.plugins[this.name || this.type], {
|
|
396
|
-
config: this.config
|
|
397
|
-
}) : { config: this.config };
|
|
398
|
-
if (!config.config.path) {
|
|
399
|
-
config.config.path = `/${(_a = data.name) == null ? void 0 : _a.replace(/_/g, "/").replace(/\/index$/, "")}`;
|
|
400
|
-
if (config.config.path === "/index") config.config.path = "/";
|
|
401
|
-
if (config.config.ignorePathPrefix) {
|
|
402
|
-
config.config.path = config.config.path.replace(
|
|
403
|
-
new RegExp(`^${config.config.ignorePathPrefix}`),
|
|
404
|
-
""
|
|
405
|
-
);
|
|
406
|
-
if (config.config.path === "") config.config.path = "/";
|
|
407
|
-
}
|
|
406
|
+
this.name = config?.name || this.type;
|
|
407
|
+
this.config = config?.config || /* @__PURE__ */ Object.create(null);
|
|
408
|
+
if (config?.validator) {
|
|
409
|
+
console.warn("Validator will deprecated in the v3.");
|
|
410
|
+
this.validatorOptions = config.validator;
|
|
408
411
|
}
|
|
409
|
-
logger$1.debug("Api gateway's config: %j", config);
|
|
410
|
-
const Provider = __require(config.provider.type).Provider;
|
|
411
|
-
const provider = new Provider(config.provider.config);
|
|
412
|
-
await provider.deploy(this.type, data, config);
|
|
413
412
|
}
|
|
414
413
|
async onMount(data, next) {
|
|
415
|
-
|
|
416
|
-
const logger$1 = new logger.Logger(((_a = data.logger) == null ? void 0 : _a.label) || this.name);
|
|
414
|
+
const logger$1 = new logger.Logger(data.logger?.label || this.name);
|
|
417
415
|
if (!logger$1.label.endsWith(this.name))
|
|
418
416
|
logger$1.label = `${logger$1.label}] [${this.name}`;
|
|
419
417
|
logger$1.debug("[onMount] merge config");
|
|
@@ -433,7 +431,7 @@ var Http = class {
|
|
|
433
431
|
} else this.config[key] = value;
|
|
434
432
|
}
|
|
435
433
|
if (!data.config) throw Error(`[${this.name}] Config not found.`);
|
|
436
|
-
if (
|
|
434
|
+
if (data.config.plugins?.[this.name || this.type])
|
|
437
435
|
this.config = deep_merge.deepMerge(
|
|
438
436
|
this.config,
|
|
439
437
|
data.config.plugins[this.name || this.type].config
|
|
@@ -450,16 +448,15 @@ var Http = class {
|
|
|
450
448
|
await next();
|
|
451
449
|
}
|
|
452
450
|
async onInvoke(data, next) {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
if (!((_b = logger$1.label) == null ? void 0 : _b.endsWith(this.name)))
|
|
451
|
+
const logger$1 = new logger.Logger(data.logger?.label || this.name);
|
|
452
|
+
if (!logger$1.label?.endsWith(this.name))
|
|
456
453
|
logger$1.label = `${logger$1.label}] [${this.name}`;
|
|
457
454
|
this.headers = data.event.headers || /* @__PURE__ */ Object.create(null);
|
|
458
455
|
this.body = data.event.body;
|
|
459
456
|
this.params = data.event.queryString || /* @__PURE__ */ Object.create(null);
|
|
460
457
|
this.response = { headers: /* @__PURE__ */ Object.create(null) };
|
|
461
458
|
if (data.event.body) {
|
|
462
|
-
if (
|
|
459
|
+
if (this.headers["content-type"]?.includes("application/json") && typeof data.event.body === "string" && data.event.body.length > 1) {
|
|
463
460
|
logger$1.debug("[onInvoke] Parse params from json body");
|
|
464
461
|
try {
|
|
465
462
|
this.params = Object.keys(this.params).length ? Object.assign(this.params, JSON.parse(data.event.body)) : JSON.parse(data.event.body);
|
|
@@ -506,7 +503,7 @@ var Http = class {
|
|
|
506
503
|
}
|
|
507
504
|
this.session.update();
|
|
508
505
|
if (data.response)
|
|
509
|
-
if (data.response instanceof Error ||
|
|
506
|
+
if (data.response instanceof Error || data.response.constructor?.name === "Error") {
|
|
510
507
|
logger$1.error(data.response);
|
|
511
508
|
this.response.body = JSON.stringify({
|
|
512
509
|
error: { message: data.response.message }
|
package/dist/index.mjs
CHANGED
|
@@ -4,16 +4,17 @@ import { Logger } from '@faasjs/logger';
|
|
|
4
4
|
import { randomBytes, pbkdf2Sync, createCipheriv, createHmac, createDecipheriv } from 'node:crypto';
|
|
5
5
|
import { brotliCompressSync, gzipSync, deflateSync } from 'node:zlib';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
-
}) : x)(function(x) {
|
|
10
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
-
});
|
|
7
|
+
// src/index.ts
|
|
13
8
|
var Session = class {
|
|
9
|
+
content;
|
|
10
|
+
config;
|
|
11
|
+
secret;
|
|
12
|
+
signedSecret;
|
|
13
|
+
cookie;
|
|
14
|
+
changed;
|
|
14
15
|
constructor(cookie, config) {
|
|
15
16
|
this.cookie = cookie;
|
|
16
|
-
if (!
|
|
17
|
+
if (!config?.secret) cookie.logger.warn("Session's secret is missing.");
|
|
17
18
|
this.config = Object.assign(
|
|
18
19
|
{
|
|
19
20
|
key: "key",
|
|
@@ -47,7 +48,7 @@ var Session = class {
|
|
|
47
48
|
try {
|
|
48
49
|
this.content = cookie ? this.decode(cookie) : /* @__PURE__ */ Object.create(null);
|
|
49
50
|
} catch (error) {
|
|
50
|
-
logger
|
|
51
|
+
logger?.error(error);
|
|
51
52
|
this.content = /* @__PURE__ */ Object.create(null);
|
|
52
53
|
}
|
|
53
54
|
this.changed = false;
|
|
@@ -106,6 +107,11 @@ var Session = class {
|
|
|
106
107
|
}
|
|
107
108
|
};
|
|
108
109
|
var Cookie = class {
|
|
110
|
+
session;
|
|
111
|
+
content;
|
|
112
|
+
config;
|
|
113
|
+
logger;
|
|
114
|
+
setCookie;
|
|
109
115
|
constructor(config, logger) {
|
|
110
116
|
this.logger = logger;
|
|
111
117
|
this.config = deepMerge(
|
|
@@ -170,6 +176,11 @@ var Cookie = class {
|
|
|
170
176
|
|
|
171
177
|
// src/validator.ts
|
|
172
178
|
var Validator = class {
|
|
179
|
+
before;
|
|
180
|
+
paramsConfig;
|
|
181
|
+
cookieConfig;
|
|
182
|
+
sessionConfig;
|
|
183
|
+
request;
|
|
173
184
|
constructor(config) {
|
|
174
185
|
this.paramsConfig = config.params;
|
|
175
186
|
this.cookieConfig = config.cookie;
|
|
@@ -350,6 +361,8 @@ var ContentType = {
|
|
|
350
361
|
jsonp: "application/javascript"
|
|
351
362
|
};
|
|
352
363
|
var HttpError = class _HttpError extends Error {
|
|
364
|
+
statusCode;
|
|
365
|
+
message;
|
|
353
366
|
constructor({
|
|
354
367
|
statusCode,
|
|
355
368
|
message
|
|
@@ -376,42 +389,27 @@ function deepClone(obj) {
|
|
|
376
389
|
return clone;
|
|
377
390
|
}
|
|
378
391
|
var Http = class {
|
|
392
|
+
type = Name;
|
|
393
|
+
name = Name;
|
|
394
|
+
headers;
|
|
395
|
+
body;
|
|
396
|
+
params;
|
|
397
|
+
cookie;
|
|
398
|
+
session;
|
|
399
|
+
config;
|
|
400
|
+
validatorOptions;
|
|
401
|
+
response;
|
|
402
|
+
validator;
|
|
379
403
|
constructor(config) {
|
|
380
|
-
this.
|
|
381
|
-
this.
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
async onDeploy(data, next) {
|
|
387
|
-
var _a;
|
|
388
|
-
data.dependencies["@faasjs/http"] = "*";
|
|
389
|
-
await next();
|
|
390
|
-
const logger = new Logger(this.name);
|
|
391
|
-
logger.debug("Generate api gateway's config");
|
|
392
|
-
logger.debug("%j", data);
|
|
393
|
-
const config = data.config.plugins ? deepMerge(data.config.plugins[this.name || this.type], {
|
|
394
|
-
config: this.config
|
|
395
|
-
}) : { config: this.config };
|
|
396
|
-
if (!config.config.path) {
|
|
397
|
-
config.config.path = `/${(_a = data.name) == null ? void 0 : _a.replace(/_/g, "/").replace(/\/index$/, "")}`;
|
|
398
|
-
if (config.config.path === "/index") config.config.path = "/";
|
|
399
|
-
if (config.config.ignorePathPrefix) {
|
|
400
|
-
config.config.path = config.config.path.replace(
|
|
401
|
-
new RegExp(`^${config.config.ignorePathPrefix}`),
|
|
402
|
-
""
|
|
403
|
-
);
|
|
404
|
-
if (config.config.path === "") config.config.path = "/";
|
|
405
|
-
}
|
|
404
|
+
this.name = config?.name || this.type;
|
|
405
|
+
this.config = config?.config || /* @__PURE__ */ Object.create(null);
|
|
406
|
+
if (config?.validator) {
|
|
407
|
+
console.warn("Validator will deprecated in the v3.");
|
|
408
|
+
this.validatorOptions = config.validator;
|
|
406
409
|
}
|
|
407
|
-
logger.debug("Api gateway's config: %j", config);
|
|
408
|
-
const Provider = __require(config.provider.type).Provider;
|
|
409
|
-
const provider = new Provider(config.provider.config);
|
|
410
|
-
await provider.deploy(this.type, data, config);
|
|
411
410
|
}
|
|
412
411
|
async onMount(data, next) {
|
|
413
|
-
|
|
414
|
-
const logger = new Logger(((_a = data.logger) == null ? void 0 : _a.label) || this.name);
|
|
412
|
+
const logger = new Logger(data.logger?.label || this.name);
|
|
415
413
|
if (!logger.label.endsWith(this.name))
|
|
416
414
|
logger.label = `${logger.label}] [${this.name}`;
|
|
417
415
|
logger.debug("[onMount] merge config");
|
|
@@ -431,7 +429,7 @@ var Http = class {
|
|
|
431
429
|
} else this.config[key] = value;
|
|
432
430
|
}
|
|
433
431
|
if (!data.config) throw Error(`[${this.name}] Config not found.`);
|
|
434
|
-
if (
|
|
432
|
+
if (data.config.plugins?.[this.name || this.type])
|
|
435
433
|
this.config = deepMerge(
|
|
436
434
|
this.config,
|
|
437
435
|
data.config.plugins[this.name || this.type].config
|
|
@@ -448,16 +446,15 @@ var Http = class {
|
|
|
448
446
|
await next();
|
|
449
447
|
}
|
|
450
448
|
async onInvoke(data, next) {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
if (!((_b = logger.label) == null ? void 0 : _b.endsWith(this.name)))
|
|
449
|
+
const logger = new Logger(data.logger?.label || this.name);
|
|
450
|
+
if (!logger.label?.endsWith(this.name))
|
|
454
451
|
logger.label = `${logger.label}] [${this.name}`;
|
|
455
452
|
this.headers = data.event.headers || /* @__PURE__ */ Object.create(null);
|
|
456
453
|
this.body = data.event.body;
|
|
457
454
|
this.params = data.event.queryString || /* @__PURE__ */ Object.create(null);
|
|
458
455
|
this.response = { headers: /* @__PURE__ */ Object.create(null) };
|
|
459
456
|
if (data.event.body) {
|
|
460
|
-
if (
|
|
457
|
+
if (this.headers["content-type"]?.includes("application/json") && typeof data.event.body === "string" && data.event.body.length > 1) {
|
|
461
458
|
logger.debug("[onInvoke] Parse params from json body");
|
|
462
459
|
try {
|
|
463
460
|
this.params = Object.keys(this.params).length ? Object.assign(this.params, JSON.parse(data.event.body)) : JSON.parse(data.event.body);
|
|
@@ -504,7 +501,7 @@ var Http = class {
|
|
|
504
501
|
}
|
|
505
502
|
this.session.update();
|
|
506
503
|
if (data.response)
|
|
507
|
-
if (data.response instanceof Error ||
|
|
504
|
+
if (data.response instanceof Error || data.response.constructor?.name === "Error") {
|
|
508
505
|
logger.error(data.response);
|
|
509
506
|
this.response.body = JSON.stringify({
|
|
510
507
|
error: { message: data.response.message }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/http",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-canary.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -34,15 +34,15 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@faasjs/func": "
|
|
38
|
-
"@faasjs/logger": "
|
|
37
|
+
"@faasjs/func": "3.0.0-canary.1",
|
|
38
|
+
"@faasjs/logger": "3.0.0-canary.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@faasjs/func": "
|
|
42
|
-
"@faasjs/logger": "
|
|
41
|
+
"@faasjs/func": "3.0.0-canary.1",
|
|
42
|
+
"@faasjs/logger": "3.0.0-canary.1"
|
|
43
43
|
},
|
|
44
44
|
"engines": {
|
|
45
|
-
"
|
|
46
|
-
"
|
|
45
|
+
"node": ">=22.0.0",
|
|
46
|
+
"npm": ">=10.0.0"
|
|
47
47
|
}
|
|
48
48
|
}
|