@wix/builder-utils 1.21.1 → 1.21.3

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 (42) hide show
  1. package/README.md +44 -0
  2. package/dist/bundles/debug/es/builder-utils.mjs +54 -1
  3. package/dist/bundles/debug/es/builder-utils.mjs.map +1 -1
  4. package/dist/bundles/debug/umd/builder-utils.js +53 -0
  5. package/dist/bundles/debug/umd/builder-utils.js.map +1 -1
  6. package/dist/bundles/es/builder-utils.mjs +401 -354
  7. package/dist/bundles/es/builder-utils.mjs.map +1 -1
  8. package/dist/bundles/umd/builder-utils.js +1 -1
  9. package/dist/bundles/umd/builder-utils.js.map +1 -1
  10. package/dist/{cjs/index.d.ts → index.d.ts} +1 -0
  11. package/dist/{esm/index.js → index.js} +1 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/mergeUtils.js.map +1 -0
  14. package/dist/routerUtils.d.ts +33 -0
  15. package/dist/routerUtils.js +55 -0
  16. package/dist/routerUtils.js.map +1 -0
  17. package/dist/signalUtils.js.map +1 -0
  18. package/package.json +11 -12
  19. package/src/index.ts +1 -0
  20. package/src/routerUtils.ts +123 -0
  21. package/dist/cjs/index.js +0 -9
  22. package/dist/cjs/index.js.map +0 -1
  23. package/dist/cjs/mergeUtils.js +0 -60
  24. package/dist/cjs/mergeUtils.js.map +0 -1
  25. package/dist/cjs/signalUtils.js +0 -28
  26. package/dist/cjs/signalUtils.js.map +0 -1
  27. package/dist/esm/index.d.ts +0 -2
  28. package/dist/esm/index.js.map +0 -1
  29. package/dist/esm/mergeUtils.d.ts +0 -2
  30. package/dist/esm/mergeUtils.js.map +0 -1
  31. package/dist/esm/signalUtils.d.ts +0 -6
  32. package/dist/esm/signalUtils.js.map +0 -1
  33. package/dist/types/index.d.ts +0 -3
  34. package/dist/types/index.d.ts.map +0 -1
  35. package/dist/types/mergeUtils.d.ts +0 -3
  36. package/dist/types/mergeUtils.d.ts.map +0 -1
  37. package/dist/types/signalUtils.d.ts +0 -7
  38. package/dist/types/signalUtils.d.ts.map +0 -1
  39. /package/dist/{cjs/mergeUtils.d.ts → mergeUtils.d.ts} +0 -0
  40. /package/dist/{esm/mergeUtils.js → mergeUtils.js} +0 -0
  41. /package/dist/{cjs/signalUtils.d.ts → signalUtils.d.ts} +0 -0
  42. /package/dist/{esm/signalUtils.js → signalUtils.js} +0 -0
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Package Overview
2
+
3
+ This package is part of the site export system provided by Wix.
4
+
5
+ It is used as a supporting dependency for React applications generated through the Wix export flow, and is installed automatically as part of that process.
6
+
7
+ ## Intended Usage
8
+
9
+ This package is designed to work within the context of:
10
+
11
+ - Applications generated via Wix site export
12
+ - The associated runtime and tooling provided by Wix
13
+
14
+ When used in this environment, it will be kept up to date and function as expected.
15
+
16
+ ## Usage Outside of Wix Export
17
+
18
+ While this package is publicly available on npm, it is not intended for standalone use.
19
+
20
+ - The API surface may change without notice
21
+ - Behavior may depend on internal Wix systems or assumptions
22
+ - Documentation is limited to the export use case
23
+
24
+ If you're not using a Wix-generated project, this package is unlikely to behave as expected.
25
+
26
+ ## Stability & Updates
27
+
28
+ This package follows the release cycle of Wix export features.
29
+
30
+ - Updates may include breaking changes
31
+ - Versioning is aligned with internal system needs
32
+ - No guarantees are made for external compatibility
33
+
34
+ Projects generated through Wix will receive compatible updates as needed.
35
+
36
+ ## Support
37
+
38
+ Support is provided for:
39
+
40
+ - Issues encountered within Wix-exported applications
41
+
42
+ Support is not provided for:
43
+
44
+ - Custom or standalone usage of this package
@@ -971,9 +971,62 @@ const getSignalValueDeep = (target, path = "") => {
971
971
  }
972
972
  return isSignal(value) ? value.get() : value;
973
973
  };
974
+ function getPageById(id, pageRegistry) {
975
+ return pageRegistry[id] ?? null;
976
+ }
977
+ function getPageRoles(routerPrefix, pageRegistry) {
978
+ return Object.entries(pageRegistry).filter(([, entry]) => entry.routerPrefix === routerPrefix).reduce((acc, [, { role, routerPrefix: _, pageName: __, ...rest }]) => {
979
+ acc[role] = rest;
980
+ return acc;
981
+ }, {});
982
+ }
983
+ async function fetchWixRouterPage(routerServiceUrl, { routerPrefix, config, rulesByPageRole, req, getAccessToken, pageRegistry, routerBaseUrl }) {
984
+ const token = await getAccessToken();
985
+ const routerUrl = new URL(routerServiceUrl + "/pages", routerBaseUrl);
986
+ const payload = {
987
+ routerPrefix,
988
+ config,
989
+ fullUrl: req.protocol + "://" + req.get("host") + req.path,
990
+ pageRoles: getPageRoles(routerPrefix, pageRegistry),
991
+ requestInfo: { env: "browser", formFactor: "desktop" },
992
+ roleVariations: rulesByPageRole,
993
+ routerSuffix: "/" + (req.params[0] || "")
994
+ };
995
+ const response = await fetch(routerUrl, {
996
+ method: "POST",
997
+ headers: { "Content-Type": "application/json", Authorization: token },
998
+ body: JSON.stringify(payload)
999
+ });
1000
+ if (!response.ok)
1001
+ return null;
1002
+ const { result } = await response.json();
1003
+ return result;
1004
+ }
1005
+ async function routeToDynamicPage(req, res, next, { routerServiceUrl, routerPrefix, getAccessToken, routerConfigs, pageRegistry, routerBaseUrl, getPageRenderData }) {
1006
+ const result = await fetchWixRouterPage(routerServiceUrl, {
1007
+ routerPrefix,
1008
+ ...routerConfigs[routerPrefix],
1009
+ req,
1010
+ getAccessToken,
1011
+ pageRegistry,
1012
+ routerBaseUrl
1013
+ });
1014
+ if (!result || result.status !== 200)
1015
+ return next();
1016
+ const page = getPageById(result.page, pageRegistry);
1017
+ if (!page)
1018
+ return next();
1019
+ res.render("layout", {
1020
+ title: page.title,
1021
+ pageName: page.pageName,
1022
+ ...getPageRenderData(result.page),
1023
+ options: {}
1024
+ });
1025
+ }
974
1026
  export {
975
1027
  getSignalValueDeep,
976
1028
  mergeProps,
977
- removeElementProps
1029
+ removeElementProps,
1030
+ routeToDynamicPage
978
1031
  };
979
1032
  //# sourceMappingURL=builder-utils.mjs.map