@ogygia/postrender 0.12.0 → 0.14.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 CHANGED
@@ -22,9 +22,12 @@ export default defineConfig({
22
22
  // src/hooks.server.ts — postrender's handle goes BEFORE ogygia's
23
23
  import { sequence } from '@sveltejs/kit/hooks';
24
24
  import * as ogygia from 'ogygia/server';
25
- import { postrender, valkey } from '@ogygia/postrender';
25
+ import { postrender, ValkeyStore } from '@ogygia/postrender';
26
26
 
27
- export const handle = sequence(postrender.handle({ store: valkey(client) }), ogygia.handle());
27
+ export const handle = sequence(
28
+ postrender.handle({ store: new ValkeyStore(client) }),
29
+ ogygia.handle()
30
+ );
28
31
  ```
29
32
 
30
33
  With no `store`, pages are kept in an in-process LRU.
@@ -1,4 +1,4 @@
1
- import { EdgeAdapter } from "../types.js";
1
+ import { EdgeAdapter, PostrenderMeta } from "../types.js";
2
2
  export interface AkamaiConfig {
3
3
  /** The EdgeGrid host, e.g. `akab-xxxx.purge.akamaiapis.net`. */
4
4
  host: string;
@@ -14,4 +14,19 @@ export interface AkamaiConfig {
14
14
  /** The s-maxage this edge is granted (defaults to the policy TTL in `headers(meta)`). */
15
15
  maxAge?: number;
16
16
  }
17
- export declare function akamai(config: AkamaiConfig): EdgeAdapter;
17
+ /**
18
+ * An Akamai edge: Fast Purge v3 by URL and by tag, with EdgeGrid request signing. `headers(meta)`
19
+ * stamps depth-capped prefix tags (`edge-cache-tag: p:/fr, p:/fr/fr, …`), and
20
+ * `purgeWhere({ prefix })` purges the matching tag, as Fast Purge has no prefix purge of its own.
21
+ * `baseUrl` points the same adapter at an emulator, so a test runs the real signing code.
22
+ */
23
+ export declare class AkamaiEdge implements EdgeAdapter {
24
+ #private;
25
+ readonly name: string;
26
+ constructor(config: AkamaiConfig);
27
+ headers(meta: PostrenderMeta): Record<string, string>;
28
+ purgeUrl(url: string): Promise<void>;
29
+ purgeWhere({ prefix }: {
30
+ prefix: string;
31
+ }): Promise<void>;
32
+ }
@@ -1,35 +1,54 @@
1
1
  import { normalize_prefix, prefix_tags } from "../key.js";
2
- import { createHash, createHmac, randomUUID } from "node:crypto";
2
+ import { OgygiaError } from "../messages.js";
3
+ import { clock, net, random } from "@ogygia/machine";
4
+ import { createHash, createHmac } from "node:crypto";
3
5
  // src/adapters/akamai.ts
4
- /**
5
- * postrender — Akamai edge adapter: Fast Purge v3 (url + tag) with real EdgeGrid request signing.
6
- *
7
- * `headers(meta)` stamps the depth-capped PREFIX tags (`edge-cache-tag: p:/fr, p:/fr/fr, …`) the
8
- * property stores by; `purgeWhere({ prefix })` purges the matching tag — Fast Purge has no
9
- * arbitrary-prefix purge, tags ARE the prefix mechanism. `purgeUrl` purges by absolute URL.
10
- *
11
- * `baseUrl` override points the SAME adapter at the harness's edge emulator — e2e exercises this
12
- * exact signing/requesting code, not a mock of it.
13
- */
14
6
  const TRAILING_SLASHES_RE = /\/+$/;
15
- /** EdgeGrid timestamp: `yyyyMMddTHH:mm:ss+0000`. */
16
7
  function edgegrid_timestamp() {
17
- const d = /* @__PURE__ */ new Date();
8
+ const d = new Date(clock.wall());
18
9
  const pad = (n) => String(n).padStart(2, "0");
19
10
  return `${d.getUTCFullYear()}${pad(d.getUTCMonth() + 1)}${pad(d.getUTCDate())}T${pad(d.getUTCHours())}:${pad(d.getUTCMinutes())}:${pad(d.getUTCSeconds())}+0000`;
20
11
  }
21
12
  const b64_hmac = (key, data) => createHmac("sha256", key).update(data).digest("base64");
22
13
  const b64_sha = (data) => createHash("sha256").update(data).digest("base64");
23
- function akamai(config) {
24
- const network = config.network ?? "production";
25
- const api_base = (config.baseUrl ?? `https://${config.host}`).replace(TRAILING_SLASHES_RE, "");
14
+ /**
15
+ * An Akamai edge: Fast Purge v3 by URL and by tag, with EdgeGrid request signing. `headers(meta)`
16
+ * stamps depth-capped prefix tags (`edge-cache-tag: p:/fr, p:/fr/fr, …`), and
17
+ * `purgeWhere({ prefix })` purges the matching tag, as Fast Purge has no prefix purge of its own.
18
+ * `baseUrl` points the same adapter at an emulator, so a test runs the real signing code.
19
+ */
20
+ var AkamaiEdge = class {
21
+ name = "akamai";
22
+ #config;
23
+ #network;
24
+ #api_base;
25
+ constructor(config) {
26
+ this.#config = config;
27
+ this.#network = config.network ?? "production";
28
+ this.#api_base = (config.baseUrl ?? `https://${config.host}`).replace(TRAILING_SLASHES_RE, "");
29
+ }
30
+ headers(meta) {
31
+ const tags = prefix_tags(meta.url).map((p) => `p:${p}`);
32
+ const out = {};
33
+ if (tags.length) out["edge-cache-tag"] = tags.join(", ");
34
+ const max_age = this.#config.maxAge ?? meta.ttl;
35
+ if (max_age > 0) out["cache-control"] = `public, s-maxage=${max_age}`;
36
+ return out;
37
+ }
38
+ async purgeUrl(url) {
39
+ await this.#signed_post(`/ccu/v3/invalidate/url/${this.#network}`, { objects: [this.#config.site.replace(TRAILING_SLASHES_RE, "") + url] });
40
+ }
41
+ async purgeWhere({ prefix }) {
42
+ await this.#signed_post(`/ccu/v3/invalidate/tag/${this.#network}`, { objects: [`p:${normalize_prefix(prefix)}`] });
43
+ }
26
44
  /** Real EdgeGrid signing (EG1-HMAC-SHA256) over the canonical request. */
27
- const signed_post = async (path, body) => {
45
+ async #signed_post(path, body) {
46
+ const config = this.#config;
28
47
  const payload = JSON.stringify(body);
29
48
  const timestamp = edgegrid_timestamp();
30
- const nonce = randomUUID();
49
+ const nonce = random.uuid();
31
50
  const auth_prefix = `EG1-HMAC-SHA256 client_token=${config.clientToken};access_token=${config.accessToken};timestamp=${timestamp};nonce=${nonce};`;
32
- const url = new URL(api_base + path);
51
+ const url = new URL(this.#api_base + path);
33
52
  const data_to_sign = [
34
53
  "POST",
35
54
  url.protocol.replace(":", ""),
@@ -41,7 +60,7 @@ function akamai(config) {
41
60
  ].join(" ");
42
61
  const signing_key = b64_hmac(config.clientSecret, timestamp);
43
62
  const signature = b64_hmac(signing_key, data_to_sign);
44
- const res = await fetch(url, {
63
+ const res = await net.fetch(url, {
45
64
  method: "POST",
46
65
  headers: {
47
66
  "content-type": "application/json",
@@ -49,24 +68,11 @@ function akamai(config) {
49
68
  },
50
69
  body: payload
51
70
  });
52
- if (!res.ok) throw new Error(`[ogygia] akamai purge failed: ${res.status} ${await res.text().catch(() => "")}`);
53
- };
54
- return {
55
- name: "akamai",
56
- headers(meta) {
57
- const tags = prefix_tags(meta.url).map((p) => `p:${p}`);
58
- const out = {};
59
- if (tags.length) out["edge-cache-tag"] = tags.join(", ");
60
- const max_age = config.maxAge ?? meta.ttl;
61
- if (max_age > 0) out["cache-control"] = `public, s-maxage=${max_age}`;
62
- return out;
63
- },
64
- async purgeUrl(url) {
65
- await signed_post(`/ccu/v3/invalidate/url/${network}`, { objects: [config.site.replace(TRAILING_SLASHES_RE, "") + url] });
66
- },
67
- async purgeWhere({ prefix }) {
68
- await signed_post(`/ccu/v3/invalidate/tag/${network}`, { objects: [`p:${normalize_prefix(prefix)}`] });
69
- }
70
- };
71
- }
72
- export { akamai };
71
+ if (!res.ok) throw new OgygiaError("postrender_adapter_request_failed", {
72
+ what: "akamai purge",
73
+ status: res.status,
74
+ body: await res.text().catch(() => "")
75
+ });
76
+ }
77
+ };
78
+ export { AkamaiEdge };
@@ -1,4 +1,4 @@
1
- import { PostrenderStore } from "../types.js";
1
+ import { PostrenderEntry, PostrenderPutOptions, PostrenderStore } from "../types.js";
2
2
  /** The minimal Workers KV binding surface (KVNamespace, structurally). */
3
3
  export interface KvNamespaceLike {
4
4
  get(key: string, type: "text"): Promise<string | null>;
@@ -17,4 +17,26 @@ export interface KvNamespaceLike {
17
17
  cursor?: string;
18
18
  }>;
19
19
  }
20
- export declare function cloudflareKv(kv: KvNamespaceLike): PostrenderStore;
20
+ /**
21
+ * A store on Cloudflare Workers KV, with the Worker's own binding. KV has no sets and no scans but
22
+ * lists by key prefix: pages are `og:a:<pathname>` (subtree eviction is one list) and each tag is
23
+ * a set of sentinel keys `og:t:<tag>:<pathname>` (tag eviction is one list).
24
+ *
25
+ * Differences from the other stores: KV is eventually consistent (an invalidation can serve the
26
+ * old copy for about a minute at far locations), and a TTL under 60 seconds is raised to 60, KV's
27
+ * floor.
28
+ *
29
+ * import { env } from 'cloudflare:workers';
30
+ * postrender.handle({ store: new CloudflareKvStore(env.PAGES) })
31
+ */
32
+ export declare class CloudflareKvStore implements PostrenderStore {
33
+ #private;
34
+ constructor(kv: KvNamespaceLike);
35
+ get(key: string): Promise<PostrenderEntry | null>;
36
+ put(key: string, entry: PostrenderEntry, { ttl, tags }: PostrenderPutOptions): Promise<void>;
37
+ evict(key: string): Promise<void>;
38
+ evictWhere({ prefix }: {
39
+ prefix: string;
40
+ }): Promise<void>;
41
+ evictByTag(tag: string): Promise<string[]>;
42
+ }
@@ -3,12 +3,65 @@ import { normalize_prefix, subtree_prefix } from "../key.js";
3
3
  const KEY_NS = "og:a:";
4
4
  const TAG_NS = "og:t:";
5
5
  const KV_MIN_TTL = 60;
6
- function cloudflareKv(kv) {
7
- const list_prefix = async (prefix) => {
6
+ /**
7
+ * A store on Cloudflare Workers KV, with the Worker's own binding. KV has no sets and no scans but
8
+ * lists by key prefix: pages are `og:a:<pathname>` (subtree eviction is one list) and each tag is
9
+ * a set of sentinel keys `og:t:<tag>:<pathname>` (tag eviction is one list).
10
+ *
11
+ * Differences from the other stores: KV is eventually consistent (an invalidation can serve the
12
+ * old copy for about a minute at far locations), and a TTL under 60 seconds is raised to 60, KV's
13
+ * floor.
14
+ *
15
+ * import { env } from 'cloudflare:workers';
16
+ * postrender.handle({ store: new CloudflareKvStore(env.PAGES) })
17
+ */
18
+ var CloudflareKvStore = class {
19
+ #kv;
20
+ constructor(kv) {
21
+ this.#kv = kv;
22
+ }
23
+ async get(key) {
24
+ const raw = await this.#kv.get(KEY_NS + key, "text");
25
+ if (!raw) return null;
26
+ try {
27
+ return JSON.parse(raw);
28
+ } catch {
29
+ return null;
30
+ }
31
+ }
32
+ async put(key, entry, { ttl, tags }) {
33
+ const kv = this.#kv;
34
+ const expirationTtl = Math.max(KV_MIN_TTL, ttl);
35
+ await kv.put(KEY_NS + key, JSON.stringify(entry), { expirationTtl });
36
+ for (const tag of tags ?? []) await kv.put(`${TAG_NS}${tag}:${key}`, "1", { expirationTtl });
37
+ }
38
+ async evict(key) {
39
+ await this.#kv.delete(KEY_NS + key);
40
+ }
41
+ async evictWhere({ prefix }) {
42
+ const kv = this.#kv;
43
+ const p = normalize_prefix(prefix);
44
+ for (const name of await this.#list_prefix(KEY_NS + subtree_prefix(p))) await kv.delete(name);
45
+ await kv.delete(KEY_NS + p);
46
+ }
47
+ async evictByTag(tag) {
48
+ const kv = this.#kv;
49
+ const sentinel_prefix = `${TAG_NS}${tag}:`;
50
+ const sentinels = await this.#list_prefix(sentinel_prefix);
51
+ const keys = [];
52
+ for (const name of sentinels) {
53
+ const key = name.slice(sentinel_prefix.length);
54
+ keys.push(key);
55
+ await kv.delete(KEY_NS + key);
56
+ await kv.delete(name);
57
+ }
58
+ return keys;
59
+ }
60
+ async #list_prefix(prefix) {
8
61
  const names = [];
9
62
  let cursor;
10
63
  do {
11
- const page = await kv.list({
64
+ const page = await this.#kv.list({
12
65
  prefix,
13
66
  cursor
14
67
  });
@@ -16,42 +69,6 @@ function cloudflareKv(kv) {
16
69
  cursor = page.list_complete ? void 0 : page.cursor;
17
70
  } while (cursor);
18
71
  return names;
19
- };
20
- return {
21
- async get(key) {
22
- const raw = await kv.get(KEY_NS + key, "text");
23
- if (!raw) return null;
24
- try {
25
- return JSON.parse(raw);
26
- } catch {
27
- return null;
28
- }
29
- },
30
- async put(key, entry, { ttl, tags }) {
31
- const expirationTtl = Math.max(KV_MIN_TTL, ttl);
32
- await kv.put(KEY_NS + key, JSON.stringify(entry), { expirationTtl });
33
- for (const tag of tags ?? []) await kv.put(`${TAG_NS}${tag}:${key}`, "1", { expirationTtl });
34
- },
35
- async evict(key) {
36
- await kv.delete(KEY_NS + key);
37
- },
38
- async evictWhere({ prefix }) {
39
- const p = normalize_prefix(prefix);
40
- for (const name of await list_prefix(KEY_NS + subtree_prefix(p))) await kv.delete(name);
41
- await kv.delete(KEY_NS + p);
42
- },
43
- async evictByTag(tag) {
44
- const sentinel_prefix = `${TAG_NS}${tag}:`;
45
- const sentinels = await list_prefix(sentinel_prefix);
46
- const keys = [];
47
- for (const name of sentinels) {
48
- const key = name.slice(sentinel_prefix.length);
49
- keys.push(key);
50
- await kv.delete(KEY_NS + key);
51
- await kv.delete(name);
52
- }
53
- return keys;
54
- }
55
- };
56
- }
57
- export { cloudflareKv };
72
+ }
73
+ };
74
+ export { CloudflareKvStore };
@@ -1,4 +1,4 @@
1
- import { EdgeAdapter } from "../types.js";
1
+ import { EdgeAdapter, PostrenderMeta } from "../types.js";
2
2
  export interface CloudflareConfig {
3
3
  zoneId: string;
4
4
  /** An API token with `Zone.Cache Purge` permission (`authorization: Bearer <token>`). */
@@ -10,4 +10,19 @@ export interface CloudflareConfig {
10
10
  /** The s-maxage this edge is granted (defaults to the policy TTL in `headers(meta)`). */
11
11
  maxAge?: number;
12
12
  }
13
- export declare function cloudflare(config: CloudflareConfig): EdgeAdapter;
13
+ /**
14
+ * A Cloudflare edge: zone purge with a bearer API token. `purgeUrl` purges by files (every plan);
15
+ * `purgeWhere({ prefix })` purges by prefixes (`<host><prefix>`, Enterprise). `headers(meta)`
16
+ * stamps the depth-capped prefix tags under `cache-tag` (plans that do not read it ignore it)
17
+ * plus the verdict's `s-maxage`. `baseUrl` points the same adapter at an emulator.
18
+ */
19
+ export declare class CloudflareEdge implements EdgeAdapter {
20
+ #private;
21
+ readonly name: string;
22
+ constructor(config: CloudflareConfig);
23
+ headers(meta: PostrenderMeta): Record<string, string>;
24
+ purgeUrl(url: string): Promise<void>;
25
+ purgeWhere({ prefix }: {
26
+ prefix: string;
27
+ }): Promise<void>;
28
+ }
@@ -1,13 +1,44 @@
1
1
  import { normalize_prefix, prefix_tags } from "../key.js";
2
+ import { OgygiaError } from "../messages.js";
3
+ import { net } from "@ogygia/machine";
2
4
  // src/adapters/cloudflare.ts
3
5
  const TRAILING_SLASHES_RE = /\/+$/;
4
6
  const HTTP_SCHEME_RE = /^https?:\/\//;
5
- function cloudflare(config) {
6
- const api_base = (config.baseUrl ?? "https://api.cloudflare.com").replace(TRAILING_SLASHES_RE, "");
7
- const site = config.site.replace(TRAILING_SLASHES_RE, "");
8
- const site_host = site.replace(HTTP_SCHEME_RE, "");
9
- const purge = async (body) => {
10
- const res = await fetch(`${api_base}/client/v4/zones/${config.zoneId}/purge_cache`, {
7
+ /**
8
+ * A Cloudflare edge: zone purge with a bearer API token. `purgeUrl` purges by files (every plan);
9
+ * `purgeWhere({ prefix })` purges by prefixes (`<host><prefix>`, Enterprise). `headers(meta)`
10
+ * stamps the depth-capped prefix tags under `cache-tag` (plans that do not read it ignore it)
11
+ * plus the verdict's `s-maxage`. `baseUrl` points the same adapter at an emulator.
12
+ */
13
+ var CloudflareEdge = class {
14
+ name = "cloudflare";
15
+ #config;
16
+ #api_base;
17
+ #site;
18
+ #site_host;
19
+ constructor(config) {
20
+ this.#config = config;
21
+ this.#api_base = (config.baseUrl ?? "https://api.cloudflare.com").replace(TRAILING_SLASHES_RE, "");
22
+ this.#site = config.site.replace(TRAILING_SLASHES_RE, "");
23
+ this.#site_host = this.#site.replace(HTTP_SCHEME_RE, "");
24
+ }
25
+ headers(meta) {
26
+ const tags = prefix_tags(meta.url).map((p) => `p:${p}`);
27
+ const out = {};
28
+ if (tags.length) out["cache-tag"] = tags.join(",");
29
+ const max_age = this.#config.maxAge ?? meta.ttl;
30
+ if (max_age > 0) out["cache-control"] = `public, s-maxage=${max_age}`;
31
+ return out;
32
+ }
33
+ async purgeUrl(url) {
34
+ await this.#purge({ files: [this.#site + url] });
35
+ }
36
+ async purgeWhere({ prefix }) {
37
+ await this.#purge({ prefixes: [this.#site_host + normalize_prefix(prefix)] });
38
+ }
39
+ async #purge(body) {
40
+ const config = this.#config;
41
+ const res = await net.fetch(`${this.#api_base}/client/v4/zones/${config.zoneId}/purge_cache`, {
11
42
  method: "POST",
12
43
  headers: {
13
44
  authorization: `Bearer ${config.apiToken}`,
@@ -15,24 +46,11 @@ function cloudflare(config) {
15
46
  },
16
47
  body: JSON.stringify(body)
17
48
  });
18
- if (!res.ok) throw new Error(`[ogygia] cloudflare purge failed: ${res.status} ${await res.text().catch(() => "")}`);
19
- };
20
- return {
21
- name: "cloudflare",
22
- headers(meta) {
23
- const tags = prefix_tags(meta.url).map((p) => `p:${p}`);
24
- const out = {};
25
- if (tags.length) out["cache-tag"] = tags.join(",");
26
- const max_age = config.maxAge ?? meta.ttl;
27
- if (max_age > 0) out["cache-control"] = `public, s-maxage=${max_age}`;
28
- return out;
29
- },
30
- async purgeUrl(url) {
31
- await purge({ files: [site + url] });
32
- },
33
- async purgeWhere({ prefix }) {
34
- await purge({ prefixes: [site_host + normalize_prefix(prefix)] });
35
- }
36
- };
37
- }
38
- export { cloudflare };
49
+ if (!res.ok) throw new OgygiaError("postrender_adapter_request_failed", {
50
+ what: "cloudflare purge",
51
+ status: res.status,
52
+ body: await res.text().catch(() => "")
53
+ });
54
+ }
55
+ };
56
+ export { CloudflareEdge };
@@ -1,4 +1,4 @@
1
- import { EdgeAdapter } from "../types.js";
1
+ import { EdgeAdapter, PostrenderMeta } from "../types.js";
2
2
  export interface CloudfrontConfig {
3
3
  distributionId: string;
4
4
  accessKeyId: string;
@@ -6,4 +6,13 @@ export interface CloudfrontConfig {
6
6
  /** Harness override: send API calls here instead of the real AWS endpoint. */
7
7
  baseUrl?: string;
8
8
  }
9
- export declare function cloudfront(config: CloudfrontConfig): EdgeAdapter;
9
+ export declare class CloudFrontEdge implements EdgeAdapter {
10
+ #private;
11
+ readonly name: string;
12
+ constructor(config: CloudfrontConfig);
13
+ headers(_meta?: PostrenderMeta): Record<string, string>;
14
+ purgeUrl(url: string): Promise<void>;
15
+ purgeWhere({ prefix }: {
16
+ prefix: string;
17
+ }): Promise<void>;
18
+ }
@@ -1,4 +1,6 @@
1
1
  import { normalize_prefix } from "../key.js";
2
+ import { OgygiaError } from "../messages.js";
3
+ import { clock, net, random } from "@ogygia/machine";
2
4
  import { createHash, createHmac } from "node:crypto";
3
5
  // src/adapters/cloudfront.ts
4
6
  /**
@@ -22,17 +24,34 @@ const hex_sha = (data) => createHash("sha256").update(data).digest("hex");
22
24
  const hmac = (key, data) => createHmac("sha256", key).update(data).digest();
23
25
  /** amz dates: `20260901T120000Z` / `20260901`. */
24
26
  function amz_dates() {
25
- const iso = (/* @__PURE__ */ new Date()).toISOString().replace(DASH_COLON_G, "").replace(MILLISECONDS_RE, "");
27
+ const iso = new Date(clock.wall()).toISOString().replace(DASH_COLON_G, "").replace(MILLISECONDS_RE, "");
26
28
  return {
27
29
  datetime: iso,
28
30
  date: iso.slice(0, 8)
29
31
  };
30
32
  }
31
- function cloudfront(config) {
32
- const api_base = (config.baseUrl ?? `https://${API_HOST}`).replace(TRAILING_SLASHES_RE, "");
33
- const create_invalidation = async (paths) => {
33
+ var CloudFrontEdge = class {
34
+ name = "cloudfront";
35
+ #config;
36
+ #api_base;
37
+ constructor(config) {
38
+ this.#config = config;
39
+ this.#api_base = (config.baseUrl ?? `https://${API_HOST}`).replace(TRAILING_SLASHES_RE, "");
40
+ }
41
+ headers(_meta) {
42
+ return {};
43
+ }
44
+ async purgeUrl(url) {
45
+ await this.#create_invalidation([url]);
46
+ }
47
+ async purgeWhere({ prefix }) {
48
+ const p = normalize_prefix(prefix);
49
+ await this.#create_invalidation([p, `${p}/*`]);
50
+ }
51
+ async #create_invalidation(paths) {
52
+ const config = this.#config;
34
53
  const items = paths.map((p) => `<Path>${p}</Path>`).join("");
35
- const body = `<?xml version="1.0" encoding="UTF-8"?><InvalidationBatch xmlns="http://cloudfront.amazonaws.com/doc/${API_VERSION}/"><CallerReference>og-${Date.now()}-${Math.floor(Math.random() * 1e6)}</CallerReference><Paths><Quantity>${paths.length}</Quantity><Items>${items}</Items></Paths></InvalidationBatch>`;
54
+ const body = `<?xml version="1.0" encoding="UTF-8"?><InvalidationBatch xmlns="http://cloudfront.amazonaws.com/doc/${API_VERSION}/"><CallerReference>og-${clock.wall()}-${Math.floor(random.float() * 1e6)}</CallerReference><Paths><Quantity>${paths.length}</Quantity><Items>${items}</Items></Paths></InvalidationBatch>`;
36
55
  const path = `/${API_VERSION}/distribution/${config.distributionId}/invalidation`;
37
56
  const { datetime, date } = amz_dates();
38
57
  const payload_hash = hex_sha(body);
@@ -54,12 +73,12 @@ function cloudfront(config) {
54
73
  scope,
55
74
  hex_sha(canonical)
56
75
  ].join("\n");
57
- const k_date = hmac("AWS4" + config.secretAccessKey, date);
76
+ const k_date = hmac(`AWS4${config.secretAccessKey}`, date);
58
77
  const k_region = hmac(k_date, REGION);
59
78
  const k_service = hmac(k_region, SERVICE);
60
79
  const k_signing = hmac(k_service, "aws4_request");
61
80
  const signature = createHmac("sha256", k_signing).update(string_to_sign).digest("hex");
62
- const res = await fetch(api_base + path, {
81
+ const res = await net.fetch(this.#api_base + path, {
63
82
  method: "POST",
64
83
  headers: {
65
84
  host: API_HOST,
@@ -70,20 +89,11 @@ function cloudfront(config) {
70
89
  },
71
90
  body
72
91
  });
73
- if (!res.ok) throw new Error(`[ogygia] cloudfront invalidation failed: ${res.status} ${await res.text().catch(() => "")}`);
74
- };
75
- return {
76
- name: "cloudfront",
77
- headers() {
78
- return {};
79
- },
80
- async purgeUrl(url) {
81
- await create_invalidation([url]);
82
- },
83
- async purgeWhere({ prefix }) {
84
- const p = normalize_prefix(prefix);
85
- await create_invalidation([p, `${p}/*`]);
86
- }
87
- };
88
- }
89
- export { cloudfront };
92
+ if (!res.ok) throw new OgygiaError("postrender_adapter_request_failed", {
93
+ what: "cloudfront invalidation",
94
+ status: res.status,
95
+ body: await res.text().catch(() => "")
96
+ });
97
+ }
98
+ };
99
+ export { CloudFrontEdge };
@@ -1,7 +1,24 @@
1
- import { PostrenderStore } from "../types.js";
1
+ import { PostrenderEntry, PostrenderPutOptions, PostrenderStore } from "../types.js";
2
2
  export interface UpstashConfig {
3
3
  /** The REST endpoint, e.g. `https://usw1-xxxx.upstash.io`. */
4
4
  url: string;
5
5
  token: string;
6
6
  }
7
- export declare function upstash(config: UpstashConfig): PostrenderStore;
7
+ /**
8
+ * A store on Upstash Redis over its REST API: no client library and no connection, every command
9
+ * is one HTTPS call, which suits serverless and edge origins. The same keys as `ValkeyStore`.
10
+ *
11
+ * postrender.handle({ store: new UpstashStore({ url: env.UPSTASH_REDIS_REST_URL,
12
+ * token: env.UPSTASH_REDIS_REST_TOKEN }) })
13
+ */
14
+ export declare class UpstashStore implements PostrenderStore {
15
+ #private;
16
+ constructor(config: UpstashConfig);
17
+ get(key: string): Promise<PostrenderEntry | null>;
18
+ put(key: string, entry: PostrenderEntry, { ttl, tags }: PostrenderPutOptions): Promise<void>;
19
+ evict(key: string): Promise<void>;
20
+ evictWhere({ prefix }: {
21
+ prefix: string;
22
+ }): Promise<void>;
23
+ evictByTag(tag: string): Promise<string[]>;
24
+ }