Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@useoptic/cli

Package Overview
Dependencies
Maintainers
2
Versions
217
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@useoptic/cli - npm Package Compare versions

Comparing version 2.0.4 to 2.1.0

lib/commands/api/add.d.ts

20

lib/commands/api/document.js

@@ -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]`

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc