@contentful/experiences-client 0.9.0 → 0.9.2
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 +16 -0
- package/README.md +1 -87
- package/dist/client-resolution.d.ts +34 -0
- package/dist/client-resolution.js +23 -0
- package/dist/client-resolution.js.map +1 -0
- package/dist/create-delivery-client.d.ts +1 -15
- package/dist/create-delivery-client.js +1 -15
- package/dist/create-delivery-client.js.map +1 -1
- package/dist/destination-guards.d.ts +16 -0
- package/dist/destination-guards.js +14 -0
- package/dist/destination-guards.js.map +1 -0
- package/dist/errors.d.ts +6 -5
- package/dist/errors.js.map +1 -1
- package/dist/fetch-destination-sitemap.d.ts +41 -0
- package/dist/fetch-destination-sitemap.js +50 -0
- package/dist/fetch-destination-sitemap.js.map +1 -0
- package/dist/fetch-experience.d.ts +3 -25
- package/dist/fetch-experience.js +9 -25
- package/dist/fetch-experience.js.map +1 -1
- package/dist/index.d.ts +4 -11
- package/dist/index.js +2 -19
- package/dist/index.js.map +1 -1
- package/package.json +2 -5
- package/dist/constants.d.ts +0 -11
- package/dist/constants.js +0 -7
- package/dist/constants.js.map +0 -1
- package/dist/contentful-experiences.d.ts +0 -75
- package/dist/contentful-experiences.js +0 -104
- package/dist/contentful-experiences.js.map +0 -1
- package/dist/create-optimization-client.d.ts +0 -20
- package/dist/create-optimization-client.js +0 -30
- package/dist/create-optimization-client.js.map +0 -1
- package/dist/event-builder.d.ts +0 -444
- package/dist/event-builder.js +0 -282
- package/dist/event-builder.js.map +0 -1
- package/dist/runtime-event-handoff.d.ts +0 -33
- package/dist/runtime-event-handoff.js +0 -68
- package/dist/runtime-event-handoff.js.map +0 -1
- package/dist/runtime-event-methods.d.ts +0 -52
- package/dist/runtime-event-methods.js +0 -109
- package/dist/runtime-event-methods.js.map +0 -1
- package/dist/sdk-info.d.ts +0 -12
- package/dist/sdk-info.js +0 -8
- package/dist/sdk-info.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import { ContentfulViewDelivery } from '@contentful/experience-delivery';
|
|
2
2
|
export { ContentfulViewDelivery, ContentfulViewDeliveryClient } from '@contentful/experience-delivery';
|
|
3
3
|
export { DestinationPreviewNotSupportedError, ExperienceFetchError } from './errors.js';
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export { ClickBuilderArgs, DEFAULT_PAGE_PROPERTIES, default as EventBuilder, EventBuilderConfig, FlagViewBuilderArgs, HoverBuilderArgs, IdentifyBuilderArgs, InteractionBuilderArgsBase, PageViewBuilderArgs, TrackBuilderArgs, UniversalEventBuilderArgs, ViewBuilderArgs } from './event-builder.js';
|
|
8
|
-
export { ByDestinationNodeIdExperienceOptions, ByDestinationPathExperienceOptions, ByIdExperienceOptions, ClientOptions, DestinationRedirectResult, ExperienceOptions, ExperienceRequestExtensions, PersonalizationOptions, ResolveOptions, fetchExperience } from './fetch-experience.js';
|
|
9
|
-
export { ContentfulExperiences, ContentfulExperiencesConfig, ExperienceRuntime, RuntimeEventBuilderConfig, RuntimeFetchByDestinationNodeOptions, RuntimeFetchByDestinationPathOptions, RuntimeFetchExperienceOptions, RuntimeResolveOptions } from './contentful-experiences.js';
|
|
10
|
-
export { AnalyticsEventMethod, EventProfileRequiredError, PersonalizationEventMethod, RuntimeEventBindings, RuntimeEventMethods } from './runtime-event-methods.js';
|
|
11
|
-
export { RUNTIME_EVENT_HANDOFF_VERSION, RuntimeEventHandoff, RuntimeEventHandoffEvent, RuntimeEventHandoffReceipt, RuntimeServerEventDelivery, assertRuntimeEventHandoffSize, parseRuntimeEventHandoff } from './runtime-event-handoff.js';
|
|
4
|
+
export { CreateClientOptions, createClient } from './create-delivery-client.js';
|
|
5
|
+
export { ByDestinationNodeIdExperienceOptions, ByDestinationPathExperienceOptions, ByIdExperienceOptions, DestinationRedirectResult, ExperienceOptions, ExperienceRequestExtensions, PersonalizationOptions, ResolveOptions, fetchExperience } from './fetch-experience.js';
|
|
6
|
+
export { DestinationSitemapResult, FetchDestinationSitemapOptions, FetchDestinationSitemapPaginationOptions, SitemapPathItem, fetchDestinationSitemap } from './fetch-destination-sitemap.js';
|
|
12
7
|
export { ExperienceResponse, readSourceMap, toExperiencePayload, toExperiencePayloadFromDestination } from './to-experience-payload.js';
|
|
13
8
|
export { DELIVERY_HOST, PREVIEW_HOST, PREVIEW_WEBSOCKET_HOST } from './hosts.js';
|
|
14
|
-
export {
|
|
15
|
-
import '@contentful/optimization-api-client';
|
|
16
|
-
import 'zod/mini';
|
|
9
|
+
export { ClientOptions } from './client-resolution.js';
|
|
17
10
|
import '@contentful/experiences-sdk-core';
|
|
18
11
|
|
|
19
12
|
declare const NotFoundError: typeof ContentfulViewDelivery.NotFoundError;
|
package/dist/index.js
CHANGED
|
@@ -5,18 +5,9 @@ import {
|
|
|
5
5
|
} from "@contentful/experience-delivery";
|
|
6
6
|
const NotFoundError = ContentfulViewDelivery.NotFoundError;
|
|
7
7
|
import { ExperienceFetchError, DestinationPreviewNotSupportedError } from "./errors.js";
|
|
8
|
-
import { ANONYMOUS_ID_COOKIE, PROFILE_CACHE_KEY } from "./constants.js";
|
|
9
8
|
import { createClient } from "./create-delivery-client.js";
|
|
10
|
-
import { default as default2 } from "./event-builder.js";
|
|
11
|
-
export * from "./event-builder.js";
|
|
12
9
|
import { fetchExperience } from "./fetch-experience.js";
|
|
13
|
-
import {
|
|
14
|
-
import { EventProfileRequiredError, EventProfileSchema } from "./runtime-event-methods.js";
|
|
15
|
-
import {
|
|
16
|
-
assertRuntimeEventHandoffSize,
|
|
17
|
-
parseRuntimeEventHandoff,
|
|
18
|
-
RUNTIME_EVENT_HANDOFF_VERSION
|
|
19
|
-
} from "./runtime-event-handoff.js";
|
|
10
|
+
import { fetchDestinationSitemap } from "./fetch-destination-sitemap.js";
|
|
20
11
|
import {
|
|
21
12
|
readSourceMap,
|
|
22
13
|
toExperiencePayload,
|
|
@@ -24,25 +15,17 @@ import {
|
|
|
24
15
|
} from "./to-experience-payload.js";
|
|
25
16
|
import { DELIVERY_HOST, PREVIEW_HOST, PREVIEW_WEBSOCKET_HOST } from "./hosts.js";
|
|
26
17
|
export {
|
|
27
|
-
ANONYMOUS_ID_COOKIE,
|
|
28
|
-
ContentfulExperiences,
|
|
29
18
|
ContentfulViewDelivery2 as ContentfulViewDelivery,
|
|
30
19
|
ContentfulViewDeliveryClient,
|
|
31
20
|
DELIVERY_HOST,
|
|
32
21
|
DestinationPreviewNotSupportedError,
|
|
33
|
-
default2 as EventBuilder,
|
|
34
|
-
EventProfileRequiredError,
|
|
35
|
-
EventProfileSchema,
|
|
36
22
|
ExperienceFetchError,
|
|
37
23
|
NotFoundError,
|
|
38
24
|
PREVIEW_HOST,
|
|
39
25
|
PREVIEW_WEBSOCKET_HOST,
|
|
40
|
-
PROFILE_CACHE_KEY,
|
|
41
|
-
RUNTIME_EVENT_HANDOFF_VERSION,
|
|
42
|
-
assertRuntimeEventHandoffSize,
|
|
43
26
|
createClient,
|
|
27
|
+
fetchDestinationSitemap,
|
|
44
28
|
fetchExperience,
|
|
45
|
-
parseRuntimeEventHandoff,
|
|
46
29
|
readSourceMap,
|
|
47
30
|
toExperiencePayload,
|
|
48
31
|
toExperiencePayloadFromDestination
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { ContentfulViewDelivery } from '@contentful/experience-delivery';\n\nexport {\n ContentfulViewDelivery,\n ContentfulViewDeliveryClient,\n} from '@contentful/experience-delivery';\nexport const NotFoundError = ContentfulViewDelivery.NotFoundError;\n// eslint-disable-next-line no-redeclare -- value + type share a name across separate TS namespaces, not a real redeclaration\nexport type NotFoundError = InstanceType<typeof ContentfulViewDelivery.NotFoundError>;\nexport { ExperienceFetchError, DestinationPreviewNotSupportedError } from './errors.js';\nexport {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { ContentfulViewDelivery } from '@contentful/experience-delivery';\n\nexport {\n ContentfulViewDelivery,\n ContentfulViewDeliveryClient,\n} from '@contentful/experience-delivery';\nexport const NotFoundError = ContentfulViewDelivery.NotFoundError;\n// eslint-disable-next-line no-redeclare -- value + type share a name across separate TS namespaces, not a real redeclaration\nexport type NotFoundError = InstanceType<typeof ContentfulViewDelivery.NotFoundError>;\nexport { ExperienceFetchError, DestinationPreviewNotSupportedError } from './errors.js';\nexport { createClient } from './create-delivery-client.js';\nexport type { CreateClientOptions } from './create-delivery-client.js';\nexport { fetchExperience } from './fetch-experience.js';\nexport { fetchDestinationSitemap } from './fetch-destination-sitemap.js';\nexport type {\n FetchDestinationSitemapOptions,\n FetchDestinationSitemapPaginationOptions,\n SitemapPathItem,\n DestinationSitemapResult,\n} from './fetch-destination-sitemap.js';\nexport {\n readSourceMap,\n toExperiencePayload,\n toExperiencePayloadFromDestination,\n} from './to-experience-payload.js';\nexport type { ExperienceResponse } from './to-experience-payload.js';\nexport type {\n ExperienceOptions,\n ExperienceRequestExtensions,\n PersonalizationOptions,\n ByIdExperienceOptions,\n ByDestinationNodeIdExperienceOptions,\n ByDestinationPathExperienceOptions,\n ClientOptions,\n ResolveOptions,\n DestinationRedirectResult,\n} from './fetch-experience.js';\nexport { DELIVERY_HOST, PREVIEW_HOST, PREVIEW_WEBSOCKET_HOST } from './hosts.js';\n"],"mappings":"AAAA,SAAS,8BAA8B;AAEvC;AAAA,EACE,0BAAAA;AAAA,EACA;AAAA,OACK;AACA,MAAM,gBAAgB,uBAAuB;AAGpD,SAAS,sBAAsB,2CAA2C;AAC1E,SAAS,oBAAoB;AAE7B,SAAS,uBAAuB;AAChC,SAAS,+BAA+B;AAOxC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAaP,SAAS,eAAe,cAAc,8BAA8B;","names":["ContentfulViewDelivery"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/experiences-client",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "Delivery client + fetchExperience for Contentful Experiences",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -31,9 +31,6 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@contentful/experience-delivery": "1.0.0-dev.9",
|
|
34
|
-
"@contentful/experiences-sdk-core": "0.12.
|
|
35
|
-
"@contentful/optimization-api-client": "^2.0.1",
|
|
36
|
-
"es-toolkit": "^1.46.0",
|
|
37
|
-
"zod": "^4.3.6"
|
|
34
|
+
"@contentful/experiences-sdk-core": "0.12.1"
|
|
38
35
|
}
|
|
39
36
|
}
|
package/dist/constants.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cookie name used to carry an anonymous/profile id between browser and server
|
|
3
|
-
* runtimes. The value matches the Contentful Optimization SDK.
|
|
4
|
-
*
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
declare const ANONYMOUS_ID_COOKIE = "ctfl-opt-aid";
|
|
8
|
-
/** @internal LocalStorage key for the persisted profile. */
|
|
9
|
-
declare const PROFILE_CACHE_KEY = "__ctfl_opt_profile__";
|
|
10
|
-
|
|
11
|
-
export { ANONYMOUS_ID_COOKIE, PROFILE_CACHE_KEY };
|
package/dist/constants.js
DELETED
package/dist/constants.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.ts"],"sourcesContent":["/**\n * Cookie name used to carry an anonymous/profile id between browser and server\n * runtimes. The value matches the Contentful Optimization SDK.\n *\n * @public\n */\nexport const ANONYMOUS_ID_COOKIE = 'ctfl-opt-aid';\n\n/** @internal LocalStorage key for the persisted profile. */\nexport const PROFILE_CACHE_KEY = '__ctfl_opt_profile__';\n"],"mappings":"AAMO,MAAM,sBAAsB;AAG5B,MAAM,oBAAoB;","names":[]}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { ExperiencePayload, PortableRenderPlan, ResolverConfig } from '@contentful/experiences-sdk-core';
|
|
2
|
-
import EventBuilder, { EventBuilderConfig } from './event-builder.js';
|
|
3
|
-
import { RuntimeDeliveryClientOptions } from './create-delivery-client.js';
|
|
4
|
-
import { PersonalizationOptions, ExperienceRequestExtensions, DestinationRedirectResult } from './fetch-experience.js';
|
|
5
|
-
import { RuntimeOptimizationConfig } from './create-optimization-client.js';
|
|
6
|
-
import { RuntimeOptimizationApiClient, RuntimeEventBindings, RuntimeEventDispatch, RuntimeEventMethods } from './runtime-event-methods.js';
|
|
7
|
-
import '@contentful/optimization-api-client/api-schemas';
|
|
8
|
-
import 'zod/mini';
|
|
9
|
-
import '@contentful/experience-delivery';
|
|
10
|
-
import '@contentful/optimization-api-client';
|
|
11
|
-
|
|
12
|
-
type RuntimeResolveOptions = {
|
|
13
|
-
metadata?: Record<string, unknown>;
|
|
14
|
-
debug?: boolean;
|
|
15
|
-
};
|
|
16
|
-
type RuntimeEventBuilderConfig = Omit<EventBuilderConfig, 'channel' | 'library'> & {
|
|
17
|
-
channel: EventBuilderConfig['channel'];
|
|
18
|
-
library?: Partial<EventBuilderConfig['library']>;
|
|
19
|
-
};
|
|
20
|
-
type RuntimeFetchExperienceOptions = {
|
|
21
|
-
experienceId: string;
|
|
22
|
-
locale?: string;
|
|
23
|
-
personalization?: PersonalizationOptions;
|
|
24
|
-
extensions?: ExperienceRequestExtensions;
|
|
25
|
-
preview?: boolean;
|
|
26
|
-
};
|
|
27
|
-
type RuntimeFetchByDestinationNodeOptions = {
|
|
28
|
-
destinationId: string;
|
|
29
|
-
nodeId: string;
|
|
30
|
-
};
|
|
31
|
-
type RuntimeFetchByDestinationPathOptions = {
|
|
32
|
-
destinationId: string;
|
|
33
|
-
path: string;
|
|
34
|
-
};
|
|
35
|
-
/** Structural contract implemented by the Client runtime. */
|
|
36
|
-
interface ExperienceRuntime {
|
|
37
|
-
readonly spaceId: string;
|
|
38
|
-
readonly environmentId: string;
|
|
39
|
-
readonly locale: string | undefined;
|
|
40
|
-
readonly eventBuilder: EventBuilder;
|
|
41
|
-
resolveExperience(payload: ExperiencePayload, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan>;
|
|
42
|
-
fetchExperience(options: RuntimeFetchExperienceOptions, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan>;
|
|
43
|
-
fetchByDestinationNode(options: RuntimeFetchByDestinationNodeOptions, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan | DestinationRedirectResult>;
|
|
44
|
-
fetchByDestinationPath(options: RuntimeFetchByDestinationPathOptions, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan | DestinationRedirectResult>;
|
|
45
|
-
}
|
|
46
|
-
type ContentfulExperiencesConfig = {
|
|
47
|
-
spaceId: string;
|
|
48
|
-
environmentId: string;
|
|
49
|
-
locale?: string;
|
|
50
|
-
resolverConfig: ResolverConfig;
|
|
51
|
-
/** Configuration for the runtime-owned Content Delivery API client. */
|
|
52
|
-
delivery: RuntimeDeliveryClientOptions;
|
|
53
|
-
/** Optional configuration for the runtime-owned Content Preview API client. */
|
|
54
|
-
preview?: RuntimeDeliveryClientOptions;
|
|
55
|
-
/** Overrides for the runtime-owned Personalization and Analytics event transport. */
|
|
56
|
-
optimization?: RuntimeOptimizationConfig;
|
|
57
|
-
resolveDefaults?: Pick<RuntimeResolveOptions, 'metadata' | 'debug'>;
|
|
58
|
-
eventBuilder: RuntimeEventBuilderConfig;
|
|
59
|
-
};
|
|
60
|
-
declare class ContentfulExperiences implements ExperienceRuntime {
|
|
61
|
-
#private;
|
|
62
|
-
readonly spaceId: string;
|
|
63
|
-
readonly environmentId: string;
|
|
64
|
-
readonly eventBuilder: EventBuilder;
|
|
65
|
-
protected readonly optimizationApi: RuntimeOptimizationApiClient;
|
|
66
|
-
constructor(config: ContentfulExperiencesConfig);
|
|
67
|
-
get locale(): string | undefined;
|
|
68
|
-
protected createEventMethods(bindings: RuntimeEventBindings, dispatch?: RuntimeEventDispatch): RuntimeEventMethods;
|
|
69
|
-
resolveExperience(payload: ExperiencePayload, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan>;
|
|
70
|
-
fetchExperience(options: RuntimeFetchExperienceOptions, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan>;
|
|
71
|
-
fetchByDestinationNode(options: RuntimeFetchByDestinationNodeOptions, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan | DestinationRedirectResult>;
|
|
72
|
-
fetchByDestinationPath(options: RuntimeFetchByDestinationPathOptions, resolveOptions?: RuntimeResolveOptions): Promise<PortableRenderPlan | DestinationRedirectResult>;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export { ContentfulExperiences, type ContentfulExperiencesConfig, type ExperienceRuntime, type RuntimeEventBuilderConfig, type RuntimeFetchByDestinationNodeOptions, type RuntimeFetchByDestinationPathOptions, type RuntimeFetchExperienceOptions, type RuntimeResolveOptions };
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { resolveExperience as resolveCoreExperience } from "@contentful/experiences-sdk-core";
|
|
2
|
-
import EventBuilder from "./event-builder.js";
|
|
3
|
-
import {
|
|
4
|
-
createRuntimeDeliveryClient
|
|
5
|
-
} from "./create-delivery-client.js";
|
|
6
|
-
import {
|
|
7
|
-
fetchExperience
|
|
8
|
-
} from "./fetch-experience.js";
|
|
9
|
-
import {
|
|
10
|
-
createRuntimeOptimizationClient
|
|
11
|
-
} from "./create-optimization-client.js";
|
|
12
|
-
import { PREVIEW_HOST } from "./hosts.js";
|
|
13
|
-
import { DEFAULT_EVENT_CONTEXT_LIBRARY } from "./sdk-info.js";
|
|
14
|
-
import {
|
|
15
|
-
createRuntimeEventMethods
|
|
16
|
-
} from "./runtime-event-methods.js";
|
|
17
|
-
class ContentfulExperiences {
|
|
18
|
-
spaceId;
|
|
19
|
-
environmentId;
|
|
20
|
-
eventBuilder;
|
|
21
|
-
#locale;
|
|
22
|
-
#resolverConfig;
|
|
23
|
-
#deliveryClient;
|
|
24
|
-
#previewClient;
|
|
25
|
-
optimizationApi;
|
|
26
|
-
#resolveDefaults;
|
|
27
|
-
constructor(config) {
|
|
28
|
-
this.spaceId = config.spaceId;
|
|
29
|
-
this.environmentId = config.environmentId;
|
|
30
|
-
this.#locale = config.locale;
|
|
31
|
-
this.#resolverConfig = config.resolverConfig;
|
|
32
|
-
this.#deliveryClient = createRuntimeDeliveryClient(config.delivery);
|
|
33
|
-
this.#previewClient = config.preview === void 0 ? void 0 : createRuntimeDeliveryClient(config.preview, PREVIEW_HOST);
|
|
34
|
-
this.optimizationApi = createRuntimeOptimizationClient({
|
|
35
|
-
spaceId: config.spaceId,
|
|
36
|
-
environmentId: config.environmentId,
|
|
37
|
-
...config.optimization
|
|
38
|
-
});
|
|
39
|
-
this.#resolveDefaults = config.resolveDefaults ?? {};
|
|
40
|
-
this.eventBuilder = new EventBuilder({
|
|
41
|
-
...config.eventBuilder,
|
|
42
|
-
library: { ...DEFAULT_EVENT_CONTEXT_LIBRARY, ...config.eventBuilder.library },
|
|
43
|
-
getLocale: config.eventBuilder.getLocale ?? (() => this.locale)
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
get locale() {
|
|
47
|
-
return this.#locale;
|
|
48
|
-
}
|
|
49
|
-
createEventMethods(bindings, dispatch) {
|
|
50
|
-
return createRuntimeEventMethods(this.optimizationApi, this.eventBuilder, bindings, dispatch);
|
|
51
|
-
}
|
|
52
|
-
resolveExperience(payload, resolveOptions) {
|
|
53
|
-
return resolveCoreExperience(
|
|
54
|
-
payload,
|
|
55
|
-
this.#resolverConfig,
|
|
56
|
-
this.#mergeResolveOptions(resolveOptions)
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
fetchExperience(options, resolveOptions) {
|
|
60
|
-
if (options.preview === true && this.#previewClient === void 0) {
|
|
61
|
-
throw new Error(
|
|
62
|
-
"fetchExperience() called with preview: true but this runtime has no preview client"
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
return fetchExperience(
|
|
66
|
-
{
|
|
67
|
-
spaceId: this.spaceId,
|
|
68
|
-
environmentId: this.environmentId,
|
|
69
|
-
experienceId: options.experienceId,
|
|
70
|
-
locale: options.locale ?? this.locale,
|
|
71
|
-
personalization: options.personalization,
|
|
72
|
-
extensions: options.extensions
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
client: options.preview ? this.#previewClient : this.#deliveryClient
|
|
76
|
-
},
|
|
77
|
-
{ config: this.#resolverConfig, ...this.#mergeResolveOptions(resolveOptions) }
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
fetchByDestinationNode(options, resolveOptions) {
|
|
81
|
-
return fetchExperience(
|
|
82
|
-
{ spaceId: this.spaceId, destinationId: options.destinationId, nodeId: options.nodeId },
|
|
83
|
-
{ client: this.#deliveryClient },
|
|
84
|
-
{ config: this.#resolverConfig, ...this.#mergeResolveOptions(resolveOptions) }
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
fetchByDestinationPath(options, resolveOptions) {
|
|
88
|
-
return fetchExperience(
|
|
89
|
-
{ spaceId: this.spaceId, destinationId: options.destinationId, path: options.path },
|
|
90
|
-
{ client: this.#deliveryClient },
|
|
91
|
-
{ config: this.#resolverConfig, ...this.#mergeResolveOptions(resolveOptions) }
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
#mergeResolveOptions(options) {
|
|
95
|
-
return {
|
|
96
|
-
metadata: { ...this.#resolveDefaults.metadata, ...options?.metadata },
|
|
97
|
-
debug: options?.debug ?? this.#resolveDefaults.debug
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
export {
|
|
102
|
-
ContentfulExperiences
|
|
103
|
-
};
|
|
104
|
-
//# sourceMappingURL=contentful-experiences.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/contentful-experiences.ts"],"sourcesContent":["import type { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';\nimport { resolveExperience as resolveCoreExperience } from '@contentful/experiences-sdk-core';\nimport type {\n ExperiencePayload,\n PortableRenderPlan,\n ResolverConfig,\n} from '@contentful/experiences-sdk-core';\nimport EventBuilder from './event-builder.js';\nimport type { EventBuilderConfig } from './event-builder.js';\nimport {\n createRuntimeDeliveryClient,\n type RuntimeDeliveryClientOptions,\n} from './create-delivery-client.js';\nimport {\n fetchExperience,\n type DestinationRedirectResult,\n type ExperienceRequestExtensions,\n type PersonalizationOptions,\n} from './fetch-experience.js';\nimport {\n createRuntimeOptimizationClient,\n type RuntimeOptimizationConfig,\n} from './create-optimization-client.js';\nimport { PREVIEW_HOST } from './hosts.js';\nimport { DEFAULT_EVENT_CONTEXT_LIBRARY } from './sdk-info.js';\nimport {\n createRuntimeEventMethods,\n type RuntimeEventBindings,\n type RuntimeEventDispatch,\n type RuntimeEventMethods,\n type RuntimeOptimizationApiClient,\n} from './runtime-event-methods.js';\n\nexport type RuntimeResolveOptions = {\n metadata?: Record<string, unknown>;\n debug?: boolean;\n};\n\nexport type RuntimeEventBuilderConfig = Omit<EventBuilderConfig, 'channel' | 'library'> & {\n channel: EventBuilderConfig['channel'];\n library?: Partial<EventBuilderConfig['library']>;\n};\n\nexport type RuntimeFetchExperienceOptions = {\n experienceId: string;\n locale?: string;\n personalization?: PersonalizationOptions;\n extensions?: ExperienceRequestExtensions;\n preview?: boolean;\n};\n\nexport type RuntimeFetchByDestinationNodeOptions = {\n destinationId: string;\n nodeId: string;\n};\n\nexport type RuntimeFetchByDestinationPathOptions = {\n destinationId: string;\n path: string;\n};\n\n/** Structural contract implemented by the Client runtime. */\nexport interface ExperienceRuntime {\n readonly spaceId: string;\n readonly environmentId: string;\n readonly locale: string | undefined;\n readonly eventBuilder: EventBuilder;\n resolveExperience(\n payload: ExperiencePayload,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan>;\n fetchExperience(\n options: RuntimeFetchExperienceOptions,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan>;\n fetchByDestinationNode(\n options: RuntimeFetchByDestinationNodeOptions,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan | DestinationRedirectResult>;\n fetchByDestinationPath(\n options: RuntimeFetchByDestinationPathOptions,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan | DestinationRedirectResult>;\n}\n\nexport type ContentfulExperiencesConfig = {\n spaceId: string;\n environmentId: string;\n locale?: string;\n resolverConfig: ResolverConfig;\n /** Configuration for the runtime-owned Content Delivery API client. */\n delivery: RuntimeDeliveryClientOptions;\n /** Optional configuration for the runtime-owned Content Preview API client. */\n preview?: RuntimeDeliveryClientOptions;\n /** Overrides for the runtime-owned Personalization and Analytics event transport. */\n optimization?: RuntimeOptimizationConfig;\n resolveDefaults?: Pick<RuntimeResolveOptions, 'metadata' | 'debug'>;\n eventBuilder: RuntimeEventBuilderConfig;\n};\n\nexport class ContentfulExperiences implements ExperienceRuntime {\n readonly spaceId: string;\n readonly environmentId: string;\n readonly eventBuilder: EventBuilder;\n\n readonly #locale: string | undefined;\n readonly #resolverConfig: ResolverConfig;\n readonly #deliveryClient: ContentfulViewDeliveryClient;\n readonly #previewClient: ContentfulViewDeliveryClient | undefined;\n protected readonly optimizationApi: RuntimeOptimizationApiClient;\n readonly #resolveDefaults: Pick<RuntimeResolveOptions, 'metadata' | 'debug'>;\n\n constructor(config: ContentfulExperiencesConfig) {\n this.spaceId = config.spaceId;\n this.environmentId = config.environmentId;\n this.#locale = config.locale;\n this.#resolverConfig = config.resolverConfig;\n this.#deliveryClient = createRuntimeDeliveryClient(config.delivery);\n this.#previewClient =\n config.preview === undefined\n ? undefined\n : createRuntimeDeliveryClient(config.preview, PREVIEW_HOST);\n this.optimizationApi = createRuntimeOptimizationClient({\n spaceId: config.spaceId,\n environmentId: config.environmentId,\n ...config.optimization,\n });\n this.#resolveDefaults = config.resolveDefaults ?? {};\n\n this.eventBuilder = new EventBuilder({\n ...config.eventBuilder,\n library: { ...DEFAULT_EVENT_CONTEXT_LIBRARY, ...config.eventBuilder.library },\n getLocale: config.eventBuilder.getLocale ?? (() => this.locale),\n });\n }\n\n get locale(): string | undefined {\n return this.#locale;\n }\n\n protected createEventMethods(\n bindings: RuntimeEventBindings,\n dispatch?: RuntimeEventDispatch\n ): RuntimeEventMethods {\n return createRuntimeEventMethods(this.optimizationApi, this.eventBuilder, bindings, dispatch);\n }\n\n resolveExperience(\n payload: ExperiencePayload,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan> {\n return resolveCoreExperience(\n payload,\n this.#resolverConfig,\n this.#mergeResolveOptions(resolveOptions)\n );\n }\n\n fetchExperience(\n options: RuntimeFetchExperienceOptions,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan> {\n if (options.preview === true && this.#previewClient === undefined) {\n throw new Error(\n 'fetchExperience() called with preview: true but this runtime has no preview client'\n );\n }\n return fetchExperience(\n {\n spaceId: this.spaceId,\n environmentId: this.environmentId,\n experienceId: options.experienceId,\n locale: options.locale ?? this.locale,\n personalization: options.personalization,\n extensions: options.extensions,\n },\n {\n client: options.preview\n ? (this.#previewClient as ContentfulViewDeliveryClient)\n : this.#deliveryClient,\n },\n { config: this.#resolverConfig, ...this.#mergeResolveOptions(resolveOptions) }\n );\n }\n\n fetchByDestinationNode(\n options: RuntimeFetchByDestinationNodeOptions,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan | DestinationRedirectResult> {\n return fetchExperience(\n { spaceId: this.spaceId, destinationId: options.destinationId, nodeId: options.nodeId },\n { client: this.#deliveryClient },\n { config: this.#resolverConfig, ...this.#mergeResolveOptions(resolveOptions) }\n );\n }\n\n fetchByDestinationPath(\n options: RuntimeFetchByDestinationPathOptions,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan | DestinationRedirectResult> {\n return fetchExperience(\n { spaceId: this.spaceId, destinationId: options.destinationId, path: options.path },\n { client: this.#deliveryClient },\n { config: this.#resolverConfig, ...this.#mergeResolveOptions(resolveOptions) }\n );\n }\n\n #mergeResolveOptions(options: RuntimeResolveOptions | undefined): RuntimeResolveOptions {\n return {\n metadata: { ...this.#resolveDefaults.metadata, ...options?.metadata },\n debug: options?.debug ?? this.#resolveDefaults.debug,\n };\n }\n}\n"],"mappings":"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","names":[]}
|
|
@@ -1,20 +0,0 @@
|
|
|
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 };
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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":[]}
|