@salesforce/storefront-next-dev 1.0.0-alpha.0 → 1.0.0-alpha.1
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/dist/logger.js +1 -1
- package/dist/mrt/ssr.mjs +51 -51
- package/dist/mrt/ssr.mjs.map +1 -1
- package/dist/mrt/streamingHandler.mjs +57 -57
- package/dist/mrt/streamingHandler.mjs.map +1 -1
- package/dist/react-router/Scripts.d.ts.map +1 -1
- package/dist/react-router/Scripts.js +3 -2
- package/dist/react-router/Scripts.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Scripts.d.ts","names":[],"sources":["../../src/react-router/Scripts.tsx"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"Scripts.d.ts","names":[],"sources":["../../src/react-router/Scripts.tsx"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;;iBA4EgB,OAAA,QAAe,KAAA,CAAM,sBAAsB,aAAmB,kBAAA,CAAA,GAAA,CAAA"}
|
|
@@ -54,13 +54,14 @@ const isSSR = typeof window === "undefined";
|
|
|
54
54
|
* @returns A script element during SSR, or null during client-side rendering
|
|
55
55
|
* @internal
|
|
56
56
|
*/
|
|
57
|
-
const InternalServerScripts = () => {
|
|
57
|
+
const InternalServerScripts = ({ nonce }) => {
|
|
58
58
|
if (!isSSR) return null;
|
|
59
59
|
const bundleId = process.env.BUNDLE_ID || "local";
|
|
60
60
|
const basePath = getBasePath();
|
|
61
61
|
const bundlePath = `${basePath}/mobify/bundle/${bundleId}/client/`;
|
|
62
62
|
return /* @__PURE__ */ jsx("script", {
|
|
63
63
|
id: "sf-next-bundle-config",
|
|
64
|
+
nonce,
|
|
64
65
|
dangerouslySetInnerHTML: { __html: `
|
|
65
66
|
window._BUNDLE_ID = ${JSON.stringify(bundleId)};
|
|
66
67
|
window._BUNDLE_PATH = ${JSON.stringify(bundlePath)};
|
|
@@ -84,7 +85,7 @@ const InternalServerScripts = () => {
|
|
|
84
85
|
* @returns A fragment containing internal bundle scripts and React Router scripts
|
|
85
86
|
*/
|
|
86
87
|
function Scripts(props) {
|
|
87
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(InternalServerScripts, {}), /* @__PURE__ */ jsx(Scripts$1, { ...props })] });
|
|
88
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(InternalServerScripts, { nonce: props.nonce }), /* @__PURE__ */ jsx(Scripts$1, { ...props })] });
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Scripts.js","names":["ReactRouterScripts"],"sources":["../../src/utils/paths.ts","../../src/react-router/Scripts.tsx"],"sourcesContent":["/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n/**\n * Normalize a file path to use forward slashes.\n * On Windows, Node APIs return backslash-separated paths, but ESM import\n * specifiers and Vite module IDs require forward slashes.\n */\nexport function toPosixPath(filePath: string): string {\n return filePath.replace(/\\\\/g, '/');\n}\n\n/**\n * Get the Commerce Cloud API URL from a short code\n */\nexport function getCommerceCloudApiUrl(shortCode: string, proxyHost?: string): string {\n return proxyHost || `https://${shortCode}.api.commercecloud.salesforce.com`;\n}\n\n/**\n * Get the configurable base path for the application.\n * Reads from MRT_ENV_BASE_PATH environment variable.\n *\n * The base path is used for CDN routing to the correct MRT environment.\n * It is prepended to all URLs: page routes, /mobify/bundle/ assets, and /mobify/proxy/api.\n *\n * Validation rules:\n * - Must be a single path segment starting with '/'\n * - Max 63 characters after the leading slash\n * - Only URL-safe characters allowed\n * - Returns empty string if not set\n *\n * @returns The sanitized base path (e.g., '/site-a' or '')\n *\n * @example\n * // No base path configured\n * getBasePath() // → ''\n *\n * // With base path '/storefront'\n * getBasePath() // → '/storefront'\n *\n * // Automatically sanitizes\n * // MRT_ENV_BASE_PATH='storefront/' → '/storefront'\n */\nexport function getBasePath(): string {\n const basePath = process.env.MRT_ENV_BASE_PATH?.trim();\n\n // Return empty string if not set or empty\n if (!basePath) {\n return '';\n }\n\n // Base path prefix must be a single path segment starting with '/', max 63 chars,\n // using only URL-safe characters (alphanumeric, hyphens, underscores, dots, and other safe symbols)\n // This aligns with the regex used by MRT\n if (!/^\\/[a-zA-Z0-9_.+$~\"'@:-]{1,63}$/.test(basePath)) {\n throw new Error(\n `Invalid base path: \"${basePath}\". ` +\n \"Base path must be a single segment starting with '/' (e.g., '/site-a'), \" +\n 'contain only URL-safe characters, and be at most 63 characters after the leading slash.'\n );\n }\n\n return basePath;\n}\n\n/**\n * Get the bundle path for static assets\n */\nexport function getBundlePath(bundleId: string): string {\n const basePath = getBasePath();\n return `${basePath}/mobify/bundle/${bundleId}/client/`;\n}\n","/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Scripts as ReactRouterScripts } from 'react-router';\nimport { getBasePath } from '../utils/paths';\n\n/**\n * Determines if the code is running in a server-side rendering (SSR) environment.\n * Returns true when window is undefined (server), false otherwise (client).\n */\nconst isSSR = typeof window === 'undefined';\n\n/**\n * Internal component that injects bundle configuration scripts during server-side rendering.\n *\n * This component renders a script tag that sets up global bundle variables on the window object,\n * which are used by the client-side application to locate and load the correct bundle assets.\n *\n * The script defines:\n * - `window._BUNDLE_ID`: The unique identifier for the current bundle (from BUNDLE_ID env var, defaults to 'local')\n * - `window._BUNDLE_PATH`: The path to the client bundle assets (e.g., `/mobify/bundle/{bundleId}/client/`)\n *\n * @returns A script element during SSR, or null during client-side rendering\n * @internal\n */\nconst InternalServerScripts = () => {\n if (!isSSR) {\n return null;\n }\n\n const bundleId = process.env.BUNDLE_ID || 'local';\n const basePath = getBasePath();\n const bundlePath = `${basePath}/mobify/bundle/${bundleId}/client/`;\n return (\n <script\n id=\"sf-next-bundle-config\"\n // eslint-disable-next-line react/no-danger\n dangerouslySetInnerHTML={{\n __html: `\n window._BUNDLE_ID = ${JSON.stringify(bundleId)};\n window._BUNDLE_PATH = ${JSON.stringify(bundlePath)};\n window._BASE_PATH = ${JSON.stringify(basePath)};\n `,\n }}\n />\n );\n};\n\n/**\n * Enhanced Scripts component that wraps React Router's Scripts component with Storefront Next-specific functionality.\n *\n * This component extends the standard React Router Scripts component by injecting additional\n * bundle configuration scripts during server-side rendering. It ensures that bundle metadata\n * (ID and path) are available on the client before any other scripts execute.\n *\n * @private This is an internal SDK component — do not import directly.\n * It is automatically applied via the `patchReactRouter` Vite plugin at build time.\n * Customers should use `Scripts` from `react-router` as normal; the plugin transparently\n * substitutes this enhanced version in production builds.\n *\n * @param props - Props passed through to the underlying React Router Scripts component\n * @returns A fragment containing internal bundle scripts and React Router scripts\n */\nexport function Scripts(props: React.ComponentProps<typeof ReactRouterScripts>) {\n return (\n <>\n <InternalServerScripts />\n <ReactRouterScripts {...props} />\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,SAAgB,cAAsB;CAClC,MAAM,WAAW,QAAQ,IAAI,mBAAmB,MAAM;AAGtD,KAAI,CAAC,SACD,QAAO;AAMX,KAAI,CAAC,kCAAkC,KAAK,SAAS,CACjD,OAAM,IAAI,MACN,uBAAuB,SAAS,oKAGnC;AAGL,QAAO;;;;;;;;;ACrDX,MAAM,QAAQ,OAAO,WAAW;;;;;;;;;;;;;;AAehC,MAAM,
|
|
1
|
+
{"version":3,"file":"Scripts.js","names":["ReactRouterScripts"],"sources":["../../src/utils/paths.ts","../../src/react-router/Scripts.tsx"],"sourcesContent":["/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n/**\n * Normalize a file path to use forward slashes.\n * On Windows, Node APIs return backslash-separated paths, but ESM import\n * specifiers and Vite module IDs require forward slashes.\n */\nexport function toPosixPath(filePath: string): string {\n return filePath.replace(/\\\\/g, '/');\n}\n\n/**\n * Get the Commerce Cloud API URL from a short code\n */\nexport function getCommerceCloudApiUrl(shortCode: string, proxyHost?: string): string {\n return proxyHost || `https://${shortCode}.api.commercecloud.salesforce.com`;\n}\n\n/**\n * Get the configurable base path for the application.\n * Reads from MRT_ENV_BASE_PATH environment variable.\n *\n * The base path is used for CDN routing to the correct MRT environment.\n * It is prepended to all URLs: page routes, /mobify/bundle/ assets, and /mobify/proxy/api.\n *\n * Validation rules:\n * - Must be a single path segment starting with '/'\n * - Max 63 characters after the leading slash\n * - Only URL-safe characters allowed\n * - Returns empty string if not set\n *\n * @returns The sanitized base path (e.g., '/site-a' or '')\n *\n * @example\n * // No base path configured\n * getBasePath() // → ''\n *\n * // With base path '/storefront'\n * getBasePath() // → '/storefront'\n *\n * // Automatically sanitizes\n * // MRT_ENV_BASE_PATH='storefront/' → '/storefront'\n */\nexport function getBasePath(): string {\n const basePath = process.env.MRT_ENV_BASE_PATH?.trim();\n\n // Return empty string if not set or empty\n if (!basePath) {\n return '';\n }\n\n // Base path prefix must be a single path segment starting with '/', max 63 chars,\n // using only URL-safe characters (alphanumeric, hyphens, underscores, dots, and other safe symbols)\n // This aligns with the regex used by MRT\n if (!/^\\/[a-zA-Z0-9_.+$~\"'@:-]{1,63}$/.test(basePath)) {\n throw new Error(\n `Invalid base path: \"${basePath}\". ` +\n \"Base path must be a single segment starting with '/' (e.g., '/site-a'), \" +\n 'contain only URL-safe characters, and be at most 63 characters after the leading slash.'\n );\n }\n\n return basePath;\n}\n\n/**\n * Get the bundle path for static assets\n */\nexport function getBundlePath(bundleId: string): string {\n const basePath = getBasePath();\n return `${basePath}/mobify/bundle/${bundleId}/client/`;\n}\n","/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Scripts as ReactRouterScripts } from 'react-router';\nimport { getBasePath } from '../utils/paths';\n\n/**\n * Determines if the code is running in a server-side rendering (SSR) environment.\n * Returns true when window is undefined (server), false otherwise (client).\n */\nconst isSSR = typeof window === 'undefined';\n\n/**\n * Internal component that injects bundle configuration scripts during server-side rendering.\n *\n * This component renders a script tag that sets up global bundle variables on the window object,\n * which are used by the client-side application to locate and load the correct bundle assets.\n *\n * The script defines:\n * - `window._BUNDLE_ID`: The unique identifier for the current bundle (from BUNDLE_ID env var, defaults to 'local')\n * - `window._BUNDLE_PATH`: The path to the client bundle assets (e.g., `/mobify/bundle/{bundleId}/client/`)\n *\n * @returns A script element during SSR, or null during client-side rendering\n * @internal\n */\nconst InternalServerScripts = ({ nonce }: { nonce?: string }) => {\n if (!isSSR) {\n return null;\n }\n\n const bundleId = process.env.BUNDLE_ID || 'local';\n const basePath = getBasePath();\n const bundlePath = `${basePath}/mobify/bundle/${bundleId}/client/`;\n return (\n <script\n id=\"sf-next-bundle-config\"\n nonce={nonce}\n // eslint-disable-next-line react/no-danger\n dangerouslySetInnerHTML={{\n __html: `\n window._BUNDLE_ID = ${JSON.stringify(bundleId)};\n window._BUNDLE_PATH = ${JSON.stringify(bundlePath)};\n window._BASE_PATH = ${JSON.stringify(basePath)};\n `,\n }}\n />\n );\n};\n\n/**\n * Enhanced Scripts component that wraps React Router's Scripts component with Storefront Next-specific functionality.\n *\n * This component extends the standard React Router Scripts component by injecting additional\n * bundle configuration scripts during server-side rendering. It ensures that bundle metadata\n * (ID and path) are available on the client before any other scripts execute.\n *\n * @private This is an internal SDK component — do not import directly.\n * It is automatically applied via the `patchReactRouter` Vite plugin at build time.\n * Customers should use `Scripts` from `react-router` as normal; the plugin transparently\n * substitutes this enhanced version in production builds.\n *\n * @param props - Props passed through to the underlying React Router Scripts component\n * @returns A fragment containing internal bundle scripts and React Router scripts\n */\nexport function Scripts(props: React.ComponentProps<typeof ReactRouterScripts>) {\n return (\n <>\n <InternalServerScripts nonce={props.nonce} />\n <ReactRouterScripts {...props} />\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,SAAgB,cAAsB;CAClC,MAAM,WAAW,QAAQ,IAAI,mBAAmB,MAAM;AAGtD,KAAI,CAAC,SACD,QAAO;AAMX,KAAI,CAAC,kCAAkC,KAAK,SAAS,CACjD,OAAM,IAAI,MACN,uBAAuB,SAAS,oKAGnC;AAGL,QAAO;;;;;;;;;ACrDX,MAAM,QAAQ,OAAO,WAAW;;;;;;;;;;;;;;AAehC,MAAM,yBAAyB,EAAE,YAAgC;AAC7D,KAAI,CAAC,MACD,QAAO;CAGX,MAAM,WAAW,QAAQ,IAAI,aAAa;CAC1C,MAAM,WAAW,aAAa;CAC9B,MAAM,aAAa,GAAG,SAAS,iBAAiB,SAAS;AACzD,QACI,oBAAC;EACG,IAAG;EACI;EAEP,yBAAyB,EACrB,QAAQ;8BACM,KAAK,UAAU,SAAS,CAAC;gCACvB,KAAK,UAAU,WAAW,CAAC;8BAC7B,KAAK,UAAU,SAAS,CAAC;OAE1C;GACH;;;;;;;;;;;;;;;;;AAmBV,SAAgB,QAAQ,OAAwD;AAC5E,QACI,4CACI,oBAAC,yBAAsB,OAAO,MAAM,QAAS,EAC7C,oBAACA,aAAmB,GAAI,QAAS,IAClC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/storefront-next-dev",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.1",
|
|
4
4
|
"description": "Dev and build tools for SFCC Storefront Next",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"react-dom": ">=19.0.0",
|
|
115
115
|
"react-router": ">=7.0.0",
|
|
116
116
|
"vite": ">=7.0.0",
|
|
117
|
-
"@salesforce/storefront-next-runtime": "1.0.0-alpha.
|
|
117
|
+
"@salesforce/storefront-next-runtime": "1.0.0-alpha.1"
|
|
118
118
|
},
|
|
119
119
|
"devDependencies": {
|
|
120
120
|
"@oclif/test": "^4.1.15",
|