@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.
Files changed (291) hide show
  1. package/README.md +178 -110
  2. package/dist/base/EnvoyAPI.d.ts +28 -0
  3. package/dist/base/EnvoyAPI.d.ts.map +1 -0
  4. package/dist/base/EnvoyAPI.js +121 -0
  5. package/dist/base/EnvoyPluginStoragePipeline.d.ts +51 -0
  6. package/dist/base/EnvoyPluginStoragePipeline.d.ts.map +1 -0
  7. package/dist/base/EnvoyPluginStoragePipeline.js +140 -0
  8. package/dist/constants.d.ts +5 -0
  9. package/dist/constants.d.ts.map +1 -0
  10. package/dist/constants.js +12 -0
  11. package/dist/factories/entryEventBodyFactory.d.ts +42 -0
  12. package/dist/factories/entryEventBodyFactory.d.ts.map +1 -0
  13. package/dist/factories/entryEventBodyFactory.js +105 -0
  14. package/dist/factories/eventBodyFactory.d.ts +18 -0
  15. package/dist/factories/eventBodyFactory.d.ts.map +1 -0
  16. package/dist/factories/eventBodyFactory.js +15 -0
  17. package/dist/factories/inviteEventBodyFactory.d.ts +38 -0
  18. package/dist/factories/inviteEventBodyFactory.d.ts.map +1 -0
  19. package/dist/factories/inviteEventBodyFactory.js +92 -0
  20. package/dist/factories/metaFactory.d.ts +10 -0
  21. package/dist/factories/metaFactory.d.ts.map +1 -0
  22. package/dist/factories/metaFactory.js +90 -0
  23. package/dist/factories/routeBodyFactory.d.ts +19 -0
  24. package/dist/factories/routeBodyFactory.d.ts.map +1 -0
  25. package/dist/factories/routeBodyFactory.js +15 -0
  26. package/dist/index.d.ts +52 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +74 -0
  29. package/dist/internal/EnvoyEntryEvent.d.ts +3 -0
  30. package/dist/internal/EnvoyEntryEvent.d.ts.map +1 -0
  31. package/dist/internal/EnvoyEntryEvent.js +2 -0
  32. package/dist/internal/EnvoyInviteEvent.d.ts +3 -0
  33. package/dist/internal/EnvoyInviteEvent.d.ts.map +1 -0
  34. package/dist/internal/EnvoyInviteEvent.js +2 -0
  35. package/dist/internal/EnvoyLocationEvent.d.ts +3 -0
  36. package/dist/internal/EnvoyLocationEvent.d.ts.map +1 -0
  37. package/dist/internal/EnvoyLocationEvent.js +2 -0
  38. package/dist/internal/EnvoyOption.d.ts +6 -0
  39. package/dist/internal/EnvoyOption.d.ts.map +1 -0
  40. package/dist/internal/EnvoyOption.js +2 -0
  41. package/dist/internal/EnvoyOptionsRouteParams.d.ts +7 -0
  42. package/dist/internal/EnvoyOptionsRouteParams.d.ts.map +1 -0
  43. package/dist/internal/EnvoyOptionsRouteParams.js +2 -0
  44. package/dist/internal/EnvoyOptionsRouteResponseBody.d.ts +4 -0
  45. package/dist/internal/EnvoyOptionsRouteResponseBody.d.ts.map +1 -0
  46. package/dist/internal/EnvoyOptionsRouteResponseBody.js +2 -0
  47. package/dist/internal/EnvoyPluginJobUpdate.d.ts +11 -0
  48. package/dist/internal/EnvoyPluginJobUpdate.d.ts.map +1 -0
  49. package/dist/internal/EnvoyPluginJobUpdate.js +2 -0
  50. package/dist/internal/EnvoyRemoteValueRouteResponseBody.d.ts +5 -0
  51. package/dist/internal/EnvoyRemoteValueRouteResponseBody.d.ts.map +1 -0
  52. package/dist/internal/EnvoyRemoteValueRouteResponseBody.js +2 -0
  53. package/dist/internal/EnvoySelectedValuesRouteParams.d.ts +5 -0
  54. package/dist/internal/EnvoySelectedValuesRouteParams.d.ts.map +1 -0
  55. package/dist/internal/EnvoySelectedValuesRouteParams.js +2 -0
  56. package/dist/internal/EnvoySelectedValuesRouteResponseBody.d.ts +4 -0
  57. package/dist/internal/EnvoySelectedValuesRouteResponseBody.d.ts.map +1 -0
  58. package/dist/internal/EnvoySelectedValuesRouteResponseBody.js +2 -0
  59. package/dist/internal/EnvoyStorageCommand.d.ts +42 -0
  60. package/dist/internal/EnvoyStorageCommand.d.ts.map +1 -0
  61. package/dist/internal/EnvoyStorageCommand.js +7 -0
  62. package/dist/internal/EnvoyStorageResult.d.ts +4 -0
  63. package/dist/internal/EnvoyStorageResult.d.ts.map +1 -0
  64. package/dist/internal/EnvoyStorageResult.js +2 -0
  65. package/dist/internal/HttpStatus.d.ts +13 -0
  66. package/dist/internal/HttpStatus.d.ts.map +1 -0
  67. package/dist/internal/HttpStatus.js +15 -0
  68. package/dist/mocks/EnvoyPluginJobMock.d.ts +12 -0
  69. package/dist/mocks/EnvoyPluginJobMock.d.ts.map +1 -0
  70. package/dist/mocks/EnvoyPluginJobMock.js +60 -0
  71. package/dist/mocks/EnvoyPluginStoragePipelineMock.d.ts +24 -0
  72. package/dist/mocks/EnvoyPluginStoragePipelineMock.d.ts.map +1 -0
  73. package/dist/mocks/EnvoyPluginStoragePipelineMock.js +212 -0
  74. package/dist/payloads/EntryPayload.d.ts +80 -0
  75. package/dist/payloads/EntryPayload.d.ts.map +1 -0
  76. package/dist/payloads/EntryPayload.js +28 -0
  77. package/dist/payloads/InvitePayload.d.ts +66 -0
  78. package/dist/payloads/InvitePayload.d.ts.map +1 -0
  79. package/dist/payloads/InvitePayload.js +24 -0
  80. package/dist/payloads/LocationPayload.d.ts +7 -0
  81. package/dist/payloads/LocationPayload.d.ts.map +1 -0
  82. package/dist/payloads/LocationPayload.js +2 -0
  83. package/dist/payloads/NotificationPayload.d.ts +54 -0
  84. package/dist/payloads/NotificationPayload.d.ts.map +1 -0
  85. package/dist/payloads/NotificationPayload.js +2 -0
  86. package/dist/resources/AgreementPageResource.d.ts +17 -0
  87. package/dist/resources/AgreementPageResource.d.ts.map +1 -0
  88. package/dist/resources/AgreementPageResource.js +2 -0
  89. package/dist/resources/AgreementResource.d.ts +24 -0
  90. package/dist/resources/AgreementResource.d.ts.map +1 -0
  91. package/dist/resources/AgreementResource.js +2 -0
  92. package/dist/resources/CompanyResource.d.ts +19 -0
  93. package/dist/resources/CompanyResource.d.ts.map +1 -0
  94. package/dist/resources/CompanyResource.js +2 -0
  95. package/dist/resources/CompanyRoleResource.d.ts +8 -0
  96. package/dist/resources/CompanyRoleResource.d.ts.map +1 -0
  97. package/dist/resources/CompanyRoleResource.js +2 -0
  98. package/dist/resources/CurrentUserResource.d.ts +8 -0
  99. package/dist/resources/CurrentUserResource.d.ts.map +1 -0
  100. package/dist/resources/CurrentUserResource.js +2 -0
  101. package/dist/resources/EmployeeResource.d.ts +43 -0
  102. package/dist/resources/EmployeeResource.d.ts.map +1 -0
  103. package/dist/resources/EmployeeResource.js +2 -0
  104. package/dist/resources/FlowResource.d.ts +31 -0
  105. package/dist/resources/FlowResource.d.ts.map +1 -0
  106. package/dist/resources/FlowResource.js +2 -0
  107. package/dist/resources/InviteResource.d.ts +86 -0
  108. package/dist/resources/InviteResource.d.ts.map +1 -0
  109. package/dist/resources/InviteResource.js +2 -0
  110. package/dist/resources/LocationResource.d.ts +64 -0
  111. package/dist/resources/LocationResource.d.ts.map +1 -0
  112. package/dist/resources/LocationResource.js +2 -0
  113. package/dist/resources/LocationRoleResource.d.ts +8 -0
  114. package/dist/resources/LocationRoleResource.d.ts.map +1 -0
  115. package/dist/resources/LocationRoleResource.js +2 -0
  116. package/dist/resources/SignInFieldPageResource.d.ts +17 -0
  117. package/dist/resources/SignInFieldPageResource.d.ts.map +1 -0
  118. package/dist/resources/SignInFieldPageResource.js +2 -0
  119. package/dist/resources/SignInFieldResource.d.ts +33 -0
  120. package/dist/resources/SignInFieldResource.d.ts.map +1 -0
  121. package/dist/resources/SignInFieldResource.js +2 -0
  122. package/dist/resources/UserResource.d.ts +13 -0
  123. package/dist/resources/UserResource.d.ts.map +1 -0
  124. package/dist/resources/UserResource.js +2 -0
  125. package/dist/sdk/EnvoyMeta.d.ts +96 -0
  126. package/dist/sdk/EnvoyMeta.d.ts.map +1 -0
  127. package/dist/sdk/EnvoyMeta.js +2 -0
  128. package/dist/sdk/EnvoyPluginAPI.d.ts +31 -0
  129. package/dist/sdk/EnvoyPluginAPI.d.ts.map +1 -0
  130. package/dist/sdk/EnvoyPluginAPI.js +205 -0
  131. package/dist/sdk/EnvoyPluginJob.d.ts +49 -0
  132. package/dist/sdk/EnvoyPluginJob.d.ts.map +1 -0
  133. package/dist/sdk/EnvoyPluginJob.js +99 -0
  134. package/dist/sdk/EnvoyPluginJobAttachment.d.ts +43 -0
  135. package/dist/sdk/EnvoyPluginJobAttachment.d.ts.map +1 -0
  136. package/dist/sdk/EnvoyPluginJobAttachment.js +2 -0
  137. package/dist/sdk/EnvoyPluginSDK.d.ts +100 -0
  138. package/dist/sdk/EnvoyPluginSDK.d.ts.map +1 -0
  139. package/dist/sdk/EnvoyPluginSDK.js +204 -0
  140. package/dist/sdk/EnvoyPluginStorage.d.ts +69 -0
  141. package/dist/sdk/EnvoyPluginStorage.d.ts.map +1 -0
  142. package/dist/sdk/EnvoyPluginStorage.js +78 -0
  143. package/dist/sdk/EnvoyRequest.d.ts +116 -0
  144. package/dist/sdk/EnvoyRequest.d.ts.map +1 -0
  145. package/dist/sdk/EnvoyRequest.js +7 -0
  146. package/dist/sdk/EnvoyResponse.d.ts +42 -0
  147. package/dist/sdk/EnvoyResponse.d.ts.map +1 -0
  148. package/dist/sdk/EnvoyResponse.js +2 -0
  149. package/dist/sdk/EnvoyStorageItem.d.ts +9 -0
  150. package/dist/sdk/EnvoyStorageItem.d.ts.map +1 -0
  151. package/dist/sdk/EnvoyStorageItem.js +2 -0
  152. package/dist/sdk/EnvoyUserAPI.d.ts +119 -0
  153. package/dist/sdk/EnvoyUserAPI.d.ts.map +1 -0
  154. package/dist/sdk/EnvoyUserAPI.js +493 -0
  155. package/dist/sdk/filters.d.ts +30 -0
  156. package/dist/sdk/filters.d.ts.map +1 -0
  157. package/dist/sdk/filters.js +72 -0
  158. package/dist/sdk/handlers.d.ts +125 -0
  159. package/dist/sdk/handlers.d.ts.map +1 -0
  160. package/dist/sdk/handlers.js +108 -0
  161. package/dist/sdk/loggers.d.ts +6 -0
  162. package/dist/sdk/loggers.d.ts.map +1 -0
  163. package/dist/sdk/loggers.js +161 -0
  164. package/dist/sdk/middleware.d.ts +19 -0
  165. package/dist/sdk/middleware.d.ts.map +1 -0
  166. package/dist/sdk/middleware.js +159 -0
  167. package/dist/util/EnvoyJWT.d.ts +17 -0
  168. package/dist/util/EnvoyJWT.d.ts.map +1 -0
  169. package/dist/util/EnvoyJWT.js +54 -0
  170. package/dist/util/EnvoySignatureVerifier.d.ts +26 -0
  171. package/dist/util/EnvoySignatureVerifier.d.ts.map +1 -0
  172. package/dist/util/EnvoySignatureVerifier.js +53 -0
  173. package/dist/util/axiosConstructor.d.ts +4 -0
  174. package/dist/util/axiosConstructor.d.ts.map +1 -0
  175. package/dist/util/axiosConstructor.js +58 -0
  176. package/dist/util/errorHandling.d.ts +2 -0
  177. package/dist/util/errorHandling.d.ts.map +1 -0
  178. package/dist/util/errorHandling.js +18 -0
  179. package/dist/util/json-api/JSONAPIData.d.ts +5 -0
  180. package/dist/util/json-api/JSONAPIData.d.ts.map +1 -0
  181. package/dist/util/json-api/JSONAPIData.js +2 -0
  182. package/dist/util/json-api/JSONAPIFilterParams.d.ts +5 -0
  183. package/dist/util/json-api/JSONAPIFilterParams.d.ts.map +1 -0
  184. package/dist/util/json-api/JSONAPIFilterParams.js +2 -0
  185. package/dist/util/json-api/JSONAPIModel.d.ts +10 -0
  186. package/dist/util/json-api/JSONAPIModel.d.ts.map +1 -0
  187. package/dist/util/json-api/JSONAPIModel.js +2 -0
  188. package/dist/util/json-api/JSONAPIPaginationParams.d.ts +9 -0
  189. package/dist/util/json-api/JSONAPIPaginationParams.d.ts.map +1 -0
  190. package/dist/util/json-api/JSONAPIPaginationParams.js +2 -0
  191. package/dist/util/json-api/JSONAPIParams.d.ts +4 -0
  192. package/dist/util/json-api/JSONAPIParams.d.ts.map +1 -0
  193. package/dist/util/json-api/JSONAPIParams.js +2 -0
  194. package/dist/util/json-api/JSONAPIResponse.d.ts +6 -0
  195. package/dist/util/json-api/JSONAPIResponse.d.ts.map +1 -0
  196. package/dist/util/json-api/JSONAPIResponse.js +2 -0
  197. package/package.json +48 -13
  198. package/src/base/EnvoyAPI.ts +87 -0
  199. package/src/base/EnvoyPluginStoragePipeline.ts +99 -0
  200. package/src/constants.ts +7 -0
  201. package/src/factories/entryEventBodyFactory.ts +124 -0
  202. package/src/factories/eventBodyFactory.ts +35 -0
  203. package/src/factories/inviteEventBodyFactory.ts +107 -0
  204. package/src/factories/metaFactory.ts +109 -0
  205. package/src/factories/routeBodyFactory.ts +37 -0
  206. package/src/index.ts +86 -0
  207. package/src/internal/EnvoyEntryEvent.ts +10 -0
  208. package/src/internal/EnvoyInviteEvent.ts +13 -0
  209. package/src/internal/EnvoyLocationEvent.ts +3 -0
  210. package/src/internal/EnvoyOption.ts +6 -0
  211. package/src/internal/EnvoyOptionsRouteParams.ts +7 -0
  212. package/src/internal/EnvoyOptionsRouteResponseBody.ts +4 -0
  213. package/src/internal/EnvoyPluginJobUpdate.ts +11 -0
  214. package/src/internal/EnvoyRemoteValueRouteResponseBody.ts +4 -0
  215. package/src/internal/EnvoySelectedValuesRouteParams.ts +5 -0
  216. package/src/internal/EnvoySelectedValuesRouteResponseBody.ts +4 -0
  217. package/src/internal/EnvoyStorageCommand.ts +60 -0
  218. package/src/internal/EnvoyStorageResult.ts +5 -0
  219. package/src/internal/HttpStatus.ts +12 -0
  220. package/src/mocks/EnvoyPluginJobMock.ts +33 -0
  221. package/src/mocks/EnvoyPluginStoragePipelineMock.ts +204 -0
  222. package/src/payloads/EntryPayload.ts +101 -0
  223. package/src/payloads/InvitePayload.ts +79 -0
  224. package/src/payloads/LocationPayload.ts +8 -0
  225. package/src/payloads/NotificationPayload.ts +54 -0
  226. package/src/resources/AgreementPageResource.ts +19 -0
  227. package/src/resources/AgreementResource.ts +26 -0
  228. package/src/resources/CompanyResource.ts +21 -0
  229. package/src/resources/CompanyRoleResource.ts +10 -0
  230. package/src/resources/CurrentUserResource.ts +10 -0
  231. package/src/resources/EmployeeResource.ts +47 -0
  232. package/src/resources/FlowResource.ts +35 -0
  233. package/src/resources/InviteResource.ts +92 -0
  234. package/src/resources/LocationResource.ts +68 -0
  235. package/src/resources/LocationRoleResource.ts +10 -0
  236. package/src/resources/SignInFieldPageResource.ts +23 -0
  237. package/src/resources/SignInFieldResource.ts +35 -0
  238. package/src/resources/UserResource.ts +14 -0
  239. package/src/sdk/EnvoyMeta.ts +101 -0
  240. package/src/sdk/EnvoyPluginAPI.ts +95 -0
  241. package/src/sdk/EnvoyPluginJob.ts +90 -0
  242. package/src/sdk/EnvoyPluginJobAttachment.ts +48 -0
  243. package/src/sdk/EnvoyPluginSDK.ts +185 -0
  244. package/src/sdk/EnvoyPluginStorage.ts +83 -0
  245. package/src/sdk/EnvoyRequest.ts +145 -0
  246. package/src/sdk/EnvoyResponse.ts +46 -0
  247. package/src/sdk/EnvoyStorageItem.ts +9 -0
  248. package/src/sdk/EnvoyUserAPI.ts +339 -0
  249. package/src/sdk/filters.ts +96 -0
  250. package/src/sdk/handlers.ts +234 -0
  251. package/src/sdk/loggers.ts +165 -0
  252. package/src/sdk/middleware.ts +101 -0
  253. package/src/util/EnvoyJWT.ts +51 -0
  254. package/src/util/EnvoySignatureVerifier.ts +61 -0
  255. package/src/util/axiosConstructor.ts +46 -0
  256. package/src/util/errorHandling.ts +15 -0
  257. package/src/util/json-api/JSONAPIData.ts +4 -0
  258. package/src/util/json-api/JSONAPIFilterParams.ts +5 -0
  259. package/src/util/json-api/JSONAPIModel.ts +10 -0
  260. package/src/util/json-api/JSONAPIPaginationParams.ts +12 -0
  261. package/src/util/json-api/JSONAPIParams.ts +3 -0
  262. package/src/util/json-api/JSONAPIResponse.ts +5 -0
  263. package/.eslintrc.js +0 -46
  264. package/.github/workflows/package.yaml +0 -43
  265. package/.github/workflows/test.yaml +0 -15
  266. package/asynchandler.md +0 -46
  267. package/envoyapi.md +0 -150
  268. package/envoyjwt.md +0 -46
  269. package/envoypluginjob.md +0 -106
  270. package/envoypluginsdk.md +0 -87
  271. package/envoypluginstorage.md +0 -95
  272. package/envoypluginstoragepipeline.md +0 -125
  273. package/envoysignatureverifier.md +0 -43
  274. package/errormiddleware.md +0 -41
  275. package/index.js +0 -49
  276. package/lib/EnvoyAPI.js +0 -564
  277. package/lib/EnvoyJWT.js +0 -72
  278. package/lib/EnvoyPluginJob.js +0 -124
  279. package/lib/EnvoyPluginSDK.js +0 -192
  280. package/lib/EnvoyPluginStorage.js +0 -121
  281. package/lib/EnvoyPluginStoragePipeline.js +0 -155
  282. package/lib/EnvoyResponseError.js +0 -18
  283. package/lib/EnvoySignatureVerifier.js +0 -67
  284. package/lib/HttpStatus.js +0 -20
  285. package/lib/asyncHandler.js +0 -17
  286. package/lib/axios.js +0 -34
  287. package/lib/errorMiddleware.js +0 -27
  288. package/lib/middleware.js +0 -110
  289. package/middleware.md +0 -53
  290. package/test/axios.test.js +0 -57
  291. package/test/promises.test.js +0 -82
package/lib/axios.js DELETED
@@ -1,34 +0,0 @@
1
- const { AxiosError } = require('axios');
2
- const axios = require('axios');
3
-
4
- function createAxiosClient(config) {
5
- const client = axios.create(config);
6
- client.interceptors.response.use(
7
- (response) => {
8
- return response
9
- },
10
- (error) => {
11
- const safeError = {
12
- code: error.code,
13
- response: {
14
- code: error.response?.code,
15
- status: error.response?.status,
16
- statusText: error.response?.statusText,
17
- data: error.response?.data,
18
- },
19
- message: error.message,
20
- name: error.name,
21
- baseURL: error.request?.baseURL ?? error.config?.baseURL,
22
- url: error.request?.url ?? error.config?.url,
23
- method: error.request?.method ?? error.config?.method,
24
- stack: error.stack,
25
- data: error.data,
26
- }
27
- return Promise.reject(safeError);
28
- },
29
- );
30
-
31
- return client;
32
- }
33
-
34
- module.exports = createAxiosClient;
@@ -1,27 +0,0 @@
1
- const HttpStatus = require('./HttpStatus');
2
-
3
- /**
4
- *
5
- * @param {Function} onError
6
- * @returns {Function}
7
- */
8
- function errorMiddleware(onError = () => {}) {
9
-
10
- /**
11
- * @param err
12
- * @param req
13
- * @param res
14
- * @param next
15
- */
16
- return (err, req, res, next) => {
17
- onError(err);
18
- if (res.headersSent) {
19
- return next(err);
20
- }
21
- res.statusCode = HttpStatus.UNEXPECTED_FAILURE;
22
- res.setHeader('Content-Type', 'application/json');
23
- res.end(JSON.stringify({ message: err.message }));
24
- };
25
- }
26
-
27
- module.exports = errorMiddleware;
package/lib/middleware.js DELETED
@@ -1,110 +0,0 @@
1
- const bodyParser = require('body-parser');
2
- const EnvoyAPI = require('./EnvoyAPI');
3
- const EnvoyPluginSDK = require('./EnvoyPluginSDK');
4
- const EnvoySignatureVerifier = require('./EnvoySignatureVerifier');
5
- const HttpStatus = require('./HttpStatus');
6
-
7
- const VERIFIED = Symbol('verified');
8
-
9
- /**
10
- * Express/connect middleware.
11
- *
12
- * @callback connectMiddleware
13
- * @param req
14
- * @param res
15
- * @param {Function} next
16
- */
17
-
18
- /**
19
- * @typedef {Object} EnvoyRequest
20
- * @property {EnvoyPluginSDK} envoy - the SDK
21
- */
22
-
23
- /**
24
- * @typedef {Object} EnvoyResponse
25
- * @property {Function} sendOngoing
26
- * @property {Function} sendIgnored
27
- * @property {Function} sendFailed
28
- */
29
-
30
- /**
31
- * Returns an instance of bodyParser.json,
32
- * which also verifies that the request came from Envoy.
33
- *
34
- * @param {SignatureVerifierOptions} [options]
35
- * @returns {connectMiddleware}
36
- */
37
- function middleware(options) {
38
-
39
- const signatureVerifier = new EnvoySignatureVerifier(options);
40
- const verify = (req, res, rawBody) => {
41
-
42
- req[VERIFIED] = signatureVerifier.verify(req, rawBody);
43
- };
44
- const json = bodyParser.json({ verify });
45
- let accessToken = null;
46
- let threshold = 0;
47
-
48
- return (req, res, next) => {
49
-
50
- json(req, res, async err => {
51
-
52
- if (err) {
53
- return next(err);
54
- }
55
- try {
56
- const now = Date.now();
57
- if (now > threshold) {
58
- const {
59
- access_token: rawAccessToken,
60
- expires_in: expiresIn,
61
- } = await EnvoyAPI.login();
62
- accessToken = rawAccessToken;
63
- threshold = now + (expiresIn * 1000) - (1000 * 60 * 10);
64
- }
65
-
66
- /**
67
- * @type {EnvoyPluginSDK}
68
- */
69
- req.envoy = new EnvoyPluginSDK(req.body, req[VERIFIED], accessToken);
70
- /**
71
- * @param {object} [data]
72
- */
73
- res.sendOngoing = (data = {}) => {
74
- res.statusCode = HttpStatus.ONGOING;
75
- res.setHeader('Content-Type', 'application/json');
76
- res.end(JSON.stringify(data));
77
- };
78
- /**
79
- * @param {string} [message]
80
- * @param {object} [data]
81
- */
82
- res.sendIgnored = (message = '', data = {}) => {
83
- if (message && data.message) {
84
- console.warn('Data to be sent already has a message.');
85
- }
86
- res.statusCode = HttpStatus.IGNORED;
87
- res.setHeader('Content-Type', 'application/json');
88
- res.end(JSON.stringify(Object.assign({ message }, data)));
89
- };
90
- /**
91
- * @param {string} [message]
92
- * @param {object} [data]
93
- */
94
- res.sendFailed = (message = '', data = {}) => {
95
- if (message && data.message) {
96
- console.warn('Data to be sent already has a message.');
97
- }
98
- res.statusCode = HttpStatus.FAILED;
99
- res.setHeader('Content-Type', 'application/json');
100
- res.end(JSON.stringify(Object.assign({ message }, data)));
101
- };
102
- next();
103
- } catch (err) {
104
- next(err);
105
- }
106
- });
107
- };
108
- }
109
-
110
- module.exports = middleware;
package/middleware.md DELETED
@@ -1,53 +0,0 @@
1
- ---
2
- description: Use this middleware to automatically and safely include Envoy in your plugin.
3
- ---
4
-
5
- # middleware
6
-
7
- ## Example
8
-
9
- ```javascript
10
- const express = require('express');
11
- const { middleware } = require('envoy-integrations-sdk-nodejs');
12
-
13
- const app = express();
14
- app.use(middleware());
15
- ```
16
-
17
- ## Functions
18
-
19
- ### middleware\(\[options\]\) ⇒ `connectMiddleware`
20
-
21
- Returns an instance of `bodyParser.json`, which also verifies that the request came from Envoy. It also attaches an instance of `EnvoyPluginSDK` attached to the `req` object, accessible at `req.envoy`.
22
-
23
- **Kind**: global function
24
-
25
- | Param | Type |
26
- | :--- | :--- |
27
- | \[options\] | `SignatureVerifierOptions` |
28
-
29
- ### Related Functions and Classes
30
-
31
- ### connectMiddleware : `function`
32
-
33
- Express/connect middleware.
34
-
35
- **Kind**: global typedef
36
-
37
- | Param | Type |
38
- | :--- | :--- |
39
- | req | [http://expressjs.com/en/4x/api.html\#req](http://expressjs.com/en/4x/api.html#req) |
40
- | res | [http://expressjs.com/en/4x/api.html\#res](http://expressjs.com/en/4x/api.html#res) |
41
- | next | `function` |
42
-
43
- ### SignatureVerifierOptions : `Object`
44
-
45
- **Properties**
46
-
47
- | Name | Type | Default |
48
- | :--- | :--- | :--- |
49
- | algorithm | `string` | `"sha256"` |
50
- | encoding | `string` | `"base64"` |
51
- | secret | `string` | `process.env.ENVOY_CLIENT_SECRET` |
52
- | header | `string` | `"x-envoy-signature"` |
53
-
@@ -1,57 +0,0 @@
1
- const axios = require('axios');
2
- const createClient = require('../lib/axios');
3
-
4
- describe('axios', () => {
5
- it('default client should leak credentials in AxiosError', async () => {
6
- const client = axios.create({
7
- headers: {
8
- Authorization: 'Bearer 1234',
9
- },
10
- proxy: {
11
- host: 'localhost',
12
- auth: {
13
- username: 'myWhackyUsername',
14
- password: 'myWhackyPassword',
15
- }
16
- }
17
- });
18
- try {
19
- await client.get('http://localhost:3000/axios-error');
20
- } catch (error) {
21
- expect(error.config).toBeDefined();
22
- const errorStr = JSON.stringify(error);
23
- expect(errorStr).toContain('Bearer 1234');
24
- expect(errorStr).toContain('myWhackyUsername');
25
- expect(errorStr).toContain('myWhackyPassword');
26
- }
27
- });
28
-
29
- it('should sanitize AxiosError response', async () => {
30
- const client = createClient({
31
- headers: {
32
- Authorization: 'Bearer 1234',
33
- },
34
- proxy: {
35
- host: 'localhost',
36
- auth: {
37
- username: 'myWhackyUsername',
38
- password: 'myWhackyPassword',
39
- }
40
- }
41
- });
42
- try {
43
- await client.get('http://localhost:3000/axios-error');
44
- } catch (error) {
45
- expect(error.config).toBeUndefined();
46
- expect(error.code).toBe('ECONNREFUSED');
47
- expect(error.message).toBe('connect ECONNREFUSED 127.0.0.1:80');
48
- expect(error.name).toBe('Error');
49
- expect(error.url).toBe('http://localhost:3000/axios-error');
50
- expect(error.method).toBe('get');
51
- const errorStr = JSON.stringify(error);
52
- expect(errorStr).not.toContain('Bearer 1234');
53
- expect(errorStr).not.toContain('myWhackyUsername');
54
- expect(errorStr).not.toContain('myWhackyPassword');
55
- }
56
- });
57
- });
@@ -1,82 +0,0 @@
1
- const request = require('request-promise-native');
2
- const EnvoyAPI = require('../lib/EnvoyAPI');
3
-
4
- describe('request-promise-native', () => {
5
- it('default client should leak credentials in error', async () => {
6
- const client = request.defaults({
7
- headers: {
8
- Authorization: 'Bearer 1234',
9
- },
10
- });
11
- try {
12
- await client('http://localhost:3000/axios-error');
13
- } catch (error) {
14
- expect(error.options).toBeDefined();
15
- const errorStr = JSON.stringify(error);
16
- expect(errorStr).toContain('Bearer 1234');
17
- }
18
- });
19
-
20
- it('should sanitize requests error response', async () => {
21
- const client = request.defaults({
22
- headers: {
23
- Authorization: 'Bearer 1234',
24
- },
25
- });
26
- try {
27
- await client('http://localhost:3000/axios-error').catch(EnvoyAPI.safeRequestsError);
28
- } catch (error) {
29
- expect(error.options).toBeUndefined();
30
- expect(error.message).toBe('Error: connect ECONNREFUSED 127.0.0.1:3000');
31
- expect(error.name).toBe('RequestError');
32
- const errorStr = JSON.stringify(error);
33
- expect(errorStr).not.toContain('Bearer 1234');
34
- }
35
- });
36
-
37
- it('should return rejected promise and leak credentials', () => {
38
- const client = request.defaults({
39
- headers: {
40
- Authorization: 'Bearer 1234',
41
- },
42
- });
43
- const response = client('http://localhost:3000/axios-error');
44
- response.then((data) => {
45
- expect(false).toBe(true);
46
- }).catch((error) => {
47
- expect(error.options).toBeDefined();
48
- const errorStr = JSON.stringify(error);
49
- expect(errorStr).toContain('Bearer 1234');
50
- });
51
- });
52
-
53
- it('should return rejected promise', () => {
54
- const client = request.defaults({
55
- headers: {
56
- Authorization: 'Bearer 1234',
57
- },
58
- });
59
- const response = client('http://localhost:3000/axios-error').catch(EnvoyAPI.safeRequestsError);
60
- response.then((data) => {
61
- expect(false).toBe(true);
62
- }).catch((error) => {
63
- expect(error.message).toBe('Error: connect ECONNREFUSED 127.0.0.1:3000');
64
- expect(error.name).toBe('RequestError');
65
- const errorStr = JSON.stringify(error);
66
- expect(errorStr).not.toContain('Bearer 1234');
67
- });
68
- });
69
-
70
- it('should make a successful request', async () => {
71
- const response = await request('https://httpstat.us/200').catch(EnvoyAPI.safeRequestsError);
72
- expect(response).toBe('200 OK');
73
- });
74
-
75
- it('should throw an error', async () => {
76
- try {
77
- await request('https://httpstat.us/500').catch(EnvoyAPI.safeRequestsError);
78
- } catch (error) {
79
- expect(error.message).toBe('500 - "500 Internal Server Error"');
80
- }
81
- });
82
- });