connectwise-rest 1.0.0 → 1.0.1

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 (217) hide show
  1. package/.eslintrc +23 -26
  2. package/README.md +62 -12
  3. package/api-extractor.json +364 -364
  4. package/dist/Automate/AVTemplatePoliciesAPI.d.ts +10 -1
  5. package/dist/Automate/AVTemplatePoliciesAPI.d.ts.map +1 -1
  6. package/dist/Automate/AVTemplatePoliciesAPI.js +6 -1
  7. package/dist/Automate/AVTemplatePoliciesAPI.js.map +1 -1
  8. package/dist/Automate/ClientsAPI.d.ts +11 -1
  9. package/dist/Automate/ClientsAPI.d.ts.map +1 -1
  10. package/dist/Automate/ClientsAPI.js +6 -1
  11. package/dist/Automate/ClientsAPI.js.map +1 -1
  12. package/dist/Automate/CommandsAPI.d.ts +6 -1
  13. package/dist/Automate/CommandsAPI.d.ts.map +1 -1
  14. package/dist/Automate/CommandsAPI.js +6 -1
  15. package/dist/Automate/CommandsAPI.js.map +1 -1
  16. package/dist/Automate/ComputersAPI.d.ts +38 -1
  17. package/dist/Automate/ComputersAPI.d.ts.map +1 -1
  18. package/dist/Automate/ComputersAPI.js +6 -1
  19. package/dist/Automate/ComputersAPI.js.map +1 -1
  20. package/dist/Automate/ContactsAPI.d.ts +7 -1
  21. package/dist/Automate/ContactsAPI.d.ts.map +1 -1
  22. package/dist/Automate/ContactsAPI.js +6 -1
  23. package/dist/Automate/ContactsAPI.js.map +1 -1
  24. package/dist/Automate/DataViewsAPI.d.ts +7 -1
  25. package/dist/Automate/DataViewsAPI.d.ts.map +1 -1
  26. package/dist/Automate/DataViewsAPI.js +6 -1
  27. package/dist/Automate/DataViewsAPI.js.map +1 -1
  28. package/dist/Automate/DrivesAPI.d.ts +7 -1
  29. package/dist/Automate/DrivesAPI.d.ts.map +1 -1
  30. package/dist/Automate/DrivesAPI.js +6 -1
  31. package/dist/Automate/DrivesAPI.js.map +1 -1
  32. package/dist/Automate/EventLogsAPI.d.ts +6 -1
  33. package/dist/Automate/EventLogsAPI.d.ts.map +1 -1
  34. package/dist/Automate/EventLogsAPI.js +6 -1
  35. package/dist/Automate/EventLogsAPI.js.map +1 -1
  36. package/dist/Automate/LocationsAPI.d.ts +16 -1
  37. package/dist/Automate/LocationsAPI.d.ts.map +1 -1
  38. package/dist/Automate/LocationsAPI.js +6 -1
  39. package/dist/Automate/LocationsAPI.js.map +1 -1
  40. package/dist/Automate/MaintenanceWindowDefinitionsAPI.d.ts +6 -1
  41. package/dist/Automate/MaintenanceWindowDefinitionsAPI.d.ts.map +1 -1
  42. package/dist/Automate/MaintenanceWindowDefinitionsAPI.js +6 -1
  43. package/dist/Automate/MaintenanceWindowDefinitionsAPI.js.map +1 -1
  44. package/dist/Automate/MonitorsAPI.d.ts +7 -1
  45. package/dist/Automate/MonitorsAPI.d.ts.map +1 -1
  46. package/dist/Automate/MonitorsAPI.js +6 -1
  47. package/dist/Automate/MonitorsAPI.js.map +1 -1
  48. package/dist/Automate/NetworkDevicesAPI.d.ts +7 -1
  49. package/dist/Automate/NetworkDevicesAPI.d.ts.map +1 -1
  50. package/dist/Automate/NetworkDevicesAPI.js +6 -1
  51. package/dist/Automate/NetworkDevicesAPI.js.map +1 -1
  52. package/dist/Automate/PatchingAPI.d.ts +7 -1
  53. package/dist/Automate/PatchingAPI.d.ts.map +1 -1
  54. package/dist/Automate/PatchingAPI.js +6 -1
  55. package/dist/Automate/PatchingAPI.js.map +1 -1
  56. package/dist/Automate/RemoteAgentAPI.d.ts +7 -1
  57. package/dist/Automate/RemoteAgentAPI.d.ts.map +1 -1
  58. package/dist/Automate/RemoteAgentAPI.js +6 -1
  59. package/dist/Automate/RemoteAgentAPI.js.map +1 -1
  60. package/dist/Automate/ScriptingAPI.d.ts +10 -1
  61. package/dist/Automate/ScriptingAPI.d.ts.map +1 -1
  62. package/dist/Automate/ScriptingAPI.js +6 -1
  63. package/dist/Automate/ScriptingAPI.js.map +1 -1
  64. package/dist/Automate/SearchesAPI.d.ts +7 -1
  65. package/dist/Automate/SearchesAPI.d.ts.map +1 -1
  66. package/dist/Automate/SearchesAPI.js +6 -1
  67. package/dist/Automate/SearchesAPI.js.map +1 -1
  68. package/dist/Automate/SystemAPI.d.ts +28 -3
  69. package/dist/Automate/SystemAPI.d.ts.map +1 -1
  70. package/dist/Automate/SystemAPI.js +8 -3
  71. package/dist/Automate/SystemAPI.js.map +1 -1
  72. package/dist/Automate/TicketsAPI.d.ts +5 -1
  73. package/dist/Automate/TicketsAPI.d.ts.map +1 -1
  74. package/dist/Automate/TicketsAPI.js +6 -1
  75. package/dist/Automate/TicketsAPI.js.map +1 -1
  76. package/dist/Automate/UserProfilesAPI.d.ts +6 -1
  77. package/dist/Automate/UserProfilesAPI.d.ts.map +1 -1
  78. package/dist/Automate/UserProfilesAPI.js +6 -1
  79. package/dist/Automate/UserProfilesAPI.js.map +1 -1
  80. package/dist/Automate.d.ts +0 -5
  81. package/dist/Automate.d.ts.map +1 -1
  82. package/dist/Automate.js +0 -3
  83. package/dist/Automate.js.map +1 -1
  84. package/dist/AutomateAPI.d.ts +55 -22
  85. package/dist/AutomateAPI.d.ts.map +1 -1
  86. package/dist/AutomateAPI.js +46 -39
  87. package/dist/AutomateAPI.js.map +1 -1
  88. package/dist/BaseAPI.d.ts +13 -0
  89. package/dist/BaseAPI.d.ts.map +1 -1
  90. package/dist/BaseAPI.js +64 -1
  91. package/dist/BaseAPI.js.map +1 -1
  92. package/dist/Manage/CompanyAPI.d.ts +90 -1
  93. package/dist/Manage/CompanyAPI.d.ts.map +1 -1
  94. package/dist/Manage/CompanyAPI.js +6 -1
  95. package/dist/Manage/CompanyAPI.js.map +1 -1
  96. package/dist/Manage/ConfigurationsAPI.d.ts +9 -1
  97. package/dist/Manage/ConfigurationsAPI.d.ts.map +1 -1
  98. package/dist/Manage/ConfigurationsAPI.js +6 -1
  99. package/dist/Manage/ConfigurationsAPI.js.map +1 -1
  100. package/dist/Manage/ExpenseAPI.d.ts +18 -1
  101. package/dist/Manage/ExpenseAPI.d.ts.map +1 -1
  102. package/dist/Manage/ExpenseAPI.js +6 -1
  103. package/dist/Manage/ExpenseAPI.js.map +1 -1
  104. package/dist/Manage/FinanceAPI.d.ts +79 -1
  105. package/dist/Manage/FinanceAPI.d.ts.map +1 -1
  106. package/dist/Manage/FinanceAPI.js +6 -1
  107. package/dist/Manage/FinanceAPI.js.map +1 -1
  108. package/dist/Manage/MarketingAPI.d.ts +23 -1
  109. package/dist/Manage/MarketingAPI.d.ts.map +1 -1
  110. package/dist/Manage/MarketingAPI.js +6 -1
  111. package/dist/Manage/MarketingAPI.js.map +1 -1
  112. package/dist/Manage/ProcurementAPI.d.ts +63 -1
  113. package/dist/Manage/ProcurementAPI.d.ts.map +1 -1
  114. package/dist/Manage/ProcurementAPI.js +6 -1
  115. package/dist/Manage/ProcurementAPI.js.map +1 -1
  116. package/dist/Manage/ProjectAPI.d.ts +37 -1
  117. package/dist/Manage/ProjectAPI.d.ts.map +1 -1
  118. package/dist/Manage/ProjectAPI.js +6 -1
  119. package/dist/Manage/ProjectAPI.js.map +1 -1
  120. package/dist/Manage/SalesAPI.d.ts +46 -1
  121. package/dist/Manage/SalesAPI.d.ts.map +1 -1
  122. package/dist/Manage/SalesAPI.js +6 -1
  123. package/dist/Manage/SalesAPI.js.map +1 -1
  124. package/dist/Manage/ScheduleAPI.d.ts +22 -1
  125. package/dist/Manage/ScheduleAPI.d.ts.map +1 -1
  126. package/dist/Manage/ScheduleAPI.js +6 -1
  127. package/dist/Manage/ScheduleAPI.js.map +1 -1
  128. package/dist/Manage/ServiceAPI.d.ts +75 -1
  129. package/dist/Manage/ServiceAPI.d.ts.map +1 -1
  130. package/dist/Manage/ServiceAPI.js +6 -1
  131. package/dist/Manage/ServiceAPI.js.map +1 -1
  132. package/dist/Manage/SystemAPI.d.ts +146 -1
  133. package/dist/Manage/SystemAPI.d.ts.map +1 -1
  134. package/dist/Manage/SystemAPI.js +6 -1
  135. package/dist/Manage/SystemAPI.js.map +1 -1
  136. package/dist/Manage/TimeAPI.d.ts +30 -1
  137. package/dist/Manage/TimeAPI.d.ts.map +1 -1
  138. package/dist/Manage/TimeAPI.js +6 -1
  139. package/dist/Manage/TimeAPI.js.map +1 -1
  140. package/dist/Manage.d.ts +5 -0
  141. package/dist/Manage.d.ts.map +1 -1
  142. package/dist/Manage.js +10 -0
  143. package/dist/Manage.js.map +1 -1
  144. package/dist/ManageAPI.d.ts +51 -15
  145. package/dist/ManageAPI.d.ts.map +1 -1
  146. package/dist/ManageAPI.js +27 -24
  147. package/dist/ManageAPI.js.map +1 -1
  148. package/dist/connectwise-rest.d.ts +108638 -0
  149. package/dist/index.d.ts +6 -3
  150. package/dist/index.d.ts.map +1 -1
  151. package/dist/index.js +0 -2
  152. package/dist/index.js.map +1 -1
  153. package/dist/tsdoc-metadata.json +11 -0
  154. package/dist/types.d.ts +4 -2
  155. package/dist/types.d.ts.map +1 -1
  156. package/dist/types.js.map +1 -1
  157. package/dist/utils/Callback.d.ts +3 -0
  158. package/dist/utils/Callback.d.ts.map +1 -1
  159. package/dist/utils/Callback.js.map +1 -1
  160. package/dist/utils/Series.d.ts +6 -0
  161. package/dist/utils/Series.d.ts.map +1 -1
  162. package/dist/utils/Series.js +6 -2
  163. package/dist/utils/Series.js.map +1 -1
  164. package/package.json +5 -2
  165. package/src/Automate/AVTemplatePoliciesAPI.ts +11 -1
  166. package/src/Automate/ClientsAPI.ts +12 -1
  167. package/src/Automate/CommandsAPI.ts +7 -1
  168. package/src/Automate/ComputersAPI.ts +39 -1
  169. package/src/Automate/ContactsAPI.ts +8 -1
  170. package/src/Automate/DataViewsAPI.ts +8 -1
  171. package/src/Automate/DrivesAPI.ts +8 -1
  172. package/src/Automate/EventLogsAPI.ts +7 -1
  173. package/src/Automate/LocationsAPI.ts +17 -1
  174. package/src/Automate/MaintenanceWindowDefinitionsAPI.ts +7 -1
  175. package/src/Automate/MonitorsAPI.ts +8 -1
  176. package/src/Automate/NetworkDevicesAPI.ts +8 -1
  177. package/src/Automate/PatchingAPI.ts +8 -1
  178. package/src/Automate/RemoteAgentAPI.ts +8 -1
  179. package/src/Automate/ScriptingAPI.ts +11 -1
  180. package/src/Automate/SearchesAPI.ts +8 -1
  181. package/src/Automate/SystemAPI.ts +29 -3
  182. package/src/Automate/TicketsAPI.ts +6 -1
  183. package/src/Automate/UserProfilesAPI.ts +7 -1
  184. package/src/Automate.ts +0 -12
  185. package/src/AutomateAPI.ts +77 -43
  186. package/src/AutomateTypes.ts +1 -1
  187. package/src/BaseAPI.ts +97 -0
  188. package/src/Manage/CompanyAPI.ts +91 -1
  189. package/src/Manage/ConfigurationsAPI.ts +10 -1
  190. package/src/Manage/ExpenseAPI.ts +19 -1
  191. package/src/Manage/FinanceAPI.ts +80 -1
  192. package/src/Manage/MarketingAPI.ts +24 -1
  193. package/src/Manage/ProcurementAPI.ts +64 -1
  194. package/src/Manage/ProjectAPI.ts +38 -1
  195. package/src/Manage/SalesAPI.ts +47 -1
  196. package/src/Manage/ScheduleAPI.ts +23 -1
  197. package/src/Manage/ServiceAPI.ts +76 -1
  198. package/src/Manage/SystemAPI.ts +147 -1
  199. package/src/Manage/TimeAPI.ts +31 -1
  200. package/src/Manage.ts +10 -1
  201. package/src/ManageAPI.ts +66 -29
  202. package/src/index.ts +6 -11
  203. package/src/types.ts +4 -2
  204. package/src/utils/Callback.ts +3 -0
  205. package/src/utils/Series.ts +6 -0
  206. package/swagger-errors.md +25 -30
  207. package/test/test.ts +34 -5
  208. package/.github/workflows/codeql-analysis.yml +0 -70
  209. package/.github/workflows/node.js.yml +0 -42
  210. package/.travis.yml +0 -11
  211. package/generator/automate-generator.js +0 -75
  212. package/generator/automate-json.js +0 -61
  213. package/generator/automate-types.js +0 -15
  214. package/generator/generator.d.ts +0 -67
  215. package/generator/generator.js +0 -255
  216. package/generator/manage-generator.js +0 -71
  217. package/generator/manage-types.js +0 -14
package/test/test.ts CHANGED
@@ -8,9 +8,9 @@ import { ManageAPI, AutomateAPI, utils } from '../dist/index'
8
8
  import assert from 'assert'
9
9
  import { describe, it } from 'mocha'
10
10
  import type { components } from '../src/ManageTypes'
11
- import { isArrayOfPromises, PromiseArray } from './test-utils'
12
11
  import { isPromise } from './test-utils'
13
- import ComputersAPI, { LabTechModelsComputer } from '../src/Automate/ComputersAPI'
12
+ import { LabTechModelsComputer } from '../src/Automate/ComputersAPI'
13
+ import { CommunicationType } from '../src/Manage/CompanyAPI'
14
14
  type Ticket = components['schemas']['Ticket']
15
15
 
16
16
  dotenv.config({ path: path.join(__dirname, '.env') })
@@ -136,8 +136,8 @@ describe('Automate', () => {
136
136
  assert(cwa.SystemAPI)
137
137
  done()
138
138
  })
139
- it('should have TicketAPI', (done) => {
140
- assert(cwa.TicketAPI)
139
+ it('should have TicketsAPI', (done) => {
140
+ assert(cwa.TicketsAPI)
141
141
  done()
142
142
  })
143
143
  it('should have UserProfilesAPI', (done) => {
@@ -156,7 +156,7 @@ describe('Automate', () => {
156
156
  assert(computer.ComputerName)
157
157
  done()
158
158
  })
159
- .catch((error: any) => done(error))
159
+ .catch((error) => done(error))
160
160
  })
161
161
  })
162
162
  })
@@ -261,6 +261,35 @@ describe('Manage', () => {
261
261
  })
262
262
  })
263
263
  })
264
+
265
+ describe('pagination', () => {
266
+ it('should return an array of CommunicationTypes', (done) => {
267
+ cwm
268
+ .paginate(cwm.CompanyAPI.getCompanyCommunicationTypes, { pageSize: 2, startPage: 1 }, {})
269
+ .then((results) => {
270
+ assert(Array.isArray(results))
271
+ assert(results.length > 0)
272
+ const firstType = <CommunicationType>results.pop()
273
+ assert(firstType.id)
274
+ assert(firstType.description)
275
+ assert(firstType._info)
276
+ done()
277
+ })
278
+ .catch((err) => done(err))
279
+ })
280
+
281
+ it('should return the same number of items', (done) => {
282
+ cwm
283
+ .paginate(cwm.CompanyAPI.getCompanyCommunicationTypes, { pageSize: 2, startPage: 1 }, {})
284
+ .then((pagedResults) => {
285
+ return cwm.CompanyAPI.getCompanyCommunicationTypes().then((unPagedResults) => {
286
+ assert(unPagedResults.length === pagedResults.length)
287
+ done()
288
+ })
289
+ })
290
+ .catch((err) => done(err))
291
+ })
292
+ })
264
293
  })
265
294
 
266
295
  describe('utils', () => {
@@ -1,70 +0,0 @@
1
- # For most projects, this workflow file will not need changing; you simply need
2
- # to commit it to your repository.
3
- #
4
- # You may wish to alter this file to override the set of languages analyzed,
5
- # or to provide custom queries or build logic.
6
- #
7
- # ******** NOTE ********
8
- # We have attempted to detect the languages in your repository. Please check
9
- # the `language` matrix defined below to confirm you have the correct set of
10
- # supported CodeQL languages.
11
- #
12
- name: "CodeQL"
13
-
14
- on:
15
- push:
16
- branches: [ master, dev ]
17
- pull_request:
18
- # The branches below must be a subset of the branches above
19
- branches: [ master, dev ]
20
- schedule:
21
- - cron: '20 19 * * 4'
22
-
23
- jobs:
24
- analyze:
25
- name: Analyze
26
- runs-on: ubuntu-latest
27
- permissions:
28
- actions: read
29
- contents: read
30
- security-events: write
31
-
32
- strategy:
33
- fail-fast: false
34
- matrix:
35
- language: [ 'javascript', 'typescript' ]
36
- # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37
- # Learn more about CodeQL language support at https://git.io/codeql-language-support
38
-
39
- steps:
40
- - name: Checkout repository
41
- uses: actions/checkout@v2
42
-
43
- # Initializes the CodeQL tools for scanning.
44
- - name: Initialize CodeQL
45
- uses: github/codeql-action/init@v1
46
- with:
47
- languages: ${{ matrix.language }}
48
- # If you wish to specify custom queries, you can do so here or in a config file.
49
- # By default, queries listed here will override any specified in a config file.
50
- # Prefix the list here with "+" to use these queries and those in the config file.
51
- # queries: ./path/to/local/query, your-org/your-repo/queries@main
52
-
53
- # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
54
- # If this step fails, then you should remove it and run the build manually (see below)
55
- - name: Autobuild
56
- uses: github/codeql-action/autobuild@v1
57
-
58
- # ℹ️ Command-line programs to run using the OS shell.
59
- # 📚 https://git.io/JvXDl
60
-
61
- # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
62
- # and modify them (or add more) to build your code if your project
63
- # uses a compiled language
64
-
65
- #- run: |
66
- # make bootstrap
67
- # make release
68
-
69
- - name: Perform CodeQL Analysis
70
- uses: github/codeql-action/analyze@v1
@@ -1,42 +0,0 @@
1
- # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
- # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
-
4
- name: Node.js CI
5
-
6
- on:
7
- push:
8
- branches: [ master, dev ]
9
- pull_request:
10
- branches: [ master, dev ]
11
-
12
- jobs:
13
- build:
14
-
15
- runs-on: ubuntu-latest
16
-
17
- strategy:
18
- matrix:
19
- node-version: [12.x, 14.x, 16.x]
20
- # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21
-
22
- steps:
23
- - uses: actions/checkout@v2
24
- - name: Use Node.js ${{ matrix.node-version }}
25
- uses: actions/setup-node@v2
26
- with:
27
- node-version: ${{ matrix.node-version }}
28
- cache: 'npm'
29
- - run: npm ci
30
- - run: npm run build --if-present
31
- - run: npm test
32
- env:
33
- MANAGE_API_COMPANY: ${{ secrets.MANAGE_API_COMPANY }}
34
- MANAGE_API_URL: ${{ secrets.MANAGE_API_URL }}
35
- MANAGE_API_PUBLIC_KEY: ${{ secrets.MANAGE_API_PUBLIC_KEY }}
36
- MANAGE_API_PRIVATE_KEY: ${{ secrets.MANAGE_API_PRIVATE_KEY }}
37
- MANAGE_API_CLIENT_ID: ${{ secrets.MANAGE_API_CLIENT_ID }}
38
-
39
- AUTOMATE_API_URL: ${{ secrets.AUTOMATE_API_URL }}
40
- AUTOMATE_API_USER: ${{ secrets.AUTOMATE_API_USER }}
41
- AUTOMATE_API_PASSWORD: ${{ secrets.AUTOMATE_API_PASSWORD }}
42
- AUTOMATE_API_CLIENT_ID: ${{ secrets.AUTOMATE_API_CLIENT_ID }}
package/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - "8"
4
- - "10"
5
- - "12"
6
- - "14"
7
- - "16"
8
- after_script:
9
- - npm run coveralls
10
- before_script:
11
- - npm run build
@@ -1,75 +0,0 @@
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'))
@@ -1,61 +0,0 @@
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
- }
@@ -1,15 +0,0 @@
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')
@@ -1,67 +0,0 @@
1
- type Method = 'get' | 'post' | 'patch' | 'delete' | 'put'
2
- type ResponseTypes =
3
- | 'application/json'
4
- | 'text/json'
5
- | 'application/xml'
6
- | 'text/xml'
7
- | 'application/x-www-form-urlencoded'
8
-
9
- type Content = {
10
- [T in ResponseTypes]: {
11
- schema: Schema
12
- }
13
- }
14
-
15
- type RequestBody = {
16
- required?: boolean
17
- content: Content
18
- }
19
-
20
- type Responses = {
21
- 200?: {
22
- description: string
23
- content: Content
24
- }
25
- 204?: {
26
- description: string
27
- content: Content
28
- }
29
- }
30
-
31
- type Schema = {
32
- type: string
33
- enum?: Array<string>
34
- format?: string
35
- items?: {
36
- type?: string
37
- $ref?: string
38
- }
39
- }
40
-
41
- type Parameter = {
42
- name: string
43
- in: string
44
- required?: boolean
45
- explode?: boolean
46
- schema?: Schema
47
- }
48
-
49
- type Methods = {
50
- [T in Method]: Operation
51
- }
52
-
53
- type Operation = {
54
- tags?: Array<string>
55
- method: string
56
- operationId: string
57
- parameters: Array<Parameter>
58
- requestBody: {
59
- $ref: string
60
- }
61
- responses: Responses
62
- }
63
-
64
- type Components = {
65
- schemas: Record<string, Schema>
66
- requestBodies: Record<string, RequestBody>
67
- }
@@ -1,255 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-var-requires */
2
- const { getAutomateJson } = require('./automate-json')
3
-
4
- const automateSchema = getAutomateJson()
5
-
6
- const typeMapSanitize = (input = '') => {
7
- switch (input) {
8
- case 'integer':
9
- return 'number'
10
- case 'application/octet-stream':
11
- return 'OctetStreamResponse'
12
- case 'application/pdf':
13
- return 'PDFResponse'
14
- case 'text/html':
15
- return 'HTMLResponse'
16
- default:
17
- return sanitizeType(input)
18
- }
19
- }
20
-
21
- // remove invalid var name from the name of the type
22
- const sanitizeType = (input = '') => input.replace(/\./g, '').replace(/\//g, '')
23
- const generateTypeDef = ({ typeName, schemaType }) => {
24
- let name = sanitizeType(typeName)
25
-
26
- return schemaType === 'schemas'
27
- ? `export type ${name} = schemas['${typeName}']`
28
- : `export type ${name} = requestBodies['${typeName}']`
29
- }
30
-
31
- /**
32
- * @typedef {object} Operations
33
- * @property {string} url
34
- * @property {{}} methods
35
- */
36
-
37
- /**
38
- * decipher supplied definition files
39
- * @param {{}} options
40
- * @param {string} options.apiName
41
- * @param {} options.operations
42
- * @param {'Manage' | 'Automate'} options.generatorType
43
- */
44
- function generateAPIClass({ apiName, operations = [], generatorType }) {
45
- // types holder for generating type aliases
46
- // type Types = Record<string, string>
47
- // system name, sanitized name
48
- const types = {}
49
- const requestBodies = {}
50
-
51
- // loop over each defined operation for this module
52
- const functions = operations.map(({ url, methods }) =>
53
- Object.keys(methods)
54
- .map((method) => {
55
- const { responses, operationId, parameters = [], requestBody } = methods[method]
56
- const queryParams = parameters.filter(({ in: in_ }) => in_ === 'query')
57
- const pathParams = parameters.filter(({ in: in_ }) => in_ === 'path')
58
-
59
- // store generated names/types
60
- const functionParams = [] // args to the class function
61
- const requestParams = [] // args to this.request
62
- let bodyParam = {}
63
-
64
- // generally if a post command is defined
65
- if (requestBody) {
66
- if (requestBody.content && requestBody.content['application/json']) {
67
- const schema = requestBody.content['application/json'].schema
68
- if (schema.type === 'array') {
69
- if (schema.items) {
70
- const ref = schema.items.$ref
71
- const tempName = ref.split('/').pop()
72
- bodyParam.type = `Array<${tempName}>`
73
- bodyParam.name = tempName.charAt(0).toLowerCase() + tempName.slice(1) + 's'
74
-
75
- types[tempName] = {
76
- schemaType: ref.includes('requestBodies') ? 'requestBody' : 'schemas',
77
- }
78
- }
79
- } else if (schema.$ref) {
80
- const ref = schema.$ref
81
- bodyParam.type = ref.split('/').pop()
82
- if (requestBody.description) {
83
- bodyParam.name = requestBody.description
84
- } else {
85
- bodyParam.name = ref.split('.').pop()
86
- }
87
- types[bodyParam.type] = {
88
- schemaType: ref.includes('requestBodies') ? 'requestBody' : 'schemas',
89
- }
90
- // if clause for MonitorAlertSuspensions_PostSuspension
91
- } else if (!schema.description) {
92
- bodyParam.type = schema.type
93
- bodyParam.name = schema.type
94
- }
95
- } else if (requestBody.content && requestBody.content['multipart/form-data']) {
96
- const schema = requestBody.content['multipart/form-data'].schema
97
- if (schema.$ref) {
98
- const ref = schema.$ref
99
- bodyParam.type = ref.split('/').pop()
100
- bodyParam.name = bodyParam.type.charAt(0).toLowerCase() + bodyParam.type.slice(1)
101
- types[bodyParam.type] = {
102
- schemaType: ref.includes('requestBodies') ? 'requestBody' : 'schemas',
103
- }
104
- }
105
- } else if (requestBody.$ref) {
106
- const ref = requestBody.$ref
107
- // make sensible names by splitting the generated refs
108
- bodyParam.name = requestBody.$ref.split('/').pop().split('.').pop().split('_').pop()
109
- bodyParam.type = requestBody.$ref.split('/').pop()
110
- types[bodyParam.type] = {
111
- schemaType: ref.includes('requestBodies') ? 'requestBody' : 'schemas',
112
- }
113
- } else {
114
- bodyParam.name = requestBody.description
115
- bodyParam.type = 'object'
116
- }
117
-
118
- bodyParam.name = sanitizeType(bodyParam.name)
119
- }
120
-
121
- if (pathParams.length > 0) {
122
- pathParams.forEach((parameter) => {
123
- functionParams.push(`${parameter.name}: ${typeMapSanitize(parameter.schema.type)}`)
124
- })
125
- }
126
- requestParams.push(`path: \`${url.replaceAll(/({.+?})/g, (_, p1) => `$${p1}`)}\``)
127
- requestParams.push(`method: '${method}'`)
128
-
129
- if (requestBody) {
130
- functionParams.push(`${bodyParam.name}: ${typeMapSanitize(bodyParam.type)}`)
131
- requestParams.push(`data: ${bodyParam.name}`)
132
- }
133
-
134
- if (queryParams.length > 0) {
135
- functionParams.push('params: CommonParameters = {}')
136
- requestParams.push(`params`)
137
- }
138
- let returnType
139
- if (responses[204]) {
140
- returnType = 'NoContentResponse'
141
- } else {
142
- const { description, content } = responses[Object.keys(responses).pop()]
143
-
144
- if (responses['default']) {
145
- returnType = 'any'
146
- if (responses['default'].description) {
147
- returnType = `${returnType}`
148
- }
149
- } else if (content) {
150
- const { schema } = content[Object.keys(content).pop()]
151
-
152
- if (schema.items) {
153
- if (schema.items.$ref) {
154
- const ref = schema.items.$ref
155
- const tempName = ref.split('/').pop()
156
- returnType = `Array<${tempName}>`
157
- types[tempName] = {
158
- schemaType: ref.includes('requestBodies') ? 'requestBody' : 'schemas',
159
- }
160
- } else if (schema.items.additionalProperties?.$ref) {
161
- const ref = schema.items.additionalProperties.$ref
162
- const tempName = ref.split('/').pop()
163
- returnType = `Array<${tempName}>`
164
- types[tempName] = {
165
- schemaType: ref.includes('requestBodies') ? 'requestBody' : 'schemas',
166
- }
167
- } else if (schema.type) {
168
- if (schema.items.type) {
169
- returnType = `Array<${schema.items.type}>`
170
- } else {
171
- returnType = schema.type
172
- }
173
- }
174
- } else if (schema.$ref) {
175
- const ref = schema.$ref
176
- // fix for incorrect types from ResultSetWithCount
177
- if (ref.includes('LabTech.Database.ResultSetWithCount')) {
178
- const schemaName = ref.split('/').pop()
179
- const resultSchema = automateSchema.components.schemas[schemaName]
180
- const ResultSetRef = resultSchema.properties.ResultSet.items.$ref
181
- const tempName = ResultSetRef.split('/').pop()
182
- returnType = `Array<${tempName}>`
183
- types[tempName] = {
184
- schemaType: ref.includes('requestBodies') ? 'requestBody' : 'schemas',
185
- }
186
- } else {
187
- returnType = schema.$ref.split('/').pop()
188
- types[returnType] = {
189
- schemaType: ref.includes('requestBodies') ? 'requestBody' : 'schemas',
190
- }
191
- }
192
- } else {
193
- returnType = schema.type
194
- }
195
- } else {
196
- returnType = description.split(' ').pop()
197
- }
198
- }
199
-
200
- returnType = typeMapSanitize(returnType)
201
-
202
- if (!returnType) {
203
- returnType = 'any'
204
- }
205
-
206
- return `
207
- ${operationId}(${functionParams.map((param) => param).join(', ')}): Promise<${returnType}> {
208
- return this.request({
209
- ${requestParams.map((param) => param).join(', ')}
210
- })
211
- }`
212
- })
213
- .join('\n'),
214
- )
215
-
216
- // use true/false map to generate required types for this module
217
- const typeDefs = Object.keys(
218
- // sort keys to order imports
219
- Object.keys(types)
220
- .sort()
221
- .reduce((obj, key) => {
222
- obj[key] = types[key]
223
- return obj
224
- }, {}),
225
- ).map((type) => generateTypeDef({ typeName: type, schemaType: types[type].schemaType }))
226
-
227
- return `/* This file was auto-generated, do not manually edit. */
228
- import ${generatorType} from '../${generatorType}'
229
- import { components } from '../${generatorType}Types'
230
- ${
231
- generatorType === 'Manage'
232
- ? "import { CommonParameters, CWMOptions } from '../ManageAPI'"
233
- : "import { CommonParameters, CWAOptions } from '../AutomateAPI'"
234
- }
235
- import { NoContentResponse, OctetStreamResponse, PDFResponse, HTMLResponse } from '../types'
236
- type schemas = components['schemas']
237
- ${generatorType === 'Automate' ? `type requestBodies = components['requestBodies']` : ''}
238
- ${typeDefs.join('\n')}
239
-
240
- /**
241
- * @public
242
- */
243
- export default class ${apiName}API extends ${generatorType} {
244
- constructor(props: ${generatorType === 'Manage' ? 'CWMOptions' : 'CWAOptions'}) {
245
- super(props)
246
- }
247
-
248
- ${functions.join('\n')}
249
- }
250
- `
251
- }
252
-
253
- module.exports = {
254
- generateAPIClass,
255
- }