@envoy/envoy-integrations-sdk 2.0.1-beta.5 → 2.0.2
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 +178 -110
- package/dist/base/EnvoyAPI.d.ts +28 -0
- package/dist/base/EnvoyAPI.d.ts.map +1 -0
- package/dist/base/EnvoyAPI.js +121 -0
- package/dist/base/EnvoyPluginStoragePipeline.d.ts +51 -0
- package/dist/base/EnvoyPluginStoragePipeline.d.ts.map +1 -0
- package/dist/base/EnvoyPluginStoragePipeline.js +140 -0
- package/dist/constants.d.ts +5 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +12 -0
- package/dist/factories/entryEventBodyFactory.d.ts +42 -0
- package/dist/factories/entryEventBodyFactory.d.ts.map +1 -0
- package/dist/factories/entryEventBodyFactory.js +105 -0
- package/dist/factories/eventBodyFactory.d.ts +18 -0
- package/dist/factories/eventBodyFactory.d.ts.map +1 -0
- package/dist/factories/eventBodyFactory.js +15 -0
- package/dist/factories/inviteEventBodyFactory.d.ts +38 -0
- package/dist/factories/inviteEventBodyFactory.d.ts.map +1 -0
- package/dist/factories/inviteEventBodyFactory.js +92 -0
- package/dist/factories/metaFactory.d.ts +10 -0
- package/dist/factories/metaFactory.d.ts.map +1 -0
- package/dist/factories/metaFactory.js +90 -0
- package/dist/factories/routeBodyFactory.d.ts +19 -0
- package/dist/factories/routeBodyFactory.d.ts.map +1 -0
- package/dist/factories/routeBodyFactory.js +15 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +74 -0
- package/dist/internal/EnvoyEntryEvent.d.ts +3 -0
- package/dist/internal/EnvoyEntryEvent.d.ts.map +1 -0
- package/dist/internal/EnvoyEntryEvent.js +2 -0
- package/dist/internal/EnvoyInviteEvent.d.ts +3 -0
- package/dist/internal/EnvoyInviteEvent.d.ts.map +1 -0
- package/dist/internal/EnvoyInviteEvent.js +2 -0
- package/dist/internal/EnvoyLocationEvent.d.ts +3 -0
- package/dist/internal/EnvoyLocationEvent.d.ts.map +1 -0
- package/dist/internal/EnvoyLocationEvent.js +2 -0
- package/dist/internal/EnvoyOption.d.ts +6 -0
- package/dist/internal/EnvoyOption.d.ts.map +1 -0
- package/dist/internal/EnvoyOption.js +2 -0
- package/dist/internal/EnvoyOptionsRouteParams.d.ts +7 -0
- package/dist/internal/EnvoyOptionsRouteParams.d.ts.map +1 -0
- package/dist/internal/EnvoyOptionsRouteParams.js +2 -0
- package/dist/internal/EnvoyOptionsRouteResponseBody.d.ts +4 -0
- package/dist/internal/EnvoyOptionsRouteResponseBody.d.ts.map +1 -0
- package/dist/internal/EnvoyOptionsRouteResponseBody.js +2 -0
- package/dist/internal/EnvoyPluginJobUpdate.d.ts +11 -0
- package/dist/internal/EnvoyPluginJobUpdate.d.ts.map +1 -0
- package/dist/internal/EnvoyPluginJobUpdate.js +2 -0
- package/dist/internal/EnvoyRemoteValueRouteResponseBody.d.ts +5 -0
- package/dist/internal/EnvoyRemoteValueRouteResponseBody.d.ts.map +1 -0
- package/dist/internal/EnvoyRemoteValueRouteResponseBody.js +2 -0
- package/dist/internal/EnvoySelectedValuesRouteParams.d.ts +5 -0
- package/dist/internal/EnvoySelectedValuesRouteParams.d.ts.map +1 -0
- package/dist/internal/EnvoySelectedValuesRouteParams.js +2 -0
- package/dist/internal/EnvoySelectedValuesRouteResponseBody.d.ts +4 -0
- package/dist/internal/EnvoySelectedValuesRouteResponseBody.d.ts.map +1 -0
- package/dist/internal/EnvoySelectedValuesRouteResponseBody.js +2 -0
- package/dist/internal/EnvoyStorageCommand.d.ts +42 -0
- package/dist/internal/EnvoyStorageCommand.d.ts.map +1 -0
- package/dist/internal/EnvoyStorageCommand.js +7 -0
- package/dist/internal/EnvoyStorageResult.d.ts +4 -0
- package/dist/internal/EnvoyStorageResult.d.ts.map +1 -0
- package/dist/internal/EnvoyStorageResult.js +2 -0
- package/dist/internal/HttpStatus.d.ts +13 -0
- package/dist/internal/HttpStatus.d.ts.map +1 -0
- package/dist/internal/HttpStatus.js +15 -0
- package/dist/mocks/EnvoyPluginJobMock.d.ts +12 -0
- package/dist/mocks/EnvoyPluginJobMock.d.ts.map +1 -0
- package/dist/mocks/EnvoyPluginJobMock.js +60 -0
- package/dist/mocks/EnvoyPluginStoragePipelineMock.d.ts +24 -0
- package/dist/mocks/EnvoyPluginStoragePipelineMock.d.ts.map +1 -0
- package/dist/mocks/EnvoyPluginStoragePipelineMock.js +212 -0
- package/dist/payloads/EntryPayload.d.ts +80 -0
- package/dist/payloads/EntryPayload.d.ts.map +1 -0
- package/dist/payloads/EntryPayload.js +28 -0
- package/dist/payloads/InvitePayload.d.ts +66 -0
- package/dist/payloads/InvitePayload.d.ts.map +1 -0
- package/dist/payloads/InvitePayload.js +24 -0
- package/dist/payloads/LocationPayload.d.ts +7 -0
- package/dist/payloads/LocationPayload.d.ts.map +1 -0
- package/dist/payloads/LocationPayload.js +2 -0
- package/dist/payloads/NotificationPayload.d.ts +54 -0
- package/dist/payloads/NotificationPayload.d.ts.map +1 -0
- package/dist/payloads/NotificationPayload.js +2 -0
- package/dist/resources/AgreementPageResource.d.ts +17 -0
- package/dist/resources/AgreementPageResource.d.ts.map +1 -0
- package/dist/resources/AgreementPageResource.js +2 -0
- package/dist/resources/AgreementResource.d.ts +24 -0
- package/dist/resources/AgreementResource.d.ts.map +1 -0
- package/dist/resources/AgreementResource.js +2 -0
- package/dist/resources/CompanyResource.d.ts +19 -0
- package/dist/resources/CompanyResource.d.ts.map +1 -0
- package/dist/resources/CompanyResource.js +2 -0
- package/dist/resources/CompanyRoleResource.d.ts +8 -0
- package/dist/resources/CompanyRoleResource.d.ts.map +1 -0
- package/dist/resources/CompanyRoleResource.js +2 -0
- package/dist/resources/CurrentUserResource.d.ts +8 -0
- package/dist/resources/CurrentUserResource.d.ts.map +1 -0
- package/dist/resources/CurrentUserResource.js +2 -0
- package/dist/resources/EmployeeResource.d.ts +43 -0
- package/dist/resources/EmployeeResource.d.ts.map +1 -0
- package/dist/resources/EmployeeResource.js +2 -0
- package/dist/resources/FlowResource.d.ts +31 -0
- package/dist/resources/FlowResource.d.ts.map +1 -0
- package/dist/resources/FlowResource.js +2 -0
- package/dist/resources/InviteResource.d.ts +86 -0
- package/dist/resources/InviteResource.d.ts.map +1 -0
- package/dist/resources/InviteResource.js +2 -0
- package/dist/resources/LocationResource.d.ts +64 -0
- package/dist/resources/LocationResource.d.ts.map +1 -0
- package/dist/resources/LocationResource.js +2 -0
- package/dist/resources/LocationRoleResource.d.ts +8 -0
- package/dist/resources/LocationRoleResource.d.ts.map +1 -0
- package/dist/resources/LocationRoleResource.js +2 -0
- package/dist/resources/SignInFieldPageResource.d.ts +17 -0
- package/dist/resources/SignInFieldPageResource.d.ts.map +1 -0
- package/dist/resources/SignInFieldPageResource.js +2 -0
- package/dist/resources/SignInFieldResource.d.ts +33 -0
- package/dist/resources/SignInFieldResource.d.ts.map +1 -0
- package/dist/resources/SignInFieldResource.js +2 -0
- package/dist/resources/UserResource.d.ts +13 -0
- package/dist/resources/UserResource.d.ts.map +1 -0
- package/dist/resources/UserResource.js +2 -0
- package/dist/sdk/EnvoyMeta.d.ts +96 -0
- package/dist/sdk/EnvoyMeta.d.ts.map +1 -0
- package/dist/sdk/EnvoyMeta.js +2 -0
- package/dist/sdk/EnvoyPluginAPI.d.ts +31 -0
- package/dist/sdk/EnvoyPluginAPI.d.ts.map +1 -0
- package/dist/sdk/EnvoyPluginAPI.js +205 -0
- package/dist/sdk/EnvoyPluginJob.d.ts +49 -0
- package/dist/sdk/EnvoyPluginJob.d.ts.map +1 -0
- package/dist/sdk/EnvoyPluginJob.js +99 -0
- package/dist/sdk/EnvoyPluginJobAttachment.d.ts +43 -0
- package/dist/sdk/EnvoyPluginJobAttachment.d.ts.map +1 -0
- package/dist/sdk/EnvoyPluginJobAttachment.js +2 -0
- package/dist/sdk/EnvoyPluginSDK.d.ts +100 -0
- package/dist/sdk/EnvoyPluginSDK.d.ts.map +1 -0
- package/dist/sdk/EnvoyPluginSDK.js +204 -0
- package/dist/sdk/EnvoyPluginStorage.d.ts +69 -0
- package/dist/sdk/EnvoyPluginStorage.d.ts.map +1 -0
- package/dist/sdk/EnvoyPluginStorage.js +78 -0
- package/dist/sdk/EnvoyRequest.d.ts +116 -0
- package/dist/sdk/EnvoyRequest.d.ts.map +1 -0
- package/dist/sdk/EnvoyRequest.js +7 -0
- package/dist/sdk/EnvoyResponse.d.ts +42 -0
- package/dist/sdk/EnvoyResponse.d.ts.map +1 -0
- package/dist/sdk/EnvoyResponse.js +2 -0
- package/dist/sdk/EnvoyStorageItem.d.ts +9 -0
- package/dist/sdk/EnvoyStorageItem.d.ts.map +1 -0
- package/dist/sdk/EnvoyStorageItem.js +2 -0
- package/dist/sdk/EnvoyUserAPI.d.ts +119 -0
- package/dist/sdk/EnvoyUserAPI.d.ts.map +1 -0
- package/dist/sdk/EnvoyUserAPI.js +493 -0
- package/dist/sdk/filters.d.ts +30 -0
- package/dist/sdk/filters.d.ts.map +1 -0
- package/dist/sdk/filters.js +72 -0
- package/dist/sdk/handlers.d.ts +125 -0
- package/dist/sdk/handlers.d.ts.map +1 -0
- package/dist/sdk/handlers.js +108 -0
- package/dist/sdk/loggers.d.ts +6 -0
- package/dist/sdk/loggers.d.ts.map +1 -0
- package/dist/sdk/loggers.js +161 -0
- package/dist/sdk/middleware.d.ts +19 -0
- package/dist/sdk/middleware.d.ts.map +1 -0
- package/dist/sdk/middleware.js +159 -0
- package/dist/util/EnvoyJWT.d.ts +17 -0
- package/dist/util/EnvoyJWT.d.ts.map +1 -0
- package/dist/util/EnvoyJWT.js +54 -0
- package/dist/util/EnvoySignatureVerifier.d.ts +26 -0
- package/dist/util/EnvoySignatureVerifier.d.ts.map +1 -0
- package/dist/util/EnvoySignatureVerifier.js +53 -0
- package/dist/util/axiosConstructor.d.ts +4 -0
- package/dist/util/axiosConstructor.d.ts.map +1 -0
- package/dist/util/axiosConstructor.js +58 -0
- package/dist/util/errorHandling.d.ts +2 -0
- package/dist/util/errorHandling.d.ts.map +1 -0
- package/dist/util/errorHandling.js +18 -0
- package/dist/util/json-api/JSONAPIData.d.ts +5 -0
- package/dist/util/json-api/JSONAPIData.d.ts.map +1 -0
- package/dist/util/json-api/JSONAPIData.js +2 -0
- package/dist/util/json-api/JSONAPIFilterParams.d.ts +5 -0
- package/dist/util/json-api/JSONAPIFilterParams.d.ts.map +1 -0
- package/dist/util/json-api/JSONAPIFilterParams.js +2 -0
- package/dist/util/json-api/JSONAPIModel.d.ts +10 -0
- package/dist/util/json-api/JSONAPIModel.d.ts.map +1 -0
- package/dist/util/json-api/JSONAPIModel.js +2 -0
- package/dist/util/json-api/JSONAPIPaginationParams.d.ts +9 -0
- package/dist/util/json-api/JSONAPIPaginationParams.d.ts.map +1 -0
- package/dist/util/json-api/JSONAPIPaginationParams.js +2 -0
- package/dist/util/json-api/JSONAPIParams.d.ts +4 -0
- package/dist/util/json-api/JSONAPIParams.d.ts.map +1 -0
- package/dist/util/json-api/JSONAPIParams.js +2 -0
- package/dist/util/json-api/JSONAPIResponse.d.ts +6 -0
- package/dist/util/json-api/JSONAPIResponse.d.ts.map +1 -0
- package/dist/util/json-api/JSONAPIResponse.js +2 -0
- package/package.json +48 -13
- package/src/base/EnvoyAPI.ts +87 -0
- package/src/base/EnvoyPluginStoragePipeline.ts +99 -0
- package/src/constants.ts +7 -0
- package/src/factories/entryEventBodyFactory.ts +124 -0
- package/src/factories/eventBodyFactory.ts +35 -0
- package/src/factories/inviteEventBodyFactory.ts +107 -0
- package/src/factories/metaFactory.ts +109 -0
- package/src/factories/routeBodyFactory.ts +37 -0
- package/src/index.ts +86 -0
- package/src/internal/EnvoyEntryEvent.ts +10 -0
- package/src/internal/EnvoyInviteEvent.ts +13 -0
- package/src/internal/EnvoyLocationEvent.ts +3 -0
- package/src/internal/EnvoyOption.ts +6 -0
- package/src/internal/EnvoyOptionsRouteParams.ts +7 -0
- package/src/internal/EnvoyOptionsRouteResponseBody.ts +4 -0
- package/src/internal/EnvoyPluginJobUpdate.ts +11 -0
- package/src/internal/EnvoyRemoteValueRouteResponseBody.ts +4 -0
- package/src/internal/EnvoySelectedValuesRouteParams.ts +5 -0
- package/src/internal/EnvoySelectedValuesRouteResponseBody.ts +4 -0
- package/src/internal/EnvoyStorageCommand.ts +60 -0
- package/src/internal/EnvoyStorageResult.ts +5 -0
- package/src/internal/HttpStatus.ts +12 -0
- package/src/mocks/EnvoyPluginJobMock.ts +33 -0
- package/src/mocks/EnvoyPluginStoragePipelineMock.ts +204 -0
- package/src/payloads/EntryPayload.ts +101 -0
- package/src/payloads/InvitePayload.ts +79 -0
- package/src/payloads/LocationPayload.ts +8 -0
- package/src/payloads/NotificationPayload.ts +54 -0
- package/src/resources/AgreementPageResource.ts +19 -0
- package/src/resources/AgreementResource.ts +26 -0
- package/src/resources/CompanyResource.ts +21 -0
- package/src/resources/CompanyRoleResource.ts +10 -0
- package/src/resources/CurrentUserResource.ts +10 -0
- package/src/resources/EmployeeResource.ts +47 -0
- package/src/resources/FlowResource.ts +35 -0
- package/src/resources/InviteResource.ts +92 -0
- package/src/resources/LocationResource.ts +68 -0
- package/src/resources/LocationRoleResource.ts +10 -0
- package/src/resources/SignInFieldPageResource.ts +23 -0
- package/src/resources/SignInFieldResource.ts +35 -0
- package/src/resources/UserResource.ts +14 -0
- package/src/sdk/EnvoyMeta.ts +101 -0
- package/src/sdk/EnvoyPluginAPI.ts +95 -0
- package/src/sdk/EnvoyPluginJob.ts +90 -0
- package/src/sdk/EnvoyPluginJobAttachment.ts +48 -0
- package/src/sdk/EnvoyPluginSDK.ts +185 -0
- package/src/sdk/EnvoyPluginStorage.ts +83 -0
- package/src/sdk/EnvoyRequest.ts +145 -0
- package/src/sdk/EnvoyResponse.ts +46 -0
- package/src/sdk/EnvoyStorageItem.ts +9 -0
- package/src/sdk/EnvoyUserAPI.ts +339 -0
- package/src/sdk/filters.ts +96 -0
- package/src/sdk/handlers.ts +234 -0
- package/src/sdk/loggers.ts +165 -0
- package/src/sdk/middleware.ts +101 -0
- package/src/util/EnvoyJWT.ts +51 -0
- package/src/util/EnvoySignatureVerifier.ts +61 -0
- package/src/util/axiosConstructor.ts +46 -0
- package/src/util/errorHandling.ts +15 -0
- package/src/util/json-api/JSONAPIData.ts +4 -0
- package/src/util/json-api/JSONAPIFilterParams.ts +5 -0
- package/src/util/json-api/JSONAPIModel.ts +10 -0
- package/src/util/json-api/JSONAPIPaginationParams.ts +12 -0
- package/src/util/json-api/JSONAPIParams.ts +3 -0
- package/src/util/json-api/JSONAPIResponse.ts +5 -0
- package/.eslintrc.js +0 -46
- package/.github/workflows/package.yaml +0 -43
- package/.github/workflows/test.yaml +0 -15
- package/asynchandler.md +0 -46
- package/envoyapi.md +0 -150
- package/envoyjwt.md +0 -46
- package/envoypluginjob.md +0 -106
- package/envoypluginsdk.md +0 -87
- package/envoypluginstorage.md +0 -95
- package/envoypluginstoragepipeline.md +0 -125
- package/envoysignatureverifier.md +0 -43
- package/errormiddleware.md +0 -41
- package/index.js +0 -49
- package/lib/EnvoyAPI.js +0 -564
- package/lib/EnvoyJWT.js +0 -72
- package/lib/EnvoyPluginJob.js +0 -124
- package/lib/EnvoyPluginSDK.js +0 -192
- package/lib/EnvoyPluginStorage.js +0 -121
- package/lib/EnvoyPluginStoragePipeline.js +0 -155
- package/lib/EnvoyResponseError.js +0 -18
- package/lib/EnvoySignatureVerifier.js +0 -67
- package/lib/HttpStatus.js +0 -20
- package/lib/asyncHandler.js +0 -17
- package/lib/axios.js +0 -34
- package/lib/errorMiddleware.js +0 -27
- package/lib/middleware.js +0 -110
- package/middleware.md +0 -53
- package/test/axios.test.js +0 -57
- package/test/promises.test.js +0 -82
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import util from 'util';
|
|
4
|
+
|
|
5
|
+
function envoyAxiosRequestLogger(config: AxiosRequestConfig) {
|
|
6
|
+
const log = console.log;
|
|
7
|
+
log('---------------- Axios Request ----------------\n');
|
|
8
|
+
if (config?.method) {
|
|
9
|
+
const boldMethodText = chalk.bold('Method:');
|
|
10
|
+
const method = config.method.toUpperCase();
|
|
11
|
+
switch (method) {
|
|
12
|
+
case 'GET':
|
|
13
|
+
log(`${boldMethodText} ${chalk.green(method)}\n`);
|
|
14
|
+
break;
|
|
15
|
+
case 'PUT':
|
|
16
|
+
log(`${boldMethodText} ${chalk.yellow(method)}\n`);
|
|
17
|
+
break;
|
|
18
|
+
case 'PATCH':
|
|
19
|
+
log(`${boldMethodText} ${chalk.yellow(method)}\n`);
|
|
20
|
+
break;
|
|
21
|
+
case 'POST':
|
|
22
|
+
log(`${boldMethodText} ${chalk.blue(method)}\n`);
|
|
23
|
+
break;
|
|
24
|
+
case 'DELETE':
|
|
25
|
+
log(`${boldMethodText} ${chalk.red(method)}\n`);
|
|
26
|
+
break;
|
|
27
|
+
default:
|
|
28
|
+
log(`${boldMethodText} ${method}\n`);
|
|
29
|
+
break;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (config?.baseURL && config?.url) {
|
|
33
|
+
log(`${chalk.bold('URL')}: ${config.baseURL}/${config.url}\n`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (config?.headers) {
|
|
37
|
+
log(`${chalk.bold('Headers:')} ${util.inspect(config?.headers)}\n`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (config?.auth) {
|
|
41
|
+
log(`${chalk.bold('Auth:')} ${util.inspect(config?.auth)}\n`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (config?.params) {
|
|
45
|
+
log(`${chalk.bold('Params:')} ${util.inspect(config?.params)}\n`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (config?.data) {
|
|
49
|
+
log(`${chalk.bold('Request Data:')} ${util.inspect(config?.data)}\n`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
log('------------ End Of Axios Request ------------\n');
|
|
53
|
+
|
|
54
|
+
return config;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function envoyAxiosResponseLogger(response: AxiosResponse) {
|
|
58
|
+
const log = console.log;
|
|
59
|
+
log('---------------- Axios Response ----------------\n');
|
|
60
|
+
if (response?.request?.method) {
|
|
61
|
+
const boldMethodText = chalk.bold('Method:');
|
|
62
|
+
const method = response.request.method;
|
|
63
|
+
switch (method) {
|
|
64
|
+
case 'GET':
|
|
65
|
+
log(`${boldMethodText} ${chalk.green(method)}\n`);
|
|
66
|
+
break;
|
|
67
|
+
case 'PUT':
|
|
68
|
+
log(`${boldMethodText} ${chalk.yellow(method)}\n`);
|
|
69
|
+
break;
|
|
70
|
+
case 'PATCH':
|
|
71
|
+
log(`${boldMethodText} ${chalk.yellow(method)}\n`);
|
|
72
|
+
break;
|
|
73
|
+
case 'POST':
|
|
74
|
+
log(`${boldMethodText} ${chalk.blue(method)}\n`);
|
|
75
|
+
break;
|
|
76
|
+
case 'DELETE':
|
|
77
|
+
log(`${boldMethodText} ${chalk.red(method)}\n`);
|
|
78
|
+
break;
|
|
79
|
+
default:
|
|
80
|
+
log(`${boldMethodText} ${method}\n`);
|
|
81
|
+
break;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (response?.request?.baseURL && response?.request?.url) {
|
|
85
|
+
log(`${chalk.bold('Request URL')}: ${response.request.baseURL}/${response.request.url}\n`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (response?.status && response?.statusText) {
|
|
89
|
+
const boldStatusTitle = chalk.bold('Status:');
|
|
90
|
+
const boldStatusTextTitle = chalk.bold('Status Text:');
|
|
91
|
+
const status = response.status;
|
|
92
|
+
const statusText = response.statusText;
|
|
93
|
+
if (199 < status && status < 300) {
|
|
94
|
+
log(`${boldStatusTitle} ${chalk.green(status)}\n`);
|
|
95
|
+
log(`${boldStatusTextTitle} ${chalk.green(statusText)}\n`);
|
|
96
|
+
} else {
|
|
97
|
+
log(`${boldStatusTitle} ${chalk.red(status)}\n`);
|
|
98
|
+
log(`${boldStatusTextTitle} ${chalk.red(statusText)}\n`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (response?.data) {
|
|
103
|
+
log(`${chalk.bold('Response Data:')} ${util.inspect(response?.data)}\n`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
log('------------ End Of Axios Response ------------\n');
|
|
107
|
+
|
|
108
|
+
return response;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function envoyAxiosErrorLogger(error: AxiosError) {
|
|
112
|
+
const log = console.log;
|
|
113
|
+
log('---------------- Axios Error ----------------\n');
|
|
114
|
+
if (error?.request?.method) {
|
|
115
|
+
const boldMethodText = chalk.bold('Method:');
|
|
116
|
+
const method = error.request.method;
|
|
117
|
+
switch (method) {
|
|
118
|
+
case 'GET':
|
|
119
|
+
log(`${boldMethodText} ${chalk.green(method)}\n`);
|
|
120
|
+
break;
|
|
121
|
+
case 'PUT':
|
|
122
|
+
log(`${boldMethodText} ${chalk.yellow(method)}\n`);
|
|
123
|
+
break;
|
|
124
|
+
case 'PATCH':
|
|
125
|
+
log(`${boldMethodText} ${chalk.yellow(method)}\n`);
|
|
126
|
+
break;
|
|
127
|
+
case 'POST':
|
|
128
|
+
log(`${boldMethodText} ${chalk.blue(method)}\n`);
|
|
129
|
+
break;
|
|
130
|
+
case 'DELETE':
|
|
131
|
+
log(`${boldMethodText} ${chalk.red(method)}\n`);
|
|
132
|
+
break;
|
|
133
|
+
default:
|
|
134
|
+
log(`${boldMethodText} ${method}\n`);
|
|
135
|
+
break;
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
if (error?.request?.baseURL && error?.request?.url) {
|
|
139
|
+
log(`${chalk.bold('Request URL')}: ${error.request.baseURL}/${error.request.url}\n`);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (error?.response?.status && error?.response?.statusText) {
|
|
143
|
+
const boldStatusTitle = chalk.bold('Status:');
|
|
144
|
+
const boldStatusTextTitle = chalk.bold('Status Text:');
|
|
145
|
+
const status = error.response.status;
|
|
146
|
+
const statusText = error.response.statusText;
|
|
147
|
+
if (199 < status && status < 300) {
|
|
148
|
+
log(`${boldStatusTitle} ${chalk.green(status)}\n`);
|
|
149
|
+
log(`${boldStatusTextTitle} ${chalk.green(statusText)}\n`);
|
|
150
|
+
} else {
|
|
151
|
+
log(`${boldStatusTitle} ${chalk.red(status)}\n`);
|
|
152
|
+
log(`${boldStatusTextTitle} ${chalk.red(statusText)}\n`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (error.response?.data) {
|
|
157
|
+
log(`${chalk.bold('Response Data:')} ${util.inspect(error.response.data)}\n`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
log('------------ End Of Axios Error ------------\n');
|
|
161
|
+
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export { envoyAxiosRequestLogger, envoyAxiosResponseLogger, envoyAxiosErrorLogger };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import bodyParser from 'body-parser';
|
|
2
|
+
import {
|
|
3
|
+
Request,
|
|
4
|
+
Response,
|
|
5
|
+
NextFunction,
|
|
6
|
+
ErrorRequestHandler,
|
|
7
|
+
RequestHandler,
|
|
8
|
+
} from 'express';
|
|
9
|
+
|
|
10
|
+
import HttpStatus from '../internal/HttpStatus';
|
|
11
|
+
import EnvoySignatureVerifier, { EnvoySignatureVerifierOptions } from '../util/EnvoySignatureVerifier';
|
|
12
|
+
import EnvoyRequest, { VERIFIED, VerifiedRequest } from './EnvoyRequest';
|
|
13
|
+
import EnvoyResponse from './EnvoyResponse';
|
|
14
|
+
import EnvoyPluginJobAttachment from './EnvoyPluginJobAttachment';
|
|
15
|
+
import EnvoyPluginSDK from './EnvoyPluginSDK';
|
|
16
|
+
import EnvoyPluginAPI from './EnvoyPluginAPI';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Sets up an {@link EnvoyPluginSDK} object in the path `req.envoy`.
|
|
20
|
+
* Modifies the `res` object to include Envoy's helpers, per {@link EnvoyResponse}.
|
|
21
|
+
*
|
|
22
|
+
* Also verifies that the request is coming from Envoy,
|
|
23
|
+
* as well as managing the plugin access token lifecycle.
|
|
24
|
+
*
|
|
25
|
+
* @category Middleware
|
|
26
|
+
*/
|
|
27
|
+
export function envoyMiddleware(options?: EnvoySignatureVerifierOptions): RequestHandler {
|
|
28
|
+
const signatureVerifier = new EnvoySignatureVerifier(options);
|
|
29
|
+
const verify = (req: VerifiedRequest, res: Response, rawBody: Buffer) => {
|
|
30
|
+
req[VERIFIED] = signatureVerifier.verify(req, rawBody);
|
|
31
|
+
};
|
|
32
|
+
const json = bodyParser.json({ verify });
|
|
33
|
+
let accessToken: string | null = null;
|
|
34
|
+
let threshold = 0;
|
|
35
|
+
|
|
36
|
+
return (req: Request, res: Response, next: NextFunction) => {
|
|
37
|
+
json(req, res, async (err) => {
|
|
38
|
+
if (err) {
|
|
39
|
+
return next(err);
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const now = Date.now();
|
|
43
|
+
if (now > threshold) {
|
|
44
|
+
const { access_token: rawAccessToken, expires_in: expiresIn } = await EnvoyPluginAPI.loginAsPlugin();
|
|
45
|
+
accessToken = rawAccessToken;
|
|
46
|
+
threshold = now + (expiresIn * 1000) - (1000 * 60 * 10);
|
|
47
|
+
}
|
|
48
|
+
const envoyRequest = req as EnvoyRequest;
|
|
49
|
+
const envoyResponse = res as EnvoyResponse;
|
|
50
|
+
envoyRequest.envoy = new EnvoyPluginSDK(envoyRequest.body, envoyRequest[VERIFIED], accessToken);
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Respond with "ongoing" for long jobs.
|
|
54
|
+
*/
|
|
55
|
+
envoyResponse.sendOngoing = (message = '', debugInfo: unknown = {}) => {
|
|
56
|
+
envoyResponse.statusCode = HttpStatus.ONGOING;
|
|
57
|
+
envoyResponse.setHeader('Content-Type', 'application/json');
|
|
58
|
+
envoyResponse.end(JSON.stringify({ message, debugInfo }));
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Respond with "ignored" if no action will be performed.
|
|
63
|
+
*/
|
|
64
|
+
envoyResponse.sendIgnored = (message = '', debugInfo: unknown = {}, ...attachments: Array<EnvoyPluginJobAttachment>) => {
|
|
65
|
+
envoyResponse.statusCode = HttpStatus.IGNORED;
|
|
66
|
+
envoyResponse.setHeader('Content-Type', 'application/json');
|
|
67
|
+
envoyResponse.end(JSON.stringify({ message, debugInfo, attachments }));
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Respond with "failed" in case of errors.
|
|
72
|
+
*/
|
|
73
|
+
envoyResponse.sendFailed = (message = '', debugInfo: unknown = {}, ...attachments: Array<EnvoyPluginJobAttachment>) => {
|
|
74
|
+
envoyResponse.statusCode = HttpStatus.FAILED;
|
|
75
|
+
envoyResponse.setHeader('Content-Type', 'application/json');
|
|
76
|
+
envoyResponse.end(JSON.stringify({ message, debugInfo, attachments }));
|
|
77
|
+
};
|
|
78
|
+
next();
|
|
79
|
+
} catch (error) {
|
|
80
|
+
next(error);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Catches errors and sets the proper status code.
|
|
88
|
+
*
|
|
89
|
+
* @category Middleware
|
|
90
|
+
*/
|
|
91
|
+
export function errorMiddleware(onError: (err: Error) => void = () => {}): ErrorRequestHandler {
|
|
92
|
+
return (err: Error, req: Request, res: Response, next: NextFunction): void => {
|
|
93
|
+
onError(err);
|
|
94
|
+
if (res.headersSent) {
|
|
95
|
+
return next(err);
|
|
96
|
+
}
|
|
97
|
+
res.statusCode = HttpStatus.UNEXPECTED_FAILURE;
|
|
98
|
+
res.setHeader('Content-Type', 'application/json');
|
|
99
|
+
res.end(JSON.stringify({ message: err.message }));
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import jwt, { SignOptions, Algorithm, VerifyOptions } from 'jsonwebtoken';
|
|
2
|
+
import { jwtSecret } from '../constants';
|
|
3
|
+
|
|
4
|
+
export type EnvoyJWTAlgorithm = Algorithm;
|
|
5
|
+
export type EnvoyJWTDecodeOptions = VerifyOptions;
|
|
6
|
+
/**
|
|
7
|
+
* Helper to encode and decode JWTs.
|
|
8
|
+
*
|
|
9
|
+
* @category Helper
|
|
10
|
+
* @category Request Object
|
|
11
|
+
*/
|
|
12
|
+
export default class EnvoyJWT {
|
|
13
|
+
private secret: string;
|
|
14
|
+
|
|
15
|
+
private algorithm: Algorithm;
|
|
16
|
+
|
|
17
|
+
constructor(secret = jwtSecret, algorithm: EnvoyJWTAlgorithm = 'HS256') {
|
|
18
|
+
if (!secret) {
|
|
19
|
+
throw new Error('JWT secret missing. Have you set the `JWT_SECRET` environment variable?');
|
|
20
|
+
}
|
|
21
|
+
this.secret = secret;
|
|
22
|
+
this.algorithm = algorithm;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
encode(
|
|
26
|
+
subject: string | number | null,
|
|
27
|
+
expiresIn: string | number | null,
|
|
28
|
+
payload: Record<string, unknown> = {},
|
|
29
|
+
): string {
|
|
30
|
+
const { secret, algorithm } = this;
|
|
31
|
+
const options: SignOptions = { algorithm };
|
|
32
|
+
if (subject) {
|
|
33
|
+
options.subject = `${subject}`;
|
|
34
|
+
}
|
|
35
|
+
if (expiresIn) {
|
|
36
|
+
options.expiresIn = expiresIn;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return jwt.sign(payload, secret, options);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
decode(token: string, options: EnvoyJWTDecodeOptions = {}): Record<string, unknown> {
|
|
43
|
+
const { secret, algorithm } = this;
|
|
44
|
+
return jwt.verify(token, secret, {
|
|
45
|
+
ignoreExpiration: false,
|
|
46
|
+
ignoreNotBefore: false,
|
|
47
|
+
...options,
|
|
48
|
+
algorithms: [algorithm], // force the algorithm
|
|
49
|
+
}) as Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import crypto, { BinaryToTextEncoding } from 'crypto';
|
|
2
|
+
import { Request } from 'express';
|
|
3
|
+
import { envoyClientSecret } from '../constants';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @category Helper
|
|
7
|
+
*/
|
|
8
|
+
export type EnvoySignatureVerifierOptions = {
|
|
9
|
+
algorithm: 'sha256' | string,
|
|
10
|
+
encoding: BinaryToTextEncoding,
|
|
11
|
+
secret: string,
|
|
12
|
+
header: 'x-envoy-signature' | string,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const defaultOptions: EnvoySignatureVerifierOptions = {
|
|
16
|
+
algorithm: 'sha256',
|
|
17
|
+
encoding: 'base64',
|
|
18
|
+
secret: envoyClientSecret,
|
|
19
|
+
header: 'x-envoy-signature',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Verifies that a request is coming from Envoy.
|
|
24
|
+
*
|
|
25
|
+
* @category Helper
|
|
26
|
+
*/
|
|
27
|
+
export default class EnvoySignatureVerifier {
|
|
28
|
+
private readonly options: EnvoySignatureVerifierOptions;
|
|
29
|
+
|
|
30
|
+
constructor(options: EnvoySignatureVerifierOptions = defaultOptions) {
|
|
31
|
+
this.options = { ...defaultOptions, ...options };
|
|
32
|
+
|
|
33
|
+
if (!this.options.secret) {
|
|
34
|
+
throw new Error('No client secret found in the ENVOY_CLIENT_SECRET environment variable.');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Verifies that the signature provided matches the request body.
|
|
40
|
+
*/
|
|
41
|
+
verify(req: Request, rawBody: Buffer): boolean {
|
|
42
|
+
const {
|
|
43
|
+
algorithm,
|
|
44
|
+
encoding,
|
|
45
|
+
secret,
|
|
46
|
+
header,
|
|
47
|
+
} = this.options;
|
|
48
|
+
|
|
49
|
+
if (!req.headers[header]) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
const receivedDigest = req.headers[header] as string;
|
|
53
|
+
const computedHmac = crypto.createHmac(algorithm, secret);
|
|
54
|
+
computedHmac.update(rawBody);
|
|
55
|
+
|
|
56
|
+
return crypto.timingSafeEqual(
|
|
57
|
+
Buffer.from(receivedDigest),
|
|
58
|
+
Buffer.from(computedHmac.digest(encoding)),
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import axios, { AxiosError, AxiosHeaders, AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { ensureError } from './errorHandling';
|
|
3
|
+
|
|
4
|
+
export function sanitizeAxiosError(error: unknown): Error {
|
|
5
|
+
if (!axios.isAxiosError(error)) {
|
|
6
|
+
return ensureError(error);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const safeError = new AxiosError(
|
|
10
|
+
error.message,
|
|
11
|
+
error.code,
|
|
12
|
+
{
|
|
13
|
+
url: error.config?.url,
|
|
14
|
+
method: error.config?.method,
|
|
15
|
+
baseURL: error.config?.baseURL,
|
|
16
|
+
headers: new AxiosHeaders(),
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
url: error.request?.url,
|
|
20
|
+
method: error.request?.method,
|
|
21
|
+
baseURL: error.request?.baseURL,
|
|
22
|
+
data: error.request?.data,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
data: error.response?.data,
|
|
26
|
+
status: error.response?.status ?? 0,
|
|
27
|
+
statusText: error.response?.statusText ?? '',
|
|
28
|
+
headers: new AxiosHeaders(),
|
|
29
|
+
config: {
|
|
30
|
+
headers: new AxiosHeaders(),
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
safeError.stack = error.stack;
|
|
35
|
+
return safeError;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function createAxiosClient(config?: AxiosRequestConfig | undefined): AxiosInstance {
|
|
39
|
+
const client = axios.create(config);
|
|
40
|
+
client.interceptors.response.use(
|
|
41
|
+
(response) => response,
|
|
42
|
+
(error) => Promise.reject(sanitizeAxiosError(error)),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return client;
|
|
46
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function ensureError(value: unknown): Error {
|
|
2
|
+
if (value instanceof Error) {
|
|
3
|
+
return value;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
let stringified = '[Unable to stringify the thrown value]';
|
|
7
|
+
try {
|
|
8
|
+
stringified = JSON.stringify(value);
|
|
9
|
+
} catch {
|
|
10
|
+
// ignore
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const error = new Error(`This value was thrown as is, not through an Error: ${stringified}`);
|
|
14
|
+
return error;
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import JSONAPIData from './JSONAPIData';
|
|
2
|
+
|
|
3
|
+
export default interface JSONAPIModel<Attributes, Relationships extends string, Type = string, ID = string> extends JSONAPIData<Type, ID> {
|
|
4
|
+
attributes: Attributes;
|
|
5
|
+
relationships: {
|
|
6
|
+
[key in Relationships]: {
|
|
7
|
+
data: JSONAPIData & Array<JSONAPIData>
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import JSONAPIFilterParams from './JSONAPIFilterParams';
|
|
2
|
+
|
|
3
|
+
export default interface JSONAPIPaginationParams<FilterFields, SortFields extends string>
|
|
4
|
+
extends JSONAPIFilterParams<FilterFields> {
|
|
5
|
+
|
|
6
|
+
page?: {
|
|
7
|
+
offset?: number;
|
|
8
|
+
limit?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
sort?: SortFields;
|
|
12
|
+
}
|
package/.eslintrc.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
env: {
|
|
3
|
-
commonjs: true,
|
|
4
|
-
es6: true,
|
|
5
|
-
node: true,
|
|
6
|
-
},
|
|
7
|
-
extends: 'airbnb-base',
|
|
8
|
-
globals: {
|
|
9
|
-
Atomics: 'readonly',
|
|
10
|
-
SharedArrayBuffer: 'readonly',
|
|
11
|
-
},
|
|
12
|
-
parserOptions: {
|
|
13
|
-
ecmaVersion: 2018,
|
|
14
|
-
},
|
|
15
|
-
rules: {
|
|
16
|
-
'no-trailing-spaces': 'off',
|
|
17
|
-
'padded-blocks': 'off',
|
|
18
|
-
'no-console': 'off',
|
|
19
|
-
'arrow-parens': 'off',
|
|
20
|
-
'no-return-assign': 'off',
|
|
21
|
-
'no-empty': 'off',
|
|
22
|
-
'consistent-return': 'off',
|
|
23
|
-
'no-shadow': 'off',
|
|
24
|
-
'no-plusplus': 'off',
|
|
25
|
-
'no-case-declarations': 'off',
|
|
26
|
-
'class-methods-use-this': 'off'
|
|
27
|
-
},
|
|
28
|
-
overrides: [
|
|
29
|
-
{
|
|
30
|
-
files: [
|
|
31
|
-
'tests/**/*.test.js'
|
|
32
|
-
],
|
|
33
|
-
env: {
|
|
34
|
-
mocha: true
|
|
35
|
-
},
|
|
36
|
-
rules: {
|
|
37
|
-
'prefer-arrow-callback': 'off',
|
|
38
|
-
'func-names': 'off',
|
|
39
|
-
'no-loop-func': 'off',
|
|
40
|
-
'no-await-in-loop': 'off',
|
|
41
|
-
'no-restricted-syntax': 'off',
|
|
42
|
-
'max-len': 'off'
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
]
|
|
46
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
name: Node.js Package
|
|
2
|
-
on:
|
|
3
|
-
release:
|
|
4
|
-
types: [created]
|
|
5
|
-
jobs:
|
|
6
|
-
build:
|
|
7
|
-
runs-on: ubuntu-latest
|
|
8
|
-
steps:
|
|
9
|
-
- uses: actions/checkout@v2
|
|
10
|
-
|
|
11
|
-
- uses: actions/setup-node@v2
|
|
12
|
-
with:
|
|
13
|
-
registry-url: "https://registry.npmjs.org"
|
|
14
|
-
|
|
15
|
-
- name: Get Node.js version
|
|
16
|
-
id: node-version
|
|
17
|
-
run: |
|
|
18
|
-
echo "::set-output name=version::$(node --version)"
|
|
19
|
-
- name: Cache node_modules
|
|
20
|
-
uses: actions/cache@v2
|
|
21
|
-
id: cache-node-modules
|
|
22
|
-
with:
|
|
23
|
-
path: node_modules
|
|
24
|
-
key: v1-node-${{ steps.node-version.outputs.version }}-modules-${{ hashFiles('package-lock.json') }}
|
|
25
|
-
|
|
26
|
-
- name: Install dependencies
|
|
27
|
-
run: npm install
|
|
28
|
-
if: steps.cache-node-modules.outputs.cache-hit != 'true'
|
|
29
|
-
env:
|
|
30
|
-
NODE_AUTH_TOKEN: ${{ secrets.ENVOYBOT_PERSONAL_ACCESS_TOKEN }}
|
|
31
|
-
|
|
32
|
-
- run: npm publish --access public
|
|
33
|
-
env:
|
|
34
|
-
NODE_AUTH_TOKEN: ${{ secrets.ENVOY_NPM_AUTOMATION_TOKEN }}
|
|
35
|
-
|
|
36
|
-
# Setup .npmrc file to publish to npm
|
|
37
|
-
- uses: actions/setup-node@v2
|
|
38
|
-
with:
|
|
39
|
-
registry-url: "https://npm.pkg.github.com"
|
|
40
|
-
|
|
41
|
-
- run: npm publish
|
|
42
|
-
env:
|
|
43
|
-
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
package/asynchandler.md
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: >-
|
|
3
|
-
Use this wrapper around your `async` endpoint handlers to catch Promise-based
|
|
4
|
-
errors.
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# asyncHandler
|
|
8
|
-
|
|
9
|
-
## Example
|
|
10
|
-
|
|
11
|
-
```javascript
|
|
12
|
-
const express = require('express');
|
|
13
|
-
const { middleware, asyncHandler } = require('envoy-integrations-sdk-nodejs');
|
|
14
|
-
|
|
15
|
-
const app = express();
|
|
16
|
-
app.use(middleware());
|
|
17
|
-
app.post('/foo', asyncHandler(async (req, res) => {
|
|
18
|
-
await somePromiseThatThrowsAnError();
|
|
19
|
-
}));
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Functions
|
|
23
|
-
|
|
24
|
-
### asyncHandler\(handler\) ⇒ `connectHandler`
|
|
25
|
-
|
|
26
|
-
Returns a wrapped handler that catches Promise-based errors.
|
|
27
|
-
|
|
28
|
-
**Kind**: global function
|
|
29
|
-
|
|
30
|
-
| Param | Type |
|
|
31
|
-
| :--- | :--- |
|
|
32
|
-
| handler | `connectHandler` |
|
|
33
|
-
|
|
34
|
-
### Related Functions and Classes
|
|
35
|
-
|
|
36
|
-
### connectHandler : `function`
|
|
37
|
-
|
|
38
|
-
Express/connect middleware.
|
|
39
|
-
|
|
40
|
-
**Kind**: global typedef
|
|
41
|
-
|
|
42
|
-
| Param | Type |
|
|
43
|
-
| :--- | :--- |
|
|
44
|
-
| req | [http://expressjs.com/en/4x/api.html\#req](http://expressjs.com/en/4x/api.html#req) |
|
|
45
|
-
| res | [http://expressjs.com/en/4x/api.html\#res](http://expressjs.com/en/4x/api.html#res) |
|
|
46
|
-
|