diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 67ac1f755b99..860f023a80a8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -84,7 +84,7 @@ jobs: } const results = [ await assertSize('./fixtures/ssg/dist/client', 308), - await assertSize('./fixtures/webstudio-remix-netlify-functions/build/client', 568), + await assertSize('./fixtures/webstudio-remix-netlify-functions/build/client', 396), ] for (const result of results) { if (result.passed) { diff --git a/apps/builder/app/builder/features/settings-panel/resource-panel.tsx b/apps/builder/app/builder/features/settings-panel/resource-panel.tsx index 59a7101858a9..283a60bb24ca 100644 --- a/apps/builder/app/builder/features/settings-panel/resource-panel.tsx +++ b/apps/builder/app/builder/features/settings-panel/resource-panel.tsx @@ -17,8 +17,8 @@ import { generateObjectExpression, isLiteralExpression, parseObjectExpression, - sitemapResourceUrl, } from "@webstudio-is/sdk"; +import { sitemapResourceUrl } from "@webstudio-is/sdk/runtime"; import { Box, Button, diff --git a/apps/builder/app/routes/rest.resources-loader.ts b/apps/builder/app/routes/rest.resources-loader.ts index ee8afafc59c8..07529a9b7412 100644 --- a/apps/builder/app/routes/rest.resources-loader.ts +++ b/apps/builder/app/routes/rest.resources-loader.ts @@ -1,10 +1,7 @@ import { z } from "zod"; import { json, type ActionFunctionArgs } from "@remix-run/server-runtime"; -import { - loadResource, - isLocalResource, - ResourceRequest, -} from "@webstudio-is/sdk"; +import { ResourceRequest } from "@webstudio-is/sdk"; +import { isLocalResource, loadResource } from "@webstudio-is/sdk/runtime"; import { loader as siteMapLoader } from "../shared/$resources/sitemap.xml.server"; import { preventCrossOriginCookie } from "~/services/no-cross-origin-cookie"; import { checkCsrf } from "~/services/csrf-session.server"; diff --git a/apps/builder/app/shared/nano-states/props.ts b/apps/builder/app/shared/nano-states/props.ts index dbf563a645df..dc30c095a4ad 100644 --- a/apps/builder/app/shared/nano-states/props.ts +++ b/apps/builder/app/shared/nano-states/props.ts @@ -9,12 +9,14 @@ import type { ImageAsset, } from "@webstudio-is/sdk"; import { - createJsonStringifyProxy, decodeDataSourceVariable, encodeDataSourceVariable, - isPlainObject, transpileExpression, } from "@webstudio-is/sdk"; +import { + createJsonStringifyProxy, + isPlainObject, +} from "@webstudio-is/sdk/runtime"; import { collectionComponent, normalizeProps, diff --git a/fixtures/ssg-netlify-by-project-id/pages/index/+data.ts b/fixtures/ssg-netlify-by-project-id/pages/index/+data.ts index c6c77c36bb06..29c99c40685b 100644 --- a/fixtures/ssg-netlify-by-project-id/pages/index/+data.ts +++ b/fixtures/ssg-netlify-by-project-id/pages/index/+data.ts @@ -1,6 +1,6 @@ import type { PageContextServer } from "vike/types"; import { redirect } from "vike/abort"; -import { loadResources } from "@webstudio-is/sdk"; +import { loadResources } from "@webstudio-is/sdk/runtime"; import { getPageMeta, getResources, diff --git a/fixtures/ssg/pages/another-page/+data.ts b/fixtures/ssg/pages/another-page/+data.ts index bb0883e59668..6b4534197b6e 100644 --- a/fixtures/ssg/pages/another-page/+data.ts +++ b/fixtures/ssg/pages/another-page/+data.ts @@ -1,6 +1,6 @@ import type { PageContextServer } from "vike/types"; import { redirect } from "vike/abort"; -import { loadResources } from "@webstudio-is/sdk"; +import { loadResources } from "@webstudio-is/sdk/runtime"; import { getPageMeta, getResources, diff --git a/fixtures/ssg/pages/index/+data.ts b/fixtures/ssg/pages/index/+data.ts index c6c77c36bb06..29c99c40685b 100644 --- a/fixtures/ssg/pages/index/+data.ts +++ b/fixtures/ssg/pages/index/+data.ts @@ -1,6 +1,6 @@ import type { PageContextServer } from "vike/types"; import { redirect } from "vike/abort"; -import { loadResources } from "@webstudio-is/sdk"; +import { loadResources } from "@webstudio-is/sdk/runtime"; import { getPageMeta, getResources, diff --git a/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx b/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx index dfbcf6458eaa..96b66e25b8d3 100644 --- a/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx +++ b/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx @@ -15,7 +15,7 @@ import { loadResources, formIdFieldName, formBotFieldName, -} from "@webstudio-is/sdk"; +} from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page, diff --git a/fixtures/webstudio-cloudflare-template/app/routes/_index.tsx b/fixtures/webstudio-cloudflare-template/app/routes/_index.tsx index d89665fc9df5..83e8ee2cfd3a 100644 --- a/fixtures/webstudio-cloudflare-template/app/routes/_index.tsx +++ b/fixtures/webstudio-cloudflare-template/app/routes/_index.tsx @@ -15,7 +15,7 @@ import { loadResources, formIdFieldName, formBotFieldName, -} from "@webstudio-is/sdk"; +} from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page, diff --git a/fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsx b/fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsx index 55291b651481..bace806e6e14 100644 --- a/fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsx +++ b/fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsx @@ -15,7 +15,7 @@ import { loadResources, formIdFieldName, formBotFieldName, -} from "@webstudio-is/sdk"; +} from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page, diff --git a/fixtures/webstudio-custom-template/app/routes/[sitemap.xml]._index.tsx b/fixtures/webstudio-custom-template/app/routes/[sitemap.xml]._index.tsx index 49a6d5ec41f7..73ec224a673a 100644 --- a/fixtures/webstudio-custom-template/app/routes/[sitemap.xml]._index.tsx +++ b/fixtures/webstudio-custom-template/app/routes/[sitemap.xml]._index.tsx @@ -1,6 +1,6 @@ import { renderToString } from "react-dom/server"; import { type LoaderFunctionArgs, redirect } from "@remix-run/server-runtime"; -import { isLocalResource, loadResources } from "@webstudio-is/sdk"; +import { isLocalResource, loadResources } from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page } from "../__generated__/[sitemap.xml]._index"; import { diff --git a/fixtures/webstudio-custom-template/app/routes/[world]._index.tsx b/fixtures/webstudio-custom-template/app/routes/[world]._index.tsx index 65ef6e449d18..cabe7ad15641 100644 --- a/fixtures/webstudio-custom-template/app/routes/[world]._index.tsx +++ b/fixtures/webstudio-custom-template/app/routes/[world]._index.tsx @@ -15,7 +15,7 @@ import { loadResources, formIdFieldName, formBotFieldName, -} from "@webstudio-is/sdk"; +} from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page, diff --git a/fixtures/webstudio-custom-template/app/routes/_index.tsx b/fixtures/webstudio-custom-template/app/routes/_index.tsx index d89665fc9df5..83e8ee2cfd3a 100644 --- a/fixtures/webstudio-custom-template/app/routes/_index.tsx +++ b/fixtures/webstudio-custom-template/app/routes/_index.tsx @@ -15,7 +15,7 @@ import { loadResources, formIdFieldName, formBotFieldName, -} from "@webstudio-is/sdk"; +} from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page, diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[another-page]._index.tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[another-page]._index.tsx index dfbcf6458eaa..96b66e25b8d3 100644 --- a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[another-page]._index.tsx +++ b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[another-page]._index.tsx @@ -15,7 +15,7 @@ import { loadResources, formIdFieldName, formBotFieldName, -} from "@webstudio-is/sdk"; +} from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page, diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsx index d89665fc9df5..83e8ee2cfd3a 100644 --- a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsx +++ b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsx @@ -15,7 +15,7 @@ import { loadResources, formIdFieldName, formBotFieldName, -} from "@webstudio-is/sdk"; +} from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page, diff --git a/fixtures/webstudio-remix-netlify-functions/app/routes/[another-page]._index.tsx b/fixtures/webstudio-remix-netlify-functions/app/routes/[another-page]._index.tsx index dfbcf6458eaa..96b66e25b8d3 100644 --- a/fixtures/webstudio-remix-netlify-functions/app/routes/[another-page]._index.tsx +++ b/fixtures/webstudio-remix-netlify-functions/app/routes/[another-page]._index.tsx @@ -15,7 +15,7 @@ import { loadResources, formIdFieldName, formBotFieldName, -} from "@webstudio-is/sdk"; +} from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page, diff --git a/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsx b/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsx index d89665fc9df5..83e8ee2cfd3a 100644 --- a/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsx +++ b/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsx @@ -15,7 +15,7 @@ import { loadResources, formIdFieldName, formBotFieldName, -} from "@webstudio-is/sdk"; +} from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page, diff --git a/fixtures/webstudio-remix-vercel/app/routes/[_route_with_symbols_]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[_route_with_symbols_]._index.tsx index 4b68bae25542..21e182ee53a3 100644 --- a/fixtures/webstudio-remix-vercel/app/routes/[_route_with_symbols_]._index.tsx +++ b/fixtures/webstudio-remix-vercel/app/routes/[_route_with_symbols_]._index.tsx @@ -15,7 +15,7 @@ import { loadResources, formIdFieldName, formBotFieldName, -} from "@webstudio-is/sdk"; +} from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page, diff --git a/fixtures/webstudio-remix-vercel/app/routes/[class-names]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[class-names]._index.tsx index 9b7e92450e9c..45f7ed05a6e0 100644 --- a/fixtures/webstudio-remix-vercel/app/routes/[class-names]._index.tsx +++ b/fixtures/webstudio-remix-vercel/app/routes/[class-names]._index.tsx @@ -15,7 +15,7 @@ import { loadResources, formIdFieldName, formBotFieldName, -} from "@webstudio-is/sdk"; +} from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page, diff --git a/fixtures/webstudio-remix-vercel/app/routes/[expressions]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[expressions]._index.tsx index b6ed3fb8ce5d..02e33f4e63b9 100644 --- a/fixtures/webstudio-remix-vercel/app/routes/[expressions]._index.tsx +++ b/fixtures/webstudio-remix-vercel/app/routes/[expressions]._index.tsx @@ -15,7 +15,7 @@ import { loadResources, formIdFieldName, formBotFieldName, -} from "@webstudio-is/sdk"; +} from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page, diff --git a/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsx index de029ac8c6b8..6266caa9509c 100644 --- a/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsx +++ b/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsx @@ -15,7 +15,7 @@ import { loadResources, formIdFieldName, formBotFieldName, -} from "@webstudio-is/sdk"; +} from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page, diff --git a/fixtures/webstudio-remix-vercel/app/routes/[heading-with-id]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[heading-with-id]._index.tsx index 609c4c131e0a..540dbedd5748 100644 --- a/fixtures/webstudio-remix-vercel/app/routes/[heading-with-id]._index.tsx +++ b/fixtures/webstudio-remix-vercel/app/routes/[heading-with-id]._index.tsx @@ -15,7 +15,7 @@ import { loadResources, formIdFieldName, formBotFieldName, -} from "@webstudio-is/sdk"; +} from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page, diff --git a/fixtures/webstudio-remix-vercel/app/routes/[nested].[nested-page]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[nested].[nested-page]._index.tsx index b308ee318234..a3bad0afa3b9 100644 --- a/fixtures/webstudio-remix-vercel/app/routes/[nested].[nested-page]._index.tsx +++ b/fixtures/webstudio-remix-vercel/app/routes/[nested].[nested-page]._index.tsx @@ -15,7 +15,7 @@ import { loadResources, formIdFieldName, formBotFieldName, -} from "@webstudio-is/sdk"; +} from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page, diff --git a/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsx index 99e1f93eff01..3ae44e0f5692 100644 --- a/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsx +++ b/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsx @@ -15,7 +15,7 @@ import { loadResources, formIdFieldName, formBotFieldName, -} from "@webstudio-is/sdk"; +} from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page, diff --git a/fixtures/webstudio-remix-vercel/app/routes/[resources]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[resources]._index.tsx index 5316bee00767..e65aa5103718 100644 --- a/fixtures/webstudio-remix-vercel/app/routes/[resources]._index.tsx +++ b/fixtures/webstudio-remix-vercel/app/routes/[resources]._index.tsx @@ -15,7 +15,7 @@ import { loadResources, formIdFieldName, formBotFieldName, -} from "@webstudio-is/sdk"; +} from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page, diff --git a/fixtures/webstudio-remix-vercel/app/routes/[sitemap.xml]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[sitemap.xml]._index.tsx index 49a6d5ec41f7..73ec224a673a 100644 --- a/fixtures/webstudio-remix-vercel/app/routes/[sitemap.xml]._index.tsx +++ b/fixtures/webstudio-remix-vercel/app/routes/[sitemap.xml]._index.tsx @@ -1,6 +1,6 @@ import { renderToString } from "react-dom/server"; import { type LoaderFunctionArgs, redirect } from "@remix-run/server-runtime"; -import { isLocalResource, loadResources } from "@webstudio-is/sdk"; +import { isLocalResource, loadResources } from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page } from "../__generated__/[sitemap.xml]._index"; import { diff --git a/fixtures/webstudio-remix-vercel/app/routes/_index.tsx b/fixtures/webstudio-remix-vercel/app/routes/_index.tsx index d89665fc9df5..83e8ee2cfd3a 100644 --- a/fixtures/webstudio-remix-vercel/app/routes/_index.tsx +++ b/fixtures/webstudio-remix-vercel/app/routes/_index.tsx @@ -15,7 +15,7 @@ import { loadResources, formIdFieldName, formBotFieldName, -} from "@webstudio-is/sdk"; +} from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page, diff --git a/packages/cli/templates/defaults/app/route-templates/html.tsx b/packages/cli/templates/defaults/app/route-templates/html.tsx index e118f479705c..62a37df37bbd 100644 --- a/packages/cli/templates/defaults/app/route-templates/html.tsx +++ b/packages/cli/templates/defaults/app/route-templates/html.tsx @@ -15,7 +15,7 @@ import { loadResources, formIdFieldName, formBotFieldName, -} from "@webstudio-is/sdk"; +} from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page, diff --git a/packages/cli/templates/defaults/app/route-templates/xml.tsx b/packages/cli/templates/defaults/app/route-templates/xml.tsx index 4a54d734e8a7..91e0dd4a682f 100644 --- a/packages/cli/templates/defaults/app/route-templates/xml.tsx +++ b/packages/cli/templates/defaults/app/route-templates/xml.tsx @@ -1,6 +1,6 @@ import { renderToString } from "react-dom/server"; import { type LoaderFunctionArgs, redirect } from "@remix-run/server-runtime"; -import { isLocalResource, loadResources } from "@webstudio-is/sdk"; +import { isLocalResource, loadResources } from "@webstudio-is/sdk/runtime"; import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; import { Page } from "__CLIENT__"; import { getPageMeta, getRemixParams, getResources } from "__SERVER__"; diff --git a/packages/cli/templates/ssg/app/route-templates/html/+data.ts b/packages/cli/templates/ssg/app/route-templates/html/+data.ts index 30a19f54f6de..90d61539b4ab 100644 --- a/packages/cli/templates/ssg/app/route-templates/html/+data.ts +++ b/packages/cli/templates/ssg/app/route-templates/html/+data.ts @@ -1,6 +1,6 @@ import type { PageContextServer } from "vike/types"; import { redirect } from "vike/abort"; -import { loadResources } from "@webstudio-is/sdk"; +import { loadResources } from "@webstudio-is/sdk/runtime"; import { getPageMeta, getResources } from "__SERVER__"; export const data = async (pageContext: PageContextServer) => { diff --git a/packages/react-sdk/src/context.tsx b/packages/react-sdk/src/context.tsx index a8eb87933545..bfac2c13ad60 100644 --- a/packages/react-sdk/src/context.tsx +++ b/packages/react-sdk/src/context.tsx @@ -1,6 +1,9 @@ import { createContext, useContext, useMemo } from "react"; import type { ImageLoader } from "@webstudio-is/image"; -import { createJsonStringifyProxy, isPlainObject } from "@webstudio-is/sdk"; +import { + createJsonStringifyProxy, + isPlainObject, +} from "@webstudio-is/sdk/runtime"; export type Params = { /** diff --git a/packages/react-sdk/src/variable-state.tsx b/packages/react-sdk/src/variable-state.tsx index 13421aee8589..c8b3e77905e2 100644 --- a/packages/react-sdk/src/variable-state.tsx +++ b/packages/react-sdk/src/variable-state.tsx @@ -1,5 +1,8 @@ -import { createJsonStringifyProxy, isPlainObject } from "@webstudio-is/sdk"; import { useState, useMemo, type Dispatch, type SetStateAction } from "react"; +import { + createJsonStringifyProxy, + isPlainObject, +} from "@webstudio-is/sdk/runtime"; export const useVariableState = ( initialState: S | (() => S) diff --git a/packages/sdk-components-react-remix/src/webhook-form.tsx b/packages/sdk-components-react-remix/src/webhook-form.tsx index 0198d2c04dbd..4a30631c8ed6 100644 --- a/packages/sdk-components-react-remix/src/webhook-form.tsx +++ b/packages/sdk-components-react-remix/src/webhook-form.tsx @@ -6,7 +6,7 @@ import { useEffect, } from "react"; import { useFetcher, type Fetcher, type FormProps } from "@remix-run/react"; -import { formIdFieldName, formBotFieldName } from "@webstudio-is/sdk"; +import { formIdFieldName, formBotFieldName } from "@webstudio-is/sdk/runtime"; export const defaultTag = "form"; diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 538cc8ff8155..f951ca60e745 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -12,6 +12,11 @@ "types": "./lib/types/index.d.ts", "import": "./lib/index.js" }, + "./runtime": { + "webstudio": "./src/runtime.ts", + "types": "./lib/types/runtime.d.ts", + "import": "./lib/runtime.js" + }, "./normalize.css": { "webstudio": "./src/__generated__/normalize.css.ts", "types": "./lib/types/__generated__/normalize.css.d.ts", @@ -30,7 +35,7 @@ "typecheck": "tsc", "test": "vitest run", "build:normalize.css": "tsx --conditions=webstudio ./scripts/normalize.css.ts && prettier --write src/__generated__/normalize.css.ts", - "build": "rm -rf lib && esbuild src/index.ts src/__generated__/normalize.css.ts --outdir=lib --bundle --format=esm --packages=external", + "build": "rm -rf lib && esbuild src/index.ts src/runtime.ts src/__generated__/normalize.css.ts --outdir=lib --bundle --format=esm --packages=external", "dts": "tsc --project tsconfig.dts.json" }, "dependencies": { diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index 1566f0208043..6bbb8dddd645 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -14,10 +14,7 @@ export * from "./schema/webstudio"; export * from "./instances-utils"; export * from "./page-utils"; export * from "./scope"; -export * from "./resource-loader"; export * from "./expression"; export * from "./resources-generator"; export * from "./page-meta-generator"; export * from "./url-pattern"; -export * from "./form-fields"; -export * from "./to-string"; diff --git a/packages/sdk/src/resource-loader.ts b/packages/sdk/src/resource-loader.ts index 44576caa0891..dd2f3504b121 100644 --- a/packages/sdk/src/resource-loader.ts +++ b/packages/sdk/src/resource-loader.ts @@ -1,5 +1,22 @@ import type { ResourceRequest } from "./schema/resources"; +const LOCAL_RESOURCE_PREFIX = "$resources"; + +/** + * Prevents fetch cycles by prefixing local resources. + */ +export const isLocalResource = (pathname: string, resourceName?: string) => { + const segments = pathname.split("/").filter(Boolean); + + if (resourceName === undefined) { + return segments[0] === LOCAL_RESOURCE_PREFIX; + } + + return segments.join("/") === `${LOCAL_RESOURCE_PREFIX}/${resourceName}`; +}; + +export const sitemapResourceUrl = `/${LOCAL_RESOURCE_PREFIX}/sitemap.xml`; + export const loadResource = async ( customFetch: typeof fetch, resourceRequest: ResourceRequest diff --git a/packages/sdk/src/runtime.ts b/packages/sdk/src/runtime.ts new file mode 100644 index 000000000000..5bf9b07feac2 --- /dev/null +++ b/packages/sdk/src/runtime.ts @@ -0,0 +1,3 @@ +export * from "./resource-loader"; +export * from "./to-string"; +export * from "./form-fields"; diff --git a/packages/sdk/src/schema/resources.ts b/packages/sdk/src/schema/resources.ts index 057f68ffb6f7..8f9a39c3e9dd 100644 --- a/packages/sdk/src/schema/resources.ts +++ b/packages/sdk/src/schema/resources.ts @@ -44,20 +44,3 @@ export type ResourceRequest = z.infer; export const Resources = z.map(ResourceId, Resource); export type Resources = z.infer; - -const LOCAL_RESOURCE_PREFIX = "$resources"; - -/** - * Prevents fetch cycles by prefixing local resources. - */ -export const isLocalResource = (pathname: string, resourceName?: string) => { - const segments = pathname.split("/").filter(Boolean); - - if (resourceName === undefined) { - return segments[0] === LOCAL_RESOURCE_PREFIX; - } - - return segments.join("/") === `${LOCAL_RESOURCE_PREFIX}/${resourceName}`; -}; - -export const sitemapResourceUrl = `/${LOCAL_RESOURCE_PREFIX}/sitemap.xml`;