@shoplifter/cli 0.1.13 → 0.1.14

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/files.js CHANGED
@@ -52,7 +52,7 @@ export async function readProject(directory = process.cwd(), sourceImages = true
52
52
  validateMigrations(JSON.parse((await readSourceBytes(resolve(directory, 'migrations.json'))).toString()));
53
53
  const previewEntry = validateAstroConfig((await readSourceBytes(resolve(directory, 'astro.config.mjs'))).toString());
54
54
  const root = await realpath(directory);
55
- for (const path of [...Object.values(project.manifest.components), ...(project.manifest.leads ? [project.manifest.leads.source, ...project.manifest.leads.forms.map(form => form.component)] : []), ...Object.values(project.assets).map(asset => asset.file)]) {
55
+ for (const path of [...Object.values(project.manifest.components), ...(project.manifest.apiRoutes?.map(route => route.handler) ?? []), ...(project.manifest.leads ? [project.manifest.leads.source, ...project.manifest.leads.forms.map(form => form.component)] : []), ...Object.values(project.assets).map(asset => asset.file)]) {
56
56
  const actual = await realpath(resolve(root, path));
57
57
  const local = relative(root, actual);
58
58
  if (local.startsWith('..' + sep) || local === '..' || !projectPath(local.split(sep).join('/')))
package/dist/index.js CHANGED
@@ -70,8 +70,9 @@ program.command('dev').action(async () => {
70
70
  throw new Error('Astro exited with status ' + code);
71
71
  });
72
72
  program.command('publication <action> <channel> [revision] [language]')
73
+ .option('--mode <mode>', 'Publication delivery mode: static or ssr')
73
74
  .option('--reset', 'Reset the channel preview link and revoke existing preview browsers')
74
- .action((action, channel, revision, language, options) => publication(action, channel, revision, language, Boolean(options.reset)));
75
+ .action((action, channel, revision, language, options) => publication(action, channel, revision, language, Boolean(options.reset), options.mode));
75
76
  try {
76
77
  if (process.argv.length === 2)
77
78
  program.outputHelp();
@@ -5,4 +5,4 @@ export declare function previewUpload(directory?: string): Promise<{
5
5
  }[];
6
6
  totalBytes: number;
7
7
  }>;
8
- export declare function publication(action: string, channel: string, revision?: string, languageCode?: string, reset?: boolean): Promise<void>;
8
+ export declare function publication(action: string, channel: string, revision?: string, languageCode?: string, reset?: boolean, mode?: string): Promise<void>;
@@ -2,17 +2,26 @@ import { apiOrigin, credentials, sessionChannel } from './auth.js';
2
2
  import { readProject } from './files.js';
3
3
  import { collectUploadFiles } from './upload-files.js';
4
4
  import { uploadSource } from './upload.js';
5
+ import { setTimeout as pause } from 'node:timers/promises';
5
6
  export async function previewUpload(directory = process.cwd()) {
6
7
  const files = await collectUploadFiles(directory, await readProject(directory, false));
7
8
  const preview = { files: files.map(file => ({ path: file.path, size: file.size })), totalBytes: files.reduce((sum, file) => sum + file.size, 0) };
8
9
  console.log(JSON.stringify(preview, null, 2));
9
10
  return preview;
10
11
  }
11
- export async function publication(action, channel, revision, languageCode, reset = false) {
12
+ export async function publication(action, channel, revision, languageCode, reset = false, mode) {
12
13
  if (!['upload', 'stage', 'preview', 'preview-link', 'build', 'publish', 'status', 'logs', 'retry', 'retry-deployment', 'activate', 'rollback'].includes(action))
13
14
  throw new Error('Unknown publication operation');
14
15
  if (reset && action !== 'preview-link')
15
16
  throw new Error('--reset is only supported for preview-link');
17
+ if (mode !== undefined && mode !== 'static' && mode !== 'ssr')
18
+ throw new Error('Publication mode must be static or ssr');
19
+ if (mode === 'ssr' && !['preview', 'publish'].includes(action))
20
+ throw new Error('Use --mode ssr with preview or publish. Other actions use the saved revision mode.');
21
+ if (mode === 'ssr' && action === 'preview' && revision)
22
+ throw new Error('SSR preview takes no revision; it stages the current project');
23
+ if (mode === 'ssr' && action === 'publish' && !revision)
24
+ throw new Error('SSR publish requires a reviewed candidate ID');
16
25
  const base = apiOrigin(), session = await credentials(false);
17
26
  const channelCode = session ? await sessionChannel(session.token) : channel;
18
27
  if (session && channel !== channelCode && channel !== session.channelId)
@@ -22,7 +31,43 @@ export async function publication(action, channel, revision, languageCode, reset
22
31
  if (!['http:', 'https:'].includes(base.protocol) || base.username || base.password)
23
32
  throw new Error('Invalid API origin');
24
33
  const selector = !session && /^\d+$/.test(channel) ? { channelId: channel } : { channelCode };
25
- const body = { ...selector, revisionId: revision, ...(languageCode ? { languageCode } : {}) };
34
+ async function operationRequest(operation, revisionId) {
35
+ const body = { ...selector, revisionId, ...(languageCode ? { languageCode } : {}) };
36
+ const response = await fetch(new URL(session ? '/shoplifter-cli/operation' : '/shoplifter-development/' + operation, base), {
37
+ method: 'POST',
38
+ headers: { 'content-type': 'application/json', ...(session ? { authorization: 'Bearer ' + session.token } : {}) },
39
+ body: JSON.stringify(session ? { channelCode, languageCode, action: operation, input: body } : body),
40
+ signal: AbortSignal.timeout(120000),
41
+ });
42
+ const result = await response.text();
43
+ if (!response.ok)
44
+ throw new Error('Publication failed (' + response.status + '): ' + result);
45
+ return result;
46
+ }
47
+ if (mode === 'ssr') {
48
+ // Dedicated actions keep a new CLI paired with an old server from running a static mutation.
49
+ const capability = JSON.parse(await operationRequest('ssr-capabilities'));
50
+ if (capability?.protocol !== 1)
51
+ throw new Error('SSR publishing is unavailable for this channel');
52
+ if (action === 'publish') {
53
+ console.log(await operationRequest('ssr-publish', revision));
54
+ return;
55
+ }
56
+ const source = await uploadSource(base, session, channelCode, { quiet: true });
57
+ let preview = JSON.parse(await operationRequest('ssr-preview', source.id));
58
+ const buildId = String(preview?.id ?? '');
59
+ if (!/^\d+$/.test(buildId))
60
+ throw new Error('SSR preview did not return a build ID');
61
+ const deadline = Date.now() + 15 * 60_000;
62
+ while (!['ready', 'failed', 'superseded'].includes(preview.status) && Date.now() < deadline) {
63
+ await pause(2000);
64
+ preview = JSON.parse(await operationRequest('status', buildId));
65
+ }
66
+ if (preview.status !== 'ready')
67
+ throw new Error('SSR preview is ' + preview.status + '. Check publication status for build ' + buildId);
68
+ console.log(await operationRequest('ssr-preview-access', buildId));
69
+ return;
70
+ }
26
71
  if (action === 'upload') {
27
72
  await uploadSource(base, session, channelCode);
28
73
  return;
@@ -32,14 +77,5 @@ export async function publication(action, channel, revision, languageCode, reset
32
77
  if (action === 'preview-link' && !session)
33
78
  throw new Error('Protected preview access requires shoplifter login');
34
79
  const operation = action === 'preview' ? 'preview-candidate' : action === 'build' ? 'build-candidate' : action === 'preview-link' ? reset ? 'preview-reset' : 'preview-access' : action;
35
- const response = await fetch(new URL(session ? '/shoplifter-cli/operation' : '/shoplifter-development/' + operation, base), {
36
- method: 'POST',
37
- headers: { 'content-type': 'application/json', ...(session ? { authorization: 'Bearer ' + session.token } : {}) },
38
- body: JSON.stringify(session ? { channelCode, languageCode, action: operation, input: body } : body),
39
- signal: AbortSignal.timeout(120000),
40
- });
41
- const result = await response.text();
42
- if (!response.ok)
43
- throw new Error(`Publication failed (${response.status}): ${result}`);
44
- console.log(result);
80
+ console.log(await operationRequest(operation, revision));
45
81
  }
@@ -27,7 +27,7 @@
27
27
  },
28
28
  {
29
29
  "path": "files.js",
30
- "sha256": "8c0433d7dd6934b14551e65d1f4090acea7333ae131fe181d7f5547de414cbb0"
30
+ "sha256": "c36b5f6cdd8b8e5aee98d37d861de0c622860df37b718b8aee5fc7e2aaa2a407"
31
31
  },
32
32
  {
33
33
  "path": "index.d.ts",
@@ -35,15 +35,15 @@
35
35
  },
36
36
  {
37
37
  "path": "index.js",
38
- "sha256": "445a9124b79949d791133123c2297a3e2c7a763949a831be45313466ee195f57"
38
+ "sha256": "da940967acebcef85972834d56b8c5c9c6ac43e9f0f3fbcf4f3c3f912b26a8d7"
39
39
  },
40
40
  {
41
41
  "path": "publication.d.ts",
42
- "sha256": "ba1a8c1662a2006954d47431aa80079827c2e2cf3ecf613472df35ed63e5e580"
42
+ "sha256": "d44fcd11e60b5ba2f2e5bb4ff622b865e1a85d5361a47c425313b0123266e083"
43
43
  },
44
44
  {
45
45
  "path": "publication.js",
46
- "sha256": "b68508530ae29ddac9dc039df6d9b9402c5df047d15138a91d691a96ddad97fa"
46
+ "sha256": "33905155dc506009b134b7374ee33df3e27b51a4dc78120899d3cfe8b3cbb42d"
47
47
  },
48
48
  {
49
49
  "path": "runtime.d.ts",
@@ -83,7 +83,7 @@
83
83
  },
84
84
  {
85
85
  "path": "upload-files.js",
86
- "sha256": "0b069a9a062a6bc795e8ed1dd162d01324b3798a82333c1c4284574e9827bf14"
86
+ "sha256": "75f652ae0e39998e75a6e5478b3af66ab4f3a9f450a22165cd4e52f0aaf4f93b"
87
87
  },
88
88
  {
89
89
  "path": "upload-runtime.d.ts",
@@ -95,11 +95,11 @@
95
95
  },
96
96
  {
97
97
  "path": "upload.d.ts",
98
- "sha256": "bc4291e91aed8bd37e72403f3d5059ef9a099dd88fd394ff1b0e96d2975ebb31"
98
+ "sha256": "633d3e9490c85d2f4740eeec12adb1ba6d3ef8f364f544af9109a5914b6d52f9"
99
99
  },
100
100
  {
101
101
  "path": "upload.js",
102
- "sha256": "218fa344012691d6ed70c5cac89bf652b41393d8c53e73404667cbc88b4f561a"
102
+ "sha256": "41c6fcf434aa467345c17bf79936a9f24d235465f30c1c2028bbd79493bd0b94"
103
103
  }
104
104
  ],
105
105
  "firstPartySources": [],
@@ -69,7 +69,8 @@ export async function collectUploadFiles(directory, project) {
69
69
  if (files.length > 2000 || files.reduce((sum, file) => sum + file.size, 0) > 96 * 1024 * 1024)
70
70
  throw new Error('Source bundle exceeds limits');
71
71
  const required = ['shoplifter.json', 'definition.json', 'editor.json', 'data.json', 'assets.json', 'design.json', 'migrations.json', 'package.json', 'astro.config.mjs',
72
- ...Object.values(project.manifest.components), ...Object.values(project.assets).map(asset => asset.file)];
72
+ ...Object.values(project.manifest.components), ...(project.manifest.apiRoutes?.map(route => route.handler) ?? []),
73
+ ...Object.values(project.assets).map(asset => asset.file)];
73
74
  const previewEntry = validateAstroConfig((await readSourceBytes(resolve(directory, 'astro.config.mjs'))).toString());
74
75
  if (previewEntry)
75
76
  required.push(previewEntry);
package/dist/upload.d.ts CHANGED
@@ -5,5 +5,7 @@ type Session = {
5
5
  expiresAt: string;
6
6
  };
7
7
  /** Only metadata and immutable archive bytes are checkpointed; capabilities and credentials are never persisted. */
8
- export declare function uploadSource(base: URL, session: Session | undefined, channelCode: string): Promise<void>;
8
+ export declare function uploadSource(base: URL, session: Session | undefined, channelCode: string, { quiet }?: {
9
+ quiet?: boolean | undefined;
10
+ }): Promise<any>;
9
11
  export {};
package/dist/upload.js CHANGED
@@ -11,7 +11,7 @@ import { packUpload, fileDigest, inventoryDigest } from './upload-archive.js';
11
11
  import { uploadRuntime } from './upload-runtime.js';
12
12
  const hash = (value) => createHash('sha256').update(value).digest('hex');
13
13
  /** Only metadata and immutable archive bytes are checkpointed; capabilities and credentials are never persisted. */
14
- export async function uploadSource(base, session, channelCode) {
14
+ export async function uploadSource(base, session, channelCode, { quiet = false } = {}) {
15
15
  const directory = await realpath(process.cwd()), files = await collectUploadFiles(directory, await readProject(directory, false));
16
16
  const sourceDigest = inventoryDigest(files), config = resolve(process.env.SHOPLIFTER_CONFIG_DIRECTORY ?? resolve(homedir(), '.config/shoplifter'));
17
17
  const root = resolve(config, 'uploads', hash(base.origin), hash(channelCode + '\n' + directory));
@@ -168,7 +168,9 @@ export async function uploadSource(base, session, channelCode) {
168
168
  }
169
169
  if (state.status !== 'ready')
170
170
  throw new Error(state.error || 'Source validation is still pending; rerun upload to resume');
171
- console.log(JSON.stringify(state.source));
171
+ if (!quiet)
172
+ console.log(JSON.stringify(state.source));
172
173
  await rm(filename, { force: true });
173
174
  await rm(archivePath, { force: true });
175
+ return state.source;
174
176
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@shoplifter/cli",
3
- "version": "0.1.13",
4
- "shoplifterRuntimeVersion": "0.3.4",
5
- "shoplifterContractVersion": "0.3.3",
3
+ "version": "0.1.14",
4
+ "shoplifterRuntimeVersion": "0.3.5",
5
+ "shoplifterContractVersion": "0.3.4",
6
6
  "private": false,
7
7
  "license": "Apache-2.0",
8
8
  "repository": {
@@ -34,7 +34,7 @@
34
34
  "ignore": "^7.0.14",
35
35
  "tar-stream": "3.2.2",
36
36
  "reflect-metadata": "^0.1.14",
37
- "@shoplifter/presentation-contract": "0.3.3"
37
+ "@shoplifter/presentation-contract": "0.3.4"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/node": "^24.19.2",