connectwise-rest 0.23.3 → 1.0.0

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 (288) hide show
  1. package/.eslintrc +19 -52
  2. package/.gitattributes +1 -0
  3. package/.github/workflows/codeql-analysis.yml +70 -0
  4. package/.github/workflows/node.js.yml +42 -0
  5. package/.mocharc.json +5 -0
  6. package/.prettierrc +7 -0
  7. package/.travis.yml +4 -2
  8. package/README.md +243 -230
  9. package/api-extractor.json +364 -0
  10. package/dist/Automate/AVTemplatePoliciesAPI.d.ts +27 -0
  11. package/dist/Automate/AVTemplatePoliciesAPI.d.ts.map +1 -0
  12. package/dist/Automate/AVTemplatePoliciesAPI.js +87 -0
  13. package/dist/Automate/AVTemplatePoliciesAPI.js.map +1 -0
  14. package/dist/Automate/ClientsAPI.d.ts +34 -0
  15. package/dist/Automate/ClientsAPI.d.ts.map +1 -0
  16. package/dist/Automate/ClientsAPI.js +114 -0
  17. package/dist/Automate/ClientsAPI.js.map +1 -0
  18. package/dist/Automate/CommandsAPI.d.ts +15 -0
  19. package/dist/Automate/CommandsAPI.d.ts.map +1 -0
  20. package/dist/Automate/CommandsAPI.js +31 -0
  21. package/dist/Automate/CommandsAPI.js.map +1 -0
  22. package/dist/Automate/ComputersAPI.d.ts +94 -0
  23. package/dist/Automate/ComputersAPI.d.ts.map +1 -0
  24. package/dist/Automate/ComputersAPI.js +353 -0
  25. package/dist/Automate/ComputersAPI.js.map +1 -0
  26. package/dist/Automate/ContactsAPI.d.ts +18 -0
  27. package/dist/Automate/ContactsAPI.d.ts.map +1 -0
  28. package/dist/Automate/ContactsAPI.js +45 -0
  29. package/dist/Automate/ContactsAPI.js.map +1 -0
  30. package/dist/Automate/DataViewsAPI.d.ts +16 -0
  31. package/dist/Automate/DataViewsAPI.d.ts.map +1 -0
  32. package/dist/Automate/DataViewsAPI.js +31 -0
  33. package/dist/Automate/DataViewsAPI.js.map +1 -0
  34. package/dist/Automate/DrivesAPI.d.ts +19 -0
  35. package/dist/Automate/DrivesAPI.d.ts.map +1 -0
  36. package/dist/Automate/DrivesAPI.js +52 -0
  37. package/dist/Automate/DrivesAPI.js.map +1 -0
  38. package/dist/Automate/EventLogsAPI.d.ts +14 -0
  39. package/dist/Automate/EventLogsAPI.d.ts.map +1 -0
  40. package/dist/Automate/EventLogsAPI.js +24 -0
  41. package/dist/Automate/EventLogsAPI.js.map +1 -0
  42. package/dist/Automate/LocationsAPI.d.ts +42 -0
  43. package/dist/Automate/LocationsAPI.d.ts.map +1 -0
  44. package/dist/Automate/LocationsAPI.js +133 -0
  45. package/dist/Automate/LocationsAPI.js.map +1 -0
  46. package/dist/Automate/MaintenanceWindowDefinitionsAPI.d.ts +14 -0
  47. package/dist/Automate/MaintenanceWindowDefinitionsAPI.d.ts.map +1 -0
  48. package/dist/Automate/MaintenanceWindowDefinitionsAPI.js +24 -0
  49. package/dist/Automate/MaintenanceWindowDefinitionsAPI.js.map +1 -0
  50. package/dist/Automate/MonitorsAPI.d.ts +23 -0
  51. package/dist/Automate/MonitorsAPI.d.ts.map +1 -0
  52. package/dist/Automate/MonitorsAPI.js +80 -0
  53. package/dist/Automate/MonitorsAPI.js.map +1 -0
  54. package/dist/Automate/NetworkDevicesAPI.d.ts +17 -0
  55. package/dist/Automate/NetworkDevicesAPI.d.ts.map +1 -0
  56. package/dist/Automate/NetworkDevicesAPI.js +38 -0
  57. package/dist/Automate/NetworkDevicesAPI.js.map +1 -0
  58. package/dist/Automate/PatchingAPI.d.ts +27 -0
  59. package/dist/Automate/PatchingAPI.d.ts.map +1 -0
  60. package/dist/Automate/PatchingAPI.js +94 -0
  61. package/dist/Automate/PatchingAPI.js.map +1 -0
  62. package/dist/Automate/RemoteAgentAPI.d.ts +18 -0
  63. package/dist/Automate/RemoteAgentAPI.d.ts.map +1 -0
  64. package/dist/Automate/RemoteAgentAPI.js +45 -0
  65. package/dist/Automate/RemoteAgentAPI.js.map +1 -0
  66. package/dist/Automate/ScriptingAPI.d.ts +32 -0
  67. package/dist/Automate/ScriptingAPI.d.ts.map +1 -0
  68. package/dist/Automate/ScriptingAPI.js +104 -0
  69. package/dist/Automate/ScriptingAPI.js.map +1 -0
  70. package/dist/Automate/SearchesAPI.d.ts +17 -0
  71. package/dist/Automate/SearchesAPI.d.ts.map +1 -0
  72. package/dist/Automate/SearchesAPI.js +38 -0
  73. package/dist/Automate/SearchesAPI.js.map +1 -0
  74. package/dist/Automate/SystemAPI.d.ts +72 -0
  75. package/dist/Automate/SystemAPI.d.ts.map +1 -0
  76. package/dist/Automate/SystemAPI.js +268 -0
  77. package/dist/Automate/SystemAPI.js.map +1 -0
  78. package/dist/Automate/TicketsAPI.d.ts +10 -0
  79. package/dist/Automate/TicketsAPI.d.ts.map +1 -0
  80. package/dist/Automate/TicketsAPI.js +24 -0
  81. package/dist/Automate/TicketsAPI.js.map +1 -0
  82. package/dist/Automate/UserProfilesAPI.d.ts +14 -0
  83. package/dist/Automate/UserProfilesAPI.d.ts.map +1 -0
  84. package/dist/Automate/UserProfilesAPI.js +23 -0
  85. package/dist/Automate/UserProfilesAPI.js.map +1 -0
  86. package/dist/Automate.d.ts +48 -0
  87. package/dist/Automate.d.ts.map +1 -0
  88. package/dist/Automate.js +167 -0
  89. package/dist/Automate.js.map +1 -0
  90. package/dist/AutomateAPI.d.ts +96 -0
  91. package/dist/AutomateAPI.d.ts.map +1 -0
  92. package/dist/AutomateAPI.js +168 -0
  93. package/dist/AutomateAPI.js.map +1 -0
  94. package/dist/AutomateTypes.d.ts +10437 -0
  95. package/dist/AutomateTypes.d.ts.map +1 -0
  96. package/dist/AutomateTypes.js +3 -0
  97. package/dist/AutomateTypes.js.map +1 -0
  98. package/dist/BaseAPI.d.ts +13 -0
  99. package/dist/BaseAPI.d.ts.map +1 -0
  100. package/dist/BaseAPI.js +53 -0
  101. package/dist/BaseAPI.js.map +1 -0
  102. package/dist/Manage/CompanyAPI.d.ts +573 -0
  103. package/dist/Manage/CompanyAPI.d.ts.map +1 -0
  104. package/dist/Manage/CompanyAPI.js +3294 -0
  105. package/dist/Manage/CompanyAPI.js.map +1 -0
  106. package/dist/Manage/ConfigurationsAPI.d.ts +24 -0
  107. package/dist/Manage/ConfigurationsAPI.d.ts.map +1 -0
  108. package/dist/Manage/ConfigurationsAPI.js +73 -0
  109. package/dist/Manage/ConfigurationsAPI.js.map +1 -0
  110. package/dist/Manage/ExpenseAPI.d.ts +68 -0
  111. package/dist/Manage/ExpenseAPI.d.ts.map +1 -0
  112. package/dist/Manage/ExpenseAPI.js +306 -0
  113. package/dist/Manage/ExpenseAPI.js.map +1 -0
  114. package/dist/Manage/FinanceAPI.d.ts +460 -0
  115. package/dist/Manage/FinanceAPI.d.ts.map +1 -0
  116. package/dist/Manage/FinanceAPI.js +2587 -0
  117. package/dist/Manage/FinanceAPI.js.map +1 -0
  118. package/dist/Manage/MarketingAPI.d.ts +120 -0
  119. package/dist/Manage/MarketingAPI.d.ts.map +1 -0
  120. package/dist/Manage/MarketingAPI.js +629 -0
  121. package/dist/Manage/MarketingAPI.js.map +1 -0
  122. package/dist/Manage/ProcurementAPI.d.ts +373 -0
  123. package/dist/Manage/ProcurementAPI.d.ts.map +1 -0
  124. package/dist/Manage/ProcurementAPI.js +2098 -0
  125. package/dist/Manage/ProcurementAPI.js.map +1 -0
  126. package/dist/Manage/ProjectAPI.d.ts +179 -0
  127. package/dist/Manage/ProjectAPI.d.ts.map +1 -0
  128. package/dist/Manage/ProjectAPI.js +940 -0
  129. package/dist/Manage/ProjectAPI.js.map +1 -0
  130. package/dist/Manage/SalesAPI.d.ts +254 -0
  131. package/dist/Manage/SalesAPI.d.ts.map +1 -0
  132. package/dist/Manage/SalesAPI.js +1392 -0
  133. package/dist/Manage/SalesAPI.js.map +1 -0
  134. package/dist/Manage/ScheduleAPI.d.ts +111 -0
  135. package/dist/Manage/ScheduleAPI.d.ts.map +1 -0
  136. package/dist/Manage/ScheduleAPI.js +575 -0
  137. package/dist/Manage/ScheduleAPI.js.map +1 -0
  138. package/dist/Manage/ServiceAPI.d.ts +419 -0
  139. package/dist/Manage/ServiceAPI.d.ts.map +1 -0
  140. package/dist/Manage/ServiceAPI.js +2334 -0
  141. package/dist/Manage/ServiceAPI.js.map +1 -0
  142. package/dist/Manage/SystemAPI.d.ts +809 -0
  143. package/dist/Manage/SystemAPI.d.ts.map +1 -0
  144. package/dist/Manage/SystemAPI.js +4531 -0
  145. package/dist/Manage/SystemAPI.js.map +1 -0
  146. package/dist/Manage/TimeAPI.d.ts +157 -0
  147. package/dist/Manage/TimeAPI.d.ts.map +1 -0
  148. package/dist/Manage/TimeAPI.js +835 -0
  149. package/dist/Manage/TimeAPI.js.map +1 -0
  150. package/dist/Manage.d.ts +34 -0
  151. package/dist/Manage.d.ts.map +1 -0
  152. package/dist/Manage.js +127 -0
  153. package/dist/Manage.js.map +1 -0
  154. package/dist/ManageAPI.d.ts +99 -0
  155. package/dist/ManageAPI.d.ts.map +1 -0
  156. package/dist/ManageAPI.js +112 -0
  157. package/dist/ManageAPI.js.map +1 -0
  158. package/dist/ManageTypes.d.ts +91320 -0
  159. package/dist/ManageTypes.d.ts.map +1 -0
  160. package/dist/ManageTypes.js +7 -0
  161. package/dist/ManageTypes.js.map +1 -0
  162. package/dist/index.d.ts +9 -0
  163. package/dist/index.d.ts.map +1 -0
  164. package/dist/index.js +38 -0
  165. package/dist/index.js.map +1 -0
  166. package/dist/types.d.ts +46 -0
  167. package/dist/types.d.ts.map +1 -0
  168. package/dist/types.js +21 -0
  169. package/dist/types.js.map +1 -0
  170. package/dist/utils/Callback.d.ts +67 -0
  171. package/dist/utils/Callback.d.ts.map +1 -0
  172. package/dist/utils/Callback.js +109 -0
  173. package/dist/utils/Callback.js.map +1 -0
  174. package/dist/utils/Series.d.ts +36 -0
  175. package/dist/utils/Series.d.ts.map +1 -0
  176. package/dist/utils/Series.js +64 -0
  177. package/dist/utils/Series.js.map +1 -0
  178. package/dist/utils/index.d.ts +7 -0
  179. package/dist/utils/index.d.ts.map +1 -0
  180. package/dist/utils/index.js +11 -0
  181. package/dist/utils/index.js.map +1 -0
  182. package/generator/automate-generator.js +75 -0
  183. package/generator/automate-json.js +61 -0
  184. package/generator/automate-types.js +15 -0
  185. package/generator/generator.d.ts +67 -0
  186. package/generator/generator.js +255 -0
  187. package/generator/manage-generator.js +71 -0
  188. package/generator/manage-types.js +14 -0
  189. package/package.json +48 -21
  190. package/src/Automate/AVTemplatePoliciesAPI.ts +114 -0
  191. package/src/Automate/ClientsAPI.ts +161 -0
  192. package/src/Automate/CommandsAPI.ts +33 -0
  193. package/src/Automate/ComputersAPI.ts +550 -0
  194. package/src/Automate/ContactsAPI.ts +56 -0
  195. package/src/Automate/DataViewsAPI.ts +36 -0
  196. package/src/Automate/DrivesAPI.ts +74 -0
  197. package/src/Automate/EventLogsAPI.ts +25 -0
  198. package/src/Automate/LocationsAPI.ts +206 -0
  199. package/src/Automate/MaintenanceWindowDefinitionsAPI.ts +28 -0
  200. package/src/Automate/MonitorsAPI.ts +94 -0
  201. package/src/Automate/NetworkDevicesAPI.ts +44 -0
  202. package/src/Automate/PatchingAPI.ts +109 -0
  203. package/src/Automate/RemoteAgentAPI.ts +58 -0
  204. package/src/Automate/ScriptingAPI.ts +137 -0
  205. package/src/Automate/SearchesAPI.ts +42 -0
  206. package/src/Automate/SystemAPI.ts +386 -0
  207. package/src/Automate/TicketsAPI.ts +24 -0
  208. package/src/Automate/UserProfilesAPI.ts +25 -0
  209. package/src/Automate.ts +216 -0
  210. package/src/AutomateAPI.ts +144 -0
  211. package/src/AutomateTypes.ts +10492 -0
  212. package/src/BaseAPI.ts +83 -0
  213. package/src/Manage/CompanyAPI.ts +4851 -0
  214. package/src/Manage/ConfigurationsAPI.ts +107 -0
  215. package/src/Manage/ExpenseAPI.ts +395 -0
  216. package/src/Manage/FinanceAPI.ts +3851 -0
  217. package/src/Manage/MarketingAPI.ts +935 -0
  218. package/src/Manage/ProcurementAPI.ts +3044 -0
  219. package/src/Manage/ProjectAPI.ts +1400 -0
  220. package/src/Manage/SalesAPI.ts +1922 -0
  221. package/src/Manage/ScheduleAPI.ts +751 -0
  222. package/src/Manage/ServiceAPI.ts +3401 -0
  223. package/src/Manage/SystemAPI.ts +6269 -0
  224. package/src/Manage/TimeAPI.ts +1121 -0
  225. package/src/Manage.ts +152 -0
  226. package/src/ManageAPI.ts +133 -0
  227. package/src/ManageTypes.ts +91318 -0
  228. package/src/index.ts +18 -0
  229. package/src/types.ts +66 -0
  230. package/src/utils/Callback.ts +145 -0
  231. package/src/utils/Series.ts +83 -0
  232. package/src/utils/index.ts +7 -0
  233. package/swagger-errors.md +30 -0
  234. package/test/.env.example +12 -4
  235. package/test/test-utils.ts +27 -0
  236. package/test/test.ts +320 -0
  237. package/tsconfig.json +29 -0
  238. package/doc.md +0 -5984
  239. package/docs/jsdoc.json +0 -15
  240. package/index.js +0 -10
  241. package/src/CompanyAPI/Companies.js +0 -149
  242. package/src/CompanyAPI/CompanyCompanyTypeAssociations.js +0 -111
  243. package/src/CompanyAPI/CompanySites.js +0 -70
  244. package/src/CompanyAPI/CompanyTeams.js +0 -108
  245. package/src/CompanyAPI/CompanyTypeInfos.js +0 -58
  246. package/src/CompanyAPI/CompanyTypes.js +0 -52
  247. package/src/CompanyAPI/Configurations.js +0 -152
  248. package/src/CompanyAPI/ContactContactTypeAssociations.js +0 -55
  249. package/src/CompanyAPI/ContactRelationships.js +0 -36
  250. package/src/CompanyAPI/Contacts.js +0 -199
  251. package/src/CompanyAPI/index.js +0 -53
  252. package/src/ConnectWise.js +0 -339
  253. package/src/ConnectWiseRest.js +0 -512
  254. package/src/FinanceAPI/Additions.js +0 -127
  255. package/src/FinanceAPI/Adjustments.js +0 -109
  256. package/src/FinanceAPI/AgreementSites.js +0 -108
  257. package/src/FinanceAPI/Agreements.js +0 -220
  258. package/src/FinanceAPI/BoardDefaults.js +0 -109
  259. package/src/FinanceAPI/WorkRoles.js +0 -113
  260. package/src/FinanceAPI/WorkTypeExclusions.js +0 -78
  261. package/src/FinanceAPI/WorkTypes.js +0 -124
  262. package/src/FinanceAPI/index.js +0 -50
  263. package/src/ProjectAPI/Projects.js +0 -142
  264. package/src/ProjectAPI/index.js +0 -28
  265. package/src/SalesAPI/Activities.js +0 -149
  266. package/src/SalesAPI/index.js +0 -14
  267. package/src/ScheduleAPI/ScheduleEntries.js +0 -109
  268. package/src/ScheduleAPI/ScheduleTypes.js +0 -101
  269. package/src/ScheduleAPI/index.js +0 -30
  270. package/src/ServiceDeskAPI/BoardItems.js +0 -134
  271. package/src/ServiceDeskAPI/BoardSubTypes.js +0 -112
  272. package/src/ServiceDeskAPI/BoardTeams.js +0 -108
  273. package/src/ServiceDeskAPI/BoardTypes.js +0 -139
  274. package/src/ServiceDeskAPI/Boards.js +0 -100
  275. package/src/ServiceDeskAPI/Priorities.js +0 -47
  276. package/src/ServiceDeskAPI/ServiceNotes.js +0 -172
  277. package/src/ServiceDeskAPI/Statuses.js +0 -116
  278. package/src/ServiceDeskAPI/Tickets.js +0 -588
  279. package/src/ServiceDeskAPI/index.js +0 -53
  280. package/src/SystemAPI/Members.js +0 -139
  281. package/src/SystemAPI/Reports.js +0 -116
  282. package/src/SystemAPI/index.js +0 -32
  283. package/src/TimeAPI/TimeEntries.js +0 -121
  284. package/src/TimeAPI/index.js +0 -27
  285. package/src/utils/Callback.js +0 -125
  286. package/src/utils/Series.js +0 -64
  287. package/src/utils/index.js +0 -21
  288. package/test/test.js +0 -114
package/src/index.ts ADDED
@@ -0,0 +1,18 @@
1
+ import ManageAPI, { CWMOptions, CommonParameters, PatchOperation } from './ManageAPI'
2
+ import AutomateAPI, { CWAOptions } from './AutomateAPI'
3
+ import type * as types from './types'
4
+ import * as utils from './utils'
5
+ import * as AutomateAPIs from './AutomateAPI'
6
+ import * as ManageAPIs from './ManageAPI'
7
+
8
+ export type {
9
+ AutomateAPIs,
10
+ ManageAPIs,
11
+ CWMOptions,
12
+ CommonParameters,
13
+ PatchOperation,
14
+ CWAOptions,
15
+ types,
16
+ }
17
+
18
+ export { AutomateAPI, ManageAPI, utils }
package/src/types.ts ADDED
@@ -0,0 +1,66 @@
1
+ import * as ManageAPI from './ManageAPI'
2
+
3
+ export enum StatusCode {
4
+ OK = 200,
5
+ Created = 201,
6
+ Accepted = 202,
7
+ NoContent = 204,
8
+ MovedPermanently = 301,
9
+ BadRequest = 400,
10
+ Unauthorized = 401,
11
+ Forbidden = 403,
12
+ NotFound = 404,
13
+ TooManyRequests = 429,
14
+ InternalServerError = 500,
15
+ BadGateway = 502,
16
+ ServiceUnavailable = 503,
17
+ GatewayTimeout = 504,
18
+ }
19
+
20
+ export type Methods = 'get' | 'put' | 'delete' | 'post' | 'patch'
21
+
22
+ export type RetryOptions = {
23
+ minTimeout: number
24
+ retries: number
25
+ maxTimeout: number
26
+ randomize: boolean
27
+ factor?: number
28
+ }
29
+
30
+ export type RequestOptions = {
31
+ path: string
32
+ method?: Methods
33
+ params?: Record<string, unknown>
34
+ data?:
35
+ | Record<string, unknown>
36
+ | Record<string, unknown>[]
37
+ | PatchOperation[]
38
+ | null
39
+ | string
40
+ | number
41
+ | undefined
42
+ }
43
+
44
+ export type LoggingLevels = 'error' | 'warn' | 'info' | 'debug'
45
+ export type CWLogger = (level: LoggingLevels, text: string, meta?: Record<string, unknown>) => void
46
+
47
+ export type DataResponse =
48
+ | Record<string, unknown>
49
+ | Record<string, unknown>[]
50
+ | string
51
+ | number
52
+ | null
53
+ | undefined
54
+
55
+ export type ErrorResponse = {
56
+ status: number | string
57
+ data: DataResponse
58
+ message: string
59
+ }
60
+
61
+ // missing types from api spec
62
+ export type NoContentResponse = undefined
63
+ export type OctetStreamResponse = Buffer
64
+ export type PDFResponse = Blob
65
+ export type HTMLResponse = string
66
+ export type PatchOperation = ManageAPI.PatchOperation
@@ -0,0 +1,145 @@
1
+ /*
2
+ * Created by kgrube on 4/3/2019
3
+ */
4
+ import axios from 'axios'
5
+ import crypto from 'crypto'
6
+ import type { ClientRequest, ServerResponse } from 'http'
7
+
8
+ export interface ExpressRequest extends ClientRequest {
9
+ body: CallbackPayload
10
+ headers: Record<string, string>
11
+ }
12
+
13
+ export type CallbackPayload = {
14
+ Action: string
15
+ CompanyId: string | number
16
+ Entity: string
17
+ FromUrl: string
18
+ ID: string | number
19
+ MemberId: string | number
20
+ Metadata: {
21
+ key_url: string
22
+ }
23
+ Type: string
24
+ }
25
+
26
+ export type Entity = Record<string, unknown> | Array<Record<string, unknown>>
27
+
28
+ /**
29
+ * Load signing key and verify the message
30
+ * @param callbackBody -
31
+ * @param contentSignature - base64 content signature req.headers[x-content-signature]
32
+ * @returns verifies callback signature
33
+ * @public
34
+ */
35
+ export function verifyCallback(
36
+ callbackBody: CallbackPayload,
37
+ contentSignature: string,
38
+ ): Promise<boolean> {
39
+ return new Promise((resolve, reject) => {
40
+ if (!callbackBody || !contentSignature) {
41
+ throw new Error('callbackBody and contentSignature must be defined.')
42
+ }
43
+
44
+ const key_url = callbackBody.Metadata && callbackBody.Metadata.key_url
45
+
46
+ axios
47
+ .get(key_url)
48
+ .then((response) => {
49
+ const body = response.data
50
+ try {
51
+ const parsed = JSON.parse(body)
52
+ const signingKey = parsed.signing_key
53
+
54
+ return resolve(verifyMessage(callbackBody, contentSignature, signingKey))
55
+ } catch (parseErr) {
56
+ return reject(parseErr)
57
+ }
58
+ })
59
+ .catch((err) => reject(err))
60
+ })
61
+ }
62
+
63
+ /**
64
+ * Validate a callback body against signed key
65
+ * @param callbackBody -
66
+ * @param contentSignature -
67
+ * @param signingKey -
68
+ * @returns boolean if verified
69
+ * @public
70
+ */
71
+ export function verifyMessage(
72
+ callbackBody: CallbackPayload,
73
+ contentSignature: string,
74
+ signingKey: string,
75
+ ): boolean {
76
+ const hash = crypto.createHash('sha256').update(signingKey).digest()
77
+ const hmac = crypto.createHmac('sha256', hash)
78
+
79
+ return contentSignature === hmac.update(JSON.stringify(callbackBody)).digest('base64')
80
+ }
81
+
82
+ /**
83
+ *
84
+ * @example
85
+ * Express style middleware
86
+ * ```
87
+ * app.post('/your/api', cw.utils.middleware((err, req, res, verified, payload) => {
88
+ * if (err) {
89
+ * //handle error
90
+ * res.status(500).end();
91
+ * } else if (!verified) {
92
+ * // send 403 on verification failure
93
+ * res.status(403).end();
94
+ * } else {
95
+ * res.status(200).end()
96
+ * }
97
+ * const {action, id} = req.query;
98
+ * // do something with the payload
99
+ * }));
100
+ * ```
101
+ *
102
+ * @param cb - callback(err, req, res, verified, payload)
103
+ * @public
104
+ */
105
+ export function middleware(
106
+ cb: (
107
+ err: Error | null,
108
+ req: ExpressRequest,
109
+ res: ServerResponse,
110
+ verified: boolean,
111
+ payload: Entity | undefined,
112
+ ) => void,
113
+ ) {
114
+ if (!cb || typeof cb !== 'function') {
115
+ throw new Error('callback must be a function.')
116
+ }
117
+
118
+ return (req: ExpressRequest, res: ServerResponse) => {
119
+ if (!req || !req.body || !req.body.Metadata) {
120
+ return cb(new Error('callback payload is invalid.'), req, res, false, undefined)
121
+ }
122
+
123
+ const contentSignature = req.headers['x-content-signature']
124
+ const callbackBody = req.body
125
+
126
+ let parsedEntity: Entity
127
+ try {
128
+ parsedEntity = JSON.parse(callbackBody.Entity)
129
+ } catch (parseErr) {
130
+ if (parseErr instanceof Error) {
131
+ return cb(parseErr, req, res, false, undefined)
132
+ }
133
+ }
134
+
135
+ verifyCallback(callbackBody, contentSignature)
136
+ .then((verified) => {
137
+ return cb(null, req, res, verified, Object.assign(callbackBody, { Entity: parsedEntity }))
138
+ })
139
+ .catch((err) => {
140
+ return cb(err, req, res, false, undefined)
141
+ })
142
+ }
143
+ }
144
+
145
+ export default { middleware, verifyCallback, verifyMessage }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Created by kgrube on 4/3/2019
3
+ */
4
+ import { types } from 'util'
5
+ const isPromise = types.isPromise
6
+
7
+ export type PromiseLikeFunction =
8
+ | (() => Promise<unknown>)
9
+ | Promise<unknown>
10
+ | (() => unknown)
11
+ | { then: () => void }
12
+
13
+ export type SeriesOptions = {
14
+ series: Array<PromiseLikeFunction>
15
+ concurrent?: number
16
+ delay?: number
17
+ }
18
+
19
+ /**
20
+ *
21
+ * @param options - options object
22
+ * @param options.series - functions or promises to be executed
23
+ * @param options.concurrent - number of concurrent requests
24
+ * @param options.delay - number of ms between request groups
25
+ * @returns array of promise results
26
+ * @public
27
+ *
28
+ * @example
29
+ * ```javascript
30
+ * const results = await Series.all({
31
+ * series: [
32
+ * () => true,
33
+ * new Promise((resolve) => resolve(true),
34
+ * () => new Promise((resolve) => resolve(true)
35
+ * ],
36
+ * concurrent: 3,
37
+ * delay: 10,
38
+ * })
39
+ * ```
40
+ */
41
+ function all({ series = [], concurrent = 1, delay = 0 }: SeriesOptions): Promise<Array<unknown>> {
42
+ const promises = series.slice()
43
+ const concurrency = concurrent
44
+ let results: Array<unknown> | null = null
45
+
46
+ return new Promise((resolve, reject) => {
47
+ function next(result?: unknown) {
48
+ const concurrentPromises: PromiseLikeFunction[] = []
49
+
50
+ if (!results) {
51
+ results = []
52
+ } else {
53
+ results = results.concat(result)
54
+ }
55
+
56
+ if (promises.length) {
57
+ while (concurrentPromises.length < concurrency && promises.length) {
58
+ let promise = promises.shift()
59
+
60
+ if (typeof promise === 'function') {
61
+ promise = <PromiseLikeFunction>promise()
62
+ }
63
+
64
+ if (!promise || !isPromise(promise)) {
65
+ promise = Promise.resolve(promise)
66
+ }
67
+
68
+ concurrentPromises.push(promise)
69
+ }
70
+
71
+ setTimeout(() => Promise.all(concurrentPromises).then(next).catch(reject), delay)
72
+ } else {
73
+ resolve(results)
74
+ }
75
+ }
76
+
77
+ next()
78
+ })
79
+ }
80
+
81
+ const Series = { all }
82
+
83
+ export default Series
@@ -0,0 +1,7 @@
1
+ import type * as SeriesTypes from './Series'
2
+ import type * as CallbackTypes from './Callback'
3
+ import Series from './Series'
4
+ import Callback from './Callback'
5
+
6
+ export type { SeriesTypes, CallbackTypes }
7
+ export { Series, Callback }
@@ -0,0 +1,30 @@
1
+ # API Spec Errors
2
+
3
+ ## Automate
4
+
5
+ **System
6
+
7
+ ## Manage
8
+
9
+ **Company.deleteCompanyContactsById**
10
+
11
+ Defines `transferContactId` as path variable but does not specify location in path
12
+
13
+ **Company.postCompanyCompanyPickerItemsClear**
14
+
15
+ Specifies `clearPickerRequest` as query variable but probably should be `body` variable.
16
+
17
+
18
+ **Project.postProjectTicketNoteByIdMarkAs**
19
+
20
+ Missing return type
21
+
22
+ **System.getSystemAudittrail &**
23
+ **System.getSystemAudittrailCount**
24
+
25
+ Operation name Audittrail typo
26
+ getRequest specified as path but should be query
27
+
28
+ **System.getSystemWorkflowsByParentIdEventsByIdTest**
29
+
30
+ Missing return type
package/test/.env.example CHANGED
@@ -1,4 +1,12 @@
1
- API_COMPANY=
2
- API_URL=
3
- API_PUBLIC_KEY=
4
- API_PRIVATE_KEY=
1
+ MANAGE_API_COMPANY=
2
+ MANAGE_API_URL=
3
+ MANAGE_API_PUBLIC_KEY=
4
+ MANAGE_API_PRIVATE_KEY=
5
+ MANAGE_API_CLIENT_ID=
6
+
7
+ AUTOMATE_API_URL=
8
+ AUTOMATE_API_USER=
9
+ AUTOMATE_API_PASSWORD=
10
+ AUTOMATE_API_CLIENT_ID=
11
+
12
+ COVERALLS_REPO_TOKEN=
@@ -0,0 +1,27 @@
1
+ export type PromiseArray<T> = Array<Promise<T>>
2
+
3
+ export function isPromise(input: unknown): input is Promise<unknown> {
4
+ return (
5
+ !!input &&
6
+ (typeof input === 'object' || typeof input === 'function') &&
7
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
8
+ // @ts-ignore
9
+ typeof input.then === 'function'
10
+ )
11
+ }
12
+
13
+ export function isPromiseType(input: unknown): input is Promise<unknown> {
14
+ return isPromise(input)
15
+ }
16
+
17
+ export function isArrayOfPromises(input: unknown): input is PromiseArray<unknown> {
18
+ if (Array.isArray(input)) {
19
+ if (Array.length === 0) {
20
+ return true
21
+ }
22
+ if (isPromise(input.pop)) {
23
+ return true
24
+ }
25
+ }
26
+ return false
27
+ }