Skip to content

example(cloudflare-pr-package): pr-package upload/download/auth example#638

Open
Mkassabov wants to merge 1 commit into
mainfrom
example/cloudflare-pr-package
Open

example(cloudflare-pr-package): pr-package upload/download/auth example#638
Mkassabov wants to merge 1 commit into
mainfrom
example/cloudflare-pr-package

Conversation

@Mkassabov

Copy link
Copy Markdown
Contributor

An example demonstrating the @alchemy.run/pr-package library end to end, with integration tests against a real deploy.

Renamed from cloudflare-worker-auth — the example is specifically about @alchemy.run/pr-package, so the name now says so. The worker is PrPackage.handler() and the stack output's bearer token comes from PrPackage.AuthTokenValue.

// src/Api.ts
export default class Api extends Cloudflare.Worker<Api>()(
  "Api",
  { main: import.meta.filename, url: true },
  PrPackage.handler(),
) {}

Tests (test/integ.test.ts)

Deployed once via beforeAll, driven over HTTP:

  • auth — valid token 200; invalid / missing / literal "<redacted>" all 401
  • upload + downloadPUT a bundle, then download the exact bytes back both directly by resourceId and via the tag (which 302-redirects to the package)
  • garbage collection — one bundle under two tags; removing one tag keeps the bundle, removing the last tag deletes it

KV is eventually consistent and cold bindings can return transient 5xx, so reads/uploads poll until the converged status (pollUntilStatus). Upload retries are safe because the R2 bucket self-empties on destroy.

Distilled pin

Bumps the distilled submodule to include the Cloudflare error-class tree-shaking fix (distilled#352) — without it the Worker bundle keeps a dangling import "@distilled.cloud/cloudflare/flagship" and Cloudflare rejects the upload with ScriptModuleNotFound.

The pin is one commit past v0.25.2 and not yet a published release. Re-pin to the tagged release once distilled cuts v0.25.3, before the next alchemy npm publish.

Rename the `cloudflare-worker-auth` example to `cloudflare-pr-package` — it
demonstrates the `@alchemy.run/pr-package` library specifically, so the name
should say so. The worker is `PrPackage.handler()` and the bearer token comes
from `PrPackage.AuthTokenValue`.

Integration tests against a real deploy:
  - bearer auth: valid -> 200, invalid / missing / "<redacted>" -> 401
  - upload a bundle and download the exact bytes back (direct + via tag)
  - garbage collection: a bundle is removed once its last tag pointer is deleted

Bumps the distilled submodule pin to include the Cloudflare error-class
tree-shaking fix (distilled#352) so the Worker bundle no longer ships a
dangling `import "@distilled.cloud/cloudflare/flagship"`. The pin is one commit
past v0.25.2 and not yet a published release; re-pin to the tagged release once
distilled cuts it.
@alchemy-version-bot

Copy link
Copy Markdown
Contributor

Install the packages built from this commit:

alchemy

bun add alchemy@https://pkg.ing/alchemy/ad9666e

@alchemy.run/better-auth

bun add @alchemy.run/better-auth@https://pkg.ing/@alchemy.run/better-auth/ad9666e

@alchemy.run/pr-package

bun add @alchemy.run/pr-package@https://pkg.ing/@alchemy.run/pr-package/ad9666e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant