From 695e674f62fbf2da138003e3595b8fede97c20a7 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 7 Jun 2021 09:03:17 -0600 Subject: [PATCH] fix: publish schemas --- package.json | 8 +-- schemas/env-list.json | 104 +++++++++++++++++++++++++++++++++++++++ schemas/env-open.json | 18 +++++++ src/commands/env/list.ts | 4 +- src/commands/env/open.ts | 7 ++- yarn.lock | 85 ++++++++++++++++++++++++++++---- 6 files changed, 211 insertions(+), 15 deletions(-) create mode 100644 schemas/env-list.json create mode 100644 schemas/env-open.json diff --git a/package.json b/package.json index 4e5470b2..79cc968d 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ }, "devDependencies": { "@oclif/dev-cli": "^1", - "@oclif/plugin-command-snapshot": "^2.0.0", + "@oclif/plugin-command-snapshot": "2.1.1", "@oclif/test": "^1.2.8", "@salesforce/cli-plugins-testkit": "^1.1.4", "@salesforce/dev-config": "^2.1.0", @@ -57,7 +57,8 @@ "files": [ "/lib", "/messages", - "/oclif.manifest.json" + "/oclif.manifest.json", + "/schemas" ], "homepage": "https://github.com/salesforcecli/plugin-env", "keywords": [ @@ -93,13 +94,14 @@ "format": "sf-format", "lint": "sf-lint", "postpack": "shx rm -f oclif.manifest.json", - "posttest": "yarn lint && yarn test:deprecation-policy && yarn test:command-reference", + "posttest": "yarn lint && yarn test:deprecation-policy && yarn test:json-schema && yarn test:command-reference", "prepack": "sf-prepack", "prepare": "sf-install", "pretest": "sf-compile-test", "test": "sf-test", "test:command-reference": "./bin/dev commandreference:generate --erroronwarnings", "test:deprecation-policy": "./bin/dev snapshot:compare", + "test:json-schema": "./bin/dev schema:compare", "test:nuts": "yarn build && nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 600000 --parallel", "version": "oclif-dev readme" }, diff --git a/schemas/env-list.json b/schemas/env-list.json new file mode 100644 index 00000000..9eabcf4c --- /dev/null +++ b/schemas/env-list.json @@ -0,0 +1,104 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/SfOrgs", + "definitions": { + "SfOrgs": { + "type": "array", + "items": { + "$ref": "#/definitions/SfOrg" + } + }, + "SfOrg": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/Optional%3CAnyJson%3E" + }, + "properties": { + "alias": { + "type": "string" + }, + "username": { + "type": "string" + }, + "orgId": { + "type": "string" + }, + "instanceUrl": { + "type": "string" + }, + "accessToken": { + "type": "string" + }, + "oauthMethod": { + "type": "string", + "enum": [ + "jwt", + "web", + "token", + "unknown" + ] + }, + "error": { + "type": "string" + } + } + }, + "Optional": { + "anyOf": [ + { + "$ref": "#/definitions/AnyJson" + }, + { + "not": {} + } + ], + "description": "A union type for either the parameterized type `T` or `undefined` -- the opposite of {@link NonOptional } ." + }, + "AnyJson": { + "anyOf": [ + { + "$ref": "#/definitions/JsonPrimitive" + }, + { + "$ref": "#/definitions/JsonCollection" + } + ], + "description": "Any valid JSON value." + }, + "JsonPrimitive": { + "type": [ + "null", + "boolean", + "number", + "string" + ], + "description": "Any valid JSON primitive value." + }, + "JsonCollection": { + "anyOf": [ + { + "$ref": "#/definitions/JsonMap" + }, + { + "$ref": "#/definitions/JsonArray" + } + ], + "description": "Any valid JSON collection value." + }, + "JsonMap": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/Optional%3CAnyJson%3E" + }, + "properties": {}, + "description": "Any JSON-compatible object." + }, + "JsonArray": { + "type": "array", + "items": { + "$ref": "#/definitions/AnyJson" + }, + "description": "Any JSON-compatible array." + } + } +} \ No newline at end of file diff --git a/schemas/env-open.json b/schemas/env-open.json new file mode 100644 index 00000000..7432d27e --- /dev/null +++ b/schemas/env-open.json @@ -0,0 +1,18 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/OpenResult", + "definitions": { + "OpenResult": { + "type": "object", + "properties": { + "url": { + "type": "string" + } + }, + "required": [ + "url" + ], + "additionalProperties": false + } + } +} \ No newline at end of file diff --git a/src/commands/env/list.ts b/src/commands/env/list.ts index c16d26cf..69eb5898 100644 --- a/src/commands/env/list.ts +++ b/src/commands/env/list.ts @@ -15,6 +15,8 @@ import { AuthInfo, SfOrg, SfdxError } from '@salesforce/core'; // Messages.importMessagesDirectory(__dirname); // const messages = Messages.loadMessages('@salesforce/plugin-env', 'list'); +export type SfOrgs = SfOrg[]; + export default class EnvList extends Command { // TODO: add back once md messages are supported // public static readonly description = messages.getMessage('description'); @@ -33,7 +35,7 @@ export default class EnvList extends Command { all: boolean; }; - public async run(): Promise { + public async run(): Promise { this.flags = this.parse(EnvList).flags; let authorizations: SfOrg[]; diff --git a/src/commands/env/open.ts b/src/commands/env/open.ts index d1565169..cf275f39 100644 --- a/src/commands/env/open.ts +++ b/src/commands/env/open.ts @@ -18,6 +18,8 @@ const messages = Messages.loadMessages('@salesforce/plugin-env', 'open'); type Environment = { name: string; openUrl: string }; +export type OpenResult = { url: string }; + export default class EnvOpen extends Command { // Use summary and description until a summary is supported in oclif public static readonly description = messages.getMessage('description') + EOL + messages.getMessage('description'); @@ -41,10 +43,10 @@ export default class EnvOpen extends Command { }), }; - public async run(): Promise { + public async run(): Promise { const { flags } = await this.parse(EnvOpen); const nameOrAlias = flags['target-env']; - let url; + let url: string; if (!nameOrAlias) { // TODO this should be retrieved from sf config once we have those commands. If not found, still throw. @@ -94,6 +96,7 @@ export default class EnvOpen extends Command { } else { throw messages.createError('error.EnvironmentNotSupported', [nameOrAlias]); } + return { url }; } // TODO login and env open should probably share the same open code. Maybe we should use cli-ux.open? diff --git a/yarn.lock b/yarn.lock index 0e9f8144..a84b2068 100644 --- a/yarn.lock +++ b/yarn.lock @@ -447,15 +447,18 @@ chalk "^2.4.2" tslib "^1.9.3" -"@oclif/plugin-command-snapshot@^2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@oclif/plugin-command-snapshot/-/plugin-command-snapshot-2.0.0.tgz#61ee06fc191a34d096024a49fdae0026c88095dc" - integrity sha512-DfEydDlic4TUY4MpgP1UGrRpdAzJZGH2RN0CxEkJ9mM4Z+q61YBjR56IVW2m4mz26DpOHAn7l6luA2WvRVHXXA== +"@oclif/plugin-command-snapshot@2.1.1": + version "2.1.1" + resolved "https://registry.npmjs.org/@oclif/plugin-command-snapshot/-/plugin-command-snapshot-2.1.1.tgz#ae35ff08f6e8ed535b63c9e8b5ef7454b37a3e99" + integrity sha512-Q59YH9H8q6Zd5ODnxNQYEbPa1NF9XHti32t41h07e+LxiIlV569GzvdHElEaMoQc346sZ1VssPQaDneuwkCTCQ== dependencies: "@oclif/command" "^1.6.0" "@oclif/config" "^1" - chalk "^4.0.0" - sinon "^9.0.0" + chalk "^4.1.1" + just-diff "^3.1.1" + semver "^7.3.5" + sinon "^10.0.0" + ts-json-schema-generator "^0.93.0" tslib "^2" "@oclif/plugin-help@^2.2.0": @@ -787,6 +790,11 @@ resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.6.tgz#f4c7ec43e81b319a9815115031709f26987891f0" integrity sha512-3c+yGKvVP5Y9TYBEibGNR+kLtijnj7mYrXRg+WpFb2X9xm04g/DXYkfg4hmzJQosc9snFNUPkbYIhu+KAm6jJw== +"@types/json-schema@^7.0.7": + version "7.0.7" + resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad" + integrity sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA== + "@types/json5@^0.0.29": version "0.0.29" resolved "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee" @@ -1461,6 +1469,14 @@ chalk@^3.0.0: ansi-styles "^4.1.0" supports-color "^7.1.0" +chalk@^4.1.1: + version "4.1.1" + resolved "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz#c80b3fab28bf6371e6863325eee67e618b77e6ad" + integrity sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + chardet@^0.7.0: version "0.7.0" resolved "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e" @@ -1733,6 +1749,11 @@ commander@^6.2.0: resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.1.tgz#0792eb682dfbc325999bb2b84fddddba110ac73c" integrity sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA== +commander@^7.2.0: + version "7.2.0" + resolved "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7" + integrity sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw== + comment-parser@^0.7.5: version "0.7.6" resolved "https://registry.npmjs.org/comment-parser/-/comment-parser-0.7.6.tgz#0e743a53c8e646c899a1323db31f6cd337b10f12" @@ -2641,7 +2662,7 @@ fast-glob@^3.0.3, fast-glob@^3.1.1: micromatch "^4.0.2" picomatch "^2.2.1" -fast-json-stable-stringify@^2.0.0: +fast-json-stable-stringify@^2.0.0, fast-json-stable-stringify@^2.1.0: version "2.1.0" resolved "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633" integrity sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw== @@ -3043,6 +3064,18 @@ glob@^6.0.1: once "^1.3.0" path-is-absolute "^1.0.0" +glob@^7.1.7: + version "7.1.7" + resolved "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz#3b193e9233f01d42d0b3f78294bbeeb418f94a90" + integrity sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.4" + once "^1.3.0" + path-is-absolute "^1.0.0" + global-dirs@^0.1.1: version "0.1.1" resolved "https://registry.npmjs.org/global-dirs/-/global-dirs-0.1.1.tgz#b319c0dd4607f353f3be9cca4c72fc148c49f445" @@ -3821,6 +3854,13 @@ json-stable-stringify-without-jsonify@^1.0.1: resolved "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651" integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE= +json-stable-stringify@^1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz#9a759d39c5f2ff503fd5300646ed445f88c4f9af" + integrity sha1-mnWdOcXy/1A/1TAGRu1EX4jE+a8= + dependencies: + jsonify "~0.0.0" + json-stringify-safe@~5.0.1: version "5.0.1" resolved "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb" @@ -3856,6 +3896,11 @@ jsonfile@^6.0.1: optionalDependencies: graceful-fs "^4.1.6" +jsonify@~0.0.0: + version "0.0.0" + resolved "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73" + integrity sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM= + jsonparse@^1.2.0: version "1.3.1" resolved "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz#3f4dae4a91fac315f71062f8521cc239f1366280" @@ -3887,6 +3932,11 @@ jsprim@^1.2.2: json-schema "0.2.3" verror "1.10.0" +just-diff@^3.1.1: + version "3.1.1" + resolved "https://registry.npmjs.org/just-diff/-/just-diff-3.1.1.tgz#d50c597c6fd4776495308c63bdee1b6839082647" + integrity sha512-sdMWKjRq8qWZEjDcVA6llnUT8RDEBIfOiGpYFPYa9u+2c39JCsejktSP7mj5eRid5EIvTzIpQ2kDOCw1Nq9BjQ== + just-extend@^4.0.2: version "4.1.0" resolved "https://registry.npmjs.org/just-extend/-/just-extend-4.1.0.tgz#7278a4027d889601640ee0ce0e5a00b992467da4" @@ -5541,7 +5591,7 @@ semver@^6.0.0, semver@^6.1.2, semver@^6.3.0: resolved "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== -semver@^7.1.1, semver@^7.3.2: +semver@^7.1.1, semver@^7.3.2, semver@^7.3.5: version "7.3.5" resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7" integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ== @@ -5657,7 +5707,7 @@ sinon@^10.0.0: nise "^4.1.0" supports-color "^7.1.0" -sinon@^9.0.0, sinon@^9.0.2: +sinon@^9.0.2: version "9.2.4" resolved "https://registry.yarnpkg.com/sinon/-/sinon-9.2.4.tgz#e55af4d3b174a4443a8762fa8421c2976683752b" integrity sha512-zljcULZQsJxVra28qIAL6ow1Z9tpattkCTEJR4RBP3TGc00FcttsP5pK284Nas5WjMZU5Yzy3kAIp3B3KRf5Yg== @@ -6217,6 +6267,18 @@ trim-off-newlines@^1.0.0: resolved "https://registry.npmjs.org/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz#9f9ba9d9efa8764c387698bcbfeb2c848f11adb3" integrity sha1-n5up2e+odkw4dpi8v+sshI8RrbM= +ts-json-schema-generator@^0.93.0: + version "0.93.0" + resolved "https://registry.npmjs.org/ts-json-schema-generator/-/ts-json-schema-generator-0.93.0.tgz#3d6adf99446a1b3d0887dbad7cca015a49394d3a" + integrity sha512-JYacSIgw4KqsOXF/zRSY4pE/v6jUk7aMDXhwK5MdopN0UeKH58TRZHrQADy9uxTf78jqUfFLzARQKNOb9H+jVQ== + dependencies: + "@types/json-schema" "^7.0.7" + commander "^7.2.0" + fast-json-stable-stringify "^2.1.0" + glob "^7.1.7" + json-stable-stringify "^1.0.1" + typescript "~4.3.2" + ts-node@^8.10.2: version "8.10.2" resolved "https://registry.npmjs.org/ts-node/-/ts-node-8.10.2.tgz#eee03764633b1234ddd37f8db9ec10b75ec7fb8d" @@ -6342,6 +6404,11 @@ typescript@^4.1.3: resolved "https://registry.npmjs.org/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7" integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg== +typescript@~4.3.2: + version "4.3.2" + resolved "https://registry.npmjs.org/typescript/-/typescript-4.3.2.tgz#399ab18aac45802d6f2498de5054fcbbe716a805" + integrity sha512-zZ4hShnmnoVnAHpVHWpTcxdv7dWP60S2FsydQLV8V5PbS3FifjWFFRiHSWpDJahly88PRyV5teTSLoq4eG7mKw== + uglify-js@^3.1.4: version "3.10.1" resolved "https://registry.npmjs.org/uglify-js/-/uglify-js-3.10.1.tgz#dd14767eb7150de97f2573a5ff210db14fffe4ad"