@envoy/envoy-integrations-sdk 2.3.0 → 2.3.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.
Files changed (84) hide show
  1. package/README.md +24 -16
  2. package/dist/base/EnvoyAPI.d.ts.map +1 -1
  3. package/dist/base/EnvoyAPI.js +26 -23
  4. package/dist/factories/entryEventBodyFactory.d.ts.map +1 -1
  5. package/dist/factories/entryEventBodyFactory.js +38 -30
  6. package/dist/factories/eventBodyFactory.d.ts.map +1 -1
  7. package/dist/factories/inviteEventBodyFactory.d.ts.map +1 -1
  8. package/dist/factories/inviteEventBodyFactory.js +11 -10
  9. package/dist/factories/routeBodyFactory.d.ts.map +1 -1
  10. package/dist/index.d.ts +2 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/internal/EnvoyEntryEvent.d.ts.map +1 -1
  13. package/dist/internal/EnvoyInviteEvent.d.ts.map +1 -1
  14. package/dist/internal/EnvoyStorageCommand.d.ts.map +1 -1
  15. package/dist/mocks/EnvoyPluginJobMock.d.ts.map +1 -1
  16. package/dist/mocks/EnvoyPluginStoragePipelineMock.d.ts.map +1 -1
  17. package/dist/mocks/EnvoyPluginStoragePipelineMock.js +1 -1
  18. package/dist/payloads/EntryPayload.d.ts.map +1 -1
  19. package/dist/payloads/InvitePayload.d.ts.map +1 -1
  20. package/dist/payloads/NotificationPayload.d.ts.map +1 -1
  21. package/dist/resources/FlowResource.d.ts +2 -1
  22. package/dist/resources/FlowResource.d.ts.map +1 -1
  23. package/dist/resources/ReservationResource.d.ts +5 -5
  24. package/dist/resources/ReservationResource.d.ts.map +1 -1
  25. package/dist/resources/SignInFieldPageResource.d.ts.map +1 -1
  26. package/dist/sdk/EnvoyMeta.d.ts.map +1 -1
  27. package/dist/sdk/EnvoyPluginAPI.d.ts.map +1 -1
  28. package/dist/sdk/EnvoyPluginJobAttachment.d.ts.map +1 -1
  29. package/dist/sdk/EnvoyPluginSDK.js +1 -1
  30. package/dist/sdk/EnvoyPluginStorage.d.ts.map +1 -1
  31. package/dist/sdk/EnvoyPluginStorage.js +6 -2
  32. package/dist/sdk/EnvoyRequest.d.ts.map +1 -1
  33. package/dist/sdk/EnvoyUserAPI.d.ts +1 -1
  34. package/dist/sdk/EnvoyUserAPI.d.ts.map +1 -1
  35. package/dist/sdk/EnvoyUserAPI.js +8 -8
  36. package/dist/sdk/filters.d.ts.map +1 -1
  37. package/dist/sdk/handlers.d.ts.map +1 -1
  38. package/dist/sdk/handlers.js +3 -1
  39. package/dist/sdk/loggers.js +2 -5
  40. package/dist/sdk/middleware.d.ts.map +1 -1
  41. package/dist/sdk/middleware.js +1 -1
  42. package/dist/util/EnvoySignatureVerifier.d.ts.map +1 -1
  43. package/dist/util/json-api/JSONAPIPaginationParams.d.ts.map +1 -1
  44. package/dist/util/json-api/JSONAPIResponse.d.ts.map +1 -1
  45. package/package.json +14 -6
  46. package/src/base/EnvoyAPI.ts +26 -25
  47. package/src/factories/entryEventBodyFactory.ts +59 -48
  48. package/src/factories/eventBodyFactory.ts +8 -10
  49. package/src/factories/inviteEventBodyFactory.ts +26 -24
  50. package/src/factories/metaFactory.ts +1 -1
  51. package/src/factories/routeBodyFactory.ts +9 -11
  52. package/src/index.ts +2 -0
  53. package/src/internal/EnvoyEntryEvent.ts +7 -7
  54. package/src/internal/EnvoyInviteEvent.ts +10 -10
  55. package/src/internal/EnvoyOption.ts +3 -3
  56. package/src/internal/EnvoyOptionsRouteParams.ts +3 -3
  57. package/src/internal/EnvoyPluginJobUpdate.ts +4 -4
  58. package/src/internal/EnvoyRemoteValueRouteResponseBody.ts +1 -1
  59. package/src/internal/EnvoySelectedValuesRouteParams.ts +1 -1
  60. package/src/internal/EnvoyStorageCommand.ts +21 -20
  61. package/src/mocks/EnvoyPluginJobMock.ts +2 -4
  62. package/src/mocks/EnvoyPluginStoragePipelineMock.ts +12 -4
  63. package/src/payloads/EntryPayload.ts +56 -60
  64. package/src/payloads/InvitePayload.ts +50 -50
  65. package/src/payloads/NotificationPayload.ts +38 -38
  66. package/src/resources/FlowResource.ts +2 -1
  67. package/src/resources/ReservationResource.ts +27 -21
  68. package/src/resources/SignInFieldPageResource.ts +6 -5
  69. package/src/resources/SignInFieldResource.ts +3 -3
  70. package/src/sdk/EnvoyMeta.ts +57 -57
  71. package/src/sdk/EnvoyPluginAPI.ts +5 -1
  72. package/src/sdk/EnvoyPluginJobAttachment.ts +14 -13
  73. package/src/sdk/EnvoyPluginSDK.ts +3 -3
  74. package/src/sdk/EnvoyPluginStorage.ts +8 -4
  75. package/src/sdk/EnvoyRequest.ts +61 -27
  76. package/src/sdk/EnvoyStorageItem.ts +2 -2
  77. package/src/sdk/EnvoyUserAPI.ts +51 -50
  78. package/src/sdk/filters.ts +5 -14
  79. package/src/sdk/handlers.ts +84 -76
  80. package/src/sdk/loggers.ts +15 -15
  81. package/src/sdk/middleware.ts +12 -10
  82. package/src/util/EnvoySignatureVerifier.ts +6 -14
  83. package/src/util/json-api/JSONAPIPaginationParams.ts +1 -2
  84. package/src/util/json-api/JSONAPIResponse.ts +3 -3
@@ -1,4 +1,3 @@
1
- import { Url } from 'url';
2
1
  import axios from 'axios';
3
2
  import EnvoyAPI from '../base/EnvoyAPI';
4
3
  import { AgreementPageModel } from '../resources/AgreementPageResource';
@@ -10,40 +9,38 @@ import { LocationFilterFields, LocationModel, LocationSortFields } from '../reso
10
9
  import { SignInFieldPageModel } from '../resources/SignInFieldPageResource';
11
10
  import { SignInFieldModel } from '../resources/SignInFieldResource';
12
11
  import JSONAPIPaginationParams from '../util/json-api/JSONAPIPaginationParams';
13
- import {
14
- InviteCreationModel, InviteFilterFields, InviteModel, InviteSortFields,
15
- } from '../resources/InviteResource';
12
+ import { InviteCreationModel, InviteFilterFields, InviteModel, InviteSortFields } from '../resources/InviteResource';
16
13
  import { UserModel } from '../resources/UserResource';
17
14
  import { envoyBaseURL, envoyClientId, envoyClientSecret } from '../constants';
18
15
  import { EnvoyMetaAuth } from './EnvoyMeta';
19
16
  import { sanitizeAxiosError } from '../util/axiosConstructor';
20
- import { ReservationCreationAttributes, ReservationModel } from "../resources/ReservationResource";
17
+ import { ReservationCreationAttributes, ReservationModel } from '../resources/ReservationResource';
21
18
 
22
19
  export type EnvoyUserAPIScope =
23
- 'flows.read' |
24
- 'entries.read' |
25
- 'entries.write' |
26
- 'invites.read' |
27
- 'invites.write' |
28
- 'invites.attest' |
29
- 'locations.read' |
30
- 'companies.read' |
31
- 'agreements.read' |
32
- 'agreements.write' |
33
- 'sign-in-field-pages.read' |
34
- 'sign-in-fields.read' |
35
- 'sign-in-fields.write' |
36
- 'employees.read' |
37
- 'employees.write' |
38
- 'badges.read' |
39
- 'blacklist-filters.read' |
40
- 'blacklist-filters.write' |
41
- 'tickets.read' |
42
- 'tickets.write' |
43
- 'spaces.read' |
44
- 'reservations.read' |
45
- 'reservations.write' |
46
- string;
20
+ | 'flows.read'
21
+ | 'entries.read'
22
+ | 'entries.write'
23
+ | 'invites.read'
24
+ | 'invites.write'
25
+ | 'invites.attest'
26
+ | 'locations.read'
27
+ | 'companies.read'
28
+ | 'agreements.read'
29
+ | 'agreements.write'
30
+ | 'sign-in-field-pages.read'
31
+ | 'sign-in-fields.read'
32
+ | 'sign-in-fields.write'
33
+ | 'employees.read'
34
+ | 'employees.write'
35
+ | 'badges.read'
36
+ | 'blacklist-filters.read'
37
+ | 'blacklist-filters.write'
38
+ | 'tickets.read'
39
+ | 'tickets.write'
40
+ | 'spaces.read'
41
+ | 'reservations.read'
42
+ | 'reservations.write'
43
+ | string;
47
44
 
48
45
  /**
49
46
  * API endpoints for *user-scoped* tokens.
@@ -122,7 +119,11 @@ export default class EnvoyUserAPI extends EnvoyAPI {
122
119
  limit: 1,
123
120
  },
124
121
  };
125
- const { data: { data: [employee] } } = await this.axios.get('/api/v3/employees', {
122
+ const {
123
+ data: {
124
+ data: [employee],
125
+ },
126
+ } = await this.axios.get('/api/v3/employees', {
126
127
  params: {
127
128
  include,
128
129
  ...paginationParams,
@@ -197,34 +198,34 @@ export default class EnvoyUserAPI extends EnvoyAPI {
197
198
  }
198
199
 
199
200
  async createReservation(reservationDetails: ReservationCreationAttributes): Promise<ReservationModel> {
200
- let createReservationBody = {
201
+ const createReservationBody = {
201
202
  data: {
202
203
  relationships: {
203
204
  user: {
204
205
  data: {
205
206
  type: 'users',
206
- id: reservationDetails.userId
207
- }},
207
+ id: reservationDetails.userId,
208
+ },
209
+ },
208
210
  ...(reservationDetails.locationId && {
209
- location: {
210
- data: {
211
- type: 'locations',
212
- id: reservationDetails.locationId
213
- }
214
- }
215
- }
216
- )
211
+ location: {
212
+ data: {
213
+ type: 'locations',
214
+ id: reservationDetails.locationId,
215
+ },
216
+ },
217
+ }),
217
218
  },
218
219
  attributes: {
219
- 'start-time': reservationDetails.startTime,
220
- ...(reservationDetails.endTime && {
221
- 'end-time': reservationDetails.endTime
222
- }),
223
- 'booking-source': 'EXTERNAL_API',
224
- 'booking-type': 'visitor'
225
- }
226
- }
227
- }
220
+ 'start-time': reservationDetails.startTime,
221
+ ...(reservationDetails.endTime && {
222
+ 'end-time': reservationDetails.endTime,
223
+ }),
224
+ 'booking-source': 'EXTERNAL_API',
225
+ 'booking-type': 'visitor',
226
+ },
227
+ },
228
+ };
228
229
  const { data } = await this.axios({
229
230
  method: 'POST',
230
231
  url: '/a/rms/reservations',
@@ -1,9 +1,4 @@
1
- import {
2
- Request,
3
- Response,
4
- NextFunction,
5
- RequestHandler,
6
- } from 'express';
1
+ import { Request, Response, NextFunction, RequestHandler } from 'express';
7
2
  import EnvoyRequest, { EnvoyEntryEventRequest } from './EnvoyRequest';
8
3
  import EnvoyResponse from './EnvoyResponse';
9
4
 
@@ -47,16 +42,14 @@ export function excludedEmployeesFilterMiddleware<Config>(
47
42
  return (req: Request, res: Response, next: NextFunction): void => {
48
43
  const {
49
44
  envoy: {
50
- meta: {
51
- config,
52
- },
45
+ meta: { config },
53
46
  payload,
54
47
  },
55
48
  } = req as EnvoyEntryEventRequest<Config>;
56
49
  if (!payload.attributes['employee-screening-flow']) {
57
50
  return next();
58
51
  }
59
- const excludedEmployees = config[excludeEmployeesKey] as unknown as Array<string> || [];
52
+ const excludedEmployees = (config[excludeEmployeesKey] as unknown as Array<string>) || [];
60
53
  if (!Array.isArray(excludedEmployees)) {
61
54
  return next(new Error(`${excludeEmployeesKey} is not an array.`));
62
55
  }
@@ -82,12 +75,10 @@ export function inviteOnlyEntryFilterMiddleware<Config>(
82
75
  return (req: Request, res: Response, next: NextFunction): void => {
83
76
  const {
84
77
  envoy: {
85
- meta: {
86
- config,
87
- },
78
+ meta: { config },
88
79
  payload,
89
80
  },
90
- } = (req as EnvoyEntryEventRequest<Config>);
81
+ } = req as EnvoyEntryEventRequest<Config>;
91
82
  if (!payload.relationships.invite && config[invitesOnlyKey]) {
92
83
  return (res as EnvoyResponse).sendIgnored(message);
93
84
  }
@@ -1,9 +1,4 @@
1
- import {
2
- NextFunction,
3
- RequestHandler,
4
- Request,
5
- Response,
6
- } from 'express';
1
+ import { NextFunction, RequestHandler, Request, Response } from 'express';
7
2
  import {
8
3
  EnvoyEntryEventRequest,
9
4
  EnvoyEventRequest,
@@ -32,78 +27,100 @@ type Result = Promise<void> | void;
32
27
  * Handle an entry event, such as `entry_sign_in`.
33
28
  * @category Handler
34
29
  */
35
- export type EntryEventHandler<Config = SomeObject, Additions = SomeObject> =
36
- (req: EnvoyEntryEventRequest<Config> & Additions, res: EnvoyResponse) => Result;
30
+ export type EntryEventHandler<Config = SomeObject, Additions = SomeObject> = (
31
+ req: EnvoyEntryEventRequest<Config> & Additions,
32
+ res: EnvoyResponse,
33
+ ) => Result;
37
34
 
38
35
  /**
39
36
  * Handle an invite event, such as `invite_created`.
40
37
  * @category Handler
41
38
  */
42
- export type InviteEventHandler<Config = SomeObject, Additions = SomeObject> =
43
- (req: EnvoyInviteEventRequest<Config> & Additions, res: EnvoyResponse) => Result;
39
+ export type InviteEventHandler<Config = SomeObject, Additions = SomeObject> = (
40
+ req: EnvoyInviteEventRequest<Config> & Additions,
41
+ res: EnvoyResponse,
42
+ ) => Result;
44
43
 
45
44
  /**
46
45
  * Handle an location event, such as `location_capacity_updated`.
47
46
  * @category Handler
48
47
  */
49
- export type LocationEventHandler<Config = SomeObject, Additions = SomeObject> =
50
- (req: EnvoyLocationEventRequest<Config> & Additions, res: EnvoyResponse) => Result;
48
+ export type LocationEventHandler<Config = SomeObject, Additions = SomeObject> = (
49
+ req: EnvoyLocationEventRequest<Config> & Additions,
50
+ res: EnvoyResponse,
51
+ ) => Result;
51
52
 
52
53
  /**
53
54
  * Handle an notification event.
54
55
  * @category Handler
55
56
  */
56
- export type NotificationEventHandler<Config = SomeObject, Additions = SomeObject> =
57
- (req: EnvoyNotificationEventRequest<Config> & Additions, res: EnvoyResponse) => Result;
57
+ export type NotificationEventHandler<Config = SomeObject, Additions = SomeObject> = (
58
+ req: EnvoyNotificationEventRequest<Config> & Additions,
59
+ res: EnvoyResponse,
60
+ ) => Result;
58
61
 
59
62
  /**
60
63
  * Handle a takeover event.
61
64
  * @category Handler
62
65
  */
63
- export type TakeoverEventHandler<Config = SomeObject, Additions = SomeObject> =
64
- (req: EnvoyTakeoverEventRequest<Config> & Additions, res: EnvoyResponse) => Result;
66
+ export type TakeoverEventHandler<Config = SomeObject, Additions = SomeObject> = (
67
+ req: EnvoyTakeoverEventRequest<Config> & Additions,
68
+ res: EnvoyResponse,
69
+ ) => Result;
65
70
 
66
71
  /**
67
72
  * Handle a `plugin_uninstalled` event for cleaning up.
68
73
  * @category Handler
69
74
  */
70
- export type PluginUninstalledEventHandler<Config = SomeObject, Additions = SomeObject> =
71
- (req: EnvoyEventRequest<'plugin_uninstalled', never, Config> & Additions, res: EnvoyResponse) => Result;
75
+ export type PluginUninstalledEventHandler<Config = SomeObject, Additions = SomeObject> = (
76
+ req: EnvoyEventRequest<'plugin_uninstalled', never, Config> & Additions,
77
+ res: EnvoyResponse,
78
+ ) => Result;
72
79
 
73
80
  /**
74
81
  * Handle a "migration" route.
75
82
  * @category Handler
76
83
  */
77
- export type MigrationRouteHandler<OldConfig = SomeObject, NewConfig = SomeObject, Additions = SomeObject> =
78
- (req: EnvoyMigrationRouteRequest<OldConfig> & Additions, res: EnvoyResponse<NewConfig>) => Result;
84
+ export type MigrationRouteHandler<OldConfig = SomeObject, NewConfig = SomeObject, Additions = SomeObject> = (
85
+ req: EnvoyMigrationRouteRequest<OldConfig> & Additions,
86
+ res: EnvoyResponse<NewConfig>,
87
+ ) => Result;
79
88
 
80
89
  /**
81
90
  * Handle an "options" route.
82
91
  * @category Handler
83
92
  */
84
- export type OptionsRouteHandler<Config = SomeObject, Additions = SomeObject> =
85
- (req: EnvoyOptionsRouteRequest<Config> & Additions, res: EnvoyOptionsRouteResponse) => Result;
93
+ export type OptionsRouteHandler<Config = SomeObject, Additions = SomeObject> = (
94
+ req: EnvoyOptionsRouteRequest<Config> & Additions,
95
+ res: EnvoyOptionsRouteResponse,
96
+ ) => Result;
86
97
 
87
98
  /**
88
99
  * Handle a "remote value" route.
89
100
  * @category Handler
90
101
  */
91
- export type RemoteValueRouteHandler<Config = SomeObject, Additions = SomeObject> =
92
- (req: EnvoyRemoteValueRouteRequest<Config> & Additions, res: EnvoyRemoteValueRouteResponse) => Result;
102
+ export type RemoteValueRouteHandler<Config = SomeObject, Additions = SomeObject> = (
103
+ req: EnvoyRemoteValueRouteRequest<Config> & Additions,
104
+ res: EnvoyRemoteValueRouteResponse,
105
+ ) => Result;
93
106
 
94
107
  /**
95
108
  * Handle a "selected values" route.
96
109
  * @category Handler
97
110
  */
98
- export type SelectedValuesRouteHandler<Config = SomeObject, Additions = SomeObject> =
99
- (req: EnvoySelectedValuesRouteRequest<Config> & Additions, res: EnvoySelectedValuesRouteResponse) => Result;
111
+ export type SelectedValuesRouteHandler<Config = SomeObject, Additions = SomeObject> = (
112
+ req: EnvoySelectedValuesRouteRequest<Config> & Additions,
113
+ res: EnvoySelectedValuesRouteResponse,
114
+ ) => Result;
100
115
 
101
116
  /**
102
117
  * Handle a "validation" route.
103
118
  * @category Handler
104
119
  */
105
- export type ValidationRouteHandler<Config = SomeObject, Payload = SomeObject, Additions = SomeObject> =
106
- (req: EnvoyValidationRouteRequest<Payload, Config> & Additions, res: EnvoyValidationRouteResponse<Config>) => Result;
120
+ export type ValidationRouteHandler<Config = SomeObject, Payload = SomeObject, Additions = SomeObject> = (
121
+ req: EnvoyValidationRouteRequest<Payload, Config> & Additions,
122
+ res: EnvoyValidationRouteResponse<Config>,
123
+ ) => Result;
107
124
 
108
125
  /**
109
126
  * Wraps any express.js-based handlers
@@ -112,11 +129,15 @@ export type ValidationRouteHandler<Config = SomeObject, Payload = SomeObject, Ad
112
129
  * @category Handler
113
130
  */
114
131
  // eslint-disable-next-line max-len
115
- export function asyncHandler<Req extends Request, Res extends Response>(handler: (req: Req, res: Res) => Result): RequestHandler {
132
+ export function asyncHandler<Req extends Request, Res extends Response>(
133
+ handler: (req: Req, res: Res) => Result,
134
+ ): RequestHandler {
116
135
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
117
136
  // @ts-ignore
118
137
  return (req: Req, res: Res, next: NextFunction): void => {
119
- void Promise.resolve().then(() => handler(req, res)).catch(next);
138
+ void Promise.resolve()
139
+ .then(() => handler(req, res))
140
+ .catch(next);
120
141
  };
121
142
  }
122
143
 
@@ -125,10 +146,9 @@ export function asyncHandler<Req extends Request, Res extends Response>(handler:
125
146
  *
126
147
  * @category Handler
127
148
  */
128
- export function entryEventHandler<
129
- Config = SomeObject,
130
- Additions = SomeObject,
131
- >(handler: EntryEventHandler<Config, Additions>) {
149
+ export function entryEventHandler<Config = SomeObject, Additions = SomeObject>(
150
+ handler: EntryEventHandler<Config, Additions>,
151
+ ) {
132
152
  return asyncHandler(handler);
133
153
  }
134
154
 
@@ -137,10 +157,9 @@ export function entryEventHandler<
137
157
  *
138
158
  * @category Handler
139
159
  */
140
- export function inviteEventHandler<
141
- Config = SomeObject,
142
- Additions = SomeObject,
143
- >(handler: InviteEventHandler<Config, Additions>) {
160
+ export function inviteEventHandler<Config = SomeObject, Additions = SomeObject>(
161
+ handler: InviteEventHandler<Config, Additions>,
162
+ ) {
144
163
  return asyncHandler(handler);
145
164
  }
146
165
 
@@ -149,10 +168,9 @@ export function inviteEventHandler<
149
168
  *
150
169
  * @category Handler
151
170
  */
152
- export function locationEventHandler<
153
- Config = SomeObject,
154
- Additions = SomeObject,
155
- >(handler: LocationEventHandler<Config, Additions>) {
171
+ export function locationEventHandler<Config = SomeObject, Additions = SomeObject>(
172
+ handler: LocationEventHandler<Config, Additions>,
173
+ ) {
156
174
  return asyncHandler(handler);
157
175
  }
158
176
 
@@ -161,11 +179,9 @@ export function locationEventHandler<
161
179
  *
162
180
  * @category Handler
163
181
  */
164
- export function migrationRouteHandler<
165
- OldConfig,
166
- NewConfig,
167
- Additions = SomeObject,
168
- >(handler: MigrationRouteHandler<OldConfig, NewConfig, Additions>) {
182
+ export function migrationRouteHandler<OldConfig, NewConfig, Additions = SomeObject>(
183
+ handler: MigrationRouteHandler<OldConfig, NewConfig, Additions>,
184
+ ) {
169
185
  return asyncHandler(handler);
170
186
  }
171
187
 
@@ -174,10 +190,9 @@ export function migrationRouteHandler<
174
190
  *
175
191
  * @category Handler
176
192
  */
177
- export function notificationEventHandler<
178
- Config = SomeObject,
179
- Additions = SomeObject,
180
- >(handler: NotificationEventHandler<Config, Additions>) {
193
+ export function notificationEventHandler<Config = SomeObject, Additions = SomeObject>(
194
+ handler: NotificationEventHandler<Config, Additions>,
195
+ ) {
181
196
  return asyncHandler(handler);
182
197
  }
183
198
 
@@ -186,10 +201,9 @@ export function notificationEventHandler<
186
201
  *
187
202
  * @category Handler
188
203
  */
189
- export function takeoverEventHandler<
190
- Config = SomeObject,
191
- Additions = SomeObject,
192
- >(handler: TakeoverEventHandler<Config, Additions>) {
204
+ export function takeoverEventHandler<Config = SomeObject, Additions = SomeObject>(
205
+ handler: TakeoverEventHandler<Config, Additions>,
206
+ ) {
193
207
  return asyncHandler(handler);
194
208
  }
195
209
 
@@ -198,10 +212,9 @@ export function takeoverEventHandler<
198
212
  *
199
213
  * @category Handler
200
214
  */
201
- export function optionsRouteHandler<
202
- Config = SomeObject,
203
- Additions = SomeObject,
204
- >(handler: OptionsRouteHandler<Config, Additions>) {
215
+ export function optionsRouteHandler<Config = SomeObject, Additions = SomeObject>(
216
+ handler: OptionsRouteHandler<Config, Additions>,
217
+ ) {
205
218
  return asyncHandler(handler);
206
219
  }
207
220
 
@@ -210,10 +223,9 @@ export function optionsRouteHandler<
210
223
  *
211
224
  * @category Handler
212
225
  */
213
- export function pluginUninstalledEventHandler<
214
- Config = SomeObject,
215
- Additions = SomeObject,
216
- >(handler: PluginUninstalledEventHandler<Config, Additions>) {
226
+ export function pluginUninstalledEventHandler<Config = SomeObject, Additions = SomeObject>(
227
+ handler: PluginUninstalledEventHandler<Config, Additions>,
228
+ ) {
217
229
  return asyncHandler(handler);
218
230
  }
219
231
 
@@ -222,10 +234,9 @@ export function pluginUninstalledEventHandler<
222
234
  *
223
235
  * @category Handler
224
236
  */
225
- export function remoteValueRouteHandler<
226
- Config = SomeObject,
227
- Additions = SomeObject,
228
- >(handler: RemoteValueRouteHandler<Config, Additions>) {
237
+ export function remoteValueRouteHandler<Config = SomeObject, Additions = SomeObject>(
238
+ handler: RemoteValueRouteHandler<Config, Additions>,
239
+ ) {
229
240
  return asyncHandler(handler);
230
241
  }
231
242
 
@@ -234,10 +245,9 @@ export function remoteValueRouteHandler<
234
245
  *
235
246
  * @category Handler
236
247
  */
237
- export function selectedValuesRouteHandler<
238
- Config = SomeObject,
239
- Additions = SomeObject,
240
- >(handler: SelectedValuesRouteHandler<Config, Additions>) {
248
+ export function selectedValuesRouteHandler<Config = SomeObject, Additions = SomeObject>(
249
+ handler: SelectedValuesRouteHandler<Config, Additions>,
250
+ ) {
241
251
  return asyncHandler(handler);
242
252
  }
243
253
 
@@ -246,10 +256,8 @@ export function selectedValuesRouteHandler<
246
256
  *
247
257
  * @category Handler
248
258
  */
249
- export function validationRouteHandler<
250
- Config = SomeObject,
251
- Payload = SomeObject,
252
- Additions = SomeObject,
253
- >(handler: ValidationRouteHandler<Config, Payload, Additions>) {
259
+ export function validationRouteHandler<Config = SomeObject, Payload = SomeObject, Additions = SomeObject>(
260
+ handler: ValidationRouteHandler<Config, Payload, Additions>,
261
+ ) {
254
262
  return asyncHandler(handler);
255
263
  }
@@ -3,7 +3,7 @@ import chalk from 'chalk';
3
3
  import util from 'util';
4
4
 
5
5
  function envoyAxiosRequestLogger(config: AxiosRequestConfig) {
6
- const log = console.log;
6
+ const { log } = console;
7
7
  log('---------------- Axios Request ----------------\n');
8
8
  if (config?.method) {
9
9
  const boldMethodText = chalk.bold('Method:');
@@ -27,7 +27,7 @@ function envoyAxiosRequestLogger(config: AxiosRequestConfig) {
27
27
  default:
28
28
  log(`${boldMethodText} ${method}\n`);
29
29
  break;
30
- };
30
+ }
31
31
  }
32
32
  if (config?.baseURL && config?.url) {
33
33
  log(`${chalk.bold('URL')}: ${config.baseURL}/${config.url}\n`);
@@ -55,11 +55,11 @@ function envoyAxiosRequestLogger(config: AxiosRequestConfig) {
55
55
  }
56
56
 
57
57
  function envoyAxiosResponseLogger(response: AxiosResponse) {
58
- const log = console.log;
58
+ const { log } = console;
59
59
  log('---------------- Axios Response ----------------\n');
60
60
  if (response?.request?.method) {
61
61
  const boldMethodText = chalk.bold('Method:');
62
- const method = response.request.method;
62
+ const { method } = response.request;
63
63
  switch (method) {
64
64
  case 'GET':
65
65
  log(`${boldMethodText} ${chalk.green(method)}\n`);
@@ -79,7 +79,7 @@ function envoyAxiosResponseLogger(response: AxiosResponse) {
79
79
  default:
80
80
  log(`${boldMethodText} ${method}\n`);
81
81
  break;
82
- };
82
+ }
83
83
  }
84
84
  if (response?.request?.baseURL && response?.request?.url) {
85
85
  log(`${chalk.bold('Request URL')}: ${response.request.baseURL}/${response.request.url}\n`);
@@ -88,9 +88,9 @@ function envoyAxiosResponseLogger(response: AxiosResponse) {
88
88
  if (response?.status && response?.statusText) {
89
89
  const boldStatusTitle = chalk.bold('Status:');
90
90
  const boldStatusTextTitle = chalk.bold('Status Text:');
91
- const status = response.status;
92
- const statusText = response.statusText;
93
- if (199 < status && status < 300) {
91
+ const { status } = response;
92
+ const { statusText } = response;
93
+ if (status > 199 && status < 300) {
94
94
  log(`${boldStatusTitle} ${chalk.green(status)}\n`);
95
95
  log(`${boldStatusTextTitle} ${chalk.green(statusText)}\n`);
96
96
  } else {
@@ -109,11 +109,11 @@ function envoyAxiosResponseLogger(response: AxiosResponse) {
109
109
  }
110
110
 
111
111
  function envoyAxiosErrorLogger(error: AxiosError) {
112
- const log = console.log;
112
+ const { log } = console;
113
113
  log('---------------- Axios Error ----------------\n');
114
114
  if (error?.request?.method) {
115
115
  const boldMethodText = chalk.bold('Method:');
116
- const method = error.request.method;
116
+ const { method } = error.request;
117
117
  switch (method) {
118
118
  case 'GET':
119
119
  log(`${boldMethodText} ${chalk.green(method)}\n`);
@@ -133,7 +133,7 @@ function envoyAxiosErrorLogger(error: AxiosError) {
133
133
  default:
134
134
  log(`${boldMethodText} ${method}\n`);
135
135
  break;
136
- };
136
+ }
137
137
  }
138
138
  if (error?.request?.baseURL && error?.request?.url) {
139
139
  log(`${chalk.bold('Request URL')}: ${error.request.baseURL}/${error.request.url}\n`);
@@ -142,9 +142,9 @@ function envoyAxiosErrorLogger(error: AxiosError) {
142
142
  if (error?.response?.status && error?.response?.statusText) {
143
143
  const boldStatusTitle = chalk.bold('Status:');
144
144
  const boldStatusTextTitle = chalk.bold('Status Text:');
145
- const status = error.response.status;
146
- const statusText = error.response.statusText;
147
- if (199 < status && status < 300) {
145
+ const { status } = error.response;
146
+ const { statusText } = error.response;
147
+ if (status > 199 && status < 300) {
148
148
  log(`${boldStatusTitle} ${chalk.green(status)}\n`);
149
149
  log(`${boldStatusTextTitle} ${chalk.green(statusText)}\n`);
150
150
  } else {
@@ -162,4 +162,4 @@ function envoyAxiosErrorLogger(error: AxiosError) {
162
162
  throw error;
163
163
  }
164
164
 
165
- export { envoyAxiosRequestLogger, envoyAxiosResponseLogger, envoyAxiosErrorLogger };
165
+ export { envoyAxiosRequestLogger, envoyAxiosResponseLogger, envoyAxiosErrorLogger };
@@ -1,11 +1,5 @@
1
1
  import bodyParser from 'body-parser';
2
- import {
3
- Request,
4
- Response,
5
- NextFunction,
6
- ErrorRequestHandler,
7
- RequestHandler,
8
- } from 'express';
2
+ import { Request, Response, NextFunction, ErrorRequestHandler, RequestHandler } from 'express';
9
3
 
10
4
  import HttpStatus from '../internal/HttpStatus';
11
5
  import EnvoySignatureVerifier, { EnvoySignatureVerifierOptions } from '../util/EnvoySignatureVerifier';
@@ -43,7 +37,7 @@ export function envoyMiddleware(options?: EnvoySignatureVerifierOptions): Reques
43
37
  if (now > threshold) {
44
38
  const { access_token: rawAccessToken, expires_in: expiresIn } = await EnvoyPluginAPI.loginAsPlugin();
45
39
  accessToken = rawAccessToken;
46
- threshold = now + (expiresIn * 1000) - (1000 * 60 * 10);
40
+ threshold = now + expiresIn * 1000 - 1000 * 60 * 10;
47
41
  }
48
42
  const envoyRequest = req as EnvoyRequest;
49
43
  const envoyResponse = res as EnvoyResponse;
@@ -61,7 +55,11 @@ export function envoyMiddleware(options?: EnvoySignatureVerifierOptions): Reques
61
55
  /**
62
56
  * Respond with "ignored" if no action will be performed.
63
57
  */
64
- envoyResponse.sendIgnored = (message = '', debugInfo: unknown = {}, ...attachments: Array<EnvoyPluginJobAttachment>) => {
58
+ envoyResponse.sendIgnored = (
59
+ message = '',
60
+ debugInfo: unknown = {},
61
+ ...attachments: Array<EnvoyPluginJobAttachment>
62
+ ) => {
65
63
  envoyResponse.statusCode = HttpStatus.IGNORED;
66
64
  envoyResponse.setHeader('Content-Type', 'application/json');
67
65
  envoyResponse.end(JSON.stringify({ message, debugInfo, attachments }));
@@ -70,7 +68,11 @@ export function envoyMiddleware(options?: EnvoySignatureVerifierOptions): Reques
70
68
  /**
71
69
  * Respond with "failed" in case of errors.
72
70
  */
73
- envoyResponse.sendFailed = (message = '', debugInfo: unknown = {}, ...attachments: Array<EnvoyPluginJobAttachment>) => {
71
+ envoyResponse.sendFailed = (
72
+ message = '',
73
+ debugInfo: unknown = {},
74
+ ...attachments: Array<EnvoyPluginJobAttachment>
75
+ ) => {
74
76
  envoyResponse.statusCode = HttpStatus.FAILED;
75
77
  envoyResponse.setHeader('Content-Type', 'application/json');
76
78
  envoyResponse.end(JSON.stringify({ message, debugInfo, attachments }));
@@ -6,10 +6,10 @@ import { envoyClientSecret } from '../constants';
6
6
  * @category Helper
7
7
  */
8
8
  export type EnvoySignatureVerifierOptions = {
9
- algorithm: 'sha256' | string,
10
- encoding: BinaryToTextEncoding,
11
- secret: string,
12
- header: 'x-envoy-signature' | string,
9
+ algorithm: 'sha256' | string;
10
+ encoding: BinaryToTextEncoding;
11
+ secret: string;
12
+ header: 'x-envoy-signature' | string;
13
13
  };
14
14
 
15
15
  const defaultOptions: EnvoySignatureVerifierOptions = {
@@ -39,12 +39,7 @@ export default class EnvoySignatureVerifier {
39
39
  * Verifies that the signature provided matches the request body.
40
40
  */
41
41
  verify(req: Request, rawBody: Buffer): boolean {
42
- const {
43
- algorithm,
44
- encoding,
45
- secret,
46
- header,
47
- } = this.options;
42
+ const { algorithm, encoding, secret, header } = this.options;
48
43
 
49
44
  if (!req.headers[header]) {
50
45
  return false;
@@ -53,9 +48,6 @@ export default class EnvoySignatureVerifier {
53
48
  const computedHmac = crypto.createHmac(algorithm, secret);
54
49
  computedHmac.update(rawBody);
55
50
 
56
- return crypto.timingSafeEqual(
57
- Buffer.from(receivedDigest),
58
- Buffer.from(computedHmac.digest(encoding)),
59
- );
51
+ return crypto.timingSafeEqual(Buffer.from(receivedDigest), Buffer.from(computedHmac.digest(encoding)));
60
52
  }
61
53
  }