run402 2.10.0 → 2.11.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/cli.mjs +24 -0
- package/lib/cache.mjs +264 -0
- package/lib/dev.mjs +137 -0
- package/lib/doctor.mjs +188 -0
- package/lib/init-astro.mjs +277 -0
- package/lib/init.mjs +14 -0
- package/lib/logs.mjs +168 -0
- package/package.json +1 -1
- package/sdk/dist/index.d.ts +3 -0
- package/sdk/dist/index.d.ts.map +1 -1
- package/sdk/dist/index.js +3 -0
- package/sdk/dist/index.js.map +1 -1
- package/sdk/dist/namespaces/cache.d.ts +100 -0
- package/sdk/dist/namespaces/cache.d.ts.map +1 -0
- package/sdk/dist/namespaces/cache.js +104 -0
- package/sdk/dist/namespaces/cache.js.map +1 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `cache` namespace — SSR origin cache inspection and invalidation.
|
|
3
|
+
*
|
|
4
|
+
* Capability `ssr-isr-cache` (Run402 v1.52). Used by AI coding agents
|
|
5
|
+
* and CLI tooling to invalidate cached SSR responses after admin
|
|
6
|
+
* content edits, OR to inspect what's currently cached.
|
|
7
|
+
*
|
|
8
|
+
* All operations are project-scoped: the SDK reads the active project
|
|
9
|
+
* from the credentials provider, and the gateway enforces host
|
|
10
|
+
* ownership (cross-project hosts throw
|
|
11
|
+
* `R402_CACHE_INVALIDATION_HOST_FORBIDDEN`).
|
|
12
|
+
*
|
|
13
|
+
* @see https://docs.run402.com/cache/concepts
|
|
14
|
+
*/
|
|
15
|
+
import { LocalError } from "../errors.js";
|
|
16
|
+
export class Cache {
|
|
17
|
+
client;
|
|
18
|
+
constructor(client) {
|
|
19
|
+
this.client = client;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Invalidate a single cached SSR response.
|
|
23
|
+
*
|
|
24
|
+
* @param url - Absolute URL (e.g., `https://eagles.kychon.com/the-guys`).
|
|
25
|
+
* The host MUST be owned by the SDK's active project;
|
|
26
|
+
* cross-project calls throw `R402_CACHE_INVALIDATION_HOST_FORBIDDEN`.
|
|
27
|
+
*/
|
|
28
|
+
async invalidate(url) {
|
|
29
|
+
const u = url instanceof URL ? url : new URL(url);
|
|
30
|
+
return this.client.request("/cache/v1/invalidate", {
|
|
31
|
+
method: "POST",
|
|
32
|
+
body: {
|
|
33
|
+
kind: "exact",
|
|
34
|
+
host: u.host.toLowerCase(),
|
|
35
|
+
path: u.pathname + (u.search || ""),
|
|
36
|
+
},
|
|
37
|
+
context: "invalidating cache (exact URL)",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Invalidate all cache rows under a path prefix on the given host.
|
|
42
|
+
*/
|
|
43
|
+
async invalidatePrefix(opts) {
|
|
44
|
+
if (!opts.prefix.startsWith("/")) {
|
|
45
|
+
throw new LocalError("cache.invalidatePrefix: prefix must start with '/'", "invalidating cache (prefix)");
|
|
46
|
+
}
|
|
47
|
+
return this.client.request("/cache/v1/invalidate", {
|
|
48
|
+
method: "POST",
|
|
49
|
+
body: {
|
|
50
|
+
kind: "prefix",
|
|
51
|
+
host: opts.host.toLowerCase(),
|
|
52
|
+
prefix: opts.prefix,
|
|
53
|
+
},
|
|
54
|
+
context: "invalidating cache (prefix)",
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Invalidate ALL cache rows for the given host. Use for catastrophic
|
|
59
|
+
* content changes (nav restructure, layout-wide update, etc.) where
|
|
60
|
+
* targeted invalidation would be impractical.
|
|
61
|
+
*/
|
|
62
|
+
async invalidateAll(opts) {
|
|
63
|
+
return this.client.request("/cache/v1/invalidate", {
|
|
64
|
+
method: "POST",
|
|
65
|
+
body: {
|
|
66
|
+
kind: "all",
|
|
67
|
+
host: opts.host.toLowerCase(),
|
|
68
|
+
},
|
|
69
|
+
context: "invalidating cache (all)",
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Bulk-invalidate many absolute URLs in a single round-trip. Groups
|
|
74
|
+
* by host and issues one transaction per host.
|
|
75
|
+
*/
|
|
76
|
+
async invalidateMany(urls) {
|
|
77
|
+
const normalized = urls.map((u) => (u instanceof URL ? u.toString() : u));
|
|
78
|
+
return this.client.request("/cache/v1/invalidate", {
|
|
79
|
+
method: "POST",
|
|
80
|
+
body: { kind: "many", urls: normalized },
|
|
81
|
+
context: "invalidating cache (many)",
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Inspect the cache row state for a URL. Returns `{ status: 'HIT' | 'MISS', ... }`.
|
|
86
|
+
* Does NOT issue a request to the URL.
|
|
87
|
+
*
|
|
88
|
+
* @param url - Absolute URL.
|
|
89
|
+
* @param options - Optional `--locale` / `--release-id` overrides.
|
|
90
|
+
*/
|
|
91
|
+
async inspect(url, options = {}) {
|
|
92
|
+
const u = url instanceof URL ? url : new URL(url);
|
|
93
|
+
const params = new URLSearchParams();
|
|
94
|
+
params.set("host", u.host.toLowerCase());
|
|
95
|
+
params.set("path", u.pathname + (u.search || ""));
|
|
96
|
+
if (options.locale)
|
|
97
|
+
params.set("locale", options.locale);
|
|
98
|
+
if (options.releaseId)
|
|
99
|
+
params.set("release_id", options.releaseId);
|
|
100
|
+
const result = await this.client.request(`/cache/v1/inspect?${params.toString()}`, { context: "inspecting cache" });
|
|
101
|
+
return { ...result, url: url.toString() };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/namespaces/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAoD1C,MAAM,OAAO,KAAK;IACa;IAA7B,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAE/C;;;;;;OAMG;I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