connectwise-rest 0.25.1 → 1.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.
- package/.eslintrc +17 -52
- package/.gitattributes +1 -0
- package/.mocharc.json +5 -0
- package/.prettierrc +7 -0
- package/README.md +293 -230
- package/api-extractor.json +364 -0
- package/dist/Automate/AVTemplatePoliciesAPI.d.ts +36 -0
- package/dist/Automate/AVTemplatePoliciesAPI.d.ts.map +1 -0
- package/dist/Automate/AVTemplatePoliciesAPI.js +92 -0
- package/dist/Automate/AVTemplatePoliciesAPI.js.map +1 -0
- package/dist/Automate/ClientsAPI.d.ts +44 -0
- package/dist/Automate/ClientsAPI.d.ts.map +1 -0
- package/dist/Automate/ClientsAPI.js +119 -0
- package/dist/Automate/ClientsAPI.js.map +1 -0
- package/dist/Automate/CommandsAPI.d.ts +20 -0
- package/dist/Automate/CommandsAPI.d.ts.map +1 -0
- package/dist/Automate/CommandsAPI.js +36 -0
- package/dist/Automate/CommandsAPI.js.map +1 -0
- package/dist/Automate/ComputersAPI.d.ts +131 -0
- package/dist/Automate/ComputersAPI.d.ts.map +1 -0
- package/dist/Automate/ComputersAPI.js +358 -0
- package/dist/Automate/ComputersAPI.js.map +1 -0
- package/dist/Automate/ContactsAPI.d.ts +24 -0
- package/dist/Automate/ContactsAPI.d.ts.map +1 -0
- package/dist/Automate/ContactsAPI.js +50 -0
- package/dist/Automate/ContactsAPI.js.map +1 -0
- package/dist/Automate/DataViewsAPI.d.ts +22 -0
- package/dist/Automate/DataViewsAPI.d.ts.map +1 -0
- package/dist/Automate/DataViewsAPI.js +36 -0
- package/dist/Automate/DataViewsAPI.js.map +1 -0
- package/dist/Automate/DrivesAPI.d.ts +25 -0
- package/dist/Automate/DrivesAPI.d.ts.map +1 -0
- package/dist/Automate/DrivesAPI.js +57 -0
- package/dist/Automate/DrivesAPI.js.map +1 -0
- package/dist/Automate/EventLogsAPI.d.ts +19 -0
- package/dist/Automate/EventLogsAPI.d.ts.map +1 -0
- package/dist/Automate/EventLogsAPI.js +29 -0
- package/dist/Automate/EventLogsAPI.js.map +1 -0
- package/dist/Automate/LocationsAPI.d.ts +57 -0
- package/dist/Automate/LocationsAPI.d.ts.map +1 -0
- package/dist/Automate/LocationsAPI.js +138 -0
- package/dist/Automate/LocationsAPI.js.map +1 -0
- package/dist/Automate/MaintenanceWindowDefinitionsAPI.d.ts +19 -0
- package/dist/Automate/MaintenanceWindowDefinitionsAPI.d.ts.map +1 -0
- package/dist/Automate/MaintenanceWindowDefinitionsAPI.js +29 -0
- package/dist/Automate/MaintenanceWindowDefinitionsAPI.js.map +1 -0
- package/dist/Automate/MonitorsAPI.d.ts +29 -0
- package/dist/Automate/MonitorsAPI.d.ts.map +1 -0
- package/dist/Automate/MonitorsAPI.js +85 -0
- package/dist/Automate/MonitorsAPI.js.map +1 -0
- package/dist/Automate/NetworkDevicesAPI.d.ts +23 -0
- package/dist/Automate/NetworkDevicesAPI.d.ts.map +1 -0
- package/dist/Automate/NetworkDevicesAPI.js +43 -0
- package/dist/Automate/NetworkDevicesAPI.js.map +1 -0
- package/dist/Automate/PatchingAPI.d.ts +33 -0
- package/dist/Automate/PatchingAPI.d.ts.map +1 -0
- package/dist/Automate/PatchingAPI.js +99 -0
- package/dist/Automate/PatchingAPI.js.map +1 -0
- package/dist/Automate/RemoteAgentAPI.d.ts +24 -0
- package/dist/Automate/RemoteAgentAPI.d.ts.map +1 -0
- package/dist/Automate/RemoteAgentAPI.js +50 -0
- package/dist/Automate/RemoteAgentAPI.js.map +1 -0
- package/dist/Automate/ScriptingAPI.d.ts +41 -0
- package/dist/Automate/ScriptingAPI.d.ts.map +1 -0
- package/dist/Automate/ScriptingAPI.js +109 -0
- package/dist/Automate/ScriptingAPI.js.map +1 -0
- package/dist/Automate/SearchesAPI.d.ts +23 -0
- package/dist/Automate/SearchesAPI.d.ts.map +1 -0
- package/dist/Automate/SearchesAPI.js +43 -0
- package/dist/Automate/SearchesAPI.js.map +1 -0
- package/dist/Automate/SystemAPI.d.ts +97 -0
- package/dist/Automate/SystemAPI.d.ts.map +1 -0
- package/dist/Automate/SystemAPI.js +273 -0
- package/dist/Automate/SystemAPI.js.map +1 -0
- package/dist/Automate/TicketsAPI.d.ts +14 -0
- package/dist/Automate/TicketsAPI.d.ts.map +1 -0
- package/dist/Automate/TicketsAPI.js +29 -0
- package/dist/Automate/TicketsAPI.js.map +1 -0
- package/dist/Automate/UserProfilesAPI.d.ts +19 -0
- package/dist/Automate/UserProfilesAPI.d.ts.map +1 -0
- package/dist/Automate/UserProfilesAPI.js +28 -0
- package/dist/Automate/UserProfilesAPI.js.map +1 -0
- package/dist/Automate.d.ts +43 -0
- package/dist/Automate.d.ts.map +1 -0
- package/dist/Automate.js +164 -0
- package/dist/Automate.js.map +1 -0
- package/dist/AutomateAPI.d.ts +129 -0
- package/dist/AutomateAPI.d.ts.map +1 -0
- package/dist/AutomateAPI.js +175 -0
- package/dist/AutomateAPI.js.map +1 -0
- package/dist/AutomateTypes.d.ts +10437 -0
- package/dist/AutomateTypes.d.ts.map +1 -0
- package/dist/AutomateTypes.js +3 -0
- package/dist/AutomateTypes.js.map +1 -0
- package/dist/BaseAPI.d.ts +26 -0
- package/dist/BaseAPI.d.ts.map +1 -0
- package/dist/BaseAPI.js +116 -0
- package/dist/BaseAPI.js.map +1 -0
- package/dist/Manage/CompanyAPI.d.ts +662 -0
- package/dist/Manage/CompanyAPI.d.ts.map +1 -0
- package/dist/Manage/CompanyAPI.js +3299 -0
- package/dist/Manage/CompanyAPI.js.map +1 -0
- package/dist/Manage/ConfigurationsAPI.d.ts +32 -0
- package/dist/Manage/ConfigurationsAPI.d.ts.map +1 -0
- package/dist/Manage/ConfigurationsAPI.js +78 -0
- package/dist/Manage/ConfigurationsAPI.js.map +1 -0
- package/dist/Manage/ExpenseAPI.d.ts +85 -0
- package/dist/Manage/ExpenseAPI.d.ts.map +1 -0
- package/dist/Manage/ExpenseAPI.js +311 -0
- package/dist/Manage/ExpenseAPI.js.map +1 -0
- package/dist/Manage/FinanceAPI.d.ts +538 -0
- package/dist/Manage/FinanceAPI.d.ts.map +1 -0
- package/dist/Manage/FinanceAPI.js +2592 -0
- package/dist/Manage/FinanceAPI.js.map +1 -0
- package/dist/Manage/MarketingAPI.d.ts +142 -0
- package/dist/Manage/MarketingAPI.d.ts.map +1 -0
- package/dist/Manage/MarketingAPI.js +634 -0
- package/dist/Manage/MarketingAPI.js.map +1 -0
- package/dist/Manage/ProcurementAPI.d.ts +435 -0
- package/dist/Manage/ProcurementAPI.d.ts.map +1 -0
- package/dist/Manage/ProcurementAPI.js +2103 -0
- package/dist/Manage/ProcurementAPI.js.map +1 -0
- package/dist/Manage/ProjectAPI.d.ts +215 -0
- package/dist/Manage/ProjectAPI.d.ts.map +1 -0
- package/dist/Manage/ProjectAPI.js +945 -0
- package/dist/Manage/ProjectAPI.js.map +1 -0
- package/dist/Manage/SalesAPI.d.ts +299 -0
- package/dist/Manage/SalesAPI.d.ts.map +1 -0
- package/dist/Manage/SalesAPI.js +1397 -0
- package/dist/Manage/SalesAPI.js.map +1 -0
- package/dist/Manage/ScheduleAPI.d.ts +132 -0
- package/dist/Manage/ScheduleAPI.d.ts.map +1 -0
- package/dist/Manage/ScheduleAPI.js +580 -0
- package/dist/Manage/ScheduleAPI.js.map +1 -0
- package/dist/Manage/ServiceAPI.d.ts +493 -0
- package/dist/Manage/ServiceAPI.d.ts.map +1 -0
- package/dist/Manage/ServiceAPI.js +2339 -0
- package/dist/Manage/ServiceAPI.js.map +1 -0
- package/dist/Manage/SystemAPI.d.ts +954 -0
- package/dist/Manage/SystemAPI.d.ts.map +1 -0
- package/dist/Manage/SystemAPI.js +4536 -0
- package/dist/Manage/SystemAPI.js.map +1 -0
- package/dist/Manage/TimeAPI.d.ts +186 -0
- package/dist/Manage/TimeAPI.d.ts.map +1 -0
- package/dist/Manage/TimeAPI.js +840 -0
- package/dist/Manage/TimeAPI.js.map +1 -0
- package/dist/Manage.d.ts +39 -0
- package/dist/Manage.d.ts.map +1 -0
- package/dist/Manage.js +137 -0
- package/dist/Manage.js.map +1 -0
- package/dist/ManageAPI.d.ts +135 -0
- package/dist/ManageAPI.d.ts.map +1 -0
- package/dist/ManageAPI.js +115 -0
- package/dist/ManageAPI.js.map +1 -0
- package/dist/ManageTypes.d.ts +91320 -0
- package/dist/ManageTypes.d.ts.map +1 -0
- package/dist/ManageTypes.js +7 -0
- package/dist/ManageTypes.js.map +1 -0
- package/dist/connectwise-rest.d.ts +108638 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/types.d.ts +48 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +21 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/Callback.d.ts +70 -0
- package/dist/utils/Callback.d.ts.map +1 -0
- package/dist/utils/Callback.js +109 -0
- package/dist/utils/Callback.js.map +1 -0
- package/dist/utils/Series.d.ts +42 -0
- package/dist/utils/Series.d.ts.map +1 -0
- package/dist/utils/Series.js +68 -0
- package/dist/utils/Series.js.map +1 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +11 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +50 -19
- package/src/Automate/AVTemplatePoliciesAPI.ts +124 -0
- package/src/Automate/ClientsAPI.ts +172 -0
- package/src/Automate/CommandsAPI.ts +39 -0
- package/src/Automate/ComputersAPI.ts +588 -0
- package/src/Automate/ContactsAPI.ts +63 -0
- package/src/Automate/DataViewsAPI.ts +43 -0
- package/src/Automate/DrivesAPI.ts +81 -0
- package/src/Automate/EventLogsAPI.ts +31 -0
- package/src/Automate/LocationsAPI.ts +222 -0
- package/src/Automate/MaintenanceWindowDefinitionsAPI.ts +34 -0
- package/src/Automate/MonitorsAPI.ts +101 -0
- package/src/Automate/NetworkDevicesAPI.ts +51 -0
- package/src/Automate/PatchingAPI.ts +116 -0
- package/src/Automate/RemoteAgentAPI.ts +65 -0
- package/src/Automate/ScriptingAPI.ts +147 -0
- package/src/Automate/SearchesAPI.ts +49 -0
- package/src/Automate/SystemAPI.ts +412 -0
- package/src/Automate/TicketsAPI.ts +29 -0
- package/src/Automate/UserProfilesAPI.ts +31 -0
- package/src/Automate.ts +204 -0
- package/src/AutomateAPI.ts +178 -0
- package/src/AutomateTypes.ts +10492 -0
- package/src/BaseAPI.ts +180 -0
- package/src/Manage/CompanyAPI.ts +4941 -0
- package/src/Manage/ConfigurationsAPI.ts +116 -0
- package/src/Manage/ExpenseAPI.ts +413 -0
- package/src/Manage/FinanceAPI.ts +3930 -0
- package/src/Manage/MarketingAPI.ts +958 -0
- package/src/Manage/ProcurementAPI.ts +3107 -0
- package/src/Manage/ProjectAPI.ts +1437 -0
- package/src/Manage/SalesAPI.ts +1968 -0
- package/src/Manage/ScheduleAPI.ts +773 -0
- package/src/Manage/ServiceAPI.ts +3476 -0
- package/src/Manage/SystemAPI.ts +6415 -0
- package/src/Manage/TimeAPI.ts +1151 -0
- package/src/Manage.ts +161 -0
- package/src/ManageAPI.ts +170 -0
- package/src/ManageTypes.ts +91318 -0
- package/src/index.ts +13 -0
- package/src/types.ts +68 -0
- package/src/utils/Callback.ts +148 -0
- package/src/utils/Series.ts +89 -0
- package/src/utils/index.ts +7 -0
- package/swagger-errors.md +25 -0
- package/test/.env.example +12 -6
- package/test/test-utils.ts +27 -0
- package/test/test.js +331 -108
- package/tsconfig.json +29 -0
- package/.travis.yml +0 -9
- package/doc.md +0 -5984
- package/docs/jsdoc.json +0 -15
- package/index.js +0 -10
- package/src/CompanyAPI/Companies.js +0 -149
- package/src/CompanyAPI/CompanyCompanyTypeAssociations.js +0 -111
- package/src/CompanyAPI/CompanySites.js +0 -80
- package/src/CompanyAPI/CompanyTeams.js +0 -108
- package/src/CompanyAPI/CompanyTypeInfos.js +0 -58
- package/src/CompanyAPI/CompanyTypes.js +0 -52
- package/src/CompanyAPI/Configurations.js +0 -152
- package/src/CompanyAPI/ContactContactTypeAssociations.js +0 -55
- package/src/CompanyAPI/ContactRelationships.js +0 -36
- package/src/CompanyAPI/Contacts.js +0 -199
- package/src/CompanyAPI/index.js +0 -53
- package/src/ConnectWise.js +0 -339
- package/src/ConnectWiseRest.js +0 -515
- package/src/FinanceAPI/Additions.js +0 -127
- package/src/FinanceAPI/Adjustments.js +0 -109
- package/src/FinanceAPI/AgreementSites.js +0 -108
- package/src/FinanceAPI/Agreements.js +0 -220
- package/src/FinanceAPI/BoardDefaults.js +0 -109
- package/src/FinanceAPI/WorkRoles.js +0 -113
- package/src/FinanceAPI/WorkTypeExclusions.js +0 -78
- package/src/FinanceAPI/WorkTypes.js +0 -124
- package/src/FinanceAPI/index.js +0 -50
- package/src/ProcurementAPI/CatalogItems.js +0 -94
- package/src/ProcurementAPI/index.js +0 -22
- package/src/ProjectAPI/Projects.js +0 -142
- package/src/ProjectAPI/index.js +0 -28
- package/src/SalesAPI/Activities.js +0 -149
- package/src/SalesAPI/index.js +0 -14
- package/src/ScheduleAPI/ScheduleEntries.js +0 -109
- package/src/ScheduleAPI/ScheduleTypes.js +0 -101
- package/src/ScheduleAPI/index.js +0 -30
- package/src/ServiceDeskAPI/BoardItems.js +0 -134
- package/src/ServiceDeskAPI/BoardSubTypes.js +0 -112
- package/src/ServiceDeskAPI/BoardTeams.js +0 -108
- package/src/ServiceDeskAPI/BoardTypes.js +0 -139
- package/src/ServiceDeskAPI/Boards.js +0 -100
- package/src/ServiceDeskAPI/Priorities.js +0 -47
- package/src/ServiceDeskAPI/ServiceNotes.js +0 -172
- package/src/ServiceDeskAPI/Statuses.js +0 -116
- package/src/ServiceDeskAPI/Tickets.js +0 -588
- package/src/ServiceDeskAPI/index.js +0 -53
- package/src/SystemAPI/Members.js +0 -139
- package/src/SystemAPI/Reports.js +0 -116
- package/src/SystemAPI/index.js +0 -32
- package/src/TimeAPI/TimeEntries.js +0 -121
- package/src/TimeAPI/index.js +0 -27
- package/src/utils/Callback.js +0 -124
- package/src/utils/Series.js +0 -63
- package/src/utils/index.js +0 -21
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import ManageAPI, { CWMOptions, CommonParameters, PatchOperation } from './ManageAPI'
|
|
2
|
+
import AutomateAPI, { CWAOptions } from './AutomateAPI'
|
|
3
|
+
import type * as types from './types'
|
|
4
|
+
import type * as Automate from './AutomateAPI'
|
|
5
|
+
import type * as Manage from './ManageAPI'
|
|
6
|
+
import * as utils from './utils'
|
|
7
|
+
|
|
8
|
+
export type { CWMOptions, CommonParameters, PatchOperation, CWAOptions, types, Automate, Manage }
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export { AutomateAPI, ManageAPI, utils }
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type * as ManageAPIs from './ManageAPI'
|
|
2
|
+
import type * as AutomateApis from './AutomateAPI'
|
|
3
|
+
|
|
4
|
+
export enum StatusCode {
|
|
5
|
+
OK = 200,
|
|
6
|
+
Created = 201,
|
|
7
|
+
Accepted = 202,
|
|
8
|
+
NoContent = 204,
|
|
9
|
+
MovedPermanently = 301,
|
|
10
|
+
BadRequest = 400,
|
|
11
|
+
Unauthorized = 401,
|
|
12
|
+
Forbidden = 403,
|
|
13
|
+
NotFound = 404,
|
|
14
|
+
TooManyRequests = 429,
|
|
15
|
+
InternalServerError = 500,
|
|
16
|
+
BadGateway = 502,
|
|
17
|
+
ServiceUnavailable = 503,
|
|
18
|
+
GatewayTimeout = 504,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type Methods = 'get' | 'put' | 'delete' | 'post' | 'patch'
|
|
22
|
+
|
|
23
|
+
export type RetryOptions = {
|
|
24
|
+
minTimeout: number
|
|
25
|
+
retries: number
|
|
26
|
+
maxTimeout: number
|
|
27
|
+
randomize: boolean
|
|
28
|
+
factor?: number
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type RequestOptions = {
|
|
32
|
+
path: string
|
|
33
|
+
method?: Methods
|
|
34
|
+
params?: Record<string, unknown>
|
|
35
|
+
data?:
|
|
36
|
+
| Record<string, unknown>
|
|
37
|
+
| Record<string, unknown>[]
|
|
38
|
+
| PatchOperation[]
|
|
39
|
+
| null
|
|
40
|
+
| string
|
|
41
|
+
| number
|
|
42
|
+
| undefined
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type LoggingLevels = 'error' | 'warn' | 'info' | 'debug'
|
|
46
|
+
export type CWLogger = (level: LoggingLevels, text: string, meta?: Record<string, unknown>) => void
|
|
47
|
+
|
|
48
|
+
export type DataResponse =
|
|
49
|
+
| Record<string, unknown>
|
|
50
|
+
| Record<string, unknown>[]
|
|
51
|
+
| string
|
|
52
|
+
| number
|
|
53
|
+
| null
|
|
54
|
+
| undefined
|
|
55
|
+
|
|
56
|
+
export type ErrorResponse = {
|
|
57
|
+
status: number | string
|
|
58
|
+
data: DataResponse
|
|
59
|
+
message: string
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// missing types from api spec
|
|
63
|
+
export type NoContentResponse = undefined
|
|
64
|
+
export type OctetStreamResponse = Buffer
|
|
65
|
+
export type PDFResponse = Blob
|
|
66
|
+
export type HTMLResponse = string
|
|
67
|
+
export type PatchOperation = ManageAPIs.PatchOperation
|
|
68
|
+
export type { ManageAPIs, AutomateApis }
|
|
@@ -0,0 +1,148 @@
|
|
|
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
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export type CallbackPayload = {
|
|
17
|
+
Action: string
|
|
18
|
+
CompanyId: string | number
|
|
19
|
+
Entity: string
|
|
20
|
+
FromUrl: string
|
|
21
|
+
ID: string | number
|
|
22
|
+
MemberId: string | number
|
|
23
|
+
Metadata: {
|
|
24
|
+
key_url: string
|
|
25
|
+
}
|
|
26
|
+
Type: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type Entity = Record<string, unknown> | Array<Record<string, unknown>>
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Load signing key and verify the message
|
|
33
|
+
* @param callbackBody -
|
|
34
|
+
* @param contentSignature - base64 content signature req.headers[x-content-signature]
|
|
35
|
+
* @returns verifies callback signature
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export function verifyCallback(
|
|
39
|
+
callbackBody: CallbackPayload,
|
|
40
|
+
contentSignature: string,
|
|
41
|
+
): Promise<boolean> {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
if (!callbackBody || !contentSignature) {
|
|
44
|
+
throw new Error('callbackBody and contentSignature must be defined.')
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const key_url = callbackBody.Metadata && callbackBody.Metadata.key_url
|
|
48
|
+
|
|
49
|
+
axios
|
|
50
|
+
.get(key_url)
|
|
51
|
+
.then((response) => {
|
|
52
|
+
const body = response.data
|
|
53
|
+
try {
|
|
54
|
+
const parsed = JSON.parse(body)
|
|
55
|
+
const signingKey = parsed.signing_key
|
|
56
|
+
|
|
57
|
+
return resolve(verifyMessage(callbackBody, contentSignature, signingKey))
|
|
58
|
+
} catch (parseErr) {
|
|
59
|
+
return reject(parseErr)
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
.catch((err) => reject(err))
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Validate a callback body against signed key
|
|
68
|
+
* @param callbackBody -
|
|
69
|
+
* @param contentSignature -
|
|
70
|
+
* @param signingKey -
|
|
71
|
+
* @returns boolean if verified
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
export function verifyMessage(
|
|
75
|
+
callbackBody: CallbackPayload,
|
|
76
|
+
contentSignature: string,
|
|
77
|
+
signingKey: string,
|
|
78
|
+
): boolean {
|
|
79
|
+
const hash = crypto.createHash('sha256').update(signingKey).digest()
|
|
80
|
+
const hmac = crypto.createHmac('sha256', hash)
|
|
81
|
+
|
|
82
|
+
return contentSignature === hmac.update(JSON.stringify(callbackBody)).digest('base64')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* Express style middleware
|
|
89
|
+
* ```
|
|
90
|
+
* app.post('/your/api', cw.utils.middleware((err, req, res, verified, payload) => {
|
|
91
|
+
* if (err) {
|
|
92
|
+
* //handle error
|
|
93
|
+
* res.status(500).end();
|
|
94
|
+
* } else if (!verified) {
|
|
95
|
+
* // send 403 on verification failure
|
|
96
|
+
* res.status(403).end();
|
|
97
|
+
* } else {
|
|
98
|
+
* res.status(200).end()
|
|
99
|
+
* }
|
|
100
|
+
* const {action, id} = req.query;
|
|
101
|
+
* // do something with the payload
|
|
102
|
+
* }));
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @param cb - callback(err, req, res, verified, payload)
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
export function middleware(
|
|
109
|
+
cb: (
|
|
110
|
+
err: Error | null,
|
|
111
|
+
req: ExpressRequest,
|
|
112
|
+
res: ServerResponse,
|
|
113
|
+
verified: boolean,
|
|
114
|
+
payload: Entity | undefined,
|
|
115
|
+
) => void,
|
|
116
|
+
) {
|
|
117
|
+
if (!cb || typeof cb !== 'function') {
|
|
118
|
+
throw new Error('callback must be a function.')
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return (req: ExpressRequest, res: ServerResponse) => {
|
|
122
|
+
if (!req || !req.body || !req.body.Metadata) {
|
|
123
|
+
return cb(new Error('callback payload is invalid.'), req, res, false, undefined)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const contentSignature = req.headers['x-content-signature']
|
|
127
|
+
const callbackBody = req.body
|
|
128
|
+
|
|
129
|
+
let parsedEntity: Entity
|
|
130
|
+
try {
|
|
131
|
+
parsedEntity = JSON.parse(callbackBody.Entity)
|
|
132
|
+
} catch (parseErr) {
|
|
133
|
+
if (parseErr instanceof Error) {
|
|
134
|
+
return cb(parseErr, req, res, false, undefined)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
verifyCallback(callbackBody, contentSignature)
|
|
139
|
+
.then((verified) => {
|
|
140
|
+
return cb(null, req, res, verified, Object.assign(callbackBody, { Entity: parsedEntity }))
|
|
141
|
+
})
|
|
142
|
+
.catch((err) => {
|
|
143
|
+
return cb(err, req, res, false, undefined)
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export default { middleware, verifyCallback, verifyMessage }
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export type SeriesOptions = {
|
|
17
|
+
series: Array<PromiseLikeFunction>
|
|
18
|
+
concurrent?: number
|
|
19
|
+
delay?: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param options - options object
|
|
25
|
+
* @param options.series - functions or promises to be executed
|
|
26
|
+
* @param options.concurrent - number of concurrent requests
|
|
27
|
+
* @param options.delay - number of ms between request groups
|
|
28
|
+
* @returns array of promise results
|
|
29
|
+
* @public
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```javascript
|
|
33
|
+
* const results = await Series.all({
|
|
34
|
+
* series: [
|
|
35
|
+
* () => true,
|
|
36
|
+
* new Promise((resolve) => resolve(true),
|
|
37
|
+
* () => new Promise((resolve) => resolve(true)
|
|
38
|
+
* ],
|
|
39
|
+
* concurrent: 3,
|
|
40
|
+
* delay: 10,
|
|
41
|
+
* })
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
function all({ series = [], concurrent = 1, delay = 0 }: SeriesOptions): Promise<Array<unknown>> {
|
|
45
|
+
const promises = series.slice()
|
|
46
|
+
const concurrency = concurrent
|
|
47
|
+
let results: Array<unknown> | null = null
|
|
48
|
+
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
function next(result?: unknown) {
|
|
51
|
+
const concurrentPromises: PromiseLikeFunction[] = []
|
|
52
|
+
|
|
53
|
+
if (!results) {
|
|
54
|
+
results = []
|
|
55
|
+
} else {
|
|
56
|
+
results = results.concat(result)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (promises.length) {
|
|
60
|
+
while (concurrentPromises.length < concurrency && promises.length) {
|
|
61
|
+
let promise = promises.shift()
|
|
62
|
+
|
|
63
|
+
if (typeof promise === 'function') {
|
|
64
|
+
promise = <PromiseLikeFunction>promise()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!promise || !isPromise(promise)) {
|
|
68
|
+
promise = Promise.resolve(promise)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
concurrentPromises.push(promise)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
setTimeout(() => Promise.all(concurrentPromises).then(next).catch(reject), delay)
|
|
75
|
+
} else {
|
|
76
|
+
resolve(results)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
next()
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @public
|
|
86
|
+
*/
|
|
87
|
+
const Series = { all }
|
|
88
|
+
|
|
89
|
+
export default Series
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# API Spec Errors
|
|
2
|
+
|
|
3
|
+
## Automate
|
|
4
|
+
|
|
5
|
+
**System.ApiToken_Get**
|
|
6
|
+
Renamed to ApiToken_GetAuthInformation
|
|
7
|
+
|
|
8
|
+
## Manage
|
|
9
|
+
|
|
10
|
+
**Company.deleteCompanyContactsById**
|
|
11
|
+
Defines `transferContactId` as path variable but does not specify location in path
|
|
12
|
+
|
|
13
|
+
**Company.postCompanyCompanyPickerItemsClear**
|
|
14
|
+
Specifies `clearPickerRequest` as query variable but probably should be `body` variable.
|
|
15
|
+
|
|
16
|
+
**Project.postProjectTicketNoteByIdMarkAs**
|
|
17
|
+
Missing return type
|
|
18
|
+
|
|
19
|
+
**System.getSystemAudittrail &**
|
|
20
|
+
**System.getSystemAudittrailCount**
|
|
21
|
+
Operation name Audittrail typo
|
|
22
|
+
getRequest specified as path but should be query
|
|
23
|
+
|
|
24
|
+
**System.getSystemWorkflowsByParentIdEventsByIdTest**
|
|
25
|
+
Missing return type
|
package/test/.env.example
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
+
}
|