swaggerhub-cli 0.12.1 → 0.13.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,7 +1,7 @@
1
1
  {
2
2
  "name": "swaggerhub-cli",
3
3
  "description": "SwaggerHub CLI",
4
- "version": "0.12.1",
4
+ "version": "0.13.0",
5
5
  "author": "SmartBear",
6
6
  "bin": {
7
7
  "swaggerhub": "./bin/run"
@@ -14,10 +14,13 @@
14
14
  "archiver": "^7.0.1",
15
15
  "deep-extend": "^0.6.0",
16
16
  "fs-extra": "^11.1.1",
17
+ "http-proxy-agent": "^9.1.0",
18
+ "https-proxy-agent": "^9.1.0",
17
19
  "inquirer": "^8.2.5",
18
20
  "js-yaml": "^5.2.2",
19
21
  "json-templates": "^5.0.0",
20
22
  "node-fetch": "^2.6.12",
23
+ "proxy-from-env": "^2.1.0",
21
24
  "semver": "^7.6.0",
22
25
  "unzipper": "^0.12.3"
23
26
  },
@@ -25,7 +28,7 @@
25
28
  "@faker-js/faker": "^10.0.0",
26
29
  "@oclif/test": "^3.2.15",
27
30
  "chai": "^6.3.0",
28
- "eslint": "^10.10.0",
31
+ "eslint": "^10.13.0",
29
32
  "eslint-plugin-chai-friendly": "^1.0.0",
30
33
  "eslint-plugin-immutable": "^1.0.0",
31
34
  "eslint-plugin-mocha": "^11.3.0",
@@ -40,13 +43,13 @@
40
43
  "tmp": "^0.2.7"
41
44
  },
42
45
  "engines": {
43
- "node": "^20.17.0 || >=22.9.0",
46
+ "node": ">=22.9.0",
44
47
  "npm": ">=11.9.0"
45
48
  },
46
49
  "overrides": {
47
50
  "npm": "^11.9.0",
48
51
  "glob": "^10.5.0",
49
- "serialize-javascript": "^7.0.5"
52
+ "serialize-javascript": "^7.1.4"
50
53
  },
51
54
  "files": [
52
55
  "/bin",
@@ -1,4 +1,4 @@
1
- const { Args } = require('@oclif/core')
1
+ const { Flags, Args } = require('@oclif/core')
2
2
  const { getDomainIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
3
3
  const BaseCommand = require('../../support/command/base-command')
4
4
  const UpdateCommand = require('../../support/command/update-command')
@@ -6,18 +6,19 @@ const UpdateCommand = require('../../support/command/update-command')
6
6
  class PublishCommand extends UpdateCommand {
7
7
 
8
8
  async run() {
9
- const { args } = await this.parse(PublishCommand)
9
+ const { args, flags } = await this.parse(PublishCommand)
10
10
  const domainPath = getDomainIdentifierArg(args)
11
11
  const [owner, name, version] = splitPathParams(domainPath)
12
12
 
13
- await this.updatePublish('domains', owner, name, version, true)
13
+ await this.updatePublish('domains', owner, name, version, true, flags)
14
14
  }
15
15
  }
16
16
 
17
17
  PublishCommand.description = 'publish a domain version'
18
18
 
19
19
  PublishCommand.examples = [
20
- 'swaggerhub domain:publish organization/domain/1.0.0'
20
+ 'swaggerhub domain:publish organization/domain/1.0.0',
21
+ 'swaggerhub domain:publish organization/domain/1.0.0 --force'
21
22
  ]
22
23
 
23
24
  PublishCommand.args = {
@@ -27,6 +28,12 @@ PublishCommand.args = {
27
28
  })
28
29
  }
29
30
 
30
- PublishCommand.flags = BaseCommand.flags
31
+ PublishCommand.flags = {
32
+ force: Flags.boolean({
33
+ char: 'f',
34
+ description: 'publish domain without prompting for confirmation'
35
+ }),
36
+ ...BaseCommand.flags
37
+ }
31
38
 
32
39
  module.exports = PublishCommand
@@ -1,4 +1,4 @@
1
- const { ux, Args } = require('@oclif/core')
1
+ const { ux, Args, Flags } = require('@oclif/core')
2
2
  const { getProject } = require('../../requests/project')
3
3
  const { getResponseContent } = require('../../support/command/handle-response')
4
4
  const BaseCommand = require('../../support/command/base-command')
@@ -10,8 +10,8 @@ class ListProjectCommand extends BaseCommand {
10
10
  }
11
11
 
12
12
  async run() {
13
- const { args } = await this.parse(ListProjectCommand)
14
- await this.listProjects(args['OWNER'])
13
+ const { args, flags } = await this.parse(ListProjectCommand)
14
+ await this.listProjects(args['OWNER'], flags)
15
15
  }
16
16
 
17
17
  async logProject(response) {
@@ -33,9 +33,12 @@ class ListProjectCommand extends BaseCommand {
33
33
  }
34
34
  }
35
35
 
36
- async listProjects(args) {
36
+ async listProjects(owner, { limit, page, order }) {
37
+ const queryParams = Object.fromEntries(
38
+ Object.entries({ limit, page, order }).filter(([, value]) => value !== undefined)
39
+ )
37
40
  return this.executeHttp({
38
- execute: () => getProject([args]),
41
+ execute: () => getProject([owner], Object.keys(queryParams).length ? queryParams : undefined),
39
42
  onResolve: this.logProject,
40
43
  options: {}
41
44
  })
@@ -46,7 +49,9 @@ ListProjectCommand.description = 'list projects'
46
49
 
47
50
  ListProjectCommand.examples = [
48
51
  'swaggerhub project:list',
49
- 'swaggerhub project:list organization'
52
+ 'swaggerhub project:list organization',
53
+ 'swaggerhub project:list organization --limit 20 --order DESC',
54
+ 'swaggerhub project:list organization --page 2 --limit 20'
50
55
  ]
51
56
 
52
57
  ListProjectCommand.args = {
@@ -57,7 +62,21 @@ ListProjectCommand.args = {
57
62
  }
58
63
 
59
64
  ListProjectCommand.flags = {
60
- ...BaseCommand.flags
65
+ ...BaseCommand.flags,
66
+ limit: Flags.integer({
67
+ char: 'l',
68
+ min: 1,
69
+ max: 100,
70
+ description: 'number of projects per page (1-100)'
71
+ }),
72
+ page: Flags.integer({
73
+ min: 0,
74
+ description: 'zero-based page of projects to return'
75
+ }),
76
+ order: Flags.string({
77
+ options: ['ASC', 'DESC'],
78
+ description: 'sort order of the projects'
79
+ })
61
80
  }
62
81
 
63
82
  module.exports = ListProjectCommand
@@ -1,6 +1,7 @@
1
1
  const BaseCommand = require('./base-command')
2
2
  const { putSpec } = require('../../requests/spec')
3
3
  const { handleErrors } = require('./handle-response')
4
+ const inquirer = require('inquirer')
4
5
 
5
6
  class UpdateCommand extends BaseCommand {
6
7
 
@@ -8,20 +9,21 @@ class UpdateCommand extends BaseCommand {
8
9
  const pathParams = [owner, name, version, 'settings', 'lifecycle']
9
10
  const body = JSON.stringify({ published: isPublished })
10
11
  const successMessage = isPublished ? 'published' : 'unpublished'
12
+ const typeLabel = type === 'apis' ? 'API' : 'domain'
11
13
 
12
14
  await this.executeHttp({
13
15
  execute: () => flags.force ? putSpec(type, pathParams, body, flags) : putSpec(type, pathParams, body),
14
16
  onResolve: this.setSuccessMessage(successMessage)({
15
- type: type === 'apis' ? 'API' : 'domain',
17
+ type: typeLabel,
16
18
  path: `${owner}/${name}/${version}`
17
19
  }),
18
20
  onReject: async err => {
19
- if (err.status === 424 && type === 'apis') {
21
+ if (err.status === 424) {
20
22
  if (await this.confirmPublish() === true) {
21
- this.executeHttp({
23
+ await this.executeHttp({
22
24
  execute: () => putSpec(type, pathParams, body, { 'force': 'true' }),
23
25
  onResolve: this.setSuccessMessage(successMessage)({
24
- type: 'API',
26
+ type: typeLabel,
25
27
  path: `${owner}/${name}/${version}`
26
28
  }),
27
29
  options: { resolveStatus: [403] }
@@ -35,6 +37,20 @@ class UpdateCommand extends BaseCommand {
35
37
  })
36
38
  }
37
39
 
40
+ async confirmPublish() {
41
+ const confirm = await inquirer.prompt([
42
+ {
43
+ type: 'confirm',
44
+ name: 'answer',
45
+ message: `A conflict was detected with other resources referencing or referenced by this definition.
46
+ Forcing the change may affect them.
47
+ Do you wish to continue?`,
48
+ default: false
49
+ }
50
+ ])
51
+ return confirm.answer
52
+ }
53
+
38
54
  async updateDefault(type, owner, name, version) {
39
55
  const pathParams = [owner, name, 'settings', 'default']
40
56
  const body = JSON.stringify({ version })
@@ -2,6 +2,7 @@ const fetch = require('node-fetch')
2
2
  const qs = require('querystring')
3
3
  const headerTemplates = require('./header-templates')
4
4
  const defaultHeaders = require('./default-headers')
5
+ const { agentFor } = require('./proxy-agent')
5
6
 
6
7
  const { pipe, pick, omit } = require('../../utils/general')
7
8
 
@@ -34,7 +35,7 @@ const parseHeaders = options => {
34
35
  }
35
36
  }
36
37
 
37
- const request = ({ url, ...options }) => fetch(url, options)
38
+ const request = ({ url, ...options }) => fetch(url, { agent: agentFor, ...options })
38
39
 
39
40
  module.exports = options => (
40
41
  pipe(parseQuery, parseUrl, parseHeaders, request)(options)
@@ -0,0 +1,25 @@
1
+ const { getProxyForUrl } = require('proxy-from-env')
2
+ const { HttpsProxyAgent } = require('https-proxy-agent')
3
+ const { HttpProxyAgent } = require('http-proxy-agent')
4
+
5
+ const normalizeProxy = proxy => {
6
+ try {
7
+ return new URL(proxy).href
8
+ } catch {
9
+ throw new Error('Invalid proxy URL in HTTP_PROXY/HTTPS_PROXY environment variable')
10
+ }
11
+ }
12
+
13
+ const agentFor = parsedUrl => {
14
+ const proxy = getProxyForUrl(parsedUrl.href)
15
+ if (!proxy) {
16
+ return undefined
17
+ }
18
+
19
+ const proxyUrl = normalizeProxy(proxy)
20
+ return parsedUrl.protocol === 'https:' ?
21
+ new HttpsProxyAgent(proxyUrl) :
22
+ new HttpProxyAgent(proxyUrl)
23
+ }
24
+
25
+ module.exports = { agentFor }