@envoy/envoy-integrations-sdk 2.4.1-beta.1 → 2.4.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.
@@ -1 +1 @@
1
- {"version":3,"file":"EnvoyAPI.d.ts","sourceRoot":"","sources":["../../src/base/EnvoyAPI.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,WAAW,MAAM,8BAA8B,CAAC;AAIvD,UAAU,qBAAsB,SAAQ,WAAW;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AASD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B;;OAEG;IACH,QAAQ,CAAC,KAAK,gCAWX;IAEH;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,UAAU,iDAW3B;gBAEU,WAAW,EAAE,MAAM;CA2BhC"}
1
+ {"version":3,"file":"EnvoyAPI.d.ts","sourceRoot":"","sources":["../../src/base/EnvoyAPI.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,WAAW,MAAM,8BAA8B,CAAC;AAKvD,UAAU,qBAAsB,SAAQ,WAAW;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AASD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B;;OAEG;IACH,QAAQ,CAAC,KAAK,gCAWX;IAEH;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,UAAU,iDAW3B;gBAEU,WAAW,EAAE,MAAM;CA2BhC"}
@@ -43,6 +43,7 @@ var qs_1 = __importDefault(require("qs"));
43
43
  var dataloader_1 = __importDefault(require("dataloader"));
44
44
  var constants_1 = require("../constants");
45
45
  var axiosConstructor_1 = require("../util/axiosConstructor");
46
+ var errorHandling_1 = require("../util/errorHandling");
46
47
  /**
47
48
  * Sometimes envoy-web will give us back some relationship data
48
49
  * with the "type" set to the relationships name instead of the actual model's name.
@@ -108,7 +109,7 @@ var EnvoyAPI = /** @class */ (function () {
108
109
  var _a = response.data, modelOrModels = _a.data, included = _a.included;
109
110
  (included || []).concat(modelOrModels).forEach(function (model) {
110
111
  if (!model) {
111
- throw new Error('The data you are looking for may not exist.');
112
+ throw new Error(errorHandling_1.EMPTY_STORAGE_ERROR_MESSAGE);
112
113
  }
113
114
  _this.dataLoader.prime({ type: model.type, id: model.id }, model);
114
115
  var alias = TYPE_ALIASES.get(model.type);
package/dist/index.d.ts CHANGED
@@ -50,5 +50,6 @@ export * from './sdk/loggers';
50
50
  export * from './sdk/middleware';
51
51
  export * from './util/EnvoySignatureVerifier';
52
52
  export * from './util/axiosConstructor';
53
+ export * from './util/errorHandling';
53
54
  export { EntryPayload, InvitePayload, EnvoyJWT, EnvoyMeta, EnvoyPluginJob, EnvoyPluginJobMock, EnvoyPluginSDK, EnvoyPluginStorage, EnvoyPluginStoragePipeline, EnvoyPluginStoragePipelineMock, EnvoyRequest, EnvoyResponse, EnvoySignatureVerifier, EnvoyStorageItem, EnvoyPluginAPI, EnvoyUserAPI, EnvoyValidationRouteResponseBody, JSONAPIData, JSONAPIResponse, HttpStatus, entryEventBodyFactory, eventBodyFactory, inviteEventBodyFactory, routeBodyFactory, };
54
55
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AAErB,OAAO,0BAA0B,MAAM,mCAAmC,CAAC;AAE3E,OAAO,qBAAqB,MAAM,mCAAmC,CAAC;AACtE,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;AAC5D,OAAO,sBAAsB,MAAM,oCAAoC,CAAC;AACxE,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;AAE5D,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAE/C,OAAO,kBAAkB,MAAM,4BAA4B,CAAC;AAC5D,OAAO,8BAA8B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ACtB,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,gCAAgC,EAChC,WAAW,EACX,eAAe,EACf,UAAU,EACV,qBAAqB,EACrB,gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,GACjB,CAAC"}
package/dist/index.js CHANGED
@@ -72,3 +72,4 @@ __exportStar(require("./sdk/loggers"), exports);
72
72
  __exportStar(require("./sdk/middleware"), exports);
73
73
  __exportStar(require("./util/EnvoySignatureVerifier"), exports);
74
74
  __exportStar(require("./util/axiosConstructor"), exports);
75
+ __exportStar(require("./util/errorHandling"), exports);
@@ -33,9 +33,9 @@ export default class EnvoyPluginJob {
33
33
  */
34
34
  ignore(message: string, reason: string): Promise<void>;
35
35
  /**
36
- * Reports that the job is ignored.
36
+ * Reports that the job is failed.
37
37
  *
38
- * Instead of calling this directly, you can return a 400 response from the job's event handler,
38
+ * Instead of calling this directly, you can return a 412 response from the job's event handler,
39
39
  * using {@link EnvoyRequest.sendFailed}.
40
40
  */
41
41
  fail(message: string, reason: string): Promise<void>;
@@ -74,9 +74,9 @@ var EnvoyPluginJob = /** @class */ (function () {
74
74
  return this.execute('ignored', message, reason);
75
75
  };
76
76
  /**
77
- * Reports that the job is ignored.
77
+ * Reports that the job is failed.
78
78
  *
79
- * Instead of calling this directly, you can return a 400 response from the job's event handler,
79
+ * Instead of calling this directly, you can return a 412 response from the job's event handler,
80
80
  * using {@link EnvoyRequest.sendFailed}.
81
81
  */
82
82
  EnvoyPluginJob.prototype.fail = function (message, reason) {
@@ -8,6 +8,16 @@ export interface EnvoyPluginTextJobAttachment {
8
8
  label: string;
9
9
  value: string;
10
10
  }
11
+ /**
12
+ * Display some JSON data in Envoy's dashboard.
13
+ *
14
+ * @category Attachment
15
+ */
16
+ export interface EnvoyPluginJSONJobAttachment {
17
+ type: 'json';
18
+ label: string;
19
+ value: unknown;
20
+ }
11
21
  /**
12
22
  * Display a link in Envoy's dashboard.
13
23
  *
@@ -31,6 +41,44 @@ export interface EnvoyPluginCredentialJobAttachment extends EnvoyPluginTextJobAt
31
41
  link: string;
32
42
  };
33
43
  }
44
+ /**
45
+ * Display a screener report in Envoy's dashboard,
46
+ * and allow for approval or rejection.
47
+ *
48
+ * @category Attachment
49
+ */
50
+ export interface EnvoyPluginScreenerJobAttachment extends EnvoyPluginJSONJobAttachment {
51
+ label: string;
52
+ value: ScreenerDetails;
53
+ }
54
+ /**
55
+ * Screener report definitions
56
+ */
57
+ export interface ScreenerDetails {
58
+ input: {
59
+ fields: ScreenerInputField[];
60
+ };
61
+ matches: ScreenerMatch[];
62
+ }
63
+ export interface ScreenerMatch {
64
+ headers: ScreenerMatchHeaders;
65
+ 'visible-fields-count': number;
66
+ fields: ScreenerMatchField[];
67
+ }
68
+ export interface ScreenerMatchHeaders {
69
+ name: string;
70
+ value: string;
71
+ }
72
+ export interface ScreenerMatchField {
73
+ name: string;
74
+ value: string;
75
+ type: 'text' | 'image';
76
+ }
77
+ export interface ScreenerInputField {
78
+ name: string;
79
+ value: string;
80
+ type: 'text' | 'image';
81
+ }
34
82
  /**
35
83
  * Attachments to jobs, which will be displayed in the Envoy dashboard.
36
84
  * Some attachments like `credential_image` can show up in other places,
@@ -38,6 +86,6 @@ export interface EnvoyPluginCredentialJobAttachment extends EnvoyPluginTextJobAt
38
86
  *
39
87
  * @category Attachment
40
88
  */
41
- declare type EnvoyPluginJobAttachment = EnvoyPluginTextJobAttachment | EnvoyPluginLinkJobAttachment | EnvoyPluginCredentialJobAttachment;
89
+ declare type EnvoyPluginJobAttachment = EnvoyPluginTextJobAttachment | EnvoyPluginLinkJobAttachment | EnvoyPluginCredentialJobAttachment | EnvoyPluginScreenerJobAttachment;
42
90
  export default EnvoyPluginJobAttachment;
43
91
  //# sourceMappingURL=EnvoyPluginJobAttachment.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EnvoyPluginJobAttachment.d.ts","sourceRoot":"","sources":["../../src/sdk/EnvoyPluginJobAttachment.ts"],"names":[],"mappings":"AAAA;;;;GAIG;A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AAC;IACd,KAAK,EAAE;QACL,IAAI,EAAE,IAAI,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED;;;;;GAKG;AACH,MAAM,WAAW,gCAAiC,SAAQ,4BAA4B;IACpF,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,eAAe,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE;QACL,MAAM,EAAE,kBAAkB,EAAE,CAAC;KAC9B,CAAA;IACD,OAAO,EAAE,aAAa,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,oBAAoB,CAAC;IAC9B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,MAAM,EAAE,kBAAkB,EAAE,CAAC;CAC9B;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;GAMG;AACH,aAAK,wBAAwB,GACzB,4BAA4B,GAC5B,4BAA4B,GAC5B,kCAAkC,GAClC,gCAAgC,CAAC;AAErC,eAAe,wBAAwB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { Response } from 'express';
2
- import EnvoyPluginJobAttachment from './EnvoyPluginJobAttachment';
2
+ import EnvoyPluginJobAttachment, { EnvoyPluginScreenerJobAttachment } from './EnvoyPluginJobAttachment';
3
3
  import EnvoyOptionsRouteResponseBody from '../internal/EnvoyOptionsRouteResponseBody';
4
4
  import EnvoySelectedValuesRouteResponseBody from '../internal/EnvoySelectedValuesRouteResponseBody';
5
5
  import EnvoyRemoteValueRouteResponseBody from '../internal/EnvoyRemoteValueRouteResponseBody';
@@ -24,6 +24,10 @@ export default interface EnvoyResponse<Body = unknown> extends Response {
24
24
  * Marks the job as "failed". The message will be communicated to the Envoy Dashboard user.
25
25
  */
26
26
  sendFailed: (message: string, debugInfo?: unknown, ...attachments: Array<EnvoyPluginJobAttachment>) => void;
27
+ /**
28
+ * Marks the job as "failed". The message will be communicated to the Envoy Dashboard user.
29
+ */
30
+ sendFailedScreen: (message: string, debugInfo?: unknown, attachments?: EnvoyPluginScreenerJobAttachment) => void;
27
31
  }
28
32
  /**
29
33
  * Use to type your `res` object in Envoy "options URL" route handlers.
@@ -1 +1 @@
1
- {"version":3,"file":"EnvoyResponse.d.ts","sourceRoot":"","sources":["../../src/sdk/EnvoyResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,wBAAwB,MAAM,4BAA4B,CAAC;AAClE,OAAO,6BAA6B,MAAM,2CAA2C,CAAC;AACtF,OAAO,oCAAoC,MAAM,kDAAkD,CAAC;AACpG,OAAO,iCAAiC,MAAM,+CAA+C,CAAC;AAC9F,OAAO,gCAAgC,MAAM,oCAAoC,CAAC;AAElF;;;GAGG;AACH,MAAM,CAAC,OAAO,WAAW,aAAa,CAAC,IAAI,GAAG,OAAO,CAAE,SAAQ,QAAQ;IACrE,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,KAAK,IAAI,CAAC;IAC5B;;;;OAIG;IACH,WAAW,EAAE,CAAC,SAAS,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3C;;OAEG;IACH,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,GAAG,WAAW,EAAE,KAAK,CAAC,wBAAwB,CAAC,KAAK,IAAI,CAAC;IAE7G;;OAEG;IACH,UAAU,EAAE,CAAC,OAA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H,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,GAAG,WAAW,EAAE,KAAK,CAAC,wBAAwB,CAAC,KAAK,IAAI,CAAC;IAC5G;;OAEG;IACH,gBAAgB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,gCAAgC,KAAK,IAAI,CAAC;CAClH;AAED;;;GAGG;AACH,oBAAY,yBAAyB,GAAG,aAAa,CAAC,6BAA6B,CAAC,CAAC;AAErF;;;GAGG;AACH,oBAAY,6BAA6B,GAAG,aAAa,CAAC,iCAAiC,CAAC,CAAC;AAE7F;;;GAGG;AACH,oBAAY,gCAAgC,GAAG,aAAa,CAAC,oCAAoC,CAAC,CAAC;AAEnG;;;;;GAKG;AACH,oBAAY,4BAA4B,CAAC,MAAM,IAAI,aAAa,CAAC,gCAAgC,CAAC,MAAM,CAAC,CAAC,CAAC"}
@@ -1,14 +1,5 @@
1
1
  import { ErrorRequestHandler, RequestHandler } from 'express';
2
2
  import { EnvoySignatureVerifierOptions } from '../util/EnvoySignatureVerifier';
3
- /**
4
- * Options for configuring the Envoy middleware.
5
- */
6
- export interface EnvoyMiddlewareOptions extends Partial<EnvoySignatureVerifierOptions> {
7
- /** Optional custom client ID to use for API authentication instead of environment variable */
8
- customClientId?: string;
9
- /** Optional custom client secret to use for API authentication instead of environment variable */
10
- customClientSecret?: string;
11
- }
12
3
  /**
13
4
  * Sets up an {@link EnvoyPluginSDK} object in the path `req.envoy`.
14
5
  * Modifies the `res` object to include Envoy's helpers, per {@link EnvoyResponse}.
@@ -18,7 +9,7 @@ export interface EnvoyMiddlewareOptions extends Partial<EnvoySignatureVerifierOp
18
9
  *
19
10
  * @category Middleware
20
11
  */
21
- export declare function envoyMiddleware(options?: EnvoyMiddlewareOptions): RequestHandler;
12
+ export declare function envoyMiddleware(options?: EnvoySignatureVerifierOptions): RequestHandler;
22
13
  /**
23
14
  * Catches errors and sets the proper status code.
24
15
  *
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/sdk/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,mBAAmB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG/F,OAA+B,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAOvG;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,OAAO,CAAC,6BAA6B,CAAC;IACpF,8FAA8F;IAC9F,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kGAAkG;IAClG,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,sBAAsB,GAAG,cAAc,CAoEhF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAe,GAAG,mBAAmB,CAU7F"}
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/sdk/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,mBAAmB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG/F,OAA+B,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAOvG;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,6BAA6B,GAAG,cAAc,CA8EvF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAe,GAAG,mBAAmB,CAU7F"}
@@ -66,34 +66,25 @@ function envoyMiddleware(options) {
66
66
  var threshold = 0;
67
67
  return function (req, res, next) {
68
68
  json(req, res, function (err) { return __awaiter(_this, void 0, void 0, function () {
69
- var now, hasCustomCredentials, _a, rawAccessToken, expiresIn, _b, envoyRequest, envoyResponse_1, error_1;
70
- return __generator(this, function (_c) {
71
- switch (_c.label) {
69
+ var now, _a, rawAccessToken, expiresIn, envoyRequest, envoyResponse_1, error_1;
70
+ return __generator(this, function (_b) {
71
+ switch (_b.label) {
72
72
  case 0:
73
73
  if (err) {
74
74
  return [2 /*return*/, next(err)];
75
75
  }
76
- _c.label = 1;
76
+ _b.label = 1;
77
77
  case 1:
78
- _c.trys.push([1, 7, , 8]);
78
+ _b.trys.push([1, 4, , 5]);
79
79
  now = Date.now();
80
- if (!(now > threshold)) return [3 /*break*/, 6];
81
- hasCustomCredentials = (options === null || options === void 0 ? void 0 : options.customClientId) && (options === null || options === void 0 ? void 0 : options.customClientSecret);
82
- if (!hasCustomCredentials) return [3 /*break*/, 3];
83
- return [4 /*yield*/, EnvoyPluginAPI_1.default.loginAsPlugin(options === null || options === void 0 ? void 0 : options.customClientId, options === null || options === void 0 ? void 0 : options.customClientSecret)];
80
+ if (!(now > threshold)) return [3 /*break*/, 3];
81
+ return [4 /*yield*/, EnvoyPluginAPI_1.default.loginAsPlugin()];
84
82
  case 2:
85
- _b = _c.sent();
86
- return [3 /*break*/, 5];
87
- case 3: return [4 /*yield*/, EnvoyPluginAPI_1.default.loginAsPlugin()];
88
- case 4:
89
- _b = _c.sent();
90
- _c.label = 5;
91
- case 5:
92
- _a = _b, rawAccessToken = _a.access_token, expiresIn = _a.expires_in;
83
+ _a = _b.sent(), rawAccessToken = _a.access_token, expiresIn = _a.expires_in;
93
84
  accessToken = rawAccessToken;
94
85
  threshold = now + expiresIn * 1000 - 1000 * 60 * 10;
95
- _c.label = 6;
96
- case 6:
86
+ _b.label = 3;
87
+ case 3:
97
88
  envoyRequest = req;
98
89
  envoyResponse_1 = res;
99
90
  envoyRequest.envoy = new EnvoyPluginSDK_1.default(envoyRequest.body, envoyRequest[EnvoyRequest_1.VERIFIED], accessToken);
@@ -135,13 +126,23 @@ function envoyMiddleware(options) {
135
126
  envoyResponse_1.setHeader('Content-Type', 'application/json');
136
127
  envoyResponse_1.end(JSON.stringify({ message: message, debugInfo: debugInfo, attachments: attachments }));
137
128
  };
129
+ /**
130
+ * Respond with "failed" for screener in case of screener matches.
131
+ */
132
+ envoyResponse_1.sendFailedScreen = function (message, debugInfo, attachments) {
133
+ if (message === void 0) { message = ''; }
134
+ if (debugInfo === void 0) { debugInfo = {}; }
135
+ envoyResponse_1.statusCode = HttpStatus_1.default.FAILED;
136
+ envoyResponse_1.setHeader('Content-Type', 'application/json');
137
+ envoyResponse_1.end(JSON.stringify({ message: message, debugInfo: debugInfo, attachments: attachments }));
138
+ };
138
139
  next();
139
- return [3 /*break*/, 8];
140
- case 7:
141
- error_1 = _c.sent();
140
+ return [3 /*break*/, 5];
141
+ case 4:
142
+ error_1 = _b.sent();
142
143
  next(error_1);
143
- return [3 /*break*/, 8];
144
- case 8: return [2 /*return*/];
144
+ return [3 /*break*/, 5];
145
+ case 5: return [2 /*return*/];
145
146
  }
146
147
  });
147
148
  }); });
@@ -1,2 +1,15 @@
1
+ /**
2
+ * Error message indicating missing data, used to detect missing storage items.
3
+ * Added in https://github.com/envoy/envoy-integrations-sdk-nodejs/blob/v2.3.1/src/base/EnvoyAPI.ts#L79
4
+ */
5
+ export declare const EMPTY_STORAGE_ERROR_MESSAGE = "The data you are looking for may not exist";
1
6
  export declare function ensureError(value: unknown): Error;
7
+ /**
8
+ * Check whether an error is due to an item not existing in Envoy.
9
+ * Certain Envoy operations (notably storage ones) throw an error when an item does not exist, though
10
+ * non-existence may be expected. Currently, the best way to identify this case is the error message.
11
+ * @param error - The error to check.
12
+ * @returns True if the error is likely due to a missing storage item, false otherwise.
13
+ */
14
+ export declare function isEmptyStorageError(error: Error): boolean;
2
15
  //# sourceMappingURL=errorHandling.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"errorHandling.d.ts","sourceRoot":"","sources":["../../src/util/errorHandling.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,2BAA2B,+CAA+C,CAAC;AAExF,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAcjD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAMzD"}
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ensureError = void 0;
3
+ exports.isEmptyStorageError = exports.ensureError = exports.EMPTY_STORAGE_ERROR_MESSAGE = void 0;
4
+ /**
5
+ * Error message indicating missing data, used to detect missing storage items.
6
+ * Added in https://github.com/envoy/envoy-integrations-sdk-nodejs/blob/v2.3.1/src/base/EnvoyAPI.ts#L79
7
+ */
8
+ exports.EMPTY_STORAGE_ERROR_MESSAGE = 'The data you are looking for may not exist';
4
9
  function ensureError(value) {
5
10
  if (value instanceof Error) {
6
11
  return value;
@@ -16,3 +21,17 @@ function ensureError(value) {
16
21
  return error;
17
22
  }
18
23
  exports.ensureError = ensureError;
24
+ /**
25
+ * Check whether an error is due to an item not existing in Envoy.
26
+ * Certain Envoy operations (notably storage ones) throw an error when an item does not exist, though
27
+ * non-existence may be expected. Currently, the best way to identify this case is the error message.
28
+ * @param error - The error to check.
29
+ * @returns True if the error is likely due to a missing storage item, false otherwise.
30
+ */
31
+ function isEmptyStorageError(error) {
32
+ if (error.message.includes(exports.EMPTY_STORAGE_ERROR_MESSAGE)) {
33
+ return true;
34
+ }
35
+ return false;
36
+ }
37
+ exports.isEmptyStorageError = isEmptyStorageError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@envoy/envoy-integrations-sdk",
3
- "version": "2.4.1-beta.1",
3
+ "version": "2.4.2",
4
4
  "description": "SDK for building Envoy integrations.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -3,6 +3,7 @@ import DataLoader from 'dataloader';
3
3
  import JSONAPIData from '../util/json-api/JSONAPIData';
4
4
  import { envoyBaseURL } from '../constants';
5
5
  import { createAxiosClient } from '../util/axiosConstructor';
6
+ import { EMPTY_STORAGE_ERROR_MESSAGE } from '../util/errorHandling';
6
7
 
7
8
  interface EnvoyWebDataLoaderKey extends JSONAPIData {
8
9
  include?: string;
@@ -72,7 +73,7 @@ export default class EnvoyAPI {
72
73
 
73
74
  (included || []).concat(modelOrModels).forEach((model: JSONAPIData) => {
74
75
  if (!model) {
75
- throw new Error('The data you are looking for may not exist.');
76
+ throw new Error(EMPTY_STORAGE_ERROR_MESSAGE);
76
77
  }
77
78
  this.dataLoader.prime({ type: model.type, id: model.id }, model);
78
79
  const alias = TYPE_ALIASES.get(model.type);
package/src/index.ts CHANGED
@@ -61,6 +61,7 @@ export * from './sdk/middleware';
61
61
 
62
62
  export * from './util/EnvoySignatureVerifier';
63
63
  export * from './util/axiosConstructor';
64
+ export * from './util/errorHandling';
64
65
 
65
66
  export {
66
67
  EntryPayload,
@@ -70,9 +70,9 @@ export default class EnvoyPluginJob {
70
70
  }
71
71
 
72
72
  /**
73
- * Reports that the job is ignored.
73
+ * Reports that the job is failed.
74
74
  *
75
- * Instead of calling this directly, you can return a 400 response from the job's event handler,
75
+ * Instead of calling this directly, you can return a 412 response from the job's event handler,
76
76
  * using {@link EnvoyRequest.sendFailed}.
77
77
  */
78
78
  fail(message: string, reason: string): Promise<void> {
@@ -9,6 +9,17 @@ export interface EnvoyPluginTextJobAttachment {
9
9
  value: string;
10
10
  }
11
11
 
12
+ /**
13
+ * Display some JSON data in Envoy's dashboard.
14
+ *
15
+ * @category Attachment
16
+ */
17
+ export interface EnvoyPluginJSONJobAttachment {
18
+ type: 'json';
19
+ label: string;
20
+ value: unknown;
21
+ }
22
+
12
23
  /**
13
24
  * Display a link in Envoy's dashboard.
14
25
  *
@@ -34,6 +45,50 @@ export interface EnvoyPluginCredentialJobAttachment extends EnvoyPluginTextJobAt
34
45
  };
35
46
  }
36
47
 
48
+ /**
49
+ * Display a screener report in Envoy's dashboard,
50
+ * and allow for approval or rejection.
51
+ *
52
+ * @category Attachment
53
+ */
54
+ export interface EnvoyPluginScreenerJobAttachment extends EnvoyPluginJSONJobAttachment {
55
+ label: string;
56
+ value: ScreenerDetails;
57
+ }
58
+
59
+ /**
60
+ * Screener report definitions
61
+ */
62
+ export interface ScreenerDetails {
63
+ input: {
64
+ fields: ScreenerInputField[];
65
+ }
66
+ matches: ScreenerMatch[];
67
+ }
68
+
69
+ export interface ScreenerMatch {
70
+ headers: ScreenerMatchHeaders;
71
+ 'visible-fields-count': number;
72
+ fields: ScreenerMatchField[];
73
+ }
74
+
75
+ export interface ScreenerMatchHeaders {
76
+ name: string; // ex: Tags
77
+ value: string; // ex: Content
78
+ }
79
+
80
+ export interface ScreenerMatchField {
81
+ name: string;
82
+ value: string;
83
+ type: 'text' | 'image';
84
+ }
85
+
86
+ export interface ScreenerInputField {
87
+ name: string;
88
+ value: string;
89
+ type: 'text' | 'image';
90
+ }
91
+
37
92
  /**
38
93
  * Attachments to jobs, which will be displayed in the Envoy dashboard.
39
94
  * Some attachments like `credential_image` can show up in other places,
@@ -44,6 +99,7 @@ export interface EnvoyPluginCredentialJobAttachment extends EnvoyPluginTextJobAt
44
99
  type EnvoyPluginJobAttachment =
45
100
  | EnvoyPluginTextJobAttachment
46
101
  | EnvoyPluginLinkJobAttachment
47
- | EnvoyPluginCredentialJobAttachment;
102
+ | EnvoyPluginCredentialJobAttachment
103
+ | EnvoyPluginScreenerJobAttachment;
48
104
 
49
105
  export default EnvoyPluginJobAttachment;
@@ -1,5 +1,5 @@
1
1
  import { Response } from 'express';
2
- import EnvoyPluginJobAttachment from './EnvoyPluginJobAttachment';
2
+ import EnvoyPluginJobAttachment, { EnvoyPluginScreenerJobAttachment } from './EnvoyPluginJobAttachment';
3
3
  import EnvoyOptionsRouteResponseBody from '../internal/EnvoyOptionsRouteResponseBody';
4
4
  import EnvoySelectedValuesRouteResponseBody from '../internal/EnvoySelectedValuesRouteResponseBody';
5
5
  import EnvoyRemoteValueRouteResponseBody from '../internal/EnvoyRemoteValueRouteResponseBody';
@@ -26,6 +26,10 @@ export default interface EnvoyResponse<Body = unknown> extends Response {
26
26
  * Marks the job as "failed". The message will be communicated to the Envoy Dashboard user.
27
27
  */
28
28
  sendFailed: (message: string, debugInfo?: unknown, ...attachments: Array<EnvoyPluginJobAttachment>) => void;
29
+ /**
30
+ * Marks the job as "failed". The message will be communicated to the Envoy Dashboard user.
31
+ */
32
+ sendFailedScreen: (message: string, debugInfo?: unknown, attachments?: EnvoyPluginScreenerJobAttachment) => void;
29
33
  }
30
34
 
31
35
  /**
@@ -5,20 +5,10 @@ import HttpStatus from '../internal/HttpStatus';
5
5
  import EnvoySignatureVerifier, { EnvoySignatureVerifierOptions } from '../util/EnvoySignatureVerifier';
6
6
  import EnvoyRequest, { VERIFIED, VerifiedRequest } from './EnvoyRequest';
7
7
  import EnvoyResponse from './EnvoyResponse';
8
- import EnvoyPluginJobAttachment from './EnvoyPluginJobAttachment';
8
+ import EnvoyPluginJobAttachment, { EnvoyPluginScreenerJobAttachment } from './EnvoyPluginJobAttachment';
9
9
  import EnvoyPluginSDK from './EnvoyPluginSDK';
10
10
  import EnvoyPluginAPI from './EnvoyPluginAPI';
11
11
 
12
- /**
13
- * Options for configuring the Envoy middleware.
14
- */
15
- export interface EnvoyMiddlewareOptions extends Partial<EnvoySignatureVerifierOptions> {
16
- /** Optional custom client ID to use for API authentication instead of environment variable */
17
- customClientId?: string;
18
- /** Optional custom client secret to use for API authentication instead of environment variable */
19
- customClientSecret?: string;
20
- }
21
-
22
12
  /**
23
13
  * Sets up an {@link EnvoyPluginSDK} object in the path `req.envoy`.
24
14
  * Modifies the `res` object to include Envoy's helpers, per {@link EnvoyResponse}.
@@ -28,8 +18,8 @@ export interface EnvoyMiddlewareOptions extends Partial<EnvoySignatureVerifierOp
28
18
  *
29
19
  * @category Middleware
30
20
  */
31
- export function envoyMiddleware(options?: EnvoyMiddlewareOptions): RequestHandler {
32
- const signatureVerifier = new EnvoySignatureVerifier(options as EnvoySignatureVerifierOptions);
21
+ export function envoyMiddleware(options?: EnvoySignatureVerifierOptions): RequestHandler {
22
+ const signatureVerifier = new EnvoySignatureVerifier(options);
33
23
  const verify = (req: VerifiedRequest, res: Response, rawBody: Buffer) => {
34
24
  req[VERIFIED] = signatureVerifier.verify(req, rawBody);
35
25
  };
@@ -45,10 +35,7 @@ export function envoyMiddleware(options?: EnvoyMiddlewareOptions): RequestHandle
45
35
  try {
46
36
  const now = Date.now();
47
37
  if (now > threshold) {
48
- const hasCustomCredentials = options?.customClientId && options?.customClientSecret;
49
- const { access_token: rawAccessToken, expires_in: expiresIn } = hasCustomCredentials
50
- ? await EnvoyPluginAPI.loginAsPlugin(options?.customClientId, options?.customClientSecret)
51
- : await EnvoyPluginAPI.loginAsPlugin();
38
+ const { access_token: rawAccessToken, expires_in: expiresIn } = await EnvoyPluginAPI.loginAsPlugin();
52
39
  accessToken = rawAccessToken;
53
40
  threshold = now + expiresIn * 1000 - 1000 * 60 * 10;
54
41
  }
@@ -90,6 +77,19 @@ export function envoyMiddleware(options?: EnvoyMiddlewareOptions): RequestHandle
90
77
  envoyResponse.setHeader('Content-Type', 'application/json');
91
78
  envoyResponse.end(JSON.stringify({ message, debugInfo, attachments }));
92
79
  };
80
+
81
+ /**
82
+ * Respond with "failed" for screener in case of screener matches.
83
+ */
84
+ envoyResponse.sendFailedScreen = (
85
+ message = '',
86
+ debugInfo: unknown = {},
87
+ attachments?: EnvoyPluginScreenerJobAttachment,
88
+ ) => {
89
+ envoyResponse.statusCode = HttpStatus.FAILED;
90
+ envoyResponse.setHeader('Content-Type', 'application/json');
91
+ envoyResponse.end(JSON.stringify({ message, debugInfo, attachments }));
92
+ };
93
93
  next();
94
94
  } catch (error) {
95
95
  next(error);
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Error message indicating missing data, used to detect missing storage items.
3
+ * Added in https://github.com/envoy/envoy-integrations-sdk-nodejs/blob/v2.3.1/src/base/EnvoyAPI.ts#L79
4
+ */
5
+ export const EMPTY_STORAGE_ERROR_MESSAGE = 'The data you are looking for may not exist';
6
+
1
7
  export function ensureError(value: unknown): Error {
2
8
  if (value instanceof Error) {
3
9
  return value;
@@ -13,3 +19,18 @@ export function ensureError(value: unknown): Error {
13
19
  const error = new Error(`This value was thrown as is, not through an Error: ${stringified}`);
14
20
  return error;
15
21
  }
22
+
23
+ /**
24
+ * Check whether an error is due to an item not existing in Envoy.
25
+ * Certain Envoy operations (notably storage ones) throw an error when an item does not exist, though
26
+ * non-existence may be expected. Currently, the best way to identify this case is the error message.
27
+ * @param error - The error to check.
28
+ * @returns True if the error is likely due to a missing storage item, false otherwise.
29
+ */
30
+ export function isEmptyStorageError(error: Error): boolean {
31
+ if (error.message.includes(EMPTY_STORAGE_ERROR_MESSAGE)) {
32
+ return true;
33
+ }
34
+
35
+ return false;
36
+ }