fix: align identity, CORS, and event payload shape with real platform behavior - #2
Merged
Merged
Conversation
… behavior Found by a live end-to-end dry run against production (register → install → iframe launch → bootstrap → ping → real order.created). Three bugs meant the starter could not complete a real integration out of the box: 1. Identity verification rejected every real launch token: requiredClaims demanded `nbf`, but platform tokens carry iss/sub/aud/iat/exp only (and the docs never promise nbf). Dropped nbf from requiredClaims — jose still validates it when present. The "missing nbf" test now asserts acceptance. 2. Worker CORS only allowed the dashboard origin, but the iframe UI calls the Worker from the UI's OWN origin, so every UI request failed preflight in the documented split-origin deployment. Added an optional EXTENSION_UI_ORIGIN var (exact HTTPS origin, validated at boot) that is allowed alongside the dashboard origin; documented in wrangler.jsonc, README, cloudflare-deployment.md, and local-development.md. 3. The demo connector read `event.data.orderId`, but real order.created deliveries carry the full order under `data.order` — the demo terminal- failed on its first real event while its invented fixture kept tests green. Now reads data.order.id; the fixture and every event literal in tests model the real payload shape. Also repairs two breaks that slipped into main via #1 (its final check ran stale): an unused-var lint error in contracts.test.ts and three webhook verification tests whose signed rawBody fixture predated the required `version` field (digest recomputed). Verified: pnpm check (format, lint, typecheck, 137 root + all package tests, wrangler dry-run build) exit 0. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A live end-to-end dry run against production (register → private publish → install → iframe launch → bootstrap → connectivity ping → real
order.created) surfaced three bugs that each independently break a real integration, despite the full test suite passing — the suite validated invented contracts, not the platform's real ones.Fixes
1. Launch-token verification rejected every real token (
packages/throttle/src/identity.ts)requiredClaimsdemandednbf, but platform launch tokens carryiss/sub/aud/iat/exponly (verified by decoding a real token; the identity docs never promisenbf). Droppednbffrom the required list — jose still validatesnbfwhen present (the "future nbf" rejection test is unchanged). The "missing nbf" test now asserts acceptance.2. Worker CORS blocked its own UI (
apps/cloudflare/src/app.ts)CORS allowed only
THROTTLE_DASHBOARD_ORIGIN, but the iframe UI calls the Worker from the UI's own origin — every request failed preflight (OPTIONS /api/installation 403) in the documented split-origin deployment. New optionalEXTENSION_UI_ORIGINvar (exact-HTTPS-origin validated at boot, same rules as the dashboard origin) is allowed alongside the dashboard origin. Documented inwrangler.jsonc(commented example), README secret table,cloudflare-deployment.md, andlocal-development.md(tunnel workflow).3. Demo connector couldn't process a real event (
examples/demo-connector)It read
event.data.orderId, but real deliveries carry the full order underdata.order(platform emit site:data: { order, fromCart }). The demo terminal-failed on its first real event. Now readsdata.order.id; theorder-created.jsonfixture and every event literal in tests now model the real payload shape.Also repairs two breaks that landed on main via #1
That PR's final verification ran stale — apologies.
maincurrently failspnpm check:contracts.test.ts(rest-destructure_version)rawBodyfixture predates the now-requiredversionfield (verifyThrottleWebhookschema-parses after signature checks → null). Fixture updated + HMAC digest recomputed.Verification
pnpm checkexit 0 (format, lint, typecheck, all package suites + 137 root tests, wrangler dry-run build)202+ queue-processed, realorder.createddelivered, signature-verified, and processed by the demo provider on attempt 1.🤖 Generated with Claude Code