@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
package/lib/axios.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
const { AxiosError } = require('axios');
|
|
2
|
-
const axios = require('axios');
|
|
3
|
-
|
|
4
|
-
function createAxiosClient(config) {
|
|
5
|
-
const client = axios.create(config);
|
|
6
|
-
client.interceptors.response.use(
|
|
7
|
-
(response) => {
|
|
8
|
-
return response
|
|
9
|
-
},
|
|
10
|
-
(error) => {
|
|
11
|
-
const safeError = {
|
|
12
|
-
code: error.code,
|
|
13
|
-
response: {
|
|
14
|
-
code: error.response?.code,
|
|
15
|
-
status: error.response?.status,
|
|
16
|
-
statusText: error.response?.statusText,
|
|
17
|
-
data: error.response?.data,
|
|
18
|
-
},
|
|
19
|
-
message: error.message,
|
|
20
|
-
name: error.name,
|
|
21
|
-
baseURL: error.request?.baseURL ?? error.config?.baseURL,
|
|
22
|
-
url: error.request?.url ?? error.config?.url,
|
|
23
|
-
method: error.request?.method ?? error.config?.method,
|
|
24
|
-
stack: error.stack,
|
|
25
|
-
data: error.data,
|
|
26
|
-
}
|
|
27
|
-
return Promise.reject(safeError);
|
|
28
|
-
},
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
return client;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
module.exports = createAxiosClient;
|
package/lib/errorMiddleware.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
const HttpStatus = require('./HttpStatus');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param {Function} onError
|
|
6
|
-
* @returns {Function}
|
|
7
|
-
*/
|
|
8
|
-
function errorMiddleware(onError = () => {}) {
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @param err
|
|
12
|
-
* @param req
|
|
13
|
-
* @param res
|
|
14
|
-
* @param next
|
|
15
|
-
*/
|
|
16
|
-
return (err, req, res, next) => {
|
|
17
|
-
onError(err);
|
|
18
|
-
if (res.headersSent) {
|
|
19
|
-
return next(err);
|
|
20
|
-
}
|
|
21
|
-
res.statusCode = HttpStatus.UNEXPECTED_FAILURE;
|
|
22
|
-
res.setHeader('Content-Type', 'application/json');
|
|
23
|
-
res.end(JSON.stringify({ message: err.message }));
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
module.exports = errorMiddleware;
|
package/lib/middleware.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
const bodyParser = require('body-parser');
|
|
2
|
-
const EnvoyAPI = require('./EnvoyAPI');
|
|
3
|
-
const EnvoyPluginSDK = require('./EnvoyPluginSDK');
|
|
4
|
-
const EnvoySignatureVerifier = require('./EnvoySignatureVerifier');
|
|
5
|
-
const HttpStatus = require('./HttpStatus');
|
|
6
|
-
|
|
7
|
-
const VERIFIED = Symbol('verified');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Express/connect middleware.
|
|
11
|
-
*
|
|
12
|
-
* @callback connectMiddleware
|
|
13
|
-
* @param req
|
|
14
|
-
* @param res
|
|
15
|
-
* @param {Function} next
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @typedef {Object} EnvoyRequest
|
|
20
|
-
* @property {EnvoyPluginSDK} envoy - the SDK
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @typedef {Object} EnvoyResponse
|
|
25
|
-
* @property {Function} sendOngoing
|
|
26
|
-
* @property {Function} sendIgnored
|
|
27
|
-
* @property {Function} sendFailed
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Returns an instance of bodyParser.json,
|
|
32
|
-
* which also verifies that the request came from Envoy.
|
|
33
|
-
*
|
|
34
|
-
* @param {SignatureVerifierOptions} [options]
|
|
35
|
-
* @returns {connectMiddleware}
|
|
36
|
-
*/
|
|
37
|
-
function middleware(options) {
|
|
38
|
-
|
|
39
|
-
const signatureVerifier = new EnvoySignatureVerifier(options);
|
|
40
|
-
const verify = (req, res, rawBody) => {
|
|
41
|
-
|
|
42
|
-
req[VERIFIED] = signatureVerifier.verify(req, rawBody);
|
|
43
|
-
};
|
|
44
|
-
const json = bodyParser.json({ verify });
|
|
45
|
-
let accessToken = null;
|
|
46
|
-
let threshold = 0;
|
|
47
|
-
|
|
48
|
-
return (req, res, next) => {
|
|
49
|
-
|
|
50
|
-
json(req, res, async err => {
|
|
51
|
-
|
|
52
|
-
if (err) {
|
|
53
|
-
return next(err);
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
const now = Date.now();
|
|
57
|
-
if (now > threshold) {
|
|
58
|
-
const {
|
|
59
|
-
access_token: rawAccessToken,
|
|
60
|
-
expires_in: expiresIn,
|
|
61
|
-
} = await EnvoyAPI.login();
|
|
62
|
-
accessToken = rawAccessToken;
|
|
63
|
-
threshold = now + (expiresIn * 1000) - (1000 * 60 * 10);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* @type {EnvoyPluginSDK}
|
|
68
|
-
*/
|
|
69
|
-
req.envoy = new EnvoyPluginSDK(req.body, req[VERIFIED], accessToken);
|
|
70
|
-
/**
|
|
71
|
-
* @param {object} [data]
|
|
72
|
-
*/
|
|
73
|
-
res.sendOngoing = (data = {}) => {
|
|
74
|
-
res.statusCode = HttpStatus.ONGOING;
|
|
75
|
-
res.setHeader('Content-Type', 'application/json');
|
|
76
|
-
res.end(JSON.stringify(data));
|
|
77
|
-
};
|
|
78
|
-
/**
|
|
79
|
-
* @param {string} [message]
|
|
80
|
-
* @param {object} [data]
|
|
81
|
-
*/
|
|
82
|
-
res.sendIgnored = (message = '', data = {}) => {
|
|
83
|
-
if (message && data.message) {
|
|
84
|
-
console.warn('Data to be sent already has a message.');
|
|
85
|
-
}
|
|
86
|
-
res.statusCode = HttpStatus.IGNORED;
|
|
87
|
-
res.setHeader('Content-Type', 'application/json');
|
|
88
|
-
res.end(JSON.stringify(Object.assign({ message }, data)));
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* @param {string} [message]
|
|
92
|
-
* @param {object} [data]
|
|
93
|
-
*/
|
|
94
|
-
res.sendFailed = (message = '', data = {}) => {
|
|
95
|
-
if (message && data.message) {
|
|
96
|
-
console.warn('Data to be sent already has a message.');
|
|
97
|
-
}
|
|
98
|
-
res.statusCode = HttpStatus.FAILED;
|
|
99
|
-
res.setHeader('Content-Type', 'application/json');
|
|
100
|
-
res.end(JSON.stringify(Object.assign({ message }, data)));
|
|
101
|
-
};
|
|
102
|
-
next();
|
|
103
|
-
} catch (err) {
|
|
104
|
-
next(err);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
module.exports = middleware;
|
package/middleware.md
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: Use this middleware to automatically and safely include Envoy in your plugin.
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# middleware
|
|
6
|
-
|
|
7
|
-
## Example
|
|
8
|
-
|
|
9
|
-
```javascript
|
|
10
|
-
const express = require('express');
|
|
11
|
-
const { middleware } = require('envoy-integrations-sdk-nodejs');
|
|
12
|
-
|
|
13
|
-
const app = express();
|
|
14
|
-
app.use(middleware());
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Functions
|
|
18
|
-
|
|
19
|
-
### middleware\(\[options\]\) ⇒ `connectMiddleware`
|
|
20
|
-
|
|
21
|
-
Returns an instance of `bodyParser.json`, which also verifies that the request came from Envoy. It also attaches an instance of `EnvoyPluginSDK` attached to the `req` object, accessible at `req.envoy`.
|
|
22
|
-
|
|
23
|
-
**Kind**: global function
|
|
24
|
-
|
|
25
|
-
| Param | Type |
|
|
26
|
-
| :--- | :--- |
|
|
27
|
-
| \[options\] | `SignatureVerifierOptions` |
|
|
28
|
-
|
|
29
|
-
### Related Functions and Classes
|
|
30
|
-
|
|
31
|
-
### connectMiddleware : `function`
|
|
32
|
-
|
|
33
|
-
Express/connect middleware.
|
|
34
|
-
|
|
35
|
-
**Kind**: global typedef
|
|
36
|
-
|
|
37
|
-
| Param | Type |
|
|
38
|
-
| :--- | :--- |
|
|
39
|
-
| req | [http://expressjs.com/en/4x/api.html\#req](http://expressjs.com/en/4x/api.html#req) |
|
|
40
|
-
| res | [http://expressjs.com/en/4x/api.html\#res](http://expressjs.com/en/4x/api.html#res) |
|
|
41
|
-
| next | `function` |
|
|
42
|
-
|
|
43
|
-
### SignatureVerifierOptions : `Object`
|
|
44
|
-
|
|
45
|
-
**Properties**
|
|
46
|
-
|
|
47
|
-
| Name | Type | Default |
|
|
48
|
-
| :--- | :--- | :--- |
|
|
49
|
-
| algorithm | `string` | `"sha256"` |
|
|
50
|
-
| encoding | `string` | `"base64"` |
|
|
51
|
-
| secret | `string` | `process.env.ENVOY_CLIENT_SECRET` |
|
|
52
|
-
| header | `string` | `"x-envoy-signature"` |
|
|
53
|
-
|
package/test/axios.test.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
const axios = require('axios');
|
|
2
|
-
const createClient = require('../lib/axios');
|
|
3
|
-
|
|
4
|
-
describe('axios', () => {
|
|
5
|
-
it('default client should leak credentials in AxiosError', async () => {
|
|
6
|
-
const client = axios.create({
|
|
7
|
-
headers: {
|
|
8
|
-
Authorization: 'Bearer 1234',
|
|
9
|
-
},
|
|
10
|
-
proxy: {
|
|
11
|
-
host: 'localhost',
|
|
12
|
-
auth: {
|
|
13
|
-
username: 'myWhackyUsername',
|
|
14
|
-
password: 'myWhackyPassword',
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
try {
|
|
19
|
-
await client.get('http://localhost:3000/axios-error');
|
|
20
|
-
} catch (error) {
|
|
21
|
-
expect(error.config).toBeDefined();
|
|
22
|
-
const errorStr = JSON.stringify(error);
|
|
23
|
-
expect(errorStr).toContain('Bearer 1234');
|
|
24
|
-
expect(errorStr).toContain('myWhackyUsername');
|
|
25
|
-
expect(errorStr).toContain('myWhackyPassword');
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should sanitize AxiosError response', async () => {
|
|
30
|
-
const client = createClient({
|
|
31
|
-
headers: {
|
|
32
|
-
Authorization: 'Bearer 1234',
|
|
33
|
-
},
|
|
34
|
-
proxy: {
|
|
35
|
-
host: 'localhost',
|
|
36
|
-
auth: {
|
|
37
|
-
username: 'myWhackyUsername',
|
|
38
|
-
password: 'myWhackyPassword',
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
try {
|
|
43
|
-
await client.get('http://localhost:3000/axios-error');
|
|
44
|
-
} catch (error) {
|
|
45
|
-
expect(error.config).toBeUndefined();
|
|
46
|
-
expect(error.code).toBe('ECONNREFUSED');
|
|
47
|
-
expect(error.message).toBe('connect ECONNREFUSED 127.0.0.1:80');
|
|
48
|
-
expect(error.name).toBe('Error');
|
|
49
|
-
expect(error.url).toBe('http://localhost:3000/axios-error');
|
|
50
|
-
expect(error.method).toBe('get');
|
|
51
|
-
const errorStr = JSON.stringify(error);
|
|
52
|
-
expect(errorStr).not.toContain('Bearer 1234');
|
|
53
|
-
expect(errorStr).not.toContain('myWhackyUsername');
|
|
54
|
-
expect(errorStr).not.toContain('myWhackyPassword');
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
});
|
package/test/promises.test.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
const request = require('request-promise-native');
|
|
2
|
-
const EnvoyAPI = require('../lib/EnvoyAPI');
|
|
3
|
-
|
|
4
|
-
describe('request-promise-native', () => {
|
|
5
|
-
it('default client should leak credentials in error', async () => {
|
|
6
|
-
const client = request.defaults({
|
|
7
|
-
headers: {
|
|
8
|
-
Authorization: 'Bearer 1234',
|
|
9
|
-
},
|
|
10
|
-
});
|
|
11
|
-
try {
|
|
12
|
-
await client('http://localhost:3000/axios-error');
|
|
13
|
-
} catch (error) {
|
|
14
|
-
expect(error.options).toBeDefined();
|
|
15
|
-
const errorStr = JSON.stringify(error);
|
|
16
|
-
expect(errorStr).toContain('Bearer 1234');
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should sanitize requests error response', async () => {
|
|
21
|
-
const client = request.defaults({
|
|
22
|
-
headers: {
|
|
23
|
-
Authorization: 'Bearer 1234',
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
try {
|
|
27
|
-
await client('http://localhost:3000/axios-error').catch(EnvoyAPI.safeRequestsError);
|
|
28
|
-
} catch (error) {
|
|
29
|
-
expect(error.options).toBeUndefined();
|
|
30
|
-
expect(error.message).toBe('Error: connect ECONNREFUSED 127.0.0.1:3000');
|
|
31
|
-
expect(error.name).toBe('RequestError');
|
|
32
|
-
const errorStr = JSON.stringify(error);
|
|
33
|
-
expect(errorStr).not.toContain('Bearer 1234');
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should return rejected promise and leak credentials', () => {
|
|
38
|
-
const client = request.defaults({
|
|
39
|
-
headers: {
|
|
40
|
-
Authorization: 'Bearer 1234',
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
const response = client('http://localhost:3000/axios-error');
|
|
44
|
-
response.then((data) => {
|
|
45
|
-
expect(false).toBe(true);
|
|
46
|
-
}).catch((error) => {
|
|
47
|
-
expect(error.options).toBeDefined();
|
|
48
|
-
const errorStr = JSON.stringify(error);
|
|
49
|
-
expect(errorStr).toContain('Bearer 1234');
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('should return rejected promise', () => {
|
|
54
|
-
const client = request.defaults({
|
|
55
|
-
headers: {
|
|
56
|
-
Authorization: 'Bearer 1234',
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
const response = client('http://localhost:3000/axios-error').catch(EnvoyAPI.safeRequestsError);
|
|
60
|
-
response.then((data) => {
|
|
61
|
-
expect(false).toBe(true);
|
|
62
|
-
}).catch((error) => {
|
|
63
|
-
expect(error.message).toBe('Error: connect ECONNREFUSED 127.0.0.1:3000');
|
|
64
|
-
expect(error.name).toBe('RequestError');
|
|
65
|
-
const errorStr = JSON.stringify(error);
|
|
66
|
-
expect(errorStr).not.toContain('Bearer 1234');
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('should make a successful request', async () => {
|
|
71
|
-
const response = await request('https://httpstat.us/200').catch(EnvoyAPI.safeRequestsError);
|
|
72
|
-
expect(response).toBe('200 OK');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('should throw an error', async () => {
|
|
76
|
-
try {
|
|
77
|
-
await request('https://httpstat.us/500').catch(EnvoyAPI.safeRequestsError);
|
|
78
|
-
} catch (error) {
|
|
79
|
-
expect(error.message).toBe('500 - "500 Internal Server Error"');
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
});
|