@contentful/experiences-client 0.8.0 → 0.9.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 +144 -0
- 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/contentful-experiences.d.ts +1 -1
- package/dist/contentful-experiences.js +1 -2
- package/dist/contentful-experiences.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 -31
- package/dist/fetch-experience.js +14 -32
- package/dist/fetch-experience.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/sdk-info.js +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,147 @@
|
|
|
1
|
+
## 0.9.1 (2026-10-08)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- add fetchDestinationSitemap for paginated route listing [AIS-569] ([#218](https://github.com/contentful/experiences/pull/218))
|
|
6
|
+
|
|
7
|
+
## 0.9.0 (2026-10-08)
|
|
8
|
+
|
|
9
|
+
### 🚀 Features
|
|
10
|
+
|
|
11
|
+
- ⚠️ remove sdk viewport surface [SPA-5275] ([#220](https://github.com/contentful/experiences/pull/220))
|
|
12
|
+
|
|
13
|
+
### ⚠️ Breaking Changes
|
|
14
|
+
|
|
15
|
+
- remove sdk viewport surface [SPA-5275] ([#220](https://github.com/contentful/experiences/pull/220))
|
|
16
|
+
The SDK no longer exposes viewport definitions, viewport-aware design-value resolution, or active-viewport hooks. Use CSS media queries or application-owned matchMedia integration for responsive behavior. Delivered design property values are now flat and require no migration."
|
|
17
|
+
M AGENTS.md
|
|
18
|
+
M ARCHITECTURE.md
|
|
19
|
+
M CONTRIBUTING.md
|
|
20
|
+
M README.md
|
|
21
|
+
M catalog-info.yaml
|
|
22
|
+
M examples/angular/README.md
|
|
23
|
+
M examples/angular/src/app/components/heading.component.ts
|
|
24
|
+
D examples/angular/src/app/lib/detect-viewport.ts
|
|
25
|
+
M examples/angular/src/app/lib/experience-config.ts
|
|
26
|
+
M examples/angular/src/app/lib/experience-route-data.ts
|
|
27
|
+
M examples/angular/src/app/pages/experience-page.component.ts
|
|
28
|
+
M examples/angular/src/server.ts
|
|
29
|
+
M examples/nextjs/README.md
|
|
30
|
+
M examples/nextjs/app/[slug]/page.tsx
|
|
31
|
+
M examples/nextjs/components/Heading.tsx
|
|
32
|
+
M examples/nextjs/components/LivePreviewExperience.tsx
|
|
33
|
+
M examples/nextjs/components/Section.tsx
|
|
34
|
+
D examples/nextjs/lib/detect-viewport.ts
|
|
35
|
+
M examples/nextjs/lib/experience-config.tsx
|
|
36
|
+
M examples/scripts/bootstrap-example.ts
|
|
37
|
+
M examples/scripts/fixture/experience.ts
|
|
38
|
+
M examples/scripts/fixture/types.ts
|
|
39
|
+
M examples/sveltekit/README.md
|
|
40
|
+
M examples/sveltekit/src/lib/components/Heading.svelte
|
|
41
|
+
D examples/sveltekit/src/lib/detect-viewport.ts
|
|
42
|
+
M examples/sveltekit/src/lib/experience-config.ts
|
|
43
|
+
M examples/sveltekit/src/routes/[slug]/+page.server.ts
|
|
44
|
+
M examples/sveltekit/src/routes/[slug]/+page.svelte
|
|
45
|
+
M examples/sveltekit/vite.config.ts
|
|
46
|
+
M package-lock.json
|
|
47
|
+
M packages/adapter-angular/README.md
|
|
48
|
+
M packages/adapter-angular/src/client-experience-renderer.component.ts
|
|
49
|
+
M packages/adapter-angular/src/context.ts
|
|
50
|
+
M packages/adapter-angular/src/debug-experience.test.ts
|
|
51
|
+
M packages/adapter-angular/src/debug-panel-coverage.ssr.test.ts
|
|
52
|
+
M packages/adapter-angular/src/debug-panel-coverage.test.ts
|
|
53
|
+
M packages/adapter-angular/src/dom-parity.test.ts
|
|
54
|
+
M packages/adapter-angular/src/experience-defaults.ts
|
|
55
|
+
M packages/adapter-angular/src/experience-scope.ts
|
|
56
|
+
M packages/adapter-angular/src/index.ts
|
|
57
|
+
D packages/adapter-angular/src/inject-active-viewport.ts
|
|
58
|
+
M packages/adapter-angular/src/inject-design-values.ts
|
|
59
|
+
M packages/adapter-angular/src/inject-experience-plan.ts
|
|
60
|
+
M packages/adapter-angular/src/live-preview-experience.ssr.test.ts
|
|
61
|
+
M packages/adapter-angular/src/live-preview-experience.test.ts
|
|
62
|
+
M packages/adapter-angular/src/node-render-engine.test.ts
|
|
63
|
+
M packages/adapter-angular/src/node-render-engine.ts
|
|
64
|
+
M packages/adapter-angular/src/node-scopes.ts
|
|
65
|
+
M packages/adapter-angular/src/nodes-renderer.ssr.test.ts
|
|
66
|
+
M packages/adapter-angular/src/server-experience-renderer.component.ts
|
|
67
|
+
M packages/adapter-angular/src/server-renderer.test.ts
|
|
68
|
+
M packages/adapter-angular/src/test-fixtures/render-harness.ts
|
|
69
|
+
M packages/adapter-angular/src/types.ts
|
|
70
|
+
M packages/adapter-react/README.md
|
|
71
|
+
M packages/adapter-react/src/client-renderer.tsx
|
|
72
|
+
M packages/adapter-react/src/context.tsx
|
|
73
|
+
M packages/adapter-react/src/debug-experience.test.tsx
|
|
74
|
+
M packages/adapter-react/src/debug-experience.tsx
|
|
75
|
+
M packages/adapter-react/src/debug-panel-coverage.test.tsx
|
|
76
|
+
M packages/adapter-react/src/index.ts
|
|
77
|
+
M packages/adapter-react/src/nodes-renderer.ssr.test.tsx
|
|
78
|
+
M packages/adapter-react/src/nodes-renderer.test.tsx
|
|
79
|
+
M packages/adapter-react/src/nodes-renderer.tsx
|
|
80
|
+
M packages/adapter-react/src/server-renderer.test.tsx
|
|
81
|
+
M packages/adapter-react/src/server-renderer.tsx
|
|
82
|
+
M packages/adapter-react/src/types.ts
|
|
83
|
+
D packages/adapter-react/src/use-active-viewport.ts
|
|
84
|
+
M packages/adapter-react/src/use-design-values.tsx
|
|
85
|
+
M packages/adapter-react/src/use-experience-plan.test.tsx
|
|
86
|
+
M packages/adapter-react/src/use-experience-plan.ts
|
|
87
|
+
M packages/adapter-react/src/use-live-preview-experience.test.tsx
|
|
88
|
+
M packages/adapter-react/src/use-live-preview.test.tsx
|
|
89
|
+
M packages/adapter-svelte/README.md
|
|
90
|
+
M packages/adapter-svelte/src/ClientExperienceRenderer.svelte
|
|
91
|
+
M packages/adapter-svelte/src/DebugExperience.svelte
|
|
92
|
+
M packages/adapter-svelte/src/DebugExperience.test.ts
|
|
93
|
+
M packages/adapter-svelte/src/NodeRenderer.svelte
|
|
94
|
+
M packages/adapter-svelte/src/NodeRenderer.test.ts
|
|
95
|
+
M packages/adapter-svelte/src/NodesRenderer.svelte
|
|
96
|
+
M packages/adapter-svelte/src/ServerExperienceRenderer.svelte
|
|
97
|
+
M packages/adapter-svelte/src/component-props.ts
|
|
98
|
+
M packages/adapter-svelte/src/context.ts
|
|
99
|
+
M packages/adapter-svelte/src/debug-panel-coverage.ssr.test.ts
|
|
100
|
+
M packages/adapter-svelte/src/debug-panel-coverage.test.ts
|
|
101
|
+
M packages/adapter-svelte/src/get-design-values.ts
|
|
102
|
+
M packages/adapter-svelte/src/index.ts
|
|
103
|
+
M packages/adapter-svelte/src/nodes-renderer.ssr.test.ts
|
|
104
|
+
M packages/adapter-svelte/src/server-renderer.test.ts
|
|
105
|
+
M packages/adapter-svelte/src/types.ts
|
|
106
|
+
D packages/adapter-svelte/src/use-active-viewport.svelte.ts
|
|
107
|
+
M packages/adapter-svelte/src/use-experience-plan.test.ts
|
|
108
|
+
M packages/adapter-svelte/src/use-live-preview-experience.test.ts
|
|
109
|
+
M packages/adapter-svelte/src/use-live-preview.test.ts
|
|
110
|
+
M packages/client/src/contentful-experiences.test.ts
|
|
111
|
+
M packages/client/src/contentful-experiences.ts
|
|
112
|
+
M packages/client/src/fetch-experience.test.ts
|
|
113
|
+
M packages/client/src/fetch-experience.ts
|
|
114
|
+
M packages/core/README.md
|
|
115
|
+
A packages/core/src/design-properties.test.ts
|
|
116
|
+
A packages/core/src/design-properties.ts
|
|
117
|
+
M packages/core/src/index.ts
|
|
118
|
+
M packages/core/src/resolve-experience.test.ts
|
|
119
|
+
M packages/core/src/resolve-experience.ts
|
|
120
|
+
M packages/core/src/types.ts
|
|
121
|
+
D packages/core/src/viewport.test.ts
|
|
122
|
+
D packages/core/src/viewport.ts
|
|
123
|
+
M packages/design/README.md
|
|
124
|
+
M packages/design/package.json
|
|
125
|
+
M packages/design/src/index.ts
|
|
126
|
+
D packages/design/src/media-query-matchers.ts
|
|
127
|
+
D packages/design/src/select-resolved-design.ts
|
|
128
|
+
D packages/design/src/viewport.test.ts
|
|
129
|
+
D packages/design/src/viewport.ts
|
|
130
|
+
M packages/live-preview/README.md
|
|
131
|
+
M packages/live-preview/src/experience-payload.ts
|
|
132
|
+
M packages/live-preview/src/fetch-preview-session.test.ts
|
|
133
|
+
M packages/live-preview/src/fetch-preview-session.ts
|
|
134
|
+
M packages/live-preview/src/live-preview-client.test.ts
|
|
135
|
+
M packages/node/README.md
|
|
136
|
+
M packages/node/src/contentful-experiences.test.ts
|
|
137
|
+
M packages/node/src/contentful-experiences.ts
|
|
138
|
+
M packages/web/README.md
|
|
139
|
+
M packages/web/src/contentful-experiences.test.ts
|
|
140
|
+
|
|
141
|
+
### 🧱 Updated Dependencies
|
|
142
|
+
|
|
143
|
+
- Updated core to 0.12.0
|
|
144
|
+
|
|
1
145
|
## 0.8.0 (2026-10-06)
|
|
2
146
|
|
|
3
147
|
### 🧱 Updated Dependencies
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';
|
|
2
|
+
import { createDebugLogger } from '@contentful/experiences-sdk-core';
|
|
3
|
+
|
|
4
|
+
type ClientOptions = {
|
|
5
|
+
accessToken: string;
|
|
6
|
+
/**
|
|
7
|
+
* Preview access token. Required when calling with `preview: true`.
|
|
8
|
+
*/
|
|
9
|
+
previewToken?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Flip between delivery (default) and preview at request time. When
|
|
12
|
+
* `true`, uses `previewToken` and the preview host; when `false` or
|
|
13
|
+
* unset, uses `accessToken` and the delivery host. Ignored when a
|
|
14
|
+
* pre-made `client` is passed instead of inline creds.
|
|
15
|
+
*/
|
|
16
|
+
preview?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Custom base URL for the delivery client (staging, proxy, per-region).
|
|
19
|
+
* Wins over the `preview`-derived default host — combine `host` with
|
|
20
|
+
* `preview: true` to point preview mode at a non-prod endpoint.
|
|
21
|
+
* Omit for the standard delivery / preview hosts.
|
|
22
|
+
*/
|
|
23
|
+
host?: string;
|
|
24
|
+
} | {
|
|
25
|
+
client: ContentfulViewDeliveryClient;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Resolve a `ClientOptions` union into a real delivery client. Shared by
|
|
29
|
+
* `fetchExperience` and `fetchDestinationSitemap` — both accept the same
|
|
30
|
+
* inline-creds-or-pre-made-client shape.
|
|
31
|
+
*/
|
|
32
|
+
declare function resolveDeliveryClient(clientOptions: ClientOptions, log: ReturnType<typeof createDebugLogger>, callerName: string): ContentfulViewDeliveryClient;
|
|
33
|
+
|
|
34
|
+
export { type ClientOptions, resolveDeliveryClient };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createClient } from "./create-delivery-client.js";
|
|
2
|
+
import { PREVIEW_HOST } from "./hosts.js";
|
|
3
|
+
function resolveDeliveryClient(clientOptions, log, callerName) {
|
|
4
|
+
if ("client" in clientOptions) {
|
|
5
|
+
log.log("using caller-supplied delivery client");
|
|
6
|
+
return clientOptions.client;
|
|
7
|
+
}
|
|
8
|
+
const { accessToken, previewToken, preview, host } = clientOptions;
|
|
9
|
+
if (preview && !previewToken) {
|
|
10
|
+
throw new Error(`${callerName}() called with preview: true but no previewToken was provided`);
|
|
11
|
+
}
|
|
12
|
+
const resolvedHost = host ?? (preview ? PREVIEW_HOST : void 0);
|
|
13
|
+
const client = createClient({
|
|
14
|
+
accessToken: preview ? previewToken : accessToken,
|
|
15
|
+
host: resolvedHost
|
|
16
|
+
});
|
|
17
|
+
log.log("created delivery client", { preview: Boolean(preview), host: resolvedHost });
|
|
18
|
+
return client;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
resolveDeliveryClient
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=client-resolution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client-resolution.ts"],"sourcesContent":["import type { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';\nimport { createClient } from './create-delivery-client.js';\nimport { createDebugLogger } from '@contentful/experiences-sdk-core';\nimport { PREVIEW_HOST } from './hosts.js';\n\nexport type ClientOptions =\n | {\n accessToken: string;\n /**\n * Preview access token. Required when calling with `preview: true`.\n */\n previewToken?: string;\n /**\n * Flip between delivery (default) and preview at request time. When\n * `true`, uses `previewToken` and the preview host; when `false` or\n * unset, uses `accessToken` and the delivery host. Ignored when a\n * pre-made `client` is passed instead of inline creds.\n */\n preview?: boolean;\n /**\n * Custom base URL for the delivery client (staging, proxy, per-region).\n * Wins over the `preview`-derived default host — combine `host` with\n * `preview: true` to point preview mode at a non-prod endpoint.\n * Omit for the standard delivery / preview hosts.\n */\n host?: string;\n }\n | { client: ContentfulViewDeliveryClient };\n\n/**\n * Resolve a `ClientOptions` union into a real delivery client. Shared by\n * `fetchExperience` and `fetchDestinationSitemap` — both accept the same\n * inline-creds-or-pre-made-client shape.\n */\nexport function resolveDeliveryClient(\n clientOptions: ClientOptions,\n log: ReturnType<typeof createDebugLogger>,\n callerName: string\n): ContentfulViewDeliveryClient {\n if ('client' in clientOptions) {\n log.log('using caller-supplied delivery client');\n return clientOptions.client;\n }\n\n const { accessToken, previewToken, preview, host } = clientOptions;\n if (preview && !previewToken) {\n throw new Error(`${callerName}() called with preview: true but no previewToken was provided`);\n }\n const resolvedHost = host ?? (preview ? PREVIEW_HOST : undefined);\n const client = createClient({\n accessToken: preview ? (previewToken as string) : accessToken,\n host: resolvedHost,\n });\n log.log('created delivery client', { preview: Boolean(preview), host: resolvedHost });\n return client;\n}\n"],"mappings":"AACA,SAAS,oBAAoB;AAE7B,SAAS,oBAAoB;AA+BtB,SAAS,sBACd,eACA,KACA,YAC8B;AAC9B,MAAI,YAAY,eAAe;AAC7B,QAAI,IAAI,uCAAuC;AAC/C,WAAO,cAAc;AAAA,EACvB;AAEA,QAAM,EAAE,aAAa,cAAc,SAAS,KAAK,IAAI;AACrD,MAAI,WAAW,CAAC,cAAc;AAC5B,UAAM,IAAI,MAAM,GAAG,UAAU,+DAA+D;AAAA,EAC9F;AACA,QAAM,eAAe,SAAS,UAAU,eAAe;AACvD,QAAM,SAAS,aAAa;AAAA,IAC1B,aAAa,UAAW,eAA0B;AAAA,IAClD,MAAM;AAAA,EACR,CAAC;AACD,MAAI,IAAI,2BAA2B,EAAE,SAAS,QAAQ,OAAO,GAAG,MAAM,aAAa,CAAC;AACpF,SAAO;AACT;","names":[]}
|
|
@@ -7,12 +7,12 @@ import { RuntimeOptimizationApiClient, RuntimeEventBindings, RuntimeEventDispatc
|
|
|
7
7
|
import '@contentful/optimization-api-client/api-schemas';
|
|
8
8
|
import 'zod/mini';
|
|
9
9
|
import '@contentful/experience-delivery';
|
|
10
|
+
import './client-resolution.js';
|
|
10
11
|
import '@contentful/optimization-api-client';
|
|
11
12
|
|
|
12
13
|
type RuntimeResolveOptions = {
|
|
13
14
|
metadata?: Record<string, unknown>;
|
|
14
15
|
debug?: boolean;
|
|
15
|
-
initialViewportId?: string;
|
|
16
16
|
};
|
|
17
17
|
type RuntimeEventBuilderConfig = Omit<EventBuilderConfig, 'channel' | 'library'> & {
|
|
18
18
|
channel: EventBuilderConfig['channel'];
|
|
@@ -94,8 +94,7 @@ class ContentfulExperiences {
|
|
|
94
94
|
#mergeResolveOptions(options) {
|
|
95
95
|
return {
|
|
96
96
|
metadata: { ...this.#resolveDefaults.metadata, ...options?.metadata },
|
|
97
|
-
debug: options?.debug ?? this.#resolveDefaults.debug
|
|
98
|
-
initialViewportId: options?.initialViewportId
|
|
97
|
+
debug: options?.debug ?? this.#resolveDefaults.debug
|
|
99
98
|
};
|
|
100
99
|
}
|
|
101
100
|
}
|
|
@@ -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 {\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
|
|
1
|
+
{"version":3,"sources":["../src/contentful-experiences.ts"],"sourcesContent":["import type { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';\nimport { resolveExperience as resolveCoreExperience } from '@contentful/experiences-sdk-core';\nimport type {\n ExperiencePayload,\n PortableRenderPlan,\n ResolverConfig,\n} from '@contentful/experiences-sdk-core';\nimport EventBuilder from './event-builder.js';\nimport type { EventBuilderConfig } from './event-builder.js';\nimport {\n createRuntimeDeliveryClient,\n type RuntimeDeliveryClientOptions,\n} from './create-delivery-client.js';\nimport {\n fetchExperience,\n type DestinationRedirectResult,\n type ExperienceRequestExtensions,\n type PersonalizationOptions,\n} from './fetch-experience.js';\nimport {\n createRuntimeOptimizationClient,\n type RuntimeOptimizationConfig,\n} from './create-optimization-client.js';\nimport { PREVIEW_HOST } from './hosts.js';\nimport { DEFAULT_EVENT_CONTEXT_LIBRARY } from './sdk-info.js';\nimport {\n createRuntimeEventMethods,\n type RuntimeEventBindings,\n type RuntimeEventDispatch,\n type RuntimeEventMethods,\n type RuntimeOptimizationApiClient,\n} from './runtime-event-methods.js';\n\nexport type RuntimeResolveOptions = {\n metadata?: Record<string, unknown>;\n debug?: boolean;\n};\n\nexport type RuntimeEventBuilderConfig = Omit<EventBuilderConfig, 'channel' | 'library'> & {\n channel: EventBuilderConfig['channel'];\n library?: Partial<EventBuilderConfig['library']>;\n};\n\nexport type RuntimeFetchExperienceOptions = {\n experienceId: string;\n locale?: string;\n personalization?: PersonalizationOptions;\n extensions?: ExperienceRequestExtensions;\n preview?: boolean;\n};\n\nexport type RuntimeFetchByDestinationNodeOptions = {\n destinationId: string;\n nodeId: string;\n};\n\nexport type RuntimeFetchByDestinationPathOptions = {\n destinationId: string;\n path: string;\n};\n\n/** Structural contract implemented by the Client runtime. */\nexport interface ExperienceRuntime {\n readonly spaceId: string;\n readonly environmentId: string;\n readonly locale: string | undefined;\n readonly eventBuilder: EventBuilder;\n resolveExperience(\n payload: ExperiencePayload,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan>;\n fetchExperience(\n options: RuntimeFetchExperienceOptions,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan>;\n fetchByDestinationNode(\n options: RuntimeFetchByDestinationNodeOptions,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan | DestinationRedirectResult>;\n fetchByDestinationPath(\n options: RuntimeFetchByDestinationPathOptions,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan | DestinationRedirectResult>;\n}\n\nexport type ContentfulExperiencesConfig = {\n spaceId: string;\n environmentId: string;\n locale?: string;\n resolverConfig: ResolverConfig;\n /** Configuration for the runtime-owned Content Delivery API client. */\n delivery: RuntimeDeliveryClientOptions;\n /** Optional configuration for the runtime-owned Content Preview API client. */\n preview?: RuntimeDeliveryClientOptions;\n /** Overrides for the runtime-owned Personalization and Analytics event transport. */\n optimization?: RuntimeOptimizationConfig;\n resolveDefaults?: Pick<RuntimeResolveOptions, 'metadata' | 'debug'>;\n eventBuilder: RuntimeEventBuilderConfig;\n};\n\nexport class ContentfulExperiences implements ExperienceRuntime {\n readonly spaceId: string;\n readonly environmentId: string;\n readonly eventBuilder: EventBuilder;\n\n readonly #locale: string | undefined;\n readonly #resolverConfig: ResolverConfig;\n readonly #deliveryClient: ContentfulViewDeliveryClient;\n readonly #previewClient: ContentfulViewDeliveryClient | undefined;\n protected readonly optimizationApi: RuntimeOptimizationApiClient;\n readonly #resolveDefaults: Pick<RuntimeResolveOptions, 'metadata' | 'debug'>;\n\n constructor(config: ContentfulExperiencesConfig) {\n this.spaceId = config.spaceId;\n this.environmentId = config.environmentId;\n this.#locale = config.locale;\n this.#resolverConfig = config.resolverConfig;\n this.#deliveryClient = createRuntimeDeliveryClient(config.delivery);\n this.#previewClient =\n config.preview === undefined\n ? undefined\n : createRuntimeDeliveryClient(config.preview, PREVIEW_HOST);\n this.optimizationApi = createRuntimeOptimizationClient({\n spaceId: config.spaceId,\n environmentId: config.environmentId,\n ...config.optimization,\n });\n this.#resolveDefaults = config.resolveDefaults ?? {};\n\n this.eventBuilder = new EventBuilder({\n ...config.eventBuilder,\n library: { ...DEFAULT_EVENT_CONTEXT_LIBRARY, ...config.eventBuilder.library },\n getLocale: config.eventBuilder.getLocale ?? (() => this.locale),\n });\n }\n\n get locale(): string | undefined {\n return this.#locale;\n }\n\n protected createEventMethods(\n bindings: RuntimeEventBindings,\n dispatch?: RuntimeEventDispatch\n ): RuntimeEventMethods {\n return createRuntimeEventMethods(this.optimizationApi, this.eventBuilder, bindings, dispatch);\n }\n\n resolveExperience(\n payload: ExperiencePayload,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan> {\n return resolveCoreExperience(\n payload,\n this.#resolverConfig,\n this.#mergeResolveOptions(resolveOptions)\n );\n }\n\n fetchExperience(\n options: RuntimeFetchExperienceOptions,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan> {\n if (options.preview === true && this.#previewClient === undefined) {\n throw new Error(\n 'fetchExperience() called with preview: true but this runtime has no preview client'\n );\n }\n return fetchExperience(\n {\n spaceId: this.spaceId,\n environmentId: this.environmentId,\n experienceId: options.experienceId,\n locale: options.locale ?? this.locale,\n personalization: options.personalization,\n extensions: options.extensions,\n },\n {\n client: options.preview\n ? (this.#previewClient as ContentfulViewDeliveryClient)\n : this.#deliveryClient,\n },\n { config: this.#resolverConfig, ...this.#mergeResolveOptions(resolveOptions) }\n );\n }\n\n fetchByDestinationNode(\n options: RuntimeFetchByDestinationNodeOptions,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan | DestinationRedirectResult> {\n return fetchExperience(\n { spaceId: this.spaceId, destinationId: options.destinationId, nodeId: options.nodeId },\n { client: this.#deliveryClient },\n { config: this.#resolverConfig, ...this.#mergeResolveOptions(resolveOptions) }\n );\n }\n\n fetchByDestinationPath(\n options: RuntimeFetchByDestinationPathOptions,\n resolveOptions?: RuntimeResolveOptions\n ): Promise<PortableRenderPlan | DestinationRedirectResult> {\n return fetchExperience(\n { spaceId: this.spaceId, destinationId: options.destinationId, path: options.path },\n { client: this.#deliveryClient },\n { config: this.#resolverConfig, ...this.#mergeResolveOptions(resolveOptions) }\n );\n }\n\n #mergeResolveOptions(options: RuntimeResolveOptions | undefined): RuntimeResolveOptions {\n return {\n metadata: { ...this.#resolveDefaults.metadata, ...options?.metadata },\n debug: options?.debug ?? this.#resolveDefaults.debug,\n };\n }\n}\n"],"mappings":"AACA,SAAS,qBAAqB,6BAA6B;AAM3D,OAAO,kBAAkB;AAEzB;AAAA,EACE;AAAA,OAEK;AACP;AAAA,EACE;AAAA,OAIK;AACP;AAAA,EACE;AAAA,OAEK;AACP,SAAS,oBAAoB;AAC7B,SAAS,qCAAqC;AAC9C;AAAA,EACE;AAAA,OAKK;AAqEA,MAAM,sBAAmD;AAAA,EACrD;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACU;AAAA,EACV;AAAA,EAET,YAAY,QAAqC;AAC/C,SAAK,UAAU,OAAO;AACtB,SAAK,gBAAgB,OAAO;AAC5B,SAAK,UAAU,OAAO;AACtB,SAAK,kBAAkB,OAAO;AAC9B,SAAK,kBAAkB,4BAA4B,OAAO,QAAQ;AAClE,SAAK,iBACH,OAAO,YAAY,SACf,SACA,4BAA4B,OAAO,SAAS,YAAY;AAC9D,SAAK,kBAAkB,gCAAgC;AAAA,MACrD,SAAS,OAAO;AAAA,MAChB,eAAe,OAAO;AAAA,MACtB,GAAG,OAAO;AAAA,IACZ,CAAC;AACD,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,EAEU,mBACR,UACA,UACqB;AACrB,WAAO,0BAA0B,KAAK,iBAAiB,KAAK,cAAc,UAAU,QAAQ;AAAA,EAC9F;AAAA,EAEA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A,MACpE,OAAO,SAAS,SAAS,KAAK,iBAAiB;AAAA,IACjD;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throws `DestinationPreviewNotSupportedError` when `clientOptions.preview` is
|
|
3
|
+
* `true` and `experienceOptions` is destination-shaped (a caller-supplied
|
|
4
|
+
* `{ client }` already ignores `preview` entirely, so this only fires for the
|
|
5
|
+
* inline-credentials branch). Shared by `fetchExperience` and
|
|
6
|
+
* `fetchDestinationSitemap` — both call into the same preview-less
|
|
7
|
+
* Destinations Delivery API.
|
|
8
|
+
*/
|
|
9
|
+
declare function assertDestinationPreviewSupported(isPreview: boolean | undefined, destination: {
|
|
10
|
+
spaceId: string;
|
|
11
|
+
destinationId: string;
|
|
12
|
+
nodeId?: string;
|
|
13
|
+
path?: string;
|
|
14
|
+
}): void;
|
|
15
|
+
|
|
16
|
+
export { assertDestinationPreviewSupported };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DestinationPreviewNotSupportedError } from "./errors.js";
|
|
2
|
+
function assertDestinationPreviewSupported(isPreview, destination) {
|
|
3
|
+
if (!isPreview) return;
|
|
4
|
+
const { spaceId, destinationId, nodeId, path } = destination;
|
|
5
|
+
const locator = nodeId !== void 0 ? `nodeId "${nodeId}"` : `path "${path}"`;
|
|
6
|
+
throw new DestinationPreviewNotSupportedError(
|
|
7
|
+
`preview: true was combined with a destination-shaped call (destinationId "${destinationId}", ${locator}). The Destinations Delivery API does not support preview mode yet \u2014 pass preview: false (or omit it) for destination-based fetches.`,
|
|
8
|
+
{ spaceId, destinationId, nodeId, path }
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
assertDestinationPreviewSupported
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=destination-guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/destination-guards.ts"],"sourcesContent":["import { DestinationPreviewNotSupportedError } from './errors.js';\n\n/**\n * Throws `DestinationPreviewNotSupportedError` when `clientOptions.preview` is\n * `true` and `experienceOptions` is destination-shaped (a caller-supplied\n * `{ client }` already ignores `preview` entirely, so this only fires for the\n * inline-credentials branch). Shared by `fetchExperience` and\n * `fetchDestinationSitemap` — both call into the same preview-less\n * Destinations Delivery API.\n */\nexport function assertDestinationPreviewSupported(\n isPreview: boolean | undefined,\n destination: { spaceId: string; destinationId: string; nodeId?: string; path?: string }\n): void {\n if (!isPreview) return;\n\n const { spaceId, destinationId, nodeId, path } = destination;\n const locator = nodeId !== undefined ? `nodeId \"${nodeId}\"` : `path \"${path}\"`;\n throw new DestinationPreviewNotSupportedError(\n `preview: true was combined with a destination-shaped call (destinationId ` +\n `\"${destinationId}\", ${locator}). The Destinations Delivery API does not support ` +\n `preview mode yet — pass preview: false (or omit it) for destination-based fetches.`,\n { spaceId, destinationId, nodeId, path }\n );\n}\n"],"mappings":"AAAA,SAAS,2CAA2C;AAU7C,SAAS,kCACd,WACA,aACM;AACN,MAAI,CAAC,UAAW;AAEhB,QAAM,EAAE,SAAS,eAAe,QAAQ,KAAK,IAAI;AACjD,QAAM,UAAU,WAAW,SAAY,WAAW,MAAM,MAAM,SAAS,IAAI;AAC3E,QAAM,IAAI;AAAA,IACR,6EACM,aAAa,MAAM,OAAO;AAAA,IAEhC,EAAE,SAAS,eAAe,QAAQ,KAAK;AAAA,EACzC;AACF;","names":[]}
|
package/dist/errors.d.ts
CHANGED
|
@@ -27,11 +27,12 @@ declare class ExperienceFetchError extends Error {
|
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
* Thrown by `fetchExperience`
|
|
31
|
-
* `
|
|
32
|
-
* `destinationId` + `path
|
|
33
|
-
* host or preview-token support yet, so this
|
|
34
|
-
* production host with a preview token
|
|
30
|
+
* Thrown by `fetchExperience` and `fetchDestinationSitemap` when
|
|
31
|
+
* `clientOptions.preview` is `true` for a destination-shaped call
|
|
32
|
+
* (`destinationId` + `nodeId`/`path`, or a sitemap fetch). The Destinations
|
|
33
|
+
* Delivery API has no preview host or preview-token support yet, so this
|
|
34
|
+
* guards against silently hitting the production host with a preview token
|
|
35
|
+
* it doesn't accept.
|
|
35
36
|
*
|
|
36
37
|
* This is a bridge, not a permanent design: revisit once the platform ships
|
|
37
38
|
* preview support for destinations.
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Thrown by `fetchExperience` for a fetch failure that is not \"experience not\n * found\" — network failure, an invalid/expired token, a 5xx from the\n * delivery API, etc. This failure mode is \"surface clearly to the host app,\"\n * unlike the diagnostics `resolveExperience` collects for resolve/render-time\n * issues — there's no partial payload to render around a fetch that never\n * returned one, so a real thrown class is the right shape.\n *\n * `NotFoundError` (the delivery client's class, re-exported from this\n * package) is the one exception: it passes through undisturbed so callers\n * can route it to their framework's 404 idiom, per the existing\n * distinguishable-404 contract.\n *\n * `environmentId` is `undefined` for the destination-shaped `fetchExperience`\n * branches — the destinations delivery endpoints are space-scoped only, with\n * no environment segment, unlike the by-id path.\n */\nexport class ExperienceFetchError extends Error {\n readonly spaceId: string;\n readonly environmentId: string | undefined;\n readonly experienceId: string;\n\n constructor(\n message: string,\n options: {\n spaceId: string;\n environmentId?: string;\n experienceId: string;\n cause?: unknown;\n }\n ) {\n super(message, options.cause !== undefined ? { cause: options.cause } : undefined);\n this.name = 'ExperienceFetchError';\n this.spaceId = options.spaceId;\n this.environmentId = options.environmentId;\n this.experienceId = options.experienceId;\n }\n}\n\n/**\n * Thrown by `fetchExperience` when `clientOptions.preview` is `true`
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Thrown by `fetchExperience` for a fetch failure that is not \"experience not\n * found\" — network failure, an invalid/expired token, a 5xx from the\n * delivery API, etc. This failure mode is \"surface clearly to the host app,\"\n * unlike the diagnostics `resolveExperience` collects for resolve/render-time\n * issues — there's no partial payload to render around a fetch that never\n * returned one, so a real thrown class is the right shape.\n *\n * `NotFoundError` (the delivery client's class, re-exported from this\n * package) is the one exception: it passes through undisturbed so callers\n * can route it to their framework's 404 idiom, per the existing\n * distinguishable-404 contract.\n *\n * `environmentId` is `undefined` for the destination-shaped `fetchExperience`\n * branches — the destinations delivery endpoints are space-scoped only, with\n * no environment segment, unlike the by-id path.\n */\nexport class ExperienceFetchError extends Error {\n readonly spaceId: string;\n readonly environmentId: string | undefined;\n readonly experienceId: string;\n\n constructor(\n message: string,\n options: {\n spaceId: string;\n environmentId?: string;\n experienceId: string;\n cause?: unknown;\n }\n ) {\n super(message, options.cause !== undefined ? { cause: options.cause } : undefined);\n this.name = 'ExperienceFetchError';\n this.spaceId = options.spaceId;\n this.environmentId = options.environmentId;\n this.experienceId = options.experienceId;\n }\n}\n\n/**\n * Thrown by `fetchExperience` and `fetchDestinationSitemap` when\n * `clientOptions.preview` is `true` for a destination-shaped call\n * (`destinationId` + `nodeId`/`path`, or a sitemap fetch). The Destinations\n * Delivery API has no preview host or preview-token support yet, so this\n * guards against silently hitting the production host with a preview token\n * it doesn't accept.\n *\n * This is a bridge, not a permanent design: revisit once the platform ships\n * preview support for destinations.\n *\n * Only fires for the inline-credentials branch of `ClientOptions`. A\n * caller-supplied `{ client }` already ignores `preview` entirely, per that\n * branch's existing contract.\n */\nexport class DestinationPreviewNotSupportedError extends Error {\n readonly spaceId: string;\n readonly destinationId: string;\n readonly nodeId: string | undefined;\n readonly path: string | undefined;\n\n constructor(\n message: string,\n options: { spaceId: string; destinationId: string; nodeId?: string; path?: string }\n ) {\n super(message);\n this.name = 'DestinationPreviewNotSupportedError';\n this.spaceId = options.spaceId;\n this.destinationId = options.destinationId;\n this.nodeId = options.nodeId;\n this.path = options.path;\n }\n}\n"],"mappings":"AAiBO,MAAM,6BAA6B,MAAM;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EAET,YACE,SACA,SAMA;AACA,UAAM,SAAS,QAAQ,UAAU,SAAY,EAAE,OAAO,QAAQ,MAAM,IAAI,MAAS;AACjF,SAAK,OAAO;AACZ,SAAK,UAAU,QAAQ;AACvB,SAAK,gBAAgB,QAAQ;AAC7B,SAAK,eAAe,QAAQ;AAAA,EAC9B;AACF;AAiBO,MAAM,4CAA4C,MAAM;AAAA,EACpD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YACE,SACA,SACA;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,UAAU,QAAQ;AACvB,SAAK,gBAAgB,QAAQ;AAC7B,SAAK,SAAS,QAAQ;AACtB,SAAK,OAAO,QAAQ;AAAA,EACtB;AACF;","names":[]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ClientOptions } from './client-resolution.js';
|
|
2
|
+
import '@contentful/experience-delivery';
|
|
3
|
+
import '@contentful/experiences-sdk-core';
|
|
4
|
+
|
|
5
|
+
type FetchDestinationSitemapOptions = {
|
|
6
|
+
spaceId: string;
|
|
7
|
+
destinationId: string;
|
|
8
|
+
};
|
|
9
|
+
type FetchDestinationSitemapPaginationOptions = {
|
|
10
|
+
/** Maximum number of paths to return. Defaults to `100`, maximum `1000`. */
|
|
11
|
+
limit?: number;
|
|
12
|
+
/** Cursor from a previous call's `pages.next`. Treat as opaque; don't combine with `pagePrev`. */
|
|
13
|
+
pageNext?: string;
|
|
14
|
+
/** Cursor from a previous call's `pages.prev`. Treat as opaque; don't combine with `pageNext`. */
|
|
15
|
+
pagePrev?: string;
|
|
16
|
+
};
|
|
17
|
+
type SitemapPathItem = {
|
|
18
|
+
/** Path this entry routes. */
|
|
19
|
+
path: string;
|
|
20
|
+
/** Flat id extracted from the entry's `experienceUrn`. */
|
|
21
|
+
experienceId: string;
|
|
22
|
+
/** Type of the Destination Node that claims this path, e.g. `"DestinationExperienceNode"`. */
|
|
23
|
+
type: string;
|
|
24
|
+
};
|
|
25
|
+
type DestinationSitemapResult = {
|
|
26
|
+
items: SitemapPathItem[];
|
|
27
|
+
limit: number;
|
|
28
|
+
pages: {
|
|
29
|
+
next?: string;
|
|
30
|
+
prev?: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* List every routable path in a published Destination. Bulk enumeration —
|
|
35
|
+
* pairs with `fetchExperience`'s `destinationId` + `nodeId`/`path` branches,
|
|
36
|
+
* which resolve one path at a time. Does not hydrate any Experience itself
|
|
37
|
+
* and does not call `fetchExperience` internally.
|
|
38
|
+
*/
|
|
39
|
+
declare function fetchDestinationSitemap(destinationOptions: FetchDestinationSitemapOptions, clientOptions: ClientOptions, paginationOptions?: FetchDestinationSitemapPaginationOptions): Promise<DestinationSitemapResult>;
|
|
40
|
+
|
|
41
|
+
export { type DestinationSitemapResult, type FetchDestinationSitemapOptions, type FetchDestinationSitemapPaginationOptions, type SitemapPathItem, fetchDestinationSitemap };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ContentfulViewDelivery } from "@contentful/experience-delivery";
|
|
2
|
+
import { createDebugLogger } from "@contentful/experiences-sdk-core";
|
|
3
|
+
import { assertDestinationPreviewSupported } from "./destination-guards.js";
|
|
4
|
+
import { resolveDeliveryClient } from "./client-resolution.js";
|
|
5
|
+
import { ExperienceFetchError } from "./errors.js";
|
|
6
|
+
async function fetchDestinationSitemap(destinationOptions, clientOptions, paginationOptions = {}) {
|
|
7
|
+
const { spaceId, destinationId } = destinationOptions;
|
|
8
|
+
const log = createDebugLogger(false, "client");
|
|
9
|
+
if (!("client" in clientOptions)) {
|
|
10
|
+
assertDestinationPreviewSupported(clientOptions.preview, { spaceId, destinationId });
|
|
11
|
+
}
|
|
12
|
+
const client = resolveDeliveryClient(clientOptions, log, "fetchDestinationSitemap");
|
|
13
|
+
const { limit, pageNext, pagePrev } = paginationOptions;
|
|
14
|
+
let response;
|
|
15
|
+
try {
|
|
16
|
+
response = await client.destination.sitemap(spaceId, destinationId, {
|
|
17
|
+
limit,
|
|
18
|
+
pageNext,
|
|
19
|
+
pagePrev
|
|
20
|
+
});
|
|
21
|
+
} catch (err) {
|
|
22
|
+
if (err instanceof ContentfulViewDelivery.NotFoundError) {
|
|
23
|
+
throw err;
|
|
24
|
+
}
|
|
25
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
26
|
+
throw new ExperienceFetchError(
|
|
27
|
+
`Failed to fetch sitemap for Destination "${destinationId}" (space "${spaceId}"): ${reason}. Check network connectivity, the access token, and that the space/destination ids are correct.`,
|
|
28
|
+
{ spaceId, experienceId: destinationId, cause: err }
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
const result = {
|
|
32
|
+
items: response.paths.items.map((item) => ({
|
|
33
|
+
path: item.path,
|
|
34
|
+
experienceId: extractIdFromUrn(item.experienceUrn),
|
|
35
|
+
type: item.sys.type
|
|
36
|
+
})),
|
|
37
|
+
limit: response.paths.limit,
|
|
38
|
+
pages: response.paths.pages
|
|
39
|
+
};
|
|
40
|
+
log.lazy("received sitemap page", () => result);
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
function extractIdFromUrn(urn) {
|
|
44
|
+
const segments = urn.split("/").filter((s) => s.length > 0);
|
|
45
|
+
return segments[segments.length - 1] ?? urn;
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
fetchDestinationSitemap
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=fetch-destination-sitemap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/fetch-destination-sitemap.ts"],"sourcesContent":["import { ContentfulViewDelivery } from '@contentful/experience-delivery';\nimport { createDebugLogger } from '@contentful/experiences-sdk-core';\nimport { assertDestinationPreviewSupported } from './destination-guards.js';\nimport { resolveDeliveryClient, type ClientOptions } from './client-resolution.js';\nimport { ExperienceFetchError } from './errors.js';\n\nexport type FetchDestinationSitemapOptions = {\n spaceId: string;\n destinationId: string;\n};\n\nexport type FetchDestinationSitemapPaginationOptions = {\n /** Maximum number of paths to return. Defaults to `100`, maximum `1000`. */\n limit?: number;\n /** Cursor from a previous call's `pages.next`. Treat as opaque; don't combine with `pagePrev`. */\n pageNext?: string;\n /** Cursor from a previous call's `pages.prev`. Treat as opaque; don't combine with `pageNext`. */\n pagePrev?: string;\n};\n\nexport type SitemapPathItem = {\n /** Path this entry routes. */\n path: string;\n /** Flat id extracted from the entry's `experienceUrn`. */\n experienceId: string;\n /** Type of the Destination Node that claims this path, e.g. `\"DestinationExperienceNode\"`. */\n type: string;\n};\n\nexport type DestinationSitemapResult = {\n items: SitemapPathItem[];\n limit: number;\n pages: { next?: string; prev?: string };\n};\n\n/**\n * List every routable path in a published Destination. Bulk enumeration —\n * pairs with `fetchExperience`'s `destinationId` + `nodeId`/`path` branches,\n * which resolve one path at a time. Does not hydrate any Experience itself\n * and does not call `fetchExperience` internally.\n */\nexport async function fetchDestinationSitemap(\n destinationOptions: FetchDestinationSitemapOptions,\n clientOptions: ClientOptions,\n paginationOptions: FetchDestinationSitemapPaginationOptions = {}\n): Promise<DestinationSitemapResult> {\n const { spaceId, destinationId } = destinationOptions;\n const log = createDebugLogger(false, 'client');\n\n if (!('client' in clientOptions)) {\n assertDestinationPreviewSupported(clientOptions.preview, { spaceId, destinationId });\n }\n\n const client = resolveDeliveryClient(clientOptions, log, 'fetchDestinationSitemap');\n\n const { limit, pageNext, pagePrev } = paginationOptions;\n\n let response: ContentfulViewDelivery.DestinationSitemap;\n try {\n response = await client.destination.sitemap(spaceId, destinationId, {\n limit,\n pageNext,\n pagePrev,\n });\n } catch (err) {\n if (err instanceof ContentfulViewDelivery.NotFoundError) {\n throw err;\n }\n const reason = err instanceof Error ? err.message : String(err);\n throw new ExperienceFetchError(\n `Failed to fetch sitemap for Destination \"${destinationId}\" (space \"${spaceId}\"): ` +\n `${reason}. Check network connectivity, the access token, and that the space/` +\n `destination ids are correct.`,\n { spaceId, experienceId: destinationId, cause: err }\n );\n }\n\n const result = {\n items: response.paths.items.map((item) => ({\n path: item.path,\n experienceId: extractIdFromUrn(item.experienceUrn),\n type: item.sys.type,\n })),\n limit: response.paths.limit,\n pages: response.paths.pages,\n };\n\n log.lazy('received sitemap page', () => result);\n\n return result;\n}\n\n/**\n * Extract the flat id from an `experienceUrn`. Real shape:\n * crn:contentful:::experience:spaces/$self/environments/$self/experiences/<id>\n *\n * Same one-line logic as the private `extractIdFromUrn` in\n * `packages/core/src/resolve-experience.ts` — not shared across the\n * `core`/`client` package boundary (core stays zero-dep) for one line.\n */\nfunction extractIdFromUrn(urn: string): string {\n const segments = urn.split('/').filter((s) => s.length > 0);\n return segments[segments.length - 1] ?? urn;\n}\n"],"mappings":"AAAA,SAAS,8BAA8B;AACvC,SAAS,yBAAyB;AAClC,SAAS,yCAAyC;AAClD,SAAS,6BAAiD;AAC1D,SAAS,4BAA4B;AAqCrC,eAAsB,wBACpB,oBACA,eACA,oBAA8D,CAAC,GAC5B;AACnC,QAAM,EAAE,SAAS,cAAc,IAAI;AACnC,QAAM,MAAM,kBAAkB,OAAO,QAAQ;AAE7C,MAAI,EAAE,YAAY,gBAAgB;AAChC,sCAAkC,cAAc,SAAS,EAAE,SAAS,cAAc,CAAC;AAAA,EACrF;AAEA,QAAM,SAAS,sBAAsB,eAAe,KAAK,yBAAyB;AAElF,QAAM,EAAE,OAAO,UAAU,SAAS,IAAI;AAEtC,MAAI;AACJ,MAAI;AACF,eAAW,MAAM,OAAO,YAAY,QAAQ,SAAS,eAAe;AAAA,MAClE;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH,SAAS,KAAK;AACZ,QAAI,eAAe,uBAAuB,eAAe;AACvD,YAAM;AAAA,IACR;AACA,UAAM,SAAS,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAC9D,UAAM,IAAI;AAAA,MACR,4CAA4C,aAAa,aAAa,OAAO,OACxE,MAAM;AAAA,MAEX,EAAE,SAAS,cAAc,eAAe,OAAO,IAAI;AAAA,IACrD;AAAA,EACF;AAEA,QAAM,SAAS;AAAA,IACb,OAAO,SAAS,MAAM,MAAM,IAAI,CAAC,UAAU;AAAA,MACzC,MAAM,KAAK;AAAA,MACX,cAAc,iBAAiB,KAAK,aAAa;AAAA,MACjD,MAAM,KAAK,IAAI;AAAA,IACjB,EAAE;AAAA,IACF,OAAO,SAAS,MAAM;AAAA,IACtB,OAAO,SAAS,MAAM;AAAA,EACxB;AAEA,MAAI,KAAK,yBAAyB,MAAM,MAAM;AAE9C,SAAO;AACT;AAUA,SAAS,iBAAiB,KAAqB;AAC7C,QAAM,WAAW,IAAI,MAAM,GAAG,EAAE,OAAO,CAAC,MAAM,EAAE,SAAS,CAAC;AAC1D,SAAO,SAAS,SAAS,SAAS,CAAC,KAAK;AAC1C;","names":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ContentfulViewDelivery
|
|
1
|
+
import { ContentfulViewDelivery } from '@contentful/experience-delivery';
|
|
2
2
|
import { ResolverConfig, PortableRenderPlan } from '@contentful/experiences-sdk-core';
|
|
3
|
+
import { ClientOptions } from './client-resolution.js';
|
|
3
4
|
|
|
4
5
|
type DeliveryExperienceRequestExtensions = ContentfulViewDelivery.GetWithOverridesExperienceRequestExtensions;
|
|
5
6
|
type PersonalizationOptions = NonNullable<DeliveryExperienceRequestExtensions['personalization']>;
|
|
@@ -52,29 +53,6 @@ interface DestinationRedirectResult {
|
|
|
52
53
|
path: string;
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
|
-
type ClientOptions = {
|
|
56
|
-
accessToken: string;
|
|
57
|
-
/**
|
|
58
|
-
* Preview access token. Required when calling with `preview: true`.
|
|
59
|
-
*/
|
|
60
|
-
previewToken?: string;
|
|
61
|
-
/**
|
|
62
|
-
* Flip between delivery (default) and preview at request time. When
|
|
63
|
-
* `true`, `fetchExperience` uses `previewToken` and the preview host;
|
|
64
|
-
* when `false` or unset, it uses `accessToken` and the delivery host.
|
|
65
|
-
* Ignored when a pre-made `client` is passed instead of inline creds.
|
|
66
|
-
*/
|
|
67
|
-
preview?: boolean;
|
|
68
|
-
/**
|
|
69
|
-
* Custom base URL for the delivery client (staging, proxy, per-region).
|
|
70
|
-
* Wins over the `preview`-derived default host — combine `host` with
|
|
71
|
-
* `preview: true` to point preview mode at a non-prod endpoint.
|
|
72
|
-
* Omit for the standard delivery / preview hosts.
|
|
73
|
-
*/
|
|
74
|
-
host?: string;
|
|
75
|
-
} | {
|
|
76
|
-
client: ContentfulViewDeliveryClient;
|
|
77
|
-
};
|
|
78
56
|
type ResolveOptions = {
|
|
79
57
|
config: ResolverConfig;
|
|
80
58
|
/**
|
|
@@ -90,15 +68,9 @@ type ResolveOptions = {
|
|
|
90
68
|
* debug fallback). A single boolean across fetch + resolve + render.
|
|
91
69
|
*/
|
|
92
70
|
debug?: boolean;
|
|
93
|
-
/**
|
|
94
|
-
* Per-request fallback viewport for server-side design pre-resolution. Pass
|
|
95
|
-
* the same id you seed the renderer's `initialViewportId` with (e.g. a
|
|
96
|
-
* User-Agent-derived viewport) so SSR paints correct design on first render.
|
|
97
|
-
*/
|
|
98
|
-
initialViewportId?: string;
|
|
99
71
|
};
|
|
100
72
|
declare function fetchExperience(experienceOptions: ByIdExperienceOptions, clientOptions: ClientOptions, resolveOptions: ResolveOptions): Promise<PortableRenderPlan>;
|
|
101
73
|
declare function fetchExperience(experienceOptions: ByDestinationNodeIdExperienceOptions, clientOptions: ClientOptions, resolveOptions: ResolveOptions): Promise<PortableRenderPlan | DestinationRedirectResult>;
|
|
102
74
|
declare function fetchExperience(experienceOptions: ByDestinationPathExperienceOptions, clientOptions: ClientOptions, resolveOptions: ResolveOptions): Promise<PortableRenderPlan | DestinationRedirectResult>;
|
|
103
75
|
|
|
104
|
-
export { type ByDestinationNodeIdExperienceOptions, type ByDestinationPathExperienceOptions, type ByIdExperienceOptions,
|
|
76
|
+
export { type ByDestinationNodeIdExperienceOptions, type ByDestinationPathExperienceOptions, type ByIdExperienceOptions, ClientOptions, type DestinationRedirectResult, type ExperienceOptions, type ExperienceRequestExtensions, type PersonalizationOptions, type ResolveOptions, fetchExperience };
|
package/dist/fetch-experience.js
CHANGED
|
@@ -1,49 +1,33 @@
|
|
|
1
1
|
import { ContentfulViewDelivery } from "@contentful/experience-delivery";
|
|
2
2
|
import { createDebugLogger, resolveExperience } from "@contentful/experiences-sdk-core";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { assertDestinationPreviewSupported } from "./destination-guards.js";
|
|
4
|
+
import { resolveDeliveryClient } from "./client-resolution.js";
|
|
5
|
+
import { ExperienceFetchError } from "./errors.js";
|
|
6
6
|
import {
|
|
7
7
|
readSourceMap,
|
|
8
8
|
toExperiencePayload,
|
|
9
9
|
toExperiencePayloadFromDestination
|
|
10
10
|
} from "./to-experience-payload.js";
|
|
11
11
|
async function fetchExperience(experienceOptions, clientOptions, resolveOptions) {
|
|
12
|
-
const { config, metadata, debug
|
|
12
|
+
const { config, metadata, debug } = resolveOptions;
|
|
13
13
|
const log = createDebugLogger(debug, "client");
|
|
14
|
-
if (!("client" in clientOptions) &&
|
|
14
|
+
if (!("client" in clientOptions) && "destinationId" in experienceOptions) {
|
|
15
15
|
const { spaceId: spaceId2, destinationId } = experienceOptions;
|
|
16
16
|
const locator = "nodeId" in experienceOptions ? { nodeId: experienceOptions.nodeId } : { path: experienceOptions.path };
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
let client;
|
|
23
|
-
if ("client" in clientOptions) {
|
|
24
|
-
client = clientOptions.client;
|
|
25
|
-
log.log("using caller-supplied delivery client");
|
|
26
|
-
} else {
|
|
27
|
-
const { accessToken, previewToken, preview, host } = clientOptions;
|
|
28
|
-
if (preview && !previewToken) {
|
|
29
|
-
throw new Error(
|
|
30
|
-
"fetchExperience() called with preview: true but no previewToken was provided"
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
const resolvedHost = host ?? (preview ? PREVIEW_HOST : void 0);
|
|
34
|
-
client = createClient({
|
|
35
|
-
accessToken: preview ? previewToken : accessToken,
|
|
36
|
-
host: resolvedHost
|
|
17
|
+
assertDestinationPreviewSupported(clientOptions.preview, {
|
|
18
|
+
spaceId: spaceId2,
|
|
19
|
+
destinationId,
|
|
20
|
+
...locator
|
|
37
21
|
});
|
|
38
|
-
log.log("created delivery client", { preview: Boolean(preview), host: resolvedHost });
|
|
39
22
|
}
|
|
23
|
+
const client = resolveDeliveryClient(clientOptions, log, "fetchExperience");
|
|
40
24
|
if ("nodeId" in experienceOptions) {
|
|
41
25
|
const { spaceId: spaceId2, destinationId, nodeId } = experienceOptions;
|
|
42
26
|
return fetchByDestination(
|
|
43
27
|
{ spaceId: spaceId2, destinationId, locator: nodeId },
|
|
44
28
|
() => client.destination.resolveByNodeId(spaceId2, destinationId, nodeId),
|
|
45
29
|
log,
|
|
46
|
-
{ config, metadata, debug
|
|
30
|
+
{ config, metadata, debug }
|
|
47
31
|
);
|
|
48
32
|
}
|
|
49
33
|
if ("path" in experienceOptions) {
|
|
@@ -52,7 +36,7 @@ async function fetchExperience(experienceOptions, clientOptions, resolveOptions)
|
|
|
52
36
|
{ spaceId: spaceId2, destinationId, locator: path },
|
|
53
37
|
() => client.destination.resolveByPath(spaceId2, destinationId, { path }),
|
|
54
38
|
log,
|
|
55
|
-
{ config, metadata, debug
|
|
39
|
+
{ config, metadata, debug }
|
|
56
40
|
);
|
|
57
41
|
}
|
|
58
42
|
const { spaceId, environmentId, experienceId, locale, personalization, extensions } = experienceOptions;
|
|
@@ -72,7 +56,6 @@ async function fetchExperience(experienceOptions, clientOptions, resolveOptions)
|
|
|
72
56
|
return resolveExperience(payload, config, {
|
|
73
57
|
metadata,
|
|
74
58
|
debug,
|
|
75
|
-
initialViewportId,
|
|
76
59
|
sourceMap
|
|
77
60
|
});
|
|
78
61
|
}
|
|
@@ -103,7 +86,7 @@ async function fetchByExperienceId(client, options) {
|
|
|
103
86
|
}
|
|
104
87
|
async function fetchByDestination(identity, resolve, log, resolveOptions) {
|
|
105
88
|
const { spaceId, destinationId, locator } = identity;
|
|
106
|
-
const { config, metadata, debug
|
|
89
|
+
const { config, metadata, debug } = resolveOptions;
|
|
107
90
|
log.log("resolving destination experience", { spaceId, destinationId, locator });
|
|
108
91
|
let response;
|
|
109
92
|
try {
|
|
@@ -133,8 +116,7 @@ async function fetchByDestination(identity, resolve, log, resolveOptions) {
|
|
|
133
116
|
log.lazy("received raw payload", () => payload);
|
|
134
117
|
return resolveExperience(payload, config, {
|
|
135
118
|
metadata,
|
|
136
|
-
debug
|
|
137
|
-
initialViewportId
|
|
119
|
+
debug
|
|
138
120
|
});
|
|
139
121
|
}
|
|
140
122
|
function hasRequestExtensions(extensions) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/fetch-experience.ts"],"sourcesContent":["import type { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';\nimport { ContentfulViewDelivery } from '@contentful/experience-delivery';\nimport { createDebugLogger, resolveExperience } from '@contentful/experiences-sdk-core';\nimport type { PortableRenderPlan, ResolverConfig } from '@contentful/experiences-sdk-core';\nimport { createClient } from './create-delivery-client.js';\nimport { DestinationPreviewNotSupportedError, ExperienceFetchError } from './errors.js';\nimport { PREVIEW_HOST } from './hosts.js';\nimport {\n readSourceMap,\n toExperiencePayload,\n toExperiencePayloadFromDestination,\n type ExperienceResponse,\n} from './to-experience-payload.js';\n\ntype DeliveryExperienceRequestExtensions =\n ContentfulViewDelivery.GetWithOverridesExperienceRequestExtensions;\n\nexport type PersonalizationOptions = NonNullable<\n DeliveryExperienceRequestExtensions['personalization']\n>;\n\nexport type ExperienceRequestExtensions = Omit<\n DeliveryExperienceRequestExtensions,\n 'personalization'\n>;\n\nexport type ByIdExperienceOptions = {\n spaceId: string;\n environmentId: string;\n experienceId: string;\n locale?: string;\n /**\n * Profile and events used by XDA to personalize the resolved Experience.\n */\n personalization?: PersonalizationOptions;\n /**\n * Additional XDA request extensions such as source maps. Supplying a defined\n * extension switches the request to POST.\n */\n extensions?: ExperienceRequestExtensions;\n};\n\n/**\n * Resolve an Experience by the Destination Node instead of `experienceId`\n * The destinations delivery endpoints are space-scoped only and have no locale\n * param, unlike the by-id path.\n */\nexport type ByDestinationNodeIdExperienceOptions = {\n spaceId: string;\n destinationId: string;\n nodeId: string;\n};\n\n/**\n * Resolve an Experience by the absolute path wired up to a\n * Destination Node, instead of a node id directly. Same scoping as\n * `ByDestinationNodeIdExperienceOptions` — no `environmentId` or `locale`.\n */\nexport type ByDestinationPathExperienceOptions = {\n spaceId: string;\n destinationId: string;\n /** Absolute path to resolve. Must start with `/`. */\n path: string;\n};\n\nexport type ExperienceOptions =\n ByIdExperienceOptions | ByDestinationNodeIdExperienceOptions | ByDestinationPathExperienceOptions;\n\n/**\n * A Destination resolution that the app must act on as control flow — honor\n * it by navigating or re-resolving at the new path — rather than a hydrated\n * Experience to render. Modeled as a normal return value, not a thrown error,\n * per the Destinations delivery API's own framing of a redirect response.\n */\nexport interface DestinationRedirectResult {\n redirect: { path: string };\n}\n\nexport type ClientOptions =\n | {\n accessToken: string;\n /**\n * Preview access token. Required when calling with `preview: true`.\n */\n previewToken?: string;\n /**\n * Flip between delivery (default) and preview at request time. When\n * `true`, `fetchExperience` uses `previewToken` and the preview host;\n * when `false` or unset, it uses `accessToken` and the delivery host.\n * Ignored when a pre-made `client` is passed instead of inline creds.\n */\n preview?: boolean;\n /**\n * Custom base URL for the delivery client (staging, proxy, per-region).\n * Wins over the `preview`-derived default host — combine `host` with\n * `preview: true` to point preview mode at a non-prod endpoint.\n * Omit for the standard delivery / preview hosts.\n */\n host?: string;\n }\n | { client: ContentfulViewDeliveryClient };\n\nexport type ResolveOptions = {\n config: ResolverConfig;\n /**\n * Arbitrary per-render metadata exposed to every resolver as\n * `ctx.experience.metadata` and readable at render time via the framework\n * adapter's `useExperience()` / `getExperience()`.\n */\n metadata?: Record<string, unknown>;\n /**\n * Observability switch. When on: logs the fetch (host, ids) and the raw\n * payload here, and threads through to `resolveExperience` (resolution steps\n * + `resolveData` timings) and the renderer (visible missing-component box,\n * debug fallback). A single boolean across fetch + resolve + render.\n */\n debug?: boolean;\n /**\n * Per-request fallback viewport for server-side design pre-resolution. Pass\n * the same id you seed the renderer's `initialViewportId` with (e.g. a\n * User-Agent-derived viewport) so SSR paints correct design on first render.\n */\n initialViewportId?: string;\n};\n\n// TS overload signatures, not real redeclarations — base ESLint's no-redeclare doesn't know the\n// overload form (@typescript-eslint's own version does), so each repeated signature needs a\n// disable comment.\nexport async function fetchExperience(\n experienceOptions: ByIdExperienceOptions,\n clientOptions: ClientOptions,\n resolveOptions: ResolveOptions\n): Promise<PortableRenderPlan>;\n// eslint-disable-next-line no-redeclare -- see above\nexport async function fetchExperience(\n experienceOptions: ByDestinationNodeIdExperienceOptions,\n clientOptions: ClientOptions,\n resolveOptions: ResolveOptions\n): Promise<PortableRenderPlan | DestinationRedirectResult>;\n// eslint-disable-next-line no-redeclare -- see above\nexport async function fetchExperience(\n experienceOptions: ByDestinationPathExperienceOptions,\n clientOptions: ClientOptions,\n resolveOptions: ResolveOptions\n): Promise<PortableRenderPlan | DestinationRedirectResult>;\n// eslint-disable-next-line no-redeclare -- see above\nexport async function fetchExperience(\n experienceOptions: ExperienceOptions,\n clientOptions: ClientOptions,\n resolveOptions: ResolveOptions\n): Promise<PortableRenderPlan | DestinationRedirectResult> {\n const { config, metadata, debug, initialViewportId } = resolveOptions;\n const log = createDebugLogger(debug, 'client');\n\n if (\n !('client' in clientOptions) &&\n clientOptions.preview &&\n 'destinationId' in experienceOptions\n ) {\n const { spaceId, destinationId } = experienceOptions;\n const locator =\n 'nodeId' in experienceOptions\n ? { nodeId: experienceOptions.nodeId }\n : { path: experienceOptions.path };\n throw new DestinationPreviewNotSupportedError(\n `fetchExperience() called with preview: true and a destination-shaped experienceOptions ` +\n `(destinationId \"${destinationId}\"). The Destinations Delivery API does not support ` +\n `preview mode yet — pass preview: false (or omit it) for destination-based fetches.`,\n { spaceId, destinationId, ...locator }\n );\n }\n\n let client: ContentfulViewDeliveryClient;\n if ('client' in clientOptions) {\n client = clientOptions.client;\n log.log('using caller-supplied delivery client');\n } else {\n const { accessToken, previewToken, preview, host } = clientOptions;\n if (preview && !previewToken) {\n throw new Error(\n 'fetchExperience() called with preview: true but no previewToken was provided'\n );\n }\n const resolvedHost = host ?? (preview ? PREVIEW_HOST : undefined);\n client = createClient({\n accessToken: preview ? (previewToken as string) : accessToken,\n host: resolvedHost,\n });\n log.log('created delivery client', { preview: Boolean(preview), host: resolvedHost });\n }\n\n if ('nodeId' in experienceOptions) {\n const { spaceId, destinationId, nodeId } = experienceOptions;\n return fetchByDestination(\n { spaceId, destinationId, locator: nodeId },\n () => client.destination.resolveByNodeId(spaceId, destinationId, nodeId),\n log,\n { config, metadata, debug, initialViewportId }\n );\n }\n\n if ('path' in experienceOptions) {\n const { spaceId, destinationId, path } = experienceOptions;\n return fetchByDestination(\n { spaceId, destinationId, locator: path },\n () => client.destination.resolveByPath(spaceId, destinationId, { path }),\n log,\n { config, metadata, debug, initialViewportId }\n );\n }\n\n const { spaceId, environmentId, experienceId, locale, personalization, extensions } =\n experienceOptions;\n\n log.log('fetching experience', {\n spaceId,\n environmentId,\n experienceId,\n locale,\n // avoiding log any personalization sensitive data\n personalization: personalization !== undefined,\n extensions,\n });\n\n const response = await fetchByExperienceId(client, experienceOptions);\n\n const payload = toExperiencePayload(response);\n const sourceMap = extensions?.sourceMap !== undefined ? readSourceMap(response) : undefined;\n\n log.lazy('received raw payload', () => payload);\n\n return resolveExperience(payload, config, {\n metadata,\n debug,\n initialViewportId,\n sourceMap,\n });\n}\n\nasync function fetchByExperienceId(\n client: ContentfulViewDeliveryClient,\n options: ByIdExperienceOptions\n): Promise<ExperienceResponse> {\n const { spaceId, environmentId, experienceId, locale, personalization, extensions } = options;\n const requestExtensions: DeliveryExperienceRequestExtensions = {\n ...extensions,\n ...(personalization === undefined ? {} : { personalization }),\n };\n\n try {\n // Both methods hit the same endpoint, but only the POST operation accepts\n // extensions in its request body. Keep the cacheable GET when there are no\n // extensions to evaluate.\n // The generated delivery client owns the alpha-feature header on both\n // paths, including when the caller supplied the client instance.\n //\n // Await inside the try so rejected requests are normalized below.\n if (hasRequestExtensions(requestExtensions)) {\n return await client.experience.getWithOverrides(spaceId, environmentId, experienceId, {\n locale,\n extensions: requestExtensions,\n });\n }\n\n return await client.experience.get(spaceId, environmentId, experienceId, { locale });\n } catch (err) {\n // Preserve expected 404 control flow for framework routers. Other failures\n // are wrapped with stable SDK context instead of exposing transport-specific\n // error shapes.\n if (err instanceof ContentfulViewDelivery.NotFoundError) {\n throw err;\n }\n const reason = err instanceof Error ? err.message : String(err);\n throw new ExperienceFetchError(\n `Failed to fetch Experience \"${experienceId}\" (space \"${spaceId}\", environment ` +\n `\"${environmentId}\"): ${reason}. Check network connectivity, the access token, and ` +\n `that the space/environment/experience ids are correct.`,\n { spaceId, environmentId, experienceId, cause: err }\n );\n }\n}\n\n/**\n * Shared response-handling for both destination-shaped `fetchExperience`\n * branches (by node id, by path).\n */\nasync function fetchByDestination(\n identity: { spaceId: string; destinationId: string; locator: string },\n resolve: () => Promise<ContentfulViewDelivery.DestinationExperienceResolutionResponse>,\n log: ReturnType<typeof createDebugLogger>,\n resolveOptions: {\n config: ResolverConfig;\n metadata: Record<string, unknown> | undefined;\n debug: boolean | undefined;\n initialViewportId: string | undefined;\n }\n): Promise<PortableRenderPlan | DestinationRedirectResult> {\n const { spaceId, destinationId, locator } = identity;\n const { config, metadata, debug, initialViewportId } = resolveOptions;\n\n log.log('resolving destination experience', { spaceId, destinationId, locator });\n\n let response: ContentfulViewDelivery.DestinationExperienceResolutionResponse;\n try {\n response = await resolve();\n } catch (err) {\n if (err instanceof ContentfulViewDelivery.NotFoundError) {\n throw err;\n }\n const reason = err instanceof Error ? err.message : String(err);\n throw new ExperienceFetchError(\n `Failed to resolve Destination \"${destinationId}\" at \"${locator}\" (space \"${spaceId}\"): ` +\n `${reason}. Check network connectivity, the access token, and that the space/` +\n `destination/node-or-path values are correct.`,\n { spaceId, experienceId: locator, cause: err }\n );\n }\n\n if ('redirect' in response) {\n log.log('destination resolved to a redirect', response.redirect);\n return { redirect: response.redirect };\n }\n\n const [firstExperience] = response.experiences;\n if (!firstExperience) {\n throw new ExperienceFetchError(\n `Destination \"${destinationId}\" resolved \"${locator}\" to zero Experiences ` +\n `(space \"${spaceId}\"). Expected exactly one hydrated Experience or a redirect.`,\n { spaceId, experienceId: locator }\n );\n }\n\n const payload = toExperiencePayloadFromDestination(firstExperience.experience);\n log.lazy('received raw payload', () => payload);\n\n return resolveExperience(payload, config, {\n metadata,\n debug,\n initialViewportId,\n });\n}\n\nfunction hasRequestExtensions(\n extensions: DeliveryExperienceRequestExtensions | undefined\n): extensions is DeliveryExperienceRequestExtensions {\n return (\n extensions !== undefined &&\n Object.values(extensions).some((extension) => extension !== undefined)\n );\n}\n"],"mappings":"AACA,SAAS,8BAA8B;AACvC,SAAS,mBAAmB,yBAAyB;AAErD,SAAS,oBAAoB;AAC7B,SAAS,qCAAqC,4BAA4B;AAC1E,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAsIP,eAAsB,gBACpB,mBACA,eACA,gBACyD;AACzD,QAAM,EAAE,QAAQ,UAAU,OAAO,kBAAkB,IAAI;AACvD,QAAM,MAAM,kBAAkB,OAAO,QAAQ;AAE7C,MACE,EAAE,YAAY,kBACd,cAAc,WACd,mBAAmB,mBACnB;AACA,UAAM,EAAE,SAAAA,UAAS,cAAc,IAAI;AACnC,UAAM,UACJ,YAAY,oBACR,EAAE,QAAQ,kBAAkB,OAAO,IACnC,EAAE,MAAM,kBAAkB,KAAK;AACrC,UAAM,IAAI;AAAA,MACR,0GACqB,aAAa;AAAA,MAElC,EAAE,SAAAA,UAAS,eAAe,GAAG,QAAQ;AAAA,IACvC;AAAA,EACF;AAEA,MAAI;AACJ,MAAI,YAAY,eAAe;AAC7B,aAAS,cAAc;AACvB,QAAI,IAAI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,UAAM,SAAS,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAC9D,UAAM,IAAI;AAAA,MACR,kCAAkC,aAAa,SAAS,OAAO,aAAa,OAAO,OAC9E,MAAM;AAAA,MAEX,EAAE,SAAS,cAAc,SAAS,OAAO,IAAI;AAAA,IAC/C;AAAA,EACF;AAEA,MAAI,cAAc,UAAU;AAC1B,QAAI,IAAI,sCAAsC,SAAS,QAAQ;AAC/D,WAAO,EAAE,UAAU,SAAS,SAAS;AAAA,EACvC;AAEA,QAAM,CAAC,eAAe,IAAI,SAAS;AACnC,MAAI,CAAC,iBAAiB;AACpB,UAAM,IAAI;AAAA,MACR,gBAAgB,aAAa,eAAe,OAAO,iCACtC,OAAO;AAAA,MACpB,EAAE,SAAS,cAAc,QAAQ;AAAA,IACnC;AAAA,EACF;AAEA,QAAM,UAAU,mCAAmC,gBAAgB,UAAU;AAC7E,MAAI,KAAK,wBAAwB,MAAM,OAAO;AAE9C,SAAO,kBAAkB,SAAS,QAAQ;AAAA,IACxC;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAEA,SAAS,qBACP,YACmD;AACnD,SACE,eAAe,UACf,OAAO,OAAO,UAAU,EAAE,KAAK,CAAC,cAAc,cAAc,MAAS;AAEzE;","names":["spaceId"]}
|
|
1
|
+
{"version":3,"sources":["../src/fetch-experience.ts"],"sourcesContent":["import type { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';\nimport { ContentfulViewDelivery } from '@contentful/experience-delivery';\nimport { createDebugLogger, resolveExperience } from '@contentful/experiences-sdk-core';\nimport type { PortableRenderPlan, ResolverConfig } from '@contentful/experiences-sdk-core';\nimport { assertDestinationPreviewSupported } from './destination-guards.js';\nimport { resolveDeliveryClient, type ClientOptions } from './client-resolution.js';\nimport { ExperienceFetchError } from './errors.js';\nimport {\n readSourceMap,\n toExperiencePayload,\n toExperiencePayloadFromDestination,\n type ExperienceResponse,\n} from './to-experience-payload.js';\n\nexport type { ClientOptions };\n\ntype DeliveryExperienceRequestExtensions =\n ContentfulViewDelivery.GetWithOverridesExperienceRequestExtensions;\n\nexport type PersonalizationOptions = NonNullable<\n DeliveryExperienceRequestExtensions['personalization']\n>;\n\nexport type ExperienceRequestExtensions = Omit<\n DeliveryExperienceRequestExtensions,\n 'personalization'\n>;\n\nexport type ByIdExperienceOptions = {\n spaceId: string;\n environmentId: string;\n experienceId: string;\n locale?: string;\n /**\n * Profile and events used by XDA to personalize the resolved Experience.\n */\n personalization?: PersonalizationOptions;\n /**\n * Additional XDA request extensions such as source maps. Supplying a defined\n * extension switches the request to POST.\n */\n extensions?: ExperienceRequestExtensions;\n};\n\n/**\n * Resolve an Experience by the Destination Node instead of `experienceId`\n * The destinations delivery endpoints are space-scoped only and have no locale\n * param, unlike the by-id path.\n */\nexport type ByDestinationNodeIdExperienceOptions = {\n spaceId: string;\n destinationId: string;\n nodeId: string;\n};\n\n/**\n * Resolve an Experience by the absolute path wired up to a\n * Destination Node, instead of a node id directly. Same scoping as\n * `ByDestinationNodeIdExperienceOptions` — no `environmentId` or `locale`.\n */\nexport type ByDestinationPathExperienceOptions = {\n spaceId: string;\n destinationId: string;\n /** Absolute path to resolve. Must start with `/`. */\n path: string;\n};\n\nexport type ExperienceOptions =\n ByIdExperienceOptions | ByDestinationNodeIdExperienceOptions | ByDestinationPathExperienceOptions;\n\n/**\n * A Destination resolution that the app must act on as control flow — honor\n * it by navigating or re-resolving at the new path — rather than a hydrated\n * Experience to render. Modeled as a normal return value, not a thrown error,\n * per the Destinations delivery API's own framing of a redirect response.\n */\nexport interface DestinationRedirectResult {\n redirect: { path: string };\n}\n\nexport type ResolveOptions = {\n config: ResolverConfig;\n /**\n * Arbitrary per-render metadata exposed to every resolver as\n * `ctx.experience.metadata` and readable at render time via the framework\n * adapter's `useExperience()` / `getExperience()`.\n */\n metadata?: Record<string, unknown>;\n /**\n * Observability switch. When on: logs the fetch (host, ids) and the raw\n * payload here, and threads through to `resolveExperience` (resolution steps\n * + `resolveData` timings) and the renderer (visible missing-component box,\n * debug fallback). A single boolean across fetch + resolve + render.\n */\n debug?: boolean;\n};\n\n// TS overload signatures, not real redeclarations — base ESLint's no-redeclare doesn't know the\n// overload form (@typescript-eslint's own version does), so each repeated signature needs a\n// disable comment.\nexport async function fetchExperience(\n experienceOptions: ByIdExperienceOptions,\n clientOptions: ClientOptions,\n resolveOptions: ResolveOptions\n): Promise<PortableRenderPlan>;\n// eslint-disable-next-line no-redeclare -- see above\nexport async function fetchExperience(\n experienceOptions: ByDestinationNodeIdExperienceOptions,\n clientOptions: ClientOptions,\n resolveOptions: ResolveOptions\n): Promise<PortableRenderPlan | DestinationRedirectResult>;\n// eslint-disable-next-line no-redeclare -- see above\nexport async function fetchExperience(\n experienceOptions: ByDestinationPathExperienceOptions,\n clientOptions: ClientOptions,\n resolveOptions: ResolveOptions\n): Promise<PortableRenderPlan | DestinationRedirectResult>;\n// eslint-disable-next-line no-redeclare -- see above\nexport async function fetchExperience(\n experienceOptions: ExperienceOptions,\n clientOptions: ClientOptions,\n resolveOptions: ResolveOptions\n): Promise<PortableRenderPlan | DestinationRedirectResult> {\n const { config, metadata, debug } = resolveOptions;\n const log = createDebugLogger(debug, 'client');\n\n if (!('client' in clientOptions) && 'destinationId' in experienceOptions) {\n const { spaceId, destinationId } = experienceOptions;\n const locator =\n 'nodeId' in experienceOptions\n ? { nodeId: experienceOptions.nodeId }\n : { path: experienceOptions.path };\n assertDestinationPreviewSupported(clientOptions.preview, {\n spaceId,\n destinationId,\n ...locator,\n });\n }\n\n const client = resolveDeliveryClient(clientOptions, log, 'fetchExperience');\n\n if ('nodeId' in experienceOptions) {\n const { spaceId, destinationId, nodeId } = experienceOptions;\n return fetchByDestination(\n { spaceId, destinationId, locator: nodeId },\n () => client.destination.resolveByNodeId(spaceId, destinationId, nodeId),\n log,\n { config, metadata, debug }\n );\n }\n\n if ('path' in experienceOptions) {\n const { spaceId, destinationId, path } = experienceOptions;\n return fetchByDestination(\n { spaceId, destinationId, locator: path },\n () => client.destination.resolveByPath(spaceId, destinationId, { path }),\n log,\n { config, metadata, debug }\n );\n }\n\n const { spaceId, environmentId, experienceId, locale, personalization, extensions } =\n experienceOptions;\n\n log.log('fetching experience', {\n spaceId,\n environmentId,\n experienceId,\n locale,\n // avoiding log any personalization sensitive data\n personalization: personalization !== undefined,\n extensions,\n });\n\n const response = await fetchByExperienceId(client, experienceOptions);\n\n const payload = toExperiencePayload(response);\n const sourceMap = extensions?.sourceMap !== undefined ? readSourceMap(response) : undefined;\n\n log.lazy('received raw payload', () => payload);\n\n return resolveExperience(payload, config, {\n metadata,\n debug,\n sourceMap,\n });\n}\n\nasync function fetchByExperienceId(\n client: ContentfulViewDeliveryClient,\n options: ByIdExperienceOptions\n): Promise<ExperienceResponse> {\n const { spaceId, environmentId, experienceId, locale, personalization, extensions } = options;\n const requestExtensions: DeliveryExperienceRequestExtensions = {\n ...extensions,\n ...(personalization === undefined ? {} : { personalization }),\n };\n\n try {\n // Both methods hit the same endpoint, but only the POST operation accepts\n // extensions in its request body. Keep the cacheable GET when there are no\n // extensions to evaluate.\n // The generated delivery client owns the alpha-feature header on both\n // paths, including when the caller supplied the client instance.\n //\n // Await inside the try so rejected requests are normalized below.\n if (hasRequestExtensions(requestExtensions)) {\n return await client.experience.getWithOverrides(spaceId, environmentId, experienceId, {\n locale,\n extensions: requestExtensions,\n });\n }\n\n return await client.experience.get(spaceId, environmentId, experienceId, { locale });\n } catch (err) {\n // Preserve expected 404 control flow for framework routers. Other failures\n // are wrapped with stable SDK context instead of exposing transport-specific\n // error shapes.\n if (err instanceof ContentfulViewDelivery.NotFoundError) {\n throw err;\n }\n const reason = err instanceof Error ? err.message : String(err);\n throw new ExperienceFetchError(\n `Failed to fetch Experience \"${experienceId}\" (space \"${spaceId}\", environment ` +\n `\"${environmentId}\"): ${reason}. Check network connectivity, the access token, and ` +\n `that the space/environment/experience ids are correct.`,\n { spaceId, environmentId, experienceId, cause: err }\n );\n }\n}\n\n/**\n * Shared response-handling for both destination-shaped `fetchExperience`\n * branches (by node id, by path).\n */\nasync function fetchByDestination(\n identity: { spaceId: string; destinationId: string; locator: string },\n resolve: () => Promise<ContentfulViewDelivery.DestinationExperienceResolutionResponse>,\n log: ReturnType<typeof createDebugLogger>,\n resolveOptions: {\n config: ResolverConfig;\n metadata: Record<string, unknown> | undefined;\n debug: boolean | undefined;\n }\n): Promise<PortableRenderPlan | DestinationRedirectResult> {\n const { spaceId, destinationId, locator } = identity;\n const { config, metadata, debug } = resolveOptions;\n\n log.log('resolving destination experience', { spaceId, destinationId, locator });\n\n let response: ContentfulViewDelivery.DestinationExperienceResolutionResponse;\n try {\n response = await resolve();\n } catch (err) {\n if (err instanceof ContentfulViewDelivery.NotFoundError) {\n throw err;\n }\n const reason = err instanceof Error ? err.message : String(err);\n throw new ExperienceFetchError(\n `Failed to resolve Destination \"${destinationId}\" at \"${locator}\" (space \"${spaceId}\"): ` +\n `${reason}. Check network connectivity, the access token, and that the space/` +\n `destination/node-or-path values are correct.`,\n { spaceId, experienceId: locator, cause: err }\n );\n }\n\n if ('redirect' in response) {\n log.log('destination resolved to a redirect', response.redirect);\n return { redirect: response.redirect };\n }\n\n const [firstExperience] = response.experiences;\n if (!firstExperience) {\n throw new ExperienceFetchError(\n `Destination \"${destinationId}\" resolved \"${locator}\" to zero Experiences ` +\n `(space \"${spaceId}\"). Expected exactly one hydrated Experience or a redirect.`,\n { spaceId, experienceId: locator }\n );\n }\n\n const payload = toExperiencePayloadFromDestination(firstExperience.experience);\n log.lazy('received raw payload', () => payload);\n\n return resolveExperience(payload, config, {\n metadata,\n debug,\n });\n}\n\nfunction hasRequestExtensions(\n extensions: DeliveryExperienceRequestExtensions | undefined\n): extensions is DeliveryExperienceRequestExtensions {\n return (\n extensions !== undefined &&\n Object.values(extensions).some((extension) => extension !== undefined)\n );\n}\n"],"mappings":"AACA,SAAS,8BAA8B;AACvC,SAAS,mBAAmB,yBAAyB;AAErD,SAAS,yCAAyC;AAClD,SAAS,6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AC;AAE/E,MAAI;AACJ,MAAI;AACF,eAAW,MAAM,QAAQ;AAAA,EAC3B,SAAS,KAAK;AACZ,QAAI,eAAe,uBAAuB,eAAe;AACvD,YAAM;AAAA,IACR;AACA,UAAM,SAAS,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAC9D,UAAM,IAAI;AAAA,MACR,kCAAkC,aAAa,SAAS,OAAO,aAAa,OAAO,OAC9E,MAAM;AAAA,MAEX,EAAE,SAAS,cAAc,SAAS,OAAO,IAAI;AAAA,IAC/C;AAAA,EACF;AAEA,MAAI,cAAc,UAAU;AAC1B,QAAI,IAAI,sCAAsC,SAAS,QAAQ;AAC/D,WAAO,EAAE,UAAU,SAAS,SAAS;AAAA,EACvC;AAEA,QAAM,CAAC,eAAe,IAAI,SAAS;AACnC,MAAI,CAAC,iBAAiB;AACpB,UAAM,IAAI;AAAA,MACR,gBAAgB,aAAa,eAAe,OAAO,iCACtC,OAAO;AAAA,MACpB,EAAE,SAAS,cAAc,QAAQ;AAAA,IACnC;AAAA,EACF;AAEA,QAAM,UAAU,mCAAmC,gBAAgB,UAAU;AAC7E,MAAI,KAAK,wBAAwB,MAAM,OAAO;AAE9C,SAAO,kBAAkB,SAAS,QAAQ;AAAA,IACxC;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAEA,SAAS,qBACP,YACmD;AACnD,SACE,eAAe,UACf,OAAO,OAAO,UAAU,EAAE,KAAK,CAAC,cAAc,cAAc,MAAS;AAEzE;","names":["spaceId"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,12 +5,14 @@ export { ANONYMOUS_ID_COOKIE, PROFILE_CACHE_KEY } from './constants.js';
|
|
|
5
5
|
export { CreateClientOptions, RuntimeDeliveryClientOptions, createClient } from './create-delivery-client.js';
|
|
6
6
|
export { RuntimeOptimizationConfig } from './create-optimization-client.js';
|
|
7
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,
|
|
8
|
+
export { ByDestinationNodeIdExperienceOptions, ByDestinationPathExperienceOptions, ByIdExperienceOptions, DestinationRedirectResult, ExperienceOptions, ExperienceRequestExtensions, PersonalizationOptions, ResolveOptions, fetchExperience } from './fetch-experience.js';
|
|
9
|
+
export { DestinationSitemapResult, FetchDestinationSitemapOptions, FetchDestinationSitemapPaginationOptions, SitemapPathItem, fetchDestinationSitemap } from './fetch-destination-sitemap.js';
|
|
9
10
|
export { ContentfulExperiences, ContentfulExperiencesConfig, ExperienceRuntime, RuntimeEventBuilderConfig, RuntimeFetchByDestinationNodeOptions, RuntimeFetchByDestinationPathOptions, RuntimeFetchExperienceOptions, RuntimeResolveOptions } from './contentful-experiences.js';
|
|
10
11
|
export { AnalyticsEventMethod, EventProfileRequiredError, PersonalizationEventMethod, RuntimeEventBindings, RuntimeEventMethods } from './runtime-event-methods.js';
|
|
11
12
|
export { RUNTIME_EVENT_HANDOFF_VERSION, RuntimeEventHandoff, RuntimeEventHandoffEvent, RuntimeEventHandoffReceipt, RuntimeServerEventDelivery, assertRuntimeEventHandoffSize, parseRuntimeEventHandoff } from './runtime-event-handoff.js';
|
|
12
13
|
export { ExperienceResponse, readSourceMap, toExperiencePayload, toExperiencePayloadFromDestination } from './to-experience-payload.js';
|
|
13
14
|
export { DELIVERY_HOST, PREVIEW_HOST, PREVIEW_WEBSOCKET_HOST } from './hosts.js';
|
|
15
|
+
export { ClientOptions } from './client-resolution.js';
|
|
14
16
|
export { OptimizationData as EventOptimizationData, PartialProfile as EventProfile, PartialProfile as EventProfileSchema } from '@contentful/optimization-api-client/api-schemas';
|
|
15
17
|
import '@contentful/optimization-api-client';
|
|
16
18
|
import 'zod/mini';
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import { createClient } from "./create-delivery-client.js";
|
|
|
10
10
|
import { default as default2 } from "./event-builder.js";
|
|
11
11
|
export * from "./event-builder.js";
|
|
12
12
|
import { fetchExperience } from "./fetch-experience.js";
|
|
13
|
+
import { fetchDestinationSitemap } from "./fetch-destination-sitemap.js";
|
|
13
14
|
import { ContentfulExperiences } from "./contentful-experiences.js";
|
|
14
15
|
import { EventProfileRequiredError, EventProfileSchema } from "./runtime-event-methods.js";
|
|
15
16
|
import {
|
|
@@ -41,6 +42,7 @@ export {
|
|
|
41
42
|
RUNTIME_EVENT_HANDOFF_VERSION,
|
|
42
43
|
assertRuntimeEventHandoffSize,
|
|
43
44
|
createClient,
|
|
45
|
+
fetchDestinationSitemap,
|
|
44
46
|
fetchExperience,
|
|
45
47
|
parseRuntimeEventHandoff,
|
|
46
48
|
readSourceMap,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { ContentfulViewDelivery } from '@contentful/experience-delivery';\n\nexport {\n ContentfulViewDelivery,\n ContentfulViewDeliveryClient,\n} from '@contentful/experience-delivery';\nexport const NotFoundError = ContentfulViewDelivery.NotFoundError;\n// eslint-disable-next-line no-redeclare -- value + type share a name across separate TS namespaces, not a real redeclaration\nexport type NotFoundError = InstanceType<typeof ContentfulViewDelivery.NotFoundError>;\nexport { ExperienceFetchError, DestinationPreviewNotSupportedError } from './errors.js';\nexport { ANONYMOUS_ID_COOKIE, PROFILE_CACHE_KEY } from './constants.js';\nexport { createClient } from './create-delivery-client.js';\nexport type {\n CreateClientOptions,\n RuntimeDeliveryClientOptions,\n} from './create-delivery-client.js';\nexport type { RuntimeOptimizationConfig } from './create-optimization-client.js';\nexport { default as EventBuilder } from './event-builder.js';\nexport * from './event-builder.js';\nexport { fetchExperience } from './fetch-experience.js';\nexport { 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
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { ContentfulViewDelivery } from '@contentful/experience-delivery';\n\nexport {\n ContentfulViewDelivery,\n ContentfulViewDeliveryClient,\n} from '@contentful/experience-delivery';\nexport const NotFoundError = ContentfulViewDelivery.NotFoundError;\n// eslint-disable-next-line no-redeclare -- value + type share a name across separate TS namespaces, not a real redeclaration\nexport type NotFoundError = InstanceType<typeof ContentfulViewDelivery.NotFoundError>;\nexport { ExperienceFetchError, DestinationPreviewNotSupportedError } from './errors.js';\nexport { ANONYMOUS_ID_COOKIE, PROFILE_CACHE_KEY } from './constants.js';\nexport { createClient } from './create-delivery-client.js';\nexport type {\n CreateClientOptions,\n RuntimeDeliveryClientOptions,\n} from './create-delivery-client.js';\nexport type { RuntimeOptimizationConfig } from './create-optimization-client.js';\nexport { default as EventBuilder } from './event-builder.js';\nexport * from './event-builder.js';\nexport { fetchExperience } from './fetch-experience.js';\nexport { fetchDestinationSitemap } from './fetch-destination-sitemap.js';\nexport type {\n FetchDestinationSitemapOptions,\n FetchDestinationSitemapPaginationOptions,\n SitemapPathItem,\n DestinationSitemapResult,\n} from './fetch-destination-sitemap.js';\nexport { ContentfulExperiences } from './contentful-experiences.js';\nexport type {\n ContentfulExperiencesConfig,\n ExperienceRuntime,\n RuntimeFetchExperienceOptions,\n RuntimeFetchByDestinationNodeOptions,\n RuntimeFetchByDestinationPathOptions,\n RuntimeEventBuilderConfig,\n RuntimeResolveOptions,\n} from './contentful-experiences.js';\nexport { EventProfileRequiredError, EventProfileSchema } from './runtime-event-methods.js';\nexport type {\n EventOptimizationData,\n EventProfile,\n AnalyticsEventMethod,\n PersonalizationEventMethod,\n RuntimeEventBindings,\n RuntimeEventMethods,\n} from './runtime-event-methods.js';\nexport {\n assertRuntimeEventHandoffSize,\n parseRuntimeEventHandoff,\n RUNTIME_EVENT_HANDOFF_VERSION,\n} from './runtime-event-handoff.js';\nexport type {\n RuntimeEventHandoff,\n RuntimeEventHandoffEvent,\n RuntimeEventHandoffReceipt,\n RuntimeServerEventDelivery,\n} from './runtime-event-handoff.js';\nexport {\n readSourceMap,\n toExperiencePayload,\n toExperiencePayloadFromDestination,\n} from './to-experience-payload.js';\nexport type { ExperienceResponse } from './to-experience-payload.js';\nexport type {\n ExperienceOptions,\n ExperienceRequestExtensions,\n PersonalizationOptions,\n ByIdExperienceOptions,\n ByDestinationNodeIdExperienceOptions,\n ByDestinationPathExperienceOptions,\n ClientOptions,\n ResolveOptions,\n DestinationRedirectResult,\n} from './fetch-experience.js';\nexport { DELIVERY_HOST, PREVIEW_HOST, PREVIEW_WEBSOCKET_HOST } from './hosts.js';\n"],"mappings":"AAAA,SAAS,8BAA8B;AAEvC;AAAA,EACE,0BAAAA;AAAA,EACA;AAAA,OACK;AACA,MAAM,gBAAgB,uBAAuB;AAGpD,SAAS,sBAAsB,2CAA2C;AAC1E,SAAS,qBAAqB,yBAAyB;AACvD,SAAS,oBAAoB;AAM7B,SAAoB,WAAXC,gBAA+B;AACxC,cAAc;AACd,SAAS,uBAAuB;AAChC,SAAS,+BAA+B;AAOxC,SAAS,6BAA6B;AAUtC,SAAS,2BAA2B,0BAA0B;AAS9D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAOP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAaP,SAAS,eAAe,cAAc,8BAA8B;","names":["ContentfulViewDelivery","default"]}
|
package/dist/sdk-info.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/experiences-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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.
|
|
34
|
+
"@contentful/experiences-sdk-core": "0.12.0",
|
|
35
35
|
"@contentful/optimization-api-client": "^2.0.1",
|
|
36
36
|
"es-toolkit": "^1.46.0",
|
|
37
37
|
"zod": "^4.3.6"
|