@replaystage/cli 2.1.0 → 2.1.2
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/commands/admin.js +65 -11
- package/dist/commands/creator-publish.d.ts +5 -0
- package/dist/commands/creator-publish.js +352 -0
- package/dist/commands/creator-scaffold.d.ts +5 -0
- package/dist/commands/creator-scaffold.js +376 -0
- package/dist/commands/creator.d.ts +2 -7
- package/dist/commands/creator.js +38 -668
- package/dist/config.js +21 -9
- package/dist/http.js +35 -15
- package/dist/index.js +4 -6
- package/dist/manifest.d.ts +5 -0
- package/dist/manifest.js +189 -36
- package/dist/validate.d.ts +2 -2
- package/dist/validate.js +93 -29
- package/package.json +2 -2
package/dist/validate.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { readFile, readdir, stat } from 'node:fs/promises';
|
|
1
|
+
import { lstat, readFile, readdir, realpath, stat } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { loadAndValidateManifest } from './manifest.js';
|
|
3
|
+
import { VERSION_RE, loadAndValidateManifest } from './manifest.js';
|
|
4
4
|
import { CliError } from './output.js';
|
|
5
5
|
export const MAX_FILE_BYTES = 25 * 1024 * 1024; // 25 MB
|
|
6
6
|
export const MAX_TOTAL_BYTES = 50 * 1024 * 1024; // 50 MB
|
|
7
7
|
export const MAX_FILE_COUNT = 1000;
|
|
8
8
|
export const MAX_MEDIA_BYTES = 2 * 1024 * 1024; // 2 MB
|
|
9
|
+
const MEDIA_FILENAME_RE = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}\.(?:png|jpg|jpeg|webp|svg)$/;
|
|
9
10
|
const AUTO_SKIP_DIRS = new Set(['.git', 'node_modules', '__MACOSX']);
|
|
10
11
|
const AUTO_SKIP_FILES = new Set(['.DS_Store', 'Thumbs.db']);
|
|
11
12
|
const PROHIBITED_EXTENSIONS = new Set(['.exe', '.dll', '.sh', '.bat', '.cmd', '.msi', '.com', '.scr']);
|
|
@@ -47,56 +48,109 @@ export function guessContentType(filePath) {
|
|
|
47
48
|
function isEnvFile(name) {
|
|
48
49
|
return name === '.env' || name.startsWith('.env.');
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
+
function isPathWithinRoot(targetReal, rootReal) {
|
|
52
|
+
return targetReal === rootReal || targetReal.startsWith(`${rootReal}${path.sep}`);
|
|
53
|
+
}
|
|
54
|
+
async function resolveSafeRegularFile(candidate, allowedRealRoots) {
|
|
51
55
|
try {
|
|
52
|
-
const
|
|
53
|
-
|
|
56
|
+
const linkInfo = await lstat(candidate);
|
|
57
|
+
if (linkInfo.isSymbolicLink()) {
|
|
58
|
+
throw new CliError('SYMLINK_NOT_ALLOWED', `Symlink artwork path is not permitted: ${candidate}`, { details: { path: candidate } });
|
|
59
|
+
}
|
|
60
|
+
if (!linkInfo.isFile())
|
|
61
|
+
return null;
|
|
62
|
+
const realTarget = await realpath(candidate);
|
|
63
|
+
const contained = allowedRealRoots.some(root => isPathWithinRoot(realTarget, root));
|
|
64
|
+
if (!contained) {
|
|
65
|
+
throw new CliError('PATH_ESCAPE_BLOCKED', `Artwork file escapes repository boundary: ${candidate}`, { details: { path: candidate } });
|
|
66
|
+
}
|
|
67
|
+
return { absPath: realTarget, size: linkInfo.size };
|
|
54
68
|
}
|
|
55
|
-
catch {
|
|
56
|
-
|
|
69
|
+
catch (err) {
|
|
70
|
+
if (err instanceof CliError)
|
|
71
|
+
throw err;
|
|
72
|
+
return null;
|
|
57
73
|
}
|
|
58
74
|
}
|
|
59
75
|
export async function discoverMediaFile(slot, artworkUrl, slug, repoDir, distDir) {
|
|
60
|
-
// Expected format: `/media/<slug>/<filename>`
|
|
76
|
+
// Expected format: `/media/<slug>/<filename>` or local repo-relative path (e.g. `public/icon.svg`)
|
|
61
77
|
const expectedPrefix = `/media/${slug}/`;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
78
|
+
const isCanonicalMedia = artworkUrl.startsWith(expectedPrefix);
|
|
79
|
+
let baseFilename = '';
|
|
80
|
+
const directCandidates = [];
|
|
81
|
+
if (isCanonicalMedia) {
|
|
82
|
+
baseFilename = artworkUrl.slice(expectedPrefix.length);
|
|
65
83
|
}
|
|
66
84
|
else if (artworkUrl.startsWith('/')) {
|
|
67
|
-
|
|
85
|
+
const cleanRel = artworkUrl.replace(/^\/+/, '');
|
|
86
|
+
if (cleanRel && !cleanRel.includes('..') && !cleanRel.includes('\\')) {
|
|
87
|
+
directCandidates.push(path.join(repoDir, cleanRel));
|
|
88
|
+
if (distDir)
|
|
89
|
+
directCandidates.push(path.join(distDir, cleanRel));
|
|
90
|
+
}
|
|
91
|
+
baseFilename = path.basename(cleanRel);
|
|
68
92
|
}
|
|
69
93
|
else if (!artworkUrl.startsWith('http://') && !artworkUrl.startsWith('https://')) {
|
|
70
|
-
|
|
94
|
+
const cleanRel = artworkUrl.replace(/^\.\/+/, '');
|
|
95
|
+
if (cleanRel && !cleanRel.includes('..') && !cleanRel.includes('\\')) {
|
|
96
|
+
directCandidates.push(path.join(repoDir, cleanRel));
|
|
97
|
+
if (distDir)
|
|
98
|
+
directCandidates.push(path.join(distDir, cleanRel));
|
|
99
|
+
}
|
|
100
|
+
baseFilename = path.basename(cleanRel);
|
|
71
101
|
}
|
|
72
102
|
else {
|
|
73
103
|
return null;
|
|
74
104
|
}
|
|
75
|
-
if (!
|
|
105
|
+
if (!baseFilename || baseFilename.includes('..') || baseFilename.includes('/') || baseFilename.includes('\\')) {
|
|
76
106
|
return null;
|
|
77
107
|
}
|
|
108
|
+
const allowedRealRoots = [];
|
|
109
|
+
try {
|
|
110
|
+
allowedRealRoots.push(await realpath(repoDir));
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
allowedRealRoots.push(path.resolve(repoDir));
|
|
114
|
+
}
|
|
115
|
+
if (distDir) {
|
|
116
|
+
try {
|
|
117
|
+
allowedRealRoots.push(await realpath(distDir));
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
allowedRealRoots.push(path.resolve(distDir));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
78
123
|
const candidates = [
|
|
79
|
-
|
|
80
|
-
path.join(repoDir, 'media', slug,
|
|
81
|
-
path.join(repoDir, 'media',
|
|
82
|
-
path.join(repoDir, '
|
|
83
|
-
path.join(repoDir,
|
|
124
|
+
...directCandidates,
|
|
125
|
+
path.join(repoDir, 'public', 'media', slug, baseFilename),
|
|
126
|
+
path.join(repoDir, 'media', slug, baseFilename),
|
|
127
|
+
path.join(repoDir, 'media', baseFilename),
|
|
128
|
+
path.join(repoDir, 'public', baseFilename),
|
|
129
|
+
path.join(repoDir, baseFilename),
|
|
84
130
|
...(distDir
|
|
85
|
-
? [path.join(distDir, 'media', slug,
|
|
131
|
+
? [path.join(distDir, 'media', slug, baseFilename), path.join(distDir, baseFilename)]
|
|
86
132
|
: []),
|
|
87
133
|
];
|
|
88
134
|
for (const candidate of candidates) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
135
|
+
const safeFile = await resolveSafeRegularFile(candidate, allowedRealRoots);
|
|
136
|
+
if (safeFile) {
|
|
137
|
+
const ext = path.extname(safeFile.absPath).toLowerCase();
|
|
138
|
+
const normalizedFilename = isCanonicalMedia ? baseFilename : `${slot}${ext}`;
|
|
139
|
+
if (normalizedFilename.includes('..') || !MEDIA_FILENAME_RE.test(normalizedFilename)) {
|
|
140
|
+
throw new CliError('INVALID_MEDIA_FILENAME', `Unsupported artwork filename "${normalizedFilename}". Use .png, .jpg, .jpeg, .webp, or .svg.`, { details: { slot, filename: normalizedFilename } });
|
|
141
|
+
}
|
|
142
|
+
if (safeFile.size === 0) {
|
|
143
|
+
throw new CliError('EMPTY_MEDIA_FILE', `Artwork file "${normalizedFilename}" is empty (0 bytes).`, { details: { slot, filename: normalizedFilename } });
|
|
144
|
+
}
|
|
145
|
+
if (safeFile.size > MAX_MEDIA_BYTES) {
|
|
146
|
+
throw new CliError('MEDIA_TOO_LARGE', `Artwork file "${normalizedFilename}" (${safeFile.size} bytes) exceeds the 2 MB media limit.`, { details: { slot, filename: normalizedFilename, bytes: safeFile.size, maxBytes: MAX_MEDIA_BYTES } });
|
|
93
147
|
}
|
|
94
148
|
return {
|
|
95
149
|
slot,
|
|
96
|
-
filename,
|
|
97
|
-
absPath:
|
|
98
|
-
bytes:
|
|
99
|
-
contentType: guessContentType(
|
|
150
|
+
filename: normalizedFilename,
|
|
151
|
+
absPath: safeFile.absPath,
|
|
152
|
+
bytes: safeFile.size,
|
|
153
|
+
contentType: guessContentType(safeFile.absPath),
|
|
100
154
|
};
|
|
101
155
|
}
|
|
102
156
|
}
|
|
@@ -208,7 +262,17 @@ export async function validateProjectBundle(options) {
|
|
|
208
262
|
else if (!manifest.artwork.cover.startsWith('http://') && !manifest.artwork.cover.startsWith('https://')) {
|
|
209
263
|
warnings.push(`Artwork "cover" (${manifest.artwork.cover}) was not found locally — add public/media/${manifest.slug}/${path.basename(manifest.artwork.cover)} so lobby cards render cleanly.`);
|
|
210
264
|
}
|
|
211
|
-
|
|
265
|
+
if (manifest.artwork.poster) {
|
|
266
|
+
const posterMedia = await discoverMediaFile('poster', manifest.artwork.poster, manifest.slug, repoDir, resolvedDistDir);
|
|
267
|
+
if (posterMedia) {
|
|
268
|
+
media.push(posterMedia);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
const versionOverride = options.versionOverride?.trim();
|
|
272
|
+
if (versionOverride && !VERSION_RE.test(versionOverride)) {
|
|
273
|
+
throw new CliError('INVALID_VERSION', `Invalid --version override "${versionOverride}". Must match /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,47}$/.`, { details: { version: versionOverride } });
|
|
274
|
+
}
|
|
275
|
+
const version = versionOverride || manifest.version;
|
|
212
276
|
return {
|
|
213
277
|
slug: manifest.slug,
|
|
214
278
|
version,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@replaystage/cli",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "Unified agent-native CLI for building, validating, previewing, publishing, and operating ReplayStage portrait games.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"README.md"
|
|
34
34
|
],
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/node": "^
|
|
36
|
+
"@types/node": "^22.15.0"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsc -p tsconfig.json",
|