@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/config.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { chmod, mkdir, readFile, stat, writeFile } from 'node:fs/promises';
|
|
1
|
+
import { chmod, mkdir, readFile, rename, stat, unlink, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { randomBytes } from 'node:crypto';
|
|
2
3
|
import os from 'node:os';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
import { CliError } from './output.js';
|
|
@@ -24,14 +25,23 @@ export async function readStoredConfig() {
|
|
|
24
25
|
}
|
|
25
26
|
export async function writeStoredConfig(next) {
|
|
26
27
|
const filePath = getConfigFilePath();
|
|
27
|
-
|
|
28
|
+
const dir = path.dirname(filePath);
|
|
29
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
28
30
|
const payload = `${JSON.stringify({ ...next, updatedAt: new Date().toISOString() }, null, 2)}\n`;
|
|
29
|
-
|
|
31
|
+
const tmpPath = path.join(dir, `.config.${process.pid}.${randomBytes(6).toString('hex')}.tmp`);
|
|
30
32
|
try {
|
|
31
|
-
await
|
|
33
|
+
await writeFile(tmpPath, payload, { encoding: 'utf8', mode: 0o600, flag: 'wx' });
|
|
34
|
+
try {
|
|
35
|
+
await chmod(tmpPath, 0o600);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// ignore chmod failures on filesystems that don't support POSIX modes
|
|
39
|
+
}
|
|
40
|
+
await rename(tmpPath, filePath);
|
|
32
41
|
}
|
|
33
|
-
catch {
|
|
34
|
-
|
|
42
|
+
catch (err) {
|
|
43
|
+
await unlink(tmpPath).catch(() => { });
|
|
44
|
+
throw err;
|
|
35
45
|
}
|
|
36
46
|
return filePath;
|
|
37
47
|
}
|
|
@@ -100,13 +110,15 @@ export async function resolveAuthToken(options) {
|
|
|
100
110
|
if (pubEnv)
|
|
101
111
|
return pubEnv;
|
|
102
112
|
}
|
|
103
|
-
const stored = await readStoredConfig();
|
|
104
|
-
if (stored.token?.trim())
|
|
105
|
-
return stored.token.trim();
|
|
106
113
|
if (options.allowAdminEnvFallback) {
|
|
107
114
|
const adminEnv = process.env.REPLAYSTAGE_ADMIN_TOKEN?.trim();
|
|
108
115
|
if (adminEnv)
|
|
109
116
|
return adminEnv;
|
|
117
|
+
}
|
|
118
|
+
const stored = await readStoredConfig();
|
|
119
|
+
if (stored.token?.trim())
|
|
120
|
+
return stored.token.trim();
|
|
121
|
+
if (options.allowAdminEnvFallback) {
|
|
110
122
|
const fromDotEnv = await readLocalAdminEnvToken(options.cwd);
|
|
111
123
|
if (fromDotEnv)
|
|
112
124
|
return fromDotEnv;
|
package/dist/http.js
CHANGED
|
@@ -33,24 +33,31 @@ export async function apiRequestJson(opts) {
|
|
|
33
33
|
const maxRetries = opts.retries ?? (opts.method === 'POST' ? 0 : 2);
|
|
34
34
|
for (let attempt = 0; attempt <= maxRetries; attempt += 1) {
|
|
35
35
|
let res;
|
|
36
|
+
let text = '';
|
|
37
|
+
let shouldRetryStatus = false;
|
|
38
|
+
let retryMs = 350 * 2 ** attempt;
|
|
39
|
+
const controller = new AbortController();
|
|
40
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
36
41
|
try {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
res = await fetch(url, {
|
|
43
|
+
method: opts.method,
|
|
44
|
+
headers,
|
|
45
|
+
body: requestBody,
|
|
46
|
+
signal: controller.signal,
|
|
47
|
+
});
|
|
48
|
+
if (!res.ok && RETRYABLE_STATUSES.has(res.status) && attempt < maxRetries) {
|
|
49
|
+
shouldRetryStatus = true;
|
|
50
|
+
retryMs = parseRetryAfterMs(res.headers.get('retry-after')) ?? retryMs;
|
|
51
|
+
await res.body?.cancel().catch(() => { });
|
|
46
52
|
}
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
else {
|
|
54
|
+
text = await res.text();
|
|
49
55
|
}
|
|
50
56
|
}
|
|
51
57
|
catch (err) {
|
|
52
58
|
const isTimeout = err instanceof Error && err.name === 'AbortError';
|
|
53
59
|
if (attempt < maxRetries) {
|
|
60
|
+
clearTimeout(timer);
|
|
54
61
|
await delay(350 * 2 ** attempt);
|
|
55
62
|
continue;
|
|
56
63
|
}
|
|
@@ -58,12 +65,13 @@ export async function apiRequestJson(opts) {
|
|
|
58
65
|
? `Request timed out after ${timeoutMs}ms: ${opts.method} ${url}`
|
|
59
66
|
: `Failed to reach ${url}: ${err instanceof Error ? err.message : String(err)}`);
|
|
60
67
|
}
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
finally {
|
|
69
|
+
clearTimeout(timer);
|
|
70
|
+
}
|
|
71
|
+
if (shouldRetryStatus) {
|
|
63
72
|
await delay(retryMs);
|
|
64
73
|
continue;
|
|
65
74
|
}
|
|
66
|
-
const text = await res.text();
|
|
67
75
|
let parsed = {};
|
|
68
76
|
if (text) {
|
|
69
77
|
try {
|
|
@@ -90,7 +98,19 @@ export async function apiRequestJson(opts) {
|
|
|
90
98
|
method: opts.method,
|
|
91
99
|
path: opts.path,
|
|
92
100
|
};
|
|
93
|
-
if (Array.isArray(parsed.
|
|
101
|
+
if (Array.isArray(parsed.issues)) {
|
|
102
|
+
details.issues = parsed.issues;
|
|
103
|
+
details.errors = parsed.issues.map(item => {
|
|
104
|
+
if (item && typeof item === 'object') {
|
|
105
|
+
const rec = item;
|
|
106
|
+
if (typeof rec.field === 'string' && typeof rec.message === 'string') {
|
|
107
|
+
return `${rec.field}: ${rec.message}`;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return String(item);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
else if (Array.isArray(parsed.details)) {
|
|
94
114
|
details.errors = parsed.details;
|
|
95
115
|
}
|
|
96
116
|
else if (parsed.details && typeof parsed.details === 'object') {
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { cmdCreateGame, cmdDelete, cmdGames, cmdInit, cmdPublish, cmdReleases, c
|
|
|
5
5
|
import { CliError, DEFAULT_STREAMS, emitError, emitSuccess, extractBoolFlag, extractFlag, } from './output.js';
|
|
6
6
|
const require = createRequire(import.meta.url);
|
|
7
7
|
const pkgJson = require('../package.json');
|
|
8
|
-
export const CLI_VERSION = pkgJson.version ?? '2.1.
|
|
8
|
+
export const CLI_VERSION = pkgJson.version ?? '2.1.2';
|
|
9
9
|
export { CliError } from './output.js';
|
|
10
10
|
export { validateManifestObject, buildStarterManifest } from './manifest.js';
|
|
11
11
|
export { validateProjectBundle } from './validate.js';
|
|
@@ -64,14 +64,12 @@ export async function runCli(rawArgs, runtime = {}) {
|
|
|
64
64
|
const tokenParsed = extractFlag(rest, ['--token', '-t', '--auth-token']);
|
|
65
65
|
opts.token = tokenParsed.value;
|
|
66
66
|
rest = tokenParsed.rest;
|
|
67
|
-
|
|
68
|
-
rest = versionFlag.rest;
|
|
69
|
-
const helpFlag = extractBoolFlag(rest, ['-h', '--help']);
|
|
70
|
-
rest = helpFlag.rest;
|
|
71
|
-
if (versionFlag.present && rest.length === 0) {
|
|
67
|
+
if (rest.length === 1 && (rest[0] === '-v' || rest[0] === '--version')) {
|
|
72
68
|
emitSuccess(opts, { version: CLI_VERSION }, () => [`replaystage v${CLI_VERSION}`]);
|
|
73
69
|
return 0;
|
|
74
70
|
}
|
|
71
|
+
const helpFlag = extractBoolFlag(rest, ['-h', '--help']);
|
|
72
|
+
rest = helpFlag.rest;
|
|
75
73
|
const [command, ...cmdArgs] = rest;
|
|
76
74
|
if (!command || helpFlag.present) {
|
|
77
75
|
emitSuccess(opts, {
|
package/dist/manifest.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export interface ReplayStageManifest {
|
|
|
34
34
|
artwork: {
|
|
35
35
|
icon: string;
|
|
36
36
|
cover: string;
|
|
37
|
+
poster?: string;
|
|
37
38
|
};
|
|
38
39
|
platforms: {
|
|
39
40
|
web: boolean;
|
|
@@ -56,12 +57,16 @@ export interface ReplayStageManifest {
|
|
|
56
57
|
};
|
|
57
58
|
}
|
|
58
59
|
export declare const SLUG_RE: RegExp;
|
|
60
|
+
export declare const VERSION_RE: RegExp;
|
|
61
|
+
export declare const ENTRY_PATH_RE: RegExp;
|
|
59
62
|
export declare const HEX_COLOR_RE: RegExp;
|
|
60
63
|
export declare const ASPECT_RATIO_RE: RegExp;
|
|
64
|
+
export declare const RESERVED_GAME_SLUGS: Set<string>;
|
|
61
65
|
export declare const VALID_GENRES: readonly GameGenre[];
|
|
62
66
|
export declare const VALID_CREATOR_VISIBILITIES: readonly ["live", "beta", "unlisted", "hidden"];
|
|
63
67
|
export declare const VALID_ADMIN_VISIBILITIES: readonly GameVisibility[];
|
|
64
68
|
export declare function slugToTitle(slug: string): string;
|
|
69
|
+
export declare function isSafeEntryPath(val: unknown): val is string;
|
|
65
70
|
export declare function validateManifestObject(raw: unknown): {
|
|
66
71
|
valid: boolean;
|
|
67
72
|
errors: string[];
|
package/dist/manifest.js
CHANGED
|
@@ -2,9 +2,49 @@ import { readFile, stat, writeFile } from 'node:fs/promises';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { CliError } from './output.js';
|
|
4
4
|
export const SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
5
|
+
export const VERSION_RE = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,47}$/;
|
|
6
|
+
export const ENTRY_PATH_RE = /^\/(?:[a-zA-Z0-9._-]+\/)*[a-zA-Z0-9._-]+$/;
|
|
5
7
|
export const HEX_COLOR_RE = /^#[0-9a-fA-F]{6}$/;
|
|
6
8
|
export const ASPECT_RATIO_RE = /^\d+:\d+$/;
|
|
9
|
+
export const RESERVED_GAME_SLUGS = new Set([
|
|
10
|
+
'admin',
|
|
11
|
+
'api',
|
|
12
|
+
'assets',
|
|
13
|
+
'auth',
|
|
14
|
+
'c',
|
|
15
|
+
'catalog',
|
|
16
|
+
'constructor',
|
|
17
|
+
'creator',
|
|
18
|
+
'creators',
|
|
19
|
+
'daily',
|
|
20
|
+
'emulator',
|
|
21
|
+
'favicon',
|
|
22
|
+
'health',
|
|
23
|
+
'icons',
|
|
24
|
+
'login',
|
|
25
|
+
'manifest',
|
|
26
|
+
'media',
|
|
27
|
+
'og',
|
|
28
|
+
'platform',
|
|
29
|
+
'play',
|
|
30
|
+
'privacy',
|
|
31
|
+
'prototype',
|
|
32
|
+
'register',
|
|
33
|
+
'replaystage',
|
|
34
|
+
'robots',
|
|
35
|
+
'schemas',
|
|
36
|
+
'sdk',
|
|
37
|
+
'sitemap',
|
|
38
|
+
'skill',
|
|
39
|
+
'stats',
|
|
40
|
+
'studio',
|
|
41
|
+
'support',
|
|
42
|
+
'sw',
|
|
43
|
+
'system',
|
|
44
|
+
'www',
|
|
45
|
+
]);
|
|
7
46
|
export const VALID_GENRES = ['arcade', 'puzzle', 'mystery', 'strategy'];
|
|
47
|
+
const VALID_LOCALES = ['en', 'zh-Hans'];
|
|
8
48
|
export const VALID_CREATOR_VISIBILITIES = ['live', 'beta', 'unlisted', 'hidden'];
|
|
9
49
|
export const VALID_ADMIN_VISIBILITIES = [
|
|
10
50
|
'featured',
|
|
@@ -21,8 +61,52 @@ export function slugToTitle(slug) {
|
|
|
21
61
|
.map(part => (part[0] ? part[0].toUpperCase() + part.slice(1) : part))
|
|
22
62
|
.join(' ');
|
|
23
63
|
}
|
|
24
|
-
function isNonEmptyString(val) {
|
|
25
|
-
return typeof val === 'string' && val.trim().length > 0;
|
|
64
|
+
function isNonEmptyString(val, maxLen = 600) {
|
|
65
|
+
return typeof val === 'string' && val.trim().length > 0 && val.length <= maxLen;
|
|
66
|
+
}
|
|
67
|
+
export function isSafeEntryPath(val) {
|
|
68
|
+
if (typeof val !== 'string')
|
|
69
|
+
return false;
|
|
70
|
+
if (val.length < 2 || val.length > 256)
|
|
71
|
+
return false;
|
|
72
|
+
if (!val.startsWith('/') || val.startsWith('//'))
|
|
73
|
+
return false;
|
|
74
|
+
if (val.includes('..') || val.includes('\\'))
|
|
75
|
+
return false;
|
|
76
|
+
return ENTRY_PATH_RE.test(val);
|
|
77
|
+
}
|
|
78
|
+
function isSafeAspectRatio(val) {
|
|
79
|
+
if (typeof val !== 'string' || val.length > 9 || !ASPECT_RATIO_RE.test(val))
|
|
80
|
+
return false;
|
|
81
|
+
const [rawW, rawH] = val.split(':');
|
|
82
|
+
const w = Number(rawW);
|
|
83
|
+
const h = Number(rawH);
|
|
84
|
+
return Number.isInteger(w) && Number.isInteger(h) && w >= 1 && w <= 100 && h >= 1 && h <= 100;
|
|
85
|
+
}
|
|
86
|
+
function isSafeHttpUrl(val, maxLen = 300) {
|
|
87
|
+
if (val.length === 0 || val.length > maxLen)
|
|
88
|
+
return false;
|
|
89
|
+
try {
|
|
90
|
+
const u = new URL(val);
|
|
91
|
+
return u.protocol === 'https:' || u.protocol === 'http:';
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function isSafeArtworkRef(val) {
|
|
98
|
+
if (!isNonEmptyString(val, 256))
|
|
99
|
+
return false;
|
|
100
|
+
const trimmed = val.trim();
|
|
101
|
+
if (/[\u0000-\u001f\u007f]/.test(trimmed))
|
|
102
|
+
return false;
|
|
103
|
+
if (trimmed.startsWith('https://'))
|
|
104
|
+
return isSafeHttpUrl(trimmed, 256);
|
|
105
|
+
if (trimmed.startsWith('//') || trimmed.includes('..') || trimmed.includes('\\'))
|
|
106
|
+
return false;
|
|
107
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(trimmed))
|
|
108
|
+
return false;
|
|
109
|
+
return true;
|
|
26
110
|
}
|
|
27
111
|
export function validateManifestObject(raw) {
|
|
28
112
|
const errors = [];
|
|
@@ -30,11 +114,17 @@ export function validateManifestObject(raw) {
|
|
|
30
114
|
return { valid: false, errors: ['Manifest must be a JSON object'] };
|
|
31
115
|
}
|
|
32
116
|
const m = raw;
|
|
33
|
-
if (
|
|
34
|
-
errors.push('
|
|
117
|
+
if (m.schemaVersion !== 1) {
|
|
118
|
+
errors.push('schemaVersion must be 1');
|
|
119
|
+
}
|
|
120
|
+
if (!isNonEmptyString(m.slug, 40) || !SLUG_RE.test(m.slug) || m.slug.length < 2 || m.slug.length > 40) {
|
|
121
|
+
errors.push('slug must be 2-40 chars lowercase kebab-case (e.g. "neon-stack")');
|
|
35
122
|
}
|
|
36
|
-
if (
|
|
37
|
-
errors.push(
|
|
123
|
+
else if (RESERVED_GAME_SLUGS.has(m.slug)) {
|
|
124
|
+
errors.push(`slug "${m.slug}" is reserved`);
|
|
125
|
+
}
|
|
126
|
+
if (!isNonEmptyString(m.version, 48) || !VERSION_RE.test(m.version)) {
|
|
127
|
+
errors.push('version must match /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,47}$/ (e.g. "1.0.0")');
|
|
38
128
|
}
|
|
39
129
|
if (m.tier !== 0 && m.tier !== 1 && m.tier !== 2) {
|
|
40
130
|
errors.push('tier must be 0, 1, or 2');
|
|
@@ -45,65 +135,128 @@ export function validateManifestObject(raw) {
|
|
|
45
135
|
if (!isNonEmptyString(m.accentColor) || !HEX_COLOR_RE.test(m.accentColor)) {
|
|
46
136
|
errors.push('accentColor must be a 6-digit hex color (e.g. "#0F62FE")');
|
|
47
137
|
}
|
|
48
|
-
if (!
|
|
49
|
-
errors.push('aspectRatio must match "<w>:<h>" (e.g. "9:16")');
|
|
138
|
+
if (!isSafeAspectRatio(m.aspectRatio)) {
|
|
139
|
+
errors.push('aspectRatio must match "<w>:<h>" with 1..100 integers (e.g. "9:16")');
|
|
140
|
+
}
|
|
141
|
+
if (!isNonEmptyString(m.sessionMinutes, 40)) {
|
|
142
|
+
errors.push('sessionMinutes must be a non-empty string <= 40 chars (e.g. "1–3 min")');
|
|
50
143
|
}
|
|
51
|
-
if (!isNonEmptyString(m.
|
|
52
|
-
errors.push('
|
|
144
|
+
if (!isNonEmptyString(m.ageRating, 16)) {
|
|
145
|
+
errors.push('ageRating must be a non-empty string <= 16 chars (e.g. "6+")');
|
|
53
146
|
}
|
|
54
|
-
if (
|
|
55
|
-
|
|
147
|
+
if (m.gameLanguages !== undefined) {
|
|
148
|
+
if (!Array.isArray(m.gameLanguages) ||
|
|
149
|
+
m.gameLanguages.length === 0 ||
|
|
150
|
+
m.gameLanguages.length > 2 ||
|
|
151
|
+
!m.gameLanguages.every(item => VALID_LOCALES.includes(item))) {
|
|
152
|
+
errors.push('gameLanguages must be an array of 1..2 supported locales ("en", "zh-Hans")');
|
|
153
|
+
}
|
|
56
154
|
}
|
|
57
155
|
const locales = m.locales;
|
|
58
156
|
for (const loc of ['en', 'zh-Hans']) {
|
|
59
157
|
const copy = locales?.[loc];
|
|
60
|
-
if (!copy || typeof copy !== 'object') {
|
|
158
|
+
if (!copy || typeof copy !== 'object' || Array.isArray(copy)) {
|
|
61
159
|
errors.push(`locales.${loc} is required`);
|
|
62
160
|
continue;
|
|
63
161
|
}
|
|
64
|
-
if (!isNonEmptyString(copy.title))
|
|
65
|
-
errors.push(`locales.${loc}.title is required`);
|
|
66
|
-
if (!isNonEmptyString(copy.tagline))
|
|
67
|
-
errors.push(`locales.${loc}.tagline is required`);
|
|
68
|
-
if (!isNonEmptyString(copy.description))
|
|
69
|
-
errors.push(`locales.${loc}.description is required`);
|
|
70
|
-
if (!Array.isArray(copy.howToPlay) ||
|
|
71
|
-
|
|
162
|
+
if (!isNonEmptyString(copy.title, 80))
|
|
163
|
+
errors.push(`locales.${loc}.title is required (<= 80 chars)`);
|
|
164
|
+
if (!isNonEmptyString(copy.tagline, 160))
|
|
165
|
+
errors.push(`locales.${loc}.tagline is required (<= 160 chars)`);
|
|
166
|
+
if (!isNonEmptyString(copy.description, 600))
|
|
167
|
+
errors.push(`locales.${loc}.description is required (<= 600 chars)`);
|
|
168
|
+
if (!Array.isArray(copy.howToPlay) ||
|
|
169
|
+
copy.howToPlay.length === 0 ||
|
|
170
|
+
copy.howToPlay.length > 6 ||
|
|
171
|
+
!copy.howToPlay.every(item => isNonEmptyString(item, 240))) {
|
|
172
|
+
errors.push(`locales.${loc}.howToPlay must be an array of 1..6 non-empty strings (<= 240 chars)`);
|
|
72
173
|
}
|
|
73
|
-
if (
|
|
74
|
-
|
|
174
|
+
if (copy.tags !== undefined) {
|
|
175
|
+
if (!Array.isArray(copy.tags) ||
|
|
176
|
+
copy.tags.length > 8 ||
|
|
177
|
+
!copy.tags.every(item => isNonEmptyString(item, 32))) {
|
|
178
|
+
errors.push(`locales.${loc}.tags must be an array of <= 8 strings (<= 32 chars)`);
|
|
179
|
+
}
|
|
75
180
|
}
|
|
76
181
|
}
|
|
77
182
|
const runtime = m.runtime;
|
|
78
|
-
if (!runtime || typeof runtime !== 'object') {
|
|
183
|
+
if (!runtime || typeof runtime !== 'object' || Array.isArray(runtime)) {
|
|
79
184
|
errors.push('runtime is required');
|
|
80
185
|
}
|
|
81
186
|
else {
|
|
82
|
-
if (
|
|
83
|
-
|
|
187
|
+
if (runtime.originSlug !== undefined) {
|
|
188
|
+
if (!isNonEmptyString(runtime.originSlug, 40) ||
|
|
189
|
+
!SLUG_RE.test(runtime.originSlug) ||
|
|
190
|
+
runtime.originSlug.length < 2 ||
|
|
191
|
+
runtime.originSlug.length > 40) {
|
|
192
|
+
errors.push('runtime.originSlug must be 2-40 chars lowercase kebab-case');
|
|
193
|
+
}
|
|
194
|
+
else if (RESERVED_GAME_SLUGS.has(runtime.originSlug)) {
|
|
195
|
+
errors.push(`runtime.originSlug "${runtime.originSlug}" is reserved`);
|
|
196
|
+
}
|
|
84
197
|
}
|
|
85
|
-
if (!
|
|
86
|
-
errors.push('runtime.entryPath must
|
|
198
|
+
if (!isSafeEntryPath(runtime.entryPath)) {
|
|
199
|
+
errors.push('runtime.entryPath must be a clean relative path starting with "/" (e.g. "/index.html")');
|
|
200
|
+
}
|
|
201
|
+
if (runtime.productionOrigin !== undefined &&
|
|
202
|
+
(typeof runtime.productionOrigin !== 'string' || !isSafeHttpUrl(runtime.productionOrigin))) {
|
|
203
|
+
errors.push('runtime.productionOrigin must be a valid http(s) URL');
|
|
204
|
+
}
|
|
205
|
+
if (runtime.challengeOrigin !== undefined &&
|
|
206
|
+
(typeof runtime.challengeOrigin !== 'string' || !isSafeHttpUrl(runtime.challengeOrigin))) {
|
|
207
|
+
errors.push('runtime.challengeOrigin must be a valid http(s) URL');
|
|
87
208
|
}
|
|
88
209
|
}
|
|
89
210
|
const artwork = m.artwork;
|
|
90
|
-
if (!artwork || typeof artwork !== 'object') {
|
|
211
|
+
if (!artwork || typeof artwork !== 'object' || Array.isArray(artwork)) {
|
|
91
212
|
errors.push('artwork is required');
|
|
92
213
|
}
|
|
93
214
|
else {
|
|
94
|
-
if (!
|
|
95
|
-
errors.push('artwork.icon
|
|
96
|
-
if (!
|
|
97
|
-
errors.push('artwork.cover
|
|
215
|
+
if (!isSafeArtworkRef(artwork.icon))
|
|
216
|
+
errors.push('artwork.icon must be a safe relative path or https:// URL');
|
|
217
|
+
if (!isSafeArtworkRef(artwork.cover))
|
|
218
|
+
errors.push('artwork.cover must be a safe relative path or https:// URL');
|
|
219
|
+
if (artwork.poster !== undefined && artwork.poster !== '' && !isSafeArtworkRef(artwork.poster)) {
|
|
220
|
+
errors.push('artwork.poster must be a safe relative path or https:// URL');
|
|
221
|
+
}
|
|
98
222
|
}
|
|
99
223
|
const platforms = m.platforms;
|
|
100
|
-
if (!platforms || typeof platforms
|
|
101
|
-
errors.push('platforms
|
|
224
|
+
if (!platforms || typeof platforms !== 'object' || Array.isArray(platforms)) {
|
|
225
|
+
errors.push('platforms must be an object');
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
if (platforms.web !== undefined && typeof platforms.web !== 'boolean') {
|
|
229
|
+
errors.push('platforms.web must be a boolean');
|
|
230
|
+
}
|
|
231
|
+
for (const key of ['ios', 'android']) {
|
|
232
|
+
const store = platforms[key];
|
|
233
|
+
if (store && typeof store === 'object' && !Array.isArray(store)) {
|
|
234
|
+
const storeUrl = store.storeUrl;
|
|
235
|
+
if (storeUrl !== undefined && storeUrl !== '') {
|
|
236
|
+
if (typeof storeUrl !== 'string' || !isSafeHttpUrl(storeUrl.trim())) {
|
|
237
|
+
errors.push(`platforms.${key}.storeUrl must be a valid http(s) URL`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
102
242
|
}
|
|
103
243
|
if (errors.length > 0) {
|
|
104
244
|
return { valid: false, errors };
|
|
105
245
|
}
|
|
106
|
-
|
|
246
|
+
const normalized = {
|
|
247
|
+
...raw,
|
|
248
|
+
runtime: {
|
|
249
|
+
...runtime,
|
|
250
|
+
originSlug: typeof runtime?.originSlug === 'string' && runtime.originSlug
|
|
251
|
+
? runtime.originSlug
|
|
252
|
+
: m.slug,
|
|
253
|
+
},
|
|
254
|
+
platforms: {
|
|
255
|
+
...platforms,
|
|
256
|
+
web: typeof platforms?.web === 'boolean' ? platforms.web : true,
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
return { valid: true, errors: [], manifest: normalized };
|
|
107
260
|
}
|
|
108
261
|
export async function loadAndValidateManifest(manifestPath) {
|
|
109
262
|
const resolved = path.resolve(manifestPath);
|
package/dist/validate.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface BundleFileItem {
|
|
|
11
11
|
contentType: string;
|
|
12
12
|
}
|
|
13
13
|
export interface DiscoveredMediaItem {
|
|
14
|
-
slot: 'icon' | 'cover';
|
|
14
|
+
slot: 'icon' | 'cover' | 'poster';
|
|
15
15
|
filename: string;
|
|
16
16
|
absPath: string;
|
|
17
17
|
bytes: number;
|
|
@@ -30,7 +30,7 @@ export interface ValidationReport {
|
|
|
30
30
|
warnings: string[];
|
|
31
31
|
manifest: ReplayStageManifest;
|
|
32
32
|
}
|
|
33
|
-
export declare function discoverMediaFile(slot: 'icon' | 'cover', artworkUrl: string, slug: string, repoDir: string, distDir?: string): Promise<DiscoveredMediaItem | null>;
|
|
33
|
+
export declare function discoverMediaFile(slot: 'icon' | 'cover' | 'poster', artworkUrl: string, slug: string, repoDir: string, distDir?: string): Promise<DiscoveredMediaItem | null>;
|
|
34
34
|
export declare function validateProjectBundle(options: {
|
|
35
35
|
cwd: string;
|
|
36
36
|
distDir?: string;
|