@shoplifter/cli 0.1.7 → 0.1.8

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/README.md CHANGED
@@ -57,6 +57,8 @@ Set `SHOPLIFTER_API_URL=https://<platform-api-host>` before production operation
57
57
  `shoplifter dependencies sync` anonymously downloads the platform-approved public
58
58
  runtime, verifies hashes and explicitly updates local archives and the lockfile.
59
59
  It preserves authored files. Run `npm ci --ignore-scripts` after synchronization.
60
+ For an unpublished local runtime pair, use `shoplifter dependencies sync
61
+ /absolute/path/sdk.tgz /absolute/path/contract.tgz`; both archives are required.
60
62
 
61
63
  `shoplifter login combo-media` opens dashboard approval for that channel code.
62
64
  With `shoplifter login` alone, explicitly choose a channel on the approval page.
package/dist/auth.d.ts CHANGED
@@ -8,4 +8,4 @@ export declare function credentials(required?: boolean): Promise<{
8
8
  export declare function sessionChannel(token: string): Promise<string>;
9
9
  export declare function login(channelCode?: string): Promise<void>;
10
10
  export declare function logout(): Promise<void>;
11
- export declare function syncDependencies(): Promise<void>;
11
+ export declare function syncDependencies(sdkArchive?: string, contractArchive?: string): Promise<void>;
package/dist/auth.js CHANGED
@@ -98,9 +98,13 @@ export async function logout() {
98
98
  }
99
99
  console.log('CLI session removed');
100
100
  }
101
- export async function syncDependencies() {
101
+ export async function syncDependencies(sdkArchive, contractArchive) {
102
102
  await readFile(resolve('shoplifter.json'));
103
- const { sdk, contract } = await downloadRuntime(process.env.SHOPLIFTER_API_URL ? apiOrigin() : undefined);
103
+ if (Boolean(sdkArchive) !== Boolean(contractArchive))
104
+ throw new Error('Provide both local SDK and contract archives');
105
+ const { sdk, contract } = sdkArchive && contractArchive
106
+ ? { sdk: await readFile(resolve(sdkArchive)), contract: await readFile(resolve(contractArchive)) }
107
+ : await downloadRuntime(process.env.SHOPLIFTER_API_URL ? apiOrigin() : undefined);
104
108
  const pkg = JSON.parse(await readFile(resolve('package.json'), 'utf8'));
105
109
  await mkdir(resolve('vendor'), { recursive: true });
106
110
  await writeFile(resolve('vendor/sdk.tgz'), sdk);
package/dist/files.js CHANGED
@@ -2,6 +2,9 @@ import { readFile, writeFile, rename, mkdir, realpath, readdir, lstat } from 'no
2
2
  import { createReadStream } from 'node:fs';
3
3
  import { resolve, relative, sep } from 'node:path';
4
4
  import { randomUUID } from 'node:crypto';
5
+ import { execFile } from 'node:child_process';
6
+ import { promisify } from 'node:util';
7
+ import { pathToFileURL } from 'node:url';
5
8
  import { validateProject, validateMigrations, generateFixtures, generateContentType, generateDataType, projectPath, validateImageMarkup, validateAstroConfig, } from '@shoplifter/presentation-contract';
6
9
  export const projectFiles = {
7
10
  manifest: 'shoplifter.json', definition: 'definition.json', editor: 'editor.json',
@@ -29,11 +32,27 @@ export async function readSourceBytes(path, maximum = 12 * 1024 * 1024) {
29
32
  }
30
33
  export async function readProject(directory = process.cwd(), sourceImages = true) {
31
34
  const entries = await Promise.all(Object.entries(projectFiles).map(async ([key, file]) => [key, JSON.parse((await readSourceBytes(resolve(directory, file))).toString())]));
35
+ const manifest = entries.find(([key]) => key === 'manifest')[1];
36
+ if (manifest.leads?.source) {
37
+ if (!projectPath(manifest.leads.source) || !manifest.leads.source.startsWith('src/') || !manifest.leads.source.endsWith('.ts'))
38
+ throw new Error('Invalid lead source');
39
+ const root = await realpath(directory), source = await realpath(resolve(directory, manifest.leads.source));
40
+ if (!source.startsWith(root + sep))
41
+ throw new Error('Lead source must stay inside the project');
42
+ const script = 'const m = await import(process.argv[1]); console.log(JSON.stringify({defaultFormId:m.defaultFormId,forms:m.leadForms.map(({form,component})=>({component,definition:JSON.parse(JSON.stringify(form))}))}));';
43
+ const { stdout } = await promisify(execFile)(process.execPath, ['--input-type=module', '-e', script, pathToFileURL(source).href], { cwd: root, timeout: 30000, maxBuffer: 256 * 1024 });
44
+ const generated = JSON.parse(stdout);
45
+ const next = { ...manifest, leads: { source: manifest.leads.source, ...generated } };
46
+ validateProject({ ...Object.fromEntries(entries), manifest: next });
47
+ if (JSON.stringify(manifest) !== JSON.stringify(next))
48
+ await writeJson(resolve(directory, 'shoplifter.json'), next);
49
+ entries.find(([key]) => key === 'manifest')[1] = next;
50
+ }
32
51
  const project = validateProject(Object.fromEntries(entries));
33
52
  validateMigrations(JSON.parse((await readSourceBytes(resolve(directory, 'migrations.json'))).toString()));
34
53
  validateAstroConfig((await readSourceBytes(resolve(directory, 'astro.config.mjs'))).toString());
35
54
  const root = await realpath(directory);
36
- for (const path of [...Object.values(project.manifest.components), ...Object.values(project.assets).map(asset => asset.file)]) {
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)]) {
37
56
  const actual = await realpath(resolve(root, path));
38
57
  const local = relative(root, actual);
39
58
  if (local.startsWith('..' + sep) || local === '..' || !projectPath(local.split(sep).join('/')))
package/dist/index.js CHANGED
@@ -32,8 +32,13 @@ let Shoplifter = class Shoplifter {
32
32
  async files() { await previewUpload(); }
33
33
  async login(channelCode) { await reportFailure(() => login(channelCode)); }
34
34
  async logout() { await logout(); }
35
- async dependencies(action) { if (action !== 'sync')
36
- throw new Error('Choose dependencies sync'); await syncDependencies(); }
35
+ async dependencies(action, sdkArchive, contractArchive) {
36
+ await reportFailure(async () => {
37
+ if (action !== 'sync')
38
+ throw new Error('Choose dependencies sync');
39
+ await syncDependencies(sdkArchive, contractArchive);
40
+ });
41
+ }
37
42
  run() {
38
43
  if (process.argv.length === 2)
39
44
  console.log('Commands: login, logout, dependencies, init, scaffold, fields, editor, assets, data, design, migrations, fixtures, dev, validate, types, files, publication');
@@ -95,8 +100,10 @@ __decorate([
95
100
  __decorate([
96
101
  command(),
97
102
  __param(0, requiredArg('action')),
103
+ __param(1, optionalArg('sdk-archive')),
104
+ __param(2, optionalArg('contract-archive')),
98
105
  __metadata("design:type", Function),
99
- __metadata("design:paramtypes", [String]),
106
+ __metadata("design:paramtypes", [String, String, String]),
100
107
  __metadata("design:returntype", Promise)
101
108
  ], Shoplifter.prototype, "dependencies", null);
102
109
  __decorate([
@@ -7,11 +7,11 @@
7
7
  },
8
8
  {
9
9
  "path": "auth.d.ts",
10
- "sha256": "ff98d7cbeca5a9fc2985acf804d18fcfe18e54cdac63a4484367b3e1638d349a"
10
+ "sha256": "19ccc11fadb17406cfa61d830338a58f0da2e51ab050a820ca4c02192bd6e8f9"
11
11
  },
12
12
  {
13
13
  "path": "auth.js",
14
- "sha256": "848d11a0471e0e82cfd759b82b5a927517bcb6ff89b47e12f4b588995bd32077"
14
+ "sha256": "686a9b0e3b7af947422eab83641d6e9cb5ea028b38c8f739b647fd5146769a86"
15
15
  },
16
16
  {
17
17
  "path": "author.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  {
29
29
  "path": "files.js",
30
- "sha256": "7deb659f0cdcbbc82b4e225d930c12627ab5f871c1cf2b24c119d08bc1282d79"
30
+ "sha256": "914bf01a167e644088c71a699f9d623e0f3b06e0d718ca5af7d4347d7ccf0ca7"
31
31
  },
32
32
  {
33
33
  "path": "index.d.ts",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  {
37
37
  "path": "index.js",
38
- "sha256": "a8527790a792a857f9e87d02753af4ca1c4e8bf70c93a33b22f28c35c600839c"
38
+ "sha256": "0cd2884a23ab36b3df6006e079af2bc25f5606408f1dcb00b63f186840c9a77f"
39
39
  },
40
40
  {
41
41
  "path": "publication.d.ts",
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@shoplifter/cli",
3
- "version": "0.1.7",
4
- "shoplifterRuntimeVersion": "0.1.3",
5
- "shoplifterContractVersion": "0.1.2",
3
+ "version": "0.1.8",
4
+ "shoplifterRuntimeVersion": "0.2.0",
5
+ "shoplifterContractVersion": "0.2.0",
6
6
  "private": false,
7
7
  "license": "Apache-2.0",
8
8
  "description": "Author, validate and publish independent Shoplifter Astro presentations",
@@ -29,7 +29,7 @@
29
29
  "ignore": "^7.0.14",
30
30
  "tar-stream": "3.2.2",
31
31
  "reflect-metadata": "^0.1.14",
32
- "@shoplifter/presentation-contract": "0.1.2"
32
+ "@shoplifter/presentation-contract": "0.2.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/node": "^24.19.2",