diff --git a/package.json b/package.json index 56b32a30..9f92de66 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,7 @@ "fetch-repo-dir": "^1.0.6", "fs-extra": "^11.2.0", "git-url-parse": "^14.0.0", - "got": "^14.0.0", + "got": "^12.0.0", "graphql": "^16.8.1", "graphql-request": "^6.1.0", "graphql-tag": "^2.12.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c6e5d19f..c7d6b567 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -60,8 +60,8 @@ dependencies: specifier: ^14.0.0 version: 14.0.0 got: - specifier: ^14.0.0 - version: 14.0.0 + specifier: ^12.0.0 + version: 12.6.1 graphql: specifier: ^16.8.1 version: 16.8.1 @@ -2347,12 +2347,6 @@ packages: /@sindresorhus/is@5.6.0: resolution: {integrity: sha512-TV7t8GKYaJWsn00tFDqBw8+Uqmr8A0fRU1tvTQhyZzGv0sJCGRQL3JGMI3ucuKo3XIZdUP+Lx7/gh2t3lewy7g==} engines: {node: '>=14.16'} - dev: true - - /@sindresorhus/is@6.1.0: - resolution: {integrity: sha512-BuvU07zq3tQ/2SIgBsEuxKYDyDjC0n7Zir52bpHy2xnBbW81+po43aLFPLbeV3HRAheFbGud1qgcqSYfhtHMAg==} - engines: {node: '>=16'} - dev: false /@sindresorhus/merge-streams@1.0.0: resolution: {integrity: sha512-rUV5WyJrJLoloD4NDN1V1+LDMDWOa4OTsT4yYJwQNpTU6FWxkxHpL7eu4w+DmiH8x/EAM1otkPE1+LaspIbplw==} @@ -3267,19 +3261,6 @@ packages: resolution: {integrity: sha512-+qJyx4xiKra8mZrcwhjMRMUhD5NR1R8esPkzIYxX96JiecFoxAXFuz/GpR3+ev4PE1WamHip78wV0vcmPQtp8w==} engines: {node: '>=14.16'} - /cacheable-request@10.2.13: - resolution: {integrity: sha512-3SD4rrMu1msNGEtNSt8Od6enwdo//U9s4ykmXfA2TD58kcLkCobtCDiby7kNyj7a/Q7lz/mAesAFI54rTdnvBA==} - engines: {node: '>=14.16'} - dependencies: - '@types/http-cache-semantics': 4.0.2 - get-stream: 6.0.1 - http-cache-semantics: 4.1.1 - keyv: 4.5.3 - mimic-response: 4.0.0 - normalize-url: 8.0.0 - responselike: 3.0.0 - dev: true - /cacheable-request@10.2.14: resolution: {integrity: sha512-zkDT5WAF4hSSoUgyfg5tFIxz8XQK+25W/TLVojJTMKBaxevLBBtLxgqguAuVQB8PVW79FVjHcU+GJ9tVbDZ9mQ==} engines: {node: '>=14.16'} @@ -3291,7 +3272,6 @@ packages: mimic-response: 4.0.0 normalize-url: 8.0.0 responselike: 3.0.0 - dev: false /call-bind@1.0.2: resolution: {integrity: sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==} @@ -4954,12 +4934,6 @@ packages: /form-data-encoder@2.1.4: resolution: {integrity: sha512-yDYSgNMraqvnxiEXO4hi88+YZxaHC6QKzb5N84iRCTDeRO7ZALpir/lVmf/uXUhnwUr2O4HU8s/n6x+yNjQkHw==} engines: {node: '>= 14.17'} - dev: true - - /form-data-encoder@4.0.2: - resolution: {integrity: sha512-KQVhvhK8ZkWzxKxOr56CPulAhH3dobtuQ4+hNQ+HekH/Wp5gSOafqRAeTphQUJAIk0GBvHZgJ2ZGRWd5kphMuw==} - engines: {node: '>= 18'} - dev: false /formdata-polyfill@4.0.10: resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==} @@ -5092,6 +5066,7 @@ packages: /get-stream@8.0.1: resolution: {integrity: sha512-VaUJspBffn/LMCJVoMvSAdmscJyS1auj5Zulnn5UoYcY531UWmdwhRWkcGKnGU93m5HSXP9LP2usOryrBtQowA==} engines: {node: '>=16'} + dev: true /get-symbol-description@1.0.0: resolution: {integrity: sha512-2EmdH1YvIQiZpltCNgkuiUnyukzxM/R6NDJX31Ke3BG1Nq5b0S2PhX59UKi9vZpPDQVdqn+1IcaAwnzTT5vCjw==} @@ -5230,15 +5205,14 @@ packages: '@sindresorhus/is': 5.6.0 '@szmarczak/http-timer': 5.0.1 cacheable-lookup: 7.0.0 - cacheable-request: 10.2.13 + cacheable-request: 10.2.14 decompress-response: 6.0.0 form-data-encoder: 2.1.4 get-stream: 6.0.1 - http2-wrapper: 2.2.0 + http2-wrapper: 2.2.1 lowercase-keys: 3.0.0 p-cancelable: 3.0.0 responselike: 3.0.0 - dev: true /got@13.0.0: resolution: {integrity: sha512-XfBk1CxOOScDcMr9O1yKkNaQyy865NbYs+F7dr4H0LZMVgCj2Le59k6PqbNHoL5ToeaEQUYh6c6yMfVcc6SJxA==} @@ -5247,33 +5221,16 @@ packages: '@sindresorhus/is': 5.6.0 '@szmarczak/http-timer': 5.0.1 cacheable-lookup: 7.0.0 - cacheable-request: 10.2.13 + cacheable-request: 10.2.14 decompress-response: 6.0.0 form-data-encoder: 2.1.4 get-stream: 6.0.1 - http2-wrapper: 2.2.0 + http2-wrapper: 2.2.1 lowercase-keys: 3.0.0 p-cancelable: 3.0.0 responselike: 3.0.0 dev: true - /got@14.0.0: - resolution: {integrity: sha512-X01vTgaX9SwaMq5DfImvS+3GMQFFs5HtrrlS9CuzUSzkxAf/tWGEyynuI+Qy7BjciMczZGjyVSmawYbP4eYhYA==} - engines: {node: '>=20'} - dependencies: - '@sindresorhus/is': 6.1.0 - '@szmarczak/http-timer': 5.0.1 - cacheable-lookup: 7.0.0 - cacheable-request: 10.2.14 - decompress-response: 6.0.0 - form-data-encoder: 4.0.2 - get-stream: 8.0.1 - http2-wrapper: 2.2.1 - lowercase-keys: 3.0.0 - p-cancelable: 4.0.1 - responselike: 3.0.0 - dev: false - /graceful-fs@4.2.10: resolution: {integrity: sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==} dev: true @@ -5458,21 +5415,12 @@ packages: - debug dev: true - /http2-wrapper@2.2.0: - resolution: {integrity: sha512-kZB0wxMo0sh1PehyjJUWRFEd99KC5TLjZ2cULC4f9iqJBAmKQQXEICjxl5iPJRwP40dpeHFqqhm7tYCvODpqpQ==} - engines: {node: '>=10.19.0'} - dependencies: - quick-lru: 5.1.1 - resolve-alpn: 1.2.1 - dev: true - /http2-wrapper@2.2.1: resolution: {integrity: sha512-V5nVw1PAOgfI3Lmeaj2Exmeg7fenjhRUgz1lPSezy1CuhPYbgQtbQj4jZfEAEMlaL+vupsvhjqCyjzob0yxsmQ==} engines: {node: '>=10.19.0'} dependencies: quick-lru: 5.1.1 resolve-alpn: 1.2.1 - dev: false /https-proxy-agent@5.0.1: resolution: {integrity: sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==} @@ -6964,12 +6912,6 @@ packages: /p-cancelable@3.0.0: resolution: {integrity: sha512-mlVgR3PGuzlo0MmTdk4cXqXWlwQDLnONTAg6sm62XkMJEiRxN3GL3SffkYvqwonbkJBcrI7Uvv5Zh9yjvn2iUw==} engines: {node: '>=12.20'} - dev: true - - /p-cancelable@4.0.1: - resolution: {integrity: sha512-wBowNApzd45EIKdO1LaU+LrMBwAcjfPaYtVzV3lmfM3gf8Z4CHZsiIqlM8TZZ8okYvh5A1cP6gTfCRQtwUpaUg==} - engines: {node: '>=14.16'} - dev: false /p-is-promise@3.0.0: resolution: {integrity: sha512-Wo8VsW4IRQSKVXsJCn7TomUaVtyfjVDn3nUP7kE967BQk0CwFpdbZs0X0uk5sW9mkBa9eNM7hCMaG93WUAwxYQ==} diff --git a/src/cli/configure.ts b/src/cli/configure.ts index d1e9df4c..8ff6d710 100644 --- a/src/cli/configure.ts +++ b/src/cli/configure.ts @@ -29,7 +29,7 @@ export const builder: CommandBuilder = (_) => desc: 'skip additional prompts', }); -export const handler = async (argv: Arguments) => { +export const handler = async (argv: Arguments) => { debug('command arguments: %O', obfuscateArgv(argv)); const { token, force } = argv; diff --git a/src/cli/dev/prepare.ts b/src/cli/dev/prepare.ts index 81e80a9b..80b68caa 100644 --- a/src/cli/dev/prepare.ts +++ b/src/cli/dev/prepare.ts @@ -9,16 +9,12 @@ import { Config } from '../../lib/config.js'; import { GitError, obfuscateArgv, printlnSuccess } from '../../lib/util.js'; import { useGithub } from '../../middleware/index.js'; -interface Options { - branch?: string; -} - const debug = Debug('saleor-cli:dev:prepare'); export const command = 'prepare [branch|prURL]'; export const desc = 'Build cli from branch or pull request URL'; -export const handler = async (argv: Arguments) => { +export const handler = async (argv: Arguments) => { debug('command arguments: %O', obfuscateArgv(argv)); const git = simpleGit(); diff --git a/src/cli/env/cors.ts b/src/cli/env/cors.ts index 64581c76..d31724f7 100644 --- a/src/cli/env/cors.ts +++ b/src/cli/env/cors.ts @@ -95,42 +95,39 @@ export const handler = async (argv: Arguments) => { } // First form to check current - const { kind } = await Enquirer.prompt<{ - kind: string; - }>([ - { - type: 'select', - name: 'kind', - message: 'Choose allowed API origins ', - choices: [ - { - message: 'Allow all origins', - name: 'all', - }, - { - message: 'Selected Origins', - name: 'selected', - }, - { - message: 'Dashboard only', - name: 'dashboard', - }, - ], - initial: () => { - if (allowedCorsOrigins === '*') { - return 1; - } - if (allowedCorsOrigins == null) { - return 2; - } - if (Array.isArray(allowedCorsOrigins)) { - return 3; - } - - return 1; + const kindPrompt = new (Enquirer as any).Select({ + name: 'kind', + message: 'Choose allowed API origins ', + choices: [ + { + message: 'Allow all origins', + name: 'all', }, + { + message: 'Selected Origins', + name: 'selected', + }, + { + message: 'Dashboard only', + name: 'dashboard', + }, + ], + initial: () => { + if (allowedCorsOrigins === '*') { + return 1; + } + if (allowedCorsOrigins == null) { + return 2; + } + if (Array.isArray(allowedCorsOrigins)) { + return 3; + } + + return 1; }, - ]); + }); + + const kind = (await kindPrompt.run()) as string; // Trigger an update for all and dashboard if (['all', 'dashboard'].includes(kind)) { @@ -153,18 +150,15 @@ export const handler = async (argv: Arguments) => { const addNewMsg = 'Add a new CORS origin'; - const { origins } = await Enquirer.prompt<{ - origins: string; - }>([ - { - type: 'multiselect', - name: 'origins', - message: - 'Define Selected Origins\n (use the arrows to navigate and the space bar to select)', - choices: [...selected, addNewMsg], - initial: selected, - }, - ]); + const originsPrompt = new (Enquirer as any).MultiSelect({ + name: 'origins', + message: + 'Define Trusted Origins\n (use the arrows to navigate and the space bar to select)', + choices: [...selected, addNewMsg], + initial: selected, + }); + + const origins = (await originsPrompt.run()) as string; do { if (origins.length === 0) { diff --git a/src/cli/env/create.ts b/src/cli/env/create.ts index 753a401c..3a7fdce6 100644 --- a/src/cli/env/create.ts +++ b/src/cli/env/create.ts @@ -29,7 +29,7 @@ interface CommandOptions extends Options { pass?: string; restore: boolean; restoreFrom: string; - skipWebhooksUpdate: boolean; + skipWebhooksUpdate?: boolean; skipRestrict: boolean; } diff --git a/src/cli/env/origins.ts b/src/cli/env/origins.ts index 13357108..ea73fdff 100644 --- a/src/cli/env/origins.ts +++ b/src/cli/env/origins.ts @@ -53,18 +53,15 @@ export const handler = async (argv: Arguments) => { const selected: string[] = (allowedClientOrigins as string[]) || []; let addMore = true; - const { origins } = await Enquirer.prompt<{ - origins: string; - }>([ - { - type: 'multiselect', - name: 'origins', - message: - 'Define Trusted Origins\n (use the arrows to navigate and the space bar to select)', - choices: [...selected, 'Add a new trusted origin'], - initial: selected, - }, - ]); + const originsPrompt = new (Enquirer as any).MultiSelect({ + name: 'origins', + message: + 'Define Trusted Origins\n (use the arrows to navigate and the space bar to select)', + choices: [...selected, 'Add a new trusted origin'], + initial: selected, + }); + + const origins = (await originsPrompt.run()) as string; do { if (origins.length === 0) { diff --git a/src/cli/info.ts b/src/cli/info.ts index 4385b936..09044154 100644 --- a/src/cli/info.ts +++ b/src/cli/info.ts @@ -8,7 +8,7 @@ import type { CommandBuilder } from 'yargs'; import { Config } from '../lib/config.js'; import { header } from '../lib/images.js'; import { API, GET, getEnvironment } from '../lib/index.js'; -import { User } from '../types.js'; +import { Options, User } from '../types.js'; const require = createRequire(import.meta.url); const pkg = require('../package.json'); diff --git a/src/cli/login.ts b/src/cli/login.ts index 09a5b199..161c0b06 100644 --- a/src/cli/login.ts +++ b/src/cli/login.ts @@ -24,7 +24,7 @@ import { println, successPage, } from '../lib/util.js'; -import { BaseOptions } from '../types.js'; +import { Options } from '../types.js'; const environment = await getEnvironment(); const RedirectURI = `http://127.0.0.1:${SaleorCLIPort}/`; @@ -49,7 +49,7 @@ export const builder: CommandBuilder = (_) => .example('saleor login --headless', '') .example('saleor login --headless --token=TOKEN', ''); -export const handler = async (argv: Arguments) => { +export const handler = async (argv: Arguments) => { if (argv.headless) { const { ux: cli } = CliUx; let { token } = argv; @@ -155,7 +155,7 @@ export const doLogin = async () => { const { token }: any = await POST(API.Token, { token: `Bearer ${idToken}`, - }); + } as Options); await createConfig(token, secrets); } catch (error) { diff --git a/src/cli/open.ts b/src/cli/open.ts index 0721ee6e..692c11ab 100644 --- a/src/cli/open.ts +++ b/src/cli/open.ts @@ -3,14 +3,13 @@ import { Arguments, CommandBuilder } from 'yargs'; import { openURL } from '../lib/util.js'; import { useInstanceConnector } from '../middleware/index.js'; -import { Options } from '../types.js'; export const command = 'open [resource]'; export const desc = 'Open resource in a browser'; const resources: Record = { - dashboard: '/dashboard', - api: '/graphql/', + dashboard: 'dashboard', + api: 'graphql/', docs: 'https://docs.saleor.io/docs/3.x/', 'docs/api': 'https://docs.saleor.io/docs/3.x/developer', 'docs/apps': @@ -31,7 +30,7 @@ export const builder: CommandBuilder = (_) => .example('saleor open api', 'Open instance GraphQL endpoint') .example('saleor open docs', 'Open Saleor documentation page'); -export const handler = async (argv: Arguments) => { +export const handler = async (argv: Arguments) => { const choices = Object.keys(resources); const { resource } = await Enquirer.prompt<{ resource: string }>({ @@ -53,7 +52,7 @@ export const handler = async (argv: Arguments) => { await openURL(path); }; -const getURL = async (path: string, argv: Arguments) => { +const getURL = async (path: string, argv: Arguments) => { const _argv = await useInstanceConnector(argv); const { instance } = _argv; return `${instance}${path}`; diff --git a/src/cli/register.ts b/src/cli/register.ts index defbaaea..1b11e29e 100644 --- a/src/cli/register.ts +++ b/src/cli/register.ts @@ -17,7 +17,7 @@ export const builder: CommandBuilder = (_) => desc: 'specify sign up via CLI', }); -export const handler = async (argv: Arguments) => { +export const handler = async (argv: Arguments) => { debug('command arguments: %O', obfuscateArgv(argv)); const link = 'https://cloud.saleor.io/signup'; diff --git a/src/cli/trigger.ts b/src/cli/trigger.ts index 3fa541e2..19712687 100644 --- a/src/cli/trigger.ts +++ b/src/cli/trigger.ts @@ -9,7 +9,6 @@ import { Config } from '../lib/config.js'; import { DefaultSaleorEndpoint } from '../lib/index.js'; import { capitalize, obfuscateArgv, SaleorEventError } from '../lib/util.js'; import { useAppConfig, useInstanceConnector } from '../middleware/index.js'; -import { Options } from '../types.js'; const debug = Debug('saleor-cli:trigger'); @@ -19,7 +18,7 @@ export const desc = 'This triggers a Saleor event'; export const builder: CommandBuilder = (_) => _.option('event', { type: 'string' }).option('id', { type: 'string' }); -export const handler = async (argv: Arguments) => { +export const handler = async (argv: Arguments) => { debug('command arguments: %O', obfuscateArgv(argv)); const { id, instance } = argv; @@ -90,8 +89,6 @@ export const handler = async (argv: Arguments) => { console.error(message); } } - - process.exit(0); }; export const middlewares = [useAppConfig, useInstanceConnector]; diff --git a/src/types.ts b/src/types.ts index 131fe30d..4683a1c8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -84,10 +84,6 @@ export interface AppDeploy extends Deploy { manifestPath: string; } -export interface Open extends BaseOptions { - resource?: string; -} - export interface WebhookDryRun extends BaseOptions { objectId?: string; query?: string; diff --git a/tsconfig.json b/tsconfig.json index 8a644a35..8af6c6fb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,7 +25,7 @@ /* Modules */ "module": "ES2022" /* Specify what module code is generated. */, // "rootDir": "./", /* Specify the root folder within your source files. */ - "moduleResolution": "node16" /* Specify how TypeScript looks up a file from a given module specifier. */, + "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */, // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */