@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,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
18
|
+
var constants_1 = require("../constants");
|
|
19
|
+
/**
|
|
20
|
+
* Helper to encode and decode JWTs.
|
|
21
|
+
*
|
|
22
|
+
* @category Helper
|
|
23
|
+
* @category Request Object
|
|
24
|
+
*/
|
|
25
|
+
var EnvoyJWT = /** @class */ (function () {
|
|
26
|
+
function EnvoyJWT(secret, algorithm) {
|
|
27
|
+
if (secret === void 0) { secret = constants_1.jwtSecret; }
|
|
28
|
+
if (algorithm === void 0) { algorithm = 'HS256'; }
|
|
29
|
+
if (!secret) {
|
|
30
|
+
throw new Error('JWT secret missing. Have you set the `JWT_SECRET` environment variable?');
|
|
31
|
+
}
|
|
32
|
+
this.secret = secret;
|
|
33
|
+
this.algorithm = algorithm;
|
|
34
|
+
}
|
|
35
|
+
EnvoyJWT.prototype.encode = function (subject, expiresIn, payload) {
|
|
36
|
+
if (payload === void 0) { payload = {}; }
|
|
37
|
+
var _a = this, secret = _a.secret, algorithm = _a.algorithm;
|
|
38
|
+
var options = { algorithm: algorithm };
|
|
39
|
+
if (subject) {
|
|
40
|
+
options.subject = "" + subject;
|
|
41
|
+
}
|
|
42
|
+
if (expiresIn) {
|
|
43
|
+
options.expiresIn = expiresIn;
|
|
44
|
+
}
|
|
45
|
+
return jsonwebtoken_1.default.sign(payload, secret, options);
|
|
46
|
+
};
|
|
47
|
+
EnvoyJWT.prototype.decode = function (token, options) {
|
|
48
|
+
if (options === void 0) { options = {}; }
|
|
49
|
+
var _a = this, secret = _a.secret, algorithm = _a.algorithm;
|
|
50
|
+
return jsonwebtoken_1.default.verify(token, secret, __assign(__assign({ ignoreExpiration: false, ignoreNotBefore: false }, options), { algorithms: [algorithm] }));
|
|
51
|
+
};
|
|
52
|
+
return EnvoyJWT;
|
|
53
|
+
}());
|
|
54
|
+
exports.default = EnvoyJWT;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { BinaryToTextEncoding } from 'crypto';
|
|
3
|
+
import { Request } from 'express';
|
|
4
|
+
/**
|
|
5
|
+
* @category Helper
|
|
6
|
+
*/
|
|
7
|
+
export declare type EnvoySignatureVerifierOptions = {
|
|
8
|
+
algorithm: 'sha256' | string;
|
|
9
|
+
encoding: BinaryToTextEncoding;
|
|
10
|
+
secret: string;
|
|
11
|
+
header: 'x-envoy-signature' | string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Verifies that a request is coming from Envoy.
|
|
15
|
+
*
|
|
16
|
+
* @category Helper
|
|
17
|
+
*/
|
|
18
|
+
export default class EnvoySignatureVerifier {
|
|
19
|
+
private readonly options;
|
|
20
|
+
constructor(options?: EnvoySignatureVerifierOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Verifies that the signature provided matches the request body.
|
|
23
|
+
*/
|
|
24
|
+
verify(req: Request, rawBody: Buffer): boolean;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=EnvoySignatureVerifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnvoySignatureVerifier.d.ts","sourceRoot":"","sources":["../../src/util/EnvoySignatureVerifier.ts"],"names":[],"mappings":";AAAA,OAAe,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGlC;;GAEG;AACH,oBAAY,6BAA6B,GAAG;IAC1C,SAAS,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC7B,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAAC;CACtC,CAAC;AASF;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,sBAAsB;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgC;gBAE5C,OAAO,GAAE,6BAA8C;IAQnE;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO;CAoB/C"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
var crypto_1 = __importDefault(require("crypto"));
|
|
18
|
+
var constants_1 = require("../constants");
|
|
19
|
+
var defaultOptions = {
|
|
20
|
+
algorithm: 'sha256',
|
|
21
|
+
encoding: 'base64',
|
|
22
|
+
secret: constants_1.envoyClientSecret,
|
|
23
|
+
header: 'x-envoy-signature',
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Verifies that a request is coming from Envoy.
|
|
27
|
+
*
|
|
28
|
+
* @category Helper
|
|
29
|
+
*/
|
|
30
|
+
var EnvoySignatureVerifier = /** @class */ (function () {
|
|
31
|
+
function EnvoySignatureVerifier(options) {
|
|
32
|
+
if (options === void 0) { options = defaultOptions; }
|
|
33
|
+
this.options = __assign(__assign({}, defaultOptions), options);
|
|
34
|
+
if (!this.options.secret) {
|
|
35
|
+
throw new Error('No client secret found in the ENVOY_CLIENT_SECRET environment variable.');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Verifies that the signature provided matches the request body.
|
|
40
|
+
*/
|
|
41
|
+
EnvoySignatureVerifier.prototype.verify = function (req, rawBody) {
|
|
42
|
+
var _a = this.options, algorithm = _a.algorithm, encoding = _a.encoding, secret = _a.secret, header = _a.header;
|
|
43
|
+
if (!req.headers[header]) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
var receivedDigest = req.headers[header];
|
|
47
|
+
var computedHmac = crypto_1.default.createHmac(algorithm, secret);
|
|
48
|
+
computedHmac.update(rawBody);
|
|
49
|
+
return crypto_1.default.timingSafeEqual(Buffer.from(receivedDigest), Buffer.from(computedHmac.digest(encoding)));
|
|
50
|
+
};
|
|
51
|
+
return EnvoySignatureVerifier;
|
|
52
|
+
}());
|
|
53
|
+
exports.default = EnvoySignatureVerifier;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
export declare function sanitizeAxiosError(error: unknown): Error;
|
|
3
|
+
export declare function createAxiosClient(config?: AxiosRequestConfig | undefined): AxiosInstance;
|
|
4
|
+
//# sourceMappingURL=axiosConstructor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"axiosConstructor.d.ts","sourceRoot":"","sources":["../../src/util/axiosConstructor.ts"],"names":[],"mappings":"AAAA,OAAc,EAA4B,aAAa,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAG3F,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAgCxD;AAED,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,SAAS,GAAG,aAAa,CAQxF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.createAxiosClient = exports.sanitizeAxiosError = void 0;
|
|
23
|
+
var axios_1 = __importStar(require("axios"));
|
|
24
|
+
var errorHandling_1 = require("./errorHandling");
|
|
25
|
+
function sanitizeAxiosError(error) {
|
|
26
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
27
|
+
if (!axios_1.default.isAxiosError(error)) {
|
|
28
|
+
return errorHandling_1.ensureError(error);
|
|
29
|
+
}
|
|
30
|
+
var safeError = new axios_1.AxiosError(error.message, error.code, {
|
|
31
|
+
url: (_a = error.config) === null || _a === void 0 ? void 0 : _a.url,
|
|
32
|
+
method: (_b = error.config) === null || _b === void 0 ? void 0 : _b.method,
|
|
33
|
+
baseURL: (_c = error.config) === null || _c === void 0 ? void 0 : _c.baseURL,
|
|
34
|
+
headers: new axios_1.AxiosHeaders(),
|
|
35
|
+
}, {
|
|
36
|
+
url: (_d = error.request) === null || _d === void 0 ? void 0 : _d.url,
|
|
37
|
+
method: (_e = error.request) === null || _e === void 0 ? void 0 : _e.method,
|
|
38
|
+
baseURL: (_f = error.request) === null || _f === void 0 ? void 0 : _f.baseURL,
|
|
39
|
+
data: (_g = error.request) === null || _g === void 0 ? void 0 : _g.data,
|
|
40
|
+
}, {
|
|
41
|
+
data: (_h = error.response) === null || _h === void 0 ? void 0 : _h.data,
|
|
42
|
+
status: (_k = (_j = error.response) === null || _j === void 0 ? void 0 : _j.status) !== null && _k !== void 0 ? _k : 0,
|
|
43
|
+
statusText: (_m = (_l = error.response) === null || _l === void 0 ? void 0 : _l.statusText) !== null && _m !== void 0 ? _m : '',
|
|
44
|
+
headers: new axios_1.AxiosHeaders(),
|
|
45
|
+
config: {
|
|
46
|
+
headers: new axios_1.AxiosHeaders(),
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
safeError.stack = error.stack;
|
|
50
|
+
return safeError;
|
|
51
|
+
}
|
|
52
|
+
exports.sanitizeAxiosError = sanitizeAxiosError;
|
|
53
|
+
function createAxiosClient(config) {
|
|
54
|
+
var client = axios_1.default.create(config);
|
|
55
|
+
client.interceptors.response.use(function (response) { return response; }, function (error) { return Promise.reject(sanitizeAxiosError(error)); });
|
|
56
|
+
return client;
|
|
57
|
+
}
|
|
58
|
+
exports.createAxiosClient = createAxiosClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorHandling.d.ts","sourceRoot":"","sources":["../../src/util/errorHandling.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAcjD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureError = void 0;
|
|
4
|
+
function ensureError(value) {
|
|
5
|
+
if (value instanceof Error) {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
var stringified = '[Unable to stringify the thrown value]';
|
|
9
|
+
try {
|
|
10
|
+
stringified = JSON.stringify(value);
|
|
11
|
+
}
|
|
12
|
+
catch (_a) {
|
|
13
|
+
// ignore
|
|
14
|
+
}
|
|
15
|
+
var error = new Error("This value was thrown as is, not through an Error: " + stringified);
|
|
16
|
+
return error;
|
|
17
|
+
}
|
|
18
|
+
exports.ensureError = ensureError;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JSONAPIData.d.ts","sourceRoot":"","sources":["../../../src/util/json-api/JSONAPIData.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,WAAW,WAAW,CAAC,IAAI,GAAG,MAAM,EAAE,EAAE,GAAG,MAAM;IAC7D,EAAE,EAAE,EAAE,CAAC;IACP,IAAI,EAAE,IAAI,CAAC;CACZ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JSONAPIFilterParams.d.ts","sourceRoot":"","sources":["../../../src/util/json-api/JSONAPIFilterParams.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,MAAM,CAAC,OAAO,WAAW,mBAAmB,CAAC,YAAY,CAAE,SAAQ,aAAa;IAC9E,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import JSONAPIData from './JSONAPIData';
|
|
2
|
+
export default interface JSONAPIModel<Attributes, Relationships extends string, Type = string, ID = string> extends JSONAPIData<Type, ID> {
|
|
3
|
+
attributes: Attributes;
|
|
4
|
+
relationships: {
|
|
5
|
+
[key in Relationships]: {
|
|
6
|
+
data: JSONAPIData & Array<JSONAPIData>;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=JSONAPIModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JSONAPIModel.d.ts","sourceRoot":"","sources":["../../../src/util/json-api/JSONAPIModel.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC,MAAM,CAAC,OAAO,WAAW,YAAY,CAAC,UAAU,EAAE,aAAa,SAAS,MAAM,EAAE,IAAI,GAAG,MAAM,EAAE,EAAE,GAAG,MAAM,CAAE,SAAQ,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC;IACvI,UAAU,EAAE,UAAU,CAAC;IACvB,aAAa,EAAE;SACZ,GAAG,IAAI,aAAa,GAAG;YACtB,IAAI,EAAE,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC,CAAA;SACvC;KACF,CAAA;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import JSONAPIFilterParams from './JSONAPIFilterParams';
|
|
2
|
+
export default interface JSONAPIPaginationParams<FilterFields, SortFields extends string> extends JSONAPIFilterParams<FilterFields> {
|
|
3
|
+
page?: {
|
|
4
|
+
offset?: number;
|
|
5
|
+
limit?: number;
|
|
6
|
+
};
|
|
7
|
+
sort?: SortFields;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=JSONAPIPaginationParams.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JSONAPIPaginationParams.d.ts","sourceRoot":"","sources":["../../../src/util/json-api/JSONAPIPaginationParams.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AAExD,MAAM,CAAC,OAAO,WAAW,uBAAuB,CAAC,YAAY,EAAE,UAAU,SAAS,MAAM,CACtF,SAAQ,mBAAmB,CAAC,YAAY,CAAC;IAEzC,IAAI,CAAC,EAAE;QACL,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAA;IAED,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JSONAPIParams.d.ts","sourceRoot":"","sources":["../../../src/util/json-api/JSONAPIParams.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,WAAW,aAAa;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JSONAPIResponse.d.ts","sourceRoot":"","sources":["../../../src/util/json-api/JSONAPIResponse.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,WAAW,eAAe,CAAC,KAAK;IAC5C,IAAI,EAAE,KAAK,CAAC;IACZ,QAAQ,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC1B,IAAI,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;CACtB"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envoy/envoy-integrations-sdk",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
3
|
+
"version": "2.0.2",
|
|
4
|
+
"description": "SDK for building Envoy integrations.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"directories": {
|
|
8
|
+
"lib": "src",
|
|
9
|
+
"doc": "docs"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/*.d.ts",
|
|
13
|
+
"dist/*.d.ts.map",
|
|
14
|
+
"dist",
|
|
15
|
+
"src"
|
|
16
|
+
],
|
|
6
17
|
"scripts": {
|
|
7
|
-
"test": "
|
|
18
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
19
|
+
"docs:generate": "typedoc",
|
|
20
|
+
"prepublishOnly": "tsc",
|
|
21
|
+
"compile": "tsc"
|
|
8
22
|
},
|
|
9
23
|
"repository": {
|
|
10
24
|
"type": "git",
|
|
@@ -17,22 +31,43 @@
|
|
|
17
31
|
},
|
|
18
32
|
"homepage": "https://github.com/envoy/envoy-integrations-sdk-nodejs#readme",
|
|
19
33
|
"dependencies": {
|
|
34
|
+
"@types/dotenv": "^8.2.0",
|
|
35
|
+
"@types/faker": "^5.5.6",
|
|
36
|
+
"@types/jsonwebtoken": "^9.0.0",
|
|
37
|
+
"@types/node": "^15.12.0",
|
|
38
|
+
"@types/qs": "^6.9.6",
|
|
20
39
|
"axios": "^1.4.0",
|
|
21
40
|
"body-parser": "^1.19.0",
|
|
22
|
-
"
|
|
41
|
+
"dataloader": "^2.0.0",
|
|
42
|
+
"dotenv-flow": "^3.2.0",
|
|
43
|
+
"factory.ts": "^0.5.2",
|
|
44
|
+
"faker": "^5.5.3",
|
|
23
45
|
"jsonwebtoken": "^9.0.0",
|
|
24
|
-
"
|
|
25
|
-
"
|
|
46
|
+
"lodash.ismatch": "^4.4.0",
|
|
47
|
+
"luxon": "^1.27.0",
|
|
48
|
+
"qs": "^6.10.1"
|
|
26
49
|
},
|
|
27
50
|
"devDependencies": {
|
|
51
|
+
"@types/dotenv-flow": "^3.1.1",
|
|
52
|
+
"@types/express": "^4.17.12",
|
|
53
|
+
"@types/lodash.ismatch": "^4.4.6",
|
|
54
|
+
"@types/luxon": "^1.27.0",
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "^4.26.0",
|
|
56
|
+
"@typescript-eslint/parser": "^4.26.0",
|
|
28
57
|
"chai": "^4.2.0",
|
|
29
|
-
"eslint": "^
|
|
30
|
-
"eslint-config-airbnb-
|
|
31
|
-
"eslint-plugin-import": "^2.
|
|
32
|
-
"jest": "^29.5.0",
|
|
58
|
+
"eslint": "^7.27.0",
|
|
59
|
+
"eslint-config-airbnb-typescript": "^12.3.1",
|
|
60
|
+
"eslint-plugin-import": "^2.23.4",
|
|
33
61
|
"jsdoc-to-markdown": "^5.0.0",
|
|
34
|
-
"mocha": "^
|
|
62
|
+
"mocha": "^6.1.4",
|
|
35
63
|
"proxyquire": "^2.1.0",
|
|
36
|
-
"sinon": "^7.3.2"
|
|
64
|
+
"sinon": "^7.3.2",
|
|
65
|
+
"typedoc": "^0.20.36",
|
|
66
|
+
"typedoc-github-wiki-theme": "^0.3.0",
|
|
67
|
+
"typedoc-plugin-markdown": "^3.9.0",
|
|
68
|
+
"typescript": "4.2"
|
|
69
|
+
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"@types/express": "^4"
|
|
37
72
|
}
|
|
38
73
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import qs from 'qs';
|
|
2
|
+
import DataLoader from 'dataloader';
|
|
3
|
+
import JSONAPIData from '../util/json-api/JSONAPIData';
|
|
4
|
+
import { envoyBaseURL } from '../constants';
|
|
5
|
+
import { createAxiosClient } from '../util/axiosConstructor';
|
|
6
|
+
|
|
7
|
+
interface EnvoyWebDataLoaderKey extends JSONAPIData {
|
|
8
|
+
include?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Sometimes envoy-web will give us back some relationship data
|
|
13
|
+
* with the "type" set to the relationships name instead of the actual model's name.
|
|
14
|
+
* This mapping allows us to alias those cases.
|
|
15
|
+
*/
|
|
16
|
+
const TYPE_ALIASES = new Map<string, string>([
|
|
17
|
+
['employee-screening-flows', 'flows'],
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Make typed API calls to Envoy.
|
|
22
|
+
* Uses a data loader to leverage JSONAPI's "include" functionality.
|
|
23
|
+
* This allows us to save everything that was included in the initial response
|
|
24
|
+
* to be used later without re-fetching from the API.
|
|
25
|
+
*
|
|
26
|
+
* @category Base
|
|
27
|
+
*/
|
|
28
|
+
export default class EnvoyAPI {
|
|
29
|
+
/**
|
|
30
|
+
* HTTP Client with Envoy's defaults.
|
|
31
|
+
*/
|
|
32
|
+
readonly axios = createAxiosClient({
|
|
33
|
+
baseURL: envoyBaseURL,
|
|
34
|
+
headers: {
|
|
35
|
+
'Content-Type': 'application/vnd.api+json',
|
|
36
|
+
Accept: 'application/vnd.api+json',
|
|
37
|
+
},
|
|
38
|
+
paramsSerializer: (params) => qs.stringify(params, {
|
|
39
|
+
arrayFormat: 'brackets',
|
|
40
|
+
encode: false,
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A dataloader: https://github.com/graphql/dataloader
|
|
46
|
+
* Will fetch individual resources from the API,
|
|
47
|
+
* unless they exist in cache (which they usually will).
|
|
48
|
+
*/
|
|
49
|
+
protected readonly dataLoader = new DataLoader<EnvoyWebDataLoaderKey, any, string>(
|
|
50
|
+
(keys) => Promise.all(
|
|
51
|
+
keys.map(async ({ type, id, include }) => {
|
|
52
|
+
const { data } = await this.axios.get(`api/v3/${type}/${id}`, { params: { include } });
|
|
53
|
+
return data.data;
|
|
54
|
+
}),
|
|
55
|
+
),
|
|
56
|
+
{
|
|
57
|
+
cacheKeyFn: (key) => `${key.type}_${key.id}`,
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
constructor(accessToken: string) {
|
|
62
|
+
this.axios.defaults.headers.authorization = `Bearer ${accessToken}`;
|
|
63
|
+
/**
|
|
64
|
+
* Saves every model that was "include"ed in the response,
|
|
65
|
+
* which saves us the trouble of fetching related data.
|
|
66
|
+
*/
|
|
67
|
+
this.axios.interceptors.response.use((response) => {
|
|
68
|
+
const {
|
|
69
|
+
data: {
|
|
70
|
+
data: modelOrModels,
|
|
71
|
+
included,
|
|
72
|
+
},
|
|
73
|
+
} = response;
|
|
74
|
+
|
|
75
|
+
(included || [])
|
|
76
|
+
.concat(modelOrModels)
|
|
77
|
+
.forEach((model: JSONAPIData) => {
|
|
78
|
+
this.dataLoader.prime({ type: model.type, id: model.id }, model);
|
|
79
|
+
const alias = TYPE_ALIASES.get(model.type);
|
|
80
|
+
if (alias) {
|
|
81
|
+
this.dataLoader.prime({ type: alias, id: model.id }, model);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return response;
|
|
85
|
+
}, (error) => Promise.reject(error));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import EnvoyStorageCommand, {
|
|
2
|
+
EnvoyStorageSetUniqueNumOptions,
|
|
3
|
+
EnvoyStorageSetUniqueOptions,
|
|
4
|
+
} from '../internal/EnvoyStorageCommand';
|
|
5
|
+
import EnvoyStorageResult from '../internal/EnvoyStorageResult';
|
|
6
|
+
import EnvoyPluginAPI from '../sdk/EnvoyPluginAPI';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Builds up a request pipeline for submitting storage commands.
|
|
10
|
+
*
|
|
11
|
+
* @category Base
|
|
12
|
+
*/
|
|
13
|
+
export default class EnvoyPluginStoragePipeline {
|
|
14
|
+
protected readonly api: EnvoyPluginAPI;
|
|
15
|
+
|
|
16
|
+
readonly installId: string | undefined;
|
|
17
|
+
|
|
18
|
+
protected readonly commands: Array<EnvoyStorageCommand>;
|
|
19
|
+
|
|
20
|
+
constructor(pluginAPI: EnvoyPluginAPI, installId?: string) {
|
|
21
|
+
this.api = pluginAPI;
|
|
22
|
+
this.installId = installId;
|
|
23
|
+
this.commands = [];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Executes all the commands in the pipeline.
|
|
28
|
+
*/
|
|
29
|
+
execute<Result extends EnvoyStorageResult = EnvoyStorageResult>(): Promise<Array<Result>> {
|
|
30
|
+
return this.api.storagePipeline<Result>(this.commands, this.installId);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Executes the pipeline and returns the first result.
|
|
35
|
+
*/
|
|
36
|
+
async executeSingle<Result extends EnvoyStorageResult = EnvoyStorageResult>(): Promise<Result> {
|
|
37
|
+
const [result] = await this.execute<Result>();
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
addCommand(command: EnvoyStorageCommand): EnvoyPluginStoragePipeline {
|
|
42
|
+
this.commands.push(command);
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Gets a storage item.
|
|
48
|
+
*/
|
|
49
|
+
get(key: string): EnvoyPluginStoragePipeline {
|
|
50
|
+
return this.addCommand({ action: 'get', key });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Sets a value for a storage item,
|
|
55
|
+
* and returns that item.
|
|
56
|
+
*/
|
|
57
|
+
set(key: string, value: unknown): EnvoyPluginStoragePipeline {
|
|
58
|
+
return this.addCommand({ action: 'set', key, value });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Sets a unique value for a storage item,
|
|
63
|
+
* and returns that item.
|
|
64
|
+
*/
|
|
65
|
+
setUnique(key: string, options: EnvoyStorageSetUniqueOptions = {}): EnvoyPluginStoragePipeline {
|
|
66
|
+
return this.addCommand({ action: 'set_unique', key, ...options });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Sets a unique number value for a storage item,
|
|
71
|
+
* and returns that item.
|
|
72
|
+
*/
|
|
73
|
+
setUniqueNum(key: string, options: EnvoyStorageSetUniqueNumOptions = {}): EnvoyPluginStoragePipeline {
|
|
74
|
+
if (options.min) {
|
|
75
|
+
options.min = Number(options.min);
|
|
76
|
+
}
|
|
77
|
+
if (options.max) {
|
|
78
|
+
options.max = Number(options.max);
|
|
79
|
+
}
|
|
80
|
+
return this.addCommand({ action: 'set_unique_num', key, ...options });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Unsets a storage item.
|
|
85
|
+
*/
|
|
86
|
+
unset(key: string): EnvoyPluginStoragePipeline {
|
|
87
|
+
return this.addCommand({ action: 'unset', key });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Lists storage items.
|
|
92
|
+
*/
|
|
93
|
+
list(page = 1): EnvoyPluginStoragePipeline {
|
|
94
|
+
if (!page) {
|
|
95
|
+
page = 1;
|
|
96
|
+
}
|
|
97
|
+
return this.addCommand({ action: 'list', page });
|
|
98
|
+
}
|
|
99
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import dotenv from 'dotenv-flow';
|
|
2
|
+
|
|
3
|
+
dotenv.config();
|
|
4
|
+
export const envoyBaseURL = process.env.ENVOY_BASE_URL || 'https://app.envoy.com';
|
|
5
|
+
export const envoyClientId = process.env.ENVOY_CLIENT_ID as string;
|
|
6
|
+
export const envoyClientSecret = process.env.ENVOY_CLIENT_SECRET as string;
|
|
7
|
+
export const jwtSecret = process.env.JWT_SECRET as string;
|