@amplifyup/sdk 0.3.1 → 0.3.2-uat.107.gfe9868a

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/index.js CHANGED
@@ -396,6 +396,12 @@ function resolveAmplifyUpUrls(target) {
396
396
  function isPreviewRequest(searchParams) {
397
397
  return paramIsTrue(searchParams, "preview") || paramIsTrue(searchParams, "visualEditor");
398
398
  }
399
+ var PREVIEW_ACCESS_REQUIRED = "preview_access_required";
400
+ function readPreviewToken(searchParams) {
401
+ if (searchParams instanceof URLSearchParams) return searchParams.get("previewToken");
402
+ const value = searchParams.previewToken;
403
+ return (Array.isArray(value) ? value[0] : value) || null;
404
+ }
399
405
  function isWorkingContentRequest(searchParams) {
400
406
  return paramIsTrue(searchParams, "working");
401
407
  }
@@ -2425,6 +2431,8 @@ Available Console Commands:
2425
2431
  if (compositionId) params.set("compositionId", compositionId);
2426
2432
  const layoutId = pageSearch.get("layoutId");
2427
2433
  if (layoutId) params.set("layoutId", layoutId);
2434
+ const previewToken = readPreviewToken(pageSearch);
2435
+ if (previewToken) params.set("previewToken", previewToken);
2428
2436
  }
2429
2437
  }
2430
2438
  if (isOnOrchestratorOrigin) {
@@ -2469,6 +2477,10 @@ Available Console Commands:
2469
2477
  if (response.status === 404) {
2470
2478
  return null;
2471
2479
  }
2480
+ if (response.status === 401) {
2481
+ const body = await response.json().catch(() => null);
2482
+ if (body?.error === PREVIEW_ACCESS_REQUIRED) throw new Error(PREVIEW_ACCESS_REQUIRED);
2483
+ }
2472
2484
  throw new Error(`Failed to fetch page: ${response.statusText}`);
2473
2485
  }
2474
2486
  const contentType = response.headers.get("content-type") || "";