@contentful/experiences-client 0.6.0 → 0.7.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/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## 0.7.1 (2026-10-01)
2
+
3
+ ### 🚀 Features
4
+
5
+ - persist web personalization profile ID ([#213](https://github.com/contentful/experiences/pull/213))
6
+
7
+ ### 🧱 Updated Dependencies
8
+
9
+ - Updated core to 0.10.1
10
+
11
+ ## 0.7.0 (2026-09-30)
12
+
13
+ ### 🚀 Features
14
+
15
+ - ⚠️ add event-triggering methods to runtimes ([#209](https://github.com/contentful/experiences/pull/209))
16
+
17
+ ### ⚠️ Breaking Changes
18
+
19
+ - add event-triggering methods to runtimes ([#209](https://github.com/contentful/experiences/pull/209))
20
+
1
21
  ## 0.6.0 (2026-09-30)
2
22
 
3
23
  ### 🚀 Features
package/README.md CHANGED
@@ -16,35 +16,81 @@ remain supported for adapter and application integration.
16
16
 
17
17
  `ContentfulExperiences` is an internal shared runtime contract for the public
18
18
  Node/Web SDKs. Construct it with a space, environment, resolver configuration,
19
- a delivery client source, and an `eventBuilder` config with an explicit
20
- `channel`; optionally provide a preview client source. It retains those clients,
21
- merges configured resolve defaults with per-call options, and exposes
22
- `resolveExperience` and by-id/destination `fetchExperience` methods. Calling
23
- `fetchExperience` with `preview: true` requires the optional preview client.
24
-
25
- The Client transport configuration is trusted: its bearer token is sent to the
26
- selected endpoint. `environmentId` is the Contentful environment identifier
27
- passed to by-ID Experience requests; it is not the generated delivery client's
28
- optional `environment` endpoint setting. For a Client-created transport,
29
- Experiences' `host` is passed through as the generated client's `baseUrl`.
30
- Callers that construct a raw `ContentfulViewDeliveryClient` may configure
31
- `baseUrl` directly. This is how both public leaves can use trusted custom
32
- endpoints (for example, a proxy, staging service, or regional endpoint).
33
- Endpoint precedence is explicit `host`/raw-client `baseUrl`, then the generated
34
- client's `environment`, then the delivery or preview default.
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.
35
39
 
36
40
  The optional preview client enables direct CPA fetches by Experience ID through
37
41
  the same shared runtime. It is separate from `@contentful/experiences-live-preview`,
38
42
  which owns Preview Session HTTP loading, WebSocket subscription, and update state.
39
43
  Destination operations continue to use the delivery client.
40
44
 
41
- The runtime constructs and owns one `EventBuilder`. The caller supplies its
42
- channel, while the runtime retains this SDK's default library identity and the
43
- runtime locale unless overridden. This is the owner of event construction for
44
- the lower layer, rather than Core.
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).
45
91
 
46
92
  This package's direct dependencies are the generated delivery client,
47
- `@contentful/optimization-api-client` (event schemas and logger), `es-toolkit`
93
+ `@contentful/optimization-api-client` (event schemas, logger, and transport), `es-toolkit`
48
94
  (event-property merging), and `zod` (event argument schemas), in addition to
49
95
  Core. None of those dependencies are introduced into Core.
50
96
 
@@ -201,7 +247,7 @@ const client = new ContentfulViewDeliveryClient({
201
247
  - Do not import `@contentful/experience-delivery` from anywhere except this package.
202
248
  - Re-export only what framework adapters need to surface to their users.
203
249
  - Keep `fetchExperience` thin — fetch + cast + resolve. Business logic belongs in `packages/core`.
204
- - Name mappings between SDK options and delivery-client options live in `create-client.ts` — one place to change.
250
+ - Name mappings between SDK options and delivery-client options live in `create-delivery-client.ts` — one place to change.
205
251
 
206
252
  ## License
207
253
 
@@ -0,0 +1,11 @@
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 };
@@ -0,0 +1,7 @@
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
@@ -0,0 +1 @@
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,14 +1,14 @@
1
- import { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';
2
1
  import { ExperiencePayload, PortableRenderPlan, ResolverConfig } from '@contentful/experiences-sdk-core';
3
2
  import EventBuilder, { EventBuilderConfig } from './event-builder.js';
3
+ import { RuntimeDeliveryClientOptions } from './create-delivery-client.js';
4
4
  import { PersonalizationOptions, ExperienceRequestExtensions, DestinationRedirectResult } from './fetch-experience.js';
5
- import { CreateClientOptions } from './create-client.js';
5
+ import { RuntimeOptimizationConfig } from './create-optimization-client.js';
6
+ import { RuntimeOptimizationApiClient, RuntimeEventBindings, RuntimeEventDispatch, RuntimeEventMethods } from './runtime-event-methods.js';
6
7
  import '@contentful/optimization-api-client/api-schemas';
7
8
  import 'zod/mini';
9
+ import '@contentful/experience-delivery';
10
+ import '@contentful/optimization-api-client';
8
11
 
9
- type RuntimeClientSource = CreateClientOptions | {
10
- client: ContentfulViewDeliveryClient;
11
- };
12
12
  type RuntimeResolveOptions = {
13
13
  metadata?: Record<string, unknown>;
14
14
  debug?: boolean;
@@ -49,8 +49,12 @@ type ContentfulExperiencesConfig = {
49
49
  environmentId: string;
50
50
  locale?: string;
51
51
  resolverConfig: ResolverConfig;
52
- delivery: RuntimeClientSource;
53
- preview?: RuntimeClientSource;
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;
54
58
  resolveDefaults?: Pick<RuntimeResolveOptions, 'metadata' | 'debug'>;
55
59
  eventBuilder: RuntimeEventBuilderConfig;
56
60
  };
@@ -59,12 +63,14 @@ declare class ContentfulExperiences implements ExperienceRuntime {
59
63
  readonly spaceId: string;
60
64
  readonly environmentId: string;
61
65
  readonly eventBuilder: EventBuilder;
66
+ protected readonly optimizationApi: RuntimeOptimizationApiClient;
62
67
  constructor(config: ContentfulExperiencesConfig);
63
68
  get locale(): string | undefined;
69
+ protected createEventMethods(bindings: RuntimeEventBindings, dispatch?: RuntimeEventDispatch): RuntimeEventMethods;
64
70
  resolveExperience(payload: ExperiencePayload, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan>;
65
71
  fetchExperience(options: RuntimeFetchExperienceOptions, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan>;
66
72
  fetchByDestinationNode(options: RuntimeFetchByDestinationNodeOptions, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan | DestinationRedirectResult>;
67
73
  fetchByDestinationPath(options: RuntimeFetchByDestinationPathOptions, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan | DestinationRedirectResult>;
68
74
  }
69
75
 
70
- export { ContentfulExperiences, type ContentfulExperiencesConfig, type ExperienceRuntime, type RuntimeClientSource, type RuntimeEventBuilderConfig, type RuntimeFetchByDestinationNodeOptions, type RuntimeFetchByDestinationPathOptions, type RuntimeFetchExperienceOptions, type RuntimeResolveOptions };
76
+ export { ContentfulExperiences, type ContentfulExperiencesConfig, type ExperienceRuntime, type RuntimeEventBuilderConfig, type RuntimeFetchByDestinationNodeOptions, type RuntimeFetchByDestinationPathOptions, type RuntimeFetchExperienceOptions, type RuntimeResolveOptions };
@@ -1,11 +1,19 @@
1
1
  import { resolveExperience as resolveCoreExperience } from "@contentful/experiences-sdk-core";
2
2
  import EventBuilder from "./event-builder.js";
3
- import { createClient } from "./create-client.js";
3
+ import {
4
+ createRuntimeDeliveryClient
5
+ } from "./create-delivery-client.js";
4
6
  import {
5
7
  fetchExperience
6
8
  } from "./fetch-experience.js";
9
+ import {
10
+ createRuntimeOptimizationClient
11
+ } from "./create-optimization-client.js";
7
12
  import { PREVIEW_HOST } from "./hosts.js";
8
13
  import { DEFAULT_EVENT_CONTEXT_LIBRARY } from "./sdk-info.js";
14
+ import {
15
+ createRuntimeEventMethods
16
+ } from "./runtime-event-methods.js";
9
17
  class ContentfulExperiences {
10
18
  spaceId;
11
19
  environmentId;
@@ -14,14 +22,20 @@ class ContentfulExperiences {
14
22
  #resolverConfig;
15
23
  #deliveryClient;
16
24
  #previewClient;
25
+ optimizationApi;
17
26
  #resolveDefaults;
18
27
  constructor(config) {
19
28
  this.spaceId = config.spaceId;
20
29
  this.environmentId = config.environmentId;
21
30
  this.#locale = config.locale;
22
31
  this.#resolverConfig = config.resolverConfig;
23
- this.#deliveryClient = resolveClient(config.delivery);
24
- this.#previewClient = config.preview === void 0 ? void 0 : resolveClient(config.preview, PREVIEW_HOST);
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
+ });
25
39
  this.#resolveDefaults = config.resolveDefaults ?? {};
26
40
  this.eventBuilder = new EventBuilder({
27
41
  ...config.eventBuilder,
@@ -32,6 +46,9 @@ class ContentfulExperiences {
32
46
  get locale() {
33
47
  return this.#locale;
34
48
  }
49
+ createEventMethods(bindings, dispatch) {
50
+ return createRuntimeEventMethods(this.optimizationApi, this.eventBuilder, bindings, dispatch);
51
+ }
35
52
  resolveExperience(payload, resolveOptions) {
36
53
  return resolveCoreExperience(
37
54
  payload,
@@ -82,13 +99,6 @@ class ContentfulExperiences {
82
99
  };
83
100
  }
84
101
  }
85
- function resolveClient(source, defaultHost) {
86
- if ("client" in source) return source.client;
87
- return createClient({
88
- ...source,
89
- host: source.host ?? (source.environment === void 0 ? defaultHost : void 0)
90
- });
91
- }
92
102
  export {
93
103
  ContentfulExperiences
94
104
  };
@@ -1 +1 @@
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 { createClient } from './create-client.js';\nimport {\n fetchExperience,\n type DestinationRedirectResult,\n type ExperienceRequestExtensions,\n type PersonalizationOptions,\n} from './fetch-experience.js';\nimport type { CreateClientOptions } from './create-client.js';\nimport { PREVIEW_HOST } from './hosts.js';\nimport { DEFAULT_EVENT_CONTEXT_LIBRARY } from './sdk-info.js';\n\nexport type RuntimeClientSource = CreateClientOptions | { client: ContentfulViewDeliveryClient };\n\nexport type RuntimeResolveOptions = {\n metadata?: Record<string, unknown>;\n debug?: boolean;\n initialViewportId?: string;\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 delivery: RuntimeClientSource;\n preview?: RuntimeClientSource;\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 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 = resolveClient(config.delivery);\n this.#previewClient =\n config.preview === undefined ? undefined : resolveClient(config.preview, PREVIEW_HOST);\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 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 initialViewportId: options?.initialViewportId,\n };\n }\n}\n\nfunction resolveClient(\n source: RuntimeClientSource,\n defaultHost?: string\n): ContentfulViewDeliveryClient {\n if ('client' in source) return source.client;\n\n return createClient({\n ...source,\n host: source.host ?? (source.environment === undefined ? defaultHost : undefined),\n });\n}\n"],"mappings":"AACA,SAAS,qBAAqB,6BAA6B;AAM3D,OAAO,kBAAkB;AAEzB,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,OAIK;AAEP,SAAS,oBAAoB;AAC7B,SAAS,qCAAqC;AAoEvC,MAAM,sBAAmD;AAAA,EACrD;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,QAAqC;AAC/C,SAAK,UAAU,OAAO;AACtB,SAAK,gBAAgB,OAAO;AAC5B,SAAK,UAAU,OAAO;AACtB,SAAK,kBAAkB,OAAO;AAC9B,SAAK,kBAAkB,cAAc,OAAO,QAAQ;AACpD,SAAK,iBACH,OAAO,YAAY,SAAY,SAAY,cAAc,OAAO,SAAS,YAAY;AACvF,SAAK,mBAAmB,OAAO,mBAAmB,CAAC;AAEnD,SAAK,eAAe,IAAI,aAAa;AAAA,MACnC,GAAG,OAAO;AAAA,MACV,SAAS,EAAE,GAAG,+BAA+B,GAAG,OAAO,aAAa,QAAQ;AAAA,MAC5E,WAAW,OAAO,aAAa,cAAc,MAAM,KAAK;AAAA,IAC1D,CAAC;AAAA,EACH;AAAA,EAEA,IAAI,SAA6B;AAC/B,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,kBACE,SACA,gBAC6B;AAC7B,WAAO;AAAA,MACL;AAAA,MACA,KAAK;AAAA,MACL,KAAK,qBAAqB,cAAc;AAAA,IAC1C;AAAA,EACF;AAAA,EAEA,gBACE,SACA,gBAC6B;AAC7B,QAAI,QAAQ,YAAY,QAAQ,KAAK,mBAAmB,QAAW;AACjE,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,MACL;AAAA,QACE,SAAS,KAAK;AAAA,QACd,eAAe,KAAK;AAAA,QACpB,cAAc,QAAQ;AAAA,QACtB,QAAQ,QAAQ,UAAU,KAAK;AAAA,QAC/B,iBAAiB,QAAQ;AAAA,QACzB,YAAY,QAAQ;AAAA,MACtB;AAAA,MACA;AAAA,QACE,QAAQ,QAAQ,UACX,KAAK,iBACN,KAAK;AAAA,MACX;AAAA,MACA,EAAE,QAAQ,KAAK,iBAAiB,GAAG,KAAK,qBAAqB,cAAc,EAAE;AAAA,IAC/E;AAAA,EACF;AAAA,EAEA,uBACE,SACA,gBACyD;AACzD,WAAO;AAAA,MACL,EAAE,SAAS,KAAK,SAAS,eAAe,QAAQ,eAAe,QAAQ,QAAQ,OAAO;AAAA,MACtF,EAAE,QAAQ,KAAK,gBAAgB;AAAA,MAC/B,EAAE,QAAQ,KAAK,iBAAiB,GAAG,KAAK,qBAAqB,cAAc,EAAE;AAAA,IAC/E;AAAA,EACF;AAAA,EAEA,uBACE,SACA,gBACyD;AACzD,WAAO;AAAA,MACL,EAAE,SAAS,KAAK,SAAS,eAAe,QAAQ,eAAe,MAAM,QAAQ,KAAK;AAAA,MAClF,EAAE,QAAQ,KAAK,gBAAgB;AAAA,MAC/B,EAAE,QAAQ,KAAK,iBAAiB,GAAG,KAAK,qBAAqB,cAAc,EAAE;AAAA,IAC/E;AAAA,EACF;AAAA,EAEA,qBAAqB,SAAmE;AACtF,WAAO;AAAA,MACL,UAAU,EAAE,GAAG,KAAK,iBAAiB,UAAU,GAAG,SAAS,SAAS;AAAA,MACpE,OAAO,SAAS,SAAS,KAAK,iBAAiB;AAAA,MAC/C,mBAAmB,SAAS;AAAA,IAC9B;AAAA,EACF;AACF;AAEA,SAAS,cACP,QACA,aAC8B;AAC9B,MAAI,YAAY,OAAQ,QAAO,OAAO;AAEtC,SAAO,aAAa;AAAA,IAClB,GAAG;AAAA,IACH,MAAM,OAAO,SAAS,OAAO,gBAAgB,SAAY,cAAc;AAAA,EACzE,CAAC;AACH;","names":[]}
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 initialViewportId?: string;\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 initialViewportId: options?.initialViewportId,\n };\n }\n}\n"],"mappings":"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","names":[]}
@@ -0,0 +1,29 @@
1
+ import { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';
2
+
3
+ /** Options for the legacy functional Delivery client constructor. */
4
+ type CreateClientOptions = {
5
+ accessToken: string;
6
+ /**
7
+ * Base URL for the delivery client. Defaults to `DELIVERY_HOST` when omitted.
8
+ * Pass `PREVIEW_HOST` for preview mode, or any custom URL (staging, proxy,
9
+ * per-region). Both constants are exported from this package.
10
+ */
11
+ host?: string;
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
+ 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
+
29
+ export { type CreateClientOptions, type RuntimeDeliveryClientOptions, createClient, createRuntimeDeliveryClient };
@@ -0,0 +1,27 @@
1
+ import { ContentfulViewDeliveryClient } from "@contentful/experience-delivery";
2
+ function createClient(options) {
3
+ const { accessToken, host, ...rest } = options;
4
+ return new ContentfulViewDeliveryClient({
5
+ ...rest,
6
+ token: accessToken,
7
+ baseUrl: host
8
+ });
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
+ export {
24
+ createClient,
25
+ createRuntimeDeliveryClient
26
+ };
27
+ //# sourceMappingURL=create-delivery-client.js.map
@@ -0,0 +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":[]}
@@ -0,0 +1,20 @@
1
+ import { ExperienceApiClientConfig, InsightsApiClientConfig, ApiClientConfig } from '@contentful/optimization-api-client';
2
+ import { RuntimeOptimizationApiClient } from './runtime-event-methods.js';
3
+ import '@contentful/optimization-api-client/api-schemas';
4
+ import './event-builder.js';
5
+ import 'zod/mini';
6
+
7
+ /** Stable configuration for the runtime-owned Optimization API client. */
8
+ type RuntimeOptimizationConfig = {
9
+ personalizationBaseUrl?: ExperienceApiClientConfig['baseUrl'];
10
+ analyticsBaseUrl?: InsightsApiClientConfig['baseUrl'];
11
+ personalizationEnabledFeatures?: ExperienceApiClientConfig['enabledFeatures'];
12
+ fetchOptions?: ApiClientConfig['fetchOptions'];
13
+ };
14
+ type CreateRuntimeOptimizationClientOptions = RuntimeOptimizationConfig & {
15
+ spaceId: string;
16
+ environmentId: string;
17
+ };
18
+ declare function createRuntimeOptimizationClient({ spaceId, environmentId, personalizationBaseUrl, analyticsBaseUrl, personalizationEnabledFeatures, fetchOptions, }: CreateRuntimeOptimizationClientOptions): RuntimeOptimizationApiClient;
19
+
20
+ export { type RuntimeOptimizationConfig, createRuntimeOptimizationClient };
@@ -0,0 +1,30 @@
1
+ import {
2
+ ApiClient as OptimizationApiClient
3
+ } from "@contentful/optimization-api-client";
4
+ function createRuntimeOptimizationClient({
5
+ spaceId,
6
+ environmentId,
7
+ personalizationBaseUrl,
8
+ analyticsBaseUrl,
9
+ personalizationEnabledFeatures,
10
+ fetchOptions
11
+ }) {
12
+ const client = new OptimizationApiClient({
13
+ spaceId,
14
+ environment: environmentId,
15
+ fetchOptions,
16
+ experience: {
17
+ baseUrl: personalizationBaseUrl,
18
+ enabledFeatures: personalizationEnabledFeatures
19
+ },
20
+ insights: { baseUrl: analyticsBaseUrl }
21
+ });
22
+ return {
23
+ personalization: client.experience,
24
+ analytics: client.insights
25
+ };
26
+ }
27
+ export {
28
+ createRuntimeOptimizationClient
29
+ };
30
+ //# sourceMappingURL=create-optimization-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/create-optimization-client.ts"],"sourcesContent":["import {\n ApiClient as OptimizationApiClient,\n type ApiClientConfig as OptimizationApiClientConfig,\n type ExperienceApiClientConfig as PersonalizationApiClientConfig,\n type InsightsApiClientConfig as AnalyticsApiClientConfig,\n} from '@contentful/optimization-api-client';\nimport type { RuntimeOptimizationApiClient } from './runtime-event-methods.js';\n\n/** Stable configuration for the runtime-owned Optimization API client. */\nexport type RuntimeOptimizationConfig = {\n personalizationBaseUrl?: PersonalizationApiClientConfig['baseUrl'];\n analyticsBaseUrl?: AnalyticsApiClientConfig['baseUrl'];\n personalizationEnabledFeatures?: PersonalizationApiClientConfig['enabledFeatures'];\n fetchOptions?: OptimizationApiClientConfig['fetchOptions'];\n};\n\ntype CreateRuntimeOptimizationClientOptions = RuntimeOptimizationConfig & {\n spaceId: string;\n environmentId: string;\n};\n\nexport function createRuntimeOptimizationClient({\n spaceId,\n environmentId,\n personalizationBaseUrl,\n analyticsBaseUrl,\n personalizationEnabledFeatures,\n fetchOptions,\n}: CreateRuntimeOptimizationClientOptions): RuntimeOptimizationApiClient {\n const client = new OptimizationApiClient({\n spaceId,\n environment: environmentId,\n fetchOptions,\n experience: {\n baseUrl: personalizationBaseUrl,\n enabledFeatures: personalizationEnabledFeatures,\n },\n insights: { baseUrl: analyticsBaseUrl },\n });\n\n return {\n personalization: client.experience,\n analytics: client.insights,\n };\n}\n"],"mappings":"AAAA;AAAA,EACE,aAAa;AAAA,OAIR;AAgBA,SAAS,gCAAgC;AAAA,EAC9C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyE;AACvE,QAAM,SAAS,IAAI,sBAAsB;AAAA,IACvC;AAAA,IACA,aAAa;AAAA,IACb;AAAA,IACA,YAAY;AAAA,MACV,SAAS;AAAA,MACT,iBAAiB;AAAA,IACnB;AAAA,IACA,UAAU,EAAE,SAAS,iBAAiB;AAAA,EACxC,CAAC;AAED,SAAO;AAAA,IACL,iBAAiB,OAAO;AAAA,IACxB,WAAW,OAAO;AAAA,EACpB;AACF;","names":[]}
@@ -1,18 +1,18 @@
1
1
  import {
2
- Campaign,
3
- ExoEntityKind,
4
- GeoLocation,
5
- Page,
6
- PageEventContext,
7
- parseWithFriendlyError,
8
- Properties,
9
- Screen,
10
- Traits
2
+ Campaign as OptimizationCampaign,
3
+ ExoEntityKind as OptimizationExoEntityKind,
4
+ GeoLocation as OptimizationGeoLocation,
5
+ Page as OptimizationPage,
6
+ PageEventContext as OptimizationPageEventContext,
7
+ parseWithFriendlyError as parseOptimizationSchema,
8
+ Properties as OptimizationProperties,
9
+ Screen as OptimizationScreen,
10
+ Traits as OptimizationTraits
11
11
  } from "@contentful/optimization-api-client/api-schemas";
12
- import { createScopedLogger } from "@contentful/optimization-api-client/logger";
12
+ import { createScopedLogger as createOptimizationScopedLogger } from "@contentful/optimization-api-client/logger";
13
13
  import { merge } from "es-toolkit/object";
14
14
  import * as z from "zod/mini";
15
- const eventBuilderLogger = createScopedLogger("Experiences:EventBuilder");
15
+ const eventBuilderLogger = createOptimizationScopedLogger("Experiences:EventBuilder");
16
16
  const UTM_CAMPAIGN_PARAMETERS = [
17
17
  ["utm_campaign", "name"],
18
18
  ["utm_source", "source"],
@@ -37,16 +37,16 @@ function extractCampaignFromUrl(url) {
37
37
  }
38
38
  }
39
39
  const UniversalEventBuilderArgs = z.object({
40
- campaign: z.optional(Campaign),
40
+ campaign: z.optional(OptimizationCampaign),
41
41
  locale: z.optional(z.string()),
42
- location: z.optional(GeoLocation),
43
- page: z.optional(Page),
44
- screen: z.optional(Screen),
42
+ location: z.optional(OptimizationGeoLocation),
43
+ page: z.optional(OptimizationPage),
44
+ screen: z.optional(OptimizationScreen),
45
45
  userAgent: z.optional(z.string())
46
46
  });
47
47
  const InteractionBuilderArgsBase = z.extend(UniversalEventBuilderArgs, {
48
48
  entityId: z.string(),
49
- entityKind: ExoEntityKind,
49
+ entityKind: OptimizationExoEntityKind,
50
50
  entityKindId: z.optional(z.string()),
51
51
  entryIds: z.optional(z.array(z.string())),
52
52
  optimizationId: z.optional(z.string()),
@@ -74,15 +74,15 @@ const FlagViewBuilderArgs = z.extend(FlagInteractionBuilderArgsBase, {
74
74
  viewDurationMs: z.optional(z.number())
75
75
  });
76
76
  const IdentifyBuilderArgs = z.extend(UniversalEventBuilderArgs, {
77
- traits: z.optional(Traits),
77
+ traits: z.optional(OptimizationTraits),
78
78
  userId: z.string()
79
79
  });
80
80
  const PageViewBuilderArgs = z.extend(UniversalEventBuilderArgs, {
81
- properties: z.optional(z.partial(Page))
81
+ properties: z.optional(z.partial(OptimizationPage))
82
82
  });
83
83
  const TrackBuilderArgs = z.extend(UniversalEventBuilderArgs, {
84
84
  event: z.string(),
85
- properties: z.optional(z.prefault(Properties, {}))
85
+ properties: z.optional(z.prefault(OptimizationProperties, {}))
86
86
  });
87
87
  const PAGE_CONTEXT_CONFLICT_KEYS = ["path", "query", "search", "url"];
88
88
  function warnIfPageContextConflicts(explicitPage, properties) {
@@ -167,7 +167,7 @@ class EventBuilder {
167
167
  };
168
168
  }
169
169
  buildView(args) {
170
- const { viewId, viewDurationMs, ...interaction } = parseWithFriendlyError(
170
+ const { viewId, viewDurationMs, ...interaction } = parseOptimizationSchema(
171
171
  ViewBuilderArgs,
172
172
  args
173
173
  );
@@ -179,14 +179,14 @@ class EventBuilder {
179
179
  };
180
180
  }
181
181
  buildClick(args) {
182
- const interaction = parseWithFriendlyError(ClickBuilderArgs, args);
182
+ const interaction = parseOptimizationSchema(ClickBuilderArgs, args);
183
183
  return {
184
184
  ...this.buildInteractionBase(interaction),
185
185
  type: "exo_node_click"
186
186
  };
187
187
  }
188
188
  buildHover(args) {
189
- const { hoverId, hoverDurationMs, ...interaction } = parseWithFriendlyError(
189
+ const { hoverId, hoverDurationMs, ...interaction } = parseOptimizationSchema(
190
190
  HoverBuilderArgs,
191
191
  args
192
192
  );
@@ -198,7 +198,7 @@ class EventBuilder {
198
198
  };
199
199
  }
200
200
  buildFlagView(args) {
201
- const { componentId, experienceId, variantIndex, viewId, viewDurationMs, ...universal } = parseWithFriendlyError(FlagViewBuilderArgs, args);
201
+ const { componentId, experienceId, variantIndex, viewId, viewDurationMs, ...universal } = parseOptimizationSchema(FlagViewBuilderArgs, args);
202
202
  return {
203
203
  ...this.buildUniversalEventProperties(universal),
204
204
  ...viewDurationMs === void 0 ? {} : { viewDurationMs },
@@ -211,7 +211,11 @@ class EventBuilder {
211
211
  };
212
212
  }
213
213
  buildIdentify(args) {
214
- const { traits = {}, userId, ...universal } = parseWithFriendlyError(IdentifyBuilderArgs, args);
214
+ const {
215
+ traits = {},
216
+ userId,
217
+ ...universal
218
+ } = parseOptimizationSchema(IdentifyBuilderArgs, args);
215
219
  return {
216
220
  ...this.buildUniversalEventProperties(universal),
217
221
  type: "identify",
@@ -220,7 +224,7 @@ class EventBuilder {
220
224
  };
221
225
  }
222
226
  buildPageView(args = {}) {
223
- const { properties = {}, ...universal } = parseWithFriendlyError(PageViewBuilderArgs, args);
227
+ const { properties = {}, ...universal } = parseOptimizationSchema(PageViewBuilderArgs, args);
224
228
  const propertiesCampaign = extractCampaignFromUrl(properties.url);
225
229
  const pageProperties = this.getPageProperties();
226
230
  const merged = merge(
@@ -239,7 +243,7 @@ class EventBuilder {
239
243
  campaign: universal.campaign ?? propertiesCampaign,
240
244
  page: universal.page ?? merged
241
245
  });
242
- const context = parseWithFriendlyError(PageEventContext, universalContext);
246
+ const context = parseOptimizationSchema(OptimizationPageEventContext, universalContext);
243
247
  return {
244
248
  ...universalProperties,
245
249
  context,
@@ -248,7 +252,11 @@ class EventBuilder {
248
252
  };
249
253
  }
250
254
  buildTrack(args) {
251
- const { event, properties = {}, ...universal } = parseWithFriendlyError(TrackBuilderArgs, args);
255
+ const {
256
+ event,
257
+ properties = {},
258
+ ...universal
259
+ } = parseOptimizationSchema(TrackBuilderArgs, args);
252
260
  return {
253
261
  ...this.buildUniversalEventProperties(universal),
254
262
  type: "track",