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