@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
@@ -0,0 +1,124 @@
1
+ import { Sync, each } from 'factory.ts';
2
+ import faker from 'faker';
3
+
4
+ import EntryPayload from '../payloads/EntryPayload';
5
+ import EnvoyEntryEvent from '../internal/EnvoyEntryEvent';
6
+ import { EnvoyUserAPIScope } from '../sdk/EnvoyUserAPI';
7
+ import eventBodyFactory from './eventBodyFactory';
8
+
9
+ export type EntryPayloadFactoryVisitorOptions = {
10
+ isProtectFlow: false,
11
+ isSignedIn: boolean,
12
+ hasEmail: boolean,
13
+ hasHost: boolean,
14
+ hasInvite: boolean,
15
+ hasDevice: boolean,
16
+ hasPhoneNumber?: boolean,
17
+ hasPhoto?: boolean,
18
+ };
19
+
20
+ export type EntryPayloadFactoryProtectOptions = {
21
+ isProtectFlow: true,
22
+ isSignedIn: boolean,
23
+ hasPhoneNumber?: boolean,
24
+ hasPhoto?: boolean,
25
+ };
26
+
27
+ export type EntryPayloadFactoryOptions = EntryPayloadFactoryVisitorOptions | EntryPayloadFactoryProtectOptions;
28
+
29
+ export const entryEventBodyFactoryDefaultIds = {
30
+ location: '1',
31
+ company: '1',
32
+ flow: '1',
33
+ invite: '1',
34
+ device: '1',
35
+ employee: '1',
36
+ };
37
+
38
+ export function entryPayloadFactory(
39
+ options: EntryPayloadFactoryOptions,
40
+ ids: Partial<typeof entryEventBodyFactoryDefaultIds> = entryEventBodyFactoryDefaultIds,
41
+ ): Sync.Factory<EntryPayload> {
42
+ const signedInDate = faker.date.past();
43
+ const allIds = { ...entryEventBodyFactoryDefaultIds, ...ids };
44
+ return Sync.makeFactory<EntryPayload>({
45
+ id: each((i) => `${i + 1}`),
46
+ type: 'entries',
47
+ attributes: {
48
+ 'full-name': faker.name.findName(),
49
+ 'phone-number': options.hasPhoneNumber ? faker.phone.phoneNumber() : undefined,
50
+ email: (options.isProtectFlow || options.hasEmail) ? faker.internet.email() : null,
51
+ 'employee-screening-flow': options.isProtectFlow,
52
+ host: (!options.isProtectFlow && options.hasHost) ? faker.name.findName() : null,
53
+ 'host-email': (!options.isProtectFlow && options.hasHost) ? faker.internet.email() : null,
54
+ 'private-notes': null,
55
+ 'signed-in-at': signedInDate.toISOString(),
56
+ 'signed-out-at': options.isSignedIn ? undefined : faker.date.between(signedInDate, new Date()).toISOString(),
57
+ thumbnails: options.hasPhoto ? {
58
+ large: faker.image.avatar(),
59
+ original: faker.image.avatar(),
60
+ small: faker.image.avatar(),
61
+ } : {
62
+ large: null,
63
+ original: null,
64
+ small: null,
65
+ },
66
+ 'flow-name': options.isProtectFlow ? 'Employee registration' : 'Visitor',
67
+ 'user-data': [] as Array<{ field: string, value: string | null }>,
68
+ },
69
+ relationships: {
70
+ location: {
71
+ data: {
72
+ id: allIds.location,
73
+ type: 'locations',
74
+ },
75
+ },
76
+ flow: {
77
+ data: {
78
+ id: allIds.flow,
79
+ type: 'flows',
80
+ },
81
+ },
82
+ invite: (options.isProtectFlow || options.hasInvite) ? {
83
+ data: {
84
+ id: allIds.invite,
85
+ type: 'invites',
86
+ },
87
+ } : undefined,
88
+ device: (!options.isProtectFlow && options.hasDevice) ? {
89
+ data: {
90
+ id: allIds.device,
91
+ type: 'devices',
92
+ },
93
+ } : undefined,
94
+ employee: (options.isProtectFlow || options.hasHost) ? {
95
+ data: {
96
+ id: allIds.employee,
97
+ type: 'employees',
98
+ },
99
+ } : undefined,
100
+ },
101
+ });
102
+ }
103
+
104
+ export type EntryEventBodyFactoryOptions<Config extends Record<string, unknown> = Record<string, never>> = {
105
+ event: EnvoyEntryEvent,
106
+ config: Partial<Config>,
107
+ payloadOptions: EntryPayloadFactoryOptions,
108
+ scope?: Array<EnvoyUserAPIScope>,
109
+ ids?: Partial<typeof entryEventBodyFactoryDefaultIds>,
110
+ };
111
+
112
+ export default function entryEventBodyFactory<Config extends Record<string, unknown> = Record<string, never>>(
113
+ options: EntryEventBodyFactoryOptions<Config>,
114
+ ) {
115
+ const ids = options.ids || entryEventBodyFactoryDefaultIds;
116
+ return eventBodyFactory<EnvoyEntryEvent, Config, EntryPayload>({
117
+ event: options.event,
118
+ config: options.config,
119
+ scope: options.scope || [],
120
+ locationId: options.ids?.location || entryEventBodyFactoryDefaultIds.location,
121
+ companyId: options.ids?.company || entryEventBodyFactoryDefaultIds.company,
122
+ payload: entryPayloadFactory(options.payloadOptions, ids).build(),
123
+ });
124
+ }
@@ -0,0 +1,35 @@
1
+ import { EnvoyUserAPIScope } from '../sdk/EnvoyUserAPI';
2
+ import { eventMetaFactory } from './metaFactory';
3
+
4
+ export const eventBodyFactoryDefaultIds = {
5
+ locationId: '1',
6
+ companyId: '1',
7
+ };
8
+
9
+ export type EventBodyFactoryOptions<Event, Config, Payload> = {
10
+ event: Event,
11
+ config: Partial<Config>,
12
+ payload: Payload,
13
+ scope: Array<EnvoyUserAPIScope>,
14
+ locationId?: string,
15
+ companyId?: string,
16
+ };
17
+
18
+ export default function eventBodyFactory<
19
+ Event extends string = string,
20
+ Config extends Record<string, unknown> = Record<string, never>,
21
+ Payload extends Record<string, unknown> = Record<string, never>,
22
+ >(
23
+ options: EventBodyFactoryOptions<Event, Config, Payload>,
24
+ ) {
25
+ return {
26
+ meta: eventMetaFactory<Config>(
27
+ options.event,
28
+ options.config,
29
+ options.scope,
30
+ options.locationId || eventBodyFactoryDefaultIds.locationId,
31
+ options.companyId || eventBodyFactoryDefaultIds.companyId,
32
+ ).build(),
33
+ payload: options.payload,
34
+ };
35
+ }
@@ -0,0 +1,107 @@
1
+ import { Sync, each } from 'factory.ts';
2
+ import faker from 'faker';
3
+
4
+ import InvitePayload from '../payloads/InvitePayload';
5
+ import EnvoyInviteEvent from '../internal/EnvoyInviteEvent';
6
+ import { EnvoyUserAPIScope } from '../sdk/EnvoyUserAPI';
7
+ import eventBodyFactory from './eventBodyFactory';
8
+
9
+ export type InvitePayloadFactoryVisitorOptions = {
10
+ isProtectFlow: false,
11
+ hasEmail: boolean,
12
+ hasHost: boolean,
13
+ preregistrationComplete: boolean,
14
+ hasPhoto?: boolean,
15
+ };
16
+
17
+ export type InvitePayloadFactoryProtectOptions = {
18
+ isProtectFlow: true,
19
+ preregistrationComplete: boolean,
20
+ hasPhoto?: boolean,
21
+ };
22
+
23
+ export type InvitePayloadFactoryOptions = InvitePayloadFactoryVisitorOptions | InvitePayloadFactoryProtectOptions;
24
+
25
+ export const inviteEventBodyFactoryDefaultIds = {
26
+ location: '1',
27
+ company: '1',
28
+ flow: '1',
29
+ invite: '1',
30
+ device: '1',
31
+ employee: '1',
32
+ };
33
+
34
+ export function invitePayloadFactory(
35
+ options: InvitePayloadFactoryOptions,
36
+ ids: Partial<typeof inviteEventBodyFactoryDefaultIds> = inviteEventBodyFactoryDefaultIds,
37
+ ): Sync.Factory<InvitePayload> {
38
+ const signedInDate = faker.date.past();
39
+ const allIds = { ...inviteEventBodyFactoryDefaultIds, ...ids };
40
+ return Sync.makeFactory<InvitePayload>({
41
+ id: each((i) => `${i + 1}`),
42
+ type: 'invites',
43
+ attributes: {
44
+ 'employee-screening-flow': options.isProtectFlow,
45
+ 'full-name': faker.name.findName(),
46
+ email: (options.isProtectFlow || options.hasEmail) ? faker.internet.email() : null,
47
+ 'inviter-name': (!options.isProtectFlow && options.hasHost) ? faker.name.findName() : null,
48
+ 'inviter-email': (!options.isProtectFlow && options.hasHost) ? faker.internet.email() : null,
49
+ 'expected-arrival-time': faker.date.future().toISOString(),
50
+ 'private-notes': null,
51
+ arrived: false,
52
+ 'been-here-before': false,
53
+ 'flow-name': options.isProtectFlow ? 'Employee registration' : 'Visitor',
54
+ 'flow-id': allIds.flow,
55
+ 'user-data': [] as Array<{ field: string, value: string | null }>,
56
+ 'secret-token': faker.random.alphaNumeric(10),
57
+ 'edit-token': faker.random.alphaNumeric(10),
58
+ 'photo-url': faker.image.avatar(),
59
+ 'qr-code': null,
60
+ 'qr-code-sent-at': null,
61
+ 'preregistration-complete': options.preregistrationComplete,
62
+ 'reminder-sent-at': null,
63
+ },
64
+ relationships: {
65
+ location: {
66
+ data: {
67
+ id: allIds.location,
68
+ type: 'locations',
69
+ },
70
+ },
71
+ flow: {
72
+ data: {
73
+ id: allIds.flow,
74
+ type: 'flows',
75
+ },
76
+ },
77
+ employee: (options.isProtectFlow || options.hasHost) ? {
78
+ data: {
79
+ id: allIds.employee,
80
+ type: 'employees',
81
+ },
82
+ } : undefined,
83
+ },
84
+ });
85
+ }
86
+
87
+ export type InviteEventBodyFactoryOptions<Config extends Record<string, unknown> = Record<string, never>> = {
88
+ event: EnvoyInviteEvent,
89
+ config: Partial<Config>,
90
+ payloadOptions: InvitePayloadFactoryOptions,
91
+ scope?: Array<EnvoyUserAPIScope>,
92
+ ids?: Partial<typeof inviteEventBodyFactoryDefaultIds>,
93
+ };
94
+
95
+ export default function entryEventBodyFactory<Config extends Record<string, unknown> = Record<string, never>>(
96
+ options: InviteEventBodyFactoryOptions<Config>,
97
+ ) {
98
+ const ids = options.ids || inviteEventBodyFactoryDefaultIds;
99
+ return eventBodyFactory<EnvoyInviteEvent, Config, InvitePayload>({
100
+ event: options.event,
101
+ config: options.config,
102
+ scope: options.scope || [],
103
+ locationId: options.ids?.location || inviteEventBodyFactoryDefaultIds.location,
104
+ companyId: options.ids?.company || inviteEventBodyFactoryDefaultIds.company,
105
+ payload: invitePayloadFactory(options.payloadOptions, ids).build(),
106
+ });
107
+ }
@@ -0,0 +1,109 @@
1
+ import { Sync } from 'factory.ts';
2
+ import faker from 'faker';
3
+ import {
4
+ EnvoyEventMeta,
5
+ EnvoyMetaAuth,
6
+ EnvoyMetaCompany,
7
+ EnvoyMetaJob,
8
+ EnvoyMetaLocation,
9
+ EnvoyRouteMeta,
10
+ } from '../sdk/EnvoyMeta';
11
+ import { EnvoyUserAPIScope } from '../sdk/EnvoyUserAPI';
12
+
13
+ export function jobFactory(name: string): Sync.Factory<EnvoyMetaJob> {
14
+ return Sync.makeFactory<EnvoyMetaJob>({
15
+ id: faker.datatype.uuid(),
16
+ identifier: faker.datatype.string(),
17
+ name,
18
+ });
19
+ }
20
+
21
+ export function locationFactory(id: string): Sync.Factory<EnvoyMetaLocation> {
22
+ const cityName = faker.address.cityName();
23
+ const street = faker.address.streetAddress();
24
+ return Sync.makeFactory<EnvoyMetaLocation>({
25
+ id,
26
+ type: 'locations',
27
+ attributes: {
28
+ name: cityName,
29
+ 'company-name-override': null,
30
+ timezone: faker.address.timeZone(),
31
+ locale: null,
32
+ address: street,
33
+ 'address-line-one': street,
34
+ 'address-line-two': null,
35
+ city: cityName,
36
+ state: faker.address.stateAbbr(),
37
+ country: faker.address.country(),
38
+ zip: faker.address.zipCode(),
39
+ longitude: null,
40
+ latitude: null,
41
+ 'created-at': faker.date.past().toISOString(),
42
+ },
43
+ });
44
+ }
45
+
46
+ export function companyFactory(id: string): Sync.Factory<EnvoyMetaCompany> {
47
+ return Sync.makeFactory<EnvoyMetaCompany>({
48
+ id,
49
+ type: 'companies',
50
+ attributes: {
51
+ name: faker.company.companyName(),
52
+ active: true,
53
+ 'created-at': faker.date.past().toISOString(),
54
+ },
55
+ });
56
+ }
57
+
58
+ export function authFactory(): Sync.Factory<EnvoyMetaAuth> {
59
+ return Sync.makeFactory<EnvoyMetaAuth>({
60
+ token_type: 'Bearer',
61
+ access_token: faker.random.alphaNumeric(),
62
+ expires_in: faker.date.future().getSeconds(),
63
+ refresh_token: null,
64
+ refresh_token_expires_in: null,
65
+ });
66
+ }
67
+
68
+ export function routeMetaFactory<
69
+ Config extends Record<string, unknown> = Record<string, never>,
70
+ Params extends Record<string, unknown> = Record<string, never>,
71
+ >(
72
+ route: string,
73
+ config: Partial<Config>,
74
+ params: Params,
75
+ scope: Array<EnvoyUserAPIScope>,
76
+ locationId: string,
77
+ companyId: string,
78
+ ): Sync.Factory<EnvoyRouteMeta> {
79
+ return Sync.makeFactory<EnvoyRouteMeta>({
80
+ plugin_id: faker.datatype.uuid(),
81
+ install_id: Math.ceil(Math.abs(faker.datatype.number())).toString(),
82
+ location: locationFactory(locationId).build(),
83
+ company: companyFactory(companyId).build(),
84
+ auth: scope.length ? authFactory().build() : null,
85
+ forwarded_bearer_token: faker.random.alphaNumeric(),
86
+ route,
87
+ config,
88
+ params,
89
+ });
90
+ }
91
+
92
+ export function eventMetaFactory<Config extends Record<string, unknown> = Record<string, never>>(
93
+ event: string,
94
+ config: Partial<Config>,
95
+ scope: Array<EnvoyUserAPIScope>,
96
+ locationId: string,
97
+ companyId: string,
98
+ ): Sync.Factory<EnvoyEventMeta> {
99
+ return Sync.makeFactory<EnvoyEventMeta>({
100
+ plugin_id: faker.datatype.uuid(),
101
+ install_id: Math.ceil(Math.abs(faker.datatype.number())).toString(),
102
+ job: jobFactory(event).build(),
103
+ location: locationFactory(locationId).build(),
104
+ company: companyFactory(companyId).build(),
105
+ auth: scope.length ? authFactory().build() : null,
106
+ event,
107
+ config,
108
+ });
109
+ }
@@ -0,0 +1,37 @@
1
+ import { EnvoyUserAPIScope } from '../sdk/EnvoyUserAPI';
2
+ import { routeMetaFactory } from './metaFactory';
3
+
4
+ export const routeBodyFactoryDefaultIds = {
5
+ locationId: '1',
6
+ companyId: '1',
7
+ };
8
+
9
+ export type RouteBodyFactoryOptions<Config, Params, Payload> = {
10
+ config: Partial<Config>,
11
+ params: Params,
12
+ payload: Payload,
13
+ scope?: Array<EnvoyUserAPIScope>,
14
+ locationId?: string,
15
+ companyId?: string,
16
+ route?: string,
17
+ };
18
+
19
+ export default function routeBodyFactory<
20
+ Config extends Record<string, unknown> = Record<string, never>,
21
+ Params extends Record<string, unknown> = Record<string, never>,
22
+ Payload extends Record<string, unknown> = Record<string, never>,
23
+ >(
24
+ options: RouteBodyFactoryOptions<Config, Params, Payload>,
25
+ ) {
26
+ return {
27
+ meta: routeMetaFactory<Config, Params>(
28
+ options.route || '',
29
+ options.config,
30
+ options.params,
31
+ options.scope || [],
32
+ options.locationId || routeBodyFactoryDefaultIds.locationId,
33
+ options.companyId || routeBodyFactoryDefaultIds.companyId,
34
+ ).build(),
35
+ payload: options.payload,
36
+ };
37
+ }
package/src/index.ts ADDED
@@ -0,0 +1,86 @@
1
+ import './constants';
2
+
3
+ import EnvoyPluginStoragePipeline from './base/EnvoyPluginStoragePipeline';
4
+
5
+ import entryEventBodyFactory from './factories/entryEventBodyFactory';
6
+ import eventBodyFactory from './factories/eventBodyFactory';
7
+ import inviteEventBodyFactory from './factories/inviteEventBodyFactory';
8
+ import routeBodyFactory from './factories/routeBodyFactory';
9
+
10
+ import HttpStatus from './internal/HttpStatus';
11
+
12
+ import EnvoyPluginJobMock from './mocks/EnvoyPluginJobMock';
13
+ import EnvoyPluginStoragePipelineMock from './mocks/EnvoyPluginStoragePipelineMock';
14
+
15
+ import EntryPayload from './payloads/EntryPayload';
16
+ import InvitePayload from './payloads/InvitePayload';
17
+
18
+ import EnvoyMeta from './sdk/EnvoyMeta';
19
+ import EnvoyPluginJob from './sdk/EnvoyPluginJob';
20
+ import EnvoyPluginSDK from './sdk/EnvoyPluginSDK';
21
+ import EnvoyPluginStorage from './sdk/EnvoyPluginStorage';
22
+ import EnvoyRequest from './sdk/EnvoyRequest';
23
+ import EnvoyResponse from './sdk/EnvoyResponse';
24
+ import EnvoyStorageItem from './sdk/EnvoyStorageItem';
25
+ import EnvoyUserAPI from './sdk/EnvoyUserAPI';
26
+ import EnvoyPluginAPI from './sdk/EnvoyPluginAPI';
27
+
28
+ import EnvoyJWT from './util/EnvoyJWT';
29
+ import EnvoySignatureVerifier from './util/EnvoySignatureVerifier';
30
+ import JSONAPIData from './util/json-api/JSONAPIData';
31
+
32
+ export * from './factories/entryEventBodyFactory';
33
+ export * from './factories/eventBodyFactory';
34
+ export * from './factories/inviteEventBodyFactory';
35
+ export * from './factories/metaFactory';
36
+ export * from './factories/routeBodyFactory';
37
+
38
+ export * from './resources/AgreementPageResource';
39
+ export * from './resources/AgreementResource';
40
+ export * from './resources/CompanyResource';
41
+ export * from './resources/CompanyRoleResource';
42
+ export * from './resources/CurrentUserResource';
43
+ export * from './resources/EmployeeResource';
44
+ export * from './resources/FlowResource';
45
+ export * from './resources/InviteResource';
46
+ export * from './resources/LocationResource';
47
+ export * from './resources/LocationRoleResource';
48
+ export * from './resources/SignInFieldPageResource';
49
+ export * from './resources/SignInFieldResource';
50
+ export * from './resources/UserResource';
51
+
52
+ export * from './sdk/EnvoyMeta';
53
+ export * from './sdk/EnvoyRequest';
54
+ export * from './sdk/EnvoyResponse';
55
+ export * from './sdk/filters';
56
+ export * from './sdk/handlers';
57
+ export * from './sdk/loggers';
58
+ export * from './sdk/middleware';
59
+
60
+ export * from './util/EnvoySignatureVerifier';
61
+ export * from './util/axiosConstructor';
62
+
63
+ export {
64
+ EntryPayload,
65
+ InvitePayload,
66
+ EnvoyJWT,
67
+ EnvoyMeta,
68
+ EnvoyPluginJob,
69
+ EnvoyPluginJobMock,
70
+ EnvoyPluginSDK,
71
+ EnvoyPluginStorage,
72
+ EnvoyPluginStoragePipeline,
73
+ EnvoyPluginStoragePipelineMock,
74
+ EnvoyRequest,
75
+ EnvoyResponse,
76
+ EnvoySignatureVerifier,
77
+ EnvoyStorageItem,
78
+ EnvoyPluginAPI,
79
+ EnvoyUserAPI,
80
+ JSONAPIData,
81
+ HttpStatus,
82
+ entryEventBodyFactory,
83
+ eventBodyFactory,
84
+ inviteEventBodyFactory,
85
+ routeBodyFactory,
86
+ };
@@ -0,0 +1,10 @@
1
+ type EnvoyEntryEvent =
2
+ 'entry_sign_in' |
3
+ 'entry_sign_out' |
4
+ 'entry_blacklist_review' |
5
+ 'entry_blacklist_deny' |
6
+ 'employee_entry_sign_in' |
7
+ 'employee_entry_sign_out' |
8
+ string;
9
+
10
+ export default EnvoyEntryEvent;
@@ -0,0 +1,13 @@
1
+ type EnvoyInviteEvent =
2
+ 'invite_created' |
3
+ 'invite_updated' |
4
+ 'invite_removed' |
5
+ 'upcoming_visit' |
6
+ 'qr_code_sent' |
7
+ 'employee_invite_created' |
8
+ 'employee_invite_updated' |
9
+ 'employee_invite_removed' |
10
+ 'employee_upcoming_visit' |
11
+ string;
12
+
13
+ export default EnvoyInviteEvent;
@@ -0,0 +1,3 @@
1
+ type EnvoyLocationEvent = 'location_capacity_updated' | string;
2
+
3
+ export default EnvoyLocationEvent;
@@ -0,0 +1,6 @@
1
+ type EnvoyOption = {
2
+ label: string,
3
+ value: string,
4
+ };
5
+
6
+ export default EnvoyOption;
@@ -0,0 +1,7 @@
1
+ type EnvoyOptionsRouteParams = {
2
+ search?: string,
3
+ page?: number,
4
+ cursor?: string,
5
+ };
6
+
7
+ export default EnvoyOptionsRouteParams;
@@ -0,0 +1,4 @@
1
+ import EnvoyOption from './EnvoyOption';
2
+
3
+ type EnvoyOptionsRouteResponseBody = Array<EnvoyOption>;
4
+ export default EnvoyOptionsRouteResponseBody;
@@ -0,0 +1,11 @@
1
+ import EnvoyPluginJobAttachment from '../sdk/EnvoyPluginJobAttachment';
2
+
3
+ /**
4
+ * @internal
5
+ */
6
+ export default interface EnvoyPluginJobUpdate {
7
+ status?: string,
8
+ status_message?: string,
9
+ failure_reason?: string,
10
+ attachments: Array<EnvoyPluginJobAttachment>,
11
+ }
@@ -0,0 +1,4 @@
1
+ type EnvoyRemoteValueRouteResponseBody = {
2
+ value: string,
3
+ };
4
+ export default EnvoyRemoteValueRouteResponseBody;
@@ -0,0 +1,5 @@
1
+ type EnvoySelectedValuesRouteParams = {
2
+ value: Array<string> | string,
3
+ };
4
+
5
+ export default EnvoySelectedValuesRouteParams;
@@ -0,0 +1,4 @@
1
+ import EnvoyOption from './EnvoyOption';
2
+
3
+ type EnvoySelectedValuesRouteResponseBody = Array<EnvoyOption> | EnvoyOption | null;
4
+ export default EnvoySelectedValuesRouteResponseBody;
@@ -0,0 +1,60 @@
1
+ export const UNIQUE_OPTIONS_DEFAULT_CHARS = '0123456789';
2
+
3
+ export const UNIQUE_OPTIONS_DEFAULT_SIZE = 12;
4
+
5
+ export const UNIQUE_NUM_OPTIONS_DEFAULT_MIN = 0;
6
+
7
+ export const UNIQUE_NUM_OPTIONS_DEFAULT_MAX = 9_007_199_254_740_991;
8
+
9
+ export interface EnvoyStorageSetUniqueOptions {
10
+ chars?: string,
11
+ size?: number,
12
+ }
13
+
14
+ export interface EnvoyStorageSetUniqueNumOptions {
15
+ min?: number,
16
+ max?: number,
17
+ }
18
+
19
+ export interface EnvoyBaseStorageCommand {
20
+ action: 'get' | 'set' | 'set_unique' | 'set_unique_num' | 'unset',
21
+ key: string,
22
+ }
23
+
24
+ export interface EnvoyGetStorageCommand extends EnvoyBaseStorageCommand {
25
+ action: 'get',
26
+ }
27
+
28
+ export interface EnvoySetStorageCommand extends EnvoyBaseStorageCommand {
29
+ action: 'set',
30
+ value: unknown,
31
+ }
32
+
33
+ export interface EnvoySetUniqueStorageCommand extends EnvoyBaseStorageCommand, EnvoyStorageSetUniqueOptions {
34
+ action: 'set_unique',
35
+ }
36
+
37
+ export interface EnvoySetUniqueNumStorageCommand extends EnvoyBaseStorageCommand, EnvoyStorageSetUniqueNumOptions {
38
+ action: 'set_unique_num',
39
+ }
40
+
41
+ export interface EnvoyUnsetStorageCommand extends EnvoyBaseStorageCommand {
42
+ action: 'unset',
43
+ }
44
+
45
+ export interface EnvoyListStorageCommand {
46
+ action: 'list',
47
+ page: number,
48
+ }
49
+
50
+ /**
51
+ * @internal
52
+ */
53
+ type EnvoyStorageCommand = EnvoyGetStorageCommand
54
+ | EnvoySetStorageCommand
55
+ | EnvoySetUniqueStorageCommand
56
+ | EnvoySetUniqueNumStorageCommand
57
+ | EnvoyUnsetStorageCommand
58
+ | EnvoyListStorageCommand;
59
+
60
+ export default EnvoyStorageCommand;
@@ -0,0 +1,5 @@
1
+ import EnvoyStorageItem from '../sdk/EnvoyStorageItem';
2
+
3
+ type EnvoyStorageResult<Value = unknown> = EnvoyStorageItem<Value> | Array<EnvoyStorageItem<Value>> | null;
4
+
5
+ export default EnvoyStorageResult;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Use these status codes to inform Envoy of a job's or route's status.
3
+ *
4
+ * @internal
5
+ */
6
+ enum HttpStatus {
7
+ ONGOING = 202,
8
+ IGNORED = 400,
9
+ FAILED = 412,
10
+ UNEXPECTED_FAILURE = 500,
11
+ }
12
+ export default HttpStatus;