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.
- package/.eslintrc +19 -52
- package/.gitattributes +1 -0
- package/.github/workflows/codeql-analysis.yml +70 -0
- package/.github/workflows/node.js.yml +42 -0
- package/.mocharc.json +5 -0
- package/.prettierrc +7 -0
- package/.travis.yml +4 -2
- package/README.md +243 -230
- package/api-extractor.json +364 -0
- package/dist/Automate/AVTemplatePoliciesAPI.d.ts +27 -0
- package/dist/Automate/AVTemplatePoliciesAPI.d.ts.map +1 -0
- package/dist/Automate/AVTemplatePoliciesAPI.js +87 -0
- package/dist/Automate/AVTemplatePoliciesAPI.js.map +1 -0
- package/dist/Automate/ClientsAPI.d.ts +34 -0
- package/dist/Automate/ClientsAPI.d.ts.map +1 -0
- package/dist/Automate/ClientsAPI.js +114 -0
- package/dist/Automate/ClientsAPI.js.map +1 -0
- package/dist/Automate/CommandsAPI.d.ts +15 -0
- package/dist/Automate/CommandsAPI.d.ts.map +1 -0
- package/dist/Automate/CommandsAPI.js +31 -0
- package/dist/Automate/CommandsAPI.js.map +1 -0
- package/dist/Automate/ComputersAPI.d.ts +94 -0
- package/dist/Automate/ComputersAPI.d.ts.map +1 -0
- package/dist/Automate/ComputersAPI.js +353 -0
- package/dist/Automate/ComputersAPI.js.map +1 -0
- package/dist/Automate/ContactsAPI.d.ts +18 -0
- package/dist/Automate/ContactsAPI.d.ts.map +1 -0
- package/dist/Automate/ContactsAPI.js +45 -0
- package/dist/Automate/ContactsAPI.js.map +1 -0
- package/dist/Automate/DataViewsAPI.d.ts +16 -0
- package/dist/Automate/DataViewsAPI.d.ts.map +1 -0
- package/dist/Automate/DataViewsAPI.js +31 -0
- package/dist/Automate/DataViewsAPI.js.map +1 -0
- package/dist/Automate/DrivesAPI.d.ts +19 -0
- package/dist/Automate/DrivesAPI.d.ts.map +1 -0
- package/dist/Automate/DrivesAPI.js +52 -0
- package/dist/Automate/DrivesAPI.js.map +1 -0
- package/dist/Automate/EventLogsAPI.d.ts +14 -0
- package/dist/Automate/EventLogsAPI.d.ts.map +1 -0
- package/dist/Automate/EventLogsAPI.js +24 -0
- package/dist/Automate/EventLogsAPI.js.map +1 -0
- package/dist/Automate/LocationsAPI.d.ts +42 -0
- package/dist/Automate/LocationsAPI.d.ts.map +1 -0
- package/dist/Automate/LocationsAPI.js +133 -0
- package/dist/Automate/LocationsAPI.js.map +1 -0
- package/dist/Automate/MaintenanceWindowDefinitionsAPI.d.ts +14 -0
- package/dist/Automate/MaintenanceWindowDefinitionsAPI.d.ts.map +1 -0
- package/dist/Automate/MaintenanceWindowDefinitionsAPI.js +24 -0
- package/dist/Automate/MaintenanceWindowDefinitionsAPI.js.map +1 -0
- package/dist/Automate/MonitorsAPI.d.ts +23 -0
- package/dist/Automate/MonitorsAPI.d.ts.map +1 -0
- package/dist/Automate/MonitorsAPI.js +80 -0
- package/dist/Automate/MonitorsAPI.js.map +1 -0
- package/dist/Automate/NetworkDevicesAPI.d.ts +17 -0
- package/dist/Automate/NetworkDevicesAPI.d.ts.map +1 -0
- package/dist/Automate/NetworkDevicesAPI.js +38 -0
- package/dist/Automate/NetworkDevicesAPI.js.map +1 -0
- package/dist/Automate/PatchingAPI.d.ts +27 -0
- package/dist/Automate/PatchingAPI.d.ts.map +1 -0
- package/dist/Automate/PatchingAPI.js +94 -0
- package/dist/Automate/PatchingAPI.js.map +1 -0
- package/dist/Automate/RemoteAgentAPI.d.ts +18 -0
- package/dist/Automate/RemoteAgentAPI.d.ts.map +1 -0
- package/dist/Automate/RemoteAgentAPI.js +45 -0
- package/dist/Automate/RemoteAgentAPI.js.map +1 -0
- package/dist/Automate/ScriptingAPI.d.ts +32 -0
- package/dist/Automate/ScriptingAPI.d.ts.map +1 -0
- package/dist/Automate/ScriptingAPI.js +104 -0
- package/dist/Automate/ScriptingAPI.js.map +1 -0
- package/dist/Automate/SearchesAPI.d.ts +17 -0
- package/dist/Automate/SearchesAPI.d.ts.map +1 -0
- package/dist/Automate/SearchesAPI.js +38 -0
- package/dist/Automate/SearchesAPI.js.map +1 -0
- package/dist/Automate/SystemAPI.d.ts +72 -0
- package/dist/Automate/SystemAPI.d.ts.map +1 -0
- package/dist/Automate/SystemAPI.js +268 -0
- package/dist/Automate/SystemAPI.js.map +1 -0
- package/dist/Automate/TicketsAPI.d.ts +10 -0
- package/dist/Automate/TicketsAPI.d.ts.map +1 -0
- package/dist/Automate/TicketsAPI.js +24 -0
- package/dist/Automate/TicketsAPI.js.map +1 -0
- package/dist/Automate/UserProfilesAPI.d.ts +14 -0
- package/dist/Automate/UserProfilesAPI.d.ts.map +1 -0
- package/dist/Automate/UserProfilesAPI.js +23 -0
- package/dist/Automate/UserProfilesAPI.js.map +1 -0
- package/dist/Automate.d.ts +48 -0
- package/dist/Automate.d.ts.map +1 -0
- package/dist/Automate.js +167 -0
- package/dist/Automate.js.map +1 -0
- package/dist/AutomateAPI.d.ts +96 -0
- package/dist/AutomateAPI.d.ts.map +1 -0
- package/dist/AutomateAPI.js +168 -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 +13 -0
- package/dist/BaseAPI.d.ts.map +1 -0
- package/dist/BaseAPI.js +53 -0
- package/dist/BaseAPI.js.map +1 -0
- package/dist/Manage/CompanyAPI.d.ts +573 -0
- package/dist/Manage/CompanyAPI.d.ts.map +1 -0
- package/dist/Manage/CompanyAPI.js +3294 -0
- package/dist/Manage/CompanyAPI.js.map +1 -0
- package/dist/Manage/ConfigurationsAPI.d.ts +24 -0
- package/dist/Manage/ConfigurationsAPI.d.ts.map +1 -0
- package/dist/Manage/ConfigurationsAPI.js +73 -0
- package/dist/Manage/ConfigurationsAPI.js.map +1 -0
- package/dist/Manage/ExpenseAPI.d.ts +68 -0
- package/dist/Manage/ExpenseAPI.d.ts.map +1 -0
- package/dist/Manage/ExpenseAPI.js +306 -0
- package/dist/Manage/ExpenseAPI.js.map +1 -0
- package/dist/Manage/FinanceAPI.d.ts +460 -0
- package/dist/Manage/FinanceAPI.d.ts.map +1 -0
- package/dist/Manage/FinanceAPI.js +2587 -0
- package/dist/Manage/FinanceAPI.js.map +1 -0
- package/dist/Manage/MarketingAPI.d.ts +120 -0
- package/dist/Manage/MarketingAPI.d.ts.map +1 -0
- package/dist/Manage/MarketingAPI.js +629 -0
- package/dist/Manage/MarketingAPI.js.map +1 -0
- package/dist/Manage/ProcurementAPI.d.ts +373 -0
- package/dist/Manage/ProcurementAPI.d.ts.map +1 -0
- package/dist/Manage/ProcurementAPI.js +2098 -0
- package/dist/Manage/ProcurementAPI.js.map +1 -0
- package/dist/Manage/ProjectAPI.d.ts +179 -0
- package/dist/Manage/ProjectAPI.d.ts.map +1 -0
- package/dist/Manage/ProjectAPI.js +940 -0
- package/dist/Manage/ProjectAPI.js.map +1 -0
- package/dist/Manage/SalesAPI.d.ts +254 -0
- package/dist/Manage/SalesAPI.d.ts.map +1 -0
- package/dist/Manage/SalesAPI.js +1392 -0
- package/dist/Manage/SalesAPI.js.map +1 -0
- package/dist/Manage/ScheduleAPI.d.ts +111 -0
- package/dist/Manage/ScheduleAPI.d.ts.map +1 -0
- package/dist/Manage/ScheduleAPI.js +575 -0
- package/dist/Manage/ScheduleAPI.js.map +1 -0
- package/dist/Manage/ServiceAPI.d.ts +419 -0
- package/dist/Manage/ServiceAPI.d.ts.map +1 -0
- package/dist/Manage/ServiceAPI.js +2334 -0
- package/dist/Manage/ServiceAPI.js.map +1 -0
- package/dist/Manage/SystemAPI.d.ts +809 -0
- package/dist/Manage/SystemAPI.d.ts.map +1 -0
- package/dist/Manage/SystemAPI.js +4531 -0
- package/dist/Manage/SystemAPI.js.map +1 -0
- package/dist/Manage/TimeAPI.d.ts +157 -0
- package/dist/Manage/TimeAPI.d.ts.map +1 -0
- package/dist/Manage/TimeAPI.js +835 -0
- package/dist/Manage/TimeAPI.js.map +1 -0
- package/dist/Manage.d.ts +34 -0
- package/dist/Manage.d.ts.map +1 -0
- package/dist/Manage.js +127 -0
- package/dist/Manage.js.map +1 -0
- package/dist/ManageAPI.d.ts +99 -0
- package/dist/ManageAPI.d.ts.map +1 -0
- package/dist/ManageAPI.js +112 -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/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +46 -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 +67 -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 +36 -0
- package/dist/utils/Series.d.ts.map +1 -0
- package/dist/utils/Series.js +64 -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/generator/automate-generator.js +75 -0
- package/generator/automate-json.js +61 -0
- package/generator/automate-types.js +15 -0
- package/generator/generator.d.ts +67 -0
- package/generator/generator.js +255 -0
- package/generator/manage-generator.js +71 -0
- package/generator/manage-types.js +14 -0
- package/package.json +48 -21
- package/src/Automate/AVTemplatePoliciesAPI.ts +114 -0
- package/src/Automate/ClientsAPI.ts +161 -0
- package/src/Automate/CommandsAPI.ts +33 -0
- package/src/Automate/ComputersAPI.ts +550 -0
- package/src/Automate/ContactsAPI.ts +56 -0
- package/src/Automate/DataViewsAPI.ts +36 -0
- package/src/Automate/DrivesAPI.ts +74 -0
- package/src/Automate/EventLogsAPI.ts +25 -0
- package/src/Automate/LocationsAPI.ts +206 -0
- package/src/Automate/MaintenanceWindowDefinitionsAPI.ts +28 -0
- package/src/Automate/MonitorsAPI.ts +94 -0
- package/src/Automate/NetworkDevicesAPI.ts +44 -0
- package/src/Automate/PatchingAPI.ts +109 -0
- package/src/Automate/RemoteAgentAPI.ts +58 -0
- package/src/Automate/ScriptingAPI.ts +137 -0
- package/src/Automate/SearchesAPI.ts +42 -0
- package/src/Automate/SystemAPI.ts +386 -0
- package/src/Automate/TicketsAPI.ts +24 -0
- package/src/Automate/UserProfilesAPI.ts +25 -0
- package/src/Automate.ts +216 -0
- package/src/AutomateAPI.ts +144 -0
- package/src/AutomateTypes.ts +10492 -0
- package/src/BaseAPI.ts +83 -0
- package/src/Manage/CompanyAPI.ts +4851 -0
- package/src/Manage/ConfigurationsAPI.ts +107 -0
- package/src/Manage/ExpenseAPI.ts +395 -0
- package/src/Manage/FinanceAPI.ts +3851 -0
- package/src/Manage/MarketingAPI.ts +935 -0
- package/src/Manage/ProcurementAPI.ts +3044 -0
- package/src/Manage/ProjectAPI.ts +1400 -0
- package/src/Manage/SalesAPI.ts +1922 -0
- package/src/Manage/ScheduleAPI.ts +751 -0
- package/src/Manage/ServiceAPI.ts +3401 -0
- package/src/Manage/SystemAPI.ts +6269 -0
- package/src/Manage/TimeAPI.ts +1121 -0
- package/src/Manage.ts +152 -0
- package/src/ManageAPI.ts +133 -0
- package/src/ManageTypes.ts +91318 -0
- package/src/index.ts +18 -0
- package/src/types.ts +66 -0
- package/src/utils/Callback.ts +145 -0
- package/src/utils/Series.ts +83 -0
- package/src/utils/index.ts +7 -0
- package/swagger-errors.md +30 -0
- package/test/.env.example +12 -4
- package/test/test-utils.ts +27 -0
- package/test/test.ts +320 -0
- package/tsconfig.json +29 -0
- 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 -70
- 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 -512
- 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/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 -125
- package/src/utils/Series.js +0 -64
- package/src/utils/index.js +0 -21
- package/test/test.js +0 -114
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ManageTypes.js","sourceRoot":"","sources":["../src/ManageTypes.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
export type { AutomateAPIs, ManageAPIs, CWMOptions, CommonParameters, PatchOperation, CWAOptions, types, };
|
|
8
|
+
export { AutomateAPI, ManageAPI, utils };
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,EAAE,EAAE,UAAU,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACrF,OAAO,WAAW,EAAE,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,KAAK,KAAK,KAAK,MAAM,SAAS,CAAA;AACrC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAA;AAChC,OAAO,KAAK,YAAY,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,UAAU,MAAM,aAAa,CAAA;AAEzC,YAAY,EACV,YAAY,EACZ,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,KAAK,GACN,CAAA;AAED,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.utils = exports.ManageAPI = exports.AutomateAPI = void 0;
|
|
30
|
+
const ManageAPI_1 = __importDefault(require("./ManageAPI"));
|
|
31
|
+
exports.ManageAPI = ManageAPI_1.default;
|
|
32
|
+
const AutomateAPI_1 = __importDefault(require("./AutomateAPI"));
|
|
33
|
+
exports.AutomateAPI = AutomateAPI_1.default;
|
|
34
|
+
const utils = __importStar(require("./utils"));
|
|
35
|
+
exports.utils = utils;
|
|
36
|
+
const AutomateAPIs = __importStar(require("./AutomateAPI"));
|
|
37
|
+
const ManageAPIs = __importStar(require("./ManageAPI"));
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAAqF;AAiB/D,oBAjBf,mBAAS,CAiBe;AAhB/B,gEAAuD;AAgB9C,sBAhBF,qBAAW,CAgBE;AAdpB,+CAAgC;AAcC,sBAAK;AAbtC,4DAA6C;AAC7C,wDAAyC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as ManageAPI from './ManageAPI';
|
|
3
|
+
export declare 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
|
+
export declare type Methods = 'get' | 'put' | 'delete' | 'post' | 'patch';
|
|
20
|
+
export declare type RetryOptions = {
|
|
21
|
+
minTimeout: number;
|
|
22
|
+
retries: number;
|
|
23
|
+
maxTimeout: number;
|
|
24
|
+
randomize: boolean;
|
|
25
|
+
factor?: number;
|
|
26
|
+
};
|
|
27
|
+
export declare type RequestOptions = {
|
|
28
|
+
path: string;
|
|
29
|
+
method?: Methods;
|
|
30
|
+
params?: Record<string, unknown>;
|
|
31
|
+
data?: Record<string, unknown> | Record<string, unknown>[] | PatchOperation[] | null | string | number | undefined;
|
|
32
|
+
};
|
|
33
|
+
export declare type LoggingLevels = 'error' | 'warn' | 'info' | 'debug';
|
|
34
|
+
export declare type CWLogger = (level: LoggingLevels, text: string, meta?: Record<string, unknown>) => void;
|
|
35
|
+
export declare type DataResponse = Record<string, unknown> | Record<string, unknown>[] | string | number | null | undefined;
|
|
36
|
+
export declare type ErrorResponse = {
|
|
37
|
+
status: number | string;
|
|
38
|
+
data: DataResponse;
|
|
39
|
+
message: string;
|
|
40
|
+
};
|
|
41
|
+
export declare type NoContentResponse = undefined;
|
|
42
|
+
export declare type OctetStreamResponse = Buffer;
|
|
43
|
+
export declare type PDFResponse = Blob;
|
|
44
|
+
export declare type HTMLResponse = string;
|
|
45
|
+
export declare type PatchOperation = ManageAPI.PatchOperation;
|
|
46
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,SAAS,MAAM,aAAa,CAAA;AAExC,oBAAY,UAAU;IACpB,EAAE,MAAM;IACR,OAAO,MAAM;IACb,QAAQ,MAAM;IACd,SAAS,MAAM;IACf,gBAAgB,MAAM;IACtB,UAAU,MAAM;IAChB,YAAY,MAAM;IAClB,SAAS,MAAM;IACf,QAAQ,MAAM;IACd,eAAe,MAAM;IACrB,mBAAmB,MAAM;IACzB,UAAU,MAAM;IAChB,kBAAkB,MAAM;IACxB,cAAc,MAAM;CACrB;AAED,oBAAY,OAAO,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;AAEjE,oBAAY,YAAY,GAAG;IACzB,U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,CAAA"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StatusCode = void 0;
|
|
4
|
+
var StatusCode;
|
|
5
|
+
(function (StatusCode) {
|
|
6
|
+
StatusCode[StatusCode["OK"] = 200] = "OK";
|
|
7
|
+
StatusCode[StatusCode["Created"] = 201] = "Created";
|
|
8
|
+
StatusCode[StatusCode["Accepted"] = 202] = "Accepted";
|
|
9
|
+
StatusCode[StatusCode["NoContent"] = 204] = "NoContent";
|
|
10
|
+
StatusCode[StatusCode["MovedPermanently"] = 301] = "MovedPermanently";
|
|
11
|
+
StatusCode[StatusCode["BadRequest"] = 400] = "BadRequest";
|
|
12
|
+
StatusCode[StatusCode["Unauthorized"] = 401] = "Unauthorized";
|
|
13
|
+
StatusCode[StatusCode["Forbidden"] = 403] = "Forbidden";
|
|
14
|
+
StatusCode[StatusCode["NotFound"] = 404] = "NotFound";
|
|
15
|
+
StatusCode[StatusCode["TooManyRequests"] = 429] = "TooManyRequests";
|
|
16
|
+
StatusCode[StatusCode["InternalServerError"] = 500] = "InternalServerError";
|
|
17
|
+
StatusCode[StatusCode["BadGateway"] = 502] = "BadGateway";
|
|
18
|
+
StatusCode[StatusCode["ServiceUnavailable"] = 503] = "ServiceUnavailable";
|
|
19
|
+
StatusCode[StatusCode["GatewayTimeout"] = 504] = "GatewayTimeout";
|
|
20
|
+
})(StatusCode = exports.StatusCode || (exports.StatusCode = {}));
|
|
21
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAEA,IAAY,UAeX;AAfD,WAAY,UAAU;IACpB,yCAAQ,CAAA;IACR,mDAAa,CAAA;IACb,qDAAc,CAAA;IACd,uDAAe,CAAA;IACf,qEAAsB,CAAA;IACtB,yDAAgB,CAAA;IAChB,6DAAkB,CAAA;IAClB,uDAAe,CAAA;IACf,qDAAc,CAAA;IACd,mEAAqB,CAAA;IACrB,2EAAyB,CAAA;IACzB,yDAAgB,CAAA;IAChB,yEAAwB,CAAA;IACxB,iEAAoB,CAAA;AACtB,CAAC,EAfW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAerB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { ClientRequest, ServerResponse } from 'http';
|
|
3
|
+
export interface ExpressRequest extends ClientRequest {
|
|
4
|
+
body: CallbackPayload;
|
|
5
|
+
headers: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
export declare type CallbackPayload = {
|
|
8
|
+
Action: string;
|
|
9
|
+
CompanyId: string | number;
|
|
10
|
+
Entity: string;
|
|
11
|
+
FromUrl: string;
|
|
12
|
+
ID: string | number;
|
|
13
|
+
MemberId: string | number;
|
|
14
|
+
Metadata: {
|
|
15
|
+
key_url: string;
|
|
16
|
+
};
|
|
17
|
+
Type: string;
|
|
18
|
+
};
|
|
19
|
+
export declare type Entity = Record<string, unknown> | Array<Record<string, unknown>>;
|
|
20
|
+
/**
|
|
21
|
+
* Load signing key and verify the message
|
|
22
|
+
* @param callbackBody -
|
|
23
|
+
* @param contentSignature - base64 content signature req.headers[x-content-signature]
|
|
24
|
+
* @returns verifies callback signature
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export declare function verifyCallback(callbackBody: CallbackPayload, contentSignature: string): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Validate a callback body against signed key
|
|
30
|
+
* @param callbackBody -
|
|
31
|
+
* @param contentSignature -
|
|
32
|
+
* @param signingKey -
|
|
33
|
+
* @returns boolean if verified
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export declare function verifyMessage(callbackBody: CallbackPayload, contentSignature: string, signingKey: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* Express style middleware
|
|
41
|
+
* ```
|
|
42
|
+
* app.post('/your/api', cw.utils.middleware((err, req, res, verified, payload) => {
|
|
43
|
+
* if (err) {
|
|
44
|
+
* //handle error
|
|
45
|
+
* res.status(500).end();
|
|
46
|
+
* } else if (!verified) {
|
|
47
|
+
* // send 403 on verification failure
|
|
48
|
+
* res.status(403).end();
|
|
49
|
+
* } else {
|
|
50
|
+
* res.status(200).end()
|
|
51
|
+
* }
|
|
52
|
+
* const {action, id} = req.query;
|
|
53
|
+
* // do something with the payload
|
|
54
|
+
* }));
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @param cb - callback(err, req, res, verified, payload)
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
export declare function middleware(cb: (err: Error | null, req: ExpressRequest, res: ServerResponse, verified: boolean, payload: Entity | undefined) => void): (req: ExpressRequest, res: ServerResponse) => void;
|
|
61
|
+
declare const _default: {
|
|
62
|
+
middleware: typeof middleware;
|
|
63
|
+
verifyCallback: typeof verifyCallback;
|
|
64
|
+
verifyMessage: typeof verifyMessage;
|
|
65
|
+
};
|
|
66
|
+
export default _default;
|
|
67
|
+
//# sourceMappingURL=Callback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Callback.d.ts","sourceRoot":"","sources":["../../src/utils/Callback.ts"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAEzD,MAAM,WAAW,cAAe,SAAQ,aAAa;IACnD,IAAI,EAAE,eAAe,CAAA;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAChC;AAED,oBAAY,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,GAAG,MAAM,CAAA;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;IACzB,QAAQ,EAAE;QACR,OAAO,EAAE,MAAM,CAAA;KAChB,CAAA;IACD,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,oBAAY,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;AAE7E;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,YAAY,EAAE,eAAe,EAC7B,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,OAAO,CAAC,CAuBlB;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,YAAY,EAAE,eAAe,EAC7B,gBAAgB,EAAE,MAAM,EACxB,UAAU,EAAE,MAAM,GACjB,OAAO,CAKT;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,UAAU,CACxB,EAAE,EAAE,CACF,GAAG,EAAE,KAAK,GAAG,IAAI,EACjB,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,cAAc,EACnB,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,MAAM,GAAG,SAAS,KACxB,IAAI,SAMI,cAAc,OAAO,cAAc,UAyBjD;;;;;;AAED,wBAA4D"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.middleware = exports.verifyMessage = exports.verifyCallback = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* Created by kgrube on 4/3/2019
|
|
9
|
+
*/
|
|
10
|
+
const axios_1 = __importDefault(require("axios"));
|
|
11
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
12
|
+
/**
|
|
13
|
+
* Load signing key and verify the message
|
|
14
|
+
* @param callbackBody -
|
|
15
|
+
* @param contentSignature - base64 content signature req.headers[x-content-signature]
|
|
16
|
+
* @returns verifies callback signature
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
function verifyCallback(callbackBody, contentSignature) {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
if (!callbackBody || !contentSignature) {
|
|
22
|
+
throw new Error('callbackBody and contentSignature must be defined.');
|
|
23
|
+
}
|
|
24
|
+
const key_url = callbackBody.Metadata && callbackBody.Metadata.key_url;
|
|
25
|
+
axios_1.default
|
|
26
|
+
.get(key_url)
|
|
27
|
+
.then((response) => {
|
|
28
|
+
const body = response.data;
|
|
29
|
+
try {
|
|
30
|
+
const parsed = JSON.parse(body);
|
|
31
|
+
const signingKey = parsed.signing_key;
|
|
32
|
+
return resolve(verifyMessage(callbackBody, contentSignature, signingKey));
|
|
33
|
+
}
|
|
34
|
+
catch (parseErr) {
|
|
35
|
+
return reject(parseErr);
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
.catch((err) => reject(err));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.verifyCallback = verifyCallback;
|
|
42
|
+
/**
|
|
43
|
+
* Validate a callback body against signed key
|
|
44
|
+
* @param callbackBody -
|
|
45
|
+
* @param contentSignature -
|
|
46
|
+
* @param signingKey -
|
|
47
|
+
* @returns boolean if verified
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
function verifyMessage(callbackBody, contentSignature, signingKey) {
|
|
51
|
+
const hash = crypto_1.default.createHash('sha256').update(signingKey).digest();
|
|
52
|
+
const hmac = crypto_1.default.createHmac('sha256', hash);
|
|
53
|
+
return contentSignature === hmac.update(JSON.stringify(callbackBody)).digest('base64');
|
|
54
|
+
}
|
|
55
|
+
exports.verifyMessage = verifyMessage;
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* Express style middleware
|
|
60
|
+
* ```
|
|
61
|
+
* app.post('/your/api', cw.utils.middleware((err, req, res, verified, payload) => {
|
|
62
|
+
* if (err) {
|
|
63
|
+
* //handle error
|
|
64
|
+
* res.status(500).end();
|
|
65
|
+
* } else if (!verified) {
|
|
66
|
+
* // send 403 on verification failure
|
|
67
|
+
* res.status(403).end();
|
|
68
|
+
* } else {
|
|
69
|
+
* res.status(200).end()
|
|
70
|
+
* }
|
|
71
|
+
* const {action, id} = req.query;
|
|
72
|
+
* // do something with the payload
|
|
73
|
+
* }));
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @param cb - callback(err, req, res, verified, payload)
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
function middleware(cb) {
|
|
80
|
+
if (!cb || typeof cb !== 'function') {
|
|
81
|
+
throw new Error('callback must be a function.');
|
|
82
|
+
}
|
|
83
|
+
return (req, res) => {
|
|
84
|
+
if (!req || !req.body || !req.body.Metadata) {
|
|
85
|
+
return cb(new Error('callback payload is invalid.'), req, res, false, undefined);
|
|
86
|
+
}
|
|
87
|
+
const contentSignature = req.headers['x-content-signature'];
|
|
88
|
+
const callbackBody = req.body;
|
|
89
|
+
let parsedEntity;
|
|
90
|
+
try {
|
|
91
|
+
parsedEntity = JSON.parse(callbackBody.Entity);
|
|
92
|
+
}
|
|
93
|
+
catch (parseErr) {
|
|
94
|
+
if (parseErr instanceof Error) {
|
|
95
|
+
return cb(parseErr, req, res, false, undefined);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
verifyCallback(callbackBody, contentSignature)
|
|
99
|
+
.then((verified) => {
|
|
100
|
+
return cb(null, req, res, verified, Object.assign(callbackBody, { Entity: parsedEntity }));
|
|
101
|
+
})
|
|
102
|
+
.catch((err) => {
|
|
103
|
+
return cb(err, req, res, false, undefined);
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
exports.middleware = middleware;
|
|
108
|
+
exports.default = { middleware, verifyCallback, verifyMessage };
|
|
109
|
+
//# sourceMappingURL=Callback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Callback.js","sourceRoot":"","sources":["../../src/utils/Callback.ts"],"names":[],"mappings":";;;;;;AAAA;;GAEG;AACH,kDAAyB;AACzB,oDAA2B;AAuB3B;;;;;;GAMG;AACH,SAAgB,cAAc,CAC5B,YAA6B,EAC7B,gBAAwB;IAExB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,CAAC,YAAY,IAAI,CAAC,gBAAgB,EAAE;YACtC,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;SACtE;QAED,MAAM,OAAO,GAAG,YAAY,CAAC,QAAQ,IAAI,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAA;QAEtE,eAAK;aACF,GAAG,CAAC,OAAO,CAAC;aACZ,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;YACjB,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAA;YAC1B,IAAI;gBACF,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;gBAC/B,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CAAA;gBAErC,OAAO,OAAO,CAAC,aAAa,CAAC,YAAY,EAAE,gBAAgB,EAAE,UAAU,CAAC,CAAC,CAAA;aAC1E;YAAC,OAAO,QAAQ,EAAE;gBACjB,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAA;aACxB;QACH,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;IAChC,CAAC,CAAC,CAAA;AACJ,CAAC;AA1BD,wCA0BC;AAED;;;;;;;GAOG;AACH,SAAgB,aAAa,CAC3B,YAA6B,EAC7B,gBAAwB,EACxB,UAAkB;IAElB,MAAM,IAAI,GAAG,gB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AC3C,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;YACjB,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC,CAAA;QAC5F,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACb,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;QAC5C,CAAC,CAAC,CAAA;IACN,CAAC,CAAA;AACH,CAAC;AAtCD,gCAsCC;AAED,kBAAe,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare type PromiseLikeFunction = (() => Promise<unknown>) | Promise<unknown> | (() => unknown) | {
|
|
2
|
+
then: () => void;
|
|
3
|
+
};
|
|
4
|
+
export declare type SeriesOptions = {
|
|
5
|
+
series: Array<PromiseLikeFunction>;
|
|
6
|
+
concurrent?: number;
|
|
7
|
+
delay?: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param options - options object
|
|
12
|
+
* @param options.series - functions or promises to be executed
|
|
13
|
+
* @param options.concurrent - number of concurrent requests
|
|
14
|
+
* @param options.delay - number of ms between request groups
|
|
15
|
+
* @returns array of promise results
|
|
16
|
+
* @public
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```javascript
|
|
20
|
+
* const results = await Series.all({
|
|
21
|
+
* series: [
|
|
22
|
+
* () => true,
|
|
23
|
+
* new Promise((resolve) => resolve(true),
|
|
24
|
+
* () => new Promise((resolve) => resolve(true)
|
|
25
|
+
* ],
|
|
26
|
+
* concurrent: 3,
|
|
27
|
+
* delay: 10,
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
declare function all({ series, concurrent, delay }: SeriesOptions): Promise<Array<unknown>>;
|
|
32
|
+
declare const Series: {
|
|
33
|
+
all: typeof all;
|
|
34
|
+
};
|
|
35
|
+
export default Series;
|
|
36
|
+
//# sourceMappingURL=Series.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Series.d.ts","sourceRoot":"","sources":["../../src/utils/Series.ts"],"names":[],"mappings":"AAKA,oBAAY,mBAAmB,GAC3B,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,GACxB,OAAO,CAAC,OAAO,CAAC,GAChB,CAAC,MAAM,OAAO,CAAC,GACf;IAAE,IAAI,EAAE,MAAM,IAAI,CAAA;CAAE,CAAA;AAExB,oBAAY,aAAa,GAAG;IAC1B,MAAM,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAA;IAClC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,iBAAS,GAAG,CAAC,EAAE,MAAW,EAAE,UAAc,EAAE,KAAS,EAAE,EAAE,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAsC/F;AAED,QAAA,MAAM,MAAM;;CAAU,CAAA;AAEtB,eAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Created by kgrube on 4/3/2019
|
|
5
|
+
*/
|
|
6
|
+
const types_1 = require("util/types");
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param options - options object
|
|
10
|
+
* @param options.series - functions or promises to be executed
|
|
11
|
+
* @param options.concurrent - number of concurrent requests
|
|
12
|
+
* @param options.delay - number of ms between request groups
|
|
13
|
+
* @returns array of promise results
|
|
14
|
+
* @public
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```javascript
|
|
18
|
+
* const results = await Series.all({
|
|
19
|
+
* series: [
|
|
20
|
+
* () => true,
|
|
21
|
+
* new Promise((resolve) => resolve(true),
|
|
22
|
+
* () => new Promise((resolve) => resolve(true)
|
|
23
|
+
* ],
|
|
24
|
+
* concurrent: 3,
|
|
25
|
+
* delay: 10,
|
|
26
|
+
* })
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
function all({ series = [], concurrent = 1, delay = 0 }) {
|
|
30
|
+
const promises = series.slice();
|
|
31
|
+
const concurrency = concurrent;
|
|
32
|
+
let results = null;
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
function next(result) {
|
|
35
|
+
const concurrentPromises = [];
|
|
36
|
+
if (!results) {
|
|
37
|
+
results = [];
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
results = results.concat(result);
|
|
41
|
+
}
|
|
42
|
+
if (promises.length) {
|
|
43
|
+
while (concurrentPromises.length < concurrency && promises.length) {
|
|
44
|
+
let promise = promises.shift();
|
|
45
|
+
if (typeof promise === 'function') {
|
|
46
|
+
promise = promise();
|
|
47
|
+
}
|
|
48
|
+
if (!promise || !(0, types_1.isPromise)(promise)) {
|
|
49
|
+
promise = Promise.resolve(promise);
|
|
50
|
+
}
|
|
51
|
+
concurrentPromises.push(promise);
|
|
52
|
+
}
|
|
53
|
+
setTimeout(() => Promise.all(concurrentPromises).then(next).catch(reject), delay);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
resolve(results);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
next();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const Series = { all };
|
|
63
|
+
exports.default = Series;
|
|
64
|
+
//# sourceMappingURL=Series.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Series.js","sourceRoot":"","sources":["../../src/utils/Series.ts"],"names":[],"mappings":";;AAAA;;GAEG;AAC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B;QACH,CAAC;QAED,IAAI,EAAE,CAAA;IACR,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,CAAA;AAEtB,kBAAe,MAAM,CAAA"}
|
|
@@ -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
|
+
export type { SeriesTypes, CallbackTypes };
|
|
6
|
+
export { Series, Callback };
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,WAAW,MAAM,UAAU,CAAA;AAC5C,OAAO,KAAK,KAAK,aAAa,MAAM,YAAY,CAAA;AAChD,OAAO,MAAM,MAAM,UAAU,CAAA;AAC7B,OAAO,QAAQ,MAAM,YAAY,CAAA;AAEjC,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Callback = exports.Series = void 0;
|
|
7
|
+
const Series_1 = __importDefault(require("./Series"));
|
|
8
|
+
exports.Series = Series_1.default;
|
|
9
|
+
const Callback_1 = __importDefault(require("./Callback"));
|
|
10
|
+
exports.Callback = Callback_1.default;
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;AAEA,sDAA6B;AAIpB,iBAJF,gBAAM,CAIE;AAHf,0DAAiC;AAGhB,mBAHV,kBAAQ,CAGU"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
+
const { getAutomateJson } = require('./automate-json')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
const { ESLint } = require('eslint')
|
|
6
|
+
const { generateAPIClass } = require('./generator')
|
|
7
|
+
|
|
8
|
+
const eslint = new ESLint({ fix: true })
|
|
9
|
+
|
|
10
|
+
async function generate() {
|
|
11
|
+
const automate = getAutomateJson()
|
|
12
|
+
const {
|
|
13
|
+
paths,
|
|
14
|
+
components: { schemas },
|
|
15
|
+
} = automate
|
|
16
|
+
|
|
17
|
+
const sections = {}
|
|
18
|
+
|
|
19
|
+
const automateTempFolder = path.join(__dirname, 'Automate')
|
|
20
|
+
|
|
21
|
+
if (!fs.existsSync(automateTempFolder)) {
|
|
22
|
+
fs.mkdirSync(automateTempFolder)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
Object.keys(paths).forEach((url) => {
|
|
26
|
+
const methods = paths[url]
|
|
27
|
+
const section = paths[url][Object.keys(methods).pop()].section
|
|
28
|
+
|
|
29
|
+
if (!sections[section]) {
|
|
30
|
+
sections[section] = []
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
sections[section].push({ url, methods })
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
for (const section of Object.keys(sections)) {
|
|
37
|
+
const apiName = section.charAt(0).toUpperCase() + section.slice(1)
|
|
38
|
+
const operations = sections[section]
|
|
39
|
+
|
|
40
|
+
const file = generateAPIClass({ apiName, operations, generatorType: 'Automate' })
|
|
41
|
+
const fileName = path.join(automateTempFolder, `${apiName}API.ts`)
|
|
42
|
+
|
|
43
|
+
if (fs.existsSync(fileName)) {
|
|
44
|
+
fs.rmSync(fileName)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
console.log('Creating file', fileName)
|
|
48
|
+
fs.writeFileSync(fileName, file)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
console.log('running eslint')
|
|
52
|
+
const results = await eslint.lintFiles(['generator/Automate/**/*.ts'])
|
|
53
|
+
await ESLint.outputFixes(results)
|
|
54
|
+
const formatter = await eslint.loadFormatter('stylish')
|
|
55
|
+
const resultText = formatter.format(results)
|
|
56
|
+
console.log('eslint results', resultText)
|
|
57
|
+
|
|
58
|
+
console.log('copying files to src/')
|
|
59
|
+
const files = fs.readdirSync(path.join(__dirname, 'Automate'))
|
|
60
|
+
files.forEach((file) => {
|
|
61
|
+
const automateFolder = path.join(__dirname, '../src', 'Automate')
|
|
62
|
+
if (!fs.existsSync(automateFolder)) {
|
|
63
|
+
fs.mkdirSync(automateFolder)
|
|
64
|
+
}
|
|
65
|
+
const src = path.join(automateTempFolder, file)
|
|
66
|
+
const dest = path.join(automateFolder, file)
|
|
67
|
+
console.log(`${src} ==> ${dest}`)
|
|
68
|
+
fs.copyFileSync(src, dest)
|
|
69
|
+
})
|
|
70
|
+
fs.rmSync(automateTempFolder, { recursive: true })
|
|
71
|
+
console.log('temp folder removed')
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
console.log('generating static Automate client files')
|
|
75
|
+
generate().then(() => console.log('done'))
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
+
const fs = require('fs')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
function getAutomateJson() {
|
|
9
|
+
const sections = []
|
|
10
|
+
|
|
11
|
+
const files = fs.readdirSync(path.join(__dirname, 'automate-json'))
|
|
12
|
+
files.forEach((fileName) => {
|
|
13
|
+
const section = require(path.join(__dirname, 'automate-json', fileName))
|
|
14
|
+
|
|
15
|
+
Object.keys(section.paths).forEach((path) => {
|
|
16
|
+
Object.keys(section.paths[path]).forEach((method) => {
|
|
17
|
+
const definition = section.paths[path][method]
|
|
18
|
+
const operationId = definition.operationId.split('_').pop()
|
|
19
|
+
section.paths[path][method] = {
|
|
20
|
+
...definition,
|
|
21
|
+
// manually define api section
|
|
22
|
+
// clean up operation names
|
|
23
|
+
operationId: operationId.charAt(0).toLowerCase() + operationId.slice(1),
|
|
24
|
+
section: fileName.replace('.json', ''),
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
sections.push(section)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const automate = {
|
|
32
|
+
openapi: '',
|
|
33
|
+
info: {},
|
|
34
|
+
components: {
|
|
35
|
+
requestBodies: {},
|
|
36
|
+
schemas: {},
|
|
37
|
+
},
|
|
38
|
+
paths: {},
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
sections.forEach((section) => {
|
|
42
|
+
const {
|
|
43
|
+
openapi,
|
|
44
|
+
info,
|
|
45
|
+
components: { requestBodies, schemas },
|
|
46
|
+
paths,
|
|
47
|
+
} = section
|
|
48
|
+
|
|
49
|
+
automate.openapi = openapi
|
|
50
|
+
automate.info = { ...info }
|
|
51
|
+
automate.components.requestBodies = { ...requestBodies, ...automate.components.requestBodies }
|
|
52
|
+
automate.components.schemas = { ...schemas, ...automate.components.schemas }
|
|
53
|
+
automate.paths = { ...paths, ...automate.paths }
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
return automate
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = {
|
|
60
|
+
getAutomateJson,
|
|
61
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
+
const openapiTS = require('openapi-typescript')
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const { getAutomateJson } = require('./automate-json.js')
|
|
6
|
+
|
|
7
|
+
const automate = await getAutomateJson()
|
|
8
|
+
const types = await openapiTS(automate)
|
|
9
|
+
fs.writeFileSync(path.join(__dirname, 'AutomateTypes.ts'), types)
|
|
10
|
+
fs.copyFileSync(
|
|
11
|
+
path.join(__dirname, 'AutomateTypes.ts'),
|
|
12
|
+
path.join(__dirname, '../src/Automate/AutomateTypes.ts'),
|
|
13
|
+
)
|
|
14
|
+
fs.rmSync(path.join(__dirname, 'AutomateTypes.ts'))
|
|
15
|
+
console.log('done')
|