@weaverse/next 0.1.0-alpha.18 → 0.1.0-alpha.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.js CHANGED
@@ -150,6 +150,82 @@ function getWeaverseNextConfigs(context, options = {}) {
150
150
  };
151
151
  }
152
152
 
153
+ // src/request-info.ts
154
+ function toUrl2(value) {
155
+ return typeof value === "string" ? new URL(value, "http://localhost") : value;
156
+ }
157
+ function getSearchParamsFromContext(context) {
158
+ if (context?.searchParams) {
159
+ return new URLSearchParams(context.searchParams);
160
+ }
161
+ if (context?.url) {
162
+ let url = toUrl2(context.url);
163
+ return new URLSearchParams(url.searchParams);
164
+ }
165
+ return new URLSearchParams();
166
+ }
167
+ function withPathPrefix(pathname, i18n) {
168
+ let raw = typeof i18n?.pathPrefix === "string" ? i18n.pathPrefix : "";
169
+ let segments = raw.split("/").filter(Boolean);
170
+ let prefix = segments.length > 0 ? `/${segments.join("/")}` : "";
171
+ if (prefix === "" || pathname === prefix || pathname.startsWith(`${prefix}/`)) {
172
+ return pathname;
173
+ }
174
+ return pathname === "/" ? prefix : `${prefix}${pathname}`;
175
+ }
176
+ function getPathnameFromContext(context) {
177
+ if (context?.pathname) {
178
+ return withPathPrefix(context.pathname, context.i18n);
179
+ }
180
+ if (context?.url) {
181
+ let url = toUrl2(context.url);
182
+ return withPathPrefix(url.pathname || "/", context.i18n);
183
+ }
184
+ return "/";
185
+ }
186
+ function coerceQueryValue(value) {
187
+ if (value === "true") {
188
+ return true;
189
+ }
190
+ if (value === "false") {
191
+ return false;
192
+ }
193
+ return value;
194
+ }
195
+ function toQueryRecord(searchParams) {
196
+ let queries = {};
197
+ for (let [key, value] of searchParams.entries()) {
198
+ queries[key] = coerceQueryValue(value);
199
+ }
200
+ return queries;
201
+ }
202
+ var TRANSIENT_STUDIO_PARAMS = /* @__PURE__ */ new Set([
203
+ "weaverseDraftItem",
204
+ // Legacy name from the original design-mode draft-item spike. Keep it out of
205
+ // runtime requestInfo too, in case an older Builder bundle is in front of a
206
+ // newer Next storefront.
207
+ "__weaverseDraftItem"
208
+ ]);
209
+ function getRequestInfoSearchParams(context) {
210
+ let searchParams = new URLSearchParams(getSearchParamsFromContext(context));
211
+ for (let key of TRANSIENT_STUDIO_PARAMS) {
212
+ searchParams.delete(key);
213
+ }
214
+ return searchParams;
215
+ }
216
+ function buildWeaverseNextRequestInfo(context) {
217
+ let searchParams = getRequestInfoSearchParams(context);
218
+ let search = searchParams.toString();
219
+ return {
220
+ pathname: getPathnameFromContext(context),
221
+ search: search ? `?${search}` : "",
222
+ queries: toQueryRecord(searchParams),
223
+ ...context?.i18n ? { i18n: context.i18n } : {},
224
+ ...context?.pageType ? { pageType: context.pageType } : {},
225
+ ...context?.handle ? { handle: context.handle } : {}
226
+ };
227
+ }
228
+
153
229
  // src/server/normalize-page-url.ts
154
230
  var KEPT_PARAM_RE = /^(?:__revisionId|__weaverseDraftItem|isDesignMode|weaverse)/;
155
231
  var DATA_SUFFIX = ".data";
@@ -175,9 +251,16 @@ function normalizeNextPageUrl(url) {
175
251
  }
176
252
  function resolveRequestUrl(context) {
177
253
  if (context?.url) {
178
- return typeof context.url === "string" ? context.url : context.url.toString();
254
+ let raw = String(context.url);
255
+ let url = new URL(raw, "http://localhost");
256
+ let pathname2 = withPathPrefix(url.pathname, context.i18n);
257
+ if (pathname2 === url.pathname) {
258
+ return raw;
259
+ }
260
+ url.pathname = pathname2;
261
+ return url.toString();
179
262
  }
180
- let pathname = context?.pathname || "/";
263
+ let pathname = withPathPrefix(context?.pathname || "/", context?.i18n);
181
264
  let search = context?.searchParams ? new URLSearchParams(context.searchParams).toString() : "";
182
265
  return `http://localhost${pathname}${search ? `?${search}` : ""}`;
183
266
  }
@@ -512,73 +595,6 @@ async function runWeaverseComponentLoaders(args) {
512
595
  return data;
513
596
  }
514
597
 
515
- // src/request-info.ts
516
- function toUrl2(value) {
517
- return typeof value === "string" ? new URL(value, "http://localhost") : value;
518
- }
519
- function getSearchParamsFromContext(context) {
520
- if (context?.searchParams) {
521
- return new URLSearchParams(context.searchParams);
522
- }
523
- if (context?.url) {
524
- let url = toUrl2(context.url);
525
- return new URLSearchParams(url.searchParams);
526
- }
527
- return new URLSearchParams();
528
- }
529
- function getPathnameFromContext(context) {
530
- if (context?.pathname) {
531
- return context.pathname;
532
- }
533
- if (context?.url) {
534
- let url = toUrl2(context.url);
535
- return url.pathname || "/";
536
- }
537
- return "/";
538
- }
539
- function coerceQueryValue(value) {
540
- if (value === "true") {
541
- return true;
542
- }
543
- if (value === "false") {
544
- return false;
545
- }
546
- return value;
547
- }
548
- function toQueryRecord(searchParams) {
549
- let queries = {};
550
- for (let [key, value] of searchParams.entries()) {
551
- queries[key] = coerceQueryValue(value);
552
- }
553
- return queries;
554
- }
555
- var TRANSIENT_STUDIO_PARAMS = /* @__PURE__ */ new Set([
556
- "weaverseDraftItem",
557
- // Legacy name from the original design-mode draft-item spike. Keep it out of
558
- // runtime requestInfo too, in case an older Builder bundle is in front of a
559
- // newer Next storefront.
560
- "__weaverseDraftItem"
561
- ]);
562
- function getRequestInfoSearchParams(context) {
563
- let searchParams = new URLSearchParams(getSearchParamsFromContext(context));
564
- for (let key of TRANSIENT_STUDIO_PARAMS) {
565
- searchParams.delete(key);
566
- }
567
- return searchParams;
568
- }
569
- function buildWeaverseNextRequestInfo(context) {
570
- let searchParams = getRequestInfoSearchParams(context);
571
- let search = searchParams.toString();
572
- return {
573
- pathname: getPathnameFromContext(context),
574
- search: search ? `?${search}` : "",
575
- queries: toQueryRecord(searchParams),
576
- ...context?.i18n ? { i18n: context.i18n } : {},
577
- ...context?.pageType ? { pageType: context.pageType } : {},
578
- ...context?.handle ? { handle: context.handle } : {}
579
- };
580
- }
581
-
582
598
  // src/server/server-client.ts
583
599
  var DEFAULT_FETCH_TIMEOUT_MS = 1e4;
584
600
  var RANDOM_ID_RADIX = 36;