@amplifyup/sdk 0.1.76 → 0.1.78

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/README.md CHANGED
@@ -550,6 +550,8 @@ Pass `pageContext` at provider/init for From-page components. Do not wait until
550
550
 
551
551
  The SDK maps Edge's resolved tree into `layoutTree` and renders it. Edge already applies personalization and CMS projection — the site does not call CMS or Decision APIs for layout. After paint, the overlay calls `POST /v1/select` (or `selectVariants()`) then `/v1/resolve?variants=` so decisions stay on the edge (`clientPersonalization`).
552
552
 
553
+ Wrap your whole site in `AmplifyUpProvider` so every page is tracked. The overlay only runs on pages that render `AmplifyPageContent` (or `AmplifyRenderer` without a `pageConfig`). Pages you build yourself are tracked but never request a layout.
554
+
553
555
  ## Runtime queries
554
556
 
555
557
  Page resolve covers data known at Deploy. For data a visitor asks for — search, load more, a picker — use `queryContent`. The browser asks AmplifyUp, AmplifyUp asks your content source, so no CMS credentials or query syntax live in your site.
@@ -168,6 +168,7 @@ var AWSAdapter = class {
168
168
  return;
169
169
  }
170
170
  const trackingId = eventData?.trackingId || this.config?.trackingId;
171
+ const debug = this.config?.debug;
171
172
  const query = trackingId ? `?tid=${encodeURIComponent(trackingId)}` : "";
172
173
  const url = `${this.apiGatewayUrl}${endpoint}${query}`;
173
174
  try {
@@ -182,15 +183,15 @@ var AWSAdapter = class {
182
183
  keepalive: true
183
184
  });
184
185
  if (!response.ok) {
185
- if (this.config.debug) {
186
+ if (debug) {
186
187
  console.warn(`AmplifyUp SDK: Event tracking failed: ${response.status} ${response.statusText}`);
187
188
  }
188
- } else if (this.config.debug) {
189
+ } else if (debug) {
189
190
  const result = await response.json().catch(() => ({}));
190
191
  console.log("AmplifyUp SDK: Event tracked", result);
191
192
  }
192
193
  } catch (error) {
193
- if (this.config.debug) {
194
+ if (debug) {
194
195
  console.error("AmplifyUp SDK: Event tracking error:", error);
195
196
  }
196
197
  }
@@ -3565,6 +3566,14 @@ function getSDK(adapter) {
3565
3566
  var trackContentView = (contentId, contentType, properties) => getSDK().trackContentView(contentId, contentType, properties);
3566
3567
  var refreshEventTracking = () => getSDK().refreshEventTracking();
3567
3568
  getSDK();
3569
+ var PageContentRegistryContext = react.createContext(null);
3570
+ function useRegisterPageContent(enabled = true) {
3571
+ const register = react.useContext(PageContentRegistryContext);
3572
+ react.useEffect(() => {
3573
+ if (!enabled || !register) return;
3574
+ return register();
3575
+ }, [enabled, register]);
3576
+ }
3568
3577
  function useInComposer(force = false) {
3569
3578
  const [detected, setDetected] = react.useState(false);
3570
3579
  react.useEffect(() => {
@@ -3626,14 +3635,16 @@ function applyComposerPatch(store, name, value, ref, layoutNodeId) {
3626
3635
  store.set(composerStoreKey(name, ref, layoutNodeId), value);
3627
3636
  }
3628
3637
  function ComposerProvider({
3629
- children
3638
+ children,
3639
+ enabled = true
3630
3640
  }) {
3631
3641
  const existing = react.useContext(ComposerStoreContext);
3632
3642
  const storeRef = react.useRef(null);
3633
3643
  if (!storeRef.current) storeRef.current = new ComposerFieldStore();
3634
- const store = existing || storeRef.current;
3644
+ const ownsStore = !existing && enabled;
3645
+ const store = existing || (enabled ? storeRef.current : null);
3635
3646
  react.useEffect(() => {
3636
- if (existing) return;
3647
+ if (!ownsStore || !store) return;
3637
3648
  const applyField = (fieldName, value, nodeId, ref) => {
3638
3649
  if (!fieldName || typeof fieldName !== "string") return;
3639
3650
  const fieldRef = isFieldRef(ref) ? ref : void 0;
@@ -3691,8 +3702,7 @@ function ComposerProvider({
3691
3702
  window.removeEventListener("amplifyup:props-patch", onPropsPatch);
3692
3703
  window.removeEventListener("message", onMessage);
3693
3704
  };
3694
- }, [existing, store]);
3695
- if (existing) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
3705
+ }, [ownsStore, store]);
3696
3706
  return /* @__PURE__ */ jsxRuntime.jsx(ComposerStoreContext.Provider, { value: store, children });
3697
3707
  }
3698
3708
  function MaybeComposerProvider({
@@ -3700,9 +3710,7 @@ function MaybeComposerProvider({
3700
3710
  layoutNodeId,
3701
3711
  children
3702
3712
  }) {
3703
- const content = react.useMemo(() => children, [children]);
3704
- if (!enabled) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: content });
3705
- return /* @__PURE__ */ jsxRuntime.jsx(ComposerProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(ComposerNodeContext.Provider, { value: layoutNodeId, children }) });
3713
+ return /* @__PURE__ */ jsxRuntime.jsx(ComposerProvider, { enabled, children: /* @__PURE__ */ jsxRuntime.jsx(ComposerNodeContext.Provider, { value: enabled ? layoutNodeId : void 0, children }) });
3706
3714
  }
3707
3715
  react.createContext(null);
3708
3716
  var usePathname = null;
@@ -3807,6 +3815,7 @@ function AmplifyRendererInner({
3807
3815
  composerPreview
3808
3816
  }) {
3809
3817
  const clientHook = useAmplifyUp();
3818
+ useRegisterPageContent(!serverPageConfig);
3810
3819
  const composerPreviewFlag = useComposerPreviewFlag(!!composerPreview);
3811
3820
  const pageConfig = serverPageConfig || clientHook.pageConfig || null;
3812
3821
  const loading = serverPageConfig ? false : clientHook.loading;
@@ -4154,17 +4163,16 @@ function AmplifyRendererInner({
4154
4163
  if (layoutTree.length === 0) {
4155
4164
  return /* @__PURE__ */ jsxRuntime.jsx("main", { children: emptyComponent || /* @__PURE__ */ jsxRuntime.jsx("div", { className: "container mx-auto px-4 py-16", children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground", children: "No content configured for this page." }) }) });
4156
4165
  }
4157
- return /* @__PURE__ */ jsxRuntime.jsx(ComposerProvider, { children: /* @__PURE__ */ jsxRuntime.jsx("main", { children: composerPreviewFlag ? /* @__PURE__ */ jsxRuntime.jsx(
4158
- "div",
4166
+ return /* @__PURE__ */ jsxRuntime.jsx(ComposerProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(
4167
+ "main",
4159
4168
  {
4160
- "data-slot-id": "main",
4161
- "data-amplifyup-slot": "main",
4162
- "data-slot-source": "page",
4163
- "data-slot-state": layoutTree.length === 0 ? "empty" : "filled",
4164
- "data-slot-empty": layoutTree.length === 0 ? "true" : void 0,
4169
+ "data-slot-id": composerPreviewFlag ? "main" : void 0,
4170
+ "data-amplifyup-slot": composerPreviewFlag ? "main" : void 0,
4171
+ "data-slot-source": composerPreviewFlag ? "page" : void 0,
4172
+ "data-slot-state": composerPreviewFlag ? "filled" : void 0,
4165
4173
  children: layoutTree.map((node) => /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: renderNode(node) }, node.id))
4166
4174
  }
4167
- ) : layoutTree.map((node) => /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: renderNode(node) }, node.id)) }) });
4175
+ ) });
4168
4176
  }
4169
4177
  var AmplifyRenderer = react.memo(AmplifyRendererInner);
4170
4178