@faasjs/http 3.3.0 → 3.5.0
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 -0
- package/dist/index.d.mts +30 -16
- package/dist/index.d.ts +30 -16
- package/dist/index.js +11 -0
- package/dist/index.mjs +12 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ npm install @faasjs/http
|
|
|
14
14
|
## Functions
|
|
15
15
|
|
|
16
16
|
- [useHttp](functions/useHttp.md)
|
|
17
|
+
- [useHttpFunc](functions/useHttpFunc.md)
|
|
17
18
|
|
|
18
19
|
## Classes
|
|
19
20
|
|
|
@@ -27,6 +28,7 @@ npm install @faasjs/http
|
|
|
27
28
|
|
|
28
29
|
- [CookieOptions](type-aliases/CookieOptions.md)
|
|
29
30
|
- [HttpConfig](type-aliases/HttpConfig.md)
|
|
31
|
+
- [HttpFuncHandler](type-aliases/HttpFuncHandler.md)
|
|
30
32
|
- [Response](type-aliases/Response.md)
|
|
31
33
|
- [SessionOptions](type-aliases/SessionOptions.md)
|
|
32
34
|
- [ValidatorConfig](type-aliases/ValidatorConfig.md)
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as _faasjs_func from '@faasjs/func';
|
|
1
2
|
import { Plugin, MountData, Next, InvokeData, UseifyPlugin } from '@faasjs/func';
|
|
2
3
|
import { Logger } from '@faasjs/logger';
|
|
3
4
|
|
|
@@ -135,21 +136,6 @@ declare class Validator<TParams extends Record<string, any> = any, TCookie exten
|
|
|
135
136
|
}, baseKey: string, config: ValidatorOptions, logger: Logger): void;
|
|
136
137
|
}
|
|
137
138
|
|
|
138
|
-
/**
|
|
139
|
-
* FaasJS's http plugin.
|
|
140
|
-
*
|
|
141
|
-
* [](https://github.com/faasjs/faasjs/blob/main/packages/http/LICENSE)
|
|
142
|
-
* [](https://www.npmjs.com/package/@faasjs/http)
|
|
143
|
-
*
|
|
144
|
-
* ## Install
|
|
145
|
-
*
|
|
146
|
-
* ```sh
|
|
147
|
-
* npm install @faasjs/http
|
|
148
|
-
* ```
|
|
149
|
-
*
|
|
150
|
-
* @packageDocumentation
|
|
151
|
-
*/
|
|
152
|
-
|
|
153
139
|
declare const ContentType: {
|
|
154
140
|
[key: string]: string;
|
|
155
141
|
};
|
|
@@ -227,5 +213,33 @@ declare class Http<TParams extends Record<string, any> = any, TCookie extends Re
|
|
|
227
213
|
setBody(body: string): Http<TParams, TCookie, TSession>;
|
|
228
214
|
}
|
|
229
215
|
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>>;
|
|
216
|
+
type HttpFuncHandler<TParams extends Record<string, any> = Record<string, any>, TCookie extends Record<string, string> = Record<string, string>, TSession extends Record<string, any> = Record<string, any>, TResult = any> = (data: InvokeData<{
|
|
217
|
+
[key: string]: any;
|
|
218
|
+
params?: TParams;
|
|
219
|
+
}> & {
|
|
220
|
+
params?: TParams;
|
|
221
|
+
cookie?: Cookie<TCookie, TSession>;
|
|
222
|
+
session?: Session<TSession, TCookie>;
|
|
223
|
+
}) => Promise<TResult>;
|
|
224
|
+
/**
|
|
225
|
+
* A hook to create an HTTP function with specified handler and configuration.
|
|
226
|
+
*
|
|
227
|
+
* @template TParams - The type of the parameters object.
|
|
228
|
+
* @template TCookie - The type of the cookies object.
|
|
229
|
+
* @template TSession - The type of the session object.
|
|
230
|
+
* @template TResult - The type of the result.
|
|
231
|
+
*
|
|
232
|
+
* @param {() => HttpFuncHandler<TParams, TCookie, TSession, TResult>} handler - The function handler to be used.
|
|
233
|
+
* @param {Object} [config] - Optional configuration object.
|
|
234
|
+
* @param {HttpConfig} [config.http] - Optional HTTP configuration.
|
|
235
|
+
*
|
|
236
|
+
* @returns {Function} The created HTTP function.
|
|
237
|
+
*/
|
|
238
|
+
declare function useHttpFunc<TParams extends Record<string, any> = Record<string, any>, TCookie extends Record<string, string> = Record<string, string>, TSession extends Record<string, any> = Record<string, any>, TResult = any>(handler: () => HttpFuncHandler<TParams, TCookie, TSession, TResult>, config?: {
|
|
239
|
+
http?: HttpConfig;
|
|
240
|
+
}): _faasjs_func.Func<{
|
|
241
|
+
[key: string]: any;
|
|
242
|
+
params?: TParams;
|
|
243
|
+
}, any, TResult>;
|
|
230
244
|
|
|
231
|
-
export { ContentType, Cookie, type CookieOptions, Http, type HttpConfig, HttpError, type Response, Session, type SessionOptions, Validator, type ValidatorConfig, type ValidatorOptions, type ValidatorRuleOptions, useHttp };
|
|
245
|
+
export { ContentType, Cookie, type CookieOptions, Http, type HttpConfig, HttpError, type HttpFuncHandler, type Response, Session, type SessionOptions, Validator, type ValidatorConfig, type ValidatorOptions, type ValidatorRuleOptions, useHttp, useHttpFunc };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as _faasjs_func from '@faasjs/func';
|
|
1
2
|
import { Plugin, MountData, Next, InvokeData, UseifyPlugin } from '@faasjs/func';
|
|
2
3
|
import { Logger } from '@faasjs/logger';
|
|
3
4
|
|
|
@@ -135,21 +136,6 @@ declare class Validator<TParams extends Record<string, any> = any, TCookie exten
|
|
|
135
136
|
}, baseKey: string, config: ValidatorOptions, logger: Logger): void;
|
|
136
137
|
}
|
|
137
138
|
|
|
138
|
-
/**
|
|
139
|
-
* FaasJS's http plugin.
|
|
140
|
-
*
|
|
141
|
-
* [](https://github.com/faasjs/faasjs/blob/main/packages/http/LICENSE)
|
|
142
|
-
* [](https://www.npmjs.com/package/@faasjs/http)
|
|
143
|
-
*
|
|
144
|
-
* ## Install
|
|
145
|
-
*
|
|
146
|
-
* ```sh
|
|
147
|
-
* npm install @faasjs/http
|
|
148
|
-
* ```
|
|
149
|
-
*
|
|
150
|
-
* @packageDocumentation
|
|
151
|
-
*/
|
|
152
|
-
|
|
153
139
|
declare const ContentType: {
|
|
154
140
|
[key: string]: string;
|
|
155
141
|
};
|
|
@@ -227,5 +213,33 @@ declare class Http<TParams extends Record<string, any> = any, TCookie extends Re
|
|
|
227
213
|
setBody(body: string): Http<TParams, TCookie, TSession>;
|
|
228
214
|
}
|
|
229
215
|
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>>;
|
|
216
|
+
type HttpFuncHandler<TParams extends Record<string, any> = Record<string, any>, TCookie extends Record<string, string> = Record<string, string>, TSession extends Record<string, any> = Record<string, any>, TResult = any> = (data: InvokeData<{
|
|
217
|
+
[key: string]: any;
|
|
218
|
+
params?: TParams;
|
|
219
|
+
}> & {
|
|
220
|
+
params?: TParams;
|
|
221
|
+
cookie?: Cookie<TCookie, TSession>;
|
|
222
|
+
session?: Session<TSession, TCookie>;
|
|
223
|
+
}) => Promise<TResult>;
|
|
224
|
+
/**
|
|
225
|
+
* A hook to create an HTTP function with specified handler and configuration.
|
|
226
|
+
*
|
|
227
|
+
* @template TParams - The type of the parameters object.
|
|
228
|
+
* @template TCookie - The type of the cookies object.
|
|
229
|
+
* @template TSession - The type of the session object.
|
|
230
|
+
* @template TResult - The type of the result.
|
|
231
|
+
*
|
|
232
|
+
* @param {() => HttpFuncHandler<TParams, TCookie, TSession, TResult>} handler - The function handler to be used.
|
|
233
|
+
* @param {Object} [config] - Optional configuration object.
|
|
234
|
+
* @param {HttpConfig} [config.http] - Optional HTTP configuration.
|
|
235
|
+
*
|
|
236
|
+
* @returns {Function} The created HTTP function.
|
|
237
|
+
*/
|
|
238
|
+
declare function useHttpFunc<TParams extends Record<string, any> = Record<string, any>, TCookie extends Record<string, string> = Record<string, string>, TSession extends Record<string, any> = Record<string, any>, TResult = any>(handler: () => HttpFuncHandler<TParams, TCookie, TSession, TResult>, config?: {
|
|
239
|
+
http?: HttpConfig;
|
|
240
|
+
}): _faasjs_func.Func<{
|
|
241
|
+
[key: string]: any;
|
|
242
|
+
params?: TParams;
|
|
243
|
+
}, any, TResult>;
|
|
230
244
|
|
|
231
|
-
export { ContentType, Cookie, type CookieOptions, Http, type HttpConfig, HttpError, type Response, Session, type SessionOptions, Validator, type ValidatorConfig, type ValidatorOptions, type ValidatorRuleOptions, useHttp };
|
|
245
|
+
export { ContentType, Cookie, type CookieOptions, Http, type HttpConfig, HttpError, type HttpFuncHandler, type Response, Session, type SessionOptions, Validator, type ValidatorConfig, type ValidatorOptions, type ValidatorRuleOptions, useHttp, useHttpFunc };
|
package/dist/index.js
CHANGED
|
@@ -468,6 +468,7 @@ var Http = class {
|
|
|
468
468
|
data.event.params = deepClone(this.params);
|
|
469
469
|
data.logger.debug("Params: %j", this.params);
|
|
470
470
|
}
|
|
471
|
+
data.params = data.event.params;
|
|
471
472
|
this.cookie.invoke(this.headers.cookie, data.logger);
|
|
472
473
|
if (this.headers.cookie) {
|
|
473
474
|
data.logger.debug("Cookie: %j", this.cookie.content);
|
|
@@ -477,6 +478,8 @@ var Http = class {
|
|
|
477
478
|
this.session.content
|
|
478
479
|
);
|
|
479
480
|
}
|
|
481
|
+
data.cookie = this.cookie;
|
|
482
|
+
data.session = this.session;
|
|
480
483
|
try {
|
|
481
484
|
if (this.validator) {
|
|
482
485
|
data.logger.debug("Valid request");
|
|
@@ -588,6 +591,13 @@ var Http = class {
|
|
|
588
591
|
function useHttp(config) {
|
|
589
592
|
return func.usePlugin(new Http(config));
|
|
590
593
|
}
|
|
594
|
+
function useHttpFunc(handler, config) {
|
|
595
|
+
const func$1 = func.useFunc(() => {
|
|
596
|
+
useHttp(config?.http);
|
|
597
|
+
return handler();
|
|
598
|
+
});
|
|
599
|
+
return func$1;
|
|
600
|
+
}
|
|
591
601
|
|
|
592
602
|
exports.ContentType = ContentType;
|
|
593
603
|
exports.Cookie = Cookie;
|
|
@@ -596,3 +606,4 @@ exports.HttpError = HttpError;
|
|
|
596
606
|
exports.Session = Session;
|
|
597
607
|
exports.Validator = Validator;
|
|
598
608
|
exports.useHttp = useHttp;
|
|
609
|
+
exports.useHttpFunc = useHttpFunc;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { usePlugin } from '@faasjs/func';
|
|
1
|
+
import { usePlugin, useFunc } from '@faasjs/func';
|
|
2
2
|
import { deepMerge } from '@faasjs/deep_merge';
|
|
3
3
|
import { randomBytes, pbkdf2Sync, createCipheriv, createHmac, createDecipheriv } from 'node:crypto';
|
|
4
4
|
import { brotliCompressSync, gzipSync, deflateSync } from 'node:zlib';
|
|
@@ -466,6 +466,7 @@ var Http = class {
|
|
|
466
466
|
data.event.params = deepClone(this.params);
|
|
467
467
|
data.logger.debug("Params: %j", this.params);
|
|
468
468
|
}
|
|
469
|
+
data.params = data.event.params;
|
|
469
470
|
this.cookie.invoke(this.headers.cookie, data.logger);
|
|
470
471
|
if (this.headers.cookie) {
|
|
471
472
|
data.logger.debug("Cookie: %j", this.cookie.content);
|
|
@@ -475,6 +476,8 @@ var Http = class {
|
|
|
475
476
|
this.session.content
|
|
476
477
|
);
|
|
477
478
|
}
|
|
479
|
+
data.cookie = this.cookie;
|
|
480
|
+
data.session = this.session;
|
|
478
481
|
try {
|
|
479
482
|
if (this.validator) {
|
|
480
483
|
data.logger.debug("Valid request");
|
|
@@ -586,5 +589,12 @@ var Http = class {
|
|
|
586
589
|
function useHttp(config) {
|
|
587
590
|
return usePlugin(new Http(config));
|
|
588
591
|
}
|
|
592
|
+
function useHttpFunc(handler, config) {
|
|
593
|
+
const func = useFunc(() => {
|
|
594
|
+
useHttp(config?.http);
|
|
595
|
+
return handler();
|
|
596
|
+
});
|
|
597
|
+
return func;
|
|
598
|
+
}
|
|
589
599
|
|
|
590
|
-
export { ContentType, Cookie, Http, HttpError, Session, Validator, useHttp };
|
|
600
|
+
export { ContentType, Cookie, Http, HttpError, Session, Validator, useHttp, useHttpFunc };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/http",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@faasjs/func": "3.
|
|
38
|
-
"@faasjs/logger": "3.
|
|
37
|
+
"@faasjs/func": "3.5.0",
|
|
38
|
+
"@faasjs/logger": "3.5.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@faasjs/func": "3.
|
|
42
|
-
"@faasjs/logger": "3.
|
|
41
|
+
"@faasjs/func": "3.5.0",
|
|
42
|
+
"@faasjs/logger": "3.5.0"
|
|
43
43
|
},
|
|
44
44
|
"engines": {
|
|
45
45
|
"node": ">=22.0.0",
|