@rainbow-o23/n3 1.0.25 → 1.0.27
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 +21 -21
- package/index.cjs +4 -3
- package/index.js +4 -3
- package/lib/http/fetch-step.d.ts +2 -1
- package/package.json +2 -2
- package/src/lib/http/fetch-step.ts +6 -4
package/README.md
CHANGED
|
@@ -583,15 +583,13 @@ step set. Additionally, nested transactions are also supported, which means Tran
|
|
|
583
583
|
|
|
584
584
|
#### Environment Parameters
|
|
585
585
|
|
|
586
|
-
| Name
|
|
587
|
-
|
|
588
|
-
| `endpoints.SYSTEM.ENDPOINT.url`
|
|
589
|
-
| `endpoints.SYSTEM.ENDPOINT.
|
|
590
|
-
| `endpoints.SYSTEM.
|
|
591
|
-
| `endpoints.SYSTEM.
|
|
592
|
-
| `endpoints.SYSTEM.
|
|
593
|
-
| `endpoints.SYSTEM.global.timeout` | string | -1 | Endpoint system global timeout, in seconds, `-1` represents no timeout. |
|
|
594
|
-
| `endpoints.SYSTEM.ENDPOINT.body.used` | boolean | true | Endpoint use request body or not. |
|
|
586
|
+
| Name | Type | Default Value | Comments |
|
|
587
|
+
|-------------------------------------|--------|---------------|-----------------------------------------------------------------------------------------------------------------------------------|
|
|
588
|
+
| `endpoints.SYSTEM.ENDPOINT.url` | string | | Endpoint URL. |
|
|
589
|
+
| `endpoints.SYSTEM.ENDPOINT.headers` | string | | Endpoint request headers, use global headers if this parameter doesn't present.<br>Format follows `name=value[;name=value[...]]`. |
|
|
590
|
+
| `endpoints.SYSTEM.global.headers` | string | | Endpoint system global request headers.<br>Format follows `name=value[;name=value[...]]`. |
|
|
591
|
+
| `endpoints.SYSTEM.ENDPOINT.timeout` | string | | Endpoint request timeout, in seconds, use global timeout if this parameter doesn't present. |
|
|
592
|
+
| `endpoints.SYSTEM.global.timeout` | string | -1 | Endpoint system global timeout, in seconds, `-1` represents no timeout. |
|
|
595
593
|
|
|
596
594
|
`SYSTEM` represents endpoint system, `ENDPOINT` represents endpoint url. For example:
|
|
597
595
|
|
|
@@ -600,20 +598,22 @@ CFG_ENDPOINTS_ORDER_PURCHASE_URL=https://order.com/purchase
|
|
|
600
598
|
CFG_ENDPOINTS_ORDER_PAYMENT_URL=https://order.com/payment
|
|
601
599
|
```
|
|
602
600
|
|
|
601
|
+
>
|
|
603
602
|
#### Constructor Parameters
|
|
604
603
|
|
|
605
|
-
| Name | Type | Default Value | Comments
|
|
606
|
-
|
|
607
|
-
| endpointSystemCode | string | | Endpoint system code.
|
|
608
|
-
| endpointName | string | | Endpoint name.
|
|
609
|
-
| urlGenerate | ScriptFuncOrBody\<HttpGenerateUrl> | | Endpoint url generator, `$endpointUrl`.
|
|
610
|
-
| method | string | | Http method
|
|
611
|
-
| timeout | number | | Endpoint timeout, in seconds.
|
|
612
|
-
| headersGenerate | ScriptFuncOrBody\<HttpGenerateHeaders> | | Endpoint request headers generator.
|
|
613
|
-
|
|
|
614
|
-
|
|
|
615
|
-
|
|
|
604
|
+
| Name | Type | Default Value | Comments |
|
|
605
|
+
|----------------------|------------------------------------------------------------|---------------|----------------------------------------------------------------------------------------------------------------------|
|
|
606
|
+
| endpointSystemCode | string | | Endpoint system code. |
|
|
607
|
+
| endpointName | string | | Endpoint name. |
|
|
608
|
+
| urlGenerate | ScriptFuncOrBody\<HttpGenerateUrl> | | Endpoint url generator, `$endpointUrl`. |
|
|
609
|
+
| method | string | | Http method, default `post`. |
|
|
610
|
+
| timeout | number | | Endpoint timeout, in seconds. |
|
|
611
|
+
| headersGenerate | ScriptFuncOrBody\<HttpGenerateHeaders> | | Endpoint request headers generator. |
|
|
612
|
+
| bodyUsed | boolean | | Send request with body or not, or automatically disregards the body when sending a `get` request when not specified. |
|
|
613
|
+
| bodyGenerate | ScriptFuncOrBody\<HttpGenerateBody> | | Endpoint request body generator. |
|
|
614
|
+
| responseGenerate | ScriptFuncOrBody\<HttpGenerateResponse> | | Endpoint response body generator, `$response`. |
|
|
615
|
+
| responseErrorHandles | {[key: HttpErrorCode]: ScriptFuncOrBody\<HttpHandleError>} | | Endpoint response error handlers. |
|
|
616
616
|
|
|
617
617
|
## Installation
|
|
618
618
|
|
|
619
|
-
Note since nestjs only support commonjs module, which means `node-fetch` 3 series cannot be imported since it is built on esm mode.
|
|
619
|
+
Note since `nestjs` only support commonjs module, which means `node-fetch` 3 series cannot be imported since it is built on esm mode.
|
package/index.cjs
CHANGED
|
@@ -1150,7 +1150,7 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
|
|
|
1150
1150
|
this._endpointName = options.endpointName;
|
|
1151
1151
|
const endpointKey = this.getEndpointKey();
|
|
1152
1152
|
this._endpointUrl = config.getString(`endpoints.${endpointKey}.url`);
|
|
1153
|
-
this._endpointMethod = (
|
|
1153
|
+
this._endpointMethod = (options.method ?? 'POST').trim().toLowerCase();
|
|
1154
1154
|
this._endpointHeaders = this.generateEndpointHeaders(config.getString(`endpoints.${endpointKey}.headers`), this.generateEndpointHeaders(config.getString(`endpoints.${this.getEndpointSystemCode()}.global.headers`)));
|
|
1155
1155
|
this._endpointTimeout = options.timeout
|
|
1156
1156
|
?? config.getNumber(`endpoints.${endpointKey}.timeout`)
|
|
@@ -1174,7 +1174,7 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
|
|
|
1174
1174
|
throw e;
|
|
1175
1175
|
}
|
|
1176
1176
|
});
|
|
1177
|
-
this._bodyUsed =
|
|
1177
|
+
this._bodyUsed = options.bodyUsed;
|
|
1178
1178
|
this._bodyGenerateSnippet = options.bodyGenerate;
|
|
1179
1179
|
this._bodyGenerateFunc = Utils.createSyncFunction(this.getBodyGenerateSnippet(), {
|
|
1180
1180
|
createDefault: () => ($factor, _$request, _$helpers, _$) => {
|
|
@@ -1305,7 +1305,8 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
|
|
|
1305
1305
|
const staticHeaders = this.getEndpointHeaders() ?? {};
|
|
1306
1306
|
const headers = this._headersGenerateFunc(data, request, $helpers, $helpers) ?? {};
|
|
1307
1307
|
let body;
|
|
1308
|
-
|
|
1308
|
+
const bodyUsed = this.isBodyUsed();
|
|
1309
|
+
if (bodyUsed === true || (bodyUsed == null && method !== 'get')) {
|
|
1309
1310
|
body = this._bodyGenerateFunc(data, request, $helpers, $helpers);
|
|
1310
1311
|
}
|
|
1311
1312
|
else {
|
package/index.js
CHANGED
|
@@ -1148,7 +1148,7 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
|
|
|
1148
1148
|
this._endpointName = options.endpointName;
|
|
1149
1149
|
const endpointKey = this.getEndpointKey();
|
|
1150
1150
|
this._endpointUrl = config.getString(`endpoints.${endpointKey}.url`);
|
|
1151
|
-
this._endpointMethod = (
|
|
1151
|
+
this._endpointMethod = (options.method ?? 'POST').trim().toLowerCase();
|
|
1152
1152
|
this._endpointHeaders = this.generateEndpointHeaders(config.getString(`endpoints.${endpointKey}.headers`), this.generateEndpointHeaders(config.getString(`endpoints.${this.getEndpointSystemCode()}.global.headers`)));
|
|
1153
1153
|
this._endpointTimeout = options.timeout
|
|
1154
1154
|
?? config.getNumber(`endpoints.${endpointKey}.timeout`)
|
|
@@ -1172,7 +1172,7 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
|
|
|
1172
1172
|
throw e;
|
|
1173
1173
|
}
|
|
1174
1174
|
});
|
|
1175
|
-
this._bodyUsed =
|
|
1175
|
+
this._bodyUsed = options.bodyUsed;
|
|
1176
1176
|
this._bodyGenerateSnippet = options.bodyGenerate;
|
|
1177
1177
|
this._bodyGenerateFunc = Utils.createSyncFunction(this.getBodyGenerateSnippet(), {
|
|
1178
1178
|
createDefault: () => ($factor, _$request, _$helpers, _$) => {
|
|
@@ -1303,7 +1303,8 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
|
|
|
1303
1303
|
const staticHeaders = this.getEndpointHeaders() ?? {};
|
|
1304
1304
|
const headers = this._headersGenerateFunc(data, request, $helpers, $helpers) ?? {};
|
|
1305
1305
|
let body;
|
|
1306
|
-
|
|
1306
|
+
const bodyUsed = this.isBodyUsed();
|
|
1307
|
+
if (bodyUsed === true || (bodyUsed == null && method !== 'get')) {
|
|
1307
1308
|
body = this._bodyGenerateFunc(data, request, $helpers, $helpers);
|
|
1308
1309
|
}
|
|
1309
1310
|
else {
|
package/lib/http/fetch-step.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export interface FetchPipelineStepOptions<In = PipelineStepPayload, Out = Pipeli
|
|
|
8
8
|
method?: string;
|
|
9
9
|
timeout?: number;
|
|
10
10
|
headersGenerate?: ScriptFuncOrBody<HttpGenerateHeaders<In, InFragment>>;
|
|
11
|
+
bodyUsed?: boolean;
|
|
11
12
|
bodyGenerate?: ScriptFuncOrBody<HttpGenerateBody<In, InFragment>>;
|
|
12
13
|
responseGenerate?: ScriptFuncOrBody<HttpGenerateResponse<In, InFragment>>;
|
|
13
14
|
responseErrorHandles?: {
|
|
@@ -45,7 +46,7 @@ export declare class FetchPipelineStep<In = PipelineStepPayload, Out = PipelineS
|
|
|
45
46
|
protected getUrlGenerateVariableName(): Array<string>;
|
|
46
47
|
getHeadersGenerateSnippet(): ScriptFuncOrBody<HttpGenerateHeaders<In, InFragment>>;
|
|
47
48
|
protected getHeadersGenerateVariableNames(): Array<string>;
|
|
48
|
-
protected isBodyUsed(): boolean;
|
|
49
|
+
protected isBodyUsed(): boolean | undefined;
|
|
49
50
|
getBodyGenerateSnippet(): ScriptFuncOrBody<HttpGenerateBody<In, InFragment>>;
|
|
50
51
|
protected getBodyGenerateVariableNames(): Array<string>;
|
|
51
52
|
getResponseGenerateSnippet(): ScriptFuncOrBody<HttpGenerateResponse<In, InFragment>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rainbow-o23/n3",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"description": "o23 pipelines",
|
|
5
5
|
"main": "index.cjs",
|
|
6
6
|
"module": "index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"url": "https://github.com/InsureMO/rainbow-o23/issues"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@rainbow-o23/n1": "1.0.
|
|
24
|
+
"@rainbow-o23/n1": "1.0.27",
|
|
25
25
|
"@theinternetfolks/snowflake": "^1.3.0",
|
|
26
26
|
"node-fetch": "2.6.7",
|
|
27
27
|
"typeorm": "^0.3.17"
|
|
@@ -23,6 +23,7 @@ export interface FetchPipelineStepOptions<In = PipelineStepPayload, Out = Pipeli
|
|
|
23
23
|
/** on seconds */
|
|
24
24
|
timeout?: number;
|
|
25
25
|
headersGenerate?: ScriptFuncOrBody<HttpGenerateHeaders<In, InFragment>>;
|
|
26
|
+
bodyUsed?: boolean;
|
|
26
27
|
bodyGenerate?: ScriptFuncOrBody<HttpGenerateBody<In, InFragment>>;
|
|
27
28
|
responseGenerate?: ScriptFuncOrBody<HttpGenerateResponse<In, InFragment>>;
|
|
28
29
|
responseErrorHandles?: {
|
|
@@ -56,7 +57,7 @@ export class FetchPipelineStep<In = PipelineStepPayload, Out = PipelineStepPaylo
|
|
|
56
57
|
this._endpointName = options.endpointName;
|
|
57
58
|
const endpointKey = this.getEndpointKey();
|
|
58
59
|
this._endpointUrl = config.getString(`endpoints.${endpointKey}.url`);
|
|
59
|
-
this._endpointMethod = (
|
|
60
|
+
this._endpointMethod = (options.method ?? 'POST').trim().toLowerCase();
|
|
60
61
|
this._endpointHeaders = this.generateEndpointHeaders(
|
|
61
62
|
config.getString(`endpoints.${endpointKey}.headers`),
|
|
62
63
|
this.generateEndpointHeaders(config.getString(`endpoints.${this.getEndpointSystemCode()}.global.headers`)));
|
|
@@ -86,7 +87,7 @@ export class FetchPipelineStep<In = PipelineStepPayload, Out = PipelineStepPaylo
|
|
|
86
87
|
throw e;
|
|
87
88
|
}
|
|
88
89
|
});
|
|
89
|
-
this._bodyUsed =
|
|
90
|
+
this._bodyUsed = options.bodyUsed;
|
|
90
91
|
this._bodyGenerateSnippet = options.bodyGenerate;
|
|
91
92
|
this._bodyGenerateFunc = Utils.createSyncFunction(this.getBodyGenerateSnippet(), {
|
|
92
93
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -212,7 +213,7 @@ export class FetchPipelineStep<In = PipelineStepPayload, Out = PipelineStepPaylo
|
|
|
212
213
|
return ['$factor', '$request', ...this.getHelpersVariableNames()];
|
|
213
214
|
}
|
|
214
215
|
|
|
215
|
-
protected isBodyUsed(): boolean {
|
|
216
|
+
protected isBodyUsed(): boolean | undefined {
|
|
216
217
|
return this._bodyUsed;
|
|
217
218
|
}
|
|
218
219
|
|
|
@@ -249,7 +250,8 @@ export class FetchPipelineStep<In = PipelineStepPayload, Out = PipelineStepPaylo
|
|
|
249
250
|
const headers = this._headersGenerateFunc(data, request, $helpers, $helpers) ?? {};
|
|
250
251
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
251
252
|
let body: any;
|
|
252
|
-
|
|
253
|
+
const bodyUsed = this.isBodyUsed();
|
|
254
|
+
if (bodyUsed === true || (bodyUsed == null && method !== 'get')) {
|
|
253
255
|
body = this._bodyGenerateFunc(data, request, $helpers, $helpers);
|
|
254
256
|
} else {
|
|
255
257
|
body = (void 0);
|