@sanity/cli 6.1.8 → 6.2.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 +105 -103
- package/dist/actions/debug/gatherDebugInfo.js +130 -81
- package/dist/actions/debug/gatherDebugInfo.js.map +1 -1
- package/dist/actions/debug/output.js +25 -0
- package/dist/actions/debug/output.js.map +1 -0
- package/dist/actions/debug/types.js.map +1 -1
- package/dist/actions/mcp/setupMCP.js +5 -5
- package/dist/actions/mcp/setupMCP.js.map +1 -1
- package/dist/actions/schema/getExtractOptions.js.map +1 -1
- package/dist/commands/{backup → backups}/disable.js +3 -0
- package/dist/commands/backups/disable.js.map +1 -0
- package/dist/commands/{backup → backups}/download.js +3 -0
- package/dist/commands/backups/download.js.map +1 -0
- package/dist/commands/{backup → backups}/enable.js +3 -0
- package/dist/commands/backups/enable.js.map +1 -0
- package/dist/commands/{backup → backups}/list.js +3 -0
- package/dist/commands/backups/list.js.map +1 -0
- package/dist/commands/{dataset → datasets}/alias/create.js +3 -0
- package/dist/commands/datasets/alias/create.js.map +1 -0
- package/dist/commands/{dataset → datasets}/alias/delete.js +3 -0
- package/dist/commands/datasets/alias/delete.js.map +1 -0
- package/dist/commands/{dataset → datasets}/alias/link.js +3 -0
- package/dist/commands/datasets/alias/link.js.map +1 -0
- package/dist/commands/{dataset → datasets}/alias/unlink.js +3 -0
- package/dist/commands/datasets/alias/unlink.js.map +1 -0
- package/dist/commands/{dataset → datasets}/copy.js +3 -0
- package/dist/commands/datasets/copy.js.map +1 -0
- package/dist/commands/{dataset → datasets}/create.js +3 -0
- package/dist/commands/datasets/create.js.map +1 -0
- package/dist/commands/{dataset → datasets}/delete.js +3 -0
- package/dist/commands/datasets/delete.js.map +1 -0
- package/dist/commands/{dataset → datasets}/embeddings/disable.js +3 -0
- package/dist/commands/datasets/embeddings/disable.js.map +1 -0
- package/dist/commands/{dataset → datasets}/embeddings/enable.js +3 -0
- package/dist/commands/datasets/embeddings/enable.js.map +1 -0
- package/dist/commands/{dataset → datasets}/embeddings/status.js +3 -0
- package/dist/commands/datasets/embeddings/status.js.map +1 -0
- package/dist/commands/{dataset → datasets}/export.js +3 -0
- package/dist/commands/datasets/export.js.map +1 -0
- package/dist/commands/{dataset → datasets}/import.js +3 -0
- package/dist/commands/datasets/import.js.map +1 -0
- package/dist/commands/{dataset → datasets}/list.js +3 -0
- package/dist/commands/datasets/list.js.map +1 -0
- package/dist/commands/{dataset → datasets}/visibility/get.js +3 -0
- package/dist/commands/datasets/visibility/get.js.map +1 -0
- package/dist/commands/{dataset → datasets}/visibility/set.js +3 -0
- package/dist/commands/datasets/visibility/set.js.map +1 -0
- package/dist/commands/debug.js +189 -74
- package/dist/commands/debug.js.map +1 -1
- package/dist/commands/documents/create.js +3 -0
- package/dist/commands/documents/create.js.map +1 -1
- package/dist/commands/documents/delete.js +3 -0
- package/dist/commands/documents/delete.js.map +1 -1
- package/dist/commands/documents/get.js +3 -0
- package/dist/commands/documents/get.js.map +1 -1
- package/dist/commands/documents/query.js +3 -0
- package/dist/commands/documents/query.js.map +1 -1
- package/dist/commands/documents/validate.js +3 -0
- package/dist/commands/documents/validate.js.map +1 -1
- package/dist/commands/{hook → hooks}/attempt.js +3 -0
- package/dist/commands/hooks/attempt.js.map +1 -0
- package/dist/commands/{hook → hooks}/create.js +3 -0
- package/dist/commands/hooks/create.js.map +1 -0
- package/dist/commands/{hook → hooks}/delete.js +3 -0
- package/dist/commands/hooks/delete.js.map +1 -0
- package/dist/commands/{hook → hooks}/list.js +3 -0
- package/dist/commands/hooks/list.js.map +1 -0
- package/dist/commands/{hook → hooks}/logs.js +3 -0
- package/dist/commands/hooks/logs.js.map +1 -0
- package/dist/commands/init.js +65 -13
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/mcp/configure.js +3 -2
- package/dist/commands/mcp/configure.js.map +1 -1
- package/dist/commands/preview.js +1 -0
- package/dist/commands/preview.js.map +1 -1
- package/dist/commands/projects/create.js +3 -0
- package/dist/commands/projects/create.js.map +1 -1
- package/dist/commands/projects/list.js +3 -0
- package/dist/commands/projects/list.js.map +1 -1
- package/dist/commands/{schema → schemas}/delete.js +3 -0
- package/dist/commands/schemas/delete.js.map +1 -0
- package/dist/commands/{schema → schemas}/deploy.js +3 -0
- package/dist/commands/schemas/deploy.js.map +1 -0
- package/dist/commands/{schema → schemas}/extract.js +3 -0
- package/dist/commands/schemas/extract.js.map +1 -0
- package/dist/commands/{schema → schemas}/list.js +3 -0
- package/dist/commands/schemas/list.js.map +1 -0
- package/dist/commands/{schema → schemas}/validate.js +3 -0
- package/dist/commands/schemas/validate.js.map +1 -0
- package/dist/commands/tokens/add.js +3 -0
- package/dist/commands/tokens/add.js.map +1 -1
- package/dist/commands/tokens/delete.js +3 -0
- package/dist/commands/tokens/delete.js.map +1 -1
- package/dist/commands/tokens/list.js +3 -0
- package/dist/commands/tokens/list.js.map +1 -1
- package/dist/commands/users/invite.js +3 -0
- package/dist/commands/users/invite.js.map +1 -1
- package/dist/commands/users/list.js +3 -0
- package/dist/commands/users/list.js.map +1 -1
- package/dist/hooks/commandNotFound/topicAliases.js +71 -0
- package/dist/hooks/commandNotFound/topicAliases.js.map +1 -0
- package/dist/topicAliases.js +51 -0
- package/dist/topicAliases.js.map +1 -0
- package/oclif.config.js +20 -7
- package/oclif.manifest.json +471 -359
- package/package.json +5 -4
- package/dist/actions/debug/formatters.js +0 -22
- package/dist/actions/debug/formatters.js.map +0 -1
- package/dist/actions/debug/getGlobalConfigLocation.js +0 -7
- package/dist/actions/debug/getGlobalConfigLocation.js.map +0 -1
- package/dist/commands/backup/disable.js.map +0 -1
- package/dist/commands/backup/download.js.map +0 -1
- package/dist/commands/backup/enable.js.map +0 -1
- package/dist/commands/backup/list.js.map +0 -1
- package/dist/commands/dataset/alias/create.js.map +0 -1
- package/dist/commands/dataset/alias/delete.js.map +0 -1
- package/dist/commands/dataset/alias/link.js.map +0 -1
- package/dist/commands/dataset/alias/unlink.js.map +0 -1
- package/dist/commands/dataset/copy.js.map +0 -1
- package/dist/commands/dataset/create.js.map +0 -1
- package/dist/commands/dataset/delete.js.map +0 -1
- package/dist/commands/dataset/embeddings/disable.js.map +0 -1
- package/dist/commands/dataset/embeddings/enable.js.map +0 -1
- package/dist/commands/dataset/embeddings/status.js.map +0 -1
- package/dist/commands/dataset/export.js.map +0 -1
- package/dist/commands/dataset/import.js.map +0 -1
- package/dist/commands/dataset/list.js.map +0 -1
- package/dist/commands/dataset/visibility/get.js.map +0 -1
- package/dist/commands/dataset/visibility/set.js.map +0 -1
- package/dist/commands/hook/attempt.js.map +0 -1
- package/dist/commands/hook/create.js.map +0 -1
- package/dist/commands/hook/delete.js.map +0 -1
- package/dist/commands/hook/list.js.map +0 -1
- package/dist/commands/hook/logs.js.map +0 -1
- package/dist/commands/schema/delete.js.map +0 -1
- package/dist/commands/schema/deploy.js.map +0 -1
- package/dist/commands/schema/extract.js.map +0 -1
- package/dist/commands/schema/list.js.map +0 -1
- package/dist/commands/schema/validate.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/documents/query.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {colorizeJson, getProjectCliClient, SanityCommand, subdebug} from '@sanity/cli-core'\n\nimport {DOCUMENTS_API_VERSION} from '../../actions/documents/constants.js'\nimport {promptForProject} from '../../prompts/promptForProject.js'\nimport {getDatasetFlag, getProjectIdFlag} from '../../util/sharedFlags.js'\n\nconst queryDocumentDebug = subdebug('documents:query')\n\nexport class QueryDocumentCommand extends SanityCommand<typeof QueryDocumentCommand> {\n static override args = {\n query: Args.string({\n description: 'GROQ query to run against the dataset',\n required: true,\n }),\n }\n\n static override description = 'Query for documents'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> \\'*[_type == \"movie\"][0..4]\\'',\n description: 'Fetch 5 documents of type \"movie\"',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> \\'*[_type == \"movie\"]|order(releaseDate asc)[0]{title}\\' --dataset staging',\n description: 'Fetch title of the oldest movie in the dataset named \"staging\"',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> \\'*[_id == \"header\"] { \"headerText\": pt::text(body) }\\' --api-version v2021-06-07',\n description: 'Use API version v2021-06-07 and do a query',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> \\'*[_type == \"post\"]\\' --project-id abc123 --dataset production',\n description: 'Query documents in a specific project and dataset',\n },\n ]\n\n static override flags = {\n ...getProjectIdFlag({description: 'Project ID to query', semantics: 'override'}),\n ...getDatasetFlag({description: 'Dataset to query', semantics: 'override'}),\n anonymous: Flags.boolean({\n default: false,\n description: 'Send the query without any authorization token',\n }),\n 'api-version': Flags.string({\n description: `API version to use (defaults to ${DOCUMENTS_API_VERSION})`,\n env: 'SANITY_CLI_QUERY_API_VERSION',\n }),\n pretty: Flags.boolean({\n default: false,\n description: 'Colorize JSON output',\n }),\n project: Flags.string({\n deprecated: {to: 'project-id'},\n description: 'Project ID to query',\n hidden: true,\n }),\n }\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(QueryDocumentCommand)\n const {query} = args\n const {anonymous, 'api-version': apiVersion, dataset, pretty} = flags\n\n const cliConfig = await this.tryGetCliConfig()\n\n const projectId = await this.getProjectId({\n deprecatedFlagName: 'project',\n fallback: () => promptForProject({}),\n })\n\n const requireUser = !anonymous\n\n if (!cliConfig.api?.dataset && !dataset) {\n this.error(\n 'No dataset specified. Either configure a dataset in sanity.cli.ts or use the --dataset flag',\n {exit: 1},\n )\n }\n\n const targetDataset = dataset || cliConfig.api?.dataset\n const targetApiVersion = apiVersion || DOCUMENTS_API_VERSION\n\n if (!apiVersion) {\n this.warn(`--api-version not specified, using \\`${DOCUMENTS_API_VERSION}\\``)\n }\n\n try {\n const projectClient = await getProjectCliClient({\n apiVersion: targetApiVersion,\n dataset: targetDataset,\n projectId,\n requireUser,\n })\n\n const docs = await projectClient.fetch(query)\n\n if (!docs) {\n this.error('Query returned no results', {exit: 1})\n }\n\n // Output the query results\n if (pretty) {\n this.log(colorizeJson(docs))\n } else {\n this.log(JSON.stringify(docs, null, 2))\n }\n } catch (error) {\n const err = error as Error\n\n queryDocumentDebug(`Error running query: ${query}`, err)\n\n // Provide more context in error messages\n const errorMsg = err.message.toLowerCase().includes('syntax')\n ? `Invalid GROQ query syntax: ${err.message}`\n : `Failed to run query: ${err.message}`\n\n this.error(`${errorMsg}\\nQuery: ${query}`, {exit: 1})\n }\n }\n}\n"],"names":["Args","Flags","colorizeJson","getProjectCliClient","SanityCommand","subdebug","DOCUMENTS_API_VERSION","promptForProject","getDatasetFlag","getProjectIdFlag","queryDocumentDebug","QueryDocumentCommand","args","query","string","description","required","examples","command","flags","semantics","anonymous","boolean","default","env","pretty","project","deprecated","to","hidden","run","parse","apiVersion","dataset","cliConfig","tryGetCliConfig","projectId","getProjectId","deprecatedFlagName","fallback","requireUser","api","error","exit","targetDataset","targetApiVersion","warn","projectClient","docs","fetch","log","JSON","stringify","err","errorMsg","message","toLowerCase","includes"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,YAAY,EAAEC,mBAAmB,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AAE3F,SAAQC,qBAAqB,QAAO,uCAAsC;AAC1E,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,cAAc,EAAEC,gBAAgB,QAAO,4BAA2B;AAE1E,MAAMC,qBAAqBL,SAAS;AAEpC,OAAO,MAAMM,6BAA6BP;IACxC,OAAgBQ,OAAO;QACrBC,OAAOb,KAAKc,MAAM,CAAC;YACjBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,sBAAqB;IAEnD,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SACE;YACFH,aAAa;QACf;QACA;YACEG,SACE;YACFH,aAAa;QACf;QACA;YACEG,SACE;YACFH,aAAa;QACf;KACD,CAAA;IAED,OAAgBI,QAAQ;QACtB,GAAGV,iBAAiB;YAACM,aAAa;YAAuBK,WAAW;QAAU,EAAE;QAChF,GAAGZ,eAAe;YAACO,aAAa;YAAoBK,WAAW;QAAU,EAAE;QAC3EC,WAAWpB,MAAMqB,OAAO,CAAC;YACvBC,SAAS;YACTR,aAAa;QACf;QACA,eAAed,MAAMa,MAAM,CAAC;YAC1BC,aAAa,CAAC,gCAAgC,EAAET,sBAAsB,CAAC,CAAC;YACxEkB,KAAK;QACP;QACAC,QAAQxB,MAAMqB,OAAO,CAAC;YACpBC,SAAS;YACTR,aAAa;QACf;QACAW,SAASzB,MAAMa,MAAM,CAAC;YACpBa,YAAY;gBAACC,IAAI;YAAY;YAC7Bb,aAAa;YACbc,QAAQ;QACV;IACF,EAAC;IAED,MAAaC,MAAqB;QAChC,MAAM,
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/documents/query.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {colorizeJson, getProjectCliClient, SanityCommand, subdebug} from '@sanity/cli-core'\n\nimport {DOCUMENTS_API_VERSION} from '../../actions/documents/constants.js'\nimport {promptForProject} from '../../prompts/promptForProject.js'\nimport {getDatasetFlag, getProjectIdFlag} from '../../util/sharedFlags.js'\n\nconst queryDocumentDebug = subdebug('documents:query')\n\nexport class QueryDocumentCommand extends SanityCommand<typeof QueryDocumentCommand> {\n static override args = {\n query: Args.string({\n description: 'GROQ query to run against the dataset',\n required: true,\n }),\n }\n\n static override description = 'Query for documents'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> \\'*[_type == \"movie\"][0..4]\\'',\n description: 'Fetch 5 documents of type \"movie\"',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> \\'*[_type == \"movie\"]|order(releaseDate asc)[0]{title}\\' --dataset staging',\n description: 'Fetch title of the oldest movie in the dataset named \"staging\"',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> \\'*[_id == \"header\"] { \"headerText\": pt::text(body) }\\' --api-version v2021-06-07',\n description: 'Use API version v2021-06-07 and do a query',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> \\'*[_type == \"post\"]\\' --project-id abc123 --dataset production',\n description: 'Query documents in a specific project and dataset',\n },\n ]\n\n static override flags = {\n ...getProjectIdFlag({description: 'Project ID to query', semantics: 'override'}),\n ...getDatasetFlag({description: 'Dataset to query', semantics: 'override'}),\n anonymous: Flags.boolean({\n default: false,\n description: 'Send the query without any authorization token',\n }),\n 'api-version': Flags.string({\n description: `API version to use (defaults to ${DOCUMENTS_API_VERSION})`,\n env: 'SANITY_CLI_QUERY_API_VERSION',\n }),\n pretty: Flags.boolean({\n default: false,\n description: 'Colorize JSON output',\n }),\n project: Flags.string({\n deprecated: {to: 'project-id'},\n description: 'Project ID to query',\n hidden: true,\n }),\n }\n\n static override hiddenAliases: string[] = ['document:query']\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(QueryDocumentCommand)\n const {query} = args\n const {anonymous, 'api-version': apiVersion, dataset, pretty} = flags\n\n const cliConfig = await this.tryGetCliConfig()\n\n const projectId = await this.getProjectId({\n deprecatedFlagName: 'project',\n fallback: () => promptForProject({}),\n })\n\n const requireUser = !anonymous\n\n if (!cliConfig.api?.dataset && !dataset) {\n this.error(\n 'No dataset specified. Either configure a dataset in sanity.cli.ts or use the --dataset flag',\n {exit: 1},\n )\n }\n\n const targetDataset = dataset || cliConfig.api?.dataset\n const targetApiVersion = apiVersion || DOCUMENTS_API_VERSION\n\n if (!apiVersion) {\n this.warn(`--api-version not specified, using \\`${DOCUMENTS_API_VERSION}\\``)\n }\n\n try {\n const projectClient = await getProjectCliClient({\n apiVersion: targetApiVersion,\n dataset: targetDataset,\n projectId,\n requireUser,\n })\n\n const docs = await projectClient.fetch(query)\n\n if (!docs) {\n this.error('Query returned no results', {exit: 1})\n }\n\n // Output the query results\n if (pretty) {\n this.log(colorizeJson(docs))\n } else {\n this.log(JSON.stringify(docs, null, 2))\n }\n } catch (error) {\n const err = error as Error\n\n queryDocumentDebug(`Error running query: ${query}`, err)\n\n // Provide more context in error messages\n const errorMsg = err.message.toLowerCase().includes('syntax')\n ? `Invalid GROQ query syntax: ${err.message}`\n : `Failed to run query: ${err.message}`\n\n this.error(`${errorMsg}\\nQuery: ${query}`, {exit: 1})\n }\n }\n}\n"],"names":["Args","Flags","colorizeJson","getProjectCliClient","SanityCommand","subdebug","DOCUMENTS_API_VERSION","promptForProject","getDatasetFlag","getProjectIdFlag","queryDocumentDebug","QueryDocumentCommand","args","query","string","description","required","examples","command","flags","semantics","anonymous","boolean","default","env","pretty","project","deprecated","to","hidden","hiddenAliases","run","parse","apiVersion","dataset","cliConfig","tryGetCliConfig","projectId","getProjectId","deprecatedFlagName","fallback","requireUser","api","error","exit","targetDataset","targetApiVersion","warn","projectClient","docs","fetch","log","JSON","stringify","err","errorMsg","message","toLowerCase","includes"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,YAAY,EAAEC,mBAAmB,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AAE3F,SAAQC,qBAAqB,QAAO,uCAAsC;AAC1E,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,cAAc,EAAEC,gBAAgB,QAAO,4BAA2B;AAE1E,MAAMC,qBAAqBL,SAAS;AAEpC,OAAO,MAAMM,6BAA6BP;IACxC,OAAgBQ,OAAO;QACrBC,OAAOb,KAAKc,MAAM,CAAC;YACjBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,sBAAqB;IAEnD,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SACE;YACFH,aAAa;QACf;QACA;YACEG,SACE;YACFH,aAAa;QACf;QACA;YACEG,SACE;YACFH,aAAa;QACf;KACD,CAAA;IAED,OAAgBI,QAAQ;QACtB,GAAGV,iBAAiB;YAACM,aAAa;YAAuBK,WAAW;QAAU,E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ZZ,SAASW;gBACTR;gBACAI;YACF;YAEA,MAAMQ,OAAO,MAAMD,cAAcE,KAAK,CAACrC;YAEvC,IAAI,CAACoC,MAAM;gBACT,IAAI,CAACN,KAAK,CAAC,6BAA6B;oBAACC,MAAM;gBAAC;YAClD;YAEA,2BAA2B;YAC3B,IAAInB,QAAQ;gBACV,IAAI,CAAC0B,GAAG,CAACjD,aAAa+C;YACxB,OAAO;gBACL,IAAI,CAACE,GAAG,CAACC,KAAKC,SAAS,CAACJ,MAAM,MAAM;YACtC;QACF,EAAE,OAAON,OAAO;YACd,MAAMW,MAAMX;YAEZjC,mBAAmB,CAAC,qBAAqB,EAAEG,OAAO,EAAEyC;YAEpD,yCAAyC;YACzC,MAAMC,WAAWD,IAAIE,OAAO,CAACC,WAAW,GAAGC,QAAQ,CAAC,YAChD,CAAC,2BAA2B,EAAEJ,IAAIE,OAAO,EAAE,GAC3C,CAAC,qBAAqB,EAAEF,IAAIE,OAAO,EAAE;YAEzC,IAAI,CAACb,KAAK,CAAC,GAAGY,SAAS,SAAS,EAAE1C,OAAO,EAAE;gBAAC+B,MAAM;YAAC;QACrD;IACF;AACF"}
|
|
@@ -72,6 +72,9 @@ export class ValidateDocumentsCommand extends SanityCommand {
|
|
|
72
72
|
description: 'Skips the first confirmation prompt'
|
|
73
73
|
})
|
|
74
74
|
};
|
|
75
|
+
static hiddenAliases = [
|
|
76
|
+
'document:validate'
|
|
77
|
+
];
|
|
75
78
|
async run() {
|
|
76
79
|
const { flags } = await this.parse(ValidateDocumentsCommand);
|
|
77
80
|
const { dataset, file, format, level, 'max-custom-validation-concurrency': maxCustomValidationConcurrency, 'max-fetch-concurrency': maxFetchConcurrency, 'project-id': projectId, workspace } = flags;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/documents/validate.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {Flags} from '@oclif/core'\nimport {type CliConfig, ProjectRootNotFoundError, SanityCommand} from '@sanity/cli-core'\nimport {confirm, logSymbols} from '@sanity/cli-core/ux'\n\nimport {type Level} from '../../actions/documents/types.js'\nimport {validateDocuments} from '../../actions/documents/validate.js'\nimport {reporters} from '../../actions/documents/validation/reporters/index.js'\nimport {getDatasetFlag, getProjectIdFlag} from '../../util/sharedFlags.js'\n\nexport class ValidateDocumentsCommand extends SanityCommand<typeof ValidateDocumentsCommand> {\n static description = 'Validate documents in a dataset against the studio schema'\n\n static examples = [\n {\n command: '<%= config.bin %> <%= command.id %> --workspace default',\n description: 'Validates all documents in a Sanity project with more than one workspace',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --workspace default --dataset staging',\n description: 'Override the dataset specified in the workspace',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --yes > report.txt',\n description: 'Save the results of the report into a file',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --level info',\n description: 'Report out info level validation markers too',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --project-id abc123 --dataset production',\n description: 'Validate documents in a specific project and dataset',\n },\n ]\n\n static flags = {\n ...getProjectIdFlag({\n description:\n 'Override the project ID used. By default, this is derived from the given workspace',\n semantics: 'specify',\n }),\n ...getDatasetFlag({\n description:\n 'Override the dataset used. By default, this is derived from the given workspace',\n semantics: 'specify',\n }),\n file: Flags.string({\n description:\n 'Provide a path to either an .ndjson file or a tarball containing an .ndjson file',\n }),\n format: Flags.string({\n description:\n 'The output format used to print the found validation markers and report progress',\n }),\n level: Flags.custom<Level>({\n default: 'warning',\n description: 'The minimum level reported. Defaults to warning',\n options: ['error', 'warning', 'info'],\n })(),\n 'max-custom-validation-concurrency': Flags.integer({\n default: 5,\n description: 'Specify how many custom validators can run concurrently',\n }),\n 'max-fetch-concurrency': Flags.integer({\n default: 25,\n description: 'Specify how many `client.fetch` requests are allowed to run concurrently',\n }),\n workspace: Flags.string({\n description: 'The name of the workspace to use when downloading and validating all documents',\n }),\n yes: Flags.boolean({\n char: 'y',\n default: false,\n description: 'Skips the first confirmation prompt',\n }),\n }\n\n public async run(): Promise<void> {\n const {flags} = await this.parse(ValidateDocumentsCommand)\n const {\n dataset,\n file,\n format,\n level,\n 'max-custom-validation-concurrency': maxCustomValidationConcurrency,\n 'max-fetch-concurrency': maxFetchConcurrency,\n 'project-id': projectId,\n workspace,\n } = flags\n const unattendedMode = Boolean(flags.yes)\n\n let workDir: string\n let cliConfig: CliConfig\n try {\n const root = await this.getProjectRoot()\n workDir = root.directory\n cliConfig = await this.getCliConfig()\n } catch (err) {\n if (err instanceof ProjectRootNotFoundError) {\n this.error(\n 'This command must be run from within a Sanity project directory (requires studio schema for validation)',\n {exit: 1},\n )\n }\n throw err\n }\n\n if (!unattendedMode) {\n this.log(\n `${styleText('yellow', `${logSymbols.warning} Warning:`)} This command ${\n file\n ? 'reads all documents from your input file'\n : 'downloads all documents from your dataset'\n } and processes them through your local schema within a ` +\n `simulated browser environment.\\n`,\n )\n this.log(`Potential pitfalls:\\n`)\n this.log(\n `- Processes all documents locally (excluding assets). Large datasets may require more resources.`,\n )\n this.log(\n `- Executes all custom validation functions. Some functions may need to be refactored for compatibility.`,\n )\n this.log(\n `- Not all standard browser features are available and may cause issues while loading your Studio.`,\n )\n this.log(\n `- Adheres to document permissions. Ensure this account can see all desired documents.`,\n )\n if (file) {\n this.log(\n `- Checks for missing document references against the live dataset if not found in your file.`,\n )\n }\n\n const confirmed = await confirm({\n default: true,\n message: `Are you sure you want to continue?`,\n })\n\n if (!confirmed) {\n this.error('User aborted', {exit: 1})\n }\n }\n\n if (format && !(format in reporters)) {\n const formatter = new Intl.ListFormat('en-US', {\n style: 'long',\n type: 'conjunction',\n })\n this.error(\n `Did not recognize format '${format}'. Available formats are ${formatter.format(\n Object.keys(reporters).map((key) => `'${key}'`),\n )}`,\n {exit: 1},\n )\n }\n\n let ndjsonFilePath\n if (file) {\n const filePath = path.resolve(workDir, file)\n\n const stat = await fs.promises.stat(filePath)\n if (!stat.isFile()) {\n this.error(`'--file' must point to a valid ndjson file or tarball`, {exit: 1})\n }\n\n ndjsonFilePath = filePath\n }\n\n try {\n const overallLevel = await validateDocuments({\n dataset,\n level,\n maxCustomValidationConcurrency,\n maxFetchConcurrency,\n ndjsonFilePath,\n projectId,\n reporter: (worker) => {\n const reporter =\n format && format in reporters\n ? reporters[format as keyof typeof reporters]\n : reporters.pretty\n\n return reporter({flags, output: this.output, worker})\n },\n studioHost: cliConfig.studioHost,\n workDir,\n workspace,\n })\n\n if (overallLevel === 'error') {\n this.exit(1)\n }\n } catch (err) {\n this.error(err instanceof Error ? err.message : String(err), {exit: 1})\n }\n }\n}\n"],"names":["fs","path","styleText","Flags","ProjectRootNotFoundError","SanityCommand","confirm","logSymbols","validateDocuments","reporters","getDatasetFlag","getProjectIdFlag","ValidateDocumentsCommand","description","examples","command","flags","semantics","file","string","format","level","custom","default","options","integer","workspace","yes","boolean","char","run","parse","dataset","maxCustomValidationConcurrency","maxFetchConcurrency","projectId","unattendedMode","Boolean","workDir","cliConfig","root","getProjectRoot","directory","getCliConfig","err","error","exit","log","warning","confirmed","message","formatter","Intl","ListFormat","style","type","Object","keys","map","key","ndjsonFilePath","filePath","resolve","stat","promises","isFile","overallLevel","reporter","worker","pretty","output","studioHost","Error","String"],"mappings":"AAAA,OAAOA,QAAQ,UAAS;AACxB,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAQC,KAAK,QAAO,cAAa;AACjC,SAAwBC,wBAAwB,EAAEC,aAAa,QAAO,mBAAkB;AACxF,SAAQC,OAAO,EAAEC,UAAU,QAAO,sBAAqB;AAGvD,SAAQC,iBAAiB,QAAO,sCAAqC;AACrE,SAAQC,SAAS,QAAO,wDAAuD;AAC/E,SAAQC,cAAc,EAAEC,gBAAgB,QAAO,4BAA2B;AAE1E,OAAO,MAAMC,iCAAiCP;IAC5C,OAAOQ,cAAc,4DAA2D;IAEhF,OAAOC,WAAW;QAChB;YACEC,SAAS;YACTF,aAAa;QACf;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5D,KAAK6D,OAAO,CAACxB,SAASpB;YAEvC,MAAM6C,OAAO,MAAM/D,GAAGgE,QAAQ,CAACD,IAAI,CAACF;YACpC,IAAI,CAACE,KAAKE,MAAM,IAAI;gBAClB,IAAI,CAACpB,KAAK,CAAC,CAAC,qDAAqD,CAAC,EAAE;oBAACC,MAAM;gBAAC;YAC9E;YAEAc,iBAAiBC;QACnB;QAEA,IAAI;YACF,MAAMK,eAAe,MAAM1D,kBAAkB;gBAC3CwB;gBACAX;gBACAY;gBACAC;gBACA0B;gBACAzB;gBACAgC,UAAU,CAACC;oBACT,MAAMD,WACJ/C,UAAUA,UAAUX,YAChBA,SAAS,CAACW,OAAiC,GAC3CX,UAAU4D,MAAM;oBAEtB,OAAOF,SAAS;wBAACnD;wBAAOsD,QAAQ,IAAI,CAACA,MAAM;wBAAEF;oBAAM;gBACrD;gBACAG,YAAYhC,UAAUgC,UAAU;gBAChCjC;gBACAZ;YACF;YAEA,IAAIwC,iBAAiB,SAAS;gBAC5B,IAAI,CAACpB,IAAI,CAAC;YACZ;QACF,EAAE,OAAOF,KAAK;YACZ,IAAI,CAACC,KAAK,CAACD,eAAe4B,QAAQ5B,IAAIM,OAAO,GAAGuB,OAAO7B,MAAM;gBAACE,MAAM;YAAC;QACvE;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/documents/validate.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {Flags} from '@oclif/core'\nimport {type CliConfig, ProjectRootNotFoundError, SanityCommand} from '@sanity/cli-core'\nimport {confirm, logSymbols} from '@sanity/cli-core/ux'\n\nimport {type Level} from '../../actions/documents/types.js'\nimport {validateDocuments} from '../../actions/documents/validate.js'\nimport {reporters} from '../../actions/documents/validation/reporters/index.js'\nimport {getDatasetFlag, getProjectIdFlag} from '../../util/sharedFlags.js'\n\nexport class ValidateDocumentsCommand extends SanityCommand<typeof ValidateDocumentsCommand> {\n static description = 'Validate documents in a dataset against the studio schema'\n\n static examples = [\n {\n command: '<%= config.bin %> <%= command.id %> --workspace default',\n description: 'Validates all documents in a Sanity project with more than one workspace',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --workspace default --dataset staging',\n description: 'Override the dataset specified in the workspace',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --yes > report.txt',\n description: 'Save the results of the report into a file',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --level info',\n description: 'Report out info level validation markers too',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --project-id abc123 --dataset production',\n description: 'Validate documents in a specific project and dataset',\n },\n ]\n\n static flags = {\n ...getProjectIdFlag({\n description:\n 'Override the project ID used. By default, this is derived from the given workspace',\n semantics: 'specify',\n }),\n ...getDatasetFlag({\n description:\n 'Override the dataset used. By default, this is derived from the given workspace',\n semantics: 'specify',\n }),\n file: Flags.string({\n description:\n 'Provide a path to either an .ndjson file or a tarball containing an .ndjson file',\n }),\n format: Flags.string({\n description:\n 'The output format used to print the found validation markers and report progress',\n }),\n level: Flags.custom<Level>({\n default: 'warning',\n description: 'The minimum level reported. Defaults to warning',\n options: ['error', 'warning', 'info'],\n })(),\n 'max-custom-validation-concurrency': Flags.integer({\n default: 5,\n description: 'Specify how many custom validators can run concurrently',\n }),\n 'max-fetch-concurrency': Flags.integer({\n default: 25,\n description: 'Specify how many `client.fetch` requests are allowed to run concurrently',\n }),\n workspace: Flags.string({\n description: 'The name of the workspace to use when downloading and validating all documents',\n }),\n yes: Flags.boolean({\n char: 'y',\n default: false,\n description: 'Skips the first confirmation prompt',\n }),\n }\n\n static override hiddenAliases: string[] = ['document:validate']\n\n public async run(): Promise<void> {\n const {flags} = await this.parse(ValidateDocumentsCommand)\n const {\n dataset,\n file,\n format,\n level,\n 'max-custom-validation-concurrency': maxCustomValidationConcurrency,\n 'max-fetch-concurrency': maxFetchConcurrency,\n 'project-id': projectId,\n workspace,\n } = flags\n const unattendedMode = Boolean(flags.yes)\n\n let workDir: string\n let cliConfig: CliConfig\n try {\n const root = await this.getProjectRoot()\n workDir = root.directory\n cliConfig = await this.getCliConfig()\n } catch (err) {\n if (err instanceof ProjectRootNotFoundError) {\n this.error(\n 'This command must be run from within a Sanity project directory (requires studio schema for validation)',\n {exit: 1},\n )\n }\n throw err\n }\n\n if (!unattendedMode) {\n this.log(\n `${styleText('yellow', `${logSymbols.warning} Warning:`)} This command ${\n file\n ? 'reads all documents from your input file'\n : 'downloads all documents from your dataset'\n } and processes them through your local schema within a ` +\n `simulated browser environment.\\n`,\n )\n this.log(`Potential pitfalls:\\n`)\n this.log(\n `- Processes all documents locally (excluding assets). Large datasets may require more resources.`,\n )\n this.log(\n `- Executes all custom validation functions. Some functions may need to be refactored for compatibility.`,\n )\n this.log(\n `- Not all standard browser features are available and may cause issues while loading your Studio.`,\n )\n this.log(\n `- Adheres to document permissions. Ensure this account can see all desired documents.`,\n )\n if (file) {\n this.log(\n `- Checks for missing document references against the live dataset if not found in your file.`,\n )\n }\n\n const confirmed = await confirm({\n default: true,\n message: `Are you sure you want to continue?`,\n })\n\n if (!confirmed) {\n this.error('User aborted', {exit: 1})\n }\n }\n\n if (format && !(format in reporters)) {\n const formatter = new Intl.ListFormat('en-US', {\n style: 'long',\n type: 'conjunction',\n })\n this.error(\n `Did not recognize format '${format}'. Available formats are ${formatter.format(\n Object.keys(reporters).map((key) => `'${key}'`),\n )}`,\n {exit: 1},\n )\n }\n\n let ndjsonFilePath\n if (file) {\n const filePath = path.resolve(workDir, file)\n\n const stat = await fs.promises.stat(filePath)\n if (!stat.isFile()) {\n this.error(`'--file' must point to a valid ndjson file or tarball`, {exit: 1})\n }\n\n ndjsonFilePath = filePath\n }\n\n try {\n const overallLevel = await validateDocuments({\n dataset,\n level,\n maxCustomValidationConcurrency,\n maxFetchConcurrency,\n ndjsonFilePath,\n projectId,\n reporter: (worker) => {\n const reporter =\n format && format in reporters\n ? reporters[format as keyof typeof reporters]\n : reporters.pretty\n\n return reporter({flags, output: this.output, worker})\n },\n studioHost: cliConfig.studioHost,\n workDir,\n workspace,\n })\n\n if (overallLevel === 'error') {\n this.exit(1)\n }\n } catch (err) {\n this.error(err instanceof Error ? err.message : String(err), {exit: 1})\n }\n }\n}\n"],"names":["fs","path","styleText","Flags","ProjectRootNotFoundError","SanityCommand","confirm","logSymbols","validateDocuments","reporters","getDatasetFlag","getProjectIdFlag","ValidateDocumentsCommand","description","examples","command","flags","semantics","file","string","format","level","custom","default","options","integer","workspace","yes","boolean","char","hiddenAliases","run","parse","dataset","maxCustomValidationConcurrency","maxFetchConcurrency","projectId","unattendedMode","Boolean","workDir","cliConfig","root","getProjectRoot","directory","getCliConfig","err","error","exit","log","warning","confirmed","message","formatter","Intl","ListFormat","style","type","Object","keys","map","key","ndjsonFilePath","filePath","resolve","stat","promises","isFile","overallLevel","reporter","worker","pretty","output","studioHost","Error","String"],"mappings":"AAAA,OAAOA,QAAQ,UAAS;AACxB,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAQC,KAAK,QAAO,cAAa;AACjC,SAAwBC,wBAAwB,EAAEC,aAAa,QAAO,mBAAkB;AACxF,SAAQC,OAAO,EAAEC,UAAU,QAAO,sBAAqB;AAGvD,SAAQC,iBAAiB,QAAO,sCAAqC;AACrE,SAAQC,SAAS,QAAO,wDAAuD;AAC/E,SAAQC,cAAc,EAAEC,gBAAgB,QAAO,4BAA2B;AAE1E,OAAO,MAAMC,iCAAiCP;IAC5C,OAAOQ,cAAc,4DAA2D;IAEhF,OAAOC,WAAW;QAChB;YACEC,SAAS;YACTF,aAAa;QACf;QACA;YACEE,SAAS;YACTF,aAAa;QACf;QACA;YACEE,SAAS;YACTF,aAAa;QACf;QACA;YACEE,SAAS;YACTF,aAAa;QACf;QACA;YACEE,SAAS;YACTF,aAAa;QACf;KACD,CAAA;IAED,OAAOG,QAAQ;QACb,GAAGL,iBAAiB;YAClBE,aACE;YACFI,WAAW;QACb,EAAE;QACF,GAAGP,eAAe;YAChBG,a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AAM;gBAAC;YAC9E;YAEAc,iBAAiBC;QACnB;QAEA,IAAI;YACF,MAAMK,eAAe,MAAM3D,kBAAkB;gBAC3CyB;gBACAZ;gBACAa;gBACAC;gBACA0B;gBACAzB;gBACAgC,UAAU,CAACC;oBACT,MAAMD,WACJhD,UAAUA,UAAUX,YAChBA,SAAS,CAACW,OAAiC,GAC3CX,UAAU6D,MAAM;oBAEtB,OAAOF,SAAS;wBAACpD;wBAAOuD,QAAQ,IAAI,CAACA,MAAM;wBAAEF;oBAAM;gBACrD;gBACAG,YAAYhC,UAAUgC,UAAU;gBAChCjC;gBACAb;YACF;YAEA,IAAIyC,iBAAiB,SAAS;gBAC5B,IAAI,CAACpB,IAAI,CAAC;YACZ;QACF,EAAE,OAAOF,KAAK;YACZ,IAAI,CAACC,KAAK,CAACD,eAAe4B,QAAQ5B,IAAIM,OAAO,GAAGuB,OAAO7B,MAAM;gBAACE,MAAM;YAAC;QACvE;IACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/hooks/attempt.ts"],"sourcesContent":["import {Args} from '@oclif/core'\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\n\nimport {formatFailure} from '../../actions/hook/formatFailure.js'\nimport {type DeliveryAttempt} from '../../actions/hook/types.js'\nimport {promptForProject} from '../../prompts/promptForProject.js'\nimport {getHookAttempt} from '../../services/hooks.js'\nimport {getProjectIdFlag} from '../../util/sharedFlags.js'\n\nconst attemptDebug = subdebug('hook:attempt')\n\nexport class AttemptHookCommand extends SanityCommand<typeof AttemptHookCommand> {\n static override args = {\n attemptId: Args.string({\n description: 'The delivery attempt ID to get details for',\n required: true,\n }),\n }\n static override description = 'Print details of a given webhook delivery attempt'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> abc123',\n description: 'Print details of webhook delivery attempt with ID abc123',\n },\n {\n command: '<%= config.bin %> <%= command.id %> abc123 --project-id projectId',\n description: 'Get attempt details for a specific project',\n },\n ]\n\n static override flags = {\n ...getProjectIdFlag({\n description: 'Project ID to view webhook attempt for',\n semantics: 'override',\n }),\n }\n\n static override hiddenAliases: string[] = ['hook:attempt']\n\n public async run() {\n const {args} = await this.parse(AttemptHookCommand)\n const {attemptId} = args\n\n const projectId = await this.getProjectId({\n fallback: () =>\n promptForProject({\n requiredPermissions: [{grant: 'read', permission: 'sanity.project.webhooks'}],\n }),\n })\n\n let attempt: DeliveryAttempt\n try {\n attempt = await getHookAttempt({attemptId, projectId})\n } catch (error) {\n const err = error as Error\n attemptDebug(`Error fetching hook attempt ${attemptId}`, err)\n this.error(`Hook attempt retrieval failed:\\n${err.message}`, {exit: 1})\n }\n\n const {createdAt, failureReason, inProgress, resultBody, resultCode} = attempt\n\n this.log(`Date: ${createdAt}`)\n this.log(`Status: ${this.getStatus(attempt)}`)\n this.log(`Status code: ${resultCode}`)\n\n if (attempt.isFailure) {\n this.log(`Failure: ${formatFailure(attempt)}`)\n }\n\n if (!inProgress && (!failureReason || failureReason === 'http')) {\n const body = resultBody ? `\\n---\\n${resultBody}\\n---\\n` : '<empty>'\n this.log(`Response body: ${body}`)\n }\n }\n\n private getStatus(attempt: DeliveryAttempt): string {\n if (attempt.isFailure) {\n return 'Failed'\n }\n\n if (attempt.inProgress) {\n return 'In progress'\n }\n\n return 'Delivered'\n }\n}\n"],"names":["Args","SanityCommand","subdebug","formatFailure","promptForProject","getHookAttempt","getProjectIdFlag","attemptDebug","AttemptHookCommand","args","attemptId","string","description","required","examples","command","flags","semantics","hiddenAliases","run","parse","projectId","getProjectId","fallback","requiredPermissions","grant","permission","attempt","error","err","message","exit","createdAt","failureReason","inProgress","resultBody","resultCode","log","getStatus","isFailure","body"],"mappings":"AAAA,SAAQA,IAAI,QAAO,cAAa;AAChC,SAAQC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AAExD,SAAQC,aAAa,QAAO,sCAAqC;AAEjE,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,cAAc,QAAO,0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X,UAAU;QAC7C,IAAI,CAACU,GAAG,CAAC,CAAC,aAAa,EAAED,YAAY;QAErC,IAAIT,QAAQY,SAAS,EAAE;YACrB,IAAI,CAACF,GAAG,CAAC,CAAC,SAAS,EAAElC,cAAcwB,UAAU;QAC/C;QAEA,IAAI,CAACO,cAAe,CAAA,CAACD,iBAAiBA,kBAAkB,MAAK,GAAI;YAC/D,MAAMO,OAAOL,aAAa,CAAC,OAAO,EAAEA,WAAW,OAAO,CAAC,GAAG;YAC1D,IAAI,CAACE,GAAG,CAAC,CAAC,eAAe,EAAEG,MAAM;QACnC;IACF;IAEQF,UAAUX,OAAwB,EAAU;QAClD,IAAIA,QAAQY,SAAS,EAAE;YACrB,OAAO;QACT;QAEA,IAAIZ,QAAQO,UAAU,EAAE;YACtB,OAAO;QACT;QAEA,OAAO;IACT;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/hooks/create.ts"],"sourcesContent":["import {getSanityUrl, SanityCommand, subdebug} from '@sanity/cli-core'\nimport open from 'open'\n\nimport {promptForProject} from '../../prompts/promptForProject.js'\nimport {getProjectById} from '../../services/projects.js'\nimport {getProjectIdFlag} from '../../util/sharedFlags.js'\n\nconst createHookDebug = subdebug('hook:create')\n\nexport class CreateHookCommand extends SanityCommand<typeof CreateHookCommand> {\n static override description = 'Create a new webhook for the current project'\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'Create a new webhook for the current project',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --project-id abc123',\n description: 'Create a webhook for a specific project',\n },\n ]\n\n static override flags = {\n ...getProjectIdFlag({\n description: 'Project ID to create webhook for',\n semantics: 'override',\n }),\n }\n\n static override hiddenAliases: string[] = ['hook:create']\n\n public async run() {\n const projectId = await this.getProjectId({\n fallback: () =>\n promptForProject({requiredPermissions: [{grant: 'read', permission: 'sanity.project'}]}),\n })\n\n let projectInfo: {organizationId?: string | null}\n try {\n projectInfo = await getProjectById(projectId)\n } catch (error) {\n const err = error as Error\n createHookDebug(`Error fetching project info for project ${projectId}`, err)\n this.error(`Failed to fetch project information:\\n${err.message}`, {exit: 1})\n }\n\n const organizationId = projectInfo.organizationId || 'personal'\n const manageUrl = getSanityUrl(\n `/organizations/${organizationId}/project/${projectId}/api/webhooks/new`,\n )\n\n this.log(`Opening ${manageUrl}`)\n\n try {\n await open(manageUrl)\n } catch (error) {\n const err = error as Error\n createHookDebug('Error opening browser', err)\n this.error(`Failed to open browser:\\n${err.message}`, {exit: 1})\n }\n }\n}\n"],"names":["getSanityUrl","SanityCommand","subdebug","open","promptForProject","getProjectById","getProjectIdFlag","createHookDebug","CreateHookCommand","description","examples","command","flags","semantics","hiddenAliases","run","projectId","getProjectId","fallback","requiredPermissions","grant","permission","projectInfo","error","err","message","exit","organizationId","manageUrl","log"],"mappings":"AAAA,SAAQA,YAAY,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACtE,OAAOC,UAAU,OAAM;AAEvB,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,cAAc,QAAO,6BAA4B;AACzD,SAAQC,gBAAgB,QAAO,4BAA2B;AAE1D,MAAMC,kBAAkBL,SAAS;AAEjC,OAAO,MAAMM,0BAA0BP;IACrC,OAAgBQ,cAAc,+CAA8C;IAC5E,OAAgBC,WAAW;QACzB;YACEC,SAAS;YACTF,aAAa;QACf;QACA;YACEE,SAAS;YACTF,aAAa;QACf;KACD,CAAA;IAED,OAAgBG,QAAQ;QACtB,GAAGN,iBAAiB;YAClBG,aAAa;YACbI,WAAW;QACb,EAAE;IACJ,EAAC;IAED,OAAgBC,gBAA0B;QAAC;KAAc,CAAA;IAEzD,MAAaC,MAAM;QACjB,MAAMC,YAAY,MAAM,IAAI,CAACC,YAAY,CAAC;YACxCC,UAAU,IACRd,iBAAiB;oBAACe,qBAAqB;wBAAC;4BAACC,OAAO;4BAAQC,YAAY;wBAAgB;qBAAE;gBAAA;QAC1F;QAEA,IAAIC;QACJ,IAAI;YACFA,cAAc,MAAMjB,eAAeW;QACrC,EAAE,OAAOO,OAAO;YACd,MAAMC,MAAMD;YACZhB,gBAAgB,CAAC,wCAAwC,EAAES,WAAW,EAAEQ;YACxE,IAAI,CAACD,KAAK,CAAC,CAAC,sCAAsC,EAAEC,IAAIC,OAAO,EAAE,EAAE;gBAACC,MAAM;YAAC;QAC7E;QAEA,MAAMC,iBAAiBL,YAAYK,cAAc,IAAI;QACrD,MAAMC,YAAY5B,aAChB,CAAC,eAAe,EAAE2B,eAAe,SAAS,EAAEX,UAAU,iBAAiB,CAAC;QAG1E,IAAI,CAACa,GAAG,CAAC,CAAC,QAAQ,EAAED,WAAW;QAE/B,IAAI;YACF,MAAMzB,KAAKyB;QACb,EAAE,OAAOL,OAAO;YACd,MAAMC,MAAMD;YACZhB,gBAAgB,yBAAyBiB;YACzC,IAAI,CAACD,KAAK,CAAC,CAAC,yBAAyB,EAAEC,IAAIC,OAAO,EAAE,EAAE;gBAACC,MAAM;YAAC;QAChE;IACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/hooks/delete.ts"],"sourcesContent":["import {Args} from '@oclif/core'\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\nimport {select} from '@sanity/cli-core/ux'\n\nimport {type Hook} from '../../actions/hook/types'\nimport {promptForProject} from '../../prompts/promptForProject.js'\nimport {deleteHookForProject, listHooksForProject} from '../../services/hooks.js'\nimport {getProjectIdFlag} from '../../util/sharedFlags.js'\n\nconst deleteHookDebug = subdebug('hook:delete')\n\nexport class Delete extends SanityCommand<typeof Delete> {\n static override args = {\n name: Args.string({\n description: 'Name of hook to delete (will prompt if not provided)',\n required: false,\n }),\n }\n\n static override description = 'Delete a hook within your project'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'Interactively select and delete a hook',\n },\n {\n command: '<%= config.bin %> <%= command.id %> my-hook',\n description: 'Delete a specific hook by name',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --project-id abc123',\n description: 'Delete a hook from a specific project',\n },\n ]\n\n static override flags = {\n ...getProjectIdFlag({\n description: 'Project ID to delete webhook from',\n semantics: 'override',\n }),\n }\n\n static override hiddenAliases: string[] = ['hook:delete']\n\n public async run(): Promise<void> {\n const {args} = await this.parse(Delete)\n\n const projectId = await this.getProjectId({\n fallback: () =>\n promptForProject({\n requiredPermissions: [{grant: 'delete', permission: 'sanity.project.webhooks'}],\n }),\n })\n\n // Get the hook ID to delete\n const hookId = await this.promptForHook(args.name, projectId)\n\n try {\n await deleteHookForProject(projectId, hookId)\n\n this.log('Hook deleted')\n } catch (error) {\n const err = error as Error\n deleteHookDebug(`Error deleting hook ${hookId} for project ${projectId}`, err)\n this.error(`Hook deletion failed:\\n${err.message}`, {exit: 1})\n }\n }\n\n private async promptForHook(\n specifiedName: string | undefined,\n projectId: string,\n ): Promise<string> {\n let hooks: Hook[]\n try {\n hooks = await listHooksForProject(projectId)\n } catch (error) {\n const err = error as Error\n deleteHookDebug(`Error fetching hooks for project ${projectId}`, err)\n this.error(`Failed to fetch hooks:\\n${err.message}`, {exit: 1})\n }\n\n if (hooks.length === 0) {\n this.error('No hooks configured for this project.', {exit: 1})\n }\n\n // If hook name is specified, find it in the list\n if (specifiedName) {\n const specifiedNameLower = specifiedName.toLowerCase()\n const selectedHook = hooks.find((hook) => hook.name.toLowerCase() === specifiedNameLower)\n\n if (!selectedHook) {\n this.error(`Hook with name \"${specifiedName}\" not found`, {exit: 1})\n }\n\n return selectedHook.id\n }\n\n // If no hook name specified, prompt user to select one\n const choices = hooks.map((hook) => ({\n name: hook.name,\n value: hook.id,\n }))\n\n const selectedId = await select({\n choices,\n message: 'Select hook to delete',\n })\n\n return selectedId\n }\n}\n"],"names":["Args","SanityCommand","subdebug","select","promptForProject","deleteHookForProject","listHooksForProject","getProjectIdFlag","deleteHookDebug","Delete","args","name","string","description","required","examples","command","flags","semantics","hiddenAliases","run","parse","projectId","getProjectId","fallback","requiredPermissions","grant","permission","hookId","promptForHook","log","error","err","message","exit","specifiedName","hooks","length","specifiedNameLower","toLowerCase","selectedHook","find","hook","id","choices","map","value","selectedId"],"mappings":"AAAA,SAAQA,IAAI,QAAO,cAAa;AAChC,SAAQC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACxD,SAAQC,MAAM,QAAO,sBAAqB;AAG1C,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,oBAAoB,EAAEC,mBAAmB,QAAO,0BAAyB;AACjF,SAAQC,gBAAgB,QAAO,4BAA2B;AAE1D,MAAMC,kBAAkBN,SAAS;AAEjC,OAAO,MAAMO,eAAeR;IAC1B,OAAgBS,OAAO;QACrBC,MAAMX,KAAKY,MAAM,CAAC;YAChBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,oCAAmC;IAEjE,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,GAAGV,iBAAiB;YAClBM,aAAa;YACbK,WAAW;QACb,EAAE;IACJ,EAAC;IAED,OAAgBC,gBAA0B;QAAC;KAAc,CAAA;IAEzD,MAAaC,MAAqB;QAChC,MAAM,EAACV,IAAI,EAAC,GAAG,MAAM,IAAI,CAACW,KAAK,CAACZ;QAEhC,MAAMa,YAAY,MAAM,IAAI,CAACC,YAAY,CAAC;YACxCC,UAAU,IACRpB,iBAAiB;oBACfqB,qBAAqB;wBAAC;4BAACC,OAAO;4BAAUC,YAAY;wBAAyB;qBAAE;gBACjF;QACJ;QAEA,4BAA4B;QAC5B,MAAMC,SAAS,MAAM,IAAI,CAACC,aAAa,CAACnB,KAAKC,IAAI,EAAEW;QAEnD,IAAI;YACF,MAAMjB,qBAAqBiB,WAAWM;YAEtC,IAAI,CAACE,GAAG,CAAC;QACX,EAAE,OAAOC,O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],"sourcesContent":["import {SanityCommand, subdebug} from '@sanity/cli-core'\n\nimport {type Hook} from '../../actions/hook/types'\nimport {promptForProject} from '../../prompts/promptForProject.js'\nimport {listHooksForProject} from '../../services/hooks.js'\nimport {getProjectIdFlag} from '../../util/sharedFlags.js'\n\nconst listHookDebug = subdebug('hook:list')\n\nexport class List extends SanityCommand<typeof List> {\n static override description = 'List hooks for a given project'\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'List hooks for a given project',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --project-id abc123',\n description: 'List hooks for a specific project',\n },\n ]\n\n static override flags = {\n ...getProjectIdFlag({\n description: 'Project ID to list webhooks for',\n semantics: 'override',\n }),\n }\n\n static override hiddenAliases: string[] = ['hook:list']\n\n public async run() {\n // Ensure we have project context\n const projectId = await this.getProjectId({\n fallback: () =>\n promptForProject({\n requiredPermissions: [{grant: 'read', permission: 'sanity.project.webhooks'}],\n }),\n })\n\n let hooks: Hook[]\n try {\n hooks = await listHooksForProject(projectId)\n } catch (error) {\n const err = error as Error\n\n listHookDebug(`Error fetching hooks for project ${projectId}`, err)\n this.error(`Hook list retrieval failed:\\n${err.message}`, {exit: 1})\n }\n\n for (const hook of hooks) {\n this.log(`Name: ${hook.name}`)\n this.log(`Dataset: ${hook.dataset}`)\n this.log(`URL: ${hook.url}`)\n\n if (hook.type === 'document') {\n this.log(`HTTP method: ${hook.httpMethod}`)\n\n if (hook.description) {\n this.log(`Description: ${hook.description}`)\n }\n }\n\n this.log('')\n }\n }\n}\n"],"names":["SanityCommand","subdebug","promptForProject","listHooksForProject","getProjectIdFlag","listHookDebug","List","description","examples","command","flags","semantics","hiddenAliases","run","projectId","getProjectId","fallback","requiredPermissions","grant","permission","hooks","error","err","message","exit","hook","log","name","dataset","url","type","httpMethod"],"mappings":"AAAA,SAAQA,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AAGxD,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,mBAA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AAC,CAAC,aAAa,EAAED,KAAKlB,WAAW,EAAE;gBAC7C;YACF;YAEA,IAAI,CAACmB,GAAG,CAAC;QACX;IACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/hooks/logs.ts"],"sourcesContent":["import {inspect, styleText} from 'node:util'\n\nimport {Args, Flags} from '@oclif/core'\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\nimport {select} from '@sanity/cli-core/ux'\nimport groupBy from 'lodash-es/groupBy.js'\n\nimport {formatFailure} from '../../actions/hook/formatFailure.js'\nimport {type DeliveryAttempt, type Hook, type HookMessage} from '../../actions/hook/types'\nimport {promptForProject} from '../../prompts/promptForProject.js'\nimport {\n getHookAttemptsForProject,\n getHookMessagesForProject,\n getHooksForProject,\n} from '../../services/hooks.js'\nimport {getProjectIdFlag} from '../../util/sharedFlags.js'\n\nconst logsHookDebug = subdebug('hook:logs')\n\nexport class LogsHookCommand extends SanityCommand<typeof LogsHookCommand> {\n static override args = {\n name: Args.string({\n description: 'Name of the hook to show logs for',\n required: false,\n }),\n }\n\n static override description = 'List latest log entries for a given hook'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'List latest log entries for a given hook',\n },\n {\n command: '<%= config.bin %> <%= command.id %> [NAME]',\n description: 'List latest log entries for a specific hook by name',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --project-id abc123',\n description: 'List hook logs for a specific project',\n },\n ]\n\n static override flags = {\n ...getProjectIdFlag({\n description: 'Project ID to view webhook logs for',\n semantics: 'override',\n }),\n detailed: Flags.boolean({\n description: 'Include detailed payload and attempts',\n required: false,\n }),\n }\n\n static override hiddenAliases: string[] = ['hook:logs']\n\n public async run() {\n const {args, flags} = await this.parse(LogsHookCommand)\n\n // Ensure we have project context\n const projectId = await this.getProjectId({\n fallback: () =>\n promptForProject({\n requiredPermissions: [{grant: 'read', permission: 'sanity.project.webhooks'}],\n }),\n })\n\n // Get hooks for the project\n let hooks: Hook[]\n try {\n hooks = await getHooksForProject(projectId)\n } catch (error) {\n const err = error as Error\n logsHookDebug(`Error fetching hooks for project ${projectId}`, err)\n this.error(`Hook list retrieval failed:\\n${err.message}`, {exit: 1})\n }\n\n if (hooks.length === 0) {\n this.error('No hooks currently registered', {exit: 1})\n }\n\n // If hook name is provided, find that specific hook\n let selectedHook: Hook | undefined\n if (args.name) {\n selectedHook = hooks.find((hook) => hook.name.toLowerCase() === args.name?.toLowerCase())\n if (!selectedHook) {\n this.error(`Hook with name \"${args.name}\" not found`, {exit: 1})\n }\n } else if (hooks.length === 1) {\n // If only one hook exists, use that\n selectedHook = hooks[0]\n } else {\n // Otherwise prompt user to select a hook\n selectedHook = await this.selectHook(hooks)\n }\n\n if (!selectedHook) {\n this.error('No hook selected', {exit: 1})\n }\n\n // Fetch messages and attempts for the selected hook\n let messages: HookMessage[]\n let attempts: DeliveryAttempt[] = []\n try {\n ;[messages, attempts] = await Promise.all([\n getHookMessagesForProject({\n hookId: selectedHook.id,\n projectId,\n }),\n getHookAttemptsForProject({\n hookId: selectedHook.id,\n projectId,\n }),\n ])\n } catch (error) {\n const err = error as Error\n logsHookDebug(`Error fetching logs for hook ${selectedHook.id}`, err)\n this.error(`Hook logs retrieval failed:\\n${err.message}`, {exit: 1})\n }\n\n // Group attempts by message ID\n const groupedAttempts = groupBy(attempts, 'messageId')\n\n // Populate messages with attempts\n const populated = messages.map((msg): HookMessage & {attempts: DeliveryAttempt[]} => ({\n ...msg,\n attempts: groupedAttempts[msg.id] || [],\n }))\n\n const totalMessages = messages.length - 1\n\n for (const [i, message] of populated.entries()) {\n this.printMessage(message, {detailed: flags.detailed})\n this.printSeparator(totalMessages === i)\n }\n }\n\n private formatAttemptDate(dateString: string): string {\n try {\n return new Date(dateString).toISOString().replace(/\\.\\d+Z$/, 'Z')\n } catch {\n return dateString // fallback to original if parsing fails\n }\n }\n\n private printMessage(\n message: HookMessage & {attempts: DeliveryAttempt[]},\n options: {detailed?: boolean},\n ) {\n const {detailed} = options\n\n this.log(`Date: ${message.createdAt}`)\n this.log(`Status: ${message.status}`)\n if (message.resultCode) {\n this.log(`Result code: ${message.resultCode}`)\n }\n\n if (message.failureCount > 0) {\n this.log(`Failures: ${message.failureCount}`)\n }\n\n if (detailed) {\n this.log('Payload:')\n try {\n const payload = JSON.parse(message.payload)\n this.log(inspect(payload, {colors: true}))\n } catch (error) {\n this.log(`Payload (raw): ${message.payload}`)\n logsHookDebug('Failed to parse payload JSON:', error)\n }\n }\n\n if (detailed && message.attempts && message.attempts.length > 0) {\n this.log('Attempts:')\n for (const attempt of message.attempts) {\n const date = this.formatAttemptDate(attempt.createdAt)\n const prefix = ` [${date}]`\n\n if (attempt.inProgress) {\n this.log(`${prefix} ${styleText('yellow', 'Pending')}`)\n } else if (attempt.isFailure) {\n const failure = formatFailure(attempt, {includeHelp: true})\n this.log(`${prefix} ${styleText('yellow', `Failure: ${failure}`)}`)\n } else {\n this.log(`${prefix} Success: HTTP ${attempt.resultCode} (${attempt.duration}ms)`)\n }\n }\n }\n\n // Leave some empty space between messages\n this.log('')\n }\n\n private printSeparator(skip: boolean) {\n if (!skip) {\n this.log('---\\n')\n }\n }\n\n private async selectHook(hooks: Hook[]) {\n const hookId = await select({\n choices: hooks.map((hook) => ({\n name: hook.name,\n value: hook.id,\n })),\n message: 'Select hook to list logs for',\n })\n\n return hooks.find((hook) => hook.id === hookId)\n }\n}\n"],"names":["inspect","styleText","Args","Flags","SanityCommand","subdebug","select","groupBy","formatFailure","promptForProject","getHookAttemptsForProject","getHookMessagesForProject","getHooksForProject","getProjectIdFlag","logsHookDebug","LogsHookCommand","args","name","string","description","required","examples","command","flags","semantics","detailed","boolean","hiddenAliases","run","parse","projectId","getProjectId","fallback","requiredPermissions","grant","permission","hooks","error","err","message","exit","length","selectedHook","find","hook","toLowerCase","selectHook","messages","attempts","Promise","all","hookId","id","groupedAttempts","populated","map","msg","totalMessages","i","entries","printMessage","printSeparator","formatAttemptDate","dateString","Date","toISOString","replace","options","log","createdAt","status","resultCode","failureCount","payload","JSON","colors","attempt","date","prefix","inProgress","isFailure","failure","includeHelp","duration","skip","choices","value"],"mappings":"AAAA,SAAQA,OAAO,EAAEC,SAAS,QAAO,YAAW;AAE5C,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACxD,SAAQC,MAAM,QAAO,sBAAqB;AAC1C,OAAOC,aAAa,uBAAsB;AAE1C,SAAQC,aAAa,QAAO,sCAAqC;AAEjE,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SACEC,yBAAyB,EACzBC,yBAAyB,EACzBC,kBAAkB,QACb,0BAAyB;AAChC,SAAQC,gBAAgB,QAAO,4BAA2B;AAE1D,MAAMC,gBAAgBT,SAAS;AAE/B,OAAO,MAAMU,wBAAwBX;IACnC,OAAgBY,OAAO;QACrBC,MAAMf,KAAKgB,MAAM,CAAC;YAChBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,2CAA0C;IAExE,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,GAAGV,iBAAiB;YAClBM,aAAa;YACbK,WAAW;QACb,EAAE;QACFC,UAAUtB,MAAMuB,OAAO,CAAC;YACtBP,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBO,gBAA0B;QAAC;KAAY,CAAA;IAEvD,MAAaC,MAAM;QACjB,MAAM,EAACZ,IAAI,EAAEO,KAAK,EAAC,GAAG,MAAM,IAAI,CAACM,KAAK,CAACd;QAEvC,iCAAiC;QACjC,MAAMe,YAAY,MAAM,IAAI,CAACC,YAAY,CAAC;YACxCC,UAAU,IACRvB,iBAAiB;oBACfwB,qBAAqB;wBAAC;4BAACC,OAAO;4BAAQC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AAM;YACT,IAAI,CAAChB,GAAG,CAAC;QACX;IACF;IAEA,MAActB,WAAWV,KAAa,EAAE;QACtC,MAAMe,SAAS,MAAM7C,OAAO;YAC1B+E,SAASjD,MAAMmB,GAAG,CAAC,CAACX,OAAU,CAAA;oBAC5B3B,MAAM2B,KAAK3B,IAAI;oBACfqE,OAAO1C,KAAKQ,EAAE;gBAChB,CAAA;YACAb,SAAS;QACX;QAEA,OAAOH,MAAMO,IAAI,CAAC,CAACC,OAASA,KAAKQ,EAAE,KAAKD;IAC1C;AACF"}
|
package/dist/commands/init.js
CHANGED
|
@@ -50,7 +50,7 @@ import { getSanityEnv } from '../util/getSanityEnv.js';
|
|
|
50
50
|
import { getPeerDependencies } from '../util/packageManager/getPeerDependencies.js';
|
|
51
51
|
import { installDeclaredPackages, installNewPackages } from '../util/packageManager/installPackages.js';
|
|
52
52
|
import { getPartialEnvWithNpmPath } from '../util/packageManager/packageManagerChoice.js';
|
|
53
|
-
import { ImportDatasetCommand } from './
|
|
53
|
+
import { ImportDatasetCommand } from './datasets/import.js';
|
|
54
54
|
const debug = subdebug('init');
|
|
55
55
|
export class InitCommand extends SanityCommand {
|
|
56
56
|
static args = {
|
|
@@ -75,7 +75,7 @@ export class InitCommand extends SanityCommand {
|
|
|
75
75
|
description: 'Initialize a project with the given project ID and dataset using the moviedb template to the given path'
|
|
76
76
|
},
|
|
77
77
|
{
|
|
78
|
-
command: '<%= config.bin %> <%= command.id %> -y --
|
|
78
|
+
command: '<%= config.bin %> <%= command.id %> -y --project-name "Movies Unlimited" --dataset moviedb --visibility private --template moviedb --output-path /Users/espenh/movies-unlimited',
|
|
79
79
|
description: 'Create a brand new project with name "Movies Unlimited"'
|
|
80
80
|
}
|
|
81
81
|
];
|
|
@@ -99,8 +99,12 @@ export class InitCommand extends SanityCommand {
|
|
|
99
99
|
helpValue: '<code>'
|
|
100
100
|
}),
|
|
101
101
|
'create-project': Flags.string({
|
|
102
|
+
deprecated: {
|
|
103
|
+
message: 'Use --project-name instead'
|
|
104
|
+
},
|
|
102
105
|
description: 'Create a new project with the given name',
|
|
103
|
-
helpValue: '<name>'
|
|
106
|
+
helpValue: '<name>',
|
|
107
|
+
hidden: true
|
|
104
108
|
}),
|
|
105
109
|
dataset: Flags.string({
|
|
106
110
|
description: 'Dataset name for the studio',
|
|
@@ -139,6 +143,11 @@ export class InitCommand extends SanityCommand {
|
|
|
139
143
|
helpLabel: ' --[no-]git',
|
|
140
144
|
helpValue: '<message>'
|
|
141
145
|
}),
|
|
146
|
+
'import-dataset': Flags.boolean({
|
|
147
|
+
allowNo: true,
|
|
148
|
+
default: undefined,
|
|
149
|
+
description: 'Import template sample dataset'
|
|
150
|
+
}),
|
|
142
151
|
mcp: Flags.boolean({
|
|
143
152
|
allowNo: true,
|
|
144
153
|
default: true,
|
|
@@ -206,10 +215,19 @@ export class InitCommand extends SanityCommand {
|
|
|
206
215
|
],
|
|
207
216
|
description: 'Project ID to use for the studio',
|
|
208
217
|
exclusive: [
|
|
209
|
-
'create-project'
|
|
218
|
+
'create-project',
|
|
219
|
+
'project-name'
|
|
210
220
|
],
|
|
211
221
|
helpValue: '<id>'
|
|
212
222
|
}),
|
|
223
|
+
'project-name': Flags.string({
|
|
224
|
+
description: 'Create a new project with the given name',
|
|
225
|
+
exclusive: [
|
|
226
|
+
'project',
|
|
227
|
+
'create-project'
|
|
228
|
+
],
|
|
229
|
+
helpValue: '<name>'
|
|
230
|
+
}),
|
|
213
231
|
'project-plan': Flags.string({
|
|
214
232
|
description: 'Optionally select a plan for a new project',
|
|
215
233
|
helpValue: '<name>'
|
|
@@ -269,7 +287,7 @@ export class InitCommand extends SanityCommand {
|
|
|
269
287
|
_trace;
|
|
270
288
|
async run() {
|
|
271
289
|
const workDir = process.cwd();
|
|
272
|
-
const createProjectName = this.flags['create-project'];
|
|
290
|
+
const createProjectName = this.flags['project-name'] ?? this.flags['create-project'];
|
|
273
291
|
// For backwards "compatibility" - we used to allow `sanity init plugin`,
|
|
274
292
|
// and no longer do - but instead of printing an error about an unknown
|
|
275
293
|
// _command_, we want to acknowledge that the user is trying to do something
|
|
@@ -312,10 +330,13 @@ export class InitCommand extends SanityCommand {
|
|
|
312
330
|
exit: 1
|
|
313
331
|
});
|
|
314
332
|
}
|
|
333
|
+
const isAppTemplate = this.flags.template ? determineAppTemplate(this.flags.template) : false // Default to false
|
|
334
|
+
;
|
|
315
335
|
// Checks flags are present when in unattended mode
|
|
316
336
|
if (this.isUnattended()) {
|
|
317
337
|
this.checkFlagsInUnattendedMode({
|
|
318
338
|
createProjectName,
|
|
339
|
+
isAppTemplate,
|
|
319
340
|
isNextJs
|
|
320
341
|
});
|
|
321
342
|
}
|
|
@@ -346,8 +367,6 @@ export class InitCommand extends SanityCommand {
|
|
|
346
367
|
const envFilename = typeof this.flags.env === 'string' ? this.flags.env : envFilenameDefault;
|
|
347
368
|
// If the user isn't already autenticated, make it so
|
|
348
369
|
const { user } = await this.ensureAuthenticated();
|
|
349
|
-
const isAppTemplate = this.flags.template ? determineAppTemplate(this.flags.template) : false // Default to false
|
|
350
|
-
;
|
|
351
370
|
if (!isAppTemplate) {
|
|
352
371
|
this.log(`${logSymbols.success} Fetching existing projects`);
|
|
353
372
|
this.log('');
|
|
@@ -401,8 +420,14 @@ export class InitCommand extends SanityCommand {
|
|
|
401
420
|
workDir
|
|
402
421
|
});
|
|
403
422
|
// Set up MCP integration
|
|
423
|
+
let mcpMode = 'prompt';
|
|
424
|
+
if (!this.flags.mcp || !this.resolveIsInteractive()) {
|
|
425
|
+
mcpMode = 'skip';
|
|
426
|
+
} else if (this.flags.yes) {
|
|
427
|
+
mcpMode = 'auto';
|
|
428
|
+
}
|
|
404
429
|
const mcpResult = await setupMCP({
|
|
405
|
-
|
|
430
|
+
mode: mcpMode
|
|
406
431
|
});
|
|
407
432
|
this._trace.log({
|
|
408
433
|
configuredEditors: mcpResult.configuredEditors,
|
|
@@ -476,7 +501,8 @@ export class InitCommand extends SanityCommand {
|
|
|
476
501
|
});
|
|
477
502
|
}
|
|
478
503
|
// If the template has a sample dataset, prompt the user whether or not we should import it
|
|
479
|
-
const
|
|
504
|
+
const importDatasetFlag = this.flags['import-dataset'];
|
|
505
|
+
const shouldImport = template?.datasetUrl && (importDatasetFlag ?? (!this.isUnattended() && await this.promptForDatasetImport(template.importPrompt)));
|
|
480
506
|
this._trace.log({
|
|
481
507
|
selectedOption: shouldImport ? 'yes' : 'no',
|
|
482
508
|
step: 'importTemplateDataset'
|
|
@@ -621,8 +647,22 @@ export class InitCommand extends SanityCommand {
|
|
|
621
647
|
}
|
|
622
648
|
this._trace.complete();
|
|
623
649
|
}
|
|
624
|
-
checkFlagsInUnattendedMode({ createProjectName, isNextJs }) {
|
|
650
|
+
checkFlagsInUnattendedMode({ createProjectName, isAppTemplate, isNextJs }) {
|
|
625
651
|
debug('Unattended mode, validating required options');
|
|
652
|
+
// App templates only require --organization and --output-path
|
|
653
|
+
if (isAppTemplate) {
|
|
654
|
+
if (!this.flags['output-path']) {
|
|
655
|
+
this.error('`--output-path` must be specified in unattended mode', {
|
|
656
|
+
exit: 1
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
if (!this.flags.organization) {
|
|
660
|
+
this.error('The --organization flag is required for app templates in unattended mode. ' + 'Use --organization <id> to specify which organization to use.', {
|
|
661
|
+
exit: 1
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
626
666
|
if (!this.flags['dataset']) {
|
|
627
667
|
this.error(`\`--dataset\` must be specified in unattended mode`, {
|
|
628
668
|
exit: 1
|
|
@@ -635,18 +675,18 @@ export class InitCommand extends SanityCommand {
|
|
|
635
675
|
});
|
|
636
676
|
}
|
|
637
677
|
if (!this.flags.project && !createProjectName) {
|
|
638
|
-
this.error('`--project <id>` or `--
|
|
678
|
+
this.error('`--project <id>` or `--project-name <name>` must be specified in unattended mode', {
|
|
639
679
|
exit: 1
|
|
640
680
|
});
|
|
641
681
|
}
|
|
642
682
|
if (createProjectName && !this.flags.organization) {
|
|
643
|
-
this.error('
|
|
683
|
+
this.error('`--project-name` requires `--organization <id>` in unattended mode', {
|
|
644
684
|
exit: 1
|
|
645
685
|
});
|
|
646
686
|
}
|
|
647
687
|
}
|
|
648
688
|
async createProjectFromName({ createProjectName, planId, user }) {
|
|
649
|
-
debug('--
|
|
689
|
+
debug('--project-name specified, creating a new project');
|
|
650
690
|
let orgForCreateProjectFlag = this.flags.organization;
|
|
651
691
|
if (!orgForCreateProjectFlag) {
|
|
652
692
|
debug('no organization specified, selecting one');
|
|
@@ -948,6 +988,18 @@ export class InitCommand extends SanityCommand {
|
|
|
948
988
|
}
|
|
949
989
|
async getProjectDetails({ isAppTemplate, newProject, planId, showDefaultConfigPrompt, user }) {
|
|
950
990
|
if (isAppTemplate) {
|
|
991
|
+
// If organization flag is provided, use it directly (skip prompt and API call)
|
|
992
|
+
if (this.flags.organization) {
|
|
993
|
+
return {
|
|
994
|
+
datasetName: '',
|
|
995
|
+
displayName: '',
|
|
996
|
+
isFirstProject: false,
|
|
997
|
+
organizationId: this.flags.organization,
|
|
998
|
+
projectId: ''
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
// Interactive mode: fetch orgs and prompt
|
|
1002
|
+
// Note: unattended mode without --organization is rejected by checkFlagsInUnattendedMode
|
|
951
1003
|
const organizations = await listOrganizations({
|
|
952
1004
|
includeImplicitMemberships: 'true',
|
|
953
1005
|
includeMembers: 'true'
|