@useoptic/cli
Advanced tools
Comparing version 2.0.4 to 2.1.0
@@ -15,2 +15,8 @@ "use strict"; | ||
config = config_1.parseOpticYaml(config_1.readOpticYaml()); | ||
if (!config.strategy) { | ||
throw new Error('Your optic.yml is missing the strategy section'); | ||
} | ||
if (!config.api) { | ||
throw new Error('Your optic.yml is missing the api section'); | ||
} | ||
} | ||
@@ -21,5 +27,5 @@ catch (error) { | ||
const sessionManager = new core_1.SessionManager(config); | ||
cli_ux_1.cli.action.start('Observing API Behavior:'); | ||
cli_ux_1.cli.action.start('Observing API Behavior'); | ||
const successful = await sessionManager.run(); | ||
cli_ux_1.cli.action.stop('Analyzing…'); | ||
cli_ux_1.cli.action.start('Analyzing'); | ||
let shouldBuildReport = true; | ||
@@ -30,3 +36,4 @@ if (!successful) { | ||
} | ||
shouldBuildReport = await cli_ux_1.cli.confirm('The test command was not successful :( Continue anyway?'); | ||
cli_ux_1.cli.log('The test command was not successful :('); | ||
shouldBuildReport = await cli_ux_1.cli.confirm('Continue anyway? (y/n)'); | ||
} | ||
@@ -37,11 +44,12 @@ if (!shouldBuildReport) { | ||
} | ||
cli_ux_1.cli.action.start('Generating reports…'); | ||
cli_ux_1.cli.action.start('Generating reports'); | ||
const report = new report_builder_1.ReportBuilder().buildReport(config, sessionManager.samples); | ||
const { messages, observations } = report; | ||
messages.forEach(message => this.log(message)); | ||
config_1.writeOutput('observations.json', JSON.stringify(observations)); | ||
config_1.writeOutput('observations.json', JSON.stringify(observations, null, 2)); | ||
const observationsToGraph = new src_1.ObservationsToGraph(); | ||
observationsToGraph.interpretObservations(observations); | ||
config_1.writeOutput('graphviz.txt', observationsToGraph.graph.toGraphViz()); | ||
cli_ux_1.cli.action.stop('Done!'); | ||
cli_ux_1.cli.action.stop(); | ||
cli_ux_1.cli.log('Your API has now been documented! Next you might want to run api:publish'); | ||
} | ||
@@ -48,0 +56,0 @@ } |
import { Command } from '@oclif/command'; | ||
export declare type Callback<T> = (error: Error | null, result?: T) => void; | ||
export default class ApiPublish extends Command { | ||
@@ -3,0 +4,0 @@ static description: string; |
@@ -8,2 +8,3 @@ "use strict"; | ||
const path = require("path"); | ||
const api_id_1 = require("../../common/api-id"); | ||
const config_1 = require("../../common/config"); | ||
@@ -29,2 +30,5 @@ const credentials_1 = require("../../common/credentials"); | ||
config = config_1.parseOpticYaml(config_1.readOpticYaml()); | ||
if (!config.api) { | ||
throw new Error('Your optic.yml is missing the api section'); | ||
} | ||
} | ||
@@ -63,3 +67,3 @@ catch (error) { | ||
if (shouldPublish && status.isDirty) { | ||
return this.error('Sorry, I am not able to publish when there are uncommitted changes. Please commit your changes and try again.'); | ||
this.warn('There are uncommitted changes. Please make sure this is intended.'); | ||
} | ||
@@ -72,5 +76,6 @@ // this.log(JSON.stringify(status)) | ||
published: shouldPublish, | ||
version: config.api.version, | ||
observations | ||
}; | ||
cli_ux_1.cli.action.start('Uploading…'); | ||
cli_ux_1.cli.action.start('Uploading'); | ||
const token = await new credentials_1.Credentials().get(); | ||
@@ -81,19 +86,27 @@ if (token === null) { | ||
try { | ||
const splitApiId = config.api.id.split('/'); | ||
const apiId = splitApiId[splitApiId.length - 1]; | ||
const teamId = (splitApiId.length === 2) ? splitApiId[0] : undefined; | ||
const uploadResult = await new optic_1.OpticService(config.optic.apiBaseUrl).saveSnapshot(token, snapshot, apiId, teamId); | ||
const opticService = new optic_1.OpticService(config.optic.apiBaseUrl, () => ({ token })); | ||
const { teamSlug, apiSlug } = api_id_1.apiIdToTeamSlugAndApiSlug(config.api.id); | ||
let uploadResult; | ||
if (teamSlug) { | ||
uploadResult = await opticService.postTeamApiSnapshotByTeamSlugAndApiSlug(teamSlug, apiSlug, snapshot); | ||
} | ||
else { | ||
uploadResult = await opticService.postSelfApiSnapshotByApiSlug(apiSlug, snapshot); | ||
} | ||
if (uploadResult.statusCode !== 200) { | ||
return this.error(uploadResult.body); | ||
} | ||
cli_ux_1.cli.action.stop(); | ||
this.log('Upload complete! Opening your API Documentation on ' + config.optic.baseUrl); | ||
this.log(`Upload complete! Opening your API Documentation on ${config.optic.baseUrl}`); | ||
//@TODO use a proper url joining and query builder... | ||
const query = `?branch=${uploadResult.branch}&version=${uploadResult.uuid}`; | ||
if (teamId) { | ||
await cli_ux_1.cli.open(`${config.optic.baseUrl}/apis/${teamId}/${apiId}${query}`); | ||
const query = `?branch=${uploadResult.body.branch}&version=${uploadResult.body.uuid}`; | ||
if (teamSlug) { | ||
await cli_ux_1.cli.open(`${config.optic.baseUrl}/apis/${teamSlug}/${apiSlug}${query}`); | ||
} | ||
else { | ||
await cli_ux_1.cli.open(`${config.optic.baseUrl}/apis/${apiId}${query}`); | ||
await cli_ux_1.cli.open(`${config.optic.baseUrl}/apis/${apiSlug}${query}`); | ||
} | ||
} | ||
catch (error) { | ||
this.error(error); | ||
return this.error(error); | ||
} | ||
@@ -100,0 +113,0 @@ } |
@@ -9,3 +9,9 @@ "use strict"; | ||
try { | ||
config_1.parseOpticYaml(config_1.readOpticYaml()); | ||
const config = config_1.parseOpticYaml(config_1.readOpticYaml()); | ||
if (!config.strategy) { | ||
this.log('Your optic.yml is missing the strategy section - you will not be able to run api:document'); | ||
} | ||
if (!config.api) { | ||
this.log('Your optic.yml is missing the api section - you will not be able to run api:document or api:publish'); | ||
} | ||
this.log('Everything looks ok!'); | ||
@@ -12,0 +18,0 @@ } |
import { IOpticYamlConfig } from '@useoptic/core/build/src/optic-config'; | ||
export declare function parseOpticYaml(fileContents: string): IOpticYamlConfig; | ||
export declare function readOpticYaml(): string; | ||
export declare function writeOpticYaml(config: IOpticYamlConfig): void; | ||
export declare function writeOutput(outputFileName: string, contents: string): void; |
@@ -20,2 +20,6 @@ "use strict"; | ||
exports.readOpticYaml = readOpticYaml; | ||
function writeOpticYaml(config) { | ||
return fs.writeFileSync(optic_config_1.opticYamlFileName, yaml.dump(config)); | ||
} | ||
exports.writeOpticYaml = writeOpticYaml; | ||
function writeOutput(outputFileName, contents) { | ||
@@ -22,0 +26,0 @@ const outputFolder = './.optic'; |
@@ -1,3 +0,2 @@ | ||
import * as requestPromise from 'request-promise-native'; | ||
export interface IOpticApiSnapshot { | ||
export interface IOpticApiSnapshotRequest { | ||
observations: object; | ||
@@ -7,14 +6,6 @@ opticVersion: string; | ||
commitName: string; | ||
version: string; | ||
published: boolean; | ||
} | ||
declare class JsonHttpClient { | ||
private readonly baseUrl; | ||
constructor(baseUrl: string); | ||
postJsonWithToken(token: string, url: string, body: object): requestPromise.RequestPromise<any>; | ||
} | ||
declare class OpticService { | ||
private readonly httpClient; | ||
constructor(baseUrl: string); | ||
saveSnapshot(token: string, snapshot: IOpticApiSnapshot, apiId: string, teamId?: string): requestPromise.RequestPromise<any>; | ||
} | ||
export { OpticService, JsonHttpClient }; | ||
declare const OpticService: any; | ||
export { OpticService }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const requestPromise = require("request-promise-native"); | ||
class JsonHttpClient { | ||
constructor(baseUrl) { | ||
this.baseUrl = baseUrl; | ||
} | ||
postJsonWithToken(token, url, body) { | ||
const headers = { | ||
Authorization: `Bearer ${token}` | ||
}; | ||
return requestPromise | ||
.post(url, { | ||
baseUrl: this.baseUrl, | ||
headers, | ||
body, | ||
json: true, | ||
}); | ||
} | ||
} | ||
exports.JsonHttpClient = JsonHttpClient; | ||
class OpticService { | ||
constructor(baseUrl) { | ||
this.httpClient = new JsonHttpClient(baseUrl); | ||
} | ||
saveSnapshot(token, snapshot, apiId, teamId) { | ||
if (teamId) { | ||
return this.httpClient.postJsonWithToken(token, `/teams/${teamId}/apis/${apiId}/snapshots`, snapshot); | ||
} | ||
else { | ||
return this.httpClient.postJsonWithToken(token, `/self/apis/${apiId}/snapshots`, snapshot); | ||
} | ||
} | ||
} | ||
// @ts-ignore | ||
const api_js_client_1 = require("api-js-client"); | ||
const OpticService = api_js_client_1.Client; | ||
exports.OpticService = OpticService; |
@@ -1,1 +0,1 @@ | ||
{"version":"2.0.4","commands":{"api:document":{"id":"api:document","description":"document your API contract","pluginName":"@useoptic/cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"api:publish":{"id":"api:publish","description":"publish your API contract to Optic","pluginName":"@useoptic/cli","pluginType":"core","aliases":[],"flags":{"draft":{"name":"draft","type":"boolean","char":"d","allowNo":false}},"args":[]},"config:check":{"id":"config:check","description":"validate your optic.yml","pluginName":"@useoptic/cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"credentials:add-token":{"id":"credentials:add-token","description":"authenticate the CLI","pluginName":"@useoptic/cli","pluginType":"core","aliases":[],"flags":{},"args":[]}}} | ||
{"version":"2.1.0","commands":{"api:add":{"id":"api:add","description":"Install an Optic API and generate artifacts (Swagger/OAS, SDKs, etc.)","pluginName":"@useoptic/cli","pluginType":"core","aliases":[],"flags":{"outputDirectory":{"name":"outputDirectory","type":"option","char":"o","description":"directory to output generated artifacts (Swagger/OAS, SDKs, etc.)","required":false}},"args":[{"name":"apiId","description":"\"team/api\" or \"api\"","required":true},{"name":"apiVersion","description":"the version of \"apiId\" you want to consume","required":true}]},"api:document":{"id":"api:document","description":"document your API contract","pluginName":"@useoptic/cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"api:install":{"id":"api:install","description":"Generates artifacts (Swagger/OAS, SDKs, etc.) for the APIs that have been added via api:add","pluginName":"@useoptic/cli","pluginType":"core","aliases":[],"flags":{"outputDirectory":{"name":"outputDirectory","type":"option","char":"o","description":"directory to output generated artifacts (Swagger/OAS, SDKs, etc.)","required":true}},"args":[]},"api:publish":{"id":"api:publish","description":"publish your API contract to Optic","pluginName":"@useoptic/cli","pluginType":"core","aliases":[],"flags":{"draft":{"name":"draft","type":"boolean","char":"d","allowNo":false}},"args":[]},"config:check":{"id":"config:check","description":"validate your optic.yml","pluginName":"@useoptic/cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"credentials:add-token":{"id":"credentials:add-token","description":"authenticate the CLI","pluginName":"@useoptic/cli","pluginType":"core","aliases":[],"flags":{},"args":[]}}} |
{ | ||
"name": "@useoptic/cli", | ||
"description": "API automation for the modern team", | ||
"version": "2.0.4", | ||
"version": "2.1.0", | ||
"author": "@useoptic", | ||
@@ -14,5 +14,8 @@ "bin": { | ||
"@oclif/plugin-help": "^2.1.6", | ||
"@useoptic/core": "^0.1.3-alpha.13", | ||
"@useoptic/core": "file:../optic-core", | ||
"api-js-client": "file:managed/services/optic", | ||
"archy": "^1.0.0", | ||
"cli-ux": "^5.1.0", | ||
"debug": "^4.1.1", | ||
"fs-extra": "^7.0.1", | ||
"git-state": "^4.1.0", | ||
@@ -29,5 +32,7 @@ "js-yaml": "^3.12.1", | ||
"@oclif/tslint": "^3.1.1", | ||
"@types/archy": "0.0.31", | ||
"@types/chai": "^4.1.7", | ||
"@types/debug": "^4.1.1", | ||
"@types/express": "^4.16.1", | ||
"@types/fs-extra": "^5.0.5", | ||
"@types/joi": "^14.3.1", | ||
@@ -34,0 +39,0 @@ "@types/js-yaml": "^3.12.0", |
@@ -22,3 +22,3 @@ @useoptic/cli | ||
$ optic (-v|--version|version) | ||
@useoptic/cli/2.0.4 darwin-x64 node-v8.12.0 | ||
@useoptic/cli/2.1.0 darwin-x64 node-v8.12.0 | ||
$ optic --help [COMMAND] | ||
@@ -32,3 +32,5 @@ USAGE | ||
<!-- commands --> | ||
* [`optic api:add APIID APIVERSION`](#optic-apiadd-apiid-apiversion) | ||
* [`optic api:document`](#optic-apidocument) | ||
* [`optic api:install`](#optic-apiinstall) | ||
* [`optic api:publish`](#optic-apipublish) | ||
@@ -39,2 +41,20 @@ * [`optic config:check`](#optic-configcheck) | ||
## `optic api:add APIID APIVERSION` | ||
Install an Optic API and generate artifacts (Swagger/OAS, SDKs, etc.) | ||
``` | ||
USAGE | ||
$ optic api:add APIID APIVERSION | ||
ARGUMENTS | ||
APIID "team/api" or "api" | ||
APIVERSION the version of "apiId" you want to consume | ||
OPTIONS | ||
-o, --outputDirectory=outputDirectory directory to output generated artifacts (Swagger/OAS, SDKs, etc.) | ||
``` | ||
_See code: [src/commands/api/add.ts](https://github.com/opticdev/optic-cli/blob/v2.1.0/src/commands/api/add.ts)_ | ||
## `optic api:document` | ||
@@ -49,4 +69,18 @@ | ||
_See code: [src/commands/api/document.ts](https://github.com/opticdev/optic-cli/blob/v2.0.4/src/commands/api/document.ts)_ | ||
_See code: [src/commands/api/document.ts](https://github.com/opticdev/optic-cli/blob/v2.1.0/src/commands/api/document.ts)_ | ||
## `optic api:install` | ||
Generates artifacts (Swagger/OAS, SDKs, etc.) for the APIs that have been added via api:add | ||
``` | ||
USAGE | ||
$ optic api:install | ||
OPTIONS | ||
-o, --outputDirectory=outputDirectory (required) directory to output generated artifacts (Swagger/OAS, SDKs, etc.) | ||
``` | ||
_See code: [src/commands/api/install.ts](https://github.com/opticdev/optic-cli/blob/v2.1.0/src/commands/api/install.ts)_ | ||
## `optic api:publish` | ||
@@ -64,3 +98,3 @@ | ||
_See code: [src/commands/api/publish.ts](https://github.com/opticdev/optic-cli/blob/v2.0.4/src/commands/api/publish.ts)_ | ||
_See code: [src/commands/api/publish.ts](https://github.com/opticdev/optic-cli/blob/v2.1.0/src/commands/api/publish.ts)_ | ||
@@ -76,3 +110,3 @@ ## `optic config:check` | ||
_See code: [src/commands/config/check.ts](https://github.com/opticdev/optic-cli/blob/v2.0.4/src/commands/config/check.ts)_ | ||
_See code: [src/commands/config/check.ts](https://github.com/opticdev/optic-cli/blob/v2.1.0/src/commands/config/check.ts)_ | ||
@@ -88,3 +122,3 @@ ## `optic credentials:add-token` | ||
_See code: [src/commands/credentials/add-token.ts](https://github.com/opticdev/optic-cli/blob/v2.0.4/src/commands/credentials/add-token.ts)_ | ||
_See code: [src/commands/credentials/add-token.ts](https://github.com/opticdev/optic-cli/blob/v2.1.0/src/commands/credentials/add-token.ts)_ | ||
@@ -91,0 +125,0 @@ ## `optic help [COMMAND]` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29104
29
572
135
15
21
7
+ Addedarchy@^1.0.0
+ Addedfs-extra@^7.0.1
+ Addedarchy@1.0.0(transitive)
+ Addedfs-extra@7.0.1(transitive)
- Removed@useoptic/core@0.1.3-alpha.19(transitive)
- Removedaccepts@1.3.8(transitive)
- Removedarray-flatten@1.1.1(transitive)
- Removedbody-parser@1.20.3(transitive)
- Removedbytes@3.1.2(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removedcamel-case@3.0.0(transitive)
- Removedchange-case@3.1.0(transitive)
- Removedconstant-case@2.0.0(transitive)
- Removedcontent-disposition@0.5.4(transitive)
- Removedcontent-type@1.0.5(transitive)
- Removedcookie@0.3.10.7.10.7.2(transitive)
- Removedcookie-parser@1.4.7(transitive)
- Removedcookie-signature@1.0.6(transitive)
- Removeddebug@2.6.93.2.7(transitive)
- Removeddeepdash@1.9.5(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddepd@2.0.0(transitive)
- Removeddestroy@1.2.0(transitive)
- Removeddot-case@2.1.1(transitive)
- Removedee-first@1.1.1(transitive)
- Removedencodeurl@1.0.22.0.0(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes6-promise@4.2.8(transitive)
- Removedescape-html@1.0.3(transitive)
- Removedetag@1.8.1(transitive)
- Removedeventemitter3@4.0.7(transitive)
- Removedexpress@4.21.1(transitive)
- Removedexpress-http-proxy@1.6.3(transitive)
- Removedfinalhandler@1.3.1(transitive)
- Removedfollow-redirects@1.15.9(transitive)
- Removedforwarded@0.2.0(transitive)
- Removedfresh@0.5.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhash-string@1.0.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedheader-case@1.0.1(transitive)
- Removedhoek@6.1.3(transitive)
- Removedhttp-errors@1.4.02.0.0(transitive)
- Removedhttp-proxy@1.18.1(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedinherits@2.0.1(transitive)
- Removedipaddr.js@1.9.1(transitive)
- Removedis-lower-case@1.1.3(transitive)
- Removedis-upper-case@1.1.2(transitive)
- Removedisarray@0.0.1(transitive)
- Removedisemail@3.2.0(transitive)
- Removedjoi@14.3.1(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedloose-envify@1.4.0(transitive)
- Removedlower-case@1.1.4(transitive)
- Removedlower-case-first@1.0.2(transitive)
- Removedmedia-typer@0.3.0(transitive)
- Removedmerge-descriptors@1.0.3(transitive)
- Removedmethods@1.1.2(transitive)
- Removedmime@1.6.0(transitive)
- Removedms@2.0.0(transitive)
- Removednegotiator@0.6.3(transitive)
- Removedno-case@2.3.2(transitive)
- Removedobject-inspect@1.13.3(transitive)
- Removedon-finished@2.4.1(transitive)
- Removedparam-case@2.1.1(transitive)
- Removedparseurl@1.3.3(transitive)
- Removedpascal-case@2.0.1(transitive)
- Removedpath-case@2.1.1(transitive)
- Removedpath-match@1.2.4(transitive)
- Removedpath-to-regexp@0.1.101.9.03.3.0(transitive)
- Removedpluralize@7.0.0(transitive)
- Removedprop-types@15.8.1(transitive)
- Removedproxy-addr@2.0.7(transitive)
- Removedqs@6.13.0(transitive)
- Removedrange-parser@1.2.1(transitive)
- Removedraw-body@2.5.2(transitive)
- Removedreact@16.14.0(transitive)
- Removedreact-is@16.13.1(transitive)
- Removedrequires-port@1.0.0(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsend@0.19.0(transitive)
- Removedsentence-case@2.1.1(transitive)
- Removedserve-static@1.16.2(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedsetprototypeof@1.2.0(transitive)
- Removedshort-hash@1.0.0(transitive)
- Removedside-channel@1.0.6(transitive)
- Removedsnake-case@2.1.0(transitive)
- Removedstatuses@1.5.02.0.1(transitive)
- Removedswap-case@1.1.2(transitive)
- Removedtitle-case@2.1.1(transitive)
- Removedtoidentifier@1.0.1(transitive)
- Removedtopo@3.0.3(transitive)
- Removedtslib@1.9.3(transitive)
- Removedtype-is@1.6.18(transitive)
- Removedunpipe@1.0.0(transitive)
- Removedupper-case@1.1.3(transitive)
- Removedupper-case-first@1.1.2(transitive)
- Removedutils-merge@1.0.1(transitive)
- Removedvary@1.1.2(transitive)