@sanity/cli 7.12.0 → 7.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -0
- package/dist/actions/api/constants.js +13 -0
- package/dist/actions/api/constants.js.map +1 -0
- package/dist/actions/api/distillApiRoutes.js +106 -0
- package/dist/actions/api/distillApiRoutes.js.map +1 -0
- package/dist/actions/api/errors.js +18 -0
- package/dist/actions/api/errors.js.map +1 -0
- package/dist/actions/api/parseFields.js +183 -0
- package/dist/actions/api/parseFields.js.map +1 -0
- package/dist/actions/api/resolveEndpoint.js +159 -0
- package/dist/actions/api/resolveEndpoint.js.map +1 -0
- package/dist/actions/api/types.js +10 -0
- package/dist/actions/api/types.js.map +1 -0
- package/dist/actions/build/buildApp.js +4 -2
- package/dist/actions/build/buildApp.js.map +1 -1
- package/dist/actions/build/buildStudio.js +105 -14
- package/dist/actions/build/buildStudio.js.map +1 -1
- package/dist/actions/build/eventListenerFactory.js +70 -0
- package/dist/actions/build/eventListenerFactory.js.map +1 -0
- package/dist/actions/dev/servers/startStudioDevServer.js +5 -1
- package/dist/actions/dev/servers/startStudioDevServer.js.map +1 -1
- package/dist/commands/api.js +294 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/backups/disable.js +4 -4
- package/dist/commands/backups/disable.js.map +1 -1
- package/dist/commands/backups/download.js +7 -7
- package/dist/commands/backups/download.js.map +1 -1
- package/dist/commands/backups/enable.js +4 -4
- package/dist/commands/backups/enable.js.map +1 -1
- package/dist/commands/backups/list.js +7 -7
- package/dist/commands/backups/list.js.map +1 -1
- package/dist/commands/codemod.js +5 -5
- package/dist/commands/codemod.js.map +1 -1
- package/dist/commands/cors/add.js +1 -1
- package/dist/commands/cors/add.js.map +1 -1
- package/dist/commands/cors/delete.js +4 -4
- package/dist/commands/cors/delete.js.map +1 -1
- package/dist/commands/cors/list.js +2 -2
- package/dist/commands/cors/list.js.map +1 -1
- package/dist/commands/datasets/alias/create.js +5 -5
- package/dist/commands/datasets/alias/create.js.map +1 -1
- package/dist/commands/datasets/alias/delete.js +2 -2
- package/dist/commands/datasets/alias/delete.js.map +1 -1
- package/dist/commands/datasets/alias/link.js +5 -5
- package/dist/commands/datasets/alias/link.js.map +1 -1
- package/dist/commands/datasets/alias/unlink.js +3 -3
- package/dist/commands/datasets/alias/unlink.js.map +1 -1
- package/dist/commands/datasets/copy.js +7 -7
- package/dist/commands/datasets/copy.js.map +1 -1
- package/dist/commands/datasets/create.js +3 -3
- package/dist/commands/datasets/create.js.map +1 -1
- package/dist/commands/datasets/delete.js +2 -2
- package/dist/commands/datasets/delete.js.map +1 -1
- package/dist/commands/datasets/embeddings/disable.js +3 -3
- package/dist/commands/datasets/embeddings/disable.js.map +1 -1
- package/dist/commands/datasets/embeddings/enable.js +5 -5
- package/dist/commands/datasets/embeddings/enable.js.map +1 -1
- package/dist/commands/datasets/embeddings/status.js +3 -3
- package/dist/commands/datasets/embeddings/status.js.map +1 -1
- package/dist/commands/datasets/export.js +6 -6
- package/dist/commands/datasets/export.js.map +1 -1
- package/dist/commands/datasets/import.js +3 -3
- package/dist/commands/datasets/import.js.map +1 -1
- package/dist/commands/datasets/list.js +2 -2
- package/dist/commands/datasets/list.js.map +1 -1
- package/dist/commands/datasets/visibility/get.js +2 -2
- package/dist/commands/datasets/visibility/get.js.map +1 -1
- package/dist/commands/datasets/visibility/set.js +3 -3
- package/dist/commands/datasets/visibility/set.js.map +1 -1
- package/dist/commands/deploy.js +2 -2
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/dev.js +2 -2
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/docs/read.js +1 -1
- package/dist/commands/docs/read.js.map +1 -1
- package/dist/commands/docs/search.js +3 -3
- package/dist/commands/docs/search.js.map +1 -1
- package/dist/commands/doctor.js +3 -3
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/documents/create.js +3 -3
- package/dist/commands/documents/create.js.map +1 -1
- package/dist/commands/documents/delete.js +3 -3
- package/dist/commands/documents/delete.js.map +1 -1
- package/dist/commands/documents/get.js +2 -2
- package/dist/commands/documents/get.js.map +1 -1
- package/dist/commands/documents/query.js +2 -2
- package/dist/commands/documents/query.js.map +1 -1
- package/dist/commands/documents/validate.js +3 -3
- package/dist/commands/documents/validate.js.map +1 -1
- package/dist/commands/graphql/deploy.js +13 -13
- package/dist/commands/graphql/deploy.js.map +1 -1
- package/dist/commands/graphql/list.js +2 -2
- package/dist/commands/graphql/list.js.map +1 -1
- package/dist/commands/graphql/undeploy.js +2 -2
- package/dist/commands/graphql/undeploy.js.map +1 -1
- package/dist/commands/hooks/attempt.js +2 -2
- package/dist/commands/hooks/attempt.js.map +1 -1
- package/dist/commands/hooks/create.js +3 -3
- package/dist/commands/hooks/create.js.map +1 -1
- package/dist/commands/hooks/delete.js +4 -4
- package/dist/commands/hooks/delete.js.map +1 -1
- package/dist/commands/hooks/list.js +2 -2
- package/dist/commands/hooks/list.js.map +1 -1
- package/dist/commands/hooks/logs.js +5 -5
- package/dist/commands/hooks/logs.js.map +1 -1
- package/dist/commands/login.js +2 -2
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.js +2 -2
- package/dist/commands/logout.js.map +1 -1
- package/dist/commands/manifest/extract.js +3 -3
- package/dist/commands/manifest/extract.js.map +1 -1
- package/dist/commands/mcp/configure.js +4 -4
- package/dist/commands/mcp/configure.js.map +1 -1
- package/dist/commands/media/create-aspect.js +3 -3
- package/dist/commands/media/create-aspect.js.map +1 -1
- package/dist/commands/media/delete-aspect.js +1 -1
- package/dist/commands/media/delete-aspect.js.map +1 -1
- package/dist/commands/media/deploy-aspect.js +4 -4
- package/dist/commands/media/deploy-aspect.js.map +1 -1
- package/dist/commands/media/export.js +7 -7
- package/dist/commands/media/export.js.map +1 -1
- package/dist/commands/media/import.js +6 -6
- package/dist/commands/media/import.js.map +1 -1
- package/dist/commands/migrations/create.js +4 -4
- package/dist/commands/migrations/create.js.map +1 -1
- package/dist/commands/migrations/list.js +2 -2
- package/dist/commands/migrations/list.js.map +1 -1
- package/dist/commands/migrations/run.js +14 -14
- package/dist/commands/migrations/run.js.map +1 -1
- package/dist/commands/openapi/get.js +3 -3
- package/dist/commands/openapi/get.js.map +1 -1
- package/dist/commands/openapi/list.js +2 -2
- package/dist/commands/openapi/list.js.map +1 -1
- package/dist/commands/organizations/create.js +5 -5
- package/dist/commands/organizations/create.js.map +1 -1
- package/dist/commands/organizations/delete.js +6 -6
- package/dist/commands/organizations/delete.js.map +1 -1
- package/dist/commands/organizations/get.js +3 -3
- package/dist/commands/organizations/get.js.map +1 -1
- package/dist/commands/organizations/list.js +2 -2
- package/dist/commands/organizations/list.js.map +1 -1
- package/dist/commands/organizations/update.js +6 -6
- package/dist/commands/organizations/update.js.map +1 -1
- package/dist/commands/preview.js +2 -2
- package/dist/commands/preview.js.map +1 -1
- package/dist/commands/projects/create.js +2 -2
- package/dist/commands/projects/create.js.map +1 -1
- package/dist/commands/projects/list.js +2 -2
- package/dist/commands/projects/list.js.map +1 -1
- package/dist/commands/schemas/delete.js +2 -2
- package/dist/commands/schemas/delete.js.map +1 -1
- package/dist/commands/schemas/deploy.js +2 -2
- package/dist/commands/schemas/deploy.js.map +1 -1
- package/dist/commands/schemas/list.js +1 -1
- package/dist/commands/schemas/list.js.map +1 -1
- package/dist/commands/schemas/validate.js +2 -1
- package/dist/commands/schemas/validate.js.map +1 -1
- package/dist/commands/skills/install.js +2 -2
- package/dist/commands/skills/install.js.map +1 -1
- package/dist/commands/telemetry/disable.js +2 -2
- package/dist/commands/telemetry/disable.js.map +1 -1
- package/dist/commands/telemetry/enable.js +2 -2
- package/dist/commands/telemetry/enable.js.map +1 -1
- package/dist/commands/tokens/create.js +2 -2
- package/dist/commands/tokens/create.js.map +1 -1
- package/dist/commands/tokens/delete.js +2 -2
- package/dist/commands/tokens/delete.js.map +1 -1
- package/dist/commands/tokens/list.js +2 -2
- package/dist/commands/tokens/list.js.map +1 -1
- package/dist/commands/users/invite.js +3 -3
- package/dist/commands/users/invite.js.map +1 -1
- package/dist/generated/apiRoutes.js +401 -0
- package/dist/generated/apiRoutes.js.map +1 -0
- package/dist/services/api.js +116 -0
- package/dist/services/api.js.map +1 -0
- package/oclif.manifest.json +433 -252
- package/package.json +5 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/migrations/run.ts"],"sourcesContent":["import path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {Args, Flags} from '@oclif/core'\nimport {getProjectCliClient, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {confirm, spinner} from '@sanity/cli-core/ux'\nimport {\n type APIConfig,\n DEFAULT_MUTATION_CONCURRENCY,\n dryRun,\n MAX_MUTATION_CONCURRENCY,\n type Migration,\n type MigrationProgress,\n run,\n} from '@sanity/migrate'\nimport {Table} from 'console-table-printer'\n\nimport {DEFAULT_API_VERSION, MIGRATIONS_DIRECTORY} from '../../actions/migration/constants.js'\nimport {ensureApiVersionFormat} from '../../actions/migration/ensureApiVersionFormat.js'\nimport {prettyFormat} from '../../actions/migration/prettyMutationFormatter.js'\nimport {resolveMigrations} from '../../actions/migration/resolveMigrations.js'\nimport {\n isLoadableMigrationScript,\n resolveMigrationScript,\n} from '../../actions/migration/resolveMigrationScript.js'\n\nconst runMigrationDebug = subdebug('migration:run')\n\nexport type RunMigrationFlags = RunMigrationCommand['flags']\n\nexport class RunMigrationCommand extends SanityCommand<typeof RunMigrationCommand> {\n static override args = {\n id: Args.string({\n description: 'ID',\n required: false,\n }),\n }\n\n static override description = 'Run a migration against a dataset'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> <id>',\n description: 'dry run the migration',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> <id> --no-dry-run --project xyz --dataset staging',\n description: 'execute the migration against a dataset',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> <id> --from-export=production.tar.gz --no-dry-run --project xyz --dataset staging',\n description: 'execute the migration using a dataset export as the source',\n },\n ]\n\n static override flags = {\n 'api-version': Flags.string({\n description: `API version to use when migrating. Defaults to ${DEFAULT_API_VERSION}.`,\n }),\n concurrency: Flags.integer({\n default: DEFAULT_MUTATION_CONCURRENCY,\n description: `How many mutation requests to run in parallel. Must be between 1 and ${MAX_MUTATION_CONCURRENCY}. Default: ${DEFAULT_MUTATION_CONCURRENCY}.`,\n }),\n confirm: Flags.boolean({\n allowNo: true,\n default: true,\n description:\n 'Prompt for confirmation before running the migration (default: true). Use --no-confirm to skip.',\n }),\n dataset: Flags.string({\n description:\n 'Dataset to migrate. Defaults to the dataset configured in your Sanity CLI config.',\n }),\n 'dry-run': Flags.boolean({\n allowNo: true,\n default: true,\n description:\n 'By default the migration runs in dry mode. Use --no-dry-run to migrate dataset.',\n }),\n 'from-export': Flags.string({\n description:\n 'Use a local dataset export as source for migration instead of calling the Sanity API. Note: this is only supported for dry runs.',\n }),\n progress: Flags.boolean({\n allowNo: true,\n default: true,\n description:\n 'Display progress during migration (default: true). Use --no-progress to hide output.',\n }),\n project: Flags.string({\n description:\n 'Project ID of the dataset to migrate. Defaults to the projectId configured in your Sanity CLI config.',\n }),\n }\n\n static override hiddenAliases = ['migration:run']\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(RunMigrationCommand)\n const {directory: workDir} = await this.getProjectRoot()\n const id = args.id\n const migrationsDirectoryPath = path.join(workDir, MIGRATIONS_DIRECTORY)\n\n // Listing migrations (no id given) only needs a project root, mirroring\n // `sanity migrations list` — it must not require api.projectId/dataset.\n if (!id) {\n this.warn(styleText('red', 'Error: Migration ID must be provided'))\n\n let migrations: Awaited<ReturnType<typeof resolveMigrations>> = []\n try {\n migrations = await resolveMigrations(workDir)\n } catch (error) {\n // A missing migrations folder is expected for a fresh project; surface\n // any other failure (e.g. a syntax error in a migration file).\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {\n this.error(\n `Failed to list migrations: ${error instanceof Error ? error.message : String(error)}`,\n {exit: 1},\n )\n }\n }\n\n if (migrations.length === 0) {\n this.log('\\nNo migrations found in the project')\n this.log(\n `Run ${styleText('green', '`sanity migration create <NAME>`')} to create a new migration`,\n )\n this.exit(1)\n }\n\n const table = new Table({\n columns: [\n {alignment: 'left', name: 'id', title: 'ID'},\n {alignment: 'left', name: 'title', title: 'Title'},\n ],\n title: `Migrations found in project`,\n })\n\n for (const definedMigration of migrations) {\n table.addRow({id: definedMigration.id, title: definedMigration.migration.title})\n }\n table.printTable()\n this.log('\\nRun `sanity migration run <ID>` to run a migration')\n\n this.exit(1)\n }\n\n const cliConfig = await this.getCliConfig()\n const projectId = await this.getProjectId({deprecatedFlagName: 'project'})\n const datasetFromConfig = cliConfig.api?.dataset\n\n const fromExport = flags['from-export']\n const dry = flags['dry-run']\n const dataset = flags.dataset\n const project = flags.project\n const apiVersion = ensureApiVersionFormat(flags['api-version'] ?? DEFAULT_API_VERSION)\n\n if ((dataset && !project) || (project && !dataset)) {\n this.error('If either --dataset or --project is provided, both must be provided', {exit: 1})\n }\n\n if (!project && !projectId) {\n this.error(\n 'sanity.cli.js does not contain a project identifier (\"api.projectId\") and no --project option was provided.',\n {exit: 1},\n )\n }\n\n if (!dataset && !datasetFromConfig) {\n this.error(\n 'sanity.cli.js does not contain a dataset identifier (\"api.dataset\") and no --dataset option was provided.',\n {exit: 1},\n )\n }\n\n const candidates = await resolveMigrationScript(workDir, id)\n const resolvedScripts = candidates.filter((candidate) => isLoadableMigrationScript(candidate))\n\n if (resolvedScripts.length > 1) {\n // todo: consider prompt user about which one to run? note: it's likely a mistake if multiple files resolve to the same name\n this.error(\n `Found multiple migrations for \"${id}\" in ${styleText('cyan', migrationsDirectoryPath)}: \\n - ${candidates\n .map((candidate) => path.relative(migrationsDirectoryPath, candidate.absolutePath))\n .join('\\n - ')}`,\n {exit: 1},\n )\n }\n\n const script = resolvedScripts[0]\n if (!script) {\n this.error(\n `No migration found for \"${id}\" in ${styleText('cyan', migrationsDirectoryPath)}. Make sure that the migration file exists and exports a valid migration as its default export.\\n\n Tried the following files:\\n - ${candidates\n .map((candidate) => path.relative(migrationsDirectoryPath, candidate.absolutePath))\n .join('\\n - ')}`,\n {exit: 1},\n )\n }\n\n const mod = script.mod\n if ('up' in mod || 'down' in mod) {\n // todo: consider adding support for up/down as separate named exports\n // For now, make sure we reserve the names for future use\n this.error(\n 'Named \"up\"/\"down\" migration exports are not supported at this time, please export your migration as the default export',\n {\n exit: 1,\n },\n )\n }\n\n const migration: Migration = mod.default\n\n if (fromExport && !dry) {\n this.error('Can only dry run migrations from a dataset export file', {exit: 1})\n }\n\n const concurrency = flags.concurrency\n if (concurrency !== undefined) {\n if (concurrency > MAX_MUTATION_CONCURRENCY) {\n this.error(`Concurrency exceeds the maximum allowed value of ${MAX_MUTATION_CONCURRENCY}`, {\n exit: 1,\n })\n }\n\n if (concurrency < 1) {\n this.error(`Concurrency must be a positive number, got ${concurrency}`, {exit: 1})\n }\n }\n\n const projectClient = await getProjectCliClient({\n apiVersion,\n projectId: (project ?? projectId)!,\n requireUser: true,\n })\n const projectConfig = projectClient.config()\n\n const apiConfig: APIConfig = {\n apiHost: projectConfig.apiHost,\n apiVersion,\n dataset: (dataset ?? datasetFromConfig)!,\n projectId: (project ?? projectId)!,\n token: projectConfig.token!,\n } as const\n if (dry) {\n await this.dryRunHandler(id, migration, apiConfig, fromExport)\n return\n }\n\n this.log(\n `\\n${styleText(['yellow', 'bold'], 'Note: During migrations, your webhooks stay active.')}`,\n )\n this.log(\n `To adjust them, launch the management interface with ${styleText('cyan', 'sanity manage')}, navigate to the API settings, and toggle the webhooks before and after the migration as needed.\\n`,\n )\n\n if (flags.confirm) {\n await this.promptConfirmMigrate(apiConfig)\n }\n\n const spin = spinner(`Running migration \"${id}\"`).start()\n try {\n await run(\n {\n api: apiConfig,\n concurrency,\n onProgress: this.createProgress(spin, flags, id, dry, apiConfig, migration),\n },\n migration,\n )\n } finally {\n spin.stop()\n }\n }\n\n private createProgress(\n progressSpinner: ReturnType<typeof spinner>,\n flags: RunMigrationFlags,\n id: string,\n dry: boolean,\n apiConfig: APIConfig,\n migration: Migration,\n ) {\n return function onProgress(progress: MigrationProgress) {\n if (!flags.progress) {\n progressSpinner.stop()\n return\n }\n if (progress.done) {\n progressSpinner.text = `Migration \"${id}\" completed.\n\n Project id: ${styleText('bold', apiConfig.projectId)}\n Dataset: ${styleText('bold', apiConfig.dataset)}\n\n ${progress.documents} documents processed.\n ${progress.mutations} mutations generated.\n ${styleText('green', String(progress.completedTransactions.length))} transactions committed.`\n progressSpinner.stopAndPersist({symbol: styleText('green', '✔')})\n return\n }\n\n for (const transaction of [null, ...progress.currentTransactions]) {\n progressSpinner.text = `Running migration \"${id}\" ${dry ? 'in dry mode...' : '...'}\n\n Project id: ${styleText('bold', apiConfig.projectId)}\n Dataset: ${styleText('bold', apiConfig.dataset)}\n Document type: ${styleText('bold', migration.documentTypes?.join(',') ?? '')}\n\n ${progress.documents} documents processed…\n ${progress.mutations} mutations generated…\n ${styleText('blue', String(progress.pending))} requests pending…\n ${styleText('green', String(progress.completedTransactions.length))} transactions committed.\n\n ${\n transaction && !progress.done\n ? `» ${prettyFormat({indentSize: 2, migration, subject: transaction})}`\n : ''\n }`\n }\n }\n }\n\n private async dryRunHandler(\n id: string,\n migration: Migration,\n apiConfig: APIConfig,\n fromExport: string | undefined,\n ) {\n this.log(`Running migration \"${id}\" in dry mode`)\n\n if (fromExport) {\n this.log(`Using export ${styleText('cyan', fromExport)}`)\n }\n\n this.log()\n this.log(`Project id: ${styleText('bold', apiConfig.projectId)}`)\n this.log(`Dataset: ${styleText('bold', apiConfig.dataset)}`)\n\n for await (const mutation of dryRun({api: apiConfig, exportPath: fromExport}, migration)) {\n if (!mutation) continue\n this.log()\n this.log(\n prettyFormat({\n migration,\n subject: mutation,\n }),\n )\n }\n }\n\n private async promptConfirmMigrate(apiConfig: APIConfig) {\n const response = await confirm({\n message: `This migration will run on the ${styleText(\n ['yellow', 'bold'],\n apiConfig.dataset,\n )} dataset in ${styleText(['yellow', 'bold'], apiConfig.projectId)} project. Are you sure?`,\n })\n\n if (!response) {\n runMigrationDebug('User aborted migration')\n this.exit(1)\n }\n }\n}\n"],"names":["path","styleText","Args","Flags","getProjectCliClient","SanityCommand","subdebug","confirm","spinner","DEFAULT_MUTATION_CONCURRENCY","dryRun","MAX_MUTATION_CONCURRENCY","run","Table","DEFAULT_API_VERSION","MIGRATIONS_DIRECTORY","ensureApiVersionFormat","prettyFormat","resolveMigrations","isLoadableMigrationScript","resolveMigrationScript","runMigrationDebug","RunMigrationCommand","args","id","string","description","required","examples","command","flags","concurrency","integer","default","boolean","allowNo","dataset","progress","project","hiddenAliases","parse","directory","workDir","getProjectRoot","migrationsDirectoryPath","join","warn","migrations","error","code","Error","message","String","exit","length","log","table","columns","alignment","name","title","definedMigration","addRow","migration","printTable","cliConfig","getCliConfig","projectId","getProjectId","deprecatedFlagName","datasetFromConfig","api","fromExport","dry","apiVersion","candidates","resolvedScripts","filter","candidate","map","relative","absolutePath","script","mod","undefined","projectClient","requireUser","projectConfig","config","apiConfig","apiHost","token","dryRunHandler","promptConfirmMigrate","spin","start","onProgress","createProgress","stop","progressSpinner","done","text","documents","mutations","completedTransactions","stopAndPersist","symbol","transaction","currentTransactions","documentTypes","pending","indentSize","subject","mutation","exportPath","response"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,mBAAmB,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AAC7E,SAAQC,OAAO,EAAEC,OAAO,QAAO,sBAAqB;AACpD,SAEEC,4BAA4B,EAC5BC,MAAM,EACNC,wBAAwB,EAGxBC,GAAG,QACE,kBAAiB;AACxB,SAAQC,KAAK,QAAO,wBAAuB;AAE3C,SAAQC,mBAAmB,EAAEC,oBAAoB,QAAO,uCAAsC;AAC9F,SAAQC,sBAAsB,QAAO,oDAAmD;AACxF,SAAQC,YAAY,QA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J,SAAoB,EAAE;QACvD,MAAM0B,WAAW,MAAM5G,QAAQ;YAC7B4C,SAAS,CAAC,+BAA+B,EAAElD,UACzC;gBAAC;gBAAU;aAAO,EAClBwF,UAAUrD,OAAO,EACjB,YAAY,EAAEnC,UAAU;gBAAC;gBAAU;aAAO,EAAEwF,UAAUtB,SAAS,EAAE,uBAAuB,CAAC;QAC7F;QAEA,IAAI,CAACgD,UAAU;YACb9F,kBAAkB;YAClB,IAAI,CAACgC,IAAI,CAAC;QACZ;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/migrations/run.ts"],"sourcesContent":["import path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {Args, Flags} from '@oclif/core'\nimport {exitCodes, getProjectCliClient, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {confirm, spinner} from '@sanity/cli-core/ux'\nimport {\n type APIConfig,\n DEFAULT_MUTATION_CONCURRENCY,\n dryRun,\n MAX_MUTATION_CONCURRENCY,\n type Migration,\n type MigrationProgress,\n run,\n} from '@sanity/migrate'\nimport {Table} from 'console-table-printer'\n\nimport {DEFAULT_API_VERSION, MIGRATIONS_DIRECTORY} from '../../actions/migration/constants.js'\nimport {ensureApiVersionFormat} from '../../actions/migration/ensureApiVersionFormat.js'\nimport {prettyFormat} from '../../actions/migration/prettyMutationFormatter.js'\nimport {resolveMigrations} from '../../actions/migration/resolveMigrations.js'\nimport {\n isLoadableMigrationScript,\n resolveMigrationScript,\n} from '../../actions/migration/resolveMigrationScript.js'\n\nconst runMigrationDebug = subdebug('migration:run')\n\nexport type RunMigrationFlags = RunMigrationCommand['flags']\n\nexport class RunMigrationCommand extends SanityCommand<typeof RunMigrationCommand> {\n static override args = {\n id: Args.string({\n description: 'ID',\n required: false,\n }),\n }\n\n static override description = 'Run a migration against a dataset'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> <id>',\n description: 'dry run the migration',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> <id> --no-dry-run --project xyz --dataset staging',\n description: 'execute the migration against a dataset',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> <id> --from-export=production.tar.gz --no-dry-run --project xyz --dataset staging',\n description: 'execute the migration using a dataset export as the source',\n },\n ]\n\n static override flags = {\n 'api-version': Flags.string({\n description: `API version to use when migrating. Defaults to ${DEFAULT_API_VERSION}.`,\n }),\n concurrency: Flags.integer({\n default: DEFAULT_MUTATION_CONCURRENCY,\n description: `How many mutation requests to run in parallel. Must be between 1 and ${MAX_MUTATION_CONCURRENCY}. Default: ${DEFAULT_MUTATION_CONCURRENCY}.`,\n }),\n confirm: Flags.boolean({\n allowNo: true,\n default: true,\n description:\n 'Prompt for confirmation before running the migration (default: true). Use --no-confirm to skip.',\n }),\n dataset: Flags.string({\n description:\n 'Dataset to migrate. Defaults to the dataset configured in your Sanity CLI config.',\n }),\n 'dry-run': Flags.boolean({\n allowNo: true,\n default: true,\n description:\n 'By default the migration runs in dry mode. Use --no-dry-run to migrate dataset.',\n }),\n 'from-export': Flags.string({\n description:\n 'Use a local dataset export as source for migration instead of calling the Sanity API. Note: this is only supported for dry runs.',\n }),\n progress: Flags.boolean({\n allowNo: true,\n default: true,\n description:\n 'Display progress during migration (default: true). Use --no-progress to hide output.',\n }),\n project: Flags.string({\n description:\n 'Project ID of the dataset to migrate. Defaults to the projectId configured in your Sanity CLI config.',\n }),\n }\n\n static override hiddenAliases = ['migration:run']\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(RunMigrationCommand)\n const {directory: workDir} = await this.getProjectRoot()\n const id = args.id\n const migrationsDirectoryPath = path.join(workDir, MIGRATIONS_DIRECTORY)\n\n // Listing migrations (no id given) only needs a project root, mirroring\n // `sanity migrations list` — it must not require api.projectId/dataset.\n if (!id) {\n this.warn(styleText('red', 'Error: Migration ID must be provided'))\n\n let migrations: Awaited<ReturnType<typeof resolveMigrations>> = []\n try {\n migrations = await resolveMigrations(workDir)\n } catch (error) {\n // A missing migrations folder is expected for a fresh project; surface\n // any other failure (e.g. a syntax error in a migration file).\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {\n this.error(\n `Failed to list migrations: ${error instanceof Error ? error.message : String(error)}`,\n {exit: exitCodes.RUNTIME_ERROR},\n )\n }\n }\n\n if (migrations.length === 0) {\n this.log('\\nNo migrations found in the project')\n this.log(\n `Run ${styleText('green', '`sanity migration create <NAME>`')} to create a new migration`,\n )\n this.exit(exitCodes.RUNTIME_ERROR)\n }\n\n const table = new Table({\n columns: [\n {alignment: 'left', name: 'id', title: 'ID'},\n {alignment: 'left', name: 'title', title: 'Title'},\n ],\n title: `Migrations found in project`,\n })\n\n for (const definedMigration of migrations) {\n table.addRow({id: definedMigration.id, title: definedMigration.migration.title})\n }\n table.printTable()\n this.log('\\nRun `sanity migration run <ID>` to run a migration')\n\n this.exit(exitCodes.RUNTIME_ERROR)\n }\n\n const cliConfig = await this.getCliConfig()\n const projectId = await this.getProjectId({deprecatedFlagName: 'project'})\n const datasetFromConfig = cliConfig.api?.dataset\n\n const fromExport = flags['from-export']\n const dry = flags['dry-run']\n const dataset = flags.dataset\n const project = flags.project\n const apiVersion = ensureApiVersionFormat(flags['api-version'] ?? DEFAULT_API_VERSION)\n\n if ((dataset && !project) || (project && !dataset)) {\n this.error('If either --dataset or --project is provided, both must be provided', {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (!project && !projectId) {\n this.error(\n 'sanity.cli.js does not contain a project identifier (\"api.projectId\") and no --project option was provided.',\n {exit: exitCodes.RUNTIME_ERROR},\n )\n }\n\n if (!dataset && !datasetFromConfig) {\n this.error(\n 'sanity.cli.js does not contain a dataset identifier (\"api.dataset\") and no --dataset option was provided.',\n {exit: exitCodes.RUNTIME_ERROR},\n )\n }\n\n const candidates = await resolveMigrationScript(workDir, id)\n const resolvedScripts = candidates.filter((candidate) => isLoadableMigrationScript(candidate))\n\n if (resolvedScripts.length > 1) {\n // todo: consider prompt user about which one to run? note: it's likely a mistake if multiple files resolve to the same name\n this.error(\n `Found multiple migrations for \"${id}\" in ${styleText('cyan', migrationsDirectoryPath)}: \\n - ${candidates\n .map((candidate) => path.relative(migrationsDirectoryPath, candidate.absolutePath))\n .join('\\n - ')}`,\n {exit: exitCodes.RUNTIME_ERROR},\n )\n }\n\n const script = resolvedScripts[0]\n if (!script) {\n this.error(\n `No migration found for \"${id}\" in ${styleText('cyan', migrationsDirectoryPath)}. Make sure that the migration file exists and exports a valid migration as its default export.\\n\n Tried the following files:\\n - ${candidates\n .map((candidate) => path.relative(migrationsDirectoryPath, candidate.absolutePath))\n .join('\\n - ')}`,\n {exit: exitCodes.RUNTIME_ERROR},\n )\n }\n\n const mod = script.mod\n if ('up' in mod || 'down' in mod) {\n // todo: consider adding support for up/down as separate named exports\n // For now, make sure we reserve the names for future use\n this.error(\n 'Named \"up\"/\"down\" migration exports are not supported at this time, please export your migration as the default export',\n {\n exit: exitCodes.RUNTIME_ERROR,\n },\n )\n }\n\n const migration: Migration = mod.default\n\n if (fromExport && !dry) {\n this.error('Can only dry run migrations from a dataset export file', {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n const concurrency = flags.concurrency\n if (concurrency !== undefined) {\n if (concurrency > MAX_MUTATION_CONCURRENCY) {\n this.error(`Concurrency exceeds the maximum allowed value of ${MAX_MUTATION_CONCURRENCY}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (concurrency < 1) {\n this.error(`Concurrency must be a positive number, got ${concurrency}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n\n const projectClient = await getProjectCliClient({\n apiVersion,\n projectId: (project ?? projectId)!,\n requireUser: true,\n })\n const projectConfig = projectClient.config()\n\n const apiConfig: APIConfig = {\n apiHost: projectConfig.apiHost,\n apiVersion,\n dataset: (dataset ?? datasetFromConfig)!,\n projectId: (project ?? projectId)!,\n token: projectConfig.token!,\n } as const\n if (dry) {\n await this.dryRunHandler(id, migration, apiConfig, fromExport)\n return\n }\n\n this.log(\n `\\n${styleText(['yellow', 'bold'], 'Note: During migrations, your webhooks stay active.')}`,\n )\n this.log(\n `To adjust them, launch the management interface with ${styleText('cyan', 'sanity manage')}, navigate to the API settings, and toggle the webhooks before and after the migration as needed.\\n`,\n )\n\n if (flags.confirm) {\n await this.promptConfirmMigrate(apiConfig)\n }\n\n const spin = spinner(`Running migration \"${id}\"`).start()\n try {\n await run(\n {\n api: apiConfig,\n concurrency,\n onProgress: this.createProgress(spin, flags, id, dry, apiConfig, migration),\n },\n migration,\n )\n } finally {\n spin.stop()\n }\n }\n\n private createProgress(\n progressSpinner: ReturnType<typeof spinner>,\n flags: RunMigrationFlags,\n id: string,\n dry: boolean,\n apiConfig: APIConfig,\n migration: Migration,\n ) {\n return function onProgress(progress: MigrationProgress) {\n if (!flags.progress) {\n progressSpinner.stop()\n return\n }\n if (progress.done) {\n progressSpinner.text = `Migration \"${id}\" completed.\n\n Project id: ${styleText('bold', apiConfig.projectId)}\n Dataset: ${styleText('bold', apiConfig.dataset)}\n\n ${progress.documents} documents processed.\n ${progress.mutations} mutations generated.\n ${styleText('green', String(progress.completedTransactions.length))} transactions committed.`\n progressSpinner.stopAndPersist({symbol: styleText('green', '✔')})\n return\n }\n\n for (const transaction of [null, ...progress.currentTransactions]) {\n progressSpinner.text = `Running migration \"${id}\" ${dry ? 'in dry mode...' : '...'}\n\n Project id: ${styleText('bold', apiConfig.projectId)}\n Dataset: ${styleText('bold', apiConfig.dataset)}\n Document type: ${styleText('bold', migration.documentTypes?.join(',') ?? '')}\n\n ${progress.documents} documents processed…\n ${progress.mutations} mutations generated…\n ${styleText('blue', String(progress.pending))} requests pending…\n ${styleText('green', String(progress.completedTransactions.length))} transactions committed.\n\n ${\n transaction && !progress.done\n ? `» ${prettyFormat({indentSize: 2, migration, subject: transaction})}`\n : ''\n }`\n }\n }\n }\n\n private async dryRunHandler(\n id: string,\n migration: Migration,\n apiConfig: APIConfig,\n fromExport: string | undefined,\n ) {\n this.log(`Running migration \"${id}\" in dry mode`)\n\n if (fromExport) {\n this.log(`Using export ${styleText('cyan', fromExport)}`)\n }\n\n this.log()\n this.log(`Project id: ${styleText('bold', apiConfig.projectId)}`)\n this.log(`Dataset: ${styleText('bold', apiConfig.dataset)}`)\n\n for await (const mutation of dryRun({api: apiConfig, exportPath: fromExport}, migration)) {\n if (!mutation) continue\n this.log()\n this.log(\n prettyFormat({\n migration,\n subject: mutation,\n }),\n )\n }\n }\n\n private async promptConfirmMigrate(apiConfig: APIConfig) {\n const response = await confirm({\n message: `This migration will run on the ${styleText(\n ['yellow', 'bold'],\n apiConfig.dataset,\n )} dataset in ${styleText(['yellow', 'bold'], apiConfig.projectId)} project. Are you sure?`,\n })\n\n if (!response) {\n runMigrationDebug('User aborted migration')\n this.exit(exitCodes.RUNTIME_ERROR)\n }\n }\n}\n"],"names":["path","styleText","Args","Flags","exitCodes","getProjectCliClient","SanityCommand","subdebug","confirm","spinner","DEFAULT_MUTATION_CONCURRENCY","dryRun","MAX_MUTATION_CONCURRENCY","run","Table","DEFAULT_API_VERSION","MIGRATIONS_DIRECTORY","ensureApiVersionFormat","prettyFormat","resolveMigrations","isLoadableMigrationScript","resolveMigrationScript","runMigrationDebug","RunMigrationCommand","args","id","string","description","required","examples","command","flags","concurrency","integer","default","boolean","allowNo","dataset","progress","project","hiddenAliases","parse","directory","workDir","getProjectRoot","migrationsDirectoryPath","join","warn","migrations","error","code","Error","message","String","exit","RUNTIME_ERROR","length","log","table","columns","alignment","name","title","definedMigration","addRow","migration","printTable","cliConfig","getCliConfig","projectId","getProjectId","deprecatedFlagName","datasetFromConfig","api","fromExport","dry","apiVersion","candidates","resolvedScripts","filter","candidate","map","relative","absolutePath","script","mod","undefined","projectClient","requireUser","projectConfig","config","apiConfig","apiHost","token","dryRunHandler","promptConfirmMigrate","spin","start","onProgress","createProgress","stop","progressSpinner","done","text","documents","mutations","completedTransactions","stopAndPersist","symbol","transaction","currentTransactions","documentTypes","pending","indentSize","subject","mutation","exportPath","response"],"mappings":"AAAA,OAAOA,UAAU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B,EACpBjB,UAA8B,EAC9B;QACA,IAAI,CAACjB,GAAG,CAAC,CAAC,mBAAmB,EAAEhC,GAAG,aAAa,CAAC;QAEhD,IAAIiD,YAAY;YACd,IAAI,CAACjB,GAAG,CAAC,CAAC,aAAa,EAAExD,UAAU,QAAQyE,aAAa;QAC1D;QAEA,IAAI,CAACjB,GAAG;QACR,IAAI,CAACA,GAAG,CAAC,CAAC,aAAa,EAAExD,UAAU,QAAQ0F,UAAUtB,SAAS,GAAG;QACjE,IAAI,CAACZ,GAAG,CAAC,CAAC,aAAa,EAAExD,UAAU,QAAQ0F,UAAUtD,OAAO,GAAG;QAE/D,WAAW,MAAM8E,YAAYxG,OAAO;YAAC8D,KAAKkB;YAAWyB,YAAY1C;QAAU,GAAGT,WAAY;YACxF,IAAI,CAACkD,UAAU;YACf,IAAI,CAAC1D,GAAG;YACR,IAAI,CAACA,GAAG,CACNvC,aAAa;gBACX+C;gBACAiD,SAASC;YACX;QAEJ;IACF;IAEA,MAAcpB,qBAAqBJ,SAAoB,EAAE;QACvD,MAAM0B,WAAW,MAAM7G,QAAQ;YAC7B4C,SAAS,CAAC,+BAA+B,EAAEnD,UACzC;gBAAC;gBAAU;aAAO,EAClB0F,UAAUtD,OAAO,EACjB,YAAY,EAAEpC,UAAU;gBAAC;gBAAU;aAAO,EAAE0F,UAAUtB,SAAS,EAAE,uBAAuB,CAAC;QAC7F;QAEA,IAAI,CAACgD,UAAU;YACb/F,kBAAkB;YAClB,IAAI,CAACgC,IAAI,CAAClD,UAAUmD,aAAa;QACnC;IACF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Args, Flags } from '@oclif/core';
|
|
2
|
-
import { SanityCommand, subdebug } from '@sanity/cli-core';
|
|
2
|
+
import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
|
|
3
3
|
import open from 'open';
|
|
4
4
|
const getOpenapiDebug = subdebug('openapi:get');
|
|
5
5
|
export class GetOpenApiCommand extends SanityCommand {
|
|
@@ -59,11 +59,11 @@ export class GetOpenApiCommand extends SanityCommand {
|
|
|
59
59
|
getOpenapiDebug(`Error fetching OpenAPI spec ${slug}`, error);
|
|
60
60
|
if (error instanceof Response && error.status === 404) {
|
|
61
61
|
this.error(`OpenAPI specification not found. ${slug}`, {
|
|
62
|
-
exit:
|
|
62
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
this.error('The OpenAPI service is currently unavailable. Please try again later.', {
|
|
66
|
-
exit:
|
|
66
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/openapi/get.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\nimport open from 'open'\n\nconst getOpenapiDebug = subdebug('openapi:get')\n\nexport class GetOpenApiCommand extends SanityCommand<typeof GetOpenApiCommand> {\n static override args = {\n slug: Args.string({\n description: 'Slug of the OpenAPI specification to retrieve',\n required: true,\n }),\n }\n\n static override description = 'Get an OpenAPI specification by slug'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> query',\n description: 'Get a specification (YAML format, default)',\n },\n {\n command: '<%= config.bin %> <%= command.id %> query --format=json',\n description: 'Get specification in JSON format',\n },\n {\n command: '<%= config.bin %> <%= command.id %> query --web',\n description: 'Open specification in browser',\n },\n {\n command: '<%= config.bin %> <%= command.id %> query > query-api.yaml',\n description: 'Pipe to file',\n },\n ]\n\n static override flags = {\n format: Flags.string({\n default: 'yaml',\n description: 'Output format: yaml (default), json',\n options: ['yaml', 'json'],\n }),\n web: Flags.boolean({\n char: 'w',\n description: 'Open in web browser',\n }),\n }\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(GetOpenApiCommand)\n const {slug} = args\n const {format, web} = flags\n\n if (web) {\n const url = `https://www.sanity.io/docs/http-reference/${slug}`\n this.log(`Opening ${url}`)\n await open(url)\n return\n }\n\n try {\n const specContent = await this.getSpecContent(slug, format)\n\n this.log(specContent)\n } catch (error) {\n getOpenapiDebug(`Error fetching OpenAPI spec ${slug}`, error)\n\n if (error instanceof Response && error.status === 404) {\n this.error(`OpenAPI specification not found. ${slug}`, {exit:
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/openapi/get.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport open from 'open'\n\nconst getOpenapiDebug = subdebug('openapi:get')\n\nexport class GetOpenApiCommand extends SanityCommand<typeof GetOpenApiCommand> {\n static override args = {\n slug: Args.string({\n description: 'Slug of the OpenAPI specification to retrieve',\n required: true,\n }),\n }\n\n static override description = 'Get an OpenAPI specification by slug'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> query',\n description: 'Get a specification (YAML format, default)',\n },\n {\n command: '<%= config.bin %> <%= command.id %> query --format=json',\n description: 'Get specification in JSON format',\n },\n {\n command: '<%= config.bin %> <%= command.id %> query --web',\n description: 'Open specification in browser',\n },\n {\n command: '<%= config.bin %> <%= command.id %> query > query-api.yaml',\n description: 'Pipe to file',\n },\n ]\n\n static override flags = {\n format: Flags.string({\n default: 'yaml',\n description: 'Output format: yaml (default), json',\n options: ['yaml', 'json'],\n }),\n web: Flags.boolean({\n char: 'w',\n description: 'Open in web browser',\n }),\n }\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(GetOpenApiCommand)\n const {slug} = args\n const {format, web} = flags\n\n if (web) {\n const url = `https://www.sanity.io/docs/http-reference/${slug}`\n this.log(`Opening ${url}`)\n await open(url)\n return\n }\n\n try {\n const specContent = await this.getSpecContent(slug, format)\n\n this.log(specContent)\n } catch (error) {\n getOpenapiDebug(`Error fetching OpenAPI spec ${slug}`, error)\n\n if (error instanceof Response && error.status === 404) {\n this.error(`OpenAPI specification not found. ${slug}`, {exit: exitCodes.RUNTIME_ERROR})\n }\n\n this.error('The OpenAPI service is currently unavailable. Please try again later.', {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n\n private async getSpecContent(slug: string, format: string): Promise<string> {\n const url = new URL(`https://www.sanity.io/docs/api/openapi/${slug}`)\n url.searchParams.set('format', format)\n const response = await fetch(url, {\n signal: AbortSignal.timeout(10_000),\n })\n\n if (response.ok) {\n return response.text()\n }\n\n throw response\n }\n}\n"],"names":["Args","Flags","exitCodes","SanityCommand","subdebug","open","getOpenapiDebug","GetOpenApiCommand","args","slug","string","description","required","examples","command","flags","format","default","options","web","boolean","char","run","parse","url","log","specContent","getSpecContent","error","Response","status","exit","RUNTIME_ERROR","URL","searchParams","set","response","fetch","signal","AbortSignal","timeout","ok","text"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,OAAOC,UAAU,OAAM;AAEvB,MAAMC,kBAAkBF,SAAS;AAEjC,OAAO,MAAMG,0BAA0BJ;IACrC,OAAgBK,OAAO;QACrBC,MAAMT,KAAKU,MAAM,CAAC;YAChBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,uCAAsC;IAEpE,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;KACD,CAAA;IAED,OAAgBI,QAAQ;QACtBC,QAAQf,MAAMS,MAAM,CAAC;YACnBO,SAAS;YACTN,aAAa;YACbO,SAAS;gBAAC;gBAAQ;aAAO;QAC3B;QACAC,KAAKlB,MAAMmB,OAAO,CAAC;YACjBC,MAAM;YACNV,aAAa;QACf;IACF,EAAC;IAED,MAAaW,MAAqB;QAChC,MAAM,EAACd,IAAI,EAAEO,KAAK,EAAC,GAAG,MAAM,IAAI,CAACQ,KAAK,CAAChB;QACvC,MAAM,EAACE,IAAI,EAAC,GAAGD;QACf,MAAM,EAACQ,MAAM,EAAEG,GAAG,EAAC,GAAGJ;QAEtB,IAAII,KAAK;YACP,MAAMK,MAAM,CAAC,0CAA0C,EAAEf,MAAM;YAC/D,IAAI,CAACgB,GAAG,CAAC,CAAC,QAAQ,EAAED,KAAK;YACzB,MAAMnB,KAAKmB;YACX;QACF;QAEA,IAAI;YACF,MAAME,cAAc,MAAM,IAAI,CAACC,cAAc,CAAClB,MAAMO;YAEpD,IAAI,CAACS,GAAG,CAACC;QACX,EAAE,OAAOE,OAAO;YACdtB,gBAAgB,CAAC,4BAA4B,EAAEG,MAAM,EAAEmB;YAEvD,IAAIA,iBAAiBC,YAAYD,MAAME,MAAM,KAAK,KAAK;gBACrD,IAAI,CAACF,KAAK,CAAC,CAAC,iCAAiC,EAAEnB,MAAM,EAAE;oBAACsB,MAAM7B,UAAU8B,aAAa;gBAAA;YACvF;YAEA,IAAI,CAACJ,KAAK,CAAC,yEAAyE;gBAClFG,MAAM7B,UAAU8B,aAAa;YAC/B;QACF;IACF;IAEA,MAAcL,eAAelB,IAAY,EAAEO,MAAc,EAAmB;QAC1E,MAAMQ,MAAM,IAAIS,IAAI,CAAC,uCAAuC,EAAExB,MAAM;QACpEe,IAAIU,YAAY,CAACC,GAAG,CAAC,UAAUnB;QAC/B,MAAMoB,WAAW,MAAMC,MAAMb,KAAK;YAChCc,QAAQC,YAAYC,OAAO,CAAC;QAC9B;QAEA,IAAIJ,SAASK,EAAE,EAAE;YACf,OAAOL,SAASM,IAAI;QACtB;QAEA,MAAMN;IACR;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Flags } from '@oclif/core';
|
|
2
|
-
import { SanityCommand, subdebug } from '@sanity/cli-core';
|
|
2
|
+
import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
|
|
3
3
|
import open from 'open';
|
|
4
4
|
const listOpenapiDebug = subdebug('openapi:list');
|
|
5
5
|
export class ListOpenApiCommand extends SanityCommand {
|
|
@@ -42,7 +42,7 @@ export class ListOpenApiCommand extends SanityCommand {
|
|
|
42
42
|
} catch (error) {
|
|
43
43
|
listOpenapiDebug('Error fetching OpenAPI specs', error);
|
|
44
44
|
this.error('The OpenAPI service is currently unavailable. Please try again later.', {
|
|
45
|
-
exit:
|
|
45
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
if (json) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/openapi/list.ts"],"sourcesContent":["import {Flags} from '@oclif/core'\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\nimport open from 'open'\n\ninterface OpenAPISpec {\n description: string\n slug: string\n title: string\n}\n\nconst listOpenapiDebug = subdebug('openapi:list')\n\nexport class ListOpenApiCommand extends SanityCommand<typeof ListOpenApiCommand> {\n static override description = 'List all available OpenAPI specifications'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'List all available OpenAPI specs',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --json',\n description: 'List with JSON output',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --web',\n description: 'Open HTTP Reference in browser',\n },\n ]\n\n static override flags = {\n json: Flags.boolean({\n description: 'Output JSON',\n }),\n web: Flags.boolean({\n char: 'w',\n description: 'Open HTTP Reference in web browser',\n }),\n }\n\n public async run(): Promise<void> {\n const {flags} = await this.parse(ListOpenApiCommand)\n const {json, web} = flags\n\n if (web) {\n const url = 'https://www.sanity.io/docs/http-reference'\n this.log(`Opening ${url}`)\n await open(url)\n return\n }\n\n let specs: OpenAPISpec[]\n try {\n specs = await this.getSpecs()\n } catch (error) {\n listOpenapiDebug('Error fetching OpenAPI specs', error)\n\n this.error('The OpenAPI service is currently unavailable. Please try again later.', {\n exit:
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/openapi/list.ts"],"sourcesContent":["import {Flags} from '@oclif/core'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport open from 'open'\n\ninterface OpenAPISpec {\n description: string\n slug: string\n title: string\n}\n\nconst listOpenapiDebug = subdebug('openapi:list')\n\nexport class ListOpenApiCommand extends SanityCommand<typeof ListOpenApiCommand> {\n static override description = 'List all available OpenAPI specifications'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'List all available OpenAPI specs',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --json',\n description: 'List with JSON output',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --web',\n description: 'Open HTTP Reference in browser',\n },\n ]\n\n static override flags = {\n json: Flags.boolean({\n description: 'Output JSON',\n }),\n web: Flags.boolean({\n char: 'w',\n description: 'Open HTTP Reference in web browser',\n }),\n }\n\n public async run(): Promise<void> {\n const {flags} = await this.parse(ListOpenApiCommand)\n const {json, web} = flags\n\n if (web) {\n const url = 'https://www.sanity.io/docs/http-reference'\n this.log(`Opening ${url}`)\n await open(url)\n return\n }\n\n let specs: OpenAPISpec[]\n try {\n specs = await this.getSpecs()\n } catch (error) {\n listOpenapiDebug('Error fetching OpenAPI specs', error)\n\n this.error('The OpenAPI service is currently unavailable. Please try again later.', {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.log(JSON.stringify(specs, null, 2))\n return\n }\n\n if (specs.length === 0) {\n this.log('No OpenAPI specifications available.')\n return\n }\n\n // Human-readable table format\n this.log(`\\nFound ${specs.length} OpenAPI specification(s):\\n`)\n\n for (const spec of specs) {\n this.log(`Title: ${spec.title}`)\n this.log(`Slug: ${spec.slug}`)\n if (spec.description) {\n this.log(`Description: ${spec.description}`)\n }\n this.log('')\n }\n\n this.log(`Use 'sanity openapi get <slug>' to retrieve a specific specification.`)\n }\n\n private async getSpecs(): Promise<OpenAPISpec[]> {\n const response = await fetch('https://www.sanity.io/docs/api/openapi', {\n signal: AbortSignal.timeout(10_000),\n })\n\n if (response.ok) {\n const data = await response.json()\n return Array.isArray(data?.specs) ? data.specs : []\n }\n\n throw response\n }\n}\n"],"names":["Flags","exitCodes","SanityCommand","subdebug","open","listOpenapiDebug","ListOpenApiCommand","description","examples","command","flags","json","boolean","web","char","run","parse","url","log","specs","getSpecs","error","exit","RUNTIME_ERROR","JSON","stringify","length","spec","title","slug","response","fetch","signal","AbortSignal","timeout","ok","data","Array","isArray"],"mappings":"AAAA,SAAQA,KAAK,QAAO,cAAa;AACjC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,OAAOC,UAAU,OAAM;AAQvB,MAAMC,mBAAmBF,SAAS;AAElC,OAAO,MAAMG,2BAA2BJ;IACtC,OAAgBK,cAAc,4CAA2C;IAEzE,OAAgBC,WAAW;QACzB;YACEC,SAAS;YACTF,aAAa;QACf;QACA;YACEE,SAAS;YACTF,aAAa;QACf;QACA;YACEE,SAAS;YACTF,aAAa;QACf;KACD,CAAA;IAED,OAAgBG,QAAQ;QACtBC,MAAMX,MAAMY,OAAO,CAAC;YAClBL,aAAa;QACf;QACAM,KAAKb,MAAMY,OAAO,CAAC;YACjBE,MAAM;YACNP,aAAa;QACf;IACF,EAAC;IAED,MAAaQ,MAAqB;QAChC,MAAM,EAACL,KAAK,EAAC,GAAG,MAAM,IAAI,CAACM,KAAK,CAACV;QACjC,MAAM,EAACK,IAAI,EAAEE,GAAG,EAAC,GAAGH;QAEpB,IAAIG,KAAK;YACP,MAAMI,MAAM;YACZ,IAAI,CAACC,GAAG,CAAC,CAAC,QAAQ,EAAED,KAAK;YACzB,MAAMb,KAAKa;YACX;QACF;QAEA,IAAIE;QACJ,IAAI;YACFA,QAAQ,MAAM,IAAI,CAACC,QAAQ;QAC7B,EAAE,OAAOC,OAAO;YACdhB,iBAAiB,gCAAgCgB;YAEjD,IAAI,CAACA,KAAK,CAAC,yEAAyE;gBAClFC,MAAMrB,UAAUsB,aAAa;YAC/B;QACF;QAEA,IAAIZ,MAAM;YACR,IAAI,CAACO,GAAG,CAACM,KAAKC,SAAS,CAACN,OAAO,MAAM;YACrC;QACF;QAEA,IAAIA,MAAMO,MAAM,KAAK,GAAG;YACtB,IAAI,CAACR,GAAG,CAAC;YACT;QACF;QAEA,8BAA8B;QAC9B,IAAI,CAACA,GAAG,CAAC,CAAC,QAAQ,EAAEC,MAAMO,MAAM,CAAC,4BAA4B,CAAC;QAE9D,KAAK,MAAMC,QAAQR,MAAO;YACxB,IAAI,CAACD,GAAG,CAAC,CAAC,OAAO,EAAES,KAAKC,KAAK,EAAE;YAC/B,IAAI,CAACV,GAAG,CAAC,CAAC,MAAM,EAAES,KAAKE,IAAI,EAAE;YAC7B,IAAIF,KAAKpB,WAAW,EAAE;gBACpB,IAAI,CAACW,GAAG,CAAC,CAAC,aAAa,EAAES,KAAKpB,WAAW,EAAE;YAC7C;YACA,IAAI,CAACW,GAAG,CAAC;QACX;QAEA,IAAI,CAACA,GAAG,CAAC,CAAC,qEAAqE,CAAC;IAClF;IAEA,MAAcE,WAAmC;QAC/C,MAAMU,WAAW,MAAMC,MAAM,0CAA0C;YACrEC,QAAQC,YAAYC,OAAO,CAAC;QAC9B;QAEA,IAAIJ,SAASK,EAAE,EAAE;YACf,MAAMC,OAAO,MAAMN,SAASnB,IAAI;YAChC,OAAO0B,MAAMC,OAAO,CAACF,MAAMjB,SAASiB,KAAKjB,KAAK,GAAG,EAAE;QACrD;QAEA,MAAMW;IACR;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Flags } from '@oclif/core';
|
|
2
|
-
import { SanityCommand, subdebug } from '@sanity/cli-core';
|
|
2
|
+
import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
|
|
3
3
|
import { getErrorMessage } from '@sanity/cli-core/errors';
|
|
4
4
|
import { spinner } from '@sanity/cli-core/ux';
|
|
5
5
|
import { validateOrganizationName } from '../../actions/organizations/validateOrganizationName.js';
|
|
@@ -39,14 +39,14 @@ export class CreateOrganizationCommand extends SanityCommand {
|
|
|
39
39
|
const defaultRole = defaultRoleFlag?.trim();
|
|
40
40
|
if (defaultRole === '') {
|
|
41
41
|
this.error('Default role cannot be empty', {
|
|
42
|
-
exit:
|
|
42
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
let name;
|
|
46
46
|
if (nameFlag === undefined) {
|
|
47
47
|
if (this.isUnattended()) {
|
|
48
48
|
this.error('Organization name is required. Provide it with the --name flag.', {
|
|
49
|
-
exit:
|
|
49
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
name = await promptForOrganizationName();
|
|
@@ -55,7 +55,7 @@ export class CreateOrganizationCommand extends SanityCommand {
|
|
|
55
55
|
const validation = validateOrganizationName(trimmedName);
|
|
56
56
|
if (validation !== true) {
|
|
57
57
|
this.error(validation, {
|
|
58
|
-
exit:
|
|
58
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
name = trimmedName;
|
|
@@ -70,7 +70,7 @@ export class CreateOrganizationCommand extends SanityCommand {
|
|
|
70
70
|
spin.fail();
|
|
71
71
|
createOrgDebug('Error creating organization', error);
|
|
72
72
|
this.error(`Failed to create organization: ${getErrorMessage(error)}`, {
|
|
73
|
-
exit:
|
|
73
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/organizations/create.ts"],"sourcesContent":["import {Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {spinner} from '@sanity/cli-core/ux'\n\nimport {validateOrganizationName} from '../../actions/organizations/validateOrganizationName.js'\nimport {promptForOrganizationName} from '../../prompts/promptForOrganizationName.js'\nimport {createOrganization} from '../../services/organizations.js'\nimport {organizationAliases} from '../../util/organizationAliases.js'\n\nconst createOrgDebug = subdebug('organizations:create')\n\nexport class CreateOrganizationCommand extends SanityCommand<typeof CreateOrganizationCommand> {\n static override description = 'Create a new organization'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'Interactively create an organization',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --name \"Acme Corp\"',\n description: 'Create an organization named \"Acme Corp\"',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --name \"Acme Corp\" --default-role member',\n description: 'Create an organization with a default member role',\n },\n ]\n\n static override flags = {\n 'default-role': Flags.string({\n description: 'Default role assigned to new members',\n required: false,\n }),\n name: Flags.string({\n description: 'Organization name',\n required: false,\n }),\n } satisfies FlagInput\n\n static override hiddenAliases = organizationAliases('create')\n\n public async run(): Promise<void> {\n const {'default-role': defaultRoleFlag, name: nameFlag} = this.flags\n\n const defaultRole = defaultRoleFlag?.trim()\n if (defaultRole === '') {\n this.error('Default role cannot be empty', {exit:
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/organizations/create.ts"],"sourcesContent":["import {Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {spinner} from '@sanity/cli-core/ux'\n\nimport {validateOrganizationName} from '../../actions/organizations/validateOrganizationName.js'\nimport {promptForOrganizationName} from '../../prompts/promptForOrganizationName.js'\nimport {createOrganization} from '../../services/organizations.js'\nimport {organizationAliases} from '../../util/organizationAliases.js'\n\nconst createOrgDebug = subdebug('organizations:create')\n\nexport class CreateOrganizationCommand extends SanityCommand<typeof CreateOrganizationCommand> {\n static override description = 'Create a new organization'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'Interactively create an organization',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --name \"Acme Corp\"',\n description: 'Create an organization named \"Acme Corp\"',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --name \"Acme Corp\" --default-role member',\n description: 'Create an organization with a default member role',\n },\n ]\n\n static override flags = {\n 'default-role': Flags.string({\n description: 'Default role assigned to new members',\n required: false,\n }),\n name: Flags.string({\n description: 'Organization name',\n required: false,\n }),\n } satisfies FlagInput\n\n static override hiddenAliases = organizationAliases('create')\n\n public async run(): Promise<void> {\n const {'default-role': defaultRoleFlag, name: nameFlag} = this.flags\n\n const defaultRole = defaultRoleFlag?.trim()\n if (defaultRole === '') {\n this.error('Default role cannot be empty', {exit: exitCodes.RUNTIME_ERROR})\n }\n\n let name: string\n if (nameFlag === undefined) {\n if (this.isUnattended()) {\n this.error('Organization name is required. Provide it with the --name flag.', {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n name = await promptForOrganizationName()\n } else {\n const trimmedName = nameFlag.trim()\n const validation = validateOrganizationName(trimmedName)\n if (validation !== true) {\n this.error(validation, {exit: exitCodes.RUNTIME_ERROR})\n }\n name = trimmedName\n }\n\n const spin = spinner('Creating organization').start()\n try {\n const org = await createOrganization(name, defaultRole)\n spin.succeed('Organization created')\n this.log(`ID: ${org.id}`)\n this.log(`Name: ${org.name}`)\n } catch (error) {\n spin.fail()\n createOrgDebug('Error creating organization', error)\n this.error(`Failed to create organization: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n}\n"],"names":["Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","spinner","validateOrganizationName","promptForOrganizationName","createOrganization","organizationAliases","createOrgDebug","CreateOrganizationCommand","description","examples","command","flags","string","required","name","hiddenAliases","run","defaultRoleFlag","nameFlag","defaultRole","trim","error","exit","RUNTIME_ERROR","undefined","isUnattended","trimmedName","validation","spin","start","org","succeed","log","id","fail"],"mappings":"AAAA,SAAQA,KAAK,QAAO,cAAa;AAEjC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eA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AA;YACvD;YACAT,OAAOY;QACT;QAEA,MAAME,OAAO3B,QAAQ,yBAAyB4B,KAAK;QACnD,IAAI;YACF,MAAMC,MAAM,MAAM1B,mBAAmBU,MAAMK;YAC3CS,KAAKG,OAAO,CAAC;YACb,IAAI,CAACC,GAAG,CAAC,CAAC,MAAM,EAAEF,IAAIG,EAAE,EAAE;YAC1B,IAAI,CAACD,GAAG,CAAC,CAAC,MAAM,EAAEF,IAAIhB,IAAI,EAAE;QAC9B,EAAE,OAAOO,OAAO;YACdO,KAAKM,IAAI;YACT5B,eAAe,+BAA+Be;YAC9C,IAAI,CAACA,KAAK,CAAC,CAAC,+BAA+B,EAAErB,gBAAgBqB,QAAQ,EAAE;gBACrEC,MAAMzB,UAAU0B,aAAa;YAC/B;QACF;IACF;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { styleText } from 'node:util';
|
|
2
2
|
import { Args, Flags } from '@oclif/core';
|
|
3
|
-
import { SanityCommand, subdebug } from '@sanity/cli-core';
|
|
3
|
+
import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
|
|
4
4
|
import { getErrorMessage } from '@sanity/cli-core/errors';
|
|
5
5
|
import { input, logSymbols, spinner } from '@sanity/cli-core/ux';
|
|
6
6
|
import { isHttpError } from '@sanity/client';
|
|
@@ -50,11 +50,11 @@ export class DeleteOrganizationCommand extends SanityCommand {
|
|
|
50
50
|
deleteOrgDebug('Error deleting organization', error);
|
|
51
51
|
if (isHttpError(error) && error.statusCode === 404) {
|
|
52
52
|
this.error(`Organization "${organizationId}" not found`, {
|
|
53
|
-
exit:
|
|
53
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
this.error(`Failed to delete organization: ${getErrorMessage(error)}`, {
|
|
57
|
-
exit:
|
|
57
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -68,11 +68,11 @@ export class DeleteOrganizationCommand extends SanityCommand {
|
|
|
68
68
|
deleteOrgDebug(`Error getting organization ${organizationId}`, err);
|
|
69
69
|
if (isHttpError(error) && error.statusCode === 404) {
|
|
70
70
|
this.error(`Organization "${organizationId}" not found`, {
|
|
71
|
-
exit:
|
|
71
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
this.error(`Organization retrieval failed: ${err.message}`, {
|
|
75
|
-
exit:
|
|
75
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
this.log(styleText('yellow', `${logSymbols.warning} Deleting organization "${styleText([
|
|
@@ -91,7 +91,7 @@ export class DeleteOrganizationCommand extends SanityCommand {
|
|
|
91
91
|
const err = error instanceof Error ? error : new Error(`${error}`);
|
|
92
92
|
deleteOrgDebug(`User cancelled`, err);
|
|
93
93
|
this.error(`User cancelled`, {
|
|
94
|
-
exit:
|
|
94
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/organizations/delete.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {Args, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {input, logSymbols, spinner} from '@sanity/cli-core/ux'\nimport {isHttpError} from '@sanity/client'\n\nimport {deleteOrganization, getOrganization} from '../../services/organizations.js'\nimport {organizationAliases} from '../../util/organizationAliases.js'\n\nconst deleteOrgDebug = subdebug('organizations:delete')\n\nexport class DeleteOrganizationCommand extends SanityCommand<typeof DeleteOrganizationCommand> {\n static override args = {\n organizationId: Args.string({\n description: 'Organization ID to delete',\n required: true,\n }),\n }\n\n static override description = 'Delete an organization'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> org-abc123',\n description: 'Delete an organization (prompts for confirmation)',\n },\n {\n command: '<%= config.bin %> <%= command.id %> org-abc123 --force',\n description: 'Delete an organization without confirmation',\n },\n ]\n\n static override flags = {\n force: Flags.boolean({\n description: 'Do not prompt for delete confirmation - forcefully delete',\n required: false,\n }),\n } satisfies FlagInput\n\n static override hiddenAliases = organizationAliases('delete')\n\n public async run(): Promise<void> {\n const {organizationId} = this.args\n const {force} = this.flags\n\n if (force) {\n this.warn(`'--force' used: skipping confirmation, deleting organization \"${organizationId}\"`)\n } else {\n await this.confirmDeletion(organizationId)\n }\n\n const spin = spinner('Deleting organization').start()\n try {\n await deleteOrganization(organizationId)\n spin.succeed()\n this.log('Organization deleted')\n } catch (error) {\n spin.fail()\n deleteOrgDebug('Error deleting organization', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Organization \"${organizationId}\" not found`, {exit:
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/organizations/delete.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {Args, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {input, logSymbols, spinner} from '@sanity/cli-core/ux'\nimport {isHttpError} from '@sanity/client'\n\nimport {deleteOrganization, getOrganization} from '../../services/organizations.js'\nimport {organizationAliases} from '../../util/organizationAliases.js'\n\nconst deleteOrgDebug = subdebug('organizations:delete')\n\nexport class DeleteOrganizationCommand extends SanityCommand<typeof DeleteOrganizationCommand> {\n static override args = {\n organizationId: Args.string({\n description: 'Organization ID to delete',\n required: true,\n }),\n }\n\n static override description = 'Delete an organization'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> org-abc123',\n description: 'Delete an organization (prompts for confirmation)',\n },\n {\n command: '<%= config.bin %> <%= command.id %> org-abc123 --force',\n description: 'Delete an organization without confirmation',\n },\n ]\n\n static override flags = {\n force: Flags.boolean({\n description: 'Do not prompt for delete confirmation - forcefully delete',\n required: false,\n }),\n } satisfies FlagInput\n\n static override hiddenAliases = organizationAliases('delete')\n\n public async run(): Promise<void> {\n const {organizationId} = this.args\n const {force} = this.flags\n\n if (force) {\n this.warn(`'--force' used: skipping confirmation, deleting organization \"${organizationId}\"`)\n } else {\n await this.confirmDeletion(organizationId)\n }\n\n const spin = spinner('Deleting organization').start()\n try {\n await deleteOrganization(organizationId)\n spin.succeed()\n this.log('Organization deleted')\n } catch (error) {\n spin.fail()\n deleteOrgDebug('Error deleting organization', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Organization \"${organizationId}\" not found`, {exit: exitCodes.RUNTIME_ERROR})\n }\n this.error(`Failed to delete organization: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n\n private async confirmDeletion(organizationId: string): Promise<void> {\n let orgName: string\n try {\n const org = await getOrganization(organizationId)\n orgName = org.name\n } catch (error) {\n const err = error instanceof Error ? error : new Error(`${error}`)\n deleteOrgDebug(`Error getting organization ${organizationId}`, err)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Organization \"${organizationId}\" not found`, {exit: exitCodes.RUNTIME_ERROR})\n }\n this.error(`Organization retrieval failed: ${err.message}`, {exit: exitCodes.RUNTIME_ERROR})\n }\n\n this.log(\n styleText(\n 'yellow',\n `${logSymbols.warning} Deleting organization \"${styleText(['bold', 'underline'], orgName)}\"\\n`,\n ),\n )\n\n try {\n await input({\n message:\n 'Are you ABSOLUTELY sure you want to delete this organization?\\n Type the name of the organization to confirm delete:',\n validate: (value) => {\n const trimmed = value.trim().toLowerCase()\n return (\n trimmed === orgName.trim().toLowerCase() ||\n 'Incorrect organization name. Ctrl + C to cancel delete.'\n )\n },\n })\n } catch (error) {\n const err = error instanceof Error ? error : new Error(`${error}`)\n deleteOrgDebug(`User cancelled`, err)\n this.error(`User cancelled`, {exit: exitCodes.RUNTIME_ERROR})\n }\n }\n}\n"],"names":["styleText","Args","Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","input","logSymbols","spinner","isHttpError","deleteOrganization","getOrganization","organizationAliases","deleteOrgDebug","DeleteOrganizationCommand","args","organizationId","string","description","required","examples","command","flags","force","boolean","hiddenAliases","run","warn","confirmDeletion","spin","start","succeed","log","error","fail","statusCode","exit","RUNTIME_ERROR","orgName","org","name","err","Error","message","warning","validate","value","trimmed","trim","toLowerCase"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AAEvC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,KAAK,EAAEC,UAAU,EAAEC,OAAO,QAAO,sBAAqB;AAC9D,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,kBAAkB,EAAEC,eAAe,QAAO,kCAAiC;AACnF,SAAQC,mBAAmB,QAAO,oCAAmC;AAErE,MAAMC,iBAAiBT,SAAS;AAEhC,OAAO,MAAMU,kCAAkCX;IAC7C,OAAgBY,OAAO;QACrBC,gBAAgBhB,KAAKiB,MAAM,CAAC;YAC1BC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,yBAAwB;IAEtD,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;KACD,CAAA;IAED,OAAgBI,QAAQ;QACtBC,OAAOtB,MAAMuB,OAAO,CAAC;YACnBN,aAAa;YACbC,UAAU;QACZ;IACF,EAAqB;IAErB,OAAgBM,gBAAgBb,oBAAoB,UAAS;IAE7D,MAAac,MAAqB;QAChC,MAAM,EAACV,cAAc,EAAC,GAAG,IAAI,CAACD,IAAI;QAClC,MAAM,EAACQ,KAAK,EAAC,GAAG,IAAI,CAACD,KAAK;QAE1B,IAAIC,OAAO;YACT,IAAI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,GAAGQ,WAAWqC,OAAO,CAAC,wBAAwB,EAAE7C,UAAU;YAAC;YAAQ;SAAY,EAAEuC,SAAS,GAAG,CAAC;QAIlG,IAAI;YACF,MAAMhC,MAAM;gBACVqC,SACE;gBACFE,UAAU,CAACC;oBACT,MAAMC,UAAUD,MAAME,IAAI,GAAGC,WAAW;oBACxC,OACEF,YAAYT,QAAQU,IAAI,GAAGC,WAAW,MACtC;gBAEJ;YACF;QACF,EAAE,OAAOhB,OAAO;YACd,MAAMQ,MAAMR,iBAAiBS,QAAQT,QAAQ,IAAIS,MAAM,GAAGT,OAAO;YACjEpB,eAAe,CAAC,cAAc,CAAC,EAAE4B;YACjC,IAAI,CAACR,KAAK,CAAC,CAAC,cAAc,CAAC,EAAE;gBAACG,MAAMlC,UAAUmC,aAAa;YAAA;QAC7D;IACF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Args } from '@oclif/core';
|
|
2
|
-
import { SanityCommand, subdebug } from '@sanity/cli-core';
|
|
2
|
+
import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
|
|
3
3
|
import { getErrorMessage } from '@sanity/cli-core/errors';
|
|
4
4
|
import { isHttpError } from '@sanity/client';
|
|
5
5
|
import { getOrganization } from '../../services/organizations.js';
|
|
@@ -29,11 +29,11 @@ export class GetOrganizationCommand extends SanityCommand {
|
|
|
29
29
|
getOrgDebug('Error getting organization', error);
|
|
30
30
|
if (isHttpError(error) && error.statusCode === 404) {
|
|
31
31
|
this.error(`Organization "${organizationId}" not found`, {
|
|
32
|
-
exit:
|
|
32
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
this.error(`Failed to get organization: ${getErrorMessage(error)}`, {
|
|
36
|
-
exit:
|
|
36
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
this.log(`ID: ${org.id}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/organizations/get.ts"],"sourcesContent":["import {Args} from '@oclif/core'\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {isHttpError} from '@sanity/client'\n\nimport {getOrganization} from '../../services/organizations.js'\nimport {organizationAliases} from '../../util/organizationAliases.js'\n\nconst getOrgDebug = subdebug('organizations:get')\n\nexport class GetOrganizationCommand extends SanityCommand<typeof GetOrganizationCommand> {\n static override args = {\n organizationId: Args.string({\n description: 'Organization ID',\n required: true,\n }),\n }\n\n static override description = 'Get details of an organization'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> org-abc123',\n description: 'Get details of a specific organization',\n },\n ]\n\n static override hiddenAliases = organizationAliases('get')\n\n public async run(): Promise<void> {\n const {organizationId} = this.args\n\n let org\n try {\n org = await getOrganization(organizationId)\n } catch (error) {\n getOrgDebug('Error getting organization', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Organization \"${organizationId}\" not found`, {exit:
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/organizations/get.ts"],"sourcesContent":["import {Args} from '@oclif/core'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {isHttpError} from '@sanity/client'\n\nimport {getOrganization} from '../../services/organizations.js'\nimport {organizationAliases} from '../../util/organizationAliases.js'\n\nconst getOrgDebug = subdebug('organizations:get')\n\nexport class GetOrganizationCommand extends SanityCommand<typeof GetOrganizationCommand> {\n static override args = {\n organizationId: Args.string({\n description: 'Organization ID',\n required: true,\n }),\n }\n\n static override description = 'Get details of an organization'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> org-abc123',\n description: 'Get details of a specific organization',\n },\n ]\n\n static override hiddenAliases = organizationAliases('get')\n\n public async run(): Promise<void> {\n const {organizationId} = this.args\n\n let org\n try {\n org = await getOrganization(organizationId)\n } catch (error) {\n getOrgDebug('Error getting organization', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Organization \"${organizationId}\" not found`, {exit: exitCodes.RUNTIME_ERROR})\n }\n this.error(`Failed to get organization: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n this.log(`ID: ${org.id}`)\n this.log(`Name: ${org.name}`)\n this.log(`Slug: ${org.slug ?? '-'}`)\n this.log(`Default role: ${org.defaultRoleName ?? '-'}`)\n this.log(`Created: ${org.createdAt}`)\n this.log(`Updated: ${org.updatedAt}`)\n }\n}\n"],"names":["Args","exitCodes","SanityCommand","subdebug","getErrorMessage","isHttpError","getOrganization","organizationAliases","getOrgDebug","GetOrganizationCommand","args","organizationId","string","description","required","examples","command","hiddenAliases","run","org","error","statusCode","exit","RUNTIME_ERROR","log","id","name","slug","defaultRoleName","createdAt","updatedAt"],"mappings":"AAAA,SAAQA,IAAI,QAAO,cAAa;AAChC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,eAAe,QAAO,kCAAiC;AAC/D,SAAQC,mBAAmB,QAAO,oCAAmC;AAErE,MAAMC,cAAcL,SAAS;AAE7B,OAAO,MAAMM,+BAA+BP;IAC1C,OAAgBQ,OAAO;QACrBC,gBAAgBX,KAAKY,MAAM,CAAC;YAC1BC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,iCAAgC;IAE9D,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;KACD,CAAA;IAED,OAAgBI,gBAAgBV,oBAAoB,OAAM;IAE1D,MAAaW,MAAqB;QAChC,MAAM,EAACP,cAAc,EAAC,GAAG,IAAI,CAACD,IAAI;QAElC,IAAIS;QACJ,IAAI;YACFA,MAAM,MAAMb,gBAAgBK;QAC9B,EAAE,OAAOS,OAAO;YACdZ,YAAY,8BAA8BY;YAC1C,IAAIf,YAAYe,UAAUA,MAAMC,UAAU,KAAK,KAAK;gBAClD,IAAI,CAACD,KAAK,CAAC,CAAC,cAAc,EAAET,eAAe,WAAW,CAAC,EAAE;oBAACW,MAAMrB,UAAUsB,aAAa;gBAAA;YACzF;YACA,IAAI,CAACH,KAAK,CAAC,CAAC,4BAA4B,EAAEhB,gBAAgBgB,QAAQ,EAAE;gBAClEE,MAAMrB,UAAUsB,aAAa;YAC/B;QACF;QAEA,IAAI,CAACC,GAAG,CAAC,CAAC,cAAc,EAAEL,IAAIM,EAAE,EAAE;QAClC,IAAI,CAACD,GAAG,CAAC,CAAC,cAAc,EAAEL,IAAIO,IAAI,EAAE;QACpC,IAAI,CAACF,GAAG,CAAC,CAAC,cAAc,EAAEL,IAAIQ,IAAI,IAAI,KAAK;QAC3C,IAAI,CAACH,GAAG,CAAC,CAAC,cAAc,EAAEL,IAAIS,eAAe,IAAI,KAAK;QACtD,IAAI,CAACJ,GAAG,CAAC,CAAC,cAAc,EAAEL,IAAIU,SAAS,EAAE;QACzC,IAAI,CAACL,GAAG,CAAC,CAAC,cAAc,EAAEL,IAAIW,SAAS,EAAE;IAC3C;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SanityCommand, subdebug } from '@sanity/cli-core';
|
|
1
|
+
import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
|
|
2
2
|
import { getErrorMessage } from '@sanity/cli-core/errors';
|
|
3
3
|
import { Table } from 'console-table-printer';
|
|
4
4
|
import { listOrganizations } from '../../services/organizations.js';
|
|
@@ -20,7 +20,7 @@ export class ListOrganizationsCommand extends SanityCommand {
|
|
|
20
20
|
} catch (error) {
|
|
21
21
|
listOrgsDebug('Error listing organizations', error);
|
|
22
22
|
this.error(`Failed to list organizations: ${getErrorMessage(error)}`, {
|
|
23
|
-
exit:
|
|
23
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
if (organizations.length === 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/organizations/list.ts"],"sourcesContent":["import {SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {Table} from 'console-table-printer'\n\nimport {listOrganizations} from '../../services/organizations.js'\nimport {organizationAliases} from '../../util/organizationAliases.js'\n\nconst listOrgsDebug = subdebug('organizations:list')\n\nexport class ListOrganizationsCommand extends SanityCommand<typeof ListOrganizationsCommand> {\n static override description = 'List organizations you are a member of'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'List all your organizations',\n },\n ]\n\n static override hiddenAliases = organizationAliases('list')\n\n public async run(): Promise<void> {\n let organizations\n try {\n organizations = await listOrganizations()\n } catch (error) {\n listOrgsDebug('Error listing organizations', error)\n this.error(`Failed to list organizations: ${getErrorMessage(error)}`, {exit:
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/organizations/list.ts"],"sourcesContent":["import {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {Table} from 'console-table-printer'\n\nimport {listOrganizations} from '../../services/organizations.js'\nimport {organizationAliases} from '../../util/organizationAliases.js'\n\nconst listOrgsDebug = subdebug('organizations:list')\n\nexport class ListOrganizationsCommand extends SanityCommand<typeof ListOrganizationsCommand> {\n static override description = 'List organizations you are a member of'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'List all your organizations',\n },\n ]\n\n static override hiddenAliases = organizationAliases('list')\n\n public async run(): Promise<void> {\n let organizations\n try {\n organizations = await listOrganizations()\n } catch (error) {\n listOrgsDebug('Error listing organizations', error)\n this.error(`Failed to list organizations: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (organizations.length === 0) {\n this.log('No organizations found')\n return\n }\n\n const table = new Table({\n columns: [\n {alignment: 'left', name: 'id', title: 'ID'},\n {alignment: 'left', name: 'name', title: 'Name'},\n {alignment: 'left', name: 'slug', title: 'Slug'},\n ],\n })\n\n for (const {id, name, slug} of organizations) {\n table.addRow({id, name, slug: slug ?? '-'})\n }\n\n table.printTable()\n }\n}\n"],"names":["exitCodes","SanityCommand","subdebug","getErrorMessage","Table","listOrganizations","organizationAliases","listOrgsDebug","ListOrganizationsCommand","description","examples","command","hiddenAliases","run","organizations","error","exit","RUNTIME_ERROR","length","log","table","columns","alignment","name","title","id","slug","addRow","printTable"],"mappings":"AAAA,SAAQA,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,KAAK,QAAO,wBAAuB;AAE3C,SAAQC,iBAAiB,QAAO,kCAAiC;AACjE,SAAQC,mBAAmB,QAAO,oCAAmC;AAErE,MAAMC,gBAAgBL,SAAS;AAE/B,OAAO,MAAMM,iCAAiCP;IAC5C,OAAgBQ,cAAc,yCAAwC;IAEtE,OAAgBC,WAAW;QACzB;YACEC,SAAS;YACTF,aAAa;QACf;KACD,CAAA;IAED,OAAgBG,gBAAgBN,oBAAoB,QAAO;IAE3D,MAAaO,MAAqB;QAChC,IAAIC;QACJ,IAAI;YACFA,gBAAgB,MAAMT;QACxB,EAAE,OAAOU,OAAO;YACdR,cAAc,+BAA+BQ;YAC7C,IAAI,CAACA,KAAK,CAAC,CAAC,8BAA8B,EAAEZ,gBAAgBY,QAAQ,EAAE;gBACpEC,MAAMhB,UAAUiB,aAAa;YAC/B;QACF;QAEA,IAAIH,cAAcI,MAAM,KAAK,GAAG;YAC9B,IAAI,CAACC,GAAG,CAAC;YACT;QACF;QAEA,MAAMC,QAAQ,IAAIhB,MAAM;YACtBiB,SAAS;gBACP;oBAACC,WAAW;oBAAQC,MAAM;oBAAMC,OAAO;gBAAI;gBAC3C;oBAACF,WAAW;oBAAQC,MAAM;oBAAQC,OAAO;gBAAM;gBAC/C;oBAACF,WAAW;oBAAQC,MAAM;oBAAQC,OAAO;gBAAM;aAChD;QACH;QAEA,KAAK,MAAM,EAACC,EAAE,EAAEF,IAAI,EAAEG,IAAI,EAAC,IAAIZ,cAAe;YAC5CM,MAAMO,MAAM,CAAC;gBAACF;gBAAIF;gBAAMG,MAAMA,QAAQ;YAAG;QAC3C;QAEAN,MAAMQ,UAAU;IAClB;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Args, Flags } from '@oclif/core';
|
|
2
|
-
import { SanityCommand, subdebug } from '@sanity/cli-core';
|
|
2
|
+
import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
|
|
3
3
|
import { getErrorMessage } from '@sanity/cli-core/errors';
|
|
4
4
|
import { spinner } from '@sanity/cli-core/ux';
|
|
5
5
|
import { isHttpError } from '@sanity/client';
|
|
@@ -68,7 +68,7 @@ export class UpdateOrganizationCommand extends SanityCommand {
|
|
|
68
68
|
const validation = validateOrganizationName(trimmedName);
|
|
69
69
|
if (validation !== true) {
|
|
70
70
|
this.error(validation, {
|
|
71
|
-
exit:
|
|
71
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
params.name = trimmedName;
|
|
@@ -78,7 +78,7 @@ export class UpdateOrganizationCommand extends SanityCommand {
|
|
|
78
78
|
const slugValidation = validateOrganizationSlug(trimmedSlug);
|
|
79
79
|
if (slugValidation !== true) {
|
|
80
80
|
this.error(slugValidation, {
|
|
81
|
-
exit:
|
|
81
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
84
|
params.slug = trimmedSlug;
|
|
@@ -87,7 +87,7 @@ export class UpdateOrganizationCommand extends SanityCommand {
|
|
|
87
87
|
const trimmedRole = defaultRole.trim();
|
|
88
88
|
if (trimmedRole === '') {
|
|
89
89
|
this.error('Default role cannot be empty', {
|
|
90
|
-
exit:
|
|
90
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
93
|
params.defaultRoleName = trimmedRole;
|
|
@@ -102,11 +102,11 @@ export class UpdateOrganizationCommand extends SanityCommand {
|
|
|
102
102
|
updateOrgDebug('Error updating organization', error);
|
|
103
103
|
if (isHttpError(error) && error.statusCode === 404) {
|
|
104
104
|
this.error(`Organization "${organizationId}" not found`, {
|
|
105
|
-
exit:
|
|
105
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
this.error(`Failed to update organization: ${getErrorMessage(error)}`, {
|
|
109
|
-
exit:
|
|
109
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/organizations/update.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {isHttpError} from '@sanity/client'\n\nimport {validateOrganizationName} from '../../actions/organizations/validateOrganizationName.js'\nimport {validateOrganizationSlug} from '../../actions/organizations/validateOrganizationSlug.js'\nimport {type OrganizationUpdateParams, updateOrganization} from '../../services/organizations.js'\nimport {organizationAliases} from '../../util/organizationAliases.js'\n\nconst updateOrgDebug = subdebug('organizations:update')\n\nconst UPDATE_FLAGS = ['name', 'slug', 'default-role'] as const\n\nexport class UpdateOrganizationCommand extends SanityCommand<typeof UpdateOrganizationCommand> {\n static override args = {\n organizationId: Args.string({\n description: 'Organization ID',\n required: true,\n }),\n }\n\n static override description = 'Update an organization'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> org-abc123 --name \"New Name\"',\n description: 'Rename an organization',\n },\n {\n command: '<%= config.bin %> <%= command.id %> org-abc123 --slug new-slug',\n description: 'Set the organization slug (requires authSAML feature)',\n },\n {\n command: '<%= config.bin %> <%= command.id %> org-abc123 --default-role viewer',\n description: 'Change the default member role',\n },\n ]\n\n static override flags = {\n 'default-role': Flags.string({\n atLeastOne: [...UPDATE_FLAGS],\n description: 'New default role for new members',\n required: false,\n }),\n name: Flags.string({\n atLeastOne: [...UPDATE_FLAGS],\n description: 'New organization name',\n required: false,\n }),\n slug: Flags.string({\n atLeastOne: [...UPDATE_FLAGS],\n description: 'New URL slug (requires authSAML feature on the organization)',\n required: false,\n }),\n } satisfies FlagInput\n\n static override hiddenAliases = organizationAliases('update')\n\n public async run(): Promise<void> {\n const {organizationId} = this.args\n const {'default-role': defaultRole, name, slug} = this.flags\n\n const params: OrganizationUpdateParams = {}\n if (name !== undefined) {\n const trimmedName = name.trim()\n const validation = validateOrganizationName(trimmedName)\n if (validation !== true) {\n this.error(validation, {exit:
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/organizations/update.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {isHttpError} from '@sanity/client'\n\nimport {validateOrganizationName} from '../../actions/organizations/validateOrganizationName.js'\nimport {validateOrganizationSlug} from '../../actions/organizations/validateOrganizationSlug.js'\nimport {type OrganizationUpdateParams, updateOrganization} from '../../services/organizations.js'\nimport {organizationAliases} from '../../util/organizationAliases.js'\n\nconst updateOrgDebug = subdebug('organizations:update')\n\nconst UPDATE_FLAGS = ['name', 'slug', 'default-role'] as const\n\nexport class UpdateOrganizationCommand extends SanityCommand<typeof UpdateOrganizationCommand> {\n static override args = {\n organizationId: Args.string({\n description: 'Organization ID',\n required: true,\n }),\n }\n\n static override description = 'Update an organization'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> org-abc123 --name \"New Name\"',\n description: 'Rename an organization',\n },\n {\n command: '<%= config.bin %> <%= command.id %> org-abc123 --slug new-slug',\n description: 'Set the organization slug (requires authSAML feature)',\n },\n {\n command: '<%= config.bin %> <%= command.id %> org-abc123 --default-role viewer',\n description: 'Change the default member role',\n },\n ]\n\n static override flags = {\n 'default-role': Flags.string({\n atLeastOne: [...UPDATE_FLAGS],\n description: 'New default role for new members',\n required: false,\n }),\n name: Flags.string({\n atLeastOne: [...UPDATE_FLAGS],\n description: 'New organization name',\n required: false,\n }),\n slug: Flags.string({\n atLeastOne: [...UPDATE_FLAGS],\n description: 'New URL slug (requires authSAML feature on the organization)',\n required: false,\n }),\n } satisfies FlagInput\n\n static override hiddenAliases = organizationAliases('update')\n\n public async run(): Promise<void> {\n const {organizationId} = this.args\n const {'default-role': defaultRole, name, slug} = this.flags\n\n const params: OrganizationUpdateParams = {}\n if (name !== undefined) {\n const trimmedName = name.trim()\n const validation = validateOrganizationName(trimmedName)\n if (validation !== true) {\n this.error(validation, {exit: exitCodes.RUNTIME_ERROR})\n }\n params.name = trimmedName\n }\n if (slug !== undefined) {\n const trimmedSlug = slug.trim()\n const slugValidation = validateOrganizationSlug(trimmedSlug)\n if (slugValidation !== true) {\n this.error(slugValidation, {exit: exitCodes.RUNTIME_ERROR})\n }\n params.slug = trimmedSlug\n }\n if (defaultRole !== undefined) {\n const trimmedRole = defaultRole.trim()\n if (trimmedRole === '') {\n this.error('Default role cannot be empty', {exit: exitCodes.RUNTIME_ERROR})\n }\n params.defaultRoleName = trimmedRole\n }\n\n const spin = spinner('Updating organization').start()\n try {\n await updateOrganization(organizationId, params)\n spin.succeed()\n this.log('Organization updated')\n } catch (error) {\n spin.fail()\n updateOrgDebug('Error updating organization', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Organization \"${organizationId}\" not found`, {exit: exitCodes.RUNTIME_ERROR})\n }\n this.error(`Failed to update organization: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n}\n"],"names":["Args","Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","spinner","isHttpError","validateOrganizationName","validateOrganizationSlug","updateOrganization","organizationAliases","updateOrgDebug","UPDATE_FLAGS","UpdateOrganizationCommand","args","organizationId","string","description","required","examples","command","flags","atLeastOne","name","slug","hiddenAliases","run","defaultRole","params","undefined","trimmedName","trim","validation","error","exit","RUNTIME_ERROR","trimmedSlug","slugValidation","trimmedRole","defaultRoleName","spin","start","succeed","log","fail","statusCode"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AAEvC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,wBAAwB,QAAO,0DAAyD;AAChG,SAAQC,wBAAwB,QAAO,0DAAyD;AAChG,SAAuCC,kBAAkB,QAAO,kCAAiC;AACjG,SAAQC,mBAAmB,QAAO,oCAAmC;AAErE,MAAMC,iBAAiBR,SAAS;AAEhC,MAAMS,eAAe;IAAC;IAAQ;IAAQ;CAAe;AAErD,OAAO,MAAMC,kCAAkCX;IAC7C,OAAgBY,OAAO;QACrBC,gBAAgBhB,KAAKiB,MAAM,CAAC;YAC1BC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,yBAAwB;IAEtD,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;KACD,CAAA;IAED,OAAgBI,QAAQ;QACtB,gBAAgBrB,MAAMgB,MAAM,CAAC;YAC3BM,YAAY;mBAAIV;aAAa;YAC7BK,aAAa;YACbC,UAAU;QACZ;QACAK,MAAMvB,MAAMgB,MAAM,CAAC;YACjBM,YAAY;mBAAIV;aAAa;YAC7BK,aAAa;YACbC,UAAU;QACZ;QACAM,MAAMxB,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,YAAY2B,UAAUA,MAAMY,UAAU,KAAK,KAAK;gBAClD,IAAI,CAACZ,KAAK,CAAC,CAAC,cAAc,EAAElB,eAAe,WAAW,CAAC,EAAE;oBAACmB,MAAMjC,UAAUkC,aAAa;gBAAA;YACzF;YACA,IAAI,CAACF,KAAK,CAAC,CAAC,+BAA+B,EAAE7B,gBAAgB6B,QAAQ,EAAE;gBACrEC,MAAMjC,UAAUkC,aAAa;YAC/B;QACF;IACF;AACF"}
|
package/dist/commands/preview.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { Args, Flags } from '@oclif/core';
|
|
3
|
-
import { SanityCommand, subdebug } from '@sanity/cli-core';
|
|
3
|
+
import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
|
|
4
4
|
import { previewAction } from '../actions/preview/previewAction.js';
|
|
5
5
|
export const previewDebug = subdebug('preview');
|
|
6
6
|
export class PreviewCommand extends SanityCommand {
|
|
@@ -49,7 +49,7 @@ export class PreviewCommand extends SanityCommand {
|
|
|
49
49
|
] : undefined;
|
|
50
50
|
const message = error instanceof Error ? error.message : String(error);
|
|
51
51
|
this.output.error(`Failed to start preview server: ${message}`, {
|
|
52
|
-
exit:
|
|
52
|
+
exit: exitCodes.RUNTIME_ERROR,
|
|
53
53
|
suggestions
|
|
54
54
|
});
|
|
55
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/preview.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {Args, Flags} from '@oclif/core'\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\n\nimport {previewAction} from '../actions/preview/previewAction.js'\nimport {type PreviewServer} from '../server/previewServer.js'\n\nexport const previewDebug = subdebug('preview')\n\nexport class PreviewCommand extends SanityCommand<typeof PreviewCommand> {\n static override args = {\n outputDir: Args.directory({description: 'Output directory'}),\n }\n\n static override deprecateAliases = true\n\n static override description = 'Start a local server to preview a production build'\n\n static override examples = [\n '<%= config.bin %> <%= command.id %> --host=0.0.0.0',\n '<%= config.bin %> <%= command.id %> --port=1942',\n '<%= config.bin %> <%= command.id %> some/build-output-dir',\n ]\n\n static override flags = {\n host: Flags.string({\n description: 'Local network interface to listen on (default: localhost)',\n }),\n port: Flags.string({\n description: 'TCP port to start server on (default: 3333)',\n }),\n }\n static override hiddenAliases: string[] = ['start']\n\n public async run(): Promise<PreviewServer | {close: () => Promise<void>} | void> {\n const {args, flags} = await this.parse(PreviewCommand)\n\n const workDir = (await this.getProjectRoot()).directory\n const cliConfig = await this.getCliConfig()\n\n const {outputDir} = args\n\n const defaultRootDir = path.resolve(path.join(workDir, 'dist'))\n const outDir = path.resolve(outputDir || defaultRootDir)\n\n try {\n return await previewAction({cliConfig, flags, outDir, output: this.output, workDir})\n } catch (error: unknown) {\n const suggestions =\n error instanceof Error && error.name === 'BUILD_NOT_FOUND'\n ? [\n '`sanity build` to create a production build',\n '`sanity dev` to run a development server',\n ]\n : undefined\n\n const message = error instanceof Error ? error.message : String(error)\n this.output.error(`Failed to start preview server: ${message}`, {\n exit:
|
|
1
|
+
{"version":3,"sources":["../../src/commands/preview.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {Args, Flags} from '@oclif/core'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\n\nimport {previewAction} from '../actions/preview/previewAction.js'\nimport {type PreviewServer} from '../server/previewServer.js'\n\nexport const previewDebug = subdebug('preview')\n\nexport class PreviewCommand extends SanityCommand<typeof PreviewCommand> {\n static override args = {\n outputDir: Args.directory({description: 'Output directory'}),\n }\n\n static override deprecateAliases = true\n\n static override description = 'Start a local server to preview a production build'\n\n static override examples = [\n '<%= config.bin %> <%= command.id %> --host=0.0.0.0',\n '<%= config.bin %> <%= command.id %> --port=1942',\n '<%= config.bin %> <%= command.id %> some/build-output-dir',\n ]\n\n static override flags = {\n host: Flags.string({\n description: 'Local network interface to listen on (default: localhost)',\n }),\n port: Flags.string({\n description: 'TCP port to start server on (default: 3333)',\n }),\n }\n static override hiddenAliases: string[] = ['start']\n\n public async run(): Promise<PreviewServer | {close: () => Promise<void>} | void> {\n const {args, flags} = await this.parse(PreviewCommand)\n\n const workDir = (await this.getProjectRoot()).directory\n const cliConfig = await this.getCliConfig()\n\n const {outputDir} = args\n\n const defaultRootDir = path.resolve(path.join(workDir, 'dist'))\n const outDir = path.resolve(outputDir || defaultRootDir)\n\n try {\n return await previewAction({cliConfig, flags, outDir, output: this.output, workDir})\n } catch (error: unknown) {\n const suggestions =\n error instanceof Error && error.name === 'BUILD_NOT_FOUND'\n ? [\n '`sanity build` to create a production build',\n '`sanity dev` to run a development server',\n ]\n : undefined\n\n const message = error instanceof Error ? error.message : String(error)\n this.output.error(`Failed to start preview server: ${message}`, {\n exit: exitCodes.RUNTIME_ERROR,\n suggestions,\n })\n }\n }\n}\n"],"names":["path","Args","Flags","exitCodes","SanityCommand","subdebug","previewAction","previewDebug","PreviewCommand","args","outputDir","directory","description","deprecateAliases","examples","flags","host","string","port","hiddenAliases","run","parse","workDir","getProjectRoot","cliConfig","getCliConfig","defaultRootDir","resolve","join","outDir","output","error","suggestions","Error","name","undefined","message","String","exit","RUNTIME_ERROR"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AAEnE,SAAQC,aAAa,QAAO,sCAAqC;AAGjE,OAAO,MAAMC,eAAeF,SAAS,WAAU;AAE/C,OAAO,MAAMG,uBAAuBJ;IAClC,OAAgBK,OAAO;QACrBC,WAAWT,KAAKU,SAAS,CAAC;YAACC,aAAa;QAAkB;IAC5D,EAAC;IAED,OAAgBC,mBAAmB,KAAI;IAEvC,OAAgBD,cAAc,qDAAoD;IAElF,OAAgBE,WAAW;QACzB;QACA;QACA;KACD,CAAA;IAED,OAAgBC,QAAQ;QACtBC,MAAMd,MAAMe,MAAM,CAAC;YACjBL,aAAa;QACf;QACAM,MAAMhB,MAAMe,MAAM,CAAC;YACjBL,aAAa;QACf;IACF,EAAC;IACD,OAAgBO,gBAA0B;QAAC;KAAQ,CAAA;IAEnD,MAAaC,MAAoE;QAC/E,MAAM,EAACX,IAAI,EAAEM,KAAK,EAAC,GAAG,MAAM,IAAI,CAACM,KAAK,CAACb;QAEvC,MAAMc,UAAU,AAAC,CAAA,MAAM,IAAI,CAACC,cAAc,EAAC,EAAGZ,SAAS;QACvD,MAAMa,YAAY,MAAM,IAAI,CAACC,YAAY;QAEzC,MAAM,EAACf,SAAS,EAAC,GAAGD;QAEpB,MAAMiB,iBAAiB1B,KAAK2B,OAAO,CAAC3B,KAAK4B,IAAI,CAACN,SAAS;QACvD,MAAMO,SAAS7B,KAAK2B,OAAO,CAACjB,aAAagB;QAEzC,IAAI;YACF,OAAO,MAAMpB,cAAc;gBAACkB;gBAAWT;gBAAOc;gBAAQC,QAAQ,IAAI,CAACA,MAAM;gBAAER;YAAO;QACpF,EAAE,OAAOS,OAAgB;YACvB,MAAMC,cACJD,iBAAiBE,SAASF,MAAMG,IAAI,KAAK,oBACrC;gBACE;gBACA;aACD,GACDC;YAEN,MAAMC,UAAUL,iBAAiBE,QAAQF,MAAMK,OAAO,GAAGC,OAAON;YAChE,IAAI,CAACD,MAAM,CAACC,KAAK,CAAC,CAAC,gCAAgC,EAAEK,SAAS,EAAE;gBAC9DE,MAAMnC,UAAUoC,aAAa;gBAC7BP;YACF;QACF;IACF;AACF"}
|
|
@@ -107,7 +107,7 @@ export class CreateProjectCommand extends SanityCommand {
|
|
|
107
107
|
} catch (error) {
|
|
108
108
|
const errorText = organization ? `Failed to retrieve organization ${organization}` : 'Failed to retrieve an organization';
|
|
109
109
|
return this.output.error(`${errorText}: ${error}`, {
|
|
110
|
-
exit:
|
|
110
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
113
|
const spin = spinner('Creating project').start();
|
|
@@ -125,7 +125,7 @@ export class CreateProjectCommand extends SanityCommand {
|
|
|
125
125
|
spin.fail();
|
|
126
126
|
debug(`Failed to create project: ${error}`);
|
|
127
127
|
return this.output.error(`Failed to create project: ${error}`, {
|
|
128
|
-
exit:
|
|
128
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
131
|
let newDataset;
|