@websolutespa/bom-next 3.0.2 → 4.0.0-next.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 (264) hide show
  1. package/CHANGELOG.md +37 -7
  2. package/README.md +28 -0
  3. package/dist/_virtual/{_rolldown/runtime.js → rolldown_runtime.js} +7 -4
  4. package/dist/client/client.d.ts.map +1 -1
  5. package/dist/client/client.js +17 -6
  6. package/dist/client/client.js.map +1 -1
  7. package/dist/client/extra.d.ts +3 -3
  8. package/dist/client/extra.d.ts.map +1 -1
  9. package/dist/client/extra.js +10 -5
  10. package/dist/client/extra.js.map +1 -1
  11. package/dist/client/label.d.ts +3 -3
  12. package/dist/client/label.d.ts.map +1 -1
  13. package/dist/client/label.js +10 -5
  14. package/dist/client/label.js.map +1 -1
  15. package/dist/client/layout.d.ts +3 -3
  16. package/dist/client/layout.d.ts.map +1 -1
  17. package/dist/client/layout.js +10 -5
  18. package/dist/client/layout.js.map +1 -1
  19. package/dist/client/local.collection.d.ts.map +1 -1
  20. package/dist/client/local.collection.js +4 -2
  21. package/dist/client/local.collection.js.map +1 -1
  22. package/dist/client/metadata.d.ts +3 -3
  23. package/dist/client/metadata.d.ts.map +1 -1
  24. package/dist/client/metadata.js +48 -40
  25. package/dist/client/metadata.js.map +1 -1
  26. package/dist/client/page.d.ts +3 -3
  27. package/dist/client/page.d.ts.map +1 -1
  28. package/dist/client/page.js +10 -5
  29. package/dist/client/page.js.map +1 -1
  30. package/dist/client/useApi.d.ts +7 -7
  31. package/dist/client/useApi.d.ts.map +1 -1
  32. package/dist/client/useApi.js +2 -1
  33. package/dist/client/useApi.js.map +1 -1
  34. package/dist/client/useCollectionApi.d.ts +6 -6
  35. package/dist/client/useCollectionApi.d.ts.map +1 -1
  36. package/dist/client/useCollectionApi.js +4 -2
  37. package/dist/client/useCollectionApi.js.map +1 -1
  38. package/dist/client/useExtra.d.ts.map +1 -1
  39. package/dist/client/useExtra.js +5 -2
  40. package/dist/client/useExtra.js.map +1 -1
  41. package/dist/client/useHttp.d.ts.map +1 -1
  42. package/dist/client/useHttp.js +9 -6
  43. package/dist/client/useHttp.js.map +1 -1
  44. package/dist/client/useLabel.d.ts.map +1 -1
  45. package/dist/client/useLabel.js +5 -2
  46. package/dist/client/useLabel.js.map +1 -1
  47. package/dist/client/useLayout.d.ts.map +1 -1
  48. package/dist/client/useLayout.js +5 -2
  49. package/dist/client/useLayout.js.map +1 -1
  50. package/dist/client/useLink.d.ts.map +1 -1
  51. package/dist/client/useLink.js +7 -3
  52. package/dist/client/useLink.js.map +1 -1
  53. package/dist/client/useMetaData.d.ts.map +1 -1
  54. package/dist/client/useMetaData.js +5 -2
  55. package/dist/client/useMetaData.js.map +1 -1
  56. package/dist/client/usePage.d.ts.map +1 -1
  57. package/dist/client/usePage.js +5 -2
  58. package/dist/client/usePage.js.map +1 -1
  59. package/dist/client/useUser.d.ts.map +1 -1
  60. package/dist/client/useUser.js +5 -2
  61. package/dist/client/useUser.js.map +1 -1
  62. package/dist/client/user.d.ts.map +1 -1
  63. package/dist/client/user.js +17 -11
  64. package/dist/client/user.js.map +1 -1
  65. package/dist/exports/client.js +2 -1
  66. package/dist/exports/instrumentation.js +2 -1
  67. package/dist/exports/proxy.js +2 -1
  68. package/dist/exports/server.d.ts +5 -4
  69. package/dist/exports/server.js +7 -5
  70. package/dist/index.d.ts +3 -3
  71. package/dist/index.js +3 -2
  72. package/dist/instrumentation/client.d.ts.map +1 -1
  73. package/dist/instrumentation/client.js +2 -1
  74. package/dist/instrumentation/client.js.map +1 -1
  75. package/dist/instrumentation/sentry/capture.requestError.js +4 -1
  76. package/dist/instrumentation/sentry/capture.requestError.js.map +1 -1
  77. package/dist/instrumentation/sentry/capture.routerTransitionStart.js +2 -1
  78. package/dist/instrumentation/sentry/capture.routerTransitionStart.js.map +1 -1
  79. package/dist/instrumentation/sentry/config.client.js +10 -2
  80. package/dist/instrumentation/sentry/config.client.js.map +1 -0
  81. package/dist/instrumentation/sentry/config.edge.js +10 -2
  82. package/dist/instrumentation/sentry/config.edge.js.map +1 -0
  83. package/dist/instrumentation/sentry/config.server.js +10 -2
  84. package/dist/instrumentation/sentry/config.server.js.map +1 -0
  85. package/dist/instrumentation/server.d.ts.map +1 -1
  86. package/dist/instrumentation/server.js +8 -5
  87. package/dist/instrumentation/server.js.map +1 -1
  88. package/dist/instrumentation/types.d.ts.map +1 -1
  89. package/dist/lib/breadcrumb.d.ts.map +1 -1
  90. package/dist/lib/breadcrumb.js +6 -1
  91. package/dist/lib/breadcrumb.js.map +1 -1
  92. package/dist/lib/const.d.ts +14 -2
  93. package/dist/lib/const.d.ts.map +1 -1
  94. package/dist/lib/const.js +24 -2
  95. package/dist/lib/const.js.map +1 -1
  96. package/dist/lib/http.d.ts +9 -0
  97. package/dist/lib/http.d.ts.map +1 -1
  98. package/dist/lib/http.js +27 -4
  99. package/dist/lib/http.js.map +1 -1
  100. package/dist/lib/label.d.ts.map +1 -1
  101. package/dist/lib/label.js +4 -3
  102. package/dist/lib/label.js.map +1 -1
  103. package/dist/lib/layout.defaults.d.ts.map +1 -1
  104. package/dist/lib/layout.defaults.js +1 -1
  105. package/dist/lib/layout.defaults.js.map +1 -1
  106. package/dist/lib/link.d.ts.map +1 -1
  107. package/dist/lib/link.js +2 -1
  108. package/dist/lib/link.js.map +1 -1
  109. package/dist/lib/meta-data.d.ts.map +1 -1
  110. package/dist/lib/open-graph.d.ts.map +1 -1
  111. package/dist/lib/pagination.d.ts.map +1 -1
  112. package/dist/lib/pagination.js +4 -2
  113. package/dist/lib/pagination.js.map +1 -1
  114. package/dist/lib/route.d.ts.map +1 -1
  115. package/dist/lib/route.js +9 -3
  116. package/dist/lib/route.js.map +1 -1
  117. package/dist/lib/store.d.ts.map +1 -1
  118. package/dist/lib/store.js +31 -31
  119. package/dist/lib/store.js.map +1 -1
  120. package/dist/lib/structured-data.d.ts.map +1 -1
  121. package/dist/lib/twitter-card.d.ts.map +1 -1
  122. package/dist/lib/utils.d.ts.map +1 -1
  123. package/dist/lib/utils.js +3 -2
  124. package/dist/lib/utils.js.map +1 -1
  125. package/dist/mock.d.ts.map +1 -1
  126. package/dist/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.js +3 -2
  127. package/dist/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.js.map +1 -1
  128. package/dist/node_modules/deepmerge/dist/cjs.js +17 -9
  129. package/dist/node_modules/deepmerge/dist/cjs.js.map +1 -1
  130. package/dist/node_modules/dom-serializer/lib/esm/foreignNames.js +2 -2
  131. package/dist/node_modules/dom-serializer/lib/esm/foreignNames.js.map +1 -1
  132. package/dist/node_modules/dom-serializer/lib/esm/index.js +10 -15
  133. package/dist/node_modules/dom-serializer/lib/esm/index.js.map +1 -1
  134. package/dist/node_modules/domelementtype/lib/esm/index.js +12 -12
  135. package/dist/node_modules/domelementtype/lib/esm/index.js.map +1 -1
  136. package/dist/node_modules/domhandler/lib/esm/index.js +4 -3
  137. package/dist/node_modules/domhandler/lib/esm/index.js.map +1 -1
  138. package/dist/node_modules/domhandler/lib/esm/node.js +8 -7
  139. package/dist/node_modules/domhandler/lib/esm/node.js.map +1 -1
  140. package/dist/node_modules/entities/lib/esm/decode.js +33 -32
  141. package/dist/node_modules/entities/lib/esm/decode.js.map +1 -1
  142. package/dist/node_modules/entities/lib/esm/decode_codepoint.js +5 -5
  143. package/dist/node_modules/entities/lib/esm/decode_codepoint.js.map +1 -1
  144. package/dist/node_modules/entities/lib/esm/escape.js +14 -6
  145. package/dist/node_modules/entities/lib/esm/escape.js.map +1 -1
  146. package/dist/node_modules/entities/lib/esm/generated/decode-data-html.js +2 -2
  147. package/dist/node_modules/entities/lib/esm/generated/decode-data-html.js.map +1 -1
  148. package/dist/node_modules/entities/lib/esm/generated/decode-data-xml.js +2 -2
  149. package/dist/node_modules/entities/lib/esm/generated/decode-data-xml.js.map +1 -1
  150. package/dist/node_modules/html-to-text/lib/html-to-text.js +45 -33
  151. package/dist/node_modules/html-to-text/lib/html-to-text.js.map +1 -1
  152. package/dist/node_modules/html-to-text/node_modules/htmlparser2/lib/esm/Parser.js +25 -25
  153. package/dist/node_modules/html-to-text/node_modules/htmlparser2/lib/esm/Parser.js.map +1 -1
  154. package/dist/node_modules/html-to-text/node_modules/htmlparser2/lib/esm/Tokenizer.js +76 -73
  155. package/dist/node_modules/html-to-text/node_modules/htmlparser2/lib/esm/Tokenizer.js.map +1 -1
  156. package/dist/node_modules/html-to-text/node_modules/htmlparser2/lib/esm/index.js +4 -3
  157. package/dist/node_modules/html-to-text/node_modules/htmlparser2/lib/esm/index.js.map +1 -1
  158. package/dist/node_modules/leac/lib/leac.js +72 -72
  159. package/dist/node_modules/leac/lib/leac.js.map +1 -1
  160. package/dist/node_modules/parseley/lib/parseley.js +37 -33
  161. package/dist/node_modules/parseley/lib/parseley.js.map +1 -1
  162. package/dist/node_modules/peberminta/lib/core.js +4 -4
  163. package/dist/node_modules/peberminta/lib/core.js.map +1 -1
  164. package/dist/node_modules/selderee/lib/selderee.js +16 -10
  165. package/dist/node_modules/selderee/lib/selderee.js.map +1 -1
  166. package/dist/proxy/protected-route.d.ts.map +1 -1
  167. package/dist/proxy/protected-route.js +11 -6
  168. package/dist/proxy/protected-route.js.map +1 -1
  169. package/dist/proxy/proxy.d.ts +5 -4
  170. package/dist/proxy/proxy.d.ts.map +1 -1
  171. package/dist/proxy/proxy.js +26 -6
  172. package/dist/proxy/proxy.js.map +1 -1
  173. package/dist/proxy/route-auto-detection.d.ts.map +1 -1
  174. package/dist/proxy/route-auto-detection.js +26 -14
  175. package/dist/proxy/route-auto-detection.js.map +1 -1
  176. package/dist/proxy/route-proxy.d.ts.map +1 -1
  177. package/dist/proxy/route-proxy.js +22 -5
  178. package/dist/proxy/route-proxy.js.map +1 -1
  179. package/dist/server/context.d.ts +31 -15
  180. package/dist/server/context.d.ts.map +1 -1
  181. package/dist/server/context.js +156 -69
  182. package/dist/server/context.js.map +1 -1
  183. package/dist/server/handlers/auth.handler.d.ts.map +1 -1
  184. package/dist/server/handlers/auth.handler.js +4 -2
  185. package/dist/server/handlers/auth.handler.js.map +1 -1
  186. package/dist/server/handlers/captions.handler.d.ts.map +1 -1
  187. package/dist/server/handlers/captions.handler.js +4 -2
  188. package/dist/server/handlers/captions.handler.js.map +1 -1
  189. package/dist/server/handlers/collection.handler.d.ts.map +1 -1
  190. package/dist/server/handlers/collection.handler.js +2 -1
  191. package/dist/server/handlers/collection.handler.js.map +1 -1
  192. package/dist/server/handlers/error-response.js +6 -2
  193. package/dist/server/handlers/error-response.js.map +1 -1
  194. package/dist/server/handlers/index.handler.d.ts.map +1 -1
  195. package/dist/server/handlers/index.handler.js +2 -1
  196. package/dist/server/handlers/index.handler.js.map +1 -1
  197. package/dist/server/handlers/preview.handler.d.ts.map +1 -1
  198. package/dist/server/handlers/preview.handler.js +6 -3
  199. package/dist/server/handlers/preview.handler.js.map +1 -1
  200. package/dist/server/handlers/registry.handler.d.ts.map +1 -1
  201. package/dist/server/handlers/registry.handler.js +14 -9
  202. package/dist/server/handlers/registry.handler.js.map +1 -1
  203. package/dist/server/handlers/route.handler.d.ts.map +1 -1
  204. package/dist/server/handlers/route.handler.js +12 -3
  205. package/dist/server/handlers/route.handler.js.map +1 -1
  206. package/dist/server/handlers/sitemap.handler.d.ts.map +1 -1
  207. package/dist/server/handlers/sitemap.handler.js +12 -9
  208. package/dist/server/handlers/sitemap.handler.js.map +1 -1
  209. package/dist/server/handlers/static-params.handler.d.ts.map +1 -1
  210. package/dist/server/handlers/static-params.handler.js +13 -8
  211. package/dist/server/handlers/static-params.handler.js.map +1 -1
  212. package/dist/server/handlers/vars.handler.d.ts.map +1 -1
  213. package/dist/server/handlers/vars.handler.js +5 -4
  214. package/dist/server/handlers/vars.handler.js.map +1 -1
  215. package/dist/server/helpers.d.ts +50 -0
  216. package/dist/server/helpers.d.ts.map +1 -0
  217. package/dist/server/helpers.js +60 -0
  218. package/dist/server/helpers.js.map +1 -0
  219. package/dist/server/layout.js +69 -34
  220. package/dist/server/layout.js.map +1 -1
  221. package/dist/server/lazy.d.ts +1 -0
  222. package/dist/server/lazy.d.ts.map +1 -1
  223. package/dist/server/lazy.js +3 -2
  224. package/dist/server/lazy.js.map +1 -1
  225. package/dist/server/local-api.d.ts.map +1 -1
  226. package/dist/server/local-api.js +12 -6
  227. package/dist/server/local-api.js.map +1 -1
  228. package/dist/server/metadata.d.ts +8 -5
  229. package/dist/server/metadata.d.ts.map +1 -1
  230. package/dist/server/metadata.js +21 -7
  231. package/dist/server/metadata.js.map +1 -1
  232. package/dist/server/mixer-payload.d.ts +1 -1
  233. package/dist/server/mixer-payload.d.ts.map +1 -1
  234. package/dist/server/mixer.d.ts +48 -6
  235. package/dist/server/mixer.d.ts.map +1 -1
  236. package/dist/server/mixer.js +235 -68
  237. package/dist/server/mixer.js.map +1 -1
  238. package/dist/server/page.d.ts +21 -5
  239. package/dist/server/page.d.ts.map +1 -1
  240. package/dist/server/page.js +74 -15
  241. package/dist/server/page.js.map +1 -1
  242. package/dist/server/utils.d.ts.map +1 -1
  243. package/dist/server/utils.js +4 -2
  244. package/dist/server/utils.js.map +1 -1
  245. package/dist/server/utmz.d.ts.map +1 -1
  246. package/dist/server/utmz.js +1 -1
  247. package/dist/server/utmz.js.map +1 -1
  248. package/dist/types.d.ts +79 -8
  249. package/dist/types.d.ts.map +1 -1
  250. package/package.json +16 -15
  251. package/src/exports/server.ts +1 -0
  252. package/src/lib/const.ts +15 -0
  253. package/src/lib/http.ts +15 -4
  254. package/src/proxy/proxy.ts +11 -4
  255. package/src/server/context.test.ts +467 -0
  256. package/src/server/context.ts +237 -78
  257. package/src/server/context.type-test.ts +106 -0
  258. package/src/server/helpers.ts +58 -0
  259. package/src/server/layout.ts +45 -39
  260. package/src/server/lazy.ts +1 -1
  261. package/src/server/metadata.ts +15 -7
  262. package/src/server/mixer.ts +57 -9
  263. package/src/server/page.ts +62 -17
  264. package/src/types.ts +109 -7
@@ -6,19 +6,23 @@ const isPublic = (error, status) => {
6
6
  return error.isPublic === true || error.isPublic === void 0 && status >= 400 && status < 500;
7
7
  };
8
8
  /**
9
+
9
10
  * Converts errors thrown by Next or Payload handlers into Payload-compatible
11
+
10
12
  * API responses without exposing messages or data from non-public errors.
13
+
11
14
  */
12
15
  function getHandlerErrorResponse(error) {
13
16
  const statusError = error && typeof error === "object" ? error : {};
14
17
  const status = getStatus(statusError);
15
18
  const publicError = isPublic(statusError, status);
16
- const payloadError = { message: publicError && typeof statusError.message === "string" ? statusError.message : publicError && typeof statusError.statusText === "string" ? statusError.statusText : "Something went wrong." };
19
+ const message = publicError && typeof statusError.message === "string" ? statusError.message : publicError && typeof statusError.statusText === "string" ? statusError.statusText : "Something went wrong.";
20
+ const payloadError = { message };
17
21
  if (publicError && typeof statusError.name === "string") payloadError.name = statusError.name;
18
22
  if (publicError && statusError.data !== null && statusError.data !== void 0) payloadError.data = statusError.data;
19
23
  return Response.json({ errors: [payloadError] }, { status });
20
24
  }
25
+
21
26
  //#endregion
22
27
  export { getHandlerErrorResponse };
23
-
24
28
  //# sourceMappingURL=error-response.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-response.js","names":[],"sources":["../../../src/server/handlers/error-response.ts"],"sourcesContent":["type StatusError = {\r\n data?: unknown;\r\n isPublic?: unknown;\r\n message?: unknown;\r\n name?: unknown;\r\n status?: unknown;\r\n statusText?: unknown;\r\n};\r\n\r\ntype PayloadErrorItem = {\r\n data?: unknown;\r\n message: string;\r\n name?: string;\r\n};\r\n\r\nconst getStatus = (error: StatusError): number => {\r\n return typeof error.status === 'number' && error.status >= 400 && error.status < 600 ? error.status : 500;\r\n};\r\n\r\nconst isPublic = (error: StatusError, status: number): boolean => {\r\n return error.isPublic === true || (error.isPublic === undefined && status >= 400 && status < 500);\r\n};\r\n\r\n/**\r\n * Converts errors thrown by Next or Payload handlers into Payload-compatible\r\n * API responses without exposing messages or data from non-public errors.\r\n */\r\nexport function getHandlerErrorResponse(error: unknown): Response {\r\n const statusError = error && typeof error === 'object' ? error as StatusError : {};\r\n const status = getStatus(statusError);\r\n const publicError = isPublic(statusError, status);\r\n const message = publicError && typeof statusError.message === 'string' ?\r\n statusError.message :\r\n publicError && typeof statusError.statusText === 'string' ? statusError.statusText : 'Something went wrong.';\r\n const payloadError: PayloadErrorItem = { message };\r\n\r\n if (publicError && typeof statusError.name === 'string') {\r\n payloadError.name = statusError.name;\r\n }\r\n if (publicError && statusError.data !== null && statusError.data !== undefined) {\r\n payloadError.data = statusError.data;\r\n }\r\n\r\n return Response.json({ errors: [payloadError] }, { status });\r\n}\r\n"],"mappings":";AAeA,MAAM,aAAa,UAA+B;CAC9C,OAAO,OAAO,MAAM,WAAW,YAAY,MAAM,UAAU,OAAO,MAAM,SAAS,MAAM,MAAM,SAAS;AAC1G;AAEA,MAAM,YAAY,OAAoB,WAA4B;CAC9D,OAAO,MAAM,aAAa,QAAS,MAAM,aAAa,KAAA,KAAa,UAAU,OAAO,SAAS;AACjG;;;;;AAMA,SAAgB,wBAAwB,OAA0B;CAC9D,MAAM,cAAc,SAAS,OAAO,UAAU,WAAW,QAAuB,CAAC;CACjF,MAAM,SAAS,UAAU,WAAW;CACpC,MAAM,cAAc,SAAS,aAAa,MAAM;CAIhD,MAAM,eAAiC,EAAE,SAHzB,eAAe,OAAO,YAAY,YAAY,WAC1D,YAAY,UACZ,eAAe,OAAO,YAAY,eAAe,WAAW,YAAY,aAAa,wBACxC;CAEjD,IAAI,eAAe,OAAO,YAAY,SAAS,UAC3C,aAAa,OAAO,YAAY;CAEpC,IAAI,eAAe,YAAY,SAAS,QAAQ,YAAY,SAAS,KAAA,GACjE,aAAa,OAAO,YAAY;CAGpC,OAAO,SAAS,KAAK,EAAE,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE,OAAO,CAAC;AAC/D"}
1
+ {"version":3,"file":"error-response.js","names":["error: StatusError","status: number","error: unknown","payloadError: PayloadErrorItem"],"sources":["../../../src/server/handlers/error-response.ts"],"sourcesContent":["type StatusError = {\r\n data?: unknown;\r\n isPublic?: unknown;\r\n message?: unknown;\r\n name?: unknown;\r\n status?: unknown;\r\n statusText?: unknown;\r\n};\r\n\r\ntype PayloadErrorItem = {\r\n data?: unknown;\r\n message: string;\r\n name?: string;\r\n};\r\n\r\nconst getStatus = (error: StatusError): number => {\r\n return typeof error.status === 'number' && error.status >= 400 && error.status < 600 ? error.status : 500;\r\n};\r\n\r\nconst isPublic = (error: StatusError, status: number): boolean => {\r\n return error.isPublic === true || (error.isPublic === undefined && status >= 400 && status < 500);\r\n};\r\n\r\n/**\r\n * Converts errors thrown by Next or Payload handlers into Payload-compatible\r\n * API responses without exposing messages or data from non-public errors.\r\n */\r\nexport function getHandlerErrorResponse(error: unknown): Response {\r\n const statusError = error && typeof error === 'object' ? error as StatusError : {};\r\n const status = getStatus(statusError);\r\n const publicError = isPublic(statusError, status);\r\n const message = publicError && typeof statusError.message === 'string' ?\r\n statusError.message :\r\n publicError && typeof statusError.statusText === 'string' ? statusError.statusText : 'Something went wrong.';\r\n const payloadError: PayloadErrorItem = { message };\r\n\r\n if (publicError && typeof statusError.name === 'string') {\r\n payloadError.name = statusError.name;\r\n }\r\n if (publicError && statusError.data !== null && statusError.data !== undefined) {\r\n payloadError.data = statusError.data;\r\n }\r\n\r\n return Response.json({ errors: [payloadError] }, { status });\r\n}\r\n"],"mappings":";AAeA,MAAM,YAAY,CAACA,UAA+B;AAC9C,QAAO,OAAO,MAAM,WAAW,YAAY,MAAM,UAAU,OAAO,MAAM,SAAS,MAAM,MAAM,SAAS;AACzG;AAED,MAAM,WAAW,CAACA,OAAoBC,WAA4B;AAC9D,QAAO,MAAM,aAAa,QAAS,MAAM,aAAa,UAAa,UAAU,OAAO,SAAS;AAChG;;;;;;;;AAMD,SAAgB,wBAAwBC,OAA0B;CAC9D,MAAM,cAAc,SAAS,OAAO,UAAU,WAAW,QAAuB,CAAE;CAClF,MAAM,SAAS,UAAU,YAAY;CACrC,MAAM,cAAc,SAAS,aAAa,OAAO;CACjD,MAAM,UAAU,eAAe,OAAO,YAAY,YAAY,WAC1D,YAAY,UACZ,eAAe,OAAO,YAAY,eAAe,WAAW,YAAY,aAAa;CACzF,MAAMC,eAAiC,EAAE,QAAS;AAElD,KAAI,eAAe,OAAO,YAAY,SAAS,UAC3C,aAAa,OAAO,YAAY;AAEpC,KAAI,eAAe,YAAY,SAAS,QAAQ,YAAY,SAAS,QACjE,aAAa,OAAO,YAAY;AAGpC,QAAO,SAAS,KAAK,EAAE,QAAQ,CAAC,YAAa,EAAE,GAAE,EAAE,OAAQ,EAAC;AAC/D"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.handler.d.ts","names":[],"sources":["../../../src/server/handlers/index.handler.ts"],"mappings":";;;iBAIgB,eAAA,SAAwB,QAAQ,6BACd,YAAO,QAAA"}
1
+ {"version":3,"file":"index.handler.d.ts","names":[],"sources":["../../../src/server/handlers/index.handler.ts"],"sourcesContent":[],"mappings":";;;iBAIgB,eAAA,SAAwB,QAAQ,6BACd,YAAO,QAAA"}
@@ -1,6 +1,7 @@
1
1
  import { getHandlerErrorResponse } from "./error-response.js";
2
2
  import { defaultLocale, defaultMarket } from "@websolutespa/bom-core";
3
3
  import { getPayload } from "payload";
4
+
4
5
  //#region src/server/handlers/index.handler.ts
5
6
  function indexGetHandler(config) {
6
7
  return async function(request) {
@@ -139,7 +140,7 @@ function indexGetHandler(config) {
139
140
  }
140
141
  };
141
142
  }
143
+
142
144
  //#endregion
143
145
  export { indexGetHandler };
144
-
145
146
  //# sourceMappingURL=index.handler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.handler.js","names":[],"sources":["../../../src/server/handlers/index.handler.ts"],"sourcesContent":["import { defaultLocale, defaultMarket } from '@websolutespa/bom-core';\r\nimport { getPayload, SanitizedConfig } from 'payload';\r\nimport { getHandlerErrorResponse } from './error-response';\r\n\r\nexport function indexGetHandler(config: Promise<SanitizedConfig>) {\r\n return async function (request: Request) {\r\n try {\r\n const payload = await getPayload({ config });\r\n const keys = [\r\n ...payload.config.collections.map(x => x.slug),\r\n ...payload.config.globals.map(x => x.slug),\r\n ];\r\n keys.sort();\r\n const market = defaultMarket;\r\n const locale = defaultLocale;\r\n if (!Array.isArray(keys) || keys?.length === 0) {\r\n console.error('apiHome.collectionGet', 'collections not found', keys);\r\n return new Response('method not allowed', {\r\n status: 405,\r\n statusText: 'method not allowed',\r\n });\r\n }\r\n return new Response(`\r\n <html>\r\n <head>\r\n <title>REST Api</title>\r\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\r\n <style type=\"text/css\">\r\n html {\r\n padding: 0;\r\n background: #09090A;\r\n color: #fefefe;\r\n }\r\n body {\r\n padding: 15px;\r\n font-family: Inter,-apple-system,'Helvetica Neue','Segoe UI',Roboto,Arial,'Noto Sans',sans-serif;\r\n font-size: 13px;\r\n background: #09090A;\r\n color: #fefefe;\r\n }\r\n .container {\r\n margin: 0 auto;\r\n max-width: 1280px;\r\n }\r\n a {\r\n color: #fefefe;\r\n text-decoration: none;\r\n }\r\n a:visited {\r\n color: #9e9e9e;\r\n }\r\n a:hover {\r\n text-decoration: underline;\r\n }\r\n table {\r\n width: 100%;\r\n margin: 10px 0;\r\n border: none;\r\n border-collapse: collapse;\r\n }\r\n td,\r\n th {\r\n text-align: left;\r\n font-size: 12px;\r\n padding: 3px;\r\n }\r\n th:not(:last-child),\r\n td:not(:last-child) {\r\n padding-right: 30px;\r\n }\r\n thead th {\r\n border-bottom: 1px solid #0e0e0f;\r\n }\r\n #table tr:nth-child(odd) td {\r\n background-color: #0e0e0f;\r\n }\r\n #table tbody tr:hover td {\r\n background-color: #1A1A1B;\r\n }\r\n #table tbody tr:hover td,\r\n #table tbody tr:hover td a {\r\n color: #fefefe;\r\n }\r\n .wysiwyg {\r\n margin: 0;\r\n padding: 0 0 10px 0;\r\n line-height: 1.2em;\r\n }\r\n .wysiwyg a {\r\n color: #00ea4e;\r\n font-weight: 600;\r\n }\r\n .wysiwyg a:visited {\r\n color: #00ea4e;\r\n }\r\n </style>\r\n </head>\r\n <body>\r\n <div class=\"container\">\r\n <h1>REST API</h1>\r\n <p class=\"wysiwyg\">\r\n This is the REST Api generated by <a href=\"https://github.com/websolutespa/bom\" target=\"_blank\" rel=\"noopener\">Mixer</a>.\r\n </p>\r\n <p class=\"wysiwyg\">\r\n It contains a list of all the generic local api CRUD handlers of Mixer app. <br />\r\n All methods should be called with market and locale parameters.\r\n </p>\r\n <table id=\"table\" cellpadding=\"3\">\r\n <thead>\r\n <tr>\r\n <th width=\"150px\">Method</th>\r\n <th width=\"150px\">Collection</th>\r\n <th>Endpoint</th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n ${keys.map(c => (`\r\n <tr>\r\n <td>GET, POST, PATCH</td>\r\n <td>${c}</td>\r\n <td><a href=\"/api/${c}?market=${market}&locale=${locale}\" target=\"_blank\">/api/${c}</a></td>\r\n </tr>\r\n <tr>\r\n <td>GET, DELETE</td>\r\n <td>${c}</td>\r\n <td><a href=\"/api/${c}/1?market=${market}&locale=${locale}\" target=\"_blank\">/api/${c}/{id}</a></td>\r\n </tr>\r\n `)).join('\\n')}\r\n </tbody>\r\n </table>\r\n </div>\r\n </body>\r\n `, {\r\n headers: {\r\n 'Content-Type': 'text/html; charset=UTF-8',\r\n 'X-Frame-Options': 'SAMEORIGIN',\r\n 'X-Robots-Tag': 'noindex, follow',\r\n },\r\n });\r\n } catch (error: unknown) {\r\n const response = getHandlerErrorResponse(error);\r\n console.error('storeHandler.indexGet.error', response.status, error);\r\n return response;\r\n }\r\n };\r\n}\r\n"],"mappings":";;;;AAIA,SAAgB,gBAAgB,QAAkC;CAChE,OAAO,eAAgB,SAAkB;EACvC,IAAI;GACF,MAAM,UAAU,MAAM,WAAW,EAAE,OAAO,CAAC;GAC3C,MAAM,OAAO,CACX,GAAG,QAAQ,OAAO,YAAY,KAAI,MAAK,EAAE,IAAI,GAC7C,GAAG,QAAQ,OAAO,QAAQ,KAAI,MAAK,EAAE,IAAI,CAC3C;GACA,KAAK,KAAK;GACV,MAAM,SAAS;GACf,MAAM,SAAS;GACf,IAAI,CAAC,MAAM,QAAQ,IAAI,KAAK,MAAM,WAAW,GAAG;IAC9C,QAAQ,MAAM,yBAAyB,yBAAyB,IAAI;IACpE,OAAO,IAAI,SAAS,sBAAsB;KACxC,QAAQ;KACR,YAAY;IACd,CAAC;GACH;GACA,OAAO,IAAI,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA8Fd,KAAK,KAAI,MAAM;;;oBAGP,EAAE;kCACY,EAAE,UAAU,OAAO,UAAU,OAAO,yBAAyB,EAAE;;;;oBAI7E,EAAE;kCACY,EAAE,YAAY,OAAO,UAAU,OAAO,yBAAyB,EAAE;;WAEvF,CAAC,CAAC,KAAK,IAAI,EAAE;;;;;OAKlB,EACC,SAAS;IACP,gBAAgB;IAChB,mBAAmB;IACnB,gBAAgB;GAClB,EACF,CAAC;EACH,SAAS,OAAgB;GACvB,MAAM,WAAW,wBAAwB,KAAK;GAC9C,QAAQ,MAAM,+BAA+B,SAAS,QAAQ,KAAK;GACnE,OAAO;EACT;CACF;AACF"}
1
+ {"version":3,"file":"index.handler.js","names":["config: Promise<SanitizedConfig>","request: Request","error: unknown"],"sources":["../../../src/server/handlers/index.handler.ts"],"sourcesContent":["import { defaultLocale, defaultMarket } from '@websolutespa/bom-core';\r\nimport { getPayload, SanitizedConfig } from 'payload';\r\nimport { getHandlerErrorResponse } from './error-response';\r\n\r\nexport function indexGetHandler(config: Promise<SanitizedConfig>) {\r\n return async function (request: Request) {\r\n try {\r\n const payload = await getPayload({ config });\r\n const keys = [\r\n ...payload.config.collections.map(x => x.slug),\r\n ...payload.config.globals.map(x => x.slug),\r\n ];\r\n keys.sort();\r\n const market = defaultMarket;\r\n const locale = defaultLocale;\r\n if (!Array.isArray(keys) || keys?.length === 0) {\r\n console.error('apiHome.collectionGet', 'collections not found', keys);\r\n return new Response('method not allowed', {\r\n status: 405,\r\n statusText: 'method not allowed',\r\n });\r\n }\r\n return new Response(`\r\n <html>\r\n <head>\r\n <title>REST Api</title>\r\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\r\n <style type=\"text/css\">\r\n html {\r\n padding: 0;\r\n background: #09090A;\r\n color: #fefefe;\r\n }\r\n body {\r\n padding: 15px;\r\n font-family: Inter,-apple-system,'Helvetica Neue','Segoe UI',Roboto,Arial,'Noto Sans',sans-serif;\r\n font-size: 13px;\r\n background: #09090A;\r\n color: #fefefe;\r\n }\r\n .container {\r\n margin: 0 auto;\r\n max-width: 1280px;\r\n }\r\n a {\r\n color: #fefefe;\r\n text-decoration: none;\r\n }\r\n a:visited {\r\n color: #9e9e9e;\r\n }\r\n a:hover {\r\n text-decoration: underline;\r\n }\r\n table {\r\n width: 100%;\r\n margin: 10px 0;\r\n border: none;\r\n border-collapse: collapse;\r\n }\r\n td,\r\n th {\r\n text-align: left;\r\n font-size: 12px;\r\n padding: 3px;\r\n }\r\n th:not(:last-child),\r\n td:not(:last-child) {\r\n padding-right: 30px;\r\n }\r\n thead th {\r\n border-bottom: 1px solid #0e0e0f;\r\n }\r\n #table tr:nth-child(odd) td {\r\n background-color: #0e0e0f;\r\n }\r\n #table tbody tr:hover td {\r\n background-color: #1A1A1B;\r\n }\r\n #table tbody tr:hover td,\r\n #table tbody tr:hover td a {\r\n color: #fefefe;\r\n }\r\n .wysiwyg {\r\n margin: 0;\r\n padding: 0 0 10px 0;\r\n line-height: 1.2em;\r\n }\r\n .wysiwyg a {\r\n color: #00ea4e;\r\n font-weight: 600;\r\n }\r\n .wysiwyg a:visited {\r\n color: #00ea4e;\r\n }\r\n </style>\r\n </head>\r\n <body>\r\n <div class=\"container\">\r\n <h1>REST API</h1>\r\n <p class=\"wysiwyg\">\r\n This is the REST Api generated by <a href=\"https://github.com/websolutespa/bom\" target=\"_blank\" rel=\"noopener\">Mixer</a>.\r\n </p>\r\n <p class=\"wysiwyg\">\r\n It contains a list of all the generic local api CRUD handlers of Mixer app. <br />\r\n All methods should be called with market and locale parameters.\r\n </p>\r\n <table id=\"table\" cellpadding=\"3\">\r\n <thead>\r\n <tr>\r\n <th width=\"150px\">Method</th>\r\n <th width=\"150px\">Collection</th>\r\n <th>Endpoint</th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n ${keys.map(c => (`\r\n <tr>\r\n <td>GET, POST, PATCH</td>\r\n <td>${c}</td>\r\n <td><a href=\"/api/${c}?market=${market}&locale=${locale}\" target=\"_blank\">/api/${c}</a></td>\r\n </tr>\r\n <tr>\r\n <td>GET, DELETE</td>\r\n <td>${c}</td>\r\n <td><a href=\"/api/${c}/1?market=${market}&locale=${locale}\" target=\"_blank\">/api/${c}/{id}</a></td>\r\n </tr>\r\n `)).join('\\n')}\r\n </tbody>\r\n </table>\r\n </div>\r\n </body>\r\n `, {\r\n headers: {\r\n 'Content-Type': 'text/html; charset=UTF-8',\r\n 'X-Frame-Options': 'SAMEORIGIN',\r\n 'X-Robots-Tag': 'noindex, follow',\r\n },\r\n });\r\n } catch (error: unknown) {\r\n const response = getHandlerErrorResponse(error);\r\n console.error('storeHandler.indexGet.error', response.status, error);\r\n return response;\r\n }\r\n };\r\n}\r\n"],"mappings":";;;;;AAIA,SAAgB,gBAAgBA,QAAkC;AAChE,QAAO,eAAgBC,SAAkB;AACvC,MAAI;GACF,MAAM,UAAU,MAAM,WAAW,EAAE,OAAQ,EAAC;GAC5C,MAAM,OAAO,CACX,GAAG,QAAQ,OAAO,YAAY,IAAI,OAAK,EAAE,KAAK,EAC9C,GAAG,QAAQ,OAAO,QAAQ,IAAI,OAAK,EAAE,KAAK,AAC3C;GACD,KAAK,MAAM;GACX,MAAM,SAAS;GACf,MAAM,SAAS;AACf,OAAI,CAAC,MAAM,QAAQ,KAAK,IAAI,MAAM,WAAW,GAAG;IAC9C,QAAQ,MAAM,yBAAyB,yBAAyB,KAAK;AACrE,WAAO,IAAI,SAAS,sBAAsB;KACxC,QAAQ;KACR,YAAY;IACb;GACF;AACD,UAAO,IAAI,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA8FjB,EAAE,KAAK,IAAI,OAAM,CAAC;;;kBAGV,EAAE,EAAE;gCACU,EAAE,EAAE,QAAQ,EAAE,OAAO,QAAQ,EAAE,OAAO,uBAAuB,EAAE,EAAE;;;;kBAI/E,EAAE,EAAE;gCACU,EAAE,EAAE,UAAU,EAAE,OAAO,QAAQ,EAAE,OAAO,uBAAuB,EAAE,EAAE;;UAEzF,CAAC,CAAE,CAAC,KAAK,KAAK,CAAC;;;;;IAKrB,CAAC,EAAE,EACC,SAAS;IACP,gBAAgB;IAChB,mBAAmB;IACnB,gBAAgB;GACjB,EACF;EACF,SAAQC,OAAgB;GACvB,MAAM,WAAW,wBAAwB,MAAM;GAC/C,QAAQ,MAAM,+BAA+B,SAAS,QAAQ,MAAM;AACpE,UAAO;EACR;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"preview.handler.d.ts","names":[],"sources":["../../../src/server/handlers/preview.handler.ts"],"mappings":";;;iBAKsB,cAAA,UAAwB,cAAW,QAAA"}
1
+ {"version":3,"file":"preview.handler.d.ts","names":[],"sources":["../../../src/server/handlers/preview.handler.ts"],"sourcesContent":[],"mappings":";;;iBAKsB,cAAA,UAAwB,cAAW,QAAA"}
@@ -1,15 +1,18 @@
1
1
  import { NextResponse } from "next/server";
2
2
  import { draftMode } from "next/headers";
3
+
3
4
  //#region src/server/handlers/preview.handler.ts
4
5
  async function previewHandler(request) {
5
6
  const { searchParams } = new URL(request.url);
6
- const { marketId, localeId, templateId, documentId, _status, _live } = Object.fromEntries(searchParams);
7
+ const params = Object.fromEntries(searchParams);
8
+ const { marketId, localeId, templateId, documentId, _status, _live } = params;
7
9
  const destination = `/${marketId}/${localeId}/${templateId}/${documentId}${_live ? "?_live=true" : ""}`;
8
- (await draftMode()).enable();
10
+ const draft = await draftMode();
11
+ draft.enable();
9
12
  const path = `${process.env.NEXT_PUBLIC_URL}${destination}`;
10
13
  return NextResponse.redirect(path, { status: 303 });
11
14
  }
15
+
12
16
  //#endregion
13
17
  export { previewHandler };
14
-
15
18
  //# sourceMappingURL=preview.handler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"preview.handler.js","names":[],"sources":["../../../src/server/handlers/preview.handler.ts"],"sourcesContent":["import { draftMode } from 'next/headers';\r\nimport { NextRequest, NextResponse } from 'next/server';\r\n\r\n// http://localhost:3000/api/-preview?marketId=ww&localeId=it&templateId=homepage&documentId=6a6b33177d8f191df34b33a3\r\n\r\nexport async function previewHandler(request: NextRequest) {\r\n const { searchParams } = new URL(request.url);\r\n const params = Object.fromEntries(searchParams) as {\r\n marketId: string;\r\n localeId: string;\r\n templateId: string;\r\n documentId: string;\r\n _status: 'published' | 'draft';\r\n _live: string;\r\n _token: string;\r\n };\r\n /*\r\n if (params.secret !== process.env.MIXER_SECRET) {\r\n return new Response('Invalid token', { status: 401 })\r\n }\r\n */\r\n /*\r\n const headersList = await headers()\r\n const userAgent = headersList.get('user-agent')\r\n */\r\n const { marketId, localeId, templateId, documentId, _status, _live } = params;\r\n const destination = `/${marketId}/${localeId}/${templateId}/${documentId}${_live ? '?_live=true' : ''}`;\r\n /*\r\n response.setPreviewData({ _status });\r\n response.setDraftMode({ enable: true });\r\n response.redirect(307, destination);\r\n redirect(destination, RedirectType.replace);\r\n */\r\n const draft = await draftMode();\r\n draft.enable();\r\n const path = `${process.env.NEXT_PUBLIC_URL}${destination}`;\r\n return NextResponse.redirect(path, {\r\n status: 303,\r\n });\r\n /*\r\n return NextResponse.redirect(path, {\r\n status: 303,\r\n });\r\n */\r\n /*\r\n return new Response(null, {\r\n status: 303,\r\n headers: {\r\n Location: path,\r\n },\r\n });\r\n */\r\n /*\r\n redirect(path);\r\n return;\r\n */\r\n /*\r\n return NextResponse.json({\r\n destination: destination,\r\n permanent: false\r\n });\r\n */\r\n}\r\n"],"mappings":";;;AAKA,eAAsB,eAAe,SAAsB;CACzD,MAAM,EAAE,iBAAiB,IAAI,IAAI,QAAQ,GAAG;CAmB5C,MAAM,EAAE,UAAU,UAAU,YAAY,YAAY,SAAS,UAlB9C,OAAO,YAAY,YAkB0C;CAC5E,MAAM,cAAc,IAAI,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,aAAa,QAAQ,gBAAgB;CAQnG,CAAA,MADoB,UAAU,EAAA,CACxB,OAAO;CACb,MAAM,OAAO,GAAG,QAAQ,IAAI,kBAAkB;CAC9C,OAAO,aAAa,SAAS,MAAM,EACjC,QAAQ,IACV,CAAC;AAwBH"}
1
+ {"version":3,"file":"preview.handler.js","names":["request: NextRequest"],"sources":["../../../src/server/handlers/preview.handler.ts"],"sourcesContent":["import { draftMode } from 'next/headers';\r\nimport { NextRequest, NextResponse } from 'next/server';\r\n\r\n// http://localhost:3000/api/-preview?marketId=ww&localeId=it&templateId=homepage&documentId=6a6b33177d8f191df34b33a3\r\n\r\nexport async function previewHandler(request: NextRequest) {\r\n const { searchParams } = new URL(request.url);\r\n const params = Object.fromEntries(searchParams) as {\r\n marketId: string;\r\n localeId: string;\r\n templateId: string;\r\n documentId: string;\r\n _status: 'published' | 'draft';\r\n _live: string;\r\n _token: string;\r\n };\r\n /*\r\n if (params.secret !== process.env.MIXER_SECRET) {\r\n return new Response('Invalid token', { status: 401 })\r\n }\r\n */\r\n /*\r\n const headersList = await headers()\r\n const userAgent = headersList.get('user-agent')\r\n */\r\n const { marketId, localeId, templateId, documentId, _status, _live } = params;\r\n const destination = `/${marketId}/${localeId}/${templateId}/${documentId}${_live ? '?_live=true' : ''}`;\r\n /*\r\n response.setPreviewData({ _status });\r\n response.setDraftMode({ enable: true });\r\n response.redirect(307, destination);\r\n redirect(destination, RedirectType.replace);\r\n */\r\n const draft = await draftMode();\r\n draft.enable();\r\n const path = `${process.env.NEXT_PUBLIC_URL}${destination}`;\r\n return NextResponse.redirect(path, {\r\n status: 303,\r\n });\r\n /*\r\n return NextResponse.redirect(path, {\r\n status: 303,\r\n });\r\n */\r\n /*\r\n return new Response(null, {\r\n status: 303,\r\n headers: {\r\n Location: path,\r\n },\r\n });\r\n */\r\n /*\r\n redirect(path);\r\n return;\r\n */\r\n /*\r\n return NextResponse.json({\r\n destination: destination,\r\n permanent: false\r\n });\r\n */\r\n}\r\n"],"mappings":";;;;AAKA,eAAsB,eAAeA,SAAsB;CACzD,MAAM,EAAE,cAAc,GAAG,IAAI,IAAI,QAAQ;CACzC,MAAM,SAAS,OAAO,YAAY,aAAa;CAkB/C,MAAM,EAAE,UAAU,UAAU,YAAY,YAAY,SAAS,OAAO,GAAG;CACvE,MAAM,cAAc,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,SAAS,CAAC,EAAE,WAAW,CAAC,EAAE,aAAa,QAAQ,gBAAgB,IAAI;CAOvG,MAAM,QAAQ,MAAM,WAAW;CAC/B,MAAM,QAAQ;CACd,MAAM,OAAO,GAAG,QAAQ,IAAI,kBAAkB,aAAa;AAC3D,QAAO,aAAa,SAAS,MAAM,EACjC,QAAQ,IACT,EAAC;AAwBH"}
@@ -1 +1 @@
1
- {"version":3,"file":"registry.handler.d.ts","names":[],"sources":["../../../src/server/handlers/registry.handler.ts"],"mappings":";;;iBA+OgB,WAAA,CAAA,aACkB,gBAAW,QAAA;iBAQ7B,eAAA,CAAA,aACkB;UAAa;AATF;EAD7B,MAAA,EAUgE,OAVrD,CAAA;IAAA,IAAA,EAAA,MAAA,EAAA;EACO,CAAA,CAAA;AAAW,CAAA,EAAA,GASgE,OAThE,CASgE,QAThE,CAAA;AAAA"}
1
+ {"version":3,"file":"registry.handler.d.ts","names":[],"sources":["../../../src/server/handlers/registry.handler.ts"],"sourcesContent":[],"mappings":";;;iBA+OgB,WAAA,CAAA,aACkB,gBAAW,QAAA;iBAQ7B,eAAA,CAAA,aACkB;UAAa;;EAV/B,MAAA,EAUgE,OAVrD,CAAA;IAAA,IAAA,EAAA,MAAA,EAAA;EAAA,CAAA,CAAA;CACkB,EAAA,GASgE,OAThE,CASgE,QAThE,CAAA"}
@@ -1,15 +1,16 @@
1
1
  import { readFile, readdir, stat } from "node:fs/promises";
2
2
  import { basename, dirname, extname, join, relative, resolve } from "node:path";
3
+
3
4
  //#region src/server/handlers/registry.handler.ts
4
5
  const REGISTRY_SCHEMA = "https://ui.shadcn.com/schema/registry.json";
5
6
  const REGISTRY_ITEM_SCHEMA = "https://ui.shadcn.com/schema/registry-item.json";
6
- const SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([
7
+ const SOURCE_EXTENSIONS = new Set([
7
8
  ".css",
8
9
  ".json",
9
10
  ".ts",
10
11
  ".tsx"
11
12
  ]);
12
- const PUBLISHED_DIRECTORIES = /* @__PURE__ */ new Set([
13
+ const PUBLISHED_DIRECTORIES = new Set([
13
14
  "components",
14
15
  "examples",
15
16
  "hooks",
@@ -18,7 +19,7 @@ const PUBLISHED_DIRECTORIES = /* @__PURE__ */ new Set([
18
19
  "sections",
19
20
  "theme"
20
21
  ]);
21
- const SHADCN_COMPONENTS = /* @__PURE__ */ new Set([
22
+ const SHADCN_COMPONENTS = new Set([
22
23
  "accordion",
23
24
  "alert-dialog",
24
25
  "alert",
@@ -102,7 +103,7 @@ async function getUiSourceDirectory() {
102
103
  }
103
104
  async function getSourceFiles(directory, sourceDirectory = directory) {
104
105
  const entries = await readdir(directory, { withFileTypes: true });
105
- return (await Promise.all(entries.map(async (entry) => {
106
+ const files = await Promise.all(entries.map(async (entry) => {
106
107
  const absolutePath = join(directory, entry.name);
107
108
  if (entry.isDirectory()) return getSourceFiles(absolutePath, sourceDirectory);
108
109
  if (!SOURCE_EXTENSIONS.has(extname(entry.name)) || entry.name.endsWith(".d.ts") || /\.(test|spec)\.[^.]+$/.test(entry.name)) return [];
@@ -110,7 +111,8 @@ async function getSourceFiles(directory, sourceDirectory = directory) {
110
111
  absolutePath,
111
112
  relativePath: entry.name
112
113
  }];
113
- }))).flat().map((file) => ({
114
+ }));
115
+ return files.flat().map((file) => ({
114
116
  ...file,
115
117
  relativePath: relative(sourceDirectory, file.absolutePath).replaceAll("\\", "/")
116
118
  }));
@@ -158,7 +160,8 @@ function isPublishedFile(file) {
158
160
  }
159
161
  function getRegistryItemName(file) {
160
162
  const [directory, ...path] = file.relativePath.split("/");
161
- const name = toKebabCase(path.join("/").replace(extname(file.relativePath), "").replaceAll("/", "-"));
163
+ const filename = path.join("/").replace(extname(file.relativePath), "");
164
+ const name = toKebabCase(filename.replaceAll("/", "-"));
162
165
  return directory === "components" ? name : `${directory}-${name}`;
163
166
  }
164
167
  async function createRegistryCatalog(sourceDirectory, origin) {
@@ -235,7 +238,8 @@ function jsonResponse(body, status = 200) {
235
238
  }
236
239
  function getRegistry() {
237
240
  return async function(request) {
238
- const catalog = await createRegistryCatalog(await getUiSourceDirectory(), getOrigin(request));
241
+ const sourceDirectory = await getUiSourceDirectory();
242
+ const catalog = await createRegistryCatalog(sourceDirectory, getOrigin(request));
239
243
  const items = (await Promise.all([...catalog.items].sort().map((name) => catalog.getCatalogItem(name)))).filter(Boolean);
240
244
  return jsonResponse({
241
245
  $schema: REGISTRY_SCHEMA,
@@ -250,11 +254,12 @@ function getRegistryItem() {
250
254
  const { slug } = await getParams;
251
255
  const name = slug.at(-1)?.replace(/\.json$/, "");
252
256
  if (!name) return jsonResponse({ error: "Registry item name is required." }, 404);
253
- const item = await (await createRegistryCatalog(await getUiSourceDirectory(), getOrigin(request))).getItem(name);
257
+ const sourceDirectory = await getUiSourceDirectory();
258
+ const item = await (await createRegistryCatalog(sourceDirectory, getOrigin(request))).getItem(name);
254
259
  return item ? jsonResponse(item) : jsonResponse({ error: `Registry item not found: ${name}` }, 404);
255
260
  };
256
261
  }
262
+
257
263
  //#endregion
258
264
  export { getRegistry, getRegistryItem };
259
-
260
265
  //# sourceMappingURL=registry.handler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.handler.js","names":[],"sources":["../../../src/server/handlers/registry.handler.ts"],"sourcesContent":["import { NextRequest } from 'next/server';\r\nimport { readdir, readFile, stat } from 'node:fs/promises';\r\nimport { basename, dirname, extname, join, relative, resolve } from 'node:path';\r\n\r\nconst REGISTRY_SCHEMA = 'https://ui.shadcn.com/schema/registry.json';\r\nconst REGISTRY_ITEM_SCHEMA = 'https://ui.shadcn.com/schema/registry-item.json';\r\nconst SOURCE_EXTENSIONS = new Set(['.css', '.json', '.ts', '.tsx']);\r\nconst PUBLISHED_DIRECTORIES = new Set(['components', 'examples', 'hooks', 'lazy', 'lib', 'sections', 'theme']);\r\nconst SHADCN_COMPONENTS = new Set([\r\n 'accordion', 'alert-dialog', 'alert', 'aspect-ratio', 'avatar', 'badge', 'breadcrumb', 'calendar', 'card',\r\n 'carousel', 'chart', 'checkbox', 'collapsible', 'combobox', 'command', 'context-menu', 'dialog', 'drawer',\r\n 'dropdown-menu', 'form', 'hover-card', 'input', 'input-otp', 'label', 'menubar', 'navigation-menu',\r\n 'pagination', 'popover', 'progress', 'radio-group', 'resizable', 'scroll-area', 'select', 'separator', 'sheet',\r\n 'sidebar', 'skeleton', 'slider', 'sonner', 'switch', 'table', 'tabs', 'textarea', 'toast', 'toggle',\r\n 'toggle-group', 'tooltip',\r\n]);\r\n\r\ntype RegistryFile = {\r\n path: string;\r\n content: string;\r\n type: 'registry:ui' | 'registry:lib' | 'registry:hook' | 'registry:style' | 'registry:file';\r\n target: string;\r\n};\r\n\r\ntype RegistryCatalogFile = Omit<RegistryFile, 'content'>;\r\n\r\ntype RegistryItem = {\r\n $schema: typeof REGISTRY_ITEM_SCHEMA;\r\n name: string;\r\n type: 'registry:ui';\r\n title: string;\r\n dependencies?: string[];\r\n registryDependencies?: string[];\r\n files: RegistryFile[];\r\n};\r\n\r\ntype RegistryCatalogItem = Omit<RegistryItem, 'files'> & {\r\n files: RegistryCatalogFile[];\r\n};\r\n\r\ntype SourceFile = { absolutePath: string; relativePath: string };\r\n\r\nfunction toKebabCase(value: string) {\r\n return value.replace(/([a-z0-9])([A-Z])/g, '$1-$2').replace(/[._\\s]+/g, '-').toLowerCase();\r\n}\r\n\r\nfunction titleFromName(name: string) {\r\n return name.replace(/(^|[-_])(\\w)/g, (_, __, character: string) => character.toUpperCase());\r\n}\r\n\r\nfunction packageName(specifier: string) {\r\n return specifier.startsWith('@') ? specifier.split('/').slice(0, 2).join('/') : specifier.split('/')[0];\r\n}\r\n\r\nfunction getOrigin(request: NextRequest) {\r\n return process.env.NEXT_PUBLIC_URL?.replace(/\\/$/, '') || request.nextUrl.origin;\r\n}\r\n\r\nasync function directoryExists(directory: string) {\r\n try {\r\n return (await stat(directory)).isDirectory();\r\n } catch {\r\n return false;\r\n }\r\n}\r\n\r\nasync function getUiSourceDirectory() {\r\n if (process.env.UI_REGISTRY_SOURCE_DIR) {\r\n const configuredPath = resolve(process.env.UI_REGISTRY_SOURCE_DIR);\r\n if (await directoryExists(configuredPath)) return configuredPath;\r\n throw new Error(`UI_REGISTRY_SOURCE_DIR does not exist: ${configuredPath}`);\r\n }\r\n\r\n let currentDirectory = process.cwd();\r\n while (dirname(currentDirectory) !== currentDirectory) {\r\n const candidate = join(currentDirectory, 'packages', 'ui', 'src');\r\n if (await directoryExists(candidate)) return candidate;\r\n currentDirectory = dirname(currentDirectory);\r\n }\r\n throw new Error('Unable to find packages/ui/src. Set UI_REGISTRY_SOURCE_DIR to its absolute path.');\r\n}\r\n\r\nasync function getSourceFiles(directory: string, sourceDirectory = directory): Promise<SourceFile[]> {\r\n const entries = await readdir(directory, { withFileTypes: true });\r\n const files = await Promise.all(entries.map(async entry => {\r\n const absolutePath = join(directory, entry.name);\r\n if (entry.isDirectory()) return getSourceFiles(absolutePath, sourceDirectory);\r\n if (!SOURCE_EXTENSIONS.has(extname(entry.name)) || entry.name.endsWith('.d.ts') || /\\.(test|spec)\\.[^.]+$/.test(entry.name)) return [];\r\n return [{ absolutePath, relativePath: entry.name }];\r\n }));\r\n\r\n return files.flat().map(file => ({\r\n ...file,\r\n relativePath: relative(sourceDirectory, file.absolutePath).replaceAll('\\\\', '/'),\r\n }));\r\n}\r\n\r\nfunction getImportSpecifiers(source: string) {\r\n return [...source.matchAll(/(?:import|export)\\s+(?:type\\s+)?(?:[\\s\\S]*?\\s+from\\s+)?['\"]([^'\"]+)['\"]/g)]\r\n .map(match => match[1]);\r\n}\r\n\r\nfunction resolveSourceImport(sourceDirectory: string, sourceFile: string, specifier: string, sourceFiles: Map<string, SourceFile>) {\r\n let candidate: string | undefined;\r\n if (specifier.startsWith('@app/ui/')) candidate = specifier.slice('@app/ui/'.length);\r\n if (specifier.startsWith('.')) candidate = relative(sourceDirectory, resolve(dirname(sourceFile), specifier)).replaceAll('\\\\', '/');\r\n if (!candidate) return undefined;\r\n\r\n const normalizedCandidate = candidate.replace(/^\\.\\//, '');\r\n return sourceFiles.get(normalizedCandidate) ||\r\n sourceFiles.get(`${normalizedCandidate}.ts`) || sourceFiles.get(`${normalizedCandidate}.tsx`) ||\r\n sourceFiles.get(`${normalizedCandidate}/index.ts`) || sourceFiles.get(`${normalizedCandidate}/index.tsx`);\r\n}\r\n\r\nfunction rewriteUiImports(source: string, sourceFile: SourceFile, sourceDirectory: string, sourceFiles: Map<string, SourceFile>) {\r\n return source.replace(/(['\"])(@app\\/ui\\/[^'\"]+|\\.\\.?\\/[^'\"]+)\\1/g, (match, quote: string, specifier: string) => {\r\n const importedFile = resolveSourceImport(sourceDirectory, sourceFile.absolutePath, specifier, sourceFiles);\r\n return importedFile ? `${quote}${getImportPath(importedFile.relativePath)}${quote}` : match;\r\n });\r\n}\r\n\r\nfunction getImportPath(relativePath: string) {\r\n const extensionlessPath = relativePath.replace(/\\.(tsx?|mts|cts)$/, '');\r\n if (extensionlessPath.startsWith('components/')) return `@/components/ui/${extensionlessPath.slice('components/'.length)}`;\r\n if (extensionlessPath.startsWith('hooks/')) return `@/hooks/${extensionlessPath.slice('hooks/'.length)}`;\r\n if (extensionlessPath.startsWith('lib/')) return `@/lib/${extensionlessPath.slice('lib/'.length)}`;\r\n return `@/components/${extensionlessPath}`;\r\n}\r\n\r\nfunction getTargetPath(relativePath: string) {\r\n if (relativePath.startsWith('components/')) return `@ui/${relativePath.slice('components/'.length)}`;\r\n if (relativePath.startsWith('hooks/')) return `@hooks/${relativePath.slice('hooks/'.length)}`;\r\n if (relativePath.startsWith('lib/')) return `@lib/${relativePath.slice('lib/'.length)}`;\r\n return `@components/${relativePath}`;\r\n}\r\n\r\nfunction getRegistryFileType(relativePath: string): RegistryFile['type'] {\r\n if (relativePath.startsWith('components/')) return 'registry:ui';\r\n if (relativePath.startsWith('hooks/')) return 'registry:hook';\r\n if (relativePath.startsWith('theme/')) return 'registry:style';\r\n if (extname(relativePath) === '.json') return 'registry:file';\r\n return 'registry:lib';\r\n}\r\n\r\nfunction isPublishedFile(file: SourceFile) {\r\n const [directory] = file.relativePath.split('/');\r\n return PUBLISHED_DIRECTORIES.has(directory) && !/(^|\\/)index\\.[^.]+$/.test(file.relativePath);\r\n}\r\n\r\nfunction getRegistryItemName(file: SourceFile) {\r\n const [directory, ...path] = file.relativePath.split('/');\r\n const filename = path.join('/').replace(extname(file.relativePath), '');\r\n const name = toKebabCase(filename.replaceAll('/', '-'));\r\n return directory === 'components' ? name : `${directory}-${name}`;\r\n}\r\n\r\nasync function createRegistryCatalog(sourceDirectory: string, origin: string) {\r\n const files = (await getSourceFiles(sourceDirectory)).filter(file => PUBLISHED_DIRECTORIES.has(file.relativePath.split('/')[0]));\r\n const filesByRelativePath = new Map(files.map(file => [file.relativePath, file]));\r\n const entries = new Map(files.filter(isPublishedFile).map(file => [getRegistryItemName(file), file]));\r\n const entryNamesByPath = new Map([...entries].map(([name, file]) => [file.relativePath, name]));\r\n const includedItems = new Set([...entries].filter(([name, file]) =>\r\n !file.relativePath.startsWith('components/') || name === 'button' || !SHADCN_COMPONENTS.has(name)\r\n ).map(([name]) => name));\r\n\r\n async function getItem(name: string): Promise<RegistryItem | undefined> {\r\n const entry = entries.get(name);\r\n if (!entry || !includedItems.has(name)) return undefined;\r\n\r\n const filesToInclude = new Map<string, SourceFile>();\r\n const externalDependencies = new Set<string>();\r\n const registryDependencies = new Set<string>();\r\n const pendingFiles = [entry];\r\n\r\n while (pendingFiles.length) {\r\n const file = pendingFiles.pop()!;\r\n if (filesToInclude.has(file.relativePath)) continue;\r\n filesToInclude.set(file.relativePath, file);\r\n const source = await readFile(file.absolutePath, 'utf8');\r\n\r\n for (const specifier of getImportSpecifiers(source)) {\r\n const localFile = resolveSourceImport(sourceDirectory, file.absolutePath, specifier, filesByRelativePath);\r\n const dependencyName = localFile && entryNamesByPath.get(localFile.relativePath);\r\n if (localFile?.relativePath.startsWith('components/')) {\r\n const componentName = toKebabCase(basename(localFile.relativePath, extname(localFile.relativePath)));\r\n if (dependencyName !== name) {\r\n registryDependencies.add(includedItems.has(componentName) ? `${origin}/r/${componentName}.json` : componentName);\r\n }\r\n } else if (localFile && dependencyName && dependencyName !== name && includedItems.has(dependencyName)) {\r\n registryDependencies.add(`${origin}/r/${dependencyName}.json`);\r\n } else if (localFile) {\r\n pendingFiles.push(localFile);\r\n } else if (!specifier.startsWith('.') && !specifier.startsWith('@app/ui/') && !specifier.startsWith('node:') && specifier !== 'react' && specifier !== 'react-dom') {\r\n externalDependencies.add(packageName(specifier));\r\n }\r\n }\r\n }\r\n\r\n const registryFiles = await Promise.all([...filesToInclude.values()].sort((left, right) => left.relativePath.localeCompare(right.relativePath)).map(async file => ({\r\n path: file.relativePath,\r\n content: rewriteUiImports(await readFile(file.absolutePath, 'utf8'), file, sourceDirectory, filesByRelativePath),\r\n type: getRegistryFileType(file.relativePath),\r\n target: getTargetPath(file.relativePath),\r\n })));\r\n\r\n return {\r\n $schema: REGISTRY_ITEM_SCHEMA,\r\n name,\r\n type: 'registry:ui',\r\n title: titleFromName(name),\r\n ...(externalDependencies.size && { dependencies: [...externalDependencies].sort() }),\r\n ...(registryDependencies.size && { registryDependencies: [...registryDependencies].sort() }),\r\n files: registryFiles,\r\n };\r\n }\r\n\r\n async function getCatalogItem(name: string): Promise<RegistryCatalogItem | undefined> {\r\n const item = await getItem(name);\r\n if (!item) return undefined;\r\n return {\r\n ...item,\r\n files: item.files.map(file => ({\r\n path: file.path,\r\n type: file.type,\r\n target: file.target,\r\n })),\r\n };\r\n }\r\n\r\n return { items: includedItems, getCatalogItem, getItem };\r\n}\r\n\r\nfunction jsonResponse(body: unknown, status = 200) {\r\n return Response.json(body, {\r\n status,\r\n headers: { 'X-Frame-Options': 'SAMEORIGIN', 'X-Robots-Tag': 'noindex, follow' },\r\n });\r\n}\r\n\r\nexport function getRegistry() {\r\n return async function (request: NextRequest) {\r\n const sourceDirectory = await getUiSourceDirectory();\r\n const catalog = await createRegistryCatalog(sourceDirectory, getOrigin(request));\r\n const items = (await Promise.all([...catalog.items].sort().map(name => catalog.getCatalogItem(name)))).filter(Boolean);\r\n return jsonResponse({ $schema: REGISTRY_SCHEMA, name: 'bom-ui', homepage: getOrigin(request), items });\r\n };\r\n}\r\n\r\nexport function getRegistryItem() {\r\n return async function (request: NextRequest, { params: getParams }: { params: Promise<{ slug: string[] }> }) {\r\n const { slug } = await getParams;\r\n const name = slug.at(-1)?.replace(/\\.json$/, '');\r\n if (!name) return jsonResponse({ error: 'Registry item name is required.' }, 404);\r\n\r\n const sourceDirectory = await getUiSourceDirectory();\r\n const item = await (await createRegistryCatalog(sourceDirectory, getOrigin(request))).getItem(name);\r\n return item ? jsonResponse(item) : jsonResponse({ error: `Registry item not found: ${name}` }, 404);\r\n };\r\n}\r\n"],"mappings":";;;AAIA,MAAM,kBAAkB;AACxB,MAAM,uBAAuB;AAC7B,MAAM,oCAAoB,IAAI,IAAI;CAAC;CAAQ;CAAS;CAAO;AAAM,CAAC;AAClE,MAAM,wCAAwB,IAAI,IAAI;CAAC;CAAc;CAAY;CAAS;CAAQ;CAAO;CAAY;AAAO,CAAC;AAC7G,MAAM,oCAAoB,I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AChC,OAAO,eAAgB,SAAsB,EAAE,QAAQ,aAAsD;EAC3G,MAAM,EAAE,SAAS,MAAM;EACvB,MAAM,OAAO,KAAK,GAAG,EAAE,CAAC,EAAE,QAAQ,WAAW,EAAE;EAC/C,IAAI,CAAC,MAAM,OAAO,aAAa,EAAE,OAAO,kCAAkC,GAAG,GAAG;EAGhF,MAAM,OAAO,OAAO,MAAM,sBAAsB,MADlB,qBAAqB,GACc,UAAU,OAAO,CAAC,EAAA,CAAG,QAAQ,IAAI;EAClG,OAAO,OAAO,aAAa,IAAI,IAAI,aAAa,EAAE,OAAO,4BAA4B,OAAO,GAAG,GAAG;CACpG;AACF"}
1
+ {"version":3,"file":"registry.handler.js","names":["value: string","name: string","character: string","specifier: string","request: NextRequest","directory: string","source: string","sourceDirectory: string","sourceFile: string","sourceFiles: Map<string, SourceFile>","candidate: string | undefined","sourceFile: SourceFile","quote: string","relativePath: string","file: SourceFile","origin: string","body: unknown"],"sources":["../../../src/server/handlers/registry.handler.ts"],"sourcesContent":["import { NextRequest } from 'next/server';\r\nimport { readdir, readFile, stat } from 'node:fs/promises';\r\nimport { basename, dirname, extname, join, relative, resolve } from 'node:path';\r\n\r\nconst REGISTRY_SCHEMA = 'https://ui.shadcn.com/schema/registry.json';\r\nconst REGISTRY_ITEM_SCHEMA = 'https://ui.shadcn.com/schema/registry-item.json';\r\nconst SOURCE_EXTENSIONS = new Set(['.css', '.json', '.ts', '.tsx']);\r\nconst PUBLISHED_DIRECTORIES = new Set(['components', 'examples', 'hooks', 'lazy', 'lib', 'sections', 'theme']);\r\nconst SHADCN_COMPONENTS = new Set([\r\n 'accordion', 'alert-dialog', 'alert', 'aspect-ratio', 'avatar', 'badge', 'breadcrumb', 'calendar', 'card',\r\n 'carousel', 'chart', 'checkbox', 'collapsible', 'combobox', 'command', 'context-menu', 'dialog', 'drawer',\r\n 'dropdown-menu', 'form', 'hover-card', 'input', 'input-otp', 'label', 'menubar', 'navigation-menu',\r\n 'pagination', 'popover', 'progress', 'radio-group', 'resizable', 'scroll-area', 'select', 'separator', 'sheet',\r\n 'sidebar', 'skeleton', 'slider', 'sonner', 'switch', 'table', 'tabs', 'textarea', 'toast', 'toggle',\r\n 'toggle-group', 'tooltip',\r\n]);\r\n\r\ntype RegistryFile = {\r\n path: string;\r\n content: string;\r\n type: 'registry:ui' | 'registry:lib' | 'registry:hook' | 'registry:style' | 'registry:file';\r\n target: string;\r\n};\r\n\r\ntype RegistryCatalogFile = Omit<RegistryFile, 'content'>;\r\n\r\ntype RegistryItem = {\r\n $schema: typeof REGISTRY_ITEM_SCHEMA;\r\n name: string;\r\n type: 'registry:ui';\r\n title: string;\r\n dependencies?: string[];\r\n registryDependencies?: string[];\r\n files: RegistryFile[];\r\n};\r\n\r\ntype RegistryCatalogItem = Omit<RegistryItem, 'files'> & {\r\n files: RegistryCatalogFile[];\r\n};\r\n\r\ntype SourceFile = { absolutePath: string; relativePath: string };\r\n\r\nfunction toKebabCase(value: string) {\r\n return value.replace(/([a-z0-9])([A-Z])/g, '$1-$2').replace(/[._\\s]+/g, '-').toLowerCase();\r\n}\r\n\r\nfunction titleFromName(name: string) {\r\n return name.replace(/(^|[-_])(\\w)/g, (_, __, character: string) => character.toUpperCase());\r\n}\r\n\r\nfunction packageName(specifier: string) {\r\n return specifier.startsWith('@') ? specifier.split('/').slice(0, 2).join('/') : specifier.split('/')[0];\r\n}\r\n\r\nfunction getOrigin(request: NextRequest) {\r\n return process.env.NEXT_PUBLIC_URL?.replace(/\\/$/, '') || request.nextUrl.origin;\r\n}\r\n\r\nasync function directoryExists(directory: string) {\r\n try {\r\n return (await stat(directory)).isDirectory();\r\n } catch {\r\n return false;\r\n }\r\n}\r\n\r\nasync function getUiSourceDirectory() {\r\n if (process.env.UI_REGISTRY_SOURCE_DIR) {\r\n const configuredPath = resolve(process.env.UI_REGISTRY_SOURCE_DIR);\r\n if (await directoryExists(configuredPath)) return configuredPath;\r\n throw new Error(`UI_REGISTRY_SOURCE_DIR does not exist: ${configuredPath}`);\r\n }\r\n\r\n let currentDirectory = process.cwd();\r\n while (dirname(currentDirectory) !== currentDirectory) {\r\n const candidate = join(currentDirectory, 'packages', 'ui', 'src');\r\n if (await directoryExists(candidate)) return candidate;\r\n currentDirectory = dirname(currentDirectory);\r\n }\r\n throw new Error('Unable to find packages/ui/src. Set UI_REGISTRY_SOURCE_DIR to its absolute path.');\r\n}\r\n\r\nasync function getSourceFiles(directory: string, sourceDirectory = directory): Promise<SourceFile[]> {\r\n const entries = await readdir(directory, { withFileTypes: true });\r\n const files = await Promise.all(entries.map(async entry => {\r\n const absolutePath = join(directory, entry.name);\r\n if (entry.isDirectory()) return getSourceFiles(absolutePath, sourceDirectory);\r\n if (!SOURCE_EXTENSIONS.has(extname(entry.name)) || entry.name.endsWith('.d.ts') || /\\.(test|spec)\\.[^.]+$/.test(entry.name)) return [];\r\n return [{ absolutePath, relativePath: entry.name }];\r\n }));\r\n\r\n return files.flat().map(file => ({\r\n ...file,\r\n relativePath: relative(sourceDirectory, file.absolutePath).replaceAll('\\\\', '/'),\r\n }));\r\n}\r\n\r\nfunction getImportSpecifiers(source: string) {\r\n return [...source.matchAll(/(?:import|export)\\s+(?:type\\s+)?(?:[\\s\\S]*?\\s+from\\s+)?['\"]([^'\"]+)['\"]/g)]\r\n .map(match => match[1]);\r\n}\r\n\r\nfunction resolveSourceImport(sourceDirectory: string, sourceFile: string, specifier: string, sourceFiles: Map<string, SourceFile>) {\r\n let candidate: string | undefined;\r\n if (specifier.startsWith('@app/ui/')) candidate = specifier.slice('@app/ui/'.length);\r\n if (specifier.startsWith('.')) candidate = relative(sourceDirectory, resolve(dirname(sourceFile), specifier)).replaceAll('\\\\', '/');\r\n if (!candidate) return undefined;\r\n\r\n const normalizedCandidate = candidate.replace(/^\\.\\//, '');\r\n return sourceFiles.get(normalizedCandidate) ||\r\n sourceFiles.get(`${normalizedCandidate}.ts`) || sourceFiles.get(`${normalizedCandidate}.tsx`) ||\r\n sourceFiles.get(`${normalizedCandidate}/index.ts`) || sourceFiles.get(`${normalizedCandidate}/index.tsx`);\r\n}\r\n\r\nfunction rewriteUiImports(source: string, sourceFile: SourceFile, sourceDirectory: string, sourceFiles: Map<string, SourceFile>) {\r\n return source.replace(/(['\"])(@app\\/ui\\/[^'\"]+|\\.\\.?\\/[^'\"]+)\\1/g, (match, quote: string, specifier: string) => {\r\n const importedFile = resolveSourceImport(sourceDirectory, sourceFile.absolutePath, specifier, sourceFiles);\r\n return importedFile ? `${quote}${getImportPath(importedFile.relativePath)}${quote}` : match;\r\n });\r\n}\r\n\r\nfunction getImportPath(relativePath: string) {\r\n const extensionlessPath = relativePath.replace(/\\.(tsx?|mts|cts)$/, '');\r\n if (extensionlessPath.startsWith('components/')) return `@/components/ui/${extensionlessPath.slice('components/'.length)}`;\r\n if (extensionlessPath.startsWith('hooks/')) return `@/hooks/${extensionlessPath.slice('hooks/'.length)}`;\r\n if (extensionlessPath.startsWith('lib/')) return `@/lib/${extensionlessPath.slice('lib/'.length)}`;\r\n return `@/components/${extensionlessPath}`;\r\n}\r\n\r\nfunction getTargetPath(relativePath: string) {\r\n if (relativePath.startsWith('components/')) return `@ui/${relativePath.slice('components/'.length)}`;\r\n if (relativePath.startsWith('hooks/')) return `@hooks/${relativePath.slice('hooks/'.length)}`;\r\n if (relativePath.startsWith('lib/')) return `@lib/${relativePath.slice('lib/'.length)}`;\r\n return `@components/${relativePath}`;\r\n}\r\n\r\nfunction getRegistryFileType(relativePath: string): RegistryFile['type'] {\r\n if (relativePath.startsWith('components/')) return 'registry:ui';\r\n if (relativePath.startsWith('hooks/')) return 'registry:hook';\r\n if (relativePath.startsWith('theme/')) return 'registry:style';\r\n if (extname(relativePath) === '.json') return 'registry:file';\r\n return 'registry:lib';\r\n}\r\n\r\nfunction isPublishedFile(file: SourceFile) {\r\n const [directory] = file.relativePath.split('/');\r\n return PUBLISHED_DIRECTORIES.has(directory) && !/(^|\\/)index\\.[^.]+$/.test(file.relativePath);\r\n}\r\n\r\nfunction getRegistryItemName(file: SourceFile) {\r\n const [directory, ...path] = file.relativePath.split('/');\r\n const filename = path.join('/').replace(extname(file.relativePath), '');\r\n const name = toKebabCase(filename.replaceAll('/', '-'));\r\n return directory === 'components' ? name : `${directory}-${name}`;\r\n}\r\n\r\nasync function createRegistryCatalog(sourceDirectory: string, origin: string) {\r\n const files = (await getSourceFiles(sourceDirectory)).filter(file => PUBLISHED_DIRECTORIES.has(file.relativePath.split('/')[0]));\r\n const filesByRelativePath = new Map(files.map(file => [file.relativePath, file]));\r\n const entries = new Map(files.filter(isPublishedFile).map(file => [getRegistryItemName(file), file]));\r\n const entryNamesByPath = new Map([...entries].map(([name, file]) => [file.relativePath, name]));\r\n const includedItems = new Set([...entries].filter(([name, file]) =>\r\n !file.relativePath.startsWith('components/') || name === 'button' || !SHADCN_COMPONENTS.has(name)\r\n ).map(([name]) => name));\r\n\r\n async function getItem(name: string): Promise<RegistryItem | undefined> {\r\n const entry = entries.get(name);\r\n if (!entry || !includedItems.has(name)) return undefined;\r\n\r\n const filesToInclude = new Map<string, SourceFile>();\r\n const externalDependencies = new Set<string>();\r\n const registryDependencies = new Set<string>();\r\n const pendingFiles = [entry];\r\n\r\n while (pendingFiles.length) {\r\n const file = pendingFiles.pop()!;\r\n if (filesToInclude.has(file.relativePath)) continue;\r\n filesToInclude.set(file.relativePath, file);\r\n const source = await readFile(file.absolutePath, 'utf8');\r\n\r\n for (const specifier of getImportSpecifiers(source)) {\r\n const localFile = resolveSourceImport(sourceDirectory, file.absolutePath, specifier, filesByRelativePath);\r\n const dependencyName = localFile && entryNamesByPath.get(localFile.relativePath);\r\n if (localFile?.relativePath.startsWith('components/')) {\r\n const componentName = toKebabCase(basename(localFile.relativePath, extname(localFile.relativePath)));\r\n if (dependencyName !== name) {\r\n registryDependencies.add(includedItems.has(componentName) ? `${origin}/r/${componentName}.json` : componentName);\r\n }\r\n } else if (localFile && dependencyName && dependencyName !== name && includedItems.has(dependencyName)) {\r\n registryDependencies.add(`${origin}/r/${dependencyName}.json`);\r\n } else if (localFile) {\r\n pendingFiles.push(localFile);\r\n } else if (!specifier.startsWith('.') && !specifier.startsWith('@app/ui/') && !specifier.startsWith('node:') && specifier !== 'react' && specifier !== 'react-dom') {\r\n externalDependencies.add(packageName(specifier));\r\n }\r\n }\r\n }\r\n\r\n const registryFiles = await Promise.all([...filesToInclude.values()].sort((left, right) => left.relativePath.localeCompare(right.relativePath)).map(async file => ({\r\n path: file.relativePath,\r\n content: rewriteUiImports(await readFile(file.absolutePath, 'utf8'), file, sourceDirectory, filesByRelativePath),\r\n type: getRegistryFileType(file.relativePath),\r\n target: getTargetPath(file.relativePath),\r\n })));\r\n\r\n return {\r\n $schema: REGISTRY_ITEM_SCHEMA,\r\n name,\r\n type: 'registry:ui',\r\n title: titleFromName(name),\r\n ...(externalDependencies.size && { dependencies: [...externalDependencies].sort() }),\r\n ...(registryDependencies.size && { registryDependencies: [...registryDependencies].sort() }),\r\n files: registryFiles,\r\n };\r\n }\r\n\r\n async function getCatalogItem(name: string): Promise<RegistryCatalogItem | undefined> {\r\n const item = await getItem(name);\r\n if (!item) return undefined;\r\n return {\r\n ...item,\r\n files: item.files.map(file => ({\r\n path: file.path,\r\n type: file.type,\r\n target: file.target,\r\n })),\r\n };\r\n }\r\n\r\n return { items: includedItems, getCatalogItem, getItem };\r\n}\r\n\r\nfunction jsonResponse(body: unknown, status = 200) {\r\n return Response.json(body, {\r\n status,\r\n headers: { 'X-Frame-Options': 'SAMEORIGIN', 'X-Robots-Tag': 'noindex, follow' },\r\n });\r\n}\r\n\r\nexport function getRegistry() {\r\n return async function (request: NextRequest) {\r\n const sourceDirectory = await getUiSourceDirectory();\r\n const catalog = await createRegistryCatalog(sourceDirectory, getOrigin(request));\r\n const items = (await Promise.all([...catalog.items].sort().map(name => catalog.getCatalogItem(name)))).filter(Boolean);\r\n return jsonResponse({ $schema: REGISTRY_SCHEMA, name: 'bom-ui', homepage: getOrigin(request), items });\r\n };\r\n}\r\n\r\nexport function getRegistryItem() {\r\n return async function (request: NextRequest, { params: getParams }: { params: Promise<{ slug: string[] }> }) {\r\n const { slug } = await getParams;\r\n const name = slug.at(-1)?.replace(/\\.json$/, '');\r\n if (!name) return jsonResponse({ error: 'Registry item name is required.' }, 404);\r\n\r\n const sourceDirectory = await getUiSourceDirectory();\r\n const item = await (await createRegistryCatalog(sourceDirectory, getOrigin(request))).getItem(name);\r\n return item ? jsonResponse(item) : jsonResponse({ error: `Registry item not found: ${name}` }, 404);\r\n };\r\n}\r\n"],"mappings":";;;;AAIA,MAAM,kBAAkB;AACxB,MAAM,uBAAuB;AAC7B,MAAM,oBAAoB,IAAI,IAAI;CAAC;CAAQ;CAAS;CAAO;AAAO;AAClE,MAAM,wBAAwB,IAAI,IAAI;CAAC;CAAc;CAAY;CAAS;CAAQ;CAAO;CAAY;AAAQ;AAC7G,MAAM,oBAAoB,IAAI,IAAI;CAChC;CAAa;CAAgB;CAAS;CAAgB;CAAU;CAAS;CAAc;CAAY;CACnG;CAAY;CAAS;CAAY;CAAe;CAAY;CAAW;CAAgB;CAAU;CACjG;CAAiB;CAAQ;CAAc;CAAS;CAAa;CAAS;CAAW;CACjF;CAAc;CAAW;CAAY;CAAe;CAAa;CAAe;CAAU;CAAa;CACvG;CAAW;CAAY;CAAU;CAAU;CAAU;CAAS;CAAQ;CAAY;CAAS;CAC3F;CAAgB;AACjB;AA2BD,SAAS,YAAYA,OAAe;AAClC,QAAO,MAAM,QAAQ,sBAAsB,QAAQ,CAAC,QAAQ,YAAY,IAAI,CAAC,aAAa;AAC3F;AAED,SAAS,cAAcC,MAAc;AACnC,QAAO,KAAK,QAAQ,iBAAiB,CAAC,GAAG,IAAIC,cAAsB,UAAU,aAAa,CAAC;AAC5F;AAED,SAAS,YAAYC,WAAmB;AACtC,QAAO,UAAU,WAAW,IAAI,GAAG,UAAU,MAAM,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC,KAAK,IAAI,GAAG,UAAU,MAAM,IAAI,CAAC;AAC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],"mappings":";;;;;;;AAkBA;AAA+B;AAAiB;AAAR;AACN;AAAW;AAAA;AAAA,iBAD7B,eAAA,CAC6B,MAAA,EADL,OACK,CADG,eACH,CAAA,CAAA,EAAA,CAAA,OAAA,EAAX,WAAW,EAAA,GAAA,OAAA,CAAA,QAAA,CAAA"}
1
+ {"version":3,"file":"route.handler.d.ts","names":[],"sources":["../../../src/server/handlers/route.handler.ts"],"sourcesContent":[],"mappings":";;;;;;;AAkBA;;;;;;;AAC6C,iBAD7B,eAAA,CAC6B,MAAA,EADL,OACK,CADG,eACH,CAAA,CAAA,EAAA,CAAA,OAAA,EAAX,WAAW,EAAA,GAAA,OAAA,CAAA,QAAA,CAAA"}
@@ -5,15 +5,24 @@ import { qsDeserialize } from "@websolutespa/bom-core";
5
5
  import { getRouteSnapshot, getRoutes, sortCollection, whereCollection } from "@websolutespa/payload-plugin-bowl";
6
6
  import { createPayloadRequest, getPayload } from "payload";
7
7
  import { ResponseNotFound, ResponseSuccess } from "@websolutespa/payload-utils/server";
8
+
8
9
  //#region src/server/handlers/route.handler.ts
9
10
  /**
11
+
10
12
  * Creates the internal `/-route` GET handler used by middleware to resolve CMS
13
+
11
14
  * paths, route schemas, and redirects before a page is rendered.
15
+
12
16
  *
17
+
13
18
  * One Payload request is created per incoming API request so authentication and
19
+
14
20
  * query context are shared by every route operation. The route service then
21
+
15
22
  * reuses its snapshot cache, which avoids rebuilding the complete route graph
23
+
16
24
  * for repeated market, locale, and access contexts.
25
+
17
26
  */
18
27
  function getRouteHandler(config) {
19
28
  return async function(request) {
@@ -54,8 +63,8 @@ function getRouteHandler(config) {
54
63
  const url = new URL(href);
55
64
  const urlBeforeRedirect = hrefBeforeRedirect ? new URL(hrefBeforeRedirect) : null;
56
65
  const sanitizedHref = sanitizeHref(url, urlBeforeRedirect);
57
- const { payload } = req;
58
- const payloadResponse = await payload.find({
66
+ const { payload: payload$1 } = req;
67
+ const payloadResponse = await payload$1.find({
59
68
  collection: "redirect",
60
69
  where: { isActive: { equals: true } },
61
70
  sort: "order",
@@ -116,7 +125,7 @@ function getRouteHandler(config) {
116
125
  }
117
126
  };
118
127
  }
128
+
119
129
  //#endregion
120
130
  export { getRouteHandler };
121
-
122
131
  //# sourceMappingURL=route.handler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"route.handler.js","names":["getPayload_"],"sources":["../../../src/server/handlers/route.handler.ts"],"sourcesContent":["import { IRedirect, IRoute, qsDeserialize } from '@websolutespa/bom-core';\r\nimport { getRoutes, getRouteSnapshot, sortCollection, whereCollection } from '@websolutespa/payload-plugin-bowl';\r\nimport { ResponseNotFound, ResponseSuccess } from '@websolutespa/payload-utils/server';\r\nimport { NextRequest } from 'next/server';\r\nimport { createPayloadRequest, getPayload as getPayload_, PayloadRequest, SanitizedConfig } from 'payload';\r\nimport { guest } from '../../lib/const';\r\nimport { sanitizeHref, sanitizeRedirectFrom, sanitizeRedirectTo, sanitizeRedirectUrl } from '../../lib/utils';\r\nimport { getHandlerErrorResponse } from './error-response';\r\n\r\n/**\r\n * Creates the internal `/-route` GET handler used by middleware to resolve CMS\r\n * paths, route schemas, and redirects before a page is rendered.\r\n *\r\n * One Payload request is created per incoming API request so authentication and\r\n * query context are shared by every route operation. The route service then\r\n * reuses its snapshot cache, which avoids rebuilding the complete route graph\r\n * for repeated market, locale, and access contexts.\r\n */\r\nexport function getRouteHandler(config: Promise<SanitizedConfig>) {\r\n return async function (request: NextRequest) {\r\n try {\r\n const searchParams = request.nextUrl.searchParams;\r\n const pathname = searchParams.get('pathname') || undefined;\r\n const href = searchParams.get('href') || undefined;\r\n const hrefBeforeRedirect = searchParams.get('hrefBeforeRedirect') || undefined;\r\n const schema = searchParams.get('schema') || undefined;\r\n const market = searchParams.get('market') || undefined;\r\n const locale = searchParams.get('locale') || undefined;\r\n const payload = await getPayload_({ config });\r\n const req: PayloadRequest = await createPayloadRequest({\r\n config,\r\n request,\r\n });\r\n req.payload = payload;\r\n req.user = guest as never;\r\n if (schema && market && locale) {\r\n // Schema lookups are used by middleware such as login protection. They\r\n // resolve directly from the snapshot instead of enumerating routes.\r\n req.query = { locale, market };\r\n const route = (await getRouteSnapshot(req)).getSchema(schema, market, locale);\r\n return route ? ResponseSuccess({ route }) : ResponseNotFound();\r\n }\r\n // console.log('routes.length', routes.length);\r\n if (pathname && href) {\r\n // Resolve the public path first. A successful result bypasses the\r\n // redirect collection query, the costliest branch for normal traffic.\r\n const resolution = (await getRouteSnapshot(req)).resolve(pathname);\r\n /*\r\n console.log('pathname', pathname);\r\n console.log('href', href);\r\n console.log('hrefBeforeRedirect', hrefBeforeRedirect);\r\n */\r\n const route = resolution.route;\r\n // console.log('route', route, 'pathname', pathname);\r\n if (route !== undefined) {\r\n return ResponseSuccess({\r\n parent: resolution.parent,\r\n route: {\r\n ...route,\r\n ...(resolution.splat ? { splat: resolution.splat } : {}),\r\n },\r\n });\r\n } else {\r\n const url = new URL(href);\r\n const urlBeforeRedirect = hrefBeforeRedirect ? new URL(hrefBeforeRedirect) : null;\r\n const sanitizedHref = sanitizeHref(url, urlBeforeRedirect);\r\n // Query only active redirects and request depth 0 because matching\r\n // needs scalar fields only; this minimizes Payload serialization.\r\n const { payload } = req;\r\n const payloadResponse = await payload.find({\r\n collection: 'redirect',\r\n where: {\r\n isActive: {\r\n equals: true,\r\n },\r\n },\r\n sort: 'order',\r\n depth: 0,\r\n limit: 10000,\r\n pagination: false,\r\n req,\r\n overrideAccess: true,\r\n });\r\n let redirects = (payloadResponse.docs ? payloadResponse.docs : []) as unknown as IRedirect[];\r\n redirects = redirects.map(x => ({\r\n ...x,\r\n from: sanitizeRedirectFrom(x.from, url, urlBeforeRedirect),\r\n to: sanitizeRedirectTo(x.to),\r\n }));\r\n // redirects.sort((a, b) => a.order - b.order);\r\n // exact match redirect resolver\r\n const exactMatchResolver = (redirect: IRedirect) => {\r\n const status: number = parseInt(redirect.status) || 307;\r\n if (status < 400) {\r\n const redirectUrl = sanitizeRedirectUrl(redirect.to, url);\r\n // console.log('>>>>>>>>>> findRoute exactMatchResolver', status, redirectUrl, redirect.to);\r\n return Response.json({ redirectUrl }, { status });\r\n } else {\r\n return Response.json('gone', { status });\r\n }\r\n };\r\n // check exact match redirects\r\n const exactMatchRedirect = redirects.find(x => x.from === sanitizedHref);\r\n if (exactMatchRedirect !== undefined) {\r\n // Exact matching avoids compiling patterns for the common case.\r\n return exactMatchResolver(exactMatchRedirect);\r\n }\r\n // pattern match redirect resolver\r\n const patternMatchResolver = (redirect: IRedirect) => {\r\n const status: number = parseInt(redirect.status) || 307;\r\n if (status < 400) {\r\n const regexp = new RegExp(redirect.from);\r\n let i = 0;\r\n let redirectUrl = (redirect.to as string).replace(/\\*/g, (...rest) => {\r\n return `$${++i}`;\r\n });\r\n redirectUrl = sanitizedHref.replace(regexp, redirectUrl);\r\n // console.log('>>>>>>>>>> findRoute patternMatchResolver', status, redirectUrl, redirect.to);\r\n return Response.json({ redirectUrl }, { status });\r\n } else {\r\n return Response.json('gone', { status });\r\n }\r\n };\r\n // check redirects by pattern\r\n redirects.forEach(x => {\r\n let expression = x.from;\r\n // wrapping catchall in (.*)\r\n expression = expression.replace(/\\*(?!\\))/g, '(.*)');\r\n // wrapping expression in ^...$\r\n expression = `^${expression.replace(/(^\\^)|(\\$$)/g, '')}$`;\r\n x.from = expression;\r\n });\r\n // check if a regex pattern redirect does match\r\n const firstMatch = redirects.find(x => sanitizedHref.match(x.from));\r\n // console.log('>>>>>>>>>> findRoute firstMatch', firstMatch);\r\n if (firstMatch) {\r\n return patternMatchResolver(firstMatch);\r\n }\r\n // console.error('not found', collection);\r\n // Preserve the nearest parent so middleware can render a localized\r\n // 404 without a second snapshot lookup.\r\n return ResponseSuccess({ parent: resolution.parent });\r\n }\r\n } else {\r\n // The collection branch serves management/list callers. Apply in-memory\r\n // filtering after the cached route graph is built, avoiding duplicate\r\n // collection queries for each filter or sort combination.\r\n const query = qsDeserialize(decodeURIComponent(searchParams.toString()));\r\n req.query = query;\r\n const routes = await getRoutes(req);\r\n let items = await whereCollection<IRoute>(routes, query.where);\r\n items = await sortCollection(items, query.sort);\r\n return ResponseSuccess(items);\r\n // return ResponseBadRequest();\r\n }\r\n } catch (error: unknown) {\r\n console.error('routeGetHandler.error', error);\r\n return getHandlerErrorResponse(error);\r\n }\r\n };\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;AAkBA,SAAgB,gBAAgB,QAAkC;CAChE,OAAO,eAAgB,SAAsB;EAC3C,IAAI;GACF,MAAM,eAAe,QAAQ,QAAQ;GACrC,MAAM,WAAW,aAAa,IAAI,UAAU,KAAK,KAAA;GACjD,MAAM,OAAO,aAAa,IAAI,MAAM,KAAK,KAAA;GACzC,MAAM,qBAAqB,aAAa,IAAI,oBAAoB,KAAK,KAAA;GACrE,MAAM,SAAS,aAAa,IAAI,QAAQ,KAAK,KAAA;GAC7C,MAAM,SAAS,aAAa,IAAI,QAAQ,KAAK,KAAA;GAC7C,MAAM,SAAS,aAAa,IAAI,QAAQ,KAAK,KAAA;GAC7C,MAAM,UAAU,MAAMA,WAAY,EAAE,OAAO,CAAC;GAC5C,MAAM,MAAsB,MAAM,qBAAqB;IACrD;IACA;GACF,CAAC;GACD,IAAI,UAAU;GACd,IAAI,OAAO;GACX,IAAI,UAAU,UAAU,QAAQ;IAG9B,IAAI,QAAQ;KAAE;KAAQ;IAAO;IAC7B,MAAM,SAAS,MAAM,iBAAiB,GAAG,EAAA,CAAG,UAAU,QAAQ,QAAQ,MAAM;IAC5E,OAAO,QAAQ,gBAAgB,EAAE,MAAM,CAAC,IAAI,iBAAiB;GAC/D;GAEA,IAAI,YAAY,MAAM;IAGpB,MAAM,cAAc,MAAM,iBAAiB,GAAG,EAAA,CAAG,QAAQ,QAAQ;IAMjE,MAAM,QAAQ,WAAW;IAEzB,IAAI,UAAU,KAAA,GACZ,OAAO,gBAAgB;KACrB,QAAQ,WAAW;KACnB,OAAO;MACL,GAAG;MACH,GAAI,WAAW,QAAQ,EAAE,OAAO,WAAW,MAAM,IAAI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,YAAY,GAAG,EAAE,OAAO,CAAC;MAClD,OACE,OAAO,SAAS,KAAK,QAAQ,EAAE,OAAO,CAAC;KAE3C;KAEA,UAAU,SAAQ,MAAK;MACrB,IAAI,aAAa,EAAE;MAEnB,aAAa,WAAW,QAAQ,aAAa,MAAM;MAEnD,aAAa,IAAI,WAAW,QAAQ,gBAAgB,EAAE,EAAE;MACxD,EAAE,OAAO;KACX,CAAC;KAED,MAAM,aAAa,UAAU,MAAK,MAAK,cAAc,MAAM,EAAE,IAAI,CAAC;KAElE,IAAI,YACF,OAAO,qBAAqB,UAAU;KAKxC,OAAO,gBAAgB,EAAE,QAAQ,WAAW,OAAO,CAAC;IACtD;GACF,OAAO;IAIL,MAAM,QAAQ,cAAc,mBAAmB,aAAa,SAAS,CAAC,CAAC;IACvE,IAAI,QAAQ;IACZ,MAAM,SAAS,MAAM,UAAU,GAAG;IAClC,IAAI,QAAQ,MAAM,gBAAwB,QAAQ,MAAM,KAAK;IAC7D,QAAQ,MAAM,eAAe,OAAO,MAAM,IAAI;IAC9C,OAAO,gBAAgB,KAAK;GAE9B;EACF,SAAS,OAAgB;GACvB,QAAQ,MAAM,yBAAyB,KAAK;GAC5C,OAAO,wBAAwB,KAAK;EACtC;CACF;AACF"}
1
+ {"version":3,"file":"route.handler.js","names":["config: Promise<SanitizedConfig>","request: NextRequest","getPayload_","req: PayloadRequest","payload","redirect: IRedirect","status: number","error: unknown"],"sources":["../../../src/server/handlers/route.handler.ts"],"sourcesContent":["import { IRedirect, IRoute, qsDeserialize } from '@websolutespa/bom-core';\r\nimport { getRoutes, getRouteSnapshot, sortCollection, whereCollection } from '@websolutespa/payload-plugin-bowl';\r\nimport { ResponseNotFound, ResponseSuccess } from '@websolutespa/payload-utils/server';\r\nimport { NextRequest } from 'next/server';\r\nimport { createPayloadRequest, getPayload as getPayload_, PayloadRequest, SanitizedConfig } from 'payload';\r\nimport { guest } from '../../lib/const';\r\nimport { sanitizeHref, sanitizeRedirectFrom, sanitizeRedirectTo, sanitizeRedirectUrl } from '../../lib/utils';\r\nimport { getHandlerErrorResponse } from './error-response';\r\n\r\n/**\r\n * Creates the internal `/-route` GET handler used by middleware to resolve CMS\r\n * paths, route schemas, and redirects before a page is rendered.\r\n *\r\n * One Payload request is created per incoming API request so authentication and\r\n * query context are shared by every route operation. The route service then\r\n * reuses its snapshot cache, which avoids rebuilding the complete route graph\r\n * for repeated market, locale, and access contexts.\r\n */\r\nexport function getRouteHandler(config: Promise<SanitizedConfig>) {\r\n return async function (request: NextRequest) {\r\n try {\r\n const searchParams = request.nextUrl.searchParams;\r\n const pathname = searchParams.get('pathname') || undefined;\r\n const href = searchParams.get('href') || undefined;\r\n const hrefBeforeRedirect = searchParams.get('hrefBeforeRedirect') || undefined;\r\n const schema = searchParams.get('schema') || undefined;\r\n const market = searchParams.get('market') || undefined;\r\n const locale = searchParams.get('locale') || undefined;\r\n const payload = await getPayload_({ config });\r\n const req: PayloadRequest = await createPayloadRequest({\r\n config,\r\n request,\r\n });\r\n req.payload = payload;\r\n req.user = guest as never;\r\n if (schema && market && locale) {\r\n // Schema lookups are used by middleware such as login protection. They\r\n // resolve directly from the snapshot instead of enumerating routes.\r\n req.query = { locale, market };\r\n const route = (await getRouteSnapshot(req)).getSchema(schema, market, locale);\r\n return route ? ResponseSuccess({ route }) : ResponseNotFound();\r\n }\r\n // console.log('routes.length', routes.length);\r\n if (pathname && href) {\r\n // Resolve the public path first. A successful result bypasses the\r\n // redirect collection query, the costliest branch for normal traffic.\r\n const resolution = (await getRouteSnapshot(req)).resolve(pathname);\r\n /*\r\n console.log('pathname', pathname);\r\n console.log('href', href);\r\n console.log('hrefBeforeRedirect', hrefBeforeRedirect);\r\n */\r\n const route = resolution.route;\r\n // console.log('route', route, 'pathname', pathname);\r\n if (route !== undefined) {\r\n return ResponseSuccess({\r\n parent: resolution.parent,\r\n route: {\r\n ...route,\r\n ...(resolution.splat ? { splat: resolution.splat } : {}),\r\n },\r\n });\r\n } else {\r\n const url = new URL(href);\r\n const urlBeforeRedirect = hrefBeforeRedirect ? new URL(hrefBeforeRedirect) : null;\r\n const sanitizedHref = sanitizeHref(url, urlBeforeRedirect);\r\n // Query only active redirects and request depth 0 because matching\r\n // needs scalar fields only; this minimizes Payload serialization.\r\n const { payload } = req;\r\n const payloadResponse = await payload.find({\r\n collection: 'redirect',\r\n where: {\r\n isActive: {\r\n equals: true,\r\n },\r\n },\r\n sort: 'order',\r\n depth: 0,\r\n limit: 10000,\r\n pagination: false,\r\n req,\r\n overrideAccess: true,\r\n });\r\n let redirects = (payloadResponse.docs ? payloadResponse.docs : []) as unknown as IRedirect[];\r\n redirects = redirects.map(x => ({\r\n ...x,\r\n from: sanitizeRedirectFrom(x.from, url, urlBeforeRedirect),\r\n to: sanitizeRedirectTo(x.to),\r\n }));\r\n // redirects.sort((a, b) => a.order - b.order);\r\n // exact match redirect resolver\r\n const exactMatchResolver = (redirect: IRedirect) => {\r\n const status: number = parseInt(redirect.status) || 307;\r\n if (status < 400) {\r\n const redirectUrl = sanitizeRedirectUrl(redirect.to, url);\r\n // console.log('>>>>>>>>>> findRoute exactMatchResolver', status, redirectUrl, redirect.to);\r\n return Response.json({ redirectUrl }, { status });\r\n } else {\r\n return Response.json('gone', { status });\r\n }\r\n };\r\n // check exact match redirects\r\n const exactMatchRedirect = redirects.find(x => x.from === sanitizedHref);\r\n if (exactMatchRedirect !== undefined) {\r\n // Exact matching avoids compiling patterns for the common case.\r\n return exactMatchResolver(exactMatchRedirect);\r\n }\r\n // pattern match redirect resolver\r\n const patternMatchResolver = (redirect: IRedirect) => {\r\n const status: number = parseInt(redirect.status) || 307;\r\n if (status < 400) {\r\n const regexp = new RegExp(redirect.from);\r\n let i = 0;\r\n let redirectUrl = (redirect.to as string).replace(/\\*/g, (...rest) => {\r\n return `$${++i}`;\r\n });\r\n redirectUrl = sanitizedHref.replace(regexp, redirectUrl);\r\n // console.log('>>>>>>>>>> findRoute patternMatchResolver', status, redirectUrl, redirect.to);\r\n return Response.json({ redirectUrl }, { status });\r\n } else {\r\n return Response.json('gone', { status });\r\n }\r\n };\r\n // check redirects by pattern\r\n redirects.forEach(x => {\r\n let expression = x.from;\r\n // wrapping catchall in (.*)\r\n expression = expression.replace(/\\*(?!\\))/g, '(.*)');\r\n // wrapping expression in ^...$\r\n expression = `^${expression.replace(/(^\\^)|(\\$$)/g, '')}$`;\r\n x.from = expression;\r\n });\r\n // check if a regex pattern redirect does match\r\n const firstMatch = redirects.find(x => sanitizedHref.match(x.from));\r\n // console.log('>>>>>>>>>> findRoute firstMatch', firstMatch);\r\n if (firstMatch) {\r\n return patternMatchResolver(firstMatch);\r\n }\r\n // console.error('not found', collection);\r\n // Preserve the nearest parent so middleware can render a localized\r\n // 404 without a second snapshot lookup.\r\n return ResponseSuccess({ parent: resolution.parent });\r\n }\r\n } else {\r\n // The collection branch serves management/list callers. Apply in-memory\r\n // filtering after the cached route graph is built, avoiding duplicate\r\n // collection queries for each filter or sort combination.\r\n const query = qsDeserialize(decodeURIComponent(searchParams.toString()));\r\n req.query = query;\r\n const routes = await getRoutes(req);\r\n let items = await whereCollection<IRoute>(routes, query.where);\r\n items = await sortCollection(items, query.sort);\r\n return ResponseSuccess(items);\r\n // return ResponseBadRequest();\r\n }\r\n } catch (error: unknown) {\r\n console.error('routeGetHandler.error', error);\r\n return getHandlerErrorResponse(error);\r\n }\r\n };\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,SAAgB,gBAAgBA,QAAkC;AAChE,QAAO,eAAgBC,SAAsB;AAC3C,MAAI;GACF,MAAM,eAAe,QAAQ,QAAQ;GACrC,MAAM,WAAW,aAAa,IAAI,WAAW,IAAI;GACjD,MAAM,OAAO,aAAa,IAAI,OAAO,IAAI;GACzC,MAAM,qBAAqB,aAAa,IAAI,qBAAqB,IAAI;GACrE,MAAM,SAAS,aAAa,IAAI,SAAS,IAAI;GAC7C,MAAM,SAAS,aAAa,IAAI,SAAS,IAAI;GAC7C,MAAM,S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nC,IAAI,QAAQ,MAAM,gBAAwB,QAAQ,MAAM,MAAM;IAC9D,QAAQ,MAAM,eAAe,OAAO,MAAM,KAAK;AAC/C,WAAO,gBAAgB,MAAM;GAE9B;EACF,SAAQC,OAAgB;GACvB,QAAQ,MAAM,yBAAyB,MAAM;AAC7C,UAAO,wBAAwB,MAAM;EACtC;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"sitemap.handler.d.ts","names":[],"sources":["../../../src/server/handlers/sitemap.handler.ts"],"mappings":";;;;KAQY,QAAA;;EAAA,SAAA,CAAA,EAAQ,MAAA,GAEG,IAAA;AAGvB,CAAA;AAA+B,iBAAf,eAAA,CAAe,MAAA,EAAS,OAAT,CAAiB,eAAjB,CAAA,CAAA,EAAA,CAAA,OAAA,EACG,WADH,EAAA,GACc,OADd,CACc,QADd,CAAA;AAAiB,iBA2ChC,aAAA,CA3CgC,MAAA,EA2CV,OA3CU,CA2CF,eA3CE,CAAA,CAAA,EAAA,CAAA,OAAA,EA4Cd,WA5Cc,EAAA;EAAA,MAAA,EA4CD;AA3CF,CADG,EAAA;EAAR,MAAA,EA+C5B,OA/C4B,CAAA;IACN,MAAA,CAAA,EAAA,MAAA;IAAW,MAAA,CAAA,EAAA,MAAA;EAAA,CAAA,CAAA;AAAA,CAAA,EAAA,GA+C1C,OA/C0C,CA+C1C,QA/C0C,CAAA;AA0C7B,iBAuDA,aAAA,CAvDa,MAAA,EAuDS,OAvDT,CAuDiB,eAvDjB,CAAA,CAAA,EAAA,CAAA,OAAA,EAwDK,WAxDL,EAAA;EAAA,MAAA,EAwDkB;AAvDA,CADlB,EAAA;EAAA,MAAA,EA2DjB,OA3DiB,CAAA;IAAiB,MAAA,CAAA,EAAA,MAAA;IAAR,MAAA,CAAA,EAAA,MAAA;EACJ,CAAA,CAAA;AAAa,CAAA,EAAA,GA2D5C,OA3D4C,CA2D5C,QA3D4C,CAAA;AAGnC"}
1
+ {"version":3,"file":"sitemap.handler.d.ts","names":[],"sources":["../../../src/server/handlers/sitemap.handler.ts"],"sourcesContent":[],"mappings":";;;;KAQY,QAAA;;EAAA,SAAA,CAAA,EAAQ,MAAA,GAEG,IAAA;AAGvB,CAAA;AAA+B,iBAAf,eAAA,CAAe,MAAA,EAAS,OAAT,CAAiB,eAAjB,CAAA,CAAA,EAAA,CAAA,OAAA,EACG,WADH,EAAA,GACc,OADd,CACc,QADd,CAAA;AAAiB,iBA2ChC,aAAA,CA3CgC,MAAA,EA2CV,OA3CU,CA2CF,eA3CE,CAAA,CAAA,EAAA,CAAA,OAAA,EA4Cd,WA5Cc,EAAA;EAAA,MAAA,EA4CD;AA3CF,CADG,EAAA;EAAe,MAAvB,EA+C5B,OA/C4B,CAAA;IACN,MAAA,CAAA,EAAA,MAAA;IAAW,MAAA,CAAA,EAAA,MAAA;EAAA,CAAA,CAAA;AAAA,CAAA,EAAA,GA+C1C,OA/C0C,CA+C1C,QA/C0C,CAAA;AA0C7B,iBAuDA,aAAA,CAvDa,MAAA,EAuDS,OAvDT,CAuDiB,eAvDjB,CAAA,CAAA,EAAA,CAAA,OAAA,EAwDK,WAxDL,EAAA;EAAA,MAAA,EAwDkB;CAxDlB,EAAA;EAAA,MAAA,EA2DjB,OA3DiB,CAAA;IAAiB,MAAA,CAAA,EAAA,MAAA;IAAR,MAAA,CAAA,EAAA,MAAA;EAAO,CAAA,CAAA;CACA,EAAA,GA2D1C,OA3D4C,CA2D5C,QA3D4C,CAAA"}
@@ -1,6 +1,7 @@
1
1
  import { getPayload } from "../mixer.js";
2
2
  import { getHandlerErrorResponse } from "./error-response.js";
3
3
  import { defaultLocale, defaultMarket, eachMarketLocale } from "@websolutespa/bom-core";
4
+
4
5
  //#region src/server/handlers/sitemap.handler.ts
5
6
  const origin = process.env.NEXT_PUBLIC_URL || "";
6
7
  function getSiteMapIndex(config) {
@@ -12,7 +13,7 @@ function getSiteMapIndex(config) {
12
13
  const getTime = (date) => {
13
14
  return typeof date !== "undefined" ? (typeof date === "string" ? new Date(date) : date).getTime() : 0;
14
15
  };
15
- eachMarketLocale(markets, locales, (market, locale, markets, locales) => {
16
+ eachMarketLocale(markets, locales, (market, locale, markets$1, locales$1) => {
16
17
  const sitemapRoutes = routes.filter((x) => x.market === market.id && x.locale === locale.id);
17
18
  sitemapRoutes.sort((a, b) => getTime(a.updatedAt) - getTime(b.updatedAt));
18
19
  sitemaps.push({
@@ -100,6 +101,8 @@ ${getSiteMapXMLUrls(origin, canonicalRoutes)}
100
101
  function getSiteMapXSL(config) {
101
102
  return async function(request, { params: getParams }) {
102
103
  try {
104
+ const params = await getParams;
105
+ const locale = params?.locale || defaultLocale;
103
106
  const body = `<?xml version="1.0" encoding="UTF-8"?>
104
107
  <xsl:stylesheet version="2.0"
105
108
  xmlns:html="http://www.w3.org/TR/REC-html40"
@@ -108,7 +111,7 @@ function getSiteMapXSL(config) {
108
111
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
109
112
  <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
110
113
  <xsl:template match="/">
111
- <html lang="${(await getParams)?.locale || defaultLocale}" xmlns="http://www.w3.org/1999/xhtml">
114
+ <html lang="${locale}" xmlns="http://www.w3.org/1999/xhtml">
112
115
  <head>
113
116
  <title>XML Sitemap</title>
114
117
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
@@ -285,14 +288,14 @@ function getSiteMapXMLImage(canonical) {
285
288
  <image:loc>${escapeHtml(encodeURI(`${canonical.media.src || canonical.media.url}`))}</image:loc>
286
289
  </image:image>` : "";
287
290
  }
288
- function getSiteMapXMLAlternates(origin, canonical) {
291
+ function getSiteMapXMLAlternates(origin$1, canonical) {
289
292
  return canonical.alternates.map((alternate) => `
290
- <xhtml:link href="${escapeHtml(encodeURI(`${origin}${alternate.id}`))}" hreflang="${alternate.locale}-${alternate.market}" rel="alternate" />`).join("");
293
+ <xhtml:link href="${escapeHtml(encodeURI(`${origin$1}${alternate.id}`))}" hreflang="${alternate.locale}-${alternate.market}" rel="alternate" />`).join("");
291
294
  }
292
- function getSiteMapXMLUrl(origin, canonical) {
295
+ function getSiteMapXMLUrl(origin$1, canonical) {
293
296
  return `
294
297
  <url>
295
- <loc>${escapeHtml(encodeURI(`${origin}${canonical.id}`))}</loc>${getSiteMapXMLLastMod(canonical)}${getSiteMapXMLAlternates(origin, canonical)}${getSiteMapXMLImage(canonical)}
298
+ <loc>${escapeHtml(encodeURI(`${origin$1}${canonical.id}`))}</loc>${getSiteMapXMLLastMod(canonical)}${getSiteMapXMLAlternates(origin$1, canonical)}${getSiteMapXMLImage(canonical)}
296
299
  </url>`;
297
300
  }
298
301
  function escapeHtml(string) {
@@ -329,10 +332,10 @@ function escapeHtml(string) {
329
332
  }
330
333
  return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
331
334
  }
332
- function getSiteMapXMLUrls(origin, canonicalRoutes) {
333
- return canonicalRoutes.map((canonicalRoute) => getSiteMapXMLUrl(origin, canonicalRoute)).join("");
335
+ function getSiteMapXMLUrls(origin$1, canonicalRoutes) {
336
+ return canonicalRoutes.map((canonicalRoute) => getSiteMapXMLUrl(origin$1, canonicalRoute)).join("");
334
337
  }
338
+
335
339
  //#endregion
336
340
  export { getSiteMapIndex, getSiteMapXML, getSiteMapXSL };
337
-
338
341
  //# sourceMappingURL=sitemap.handler.js.map