@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/index.mjs
CHANGED
|
@@ -743,6 +743,7 @@ function applyPageContext(input, opts) {
|
|
|
743
743
|
}
|
|
744
744
|
const pageFields = {};
|
|
745
745
|
for (const pf of opts.pageData?.pageFields || []) {
|
|
746
|
+
if (pf.dataType === "taxonomy") continue;
|
|
746
747
|
if (pf.source === "static") {
|
|
747
748
|
if (pf.value !== void 0) pageFields[pf.key] = pf.value;
|
|
748
749
|
continue;
|
|
@@ -765,6 +766,7 @@ function applyPageContext(input, opts) {
|
|
|
765
766
|
function staticPageFieldsFromSnapshot(pageData) {
|
|
766
767
|
const pageFields = {};
|
|
767
768
|
for (const pf of pageData?.pageFields || []) {
|
|
769
|
+
if (pf.dataType === "taxonomy") continue;
|
|
768
770
|
if (pf.source === "static" && pf.value !== void 0) {
|
|
769
771
|
pageFields[pf.key] = pf.value;
|
|
770
772
|
}
|
|
@@ -782,6 +784,11 @@ function attachStaticPageContext(pageData, pageRoute) {
|
|
|
782
784
|
pageRoute: pageRoute || ""
|
|
783
785
|
};
|
|
784
786
|
}
|
|
787
|
+
function withPageTaxonomies(properties, taxonomies) {
|
|
788
|
+
if (!taxonomies || Object.keys(taxonomies).length === 0) return properties;
|
|
789
|
+
const page2 = properties.page && typeof properties.page === "object" && !Array.isArray(properties.page) ? properties.page : { fields: {} };
|
|
790
|
+
return { ...properties, page: { ...page2, taxonomies } };
|
|
791
|
+
}
|
|
785
792
|
function mergeEventContext(properties, attached) {
|
|
786
793
|
if (!attached) return properties;
|
|
787
794
|
return {
|
|
@@ -792,6 +799,27 @@ function mergeEventContext(properties, attached) {
|
|
|
792
799
|
...attached.pageResource ? { pageResource: attached.pageResource } : {}
|
|
793
800
|
};
|
|
794
801
|
}
|
|
802
|
+
|
|
803
|
+
// src/edge/normalizeRoute.ts
|
|
804
|
+
function normalizeRoute(route) {
|
|
805
|
+
let path = String(route || "").trim();
|
|
806
|
+
if (!path) return "/";
|
|
807
|
+
try {
|
|
808
|
+
if (/^https?:\/\//i.test(path)) {
|
|
809
|
+
path = new URL(path).pathname;
|
|
810
|
+
}
|
|
811
|
+
} catch {
|
|
812
|
+
}
|
|
813
|
+
const q = path.indexOf("?");
|
|
814
|
+
if (q >= 0) path = path.slice(0, q);
|
|
815
|
+
const h = path.indexOf("#");
|
|
816
|
+
if (h >= 0) path = path.slice(0, h);
|
|
817
|
+
if (!path.startsWith("/")) path = `/${path}`;
|
|
818
|
+
if (path.length > 1 && path.endsWith("/")) {
|
|
819
|
+
path = path.replace(/\/+$/, "");
|
|
820
|
+
}
|
|
821
|
+
return path || "/";
|
|
822
|
+
}
|
|
795
823
|
function setPageResourceFields(fields) {
|
|
796
824
|
}
|
|
797
825
|
|
|
@@ -869,27 +897,6 @@ function isAmplifyUpEditorRoute(pathname) {
|
|
|
869
897
|
return pathname === AMPLIFYUP_EDITOR_ROUTE || pathname.startsWith(`${AMPLIFYUP_EDITOR_ROUTE}/`);
|
|
870
898
|
}
|
|
871
899
|
|
|
872
|
-
// src/edge/normalizeRoute.ts
|
|
873
|
-
function normalizeRoute(route) {
|
|
874
|
-
let path = String(route || "").trim();
|
|
875
|
-
if (!path) return "/";
|
|
876
|
-
try {
|
|
877
|
-
if (/^https?:\/\//i.test(path)) {
|
|
878
|
-
path = new URL(path).pathname;
|
|
879
|
-
}
|
|
880
|
-
} catch {
|
|
881
|
-
}
|
|
882
|
-
const q = path.indexOf("?");
|
|
883
|
-
if (q >= 0) path = path.slice(0, q);
|
|
884
|
-
const h = path.indexOf("#");
|
|
885
|
-
if (h >= 0) path = path.slice(0, h);
|
|
886
|
-
if (!path.startsWith("/")) path = `/${path}`;
|
|
887
|
-
if (path.length > 1 && path.endsWith("/")) {
|
|
888
|
-
path = path.replace(/\/+$/, "");
|
|
889
|
-
}
|
|
890
|
-
return path || "/";
|
|
891
|
-
}
|
|
892
|
-
|
|
893
900
|
// src/edge/variantKeys.ts
|
|
894
901
|
function serializeVariantKeys(keys) {
|
|
895
902
|
if (!keys) return "";
|
|
@@ -1011,7 +1018,8 @@ function mapResolvedToPageConfig(payload) {
|
|
|
1011
1018
|
},
|
|
1012
1019
|
...payload.eventTracking && payload.eventTracking.length > 0 ? { eventTracking: payload.eventTracking } : {},
|
|
1013
1020
|
...payload.pageData ? { pageData: payload.pageData } : {},
|
|
1014
|
-
...payload.pageResources ? { pageResources: payload.pageResources } : {}
|
|
1021
|
+
...payload.pageResources ? { pageResources: payload.pageResources } : {},
|
|
1022
|
+
...payload.pageTaxonomies ? { pageTaxonomies: payload.pageTaxonomies } : {}
|
|
1015
1023
|
};
|
|
1016
1024
|
}
|
|
1017
1025
|
function collectDegraded(payload) {
|
|
@@ -1243,6 +1251,7 @@ function searchSpec(pagination, field, term) {
|
|
|
1243
1251
|
}
|
|
1244
1252
|
|
|
1245
1253
|
// src/index.ts
|
|
1254
|
+
var PAGE_VIEW_HOLD_MS = 1500;
|
|
1246
1255
|
var DWELL_ACTIVITY_IDLE_MS = 2 * 60 * 1e3;
|
|
1247
1256
|
var DWELL_POLL_MS = 5e3;
|
|
1248
1257
|
function readPreviewQueryOverrides() {
|
|
@@ -1316,6 +1325,12 @@ var AmplifyUpSDK = class {
|
|
|
1316
1325
|
this.resolvedPageResource = null;
|
|
1317
1326
|
this.resolvedPageRoute = "";
|
|
1318
1327
|
this.resolvedRouteParams = {};
|
|
1328
|
+
/** Path whose delivery response is in flight; page_view for it is held. */
|
|
1329
|
+
this.pendingResolvePath = null;
|
|
1330
|
+
this.heldPageView = null;
|
|
1331
|
+
this.resolvedPageTaxonomies = null;
|
|
1332
|
+
/** Path the taxonomies above were resolved for. */
|
|
1333
|
+
this.resolvedTaxonomiesPath = null;
|
|
1319
1334
|
this.historyHooksInstalled = false;
|
|
1320
1335
|
this.pageEngagementState = {
|
|
1321
1336
|
reached: /* @__PURE__ */ new Set(),
|
|
@@ -1846,8 +1861,10 @@ var AmplifyUpSDK = class {
|
|
|
1846
1861
|
* Apply published pageData (from /v1/resolve) so field validation and
|
|
1847
1862
|
* mapped page fields can run.
|
|
1848
1863
|
*/
|
|
1849
|
-
applyResolvedPageData(pageData, pageRoute, routeParams, pageResources) {
|
|
1864
|
+
applyResolvedPageData(pageData, pageRoute, routeParams, pageResources, pageTaxonomies) {
|
|
1850
1865
|
this.resolvedPageData = pageData || null;
|
|
1866
|
+
this.resolvedPageTaxonomies = pageTaxonomies || null;
|
|
1867
|
+
this.resolvedTaxonomiesPath = this.pendingResolvePath;
|
|
1851
1868
|
if (pageRoute) this.resolvedPageRoute = pageRoute;
|
|
1852
1869
|
if (routeParams) this.resolvedRouteParams = routeParams;
|
|
1853
1870
|
const firstResourceName = pageData?.resources?.[0]?.name;
|
|
@@ -1880,6 +1897,28 @@ var AmplifyUpSDK = class {
|
|
|
1880
1897
|
getAttachedPageContext() {
|
|
1881
1898
|
return this.attachedPageContext;
|
|
1882
1899
|
}
|
|
1900
|
+
/**
|
|
1901
|
+
* The page's delivery response for `path` is on its way. A page_view for the
|
|
1902
|
+
* same path waits for it (up to PAGE_VIEW_HOLD_MS) so it carries the page's
|
|
1903
|
+
* taxonomies.
|
|
1904
|
+
*/
|
|
1905
|
+
beginPageResolve(path) {
|
|
1906
|
+
this.pendingResolvePath = normalizeRoute(path);
|
|
1907
|
+
this.resolvedPageTaxonomies = null;
|
|
1908
|
+
this.resolvedTaxonomiesPath = null;
|
|
1909
|
+
}
|
|
1910
|
+
endPageResolve(path) {
|
|
1911
|
+
if (this.pendingResolvePath !== normalizeRoute(path)) return;
|
|
1912
|
+
this.pendingResolvePath = null;
|
|
1913
|
+
this.flushHeldPageView();
|
|
1914
|
+
}
|
|
1915
|
+
flushHeldPageView() {
|
|
1916
|
+
const held = this.heldPageView;
|
|
1917
|
+
if (!held) return;
|
|
1918
|
+
clearTimeout(held.timer);
|
|
1919
|
+
this.heldPageView = null;
|
|
1920
|
+
this.sendPageView(held.url, held.properties);
|
|
1921
|
+
}
|
|
1883
1922
|
/**
|
|
1884
1923
|
* Track a page view
|
|
1885
1924
|
*/
|
|
@@ -1890,6 +1929,21 @@ var AmplifyUpSDK = class {
|
|
|
1890
1929
|
if (!this.isInitialized()) {
|
|
1891
1930
|
return;
|
|
1892
1931
|
}
|
|
1932
|
+
this.lastTrackedPath = url;
|
|
1933
|
+
if (this.pendingResolvePath && this.pendingResolvePath === normalizeRoute(url)) {
|
|
1934
|
+
this.flushHeldPageView();
|
|
1935
|
+
this.heldPageView = {
|
|
1936
|
+
url,
|
|
1937
|
+
properties,
|
|
1938
|
+
timer: setTimeout(() => this.flushHeldPageView(), PAGE_VIEW_HOLD_MS)
|
|
1939
|
+
};
|
|
1940
|
+
return;
|
|
1941
|
+
}
|
|
1942
|
+
this.flushHeldPageView();
|
|
1943
|
+
this.sendPageView(url, properties);
|
|
1944
|
+
}
|
|
1945
|
+
sendPageView(url, properties) {
|
|
1946
|
+
const taxonomies = this.resolvedTaxonomiesPath && this.resolvedTaxonomiesPath === normalizeRoute(url) ? this.resolvedPageTaxonomies : null;
|
|
1893
1947
|
const instanceId = getInstanceId();
|
|
1894
1948
|
const sessionId = getSessionId();
|
|
1895
1949
|
const pageProperties = {
|
|
@@ -1901,10 +1955,9 @@ var AmplifyUpSDK = class {
|
|
|
1901
1955
|
sessionId,
|
|
1902
1956
|
trackingId: this.config?.trackingId,
|
|
1903
1957
|
// Timestamp is included in event payload
|
|
1904
|
-
...mergeEventContext(properties || {}, this.attachedPageContext)
|
|
1958
|
+
...withPageTaxonomies(mergeEventContext(properties || {}, this.attachedPageContext), taxonomies)
|
|
1905
1959
|
};
|
|
1906
1960
|
this.adapter.page(pageProperties);
|
|
1907
|
-
this.lastTrackedPath = url;
|
|
1908
1961
|
}
|
|
1909
1962
|
/**
|
|
1910
1963
|
* Track an event
|