@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.
@@ -403,6 +403,12 @@ function resolveAmplifyUpUrls(target) {
403
403
  function isPreviewRequest(searchParams) {
404
404
  return paramIsTrue(searchParams, "preview") || paramIsTrue(searchParams, "visualEditor");
405
405
  }
406
+ var PREVIEW_ACCESS_REQUIRED = "preview_access_required";
407
+ function readPreviewToken(searchParams) {
408
+ if (searchParams instanceof URLSearchParams) return searchParams.get("previewToken");
409
+ const value = searchParams.previewToken;
410
+ return (Array.isArray(value) ? value[0] : value) || null;
411
+ }
406
412
  function isWorkingContentRequest(searchParams) {
407
413
  return paramIsTrue(searchParams, "working");
408
414
  }
@@ -2112,6 +2118,8 @@ Available Console Commands:
2112
2118
  if (compositionId) params.set("compositionId", compositionId);
2113
2119
  const layoutId = pageSearch.get("layoutId");
2114
2120
  if (layoutId) params.set("layoutId", layoutId);
2121
+ const previewToken = readPreviewToken(pageSearch);
2122
+ if (previewToken) params.set("previewToken", previewToken);
2115
2123
  }
2116
2124
  }
2117
2125
  if (isOnOrchestratorOrigin) {
@@ -2156,6 +2164,10 @@ Available Console Commands:
2156
2164
  if (response.status === 404) {
2157
2165
  return null;
2158
2166
  }
2167
+ if (response.status === 401) {
2168
+ const body = await response.json().catch(() => null);
2169
+ if (body?.error === PREVIEW_ACCESS_REQUIRED) throw new Error(PREVIEW_ACCESS_REQUIRED);
2170
+ }
2159
2171
  throw new Error(`Failed to fetch page: ${response.statusText}`);
2160
2172
  }
2161
2173
  const contentType = response.headers.get("content-type") || "";
@@ -4034,7 +4046,9 @@ function AmplifyRendererInner(rendererProps) {
4034
4046
  }
4035
4047
  personalizationUrl = url.toString();
4036
4048
  } else if (orchestratorUrl) {
4037
- personalizationUrl = `${orchestratorUrl}/api/personalization/variant?instanceId=${encodeURIComponent(instanceId)}&layoutId=${encodeURIComponent(pageConfig.layoutId)}&slotId=${encodeURIComponent(slot.slotId)}&nodeId=${encodeURIComponent(node.id)}`;
4049
+ const trackingId = sdk.getTrackingId();
4050
+ if (!trackingId) return;
4051
+ personalizationUrl = `${orchestratorUrl}/api/personalization/variant?trackingId=${encodeURIComponent(trackingId)}&instanceId=${encodeURIComponent(instanceId)}&layoutId=${encodeURIComponent(pageConfig.layoutId)}&slotId=${encodeURIComponent(slot.slotId)}&nodeId=${encodeURIComponent(node.id)}`;
4038
4052
  } else {
4039
4053
  return;
4040
4054
  }