@webiny/website-builder-sdk 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.
- package/BindingsApi.d.ts +25 -0
- package/BindingsApi.js +35 -0
- package/BindingsApi.js.map +1 -0
- package/BindingsProcessor.d.ts +11 -0
- package/BindingsProcessor.js +40 -0
- package/BindingsProcessor.js.map +1 -0
- package/BindingsProcessor.test.d.ts +1 -0
- package/BindingsProcessor.test.js +91 -0
- package/BindingsProcessor.test.js.map +1 -0
- package/BindingsResolver.d.ts +23 -0
- package/BindingsResolver.js +104 -0
- package/BindingsResolver.js.map +1 -0
- package/BindingsResolver.test.d.ts +1 -0
- package/BindingsResolver.test.js +419 -0
- package/BindingsResolver.test.js.map +1 -0
- package/ComponentInputTraverser.d.ts +18 -0
- package/ComponentInputTraverser.js +39 -0
- package/ComponentInputTraverser.js.map +1 -0
- package/ComponentManifestToAstConverter.d.ts +13 -0
- package/ComponentManifestToAstConverter.js +23 -0
- package/ComponentManifestToAstConverter.js.map +1 -0
- package/ComponentRegistry.d.ts +16 -0
- package/ComponentRegistry.js +43 -0
- package/ComponentRegistry.js.map +1 -0
- package/ComponentResolver.d.ts +17 -0
- package/ComponentResolver.js +37 -0
- package/ComponentResolver.js.map +1 -0
- package/ConstraintEvaluator.d.ts +36 -0
- package/ConstraintEvaluator.js +302 -0
- package/ConstraintEvaluator.js.map +1 -0
- package/ConstraintEvaluator.test.d.ts +1 -0
- package/ConstraintEvaluator.test.js +1738 -0
- package/ConstraintEvaluator.test.js.map +1 -0
- package/ContentSdk.d.ts +118 -0
- package/ContentSdk.js +194 -0
- package/ContentSdk.js.map +1 -0
- package/DocumentStore.d.ts +15 -0
- package/DocumentStore.js +55 -0
- package/DocumentStore.js.map +1 -0
- package/DocumentStoreManager.d.ts +18 -0
- package/DocumentStoreManager.js +42 -0
- package/DocumentStoreManager.js.map +1 -0
- package/EditingSdk.d.ts +37 -0
- package/EditingSdk.js +131 -0
- package/EditingSdk.js.map +1 -0
- package/ElementBindings.d.ts +28 -0
- package/ElementBindings.js +88 -0
- package/ElementBindings.js.map +1 -0
- package/ElementBindings.test.d.ts +1 -0
- package/ElementBindings.test.js +127 -0
- package/ElementBindings.test.js.map +1 -0
- package/ElementFactory.d.ts +62 -0
- package/ElementFactory.js +179 -0
- package/ElementFactory.js.map +1 -0
- package/ElementFactory.test.d.ts +1 -0
- package/ElementFactory.test.js +353 -0
- package/ElementFactory.test.js.map +1 -0
- package/ElementSelection.d.ts +20 -0
- package/ElementSelection.js +32 -0
- package/ElementSelection.js.map +1 -0
- package/ElementSelection.test.d.ts +1 -0
- package/ElementSelection.test.js +73 -0
- package/ElementSelection.test.js.map +1 -0
- package/Environment.d.ts +13 -0
- package/Environment.js +23 -0
- package/Environment.js.map +1 -0
- package/Environment.test.d.ts +1 -0
- package/Environment.test.js +35 -0
- package/Environment.test.js.map +1 -0
- package/FunctionConverter.d.ts +6 -0
- package/FunctionConverter.js +12 -0
- package/FunctionConverter.js.map +1 -0
- package/GlobalComponentLanguage.d.ts +31 -0
- package/GlobalComponentLanguage.js +37 -0
- package/GlobalComponentLanguage.js.map +1 -0
- package/HashObject.d.ts +6 -0
- package/HashObject.js +16 -0
- package/HashObject.js.map +1 -0
- package/HotkeyManager.d.ts +6 -0
- package/HotkeyManager.js +51 -0
- package/HotkeyManager.js.map +1 -0
- package/IBindingsUpdater.d.ts +6 -0
- package/IBindingsUpdater.js +0 -0
- package/IRedirects.d.ts +5 -0
- package/IRedirects.js +0 -0
- package/InheritanceProcessor.d.ts +29 -0
- package/InheritanceProcessor.js +107 -0
- package/InheritanceProcessor.js.map +1 -0
- package/InheritanceProcessor.test.d.ts +1 -0
- package/InheritanceProcessor.test.js +192 -0
- package/InheritanceProcessor.test.js.map +1 -0
- package/InheritedValueResolver.d.ts +10 -0
- package/InheritedValueResolver.js +19 -0
- package/InheritedValueResolver.js.map +1 -0
- package/InputBindingsProcessor.d.ts +38 -0
- package/InputBindingsProcessor.js +204 -0
- package/InputBindingsProcessor.js.map +1 -0
- package/InputsBindingsProcessor.test.d.ts +1 -0
- package/InputsBindingsProcessor.test.js +359 -0
- package/InputsBindingsProcessor.test.js.map +1 -0
- package/InputsUpdater.d.ts +12 -0
- package/InputsUpdater.js +32 -0
- package/InputsUpdater.js.map +1 -0
- package/LICENSE +21 -0
- package/LayoutContentArea.d.ts +68 -0
- package/LayoutContentArea.js +78 -0
- package/LayoutContentArea.js.map +1 -0
- package/LayoutContentArea.test.d.ts +1 -0
- package/LayoutContentArea.test.js +111 -0
- package/LayoutContentArea.test.js.map +1 -0
- package/LiveSdk.d.ts +10 -0
- package/LiveSdk.js +21 -0
- package/LiveSdk.js.map +1 -0
- package/Logger.d.ts +2 -0
- package/Logger.js +14 -0
- package/Logger.js.map +1 -0
- package/MouseTracker.d.ts +39 -0
- package/MouseTracker.js +87 -0
- package/MouseTracker.js.map +1 -0
- package/NullSdk.d.ts +10 -0
- package/NullSdk.js +28 -0
- package/NullSdk.js.map +1 -0
- package/PreviewDocument.d.ts +10 -0
- package/PreviewDocument.js +35 -0
- package/PreviewDocument.js.map +1 -0
- package/PreviewSdk.d.ts +12 -0
- package/PreviewSdk.js +28 -0
- package/PreviewSdk.js.map +1 -0
- package/PreviewViewport.d.ts +13 -0
- package/PreviewViewport.js +65 -0
- package/PreviewViewport.js.map +1 -0
- package/PreviewViewport.test.d.ts +1 -0
- package/PreviewViewport.test.js +27 -0
- package/PreviewViewport.test.js.map +1 -0
- package/README.md +11 -0
- package/ResizeObserver.d.ts +5 -0
- package/ResizeObserver.js +34 -0
- package/ResizeObserver.js.map +1 -0
- package/StylesBindingsProcessor.d.ts +33 -0
- package/StylesBindingsProcessor.js +53 -0
- package/StylesBindingsProcessor.js.map +1 -0
- package/StylesUpdater.d.ts +10 -0
- package/StylesUpdater.js +32 -0
- package/StylesUpdater.js.map +1 -0
- package/Theme.d.ts +4 -0
- package/Theme.js +34 -0
- package/Theme.js.map +1 -0
- package/ViewportManager.d.ts +36 -0
- package/ViewportManager.js +98 -0
- package/ViewportManager.js.map +1 -0
- package/asset/deliveryUrl.d.ts +41 -0
- package/asset/deliveryUrl.js +34 -0
- package/asset/deliveryUrl.js.map +1 -0
- package/asset/deliveryUrl.test.d.ts +1 -0
- package/asset/deliveryUrl.test.js +127 -0
- package/asset/deliveryUrl.test.js.map +1 -0
- package/asset/geometry.d.ts +7 -0
- package/asset/geometry.js +10 -0
- package/asset/geometry.js.map +1 -0
- package/asset/imageSrcSet.d.ts +63 -0
- package/asset/imageSrcSet.js +98 -0
- package/asset/imageSrcSet.js.map +1 -0
- package/asset/imageSrcSet.test.d.ts +1 -0
- package/asset/imageSrcSet.test.js +103 -0
- package/asset/imageSrcSet.test.js.map +1 -0
- package/asset/index.d.ts +5 -0
- package/asset/index.js +5 -0
- package/asset/normalize.d.ts +24 -0
- package/asset/normalize.js +106 -0
- package/asset/normalize.js.map +1 -0
- package/asset/normalize.test.d.ts +1 -0
- package/asset/normalize.test.js +263 -0
- package/asset/normalize.test.js.map +1 -0
- package/asset/types.d.ts +2 -0
- package/asset/types.js +0 -0
- package/componentLoader/ComponentLoader.d.ts +16 -0
- package/componentLoader/ComponentLoader.js +0 -0
- package/componentLoader/RegistryOnlyComponentLoader.d.ts +9 -0
- package/componentLoader/RegistryOnlyComponentLoader.js +8 -0
- package/componentLoader/RegistryOnlyComponentLoader.js.map +1 -0
- package/componentLoader/createComponentLoader.d.ts +7 -0
- package/componentLoader/createComponentLoader.js +10 -0
- package/componentLoader/createComponentLoader.js.map +1 -0
- package/componentLoader/defaultComponentLoader.d.ts +7 -0
- package/componentLoader/defaultComponentLoader.js +8 -0
- package/componentLoader/defaultComponentLoader.js.map +1 -0
- package/componentLoader/index.d.ts +3 -0
- package/componentLoader/index.js +3 -0
- package/constants.d.ts +7 -0
- package/constants.js +10 -0
- package/constants.js.map +1 -0
- package/contentClientState.test.d.ts +1 -0
- package/contentClientState.test.js +384 -0
- package/contentClientState.test.js.map +1 -0
- package/contentEntry/ContentEntryBindingsResolver.d.ts +33 -0
- package/contentEntry/ContentEntryBindingsResolver.js +52 -0
- package/contentEntry/ContentEntryBindingsResolver.js.map +1 -0
- package/contentEntry/ContentEntryCache.d.ts +49 -0
- package/contentEntry/ContentEntryCache.js +51 -0
- package/contentEntry/ContentEntryCache.js.map +1 -0
- package/contentEntry/resolveContentEntry.d.ts +74 -0
- package/contentEntry/resolveContentEntry.js +53 -0
- package/contentEntry/resolveContentEntry.js.map +1 -0
- package/contentEntry/resolveContentEntry.test.d.ts +1 -0
- package/contentEntry/resolveContentEntry.test.js +213 -0
- package/contentEntry/resolveContentEntry.test.js.map +1 -0
- package/createComponent.d.ts +5 -0
- package/createComponent.js +32 -0
- package/createComponent.js.map +1 -0
- package/createContentClient.d.ts +17 -0
- package/createContentClient.js +16 -0
- package/createContentClient.js.map +1 -0
- package/createContentClient.test.d.ts +1 -0
- package/createContentClient.test.js +165 -0
- package/createContentClient.test.js.map +1 -0
- package/createElement.d.ts +10 -0
- package/createElement.js +7 -0
- package/createElement.js.map +1 -0
- package/createGlobalElementDocument.d.ts +6 -0
- package/createGlobalElementDocument.js +23 -0
- package/createGlobalElementDocument.js.map +1 -0
- package/createInput.d.ts +133 -0
- package/createInput.js +109 -0
- package/createInput.js.map +1 -0
- package/createTheme.d.ts +3 -0
- package/createTheme.js +4 -0
- package/createTheme.js.map +1 -0
- package/dataProviders/ApiClient.d.ts +23 -0
- package/dataProviders/ApiClient.js +45 -0
- package/dataProviders/ApiClient.js.map +1 -0
- package/dataProviders/DefaultDataProvider.d.ts +19 -0
- package/dataProviders/DefaultDataProvider.js +110 -0
- package/dataProviders/DefaultDataProvider.js.map +1 -0
- package/dataProviders/DefaultDataProvider.test.d.ts +1 -0
- package/dataProviders/DefaultDataProvider.test.js +81 -0
- package/dataProviders/DefaultDataProvider.test.js.map +1 -0
- package/dataProviders/GET_EXPERIMENT_PAUSED.d.ts +1 -0
- package/dataProviders/GET_EXPERIMENT_PAUSED.js +17 -0
- package/dataProviders/GET_EXPERIMENT_PAUSED.js.map +1 -0
- package/dataProviders/GET_LAYOUT_BY_SLUG.d.ts +1 -0
- package/dataProviders/GET_LAYOUT_BY_SLUG.js +27 -0
- package/dataProviders/GET_LAYOUT_BY_SLUG.js.map +1 -0
- package/dataProviders/GET_PAGE_BY_ID.d.ts +1 -0
- package/dataProviders/GET_PAGE_BY_ID.js +31 -0
- package/dataProviders/GET_PAGE_BY_ID.js.map +1 -0
- package/dataProviders/GET_PAGE_BY_PATH.d.ts +1 -0
- package/dataProviders/GET_PAGE_BY_PATH.js +31 -0
- package/dataProviders/GET_PAGE_BY_PATH.js.map +1 -0
- package/dataProviders/GET_PAGE_EXPERIMENT.d.ts +1 -0
- package/dataProviders/GET_PAGE_EXPERIMENT.js +32 -0
- package/dataProviders/GET_PAGE_EXPERIMENT.js.map +1 -0
- package/dataProviders/GET_VARIANT_CONTENT.d.ts +1 -0
- package/dataProviders/GET_VARIANT_CONTENT.js +24 -0
- package/dataProviders/GET_VARIANT_CONTENT.js.map +1 -0
- package/dataProviders/LIST_PUBLISHED_PAGES.d.ts +1 -0
- package/dataProviders/LIST_PUBLISHED_PAGES.js +33 -0
- package/dataProviders/LIST_PUBLISHED_PAGES.js.map +1 -0
- package/dataProviders/NullDataProvider.d.ts +20 -0
- package/dataProviders/NullDataProvider.js +36 -0
- package/dataProviders/NullDataProvider.js.map +1 -0
- package/dataProviders/RedirectsProvider.d.ts +11 -0
- package/dataProviders/RedirectsProvider.js +29 -0
- package/dataProviders/RedirectsProvider.js.map +1 -0
- package/dataProviders/queries.test.d.ts +1 -0
- package/dataProviders/queries.test.js +53 -0
- package/dataProviders/queries.test.js.map +1 -0
- package/defaultBreakpoints.d.ts +2 -0
- package/defaultBreakpoints.js +46 -0
- package/defaultBreakpoints.js.map +1 -0
- package/documentOperations/$addElementReferenceToParent.d.ts +9 -0
- package/documentOperations/$addElementReferenceToParent.js +35 -0
- package/documentOperations/$addElementReferenceToParent.js.map +1 -0
- package/documentOperations/AddElement.d.ts +7 -0
- package/documentOperations/AddElement.js +11 -0
- package/documentOperations/AddElement.js.map +1 -0
- package/documentOperations/AddToParent.d.ts +8 -0
- package/documentOperations/AddToParent.js +18 -0
- package/documentOperations/AddToParent.js.map +1 -0
- package/documentOperations/IDocumentOperation.d.ts +4 -0
- package/documentOperations/IDocumentOperation.js +0 -0
- package/documentOperations/RemoveElement.d.ts +7 -0
- package/documentOperations/RemoveElement.js +13 -0
- package/documentOperations/RemoveElement.js.map +1 -0
- package/documentOperations/SetGlobalInputBinding.d.ts +9 -0
- package/documentOperations/SetGlobalInputBinding.js +26 -0
- package/documentOperations/SetGlobalInputBinding.js.map +1 -0
- package/documentOperations/SetGlobalStyleBinding.d.ts +9 -0
- package/documentOperations/SetGlobalStyleBinding.js +26 -0
- package/documentOperations/SetGlobalStyleBinding.js.map +1 -0
- package/documentOperations/SetInputBindingOverride.d.ts +10 -0
- package/documentOperations/SetInputBindingOverride.js +34 -0
- package/documentOperations/SetInputBindingOverride.js.map +1 -0
- package/documentOperations/SetStyleBindingOverride.d.ts +10 -0
- package/documentOperations/SetStyleBindingOverride.js +34 -0
- package/documentOperations/SetStyleBindingOverride.js.map +1 -0
- package/documentOperations/index.d.ts +17 -0
- package/documentOperations/index.js +19 -0
- package/documentOperations/index.js.map +1 -0
- package/experiments/PostHogAnalyticsProvider.d.ts +31 -0
- package/experiments/PostHogAnalyticsProvider.js +28 -0
- package/experiments/PostHogAnalyticsProvider.js.map +1 -0
- package/experiments/analyticsProvider.d.ts +4 -0
- package/experiments/analyticsProvider.js +11 -0
- package/experiments/analyticsProvider.js.map +1 -0
- package/experiments/bucketing.d.ts +27 -0
- package/experiments/bucketing.js +91 -0
- package/experiments/bucketing.js.map +1 -0
- package/experiments/bucketing.test.d.ts +1 -0
- package/experiments/bucketing.test.js +183 -0
- package/experiments/bucketing.test.js.map +1 -0
- package/experiments/index.d.ts +5 -0
- package/experiments/index.js +5 -0
- package/experiments/render.d.ts +82 -0
- package/experiments/render.js +149 -0
- package/experiments/render.js.map +1 -0
- package/experiments/types.d.ts +108 -0
- package/experiments/types.js +4 -0
- package/experiments/types.js.map +1 -0
- package/findMatchingAstNode.d.ts +2 -0
- package/findMatchingAstNode.js +15 -0
- package/findMatchingAstNode.js.map +1 -0
- package/generateElementId.d.ts +1 -0
- package/generateElementId.js +7 -0
- package/generateElementId.js.map +1 -0
- package/globalElements.d.ts +43 -0
- package/globalElements.js +79 -0
- package/globalElements.js.map +1 -0
- package/globalElements.test.d.ts +1 -0
- package/globalElements.test.js +343 -0
- package/globalElements.test.js.map +1 -0
- package/headersProvider.d.ts +3 -0
- package/headersProvider.js +8 -0
- package/headersProvider.js.map +1 -0
- package/image/geometry.d.ts +54 -0
- package/image/geometry.js +112 -0
- package/image/geometry.js.map +1 -0
- package/image/geometry.test.d.ts +1 -0
- package/image/geometry.test.js +190 -0
- package/image/geometry.test.js.map +1 -0
- package/image/index.d.ts +3 -0
- package/image/index.js +3 -0
- package/image/presets.d.ts +6 -0
- package/image/presets.js +20 -0
- package/image/presets.js.map +1 -0
- package/image/types.d.ts +10 -0
- package/image/types.js +0 -0
- package/index.d.ts +49 -0
- package/index.js +48 -0
- package/jsonPatch.d.ts +6 -0
- package/jsonPatch.js +8 -0
- package/jsonPatch.js.map +1 -0
- package/messages.d.ts +13 -0
- package/messages.js +16 -0
- package/messages.js.map +1 -0
- package/messenger/MessageOrigin.d.ts +7 -0
- package/messenger/MessageOrigin.js +15 -0
- package/messenger/MessageOrigin.js.map +1 -0
- package/messenger/Messenger.d.ts +22 -0
- package/messenger/Messenger.js +69 -0
- package/messenger/Messenger.js.map +1 -0
- package/messenger/index.d.ts +2 -0
- package/messenger/index.js +2 -0
- package/package.json +50 -0
- package/registerComponentGroup.d.ts +2 -0
- package/registerComponentGroup.js +9 -0
- package/registerComponentGroup.js.map +1 -0
- package/types/ShorthandCssProperties.d.ts +1 -0
- package/types/ShorthandCssProperties.js +0 -0
- package/types/WebsiteBuilderTheme.d.ts +101 -0
- package/types/WebsiteBuilderTheme.js +0 -0
- package/types.d.ts +607 -0
- package/types.js +0 -0
- package/withGlobalElementDefaults.d.ts +8 -0
- package/withGlobalElementDefaults.js +60 -0
- package/withGlobalElementDefaults.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createContentClient.test.js","sources":["../src/createContentClient.test.ts"],"sourcesContent":["import { describe, it, expect, beforeEach, afterEach, vi } from \"vitest\";\nimport { createContentClient } from \"./createContentClient.js\";\nimport { contentSdk } from \"./ContentSdk.js\";\n\ninterface RecordedRequest {\n url: string;\n tenant: string;\n authorization: string;\n path: string;\n}\n\nconst pageResponse = (path: string) => {\n return {\n data: {\n websiteBuilder: {\n getPageByPath: {\n data: { id: `page:${path}`, properties: { id: `page:${path}`, path } },\n error: null\n }\n }\n }\n };\n};\n\ndescribe(\"createContentClient\", () => {\n let requests: RecordedRequest[];\n let delays: Record<string, number>;\n\n beforeEach(() => {\n requests = [];\n delays = {};\n\n const fetchMock = vi.fn(async (url: string, init: RequestInit) => {\n const headers = init.headers as Record<string, string>;\n const body = JSON.parse(init.body as string);\n const path: string = body.variables.path;\n requests.push({\n url,\n tenant: headers[\"X-Tenant\"],\n authorization: headers[\"Authorization\"],\n path\n });\n\n const delay = delays[path] ?? 0;\n await new Promise(resolve => setTimeout(resolve, delay));\n\n return { json: async () => pageResponse(path) };\n });\n\n vi.stubGlobal(\"fetch\", fetchMock);\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n });\n\n it(\"sends each client's own tenant, host and key\", async () => {\n const clientA = createContentClient({\n apiHost: \"https://a.example.com\",\n apiKey: \"key-a\",\n apiTenant: \"tenant-a\"\n });\n const clientB = createContentClient({\n apiHost: \"https://b.example.com\",\n apiKey: \"key-b\",\n apiTenant: \"tenant-b\"\n });\n\n await clientA.getPage(\"/a\");\n await clientB.getPage(\"/b\");\n\n expect(requests).toEqual([\n {\n url: \"https://a.example.com/graphql\",\n tenant: \"tenant-a\",\n authorization: \"Bearer key-a\",\n path: \"/a\"\n },\n {\n url: \"https://b.example.com/graphql\",\n tenant: \"tenant-b\",\n authorization: \"Bearer key-b\",\n path: \"/b\"\n }\n ]);\n });\n\n it(\"keeps clients isolated when their calls interleave\", async () => {\n const clientA = createContentClient({\n apiHost: \"https://a.example.com\",\n apiKey: \"key-a\",\n apiTenant: \"tenant-a\"\n });\n const clientB = createContentClient({\n apiHost: \"https://b.example.com\",\n apiKey: \"key-b\",\n apiTenant: \"tenant-b\"\n });\n\n // The first request to start is the last to finish.\n delays[\"/a\"] = 20;\n delays[\"/b\"] = 0;\n\n const [pageA, pageB] = await Promise.all([clientA.getPage(\"/a\"), clientB.getPage(\"/b\")]);\n\n expect(pageA?.properties.path).toBe(\"/a\");\n expect(pageB?.properties.path).toBe(\"/b\");\n\n const requestA = requests.find(request => request.path === \"/a\");\n const requestB = requests.find(request => request.path === \"/b\");\n\n expect(requestA).toMatchObject({\n url: \"https://a.example.com/graphql\",\n tenant: \"tenant-a\",\n authorization: \"Bearer key-a\"\n });\n expect(requestB).toMatchObject({\n url: \"https://b.example.com/graphql\",\n tenant: \"tenant-b\",\n authorization: \"Bearer key-b\"\n });\n });\n\n it(\"does not change what the contentSdk singleton sends, and init() does not change a client\", async () => {\n contentSdk.init({\n apiHost: \"https://singleton.example.com\",\n apiKey: \"key-singleton\",\n apiTenant: \"root\"\n });\n\n const client = createContentClient({\n apiHost: \"https://client.example.com\",\n apiKey: \"key-client\",\n apiTenant: \"tenant-client\"\n });\n\n await contentSdk.getPage(\"/singleton\");\n\n contentSdk.init({\n apiHost: \"https://singleton-2.example.com\",\n apiKey: \"key-singleton-2\",\n apiTenant: \"root-2\"\n });\n\n await client.getPage(\"/client\");\n await contentSdk.getPage(\"/singleton-2\");\n\n expect(requests).toEqual([\n {\n url: \"https://singleton.example.com/graphql\",\n tenant: \"root\",\n authorization: \"Bearer key-singleton\",\n path: \"/singleton\"\n },\n {\n url: \"https://client.example.com/graphql\",\n tenant: \"tenant-client\",\n authorization: \"Bearer key-client\",\n path: \"/client\"\n },\n {\n url: \"https://singleton-2.example.com/graphql\",\n tenant: \"root-2\",\n authorization: \"Bearer key-singleton-2\",\n path: \"/singleton-2\"\n }\n ]);\n });\n\n it(\"keeps the preview flag per client\", () => {\n const live = createContentClient({\n apiHost: \"https://a.example.com\",\n apiKey: \"key-a\",\n apiTenant: \"tenant-a\"\n });\n const preview = createContentClient({\n apiHost: \"https://a.example.com\",\n apiKey: \"key-a\",\n apiTenant: \"tenant-a\",\n preview: true,\n previewParams: \"wb.type=page&wb.path=/a&wb.id=page-1\"\n });\n\n expect(live.isPreviewing()).toBe(false);\n expect(preview.isPreviewing()).toBe(true);\n });\n});\n"],"names":["pageResponse","path","describe","requests","delays","beforeEach","fetchMock","vi","url","init","headers","body","JSON","delay","Promise","resolve","setTimeout","afterEach","it","clientA","createContentClient","clientB","expect","pageA","pageB","requestA","request","requestB","contentSdk","client","live","preview"],"mappings":"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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ResponsiveStyles } from "./types.js";
|
|
2
|
+
export interface CreateElementParams {
|
|
3
|
+
component: string;
|
|
4
|
+
inputs?: Record<string, any>;
|
|
5
|
+
styles?: ResponsiveStyles;
|
|
6
|
+
}
|
|
7
|
+
export declare const createElement: (params: CreateElementParams) => {
|
|
8
|
+
action: string;
|
|
9
|
+
params: CreateElementParams;
|
|
10
|
+
};
|
package/createElement.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createElement.js","sources":["../src/createElement.ts"],"sourcesContent":["import type { ResponsiveStyles } from \"~/types.js\";\n\nexport interface CreateElementParams {\n component: string;\n inputs?: Record<string, any>;\n styles?: ResponsiveStyles;\n}\n\nexport const createElement = (params: CreateElementParams) => {\n return {\n action: \"CreateElement\",\n params\n };\n};\n"],"names":["createElement","params"],"mappings":"AAQO,MAAMA,gBAAgB,CAACC,SACnB;QACH,QAAQ;QACRA;IACJ"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ComponentManifest, GlobalDocument } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Build the default instance of a global component (element + bindings) from its manifest defaults.
|
|
4
|
+
* Used when a global exists in code but has no stored instance yet.
|
|
5
|
+
*/
|
|
6
|
+
export declare const createGlobalElementDocument: (componentName: string, components: Record<string, ComponentManifest>) => GlobalDocument;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ElementFactory } from "./ElementFactory.js";
|
|
2
|
+
const createDefaultIdGenerator = (componentName)=>{
|
|
3
|
+
const name = componentName.replace(/[^a-zA-Z0-9]/gu, (char)=>`_${char.codePointAt(0).toString(16)}_`);
|
|
4
|
+
const prefix = `global-${name}`;
|
|
5
|
+
let counter = 0;
|
|
6
|
+
return ()=>`${prefix}-${++counter}`;
|
|
7
|
+
};
|
|
8
|
+
const createGlobalElementDocument = (componentName, components)=>{
|
|
9
|
+
const factory = new ElementFactory(components, createDefaultIdGenerator(componentName));
|
|
10
|
+
const { operations } = factory.createGlobalElement(componentName);
|
|
11
|
+
const document = {
|
|
12
|
+
elements: {},
|
|
13
|
+
bindings: {}
|
|
14
|
+
};
|
|
15
|
+
operations.forEach((operation)=>operation.apply(document));
|
|
16
|
+
return {
|
|
17
|
+
elements: document.elements,
|
|
18
|
+
bindings: document.bindings
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export { createGlobalElementDocument };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=createGlobalElementDocument.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createGlobalElementDocument.js","sources":["../src/createGlobalElementDocument.ts"],"sourcesContent":["import type { ComponentManifest, Document, GlobalDocument } from \"./types.js\";\nimport { ElementFactory } from \"./ElementFactory.js\";\n\n/**\n * Ids for the elements and bindings of a default global instance. They are derived from the component\n * name, so every build of the same defaults yields the same ids: the server render and the client\n * hydration agree, and re-renders don't remount the global's children. The hyphens keep them apart\n * from generated ids, which use only lowercase letters and digits.\n * Every other character of the name is escaped as `_<hex code point>_`, so two different names never\n * share a prefix (`Demo/Header` and `Demo-Header` would both collapse to `Demo-Header` otherwise).\n */\nconst createDefaultIdGenerator = (componentName: string) => {\n const name = componentName.replace(/[^a-zA-Z0-9]/gu, char => {\n return `_${char.codePointAt(0)!.toString(16)}_`;\n });\n const prefix = `global-${name}`;\n let counter = 0;\n return () => `${prefix}-${++counter}`;\n};\n\n/**\n * Build the default instance of a global component (element + bindings) from its manifest defaults.\n * Used when a global exists in code but has no stored instance yet.\n */\nexport const createGlobalElementDocument = (\n componentName: string,\n components: Record<string, ComponentManifest>\n): GlobalDocument => {\n const factory = new ElementFactory(components, createDefaultIdGenerator(componentName));\n const { operations } = factory.createGlobalElement(componentName);\n\n const document = { elements: {}, bindings: {} } as Document;\n operations.forEach(operation => operation.apply(document));\n\n return { elements: document.elements, bindings: document.bindings };\n};\n"],"names":["createDefaultIdGenerator","componentName","name","char","prefix","counter","createGlobalElementDocument","components","factory","ElementFactory","operations","document","operation"],"mappings":";AAWA,MAAMA,2BAA2B,CAACC;IAC9B,MAAMC,OAAOD,cAAc,OAAO,CAAC,kBAAkBE,CAAAA,OAC1C,CAAC,CAAC,EAAEA,KAAK,WAAW,CAAC,GAAI,QAAQ,CAAC,IAAI,CAAC,CAAC;IAEnD,MAAMC,SAAS,CAAC,OAAO,EAAEF,MAAM;IAC/B,IAAIG,UAAU;IACd,OAAO,IAAM,GAAGD,OAAO,CAAC,EAAE,EAAEC,SAAS;AACzC;AAMO,MAAMC,8BAA8B,CACvCL,eACAM;IAEA,MAAMC,UAAU,IAAIC,eAAeF,YAAYP,yBAAyBC;IACxE,MAAM,EAAES,UAAU,EAAE,GAAGF,QAAQ,mBAAmB,CAACP;IAEnD,MAAMU,WAAW;QAAE,UAAU,CAAC;QAAG,UAAU,CAAC;IAAE;IAC9CD,WAAW,OAAO,CAACE,CAAAA,YAAaA,UAAU,KAAK,CAACD;IAEhD,OAAO;QAAE,UAAUA,SAAS,QAAQ;QAAE,UAAUA,SAAS,QAAQ;IAAC;AACtE"}
|
package/createInput.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { TextInput, LongTextInput, NumberInput, BooleanInput, ColorInput, FileInput, LexicalInput, SelectInput, RadioInput, ObjectInput, DateTimeInput, ComponentInput, TagsInput, SlotInput, ContentEntryInput } from "./types.js";
|
|
2
|
+
export type InputFactory<Name extends string> = ReturnType<typeof createTextInput<Name>> | ReturnType<typeof createLongTextInput<Name>> | ReturnType<typeof createNumberInput<Name>> | ReturnType<typeof createBooleanInput<Name>> | ReturnType<typeof createColorInput<Name>> | ReturnType<typeof createFileInput<Name>> | ReturnType<typeof createDateInput<Name>> | ReturnType<typeof createLexicalInput<Name>> | ReturnType<typeof createSelectInput<Name>> | ReturnType<typeof createRadioInput<Name>> | ReturnType<typeof createObjectInput<Name>> | ReturnType<typeof createTagsInput<Name>> | ReturnType<typeof createSlotInput<Name>> | ReturnType<typeof createContentEntryInput<Name>>;
|
|
3
|
+
/**
|
|
4
|
+
* TypeScript Overload Resolution and Input Factory Design
|
|
5
|
+
*
|
|
6
|
+
* Each input factory (e.g., createTextInput) is defined with two TypeScript overload signatures:
|
|
7
|
+
* 1. One overload requires a `name` property in the input (used for array-based APIs, where inference is needed).
|
|
8
|
+
* 2. The other overload omits the `name` property (used for object-based APIs, where the key provides the name).
|
|
9
|
+
*
|
|
10
|
+
* TypeScript resolves overloads by scanning from top to bottom and picking the first matching signature.
|
|
11
|
+
* The implementation signature uses `any` for the argument, and the return type is unified to match all overloads.
|
|
12
|
+
*
|
|
13
|
+
* In array mode, the `name` must be explicitly provided in the input object, so inference for `TName` works.
|
|
14
|
+
* In object mode, the input does not require a `name` property; instead, the key in the object (e.g., `{ foo: createTextInput({ ... }) }`)
|
|
15
|
+
* provides the name via contextual typing from the consuming function (such as `createComponent`). TypeScript uses this context
|
|
16
|
+
* to resolve the correct type for `TName` even when `name` is omitted from the input.
|
|
17
|
+
*
|
|
18
|
+
* This pattern ensures that all returned input objects are typed as `{ name: TName }`, whether `name` is provided explicitly or inferred,
|
|
19
|
+
* so consumers of these factories do not need to worry about the presence of the `name` property in the result.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createTextInput<TName extends string>(input: {
|
|
22
|
+
name: TName;
|
|
23
|
+
} & Omit<TextInput, "type" | "name">): TextInput & {
|
|
24
|
+
name: TName;
|
|
25
|
+
};
|
|
26
|
+
export declare function createTextInput<TName extends string>(input: Omit<TextInput, "type" | "name">): TextInput & {
|
|
27
|
+
name: TName;
|
|
28
|
+
};
|
|
29
|
+
export declare function createLongTextInput<TName extends string>(input: {
|
|
30
|
+
name: TName;
|
|
31
|
+
} & Omit<LongTextInput, "type" | "name">): LongTextInput & {
|
|
32
|
+
name: TName;
|
|
33
|
+
};
|
|
34
|
+
export declare function createLongTextInput<TName extends string>(input: Omit<LongTextInput, "type" | "name">): LongTextInput & {
|
|
35
|
+
name: TName;
|
|
36
|
+
};
|
|
37
|
+
export declare function createNumberInput<TName extends string>(input: {
|
|
38
|
+
name: TName;
|
|
39
|
+
} & Omit<NumberInput, "type" | "name">): NumberInput & {
|
|
40
|
+
name: TName;
|
|
41
|
+
};
|
|
42
|
+
export declare function createNumberInput<TName extends string>(input: Omit<NumberInput, "type" | "name">): NumberInput & {
|
|
43
|
+
name: TName;
|
|
44
|
+
};
|
|
45
|
+
export declare function createBooleanInput<TName extends string>(input: {
|
|
46
|
+
name: TName;
|
|
47
|
+
} & Omit<BooleanInput, "type" | "name">): BooleanInput & {
|
|
48
|
+
name: TName;
|
|
49
|
+
};
|
|
50
|
+
export declare function createBooleanInput<TName extends string>(input: Omit<BooleanInput, "type" | "name">): BooleanInput & {
|
|
51
|
+
name: TName;
|
|
52
|
+
};
|
|
53
|
+
export declare function createColorInput<TName extends string>(input: {
|
|
54
|
+
name: TName;
|
|
55
|
+
} & Omit<ColorInput, "type" | "name">): ColorInput & {
|
|
56
|
+
name: TName;
|
|
57
|
+
};
|
|
58
|
+
export declare function createColorInput<TName extends string>(input: Omit<ColorInput, "type" | "name">): ColorInput & {
|
|
59
|
+
name: TName;
|
|
60
|
+
};
|
|
61
|
+
export declare function createFileInput<TName extends string>(input: {
|
|
62
|
+
name: TName;
|
|
63
|
+
} & Omit<FileInput, "type" | "name">): FileInput & {
|
|
64
|
+
name: TName;
|
|
65
|
+
};
|
|
66
|
+
export declare function createFileInput<TName extends string>(input: Omit<FileInput, "type" | "name">): FileInput & {
|
|
67
|
+
name: TName;
|
|
68
|
+
};
|
|
69
|
+
export declare function createDateInput<TName extends string>(input: {
|
|
70
|
+
name: TName;
|
|
71
|
+
} & Omit<DateTimeInput, "type" | "name">): DateTimeInput & {
|
|
72
|
+
name: TName;
|
|
73
|
+
};
|
|
74
|
+
export declare function createDateInput<TName extends string>(input: Omit<DateTimeInput, "type" | "name">): DateTimeInput & {
|
|
75
|
+
name: TName;
|
|
76
|
+
};
|
|
77
|
+
export declare function createLexicalInput<TName extends string>(input: {
|
|
78
|
+
name: TName;
|
|
79
|
+
} & Omit<LexicalInput, "type" | "name">): LexicalInput & {
|
|
80
|
+
name: TName;
|
|
81
|
+
};
|
|
82
|
+
export declare function createLexicalInput<TName extends string>(input: Omit<LexicalInput, "type" | "name">): LexicalInput & {
|
|
83
|
+
name: TName;
|
|
84
|
+
};
|
|
85
|
+
export declare function createSelectInput<TName extends string>(input: {
|
|
86
|
+
name: TName;
|
|
87
|
+
} & Omit<SelectInput, "type" | "name">): SelectInput & {
|
|
88
|
+
name: TName;
|
|
89
|
+
};
|
|
90
|
+
export declare function createSelectInput<TName extends string>(input: Omit<SelectInput, "type" | "name">): SelectInput & {
|
|
91
|
+
name: TName;
|
|
92
|
+
};
|
|
93
|
+
export declare function createRadioInput<TName extends string>(input: {
|
|
94
|
+
name: TName;
|
|
95
|
+
} & Omit<RadioInput, "type" | "name">): RadioInput & {
|
|
96
|
+
name: TName;
|
|
97
|
+
};
|
|
98
|
+
export declare function createRadioInput<TName extends string>(input: Omit<RadioInput, "type" | "name">): RadioInput & {
|
|
99
|
+
name: TName;
|
|
100
|
+
};
|
|
101
|
+
export declare function createObjectInput<TName extends string>(input: {
|
|
102
|
+
name: TName;
|
|
103
|
+
} & Omit<ObjectInput, "type" | "name">): ObjectInput & {
|
|
104
|
+
name: TName;
|
|
105
|
+
};
|
|
106
|
+
export declare function createObjectInput<TName extends string>(input: Omit<ObjectInput, "type" | "name">): ObjectInput & {
|
|
107
|
+
name: TName;
|
|
108
|
+
};
|
|
109
|
+
export declare function createTagsInput<TName extends string>(input: {
|
|
110
|
+
name: TName;
|
|
111
|
+
} & Omit<TagsInput, "type" | "name">): TagsInput & {
|
|
112
|
+
name: TName;
|
|
113
|
+
};
|
|
114
|
+
export declare function createTagsInput<TName extends string>(input: Omit<TagsInput, "type" | "name">): TagsInput & {
|
|
115
|
+
name: TName;
|
|
116
|
+
};
|
|
117
|
+
export declare function createSlotInput<TName extends string>(input: {
|
|
118
|
+
name: TName;
|
|
119
|
+
} & Omit<SlotInput, "type" | "name">): SlotInput & {
|
|
120
|
+
name: TName;
|
|
121
|
+
};
|
|
122
|
+
export declare function createSlotInput<TName extends string>(input: Omit<SlotInput, "type" | "name">): SlotInput & {
|
|
123
|
+
name: TName;
|
|
124
|
+
};
|
|
125
|
+
export declare function createContentEntryInput<TName extends string>(input: {
|
|
126
|
+
name: TName;
|
|
127
|
+
} & Omit<ContentEntryInput, "type" | "name">): ContentEntryInput & {
|
|
128
|
+
name: TName;
|
|
129
|
+
};
|
|
130
|
+
export declare function createContentEntryInput<TName extends string>(input: Omit<ContentEntryInput, "type" | "name">): ContentEntryInput & {
|
|
131
|
+
name: TName;
|
|
132
|
+
};
|
|
133
|
+
export declare function createInput(input: ComponentInput): ComponentInput;
|
package/createInput.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { functionConverter } from "./FunctionConverter.js";
|
|
2
|
+
function createTextInput(input) {
|
|
3
|
+
return createInput({
|
|
4
|
+
type: "text",
|
|
5
|
+
renderer: "Webiny/Input",
|
|
6
|
+
...input
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
function createLongTextInput(input) {
|
|
10
|
+
return createInput({
|
|
11
|
+
type: "longText",
|
|
12
|
+
renderer: "Webiny/Textarea",
|
|
13
|
+
...input
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function createNumberInput(input) {
|
|
17
|
+
return createInput({
|
|
18
|
+
type: "number",
|
|
19
|
+
renderer: "Webiny/Number",
|
|
20
|
+
...input
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function createBooleanInput(input) {
|
|
24
|
+
return createInput({
|
|
25
|
+
type: "boolean",
|
|
26
|
+
renderer: "Webiny/Switch",
|
|
27
|
+
...input
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function createColorInput(input) {
|
|
31
|
+
return createInput({
|
|
32
|
+
type: "color",
|
|
33
|
+
renderer: "Webiny/ColorPicker",
|
|
34
|
+
...input
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function createFileInput(input) {
|
|
38
|
+
return createInput({
|
|
39
|
+
type: "file",
|
|
40
|
+
renderer: "Webiny/FileManager",
|
|
41
|
+
...input
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function createDateInput(input) {
|
|
45
|
+
return createInput({
|
|
46
|
+
type: "datetime",
|
|
47
|
+
renderer: "Webiny/DateTime",
|
|
48
|
+
...input
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function createLexicalInput(input) {
|
|
52
|
+
return createInput({
|
|
53
|
+
type: "lexical",
|
|
54
|
+
renderer: "Webiny/Lexical",
|
|
55
|
+
...input
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function createSelectInput(input) {
|
|
59
|
+
return createInput({
|
|
60
|
+
type: "select",
|
|
61
|
+
renderer: "Webiny/Select",
|
|
62
|
+
...input
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function createRadioInput(input) {
|
|
66
|
+
return createInput({
|
|
67
|
+
type: "radio",
|
|
68
|
+
renderer: "Webiny/RadioGroup",
|
|
69
|
+
...input
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function createObjectInput(input) {
|
|
73
|
+
return createInput({
|
|
74
|
+
type: "object",
|
|
75
|
+
renderer: "Webiny/Object",
|
|
76
|
+
...input
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function createTagsInput(input) {
|
|
80
|
+
return createInput({
|
|
81
|
+
type: "text",
|
|
82
|
+
list: true,
|
|
83
|
+
renderer: "Webiny/Tags",
|
|
84
|
+
...input
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function createSlotInput(input) {
|
|
88
|
+
return createInput({
|
|
89
|
+
type: "slot",
|
|
90
|
+
list: true,
|
|
91
|
+
renderer: "Webiny/Slot",
|
|
92
|
+
defaultValue: [],
|
|
93
|
+
...input
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function createContentEntryInput(input) {
|
|
97
|
+
return createInput({
|
|
98
|
+
type: "contentEntry",
|
|
99
|
+
renderer: "Webiny/ContentEntry",
|
|
100
|
+
...input
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function createInput(input) {
|
|
104
|
+
if (input.onChange) input.onChange = functionConverter.serialize(input.onChange);
|
|
105
|
+
return input;
|
|
106
|
+
}
|
|
107
|
+
export { createBooleanInput, createColorInput, createContentEntryInput, createDateInput, createFileInput, createInput, createLexicalInput, createLongTextInput, createNumberInput, createObjectInput, createRadioInput, createSelectInput, createSlotInput, createTagsInput, createTextInput };
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=createInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createInput.js","sources":["../src/createInput.ts"],"sourcesContent":["import type {\n TextInput,\n LongTextInput,\n NumberInput,\n BooleanInput,\n ColorInput,\n FileInput,\n LexicalInput,\n SelectInput,\n RadioInput,\n ObjectInput,\n DateTimeInput,\n ComponentInput,\n TagsInput,\n SlotInput,\n ContentEntryInput\n} from \"./types.js\";\nimport { functionConverter } from \"~/FunctionConverter.js\";\n\nexport type InputFactory<Name extends string> =\n | ReturnType<typeof createTextInput<Name>>\n | ReturnType<typeof createLongTextInput<Name>>\n | ReturnType<typeof createNumberInput<Name>>\n | ReturnType<typeof createBooleanInput<Name>>\n | ReturnType<typeof createColorInput<Name>>\n | ReturnType<typeof createFileInput<Name>>\n | ReturnType<typeof createDateInput<Name>>\n | ReturnType<typeof createLexicalInput<Name>>\n | ReturnType<typeof createSelectInput<Name>>\n | ReturnType<typeof createRadioInput<Name>>\n | ReturnType<typeof createObjectInput<Name>>\n | ReturnType<typeof createTagsInput<Name>>\n | ReturnType<typeof createSlotInput<Name>>\n | ReturnType<typeof createContentEntryInput<Name>>;\n\n/**\n * TypeScript Overload Resolution and Input Factory Design\n *\n * Each input factory (e.g., createTextInput) is defined with two TypeScript overload signatures:\n * 1. One overload requires a `name` property in the input (used for array-based APIs, where inference is needed).\n * 2. The other overload omits the `name` property (used for object-based APIs, where the key provides the name).\n *\n * TypeScript resolves overloads by scanning from top to bottom and picking the first matching signature.\n * The implementation signature uses `any` for the argument, and the return type is unified to match all overloads.\n *\n * In array mode, the `name` must be explicitly provided in the input object, so inference for `TName` works.\n * In object mode, the input does not require a `name` property; instead, the key in the object (e.g., `{ foo: createTextInput({ ... }) }`)\n * provides the name via contextual typing from the consuming function (such as `createComponent`). TypeScript uses this context\n * to resolve the correct type for `TName` even when `name` is omitted from the input.\n *\n * This pattern ensures that all returned input objects are typed as `{ name: TName }`, whether `name` is provided explicitly or inferred,\n * so consumers of these factories do not need to worry about the presence of the `name` property in the result.\n */\n// Text\nexport function createTextInput<TName extends string>(\n input: { name: TName } & Omit<TextInput, \"type\" | \"name\">\n): TextInput & { name: TName };\nexport function createTextInput<TName extends string>(\n input: Omit<TextInput, \"type\" | \"name\">\n): TextInput & { name: TName };\nexport function createTextInput<TName extends string>(input: any): TextInput & { name: TName } {\n return createInput({\n type: \"text\",\n renderer: \"Webiny/Input\",\n ...input\n }) as TextInput & { name: TName };\n}\n\n// Long Text\nexport function createLongTextInput<TName extends string>(\n input: { name: TName } & Omit<LongTextInput, \"type\" | \"name\">\n): LongTextInput & { name: TName };\nexport function createLongTextInput<TName extends string>(\n input: Omit<LongTextInput, \"type\" | \"name\">\n): LongTextInput & { name: TName };\nexport function createLongTextInput<TName extends string>(\n input: any\n): LongTextInput & { name: TName } {\n return createInput({\n type: \"longText\",\n renderer: \"Webiny/Textarea\",\n ...input\n }) as LongTextInput & { name: TName };\n}\n\n// Number\nexport function createNumberInput<TName extends string>(\n input: { name: TName } & Omit<NumberInput, \"type\" | \"name\">\n): NumberInput & { name: TName };\nexport function createNumberInput<TName extends string>(\n input: Omit<NumberInput, \"type\" | \"name\">\n): NumberInput & { name: TName };\nexport function createNumberInput<TName extends string>(input: any): NumberInput & { name: TName } {\n return createInput({\n type: \"number\",\n renderer: \"Webiny/Number\",\n ...input\n }) as NumberInput & { name: TName };\n}\n\n// Boolean\nexport function createBooleanInput<TName extends string>(\n input: { name: TName } & Omit<BooleanInput, \"type\" | \"name\">\n): BooleanInput & { name: TName };\nexport function createBooleanInput<TName extends string>(\n input: Omit<BooleanInput, \"type\" | \"name\">\n): BooleanInput & { name: TName };\nexport function createBooleanInput<TName extends string>(\n input: any\n): BooleanInput & { name: TName } {\n return createInput({\n type: \"boolean\",\n renderer: \"Webiny/Switch\",\n ...input\n }) as BooleanInput & { name: TName };\n}\n\n// Color\nexport function createColorInput<TName extends string>(\n input: { name: TName } & Omit<ColorInput, \"type\" | \"name\">\n): ColorInput & { name: TName };\nexport function createColorInput<TName extends string>(\n input: Omit<ColorInput, \"type\" | \"name\">\n): ColorInput & { name: TName };\nexport function createColorInput<TName extends string>(input: any): ColorInput & { name: TName } {\n return createInput({\n type: \"color\",\n renderer: \"Webiny/ColorPicker\",\n ...input\n }) as ColorInput & { name: TName };\n}\n\n// File\nexport function createFileInput<TName extends string>(\n input: { name: TName } & Omit<FileInput, \"type\" | \"name\">\n): FileInput & { name: TName };\nexport function createFileInput<TName extends string>(\n input: Omit<FileInput, \"type\" | \"name\">\n): FileInput & { name: TName };\nexport function createFileInput<TName extends string>(input: any): FileInput & { name: TName } {\n return createInput({\n type: \"file\",\n renderer: \"Webiny/FileManager\",\n ...input\n }) as FileInput & { name: TName };\n}\n\n// Date\nexport function createDateInput<TName extends string>(\n input: { name: TName } & Omit<DateTimeInput, \"type\" | \"name\">\n): DateTimeInput & { name: TName };\nexport function createDateInput<TName extends string>(\n input: Omit<DateTimeInput, \"type\" | \"name\">\n): DateTimeInput & { name: TName };\nexport function createDateInput<TName extends string>(input: any): DateTimeInput & { name: TName } {\n return createInput({\n type: \"datetime\",\n renderer: \"Webiny/DateTime\",\n ...input\n }) as DateTimeInput & { name: TName };\n}\n\n// Rich Text\nexport function createLexicalInput<TName extends string>(\n input: { name: TName } & Omit<LexicalInput, \"type\" | \"name\">\n): LexicalInput & { name: TName };\nexport function createLexicalInput<TName extends string>(\n input: Omit<LexicalInput, \"type\" | \"name\">\n): LexicalInput & { name: TName };\nexport function createLexicalInput<TName extends string>(\n input: any\n): LexicalInput & { name: TName } {\n return createInput({\n type: \"lexical\",\n renderer: \"Webiny/Lexical\",\n ...input\n }) as LexicalInput & { name: TName };\n}\n\n// Select\nexport function createSelectInput<TName extends string>(\n input: { name: TName } & Omit<SelectInput, \"type\" | \"name\">\n): SelectInput & { name: TName };\nexport function createSelectInput<TName extends string>(\n input: Omit<SelectInput, \"type\" | \"name\">\n): SelectInput & { name: TName };\nexport function createSelectInput<TName extends string>(input: any): SelectInput & { name: TName } {\n return createInput({\n type: \"select\",\n renderer: \"Webiny/Select\",\n ...input\n }) as SelectInput & { name: TName };\n}\n\n// Radio\nexport function createRadioInput<TName extends string>(\n input: { name: TName } & Omit<RadioInput, \"type\" | \"name\">\n): RadioInput & { name: TName };\nexport function createRadioInput<TName extends string>(\n input: Omit<RadioInput, \"type\" | \"name\">\n): RadioInput & { name: TName };\nexport function createRadioInput<TName extends string>(input: any): RadioInput & { name: TName } {\n return createInput({\n type: \"radio\",\n renderer: \"Webiny/RadioGroup\",\n ...input\n }) as RadioInput & { name: TName };\n}\n\n// Object\nexport function createObjectInput<TName extends string>(\n input: { name: TName } & Omit<ObjectInput, \"type\" | \"name\">\n): ObjectInput & { name: TName };\nexport function createObjectInput<TName extends string>(\n input: Omit<ObjectInput, \"type\" | \"name\">\n): ObjectInput & { name: TName };\nexport function createObjectInput<TName extends string>(input: any): ObjectInput & { name: TName } {\n return createInput({\n type: \"object\",\n renderer: \"Webiny/Object\",\n ...input\n }) as ObjectInput & { name: TName };\n}\n\n// Tags\nexport function createTagsInput<TName extends string>(\n input: { name: TName } & Omit<TagsInput, \"type\" | \"name\">\n): TagsInput & { name: TName };\nexport function createTagsInput<TName extends string>(\n input: Omit<TagsInput, \"type\" | \"name\">\n): TagsInput & { name: TName };\nexport function createTagsInput<TName extends string>(input: any): TagsInput & { name: TName } {\n return createInput({\n type: \"text\",\n list: true,\n renderer: \"Webiny/Tags\",\n ...input\n }) as TagsInput & { name: TName };\n}\n\nexport function createSlotInput<TName extends string>(\n input: { name: TName } & Omit<SlotInput, \"type\" | \"name\">\n): SlotInput & { name: TName };\nexport function createSlotInput<TName extends string>(\n input: Omit<SlotInput, \"type\" | \"name\">\n): SlotInput & { name: TName };\nexport function createSlotInput<TName extends string>(input: any): SlotInput & { name: TName } {\n return createInput({\n type: \"slot\",\n list: true,\n renderer: \"Webiny/Slot\",\n defaultValue: [],\n ...input\n }) as SlotInput & { name: TName };\n}\n\n// Content Entry\nexport function createContentEntryInput<TName extends string>(\n input: { name: TName } & Omit<ContentEntryInput, \"type\" | \"name\">\n): ContentEntryInput & { name: TName };\nexport function createContentEntryInput<TName extends string>(\n input: Omit<ContentEntryInput, \"type\" | \"name\">\n): ContentEntryInput & { name: TName };\nexport function createContentEntryInput<TName extends string>(\n input: any\n): ContentEntryInput & { name: TName } {\n return createInput({\n type: \"contentEntry\",\n renderer: \"Webiny/ContentEntry\",\n ...input\n }) as ContentEntryInput & { name: TName };\n}\n\n// Implementation\nexport function createInput(input: ComponentInput): ComponentInput {\n if (input.onChange) {\n // @ts-expect-error We don't use this function on the frontend, so this is ok.\n input.onChange = functionConverter.serialize(input.onChange!);\n }\n return input;\n}\n"],"names":["createTextInput","input","createInput","createLongTextInput","createNumberInput","createBooleanInput","createColorInput","createFileInput","createDateInput","createLexicalInput","createSelectInput","createRadioInput","createObjectInput","createTagsInput","createSlotInput","createContentEntryInput","functionConverter"],"mappings":";AA4DO,SAASA,gBAAsCC,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASE,oBACZF,KAAU;IAEV,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASG,kBAAwCH,KAAU;IAC9D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASI,mBACZJ,KAAU;IAEV,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASK,iBAAuCL,KAAU;IAC7D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASM,gBAAsCN,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASO,gBAAsCP,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASQ,mBACZR,KAAU;IAEV,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASS,kBAAwCT,KAAU;IAC9D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASU,iBAAuCV,KAAU;IAC7D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASW,kBAAwCX,KAAU;IAC9D,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AASO,SAASY,gBAAsCZ,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AAQO,SAASa,gBAAsCb,KAAU;IAC5D,OAAOC,YAAY;QACf,MAAM;QACN,MAAM;QACN,UAAU;QACV,cAAc,EAAE;QAChB,GAAGD,KAAK;IACZ;AACJ;AASO,SAASc,wBACZd,KAAU;IAEV,OAAOC,YAAY;QACf,MAAM;QACN,UAAU;QACV,GAAGD,KAAK;IACZ;AACJ;AAGO,SAASC,YAAYD,KAAqB;IAC7C,IAAIA,MAAM,QAAQ,EAEdA,MAAM,QAAQ,GAAGe,kBAAkB,SAAS,CAACf,MAAM,QAAQ;IAE/D,OAAOA;AACX"}
|
package/createTheme.d.ts
ADDED
package/createTheme.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTheme.js","sources":["../src/createTheme.ts"],"sourcesContent":["import type { WebsiteBuilderThemeInput } from \"~/types/WebsiteBuilderTheme.js\";\n\nexport type { WebsiteBuilderThemeInput };\n\nexport const createTheme = (theme: WebsiteBuilderThemeInput) => {\n return theme;\n};\n"],"names":["createTheme","theme"],"mappings":"AAIO,MAAMA,cAAc,CAACC,QACjBA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
interface QueryParams {
|
|
2
|
+
query: string;
|
|
3
|
+
variables: Record<string, any>;
|
|
4
|
+
}
|
|
5
|
+
export interface ApiClientConfig {
|
|
6
|
+
apiHost: string;
|
|
7
|
+
apiKey: string;
|
|
8
|
+
apiTenant: string;
|
|
9
|
+
preview?: boolean;
|
|
10
|
+
}
|
|
11
|
+
type WithPath<T> = T & {
|
|
12
|
+
path?: string;
|
|
13
|
+
next?: Record<string, any>;
|
|
14
|
+
};
|
|
15
|
+
export declare class ApiClient {
|
|
16
|
+
private readonly config;
|
|
17
|
+
constructor(config: ApiClientConfig);
|
|
18
|
+
fetch({ headers, path, ...params }: WithPath<RequestInit>): Promise<any>;
|
|
19
|
+
query({ query, variables }: QueryParams, options?: {
|
|
20
|
+
noStore?: boolean;
|
|
21
|
+
}): Promise<any>;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
class ApiClient {
|
|
2
|
+
constructor(config){
|
|
3
|
+
this.config = config;
|
|
4
|
+
}
|
|
5
|
+
async fetch({ headers, path, ...params }) {
|
|
6
|
+
return fetch(`${this.config.apiHost}${path}`, {
|
|
7
|
+
method: "GET",
|
|
8
|
+
headers: {
|
|
9
|
+
"Content-Type": "application/json",
|
|
10
|
+
"X-Tenant": this.config.apiTenant,
|
|
11
|
+
Authorization: "Bearer " + this.config.apiKey,
|
|
12
|
+
...headers
|
|
13
|
+
},
|
|
14
|
+
...params
|
|
15
|
+
}).then((res)=>res.json());
|
|
16
|
+
}
|
|
17
|
+
async query({ query, variables }, options) {
|
|
18
|
+
const fetchOptions = options?.noStore ? {
|
|
19
|
+
cache: "no-store"
|
|
20
|
+
} : {
|
|
21
|
+
next: {
|
|
22
|
+
revalidate: this.config.preview ? 0 : 60
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const request = {
|
|
26
|
+
...fetchOptions,
|
|
27
|
+
path: "/graphql",
|
|
28
|
+
method: "POST",
|
|
29
|
+
body: JSON.stringify({
|
|
30
|
+
query,
|
|
31
|
+
variables
|
|
32
|
+
})
|
|
33
|
+
};
|
|
34
|
+
const json = await this.fetch(request);
|
|
35
|
+
if (json.message) throw new Error(json.message);
|
|
36
|
+
if (json.errors) {
|
|
37
|
+
console.error(json.errors);
|
|
38
|
+
throw new Error("Failed to fetch API");
|
|
39
|
+
}
|
|
40
|
+
return json.data;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export { ApiClient };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=ApiClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataProviders/ApiClient.js","sources":["../../src/dataProviders/ApiClient.ts"],"sourcesContent":["interface QueryParams {\n query: string;\n variables: Record<string, any>;\n}\n\nexport interface ApiClientConfig {\n apiHost: string;\n apiKey: string;\n apiTenant: string;\n preview?: boolean;\n}\n\ntype WithPath<T> = T & {\n path?: string;\n next?: Record<string, any>;\n};\n\nexport class ApiClient {\n private readonly config: ApiClientConfig;\n\n constructor(config: ApiClientConfig) {\n this.config = config;\n }\n\n async fetch({ headers, path, ...params }: WithPath<RequestInit>): Promise<any> {\n return fetch(`${this.config.apiHost}${path}`, {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-Tenant\": this.config.apiTenant,\n Authorization: \"Bearer \" + this.config.apiKey,\n ...headers\n },\n ...params\n }).then(res => res.json());\n }\n\n async query({ query, variables }: QueryParams, options?: { noStore?: boolean }) {\n // Runtime reads (e.g. the experiment kill-switch) must bypass the cache so they take\n // effect immediately; everything else caches and revalidates on an interval.\n const fetchOptions: Pick<WithPath<RequestInit>, \"cache\" | \"next\"> = options?.noStore\n ? { cache: \"no-store\" }\n : { next: { revalidate: this.config.preview ? 0 : 60 } };\n\n const request: WithPath<RequestInit> = {\n ...fetchOptions,\n path: \"/graphql\",\n method: \"POST\",\n body: JSON.stringify({\n query,\n variables\n })\n };\n\n const json = await this.fetch(request);\n\n if (json.message) {\n throw new Error(json.message);\n }\n\n if (json.errors) {\n console.error(json.errors);\n throw new Error(\"Failed to fetch API\");\n }\n\n return json.data;\n }\n}\n"],"names":["ApiClient","config","headers","path","params","fetch","res","query","variables","options","fetchOptions","request","JSON","json","Error","console"],"mappings":"AAiBO,MAAMA;IAGT,YAAYC,MAAuB,CAAE;QACjC,IAAI,CAAC,MAAM,GAAGA;IAClB;IAEA,MAAM,MAAM,EAAEC,OAAO,EAAEC,IAAI,EAAE,GAAGC,QAA+B,EAAgB;QAC3E,OAAOC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,GAAGF,MAAM,EAAE;YAC1C,QAAQ;YACR,SAAS;gBACL,gBAAgB;gBAChB,YAAY,IAAI,CAAC,MAAM,CAAC,SAAS;gBACjC,eAAe,YAAY,IAAI,CAAC,MAAM,CAAC,MAAM;gBAC7C,GAAGD,OAAO;YACd;YACA,GAAGE,MAAM;QACb,GAAG,IAAI,CAACE,CAAAA,MAAOA,IAAI,IAAI;IAC3B;IAEA,MAAM,MAAM,EAAEC,KAAK,EAAEC,SAAS,EAAe,EAAEC,OAA+B,EAAE;QAG5E,MAAMC,eAA8DD,SAAS,UACvE;YAAE,OAAO;QAAW,IACpB;YAAE,MAAM;gBAAE,YAAY,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,IAAI;YAAG;QAAE;QAE3D,MAAME,UAAiC;YACnC,GAAGD,YAAY;YACf,MAAM;YACN,QAAQ;YACR,MAAME,KAAK,SAAS,CAAC;gBACjBL;gBACAC;YACJ;QACJ;QAEA,MAAMK,OAAO,MAAM,IAAI,CAAC,KAAK,CAACF;QAE9B,IAAIE,KAAK,OAAO,EACZ,MAAM,IAAIC,MAAMD,KAAK,OAAO;QAGhC,IAAIA,KAAK,MAAM,EAAE;YACbE,QAAQ,KAAK,CAACF,KAAK,MAAM;YACzB,MAAM,IAAIC,MAAM;QACpB;QAEA,OAAOD,KAAK,IAAI;IACpB;AACJ"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { GetLayoutParams, IDataProvider, ListPagesOptions, ListPagesResult, PublicLayout, PublicPage } from "../types.js";
|
|
2
|
+
import type { ActiveExperiment, VariantContent } from "../experiments/types.js";
|
|
3
|
+
import type { ApiClient } from "../dataProviders/ApiClient.js";
|
|
4
|
+
interface DefaultDataProviderConfig {
|
|
5
|
+
apiClient: ApiClient;
|
|
6
|
+
}
|
|
7
|
+
export declare class DefaultDataProvider implements IDataProvider {
|
|
8
|
+
private config;
|
|
9
|
+
constructor(config: DefaultDataProviderConfig);
|
|
10
|
+
getPageByPath(path: string): Promise<PublicPage | null>;
|
|
11
|
+
getPageById(id: string): Promise<PublicPage | null>;
|
|
12
|
+
getLayoutBySlug(params: GetLayoutParams): Promise<PublicLayout | null>;
|
|
13
|
+
listPages(options?: ListPagesOptions): Promise<ListPagesResult>;
|
|
14
|
+
getPageExperiment(path: string): Promise<ActiveExperiment | null>;
|
|
15
|
+
getVariantContent(variantId: string): Promise<VariantContent | null>;
|
|
16
|
+
getExperimentPaused(experimentId: string): Promise<boolean>;
|
|
17
|
+
private checkForErrors;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { GET_PAGE_BY_PATH } from "./GET_PAGE_BY_PATH.js";
|
|
2
|
+
import { GET_PAGE_BY_ID } from "./GET_PAGE_BY_ID.js";
|
|
3
|
+
import { GET_LAYOUT_BY_SLUG } from "./GET_LAYOUT_BY_SLUG.js";
|
|
4
|
+
import { LIST_PUBLISHED_PAGES } from "./LIST_PUBLISHED_PAGES.js";
|
|
5
|
+
import { GET_PAGE_EXPERIMENT } from "./GET_PAGE_EXPERIMENT.js";
|
|
6
|
+
import { GET_VARIANT_CONTENT } from "./GET_VARIANT_CONTENT.js";
|
|
7
|
+
import { GET_EXPERIMENT_PAUSED } from "./GET_EXPERIMENT_PAUSED.js";
|
|
8
|
+
const ignoreActions = [
|
|
9
|
+
".well-known",
|
|
10
|
+
"_next"
|
|
11
|
+
];
|
|
12
|
+
class DefaultDataProvider {
|
|
13
|
+
constructor(config){
|
|
14
|
+
this.config = config;
|
|
15
|
+
}
|
|
16
|
+
async getPageByPath(path) {
|
|
17
|
+
const result = await this.config.apiClient.query({
|
|
18
|
+
query: GET_PAGE_BY_PATH,
|
|
19
|
+
variables: {
|
|
20
|
+
path
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
this.checkForErrors(`getPageByPath:${path}`, result.websiteBuilder.getPageByPath);
|
|
24
|
+
return result.websiteBuilder.getPageByPath.data;
|
|
25
|
+
}
|
|
26
|
+
async getPageById(id) {
|
|
27
|
+
const result = await this.config.apiClient.query({
|
|
28
|
+
query: GET_PAGE_BY_ID,
|
|
29
|
+
variables: {
|
|
30
|
+
id
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
this.checkForErrors("getPageById", result.websiteBuilder.getPageById);
|
|
34
|
+
return result.websiteBuilder.getPageById.data;
|
|
35
|
+
}
|
|
36
|
+
async getLayoutBySlug(params) {
|
|
37
|
+
const result = await this.config.apiClient.query({
|
|
38
|
+
query: GET_LAYOUT_BY_SLUG,
|
|
39
|
+
variables: {
|
|
40
|
+
slug: params.slug,
|
|
41
|
+
language: params.language ?? null
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
this.checkForErrors(`getLayoutBySlug:${params.slug}`, result.websiteBuilder.getLayoutBySlug);
|
|
45
|
+
return result.websiteBuilder.getLayoutBySlug.data ?? null;
|
|
46
|
+
}
|
|
47
|
+
async listPages(options) {
|
|
48
|
+
const { where, ...rest } = options ?? {};
|
|
49
|
+
const result = await this.config.apiClient.query({
|
|
50
|
+
query: LIST_PUBLISHED_PAGES,
|
|
51
|
+
variables: {
|
|
52
|
+
where: {
|
|
53
|
+
...where,
|
|
54
|
+
published: true
|
|
55
|
+
},
|
|
56
|
+
...rest
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
this.checkForErrors("listPages", result.websiteBuilder.listPages);
|
|
60
|
+
return {
|
|
61
|
+
data: result.websiteBuilder.listPages.data ?? [],
|
|
62
|
+
meta: result.websiteBuilder.listPages.meta ?? {
|
|
63
|
+
hasMoreItems: false,
|
|
64
|
+
totalCount: 0,
|
|
65
|
+
cursor: null
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
async getPageExperiment(path) {
|
|
70
|
+
const result = await this.config.apiClient.query({
|
|
71
|
+
query: GET_PAGE_EXPERIMENT,
|
|
72
|
+
variables: {
|
|
73
|
+
path
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
this.checkForErrors(`getPageExperiment:${path}`, result.websiteBuilder.getPageExperiment);
|
|
77
|
+
return result.websiteBuilder.getPageExperiment.data ?? null;
|
|
78
|
+
}
|
|
79
|
+
async getVariantContent(variantId) {
|
|
80
|
+
const result = await this.config.apiClient.query({
|
|
81
|
+
query: GET_VARIANT_CONTENT,
|
|
82
|
+
variables: {
|
|
83
|
+
id: variantId
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
this.checkForErrors(`getVariantContent:${variantId}`, result.websiteBuilder.getVariantContent);
|
|
87
|
+
return result.websiteBuilder.getVariantContent.data ?? null;
|
|
88
|
+
}
|
|
89
|
+
async getExperimentPaused(experimentId) {
|
|
90
|
+
const result = await this.config.apiClient.query({
|
|
91
|
+
query: GET_EXPERIMENT_PAUSED,
|
|
92
|
+
variables: {
|
|
93
|
+
experimentId
|
|
94
|
+
}
|
|
95
|
+
}, {
|
|
96
|
+
noStore: true
|
|
97
|
+
});
|
|
98
|
+
this.checkForErrors(`getExperimentPaused:${experimentId}`, result.websiteBuilder.getExperimentPaused);
|
|
99
|
+
return true === result.websiteBuilder.getExperimentPaused.data;
|
|
100
|
+
}
|
|
101
|
+
checkForErrors(action, data) {
|
|
102
|
+
if (data.error) {
|
|
103
|
+
if (ignoreActions.some((item)=>action.includes(item))) return;
|
|
104
|
+
console.error(`Could not execute "${action}". Reason: ${data.error.message}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export { DefaultDataProvider };
|
|
109
|
+
|
|
110
|
+
//# sourceMappingURL=DefaultDataProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataProviders/DefaultDataProvider.js","sources":["../../src/dataProviders/DefaultDataProvider.ts"],"sourcesContent":["import type {\n GetLayoutParams,\n IDataProvider,\n ListPagesOptions,\n ListPagesResult,\n PublicLayout,\n PublicPage\n} from \"~/types.js\";\nimport type { ActiveExperiment, VariantContent } from \"~/experiments/types.js\";\nimport type { ApiClient } from \"~/dataProviders/ApiClient.js\";\nimport { GET_PAGE_BY_PATH } from \"./GET_PAGE_BY_PATH.js\";\nimport { GET_PAGE_BY_ID } from \"./GET_PAGE_BY_ID.js\";\nimport { GET_LAYOUT_BY_SLUG } from \"./GET_LAYOUT_BY_SLUG.js\";\nimport { LIST_PUBLISHED_PAGES } from \"./LIST_PUBLISHED_PAGES.js\";\nimport { GET_PAGE_EXPERIMENT } from \"./GET_PAGE_EXPERIMENT.js\";\nimport { GET_VARIANT_CONTENT } from \"./GET_VARIANT_CONTENT.js\";\nimport { GET_EXPERIMENT_PAUSED } from \"./GET_EXPERIMENT_PAUSED.js\";\n\ninterface DefaultDataProviderConfig {\n apiClient: ApiClient;\n}\n\nconst ignoreActions = [\".well-known\", \"_next\"];\n\nexport class DefaultDataProvider implements IDataProvider {\n private config: DefaultDataProviderConfig;\n\n constructor(config: DefaultDataProviderConfig) {\n this.config = config;\n }\n\n public async getPageByPath(path: string): Promise<PublicPage | null> {\n const result = await this.config.apiClient.query({\n query: GET_PAGE_BY_PATH,\n variables: {\n path\n }\n });\n\n this.checkForErrors(`getPageByPath:${path}`, result.websiteBuilder.getPageByPath);\n\n return result.websiteBuilder.getPageByPath.data;\n }\n\n public async getPageById(id: string): Promise<PublicPage | null> {\n const result = await this.config.apiClient.query({\n query: GET_PAGE_BY_ID,\n variables: {\n id\n }\n });\n\n this.checkForErrors(\"getPageById\", result.websiteBuilder.getPageById);\n\n return result.websiteBuilder.getPageById.data;\n }\n\n public async getLayoutBySlug(params: GetLayoutParams): Promise<PublicLayout | null> {\n const result = await this.config.apiClient.query({\n query: GET_LAYOUT_BY_SLUG,\n variables: {\n slug: params.slug,\n language: params.language ?? null\n }\n });\n\n this.checkForErrors(\n `getLayoutBySlug:${params.slug}`,\n result.websiteBuilder.getLayoutBySlug\n );\n\n return result.websiteBuilder.getLayoutBySlug.data ?? null;\n }\n\n public async listPages(options?: ListPagesOptions): Promise<ListPagesResult> {\n const { where, ...rest } = options ?? {};\n\n const result = await this.config.apiClient.query({\n query: LIST_PUBLISHED_PAGES,\n variables: {\n where: {\n ...where,\n published: true\n },\n ...rest\n }\n });\n\n this.checkForErrors(\"listPages\", result.websiteBuilder.listPages);\n\n return {\n data: result.websiteBuilder.listPages.data ?? [],\n meta: result.websiteBuilder.listPages.meta ?? {\n hasMoreItems: false,\n totalCount: 0,\n cursor: null\n }\n };\n }\n\n public async getPageExperiment(path: string): Promise<ActiveExperiment | null> {\n const result = await this.config.apiClient.query({\n query: GET_PAGE_EXPERIMENT,\n variables: {\n path\n }\n });\n\n this.checkForErrors(`getPageExperiment:${path}`, result.websiteBuilder.getPageExperiment);\n\n return result.websiteBuilder.getPageExperiment.data ?? null;\n }\n\n public async getVariantContent(variantId: string): Promise<VariantContent | null> {\n const result = await this.config.apiClient.query({\n query: GET_VARIANT_CONTENT,\n variables: {\n id: variantId\n }\n });\n\n this.checkForErrors(\n `getVariantContent:${variantId}`,\n result.websiteBuilder.getVariantContent\n );\n\n return result.websiteBuilder.getVariantContent.data ?? null;\n }\n\n public async getExperimentPaused(experimentId: string): Promise<boolean> {\n // Uncached: the kill-switch must take effect immediately, even while page/variant content\n // stays cached.\n const result = await this.config.apiClient.query(\n {\n query: GET_EXPERIMENT_PAUSED,\n variables: { experimentId }\n },\n { noStore: true }\n );\n\n this.checkForErrors(\n `getExperimentPaused:${experimentId}`,\n result.websiteBuilder.getExperimentPaused\n );\n\n return result.websiteBuilder.getExperimentPaused.data === true;\n }\n\n private checkForErrors(action: string, data: any) {\n if (data.error) {\n // TODO: investigate how these ignored actions make their way to the SDK.\n if (ignoreActions.some(item => action.includes(item))) {\n return;\n }\n console.error(`Could not execute \"${action}\". Reason: ${data.error.message}`);\n }\n }\n}\n"],"names":["ignoreActions","DefaultDataProvider","config","path","result","GET_PAGE_BY_PATH","id","GET_PAGE_BY_ID","params","GET_LAYOUT_BY_SLUG","options","where","rest","LIST_PUBLISHED_PAGES","GET_PAGE_EXPERIMENT","variantId","GET_VARIANT_CONTENT","experimentId","GET_EXPERIMENT_PAUSED","action","data","item","console"],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|