@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,111 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { RequestContext } from "../sdk/requestContext";
|
|
3
|
-
import { buildSectionLoaderContext } from "./sectionLoaderContext";
|
|
4
|
-
|
|
5
|
-
const MOBILE_UA =
|
|
6
|
-
"Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 Mobile/15E148";
|
|
7
|
-
const DESKTOP_UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36";
|
|
8
|
-
const TABLET_UA = "Mozilla/5.0 (iPad; CPU OS 17_0 like Mac OS X) AppleWebKit/605.1.15";
|
|
9
|
-
|
|
10
|
-
function reqWithUA(ua: string, url = "https://store.example/path?q=shoes"): Request {
|
|
11
|
-
return new Request(url, { headers: { "user-agent": ua } });
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
describe("buildSectionLoaderContext", () => {
|
|
15
|
-
describe("device", () => {
|
|
16
|
-
it("detects mobile / desktop / tablet from the request User-Agent", () => {
|
|
17
|
-
expect(buildSectionLoaderContext(reqWithUA(MOBILE_UA)).device).toBe("mobile");
|
|
18
|
-
expect(buildSectionLoaderContext(reqWithUA(DESKTOP_UA)).device).toBe("desktop");
|
|
19
|
-
expect(buildSectionLoaderContext(reqWithUA(TABLET_UA)).device).toBe("tablet");
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("defaults to desktop when there is no User-Agent", () => {
|
|
23
|
-
expect(buildSectionLoaderContext(new Request("https://store.example/")).device).toBe(
|
|
24
|
-
"desktop",
|
|
25
|
-
);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("never throws for a minimal/mock request without headers", () => {
|
|
29
|
-
const badReq = { url: "not a url" } as unknown as Request;
|
|
30
|
-
expect(() => buildSectionLoaderContext(badReq)).not.toThrow();
|
|
31
|
-
expect(buildSectionLoaderContext(badReq).device).toBe("desktop");
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe("app state", () => {
|
|
36
|
-
it("resolves ctx.<appName> to the app's registered state inside a request scope", async () => {
|
|
37
|
-
const req = reqWithUA(DESKTOP_UA);
|
|
38
|
-
await RequestContext.run(req, async () => {
|
|
39
|
-
RequestContext.setBag("app:vtex:state", { config: { account: "acme" } });
|
|
40
|
-
const ctx = buildSectionLoaderContext(req);
|
|
41
|
-
expect((ctx as any).vtex).toEqual({ config: { account: "acme" } });
|
|
42
|
-
expect(ctx.getAppState("vtex")).toEqual({ config: { account: "acme" } });
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("returns undefined for an unconfigured app (no fake object)", async () => {
|
|
47
|
-
const req = reqWithUA(DESKTOP_UA);
|
|
48
|
-
await RequestContext.run(req, async () => {
|
|
49
|
-
const ctx = buildSectionLoaderContext(req);
|
|
50
|
-
expect((ctx as any).salesforce).toBeUndefined();
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("returns undefined for app state outside a request scope", () => {
|
|
55
|
-
const ctx = buildSectionLoaderContext(reqWithUA(DESKTOP_UA));
|
|
56
|
-
expect((ctx as any).vtex).toBeUndefined();
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
describe("response.headers", () => {
|
|
61
|
-
it("writes through to RequestContext.responseHeaders inside a scope", async () => {
|
|
62
|
-
const req = reqWithUA(DESKTOP_UA);
|
|
63
|
-
await RequestContext.run(req, async () => {
|
|
64
|
-
const ctx = buildSectionLoaderContext(req);
|
|
65
|
-
ctx.response.headers.set("set-cookie", "a=1");
|
|
66
|
-
expect(RequestContext.responseHeaders.get("set-cookie")).toBe("a=1");
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("degrades to an inert Headers outside a scope (does not throw)", () => {
|
|
71
|
-
const ctx = buildSectionLoaderContext(reqWithUA(DESKTOP_UA));
|
|
72
|
-
expect(() => ctx.response.headers.set("x", "y")).not.toThrow();
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
describe("invoke (server-side self-fetch)", () => {
|
|
77
|
-
let fetchMock: ReturnType<typeof vi.fn>;
|
|
78
|
-
|
|
79
|
-
beforeEach(() => {
|
|
80
|
-
fetchMock = vi
|
|
81
|
-
.fn()
|
|
82
|
-
.mockResolvedValue(new Response(JSON.stringify({ ok: true }), { status: 200 }));
|
|
83
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
afterEach(() => {
|
|
87
|
-
vi.unstubAllGlobals();
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("POSTs to the request's absolute origin /deco/invoke/<key>", async () => {
|
|
91
|
-
const ctx = buildSectionLoaderContext(reqWithUA(DESKTOP_UA, "https://store.example/pdp"));
|
|
92
|
-
const result = await ctx.invoke.vtex.loaders.product.detailsPageGQL({ slug: "x" });
|
|
93
|
-
|
|
94
|
-
expect(result).toEqual({ ok: true });
|
|
95
|
-
const [url, init] = fetchMock.mock.calls[0];
|
|
96
|
-
expect(url).toBe("https://store.example/deco/invoke/vtex/loaders/product/detailsPageGQL");
|
|
97
|
-
expect(init.method).toBe("POST");
|
|
98
|
-
expect(JSON.parse(init.body)).toEqual({ slug: "x" });
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("injects the request AbortSignal when invoked inside a request scope", async () => {
|
|
102
|
-
const req = reqWithUA(DESKTOP_UA, "https://store.example/pdp");
|
|
103
|
-
await RequestContext.run(req, async () => {
|
|
104
|
-
const ctx = buildSectionLoaderContext(req);
|
|
105
|
-
await ctx.invoke.vtex.loaders.x({});
|
|
106
|
-
const [, init] = fetchMock.mock.calls[0];
|
|
107
|
-
expect(init.signal).toBeInstanceOf(AbortSignal);
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
});
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Section-loader compatibility context (`ctx`) — issue #305.
|
|
3
|
-
*
|
|
4
|
-
* deco.cx (Fresh) section loaders use a 3-arg signature
|
|
5
|
-
* `(props, req, ctx: AppContext)`, where `ctx` exposes device detection,
|
|
6
|
-
* `ctx.invoke.*`, per-app state (`ctx.vtex`, `ctx.salesforce`, …) and
|
|
7
|
-
* `ctx.response.headers`. `@decocms/blocks` invokes loaders with only
|
|
8
|
-
* `(props, req)`, so migrated loaders read `undefined` and throw.
|
|
9
|
-
*
|
|
10
|
-
* Rather than delete `ctx` (which would force rewriting every migrated
|
|
11
|
-
* loader by hand), we re-assemble a **real** compat `ctx` from the primitives
|
|
12
|
-
* the framework already has — no fabricated stubs (policy D3):
|
|
13
|
-
*
|
|
14
|
-
* - `device` → {@link detectDevice} on the request User-Agent. Derived from
|
|
15
|
-
* `req` (NOT `RequestContext`) on purpose: the `createServerFn` path used in
|
|
16
|
-
* dev / SPA navigation is not wrapped in `RequestContext.run`, so a
|
|
17
|
-
* RequestContext-only device would silently degrade to "desktop" there.
|
|
18
|
-
* - `invoke` → the same nested invoke proxy the client uses, but pointed at
|
|
19
|
-
* an absolute self-origin and routed through `RequestContext.fetch` so the
|
|
20
|
-
* request's AbortSignal propagates. `ctx.invoke.vtex.loaders.x(props)` works
|
|
21
|
-
* server-side via a self-fetch to `/deco/invoke`.
|
|
22
|
-
* - app state → `RequestContext.getAppState(name)`; any unknown property access
|
|
23
|
-
* (`ctx.vtex`, `ctx.salesforce`, …) resolves to the app's registered state
|
|
24
|
-
* or `undefined`. Real lookup, not a fake object.
|
|
25
|
-
* - `response.headers` → `RequestContext.responseHeaders` when in a request
|
|
26
|
-
* scope; an inert `Headers` otherwise (writes don't propagate in dev/SPA but
|
|
27
|
-
* never crash).
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
import { type Device, detectDevice } from "../sdk/detectDevice";
|
|
31
|
-
import { createAppInvokeWith } from "../sdk/invoke";
|
|
32
|
-
import { RequestContext } from "../sdk/requestContext";
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* The compat context handed to section loaders as the 3rd argument.
|
|
36
|
-
*
|
|
37
|
-
* It is indexable (`[appName: string]: unknown`) because Fresh loaders read
|
|
38
|
-
* per-app state off `ctx` directly (`ctx.vtex`, `ctx.salesforce`, …). Those
|
|
39
|
-
* reads resolve through {@link RequestContext.getAppState}. Migrated code
|
|
40
|
-
* should still optional-chain deep app-state reads (`ctx.vtex?.config`), since
|
|
41
|
-
* an app that isn't configured yields `undefined`.
|
|
42
|
-
*/
|
|
43
|
-
export interface SectionLoaderContext {
|
|
44
|
-
/** Device type detected from the request User-Agent. */
|
|
45
|
-
device: Device;
|
|
46
|
-
/**
|
|
47
|
-
* Nested invoke proxy (`ctx.invoke.vtex.loaders.x(props)`), bound to this
|
|
48
|
-
* request's origin and AbortSignal. Works server-side via self-fetch.
|
|
49
|
-
*/
|
|
50
|
-
invoke: any;
|
|
51
|
-
/** Outgoing response headers (e.g. for Set-Cookie forwarding). */
|
|
52
|
-
response: { headers: Headers };
|
|
53
|
-
/** Typed access to an app's request-scoped state. */
|
|
54
|
-
getAppState: <T>(appName: string) => T | undefined;
|
|
55
|
-
/** Per-app state read directly off ctx (Fresh compatibility). */
|
|
56
|
-
[appName: string]: unknown;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Build the compat {@link SectionLoaderContext} for a single loader call.
|
|
61
|
-
* Cheap to construct (device detect + lazy proxies), so it's fine to build
|
|
62
|
-
* per section loader invocation.
|
|
63
|
-
*/
|
|
64
|
-
export function buildSectionLoaderContext(req: Request): SectionLoaderContext {
|
|
65
|
-
// Defensive: `req` may be a minimal/mock request without a real `headers`
|
|
66
|
-
// object. Building the ctx must never throw — that would take down the
|
|
67
|
-
// loader before it runs.
|
|
68
|
-
const device = detectDevice(req.headers?.get?.("user-agent") ?? "");
|
|
69
|
-
|
|
70
|
-
let origin = "";
|
|
71
|
-
try {
|
|
72
|
-
origin = new URL(req.url).origin;
|
|
73
|
-
} catch {
|
|
74
|
-
// Relative/opaque request URL — fall back to a relative base path.
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const invoke = createAppInvokeWith({
|
|
78
|
-
basePath: `${origin}/deco/invoke`,
|
|
79
|
-
fetcher: (input, init) => RequestContext.fetch(input, init),
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
const base = {
|
|
83
|
-
device,
|
|
84
|
-
invoke,
|
|
85
|
-
get response(): { headers: Headers } {
|
|
86
|
-
// `responseHeaders` throws outside a request scope (dev/SPA serverFn
|
|
87
|
-
// path). Degrade to an inert Headers rather than crash the loader.
|
|
88
|
-
let headers: Headers;
|
|
89
|
-
try {
|
|
90
|
-
headers = RequestContext.responseHeaders;
|
|
91
|
-
} catch {
|
|
92
|
-
headers = new Headers();
|
|
93
|
-
}
|
|
94
|
-
return { headers };
|
|
95
|
-
},
|
|
96
|
-
getAppState<T>(appName: string): T | undefined {
|
|
97
|
-
return RequestContext.getAppState<T>(appName);
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const known = new Set(["device", "invoke", "response", "getAppState"]);
|
|
102
|
-
|
|
103
|
-
// Wrap so unknown property access (`ctx.vtex`, `ctx.salesforce`, …) resolves
|
|
104
|
-
// to the app's registered state. Known fields fall through to `base`.
|
|
105
|
-
return new Proxy(base as SectionLoaderContext, {
|
|
106
|
-
get(target, prop, receiver) {
|
|
107
|
-
if (typeof prop === "string" && !known.has(prop) && !(prop in target)) {
|
|
108
|
-
return RequestContext.getAppState(prop);
|
|
109
|
-
}
|
|
110
|
-
return Reflect.get(target, prop, receiver);
|
|
111
|
-
},
|
|
112
|
-
});
|
|
113
|
-
}
|