diff --git a/packages/alchemy/src/Cloudflare/Logs.ts b/packages/alchemy/src/Cloudflare/Logs.ts
index ff35c53ee3c..909dff9c916 100644
--- a/packages/alchemy/src/Cloudflare/Logs.ts
+++ b/packages/alchemy/src/Cloudflare/Logs.ts
@@ -78,6 +78,30 @@ export const CloudflareLogs = Effect.gen(function* () {
const createScriptTail = yield* workers.createScriptTail;
const deleteScriptTail = yield* workers.deleteScriptTail;
+ /**
+ * The telemetry query needs the `workers_observability:read` OAuth scope.
+ * A token minted by an older `alchemy login` (before the scope joined the
+ * defaults) keeps its original grants forever, so the query fails with a
+ * bare `Unauthorized`/`Forbidden` even though a fresh login would work —
+ * explain the fix instead of surfacing the raw tag.
+ */
+ const explainMissingObservabilityScope = (
+ effect: Effect.Effect,
+ ): Effect.Effect =>
+ effect.pipe(
+ Effect.catchTag("Unauthorized", () =>
+ Effect.die(
+ new Error(
+ "Cloudflare rejected the observability telemetry query (Unauthorized). " +
+ 'Your stored credentials are likely missing the "workers_observability:read" scope — ' +
+ "OAuth tokens keep the scopes they were minted with, so tokens from an older " +
+ "`alchemy login` won't have it. Run `alchemy login` again to mint a token with " +
+ "the current default scopes, or use an API token that grants Workers Observability read access.",
+ ),
+ ),
+ ),
+ );
+
const queryLogs = (opts: {
accountId: string;
filters: TelemetryFilter[];
@@ -88,30 +112,34 @@ export const CloudflareLogs = Effect.gen(function* () {
const limit = opts.options.limit ?? 100;
if (opts.options.since) {
- const response = yield* queryTelemetry({
+ const response = yield* explainMissingObservabilityScope(
+ queryTelemetry({
+ accountId: opts.accountId,
+ queryId: "events",
+ view: "events",
+ timeframe: { from: opts.options.since.getTime(), to: now },
+ limit,
+ parameters: {
+ filters: opts.filters,
+ // orderBy: { value: "timestamp", order: "desc" },
+ },
+ }),
+ );
+ return parseEvents(response);
+ }
+
+ const response = yield* explainMissingObservabilityScope(
+ queryTelemetry({
accountId: opts.accountId,
queryId: "events",
view: "events",
- timeframe: { from: opts.options.since.getTime(), to: now },
+ timeframe: { from: now - DEFAULT_LOOKBACK_MS, to: now },
limit,
parameters: {
filters: opts.filters,
- // orderBy: { value: "timestamp", order: "desc" },
},
- });
- return parseEvents(response);
- }
-
- const response = yield* queryTelemetry({
- accountId: opts.accountId,
- queryId: "events",
- view: "events",
- timeframe: { from: now - DEFAULT_LOOKBACK_MS, to: now },
- limit,
- parameters: {
- filters: opts.filters,
- },
- });
+ }),
+ );
return parseEvents(response);
});
@@ -207,17 +235,19 @@ export const CloudflareLogs = Effect.gen(function* () {
yield* Effect.sleep("2 seconds");
const now = Date.now();
- const response = yield* queryTelemetry({
- accountId: opts.accountId,
- queryId: "events",
- view: "events",
- timeframe: { from: since, to: now },
- limit: 100,
- parameters: {
- filters: opts.filters,
- orderBy: { value: "timestamp", order: "asc" },
- },
- });
+ const response = yield* explainMissingObservabilityScope(
+ queryTelemetry({
+ accountId: opts.accountId,
+ queryId: "events",
+ view: "events",
+ timeframe: { from: since, to: now },
+ limit: 100,
+ parameters: {
+ filters: opts.filters,
+ orderBy: { value: "timestamp", order: "asc" },
+ },
+ }),
+ );
const lines = parseEvents(response);
const nextSince =
diff --git a/packages/alchemy/src/Cloudflare/Website/StaticSite.ts b/packages/alchemy/src/Cloudflare/Website/StaticSite.ts
index 5321c866c02..c7efa7f3000 100644
--- a/packages/alchemy/src/Cloudflare/Website/StaticSite.ts
+++ b/packages/alchemy/src/Cloudflare/Website/StaticSite.ts
@@ -6,7 +6,11 @@ import * as Command from "../../Command/index.ts";
import type { Input, InputProps } from "../../Input.ts";
import * as Namespace from "../../Namespace.ts";
import * as Output from "../../Output.ts";
-import { effectClass } from "../../Util/effect.ts";
+import {
+ effectClass,
+ isYieldableEffectLike,
+ type YieldableEffectLike,
+} from "../../Util/effect.ts";
import { asEffect } from "../../Util/types.ts";
import type { Providers } from "../Providers.ts";
import type { AssetsConfig } from "../Workers/Assets.ts";
@@ -175,6 +179,25 @@ type StaticSiteWorker = Worker<{
* });
* ```
*
+ * @example Rebuilding when a sibling workspace package changes
+ * The default scope only hashes files under `cwd` (plus the nearest
+ * lockfile), so edits to a sibling workspace package the app imports do
+ * not retrigger the build on their own. Add the sibling's sources with a
+ * `../` include glob — and keep `lockfile: true`, since providing
+ * `include` otherwise drops the lockfile from the hash:
+ * ```typescript
+ * const site = yield* Cloudflare.Website.StaticSite("Web", {
+ * cwd: "apps/web",
+ * command: "npm run build",
+ * outdir: "dist",
+ * main: "./src/worker.ts",
+ * memo: {
+ * include: ["**\/*", "../../packages/env/src/**"],
+ * lockfile: true,
+ * },
+ * });
+ * ```
+ *
* @section Class Form
* Calling `StaticSite` with no arguments returns a constructor you can
* `extend` to declare the Worker as a named class. The class is both
@@ -241,7 +264,7 @@ const makeStaticSite = <
cwd:
props.dev.cwd ??
(typeof props.cwd === "string" ? props.cwd : undefined),
- env: serializeEnv(props.dev.env ?? props.env),
+ env: yield* serializeEnv(props.dev.env ?? props.env),
}).pipe(
Effect.map((d) =>
Output.map(d.url, (url) => ({
@@ -258,7 +281,7 @@ const makeStaticSite = <
cwd: props.cwd,
memo: props.memo,
outdir: props.outdir,
- env: serializeEnv(props.env),
+ env: yield* serializeEnv(props.env),
});
// Pure-static sites (neither `main` nor `script`) deploy as
@@ -281,17 +304,71 @@ const makeStaticSite = <
});
}).pipe(Namespace.push(id));
-const serializeEnv = (
+/**
+ * Serialize the site's `env` for the build/dev subprocess. The same record
+ * doubles as the Worker's binding props, so entries may be plain strings,
+ * `Redacted` secrets, `effect/Config` values, `Output` references, or
+ * binding Effects:
+ *
+ * - strings and `Redacted` values pass through unchanged
+ * - `Config` (and any other runnable Effect) is resolved here, at stack
+ * construction — passing it through unresolved would hand the subprocess
+ * the JSON-serialized `Config` object (`{"_id":"Config"}`) instead of its
+ * value (#796)
+ * - `Output` references resolve at reconcile; the resolved value is
+ * serialized the same way inline values are (an `Output