@flowerforce/flowerbase 1.8.4-beta.5 → 1.8.4-beta.7
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/auth/providers/custom-function/controller.d.ts.map +1 -1
- package/dist/auth/providers/custom-function/controller.js +2 -1
- package/dist/cli/call-function.js +2 -1
- package/dist/features/functions/controller.d.ts.map +1 -1
- package/dist/features/functions/controller.js +2 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/utils/context/helpers.d.ts +11 -8
- package/dist/utils/context/helpers.d.ts.map +1 -1
- package/dist/utils/context/helpers.js +19 -2
- package/dist/utils/context/interface.d.ts +1 -1
- package/dist/utils/context/interface.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/auth/providers/custom-function/controller.ts +2 -1
- package/src/cli/call-function.ts +2 -1
- package/src/features/functions/controller.ts +2 -1
- package/src/index.ts +19 -2
- package/src/utils/context/helpers.ts +18 -2
- package/src/utils/context/interface.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../../src/auth/providers/custom-function/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAUzC;;;;GAIG;AACH,wBAAsB,wBAAwB,CAAC,GAAG,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../../src/auth/providers/custom-function/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAUzC;;;;GAIG;AACH,wBAAsB,wBAAwB,CAAC,GAAG,EAAE,eAAe,iBA2IlE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/features/functions/controller.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAKvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AA0IhD,eAAO,MAAM,iCAAiC,GAAI,OAAO,OAAO,KAAG,OA0BlE,CAAA;AAID,eAAO,MAAM,6BAA6B,GAAI,OAAO,OAAO,KAAG,OAgD9D,CAAA;AAqHD,eAAO,MAAM,oCAAoC,GAAI,QAAQ,QAAQ,YAClC,CAAA;AAEnC;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/features/functions/controller.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAKvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AA0IhD,eAAO,MAAM,iCAAiC,GAAI,OAAO,OAAO,KAAG,OA0BlE,CAAA;AAID,eAAO,MAAM,6BAA6B,GAAI,OAAO,OAAO,KAAG,OAgD9D,CAAA;AAqHD,eAAO,MAAM,oCAAoC,GAAI,QAAQ,QAAQ,YAClC,CAAA;AAEnC;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,kBAuSjC,CAAA"}
|
|
@@ -356,7 +356,8 @@ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0
|
|
|
356
356
|
currentFunction,
|
|
357
357
|
functionName: String(method),
|
|
358
358
|
functionsList,
|
|
359
|
-
services: services_1.services
|
|
359
|
+
services: services_1.services,
|
|
360
|
+
request: req
|
|
360
361
|
});
|
|
361
362
|
const normalizedResult = yield normalizeFunctionResult(result);
|
|
362
363
|
if (isReturnedError(normalizedResult)) {
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,16 @@ export type CorsConfig = {
|
|
|
6
6
|
origin: string;
|
|
7
7
|
methods: ALLOWED_METHODS[];
|
|
8
8
|
};
|
|
9
|
+
export type FastifyTimeoutConfig = {
|
|
10
|
+
/** Milliseconds to wait for a new connection (default: 0 = disabled) */
|
|
11
|
+
connectionTimeout?: number;
|
|
12
|
+
/** Milliseconds to keep idle keep-alive connections open (default: 72000) */
|
|
13
|
+
keepAliveTimeout?: number;
|
|
14
|
+
/** Milliseconds to wait for an incoming request body (default: 0 = disabled) */
|
|
15
|
+
requestTimeout?: number;
|
|
16
|
+
/** Milliseconds to wait for a plugin to load (default: 10000) */
|
|
17
|
+
pluginTimeout?: number;
|
|
18
|
+
};
|
|
9
19
|
export type InitializeConfig = {
|
|
10
20
|
projectId: string;
|
|
11
21
|
mongodbUrl?: string;
|
|
@@ -15,6 +25,7 @@ export type InitializeConfig = {
|
|
|
15
25
|
corsConfig?: CorsConfig;
|
|
16
26
|
basePath?: string;
|
|
17
27
|
mongodbEncryptionConfig?: MongoDbEncryptionConfig;
|
|
28
|
+
timeoutConfig?: FastifyTimeoutConfig;
|
|
18
29
|
};
|
|
19
30
|
/**
|
|
20
31
|
* > Used to initialize fastify app
|
|
@@ -24,5 +35,5 @@ export type InitializeConfig = {
|
|
|
24
35
|
* @param port -> the serve port number
|
|
25
36
|
* @param mongodbUrl -> the database connection string
|
|
26
37
|
*/
|
|
27
|
-
export declare function initialize({ projectId, host, jwtSecret, port, mongodbUrl, corsConfig, basePath, mongodbEncryptionConfig }: InitializeConfig): Promise<void>;
|
|
38
|
+
export declare function initialize({ projectId, host, jwtSecret, port, mongodbUrl, corsConfig, basePath, mongodbEncryptionConfig, timeoutConfig }: InitializeConfig): Promise<void>;
|
|
28
39
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAA;AAetB,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAC/E,cAAc,SAAS,CAAA;AAGvB,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,MAA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,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,uBAAuB,CAAC,EAAE,uBAAuB,CAAA;IACjD,aAAa,CAAC,EAAE,oBAAoB,CAAA;CACrC,CAAA;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,EAC/B,SAAS,EACT,IAA0B,EAC1B,SAAqC,EACrC,IAA0B,EAC1B,UAAuC,EACvC,UAAwC,EACxC,QAAQ,EACR,uBAAuB,EACvB,aAAa,EACd,EAAE,gBAAgB,iBAiIlB"}
|
package/dist/index.js
CHANGED
|
@@ -74,15 +74,13 @@ __exportStar(require("./model"), exports);
|
|
|
74
74
|
* @param mongodbUrl -> the database connection string
|
|
75
75
|
*/
|
|
76
76
|
function initialize(_a) {
|
|
77
|
-
return __awaiter(this, arguments, void 0, function* ({ projectId, host = constants_1.DEFAULT_CONFIG.HOST, jwtSecret = constants_1.DEFAULT_CONFIG.JWT_SECRET, port = constants_1.DEFAULT_CONFIG.PORT, mongodbUrl = constants_1.DEFAULT_CONFIG.MONGODB_URL, corsConfig = constants_1.DEFAULT_CONFIG.CORS_OPTIONS, basePath, mongodbEncryptionConfig }) {
|
|
77
|
+
return __awaiter(this, arguments, void 0, function* ({ projectId, host = constants_1.DEFAULT_CONFIG.HOST, jwtSecret = constants_1.DEFAULT_CONFIG.JWT_SECRET, port = constants_1.DEFAULT_CONFIG.PORT, mongodbUrl = constants_1.DEFAULT_CONFIG.MONGODB_URL, corsConfig = constants_1.DEFAULT_CONFIG.CORS_OPTIONS, basePath, mongodbEncryptionConfig, timeoutConfig }) {
|
|
78
78
|
var _b, _c;
|
|
79
79
|
if (!jwtSecret || jwtSecret.trim().length === 0) {
|
|
80
80
|
throw new Error('JWT secret missing: set JWT_SECRET or pass jwtSecret to initialize()');
|
|
81
81
|
}
|
|
82
82
|
const resolvedBasePath = (_c = basePath !== null && basePath !== void 0 ? basePath : (_b = require.main) === null || _b === void 0 ? void 0 : _b.path) !== null && _c !== void 0 ? _c : process.cwd();
|
|
83
|
-
const fastify = (0, fastify_1.default)({
|
|
84
|
-
logger: !!constants_1.DEFAULT_CONFIG.ENABLE_LOGGER
|
|
85
|
-
});
|
|
83
|
+
const fastify = (0, fastify_1.default)(Object.assign(Object.assign(Object.assign(Object.assign({ logger: !!constants_1.DEFAULT_CONFIG.ENABLE_LOGGER }, ((timeoutConfig === null || timeoutConfig === void 0 ? void 0 : timeoutConfig.connectionTimeout) !== undefined && { connectionTimeout: timeoutConfig.connectionTimeout })), ((timeoutConfig === null || timeoutConfig === void 0 ? void 0 : timeoutConfig.keepAliveTimeout) !== undefined && { keepAliveTimeout: timeoutConfig.keepAliveTimeout })), ((timeoutConfig === null || timeoutConfig === void 0 ? void 0 : timeoutConfig.requestTimeout) !== undefined && { requestTimeout: timeoutConfig.requestTimeout })), ((timeoutConfig === null || timeoutConfig === void 0 ? void 0 : timeoutConfig.pluginTimeout) !== undefined && { pluginTimeout: timeoutConfig.pluginTimeout })));
|
|
86
84
|
const isTest = process.env.NODE_ENV === 'test' || process.env.JEST_WORKER_ID !== undefined;
|
|
87
85
|
const logInfo = (...args) => {
|
|
88
86
|
if (!isTest) {
|
|
@@ -33,14 +33,17 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
33
33
|
};
|
|
34
34
|
context: {
|
|
35
35
|
request: {
|
|
36
|
-
remoteIPAddress: string
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
remoteIPAddress: string;
|
|
37
|
+
requestHeaders: {
|
|
38
|
+
[k: string]: string[];
|
|
39
|
+
};
|
|
40
|
+
webhookUrl: string | undefined;
|
|
41
|
+
httpMethod: string | undefined;
|
|
42
|
+
rawQueryString: string;
|
|
43
|
+
httpReferrer: string | undefined;
|
|
44
|
+
httpUserAgent: string | undefined;
|
|
45
|
+
service: string;
|
|
46
|
+
action: string;
|
|
44
47
|
};
|
|
45
48
|
user: unknown;
|
|
46
49
|
environment: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/context/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAG1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAEvD,KAAK,QAAQ,GAAG;IACd,MAAM,EAAE,CACN,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACzC,MAAM,CAAA;IACX,MAAM,EAAE,CACN,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,GAAG,MAAM,EACpB,YAAY,CAAC,EAAE,OAAO,EACtB,sBAAsB,CAAC,EAAE,MAAM,EAAE,KAC9B,OAAO,CAAA;CACb,CAAA;AAgFD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAAI,4GAUjC,yBAAyB;;;;;;;;;;;;;uBA4DP,SAAS;yBAGP,SAAS
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/context/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAG1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAEvD,KAAK,QAAQ,GAAG;IACd,MAAM,EAAE,CACN,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,kBAAkB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=> {
|
|
|
109
109
|
* @param functionsList -> the list of all functions
|
|
110
110
|
*/
|
|
111
111
|
const generateContextData = ({ user, services, app, rules, currentFunction, functionName, functionsList, GenerateContextSync, request }) => {
|
|
112
|
-
var _a;
|
|
112
|
+
var _a, _b, _c, _d, _e, _f;
|
|
113
113
|
const BSON = mongodb_1.mongodb.BSON;
|
|
114
114
|
const Binary = BSON === null || BSON === void 0 ? void 0 : BSON.Binary;
|
|
115
115
|
if (Binary && typeof Binary.fromBase64 !== 'function') {
|
|
@@ -160,7 +160,24 @@ const generateContextData = ({ user, services, app, rules, currentFunction, func
|
|
|
160
160
|
}
|
|
161
161
|
},
|
|
162
162
|
context: {
|
|
163
|
-
request:
|
|
163
|
+
request: {
|
|
164
|
+
remoteIPAddress: (_b = request === null || request === void 0 ? void 0 : request.ip) !== null && _b !== void 0 ? _b : '',
|
|
165
|
+
requestHeaders: (request === null || request === void 0 ? void 0 : request.headers)
|
|
166
|
+
? Object.fromEntries(Object.entries(request.headers).map(([key, value]) => [
|
|
167
|
+
key,
|
|
168
|
+
Array.isArray(value) ? value : value !== undefined ? [value] : []
|
|
169
|
+
]))
|
|
170
|
+
: {},
|
|
171
|
+
webhookUrl: (_c = request === null || request === void 0 ? void 0 : request.url) === null || _c === void 0 ? void 0 : _c.split('?')[0],
|
|
172
|
+
httpMethod: request === null || request === void 0 ? void 0 : request.method,
|
|
173
|
+
rawQueryString: ((_d = request === null || request === void 0 ? void 0 : request.url) === null || _d === void 0 ? void 0 : _d.includes('?'))
|
|
174
|
+
? request.url.substring(request.url.indexOf('?'))
|
|
175
|
+
: '',
|
|
176
|
+
httpReferrer: (_e = request === null || request === void 0 ? void 0 : request.headers) === null || _e === void 0 ? void 0 : _e.referer,
|
|
177
|
+
httpUserAgent: (_f = request === null || request === void 0 ? void 0 : request.headers) === null || _f === void 0 ? void 0 : _f['user-agent'],
|
|
178
|
+
service: '',
|
|
179
|
+
action: ''
|
|
180
|
+
},
|
|
164
181
|
user,
|
|
165
182
|
environment: {
|
|
166
183
|
tag: process.env.NODE_ENV
|
|
@@ -17,7 +17,7 @@ export interface GenerateContextParams {
|
|
|
17
17
|
enqueue?: boolean;
|
|
18
18
|
request?: ContextRequest;
|
|
19
19
|
}
|
|
20
|
-
type ContextRequest = Pick<FastifyRequest, "ips" | "host" | "hostname" | "url" | "method" | "ip" | "id">;
|
|
20
|
+
type ContextRequest = Pick<FastifyRequest, "ips" | "host" | "hostname" | "url" | "method" | "ip" | "id" | "headers">;
|
|
21
21
|
export interface GenerateContextDataParams extends Omit<GenerateContextParams, 'args'> {
|
|
22
22
|
GenerateContext: (params: GenerateContextParams) => Promise<unknown>;
|
|
23
23
|
GenerateContextSync: (params: GenerateContextParams) => unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/utils/context/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACzD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAA;AACxE,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAEnD,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,eAAe,CAAA;IACpB,eAAe,EAAE,QAAQ,CAAA;IACzB,aAAa,EAAE,SAAS,CAAA;IACxB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,EAAE,KAAK,CAAA;IACZ,IAAI,EAAE,IAAI,CAAA;IACV,QAAQ,EAAE,QAAQ,CAAA;IAClB,IAAI,EAAE,SAAS,CAAA;IACf,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,OAAO,CAAC,EAAE,OAAO,CAAA;IACj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E,qBAAqB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IACpE,mBAAmB,EAAE,CAAC,MAAM,EAAE,qBAAqB,KAAK,OAAO,CAAA;CAChE"}
|
package/package.json
CHANGED
package/src/cli/call-function.ts
CHANGED
|
@@ -441,7 +441,8 @@ export const functionsController: FunctionController = async (
|
|
|
441
441
|
currentFunction,
|
|
442
442
|
functionName: String(method),
|
|
443
443
|
functionsList,
|
|
444
|
-
services
|
|
444
|
+
services,
|
|
445
|
+
request: req
|
|
445
446
|
})
|
|
446
447
|
const normalizedResult = await normalizeFunctionResult(result)
|
|
447
448
|
if (isReturnedError(normalizedResult)) {
|
package/src/index.ts
CHANGED
|
@@ -24,6 +24,17 @@ export type CorsConfig = {
|
|
|
24
24
|
methods: ALLOWED_METHODS[]
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
export type FastifyTimeoutConfig = {
|
|
28
|
+
/** Milliseconds to wait for a new connection (default: 0 = disabled) */
|
|
29
|
+
connectionTimeout?: number
|
|
30
|
+
/** Milliseconds to keep idle keep-alive connections open (default: 72000) */
|
|
31
|
+
keepAliveTimeout?: number
|
|
32
|
+
/** Milliseconds to wait for an incoming request body (default: 0 = disabled) */
|
|
33
|
+
requestTimeout?: number
|
|
34
|
+
/** Milliseconds to wait for a plugin to load (default: 10000) */
|
|
35
|
+
pluginTimeout?: number
|
|
36
|
+
}
|
|
37
|
+
|
|
27
38
|
export type InitializeConfig = {
|
|
28
39
|
projectId: string
|
|
29
40
|
mongodbUrl?: string
|
|
@@ -33,6 +44,7 @@ export type InitializeConfig = {
|
|
|
33
44
|
corsConfig?: CorsConfig
|
|
34
45
|
basePath?: string
|
|
35
46
|
mongodbEncryptionConfig?: MongoDbEncryptionConfig
|
|
47
|
+
timeoutConfig?: FastifyTimeoutConfig
|
|
36
48
|
}
|
|
37
49
|
|
|
38
50
|
/**
|
|
@@ -51,7 +63,8 @@ export async function initialize({
|
|
|
51
63
|
mongodbUrl = DEFAULT_CONFIG.MONGODB_URL,
|
|
52
64
|
corsConfig = DEFAULT_CONFIG.CORS_OPTIONS,
|
|
53
65
|
basePath,
|
|
54
|
-
mongodbEncryptionConfig
|
|
66
|
+
mongodbEncryptionConfig,
|
|
67
|
+
timeoutConfig
|
|
55
68
|
}: InitializeConfig) {
|
|
56
69
|
if (!jwtSecret || jwtSecret.trim().length === 0) {
|
|
57
70
|
throw new Error('JWT secret missing: set JWT_SECRET or pass jwtSecret to initialize()')
|
|
@@ -59,7 +72,11 @@ export async function initialize({
|
|
|
59
72
|
|
|
60
73
|
const resolvedBasePath = basePath ?? require.main?.path ?? process.cwd()
|
|
61
74
|
const fastify = Fastify({
|
|
62
|
-
logger: !!DEFAULT_CONFIG.ENABLE_LOGGER
|
|
75
|
+
logger: !!DEFAULT_CONFIG.ENABLE_LOGGER,
|
|
76
|
+
...(timeoutConfig?.connectionTimeout !== undefined && { connectionTimeout: timeoutConfig.connectionTimeout }),
|
|
77
|
+
...(timeoutConfig?.keepAliveTimeout !== undefined && { keepAliveTimeout: timeoutConfig.keepAliveTimeout }),
|
|
78
|
+
...(timeoutConfig?.requestTimeout !== undefined && { requestTimeout: timeoutConfig.requestTimeout }),
|
|
79
|
+
...(timeoutConfig?.pluginTimeout !== undefined && { pluginTimeout: timeoutConfig.pluginTimeout })
|
|
63
80
|
})
|
|
64
81
|
|
|
65
82
|
const isTest = process.env.NODE_ENV === 'test' || process.env.JEST_WORKER_ID !== undefined
|
|
@@ -187,8 +187,24 @@ export const generateContextData = ({
|
|
|
187
187
|
},
|
|
188
188
|
context: {
|
|
189
189
|
request: {
|
|
190
|
-
|
|
191
|
-
|
|
190
|
+
remoteIPAddress: request?.ip ?? '',
|
|
191
|
+
requestHeaders: request?.headers
|
|
192
|
+
? Object.fromEntries(
|
|
193
|
+
Object.entries(request.headers).map(([key, value]) => [
|
|
194
|
+
key,
|
|
195
|
+
Array.isArray(value) ? value : value !== undefined ? [value] : []
|
|
196
|
+
])
|
|
197
|
+
)
|
|
198
|
+
: {},
|
|
199
|
+
webhookUrl: request?.url?.split('?')[0],
|
|
200
|
+
httpMethod: request?.method,
|
|
201
|
+
rawQueryString: request?.url?.includes('?')
|
|
202
|
+
? request.url.substring(request.url.indexOf('?'))
|
|
203
|
+
: '',
|
|
204
|
+
httpReferrer: request?.headers?.referer as string | undefined,
|
|
205
|
+
httpUserAgent: request?.headers?.['user-agent'] as string | undefined,
|
|
206
|
+
service: '',
|
|
207
|
+
action: ''
|
|
192
208
|
},
|
|
193
209
|
user,
|
|
194
210
|
environment: {
|
|
@@ -19,7 +19,7 @@ export interface GenerateContextParams {
|
|
|
19
19
|
request?: ContextRequest
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
type ContextRequest = Pick<FastifyRequest, "ips" | "host" | "hostname" | "url" | "method" | "ip" | "id">
|
|
22
|
+
type ContextRequest = Pick<FastifyRequest, "ips" | "host" | "hostname" | "url" | "method" | "ip" | "id" | "headers">
|
|
23
23
|
export interface GenerateContextDataParams extends Omit<GenerateContextParams, 'args'> {
|
|
24
24
|
GenerateContext: (params: GenerateContextParams) => Promise<unknown>
|
|
25
25
|
GenerateContextSync: (params: GenerateContextParams) => unknown
|