@rainbow-o23/n3 1.0.39 → 1.0.41
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 +12 -12
- package/index.cjs +15 -6
- package/index.js +15 -6
- package/lib/http/fetch-step.d.ts +1 -1
- package/package.json +6 -6
- package/src/lib/http/fetch-step.ts +17 -10
package/README.md
CHANGED
|
@@ -602,18 +602,18 @@ CFG_ENDPOINTS_ORDER_PAYMENT_URL=https://order.com/payment
|
|
|
602
602
|
|
|
603
603
|
#### Constructor Parameters
|
|
604
604
|
|
|
605
|
-
| Name | Type
|
|
606
|
-
|
|
607
|
-
| endpointSystemCode | string
|
|
608
|
-
| endpointName | string
|
|
609
|
-
| urlGenerate | ScriptFuncOrBody\<HttpGenerateUrl>
|
|
610
|
-
| method | string
|
|
611
|
-
| timeout | number
|
|
612
|
-
| headersGenerate | ScriptFuncOrBody\<HttpGenerateHeaders>
|
|
613
|
-
| bodyUsed | boolean
|
|
614
|
-
| bodyGenerate | ScriptFuncOrBody\<HttpGenerateBody>
|
|
615
|
-
| responseGenerate | ScriptFuncOrBody\<HttpGenerateResponse>
|
|
616
|
-
| responseErrorHandles | {[key: HttpErrorCode]: ScriptFuncOrBody\<HttpHandleError>} | | Endpoint response error handlers. |
|
|
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, default `post`. |
|
|
611
|
+
| timeout | number | | Endpoint timeout, in seconds. |
|
|
612
|
+
| headersGenerate | ScriptFuncOrBody\<HttpGenerateHeaders> | | Endpoint request headers generator. |
|
|
613
|
+
| bodyUsed | boolean | | Send request with body or not, or automatically disregards the body when sending a `get` request when not specified. |
|
|
614
|
+
| bodyGenerate | ScriptFuncOrBody\<HttpGenerateBody> | | Endpoint request body generator. |
|
|
615
|
+
| responseGenerate | ScriptFuncOrBody\<HttpGenerateResponse> | | Endpoint response body generator, `$response`. |
|
|
616
|
+
| responseErrorHandles | ScriptFuncOrBody\<HttpHandleError><br>or<br>{[key: HttpErrorCode]: ScriptFuncOrBody\<HttpHandleError>} | | Endpoint response error handlers. |
|
|
617
617
|
|
|
618
618
|
## Installation
|
|
619
619
|
|
package/index.cjs
CHANGED
|
@@ -1297,12 +1297,21 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
|
|
|
1297
1297
|
throw e;
|
|
1298
1298
|
}
|
|
1299
1299
|
});
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1300
|
+
const defaultHandler = async (options, _$helpers, _$) => {
|
|
1301
|
+
throw new n1.UncatchableError(ERR_FETCH_ERROR, `Error[${options.$errorCode}] caught when fetch data from remote[${options.$url}].`);
|
|
1302
|
+
};
|
|
1303
|
+
const createDefaultHandler = () => defaultHandler;
|
|
1304
|
+
const getVariableNames = () => this.getErrorHandlerVariableName();
|
|
1305
|
+
if (typeof options.responseErrorHandles === 'string' || typeof options.responseErrorHandles === 'function') {
|
|
1306
|
+
this._responseErrorHandleFunc = Utils.createAsyncFunction(options.responseErrorHandles, {
|
|
1307
|
+
createDefault: createDefaultHandler, getVariableNames,
|
|
1308
|
+
error: (e) => {
|
|
1309
|
+
this.getLogger().error(`Failed on create function for response error handler, snippet is [${options.responseErrorHandles}].`);
|
|
1310
|
+
throw e;
|
|
1311
|
+
}
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1314
|
+
else if (options.responseErrorHandles != null) {
|
|
1306
1315
|
const handlers = Object.keys(options.responseErrorHandles).reduce((handlers, status) => {
|
|
1307
1316
|
handlers[status] = Utils.createAsyncFunction(options.responseErrorHandles[status], {
|
|
1308
1317
|
createDefault: createDefaultHandler, getVariableNames,
|
package/index.js
CHANGED
|
@@ -1295,12 +1295,21 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
|
|
|
1295
1295
|
throw e;
|
|
1296
1296
|
}
|
|
1297
1297
|
});
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1298
|
+
const defaultHandler = async (options, _$helpers, _$) => {
|
|
1299
|
+
throw new UncatchableError(ERR_FETCH_ERROR, `Error[${options.$errorCode}] caught when fetch data from remote[${options.$url}].`);
|
|
1300
|
+
};
|
|
1301
|
+
const createDefaultHandler = () => defaultHandler;
|
|
1302
|
+
const getVariableNames = () => this.getErrorHandlerVariableName();
|
|
1303
|
+
if (typeof options.responseErrorHandles === 'string' || typeof options.responseErrorHandles === 'function') {
|
|
1304
|
+
this._responseErrorHandleFunc = Utils.createAsyncFunction(options.responseErrorHandles, {
|
|
1305
|
+
createDefault: createDefaultHandler, getVariableNames,
|
|
1306
|
+
error: (e) => {
|
|
1307
|
+
this.getLogger().error(`Failed on create function for response error handler, snippet is [${options.responseErrorHandles}].`);
|
|
1308
|
+
throw e;
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
else if (options.responseErrorHandles != null) {
|
|
1304
1313
|
const handlers = Object.keys(options.responseErrorHandles).reduce((handlers, status) => {
|
|
1305
1314
|
handlers[status] = Utils.createAsyncFunction(options.responseErrorHandles[status], {
|
|
1306
1315
|
createDefault: createDefaultHandler, getVariableNames,
|
package/lib/http/fetch-step.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface FetchPipelineStepOptions<In = PipelineStepPayload, Out = Pipeli
|
|
|
11
11
|
bodyUsed?: boolean;
|
|
12
12
|
bodyGenerate?: ScriptFuncOrBody<HttpGenerateBody<In, InFragment>>;
|
|
13
13
|
responseGenerate?: ScriptFuncOrBody<HttpGenerateResponse<In, InFragment>>;
|
|
14
|
-
responseErrorHandles?: {
|
|
14
|
+
responseErrorHandles?: ScriptFuncOrBody<HttpHandleError<In, InFragment, OutFragment>> | {
|
|
15
15
|
[key: HttpErrorCode]: ScriptFuncOrBody<HttpHandleError<In, InFragment, OutFragment>>;
|
|
16
16
|
};
|
|
17
17
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rainbow-o23/n3",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.41",
|
|
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.41",
|
|
25
25
|
"node-fetch": "2.6.7",
|
|
26
26
|
"typeorm": "^0.3.17"
|
|
27
27
|
},
|
|
@@ -35,16 +35,16 @@
|
|
|
35
35
|
"@types/events": "^3.0.1",
|
|
36
36
|
"@types/node": "18.16.12",
|
|
37
37
|
"@types/node-fetch": "2.6.4",
|
|
38
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
39
|
-
"@typescript-eslint/parser": "^
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
39
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
40
40
|
"better-sqlite3": "^9.0.0",
|
|
41
|
-
"eslint": "^8.
|
|
41
|
+
"eslint": "^9.8.0",
|
|
42
42
|
"mssql": "^10.0.1",
|
|
43
43
|
"mysql2": "^3.9.8",
|
|
44
44
|
"oracledb": "^6.2.0",
|
|
45
45
|
"pg": "^8.11.3",
|
|
46
46
|
"pg-query-stream": "^4.5.3",
|
|
47
|
-
"reflect-metadata": "^0.
|
|
47
|
+
"reflect-metadata": "^0.2.2",
|
|
48
48
|
"rollup": "^3.7.0",
|
|
49
49
|
"rollup-plugin-tslint": "^0.2.2",
|
|
50
50
|
"rollup-plugin-typescript2": "^0.34.1",
|
|
@@ -26,9 +26,8 @@ export interface FetchPipelineStepOptions<In = PipelineStepPayload, Out = Pipeli
|
|
|
26
26
|
bodyUsed?: boolean;
|
|
27
27
|
bodyGenerate?: ScriptFuncOrBody<HttpGenerateBody<In, InFragment>>;
|
|
28
28
|
responseGenerate?: ScriptFuncOrBody<HttpGenerateResponse<In, InFragment>>;
|
|
29
|
-
responseErrorHandles?:
|
|
30
|
-
[key: HttpErrorCode]: ScriptFuncOrBody<HttpHandleError<In, InFragment, OutFragment>>;
|
|
31
|
-
};
|
|
29
|
+
responseErrorHandles?: ScriptFuncOrBody<HttpHandleError<In, InFragment, OutFragment>>
|
|
30
|
+
| { [key: HttpErrorCode]: ScriptFuncOrBody<HttpHandleError<In, InFragment, OutFragment>>; };
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
export class FetchPipelineStep<In = PipelineStepPayload, Out = PipelineStepPayload, InFragment = In, OutFragment = Out>
|
|
@@ -112,13 +111,21 @@ export class FetchPipelineStep<In = PipelineStepPayload, Out = PipelineStepPaylo
|
|
|
112
111
|
throw e;
|
|
113
112
|
}
|
|
114
113
|
});
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
114
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
115
|
+
const defaultHandler = async (options: HttpErrorHandleOptions<In, InFragment>, _$helpers: PipelineStepHelpers, _$: PipelineStepHelpers): Promise<OutFragment> | never => {
|
|
116
|
+
throw new UncatchableError(ERR_FETCH_ERROR, `Error[${options.$errorCode}] caught when fetch data from remote[${options.$url}].`);
|
|
117
|
+
};
|
|
118
|
+
const createDefaultHandler = () => defaultHandler;
|
|
119
|
+
const getVariableNames = () => this.getErrorHandlerVariableName();
|
|
120
|
+
if (typeof options.responseErrorHandles === 'string' || typeof options.responseErrorHandles === 'function') {
|
|
121
|
+
this._responseErrorHandleFunc = Utils.createAsyncFunction(options.responseErrorHandles, {
|
|
122
|
+
createDefault: createDefaultHandler, getVariableNames,
|
|
123
|
+
error: (e: Error) => {
|
|
124
|
+
this.getLogger().error(`Failed on create function for response error handler, snippet is [${options.responseErrorHandles}].`);
|
|
125
|
+
throw e;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
} else if (options.responseErrorHandles != null) {
|
|
122
129
|
const handlers: Record<HttpErrorCode, HttpHandleError<In, InFragment, OutFragment>> = Object.keys(options.responseErrorHandles).reduce((handlers, status) => {
|
|
123
130
|
handlers[status] = Utils.createAsyncFunction(options.responseErrorHandles[status], {
|
|
124
131
|
createDefault: createDefaultHandler, getVariableNames,
|