connectwise-rest 1.2.1 → 1.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "connectwise-rest",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "A nodejs module for interacting with the ConnectWise Manage and Automate REST APIs.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -10,7 +10,9 @@
10
10
  "clean:dist": "npx rimraf dist/",
11
11
  "clean:src": "npx rimraf src/Manage/ & npx rimraf src/Automate/",
12
12
  "clean": "npm run clean:dist & npm run clean:generator & npm run clean:src",
13
- "test": "npx nyc mocha",
13
+ "test": "npm run test:manage",
14
+ "test:automate": "npx nyc mocha test/test-automate.js",
15
+ "test:manage": "npx nyc mocha test/test-manage.js",
14
16
  "pregenerate": "npm run clean",
15
17
  "generate:automate": "node generator/automate-generator.js",
16
18
  "generate:manage": "node generator/manage-generator.js",
@@ -27,7 +29,7 @@
27
29
  },
28
30
  "repository": {
29
31
  "type": "git",
30
- "url": "https://github.com/covenanttechnologysolutions/connectwise-rest"
32
+ "url": "git+https://github.com/covenanttechnologysolutions/connectwise-rest"
31
33
  },
32
34
  "keywords": [
33
35
  "connectwise",
@@ -47,7 +49,7 @@
47
49
  },
48
50
  "homepage": "https://github.com/covenanttechnologysolutions/connectwise-rest",
49
51
  "dependencies": {
50
- "axios": "^0.26.1",
52
+ "axios": "^1.6.7",
51
53
  "promise-retry": "^2.0.1"
52
54
  },
53
55
  "devDependencies": {
@@ -69,7 +71,7 @@
69
71
  "mocha": "^9.2.2",
70
72
  "mocha-lcov-reporter": "^1.3.0",
71
73
  "nyc": "^15.1.0",
72
- "openapi-typescript": "^5.4.1",
74
+ "openapi-typescript": "^6.7.4",
73
75
  "prettier": "^2.6.0",
74
76
  "rimraf": "^3.0.2",
75
77
  "ts-node": "^10.7.0",
@@ -6407,7 +6407,7 @@ export class SystemAPI extends Manage {
6407
6407
  params: CommonParameters = {},
6408
6408
  ): Promise<Array<WorkflowActionUserDefinedField>> {
6409
6409
  return this.request({
6410
- path: `/system/workflows/userdefinedfields/events${grandparentId}/actions/${parentId}`,
6410
+ path: `/system/workflows/userdefinedfields/events/${grandparentId}/actions/${parentId}`,
6411
6411
  method: 'get',
6412
6412
  params,
6413
6413
  })
package/src/Manage.ts CHANGED
@@ -1,4 +1,4 @@
1
- import axios, { AxiosError, AxiosInstance, AxiosResponse } from 'axios'
1
+ import axios, { AxiosInstance, InternalAxiosRequestConfig } from 'axios'
2
2
  import { makeRequest, makePaginate, PaginationOptions, PaginationApiMethod } from './BaseAPI'
3
3
  import promiseRetry from 'promise-retry'
4
4
  import type { CWMOptions } from './ManageAPI'
@@ -6,6 +6,13 @@ import { CWLogger, DataResponse, ErrorResponse, RequestOptions, RetryOptions } f
6
6
 
7
7
  const CW_MANAGE_DEBUG = !!process.env.CW_MANAGE_DEBUG
8
8
 
9
+ /**
10
+ * DEFAULTS variable.
11
+ * @type {Object}
12
+ * @property {RetryOptions} retryOptions - Retry options for API requests.
13
+ * @property {string} apiPath - The endpoint path for API requests.
14
+ * @property {(debug: boolean) => CWLogger} logger - Logger function that takes a boolean flag to enable debug mode.
15
+ */
9
16
  export const DEFAULTS: {
10
17
  retryOptions: RetryOptions
11
18
  apiPath: string
@@ -43,6 +50,12 @@ export const DEFAULTS: {
43
50
  },
44
51
  }
45
52
 
53
+ /**
54
+ * Represents a class for managing configuration options.
55
+ *
56
+ * @interface
57
+ * @extends CWMOptions
58
+ */
46
59
  export interface ManageConfig extends CWMOptions {
47
60
  authorization: string
48
61
  entryPoint: string
@@ -133,6 +146,26 @@ export default class Manage {
133
146
  },
134
147
  })
135
148
 
149
+ this.instance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
150
+ if (
151
+ config.url &&
152
+ config.headers &&
153
+ config.method === 'get' &&
154
+ config.headers.Accept &&
155
+ typeof config.headers.Accept === 'string'
156
+ ) {
157
+ //check for requests to /system/documents/{id}/download
158
+ const documentDownloadEndpointRegExp = /^\/system\/documents\/[0-9]*\/download$/
159
+ if (documentDownloadEndpointRegExp.test(config.url)) {
160
+ //replace the string "application/json" with "blob" in the Accept header
161
+ config.headers.Accept = config.headers.Accept.replace('application/json', 'blob')
162
+ //add response type 'stream' to axios response type
163
+ config.responseType = 'stream'
164
+ }
165
+ }
166
+ return config
167
+ })
168
+
136
169
  this.request = makeRequest({ config: this.config, api: this.api, thisObj: this })
137
170
  this.paginate = makePaginate({ thisObj: this })
138
171
  }
package/src/ManageAPI.ts CHANGED
@@ -32,7 +32,7 @@ import { CWLogger, RetryOptions } from './types'
32
32
  export type PatchOperation = {
33
33
  op: 'add' | 'replace' | 'remove'
34
34
  path: string
35
- value: Record<string, unknown> | Record<string, unknown>[] | string | null
35
+ value: unknown
36
36
  }
37
37
 
38
38
  /**
package/swagger-errors.md CHANGED
@@ -23,3 +23,6 @@ getRequest specified as path but should be query
23
23
 
24
24
  **System.getSystemWorkflowsByParentIdEventsByIdTest**
25
25
  Missing return type
26
+
27
+ **System.getSystemWorkflowsUserdefinedfieldsByGrandparentIdActionsByParentId**
28
+ Missing slash in path
@@ -0,0 +1,120 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+ const dotenv = require('dotenv')
3
+ const path = require('path')
4
+ const { AutomateAPI } = require('../dist')
5
+ const assert = require('assert')
6
+ const { describe, it } = require('mocha')
7
+
8
+ dotenv.config({ path: path.join(__dirname, '.env') })
9
+
10
+ const { AUTOMATE_API_CLIENT_ID, AUTOMATE_API_PASSWORD, AUTOMATE_API_URL, AUTOMATE_API_USER } =
11
+ process.env
12
+
13
+ const cwa = new AutomateAPI({
14
+ clientId: AUTOMATE_API_CLIENT_ID,
15
+ serverUrl: AUTOMATE_API_URL,
16
+ username: AUTOMATE_API_USER,
17
+ password: AUTOMATE_API_PASSWORD,
18
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
19
+ logger: () => {},
20
+ })
21
+
22
+ describe('Automate', () => {
23
+ describe('instance', () => {
24
+ it('should be an instance of Automate', (done) => {
25
+ assert(cwa instanceof AutomateAPI)
26
+ done()
27
+ })
28
+
29
+ it('should have AVTemplatePoliciesAPI', (done) => {
30
+ assert(cwa.AVTemplatePoliciesAPI)
31
+ done()
32
+ })
33
+ it('should have ClientsAPI', (done) => {
34
+ assert(cwa.ClientsAPI)
35
+ done()
36
+ })
37
+ it('should have CommandsAPI', (done) => {
38
+ assert(cwa.CommandsAPI)
39
+ done()
40
+ })
41
+ it('should have ComputersAPI', (done) => {
42
+ assert(cwa.ComputersAPI)
43
+ done()
44
+ })
45
+ it('should have ContactsAPI', (done) => {
46
+ assert(cwa.ContactsAPI)
47
+ done()
48
+ })
49
+ it('should have DataViewsAPI', (done) => {
50
+ assert(cwa.DataViewsAPI)
51
+ done()
52
+ })
53
+ it('should have DrivesAPI', (done) => {
54
+ assert(cwa.DrivesAPI)
55
+ done()
56
+ })
57
+ it('should have EventLogsAPI', (done) => {
58
+ assert(cwa.EventLogsAPI)
59
+ done()
60
+ })
61
+ it('should have LocationsAPI', (done) => {
62
+ assert(cwa.LocationsAPI)
63
+ done()
64
+ })
65
+ it('should have MaintenanceWindowDefinitionsAPI', (done) => {
66
+ assert(cwa.MaintenanceWindowDefinitionsAPI)
67
+ done()
68
+ })
69
+ it('should have MonitorsAPI', (done) => {
70
+ assert(cwa.MonitorsAPI)
71
+ done()
72
+ })
73
+ it('should have NetworkDevicesAPI', (done) => {
74
+ assert(cwa.NetworkDevicesAPI)
75
+ done()
76
+ })
77
+ it('should have PatchingAPI', (done) => {
78
+ assert(cwa.PatchingAPI)
79
+ done()
80
+ })
81
+ it('should have RemoteAgentAPI', (done) => {
82
+ assert(cwa.RemoteAgentAPI)
83
+ done()
84
+ })
85
+ it('should have ScriptingAPI', (done) => {
86
+ assert(cwa.ScriptingAPI)
87
+ done()
88
+ })
89
+ it('should have SearchesAPI', (done) => {
90
+ assert(cwa.SearchesAPI)
91
+ done()
92
+ })
93
+ it('should have SystemAPI', (done) => {
94
+ assert(cwa.SystemAPI)
95
+ done()
96
+ })
97
+ it('should have TicketsAPI', (done) => {
98
+ assert(cwa.TicketsAPI)
99
+ done()
100
+ })
101
+ it('should have UserProfilesAPI', (done) => {
102
+ assert(cwa.UserProfilesAPI)
103
+ done()
104
+ })
105
+ })
106
+
107
+ describe('ComputersAPI', () => {
108
+ it('should return a list of computers', (done) => {
109
+ cwa.ComputersAPI.getComputerList({ pageSize: 1 })
110
+ .then((results) => {
111
+ assert(results.length === 1)
112
+ const computer = results[0]
113
+ assert(computer.Id)
114
+ assert(computer.ComputerName)
115
+ done()
116
+ })
117
+ .catch((error) => done(error))
118
+ })
119
+ })
120
+ })
@@ -4,7 +4,7 @@
4
4
  /* eslint-disable @typescript-eslint/no-var-requires */
5
5
  const dotenv = require('dotenv')
6
6
  const path = require('path')
7
- const { ManageAPI, AutomateAPI, utils } = require('../dist')
7
+ const { ManageAPI, utils } = require('../dist')
8
8
  const assert = require('assert')
9
9
  const { describe, it } = require('mocha')
10
10
  const { isPromise } = require('./test-utils.js')
@@ -17,10 +17,6 @@ const {
17
17
  MANAGE_API_PUBLIC_KEY,
18
18
  MANAGE_API_PRIVATE_KEY,
19
19
  MANAGE_API_CLIENT_ID,
20
- AUTOMATE_API_CLIENT_ID,
21
- AUTOMATE_API_PASSWORD,
22
- AUTOMATE_API_URL,
23
- AUTOMATE_API_USER,
24
20
  } = process.env
25
21
 
26
22
  const cwm = new ManageAPI({
@@ -34,115 +30,6 @@ const cwm = new ManageAPI({
34
30
  logger: () => {},
35
31
  })
36
32
 
37
- const cwa = new AutomateAPI({
38
- clientId: AUTOMATE_API_CLIENT_ID,
39
- serverUrl: AUTOMATE_API_URL,
40
- username: AUTOMATE_API_USER,
41
- password: AUTOMATE_API_PASSWORD,
42
- // eslint-disable-next-line @typescript-eslint/no-empty-function
43
- logger: () => {},
44
- })
45
-
46
- describe('Automate', () => {
47
- describe('instance', () => {
48
- it('should be an instance of Automate', (done) => {
49
- assert(cwa instanceof AutomateAPI)
50
- done()
51
- })
52
-
53
- it('should have AVTemplatePoliciesAPI', (done) => {
54
- assert(cwa.AVTemplatePoliciesAPI)
55
- done()
56
- })
57
- it('should have ClientsAPI', (done) => {
58
- assert(cwa.ClientsAPI)
59
- done()
60
- })
61
- it('should have CommandsAPI', (done) => {
62
- assert(cwa.CommandsAPI)
63
- done()
64
- })
65
- it('should have ComputersAPI', (done) => {
66
- assert(cwa.ComputersAPI)
67
- done()
68
- })
69
- it('should have ContactsAPI', (done) => {
70
- assert(cwa.ContactsAPI)
71
- done()
72
- })
73
- it('should have DataViewsAPI', (done) => {
74
- assert(cwa.DataViewsAPI)
75
- done()
76
- })
77
- it('should have DrivesAPI', (done) => {
78
- assert(cwa.DrivesAPI)
79
- done()
80
- })
81
- it('should have EventLogsAPI', (done) => {
82
- assert(cwa.EventLogsAPI)
83
- done()
84
- })
85
- it('should have LocationsAPI', (done) => {
86
- assert(cwa.LocationsAPI)
87
- done()
88
- })
89
- it('should have MaintenanceWindowDefinitionsAPI', (done) => {
90
- assert(cwa.MaintenanceWindowDefinitionsAPI)
91
- done()
92
- })
93
- it('should have MonitorsAPI', (done) => {
94
- assert(cwa.MonitorsAPI)
95
- done()
96
- })
97
- it('should have NetworkDevicesAPI', (done) => {
98
- assert(cwa.NetworkDevicesAPI)
99
- done()
100
- })
101
- it('should have PatchingAPI', (done) => {
102
- assert(cwa.PatchingAPI)
103
- done()
104
- })
105
- it('should have RemoteAgentAPI', (done) => {
106
- assert(cwa.RemoteAgentAPI)
107
- done()
108
- })
109
- it('should have ScriptingAPI', (done) => {
110
- assert(cwa.ScriptingAPI)
111
- done()
112
- })
113
- it('should have SearchesAPI', (done) => {
114
- assert(cwa.SearchesAPI)
115
- done()
116
- })
117
- it('should have SystemAPI', (done) => {
118
- assert(cwa.SystemAPI)
119
- done()
120
- })
121
- it('should have TicketsAPI', (done) => {
122
- assert(cwa.TicketsAPI)
123
- done()
124
- })
125
- it('should have UserProfilesAPI', (done) => {
126
- assert(cwa.UserProfilesAPI)
127
- done()
128
- })
129
- })
130
-
131
- describe('ComputersAPI', () => {
132
- it('should return a list of computers', (done) => {
133
- cwa.ComputersAPI.getComputerList({ pageSize: 1 })
134
- .then((results) => {
135
- assert(results.length === 1)
136
- const computer = results[0]
137
- assert(computer.Id)
138
- assert(computer.ComputerName)
139
- done()
140
- })
141
- .catch((error) => done(error))
142
- })
143
- })
144
- })
145
-
146
33
  describe('Manage', () => {
147
34
  describe('instance', () => {
148
35
  it('should be an instance of Manage', (done) => {
@@ -278,10 +165,12 @@ describe('Manage', () => {
278
165
  cwm
279
166
  .paginate(cwm.CompanyAPI.getCompanyCommunicationTypes, { pageSize: 2, startPage: 1 }, {})
280
167
  .then((pagedResults) => {
281
- return cwm.CompanyAPI.getCompanyCommunicationTypes().then((unPagedResults) => {
282
- assert(unPagedResults.length === pagedResults.length)
283
- done()
284
- })
168
+ return cwm.CompanyAPI.getCompanyCommunicationTypes({ pageSize: 50 }).then(
169
+ (unPagedResults) => {
170
+ assert(unPagedResults.length === pagedResults.length)
171
+ done()
172
+ },
173
+ )
285
174
  })
286
175
  .catch((err) => done(err))
287
176
  })