@amplifyup/sdk 0.3.1 → 0.3.2

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/react.mjs CHANGED
@@ -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
  }
@@ -2500,6 +2506,8 @@ Available Console Commands:
2500
2506
  if (compositionId) params.set("compositionId", compositionId);
2501
2507
  const layoutId = pageSearch.get("layoutId");
2502
2508
  if (layoutId) params.set("layoutId", layoutId);
2509
+ const previewToken = readPreviewToken(pageSearch);
2510
+ if (previewToken) params.set("previewToken", previewToken);
2503
2511
  }
2504
2512
  }
2505
2513
  if (isOnOrchestratorOrigin) {
@@ -2544,6 +2552,10 @@ Available Console Commands:
2544
2552
  if (response.status === 404) {
2545
2553
  return null;
2546
2554
  }
2555
+ if (response.status === 401) {
2556
+ const body = await response.json().catch(() => null);
2557
+ if (body?.error === PREVIEW_ACCESS_REQUIRED) throw new Error(PREVIEW_ACCESS_REQUIRED);
2558
+ }
2547
2559
  throw new Error(`Failed to fetch page: ${response.statusText}`);
2548
2560
  }
2549
2561
  const contentType = response.headers.get("content-type") || "";
@@ -5237,7 +5249,9 @@ function AmplifyRendererInner(rendererProps) {
5237
5249
  }
5238
5250
  personalizationUrl = url.toString();
5239
5251
  } else if (orchestratorUrl) {
5240
- personalizationUrl = `${orchestratorUrl}/api/personalization/variant?instanceId=${encodeURIComponent(instanceId)}&layoutId=${encodeURIComponent(pageConfig.layoutId)}&slotId=${encodeURIComponent(slot.slotId)}&nodeId=${encodeURIComponent(node.id)}`;
5252
+ const trackingId = sdk.getTrackingId();
5253
+ if (!trackingId) return;
5254
+ personalizationUrl = `${orchestratorUrl}/api/personalization/variant?trackingId=${encodeURIComponent(trackingId)}&instanceId=${encodeURIComponent(instanceId)}&layoutId=${encodeURIComponent(pageConfig.layoutId)}&slotId=${encodeURIComponent(slot.slotId)}&nodeId=${encodeURIComponent(node.id)}`;
5241
5255
  } else {
5242
5256
  return;
5243
5257
  }
@@ -5418,6 +5432,40 @@ function AmplifyRendererInner(rendererProps) {
5418
5432
  ) });
5419
5433
  }
5420
5434
  var AmplifyRenderer = memo(AmplifyRendererInner);
5435
+ var containerStyle = {
5436
+ display: "flex",
5437
+ minHeight: "50vh",
5438
+ alignItems: "center",
5439
+ justifyContent: "center",
5440
+ padding: "24px",
5441
+ fontFamily: "system-ui, sans-serif"
5442
+ };
5443
+ var cardStyle = {
5444
+ maxWidth: "24rem",
5445
+ padding: "24px",
5446
+ textAlign: "center",
5447
+ border: "1px solid #e2e8f0",
5448
+ borderRadius: "12px",
5449
+ background: "#ffffff",
5450
+ color: "#0f172a"
5451
+ };
5452
+ var headingStyle = { margin: "0 0 8px", fontSize: "18px", fontWeight: 600 };
5453
+ var bodyStyle = { margin: "0 0 16px", fontSize: "14px", lineHeight: 1.5, color: "#475569" };
5454
+ var buttonStyle = {
5455
+ padding: "8px 16px",
5456
+ border: "none",
5457
+ borderRadius: "8px",
5458
+ background: "#0f172a",
5459
+ color: "#ffffff",
5460
+ fontSize: "14px",
5461
+ fontWeight: 500,
5462
+ cursor: "pointer"
5463
+ };
5464
+ var PreviewRefreshNotice = () => /* @__PURE__ */ jsx("div", { style: containerStyle, children: /* @__PURE__ */ jsxs("div", { style: cardStyle, children: [
5465
+ /* @__PURE__ */ jsx("h2", { style: headingStyle, children: "This preview needs a refresh" }),
5466
+ /* @__PURE__ */ jsx("p", { style: bodyStyle, children: "Reload it to keep seeing your latest changes." }),
5467
+ /* @__PURE__ */ jsx("button", { type: "button", style: buttonStyle, onClick: () => window.location.reload(), children: "Reload preview" })
5468
+ ] }) });
5421
5469
  function previewPageSlot(state) {
5422
5470
  return /* @__PURE__ */ jsx(
5423
5471
  "div",
@@ -5486,6 +5534,9 @@ function AmplifyPageContent(contentProps) {
5486
5534
  const previewEmpty = previewEmptyComponent ?? previewPageSlot("empty");
5487
5535
  const previewLoading = previewLoadingComponent ?? previewPageSlot("loading");
5488
5536
  if (preview) {
5537
+ if (client.error === PREVIEW_ACCESS_REQUIRED && !pageConfig) {
5538
+ return /* @__PURE__ */ jsx(PreviewRefreshNotice, {});
5539
+ }
5489
5540
  const ready = previewLayoutReady({
5490
5541
  clientLoading: client.loading,
5491
5542
  hasClientLayout: !!clientLayout,