@joiner-platform/cli 0.0.0-stage → 0.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.
- package/README.md +30 -2
- package/bundled-resources/poe-tile-templates/base/CLAUDE.md +72 -0
- package/bundled-resources/poe-tile-templates/base/README.md +7 -0
- package/bundled-resources/poe-tile-templates/base/_bunfig.toml +8 -0
- package/bundled-resources/poe-tile-templates/base/_gitignore +18 -0
- package/bundled-resources/poe-tile-templates/base/client.ts +12 -0
- package/bundled-resources/poe-tile-templates/base/package.json +36 -0
- package/bundled-resources/poe-tile-templates/base/playwright.config.ts +38 -0
- package/bundled-resources/poe-tile-templates/base/scripts/check-source.ts +148 -0
- package/bundled-resources/poe-tile-templates/base/scripts/dev.ts +19 -0
- package/bundled-resources/poe-tile-templates/base/scripts/doctor.sh +29 -0
- package/bundled-resources/poe-tile-templates/base/scripts/visual-check.ts +64 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/backend-config.ts +9 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/client-config.ts +8 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/data/items.ts +16 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/index.ts +10 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/remove-todo.ts +5 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/set-todo.ts +20 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/types.ts +5 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators.test.ts +138 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/schema.ts +40 -0
- package/bundled-resources/poe-tile-templates/base/tests/e2e.test.playwright.ts +92 -0
- package/bundled-resources/poe-tile-templates/base/tests/mobile-viewport.test.playwright.ts +111 -0
- package/bundled-resources/poe-tile-templates/base/tests/render-check.test.playwright.ts +128 -0
- package/bundled-resources/poe-tile-templates/base/tests/screenshot.test.playwright.ts +86 -0
- package/bundled-resources/poe-tile-templates/base/tests/setup-dom.ts +70 -0
- package/bundled-resources/poe-tile-templates/base/tile/src/backend.ts +3 -0
- package/bundled-resources/poe-tile-templates/base/tile/styles.css +47 -0
- package/bundled-resources/poe-tile-templates/base/tsconfig.json +13 -0
- package/bundled-resources/poe-tile-templates/coverage.config.json +6 -0
- package/bundled-resources/poe-tile-templates/index.ts +27 -0
- package/bundled-resources/poe-tile-templates/package.json +31 -0
- package/bundled-resources/poe-tile-templates/phaserjs/package.partial.json +6 -0
- package/bundled-resources/poe-tile-templates/phaserjs/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/phaserjs/tile/src/entry.ts +35 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/App.test.happydom.tsx +98 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/App.ts +180 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/phaser-scene.ts +174 -0
- package/bundled-resources/poe-tile-templates/phaserjs/vite.config.ts +28 -0
- package/bundled-resources/poe-tile-templates/preact/package.partial.json +9 -0
- package/bundled-resources/poe-tile-templates/preact/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/preact/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/preact/tile/src/entry.tsx +36 -0
- package/bundled-resources/poe-tile-templates/preact/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/preact/tsconfig.json +15 -0
- package/bundled-resources/poe-tile-templates/preact/ui/App.test.happydom.tsx +69 -0
- package/bundled-resources/poe-tile-templates/preact/ui/App.tsx +116 -0
- package/bundled-resources/poe-tile-templates/preact/vite.config.ts +18 -0
- package/bundled-resources/poe-tile-templates/react/package.partial.json +12 -0
- package/bundled-resources/poe-tile-templates/react/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/react/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/react/tile/src/entry.tsx +38 -0
- package/bundled-resources/poe-tile-templates/react/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/react/tsconfig.json +14 -0
- package/bundled-resources/poe-tile-templates/react/ui/App.test.happydom.tsx +71 -0
- package/bundled-resources/poe-tile-templates/react/ui/App.tsx +110 -0
- package/bundled-resources/poe-tile-templates/react/vite.config.ts +21 -0
- package/bundled-resources/poe-tile-templates/scripts/cleanup.ts +10 -0
- package/bundled-resources/poe-tile-templates/scripts/generate.ts +57 -0
- package/bundled-resources/poe-tile-templates/scripts/install-diagnostics.ts +52 -0
- package/bundled-resources/poe-tile-templates/scripts/paths.ts +7 -0
- package/bundled-resources/poe-tile-templates/scripts/sdk-dependency-key.ts +288 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-all-sdks.ts +132 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-command.ts +30 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-tarball.ts +397 -0
- package/bundled-resources/poe-tile-templates/solidjs/_bunfig.toml +14 -0
- package/bundled-resources/poe-tile-templates/solidjs/package.partial.json +13 -0
- package/bundled-resources/poe-tile-templates/solidjs/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/solidjs/tests/solid-plugin.ts +49 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/src/entry.tsx +36 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/solidjs/tsconfig.json +15 -0
- package/bundled-resources/poe-tile-templates/solidjs/ui/App.test.happydom.tsx +70 -0
- package/bundled-resources/poe-tile-templates/solidjs/ui/App.tsx +129 -0
- package/bundled-resources/poe-tile-templates/solidjs/vite.config.ts +18 -0
- package/bundled-resources/poe-tile-templates/tests/check-source.test.ts +131 -0
- package/bundled-resources/poe-tile-templates/tests/dev-script.test.slow.ts +166 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/customized-manager.ts +67 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/extended-mutators.ts.txt +106 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/multiplayer-verification.test.playwright.ts.txt +103 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/replace-starter-schema.ts +67 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/phaserjs.tsx.txt +85 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/preact.tsx.txt +69 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/react.tsx.txt +73 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/seating.ts.txt +54 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/solidjs.tsx.txt +70 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/vanilla-js.tsx.txt +85 -0
- package/bundled-resources/poe-tile-templates/tests/generated-templates.test.ts +278 -0
- package/bundled-resources/poe-tile-templates/tests/happy-dom-version.test.ts +27 -0
- package/bundled-resources/poe-tile-templates/tests/install-diagnostics.test.ts +99 -0
- package/bundled-resources/poe-tile-templates/tests/native-gesture-defaults.test.ts +23 -0
- package/bundled-resources/poe-tile-templates/tests/playwright-version.test.ts +84 -0
- package/bundled-resources/poe-tile-templates/tests/render-check-scaffold.test.ts +56 -0
- package/bundled-resources/poe-tile-templates/tests/sdk-dependency-key.test.ts +129 -0
- package/bundled-resources/poe-tile-templates/tests/visual-check.test.ts +90 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/package.partial.json +3 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/tile/src/entry.ts +35 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.test.happydom.tsx +96 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.ts +113 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/vite.config.ts +17 -0
- package/cli.ts +134 -0
- package/index.ts +96 -0
- package/package.json +48 -5
- package/skills/audio-generation/.generated-by-poe-templated-docs +0 -0
- package/skills/audio-generation/SKILL.md +125 -0
- package/skills/finish-prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/finish-prototype/SKILL.md +22 -0
- package/skills/help-me-build/.generated-by-poe-templated-docs +0 -0
- package/skills/help-me-build/SKILL.md +56 -0
- package/skills/image-generation/.generated-by-poe-templated-docs +0 -0
- package/skills/image-generation/SKILL.md +128 -0
- package/skills/one-shot/.generated-by-poe-templated-docs +0 -0
- package/skills/one-shot/SKILL.md +22 -0
- package/skills/platform-prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/platform-prototype/SKILL.md +60 -0
- package/skills/platform-subagent/.generated-by-poe-templated-docs +0 -0
- package/skills/platform-subagent/SKILL.md +16 -0
- package/skills/poe-tiles-cli/.generated-by-poe-templated-docs +0 -0
- package/skills/poe-tiles-cli/SKILL.md +609 -0
- package/skills/poe-tiles-cli/references/device-motion.md +40 -0
- package/skills/poe-tiles-cli/references/player-updates.md +41 -0
- package/skills/prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/prototype/SKILL.md +149 -0
- package/skills/publish/.generated-by-poe-templated-docs +0 -0
- package/skills/publish/SKILL.md +73 -0
- package/skills/synced-store/.generated-by-poe-templated-docs +0 -0
- package/skills/synced-store/SKILL.md +583 -0
- package/skills/synced-store/references/actions.md +85 -0
- package/skills/synced-store/references/api-patterns.md +245 -0
- package/skills/synced-store/references/architecture-scaling-and-performance.md +280 -0
- package/skills/synced-store/references/client-api-reference.md +263 -0
- package/skills/synced-store/references/data-visibility.md +95 -0
- package/skills/synced-store/references/external-stores.md +162 -0
- package/skills/synced-store/references/file-uploads.md +216 -0
- package/skills/synced-store/references/getting-user-info-of-members.md +228 -0
- package/skills/synced-store/references/limitations.md +72 -0
- package/skills/synced-store/references/live-data-limit-hook.md +131 -0
- package/skills/synced-store/references/mutator-rules.md +169 -0
- package/skills/synced-store/references/platform.md +49 -0
- package/skills/synced-store/references/schema-and-bindings.md +85 -0
- package/skills/synced-store/references/schema-libraries.md +57 -0
- package/skills/synced-store/references/schema-migrations.md +119 -0
- package/skills/synced-store/references/searchable-tables.md +27 -0
- package/skills/synced-store/references/server-forking.md +115 -0
- package/skills/synced-store/references/singleton-tables.md +61 -0
- package/skills/synced-store/references/sort-keys.md +253 -0
- package/skills/synced-store/references/ui-patterns.md +95 -0
- package/skills/tile-creator/.generated-by-poe-templated-docs +0 -0
- package/skills/tile-creator/SKILL.md +197 -0
- package/skills/tile-creator/references/assets.md +124 -0
- package/skills/tile-creator/references/backend-api.md +354 -0
- package/skills/tile-creator/references/cli-limitations.md +64 -0
- package/skills/tile-creator/references/cli.md +604 -0
- package/skills/tile-creator/references/client-api.md +2407 -0
- package/skills/tile-creator/references/composing-apps.md +166 -0
- package/skills/tile-creator/references/e2e-tests.md +55 -0
- package/skills/tile-creator/references/game-ux-best-practices.md +57 -0
- package/skills/tile-creator/references/migrating-pre-rename-tiles.md +79 -0
- package/skills/tile-creator/references/multiplayer-api-recipe.md +205 -0
- package/skills/tile-creator/references/native-results.md +100 -0
- package/skills/tile-creator/references/platform-integration.md +201 -0
- package/skills/tile-creator/references/power-report.md +199 -0
- package/skills/tile-creator/references/publish-rollout.md +166 -0
- package/skills/tile-creator/references/publishing.md +33 -0
- package/skills/tile-creator/references/push-notification-guidelines.md +58 -0
- package/skills/tile-creator/references/render-check.md +266 -0
- package/skills/tile-creator/references/running-the-client-api-on-a-server-owned-by-the-user.md +95 -0
- package/skills/tile-creator/references/safe-area-insets.md +79 -0
- package/skills/tile-creator/references/sandbox-limitations.md +32 -0
- package/skills/tile-creator/references/scaffolded-tile-folder-structure.md +48 -0
- package/skills/tile-creator/references/scaffolding-a-new-app.md +202 -0
- package/skills/tile-creator/references/simulations.md +125 -0
- package/skills/tile-creator/references/synced-store-client-reference.md +92 -0
- package/skills/tile-creator/references/troubleshooting.md +22 -0
- package/skills/tile-creator/references/turn-based-mutator.md +43 -0
- package/skills/tile-creator/references/user-erasure.md +14 -0
- package/skills/tile-creator/references/vite-plugin.md +166 -0
- package/skills/tile-creator/references/workspace-retention.md +72 -0
- package/src/admin-conversions-client.ts +28 -0
- package/src/admin-reviews-client.ts +36 -0
- package/src/api.generated.ts +1527 -0
- package/src/auth-token.ts +198 -0
- package/src/bounded-read.ts +35 -0
- package/src/bun-version.ts +33 -0
- package/src/checkout-base.ts +207 -0
- package/src/cli-bun-version.ts +16 -0
- package/src/cli-env.ts +28 -0
- package/src/cli-name.ts +23 -0
- package/src/client.ts +2474 -0
- package/src/collect-files.ts +226 -0
- package/src/commands/accounts.ts +55 -0
- package/src/commands/admin-abandon-conversion.ts +60 -0
- package/src/commands/admin-reviews.ts +66 -0
- package/src/commands/admin.ts +219 -0
- package/src/commands/auth.ts +89 -0
- package/src/commands/checkout-prototype.ts +67 -0
- package/src/commands/creator-source-capability.ts +11 -0
- package/src/commands/doctor-bun.ts +145 -0
- package/src/commands/doctor-command.ts +64 -0
- package/src/commands/doctor-package-json.ts +47 -0
- package/src/commands/doctor-sdk-pin.ts +156 -0
- package/src/commands/doctor-store-keys-lexer.ts +213 -0
- package/src/commands/doctor-store-keys-scan.ts +262 -0
- package/src/commands/doctor-store-keys.ts +196 -0
- package/src/commands/doctor.ts +371 -0
- package/src/commands/init/blank-scaffold-templates.ts +397 -0
- package/src/commands/init/index.ts +170 -0
- package/src/commands/init/internal-toolchain.ts +49 -0
- package/src/commands/init/manager-test-template.ts +107 -0
- package/src/commands/init/multiplayer-test-template.ts +217 -0
- package/src/commands/init/name-input.tsx +167 -0
- package/src/commands/init/no-store-scaffold-templates.ts +281 -0
- package/src/commands/init/no-store-scaffold.ts +134 -0
- package/src/commands/init/package-json-scripts.ts +72 -0
- package/src/commands/init/scaffold.ts +960 -0
- package/src/commands/init/sdk-tarball-url.generated.ts +4 -0
- package/src/commands/init/sdk-tarball-url.ts +31 -0
- package/src/commands/init/template-picker.tsx +147 -0
- package/src/commands/inspect-child-entry.ts +107 -0
- package/src/commands/inspect-contract.ts +87 -0
- package/src/commands/inspect-freshness.ts +217 -0
- package/src/commands/inspect-lock.ts +201 -0
- package/src/commands/inspect-options.ts +360 -0
- package/src/commands/inspect-orchestrate.ts +375 -0
- package/src/commands/inspect-process.ts +172 -0
- package/src/commands/inspect-ready.ts +65 -0
- package/src/commands/inspect-report.ts +235 -0
- package/src/commands/inspect-run-state.ts +296 -0
- package/src/commands/inspect-run.ts +157 -0
- package/src/commands/inspect-watchdog.ts +74 -0
- package/src/commands/install-joiner.ts +208 -0
- package/src/commands/login.ts +308 -0
- package/src/commands/models.ts +40 -0
- package/src/commands/parse-options.ts +36 -0
- package/src/commands/remix-package-json.ts +64 -0
- package/src/commands/remix.ts +379 -0
- package/src/commands/sdk-url.ts +141 -0
- package/src/commands/simulations.ts +133 -0
- package/src/commands/skills.ts +108 -0
- package/src/commands/store-files.ts +92 -0
- package/src/commands/stores.ts +703 -0
- package/src/commands/tiles-channel-commands.ts +115 -0
- package/src/commands/tiles-checkout.ts +351 -0
- package/src/commands/tiles-gallery-command.ts +95 -0
- package/src/commands/tiles-get-helpers.ts +27 -0
- package/src/commands/tiles-inspect.ts +276 -0
- package/src/commands/tiles-power-command.ts +308 -0
- package/src/commands/tiles-power-format.ts +396 -0
- package/src/commands/tiles-power-versions.ts +299 -0
- package/src/commands/tiles-publish-helpers.ts +145 -0
- package/src/commands/tiles-upload-command.ts +277 -0
- package/src/commands/tiles-version-commands.ts +201 -0
- package/src/commands/tiles-visibility-command.ts +103 -0
- package/src/commands/tiles.ts +257 -0
- package/src/commands/upgrade.ts +307 -0
- package/src/commit-in-progress.ts +42 -0
- package/src/creator-source-context.ts +97 -0
- package/src/creator-source-publish.ts +52 -0
- package/src/deferred-assets.ts +125 -0
- package/src/distribution.ts +28 -0
- package/src/errors.ts +61 -0
- package/src/install-command.ts +43 -0
- package/src/output.ts +62 -0
- package/src/poe-tile-config-files.ts +100 -0
- package/src/poe-tile-config-players.ts +168 -0
- package/src/poe-tile-config-remix.ts +166 -0
- package/src/poe-tile-config.ts +831 -0
- package/src/power-report-client.ts +55 -0
- package/src/prototype-startup.ts +21 -0
- package/src/publish-change-summary.ts +55 -0
- package/src/publish-overrides-validation.ts +49 -0
- package/src/publish-pack.ts +167 -0
- package/src/publish-phases.ts +57 -0
- package/src/publish-retry.ts +51 -0
- package/src/publish-tile-from-config.ts +434 -0
- package/src/recorder-stream.ts +169 -0
- package/src/remix-provenance.ts +156 -0
- package/src/resolve-client-credential.ts +71 -0
- package/src/resolve-media-uploads.ts +147 -0
- package/src/sdk-dependency.ts +54 -0
- package/src/sdk-skills.ts +85 -0
- package/src/should-skip-client-setup.ts +20 -0
- package/src/simulation-snapshot.ts +123 -0
- package/src/simulation-types.ts +74 -0
- package/src/simulations-client.ts +112 -0
- package/src/source-bundle.ts +466 -0
- package/src/staged-publish-cleanup.ts +44 -0
- package/src/staged-publish-deferred.ts +160 -0
- package/src/staged-publish.ts +401 -0
- package/src/store-file-upload.ts +268 -0
- package/src/store-request.ts +168 -0
- package/src/tar-canonical.ts +41 -0
- package/src/tar-extensions.ts +159 -0
- package/src/tar-extract.ts +193 -0
- package/src/tar-parse.ts +224 -0
- package/src/tar.ts +231 -0
- package/src/template-check-scripts.ts +18 -0
- package/src/tile-gallery-client.ts +82 -0
- package/src/types.ts +258 -0
- package/src/upload-concurrency.ts +54 -0
- package/src/whole-tile.ts +52 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// owner: aaronroe
|
|
2
|
+
|
|
3
|
+
// A retried commit often lands while the attempt whose response was lost is
|
|
4
|
+
// still running, and the server refuses it with `publish_commit_in_progress`.
|
|
5
|
+
// If that attempt succeeds, asking again replays its stored result; if it
|
|
6
|
+
// fails, the server releases the claim and the next ask runs the commit again,
|
|
7
|
+
// so this is not an idempotency guarantee. About a
|
|
8
|
+
// minute covers a slow commit; a claim held longer than that belongs to a dead
|
|
9
|
+
// worker, and only a fresh publish id gets past it.
|
|
10
|
+
const COMMIT_IN_PROGRESS_WAITS_MS = [
|
|
11
|
+
1_000, 2_000, 4_000, 8_000, 15_000, 15_000, 15_000,
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
export async function conflictCode(response: Response): Promise<unknown> {
|
|
15
|
+
if (response.status !== 409) return undefined;
|
|
16
|
+
const payload = (await response
|
|
17
|
+
.clone()
|
|
18
|
+
.json()
|
|
19
|
+
.catch(() => null)) as { code?: unknown } | null;
|
|
20
|
+
return payload?.code;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function wallClockSleep(ms: number): Promise<void> {
|
|
24
|
+
// biome-ignore lint: a commit still running server-side needs real wall-clock time to finish.
|
|
25
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function awaitCommitInProgress(
|
|
29
|
+
response: Response,
|
|
30
|
+
commitRequest: () => Promise<Response>,
|
|
31
|
+
sleep: (ms: number) => Promise<void>,
|
|
32
|
+
): Promise<Response> {
|
|
33
|
+
let latest = response;
|
|
34
|
+
for (const waitMs of COMMIT_IN_PROGRESS_WAITS_MS) {
|
|
35
|
+
// biome-ignore lint/performance/noAwaitInLoops: polling is sequential by design; each attempt depends on the previous answer.
|
|
36
|
+
if ((await conflictCode(latest)) !== "publish_commit_in_progress") break;
|
|
37
|
+
// biome-ignore lint: each wait must elapse before the next commit attempt; the backoff is the point.
|
|
38
|
+
await sleep(waitMs);
|
|
39
|
+
latest = await commitRequest();
|
|
40
|
+
}
|
|
41
|
+
return latest;
|
|
42
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// owner: aaronroe
|
|
2
|
+
|
|
3
|
+
import { CliError } from "./errors.js";
|
|
4
|
+
|
|
5
|
+
export const CREATOR_SOURCE_CONTEXT_ENV = "POE_CREATOR_SOURCE_CONTEXT";
|
|
6
|
+
export const CREATOR_SOURCE_CONTEXT_MAX_BYTES = 4_096;
|
|
7
|
+
|
|
8
|
+
export type CreatorSourceMode = "edit" | "remix";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Read only the mode needed by the CLI. The sandbox validates and renders the
|
|
12
|
+
* complete structured context before Claude starts; the server remains the
|
|
13
|
+
* authority for every publish target and permission.
|
|
14
|
+
*/
|
|
15
|
+
export function readCreatorSourceMode(
|
|
16
|
+
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
17
|
+
): CreatorSourceMode | null {
|
|
18
|
+
const raw = env[CREATOR_SOURCE_CONTEXT_ENV];
|
|
19
|
+
if (raw === undefined) return null;
|
|
20
|
+
if (Buffer.byteLength(raw, "utf8") > CREATOR_SOURCE_CONTEXT_MAX_BYTES) {
|
|
21
|
+
throw new CliError(
|
|
22
|
+
`${CREATOR_SOURCE_CONTEXT_ENV} exceeds ${CREATOR_SOURCE_CONTEXT_MAX_BYTES} bytes.`,
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let parsed: unknown;
|
|
27
|
+
try {
|
|
28
|
+
parsed = JSON.parse(raw);
|
|
29
|
+
} catch {
|
|
30
|
+
throw new CliError(`${CREATOR_SOURCE_CONTEXT_ENV} is not valid JSON.`);
|
|
31
|
+
}
|
|
32
|
+
if (
|
|
33
|
+
!isRecord(parsed) ||
|
|
34
|
+
(parsed["mode"] !== "edit" && parsed["mode"] !== "remix")
|
|
35
|
+
) {
|
|
36
|
+
throw new CliError(
|
|
37
|
+
`${CREATOR_SOURCE_CONTEXT_ENV} must identify an Edit or Remix session.`,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return parsed["mode"];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The branch point a Remix session was launched from, as recorded in the
|
|
45
|
+
* sandbox-supplied context.
|
|
46
|
+
*/
|
|
47
|
+
export type CreatorSourceRemixProvenance = {
|
|
48
|
+
tileId: string;
|
|
49
|
+
versionNumber: number;
|
|
50
|
+
sourceBundleId: string;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Read the Remix session's branch point out of the same structured context
|
|
55
|
+
* {@link readCreatorSourceMode} parses, so `remix --local-archive` can stamp
|
|
56
|
+
* `remixOf` into the extracted config.
|
|
57
|
+
*
|
|
58
|
+
* Returns `null` whenever provenance can't be recorded — no context, an Edit
|
|
59
|
+
* session (an edit republishes the same app, so it is never its own remix), or
|
|
60
|
+
* a `source` block missing/malforming any of the three fields. Absent
|
|
61
|
+
* provenance costs attribution, never the extraction, so this reports nothing
|
|
62
|
+
* and lets the caller continue. It deliberately does NOT throw on a malformed
|
|
63
|
+
* `source`: the sandbox validates the context it renders, and an older sandbox
|
|
64
|
+
* simply won't carry `sourceBundleId` yet.
|
|
65
|
+
*/
|
|
66
|
+
export function readCreatorSourceRemixProvenance(
|
|
67
|
+
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
68
|
+
): CreatorSourceRemixProvenance | null {
|
|
69
|
+
const raw = env[CREATOR_SOURCE_CONTEXT_ENV];
|
|
70
|
+
if (raw === undefined) return null;
|
|
71
|
+
let parsed: unknown;
|
|
72
|
+
try {
|
|
73
|
+
parsed = JSON.parse(raw);
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
if (!isRecord(parsed) || parsed["mode"] !== "remix") return null;
|
|
78
|
+
const source = parsed["source"];
|
|
79
|
+
if (!isRecord(source)) return null;
|
|
80
|
+
const { tileId, versionNumber, sourceBundleId } = source;
|
|
81
|
+
if (
|
|
82
|
+
typeof tileId !== "string" ||
|
|
83
|
+
tileId.length === 0 ||
|
|
84
|
+
typeof versionNumber !== "number" ||
|
|
85
|
+
!Number.isSafeInteger(versionNumber) ||
|
|
86
|
+
versionNumber < 1 ||
|
|
87
|
+
typeof sourceBundleId !== "string" ||
|
|
88
|
+
sourceBundleId.length === 0
|
|
89
|
+
) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
return { tileId, versionNumber, sourceBundleId };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
96
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
97
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// owner: aaronroe
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The extra intent a publish carries inside a platform Edit session.
|
|
5
|
+
*
|
|
6
|
+
* `--edit-visibility` used to live here and no longer does. Publishing a bundle
|
|
7
|
+
* and deciding who can find a tile are separate operations — `poe-tiles tiles
|
|
8
|
+
* visibility` is the one that changes discovery — and finalizing an Edit is a
|
|
9
|
+
* publish like any other.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { EditSourcePublishIntent } from "./client.js";
|
|
13
|
+
import { readCreatorSourceMode } from "./creator-source-context.js";
|
|
14
|
+
import { CliError } from "./errors.js";
|
|
15
|
+
import { describeInvalidTileHandle } from "./poe-tile-config.js";
|
|
16
|
+
|
|
17
|
+
export interface CreatorSourcePublishOverrides {
|
|
18
|
+
finalizeEdit?: boolean;
|
|
19
|
+
editHandle?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function resolveEditSourcePublishIntent(
|
|
23
|
+
overrides: CreatorSourcePublishOverrides,
|
|
24
|
+
): EditSourcePublishIntent | undefined {
|
|
25
|
+
if (!hasEditIntent(overrides)) return undefined;
|
|
26
|
+
if (readCreatorSourceMode() !== "edit") {
|
|
27
|
+
throw new CliError(
|
|
28
|
+
"Edit finalization options are available only inside a platform Edit session.",
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
if (!overrides.finalizeEdit) {
|
|
32
|
+
throw new CliError("--edit-handle requires --finalize-edit.");
|
|
33
|
+
}
|
|
34
|
+
if (overrides.editHandle !== undefined) {
|
|
35
|
+
const problem = describeInvalidTileHandle(overrides.editHandle);
|
|
36
|
+
if (problem !== undefined) {
|
|
37
|
+
throw new CliError(
|
|
38
|
+
`Invalid Edit handle "${overrides.editHandle}": ${problem}.`,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
finalizeEdit: true,
|
|
44
|
+
...(overrides.editHandle === undefined
|
|
45
|
+
? undefined
|
|
46
|
+
: { handle: overrides.editHandle }),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function hasEditIntent(overrides: CreatorSourcePublishOverrides): boolean {
|
|
51
|
+
return overrides.finalizeEdit === true || overrides.editHandle !== undefined;
|
|
52
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The publisher's half of deferred bundle assets: every client file under
|
|
5
|
+
* `deferred/` leaves the tar, and the tar gains `.poe-deferred.json`, the
|
|
6
|
+
* index of their hashes and sizes. The tar then depends on no upload, so it
|
|
7
|
+
* and the deferred files upload side by side.
|
|
8
|
+
*
|
|
9
|
+
* Mirrors `partitionDeferredAssets` and `serializeDeferredIndex` in
|
|
10
|
+
* `packages/poe-tiles-kernel/src/tile-deferred-assets.ts`. Duplicated rather
|
|
11
|
+
* than imported because the CLI ships its sources with no workspace runtime
|
|
12
|
+
* dependency (`packaging.test.ts`); `deferred-assets.test.ts` holds the two
|
|
13
|
+
* to the same answers and the same index bytes.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { createHash } from "node:crypto";
|
|
17
|
+
|
|
18
|
+
const MANIFEST_PATH = ".poe-tile-runtime.json";
|
|
19
|
+
const DEFERRED_PREFIX = "deferred/";
|
|
20
|
+
export const DEFERRED_INDEX_PATH = ".poe-deferred.json";
|
|
21
|
+
const MIN_KERNEL_VERSION = 67;
|
|
22
|
+
const MAX_FILES = 1000;
|
|
23
|
+
const MAX_FILE_BYTES = 50 * 1024 * 1024;
|
|
24
|
+
const MAX_TOTAL_BYTES = 250 * 1024 * 1024;
|
|
25
|
+
const MAX_PATH_BYTES = 1024;
|
|
26
|
+
const JSON_ESCAPED_CHARACTER = /["\\\u0000-\u001f\u007f]/;
|
|
27
|
+
|
|
28
|
+
export type DeferredPartition = {
|
|
29
|
+
/** Files the tar keeps, the index among them. */
|
|
30
|
+
kept: Map<string, Uint8Array>;
|
|
31
|
+
/** Files to upload one by one, keyed by bundle path. */
|
|
32
|
+
deferred: Map<string, Uint8Array>;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function checkPath(path: string): void {
|
|
36
|
+
if (
|
|
37
|
+
new TextEncoder().encode(path).byteLength > MAX_PATH_BYTES ||
|
|
38
|
+
JSON_ESCAPED_CHARACTER.test(path) ||
|
|
39
|
+
path.split("/").some((part) => part === "" || part === "." || part === "..")
|
|
40
|
+
)
|
|
41
|
+
throw new Error(
|
|
42
|
+
`Invalid deferred asset path ${JSON.stringify(path)}; it must be a file under ${DEFERRED_PREFIX}, at most ${MAX_PATH_BYTES} UTF-8 bytes, without control characters, quotes or backslashes`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function checkLimits(deferred: ReadonlyMap<string, Uint8Array>): void {
|
|
47
|
+
if (deferred.size > MAX_FILES)
|
|
48
|
+
throw new Error(
|
|
49
|
+
`${deferred.size} deferred files; the limit is ${MAX_FILES}`,
|
|
50
|
+
);
|
|
51
|
+
let totalBytes = 0;
|
|
52
|
+
for (const [path, data] of deferred) {
|
|
53
|
+
if (data.byteLength === 0)
|
|
54
|
+
throw new Error(
|
|
55
|
+
`Deferred file ${path} is empty; remove it or move it out of ${DEFERRED_PREFIX}`,
|
|
56
|
+
);
|
|
57
|
+
if (data.byteLength > MAX_FILE_BYTES)
|
|
58
|
+
throw new Error(
|
|
59
|
+
`Deferred file ${path} is ${data.byteLength} bytes; the limit is ${MAX_FILE_BYTES}`,
|
|
60
|
+
);
|
|
61
|
+
totalBytes += data.byteLength;
|
|
62
|
+
}
|
|
63
|
+
if (totalBytes > MAX_TOTAL_BYTES)
|
|
64
|
+
throw new Error(
|
|
65
|
+
`Deferred files total ${totalBytes} bytes; the limit is ${MAX_TOTAL_BYTES}`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function requireKernel(manifest: Uint8Array | undefined): void {
|
|
70
|
+
const minimum =
|
|
71
|
+
manifest === undefined
|
|
72
|
+
? null
|
|
73
|
+
: (
|
|
74
|
+
JSON.parse(new TextDecoder().decode(manifest)) as {
|
|
75
|
+
minKernelVersion?: unknown;
|
|
76
|
+
}
|
|
77
|
+
).minKernelVersion;
|
|
78
|
+
if (typeof minimum === "number" && minimum >= MIN_KERNEL_VERSION) return;
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Deferred assets need Joiner kernel ${MIN_KERNEL_VERSION}, but this bundle declares minimum ${
|
|
81
|
+
typeof minimum === "number" ? minimum : "none"
|
|
82
|
+
}. Upgrade the SDK (joiner-sdk, or poe-tiles-sdk in older tiles) and rebuild; its Vite plugin raises the minimum for you.`,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The index text: one object, keys sorted, as `serializeDeferredIndex` writes it. */
|
|
87
|
+
export function serializeDeferredIndex(
|
|
88
|
+
deferred: ReadonlyMap<string, Uint8Array>,
|
|
89
|
+
): string {
|
|
90
|
+
const files: Record<string, { sha256: string; size: number }> = {};
|
|
91
|
+
for (const path of [...deferred.keys()].sort()) {
|
|
92
|
+
const data = deferred.get(path) as Uint8Array;
|
|
93
|
+
files[path] = {
|
|
94
|
+
sha256: createHash("sha256").update(data).digest("hex"),
|
|
95
|
+
size: data.byteLength,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return JSON.stringify({ files });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Split client files by the `deferred/` prefix, limits checked, and add the
|
|
103
|
+
* index to the kept files. Null when no file is deferred. O(deferred bytes).
|
|
104
|
+
*/
|
|
105
|
+
export function partitionDeferredFiles(
|
|
106
|
+
files: ReadonlyMap<string, Uint8Array>,
|
|
107
|
+
): DeferredPartition | null {
|
|
108
|
+
if (files.has(DEFERRED_INDEX_PATH))
|
|
109
|
+
throw new Error(
|
|
110
|
+
`${DEFERRED_INDEX_PATH} is written by the publisher; remove it from the build`,
|
|
111
|
+
);
|
|
112
|
+
const kept = new Map<string, Uint8Array>();
|
|
113
|
+
const deferred = new Map<string, Uint8Array>();
|
|
114
|
+
for (const [path, data] of files)
|
|
115
|
+
(path.startsWith(DEFERRED_PREFIX) ? deferred : kept).set(path, data);
|
|
116
|
+
if (deferred.size === 0) return null;
|
|
117
|
+
for (const path of deferred.keys()) checkPath(path);
|
|
118
|
+
checkLimits(deferred);
|
|
119
|
+
requireKernel(files.get(MANIFEST_PATH));
|
|
120
|
+
kept.set(
|
|
121
|
+
DEFERRED_INDEX_PATH,
|
|
122
|
+
new TextEncoder().encode(serializeDeferredIndex(deferred)),
|
|
123
|
+
);
|
|
124
|
+
return { kept, deferred };
|
|
125
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
/**
|
|
3
|
+
* Which published package this CLI was installed from.
|
|
4
|
+
*
|
|
5
|
+
* The same sources ship twice: as the `@ai-app/poe-tiles-cli` tarball on the
|
|
6
|
+
* upload host (bin `poe-tiles`, plus the opt-in `joiner` launcher), and as
|
|
7
|
+
* `@joiner-platform/cli` on npm (bins `joiner` and `poe-tiles`). `scripts/publish-npm.ts`
|
|
8
|
+
* rewrites the tarball's manifest for npm, so the package's own name says
|
|
9
|
+
* which one is running.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// A static import, not a file read: bundles that embed the CLI client (the
|
|
13
|
+
// Creator bridge) carry no package.json beside them, so Bun must inline it.
|
|
14
|
+
// Run from source, as the installed package is, it loads the package's own
|
|
15
|
+
// manifest, which publish-npm.ts rewrites.
|
|
16
|
+
import ownManifest from "../package.json" with { type: "json" };
|
|
17
|
+
|
|
18
|
+
export const NPM_PACKAGE_NAME = "@joiner-platform/cli";
|
|
19
|
+
|
|
20
|
+
export type CliDistribution = "npm" | "tarball";
|
|
21
|
+
|
|
22
|
+
export const CLI_VERSION = ownManifest.version;
|
|
23
|
+
|
|
24
|
+
export function cliDistribution(
|
|
25
|
+
packageName: string = ownManifest.name,
|
|
26
|
+
): CliDistribution {
|
|
27
|
+
return packageName === NPM_PACKAGE_NAME ? "npm" : "tarball";
|
|
28
|
+
}
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
/**
|
|
3
|
+
* CLI-specific error handling.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { ApiResult } from "./types.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Error class for expected, user-facing errors.
|
|
10
|
+
* These are caught at the top level and printed without a stack trace.
|
|
11
|
+
*/
|
|
12
|
+
export class CliError extends Error {
|
|
13
|
+
/**
|
|
14
|
+
* When true, this is a permanent local/config condition (e.g. not logged in,
|
|
15
|
+
* no session cookie) that retrying cannot fix. Callers with a reconnect/retry
|
|
16
|
+
* loop must surface it immediately instead of backing off — otherwise the
|
|
17
|
+
* user waits through minutes of misleading "connection attempt failed" spam
|
|
18
|
+
* before a config error they could have seen at once. Defaults to false
|
|
19
|
+
* (transient/unknown → safe to retry).
|
|
20
|
+
*/
|
|
21
|
+
readonly nonRetryable: boolean;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The HTTP status of the API response this error reports, when it reports
|
|
25
|
+
* one. A command that explains a status in its own words (the power
|
|
26
|
+
* report's "not one of your tiles") branches on this, never on the message
|
|
27
|
+
* text, which carries the server's wording.
|
|
28
|
+
*/
|
|
29
|
+
readonly status: number | undefined;
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
message: string,
|
|
33
|
+
options?: { nonRetryable?: boolean; status?: number },
|
|
34
|
+
) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = "CliError";
|
|
37
|
+
this.nonRetryable = options?.nonRetryable ?? false;
|
|
38
|
+
this.status = options?.status;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* True when `error` is a {@link CliError} tagged non-retryable — a permanent
|
|
44
|
+
* local/config failure a retry loop should rethrow immediately rather than
|
|
45
|
+
* back off on.
|
|
46
|
+
*/
|
|
47
|
+
export function isNonRetryableError(error: unknown): boolean {
|
|
48
|
+
return error instanceof CliError && error.nonRetryable;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Type-narrowing assertion that throws CliError on API failure.
|
|
53
|
+
* After this call, `result` is narrowed to the success branch.
|
|
54
|
+
*/
|
|
55
|
+
export function assertSuccess<T>(
|
|
56
|
+
result: ApiResult<T>,
|
|
57
|
+
): asserts result is T & { success: true } {
|
|
58
|
+
if (!result.success) {
|
|
59
|
+
throw new CliError(result.error);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Format the shell snippet that consumers run to install the published CLI
|
|
5
|
+
* tarball globally. Shared between publish-tar.ts (writes the snippet into
|
|
6
|
+
* docs and prints it to the operator) and install-command.test.slow.ts
|
|
7
|
+
* (verifies the snippet survives reinstalls across tarball URLs).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const PACKAGE_NAME = "@ai-app/poe-tiles-cli";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Bun 1.3.11's global install treats two different tarball URLs of the same package
|
|
14
|
+
* name as conflicting "different versions" and rejects the second one with
|
|
15
|
+
* `error: ... has a dependency loop`. Reinstalling the CLI on top of a
|
|
16
|
+
* previously-published URL is the common case for end users, so the snippet
|
|
17
|
+
* uninstalls the old install first (no-op when nothing is installed) before
|
|
18
|
+
* `bun install -g`. `2>/dev/null` swallows the "No package.json, so nothing
|
|
19
|
+
* to remove" notice Bun prints on a fresh machine.
|
|
20
|
+
*/
|
|
21
|
+
export function formatInstallCommand(url: string): string {
|
|
22
|
+
return `bun remove -g ${PACKAGE_NAME} 2>/dev/null; bun install -g ${url}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The launcher step. It runs the `poe-tiles` in Bun's global bin, the copy the
|
|
27
|
+
* install step just wrote, not whatever `poe-tiles` comes first on PATH (an
|
|
28
|
+
* older launcher or a monorepo wrapper would refuse), and it works when that
|
|
29
|
+
* directory is not on PATH at all.
|
|
30
|
+
*/
|
|
31
|
+
export const LAUNCHER_SETUP_COMMAND =
|
|
32
|
+
'"$(bun pm bin -g)/poe-tiles" install-joiner';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The documented install command: install the CLI, then add the `joiner`
|
|
36
|
+
* launcher, so a fresh install has both commands at once. The published
|
|
37
|
+
* package keeps only the `poe-tiles` bin (see `install-joiner.ts`). The
|
|
38
|
+
* launcher step is its own line, so the install line's exit status still
|
|
39
|
+
* reflects the install alone.
|
|
40
|
+
*/
|
|
41
|
+
export function formatSetupCommand(url: string): string {
|
|
42
|
+
return `${formatInstallCommand(url)}\n${LAUNCHER_SETUP_COMMAND}`;
|
|
43
|
+
}
|
package/src/output.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
/**
|
|
3
|
+
* Output formatters and CLI display utilities.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Command } from "commander";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Check if --json flag is set on the root command.
|
|
10
|
+
*/
|
|
11
|
+
export function isJsonMode(cmd: Command): boolean {
|
|
12
|
+
let root: Command = cmd;
|
|
13
|
+
while (root.parent) {
|
|
14
|
+
root = root.parent;
|
|
15
|
+
}
|
|
16
|
+
const opts = root.opts() as Record<string, unknown>;
|
|
17
|
+
return opts["json"] === true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Print key-value pairs for single-object results.
|
|
22
|
+
*/
|
|
23
|
+
export function printKeyValue(
|
|
24
|
+
rows: [string, string | number | undefined][],
|
|
25
|
+
): void {
|
|
26
|
+
const maxKeyLen = Math.max(...rows.map(([k]) => k.length));
|
|
27
|
+
for (const [key, value] of rows) {
|
|
28
|
+
console.log(` ${key.padEnd(maxKeyLen)} ${value ?? ""}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Print a table for list results.
|
|
34
|
+
*/
|
|
35
|
+
export function printTable(options: {
|
|
36
|
+
headers: string[];
|
|
37
|
+
rows: (string | number)[][];
|
|
38
|
+
}): void {
|
|
39
|
+
const { headers, rows } = options;
|
|
40
|
+
const colWidths = headers.map((h, i) =>
|
|
41
|
+
Math.max(h.length, ...rows.map((r) => String(r[i] ?? "").length)),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const headerLine = headers.map((h, i) => h.padEnd(colWidths[i]!)).join(" ");
|
|
45
|
+
const separator = colWidths.map((w) => "-".repeat(w)).join(" ");
|
|
46
|
+
|
|
47
|
+
console.log(headerLine);
|
|
48
|
+
console.log(separator);
|
|
49
|
+
for (const row of rows) {
|
|
50
|
+
const line = row
|
|
51
|
+
.map((cell, i) => String(cell).padEnd(colWidths[i]!))
|
|
52
|
+
.join(" ");
|
|
53
|
+
console.log(line);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Print data as JSON (for --json flag).
|
|
59
|
+
*/
|
|
60
|
+
export function printJson(data: unknown): void {
|
|
61
|
+
console.log(JSON.stringify(data, null, 2));
|
|
62
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { lstatSync, statSync } from "node:fs";
|
|
2
|
+
import { readBoundedText } from "./bounded-read.js";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { isDeepStrictEqual } from "node:util";
|
|
5
|
+
import type {
|
|
6
|
+
PoeTileConfig,
|
|
7
|
+
ReadPoeTileConfigResult,
|
|
8
|
+
} from "./poe-tile-config.js";
|
|
9
|
+
|
|
10
|
+
export const LEGACY_PUBLISH_CONFIG_FILENAME = ".poe-app.json";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A config is a few KB of JSON; anything past this is not one, and is refused
|
|
14
|
+
* by its size before it is read (see `bounded-read.ts`).
|
|
15
|
+
*/
|
|
16
|
+
export const CONFIG_FILE_MAX_BYTES = 256 * 1024;
|
|
17
|
+
|
|
18
|
+
export const POE_APP_CONFIG_SCHEMA_URLS_V2 = [
|
|
19
|
+
"https://poe-app-platform-docs.pages.dev/schemas/poe-app/v2.json",
|
|
20
|
+
"https://poe-tiles-docs.pages.dev/schemas/poe-app/v2.json",
|
|
21
|
+
] as const;
|
|
22
|
+
|
|
23
|
+
function describeError(error: unknown): string {
|
|
24
|
+
return error instanceof Error ? error.message : String(error);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function comparableFields(parsed: unknown): unknown {
|
|
28
|
+
return parsed !== null && typeof parsed === "object"
|
|
29
|
+
? Object.fromEntries(
|
|
30
|
+
Object.entries(parsed).filter(([name]) => name !== "$schema"),
|
|
31
|
+
)
|
|
32
|
+
: parsed;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Refused before it is opened: a named pipe with no writer blocks the process
|
|
37
|
+
* on open, and a directory or device is not a config. `stat` follows a
|
|
38
|
+
* symlink, so a link to one of those is refused too; a link to nothing falls
|
|
39
|
+
* through to the read's own ENOENT.
|
|
40
|
+
*/
|
|
41
|
+
function refuseSpecialFile(filename: string, path: string): void {
|
|
42
|
+
const target = statSync(path, { throwIfNoEntry: false });
|
|
43
|
+
if (target && !target.isFile()) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
`Failed to read ${filename} at ${path}: not a regular file. The config must be a plain JSON file.`,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function readPoeTileConfigFiles(
|
|
51
|
+
directory: string,
|
|
52
|
+
currentFilename: string,
|
|
53
|
+
validate: (value: unknown) => PoeTileConfig,
|
|
54
|
+
): ReadPoeTileConfigResult {
|
|
55
|
+
function readConfig(filename: string) {
|
|
56
|
+
const path = join(directory, filename);
|
|
57
|
+
if (!lstatSync(path, { throwIfNoEntry: false })) return undefined;
|
|
58
|
+
refuseSpecialFile(filename, path);
|
|
59
|
+
let raw: string;
|
|
60
|
+
try {
|
|
61
|
+
raw = readBoundedText(
|
|
62
|
+
path,
|
|
63
|
+
CONFIG_FILE_MAX_BYTES,
|
|
64
|
+
(size) =>
|
|
65
|
+
new Error(`${size} bytes; the maximum is ${CONFIG_FILE_MAX_BYTES}`),
|
|
66
|
+
);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
`Failed to read ${filename} at ${path}: ${describeError(error)}`,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
let parsed: unknown;
|
|
73
|
+
try {
|
|
74
|
+
parsed = JSON.parse(raw);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
throw new Error(`${filename} is not valid JSON: ${describeError(error)}`);
|
|
77
|
+
}
|
|
78
|
+
let config: PoeTileConfig;
|
|
79
|
+
try {
|
|
80
|
+
config = validate(parsed);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
describeError(error).replaceAll(currentFilename, filename),
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
return { path, config, fields: comparableFields(parsed) };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const current = readConfig(currentFilename);
|
|
90
|
+
const legacy = readConfig(LEGACY_PUBLISH_CONFIG_FILENAME);
|
|
91
|
+
if (current && legacy && !isDeepStrictEqual(current.fields, legacy.fields)) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`${currentFilename} and ${LEGACY_PUBLISH_CONFIG_FILENAME} differ. Reconcile them or keep only the intended config before continuing. Neither file was changed.`,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
const selected = current ?? legacy;
|
|
97
|
+
return selected
|
|
98
|
+
? { found: true, path: selected.path, config: selected.config }
|
|
99
|
+
: { found: false };
|
|
100
|
+
}
|