bump-cli 2.3.1 → 2.3.2-beta

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.
@@ -1,6 +1,6 @@
1
1
  import * as Config from '@oclif/config';
2
2
  import { AxiosInstance, AxiosResponse } from 'axios';
3
- import { PingResponse, PreviewRequest, PreviewResponse, VersionRequest, VersionResponse, WithDiff } from './models';
3
+ import { PingResponse, PreviewRequest, PreviewResponse, VersionRequest, VersionResponse, DiffRequest, DiffResponse, WithDiff } from './models';
4
4
  import APIError from './error';
5
5
  declare class BumpApi {
6
6
  protected config: Config.IConfig;
@@ -11,6 +11,8 @@ declare class BumpApi {
11
11
  postPreview: (body?: PreviewRequest | undefined) => Promise<AxiosResponse<PreviewResponse>>;
12
12
  putPreview: (versionId: string, body?: PreviewRequest | undefined) => Promise<AxiosResponse<PreviewResponse>>;
13
13
  postVersion: (body: VersionRequest, token: string) => Promise<AxiosResponse<VersionResponse>>;
14
+ postDiff: (body: DiffRequest) => Promise<AxiosResponse<DiffResponse>>;
15
+ getDiff: (diffId: string) => Promise<AxiosResponse<DiffResponse>>;
14
16
  postValidation: (body: VersionRequest, token: string) => Promise<AxiosResponse<void>>;
15
17
  private initializeResponseInterceptor;
16
18
  private handleError;
package/lib/api/index.js CHANGED
@@ -29,6 +29,12 @@ class BumpApi {
29
29
  headers: this.authorizationHeader(token),
30
30
  });
31
31
  };
32
+ this.postDiff = (body) => {
33
+ return this.client.post('/diffs', body);
34
+ };
35
+ this.getDiff = (diffId) => {
36
+ return this.client.get(`/diffs/${diffId}`);
37
+ };
32
38
  this.postValidation = (body, token) => {
33
39
  return this.client.post('/validations', body, {
34
40
  headers: this.authorizationHeader(token),
@@ -41,6 +41,20 @@ export interface WithDiff {
41
41
  diff_details?: DiffItem[];
42
42
  diff_breaking?: boolean;
43
43
  }
44
+ export interface DiffRequest {
45
+ definition: string;
46
+ references?: Reference[];
47
+ previous_definition: string;
48
+ previous_references?: Reference[];
49
+ }
50
+ export interface DiffResponse {
51
+ id: string;
52
+ public_url?: string;
53
+ text?: string;
54
+ markdown?: string;
55
+ details?: DiffItem[];
56
+ breaking?: boolean;
57
+ }
44
58
  export interface DiffItem {
45
59
  id: string;
46
60
  name: string;
@@ -1,6 +1,6 @@
1
1
  import Command from '../command';
2
2
  import * as flags from '../flags';
3
- import { WithDiff } from '../api/models';
3
+ import { DiffResponse } from '../api/models';
4
4
  export default class Diff extends Command {
5
5
  static description: string;
6
6
  static examples: string[];
@@ -17,5 +17,5 @@ export default class Diff extends Command {
17
17
  description: string;
18
18
  }[];
19
19
  run(): Promise<void>;
20
- displayCompareResult(result: WithDiff, format: string, open: boolean): Promise<void>;
20
+ displayCompareResult(result: DiffResponse, format: string, open: boolean): Promise<void>;
21
21
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
+ const errors_1 = require("@oclif/errors");
4
5
  const command_1 = (0, tslib_1.__importDefault)(require("../command"));
5
6
  const flags = (0, tslib_1.__importStar)(require("../flags"));
6
7
  const diff_1 = require("../core/diff");
@@ -15,7 +16,6 @@ class Diff extends command_1.default {
15
16
  */
16
17
  async run() {
17
18
  const { args, flags } = this.parse(Diff);
18
- /* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
19
19
  const [documentation, hub, token] = [flags.doc, flags.hub, flags.token];
20
20
  if (flags.format == 'text') {
21
21
  if (args.FILE2) {
@@ -25,6 +25,9 @@ class Diff extends command_1.default {
25
25
  cli_1.cli.action.start('* Comparing the given definition file with the currently deployed one');
26
26
  }
27
27
  }
28
+ if (!args.FILE2 && (!documentation || !token)) {
29
+ throw new errors_1.CLIError('Please provide a second file argument or login with an existing token');
30
+ }
28
31
  const diff = await new diff_1.Diff(this.config).run(args.FILE, args.FILE2, documentation, hub, token);
29
32
  cli_1.cli.action.stop();
30
33
  if (diff) {
@@ -39,20 +42,20 @@ class Diff extends command_1.default {
39
42
  return;
40
43
  }
41
44
  async displayCompareResult(result, format, open) {
42
- if (format == 'text' && result.diff_summary) {
43
- await cli_1.cli.log(result.diff_summary);
45
+ if (format == 'text' && result.text) {
46
+ await cli_1.cli.log(result.text);
44
47
  }
45
- else if (format == 'markdown' && result.diff_markdown) {
46
- await cli_1.cli.log(result.diff_markdown);
48
+ else if (format == 'markdown' && result.markdown) {
49
+ await cli_1.cli.log(result.markdown);
47
50
  }
48
- else if (format == 'json' && result.diff_details) {
49
- await cli_1.cli.log(JSON.stringify(result.diff_details, null, 2));
51
+ else if (format == 'json' && result.details) {
52
+ await cli_1.cli.log(JSON.stringify(result.details, null, 2));
50
53
  }
51
54
  else {
52
55
  await cli_1.cli.log('No structural changes detected.');
53
56
  }
54
- if (open && result.diff_public_url) {
55
- await cli_1.cli.open(result.diff_public_url);
57
+ if (open && result.public_url) {
58
+ await cli_1.cli.open(result.public_url);
56
59
  }
57
60
  }
58
61
  }
@@ -91,9 +94,9 @@ Diff.examples = [
91
94
  ];
92
95
  Diff.flags = {
93
96
  help: flags.help({ char: 'h' }),
94
- doc: flags.doc(),
97
+ doc: flags.doc({ required: false }),
95
98
  hub: flags.hub(),
96
- token: flags.token(),
99
+ token: flags.token({ required: false }),
97
100
  open: flags.open({ description: 'Open the visual diff in your browser' }),
98
101
  format: flags.format(),
99
102
  };
@@ -1,18 +1,22 @@
1
1
  import * as Config from '@oclif/config';
2
2
  import { BumpApi } from '../api';
3
- import { VersionResponse, WithDiff } from '../api/models';
3
+ import { VersionResponse, WithDiff, DiffResponse } from '../api/models';
4
4
  export declare class Diff {
5
5
  _bump: BumpApi;
6
6
  _config: Config.IConfig;
7
7
  constructor(config: Config.IConfig);
8
- run(file1: string, file2: string | undefined, documentation: string, hub: string | undefined, token: string): Promise<WithDiff | undefined>;
8
+ run(file1: string, file2: string | undefined, documentation: string | undefined, hub: string | undefined, token: string | undefined): Promise<DiffResponse | undefined>;
9
9
  get bumpClient(): BumpApi;
10
10
  get pollingPeriod(): number;
11
+ createDiff(file1: string, file2: string): Promise<DiffResponse | undefined>;
11
12
  createVersion(file: string, documentation: string, token: string, hub: string | undefined, previous_version_id?: string | undefined): Promise<VersionResponse | undefined>;
12
- waitResult(result: VersionResponse, token: string, opts: {
13
+ waitResult(result: VersionResponse | DiffResponse, token: string | undefined, opts: {
13
14
  timeout: number;
14
- }): Promise<WithDiff>;
15
+ }): Promise<DiffResponse>;
15
16
  pollingDelay(): Promise<void>;
16
17
  private delay;
17
18
  d(formatter: any, ...args: any[]): void;
19
+ isVersion(result: VersionResponse | DiffResponse): result is VersionResponse;
20
+ isVersionWithDiff(result: (VersionResponse & WithDiff) | DiffResponse): result is VersionResponse & WithDiff;
21
+ extractDiff(versionWithDiff: VersionResponse & WithDiff): DiffResponse;
18
22
  }
package/lib/core/diff.js CHANGED
@@ -11,13 +11,18 @@ class Diff {
11
11
  this._config = config;
12
12
  }
13
13
  async run(file1, file2, documentation, hub, token) {
14
- const version = await this.createVersion(file1, documentation, token, hub);
15
14
  let diffVersion = undefined;
16
- if (file2) {
17
- diffVersion = await this.createVersion(file2, documentation, token, hub, version && version.id);
15
+ if (file2 && (!documentation || !token)) {
16
+ diffVersion = await this.createDiff(file1, file2);
18
17
  }
19
18
  else {
20
- diffVersion = version;
19
+ if (!documentation || !token) {
20
+ throw new Error('Please login to bump (with documentation & token) when using a single file argument');
21
+ }
22
+ diffVersion = await this.createVersion(file1, documentation, token, hub);
23
+ if (file2) {
24
+ diffVersion = await this.createVersion(file2, documentation, token, hub, diffVersion && diffVersion.id);
25
+ }
21
26
  }
22
27
  if (diffVersion) {
23
28
  return await this.waitResult(diffVersion, token, {
@@ -36,6 +41,29 @@ class Diff {
36
41
  get pollingPeriod() {
37
42
  return 1000;
38
43
  }
44
+ async createDiff(file1, file2) {
45
+ const api = await definition_1.API.load(file1);
46
+ const [previous_definition, previous_references] = api.extractDefinition();
47
+ const api2 = await definition_1.API.load(file2);
48
+ const [definition, references] = api2.extractDefinition();
49
+ const request = {
50
+ previous_definition,
51
+ previous_references,
52
+ definition,
53
+ references,
54
+ };
55
+ const response = await this.bumpClient.postDiff(request);
56
+ switch (response.status) {
57
+ case 201:
58
+ this.d(`Diff created with ID ${response.data.id}`);
59
+ this.d(response.data);
60
+ return response.data;
61
+ break;
62
+ case 204:
63
+ break;
64
+ }
65
+ return;
66
+ }
39
67
  async createVersion(file, documentation, token, hub, previous_version_id = undefined) {
40
68
  const api = await definition_1.API.load(file);
41
69
  const [definition, references] = api.extractDefinition();
@@ -59,13 +87,22 @@ class Diff {
59
87
  return;
60
88
  }
61
89
  async waitResult(result, token, opts) {
62
- const diffResponse = await this.bumpClient.getVersion(result.id, token);
90
+ let pollingResponse = undefined;
91
+ if (this.isVersion(result) && token) {
92
+ pollingResponse = await this.bumpClient.getVersion(result.id, token);
93
+ }
94
+ else {
95
+ pollingResponse = await this.bumpClient.getDiff(result.id);
96
+ }
63
97
  if (opts.timeout <= 0) {
64
98
  throw new errors_1.CLIError('We were unable to compute your documentation diff. Sorry about that. Please try again later');
65
99
  }
66
- switch (diffResponse.status) {
100
+ switch (pollingResponse.status) {
67
101
  case 200:
68
- const diff = diffResponse.data;
102
+ let diff = pollingResponse.data;
103
+ if (this.isVersionWithDiff(diff)) {
104
+ diff = this.extractDiff(diff);
105
+ }
69
106
  this.d('Received diff:');
70
107
  this.d(diff);
71
108
  return diff;
@@ -92,5 +129,22 @@ class Diff {
92
129
  d(formatter, ...args) {
93
130
  return (0, debug_1.default)(`bump-cli:core:diff`)(formatter, ...args);
94
131
  }
132
+ isVersion(result) {
133
+ return result.doc_public_url !== undefined;
134
+ }
135
+ isVersionWithDiff(result) {
136
+ return result.diff_summary !== undefined;
137
+ }
138
+ extractDiff(versionWithDiff) {
139
+ // TODO: return a real diff_id in the GET /version API
140
+ return {
141
+ id: versionWithDiff.id,
142
+ public_url: versionWithDiff.diff_public_url,
143
+ text: versionWithDiff.diff_summary,
144
+ markdown: versionWithDiff.diff_markdown,
145
+ details: versionWithDiff.diff_details,
146
+ breaking: versionWithDiff.diff_breaking,
147
+ };
148
+ }
95
149
  }
96
150
  exports.Diff = Diff;
package/lib/index.d.ts CHANGED
@@ -2,5 +2,5 @@ import { run } from '@oclif/command';
2
2
  import { Diff } from './core/diff';
3
3
  import Deploy from './commands/deploy';
4
4
  import Preview from './commands/preview';
5
- import { VersionResponse, WithDiff } from './api/models';
6
- export { run, Deploy, Diff, Preview, VersionResponse, WithDiff };
5
+ export { VersionResponse, PreviewResponse, DiffResponse, WithDiff } from './api/models';
6
+ export { run, Deploy, Diff, Preview };
@@ -1 +1 @@
1
- {"version":"2.3.1","commands":{"deploy":{"id":"deploy","description":"create a new version of your documentation from the given file or URL","pluginName":"bump-cli","pluginType":"core","aliases":[],"examples":["Deploy a new version of an existing documentation\n\n$ bump deploy FILE --doc <your_doc_id_or_slug> --token <your_doc_token>\n* Let's deploy a new documentation version on Bump... done\n* Your new documentation version will soon be ready\n","Deploy a new version of an existing documentation attached to a hub\n\n$ bump deploy FILE --doc <doc_slug> --hub <your_hub_id_or_slug> --token <your_doc_token>\n* Let's deploy a new documentation version on Bump... done\n* Your new documentation version will soon be ready\n","Validate a new documentation version before deploying it\n\n$ bump deploy FILE --dry-run --doc <doc_slug> --token <your_doc_token>\n* Let's validate a new documentation version on Bump... done\n* Definition is valid\n"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"doc":{"name":"doc","type":"option","char":"d","description":"Documentation public id or slug. Can be provided via BUMP_ID environment variable","required":true},"doc-name":{"name":"doc-name","type":"option","char":"n","description":"Documentation name. Used with --auto-create flag."},"hub":{"name":"hub","type":"option","char":"b","description":"Hub id or slug. Can be provided via BUMP_HUB_ID environment variable"},"token":{"name":"token","type":"option","char":"t","description":"Documentation or Hub token. Can be provided via BUMP_TOKEN environment variable","required":true},"auto-create":{"name":"auto-create","type":"boolean","description":"Automatically create the documentation if needed (only available with a --hub flag). Documentation name can be provided with --doc-name flag. Default: false","allowNo":false},"dry-run":{"name":"dry-run","type":"boolean","description":"Validate a new documentation version. Does everything a normal deploy would do except publishing the new version. Useful in automated environments such as test platforms or continuous integration. Default: false","allowNo":false}},"args":[{"name":"FILE","description":"Path or URL to your API documentation file. OpenAPI (2.0 to 3.1.0) and AsyncAPI (2.0 to 2.2) specifications are currently supported.","required":true}]},"diff":{"id":"diff","description":"Get a comparaison diff with your documentation from the given file or URL","pluginName":"bump-cli","pluginType":"core","aliases":[],"examples":["Compare a potential new version with the currently published one:\n\n $ bump diff FILE --doc <your_doc_id_or_slug> --token <your_doc_token>\n * Comparing the given definition file with the currently deployed one... done\n Removed: GET /compare\n Added: GET /versions/{versionId}\n","Store the diff in a dedicated file:\n\n $ bump diff FILE --doc <doc_slug> --token <doc_token> > /tmp/my-saved-diff\n * Comparing the given definition file with the currently deployed one... done\n\n $ cat /tmp/my-saved-diff\n Removed: GET /compare\n Added: GET /versions/{versionId}\n","In case of a non modified definition FILE compared to your existing documentation, no changes are output:\n\n $ bump diff FILE --doc <doc_slug> --token <your_doc_token>\n * Comparing the given definition file with the currently deployed one... done\n › Warning: Your documentation has not changed\n","Compare two different input files or URL independently to the one published on bump.sh\n\n $ bump diff FILE FILE2 --doc <doc_slug> --token <your_doc_token>\n * Comparing the two given definition files... done\n Updated: POST /versions\n Body attribute added: previous_version_id\n"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"doc":{"name":"doc","type":"option","char":"d","description":"Documentation public id or slug. Can be provided via BUMP_ID environment variable","required":true},"hub":{"name":"hub","type":"option","char":"b","description":"Hub id or slug. Can be provided via BUMP_HUB_ID environment variable"},"token":{"name":"token","type":"option","char":"t","description":"Documentation or Hub token. Can be provided via BUMP_TOKEN environment variable","required":true},"open":{"name":"open","type":"boolean","char":"o","description":"Open the visual diff in your browser","allowNo":false},"format":{"name":"format","type":"option","char":"f","description":"Format in which to provide the diff result","options":["text","markdown","json"],"default":"text"}},"args":[{"name":"FILE","description":"Path or URL to your API documentation file. OpenAPI (2.0 to 3.1.0) and AsyncAPI (2.0 to 2.2) specifications are currently supported.","required":true},{"name":"FILE2","description":"Path or URL to a second API documentation file to compute its diff"}]},"preview":{"id":"preview","description":"create a documentation preview from the given file or URL","pluginName":"bump-cli","pluginType":"core","aliases":[],"examples":["$ bump preview FILE\n* Your preview is visible at: https://bump.sh/preview/45807371-9a32-48a7-b6e4-1cb7088b5b9b\n"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"live":{"name":"live","type":"boolean","char":"l","description":"Generate a preview each time you save the given file","allowNo":false},"open":{"name":"open","type":"boolean","char":"o","description":"Open the generated preview URL in your browser","allowNo":false}},"args":[{"name":"FILE","description":"Path or URL to your API documentation file. OpenAPI (2.0 to 3.1.0) and AsyncAPI (2.0 to 2.2) specifications are currently supported.","required":true}]}}}
1
+ {"version":"2.3.2-beta","commands":{"deploy":{"id":"deploy","description":"create a new version of your documentation from the given file or URL","pluginName":"bump-cli","pluginType":"core","aliases":[],"examples":["Deploy a new version of an existing documentation\n\n$ bump deploy FILE --doc <your_doc_id_or_slug> --token <your_doc_token>\n* Let's deploy a new documentation version on Bump... done\n* Your new documentation version will soon be ready\n","Deploy a new version of an existing documentation attached to a hub\n\n$ bump deploy FILE --doc <doc_slug> --hub <your_hub_id_or_slug> --token <your_doc_token>\n* Let's deploy a new documentation version on Bump... done\n* Your new documentation version will soon be ready\n","Validate a new documentation version before deploying it\n\n$ bump deploy FILE --dry-run --doc <doc_slug> --token <your_doc_token>\n* Let's validate a new documentation version on Bump... done\n* Definition is valid\n"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"doc":{"name":"doc","type":"option","char":"d","description":"Documentation public id or slug. Can be provided via BUMP_ID environment variable","required":true},"doc-name":{"name":"doc-name","type":"option","char":"n","description":"Documentation name. Used with --auto-create flag."},"hub":{"name":"hub","type":"option","char":"b","description":"Hub id or slug. Can be provided via BUMP_HUB_ID environment variable"},"token":{"name":"token","type":"option","char":"t","description":"Documentation or Hub token. Can be provided via BUMP_TOKEN environment variable","required":true},"auto-create":{"name":"auto-create","type":"boolean","description":"Automatically create the documentation if needed (only available with a --hub flag). Documentation name can be provided with --doc-name flag. Default: false","allowNo":false},"dry-run":{"name":"dry-run","type":"boolean","description":"Validate a new documentation version. Does everything a normal deploy would do except publishing the new version. Useful in automated environments such as test platforms or continuous integration. Default: false","allowNo":false}},"args":[{"name":"FILE","description":"Path or URL to your API documentation file. OpenAPI (2.0 to 3.1.0) and AsyncAPI (2.0 to 2.2) specifications are currently supported.","required":true}]},"diff":{"id":"diff","description":"Get a comparaison diff with your documentation from the given file or URL","pluginName":"bump-cli","pluginType":"core","aliases":[],"examples":["Compare a potential new version with the currently published one:\n\n $ bump diff FILE --doc <your_doc_id_or_slug> --token <your_doc_token>\n * Comparing the given definition file with the currently deployed one... done\n Removed: GET /compare\n Added: GET /versions/{versionId}\n","Store the diff in a dedicated file:\n\n $ bump diff FILE --doc <doc_slug> --token <doc_token> > /tmp/my-saved-diff\n * Comparing the given definition file with the currently deployed one... done\n\n $ cat /tmp/my-saved-diff\n Removed: GET /compare\n Added: GET /versions/{versionId}\n","In case of a non modified definition FILE compared to your existing documentation, no changes are output:\n\n $ bump diff FILE --doc <doc_slug> --token <your_doc_token>\n * Comparing the given definition file with the currently deployed one... done\n › Warning: Your documentation has not changed\n","Compare two different input files or URL independently to the one published on bump.sh\n\n $ bump diff FILE FILE2 --doc <doc_slug> --token <your_doc_token>\n * Comparing the two given definition files... done\n Updated: POST /versions\n Body attribute added: previous_version_id\n"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"doc":{"name":"doc","type":"option","char":"d","description":"Documentation public id or slug. Can be provided via BUMP_ID environment variable","required":false},"hub":{"name":"hub","type":"option","char":"b","description":"Hub id or slug. Can be provided via BUMP_HUB_ID environment variable"},"token":{"name":"token","type":"option","char":"t","description":"Documentation or Hub token. Can be provided via BUMP_TOKEN environment variable","required":false},"open":{"name":"open","type":"boolean","char":"o","description":"Open the visual diff in your browser","allowNo":false},"format":{"name":"format","type":"option","char":"f","description":"Format in which to provide the diff result","options":["text","markdown","json"],"default":"text"}},"args":[{"name":"FILE","description":"Path or URL to your API documentation file. OpenAPI (2.0 to 3.1.0) and AsyncAPI (2.0 to 2.2) specifications are currently supported.","required":true},{"name":"FILE2","description":"Path or URL to a second API documentation file to compute its diff"}]},"preview":{"id":"preview","description":"create a documentation preview from the given file or URL","pluginName":"bump-cli","pluginType":"core","aliases":[],"examples":["$ bump preview FILE\n* Your preview is visible at: https://bump.sh/preview/45807371-9a32-48a7-b6e4-1cb7088b5b9b\n"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"live":{"name":"live","type":"boolean","char":"l","description":"Generate a preview each time you save the given file","allowNo":false},"open":{"name":"open","type":"boolean","char":"o","description":"Open the generated preview URL in your browser","allowNo":false}},"args":[{"name":"FILE","description":"Path or URL to your API documentation file. OpenAPI (2.0 to 3.1.0) and AsyncAPI (2.0 to 2.2) specifications are currently supported.","required":true}]}}}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bump-cli",
3
3
  "description": "The Bump CLI is used to interact with your API documentation hosted on Bump by using the API of developers.bump.sh",
4
- "version": "2.3.1",
4
+ "version": "2.3.2-beta",
5
5
  "author": "Paul Bonaud <paulr@bump.sh>",
6
6
  "bin": {
7
7
  "bump": "./bin/run"
@@ -82,7 +82,7 @@
82
82
  "@oclif/config": "^1.17.0",
83
83
  "@oclif/plugin-help": "^5.1.10",
84
84
  "async-mutex": "^0.3.2",
85
- "axios": "^0.24.0",
85
+ "axios": "^0.25.0",
86
86
  "cli-ux": "^6.0.7",
87
87
  "debug": "^4.3.1",
88
88
  "oas-schemas": "git+https://git@github.com/OAI/OpenAPI-Specification.git#0f9d3ec7c033fef184ec54e1ffc201b2d61ce023",