From d8e2167125d9ca9c5d0609ab538dae0af100e246 Mon Sep 17 00:00:00 2001 From: Mircea Nistor Date: Thu, 22 Feb 2024 18:31:01 +0100 Subject: [PATCH] fix(cli): remove interactive prompting on CLI execute command (#1347) using Debug instead of `console.log` for logging, so that the console can be used for stdout. fixes #1281 --- package.json | 1 - packages/cli/package.json | 1 - packages/cli/src/execute.ts | 70 +++---------------- .../src/imported-types/imported-modules.d.ts | 1 - packages/credential-w3c/src/action-handler.ts | 6 +- pnpm-lock.yaml | 37 +--------- 6 files changed, 15 insertions(+), 101 deletions(-) diff --git a/package.json b/package.json index e9574dff4f..af02d683eb 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,6 @@ "json-schema": "0.4.0", "lerna": "7.3.0", "lerna-changelog": "2.2.0", - "oas-resolver": "2.5.6", "openapi-types": "12.1.3", "prettier": "3.0.2", "rimraf": "5.0.1", diff --git a/packages/cli/package.json b/packages/cli/package.json index ca59b32b76..60aaff4ddd 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -84,7 +84,6 @@ "json-schema": "^0.4.0", "json5": "^2.2.3", "jsonpointer": "^5.0.1", - "oas-resolver": "^2.5.6", "openapi-types": "^12.1.3", "passport": "^0.6.0", "passport-http-bearer": "^1.0.1", diff --git a/packages/cli/src/execute.ts b/packages/cli/src/execute.ts index 1c63fa7d81..11e50e249c 100644 --- a/packages/cli/src/execute.ts +++ b/packages/cli/src/execute.ts @@ -2,8 +2,10 @@ import { Command } from 'commander' import inquirer from 'inquirer' import { getAgent } from './setup.js' import fs from 'fs' -import OasResolver from 'oas-resolver' import fuzzy from 'fuzzy' +import Debug from 'debug' + +const debug = Debug('veramo:cli:execute') const execute = new Command('execute') .description('Execute agent method') @@ -19,8 +21,6 @@ const execute = new Command('execute') let argsFile = options.argsFile let argsObj - const { openapi } = await OasResolver.resolve(agent.getSchema(), null, { resolveInternal: true }) - if (!method) { const answers = await inquirer.prompt({ // @ts-ignore @@ -38,78 +38,30 @@ const execute = new Command('execute') }) method = answers.method } - const methodApi = openapi.components.methods[method] if (!argsString && !argsFile) { - // parse schema, generate options - - const questions = [] - // console.log(methodApi.arguments.type) - if (methodApi.arguments.type === 'object') { - for (const property in methodApi.arguments.properties) { - const propertySchema = methodApi.arguments.properties[property] - // console.log({property, propertySchema}) - let question: any = { - name: property, - message: property + ' - ' + propertySchema.description, - } - - // TODO handle anyOf - switch (propertySchema.type) { - case 'object': - question.type = 'input' - question.filter = (input: string) => JSON.parse(input === '' ? '{}' : input) - question.transformer = (input: object) => JSON.stringify(input) - break - case 'string': - question.type = 'input' - break - case 'number': - question.type = 'number' - break - case 'boolean': - question.type = 'confirm' - break - // TODO - case 'array': - default: - console.log(`Method argument type ${propertySchema.type} not supported yet`) - process.exit(1) - } - - if (question.type) { - if (propertySchema.enum) { - question.type = 'list' - question.choices = propertySchema.enum - } - questions.push(question) - } - } - } - - argsObj = await inquirer.prompt(questions) + console.error(`No arguments provided for execute method=${method}`) + process.exit(1) } else { + debug(`Attempting to extract method arguments from file (${argsFile})`) if (argsFile) { - console.log({ argsFile }) argsString = fs.readFileSync(argsFile).toString('utf-8') } try { argsObj = JSON.parse(argsString!) } catch (e: any) { console.error('could not parse arguments JSON') + process.exit(1) } } - console.log('\nMethod: ', method) - console.log('\nArguments: ', JSON.stringify(argsObj, null, 2)) + debug('\nMethod: ', method) + debug('\nArguments: ', JSON.stringify(argsObj, null, 2)) const result = await agent.execute(method, argsObj) - console.log( - '\nResult', - methodApi.returnType.description ? `(${methodApi.returnType.description}):` : ':', - JSON.stringify(result, null, 2), - ) + debug('\nResult: ', JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result)) } catch (e: any) { console.error(e.message) } diff --git a/packages/cli/src/imported-types/imported-modules.d.ts b/packages/cli/src/imported-types/imported-modules.d.ts index d7cd60f853..f8d9f8e479 100644 --- a/packages/cli/src/imported-types/imported-modules.d.ts +++ b/packages/cli/src/imported-types/imported-modules.d.ts @@ -1,2 +1 @@ declare module 'cors' -declare module 'oas-resolver' diff --git a/packages/credential-w3c/src/action-handler.ts b/packages/credential-w3c/src/action-handler.ts index acf20ada43..dee7c2c2ac 100644 --- a/packages/credential-w3c/src/action-handler.ts +++ b/packages/credential-w3c/src/action-handler.ts @@ -497,10 +497,10 @@ export class CredentialPlugin implements IAgentPlugin { /** * Checks if a key is suitable for signing JWT payloads. - * @param key - * @param context + * @param key - the key to check for support + * @param context - This reserved param is automatically added and handled by the framework, *do not override* * - * @internal + * @beta */ async matchKeyForJWT(key: IKey, context: IssuerAgentContext): Promise { switch (key.type) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8a802a46fa..84efb40998 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -105,9 +105,6 @@ importers: lerna-changelog: specifier: 2.2.0 version: 2.2.0 - oas-resolver: - specifier: 2.5.6 - version: 2.5.6 openapi-types: specifier: 12.1.3 version: 12.1.3 @@ -300,9 +297,6 @@ importers: jsonpointer: specifier: ^5.0.1 version: 5.0.1 - oas-resolver: - specifier: ^2.5.6 - version: 2.5.6 openapi-types: specifier: ^12.1.3 version: 12.1.3 @@ -16383,9 +16377,6 @@ packages: resolution: {integrity: sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==} dev: true - /fast-safe-stringify@2.1.1: - resolution: {integrity: sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==} - /fast-text-encoding@1.0.6: resolution: {integrity: sha512-VhXlQgj9ioXCqGstD37E/HBeqEGV/qOD/kmbVG8h5xKBYvM1L3lR1Zn4555cQ8GkYbJa8aJSipLPndE1k6zK2w==} dev: false @@ -17724,9 +17715,6 @@ packages: - debug dev: true - /http2-client@1.3.5: - resolution: {integrity: sha512-EC2utToWl4RKfs5zd36Mxq7nzHHBuomZboI0yYL6Y0RmBgT7Sgkq4rQ0ezFTYoIsSs7Tm9SJe+o2FcAg6GBhGA==} - /https-proxy-agent@5.0.1: resolution: {integrity: sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==} engines: {node: '>= 6'} @@ -21576,12 +21564,6 @@ packages: lodash: 4.17.21 dev: true - /node-fetch-h2@2.3.0: - resolution: {integrity: sha512-ofRW94Ab0T4AOh5Fk8t0h8OBWrmjb0SSB20xh1H8YnPV9EJ+f5AMoYSUQ2zgJ4Iq2HAK0I2l5/Nequ8YzFS3Hg==} - engines: {node: 4.x || >=6.0.0} - dependencies: - http2-client: 1.3.5 - /node-fetch@2.6.12: resolution: {integrity: sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==} engines: {node: 4.x || >=6.0.0} @@ -22074,21 +22056,6 @@ packages: - debug dev: true - /oas-kit-common@1.0.8: - resolution: {integrity: sha512-pJTS2+T0oGIwgjGpw7sIRU8RQMcUoKCDWFLdBqKB2BNmGpbBMH2sdqAaOXUg8OzonZHU0L7vfJu1mJFEiYDWOQ==} - dependencies: - fast-safe-stringify: 2.1.1 - - /oas-resolver@2.5.6: - resolution: {integrity: sha512-Yx5PWQNZomfEhPPOphFbZKi9W93CocQj18NlD2Pa4GWZzdZpSJvYwoiuurRI7m3SpcChrnO08hkuQDL3FGsVFQ==} - hasBin: true - dependencies: - node-fetch-h2: 2.3.0 - oas-kit-common: 1.0.8 - reftools: 1.1.9 - yaml: 1.10.2 - yargs: 17.7.2 - /ob1@0.80.1: resolution: {integrity: sha512-o9eYflOo+QnbC/k9GYQuAy90zOGQ/OBgrjlIeW6VrKhevSxth83JSdEvKuKaV7SMGJVQhSY3Zp8eGa3g0rLP0A==} engines: {node: '>=18'} @@ -24552,9 +24519,6 @@ packages: /reflect-metadata@0.1.13: resolution: {integrity: sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==} - /reftools@1.1.9: - resolution: {integrity: sha512-OVede/NQE13xBQ+ob5CKd5KyeJYU2YInb1bmV4nRoOfquZPkAkxuOXicSe1PvqIuZZ4kD13sPKBbR7UFDmli6w==} - /regenerate-unicode-properties@10.1.0: resolution: {integrity: sha512-d1VudCLoIGitcU/hEg2QqvyGZQmdC0Lf8BqdOMXGFSvJP4bNV1+XqbPQeHHLD51Jh4QJJ225dlIFvY4Ly6MXmQ==} engines: {node: '>=4'} @@ -28007,6 +27971,7 @@ packages: /yaml@1.10.2: resolution: {integrity: sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==} engines: {node: '>= 6'} + dev: true /yaml@2.3.1: resolution: {integrity: sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==}