@contentful/experiences-client 0.4.9 → 0.5.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,47 @@
1
+ ## 0.5.1 (2026-09-29)
2
+
3
+ ### 🚀 Features
4
+
5
+ - add Web SDK runtime ([#208](https://github.com/contentful/experiences/pull/208))
6
+
7
+ ### 🧱 Updated Dependencies
8
+
9
+ - Updated core to 0.9.1
10
+
11
+ ## 0.5.0 (2026-09-28)
12
+
13
+ ### 🚀 Features
14
+
15
+ - ⚠️ add request-scoped Node SDK ([#207](https://github.com/contentful/experiences/pull/207))
16
+
17
+ ### ⚠️ Breaking Changes
18
+
19
+ - add request-scoped Node SDK ([#207](https://github.com/contentful/experiences/pull/207))
20
+ ContentfulExperiencesConfig now requires eventBuilder.channel."
21
+ M .husky/pre-commit
22
+ M AGENTS.md
23
+ M ARCHITECTURE.md
24
+ M README.md
25
+ M package-lock.json
26
+ M packages/client/README.md
27
+ M packages/client/src/contentful-experiences.test.ts
28
+ M packages/client/src/contentful-experiences.ts
29
+ A packages/node/README.md
30
+ A packages/node/package.json
31
+ A packages/node/project.json
32
+ A packages/node/src/contentful-experiences.test.ts
33
+ A packages/node/src/contentful-experiences.ts
34
+ A packages/node/src/index.ts
35
+ A packages/node/src/sdk-info.ts
36
+ A packages/node/tsconfig.json
37
+ A packages/node/tsconfig.lib.json
38
+ A packages/node/tsup.config.ts
39
+ A packages/node/vitest.config.ts
40
+
41
+ ### 🧱 Updated Dependencies
42
+
43
+ - Updated core to 0.9.0
44
+
1
45
  ## 0.4.9 (2026-09-28)
2
46
 
3
47
  ### 🚀 Features
package/README.md CHANGED
@@ -2,7 +2,7 @@
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 future Node/Web SDKs and event construction.
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
6
 
7
7
  `ContentfulExperiences` is intentionally not re-exported by framework adapters
8
8
  and is not a new application-facing adapter API. The existing free functions
@@ -14,18 +14,34 @@ remain supported for adapter and application integration.
14
14
 
15
15
  ### Shared lower-layer runtime
16
16
 
17
- `ContentfulExperiences` is an internal shared runtime contract for future
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
- and a delivery client source; optionally provide a preview client source. It
20
- retains those clients, merges configured resolve defaults with per-call options,
21
- and exposes `resolveExperience` and by-id/destination `fetchExperience` methods.
22
- Calling `fetchExperience` with `preview: true` requires the optional preview
23
- client.
24
-
25
- The runtime constructs and owns one `EventBuilder`. Its defaults are server
26
- channel, this SDK's library identity, and the runtime locale; callers may
27
- override the supported event-builder configuration. This is the owner of event
28
- construction for the lower layer, rather than Core.
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.
35
+
36
+ The optional preview client enables direct CPA fetches by Experience ID through
37
+ the same shared runtime. It is separate from `@contentful/experiences-live-preview`,
38
+ which owns Preview Session HTTP loading, WebSocket subscription, and update state.
39
+ Destination operations continue to use the delivery client.
40
+
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.
29
45
 
30
46
  This package's direct dependencies are the generated delivery client,
31
47
  `@contentful/optimization-api-client` (event schemas and logger), `es-toolkit`
@@ -15,7 +15,7 @@ type RuntimeResolveOptions = {
15
15
  initialViewportId?: string;
16
16
  };
17
17
  type RuntimeEventBuilderConfig = Omit<EventBuilderConfig, 'channel' | 'library'> & {
18
- channel?: EventBuilderConfig['channel'];
18
+ channel: EventBuilderConfig['channel'];
19
19
  library?: Partial<EventBuilderConfig['library']>;
20
20
  };
21
21
  type RuntimeFetchExperienceOptions = {
@@ -51,15 +51,15 @@ type ContentfulExperiencesConfig = {
51
51
  delivery: RuntimeClientSource;
52
52
  preview?: RuntimeClientSource;
53
53
  resolveDefaults?: Pick<RuntimeResolveOptions, 'metadata' | 'debug'>;
54
- eventBuilder?: RuntimeEventBuilderConfig;
54
+ eventBuilder: RuntimeEventBuilderConfig;
55
55
  };
56
56
  declare class ContentfulExperiences implements ExperienceRuntime {
57
57
  #private;
58
58
  readonly spaceId: string;
59
59
  readonly environmentId: string;
60
- readonly locale: string | undefined;
61
60
  readonly eventBuilder: EventBuilder;
62
61
  constructor(config: ContentfulExperiencesConfig);
62
+ get locale(): string | undefined;
63
63
  resolveExperience(payload: ExperiencePayload, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan>;
64
64
  fetchExperience(options: RuntimeFetchExperienceOptions, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan>;
65
65
  fetchByDestinationNode(options: RuntimeFetchByDestinationNodeOptions, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan | DestinationRedirectResult>;
@@ -7,8 +7,8 @@ import { DEFAULT_EVENT_CONTEXT_LIBRARY } from "./sdk-info.js";
7
7
  class ContentfulExperiences {
8
8
  spaceId;
9
9
  environmentId;
10
- locale;
11
10
  eventBuilder;
11
+ #locale;
12
12
  #resolverConfig;
13
13
  #deliveryClient;
14
14
  #previewClient;
@@ -16,19 +16,20 @@ class ContentfulExperiences {
16
16
  constructor(config) {
17
17
  this.spaceId = config.spaceId;
18
18
  this.environmentId = config.environmentId;
19
- this.locale = config.locale;
19
+ this.#locale = config.locale;
20
20
  this.#resolverConfig = config.resolverConfig;
21
21
  this.#deliveryClient = resolveClient(config.delivery);
22
22
  this.#previewClient = config.preview === void 0 ? void 0 : resolveClient(config.preview, PREVIEW_HOST);
23
23
  this.#resolveDefaults = config.resolveDefaults ?? {};
24
- const eventBuilder = config.eventBuilder ?? {};
25
24
  this.eventBuilder = new EventBuilder({
26
- ...eventBuilder,
27
- channel: eventBuilder.channel ?? "server",
28
- library: { ...DEFAULT_EVENT_CONTEXT_LIBRARY, ...eventBuilder.library },
29
- getLocale: eventBuilder.getLocale ?? (() => this.locale)
25
+ ...config.eventBuilder,
26
+ library: { ...DEFAULT_EVENT_CONTEXT_LIBRARY, ...config.eventBuilder.library },
27
+ getLocale: config.eventBuilder.getLocale ?? (() => this.locale)
30
28
  });
31
29
  }
30
+ get locale() {
31
+ return this.#locale;
32
+ }
32
33
  resolveExperience(payload, resolveOptions) {
33
34
  return resolveCoreExperience(
34
35
  payload,
@@ -79,7 +80,11 @@ class ContentfulExperiences {
79
80
  }
80
81
  }
81
82
  function resolveClient(source, defaultHost) {
82
- return "client" in source ? source.client : createClient({ ...source, host: source.host ?? defaultHost });
83
+ if ("client" in source) return source.client;
84
+ return createClient({
85
+ ...source,
86
+ host: source.host ?? (source.environment === void 0 ? defaultHost : void 0)
87
+ });
83
88
  }
84
89
  export {
85
90
  ContentfulExperiences
@@ -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 { fetchExperience, type DestinationRedirectResult } 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 preview?: boolean;\n withSourceMap?: 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 locale: string | undefined;\n readonly eventBuilder: EventBuilder;\n\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 const eventBuilder = config.eventBuilder ?? {};\n this.eventBuilder = new EventBuilder({\n ...eventBuilder,\n channel: eventBuilder.channel ?? 'server',\n library: { ...DEFAULT_EVENT_CONTEXT_LIBRARY, ...eventBuilder.library },\n getLocale: eventBuilder.getLocale ?? (() => this.locale),\n });\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 withSourceMap: options.withSourceMap,\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 return 'client' in source\n ? source.client\n : createClient({ ...source, host: source.host ?? defaultHost });\n}\n"],"mappings":"AACA,SAAS,qBAAqB,6BAA6B;AAM3D,OAAO,kBAAkB;AAEzB,SAAS,oBAAoB;AAC7B,SAAS,uBAAuD;AA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AqB,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,SAAO,YAAY,SACf,OAAO,SACP,aAAa,EAAE,GAAG,QAAQ,MAAM,OAAO,QAAQ,YAAY,CAAC;AAClE;","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 { createClient } from './create-client.js';\nimport { fetchExperience, type DestinationRedirectResult } 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 preview?: boolean;\n withSourceMap?: 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 withSourceMap: options.withSourceMap,\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,SAAS,uBAAuD;AAEhE,SAAS,oBAAoB;AAC7B,SAAS,qCAAqC;AAmEvC,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,mBAA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AAQ,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":[]}
package/dist/sdk-info.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const DEFAULT_EVENT_CONTEXT_LIBRARY = {
2
2
  name: true ? "@contentful/experiences-client" : "@contentful/experiences-client",
3
- version: true ? "0.4.8" : "0.0.0"
3
+ version: true ? "0.5.0" : "0.0.0"
4
4
  };
5
5
  export {
6
6
  DEFAULT_EVENT_CONTEXT_LIBRARY
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/experiences-client",
3
- "version": "0.4.9",
3
+ "version": "0.5.1",
4
4
  "description": "Delivery client + fetchExperience for Contentful Experiences",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@contentful/experience-delivery": "1.0.0-dev.8",
34
- "@contentful/experiences-sdk-core": "0.8.7",
34
+ "@contentful/experiences-sdk-core": "0.9.1",
35
35
  "@contentful/optimization-api-client": "^2.0.1",
36
36
  "es-toolkit": "^1.46.0",
37
37
  "zod": "^4.3.6"