workers-start 0.12.0 → 0.13.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/CHANGELOG.md +5 -0
- package/README.md +24 -2
- package/dist/cache.d.ts +56 -0
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +101 -0
- package/dist/cache.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/cache.ts +161 -0
- package/src/index.ts +8 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.13.0 (2026-11-20)
|
|
4
|
+
|
|
5
|
+
- `workers-start/cache`: `cached(key, compute, { freshSeconds, staleSeconds, kv, version, onError })` and `cachedEntry` keep computed values in the Cache API with stale-while-revalidate (one background refresh per key per isolate) and stale-if-error, with KV as an optional second tier shared across locations.
|
|
6
|
+
- READMEs carry npm, downloads, CI and license badges.
|
|
7
|
+
|
|
3
8
|
## 0.12.0 (2026-11-20)
|
|
4
9
|
|
|
5
10
|
- `workers-start/rate-limit`: `rateLimit(request, binding, policy, options)` on the Workers rate limiting binding. It counts by a salted hash of the client IP (`clientKey`) or a key the app names, fails open with a once-per-isolate `onUnbound` report, can let verified bots through, and answers a 429 problem with `Retry-After`, `RateLimit-Policy`, `RateLimit` and `no-store` (`tooManyRequests`, `rateLimitHeaders`).
|
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# workers-start
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/workers-start) [](https://www.npmjs.com/package/workers-start) [](https://github.com/ryanio/workers-kit/actions/workflows/ci.yml) [](https://github.com/ryanio/workers-kit/blob/main/LICENSE)
|
|
4
|
+
|
|
5
|
+
The parts every app on Cloudflare Workers ends up writing by hand, TanStack Start apps most of all.
|
|
4
6
|
|
|
5
7
|
It has no runtime dependencies. Each piece is its own entry point, so an app takes only what it uses.
|
|
6
8
|
|
|
@@ -13,7 +15,7 @@ Check this list before writing a helper in an app. Anything generic to TanStack
|
|
|
13
15
|
| `workers-start/entry` | `createEntry`, `withHeaders`, `wantsMarkdown`, `acceptsHtml` | The Worker entry: Markdown for agents, Accept fixes, 405s, headers on every response |
|
|
14
16
|
| `workers-start/head` | `createPageHead`, `jsonLdScript` | Per-route head tags and escaped JSON-LD |
|
|
15
17
|
| `workers-start/scripts` | `themeScript`, `analyticsScript`, `tagManagerScript`, `gaEvent`, `inlineJson` | Inline bootstraps, analytics events, JSON safe inside a script tag |
|
|
16
|
-
| `workers-start/cache` | `withEdgeCache`, `sharedMaxAge`, `withoutBrowserMaxAge`
|
|
18
|
+
| `workers-start/cache` | `withEdgeCache`, `sharedMaxAge`, `withoutBrowserMaxAge`, `cached`, `cachedEntry` | Rendered pages and computed values kept in the Workers Cache API |
|
|
17
19
|
| `workers-start/workers` | `getBinding`, `getEnvString`, `afterResponse`, `isKvNamespace` | Bindings and `waitUntil` without a static `cloudflare:workers` import |
|
|
18
20
|
| `workers-start/access` | `verifyAccessToken`, `createAccessVerifier`, `parseAccessConfig`, `accessToken` | Cloudflare Access sign-ins checked in the Worker, failing closed |
|
|
19
21
|
| `workers-start/access/testing` | `createTestAccessTeam` | A fake Access team for tests: keys, certs and signed tokens |
|
|
@@ -185,6 +187,26 @@ return withEdgeCache(request, () => handler.fetch(request), {
|
|
|
185
187
|
|
|
186
188
|
A cache hit has its browser `max-age` removed (the zone adds one, and a browser holding page HTML that long outlives the next deploy's assets). The store runs after the response through `afterResponse`; pass `waitUntil` or `cache` to override, as tests do. Outside workerd every request renders.
|
|
187
189
|
|
|
190
|
+
### Cached values
|
|
191
|
+
|
|
192
|
+
`cached(key, compute, options)` keeps a computed value (an upstream API's answer, an aggregate from the database) in the Cache API, with stale-while-revalidate and stale-if-error:
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
import { cached } from "workers-start/cache";
|
|
196
|
+
|
|
197
|
+
const gas = await cached("gas", () => fetchGasSnapshot(env), {
|
|
198
|
+
freshSeconds: 15,
|
|
199
|
+
staleSeconds: 600,
|
|
200
|
+
onError: (error) => console.error("gas refresh failed", error),
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
- Within `freshSeconds` the stored value is returned as is.
|
|
205
|
+
- Within `staleSeconds` after that it is returned too, and recomputed after the response, one refresh per key per isolate at a time.
|
|
206
|
+
- Older or missing, it is recomputed before answering. If that fails and an earlier value is still stored, the earlier value is returned and the error goes to `onError`; with nothing stored, the error is thrown.
|
|
207
|
+
- Values live in each location's Cache API, which has no write limit or cost. Pass `kv` to share them across locations too, for an upstream too slow or rate limited to call once per location; a location then warms its own cache from KV.
|
|
208
|
+
- `version` is added to every key, so a deploy that changes the value's shape starts fresh. Values must be JSON. `cachedEntry` returns `{ value, at, stale }` instead of the value, for a page that shows how old its numbers are.
|
|
209
|
+
|
|
188
210
|
## Cloudflare Access
|
|
189
211
|
|
|
190
212
|
Access adds a signed JWT to every request it lets through, as the `Cf-Access-Jwt-Assertion` header and the `CF_Authorization` cookie. The header alone proves nothing: anyone can send it to the Worker's `workers.dev` or other hostnames, and paths Access does not cover (such as `/_serverFn`) never get one. `workers-start/access` checks the token itself, on WebCrypto with no dependencies: the RS256 signature against the team's published keys, the issuer, the audience, `exp` and `nbf` (60 seconds of leeway), then the email against an allowlist.
|
package/dist/cache.d.ts
CHANGED
|
@@ -38,4 +38,60 @@ export declare function withoutBrowserMaxAge(response: Response): Response;
|
|
|
38
38
|
* Cache-Control allows a shared cache to keep it.
|
|
39
39
|
*/
|
|
40
40
|
export declare function withEdgeCache(request: Request, render: () => Promise<Response>, options?: EdgeCacheOptions): Promise<Response>;
|
|
41
|
+
/** A KV namespace, structurally. */
|
|
42
|
+
export interface CachedKv {
|
|
43
|
+
get(key: string): Promise<string | null>;
|
|
44
|
+
put(key: string, value: string, options?: {
|
|
45
|
+
expirationTtl?: number;
|
|
46
|
+
}): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
export interface CachedOptions {
|
|
49
|
+
/** Served as is for this long after it was computed. */
|
|
50
|
+
freshSeconds: number;
|
|
51
|
+
/**
|
|
52
|
+
* After that, served for this much longer while one refresh runs after the
|
|
53
|
+
* response. Default 0: a value past fresh is recomputed before answering.
|
|
54
|
+
*/
|
|
55
|
+
staleSeconds?: number;
|
|
56
|
+
/**
|
|
57
|
+
* A KV namespace to share values across locations, for upstreams too slow
|
|
58
|
+
* or rate limited to call once per location. Without it, values live in
|
|
59
|
+
* each location's Cache API, which has no write limit or cost.
|
|
60
|
+
*/
|
|
61
|
+
kv?: CachedKv;
|
|
62
|
+
/** Added to every key, so a deploy that changes the value's shape starts fresh. */
|
|
63
|
+
version?: string;
|
|
64
|
+
/** The Cache to use. Default `caches.default`; none outside workerd. */
|
|
65
|
+
cache?: Pick<Cache, "match" | "put">;
|
|
66
|
+
/** Schedules background refreshes and stores. Default `afterResponse`. */
|
|
67
|
+
waitUntil?: (work: Promise<unknown>) => void;
|
|
68
|
+
/** Hears a failed compute that was answered with a stale value instead, or a failed store. */
|
|
69
|
+
onError?: (error: unknown) => void;
|
|
70
|
+
/** Milliseconds since the epoch. */
|
|
71
|
+
now?: () => number;
|
|
72
|
+
}
|
|
73
|
+
export interface CachedEntry<T> {
|
|
74
|
+
value: T;
|
|
75
|
+
/** When the value was computed, in milliseconds since the epoch. */
|
|
76
|
+
at: number;
|
|
77
|
+
/** True when the value is past `freshSeconds`. */
|
|
78
|
+
stale: boolean;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* A value computed at most once per `freshSeconds`, kept in the Cache API
|
|
82
|
+
* (and in KV, when given), with stale-while-revalidate and stale-if-error:
|
|
83
|
+
*
|
|
84
|
+
* - fresh: returned as is;
|
|
85
|
+
* - within `staleSeconds` after that: returned, and recomputed after the
|
|
86
|
+
* response (one refresh per key per isolate at a time);
|
|
87
|
+
* - older, or missing: recomputed before answering. If that fails and any
|
|
88
|
+
* earlier value is still stored, the earlier value is returned (with
|
|
89
|
+
* `stale: true`) and the error goes to `onError`; with nothing stored, the
|
|
90
|
+
* error is thrown.
|
|
91
|
+
*
|
|
92
|
+
* Values must be JSON. Keys are any string.
|
|
93
|
+
*/
|
|
94
|
+
export declare function cachedEntry<T>(key: string, compute: () => Promise<T>, options: CachedOptions): Promise<CachedEntry<T>>;
|
|
95
|
+
/** `cachedEntry`, returning only the value. */
|
|
96
|
+
export declare function cached<T>(key: string, compute: () => Promise<T>, options: CachedOptions): Promise<T>;
|
|
41
97
|
//# sourceMappingURL=cache.d.ts.map
|
package/dist/cache.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,KAAK,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAAC,CAAC;IACrC;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;CAC9C;AAKD,wEAAwE;AACxE,wBAAgB,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAGvD;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAajE;AAMD;;;GAGG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,EAC/B,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,QAAQ,CAAC,CAsBnB"}
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["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GAAG,KAAK,CAAC,CAAC;IACrC,0EAA0E;IAC1E,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;IAC7C,8FAA8F;IAC9F,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,oCAAoC;IACpC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,KAAK,EAAE,CAAC,CAAC;IACT,oEAAoE;IACpE,EAAE,EAAE,MAAM,CAAC;IACX,kDAAkD;IAClD,KAAK,EAAE,OAAO,CAAC;CAChB;AASD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACzB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAwEzB;AAED,+CAA+C;AAC/C,wBAAsB,MAAM,CAAC,CAAC,EAC5B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACzB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,CAAC,CAAC,CAEZ"}
|
package/dist/cache.js
CHANGED
|
@@ -61,4 +61,105 @@ export async function withEdgeCache(request, render, options = {}) {
|
|
|
61
61
|
}
|
|
62
62
|
return response;
|
|
63
63
|
}
|
|
64
|
+
const refreshing = new Map();
|
|
65
|
+
/**
|
|
66
|
+
* A value computed at most once per `freshSeconds`, kept in the Cache API
|
|
67
|
+
* (and in KV, when given), with stale-while-revalidate and stale-if-error:
|
|
68
|
+
*
|
|
69
|
+
* - fresh: returned as is;
|
|
70
|
+
* - within `staleSeconds` after that: returned, and recomputed after the
|
|
71
|
+
* response (one refresh per key per isolate at a time);
|
|
72
|
+
* - older, or missing: recomputed before answering. If that fails and any
|
|
73
|
+
* earlier value is still stored, the earlier value is returned (with
|
|
74
|
+
* `stale: true`) and the error goes to `onError`; with nothing stored, the
|
|
75
|
+
* error is thrown.
|
|
76
|
+
*
|
|
77
|
+
* Values must be JSON. Keys are any string.
|
|
78
|
+
*/
|
|
79
|
+
export async function cachedEntry(key, compute, options) {
|
|
80
|
+
const now = options.now ?? Date.now;
|
|
81
|
+
const freshMs = options.freshSeconds * 1000;
|
|
82
|
+
const staleMs = (options.staleSeconds ?? 0) * 1000;
|
|
83
|
+
const keepSeconds = Math.max(60, Math.ceil(options.freshSeconds + (options.staleSeconds ?? 0)) * 4);
|
|
84
|
+
const fullKey = options.version ? `${options.version}:${key}` : key;
|
|
85
|
+
const cache = options.cache ?? defaultCache();
|
|
86
|
+
const cacheKey = new Request(`https://workers-start.cache/${encodeURIComponent(fullKey)}`);
|
|
87
|
+
const later = (work) => {
|
|
88
|
+
const guarded = work.catch((error) => options.onError?.(error));
|
|
89
|
+
if (options.waitUntil)
|
|
90
|
+
options.waitUntil(guarded);
|
|
91
|
+
else
|
|
92
|
+
void afterResponse(guarded);
|
|
93
|
+
};
|
|
94
|
+
const read = async () => {
|
|
95
|
+
const hit = cache ? await cache.match(cacheKey) : undefined;
|
|
96
|
+
if (hit)
|
|
97
|
+
return (await hit.json());
|
|
98
|
+
if (!options.kv)
|
|
99
|
+
return null;
|
|
100
|
+
const raw = await options.kv.get(fullKey);
|
|
101
|
+
if (!raw)
|
|
102
|
+
return null;
|
|
103
|
+
const envelope = JSON.parse(raw);
|
|
104
|
+
if (cache)
|
|
105
|
+
later(cache.put(cacheKey, toResponse(envelope, keepSeconds)));
|
|
106
|
+
return envelope;
|
|
107
|
+
};
|
|
108
|
+
const store = async (envelope) => {
|
|
109
|
+
const text = JSON.stringify(envelope);
|
|
110
|
+
await Promise.all([
|
|
111
|
+
cache?.put(cacheKey, toResponse(envelope, keepSeconds)),
|
|
112
|
+
options.kv?.put(fullKey, text, { expirationTtl: keepSeconds }),
|
|
113
|
+
]);
|
|
114
|
+
};
|
|
115
|
+
const refresh = () => {
|
|
116
|
+
const running = refreshing.get(fullKey);
|
|
117
|
+
if (running)
|
|
118
|
+
return running;
|
|
119
|
+
const next = (async () => {
|
|
120
|
+
const envelope = { at: now(), value: await compute() };
|
|
121
|
+
later(store(envelope));
|
|
122
|
+
return envelope;
|
|
123
|
+
})().finally(() => refreshing.delete(fullKey));
|
|
124
|
+
refreshing.set(fullKey, next);
|
|
125
|
+
return next;
|
|
126
|
+
};
|
|
127
|
+
let current = null;
|
|
128
|
+
try {
|
|
129
|
+
current = await read();
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
options.onError?.(error);
|
|
133
|
+
}
|
|
134
|
+
const age = current ? now() - current.at : Number.POSITIVE_INFINITY;
|
|
135
|
+
if (current && age <= freshMs) {
|
|
136
|
+
return { value: current.value, at: current.at, stale: false };
|
|
137
|
+
}
|
|
138
|
+
if (current && age <= freshMs + staleMs) {
|
|
139
|
+
later(refresh());
|
|
140
|
+
return { value: current.value, at: current.at, stale: true };
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
const fresh = await refresh();
|
|
144
|
+
return { value: fresh.value, at: fresh.at, stale: false };
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
if (!current)
|
|
148
|
+
throw error;
|
|
149
|
+
options.onError?.(error);
|
|
150
|
+
return { value: current.value, at: current.at, stale: true };
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/** `cachedEntry`, returning only the value. */
|
|
154
|
+
export async function cached(key, compute, options) {
|
|
155
|
+
return (await cachedEntry(key, compute, options)).value;
|
|
156
|
+
}
|
|
157
|
+
function toResponse(envelope, seconds) {
|
|
158
|
+
return new Response(JSON.stringify(envelope), {
|
|
159
|
+
headers: {
|
|
160
|
+
"content-type": "application/json",
|
|
161
|
+
"cache-control": `public, s-maxage=${seconds}, max-age=${seconds}`,
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
}
|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,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAC5D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,OAAO;YAAE,MAAM,KAAK,CAAC;QAC1B,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;QACzB,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAC/D,CAAC;AACH,CAAC;AAED,+CAA+C;AAC/C,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,GAAW,EACX,OAAyB,EACzB,OAAsB;IAEtB,OAAO,CAAC,MAAM,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;AAC1D,CAAC;AAED,SAAS,UAAU,CAAC,QAA2B,EAAE,OAAe;IAC9D,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE;QAC5C,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,eAAe,EAAE,oBAAoB,OAAO,aAAa,OAAO,EAAE;SACnE;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ export type { MediaRange } from "./accept.js";
|
|
|
2
2
|
export { parseAccept, quality } from "./accept.js";
|
|
3
3
|
export type { AccessConfig, AccessEnv, AccessFailure, AccessResult, AccessVerifier, AccessVerifierOptions, } from "./access.js";
|
|
4
4
|
export { accessToken, createAccessVerifier, parseAccessConfig, verifyAccessToken, } from "./access.js";
|
|
5
|
-
export type { EdgeCacheOptions } from "./cache.js";
|
|
6
|
-
export { sharedMaxAge, withEdgeCache, withoutBrowserMaxAge, } from "./cache.js";
|
|
5
|
+
export type { CachedEntry, CachedKv, CachedOptions, EdgeCacheOptions, } from "./cache.js";
|
|
6
|
+
export { cached, cachedEntry, sharedMaxAge, withEdgeCache, withoutBrowserMaxAge, } from "./cache.js";
|
|
7
7
|
export type { EntryOptions, FetchHandler, MarkdownPage, MarkdownResult, } from "./entry.js";
|
|
8
8
|
export { acceptsHtml, createEntry, defaultIsPage, MARKDOWN_HEADERS, mergeVary, normalizePath, underPrefix, wantsMarkdown, withHeaders, } from "./entry.js";
|
|
9
9
|
export type { Ga4DateRange, Ga4FilterExpression, Ga4Report, Ga4ReportRequest, Ga4RowObject, GoogleAuthOptions, GoogleCallOptions, GoogleTokenSource, SearchAnalyticsQuery, SearchAnalyticsRow, ServiceAccount, } from "./google.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACnD,YAAY,EACV,YAAY,EACZ,SAAS,EACT,aAAa,EACb,YAAY,EACZ,cAAc,EACd,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACnD,YAAY,EACV,YAAY,EACZ,SAAS,EACT,aAAa,EACb,YAAY,EACZ,cAAc,EACd,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,iBAAiB,EACjB,iBAA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EACV,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,cAAc,EACd,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,sBAAsB,EACtB,aAAa,EACb,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,eAAe,EACf,OAAO,EACP,UAAU,EACV,gBAAgB,EAChB,WAAW,GACZ,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,oBAAoB,EACpB,eAAe,EACf,mBAAmB,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,cAAc,EACd,YAAY,EACZ,aAAa,EACb,cAAc,EACd,QAAQ,EACR,mBAAmB,GACpB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC5D,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EACL,aAAa,EACb,UAAU,EACV,YAAY,EACZ,aAAa,EACb,WAAW,EACX,gBAAgB,GACjB,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { parseAccept, quality } from "./accept.js";
|
|
2
2
|
export { accessToken, createAccessVerifier, parseAccessConfig, verifyAccessToken, } from "./access.js";
|
|
3
|
-
export { sharedMaxAge, withEdgeCache, withoutBrowserMaxAge, } from "./cache.js";
|
|
3
|
+
export { cached, cachedEntry, sharedMaxAge, withEdgeCache, withoutBrowserMaxAge, } from "./cache.js";
|
|
4
4
|
export { acceptsHtml, createEntry, defaultIsPage, MARKDOWN_HEADERS, mergeVary, normalizePath, underPrefix, wantsMarkdown, withHeaders, } from "./entry.js";
|
|
5
5
|
export { createGoogleAuth, GA4_SCOPE, GOOGLE_TOKEN_URL, GoogleApiError, ga4BatchRunReports, ga4Rows, ga4RunReport, googleAccessToken, importServiceAccountKey, inListFilter, parseServiceAccount, SEARCH_CONSOLE_SCOPE, searchConsoleQuery, serviceAccountJwt, } from "./google.js";
|
|
6
6
|
export { createPageHead, jsonLdScript } from "./head.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AASnD,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AASnD,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAOrB,OAAO,EACL,MAAM,EACN,WAAW,EACX,YAAY,EACZ,aAAa,EACb,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAOpB,OAAO,EACL,WAAW,EACX,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,WAAW,EACX,aAAa,EACb,WAAW,GACZ,MAAM,YAAY,CAAC;AAcpB,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,OAAO,EACP,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,EACvB,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAUrB,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAUzD,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,SAAS,EACT,eAAe,EACf,YAAY,GACb,MAAM,WAAW,CAAC;AAMnB,OAAO,EACL,cAAc,EACd,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,eAAe,GAChB,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EACL,eAAe,EACf,OAAO,EACP,UAAU,EACV,gBAAgB,EAChB,WAAW,GACZ,MAAM,cAAc,CAAC;AAMtB,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,cAAc,EACd,YAAY,EACZ,aAAa,EACb,cAAc,EACd,QAAQ,EACR,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE5D,OAAO,EACL,aAAa,EACb,UAAU,EACV,YAAY,EACZ,aAAa,EACb,WAAW,EACX,gBAAgB,GACjB,MAAM,cAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "workers-start",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "The parts every
|
|
3
|
+
"version": "0.13.0",
|
|
4
|
+
"description": "The parts every app on Cloudflare Workers ends up writing: the TanStack Start entry with Markdown for agents, head tags, bindings, edge and value caches, Cloudflare Access checks, Google service-account calls, Sentry options, mail, rate limiting, and a check that no local secret ships in the build.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ryan Ghods",
|
|
7
7
|
"repository": {
|
package/src/cache.ts
CHANGED
|
@@ -93,3 +93,164 @@ export async function withEdgeCache(
|
|
|
93
93
|
}
|
|
94
94
|
return response;
|
|
95
95
|
}
|
|
96
|
+
|
|
97
|
+
/** A KV namespace, structurally. */
|
|
98
|
+
export interface CachedKv {
|
|
99
|
+
get(key: string): Promise<string | null>;
|
|
100
|
+
put(
|
|
101
|
+
key: string,
|
|
102
|
+
value: string,
|
|
103
|
+
options?: { expirationTtl?: number },
|
|
104
|
+
): Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface CachedOptions {
|
|
108
|
+
/** Served as is for this long after it was computed. */
|
|
109
|
+
freshSeconds: number;
|
|
110
|
+
/**
|
|
111
|
+
* After that, served for this much longer while one refresh runs after the
|
|
112
|
+
* response. Default 0: a value past fresh is recomputed before answering.
|
|
113
|
+
*/
|
|
114
|
+
staleSeconds?: number;
|
|
115
|
+
/**
|
|
116
|
+
* A KV namespace to share values across locations, for upstreams too slow
|
|
117
|
+
* or rate limited to call once per location. Without it, values live in
|
|
118
|
+
* each location's Cache API, which has no write limit or cost.
|
|
119
|
+
*/
|
|
120
|
+
kv?: CachedKv;
|
|
121
|
+
/** Added to every key, so a deploy that changes the value's shape starts fresh. */
|
|
122
|
+
version?: string;
|
|
123
|
+
/** The Cache to use. Default `caches.default`; none outside workerd. */
|
|
124
|
+
cache?: Pick<Cache, "match" | "put">;
|
|
125
|
+
/** Schedules background refreshes and stores. Default `afterResponse`. */
|
|
126
|
+
waitUntil?: (work: Promise<unknown>) => void;
|
|
127
|
+
/** Hears a failed compute that was answered with a stale value instead, or a failed store. */
|
|
128
|
+
onError?: (error: unknown) => void;
|
|
129
|
+
/** Milliseconds since the epoch. */
|
|
130
|
+
now?: () => number;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface CachedEntry<T> {
|
|
134
|
+
value: T;
|
|
135
|
+
/** When the value was computed, in milliseconds since the epoch. */
|
|
136
|
+
at: number;
|
|
137
|
+
/** True when the value is past `freshSeconds`. */
|
|
138
|
+
stale: boolean;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface Envelope<T> {
|
|
142
|
+
at: number;
|
|
143
|
+
value: T;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const refreshing = new Map<string, Promise<unknown>>();
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* A value computed at most once per `freshSeconds`, kept in the Cache API
|
|
150
|
+
* (and in KV, when given), with stale-while-revalidate and stale-if-error:
|
|
151
|
+
*
|
|
152
|
+
* - fresh: returned as is;
|
|
153
|
+
* - within `staleSeconds` after that: returned, and recomputed after the
|
|
154
|
+
* response (one refresh per key per isolate at a time);
|
|
155
|
+
* - older, or missing: recomputed before answering. If that fails and any
|
|
156
|
+
* earlier value is still stored, the earlier value is returned (with
|
|
157
|
+
* `stale: true`) and the error goes to `onError`; with nothing stored, the
|
|
158
|
+
* error is thrown.
|
|
159
|
+
*
|
|
160
|
+
* Values must be JSON. Keys are any string.
|
|
161
|
+
*/
|
|
162
|
+
export async function cachedEntry<T>(
|
|
163
|
+
key: string,
|
|
164
|
+
compute: () => Promise<T>,
|
|
165
|
+
options: CachedOptions,
|
|
166
|
+
): Promise<CachedEntry<T>> {
|
|
167
|
+
const now = options.now ?? Date.now;
|
|
168
|
+
const freshMs = options.freshSeconds * 1000;
|
|
169
|
+
const staleMs = (options.staleSeconds ?? 0) * 1000;
|
|
170
|
+
const keepSeconds = Math.max(
|
|
171
|
+
60,
|
|
172
|
+
Math.ceil(options.freshSeconds + (options.staleSeconds ?? 0)) * 4,
|
|
173
|
+
);
|
|
174
|
+
const fullKey = options.version ? `${options.version}:${key}` : key;
|
|
175
|
+
const cache = options.cache ?? defaultCache();
|
|
176
|
+
const cacheKey = new Request(
|
|
177
|
+
`https://workers-start.cache/${encodeURIComponent(fullKey)}`,
|
|
178
|
+
);
|
|
179
|
+
const later = (work: Promise<unknown>) => {
|
|
180
|
+
const guarded = work.catch((error) => options.onError?.(error));
|
|
181
|
+
if (options.waitUntil) options.waitUntil(guarded);
|
|
182
|
+
else void afterResponse(guarded);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const read = async (): Promise<Envelope<T> | null> => {
|
|
186
|
+
const hit = cache ? await cache.match(cacheKey) : undefined;
|
|
187
|
+
if (hit) return (await hit.json()) as Envelope<T>;
|
|
188
|
+
if (!options.kv) return null;
|
|
189
|
+
const raw = await options.kv.get(fullKey);
|
|
190
|
+
if (!raw) return null;
|
|
191
|
+
const envelope = JSON.parse(raw) as Envelope<T>;
|
|
192
|
+
if (cache) later(cache.put(cacheKey, toResponse(envelope, keepSeconds)));
|
|
193
|
+
return envelope;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const store = async (envelope: Envelope<T>) => {
|
|
197
|
+
const text = JSON.stringify(envelope);
|
|
198
|
+
await Promise.all([
|
|
199
|
+
cache?.put(cacheKey, toResponse(envelope, keepSeconds)),
|
|
200
|
+
options.kv?.put(fullKey, text, { expirationTtl: keepSeconds }),
|
|
201
|
+
]);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const refresh = (): Promise<Envelope<T>> => {
|
|
205
|
+
const running = refreshing.get(fullKey) as Promise<Envelope<T>> | undefined;
|
|
206
|
+
if (running) return running;
|
|
207
|
+
const next = (async () => {
|
|
208
|
+
const envelope = { at: now(), value: await compute() };
|
|
209
|
+
later(store(envelope));
|
|
210
|
+
return envelope;
|
|
211
|
+
})().finally(() => refreshing.delete(fullKey));
|
|
212
|
+
refreshing.set(fullKey, next);
|
|
213
|
+
return next;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
let current: Envelope<T> | null = null;
|
|
217
|
+
try {
|
|
218
|
+
current = await read();
|
|
219
|
+
} catch (error) {
|
|
220
|
+
options.onError?.(error);
|
|
221
|
+
}
|
|
222
|
+
const age = current ? now() - current.at : Number.POSITIVE_INFINITY;
|
|
223
|
+
if (current && age <= freshMs) {
|
|
224
|
+
return { value: current.value, at: current.at, stale: false };
|
|
225
|
+
}
|
|
226
|
+
if (current && age <= freshMs + staleMs) {
|
|
227
|
+
later(refresh());
|
|
228
|
+
return { value: current.value, at: current.at, stale: true };
|
|
229
|
+
}
|
|
230
|
+
try {
|
|
231
|
+
const fresh = await refresh();
|
|
232
|
+
return { value: fresh.value, at: fresh.at, stale: false };
|
|
233
|
+
} catch (error) {
|
|
234
|
+
if (!current) throw error;
|
|
235
|
+
options.onError?.(error);
|
|
236
|
+
return { value: current.value, at: current.at, stale: true };
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** `cachedEntry`, returning only the value. */
|
|
241
|
+
export async function cached<T>(
|
|
242
|
+
key: string,
|
|
243
|
+
compute: () => Promise<T>,
|
|
244
|
+
options: CachedOptions,
|
|
245
|
+
): Promise<T> {
|
|
246
|
+
return (await cachedEntry(key, compute, options)).value;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function toResponse(envelope: Envelope<unknown>, seconds: number): Response {
|
|
250
|
+
return new Response(JSON.stringify(envelope), {
|
|
251
|
+
headers: {
|
|
252
|
+
"content-type": "application/json",
|
|
253
|
+
"cache-control": `public, s-maxage=${seconds}, max-age=${seconds}`,
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -14,8 +14,15 @@ export {
|
|
|
14
14
|
parseAccessConfig,
|
|
15
15
|
verifyAccessToken,
|
|
16
16
|
} from "./access.js";
|
|
17
|
-
export type {
|
|
17
|
+
export type {
|
|
18
|
+
CachedEntry,
|
|
19
|
+
CachedKv,
|
|
20
|
+
CachedOptions,
|
|
21
|
+
EdgeCacheOptions,
|
|
22
|
+
} from "./cache.js";
|
|
18
23
|
export {
|
|
24
|
+
cached,
|
|
25
|
+
cachedEntry,
|
|
19
26
|
sharedMaxAge,
|
|
20
27
|
withEdgeCache,
|
|
21
28
|
withoutBrowserMaxAge,
|