@replaystage/cli 2.0.0 → 2.1.1

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.
@@ -1,430 +1,106 @@
1
- import { cp, mkdir, readdir, readFile, stat, writeFile } from 'node:fs/promises';
1
+ import { readFile } from 'node:fs/promises';
2
2
  import path from 'node:path';
3
- import { DEFAULT_PORTAL_ORIGIN, DEFAULT_STUDIO_ORIGIN, findPlatformWorkspaceRoot, requireAuthToken, resolveApiBase, } from '../config.js';
3
+ import { DEFAULT_PORTAL_ORIGIN, requireAuthToken, resolveApiBase } from '../config.js';
4
4
  import { apiRequestJson } from '../http.js';
5
- import { HEX_COLOR_RE, SLUG_RE, VALID_CREATOR_VISIBILITIES, VALID_GENRES, buildStarterManifest, slugToTitle, writeStarterManifest, } from '../manifest.js';
5
+ import { SLUG_RE, VALID_CREATOR_VISIBILITIES, loadAndValidateManifest } from '../manifest.js';
6
6
  import { CliError, assertNoUnknownFlags, emitSuccess, extractBoolFlag, extractFlag, } from '../output.js';
7
- import { validateProjectBundle } from '../validate.js';
8
- async function exists(targetPath) {
9
- try {
10
- await stat(targetPath);
11
- return true;
12
- }
13
- catch {
14
- return false;
15
- }
16
- }
17
- function formatBytes(bytes) {
18
- if (bytes < 1024)
19
- return `${bytes} B`;
20
- if (bytes < 1024 * 1024)
21
- return `${(bytes / 1024).toFixed(1)} KB`;
22
- return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
23
- }
24
- async function runPool(items, concurrency, worker) {
25
- let cursor = 0;
26
- const workers = Array.from({ length: Math.min(concurrency, items.length) }, async () => {
27
- while (cursor < items.length) {
28
- const idx = cursor;
29
- cursor += 1;
30
- const item = items[idx];
31
- if (item !== undefined) {
32
- await worker(item);
33
- }
34
- }
35
- });
36
- await Promise.all(workers);
37
- }
38
- export async function cmdInit(args, opts) {
39
- let rest = args;
40
- const dirFlag = extractFlag(rest, ['--dir']);
41
- rest = dirFlag.rest;
42
- const titleFlag = extractFlag(rest, ['--title']);
43
- rest = titleFlag.rest;
44
- const zhFlag = extractFlag(rest, ['--zh']);
45
- rest = zhFlag.rest;
46
- const genreFlag = extractFlag(rest, ['--genre']);
47
- rest = genreFlag.rest;
48
- const accentFlag = extractFlag(rest, ['--accent']);
49
- rest = accentFlag.rest;
50
- const forceFlag = extractBoolFlag(rest, ['--force', '-f']);
51
- rest = forceFlag.rest;
52
- assertNoUnknownFlags(rest);
53
- const slug = rest[0]?.trim().toLowerCase();
54
- if (!slug || !SLUG_RE.test(slug) || slug.length < 3 || slug.length > 48) {
55
- throw new CliError('INVALID_ARGUMENTS', 'Usage: replaystage init <slug> [--dir <path>] [--title "<English>"] [--zh "<中文>"] [--genre arcade|puzzle|mystery|strategy] [--accent "#E5482E"] [--force]');
56
- }
57
- const genre = (genreFlag.value || 'arcade');
58
- if (!VALID_GENRES.includes(genre)) {
59
- throw new CliError('INVALID_ARGUMENTS', `Invalid --genre "${genre}". Expected one of: ${VALID_GENRES.join(', ')}`);
60
- }
61
- const accentColor = accentFlag.value || '#E5482E';
62
- if (!HEX_COLOR_RE.test(accentColor)) {
63
- throw new CliError('INVALID_ARGUMENTS', `Invalid --accent "${accentColor}". Expected 6-digit hex like "#E5482E".`);
64
- }
65
- const targetDir = path.resolve(opts.cwd, dirFlag.value || '.');
66
- await mkdir(targetDir, { recursive: true });
67
- const manifest = buildStarterManifest({
68
- slug,
69
- titleEn: titleFlag.value,
70
- titleZh: zhFlag.value,
71
- genre,
72
- accentColor,
73
- });
74
- const writtenPath = await writeStarterManifest(path.join(targetDir, 'replaystage.manifest.json'), manifest, forceFlag.present);
75
- emitSuccess(opts, { slug, manifestPath: writtenPath, manifest }, () => [
76
- `Created ${writtenPath}`,
77
- 'Next steps:',
78
- ' 1. Replace the placeholder tagline/description/howToPlay with real bilingual (en + zh-Hans) copy.',
79
- ` 2. Add icon.png and cover.png under public/media/${slug}/ (<= 2 MB each).`,
80
- ' 3. Build your game and run `npx -y replaystage validate ./dist --json`.',
81
- ' 4. Publish an unlisted preview with `npx -y replaystage publish ./dist --json`.',
82
- ]);
83
- }
84
- export async function cmdCreateGame(args, opts) {
85
- let rest = args;
86
- const dirFlag = extractFlag(rest, ['--dir']);
87
- rest = dirFlag.rest;
88
- const titleFlag = extractFlag(rest, ['--title']);
89
- rest = titleFlag.rest;
90
- const zhFlag = extractFlag(rest, ['--zh']);
91
- rest = zhFlag.rest;
92
- const genreFlag = extractFlag(rest, ['--genre']);
93
- rest = genreFlag.rest;
94
- assertNoUnknownFlags(rest);
95
- const slug = rest[0]?.trim().toLowerCase();
96
- if (!slug || !SLUG_RE.test(slug) || slug.length < 3 || slug.length > 48) {
97
- throw new CliError('INVALID_ARGUMENTS', 'Usage: replaystage create-game <slug> [--dir <path>] [--title "<English>"] [--zh "<中文>"] [--genre arcade|puzzle|mystery|strategy]');
98
- }
99
- const titleEn = titleFlag.value?.trim() || slugToTitle(slug);
100
- const titleZh = zhFlag.value?.trim() || titleEn;
101
- const genre = (genreFlag.value || 'arcade');
102
- if (!VALID_GENRES.includes(genre)) {
103
- throw new CliError('INVALID_ARGUMENTS', `Invalid --genre "${genre}".`);
104
- }
105
- const workspaceRoot = await findPlatformWorkspaceRoot(opts.cwd);
106
- const targetDir = dirFlag.value
107
- ? path.resolve(opts.cwd, dirFlag.value)
108
- : workspaceRoot
109
- ? path.resolve(workspaceRoot, '..', slug)
110
- : path.resolve(opts.cwd, slug);
111
- if (await exists(targetDir)) {
112
- const existing = await readdir(targetDir);
113
- if (existing.length > 0) {
114
- throw new CliError('TARGET_NOT_EMPTY', `Target directory is not empty: ${targetDir}`, {
115
- details: { targetDir },
116
- });
117
- }
118
- }
119
- await mkdir(targetDir, { recursive: true });
120
- let mode = 'standalone-starter';
121
- if (workspaceRoot && (await exists(path.join(workspaceRoot, 'templates', 'starter-web-game')))) {
122
- mode = 'workspace-template';
123
- const templateDir = path.join(workspaceRoot, 'templates', 'starter-web-game');
124
- await cp(templateDir, targetDir, { recursive: true });
125
- const replacements = [
126
- ['package.json', [['"name": "replaystage-starter-game"', `"name": "${slug}"`]]],
127
- ['index.html', [['<title>ReplayStage Starter Game</title>', `<title>${titleEn}</title>`]]],
128
- ['.github/workflows/publish-replaystage.yml', [['slug: starter-game', `slug: ${slug}`]]],
129
- [
130
- 'replaystage.manifest.json',
131
- [
132
- ['"slug": "starter-game"', `"slug": "${slug}"`],
133
- ['"originSlug": "starter-game"', `"originSlug": "${slug}"`],
134
- ['"genre": "arcade"', `"genre": "${genre}"`],
135
- ['"title": "Pulse Tap"', `"title": ${JSON.stringify(titleEn)}`],
136
- ['"title": "节拍点按"', `"title": ${JSON.stringify(titleZh)}`],
137
- ],
138
- ],
139
- [
140
- 'src/main.ts',
141
- [
142
- [
143
- "const STORAGE_KEY = 'rs_starter_save_v1';",
144
- `const STORAGE_KEY = 'rs_${slug.replace(/-/g, '_')}_save_v1';`,
145
- ],
146
- ["title: 'PULSE TAP'", `title: ${JSON.stringify(titleEn.toUpperCase())}`],
147
- ["title: '节拍点按'", `title: ${JSON.stringify(titleZh)}`],
148
- ],
149
- ],
150
- ['public/cover.svg', [['PULSE TAP', titleEn.toUpperCase()]]],
151
- ];
152
- for (const [relFile, pairs] of replacements) {
153
- const full = path.join(targetDir, relFile);
154
- if (!(await exists(full)))
155
- continue;
156
- let content = await readFile(full, 'utf8');
157
- for (const [from, to] of pairs) {
158
- content = content.replace(from, to);
159
- }
160
- await writeFile(full, content, 'utf8');
161
- }
162
- }
163
- else {
164
- // Standalone zero-install Tier 2 starter using ReplayStage hosted CDN SDK
165
- const manifest = buildStarterManifest({ slug, titleEn, titleZh, genre });
166
- await writeFile(path.join(targetDir, 'replaystage.manifest.json'), `${JSON.stringify(manifest, null, 2)}\n`, 'utf8');
167
- await mkdir(path.join(targetDir, 'dist'), { recursive: true });
168
- await mkdir(path.join(targetDir, '.github', 'workflows'), { recursive: true });
169
- await writeFile(path.join(targetDir, 'dist', 'index.html'), `<!doctype html>
170
- <html lang="en">
171
- <head>
172
- <meta charset="utf-8" />
173
- <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
174
- <title>${titleEn}</title>
175
- <style>
176
- html, body { margin: 0; height: 100%; background: #101217; color: #f4f5f7; font-family: system-ui, sans-serif; display: grid; place-items: center; }
177
- main { text-align: center; padding: 24px; }
178
- button { padding: 14px 28px; border-radius: 999px; border: 0; background: #e5482e; color: #fff; font-size: 16px; font-weight: 700; cursor: pointer; }
179
- </style>
180
- </head>
181
- <body>
182
- <main>
183
- <h1>${titleEn}</h1>
184
- <p id="score">Score: 0</p>
185
- <button id="tap" type="button">Tap +1</button>
186
- </main>
187
- <script type="module">
188
- import { createReplayStageGameClient } from 'https://replaystage.com/sdk/v1/replaystage.esm.js';
189
- let score = 0;
190
- const client = createReplayStageGameClient({ gameVersion: '1.0.0' });
191
- client.ready();
192
- document.getElementById('tap').addEventListener('click', () => {
193
- score += 1;
194
- document.getElementById('score').textContent = 'Score: ' + score;
195
- client.reportResult({ score, scoreUnit: 'pts', completed: false });
196
- });
197
- </script>
198
- </body>
199
- </html>
200
- `, 'utf8');
201
- await writeFile(path.join(targetDir, '.github', 'workflows', 'publish-replaystage.yml'), `name: Publish to ReplayStage
202
-
203
- on:
204
- push:
205
- branches:
206
- - main
207
- workflow_dispatch:
208
-
209
- jobs:
210
- publish:
211
- uses: replaystage/platform/.github/workflows/publish-game-reusable.yml@main
212
- with:
213
- slug: ${slug}
214
- manifest_path: replaystage.manifest.json
215
- dist_dir: dist
216
- build_command: "true"
217
- package_manager: npm
218
- secrets:
219
- REPLAYSTAGE_PUBLISH_TOKEN: \${{ secrets.REPLAYSTAGE_PUBLISH_TOKEN }}
220
- `, 'utf8');
221
- }
222
- emitSuccess(opts, { slug, targetDir, mode, titleEn, titleZh, genre }, () => [
223
- `Created Tier 2 starter project "${slug}" at ${targetDir} (${mode})`,
224
- 'Next steps:',
225
- ` 1. cd ${targetDir}`,
226
- ' 2. Build your game and run `npx -y replaystage validate ./dist --json`',
227
- ' 3. Publish an unlisted preview with `npx -y replaystage publish ./dist --json`',
228
- ]);
229
- }
230
- export async function cmdValidate(args, opts) {
231
- let rest = args;
232
- const manifestFlag = extractFlag(rest, ['--manifest', '-m']);
233
- rest = manifestFlag.rest;
234
- const versionFlag = extractFlag(rest, ['--version']);
235
- rest = versionFlag.rest;
236
- assertNoUnknownFlags(rest);
237
- const distDir = rest[0] || 'dist';
238
- const report = await validateProjectBundle({
239
- cwd: opts.cwd,
240
- distDir,
241
- manifestPath: manifestFlag.value,
242
- versionOverride: versionFlag.value,
243
- });
244
- emitSuccess(opts, {
245
- slug: report.slug,
246
- version: report.version,
247
- manifestPath: report.manifestPath,
248
- distDir: report.distDir,
249
- entryPath: report.entryPath,
250
- fileCount: report.fileCount,
251
- totalBytes: report.totalBytes,
252
- media: report.media.map(m => ({ slot: m.slot, filename: m.filename, bytes: m.bytes })),
253
- warnings: report.warnings,
254
- }, () => {
255
- const lines = [
256
- `Valid ReplayStage bundle: ${report.slug} v${report.version}`,
257
- ` Manifest: ${report.manifestPath}`,
258
- ` Dist: ${report.distDir} (${report.fileCount} files, ${formatBytes(report.totalBytes)}, entry ${report.entryPath})`,
259
- ];
260
- if (report.media.length > 0) {
261
- lines.push(` Media: ${report.media.map(m => `${m.slot}=${m.filename}`).join(', ')}`);
262
- }
263
- for (const w of report.warnings) {
264
- lines.push(` [WARN] ${w}`);
265
- }
266
- return lines;
267
- });
268
- }
269
- export async function cmdPublish(args, opts) {
7
+ import { discoverMediaFile } from '../validate.js';
8
+ export { cmdCreateGame, cmdInit, cmdSdk } from './creator-scaffold.js';
9
+ export { cmdPublish, cmdReleases, cmdRollback, cmdValidate } from './creator-publish.js';
10
+ export async function cmdUpdate(args, opts) {
270
11
  let rest = args;
271
12
  const manifestFlag = extractFlag(rest, ['--manifest', '-m']);
272
13
  rest = manifestFlag.rest;
273
- const versionFlag = extractFlag(rest, ['--version']);
274
- rest = versionFlag.rest;
275
14
  const visFlag = extractFlag(rest, ['--visibility']);
276
15
  rest = visFlag.rest;
277
- const unlistedFlag = extractBoolFlag(rest, ['--unlisted']);
278
- rest = unlistedFlag.rest;
279
- const liveFlag = extractBoolFlag(rest, ['--live']);
280
- rest = liveFlag.rest;
281
- const betaFlag = extractBoolFlag(rest, ['--beta']);
282
- rest = betaFlag.rest;
283
- const hiddenFlag = extractBoolFlag(rest, ['--hidden']);
284
- rest = hiddenFlag.rest;
285
- const skipHealthFlag = extractBoolFlag(rest, ['--skip-health']);
286
- rest = skipHealthFlag.rest;
287
16
  assertNoUnknownFlags(rest);
288
- const selectedVisFlags = [
289
- visFlag.value,
290
- unlistedFlag.present ? 'unlisted' : undefined,
291
- liveFlag.present ? 'live' : undefined,
292
- betaFlag.present ? 'beta' : undefined,
293
- hiddenFlag.present ? 'hidden' : undefined,
294
- ].filter((v) => Boolean(v));
295
- if (selectedVisFlags.length > 1) {
296
- throw new CliError('INVALID_ARGUMENTS', 'Specify at most one visibility flag (--unlisted, --live, --beta, --hidden, or --visibility).');
17
+ const manifestPath = manifestFlag.value
18
+ ? path.resolve(opts.cwd, manifestFlag.value)
19
+ : path.resolve(opts.cwd, 'replaystage.manifest.json');
20
+ const { manifest, manifestPath: resolvedManifestPath } = await loadAndValidateManifest(manifestPath);
21
+ const slug = rest[0]?.trim().toLowerCase() || manifest.slug;
22
+ if (!SLUG_RE.test(slug)) {
23
+ throw new CliError('INVALID_ARGUMENTS', 'Usage: replaystage update [slug] [--manifest <path>] [--visibility live|beta|unlisted|hidden] [--json]');
297
24
  }
298
- const explicitVisibility = selectedVisFlags[0];
299
- if (explicitVisibility &&
300
- !VALID_CREATOR_VISIBILITIES.includes(explicitVisibility)) {
301
- throw new CliError('INVALID_ARGUMENTS', `Invalid visibility "${explicitVisibility}". Allowed: ${VALID_CREATOR_VISIBILITIES.join(', ')}.`);
25
+ if (manifest.slug !== slug) {
26
+ throw new CliError('SLUG_MISMATCH', `Manifest slug "${manifest.slug}" does not match target slug "${slug}".`);
27
+ }
28
+ if (visFlag.value && !VALID_CREATOR_VISIBILITIES.includes(visFlag.value)) {
29
+ throw new CliError('INVALID_ARGUMENTS', `Invalid visibility "${visFlag.value}". Allowed: ${VALID_CREATOR_VISIBILITIES.join(', ')}.`);
302
30
  }
303
- const distDir = rest[0] || 'dist';
304
- // 1. Offline preflight validation (fail fast before touching network!)
305
- const report = await validateProjectBundle({
306
- cwd: opts.cwd,
307
- distDir,
308
- manifestPath: manifestFlag.value,
309
- versionOverride: versionFlag.value,
310
- });
311
31
  const apiBase = await resolveApiBase(opts.apiBase);
312
- const token = await requireAuthToken({
313
- flagToken: opts.token,
314
- allowPublishEnvFallback: true,
315
- cwd: opts.cwd,
316
- });
317
- const slug = report.slug;
318
- const version = report.version;
319
- let createdSlot = false;
320
- // 2. If using an account key (RSKEY_ / RSSESS_), auto-register the game slot when new
321
- if (token.startsWith('RSKEY_') || token.startsWith('RSSESS_')) {
322
- const owned = await apiRequestJson({
323
- apiBase,
324
- method: 'GET',
325
- path: '/v1/creator/games',
326
- token,
327
- });
328
- const existsInAccount = (owned.games ?? []).some(g => g.slug === slug);
329
- if (!existsInAccount) {
330
- await apiRequestJson({
32
+ const token = await requireAuthToken({ flagToken: opts.token, cwd: opts.cwd });
33
+ const repoDir = path.dirname(resolvedManifestPath);
34
+ const mediaUploaded = [];
35
+ const nextManifest = {
36
+ ...manifest,
37
+ artwork: { ...manifest.artwork },
38
+ };
39
+ for (const slot of ['icon', 'cover', 'poster']) {
40
+ const rawRef = manifest.artwork[slot];
41
+ if (!rawRef)
42
+ continue;
43
+ const discovered = await discoverMediaFile(slot, rawRef, slug, repoDir);
44
+ if (discovered) {
45
+ const bytes = await readFile(discovered.absPath);
46
+ const uploaded = await apiRequestJson({
331
47
  apiBase,
332
- method: 'POST',
333
- path: '/v1/creator/games',
48
+ method: 'PUT',
49
+ path: `/v1/publish/${encodeURIComponent(slug)}/media/${encodeURIComponent(discovered.filename)}`,
334
50
  token,
335
- body: {
336
- slug,
337
- titleEn: report.manifest.locales.en.title,
338
- titleZh: report.manifest.locales['zh-Hans'].title,
339
- genre: report.manifest.genre,
340
- accentColor: report.manifest.accentColor,
341
- },
51
+ rawBody: bytes,
52
+ contentType: discovered.contentType,
342
53
  });
343
- createdSlot = true;
54
+ const canonicalUrl = uploaded.url || `/media/${slug}/${discovered.filename}`;
55
+ nextManifest.artwork[slot] = canonicalUrl;
56
+ mediaUploaded.push(canonicalUrl);
344
57
  }
345
58
  }
346
- // 3. Upload immutable bundle files concurrently
347
- await runPool(report.files, 8, async (file) => {
348
- const bytes = await readFile(file.absPath);
349
- const encodedRel = file.relPath.split('/').map(encodeURIComponent).join('/');
350
- await apiRequestJson({
351
- apiBase,
352
- method: 'PUT',
353
- path: `/v1/publish/${encodeURIComponent(slug)}/files/${encodeURIComponent(version)}/${encodedRel}`,
354
- token,
355
- rawBody: bytes,
356
- contentType: file.contentType,
357
- });
358
- });
359
- // 4. Upload discovered local artwork (<= 2 MB each)
360
- const mediaUploaded = [];
361
- for (const media of report.media) {
362
- const bytes = await readFile(media.absPath);
363
- await apiRequestJson({
364
- apiBase,
365
- method: 'PUT',
366
- path: `/v1/publish/${encodeURIComponent(slug)}/media/${encodeURIComponent(media.filename)}`,
367
- token,
368
- rawBody: bytes,
369
- contentType: media.contentType,
370
- });
371
- mediaUploaded.push(`/media/${slug}/${media.filename}`);
372
- }
373
- // 5. Finalize atomic pointer release
374
- const releaseRes = await apiRequestJson({
59
+ const res = await apiRequestJson({
375
60
  apiBase,
376
- method: 'POST',
377
- path: `/v1/publish/${encodeURIComponent(slug)}/release`,
61
+ method: 'PUT',
62
+ path: `/v1/creator/games/${encodeURIComponent(slug)}`,
378
63
  token,
379
64
  body: {
380
- version,
381
- manifest: report.manifest,
382
- fileCount: report.fileCount,
383
- totalBytes: report.totalBytes,
384
- ...(explicitVisibility ? { visibility: explicitVisibility } : {}),
65
+ manifest: nextManifest,
66
+ ...(visFlag.value ? { visibility: visFlag.value } : {}),
385
67
  },
386
68
  });
387
- // 6. Verify live edge health unless skipped
388
- let health = null;
389
- if (!skipHealthFlag.present && releaseRes.origin) {
390
- try {
391
- const probe = await fetch(`${releaseRes.origin}/_rs/health`);
392
- health = { ok: probe.ok, status: probe.status };
393
- }
394
- catch {
395
- health = { ok: false, status: 0 };
396
- }
397
- }
398
- const playUrl = releaseRes.playUrl || `${DEFAULT_PORTAL_ORIGIN}/play/${slug}`;
399
- const studioUrl = `${DEFAULT_STUDIO_ORIGIN}/games/${slug}`;
400
- const emulatorUrl = `${DEFAULT_STUDIO_ORIGIN}/emulator?game=${encodeURIComponent(slug)}`;
401
69
  emitSuccess(opts, {
402
70
  slug,
403
- version,
404
- releaseId: releaseRes.releaseId,
405
- visibility: releaseRes.visibility,
406
- createdSlot,
407
- playUrl,
408
- origin: releaseRes.origin,
409
- studioUrl,
410
- emulatorUrl,
411
- bundle: releaseRes.bundle ?? { fileCount: report.fileCount, totalBytes: report.totalBytes },
71
+ manifestPath: resolvedManifestPath,
412
72
  mediaUploaded,
413
- health,
414
- warnings: report.warnings,
415
- }, () => {
416
- const lines = [
417
- `Published ${slug} v${version} (${releaseRes.visibility})`,
418
- ` Play URL: ${playUrl}`,
419
- ` Game Origin: ${releaseRes.origin}`,
420
- ` Emulator: ${emulatorUrl}`,
421
- ` Bundle: ${report.fileCount} files (${formatBytes(report.totalBytes)})`,
422
- ];
423
- if (releaseRes.visibility === 'unlisted') {
424
- lines.push(` Preview: Unlisted (noindex, direct-link playable). Promote when ready with: replaystage visibility ${slug} live`);
425
- }
426
- return lines;
73
+ game: res.game,
74
+ }, () => [
75
+ `Updated metadata for "${slug}" from ${resolvedManifestPath}`,
76
+ ...(mediaUploaded.length > 0 ? [` Media synced: ${mediaUploaded.join(', ')}`] : []),
77
+ ]);
78
+ }
79
+ export async function cmdDelete(args, opts) {
80
+ const yesFlag = extractBoolFlag(args, ['--yes', '-y']);
81
+ assertNoUnknownFlags(yesFlag.rest);
82
+ const slug = yesFlag.rest[0]?.trim().toLowerCase();
83
+ if (!slug || !SLUG_RE.test(slug)) {
84
+ throw new CliError('INVALID_ARGUMENTS', 'Usage: replaystage delete <slug> --yes [--json]');
85
+ }
86
+ if (!yesFlag.present) {
87
+ throw new CliError('CONFIRMATION_REQUIRED', `Deleting "${slug}" removes its catalog entry, purges R2 releases/media, and revokes its CI tokens. Re-run with --yes to confirm.`);
88
+ }
89
+ const apiBase = await resolveApiBase(opts.apiBase);
90
+ const token = await requireAuthToken({ flagToken: opts.token, cwd: opts.cwd });
91
+ const res = await apiRequestJson({
92
+ apiBase,
93
+ method: 'DELETE',
94
+ path: `/v1/creator/games/${encodeURIComponent(slug)}`,
95
+ token,
427
96
  });
97
+ emitSuccess(opts, {
98
+ slug,
99
+ deleted: res.deleted ?? true,
100
+ ...(res.deletedR2Objects !== undefined ? { deletedR2Objects: res.deletedR2Objects } : {}),
101
+ }, () => [
102
+ `Deleted "${slug}", purged ${res.deletedR2Objects ?? 0} R2 asset(s), and revoked its scoped CI tokens.`,
103
+ ]);
428
104
  }
429
105
  export async function cmdGames(args, opts) {
430
106
  assertNoUnknownFlags(args);
@@ -446,48 +122,6 @@ export async function cmdGames(args, opts) {
446
122
  ];
447
123
  });
448
124
  }
449
- export async function cmdReleases(args, opts) {
450
- assertNoUnknownFlags(args);
451
- const slug = args[0]?.trim().toLowerCase();
452
- if (!slug || !SLUG_RE.test(slug)) {
453
- throw new CliError('INVALID_ARGUMENTS', 'Usage: replaystage releases <slug> [--json]');
454
- }
455
- const apiBase = await resolveApiBase(opts.apiBase);
456
- const token = await requireAuthToken({ flagToken: opts.token, cwd: opts.cwd });
457
- const data = await apiRequestJson({
458
- apiBase,
459
- method: 'GET',
460
- path: `/v1/creator/games/${encodeURIComponent(slug)}/releases`,
461
- token,
462
- });
463
- emitSuccess(opts, { slug, releases: data.releases }, () => [
464
- `Releases for ${slug}:`,
465
- ...(data.releases.length === 0
466
- ? [' (no releases published yet)']
467
- : data.releases.map(r => ` v${r.version.padEnd(14)} ${r.status.padEnd(10)} ${String(r.fileCount).padStart(4)} files ${formatBytes(r.totalBytes).padEnd(10)} ${r.createdAt}`)),
468
- ]);
469
- }
470
- export async function cmdRollback(args, opts) {
471
- assertNoUnknownFlags(args);
472
- const [slugRaw, versionRaw] = args;
473
- const slug = slugRaw?.trim().toLowerCase();
474
- const version = versionRaw?.trim();
475
- if (!slug || !SLUG_RE.test(slug) || !version) {
476
- throw new CliError('INVALID_ARGUMENTS', 'Usage: replaystage rollback <slug> <version> [--json]');
477
- }
478
- const apiBase = await resolveApiBase(opts.apiBase);
479
- const token = await requireAuthToken({ flagToken: opts.token, cwd: opts.cwd });
480
- const res = await apiRequestJson({
481
- apiBase,
482
- method: 'POST',
483
- path: `/v1/creator/games/${encodeURIComponent(slug)}/rollback`,
484
- token,
485
- body: { version },
486
- });
487
- emitSuccess(opts, { slug, version, ...res }, () => [
488
- `Rolled back ${slug} to v${version}.`,
489
- ]);
490
- }
491
125
  export async function cmdVisibility(args, opts) {
492
126
  assertNoUnknownFlags(args);
493
127
  const [slugRaw, visibilityRaw] = args;
package/dist/http.d.ts CHANGED
@@ -6,5 +6,9 @@ export interface ApiRequestOptions {
6
6
  body?: unknown;
7
7
  rawBody?: Uint8Array;
8
8
  contentType?: string;
9
+ /** Per-attempt timeout in milliseconds (default: 45s for binary uploads, 25s otherwise). */
10
+ timeoutMs?: number;
11
+ /** Maximum retries on transient network/timeout/429/5xx errors (default: 2 for idempotent methods, 0 for POST). */
12
+ retries?: number;
9
13
  }
10
14
  export declare function apiRequestJson<T = Record<string, unknown>>(opts: ApiRequestOptions): Promise<T>;