@sanity/workbench-cli 1.1.3 → 1.3.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/_exports/build.d.ts +81 -8
- package/dist/_exports/build.js.map +1 -1
- package/dist/_exports/deploy.d.ts +287 -12
- package/dist/_exports/deploy.js +4 -3
- package/dist/_exports/deploy.js.map +1 -1
- package/dist/_exports/dev.d.ts +25 -0
- package/dist/_exports/index.d.ts +85 -31
- package/dist/_exports/index.js +1 -11
- package/dist/_exports/index.js.map +1 -1
- package/dist/actions/build/artifact.js +8 -7
- package/dist/actions/build/artifact.js.map +1 -1
- package/dist/actions/build/configs/artifact.js +45 -0
- package/dist/actions/build/configs/artifact.js.map +1 -0
- package/dist/actions/build/vite/plugin.js +6 -14
- package/dist/actions/build/vite/plugin.js.map +1 -1
- package/dist/actions/build/vite/plugins/plugin-sanity-app-id.js +24 -0
- package/dist/actions/build/vite/plugins/plugin-sanity-app-id.js.map +1 -0
- package/dist/actions/build/vite/workbench-vite-plugins.js +8 -4
- package/dist/actions/build/vite/workbench-vite-plugins.js.map +1 -1
- package/dist/actions/deploy/apiVersion.js +5 -0
- package/dist/actions/deploy/apiVersion.js.map +1 -0
- package/dist/actions/deploy/buildExposes.js +56 -0
- package/dist/actions/deploy/buildExposes.js.map +1 -0
- package/dist/actions/deploy/checkBuiltOutput.js +25 -0
- package/dist/actions/deploy/checkBuiltOutput.js.map +1 -0
- package/dist/actions/deploy/deployConfig.js +90 -0
- package/dist/actions/deploy/deployConfig.js.map +1 -0
- package/dist/actions/deploy/deployWorkbenchApp.js +185 -0
- package/dist/actions/deploy/deployWorkbenchApp.js.map +1 -0
- package/dist/actions/deploy/getWorkbench.js +14 -25
- package/dist/actions/deploy/getWorkbench.js.map +1 -1
- package/dist/actions/deploy/viewDeployment.js +32 -0
- package/dist/actions/deploy/viewDeployment.js.map +1 -0
- package/dist/actions/dev/deriveInterfaces.js +63 -6
- package/dist/actions/dev/deriveInterfaces.js.map +1 -1
- package/dist/actions/dev/exposesSetId.js +69 -0
- package/dist/actions/dev/exposesSetId.js.map +1 -0
- package/dist/actions/dev/registry.js +27 -1
- package/dist/actions/dev/registry.js.map +1 -1
- package/dist/actions/dev/startDevManifestWatcher.js +2 -1
- package/dist/actions/dev/startDevManifestWatcher.js.map +1 -1
- package/dist/actions/dev/startDevServerRegistration.js +26 -11
- package/dist/actions/dev/startDevServerRegistration.js.map +1 -1
- package/dist/actions/dev/startWorkbenchDevServer.js +23 -5
- package/dist/actions/dev/startWorkbenchDevServer.js.map +1 -1
- package/dist/actions/dev/writeWorkbenchRuntime.js +4 -1
- package/dist/actions/dev/writeWorkbenchRuntime.js.map +1 -1
- package/dist/contract.js +43 -40
- package/dist/contract.js.map +1 -1
- package/dist/defineApp.js +60 -1
- package/dist/defineApp.js.map +1 -1
- package/dist/resolveWorkbenchApp.js +5 -1
- package/dist/resolveWorkbenchApp.js.map +1 -1
- package/package.json +7 -4
- package/dist/actions/dev/interfaceSetId.js +0 -51
- package/dist/actions/dev/interfaceSetId.js.map +0 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { stat } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Throws unless `sourceDir` is a directory holding a federation build.
|
|
5
|
+
* Workbench builds emit a module-federation remote instead of a static SPA,
|
|
6
|
+
* so the usual `index.html` contract doesn't apply — `mf-manifest.json` is the
|
|
7
|
+
* marker that `sanity build` produced a federation build.
|
|
8
|
+
*/ export async function checkBuiltOutput(sourceDir) {
|
|
9
|
+
try {
|
|
10
|
+
const stats = await stat(sourceDir);
|
|
11
|
+
if (!stats.isDirectory()) {
|
|
12
|
+
throw new Error(`"${sourceDir}" is not a directory`);
|
|
13
|
+
}
|
|
14
|
+
} catch (err) {
|
|
15
|
+
throw err.code === 'ENOENT' ? new Error(`Directory "${sourceDir}" does not exist`) : err;
|
|
16
|
+
}
|
|
17
|
+
const manifestPath = join(sourceDir, 'mf-manifest.json');
|
|
18
|
+
try {
|
|
19
|
+
await stat(manifestPath);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
throw err.code === 'ENOENT' ? new Error(`"${manifestPath}" does not exist. ` + 'The deploy directory must contain a federation build created with "sanity build".') : err;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=checkBuiltOutput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/checkBuiltOutput.ts"],"sourcesContent":["import {stat} from 'node:fs/promises'\nimport {join} from 'node:path'\n\n/**\n * Throws unless `sourceDir` is a directory holding a federation build.\n * Workbench builds emit a module-federation remote instead of a static SPA,\n * so the usual `index.html` contract doesn't apply — `mf-manifest.json` is the\n * marker that `sanity build` produced a federation build.\n */\nexport async function checkBuiltOutput(sourceDir: string): Promise<void> {\n try {\n const stats = await stat(sourceDir)\n if (!stats.isDirectory()) {\n throw new Error(`\"${sourceDir}\" is not a directory`)\n }\n } catch (err) {\n throw err.code === 'ENOENT' ? new Error(`Directory \"${sourceDir}\" does not exist`) : err\n }\n\n const manifestPath = join(sourceDir, 'mf-manifest.json')\n try {\n await stat(manifestPath)\n } catch (err) {\n throw err.code === 'ENOENT'\n ? new Error(\n `\"${manifestPath}\" does not exist. ` +\n 'The deploy directory must contain a federation build created with \"sanity build\".',\n )\n : err\n }\n}\n"],"names":["stat","join","checkBuiltOutput","sourceDir","stats","isDirectory","Error","err","code","manifestPath"],"mappings":"AAAA,SAAQA,IAAI,QAAO,mBAAkB;AACrC,SAAQC,IAAI,QAAO,YAAW;AAE9B;;;;;CAKC,GACD,OAAO,eAAeC,iBAAiBC,SAAiB;IACtD,IAAI;QACF,MAAMC,QAAQ,MAAMJ,KAAKG;QACzB,IAAI,CAACC,MAAMC,WAAW,IAAI;YACxB,MAAM,IAAIC,MAAM,CAAC,CAAC,EAAEH,UAAU,oBAAoB,CAAC;QACrD;IACF,EAAE,OAAOI,KAAK;QACZ,MAAMA,IAAIC,IAAI,KAAK,WAAW,IAAIF,MAAM,CAAC,WAAW,EAAEH,UAAU,gBAAgB,CAAC,IAAII;IACvF;IAEA,MAAME,eAAeR,KAAKE,WAAW;IACrC,IAAI;QACF,MAAMH,KAAKS;IACb,EAAE,OAAOF,KAAK;QACZ,MAAMA,IAAIC,IAAI,KAAK,WACf,IAAIF,MACF,CAAC,CAAC,EAAEG,aAAa,kBAAkB,CAAC,GAClC,uFAEJF;IACN;AACF"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { basename, dirname } from 'node:path';
|
|
2
|
+
import { PassThrough } from 'node:stream';
|
|
3
|
+
import { styleText } from 'node:util';
|
|
4
|
+
import { createGzip } from 'node:zlib';
|
|
5
|
+
import { getGlobalCliClient, subdebug } from '@sanity/cli-core';
|
|
6
|
+
import FormData from 'form-data';
|
|
7
|
+
import { pack } from 'tar-fs';
|
|
8
|
+
import { APP_WORKBENCH_API_VERSION } from './apiVersion.js';
|
|
9
|
+
const debug = subdebug('deploy');
|
|
10
|
+
/**
|
|
11
|
+
* The org's active installation for an app type, or `undefined` when none is
|
|
12
|
+
* installed. Read-only, so `--dry-run` can report deployability.
|
|
13
|
+
* @internal
|
|
14
|
+
*/ export async function resolveInstallationId(options) {
|
|
15
|
+
switch(options.appType){
|
|
16
|
+
case 'media-library':
|
|
17
|
+
{
|
|
18
|
+
return resolveSingletonInstallationId(options.organizationId, 'media-library');
|
|
19
|
+
}
|
|
20
|
+
default:
|
|
21
|
+
{
|
|
22
|
+
throw new Error(`Cannot create config for unknown app type: ${options.appType}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A report heading and item list for a config; a media library's `fields` are
|
|
28
|
+
* one of potentially many shapes.
|
|
29
|
+
* @internal
|
|
30
|
+
*/ export function summarizeConfig(config) {
|
|
31
|
+
switch(config.appType){
|
|
32
|
+
case 'media-library':
|
|
33
|
+
{
|
|
34
|
+
const items = config.fields.map((field)=>` ${field.title} (${field.name})`).join('\n');
|
|
35
|
+
return `Media library fields:\n${items}`;
|
|
36
|
+
}
|
|
37
|
+
default:
|
|
38
|
+
{
|
|
39
|
+
throw new Error(`Cannot create config for unknown app type: ${config.appType}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Upload the built module-federation remote to the installation as its config
|
|
45
|
+
* snapshot. `installationId` is resolved by the caller so `--dry-run` never
|
|
46
|
+
* reaches this mutating step.
|
|
47
|
+
* @internal
|
|
48
|
+
*/ export async function deployConfig(options) {
|
|
49
|
+
const { appType, installationId, output, sourceDir, version } = options;
|
|
50
|
+
const tarball = pack(dirname(sourceDir), {
|
|
51
|
+
entries: [
|
|
52
|
+
basename(sourceDir)
|
|
53
|
+
]
|
|
54
|
+
}).pipe(createGzip());
|
|
55
|
+
const formData = new FormData();
|
|
56
|
+
formData.append('version', version);
|
|
57
|
+
formData.append('tarball', tarball, {
|
|
58
|
+
contentType: 'application/gzip',
|
|
59
|
+
filename: 'installation-config.tar.gz'
|
|
60
|
+
});
|
|
61
|
+
const client = await getGlobalCliClient({
|
|
62
|
+
apiVersion: APP_WORKBENCH_API_VERSION,
|
|
63
|
+
requireUser: true
|
|
64
|
+
});
|
|
65
|
+
await client.request({
|
|
66
|
+
body: formData.pipe(new PassThrough()),
|
|
67
|
+
headers: formData.getHeaders(),
|
|
68
|
+
method: 'POST',
|
|
69
|
+
uri: `/installations/${installationId}/configs`
|
|
70
|
+
});
|
|
71
|
+
debug('Deployed config for app type: %s', appType);
|
|
72
|
+
output.log(`\n🚀 ${styleText('bold', 'Success!')} Config deployed`);
|
|
73
|
+
}
|
|
74
|
+
/** The org's active singleton installation, matched on its slug. */ async function resolveSingletonInstallationId(organizationId, slug) {
|
|
75
|
+
const client = await getGlobalCliClient({
|
|
76
|
+
apiVersion: APP_WORKBENCH_API_VERSION,
|
|
77
|
+
requireUser: true
|
|
78
|
+
});
|
|
79
|
+
// `limit=none` returns every installation in one response, no pagination.
|
|
80
|
+
const { data } = await client.request({
|
|
81
|
+
query: {
|
|
82
|
+
limit: 'none',
|
|
83
|
+
organizationId
|
|
84
|
+
},
|
|
85
|
+
uri: '/installations'
|
|
86
|
+
});
|
|
87
|
+
return data.find((item)=>item.application?.slug === slug)?.id;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=deployConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/deployConfig.ts"],"sourcesContent":["import {basename, dirname} from 'node:path'\nimport {PassThrough} from 'node:stream'\nimport {styleText} from 'node:util'\nimport {createGzip} from 'node:zlib'\n\nimport {getGlobalCliClient, type Output, subdebug} from '@sanity/cli-core'\nimport FormData from 'form-data'\nimport {pack} from 'tar-fs'\n\nimport {APP_WORKBENCH_API_VERSION} from './apiVersion.js'\n\nconst debug = subdebug('deploy')\n\ninterface InstallationListItem {\n id: string\n\n application?: {slug?: string}\n}\n\n/**\n * The org's active installation for an app type, or `undefined` when none is\n * installed. Read-only, so `--dry-run` can report deployability.\n * @internal\n */\nexport async function resolveInstallationId(options: {\n appType: string\n organizationId: string\n}): Promise<string | undefined> {\n switch (options.appType) {\n case 'media-library': {\n return resolveSingletonInstallationId(options.organizationId, 'media-library')\n }\n default: {\n throw new Error(`Cannot create config for unknown app type: ${options.appType}`)\n }\n }\n}\n\n/**\n * A report heading and item list for a config; a media library's `fields` are\n * one of potentially many shapes.\n * @internal\n */\nexport function summarizeConfig(config: {\n appType: string\n fields: {name: string; title: string}[]\n}): string {\n switch (config.appType) {\n case 'media-library': {\n const items = config.fields.map((field) => ` ${field.title} (${field.name})`).join('\\n')\n return `Media library fields:\\n${items}`\n }\n default: {\n throw new Error(`Cannot create config for unknown app type: ${config.appType}`)\n }\n }\n}\n\n/**\n * Upload the built module-federation remote to the installation as its config\n * snapshot. `installationId` is resolved by the caller so `--dry-run` never\n * reaches this mutating step.\n * @internal\n */\nexport async function deployConfig(options: {\n appType: string\n installationId: string\n output: Output\n sourceDir: string\n version: string\n}): Promise<void> {\n const {appType, installationId, output, sourceDir, version} = options\n const tarball = pack(dirname(sourceDir), {entries: [basename(sourceDir)]}).pipe(createGzip())\n const formData = new FormData()\n formData.append('version', version)\n formData.append('tarball', tarball, {\n contentType: 'application/gzip',\n filename: 'installation-config.tar.gz',\n })\n\n const client = await getGlobalCliClient({\n apiVersion: APP_WORKBENCH_API_VERSION,\n requireUser: true,\n })\n await client.request({\n body: formData.pipe(new PassThrough()),\n headers: formData.getHeaders(),\n method: 'POST',\n uri: `/installations/${installationId}/configs`,\n })\n\n debug('Deployed config for app type: %s', appType)\n output.log(`\\n🚀 ${styleText('bold', 'Success!')} Config deployed`)\n}\n\n/** The org's active singleton installation, matched on its slug. */\nasync function resolveSingletonInstallationId(\n organizationId: string,\n slug: string,\n): Promise<string | undefined> {\n const client = await getGlobalCliClient({\n apiVersion: APP_WORKBENCH_API_VERSION,\n requireUser: true,\n })\n // `limit=none` returns every installation in one response, no pagination.\n const {data}: {data: InstallationListItem[]} = await client.request({\n query: {limit: 'none', organizationId},\n uri: '/installations',\n })\n return data.find((item) => item.application?.slug === slug)?.id\n}\n"],"names":["basename","dirname","PassThrough","styleText","createGzip","getGlobalCliClient","subdebug","FormData","pack","APP_WORKBENCH_API_VERSION","debug","resolveInstallationId","options","appType","resolveSingletonInstallationId","organizationId","Error","summarizeConfig","config","items","fields","map","field","title","name","join","deployConfig","installationId","output","sourceDir","version","tarball","entries","pipe","formData","append","contentType","filename","client","apiVersion","requireUser","request","body","headers","getHeaders","method","uri","log","slug","data","query","limit","find","item","application","id"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,QAAO,YAAW;AAC3C,SAAQC,WAAW,QAAO,cAAa;AACvC,SAAQC,SAAS,QAAO,YAAW;AACnC,SAAQC,UAAU,QAAO,YAAW;AAEpC,SAAQC,kBAAkB,E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,aAAa;IACf;IACA,MAAMF,OAAOG,OAAO,CAAC;QACnBC,MAAMR,SAASD,IAAI,CAAC,IAAI/B;QACxByC,SAAST,SAASU,UAAU;QAC5BC,QAAQ;QACRC,KAAK,CAAC,eAAe,EAAEnB,eAAe,QAAQ,CAAC;IACjD;IAEAjB,MAAM,oCAAoCG;IAC1Ce,OAAOmB,GAAG,CAAC,CAAC,KAAK,EAAE5C,UAAU,QAAQ,YAAY,gBAAgB,CAAC;AACpE;AAEA,kEAAkE,GAClE,eAAeW,+BACbC,cAAsB,EACtBiC,IAAY;IAEZ,MAAMV,SAAS,MAAMjC,mBAAmB;QACtCkC,YAAY9B;QACZ+B,aAAa;IACf;IACA,0EAA0E;IAC1E,MAAM,EAACS,IAAI,EAAC,GAAmC,MAAMX,OAAOG,OAAO,CAAC;QAClES,OAAO;YAACC,OAAO;YAAQpC;QAAc;QACrC+B,KAAK;IACP;IACA,OAAOG,KAAKG,IAAI,CAAC,CAACC,OAASA,KAAKC,WAAW,EAAEN,SAASA,OAAOO;AAC/D"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { basename, dirname } from 'node:path';
|
|
2
|
+
import { PassThrough } from 'node:stream';
|
|
3
|
+
import { createGzip } from 'node:zlib';
|
|
4
|
+
import { exitCodes, getGlobalCliClient } from '@sanity/cli-core';
|
|
5
|
+
import { spinner } from '@sanity/cli-core/ux';
|
|
6
|
+
import FormData from 'form-data';
|
|
7
|
+
import { pack } from 'tar-fs';
|
|
8
|
+
import { APP_WORKBENCH_API_VERSION } from './apiVersion.js';
|
|
9
|
+
export async function getApplication(applicationId) {
|
|
10
|
+
const client = await getGlobalCliClient({
|
|
11
|
+
apiVersion: APP_WORKBENCH_API_VERSION,
|
|
12
|
+
requireUser: true
|
|
13
|
+
});
|
|
14
|
+
try {
|
|
15
|
+
return await client.request({
|
|
16
|
+
uri: `/applications/${applicationId}`
|
|
17
|
+
});
|
|
18
|
+
} catch (err) {
|
|
19
|
+
if (err?.statusCode === 404) return null;
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** Create an application and its first deployment in one call. */ export async function createApplication(options) {
|
|
24
|
+
const { interfaces, isSingleton, organizationId, projectId, slug, tarball, title, type, version, workspaces } = options;
|
|
25
|
+
const formData = new FormData();
|
|
26
|
+
formData.append('type', type);
|
|
27
|
+
formData.append('title', title);
|
|
28
|
+
formData.append('organizationId', organizationId);
|
|
29
|
+
formData.append('slug', slug);
|
|
30
|
+
if (isSingleton !== undefined) formData.append('isSingleton', String(isSingleton));
|
|
31
|
+
// Studio config is set once, at create — it's immutable on redeploy.
|
|
32
|
+
if (projectId) appendJson(formData, 'config', {
|
|
33
|
+
studio: {
|
|
34
|
+
projectId
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
appendDeploymentParts(formData, {
|
|
38
|
+
interfaces,
|
|
39
|
+
tarball,
|
|
40
|
+
version,
|
|
41
|
+
workspaces
|
|
42
|
+
});
|
|
43
|
+
return request(`/applications`, formData);
|
|
44
|
+
}
|
|
45
|
+
/** Deploy a new active version to an existing application. */ export async function createDeployment(options) {
|
|
46
|
+
const { applicationId, interfaces, isAutoUpdating, tarball, version, workspaces } = options;
|
|
47
|
+
const formData = new FormData();
|
|
48
|
+
formData.append('isAutoUpdating', isAutoUpdating.toString());
|
|
49
|
+
appendDeploymentParts(formData, {
|
|
50
|
+
interfaces,
|
|
51
|
+
tarball,
|
|
52
|
+
version,
|
|
53
|
+
workspaces
|
|
54
|
+
});
|
|
55
|
+
return request(`/applications/${applicationId}/deployments`, formData);
|
|
56
|
+
}
|
|
57
|
+
function appendDeploymentParts(formData, { interfaces, tarball, version, workspaces }) {
|
|
58
|
+
formData.append('version', version);
|
|
59
|
+
appendJson(formData, 'interfaces', interfaces);
|
|
60
|
+
// Studio-only — the server rejects a workspaces part on non-studio types.
|
|
61
|
+
if (workspaces?.length) appendJson(formData, 'workspaces', workspaces);
|
|
62
|
+
formData.append('tarball', tarball, {
|
|
63
|
+
contentType: 'application/gzip',
|
|
64
|
+
filename: 'app.tar.gz'
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/** Structured parts must arrive as JSON so the server parses them. */ function appendJson(formData, name, value) {
|
|
68
|
+
formData.append(name, JSON.stringify(value), {
|
|
69
|
+
contentType: 'application/json'
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async function request(uri, formData) {
|
|
73
|
+
const client = await getGlobalCliClient({
|
|
74
|
+
apiVersion: APP_WORKBENCH_API_VERSION,
|
|
75
|
+
requireUser: true
|
|
76
|
+
});
|
|
77
|
+
return client.request({
|
|
78
|
+
body: formData.pipe(new PassThrough()),
|
|
79
|
+
headers: formData.getHeaders(),
|
|
80
|
+
method: 'POST',
|
|
81
|
+
uri
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Deploy a workbench coreApp through Brett: redeploy when `appId` is set,
|
|
86
|
+
* otherwise create the application at `slug`. Returns the application id for the
|
|
87
|
+
* shell to report.
|
|
88
|
+
* @internal
|
|
89
|
+
*/ export async function deployCoreApp(options) {
|
|
90
|
+
const { appId, interfaces, isAutoUpdating, isSingleton, organizationId, slug, sourceDir, title, version } = options;
|
|
91
|
+
const tarball = pack(dirname(sourceDir), {
|
|
92
|
+
entries: [
|
|
93
|
+
basename(sourceDir)
|
|
94
|
+
]
|
|
95
|
+
}).pipe(createGzip());
|
|
96
|
+
const spin = spinner('Deploying...').start();
|
|
97
|
+
try {
|
|
98
|
+
if (appId) {
|
|
99
|
+
await createDeployment({
|
|
100
|
+
applicationId: appId,
|
|
101
|
+
interfaces,
|
|
102
|
+
isAutoUpdating,
|
|
103
|
+
tarball,
|
|
104
|
+
version
|
|
105
|
+
});
|
|
106
|
+
spin.succeed();
|
|
107
|
+
return {
|
|
108
|
+
applicationId: appId
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const { id } = await createApplication({
|
|
112
|
+
interfaces,
|
|
113
|
+
isSingleton,
|
|
114
|
+
organizationId,
|
|
115
|
+
slug,
|
|
116
|
+
tarball,
|
|
117
|
+
title,
|
|
118
|
+
type: 'coreApp',
|
|
119
|
+
version
|
|
120
|
+
});
|
|
121
|
+
spin.succeed();
|
|
122
|
+
return {
|
|
123
|
+
applicationId: id
|
|
124
|
+
};
|
|
125
|
+
} catch (error) {
|
|
126
|
+
spin.clear();
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Deploy a workbench studio through Brett: redeploy when `appId` is set,
|
|
132
|
+
* otherwise create the studio at `studioHost`. Returns the application id for
|
|
133
|
+
* the shell to report; a missing `studioHost` on create is a usage error.
|
|
134
|
+
* @internal
|
|
135
|
+
*/ export async function deployStudio(options) {
|
|
136
|
+
const { appId, interfaces, isAutoUpdating, organizationId, output, projectId, sourceDir, studioHost, title, version, workspaces } = options;
|
|
137
|
+
const tarball = pack(dirname(sourceDir), {
|
|
138
|
+
entries: [
|
|
139
|
+
basename(sourceDir)
|
|
140
|
+
]
|
|
141
|
+
}).pipe(createGzip());
|
|
142
|
+
const spin = spinner('Deploying to sanity.studio').start();
|
|
143
|
+
try {
|
|
144
|
+
if (appId) {
|
|
145
|
+
await createDeployment({
|
|
146
|
+
applicationId: appId,
|
|
147
|
+
interfaces,
|
|
148
|
+
isAutoUpdating,
|
|
149
|
+
tarball,
|
|
150
|
+
version,
|
|
151
|
+
workspaces
|
|
152
|
+
});
|
|
153
|
+
spin.succeed();
|
|
154
|
+
return {
|
|
155
|
+
applicationId: appId
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
if (!studioHost) {
|
|
159
|
+
spin.fail();
|
|
160
|
+
return output.error('No studio hostname configured. Set `studioHost` in sanity.cli.ts to create a studio.', {
|
|
161
|
+
exit: exitCodes.USAGE_ERROR
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
const application = await createApplication({
|
|
165
|
+
interfaces,
|
|
166
|
+
organizationId,
|
|
167
|
+
projectId,
|
|
168
|
+
slug: studioHost,
|
|
169
|
+
tarball,
|
|
170
|
+
title,
|
|
171
|
+
type: 'studio',
|
|
172
|
+
version,
|
|
173
|
+
workspaces
|
|
174
|
+
});
|
|
175
|
+
spin.succeed();
|
|
176
|
+
return {
|
|
177
|
+
applicationId: application.id
|
|
178
|
+
};
|
|
179
|
+
} catch (error) {
|
|
180
|
+
spin.fail();
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
//# sourceMappingURL=deployWorkbenchApp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/deployWorkbenchApp.ts"],"sourcesContent":["import {basename, dirname} from 'node:path'\nimport {PassThrough} from 'node:stream'\nimport {createGzip, type Gzip} from 'node:zlib'\n\nimport {exitCodes, getGlobalCliClient, type Output} from '@sanity/cli-core'\nimport {spinner} from '@sanity/cli-core/ux'\nimport FormData from 'form-data'\nimport {pack} from 'tar-fs'\n\nimport {APP_WORKBENCH_API_VERSION} from './apiVersion.js'\nimport {type BrettInterface} from './buildExposes.js'\n\nexport type ApplicationType = 'coreApp' | 'studio'\n\nexport interface Application {\n id: string\n organizationId: string\n slug: string | null\n title: string\n type: ApplicationType\n}\n\n/** A studio workspace as Brett stores it. */\nexport interface BrettWorkspace {\n dataset: string\n projectId: string\n\n basePath?: string\n icon?: string\n name?: string\n subtitle?: string\n title?: string\n}\n\nexport async function getApplication(applicationId: string): Promise<Application | null> {\n const client = await getGlobalCliClient({\n apiVersion: APP_WORKBENCH_API_VERSION,\n requireUser: true,\n })\n try {\n return await client.request({uri: `/applications/${applicationId}`})\n } catch (err) {\n if ((err as {statusCode?: number})?.statusCode === 404) return null\n throw err\n }\n}\n\n/** Create an application and its first deployment in one call. */\nexport async function createApplication(options: {\n interfaces: readonly BrettInterface[]\n isSingleton?: boolean\n organizationId: string\n projectId?: string\n slug: string\n tarball: Gzip\n title: string\n type: ApplicationType\n version: string\n workspaces?: readonly BrettWorkspace[]\n}): Promise<Application> {\n const {\n interfaces,\n isSingleton,\n organizationId,\n projectId,\n slug,\n tarball,\n title,\n type,\n version,\n workspaces,\n } = options\n const formData = new FormData()\n formData.append('type', type)\n formData.append('title', title)\n formData.append('organizationId', organizationId)\n formData.append('slug', slug)\n if (isSingleton !== undefined) formData.append('isSingleton', String(isSingleton))\n // Studio config is set once, at create — it's immutable on redeploy.\n if (projectId) appendJson(formData, 'config', {studio: {projectId}})\n appendDeploymentParts(formData, {interfaces, tarball, version, workspaces})\n return request(`/applications`, formData)\n}\n\n/** Deploy a new active version to an existing application. */\nexport async function createDeployment(options: {\n applicationId: string\n interfaces: readonly BrettInterface[]\n isAutoUpdating: boolean\n tarball: Gzip\n version: string\n workspaces?: readonly BrettWorkspace[]\n}): Promise<{id: string}> {\n const {applicationId, interfaces, isAutoUpdating, tarball, version, workspaces} = options\n const formData = new FormData()\n formData.append('isAutoUpdating', isAutoUpdating.toString())\n appendDeploymentParts(formData, {interfaces, tarball, version, workspaces})\n return request(`/applications/${applicationId}/deployments`, formData)\n}\n\nfunction appendDeploymentParts(\n formData: FormData,\n {\n interfaces,\n tarball,\n version,\n workspaces,\n }: {\n interfaces: readonly BrettInterface[]\n tarball: Gzip\n version: string\n workspaces?: readonly BrettWorkspace[]\n },\n): void {\n formData.append('version', version)\n appendJson(formData, 'interfaces', interfaces)\n // Studio-only — the server rejects a workspaces part on non-studio types.\n if (workspaces?.length) appendJson(formData, 'workspaces', workspaces)\n formData.append('tarball', tarball, {contentType: 'application/gzip', filename: 'app.tar.gz'})\n}\n\n/** Structured parts must arrive as JSON so the server parses them. */\nfunction appendJson(formData: FormData, name: string, value: unknown): void {\n formData.append(name, JSON.stringify(value), {contentType: 'application/json'})\n}\n\nasync function request<T>(uri: string, formData: FormData): Promise<T> {\n const client = await getGlobalCliClient({\n apiVersion: APP_WORKBENCH_API_VERSION,\n requireUser: true,\n })\n return client.request({\n body: formData.pipe(new PassThrough()),\n headers: formData.getHeaders(),\n method: 'POST',\n uri,\n })\n}\n\n/**\n * Deploy a workbench coreApp through Brett: redeploy when `appId` is set,\n * otherwise create the application at `slug`. Returns the application id for the\n * shell to report.\n * @internal\n */\nexport async function deployCoreApp(options: {\n appId: string | undefined\n interfaces: readonly BrettInterface[]\n isAutoUpdating: boolean\n isSingleton?: boolean\n organizationId: string\n slug: string\n sourceDir: string\n title: string\n version: string\n}): Promise<{applicationId: string}> {\n const {\n appId,\n interfaces,\n isAutoUpdating,\n isSingleton,\n organizationId,\n slug,\n sourceDir,\n title,\n version,\n } = options\n const tarball = pack(dirname(sourceDir), {entries: [basename(sourceDir)]}).pipe(createGzip())\n\n const spin = spinner('Deploying...').start()\n try {\n if (appId) {\n await createDeployment({applicationId: appId, interfaces, isAutoUpdating, tarball, version})\n spin.succeed()\n return {applicationId: appId}\n }\n\n const {id} = await createApplication({\n interfaces,\n isSingleton,\n organizationId,\n slug,\n tarball,\n title,\n type: 'coreApp',\n version,\n })\n spin.succeed()\n return {applicationId: id}\n } catch (error) {\n spin.clear()\n throw error\n }\n}\n\n/**\n * Deploy a workbench studio through Brett: redeploy when `appId` is set,\n * otherwise create the studio at `studioHost`. Returns the application id for\n * the shell to report; a missing `studioHost` on create is a usage error.\n * @internal\n */\nexport async function deployStudio(options: {\n appId: string | undefined\n interfaces: readonly BrettInterface[]\n isAutoUpdating: boolean\n organizationId: string\n output: Output\n projectId: string | undefined\n sourceDir: string\n studioHost: string | undefined\n title: string\n version: string\n workspaces: readonly BrettWorkspace[]\n}): Promise<{applicationId: string}> {\n const {\n appId,\n interfaces,\n isAutoUpdating,\n organizationId,\n output,\n projectId,\n sourceDir,\n studioHost,\n title,\n version,\n workspaces,\n } = options\n const tarball = pack(dirname(sourceDir), {entries: [basename(sourceDir)]}).pipe(createGzip())\n\n const spin = spinner('Deploying to sanity.studio').start()\n try {\n if (appId) {\n await createDeployment({\n applicationId: appId,\n interfaces,\n isAutoUpdating,\n tarball,\n version,\n workspaces,\n })\n spin.succeed()\n return {applicationId: appId}\n }\n\n if (!studioHost) {\n spin.fail()\n return output.error(\n 'No studio hostname configured. Set `studioHost` in sanity.cli.ts to create a studio.',\n {exit: exitCodes.USAGE_ERROR},\n )\n }\n\n const application = await createApplication({\n interfaces,\n organizationId,\n projectId,\n slug: studioHost,\n tarball,\n title,\n type: 'studio',\n version,\n workspaces,\n })\n spin.succeed()\n return {applicationId: application.id}\n } catch (error) {\n spin.fail()\n throw error\n }\n}\n"],"names":["basename","dirname","PassThrough","createGzip","exitCodes","getGlobalCliClient","spinner","FormData","pack","APP_WORKBENCH_API_VERSION","getApplication","applicationId","client","apiVersion","requireUser","request","uri","err","statusCode","createApplication","options","interfaces","isSingleton","organizationId","projectId","slug","tarball","title","type","version","workspaces","formData","append","undefined","String","appendJson","studio","appendDeploymentParts","createDeployment","isAutoUpdating","toString","length","contentType","filename","name","value","JSON","stringify","body","pipe","headers","getHeaders","method","deployCoreApp","appId","sourceDir","entries","spin","start","succeed","id","error","clear","deployStudio","output","studioHost","fail","exit","USAGE_ERROR","application"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,QAAO,YAAW;AAC3C,SAAQC,WAAW,QAAO,cAAa;AACvC,SAAQC,UAAU,QAAkB,YAAW;AAE/C,SAAQC,SAAS,EAAEC,kBAAkB,QAAoB,mBAAkB;AAC3E,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,OAAOC,cAAc,YAAW;AAChC,SAAQC,IAAI,QAAO,SAAQ;AAE3B,SAAQC,yBAAyB,QAAO,kBAAiB;AAyBzD,OAAO,eAAeC,eAAeC,aAAqB;IACxD,MAAMC,SAAS,MAAMP,mBAAmB;QACtCQ,YAAYJ;QACZK,aAAa;IACf;IACA,IAAI;QACF,OAAO,MAAMF,OAAOG,OAAO,CAAC;YAACC,KAAK,CAAC,cAAc,EAAEL,eAAe;QAAA;IACpE,EAAE,OAAOM,KAAK;QACZ,IAAI,AAACA,KAA+BC,eAAe,KAAK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AAEA;;;;;CAKC,GACD,OAAO,eAAeE,aAAa3C,OAYlC;IACC,MAAM,EACJkC,KAAK,EACLjC,UAAU,EACVkB,cAAc,EACdhB,cAAc,EACdyC,MAAM,EACNxC,SAAS,EACT+B,SAAS,EACTU,UAAU,EACVtC,KAAK,EACLE,OAAO,EACPC,UAAU,EACX,GAAGV;IACJ,MAAMM,UAAUlB,KAAKP,QAAQsD,YAAY;QAACC,SAAS;YAACxD,SAASuD;SAAW;IAAA,GAAGN,IAAI,CAAC9C;IAEhF,MAAMsD,OAAOnD,QAAQ,8BAA8BoD,KAAK;IACxD,IAAI;QACF,IAAIJ,OAAO;YACT,MAAMhB,iBAAiB;gBACrB3B,eAAe2C;gBACfjC;gBACAkB;gBACAb;gBACAG;gBACAC;YACF;YACA2B,KAAKE,OAAO;YACZ,OAAO;gBAAChD,eAAe2C;YAAK;QAC9B;QAEA,IAAI,CAACW,YAAY;YACfR,KAAKS,IAAI;YACT,OAAOF,OAAOH,KAAK,CACjB,wFACA;gBAACM,MAAM/D,UAAUgE,WAAW;YAAA;QAEhC;QAEA,MAAMC,cAAc,MAAMlD,kBAAkB;YAC1CE;YACAE;YACAC;YACAC,MAAMwC;YACNvC;YACAC;YACAC,MAAM;YACNC;YACAC;QACF;QACA2B,KAAKE,OAAO;QACZ,OAAO;YAAChD,eAAe0D,YAAYT,EAAE;QAAA;IACvC,EAAE,OAAOC,OAAO;QACdJ,KAAKS,IAAI;QACT,MAAML;IACR;AACF"}
|
|
@@ -1,38 +1,27 @@
|
|
|
1
1
|
// The deploy command's view of a workbench app: the resolved interfaces plus
|
|
2
|
-
// the
|
|
3
|
-
// and either gets `null` (plain project — normal
|
|
4
|
-
// to validate the app
|
|
5
|
-
//
|
|
6
|
-
// Node-only (the build-output guard touches the filesystem).
|
|
7
|
-
import { stat } from 'node:fs/promises';
|
|
8
|
-
import { join } from 'node:path';
|
|
2
|
+
// the deploy-time guards that need the app's declarations. `sanity deploy` calls
|
|
3
|
+
// `getWorkbench(config)` once and either gets `null` (plain project — normal
|
|
4
|
+
// deploy) or an object it asks to validate the app before shipping.
|
|
9
5
|
import { resolveWorkbenchApp } from '../../resolveWorkbenchApp.js';
|
|
6
|
+
import { buildViewDeploymentPayload } from './viewDeployment.js';
|
|
10
7
|
export function getWorkbench(cliConfig) {
|
|
11
8
|
const app = resolveWorkbenchApp(cliConfig);
|
|
12
9
|
if (!app) return null;
|
|
13
|
-
const { entry, services, views } = app;
|
|
10
|
+
const { config, entry, isSingleton, services, views } = app;
|
|
14
11
|
return {
|
|
15
12
|
...app,
|
|
13
|
+
deploySingletonConfig: !!isSingleton && !!config,
|
|
14
|
+
hasInterfaces: !!entry || views.length > 0 || services.length > 0,
|
|
16
15
|
assertDeployable () {
|
|
17
|
-
if (!entry && views.length === 0 && services.length === 0) {
|
|
18
|
-
throw new Error('Nothing to deploy:
|
|
16
|
+
if (!entry && views.length === 0 && services.length === 0 && !config) {
|
|
17
|
+
throw new Error('Nothing to deploy: the app declares no entry, views, services or config. ' + 'Add at least one to the app config.');
|
|
19
18
|
}
|
|
20
19
|
},
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
} catch (err) {
|
|
28
|
-
throw err.code === 'ENOENT' ? new Error(`Directory "${sourceDir}" does not exist`) : err;
|
|
29
|
-
}
|
|
30
|
-
const manifestPath = join(sourceDir, 'mf-manifest.json');
|
|
31
|
-
try {
|
|
32
|
-
await stat(manifestPath);
|
|
33
|
-
} catch (err) {
|
|
34
|
-
throw err.code === 'ENOENT' ? new Error(`"${manifestPath}" does not exist. ` + 'The deploy directory must contain a federation build created with "sanity build".') : err;
|
|
35
|
-
}
|
|
20
|
+
buildViewDeploymentPayload (applicationId) {
|
|
21
|
+
return buildViewDeploymentPayload({
|
|
22
|
+
applicationId,
|
|
23
|
+
views
|
|
24
|
+
});
|
|
36
25
|
}
|
|
37
26
|
};
|
|
38
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/deploy/getWorkbench.ts"],"sourcesContent":["// The deploy command's view of a workbench app: the resolved interfaces plus\n// the
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/getWorkbench.ts"],"sourcesContent":["// The deploy command's view of a workbench app: the resolved interfaces plus\n// the deploy-time guards that need the app's declarations. `sanity deploy` calls\n// `getWorkbench(config)` once and either gets `null` (plain project — normal\n// deploy) or an object it asks to validate the app before shipping.\n\nimport {type CliConfig} from '@sanity/cli-core'\n\nimport {type ResolvedWorkbenchApp, resolveWorkbenchApp} from '../../resolveWorkbenchApp.js'\nimport {buildViewDeploymentPayload, type ViewDeploymentPayload} from './viewDeployment.js'\n\ninterface DeployableWorkbenchApp extends ResolvedWorkbenchApp {\n /**\n * Throws when the app exposes nothing (no entry, view, service, or config) —\n * the remote would have nothing to load. Gated before any prompt or API call.\n */\n assertDeployable(): void\n /**\n * Validates the app's declared views into the application-service payload.\n * Throws when a view declaration is malformed.\n */\n buildViewDeploymentPayload(applicationId: string): ViewDeploymentPayload\n /**\n * A singleton (the Media Library) that carries an config — deploy\n * persists the config to the org's installation. Independent of the interfaces,\n * which register regardless; non-singletons never carry a config.\n */\n deploySingletonConfig: boolean\n /** Declares something to host as an application — an entry, view, or service. */\n hasInterfaces: boolean\n}\n\nexport function getWorkbench(\n cliConfig: CliConfig | null | undefined,\n): DeployableWorkbenchApp | null {\n const app = resolveWorkbenchApp(cliConfig)\n if (!app) return null\n\n const {config, entry, isSingleton, services, views} = app\n\n return {\n ...app,\n\n deploySingletonConfig: !!isSingleton && !!config,\n hasInterfaces: !!entry || views.length > 0 || services.length > 0,\n\n assertDeployable() {\n if (!entry && views.length === 0 && services.length === 0 && !config) {\n throw new Error(\n 'Nothing to deploy: the app declares no entry, views, services or config. ' +\n 'Add at least one to the app config.',\n )\n }\n },\n\n buildViewDeploymentPayload(applicationId) {\n return buildViewDeploymentPayload({applicationId, views})\n },\n }\n}\n"],"names":["resolveWorkbenchApp","buildViewDeploymentPayload","getWorkbench","cliConfig","app","config","entry","isSingleton","services","views","deploySingletonConfig","hasInterfaces","length","assertDeployable","Error","applicationId"],"mappings":"AAAA,6EAA6E;AAC7E,iFAAiF;AACjF,6EAA6E;AAC7E,oEAAoE;AAIpE,SAAmCA,mBAAmB,QAAO,+BAA8B;AAC3F,SAAQC,0BAA0B,QAAmC,sBAAqB;AAuB1F,OAAO,SAASC,aACdC,SAAuC;IAEvC,MAAMC,MAAMJ,oBAAoBG;IAChC,IAAI,CAACC,KAAK,OAAO;IAEjB,MAAM,EAACC,MAAM,EAAEC,KAAK,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,KAAK,EAAC,GAAGL;IAEtD,OAAO;QACL,GAAGA,GAAG;QAENM,uBAAuB,CAAC,CAACH,eAAe,CAAC,CAACF;QAC1CM,eAAe,CAAC,CAACL,SAASG,MAAMG,MAAM,GAAG,KAAKJ,SAASI,MAAM,GAAG;QAEhEC;YACE,IAAI,CAACP,SAASG,MAAMG,MAAM,KAAK,KAAKJ,SAASI,MAAM,KAAK,KAAK,CAACP,QAAQ;gBACpE,MAAM,IAAIS,MACR,8EACE;YAEN;QACF;QAEAb,4BAA2Bc,aAAa;YACtC,OAAOd,2BAA2B;gBAACc;gBAAeN;YAAK;QACzD;IACF;AACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from 'zod/mini';
|
|
2
|
+
/**
|
|
3
|
+
* A view record as persisted to the application service: `type`, `name`, `src`,
|
|
4
|
+
* plus any view-type-specific attributes (passed through for storage).
|
|
5
|
+
*/ const viewRecordSchema = z.looseObject({
|
|
6
|
+
name: z.string().check(z.regex(/^[a-zA-Z0-9_-]+$/, 'View `name` must match /^[a-zA-Z0-9_-]+$/')),
|
|
7
|
+
src: z.string(),
|
|
8
|
+
type: z.enum([
|
|
9
|
+
'panel'
|
|
10
|
+
])
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Payload registering an app's views with the application service on deploy.
|
|
14
|
+
*
|
|
15
|
+
* Phase 1 stub: the service that stores views does not exist yet, so the
|
|
16
|
+
* payload is validated and logged only — never sent. Builds the contract the
|
|
17
|
+
* application-service endpoint will accept.
|
|
18
|
+
*/ const viewDeploymentPayloadSchema = z.object({
|
|
19
|
+
applicationId: z.string(),
|
|
20
|
+
views: z.array(viewRecordSchema)
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Validates an app's declared views into the application-service payload.
|
|
24
|
+
* Throws (via Zod) when a view declaration is malformed.
|
|
25
|
+
*/ export function buildViewDeploymentPayload(input) {
|
|
26
|
+
return viewDeploymentPayloadSchema.parse({
|
|
27
|
+
applicationId: input.applicationId,
|
|
28
|
+
views: input.views ?? []
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=viewDeployment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/viewDeployment.ts"],"sourcesContent":["import {z} from 'zod/mini'\n\n/**\n * A view record as persisted to the application service: `type`, `name`, `src`,\n * plus any view-type-specific attributes (passed through for storage).\n */\nconst viewRecordSchema = z.looseObject({\n name: z.string().check(z.regex(/^[a-zA-Z0-9_-]+$/, 'View `name` must match /^[a-zA-Z0-9_-]+$/')),\n src: z.string(),\n type: z.enum(['panel']),\n})\n\n/**\n * Payload registering an app's views with the application service on deploy.\n *\n * Phase 1 stub: the service that stores views does not exist yet, so the\n * payload is validated and logged only — never sent. Builds the contract the\n * application-service endpoint will accept.\n */\nconst viewDeploymentPayloadSchema = z.object({\n applicationId: z.string(),\n views: z.array(viewRecordSchema),\n})\n\nexport type ViewDeploymentPayload = z.infer<typeof viewDeploymentPayloadSchema>\n\n/**\n * Validates an app's declared views into the application-service payload.\n * Throws (via Zod) when a view declaration is malformed.\n */\nexport function buildViewDeploymentPayload(input: {\n applicationId: string\n views?: ReadonlyArray<Record<string, unknown>>\n}): ViewDeploymentPayload {\n return viewDeploymentPayloadSchema.parse({\n applicationId: input.applicationId,\n views: input.views ?? [],\n })\n}\n"],"names":["z","viewRecordSchema","looseObject","name","string","check","regex","src","type","enum","viewDeploymentPayloadSchema","object","applicationId","views","array","buildViewDeploymentPayload","input","parse"],"mappings":"AAAA,SAAQA,CAAC,QAAO,WAAU;AAE1B;;;CAGC,GACD,MAAMC,mBAAmBD,EAAEE,WAAW,CAAC;IACrCC,MAAMH,EAAEI,MAAM,GAAGC,KAAK,CAACL,EAAEM,KAAK,CAAC,oBAAoB;IACnDC,KAAKP,EAAEI,MAAM;IACbI,MAAMR,EAAES,IAAI,CAAC;QAAC;KAAQ;AACxB;AAEA;;;;;;CAMC,GACD,MAAMC,8BAA8BV,EAAEW,MAAM,CAAC;IAC3CC,eAAeZ,EAAEI,MAAM;IACvBS,OAAOb,EAAEc,KAAK,CAACb;AACjB;AAIA;;;CAGC,GACD,OAAO,SAASc,2BAA2BC,KAG1C;IACC,OAAON,4BAA4BO,KAAK,CAAC;QACvCL,eAAeI,MAAMJ,aAAa;QAClCC,OAAOG,MAAMH,KAAK,IAAI,EAAE;IAC1B;AACF"}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { hash } from 'node:crypto';
|
|
2
|
+
import { MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION, SERVICE_CONTRACT_VERSION, VIEW_CONTRACT_VERSION } from '../../contract.js';
|
|
3
|
+
import { isWorkbenchApp, readConfig } from '../../defineApp.js';
|
|
2
4
|
/**
|
|
3
|
-
* Map
|
|
4
|
-
*
|
|
5
|
+
* Map a workbench app's declarations to the interface records forwarded on its
|
|
6
|
+
* registry entry: `views` → panels, `services` → workers, `entry` → the
|
|
5
7
|
* navigable `app` view (`entry_point` is the raw `src`, not a resolved URL).
|
|
6
8
|
* `undefined` for a non-branded app; a studio that declares `entry` is rejected
|
|
7
|
-
* (studio app views are not implemented yet).
|
|
9
|
+
* (studio app views are not implemented yet). The config is not an
|
|
10
|
+
* interface — see {@link deriveConfigs}. `version` is the contract version the
|
|
11
|
+
* interface's generated module exports, known before the module runs; the app
|
|
12
|
+
* view has no versioned contract, so it carries none.
|
|
8
13
|
*/ export function deriveInterfaces(app, options) {
|
|
9
14
|
if (!isWorkbenchApp(app)) return undefined;
|
|
10
15
|
if (!options.isApp && app.entry !== undefined) {
|
|
@@ -14,12 +19,14 @@ import { isWorkbenchApp } from '@sanity/cli-core';
|
|
|
14
19
|
...app.views?.map((view)=>({
|
|
15
20
|
entry_point: view.src,
|
|
16
21
|
interface_type: view.type,
|
|
17
|
-
name: view.name
|
|
22
|
+
name: view.name,
|
|
23
|
+
version: VIEW_CONTRACT_VERSION
|
|
18
24
|
})) ?? [],
|
|
19
25
|
...app.services?.map((service)=>({
|
|
20
26
|
entry_point: service.src,
|
|
21
27
|
interface_type: service.type,
|
|
22
|
-
name: service.name
|
|
28
|
+
name: service.name,
|
|
29
|
+
version: SERVICE_CONTRACT_VERSION
|
|
23
30
|
})) ?? [],
|
|
24
31
|
...app.entry === undefined ? [] : [
|
|
25
32
|
{
|
|
@@ -30,5 +37,55 @@ import { isWorkbenchApp } from '@sanity/cli-core';
|
|
|
30
37
|
]
|
|
31
38
|
];
|
|
32
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* The named source files a config's generated module is built from, dispatched
|
|
42
|
+
* per app type — the projection the exposes-set id keys on, so the generic HMR
|
|
43
|
+
* tracker owns none of the per-type shape. Throws on an app type it can't
|
|
44
|
+
* handle, so a new config family has to register its shape here.
|
|
45
|
+
*/ export function deriveConfigEntries(config) {
|
|
46
|
+
switch(config.appType){
|
|
47
|
+
case 'media-library':
|
|
48
|
+
{
|
|
49
|
+
return config.fields.map((field)=>({
|
|
50
|
+
name: field.name,
|
|
51
|
+
src: field.src
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
default:
|
|
55
|
+
{
|
|
56
|
+
throw new Error(`Cannot derive entries for unknown config appType: ${config.appType}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The fields' schema *values* can't serialize — the workbench loads them from
|
|
62
|
+
* the federation module. `src` stays on so the exposes-set id keys on it and a
|
|
63
|
+
* repoint rebuilds. `appType` routes the config to the singleton (no app id to
|
|
64
|
+
* key on). `id` is a content hash of the entry — it fills the
|
|
65
|
+
* installation-config id slot deployed apps get from the applications API,
|
|
66
|
+
* and the workbench keys change detection on it. `version` is the config
|
|
67
|
+
* contract version the generated module exports, known before the module runs.
|
|
68
|
+
*/ export function deriveConfigs(app) {
|
|
69
|
+
if (!isWorkbenchApp(app)) return [];
|
|
70
|
+
const config = readConfig(app);
|
|
71
|
+
if (!config) return [];
|
|
72
|
+
const entry = {
|
|
73
|
+
appType: config.appType,
|
|
74
|
+
fields: config.fields.map((field)=>({
|
|
75
|
+
name: field.name,
|
|
76
|
+
public: field.public,
|
|
77
|
+
src: field.src,
|
|
78
|
+
title: field.title
|
|
79
|
+
})),
|
|
80
|
+
moduleName: app.name,
|
|
81
|
+
version: MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION
|
|
82
|
+
};
|
|
83
|
+
return [
|
|
84
|
+
{
|
|
85
|
+
...entry,
|
|
86
|
+
id: hash('sha1', JSON.stringify(entry))
|
|
87
|
+
}
|
|
88
|
+
];
|
|
89
|
+
}
|
|
33
90
|
|
|
34
91
|
//# sourceMappingURL=deriveInterfaces.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/dev/deriveInterfaces.ts"],"sourcesContent":["import {type CliConfig
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/dev/deriveInterfaces.ts"],"sourcesContent":["import {hash} from 'node:crypto'\n\nimport {type CliConfig} from '@sanity/cli-core'\n\nimport {\n MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION,\n SERVICE_CONTRACT_VERSION,\n VIEW_CONTRACT_VERSION,\n} from '../../contract.js'\nimport {isWorkbenchApp, readConfig} from '../../defineApp.js'\nimport {type DevServerManifest} from './registry.js'\n\n/** One forwarded interface record on the dev-server registry entry. */\nexport type DevServerInterface = NonNullable<DevServerManifest['interfaces']>[number]\n\n/** One forwarded config on the dev-server registry entry. */\nexport type DevServerConfig = NonNullable<DevServerManifest['configs']>[number]\n\n/**\n * Map a workbench app's declarations to the interface records forwarded on its\n * registry entry: `views` → panels, `services` → workers, `entry` → the\n * navigable `app` view (`entry_point` is the raw `src`, not a resolved URL).\n * `undefined` for a non-branded app; a studio that declares `entry` is rejected\n * (studio app views are not implemented yet). The config is not an\n * interface — see {@link deriveConfigs}. `version` is the contract version the\n * interface's generated module exports, known before the module runs; the app\n * view has no versioned contract, so it carries none.\n */\nexport function deriveInterfaces(\n app: CliConfig['app'],\n options: {isApp: boolean},\n): DevServerInterface[] | undefined {\n if (!isWorkbenchApp(app)) return undefined\n\n if (!options.isApp && app.entry !== undefined) {\n throw new Error('App views for studios are not implemented yet')\n }\n\n return [\n ...(app.views?.map((view) => ({\n entry_point: view.src,\n interface_type: view.type,\n name: view.name,\n version: VIEW_CONTRACT_VERSION,\n })) ?? []),\n ...(app.services?.map((service) => ({\n entry_point: service.src,\n interface_type: service.type,\n name: service.name,\n version: SERVICE_CONTRACT_VERSION,\n })) ?? []),\n ...(app.entry === undefined\n ? []\n : [{entry_point: app.entry, interface_type: 'app' as const, name: app.name}]),\n ]\n}\n\n/**\n * The named source files a config's generated module is built from, dispatched\n * per app type — the projection the exposes-set id keys on, so the generic HMR\n * tracker owns none of the per-type shape. Throws on an app type it can't\n * handle, so a new config family has to register its shape here.\n */\nexport function deriveConfigEntries(config: DevServerConfig): {name: string; src: string}[] {\n switch (config.appType) {\n case 'media-library': {\n return config.fields.map((field) => ({name: field.name, src: field.src}))\n }\n default: {\n throw new Error(`Cannot derive entries for unknown config appType: ${config.appType}`)\n }\n }\n}\n\n/**\n * The fields' schema *values* can't serialize — the workbench loads them from\n * the federation module. `src` stays on so the exposes-set id keys on it and a\n * repoint rebuilds. `appType` routes the config to the singleton (no app id to\n * key on). `id` is a content hash of the entry — it fills the\n * installation-config id slot deployed apps get from the applications API,\n * and the workbench keys change detection on it. `version` is the config\n * contract version the generated module exports, known before the module runs.\n */\nexport function deriveConfigs(app: CliConfig['app']): DevServerConfig[] {\n if (!isWorkbenchApp(app)) return []\n const config = readConfig(app)\n if (!config) return []\n const entry = {\n appType: config.appType,\n fields: config.fields.map((field) => ({\n name: field.name,\n public: field.public,\n src: field.src,\n title: field.title,\n })),\n moduleName: app.name,\n version: MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION,\n }\n return [{...entry, id: hash('sha1', JSON.stringify(entry))}]\n}\n"],"names":["hash","MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION","SERVICE_CONTRACT_VERSION","VIEW_CONTRACT_VERSION","isWorkbenchApp","readConfig","deriveInterfaces","app","options","undefined","isApp","entry","Error","views","map","view","entry_point","src","interface_type","type","name","version","services","service","deriveConfigEntries","config","appType","fields","field","deriveConfigs","public","title","moduleName","id","JSON","stringify"],"mappings":"AAAA,SAAQA,IAAI,QAAO,cAAa;AAIhC,SACEC,qCAAqC,EACrCC,wBAAwB,EACxBC,qBAAqB,QAChB,oBAAmB;AAC1B,SAAQC,cAAc,EAAEC,UAAU,QAAO,qBAAoB;AAS7D;;;;;;;;;CASC,GACD,OAAO,SAASC,iBACdC,GAAqB,EACrBC,OAAyB;IAEzB,IAAI,CAACJ,eAAeG,MAAM,OAAOE;IAEjC,IAAI,CAACD,QAAQE,KAAK,IAAIH,IAAII,KAAK,KAAKF,WAAW;QAC7C,MAAM,IAAIG,MAAM;IAClB;IAEA,OAAO;WACDL,IAAIM,KAAK,EAAEC,IAAI,CAACC,OAAU,CAAA;gBAC5BC,aAAaD,KAAKE,GAAG;gBACrBC,gBAAgBH,KAAKI,IAAI;gBACzBC,MAAML,KAAKK,IAAI;gBACfC,SAASlB;YACX,CAAA,MAAO,EAAE;WACLI,IAAIe,QAAQ,EAAER,IAAI,CAACS,UAAa,CAAA;gB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