@amplifyup/sdk 0.1.74 → 0.1.75

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,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
- import { L as LayoutComponentProps, P as PageConfig } from './types-BGZYaFxP.mjs';
4
+ import { L as LayoutComponentProps, P as PageConfig } from './types-D4TSd2Yt.mjs';
5
5
 
6
6
  interface AmplifyRendererProps {
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
- import { L as LayoutComponentProps, P as PageConfig } from './types-BGZYaFxP.js';
4
+ import { L as LayoutComponentProps, P as PageConfig } from './types-D4TSd2Yt.js';
5
5
 
6
6
  interface AmplifyRendererProps {
7
7
  /**
@@ -808,6 +808,7 @@ function applyPageContext(input, opts) {
808
808
  }
809
809
  const pageFields = {};
810
810
  for (const pf of opts.pageData?.pageFields || []) {
811
+ if (pf.dataType === "taxonomy") continue;
811
812
  if (pf.source === "static") {
812
813
  if (pf.value !== void 0) pageFields[pf.key] = pf.value;
813
814
  continue;
@@ -830,6 +831,7 @@ function applyPageContext(input, opts) {
830
831
  function staticPageFieldsFromSnapshot(pageData) {
831
832
  const pageFields = {};
832
833
  for (const pf of pageData?.pageFields || []) {
834
+ if (pf.dataType === "taxonomy") continue;
833
835
  if (pf.source === "static" && pf.value !== void 0) {
834
836
  pageFields[pf.key] = pf.value;
835
837
  }
@@ -847,6 +849,11 @@ function attachStaticPageContext(pageData, pageRoute) {
847
849
  pageRoute: pageRoute || ""
848
850
  };
849
851
  }
852
+ function withPageTaxonomies(properties, taxonomies) {
853
+ if (!taxonomies || Object.keys(taxonomies).length === 0) return properties;
854
+ const page = properties.page && typeof properties.page === "object" && !Array.isArray(properties.page) ? properties.page : { fields: {} };
855
+ return { ...properties, page: { ...page, taxonomies } };
856
+ }
850
857
  function mergeEventContext(properties, attached) {
851
858
  if (!attached) return properties;
852
859
  return {
@@ -916,6 +923,27 @@ function hydratePageResourceProps(props, fields) {
916
923
  return out;
917
924
  }
918
925
 
926
+ // src/edge/normalizeRoute.ts
927
+ function normalizeRoute(route) {
928
+ let path = String(route || "").trim();
929
+ if (!path) return "/";
930
+ try {
931
+ if (/^https?:\/\//i.test(path)) {
932
+ path = new URL(path).pathname;
933
+ }
934
+ } catch {
935
+ }
936
+ const q = path.indexOf("?");
937
+ if (q >= 0) path = path.slice(0, q);
938
+ const h = path.indexOf("#");
939
+ if (h >= 0) path = path.slice(0, h);
940
+ if (!path.startsWith("/")) path = `/${path}`;
941
+ if (path.length > 1 && path.endsWith("/")) {
942
+ path = path.replace(/\/+$/, "");
943
+ }
944
+ return path || "/";
945
+ }
946
+
919
947
  // src/page-resource-runtime.ts
920
948
  var pageResourceFields = null;
921
949
  function setPageResourceFields(fields) {
@@ -1009,6 +1037,7 @@ function dedupeLayoutProviderFetch(key, fetchFn) {
1009
1037
  }
1010
1038
 
1011
1039
  // src/index.ts
1040
+ var PAGE_VIEW_HOLD_MS = 1500;
1012
1041
  var DWELL_ACTIVITY_IDLE_MS = 2 * 60 * 1e3;
1013
1042
  var DWELL_POLL_MS = 5e3;
1014
1043
  function readPreviewQueryOverrides() {
@@ -1082,6 +1111,12 @@ var AmplifyUpSDK = class {
1082
1111
  this.resolvedPageResource = null;
1083
1112
  this.resolvedPageRoute = "";
1084
1113
  this.resolvedRouteParams = {};
1114
+ /** Path whose delivery response is in flight; page_view for it is held. */
1115
+ this.pendingResolvePath = null;
1116
+ this.heldPageView = null;
1117
+ this.resolvedPageTaxonomies = null;
1118
+ /** Path the taxonomies above were resolved for. */
1119
+ this.resolvedTaxonomiesPath = null;
1085
1120
  this.historyHooksInstalled = false;
1086
1121
  this.pageEngagementState = {
1087
1122
  reached: /* @__PURE__ */ new Set(),
@@ -1612,8 +1647,10 @@ var AmplifyUpSDK = class {
1612
1647
  * Apply published pageData (from /v1/resolve) so field validation and
1613
1648
  * mapped page fields can run.
1614
1649
  */
1615
- applyResolvedPageData(pageData, pageRoute, routeParams, pageResources) {
1650
+ applyResolvedPageData(pageData, pageRoute, routeParams, pageResources, pageTaxonomies) {
1616
1651
  this.resolvedPageData = pageData || null;
1652
+ this.resolvedPageTaxonomies = pageTaxonomies || null;
1653
+ this.resolvedTaxonomiesPath = this.pendingResolvePath;
1617
1654
  if (pageRoute) this.resolvedPageRoute = pageRoute;
1618
1655
  if (routeParams) this.resolvedRouteParams = routeParams;
1619
1656
  const firstResourceName = pageData?.resources?.[0]?.name;
@@ -1647,6 +1684,28 @@ var AmplifyUpSDK = class {
1647
1684
  getAttachedPageContext() {
1648
1685
  return this.attachedPageContext;
1649
1686
  }
1687
+ /**
1688
+ * The page's delivery response for `path` is on its way. A page_view for the
1689
+ * same path waits for it (up to PAGE_VIEW_HOLD_MS) so it carries the page's
1690
+ * taxonomies.
1691
+ */
1692
+ beginPageResolve(path) {
1693
+ this.pendingResolvePath = normalizeRoute(path);
1694
+ this.resolvedPageTaxonomies = null;
1695
+ this.resolvedTaxonomiesPath = null;
1696
+ }
1697
+ endPageResolve(path) {
1698
+ if (this.pendingResolvePath !== normalizeRoute(path)) return;
1699
+ this.pendingResolvePath = null;
1700
+ this.flushHeldPageView();
1701
+ }
1702
+ flushHeldPageView() {
1703
+ const held = this.heldPageView;
1704
+ if (!held) return;
1705
+ clearTimeout(held.timer);
1706
+ this.heldPageView = null;
1707
+ this.sendPageView(held.url, held.properties);
1708
+ }
1650
1709
  /**
1651
1710
  * Track a page view
1652
1711
  */
@@ -1657,6 +1716,21 @@ var AmplifyUpSDK = class {
1657
1716
  if (!this.isInitialized()) {
1658
1717
  return;
1659
1718
  }
1719
+ this.lastTrackedPath = url;
1720
+ if (this.pendingResolvePath && this.pendingResolvePath === normalizeRoute(url)) {
1721
+ this.flushHeldPageView();
1722
+ this.heldPageView = {
1723
+ url,
1724
+ properties,
1725
+ timer: setTimeout(() => this.flushHeldPageView(), PAGE_VIEW_HOLD_MS)
1726
+ };
1727
+ return;
1728
+ }
1729
+ this.flushHeldPageView();
1730
+ this.sendPageView(url, properties);
1731
+ }
1732
+ sendPageView(url, properties) {
1733
+ const taxonomies = this.resolvedTaxonomiesPath && this.resolvedTaxonomiesPath === normalizeRoute(url) ? this.resolvedPageTaxonomies : null;
1660
1734
  const instanceId = getInstanceId();
1661
1735
  const sessionId = getSessionId();
1662
1736
  const pageProperties = {
@@ -1668,10 +1742,9 @@ var AmplifyUpSDK = class {
1668
1742
  sessionId,
1669
1743
  trackingId: this.config?.trackingId,
1670
1744
  // Timestamp is included in event payload
1671
- ...mergeEventContext(properties || {}, this.attachedPageContext)
1745
+ ...withPageTaxonomies(mergeEventContext(properties || {}, this.attachedPageContext), taxonomies)
1672
1746
  };
1673
1747
  this.adapter.page(pageProperties);
1674
- this.lastTrackedPath = url;
1675
1748
  }
1676
1749
  /**
1677
1750
  * Track an event