@joiner-platform/cli 0.0.0-stage → 0.1.0
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 +148 -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 +196 -0
- package/skills/tile-creator/references/assets.md +124 -0
- package/skills/tile-creator/references/backend-api.md +308 -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,160 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The deferred half of a staged publish, one task in the artifacts' upload
|
|
5
|
+
* wave since the client bundle carries only the files' hashes. It names every
|
|
6
|
+
* `deferred/` file by hash and size (`POST
|
|
7
|
+
* /tiles/publish-sessions/{id}/deferred/files`), then uploads only the files
|
|
8
|
+
* the answer names missing (`PUT …/deferred-assets`). The commit finds the
|
|
9
|
+
* rest among the caller's own files, so a republish of unchanged files
|
|
10
|
+
* uploads none of them. The lookup starts beside the bundle; the server takes
|
|
11
|
+
* an upload only once its publish has staged the bundle, so the uploads wait
|
|
12
|
+
* for it (`bundleGate`).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { createHash } from "node:crypto";
|
|
16
|
+
import { fetchRetry } from "./publish-retry";
|
|
17
|
+
import {
|
|
18
|
+
PUBLISH_UPLOAD_CONCURRENCY,
|
|
19
|
+
uploadConcurrently,
|
|
20
|
+
} from "./upload-concurrency";
|
|
21
|
+
|
|
22
|
+
type FetchLike = (
|
|
23
|
+
input: string | URL | Request,
|
|
24
|
+
init?: RequestInit,
|
|
25
|
+
) => Promise<Response>;
|
|
26
|
+
|
|
27
|
+
type Upload = () => Promise<Response>;
|
|
28
|
+
|
|
29
|
+
/** Resolves null once the bundle is staged, or the failed upload's response. */
|
|
30
|
+
type BundleStaged = () => Promise<Response | null>;
|
|
31
|
+
|
|
32
|
+
type DeferredFile = { path: string; sha256: string; size: number };
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The deferred files' task, given the bundle's gate: the lookup, then each
|
|
36
|
+
* missing file's upload. It resolves with the first non-ok response, or else
|
|
37
|
+
* the lookup's. Null when the build defers nothing.
|
|
38
|
+
*/
|
|
39
|
+
export function deferredUpload(input: {
|
|
40
|
+
serverUrl: string;
|
|
41
|
+
fetchFn: FetchLike;
|
|
42
|
+
headers: Record<string, string>;
|
|
43
|
+
publishId: string;
|
|
44
|
+
sleep: (ms: number) => Promise<void>;
|
|
45
|
+
deferredFiles?: ReadonlyMap<string, Uint8Array> | undefined;
|
|
46
|
+
}): ((staged: BundleStaged) => Upload) | null {
|
|
47
|
+
const files = input.deferredFiles;
|
|
48
|
+
if (!files?.size) return null;
|
|
49
|
+
const base = `${input.serverUrl}/api/v1/tiles/publish-sessions/${input.publishId}`;
|
|
50
|
+
const put = ({ path, sha256 }: DeferredFile): Promise<Response> => {
|
|
51
|
+
const bytes = files.get(path) as Uint8Array;
|
|
52
|
+
return fetchRetry(
|
|
53
|
+
input.fetchFn,
|
|
54
|
+
`${base}/deferred-assets?path=${encodeURIComponent(path)}`,
|
|
55
|
+
{
|
|
56
|
+
method: "PUT",
|
|
57
|
+
headers: {
|
|
58
|
+
...input.headers,
|
|
59
|
+
"Content-Type": "application/octet-stream",
|
|
60
|
+
"Content-Length": String(bytes.byteLength),
|
|
61
|
+
"X-Content-SHA256": sha256,
|
|
62
|
+
},
|
|
63
|
+
body: bytes.buffer.slice(
|
|
64
|
+
bytes.byteOffset,
|
|
65
|
+
bytes.byteOffset + bytes.byteLength,
|
|
66
|
+
) as ArrayBuffer,
|
|
67
|
+
},
|
|
68
|
+
input.sleep,
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
return (staged) => async () => {
|
|
72
|
+
const named: DeferredFile[] = [...files].map(([path, bytes]) => ({
|
|
73
|
+
path,
|
|
74
|
+
sha256: createHash("sha256").update(bytes).digest("hex"),
|
|
75
|
+
size: bytes.byteLength,
|
|
76
|
+
}));
|
|
77
|
+
const body = JSON.stringify({ files: named });
|
|
78
|
+
const lookup = await fetchRetry(
|
|
79
|
+
input.fetchFn,
|
|
80
|
+
`${base}/deferred/files`,
|
|
81
|
+
{
|
|
82
|
+
method: "POST",
|
|
83
|
+
headers: {
|
|
84
|
+
...input.headers,
|
|
85
|
+
"Content-Type": "application/json",
|
|
86
|
+
"Content-Length": String(new TextEncoder().encode(body).byteLength),
|
|
87
|
+
},
|
|
88
|
+
body,
|
|
89
|
+
},
|
|
90
|
+
input.sleep,
|
|
91
|
+
);
|
|
92
|
+
if (!lookup.ok) return lookup;
|
|
93
|
+
const { missing } = (await lookup.clone().json()) as {
|
|
94
|
+
missing: DeferredFile[];
|
|
95
|
+
};
|
|
96
|
+
if (missing.length === 0) return lookup;
|
|
97
|
+
const failed = await staged();
|
|
98
|
+
if (failed) return failed;
|
|
99
|
+
return (
|
|
100
|
+
(await uploadConcurrently(missing, put, PUBLISH_UPLOAD_CONCURRENCY)) ??
|
|
101
|
+
lookup
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Gate later work on `first`: `staged` resolves null once every `first`
|
|
108
|
+
* upload answered ok, or the first failed one's response, and rejects with
|
|
109
|
+
* the error of one that threw. Queue `first` ahead of whatever waits on it so
|
|
110
|
+
* a waiting upload never holds the slot one of them needs.
|
|
111
|
+
*/
|
|
112
|
+
export function bundleGate(first: readonly Upload[]): {
|
|
113
|
+
first: Upload[];
|
|
114
|
+
staged: BundleStaged;
|
|
115
|
+
} {
|
|
116
|
+
let resolve: (failed: Response | null) => void = () => {};
|
|
117
|
+
let reject: (error: unknown) => void = () => {};
|
|
118
|
+
const done = new Promise<Response | null>((onResolve, onReject) => {
|
|
119
|
+
resolve = onResolve;
|
|
120
|
+
reject = onReject;
|
|
121
|
+
});
|
|
122
|
+
// A rejection with nothing waiting on it is not unhandled.
|
|
123
|
+
done.catch(() => {});
|
|
124
|
+
let pending = first.length;
|
|
125
|
+
if (pending === 0) resolve(null);
|
|
126
|
+
return {
|
|
127
|
+
first: first.map((upload) => async () => {
|
|
128
|
+
try {
|
|
129
|
+
const response = await upload();
|
|
130
|
+
if (!response.ok) resolve(response);
|
|
131
|
+
else if (--pending === 0) resolve(null);
|
|
132
|
+
return response;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
reject(error);
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}),
|
|
138
|
+
staged: () => done,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* A staged publish's uploads in queue order: the bundle, the deferred files'
|
|
144
|
+
* task gated on it (`bundleGate`), then the other artifacts.
|
|
145
|
+
*/
|
|
146
|
+
export function bundleFirstUploads<Artifact extends { kind: string }>(input: {
|
|
147
|
+
artifacts: readonly Artifact[];
|
|
148
|
+
uploadOne: (artifact: Artifact) => Promise<Response>;
|
|
149
|
+
deferred: ((staged: BundleStaged) => Upload) | null;
|
|
150
|
+
}): Upload[] {
|
|
151
|
+
const isBundle = (artifact: Artifact) =>
|
|
152
|
+
artifact.kind === "client-bundle" || artifact.kind === "runtime-bundle";
|
|
153
|
+
const upload = (artifact: Artifact) => () => input.uploadOne(artifact);
|
|
154
|
+
const gate = bundleGate(input.artifacts.filter(isBundle).map(upload));
|
|
155
|
+
return [
|
|
156
|
+
...gate.first,
|
|
157
|
+
...(input.deferred ? [input.deferred(gate.staged)] : []),
|
|
158
|
+
...input.artifacts.filter((artifact) => !isBundle(artifact)).map(upload),
|
|
159
|
+
];
|
|
160
|
+
}
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
// owner: aaronroe
|
|
2
|
+
|
|
3
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
4
|
+
import {
|
|
5
|
+
awaitCommitInProgress,
|
|
6
|
+
conflictCode,
|
|
7
|
+
wallClockSleep,
|
|
8
|
+
} from "./commit-in-progress";
|
|
9
|
+
import { observedStep, type PublishPhaseObserver } from "./publish-phases.js";
|
|
10
|
+
import { fetchRetry } from "./publish-retry";
|
|
11
|
+
import {
|
|
12
|
+
abandonStagedPublish,
|
|
13
|
+
isPublishCommitClaimConflict,
|
|
14
|
+
} from "./staged-publish-cleanup";
|
|
15
|
+
import { bundleFirstUploads, deferredUpload } from "./staged-publish-deferred";
|
|
16
|
+
import {
|
|
17
|
+
PUBLISH_UPLOAD_CONCURRENCY,
|
|
18
|
+
uploadConcurrently,
|
|
19
|
+
} from "./upload-concurrency";
|
|
20
|
+
|
|
21
|
+
type FetchLike = (
|
|
22
|
+
input: string | URL | Request,
|
|
23
|
+
init?: RequestInit,
|
|
24
|
+
) => Promise<Response>;
|
|
25
|
+
|
|
26
|
+
type Artifact = {
|
|
27
|
+
kind: string;
|
|
28
|
+
bytes: Uint8Array;
|
|
29
|
+
contentType: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type Commit = Record<string, unknown>;
|
|
33
|
+
|
|
34
|
+
function file(form: FormData, field: string): File | undefined {
|
|
35
|
+
const value = form.get(field);
|
|
36
|
+
return value instanceof File ? value : undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function text(form: FormData, field: string): string | undefined {
|
|
40
|
+
const value = form.get(field);
|
|
41
|
+
return typeof value === "string" ? value : undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function booleanField(form: FormData, field: string): boolean | undefined {
|
|
45
|
+
const value = text(form, field);
|
|
46
|
+
if (value === undefined) return undefined;
|
|
47
|
+
return value === "true";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function jsonField(form: FormData, field: string): unknown {
|
|
51
|
+
const value = text(form, field);
|
|
52
|
+
return value === undefined ? undefined : JSON.parse(value);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function bytes(value: File): Promise<Uint8Array> {
|
|
56
|
+
return new Uint8Array(await value.arrayBuffer());
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
type ScreenshotEntry =
|
|
60
|
+
| { kind: "url"; url: unknown }
|
|
61
|
+
| { kind: "file"; field: string };
|
|
62
|
+
|
|
63
|
+
function parseScreenshotEntry(item: unknown): ScreenshotEntry {
|
|
64
|
+
if (typeof item !== "object" || item === null) {
|
|
65
|
+
throw new Error("Invalid screenshots manifest");
|
|
66
|
+
}
|
|
67
|
+
const entry = item as { kind?: unknown; url?: unknown; field?: unknown };
|
|
68
|
+
if (entry.kind === "url") return { kind: "url", url: entry.url };
|
|
69
|
+
if (entry.kind !== "file" || typeof entry.field !== "string") {
|
|
70
|
+
throw new Error("Invalid screenshots manifest");
|
|
71
|
+
}
|
|
72
|
+
return { kind: "file", field: entry.field };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function translateScreenshotFile(input: {
|
|
76
|
+
form: FormData;
|
|
77
|
+
entry: Extract<ScreenshotEntry, { kind: "file" }>;
|
|
78
|
+
artifactIndex: number;
|
|
79
|
+
}): Promise<{ artifact: Artifact; manifestItem: unknown }> {
|
|
80
|
+
const upload = file(input.form, input.entry.field);
|
|
81
|
+
if (!upload) throw new Error(`Missing screenshot ${input.entry.field}`);
|
|
82
|
+
const kind = `screenshot-${input.artifactIndex}`;
|
|
83
|
+
return {
|
|
84
|
+
artifact: {
|
|
85
|
+
kind,
|
|
86
|
+
bytes: await bytes(upload),
|
|
87
|
+
contentType: upload.type,
|
|
88
|
+
},
|
|
89
|
+
manifestItem: { kind: "artifact", artifact: kind },
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function translateScreenshots(form: FormData): Promise<
|
|
94
|
+
| {
|
|
95
|
+
manifest: unknown[];
|
|
96
|
+
artifacts: Artifact[];
|
|
97
|
+
}
|
|
98
|
+
| undefined
|
|
99
|
+
> {
|
|
100
|
+
const manifest = jsonField(form, "screenshots");
|
|
101
|
+
if (manifest === undefined) return undefined;
|
|
102
|
+
if (!Array.isArray(manifest)) throw new Error("Invalid screenshots manifest");
|
|
103
|
+
let artifactIndex = 0;
|
|
104
|
+
const pending = manifest.map((item) => {
|
|
105
|
+
const entry = parseScreenshotEntry(item);
|
|
106
|
+
if (entry.kind === "url") {
|
|
107
|
+
return Promise.resolve({
|
|
108
|
+
artifact: undefined,
|
|
109
|
+
manifestItem: { kind: "url", url: entry.url },
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const translated = translateScreenshotFile({
|
|
113
|
+
form,
|
|
114
|
+
entry,
|
|
115
|
+
artifactIndex,
|
|
116
|
+
});
|
|
117
|
+
artifactIndex++;
|
|
118
|
+
return translated;
|
|
119
|
+
});
|
|
120
|
+
const translated = await Promise.all(pending);
|
|
121
|
+
return {
|
|
122
|
+
manifest: translated.map((item) => item.manifestItem),
|
|
123
|
+
artifacts: translated.flatMap((item) =>
|
|
124
|
+
item.artifact ? [item.artifact] : [],
|
|
125
|
+
),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function addMappedFields(form: FormData, commit: Commit): void {
|
|
130
|
+
for (const [formField, commitField] of [
|
|
131
|
+
["visibility", "visibility"],
|
|
132
|
+
["tile_id", "tileId"],
|
|
133
|
+
["short_description", "shortDescription"],
|
|
134
|
+
["display_name", "displayName"],
|
|
135
|
+
["change_summary", "changeSummary"],
|
|
136
|
+
["version_name", "versionName"],
|
|
137
|
+
["version_notes", "versionNotes"],
|
|
138
|
+
["instancing", "instancing"],
|
|
139
|
+
["whole_tile_bundle", "wholeTileBundle"],
|
|
140
|
+
] as const) {
|
|
141
|
+
const value = text(form, formField);
|
|
142
|
+
if (value !== undefined) commit[commitField] = value;
|
|
143
|
+
}
|
|
144
|
+
for (const [formField, commitField] of [
|
|
145
|
+
["publish_as_poe", "publishAsPoe"],
|
|
146
|
+
["publish_as_tile_author", "publishAsTileAuthor"],
|
|
147
|
+
["is_dev_tile", "tileAllowsTestUsers"],
|
|
148
|
+
// A field missing here never reaches the server: the multipart route
|
|
149
|
+
// this replaced is a 426 tombstone.
|
|
150
|
+
["promote", "promote"],
|
|
151
|
+
] as const) {
|
|
152
|
+
const value = booleanField(form, formField);
|
|
153
|
+
if (value !== undefined) commit[commitField] = value;
|
|
154
|
+
}
|
|
155
|
+
for (const [formField, commitField] of [
|
|
156
|
+
["players", "players"],
|
|
157
|
+
["remix_of", "remixOf"],
|
|
158
|
+
] as const) {
|
|
159
|
+
const value = jsonField(form, formField);
|
|
160
|
+
if (value !== undefined) commit[commitField] = value;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function addEdit(form: FormData, commit: Commit): void {
|
|
165
|
+
if (text(form, "finalize_edit") !== "true") return;
|
|
166
|
+
const handle = text(form, "edit_handle");
|
|
167
|
+
const visibility = text(form, "edit_visibility");
|
|
168
|
+
commit["edit"] = {
|
|
169
|
+
finalize: true,
|
|
170
|
+
...(handle === undefined ? {} : { handle }),
|
|
171
|
+
...(visibility === undefined ? {} : { visibility }),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async function addSourceBundle(
|
|
176
|
+
form: FormData,
|
|
177
|
+
artifacts: Artifact[],
|
|
178
|
+
commit: Commit,
|
|
179
|
+
): Promise<void> {
|
|
180
|
+
const source = file(form, "source_bundle");
|
|
181
|
+
if (!source) return;
|
|
182
|
+
artifacts.push({
|
|
183
|
+
kind: "source-bundle",
|
|
184
|
+
bytes: await bytes(source),
|
|
185
|
+
contentType: source.type || "application/gzip",
|
|
186
|
+
});
|
|
187
|
+
commit["sourceBundle"] = {
|
|
188
|
+
visibility: text(form, "source_bundle_visibility") ?? "public",
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async function addProfilePicture(
|
|
193
|
+
form: FormData,
|
|
194
|
+
artifacts: Artifact[],
|
|
195
|
+
commit: Commit,
|
|
196
|
+
): Promise<void> {
|
|
197
|
+
const profile = file(form, "profile_picture");
|
|
198
|
+
if (!profile) {
|
|
199
|
+
const url = text(form, "profile_picture_url");
|
|
200
|
+
if (url !== undefined) commit["profilePicture"] = { kind: "url", url };
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (profile.size === 0) {
|
|
204
|
+
commit["profilePicture"] = { kind: "clear" };
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
artifacts.push({
|
|
208
|
+
kind: "profile-picture",
|
|
209
|
+
bytes: await bytes(profile),
|
|
210
|
+
contentType: profile.type,
|
|
211
|
+
});
|
|
212
|
+
commit["profilePicture"] = { kind: "artifact" };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function addLongDescription(form: FormData, commit: Commit): void {
|
|
216
|
+
const value = text(form, "long_description");
|
|
217
|
+
if (value === undefined) return;
|
|
218
|
+
commit["longDescription"] = value === "" ? { clear: true } : { value };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async function addVideo(
|
|
222
|
+
form: FormData,
|
|
223
|
+
artifacts: Artifact[],
|
|
224
|
+
commit: Commit,
|
|
225
|
+
): Promise<void> {
|
|
226
|
+
const manifest = jsonField(form, "video");
|
|
227
|
+
if (manifest === undefined) return;
|
|
228
|
+
if (manifest === null) {
|
|
229
|
+
commit["video"] = null;
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const video = file(form, "video_file");
|
|
233
|
+
const poster = file(form, "video_poster_file");
|
|
234
|
+
if (!video || !poster) throw new Error("Missing video artifacts");
|
|
235
|
+
const [videoBytes, posterBytes] = await Promise.all([
|
|
236
|
+
bytes(video),
|
|
237
|
+
bytes(poster),
|
|
238
|
+
]);
|
|
239
|
+
artifacts.push(
|
|
240
|
+
{ kind: "preview-video", bytes: videoBytes, contentType: video.type },
|
|
241
|
+
{ kind: "video-poster", bytes: posterBytes, contentType: poster.type },
|
|
242
|
+
);
|
|
243
|
+
commit["video"] = { kind: "artifact" };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
async function translateForm(form: FormData): Promise<{
|
|
247
|
+
artifacts: Artifact[];
|
|
248
|
+
commit: Commit;
|
|
249
|
+
}> {
|
|
250
|
+
// The build arrives split (`publish-pack.ts`): the client bundle, stored by
|
|
251
|
+
// the server exactly as uploaded, and the backend entries on their own.
|
|
252
|
+
const bundle = file(form, "bundle");
|
|
253
|
+
if (!bundle) throw new Error("bundle file field is required");
|
|
254
|
+
const backend = file(form, "backend_bundle");
|
|
255
|
+
const artifacts: Artifact[] = [
|
|
256
|
+
{
|
|
257
|
+
kind: "client-bundle",
|
|
258
|
+
bytes: await bytes(bundle),
|
|
259
|
+
contentType: bundle.type || "application/gzip",
|
|
260
|
+
},
|
|
261
|
+
];
|
|
262
|
+
const handle = text(form, "handle");
|
|
263
|
+
if (!handle) throw new Error("handle field is required");
|
|
264
|
+
const commit: Commit = { handle, clientBundle: { kind: "artifact" } };
|
|
265
|
+
if (backend) {
|
|
266
|
+
artifacts.push({
|
|
267
|
+
kind: "backend-bundle",
|
|
268
|
+
bytes: await bytes(backend),
|
|
269
|
+
contentType: backend.type || "application/gzip",
|
|
270
|
+
});
|
|
271
|
+
commit["backendBundle"] = { kind: "artifact" };
|
|
272
|
+
}
|
|
273
|
+
addMappedFields(form, commit);
|
|
274
|
+
addEdit(form, commit);
|
|
275
|
+
await addSourceBundle(form, artifacts, commit);
|
|
276
|
+
await addProfilePicture(form, artifacts, commit);
|
|
277
|
+
addLongDescription(form, commit);
|
|
278
|
+
const screenshots = await translateScreenshots(form);
|
|
279
|
+
if (screenshots) {
|
|
280
|
+
artifacts.push(...screenshots.artifacts);
|
|
281
|
+
commit["screenshots"] = screenshots.manifest;
|
|
282
|
+
}
|
|
283
|
+
await addVideo(form, artifacts, commit);
|
|
284
|
+
return { artifacts, commit };
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function sha256(value: Uint8Array): string {
|
|
288
|
+
return createHash("sha256").update(value).digest("hex");
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const runUpload = (upload: () => Promise<Response>) => upload();
|
|
292
|
+
|
|
293
|
+
export async function publishFormDataStaged(input: {
|
|
294
|
+
serverUrl: string;
|
|
295
|
+
fetchFn: FetchLike;
|
|
296
|
+
headers: Record<string, string>;
|
|
297
|
+
formData: FormData;
|
|
298
|
+
/** Times each upload wave and each commit request; see `publish-phases.ts`. */
|
|
299
|
+
observe?: PublishPhaseObserver;
|
|
300
|
+
sleep?: (ms: number) => Promise<void>;
|
|
301
|
+
/**
|
|
302
|
+
* The build's `deferred/` files, which the client bundle in `formData`
|
|
303
|
+
* indexes. They are looked up alongside the artifacts, and only the ones
|
|
304
|
+
* the server does not already hold for the caller upload.
|
|
305
|
+
*/
|
|
306
|
+
deferredFiles?: ReadonlyMap<string, Uint8Array>;
|
|
307
|
+
}): Promise<Response> {
|
|
308
|
+
const { artifacts, commit } = await translateForm(input.formData);
|
|
309
|
+
const publishId = randomUUID();
|
|
310
|
+
const sleep = input.sleep ?? wallClockSleep;
|
|
311
|
+
const uploadOne = (artifact: (typeof artifacts)[number]): Promise<Response> =>
|
|
312
|
+
fetchRetry(
|
|
313
|
+
input.fetchFn,
|
|
314
|
+
`${input.serverUrl}/api/v1/tiles/publish-sessions/${publishId}/artifacts/${artifact.kind}`,
|
|
315
|
+
{
|
|
316
|
+
method: "PUT",
|
|
317
|
+
headers: {
|
|
318
|
+
...input.headers,
|
|
319
|
+
"Content-Type": artifact.contentType,
|
|
320
|
+
"Content-Length": String(artifact.bytes.byteLength),
|
|
321
|
+
"X-Content-SHA256": sha256(artifact.bytes),
|
|
322
|
+
},
|
|
323
|
+
body: artifact.bytes.buffer.slice(
|
|
324
|
+
artifact.bytes.byteOffset,
|
|
325
|
+
artifact.bytes.byteOffset + artifact.bytes.byteLength,
|
|
326
|
+
) as ArrayBuffer,
|
|
327
|
+
},
|
|
328
|
+
sleep,
|
|
329
|
+
);
|
|
330
|
+
// The first non-ok response, or null once every artifact and deferred file
|
|
331
|
+
// is staged: one wave, the deferred uploads after the client bundle. Each
|
|
332
|
+
// wave builds its own gate, so a recovery wave waits for its own bundle.
|
|
333
|
+
const wave = () =>
|
|
334
|
+
bundleFirstUploads({
|
|
335
|
+
artifacts,
|
|
336
|
+
uploadOne,
|
|
337
|
+
deferred: deferredUpload({ ...input, publishId, sleep }),
|
|
338
|
+
});
|
|
339
|
+
const uploadAll = (): Promise<Response | null> =>
|
|
340
|
+
observedStep(input.observe, "upload", () =>
|
|
341
|
+
uploadConcurrently(wave(), runUpload, PUBLISH_UPLOAD_CONCURRENCY),
|
|
342
|
+
);
|
|
343
|
+
const abandon = (): Promise<void> =>
|
|
344
|
+
abandonStagedPublish({
|
|
345
|
+
serverUrl: input.serverUrl,
|
|
346
|
+
fetchFn: input.fetchFn,
|
|
347
|
+
headers: input.headers,
|
|
348
|
+
publishId,
|
|
349
|
+
});
|
|
350
|
+
const commitRequest = (): Promise<Response> =>
|
|
351
|
+
observedStep(input.observe, "commit", () => {
|
|
352
|
+
const body = JSON.stringify(commit);
|
|
353
|
+
return fetchRetry(
|
|
354
|
+
input.fetchFn,
|
|
355
|
+
`${input.serverUrl}/api/v1/tiles/publish-sessions/${publishId}/commit`,
|
|
356
|
+
{
|
|
357
|
+
method: "POST",
|
|
358
|
+
headers: {
|
|
359
|
+
...input.headers,
|
|
360
|
+
"Content-Type": "application/json",
|
|
361
|
+
"Content-Length": String(new TextEncoder().encode(body).byteLength),
|
|
362
|
+
},
|
|
363
|
+
body,
|
|
364
|
+
},
|
|
365
|
+
sleep,
|
|
366
|
+
);
|
|
367
|
+
});
|
|
368
|
+
// Everything from the first upload on is wrapped, because a non-ok status is
|
|
369
|
+
// not the only way a publish dies: `fetchRetry` rethrows when the transport
|
|
370
|
+
// fails on every attempt, and an escaping throw would skip every cleanup
|
|
371
|
+
// branch below while leaving already-staged artifacts holding a capacity slot
|
|
372
|
+
// — the same 429 wedge, reached by throw instead of status. `translateForm`
|
|
373
|
+
// stays outside: it throws before a publish id exists, so nothing is staged.
|
|
374
|
+
try {
|
|
375
|
+
const uploadError = await uploadAll();
|
|
376
|
+
if (uploadError) {
|
|
377
|
+
await abandon();
|
|
378
|
+
return uploadError;
|
|
379
|
+
}
|
|
380
|
+
let response = await commitRequest();
|
|
381
|
+
if ((await conflictCode(response)) === "publish_artifact_missing") {
|
|
382
|
+
const retryUploadError = await uploadAll();
|
|
383
|
+
if (retryUploadError) {
|
|
384
|
+
await abandon();
|
|
385
|
+
return retryUploadError;
|
|
386
|
+
}
|
|
387
|
+
response = await commitRequest();
|
|
388
|
+
}
|
|
389
|
+
response = await awaitCommitInProgress(response, commitRequest, sleep);
|
|
390
|
+
if (!response.ok && !(await isPublishCommitClaimConflict(response)))
|
|
391
|
+
await abandon();
|
|
392
|
+
return response;
|
|
393
|
+
} catch (error) {
|
|
394
|
+
// Best-effort, like every other cleanup here: during a sustained outage the
|
|
395
|
+
// DELETE fails too and the hourly sweep remains the backstop. It reclaims the
|
|
396
|
+
// slot in the narrower window where the publish request died but a small
|
|
397
|
+
// DELETE still lands — e.g. a large artifact PUT timed out.
|
|
398
|
+
await abandon();
|
|
399
|
+
throw error;
|
|
400
|
+
}
|
|
401
|
+
}
|