@amplifyup/sdk 0.1.73 → 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 +97 -12
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +97 -12
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +27 -5
- package/dist/index.d.ts +27 -5
- package/dist/index.js +100 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +100 -34
- package/dist/index.mjs.map +1 -1
- package/dist/{query-Hay-oVYp.d.ts → query-B23UsNIv.d.ts} +1 -1
- package/dist/{query-B_DU7yEm.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 +106 -35
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +106 -35
- 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 +3 -1
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +3 -1
- package/dist/server.mjs.map +1 -1
- package/dist/{types-CGeBbx84.d.mts → types-D4TSd2Yt.d.mts} +23 -2
- package/dist/{types-CGeBbx84.d.ts → types-D4TSd2Yt.d.ts} +23 -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,15 +784,42 @@ 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 {
|
|
788
795
|
...properties,
|
|
789
796
|
...attached.resource ? { resource: attached.resource } : {},
|
|
790
797
|
page: attached.page,
|
|
791
|
-
...attached.pageRoute ? { pageRoute: attached.pageRoute } : {}
|
|
798
|
+
...attached.pageRoute ? { pageRoute: attached.pageRoute } : {},
|
|
799
|
+
...attached.pageResource ? { pageResource: attached.pageResource } : {}
|
|
792
800
|
};
|
|
793
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
|
+
}
|
|
794
823
|
function setPageResourceFields(fields) {
|
|
795
824
|
}
|
|
796
825
|
|
|
@@ -868,27 +897,6 @@ function isAmplifyUpEditorRoute(pathname) {
|
|
|
868
897
|
return pathname === AMPLIFYUP_EDITOR_ROUTE || pathname.startsWith(`${AMPLIFYUP_EDITOR_ROUTE}/`);
|
|
869
898
|
}
|
|
870
899
|
|
|
871
|
-
// src/edge/normalizeRoute.ts
|
|
872
|
-
function normalizeRoute(route) {
|
|
873
|
-
let path = String(route || "").trim();
|
|
874
|
-
if (!path) return "/";
|
|
875
|
-
try {
|
|
876
|
-
if (/^https?:\/\//i.test(path)) {
|
|
877
|
-
path = new URL(path).pathname;
|
|
878
|
-
}
|
|
879
|
-
} catch {
|
|
880
|
-
}
|
|
881
|
-
const q = path.indexOf("?");
|
|
882
|
-
if (q >= 0) path = path.slice(0, q);
|
|
883
|
-
const h = path.indexOf("#");
|
|
884
|
-
if (h >= 0) path = path.slice(0, h);
|
|
885
|
-
if (!path.startsWith("/")) path = `/${path}`;
|
|
886
|
-
if (path.length > 1 && path.endsWith("/")) {
|
|
887
|
-
path = path.replace(/\/+$/, "");
|
|
888
|
-
}
|
|
889
|
-
return path || "/";
|
|
890
|
-
}
|
|
891
|
-
|
|
892
900
|
// src/edge/variantKeys.ts
|
|
893
901
|
function serializeVariantKeys(keys) {
|
|
894
902
|
if (!keys) return "";
|
|
@@ -1009,7 +1017,9 @@ function mapResolvedToPageConfig(payload) {
|
|
|
1009
1017
|
description: payload.meta?.degraded ? "degraded" : void 0
|
|
1010
1018
|
},
|
|
1011
1019
|
...payload.eventTracking && payload.eventTracking.length > 0 ? { eventTracking: payload.eventTracking } : {},
|
|
1012
|
-
...payload.pageData ? { pageData: payload.pageData } : {}
|
|
1020
|
+
...payload.pageData ? { pageData: payload.pageData } : {},
|
|
1021
|
+
...payload.pageResources ? { pageResources: payload.pageResources } : {},
|
|
1022
|
+
...payload.pageTaxonomies ? { pageTaxonomies: payload.pageTaxonomies } : {}
|
|
1013
1023
|
};
|
|
1014
1024
|
}
|
|
1015
1025
|
function collectDegraded(payload) {
|
|
@@ -1241,6 +1251,7 @@ function searchSpec(pagination, field, term) {
|
|
|
1241
1251
|
}
|
|
1242
1252
|
|
|
1243
1253
|
// src/index.ts
|
|
1254
|
+
var PAGE_VIEW_HOLD_MS = 1500;
|
|
1244
1255
|
var DWELL_ACTIVITY_IDLE_MS = 2 * 60 * 1e3;
|
|
1245
1256
|
var DWELL_POLL_MS = 5e3;
|
|
1246
1257
|
function readPreviewQueryOverrides() {
|
|
@@ -1311,8 +1322,15 @@ var AmplifyUpSDK = class {
|
|
|
1311
1322
|
this.pendingPageContext = null;
|
|
1312
1323
|
this.attachedPageContext = null;
|
|
1313
1324
|
this.resolvedPageData = null;
|
|
1325
|
+
this.resolvedPageResource = null;
|
|
1314
1326
|
this.resolvedPageRoute = "";
|
|
1315
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;
|
|
1316
1334
|
this.historyHooksInstalled = false;
|
|
1317
1335
|
this.pageEngagementState = {
|
|
1318
1336
|
reached: /* @__PURE__ */ new Set(),
|
|
@@ -1843,30 +1861,64 @@ var AmplifyUpSDK = class {
|
|
|
1843
1861
|
* Apply published pageData (from /v1/resolve) so field validation and
|
|
1844
1862
|
* mapped page fields can run.
|
|
1845
1863
|
*/
|
|
1846
|
-
applyResolvedPageData(pageData, pageRoute, routeParams) {
|
|
1864
|
+
applyResolvedPageData(pageData, pageRoute, routeParams, pageResources, pageTaxonomies) {
|
|
1847
1865
|
this.resolvedPageData = pageData || null;
|
|
1866
|
+
this.resolvedPageTaxonomies = pageTaxonomies || null;
|
|
1867
|
+
this.resolvedTaxonomiesPath = this.pendingResolvePath;
|
|
1848
1868
|
if (pageRoute) this.resolvedPageRoute = pageRoute;
|
|
1849
1869
|
if (routeParams) this.resolvedRouteParams = routeParams;
|
|
1870
|
+
const firstResourceName = pageData?.resources?.[0]?.name;
|
|
1871
|
+
const resolvedForPage = (firstResourceName ? pageResources?.[firstResourceName] : void 0) || (pageResources ? Object.values(pageResources)[0] : void 0);
|
|
1872
|
+
this.resolvedPageResource = resolvedForPage || null;
|
|
1850
1873
|
this.recomputeAttachedContext();
|
|
1851
1874
|
}
|
|
1852
1875
|
recomputeAttachedContext() {
|
|
1853
1876
|
if (!this.pendingPageContext) {
|
|
1854
|
-
this.attachedPageContext =
|
|
1855
|
-
this.resolvedPageData,
|
|
1856
|
-
this.resolvedPageRoute
|
|
1877
|
+
this.attachedPageContext = this.withPageResource(
|
|
1878
|
+
attachStaticPageContext(this.resolvedPageData, this.resolvedPageRoute)
|
|
1857
1879
|
);
|
|
1858
1880
|
return;
|
|
1859
1881
|
}
|
|
1860
|
-
this.attachedPageContext =
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1882
|
+
this.attachedPageContext = this.withPageResource(
|
|
1883
|
+
applyPageContext(this.pendingPageContext, {
|
|
1884
|
+
pageData: this.resolvedPageData,
|
|
1885
|
+
routeParams: this.resolvedRouteParams,
|
|
1886
|
+
pageRoute: this.resolvedPageRoute
|
|
1887
|
+
})
|
|
1888
|
+
);
|
|
1865
1889
|
setPageResourceFields(this.attachedPageContext?.resource?.fields || null);
|
|
1866
1890
|
}
|
|
1891
|
+
/** Stamp the resolved entry onto the context so events carry it. */
|
|
1892
|
+
withPageResource(context) {
|
|
1893
|
+
if (!context || !this.resolvedPageResource) return context;
|
|
1894
|
+
const { entity, providerId, docId } = this.resolvedPageResource;
|
|
1895
|
+
return { ...context, pageResource: { entity, providerId, docId } };
|
|
1896
|
+
}
|
|
1867
1897
|
getAttachedPageContext() {
|
|
1868
1898
|
return this.attachedPageContext;
|
|
1869
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
|
+
}
|
|
1870
1922
|
/**
|
|
1871
1923
|
* Track a page view
|
|
1872
1924
|
*/
|
|
@@ -1877,6 +1929,21 @@ var AmplifyUpSDK = class {
|
|
|
1877
1929
|
if (!this.isInitialized()) {
|
|
1878
1930
|
return;
|
|
1879
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;
|
|
1880
1947
|
const instanceId = getInstanceId();
|
|
1881
1948
|
const sessionId = getSessionId();
|
|
1882
1949
|
const pageProperties = {
|
|
@@ -1888,10 +1955,9 @@ var AmplifyUpSDK = class {
|
|
|
1888
1955
|
sessionId,
|
|
1889
1956
|
trackingId: this.config?.trackingId,
|
|
1890
1957
|
// Timestamp is included in event payload
|
|
1891
|
-
...mergeEventContext(properties || {}, this.attachedPageContext)
|
|
1958
|
+
...withPageTaxonomies(mergeEventContext(properties || {}, this.attachedPageContext), taxonomies)
|
|
1892
1959
|
};
|
|
1893
1960
|
this.adapter.page(pageProperties);
|
|
1894
|
-
this.lastTrackedPath = url;
|
|
1895
1961
|
}
|
|
1896
1962
|
/**
|
|
1897
1963
|
* Track an event
|