@celestia-island/hikari 0.55.179 → 0.55.181

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celestia-island/hikari",
3
- "version": "0.55.179",
3
+ "version": "0.55.181",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Hikari Vue 3 component library — production-grade UI components based on shittim-chest design system",
@@ -58,6 +58,7 @@
58
58
  "vue": "^*"
59
59
  },
60
60
  "dependencies": {
61
+ "@celestia-island/tairitsu-transport": "^0.1",
61
62
  "@xterm/addon-fit": "^0.*",
62
63
  "@xterm/addon-image": "^0.10.0-beta.301",
63
64
  "@xterm/xterm": "^6.1.0-beta.304",
@@ -6,6 +6,8 @@
6
6
  * fails the origin is unreachable, otherwise the host responded but the
7
7
  * CORS policy rejected the credentialed request.
8
8
  */
9
+ import { bindHostFetch } from "@celestia-island/tairitsu-transport/contract";
10
+
9
11
  export type OriginProbe =
10
12
  | { ok: true }
11
13
  | { ok: false; reason: "unreachable" | "cors-blocked" };
@@ -14,7 +16,11 @@ export async function probeOrigin(
14
16
  url: string,
15
17
  opts?: { fetchFn?: typeof fetch },
16
18
  ): Promise<OriginProbe> {
17
- const fetchFn = opts?.fetchFn ?? fetch;
19
+ // Bare `?? fetch` detaches Window's fetch receiver — the default path
20
+ // throws "Illegal invocation" in a browser (2026-10-17 chest live
21
+ // report family). The shared bindHostFetch() from tairitsu-transport is
22
+ // the one sanctioned acquisition, re-resolved per call.
23
+ const fetchFn = opts?.fetchFn ?? bindHostFetch();
18
24
  try {
19
25
  // A successful credentialed fetch means reachable + CORS-whitelisted,
20
26
  // regardless of the HTTP status code (4xx/5xx still prove the origin).
@@ -41,7 +47,8 @@ export async function probeOriginWithBody(
41
47
  url: string,
42
48
  opts?: { fetchFn?: typeof fetch },
43
49
  ): Promise<{ ok: boolean; body?: string }> {
44
- const fetchFn = opts?.fetchFn ?? fetch;
50
+ // Same receiver rule as probeOrigin: never capture Window's fetch bare.
51
+ const fetchFn = opts?.fetchFn ?? bindHostFetch();
45
52
  try {
46
53
  const resp = await fetchFn(url, { credentials: "include", mode: "cors" });
47
54
  return { ok: true, body: await resp.text().catch(() => undefined) };
@@ -0,0 +1,94 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+
3
+ import { probeOrigin, probeOriginWithBody } from "./connectivity";
4
+ import { probeHealthEndpoint } from "./healthProbe";
5
+ import { fetchChallenge, negotiateNonce } from "./powNonce";
6
+
7
+ /**
8
+ * The browser's `fetch` is a Window method: capturing it as a bare value
9
+ * (`opts?.fetchFn ?? fetch`) detaches the receiver, and every default call
10
+ * throws "Failed to execute 'fetch' on 'Window': Illegal invocation"
11
+ * (2026-10-17 chest live report: branding silently fell back and health
12
+ * probes reported every panel unreachable — the TypeError was swallowed
13
+ * into `{ok:false}` results). Node's fetch does not check its receiver,
14
+ * so these tests stub the browser's exact contract — `this !== globalThis`
15
+ * rejects with the same TypeError — making a detached capture red here.
16
+ */
17
+ function stubWindowFetch(): void {
18
+ vi.stubGlobal(
19
+ "fetch",
20
+ vi.fn(function (this: unknown, input: RequestInfo | URL): Promise<Response> {
21
+ if (this !== globalThis) {
22
+ return Promise.reject(
23
+ new TypeError("Failed to execute 'fetch' on 'Window': Illegal invocation"),
24
+ );
25
+ }
26
+ const url = String(input);
27
+ if (url.endsWith("/health")) {
28
+ return Promise.resolve(new Response(JSON.stringify({}), { status: 200 }));
29
+ }
30
+ if (url.endsWith("/auth/nonce")) {
31
+ return Promise.resolve(
32
+ new Response(JSON.stringify({ nonce: "nonce-1" }), { status: 200 }),
33
+ );
34
+ }
35
+ // probeOrigin / probeOriginWithBody / health probe targets.
36
+ return Promise.resolve(new Response("pong", { status: 200 }));
37
+ }),
38
+ );
39
+ }
40
+
41
+ describe("connectivity / healthProbe / powNonce — default fetches keep the Window receiver", () => {
42
+ afterEach(() => {
43
+ vi.unstubAllGlobals();
44
+ });
45
+
46
+ it("probeOrigin's default fetchFn probes instead of throwing illegal invocation", async () => {
47
+ stubWindowFetch();
48
+
49
+ await expect(probeOrigin("https://panel.example/health")).resolves.toEqual({ ok: true });
50
+ });
51
+
52
+ it("probeOriginWithBody's default fetchFn captures the body", async () => {
53
+ stubWindowFetch();
54
+
55
+ // Non-/health URL: the stub's default branch answers the body "pong".
56
+ await expect(probeOriginWithBody("https://panel.example/ping")).resolves.toEqual({
57
+ ok: true,
58
+ body: "pong",
59
+ });
60
+ });
61
+
62
+ it("probeHealthEndpoint's default fetchFn reads a healthy body", async () => {
63
+ stubWindowFetch();
64
+
65
+ const result = await probeHealthEndpoint("https://panel.example/health");
66
+ expect(result.ok).toBe(true);
67
+ expect(result.body).toEqual({});
68
+ });
69
+
70
+ it("powNonce defaults complete the challenge/nonce exchange", async () => {
71
+ stubWindowFetch();
72
+
73
+ // `undefined` (fetch failed) would mean the default threw — the exact
74
+ // silent regression that dropped the X-Nonce on chest's live login.
75
+ await expect(fetchChallenge("/api")).resolves.toBe(null);
76
+ await expect(negotiateNonce("/api")).resolves.toBe("nonce-1");
77
+ });
78
+
79
+ it("an explicit fetchFn still wins over every default", async () => {
80
+ const guard = vi.fn(() => Promise.reject(new Error("global fetch must not be called")));
81
+ vi.stubGlobal("fetch", guard);
82
+ const explicit = vi.fn(async () => new Response("{}", { status: 200 }));
83
+
84
+ await probeOrigin("https://panel.example/", { fetchFn: explicit });
85
+ await probeOriginWithBody("https://panel.example/", { fetchFn: explicit });
86
+ await probeHealthEndpoint("https://panel.example/", { fetchFn: explicit });
87
+ await fetchChallenge("/api", explicit);
88
+ await negotiateNonce("/api", { fetchFn: explicit });
89
+
90
+ // negotiateNonce rides the explicit fn twice (challenge + exchange).
91
+ expect(explicit).toHaveBeenCalledTimes(6);
92
+ expect(guard).not.toHaveBeenCalled();
93
+ });
94
+ });
@@ -9,6 +9,8 @@
9
9
  * Pure function, no app config — callers bring the URL.
10
10
  */
11
11
 
12
+ import { bindHostFetch } from "@celestia-island/tairitsu-transport/contract";
13
+
12
14
  /** Minimal subset shared by all `/api/health` consumers. */
13
15
  export interface HealthProbeBody {
14
16
  status: string;
@@ -40,7 +42,12 @@ export async function probeHealthEndpoint(
40
42
  url: string,
41
43
  opts: { timeoutMs?: number; fetchFn?: typeof fetch } = {},
42
44
  ): Promise<HealthProbeResult> {
43
- const fetchFn = opts.fetchFn ?? fetch;
45
+ // Bare `?? fetch` captures Window's fetch detached — every default
46
+ // call throws "Illegal invocation" in a browser (2026-10-17 chest live
47
+ // report; the probe then silently reported every panel unreachable).
48
+ // The shared bindHostFetch() from tairitsu-transport re-attaches the
49
+ // receiver and re-resolves per call.
50
+ const fetchFn = opts.fetchFn ?? bindHostFetch();
44
51
  const started = performance.now();
45
52
  try {
46
53
  const resp = await fetchFn(url, {
@@ -1,3 +1,4 @@
1
+ import { bindHostFetch } from "@celestia-island/tairitsu-transport/contract";
1
2
  import { solvePow, type PowChallenge } from "./pow";
2
3
 
3
4
  export type ChallengeDescriptor =
@@ -29,7 +30,12 @@ function normalizeBase(baseUrl: string): string {
29
30
  */
30
31
  export async function fetchChallenge(
31
32
  baseUrl: string,
32
- fetchFn: typeof fetch = fetch,
33
+ // Bare `= fetch` captures Window's fetch detached — the default throws
34
+ // "Illegal invocation" in a browser (2026-10-17 chest live report
35
+ // family). The shared bindHostFetch() from tairitsu-transport
36
+ // re-attaches the receiver, re-resolved per call so vi.stubGlobal
37
+ // stubs stay visible.
38
+ fetchFn: typeof fetch = bindHostFetch(),
33
39
  ): Promise<ChallengeDescriptor | undefined> {
34
40
  let resp: Response;
35
41
  try {
@@ -59,7 +65,8 @@ export async function negotiateNonce(
59
65
  },
60
66
  ): Promise<string | undefined> {
61
67
  try {
62
- const fetchFn = opts?.fetchFn ?? fetch;
68
+ // Same receiver rule as fetchChallenge's default: never bare `?? fetch`.
69
+ const fetchFn = opts?.fetchFn ?? bindHostFetch();
63
70
  let body: Record<string, unknown> | undefined;
64
71
  if (opts?.captchaToken) {
65
72
  body = { type: "captcha", token: opts.captchaToken };