@sanity/cli 8.22.0 → 8.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/context/watchJob.js +9 -3
- package/dist/actions/context/watchJob.js.map +1 -1
- package/dist/actions/deploy/blueprintManaged.js +59 -0
- package/dist/actions/deploy/blueprintManaged.js.map +1 -0
- package/dist/actions/deploy/deployApp.js +117 -1
- package/dist/actions/deploy/deployApp.js.map +1 -1
- package/dist/actions/deploy/deployRunner.js.map +1 -1
- package/dist/actions/deploy/deployStudio.js +6 -31
- package/dist/actions/deploy/deployStudio.js.map +1 -1
- package/dist/actions/deploy/deployStudioSchemasAndManifestsWorker.js +6 -15
- package/dist/actions/deploy/deployStudioSchemasAndManifestsWorker.js.map +1 -1
- package/dist/actions/exec/runScript.worker.js +6 -2
- package/dist/actions/exec/runScript.worker.js.map +1 -1
- package/dist/actions/init/bootstrapLocalTemplate.js +35 -11
- package/dist/actions/init/bootstrapLocalTemplate.js.map +1 -1
- package/dist/actions/init/createMediaLibraryCliConfig.js +12 -0
- package/dist/actions/init/createMediaLibraryCliConfig.js.map +1 -0
- package/dist/actions/init/determineMediaLibraryTemplate.js +14 -0
- package/dist/actions/init/determineMediaLibraryTemplate.js.map +1 -0
- package/dist/actions/init/initAction.js +35 -6
- package/dist/actions/init/initAction.js.map +1 -1
- package/dist/actions/init/initApp.js +81 -6
- package/dist/actions/init/initApp.js.map +1 -1
- package/dist/actions/init/offerAspectPull.js +81 -0
- package/dist/actions/init/offerAspectPull.js.map +1 -0
- package/dist/actions/init/project/getProjectDetails.js +25 -2
- package/dist/actions/init/project/getProjectDetails.js.map +1 -1
- package/dist/actions/init/templates/index.js +3 -0
- package/dist/actions/init/templates/index.js.map +1 -1
- package/dist/actions/init/templates/mediaLibraryConfig.js +51 -0
- package/dist/actions/init/templates/mediaLibraryConfig.js.map +1 -0
- package/dist/actions/media/aspectName.js +8 -0
- package/dist/actions/media/aspectName.js.map +1 -0
- package/dist/actions/media/aspectSync/contract.js +163 -0
- package/dist/actions/media/aspectSync/contract.js.map +1 -0
- package/dist/actions/media/aspectSync/syncAspects.js +115 -0
- package/dist/actions/media/aspectSync/syncAspects.js.map +1 -0
- package/dist/actions/media/cliConfigFields.js +192 -0
- package/dist/actions/media/cliConfigFields.js.map +1 -0
- package/dist/actions/media/pullAspects.js +225 -0
- package/dist/actions/media/pullAspects.js.map +1 -0
- package/dist/actions/media/resolveMediaLibraryId.js +83 -0
- package/dist/actions/media/resolveMediaLibraryId.js.map +1 -0
- package/dist/actions/schema/deploySchemas.js.map +1 -1
- package/dist/actions/schema/extractSchemaWatcher.js +69 -14
- package/dist/actions/schema/extractSchemaWatcher.js.map +1 -1
- package/dist/actions/schema/updateWorkspaceSchema.js.map +1 -1
- package/dist/commands/context/build.js +2 -2
- package/dist/commands/context/build.js.map +1 -1
- package/dist/commands/context/entries/get.js +83 -0
- package/dist/commands/context/entries/get.js.map +1 -0
- package/dist/commands/context/entries/list.js +82 -0
- package/dist/commands/context/entries/list.js.map +1 -0
- package/dist/commands/context/entries/rebuild.js +95 -0
- package/dist/commands/context/entries/rebuild.js.map +1 -0
- package/dist/commands/context/issues/apply.js +86 -0
- package/dist/commands/context/issues/apply.js.map +1 -0
- package/dist/commands/context/issues/dismiss.js +52 -0
- package/dist/commands/context/issues/dismiss.js.map +1 -0
- package/dist/commands/context/issues/get.js +105 -0
- package/dist/commands/context/issues/get.js.map +1 -0
- package/dist/commands/context/issues/list.js +128 -0
- package/dist/commands/context/issues/list.js.map +1 -0
- package/dist/commands/context/issues/reopen.js +53 -0
- package/dist/commands/context/issues/reopen.js.map +1 -0
- package/dist/commands/context/issues/resolve.js +137 -0
- package/dist/commands/context/issues/resolve.js.map +1 -0
- package/dist/commands/context/jobs/get.js +2 -2
- package/dist/commands/context/jobs/get.js.map +1 -1
- package/dist/commands/context/query.js +92 -0
- package/dist/commands/context/query.js.map +1 -0
- package/dist/commands/deploy.js +13 -0
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/media/prune-aspect-data.js +170 -0
- package/dist/commands/media/prune-aspect-data.js.map +1 -0
- package/dist/commands/media/pull-aspects.js +309 -0
- package/dist/commands/media/pull-aspects.js.map +1 -0
- package/dist/exports/invokeSanityCli/commandPolicies/mcpPolicy.js +17 -0
- package/dist/exports/invokeSanityCli/commandPolicies/mcpPolicy.js.map +1 -1
- package/dist/services/context.js +96 -3
- package/dist/services/context.js.map +1 -1
- package/dist/services/mediaLibraries.js +175 -8
- package/dist/services/mediaLibraries.js.map +1 -1
- package/oclif.manifest.json +1050 -361
- package/package.json +6 -5
- package/templates/media-library-config/README.md +52 -0
- package/templates/media-library-config/eslint.config.txt +52 -0
- package/templates/media-library-config/src/fields/caption.tsx +29 -0
- package/templates/media-library-config/src/fields/notes.tsx +54 -0
|
@@ -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(
|
|
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,oBA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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,EAAE,OAAOQ,OAAO;YACdf,cAAc,uBAAuBe;YACrC,IAAIlB,YAAYkB,UAAUA,MAAMC,UAAU,KAAK,KAAK;gBAClD,IAAI,CAACD,KAAK,CAAC,CAAC,gBAAgB,EAAEZ,gBAAgB,WAAW,CAAC,EAAE;oBAC1Dc,MAAMxB,UAAUyB,aAAa;gBAC/B;YACF;YACA,IAAI,CAACH,KAAK,CAAC,CAAC,qBAAqB,EAAEnB,gBAAgBmB,QAAQ,EAAE;gBAC3DE,MAAMxB,UAAUyB,aAAa;YAC/B;QACF;QAEA,IAAI,CAACJ,OAAO;YACV,IAAI,CAACC,KAAK,CAAC,CAAC,OAAO,EAAER,KAAK,+BAA+B,EAAEJ,gBAAgB,CAAC,CAAC,EAAE;gBAC7Ec,MAAMxB,UAAUyB,aAAa;YAC/B;QACF;QAEA,IAAIN,MAAM;YACR,IAAI,CAACO,OAAO,CAACL;YACb;QACF;QAEA,MAAMM,QAAQ,EAAE,mDAAmD;;QACnE,IAAI,CAACC,GAAG,CAACvB,eAAe,QAAQgB,MAAMP,IAAI,EAAE;YAACa;QAAK;QAClD,IAAI,CAACC,GAAG,CAACvB,eAAe,SAASgB,MAAMQ,KAAK,EAAE;YAACF;QAAK;QACpD,IAAI,CAACC,GAAG,CAACvB,eAAe,UAAUgB,MAAMS,MAAM,EAAE;YAACH;QAAK;QACtD,IAAI,CAACC,GAAG,CAACvB,eAAe,SAASgB,MAAMU,IAAI,EAAEC,SAAS,KAAK;YAACL;QAAK;QACjE,IAAI,CAACC,GAAG,CAACvB,eAAe,aAAa4B,OAAOZ,MAAMa,SAAS,EAAEC,UAAU,IAAI;YAACR;QAAK;QACjF,IAAI,CAACC,GAAG,CAACvB,eAAe,aAAagB,MAAMe,WAAW,EAAE;YAACT;QAAK;QAE9D,IAAIN,MAAMgB,IAAI,EAAE;YACd,IAAI,CAACT,GAAG,CAAC,CAAC,EAAE,EAAEP,MAAMgB,IAAI,EAAE;QAC5B;IACF;AACF"}
|
|
@@ -0,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,QAAO,0BAAyB;AACvD,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,WAAW,QAAO,iBAAgB;AAE1C,SAAQC,gBAAgB,EAAEC,QAAQ,QAAO,uCAAsC;AAC/E,SAAQC,cAAc,QAAO,mCAAkC;AAC/D,SAAQC,YAAY,QAAO,+BAA8B;AAEzD,MAAMC,oBAAoBR,SAAS;AAEnC,OAAO,MAAMS,4BAA4BV;I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AA8E;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,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,uCAAsC;AAC/E,SAAQC,cAAc,QAAO,mCAAkC;AAC/D,SAAQC,WAAW,QAAO,+BAA8B;AAExD,MAAMC,mBAAmBR,SAAS;AAElC,OAAO,MAAMS,2BAA2BV;IACtC,OAAgBW,OAAO;QACrBC,iBAAiBf,KAAKgB,MAAM,CAAC;YAC3BC,aAAa;YACbC,UAAU;QACZ;QACA,gGAAgG;QAChGC,SAASnB,KAAKgB,MAAM,CAAC;YACnBC,aACE;YACFG,UAAU;YACVF,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,8CAA6C;IAE3E,OAAgBI,WAAW;QACzB;YACEC,SAAS;YACTL,aAAa;QACf;QACA;YACEK,SAAS;YACTL,aAAa;QACf;KACD,CAAA;IAED,OAAgBM,QAAQ;QACtBC,OAAOvB,MAAMwB,OAAO,CAAC;YACnBC,SAAS;YACTT,aAAa;QACf;IACF,EAAqB;IAErB,MAAaU,MAAqB;QAChC,MAAM,EAACR,SAASS,QAAQ,EAAEb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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;IAED,OAAgBD,cACd,mFAAkF;IAEpF,OAAgBG,WAAW;QACzB;YACEC,SAAS;YACTJ,aAAa;QACf;KACD,CAAA;IAED,MAAaK,MAAqB;QAChC,MAAM,EAACH,OAAO,EAAEJ,eAAe,EAAC,GAAG,IAAI,CAACD,IAAI;QAE5C,IAAIS;QACJ,IAAI;YACFA,YAAY,MAAMZ,aAAaI,iBAAiBI;QAClD,EAAE,OAAOK,OAAO;YACdZ,kBAAkB,0BAA0BY;YAC5C,IAAId,YAAYc,UAAUA,MAAMC,UAAU,KAAK,KAAK;gBAClD,IAAI,CAACD,KAAK,CAAC,CAAC,OAAO,EAAEL,QAAQ,+BAA+B,EAAEJ,gBAAgB,CAAC,CAAC,EAAE;oBAChFW,MAAMpB,UAAUqB,aAAa;gBAC/B;YACF;YACA,IAAI,CAACH,KAAK,CAAC,CAAC,yBAAyB,EAAEf,gBAAgBe,QAAQ,EAAE;gBAC/DE,MAAMpB,UAAUqB,aAAa;YAC/B;QACF;QAEA,kEAAkE;QAClE,IAAIJ,UAAUK,MAAM,KAAK,YAAY;YACnC,IAAI,CAACJ,KAAK,CAAC,CAAC,OAAO,EAAEL,QAAQ,2DAA2D,CAAC,EAAE;gBACzFO,MAAMpB,UAAUqB,aAAa;YAC/B;QACF;QAEA,IAAI,CAACE,GAAG,CAAC;IACX;AACF"}
|
|
@@ -0,0 +1,105 @@
|
|
|
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 { getIssue } from '../../../services/context.js';
|
|
7
|
+
const getIssueDebug = subdebug('context:issues:get');
|
|
8
|
+
export class GetIssueCommand extends SanityCommand {
|
|
9
|
+
static args = {
|
|
10
|
+
knowledgeBaseId: Args.string({
|
|
11
|
+
description: 'Knowledge base ID',
|
|
12
|
+
required: true
|
|
13
|
+
}),
|
|
14
|
+
// eslint-disable-next-line perfectionist/sort-objects -- positional order: knowledge base first
|
|
15
|
+
issueId: Args.string({
|
|
16
|
+
description: 'Issue ID',
|
|
17
|
+
required: true
|
|
18
|
+
})
|
|
19
|
+
};
|
|
20
|
+
static description = 'Get details of an issue';
|
|
21
|
+
static enableJsonFlag = true;
|
|
22
|
+
static examples = [
|
|
23
|
+
{
|
|
24
|
+
command: '<%= config.bin %> <%= command.id %> kb-abc123 issue.def456',
|
|
25
|
+
description: 'Get details of a specific issue'
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
command: '<%= config.bin %> <%= command.id %> kb-abc123 issue.def456 --json',
|
|
29
|
+
description: 'Output the issue as JSON'
|
|
30
|
+
}
|
|
31
|
+
];
|
|
32
|
+
async run() {
|
|
33
|
+
const { issueId, knowledgeBaseId } = this.args;
|
|
34
|
+
const { json } = this.flags;
|
|
35
|
+
let issue;
|
|
36
|
+
try {
|
|
37
|
+
issue = await getIssue(knowledgeBaseId, issueId);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
getIssueDebug('Error getting issue', error);
|
|
40
|
+
if (isHttpError(error) && error.statusCode === 404) {
|
|
41
|
+
this.error(`Knowledge base "${knowledgeBaseId}" not found`, {
|
|
42
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
this.error(`Failed to get issue: ${getErrorMessage(error)}`, {
|
|
46
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (!issue) {
|
|
50
|
+
this.error(`Issue "${issueId}" not found on knowledge base "${knowledgeBaseId}"`, {
|
|
51
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
if (json) {
|
|
55
|
+
this.logJson(issue);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const { content } = issue;
|
|
59
|
+
const padTo = 13 // "Suggested fix" is the longest key
|
|
60
|
+
;
|
|
61
|
+
this.log(formatKeyValue('ID', issue._id, {
|
|
62
|
+
padTo
|
|
63
|
+
}));
|
|
64
|
+
this.log(formatKeyValue('Kind', content.kind, {
|
|
65
|
+
padTo
|
|
66
|
+
}));
|
|
67
|
+
this.log(formatKeyValue('Severity', content.severity, {
|
|
68
|
+
padTo
|
|
69
|
+
}));
|
|
70
|
+
this.log(formatKeyValue('Status', issue.status, {
|
|
71
|
+
padTo
|
|
72
|
+
}));
|
|
73
|
+
this.log(formatKeyValue('Scope', content.scopePath, {
|
|
74
|
+
padTo
|
|
75
|
+
}));
|
|
76
|
+
this.log(formatKeyValue('Issue', content.issue, {
|
|
77
|
+
padTo
|
|
78
|
+
}));
|
|
79
|
+
this.log(formatKeyValue('Suggested fix', content.suggestedFix, {
|
|
80
|
+
padTo
|
|
81
|
+
}));
|
|
82
|
+
// Sides are labeled with the 0-based index that `issues resolve --side` takes
|
|
83
|
+
if (content.kind === 'conflict') {
|
|
84
|
+
for (const [index, side] of content.sides.entries()){
|
|
85
|
+
const entryPaths = side.entryPaths?.length ? ` (${side.entryPaths.join(', ')})` : '';
|
|
86
|
+
this.log(formatKeyValue(`Side [${index}]`, `${side.claim}${entryPaths}`, {
|
|
87
|
+
padTo
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
if (content.suggested !== undefined) {
|
|
91
|
+
this.log(formatKeyValue('Suggested', `[${content.suggested}]`, {
|
|
92
|
+
padTo
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
this.log(formatKeyValue('Resolution', issue.resolution === null ? '-' : `[${issue.resolution}]`, {
|
|
97
|
+
padTo
|
|
98
|
+
}));
|
|
99
|
+
this.log(formatKeyValue('Created', issue._createdAt, {
|
|
100
|
+
padTo
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=get.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/commands/context/issues/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 {getIssue} from '../../../services/context.js'\n\nconst getIssueDebug = subdebug('context:issues:get')\n\nexport class GetIssueCommand extends SanityCommand<typeof GetIssueCommand> {\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 = 'Get details of an issue'\n\n static override enableJsonFlag = true\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 issue.def456',\n description: 'Get details of a specific issue',\n },\n {\n command: '<%= config.bin %> <%= command.id %> kb-abc123 issue.def456 --json',\n description: 'Output the issue as JSON',\n },\n ]\n\n public async run(): Promise<void> {\n const {issueId, knowledgeBaseId} = this.args\n const {json} = this.flags\n\n let issue\n try {\n issue = await getIssue(knowledgeBaseId, issueId)\n } catch (error) {\n getIssueDebug('Error getting issue', 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 issue: ${getErrorMessage(error)}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (!issue) {\n this.error(`Issue \"${issueId}\" not found on knowledge base \"${knowledgeBaseId}\"`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n }\n\n if (json) {\n this.logJson(issue)\n return\n }\n\n const {content} = issue\n const padTo = 13 // \"Suggested fix\" is the longest key\n this.log(formatKeyValue('ID', issue._id, {padTo}))\n this.log(formatKeyValue('Kind', content.kind, {padTo}))\n this.log(formatKeyValue('Severity', content.severity, {padTo}))\n this.log(formatKeyValue('Status', issue.status, {padTo}))\n this.log(formatKeyValue('Scope', content.scopePath, {padTo}))\n this.log(formatKeyValue('Issue', content.issue, {padTo}))\n this.log(formatKeyValue('Suggested fix', content.suggestedFix, {padTo}))\n // Sides are labeled with the 0-based index that `issues resolve --side` takes\n if (content.kind === 'conflict') {\n for (const [index, side] of content.sides.entries()) {\n const entryPaths = side.entryPaths?.length ? ` (${side.entryPaths.join(', ')})` : ''\n this.log(formatKeyValue(`Side [${index}]`, `${side.claim}${entryPaths}`, {padTo}))\n }\n if (content.suggested !== undefined) {\n this.log(formatKeyValue('Suggested', `[${content.suggested}]`, {padTo}))\n }\n }\n this.log(\n formatKeyValue('Resolution', issue.resolution === null ? '-' : `[${issue.resolution}]`, {\n padTo,\n }),\n )\n this.log(formatKeyValue('Created', issue._createdAt, {padTo}))\n }\n}\n"],"names":["Args","exitCodes","SanityCommand","subdebug","getErrorMessage","isHttpError","formatKeyValue","getIssue","getIssueDebug","GetIssueCommand","args","knowledgeBaseId","string","description","required","issueId","enableJsonFlag","examples","command","run","json","flags","issue","error","statusCode","exit","RUNTIME_ERROR","logJson","content","padTo","log","_id","kind","severity","status","scopePath","suggestedFix","index","side","sides","entries","entryPaths","length","join","claim","suggested","undefined","resolution","_createdAt"],"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;QACA,gGAAgG;QAChGC,SAASf,KAAKY,MAAM,CAAC;YACnBC,aAAa;YACbC,UAAU;QACZ;IACF,EAAC;IAED,OAAgBD,cAAc,0BAAyB;IAEvD,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,EAACJ,OAAO,EAAEJ,eAAe,EAAC,GAAG,IAAI,CAACD,IAAI;QAC5C,MAAM,EAACU,IAAI,EAAC,GAAG,IAAI,CAACC,KAAK;QAEzB,IAAIC;QACJ,IAAI;YACFA,QAAQ,MAAMf,SAASI,iBAAiBI;QAC1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