@decocms/blocks 7.72.0 → 8.1.0-next.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.
Files changed (148) hide show
  1. package/bin/deco.js +13 -0
  2. package/package.json +32 -3
  3. package/src/cms/schema.ts +1 -1
  4. package/src/hooks/LiveControls.tsx +2 -0
  5. package/src/hooks/useLoadMore.ts +2 -0
  6. package/src/index.ts +37 -0
  7. package/src/protocol/assets.ts +124 -0
  8. package/src/protocol/canonical.ts +7 -0
  9. package/src/protocol/ciphertext.ts +6 -0
  10. package/src/protocol/client.ts +170 -0
  11. package/src/protocol/conformance/cases/assets.ts +81 -0
  12. package/src/protocol/conformance/cases/guards.ts +314 -0
  13. package/src/protocol/conformance/cases/reads.ts +168 -0
  14. package/src/protocol/conformance/cases/types.ts +9 -0
  15. package/src/protocol/conformance/cases/wire.ts +138 -0
  16. package/src/protocol/conformance/cases/writes.ts +345 -0
  17. package/src/protocol/conformance/contentHashFixtures.ts +79 -0
  18. package/src/protocol/conformance/context.ts +222 -0
  19. package/src/protocol/conformance/index.ts +140 -0
  20. package/src/protocol/errors.ts +142 -0
  21. package/src/protocol/index.ts +39 -0
  22. package/src/protocol/keys.ts +279 -0
  23. package/src/protocol/params.ts +67 -0
  24. package/src/protocol/secrets.ts +231 -0
  25. package/src/protocol/server/assets.ts +119 -0
  26. package/src/protocol/server/auth.ts +49 -0
  27. package/src/protocol/server/bodyCache.ts +84 -0
  28. package/src/protocol/server/content.ts +175 -0
  29. package/src/protocol/server/core.ts +112 -0
  30. package/src/protocol/server/handler.ts +102 -0
  31. package/src/protocol/server/http.ts +139 -0
  32. package/src/protocol/server/index.ts +11 -0
  33. package/src/protocol/server/methods/apply.ts +341 -0
  34. package/src/protocol/server/methods/read.ts +156 -0
  35. package/src/protocol/server/rpc.ts +136 -0
  36. package/src/protocol/storage/fs/hash.ts +21 -0
  37. package/src/protocol/storage/fs/index.ts +338 -0
  38. package/src/protocol/storage/fs/lock.ts +68 -0
  39. package/src/protocol/storage/fs/transaction.ts +183 -0
  40. package/src/protocol/storage/fs/unsupported.ts +15 -0
  41. package/src/protocol/storage/memory.ts +238 -0
  42. package/src/protocol/storage.ts +182 -0
  43. package/src/protocol/types.ts +172 -0
  44. package/src/v8/analytics.ts +50 -0
  45. package/src/v8/background.ts +107 -0
  46. package/src/v8/builtins/data.ts +23 -0
  47. package/src/v8/builtins/index.ts +26 -0
  48. package/src/v8/builtins/lazy.ts +23 -0
  49. package/src/v8/builtins/legacy.ts +65 -0
  50. package/src/v8/builtins/matchers.ts +31 -0
  51. package/src/v8/builtins/multivariate.ts +25 -0
  52. package/src/v8/builtins/secret.ts +82 -0
  53. package/src/v8/canonical.ts +117 -0
  54. package/src/v8/ciphertext.ts +158 -0
  55. package/src/v8/cli/builtins.ts +20 -0
  56. package/src/v8/cli/check/index.ts +774 -0
  57. package/src/v8/cli/check/messages.ts +168 -0
  58. package/src/v8/cli/content.ts +287 -0
  59. package/src/v8/cli/index.ts +17 -0
  60. package/src/v8/cli/log.ts +18 -0
  61. package/src/v8/cli/main.ts +12 -0
  62. package/src/v8/cli/root.ts +66 -0
  63. package/src/v8/cli/run.ts +236 -0
  64. package/src/v8/cli/schema/builtinSchemas.ts +236 -0
  65. package/src/v8/cli/schema/generate.ts +507 -0
  66. package/src/v8/cli/schema/index.ts +63 -0
  67. package/src/v8/cli/schema/tsProgram.ts +497 -0
  68. package/src/v8/cli/schema/typeToSchema.ts +689 -0
  69. package/src/v8/cli/serve/server.ts +303 -0
  70. package/src/v8/cli/watch.ts +86 -0
  71. package/src/v8/client.ts +147 -0
  72. package/src/v8/cms.ts +237 -0
  73. package/src/v8/content.ts +195 -0
  74. package/src/v8/draft.ts +136 -0
  75. package/src/v8/errors.ts +59 -0
  76. package/src/v8/fetch.ts +152 -0
  77. package/src/v8/identity.ts +65 -0
  78. package/src/v8/index.ts +39 -0
  79. package/src/v8/json.ts +74 -0
  80. package/src/v8/matchRoute.ts +204 -0
  81. package/src/v8/remoteLoader.ts +282 -0
  82. package/src/v8/resolver.ts +278 -0
  83. package/src/v8/secrets.ts +17 -0
  84. package/src/v8/telemetry.ts +533 -0
  85. package/src/v8/types.ts +240 -0
  86. package/src/cms/blockSource.test.ts +0 -76
  87. package/src/cms/client.browserBundle.test.ts +0 -44
  88. package/src/cms/deferredTrigger.test.ts +0 -32
  89. package/src/cms/draftSource.test.ts +0 -519
  90. package/src/cms/layoutCacheRace.test.ts +0 -181
  91. package/src/cms/loadDecofileDirectory.test.ts +0 -109
  92. package/src/cms/loader.test.ts +0 -557
  93. package/src/cms/registry.test.ts +0 -110
  94. package/src/cms/renderJson.test.ts +0 -167
  95. package/src/cms/resolve.test.ts +0 -1492
  96. package/src/cms/schema.test.ts +0 -356
  97. package/src/cms/sectionLoaderContext.test.ts +0 -111
  98. package/src/cms/sectionLoaders.test.ts +0 -625
  99. package/src/cms/sectionMixins.test.ts +0 -167
  100. package/src/cms/stickyFlags.test.ts +0 -117
  101. package/src/flags/flags.test.ts +0 -148
  102. package/src/hooks/Image.test.ts +0 -239
  103. package/src/hooks/RenderSection.test.tsx +0 -81
  104. package/src/hooks/Stats.test.ts +0 -112
  105. package/src/hooks/useLoadMore.test.ts +0 -205
  106. package/src/matchers/builtins.test.ts +0 -318
  107. package/src/matchers/override.test.ts +0 -205
  108. package/src/middleware/hydrationContext.test.ts +0 -61
  109. package/src/middleware/observability.test.ts +0 -335
  110. package/src/middleware/validateSection.test.ts +0 -147
  111. package/src/preview/DraftPreviewBadge.render.test.tsx +0 -67
  112. package/src/preview/DraftPreviewBadge.test.ts +0 -55
  113. package/src/sdk/abTesting.test.ts +0 -381
  114. package/src/sdk/cacheHeaders.test.ts +0 -258
  115. package/src/sdk/cacheStorage.test.ts +0 -242
  116. package/src/sdk/cachedLoader.test.ts +0 -122
  117. package/src/sdk/cachedLoaderMaxBytes.test.ts +0 -23
  118. package/src/sdk/cachedLoaderModule.test.ts +0 -209
  119. package/src/sdk/cachedLoaderSizeMetric.test.ts +0 -93
  120. package/src/sdk/cn.test.ts +0 -34
  121. package/src/sdk/composite.test.ts +0 -121
  122. package/src/sdk/cookie.test.ts +0 -108
  123. package/src/sdk/crypto.test.ts +0 -65
  124. package/src/sdk/deepOmit.test.ts +0 -45
  125. package/src/sdk/encoding.test.ts +0 -71
  126. package/src/sdk/env.test.ts +0 -33
  127. package/src/sdk/experiments.test.ts +0 -328
  128. package/src/sdk/fetchCache.test.ts +0 -164
  129. package/src/sdk/flags.test.ts +0 -91
  130. package/src/sdk/http.test.ts +0 -71
  131. package/src/sdk/inflightTimeout.test.ts +0 -35
  132. package/src/sdk/instrumentedFetch.test.ts +0 -559
  133. package/src/sdk/invoke.test.ts +0 -115
  134. package/src/sdk/logger.test.ts +0 -432
  135. package/src/sdk/otel.test.ts +0 -691
  136. package/src/sdk/otelAdapters.test.ts +0 -89
  137. package/src/sdk/otelHttpLog.test.ts +0 -457
  138. package/src/sdk/otelHttpMeter.test.ts +0 -395
  139. package/src/sdk/otelHttpTracer.test.ts +0 -474
  140. package/src/sdk/replaceStream.test.ts +0 -117
  141. package/src/sdk/requestContextStorage.browser.test.ts +0 -29
  142. package/src/sdk/splitExactRedirects.test.ts +0 -154
  143. package/src/sdk/urlRedaction.test.ts +0 -73
  144. package/src/sdk/urlUtils.test.ts +0 -34
  145. package/src/sdk/useDevice.test.ts +0 -130
  146. package/src/sdk/useScript.test.ts +0 -128
  147. package/src/sdk/useSuggestions.test.ts +0 -230
  148. package/tsconfig.json +0 -7
@@ -1,34 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { clx, cn } from "./cn";
3
-
4
- describe("cn", () => {
5
- it("joins strings", () => {
6
- expect(cn("a", "b", "c")).toBe("a b c");
7
- });
8
-
9
- it("supports conditional objects", () => {
10
- expect(cn("a", { b: true, c: false }, "d")).toBe("a b d");
11
- });
12
-
13
- it("filters out falsy values", () => {
14
- expect(cn("a", null, undefined, false, 0 as any, "b")).toBe("a b");
15
- });
16
-
17
- it("merges conflicting Tailwind utilities (last one wins)", () => {
18
- expect(cn("p-2", "p-4")).toBe("p-4");
19
- });
20
-
21
- it("merges hover variants independently from base utilities", () => {
22
- expect(cn("p-2", "hover:p-4")).toBe("p-2 hover:p-4");
23
- });
24
- });
25
-
26
- describe("clx (re-exported)", () => {
27
- it("filters falsy and joins with single spaces", () => {
28
- expect(clx("a", null, "b", undefined, "c")).toBe("a b c");
29
- });
30
-
31
- it("does NOT merge conflicting utilities (that's cn's job)", () => {
32
- expect(clx("p-2", "p-4")).toBe("p-2 p-4");
33
- });
34
- });
@@ -1,121 +0,0 @@
1
- import { afterEach, describe, expect, it, vi } from "vitest";
2
- import type { MeterAdapter } from "../middleware/observability";
3
- import { createCompositeLogger, createCompositeMeter } from "./composite";
4
- import type { LoggerAdapter } from "./logger";
5
-
6
- describe("createCompositeLogger", () => {
7
- afterEach(() => vi.restoreAllMocks());
8
-
9
- it("fans calls out to every adapter", () => {
10
- const aCalls: any[][] = [];
11
- const bCalls: any[][] = [];
12
- const a: LoggerAdapter = { log: (...args) => void aCalls.push(args) };
13
- const b: LoggerAdapter = { log: (...args) => void bCalls.push(args) };
14
- const composite = createCompositeLogger([a, b]);
15
-
16
- composite.log("info", "hello", { foo: 1 });
17
-
18
- expect(aCalls).toEqual([["info", "hello", { foo: 1 }]]);
19
- expect(bCalls).toEqual([["info", "hello", { foo: 1 }]]);
20
- });
21
-
22
- it("filters falsy entries (null/undefined/false)", () => {
23
- const calls: any[] = [];
24
- const a: LoggerAdapter = { log: (...args) => void calls.push(args) };
25
- const composite = createCompositeLogger([null, a, undefined, false]);
26
- composite.log("info", "ok");
27
- // adapter receives the call with no third arg (undefined is omitted)
28
- expect(calls.length).toBe(1);
29
- expect(calls[0][0]).toBe("info");
30
- expect(calls[0][1]).toBe("ok");
31
- });
32
-
33
- it("isolates errors so one bad adapter does not block others", () => {
34
- const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
35
- const okCalls: any[][] = [];
36
- const broken: LoggerAdapter = {
37
- log() {
38
- throw new Error("boom");
39
- },
40
- };
41
- const ok: LoggerAdapter = { log: (...args) => void okCalls.push(args) };
42
- const composite = createCompositeLogger([broken, ok]);
43
-
44
- expect(() => composite.log("error", "still goes through")).not.toThrow();
45
- expect(okCalls.length).toBe(1);
46
- expect(okCalls[0][0]).toBe("error");
47
- expect(okCalls[0][1]).toBe("still goes through");
48
- expect(errSpy).toHaveBeenCalled(); // composite reports the failure
49
- });
50
-
51
- it("returns the single adapter directly when only one is provided", () => {
52
- const a: LoggerAdapter = { log: () => {} };
53
- expect(createCompositeLogger([a])).toBe(a);
54
- });
55
- });
56
-
57
- describe("createCompositeMeter", () => {
58
- afterEach(() => vi.restoreAllMocks());
59
-
60
- function recorder() {
61
- const counter: any[] = [];
62
- const gauge: any[] = [];
63
- const histo: any[] = [];
64
- const meter: MeterAdapter = {
65
- counterInc: (n, v, l) => void counter.push([n, v, l]),
66
- gaugeSet: (n, v, l) => void gauge.push([n, v, l]),
67
- histogramRecord: (n, v, l) => void histo.push([n, v, l]),
68
- };
69
- return { meter, counter, gauge, histo };
70
- }
71
-
72
- it("fans counter/gauge/histogram across meters", () => {
73
- const a = recorder();
74
- const b = recorder();
75
- const composite = createCompositeMeter([a.meter, b.meter]);
76
-
77
- composite.counterInc("c", 1, { p: "/" });
78
- composite.gaugeSet?.("g", 5);
79
- composite.histogramRecord?.("h", 100, { route: "/p" });
80
-
81
- expect(a.counter[0].slice(0, 2)).toEqual(["c", 1]);
82
- expect(a.counter[0][2]).toEqual({ p: "/" });
83
- expect(b.counter[0].slice(0, 2)).toEqual(["c", 1]);
84
- expect(a.gauge[0].slice(0, 2)).toEqual(["g", 5]);
85
- expect(b.gauge[0].slice(0, 2)).toEqual(["g", 5]);
86
- expect(a.histo[0]).toEqual(["h", 100, { route: "/p" }]);
87
- expect(b.histo[0]).toEqual(["h", 100, { route: "/p" }]);
88
- });
89
-
90
- it("isolates errors per meter and per call type", () => {
91
- vi.spyOn(console, "error").mockImplementation(() => {});
92
- const broken: MeterAdapter = {
93
- counterInc: () => {
94
- throw new Error("c");
95
- },
96
- gaugeSet: () => {
97
- throw new Error("g");
98
- },
99
- histogramRecord: () => {
100
- throw new Error("h");
101
- },
102
- };
103
- const ok = recorder();
104
- const composite = createCompositeMeter([broken, ok.meter]);
105
-
106
- composite.counterInc("c", 1);
107
- composite.gaugeSet?.("g", 5);
108
- composite.histogramRecord?.("h", 100);
109
-
110
- expect(ok.counter[0].slice(0, 2)).toEqual(["c", 1]);
111
- expect(ok.gauge[0].slice(0, 2)).toEqual(["g", 5]);
112
- expect(ok.histo[0].slice(0, 2)).toEqual(["h", 100]);
113
- });
114
-
115
- it("skips meters that don't implement optional ops", () => {
116
- const onlyCounter: MeterAdapter = { counterInc: () => {} };
117
- const composite = createCompositeMeter([onlyCounter]);
118
- expect(() => composite.gaugeSet?.("g", 1)).not.toThrow();
119
- expect(() => composite.histogramRecord?.("h", 1)).not.toThrow();
120
- });
121
- });
@@ -1,108 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import {
3
- deleteResponseCookie,
4
- getCookies,
5
- setResponseCookie,
6
- } from "./cookie";
7
-
8
- describe("getCookies", () => {
9
- it("returns an empty object when no Cookie header is present", () => {
10
- expect(getCookies(new Headers())).toEqual({});
11
- });
12
-
13
- it("parses a single cookie", () => {
14
- const h = new Headers({ cookie: "session=abc" });
15
- expect(getCookies(h)).toEqual({ session: "abc" });
16
- });
17
-
18
- it("parses multiple cookies separated by '; '", () => {
19
- const h = new Headers({ cookie: "a=1; b=2; c=3" });
20
- expect(getCookies(h)).toEqual({ a: "1", b: "2", c: "3" });
21
- });
22
-
23
- it("URL-decodes values", () => {
24
- const h = new Headers({ cookie: "u=hello%20world" });
25
- expect(getCookies(h)).toEqual({ u: "hello world" });
26
- });
27
-
28
- it("falls back to the raw value when decoding fails", () => {
29
- // Lone '%' is invalid in URL encoding.
30
- const h = new Headers({ cookie: "x=100%" });
31
- expect(getCookies(h)).toEqual({ x: "100%" });
32
- });
33
-
34
- it("ignores entries without an '='", () => {
35
- const h = new Headers({ cookie: "garbage; ok=yes" });
36
- expect(getCookies(h)).toEqual({ ok: "yes" });
37
- });
38
-
39
- it("trims whitespace around names", () => {
40
- const h = new Headers({ cookie: " a=1; b=2 " });
41
- expect(getCookies(h)).toEqual({ a: "1", b: "2" });
42
- });
43
- });
44
-
45
- describe("setResponseCookie", () => {
46
- it("appends a Set-Cookie header with the cookie name and value", () => {
47
- const h = new Headers();
48
- setResponseCookie(h, { name: "session", value: "abc" });
49
- expect(h.get("set-cookie")).toBe("session=abc");
50
- });
51
-
52
- it("serializes maxAge, path, secure, httpOnly, sameSite, domain", () => {
53
- const h = new Headers();
54
- setResponseCookie(h, {
55
- name: "session",
56
- value: "abc",
57
- maxAge: 3600,
58
- path: "/",
59
- domain: "example.com",
60
- secure: true,
61
- httpOnly: true,
62
- sameSite: "Lax",
63
- });
64
- const value = h.get("set-cookie")!;
65
- expect(value).toContain("session=abc");
66
- expect(value).toContain("Max-Age=3600");
67
- expect(value).toContain("Domain=example.com");
68
- expect(value).toContain("Path=/");
69
- expect(value).toContain("Secure");
70
- expect(value).toContain("HttpOnly");
71
- expect(value).toContain("SameSite=Lax");
72
- });
73
-
74
- it("serializes expires as a UTC string", () => {
75
- const h = new Headers();
76
- const date = new Date("2030-01-01T00:00:00Z");
77
- setResponseCookie(h, { name: "x", value: "y", expires: date });
78
- expect(h.get("set-cookie")).toContain(`Expires=${date.toUTCString()}`);
79
- });
80
-
81
- it("appends multiple cookies (does not overwrite the first)", () => {
82
- const h = new Headers();
83
- setResponseCookie(h, { name: "a", value: "1" });
84
- setResponseCookie(h, { name: "b", value: "2" });
85
- // Headers.getAll isn't standard; getSetCookie() is the modern API.
86
- const all = (h as any).getSetCookie?.() as string[] | undefined;
87
- if (all) {
88
- expect(all).toEqual(["a=1", "b=2"]);
89
- } else {
90
- // Fallback: the combined header value should mention both.
91
- const v = h.get("set-cookie")!;
92
- expect(v).toContain("a=1");
93
- expect(v).toContain("b=2");
94
- }
95
- });
96
- });
97
-
98
- describe("deleteResponseCookie", () => {
99
- it("emits a Set-Cookie that expires immediately", () => {
100
- const h = new Headers();
101
- deleteResponseCookie(h, "session", { path: "/" });
102
- const value = h.get("set-cookie")!;
103
- expect(value).toContain("session=");
104
- expect(value).toContain("Max-Age=0");
105
- expect(value).toContain(`Expires=${new Date(0).toUTCString()}`);
106
- expect(value).toContain("Path=/");
107
- });
108
- });
@@ -1,65 +0,0 @@
1
- /**
2
- * Regression test for the CF Workers secret-decryption bug: in production/preview
3
- * DECO_CRYPTO_KEY is neither in process.env nor in .dev.vars — it only reaches
4
- * getEnvVar() via the `env` binding stashed in RequestContext (setRuntimeEnv).
5
- * If getEnvVar() stops consulting getRuntimeEnv(), encrypted secrets silently
6
- * decrypt to null in production and this test fails.
7
- */
8
-
9
- import { webcrypto } from "node:crypto";
10
- import { beforeAll, describe, expect, it } from "vitest";
11
- import { resolveSecret } from "./crypto";
12
- import { setRuntimeEnv } from "./otelAdapters";
13
- import { RequestContext } from "./requestContext";
14
-
15
- // Ensure crypto.subtle exists in the Node test runtime.
16
- beforeAll(() => {
17
- if (!globalThis.crypto?.subtle) {
18
- (globalThis as { crypto: Crypto }).crypto = webcrypto as unknown as Crypto;
19
- }
20
- });
21
-
22
- /** Build a DECO_CRYPTO_KEY value + an encrypted-hex ciphertext for `plaintext`. */
23
- async function makeKeyAndCiphertext(plaintext: string) {
24
- const rawKey = webcrypto.getRandomValues(new Uint8Array(16));
25
- const iv = webcrypto.getRandomValues(new Uint8Array(16));
26
- const key = await webcrypto.subtle.importKey("raw", rawKey, "AES-CBC", false, [
27
- "encrypt",
28
- ]);
29
- const ct = new Uint8Array(
30
- await webcrypto.subtle.encrypt(
31
- { name: "AES-CBC", iv },
32
- key,
33
- new TextEncoder().encode(plaintext),
34
- ),
35
- );
36
- const encryptedHex = Array.from(ct)
37
- .map((b) => b.toString(16).padStart(2, "0"))
38
- .join("");
39
- const decoCryptoKey = btoa(
40
- JSON.stringify({ key: Array.from(rawKey), iv: Array.from(iv) }),
41
- );
42
- return { decoCryptoKey, encryptedHex };
43
- }
44
-
45
- describe("resolveSecret in CF Workers (no process.env / no .dev.vars)", () => {
46
- it("decrypts using DECO_CRYPTO_KEY from the RequestContext env binding", async () => {
47
- // Use a unique plaintext so the module-level secretCache can't mask a
48
- // regression with a value cached by another test/run.
49
- const plaintext = `appToken-${Math.random().toString(36).slice(2)}`;
50
- const { decoCryptoKey, encryptedHex } = await makeKeyAndCiphertext(plaintext);
51
-
52
- // Guard: process.env must NOT carry the key, so the only source is the ALS.
53
- expect(process.env.DECO_CRYPTO_KEY).toBeUndefined();
54
-
55
- const resolved = await RequestContext.run(
56
- new Request("https://site.example/"),
57
- async () => {
58
- setRuntimeEnv({ DECO_CRYPTO_KEY: decoCryptoKey });
59
- return resolveSecret({ encrypted: encryptedHex });
60
- },
61
- );
62
-
63
- expect(resolved).toBe(plaintext);
64
- });
65
- });
@@ -1,45 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { deepOmit } from "./deepOmit";
3
-
4
- describe("deepOmit", () => {
5
- it("removes a top-level key immutably", () => {
6
- const input = { a: 1, b: 2 };
7
- const out = deepOmit(input, "b");
8
- expect(out).toEqual({ a: 1 });
9
- expect(input).toEqual({ a: 1, b: 2 }); // input untouched
10
- });
11
-
12
- it("removes a nested dotted path", () => {
13
- const out = deepOmit({ page: { seo: { title: "x" }, id: 1 } }, "page.seo");
14
- expect(out).toEqual({ page: { id: 1 } });
15
- });
16
-
17
- it("fans a wildcard over record values", () => {
18
- const out = deepOmit(
19
- { page: { productsMap: { a: { keep: 1, drop: 2 }, b: { keep: 3, drop: 4 } } } },
20
- "page.productsMap.*.drop",
21
- );
22
- expect(out).toEqual({ page: { productsMap: { a: { keep: 1 }, b: { keep: 3 } } } });
23
- });
24
-
25
- it("fans a wildcard over array elements", () => {
26
- const out = deepOmit({ items: [{ keep: 1, drop: 2 }, { keep: 3, drop: 4 }] }, "items.*.drop");
27
- expect(out).toEqual({ items: [{ keep: 1 }, { keep: 3 }] });
28
- });
29
-
30
- it("auto-applies a path to each array element (no explicit *)", () => {
31
- const out = deepOmit({ items: [{ a: 1, b: 2 }, { a: 3, b: 4 }] }, "items.b");
32
- expect(out).toEqual({ items: [{ a: 1 }, { a: 3 }] });
33
- });
34
-
35
- it("is a no-op for a missing key (never fabricates undefined)", () => {
36
- const out = deepOmit({ a: 1 }, "b.c.d");
37
- expect(out).toEqual({ a: 1 });
38
- expect("b" in out).toBe(false);
39
- });
40
-
41
- it("applies multiple paths", () => {
42
- const out = deepOmit({ a: 1, b: 2, c: { d: 3, e: 4 } }, "a", "c.d");
43
- expect(out).toEqual({ b: 2, c: { e: 4 } });
44
- });
45
- });
@@ -1,71 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import {
3
- decodeBase64,
4
- decodeBase64Url,
5
- encodeBase64,
6
- encodeBase64Url,
7
- } from "./encoding";
8
-
9
- describe("encodeBase64 / decodeBase64", () => {
10
- it("round-trips ASCII strings", () => {
11
- const data = "hello, world";
12
- const b64 = encodeBase64(data);
13
- expect(b64).toBe("aGVsbG8sIHdvcmxk");
14
- const decoded = new TextDecoder().decode(decodeBase64(b64));
15
- expect(decoded).toBe(data);
16
- });
17
-
18
- it("round-trips multi-byte UTF-8", () => {
19
- const data = "São Paulo — café ☕";
20
- const b64 = encodeBase64(data);
21
- const decoded = new TextDecoder().decode(decodeBase64(b64));
22
- expect(decoded).toBe(data);
23
- });
24
-
25
- it("accepts Uint8Array input", () => {
26
- const bytes = new Uint8Array([1, 2, 3, 4, 5]);
27
- const b64 = encodeBase64(bytes);
28
- expect(decodeBase64(b64)).toEqual(bytes);
29
- });
30
-
31
- it("accepts ArrayBuffer input", () => {
32
- const buf = new Uint8Array([255, 254, 253]).buffer;
33
- const b64 = encodeBase64(buf);
34
- expect(Array.from(decodeBase64(b64))).toEqual([255, 254, 253]);
35
- });
36
-
37
- it("handles inputs larger than the chunking window", () => {
38
- // 0x8000 + 7 bytes — forces the chunking branch.
39
- const bytes = new Uint8Array(0x8000 + 7);
40
- for (let i = 0; i < bytes.length; i++) bytes[i] = i & 0xff;
41
- const b64 = encodeBase64(bytes);
42
- expect(decodeBase64(b64)).toEqual(bytes);
43
- });
44
- });
45
-
46
- describe("encodeBase64Url / decodeBase64Url", () => {
47
- it("uses URL-safe alphabet and strips padding", () => {
48
- // Inputs that produce '+', '/', and padding under standard base64.
49
- const bytes = new Uint8Array([251, 255, 191, 251, 239, 254]);
50
- const standard = encodeBase64(bytes);
51
- const url = encodeBase64Url(bytes);
52
- // Every '+' becomes '-', '/' becomes '_', trailing '=' is stripped.
53
- expect(url).toBe(
54
- standard.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""),
55
- );
56
- expect(url).not.toContain("+");
57
- expect(url).not.toContain("/");
58
- expect(url).not.toContain("=");
59
- });
60
-
61
- it("round-trips through the URL-safe pair", () => {
62
- const data = new Uint8Array(64);
63
- for (let i = 0; i < data.length; i++) data[i] = (i * 7) & 0xff;
64
- expect(decodeBase64Url(encodeBase64Url(data))).toEqual(data);
65
- });
66
-
67
- it("decodes inputs missing their padding", () => {
68
- // 'a' = 0x61. encodeBase64('a') = 'YQ==', URL form drops to 'YQ'.
69
- expect(new TextDecoder().decode(decodeBase64Url("YQ"))).toBe("a");
70
- });
71
- });
@@ -1,33 +0,0 @@
1
- import { afterEach, describe, expect, it, vi } from "vitest";
2
-
3
- // isDevMode() memoises its result in module-level state after the first
4
- // call, so each case below resets modules and re-imports fresh to get an
5
- // unmemoised read for the NODE_ENV value it's stubbing.
6
- describe("isDevMode", () => {
7
- afterEach(() => {
8
- vi.unstubAllEnvs();
9
- });
10
-
11
- it("is false when NODE_ENV is production", async () => {
12
- vi.stubEnv("NODE_ENV", "production");
13
- vi.stubEnv("DECO_PREVIEW", "");
14
- vi.resetModules();
15
- const { isDevMode } = await import("./env");
16
- expect(isDevMode()).toBe(false);
17
- });
18
-
19
- it("is true when NODE_ENV is development", async () => {
20
- vi.stubEnv("NODE_ENV", "development");
21
- vi.resetModules();
22
- const { isDevMode } = await import("./env");
23
- expect(isDevMode()).toBe(true);
24
- });
25
-
26
- it("is true when DECO_PREVIEW=true even if NODE_ENV is production", async () => {
27
- vi.stubEnv("NODE_ENV", "production");
28
- vi.stubEnv("DECO_PREVIEW", "true");
29
- vi.resetModules();
30
- const { isDevMode } = await import("./env");
31
- expect(isDevMode()).toBe(true);
32
- });
33
- });