@sanity/cli 7.5.0 β†’ 7.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +6 -2
  2. package/dist/actions/build/buildApp.js +7 -183
  3. package/dist/actions/build/buildApp.js.map +1 -1
  4. package/dist/actions/build/buildStudio.js +6 -213
  5. package/dist/actions/build/buildStudio.js.map +1 -1
  6. package/dist/actions/build/shouldAutoUpdate.js +100 -22
  7. package/dist/actions/build/shouldAutoUpdate.js.map +1 -1
  8. package/dist/actions/deploy/{createStudioUserApplication.js β†’ createUserApplication.js} +56 -5
  9. package/dist/actions/deploy/createUserApplication.js.map +1 -0
  10. package/dist/actions/deploy/deployApp.js +253 -183
  11. package/dist/actions/deploy/deployApp.js.map +1 -1
  12. package/dist/actions/deploy/deployChecks.js +284 -0
  13. package/dist/actions/deploy/deployChecks.js.map +1 -0
  14. package/dist/actions/deploy/deployRunner.js +78 -0
  15. package/dist/actions/deploy/deployRunner.js.map +1 -0
  16. package/dist/actions/deploy/deployStudio.js +200 -197
  17. package/dist/actions/deploy/deployStudio.js.map +1 -1
  18. package/dist/actions/deploy/deployStudioSchemasAndManifests.js +2 -3
  19. package/dist/actions/deploy/deployStudioSchemasAndManifests.js.map +1 -1
  20. package/dist/actions/deploy/deploymentPlan.js +117 -0
  21. package/dist/actions/deploy/deploymentPlan.js.map +1 -0
  22. package/dist/actions/deploy/findUserApplication.js +209 -0
  23. package/dist/actions/deploy/findUserApplication.js.map +1 -0
  24. package/dist/actions/deploy/resolveDeployTarget.js +185 -0
  25. package/dist/actions/deploy/resolveDeployTarget.js.map +1 -0
  26. package/dist/actions/deploy/urlUtils.js +4 -0
  27. package/dist/actions/deploy/urlUtils.js.map +1 -1
  28. package/dist/actions/dev/devAction.js +1 -1
  29. package/dist/actions/dev/devAction.js.map +1 -1
  30. package/dist/actions/dev/servers/getDevServerConfig.js +18 -6
  31. package/dist/actions/dev/servers/getDevServerConfig.js.map +1 -1
  32. package/dist/actions/dev/servers/startAppDevServer.js +1 -1
  33. package/dist/actions/dev/servers/startAppDevServer.js.map +1 -1
  34. package/dist/actions/dev/servers/startStudioDevServer.js +2 -1
  35. package/dist/actions/dev/servers/startStudioDevServer.js.map +1 -1
  36. package/dist/actions/manifest/extractCoreAppManifest.js +15 -1
  37. package/dist/actions/manifest/extractCoreAppManifest.js.map +1 -1
  38. package/dist/commands/deploy.js +31 -12
  39. package/dist/commands/deploy.js.map +1 -1
  40. package/dist/commands/dev.js +2 -1
  41. package/dist/commands/dev.js.map +1 -1
  42. package/dist/commands/init.js +2 -1
  43. package/dist/commands/init.js.map +1 -1
  44. package/dist/exports/index.d.ts +9 -0
  45. package/dist/exports/index.js +1 -8
  46. package/dist/exports/index.js.map +1 -1
  47. package/dist/server/devServer.js +27 -3
  48. package/dist/server/devServer.js.map +1 -1
  49. package/dist/services/userApplications.js.map +1 -1
  50. package/dist/util/appId.js +13 -5
  51. package/dist/util/appId.js.map +1 -1
  52. package/dist/util/compareDependencyVersions.js.map +1 -1
  53. package/dist/util/determineIsApp.js +1 -1
  54. package/dist/util/determineIsApp.js.map +1 -1
  55. package/dist/util/errorMessages.js +2 -0
  56. package/dist/util/errorMessages.js.map +1 -1
  57. package/oclif.manifest.json +223 -203
  58. package/package.json +8 -8
  59. package/dist/actions/build/handlePrereleaseVersions.js +0 -44
  60. package/dist/actions/build/handlePrereleaseVersions.js.map +0 -1
  61. package/dist/actions/deploy/createStudioUserApplication.js.map +0 -1
  62. package/dist/actions/deploy/createUserApplicationForApp.js +0 -56
  63. package/dist/actions/deploy/createUserApplicationForApp.js.map +0 -1
  64. package/dist/actions/deploy/findUserApplicationForApp.js +0 -111
  65. package/dist/actions/deploy/findUserApplicationForApp.js.map +0 -1
  66. package/dist/actions/deploy/findUserApplicationForStudio.js +0 -172
  67. package/dist/actions/deploy/findUserApplicationForStudio.js.map +0 -1
  68. package/dist/actions/deploy/viewDeployment.js +0 -32
  69. package/dist/actions/deploy/viewDeployment.js.map +0 -1
@@ -1,86 +1,99 @@
1
1
  import { basename, dirname } from 'node:path';
2
2
  import { styleText } from 'node:util';
3
3
  import { createGzip } from 'node:zlib';
4
- import { CLIError } from '@oclif/core/errors';
5
- import { exitCodes, getLocalPackageVersion } from '@sanity/cli-core';
4
+ import { exitCodes } from '@sanity/cli-core';
6
5
  import { spinner } from '@sanity/cli-core/ux';
7
- import { getWorkbench } from '@sanity/workbench-cli/deploy';
6
+ import { deployInstallationConfig, getWorkbench, resolveInstallationId, summarizeInstallationConfig } from '@sanity/workbench-cli/deploy';
8
7
  import { pack } from 'tar-fs';
9
8
  import { createDeployment, updateUserApplication } from '../../services/userApplications.js';
10
9
  import { getAppId } from '../../util/appId.js';
11
- import { NO_ORGANIZATION_ID } from '../../util/errorMessages.js';
10
+ import { EXTERNAL_APP_NOT_SUPPORTED, NO_ORGANIZATION_ID } from '../../util/errorMessages.js';
12
11
  import { getErrorMessage } from '../../util/getErrorMessage.js';
13
12
  import { buildApp } from '../build/buildApp.js';
14
- import { shouldAutoUpdate } from '../build/shouldAutoUpdate.js';
15
- import { extractCoreAppManifest } from '../manifest/extractCoreAppManifest.js';
16
- import { checkDir } from './checkDir.js';
17
- import { createUserApplicationForApp } from './createUserApplicationForApp.js';
13
+ import { extractCoreAppManifest, resolveTitleUpdate } from '../manifest/extractCoreAppManifest.js';
14
+ import { createUserApplication } from './createUserApplication.js';
15
+ import { checkAppId, checkAppTarget, checkAutoUpdates, checkBuild, checkPackageVersion, verifyOutputDir } from './deployChecks.js';
18
16
  import { deployDebug } from './deployDebug.js';
19
- import { findUserApplicationForApp } from './findUserApplicationForApp.js';
20
- import { buildViewDeploymentPayload } from './viewDeployment.js';
21
- /**
22
- * Deploy a Sanity application.
23
- *
24
- * @internal
25
- */ export async function deployApp(options) {
26
- const { cliConfig, flags, output, projectRoot, sourceDir } = options;
27
- const workbench = getWorkbench(cliConfig);
28
- const workDir = projectRoot.directory;
29
- const organizationId = cliConfig.app?.organizationId;
30
- const appId = getAppId(cliConfig);
31
- const isAutoUpdating = shouldAutoUpdate({
32
- cliConfig,
33
- flags,
34
- output
17
+ import { listDeploymentFiles } from './deploymentPlan.js';
18
+ import { runDeploy } from './deployRunner.js';
19
+ import { findUserApplication } from './findUserApplication.js';
20
+ import { getCoreAppUrl } from './urlUtils.js';
21
+ const APP_PACKAGE = '@sanity/sdk-react';
22
+ export function deployApp(options) {
23
+ return runDeploy(options, {
24
+ listFiles: ({ projectRoot, sourceDir })=>listDeploymentFiles(sourceDir, projectRoot.directory),
25
+ run: runAppDeployment,
26
+ type: 'coreApp'
35
27
  });
36
- const installedSdkVersion = await getLocalPackageVersion('@sanity/sdk-react', workDir);
37
- if (!installedSdkVersion) {
38
- output.error(`Failed to find installed @sanity/sdk-react version`, {
39
- exit: 1
40
- });
41
- return;
42
- }
43
- if (!organizationId) {
44
- output.error(NO_ORGANIZATION_ID, {
45
- exit: 1
46
- });
47
- return;
48
- }
49
- if (flags.external) {
50
- output.error('Deploying an app to an external host is not supported.', {
51
- exit: 1
52
- });
53
- }
54
- // Fail before any prompts or API calls when the app declares nothing to
55
- // expose.
28
+ }
29
+ /** Validates the deploy, syncs the title from the manifest, and ships the build. */ async function runAppDeployment(options, reporter) {
30
+ const { cliConfig, flags, output, sourceDir } = options;
31
+ const workDir = options.projectRoot.directory;
32
+ const organizationId = cliConfig.app?.organizationId;
33
+ const workbench = getWorkbench(cliConfig);
34
+ const dryRun = !!flags['dry-run'];
35
+ // A singleton (the Media Library) persists its config instead of hosting an
36
+ // application; anything with interfaces still ships one.
37
+ const deploySingletonInstallationConfig = workbench?.deploySingletonInstallationConfig ?? false;
38
+ const deployApplication = !workbench || workbench.hasInterfaces;
39
+ // A federated app with no entry, view or service would ship a remote with
40
+ // nothing to load β€” reported first so it fails before any prompt or API call.
56
41
  if (workbench) {
57
42
  try {
58
43
  workbench.assertDeployable();
59
44
  } catch (err) {
60
- output.error(getErrorMessage(err), {
61
- exit: exitCodes.USAGE_ERROR
45
+ reporter.report({
46
+ exitCode: exitCodes.USAGE_ERROR,
47
+ message: getErrorMessage(err),
48
+ solution: 'Declare at least one entry, view, or service in the app',
49
+ status: 'fail'
62
50
  });
63
- return;
64
51
  }
65
52
  }
66
- let spin = spinner('Verifying local content...');
67
- try {
68
- let userApplication = await findUserApplicationForApp({
69
- cliConfig,
70
- organizationId,
71
- output
53
+ const isAutoUpdating = checkAutoUpdates(reporter, {
54
+ cliConfig,
55
+ flags
56
+ });
57
+ // An application ships the SDK runtime; a media-library config stamps its
58
+ // `sanity` version instead.
59
+ let version = null;
60
+ if (deployApplication) {
61
+ version = await checkPackageVersion(reporter, {
62
+ moduleName: APP_PACKAGE,
63
+ workDir
72
64
  });
73
- deployDebug(`User application found`, userApplication);
74
- if (!userApplication) {
75
- deployDebug(`No user application found. Creating a new one`);
76
- userApplication = await createUserApplicationForApp(organizationId);
77
- deployDebug(`User application created`, userApplication);
78
- }
79
- // Always build the project, unless --no-build is passed
80
- const shouldBuild = flags.build;
81
- if (shouldBuild) {
82
- deployDebug(`Building app`);
83
- await buildApp({
65
+ } else if (deploySingletonInstallationConfig) {
66
+ version = await checkPackageVersion(reporter, {
67
+ moduleName: 'sanity',
68
+ workDir
69
+ });
70
+ }
71
+ reporter.report(organizationId ? {
72
+ message: `Organization: ${organizationId}`,
73
+ status: 'pass'
74
+ } : {
75
+ message: NO_ORGANIZATION_ID,
76
+ solution: 'Add `app.organizationId` to sanity.cli.ts',
77
+ status: 'fail'
78
+ });
79
+ checkAppId(reporter, {
80
+ cliConfig
81
+ });
82
+ let application = null;
83
+ if (flags.external) {
84
+ reporter.report({
85
+ message: EXTERNAL_APP_NOT_SUPPORTED,
86
+ solution: 'Remove the --external flag β€” apps deploy to Sanity hosting',
87
+ status: 'fail'
88
+ });
89
+ } else if (deployApplication) {
90
+ application = await resolveAppApplication(options, {
91
+ dryRun,
92
+ reporter
93
+ });
94
+ }
95
+ await checkBuild(reporter, {
96
+ build: ()=>buildApp({
84
97
  autoUpdatesEnabled: isAutoUpdating,
85
98
  calledFromDeploy: true,
86
99
  cliConfig,
@@ -88,139 +101,196 @@ import { buildViewDeploymentPayload } from './viewDeployment.js';
88
101
  outDir: sourceDir,
89
102
  output,
90
103
  workDir
91
- });
92
- }
93
- // Ensure that the directory exists, is a directory and seems to have valid content
94
- spin = spin.start();
95
- try {
96
- await (workbench ? workbench.checkBuiltOutput(sourceDir) : checkDir(sourceDir));
97
- spin.succeed();
98
- } catch (err) {
99
- spin.fail();
100
- deployDebug('Error checking directory', err);
101
- output.error(getErrorMessage(err), {
102
- exit: 1
103
- });
104
- return;
105
- }
106
- // Create a tarball of the given directory
107
- const parentDir = dirname(sourceDir);
108
- const base = basename(sourceDir);
109
- const tarball = pack(parentDir, {
110
- entries: [
111
- base
112
- ]
113
- }).pipe(createGzip());
114
- let manifest;
115
- try {
116
- manifest = await extractCoreAppManifest({
117
- workDir
118
- });
119
- } catch (err) {
120
- deployDebug('Error extracting app manifest', err);
121
- const message = getErrorMessage(err);
122
- // manifests aren't strictly essential, so continue deploy
123
- output.warn(`Error extracting app manifest: ${message}`);
104
+ }),
105
+ skipReason: flags.build ? undefined : 'Build skipped (--no-build) β€” validating existing output directory',
106
+ successMessage: 'App built'
107
+ });
108
+ await verifyOutputDir({
109
+ isWorkbenchApp: workbench !== null,
110
+ reporter,
111
+ sourceDir
112
+ });
113
+ // Manifests aren't strictly essential, so a failure warns and continues
114
+ let manifest;
115
+ try {
116
+ manifest = await extractCoreAppManifest({
117
+ workDir
118
+ });
119
+ } catch (err) {
120
+ deployDebug('Error extracting app manifest', err);
121
+ reporter.report({
122
+ message: `Error extracting app manifest: ${getErrorMessage(err)}`,
123
+ status: 'warn'
124
+ });
125
+ }
126
+ // Resolve the installation in both modes so the report β€” dry-run and real β€”
127
+ // shows whether the config is deployable; a missing one fails the deploy here.
128
+ let installationId;
129
+ const configAppType = workbench?.installationConfig?.appType;
130
+ if (deploySingletonInstallationConfig && organizationId && workbench?.installationConfig && configAppType) {
131
+ installationId = await resolveInstallationId({
132
+ appType: configAppType,
133
+ organizationId
134
+ });
135
+ reporter.report(installationId ? {
136
+ message: summarizeInstallationConfig(workbench.installationConfig),
137
+ status: 'pass'
138
+ } : {
139
+ exitCode: exitCodes.USAGE_ERROR,
140
+ message: `No active "${configAppType}" installation for organization "${organizationId}"`,
141
+ solution: 'Install the Media Library for the organization before deploying its config',
142
+ status: 'fail'
143
+ });
144
+ }
145
+ // Dry run stops here β€” everything below mutates.
146
+ if (dryRun) return;
147
+ if (installationId && version && configAppType) {
148
+ await deployInstallationConfig({
149
+ appType: configAppType,
150
+ installationId,
151
+ output,
152
+ sourceDir,
153
+ version
154
+ });
155
+ }
156
+ // A config-only singleton ships no application, only its installation config.
157
+ if (!deployApplication) {
158
+ if (installationId && version) {
159
+ return {
160
+ applicationType: 'coreApp',
161
+ applicationVersion: version,
162
+ installationId,
163
+ target: null
164
+ };
124
165
  }
125
- // Sync app title from manifest when it has changed (Brett user-applications)
126
- if (manifest?.title !== undefined && manifest.title !== userApplication.title) {
127
- deployDebug('Updating application title from manifest', {
128
- from: userApplication.title,
129
- to: manifest.title
130
- });
131
- const existing = userApplication.title;
132
- output.log(existing ? `Updating title from "${existing}" to "${manifest.title}"` : `Setting application title to "${manifest.title}"`);
133
- spin = spinner(`Updating application title`).start();
134
- try {
135
- userApplication = await updateUserApplication({
136
- applicationId: userApplication.id,
137
- appType: 'coreApp',
138
- body: {
139
- title: manifest.title
140
- }
141
- });
142
- spin.succeed();
143
- } catch (err) {
144
- spin.fail();
145
- const message = getErrorMessage(err);
146
- deployDebug('Error updating application title', {
147
- message
148
- });
149
- output.warn(`Error updating application title: ${message}`);
150
- }
166
+ return;
167
+ }
168
+ // A real deploy has already exited if anything failed; landing here without a
169
+ // resolved application or version means the deploy target was never resolved.
170
+ if (!application || !version) return;
171
+ application = await syncApplicationTitle({
172
+ application,
173
+ manifest,
174
+ output
175
+ });
176
+ await shipAppDeployment({
177
+ application,
178
+ isAutoUpdating,
179
+ manifest,
180
+ sourceDir,
181
+ version
182
+ });
183
+ logAppDeployed({
184
+ application,
185
+ cliConfig,
186
+ output
187
+ });
188
+ return {
189
+ applicationType: 'coreApp',
190
+ applicationVersion: version,
191
+ target: {
192
+ applicationId: application.id,
193
+ title: application.title ?? null,
194
+ url: getCoreAppUrl(application.organizationId, application.id)
151
195
  }
152
- // Register the app's declared views with the application service. That
153
- // service doesn't exist yet, so validate the payload and log it (no store);
154
- // a malformed view declaration fails the deploy before we ship the bundle.
155
- // `views` lives on the branded `unstable_defineApp` result, not the legacy
156
- // `app` config object.
157
- const declaredViews = workbench?.views ?? [];
158
- if (declaredViews.length > 0) {
159
- try {
160
- const payload = buildViewDeploymentPayload({
161
- applicationId: userApplication.id,
162
- views: declaredViews
163
- });
164
- output.log(`Validated ${payload.views.length} view(s) for the application service (not yet persisted):`);
165
- output.log(JSON.stringify(payload, null, 2));
166
- deployDebug('View deployment payload', payload);
167
- } catch (err) {
168
- const message = getErrorMessage(err);
169
- output.error(`Invalid view declaration: ${message}`, {
170
- exit: 1
171
- });
172
- return;
196
+ };
197
+ }
198
+ /**
199
+ * Finds the application a real deploy targets, creating one when none is
200
+ * configured. A dry run resolves and reports the target read-only instead.
201
+ */ async function resolveAppApplication(options, { dryRun, reporter }) {
202
+ const { cliConfig, flags, output } = options;
203
+ const organizationId = cliConfig.app?.organizationId ?? '';
204
+ // Create name from --title or `app.title` config; blank falls back to the prompt
205
+ const title = flags.title?.trim() || cliConfig.app?.title?.trim() || undefined;
206
+ if (dryRun) {
207
+ await checkAppTarget(reporter, {
208
+ appId: getAppId(cliConfig),
209
+ organizationId,
210
+ title
211
+ });
212
+ return null;
213
+ }
214
+ let application = await findUserApplication({
215
+ cliConfig,
216
+ organizationId,
217
+ output,
218
+ title,
219
+ unattended: !!flags.yes
220
+ });
221
+ deployDebug('User application found', application);
222
+ if (!application) {
223
+ deployDebug('No user application found. Creating a new one');
224
+ application = await createUserApplication(organizationId, title);
225
+ deployDebug('User application created', application);
226
+ }
227
+ return application;
228
+ }
229
+ /** Syncs the application title from the manifest when it has changed. */ async function syncApplicationTitle({ application, manifest, output }) {
230
+ const titleUpdate = resolveTitleUpdate(manifest, application);
231
+ if (!titleUpdate) return application;
232
+ deployDebug('Updating application title from manifest', titleUpdate);
233
+ output.log(titleUpdate.from ? `Updating title from "${titleUpdate.from}" to "${titleUpdate.to}"` : `Setting application title to "${titleUpdate.to}"`);
234
+ const spin = spinner('Updating application title').start();
235
+ try {
236
+ const updated = await updateUserApplication({
237
+ applicationId: application.id,
238
+ appType: 'coreApp',
239
+ body: {
240
+ title: titleUpdate.to
173
241
  }
174
- }
175
- spin = spinner('Deploying...').start();
242
+ });
243
+ spin.succeed();
244
+ return updated;
245
+ } catch (err) {
246
+ spin.fail();
247
+ const message = getErrorMessage(err);
248
+ deployDebug('Error updating application title', {
249
+ message
250
+ });
251
+ output.warn(`Error updating application title: ${message}`);
252
+ return application;
253
+ }
254
+ }
255
+ async function shipAppDeployment({ application, isAutoUpdating, manifest, sourceDir, version }) {
256
+ const tarball = pack(dirname(sourceDir), {
257
+ entries: [
258
+ basename(sourceDir)
259
+ ]
260
+ }).pipe(createGzip());
261
+ const spin = spinner('Deploying...').start();
262
+ try {
176
263
  await createDeployment({
177
- applicationId: userApplication.id,
264
+ applicationId: application.id,
178
265
  isApp: true,
179
266
  isAutoUpdating,
180
267
  manifest,
181
268
  tarball,
182
- version: installedSdkVersion
269
+ version
183
270
  });
184
- spin.succeed();
185
- // And let the user know we're done
186
- output.log(`\nπŸš€ ${styleText('bold', 'Success!')} Application deployed`);
187
- if (!appId) {
188
- output.log(`\n════ ${styleText('bold', 'Next step:')} ════`);
189
- output.log(styleText('bold', '\nAdd the deployment.appId to your sanity.cli.js or sanity.cli.ts file:'));
190
- output.log(`
271
+ } catch (error) {
272
+ spin.clear();
273
+ throw error;
274
+ }
275
+ spin.succeed();
276
+ }
277
+ export function logAppDeployed({ application, cliConfig, output }) {
278
+ const url = getCoreAppUrl(application.organizationId, application.id);
279
+ const named = application.title ? ` β€” "${application.title}"` : '';
280
+ output.log(`\nSuccess! Application deployed to ${styleText('cyan', url)}${named}`);
281
+ if (getAppId(cliConfig)) return;
282
+ output.log(`\n════ ${styleText('bold', 'Next step:')} ════`);
283
+ output.log(styleText('bold', '\nAdd the deployment.appId to your sanity.cli.js or sanity.cli.ts file:'));
284
+ output.log(`
191
285
  ${styleText('dim', `app: {
192
286
  // your application config here…
193
287
  }`)},
194
288
  ${styleText([
195
- 'bold',
196
- 'green'
197
- ], `deployment: {
198
- appId: '${userApplication.id}',
289
+ 'bold',
290
+ 'green'
291
+ ], `deployment: {
292
+ appId: '${application.id}',
199
293
  }\n`)}`);
200
- }
201
- } catch (error) {
202
- spin.clear();
203
- // Don't throw generic error if user cancels
204
- if (error.name === 'ExitPromptError') {
205
- output.error('Deployment cancelled by user', {
206
- exit: 1
207
- });
208
- return;
209
- }
210
- // If the error is a CLIError, we can just output the message & error options (if any), while ensuring we exit
211
- if (error instanceof CLIError) {
212
- const { message, ...errorOptions } = error;
213
- output.error(message, {
214
- ...errorOptions,
215
- exit: 1
216
- });
217
- return;
218
- }
219
- deployDebug('Error deploying application', error);
220
- output.error(`Error deploying application: ${error}`, {
221
- exit: 1
222
- });
223
- }
224
294
  }
225
295
 
226
296
  //# sourceMappingURL=deployApp.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/deploy/deployApp.ts"],"sourcesContent":["import {basename, dirname} from 'node:path'\nimport {styleText} from 'node:util'\nimport {createGzip} from 'node:zlib'\n\nimport {CLIError} from '@oclif/core/errors'\nimport {exitCodes, getLocalPackageVersion} from '@sanity/cli-core'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {getWorkbench} from '@sanity/workbench-cli/deploy'\nimport {pack} from 'tar-fs'\n\nimport {createDeployment, updateUserApplication} from '../../services/userApplications.js'\nimport {getAppId} from '../../util/appId.js'\nimport {NO_ORGANIZATION_ID} from '../../util/errorMessages.js'\nimport {getErrorMessage} from '../../util/getErrorMessage.js'\nimport {buildApp} from '../build/buildApp.js'\nimport {shouldAutoUpdate} from '../build/shouldAutoUpdate.js'\nimport {extractCoreAppManifest} from '../manifest/extractCoreAppManifest.js'\nimport {type CoreAppManifest} from '../manifest/types.js'\nimport {checkDir} from './checkDir.js'\nimport {createUserApplicationForApp} from './createUserApplicationForApp.js'\nimport {deployDebug} from './deployDebug.js'\nimport {findUserApplicationForApp} from './findUserApplicationForApp.js'\nimport {type DeployAppOptions} from './types.js'\nimport {buildViewDeploymentPayload} from './viewDeployment.js'\n\n/**\n * Deploy a Sanity application.\n *\n * @internal\n */\nexport async function deployApp(options: DeployAppOptions) {\n const {cliConfig, flags, output, projectRoot, sourceDir} = options\n const workbench = getWorkbench(cliConfig)\n\n const workDir = projectRoot.directory\n\n const organizationId = cliConfig.app?.organizationId\n const appId = getAppId(cliConfig)\n const isAutoUpdating = shouldAutoUpdate({cliConfig, flags, output})\n const installedSdkVersion = await getLocalPackageVersion('@sanity/sdk-react', workDir)\n\n if (!installedSdkVersion) {\n output.error(`Failed to find installed @sanity/sdk-react version`, {exit: 1})\n return\n }\n\n if (!organizationId) {\n output.error(NO_ORGANIZATION_ID, {exit: 1})\n return\n }\n\n if (flags.external) {\n output.error('Deploying an app to an external host is not supported.', {exit: 1})\n }\n\n // Fail before any prompts or API calls when the app declares nothing to\n // expose.\n if (workbench) {\n try {\n workbench.assertDeployable()\n } catch (err) {\n output.error(getErrorMessage(err), {exit: exitCodes.USAGE_ERROR})\n return\n }\n }\n\n let spin = spinner('Verifying local content...')\n\n try {\n let userApplication = await findUserApplicationForApp({\n cliConfig,\n organizationId,\n output,\n })\n\n deployDebug(`User application found`, userApplication)\n\n if (!userApplication) {\n deployDebug(`No user application found. Creating a new one`)\n\n userApplication = await createUserApplicationForApp(organizationId)\n deployDebug(`User application created`, userApplication)\n }\n\n // Always build the project, unless --no-build is passed\n const shouldBuild = flags.build\n if (shouldBuild) {\n deployDebug(`Building app`)\n await buildApp({\n autoUpdatesEnabled: isAutoUpdating,\n calledFromDeploy: true,\n cliConfig,\n flags,\n outDir: sourceDir,\n output,\n workDir,\n })\n }\n\n // Ensure that the directory exists, is a directory and seems to have valid content\n spin = spin.start()\n try {\n await (workbench ? workbench.checkBuiltOutput(sourceDir) : checkDir(sourceDir))\n spin.succeed()\n } catch (err) {\n spin.fail()\n deployDebug('Error checking directory', err)\n output.error(getErrorMessage(err), {exit: 1})\n return\n }\n\n // Create a tarball of the given directory\n const parentDir = dirname(sourceDir)\n const base = basename(sourceDir)\n const tarball = pack(parentDir, {entries: [base]}).pipe(createGzip())\n let manifest: CoreAppManifest | undefined\n try {\n manifest = await extractCoreAppManifest({workDir})\n } catch (err) {\n deployDebug('Error extracting app manifest', err)\n const message = getErrorMessage(err)\n // manifests aren't strictly essential, so continue deploy\n output.warn(`Error extracting app manifest: ${message}`)\n }\n\n // Sync app title from manifest when it has changed (Brett user-applications)\n if (manifest?.title !== undefined && manifest.title !== userApplication.title) {\n deployDebug('Updating application title from manifest', {\n from: userApplication.title,\n to: manifest.title,\n })\n const existing = userApplication.title\n output.log(\n existing\n ? `Updating title from \"${existing}\" to \"${manifest.title}\"`\n : `Setting application title to \"${manifest.title}\"`,\n )\n spin = spinner(`Updating application title`).start()\n try {\n userApplication = await updateUserApplication({\n applicationId: userApplication.id,\n appType: 'coreApp',\n body: {title: manifest.title},\n })\n spin.succeed()\n } catch (err) {\n spin.fail()\n const message = getErrorMessage(err)\n deployDebug('Error updating application title', {message})\n output.warn(`Error updating application title: ${message}`)\n }\n }\n\n // Register the app's declared views with the application service. That\n // service doesn't exist yet, so validate the payload and log it (no store);\n // a malformed view declaration fails the deploy before we ship the bundle.\n // `views` lives on the branded `unstable_defineApp` result, not the legacy\n // `app` config object.\n const declaredViews = workbench?.views ?? []\n if (declaredViews.length > 0) {\n try {\n const payload = buildViewDeploymentPayload({\n applicationId: userApplication.id,\n views: declaredViews,\n })\n output.log(\n `Validated ${payload.views.length} view(s) for the application service (not yet persisted):`,\n )\n output.log(JSON.stringify(payload, null, 2))\n deployDebug('View deployment payload', payload)\n } catch (err) {\n const message = getErrorMessage(err)\n output.error(`Invalid view declaration: ${message}`, {exit: 1})\n return\n }\n }\n\n spin = spinner('Deploying...').start()\n await createDeployment({\n applicationId: userApplication.id,\n isApp: true,\n isAutoUpdating,\n manifest,\n tarball,\n version: installedSdkVersion,\n })\n\n spin.succeed()\n\n // And let the user know we're done\n output.log(`\\nπŸš€ ${styleText('bold', 'Success!')} Application deployed`)\n\n if (!appId) {\n output.log(`\\n════ ${styleText('bold', 'Next step:')} ════`)\n output.log(\n styleText(\n 'bold',\n '\\nAdd the deployment.appId to your sanity.cli.js or sanity.cli.ts file:',\n ),\n )\n output.log(`\n${styleText(\n 'dim',\n `app: {\n // your application config here…\n}`,\n)},\n${styleText(\n ['bold', 'green'],\n `deployment: {\n appId: '${userApplication.id}',\n}\\n`,\n)}`)\n }\n } catch (error) {\n spin.clear()\n // Don't throw generic error if user cancels\n if (error.name === 'ExitPromptError') {\n output.error('Deployment cancelled by user', {exit: 1})\n return\n }\n // If the error is a CLIError, we can just output the message & error options (if any), while ensuring we exit\n if (error instanceof CLIError) {\n const {message, ...errorOptions} = error\n output.error(message, {...errorOptions, exit: 1})\n return\n }\n\n deployDebug('Error deploying application', error)\n output.error(`Error deploying application: ${error}`, {exit: 1})\n }\n}\n"],"names":["basename","dirname","styleText","createGzip","CLIError","exitCodes","getLocalPackageVersion","spinner","getWorkbench","pack","createDeployment","updateUserApplication","getAppId","NO_ORGANIZATION_ID","getErrorMessage","buildApp","shouldAutoUpdate","extractCoreAppManifest","checkDir","createUserApplicationForApp","deployDebug","findUserApplicationForApp","buildViewDeploymentPayload","deployApp","options","cliConfig","flags","output","projectRoot","sourceDir","workbench","workDir","directory","organizationId","app","appId","isAutoUpdating","installedSdkVersion","error","exit","external","assertDeployable","err","USAGE_ERROR","spin","userApplication","shouldBuild","build","autoUpdatesEnabled","calledFromDeploy","outDir","start","checkBuiltOutput","succeed","fail","parentDir","base","tarball","entries","pipe","manifest","message","warn","title","undefined","from","to","existing","log","applicationId","id","appType","body","declaredViews","views","length","payload","JSON","stringify","isApp","version","clear","name","errorOptions"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,QAAO,YAAW;AAC3C,SAAQC,SAAS,QAAO,YAAW;AACnC,SAAQC,UAAU,QAAO,YAAW;AAEpC,SAAQC,QAAQ,QAAO,qBAAoB;AAC3C,SAAQC,SAAS,EAAEC,sBAAsB,QAAO,mBAAkB;AAClE,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,YAAY,QAAO,+BAA8B;AACzD,SAAQC,IAAI,QAAO,SAAQ;AAE3B,SAAQC,gBAAgB,EAAEC,qBAAqB,QAAO,qCAAoC;AAC1F,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,kBAAkB,QAAO,8BAA6B;AAC9D,SAAQC,eAAe,QAAO,gCAA+B;AAC7D,SAAQC,QAAQ,QAAO,uBAAsB;AAC7C,SAAQC,gBAAgB,QAAO,+BAA8B;AAC7D,SAAQC,sBAAsB,QAAO,wCAAuC;AAE5E,SAAQC,QAAQ,QAAO,gBAAe;AACtC,SAAQC,2BAA2B,QAAO,mCAAkC;AAC5E,SAAQC,WAAW,QAAO,mBAAkB;AAC5C,SAAQC,yBAAyB,QAAO,iCAAgC;AAExE,SAAQC,0BAA0B,QAAO,sBAAqB;AAE9D;;;;CAIC,GACD,OAAO,eAAeC,UAAUC,OAAyB;IACvD,MAAM,EAACC,SAAS,EAAEC,KAAK,EAAEC,MAAM,EAAEC,WAAW,EAAEC,SAAS,EAAC,GAAGL;IAC3D,MAAMM,YAAYtB,aAAaiB;IAE/B,MAAMM,UAAUH,YAAYI,SAAS;IAErC,MAAMC,iBAAiBR,UAAUS,GAAG,EAAED;IACtC,MAAME,QAAQvB,SAASa;IACvB,MAAMW,iBAAiBpB,iBAAiB;QAACS;QAAWC;QAAOC;IAAM;IACjE,M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E2C,gBAAgByB,EAAE,CAAC;GAC5B,CAAC,GACD;QACC;IACF,EAAE,OAAOhC,OAAO;QACdM,KAAKqC,KAAK;QACV,4CAA4C;QAC5C,IAAI3C,MAAM4C,IAAI,KAAK,mBAAmB;YACpCvD,OAAOW,KAAK,CAAC,gCAAgC;gBAACC,MAAM;YAAC;YACrD;QACF;QACA,8GAA8G;QAC9G,IAAID,iBAAiBlC,UAAU;YAC7B,MAAM,EAACyD,OAAO,EAAE,GAAGsB,cAAa,GAAG7C;YACnCX,OAAOW,KAAK,CAACuB,SAAS;gBAAC,GAAGsB,YAAY;gBAAE5C,MAAM;YAAC;YAC/C;QACF;QAEAnB,YAAY,+BAA+BkB;QAC3CX,OAAOW,KAAK,CAAC,CAAC,6BAA6B,EAAEA,OAAO,EAAE;YAACC,MAAM;QAAC;IAChE;AACF"}
1
+ {"version":3,"sources":["../../../src/actions/deploy/deployApp.ts"],"sourcesContent":["import {basename, dirname} from 'node:path'\nimport {styleText} from 'node:util'\nimport {createGzip} from 'node:zlib'\n\nimport {exitCodes} from '@sanity/cli-core'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {\n deployInstallationConfig,\n getWorkbench,\n resolveInstallationId,\n summarizeInstallationConfig,\n} from '@sanity/workbench-cli/deploy'\nimport {pack} from 'tar-fs'\n\nimport {\n createDeployment,\n updateUserApplication,\n type UserApplication,\n type UserApplicationResolved,\n} from '../../services/userApplications.js'\nimport {getAppId} from '../../util/appId.js'\nimport {EXTERNAL_APP_NOT_SUPPORTED, NO_ORGANIZATION_ID} from '../../util/errorMessages.js'\nimport {getErrorMessage} from '../../util/getErrorMessage.js'\nimport {buildApp} from '../build/buildApp.js'\nimport {extractCoreAppManifest, resolveTitleUpdate} from '../manifest/extractCoreAppManifest.js'\nimport {type CoreAppManifest} from '../manifest/types.js'\nimport {createUserApplication} from './createUserApplication.js'\nimport {\n checkAppId,\n checkAppTarget,\n checkAutoUpdates,\n checkBuild,\n checkPackageVersion,\n type CheckReporter,\n verifyOutputDir,\n} from './deployChecks.js'\nimport {deployDebug} from './deployDebug.js'\nimport {listDeploymentFiles} from './deploymentPlan.js'\nimport {type DeployResult, runDeploy} from './deployRunner.js'\nimport {findUserApplication} from './findUserApplication.js'\nimport {type DeployAppOptions} from './types.js'\nimport {getCoreAppUrl} from './urlUtils.js'\n\nconst APP_PACKAGE = '@sanity/sdk-react'\n\nexport function deployApp(options: DeployAppOptions): Promise<void> {\n return runDeploy(options, {\n listFiles: ({projectRoot, sourceDir}) => listDeploymentFiles(sourceDir, projectRoot.directory),\n run: runAppDeployment,\n type: 'coreApp',\n })\n}\n\n/** Validates the deploy, syncs the title from the manifest, and ships the build. */\nasync function runAppDeployment(\n options: DeployAppOptions,\n reporter: CheckReporter,\n): Promise<DeployResult | void> {\n const {cliConfig, flags, output, sourceDir} = options\n const workDir = options.projectRoot.directory\n const organizationId = cliConfig.app?.organizationId\n const workbench = getWorkbench(cliConfig)\n const dryRun = !!flags['dry-run']\n\n // A singleton (the Media Library) persists its config instead of hosting an\n // application; anything with interfaces still ships one.\n const deploySingletonInstallationConfig = workbench?.deploySingletonInstallationConfig ?? false\n const deployApplication = !workbench || workbench.hasInterfaces\n\n // A federated app with no entry, view or service would ship a remote with\n // nothing to load β€” reported first so it fails before any prompt or API call.\n if (workbench) {\n try {\n workbench.assertDeployable()\n } catch (err) {\n reporter.report({\n exitCode: exitCodes.USAGE_ERROR,\n message: getErrorMessage(err),\n solution: 'Declare at least one entry, view, or service in the app',\n status: 'fail',\n })\n }\n }\n\n const isAutoUpdating = checkAutoUpdates(reporter, {cliConfig, flags})\n\n // An application ships the SDK runtime; a media-library config stamps its\n // `sanity` version instead.\n let version: string | null = null\n if (deployApplication) {\n version = await checkPackageVersion(reporter, {moduleName: APP_PACKAGE, workDir})\n } else if (deploySingletonInstallationConfig) {\n version = await checkPackageVersion(reporter, {moduleName: 'sanity', workDir})\n }\n\n reporter.report(\n organizationId\n ? {message: `Organization: ${organizationId}`, status: 'pass'}\n : {\n message: NO_ORGANIZATION_ID,\n solution: 'Add `app.organizationId` to sanity.cli.ts',\n status: 'fail',\n },\n )\n\n checkAppId(reporter, {cliConfig})\n\n let application: UserApplicationResolved | null = null\n if (flags.external) {\n reporter.report({\n message: EXTERNAL_APP_NOT_SUPPORTED,\n solution: 'Remove the --external flag β€” apps deploy to Sanity hosting',\n status: 'fail',\n })\n } else if (deployApplication) {\n application = await resolveAppApplication(options, {dryRun, reporter})\n }\n\n await checkBuild(reporter, {\n build: () =>\n buildApp({\n autoUpdatesEnabled: isAutoUpdating,\n calledFromDeploy: true,\n cliConfig,\n flags,\n outDir: sourceDir,\n output,\n workDir,\n }),\n skipReason: flags.build\n ? undefined\n : 'Build skipped (--no-build) β€” validating existing output directory',\n successMessage: 'App built',\n })\n\n await verifyOutputDir({isWorkbenchApp: workbench !== null, reporter, sourceDir})\n\n // Manifests aren't strictly essential, so a failure warns and continues\n let manifest: CoreAppManifest | undefined\n try {\n manifest = await extractCoreAppManifest({workDir})\n } catch (err) {\n deployDebug('Error extracting app manifest', err)\n reporter.report({\n message: `Error extracting app manifest: ${getErrorMessage(err)}`,\n status: 'warn',\n })\n }\n\n // Resolve the installation in both modes so the report β€” dry-run and real β€”\n // shows whether the config is deployable; a missing one fails the deploy here.\n let installationId: string | undefined\n const configAppType = workbench?.installationConfig?.appType\n if (\n deploySingletonInstallationConfig &&\n organizationId &&\n workbench?.installationConfig &&\n configAppType\n ) {\n installationId = await resolveInstallationId({appType: configAppType, organizationId})\n reporter.report(\n installationId\n ? {message: summarizeInstallationConfig(workbench.installationConfig), status: 'pass'}\n : {\n exitCode: exitCodes.USAGE_ERROR,\n message: `No active \"${configAppType}\" installation for organization \"${organizationId}\"`,\n solution: 'Install the Media Library for the organization before deploying its config',\n status: 'fail',\n },\n )\n }\n\n // Dry run stops here β€” everything below mutates.\n if (dryRun) return\n\n if (installationId && version && configAppType) {\n await deployInstallationConfig({\n appType: configAppType,\n installationId,\n output,\n sourceDir,\n version,\n })\n }\n\n // A config-only singleton ships no application, only its installation config.\n if (!deployApplication) {\n if (installationId && version) {\n return {applicationType: 'coreApp', applicationVersion: version, installationId, target: null}\n }\n return\n }\n\n // A real deploy has already exited if anything failed; landing here without a\n // resolved application or version means the deploy target was never resolved.\n if (!application || !version) return\n\n application = await syncApplicationTitle({application, manifest, output})\n\n await shipAppDeployment({application, isAutoUpdating, manifest, sourceDir, version})\n\n logAppDeployed({application, cliConfig, output})\n\n return {\n applicationType: 'coreApp',\n applicationVersion: version,\n target: {\n applicationId: application.id,\n title: application.title ?? null,\n url: getCoreAppUrl(application.organizationId, application.id),\n },\n }\n}\n\n/**\n * Finds the application a real deploy targets, creating one when none is\n * configured. A dry run resolves and reports the target read-only instead.\n */\nasync function resolveAppApplication(\n options: DeployAppOptions,\n {dryRun, reporter}: {dryRun: boolean; reporter: CheckReporter},\n): Promise<UserApplicationResolved | null> {\n const {cliConfig, flags, output} = options\n const organizationId = cliConfig.app?.organizationId ?? ''\n // Create name from --title or `app.title` config; blank falls back to the prompt\n const title = flags.title?.trim() || cliConfig.app?.title?.trim() || undefined\n\n if (dryRun) {\n await checkAppTarget(reporter, {appId: getAppId(cliConfig), organizationId, title})\n return null\n }\n\n let application = await findUserApplication({\n cliConfig,\n organizationId,\n output,\n title,\n unattended: !!flags.yes,\n })\n deployDebug('User application found', application)\n\n if (!application) {\n deployDebug('No user application found. Creating a new one')\n application = await createUserApplication(organizationId, title)\n deployDebug('User application created', application)\n }\n\n return application\n}\n\n/** Syncs the application title from the manifest when it has changed. */\nasync function syncApplicationTitle({\n application,\n manifest,\n output,\n}: {\n application: UserApplicationResolved\n manifest: CoreAppManifest | undefined\n output: DeployAppOptions['output']\n}): Promise<UserApplicationResolved> {\n const titleUpdate = resolveTitleUpdate(manifest, application)\n if (!titleUpdate) return application\n\n deployDebug('Updating application title from manifest', titleUpdate)\n output.log(\n titleUpdate.from\n ? `Updating title from \"${titleUpdate.from}\" to \"${titleUpdate.to}\"`\n : `Setting application title to \"${titleUpdate.to}\"`,\n )\n const spin = spinner('Updating application title').start()\n try {\n const updated = await updateUserApplication({\n applicationId: application.id,\n appType: 'coreApp',\n body: {title: titleUpdate.to},\n })\n spin.succeed()\n return updated\n } catch (err) {\n spin.fail()\n const message = getErrorMessage(err)\n deployDebug('Error updating application title', {message})\n output.warn(`Error updating application title: ${message}`)\n return application\n }\n}\n\nasync function shipAppDeployment({\n application,\n isAutoUpdating,\n manifest,\n sourceDir,\n version,\n}: {\n application: UserApplication\n isAutoUpdating: boolean\n manifest: CoreAppManifest | undefined\n sourceDir: string\n version: string\n}): Promise<void> {\n const tarball = pack(dirname(sourceDir), {entries: [basename(sourceDir)]}).pipe(createGzip())\n\n const spin = spinner('Deploying...').start()\n try {\n await createDeployment({\n applicationId: application.id,\n isApp: true,\n isAutoUpdating,\n manifest,\n tarball,\n version,\n })\n } catch (error) {\n spin.clear()\n throw error\n }\n spin.succeed()\n}\n\nexport function logAppDeployed({\n application,\n cliConfig,\n output,\n}: {\n application: UserApplicationResolved\n cliConfig: DeployAppOptions['cliConfig']\n output: DeployAppOptions['output']\n}): void {\n const url = getCoreAppUrl(application.organizationId, application.id)\n const named = application.title ? ` β€” \"${application.title}\"` : ''\n output.log(`\\nSuccess! Application deployed to ${styleText('cyan', url)}${named}`)\n\n if (getAppId(cliConfig)) return\n\n output.log(`\\n════ ${styleText('bold', 'Next step:')} ════`)\n output.log(\n styleText('bold', '\\nAdd the deployment.appId to your sanity.cli.js or sanity.cli.ts file:'),\n )\n output.log(`\n${styleText(\n 'dim',\n `app: {\n // your application config here…\n}`,\n)},\n${styleText(\n ['bold', 'green'],\n `deployment: {\n appId: '${application.id}',\n}\\n`,\n)}`)\n}\n"],"names":["basename","dirname","styleText","createGzip","exitCodes","spinner","deployInstallationConfig","getWorkbench","resolveInstallationId","summarizeInstallationConfig","pack","createDeployment","updateUserApplication","getAppId","EXTERNAL_APP_NOT_SUPPORTED","NO_ORGANIZATION_ID","getErrorMessage","buildApp","extractCoreAppManifest","resolveTitleUpdate","createUserApplication","checkAppId","checkAppTarget","checkAutoUpdates","checkBuild","checkPackageVersion","verifyOutputDir","deployDebug","listDeploymentFiles","runDeploy","findUserApplication","getCoreAppUrl","APP_PACKAGE","deployApp","options","listFiles","projectRoot","sourceDir","directory","run","runAppDeployment","type","reporter","cliConfig","flags","output","workDir","organizationId","app","workbench","dryRun","deploySingletonInstallationConfig","deployApplication","hasInterfaces","assertDeployable","err","report","exitCode","USAGE_ERROR","message","solution","status","isAutoUpdating","version","moduleName","application","external","resolveAppApplication","build","autoUpdatesEnabled","calledFromDeploy","outDir","skipReason","undefined","successMessage","isWorkbenchApp","manifest","installationId","configAppType","installationConfig","appType","applicationType","applicationVersion","target","syncApplicationTitle","shipAppDeployment","logAppDeployed","applicationId","id","title","url","trim","appId","unattended","yes","titleUpdate","log","from","to","spin","start","updated","body","succeed","fail","warn","tarball","entries","pipe","isApp","error","clear","named"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,QAAO,YAAW;AAC3C,SAAQC,SAAS,QAAO,YAAW;AACnC,SAAQC,UAAU,QAAO,YAAW;AAEpC,SAAQC,SAAS,QAAO,mBAAkB;AAC1C,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SACEC,wBAAwB,EACxBC,YAAY,EACZC,qBAAqB,EACrBC,2BAA2B,QACtB,+BAA8B;AACrC,SAAQC,IAAI,QAAO,SAAQ;AAE3B,SACEC,gBAAgB,EAChBC,qBAAqB,QAGhB,qCAAoC;AAC3C,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,0BAA0B,EAAEC,kBAAkB,QAAO,8BAA6B;AAC1F,SAAQC,eAAe,QAAO,gCAA+B;AAC7D,SAAQC,QAAQ,QAAO,uBAAsB;AAC7C,SAAQC,sBAAsB,EAAEC,kBAAkB,QAAO,wCAAuC;AAEhG,SAAQC,qBAAqB,QAAO,6BAA4B;AAChE,SACEC,UAAU,EACVC,cAAc,EACdC,gBAAgB,EAChBC,UAAU,EACV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