@sanity/cli 8.22.1 → 8.24.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.
Files changed (98) hide show
  1. package/README.md +313 -0
  2. package/dist/actions/codemods/dashboard.js +136 -8
  3. package/dist/actions/codemods/dashboard.js.map +1 -1
  4. package/dist/actions/codemods/types.js.map +1 -1
  5. package/dist/actions/context/watchJob.js +9 -3
  6. package/dist/actions/context/watchJob.js.map +1 -1
  7. package/dist/actions/deploy/blueprintManaged.js +59 -0
  8. package/dist/actions/deploy/blueprintManaged.js.map +1 -0
  9. package/dist/actions/deploy/deployApp.js +117 -1
  10. package/dist/actions/deploy/deployApp.js.map +1 -1
  11. package/dist/actions/deploy/deployRunner.js.map +1 -1
  12. package/dist/actions/deploy/deployStudio.js +6 -31
  13. package/dist/actions/deploy/deployStudio.js.map +1 -1
  14. package/dist/actions/exec/runScript.worker.js +6 -2
  15. package/dist/actions/exec/runScript.worker.js.map +1 -1
  16. package/dist/actions/init/bootstrapLocalTemplate.js +35 -11
  17. package/dist/actions/init/bootstrapLocalTemplate.js.map +1 -1
  18. package/dist/actions/init/createMediaLibraryCliConfig.js +12 -0
  19. package/dist/actions/init/createMediaLibraryCliConfig.js.map +1 -0
  20. package/dist/actions/init/determineMediaLibraryTemplate.js +14 -0
  21. package/dist/actions/init/determineMediaLibraryTemplate.js.map +1 -0
  22. package/dist/actions/init/initAction.js +35 -6
  23. package/dist/actions/init/initAction.js.map +1 -1
  24. package/dist/actions/init/initApp.js +81 -6
  25. package/dist/actions/init/initApp.js.map +1 -1
  26. package/dist/actions/init/offerAspectPull.js +81 -0
  27. package/dist/actions/init/offerAspectPull.js.map +1 -0
  28. package/dist/actions/init/project/getOrCreateDataset.js +8 -5
  29. package/dist/actions/init/project/getOrCreateDataset.js.map +1 -1
  30. package/dist/actions/init/project/getOrCreateProject.js +7 -5
  31. package/dist/actions/init/project/getOrCreateProject.js.map +1 -1
  32. package/dist/actions/init/project/getProjectDetails.js +25 -2
  33. package/dist/actions/init/project/getProjectDetails.js.map +1 -1
  34. package/dist/actions/init/project/promptUserForOrganization.js +6 -4
  35. package/dist/actions/init/project/promptUserForOrganization.js.map +1 -1
  36. package/dist/actions/init/templates/index.js +3 -0
  37. package/dist/actions/init/templates/index.js.map +1 -1
  38. package/dist/actions/init/templates/mediaLibraryConfig.js +51 -0
  39. package/dist/actions/init/templates/mediaLibraryConfig.js.map +1 -0
  40. package/dist/actions/media/aspectName.js +8 -0
  41. package/dist/actions/media/aspectName.js.map +1 -0
  42. package/dist/actions/media/aspectSync/contract.js +163 -0
  43. package/dist/actions/media/aspectSync/contract.js.map +1 -0
  44. package/dist/actions/media/aspectSync/syncAspects.js +115 -0
  45. package/dist/actions/media/aspectSync/syncAspects.js.map +1 -0
  46. package/dist/actions/media/cliConfigFields.js +192 -0
  47. package/dist/actions/media/cliConfigFields.js.map +1 -0
  48. package/dist/actions/media/pullAspects.js +225 -0
  49. package/dist/actions/media/pullAspects.js.map +1 -0
  50. package/dist/actions/media/resolveMediaLibraryId.js +83 -0
  51. package/dist/actions/media/resolveMediaLibraryId.js.map +1 -0
  52. package/dist/commands/codemod.js +1 -0
  53. package/dist/commands/codemod.js.map +1 -1
  54. package/dist/commands/context/build.js +2 -2
  55. package/dist/commands/context/build.js.map +1 -1
  56. package/dist/commands/context/entries/get.js +83 -0
  57. package/dist/commands/context/entries/get.js.map +1 -0
  58. package/dist/commands/context/entries/list.js +82 -0
  59. package/dist/commands/context/entries/list.js.map +1 -0
  60. package/dist/commands/context/entries/rebuild.js +95 -0
  61. package/dist/commands/context/entries/rebuild.js.map +1 -0
  62. package/dist/commands/context/issues/apply.js +86 -0
  63. package/dist/commands/context/issues/apply.js.map +1 -0
  64. package/dist/commands/context/issues/dismiss.js +52 -0
  65. package/dist/commands/context/issues/dismiss.js.map +1 -0
  66. package/dist/commands/context/issues/get.js +105 -0
  67. package/dist/commands/context/issues/get.js.map +1 -0
  68. package/dist/commands/context/issues/list.js +128 -0
  69. package/dist/commands/context/issues/list.js.map +1 -0
  70. package/dist/commands/context/issues/reopen.js +53 -0
  71. package/dist/commands/context/issues/reopen.js.map +1 -0
  72. package/dist/commands/context/issues/resolve.js +137 -0
  73. package/dist/commands/context/issues/resolve.js.map +1 -0
  74. package/dist/commands/context/jobs/get.js +2 -2
  75. package/dist/commands/context/jobs/get.js.map +1 -1
  76. package/dist/commands/context/query.js +92 -0
  77. package/dist/commands/context/query.js.map +1 -0
  78. package/dist/commands/deploy.js +13 -0
  79. package/dist/commands/deploy.js.map +1 -1
  80. package/dist/commands/media/prune-aspect-data.js +170 -0
  81. package/dist/commands/media/prune-aspect-data.js.map +1 -0
  82. package/dist/commands/media/pull-aspects.js +309 -0
  83. package/dist/commands/media/pull-aspects.js.map +1 -0
  84. package/dist/exports/invokeSanityCli/commandPolicies/mcpPolicy.js +17 -0
  85. package/dist/exports/invokeSanityCli/commandPolicies/mcpPolicy.js.map +1 -1
  86. package/dist/services/context.js +96 -3
  87. package/dist/services/context.js.map +1 -1
  88. package/dist/services/mediaLibraries.js +175 -8
  89. package/dist/services/mediaLibraries.js.map +1 -1
  90. package/dist/util/searchChoices.js +52 -0
  91. package/dist/util/searchChoices.js.map +1 -0
  92. package/oclif.manifest.json +2134 -1445
  93. package/package.json +9 -8
  94. package/templates/media-library-config/README.md +52 -0
  95. package/templates/media-library-config/eslint.config.txt +52 -0
  96. package/templates/media-library-config/src/fields/caption.tsx +29 -0
  97. package/templates/media-library-config/src/fields/notes.tsx +54 -0
  98. package/templates/shopify/.gitignore +0 -26
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/codemod.ts"],"sourcesContent":["import {execSync, spawn} from 'node:child_process'\nimport {existsSync} from 'node:fs'\nimport path from 'node:path'\n\nimport {Args, Flags} from '@oclif/core'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\n\nimport {codemods} from '../actions/codemods/index.js'\nimport {type CodeMod} from '../actions/codemods/types.js'\n\nconst codemodeDebug = subdebug('codemod')\n\nexport class CodemodCommand extends SanityCommand<typeof CodemodCommand> {\n static override args = {\n codemodName: Args.string({\n description: 'Name of the codemod to run',\n required: false,\n }),\n }\n\n static override description = 'Updates Sanity Studio codebase with a code modification script'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'Show available code mods',\n },\n {\n command: '<%= config.bin %> <%= command.id %> reactIconsV3 --dry',\n description: 'Run codemod to transform react-icons imports (dry run)',\n },\n ]\n\n static override flags = {\n dry: Flags.boolean({\n default: false,\n description: 'Dry run (no changes are made to files)',\n }),\n extensions: Flags.string({\n default: 'js,ts,tsx',\n description: 'Transform files with these file extensions (comma separated)',\n }),\n 'no-verify': Flags.boolean({\n default: false,\n description: 'Skip verification steps before running codemod',\n }),\n }\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(CodemodCommand)\n const {codemodName} = args\n const workDir = process.cwd()\n\n if (!codemodName) {\n this.printMods()\n return\n }\n\n // Make a record where all the keys of the available codemods are lowercased,\n // eg `reactIconsV3` turns into `{reacticonsv3: CodeMod}`\n const normalizedMods: Map<string, CodeMod> = new Map()\n for (const [originalName, mod] of Object.entries(codemods)) {\n normalizedMods.set(originalName.toLowerCase(), mod)\n }\n\n // Verify that mod exists\n const mod = normalizedMods.get(codemodName.toLowerCase())\n if (!mod) {\n this.error(`Codemod with name \"${codemodName}\" not found`, {exit: exitCodes.RUNTIME_ERROR})\n }\n\n // Verify if there is any verification defined, and user has not opted out of it\n if (typeof mod.verify === 'function' && !flags['no-verify']) {\n try {\n await mod.verify({workDir})\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error))\n codemodeDebug('Verification failed: %s', err.message)\n this.error(`Verification failed: ${err.message}`, {exit: exitCodes.RUNTIME_ERROR})\n }\n }\n\n // If extensions are defined, they come in as CSV, so split and normalize them\n const exts = flags.extensions\n ? flags.extensions.split(',').map((ext) => ext.trim().replace(/^\\./, ''))\n : ['js', 'ts', 'tsx']\n\n const dryRun = flags.dry\n\n // We use npx to run jscodeshift, so verify that it exists and works before using it\n this.ensureNpx()\n\n const prepared = await mod.prepare?.({output: this.output, workDir})\n // jscodeshift JSON-parses option values, so encode them to keep strings like \"2024\" as strings\n const transformOptions = Object.entries(prepared?.options ?? {}).map(\n ([key, value]) => `--${key}=${JSON.stringify(value)}`,\n )\n\n // If there is a gitignore in the target folder, we want to use that to know\n // which folders to ignore - eg `dist`, `coverage` or whatever\n const hasGitIgnore = existsSync(path.join(workDir, '.gitignore'))\n\n // Build the CLI command arguments\n const cliRoot = path.resolve(import.meta.dirname, '../..')\n const modPath = path.resolve(path.join(cliRoot, 'codemods', mod.filename))\n const cmdArgs = [\n 'jscodeshift',\n '--ignore-pattern',\n 'node_modules',\n '--ignore-pattern',\n 'dist',\n hasGitIgnore && '--ignore-config',\n hasGitIgnore && '.gitignore',\n '-t',\n modPath,\n '--extensions',\n exts.join(','),\n dryRun && '--dry',\n ...transformOptions,\n ...(prepared?.paths ?? [workDir]),\n ].filter((item): item is string => typeof item === 'string')\n\n const child = spawn('npx', cmdArgs, {\n stdio: 'inherit',\n })\n\n const handleSigint = () => {\n child.kill(2)\n }\n\n process.on('SIGINT', handleSigint)\n\n // Wait inside run() so oclif handles the exit, rather than throwing from an event callback\n const code = await new Promise<number | null>((resolve) => {\n child.on('close', resolve)\n })\n process.removeListener('SIGINT', handleSigint)\n this.exit(code || undefined)\n }\n\n private ensureNpx(): void {\n try {\n const npxHelp = execSync('npx --help', {encoding: 'utf8'})\n if (!npxHelp.includes('npm')) {\n this.error('Not the npx we expected', {exit: exitCodes.RUNTIME_ERROR})\n }\n } catch {\n this.error(\n `Failed to run \"npx\" - required to run codemods. Do you have a recent version of npm installed?`,\n {exit: exitCodes.RUNTIME_ERROR},\n )\n }\n }\n\n private printMods(): void {\n this.log('Available code modifications:\\n')\n\n for (const [modName, mod] of Object.entries(codemods)) {\n this.log(`${modName} - ${mod.purpose}`)\n }\n }\n}\n"],"names":["execSync","spawn","existsSync","path","Args","Flags","exitCodes","SanityCommand","subdebug","codemods","codemodeDebug","CodemodCommand","args","codemodName","string","description","required","examples","command","flags","dry","boolean","default","extensions","run","parse","workDir","process","cwd","printMods","normalizedMods","Map","originalName","mod","Object","entries","set","toLowerCase","get","error","exit","RUNTIME_ERROR","verify","err","Error","String","message","exts","split","map","ext","trim","replace","dryRun","ensureNpx","prepared","prepare","output","transformOptions","options","key","value","JSON","stringify","hasGitIgnore","join","cliRoot","resolve","dirname","modPath","filename","cmdArgs","paths","filter","item","child","stdio","handleSigint","kill","on","code","Promise","removeListener","undefined","npxHelp","encoding","includes","log","modName","purpose"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,KAAK,QAAO,qBAAoB;AAClD,SAAQC,UAAU,QAAO,UAAS;AAClC,OAAOC,UAAU,YAAW;AAE5B,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa;AACvC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AAEnE,SAAQC,QAAQ,QAAO,+BAA8B;AAGrD,MAAMC,gBAAgBF,SAAS;AAE/B,OAAO,MAAMG,uBAAuBJ;IAClC,OAAgBK,OAAO;QACrBC,aAAaT,KAAKU,MAAM,CAAC;YACvBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,iEAAgE;IAE9F,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;KACD,CAAA;IAED,OAAgBI,QAAQ;QACtBC,KAAKf,MAAMgB,OAAO,CAAC;YACjBC,SAAS;YACTP,aAAa;QACf;QACAQ,YAAYlB,MAAMS,MAAM,CAAC;YACvBQ,SAAS;YACTP,aAAa;QACf;QACA,aAAaV,MAAMgB,OAAO,CAAC;YACzBC,SAAS;YACTP,aAAa;QACf;IACF,EAAC;IAED,MAAaS,MAAqB;QAChC,MAAM,EAACZ,IAAI,EAAEO,KAAK,EAAC,GAAG,MAAM,IAA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AAC,QAAQ;gBAC5B,IAAI,CAAC/C,KAAK,CAAC,2BAA2B;oBAACC,MAAMlC,UAAUmC,aAAa;gBAAA;YACtE;QACF,EAAE,OAAM;YACN,IAAI,CAACF,KAAK,CACR,CAAC,8FAA8F,CAAC,EAChG;gBAACC,MAAMlC,UAAUmC,aAAa;YAAA;QAElC;IACF;IAEQZ,YAAkB;QACxB,IAAI,CAAC0D,GAAG,CAAC;QAET,KAAK,MAAM,CAACC,SAASvD,IAAI,IAAIC,OAAOC,OAAO,CAAC1B,UAAW;YACrD,IAAI,CAAC8E,GAAG,CAAC,GAAGC,QAAQ,GAAG,EAAEvD,IAAIwD,OAAO,EAAE;QACxC;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/commands/codemod.ts"],"sourcesContent":["import {execSync, spawn} from 'node:child_process'\nimport {existsSync} from 'node:fs'\nimport path from 'node:path'\n\nimport {Args, Flags} from '@oclif/core'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\n\nimport {codemods} from '../actions/codemods/index.js'\nimport {type CodeMod} from '../actions/codemods/types.js'\n\nconst codemodeDebug = subdebug('codemod')\n\nexport class CodemodCommand extends SanityCommand<typeof CodemodCommand> {\n static override args = {\n codemodName: Args.string({\n description: 'Name of the codemod to run',\n required: false,\n }),\n }\n\n static override description = 'Updates Sanity Studio codebase with a code modification script'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'Show available code mods',\n },\n {\n command: '<%= config.bin %> <%= command.id %> reactIconsV3 --dry',\n description: 'Run codemod to transform react-icons imports (dry run)',\n },\n ]\n\n static override flags = {\n dry: Flags.boolean({\n default: false,\n description: 'Dry run (no changes are made to files)',\n }),\n extensions: Flags.string({\n default: 'js,ts,tsx',\n description: 'Transform files with these file extensions (comma separated)',\n }),\n 'no-verify': Flags.boolean({\n default: false,\n description: 'Skip verification steps before running codemod',\n }),\n }\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(CodemodCommand)\n const {codemodName} = args\n const workDir = process.cwd()\n\n if (!codemodName) {\n this.printMods()\n return\n }\n\n // Make a record where all the keys of the available codemods are lowercased,\n // eg `reactIconsV3` turns into `{reacticonsv3: CodeMod}`\n const normalizedMods: Map<string, CodeMod> = new Map()\n for (const [originalName, mod] of Object.entries(codemods)) {\n normalizedMods.set(originalName.toLowerCase(), mod)\n }\n\n // Verify that mod exists\n const mod = normalizedMods.get(codemodName.toLowerCase())\n if (!mod) {\n this.error(`Codemod with name \"${codemodName}\" not found`, {exit: exitCodes.RUNTIME_ERROR})\n }\n\n // Verify if there is any verification defined, and user has not opted out of it\n if (typeof mod.verify === 'function' && !flags['no-verify']) {\n try {\n await mod.verify({workDir})\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error))\n codemodeDebug('Verification failed: %s', err.message)\n this.error(`Verification failed: ${err.message}`, {exit: exitCodes.RUNTIME_ERROR})\n }\n }\n\n // If extensions are defined, they come in as CSV, so split and normalize them\n const exts = flags.extensions\n ? flags.extensions.split(',').map((ext) => ext.trim().replace(/^\\./, ''))\n : ['js', 'ts', 'tsx']\n\n const dryRun = flags.dry\n\n // We use npx to run jscodeshift, so verify that it exists and works before using it\n this.ensureNpx()\n\n const prepared = await mod.prepare?.({dry: dryRun, output: this.output, workDir})\n // jscodeshift JSON-parses option values, so encode them to keep strings like \"2024\" as strings\n const transformOptions = Object.entries(prepared?.options ?? {}).map(\n ([key, value]) => `--${key}=${JSON.stringify(value)}`,\n )\n\n // If there is a gitignore in the target folder, we want to use that to know\n // which folders to ignore - eg `dist`, `coverage` or whatever\n const hasGitIgnore = existsSync(path.join(workDir, '.gitignore'))\n\n // Build the CLI command arguments\n const cliRoot = path.resolve(import.meta.dirname, '../..')\n const modPath = path.resolve(path.join(cliRoot, 'codemods', mod.filename))\n const cmdArgs = [\n 'jscodeshift',\n '--ignore-pattern',\n 'node_modules',\n '--ignore-pattern',\n 'dist',\n hasGitIgnore && '--ignore-config',\n hasGitIgnore && '.gitignore',\n '-t',\n modPath,\n '--extensions',\n exts.join(','),\n dryRun && '--dry',\n ...transformOptions,\n ...(prepared?.paths ?? [workDir]),\n ].filter((item): item is string => typeof item === 'string')\n\n const child = spawn('npx', cmdArgs, {\n stdio: 'inherit',\n })\n\n const handleSigint = () => {\n child.kill(2)\n }\n\n process.on('SIGINT', handleSigint)\n\n // Wait inside run() so oclif handles the exit, rather than throwing from an event callback\n const code = await new Promise<number | null>((resolve) => {\n child.on('close', resolve)\n })\n process.removeListener('SIGINT', handleSigint)\n this.exit(code || undefined)\n }\n\n private ensureNpx(): void {\n try {\n const npxHelp = execSync('npx --help', {encoding: 'utf8'})\n if (!npxHelp.includes('npm')) {\n this.error('Not the npx we expected', {exit: exitCodes.RUNTIME_ERROR})\n }\n } catch {\n this.error(\n `Failed to run \"npx\" - required to run codemods. Do you have a recent version of npm installed?`,\n {exit: exitCodes.RUNTIME_ERROR},\n )\n }\n }\n\n private printMods(): void {\n this.log('Available code modifications:\\n')\n\n for (const [modName, mod] of Object.entries(codemods)) {\n this.log(`${modName} - ${mod.purpose}`)\n }\n }\n}\n"],"names":["execSync","spawn","existsSync","path","Args","Flags","exitCodes","SanityCommand","subdebug","codemods","codemodeDebug","CodemodCommand","args","codemodName","string","description","required","examples","command","flags","dry","boolean","default","extensions","run","parse","workDir","process","cwd","printMods","normalizedMods","Map","originalName","mod","Object","entries","set","toLowerCase","get","error","exit","RUNTIME_ERROR","verify","err","Error","String","message","exts","split","map","ext","trim","replace","dryRun","ensureNpx","prepared","prepare","output","transformOptions","options","key","value","JSON","stringify","hasGitIgnore","join","cliRoot","resolve","dirname","modPath","filename","cmdArgs","paths","filter","item","child","stdio","handleSigint","kill","on","code","Promise","removeListener","undefined","npxHelp","encoding","includes","log","modName","purpose"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,KAAK,QAAO,qBAAoB;AAClD,SAAQC,UAAU,QAAO,UAAS;AAClC,OAAOC,UAAU,YAAW;AAE5B,SAAQC,IAAI,EAAEC,KAAK,QAAO,cAAa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SAAS,YAAYjC,IAAIqC,QAAQ;QACxE,MAAMC,UAAU;YACd;YACA;YACA;YACA;YACA;YACAP,gBAAgB;YAChBA,gBAAgB;YAChB;YACAK;YACA;YACAtB,KAAKkB,IAAI,CAAC;YACVZ,UAAU;eACPK;eACCH,UAAUiB,SAAS;gBAAC9C;aAAQ;SACjC,CAAC+C,MAAM,CAAC,CAACC,OAAyB,OAAOA,SAAS;QAEnD,MAAMC,QAAQ1E,MAAM,OAAOsE,SAAS;YAClCK,OAAO;QACT;QAEA,MAAMC,eAAe;YACnBF,MAAMG,IAAI,CAAC;QACb;QAEAnD,QAAQoD,EAAE,CAAC,UAAUF;QAErB,2FAA2F;QAC3F,MAAMG,OAAO,MAAM,IAAIC,QAAuB,CAACd;YAC7CQ,MAAMI,EAAE,CAAC,SAASZ;QACpB;QACAxC,QAAQuD,cAAc,CAAC,UAAUL;QACjC,IAAI,CAACrC,IAAI,CAACwC,QAAQG;IACpB;IAEQ7B,YAAkB;QACxB,IAAI;YACF,MAAM8B,UAAUpF,SAAS,cAAc;gBAACqF,UAAU;YAAM;YACxD,IAAI,CAACD,QAAQE,QAAQ,CAAC,QAAQ;gBAC5B,IAAI,CAAC/C,KAAK,CAAC,2BAA2B;oBAACC,MAAMlC,UAAUmC,aAAa;gBAAA;YACtE;QACF,EAAE,OAAM;YACN,IAAI,CAACF,KAAK,CACR,CAAC,8FAA8F,CAAC,EAChG;gBAACC,MAAMlC,UAAUmC,aAAa;YAAA;QAElC;IACF;IAEQZ,YAAkB;QACxB,IAAI,CAAC0D,GAAG,CAAC;QAET,KAAK,MAAM,CAACC,SAASvD,IAAI,IAAIC,OAAOC,OAAO,CAAC1B,UAAW;YACrD,IAAI,CAAC8E,GAAG,CAAC,GAAGC,QAAQ,GAAG,EAAEvD,IAAIwD,OAAO,EAAE;QACxC;IACF;AACF"}
@@ -3,7 +3,7 @@ import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
3
  import { getErrorMessage } from '@sanity/cli-core/errors';
4
4
  import { spinner } from '@sanity/cli-core/ux';
5
5
  import { isHttpError } from '@sanity/client';
6
- import { watchJob } from '../../actions/context/watchJob.js';
6
+ import { formatJobFailure, watchJob } from '../../actions/context/watchJob.js';
7
7
  import { formatKeyValue } from '../../actions/debug/output.js';
8
8
  import { buildKnowledgeBase, cancelKnowledgeBaseBuild } from '../../services/context.js';
9
9
  const buildContextDebug = subdebug('context:build');
@@ -85,7 +85,7 @@ export class BuildKnowledgeBaseCommand extends SanityCommand {
85
85
  });
86
86
  }
87
87
  if (job.status !== 'succeeded') {
88
- this.error(`Build ${job.status}${job.error ? `: ${job.error}` : ''}`, {
88
+ this.error(formatJobFailure('Build', job), {
89
89
  exit: exitCodes.RUNTIME_ERROR
90
90
  });
91
91
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/commands/context/build.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {isHttpError} from '@sanity/client'\n\nimport {watchJob} from '../../actions/context/watchJob.js'\nimport {formatKeyValue} from '../../actions/debug/output.js'\nimport {buildKnowledgeBase, cancelKnowledgeBaseBuild} from '../../services/context.js'\n\nconst buildContextDebug = subdebug('context:build')\n\nexport class BuildKnowledgeBaseCommand extends SanityCommand<typeof BuildKnowledgeBaseCommand> {\n static override args = {\n knowledgeBaseId: Args.string({\n description: 'Knowledge base ID',\n required: true,\n }),\n }\n\n static override description = 'Build a knowledge base from its imported content'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123',\n description: 'Start a build and return the job ID',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 --watch',\n description: 'Start a build and wait for it to finish (non-zero exit on failure)',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 --cancel',\n description: 'Cancel the running build, if any',\n },\n ]\n\n static override flags = {\n cancel: Flags.boolean({\n default: false,\n description: 'Cancel the running build instead of starting one',\n exclusive: ['watch'],\n }),\n watch: Flags.boolean({\n default: false,\n description: 'Wait for the build to finish, exiting non-zero if it fails',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {knowledgeBaseId} = this.args\n const {cancel, watch} = this.flags\n\n if (cancel) {\n await this.cancelBuild(knowledgeBaseId)\n return\n }\n\n let jobId: string\n const spin = spinner('Starting build').start()\n try {\n const accepted = await buildKnowledgeBase(knowledgeBaseId)\n jobId = accepted.jobId\n spin.succeed('Build started')\n } catch (error) {\n spin.fail()\n buildContextDebug('Error starting build', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Knowledge base \"${knowledgeBaseId}\" not found`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to start build: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n this.log(formatKeyValue('Job ID', jobId))\n this.log(`Track it with: sanity context jobs get ${knowledgeBaseId} ${jobId}`)\n\n if (!watch) {\n return\n }\n\n let job\n try {\n job = await watchJob(knowledgeBaseId, jobId, {\n label: 'Building knowledge base',\n successText: 'Build succeeded',\n })\n } catch (error) {\n buildContextDebug('Error watching build job', error)\n this.error(`Failed to watch build job: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (job.status !== 'succeeded') {\n this.error(`Build ${job.status}${job.error ? `: ${job.error}` : ''}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n\n private async cancelBuild(knowledgeBaseId: string): Promise<void> {\n try {\n const {cancelled} = await cancelKnowledgeBaseBuild(knowledgeBaseId)\n this.log(cancelled ? 'Build cancelled' : 'No running build to cancel')\n } catch (error) {\n buildContextDebug('Error cancelling build', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Knowledge base \"${knowledgeBaseId}\" not found`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to cancel build: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n}\n"],"names":["Args","Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","spinner","isHttpError","watchJob","formatKeyValue","buildKnowledgeBase","cancelKnowledgeBaseBuild","buildContextDebug","BuildKnowledgeBaseCommand","args","knowledgeBaseId","string","description","required","examples","command","flags","cancel","boolean","default","exclusive","watch","run","cancelBuild","jobId","spin","start","accepted","succeed","error","fail","statusCode","exit","RUNTIME_ERROR","log","job","label","successText","status","cancelled"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AAEvC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,QAAQ,QAAO,oCAAmC;AAC1D,SAAQC,cAAc,QAAO,gCAA+B;AAC5D,SAAQC,kBAAkB,EAAEC,wBAAwB,QAAO,4BAA2B;AAEtF,MAAMC,oBAAoBR,SAAS;AAEnC,OAAO,MAAMS,kCAAkCV;IAC7C,OAAgBW,OAAO;QACrBC,iBAAiBf,KAAKgB,MAAM,CAAC;YAC3BC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,mDAAkD;IAEhF,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;QACtBC,QAAQrB,MAAMsB,OAAO,CAAC;YACpBC,SAAS;YACTP,aAAa;YACbQ,WAAW;gBAAC;aAAQ;QACtB;QACAC,OAAOzB,MAAMsB,OAAO,CAAC;YACnBC,SAAS;YACTP,aAAa;QACf;IACF,EA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,IAAI,CAACT,KAAK,CAAC,CAAC,MAAM,EAAEM,IAAIG,MAAM,GAAGH,IAAIN,KAAK,GAAG,CAAC,EAAE,EAAEM,IAAIN,KAAK,EAAE,GAAG,IAAI,EAAE;gBACpEG,MAAMnC,UAAUoC,aAAa;YAC/B;QACF;IACF;IAEA,MAAcV,YAAYb,eAAuB,EAAiB;QAChE,IAAI;YACF,MAAM,EAAC6B,SAAS,EAAC,GAAG,MAAMjC,yBAAyBI;YACnD,IAAI,CAACwB,GAAG,CAACK,YAAY,oBAAoB;QAC3C,EAAE,OAAOV,OAAO;YACdtB,kBAAkB,0BAA0BsB;YAC5C,IAAI3B,YAAY2B,UAAUA,MAAME,UAAU,KAAK,KAAK;gBAClD,IAAI,CAACF,KAAK,CAAC,CAAC,gBAAgB,EAAEnB,gBAAgB,WAAW,CAAC,EAAE;oBAC1DsB,MAAMnC,UAAUoC,aAAa;gBAC/B;YACF;YACA,IAAI,CAACJ,KAAK,CAAC,CAAC,wBAAwB,EAAE7B,gBAAgB6B,QAAQ,EAAE;gBAC9DG,MAAMnC,UAAUoC,aAAa;YAC/B;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/commands/context/build.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {isHttpError} from '@sanity/client'\n\nimport {formatJobFailure, watchJob} from '../../actions/context/watchJob.js'\nimport {formatKeyValue} from '../../actions/debug/output.js'\nimport {buildKnowledgeBase, cancelKnowledgeBaseBuild} from '../../services/context.js'\n\nconst buildContextDebug = subdebug('context:build')\n\nexport class BuildKnowledgeBaseCommand extends SanityCommand<typeof BuildKnowledgeBaseCommand> {\n static override args = {\n knowledgeBaseId: Args.string({\n description: 'Knowledge base ID',\n required: true,\n }),\n }\n\n static override description = 'Build a knowledge base from its imported content'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123',\n description: 'Start a build and return the job ID',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 --watch',\n description: 'Start a build and wait for it to finish (non-zero exit on failure)',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 --cancel',\n description: 'Cancel the running build, if any',\n },\n ]\n\n static override flags = {\n cancel: Flags.boolean({\n default: false,\n description: 'Cancel the running build instead of starting one',\n exclusive: ['watch'],\n }),\n watch: Flags.boolean({\n default: false,\n description: 'Wait for the build to finish, exiting non-zero if it fails',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {knowledgeBaseId} = this.args\n const {cancel, watch} = this.flags\n\n if (cancel) {\n await this.cancelBuild(knowledgeBaseId)\n return\n }\n\n let jobId: string\n const spin = spinner('Starting build').start()\n try {\n const accepted = await buildKnowledgeBase(knowledgeBaseId)\n jobId = accepted.jobId\n spin.succeed('Build started')\n } catch (error) {\n spin.fail()\n buildContextDebug('Error starting build', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Knowledge base \"${knowledgeBaseId}\" not found`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to start build: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n this.log(formatKeyValue('Job ID', jobId))\n this.log(`Track it with: sanity context jobs get ${knowledgeBaseId} ${jobId}`)\n\n if (!watch) {\n return\n }\n\n let job\n try {\n job = await watchJob(knowledgeBaseId, jobId, {\n label: 'Building knowledge base',\n successText: 'Build succeeded',\n })\n } catch (error) {\n buildContextDebug('Error watching build job', error)\n this.error(`Failed to watch build job: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (job.status !== 'succeeded') {\n this.error(formatJobFailure('Build', job), {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n\n private async cancelBuild(knowledgeBaseId: string): Promise<void> {\n try {\n const {cancelled} = await cancelKnowledgeBaseBuild(knowledgeBaseId)\n this.log(cancelled ? 'Build cancelled' : 'No running build to cancel')\n } catch (error) {\n buildContextDebug('Error cancelling build', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Knowledge base \"${knowledgeBaseId}\" not found`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to cancel build: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n}\n"],"names":["Args","Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","spinner","isHttpError","formatJobFailure","watchJob","formatKeyValue","buildKnowledgeBase","cancelKnowledgeBaseBuild","buildContextDebug","BuildKnowledgeBaseCommand","args","knowledgeBaseId","string","description","required","examples","command","flags","cancel","boolean","default","exclusive","watch","run","cancelBuild","jobId","spin","start","accepted","succeed","error","fail","statusCode","exit","RUNTIME_ERROR","log","job","label","successText","status","cancelled"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AAEvC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,gBAAgB,EAAEC,QAAQ,QAAO,oCAAmC;AAC5E,SAAQC,cAAc,QAAO,gCAA+B;AAC5D,SAAQC,kBAAkB,EAAEC,wBAAwB,QAAO,4BAA2B;AAEtF,MAAMC,oBAAoBT,SAAS;AAEnC,OAAO,MAAMU,kCAAkCX;IAC7C,OAAgBY,OAAO;QACrBC,iBAAiBhB,KAAKiB,MAAM,CAAC;YAC3BC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,mDAAkD;IAEhF,OAAgBE,WAAW;QACzB;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SAAS;YACTH,aAAa;QACf;QAC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PC,aAAa;YACf;QACF,EAAE,OAAOR,OAAO;YACdtB,kBAAkB,4BAA4BsB;YAC9C,IAAI,CAACA,KAAK,CAAC,CAAC,2BAA2B,EAAE9B,gBAAgB8B,QAAQ,EAAE;gBACjEG,MAAMpC,UAAUqC,aAAa;YAC/B;QACF;QAEA,IAAIE,IAAIG,MAAM,KAAK,aAAa;YAC9B,IAAI,CAACT,KAAK,CAAC3B,iBAAiB,SAASiC,MAAM;gBACzCH,MAAMpC,UAAUqC,aAAa;YAC/B;QACF;IACF;IAEA,MAAcV,YAAYb,eAAuB,EAAiB;QAChE,IAAI;YACF,MAAM,EAAC6B,SAAS,EAAC,GAAG,MAAMjC,yBAAyBI;YACnD,IAAI,CAACwB,GAAG,CAACK,YAAY,oBAAoB;QAC3C,EAAE,OAAOV,OAAO;YACdtB,kBAAkB,0BAA0BsB;YAC5C,IAAI5B,YAAY4B,UAAUA,MAAME,UAAU,KAAK,KAAK;gBAClD,IAAI,CAACF,KAAK,CAAC,CAAC,gBAAgB,EAAEnB,gBAAgB,WAAW,CAAC,EAAE;oBAC1DsB,MAAMpC,UAAUqC,aAAa;gBAC/B;YACF;YACA,IAAI,CAACJ,KAAK,CAAC,CAAC,wBAAwB,EAAE9B,gBAAgB8B,QAAQ,EAAE;gBAC9DG,MAAMpC,UAAUqC,aAAa;YAC/B;QACF;IACF;AACF"}
@@ -0,0 +1,83 @@
1
+ import { Args } from '@oclif/core';
2
+ import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
+ import { getErrorMessage } from '@sanity/cli-core/errors';
4
+ import { isHttpError } from '@sanity/client';
5
+ import { formatKeyValue } from '../../../actions/debug/output.js';
6
+ import { getEntry } from '../../../services/context.js';
7
+ const getEntryDebug = subdebug('context:entries:get');
8
+ export class GetEntryCommand extends SanityCommand {
9
+ static args = {
10
+ knowledgeBaseId: Args.string({
11
+ description: 'Knowledge base ID',
12
+ required: true
13
+ }),
14
+ path: Args.string({
15
+ description: 'Entry path, as listed by `sanity context entries list`',
16
+ required: true
17
+ })
18
+ };
19
+ static description = 'Get an entry and its content';
20
+ static enableJsonFlag = true;
21
+ static examples = [
22
+ {
23
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 billing/refunds',
24
+ description: 'Print an entry and its content'
25
+ },
26
+ {
27
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 billing/refunds --json',
28
+ description: 'Output the entry, including citations, as JSON'
29
+ }
30
+ ];
31
+ async run() {
32
+ const { knowledgeBaseId, path } = this.args;
33
+ const { json } = this.flags;
34
+ let entry;
35
+ try {
36
+ entry = await getEntry(knowledgeBaseId, path);
37
+ } catch (error) {
38
+ getEntryDebug('Error getting entry', error);
39
+ if (isHttpError(error) && error.statusCode === 404) {
40
+ this.error(`Knowledge base "${knowledgeBaseId}" not found`, {
41
+ exit: exitCodes.RUNTIME_ERROR
42
+ });
43
+ }
44
+ this.error(`Failed to get entry: ${getErrorMessage(error)}`, {
45
+ exit: exitCodes.RUNTIME_ERROR
46
+ });
47
+ }
48
+ if (!entry) {
49
+ this.error(`Entry "${path}" not found on knowledge base "${knowledgeBaseId}"`, {
50
+ exit: exitCodes.RUNTIME_ERROR
51
+ });
52
+ }
53
+ if (json) {
54
+ this.logJson(entry);
55
+ return;
56
+ }
57
+ const padTo = 9 // "Citations" and "Generated" are the longest keys
58
+ ;
59
+ this.log(formatKeyValue('Path', entry.path, {
60
+ padTo
61
+ }));
62
+ this.log(formatKeyValue('Title', entry.title, {
63
+ padTo
64
+ }));
65
+ this.log(formatKeyValue('Status', entry.status, {
66
+ padTo
67
+ }));
68
+ this.log(formatKeyValue('Scope', entry.tldr?.scope ?? '-', {
69
+ padTo
70
+ }));
71
+ this.log(formatKeyValue('Citations', String(entry.citations?.length ?? 0), {
72
+ padTo
73
+ }));
74
+ this.log(formatKeyValue('Generated', entry.generatedAt, {
75
+ padTo
76
+ }));
77
+ if (entry.body) {
78
+ this.log(`\n${entry.body}`);
79
+ }
80
+ }
81
+ }
82
+
83
+ //# sourceMappingURL=get.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/commands/context/entries/get.ts"],"sourcesContent":["import {Args} from '@oclif/core'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {isHttpError} from '@sanity/client'\n\nimport {formatKeyValue} from '../../../actions/debug/output.js'\nimport {getEntry} from '../../../services/context.js'\n\nconst getEntryDebug = subdebug('context:entries:get')\n\nexport class GetEntryCommand extends SanityCommand<typeof GetEntryCommand> {\n static override args = {\n knowledgeBaseId: Args.string({\n description: 'Knowledge base ID',\n required: true,\n }),\n path: Args.string({\n description: 'Entry path, as listed by `sanity context entries list`',\n required: true,\n }),\n }\n\n static override description = 'Get an entry and its content'\n\n static override enableJsonFlag = true\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 billing/refunds',\n description: 'Print an entry and its content',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 billing/refunds --json',\n description: 'Output the entry, including citations, as JSON',\n },\n ]\n\n public async run(): Promise<void> {\n const {knowledgeBaseId, path} = this.args\n const {json} = this.flags\n\n let entry\n try {\n entry = await getEntry(knowledgeBaseId, path)\n } catch (error) {\n getEntryDebug('Error getting entry', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Knowledge base \"${knowledgeBaseId}\" not found`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to get entry: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (!entry) {\n this.error(`Entry \"${path}\" not found on knowledge base \"${knowledgeBaseId}\"`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.logJson(entry)\n return\n }\n\n const padTo = 9 // \"Citations\" and \"Generated\" are the longest keys\n this.log(formatKeyValue('Path', entry.path, {padTo}))\n this.log(formatKeyValue('Title', entry.title, {padTo}))\n this.log(formatKeyValue('Status', entry.status, {padTo}))\n this.log(formatKeyValue('Scope', entry.tldr?.scope ?? '-', {padTo}))\n this.log(formatKeyValue('Citations', String(entry.citations?.length ?? 0), {padTo}))\n this.log(formatKeyValue('Generated', entry.generatedAt, {padTo}))\n\n if (entry.body) {\n this.log(`\\n${entry.body}`)\n }\n }\n}\n"],"names":["Args","exitCodes","SanityCommand","subdebug","getErrorMessage","isHttpError","formatKeyValue","getEntry","getEntryDebug","GetEntryCommand","args","knowledgeBaseId","string","description","required","path","enableJsonFlag","examples","command","run","json","flags","entry","error","statusCode","exit","RUNTIME_ERROR","logJson","padTo","log","title","status","tldr","scope","String","citations","length","generatedAt","body"],"mappings":"AAAA,SAAQA,IAAI,QAAO,cAAa;AAChC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,cAAc,QAAO,mCAAkC;AAC/D,SAAQC,QAAQ,QAAO,+BAA8B;AAErD,MAAMC,gBAAgBL,SAAS;AAE/B,OAAO,MAAMM,wBAAwBP;IACnC,OAAgBQ,OAAO;QACrBC,iBAAiBX,KAAKY,MAAM,CAAC;YAC3BC,aAAa;YACbC,UAAU;QACZ;QACAC,MAAMf,KAAKY,MAAM,CAAC;YAChBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,+BAA8B;IAE5D,OAAgBG,iBAAiB,KAAI;IAErC,OAAgBC,WAAW;QACzB;YACEC,SAAS;YACTL,aAAa;QACf;QACA;YACEK,SAAS;YACTL,aAAa;QACf;KACD,CAAA;IAED,MAAaM,MAAqB;QAChC,MAAM,EAACR,eAAe,EAAEI,IAAI,EAAC,GAAG,IAAI,CAACL,IAAI;QACzC,MAAM,EAACU,IAAI,EAAC,GAAG,IAAI,CAACC,KAAK;QAEzB,IAAIC;QACJ,IAAI;YACFA,QAAQ,MAAMf,SAASI,iBAAiBI;QAC1C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0 +1,82 @@
1
+ import { Args } from '@oclif/core';
2
+ import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
+ import { getErrorMessage } from '@sanity/cli-core/errors';
4
+ import { isHttpError } from '@sanity/client';
5
+ import { listEntries } from '../../../services/context.js';
6
+ import { Table } from '../../../util/responsiveTable.js';
7
+ const listEntriesDebug = subdebug('context:entries:list');
8
+ export class ListEntriesCommand extends SanityCommand {
9
+ static args = {
10
+ knowledgeBaseId: Args.string({
11
+ description: 'Knowledge base ID',
12
+ required: true
13
+ })
14
+ };
15
+ static description = 'List the entries a knowledge base build produced';
16
+ static enableJsonFlag = true;
17
+ static examples = [
18
+ {
19
+ command: '<%= config.bin %> <%= command.id %> kb-abc123',
20
+ description: 'List all entries for a knowledge base'
21
+ },
22
+ {
23
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 --json',
24
+ description: 'Output entries as JSON'
25
+ }
26
+ ];
27
+ async run() {
28
+ const { knowledgeBaseId } = this.args;
29
+ const { json } = this.flags;
30
+ let entries;
31
+ try {
32
+ entries = await listEntries(knowledgeBaseId);
33
+ } catch (error) {
34
+ listEntriesDebug('Error listing entries', error);
35
+ if (isHttpError(error) && error.statusCode === 404) {
36
+ this.error(`Knowledge base "${knowledgeBaseId}" not found`, {
37
+ exit: exitCodes.RUNTIME_ERROR
38
+ });
39
+ }
40
+ this.error(`Failed to list entries: ${getErrorMessage(error)}`, {
41
+ exit: exitCodes.RUNTIME_ERROR
42
+ });
43
+ }
44
+ if (json) {
45
+ this.logJson(entries);
46
+ return;
47
+ }
48
+ if (entries.length === 0) {
49
+ this.log('No entries found');
50
+ return;
51
+ }
52
+ const table = new Table({
53
+ columns: [
54
+ {
55
+ alignment: 'left',
56
+ name: 'path',
57
+ title: 'Path'
58
+ },
59
+ {
60
+ alignment: 'left',
61
+ name: 'title',
62
+ title: 'Title'
63
+ },
64
+ {
65
+ alignment: 'left',
66
+ name: 'status',
67
+ title: 'Status'
68
+ }
69
+ ]
70
+ });
71
+ for (const { path, status, title } of entries){
72
+ table.addRow({
73
+ path,
74
+ status,
75
+ title
76
+ });
77
+ }
78
+ this.log(table.render());
79
+ }
80
+ }
81
+
82
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/commands/context/entries/list.ts"],"sourcesContent":["import {Args} from '@oclif/core'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {isHttpError} from '@sanity/client'\n\nimport {listEntries} from '../../../services/context.js'\nimport {Table} from '../../../util/responsiveTable.js'\n\nconst listEntriesDebug = subdebug('context:entries:list')\n\nexport class ListEntriesCommand extends SanityCommand<typeof ListEntriesCommand> {\n static override args = {\n knowledgeBaseId: Args.string({\n description: 'Knowledge base ID',\n required: true,\n }),\n }\n\n static override description = 'List the entries a knowledge base build produced'\n\n static override enableJsonFlag = true\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123',\n description: 'List all entries for a knowledge base',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 --json',\n description: 'Output entries as JSON',\n },\n ]\n\n public async run(): Promise<void> {\n const {knowledgeBaseId} = this.args\n const {json} = this.flags\n\n let entries\n try {\n entries = await listEntries(knowledgeBaseId)\n } catch (error) {\n listEntriesDebug('Error listing entries', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Knowledge base \"${knowledgeBaseId}\" not found`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to list entries: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.logJson(entries)\n return\n }\n\n if (entries.length === 0) {\n this.log('No entries found')\n return\n }\n\n const table = new Table({\n columns: [\n {alignment: 'left', name: 'path', title: 'Path'},\n {alignment: 'left', name: 'title', title: 'Title'},\n {alignment: 'left', name: 'status', title: 'Status'},\n ],\n })\n\n for (const {path, status, title} of entries) {\n table.addRow({path, status, title})\n }\n\n this.log(table.render())\n }\n}\n"],"names":["Args","exitCodes","SanityCommand","subdebug","getErrorMessage","isHttpError","listEntries","Table","listEntriesDebug","ListEntriesCommand","args","knowledgeBaseId","string","description","required","enableJsonFlag","examples","command","run","json","flags","entries","error","statusCode","exit","RUNTIME_ERROR","logJson","length","log","table","columns","alignment","name","title","path","status","addRow","render"],"mappings":"AAAA,SAAQA,IAAI,QAAO,cAAa;AAChC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,WAAW,QAAO,+BAA8B;AACxD,SAAQC,KAAK,QAAO,mCAAkC;AAEtD,MAAMC,mBAAmBL,SAAS;AAElC,OAAO,MAAMM,2BAA2BP;IACtC,OAAgBQ,OAAO;QACrBC,iBAAiBX,KAAKY,MAAM,CAAC;YAC3BC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,mDAAkD;IAEhF,OAAgBE,iBAAiB,KAAI;IAErC,OAAgBC,WAAW;QACzB;YACEC,SAAS;YACTJ,aAAa;QACf;QACA;YACEI,SAAS;YACTJ,aAAa;QACf;KACD,CAAA;IAED,MAAaK,MAAqB;QAChC,MAAM,EAACP,eAAe,EAAC,GAAG,IAAI,CAACD,IAAI;QACnC,MAAM,EAACS,IAAI,EAAC,GAAG,IAAI,CAACC,KAAK;QAEzB,IAAIC;QACJ,IAAI;YACFA,UAAU,MAAMf,YAAYK;QAC9B,EAAE,OAAOW,OAAO;YACdd,iBAAiB,yBAAyBc;YAC1C,IAAIjB,YAAYiB,UAAUA,MAAMC,UAAU,KAAK,KAAK;gBAClD,IAAI,CAACD,KAAK,CAAC,CAAC,gBAAgB,EAAEX,gBAAgB,WAAW,CAAC,EAAE;oBAC1Da,MAAMvB,UAAUwB,aAAa;gBAC/B;YACF;YACA,IAAI,CAACH,KAAK,CAAC,CAAC,wBAAwB,EAAElB,gBAAgBkB,QAAQ,EAAE;gBAC9DE,MAAMvB,UAAUwB,aAAa;YAC/B;QACF;QAEA,IAAIN,MAAM;YACR,IAAI,CAACO,OAAO,CAACL;YACb;QACF;QAEA,IAAIA,QAAQM,MAAM,KAAK,GAAG;YACxB,IAAI,CAACC,GAAG,CAAC;YACT;QACF;QAEA,MAAMC,QAAQ,IAAItB,MAAM;YACtBuB,SAAS;gBACP;oBAACC,WAAW;oBAAQC,MAAM;oBAAQC,OAAO;gBAAM;gBAC/C;oBAACF,WAAW;oBAAQC,MAAM;oBAASC,OAAO;gBAAO;gBACjD;oBAACF,WAAW;oBAAQC,MAAM;oBAAUC,OAAO;gBAAQ;aACpD;QACH;QAEA,KAAK,MAAM,EAACC,IAAI,EAAEC,MAAM,EAAEF,KAAK,EAAC,IAAIZ,QAAS;YAC3CQ,MAAMO,MAAM,CAAC;gBAACF;gBAAMC;gBAAQF;YAAK;QACnC;QAEA,IAAI,CAACL,GAAG,CAACC,MAAMQ,MAAM;IACvB;AACF"}
@@ -0,0 +1,95 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
+ import { getErrorMessage } from '@sanity/cli-core/errors';
4
+ import { spinner } from '@sanity/cli-core/ux';
5
+ import { isHttpError } from '@sanity/client';
6
+ import { formatJobFailure, watchJob } from '../../../actions/context/watchJob.js';
7
+ import { formatKeyValue } from '../../../actions/debug/output.js';
8
+ import { rebuildEntry } from '../../../services/context.js';
9
+ const rebuildEntryDebug = subdebug('context:entries:rebuild');
10
+ export class RebuildEntryCommand extends SanityCommand {
11
+ static args = {
12
+ knowledgeBaseId: Args.string({
13
+ description: 'Knowledge base ID',
14
+ required: true
15
+ }),
16
+ path: Args.string({
17
+ description: 'Entry path, as listed by `sanity context entries list`',
18
+ required: true
19
+ })
20
+ };
21
+ static description = 'Rebuild one entry from its sources';
22
+ static examples = [
23
+ {
24
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 billing/refunds',
25
+ description: 'Start a rebuild and return the job ID'
26
+ },
27
+ {
28
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 billing/refunds --watch',
29
+ description: 'Rebuild an entry and wait for it to finish (non-zero exit on failure)'
30
+ }
31
+ ];
32
+ static flags = {
33
+ watch: Flags.boolean({
34
+ default: false,
35
+ description: 'Wait for the rebuild to finish, exiting non-zero if it fails'
36
+ })
37
+ };
38
+ async run() {
39
+ const { knowledgeBaseId, path } = this.args;
40
+ const { watch } = this.flags;
41
+ let accepted;
42
+ const spin = spinner('Starting rebuild').start();
43
+ try {
44
+ accepted = await rebuildEntry(knowledgeBaseId, path);
45
+ spin.succeed('Rebuild started');
46
+ } catch (error) {
47
+ spin.fail();
48
+ rebuildEntryDebug('Error starting rebuild', error);
49
+ if (isHttpError(error) && error.statusCode === 404) {
50
+ this.error(`Entry "${path}" not found on knowledge base "${knowledgeBaseId}"`, {
51
+ exit: exitCodes.RUNTIME_ERROR
52
+ });
53
+ }
54
+ this.error(`Failed to start rebuild: ${getErrorMessage(error)}`, {
55
+ exit: exitCodes.RUNTIME_ERROR
56
+ });
57
+ }
58
+ const { affectedEntries, jobId } = accepted;
59
+ const padTo = 19 // "Shares sources with" is the longest key
60
+ ;
61
+ this.log(formatKeyValue('Job ID', jobId, {
62
+ padTo
63
+ }));
64
+ // Other entries citing the same sources can change when they are next rebuilt
65
+ if (affectedEntries.length > 0) {
66
+ const paths = affectedEntries.map((entry)=>entry.path).join(', ');
67
+ this.log(formatKeyValue('Shares sources with', paths, {
68
+ padTo
69
+ }));
70
+ }
71
+ this.log(`Track it with: sanity context jobs get ${knowledgeBaseId} ${jobId}`);
72
+ if (!watch) {
73
+ return;
74
+ }
75
+ let job;
76
+ try {
77
+ job = await watchJob(knowledgeBaseId, jobId, {
78
+ label: 'Rebuilding entry',
79
+ successText: 'Entry rebuilt'
80
+ });
81
+ } catch (error) {
82
+ rebuildEntryDebug('Error watching rebuild job', error);
83
+ this.error(`Failed to watch rebuild job: ${getErrorMessage(error)}`, {
84
+ exit: exitCodes.RUNTIME_ERROR
85
+ });
86
+ }
87
+ if (job.status !== 'succeeded') {
88
+ this.error(formatJobFailure('Rebuild', job), {
89
+ exit: exitCodes.RUNTIME_ERROR
90
+ });
91
+ }
92
+ }
93
+ }
94
+
95
+ //# sourceMappingURL=rebuild.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/commands/context/entries/rebuild.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {isHttpError} from '@sanity/client'\n\nimport {formatJobFailure, watchJob} from '../../../actions/context/watchJob.js'\nimport {formatKeyValue} from '../../../actions/debug/output.js'\nimport {rebuildEntry} from '../../../services/context.js'\n\nconst rebuildEntryDebug = subdebug('context:entries:rebuild')\n\nexport class RebuildEntryCommand extends SanityCommand<typeof RebuildEntryCommand> {\n static override args = {\n knowledgeBaseId: Args.string({\n description: 'Knowledge base ID',\n required: true,\n }),\n path: Args.string({\n description: 'Entry path, as listed by `sanity context entries list`',\n required: true,\n }),\n }\n\n static override description = 'Rebuild one entry from its sources'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 billing/refunds',\n description: 'Start a rebuild and return the job ID',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 billing/refunds --watch',\n description: 'Rebuild an entry and wait for it to finish (non-zero exit on failure)',\n },\n ]\n\n static override flags = {\n watch: Flags.boolean({\n default: false,\n description: 'Wait for the rebuild to finish, exiting non-zero if it fails',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {knowledgeBaseId, path} = this.args\n const {watch} = this.flags\n\n let accepted\n const spin = spinner('Starting rebuild').start()\n try {\n accepted = await rebuildEntry(knowledgeBaseId, path)\n spin.succeed('Rebuild started')\n } catch (error) {\n spin.fail()\n rebuildEntryDebug('Error starting rebuild', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Entry \"${path}\" not found on knowledge base \"${knowledgeBaseId}\"`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to start rebuild: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n const {affectedEntries, jobId} = accepted\n const padTo = 19 // \"Shares sources with\" is the longest key\n this.log(formatKeyValue('Job ID', jobId, {padTo}))\n // Other entries citing the same sources can change when they are next rebuilt\n if (affectedEntries.length > 0) {\n const paths = affectedEntries.map((entry) => entry.path).join(', ')\n this.log(formatKeyValue('Shares sources with', paths, {padTo}))\n }\n this.log(`Track it with: sanity context jobs get ${knowledgeBaseId} ${jobId}`)\n\n if (!watch) {\n return\n }\n\n let job\n try {\n job = await watchJob(knowledgeBaseId, jobId, {\n label: 'Rebuilding entry',\n successText: 'Entry rebuilt',\n })\n } catch (error) {\n rebuildEntryDebug('Error watching rebuild job', error)\n this.error(`Failed to watch rebuild job: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (job.status !== 'succeeded') {\n this.error(formatJobFailure('Rebuild', job), {exit: exitCodes.RUNTIME_ERROR})\n }\n }\n}\n"],"names":["Args","Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","spinner","isHttpError","formatJobFailure","watchJob","formatKeyValue","rebuildEntry","rebuildEntryDebug","RebuildEntryCommand","args","knowledgeBaseId","string","description","required","path","examples","command","flags","watch","boolean","default","run","accepted","spin","start","succeed","error","fail","statusCode","exit","RUNTIME_ERROR","affectedEntries","jobId","padTo","log","length","paths","map","entry","join","job","label","successText","status"],"mappings":"AAAA,SAAQA,IAAI,EAAEC,KAAK,QAAO,cAAa;AAEvC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QA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AK,CAAC,CAAC,yBAAyB,EAAE1B,gBAAgB0B,QAAQ,EAAE;gBAC/DG,MAAMhC,UAAUiC,aAAa;YAC/B;QACF;QAEA,MAAM,EAACC,eAAe,EAAEC,KAAK,EAAC,GAAGV;QACjC,MAAMW,QAAQ,GAAG,2CAA2C;;QAC5D,IAAI,CAACC,GAAG,CAAC7B,eAAe,UAAU2B,OAAO;YAACC;QAAK;QAC/C,8EAA8E;QAC9E,IAAIF,gBAAgBI,MAAM,GAAG,GAAG;YAC9B,MAAMC,QAAQL,gBAAgBM,GAAG,CAAC,CAACC,QAAUA,MAAMxB,IAAI,EAAEyB,IAAI,CAAC;YAC9D,IAAI,CAACL,GAAG,CAAC7B,eAAe,uBAAuB+B,OAAO;gBAACH;YAAK;QAC9D;QACA,IAAI,CAACC,GAAG,CAAC,CAAC,uCAAuC,EAAExB,gBAAgB,CAAC,EAAEsB,OAAO;QAE7E,IAAI,CAACd,OAAO;YACV;QACF;QAEA,IAAIsB;QACJ,IAAI;YACFA,MAAM,MAAMpC,SAASM,iBAAiBsB,OAAO;gBAC3CS,OAAO;gBACPC,aAAa;YACf;QACF,EAAE,OAAOhB,OAAO;YACdnB,kBAAkB,8BAA8BmB;YAChD,IAAI,CAACA,KAAK,CAAC,CAAC,6BAA6B,EAAE1B,gBAAgB0B,QAAQ,EAAE;gBACnEG,MAAMhC,UAAUiC,aAAa;YAC/B;QACF;QAEA,IAAIU,IAAIG,MAAM,KAAK,aAAa;YAC9B,IAAI,CAACjB,KAAK,CAACvB,iBAAiB,WAAWqC,MAAM;gBAACX,MAAMhC,UAAUiC,aAAa;YAAA;QAC7E;IACF;AACF"}
@@ -0,0 +1,86 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
+ import { getErrorMessage } from '@sanity/cli-core/errors';
4
+ import { spinner } from '@sanity/cli-core/ux';
5
+ import { isHttpError } from '@sanity/client';
6
+ import { formatJobFailure, watchJob } from '../../../actions/context/watchJob.js';
7
+ import { formatKeyValue } from '../../../actions/debug/output.js';
8
+ import { applyIssues } from '../../../services/context.js';
9
+ const applyIssuesDebug = subdebug('context:issues:apply');
10
+ export class ApplyIssuesCommand extends SanityCommand {
11
+ static args = {
12
+ knowledgeBaseId: Args.string({
13
+ description: 'Knowledge base ID',
14
+ required: true
15
+ }),
16
+ // eslint-disable-next-line perfectionist/sort-objects -- positional order: knowledge base first
17
+ issueId: Args.string({
18
+ description: "ID of an issue to accept and apply (pass several to apply them in one batch). Conflicts can't be applied; resolve them with `sanity context issues resolve`",
19
+ multiple: true,
20
+ required: true
21
+ })
22
+ };
23
+ static description = 'Accept and apply issues to a knowledge base';
24
+ static examples = [
25
+ {
26
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 issue.def456 issue.ghi789',
27
+ description: 'Accept and apply two issues in one batch'
28
+ },
29
+ {
30
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 issue.def456 --watch',
31
+ description: 'Apply an issue and wait for it to finish (non-zero exit on failure)'
32
+ }
33
+ ];
34
+ static flags = {
35
+ watch: Flags.boolean({
36
+ default: false,
37
+ description: 'Wait for the apply to finish, exiting non-zero if it fails'
38
+ })
39
+ };
40
+ async run() {
41
+ const { issueId: issueIds, knowledgeBaseId } = this.args;
42
+ const { watch } = this.flags;
43
+ let jobId;
44
+ const spin = spinner('Starting apply').start();
45
+ try {
46
+ const accepted = await applyIssues(knowledgeBaseId, issueIds);
47
+ jobId = accepted.jobId;
48
+ spin.succeed('Apply started');
49
+ } catch (error) {
50
+ spin.fail();
51
+ applyIssuesDebug('Error applying issues', error);
52
+ if (isHttpError(error) && error.statusCode === 404) {
53
+ this.error(`Knowledge base "${knowledgeBaseId}" not found`, {
54
+ exit: exitCodes.RUNTIME_ERROR
55
+ });
56
+ }
57
+ this.error(`Failed to apply issues: ${getErrorMessage(error)}`, {
58
+ exit: exitCodes.RUNTIME_ERROR
59
+ });
60
+ }
61
+ this.log(formatKeyValue('Job ID', jobId));
62
+ this.log(`Track it with: sanity context jobs get ${knowledgeBaseId} ${jobId}`);
63
+ if (!watch) {
64
+ return;
65
+ }
66
+ let job;
67
+ try {
68
+ job = await watchJob(knowledgeBaseId, jobId, {
69
+ label: 'Applying issues',
70
+ successText: 'Issues applied'
71
+ });
72
+ } catch (error) {
73
+ applyIssuesDebug('Error watching apply job', error);
74
+ this.error(`Failed to watch apply job: ${getErrorMessage(error)}`, {
75
+ exit: exitCodes.RUNTIME_ERROR
76
+ });
77
+ }
78
+ if (job.status !== 'succeeded') {
79
+ this.error(formatJobFailure('Apply', job), {
80
+ exit: exitCodes.RUNTIME_ERROR
81
+ });
82
+ }
83
+ }
84
+ }
85
+
86
+ //# sourceMappingURL=apply.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/commands/context/issues/apply.ts"],"sourcesContent":["import {Args, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {isHttpError} from '@sanity/client'\n\nimport {formatJobFailure, watchJob} from '../../../actions/context/watchJob.js'\nimport {formatKeyValue} from '../../../actions/debug/output.js'\nimport {applyIssues} from '../../../services/context.js'\n\nconst applyIssuesDebug = subdebug('context:issues:apply')\n\nexport class ApplyIssuesCommand extends SanityCommand<typeof ApplyIssuesCommand> {\n static override args = {\n knowledgeBaseId: Args.string({\n description: 'Knowledge base ID',\n required: true,\n }),\n // eslint-disable-next-line perfectionist/sort-objects -- positional order: knowledge base first\n issueId: Args.string({\n description:\n \"ID of an issue to accept and apply (pass several to apply them in one batch). Conflicts can't be applied; resolve them with `sanity context issues resolve`\",\n multiple: true,\n required: true,\n }),\n }\n\n static override description = 'Accept and apply issues to a knowledge base'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 issue.def456 issue.ghi789',\n description: 'Accept and apply two issues in one batch',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 issue.def456 --watch',\n description: 'Apply an issue and wait for it to finish (non-zero exit on failure)',\n },\n ]\n\n static override flags = {\n watch: Flags.boolean({\n default: false,\n description: 'Wait for the apply to finish, exiting non-zero if it fails',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {issueId: issueIds, knowledgeBaseId} = this.args\n const {watch} = this.flags\n\n let jobId: string\n const spin = spinner('Starting apply').start()\n try {\n const accepted = await applyIssues(knowledgeBaseId, issueIds)\n jobId = accepted.jobId\n spin.succeed('Apply started')\n } catch (error) {\n spin.fail()\n applyIssuesDebug('Error applying issues', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Knowledge base \"${knowledgeBaseId}\" not found`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to apply issues: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n this.log(formatKeyValue('Job ID', jobId))\n this.log(`Track it with: sanity context jobs get ${knowledgeBaseId} ${jobId}`)\n\n if (!watch) {\n return\n }\n\n let job\n try {\n job = await watchJob(knowledgeBaseId, jobId, {\n label: 'Applying issues',\n successText: 'Issues applied',\n })\n } catch (error) {\n applyIssuesDebug('Error watching apply job', error)\n this.error(`Failed to watch apply job: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (job.status !== 'succeeded') {\n this.error(formatJobFailure('Apply', job), {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n }\n}\n"],"names":["Args","Flags","exitCodes","SanityCommand","subdebug","getErrorMessage","spinner","isHttpError","formatJobFailure","watchJob","formatKeyValue","applyIssues","applyIssuesDebug","ApplyIssuesCommand","args","knowledgeBaseId","string","description","required","issueId","multiple","examples","command","flags","watch","boolean","default","run","issueIds","jobId","spin","start","accepted","succeed","error","fail","statusCode","exit","RUNTIME_ERROR","log","job","label","successText","status"],"mappings":"AAAA,SAAQ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K,KAAK;gBAClD,IAAI,CAACF,KAAK,CAAC,CAAC,gBAAgB,EAAEnB,gBAAgB,WAAW,CAAC,EAAE;oBAC1DsB,MAAMnC,UAAUoC,aAAa;gBAC/B;YACF;YACA,IAAI,CAACJ,KAAK,CAAC,CAAC,wBAAwB,EAAE7B,gBAAgB6B,QAAQ,EAAE;gBAC9DG,MAAMnC,UAAUoC,aAAa;YAC/B;QACF;QAEA,IAAI,CAACC,GAAG,CAAC7B,eAAe,UAAUmB;QAClC,IAAI,CAACU,GAAG,CAAC,CAAC,uCAAuC,EAAExB,gBAAgB,CAAC,EAAEc,OAAO;QAE7E,IAAI,CAACL,OAAO;YACV;QACF;QAEA,IAAIgB;QACJ,IAAI;YACFA,MAAM,MAAM/B,SAASM,iBAAiBc,OAAO;gBAC3CY,OAAO;gBACPC,aAAa;YACf;QACF,EAAE,OAAOR,OAAO;YACdtB,iBAAiB,4BAA4BsB;YAC7C,IAAI,CAACA,KAAK,CAAC,CAAC,2BAA2B,EAAE7B,gBAAgB6B,QAAQ,EAAE;gBACjEG,MAAMnC,UAAUoC,aAAa;YAC/B;QACF;QAEA,IAAIE,IAAIG,MAAM,KAAK,aAAa;YAC9B,IAAI,CAACT,KAAK,CAAC1B,iBAAiB,SAASgC,MAAM;gBACzCH,MAAMnC,UAAUoC,aAAa;YAC/B;QACF;IACF;AACF"}
@@ -0,0 +1,52 @@
1
+ import { Args } from '@oclif/core';
2
+ import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
+ import { getErrorMessage } from '@sanity/cli-core/errors';
4
+ import { isHttpError } from '@sanity/client';
5
+ import { dismissIssue } from '../../../services/context.js';
6
+ const dismissIssueDebug = subdebug('context:issues:dismiss');
7
+ export class DismissIssueCommand extends SanityCommand {
8
+ static args = {
9
+ knowledgeBaseId: Args.string({
10
+ description: 'Knowledge base ID',
11
+ required: true
12
+ }),
13
+ // eslint-disable-next-line perfectionist/sort-objects -- positional order: knowledge base first
14
+ issueId: Args.string({
15
+ description: 'Issue ID',
16
+ required: true
17
+ })
18
+ };
19
+ static description = "Dismiss an issue\n\nDismissing is permanent: dismissed issues can't be reopened.";
20
+ static examples = [
21
+ {
22
+ command: '<%= config.bin %> <%= command.id %> kb-abc123 issue.def456',
23
+ description: 'Dismiss an issue'
24
+ }
25
+ ];
26
+ async run() {
27
+ const { issueId, knowledgeBaseId } = this.args;
28
+ let dismissed;
29
+ try {
30
+ dismissed = await dismissIssue(knowledgeBaseId, issueId);
31
+ } catch (error) {
32
+ dismissIssueDebug('Error dismissing issue', error);
33
+ if (isHttpError(error) && error.statusCode === 404) {
34
+ this.error(`Issue "${issueId}" not found on knowledge base "${knowledgeBaseId}"`, {
35
+ exit: exitCodes.RUNTIME_ERROR
36
+ });
37
+ }
38
+ this.error(`Failed to dismiss issue: ${getErrorMessage(error)}`, {
39
+ exit: exitCodes.RUNTIME_ERROR
40
+ });
41
+ }
42
+ // The API returns the issue unchanged when it already left triage
43
+ if (dismissed.status !== 'rejected') {
44
+ this.error(`Issue "${issueId}" is accepted (resolved or applied) and cannot be dismissed`, {
45
+ exit: exitCodes.RUNTIME_ERROR
46
+ });
47
+ }
48
+ this.log('Issue dismissed');
49
+ }
50
+ }
51
+
52
+ //# sourceMappingURL=dismiss.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/commands/context/issues/dismiss.ts"],"sourcesContent":["import {Args} from '@oclif/core'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage} from '@sanity/cli-core/errors'\nimport {isHttpError} from '@sanity/client'\n\nimport {dismissIssue} from '../../../services/context.js'\n\nconst dismissIssueDebug = subdebug('context:issues:dismiss')\n\nexport class DismissIssueCommand extends SanityCommand<typeof DismissIssueCommand> {\n static override args = {\n knowledgeBaseId: Args.string({\n description: 'Knowledge base ID',\n required: true,\n }),\n // eslint-disable-next-line perfectionist/sort-objects -- positional order: knowledge base first\n issueId: Args.string({\n description: 'Issue ID',\n required: true,\n }),\n }\n\n static override description =\n \"Dismiss an issue\\n\\nDismissing is permanent: dismissed issues can't be reopened.\"\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 issue.def456',\n description: 'Dismiss an issue',\n },\n ]\n\n public async run(): Promise<void> {\n const {issueId, knowledgeBaseId} = this.args\n\n let dismissed\n try {\n dismissed = await dismissIssue(knowledgeBaseId, issueId)\n } catch (error) {\n dismissIssueDebug('Error dismissing issue', error)\n if (isHttpError(error) && error.statusCode === 404) {\n this.error(`Issue \"${issueId}\" not found on knowledge base \"${knowledgeBaseId}\"`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n this.error(`Failed to dismiss issue: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n // The API returns the issue unchanged when it already left triage\n if (dismissed.status !== 'rejected') {\n this.error(`Issue \"${issueId}\" is accepted (resolved or applied) and cannot be dismissed`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n this.log('Issue dismissed')\n }\n}\n"],"names":["Args","exitCodes","SanityCommand","subdebug","getErrorMessage","isHttpError","dismissIssue","dismissIssueDebug","DismissIssueCommand","args","knowledgeBaseId","string","description","required","issueId","examples","command","run","dismissed","error","statusCode","exit","RUNTIME_ERROR","status","log"],"mappings":"AAAA,SAAQA,IAAI,QAAO,cAAa;AAChC,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,YAAY,QAAO,+BAA8B;AAEzD,MAAMC,oBAAoBJ,SAAS;AAEnC,OAAO,MAAMK,4BAA4BN;IACvC,OAAgBO,OAAO;QACrBC,iBAAiBV,KAAKW,MAAM,CAAC;YAC3BC,aAAa;YACbC,UAAU;QACZ;QACA,gGAAgG;QAChGC,SAASd,KAAKW,MAAM,CAAC;YACnBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;I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