@contentful/experiences-client 0.1.7 → 0.2.0
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 +38 -0
- package/README.md +3 -2
- package/dist/fetch-experience.d.ts +15 -2
- package/dist/fetch-experience.js +10 -4
- package/dist/fetch-experience.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
+
## 0.2.0 (2026-08-05)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- ⚠️ replace isPreview with top-level debug mode [AIS-243] ([#98](https://github.com/contentful/experiences/pull/98))
|
|
6
|
+
|
|
7
|
+
### ⚠️ Breaking Changes
|
|
8
|
+
|
|
9
|
+
- replace isPreview with top-level debug mode [AIS-243] ([#98](https://github.com/contentful/experiences/pull/98))
|
|
10
|
+
`isPreview` is removed from the render context and the nested
|
|
11
|
+
`context` option is gone. Pass `metadata` and `debug` as top-level options on
|
|
12
|
+
`fetchExperience`/`resolveExperience` and as props on the renderers.
|
|
13
|
+
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
|
14
|
+
* refactor: derive metadata once in sveltekit apps
|
|
15
|
+
Extract a single `metadata` object in the loaders and thread it through
|
|
16
|
+
both fetchExperience and the renderer, instead of duplicating the
|
|
17
|
+
`{ slug }` literal in +page.svelte. Addresses PR review feedback.
|
|
18
|
+
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
|
19
|
+
* refactor: mount DebugExperience above the tree and aggregate resolveData timing
|
|
20
|
+
Move the auto-mounted <DebugExperience> panel above the rendered tree in
|
|
21
|
+
both React and Svelte renderers (client + server) so the debug dump is
|
|
22
|
+
visible without scrolling past the experience. Update the doc comments
|
|
23
|
+
and README to match.
|
|
24
|
+
Replace per-node resolveData timing lines with a single aggregate span
|
|
25
|
+
over the whole fan-out — keeps the timing signal without emitting a log
|
|
26
|
+
line per node, which gets noisy on large trees.
|
|
27
|
+
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
|
28
|
+
|
|
29
|
+
### 🧱 Updated Dependencies
|
|
30
|
+
|
|
31
|
+
- Updated core to 0.6.0
|
|
32
|
+
|
|
33
|
+
## 0.1.8 (2026-08-04)
|
|
34
|
+
|
|
35
|
+
### 🧱 Updated Dependencies
|
|
36
|
+
|
|
37
|
+
- Updated core to 0.5.6
|
|
38
|
+
|
|
1
39
|
## 0.1.7 (2026-08-03)
|
|
2
40
|
|
|
3
41
|
### 🧱 Updated Dependencies
|
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ Three positional args group by concern:
|
|
|
18
18
|
| ------------------- | --------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
|
|
19
19
|
| `experienceOptions` | `{ spaceId, environmentId, experienceId, locale? }` | Which Experience to fetch. |
|
|
20
20
|
| `clientOptions` | `{ accessToken, previewToken?, preview?, host? }` **or** `{ client }` | How to fetch — inline credentials (with optional preview toggle) or a pre-made client. |
|
|
21
|
-
| `resolveOptions` | `{ config,
|
|
21
|
+
| `resolveOptions` | `{ config, metadata?, debug? }` | How to resolve — component registry, per-render `metadata`, and a `debug` switch. |
|
|
22
22
|
|
|
23
23
|
```ts
|
|
24
24
|
import { fetchExperience } from '@contentful/experiences-react'; // or experiences-svelte
|
|
@@ -33,7 +33,8 @@ const plan = await fetchExperience(
|
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
35
|
config: experienceConfig,
|
|
36
|
-
|
|
36
|
+
metadata: { slug }, // flows into resolveData hooks as ctx.experience.metadata
|
|
37
|
+
debug: false, // logs + visible missing-component box when true
|
|
37
38
|
}
|
|
38
39
|
);
|
|
39
40
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';
|
|
2
|
-
import { ResolverConfig,
|
|
2
|
+
import { ResolverConfig, PortableRenderPlan } from '@contentful/experiences-sdk-core';
|
|
3
3
|
|
|
4
4
|
type ExperienceOptions = {
|
|
5
5
|
spaceId: string;
|
|
@@ -32,7 +32,20 @@ type ClientOptions = {
|
|
|
32
32
|
};
|
|
33
33
|
type ResolveOptions = {
|
|
34
34
|
config: ResolverConfig;
|
|
35
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Arbitrary per-render metadata exposed to every resolver as
|
|
37
|
+
* `ctx.experience.metadata` and readable at render time via the framework
|
|
38
|
+
* adapter's `useExperience()` / `getExperience()`. Flattened to a top-level
|
|
39
|
+
* option (previously nested under `context.metadata`).
|
|
40
|
+
*/
|
|
41
|
+
metadata?: Record<string, unknown>;
|
|
42
|
+
/**
|
|
43
|
+
* Observability switch. When on: logs the fetch (host, ids) and the raw
|
|
44
|
+
* payload here, and threads through to `resolveExperience` (resolution steps
|
|
45
|
+
* + `resolveData` timings) and the renderer (visible missing-component box,
|
|
46
|
+
* debug fallback). A single boolean across fetch + resolve + render.
|
|
47
|
+
*/
|
|
48
|
+
debug?: boolean;
|
|
36
49
|
};
|
|
37
50
|
declare function fetchExperience(experienceOptions: ExperienceOptions, clientOptions: ClientOptions, resolveOptions: ResolveOptions): Promise<PortableRenderPlan>;
|
|
38
51
|
|
package/dist/fetch-experience.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { resolveExperience } from "@contentful/experiences-sdk-core";
|
|
1
|
+
import { createDebugLogger, resolveExperience } from "@contentful/experiences-sdk-core";
|
|
2
2
|
import { createClient } from "./create-client.js";
|
|
3
3
|
import { PREVIEW_HOST } from "./hosts.js";
|
|
4
4
|
async function fetchExperience(experienceOptions, clientOptions, resolveOptions) {
|
|
5
5
|
const { spaceId, environmentId, experienceId, locale } = experienceOptions;
|
|
6
|
-
const { config,
|
|
6
|
+
const { config, metadata, debug } = resolveOptions;
|
|
7
|
+
const log = createDebugLogger(debug, "client");
|
|
7
8
|
let client;
|
|
8
9
|
if ("client" in clientOptions) {
|
|
9
10
|
client = clientOptions.client;
|
|
11
|
+
log.log("using caller-supplied delivery client");
|
|
10
12
|
} else {
|
|
11
13
|
const { accessToken, previewToken, preview, host } = clientOptions;
|
|
12
14
|
if (preview && !previewToken) {
|
|
@@ -14,15 +16,19 @@ async function fetchExperience(experienceOptions, clientOptions, resolveOptions)
|
|
|
14
16
|
"fetchExperience() called with preview: true but no previewToken was provided"
|
|
15
17
|
);
|
|
16
18
|
}
|
|
19
|
+
const resolvedHost = host ?? (preview ? PREVIEW_HOST : void 0);
|
|
17
20
|
client = createClient({
|
|
18
21
|
accessToken: preview ? previewToken : accessToken,
|
|
19
|
-
host:
|
|
22
|
+
host: resolvedHost
|
|
20
23
|
});
|
|
24
|
+
log.log("created delivery client", { preview: Boolean(preview), host: resolvedHost });
|
|
21
25
|
}
|
|
26
|
+
log.log("fetching experience", { spaceId, environmentId, experienceId, locale });
|
|
22
27
|
const payload = await client.view.getExperience(spaceId, environmentId, experienceId, {
|
|
23
28
|
locale
|
|
24
29
|
});
|
|
25
|
-
|
|
30
|
+
log.lazy("received raw payload", () => payload);
|
|
31
|
+
return resolveExperience(payload, config, { metadata, debug });
|
|
26
32
|
}
|
|
27
33
|
export {
|
|
28
34
|
fetchExperience
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/fetch-experience.ts"],"sourcesContent":["import type { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';\nimport { resolveExperience } from '@contentful/experiences-sdk-core';\nimport type {\n ExperiencePayload,\n PortableRenderPlan,\n
|
|
1
|
+
{"version":3,"sources":["../src/fetch-experience.ts"],"sourcesContent":["import type { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';\nimport { createDebugLogger, resolveExperience } from '@contentful/experiences-sdk-core';\nimport type {\n ExperiencePayload,\n PortableRenderPlan,\n ResolverConfig,\n} from '@contentful/experiences-sdk-core';\nimport { createClient } from './create-client.js';\nimport { PREVIEW_HOST } from './hosts.js';\n\nexport type ExperienceOptions = {\n spaceId: string;\n environmentId: string;\n experienceId: string;\n locale?: 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()`. Flattened to a top-level\n * option (previously nested under `context.metadata`).\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\nexport async function fetchExperience(\n experienceOptions: ExperienceOptions,\n clientOptions: ClientOptions,\n resolveOptions: ResolveOptions\n): Promise<PortableRenderPlan> {\n const { spaceId, environmentId, experienceId, locale } = experienceOptions;\n const { config, metadata, debug } = resolveOptions;\n const log = createDebugLogger(debug, 'client');\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 log.log('fetching experience', { spaceId, environmentId, experienceId, locale });\n\n // Response from the experience delivery client is structurally compatible with ExperiencePayload (superset)\n const payload = (await client.view.getExperience(spaceId, environmentId, experienceId, {\n locale,\n })) as unknown as ExperiencePayload;\n\n log.lazy('received raw payload', () => payload);\n\n return resolveExperience(payload, config, { metadata, debug });\n}\n"],"mappings":"AACA,SAAS,mBAAmB,yBAAyB;AAMrD,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAmD7B,eAAsB,gBACpB,mBACA,eACA,gBAC6B;AAC7B,QAAM,EAAE,SAAS,eAAe,cAAc,OAAO,IAAI;AACzD,QAAM,EAAE,QAAQ,UAAU,MAAM,IAAI;AACpC,QAAM,MAAM,kBAAkB,OAAO,QAAQ;AAE7C,MAAI;AACJ,MAAI,YAAY,eAAe;AAC7B,aAAS,cAAc;AACvB,QAAI,IAAI,uCAAuC;AAAA,EACjD,OAAO;AACL,UAAM,EAAE,aAAa,cAAc,SAAS,KAAK,IAAI;AACrD,QAAI,WAAW,CAAC,cAAc;AAC5B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACA,UAAM,eAAe,SAAS,UAAU,eAAe;AACvD,aAAS,aAAa;AAAA,MACpB,aAAa,UAAW,eAA0B;AAAA,MAClD,MAAM;AAAA,IACR,CAAC;AACD,QAAI,IAAI,2BAA2B,EAAE,SAAS,QAAQ,OAAO,GAAG,MAAM,aAAa,CAAC;AAAA,EACtF;AAEA,MAAI,IAAI,uBAAuB,EAAE,SAAS,eAAe,cAAc,OAAO,CAAC;AAG/E,QAAM,UAAW,MAAM,OAAO,KAAK,cAAc,SAAS,eAAe,cAAc;AAAA,IACrF;AAAA,EACF,CAAC;AAED,MAAI,KAAK,wBAAwB,MAAM,OAAO;AAE9C,SAAO,kBAAkB,SAAS,QAAQ,EAAE,UAAU,MAAM,CAAC;AAC/D;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/experiences-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Delivery client + fetchExperience for Contentful Experiences",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -31,6 +31,6 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@contentful/experience-delivery": "1.0.0-dev.3",
|
|
34
|
-
"@contentful/experiences-sdk-core": "0.
|
|
34
|
+
"@contentful/experiences-sdk-core": "0.6.0"
|
|
35
35
|
}
|
|
36
36
|
}
|