@webiny/sdk-frontend 0.0.0-unstable.0d717d18dd → 0.0.0-unstable.7c2def32a7
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/ComponentsSdk.d.ts +39 -0
- package/ComponentsSdk.js +146 -0
- package/ComponentsSdk.js.map +1 -0
- package/FrontendSdk.d.ts +2 -0
- package/FrontendSdk.js +13 -1
- package/FrontendSdk.js.map +1 -1
- package/WbSdk.js +6 -2
- package/WbSdk.js.map +1 -1
- package/createCmsContentEntryLoader.d.ts +7 -0
- package/createCmsContentEntryLoader.js +9 -0
- package/createCmsContentEntryLoader.js.map +1 -0
- package/index.d.ts +5 -0
- package/index.js +3 -0
- package/package.json +7 -6
- package/resolveContentEntries.client.test.d.ts +1 -0
- package/resolveContentEntries.client.test.js +118 -0
- package/resolveContentEntries.client.test.js.map +1 -0
- package/resolveContentEntries.d.ts +20 -0
- package/resolveContentEntries.js +45 -0
- package/resolveContentEntries.js.map +1 -0
- package/resolveContentEntries.test.d.ts +1 -0
- package/resolveContentEntries.test.js +328 -0
- package/resolveContentEntries.test.js.map +1 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { WebinyConfig } from "@webiny/sdk";
|
|
2
|
+
import { Result, HttpError, ApiError, NetworkError } from "@webiny/sdk";
|
|
3
|
+
export interface RemoteComponentEntry {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
label: string;
|
|
7
|
+
bundledJs: string;
|
|
8
|
+
bundledJsSha256: string;
|
|
9
|
+
bundledCss: string;
|
|
10
|
+
bundledCssSha256: string;
|
|
11
|
+
sdkVersion: string;
|
|
12
|
+
status: string;
|
|
13
|
+
}
|
|
14
|
+
export interface LoadComponentsOptions {
|
|
15
|
+
fetchOptions?: RequestInit;
|
|
16
|
+
}
|
|
17
|
+
export interface HydrateComponentDependencies {
|
|
18
|
+
sdk: unknown;
|
|
19
|
+
React: unknown;
|
|
20
|
+
}
|
|
21
|
+
export interface HydrateComponentOptions {
|
|
22
|
+
tenantId?: string;
|
|
23
|
+
locale?: string;
|
|
24
|
+
mode?: "server" | "browser";
|
|
25
|
+
}
|
|
26
|
+
export interface HydratedComponent {
|
|
27
|
+
component: any;
|
|
28
|
+
manifest: any;
|
|
29
|
+
css: string;
|
|
30
|
+
scopeClassName: string;
|
|
31
|
+
}
|
|
32
|
+
export declare class ComponentsSdk {
|
|
33
|
+
private config;
|
|
34
|
+
private fetchFn;
|
|
35
|
+
constructor(config: WebinyConfig);
|
|
36
|
+
loadComponents(options?: LoadComponentsOptions): Promise<Result<RemoteComponentEntry[], HttpError | ApiError | NetworkError>>;
|
|
37
|
+
hydrateComponent(entry: RemoteComponentEntry, dependencies: HydrateComponentDependencies, options?: HydrateComponentOptions): HydratedComponent | null;
|
|
38
|
+
scopeCss(rawCss: string, componentName: string): string;
|
|
39
|
+
}
|
package/ComponentsSdk.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { ApiError, HttpError, NetworkError, Result } from "@webiny/sdk";
|
|
2
|
+
import * as __rspack_external_css_tree_6b21abdd from "css-tree";
|
|
3
|
+
const LIST_REMOTE_COMPONENTS = `
|
|
4
|
+
query ListRemoteComponents {
|
|
5
|
+
remoteComponents {
|
|
6
|
+
listRemoteComponents {
|
|
7
|
+
data {
|
|
8
|
+
id
|
|
9
|
+
name
|
|
10
|
+
label
|
|
11
|
+
bundledJs
|
|
12
|
+
bundledJsSha256
|
|
13
|
+
bundledCss
|
|
14
|
+
bundledCssSha256
|
|
15
|
+
sdkVersion
|
|
16
|
+
status
|
|
17
|
+
}
|
|
18
|
+
error {
|
|
19
|
+
code
|
|
20
|
+
message
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
class ComponentsSdk {
|
|
27
|
+
constructor(config){
|
|
28
|
+
this.config = config;
|
|
29
|
+
this.fetchFn = config.fetch ?? fetch;
|
|
30
|
+
}
|
|
31
|
+
async loadComponents(options) {
|
|
32
|
+
const url = `${this.config.endpoint}/graphql`;
|
|
33
|
+
const headers = {
|
|
34
|
+
"Content-Type": "application/json",
|
|
35
|
+
"x-tenant": this.config.tenant ?? "root",
|
|
36
|
+
...this.config.headers
|
|
37
|
+
};
|
|
38
|
+
if (this.config.token && !headers.Authorization) {
|
|
39
|
+
const token = "function" == typeof this.config.token ? await this.config.token() : this.config.token;
|
|
40
|
+
headers.Authorization = `Bearer ${token}`;
|
|
41
|
+
}
|
|
42
|
+
let response;
|
|
43
|
+
try {
|
|
44
|
+
response = await this.fetchFn(url, {
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers,
|
|
47
|
+
body: JSON.stringify({
|
|
48
|
+
query: LIST_REMOTE_COMPONENTS
|
|
49
|
+
}),
|
|
50
|
+
...options?.fetchOptions
|
|
51
|
+
});
|
|
52
|
+
} catch (error) {
|
|
53
|
+
return Result.fail(new NetworkError(error instanceof Error ? error.message : "Network request failed"));
|
|
54
|
+
}
|
|
55
|
+
if (!response.ok) return Result.fail(new HttpError(response.status, `HTTP error! status: ${response.status}`));
|
|
56
|
+
let json;
|
|
57
|
+
try {
|
|
58
|
+
json = await response.json();
|
|
59
|
+
} catch {
|
|
60
|
+
return Result.fail(new NetworkError("Failed to parse response JSON"));
|
|
61
|
+
}
|
|
62
|
+
if (json.errors) {
|
|
63
|
+
const error = json.errors[0];
|
|
64
|
+
return Result.fail(new ApiError(error?.message || "GraphQL error"));
|
|
65
|
+
}
|
|
66
|
+
const envelope = json.data?.remoteComponents?.listRemoteComponents;
|
|
67
|
+
if (!envelope) return Result.fail(new ApiError("Unexpected response — is the remote-components API extension deployed?"));
|
|
68
|
+
if (envelope.error) return Result.fail(new ApiError(envelope.error.message, envelope.error.code));
|
|
69
|
+
return Result.ok(envelope.data ?? []);
|
|
70
|
+
}
|
|
71
|
+
hydrateComponent(entry, dependencies, options) {
|
|
72
|
+
const runtimeSdk = {
|
|
73
|
+
version: "1",
|
|
74
|
+
dependencies: {
|
|
75
|
+
sdk: dependencies.sdk,
|
|
76
|
+
React: dependencies.React
|
|
77
|
+
},
|
|
78
|
+
environment: {
|
|
79
|
+
tenantId: options?.tenantId ?? this.config.tenant ?? "root",
|
|
80
|
+
locale: options?.locale ?? "en-US",
|
|
81
|
+
mode: options?.mode ?? "browser"
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
try {
|
|
85
|
+
const fn = new Function(`
|
|
86
|
+
var __remoteComponent__;
|
|
87
|
+
${entry.bundledJs}
|
|
88
|
+
return __remoteComponent__;
|
|
89
|
+
`);
|
|
90
|
+
const mod = fn();
|
|
91
|
+
const component = mod.createComponent(runtimeSdk);
|
|
92
|
+
if (!component) return null;
|
|
93
|
+
const scopeClass = toScopeClassName(entry.name);
|
|
94
|
+
const R = dependencies.React;
|
|
95
|
+
const OriginalComponent = component.component;
|
|
96
|
+
const ScopedComponent = (props)=>R.createElement("div", {
|
|
97
|
+
className: scopeClass
|
|
98
|
+
}, R.createElement(OriginalComponent, props));
|
|
99
|
+
ScopedComponent.displayName = `RemoteScope(${scopeClass})`;
|
|
100
|
+
return {
|
|
101
|
+
component: ScopedComponent,
|
|
102
|
+
manifest: component.manifest,
|
|
103
|
+
css: entry.bundledCss ?? "",
|
|
104
|
+
scopeClassName: scopeClass
|
|
105
|
+
};
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error(`[ComponentsSdk] Failed to hydrate component "${entry.name}":`, error);
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
scopeCss(rawCss, componentName) {
|
|
112
|
+
return scopeCss(rawCss, toScopeClassName(componentName));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function toScopeClassName(name) {
|
|
116
|
+
return `rc-${name.replace(/\//g, "-").toLowerCase()}`;
|
|
117
|
+
}
|
|
118
|
+
function scopeCss(rawCss, scopeName) {
|
|
119
|
+
if (!rawCss) return "";
|
|
120
|
+
try {
|
|
121
|
+
const ast = __rspack_external_css_tree_6b21abdd.parse(rawCss);
|
|
122
|
+
__rspack_external_css_tree_6b21abdd.walk(ast, {
|
|
123
|
+
visit: "Rule",
|
|
124
|
+
enter (node) {
|
|
125
|
+
const selectorList = node.prelude;
|
|
126
|
+
if (!selectorList || "SelectorList" !== selectorList.type) return;
|
|
127
|
+
const newSelectors = new __rspack_external_css_tree_6b21abdd.List();
|
|
128
|
+
selectorList.children.forEach((selector)=>{
|
|
129
|
+
const raw = __rspack_external_css_tree_6b21abdd.generate(selector).trim();
|
|
130
|
+
if (raw.startsWith(":root")) return void newSelectors.appendData(selector);
|
|
131
|
+
const scoped = __rspack_external_css_tree_6b21abdd.parse(`.${scopeName} ${raw}`, {
|
|
132
|
+
context: "selector"
|
|
133
|
+
});
|
|
134
|
+
newSelectors.appendData(scoped);
|
|
135
|
+
});
|
|
136
|
+
selectorList.children = newSelectors;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
return __rspack_external_css_tree_6b21abdd.generate(ast);
|
|
140
|
+
} catch {
|
|
141
|
+
return rawCss;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
export { ComponentsSdk };
|
|
145
|
+
|
|
146
|
+
//# sourceMappingURL=ComponentsSdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComponentsSdk.js","sources":["../src/ComponentsSdk.ts"],"sourcesContent":["import type { WebinyConfig } from \"@webiny/sdk\";\nimport { Result, HttpError, ApiError, NetworkError } from \"@webiny/sdk\";\n// @ts-expect-error No types available\nimport * as csstree from \"css-tree\";\n\nexport interface RemoteComponentEntry {\n id: string;\n name: string;\n label: string;\n bundledJs: string;\n bundledJsSha256: string;\n bundledCss: string;\n bundledCssSha256: string;\n sdkVersion: string;\n status: string;\n}\n\nexport interface LoadComponentsOptions {\n fetchOptions?: RequestInit;\n}\n\nexport interface HydrateComponentDependencies {\n sdk: unknown;\n React: unknown;\n}\n\nexport interface HydrateComponentOptions {\n tenantId?: string;\n locale?: string;\n mode?: \"server\" | \"browser\";\n}\n\nexport interface HydratedComponent {\n component: any;\n manifest: any;\n css: string;\n scopeClassName: string;\n}\n\nconst LIST_REMOTE_COMPONENTS = /* GraphQL */ `\n query ListRemoteComponents {\n remoteComponents {\n listRemoteComponents {\n data {\n id\n name\n label\n bundledJs\n bundledJsSha256\n bundledCss\n bundledCssSha256\n sdkVersion\n status\n }\n error {\n code\n message\n }\n }\n }\n }\n`;\n\ninterface ListRemoteComponentsResponse {\n remoteComponents: {\n listRemoteComponents: {\n data: RemoteComponentEntry[] | null;\n error: { code: string; message: string } | null;\n };\n };\n}\n\nexport class ComponentsSdk {\n private config: WebinyConfig;\n private fetchFn: typeof fetch;\n\n constructor(config: WebinyConfig) {\n this.config = config;\n this.fetchFn = config.fetch ?? fetch;\n }\n\n async loadComponents(\n options?: LoadComponentsOptions\n ): Promise<Result<RemoteComponentEntry[], HttpError | ApiError | NetworkError>> {\n const url = `${this.config.endpoint}/graphql`;\n\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n \"x-tenant\": this.config.tenant ?? \"root\",\n ...this.config.headers\n };\n\n if (this.config.token && !headers.Authorization) {\n const token =\n typeof this.config.token === \"function\"\n ? await this.config.token()\n : this.config.token;\n headers.Authorization = `Bearer ${token}`;\n }\n\n let response: Response;\n try {\n response = await this.fetchFn(url, {\n method: \"POST\",\n headers,\n body: JSON.stringify({ query: LIST_REMOTE_COMPONENTS }),\n ...options?.fetchOptions\n });\n } catch (error) {\n return Result.fail(\n new NetworkError(error instanceof Error ? error.message : \"Network request failed\")\n );\n }\n\n if (!response.ok) {\n return Result.fail(\n new HttpError(response.status, `HTTP error! status: ${response.status}`)\n );\n }\n\n let json: { data?: ListRemoteComponentsResponse; errors?: Array<{ message: string }> };\n try {\n json = await response.json();\n } catch {\n return Result.fail(new NetworkError(\"Failed to parse response JSON\"));\n }\n\n if (json.errors) {\n const error = json.errors[0];\n return Result.fail(new ApiError(error?.message || \"GraphQL error\"));\n }\n\n const envelope = json.data?.remoteComponents?.listRemoteComponents;\n if (!envelope) {\n return Result.fail(\n new ApiError(\n \"Unexpected response — is the remote-components API extension deployed?\"\n )\n );\n }\n\n if (envelope.error) {\n return Result.fail(new ApiError(envelope.error.message, envelope.error.code));\n }\n\n return Result.ok(envelope.data ?? []);\n }\n\n hydrateComponent(\n entry: RemoteComponentEntry,\n dependencies: HydrateComponentDependencies,\n options?: HydrateComponentOptions\n ): HydratedComponent | null {\n const runtimeSdk = {\n version: \"1\" as const,\n dependencies: {\n sdk: dependencies.sdk,\n React: dependencies.React\n },\n environment: {\n tenantId: options?.tenantId ?? this.config.tenant ?? \"root\",\n locale: options?.locale ?? \"en-US\",\n mode: options?.mode ?? \"browser\"\n }\n };\n\n try {\n const fn = new Function(`\n var __remoteComponent__;\n ${entry.bundledJs}\n return __remoteComponent__;\n `);\n const mod = fn();\n const component = mod.createComponent(runtimeSdk);\n if (!component) {\n return null;\n }\n\n const scopeClass = toScopeClassName(entry.name);\n const R = dependencies.React as typeof import(\"react\");\n const OriginalComponent = component.component;\n\n const ScopedComponent = (props: Record<string, unknown>) =>\n R.createElement(\n \"div\",\n { className: scopeClass },\n R.createElement(OriginalComponent, props)\n );\n ScopedComponent.displayName = `RemoteScope(${scopeClass})`;\n\n return {\n component: ScopedComponent,\n manifest: component.manifest,\n css: entry.bundledCss ?? \"\",\n scopeClassName: scopeClass\n };\n } catch (error) {\n console.error(`[ComponentsSdk] Failed to hydrate component \"${entry.name}\":`, error);\n return null;\n }\n }\n\n scopeCss(rawCss: string, componentName: string): string {\n return scopeCss(rawCss, toScopeClassName(componentName));\n }\n}\n\nfunction toScopeClassName(name: string): string {\n return `rc-${name.replace(/\\//g, \"-\").toLowerCase()}`;\n}\n\nfunction scopeCss(rawCss: string, scopeName: string): string {\n if (!rawCss) {\n return \"\";\n }\n\n try {\n const ast = csstree.parse(rawCss);\n\n csstree.walk(ast, {\n visit: \"Rule\",\n enter(node: any) {\n const selectorList = node.prelude;\n if (!selectorList || selectorList.type !== \"SelectorList\") {\n return;\n }\n\n const newSelectors = new csstree.List();\n\n selectorList.children.forEach((selector: any) => {\n const raw = csstree.generate(selector).trim();\n if (raw.startsWith(\":root\")) {\n newSelectors.appendData(selector);\n return;\n }\n\n const scoped = csstree.parse(`.${scopeName} ${raw}`, {\n context: \"selector\"\n });\n newSelectors.appendData(scoped);\n });\n\n selectorList.children = newSelectors;\n }\n });\n\n return csstree.generate(ast);\n } catch {\n return rawCss;\n }\n}\n"],"names":["LIST_REMOTE_COMPONENTS","ComponentsSdk","config","fetch","options","url","headers","token","response","JSON","error","Result","NetworkError","Error","HttpError","json","ApiError","envelope","entry","dependencies","runtimeSdk","fn","Function","mod","component","scopeClass","toScopeClassName","R","OriginalComponent","ScopedComponent","props","console","rawCss","componentName","scopeCss","name","scopeName","ast","csstree","node","selectorList","newSelectors","selector","raw","scoped"],"mappings":";;AAuCA,MAAMA,yBAAuC,CAAC;;;;;;;;;;;;;;;;;;;;;;AAsB9C,CAAC;AAWM,MAAMC;IAIT,YAAYC,MAAoB,CAAE;QAC9B,IAAI,CAAC,MAAM,GAAGA;QACd,IAAI,CAAC,OAAO,GAAGA,OAAO,KAAK,IAAIC;IACnC;IAEA,MAAM,eACFC,OAA+B,EAC6C;QAC5E,MAAMC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAE7C,MAAMC,UAAkC;YACpC,gBAAgB;YAChB,YAAY,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI;YAClC,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO;QAC1B;QAEA,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,CAACA,QAAQ,aAAa,EAAE;YAC7C,MAAMC,QACF,AAA6B,cAA7B,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,GAClB,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,KACvB,IAAI,CAAC,MAAM,CAAC,KAAK;Y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eD,KAAK,OAAO;gBACjC,IAAI,CAACC,gBAAgBA,AAAsB,mBAAtBA,aAAa,IAAI,EAClC;gBAGJ,MAAMC,eAAe,IAAIH,oCAAAA,IAAY;gBAErCE,aAAa,QAAQ,CAAC,OAAO,CAAC,CAACE;oBAC3B,MAAMC,MAAML,oCAAAA,QAAgB,CAACI,UAAU,IAAI;oBAC3C,IAAIC,IAAI,UAAU,CAAC,UAAU,YACzBF,aAAa,UAAU,CAACC;oBAI5B,MAAME,SAASN,oCAAAA,KAAa,CAAC,CAAC,CAAC,EAAEF,UAAU,CAAC,EAAEO,KAAK,EAAE;wBACjD,SAAS;oBACb;oBACAF,aAAa,UAAU,CAACG;gBAC5B;gBAEAJ,aAAa,QAAQ,GAAGC;YAC5B;QACJ;QAEA,OAAOH,oCAAAA,QAAgB,CAACD;IAC5B,EAAE,OAAM;QACJ,OAAOL;IACX;AACJ"}
|
package/FrontendSdk.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { LanguagesSdk, FileManagerSdk, TenantManagerSdk, TasksSdk, WebhooksSdk } from "@webiny/sdk";
|
|
2
2
|
import { CmsSdk } from "./CmsSdk.js";
|
|
3
3
|
import { WbSdk } from "./WbSdk.js";
|
|
4
|
+
import { ComponentsSdk } from "./ComponentsSdk.js";
|
|
4
5
|
import type { ContentSdkConfig } from "./types.js";
|
|
5
6
|
export declare class FrontendSdk {
|
|
6
7
|
private sdk?;
|
|
@@ -12,6 +13,7 @@ export declare class FrontendSdk {
|
|
|
12
13
|
get tenantManager(): TenantManagerSdk;
|
|
13
14
|
get tasks(): TasksSdk;
|
|
14
15
|
get webhooks(): WebhooksSdk;
|
|
16
|
+
get components(): ComponentsSdk;
|
|
15
17
|
init(config: ContentSdkConfig): void;
|
|
16
18
|
isEditing(): boolean;
|
|
17
19
|
isServer(): boolean;
|
package/FrontendSdk.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Webiny } from "@webiny/sdk";
|
|
2
2
|
import { contentSdk, environment } from "@webiny/cms-sdk";
|
|
3
3
|
import { contentSdk as website_builder_sdk_contentSdk } from "@webiny/website-builder-sdk";
|
|
4
|
+
import { ensureContentEntryLoader } from "./resolveContentEntries.js";
|
|
4
5
|
import { CmsSdk } from "./CmsSdk.js";
|
|
5
6
|
import { WbSdk } from "./WbSdk.js";
|
|
7
|
+
import { ComponentsSdk } from "./ComponentsSdk.js";
|
|
6
8
|
class FrontendSdk {
|
|
7
9
|
get initialized() {
|
|
8
10
|
if (!this.sdk) throw new Error("SDK is not initialized. Call sdk.init() first.");
|
|
@@ -29,6 +31,9 @@ class FrontendSdk {
|
|
|
29
31
|
get webhooks() {
|
|
30
32
|
return this.initialized.webiny.webhooks;
|
|
31
33
|
}
|
|
34
|
+
get components() {
|
|
35
|
+
return this.initialized.components;
|
|
36
|
+
}
|
|
32
37
|
init(config) {
|
|
33
38
|
const webiny = new Webiny({
|
|
34
39
|
endpoint: config.endpoint,
|
|
@@ -39,7 +44,13 @@ class FrontendSdk {
|
|
|
39
44
|
this.sdk = {
|
|
40
45
|
webiny,
|
|
41
46
|
cms: new CmsSdk(webiny),
|
|
42
|
-
wb: new WbSdk()
|
|
47
|
+
wb: new WbSdk(),
|
|
48
|
+
components: new ComponentsSdk({
|
|
49
|
+
endpoint: config.endpoint,
|
|
50
|
+
token: config.token,
|
|
51
|
+
tenant: config.tenant || "root",
|
|
52
|
+
fetch: config.fetch
|
|
53
|
+
})
|
|
43
54
|
};
|
|
44
55
|
contentSdk.init({
|
|
45
56
|
apiHost: config.endpoint,
|
|
@@ -57,6 +68,7 @@ class FrontendSdk {
|
|
|
57
68
|
previewParams: config.wb?.previewParams
|
|
58
69
|
});
|
|
59
70
|
if (config.wb?.componentGroups) for (const group of config.wb.componentGroups)this.sdk.wb.registerComponentGroup(group);
|
|
71
|
+
ensureContentEntryLoader();
|
|
60
72
|
}
|
|
61
73
|
isEditing() {
|
|
62
74
|
return environment.isEditing();
|
package/FrontendSdk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FrontendSdk.js","sources":["../src/FrontendSdk.ts"],"sourcesContent":["import { Webiny } from \"@webiny/sdk\";\nimport type {\n LanguagesSdk,\n FileManagerSdk,\n TenantManagerSdk,\n TasksSdk,\n WebhooksSdk\n} from \"@webiny/sdk\";\nimport { contentSdk as cmsContentSdk, environment as cmsEnvironment } from \"@webiny/cms-sdk\";\nimport { contentSdk as wbContentSdk } from \"@webiny/website-builder-sdk\";\nimport { CmsSdk } from \"./CmsSdk.js\";\nimport { WbSdk } from \"./WbSdk.js\";\nimport type { ContentSdkConfig } from \"./types.js\";\n\ninterface InitializedSdk {\n webiny: Webiny;\n cms: CmsSdk;\n wb: WbSdk;\n}\n\nexport class FrontendSdk {\n private sdk?: InitializedSdk;\n\n private get initialized(): InitializedSdk {\n if (!this.sdk) {\n throw new Error(\"SDK is not initialized. Call sdk.init() first.\");\n }\n return this.sdk;\n }\n\n get cms(): CmsSdk {\n return this.initialized.cms;\n }\n\n get wb(): WbSdk {\n return this.initialized.wb;\n }\n\n get languages(): LanguagesSdk {\n return this.initialized.webiny.languages;\n }\n\n get fileManager(): FileManagerSdk {\n return this.initialized.webiny.fileManager;\n }\n\n get tenantManager(): TenantManagerSdk {\n return this.initialized.webiny.tenantManager;\n }\n\n get tasks(): TasksSdk {\n return this.initialized.webiny.tasks;\n }\n\n get webhooks(): WebhooksSdk {\n return this.initialized.webiny.webhooks;\n }\n\n init(config: ContentSdkConfig): void {\n const webiny = new Webiny({\n endpoint: config.endpoint,\n token: config.token,\n tenant: config.tenant || \"root\",\n fetch: config.fetch\n });\n\n this.sdk = {\n webiny,\n cms: new CmsSdk(webiny),\n wb: new WbSdk()\n };\n\n cmsContentSdk.init(\n {\n apiHost: config.endpoint,\n apiKey: config.token,\n apiTenant: config.tenant,\n preview: config.preview,\n fetch: config.fetch\n },\n webiny\n );\n\n wbContentSdk.init({\n apiHost: config.endpoint,\n apiKey: config.token,\n apiTenant: config.tenant ?? \"root\",\n preview: config.preview,\n theme: config.wb?.theme,\n previewParams: config.wb?.previewParams\n });\n\n if (config.wb?.componentGroups) {\n for (const group of config.wb.componentGroups) {\n this.sdk.wb.registerComponentGroup(group);\n }\n }\n }\n\n isEditing(): boolean {\n return cmsEnvironment.isEditing();\n }\n\n isServer(): boolean {\n return cmsEnvironment.isServer();\n }\n\n isClient(): boolean {\n return cmsEnvironment.isClient();\n }\n}\n\nexport const sdk = new FrontendSdk();\n"],"names":["FrontendSdk","Error","config","webiny","Webiny","CmsSdk","WbSdk","cmsContentSdk","wbContentSdk","group","cmsEnvironment","sdk"],"mappings":"
|
|
1
|
+
{"version":3,"file":"FrontendSdk.js","sources":["../src/FrontendSdk.ts"],"sourcesContent":["import { Webiny } from \"@webiny/sdk\";\nimport type {\n LanguagesSdk,\n FileManagerSdk,\n TenantManagerSdk,\n TasksSdk,\n WebhooksSdk\n} from \"@webiny/sdk\";\nimport { contentSdk as cmsContentSdk, environment as cmsEnvironment } from \"@webiny/cms-sdk\";\nimport { contentSdk as wbContentSdk } from \"@webiny/website-builder-sdk\";\nimport { ensureContentEntryLoader } from \"./resolveContentEntries.js\";\nimport { CmsSdk } from \"./CmsSdk.js\";\nimport { WbSdk } from \"./WbSdk.js\";\nimport { ComponentsSdk } from \"./ComponentsSdk.js\";\nimport type { ContentSdkConfig } from \"./types.js\";\n\ninterface InitializedSdk {\n webiny: Webiny;\n cms: CmsSdk;\n wb: WbSdk;\n components: ComponentsSdk;\n}\n\nexport class FrontendSdk {\n private sdk?: InitializedSdk;\n\n private get initialized(): InitializedSdk {\n if (!this.sdk) {\n throw new Error(\"SDK is not initialized. Call sdk.init() first.\");\n }\n return this.sdk;\n }\n\n get cms(): CmsSdk {\n return this.initialized.cms;\n }\n\n get wb(): WbSdk {\n return this.initialized.wb;\n }\n\n get languages(): LanguagesSdk {\n return this.initialized.webiny.languages;\n }\n\n get fileManager(): FileManagerSdk {\n return this.initialized.webiny.fileManager;\n }\n\n get tenantManager(): TenantManagerSdk {\n return this.initialized.webiny.tenantManager;\n }\n\n get tasks(): TasksSdk {\n return this.initialized.webiny.tasks;\n }\n\n get webhooks(): WebhooksSdk {\n return this.initialized.webiny.webhooks;\n }\n\n get components(): ComponentsSdk {\n return this.initialized.components;\n }\n\n init(config: ContentSdkConfig): void {\n const webiny = new Webiny({\n endpoint: config.endpoint,\n token: config.token,\n tenant: config.tenant || \"root\",\n fetch: config.fetch\n });\n\n this.sdk = {\n webiny,\n cms: new CmsSdk(webiny),\n wb: new WbSdk(),\n components: new ComponentsSdk({\n endpoint: config.endpoint,\n token: config.token,\n tenant: config.tenant || \"root\",\n fetch: config.fetch\n })\n };\n\n cmsContentSdk.init(\n {\n apiHost: config.endpoint,\n apiKey: config.token,\n apiTenant: config.tenant,\n preview: config.preview,\n fetch: config.fetch\n },\n webiny\n );\n\n wbContentSdk.init({\n apiHost: config.endpoint,\n apiKey: config.token,\n apiTenant: config.tenant ?? \"root\",\n preview: config.preview,\n theme: config.wb?.theme,\n previewParams: config.wb?.previewParams\n });\n\n if (config.wb?.componentGroups) {\n for (const group of config.wb.componentGroups) {\n this.sdk.wb.registerComponentGroup(group);\n }\n }\n\n // Bridge the CMS SDK into the content-entry cache so the\n // BindingsResolver can resolve content-entry inputs on both\n // server (via resolveContentEntries) and client (editor preview iframe).\n ensureContentEntryLoader();\n }\n\n isEditing(): boolean {\n return cmsEnvironment.isEditing();\n }\n\n isServer(): boolean {\n return cmsEnvironment.isServer();\n }\n\n isClient(): boolean {\n return cmsEnvironment.isClient();\n }\n}\n\nexport const sdk = new FrontendSdk();\n"],"names":["FrontendSdk","Error","config","webiny","Webiny","CmsSdk","WbSdk","ComponentsSdk","cmsContentSdk","wbContentSdk","group","ensureContentEntryLoader","cmsEnvironment","sdk"],"mappings":";;;;;;;AAuBO,MAAMA;IAGT,IAAY,cAA8B;QACtC,IAAI,CAAC,IAAI,CAAC,GAAG,EACT,MAAM,IAAIC,MAAM;QAEpB,OAAO,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,SAASP,OAAO,QAAQ;YACxB,QAAQA,OAAO,KAAK;YACpB,WAAWA,OAAO,MAAM,IAAI;YAC5B,SAASA,OAAO,OAAO;YACvB,OAAOA,OAAO,EAAE,EAAE;YAClB,eAAeA,OAAO,EAAE,EAAE;QAC9B;QAEA,IAAIA,OAAO,EAAE,EAAE,iBACX,KAAK,MAAMQ,SAASR,OAAO,EAAE,CAAC,eAAe,CACzC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,sBAAsB,CAACQ;QAO3CC;IACJ;IAEA,YAAqB;QACjB,OAAOC,YAAAA,SAAwB;IACnC;IAEA,WAAoB;QAChB,OAAOA,YAAAA,QAAuB;IAClC;IAEA,WAAoB;QAChB,OAAOA,YAAAA,QAAuB;IAClC;AACJ;AAEO,MAAMC,MAAM,IAAIb"}
|
package/WbSdk.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { Result } from "@webiny/sdk";
|
|
2
2
|
import { contentSdk, registerComponentGroup } from "@webiny/website-builder-sdk";
|
|
3
|
+
import { resolveContentEntries } from "./resolveContentEntries.js";
|
|
3
4
|
class WbSdk {
|
|
4
|
-
getPage(path) {
|
|
5
|
-
|
|
5
|
+
async getPage(path) {
|
|
6
|
+
const page = await contentSdk.getPage(path);
|
|
7
|
+
if (!page) return Result.fail(new Error(`Page "${path}" not found.`));
|
|
8
|
+
await resolveContentEntries(page);
|
|
9
|
+
return Result.ok(page);
|
|
6
10
|
}
|
|
7
11
|
listPages(options) {
|
|
8
12
|
return contentSdk.listPages(options).then((result)=>Result.ok(result));
|
package/WbSdk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WbSdk.js","sources":["../src/WbSdk.ts"],"sourcesContent":["import { Result } from \"@webiny/sdk\";\nimport { contentSdk as wbContentSdk, registerComponentGroup } from \"@webiny/website-builder-sdk\";\nimport type {\n PublicPage,\n PublicRedirect,\n ListPagesOptions,\n ListPagesResult,\n Component as WbComponent,\n ComponentGroup\n} from \"@webiny/website-builder-sdk\";\n\nexport class WbSdk {\n getPage(path: string): Promise<Result<PublicPage, Error>> {\n
|
|
1
|
+
{"version":3,"file":"WbSdk.js","sources":["../src/WbSdk.ts"],"sourcesContent":["import { Result } from \"@webiny/sdk\";\nimport { contentSdk as wbContentSdk, registerComponentGroup } from \"@webiny/website-builder-sdk\";\nimport type {\n PublicPage,\n PublicRedirect,\n ListPagesOptions,\n ListPagesResult,\n Component as WbComponent,\n ComponentGroup\n} from \"@webiny/website-builder-sdk\";\nimport { resolveContentEntries } from \"./resolveContentEntries.js\";\n\nexport class WbSdk {\n async getPage(path: string): Promise<Result<PublicPage, Error>> {\n const page = await wbContentSdk.getPage(path);\n\n if (!page) {\n return Result.fail(new Error(`Page \"${path}\" not found.`));\n }\n\n await resolveContentEntries(page);\n\n return Result.ok(page);\n }\n\n listPages(options?: ListPagesOptions): Promise<Result<ListPagesResult, Error>> {\n return wbContentSdk.listPages(options).then(result => Result.ok(result));\n }\n\n getAllRedirects(): Promise<Result<Map<string, PublicRedirect>, Error>> {\n return wbContentSdk.getAllRedirects().then(redirects => Result.ok(redirects));\n }\n\n getRedirectByPath(path: string): Promise<Result<PublicRedirect | undefined, Error>> {\n return wbContentSdk.getRedirectByPath(path).then(redirect => Result.ok(redirect));\n }\n\n registerComponent(blueprint: WbComponent): void {\n wbContentSdk.registerComponent(blueprint);\n }\n\n registerComponentGroup(group: ComponentGroup): void {\n registerComponentGroup(group);\n }\n\n isPreviewing(): boolean {\n return wbContentSdk.isPreviewing();\n }\n}\n"],"names":["WbSdk","path","page","wbContentSdk","Result","Error","resolveContentEntries","options","result","redirects","redirect","blueprint","group","registerComponentGroup"],"mappings":";;;AAYO,MAAMA;IACT,MAAM,QAAQC,IAAY,EAAsC;QAC5D,MAAMC,OAAO,MAAMC,WAAAA,OAAoB,CAACF;QAExC,IAAI,CAACC,MACD,OAAOE,OAAO,IAAI,CAAC,IAAIC,MAAM,CAAC,MAAM,EAAEJ,KAAK,YAAY,CAAC;QAG5D,MAAMK,sBAAsBJ;QAE5B,OAAOE,OAAO,EAAE,CAACF;IACrB;IAEA,UAAUK,OAA0B,EAA2C;QAC3E,OAAOJ,WAAAA,SAAsB,CAACI,SAAS,IAAI,CAACC,CAAAA,SAAUJ,OAAO,EAAE,CAACI;IACpE;IAEA,kBAAuE;QACnE,OAAOL,WAAAA,eAA4B,GAAG,IAAI,CAACM,CAAAA,YAAaL,OAAO,EAAE,CAACK;IACtE;IAEA,kBAAkBR,IAAY,EAAsD;QAChF,OAAOE,WAAAA,iBAA8B,CAACF,MAAM,IAAI,CAACS,CAAAA,WAAYN,OAAO,EAAE,CAACM;IAC3E;IAEA,kBAAkBC,SAAsB,EAAQ;QAC5CR,WAAAA,iBAA8B,CAACQ;IACnC;IAEA,uBAAuBC,KAAqB,EAAQ;QAChDC,uBAAuBD;IAC3B;IAEA,eAAwB;QACpB,OAAOT,WAAAA,YAAyB;IACpC;AACJ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CmsClient } from "@webiny/cms-sdk";
|
|
2
|
+
import type { ContentEntryLoader } from "@webiny/website-builder-sdk";
|
|
3
|
+
/**
|
|
4
|
+
* A content entry loader that reads through `cmsClient`, for a content client's
|
|
5
|
+
* `contentEntryLoader` config. Pass a CMS client for the same tenant as the content client.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createCmsContentEntryLoader(cmsClient: CmsClient): ContentEntryLoader;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
function createCmsContentEntryLoader(cmsClient) {
|
|
2
|
+
return {
|
|
3
|
+
getEntry: (params)=>cmsClient.getEntry(params),
|
|
4
|
+
listEntries: (params)=>cmsClient.listEntries(params)
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export { createCmsContentEntryLoader };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=createCmsContentEntryLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createCmsContentEntryLoader.js","sources":["../src/createCmsContentEntryLoader.ts"],"sourcesContent":["import type { CmsClient } from \"@webiny/cms-sdk\";\nimport type { ContentEntryLoader } from \"@webiny/website-builder-sdk\";\n\n/**\n * A content entry loader that reads through `cmsClient`, for a content client's\n * `contentEntryLoader` config. Pass a CMS client for the same tenant as the content client.\n */\nexport function createCmsContentEntryLoader(cmsClient: CmsClient): ContentEntryLoader {\n return {\n getEntry: params => cmsClient.getEntry(params),\n listEntries: params => cmsClient.listEntries(params)\n };\n}\n"],"names":["createCmsContentEntryLoader","cmsClient","params"],"mappings":"AAOO,SAASA,4BAA4BC,SAAoB;IAC5D,OAAO;QACH,UAAUC,CAAAA,SAAUD,UAAU,QAAQ,CAACC;QACvC,aAAaA,CAAAA,SAAUD,UAAU,WAAW,CAACC;IACjD;AACJ"}
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export { sdk, FrontendSdk } from "./FrontendSdk.js";
|
|
2
|
+
export { ComponentsSdk } from "./ComponentsSdk.js";
|
|
3
|
+
export { resolveContentEntries } from "./resolveContentEntries.js";
|
|
4
|
+
export type { ResolveContentEntriesOptions } from "./resolveContentEntries.js";
|
|
5
|
+
export { createCmsContentEntryLoader } from "./createCmsContentEntryLoader.js";
|
|
6
|
+
export type { RemoteComponentEntry, LoadComponentsOptions, HydrateComponentDependencies, HydrateComponentOptions, HydratedComponent } from "./ComponentsSdk.js";
|
|
2
7
|
export type { ContentSdkConfig, WbConfig, CmsConfig } from "./types.js";
|
|
3
8
|
export { Result, HttpError, ApiError, NetworkError, ValidationError } from "@webiny/sdk";
|
|
4
9
|
export type { Language } from "@webiny/sdk";
|
package/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { FrontendSdk, sdk } from "./FrontendSdk.js";
|
|
2
|
+
export { ComponentsSdk } from "./ComponentsSdk.js";
|
|
3
|
+
export { resolveContentEntries } from "./resolveContentEntries.js";
|
|
4
|
+
export { createCmsContentEntryLoader } from "./createCmsContentEntryLoader.js";
|
|
2
5
|
export { ApiError, HttpError, NetworkError, Result, ValidationError } from "@webiny/sdk";
|
|
3
6
|
export { createComponent as createCmsComponent, resolveRefs } from "@webiny/cms-sdk";
|
|
4
7
|
export { createComponent as createWbComponent, createTheme } from "@webiny/website-builder-sdk";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/sdk-frontend",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.7c2def32a7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,14 +16,15 @@
|
|
|
16
16
|
],
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@webiny/cms-sdk": "0.0.0-unstable.
|
|
20
|
-
"@webiny/sdk": "0.0.0-unstable.
|
|
21
|
-
"@webiny/website-builder-sdk": "0.0.0-unstable.
|
|
19
|
+
"@webiny/cms-sdk": "0.0.0-unstable.7c2def32a7",
|
|
20
|
+
"@webiny/sdk": "0.0.0-unstable.7c2def32a7",
|
|
21
|
+
"@webiny/website-builder-sdk": "0.0.0-unstable.7c2def32a7",
|
|
22
|
+
"css-tree": "3.2.1"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
24
|
-
"@webiny/build-tools": "0.0.0-unstable.
|
|
25
|
+
"@webiny/build-tools": "0.0.0-unstable.7c2def32a7",
|
|
25
26
|
"typescript": "7.0.2",
|
|
26
|
-
"vitest": "4.1.
|
|
27
|
+
"vitest": "4.1.11"
|
|
27
28
|
},
|
|
28
29
|
"webiny": {
|
|
29
30
|
"publishFrom": "dist"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { createCmsClient } from "@webiny/cms-sdk";
|
|
3
|
+
import { contentEntryCache, createContentClient } from "@webiny/website-builder-sdk";
|
|
4
|
+
import { resolveContentEntries } from "./resolveContentEntries.js";
|
|
5
|
+
import { createCmsContentEntryLoader } from "./createCmsContentEntryLoader.js";
|
|
6
|
+
const fetch = vi.fn(async (_url, init)=>{
|
|
7
|
+
const headers = init?.headers;
|
|
8
|
+
const tenant = headers["x-tenant"];
|
|
9
|
+
const delay = "tenant-a" === tenant ? 20 : 0;
|
|
10
|
+
await new Promise((resolve)=>setTimeout(resolve, delay));
|
|
11
|
+
const entry = {
|
|
12
|
+
id: "42#0001",
|
|
13
|
+
entryId: "42",
|
|
14
|
+
values: {
|
|
15
|
+
title: `Article of ${tenant}`
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
ok: true,
|
|
20
|
+
json: async ()=>({
|
|
21
|
+
data: {
|
|
22
|
+
cms: {
|
|
23
|
+
getEntry: {
|
|
24
|
+
data: entry,
|
|
25
|
+
error: null
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
const createDocument = ()=>({
|
|
33
|
+
id: "doc1",
|
|
34
|
+
version: 1,
|
|
35
|
+
state: {},
|
|
36
|
+
properties: {},
|
|
37
|
+
extensions: {},
|
|
38
|
+
metadata: {},
|
|
39
|
+
elements: {
|
|
40
|
+
hero: {
|
|
41
|
+
id: "hero",
|
|
42
|
+
type: "Webiny/Element",
|
|
43
|
+
component: {
|
|
44
|
+
name: "Hero"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
bindings: {
|
|
49
|
+
hero: {
|
|
50
|
+
inputs: {
|
|
51
|
+
article: {
|
|
52
|
+
id: "article",
|
|
53
|
+
type: "contentEntry",
|
|
54
|
+
static: {
|
|
55
|
+
id: "42",
|
|
56
|
+
modelId: "blog"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
const createTenantClient = (tenant)=>{
|
|
64
|
+
const config = {
|
|
65
|
+
apiHost: `https://${tenant}.example.com`,
|
|
66
|
+
apiKey: `key-${tenant}`,
|
|
67
|
+
apiTenant: tenant
|
|
68
|
+
};
|
|
69
|
+
const cmsClient = createCmsClient({
|
|
70
|
+
...config,
|
|
71
|
+
fetch: fetch
|
|
72
|
+
});
|
|
73
|
+
return createContentClient({
|
|
74
|
+
...config,
|
|
75
|
+
contentEntryLoader: createCmsContentEntryLoader(cmsClient)
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
const titleOf = (value)=>{
|
|
79
|
+
const entry = value;
|
|
80
|
+
return entry.values.title;
|
|
81
|
+
};
|
|
82
|
+
describe("resolveContentEntries with a content client", ()=>{
|
|
83
|
+
it("resolves the same element id to each client's own tenant entry, concurrently", async ()=>{
|
|
84
|
+
const clientA = createTenantClient("tenant-a");
|
|
85
|
+
const clientB = createTenantClient("tenant-b");
|
|
86
|
+
const documentA = createDocument();
|
|
87
|
+
const documentB = createDocument();
|
|
88
|
+
await Promise.all([
|
|
89
|
+
resolveContentEntries(documentA, {
|
|
90
|
+
client: clientA
|
|
91
|
+
}),
|
|
92
|
+
resolveContentEntries(documentB, {
|
|
93
|
+
client: clientB
|
|
94
|
+
})
|
|
95
|
+
]);
|
|
96
|
+
const cachedA = clientA.getContentEntryCache().get("hero:article");
|
|
97
|
+
const cachedB = clientB.getContentEntryCache().get("hero:article");
|
|
98
|
+
expect(titleOf(cachedA)).toBe("Article of tenant-a");
|
|
99
|
+
expect(titleOf(cachedB)).toBe("Article of tenant-b");
|
|
100
|
+
const embeddedA = documentA.__cache?.contentEntries;
|
|
101
|
+
const embeddedB = documentB.__cache?.contentEntries;
|
|
102
|
+
expect(titleOf(embeddedA["hero:article"])).toBe("Article of tenant-a");
|
|
103
|
+
expect(titleOf(embeddedB["hero:article"])).toBe("Article of tenant-b");
|
|
104
|
+
expect(contentEntryCache.has("hero:article")).toBe(false);
|
|
105
|
+
});
|
|
106
|
+
it("refuses a client without a content entry loader instead of using the CMS singleton", async ()=>{
|
|
107
|
+
const client = createContentClient({
|
|
108
|
+
apiHost: "https://a.example.com",
|
|
109
|
+
apiKey: "key-a",
|
|
110
|
+
apiTenant: "tenant-a"
|
|
111
|
+
});
|
|
112
|
+
await expect(resolveContentEntries(createDocument(), {
|
|
113
|
+
client
|
|
114
|
+
})).rejects.toThrow("no contentEntryLoader");
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
//# sourceMappingURL=resolveContentEntries.client.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveContentEntries.client.test.js","sources":["../src/resolveContentEntries.client.test.ts"],"sourcesContent":["import { describe, it, expect, vi } from \"vitest\";\nimport { createCmsClient } from \"@webiny/cms-sdk\";\nimport { contentEntryCache, createContentClient } from \"@webiny/website-builder-sdk\";\nimport type { Document } from \"@webiny/website-builder-sdk\";\nimport { resolveContentEntries } from \"./resolveContentEntries.js\";\nimport { createCmsContentEntryLoader } from \"./createCmsContentEntryLoader.js\";\n\n// Answers every getEntry with an entry named after the tenant that asked. Tenant A answers last.\nconst fetch = vi.fn(async (_url: RequestInfo | URL, init?: RequestInit) => {\n const headers = init?.headers as Record<string, string>;\n const tenant = headers[\"x-tenant\"];\n\n const delay = tenant === \"tenant-a\" ? 20 : 0;\n await new Promise(resolve => setTimeout(resolve, delay));\n\n const entry = { id: \"42#0001\", entryId: \"42\", values: { title: `Article of ${tenant}` } };\n return {\n ok: true,\n json: async () => ({ data: { cms: { getEntry: { data: entry, error: null } } } })\n } as unknown as Response;\n});\n\n// The same page, seeded from one template into two tenants: same element id, same reference.\nconst createDocument = (): Document => {\n return {\n id: \"doc1\",\n version: 1,\n state: {},\n properties: {},\n extensions: {},\n metadata: {} as Document[\"metadata\"],\n elements: {\n hero: { id: \"hero\", type: \"Webiny/Element\", component: { name: \"Hero\" } }\n },\n bindings: {\n hero: {\n inputs: {\n article: {\n id: \"article\",\n type: \"contentEntry\",\n static: { id: \"42\", modelId: \"blog\" }\n }\n }\n }\n }\n };\n};\n\nconst createTenantClient = (tenant: string) => {\n const config = {\n apiHost: `https://${tenant}.example.com`,\n apiKey: `key-${tenant}`,\n apiTenant: tenant\n };\n const cmsClient = createCmsClient({ ...config, fetch });\n\n return createContentClient({\n ...config,\n contentEntryLoader: createCmsContentEntryLoader(cmsClient)\n });\n};\n\nconst titleOf = (value: unknown) => {\n const entry = value as { values: { title: string } };\n return entry.values.title;\n};\n\ndescribe(\"resolveContentEntries with a content client\", () => {\n it(\"resolves the same element id to each client's own tenant entry, concurrently\", async () => {\n const clientA = createTenantClient(\"tenant-a\");\n const clientB = createTenantClient(\"tenant-b\");\n const documentA = createDocument();\n const documentB = createDocument();\n\n await Promise.all([\n resolveContentEntries(documentA, { client: clientA }),\n resolveContentEntries(documentB, { client: clientB })\n ]);\n\n const cachedA = clientA.getContentEntryCache().get(\"hero:article\");\n const cachedB = clientB.getContentEntryCache().get(\"hero:article\");\n expect(titleOf(cachedA)).toBe(\"Article of tenant-a\");\n expect(titleOf(cachedB)).toBe(\"Article of tenant-b\");\n const embeddedA = documentA.__cache?.contentEntries as Record<string, unknown>;\n const embeddedB = documentB.__cache?.contentEntries as Record<string, unknown>;\n expect(titleOf(embeddedA[\"hero:article\"])).toBe(\"Article of tenant-a\");\n expect(titleOf(embeddedB[\"hero:article\"])).toBe(\"Article of tenant-b\");\n\n // The singleton cache isn't touched.\n expect(contentEntryCache.has(\"hero:article\")).toBe(false);\n });\n\n it(\"refuses a client without a content entry loader instead of using the CMS singleton\", async () => {\n const client = createContentClient({\n apiHost: \"https://a.example.com\",\n apiKey: \"key-a\",\n apiTenant: \"tenant-a\"\n });\n\n await expect(resolveContentEntries(createDocument(), { client })).rejects.toThrow(\n \"no contentEntryLoader\"\n );\n });\n});\n"],"names":["fetch","vi","_url","init","headers","tenant","delay","Promise","resolve","setTimeout","entry","createDocument","createTenantClient","config","cmsClient","createCmsClient","createContentClient","createCmsContentEntryLoader","titleOf","value","describe","it","clientA","clientB","documentA","documentB","resolveContentEntries","cachedA","cachedB","expect","embeddedA","embeddedB","contentEntryCache","client"],"mappings":";;;;;AAQA,MAAMA,QAAQC,GAAG,EAAE,CAAC,OAAOC,MAAyBC;IAChD,MAAMC,UAAUD,MAAM;IACtB,MAAME,SAASD,OAAO,CAAC,WAAW;IAElC,MAAME,QAAQD,AAAW,eAAXA,SAAwB,KAAK;IAC3C,MAAM,IAAIE,QAAQC,CAAAA,UAAWC,WAAWD,SAASF;IAEjD,MAAMI,QAAQ;QAAE,IAAI;QAAW,SAAS;QAAM,QAAQ;YAAE,OAAO,CAAC,WAAW,EAAEL,QAAQ;QAAC;IAAE;IACxF,OAAO;QACH,IAAI;QACJ,MAAM,UAAa;gBAAE,MAAM;oBAAE,KAAK;wBAAE,UAAU;4BAAE,MAAMK;4BAAO,OAAO;wBAAK;oBAAE;gBAAE;YAAE;IACnF;AACJ;AAGA,MAAMC,iBAAiB,IACZ;QACH,IAAI;QACJ,SAAS;QACT,OAAO,CAAC;QACR,YAAY,CAAC;QACb,YAAY,CAAC;QACb,UAAU,CAAC;QACX,UAAU;YACN,MAAM;gBAAE,IAAI;gBAAQ,MAAM;gBAAkB,WAAW;oBAAE,MAAM;gBAAO;YAAE;QAC5E;QACA,UAAU;YACN,MAAM;gBACF,QAAQ;oBACJ,SAAS;wBACL,IAAI;wBACJ,MAAM;wBACN,QAAQ;4BAAE,IAAI;4BAAM,SAAS;wBAAO;oBACxC;gBACJ;YACJ;QACJ;IACJ;AAGJ,MAAMC,qBAAqB,CAACP;IACxB,MAAMQ,SAAS;QACX,SAAS,CAAC,QAAQ,EAAER,OAAO,YAAY,CAAC;QACxC,QAAQ,CAAC,IAAI,EAAEA,QAAQ;QACvB,WAAWA;IACf;IACA,MAAMS,YAAYC,gBAAgB;QAAE,GAAGF,MAAM;QAAEb,OAAAA;IAAM;IAErD,OAAOgB,oBAAoB;QACvB,GAAGH,MAAM;QACT,oBAAoBI,4BAA4BH;IACpD;AACJ;AAEA,MAAMI,UAAU,CAACC;IACb,MAAMT,QAAQS;IACd,OAAOT,MAAM,MAAM,CAAC,KAAK;AAC7B;AAEAU,SAAS,+CAA+C;IACpDC,GAAG,gFAAgF;QAC/E,MAAMC,UAAUV,mBAAmB;QACnC,MAAMW,UAAUX,mBAAmB;QACnC,MAAMY,YAAYb;QAClB,MAAMc,YAAYd;QAElB,MAAMJ,QAAQ,GAAG,CAAC;YACdmB,sBAAsBF,WAAW;gBAAE,QAAQF;YAAQ;YACnDI,sBAAsBD,WAAW;gBAAE,QAAQF;YAAQ;SACtD;QAED,MAAMI,UAAUL,QAAQ,oBAAoB,GAAG,GAAG,CAAC;QACnD,MAAMM,UAAUL,QAAQ,oBAAoB,GAAG,GAAG,CAAC;QACnDM,OAAOX,QAAQS,UAAU,IAAI,CAAC;QAC9BE,OAAOX,QAAQU,UAAU,IAAI,CAAC;QAC9B,MAAME,YAAYN,UAAU,OAAO,EAAE;QACrC,MAAMO,YAAYN,UAAU,OAAO,EAAE;QACrCI,OAAOX,QAAQY,SAAS,CAAC,eAAe,GAAG,IAAI,CAAC;QAChDD,OAAOX,QAAQa,SAAS,CAAC,eAAe,GAAG,IAAI,CAAC;QAGhDF,OAAOG,kBAAkB,GAAG,CAAC,iBAAiB,IAAI,CAAC;IACvD;IAEAX,GAAG,sFAAsF;QACrF,MAAMY,SAASjB,oBAAoB;YAC/B,SAAS;YACT,QAAQ;YACR,WAAW;QACf;QAEA,MAAMa,OAAOH,sBAAsBf,kBAAkB;YAAEsB;QAAO,IAAI,OAAO,CAAC,OAAO,CAC7E;IAER;AACJ"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ContentClient, Document } from "@webiny/website-builder-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Register the CMS data loader on the SDK-level content-entry cache.
|
|
4
|
+
*
|
|
5
|
+
* Called by `resolveContentEntries` (server pre-pass) AND by `FrontendSdk.init()`
|
|
6
|
+
* (client bootstrap) so the `BindingsResolver` can resolve content-entry
|
|
7
|
+
* inputs in both environments.
|
|
8
|
+
*/
|
|
9
|
+
export declare const ensureContentEntryLoader: () => void;
|
|
10
|
+
export type ResolveContentEntriesOptions = {
|
|
11
|
+
client?: ContentClient;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Server-side (RSC) pre-pass: resolves every `contentEntry` input into CMS
|
|
15
|
+
* entries and seeds the SDK-level `contentEntryCache`, or the given client's cache.
|
|
16
|
+
*
|
|
17
|
+
* Content-entry inputs are identified by the `type` field on each
|
|
18
|
+
* `InputValueBinding` — no component manifests or metadata required.
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveContentEntries(document: Document | null, options?: ResolveContentEntriesOptions): Promise<void>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { contentEntryCache, isAlreadyResolved, resolveContentEntryValue } from "@webiny/website-builder-sdk";
|
|
2
|
+
import { contentSdk } from "@webiny/cms-sdk";
|
|
3
|
+
const ensureContentEntryLoader = ()=>{
|
|
4
|
+
if (!contentEntryCache.getLoader()) contentEntryCache.setLoader({
|
|
5
|
+
getEntry: (params)=>contentSdk.getEntry(params),
|
|
6
|
+
listEntries: (params)=>contentSdk.listEntries(params)
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
async function resolveContentEntries(document, options = {}) {
|
|
10
|
+
if (!document) return;
|
|
11
|
+
let cache = contentEntryCache;
|
|
12
|
+
if (options.client) cache = options.client.getContentEntryCache();
|
|
13
|
+
else ensureContentEntryLoader();
|
|
14
|
+
const loader = cache.getLoader();
|
|
15
|
+
if (!loader) throw new Error("The content client has no contentEntryLoader. Pass one in its config, bound to the client's tenant.");
|
|
16
|
+
const resolved = {};
|
|
17
|
+
const tasks = [];
|
|
18
|
+
for (const [elementId] of Object.entries(document.elements)){
|
|
19
|
+
const elementBindings = document.bindings[elementId] ?? {};
|
|
20
|
+
const inputBindings = elementBindings.inputs;
|
|
21
|
+
if (inputBindings) for (const [inputName, binding] of Object.entries(inputBindings)){
|
|
22
|
+
if (!binding || "contentEntry" !== binding.type) continue;
|
|
23
|
+
const rawValue = binding.static;
|
|
24
|
+
const list = binding.list ?? false;
|
|
25
|
+
const cacheKey = `${elementId}:${inputName}`;
|
|
26
|
+
if (isAlreadyResolved(rawValue, list)) {
|
|
27
|
+
cache.set(cacheKey, rawValue);
|
|
28
|
+
resolved[cacheKey] = rawValue;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
tasks.push(resolveContentEntryValue(rawValue, list, loader).then((result)=>{
|
|
32
|
+
cache.set(cacheKey, result);
|
|
33
|
+
resolved[cacheKey] = result;
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
await Promise.all(tasks);
|
|
38
|
+
if (Object.keys(resolved).length > 0) {
|
|
39
|
+
if (!document.__cache) document.__cache = {};
|
|
40
|
+
document.__cache.contentEntries = resolved;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export { ensureContentEntryLoader, resolveContentEntries };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=resolveContentEntries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveContentEntries.js","sources":["../src/resolveContentEntries.ts"],"sourcesContent":["import type { ContentClient, Document } from \"@webiny/website-builder-sdk\";\nimport {\n contentEntryCache,\n resolveContentEntryValue,\n isAlreadyResolved\n} from \"@webiny/website-builder-sdk\";\nimport { contentSdk } from \"@webiny/cms-sdk\";\n\n/**\n * Register the CMS data loader on the SDK-level content-entry cache.\n *\n * Called by `resolveContentEntries` (server pre-pass) AND by `FrontendSdk.init()`\n * (client bootstrap) so the `BindingsResolver` can resolve content-entry\n * inputs in both environments.\n */\nexport const ensureContentEntryLoader = () => {\n if (!contentEntryCache.getLoader()) {\n contentEntryCache.setLoader({\n getEntry: params => contentSdk.getEntry(params),\n listEntries: params => contentSdk.listEntries(params)\n });\n }\n};\n\nexport type ResolveContentEntriesOptions = {\n /*\n * Resolve with this content client's entry cache and loader instead of the\n * `contentEntryCache` singleton and the `@webiny/cms-sdk` singleton. The client\n * needs a `contentEntryLoader` in its config.\n */\n client?: ContentClient;\n};\n\n/**\n * Server-side (RSC) pre-pass: resolves every `contentEntry` input into CMS\n * entries and seeds the SDK-level `contentEntryCache`, or the given client's cache.\n *\n * Content-entry inputs are identified by the `type` field on each\n * `InputValueBinding` — no component manifests or metadata required.\n */\nexport async function resolveContentEntries(\n document: Document | null,\n options: ResolveContentEntriesOptions = {}\n): Promise<void> {\n if (!document) {\n return;\n }\n\n let cache = contentEntryCache;\n if (options.client) {\n cache = options.client.getContentEntryCache();\n } else {\n ensureContentEntryLoader();\n }\n\n const loader = cache.getLoader();\n if (!loader) {\n throw new Error(\n \"The content client has no contentEntryLoader. Pass one in its config, bound to the client's tenant.\"\n );\n }\n\n // Collect resolved entries so they can be embedded on the document and\n // travel through React serialisation from server to client.\n const resolved: Record<string, unknown> = {};\n const tasks: Promise<void>[] = [];\n\n for (const [elementId] of Object.entries(document.elements)) {\n const elementBindings = document.bindings[elementId] ?? {};\n const inputBindings = elementBindings.inputs;\n\n if (!inputBindings) {\n continue;\n }\n\n for (const [inputName, binding] of Object.entries(inputBindings)) {\n if (!binding || binding.type !== \"contentEntry\") {\n continue;\n }\n\n const rawValue = binding.static;\n const list = binding.list ?? false;\n const cacheKey = `${elementId}:${inputName}`;\n\n // Already-resolved entries (e.g. editor stored the full entry, not\n // a bare reference) are passed through directly.\n if (isAlreadyResolved(rawValue, list)) {\n cache.set(cacheKey, rawValue);\n resolved[cacheKey] = rawValue;\n continue;\n }\n\n tasks.push(\n resolveContentEntryValue(rawValue, list, loader).then(result => {\n cache.set(cacheKey, result);\n resolved[cacheKey] = result;\n })\n );\n }\n }\n\n await Promise.all(tasks);\n\n // Embed resolved entries on the document cache so the client\n // `BindingsResolver` can hydrate from them (the module-level\n // `contentEntryCache` singleton does not cross the server→client boundary).\n if (Object.keys(resolved).length > 0) {\n if (!document.__cache) {\n document.__cache = {};\n }\n document.__cache.contentEntries = resolved;\n }\n}\n"],"names":["ensureContentEntryLoader","contentEntryCache","params","contentSdk","resolveContentEntries","document","options","cache","loader","Error","resolved","tasks","elementId","Object","elementBindings","inputBindings","inputName","binding","rawValue","list","cacheKey","isAlreadyResolved","resolveContentEntryValue","result","Promise"],"mappings":";;AAeO,MAAMA,2BAA2B;IACpC,IAAI,CAACC,kBAAkB,SAAS,IAC5BA,kBAAkB,SAAS,CAAC;QACxB,UAAUC,CAAAA,SAAUC,WAAW,QAAQ,CAACD;QACxC,aAAaA,CAAAA,SAAUC,WAAW,WAAW,CAACD;IAClD;AAER;AAkBO,eAAeE,sBAClBC,QAAyB,EACzBC,UAAwC,CAAC,CAAC;IAE1C,IAAI,CAACD,UACD;IAGJ,IAAIE,QAAQN;IACZ,IAAIK,QAAQ,MAAM,EACdC,QAAQD,QAAQ,MAAM,CAAC,oBAAoB;SAE3CN;IAGJ,MAAMQ,SAASD,MAAM,SAAS;IAC9B,IAAI,CAACC,QACD,MAAM,IAAIC,MACN;IAMR,MAAMC,WAAoC,CAAC;IAC3C,MAAMC,QAAyB,EAAE;IAEjC,KAAK,MAAM,CAACC,UAAU,IAAIC,OAAO,OAAO,CAACR,SAAS,QAAQ,EAAG;QACzD,MAAMS,kBAAkBT,SAAS,QAAQ,CAACO,UAAU,IAAI,CAAC;QACzD,MAAMG,gBAAgBD,gBAAgB,MAAM;QAE5C,IAAKC,eAIL,KAAK,MAAM,CAACC,WAAWC,QAAQ,IAAIJ,OAAO,OAAO,CAACE,eAAgB;YAC9D,IAAI,CAACE,WAAWA,AAAiB,mBAAjBA,QAAQ,IAAI,EACxB;YAGJ,MAAMC,WAAWD,QAAQ,MAAM;YAC/B,MAAME,OAAOF,QAAQ,IAAI,IAAI;YAC7B,MAAMG,WAAW,GAAGR,UAAU,CAAC,EAAEI,WAAW;YAI5C,IAAIK,kBAAkBH,UAAUC,OAAO;gBACnCZ,MAAM,GAAG,CAACa,UAAUF;gBACpBR,QAAQ,CAACU,SAAS,GAAGF;gBACrB;YACJ;YAEAP,MAAM,IAAI,CACNW,yBAAyBJ,UAAUC,MAAMX,QAAQ,IAAI,CAACe,CAAAA;gBAClDhB,MAAM,GAAG,CAACa,UAAUG;gBACpBb,QAAQ,CAACU,SAAS,GAAGG;YACzB;QAER;IACJ;IAEA,MAAMC,QAAQ,GAAG,CAACb;IAKlB,IAAIE,OAAO,IAAI,CAACH,UAAU,MAAM,GAAG,GAAG;QAClC,IAAI,CAACL,SAAS,OAAO,EACjBA,SAAS,OAAO,GAAG,CAAC;QAExBA,SAAS,OAAO,CAAC,cAAc,GAAGK;IACtC;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { resolveContentEntries } from "./resolveContentEntries.js";
|
|
3
|
+
import { contentEntryCache } from "@webiny/website-builder-sdk";
|
|
4
|
+
const mockGetEntry = vi.fn();
|
|
5
|
+
const mockListEntries = vi.fn();
|
|
6
|
+
vi.mock("@webiny/cms-sdk", ()=>({
|
|
7
|
+
contentSdk: {
|
|
8
|
+
getEntry: (...args)=>mockGetEntry(...args),
|
|
9
|
+
listEntries: (...args)=>mockListEntries(...args)
|
|
10
|
+
}
|
|
11
|
+
}));
|
|
12
|
+
const entry = (id)=>({
|
|
13
|
+
id,
|
|
14
|
+
entryId: id,
|
|
15
|
+
values: {
|
|
16
|
+
title: `T${id}`
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
function makeDocument(overrides = {}) {
|
|
20
|
+
return {
|
|
21
|
+
id: "doc1",
|
|
22
|
+
version: 1,
|
|
23
|
+
state: {},
|
|
24
|
+
properties: {},
|
|
25
|
+
extensions: {},
|
|
26
|
+
metadata: {},
|
|
27
|
+
bindings: {},
|
|
28
|
+
elements: {},
|
|
29
|
+
...overrides
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
beforeEach(()=>{
|
|
33
|
+
vi.clearAllMocks();
|
|
34
|
+
contentEntryCache.cache?.clear?.();
|
|
35
|
+
contentEntryCache.loader = void 0;
|
|
36
|
+
mockGetEntry.mockImplementation(async ({ entryId })=>entry(entryId));
|
|
37
|
+
mockListEntries.mockImplementation(async ()=>({
|
|
38
|
+
data: [
|
|
39
|
+
entry("q1"),
|
|
40
|
+
entry("q2")
|
|
41
|
+
],
|
|
42
|
+
meta: {
|
|
43
|
+
cursor: "c1",
|
|
44
|
+
hasMoreItems: false,
|
|
45
|
+
totalCount: 2
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
});
|
|
49
|
+
describe("resolveContentEntries — binding-type-based resolution", ()=>{
|
|
50
|
+
it("does nothing for a null document", async ()=>{
|
|
51
|
+
await resolveContentEntries(null);
|
|
52
|
+
expect(mockGetEntry).not.toHaveBeenCalled();
|
|
53
|
+
});
|
|
54
|
+
it("does nothing when no elements have content-entry bindings", async ()=>{
|
|
55
|
+
const doc = makeDocument({
|
|
56
|
+
elements: {
|
|
57
|
+
el1: {
|
|
58
|
+
id: "el1",
|
|
59
|
+
type: "Webiny/Element",
|
|
60
|
+
component: {
|
|
61
|
+
name: "MyComponent"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
bindings: {
|
|
66
|
+
el1: {
|
|
67
|
+
inputs: {
|
|
68
|
+
text: {
|
|
69
|
+
id: "text",
|
|
70
|
+
type: "text",
|
|
71
|
+
static: "hello"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
await resolveContentEntries(doc);
|
|
78
|
+
expect(mockGetEntry).not.toHaveBeenCalled();
|
|
79
|
+
expect(doc.__cache).toBeUndefined();
|
|
80
|
+
});
|
|
81
|
+
it("resolves a manual single content-entry input", async ()=>{
|
|
82
|
+
const doc = makeDocument({
|
|
83
|
+
elements: {
|
|
84
|
+
el1: {
|
|
85
|
+
id: "el1",
|
|
86
|
+
type: "Webiny/Element",
|
|
87
|
+
component: {
|
|
88
|
+
name: "MyComponent"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
bindings: {
|
|
93
|
+
el1: {
|
|
94
|
+
inputs: {
|
|
95
|
+
article: {
|
|
96
|
+
id: "article",
|
|
97
|
+
type: "contentEntry",
|
|
98
|
+
static: {
|
|
99
|
+
id: "42",
|
|
100
|
+
modelId: "blog"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
await resolveContentEntries(doc);
|
|
108
|
+
expect(mockGetEntry).toHaveBeenCalledWith({
|
|
109
|
+
modelId: "blog",
|
|
110
|
+
entryId: "42"
|
|
111
|
+
});
|
|
112
|
+
expect(doc.__cache?.contentEntries).toBeDefined();
|
|
113
|
+
expect(doc.__cache.contentEntries["el1:article"]).toEqual(entry("42"));
|
|
114
|
+
});
|
|
115
|
+
it("resolves a manual list content-entry input", async ()=>{
|
|
116
|
+
const doc = makeDocument({
|
|
117
|
+
elements: {
|
|
118
|
+
el1: {
|
|
119
|
+
id: "el1",
|
|
120
|
+
type: "Webiny/Element",
|
|
121
|
+
component: {
|
|
122
|
+
name: "MyComponent"
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
bindings: {
|
|
127
|
+
el1: {
|
|
128
|
+
inputs: {
|
|
129
|
+
articles: {
|
|
130
|
+
id: "articles",
|
|
131
|
+
type: "contentEntry",
|
|
132
|
+
list: true,
|
|
133
|
+
static: [
|
|
134
|
+
{
|
|
135
|
+
id: "1",
|
|
136
|
+
modelId: "blog"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: "2",
|
|
140
|
+
modelId: "blog"
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
await resolveContentEntries(doc);
|
|
149
|
+
expect(mockGetEntry).toHaveBeenCalledTimes(2);
|
|
150
|
+
const resolved = doc.__cache.contentEntries["el1:articles"];
|
|
151
|
+
expect(resolved).toEqual([
|
|
152
|
+
entry("1"),
|
|
153
|
+
entry("2")
|
|
154
|
+
]);
|
|
155
|
+
});
|
|
156
|
+
it("resolves a query-mode content-entry input (modelId in value)", async ()=>{
|
|
157
|
+
const doc = makeDocument({
|
|
158
|
+
elements: {
|
|
159
|
+
el1: {
|
|
160
|
+
id: "el1",
|
|
161
|
+
type: "Webiny/Element",
|
|
162
|
+
component: {
|
|
163
|
+
name: "MyComponent"
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
bindings: {
|
|
168
|
+
el1: {
|
|
169
|
+
inputs: {
|
|
170
|
+
posts: {
|
|
171
|
+
id: "posts",
|
|
172
|
+
type: "contentEntry",
|
|
173
|
+
static: {
|
|
174
|
+
modelId: "blog",
|
|
175
|
+
limit: 5
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
await resolveContentEntries(doc);
|
|
183
|
+
expect(mockListEntries).toHaveBeenCalledWith(expect.objectContaining({
|
|
184
|
+
modelId: "blog",
|
|
185
|
+
limit: 5
|
|
186
|
+
}));
|
|
187
|
+
const resolved = doc.__cache.contentEntries["el1:posts"];
|
|
188
|
+
expect(resolved).toMatchObject({
|
|
189
|
+
items: [
|
|
190
|
+
entry("q1"),
|
|
191
|
+
entry("q2")
|
|
192
|
+
],
|
|
193
|
+
pageInfo: expect.objectContaining({
|
|
194
|
+
totalCount: 2
|
|
195
|
+
})
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
it("passes through already-resolved entries without re-fetching", async ()=>{
|
|
199
|
+
const resolvedEntry = {
|
|
200
|
+
id: "42",
|
|
201
|
+
entryId: "42",
|
|
202
|
+
values: {
|
|
203
|
+
title: "Already resolved"
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
const doc = makeDocument({
|
|
207
|
+
elements: {
|
|
208
|
+
el1: {
|
|
209
|
+
id: "el1",
|
|
210
|
+
type: "Webiny/Element",
|
|
211
|
+
component: {
|
|
212
|
+
name: "MyComponent"
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
bindings: {
|
|
217
|
+
el1: {
|
|
218
|
+
inputs: {
|
|
219
|
+
article: {
|
|
220
|
+
id: "article",
|
|
221
|
+
type: "contentEntry",
|
|
222
|
+
static: resolvedEntry
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
await resolveContentEntries(doc);
|
|
229
|
+
expect(mockGetEntry).not.toHaveBeenCalled();
|
|
230
|
+
expect(doc.__cache.contentEntries["el1:article"]).toEqual(resolvedEntry);
|
|
231
|
+
});
|
|
232
|
+
it("handles multiple elements with content-entry inputs", async ()=>{
|
|
233
|
+
const doc = makeDocument({
|
|
234
|
+
elements: {
|
|
235
|
+
el1: {
|
|
236
|
+
id: "el1",
|
|
237
|
+
type: "Webiny/Element",
|
|
238
|
+
component: {
|
|
239
|
+
name: "Hero"
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
el2: {
|
|
243
|
+
id: "el2",
|
|
244
|
+
type: "Webiny/Element",
|
|
245
|
+
component: {
|
|
246
|
+
name: "Sidebar"
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
bindings: {
|
|
251
|
+
el1: {
|
|
252
|
+
inputs: {
|
|
253
|
+
featured: {
|
|
254
|
+
id: "featured",
|
|
255
|
+
type: "contentEntry",
|
|
256
|
+
static: {
|
|
257
|
+
id: "10",
|
|
258
|
+
modelId: "article"
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
el2: {
|
|
264
|
+
inputs: {
|
|
265
|
+
related: {
|
|
266
|
+
id: "related",
|
|
267
|
+
type: "contentEntry",
|
|
268
|
+
static: {
|
|
269
|
+
id: "20",
|
|
270
|
+
modelId: "article"
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
await resolveContentEntries(doc);
|
|
278
|
+
expect(mockGetEntry).toHaveBeenCalledTimes(2);
|
|
279
|
+
const resolved = doc.__cache.contentEntries;
|
|
280
|
+
expect(resolved["el1:featured"]).toEqual(entry("10"));
|
|
281
|
+
expect(resolved["el2:related"]).toEqual(entry("20"));
|
|
282
|
+
});
|
|
283
|
+
it("skips non-contentEntry bindings", async ()=>{
|
|
284
|
+
const doc = makeDocument({
|
|
285
|
+
elements: {
|
|
286
|
+
el1: {
|
|
287
|
+
id: "el1",
|
|
288
|
+
type: "Webiny/Element",
|
|
289
|
+
component: {
|
|
290
|
+
name: "Mixed"
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
bindings: {
|
|
295
|
+
el1: {
|
|
296
|
+
inputs: {
|
|
297
|
+
text: {
|
|
298
|
+
id: "text",
|
|
299
|
+
type: "text",
|
|
300
|
+
static: "hello"
|
|
301
|
+
},
|
|
302
|
+
number: {
|
|
303
|
+
id: "number",
|
|
304
|
+
type: "number",
|
|
305
|
+
static: 42
|
|
306
|
+
},
|
|
307
|
+
item: {
|
|
308
|
+
id: "item",
|
|
309
|
+
type: "contentEntry",
|
|
310
|
+
static: {
|
|
311
|
+
id: "5",
|
|
312
|
+
modelId: "blog"
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
await resolveContentEntries(doc);
|
|
320
|
+
expect(mockGetEntry).toHaveBeenCalledTimes(1);
|
|
321
|
+
expect(mockGetEntry).toHaveBeenCalledWith({
|
|
322
|
+
modelId: "blog",
|
|
323
|
+
entryId: "5"
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
//# sourceMappingURL=resolveContentEntries.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveContentEntries.test.js","sources":["../src/resolveContentEntries.test.ts"],"sourcesContent":["import { describe, it, expect, vi, beforeEach } from \"vitest\";\nimport { resolveContentEntries } from \"./resolveContentEntries.js\";\nimport { contentEntryCache } from \"@webiny/website-builder-sdk\";\nimport type { Document } from \"@webiny/website-builder-sdk\";\n\n// Mock the CMS SDK so `ensureContentEntryLoader` wires up a controllable loader.\nconst mockGetEntry = vi.fn();\nconst mockListEntries = vi.fn();\n\nvi.mock(\"@webiny/cms-sdk\", () => ({\n contentSdk: {\n getEntry: (...args: unknown[]) => mockGetEntry(...args),\n listEntries: (...args: unknown[]) => mockListEntries(...args)\n }\n}));\n\nconst entry = (id: string) => ({ id, entryId: id, values: { title: `T${id}` } });\n\nfunction makeDocument(overrides: Partial<Document> = {}): Document {\n return {\n id: \"doc1\",\n version: 1,\n state: {},\n properties: {},\n extensions: {},\n metadata: {},\n bindings: {},\n elements: {},\n ...overrides\n };\n}\n\nbeforeEach(() => {\n vi.clearAllMocks();\n // Reset the singleton cache between tests.\n (contentEntryCache as any).cache?.clear?.();\n (contentEntryCache as any).loader = undefined;\n\n mockGetEntry.mockImplementation(async ({ entryId }: { entryId: string }) => entry(entryId));\n mockListEntries.mockImplementation(async () => ({\n data: [entry(\"q1\"), entry(\"q2\")],\n meta: { cursor: \"c1\", hasMoreItems: false, totalCount: 2 }\n }));\n});\n\ndescribe(\"resolveContentEntries — binding-type-based resolution\", () => {\n it(\"does nothing for a null document\", async () => {\n await resolveContentEntries(null);\n expect(mockGetEntry).not.toHaveBeenCalled();\n });\n\n it(\"does nothing when no elements have content-entry bindings\", async () => {\n const doc = makeDocument({\n elements: {\n el1: {\n id: \"el1\",\n type: \"Webiny/Element\",\n component: { name: \"MyComponent\" }\n }\n },\n bindings: {\n el1: {\n inputs: {\n text: { id: \"text\", type: \"text\", static: \"hello\" }\n }\n }\n }\n });\n\n await resolveContentEntries(doc);\n expect(mockGetEntry).not.toHaveBeenCalled();\n expect(doc.__cache).toBeUndefined();\n });\n\n it(\"resolves a manual single content-entry input\", async () => {\n const doc = makeDocument({\n elements: {\n el1: {\n id: \"el1\",\n type: \"Webiny/Element\",\n component: { name: \"MyComponent\" }\n }\n },\n bindings: {\n el1: {\n inputs: {\n article: {\n id: \"article\",\n type: \"contentEntry\",\n static: { id: \"42\", modelId: \"blog\" }\n }\n }\n }\n }\n });\n\n await resolveContentEntries(doc);\n\n expect(mockGetEntry).toHaveBeenCalledWith({ modelId: \"blog\", entryId: \"42\" });\n expect(doc.__cache?.contentEntries).toBeDefined();\n expect((doc.__cache!.contentEntries as Record<string, unknown>)[\"el1:article\"]).toEqual(\n entry(\"42\")\n );\n });\n\n it(\"resolves a manual list content-entry input\", async () => {\n const doc = makeDocument({\n elements: {\n el1: {\n id: \"el1\",\n type: \"Webiny/Element\",\n component: { name: \"MyComponent\" }\n }\n },\n bindings: {\n el1: {\n inputs: {\n articles: {\n id: \"articles\",\n type: \"contentEntry\",\n list: true,\n static: [\n { id: \"1\", modelId: \"blog\" },\n { id: \"2\", modelId: \"blog\" }\n ]\n }\n }\n }\n }\n });\n\n await resolveContentEntries(doc);\n\n expect(mockGetEntry).toHaveBeenCalledTimes(2);\n const resolved = (doc.__cache!.contentEntries as Record<string, unknown>)[\"el1:articles\"];\n expect(resolved).toEqual([entry(\"1\"), entry(\"2\")]);\n });\n\n it(\"resolves a query-mode content-entry input (modelId in value)\", async () => {\n const doc = makeDocument({\n elements: {\n el1: {\n id: \"el1\",\n type: \"Webiny/Element\",\n component: { name: \"MyComponent\" }\n }\n },\n bindings: {\n el1: {\n inputs: {\n posts: {\n id: \"posts\",\n type: \"contentEntry\",\n static: { modelId: \"blog\", limit: 5 }\n }\n }\n }\n }\n });\n\n await resolveContentEntries(doc);\n\n expect(mockListEntries).toHaveBeenCalledWith(\n expect.objectContaining({ modelId: \"blog\", limit: 5 })\n );\n const resolved = (doc.__cache!.contentEntries as Record<string, unknown>)[\"el1:posts\"];\n expect(resolved).toMatchObject({\n items: [entry(\"q1\"), entry(\"q2\")],\n pageInfo: expect.objectContaining({ totalCount: 2 })\n });\n });\n\n it(\"passes through already-resolved entries without re-fetching\", async () => {\n const resolvedEntry = { id: \"42\", entryId: \"42\", values: { title: \"Already resolved\" } };\n const doc = makeDocument({\n elements: {\n el1: {\n id: \"el1\",\n type: \"Webiny/Element\",\n component: { name: \"MyComponent\" }\n }\n },\n bindings: {\n el1: {\n inputs: {\n article: {\n id: \"article\",\n type: \"contentEntry\",\n static: resolvedEntry\n }\n }\n }\n }\n });\n\n await resolveContentEntries(doc);\n\n expect(mockGetEntry).not.toHaveBeenCalled();\n expect((doc.__cache!.contentEntries as Record<string, unknown>)[\"el1:article\"]).toEqual(\n resolvedEntry\n );\n });\n\n it(\"handles multiple elements with content-entry inputs\", async () => {\n const doc = makeDocument({\n elements: {\n el1: {\n id: \"el1\",\n type: \"Webiny/Element\",\n component: { name: \"Hero\" }\n },\n el2: {\n id: \"el2\",\n type: \"Webiny/Element\",\n component: { name: \"Sidebar\" }\n }\n },\n bindings: {\n el1: {\n inputs: {\n featured: {\n id: \"featured\",\n type: \"contentEntry\",\n static: { id: \"10\", modelId: \"article\" }\n }\n }\n },\n el2: {\n inputs: {\n related: {\n id: \"related\",\n type: \"contentEntry\",\n static: { id: \"20\", modelId: \"article\" }\n }\n }\n }\n }\n });\n\n await resolveContentEntries(doc);\n\n expect(mockGetEntry).toHaveBeenCalledTimes(2);\n const resolved = doc.__cache!.contentEntries as Record<string, unknown>;\n expect(resolved[\"el1:featured\"]).toEqual(entry(\"10\"));\n expect(resolved[\"el2:related\"]).toEqual(entry(\"20\"));\n });\n\n it(\"skips non-contentEntry bindings\", async () => {\n const doc = makeDocument({\n elements: {\n el1: {\n id: \"el1\",\n type: \"Webiny/Element\",\n component: { name: \"Mixed\" }\n }\n },\n bindings: {\n el1: {\n inputs: {\n text: { id: \"text\", type: \"text\", static: \"hello\" },\n number: { id: \"number\", type: \"number\", static: 42 },\n item: {\n id: \"item\",\n type: \"contentEntry\",\n static: { id: \"5\", modelId: \"blog\" }\n }\n }\n }\n }\n });\n\n await resolveContentEntries(doc);\n\n // Only the contentEntry input should be resolved.\n expect(mockGetEntry).toHaveBeenCalledTimes(1);\n expect(mockGetEntry).toHaveBeenCalledWith({ modelId: \"blog\", entryId: \"5\" });\n });\n});\n"],"names":["mockGetEntry","vi","mockListEntries","args","entry","id","makeDocument","overrides","beforeEach","contentEntryCache","undefined","entryId","describe","it","resolveContentEntries","expect","doc","resolved","resolvedEntry"],"mappings":";;;AAMA,MAAMA,eAAeC,GAAG,EAAE;AAC1B,MAAMC,kBAAkBD,GAAG,EAAE;AAE7BA,GAAG,IAAI,CAAC,mBAAmB,IAAO;QAC9B,YAAY;YACR,UAAU,CAAC,GAAGE,OAAoBH,gBAAgBG;YAClD,aAAa,CAAC,GAAGA,OAAoBD,mBAAmBC;QAC5D;IACJ;AAEA,MAAMC,QAAQ,CAACC,KAAgB;QAAEA;QAAI,SAASA;QAAI,QAAQ;YAAE,OAAO,CAAC,CAAC,EAAEA,IAAI;QAAC;IAAE;AAE9E,SAASC,aAAaC,YAA+B,CAAC,CAAC;IACnD,OAAO;QACH,IAAI;QACJ,SAAS;QACT,OAAO,CAAC;QACR,YAAY,CAAC;QACb,YAAY,CAAC;QACb,UAAU,CAAC;QACX,UAAU,CAAC;QACX,UAAU,CAAC;QACX,GAAGA,SAAS;IAChB;AACJ;AAEAC,WAAW;IACPP,GAAG,aAAa;IAEfQ,kBAAAA,KAA+B,EAAE;IACjCA,kBAAAA,MAAgC,GAAGC;IAEpCV,aAAa,kBAAkB,CAAC,OAAO,EAAEW,O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