@shoplifter/cli 0.1.10 → 0.1.12
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/auth.js +3 -1
- package/dist/release-manifest.json +10 -2
- package/dist/upload-runtime.d.ts +5 -0
- package/dist/upload-runtime.js +19 -0
- package/dist/upload.js +7 -3
- package/package.json +9 -4
package/dist/auth.js
CHANGED
|
@@ -47,7 +47,9 @@ export async function login(channelCode) {
|
|
|
47
47
|
const origin = apiOrigin();
|
|
48
48
|
const grant = await response(await fetch(new URL('/shoplifter-cli/device', origin), { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ scopes: ['read', 'content', 'source'] }), signal: AbortSignal.timeout(15000) }));
|
|
49
49
|
const url = new URL(grant.verificationUri);
|
|
50
|
-
|
|
50
|
+
const loopback = (value) => value.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(value.hostname);
|
|
51
|
+
const localDashboard = loopback(origin) && loopback(url) && url.hostname === origin.hostname;
|
|
52
|
+
if (url.username || url.password || url.origin !== origin.origin && !localDashboard || !/^[A-F0-9]{10}$/.test(grant.userCode))
|
|
51
53
|
throw new Error('Invalid CLI approval response');
|
|
52
54
|
url.searchParams.set('code', grant.userCode);
|
|
53
55
|
if (channelCode)
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
{
|
|
13
13
|
"path": "auth.js",
|
|
14
|
-
"sha256": "
|
|
14
|
+
"sha256": "fb3f72d1f6e9e4df5c3cce6e229647618778b3de38e2ca02eb2a13f041331815"
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
17
|
"path": "author.d.ts",
|
|
@@ -85,13 +85,21 @@
|
|
|
85
85
|
"path": "upload-files.js",
|
|
86
86
|
"sha256": "51c102f2d15498059e930de28797e459d9b39354741976028bca194815dd6616"
|
|
87
87
|
},
|
|
88
|
+
{
|
|
89
|
+
"path": "upload-runtime.d.ts",
|
|
90
|
+
"sha256": "bb4bfa996ac735a97d7e96b972eac98662798b643548a47ac0adbaa4cc4788a6"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"path": "upload-runtime.js",
|
|
94
|
+
"sha256": "603a11ce3b92fbc4cd0021ace5cbe8fb652f2e59be32b64c8fcec51e95085f74"
|
|
95
|
+
},
|
|
88
96
|
{
|
|
89
97
|
"path": "upload.d.ts",
|
|
90
98
|
"sha256": "bc4291e91aed8bd37e72403f3d5059ef9a099dd88fd394ff1b0e96d2975ebb31"
|
|
91
99
|
},
|
|
92
100
|
{
|
|
93
101
|
"path": "upload.js",
|
|
94
|
-
"sha256": "
|
|
102
|
+
"sha256": "218fa344012691d6ed70c5cac89bf652b41393d8c53e73404667cbc88b4f561a"
|
|
95
103
|
}
|
|
96
104
|
],
|
|
97
105
|
"firstPartySources": [],
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
/** Select exactly the project's pinned archives. The server, not this request, grants approval. */
|
|
6
|
+
export async function uploadRuntime(directory) {
|
|
7
|
+
const lock = JSON.parse(await readFile(resolve(directory, 'package-lock.json'), 'utf8'));
|
|
8
|
+
if (lock.lockfileVersion !== 3)
|
|
9
|
+
throw new Error('Run npm install to create a version 3 package lock before uploading');
|
|
10
|
+
const pair = {};
|
|
11
|
+
for (const kind of ['sdk', 'contract']) {
|
|
12
|
+
const bytes = await readFile(resolve(directory, `vendor/${kind}.tgz`));
|
|
13
|
+
const entry = lock.packages?.[`node_modules/@shoplifter/presentation-${kind}`];
|
|
14
|
+
if (entry?.resolved !== `file:vendor/${kind}.tgz` || entry.integrity !== 'sha512-' + createHash('sha512').update(bytes).digest('base64'))
|
|
15
|
+
throw new Error('Pinned runtime and lockfile differ; run shoplifter dependencies sync');
|
|
16
|
+
pair[`${kind}Sha256`] = createHash('sha256').update(bytes).digest('hex');
|
|
17
|
+
}
|
|
18
|
+
return pair;
|
|
19
|
+
}
|
package/dist/upload.js
CHANGED
|
@@ -8,6 +8,7 @@ import { setTimeout as pause } from 'node:timers/promises';
|
|
|
8
8
|
import { readProject } from './files.js';
|
|
9
9
|
import { collectUploadFiles } from './upload-files.js';
|
|
10
10
|
import { packUpload, fileDigest, inventoryDigest } from './upload-archive.js';
|
|
11
|
+
import { uploadRuntime } from './upload-runtime.js';
|
|
11
12
|
const hash = (value) => createHash('sha256').update(value).digest('hex');
|
|
12
13
|
/** Only metadata and immutable archive bytes are checkpointed; capabilities and credentials are never persisted. */
|
|
13
14
|
export async function uploadSource(base, session, channelCode) {
|
|
@@ -60,7 +61,7 @@ export async function uploadSource(base, session, channelCode) {
|
|
|
60
61
|
throw error;
|
|
61
62
|
}
|
|
62
63
|
if (saved && !saved.uploadId) {
|
|
63
|
-
const recovered = await control('POST', '', { archive: saved.archive, requestId: saved.requestId });
|
|
64
|
+
const recovered = await control('POST', '', { archive: saved.archive, requestId: saved.requestId, ...(saved.runtime ? { runtime: saved.runtime } : {}) });
|
|
64
65
|
saved.uploadId = recovered.uploadId;
|
|
65
66
|
await checkpoint(saved);
|
|
66
67
|
}
|
|
@@ -85,6 +86,7 @@ export async function uploadSource(base, session, channelCode) {
|
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
if (!saved) {
|
|
89
|
+
const runtime = await uploadRuntime(directory);
|
|
88
90
|
await rm(archivePath, { force: true });
|
|
89
91
|
console.error(`Preparing ${files.length} source files (${files.reduce((sum, file) => sum + file.size, 0)} bytes)`);
|
|
90
92
|
const archive = { ...await packUpload(directory, archivePath, files), fileCount: files.length, expandedBytes: files.reduce((sum, file) => sum + file.size, 0) };
|
|
@@ -93,9 +95,11 @@ export async function uploadSource(base, session, channelCode) {
|
|
|
93
95
|
await rm(archivePath, { force: true });
|
|
94
96
|
throw new Error('Project changed during packaging; retry upload');
|
|
95
97
|
}
|
|
96
|
-
|
|
98
|
+
if (JSON.stringify(await uploadRuntime(directory)) !== JSON.stringify(runtime))
|
|
99
|
+
throw new Error('Project runtime changed during packaging; retry upload');
|
|
100
|
+
saved = { version: 1, requestId: randomUUID(), channelCode, directory, sourceDigest, archive, runtime };
|
|
97
101
|
await checkpoint(saved);
|
|
98
|
-
state = await control('POST', '', { archive, requestId: saved.requestId });
|
|
102
|
+
state = await control('POST', '', { archive, requestId: saved.requestId, runtime });
|
|
99
103
|
saved.uploadId = state.uploadId;
|
|
100
104
|
await checkpoint(saved);
|
|
101
105
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shoplifter/cli",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"shoplifterRuntimeVersion": "0.3.
|
|
5
|
-
"shoplifterContractVersion": "0.3.
|
|
3
|
+
"version": "0.1.12",
|
|
4
|
+
"shoplifterRuntimeVersion": "0.3.3",
|
|
5
|
+
"shoplifterContractVersion": "0.3.2",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/hentech-dev/ShopLifter.git",
|
|
11
|
+
"directory": "app/shoplifter-cli"
|
|
12
|
+
},
|
|
8
13
|
"description": "Author, validate and publish independent Shoplifter Astro presentations",
|
|
9
14
|
"engines": {
|
|
10
15
|
"node": ">=24 <25"
|
|
@@ -29,7 +34,7 @@
|
|
|
29
34
|
"ignore": "^7.0.14",
|
|
30
35
|
"tar-stream": "3.2.2",
|
|
31
36
|
"reflect-metadata": "^0.1.14",
|
|
32
|
-
"@shoplifter/presentation-contract": "0.3.
|
|
37
|
+
"@shoplifter/presentation-contract": "0.3.2"
|
|
33
38
|
},
|
|
34
39
|
"devDependencies": {
|
|
35
40
|
"@types/node": "^24.19.2",
|