@amplifyup/sdk 0.1.54 → 0.1.55

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.
@@ -1,4 +1,4 @@
1
- import { i as AmplifyUpTarget } from './types-DpTzUg1C.js';
1
+ import { i as AmplifyUpTarget } from './types-Db_eLrfU.js';
2
2
 
3
3
  /**
4
4
  * On-request variant selection (tier 3).
@@ -1,4 +1,4 @@
1
- import { i as AmplifyUpTarget } from './types-DpTzUg1C.mjs';
1
+ import { i as AmplifyUpTarget } from './types-Db_eLrfU.mjs';
2
2
 
3
3
  /**
4
4
  * On-request variant selection (tier 3).
package/dist/react.d.mts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { P as PageConfig, c as AmplifyUpConfig, e as AmplifyPageContextInput, C as ContentSource, A as AmplifyContentMeta } from './types-DpTzUg1C.mjs';
3
- export { Z as ZoneConfig } from './types-DpTzUg1C.mjs';
4
- import React, { ReactNode } from 'react';
2
+ import { P as PageConfig, c as AmplifyUpConfig, e as AmplifyPageContextInput, C as ContentSource, A as AmplifyContentMeta } from './types-Db_eLrfU.mjs';
3
+ export { Z as ZoneConfig } from './types-Db_eLrfU.mjs';
4
+ import React__default, { ReactNode } from 'react';
5
5
  export { AmplifyRenderer } from './AmplifyRenderer.mjs';
6
- export { Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-CWFb7rSm.mjs';
6
+ export { Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-DaJlqU-Z.mjs';
7
7
  export { i as isComposerPreview, a as isPreviewRequest, b as isWorkingContentRequest } from './preview-_vHmzRen.mjs';
8
8
 
9
9
  type RenderComponentContext = {
@@ -97,7 +97,7 @@ declare function Field(props: {
97
97
  fallback?: ReactNode;
98
98
  className?: string;
99
99
  render?: (value: any) => ReactNode;
100
- }): string | number | true | Iterable<React.ReactNode> | react_jsx_runtime.JSX.Element | null;
100
+ }): string | number | true | Iterable<React__default.ReactNode> | react_jsx_runtime.JSX.Element | null;
101
101
  /**
102
102
  * RichText - Renders a markdown (or HTML string) value as formatted HTML.
103
103
  *
@@ -154,7 +154,7 @@ declare function Image(props: {
154
154
  */
155
155
  name?: string;
156
156
  alt?: string;
157
- } & Omit<React.ImgHTMLAttributes<HTMLImageElement>, 'src' | 'alt' | 'name'>): react_jsx_runtime.JSX.Element | null;
157
+ } & Omit<React__default.ImgHTMLAttributes<HTMLImageElement>, 'src' | 'alt' | 'name'>): react_jsx_runtime.JSX.Element | null;
158
158
 
159
159
  interface AmplifyUpContextType {
160
160
  pageConfig: PageConfig | null;
package/dist/react.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { P as PageConfig, c as AmplifyUpConfig, e as AmplifyPageContextInput, C as ContentSource, A as AmplifyContentMeta } from './types-DpTzUg1C.js';
3
- export { Z as ZoneConfig } from './types-DpTzUg1C.js';
4
- import React, { ReactNode } from 'react';
2
+ import { P as PageConfig, c as AmplifyUpConfig, e as AmplifyPageContextInput, C as ContentSource, A as AmplifyContentMeta } from './types-Db_eLrfU.js';
3
+ export { Z as ZoneConfig } from './types-Db_eLrfU.js';
4
+ import React__default, { ReactNode } from 'react';
5
5
  export { AmplifyRenderer } from './AmplifyRenderer.js';
6
- export { Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-L7zSmLFX.js';
6
+ export { Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-BqApXxQi.js';
7
7
  export { i as isComposerPreview, a as isPreviewRequest, b as isWorkingContentRequest } from './preview-_vHmzRen.js';
8
8
 
9
9
  type RenderComponentContext = {
@@ -97,7 +97,7 @@ declare function Field(props: {
97
97
  fallback?: ReactNode;
98
98
  className?: string;
99
99
  render?: (value: any) => ReactNode;
100
- }): string | number | true | Iterable<React.ReactNode> | react_jsx_runtime.JSX.Element | null;
100
+ }): string | number | true | Iterable<React__default.ReactNode> | react_jsx_runtime.JSX.Element | null;
101
101
  /**
102
102
  * RichText - Renders a markdown (or HTML string) value as formatted HTML.
103
103
  *
@@ -154,7 +154,7 @@ declare function Image(props: {
154
154
  */
155
155
  name?: string;
156
156
  alt?: string;
157
- } & Omit<React.ImgHTMLAttributes<HTMLImageElement>, 'src' | 'alt' | 'name'>): react_jsx_runtime.JSX.Element | null;
157
+ } & Omit<React__default.ImgHTMLAttributes<HTMLImageElement>, 'src' | 'alt' | 'name'>): react_jsx_runtime.JSX.Element | null;
158
158
 
159
159
  interface AmplifyUpContextType {
160
160
  pageConfig: PageConfig | null;
package/dist/react.js CHANGED
@@ -614,6 +614,49 @@ function getPageResourceFields() {
614
614
  return pageResourceFields;
615
615
  }
616
616
 
617
+ // src/debug.ts
618
+ function envFlag(value) {
619
+ if (!value) return false;
620
+ const v = value.trim().toLowerCase();
621
+ return v === "1" || v === "true" || v === "yes";
622
+ }
623
+ function readAmplifyUpDebugEnv() {
624
+ try {
625
+ if (typeof process === "undefined") return false;
626
+ return envFlag(process.env.NEXT_PUBLIC_AMPLIFYUP_DEBUG) || envFlag(process.env.AMPLIFYUP_DEBUG);
627
+ } catch {
628
+ return false;
629
+ }
630
+ }
631
+ var configDebug;
632
+ function setAmplifyUpDebug(enabled) {
633
+ configDebug = enabled;
634
+ }
635
+ function isAmplifyUpDebug() {
636
+ if (configDebug === true) return true;
637
+ if (configDebug === false) return false;
638
+ return readAmplifyUpDebugEnv();
639
+ }
640
+ var onceKeys = /* @__PURE__ */ new Set();
641
+ var onceRoute = "";
642
+ function resetOnceIfRouteChanged() {
643
+ const route = typeof window !== "undefined" ? window.location.pathname : "";
644
+ if (route === onceRoute) return;
645
+ onceKeys.clear();
646
+ onceRoute = route;
647
+ }
648
+ function sdkDebug(...args) {
649
+ if (!isAmplifyUpDebug()) return;
650
+ console.log(...args);
651
+ }
652
+ function sdkDebugOnce(key, ...args) {
653
+ if (!isAmplifyUpDebug()) return;
654
+ resetOnceIfRouteChanged();
655
+ if (onceKeys.has(key)) return;
656
+ onceKeys.add(key);
657
+ console.log(...args);
658
+ }
659
+
617
660
  // src/edge/normalizeRoute.ts
618
661
  function normalizeRoute(route) {
619
662
  let path = String(route || "").trim();
@@ -1187,13 +1230,13 @@ var AmplifyUpSDK = class {
1187
1230
  }
1188
1231
  this.config = {
1189
1232
  trackingId: previewOverrides.trackingId || config.trackingId,
1190
- debug: config.debug ?? true,
1191
- // Enable debug by default
1233
+ debug: config.debug ?? readAmplifyUpDebugEnv(),
1192
1234
  target: this.target,
1193
1235
  dev: config.dev,
1194
1236
  ...config.siteId ? { siteId: config.siteId } : {},
1195
1237
  ...config.pageContext ? { pageContext: config.pageContext } : {}
1196
1238
  };
1239
+ setAmplifyUpDebug(!!this.config.debug);
1197
1240
  if (config.pageContext) {
1198
1241
  this.pendingPageContext = config.pageContext;
1199
1242
  this.recomputeAttachedContext();
@@ -3525,23 +3568,12 @@ function Slot({
3525
3568
  className
3526
3569
  }) {
3527
3570
  const context = React.useContext(ComponentContext);
3528
- console.log(`[Slot:${name}] Rendering slot`, {
3529
- hasContext: !!context,
3530
- availableSlotKeys: context?.slots ? Object.keys(context.slots) : [],
3531
- slotContent: context?.slots?.[name] ? "EXISTS" : "MISSING",
3532
- contextSlots: context?.slots
3533
- });
3534
3571
  if (!context) {
3535
3572
  console.warn(`[AmplifyUp SDK] Slot "${name}" used outside ComponentContextProvider`);
3536
3573
  return null;
3537
3574
  }
3538
3575
  const slotContent = context.slots?.[name];
3539
3576
  const isEmpty = !slotContent;
3540
- console.log(`[Slot:${name}] Slot state`, {
3541
- isEmpty,
3542
- hasSlotContent: !!slotContent,
3543
- slotContentType: slotContent ? typeof slotContent : "null"
3544
- });
3545
3577
  const isEditorMode = typeof window !== "undefined" && // Check for preview mode flag set by proxy
3546
3578
  (window.__AMPLIFYUP_PREVIEW_MODE__ === true || // Check URL query params
3547
3579
  new URLSearchParams(window.location.search).get("preview") === "true" || new URLSearchParams(window.location.search).get("visualEditor") === "true" || // Check if in iframe from orchestrator (check referrer hostname/port)
@@ -3553,17 +3585,15 @@ function Slot({
3553
3585
  return false;
3554
3586
  }
3555
3587
  })());
3556
- console.log(`[Slot:${name}] Editor mode detection`, {
3557
- isEditorMode,
3558
- isWindowDefined: typeof window !== "undefined",
3559
- previewModeFlag: typeof window !== "undefined" ? window.__AMPLIFYUP_PREVIEW_MODE__ : void 0,
3560
- urlParams: typeof window !== "undefined" ? {
3561
- preview: new URLSearchParams(window.location.search).get("preview"),
3562
- visualEditor: new URLSearchParams(window.location.search).get("visualEditor")
3563
- } : void 0,
3564
- inIframe: typeof window !== "undefined" ? window.self !== window.top : false,
3565
- referrer: typeof window !== "undefined" && document.referrer ? document.referrer : void 0
3566
- });
3588
+ sdkDebugOnce(
3589
+ `slot:${context.layoutNodeId || ""}:${name}`,
3590
+ `[Slot:${name}]`,
3591
+ {
3592
+ isEmpty,
3593
+ isEditorMode,
3594
+ availableSlotKeys: context.slots ? Object.keys(context.slots) : []
3595
+ }
3596
+ );
3567
3597
  return /* @__PURE__ */ jsxRuntime.jsx(
3568
3598
  "div",
3569
3599
  {
@@ -4204,7 +4234,7 @@ function LiveNodeRender({
4204
4234
  layoutNodeId: nodeId
4205
4235
  }) });
4206
4236
  }
4207
- function AmplifyRenderer({
4237
+ function AmplifyRendererInner({
4208
4238
  renderComponent,
4209
4239
  pageConfig: serverPageConfig,
4210
4240
  loadingComponent,
@@ -4346,14 +4376,22 @@ function AmplifyRenderer({
4346
4376
  return `${indent}- ${n.id} (${n.componentId || "?"})${slotsDesc ? "\n" + slotsDesc : ""}`;
4347
4377
  }).join("\n");
4348
4378
  };
4349
- console.log("[AmplifyRenderer] layoutTree received:\n%s", describeLayoutTree(layoutTree2));
4379
+ sdkDebugOnce(
4380
+ `layoutTree:${pageConfig?.id || ""}:${pageConfig?.route || ""}`,
4381
+ "[AmplifyRenderer] layoutTree received:\n%s",
4382
+ describeLayoutTree(layoutTree2)
4383
+ );
4350
4384
  if (typeof window !== "undefined" && window.parent && window.parent !== window) {
4351
4385
  const message = {
4352
4386
  type: "COMPONENT_TREE",
4353
4387
  tree: componentTree
4354
4388
  };
4355
4389
  window.parent.postMessage(message, "*");
4356
- console.log("[AmplifyRenderer] Sent component tree from layoutTree:", componentTree.length, "root components");
4390
+ sdkDebug(
4391
+ "[AmplifyRenderer] Sent component tree from layoutTree:",
4392
+ componentTree.length,
4393
+ "root components"
4394
+ );
4357
4395
  }
4358
4396
  }, [pageConfig]);
4359
4397
  React.useEffect(() => {
@@ -4504,7 +4542,7 @@ function AmplifyRenderer({
4504
4542
  );
4505
4543
  }
4506
4544
  let slotChildren = {};
4507
- console.log(`[AmplifyRenderer] Rendering node ${node.id} (${node.componentId})`, {
4545
+ sdkDebugOnce(`node:${node.id}`, `[AmplifyRenderer] Rendering node ${node.id} (${node.componentId})`, {
4508
4546
  hasSlots: !!(node.slots && node.slots.length > 0),
4509
4547
  slotCount: node.slots?.length || 0,
4510
4548
  slots: node.slots?.map((s) => ({ slotId: s.slotId, zoneId: s.zoneId, childrenCount: s.children?.length || 0 }))
@@ -4513,30 +4551,13 @@ function AmplifyRenderer({
4513
4551
  for (const slot of node.slots) {
4514
4552
  const slotKey = `${node.id}-${slot.slotId}`;
4515
4553
  let childrenToRender = [];
4516
- console.log(`[AmplifyRenderer] Processing slot ${slot.slotId} for node ${node.id}`, {
4517
- slotKey,
4518
- hasZoneId: !!slot.zoneId,
4519
- hasVariants: !!slot.variants,
4520
- hasVariantCache: !!variantCache[slotKey],
4521
- directChildrenCount: slot.children?.length || 0
4522
- });
4523
4554
  if (slot.zoneId && slot.variants && variantCache[slotKey]) {
4524
4555
  childrenToRender = variantCache[slotKey].children;
4525
- console.log(`[AmplifyRenderer] Using cached variant for slot ${slot.slotId}`, {
4526
- variantId: variantCache[slotKey].variantId,
4527
- childrenCount: childrenToRender.length
4528
- });
4529
4556
  } else if (slot.zoneId && slot.variants) {
4530
4557
  const defaultVariant = slot.variants.find((v) => v.isDefault);
4531
4558
  childrenToRender = defaultVariant?.children || [];
4532
- console.log(`[AmplifyRenderer] Using default variant for slot ${slot.slotId}`, {
4533
- childrenCount: childrenToRender.length
4534
- });
4535
4559
  } else {
4536
4560
  childrenToRender = Array.isArray(slot.children) ? slot.children : [];
4537
- console.log(`[AmplifyRenderer] Using direct children for slot ${slot.slotId}`, {
4538
- childrenCount: childrenToRender.length
4539
- });
4540
4561
  }
4541
4562
  const safeChildren = Array.isArray(childrenToRender) ? childrenToRender : [];
4542
4563
  slotChildren[slot.slotId] = /* @__PURE__ */ jsxRuntime.jsx(
@@ -4551,10 +4572,6 @@ function AmplifyRenderer({
4551
4572
  },
4552
4573
  slot.slotId
4553
4574
  );
4554
- console.log(`[AmplifyRenderer] Created slot content for ${slot.slotId}`, {
4555
- slotId: slot.slotId,
4556
- renderedChildrenCount: childrenToRender.length
4557
- });
4558
4575
  }
4559
4576
  }
4560
4577
  const slotsToPass = Object.keys(slotChildren).length > 0 ? slotChildren : void 0;
@@ -4592,6 +4609,7 @@ function AmplifyRenderer({
4592
4609
  }
4593
4610
  ) : layoutTree.map((node) => /* @__PURE__ */ jsxRuntime.jsx("div", { children: renderNode(node) }, node.id)) });
4594
4611
  }
4612
+ var AmplifyRenderer = React.memo(AmplifyRendererInner);
4595
4613
  function defaultPreviewCanvas() {
4596
4614
  return /* @__PURE__ */ jsxRuntime.jsx(
4597
4615
  "div",
@@ -4695,6 +4713,12 @@ if (typeof window !== "undefined") {
4695
4713
  }
4696
4714
  }
4697
4715
  var AmplifyUpContext = React.createContext(null);
4716
+ function normalizeRoutePath2(route) {
4717
+ if (!route) return "";
4718
+ const path = route.split("?")[0] || "/";
4719
+ if (path.length > 1 && path.endsWith("/")) return path.replace(/\/+$/, "");
4720
+ return path || "/";
4721
+ }
4698
4722
  function AmplifyUpProvider({
4699
4723
  children,
4700
4724
  config,
@@ -4722,6 +4746,7 @@ function AmplifyUpProvider({
4722
4746
  }
4723
4747
  return currentPath;
4724
4748
  };
4749
+ const loadedRouteRef = React.useRef(null);
4725
4750
  const nextPathname = usePathname ? usePathname() : null;
4726
4751
  const [pathname, setPathname] = React.useState(() => {
4727
4752
  if (typeof window !== "undefined") {
@@ -4755,56 +4780,46 @@ function AmplifyUpProvider({
4755
4780
  };
4756
4781
  }
4757
4782
  }, [nextPathname]);
4758
- React.useEffect(() => {
4759
- let cancelled = false;
4760
- const sdk = getSDK();
4761
- sdk.init({
4762
- ...config,
4763
- ...pageContext ? { pageContext } : {}
4764
- }).then(() => {
4765
- if (!cancelled) {
4766
- setInitialized(true);
4767
- }
4768
- }).catch((err) => {
4769
- if (cancelled) return;
4770
- console.error("Failed to initialize AmplifyUp SDK:", err);
4771
- setError("Failed to initialize tracking");
4772
- setLoading(false);
4773
- });
4774
- return () => {
4775
- cancelled = true;
4776
- };
4777
- }, [config.trackingId, config.target, config.debug, config.dev, config.siteId, pageContext]);
4783
+ const pageContextKey = pageContext ? `${pageContext.resourceType}:${pageContext.key}` : "";
4778
4784
  React.useEffect(() => {
4779
4785
  if (!initialized || !pageContext) return;
4780
4786
  getSDK().setPageContext(pageContext);
4781
- }, [initialized, pageContext]);
4787
+ }, [initialized, pageContextKey]);
4782
4788
  React.useEffect(() => {
4783
- if (!initialized) return;
4784
4789
  let cancelled = false;
4785
- const load = async () => {
4790
+ const sdk = getSDK();
4791
+ const run = async () => {
4786
4792
  try {
4793
+ await sdk.init({
4794
+ ...config,
4795
+ ...pageContext ? { pageContext } : {}
4796
+ });
4797
+ if (cancelled) return;
4798
+ if (pageContext) sdk.setPageContext(pageContext);
4787
4799
  const actualRoute = getActualRoute();
4788
4800
  if (!actualRoute) {
4801
+ setInitialized(true);
4789
4802
  setLoading(false);
4790
4803
  return;
4791
4804
  }
4792
- const sdk = getSDK();
4793
4805
  sdk.routeChange(actualRoute);
4794
4806
  const preview = isComposerPreview();
4795
4807
  const overlay = preview || config.clientPersonalization !== false;
4796
4808
  if (!overlay) {
4809
+ setInitialized(true);
4797
4810
  setPageConfig(null);
4798
4811
  setLoading(false);
4799
4812
  return;
4800
4813
  }
4801
- setPageConfig(null);
4802
- setError(null);
4803
- setLoading(false);
4814
+ if (loadedRouteRef.current && loadedRouteRef.current !== actualRoute) {
4815
+ setPageConfig(null);
4816
+ setError(null);
4817
+ }
4804
4818
  const edgeUrl = sdk.getEdgeUrl();
4805
4819
  const orchestratorUrl = sdk.getOrchestratorUrl();
4806
4820
  const trackingId = sdk.getTrackingId();
4807
4821
  if (!trackingId || !orchestratorUrl || !edgeUrl) {
4822
+ setInitialized(true);
4808
4823
  setError("SDK not initialized");
4809
4824
  setLoading(false);
4810
4825
  return;
@@ -4840,28 +4855,37 @@ function AmplifyUpProvider({
4840
4855
  fetchOrchestratorPage: (route, isPreview) => sdk.fetchPageConfig(route, isPreview)
4841
4856
  });
4842
4857
  if (cancelled) return;
4843
- setSource(result.source);
4844
- setMeta(result.meta);
4845
- setError(result.error);
4846
- if (!result.pageConfig) {
4847
- setPageConfig({
4848
- id: "default",
4849
- route: actualRoute,
4850
- title: "Page Not Configured",
4851
- description: "This page has not been published yet.",
4852
- layoutTree: []
4853
- });
4854
- } else {
4855
- setPageConfig(result.pageConfig);
4858
+ const nextConfig = result.pageConfig || {
4859
+ id: "default",
4860
+ route: actualRoute,
4861
+ title: "Page Not Configured",
4862
+ description: "This page has not been published yet.",
4863
+ layoutTree: []
4864
+ };
4865
+ setInitialized(true);
4866
+ setSource((prev) => prev === result.source ? prev : result.source);
4867
+ setMeta(
4868
+ (prev) => prev === result.meta || JSON.stringify(prev) === JSON.stringify(result.meta) ? prev : result.meta
4869
+ );
4870
+ setError((prev) => prev === result.error ? prev : result.error);
4871
+ setPageConfig((prev) => {
4872
+ if (prev && prev.id === nextConfig.id && normalizeRoutePath2(prev.route) === normalizeRoutePath2(nextConfig.route) && JSON.stringify(prev.layoutTree) === JSON.stringify(nextConfig.layoutTree)) {
4873
+ return prev;
4874
+ }
4875
+ return nextConfig;
4876
+ });
4877
+ if (result.pageConfig) {
4856
4878
  sdk.applyResolvedPageData(
4857
4879
  result.pageConfig.pageData || null,
4858
4880
  result.pageConfig.route,
4859
4881
  extractRouteParams(result.pageConfig.route, actualRoute)
4860
4882
  );
4861
4883
  }
4884
+ loadedRouteRef.current = actualRoute;
4862
4885
  } catch (err) {
4863
4886
  if (cancelled) return;
4864
4887
  console.error("Error fetching page config:", err);
4888
+ setInitialized(true);
4865
4889
  setError(err instanceof Error ? err.message : "Unknown error");
4866
4890
  setSource(null);
4867
4891
  setMeta(null);
@@ -4869,11 +4893,20 @@ function AmplifyUpProvider({
4869
4893
  if (!cancelled) setLoading(false);
4870
4894
  }
4871
4895
  };
4872
- void load();
4896
+ void run();
4873
4897
  return () => {
4874
4898
  cancelled = true;
4875
4899
  };
4876
- }, [pathname, initialized, config.clientPersonalization]);
4900
+ }, [
4901
+ pathname,
4902
+ config.trackingId,
4903
+ config.target,
4904
+ config.debug,
4905
+ config.dev,
4906
+ config.siteId,
4907
+ config.clientPersonalization,
4908
+ pageContextKey
4909
+ ]);
4877
4910
  return /* @__PURE__ */ jsxRuntime.jsx(
4878
4911
  AmplifyUpContext.Provider,
4879
4912
  {