@contentful/experiences-client 0.7.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,13 @@
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
+
1
11
  ## 0.7.0 (2026-09-30)
2
12
 
3
13
  ### 🚀 Features
@@ -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":[]}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
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';
4
5
  export { CreateClientOptions, RuntimeDeliveryClientOptions, createClient } from './create-delivery-client.js';
5
6
  export { RuntimeOptimizationConfig } from './create-optimization-client.js';
6
7
  export { ClickBuilderArgs, DEFAULT_PAGE_PROPERTIES, default as EventBuilder, EventBuilderConfig, FlagViewBuilderArgs, HoverBuilderArgs, IdentifyBuilderArgs, InteractionBuilderArgsBase, PageViewBuilderArgs, TrackBuilderArgs, UniversalEventBuilderArgs, ViewBuilderArgs } from './event-builder.js';
@@ -10,7 +11,7 @@ export { AnalyticsEventMethod, EventProfileRequiredError, PersonalizationEventMe
10
11
  export { RUNTIME_EVENT_HANDOFF_VERSION, RuntimeEventHandoff, RuntimeEventHandoffEvent, RuntimeEventHandoffReceipt, RuntimeServerEventDelivery, assertRuntimeEventHandoffSize, parseRuntimeEventHandoff } from './runtime-event-handoff.js';
11
12
  export { ExperienceResponse, readSourceMap, toExperiencePayload, toExperiencePayloadFromDestination } from './to-experience-payload.js';
12
13
  export { DELIVERY_HOST, PREVIEW_HOST, PREVIEW_WEBSOCKET_HOST } from './hosts.js';
13
- export { OptimizationData as EventOptimizationData, PartialProfile as EventProfile } from '@contentful/optimization-api-client/api-schemas';
14
+ export { OptimizationData as EventOptimizationData, PartialProfile as EventProfile, PartialProfile as EventProfileSchema } from '@contentful/optimization-api-client/api-schemas';
14
15
  import '@contentful/optimization-api-client';
15
16
  import 'zod/mini';
16
17
  import '@contentful/experiences-sdk-core';
package/dist/index.js CHANGED
@@ -5,12 +5,13 @@ 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";
8
9
  import { createClient } from "./create-delivery-client.js";
9
10
  import { default as default2 } from "./event-builder.js";
10
11
  export * from "./event-builder.js";
11
12
  import { fetchExperience } from "./fetch-experience.js";
12
13
  import { ContentfulExperiences } from "./contentful-experiences.js";
13
- import { EventProfileRequiredError } from "./runtime-event-methods.js";
14
+ import { EventProfileRequiredError, EventProfileSchema } from "./runtime-event-methods.js";
14
15
  import {
15
16
  assertRuntimeEventHandoffSize,
16
17
  parseRuntimeEventHandoff,
@@ -23,6 +24,7 @@ import {
23
24
  } from "./to-experience-payload.js";
24
25
  import { DELIVERY_HOST, PREVIEW_HOST, PREVIEW_WEBSOCKET_HOST } from "./hosts.js";
25
26
  export {
27
+ ANONYMOUS_ID_COOKIE,
26
28
  ContentfulExperiences,
27
29
  ContentfulViewDelivery2 as ContentfulViewDelivery,
28
30
  ContentfulViewDeliveryClient,
@@ -30,10 +32,12 @@ export {
30
32
  DestinationPreviewNotSupportedError,
31
33
  default2 as EventBuilder,
32
34
  EventProfileRequiredError,
35
+ EventProfileSchema,
33
36
  ExperienceFetchError,
34
37
  NotFoundError,
35
38
  PREVIEW_HOST,
36
39
  PREVIEW_WEBSOCKET_HOST,
40
+ PROFILE_CACHE_KEY,
37
41
  RUNTIME_EVENT_HANDOFF_VERSION,
38
42
  assertRuntimeEventHandoffSize,
39
43
  createClient,
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 { 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 { 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 } 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,oBAAoB;AAM7B,SAAoB,WAAXC,gBAA+B;AACxC,cAAc;AACd,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AAUtC,SAAS,iCAAiC;AAS1C;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 { 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 { 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,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,6 +1,6 @@
1
1
  import { ExperienceApiClient, InsightsApiClient } from '@contentful/optimization-api-client';
2
2
  import { PartialProfile, ExperienceEvent, OptimizationData, InsightsEvent } from '@contentful/optimization-api-client/api-schemas';
3
- export { OptimizationData as EventOptimizationData, PartialProfile as EventProfile } from '@contentful/optimization-api-client/api-schemas';
3
+ export { OptimizationData as EventOptimizationData, PartialProfile as EventProfile, PartialProfile as EventProfileSchema } from '@contentful/optimization-api-client/api-schemas';
4
4
  import EventBuilder, { UniversalEventBuilderArgs, IdentifyBuilderArgs, PageViewBuilderArgs, TrackBuilderArgs, ViewBuilderArgs, ClickBuilderArgs, HoverBuilderArgs, FlagViewBuilderArgs } from './event-builder.js';
5
5
  import 'zod/mini';
6
6
 
@@ -1,3 +1,6 @@
1
+ import {
2
+ PartialProfile as EventProfileSchema
3
+ } from "@contentful/optimization-api-client/api-schemas";
1
4
  class EventProfileRequiredError extends Error {
2
5
  method;
3
6
  constructor(method) {
@@ -100,6 +103,7 @@ function createRuntimeEventMethods(api, eventBuilder, bindings, dispatch = creat
100
103
  }
101
104
  export {
102
105
  EventProfileRequiredError,
106
+ EventProfileSchema,
103
107
  createRuntimeEventMethods
104
108
  };
105
109
  //# sourceMappingURL=runtime-event-methods.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/runtime-event-methods.ts"],"sourcesContent":["import type {\n ExperienceApiClient as PersonalizationApiClient,\n InsightsApiClient as AnalyticsApiClient,\n} from '@contentful/optimization-api-client';\nimport type {\n ExperienceEvent as PersonalizationEvent,\n InsightsEvent as AnalyticsEvent,\n OptimizationData as EventOptimizationData,\n PartialProfile as EventProfile,\n} from '@contentful/optimization-api-client/api-schemas';\n\nimport type EventBuilder from './event-builder.js';\nimport type {\n ClickBuilderArgs,\n FlagViewBuilderArgs,\n HoverBuilderArgs,\n IdentifyBuilderArgs,\n PageViewBuilderArgs,\n TrackBuilderArgs,\n UniversalEventBuilderArgs,\n ViewBuilderArgs,\n} from './event-builder.js';\nexport type { EventOptimizationData, EventProfile };\n\nexport type PersonalizationEventMethod = 'identify' | 'page' | 'track';\nexport type AnalyticsEventMethod = 'trackView' | 'trackClick' | 'trackHover' | 'trackFlagView';\n\n/** The Optimization API surface used by the shared runtime. */\nexport interface RuntimeOptimizationApiClient {\n readonly personalization: Pick<PersonalizationApiClient, 'upsertProfile'>;\n readonly analytics: Pick<AnalyticsApiClient, 'sendBatchEvents'>;\n}\n\n/** Internal strategy used by a runtime to commit or stage built events. */\nexport interface RuntimeEventDispatch {\n personalization(\n event: PersonalizationEvent,\n profile: EventProfile | undefined\n ): Promise<EventOptimizationData>;\n analytics(event: AnalyticsEvent, profile: EventProfile): Promise<boolean>;\n}\n\n/** Runtime-owned state and context used to bind otherwise stateless event methods. */\nexport interface RuntimeEventBindings {\n getProfile: () => EventProfile | undefined;\n setProfile: (profile: EventProfile) => void;\n /** Changes when an external session boundary must invalidate an in-flight profile response. */\n getProfileRevision?: () => number;\n getEventContext?: () => UniversalEventBuilderArgs;\n getConsent?: () => boolean | undefined;\n}\n\n/**\n * Event-triggering surface shared by the public Node and Web runtimes.\n * Profile-producing calls are not serialized; await them before another\n * profile-producing or Analytics call on the same bound runtime. In Node\n * handoff mode an Analytics `true` means accepted into the handoff journal,\n * not delivered to the Analytics transport.\n */\nexport interface RuntimeEventMethods {\n readonly profile: EventProfile | undefined;\n identify(args: IdentifyBuilderArgs): Promise<EventOptimizationData>;\n page(args?: PageViewBuilderArgs): Promise<EventOptimizationData>;\n track(args: TrackBuilderArgs): Promise<EventOptimizationData>;\n trackView(args: ViewBuilderArgs): Promise<boolean>;\n trackClick(args: ClickBuilderArgs): Promise<boolean>;\n trackHover(args: HoverBuilderArgs): Promise<boolean>;\n trackFlagView(args: FlagViewBuilderArgs): Promise<boolean>;\n}\n\n/** Thrown when an Analytics event is triggered before a profile is available. */\nexport class EventProfileRequiredError extends Error {\n readonly method: AnalyticsEventMethod;\n\n constructor(method: AnalyticsEventMethod) {\n super(\n `${method}() requires a current event profile. Supply an initial profile or await identify(), page(), or track() first.`\n );\n this.name = 'EventProfileRequiredError';\n this.method = method;\n }\n}\n\nclass BoundRuntimeEventMethods implements RuntimeEventMethods {\n constructor(\n private readonly eventBuilder: EventBuilder,\n private readonly bindings: RuntimeEventBindings,\n private readonly dispatch: RuntimeEventDispatch\n ) {}\n\n get profile(): EventProfile | undefined {\n return this.bindings.getProfile();\n }\n\n async identify(args: IdentifyBuilderArgs): Promise<EventOptimizationData> {\n return this.sendPersonalizationEvent(\n this.eventBuilder.buildIdentify(this.withEventContext(args))\n );\n }\n\n async page(args: PageViewBuilderArgs = {}): Promise<EventOptimizationData> {\n return this.sendPersonalizationEvent(\n this.eventBuilder.buildPageView(this.withEventContext(args))\n );\n }\n\n async track(args: TrackBuilderArgs): Promise<EventOptimizationData> {\n return this.sendPersonalizationEvent(this.eventBuilder.buildTrack(this.withEventContext(args)));\n }\n\n async trackView(args: ViewBuilderArgs): Promise<boolean> {\n return this.sendAnalyticsEvent(\n 'trackView',\n this.eventBuilder.buildView(this.withEventContext(args))\n );\n }\n\n async trackClick(args: ClickBuilderArgs): Promise<boolean> {\n return this.sendAnalyticsEvent(\n 'trackClick',\n this.eventBuilder.buildClick(this.withEventContext(args))\n );\n }\n\n async trackHover(args: HoverBuilderArgs): Promise<boolean> {\n return this.sendAnalyticsEvent(\n 'trackHover',\n this.eventBuilder.buildHover(this.withEventContext(args))\n );\n }\n\n async trackFlagView(args: FlagViewBuilderArgs): Promise<boolean> {\n return this.sendAnalyticsEvent(\n 'trackFlagView',\n this.eventBuilder.buildFlagView(this.withEventContext(args))\n );\n }\n\n private withEventContext<TArgs extends UniversalEventBuilderArgs>(args: TArgs): TArgs {\n return { ...this.bindings.getEventContext?.(), ...args } as TArgs;\n }\n\n private withConsent<TEvent extends PersonalizationEvent | AnalyticsEvent>(event: TEvent): TEvent {\n const consent = this.bindings.getConsent?.();\n if (consent === undefined) return event;\n\n return {\n ...event,\n context: {\n ...event.context,\n gdpr: { ...event.context.gdpr, isConsentGiven: consent },\n },\n } as TEvent;\n }\n\n private async sendPersonalizationEvent(\n event: PersonalizationEvent\n ): Promise<EventOptimizationData> {\n const eventWithConsent = this.withConsent(event);\n const profileRevision = this.bindings.getProfileRevision?.();\n const data = await this.dispatch.personalization(eventWithConsent, this.profile);\n if (profileRevision === undefined || this.bindings.getProfileRevision?.() === profileRevision) {\n this.bindings.setProfile(data.profile);\n }\n return data;\n }\n\n private async sendAnalyticsEvent(\n method: AnalyticsEventMethod,\n event: AnalyticsEvent\n ): Promise<boolean> {\n const profile = this.profile;\n if (profile === undefined) throw new EventProfileRequiredError(method);\n return this.dispatch.analytics(this.withConsent(event), profile);\n }\n}\n\nfunction createDirectEventDispatch(api: RuntimeOptimizationApiClient): RuntimeEventDispatch {\n return {\n personalization: (event, profile) =>\n api.personalization.upsertProfile(\n { profileId: profile?.id, events: [event] },\n { locale: event.context.locale }\n ),\n analytics: (event, profile) => api.analytics.sendBatchEvents([{ profile, events: [event] }]),\n };\n}\n\nexport function createRuntimeEventMethods(\n api: RuntimeOptimizationApiClient,\n eventBuilder: EventBuilder,\n bindings: RuntimeEventBindings,\n dispatch: RuntimeEventDispatch = createDirectEventDispatch(api)\n): RuntimeEventMethods {\n return new BoundRuntimeEventMethods(eventBuilder, bindings, dispatch);\n}\n"],"mappings":"AAuEO,MAAM,kCAAkC,MAAM;AAAA,EAC1C;AAAA,EAET,YAAY,QAA8B;AACxC;AAAA,MACE,GAAG,MAAM;AAAA,IACX;AACA,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AACF;AAEA,MAAM,yBAAwD;AAAA,EAC5D,YACmB,cACA,UACA,UACjB;AAHiB;AACA;AACA;AAAA,EAChB;AAAA,EAHgB;AAAA,EACA;AAAA,EACA;AAAA,EAGnB,IAAI,UAAoC;AACtC,WAAO,KAAK,SAAS,WAAW;AAAA,EAClC;AAAA,EAEA,MAAM,SAAS,MAA2D;AACxE,WAAO,KAAK;AAAA,MACV,KAAK,aAAa,cAAc,KAAK,iBAAiB,IAAI,CAAC;AAAA,IAC7D;AAAA,EACF;AAAA,EAEA,MAAM,KAAK,OAA4B,CAAC,GAAmC;AACzE,WAAO,KAAK;AAAA,MACV,KAAK,aAAa,cAAc,KAAK,iBAAiB,IAAI,CAAC;AAAA,IAC7D;AAAA,EACF;AAAA,EAEA,MAAM,MAAM,MAAwD;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BAAqB,MAAM,iBAAiB;AAC7F,WAAK,SAAS,WAAW,KAAK,OAAO;AAAA,IACvC;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,mBACZ,QACA,OACkB;AAClB,UAAM,UAAU,KAAK;AACrB,QAAI,YAAY,OAAW,OAAM,IAAI,0BAA0B,MAAM;AACrE,WAAO,KAAK,SAAS,UAAU,KAAK,YAAY,KAAK,GAAG,OAAO;AAAA,EACjE;AACF;AAEA,SAAS,0BAA0B,KAAyD;AAC1F,SAAO;AAAA,IACL,iBAAiB,CAAC,OAAO,YACvB,IAAI,gBAAgB;AAAA,MAClB,EAAE,WAAW,SAAS,IAAI,QAAQ,CAAC,KAAK,EAAE;AAAA,MAC1C,EAAE,QAAQ,MAAM,QAAQ,OAAO;AAAA,IACjC;AAAA,IACF,WAAW,CAAC,OAAO,YAAY,IAAI,UAAU,gBAAgB,CAAC,EAAE,SAAS,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;AAAA,EAC7F;AACF;AAEO,SAAS,0BACd,KACA,cACA,UACA,WAAiC,0BAA0B,GAAG,GACzC;AACrB,SAAO,IAAI,yBAAyB,cAAc,UAAU,QAAQ;AACtE;","names":[]}
1
+ {"version":3,"sources":["../src/runtime-event-methods.ts"],"sourcesContent":["import type {\n ExperienceApiClient as PersonalizationApiClient,\n InsightsApiClient as AnalyticsApiClient,\n} from '@contentful/optimization-api-client';\nimport {\n PartialProfile as EventProfileSchema,\n type ExperienceEvent as PersonalizationEvent,\n type InsightsEvent as AnalyticsEvent,\n type OptimizationData as EventOptimizationData,\n type PartialProfile as EventProfile,\n} from '@contentful/optimization-api-client/api-schemas';\nimport type EventBuilder from './event-builder.js';\nimport type {\n ClickBuilderArgs,\n FlagViewBuilderArgs,\n HoverBuilderArgs,\n IdentifyBuilderArgs,\n PageViewBuilderArgs,\n TrackBuilderArgs,\n UniversalEventBuilderArgs,\n ViewBuilderArgs,\n} from './event-builder.js';\n\n/** Runtime schema for profiles retained by public runtime leaves. */\nexport { EventProfileSchema };\nexport type { EventOptimizationData, EventProfile };\n\nexport type PersonalizationEventMethod = 'identify' | 'page' | 'track';\nexport type AnalyticsEventMethod = 'trackView' | 'trackClick' | 'trackHover' | 'trackFlagView';\n\n/** The Optimization API surface used by the shared runtime. */\nexport interface RuntimeOptimizationApiClient {\n readonly personalization: Pick<PersonalizationApiClient, 'upsertProfile'>;\n readonly analytics: Pick<AnalyticsApiClient, 'sendBatchEvents'>;\n}\n\n/** Internal strategy used by a runtime to commit or stage built events. */\nexport interface RuntimeEventDispatch {\n personalization(\n event: PersonalizationEvent,\n profile: EventProfile | undefined\n ): Promise<EventOptimizationData>;\n analytics(event: AnalyticsEvent, profile: EventProfile): Promise<boolean>;\n}\n\n/** Runtime-owned state and context used to bind otherwise stateless event methods. */\nexport interface RuntimeEventBindings {\n getProfile: () => EventProfile | undefined;\n setProfile: (profile: EventProfile) => void;\n /** Changes when an external session boundary must invalidate an in-flight profile response. */\n getProfileRevision?: () => number;\n getEventContext?: () => UniversalEventBuilderArgs;\n getConsent?: () => boolean | undefined;\n}\n\n/**\n * Event-triggering surface shared by the public Node and Web runtimes.\n * Profile-producing calls are not serialized; await them before another\n * profile-producing or Analytics call on the same bound runtime. In Node\n * handoff mode an Analytics `true` means accepted into the handoff journal,\n * not delivered to the Analytics transport.\n */\nexport interface RuntimeEventMethods {\n readonly profile: EventProfile | undefined;\n identify(args: IdentifyBuilderArgs): Promise<EventOptimizationData>;\n page(args?: PageViewBuilderArgs): Promise<EventOptimizationData>;\n track(args: TrackBuilderArgs): Promise<EventOptimizationData>;\n trackView(args: ViewBuilderArgs): Promise<boolean>;\n trackClick(args: ClickBuilderArgs): Promise<boolean>;\n trackHover(args: HoverBuilderArgs): Promise<boolean>;\n trackFlagView(args: FlagViewBuilderArgs): Promise<boolean>;\n}\n\n/** Thrown when an Analytics event is triggered before a profile is available. */\nexport class EventProfileRequiredError extends Error {\n readonly method: AnalyticsEventMethod;\n\n constructor(method: AnalyticsEventMethod) {\n super(\n `${method}() requires a current event profile. Supply an initial profile or await identify(), page(), or track() first.`\n );\n this.name = 'EventProfileRequiredError';\n this.method = method;\n }\n}\n\nclass BoundRuntimeEventMethods implements RuntimeEventMethods {\n constructor(\n private readonly eventBuilder: EventBuilder,\n private readonly bindings: RuntimeEventBindings,\n private readonly dispatch: RuntimeEventDispatch\n ) {}\n\n get profile(): EventProfile | undefined {\n return this.bindings.getProfile();\n }\n\n async identify(args: IdentifyBuilderArgs): Promise<EventOptimizationData> {\n return this.sendPersonalizationEvent(\n this.eventBuilder.buildIdentify(this.withEventContext(args))\n );\n }\n\n async page(args: PageViewBuilderArgs = {}): Promise<EventOptimizationData> {\n return this.sendPersonalizationEvent(\n this.eventBuilder.buildPageView(this.withEventContext(args))\n );\n }\n\n async track(args: TrackBuilderArgs): Promise<EventOptimizationData> {\n return this.sendPersonalizationEvent(this.eventBuilder.buildTrack(this.withEventContext(args)));\n }\n\n async trackView(args: ViewBuilderArgs): Promise<boolean> {\n return this.sendAnalyticsEvent(\n 'trackView',\n this.eventBuilder.buildView(this.withEventContext(args))\n );\n }\n\n async trackClick(args: ClickBuilderArgs): Promise<boolean> {\n return this.sendAnalyticsEvent(\n 'trackClick',\n this.eventBuilder.buildClick(this.withEventContext(args))\n );\n }\n\n async trackHover(args: HoverBuilderArgs): Promise<boolean> {\n return this.sendAnalyticsEvent(\n 'trackHover',\n this.eventBuilder.buildHover(this.withEventContext(args))\n );\n }\n\n async trackFlagView(args: FlagViewBuilderArgs): Promise<boolean> {\n return this.sendAnalyticsEvent(\n 'trackFlagView',\n this.eventBuilder.buildFlagView(this.withEventContext(args))\n );\n }\n\n private withEventContext<TArgs extends UniversalEventBuilderArgs>(args: TArgs): TArgs {\n return { ...this.bindings.getEventContext?.(), ...args } as TArgs;\n }\n\n private withConsent<TEvent extends PersonalizationEvent | AnalyticsEvent>(event: TEvent): TEvent {\n const consent = this.bindings.getConsent?.();\n if (consent === undefined) return event;\n\n return {\n ...event,\n context: {\n ...event.context,\n gdpr: { ...event.context.gdpr, isConsentGiven: consent },\n },\n } as TEvent;\n }\n\n private async sendPersonalizationEvent(\n event: PersonalizationEvent\n ): Promise<EventOptimizationData> {\n const eventWithConsent = this.withConsent(event);\n const profileRevision = this.bindings.getProfileRevision?.();\n const data = await this.dispatch.personalization(eventWithConsent, this.profile);\n if (profileRevision === undefined || this.bindings.getProfileRevision?.() === profileRevision) {\n this.bindings.setProfile(data.profile);\n }\n return data;\n }\n\n private async sendAnalyticsEvent(\n method: AnalyticsEventMethod,\n event: AnalyticsEvent\n ): Promise<boolean> {\n const profile = this.profile;\n if (profile === undefined) throw new EventProfileRequiredError(method);\n return this.dispatch.analytics(this.withConsent(event), profile);\n }\n}\n\nfunction createDirectEventDispatch(api: RuntimeOptimizationApiClient): RuntimeEventDispatch {\n return {\n personalization: (event, profile) =>\n api.personalization.upsertProfile(\n { profileId: profile?.id, events: [event] },\n { locale: event.context.locale }\n ),\n analytics: (event, profile) => api.analytics.sendBatchEvents([{ profile, events: [event] }]),\n };\n}\n\nexport function createRuntimeEventMethods(\n api: RuntimeOptimizationApiClient,\n eventBuilder: EventBuilder,\n bindings: RuntimeEventBindings,\n dispatch: RuntimeEventDispatch = createDirectEventDispatch(api)\n): RuntimeEventMethods {\n return new BoundRuntimeEventMethods(eventBuilder, bindings, dispatch);\n}\n"],"mappings":"AAIA;AAAA,EACE,kBAAkB;AAAA,OAKb;AAgEA,MAAM,kCAAkC,MAAM;AAAA,EAC1C;AAAA,EAET,YAAY,QAA8B;AACxC;AAAA,MACE,GAAG,MAAM;AAAA,IACX;AACA,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AACF;AAEA,MAAM,yBAAwD;AAAA,EAC5D,YACmB,cACA,UACA,UACjB;AAHiB;AACA;AACA;AAAA,EAChB;AAAA,EAHgB;AAAA,EACA;AAAA,EACA;AAAA,EAGnB,IAAI,UAAoC;AACtC,WAAO,KAAK,SAAS,WAAW;AAAA,EAClC;AAAA,EAEA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AG,MAAM,QAAQ,MAAM,gBAAgB,QAAQ;AAAA,MACzD;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAc,yBACZ,OACgC;AAChC,UAAM,mBAAmB,KAAK,YAAY,KAAK;AAC/C,UAAM,kBAAkB,KAAK,SAAS,qBAAqB;AAC3D,UAAM,OAAO,MAAM,KAAK,SAAS,gBAAgB,kBAAkB,KAAK,OAAO;AAC/E,QAAI,oBAAoB,UAAa,KAAK,SAAS,qBAAqB,MAAM,iBAAiB;AAC7F,WAAK,SAAS,WAAW,KAAK,OAAO;AAAA,IACvC;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,mBACZ,QACA,OACkB;AAClB,UAAM,UAAU,KAAK;AACrB,QAAI,YAAY,OAAW,OAAM,IAAI,0BAA0B,MAAM;AACrE,WAAO,KAAK,SAAS,UAAU,KAAK,YAAY,KAAK,GAAG,OAAO;AAAA,EACjE;AACF;AAEA,SAAS,0BAA0B,KAAyD;AAC1F,SAAO;AAAA,IACL,iBAAiB,CAAC,OAAO,YACvB,IAAI,gBAAgB;AAAA,MAClB,EAAE,WAAW,SAAS,IAAI,QAAQ,CAAC,KAAK,EAAE;AAAA,MAC1C,EAAE,QAAQ,MAAM,QAAQ,OAAO;AAAA,IACjC;AAAA,IACF,WAAW,CAAC,OAAO,YAAY,IAAI,UAAU,gBAAgB,CAAC,EAAE,SAAS,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;AAAA,EAC7F;AACF;AAEO,SAAS,0BACd,KACA,cACA,UACA,WAAiC,0BAA0B,GAAG,GACzC;AACrB,SAAO,IAAI,yBAAyB,cAAc,UAAU,QAAQ;AACtE;","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.6.0" : "0.0.0"
3
+ version: true ? "0.7.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.7.0",
3
+ "version": "0.7.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.9",
34
- "@contentful/experiences-sdk-core": "0.10.0",
34
+ "@contentful/experiences-sdk-core": "0.10.1",
35
35
  "@contentful/optimization-api-client": "^2.0.1",
36
36
  "es-toolkit": "^1.46.0",
37
37
  "zod": "^4.3.6"