@sanity/cli 8.35.0 → 8.37.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/build/buildApp.js +1 -4
- package/dist/actions/build/buildApp.js.map +1 -1
- package/dist/actions/build/buildStudio.js +1 -0
- package/dist/actions/build/buildStudio.js.map +1 -1
- package/dist/actions/deploy/deployApp.js +32 -12
- package/dist/actions/deploy/deployApp.js.map +1 -1
- package/dist/actions/deploy/deployChecks.js +2 -1
- package/dist/actions/deploy/deployChecks.js.map +1 -1
- package/dist/actions/deploy/deployDashboardConfig.js +124 -0
- package/dist/actions/deploy/deployDashboardConfig.js.map +1 -0
- package/dist/actions/deploy/deployRunner.js.map +1 -1
- package/dist/actions/deploy/deployStudio.js +26 -9
- package/dist/actions/deploy/deployStudio.js.map +1 -1
- package/dist/actions/deploy/resolveDeployTarget.js +2 -2
- package/dist/actions/deploy/resolveDeployTarget.js.map +1 -1
- package/dist/actions/dev/servers/getDevServerConfig.js +2 -5
- package/dist/actions/dev/servers/getDevServerConfig.js.map +1 -1
- package/dist/actions/graphql/extractGraphQLAPIs.js +6 -4
- package/dist/actions/graphql/extractGraphQLAPIs.js.map +1 -1
- package/dist/actions/graphql/extractGraphQLAPIs.worker.js +2 -1
- package/dist/actions/graphql/extractGraphQLAPIs.worker.js.map +1 -1
- package/dist/actions/preview/previewAction.js +2 -2
- package/dist/actions/preview/previewAction.js.map +1 -1
- package/dist/actions/targets/resolveCommandTarget.js +130 -0
- package/dist/actions/targets/resolveCommandTarget.js.map +1 -0
- package/dist/actions/undeploy/runUndeploy.js +33 -5
- package/dist/actions/undeploy/runUndeploy.js.map +1 -1
- package/dist/actions/undeploy/undeployPlan.js +2 -2
- package/dist/actions/undeploy/undeployPlan.js.map +1 -1
- package/dist/commands/build.js +8 -1
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/deploy.js +15 -3
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/documents/query.js +26 -11
- package/dist/commands/documents/query.js.map +1 -1
- package/dist/commands/media/prune-aspect-data.js +1 -1
- package/dist/commands/media/prune-aspect-data.js.map +1 -1
- package/dist/commands/media/pull-aspects.js +1 -1
- package/dist/commands/media/pull-aspects.js.map +1 -1
- package/dist/exports/index.d.ts +2 -2
- package/dist/exports/index.js +1 -1
- package/dist/exports/index.js.map +1 -1
- package/dist/exports/runtime.d.ts +2 -2
- package/dist/exports/runtime.js +1 -1
- package/dist/exports/runtime.js.map +1 -1
- package/dist/generated/apiRoutes.js +37 -0
- package/dist/generated/apiRoutes.js.map +1 -1
- package/dist/prompts/promptForProject.js +9 -3
- package/dist/prompts/promptForProject.js.map +1 -1
- package/dist/services/blueprints.js +18 -0
- package/dist/services/blueprints.js.map +1 -0
- package/dist/util/checkoutBlueprint.js +33 -0
- package/dist/util/checkoutBlueprint.js.map +1 -0
- package/dist/util/sharedFlags.js +10 -0
- package/dist/util/sharedFlags.js.map +1 -1
- package/oclif.manifest.json +1143 -1136
- package/package.json +16 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/deploy/resolveDeployTarget.ts"],"sourcesContent":["import {\n type Application,\n getApplication,\n getApplicationUrl,\n getWorkbenchUrl,\n listApplications,\n} from '@sanity/workbench-cli/deploy'\n\nimport {\n getUserApplication,\n getUserApplications,\n type UserApplication,\n type UserApplicationResolved,\n} from '../../services/userApplications.js'\nimport {APP_ID_NOT_FOUND_IN_ORGANIZATION} from '../../util/errorMessages.js'\nimport {normalizeUrl, validateUrl} from './urlUtils.js'\n\n/** The application fields a deploy-target verdict carries for reporting. */\nexport interface DeployTargetApp {\n id: string\n title: string | null\n type: 'coreApp' | 'studio'\n\n appHost?: string\n url?: string\n}\n\n/** A coreApp verdict also carries the organization, for the dashboard URL. */\ninterface DeployTargetCoreApp extends DeployTargetApp {\n organizationId: string\n}\n\n/**\n * The read-only outcome of resolving where a deploy would go.\n *\n * - `found` — the deploy targets this existing application\n * - `would-create` — nothing registered yet; a deploy would create it without prompting\n * - `needs-input` — config doesn't determine a target; a deploy would prompt\n * (`existing` lists the applications a prompt would offer)\n * - `invalid` — the configured target can never resolve (bad host, unknown appId)\n * - `blocked` — resolution requires config that's missing (projectId/organizationId)\n *\n * Transport errors (network, permissions) throw — they're not verdicts.\n *\n * The user-applications resolvers carry the full {@link UserApplication} (the\n * real deploy needs it); the workbench resolvers and the report only need\n * {@link DeployTargetApp}, so `App` defaults to that widened shape.\n */\ntype CommonDeployTargetResolution<App = DeployTargetApp> =\n | {application: App; type: 'found'}\n | {existing: App[]; type: 'needs-input'}\n | {message: string; reason: 'app-not-found' | 'invalid-host'; type: 'invalid'}\n | {message: string; type: 'blocked'}\n\nexport type StudioDeployTargetResolution<App = DeployTargetApp> =\n | CommonDeployTargetResolution<App>\n | {appHost: string; existing: App; type: 'slug-taken'}\n | {appHost: string; type: 'would-create'}\n\nexport type AppDeployTargetResolution<App = DeployTargetCoreApp> =\n | CommonDeployTargetResolution<App>\n | {appHost: string; existing: App; type: 'slug-taken'}\n | {appHost?: string; type: 'would-create'}\n\n/**\n * Owns the studio deploy-target rules: the --url flag over studioHost config,\n * appId over appHost precedence, external URL normalization and validation.\n * Both the real deploy and the dry run consume these verdicts.\n *\n * @internal\n */\nexport async function resolveStudioDeployTarget(options: {\n appId: string | undefined\n isExternal: boolean\n projectId: string | undefined\n studioHost: string | undefined\n urlFlag: string | undefined\n}): Promise<StudioDeployTargetResolution<UserApplication>> {\n const {appId, isExternal, projectId, studioHost, urlFlag} = options\n\n // appId wins over host config (and undeploy resolves it the same way): a\n // configured appId deploys even when studioHost is stale or invalid, so it's\n // resolved before any host validation.\n if (appId) {\n if (!projectId) {\n return {message: 'api.projectId is missing', type: 'blocked'}\n }\n const application = await getUserApplication({appId, isSdkApp: false, projectId})\n if (application) {\n return {application, type: 'found'}\n }\n return {\n message: `Cannot find app with app ID ${appId}`,\n reason: 'app-not-found',\n type: 'invalid',\n }\n }\n\n const {error: hostError, host: resolvedHost} = resolveAppHost({\n isExternal,\n studioHost,\n url: urlFlag,\n })\n if (hostError) {\n return {message: hostError, reason: 'invalid-host', type: 'invalid'}\n }\n\n // A host from config hasn't passed through the --url validation yet\n let appHost = resolvedHost\n if (appHost && isExternal) {\n appHost = normalizeUrl(appHost)\n const validation = validateUrl(appHost)\n if (validation !== true) {\n return {message: validation, reason: 'invalid-host', type: 'invalid'}\n }\n }\n\n if (appHost) {\n if (!projectId) {\n return {message: 'api.projectId is missing', type: 'blocked'}\n }\n const application = await getUserApplication({appHost, isSdkApp: false, projectId})\n if (application) {\n return {application, type: 'found'}\n }\n return {appHost, type: 'would-create'}\n }\n\n // Neither appId nor host configured — a deploy would prompt.\n // Without a project there is nothing to list; a deploy would still prompt.\n const existing = projectId ? await listStudioApplications(projectId, isExternal) : []\n return {existing, type: 'needs-input'}\n}\n\n/**\n * Owns the app deploy-target rules: appId lookup, falling back to listing the\n * organization's applications. Both the real deploy and the dry run consume\n * these verdicts.\n *\n * @internal\n */\nexport async function resolveAppDeployTarget(options: {\n appId: string | undefined\n create?: boolean\n organizationId: string | undefined\n}): Promise<AppDeployTargetResolution<UserApplicationResolved>> {\n const {appId, create, organizationId} = options\n\n if (appId) {\n const application = await getUserApplication({appId, isSdkApp: true})\n if (application) {\n return {application, type: 'found'}\n }\n return {\n message: `Cannot find app with app ID ${appId}`,\n reason: 'app-not-found',\n type: 'invalid',\n }\n }\n\n if (!organizationId) {\n return {message: 'app.organizationId is missing', type: 'blocked'}\n }\n\n if (create) {\n return {type: 'would-create'}\n }\n\n const existing = await getUserApplications({appType: 'coreApp', organizationId})\n if (existing?.length) {\n return {existing, type: 'needs-input'}\n }\n\n return {type: 'would-create'}\n}\n\n/**\n * The dry-run counterpart to a workbench app's create-on-deploy: without an\n * `appId`, an org already holding the slug resolves to that app, so the report\n * can name its id instead of a create that would fail.\n *\n * @internal\n */\nexport async function resolveWorkbenchApp({\n appId,\n hasAppView = true,\n organizationId,\n slug,\n}: {\n appId: string | undefined\n hasAppView?: boolean\n organizationId?: string\n slug?: string\n}): Promise<AppDeployTargetResolution> {\n const getUrl = (application: Application) =>\n hasAppView ? getApplicationUrl(application) : getWorkbenchUrl(application.organizationId)\n\n if (appId) return resolveAppById(appId, getUrl)\n\n if (organizationId && slug) {\n const existing = (await listApplications(organizationId)).find((app) => app.slug === slug)\n if (existing) {\n return {\n appHost: slug,\n existing: {...existing, url: getUrl(existing)},\n type: 'slug-taken',\n }\n }\n }\n\n return {appHost: slug, type: 'would-create'}\n}\n\n/**\n * {@link resolveWorkbenchApp} narrowed for a studio, whose slug is always configured.\n *\n * @internal\n */\nexport async function resolveWorkbenchStudio(options: {\n appId: string | undefined\n organizationId?: string\n slug: string\n}): Promise<StudioDeployTargetResolution> {\n const resolution = await resolveWorkbenchApp(options)\n return resolution.type === 'would-create'\n ? {appHost: options.slug, type: 'would-create'}\n : resolution\n}\n\nasync function resolveAppById(\n appId: string,\n getUrl: (application: Application) => string,\n): Promise<CommonDeployTargetResolution<DeployTargetCoreApp>> {\n const application = await getApplication(appId)\n return application\n ? {\n application: {...application, url: getUrl(application)},\n type: 'found',\n }\n : {message: APP_ID_NOT_FOUND_IN_ORGANIZATION, reason: 'app-not-found', type: 'invalid'}\n}\n\nasync function listStudioApplications(\n projectId: string,\n isExternal: boolean,\n): Promise<UserApplication[]> {\n const urlType = isExternal ? 'external' : 'internal'\n const applications = await getUserApplications({appType: 'studio', projectId})\n // External deploys should only see external studios and vice versa\n return applications?.filter((application) => application.urlType === urlType) ?? []\n}\n\nfunction resolveAppHost({\n isExternal,\n studioHost,\n url,\n}: {\n isExternal: boolean\n studioHost: string | undefined\n url: string | undefined\n}): {error?: string; host?: string} {\n if (!url) {\n return {host: studioHost}\n }\n\n if (isExternal) {\n const normalized = normalizeUrl(url)\n const validation = validateUrl(normalized)\n if (validation !== true) {\n return {error: validation}\n }\n return {host: normalized}\n }\n\n // For internal deploys, strip protocol prefix and .sanity.studio suffix if present\n const hostname = url.replace(/^https?:\\/\\//i, '').replace(/\\.sanity\\.studio\\/?$/i, '')\n\n // If the result still looks like a URL (contains dots), the user likely meant --external\n if (hostname.includes('.')) {\n return {\n error: `\"${hostname}\" does not look like a sanity.studio hostname. Did you mean to use --external?`,\n }\n }\n\n // Validate hostname characters (alphanumeric and hyphens only)\n if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/i.test(hostname)) {\n return {\n error: `Invalid studio hostname \"${hostname}\". Hostnames can only contain letters, numbers, and hyphens.`,\n }\n }\n\n return {host: hostname}\n}\n"],"names":["getApplication","getApplicationUrl","getWorkbenchUrl","listApplications","getUserApplication","getUserApplications","APP_ID_NOT_FOUND_IN_ORGANIZATION","normalizeUrl","validateUrl","resolveStudioDeployTarget","options","appId","isExternal","projectId","studioHost","urlFlag","message","type","application","isSdkApp","reason","error","hostError","host","resolvedHost","resolveAppHost","url","appHost","validation","existing","listStudioApplications","resolveAppDeployTarget","create","organizationId","appType","length","resolveWorkbenchApp","hasAppView","slug","getUrl","resolveAppById","find","app","resolveWorkbenchStudio","resolution","urlType","applications","filter","normalized","hostname","replace","includes","test"],"mappings":"AAAA,SAEEA,cAAc,EACdC,iBAAiB,EACjBC,eAAe,EACfC,gBAAgB,QACX,+BAA8B;AAErC,SACEC,kBAAkB,EAClBC,mBAAmB,QAGd,qCAAoC;AAC3C,SAAQC,gCAAgC,QAAO,8BAA6B;AAC5E,SAAQC,YAAY,EAAEC,WAAW,QAAO,gBAAe;AAiDvD;;;;;;CAMC,GACD,OAAO,eAAeC,0BAA0BC,OAM/C;IACC,MAAM,EAACC,KAAK,EAAEC,UAAU,EAAEC,SAAS,EAAEC,UAAU,EAAEC,OAAO,EAAC,GAAGL;IAE5D,yEAAyE;IACzE,6EAA6E;IAC7E,uCAAuC;IACvC,IAAIC,OAAO;QACT,IAAI,CAACE,WAAW;YACd,OAAO;gBAACG,SAAS;gBAA4BC,MAAM;YAAS;QAC9D;QACA,MAAMC,cAAc,MAAMd,mBAAmB;YAACO;YAAOQ,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AAc,MAAMlB,eAAeW;IACzC,OAAOO,cACH;QACEA,aAAa;YAAC,GAAGA,WAAW;YAAEQ,KAAKa,OAAOrB;QAAY;QACtDD,MAAM;IACR,IACA;QAACD,SAASV;QAAkCc,QAAQ;QAAiBH,MAAM;IAAS;AAC1F;AAEA,eAAea,uBACbjB,SAAiB,EACjBD,UAAmB;IAEnB,MAAMiC,UAAUjC,aAAa,aAAa;IAC1C,MAAMkC,eAAe,MAAMzC,oBAAoB;QAAC6B,SAAS;QAAUrB;IAAS;IAC5E,mEAAmE;IACnE,OAAOiC,cAAcC,OAAO,CAAC7B,cAAgBA,YAAY2B,OAAO,KAAKA,YAAY,EAAE;AACrF;AAEA,SAASpB,eAAe,EACtBb,UAAU,EACVE,UAAU,EACVY,GAAG,EAKJ;IACC,IAAI,CAACA,KAAK;QACR,OAAO;YAACH,MAAMT;QAAU;IAC1B;IAEA,IAAIF,YAAY;QACd,MAAMoC,aAAazC,aAAamB;QAChC,MAAME,aAAapB,YAAYwC;QAC/B,IAAIpB,eAAe,MAAM;YACvB,OAAO;gBAACP,OAAOO;YAAU;QAC3B;QACA,OAAO;YAACL,MAAMyB;QAAU;IAC1B;IAEA,mFAAmF;IACnF,MAAMC,WAAWvB,IAAIwB,OAAO,CAAC,iBAAiB,IAAIA,OAAO,CAAC,yBAAyB;IAEnF,yFAAyF;IACzF,IAAID,SAASE,QAAQ,CAAC,MAAM;QAC1B,OAAO;YACL9B,OAAO,CAAC,CAAC,EAAE4B,SAAS,8EAA8E,CAAC;QACrG;IACF;IAEA,+DAA+D;IAC/D,IAAI,CAAC,mCAAmCG,IAAI,CAACH,WAAW;QACtD,OAAO;YACL5B,OAAO,CAAC,yBAAyB,EAAE4B,SAAS,4DAA4D,CAAC;QAC3G;IACF;IAEA,OAAO;QAAC1B,MAAM0B;IAAQ;AACxB"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/resolveDeployTarget.ts"],"sourcesContent":["import {\n type Application,\n getApplication,\n getApplicationUrl,\n getWorkbenchUrl,\n listApplications,\n} from '@sanity/workbench-cli/deploy'\n\nimport {\n getUserApplication,\n getUserApplications,\n type UserApplication,\n type UserApplicationResolved,\n} from '../../services/userApplications.js'\nimport {APP_ID_NOT_FOUND_IN_ORGANIZATION} from '../../util/errorMessages.js'\nimport {normalizeUrl, validateUrl} from './urlUtils.js'\n\n/** The application fields a deploy-target verdict carries for reporting. */\nexport interface DeployTargetApp {\n id: string\n title: string | null\n type: 'coreApp' | 'studio'\n\n appHost?: string\n url?: string\n}\n\n/** A coreApp verdict also carries the organization, for the dashboard URL. */\ninterface DeployTargetCoreApp extends DeployTargetApp {\n organizationId: string\n}\n\n/**\n * The read-only outcome of resolving where a deploy would go.\n *\n * - `found` — the deploy targets this existing application\n * - `would-create` — nothing registered yet; a deploy would create it without prompting\n * - `needs-input` — config doesn't determine a target; a deploy would prompt\n * (`existing` lists the applications a prompt would offer)\n * - `invalid` — the configured target can never resolve (bad host, unknown appId)\n * - `blocked` — resolution requires config that's missing (projectId/organizationId)\n *\n * Transport errors (network, permissions) throw — they're not verdicts.\n *\n * The user-applications resolvers carry the full {@link UserApplication} (the\n * real deploy needs it); the workbench resolvers and the report only need\n * {@link DeployTargetApp}, so `App` defaults to that widened shape.\n */\ntype CommonDeployTargetResolution<App = DeployTargetApp> =\n | {application: App; type: 'found'}\n | {existing: App[]; type: 'needs-input'}\n | {message: string; reason: 'app-not-found' | 'invalid-host'; type: 'invalid'}\n | {message: string; type: 'blocked'}\n\nexport type StudioDeployTargetResolution<App = DeployTargetApp> =\n | CommonDeployTargetResolution<App>\n | {appHost: string; existing: App; type: 'slug-taken'}\n | {appHost: string; type: 'would-create'}\n\nexport type AppDeployTargetResolution<App = DeployTargetCoreApp> =\n | CommonDeployTargetResolution<App>\n | {appHost: string; existing: App; type: 'slug-taken'}\n | {appHost?: string; type: 'would-create'}\n\n/**\n * Owns the studio deploy-target rules: the --url flag over studioHost config,\n * appId over appHost precedence, external URL normalization and validation.\n * Both the real deploy and the dry run consume these verdicts.\n *\n * @internal\n */\nexport async function resolveStudioDeployTarget(options: {\n appId: string | undefined\n isExternal: boolean\n projectId: string | undefined\n studioHost: string | undefined\n urlFlag: string | undefined\n}): Promise<StudioDeployTargetResolution<UserApplication>> {\n const {appId, isExternal, projectId, studioHost, urlFlag} = options\n\n // appId wins over host config (and undeploy resolves it the same way): a\n // configured appId deploys even when studioHost is stale or invalid, so it's\n // resolved before any host validation.\n if (appId) {\n if (!projectId) {\n return {message: 'api.projectId is missing', type: 'blocked'}\n }\n const application = await getUserApplication({appId, isSdkApp: false, projectId})\n if (application) {\n return {application, type: 'found'}\n }\n return {\n message: `Cannot find app with app ID ${appId}`,\n reason: 'app-not-found',\n type: 'invalid',\n }\n }\n\n const {error: hostError, host: resolvedHost} = resolveAppHost({\n isExternal,\n studioHost,\n url: urlFlag,\n })\n if (hostError) {\n return {message: hostError, reason: 'invalid-host', type: 'invalid'}\n }\n\n // A host from config hasn't passed through the --url validation yet\n let appHost = resolvedHost\n if (appHost && isExternal) {\n appHost = normalizeUrl(appHost)\n const validation = validateUrl(appHost)\n if (validation !== true) {\n return {message: validation, reason: 'invalid-host', type: 'invalid'}\n }\n }\n\n if (appHost) {\n if (!projectId) {\n return {message: 'api.projectId is missing', type: 'blocked'}\n }\n const application = await getUserApplication({appHost, isSdkApp: false, projectId})\n if (application) {\n return {application, type: 'found'}\n }\n return {appHost, type: 'would-create'}\n }\n\n // Neither appId nor host configured — a deploy would prompt.\n // Without a project there is nothing to list; a deploy would still prompt.\n const existing = projectId ? await listStudioApplications(projectId, isExternal) : []\n return {existing, type: 'needs-input'}\n}\n\n/**\n * Owns the app deploy-target rules: appId lookup, falling back to listing the\n * organization's applications. Both the real deploy and the dry run consume\n * these verdicts.\n *\n * @internal\n */\nexport async function resolveAppDeployTarget(options: {\n appId: string | undefined\n create?: boolean\n organizationId: string | undefined\n}): Promise<AppDeployTargetResolution<UserApplicationResolved>> {\n const {appId, create, organizationId} = options\n\n if (appId) {\n const application = await getUserApplication({appId, isSdkApp: true})\n if (application) {\n return {application, type: 'found'}\n }\n return {\n message: `Cannot find app with app ID ${appId}`,\n reason: 'app-not-found',\n type: 'invalid',\n }\n }\n\n if (!organizationId) {\n return {message: 'app.organizationId is missing', type: 'blocked'}\n }\n\n if (create) {\n return {type: 'would-create'}\n }\n\n const existing = await getUserApplications({appType: 'coreApp', organizationId})\n if (existing?.length) {\n return {existing, type: 'needs-input'}\n }\n\n return {type: 'would-create'}\n}\n\n/**\n * The dry-run counterpart to a workbench app's create-on-deploy: without an\n * `appId`, an org already holding the slug resolves to that app, so the report\n * can name its id instead of a create that would fail.\n *\n * @internal\n */\nexport async function resolveWorkbenchApp({\n appId,\n hasAppView = true,\n hostSlug,\n organizationId,\n slug,\n}: {\n appId: string | undefined\n hasAppView?: boolean\n hostSlug?: string | null\n organizationId?: string\n slug?: string\n}): Promise<AppDeployTargetResolution> {\n const getUrl = (application: Application) =>\n hasAppView\n ? getApplicationUrl(application, hostSlug)\n : getWorkbenchUrl(application.organizationId, hostSlug)\n\n if (appId) return resolveAppById(appId, getUrl)\n\n if (organizationId && slug) {\n const existing = (await listApplications(organizationId)).find((app) => app.slug === slug)\n if (existing) {\n return {\n appHost: slug,\n existing: {...existing, url: getUrl(existing)},\n type: 'slug-taken',\n }\n }\n }\n\n return {appHost: slug, type: 'would-create'}\n}\n\n/**\n * {@link resolveWorkbenchApp} narrowed for a studio, whose slug is always configured.\n *\n * @internal\n */\nexport async function resolveWorkbenchStudio(options: {\n appId: string | undefined\n hostSlug?: string | null\n organizationId?: string\n slug: string\n}): Promise<StudioDeployTargetResolution> {\n const resolution = await resolveWorkbenchApp(options)\n return resolution.type === 'would-create'\n ? {appHost: options.slug, type: 'would-create'}\n : resolution\n}\n\nasync function resolveAppById(\n appId: string,\n getUrl: (application: Application) => string,\n): Promise<CommonDeployTargetResolution<DeployTargetCoreApp>> {\n const application = await getApplication(appId)\n return application\n ? {\n application: {...application, url: getUrl(application)},\n type: 'found',\n }\n : {message: APP_ID_NOT_FOUND_IN_ORGANIZATION, reason: 'app-not-found', type: 'invalid'}\n}\n\nasync function listStudioApplications(\n projectId: string,\n isExternal: boolean,\n): Promise<UserApplication[]> {\n const urlType = isExternal ? 'external' : 'internal'\n const applications = await getUserApplications({appType: 'studio', projectId})\n // External deploys should only see external studios and vice versa\n return applications?.filter((application) => application.urlType === urlType) ?? []\n}\n\nfunction resolveAppHost({\n isExternal,\n studioHost,\n url,\n}: {\n isExternal: boolean\n studioHost: string | undefined\n url: string | undefined\n}): {error?: string; host?: string} {\n if (!url) {\n return {host: studioHost}\n }\n\n if (isExternal) {\n const normalized = normalizeUrl(url)\n const validation = validateUrl(normalized)\n if (validation !== true) {\n return {error: validation}\n }\n return {host: normalized}\n }\n\n // For internal deploys, strip protocol prefix and .sanity.studio suffix if present\n const hostname = url.replace(/^https?:\\/\\//i, '').replace(/\\.sanity\\.studio\\/?$/i, '')\n\n // If the result still looks like a URL (contains dots), the user likely meant --external\n if (hostname.includes('.')) {\n return {\n error: `\"${hostname}\" does not look like a sanity.studio hostname. Did you mean to use --external?`,\n }\n }\n\n // Validate hostname characters (alphanumeric and hyphens only)\n if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/i.test(hostname)) {\n return {\n error: `Invalid studio hostname \"${hostname}\". Hostnames can only contain letters, numbers, and hyphens.`,\n }\n }\n\n return {host: hostname}\n}\n"],"names":["getApplication","getApplicationUrl","getWorkbenchUrl","listApplications","getUserApplication","getUserApplications","APP_ID_NOT_FOUND_IN_ORGANIZATION","normalizeUrl","validateUrl","resolveStudioDeployTarget","options","appId","isExternal","projectId","studioHost","urlFlag","message","type","application","isSdkApp","reason","error","hostError","host","resolvedHost","resolveAppHost","url","appHost","validation","existing","listStudioApplications","resolveAppDeployTarget","create","organizationId","appType","length","resolveWorkbenchApp","hasAppView","hostSlug","slug","getUrl","resolveAppById","find","app","resolveWorkbenchStudio","resolution","urlType","applications","filter","normalized","hostname","replace","includes","test"],"m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vB,OAAO;gBAACP,OAAOO;YAAU;QAC3B;QACA,OAAO;YAACL,MAAM0B;QAAU;IAC1B;IAEA,mFAAmF;IACnF,MAAMC,WAAWxB,IAAIyB,OAAO,CAAC,iBAAiB,IAAIA,OAAO,CAAC,yBAAyB;IAEnF,yFAAyF;IACzF,IAAID,SAASE,QAAQ,CAAC,MAAM;QAC1B,OAAO;YACL/B,OAAO,CAAC,CAAC,EAAE6B,SAAS,8EAA8E,CAAC;QACrG;IACF;IAEA,+DAA+D;IAC/D,IAAI,CAAC,mCAAmCG,IAAI,CAACH,WAAW;QACtD,OAAO;YACL7B,OAAO,CAAC,yBAAyB,EAAE6B,SAAS,4DAA4D,CAAC;QAC3G;IACF;IAEA,OAAO;QAAC3B,MAAM2B;IAAQ;AACxB"}
|
|
@@ -21,7 +21,7 @@ export function getDevServerConfig({ cliConfig, flags, httpPort, output, workDir
|
|
|
21
21
|
const reactStrictMode = resolveReactStrictMode(cliConfig);
|
|
22
22
|
// `views`/`webWorkers` are declared via `defineApplication`, so read them off
|
|
23
23
|
// the branded app result rather than the legacy `app` config type. A config is
|
|
24
|
-
// not an app — it resolves separately and expands
|
|
24
|
+
// not an app — it resolves separately and expands into its config module.
|
|
25
25
|
const app = cliConfig?.app;
|
|
26
26
|
const workbenchConfig = resolveWorkbenchConfig(cliConfig);
|
|
27
27
|
const envBasePath = getSanityEnvVar('BASEPATH', isApp ?? false);
|
|
@@ -45,10 +45,7 @@ export function getDevServerConfig({ cliConfig, flags, httpPort, output, workDir
|
|
|
45
45
|
views: app.views,
|
|
46
46
|
webWorkers: app.webWorkers
|
|
47
47
|
} : workbenchConfig ? {
|
|
48
|
-
config:
|
|
49
|
-
appType: workbenchConfig.appType,
|
|
50
|
-
fields: workbenchConfig.fields
|
|
51
|
-
}
|
|
48
|
+
config: workbenchConfig
|
|
52
49
|
} : undefined,
|
|
53
50
|
// `devAction` passes an explicit port when a running workbench claimed the
|
|
54
51
|
// configured one; otherwise the shared resolution stands.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/actions/dev/servers/getDevServerConfig.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {type CliConfig, getSanityEnvVar, type Output} from '@sanity/cli-core'\nimport {logSymbols, spinner} from '@sanity/cli-core/ux'\nimport {isWorkbenchApp} from '@sanity/workbench-cli'\nimport {resolveAppEntry, resolveWorkbenchConfig} from '@sanity/workbench-cli/build'\n\nimport {type DevServerOptions} from '../../../server/devServer.js'\nimport {determineIsApp} from '../../../util/determineIsApp.js'\nimport {getSharedServerConfig} from '../../../util/getSharedServerConfig.js'\nimport {resolveReactStrictMode} from '../../../util/resolveReactStrictMode.js'\nimport {type DevFlags} from '../types.js'\n\nexport function getDevServerConfig({\n cliConfig,\n flags,\n httpPort,\n output,\n workDir,\n}: {\n cliConfig?: CliConfig\n flags: DevFlags\n httpPort?: number\n output: Output\n workDir: string\n}): Omit<DevServerOptions, 'spinner'> {\n const configSpinner = spinner('Checking configuration files...')\n\n const baseConfig = getSharedServerConfig({\n cliConfig,\n flags: {\n host: flags.host,\n port: flags.port,\n },\n workDir,\n })\n\n configSpinner.succeed()\n\n const isApp = cliConfig ? determineIsApp(cliConfig) : false\n const reactStrictMode = resolveReactStrictMode(cliConfig)\n // `views`/`webWorkers` are declared via `defineApplication`, so read them off\n // the branded app result rather than the legacy `app` config type. A config is\n // not an app — it resolves separately and expands
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/dev/servers/getDevServerConfig.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {type CliConfig, getSanityEnvVar, type Output} from '@sanity/cli-core'\nimport {logSymbols, spinner} from '@sanity/cli-core/ux'\nimport {isWorkbenchApp} from '@sanity/workbench-cli'\nimport {resolveAppEntry, resolveWorkbenchConfig} from '@sanity/workbench-cli/build'\n\nimport {type DevServerOptions} from '../../../server/devServer.js'\nimport {determineIsApp} from '../../../util/determineIsApp.js'\nimport {getSharedServerConfig} from '../../../util/getSharedServerConfig.js'\nimport {resolveReactStrictMode} from '../../../util/resolveReactStrictMode.js'\nimport {type DevFlags} from '../types.js'\n\nexport function getDevServerConfig({\n cliConfig,\n flags,\n httpPort,\n output,\n workDir,\n}: {\n cliConfig?: CliConfig\n flags: DevFlags\n httpPort?: number\n output: Output\n workDir: string\n}): Omit<DevServerOptions, 'spinner'> {\n const configSpinner = spinner('Checking configuration files...')\n\n const baseConfig = getSharedServerConfig({\n cliConfig,\n flags: {\n host: flags.host,\n port: flags.port,\n },\n workDir,\n })\n\n configSpinner.succeed()\n\n const isApp = cliConfig ? determineIsApp(cliConfig) : false\n const reactStrictMode = resolveReactStrictMode(cliConfig)\n // `views`/`webWorkers` are declared via `defineApplication`, so read them off\n // the branded app result rather than the legacy `app` config type. A config is\n // not an app — it resolves separately and expands into its config module.\n const app = cliConfig?.app\n const workbenchConfig = resolveWorkbenchConfig(cliConfig)\n\n const envBasePath = getSanityEnvVar('BASEPATH', isApp ?? false)\n if (envBasePath && cliConfig?.project?.basePath) {\n output.warn(\n `Overriding configured base path (${cliConfig.project.basePath}) with value from environment variable (${envBasePath})`,\n )\n }\n\n // Unstable opt-in to Vite's experimental bundled dev mode, via\n // `unstable_bundledDev` in sanity.cli.ts. Defaults to off.\n const bundledDev = cliConfig?.unstable_bundledDev ?? false\n if (bundledDev) {\n output.log(`${logSymbols.info} Running dev server with experimental Vite bundled dev mode`)\n }\n\n return {\n ...baseConfig,\n bundledDev,\n documentComponent: cliConfig?.unstable_documentComponent,\n // The app's navigable entry. A branded app that omits `entry` has no app\n // view: the runtime/federation skip the `./App` render path entirely.\n entry: resolveAppEntry(app),\n exposes: isWorkbenchApp(app)\n ? {views: app.views, webWorkers: app.webWorkers}\n : workbenchConfig\n ? {config: workbenchConfig}\n : undefined,\n // `devAction` passes an explicit port when a running workbench claimed the\n // configured one; otherwise the shared resolution stands.\n httpPort: httpPort ?? baseConfig.httpPort,\n isWorkbenchApp: isWorkbenchApp(app) || !!workbenchConfig,\n reactCompiler: cliConfig && 'reactCompiler' in cliConfig ? cliConfig.reactCompiler : undefined,\n reactStrictMode,\n staticPath: path.join(workDir, 'static'),\n typegen: cliConfig?.typegen,\n workbenchAppId: isWorkbenchApp(app) ? app.slug : undefined,\n }\n}\n"],"names":["path","getSanityEnvVar","logSymbols","spinner","isWorkbenchApp","resolveAppEntry","resolveWorkbenchConfig","determineIsApp","getSharedServerConfig","resolveReactStrictMode","getDevServerConfig","cliConfig","flags","httpPort","output","workDir","configSpinner","baseConfig","host","port","succeed","isApp","reactStrictMode","app","workbenchConfig","envBasePath","project","basePath","warn","bundledDev","unstable_bundledDev","log","info","documentComponent","unstable_documentComponent","entry","exposes","views","webWorkers","config","undefined","reactCompiler","staticPath","join","typegen","workbenchAppId","slug"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,SAAwBC,eAAe,QAAoB,mBAAkB;AAC7E,SAAQC,UAAU,EAAEC,OAAO,QAAO,sBAAqB;AACvD,SAAQC,cAAc,QAAO,wBAAuB;AACpD,SAAQC,eAAe,EAAEC,sBAAsB,QAAO,8BAA6B;AAGnF,SAAQC,cAAc,QAAO,kCAAiC;AAC9D,SAAQC,qBAAqB,QAAO,yCAAwC;AAC5E,SAAQC,sBAAsB,QAAO,0CAAyC;AAG9E,OAAO,SAASC,mBAAmB,EACjCC,SAAS,EACTC,KAAK,EACLC,QAAQ,EACRC,MAAM,EACNC,OAAO,EAOR;IACC,MAAMC,gBAAgBb,QAAQ;IAE9B,MAAMc,aAAaT,sBAAsB;QACvCG;QACAC,OAAO;YACLM,MAAMN,MAAMM,IAAI;YAChBC,MAAMP,MAAMO,IAAI;QAClB;QACAJ;IACF;IAEAC,cAAcI,OAAO;IAErB,MAAMC,QAAQV,YAAYJ,eAAeI,aAAa;IACtD,MAAMW,kBAAkBb,uBAAuBE;IAC/C,8EAA8E;IAC9E,+EAA+E;IAC/E,0EAA0E;IAC1E,MAAMY,MAAMZ,WAAWY;IACvB,MAAMC,kBAAkBlB,uBAAuBK;IAE/C,MAAMc,cAAcxB,gBAAgB,YAAYoB,SAAS;IACzD,IAAII,eAAed,WAAWe,SAASC,UAAU;QAC/Cb,OAAOc,IAAI,CACT,CAAC,iCAAiC,EAAEjB,UAAUe,OAAO,CAACC,QAAQ,CAAC,wCAAwC,EAAEF,YAAY,CAAC,CAAC;IAE3H;IAEA,+DAA+D;IAC/D,2DAA2D;IAC3D,MAAMI,aAAalB,WAAWmB,uBAAuB;IACrD,IAAID,YAAY;QACdf,OAAOiB,GAAG,CAAC,GAAG7B,WAAW8B,IAAI,CAAC,2DAA2D,CAAC;IAC5F;IAEA,OAAO;QACL,GAAGf,UAAU;QACbY;QACAI,mBAAmBtB,WAAWuB;QAC9B,yEAAyE;QACzE,sEAAsE;QACtEC,OAAO9B,gBAAgBkB;QACvBa,SAAShC,eAAemB,OACpB;YAACc,OAAOd,IAAIc,KAAK;YAAEC,YAAYf,IAAIe,UAAU;QAAA,IAC7Cd,kBACE;YAACe,QAAQf;QAAe,IACxBgB;QACN,2EAA2E;QAC3E,0DAA0D;QAC1D3B,UAAUA,YAAYI,WAAWJ,QAAQ;QACzCT,gBAAgBA,eAAemB,QAAQ,CAAC,CAACC;QACzCiB,eAAe9B,aAAa,mBAAmBA,YAAYA,UAAU8B,aAAa,GAAGD;QACrFlB;QACAoB,YAAY1C,KAAK2C,IAAI,CAAC5B,SAAS;QAC/B6B,SAASjC,WAAWiC;QACpBC,gBAAgBzC,eAAemB,OAAOA,IAAIuB,IAAI,GAAGN;IACnD;AACF"}
|
|
@@ -71,10 +71,12 @@ export async function extractGraphQLAPIsWorker(port, data, deps) {
|
|
|
71
71
|
cliConfig,
|
|
72
72
|
workspaces
|
|
73
73
|
});
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
const [{ compileSchema }, { RELEASE_DOCUMENT_TYPE: releaseDocumentType }] = await Promise.all([
|
|
75
|
+
deps.loadStudioCliTooling(workDir),
|
|
76
|
+
deps.resolveLocalPackage('sanity', workDir)
|
|
77
|
+
]);
|
|
76
78
|
// Build default schema to identify built-in types that should be filtered out
|
|
77
|
-
const defaultSchema =
|
|
79
|
+
const defaultSchema = compileSchema({
|
|
78
80
|
name: 'default',
|
|
79
81
|
types: []
|
|
80
82
|
});
|
|
@@ -99,7 +101,7 @@ export async function extractGraphQLAPIsWorker(port, data, deps) {
|
|
|
99
101
|
excludedTypes.add(releaseDocumentType);
|
|
100
102
|
excludedTypes.add('sanity.releaseMetadata');
|
|
101
103
|
}
|
|
102
|
-
const schema =
|
|
104
|
+
const schema = compileSchema({
|
|
103
105
|
name: 'default',
|
|
104
106
|
types: api.schemaTypes.filter((type)=>!excludedTypes.has(type.name))
|
|
105
107
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/graphql/extractGraphQLAPIs.ts"],"sourcesContent":["import {isMainThread, type MessagePort} from 'node:worker_threads'\n\nimport {findStudioConfigPath, getCliConfig} from '@sanity/cli-core/config'\nimport {subdebug} from '@sanity/cli-core/debug'\nimport {studioWorkerTask} from '@sanity/cli-core/tasks'\nimport {type CliConfig} from '@sanity/cli-core/types'\n\nimport {isSchemaError} from '../../util/isSchemaError.js'\nimport {extractFromSanitySchema} from './extractFromSanitySchema.js'\nimport {resolveGraphQLApis, type Workspace} from './resolveGraphQLApisFromWorkspaces.js'\nimport {SchemaError} from './SchemaError.js'\nimport {type ExtractedGraphQLAPI, type GraphQLAPIConfig, type GraphQLWorkerResult} from './types.js'\n\n// ---------------------------------------------------------------------------\n// Main-thread orchestrator\n// ---------------------------------------------------------------------------\n\nexport async function extractGraphQLAPIs(\n workDir: string,\n options: {nonNullDocumentFieldsFlag?: boolean; withUnionCache?: boolean},\n): Promise<ExtractedGraphQLAPI[]> {\n if (!isMainThread) {\n throw new Error('extractGraphQLAPIs() must be called from the main thread')\n }\n\n const [cliConfig, configPath] = await Promise.all([\n getCliConfig(workDir),\n findStudioConfigPath(workDir),\n ])\n\n const result = await studioWorkerTask<GraphQLWorkerResult>(\n new URL('extractGraphQLAPIs.worker.js', import.meta.url),\n {\n name: 'extractGraphQLAPIs',\n studioRootPath: workDir,\n workerData: {\n cliConfig: extractGraphQLConfig(cliConfig),\n configPath,\n nonNullDocumentFieldsFlag: options.nonNullDocumentFieldsFlag,\n withUnionCache: options.withUnionCache,\n workDir,\n },\n },\n )\n\n if (result.configErrors?.length) {\n throw new SchemaError(result.configErrors)\n }\n\n return result.apis\n}\n\nfunction extractGraphQLConfig(config: CliConfig) {\n return {\n graphql: config.graphql,\n }\n}\n\n// ---------------------------------------------------------------------------\n// Worker logic (runs inside the worker thread)\n// ---------------------------------------------------------------------------\n\nexport interface ExtractWorkerData {\n configPath: string\n workDir: string\n\n cliConfig?: {graphql?: GraphQLAPIConfig[]}\n nonNullDocumentFieldsFlag?: boolean\n withUnionCache?: boolean\n}\n\nexport interface ExtractWorkerDeps {\n getStudioWorkspaces: (configPath: string) => Promise<unknown[]>\n resolveLocalPackage: <T>(name: string, workDir: string) => Promise<T>\n}\n\nconst debug = subdebug('graphql:extractGraphQLAPIs:worker')\n\nexport async function extractGraphQLAPIsWorker(\n port: MessagePort,\n data: ExtractWorkerData,\n deps: ExtractWorkerDeps,\n): Promise<void> {\n const {cliConfig, configPath, nonNullDocumentFieldsFlag, withUnionCache, workDir} = data\n\n // Load workspaces — this loads sanity.config.ts through Vite, caching `sanity` in the process\n let workspaces: Workspace[]\n try {\n workspaces = (await deps.getStudioWorkspaces(configPath)) as Workspace[]\n } catch (err) {\n if (isSchemaError(err)) {\n const validation = err.schema._validation ?? []\n const configErrors = validation\n .map((g) => ({...g, problems: g.problems.filter((p) => p.severity === 'error')}))\n .filter((g) => g.problems.length > 0)\n\n // Only treat error-severity problems as schema errors. If the validation\n // only contains warnings, re-throw the original error so it isn't silently\n // swallowed — warnings alone should not block deployment.\n if (configErrors.length === 0) {\n throw err\n }\n\n port.postMessage({apis: [], configErrors} satisfies GraphQLWorkerResult)\n return\n }\n throw err\n }\n\n // Resolve which GraphQL APIs to deploy from workspace + CLI config\n const resolvedApis = resolveGraphQLApis({cliConfig, workspaces})\n\n // Get createSchema from sanity (0ms — already cached by ViteNodeRunner)\n const {createSchema, RELEASE_DOCUMENT_TYPE: releaseDocumentType} = await deps.resolveLocalPackage<\n typeof import('sanity') & {RELEASE_DOCUMENT_TYPE?: string}\n >('sanity', workDir)\n\n // Build default schema to identify built-in types that should be filtered out\n const defaultSchema = createSchema({name: 'default', types: []})\n const defaultTypes = defaultSchema.getTypeNames()\n\n // For each API: create compiled schema, extract GraphQL spec, catch SchemaError\n const results: ExtractedGraphQLAPI[] = []\n\n for (const api of resolvedApis) {\n const apiBase: Omit<ExtractedGraphQLAPI, 'extracted' | 'extractionError' | 'schemaErrors'> = {\n dataset: api.dataset,\n filterSuffix: api.filterSuffix,\n generation: api.generation,\n id: api.id,\n nonNullDocumentFields: api.nonNullDocumentFields,\n playground: api.playground,\n projectId: api.projectId,\n tag: api.tag,\n }\n\n try {\n const excludedTypes = new Set(defaultTypes)\n if (\n releaseDocumentType &&\n api.schemaTypes.some((type) => type.name === releaseDocumentType)\n ) {\n // Studio's release records and their metadata are managed by Content Releases.\n excludedTypes.add(releaseDocumentType)\n excludedTypes.add('sanity.releaseMetadata')\n }\n\n const schema = createSchema({\n name: 'default',\n types: api.schemaTypes.filter((type) => !excludedTypes.has(type.name)),\n })\n\n const extracted = extractFromSanitySchema(schema, {\n nonNullDocumentFields:\n nonNullDocumentFieldsFlag === undefined\n ? api.nonNullDocumentFields\n : nonNullDocumentFieldsFlag,\n withUnionCache,\n })\n\n results.push({...apiBase, extracted})\n } catch (err) {\n if (err instanceof SchemaError) {\n results.push({...apiBase, schemaErrors: err.problemGroups})\n } else if (isSchemaError(err)) {\n // Sanity's internal schema error from createSchema() — different class from our\n // SchemaError, but carries structured validation data on err.schema._validation.\n // This is low-probability since getStudioWorkspaces() above already validated,\n // but createSchema() on filtered types could still surface issues.\n const validation = err.schema._validation ?? []\n const errorGroups = validation\n .map((g) => ({...g, problems: g.problems.filter((p) => p.severity === 'error')}))\n .filter((g) => g.problems.length > 0)\n if (errorGroups.length > 0) {\n results.push({...apiBase, schemaErrors: errorGroups})\n } else {\n // Warning-only or empty _validation — fall through to generic error with the\n // message, matching the global path which re-throws warning-only errors.\n results.push({\n ...apiBase,\n extractionError: err instanceof Error ? err.message : String(err),\n })\n }\n } else {\n debug(\n 'Schema extraction failed for %s/%s: %O',\n apiBase.dataset,\n apiBase.tag ?? 'default',\n err,\n )\n results.push({\n ...apiBase,\n extractionError: err instanceof Error ? err.message : String(err),\n })\n }\n }\n }\n\n port.postMessage({apis: results} satisfies GraphQLWorkerResult)\n}\n"],"names":["isMainThread","findStudioConfigPath","getCliConfig","subdebug","studioWorkerTask","isSchemaError","extractFromSanitySchema","resolveGraphQLApis","SchemaError","extractGraphQLAPIs","workDir","options","Error","cliConfig","configPath","Promise","all","result","URL","url","name","studioRootPath","workerData","extractGraphQLConfig","nonNullDocumentFieldsFlag","withUnionCache","configErrors","length","apis","config","graphql","debug","extractGraphQLAPIsWorker","port","data","deps","workspaces","getStudioWorkspaces","err","validation","schema","_validation","map","g","problems","filter","p","severity","postMessage","resolvedApis","createSchema","RELEASE_DOCUMENT_TYPE","releaseDocumentType","resolveLocalPackage","defaultSchema","types","defaultTypes","getTypeNames","results","api","apiBase","dataset","filterSuffix","generation","id","nonNullDocumentFields","playground","projectId","tag","excludedTypes","Set","schemaTypes","some","type","add","has","extracted","undefined","push","schemaErrors","problemGroups","errorGroups","extractionError","message","String"],"mappings":"AAAA,SAAQA,YAAY,QAAyB,sBAAqB;AAElE,SAAQC,oBAAoB,EAAEC,YAAY,QAAO,0BAAyB;AAC1E,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,gBAAgB,QAAO,yBAAwB;AAGvD,SAAQC,aAAa,QAAO,8BAA6B;AACzD,SAAQC,uBAAuB,QAAO,+BAA8B;AACpE,SAAQC,kBAAkB,QAAuB,wCAAuC;AACxF,SAAQC,WAAW,QAAO,mBAAkB;AAG5C,8EAA8E;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AAI6C,OAAO,GAAGC,OAAO9C;gBAC/D;YACF;QACF;IACF;IAEAL,KAAKe,WAAW,CAAC;QAACpB,MAAM8B;IAAO;AACjC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/graphql/extractGraphQLAPIs.ts"],"sourcesContent":["import {isMainThread, type MessagePort} from 'node:worker_threads'\n\nimport {findStudioConfigPath, getCliConfig} from '@sanity/cli-core/config'\nimport {subdebug} from '@sanity/cli-core/debug'\nimport {type StudioCliTooling} from '@sanity/cli-core/package-manager'\nimport {studioWorkerTask} from '@sanity/cli-core/tasks'\nimport {type CliConfig} from '@sanity/cli-core/types'\n\nimport {isSchemaError} from '../../util/isSchemaError.js'\nimport {extractFromSanitySchema} from './extractFromSanitySchema.js'\nimport {resolveGraphQLApis, type Workspace} from './resolveGraphQLApisFromWorkspaces.js'\nimport {SchemaError} from './SchemaError.js'\nimport {type ExtractedGraphQLAPI, type GraphQLAPIConfig, type GraphQLWorkerResult} from './types.js'\n\n// ---------------------------------------------------------------------------\n// Main-thread orchestrator\n// ---------------------------------------------------------------------------\n\nexport async function extractGraphQLAPIs(\n workDir: string,\n options: {nonNullDocumentFieldsFlag?: boolean; withUnionCache?: boolean},\n): Promise<ExtractedGraphQLAPI[]> {\n if (!isMainThread) {\n throw new Error('extractGraphQLAPIs() must be called from the main thread')\n }\n\n const [cliConfig, configPath] = await Promise.all([\n getCliConfig(workDir),\n findStudioConfigPath(workDir),\n ])\n\n const result = await studioWorkerTask<GraphQLWorkerResult>(\n new URL('extractGraphQLAPIs.worker.js', import.meta.url),\n {\n name: 'extractGraphQLAPIs',\n studioRootPath: workDir,\n workerData: {\n cliConfig: extractGraphQLConfig(cliConfig),\n configPath,\n nonNullDocumentFieldsFlag: options.nonNullDocumentFieldsFlag,\n withUnionCache: options.withUnionCache,\n workDir,\n },\n },\n )\n\n if (result.configErrors?.length) {\n throw new SchemaError(result.configErrors)\n }\n\n return result.apis\n}\n\nfunction extractGraphQLConfig(config: CliConfig) {\n return {\n graphql: config.graphql,\n }\n}\n\n// ---------------------------------------------------------------------------\n// Worker logic (runs inside the worker thread)\n// ---------------------------------------------------------------------------\n\nexport interface ExtractWorkerData {\n configPath: string\n workDir: string\n\n cliConfig?: {graphql?: GraphQLAPIConfig[]}\n nonNullDocumentFieldsFlag?: boolean\n withUnionCache?: boolean\n}\n\nexport interface ExtractWorkerDeps {\n getStudioWorkspaces: (configPath: string) => Promise<unknown[]>\n loadStudioCliTooling: (workDir: string) => Promise<Pick<StudioCliTooling, 'compileSchema'>>\n resolveLocalPackage: <T>(name: string, workDir: string) => Promise<T>\n}\n\nconst debug = subdebug('graphql:extractGraphQLAPIs:worker')\n\nexport async function extractGraphQLAPIsWorker(\n port: MessagePort,\n data: ExtractWorkerData,\n deps: ExtractWorkerDeps,\n): Promise<void> {\n const {cliConfig, configPath, nonNullDocumentFieldsFlag, withUnionCache, workDir} = data\n\n // Load workspaces — this loads sanity.config.ts through Vite, caching `sanity` in the process\n let workspaces: Workspace[]\n try {\n workspaces = (await deps.getStudioWorkspaces(configPath)) as Workspace[]\n } catch (err) {\n if (isSchemaError(err)) {\n const validation = err.schema._validation ?? []\n const configErrors = validation\n .map((g) => ({...g, problems: g.problems.filter((p) => p.severity === 'error')}))\n .filter((g) => g.problems.length > 0)\n\n // Only treat error-severity problems as schema errors. If the validation\n // only contains warnings, re-throw the original error so it isn't silently\n // swallowed — warnings alone should not block deployment.\n if (configErrors.length === 0) {\n throw err\n }\n\n port.postMessage({apis: [], configErrors} satisfies GraphQLWorkerResult)\n return\n }\n throw err\n }\n\n // Resolve which GraphQL APIs to deploy from workspace + CLI config\n const resolvedApis = resolveGraphQLApis({cliConfig, workspaces})\n\n const [{compileSchema}, {RELEASE_DOCUMENT_TYPE: releaseDocumentType}] = await Promise.all([\n deps.loadStudioCliTooling(workDir),\n deps.resolveLocalPackage<{RELEASE_DOCUMENT_TYPE?: string}>('sanity', workDir),\n ])\n\n // Build default schema to identify built-in types that should be filtered out\n const defaultSchema = compileSchema({name: 'default', types: []})\n const defaultTypes = defaultSchema.getTypeNames()\n\n // For each API: create compiled schema, extract GraphQL spec, catch SchemaError\n const results: ExtractedGraphQLAPI[] = []\n\n for (const api of resolvedApis) {\n const apiBase: Omit<ExtractedGraphQLAPI, 'extracted' | 'extractionError' | 'schemaErrors'> = {\n dataset: api.dataset,\n filterSuffix: api.filterSuffix,\n generation: api.generation,\n id: api.id,\n nonNullDocumentFields: api.nonNullDocumentFields,\n playground: api.playground,\n projectId: api.projectId,\n tag: api.tag,\n }\n\n try {\n const excludedTypes = new Set(defaultTypes)\n if (\n releaseDocumentType &&\n api.schemaTypes.some((type) => type.name === releaseDocumentType)\n ) {\n // Studio's release records and their metadata are managed by Content Releases.\n excludedTypes.add(releaseDocumentType)\n excludedTypes.add('sanity.releaseMetadata')\n }\n\n const schema = compileSchema({\n name: 'default',\n types: api.schemaTypes.filter((type) => !excludedTypes.has(type.name)),\n })\n\n const extracted = extractFromSanitySchema(schema, {\n nonNullDocumentFields:\n nonNullDocumentFieldsFlag === undefined\n ? api.nonNullDocumentFields\n : nonNullDocumentFieldsFlag,\n withUnionCache,\n })\n\n results.push({...apiBase, extracted})\n } catch (err) {\n if (err instanceof SchemaError) {\n results.push({...apiBase, schemaErrors: err.problemGroups})\n } else if (isSchemaError(err)) {\n // Sanity's internal schema error from createSchema() — different class from our\n // SchemaError, but carries structured validation data on err.schema._validation.\n // This is low-probability since getStudioWorkspaces() above already validated,\n // but createSchema() on filtered types could still surface issues.\n const validation = err.schema._validation ?? []\n const errorGroups = validation\n .map((g) => ({...g, problems: g.problems.filter((p) => p.severity === 'error')}))\n .filter((g) => g.problems.length > 0)\n if (errorGroups.length > 0) {\n results.push({...apiBase, schemaErrors: errorGroups})\n } else {\n // Warning-only or empty _validation — fall through to generic error with the\n // message, matching the global path which re-throws warning-only errors.\n results.push({\n ...apiBase,\n extractionError: err instanceof Error ? err.message : String(err),\n })\n }\n } else {\n debug(\n 'Schema extraction failed for %s/%s: %O',\n apiBase.dataset,\n apiBase.tag ?? 'default',\n err,\n )\n results.push({\n ...apiBase,\n extractionError: err instanceof Error ? err.message : String(err),\n })\n }\n }\n }\n\n port.postMessage({apis: results} satisfies GraphQLWorkerResult)\n}\n"],"names":["isMainThread","findStudioConfigPath","getCliConfig","subdebug","studioWorkerTask","isSchemaError","extractFromSanitySchema","resolveGraphQLApis","SchemaError","extractGraphQLAPIs","workDir","options","Error","cliConfig","configPath","Promise","all","result","URL","url","name","studioRootPath","workerData","extractGraphQLConfig","nonNullDocumentFieldsFlag","withUnionCache","configErrors","length","apis","config","graphql","debug","extractGraphQLAPIsWorker","port","data","deps","workspaces","getStudioWorkspaces","err","validation","schema","_validation","map","g","problems","filter","p","severity","postMessage","resolvedApis","compileSchema","RELEASE_DOCUMENT_TYPE","releaseDocumentType","loadStudioCliTooling","resolveLocalPackage","defaultSchema","types","defaultTypes","getTypeNames","results","api","apiBase","dataset","filterSuffix","generation","id","nonNullDocumentFields","playground","projectId","tag","excludedTypes","Set","schemaTypes","some","type","add","has","extracted","undefined","push","schemaErrors","problemGroups","errorGroups","extractionError","message","String"],"mappings":"AAAA,SAAQA,YAAY,QAAyB,sBAAqB;AAElE,SAAQC,oBAAoB,EAAEC,YAAY,QAAO,0BAAyB;AAC1E,SAAQC,QAAQ,QAAO,yBAAwB;AAE/C,SAAQC,gBAAgB,QAAO,yBAAwB;AAGvD,SAAQC,aAAa,QAAO,8BAA6B;AACzD,SAAQC,uBAAuB,QAAO,+BAA8B;AACpE,SAAQC,kBAAkB,QAAuB,wCAAuC;AACxF,SAAQC,WAAW,QAAO,mBAAkB;AAG5C,8EAA8E;AAC9E,2BAA2B;AAC3B,8EAA8E;AAE9E,OAAO,eAAeC,mBACpBC,OAAe,EACfC,OAAwE;IAExE,IAAI,CAACX,cAAc;QACjB,MAAM,IAAIY,MAAM;IAClB;IAEA,MAAM,CAACC,WAAWC,WAAW,GAAG,MAAMC,QAAQC,GAAG,CAAC;QAChDd,aAAaQ;QACbT,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
import { isMainThread, parentPort, workerData } from 'node:worker_threads';
|
|
2
|
-
import { getStudioWorkspaces, resolveLocalPackage } from '@sanity/cli-core';
|
|
2
|
+
import { getStudioWorkspaces, loadStudioCliTooling, resolveLocalPackage } from '@sanity/cli-core';
|
|
3
3
|
import { extractGraphQLAPIsWorker } from './extractGraphQLAPIs.js';
|
|
4
4
|
if (isMainThread || !parentPort) {
|
|
5
5
|
throw new Error('This module must be run as a worker thread');
|
|
6
6
|
}
|
|
7
7
|
await extractGraphQLAPIsWorker(parentPort, workerData, {
|
|
8
8
|
getStudioWorkspaces,
|
|
9
|
+
loadStudioCliTooling,
|
|
9
10
|
resolveLocalPackage
|
|
10
11
|
});
|
|
11
12
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/graphql/extractGraphQLAPIs.worker.ts"],"sourcesContent":["import {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {getStudioWorkspaces, resolveLocalPackage} from '@sanity/cli-core'\n\nimport {extractGraphQLAPIsWorker, type ExtractWorkerData} from './extractGraphQLAPIs.js'\n\nif (isMainThread || !parentPort) {\n throw new Error('This module must be run as a worker thread')\n}\n\nawait extractGraphQLAPIsWorker(parentPort, workerData as ExtractWorkerData, {\n getStudioWorkspaces,\n resolveLocalPackage,\n})\n"],"names":["isMainThread","parentPort","workerData","getStudioWorkspaces","resolveLocalPackage","extractGraphQLAPIsWorker","Error"],"mappings":"AAAA,SAAQA,YAAY,EAAEC,UAAU,EAAEC,UAAU,QAAO,sBAAqB;AAExE,SAAQC,mBAAmB,EAAEC,mBAAmB,QAAO,mBAAkB;
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/graphql/extractGraphQLAPIs.worker.ts"],"sourcesContent":["import {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {getStudioWorkspaces, loadStudioCliTooling, resolveLocalPackage} from '@sanity/cli-core'\n\nimport {extractGraphQLAPIsWorker, type ExtractWorkerData} from './extractGraphQLAPIs.js'\n\nif (isMainThread || !parentPort) {\n throw new Error('This module must be run as a worker thread')\n}\n\nawait extractGraphQLAPIsWorker(parentPort, workerData as ExtractWorkerData, {\n getStudioWorkspaces,\n loadStudioCliTooling,\n resolveLocalPackage,\n})\n"],"names":["isMainThread","parentPort","workerData","getStudioWorkspaces","loadStudioCliTooling","resolveLocalPackage","extractGraphQLAPIsWorker","Error"],"mappings":"AAAA,SAAQA,YAAY,EAAEC,UAAU,EAAEC,UAAU,QAAO,sBAAqB;AAExE,SAAQC,mBAAmB,EAAEC,oBAAoB,EAAEC,mBAAmB,QAAO,mBAAkB;AAE/F,SAAQC,wBAAwB,QAA+B,0BAAyB;AAExF,IAAIN,gBAAgB,CAACC,YAAY;IAC/B,MAAM,IAAIM,MAAM;AAClB;AAEA,MAAMD,yBAAyBL,YAAYC,YAAiC;IAC1EC;IACAC;IACAC;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SANITY_CACHE_DIR } from '@sanity/cli-build/_internal/build';
|
|
2
2
|
import { extractCoreAppManifest } from '@sanity/cli-build/_internal/manifest';
|
|
3
|
-
import { isWorkbenchApp } from '@sanity/workbench-cli';
|
|
3
|
+
import { isWorkbenchApp, isWorkbenchConfig } from '@sanity/workbench-cli';
|
|
4
4
|
import { gracefulServerDeath } from '../../server/gracefulServerDeath.js';
|
|
5
5
|
import { startPreviewServer } from '../../server/previewServer.js';
|
|
6
6
|
import { checkForDeprecatedAppId } from '../../util/appId.js';
|
|
@@ -16,7 +16,7 @@ export async function previewAction(options) {
|
|
|
16
16
|
rootDir: outDir,
|
|
17
17
|
workDir
|
|
18
18
|
});
|
|
19
|
-
if (isWorkbenchApp(cliConfig?.app)) {
|
|
19
|
+
if (isWorkbenchApp(cliConfig?.app) || isWorkbenchConfig(cliConfig?.app)) {
|
|
20
20
|
const isApp = determineIsApp(cliConfig);
|
|
21
21
|
// Lazy so a non-workbench `sanity start` never loads the package. `doImport`
|
|
22
22
|
// is path-based and doesn't apply to a bare specifier.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/preview/previewAction.ts"],"sourcesContent":["import {SANITY_CACHE_DIR} from '@sanity/cli-build/_internal/build'\nimport {extractCoreAppManifest} from '@sanity/cli-build/_internal/manifest'\nimport {type CliConfig, type Output} from '@sanity/cli-core'\nimport {isWorkbenchApp} from '@sanity/workbench-cli'\n\nimport {gracefulServerDeath} from '../../server/gracefulServerDeath.js'\nimport {type PreviewServer, startPreviewServer} from '../../server/previewServer.js'\nimport {checkForDeprecatedAppId} from '../../util/appId.js'\nimport {determineIsApp} from '../../util/determineIsApp.js'\nimport {resolveReactStrictMode} from '../../util/resolveReactStrictMode.js'\nimport {extractStudioManifest} from '../manifest/extractStudioManifest.js'\nimport {getPreviewServerConfig} from './getPreviewServerConfig.js'\nimport {type PreviewFlags} from './types.js'\n\ninterface PreviewActionOptions {\n cliConfig: CliConfig\n flags: PreviewFlags\n outDir: string\n output: Output\n workDir: string\n}\n\nexport async function previewAction(\n options: PreviewActionOptions,\n): Promise<PreviewServer | {close: () => Promise<void>}> {\n const {cliConfig, flags, outDir, output, workDir} = options\n\n const config = getPreviewServerConfig({cliConfig, flags, rootDir: outDir, workDir})\n\n if (isWorkbenchApp(cliConfig?.app)) {\n const isApp = determineIsApp(cliConfig)\n // Lazy so a non-workbench `sanity start` never loads the package. `doImport`\n // is path-based and doesn't apply to a bare specifier.\n // eslint-disable-next-line eslint-js/no-restricted-syntax\n const {startWorkbenchPreview} = await import('@sanity/workbench-cli/preview')\n return startWorkbenchPreview({\n cacheDir: `${SANITY_CACHE_DIR}/vite`,\n checkForDeprecatedAppId: () => checkForDeprecatedAppId({cliConfig, output}),\n cliConfig,\n extractManifest: isApp\n ? ({iconUrl, workDir: wd}) => extractCoreAppManifest({iconUrl, workDir: wd})\n : (params) => extractStudioManifest(params),\n httpHost: config.httpHost,\n httpPort: config.httpPort,\n isApp,\n outDir,\n output,\n reactStrictMode: resolveReactStrictMode(cliConfig) ?? false,\n workDir,\n })\n }\n\n try {\n const server = await startPreviewServer(config)\n return server\n } catch (err) {\n throw gracefulServerDeath('preview', config.httpHost, config.httpPort, err)\n }\n}\n"],"names":["SANITY_CACHE_DIR","extractCoreAppManifest","isWorkbenchApp","gracefulServerDeath","startPreviewServer","checkForDeprecatedAppId","determineIsApp","resolveReactStrictMode","extractStudioManifest","getPreviewServerConfig","previewAction","options","cliConfig","flags","outDir","output","workDir","config","rootDir","app","isApp","startWorkbenchPreview","cacheDir","extractManifest","iconUrl","wd","params","httpHost","httpPort","reactStrictMode","server","err"],"mappings":"AAAA,SAAQA,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,sBAAsB,QAAO,uCAAsC;AAE3E,SAAQC,cAAc,QAAO,wBAAuB;
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/preview/previewAction.ts"],"sourcesContent":["import {SANITY_CACHE_DIR} from '@sanity/cli-build/_internal/build'\nimport {extractCoreAppManifest} from '@sanity/cli-build/_internal/manifest'\nimport {type CliConfig, type Output} from '@sanity/cli-core'\nimport {isWorkbenchApp, isWorkbenchConfig} from '@sanity/workbench-cli'\n\nimport {gracefulServerDeath} from '../../server/gracefulServerDeath.js'\nimport {type PreviewServer, startPreviewServer} from '../../server/previewServer.js'\nimport {checkForDeprecatedAppId} from '../../util/appId.js'\nimport {determineIsApp} from '../../util/determineIsApp.js'\nimport {resolveReactStrictMode} from '../../util/resolveReactStrictMode.js'\nimport {extractStudioManifest} from '../manifest/extractStudioManifest.js'\nimport {getPreviewServerConfig} from './getPreviewServerConfig.js'\nimport {type PreviewFlags} from './types.js'\n\ninterface PreviewActionOptions {\n cliConfig: CliConfig\n flags: PreviewFlags\n outDir: string\n output: Output\n workDir: string\n}\n\nexport async function previewAction(\n options: PreviewActionOptions,\n): Promise<PreviewServer | {close: () => Promise<void>}> {\n const {cliConfig, flags, outDir, output, workDir} = options\n\n const config = getPreviewServerConfig({cliConfig, flags, rootDir: outDir, workDir})\n\n if (isWorkbenchApp(cliConfig?.app) || isWorkbenchConfig(cliConfig?.app)) {\n const isApp = determineIsApp(cliConfig)\n // Lazy so a non-workbench `sanity start` never loads the package. `doImport`\n // is path-based and doesn't apply to a bare specifier.\n // eslint-disable-next-line eslint-js/no-restricted-syntax\n const {startWorkbenchPreview} = await import('@sanity/workbench-cli/preview')\n return startWorkbenchPreview({\n cacheDir: `${SANITY_CACHE_DIR}/vite`,\n checkForDeprecatedAppId: () => checkForDeprecatedAppId({cliConfig, output}),\n cliConfig,\n extractManifest: isApp\n ? ({iconUrl, workDir: wd}) => extractCoreAppManifest({iconUrl, workDir: wd})\n : (params) => extractStudioManifest(params),\n httpHost: config.httpHost,\n httpPort: config.httpPort,\n isApp,\n outDir,\n output,\n reactStrictMode: resolveReactStrictMode(cliConfig) ?? false,\n workDir,\n })\n }\n\n try {\n const server = await startPreviewServer(config)\n return server\n } catch (err) {\n throw gracefulServerDeath('preview', config.httpHost, config.httpPort, err)\n }\n}\n"],"names":["SANITY_CACHE_DIR","extractCoreAppManifest","isWorkbenchApp","isWorkbenchConfig","gracefulServerDeath","startPreviewServer","checkForDeprecatedAppId","determineIsApp","resolveReactStrictMode","extractStudioManifest","getPreviewServerConfig","previewAction","options","cliConfig","flags","outDir","output","workDir","config","rootDir","app","isApp","startWorkbenchPreview","cacheDir","extractManifest","iconUrl","wd","params","httpHost","httpPort","reactStrictMode","server","err"],"mappings":"AAAA,SAAQA,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,sBAAsB,QAAO,uCAAsC;AAE3E,SAAQC,cAAc,EAAEC,iBAAiB,QAAO,wBAAuB;AAEvE,SAAQC,mBAAmB,QAAO,sCAAqC;AACvE,SAA4BC,kBAAkB,QAAO,gCAA+B;AACpF,SAAQC,uBAAuB,QAAO,sBAAqB;AAC3D,SAAQC,cAAc,QAAO,+BAA8B;AAC3D,SAAQC,sBAAsB,QAAO,uCAAsC;AAC3E,SAAQC,qBAAqB,QAAO,uCAAsC;AAC1E,SAAQC,sBAAsB,QAAO,8BAA6B;AAWlE,OAAO,eAAeC,cACpBC,OAA6B;IAE7B,MAAM,EAACC,SAAS,EAAEC,KAAK,EAAEC,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAC,GAAGL;IAEpD,MAAMM,SAASR,uBAAuB;QAACG;QAAWC;QAAOK,SAASJ;QAAQE;IAAO;IAEjF,IAAIf,eAAeW,WAAWO,QAAQjB,kBAAkBU,WAAWO,MAAM;QACvE,MAAMC,QAAQd,eAAeM;QAC7B,6EAA6E;QAC7E,uDAAuD;QACvD,0DAA0D;QAC1D,MAAM,EAACS,qBAAqB,EAAC,GAAG,MAAM,MAAM,CAAC;QAC7C,OAAOA,sBAAsB;YAC3BC,UAAU,GAAGvB,iBAAiB,KAAK,CAAC;YACpCM,yBAAyB,IAAMA,wBAAwB;oBAACO;oBAAWG;gBAAM;YACzEH;YACAW,iBAAiBH,QACb,CAAC,EAACI,OAAO,EAAER,SAASS,EAAE,EAAC,GAAKzB,uBAAuB;oBAACwB;oBAASR,SAASS;gBAAE,KACxE,CAACC,SAAWlB,sBAAsBkB;YACtCC,UAAUV,OAAOU,QAAQ;YACzBC,UAAUX,OAAOW,QAAQ;YACzBR;YACAN;YACAC;YACAc,iBAAiBtB,uBAAuBK,cAAc;YACtDI;QACF;IACF;IAEA,IAAI;QACF,MAAMc,SAAS,MAAM1B,mBAAmBa;QACxC,OAAOa;IACT,EAAE,OAAOC,KAAK;QACZ,MAAM5B,oBAAoB,WAAWc,OAAOU,QAAQ,EAAEV,OAAOW,QAAQ,EAAEG;IACzE;AACF"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { CLIError } from '@oclif/core/errors';
|
|
2
|
+
import { exitCodes } from '@sanity/cli-core';
|
|
3
|
+
import { select } from '@sanity/cli-core/ux';
|
|
4
|
+
import { promptForDataset } from '../../prompts/promptForDataset.js';
|
|
5
|
+
import { promptForProject } from '../../prompts/promptForProject.js';
|
|
6
|
+
import { getDeployedStack } from '../../services/blueprints.js';
|
|
7
|
+
import { listDatasets } from '../../services/datasets.js';
|
|
8
|
+
import { getCheckoutBlueprint } from '../../util/checkoutBlueprint.js';
|
|
9
|
+
export async function resolveCommandTarget({ dataset: datasetFlag, loadCliConfig, needsDataset, project: projectFlag, unattended }) {
|
|
10
|
+
if (projectFlag && (!needsDataset || datasetFlag)) {
|
|
11
|
+
return {
|
|
12
|
+
dataset: datasetFlag,
|
|
13
|
+
projectId: projectFlag
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
let checkout;
|
|
17
|
+
try {
|
|
18
|
+
checkout = getCheckoutBlueprint();
|
|
19
|
+
} catch (cause) {
|
|
20
|
+
throw targetError('Could not read the local Blueprint Stack link. Check .sanity/blueprint.config.json.', retryFlags(projectFlag, datasetFlag, needsDataset), cause);
|
|
21
|
+
}
|
|
22
|
+
const studio = checkout ? undefined : (await loadCliConfig()).api;
|
|
23
|
+
const localProject = checkout?.scopeType === 'project' ? checkout.scopeId : studio?.projectId;
|
|
24
|
+
let projectId = projectFlag || localProject;
|
|
25
|
+
const sameProject = !projectFlag || projectFlag === localProject;
|
|
26
|
+
let dataset = datasetFlag || (sameProject ? studio?.dataset : undefined);
|
|
27
|
+
const targetStack = sameProject || checkout?.scopeType === 'organization' ? checkout : undefined;
|
|
28
|
+
const stack = targetStack && (!projectId || needsDataset && !dataset) ? await readStackTargets(targetStack, retryFlags(projectId, dataset, needsDataset)) : undefined;
|
|
29
|
+
if (!projectId) {
|
|
30
|
+
const projects = [
|
|
31
|
+
...stack?.projects ?? []
|
|
32
|
+
];
|
|
33
|
+
const requestedDataset = dataset;
|
|
34
|
+
const matching = requestedDataset ? projects.filter((id)=>stack?.datasets.get(id)?.has(requestedDataset)) : projects;
|
|
35
|
+
const defaultProject = stack?.defaultProjectId ?? undefined;
|
|
36
|
+
const useDefaultProject = defaultProject && (!dataset || matching.length === 0 || matching.includes(defaultProject));
|
|
37
|
+
projectId = useDefaultProject ? defaultProject : await selectStackTarget(matching.length > 0 ? matching : projects, 'project', unattended);
|
|
38
|
+
if (!projectId) {
|
|
39
|
+
if (unattended) {
|
|
40
|
+
const reason = stack ? 'No deployed project found in the linked Stack.' : 'Project is required.';
|
|
41
|
+
throw targetError(reason, retryFlags(projectId, dataset, needsDataset));
|
|
42
|
+
}
|
|
43
|
+
projectId = await promptForProject({
|
|
44
|
+
organizationId: checkout?.scopeType === 'organization' ? checkout.scopeId : undefined
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (needsDataset && !dataset) {
|
|
49
|
+
dataset = await selectStackTarget([
|
|
50
|
+
...stack?.datasets.get(projectId) ?? []
|
|
51
|
+
], 'dataset', unattended);
|
|
52
|
+
if (!dataset && unattended) {
|
|
53
|
+
const reason = stack ? 'No deployed dataset found in the linked Stack for this project.' : 'Dataset is required.';
|
|
54
|
+
throw targetError(reason, '--dataset <name>');
|
|
55
|
+
}
|
|
56
|
+
if (!dataset) {
|
|
57
|
+
const datasets = await listDatasets(projectId);
|
|
58
|
+
if (datasets.length === 0) {
|
|
59
|
+
throw targetError('No datasets found in this project. Create a dataset or choose another project.', '--project <project-id> --dataset <name>');
|
|
60
|
+
}
|
|
61
|
+
dataset = await promptForDataset({
|
|
62
|
+
datasets
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
dataset,
|
|
68
|
+
projectId
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
async function readStackTargets({ scopeId, scopeType, stackId }, flags) {
|
|
72
|
+
try {
|
|
73
|
+
const stack = await getDeployedStack({
|
|
74
|
+
scopeId,
|
|
75
|
+
scopeType,
|
|
76
|
+
stackId
|
|
77
|
+
});
|
|
78
|
+
if (!Array.isArray(stack.resources)) throw new TypeError('Stack resources are missing');
|
|
79
|
+
const projects = new Set();
|
|
80
|
+
const datasets = new Map();
|
|
81
|
+
for (const { externalId, type } of stack.resources){
|
|
82
|
+
if (!externalId) continue;
|
|
83
|
+
if (type === 'sanity.project') projects.add(externalId);
|
|
84
|
+
if (type !== 'sanity.project.dataset') continue;
|
|
85
|
+
const [projectId, dataset, remainder] = externalId.split(':');
|
|
86
|
+
if (!projectId || !dataset || remainder !== undefined) continue;
|
|
87
|
+
if (scopeType === 'project' && projectId !== scopeId) continue;
|
|
88
|
+
const names = datasets.get(projectId) ?? new Set();
|
|
89
|
+
names.add(dataset);
|
|
90
|
+
datasets.set(projectId, names);
|
|
91
|
+
projects.add(projectId);
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
datasets,
|
|
95
|
+
defaultProjectId: stack.defaultProjectId,
|
|
96
|
+
projects
|
|
97
|
+
};
|
|
98
|
+
} catch (cause) {
|
|
99
|
+
throw targetError(`Could not read Stack ${stackId}. Check your Stack access.`, flags, cause);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function selectStackTarget(values, kind, unattended) {
|
|
103
|
+
if (values.length < 2) return values[0];
|
|
104
|
+
if (unattended) {
|
|
105
|
+
const flag = kind === 'project' ? '--project <project-id>' : '--dataset <name>';
|
|
106
|
+
throw targetError(`Multiple deployed ${kind}s match the linked Stack.`, flag);
|
|
107
|
+
}
|
|
108
|
+
return select({
|
|
109
|
+
choices: values.toSorted().map((value)=>({
|
|
110
|
+
name: value,
|
|
111
|
+
value
|
|
112
|
+
})),
|
|
113
|
+
message: `Select a ${kind} from this Stack`
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function retryFlags(project, dataset, needsDataset) {
|
|
117
|
+
const flags = [];
|
|
118
|
+
if (!project) flags.push('--project <project-id>');
|
|
119
|
+
if (needsDataset && !dataset) flags.push('--dataset <name>');
|
|
120
|
+
return flags.join(' ');
|
|
121
|
+
}
|
|
122
|
+
function targetError(reason, flags, cause) {
|
|
123
|
+
return new CLIError(new Error(`${reason} Try again with \`${flags}\`.`, {
|
|
124
|
+
cause
|
|
125
|
+
}), {
|
|
126
|
+
exit: exitCodes.USAGE_ERROR
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
//# sourceMappingURL=resolveCommandTarget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/targets/resolveCommandTarget.ts"],"sourcesContent":["import {CLIError} from '@oclif/core/errors'\nimport {exitCodes} from '@sanity/cli-core'\nimport {type CliConfig} from '@sanity/cli-core/config'\nimport {select} from '@sanity/cli-core/ux'\n\nimport {promptForDataset} from '../../prompts/promptForDataset.js'\nimport {promptForProject} from '../../prompts/promptForProject.js'\nimport {getDeployedStack} from '../../services/blueprints.js'\nimport {listDatasets} from '../../services/datasets.js'\nimport {type CheckoutStack, getCheckoutBlueprint} from '../../util/checkoutBlueprint.js'\n\ninterface TargetOptions {\n loadCliConfig: () => Promise<CliConfig>\n unattended: boolean\n\n dataset?: string\n needsDataset?: boolean\n project?: string\n}\n\ninterface CommandTarget {\n projectId: string\n\n dataset?: string\n}\n\n// Call only after the command has opted in with --with-blueprints.\n// Commands that need a dataset get a complete target or a usage error.\nexport function resolveCommandTarget(\n options: TargetOptions & {needsDataset: true},\n): Promise<CommandTarget & {dataset: string}>\nexport function resolveCommandTarget(options: TargetOptions): Promise<CommandTarget>\nexport async function resolveCommandTarget({\n dataset: datasetFlag,\n loadCliConfig,\n needsDataset,\n project: projectFlag,\n unattended,\n}: TargetOptions): Promise<CommandTarget> {\n if (projectFlag && (!needsDataset || datasetFlag)) {\n return {dataset: datasetFlag, projectId: projectFlag}\n }\n\n let checkout: CheckoutStack | undefined\n try {\n checkout = getCheckoutBlueprint()\n } catch (cause) {\n throw targetError(\n 'Could not read the local Blueprint Stack link. Check .sanity/blueprint.config.json.',\n retryFlags(projectFlag, datasetFlag, needsDataset),\n cause,\n )\n }\n\n const studio = checkout ? undefined : (await loadCliConfig()).api\n const localProject = checkout?.scopeType === 'project' ? checkout.scopeId : studio?.projectId\n let projectId = projectFlag || localProject\n const sameProject = !projectFlag || projectFlag === localProject\n let dataset = datasetFlag || (sameProject ? studio?.dataset : undefined)\n const targetStack = sameProject || checkout?.scopeType === 'organization' ? checkout : undefined\n\n const stack =\n targetStack && (!projectId || (needsDataset && !dataset))\n ? await readStackTargets(targetStack, retryFlags(projectId, dataset, needsDataset))\n : undefined\n\n if (!projectId) {\n const projects = [...(stack?.projects ?? [])]\n const requestedDataset = dataset\n const matching = requestedDataset\n ? projects.filter((id) => stack?.datasets.get(id)?.has(requestedDataset))\n : projects\n const defaultProject = stack?.defaultProjectId ?? undefined\n const useDefaultProject =\n defaultProject && (!dataset || matching.length === 0 || matching.includes(defaultProject))\n projectId = useDefaultProject\n ? defaultProject\n : await selectStackTarget(matching.length > 0 ? matching : projects, 'project', unattended)\n if (!projectId) {\n if (unattended) {\n const reason = stack\n ? 'No deployed project found in the linked Stack.'\n : 'Project is required.'\n throw targetError(reason, retryFlags(projectId, dataset, needsDataset))\n }\n projectId = await promptForProject({\n organizationId: checkout?.scopeType === 'organization' ? checkout.scopeId : undefined,\n })\n }\n }\n\n if (needsDataset && !dataset) {\n dataset = await selectStackTarget(\n [...(stack?.datasets.get(projectId) ?? [])],\n 'dataset',\n unattended,\n )\n if (!dataset && unattended) {\n const reason = stack\n ? 'No deployed dataset found in the linked Stack for this project.'\n : 'Dataset is required.'\n throw targetError(reason, '--dataset <name>')\n }\n if (!dataset) {\n const datasets = await listDatasets(projectId)\n if (datasets.length === 0) {\n throw targetError(\n 'No datasets found in this project. Create a dataset or choose another project.',\n '--project <project-id> --dataset <name>',\n )\n }\n dataset = await promptForDataset({datasets})\n }\n }\n\n return {dataset, projectId}\n}\n\nasync function readStackTargets({scopeId, scopeType, stackId}: CheckoutStack, flags: string) {\n try {\n const stack = await getDeployedStack({scopeId, scopeType, stackId})\n if (!Array.isArray(stack.resources)) throw new TypeError('Stack resources are missing')\n\n const projects = new Set<string>()\n const datasets = new Map<string, Set<string>>()\n for (const {externalId, type} of stack.resources) {\n if (!externalId) continue\n if (type === 'sanity.project') projects.add(externalId)\n if (type !== 'sanity.project.dataset') continue\n const [projectId, dataset, remainder] = externalId.split(':')\n if (!projectId || !dataset || remainder !== undefined) continue\n if (scopeType === 'project' && projectId !== scopeId) continue\n const names = datasets.get(projectId) ?? new Set<string>()\n names.add(dataset)\n datasets.set(projectId, names)\n projects.add(projectId)\n }\n return {datasets, defaultProjectId: stack.defaultProjectId, projects}\n } catch (cause) {\n throw targetError(`Could not read Stack ${stackId}. Check your Stack access.`, flags, cause)\n }\n}\n\nasync function selectStackTarget(\n values: string[],\n kind: 'dataset' | 'project',\n unattended: boolean,\n): Promise<string | undefined> {\n if (values.length < 2) return values[0]\n if (unattended) {\n const flag = kind === 'project' ? '--project <project-id>' : '--dataset <name>'\n throw targetError(`Multiple deployed ${kind}s match the linked Stack.`, flag)\n }\n return select({\n choices: values.toSorted().map((value) => ({name: value, value})),\n message: `Select a ${kind} from this Stack`,\n })\n}\n\nfunction retryFlags(project?: string, dataset?: string, needsDataset?: boolean): string {\n const flags = []\n if (!project) flags.push('--project <project-id>')\n if (needsDataset && !dataset) flags.push('--dataset <name>')\n return flags.join(' ')\n}\n\nfunction targetError(reason: string, flags: string, cause?: unknown): CLIError {\n return new CLIError(new Error(`${reason} Try again with \\`${flags}\\`.`, {cause}), {\n exit: exitCodes.USAGE_ERROR,\n })\n}\n"],"names":["CLIError","exitCodes","select","promptForDataset","promptForProject","getDeployedStack","listDatasets","getCheckoutBlueprint","resolveCommandTarget","dataset","datasetFlag","loadCliConfig","needsDataset","project","projectFlag","unattended","projectId","checkout","cause","targetError","retryFlags","studio","undefined","api","localProject","scopeType","scopeId","sameProject","targetStack","stack","readStackTargets","projects","requestedDataset","matching","filter","id","datasets","get","has","defaultProject","defaultProjectId","useDefaultProject","length","includes","selectStackTarget","reason","organizationId","stackId","flags","Array","isArray","resources","TypeError","Set","Map","externalId","type","add","remainder","split","names","set","values","kind","flag","choices","toSorted","map","value","name","message","push","join","Error","exit","USAGE_ERROR"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,qBAAoB;AA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AMoC,QAAQ,EAAE;IAChB,IAAI,CAACnC,SAASmC,MAAMuB,IAAI,CAAC;IACzB,IAAI3D,gBAAgB,CAACH,SAASuC,MAAMuB,IAAI,CAAC;IACzC,OAAOvB,MAAMwB,IAAI,CAAC;AACpB;AAEA,SAASrD,YAAY0B,MAAc,EAAEG,KAAa,EAAE9B,KAAe;IACjE,OAAO,IAAIlB,SAAS,IAAIyE,MAAM,GAAG5B,OAAO,kBAAkB,EAAEG,MAAM,GAAG,CAAC,EAAE;QAAC9B;IAAK,IAAI;QAChFwD,MAAMzE,UAAU0E,WAAW;IAC7B;AACF"}
|
|
@@ -3,6 +3,8 @@ import { CLIError } from '@oclif/core/errors';
|
|
|
3
3
|
import { exitCodes, subdebug } from '@sanity/cli-core';
|
|
4
4
|
import { getErrorMessage, JsonOutputError } from '@sanity/cli-core/errors';
|
|
5
5
|
import { confirm, spinner } from '@sanity/cli-core/ux';
|
|
6
|
+
import { fetchDeploySummaryDetails, getWorkbenchUrl } from '@sanity/workbench-cli/deploy';
|
|
7
|
+
import { formatUndeploySummary } from '@sanity/workbench-cli/undeploy';
|
|
6
8
|
import { createCollectingReporter, createFailFastReporter } from '../../util/checks.js';
|
|
7
9
|
import { toStderrOutput } from '../../util/toStderrOutput.js';
|
|
8
10
|
import { describeUndeployTarget, renderUndeployPlan, undeployLabel, undeployPlanToJson } from './undeployPlan.js';
|
|
@@ -71,6 +73,7 @@ const undeployDebug = subdebug('undeploy');
|
|
|
71
73
|
}
|
|
72
74
|
/** The real run: resolve the target, confirm, delete, report. */ async function undeployApp(options, adapter) {
|
|
73
75
|
const { flags, output } = options;
|
|
76
|
+
const startedAt = Date.now();
|
|
74
77
|
const resolution = await resolveTarget(adapter, createFailFastReporter(output));
|
|
75
78
|
// A resolve failure never lands here: the fail-fast reporter already exited.
|
|
76
79
|
if (!resolution) return undefined;
|
|
@@ -86,6 +89,7 @@ const undeployDebug = subdebug('undeploy');
|
|
|
86
89
|
};
|
|
87
90
|
}
|
|
88
91
|
const { target } = resolution;
|
|
92
|
+
const summaryDetails = target.organizationId ? fetchDeploySummaryDetails(target.organizationId) : undefined;
|
|
89
93
|
if (!flags.yes && options.isUnattended) {
|
|
90
94
|
throw new CLIError('Undeploy requires confirmation. Pass --yes to continue.', {
|
|
91
95
|
exit: exitCodes.USAGE_ERROR
|
|
@@ -115,14 +119,23 @@ const undeployDebug = subdebug('undeploy');
|
|
|
115
119
|
});
|
|
116
120
|
}
|
|
117
121
|
spin.succeed();
|
|
118
|
-
|
|
122
|
+
const details = await summaryDetails;
|
|
123
|
+
printUndeployed(target, output, {
|
|
124
|
+
...details,
|
|
125
|
+
durationMs: Date.now() - startedAt
|
|
126
|
+
});
|
|
119
127
|
return {
|
|
120
128
|
application: target.application ?? null,
|
|
121
129
|
deletes: target.deletes,
|
|
122
130
|
payload: target.payload,
|
|
123
131
|
reason: null,
|
|
124
132
|
undeployed: true,
|
|
125
|
-
url: target.url
|
|
133
|
+
url: target.url,
|
|
134
|
+
...target.organizationId && {
|
|
135
|
+
organizationId: target.organizationId,
|
|
136
|
+
organizationName: details?.organizationName ?? null,
|
|
137
|
+
undeployedBy: details?.userName ?? null
|
|
138
|
+
}
|
|
126
139
|
};
|
|
127
140
|
}
|
|
128
141
|
/**
|
|
@@ -148,7 +161,7 @@ const undeployDebug = subdebug('undeploy');
|
|
|
148
161
|
}
|
|
149
162
|
function confirmUndeployMessage(target) {
|
|
150
163
|
if (target.deletes === 'config') {
|
|
151
|
-
return `This will delete the
|
|
164
|
+
return `This will delete the ${styleText('yellow', target.title ?? 'deployed config')}.
|
|
152
165
|
Are you ${styleText('red', 'sure')} you want to undeploy?`;
|
|
153
166
|
}
|
|
154
167
|
if (target.type === 'coreApp') {
|
|
@@ -164,9 +177,24 @@ Are you ${styleText('red', 'sure')} you want to undeploy?`;
|
|
|
164
177
|
return `This will undeploy ${styleText('yellow', target.url ?? target.id)} and make it unavailable for your users.
|
|
165
178
|
Are you ${styleText('red', 'sure')} you want to undeploy?`;
|
|
166
179
|
}
|
|
167
|
-
function printUndeployed(target, output) {
|
|
180
|
+
function printUndeployed(target, output, summary) {
|
|
168
181
|
if (target.deletes === 'config') {
|
|
169
|
-
output.log(
|
|
182
|
+
output.log(formatUndeploySummary({
|
|
183
|
+
...summary,
|
|
184
|
+
organizationId: target.organizationId,
|
|
185
|
+
title: target.title ?? 'Deployed config',
|
|
186
|
+
url: target.url ?? getWorkbenchUrl(target.organizationId)
|
|
187
|
+
}));
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (target.organizationId) {
|
|
191
|
+
output.log(formatUndeploySummary({
|
|
192
|
+
...summary,
|
|
193
|
+
organizationId: target.organizationId,
|
|
194
|
+
title: target.title ?? target.id,
|
|
195
|
+
type: target.type,
|
|
196
|
+
url: getWorkbenchUrl(target.organizationId, summary.hostSlug)
|
|
197
|
+
}));
|
|
170
198
|
return;
|
|
171
199
|
}
|
|
172
200
|
if (target.type === 'coreApp') {
|