@webiny/sdk-frontend 0.0.0-unstable.0156a4c312

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.
@@ -0,0 +1,313 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+ import { ApiError, HttpError, NetworkError } from "@webiny/sdk";
3
+ import { ComponentsSdk } from "./ComponentsSdk.js";
4
+ const endpoint = "https://api.example.com";
5
+ const entry = {
6
+ id: "c1",
7
+ name: "acme/hero",
8
+ label: "Hero",
9
+ bundledJs: "",
10
+ bundledJsSha256: "",
11
+ bundledCss: "",
12
+ bundledCssSha256: "",
13
+ sdkVersion: "1",
14
+ status: "published"
15
+ };
16
+ function jsonResponse(body, status = 200) {
17
+ return new Response(JSON.stringify(body), {
18
+ status,
19
+ headers: {
20
+ "Content-Type": "application/json"
21
+ }
22
+ });
23
+ }
24
+ function listResponse(data) {
25
+ return jsonResponse({
26
+ data: {
27
+ remoteComponents: {
28
+ listRemoteComponents: {
29
+ data,
30
+ error: null
31
+ }
32
+ }
33
+ }
34
+ });
35
+ }
36
+ function browserLikeFetch() {
37
+ if (this !== globalThis && void 0 !== this) throw new TypeError("Failed to execute 'fetch' on 'Window': Illegal invocation");
38
+ return Promise.resolve(listResponse([]));
39
+ }
40
+ afterEach(()=>{
41
+ vi.unstubAllGlobals();
42
+ });
43
+ describe("ComponentsSdk.loadComponents", ()=>{
44
+ describe("fetch receiver", ()=>{
45
+ it("calls the global fetch without the SDK instance as receiver", async ()=>{
46
+ vi.stubGlobal("fetch", browserLikeFetch);
47
+ const sdk = new ComponentsSdk({
48
+ endpoint: endpoint
49
+ });
50
+ const result = await sdk.loadComponents();
51
+ expect(result.isOk()).toBe(true);
52
+ expect(result.value).toEqual([]);
53
+ });
54
+ it("calls config.fetch without the SDK instance as receiver", async ()=>{
55
+ const sdk = new ComponentsSdk({
56
+ endpoint: endpoint,
57
+ fetch: browserLikeFetch
58
+ });
59
+ const result = await sdk.loadComponents();
60
+ expect(result.isOk()).toBe(true);
61
+ expect(result.value).toEqual([]);
62
+ });
63
+ });
64
+ describe("request and result", ()=>{
65
+ it("sends the same URL and init", async ()=>{
66
+ const fetchFn = vi.fn(async ()=>listResponse([
67
+ entry
68
+ ]));
69
+ const sdk = new ComponentsSdk({
70
+ endpoint: endpoint,
71
+ tenant: "acme",
72
+ token: "secret",
73
+ headers: {
74
+ "x-custom": "1"
75
+ },
76
+ fetch: fetchFn
77
+ });
78
+ await sdk.loadComponents({
79
+ fetchOptions: {
80
+ cache: "no-store",
81
+ method: "GET"
82
+ }
83
+ });
84
+ expect(fetchFn).toHaveBeenCalledTimes(1);
85
+ const [url, init] = fetchFn.mock.calls[0];
86
+ expect(url).toBe(`${endpoint}/graphql`);
87
+ expect(init).toEqual({
88
+ method: "POST",
89
+ cache: "no-store",
90
+ headers: {
91
+ "Content-Type": "application/json",
92
+ "x-tenant": "acme",
93
+ "x-custom": "1",
94
+ Authorization: "Bearer secret"
95
+ },
96
+ body: expect.stringContaining("listRemoteComponents")
97
+ });
98
+ expect(JSON.parse(init.body)).toEqual({
99
+ query: expect.any(String)
100
+ });
101
+ });
102
+ it("defaults the tenant and resolves a token function", async ()=>{
103
+ const fetchFn = vi.fn(async ()=>listResponse([]));
104
+ const sdk = new ComponentsSdk({
105
+ endpoint: endpoint,
106
+ token: async ()=>"from-fn",
107
+ fetch: fetchFn
108
+ });
109
+ await sdk.loadComponents();
110
+ const [, init] = fetchFn.mock.calls[0];
111
+ expect(init.method).toBe("POST");
112
+ expect(init.headers).toEqual({
113
+ "Content-Type": "application/json",
114
+ "x-tenant": "root",
115
+ Authorization: "Bearer from-fn"
116
+ });
117
+ });
118
+ it("returns the components on an OK response", async ()=>{
119
+ const sdk = new ComponentsSdk({
120
+ endpoint: endpoint,
121
+ fetch: vi.fn(async ()=>listResponse([
122
+ entry
123
+ ]))
124
+ });
125
+ const result = await sdk.loadComponents();
126
+ expect(result.isOk()).toBe(true);
127
+ expect(result.value).toEqual([
128
+ entry
129
+ ]);
130
+ });
131
+ it("returns an HttpError on a non-OK status", async ()=>{
132
+ const sdk = new ComponentsSdk({
133
+ endpoint: endpoint,
134
+ fetch: vi.fn(async ()=>jsonResponse({}, 503))
135
+ });
136
+ const result = await sdk.loadComponents();
137
+ expect(result.isFail()).toBe(true);
138
+ expect(result.error).toBeInstanceOf(HttpError);
139
+ expect(result.error.message).toBe("HTTP error! status: 503");
140
+ expect(result.error.data).toEqual({
141
+ status: 503
142
+ });
143
+ });
144
+ it("returns a NetworkError when fetch throws", async ()=>{
145
+ const sdk = new ComponentsSdk({
146
+ endpoint: endpoint,
147
+ fetch: vi.fn(async ()=>{
148
+ throw new Error("connection refused");
149
+ })
150
+ });
151
+ const result = await sdk.loadComponents();
152
+ expect(result.isFail()).toBe(true);
153
+ expect(result.error).toBeInstanceOf(NetworkError);
154
+ expect(result.error.message).toBe("connection refused");
155
+ });
156
+ it("returns an ApiError on a GraphQL errors response", async ()=>{
157
+ const sdk = new ComponentsSdk({
158
+ endpoint: endpoint,
159
+ fetch: vi.fn(async ()=>jsonResponse({
160
+ errors: [
161
+ {
162
+ message: "Not authorized"
163
+ }
164
+ ]
165
+ }))
166
+ });
167
+ const result = await sdk.loadComponents();
168
+ expect(result.isFail()).toBe(true);
169
+ expect(result.error).toBeInstanceOf(ApiError);
170
+ expect(result.error.message).toBe("Not authorized");
171
+ });
172
+ });
173
+ describe("fetchOptions", ()=>{
174
+ const sdkHeaders = {
175
+ "content-type": "application/json",
176
+ "x-tenant": "acme",
177
+ "x-custom": "1",
178
+ authorization: "Bearer secret"
179
+ };
180
+ function createSdk() {
181
+ const fetchFn = vi.fn(async ()=>listResponse([]));
182
+ const sdk = new ComponentsSdk({
183
+ endpoint: endpoint,
184
+ tenant: "acme",
185
+ token: "secret",
186
+ headers: {
187
+ "x-custom": "1"
188
+ },
189
+ fetch: fetchFn
190
+ });
191
+ return {
192
+ sdk,
193
+ fetchFn
194
+ };
195
+ }
196
+ function sentInit(fetchFn) {
197
+ const [, init] = fetchFn.mock.calls[0];
198
+ return init;
199
+ }
200
+ function sentHeaders(init) {
201
+ const headers = new Headers(init.headers);
202
+ return Object.fromEntries(headers.entries());
203
+ }
204
+ const callerHeaderForms = [
205
+ [
206
+ "a plain object",
207
+ {
208
+ "x-extra": "extra",
209
+ "x-tenant": "other",
210
+ Authorization: "Bearer caller",
211
+ "Content-Type": "text/plain"
212
+ }
213
+ ],
214
+ [
215
+ "a Headers instance",
216
+ new Headers({
217
+ "x-extra": "extra",
218
+ "x-tenant": "other",
219
+ Authorization: "Bearer caller",
220
+ "Content-Type": "text/plain"
221
+ })
222
+ ],
223
+ [
224
+ "an array of pairs",
225
+ [
226
+ [
227
+ "x-extra",
228
+ "extra"
229
+ ],
230
+ [
231
+ "x-tenant",
232
+ "other"
233
+ ],
234
+ [
235
+ "authorization",
236
+ "Bearer caller"
237
+ ],
238
+ [
239
+ "content-type",
240
+ "text/plain"
241
+ ]
242
+ ]
243
+ ]
244
+ ];
245
+ it.each(callerHeaderForms)("merges headers given as %s under the SDK's headers", async (_, callerHeaders)=>{
246
+ const { sdk, fetchFn } = createSdk();
247
+ await sdk.loadComponents({
248
+ fetchOptions: {
249
+ headers: callerHeaders
250
+ }
251
+ });
252
+ const init = sentInit(fetchFn);
253
+ expect(sentHeaders(init)).toEqual({
254
+ ...sdkHeaders,
255
+ "x-extra": "extra"
256
+ });
257
+ });
258
+ it("keeps the configured headers over the caller's headers", async ()=>{
259
+ const { sdk, fetchFn } = createSdk();
260
+ await sdk.loadComponents({
261
+ fetchOptions: {
262
+ headers: {
263
+ "X-Custom": "caller"
264
+ }
265
+ }
266
+ });
267
+ const init = sentInit(fetchFn);
268
+ expect(sentHeaders(init)).toEqual(sdkHeaders);
269
+ });
270
+ it("returns a NetworkError when the caller's headers are invalid", async ()=>{
271
+ const { sdk, fetchFn } = createSdk();
272
+ const result = await sdk.loadComponents({
273
+ fetchOptions: {
274
+ headers: {
275
+ "bad header": "1"
276
+ }
277
+ }
278
+ });
279
+ expect(result.isFail()).toBe(true);
280
+ expect(result.error).toBeInstanceOf(NetworkError);
281
+ expect(fetchFn).not.toHaveBeenCalled();
282
+ });
283
+ it("ignores method and body, and passes other fields through", async ()=>{
284
+ const { sdk, fetchFn } = createSdk();
285
+ const controller = new AbortController();
286
+ await sdk.loadComponents({
287
+ fetchOptions: {
288
+ method: "GET",
289
+ body: "caller body",
290
+ cache: "no-store",
291
+ credentials: "include",
292
+ signal: controller.signal,
293
+ next: {
294
+ revalidate: 60
295
+ }
296
+ }
297
+ });
298
+ const init = sentInit(fetchFn);
299
+ expect(init.method).toBe("POST");
300
+ expect(JSON.parse(init.body)).toEqual({
301
+ query: expect.stringContaining("listRemoteComponents")
302
+ });
303
+ expect(init.cache).toBe("no-store");
304
+ expect(init.credentials).toBe("include");
305
+ expect(init.signal).toBe(controller.signal);
306
+ expect(init.next).toEqual({
307
+ revalidate: 60
308
+ });
309
+ });
310
+ });
311
+ });
312
+
313
+ //# sourceMappingURL=ComponentsSdk.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ComponentsSdk.test.js","sources":["../src/ComponentsSdk.test.ts"],"sourcesContent":["import { describe, it, expect, vi, afterEach } from \"vitest\";\nimport { HttpError } from \"@webiny/sdk\";\nimport { ApiError } from \"@webiny/sdk\";\nimport { NetworkError } from \"@webiny/sdk\";\nimport { ComponentsSdk } from \"./ComponentsSdk.js\";\nimport type { RemoteComponentEntry } from \"./ComponentsSdk.js\";\n\nconst endpoint = \"https://api.example.com\";\n\nconst entry: RemoteComponentEntry = {\n id: \"c1\",\n name: \"acme/hero\",\n label: \"Hero\",\n bundledJs: \"\",\n bundledJsSha256: \"\",\n bundledCss: \"\",\n bundledCssSha256: \"\",\n sdkVersion: \"1\",\n status: \"published\"\n};\n\nfunction jsonResponse(body: unknown, status = 200): Response {\n return new Response(JSON.stringify(body), {\n status,\n headers: { \"Content-Type\": \"application/json\" }\n });\n}\n\nfunction listResponse(data: RemoteComponentEntry[]): Response {\n return jsonResponse({\n data: { remoteComponents: { listRemoteComponents: { data, error: null } } }\n });\n}\n\n// Behaves like a browser's `fetch`: only `globalThis` or `undefined` are accepted as the receiver.\nfunction browserLikeFetch(this: unknown): Promise<Response> {\n if (this !== globalThis && this !== undefined) {\n throw new TypeError(\"Failed to execute 'fetch' on 'Window': Illegal invocation\");\n }\n return Promise.resolve(listResponse([]));\n}\n\nafterEach(() => {\n vi.unstubAllGlobals();\n});\n\ndescribe(\"ComponentsSdk.loadComponents\", () => {\n describe(\"fetch receiver\", () => {\n it(\"calls the global fetch without the SDK instance as receiver\", async () => {\n vi.stubGlobal(\"fetch\", browserLikeFetch);\n const sdk = new ComponentsSdk({ endpoint });\n\n const result = await sdk.loadComponents();\n\n expect(result.isOk()).toBe(true);\n expect(result.value).toEqual([]);\n });\n\n it(\"calls config.fetch without the SDK instance as receiver\", async () => {\n const sdk = new ComponentsSdk({ endpoint, fetch: browserLikeFetch as typeof fetch });\n\n const result = await sdk.loadComponents();\n\n expect(result.isOk()).toBe(true);\n expect(result.value).toEqual([]);\n });\n });\n\n describe(\"request and result\", () => {\n it(\"sends the same URL and init\", async () => {\n const fetchFn = vi.fn(async () => listResponse([entry]));\n const sdk = new ComponentsSdk({\n endpoint,\n tenant: \"acme\",\n token: \"secret\",\n headers: { \"x-custom\": \"1\" },\n fetch: fetchFn\n });\n\n await sdk.loadComponents({\n fetchOptions: { cache: \"no-store\", method: \"GET\" }\n });\n\n expect(fetchFn).toHaveBeenCalledTimes(1);\n const [url, init] = fetchFn.mock.calls[0] as unknown as [string, RequestInit];\n expect(url).toBe(`${endpoint}/graphql`);\n expect(init).toEqual({\n // `fetchOptions` can't replace the GraphQL request's `method`.\n method: \"POST\",\n cache: \"no-store\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-tenant\": \"acme\",\n \"x-custom\": \"1\",\n Authorization: \"Bearer secret\"\n },\n body: expect.stringContaining(\"listRemoteComponents\")\n });\n expect(JSON.parse(init.body as string)).toEqual({ query: expect.any(String) });\n });\n\n it(\"defaults the tenant and resolves a token function\", async () => {\n const fetchFn = vi.fn(async () => listResponse([]));\n const sdk = new ComponentsSdk({\n endpoint,\n token: async () => \"from-fn\",\n fetch: fetchFn\n });\n\n await sdk.loadComponents();\n\n const [, init] = fetchFn.mock.calls[0] as unknown as [string, RequestInit];\n expect(init.method).toBe(\"POST\");\n expect(init.headers).toEqual({\n \"Content-Type\": \"application/json\",\n \"x-tenant\": \"root\",\n Authorization: \"Bearer from-fn\"\n });\n });\n\n it(\"returns the components on an OK response\", async () => {\n const sdk = new ComponentsSdk({\n endpoint,\n fetch: vi.fn(async () => listResponse([entry]))\n });\n\n const result = await sdk.loadComponents();\n\n expect(result.isOk()).toBe(true);\n expect(result.value).toEqual([entry]);\n });\n\n it(\"returns an HttpError on a non-OK status\", async () => {\n const sdk = new ComponentsSdk({\n endpoint,\n fetch: vi.fn(async () => jsonResponse({}, 503))\n });\n\n const result = await sdk.loadComponents();\n\n expect(result.isFail()).toBe(true);\n expect(result.error).toBeInstanceOf(HttpError);\n expect(result.error.message).toBe(\"HTTP error! status: 503\");\n expect(result.error.data).toEqual({ status: 503 });\n });\n\n it(\"returns a NetworkError when fetch throws\", async () => {\n const sdk = new ComponentsSdk({\n endpoint,\n fetch: vi.fn(async () => {\n throw new Error(\"connection refused\");\n })\n });\n\n const result = await sdk.loadComponents();\n\n expect(result.isFail()).toBe(true);\n expect(result.error).toBeInstanceOf(NetworkError);\n expect(result.error.message).toBe(\"connection refused\");\n });\n\n it(\"returns an ApiError on a GraphQL errors response\", async () => {\n const sdk = new ComponentsSdk({\n endpoint,\n fetch: vi.fn(async () => jsonResponse({ errors: [{ message: \"Not authorized\" }] }))\n });\n\n const result = await sdk.loadComponents();\n\n expect(result.isFail()).toBe(true);\n expect(result.error).toBeInstanceOf(ApiError);\n expect(result.error.message).toBe(\"Not authorized\");\n });\n });\n describe(\"fetchOptions\", () => {\n const sdkHeaders = {\n \"content-type\": \"application/json\",\n \"x-tenant\": \"acme\",\n \"x-custom\": \"1\",\n authorization: \"Bearer secret\"\n };\n\n function createSdk() {\n const fetchFn = vi.fn(async () => listResponse([]));\n const sdk = new ComponentsSdk({\n endpoint,\n tenant: \"acme\",\n token: \"secret\",\n headers: { \"x-custom\": \"1\" },\n fetch: fetchFn\n });\n return { sdk, fetchFn };\n }\n\n function sentInit(fetchFn: ReturnType<typeof createSdk>[\"fetchFn\"]): RequestInit {\n const [, init] = fetchFn.mock.calls[0] as unknown as [string, RequestInit];\n return init;\n }\n\n function sentHeaders(init: RequestInit): Record<string, string> {\n const headers = new Headers(init.headers);\n return Object.fromEntries(headers.entries());\n }\n\n const callerHeaderForms: Array<[string, HeadersInit]> = [\n [\n \"a plain object\",\n {\n \"x-extra\": \"extra\",\n \"x-tenant\": \"other\",\n Authorization: \"Bearer caller\",\n \"Content-Type\": \"text/plain\"\n }\n ],\n [\n \"a Headers instance\",\n new Headers({\n \"x-extra\": \"extra\",\n \"x-tenant\": \"other\",\n Authorization: \"Bearer caller\",\n \"Content-Type\": \"text/plain\"\n })\n ],\n [\n \"an array of pairs\",\n [\n [\"x-extra\", \"extra\"],\n [\"x-tenant\", \"other\"],\n [\"authorization\", \"Bearer caller\"],\n [\"content-type\", \"text/plain\"]\n ]\n ]\n ];\n\n it.each(callerHeaderForms)(\n \"merges headers given as %s under the SDK's headers\",\n async (_, callerHeaders) => {\n const { sdk, fetchFn } = createSdk();\n\n await sdk.loadComponents({ fetchOptions: { headers: callerHeaders } });\n\n const init = sentInit(fetchFn);\n expect(sentHeaders(init)).toEqual({ ...sdkHeaders, \"x-extra\": \"extra\" });\n }\n );\n\n it(\"keeps the configured headers over the caller's headers\", async () => {\n const { sdk, fetchFn } = createSdk();\n\n await sdk.loadComponents({ fetchOptions: { headers: { \"X-Custom\": \"caller\" } } });\n\n const init = sentInit(fetchFn);\n expect(sentHeaders(init)).toEqual(sdkHeaders);\n });\n\n it(\"returns a NetworkError when the caller's headers are invalid\", async () => {\n const { sdk, fetchFn } = createSdk();\n\n const result = await sdk.loadComponents({\n fetchOptions: { headers: { \"bad header\": \"1\" } }\n });\n\n expect(result.isFail()).toBe(true);\n expect(result.error).toBeInstanceOf(NetworkError);\n expect(fetchFn).not.toHaveBeenCalled();\n });\n\n it(\"ignores method and body, and passes other fields through\", async () => {\n const { sdk, fetchFn } = createSdk();\n const controller = new AbortController();\n\n await sdk.loadComponents({\n fetchOptions: {\n method: \"GET\",\n body: \"caller body\",\n cache: \"no-store\",\n credentials: \"include\",\n signal: controller.signal,\n next: { revalidate: 60 }\n } as RequestInit\n });\n\n const init = sentInit(fetchFn) as RequestInit & { next?: unknown };\n expect(init.method).toBe(\"POST\");\n expect(JSON.parse(init.body as string)).toEqual({\n query: expect.stringContaining(\"listRemoteComponents\")\n });\n expect(init.cache).toBe(\"no-store\");\n expect(init.credentials).toBe(\"include\");\n expect(init.signal).toBe(controller.signal);\n expect(init.next).toEqual({ revalidate: 60 });\n });\n });\n});\n"],"names":["endpoint","entry","jsonResponse","body","status","Response","JSON","listResponse","data","browserLikeFetch","globalThis","undefined","TypeError","Promise","afterEach","vi","describe","it","sdk","ComponentsSdk","result","expect","fetchFn","url","init","String","HttpError","Error","NetworkError","ApiError","sdkHeaders","createSdk","sentInit","sentHeaders","headers","Headers","Object","callerHeaderForms","_","callerHeaders","controller","AbortController"],"mappings":";;;AAOA,MAAMA,WAAW;AAEjB,MAAMC,QAA8B;IAChC,IAAI;IACJ,MAAM;IACN,OAAO;IACP,WAAW;IACX,iBAAiB;IACjB,YAAY;IACZ,kBAAkB;IAClB,YAAY;IACZ,QAAQ;AACZ;AAEA,SAASC,aAAaC,IAAa,EAAEC,SAAS,GAAG;IAC7C,OAAO,IAAIC,SAASC,KAAK,SAAS,CAACH,OAAO;QACtCC;QACA,SAAS;YAAE,gBAAgB;QAAmB;IAClD;AACJ;AAEA,SAASG,aAAaC,IAA4B;IAC9C,OAAON,aAAa;QAChB,MAAM;YAAE,kBAAkB;gBAAE,sBAAsB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B,MAAMX,SAAS,MAAMF,IAAI,cAAc,CAAC;gBACpC,cAAc;oBAAE,SAAS;wBAAE,cAAc;oBAAI;gBAAE;YACnD;YAEAG,OAAOD,OAAO,MAAM,IAAI,IAAI,CAAC;YAC7BC,OAAOD,OAAO,KAAK,EAAE,cAAc,CAACQ;YACpCP,OAAOC,SAAS,GAAG,CAAC,gBAAgB;QACxC;QAEAL,GAAG,4DAA4D;YAC3D,MAAM,EAAEC,GAAG,EAAEI,OAAO,EAAE,GAAGS;YACzB,MAAMS,aAAa,IAAIC;YAEvB,MAAMvB,IAAI,cAAc,CAAC;gBACrB,cAAc;oBACV,QAAQ;oBACR,MAAM;oBACN,OAAO;oBACP,aAAa;oBACb,QAAQsB,WAAW,MAAM;oBACzB,MAAM;wBAAE,YAAY;oBAAG;gBAC3B;YACJ;YAEA,MAAMhB,OAAOQ,SAASV;YACtBD,OAAOG,KAAK,MAAM,EAAE,IAAI,CAAC;YACzBH,OAAOf,KAAK,KAAK,CAACkB,KAAK,IAAI,GAAa,OAAO,CAAC;gBAC5C,OAAOH,OAAO,gBAAgB,CAAC;YACnC;YACAA,OAAOG,KAAK,KAAK,EAAE,IAAI,CAAC;YACxBH,OAAOG,KAAK,WAAW,EAAE,IAAI,CAAC;YAC9BH,OAAOG,KAAK,MAAM,EAAE,IAAI,CAACgB,WAAW,MAAM;YAC1CnB,OAAOG,KAAK,IAAI,EAAE,OAAO,CAAC;gBAAE,YAAY;YAAG;QAC/C;IACJ;AACJ"}
@@ -0,0 +1,22 @@
1
+ import type { LanguagesSdk, FileManagerSdk, TenantManagerSdk, TasksSdk, WebhooksSdk } from "@webiny/sdk";
2
+ import { CmsSdk } from "./CmsSdk.js";
3
+ import { WbSdk } from "./WbSdk.js";
4
+ import { ComponentsSdk } from "./ComponentsSdk.js";
5
+ import type { ContentSdkConfig } from "./types.js";
6
+ export declare class FrontendSdk {
7
+ private sdk?;
8
+ private get initialized();
9
+ get cms(): CmsSdk;
10
+ get wb(): WbSdk;
11
+ get languages(): LanguagesSdk;
12
+ get fileManager(): FileManagerSdk;
13
+ get tenantManager(): TenantManagerSdk;
14
+ get tasks(): TasksSdk;
15
+ get webhooks(): WebhooksSdk;
16
+ get components(): ComponentsSdk;
17
+ init(config: ContentSdkConfig): void;
18
+ isEditing(): boolean;
19
+ isServer(): boolean;
20
+ isClient(): boolean;
21
+ }
22
+ export declare const sdk: FrontendSdk;
package/FrontendSdk.js ADDED
@@ -0,0 +1,86 @@
1
+ import { Webiny } from "@webiny/sdk";
2
+ import { contentSdk, environment } from "@webiny/cms-sdk";
3
+ import { contentSdk as website_builder_sdk_contentSdk } from "@webiny/website-builder-sdk";
4
+ import { ensureContentEntryLoader } from "./resolveContentEntries.js";
5
+ import { CmsSdk } from "./CmsSdk.js";
6
+ import { WbSdk } from "./WbSdk.js";
7
+ import { ComponentsSdk } from "./ComponentsSdk.js";
8
+ class FrontendSdk {
9
+ get initialized() {
10
+ if (!this.sdk) throw new Error("SDK is not initialized. Call sdk.init() first.");
11
+ return this.sdk;
12
+ }
13
+ get cms() {
14
+ return this.initialized.cms;
15
+ }
16
+ get wb() {
17
+ return this.initialized.wb;
18
+ }
19
+ get languages() {
20
+ return this.initialized.webiny.languages;
21
+ }
22
+ get fileManager() {
23
+ return this.initialized.webiny.fileManager;
24
+ }
25
+ get tenantManager() {
26
+ return this.initialized.webiny.tenantManager;
27
+ }
28
+ get tasks() {
29
+ return this.initialized.webiny.tasks;
30
+ }
31
+ get webhooks() {
32
+ return this.initialized.webiny.webhooks;
33
+ }
34
+ get components() {
35
+ return this.initialized.components;
36
+ }
37
+ init(config) {
38
+ const webiny = new Webiny({
39
+ endpoint: config.endpoint,
40
+ token: config.token,
41
+ tenant: config.tenant || "root",
42
+ fetch: config.fetch
43
+ });
44
+ this.sdk = {
45
+ webiny,
46
+ cms: new CmsSdk(webiny),
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
+ })
54
+ };
55
+ contentSdk.init({
56
+ apiHost: config.endpoint,
57
+ apiKey: config.token,
58
+ apiTenant: config.tenant,
59
+ preview: config.preview,
60
+ fetch: config.fetch
61
+ }, webiny);
62
+ website_builder_sdk_contentSdk.init({
63
+ apiHost: config.endpoint,
64
+ apiKey: config.token,
65
+ apiTenant: config.tenant ?? "root",
66
+ preview: config.preview,
67
+ theme: config.wb?.theme,
68
+ previewParams: config.wb?.previewParams
69
+ });
70
+ if (config.wb?.componentGroups) for (const group of config.wb.componentGroups)this.sdk.wb.registerComponentGroup(group);
71
+ ensureContentEntryLoader();
72
+ }
73
+ isEditing() {
74
+ return environment.isEditing();
75
+ }
76
+ isServer() {
77
+ return environment.isServer();
78
+ }
79
+ isClient() {
80
+ return environment.isClient();
81
+ }
82
+ }
83
+ const sdk = new FrontendSdk();
84
+ export { FrontendSdk, sdk };
85
+
86
+ //# sourceMappingURL=FrontendSdk.js.map
@@ -0,0 +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 { 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","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O,KAAK;YACvB;QACJ;QAEAM,WAAAA,IAAkB,CACd;YACI,SAASN,OAAO,QAAQ;YACxB,QAAQA,OAAO,KAAK;YACpB,WAAWA,OAAO,MAAM;YACxB,SAASA,OAAO,OAAO;YACvB,OAAOA,OAAO,KAAK;QACvB,GACAC;QAGJM,+BAAAA,IAAiB,CAAC;YACd,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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Webiny
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # @webiny/sdk-frontend
2
+
3
+ > [!NOTE]
4
+ > This package is part of the [Webiny](https://www.webiny.com) monorepo.
5
+ > It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
6
+
7
+ 📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
8
+
9
+ ---
10
+
11
+ _This README file is automatically generated during the publish process._
package/WbSdk.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { Result } from "@webiny/sdk";
2
+ import type { GetLayoutParams, PublicLayout, PublicPage, PublicRedirect, ListPagesOptions, ListPagesResult, Component as WbComponent, ComponentGroup } from "@webiny/website-builder-sdk";
3
+ export declare class WbSdk {
4
+ getPage(path: string): Promise<Result<PublicPage, Error>>;
5
+ /**
6
+ * The published layout with the slug, in its version in `language` (or else the source layout), composed
7
+ * with that language's global components. `null` when no such layout is published.
8
+ */
9
+ getLayout(params: GetLayoutParams): Promise<Result<PublicLayout | null, Error>>;
10
+ listPages(options?: ListPagesOptions): Promise<Result<ListPagesResult, Error>>;
11
+ getAllRedirects(): Promise<Result<Map<string, PublicRedirect>, Error>>;
12
+ getRedirectByPath(path: string): Promise<Result<PublicRedirect | undefined, Error>>;
13
+ registerComponent(blueprint: WbComponent): void;
14
+ registerComponentGroup(group: ComponentGroup): void;
15
+ isPreviewing(): boolean;
16
+ }
package/WbSdk.js ADDED
@@ -0,0 +1,35 @@
1
+ import { Result } from "@webiny/sdk";
2
+ import { contentSdk, registerComponentGroup } from "@webiny/website-builder-sdk";
3
+ import { resolveContentEntries } from "./resolveContentEntries.js";
4
+ class WbSdk {
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);
10
+ }
11
+ getLayout(params) {
12
+ return contentSdk.getLayout(params).then((layout)=>Result.ok(layout));
13
+ }
14
+ listPages(options) {
15
+ return contentSdk.listPages(options).then((result)=>Result.ok(result));
16
+ }
17
+ getAllRedirects() {
18
+ return contentSdk.getAllRedirects().then((redirects)=>Result.ok(redirects));
19
+ }
20
+ getRedirectByPath(path) {
21
+ return contentSdk.getRedirectByPath(path).then((redirect)=>Result.ok(redirect));
22
+ }
23
+ registerComponent(blueprint) {
24
+ contentSdk.registerComponent(blueprint);
25
+ }
26
+ registerComponentGroup(group) {
27
+ registerComponentGroup(group);
28
+ }
29
+ isPreviewing() {
30
+ return contentSdk.isPreviewing();
31
+ }
32
+ }
33
+ export { WbSdk };
34
+
35
+ //# sourceMappingURL=WbSdk.js.map
package/WbSdk.js.map ADDED
@@ -0,0 +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 GetLayoutParams,\n PublicLayout,\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 /**\n * The published layout with the slug, in its version in `language` (or else the source layout), composed\n * with that language's global components. `null` when no such layout is published.\n */\n getLayout(params: GetLayoutParams): Promise<Result<PublicLayout | null, Error>> {\n return wbContentSdk.getLayout(params).then(layout => Result.ok(layout));\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","params","layout","options","result","redirects","redirect","blueprint","group","registerComponentGroup"],"mappings":";;;AAcO,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;IAMA,UAAUK,MAAuB,EAA+C;QAC5E,OAAOJ,WAAAA,SAAsB,CAACI,QAAQ,IAAI,CAACC,CAAAA,SAAUJ,OAAO,EAAE,CAACI;IACnE;IAEA,UAAUC,OAA0B,EAA2C;QAC3E,OAAON,WAAAA,SAAsB,CAACM,SAAS,IAAI,CAACC,CAAAA,SAAUN,OAAO,EAAE,CAACM;IACpE;IAEA,kBAAuE;QACnE,OAAOP,WAAAA,eAA4B,GAAG,IAAI,CAACQ,CAAAA,YAAaP,OAAO,EAAE,CAACO;IACtE;IAEA,kBAAkBV,IAAY,EAAsD;QAChF,OAAOE,WAAAA,iBAA8B,CAACF,MAAM,IAAI,CAACW,CAAAA,WAAYR,OAAO,EAAE,CAACQ;IAC3E;IAEA,kBAAkBC,SAAsB,EAAQ;QAC5CV,WAAAA,iBAA8B,CAACU;IACnC;IAEA,uBAAuBC,KAAqB,EAAQ;QAChDC,uBAAuBD;IAC3B;IAEA,eAAwB;QACpB,OAAOX,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 ADDED
@@ -0,0 +1,15 @@
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";
7
+ export type { ContentSdkConfig, WbConfig, CmsConfig } from "./types.js";
8
+ export type { GetLayoutForModelParams } from "./CmsSdk.js";
9
+ export { Result, HttpError, ApiError, NetworkError, ValidationError } from "@webiny/sdk";
10
+ export type { Language } from "@webiny/sdk";
11
+ export type { CmsEntryData, CreateEntryParams, CreateCmsEntryData, UpdateEntryRevisionParams, UpdateCmsEntryData, DeleteEntryRevisionParams, PublishEntryRevisionParams, UnpublishEntryRevisionParams } from "@webiny/sdk";
12
+ export { createComponent as createCmsComponent, resolveRefs } from "@webiny/cms-sdk";
13
+ export type { CmsSdkConfig, CmsEntryValues, CmsEntry, CmsListMeta, CmsListResult, GetEntryParams, ListEntriesParams, CmsModelDefinition, CmsModelMetadata, CmsRefModelMetadata, Asset, AssetImage, AssetCrop, AssetFocalPoint, AssetDocument, AssetVideo } from "@webiny/cms-sdk";
14
+ export type { PublicPage, PublicLayout, GetLayoutParams, PublicRedirect, ListPagesOptions, ListPagesResult, ComponentGroup, WebsiteBuilderThemeInput, ComponentManifest, ComponentInput } from "@webiny/website-builder-sdk";
15
+ export { createTheme, createComponent as createWbComponent } from "@webiny/website-builder-sdk";
package/index.js ADDED
@@ -0,0 +1,7 @@
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";
5
+ export { ApiError, HttpError, NetworkError, Result, ValidationError } from "@webiny/sdk";
6
+ export { createComponent as createCmsComponent, resolveRefs } from "@webiny/cms-sdk";
7
+ export { createComponent as createWbComponent, createTheme } from "@webiny/website-builder-sdk";
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@webiny/sdk-frontend",
3
+ "version": "0.0.0-unstable.0156a4c312",
4
+ "type": "module",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/webiny/webiny-js.git"
8
+ },
9
+ "exports": {
10
+ ".": "./index.js",
11
+ "./*": "./*"
12
+ },
13
+ "description": "Unified content SDK for Webiny CMS and Website Builder.",
14
+ "contributors": [
15
+ "Pavel Denisjuk <pavel@webiny.com>"
16
+ ],
17
+ "license": "MIT",
18
+ "dependencies": {
19
+ "@webiny/cms-sdk": "0.0.0-unstable.0156a4c312",
20
+ "@webiny/sdk": "0.0.0-unstable.0156a4c312",
21
+ "@webiny/website-builder-sdk": "0.0.0-unstable.0156a4c312",
22
+ "css-tree": "3.2.1"
23
+ },
24
+ "devDependencies": {
25
+ "@webiny/build-tools": "0.0.0-unstable.0156a4c312",
26
+ "typescript": "7.0.2",
27
+ "vitest": "5.0.5"
28
+ },
29
+ "webiny": {
30
+ "publishFrom": "dist"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ }
35
+ }