@envoy/envoy-integrations-sdk 2.3.6 → 2.4.0-beta.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,6 +1,6 @@
1
1
  import { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
2
2
  declare function envoyAxiosRequestLogger(config: AxiosRequestConfig): AxiosRequestConfig<any>;
3
- declare function envoyAxiosResponseLogger(response: AxiosResponse): AxiosResponse<any, any>;
3
+ declare function envoyAxiosResponseLogger(response: AxiosResponse): AxiosResponse<any, any, {}>;
4
4
  declare function envoyAxiosErrorLogger(error: AxiosError): void;
5
5
  export { envoyAxiosRequestLogger, envoyAxiosResponseLogger, envoyAxiosErrorLogger };
6
6
  //# sourceMappingURL=loggers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loggers.d.ts","sourceRoot":"","sources":["../../src/sdk/loggers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAItE,iBAAS,uBAAuB,CAAC,MAAM,EAAE,kBAAkB,2BAkD1D;AAED,iBAAS,wBAAwB,CAAC,QAAQ,EAAE,aAAa,2BAoDxD;AAED,iBAAS,qBAAqB,CAAC,KAAK,EAAE,UAAU,QAoD/C;AAED,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,CAAC"}
1
+ {"version":3,"file":"loggers.d.ts","sourceRoot":"","sources":["../../src/sdk/loggers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAItE,iBAAS,uBAAuB,CAAC,MAAM,EAAE,kBAAkB,2BAkD1D;AAED,iBAAS,wBAAwB,CAAC,QAAQ,EAAE,aAAa,+BAoDxD;AAED,iBAAS,qBAAqB,CAAC,KAAK,EAAE,UAAU,QAoD/C;AAED,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,CAAC"}
@@ -1,5 +1,14 @@
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
+ }
3
12
  /**
4
13
  * Sets up an {@link EnvoyPluginSDK} object in the path `req.envoy`.
5
14
  * Modifies the `res` object to include Envoy's helpers, per {@link EnvoyResponse}.
@@ -9,7 +18,7 @@ import { EnvoySignatureVerifierOptions } from '../util/EnvoySignatureVerifier';
9
18
  *
10
19
  * @category Middleware
11
20
  */
12
- export declare function envoyMiddleware(options?: EnvoySignatureVerifierOptions): RequestHandler;
21
+ export declare function envoyMiddleware(options?: EnvoyMiddlewareOptions): RequestHandler;
13
22
  /**
14
23
  * Catches errors and sets the proper status code.
15
24
  *
@@ -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;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,6BAA6B,GAAG,cAAc,CAiEvF;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;;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"}
@@ -66,25 +66,34 @@ 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, _a, rawAccessToken, expiresIn, envoyRequest, envoyResponse_1, error_1;
70
- return __generator(this, function (_b) {
71
- switch (_b.label) {
69
+ var now, hasCustomCredentials, _a, rawAccessToken, expiresIn, _b, envoyRequest, envoyResponse_1, error_1;
70
+ return __generator(this, function (_c) {
71
+ switch (_c.label) {
72
72
  case 0:
73
73
  if (err) {
74
74
  return [2 /*return*/, next(err)];
75
75
  }
76
- _b.label = 1;
76
+ _c.label = 1;
77
77
  case 1:
78
- _b.trys.push([1, 4, , 5]);
78
+ _c.trys.push([1, 7, , 8]);
79
79
  now = Date.now();
80
- if (!(now > threshold)) return [3 /*break*/, 3];
81
- return [4 /*yield*/, EnvoyPluginAPI_1.default.loginAsPlugin()];
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)];
82
84
  case 2:
83
- _a = _b.sent(), rawAccessToken = _a.access_token, expiresIn = _a.expires_in;
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;
84
93
  accessToken = rawAccessToken;
85
94
  threshold = now + expiresIn * 1000 - 1000 * 60 * 10;
86
- _b.label = 3;
87
- case 3:
95
+ _c.label = 6;
96
+ case 6:
88
97
  envoyRequest = req;
89
98
  envoyResponse_1 = res;
90
99
  envoyRequest.envoy = new EnvoyPluginSDK_1.default(envoyRequest.body, envoyRequest[EnvoyRequest_1.VERIFIED], accessToken);
@@ -127,12 +136,12 @@ function envoyMiddleware(options) {
127
136
  envoyResponse_1.end(JSON.stringify({ message: message, debugInfo: debugInfo, attachments: attachments }));
128
137
  };
129
138
  next();
130
- return [3 /*break*/, 5];
131
- case 4:
132
- error_1 = _b.sent();
139
+ return [3 /*break*/, 8];
140
+ case 7:
141
+ error_1 = _c.sent();
133
142
  next(error_1);
134
- return [3 /*break*/, 5];
135
- case 5: return [2 /*return*/];
143
+ return [3 /*break*/, 8];
144
+ case 8: return [2 /*return*/];
136
145
  }
137
146
  });
138
147
  }); });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@envoy/envoy-integrations-sdk",
3
- "version": "2.3.6",
3
+ "version": "2.4.0-beta.2",
4
4
  "description": "SDK for building Envoy integrations.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,6 +9,16 @@ import EnvoyPluginJobAttachment 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
+
12
22
  /**
13
23
  * Sets up an {@link EnvoyPluginSDK} object in the path `req.envoy`.
14
24
  * Modifies the `res` object to include Envoy's helpers, per {@link EnvoyResponse}.
@@ -18,8 +28,8 @@ import EnvoyPluginAPI from './EnvoyPluginAPI';
18
28
  *
19
29
  * @category Middleware
20
30
  */
21
- export function envoyMiddleware(options?: EnvoySignatureVerifierOptions): RequestHandler {
22
- const signatureVerifier = new EnvoySignatureVerifier(options);
31
+ export function envoyMiddleware(options?: EnvoyMiddlewareOptions): RequestHandler {
32
+ const signatureVerifier = new EnvoySignatureVerifier(options as EnvoySignatureVerifierOptions);
23
33
  const verify = (req: VerifiedRequest, res: Response, rawBody: Buffer) => {
24
34
  req[VERIFIED] = signatureVerifier.verify(req, rawBody);
25
35
  };
@@ -35,7 +45,10 @@ export function envoyMiddleware(options?: EnvoySignatureVerifierOptions): Reques
35
45
  try {
36
46
  const now = Date.now();
37
47
  if (now > threshold) {
38
- const { access_token: rawAccessToken, expires_in: expiresIn } = await EnvoyPluginAPI.loginAsPlugin();
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();
39
52
  accessToken = rawAccessToken;
40
53
  threshold = now + expiresIn * 1000 - 1000 * 60 * 10;
41
54
  }