@sanity/cli 8.0.0 → 8.0.2
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/dist/actions/backup/downloadAsset.js +3 -24
- package/dist/actions/backup/downloadAsset.js.map +1 -1
- package/dist/actions/backup/downloadDocument.js +11 -22
- package/dist/actions/backup/downloadDocument.js.map +1 -1
- package/dist/actions/backup/downloadStream.js +83 -0
- package/dist/actions/backup/downloadStream.js.map +1 -0
- package/dist/actions/documents/validate.js +0 -3
- package/dist/actions/documents/validate.js.map +1 -1
- package/dist/actions/documents/validateDocuments.worker.js +4 -1
- package/dist/actions/documents/validateDocuments.worker.js.map +1 -1
- package/dist/actions/init/sdkAppDependencies.js +1 -1
- package/dist/actions/init/sdkAppDependencies.js.map +1 -1
- package/dist/actions/init/studioDependencies.js +1 -1
- package/dist/actions/init/studioDependencies.js.map +1 -1
- package/dist/actions/schema/uploadSchemaToLexicon.js +3 -0
- package/dist/actions/schema/uploadSchemaToLexicon.js.map +1 -1
- package/dist/actions/telemetry/telemetryDebug.js +2 -2
- package/dist/actions/telemetry/telemetryDebug.js.map +1 -1
- package/dist/commands/assets/upload.js +35 -1
- package/dist/commands/assets/upload.js.map +1 -1
- package/dist/commands/datasets/import.js +7 -10
- package/dist/commands/datasets/import.js.map +1 -1
- package/dist/exports/_internal.d.ts +50 -82
- package/dist/exports/index.d.ts +48 -78
- package/dist/exports/invokeSanityCli/index.d.ts +108 -18
- package/dist/exports/invokeSanityCli/index.js +2 -1
- package/dist/exports/invokeSanityCli/index.js.map +1 -1
- package/dist/exports/runtime.d.ts +3 -65
- package/dist/services/api.js +23 -15
- package/dist/services/api.js.map +1 -1
- package/dist/services/auth.js +4 -4
- package/dist/services/auth.js.map +1 -1
- package/dist/services/backup.js +3 -3
- package/dist/services/backup.js.map +1 -1
- package/dist/services/cors.js +3 -3
- package/dist/services/cors.js.map +1 -1
- package/dist/services/datasetAliases.js +5 -5
- package/dist/services/datasetAliases.js.map +1 -1
- package/dist/services/datasets.js +3 -3
- package/dist/services/datasets.js.map +1 -1
- package/dist/services/documents.js +1 -1
- package/dist/services/documents.js.map +1 -1
- package/dist/services/getProjectFeatures.js +1 -1
- package/dist/services/getProjectFeatures.js.map +1 -1
- package/dist/services/getUrlHeaders.js +3 -9
- package/dist/services/getUrlHeaders.js.map +1 -1
- package/dist/services/grants.js +1 -1
- package/dist/services/grants.js.map +1 -1
- package/dist/services/graphql.js +4 -3
- package/dist/services/graphql.js.map +1 -1
- package/dist/services/hooks.js +6 -6
- package/dist/services/hooks.js.map +1 -1
- package/dist/services/mcp.js +4 -4
- package/dist/services/mcp.js.map +1 -1
- package/dist/services/mediaLibraries.js +3 -3
- package/dist/services/mediaLibraries.js.map +1 -1
- package/dist/services/mintProject.js +6 -11
- package/dist/services/mintProject.js.map +1 -1
- package/dist/services/organizations.js +6 -6
- package/dist/services/organizations.js.map +1 -1
- package/dist/services/plans.js +2 -2
- package/dist/services/plans.js.map +1 -1
- package/dist/services/projects.js +7 -7
- package/dist/services/projects.js.map +1 -1
- package/dist/services/schemas.js +2 -2
- package/dist/services/schemas.js.map +1 -1
- package/dist/services/telemetry.js +2 -2
- package/dist/services/telemetry.js.map +1 -1
- package/dist/services/tokens.js +5 -5
- package/dist/services/tokens.js.map +1 -1
- package/dist/services/user.js +1 -1
- package/dist/services/user.js.map +1 -1
- package/dist/services/userApplications.js +18 -18
- package/dist/services/userApplications.js.map +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +12 -12
|
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { Args, Flags } from '@oclif/core';
|
|
4
4
|
import { exitCodes, getProjectCliClient, SanityCommand, subdebug } from '@sanity/cli-core';
|
|
5
|
-
import { createRequester } from '@sanity/cli-core/request';
|
|
5
|
+
import { createRequester, nodeReadableFromWeb } from '@sanity/cli-core/request';
|
|
6
6
|
import { spinner } from '@sanity/cli-core/ux';
|
|
7
7
|
import { sanityImport } from '@sanity/import';
|
|
8
8
|
import prettyMs from 'pretty-ms';
|
|
@@ -25,19 +25,16 @@ function getAssetsBase(source) {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
async function getUriStream(uri) {
|
|
28
|
-
const request = createRequester(
|
|
29
|
-
middleware: {
|
|
30
|
-
promise: {
|
|
31
|
-
onlyBody: false
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
});
|
|
28
|
+
const request = createRequester();
|
|
35
29
|
try {
|
|
30
|
+
// No timeout: large dataset exports may stream for longer than get-it's
|
|
31
|
+
// default request timeout, which would abort the body mid-transfer.
|
|
36
32
|
const response = await request({
|
|
37
|
-
|
|
33
|
+
as: 'stream',
|
|
34
|
+
timeout: false,
|
|
38
35
|
url: uri
|
|
39
36
|
});
|
|
40
|
-
return response.body;
|
|
37
|
+
return nodeReadableFromWeb(response.body);
|
|
41
38
|
} catch (err) {
|
|
42
39
|
throw new Error(`Error fetching source:\n${err.message}`, {
|
|
43
40
|
cause: err
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/datasets/import.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\nimport {Args, Flags} from '@oclif/core'\nimport {exitCodes, getProjectCliClient, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {createRequester} from '@sanity/cli-core/request'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {sanityImport} from '@sanity/import'\nimport prettyMs from 'pretty-ms'\n\nimport {NEW_DATASET_VALUE, promptForDataset} from '../../prompts/promptForDataset.js'\nimport {promptForDatasetName} from '../../prompts/promptForDatasetName.js'\nimport {promptForProject} from '../../prompts/promptForProject.js'\nimport {createDataset, listDatasets} from '../../services/datasets.js'\nimport {getDatasetFlag, getProjectIdFlag} from '../../util/sharedFlags.js'\n\nconst importDebug = subdebug('dataset:import')\n\ninterface ProgressEvent {\n step: string\n\n current?: number\n total?: number\n update?: string\n}\n\nfunction getAssetsBase(source: string): string | undefined {\n if (/^https?:\\/\\//i.test(source) || source === '-') {\n return undefined\n }\n\n try {\n const fileStats = fs.statSync(source)\n const sourceIsFolder = fileStats.isDirectory()\n return sourceIsFolder ? source : path.dirname(source)\n } catch {\n return undefined\n }\n}\n\nasync function getUriStream(uri: string): Promise<NodeJS.ReadableStream> {\n const request = createRequester({\n middleware: {promise: {onlyBody: false}},\n })\n\n try {\n const response = (await request({stream: true, url: uri})) as {body: NodeJS.ReadableStream}\n return response.body\n } catch (err) {\n throw new Error(`Error fetching source:\\n${(err as Error).message}`, {cause: err})\n }\n}\n\nfunction getPercentage(opts: ProgressEvent): string {\n if (!opts.total) {\n return ''\n }\n\n const percent = Math.floor(((opts.current || 0) / opts.total) * 100)\n return `[${percent}%] `\n}\n\nexport class ImportDatasetCommand extends SanityCommand<typeof ImportDatasetCommand> {\n static override args = {\n source: Args.string({\n description: 'Source file (use \"-\" for stdin)',\n required: true,\n }),\n targetDataset: Args.string({\n description: 'Target dataset (prefer --dataset flag instead)',\n required: false,\n }),\n }\n\n static override description = 'Import documents to a Sanity dataset'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> -d staging my-dataset.ndjson',\n description: 'Import \"./my-dataset.ndjson\" into dataset \"staging\"',\n },\n {\n command: 'cat my-dataset.ndjson | <%= config.bin %> <%= command.id %> -d test -',\n description: 'Import into dataset \"test\" from stdin',\n },\n {\n command: '<%= config.bin %> <%= command.id %> -p projectId -d staging my-dataset.ndjson',\n description: 'Import with explicit project ID (overrides CLI configuration)',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> -d staging -t someSecretToken my-dataset.ndjson',\n description: 'Import with an explicit token (e.g. for CI/CD)',\n },\n ]\n\n static override flags = {\n 'allow-assets-in-different-dataset': Flags.boolean({\n default: false,\n description: 'Allow asset documents to reference different project/dataset',\n }),\n 'allow-failing-assets': Flags.boolean({\n default: false,\n description: 'Skip assets that cannot be fetched/uploaded',\n }),\n 'allow-replacement-characters': Flags.boolean({\n default: false,\n description: 'Allow unicode replacement characters in imported documents',\n }),\n 'allow-system-documents': Flags.boolean({\n default: false,\n description: 'Imports system documents',\n }),\n 'asset-concurrency': Flags.integer({\n description: 'Number of parallel asset imports',\n }),\n ...getDatasetFlag({\n description: 'Dataset to import to',\n semantics: 'specify',\n }),\n missing: Flags.boolean({\n default: false,\n description: 'Skip documents that already exist',\n exclusive: ['replace'],\n }),\n ...getProjectIdFlag({\n description: 'Project ID to import to',\n semantics: 'override',\n }),\n project: Flags.string({\n deprecated: {to: 'project-id'},\n description: 'Project ID to import to',\n hidden: true,\n }),\n replace: Flags.boolean({\n default: false,\n description: 'Replace documents with the same IDs',\n exclusive: ['missing'],\n }),\n 'replace-assets': Flags.boolean({\n default: false,\n description: 'Skip reuse of existing assets',\n }),\n 'skip-cross-dataset-references': Flags.boolean({\n default: false,\n description: 'Skips references to other datasets',\n }),\n token: Flags.string({\n char: 't',\n description: 'Token to authenticate with',\n env: 'SANITY_IMPORT_TOKEN',\n required: false,\n }),\n }\n\n static override hiddenAliases: string[] = ['dataset:import']\n\n private currentProgress?: ReturnType<typeof spinner>\n private currentStep?: string\n private spinInterval?: NodeJS.Timeout | null\n private stepStart?: number\n\n private static async getStream(source: string): Promise<NodeJS.ReadableStream> {\n if (/^https?:\\/\\//i.test(source)) {\n return getUriStream(source)\n }\n\n return source === '-' ? process.stdin : fs.createReadStream(source)\n }\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(ImportDatasetCommand)\n\n const {\n 'allow-assets-in-different-dataset': allowAssetsInDifferentDataset,\n 'allow-failing-assets': allowFailingAssets,\n 'allow-replacement-characters': allowReplacementCharacters,\n 'allow-system-documents': allowSystemDocuments,\n 'asset-concurrency': assetConcurrency,\n dataset: datasetFlag,\n missing,\n replace,\n 'replace-assets': replaceAssets,\n 'skip-cross-dataset-references': skipCrossDatasetReferences,\n token,\n } = flags\n\n const projectId = await this.getProjectId({\n deprecatedFlagName: 'project',\n fallback: () => promptForProject({}),\n })\n\n const {source, targetDataset: targetDatasetArg} = args\n\n if (targetDatasetArg && !datasetFlag) {\n this.output.warn(\n 'Positional dataset argument is deprecated. Use the --dataset flag instead: --dataset <name>',\n )\n }\n\n let dataset = datasetFlag ?? targetDatasetArg\n if (!dataset) {\n if (this.isUnattended()) {\n return this.output.error('Dataset is required. Pass it with `--dataset <name>`.', {\n exit: exitCodes.USAGE_ERROR,\n })\n }\n\n const datasets = await listDatasets(projectId)\n dataset = await promptForDataset({allowCreation: true, datasets})\n\n if (dataset === NEW_DATASET_VALUE) {\n const newDatasetName = await promptForDatasetName()\n\n try {\n await createDataset({datasetName: newDatasetName, projectId})\n dataset = newDatasetName\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n importDebug(`Failed to create dataset ${newDatasetName}: ${message}`, error)\n return this.output.error(`Failed to create dataset ${newDatasetName}: ${message}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n }\n\n let operation: 'create' | 'createIfNotExists' | 'createOrReplace' = 'create'\n let releasesOperation: 'fail' | 'ignore' | 'replace' = 'fail'\n\n if (replace || missing) {\n operation = replace ? 'createOrReplace' : 'createIfNotExists'\n releasesOperation = replace ? 'replace' : 'ignore'\n }\n\n const client = await getProjectCliClient({\n apiVersion: 'v2025-02-19',\n dataset,\n projectId,\n requireUser: true,\n ...(token ? {token} : {}),\n })\n\n try {\n const stream = await ImportDatasetCommand.getStream(source)\n const assetsBase = getAssetsBase(source)\n\n const importOptions = {\n allowAssetsInDifferentDataset,\n allowFailingAssets,\n allowReplacementCharacters,\n allowSystemDocuments,\n client,\n onProgress: this.onProgress.bind(this),\n operation,\n releasesOperation,\n replaceAssets,\n skipCrossDatasetReferences,\n tag: 'sanity.import',\n targetDataset: dataset,\n targetProjectId: projectId,\n ...(assetsBase ? {assetsBase} : {}),\n ...(assetConcurrency === undefined ? {} : {assetConcurrency}),\n }\n\n const {numDocs, warnings} = await sanityImport(stream, importOptions)\n\n if (this.stepStart) {\n const timeSpent = prettyMs(Date.now() - this.stepStart, {secondsDecimalDigits: 2})\n if (this.currentProgress) {\n if (this.spinInterval) {\n clearInterval(this.spinInterval)\n this.spinInterval = null\n }\n this.currentProgress.text = `[100%] ${this.currentStep} (${timeSpent})`\n this.currentProgress.succeed()\n }\n }\n\n this.output.log('Done! Imported %d documents to dataset \"%s\"\\n', numDocs, dataset)\n this.printWarnings(warnings)\n } catch (err) {\n if (this.spinInterval) {\n clearInterval(this.spinInterval)\n this.spinInterval = null\n }\n\n if (this.currentProgress) {\n this.currentProgress.fail()\n }\n\n return (err as Error).name === 'ReplacementCharError'\n ? this.output.error(\n `Import failed due to unicode replacement characters in the data.\\n${(err as Error).message}\\n\\nIf you are certain you want to proceed with the import despite potentially corrupt data, re-run the import with the \\`--allow-replacement-characters\\` flag set.`,\n {exit: exitCodes.RUNTIME_ERROR},\n )\n : this.output.error((err as Error).stack || (err as Error).message, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n\n private onProgress(opts: ProgressEvent): void {\n const lengthComputable = opts.total\n const sameStep = opts.step === this.currentStep\n const percent = getPercentage(opts)\n\n if (lengthComputable && opts.total === opts.current && this.spinInterval) {\n clearInterval(this.spinInterval)\n this.spinInterval = null\n }\n\n if (sameStep && !lengthComputable) {\n return\n }\n\n if (sameStep) {\n if (this.stepStart) {\n const timeSpent = prettyMs(Date.now() - this.stepStart, {secondsDecimalDigits: 2})\n if (this.currentProgress) {\n this.currentProgress.text = `${percent}${opts.step} (${timeSpent})`\n this.currentProgress.render()\n }\n }\n return\n }\n\n // Moved to a new step\n const prevStep = this.currentStep\n const prevStepStart = this.stepStart\n this.stepStart = Date.now()\n this.currentStep = opts.step\n\n if (this.spinInterval) {\n clearInterval(this.spinInterval)\n this.spinInterval = null\n }\n\n if (this.currentProgress && this.currentProgress.succeed && prevStepStart) {\n const timeSpent = prettyMs(Date.now() - prevStepStart, {\n secondsDecimalDigits: 2,\n })\n this.currentProgress.text = `[100%] ${prevStep} (${timeSpent})`\n this.currentProgress.succeed()\n }\n\n this.currentProgress = spinner(`[0%] ${opts.step} (0.00s)`).start()\n\n if (!lengthComputable) {\n this.spinInterval = setInterval(() => {\n if (this.stepStart && this.currentProgress) {\n const timeSpent = prettyMs(Date.now() - this.stepStart, {\n secondsDecimalDigits: 2,\n })\n this.currentProgress.text = `${percent}${opts.step} (${timeSpent})`\n this.currentProgress.render()\n }\n }, 60)\n }\n }\n\n private printWarnings(warnings: Array<{message: string; type?: string; url?: string}>): void {\n const assetFails = warnings.filter((warn) => warn.type === 'asset')\n\n if (assetFails.length === 0) {\n return\n }\n\n this.output.warn(\n `Failed to import the following ${assetFails.length > 1 ? 'assets' : 'asset'}:`,\n )\n\n for (const warning of assetFails) {\n if (warning.url) {\n this.output.warn(` ${warning.url}`)\n }\n }\n }\n}\n"],"names":["fs","path","Args","Flags","exitCodes","getProjectCliClient","SanityCommand","subdebug","createRequester","spinner","sanityImport","prettyMs","NEW_DATASET_VALUE","promptForDataset","promptForDatasetName","promptForProject","createDataset","listDatasets","getDatasetFlag","getProjectIdFlag","importDebug","getAssetsBase","source","test","undefined","fileStats","statSync","sourceIsFolder","isDirectory","dirname","getUriStream","uri","request","middleware","promise","onlyBody","response","stream","url","body","err","Error","message","cause","getPercentage","opts","total","percent","Math","floor","current","ImportDatasetCommand","args","string","description","required","targetDataset","examples","command","flags","boolean","default","integer","semantics","missing","exclusive","project","deprecated","to","hidden","replace","token","char","env","hiddenAliases","currentProgress","currentStep","spinInterval","stepStart","getStream","process","stdin","createReadStream","run","parse","allowAssetsInDifferentDataset","allowFailingAssets","allowReplacementCharacters","allowSystemDocuments","assetConcurrency","dataset","datasetFlag","replaceAssets","skipCrossDatasetReferences","projectId","getProjectId","deprecatedFlagName","fallback","targetDatasetArg","output","warn","isUnattended","error","exit","USAGE_ERROR","datasets","allowCreation","newDatasetName","datasetName","String","RUNTIME_ERROR","operation","releasesOperation","client","apiVersion","requireUser","assetsBase","importOptions","onProgress","bind","tag","targetProjectId","numDocs","warnings","timeSpent","Date","now","secondsDecimalDigits","clearInterval","text","succeed","log","printWarnings","fail","name","stack","lengthComputable","sameStep","step","render","prevStep","prevStepStart","start","setInterval","assetFails","filter","type","length","warning"],"mappings":"AAAA,OAAOA,QAAQ,UAAS;AACxB,OAAOC,UAAU,YAAW;AAE5B,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,SAAS,EAAEC,mBAAmB,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACxF,SAAQC,eAAe,QAAO,2BAA0B;AACxD,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,YAAY,QAAO,iBAAgB;AAC3C,OAAOC,cAAc,YAAW;AAEhC,SAAQC,iBAAiB,EAAEC,gBAAgB,QAAO,oCAAmC;AACrF,SAAQC,oBAAoB,QAAO,wCAAuC;AAC1E,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,aAAa,EAAEC,YAAY,QAAO,6BAA4B;AACtE,SAAQC,cAAc,EAAEC,gBAAgB,QAAO,4BAA2B;AAE1E,MAAMC,cAAcb,SAAS;AAU7B,SAASc,cAAcC,MAAc;IACnC,IAAI,gBAAgBC,IAAI,CAACD,WAAWA,WAAW,KAAK;QAClD,OAAOE;IACT;IAEA,IAAI;QACF,MAAMC,YAAYzB,GAAG0B,QAAQ,CAACJ;QAC9B,MAAMK,iBAAiBF,UAAUG,WAAW;QAC5C,OAAOD,iBAAiBL,SAASrB,KAAK4B,OAAO,CAACP;IAChD,EAAE,OAAM;QACN,OAAOE;IACT;AACF;AAEA,eAAeM,aAAaC,GAAW;IACrC,MAAMC,UAAUxB,gBAAgB;QAC9ByB,YAAY;YAACC,SAAS;gBAACC,UAAU;YAAK;QAAC;IACzC;IAEA,IAAI;QACF,MAAMC,WAAY,MAAMJ,QAAQ;YAACK,QAAQ;YAAMC,KAAKP;QAAG;QACvD,OAAOK,SAASG,IAAI;IACtB,EAAE,OAAOC,KAAK;QACZ,MAAM,IAAIC,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AWG,MAAM,GAAG,IAAI,WAAW,QAAQ,CAAC,CAAC;QAGjF,KAAK,MAAMC,WAAWJ,WAAY;YAChC,IAAII,QAAQ9G,GAAG,EAAE;gBACf,IAAI,CAAC6D,MAAM,CAACC,IAAI,CAAC,CAAC,EAAE,EAAEgD,QAAQ9G,GAAG,EAAE;YACrC;QACF;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/datasets/import.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\nimport {Args, Flags} from '@oclif/core'\nimport {exitCodes, getProjectCliClient, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {createRequester, nodeReadableFromWeb} from '@sanity/cli-core/request'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {sanityImport} from '@sanity/import'\nimport prettyMs from 'pretty-ms'\n\nimport {NEW_DATASET_VALUE, promptForDataset} from '../../prompts/promptForDataset.js'\nimport {promptForDatasetName} from '../../prompts/promptForDatasetName.js'\nimport {promptForProject} from '../../prompts/promptForProject.js'\nimport {createDataset, listDatasets} from '../../services/datasets.js'\nimport {getDatasetFlag, getProjectIdFlag} from '../../util/sharedFlags.js'\n\nconst importDebug = subdebug('dataset:import')\n\ninterface ProgressEvent {\n step: string\n\n current?: number\n total?: number\n update?: string\n}\n\nfunction getAssetsBase(source: string): string | undefined {\n if (/^https?:\\/\\//i.test(source) || source === '-') {\n return undefined\n }\n\n try {\n const fileStats = fs.statSync(source)\n const sourceIsFolder = fileStats.isDirectory()\n return sourceIsFolder ? source : path.dirname(source)\n } catch {\n return undefined\n }\n}\n\nasync function getUriStream(uri: string): Promise<NodeJS.ReadableStream> {\n const request = createRequester()\n\n try {\n // No timeout: large dataset exports may stream for longer than get-it's\n // default request timeout, which would abort the body mid-transfer.\n const response = await request({as: 'stream', timeout: false, url: uri})\n return nodeReadableFromWeb(response.body)\n } catch (err) {\n throw new Error(`Error fetching source:\\n${(err as Error).message}`, {cause: err})\n }\n}\n\nfunction getPercentage(opts: ProgressEvent): string {\n if (!opts.total) {\n return ''\n }\n\n const percent = Math.floor(((opts.current || 0) / opts.total) * 100)\n return `[${percent}%] `\n}\n\nexport class ImportDatasetCommand extends SanityCommand<typeof ImportDatasetCommand> {\n static override args = {\n source: Args.string({\n description: 'Source file (use \"-\" for stdin)',\n required: true,\n }),\n targetDataset: Args.string({\n description: 'Target dataset (prefer --dataset flag instead)',\n required: false,\n }),\n }\n\n static override description = 'Import documents to a Sanity dataset'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> -d staging my-dataset.ndjson',\n description: 'Import \"./my-dataset.ndjson\" into dataset \"staging\"',\n },\n {\n command: 'cat my-dataset.ndjson | <%= config.bin %> <%= command.id %> -d test -',\n description: 'Import into dataset \"test\" from stdin',\n },\n {\n command: '<%= config.bin %> <%= command.id %> -p projectId -d staging my-dataset.ndjson',\n description: 'Import with explicit project ID (overrides CLI configuration)',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> -d staging -t someSecretToken my-dataset.ndjson',\n description: 'Import with an explicit token (e.g. for CI/CD)',\n },\n ]\n\n static override flags = {\n 'allow-assets-in-different-dataset': Flags.boolean({\n default: false,\n description: 'Allow asset documents to reference different project/dataset',\n }),\n 'allow-failing-assets': Flags.boolean({\n default: false,\n description: 'Skip assets that cannot be fetched/uploaded',\n }),\n 'allow-replacement-characters': Flags.boolean({\n default: false,\n description: 'Allow unicode replacement characters in imported documents',\n }),\n 'allow-system-documents': Flags.boolean({\n default: false,\n description: 'Imports system documents',\n }),\n 'asset-concurrency': Flags.integer({\n description: 'Number of parallel asset imports',\n }),\n ...getDatasetFlag({\n description: 'Dataset to import to',\n semantics: 'specify',\n }),\n missing: Flags.boolean({\n default: false,\n description: 'Skip documents that already exist',\n exclusive: ['replace'],\n }),\n ...getProjectIdFlag({\n description: 'Project ID to import to',\n semantics: 'override',\n }),\n project: Flags.string({\n deprecated: {to: 'project-id'},\n description: 'Project ID to import to',\n hidden: true,\n }),\n replace: Flags.boolean({\n default: false,\n description: 'Replace documents with the same IDs',\n exclusive: ['missing'],\n }),\n 'replace-assets': Flags.boolean({\n default: false,\n description: 'Skip reuse of existing assets',\n }),\n 'skip-cross-dataset-references': Flags.boolean({\n default: false,\n description: 'Skips references to other datasets',\n }),\n token: Flags.string({\n char: 't',\n description: 'Token to authenticate with',\n env: 'SANITY_IMPORT_TOKEN',\n required: false,\n }),\n }\n\n static override hiddenAliases: string[] = ['dataset:import']\n\n private currentProgress?: ReturnType<typeof spinner>\n private currentStep?: string\n private spinInterval?: NodeJS.Timeout | null\n private stepStart?: number\n\n private static async getStream(source: string): Promise<NodeJS.ReadableStream> {\n if (/^https?:\\/\\//i.test(source)) {\n return getUriStream(source)\n }\n\n return source === '-' ? process.stdin : fs.createReadStream(source)\n }\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(ImportDatasetCommand)\n\n const {\n 'allow-assets-in-different-dataset': allowAssetsInDifferentDataset,\n 'allow-failing-assets': allowFailingAssets,\n 'allow-replacement-characters': allowReplacementCharacters,\n 'allow-system-documents': allowSystemDocuments,\n 'asset-concurrency': assetConcurrency,\n dataset: datasetFlag,\n missing,\n replace,\n 'replace-assets': replaceAssets,\n 'skip-cross-dataset-references': skipCrossDatasetReferences,\n token,\n } = flags\n\n const projectId = await this.getProjectId({\n deprecatedFlagName: 'project',\n fallback: () => promptForProject({}),\n })\n\n const {source, targetDataset: targetDatasetArg} = args\n\n if (targetDatasetArg && !datasetFlag) {\n this.output.warn(\n 'Positional dataset argument is deprecated. Use the --dataset flag instead: --dataset <name>',\n )\n }\n\n let dataset = datasetFlag ?? targetDatasetArg\n if (!dataset) {\n if (this.isUnattended()) {\n return this.output.error('Dataset is required. Pass it with `--dataset <name>`.', {\n exit: exitCodes.USAGE_ERROR,\n })\n }\n\n const datasets = await listDatasets(projectId)\n dataset = await promptForDataset({allowCreation: true, datasets})\n\n if (dataset === NEW_DATASET_VALUE) {\n const newDatasetName = await promptForDatasetName()\n\n try {\n await createDataset({datasetName: newDatasetName, projectId})\n dataset = newDatasetName\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n importDebug(`Failed to create dataset ${newDatasetName}: ${message}`, error)\n return this.output.error(`Failed to create dataset ${newDatasetName}: ${message}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n }\n\n let operation: 'create' | 'createIfNotExists' | 'createOrReplace' = 'create'\n let releasesOperation: 'fail' | 'ignore' | 'replace' = 'fail'\n\n if (replace || missing) {\n operation = replace ? 'createOrReplace' : 'createIfNotExists'\n releasesOperation = replace ? 'replace' : 'ignore'\n }\n\n const client = await getProjectCliClient({\n apiVersion: 'v2025-02-19',\n dataset,\n projectId,\n requireUser: true,\n ...(token ? {token} : {}),\n })\n\n try {\n const stream = await ImportDatasetCommand.getStream(source)\n const assetsBase = getAssetsBase(source)\n\n const importOptions = {\n allowAssetsInDifferentDataset,\n allowFailingAssets,\n allowReplacementCharacters,\n allowSystemDocuments,\n client,\n onProgress: this.onProgress.bind(this),\n operation,\n releasesOperation,\n replaceAssets,\n skipCrossDatasetReferences,\n tag: 'sanity.import',\n targetDataset: dataset,\n targetProjectId: projectId,\n ...(assetsBase ? {assetsBase} : {}),\n ...(assetConcurrency === undefined ? {} : {assetConcurrency}),\n }\n\n const {numDocs, warnings} = await sanityImport(stream, importOptions)\n\n if (this.stepStart) {\n const timeSpent = prettyMs(Date.now() - this.stepStart, {secondsDecimalDigits: 2})\n if (this.currentProgress) {\n if (this.spinInterval) {\n clearInterval(this.spinInterval)\n this.spinInterval = null\n }\n this.currentProgress.text = `[100%] ${this.currentStep} (${timeSpent})`\n this.currentProgress.succeed()\n }\n }\n\n this.output.log('Done! Imported %d documents to dataset \"%s\"\\n', numDocs, dataset)\n this.printWarnings(warnings)\n } catch (err) {\n if (this.spinInterval) {\n clearInterval(this.spinInterval)\n this.spinInterval = null\n }\n\n if (this.currentProgress) {\n this.currentProgress.fail()\n }\n\n return (err as Error).name === 'ReplacementCharError'\n ? this.output.error(\n `Import failed due to unicode replacement characters in the data.\\n${(err as Error).message}\\n\\nIf you are certain you want to proceed with the import despite potentially corrupt data, re-run the import with the \\`--allow-replacement-characters\\` flag set.`,\n {exit: exitCodes.RUNTIME_ERROR},\n )\n : this.output.error((err as Error).stack || (err as Error).message, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n\n private onProgress(opts: ProgressEvent): void {\n const lengthComputable = opts.total\n const sameStep = opts.step === this.currentStep\n const percent = getPercentage(opts)\n\n if (lengthComputable && opts.total === opts.current && this.spinInterval) {\n clearInterval(this.spinInterval)\n this.spinInterval = null\n }\n\n if (sameStep && !lengthComputable) {\n return\n }\n\n if (sameStep) {\n if (this.stepStart) {\n const timeSpent = prettyMs(Date.now() - this.stepStart, {secondsDecimalDigits: 2})\n if (this.currentProgress) {\n this.currentProgress.text = `${percent}${opts.step} (${timeSpent})`\n this.currentProgress.render()\n }\n }\n return\n }\n\n // Moved to a new step\n const prevStep = this.currentStep\n const prevStepStart = this.stepStart\n this.stepStart = Date.now()\n this.currentStep = opts.step\n\n if (this.spinInterval) {\n clearInterval(this.spinInterval)\n this.spinInterval = null\n }\n\n if (this.currentProgress && this.currentProgress.succeed && prevStepStart) {\n const timeSpent = prettyMs(Date.now() - prevStepStart, {\n secondsDecimalDigits: 2,\n })\n this.currentProgress.text = `[100%] ${prevStep} (${timeSpent})`\n this.currentProgress.succeed()\n }\n\n this.currentProgress = spinner(`[0%] ${opts.step} (0.00s)`).start()\n\n if (!lengthComputable) {\n this.spinInterval = setInterval(() => {\n if (this.stepStart && this.currentProgress) {\n const timeSpent = prettyMs(Date.now() - this.stepStart, {\n secondsDecimalDigits: 2,\n })\n this.currentProgress.text = `${percent}${opts.step} (${timeSpent})`\n this.currentProgress.render()\n }\n }, 60)\n }\n }\n\n private printWarnings(warnings: Array<{message: string; type?: string; url?: string}>): void {\n const assetFails = warnings.filter((warn) => warn.type === 'asset')\n\n if (assetFails.length === 0) {\n return\n }\n\n this.output.warn(\n `Failed to import the following ${assetFails.length > 1 ? 'assets' : 'asset'}:`,\n )\n\n for (const warning of assetFails) {\n if (warning.url) {\n this.output.warn(` ${warning.url}`)\n }\n }\n }\n}\n"],"names":["fs","path","Args","Flags","exitCodes","getProjectCliClient","SanityCommand","subdebug","createRequester","nodeReadableFromWeb","spinner","sanityImport","prettyMs","NEW_DATASET_VALUE","promptForDataset","promptForDatasetName","promptForProject","createDataset","listDatasets","getDatasetFlag","getProjectIdFlag","importDebug","getAssetsBase","source","test","undefined","fileStats","statSync","sourceIsFolder","isDirectory","dirname","getUriStream","uri","request","response","as","timeout","url","body","err","Error","message","cause","getPercentage","opts","total","percent","Math","floor","current","ImportDatasetCommand","args","string","description","required","targetDataset","examples","command","flags","boolean","default","integer","semantics","missing","exclusive","project","deprecated","to","hidden","replace","token","char","env","hiddenAliases","currentProgress","currentStep","spinInterval","stepStart","getStream","process","stdin","createReadStream","run","parse","allowAssetsInDifferentDataset","allowFailingAssets","allowReplacementCharacters","allowSystemDocuments","assetConcurrency","dataset","datasetFlag","replaceAssets","skipCrossDatasetReferences","projectId","getProjectId","deprecatedFlagName","fallback","targetDatasetArg","output","warn","isUnattended","error","exit","USAGE_ERROR","datasets","allowCreation","newDatasetName","datasetName","String","RUNTIME_ERROR","operation","releasesOperation","client","apiVersion","requireUser","stream","assetsBase","importOptions","onProgress","bind","tag","targetProjectId","numDocs","warnings","timeSpent","Date","now","secondsDecimalDigits","clearInterval","text","succeed","log","printWarnings","fail","name","stack","lengthComputable","sameStep","step","render","prevStep","prevStepStart","start","setInterval","assetFails","filter","type","length","warning"],"mappings":"AAAA,OAAOA,QAAQ,UAAS;AACxB,OAAOC,UAAU,YAAW;AAE5B,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,SAAS,EAAEC,mBAAmB,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACxF,SAAQC,eAAe,EAAEC,mBAAmB,QAAO,2BAA0B;AAC7E,SAAQC,OAAO,QAAO,sBAAqB;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AEW,SAAS,EAAE,EAAEhB,UAAU,CAAC,CAAC;YAC/D,IAAI,CAAClD,eAAe,CAACwD,OAAO;QAC9B;QAEA,IAAI,CAACxD,eAAe,GAAGhE,QAAQ,CAAC,KAAK,EAAEkC,KAAK8F,IAAI,CAAC,QAAQ,CAAC,EAAEI,KAAK;QAEjE,IAAI,CAACN,kBAAkB;YACrB,IAAI,CAAC5D,YAAY,GAAGmE,YAAY;gBAC9B,IAAI,IAAI,CAAClE,SAAS,IAAI,IAAI,CAACH,eAAe,EAAE;oBAC1C,MAAMkD,YAAYhH,SAASiH,KAAKC,GAAG,KAAK,IAAI,CAACjD,SAAS,EAAE;wBACtDkD,sBAAsB;oBACxB;oBACA,IAAI,CAACrD,eAAe,CAACuD,IAAI,GAAG,GAAGnF,UAAUF,KAAK8F,IAAI,CAAC,EAAE,EAAEd,UAAU,CAAC,CAAC;oBACnE,IAAI,CAAClD,eAAe,CAACiE,MAAM;gBAC7B;YACF,GAAG;QACL;IACF;IAEQP,cAAcT,QAA+D,EAAQ;QAC3F,MAAMqB,aAAarB,SAASsB,MAAM,CAAC,CAAC9C,OAASA,KAAK+C,IAAI,KAAK;QAE3D,IAAIF,WAAWG,MAAM,KAAK,GAAG;YAC3B;QACF;QAEA,IAAI,CAACjD,MAAM,CAACC,IAAI,CACd,CAAC,+BAA+B,EAAE6C,WAAWG,MAAM,GAAG,IAAI,WAAW,QAAQ,CAAC,CAAC;QAGjF,KAAK,MAAMC,WAAWJ,WAAY;YAChC,IAAII,QAAQ/G,GAAG,EAAE;gBACf,IAAI,CAAC6D,MAAM,CAACC,IAAI,CAAC,CAAC,EAAE,EAAEiD,QAAQ/G,GAAG,EAAE;YACrC;QACF;IACF;AACF"}
|
|
@@ -1,54 +1,13 @@
|
|
|
1
|
-
import { getStudioEnvironmentVariables } from "@sanity/cli-build/_internal/env";
|
|
2
|
-
import { Interfaces } from "@oclif/core";
|
|
3
1
|
import { Schema } from "@sanity/types";
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
declare type CommandTelemetryConfig<Flags extends Interfaces.FlagInput> = {
|
|
12
|
-
redact?: readonly OptionFlagName<Flags>[];
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/** @internal */
|
|
16
|
-
export declare function defineCommandTelemetry<
|
|
17
|
-
const Flags extends Interfaces.FlagInput,
|
|
18
|
-
>(flags: Flags, config: CommandTelemetryConfig<Flags>): CommandTelemetry;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Extracts all serializable properties from userland schema types,
|
|
22
|
-
* so they best-effort can be used as definitions for Schema.compile.
|
|
23
|
-
*
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
export declare function extractManifestSchemaTypes(
|
|
27
|
-
schema: Schema,
|
|
28
|
-
workDir: string,
|
|
29
|
-
): Promise<ManifestSchemaType[]>;
|
|
30
|
-
|
|
31
|
-
export { getStudioEnvironmentVariables };
|
|
32
|
-
|
|
33
|
-
declare type ManifestArrayMember = Omit<ManifestSchemaType, "name"> & {
|
|
34
|
-
name?: string;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
declare type ManifestField = ManifestSchemaType & {
|
|
38
|
-
fieldset?: string;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
declare interface ManifestFieldset {
|
|
42
|
-
[index: string]: ManifestSerializable | undefined;
|
|
43
|
-
name: string;
|
|
44
|
-
title?: string;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
declare type ManifestReferenceMember = Omit<ManifestSchemaType, "name"> & {
|
|
48
|
-
name?: string;
|
|
2
|
+
import "sanity";
|
|
3
|
+
import "zod/mini";
|
|
4
|
+
import "@sanity/cli-core";
|
|
5
|
+
import { Interfaces } from "@oclif/core";
|
|
6
|
+
import { StudioEnvVariablesOptions, getStudioEnvironmentVariables } from "@sanity/cli-build/_internal/env";
|
|
7
|
+
type ManifestSerializable = boolean | ManifestSerializable[] | number | string | {
|
|
8
|
+
[k: string]: ManifestSerializable;
|
|
49
9
|
};
|
|
50
|
-
|
|
51
|
-
declare interface ManifestSchemaType {
|
|
10
|
+
interface ManifestSchemaType {
|
|
52
11
|
name: string;
|
|
53
12
|
type: string;
|
|
54
13
|
deprecated?: {
|
|
@@ -56,7 +15,7 @@ declare interface ManifestSchemaType {
|
|
|
56
15
|
};
|
|
57
16
|
fields?: ManifestField[];
|
|
58
17
|
fieldsets?: ManifestFieldset[];
|
|
59
|
-
hidden?:
|
|
18
|
+
hidden?: 'conditional' | boolean;
|
|
60
19
|
lists?: ManifestTitledValue[];
|
|
61
20
|
marks?: {
|
|
62
21
|
annotations?: ManifestArrayMember[];
|
|
@@ -67,53 +26,62 @@ declare interface ManifestSchemaType {
|
|
|
67
26
|
preview?: {
|
|
68
27
|
select: Record<string, string>;
|
|
69
28
|
};
|
|
70
|
-
readOnly?:
|
|
29
|
+
readOnly?: 'conditional' | boolean;
|
|
71
30
|
styles?: ManifestTitledValue[];
|
|
72
31
|
title?: string;
|
|
73
32
|
to?: ManifestReferenceMember[];
|
|
74
33
|
validation?: ManifestValidationGroup[];
|
|
75
34
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
| {
|
|
83
|
-
[k: string]: ManifestSerializable;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
declare interface ManifestTitledValue {
|
|
35
|
+
interface ManifestFieldset {
|
|
36
|
+
[index: string]: ManifestSerializable | undefined;
|
|
37
|
+
name: string;
|
|
38
|
+
title?: string;
|
|
39
|
+
}
|
|
40
|
+
interface ManifestTitledValue {
|
|
87
41
|
value: string;
|
|
88
42
|
title?: string;
|
|
89
43
|
}
|
|
90
|
-
|
|
91
|
-
|
|
44
|
+
type ManifestArrayMember = Omit<ManifestSchemaType, 'name'> & {
|
|
45
|
+
name?: string;
|
|
46
|
+
};
|
|
47
|
+
type ManifestReferenceMember = Omit<ManifestSchemaType, 'name'> & {
|
|
48
|
+
name?: string;
|
|
49
|
+
};
|
|
50
|
+
type ManifestField = ManifestSchemaType & {
|
|
51
|
+
fieldset?: string;
|
|
52
|
+
};
|
|
53
|
+
interface ManifestValidationGroup {
|
|
92
54
|
rules: ManifestValidationRule[];
|
|
93
|
-
level?:
|
|
55
|
+
level?: 'error' | 'info' | 'warning';
|
|
94
56
|
message?: string;
|
|
95
57
|
}
|
|
96
|
-
|
|
97
|
-
declare type ManifestValidationRule = {
|
|
58
|
+
type ManifestValidationRule = {
|
|
98
59
|
[index: string]: ManifestSerializable | undefined;
|
|
99
60
|
constraint?: ManifestSerializable;
|
|
100
61
|
flag: string;
|
|
101
62
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}[keyof Flags];
|
|
111
|
-
|
|
112
|
-
declare interface RedactedFlag {
|
|
63
|
+
/**
|
|
64
|
+
* Extracts all serializable properties from userland schema types,
|
|
65
|
+
* so they best-effort can be used as definitions for Schema.compile.
|
|
66
|
+
*
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
declare function extractManifestSchemaTypes(schema: Schema, workDir: string): Promise<ManifestSchemaType[]>;
|
|
70
|
+
interface RedactedFlag {
|
|
113
71
|
canonical: string;
|
|
114
72
|
flags: readonly string[];
|
|
115
73
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
74
|
+
/** @internal */
|
|
75
|
+
interface CommandTelemetry {
|
|
76
|
+
redactedFlags: readonly RedactedFlag[];
|
|
77
|
+
}
|
|
78
|
+
type OptionFlagName<Flags extends Interfaces.FlagInput> = string & { [Name in keyof Flags]: Flags[Name] extends {
|
|
79
|
+
type: 'option';
|
|
80
|
+
} ? Name : never; }[keyof Flags];
|
|
81
|
+
type CommandTelemetryConfig<Flags extends Interfaces.FlagInput> = {
|
|
82
|
+
redact?: readonly OptionFlagName<Flags>[];
|
|
83
|
+
};
|
|
84
|
+
/** @internal */
|
|
85
|
+
declare function defineCommandTelemetry<const Flags extends Interfaces.FlagInput>(flags: Flags, config: CommandTelemetryConfig<Flags>): CommandTelemetry;
|
|
86
|
+
export { type CommandTelemetry, type StudioEnvVariablesOptions, defineCommandTelemetry, extractManifestSchemaTypes, getStudioEnvironmentVariables };
|
|
87
|
+
//# sourceMappingURL=_internal.d.ts.map
|
package/dist/exports/index.d.ts
CHANGED
|
@@ -1,72 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { DefineMediaLibraryInput } from "@sanity/workbench-cli";
|
|
1
|
+
import "@sanity/types";
|
|
2
|
+
import { CliConfig, CliConfig as CliConfig$1, UserViteConfig } from "@sanity/cli-core";
|
|
3
|
+
import { ClientConfig, SanityClient } from "@sanity/client";
|
|
5
4
|
import { loadEnv } from "vite";
|
|
6
|
-
import { MediaLibraryField } from "@sanity/workbench-cli";
|
|
7
|
-
import { SanityClient } from "@sanity/client";
|
|
8
|
-
import { unstable_defineApp } from "@sanity/workbench-cli";
|
|
9
|
-
import { unstable_defineMediaLibrary } from "@sanity/workbench-cli";
|
|
10
|
-
import { UserViteConfig } from "@sanity/cli-core";
|
|
11
|
-
|
|
5
|
+
import { DefineAppInput, DefineMediaLibraryInput, MediaLibraryField, unstable_defineApp, unstable_defineMediaLibrary } from "@sanity/workbench-cli";
|
|
12
6
|
/**
|
|
13
7
|
* @public
|
|
14
8
|
*/
|
|
15
|
-
|
|
16
|
-
dataset?: string;
|
|
17
|
-
projectId?: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
declare type CliClientGetter = ((
|
|
21
|
-
options?: CliClientOptions,
|
|
22
|
-
) => SanityClient) & {
|
|
23
|
-
/**
|
|
24
|
-
* @deprecated This is only for INTERNAL use, and should not be relied upon outside of official Sanity modules
|
|
25
|
-
* @returns A token to use when constructing a client without a `token` explicitly defined, or undefined
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
|
-
__internal__getToken: () => string | undefined;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @public
|
|
33
|
-
*/
|
|
34
|
-
export declare interface CliClientOptions extends ClientConfig {
|
|
35
|
-
/**
|
|
36
|
-
* If no `projectId` or `dataset` is provided, `getCliClient` will try to
|
|
37
|
-
* resolve these from the `sanity.cli.ts` configuration file. Use this option
|
|
38
|
-
* to specify the directory to look for this file.
|
|
39
|
-
*/
|
|
40
|
-
cwd?: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export { CliConfig };
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @deprecated Use `defineCliConfig` instead
|
|
47
|
-
* @public
|
|
48
|
-
*/
|
|
49
|
-
export declare function createCliConfig(config: CliConfig): CliConfig;
|
|
50
|
-
|
|
51
|
-
export { DefineAppInput };
|
|
52
|
-
|
|
53
|
-
/** @beta */
|
|
54
|
-
export declare function defineCliConfig(config: CliConfig): CliConfig;
|
|
55
|
-
|
|
56
|
-
export { DefineMediaLibraryInput };
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @public
|
|
60
|
-
*
|
|
61
|
-
* @param options - The options to use for the client.
|
|
62
|
-
* @returns A configured Sanity API client.
|
|
63
|
-
*/
|
|
64
|
-
export declare const getCliClient: CliClientGetter;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* @public
|
|
68
|
-
*/
|
|
69
|
-
export declare interface GraphQLAPIConfig {
|
|
9
|
+
interface GraphQLAPIConfig {
|
|
70
10
|
/**
|
|
71
11
|
* Suffix to use for generated filter types.
|
|
72
12
|
*
|
|
@@ -79,7 +19,7 @@ export declare interface GraphQLAPIConfig {
|
|
|
79
19
|
*
|
|
80
20
|
* Optional, defaults to `gen3` (which is the only option, currently)
|
|
81
21
|
*/
|
|
82
|
-
generation?:
|
|
22
|
+
generation?: 'gen1' | 'gen2' | 'gen3';
|
|
83
23
|
/**
|
|
84
24
|
* ID of GraphQL API. Only (currently) required when using the `--api` flag
|
|
85
25
|
* for `sanity graphql deploy`, in order to only deploy a specific API.
|
|
@@ -114,15 +54,45 @@ export declare interface GraphQLAPIConfig {
|
|
|
114
54
|
*/
|
|
115
55
|
workspace?: string;
|
|
116
56
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
57
|
+
/**
|
|
58
|
+
* @deprecated Use `defineCliConfig` instead
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
declare function createCliConfig(config: CliConfig$1): CliConfig$1;
|
|
62
|
+
/** @beta */
|
|
63
|
+
declare function defineCliConfig(config: CliConfig$1): CliConfig$1;
|
|
64
|
+
/**
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
interface CliApiConfig {
|
|
68
|
+
dataset?: string;
|
|
69
|
+
projectId?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
interface CliClientOptions extends ClientConfig {
|
|
75
|
+
/**
|
|
76
|
+
* If no `projectId` or `dataset` is provided, `getCliClient` will try to
|
|
77
|
+
* resolve these from the `sanity.cli.ts` configuration file. Use this option
|
|
78
|
+
* to specify the directory to look for this file.
|
|
79
|
+
*/
|
|
80
|
+
cwd?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @public
|
|
84
|
+
*
|
|
85
|
+
* @param options - The options to use for the client.
|
|
86
|
+
* @returns A configured Sanity API client.
|
|
87
|
+
*/
|
|
88
|
+
declare const getCliClient: CliClientGetter;
|
|
89
|
+
type CliClientGetter = ((options?: CliClientOptions) => SanityClient) & {
|
|
90
|
+
/**
|
|
91
|
+
* @deprecated This is only for INTERNAL use, and should not be relied upon outside of official Sanity modules
|
|
92
|
+
* @returns A token to use when constructing a client without a `token` explicitly defined, or undefined
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
__internal__getToken: () => string | undefined;
|
|
96
|
+
};
|
|
97
|
+
export { type CliApiConfig, type CliClientOptions, type CliConfig, type DefineAppInput, type DefineMediaLibraryInput, type GraphQLAPIConfig, type MediaLibraryField, type UserViteConfig, createCliConfig, defineCliConfig, getCliClient, loadEnv, unstable_defineApp, unstable_defineMediaLibrary };
|
|
98
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,26 +1,100 @@
|
|
|
1
1
|
import { Config } from "@oclif/core";
|
|
2
2
|
import { SanityEnvironment } from "@sanity/cli-core/executionContext";
|
|
3
|
-
|
|
4
|
-
/** Where an invocation originates; selects the policy to enforce. */
|
|
5
|
-
declare type InvocationSource = "mcp";
|
|
6
|
-
|
|
7
3
|
/**
|
|
8
|
-
*
|
|
4
|
+
* Valid body types for fetch requests.
|
|
9
5
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
6
|
+
* Includes `Uint8Array` since the standard `fetch` accepts typed-array
|
|
7
|
+
* request bodies. It is pinned to `Uint8Array<ArrayBuffer>` (rather than the
|
|
8
|
+
* abstract `ArrayBufferView` or the default `Uint8Array<ArrayBufferLike>`) to
|
|
9
|
+
* stay assignable to the platform `BodyInit` across the DOM and Node lib
|
|
10
|
+
* definitions, which keeps `FetchFunction` compatible with the runtime
|
|
11
|
+
* `fetch`. Widening further breaks that compatibility.
|
|
13
12
|
*
|
|
14
|
-
* @
|
|
13
|
+
* @public
|
|
15
14
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
type FetchBody = string | ArrayBuffer | Uint8Array<ArrayBuffer> | Blob | FormData | URLSearchParams | ReadableStream;
|
|
16
|
+
/**
|
|
17
|
+
* Accepted header formats — tuple pairs, a plain record, or a `Headers` instance.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
type FetchHeaders = [string, string][] | Record<string, string> | Headers;
|
|
22
|
+
/**
|
|
23
|
+
* Init options passed to a {@link FetchFunction}.
|
|
24
|
+
*
|
|
25
|
+
* This is a minimal subset of the standard `RequestInit` so the library
|
|
26
|
+
* doesn't depend on the full DOM lib.
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
interface FetchInit {
|
|
31
|
+
/** HTTP method (GET, POST, PUT, etc.). */
|
|
32
|
+
method?: string;
|
|
33
|
+
/** Request headers. */
|
|
34
|
+
headers?: FetchHeaders;
|
|
35
|
+
/** Request body. */
|
|
36
|
+
body?: FetchBody | null;
|
|
37
|
+
/** Abort signal for cancellation. */
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
/**
|
|
40
|
+
* Redirect handling strategy.
|
|
41
|
+
*
|
|
42
|
+
* ⚠️ In browsers, `'manual'` yields an opaque-redirect response (status `0`,
|
|
43
|
+
* empty headers) per the Fetch spec — you cannot read the status or headers
|
|
44
|
+
* (e.g. `location`) of the 3xx response. Reading them throws nothing and warns
|
|
45
|
+
* nothing: `headers.get()` returns `null` and iteration is empty. Detect it via
|
|
46
|
+
* `status === 0`. Non-browser runtimes (Node.js, Bun, Deno, edge runtimes,
|
|
47
|
+
* workers) return the real 3xx response, so its status and headers are readable.
|
|
48
|
+
*/
|
|
49
|
+
redirect?: 'error' | 'follow' | 'manual';
|
|
50
|
+
/** Credentials mode (browser-only — some runtimes crash if set). */
|
|
51
|
+
credentials?: 'include' | 'omit' | 'same-origin';
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Response object returned by a {@link FetchFunction}.
|
|
55
|
+
*
|
|
56
|
+
* A minimal subset of the standard `Response` — just the properties
|
|
57
|
+
* get-it actually reads.
|
|
58
|
+
*
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
interface FetchResponse {
|
|
62
|
+
/** Whether the response status is in the 200–299 range. */
|
|
63
|
+
ok: boolean;
|
|
64
|
+
/** HTTP status code. */
|
|
65
|
+
status: number;
|
|
66
|
+
/** HTTP status text (e.g. "OK", "Not Found"). */
|
|
67
|
+
statusText: string;
|
|
68
|
+
/** Response headers. */
|
|
69
|
+
headers: Headers;
|
|
70
|
+
/** The final URL after any redirects. */
|
|
71
|
+
url: string;
|
|
72
|
+
/** Whether the response was the result of a redirect. */
|
|
73
|
+
redirected: boolean;
|
|
74
|
+
/** Readable stream of the response body, or `null` if empty. */
|
|
75
|
+
body: ReadableStream<Uint8Array> | null;
|
|
76
|
+
/** Reads the entire body as a string. */
|
|
77
|
+
text(): Promise<string>;
|
|
78
|
+
/** Reads the entire body as an ArrayBuffer. */
|
|
79
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A function that performs an HTTP fetch. Must conform to the standard
|
|
83
|
+
* `fetch()` signature but only needs to return a `FetchResponse`.
|
|
84
|
+
*
|
|
85
|
+
* @param input - The URL to fetch.
|
|
86
|
+
* @param init - Optional request init options.
|
|
87
|
+
* @returns A promise resolving to the response.
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
type FetchFunction = (input: string, init?: FetchInit) => Promise<FetchResponse>;
|
|
92
|
+
/** Where an invocation originates; selects the policy to enforce. */
|
|
93
|
+
type InvocationSource = 'mcp';
|
|
20
94
|
/**
|
|
21
95
|
* @internal
|
|
22
96
|
*/
|
|
23
|
-
|
|
97
|
+
interface InvokeSanityCliOptions {
|
|
24
98
|
/**
|
|
25
99
|
* Arguments after `sanity` (a leading `sanity` token is tolerated), either
|
|
26
100
|
* as a single string — shell-style quoting is supported, but no shell is
|
|
@@ -43,6 +117,13 @@ export declare interface InvokeSanityCliOptions {
|
|
|
43
117
|
* package's config, loaded once and cached across invocations.
|
|
44
118
|
*/
|
|
45
119
|
config?: Config;
|
|
120
|
+
/**
|
|
121
|
+
* Optional fetch implementation for API requests made by this invocation.
|
|
122
|
+
* Scoped to this call via the CLI execution context; defaults to the CLI's
|
|
123
|
+
* own transport. The execution context's transport hygiene (such as
|
|
124
|
+
* stripping the embedding process's lineage header) is applied on top.
|
|
125
|
+
*/
|
|
126
|
+
fetch?: FetchFunction;
|
|
46
127
|
/**
|
|
47
128
|
* Sanity deployment environment for this invocation. Scoped to this call
|
|
48
129
|
* via the CLI execution context and defaults to production. The embedding
|
|
@@ -50,11 +131,10 @@ export declare interface InvokeSanityCliOptions {
|
|
|
50
131
|
*/
|
|
51
132
|
sanityEnv?: SanityEnvironment;
|
|
52
133
|
}
|
|
53
|
-
|
|
54
134
|
/**
|
|
55
135
|
* @internal
|
|
56
136
|
*/
|
|
57
|
-
|
|
137
|
+
interface InvokeSanityCliResult {
|
|
58
138
|
/** `0` on success, the command's exit code otherwise. */
|
|
59
139
|
exitCode: number;
|
|
60
140
|
/** Combined stdout and stderr output, in emission order. */
|
|
@@ -65,5 +145,15 @@ export declare interface InvokeSanityCliResult {
|
|
|
65
145
|
*/
|
|
66
146
|
commandId?: string;
|
|
67
147
|
}
|
|
68
|
-
|
|
69
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Run a policy-permitted CLI command in-process and capture its result.
|
|
150
|
+
*
|
|
151
|
+
* Command-level failures (unknown command, bad flags, API errors) are
|
|
152
|
+
* reported through `exitCode`/`output` rather than thrown, so callers can
|
|
153
|
+
* relay them verbatim.
|
|
154
|
+
*
|
|
155
|
+
* @internal
|
|
156
|
+
*/
|
|
157
|
+
declare function invokeSanityCli(options: InvokeSanityCliOptions): Promise<InvokeSanityCliResult>;
|
|
158
|
+
export { InvokeSanityCliOptions, InvokeSanityCliResult, invokeSanityCli };
|
|
159
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -93,11 +93,12 @@ function unknownCommandResult(argv, policySet) {
|
|
|
93
93
|
const resolvedConfig = options.config ?? await (cachedConfig ??= loadCliCommandConfig());
|
|
94
94
|
const output = [];
|
|
95
95
|
const sink = (line)=>output.push(line);
|
|
96
|
-
const { sanityEnv, token } = options;
|
|
96
|
+
const { fetch, sanityEnv, token } = options;
|
|
97
97
|
// Establish the isolation boundary before rendering help, loading command
|
|
98
98
|
// modules, parsing, or executing. Any code reached by an external
|
|
99
99
|
// invocation can therefore fail closed on context.
|
|
100
100
|
return runWithCliExecutionContext({
|
|
101
|
+
fetch,
|
|
101
102
|
sanityEnv,
|
|
102
103
|
stderr: sink,
|
|
103
104
|
stdout: sink,
|