@contentful/experiences-client 0.9.1 → 0.9.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## 0.9.3 (2026-10-12)
2
+
3
+ ### 🚀 Features
4
+
5
+ - [NT-4312] keep a raw payload's source map and let callers override it ([#222](https://github.com/contentful/experiences/pull/222))
6
+
7
+ ### 🧱 Updated Dependencies
8
+
9
+ - Updated core to 0.12.2
10
+
11
+ ## 0.9.2 (2026-10-09)
12
+
13
+ ### 🚀 Features
14
+
15
+ - **runtime:** extract shared runtime from client ([#228](https://github.com/contentful/experiences/pull/228))
16
+
17
+ ### 🧱 Updated Dependencies
18
+
19
+ - Updated core to 0.12.1
20
+
1
21
  ## 0.9.1 (2026-10-08)
2
22
 
3
23
  ### 🚀 Features
package/README.md CHANGED
@@ -2,98 +2,12 @@
2
2
 
3
3
  > **Internal package.** Published to npm so framework adapters can resolve it at install time, but you're not meant to import it directly. It comes in transitively via the framework adapter (`@contentful/experiences-react`, `@contentful/experiences-svelte`, etc.).
4
4
 
5
- Isolates `@contentful/experience-delivery` — the generated experience delivery client — so that `@contentful/experiences-sdk-core` stays dependency-free and framework adapters that don't need network access don't pull it in transitively. It also owns the lower-layer shared `ContentfulExperiences` runtime for the public Node and Web SDKs and event construction.
6
-
7
- `ContentfulExperiences` is intentionally not re-exported by framework adapters
8
- and is not a new application-facing adapter API. The existing free functions
9
- remain supported for adapter and application integration.
5
+ Isolates `@contentful/experience-delivery` — the generated Experience Delivery client — and owns the free fetch functions, payload conversion, delivery errors, and XDA-derived request types. The shared runtime and complete `EventBuilder` live in `@contentful/experiences-runtime`, which depends on this package. Client does not build events or depend on Runtime. The existing free functions remain supported for adapter and application integration.
10
6
 
11
7
  ---
12
8
 
13
9
  ## What's in here
14
10
 
15
- ### Shared lower-layer runtime
16
-
17
- `ContentfulExperiences` is an internal shared runtime contract for the public
18
- Node/Web SDKs. Construct it with a space, environment, resolver configuration,
19
- a delivery configuration, and an `eventBuilder` config with an explicit
20
- `channel`; optionally provide a preview configuration. It constructs and retains
21
- those clients, merges configured resolve defaults with per-call options, and
22
- exposes `resolveExperience` and by-id/destination `fetchExperience` methods.
23
- Calling `fetchExperience` with `preview: true` requires preview configuration.
24
-
25
- The runtime-owned Delivery and Preview clients support two security models. For
26
- direct API access, provide an `accessToken`; it may be a supplier and is sent to
27
- the selected endpoint. For a trusted application proxy that adds the upstream
28
- token itself, omit `accessToken` and provide an explicit `host`; the runtime
29
- disables generated bearer authentication. `environmentId` is the Contentful
30
- environment identifier passed to by-ID requests, not the generated delivery
31
- client's optional endpoint-valued `environment`. Endpoint precedence is
32
- explicit `host`, then generated-client `environment`, then the delivery or
33
- preview default.
34
-
35
- Direct browser tokens are credentials but are intentionally browser-visible
36
- when an application's scope and CORS policy permit that model. Proxy mode keeps
37
- the upstream token server-side. In either mode, treat custom endpoints as
38
- trusted configuration.
39
-
40
- The optional preview client enables direct CPA fetches by Experience ID through
41
- the same shared runtime. It is separate from `@contentful/experiences-live-preview`,
42
- which owns Preview Session HTTP loading, WebSocket subscription, and update state.
43
- Destination operations continue to use the delivery client.
44
-
45
- The runtime constructs and owns one `EventBuilder` and one Optimization API
46
- client. The caller supplies the event channel, while the runtime retains this
47
- SDK's default library identity and the runtime locale unless overridden. This
48
- package owns event construction and direct transport for the lower layer,
49
- rather than Core. It exposes a protected binding point used by the public Node
50
- and Web leaves; Client itself does not retain a mutable event profile.
51
-
52
- By default the Optimization client uses the runtime's `spaceId` and maps its
53
- Contentful `environmentId` to the Optimization client's `environment` option.
54
- This is the same Contentful environment identifier passed to by-ID delivery
55
- requests, not the generated delivery client's endpoint-valued `environment`
56
- setting. The optional `optimization` configuration can provide API-specific
57
- endpoint, feature, and fetch overrides; the runtime always constructs and owns
58
- the Optimization client. Custom Optimization base URLs receive complete event
59
- and profile payloads, so treat them as sensitive-data destinations and use only
60
- trusted HTTPS origins outside explicit local development.
61
-
62
- The bound event methods normally send immediately: `identify`, `page`, and
63
- `track` upsert a profile through the Personalization API; view, click, hover,
64
- and flag-view events send a one-event batch through Analytics. Queues, durable
65
- profile persistence, consent gating, lifecycle/beacon delivery, automatic
66
- interaction tracking, and Live Preview integration are intentionally absent.
67
- The Node leaf additionally has a request-scoped, one-shot handoff journal for
68
- paired browser replay; it is not an SDK queue or persistence mechanism. Because
69
- calls are not serialized, callers must await profile-producing calls before
70
- starting another profile-producing or Analytics call on the same bound runtime.
71
-
72
- ### Server-to-browser event handoff contract
73
-
74
- `RuntimeEventHandoff` is the internal replay payload between Node and Web. Node
75
- alone chooses direct `commit` or paired-browser `handoff` delivery per request.
76
- The handoff holds a version, Contentful scope, optional initial profile, ordered
77
- Personalization/Analytics event bodies, and an optional initial-page route key. Its
78
- internal serialized-payload cap is 64 KiB. Node can preflight the initial
79
- Personalization sequence as one batch; individual Personalization methods remain
80
- cumulative and Analytics methods stage without transport. Web validates the
81
- payload, admits page-bearing journals only for a matching browser route,
82
- batches compatible adjacent Personalization entries, preserves locale and Analytics
83
- ordering boundaries, and chains each resulting profile.
84
-
85
- The payload is browser-visible sensitive data. Application integration must use
86
- escaped serialization in a private, no-store response and exclude secrets and
87
- server-only traits. Do not cache, log, or persist it. Replay may partially
88
- commit, has no automatic retry or distributed exactly-once guarantee, and is
89
- independent from Live Preview. A failed replay rejects its receipt but releases
90
- later direct Web calls. See the root [paired replay guide](../../README.md#paired-server-to-browser-replay).
91
-
92
- This package's direct dependencies are the generated delivery client,
93
- `@contentful/optimization-api-client` (event schemas, logger, and transport), `es-toolkit`
94
- (event-property merging), and `zod` (event argument schemas), in addition to
95
- Core. None of those dependencies are introduced into Core.
96
-
97
11
  ### `fetchExperience(experienceOptions, clientOptions, resolveOptions)`
98
12
 
99
13
  The primary fetch + resolve entry point. Fetches an Experience payload from the Experience Delivery API and resolves it into a `PortableRenderPlan` in one call.
@@ -10,20 +10,6 @@ type CreateClientOptions = {
10
10
  */
11
11
  host?: string;
12
12
  } & Omit<ContentfulViewDeliveryClient.Options, 'token' | 'baseUrl'>;
13
- type RuntimeDeliveryClientBaseOptions = Omit<ContentfulViewDeliveryClient.Options, 'token' | 'baseUrl'>;
14
- /** Configuration for a Delivery or Preview client owned by a runtime. */
15
- type RuntimeDeliveryClientOptions = RuntimeDeliveryClientBaseOptions & ({
16
- /** Bearer token or token supplier used for direct Delivery/Preview API access. */
17
- accessToken: ContentfulViewDeliveryClient.Options['token'];
18
- /** Optional endpoint override or endpoint supplier. */
19
- host?: ContentfulViewDeliveryClient.Options['baseUrl'];
20
- } | {
21
- accessToken?: never;
22
- /** Explicit proxy endpoint that owns upstream authentication. */
23
- host: NonNullable<ContentfulViewDeliveryClient.Options['baseUrl']>;
24
- });
25
13
  declare function createClient(options: CreateClientOptions): ContentfulViewDeliveryClient;
26
- /** Constructs a runtime-owned client, disabling generated auth for a tokenless proxy. */
27
- declare function createRuntimeDeliveryClient(options: RuntimeDeliveryClientOptions, defaultHost?: NonNullable<ContentfulViewDeliveryClient.Options['baseUrl']>): ContentfulViewDeliveryClient;
28
14
 
29
- export { type CreateClientOptions, type RuntimeDeliveryClientOptions, createClient, createRuntimeDeliveryClient };
15
+ export { type CreateClientOptions, createClient };
@@ -7,21 +7,7 @@ function createClient(options) {
7
7
  baseUrl: host
8
8
  });
9
9
  }
10
- function createRuntimeDeliveryClient(options, defaultHost) {
11
- const { accessToken, host, ...rest } = options;
12
- if (accessToken === void 0 && host === void 0) {
13
- throw new Error(
14
- "Runtime delivery configuration requires accessToken unless an explicit proxy host is provided"
15
- );
16
- }
17
- const baseUrl = host ?? (rest.environment === void 0 ? defaultHost : void 0);
18
- const clientOptions = accessToken === void 0 ? { ...rest, auth: rest.auth ?? false, baseUrl } : { ...rest, token: accessToken, baseUrl };
19
- return new ContentfulViewDeliveryClient(
20
- clientOptions
21
- );
22
- }
23
10
  export {
24
- createClient,
25
- createRuntimeDeliveryClient
11
+ createClient
26
12
  };
27
13
  //# sourceMappingURL=create-delivery-client.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/create-delivery-client.ts"],"sourcesContent":["import { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';\n\n/** Options for the legacy functional Delivery client constructor. */\nexport type CreateClientOptions = {\n accessToken: string;\n /**\n * Base URL for the delivery client. Defaults to `DELIVERY_HOST` when omitted.\n * Pass `PREVIEW_HOST` for preview mode, or any custom URL (staging, proxy,\n * per-region). Both constants are exported from this package.\n */\n host?: string;\n} & Omit<ContentfulViewDeliveryClient.Options, 'token' | 'baseUrl'>;\n\ntype RuntimeDeliveryClientBaseOptions = Omit<\n ContentfulViewDeliveryClient.Options,\n 'token' | 'baseUrl'\n>;\n\n/** Configuration for a Delivery or Preview client owned by a runtime. */\nexport type RuntimeDeliveryClientOptions = RuntimeDeliveryClientBaseOptions &\n (\n | {\n /** Bearer token or token supplier used for direct Delivery/Preview API access. */\n accessToken: ContentfulViewDeliveryClient.Options['token'];\n /** Optional endpoint override or endpoint supplier. */\n host?: ContentfulViewDeliveryClient.Options['baseUrl'];\n }\n | {\n accessToken?: never;\n /** Explicit proxy endpoint that owns upstream authentication. */\n host: NonNullable<ContentfulViewDeliveryClient.Options['baseUrl']>;\n }\n );\n\nexport function createClient(options: CreateClientOptions): ContentfulViewDeliveryClient {\n const { accessToken, host, ...rest } = options;\n return new ContentfulViewDeliveryClient({\n ...rest,\n token: accessToken,\n baseUrl: host,\n });\n}\n\n/** Constructs a runtime-owned client, disabling generated auth for a tokenless proxy. */\nexport function createRuntimeDeliveryClient(\n options: RuntimeDeliveryClientOptions,\n defaultHost?: NonNullable<ContentfulViewDeliveryClient.Options['baseUrl']>\n): ContentfulViewDeliveryClient {\n const { accessToken, host, ...rest } = options;\n if (accessToken === undefined && host === undefined) {\n throw new Error(\n 'Runtime delivery configuration requires accessToken unless an explicit proxy host is provided'\n );\n }\n\n const baseUrl = host ?? (rest.environment === undefined ? defaultHost : undefined);\n const clientOptions =\n accessToken === undefined\n ? { ...rest, auth: rest.auth ?? false, baseUrl }\n : { ...rest, token: accessToken, baseUrl };\n\n return new ContentfulViewDeliveryClient(\n clientOptions as unknown as ContentfulViewDeliveryClient.Options\n );\n}\n"],"mappings":"AAAA,SAAS,oCAAoC;AAkCtC,SAAS,aAAa,SAA4D;AACvF,QAAM,EAAE,aAAa,MAAM,GAAG,KAAK,IAAI;AACvC,SAAO,IAAI,6BAA6B;AAAA,IACtC,GAAG;AAAA,IACH,OAAO;AAAA,IACP,SAAS;AAAA,EACX,CAAC;AACH;AAGO,SAAS,4BACd,SACA,aAC8B;AAC9B,QAAM,EAAE,aAAa,MAAM,GAAG,KAAK,IAAI;AACvC,MAAI,gBAAgB,UAAa,SAAS,QAAW;AACnD,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UAAU,SAAS,KAAK,gBAAgB,SAAY,cAAc;AACxE,QAAM,gBACJ,gBAAgB,SACZ,EAAE,GAAG,MAAM,MAAM,KAAK,QAAQ,OAAO,QAAQ,IAC7C,EAAE,GAAG,MAAM,OAAO,aAAa,QAAQ;AAE7C,SAAO,IAAI;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/create-delivery-client.ts"],"sourcesContent":["import { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';\n\n/** Options for the legacy functional Delivery client constructor. */\nexport type CreateClientOptions = {\n accessToken: string;\n /**\n * Base URL for the delivery client. Defaults to `DELIVERY_HOST` when omitted.\n * Pass `PREVIEW_HOST` for preview mode, or any custom URL (staging, proxy,\n * per-region). Both constants are exported from this package.\n */\n host?: string;\n} & Omit<ContentfulViewDeliveryClient.Options, 'token' | 'baseUrl'>;\n\nexport function createClient(options: CreateClientOptions): ContentfulViewDeliveryClient {\n const { accessToken, host, ...rest } = options;\n return new ContentfulViewDeliveryClient({\n ...rest,\n token: accessToken,\n baseUrl: host,\n });\n}\n"],"mappings":"AAAA,SAAS,oCAAoC;AAatC,SAAS,aAAa,SAA4D;AACvF,QAAM,EAAE,aAAa,MAAM,GAAG,KAAK,IAAI;AACvC,SAAO,IAAI,6BAA6B;AAAA,IACtC,GAAG;AAAA,IACH,OAAO;AAAA,IACP,SAAS;AAAA,EACX,CAAC;AACH;","names":[]}
@@ -4,7 +4,6 @@ import { assertDestinationPreviewSupported } from "./destination-guards.js";
4
4
  import { resolveDeliveryClient } from "./client-resolution.js";
5
5
  import { ExperienceFetchError } from "./errors.js";
6
6
  import {
7
- readSourceMap,
8
7
  toExperiencePayload,
9
8
  toExperiencePayloadFromDestination
10
9
  } from "./to-experience-payload.js";
@@ -51,13 +50,8 @@ async function fetchExperience(experienceOptions, clientOptions, resolveOptions)
51
50
  });
52
51
  const response = await fetchByExperienceId(client, experienceOptions);
53
52
  const payload = toExperiencePayload(response);
54
- const sourceMap = extensions?.sourceMap !== void 0 ? readSourceMap(response) : void 0;
55
53
  log.lazy("received raw payload", () => payload);
56
- return resolveExperience(payload, config, {
57
- metadata,
58
- debug,
59
- sourceMap
60
- });
54
+ return resolveExperience(payload, config, { metadata, debug });
61
55
  }
62
56
  async function fetchByExperienceId(client, options) {
63
57
  const { spaceId, environmentId, experienceId, locale, personalization, extensions } = options;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/fetch-experience.ts"],"sourcesContent":["import type { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';\nimport { ContentfulViewDelivery } from '@contentful/experience-delivery';\nimport { createDebugLogger, resolveExperience } from '@contentful/experiences-sdk-core';\nimport type { PortableRenderPlan, ResolverConfig } from '@contentful/experiences-sdk-core';\nimport { assertDestinationPreviewSupported } from './destination-guards.js';\nimport { resolveDeliveryClient, type ClientOptions } from './client-resolution.js';\nimport { ExperienceFetchError } from './errors.js';\nimport {\n readSourceMap,\n toExperiencePayload,\n toExperiencePayloadFromDestination,\n type ExperienceResponse,\n} from './to-experience-payload.js';\n\nexport type { ClientOptions };\n\ntype DeliveryExperienceRequestExtensions =\n ContentfulViewDelivery.GetWithOverridesExperienceRequestExtensions;\n\nexport type PersonalizationOptions = NonNullable<\n DeliveryExperienceRequestExtensions['personalization']\n>;\n\nexport type ExperienceRequestExtensions = Omit<\n DeliveryExperienceRequestExtensions,\n 'personalization'\n>;\n\nexport type ByIdExperienceOptions = {\n spaceId: string;\n environmentId: string;\n experienceId: string;\n locale?: string;\n /**\n * Profile and events used by XDA to personalize the resolved Experience.\n */\n personalization?: PersonalizationOptions;\n /**\n * Additional XDA request extensions such as source maps. Supplying a defined\n * extension switches the request to POST.\n */\n extensions?: ExperienceRequestExtensions;\n};\n\n/**\n * Resolve an Experience by the Destination Node instead of `experienceId`\n * The destinations delivery endpoints are space-scoped only and have no locale\n * param, unlike the by-id path.\n */\nexport type ByDestinationNodeIdExperienceOptions = {\n spaceId: string;\n destinationId: string;\n nodeId: string;\n};\n\n/**\n * Resolve an Experience by the absolute path wired up to a\n * Destination Node, instead of a node id directly. Same scoping as\n * `ByDestinationNodeIdExperienceOptions` — no `environmentId` or `locale`.\n */\nexport type ByDestinationPathExperienceOptions = {\n spaceId: string;\n destinationId: string;\n /** Absolute path to resolve. Must start with `/`. */\n path: string;\n};\n\nexport type ExperienceOptions =\n ByIdExperienceOptions | ByDestinationNodeIdExperienceOptions | ByDestinationPathExperienceOptions;\n\n/**\n * A Destination resolution that the app must act on as control flow — honor\n * it by navigating or re-resolving at the new path — rather than a hydrated\n * Experience to render. Modeled as a normal return value, not a thrown error,\n * per the Destinations delivery API's own framing of a redirect response.\n */\nexport interface DestinationRedirectResult {\n redirect: { path: string };\n}\n\nexport type ResolveOptions = {\n config: ResolverConfig;\n /**\n * Arbitrary per-render metadata exposed to every resolver as\n * `ctx.experience.metadata` and readable at render time via the framework\n * adapter's `useExperience()` / `getExperience()`.\n */\n metadata?: Record<string, unknown>;\n /**\n * Observability switch. When on: logs the fetch (host, ids) and the raw\n * payload here, and threads through to `resolveExperience` (resolution steps\n * + `resolveData` timings) and the renderer (visible missing-component box,\n * debug fallback). A single boolean across fetch + resolve + render.\n */\n debug?: boolean;\n};\n\n// TS overload signatures, not real redeclarations — base ESLint's no-redeclare doesn't know the\n// overload form (@typescript-eslint's own version does), so each repeated signature needs a\n// disable comment.\nexport async function fetchExperience(\n experienceOptions: ByIdExperienceOptions,\n clientOptions: ClientOptions,\n resolveOptions: ResolveOptions\n): Promise<PortableRenderPlan>;\n// eslint-disable-next-line no-redeclare -- see above\nexport async function fetchExperience(\n experienceOptions: ByDestinationNodeIdExperienceOptions,\n clientOptions: ClientOptions,\n resolveOptions: ResolveOptions\n): Promise<PortableRenderPlan | DestinationRedirectResult>;\n// eslint-disable-next-line no-redeclare -- see above\nexport async function fetchExperience(\n experienceOptions: ByDestinationPathExperienceOptions,\n clientOptions: ClientOptions,\n resolveOptions: ResolveOptions\n): Promise<PortableRenderPlan | DestinationRedirectResult>;\n// eslint-disable-next-line no-redeclare -- see above\nexport async function fetchExperience(\n experienceOptions: ExperienceOptions,\n clientOptions: ClientOptions,\n resolveOptions: ResolveOptions\n): Promise<PortableRenderPlan | DestinationRedirectResult> {\n const { config, metadata, debug } = resolveOptions;\n const log = createDebugLogger(debug, 'client');\n\n if (!('client' in clientOptions) && 'destinationId' in experienceOptions) {\n const { spaceId, destinationId } = experienceOptions;\n const locator =\n 'nodeId' in experienceOptions\n ? { nodeId: experienceOptions.nodeId }\n : { path: experienceOptions.path };\n assertDestinationPreviewSupported(clientOptions.preview, {\n spaceId,\n destinationId,\n ...locator,\n });\n }\n\n const client = resolveDeliveryClient(clientOptions, log, 'fetchExperience');\n\n if ('nodeId' in experienceOptions) {\n const { spaceId, destinationId, nodeId } = experienceOptions;\n return fetchByDestination(\n { spaceId, destinationId, locator: nodeId },\n () => client.destination.resolveByNodeId(spaceId, destinationId, nodeId),\n log,\n { config, metadata, debug }\n );\n }\n\n if ('path' in experienceOptions) {\n const { spaceId, destinationId, path } = experienceOptions;\n return fetchByDestination(\n { spaceId, destinationId, locator: path },\n () => client.destination.resolveByPath(spaceId, destinationId, { path }),\n log,\n { config, metadata, debug }\n );\n }\n\n const { spaceId, environmentId, experienceId, locale, personalization, extensions } =\n experienceOptions;\n\n log.log('fetching experience', {\n spaceId,\n environmentId,\n experienceId,\n locale,\n // avoiding log any personalization sensitive data\n personalization: personalization !== undefined,\n extensions,\n });\n\n const response = await fetchByExperienceId(client, experienceOptions);\n\n const payload = toExperiencePayload(response);\n const sourceMap = extensions?.sourceMap !== undefined ? readSourceMap(response) : undefined;\n\n log.lazy('received raw payload', () => payload);\n\n return resolveExperience(payload, config, {\n metadata,\n debug,\n sourceMap,\n });\n}\n\nasync function fetchByExperienceId(\n client: ContentfulViewDeliveryClient,\n options: ByIdExperienceOptions\n): Promise<ExperienceResponse> {\n const { spaceId, environmentId, experienceId, locale, personalization, extensions } = options;\n const requestExtensions: DeliveryExperienceRequestExtensions = {\n ...extensions,\n ...(personalization === undefined ? {} : { personalization }),\n };\n\n try {\n // Both methods hit the same endpoint, but only the POST operation accepts\n // extensions in its request body. Keep the cacheable GET when there are no\n // extensions to evaluate.\n // The generated delivery client owns the alpha-feature header on both\n // paths, including when the caller supplied the client instance.\n //\n // Await inside the try so rejected requests are normalized below.\n if (hasRequestExtensions(requestExtensions)) {\n return await client.experience.getWithOverrides(spaceId, environmentId, experienceId, {\n locale,\n extensions: requestExtensions,\n });\n }\n\n return await client.experience.get(spaceId, environmentId, experienceId, { locale });\n } catch (err) {\n // Preserve expected 404 control flow for framework routers. Other failures\n // are wrapped with stable SDK context instead of exposing transport-specific\n // error shapes.\n if (err instanceof ContentfulViewDelivery.NotFoundError) {\n throw err;\n }\n const reason = err instanceof Error ? err.message : String(err);\n throw new ExperienceFetchError(\n `Failed to fetch Experience \"${experienceId}\" (space \"${spaceId}\", environment ` +\n `\"${environmentId}\"): ${reason}. Check network connectivity, the access token, and ` +\n `that the space/environment/experience ids are correct.`,\n { spaceId, environmentId, experienceId, cause: err }\n );\n }\n}\n\n/**\n * Shared response-handling for both destination-shaped `fetchExperience`\n * branches (by node id, by path).\n */\nasync function fetchByDestination(\n identity: { spaceId: string; destinationId: string; locator: string },\n resolve: () => Promise<ContentfulViewDelivery.DestinationExperienceResolutionResponse>,\n log: ReturnType<typeof createDebugLogger>,\n resolveOptions: {\n config: ResolverConfig;\n metadata: Record<string, unknown> | undefined;\n debug: boolean | undefined;\n }\n): Promise<PortableRenderPlan | DestinationRedirectResult> {\n const { spaceId, destinationId, locator } = identity;\n const { config, metadata, debug } = resolveOptions;\n\n log.log('resolving destination experience', { spaceId, destinationId, locator });\n\n let response: ContentfulViewDelivery.DestinationExperienceResolutionResponse;\n try {\n response = await resolve();\n } catch (err) {\n if (err instanceof ContentfulViewDelivery.NotFoundError) {\n throw err;\n }\n const reason = err instanceof Error ? err.message : String(err);\n throw new ExperienceFetchError(\n `Failed to resolve Destination \"${destinationId}\" at \"${locator}\" (space \"${spaceId}\"): ` +\n `${reason}. Check network connectivity, the access token, and that the space/` +\n `destination/node-or-path values are correct.`,\n { spaceId, experienceId: locator, cause: err }\n );\n }\n\n if ('redirect' in response) {\n log.log('destination resolved to a redirect', response.redirect);\n return { redirect: response.redirect };\n }\n\n const [firstExperience] = response.experiences;\n if (!firstExperience) {\n throw new ExperienceFetchError(\n `Destination \"${destinationId}\" resolved \"${locator}\" to zero Experiences ` +\n `(space \"${spaceId}\"). Expected exactly one hydrated Experience or a redirect.`,\n { spaceId, experienceId: locator }\n );\n }\n\n const payload = toExperiencePayloadFromDestination(firstExperience.experience);\n log.lazy('received raw payload', () => payload);\n\n return resolveExperience(payload, config, {\n metadata,\n debug,\n });\n}\n\nfunction hasRequestExtensions(\n extensions: DeliveryExperienceRequestExtensions | undefined\n): extensions is DeliveryExperienceRequestExtensions {\n return (\n extensions !== undefined &&\n Object.values(extensions).some((extension) => extension !== undefined)\n );\n}\n"],"mappings":"AACA,SAAS,8BAA8B;AACvC,SAAS,mBAAmB,yBAAyB;AAErD,SAAS,yCAAyC;AAClD,SAAS,6BAAiD;AAC1D,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EAC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AAA,EAC3B,SAAS,KAAK;AACZ,QAAI,eAAe,uBAAuB,eAAe;AACvD,YAAM;AAAA,IACR;AACA,UAAM,SAAS,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAC9D,UAAM,IAAI;AAAA,MACR,kCAAkC,aAAa,SAAS,OAAO,aAAa,OAAO,OAC9E,MAAM;AAAA,MAEX,EAAE,SAAS,cAAc,SAAS,OAAO,IAAI;AAAA,IAC/C;AAAA,EACF;AAEA,MAAI,cAAc,UAAU;AAC1B,QAAI,IAAI,sCAAsC,SAAS,QAAQ;AAC/D,WAAO,EAAE,UAAU,SAAS,SAAS;AAAA,EACvC;AAEA,QAAM,CAAC,eAAe,IAAI,SAAS;AACnC,MAAI,CAAC,iBAAiB;AACpB,UAAM,IAAI;AAAA,MACR,gBAAgB,aAAa,eAAe,OAAO,iCACtC,OAAO;AAAA,MACpB,EAAE,SAAS,cAAc,QAAQ;AAAA,IACnC;AAAA,EACF;AAEA,QAAM,UAAU,mCAAmC,gBAAgB,UAAU;AAC7E,MAAI,KAAK,wBAAwB,MAAM,OAAO;AAE9C,SAAO,kBAAkB,SAAS,QAAQ;AAAA,IACxC;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAEA,SAAS,qBACP,YACmD;AACnD,SACE,eAAe,UACf,OAAO,OAAO,UAAU,EAAE,KAAK,CAAC,cAAc,cAAc,MAAS;AAEzE;","names":["spaceId"]}
1
+ {"version":3,"sources":["../src/fetch-experience.ts"],"sourcesContent":["import type { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';\nimport { ContentfulViewDelivery } from '@contentful/experience-delivery';\nimport { createDebugLogger, resolveExperience } from '@contentful/experiences-sdk-core';\nimport type { PortableRenderPlan, ResolverConfig } from '@contentful/experiences-sdk-core';\nimport { assertDestinationPreviewSupported } from './destination-guards.js';\nimport { resolveDeliveryClient, type ClientOptions } from './client-resolution.js';\nimport { ExperienceFetchError } from './errors.js';\nimport {\n toExperiencePayload,\n toExperiencePayloadFromDestination,\n type ExperienceResponse,\n} from './to-experience-payload.js';\n\nexport type { ClientOptions };\n\ntype DeliveryExperienceRequestExtensions =\n ContentfulViewDelivery.GetWithOverridesExperienceRequestExtensions;\n\nexport type PersonalizationOptions = NonNullable<\n DeliveryExperienceRequestExtensions['personalization']\n>;\n\nexport type ExperienceRequestExtensions = Omit<\n DeliveryExperienceRequestExtensions,\n 'personalization'\n>;\n\nexport type ByIdExperienceOptions = {\n spaceId: string;\n environmentId: string;\n experienceId: string;\n locale?: string;\n /**\n * Profile and events used by XDA to personalize the resolved Experience.\n */\n personalization?: PersonalizationOptions;\n /**\n * Additional XDA request extensions such as source maps. Supplying a defined\n * extension switches the request to POST.\n */\n extensions?: ExperienceRequestExtensions;\n};\n\n/**\n * Resolve an Experience by the Destination Node instead of `experienceId`\n * The destinations delivery endpoints are space-scoped only and have no locale\n * param, unlike the by-id path.\n */\nexport type ByDestinationNodeIdExperienceOptions = {\n spaceId: string;\n destinationId: string;\n nodeId: string;\n};\n\n/**\n * Resolve an Experience by the absolute path wired up to a\n * Destination Node, instead of a node id directly. Same scoping as\n * `ByDestinationNodeIdExperienceOptions` — no `environmentId` or `locale`.\n */\nexport type ByDestinationPathExperienceOptions = {\n spaceId: string;\n destinationId: string;\n /** Absolute path to resolve. Must start with `/`. */\n path: string;\n};\n\nexport type ExperienceOptions =\n ByIdExperienceOptions | ByDestinationNodeIdExperienceOptions | ByDestinationPathExperienceOptions;\n\n/**\n * A Destination resolution that the app must act on as control flow — honor\n * it by navigating or re-resolving at the new path — rather than a hydrated\n * Experience to render. Modeled as a normal return value, not a thrown error,\n * per the Destinations delivery API's own framing of a redirect response.\n */\nexport interface DestinationRedirectResult {\n redirect: { path: string };\n}\n\nexport type ResolveOptions = {\n config: ResolverConfig;\n /**\n * Arbitrary per-render metadata exposed to every resolver as\n * `ctx.experience.metadata` and readable at render time via the framework\n * adapter's `useExperience()` / `getExperience()`.\n */\n metadata?: Record<string, unknown>;\n /**\n * Observability switch. When on: logs the fetch (host, ids) and the raw\n * payload here, and threads through to `resolveExperience` (resolution steps\n * + `resolveData` timings) and the renderer (visible missing-component box,\n * debug fallback). A single boolean across fetch + resolve + render.\n */\n debug?: boolean;\n};\n\n// TS overload signatures, not real redeclarations — base ESLint's no-redeclare doesn't know the\n// overload form (@typescript-eslint's own version does), so each repeated signature needs a\n// disable comment.\nexport async function fetchExperience(\n experienceOptions: ByIdExperienceOptions,\n clientOptions: ClientOptions,\n resolveOptions: ResolveOptions\n): Promise<PortableRenderPlan>;\n// eslint-disable-next-line no-redeclare -- see above\nexport async function fetchExperience(\n experienceOptions: ByDestinationNodeIdExperienceOptions,\n clientOptions: ClientOptions,\n resolveOptions: ResolveOptions\n): Promise<PortableRenderPlan | DestinationRedirectResult>;\n// eslint-disable-next-line no-redeclare -- see above\nexport async function fetchExperience(\n experienceOptions: ByDestinationPathExperienceOptions,\n clientOptions: ClientOptions,\n resolveOptions: ResolveOptions\n): Promise<PortableRenderPlan | DestinationRedirectResult>;\n// eslint-disable-next-line no-redeclare -- see above\nexport async function fetchExperience(\n experienceOptions: ExperienceOptions,\n clientOptions: ClientOptions,\n resolveOptions: ResolveOptions\n): Promise<PortableRenderPlan | DestinationRedirectResult> {\n const { config, metadata, debug } = resolveOptions;\n const log = createDebugLogger(debug, 'client');\n\n if (!('client' in clientOptions) && 'destinationId' in experienceOptions) {\n const { spaceId, destinationId } = experienceOptions;\n const locator =\n 'nodeId' in experienceOptions\n ? { nodeId: experienceOptions.nodeId }\n : { path: experienceOptions.path };\n assertDestinationPreviewSupported(clientOptions.preview, {\n spaceId,\n destinationId,\n ...locator,\n });\n }\n\n const client = resolveDeliveryClient(clientOptions, log, 'fetchExperience');\n\n if ('nodeId' in experienceOptions) {\n const { spaceId, destinationId, nodeId } = experienceOptions;\n return fetchByDestination(\n { spaceId, destinationId, locator: nodeId },\n () => client.destination.resolveByNodeId(spaceId, destinationId, nodeId),\n log,\n { config, metadata, debug }\n );\n }\n\n if ('path' in experienceOptions) {\n const { spaceId, destinationId, path } = experienceOptions;\n return fetchByDestination(\n { spaceId, destinationId, locator: path },\n () => client.destination.resolveByPath(spaceId, destinationId, { path }),\n log,\n { config, metadata, debug }\n );\n }\n\n const { spaceId, environmentId, experienceId, locale, personalization, extensions } =\n experienceOptions;\n\n log.log('fetching experience', {\n spaceId,\n environmentId,\n experienceId,\n locale,\n // avoiding log any personalization sensitive data\n personalization: personalization !== undefined,\n extensions,\n });\n\n const response = await fetchByExperienceId(client, experienceOptions);\n\n const payload = toExperiencePayload(response);\n log.lazy('received raw payload', () => payload);\n\n return resolveExperience(payload, config, { metadata, debug });\n}\n\nasync function fetchByExperienceId(\n client: ContentfulViewDeliveryClient,\n options: ByIdExperienceOptions\n): Promise<ExperienceResponse> {\n const { spaceId, environmentId, experienceId, locale, personalization, extensions } = options;\n const requestExtensions: DeliveryExperienceRequestExtensions = {\n ...extensions,\n ...(personalization === undefined ? {} : { personalization }),\n };\n\n try {\n // Both methods hit the same endpoint, but only the POST operation accepts\n // extensions in its request body. Keep the cacheable GET when there are no\n // extensions to evaluate.\n // The generated delivery client owns the alpha-feature header on both\n // paths, including when the caller supplied the client instance.\n //\n // Await inside the try so rejected requests are normalized below.\n if (hasRequestExtensions(requestExtensions)) {\n return await client.experience.getWithOverrides(spaceId, environmentId, experienceId, {\n locale,\n extensions: requestExtensions,\n });\n }\n\n return await client.experience.get(spaceId, environmentId, experienceId, { locale });\n } catch (err) {\n // Preserve expected 404 control flow for framework routers. Other failures\n // are wrapped with stable SDK context instead of exposing transport-specific\n // error shapes.\n if (err instanceof ContentfulViewDelivery.NotFoundError) {\n throw err;\n }\n const reason = err instanceof Error ? err.message : String(err);\n throw new ExperienceFetchError(\n `Failed to fetch Experience \"${experienceId}\" (space \"${spaceId}\", environment ` +\n `\"${environmentId}\"): ${reason}. Check network connectivity, the access token, and ` +\n `that the space/environment/experience ids are correct.`,\n { spaceId, environmentId, experienceId, cause: err }\n );\n }\n}\n\n/**\n * Shared response-handling for both destination-shaped `fetchExperience`\n * branches (by node id, by path).\n */\nasync function fetchByDestination(\n identity: { spaceId: string; destinationId: string; locator: string },\n resolve: () => Promise<ContentfulViewDelivery.DestinationExperienceResolutionResponse>,\n log: ReturnType<typeof createDebugLogger>,\n resolveOptions: {\n config: ResolverConfig;\n metadata: Record<string, unknown> | undefined;\n debug: boolean | undefined;\n }\n): Promise<PortableRenderPlan | DestinationRedirectResult> {\n const { spaceId, destinationId, locator } = identity;\n const { config, metadata, debug } = resolveOptions;\n\n log.log('resolving destination experience', { spaceId, destinationId, locator });\n\n let response: ContentfulViewDelivery.DestinationExperienceResolutionResponse;\n try {\n response = await resolve();\n } catch (err) {\n if (err instanceof ContentfulViewDelivery.NotFoundError) {\n throw err;\n }\n const reason = err instanceof Error ? err.message : String(err);\n throw new ExperienceFetchError(\n `Failed to resolve Destination \"${destinationId}\" at \"${locator}\" (space \"${spaceId}\"): ` +\n `${reason}. Check network connectivity, the access token, and that the space/` +\n `destination/node-or-path values are correct.`,\n { spaceId, experienceId: locator, cause: err }\n );\n }\n\n if ('redirect' in response) {\n log.log('destination resolved to a redirect', response.redirect);\n return { redirect: response.redirect };\n }\n\n const [firstExperience] = response.experiences;\n if (!firstExperience) {\n throw new ExperienceFetchError(\n `Destination \"${destinationId}\" resolved \"${locator}\" to zero Experiences ` +\n `(space \"${spaceId}\"). Expected exactly one hydrated Experience or a redirect.`,\n { spaceId, experienceId: locator }\n );\n }\n\n const payload = toExperiencePayloadFromDestination(firstExperience.experience);\n log.lazy('received raw payload', () => payload);\n\n return resolveExperience(payload, config, {\n metadata,\n debug,\n });\n}\n\nfunction hasRequestExtensions(\n extensions: DeliveryExperienceRequestExtensions | undefined\n): extensions is DeliveryExperienceRequestExtensions {\n return (\n extensions !== undefined &&\n Object.values(extensions).some((extension) => extension !== undefined)\n );\n}\n"],"mappings":"AACA,SAAS,8BAA8B;AACvC,SAAS,mBAAmB,yBAAyB;AAErD,SAAS,yCAAyC;AAClD,SAAS,6BAAiD;AAC1D,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eAAe;AACvD,YAAM;AAAA,IACR;AACA,UAAM,SAAS,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAC9D,UAAM,IAAI;AAAA,MACR,kCAAkC,aAAa,SAAS,OAAO,aAAa,OAAO,OAC9E,MAAM;AAAA,MAEX,EAAE,SAAS,cAAc,SAAS,OAAO,IAAI;AAAA,IAC/C;AAAA,EACF;AAEA,MAAI,cAAc,UAAU;AAC1B,QAAI,IAAI,sCAAsC,SAAS,QAAQ;AAC/D,WAAO,EAAE,UAAU,SAAS,SAAS;AAAA,EACvC;AAEA,QAAM,CAAC,eAAe,IAAI,SAAS;AACnC,MAAI,CAAC,iBAAiB;AACpB,UAAM,IAAI;AAAA,MACR,gBAAgB,aAAa,eAAe,OAAO,iCACtC,OAAO;AAAA,MACpB,EAAE,SAAS,cAAc,QAAQ;AAAA,IACnC;AAAA,EACF;AAEA,QAAM,UAAU,mCAAmC,gBAAgB,UAAU;AAC7E,MAAI,KAAK,wBAAwB,MAAM,OAAO;AAE9C,SAAO,kBAAkB,SAAS,QAAQ;AAAA,IACxC;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAEA,SAAS,qBACP,YACmD;AACnD,SACE,eAAe,UACf,OAAO,OAAO,UAAU,EAAE,KAAK,CAAC,cAAc,cAAc,MAAS;AAEzE;","names":["spaceId"]}
package/dist/index.d.ts CHANGED
@@ -1,21 +1,12 @@
1
1
  import { ContentfulViewDelivery } from '@contentful/experience-delivery';
2
2
  export { ContentfulViewDelivery, ContentfulViewDeliveryClient } from '@contentful/experience-delivery';
3
3
  export { DestinationPreviewNotSupportedError, ExperienceFetchError } from './errors.js';
4
- export { ANONYMOUS_ID_COOKIE, PROFILE_CACHE_KEY } from './constants.js';
5
- export { CreateClientOptions, RuntimeDeliveryClientOptions, createClient } from './create-delivery-client.js';
6
- export { RuntimeOptimizationConfig } from './create-optimization-client.js';
7
- export { ClickBuilderArgs, DEFAULT_PAGE_PROPERTIES, default as EventBuilder, EventBuilderConfig, FlagViewBuilderArgs, HoverBuilderArgs, IdentifyBuilderArgs, InteractionBuilderArgsBase, PageViewBuilderArgs, TrackBuilderArgs, UniversalEventBuilderArgs, ViewBuilderArgs } from './event-builder.js';
4
+ export { CreateClientOptions, createClient } from './create-delivery-client.js';
8
5
  export { ByDestinationNodeIdExperienceOptions, ByDestinationPathExperienceOptions, ByIdExperienceOptions, DestinationRedirectResult, ExperienceOptions, ExperienceRequestExtensions, PersonalizationOptions, ResolveOptions, fetchExperience } from './fetch-experience.js';
9
6
  export { DestinationSitemapResult, FetchDestinationSitemapOptions, FetchDestinationSitemapPaginationOptions, SitemapPathItem, fetchDestinationSitemap } from './fetch-destination-sitemap.js';
10
- export { ContentfulExperiences, ContentfulExperiencesConfig, ExperienceRuntime, RuntimeEventBuilderConfig, RuntimeFetchByDestinationNodeOptions, RuntimeFetchByDestinationPathOptions, RuntimeFetchExperienceOptions, RuntimeResolveOptions } from './contentful-experiences.js';
11
- export { AnalyticsEventMethod, EventProfileRequiredError, PersonalizationEventMethod, RuntimeEventBindings, RuntimeEventMethods } from './runtime-event-methods.js';
12
- export { RUNTIME_EVENT_HANDOFF_VERSION, RuntimeEventHandoff, RuntimeEventHandoffEvent, RuntimeEventHandoffReceipt, RuntimeServerEventDelivery, assertRuntimeEventHandoffSize, parseRuntimeEventHandoff } from './runtime-event-handoff.js';
13
7
  export { ExperienceResponse, readSourceMap, toExperiencePayload, toExperiencePayloadFromDestination } from './to-experience-payload.js';
14
8
  export { DELIVERY_HOST, PREVIEW_HOST, PREVIEW_WEBSOCKET_HOST } from './hosts.js';
15
9
  export { ClientOptions } from './client-resolution.js';
16
- export { OptimizationData as EventOptimizationData, PartialProfile as EventProfile, PartialProfile as EventProfileSchema } from '@contentful/optimization-api-client/api-schemas';
17
- import '@contentful/optimization-api-client';
18
- import 'zod/mini';
19
10
  import '@contentful/experiences-sdk-core';
20
11
 
21
12
  declare const NotFoundError: typeof ContentfulViewDelivery.NotFoundError;
package/dist/index.js CHANGED
@@ -5,19 +5,9 @@ import {
5
5
  } from "@contentful/experience-delivery";
6
6
  const NotFoundError = ContentfulViewDelivery.NotFoundError;
7
7
  import { ExperienceFetchError, DestinationPreviewNotSupportedError } from "./errors.js";
8
- import { ANONYMOUS_ID_COOKIE, PROFILE_CACHE_KEY } from "./constants.js";
9
8
  import { createClient } from "./create-delivery-client.js";
10
- import { default as default2 } from "./event-builder.js";
11
- export * from "./event-builder.js";
12
9
  import { fetchExperience } from "./fetch-experience.js";
13
10
  import { fetchDestinationSitemap } from "./fetch-destination-sitemap.js";
14
- import { ContentfulExperiences } from "./contentful-experiences.js";
15
- import { EventProfileRequiredError, EventProfileSchema } from "./runtime-event-methods.js";
16
- import {
17
- assertRuntimeEventHandoffSize,
18
- parseRuntimeEventHandoff,
19
- RUNTIME_EVENT_HANDOFF_VERSION
20
- } from "./runtime-event-handoff.js";
21
11
  import {
22
12
  readSourceMap,
23
13
  toExperiencePayload,
@@ -25,26 +15,17 @@ import {
25
15
  } from "./to-experience-payload.js";
26
16
  import { DELIVERY_HOST, PREVIEW_HOST, PREVIEW_WEBSOCKET_HOST } from "./hosts.js";
27
17
  export {
28
- ANONYMOUS_ID_COOKIE,
29
- ContentfulExperiences,
30
18
  ContentfulViewDelivery2 as ContentfulViewDelivery,
31
19
  ContentfulViewDeliveryClient,
32
20
  DELIVERY_HOST,
33
21
  DestinationPreviewNotSupportedError,
34
- default2 as EventBuilder,
35
- EventProfileRequiredError,
36
- EventProfileSchema,
37
22
  ExperienceFetchError,
38
23
  NotFoundError,
39
24
  PREVIEW_HOST,
40
25
  PREVIEW_WEBSOCKET_HOST,
41
- PROFILE_CACHE_KEY,
42
- RUNTIME_EVENT_HANDOFF_VERSION,
43
- assertRuntimeEventHandoffSize,
44
26
  createClient,
45
27
  fetchDestinationSitemap,
46
28
  fetchExperience,
47
- parseRuntimeEventHandoff,
48
29
  readSourceMap,
49
30
  toExperiencePayload,
50
31
  toExperiencePayloadFromDestination
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { ContentfulViewDelivery } from '@contentful/experience-delivery';\n\nexport {\n ContentfulViewDelivery,\n ContentfulViewDeliveryClient,\n} from '@contentful/experience-delivery';\nexport const NotFoundError = ContentfulViewDelivery.NotFoundError;\n// eslint-disable-next-line no-redeclare -- value + type share a name across separate TS namespaces, not a real redeclaration\nexport type NotFoundError = InstanceType<typeof ContentfulViewDelivery.NotFoundError>;\nexport { ExperienceFetchError, DestinationPreviewNotSupportedError } from './errors.js';\nexport { ANONYMOUS_ID_COOKIE, PROFILE_CACHE_KEY } from './constants.js';\nexport { createClient } from './create-delivery-client.js';\nexport type {\n CreateClientOptions,\n RuntimeDeliveryClientOptions,\n} from './create-delivery-client.js';\nexport type { RuntimeOptimizationConfig } from './create-optimization-client.js';\nexport { default as EventBuilder } from './event-builder.js';\nexport * from './event-builder.js';\nexport { fetchExperience } from './fetch-experience.js';\nexport { fetchDestinationSitemap } from './fetch-destination-sitemap.js';\nexport type {\n FetchDestinationSitemapOptions,\n FetchDestinationSitemapPaginationOptions,\n SitemapPathItem,\n DestinationSitemapResult,\n} from './fetch-destination-sitemap.js';\nexport { ContentfulExperiences } from './contentful-experiences.js';\nexport type {\n ContentfulExperiencesConfig,\n ExperienceRuntime,\n RuntimeFetchExperienceOptions,\n RuntimeFetchByDestinationNodeOptions,\n RuntimeFetchByDestinationPathOptions,\n RuntimeEventBuilderConfig,\n RuntimeResolveOptions,\n} from './contentful-experiences.js';\nexport { EventProfileRequiredError, EventProfileSchema } from './runtime-event-methods.js';\nexport type {\n EventOptimizationData,\n EventProfile,\n AnalyticsEventMethod,\n PersonalizationEventMethod,\n RuntimeEventBindings,\n RuntimeEventMethods,\n} from './runtime-event-methods.js';\nexport {\n assertRuntimeEventHandoffSize,\n parseRuntimeEventHandoff,\n RUNTIME_EVENT_HANDOFF_VERSION,\n} from './runtime-event-handoff.js';\nexport type {\n RuntimeEventHandoff,\n RuntimeEventHandoffEvent,\n RuntimeEventHandoffReceipt,\n RuntimeServerEventDelivery,\n} from './runtime-event-handoff.js';\nexport {\n readSourceMap,\n toExperiencePayload,\n toExperiencePayloadFromDestination,\n} from './to-experience-payload.js';\nexport type { ExperienceResponse } from './to-experience-payload.js';\nexport type {\n ExperienceOptions,\n ExperienceRequestExtensions,\n PersonalizationOptions,\n ByIdExperienceOptions,\n ByDestinationNodeIdExperienceOptions,\n ByDestinationPathExperienceOptions,\n ClientOptions,\n ResolveOptions,\n DestinationRedirectResult,\n} from './fetch-experience.js';\nexport { DELIVERY_HOST, PREVIEW_HOST, PREVIEW_WEBSOCKET_HOST } from './hosts.js';\n"],"mappings":"AAAA,SAAS,8BAA8B;AAEvC;AAAA,EACE,0BAAAA;AAAA,EACA;AAAA,OACK;AACA,MAAM,gBAAgB,uBAAuB;AAGpD,SAAS,sBAAsB,2CAA2C;AAC1E,SAAS,qBAAqB,yBAAyB;AACvD,SAAS,oBAAoB;AAM7B,SAAoB,WAAXC,gBAA+B;AACxC,cAAc;AACd,SAAS,uBAAuB;AAChC,SAAS,+BAA+B;AAOxC,SAAS,6BAA6B;AAUtC,SAAS,2BAA2B,0BAA0B;AAS9D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAOP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAaP,SAAS,eAAe,cAAc,8BAA8B;","names":["ContentfulViewDelivery","default"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { ContentfulViewDelivery } from '@contentful/experience-delivery';\n\nexport {\n ContentfulViewDelivery,\n ContentfulViewDeliveryClient,\n} from '@contentful/experience-delivery';\nexport const NotFoundError = ContentfulViewDelivery.NotFoundError;\n// eslint-disable-next-line no-redeclare -- value + type share a name across separate TS namespaces, not a real redeclaration\nexport type NotFoundError = InstanceType<typeof ContentfulViewDelivery.NotFoundError>;\nexport { ExperienceFetchError, DestinationPreviewNotSupportedError } from './errors.js';\nexport { createClient } from './create-delivery-client.js';\nexport type { CreateClientOptions } from './create-delivery-client.js';\nexport { fetchExperience } from './fetch-experience.js';\nexport { fetchDestinationSitemap } from './fetch-destination-sitemap.js';\nexport type {\n FetchDestinationSitemapOptions,\n FetchDestinationSitemapPaginationOptions,\n SitemapPathItem,\n DestinationSitemapResult,\n} from './fetch-destination-sitemap.js';\nexport {\n readSourceMap,\n toExperiencePayload,\n toExperiencePayloadFromDestination,\n} from './to-experience-payload.js';\nexport type { ExperienceResponse } from './to-experience-payload.js';\nexport type {\n ExperienceOptions,\n ExperienceRequestExtensions,\n PersonalizationOptions,\n ByIdExperienceOptions,\n ByDestinationNodeIdExperienceOptions,\n ByDestinationPathExperienceOptions,\n ClientOptions,\n ResolveOptions,\n DestinationRedirectResult,\n} from './fetch-experience.js';\nexport { DELIVERY_HOST, PREVIEW_HOST, PREVIEW_WEBSOCKET_HOST } from './hosts.js';\n"],"mappings":"AAAA,SAAS,8BAA8B;AAEvC;AAAA,EACE,0BAAAA;AAAA,EACA;AAAA,OACK;AACA,MAAM,gBAAgB,uBAAuB;AAGpD,SAAS,sBAAsB,2CAA2C;AAC1E,SAAS,oBAAoB;AAE7B,SAAS,uBAAuB;AAChC,SAAS,+BAA+B;AAOxC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAaP,SAAS,eAAe,cAAc,8BAA8B;","names":["ContentfulViewDelivery"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/experiences-client",
3
- "version": "0.9.1",
3
+ "version": "0.9.3",
4
4
  "description": "Delivery client + fetchExperience for Contentful Experiences",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -31,9 +31,6 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@contentful/experience-delivery": "1.0.0-dev.9",
34
- "@contentful/experiences-sdk-core": "0.12.0",
35
- "@contentful/optimization-api-client": "^2.0.1",
36
- "es-toolkit": "^1.46.0",
37
- "zod": "^4.3.6"
34
+ "@contentful/experiences-sdk-core": "0.12.2"
38
35
  }
39
36
  }
@@ -1,11 +0,0 @@
1
- /**
2
- * Cookie name used to carry an anonymous/profile id between browser and server
3
- * runtimes. The value matches the Contentful Optimization SDK.
4
- *
5
- * @public
6
- */
7
- declare const ANONYMOUS_ID_COOKIE = "ctfl-opt-aid";
8
- /** @internal LocalStorage key for the persisted profile. */
9
- declare const PROFILE_CACHE_KEY = "__ctfl_opt_profile__";
10
-
11
- export { ANONYMOUS_ID_COOKIE, PROFILE_CACHE_KEY };
package/dist/constants.js DELETED
@@ -1,7 +0,0 @@
1
- const ANONYMOUS_ID_COOKIE = "ctfl-opt-aid";
2
- const PROFILE_CACHE_KEY = "__ctfl_opt_profile__";
3
- export {
4
- ANONYMOUS_ID_COOKIE,
5
- PROFILE_CACHE_KEY
6
- };
7
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/constants.ts"],"sourcesContent":["/**\n * Cookie name used to carry an anonymous/profile id between browser and server\n * runtimes. The value matches the Contentful Optimization SDK.\n *\n * @public\n */\nexport const ANONYMOUS_ID_COOKIE = 'ctfl-opt-aid';\n\n/** @internal LocalStorage key for the persisted profile. */\nexport const PROFILE_CACHE_KEY = '__ctfl_opt_profile__';\n"],"mappings":"AAMO,MAAM,sBAAsB;AAG5B,MAAM,oBAAoB;","names":[]}
@@ -1,76 +0,0 @@
1
- import { ExperiencePayload, PortableRenderPlan, ResolverConfig } from '@contentful/experiences-sdk-core';
2
- import EventBuilder, { EventBuilderConfig } from './event-builder.js';
3
- import { RuntimeDeliveryClientOptions } from './create-delivery-client.js';
4
- import { PersonalizationOptions, ExperienceRequestExtensions, DestinationRedirectResult } from './fetch-experience.js';
5
- import { RuntimeOptimizationConfig } from './create-optimization-client.js';
6
- import { RuntimeOptimizationApiClient, RuntimeEventBindings, RuntimeEventDispatch, RuntimeEventMethods } from './runtime-event-methods.js';
7
- import '@contentful/optimization-api-client/api-schemas';
8
- import 'zod/mini';
9
- import '@contentful/experience-delivery';
10
- import './client-resolution.js';
11
- import '@contentful/optimization-api-client';
12
-
13
- type RuntimeResolveOptions = {
14
- metadata?: Record<string, unknown>;
15
- debug?: boolean;
16
- };
17
- type RuntimeEventBuilderConfig = Omit<EventBuilderConfig, 'channel' | 'library'> & {
18
- channel: EventBuilderConfig['channel'];
19
- library?: Partial<EventBuilderConfig['library']>;
20
- };
21
- type RuntimeFetchExperienceOptions = {
22
- experienceId: string;
23
- locale?: string;
24
- personalization?: PersonalizationOptions;
25
- extensions?: ExperienceRequestExtensions;
26
- preview?: boolean;
27
- };
28
- type RuntimeFetchByDestinationNodeOptions = {
29
- destinationId: string;
30
- nodeId: string;
31
- };
32
- type RuntimeFetchByDestinationPathOptions = {
33
- destinationId: string;
34
- path: string;
35
- };
36
- /** Structural contract implemented by the Client runtime. */
37
- interface ExperienceRuntime {
38
- readonly spaceId: string;
39
- readonly environmentId: string;
40
- readonly locale: string | undefined;
41
- readonly eventBuilder: EventBuilder;
42
- resolveExperience(payload: ExperiencePayload, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan>;
43
- fetchExperience(options: RuntimeFetchExperienceOptions, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan>;
44
- fetchByDestinationNode(options: RuntimeFetchByDestinationNodeOptions, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan | DestinationRedirectResult>;
45
- fetchByDestinationPath(options: RuntimeFetchByDestinationPathOptions, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan | DestinationRedirectResult>;
46
- }
47
- type ContentfulExperiencesConfig = {
48
- spaceId: string;
49
- environmentId: string;
50
- locale?: string;
51
- resolverConfig: ResolverConfig;
52
- /** Configuration for the runtime-owned Content Delivery API client. */
53
- delivery: RuntimeDeliveryClientOptions;
54
- /** Optional configuration for the runtime-owned Content Preview API client. */
55
- preview?: RuntimeDeliveryClientOptions;
56
- /** Overrides for the runtime-owned Personalization and Analytics event transport. */
57
- optimization?: RuntimeOptimizationConfig;
58
- resolveDefaults?: Pick<RuntimeResolveOptions, 'metadata' | 'debug'>;
59
- eventBuilder: RuntimeEventBuilderConfig;
60
- };
61
- declare class ContentfulExperiences implements ExperienceRuntime {
62
- #private;
63
- readonly spaceId: string;
64
- readonly environmentId: string;
65
- readonly eventBuilder: EventBuilder;
66
- protected readonly optimizationApi: RuntimeOptimizationApiClient;
67
- constructor(config: ContentfulExperiencesConfig);
68
- get locale(): string | undefined;
69
- protected createEventMethods(bindings: RuntimeEventBindings, dispatch?: RuntimeEventDispatch): RuntimeEventMethods;
70
- resolveExperience(payload: ExperiencePayload, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan>;
71
- fetchExperience(options: RuntimeFetchExperienceOptions, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan>;
72
- fetchByDestinationNode(options: RuntimeFetchByDestinationNodeOptions, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan | DestinationRedirectResult>;
73
- fetchByDestinationPath(options: RuntimeFetchByDestinationPathOptions, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan | DestinationRedirectResult>;
74
- }
75
-
76
- export { ContentfulExperiences, type ContentfulExperiencesConfig, type ExperienceRuntime, type RuntimeEventBuilderConfig, type RuntimeFetchByDestinationNodeOptions, type RuntimeFetchByDestinationPathOptions, type RuntimeFetchExperienceOptions, type RuntimeResolveOptions };
@@ -1,104 +0,0 @@
1
- import { resolveExperience as resolveCoreExperience } from "@contentful/experiences-sdk-core";
2
- import EventBuilder from "./event-builder.js";
3
- import {
4
- createRuntimeDeliveryClient
5
- } from "./create-delivery-client.js";
6
- import {
7
- fetchExperience
8
- } from "./fetch-experience.js";
9
- import {
10
- createRuntimeOptimizationClient
11
- } from "./create-optimization-client.js";
12
- import { PREVIEW_HOST } from "./hosts.js";
13
- import { DEFAULT_EVENT_CONTEXT_LIBRARY } from "./sdk-info.js";
14
- import {
15
- createRuntimeEventMethods
16
- } from "./runtime-event-methods.js";
17
- class ContentfulExperiences {
18
- spaceId;
19
- environmentId;
20
- eventBuilder;
21
- #locale;
22
- #resolverConfig;
23
- #deliveryClient;
24
- #previewClient;
25
- optimizationApi;
26
- #resolveDefaults;
27
- constructor(config) {
28
- this.spaceId = config.spaceId;
29
- this.environmentId = config.environmentId;
30
- this.#locale = config.locale;
31
- this.#resolverConfig = config.resolverConfig;
32
- this.#deliveryClient = createRuntimeDeliveryClient(config.delivery);
33
- this.#previewClient = config.preview === void 0 ? void 0 : createRuntimeDeliveryClient(config.preview, PREVIEW_HOST);
34
- this.optimizationApi = createRuntimeOptimizationClient({
35
- spaceId: config.spaceId,
36
- environmentId: config.environmentId,
37
- ...config.optimization
38
- });
39
- this.#resolveDefaults = config.resolveDefaults ?? {};
40
- this.eventBuilder = new EventBuilder({
41
- ...config.eventBuilder,
42
- library: { ...DEFAULT_EVENT_CONTEXT_LIBRARY, ...config.eventBuilder.library },
43
- getLocale: config.eventBuilder.getLocale ?? (() => this.locale)
44
- });
45
- }
46
- get locale() {
47
- return this.#locale;
48
- }
49
- createEventMethods(bindings, dispatch) {
50
- return createRuntimeEventMethods(this.optimizationApi, this.eventBuilder, bindings, dispatch);
51
- }
52
- resolveExperience(payload, resolveOptions) {
53
- return resolveCoreExperience(
54
- payload,
55
- this.#resolverConfig,
56
- this.#mergeResolveOptions(resolveOptions)
57
- );
58
- }
59
- fetchExperience(options, resolveOptions) {
60
- if (options.preview === true && this.#previewClient === void 0) {
61
- throw new Error(
62
- "fetchExperience() called with preview: true but this runtime has no preview client"
63
- );
64
- }
65
- return fetchExperience(
66
- {
67
- spaceId: this.spaceId,
68
- environmentId: this.environmentId,
69
- experienceId: options.experienceId,
70
- locale: options.locale ?? this.locale,
71
- personalization: options.personalization,
72
- extensions: options.extensions
73
- },
74
- {
75
- client: options.preview ? this.#previewClient : this.#deliveryClient
76
- },
77
- { config: this.#resolverConfig, ...this.#mergeResolveOptions(resolveOptions) }
78
- );
79
- }
80
- fetchByDestinationNode(options, resolveOptions) {
81
- return fetchExperience(
82
- { spaceId: this.spaceId, destinationId: options.destinationId, nodeId: options.nodeId },
83
- { client: this.#deliveryClient },
84
- { config: this.#resolverConfig, ...this.#mergeResolveOptions(resolveOptions) }
85
- );
86
- }
87
- fetchByDestinationPath(options, resolveOptions) {
88
- return fetchExperience(
89
- { spaceId: this.spaceId, destinationId: options.destinationId, path: options.path },
90
- { client: this.#deliveryClient },
91
- { config: this.#resolverConfig, ...this.#mergeResolveOptions(resolveOptions) }
92
- );
93
- }
94
- #mergeResolveOptions(options) {
95
- return {
96
- metadata: { ...this.#resolveDefaults.metadata, ...options?.metadata },
97
- debug: options?.debug ?? this.#resolveDefaults.debug
98
- };
99
- }
100
- }
101
- export {
102
- ContentfulExperiences
103
- };
104
- //# sourceMappingURL=contentful-experiences.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/contentful-experiences.ts"],"sourcesContent":["import type { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';\nimport { resolveExperience as resolveCoreExperience } from '@contentful/experiences-sdk-core';\nimport type {\n ExperiencePayload,\n PortableRenderPlan,\n ResolverConfig,\n} from '@contentful/experiences-sdk-core';\nimport EventBuilder from './event-builder.js';\nimport type { EventBuilderConfig } from './event-builder.js';\nimport {\n createRuntimeDeliveryClient,\n type RuntimeDeliveryClientOptions,\n} from './create-delivery-client.js';\nimport {\n fetchExperience,\n type DestinationRedirectResult,\n type ExperienceRequestExtensions,\n type PersonalizationOptions,\n} from './fetch-experience.js';\nimport {\n createRuntimeOptimizationClient,\n type RuntimeOptimizationConfig,\n} from './create-optimization-client.js';\nimport { PREVIEW_HOST } from './hosts.js';\nimport { DEFAULT_EVENT_CONTEXT_LIBRARY } from './sdk-info.js';\nimport {\n createRuntimeEventMethods,\n type RuntimeEventBindings,\n type RuntimeEventDispatch,\n type RuntimeEventMethods,\n type RuntimeOptimizationApiClient,\n} from './runtime-event-methods.js';\n\nexport type RuntimeResolveOptions = {\n metadata?: Record<string, unknown>;\n debug?: boolean;\n};\n\nexport type RuntimeEventBuilderConfig = Omit<EventBuilderConfig, 'channel' | 'library'> & {\n channel: EventBuilderConfig['channel'];\n library?: Partial<EventBuilderConfig['library']>;\n};\n\nexport type RuntimeFetchExperienceOptions = {\n experienceId: string;\n locale?: string;\n personalization?: PersonalizationOptions;\n extensions?: ExperienceRequestExtensions;\n preview?: boolean;\n};\n\nexport type RuntimeFetchByDestinationNodeOptions = {\n destinationId: string;\n nodeId: string;\n};\n\nexport type RuntimeFetchByDestinationPathOptions = {\n destinationId: string;\n path: string;\n};\n\n/** Structural contract implemented by the Client runtime. */\nexport interface ExperienceRuntime {\n readonly spaceId: string;\n readonly environmentId: string;\n readonly locale: string | undefined;\n readonly eventBuilder: EventBuilder;\n resolveExperience(\n payload: ExperiencePayload,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan>;\n fetchExperience(\n options: RuntimeFetchExperienceOptions,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan>;\n fetchByDestinationNode(\n options: RuntimeFetchByDestinationNodeOptions,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan | DestinationRedirectResult>;\n fetchByDestinationPath(\n options: RuntimeFetchByDestinationPathOptions,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan | DestinationRedirectResult>;\n}\n\nexport type ContentfulExperiencesConfig = {\n spaceId: string;\n environmentId: string;\n locale?: string;\n resolverConfig: ResolverConfig;\n /** Configuration for the runtime-owned Content Delivery API client. */\n delivery: RuntimeDeliveryClientOptions;\n /** Optional configuration for the runtime-owned Content Preview API client. */\n preview?: RuntimeDeliveryClientOptions;\n /** Overrides for the runtime-owned Personalization and Analytics event transport. */\n optimization?: RuntimeOptimizationConfig;\n resolveDefaults?: Pick<RuntimeResolveOptions, 'metadata' | 'debug'>;\n eventBuilder: RuntimeEventBuilderConfig;\n};\n\nexport class ContentfulExperiences implements ExperienceRuntime {\n readonly spaceId: string;\n readonly environmentId: string;\n readonly eventBuilder: EventBuilder;\n\n readonly #locale: string | undefined;\n readonly #resolverConfig: ResolverConfig;\n readonly #deliveryClient: ContentfulViewDeliveryClient;\n readonly #previewClient: ContentfulViewDeliveryClient | undefined;\n protected readonly optimizationApi: RuntimeOptimizationApiClient;\n readonly #resolveDefaults: Pick<RuntimeResolveOptions, 'metadata' | 'debug'>;\n\n constructor(config: ContentfulExperiencesConfig) {\n this.spaceId = config.spaceId;\n this.environmentId = config.environmentId;\n this.#locale = config.locale;\n this.#resolverConfig = config.resolverConfig;\n this.#deliveryClient = createRuntimeDeliveryClient(config.delivery);\n this.#previewClient =\n config.preview === undefined\n ? undefined\n : createRuntimeDeliveryClient(config.preview, PREVIEW_HOST);\n this.optimizationApi = createRuntimeOptimizationClient({\n spaceId: config.spaceId,\n environmentId: config.environmentId,\n ...config.optimization,\n });\n this.#resolveDefaults = config.resolveDefaults ?? {};\n\n this.eventBuilder = new EventBuilder({\n ...config.eventBuilder,\n library: { ...DEFAULT_EVENT_CONTEXT_LIBRARY, ...config.eventBuilder.library },\n getLocale: config.eventBuilder.getLocale ?? (() => this.locale),\n });\n }\n\n get locale(): string | undefined {\n return this.#locale;\n }\n\n protected createEventMethods(\n bindings: RuntimeEventBindings,\n dispatch?: RuntimeEventDispatch\n ): RuntimeEventMethods {\n return createRuntimeEventMethods(this.optimizationApi, this.eventBuilder, bindings, dispatch);\n }\n\n resolveExperience(\n payload: ExperiencePayload,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan> {\n return resolveCoreExperience(\n payload,\n this.#resolverConfig,\n this.#mergeResolveOptions(resolveOptions)\n );\n }\n\n fetchExperience(\n options: RuntimeFetchExperienceOptions,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan> {\n if (options.preview === true && this.#previewClient === undefined) {\n throw new Error(\n 'fetchExperience() called with preview: true but this runtime has no preview client'\n );\n }\n return fetchExperience(\n {\n spaceId: this.spaceId,\n environmentId: this.environmentId,\n experienceId: options.experienceId,\n locale: options.locale ?? this.locale,\n personalization: options.personalization,\n extensions: options.extensions,\n },\n {\n client: options.preview\n ? (this.#previewClient as ContentfulViewDeliveryClient)\n : this.#deliveryClient,\n },\n { config: this.#resolverConfig, ...this.#mergeResolveOptions(resolveOptions) }\n );\n }\n\n fetchByDestinationNode(\n options: RuntimeFetchByDestinationNodeOptions,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan | DestinationRedirectResult> {\n return fetchExperience(\n { spaceId: this.spaceId, destinationId: options.destinationId, nodeId: options.nodeId },\n { client: this.#deliveryClient },\n { config: this.#resolverConfig, ...this.#mergeResolveOptions(resolveOptions) }\n );\n }\n\n fetchByDestinationPath(\n options: RuntimeFetchByDestinationPathOptions,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan | DestinationRedirectResult> {\n return fetchExperience(\n { spaceId: this.spaceId, destinationId: options.destinationId, path: options.path },\n { client: this.#deliveryClient },\n { config: this.#resolverConfig, ...this.#mergeResolveOptions(resolveOptions) }\n );\n }\n\n #mergeResolveOptions(options: RuntimeResolveOptions | undefined): RuntimeResolveOptions {\n return {\n metadata: { ...this.#resolveDefaults.metadata, ...options?.metadata },\n debug: options?.debug ?? this.#resolveDefaults.debug,\n };\n }\n}\n"],"mappings":"AACA,SAAS,qBAAqB,6BAA6B;AAM3D,OAAO,kBAAkB;AAEzB;AAAA,EACE;AAAA,OAEK;AACP;AAAA,EACE;AAAA,OAIK;AACP;AAAA,EACE;AAAA,OAEK;AACP,SAAS,oBAAoB;AAC7B,SAAS,qCAAqC;AAC9C;AAAA,EACE;AAAA,OAKK;AAqEA,MAAM,sBAAmD;AAAA,EACrD;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACU;AAAA,EACV;AAAA,EAET,YAAY,QAAqC;AAC/C,SAAK,UAAU,OAAO;AACtB,SAAK,gBAAgB,OAAO;AAC5B,SAAK,UAAU,OAAO;AACtB,SA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