@decocms/blocks 8.0.0 → 8.1.0-next.1
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/bin/deco.js +13 -0
- package/package.json +32 -82
- package/src/index.ts +35 -8
- package/src/protocol/assets.ts +124 -0
- package/src/protocol/canonical.ts +7 -0
- package/src/protocol/ciphertext.ts +6 -0
- package/src/protocol/client.ts +170 -0
- package/src/protocol/conformance/cases/assets.ts +81 -0
- package/src/protocol/conformance/cases/guards.ts +314 -0
- package/src/protocol/conformance/cases/reads.ts +168 -0
- package/src/protocol/conformance/cases/types.ts +9 -0
- package/src/protocol/conformance/cases/wire.ts +138 -0
- package/src/protocol/conformance/cases/writes.ts +345 -0
- package/src/protocol/conformance/contentHashFixtures.ts +79 -0
- package/src/protocol/conformance/context.ts +222 -0
- package/src/protocol/conformance/index.ts +140 -0
- package/src/protocol/errors.ts +142 -0
- package/src/protocol/index.ts +39 -0
- package/src/protocol/keys.ts +279 -0
- package/src/protocol/params.ts +67 -0
- package/src/protocol/secrets.ts +231 -0
- package/src/protocol/server/assets.ts +119 -0
- package/src/protocol/server/auth.ts +49 -0
- package/src/protocol/server/bodyCache.ts +84 -0
- package/src/protocol/server/content.ts +175 -0
- package/src/protocol/server/core.ts +112 -0
- package/src/protocol/server/handler.ts +102 -0
- package/src/protocol/server/http.ts +139 -0
- package/src/protocol/server/index.ts +11 -0
- package/src/protocol/server/methods/apply.ts +341 -0
- package/src/protocol/server/methods/read.ts +156 -0
- package/src/protocol/server/rpc.ts +136 -0
- package/src/protocol/storage/fs/hash.ts +21 -0
- package/src/protocol/storage/fs/index.ts +338 -0
- package/src/protocol/storage/fs/lock.ts +68 -0
- package/src/protocol/storage/fs/transaction.ts +183 -0
- package/src/protocol/storage/fs/unsupported.ts +15 -0
- package/src/protocol/storage/memory.ts +238 -0
- package/src/protocol/storage.ts +182 -0
- package/src/protocol/types.ts +172 -0
- package/src/v8/analytics.ts +50 -0
- package/src/v8/background.ts +107 -0
- package/src/v8/builtins/data.ts +23 -0
- package/src/v8/builtins/index.ts +26 -0
- package/src/v8/builtins/lazy.ts +23 -0
- package/src/v8/builtins/legacy.ts +65 -0
- package/src/v8/builtins/matchers.ts +31 -0
- package/src/v8/builtins/multivariate.ts +25 -0
- package/src/v8/builtins/secret.ts +82 -0
- package/src/v8/canonical.ts +117 -0
- package/src/v8/ciphertext.ts +158 -0
- package/src/v8/cli/builtins.ts +20 -0
- package/src/v8/cli/check/index.ts +774 -0
- package/src/v8/cli/check/messages.ts +168 -0
- package/src/v8/cli/content.ts +287 -0
- package/src/v8/cli/index.ts +17 -0
- package/src/v8/cli/log.ts +18 -0
- package/src/v8/cli/main.ts +12 -0
- package/src/v8/cli/root.ts +66 -0
- package/src/v8/cli/run.ts +236 -0
- package/src/v8/cli/schema/builtinSchemas.ts +236 -0
- package/src/v8/cli/schema/generate.ts +507 -0
- package/src/v8/cli/schema/index.ts +63 -0
- package/src/v8/cli/schema/tsProgram.ts +497 -0
- package/src/v8/cli/schema/typeToSchema.ts +689 -0
- package/src/v8/cli/serve/server.ts +303 -0
- package/src/v8/cli/watch.ts +86 -0
- package/src/v8/client.ts +147 -0
- package/src/v8/cms.ts +237 -0
- package/src/v8/content.ts +195 -0
- package/src/v8/draft.ts +136 -0
- package/src/v8/errors.ts +59 -0
- package/src/v8/fetch.ts +133 -0
- package/src/v8/identity.ts +65 -0
- package/src/v8/index.ts +39 -0
- package/src/v8/json.ts +74 -0
- package/src/v8/matchRoute.ts +204 -0
- package/src/v8/remoteLoader.ts +282 -0
- package/src/v8/resolver.ts +278 -0
- package/src/v8/secrets.ts +17 -0
- package/src/v8/telemetry.ts +533 -0
- package/src/v8/types.ts +240 -0
- package/src/cms/applySectionConventions.ts +0 -124
- package/src/cms/blockSource.test.ts +0 -76
- package/src/cms/blockSource.ts +0 -191
- package/src/cms/client.browserBundle.test.ts +0 -44
- package/src/cms/client.ts +0 -80
- package/src/cms/draftSource.test.ts +0 -343
- package/src/cms/draftSource.ts +0 -362
- package/src/cms/index.ts +0 -151
- package/src/cms/layoutCacheRace.test.ts +0 -181
- package/src/cms/loadDecofileDirectory.test.ts +0 -109
- package/src/cms/loadDecofileDirectory.ts +0 -89
- package/src/cms/loader.test.ts +0 -200
- package/src/cms/loader.ts +0 -304
- package/src/cms/registry.test.ts +0 -110
- package/src/cms/registry.ts +0 -242
- package/src/cms/resolve.test.ts +0 -980
- package/src/cms/resolve.ts +0 -2282
- package/src/cms/schema.test.ts +0 -356
- package/src/cms/schema.ts +0 -1215
- package/src/cms/sectionLoaderContext.test.ts +0 -111
- package/src/cms/sectionLoaderContext.ts +0 -113
- package/src/cms/sectionLoaders.test.ts +0 -533
- package/src/cms/sectionLoaders.ts +0 -636
- package/src/cms/sectionMixins.test.ts +0 -167
- package/src/cms/sectionMixins.ts +0 -153
- package/src/cms/stickyFlags.test.ts +0 -117
- package/src/flags/audience.ts +0 -56
- package/src/flags/everyone.ts +0 -29
- package/src/flags/flag.ts +0 -15
- package/src/flags/flags.test.ts +0 -148
- package/src/flags/multivariate/image.ts +0 -11
- package/src/flags/multivariate/message.ts +0 -11
- package/src/flags/multivariate/page.ts +0 -16
- package/src/flags/multivariate/section.ts +0 -16
- package/src/flags/multivariate.ts +0 -1
- package/src/flags/types.ts +0 -59
- package/src/flags/utils/multivariate.ts +0 -20
- package/src/hooks/Image.test.ts +0 -100
- package/src/hooks/Image.tsx +0 -250
- package/src/hooks/JsonLd.tsx +0 -353
- package/src/hooks/LazySection.tsx +0 -121
- package/src/hooks/LiveControls.tsx +0 -122
- package/src/hooks/Picture.tsx +0 -127
- package/src/hooks/RenderSection.test.tsx +0 -81
- package/src/hooks/RenderSection.tsx +0 -91
- package/src/hooks/SectionErrorFallback.tsx +0 -97
- package/src/hooks/index.ts +0 -30
- package/src/matchers/builtins.test.ts +0 -318
- package/src/matchers/builtins.ts +0 -459
- package/src/matchers/countryNames.ts +0 -104
- package/src/matchers/override.test.ts +0 -205
- package/src/matchers/override.ts +0 -136
- package/src/matchers/posthog.ts +0 -154
- package/src/middleware/decoState.ts +0 -55
- package/src/middleware/healthMetrics.ts +0 -133
- package/src/middleware/hydrationContext.test.ts +0 -61
- package/src/middleware/hydrationContext.ts +0 -79
- package/src/middleware/index.ts +0 -88
- package/src/middleware/liveness.ts +0 -21
- package/src/middleware/observability.test.ts +0 -242
- package/src/middleware/observability.ts +0 -643
- package/src/middleware/validateSection.test.ts +0 -147
- package/src/middleware/validateSection.ts +0 -100
- package/src/sdk/abTesting.test.ts +0 -326
- package/src/sdk/abTesting.ts +0 -499
- package/src/sdk/analytics.ts +0 -77
- package/src/sdk/cacheHeaders.test.ts +0 -115
- package/src/sdk/cacheHeaders.ts +0 -433
- package/src/sdk/cachedLoader.test.ts +0 -122
- package/src/sdk/cachedLoader.ts +0 -503
- package/src/sdk/cachedLoaderModule.test.ts +0 -209
- package/src/sdk/clx.ts +0 -5
- package/src/sdk/cn.test.ts +0 -34
- package/src/sdk/cn.ts +0 -28
- package/src/sdk/composite.test.ts +0 -121
- package/src/sdk/composite.ts +0 -114
- package/src/sdk/cookie.test.ts +0 -108
- package/src/sdk/cookie.ts +0 -129
- package/src/sdk/crypto.ts +0 -185
- package/src/sdk/csp.ts +0 -59
- package/src/sdk/detectDevice.ts +0 -45
- package/src/sdk/djb2.ts +0 -20
- package/src/sdk/encoding.test.ts +0 -71
- package/src/sdk/encoding.ts +0 -47
- package/src/sdk/env.test.ts +0 -33
- package/src/sdk/env.ts +0 -54
- package/src/sdk/flags.test.ts +0 -91
- package/src/sdk/flags.ts +0 -108
- package/src/sdk/http.test.ts +0 -71
- package/src/sdk/http.ts +0 -124
- package/src/sdk/index.ts +0 -90
- package/src/sdk/inflightTimeout.test.ts +0 -35
- package/src/sdk/inflightTimeout.ts +0 -53
- package/src/sdk/instrumentedFetch.test.ts +0 -559
- package/src/sdk/instrumentedFetch.ts +0 -339
- package/src/sdk/invoke.test.ts +0 -115
- package/src/sdk/invoke.ts +0 -298
- package/src/sdk/logger.test.ts +0 -432
- package/src/sdk/logger.ts +0 -304
- package/src/sdk/mergeCacheControl.ts +0 -150
- package/src/sdk/normalizeUrls.ts +0 -91
- package/src/sdk/observability.ts +0 -109
- package/src/sdk/otel.test.ts +0 -526
- package/src/sdk/otel.ts +0 -1012
- package/src/sdk/otelAdapters/clickhouseCollector.ts +0 -65
- package/src/sdk/otelAdapters.test.ts +0 -89
- package/src/sdk/otelAdapters.ts +0 -144
- package/src/sdk/otelHttpLog.test.ts +0 -457
- package/src/sdk/otelHttpLog.ts +0 -419
- package/src/sdk/otelHttpMeter.test.ts +0 -292
- package/src/sdk/otelHttpMeter.ts +0 -506
- package/src/sdk/otelHttpTracer.test.ts +0 -474
- package/src/sdk/otelHttpTracer.ts +0 -543
- package/src/sdk/redirects.ts +0 -228
- package/src/sdk/requestContext.ts +0 -281
- package/src/sdk/requestContextStorage.browser.test.ts +0 -29
- package/src/sdk/requestContextStorage.browser.ts +0 -43
- package/src/sdk/requestContextStorage.ts +0 -35
- package/src/sdk/retry.ts +0 -45
- package/src/sdk/serverTimings.ts +0 -68
- package/src/sdk/signal.ts +0 -42
- package/src/sdk/sitemap.ts +0 -160
- package/src/sdk/urlRedaction.test.ts +0 -73
- package/src/sdk/urlRedaction.ts +0 -82
- package/src/sdk/urlUtils.ts +0 -134
- package/src/sdk/useDevice.test.ts +0 -130
- package/src/sdk/useDevice.ts +0 -89
- package/src/sdk/useDeviceContext.tsx +0 -108
- package/src/sdk/useId.ts +0 -7
- package/src/sdk/useScript.test.ts +0 -128
- package/src/sdk/useScript.ts +0 -210
- package/src/sdk/useSuggestions.test.ts +0 -230
- package/src/sdk/useSuggestions.ts +0 -188
- package/src/sdk/wrapCaughtErrors.ts +0 -107
- package/src/setup.ts +0 -120
- package/src/types/index.ts +0 -53
- package/src/types/widgets.ts +0 -14
- package/tsconfig.json +0 -7
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import type { MatcherContext } from "../cms/resolve";
|
|
3
|
-
import { evaluateMatcher } from "../cms/resolve";
|
|
4
|
-
import { registerBuiltinMatchers } from "./builtins";
|
|
5
|
-
|
|
6
|
-
const LOCATION_KEY = "website/matchers/location.ts";
|
|
7
|
-
const DATE_KEY = "website/matchers/date.ts";
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
registerBuiltinMatchers();
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
function ctxFromCookies(cookies: Record<string, string>): MatcherContext {
|
|
14
|
-
return { cookies };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function ctxFromCf(cf: Record<string, unknown>): MatcherContext {
|
|
18
|
-
const request = new Request("https://example.com/");
|
|
19
|
-
Object.defineProperty(request, "cf", { value: cf, configurable: true });
|
|
20
|
-
return { request };
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function ctxFromHeaders(headers: Record<string, string>): MatcherContext {
|
|
24
|
-
return {
|
|
25
|
-
request: new Request("https://example.com/", { headers }),
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function match(rule: Record<string, unknown>, ctx: MatcherContext): boolean {
|
|
30
|
-
return evaluateMatcher({ ...rule, __resolveType: LOCATION_KEY }, ctx);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
describe("locationMatcher — typed mode (Location)", () => {
|
|
34
|
-
it("matches when regionCode equals Cloudflare's cf-region-code (SP)", () => {
|
|
35
|
-
const ctx = ctxFromHeaders({ "cf-region-code": "SP", "cf-ipcountry": "BR" });
|
|
36
|
-
expect(match({ includeLocations: [{ regionCode: "SP" }] }, ctx)).toBe(true);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("matches a raw numeric regionCode (e.g. '47') for parity with deco-cx/apps", () => {
|
|
40
|
-
const ctx = ctxFromHeaders({ "cf-region-code": "47", "cf-ipcountry": "BR" });
|
|
41
|
-
expect(match({ includeLocations: [{ regionCode: "47" }] }, ctx)).toBe(true);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("is case-insensitive on regionCode", () => {
|
|
45
|
-
const ctx = ctxFromHeaders({ "cf-region-code": "SP" });
|
|
46
|
-
expect(match({ includeLocations: [{ regionCode: "sp" }] }, ctx)).toBe(true);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("does NOT match a region NAME against cf-region-code (parity with original)", () => {
|
|
50
|
-
const ctx = ctxFromHeaders({ "cf-region-code": "SP" });
|
|
51
|
-
expect(
|
|
52
|
-
match({ includeLocations: [{ regionCode: "São Paulo" }] }, ctx),
|
|
53
|
-
).toBe(false);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("does not match when the region differs", () => {
|
|
57
|
-
const ctx = ctxFromHeaders({ "cf-region-code": "SP" });
|
|
58
|
-
expect(match({ includeLocations: [{ regionCode: "RJ" }] }, ctx)).toBe(false);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("AND's multiple fields on the same entry (regionCode + country)", () => {
|
|
62
|
-
const ctx = ctxFromHeaders({ "cf-region-code": "SP", "cf-ipcountry": "BR" });
|
|
63
|
-
expect(
|
|
64
|
-
match(
|
|
65
|
-
{ includeLocations: [{ regionCode: "SP", country: "BR" }] },
|
|
66
|
-
ctx,
|
|
67
|
-
),
|
|
68
|
-
).toBe(true);
|
|
69
|
-
expect(
|
|
70
|
-
match(
|
|
71
|
-
{ includeLocations: [{ regionCode: "SP", country: "AR" }] },
|
|
72
|
-
ctx,
|
|
73
|
-
),
|
|
74
|
-
).toBe(false);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("resolves country aliases (Brasil → BR)", () => {
|
|
78
|
-
const ctx = ctxFromHeaders({ "cf-ipcountry": "BR", "cf-region-code": "SP" });
|
|
79
|
-
expect(
|
|
80
|
-
match({ includeLocations: [{ country: "Brasil" }] }, ctx),
|
|
81
|
-
).toBe(true);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("OR's across multiple include entries", () => {
|
|
85
|
-
const ctx = ctxFromHeaders({ "cf-region-code": "RJ" });
|
|
86
|
-
expect(
|
|
87
|
-
match(
|
|
88
|
-
{
|
|
89
|
-
includeLocations: [{ regionCode: "SP" }, { regionCode: "RJ" }],
|
|
90
|
-
},
|
|
91
|
-
ctx,
|
|
92
|
-
),
|
|
93
|
-
).toBe(true);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe("locationMatcher — empty / shape edge cases", () => {
|
|
98
|
-
it("empty includeLocations array → match (no constraint)", () => {
|
|
99
|
-
const ctx = ctxFromHeaders({ "cf-region-code": "SP" });
|
|
100
|
-
expect(match({ includeLocations: [] }, ctx)).toBe(true);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("missing includeLocations → match", () => {
|
|
104
|
-
const ctx = ctxFromHeaders({ "cf-region-code": "SP" });
|
|
105
|
-
expect(match({}, ctx)).toBe(true);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("entry {} inside includeLocations matches everyone (parity with original)", () => {
|
|
109
|
-
const ctx = ctxFromHeaders({ "cf-region-code": "SP", "cf-ipcountry": "BR" });
|
|
110
|
-
expect(match({ includeLocations: [{}] }, ctx)).toBe(true);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("entry {} inside excludeLocations does NOT exclude anyone (parity)", () => {
|
|
114
|
-
const ctx = ctxFromHeaders({ "cf-region-code": "SP", "cf-ipcountry": "BR" });
|
|
115
|
-
expect(match({ excludeLocations: [{}] }, ctx)).toBe(true);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("excludeLocations short-circuits over includeLocations", () => {
|
|
119
|
-
const ctx = ctxFromHeaders({ "cf-region-code": "SP" });
|
|
120
|
-
expect(
|
|
121
|
-
match(
|
|
122
|
-
{
|
|
123
|
-
includeLocations: [{ regionCode: "SP" }],
|
|
124
|
-
excludeLocations: [{ regionCode: "SP" }],
|
|
125
|
-
},
|
|
126
|
-
ctx,
|
|
127
|
-
),
|
|
128
|
-
).toBe(false);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("includeLocations with [{regionCode}] fails when geo is empty", () => {
|
|
132
|
-
expect(
|
|
133
|
-
match({ includeLocations: [{ regionCode: "SP" }] }, {}),
|
|
134
|
-
).toBe(false);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
describe("locationMatcher — Map mode (haversine)", () => {
|
|
139
|
-
it("matches when source coords are within target radius", () => {
|
|
140
|
-
// Target: São Paulo center, 5km. Source: ~500m away.
|
|
141
|
-
const ctx = ctxFromHeaders({
|
|
142
|
-
"cf-iplatitude": "-23.5510",
|
|
143
|
-
"cf-iplongitude": "-46.6340",
|
|
144
|
-
});
|
|
145
|
-
expect(
|
|
146
|
-
match(
|
|
147
|
-
{ includeLocations: [{ coordinates: "-23.5505,-46.6333,5000" }] },
|
|
148
|
-
ctx,
|
|
149
|
-
),
|
|
150
|
-
).toBe(true);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("does NOT match when source coords are outside the radius", () => {
|
|
154
|
-
// Target: São Paulo, 5km. Source: Rio (~360km away).
|
|
155
|
-
const ctx = ctxFromHeaders({
|
|
156
|
-
"cf-iplatitude": "-22.9068",
|
|
157
|
-
"cf-iplongitude": "-43.1729",
|
|
158
|
-
});
|
|
159
|
-
expect(
|
|
160
|
-
match(
|
|
161
|
-
{ includeLocations: [{ coordinates: "-23.5505,-46.6333,5000" }] },
|
|
162
|
-
ctx,
|
|
163
|
-
),
|
|
164
|
-
).toBe(false);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it("Map-only rule does NOT match when source has no coordinates", () => {
|
|
168
|
-
// Deliberate divergence from deco-cx/apps: upstream lets coord-only rules
|
|
169
|
-
// vacuously pass when the visitor has no lat/lng, which matches every
|
|
170
|
-
// such visitor — a footgun in production. We require both sides to have
|
|
171
|
-
// coordinates before the haversine check passes.
|
|
172
|
-
const ctx = ctxFromHeaders({ "cf-region-code": "SP" });
|
|
173
|
-
expect(
|
|
174
|
-
match(
|
|
175
|
-
{ includeLocations: [{ coordinates: "-23.5505,-46.6333,5000" }] },
|
|
176
|
-
ctx,
|
|
177
|
-
),
|
|
178
|
-
).toBe(false);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it("AND's coordinates with regionCode on the same entry", () => {
|
|
182
|
-
// Source: SP coords, region=SP.
|
|
183
|
-
const ctx = ctxFromHeaders({
|
|
184
|
-
"cf-region-code": "SP",
|
|
185
|
-
"cf-iplatitude": "-23.5510",
|
|
186
|
-
"cf-iplongitude": "-46.6340",
|
|
187
|
-
});
|
|
188
|
-
// Entry asks for region=SP AND within 5km of SP center — matches.
|
|
189
|
-
expect(
|
|
190
|
-
match(
|
|
191
|
-
{
|
|
192
|
-
includeLocations: [
|
|
193
|
-
{ regionCode: "SP", coordinates: "-23.5505,-46.6333,5000" },
|
|
194
|
-
],
|
|
195
|
-
},
|
|
196
|
-
ctx,
|
|
197
|
-
),
|
|
198
|
-
).toBe(true);
|
|
199
|
-
// Entry asks for region=SP AND within 5km of Rio — fails on coords.
|
|
200
|
-
expect(
|
|
201
|
-
match(
|
|
202
|
-
{
|
|
203
|
-
includeLocations: [
|
|
204
|
-
{ regionCode: "SP", coordinates: "-22.9068,-43.1729,5000" },
|
|
205
|
-
],
|
|
206
|
-
},
|
|
207
|
-
ctx,
|
|
208
|
-
),
|
|
209
|
-
).toBe(false);
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
describe("locationMatcher — data source fallbacks", () => {
|
|
214
|
-
it("reads from request.cf when headers are absent", () => {
|
|
215
|
-
const ctx = ctxFromCf({ country: "BR", regionCode: "SP" });
|
|
216
|
-
expect(match({ includeLocations: [{ regionCode: "SP" }] }, ctx)).toBe(true);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it("reads from __cf_geo_* cookies as fallback", () => {
|
|
220
|
-
const ctx = ctxFromCookies({
|
|
221
|
-
__cf_geo_country: "BR",
|
|
222
|
-
__cf_geo_region_code: "SP",
|
|
223
|
-
});
|
|
224
|
-
expect(match({ includeLocations: [{ regionCode: "SP" }] }, ctx)).toBe(true);
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it("decodes URL-encoded cookie values (e.g. city with accent)", () => {
|
|
228
|
-
const ctx = ctxFromCookies({
|
|
229
|
-
__cf_geo_country: "BR",
|
|
230
|
-
__cf_geo_city: encodeURIComponent("São Paulo"),
|
|
231
|
-
});
|
|
232
|
-
expect(
|
|
233
|
-
match({ includeLocations: [{ city: "São Paulo" }] }, ctx),
|
|
234
|
-
).toBe(true);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it("headers take precedence over request.cf and cookies", () => {
|
|
238
|
-
const request = new Request("https://example.com/", {
|
|
239
|
-
headers: { "cf-region-code": "SP" },
|
|
240
|
-
});
|
|
241
|
-
Object.defineProperty(request, "cf", {
|
|
242
|
-
value: { regionCode: "RJ", country: "BR" },
|
|
243
|
-
configurable: true,
|
|
244
|
-
});
|
|
245
|
-
const ctx: MatcherContext = {
|
|
246
|
-
request,
|
|
247
|
-
cookies: { __cf_geo_region_code: "MG" },
|
|
248
|
-
};
|
|
249
|
-
expect(match({ includeLocations: [{ regionCode: "SP" }] }, ctx)).toBe(true);
|
|
250
|
-
expect(match({ includeLocations: [{ regionCode: "RJ" }] }, ctx)).toBe(false);
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
function matchDate(rule: Record<string, unknown>): boolean {
|
|
255
|
-
return evaluateMatcher({ ...rule, __resolveType: DATE_KEY }, {});
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
describe("dateMatcher — parity with deco-cx/apps website/matchers/date.ts", () => {
|
|
259
|
-
beforeEach(() => {
|
|
260
|
-
vi.useFakeTimers();
|
|
261
|
-
vi.setSystemTime(new Date("2026-07-07T12:00:00Z"));
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
afterEach(() => {
|
|
265
|
-
vi.useRealTimers();
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
it("matches when neither start nor end is given (vacuously true)", () => {
|
|
269
|
-
expect(matchDate({})).toBe(true);
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
it("matches when now is after start and no end is given", () => {
|
|
273
|
-
expect(matchDate({ start: "2026-07-01T00:00:00Z" })).toBe(true);
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
it("does not match when now is before start", () => {
|
|
277
|
-
expect(matchDate({ start: "2026-08-01T00:00:00Z" })).toBe(false);
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
it("matches when now is before end and no start is given", () => {
|
|
281
|
-
expect(matchDate({ end: "2026-08-01T00:00:00Z" })).toBe(true);
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
it("does not match when now is after end", () => {
|
|
285
|
-
expect(matchDate({ end: "2026-06-01T00:00:00Z" })).toBe(false);
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
it("matches when now is strictly between start and end", () => {
|
|
289
|
-
expect(
|
|
290
|
-
matchDate({ start: "2026-07-01T00:00:00Z", end: "2026-07-31T00:00:00Z" }),
|
|
291
|
-
).toBe(true);
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
it("does not match outside a [start, end] window in either direction", () => {
|
|
295
|
-
expect(
|
|
296
|
-
matchDate({ start: "2026-08-01T00:00:00Z", end: "2026-09-01T00:00:00Z" }),
|
|
297
|
-
).toBe(false);
|
|
298
|
-
expect(
|
|
299
|
-
matchDate({ start: "2026-01-01T00:00:00Z", end: "2026-02-01T00:00:00Z" }),
|
|
300
|
-
).toBe(false);
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
it("does not match at the exact start boundary instant (strict >, not >=)", () => {
|
|
304
|
-
expect(matchDate({ start: "2026-07-07T12:00:00Z" })).toBe(false);
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
it("does not match at the exact end boundary instant (strict <, not <=)", () => {
|
|
308
|
-
expect(matchDate({ end: "2026-07-07T12:00:00Z" })).toBe(false);
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
it("treats an invalid start date as non-matching (NaN comparison is always false)", () => {
|
|
312
|
-
expect(matchDate({ start: "not-a-date" })).toBe(false);
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it("treats an invalid end date as non-matching", () => {
|
|
316
|
-
expect(matchDate({ end: "not-a-date" })).toBe(false);
|
|
317
|
-
});
|
|
318
|
-
});
|