@appdirect/sfb-toolkit 5.0.9 → 6.0.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.
Files changed (119) hide show
  1. package/.eslintrc +35 -35
  2. package/CHANGELOG.md +45 -0
  3. package/Dockerfile +2 -1
  4. package/agent/.cursor/rules/sfb-storefront.mdc +18 -0
  5. package/agent/.cursor/skills/sfb-custom-components/COMPONENT-CATALOG.md +130 -0
  6. package/agent/.cursor/skills/sfb-custom-components/SKILL.md +44 -0
  7. package/agent/.cursor/skills/sfb-localization-settings/SKILL.md +99 -0
  8. package/agent/.cursor/skills/sfb-theme-customize/SKILL.md +25 -0
  9. package/agent/.cursor/skills/sfb-toolkit-commands/SKILL.md +35 -0
  10. package/agent/AGENTS.md +222 -0
  11. package/agent/CLAUDE.md +20 -0
  12. package/bin/index.js +82 -100
  13. package/coverage/clover.xml +1937 -333
  14. package/coverage/coverage-final.json +41 -20
  15. package/coverage/lcov-report/{controllers/controllers-utils → config}/index.html +19 -19
  16. package/coverage/lcov-report/config/index.js.html +124 -0
  17. package/coverage/lcov-report/index.html +108 -78
  18. package/coverage/lcov-report/{constants → src/constants}/customUserAttributesMock.js.html +12 -12
  19. package/coverage/lcov-report/{constants → src/constants}/index.html +10 -10
  20. package/coverage/lcov-report/{constants → src/constants}/pageUrls.js.html +14 -14
  21. package/coverage/lcov-report/{constants → src/constants}/userMock.js.html +13 -13
  22. package/coverage/lcov-report/{controllers → src/controllers}/controllers-utils/assetsUtils.js.html +20 -20
  23. package/coverage/lcov-report/src/controllers/controllers-utils/index.html +131 -0
  24. package/coverage/lcov-report/src/controllers/controllers-utils/locale.js.html +115 -0
  25. package/coverage/lcov-report/{controllers → src/controllers}/data-filters/bootstrap-data-filter.js.html +15 -15
  26. package/coverage/lcov-report/{controllers → src/controllers}/data-filters/call-to-actions-filter.js.html +22 -22
  27. package/coverage/lcov-report/{controllers → src/controllers}/data-filters/index.html +37 -22
  28. package/coverage/lcov-report/src/controllers/data-filters/media-url-filter.js.html +394 -0
  29. package/coverage/lcov-report/{controllers → src/controllers}/index.html +27 -27
  30. package/coverage/lcov-report/{controllers → src/controllers}/index.js.html +159 -126
  31. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/base/ResultItem.js.html +43 -43
  32. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/base/SearchBar.js.html +22 -22
  33. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/base/index.html +28 -28
  34. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/base/item.js.html +28 -28
  35. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/container.js.html +31 -31
  36. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/data-view.js.html +29 -29
  37. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/header-view.js.html +35 -38
  38. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/index.html +45 -45
  39. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/search.js.html +54 -54
  40. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/constants/index.html +22 -22
  41. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/constants/pageUrl.js.html +17 -17
  42. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/constants/roleType.js.html +14 -14
  43. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/constants/searchType.js.html +17 -17
  44. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/utils/debounce.js.html +15 -15
  45. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/utils/index.html +20 -20
  46. package/coverage/lcov-report/{middlewares → src/middlewares}/config.js.html +11 -11
  47. package/coverage/lcov-report/{middlewares → src/middlewares}/index.html +10 -10
  48. package/coverage/lcov-report/{tools → src/routes}/index.html +30 -30
  49. package/coverage/lcov-report/src/routes/media-proxy.js.html +613 -0
  50. package/coverage/lcov-report/src/tools/compile-styles.js.html +1018 -0
  51. package/coverage/lcov-report/src/tools/custom-components-export-compat-loader.js.html +745 -0
  52. package/coverage/lcov-report/src/tools/index.html +371 -0
  53. package/coverage/lcov-report/src/tools/prompt-questions.js.html +1117 -0
  54. package/coverage/lcov-report/{tools → src/tools}/proxy-fetch.js.html +15 -15
  55. package/coverage/lcov-report/src/tools/resolve-components-react.js.html +457 -0
  56. package/coverage/lcov-report/src/tools/sass-legacy-compat.js.html +1192 -0
  57. package/coverage/lcov-report/src/tools/toolkit-cli-argv.js.html +226 -0
  58. package/coverage/lcov-report/src/tools/toolkit-common-fun.js.html +1402 -0
  59. package/coverage/lcov-report/src/tools/toolkit-common-vars-namespace.js.html +403 -0
  60. package/coverage/lcov-report/src/tools/toolkit-common-vars.js.html +283 -0
  61. package/coverage/lcov-report/src/tools/toolkit-components-fun.js.html +1237 -0
  62. package/coverage/lcov-report/src/tools/toolkit-components-vars.js.html +232 -0
  63. package/coverage/lcov-report/src/tools/toolkit-install-agent-guidance.js.html +439 -0
  64. package/coverage/lcov-report/src/tools/toolkit-live-reload.js.html +688 -0
  65. package/coverage/lcov-report/src/tools/toolkit-path.js.html +184 -0
  66. package/coverage/lcov-report/src/tools/toolkit-spawn.js.html +199 -0
  67. package/coverage/lcov-report/src/tools/toolkit-v6-theme-risk.js.html +1039 -0
  68. package/coverage/lcov-report/src/tools/toolkit-zip-utils.js.html +190 -0
  69. package/coverage/lcov.info +3387 -727
  70. package/index.js +40 -20
  71. package/npm-shrinkwrap.json +5026 -15490
  72. package/package.json +49 -40
  73. package/readme.md +20 -1
  74. package/rspack-components.config.cjs +81 -0
  75. package/rspack-components.config.prod.cjs +71 -0
  76. package/rspack.config.cjs +25 -0
  77. package/rspack.shared.cjs +164 -0
  78. package/src/controllers/controllers-utils/locale.js +10 -0
  79. package/src/controllers/data-filters/media-url-filter.js +103 -0
  80. package/src/controllers/index.js +15 -4
  81. package/src/front-end-utils/dist/toolbar.bundle.js +1 -2
  82. package/src/front-end-utils/src/components/header-view.js +0 -1
  83. package/src/routes/index.js +2 -0
  84. package/src/routes/media-proxy.js +176 -0
  85. package/src/tools/compile-styles.js +311 -0
  86. package/src/tools/compiler-components-prod.js +32 -21
  87. package/src/tools/compiler-css.js +7 -7
  88. package/src/tools/custom-components-export-compat-loader.js +220 -0
  89. package/src/tools/resolve-components-react.js +124 -0
  90. package/src/tools/sass-legacy-compat.js +369 -0
  91. package/src/tools/toolkit-checkout.js +3 -6
  92. package/src/tools/toolkit-cli-argv.js +47 -0
  93. package/src/tools/toolkit-common-fun.js +149 -31
  94. package/src/tools/toolkit-common-utils.js +5 -3
  95. package/src/tools/toolkit-common-vars.js +4 -3
  96. package/src/tools/toolkit-components-copy.js +6 -4
  97. package/src/tools/toolkit-components-fun.js +6 -4
  98. package/src/tools/toolkit-config-setup.js +2 -1
  99. package/src/tools/toolkit-create.js +5 -7
  100. package/src/tools/toolkit-import.js +5 -6
  101. package/src/tools/toolkit-install-agent-guidance-cli.js +24 -0
  102. package/src/tools/toolkit-install-agent-guidance.js +118 -0
  103. package/src/tools/toolkit-install.js +8 -8
  104. package/src/tools/toolkit-live-reload.js +201 -0
  105. package/src/tools/toolkit-package.js +25 -7
  106. package/src/tools/toolkit-path.js +33 -0
  107. package/src/tools/toolkit-setup-e2e.js +2 -1
  108. package/src/tools/toolkit-setup.js +5 -1
  109. package/src/tools/toolkit-spawn.js +38 -0
  110. package/src/tools/toolkit-start.js +98 -54
  111. package/src/tools/toolkit-storybook.js +38 -19
  112. package/src/tools/toolkit-update.js +5 -3
  113. package/src/tools/toolkit-v6-theme-risk.js +318 -0
  114. package/themes-param.json +1 -0
  115. package/src/front-end-utils/dist/toolbar.bundle.js.LICENSE.txt +0 -52
  116. package/src/tools/gulp-tasks.js +0 -80
  117. package/webpack-components.config.cjs +0 -123
  118. package/webpack-components.config.prod.cjs +0 -113
  119. package/webpack.config.cjs +0 -25
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appdirect/sfb-toolkit",
3
- "version": "5.0.9",
3
+ "version": "6.0.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -21,7 +21,27 @@
21
21
  "**/src/tests/**/*test.js?(x)"
22
22
  ],
23
23
  "transform": {
24
- "^.+\\.js?$": "babel-jest"
24
+ "^.+\\.(js|jsx)$": [
25
+ "@swc/jest",
26
+ {
27
+ "jsc": {
28
+ "parser": {
29
+ "syntax": "ecmascript",
30
+ "jsx": true
31
+ },
32
+ "transform": {
33
+ "react": {
34
+ "runtime": "classic"
35
+ }
36
+ },
37
+ "target": "es2020"
38
+ },
39
+ "module": {
40
+ "type": "commonjs",
41
+ "importInterop": "babel"
42
+ }
43
+ }
44
+ ]
25
45
  },
26
46
  "transformIgnorePatterns": [
27
47
  "/node_modules/(?!(react-syntax-highlighter)/)"
@@ -33,7 +53,7 @@
33
53
  "license": "SEE LICENSE IN https://help.appdirect.com/sfb-eula.pdf",
34
54
  "scripts": {
35
55
  "test": "jest --coverage",
36
- "buildToolbar": "webpack --config ./webpack.config.cjs --mode production",
56
+ "buildToolbar": "rspack --config ./rspack.config.cjs --mode production",
37
57
  "dev": "RUN_ENV=dev concurrently \"npm run watchCSS\" \"npm run devserver\"",
38
58
  "start": "RUN_ENV=test concurrently \"npm run watchCSS\" \"npm run devserver\"",
39
59
  "devserver": "nodemon ./index.js",
@@ -56,50 +76,43 @@
56
76
  },
57
77
  "dependencies": {
58
78
  "@appdirect/public-custom-app-ui": "^0.0.31",
59
- "@appdirect/sfb-theme-plaza": "0.0.90",
79
+ "@appdirect/sfb-theme-classic": "0.0.27",
80
+ "@appdirect/sfb-theme-plaza": "0.0.95",
60
81
  "@appdirect/storefront-utils": "latest",
61
- "@babel/core": "^7.19.1",
62
- "@babel/plugin-proposal-class-properties": "^7.18.6",
63
- "@babel/plugin-transform-runtime": "^7.19.1",
64
- "@babel/preset-env": "^7.19.1",
65
- "@babel/preset-react": "^7.18.6",
66
82
  "@babel/runtime": "^7.19.0",
67
83
  "@fortawesome/fontawesome": "^1.1.8",
68
84
  "@fortawesome/fontawesome-svg-core": "^6.2.0",
69
85
  "@fortawesome/free-solid-svg-icons": "^6.2.0",
70
86
  "@fortawesome/react-fontawesome": "0.2.0",
87
+ "@rspack/cli": "^2.3.1",
88
+ "@rspack/core": "^2.3.1",
89
+ "@rspack/dev-middleware": "^2.0.6",
90
+ "@swc/core": "^1.16.22",
71
91
  "app-root-path": "^3.1.0",
72
92
  "archiver": "^5.3.1",
73
- "babel-loader": "^8.2.5",
74
- "babel-preset-minify": "^0.5.2",
75
93
  "body-parser": "^1.20.0",
76
94
  "chalk": "^4.1.2",
77
95
  "cheerio": "^1.0.0-rc.12",
96
+ "chokidar": "^3.6.0",
78
97
  "colors": "^1.4.0",
79
98
  "commander": "^9.4.0",
80
- "concurrently": "^7.4.0",
99
+ "concurrently": "^10.0.7",
81
100
  "cookie-parser": "^1.4.6",
82
- "css-loader": "^6.7.1",
101
+ "css-loader": "^7.1.5",
83
102
  "directory-tree": "^3.3.1",
84
103
  "express": "^4.18.1",
85
104
  "extract-zip": "^2.0.1",
86
105
  "fs-extra": "^10.1.0",
87
106
  "glob": "^8.0.3",
88
- "gulp": "^4.0.2",
89
- "gulp-concat": "^2.6.1",
90
- "gulp-sass": "^5.1.0",
91
- "gulp-sourcemaps": "^3.0.0",
92
107
  "inquirer": "^8.2.4",
93
- "install": "^0.13.0",
94
108
  "js-cookie": "^3.0.1",
95
109
  "js-yaml": "^4.1.0",
96
110
  "lodash": "^4.17.21",
97
111
  "message-format-inline": "^1.0.4",
98
- "mini-css-extract-plugin": "^2.6.1",
99
112
  "minimist": "^1.2.6",
100
- "moment": "^2.29.4",
113
+ "moment": "^2.31.0",
101
114
  "node-fetch": "^2.7.0",
102
- "nodemon": "^2.0.20",
115
+ "nodemon": "^3.1.14",
103
116
  "nunjucks": "^3.2.3",
104
117
  "nunjucks-intl": "^1.0.3",
105
118
  "object-assign-deep": "^0.4.0",
@@ -107,35 +120,32 @@
107
120
  "prop-types": "^15.8.1",
108
121
  "proxy-agent": "^6.3.1",
109
122
  "querystrings": "^0.4.0",
110
- "react": "16.14.0",
111
- "react-dom": "16.14.0",
123
+ "react": "18.3.1",
124
+ "react-16": "npm:react@16.14.0",
125
+ "react-dom": "18.3.1",
126
+ "react-dom-16": "npm:react-dom@16.14.0",
112
127
  "react-json-view": "^1.21.3",
113
128
  "react-select": "^4.3.1",
114
129
  "react-syntax-highlighter": "^15.5.0",
115
130
  "replace-in-file": "^6.3.5",
116
131
  "rimraf": "^4.1.3",
117
- "sass": "^1.55.0",
118
- "scheduler": "^0.19.1",
132
+ "sass-embedded": "1.89.2",
133
+ "sass-loader": "^16.0.8",
134
+ "scheduler": "0.23.2",
135
+ "scheduler-16": "npm:scheduler@0.19.1",
119
136
  "seamless-immutable": "^7.1.4",
120
137
  "snapstub": "^5.0.1",
121
138
  "styled-components": "^5.3.5",
122
139
  "tslib": "^2.4.0",
123
140
  "urijs": "^1.19.11",
124
- "watch": "^1.0.2",
125
- "webpack": "^5.74.0",
126
- "webpack-cli": "^4.10.0",
127
- "webpack-dev-middleware": "^5.3.3",
128
- "webpack-hot-middleware": "^2.25.2",
129
- "@appdirect/sfb-theme-classic": "0.0.27"
141
+ "webpack-hot-middleware": "^2.26.1"
130
142
  },
131
143
  "devDependencies": {
132
- "@babel/plugin-transform-modules-commonjs": "^7.18.6",
133
- "@types/enzyme-adapter-react-16": "^1.0.6",
144
+ "@swc/jest": "^0.2.39",
145
+ "@testing-library/jest-dom": "^5.17.0",
146
+ "@testing-library/react": "^12.1.5",
147
+ "@testing-library/user-event": "^13.5.0",
134
148
  "assert": "^2.0.0",
135
- "babel-eslint": "^8.2.3",
136
- "babel-jest": "^29.0.3",
137
- "enzyme": "^3.11.0",
138
- "enzyme-adapter-react-16": "^1.15.6",
139
149
  "eslint": "^8.23.1",
140
150
  "eslint-config-airbnb": "^19.0.4",
141
151
  "eslint-config-prettier": "^8.5.0",
@@ -148,14 +158,13 @@
148
158
  "jest-environment-jsdom": "^29.0.3",
149
159
  "jest-fetch-mock": "^3.0.3",
150
160
  "mock-require": "^3.0.3",
151
- "npm-run-all": "^4.1.5",
152
161
  "prettier": "2.7.1",
153
162
  "react-redux": "^8.0.2",
154
163
  "redux": "^4.2.0",
155
164
  "redux-thunk": "^2.4.1"
156
165
  },
157
166
  "engines": {
158
- "node": "16|18",
159
- "npm": "8|9"
167
+ "node": ">=22.12.0",
168
+ "npm": ">=10"
160
169
  }
161
170
  }
package/readme.md CHANGED
@@ -3,10 +3,26 @@ Storefront Toolkit CLI to power up building your custom theme for AppDirect's Ma
3
3
 
4
4
  ### Requirements
5
5
  * Node 10.x or 12.x for versions 1.x.x to 3.0.6
6
- * Node 16.x or 18.x for versions 4.x.x or newer
6
+ * Node 16.x or 18.x for versions 4.x.x to 5.0.x (pre-Rspack)
7
+ * Node >=22.12.0 for versions 6.x.x
8
+ * **Supported platforms:** macOS, Linux, and Windows (npm/npx are spawned via `npm.cmd`/`npx.cmd` on Windows).
9
+
10
+ ### Local server bind
11
+ * By default `sfb-toolkit start` uses Node’s default listen host (same as pre-Rspack).
12
+ * Set `HOST=0.0.0.0` (or `config.host`) to listen on all interfaces — required for Docker. The image sets `HOST=0.0.0.0`.
13
+
14
+ ### Preview live-reload (opt-in)
15
+ * **Off by default** — no SSE route and no injected script unless enabled.
16
+ * Enable with `sfb-toolkit start --live-reload` or `SFB_TOOLKIT_LIVE_RELOAD=1`.
17
+ * Refreshes the preview on theme CSS rebuilds and server restarts (settings/pages). Intended for app-builder iframes (`postMessage` + `EventSource`). Custom-components HMR is unchanged.
7
18
 
8
19
  ### Release Notes:
9
20
 
21
+ **6.0.0**
22
+ - Replaces the entire local theme build tooling (Rspack + sass-embedded). Requires Node >=22.12.0.
23
+ - We thoroughly tested toolkit 6 and include compatibility for common legacy patterns, but themes last verified on toolkit 5.x or earlier must still be thoroughly checked before packaging or publishing. To stay on or revert to 5.x: `npm install -g @appdirect/sfb-toolkit@5`.
24
+ - See `CHANGELOG.md` for the full list of changes.
25
+
10
26
  **5.0.9**
11
27
  - Updated extensions [`@appdirect/public-custom-app-ui@0.0.30`](https://www.npmjs.com/package/@appdirect/public-custom-app-ui/v/0.0.30)
12
28
 
@@ -26,9 +42,11 @@ Developers can have multiple themes in a single environment.
26
42
  |`sfb-toolkit status`|Gives information about current configuration|
27
43
  |`sfb-toolkit update`|Update current theme's configuration|
28
44
  |`sfb-toolkit start`|Starts local server with current theme on `https://localhost:3555/en-US/home`|
45
+ |`sfb-toolkit start --live-reload`|Same as `start`, plus **opt-in** SSE preview live-reload (`/__sfb_live_reload`). Off by default. Also: `SFB_TOOLKIT_LIVE_RELOAD=1`. For app-builder iframe refresh; custom-components HMR stays separate.|
29
46
  |`sfb-toolkit package`|Creates a .zip file with current theme files|
30
47
  |`sfb-toolkit storybook`|[**Deprecated**] Start storybook for the currently selected theme|
31
48
  |`sfb-toolkit install [module]`|Installs npm module in the currently selected theme|
49
+ |`sfb-toolkit install-agent-guidance`|Installs/refreshes AI agent guidance (`AGENTS.md`, Cursor skills) in the workspace|
32
50
  |`sfb-toolkit components`|Setup custom components|
33
51
  |`sfb-toolkit components-info`|Custom components information|
34
52
  |`sfb-toolkit components-copy`|Copy UI library custom components|
@@ -41,6 +59,7 @@ Developers can have multiple themes in a single environment.
41
59
  ### Other Resources
42
60
  - [Official Documentation](https://developer.appdirect.com/storefront/)
43
61
  - [Checkout Integration](https://help.appdirect.com/platform/Default.htm#StorefrontBuilder/sfb-checkout-intro.htm)
62
+ - AI agent guidance: after `sfb-toolkit setup` (or `sfb-toolkit install-agent-guidance`), see workspace `AGENTS.md` (and `CLAUDE.md` / `.cursor/skills`) for toolkit and theme workflows
44
63
 
45
64
 
46
65
  This Repository is owned and maintained by UI Platform team @ AppDirect Inc.
@@ -0,0 +1,81 @@
1
+ const {
2
+ EXTENSIONS,
3
+ getCommonModuleParser,
4
+ getCommonModuleRules,
5
+ path,
6
+ rspack
7
+ } = require('./rspack.shared.cjs');
8
+ const {
9
+ getComponentsReactResolveAlias
10
+ } = require('./src/tools/resolve-components-react');
11
+
12
+ module.exports = (currentPath, config, isAsset) => {
13
+ const assetPath = path.resolve(
14
+ currentPath,
15
+ `themes/${config.theme}/assets/js/components`
16
+ );
17
+ const libPath = path.resolve(
18
+ currentPath,
19
+ `themes/${config.theme}/components/lib`
20
+ );
21
+ const { alias: reactAlias } = getComponentsReactResolveAlias(
22
+ currentPath,
23
+ config.theme,
24
+ __dirname
25
+ );
26
+
27
+ return {
28
+ entry: [
29
+ 'webpack-hot-middleware/client?path=/__webpack_hmr&reload=true',
30
+ path.resolve(
31
+ currentPath,
32
+ `themes/${config.theme}/customComponents/index.js`
33
+ )
34
+ ],
35
+ mode: 'development',
36
+ output: {
37
+ library: {
38
+ name: '__ADComponents',
39
+ type: 'var'
40
+ },
41
+ filename: 'sfb-components.js',
42
+ path: isAsset ? assetPath : libPath,
43
+ publicPath: `http://localhost:${config.port || 3555}/sfb-toolkit-assets/js/components/`,
44
+ hotUpdateChunkFilename: 'hot/hot-update.js',
45
+ hotUpdateMainFilename: 'hot/hot-update.json'
46
+ },
47
+ plugins: [
48
+ new rspack.HotModuleReplacementPlugin(),
49
+ new rspack.CssExtractRspackPlugin({
50
+ filename: 'sfb-components.css'
51
+ }),
52
+ // Themes (e.g. Hitachi Paging) call _.debounce without importing lodash.
53
+ new rspack.ProvidePlugin({
54
+ _: 'lodash'
55
+ })
56
+ ],
57
+ module: {
58
+ parser: getCommonModuleParser(),
59
+ rules: getCommonModuleRules({
60
+ sourceMaps: true,
61
+ transpilePackages: ['@appdirect/sfb-theme-components']
62
+ })
63
+ },
64
+ resolve: {
65
+ alias: reactAlias,
66
+ modules: [
67
+ path.resolve(currentPath, 'node_modules'),
68
+ path.resolve(__dirname, 'node_modules'),
69
+ path.resolve(currentPath, `themes/${config.theme}/node_modules`)
70
+ ],
71
+ extensions: EXTENSIONS
72
+ },
73
+ resolveLoader: {
74
+ modules: [
75
+ path.resolve(currentPath, 'node_modules'),
76
+ path.resolve(__dirname, 'node_modules'),
77
+ path.resolve(currentPath, `themes/${config.theme}/node_modules`)
78
+ ]
79
+ }
80
+ };
81
+ };
@@ -0,0 +1,71 @@
1
+ const {
2
+ EXTENSIONS,
3
+ getCommonModuleParser,
4
+ getCommonModuleRules,
5
+ path,
6
+ rspack
7
+ } = require('./rspack.shared.cjs');
8
+ const {
9
+ getComponentsReactResolveAlias
10
+ } = require('./src/tools/resolve-components-react');
11
+
12
+ module.exports = (currentPath, config) => {
13
+ const assetPath = path.resolve(
14
+ currentPath,
15
+ `themes/${config.theme}/assets/js/components`
16
+ );
17
+ const { alias: reactAlias } = getComponentsReactResolveAlias(
18
+ currentPath,
19
+ config.theme,
20
+ __dirname
21
+ );
22
+
23
+ return {
24
+ entry: [
25
+ path.resolve(
26
+ currentPath,
27
+ `themes/${config.theme}/customComponents/index.js`
28
+ )
29
+ ],
30
+ mode: 'production',
31
+ output: {
32
+ library: {
33
+ name: '__ADComponents',
34
+ type: 'var'
35
+ },
36
+ filename: 'sfb-components.js',
37
+ path: assetPath
38
+ },
39
+ plugins: [
40
+ new rspack.CssExtractRspackPlugin({
41
+ filename: 'sfb-components.css'
42
+ }),
43
+ // Themes (e.g. Hitachi Paging) call _.debounce without importing lodash.
44
+ new rspack.ProvidePlugin({
45
+ _: 'lodash'
46
+ })
47
+ ],
48
+ module: {
49
+ parser: getCommonModuleParser(),
50
+ rules: getCommonModuleRules({
51
+ transpilePackages: ['@appdirect/sfb-theme-components']
52
+ })
53
+ },
54
+ resolve: {
55
+ alias: reactAlias,
56
+ modules: [
57
+ path.resolve(currentPath, 'node_modules'),
58
+ path.resolve(__dirname, 'node_modules'),
59
+ path.resolve(currentPath, `themes/${config.theme}/node_modules`)
60
+ ],
61
+ extensions: EXTENSIONS
62
+ },
63
+ resolveLoader: {
64
+ modules: [
65
+ path.resolve(currentPath, 'node_modules'),
66
+ path.resolve(__dirname, 'node_modules'),
67
+ path.resolve(currentPath, `themes/${config.theme}/node_modules`)
68
+ ]
69
+ }
70
+ };
71
+ };
@@ -0,0 +1,25 @@
1
+ const path = require('path');
2
+ const { getSwcRule } = require('./rspack.shared.cjs');
3
+
4
+ /** @type {import('@rspack/core').Configuration} */
5
+ module.exports = {
6
+ entry: './src/front-end-utils/toolbar.js',
7
+ module: {
8
+ rules: [
9
+ {
10
+ ...getSwcRule({ excludeNodeModules: true }),
11
+ resolve: {
12
+ fullySpecified: false
13
+ }
14
+ }
15
+ ]
16
+ },
17
+ resolve: {
18
+ extensions: ['.js', '.jsx']
19
+ },
20
+ output: {
21
+ path: path.resolve(__dirname, 'src/front-end-utils/dist'),
22
+ publicPath: 'http://localhost:3555/utils/dist',
23
+ filename: 'toolbar.bundle.js'
24
+ }
25
+ };
@@ -0,0 +1,164 @@
1
+ const path = require('path');
2
+ const { rspack } = require('@rspack/core');
3
+ const sassEmbedded = require('sass-embedded');
4
+
5
+ const EXTENSIONS = ['.scss', '.js', '.jsx', '.json', '.png', '.gif', '.jpg', '.svg'];
6
+
7
+ function getSwcRule({
8
+ sourceMaps = false,
9
+ excludeNodeModules = true,
10
+ // Package names under node_modules that must still be SWC'd (JSX source).
11
+ transpilePackages = []
12
+ } = {}) {
13
+ const rule = {
14
+ test: /\.(js|jsx)$/,
15
+ use: {
16
+ loader: 'builtin:swc-loader',
17
+ options: {
18
+ sourceMaps,
19
+ jsc: {
20
+ parser: {
21
+ syntax: 'ecmascript',
22
+ jsx: true
23
+ },
24
+ transform: {
25
+ react: {
26
+ runtime: 'classic'
27
+ }
28
+ },
29
+ target: 'es5'
30
+ }
31
+ }
32
+ }
33
+ };
34
+
35
+ if (transpilePackages.length > 0) {
36
+ rule.exclude = (modulePath) => {
37
+ if (!modulePath.includes('node_modules')) {
38
+ return false;
39
+ }
40
+ return !transpilePackages.some((pkg) => (
41
+ modulePath.includes(`node_modules/${pkg}`)
42
+ || modulePath.includes(`node_modules\\${pkg}`)
43
+ ));
44
+ };
45
+ } else if (excludeNodeModules) {
46
+ rule.exclude = /node_modules/;
47
+ }
48
+
49
+ return rule;
50
+ }
51
+
52
+ function getStyleRules() {
53
+ return {
54
+ test: /\.(sa|sc|c)ss$/,
55
+ use: [
56
+ rspack.CssExtractRspackPlugin.loader,
57
+ 'css-loader',
58
+ {
59
+ loader: 'sass-loader',
60
+ options: {
61
+ api: 'modern-compiler',
62
+ implementation: sassEmbedded,
63
+ webpackImporter: true,
64
+ // Themes use bare `@import 'themes/<name>/…'` (cwd-relative) and
65
+ // sometimes ship SCSS in `.css` files — match old webpack/node-sass.
66
+ sassOptions: (loaderContext) => {
67
+ const opts = {
68
+ quietDeps: true,
69
+ loadPaths: [process.cwd()],
70
+ // Pin sass-embedded <1.92 so mixed-decls still hoist (old cascade).
71
+ silenceDeprecations: [
72
+ 'import',
73
+ 'global-builtin',
74
+ 'color-functions',
75
+ 'slash-div',
76
+ 'mixed-decls',
77
+ // sfb-theme-components: mix($color, $color, 15) without %
78
+ 'function-units'
79
+ ]
80
+ };
81
+ if (
82
+ loaderContext
83
+ && /\.css$/i.test(loaderContext.resourcePath || '')
84
+ ) {
85
+ opts.syntax = 'scss';
86
+ }
87
+ return opts;
88
+ }
89
+ }
90
+ }
91
+ ]
92
+ };
93
+ }
94
+
95
+ function getAssetRules() {
96
+ return [
97
+ {
98
+ test: /\.(png|gif|jpg|svg)$/,
99
+ type: 'asset',
100
+ parser: {
101
+ dataUrlCondition: {
102
+ maxSize: 50000
103
+ }
104
+ }
105
+ },
106
+ {
107
+ test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
108
+ type: 'asset/resource',
109
+ generator: {
110
+ filename: 'fonts/[name][ext]'
111
+ }
112
+ }
113
+ ];
114
+ }
115
+
116
+ function getCustomComponentsExportCompatRule() {
117
+ return {
118
+ test: /[\\/]customComponents[\\/]index\.js$/,
119
+ use: [
120
+ {
121
+ loader: path.resolve(
122
+ __dirname,
123
+ 'src/tools/custom-components-export-compat-loader.js'
124
+ )
125
+ }
126
+ ]
127
+ };
128
+ }
129
+
130
+ function getCommonModuleRules({
131
+ sourceMaps = false,
132
+ excludeNodeModules = true,
133
+ transpilePackages = []
134
+ } = {}) {
135
+ return [
136
+ getCustomComponentsExportCompatRule(),
137
+ getSwcRule({ sourceMaps, excludeNodeModules, transpilePackages }),
138
+ getStyleRules(),
139
+ ...getAssetRules()
140
+ ];
141
+ }
142
+
143
+ /**
144
+ * Rspack 2 defaults exportsPresence to 'error' (dev overlay). Webpack warned.
145
+ * Themes often hoist a newer react-tooltip than @appdirect/sfb-theme-components
146
+ * expects — keep that as a warning so preview still loads, matching 5.x.
147
+ */
148
+ function getCommonModuleParser() {
149
+ return {
150
+ javascript: {
151
+ exportsPresence: 'warn',
152
+ importExportsPresence: 'warn'
153
+ }
154
+ };
155
+ }
156
+
157
+ module.exports = {
158
+ EXTENSIONS,
159
+ getCommonModuleParser,
160
+ getCommonModuleRules,
161
+ getSwcRule,
162
+ rspack,
163
+ path
164
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Locale path segments used by page routes (e.g. /en-US/home).
3
+ * Rejects reserved first path segments like "assets" that hit /:locale/* by accident.
4
+ */
5
+ const PLAUSIBLE_LOCALE = /^[a-z]{2}(?:[_-][a-z]{2})?$/i
6
+
7
+ const isPlausibleLocale = (locale) =>
8
+ typeof locale === "string" && PLAUSIBLE_LOCALE.test(locale)
9
+
10
+ module.exports = { isPlausibleLocale }
@@ -0,0 +1,103 @@
1
+ const _ = require('lodash');
2
+
3
+ // Protocol-relative embeds (//youtube…) break on http://localhost — force https.
4
+ const PROTOCOL_RELATIVE_URL = /^\/\/[\w.-]+(?::\d+)?\//;
5
+
6
+ // Cross-origin PDF iframes often render blank in Chrome from toolkit HTTP;
7
+ // serve them same-origin via the toolkit media proxy.
8
+ const PDF_URL = /^https?:\/\/.+\.pdf(?:[?#].*)?$/i;
9
+
10
+ const ALLOWED_PDF_HOST_SUFFIXES = [
11
+ '.cloudfront.net',
12
+ '.byappdirect.com',
13
+ '.appdirect.com',
14
+ '.att.com',
15
+ '.hpe.com'
16
+ ];
17
+
18
+ const MEDIA_PROXY_PATH = '/sfb-toolkit-media-proxy';
19
+
20
+ function isAllowedPdfHost(hostname) {
21
+ if (!hostname) {
22
+ return false;
23
+ }
24
+ const host = hostname.toLowerCase();
25
+ return ALLOWED_PDF_HOST_SUFFIXES.some(
26
+ (suffix) => host === suffix.slice(1) || host.endsWith(suffix)
27
+ );
28
+ }
29
+
30
+ function isPdfPath(pathname) {
31
+ return typeof pathname === 'string' && /\.pdf$/i.test(pathname);
32
+ }
33
+
34
+ function rewriteMediaUrl(value) {
35
+ if (typeof value !== 'string' || !value) {
36
+ return value;
37
+ }
38
+
39
+ // Upgrade //host/... first, then still apply PDF proxy rewrite when needed.
40
+ let next = value;
41
+ if (PROTOCOL_RELATIVE_URL.test(next)) {
42
+ next = `https:${next}`;
43
+ }
44
+
45
+ if (PDF_URL.test(next)) {
46
+ try {
47
+ const parsed = new URL(next);
48
+ if (isAllowedPdfHost(parsed.hostname) && isPdfPath(parsed.pathname)) {
49
+ return `${MEDIA_PROXY_PATH}?url=${encodeURIComponent(next)}`;
50
+ }
51
+ } catch (err) {
52
+ return next;
53
+ }
54
+ }
55
+
56
+ return next;
57
+ }
58
+
59
+ function walkAndRewrite(node) {
60
+ if (Array.isArray(node)) {
61
+ for (let i = 0; i < node.length; i += 1) {
62
+ const item = node[i];
63
+ if (typeof item === 'string') {
64
+ node[i] = rewriteMediaUrl(item);
65
+ } else if (item && typeof item === 'object') {
66
+ walkAndRewrite(item);
67
+ }
68
+ }
69
+ return;
70
+ }
71
+
72
+ if (!node || typeof node !== 'object') {
73
+ return;
74
+ }
75
+
76
+ Object.keys(node).forEach((key) => {
77
+ const value = node[key];
78
+ if (typeof value === 'string') {
79
+ node[key] = rewriteMediaUrl(value);
80
+ } else if (value && typeof value === 'object') {
81
+ walkAndRewrite(value);
82
+ }
83
+ });
84
+ }
85
+
86
+ /**
87
+ * Toolkit-only: make resource previews work on http://localhost.
88
+ * - //host/... → https://host/...
89
+ * - https://…/*.pdf → /sfb-toolkit-media-proxy?url=…
90
+ */
91
+ function mediaUrlFilter(dataToFilter = {}) {
92
+ const data = _.cloneDeep(dataToFilter);
93
+ walkAndRewrite(data);
94
+ return data;
95
+ }
96
+
97
+ module.exports = {
98
+ MEDIA_PROXY_PATH,
99
+ mediaUrlFilter,
100
+ rewriteMediaUrl,
101
+ isAllowedPdfHost,
102
+ isPdfPath
103
+ };