@ebitex/content-sdk 0.1.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/README.md +62 -0
- package/dist/content/cache.d.ts +26 -0
- package/dist/content/cache.d.ts.map +1 -0
- package/dist/content/cache.js +107 -0
- package/dist/content/cache.js.map +1 -0
- package/dist/content/client.d.ts +78 -0
- package/dist/content/client.d.ts.map +1 -0
- package/dist/content/client.js +150 -0
- package/dist/content/client.js.map +1 -0
- package/dist/content/locale.d.ts +18 -0
- package/dist/content/locale.d.ts.map +1 -0
- package/dist/content/locale.js +54 -0
- package/dist/content/locale.js.map +1 -0
- package/dist/content/overlay.d.ts +16 -0
- package/dist/content/overlay.d.ts.map +1 -0
- package/dist/content/overlay.js +20 -0
- package/dist/content/overlay.js.map +1 -0
- package/dist/content/site.d.ts +15 -0
- package/dist/content/site.d.ts.map +1 -0
- package/dist/content/site.js +26 -0
- package/dist/content/site.js.map +1 -0
- package/dist/content/strategy.d.ts +24 -0
- package/dist/content/strategy.d.ts.map +1 -0
- package/dist/content/strategy.js +15 -0
- package/dist/content/strategy.js.map +1 -0
- package/dist/delivery/client.d.ts +61 -0
- package/dist/delivery/client.d.ts.map +1 -0
- package/dist/delivery/client.js +88 -0
- package/dist/delivery/client.js.map +1 -0
- package/dist/delivery/query.d.ts +21 -0
- package/dist/delivery/query.d.ts.map +1 -0
- package/dist/delivery/query.js +49 -0
- package/dist/delivery/query.js.map +1 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +46 -0
- package/dist/errors.js.map +1 -0
- package/dist/guards.d.ts +42 -0
- package/dist/guards.d.ts.map +1 -0
- package/dist/guards.js +75 -0
- package/dist/guards.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/react/ContentProvider.d.ts +43 -0
- package/dist/react/ContentProvider.d.ts.map +1 -0
- package/dist/react/ContentProvider.js +36 -0
- package/dist/react/ContentProvider.js.map +1 -0
- package/dist/react/Experience.d.ts +54 -0
- package/dist/react/Experience.d.ts.map +1 -0
- package/dist/react/Experience.js +99 -0
- package/dist/react/Experience.js.map +1 -0
- package/dist/react/PresentationList.d.ts +14 -0
- package/dist/react/PresentationList.d.ts.map +1 -0
- package/dist/react/PresentationList.js +20 -0
- package/dist/react/PresentationList.js.map +1 -0
- package/dist/react/RenderPresentation.d.ts +20 -0
- package/dist/react/RenderPresentation.d.ts.map +1 -0
- package/dist/react/RenderPresentation.js +59 -0
- package/dist/react/RenderPresentation.js.map +1 -0
- package/dist/react/Resolve.d.ts +34 -0
- package/dist/react/Resolve.d.ts.map +1 -0
- package/dist/react/Resolve.js +79 -0
- package/dist/react/Resolve.js.map +1 -0
- package/dist/react/RichText.d.ts +19 -0
- package/dist/react/RichText.d.ts.map +1 -0
- package/dist/react/RichText.js +37 -0
- package/dist/react/RichText.js.map +1 -0
- package/dist/react/index.d.ts +15 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +15 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/panels.d.ts +47 -0
- package/dist/react/panels.d.ts.map +1 -0
- package/dist/react/panels.js +92 -0
- package/dist/react/panels.js.map +1 -0
- package/dist/react/registry.d.ts +58 -0
- package/dist/react/registry.d.ts.map +1 -0
- package/dist/react/registry.js +92 -0
- package/dist/react/registry.js.map +1 -0
- package/dist/types.d.ts +187 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# @ebitex/content-sdk
|
|
2
|
+
|
|
3
|
+
Consume published [ebitex](https://ebitex.io) Content from your own site: a typed client for the
|
|
4
|
+
Content Delivery API and React utilities that render a delivered page by dispatching each
|
|
5
|
+
Presentation to a component you provide.
|
|
6
|
+
|
|
7
|
+
Two entry points:
|
|
8
|
+
|
|
9
|
+
- **`@ebitex/content-sdk`** — the clients. `createDeliveryClient` is one method per endpoint;
|
|
10
|
+
`createContentClient` adds site/locale/context resolution, a resolve strategy, caching and
|
|
11
|
+
cancellation, and `resolveLocation(location)` to call on every router change. No React.
|
|
12
|
+
- **`@ebitex/content-sdk/react`** — `<ContentProvider>`, `<Experience>`, `<RenderPresentation>`,
|
|
13
|
+
`<PresentationList>`, `<RichText>`, `<Resolve>`, and a guiding fallback for every Presentation
|
|
14
|
+
that cannot be rendered. React is a peer dependency, never bundled.
|
|
15
|
+
|
|
16
|
+
A **browser-safe** delivery key (one with an allowed-origins or allowed-IP-ranges restriction) may
|
|
17
|
+
ship in a bundle. A key with neither restriction is a **server-side key** and must never reach a
|
|
18
|
+
browser. Create either in Content → Delivery.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
npm install @ebitex/content-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick start
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
import { createContentClient } from '@ebitex/content-sdk'
|
|
30
|
+
import { ContentProvider, Experience, renderersFromGlob } from '@ebitex/content-sdk/react'
|
|
31
|
+
|
|
32
|
+
const content = createContentClient({ apiKey: import.meta.env.VITE_CONTENT_DELIVERY_KEY })
|
|
33
|
+
const renderers = renderersFromGlob(import.meta.glob('./presentations/*.tsx'))
|
|
34
|
+
|
|
35
|
+
export function App() {
|
|
36
|
+
const location = useLocation()
|
|
37
|
+
const navigate = useNavigate()
|
|
38
|
+
return (
|
|
39
|
+
<ContentProvider client={content} renderers={renderers} markdown={Markdown}>
|
|
40
|
+
<Experience path={location.pathname} onRedirect={(to) => navigate(to, { replace: true })} />
|
|
41
|
+
</ContentProvider>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
// presentations/hero.tsx — one file per Template, named by its externalId, default export
|
|
48
|
+
import type { PresentationRenderer } from '@ebitex/content-sdk/react'
|
|
49
|
+
|
|
50
|
+
const Hero: PresentationRenderer<{ headline: string }, { theme: string }> = ({ settings, component }) => (
|
|
51
|
+
<section data-theme={settings.theme}>
|
|
52
|
+
<h1>{component.content.headline}</h1>
|
|
53
|
+
</section>
|
|
54
|
+
)
|
|
55
|
+
export default Hero
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
A Template with no renderer, an unpublished reference, a binding that needs server-side
|
|
59
|
+
resolution — each renders a panel naming the reason and the fix, so a missing piece is visible,
|
|
60
|
+
never silent.
|
|
61
|
+
|
|
62
|
+
Full guide: `docs/content-sdk.md` in the [monorepo](https://github.com/ebitex-io/monorepo).
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A keyed in-memory cache with in-flight de-duplication and per-subscriber cancellation (spec 359
|
|
3
|
+
* Business Logic §6). One entry per full request identity; concurrent callers for one key share
|
|
4
|
+
* one underlying request. Each caller may pass its own `AbortSignal`: aborting it rejects *that
|
|
5
|
+
* caller's* promise immediately, and the shared request is aborted only once every subscriber has
|
|
6
|
+
* gone — so a navigation superseded mid-flight never populates the cache, while a second
|
|
7
|
+
* component still waiting on the same key isn't cancelled by the first one leaving.
|
|
8
|
+
*/
|
|
9
|
+
export interface CacheOptions {
|
|
10
|
+
maxEntries?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class RequestCache {
|
|
13
|
+
private readonly entries;
|
|
14
|
+
private readonly maxEntries;
|
|
15
|
+
constructor(options?: CacheOptions);
|
|
16
|
+
/** Resolves `key` via `factory` (given the shared signal) unless already cached or in flight. */
|
|
17
|
+
getOrCreate<T>(key: string, factory: (signal: AbortSignal) => Promise<T>, signal?: AbortSignal): Promise<T>;
|
|
18
|
+
/** Drops one key, or everything. */
|
|
19
|
+
invalidate(key?: string): void;
|
|
20
|
+
has(key: string): boolean;
|
|
21
|
+
private subscribe;
|
|
22
|
+
/** Re-inserting moves the key to the end — `Map` iteration order is insertion order, which is what makes the eviction below LRU. */
|
|
23
|
+
private touch;
|
|
24
|
+
private evict;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/content/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoC;IAC5D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;gBAEvB,OAAO,GAAE,YAAiB;IAItC,iGAAiG;IACjG,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAiC3G,oCAAoC;IACpC,UAAU,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAQ9B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIzB,OAAO,CAAC,SAAS;IAkCjB,oIAAoI;IACpI,OAAO,CAAC,KAAK;IAQb,OAAO,CAAC,KAAK;CASd"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A keyed in-memory cache with in-flight de-duplication and per-subscriber cancellation (spec 359
|
|
3
|
+
* Business Logic §6). One entry per full request identity; concurrent callers for one key share
|
|
4
|
+
* one underlying request. Each caller may pass its own `AbortSignal`: aborting it rejects *that
|
|
5
|
+
* caller's* promise immediately, and the shared request is aborted only once every subscriber has
|
|
6
|
+
* gone — so a navigation superseded mid-flight never populates the cache, while a second
|
|
7
|
+
* component still waiting on the same key isn't cancelled by the first one leaving.
|
|
8
|
+
*/
|
|
9
|
+
export class RequestCache {
|
|
10
|
+
entries = new Map();
|
|
11
|
+
maxEntries;
|
|
12
|
+
constructor(options = {}) {
|
|
13
|
+
this.maxEntries = Math.max(1, options.maxEntries ?? 50);
|
|
14
|
+
}
|
|
15
|
+
/** Resolves `key` via `factory` (given the shared signal) unless already cached or in flight. */
|
|
16
|
+
getOrCreate(key, factory, signal) {
|
|
17
|
+
if (signal?.aborted) {
|
|
18
|
+
return Promise.reject(abortError());
|
|
19
|
+
}
|
|
20
|
+
let entry = this.entries.get(key);
|
|
21
|
+
if (entry === undefined) {
|
|
22
|
+
const controller = new AbortController();
|
|
23
|
+
const created = { controller, subscribers: 0, settled: false, promise: undefined };
|
|
24
|
+
created.promise = factory(controller.signal).then((value) => {
|
|
25
|
+
created.settled = true;
|
|
26
|
+
return value;
|
|
27
|
+
}, (error) => {
|
|
28
|
+
created.settled = true;
|
|
29
|
+
if (this.entries.get(key) === created) {
|
|
30
|
+
this.entries.delete(key); // never cache a failure, aborted or otherwise
|
|
31
|
+
}
|
|
32
|
+
throw error;
|
|
33
|
+
});
|
|
34
|
+
this.entries.set(key, created);
|
|
35
|
+
this.touch(key);
|
|
36
|
+
this.evict();
|
|
37
|
+
entry = created;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
this.touch(key);
|
|
41
|
+
}
|
|
42
|
+
return this.subscribe(entry, key, signal);
|
|
43
|
+
}
|
|
44
|
+
/** Drops one key, or everything. */
|
|
45
|
+
invalidate(key) {
|
|
46
|
+
if (key === undefined) {
|
|
47
|
+
this.entries.clear();
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this.entries.delete(key);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
has(key) {
|
|
54
|
+
return this.entries.has(key);
|
|
55
|
+
}
|
|
56
|
+
subscribe(entry, key, signal) {
|
|
57
|
+
if (signal === undefined || entry.settled) {
|
|
58
|
+
return entry.promise;
|
|
59
|
+
}
|
|
60
|
+
entry.subscribers++;
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
const onAbort = () => {
|
|
63
|
+
entry.subscribers--;
|
|
64
|
+
if (entry.subscribers <= 0 && !entry.settled) {
|
|
65
|
+
entry.controller.abort();
|
|
66
|
+
if (this.entries.get(key) === entry) {
|
|
67
|
+
this.entries.delete(key);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
reject(abortError());
|
|
71
|
+
};
|
|
72
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
73
|
+
entry.promise.then((value) => {
|
|
74
|
+
signal.removeEventListener('abort', onAbort);
|
|
75
|
+
entry.subscribers--;
|
|
76
|
+
resolve(value);
|
|
77
|
+
}, (error) => {
|
|
78
|
+
signal.removeEventListener('abort', onAbort);
|
|
79
|
+
entry.subscribers--;
|
|
80
|
+
reject(error);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/** Re-inserting moves the key to the end — `Map` iteration order is insertion order, which is what makes the eviction below LRU. */
|
|
85
|
+
touch(key) {
|
|
86
|
+
const entry = this.entries.get(key);
|
|
87
|
+
if (entry !== undefined) {
|
|
88
|
+
this.entries.delete(key);
|
|
89
|
+
this.entries.set(key, entry);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
evict() {
|
|
93
|
+
while (this.entries.size > this.maxEntries) {
|
|
94
|
+
const oldest = this.entries.keys().next().value;
|
|
95
|
+
if (oldest === undefined) {
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
this.entries.delete(oldest);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function abortError() {
|
|
103
|
+
const error = new Error('The request was aborted.');
|
|
104
|
+
error.name = 'AbortError';
|
|
105
|
+
return error;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/content/cache.ts"],"names":[],"mappings":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,MAAK;YACP,CAAC;YACD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAC7B,CAAC;IACH,CAAC;CACF;AAED,SAAS,UAAU;IACjB,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;IACnD,KAAK,CAAC,IAAI,GAAG,YAAY,CAAA;IACzB,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type DeliveryClient, type DeliveryClientOptions } from '../delivery/client.js';
|
|
2
|
+
import type { ComponentValue, ContextBag, ExpandedReference, LocaleTreeNode, PresentationEnvelope, SiteSummary } from '../types.js';
|
|
3
|
+
import { type CacheOptions } from './cache.js';
|
|
4
|
+
import { type ResolveStrategy } from './strategy.js';
|
|
5
|
+
export interface ContentClientOptions extends DeliveryClientOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The site to resolve paths against: a `rootNodeId`, or a function choosing from `GET /sites`.
|
|
8
|
+
* Omitted: the sole published site, else the one whose `hosts` contains this page's hostname.
|
|
9
|
+
* Required in Node when more than one site is published.
|
|
10
|
+
*/
|
|
11
|
+
site?: string | ((sites: SiteSummary[]) => SiteSummary | undefined);
|
|
12
|
+
/**
|
|
13
|
+
* The locale code to request: a string, or a function choosing from `GET /locales`. Omitted: the
|
|
14
|
+
* first of the browser's languages (each region tag followed by its base language) present in
|
|
15
|
+
* the organization's locale tree; nothing in Node, or when none matches (the server's default).
|
|
16
|
+
*/
|
|
17
|
+
locale?: string | ((locales: LocaleTreeNode[]) => string | undefined);
|
|
18
|
+
/** The personalization context bag, or a (possibly async) function producing it per resolve. Always sent — `{}` by default — so the server resolves personalization and tokens. */
|
|
19
|
+
context?: ContextBag | (() => ContextBag | Promise<ContextBag>);
|
|
20
|
+
/** Default `{ strategy: 'full', depth: 10 }`. */
|
|
21
|
+
resolve?: ResolveStrategy;
|
|
22
|
+
/** In-memory cache of resolved results (default 50 entries, LRU); `false` disables it. */
|
|
23
|
+
cache?: CacheOptions | false;
|
|
24
|
+
}
|
|
25
|
+
export interface ResolveOverrides {
|
|
26
|
+
context?: ContextBag;
|
|
27
|
+
locale?: string;
|
|
28
|
+
site?: string;
|
|
29
|
+
strategy?: ResolveStrategy;
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
/** Bypass (and replace) the cached result for this one request. */
|
|
32
|
+
fresh?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** The site a result was resolved against — the full summary when the SDK looked it up, or just the id when one was configured. */
|
|
35
|
+
export interface ResolvedSite {
|
|
36
|
+
rootNodeId: string;
|
|
37
|
+
name?: string;
|
|
38
|
+
hosts?: string[];
|
|
39
|
+
}
|
|
40
|
+
export interface PresentationExperience {
|
|
41
|
+
kind: 'presentation';
|
|
42
|
+
nodeId: string;
|
|
43
|
+
path: string;
|
|
44
|
+
presentation: PresentationEnvelope;
|
|
45
|
+
site: ResolvedSite;
|
|
46
|
+
locale: string | undefined;
|
|
47
|
+
strategy: ResolveStrategy;
|
|
48
|
+
}
|
|
49
|
+
/** The SDK never follows a redirect — the consumer's router owns navigation. */
|
|
50
|
+
export interface RedirectExperience {
|
|
51
|
+
kind: 'redirect';
|
|
52
|
+
targetPath: string;
|
|
53
|
+
targetNodeId: string | null;
|
|
54
|
+
}
|
|
55
|
+
export interface NotFoundExperience {
|
|
56
|
+
kind: 'notFound';
|
|
57
|
+
path: string;
|
|
58
|
+
}
|
|
59
|
+
export type ExperienceResult = PresentationExperience | RedirectExperience | NotFoundExperience;
|
|
60
|
+
export type LocationLike = string | URL | {
|
|
61
|
+
pathname: string;
|
|
62
|
+
};
|
|
63
|
+
export interface ContentClient {
|
|
64
|
+
/** The low-level client this one is built on — nothing is hidden. */
|
|
65
|
+
readonly delivery: DeliveryClient;
|
|
66
|
+
/** Resolves whatever lives at a location — invoke it on every router change. */
|
|
67
|
+
resolveLocation(location: LocationLike, overrides?: ResolveOverrides): Promise<ExperienceResult>;
|
|
68
|
+
/** Resolves one unexpanded reference (the normalized strategy), applying the descriptor's own contextual overlay. An already-resolved value is returned as-is. */
|
|
69
|
+
resolveReference(descriptor: ComponentValue, overrides?: ResolveOverrides): Promise<ExpandedReference>;
|
|
70
|
+
resolveSite(): Promise<ResolvedSite>;
|
|
71
|
+
resolveLocale(): Promise<string | undefined>;
|
|
72
|
+
/** The strategy in force for this client. */
|
|
73
|
+
readonly strategy: ResolveStrategy;
|
|
74
|
+
/** Drops every cached result and the memoized site/locale. */
|
|
75
|
+
invalidate(): void;
|
|
76
|
+
}
|
|
77
|
+
export declare function createContentClient(options: ContentClientOptions): ContentClient;
|
|
78
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/content/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAI7G,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,iBAAiB,EAAE,cAAc,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACnI,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AAI5D,OAAO,EAA2C,KAAK,eAAe,EAAE,MAAM,eAAe,CAAA;AAE7F,MAAM,WAAW,oBAAqB,SAAQ,qBAAqB;IACjE;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,WAAW,GAAG,SAAS,CAAC,CAAA;IAEnE;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,MAAM,GAAG,SAAS,CAAC,CAAA;IAErE,mLAAmL;IACnL,OAAO,CAAC,EAAE,UAAU,GAAG,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAA;IAE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IAC5B,qEAAqE;IACrE,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAA;IACjC,gFAAgF;IAChF,eAAe,CAAC,QAAQ,EAAE,YAAY,EAAE,SAAS,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAA;IAChG,kKAAkK;IAClK,gBAAgB,CAAC,UAAU,EAAE,cAAc,EAAE,SAAS,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;IACtG,WAAW,IAAI,OAAO,CAAC,YAAY,CAAC,CAAA;IACpC,aAAa,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;IAC5C,6CAA6C;IAC7C,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAA;IAClC,8DAA8D;IAC9D,UAAU,IAAI,IAAI,CAAA;CACnB;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CA0JhF"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { createDeliveryClient } from '../delivery/client.js';
|
|
2
|
+
import { normalizePath, serializeContext } from '../delivery/query.js';
|
|
3
|
+
import { ContentDeliveryError, ContentSdkError } from '../errors.js';
|
|
4
|
+
import { hasAdapter, isReference, isResolved, isUnresolvable } from '../guards.js';
|
|
5
|
+
import { RequestCache } from './cache.js';
|
|
6
|
+
import { browserLanguages, expandLanguageCandidates, selectLocale } from './locale.js';
|
|
7
|
+
import { applyContextualOverlay } from './overlay.js';
|
|
8
|
+
import { currentHostname, matchSite } from './site.js';
|
|
9
|
+
import { DEFAULT_STRATEGY, depthFor, strategyKey } from './strategy.js';
|
|
10
|
+
export function createContentClient(options) {
|
|
11
|
+
const delivery = createDeliveryClient(options);
|
|
12
|
+
const strategy = options.resolve ?? DEFAULT_STRATEGY;
|
|
13
|
+
const cache = options.cache === false ? null : new RequestCache(options.cache);
|
|
14
|
+
let sitePromise;
|
|
15
|
+
let localePromise;
|
|
16
|
+
function resolveSite() {
|
|
17
|
+
if (typeof options.site === 'string') {
|
|
18
|
+
return Promise.resolve({ rootNodeId: options.site });
|
|
19
|
+
}
|
|
20
|
+
sitePromise ??= (async () => {
|
|
21
|
+
const sites = await delivery.listSites();
|
|
22
|
+
const chosen = typeof options.site === 'function' ? options.site(sites) : matchSite(sites, currentHostname());
|
|
23
|
+
if (chosen === undefined) {
|
|
24
|
+
throw new ContentSdkError('site_unresolved', sites.length === 0
|
|
25
|
+
? 'No site is published in this delivery environment.'
|
|
26
|
+
: `More than one site is published and none is mapped to this hostname — pass \`site\` to createContentClient. Candidates: ${sites
|
|
27
|
+
.map((s) => `${s.name} (${s.rootNodeId}${s.hosts.length ? `: ${s.hosts.join(', ')}` : ''})`)
|
|
28
|
+
.join('; ')}.`, { sites });
|
|
29
|
+
}
|
|
30
|
+
return chosen;
|
|
31
|
+
})();
|
|
32
|
+
sitePromise.catch(() => {
|
|
33
|
+
sitePromise = undefined; // never memoize a failure
|
|
34
|
+
});
|
|
35
|
+
return sitePromise;
|
|
36
|
+
}
|
|
37
|
+
function resolveLocale() {
|
|
38
|
+
if (typeof options.locale === 'string') {
|
|
39
|
+
return Promise.resolve(options.locale);
|
|
40
|
+
}
|
|
41
|
+
localePromise ??= (async () => {
|
|
42
|
+
const candidates = typeof options.locale === 'function' ? null : expandLanguageCandidates(browserLanguages());
|
|
43
|
+
if (candidates !== null && candidates.length === 0) {
|
|
44
|
+
return undefined; // Node, or a browser with no languages — nothing to match, let the server default
|
|
45
|
+
}
|
|
46
|
+
const tree = await delivery.listLocales();
|
|
47
|
+
return typeof options.locale === 'function' ? options.locale(tree) : selectLocale(candidates, tree);
|
|
48
|
+
})();
|
|
49
|
+
localePromise.catch(() => {
|
|
50
|
+
localePromise = undefined;
|
|
51
|
+
});
|
|
52
|
+
return localePromise;
|
|
53
|
+
}
|
|
54
|
+
async function supplyContext(override) {
|
|
55
|
+
if (override !== undefined) {
|
|
56
|
+
return override;
|
|
57
|
+
}
|
|
58
|
+
const source = options.context;
|
|
59
|
+
if (source === undefined) {
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
return typeof source === 'function' ? await source() : source;
|
|
63
|
+
}
|
|
64
|
+
async function withCache(key, overrides, factory) {
|
|
65
|
+
if (cache === null) {
|
|
66
|
+
return factory(overrides.signal);
|
|
67
|
+
}
|
|
68
|
+
if (overrides.fresh) {
|
|
69
|
+
cache.invalidate(key);
|
|
70
|
+
}
|
|
71
|
+
return cache.getOrCreate(key, (shared) => factory(shared), overrides.signal);
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
delivery,
|
|
75
|
+
strategy,
|
|
76
|
+
resolveSite,
|
|
77
|
+
resolveLocale,
|
|
78
|
+
async resolveLocation(location, overrides = {}) {
|
|
79
|
+
const path = normalizePath(pathnameOf(location));
|
|
80
|
+
const site = overrides.site !== undefined ? { rootNodeId: overrides.site } : await resolveSite();
|
|
81
|
+
const locale = overrides.locale ?? (await resolveLocale());
|
|
82
|
+
const ctx = await supplyContext(overrides.context);
|
|
83
|
+
const effective = overrides.strategy ?? strategy;
|
|
84
|
+
const key = JSON.stringify(['path', site.rootNodeId, locale ?? '', serializeContext(ctx), strategyKey(effective), path]);
|
|
85
|
+
return withCache(key, overrides, async (signal) => {
|
|
86
|
+
try {
|
|
87
|
+
const result = await delivery.resolvePath(path, { site: site.rootNodeId, locale, ctx, resolve: depthFor(effective), signal });
|
|
88
|
+
if (result.kind === 'redirect') {
|
|
89
|
+
return { kind: 'redirect', targetPath: result.targetPath, targetNodeId: result.targetNodeId ?? null };
|
|
90
|
+
}
|
|
91
|
+
return { kind: 'presentation', nodeId: result.nodeId, path: result.path, presentation: result.presentation, site, locale, strategy: effective };
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
if (error instanceof ContentDeliveryError && error.status === 404 && error.code === 'path_not_found') {
|
|
95
|
+
return { kind: 'notFound', path };
|
|
96
|
+
}
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
async resolveReference(descriptor, overrides = {}) {
|
|
102
|
+
if (isResolved(descriptor)) {
|
|
103
|
+
return descriptor;
|
|
104
|
+
}
|
|
105
|
+
if (!isReference(descriptor) || isUnresolvable(descriptor)) {
|
|
106
|
+
throw new ContentSdkError('invalid_options', 'resolveReference needs an unexpanded reference descriptor ({ provider, key, … }).');
|
|
107
|
+
}
|
|
108
|
+
if (hasAdapter(descriptor)) {
|
|
109
|
+
throw new ContentSdkError('adapter_requires_server_resolve', `The binding to ${descriptor.provider}:${descriptor.key} carries an Adapter, which only the server can apply — use the 'full' strategy, or a normalized depth ≥ 1 (docs/content-delivery-api.md §5b).`, { provider: descriptor.provider, key: descriptor.key, adapter: descriptor.adapter });
|
|
110
|
+
}
|
|
111
|
+
const locale = overrides.locale ?? (await resolveLocale());
|
|
112
|
+
const ctx = await supplyContext(overrides.context);
|
|
113
|
+
const key = JSON.stringify(['component', descriptor.provider, descriptor.key, locale ?? '', serializeContext(ctx), serializeOverlay(descriptor.contextualValues)]);
|
|
114
|
+
return withCache(key, overrides, async (signal) => {
|
|
115
|
+
const fetched = await delivery.getComponent(descriptor.provider, descriptor.key, { locale, ctx, signal });
|
|
116
|
+
return {
|
|
117
|
+
...descriptor,
|
|
118
|
+
contract: fetched.contract ?? descriptor.contract,
|
|
119
|
+
content: applyContextualOverlay(fetched.content, descriptor.contextualValues),
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
invalidate() {
|
|
124
|
+
cache?.invalidate();
|
|
125
|
+
sitePromise = undefined;
|
|
126
|
+
localePromise = undefined;
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function pathnameOf(location) {
|
|
131
|
+
if (typeof location === 'string') {
|
|
132
|
+
// A full URL is accepted too; only its path matters.
|
|
133
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(location)) {
|
|
134
|
+
return new URL(location).pathname;
|
|
135
|
+
}
|
|
136
|
+
return location.split(/[?#]/, 1)[0] ?? location;
|
|
137
|
+
}
|
|
138
|
+
return location.pathname;
|
|
139
|
+
}
|
|
140
|
+
function serializeOverlay(contextualValues) {
|
|
141
|
+
if (!contextualValues) {
|
|
142
|
+
return '';
|
|
143
|
+
}
|
|
144
|
+
const ordered = {};
|
|
145
|
+
for (const key of Object.keys(contextualValues).sort()) {
|
|
146
|
+
ordered[key] = contextualValues[key];
|
|
147
|
+
}
|
|
148
|
+
return JSON.stringify(ordered);
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/content/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAmD,MAAM,uBAAuB,CAAA;AAC7G,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACtE,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACpE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAElF,OAAO,EAAE,YAAY,EAAqB,MAAM,YAAY,CAAA;AAC5D,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AACtF,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,WAAW,EAAwB,MAAM,eAAe,CAAA;AAqF7F,MAAM,UAAU,mBAAmB,CAAC,OAA6B;IAC/D,MAAM,QAAQ,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAA;IAC9C,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,IAAI,gBAAgB,CAAA;IACpD,MAAM,KAAK,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CAAC,OAAO,EAAE,UAAU,CAAC,gBAAgB,CAAC;iBAC9E,CAAA;YACH,CAAC,CAAC,CAAA;QACJ,CAAC;QAED,UAAU;YACR,KAAK,EAAE,UAAU,EAAE,CAAA;YACnB,WAAW,GAAG,SAAS,CAAA;YACvB,aAAa,GAAG,SAAS,CAAA;QAC3B,CAAC;KACF,CAAA;AACH,CAAC;AAED,SAAS,UAAU,CAAC,QAAsB;IACxC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,qDAAqD;QACrD,IAAI,0BAA0B,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC9C,OAAO,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAA;QACnC,CAAC;QAED,OAAO,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAA;IACjD,CAAC;IAED,OAAO,QAAQ,CAAC,QAAQ,CAAA;AAC1B,CAAC;AAED,SAAS,gBAAgB,CAAC,gBAAqD;IAC7E,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,OAAO,GAA4B,EAAE,CAAA;IAC3C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QACvD,OAAO,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAA;IACtC,CAAC;IAED,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;AAChC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { LocaleTreeNode } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Locale **selection** (spec 359 Business Logic §2). The server resolves exactly one requested
|
|
4
|
+
* code through the organization's tree with no `fr-CA → fr` expansion, so the client's job is to
|
|
5
|
+
* pick the one code most likely to be *in* the tree. This is a selection, never a second
|
|
6
|
+
* hierarchy resolver: the server still computes the fallback breadcrumb from whatever is sent.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Ordered candidates from a browser-style language list: each region-tagged entry is followed by
|
|
10
|
+
* its base language (`['fr-CA', 'en-US']` → `['fr-CA', 'fr', 'en-US', 'en']`), the
|
|
11
|
+
* `AcceptLanguageParser` expansion reapplied. Duplicates keep their first position.
|
|
12
|
+
*/
|
|
13
|
+
export declare function expandLanguageCandidates(languages: readonly string[]): string[];
|
|
14
|
+
/** The first candidate present in the tree (case-insensitive), returned in the tree's own casing; `undefined` when none is. */
|
|
15
|
+
export declare function selectLocale(candidates: readonly string[], tree: readonly LocaleTreeNode[]): string | undefined;
|
|
16
|
+
/** `navigator.languages` (then `navigator.language`) when running in a browser; `[]` in Node. */
|
|
17
|
+
export declare function browserLanguages(): string[];
|
|
18
|
+
//# sourceMappingURL=locale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale.d.ts","sourceRoot":"","sources":["../../src/content/locale.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD;;;;;GAKG;AAEH;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAqB/E;AAED,+HAA+H;AAC/H,wBAAgB,YAAY,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,GAAG,SAAS,CAU/G;AAED,iGAAiG;AACjG,wBAAgB,gBAAgB,IAAI,MAAM,EAAE,CAW3C"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locale **selection** (spec 359 Business Logic §2). The server resolves exactly one requested
|
|
3
|
+
* code through the organization's tree with no `fr-CA → fr` expansion, so the client's job is to
|
|
4
|
+
* pick the one code most likely to be *in* the tree. This is a selection, never a second
|
|
5
|
+
* hierarchy resolver: the server still computes the fallback breadcrumb from whatever is sent.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Ordered candidates from a browser-style language list: each region-tagged entry is followed by
|
|
9
|
+
* its base language (`['fr-CA', 'en-US']` → `['fr-CA', 'fr', 'en-US', 'en']`), the
|
|
10
|
+
* `AcceptLanguageParser` expansion reapplied. Duplicates keep their first position.
|
|
11
|
+
*/
|
|
12
|
+
export function expandLanguageCandidates(languages) {
|
|
13
|
+
const seen = new Set();
|
|
14
|
+
const candidates = [];
|
|
15
|
+
const push = (code) => {
|
|
16
|
+
const key = code.toLowerCase();
|
|
17
|
+
if (code && !seen.has(key)) {
|
|
18
|
+
seen.add(key);
|
|
19
|
+
candidates.push(code);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
for (const language of languages) {
|
|
23
|
+
const trimmed = language.trim();
|
|
24
|
+
push(trimmed);
|
|
25
|
+
const base = trimmed.split('-')[0];
|
|
26
|
+
if (base && base !== trimmed) {
|
|
27
|
+
push(base);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return candidates;
|
|
31
|
+
}
|
|
32
|
+
/** The first candidate present in the tree (case-insensitive), returned in the tree's own casing; `undefined` when none is. */
|
|
33
|
+
export function selectLocale(candidates, tree) {
|
|
34
|
+
const byLower = new Map(tree.map((node) => [node.code.toLowerCase(), node.code]));
|
|
35
|
+
for (const candidate of candidates) {
|
|
36
|
+
const match = byLower.get(candidate.toLowerCase());
|
|
37
|
+
if (match !== undefined) {
|
|
38
|
+
return match;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
/** `navigator.languages` (then `navigator.language`) when running in a browser; `[]` in Node. */
|
|
44
|
+
export function browserLanguages() {
|
|
45
|
+
const nav = globalThis.navigator;
|
|
46
|
+
if (!nav) {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(nav.languages) && nav.languages.length > 0) {
|
|
50
|
+
return [...nav.languages];
|
|
51
|
+
}
|
|
52
|
+
return typeof nav.language === 'string' && nav.language ? [nav.language] : [];
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=locale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale.js","sourceRoot":"","sources":["../../src/content/locale.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,SAA4B;IACnE,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;IAC9B,MAAM,UAAU,GAAa,EAAE,CAAA;IAC/B,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,EAAE;QAC5B,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAA;QAC9B,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAC3B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YACb,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACvB,CAAC;IACH,CAAC,CAAA;IAED,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAA;QAC/B,IAAI,CAAC,OAAO,CAAC,CAAA;QACb,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;QAClC,IAAI,IAAI,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;YAC7B,IAAI,CAAC,IAAI,CAAC,CAAA;QACZ,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAA;AACnB,CAAC;AAED,+HAA+H;AAC/H,MAAM,UAAU,YAAY,CAAC,UAA6B,EAAE,IAA+B;IACzF,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjF,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,CAAA;QAClD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,gBAAgB;IAC9B,MAAM,GAAG,GAAI,UAAmF,CAAC,SAAS,CAAA;IAC1G,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,EAAE,CAAA;IACX,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7D,OAAO,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC,CAAA;IAC3B,CAAC;IAED,OAAO,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;AAC/E,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ContentDocument } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The contextual overlay rule (docs/content-delivery-api.md §4: "the edge's own values override
|
|
4
|
+
* the target's stored defaults") — applied by the server at `resolve ≥ 1`, and by the SDK's
|
|
5
|
+
* normalized strategy after fetching a reference's target itself. **Shallow**: each key of
|
|
6
|
+
* `contextualValues` replaces the same top-level key of `content` wholesale (an object is
|
|
7
|
+
* replaced, never merged; `null` overlays to `null`; a key the target lacks is added). Contextual
|
|
8
|
+
* fields are always top-level on their owning Contract, which is what makes shallow correct.
|
|
9
|
+
*
|
|
10
|
+
* This is the one delivery rule that exists on both sides. It mirrors
|
|
11
|
+
* `Content.Api.Delivery.ContextualOverlay.Apply` exactly, and the shared fixture
|
|
12
|
+
* `apps/content-web/src/test/fixtures/contextual-overlay-cases.json` is run through both — add a
|
|
13
|
+
* case there, never a divergent behaviour here.
|
|
14
|
+
*/
|
|
15
|
+
export declare function applyContextualOverlay<T extends ContentDocument>(content: T, contextualValues: ContentDocument | null | undefined): T;
|
|
16
|
+
//# sourceMappingURL=overlay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../../src/content/overlay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,eAAe,EAAE,OAAO,EAAE,CAAC,EAAE,gBAAgB,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,CAMrI"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contextual overlay rule (docs/content-delivery-api.md §4: "the edge's own values override
|
|
3
|
+
* the target's stored defaults") — applied by the server at `resolve ≥ 1`, and by the SDK's
|
|
4
|
+
* normalized strategy after fetching a reference's target itself. **Shallow**: each key of
|
|
5
|
+
* `contextualValues` replaces the same top-level key of `content` wholesale (an object is
|
|
6
|
+
* replaced, never merged; `null` overlays to `null`; a key the target lacks is added). Contextual
|
|
7
|
+
* fields are always top-level on their owning Contract, which is what makes shallow correct.
|
|
8
|
+
*
|
|
9
|
+
* This is the one delivery rule that exists on both sides. It mirrors
|
|
10
|
+
* `Content.Api.Delivery.ContextualOverlay.Apply` exactly, and the shared fixture
|
|
11
|
+
* `apps/content-web/src/test/fixtures/contextual-overlay-cases.json` is run through both — add a
|
|
12
|
+
* case there, never a divergent behaviour here.
|
|
13
|
+
*/
|
|
14
|
+
export function applyContextualOverlay(content, contextualValues) {
|
|
15
|
+
if (!contextualValues) {
|
|
16
|
+
return content;
|
|
17
|
+
}
|
|
18
|
+
return { ...content, ...contextualValues };
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=overlay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay.js","sourceRoot":"","sources":["../../src/content/overlay.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,sBAAsB,CAA4B,OAAU,EAAE,gBAAoD;IAChI,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,gBAAgB,EAAE,CAAA;AAC5C,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SiteSummary } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Site resolution (spec 359 Business Logic §1). `GET /path` can infer the site from the request's
|
|
4
|
+
* `Host` only when the request arrives on the site's own hostname — never true for a browser
|
|
5
|
+
* calling the API's host — so the SDK picks the site itself from `GET /sites`.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Exactly one published site → that site (no host mapping needed; the local-development and
|
|
9
|
+
* single-site case). Otherwise the site whose `hosts` contains `hostname` (case-insensitive,
|
|
10
|
+
* hostname only — the server stores `Host.Host`, port-less). `undefined` when nothing matches.
|
|
11
|
+
*/
|
|
12
|
+
export declare function matchSite(sites: readonly SiteSummary[], hostname: string | undefined): SiteSummary | undefined;
|
|
13
|
+
/** `window.location.hostname` in a browser; `undefined` in Node. */
|
|
14
|
+
export declare function currentHostname(): string | undefined;
|
|
15
|
+
//# sourceMappingURL=site.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../../src/content/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C;;;;GAIG;AAEH;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAW9G;AAED,oEAAoE;AACpE,wBAAgB,eAAe,IAAI,MAAM,GAAG,SAAS,CAGpD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Site resolution (spec 359 Business Logic §1). `GET /path` can infer the site from the request's
|
|
3
|
+
* `Host` only when the request arrives on the site's own hostname — never true for a browser
|
|
4
|
+
* calling the API's host — so the SDK picks the site itself from `GET /sites`.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Exactly one published site → that site (no host mapping needed; the local-development and
|
|
8
|
+
* single-site case). Otherwise the site whose `hosts` contains `hostname` (case-insensitive,
|
|
9
|
+
* hostname only — the server stores `Host.Host`, port-less). `undefined` when nothing matches.
|
|
10
|
+
*/
|
|
11
|
+
export function matchSite(sites, hostname) {
|
|
12
|
+
if (sites.length === 1) {
|
|
13
|
+
return sites[0];
|
|
14
|
+
}
|
|
15
|
+
if (!hostname) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const wanted = hostname.toLowerCase();
|
|
19
|
+
return sites.find((site) => site.hosts.some((host) => host.toLowerCase() === wanted));
|
|
20
|
+
}
|
|
21
|
+
/** `window.location.hostname` in a browser; `undefined` in Node. */
|
|
22
|
+
export function currentHostname() {
|
|
23
|
+
const loc = globalThis.location;
|
|
24
|
+
return typeof loc?.hostname === 'string' && loc.hostname ? loc.hostname : undefined;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=site.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site.js","sourceRoot":"","sources":["../../src/content/site.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,KAA6B,EAAE,QAA4B;IACnF,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;IAED,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAA;IACrC,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,CAAC,CAAA;AACvF,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,eAAe;IAC7B,MAAM,GAAG,GAAI,UAAmD,CAAC,QAAQ,CAAA;IACzE,OAAO,OAAO,GAAG,EAAE,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAA;AACrF,CAAC"}
|