@contentful/experiences-client 0.1.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 +15 -0
- package/README.md +117 -0
- package/dist/create-client.d.ts +9 -0
- package/dist/create-client.js +13 -0
- package/dist/create-client.js.map +1 -0
- package/dist/fetch-experience.d.ts +22 -0
- package/dist/fetch-experience.js +15 -0
- package/dist/fetch-experience.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/package.json +36 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
## 0.1.1 (2026-07-17)
|
|
2
|
+
|
|
3
|
+
### 🧱 Updated Dependencies
|
|
4
|
+
|
|
5
|
+
- Updated core to 0.5.1
|
|
6
|
+
|
|
7
|
+
## 0.1.0 (2026-07-17)
|
|
8
|
+
|
|
9
|
+
### 🚀 Features
|
|
10
|
+
|
|
11
|
+
- add packages/client with fetchExperience and delivery client [AIS-147] ([#30](https://github.com/contentful/experiences/pull/30), [#27](https://github.com/contentful/experiences/issues/27))
|
|
12
|
+
|
|
13
|
+
### 🧱 Updated Dependencies
|
|
14
|
+
|
|
15
|
+
- Updated core to 0.5.0
|
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# @contentful/experiences-client
|
|
2
|
+
|
|
3
|
+
> **Internal package.** Published to npm so framework adapters can resolve it at install time, but not intended for direct customer import. Consumed transitively via the framework adapter (`@contentful/experiences-react`, `@contentful/experiences-svelte`, etc.).
|
|
4
|
+
|
|
5
|
+
Isolates `@contentful/experience-delivery` — the generated experience delivery client — so that `@contentful/experiences-core` stays zero-dep and framework adapters that don't need network access don't pull it in transitively.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## What's in here
|
|
10
|
+
|
|
11
|
+
### `fetchExperience(experienceOptions, clientOptions, resolveOptions)`
|
|
12
|
+
|
|
13
|
+
The primary fetch + resolve entry point. Fetches an Experience payload from the Experience Delivery API and resolves it into a `PortableRenderPlan` in one call.
|
|
14
|
+
|
|
15
|
+
Three positional args group by concern:
|
|
16
|
+
|
|
17
|
+
| Arg | Type | Purpose |
|
|
18
|
+
| ------------------- | --------------------------------------------------- | ------------------------------------------------- |
|
|
19
|
+
| `experienceOptions` | `{ spaceId, environmentId, experienceId, locale? }` | Which Experience to fetch. |
|
|
20
|
+
| `clientOptions` | `{ accessToken, host? }` **or** `{ client }` | How to fetch — inline creds or a pre-made client. |
|
|
21
|
+
| `resolveOptions` | `{ config, context? }` | How to resolve — component registry + context. |
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { fetchExperience } from '@contentful/experiences-react'; // or experiences-svelte
|
|
25
|
+
|
|
26
|
+
// Inline credentials — client created internally
|
|
27
|
+
const plan = await fetchExperience(
|
|
28
|
+
{ spaceId: '...', environmentId: 'master', experienceId: slug, locale: 'en-US' },
|
|
29
|
+
{
|
|
30
|
+
accessToken: process.env.CDA_TOKEN!,
|
|
31
|
+
host: 'https://preview.xdn.contentful.com', // optional — omit for default endpoint
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
config: experienceConfig,
|
|
35
|
+
context: { isPreview: false, metadata: { slug } }, // flows into resolveData hooks
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// Pre-created client — useful when you manage the client lifecycle yourself
|
|
40
|
+
import { createClient } from '@contentful/experiences-react';
|
|
41
|
+
const client = createClient({ accessToken: process.env.CDA_TOKEN! });
|
|
42
|
+
const plan = await fetchExperience(
|
|
43
|
+
{ spaceId, environmentId, experienceId },
|
|
44
|
+
{ client },
|
|
45
|
+
{ config: experienceConfig }
|
|
46
|
+
);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Returns `PortableRenderPlan`. An empty-nodes payload (draft / unpublished / empty locale) resolves to a valid plan with `nodes: []` — it is not a 404. For the missing-experience case, catch `NotFoundError` (re-exported below).
|
|
50
|
+
|
|
51
|
+
### `createClient(options)`
|
|
52
|
+
|
|
53
|
+
Functional constructor over `ContentfulViewDeliveryClient` matching the SDK's option shape. Maps `accessToken → token` and `host → baseUrl`; passes everything else through unchanged. Prefer over `new ContentfulViewDeliveryClient({...})` so field names stay consistent with `fetchExperience`'s inline-creds path.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { createClient } from '@contentful/experiences-react';
|
|
57
|
+
|
|
58
|
+
const client = createClient({
|
|
59
|
+
accessToken: process.env.CDA_TOKEN!,
|
|
60
|
+
host: 'https://preview.xdn.contentful.com', // optional
|
|
61
|
+
// headers, timeoutInSeconds, maxRetries, fetch, logging pass through
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### `NotFoundError`
|
|
66
|
+
|
|
67
|
+
Re-exported from `@contentful/experience-delivery` as a value + type. Thrown by the underlying delivery client on 404 responses. Route it to your framework's 404 idiom:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { fetchExperience, NotFoundError } from '@contentful/experiences-react';
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const experience = await fetchExperience(/* … */);
|
|
74
|
+
// …
|
|
75
|
+
} catch (err) {
|
|
76
|
+
if (err instanceof NotFoundError) notFound(); // Next.js
|
|
77
|
+
throw err;
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The full delivery-client error namespace is also re-exported as `ContentfulViewDelivery` (`UnauthorizedError`, `ForbiddenError`, `ConflictError`, `UnprocessableEntityError`, `InternalServerError`, `ContentfulViewDeliveryError`, `ContentfulViewDeliveryTimeoutError`).
|
|
82
|
+
|
|
83
|
+
### `ContentfulViewDeliveryClient`
|
|
84
|
+
|
|
85
|
+
Re-exported directly from `@contentful/experience-delivery`. Exposed for advanced use cases where you want full control over the client (custom base URL, request options, reuse across calls). Most consumers should prefer `createClient` (above).
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import { ContentfulViewDeliveryClient } from '@contentful/experiences-react';
|
|
89
|
+
|
|
90
|
+
const client = new ContentfulViewDeliveryClient({
|
|
91
|
+
token: process.env.CDA_TOKEN!,
|
|
92
|
+
baseUrl: 'https://xdn.contentful.com', // default delivery endpoint
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Why a separate package?
|
|
99
|
+
|
|
100
|
+
`@contentful/experiences-core` is intentionally zero-dep and runtime-neutral — it must stay importable without pulling in any network or platform code. The experience delivery client is large (~3,000 generated files) and only needed when doing server-side fetching. Isolating it here means:
|
|
101
|
+
|
|
102
|
+
- Core stays lean and usable in any environment (edge, SSR, test fixtures).
|
|
103
|
+
- Future adapters that render from local fixtures or a custom fetch path don't pay the delivery client's weight.
|
|
104
|
+
- The delivery client version can be bumped in one place.
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Package conventions
|
|
109
|
+
|
|
110
|
+
- Do not import `@contentful/experience-delivery` from anywhere except this package.
|
|
111
|
+
- Re-export only what framework adapters need to surface to customers.
|
|
112
|
+
- Keep `fetchExperience` thin — fetch + cast + resolve. Business logic belongs in `packages/core`.
|
|
113
|
+
- Name mappings between SDK options and delivery-client options live in `create-client.ts` — one place to change.
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
MIT. See the repository [`LICENSE`](../../LICENSE) and [`NOTICE`](../../NOTICE) for full attribution.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';
|
|
2
|
+
|
|
3
|
+
type CreateClientOptions = {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
host?: string;
|
|
6
|
+
} & Omit<ContentfulViewDeliveryClient.Options, 'token' | 'baseUrl'>;
|
|
7
|
+
declare function createClient(options: CreateClientOptions): ContentfulViewDeliveryClient;
|
|
8
|
+
|
|
9
|
+
export { type CreateClientOptions, createClient };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ContentfulViewDeliveryClient } from "@contentful/experience-delivery";
|
|
2
|
+
function createClient(options) {
|
|
3
|
+
const { accessToken, host, ...rest } = options;
|
|
4
|
+
return new ContentfulViewDeliveryClient({
|
|
5
|
+
...rest,
|
|
6
|
+
token: accessToken,
|
|
7
|
+
baseUrl: host
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
createClient
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=create-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/create-client.ts"],"sourcesContent":["import { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';\n\nexport type CreateClientOptions = {\n accessToken: string;\n host?: string;\n} & Omit<ContentfulViewDeliveryClient.Options, 'token' | 'baseUrl'>;\n\nexport function createClient(options: CreateClientOptions): ContentfulViewDeliveryClient {\n const { accessToken, host, ...rest } = options;\n return new ContentfulViewDeliveryClient({\n ...rest,\n token: accessToken,\n baseUrl: host,\n });\n}\n"],"mappings":"AAAA,SAAS,oCAAoC;AAOtC,SAAS,aAAa,SAA4D;AACvF,QAAM,EAAE,aAAa,MAAM,GAAG,KAAK,IAAI;AACvC,SAAO,IAAI,6BAA6B;AAAA,IACtC,GAAG;AAAA,IACH,OAAO;AAAA,IACP,SAAS;AAAA,EACX,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';
|
|
2
|
+
import { ResolverConfig, ResolveExperienceOptions, PortableRenderPlan } from '@contentful/experiences-core';
|
|
3
|
+
|
|
4
|
+
type ExperienceOptions = {
|
|
5
|
+
spaceId: string;
|
|
6
|
+
environmentId: string;
|
|
7
|
+
experienceId: string;
|
|
8
|
+
locale?: string;
|
|
9
|
+
};
|
|
10
|
+
type ClientOptions = {
|
|
11
|
+
accessToken: string;
|
|
12
|
+
host?: string;
|
|
13
|
+
} | {
|
|
14
|
+
client: ContentfulViewDeliveryClient;
|
|
15
|
+
};
|
|
16
|
+
type ResolveOptions = {
|
|
17
|
+
config: ResolverConfig;
|
|
18
|
+
context?: ResolveExperienceOptions['experience'];
|
|
19
|
+
};
|
|
20
|
+
declare function fetchExperience(experienceOptions: ExperienceOptions, clientOptions: ClientOptions, resolveOptions: ResolveOptions): Promise<PortableRenderPlan>;
|
|
21
|
+
|
|
22
|
+
export { type ClientOptions, type ExperienceOptions, type ResolveOptions, fetchExperience };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { resolveExperience } from "@contentful/experiences-core";
|
|
2
|
+
import { createClient } from "./create-client.js";
|
|
3
|
+
async function fetchExperience(experienceOptions, clientOptions, resolveOptions) {
|
|
4
|
+
const { spaceId, environmentId, experienceId, locale } = experienceOptions;
|
|
5
|
+
const { config, context } = resolveOptions;
|
|
6
|
+
const client = "client" in clientOptions ? clientOptions.client : createClient({ accessToken: clientOptions.accessToken, host: clientOptions.host });
|
|
7
|
+
const payload = await client.view.getExperience(spaceId, environmentId, experienceId, {
|
|
8
|
+
locale
|
|
9
|
+
});
|
|
10
|
+
return resolveExperience(payload, config, { experience: context });
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
fetchExperience
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=fetch-experience.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/fetch-experience.ts"],"sourcesContent":["import type { ContentfulViewDeliveryClient } from '@contentful/experience-delivery';\nimport { resolveExperience } from '@contentful/experiences-core';\nimport type {\n ExperiencePayload,\n PortableRenderPlan,\n ResolveExperienceOptions,\n ResolverConfig,\n} from '@contentful/experiences-core';\nimport { createClient } from './create-client.js';\n\nexport type ExperienceOptions = {\n spaceId: string;\n environmentId: string;\n experienceId: string;\n locale?: string;\n};\n\nexport type ClientOptions =\n | { accessToken: string; host?: string }\n | { client: ContentfulViewDeliveryClient };\n\nexport type ResolveOptions = {\n config: ResolverConfig;\n context?: ResolveExperienceOptions['experience'];\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, context } = resolveOptions;\n\n const client =\n 'client' in clientOptions\n ? clientOptions.client\n : createClient({ accessToken: clientOptions.accessToken, host: clientOptions.host });\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 return resolveExperience(payload, config, { experience: context });\n}\n"],"mappings":"AACA,SAAS,yBAAyB;AAOlC,SAAS,oBAAoB;AAkB7B,eAAsB,gBACpB,mBACA,eACA,gBAC6B;AAC7B,QAAM,EAAE,SAAS,eAAe,cAAc,OAAO,IAAI;AACzD,QAAM,EAAE,QAAQ,QAAQ,IAAI;AAE5B,QAAM,SACJ,YAAY,gBACR,cAAc,SACd,aAAa,EAAE,aAAa,cAAc,aAAa,MAAM,cAAc,KAAK,CAAC;AAGvF,QAAM,UAAW,MAAM,OAAO,KAAK,cAAc,SAAS,eAAe,cAAc;AAAA,IACrF;AAAA,EACF,CAAC;AAED,SAAO,kBAAkB,SAAS,QAAQ,EAAE,YAAY,QAAQ,CAAC;AACnE;","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ContentfulViewDelivery } from '@contentful/experience-delivery';
|
|
2
|
+
export { ContentfulViewDelivery, ContentfulViewDeliveryClient } from '@contentful/experience-delivery';
|
|
3
|
+
export { CreateClientOptions, createClient } from './create-client.js';
|
|
4
|
+
export { ClientOptions, ExperienceOptions, ResolveOptions, fetchExperience } from './fetch-experience.js';
|
|
5
|
+
import '@contentful/experiences-core';
|
|
6
|
+
|
|
7
|
+
declare const NotFoundError: typeof ContentfulViewDelivery.NotFoundError;
|
|
8
|
+
type NotFoundError = InstanceType<typeof ContentfulViewDelivery.NotFoundError>;
|
|
9
|
+
|
|
10
|
+
export { NotFoundError };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ContentfulViewDelivery } from "@contentful/experience-delivery";
|
|
2
|
+
import {
|
|
3
|
+
ContentfulViewDelivery as ContentfulViewDelivery2,
|
|
4
|
+
ContentfulViewDeliveryClient
|
|
5
|
+
} from "@contentful/experience-delivery";
|
|
6
|
+
const NotFoundError = ContentfulViewDelivery.NotFoundError;
|
|
7
|
+
import { createClient } from "./create-client.js";
|
|
8
|
+
import { fetchExperience } from "./fetch-experience.js";
|
|
9
|
+
export {
|
|
10
|
+
ContentfulViewDelivery2 as ContentfulViewDelivery,
|
|
11
|
+
ContentfulViewDeliveryClient,
|
|
12
|
+
NotFoundError,
|
|
13
|
+
createClient,
|
|
14
|
+
fetchExperience
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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;\nexport type NotFoundError = InstanceType<typeof ContentfulViewDelivery.NotFoundError>;\nexport { createClient } from './create-client.js';\nexport type { CreateClientOptions } from './create-client.js';\nexport { fetchExperience } from './fetch-experience.js';\nexport type { ExperienceOptions, ClientOptions, ResolveOptions } from './fetch-experience.js';\n"],"mappings":"AAAA,SAAS,8BAA8B;AAEvC;AAAA,EACE,0BAAAA;AAAA,EACA;AAAA,OACK;AACA,MAAM,gBAAgB,uBAAuB;AAEpD,SAAS,oBAAoB;AAE7B,SAAS,uBAAuB;","names":["ContentfulViewDelivery"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@contentful/experiences-client",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Delivery client + fetchExperience for Contentful Experiences",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md",
|
|
22
|
+
"CHANGELOG.md"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/contentful/experiences.git",
|
|
30
|
+
"directory": "packages/client"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@contentful/experience-delivery": "1.0.0-dev.3",
|
|
34
|
+
"@contentful/experiences-core": "0.5.1"
|
|
35
|
+
}
|
|
36
|
+
}
|