@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/react.mjs
CHANGED
|
@@ -837,6 +837,7 @@ function applyPageContext(input, opts) {
|
|
|
837
837
|
}
|
|
838
838
|
const pageFields = {};
|
|
839
839
|
for (const pf of opts.pageData?.pageFields || []) {
|
|
840
|
+
if (pf.dataType === "taxonomy") continue;
|
|
840
841
|
if (pf.source === "static") {
|
|
841
842
|
if (pf.value !== void 0) pageFields[pf.key] = pf.value;
|
|
842
843
|
continue;
|
|
@@ -859,6 +860,7 @@ function applyPageContext(input, opts) {
|
|
|
859
860
|
function staticPageFieldsFromSnapshot(pageData) {
|
|
860
861
|
const pageFields = {};
|
|
861
862
|
for (const pf of pageData?.pageFields || []) {
|
|
863
|
+
if (pf.dataType === "taxonomy") continue;
|
|
862
864
|
if (pf.source === "static" && pf.value !== void 0) {
|
|
863
865
|
pageFields[pf.key] = pf.value;
|
|
864
866
|
}
|
|
@@ -876,13 +878,19 @@ function attachStaticPageContext(pageData, pageRoute) {
|
|
|
876
878
|
pageRoute: pageRoute || ""
|
|
877
879
|
};
|
|
878
880
|
}
|
|
881
|
+
function withPageTaxonomies(properties, taxonomies) {
|
|
882
|
+
if (!taxonomies || Object.keys(taxonomies).length === 0) return properties;
|
|
883
|
+
const page = properties.page && typeof properties.page === "object" && !Array.isArray(properties.page) ? properties.page : { fields: {} };
|
|
884
|
+
return { ...properties, page: { ...page, taxonomies } };
|
|
885
|
+
}
|
|
879
886
|
function mergeEventContext(properties, attached) {
|
|
880
887
|
if (!attached) return properties;
|
|
881
888
|
return {
|
|
882
889
|
...properties,
|
|
883
890
|
...attached.resource ? { resource: attached.resource } : {},
|
|
884
891
|
page: attached.page,
|
|
885
|
-
...attached.pageRoute ? { pageRoute: attached.pageRoute } : {}
|
|
892
|
+
...attached.pageRoute ? { pageRoute: attached.pageRoute } : {},
|
|
893
|
+
...attached.pageResource ? { pageResource: attached.pageResource } : {}
|
|
886
894
|
};
|
|
887
895
|
}
|
|
888
896
|
var PAGE_RESOURCE_MARKER = "__amplifyupPageResource";
|
|
@@ -944,6 +952,27 @@ function hydratePageResourceProps(props, fields) {
|
|
|
944
952
|
return out;
|
|
945
953
|
}
|
|
946
954
|
|
|
955
|
+
// src/edge/normalizeRoute.ts
|
|
956
|
+
function normalizeRoute(route) {
|
|
957
|
+
let path = String(route || "").trim();
|
|
958
|
+
if (!path) return "/";
|
|
959
|
+
try {
|
|
960
|
+
if (/^https?:\/\//i.test(path)) {
|
|
961
|
+
path = new URL(path).pathname;
|
|
962
|
+
}
|
|
963
|
+
} catch {
|
|
964
|
+
}
|
|
965
|
+
const q = path.indexOf("?");
|
|
966
|
+
if (q >= 0) path = path.slice(0, q);
|
|
967
|
+
const h = path.indexOf("#");
|
|
968
|
+
if (h >= 0) path = path.slice(0, h);
|
|
969
|
+
if (!path.startsWith("/")) path = `/${path}`;
|
|
970
|
+
if (path.length > 1 && path.endsWith("/")) {
|
|
971
|
+
path = path.replace(/\/+$/, "");
|
|
972
|
+
}
|
|
973
|
+
return path || "/";
|
|
974
|
+
}
|
|
975
|
+
|
|
947
976
|
// src/page-resource-runtime.ts
|
|
948
977
|
var pageResourceFields = null;
|
|
949
978
|
function setPageResourceFields(fields) {
|
|
@@ -1041,27 +1070,6 @@ function previewLayoutReady(opts) {
|
|
|
1041
1070
|
return true;
|
|
1042
1071
|
}
|
|
1043
1072
|
|
|
1044
|
-
// src/edge/normalizeRoute.ts
|
|
1045
|
-
function normalizeRoute(route) {
|
|
1046
|
-
let path = String(route || "").trim();
|
|
1047
|
-
if (!path) return "/";
|
|
1048
|
-
try {
|
|
1049
|
-
if (/^https?:\/\//i.test(path)) {
|
|
1050
|
-
path = new URL(path).pathname;
|
|
1051
|
-
}
|
|
1052
|
-
} catch {
|
|
1053
|
-
}
|
|
1054
|
-
const q = path.indexOf("?");
|
|
1055
|
-
if (q >= 0) path = path.slice(0, q);
|
|
1056
|
-
const h = path.indexOf("#");
|
|
1057
|
-
if (h >= 0) path = path.slice(0, h);
|
|
1058
|
-
if (!path.startsWith("/")) path = `/${path}`;
|
|
1059
|
-
if (path.length > 1 && path.endsWith("/")) {
|
|
1060
|
-
path = path.replace(/\/+$/, "");
|
|
1061
|
-
}
|
|
1062
|
-
return path || "/";
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
1073
|
// src/edge/variantKeys.ts
|
|
1066
1074
|
function serializeVariantKeys(keys) {
|
|
1067
1075
|
if (!keys) return "";
|
|
@@ -1182,7 +1190,9 @@ function mapResolvedToPageConfig(payload) {
|
|
|
1182
1190
|
description: payload.meta?.degraded ? "degraded" : void 0
|
|
1183
1191
|
},
|
|
1184
1192
|
...payload.eventTracking && payload.eventTracking.length > 0 ? { eventTracking: payload.eventTracking } : {},
|
|
1185
|
-
...payload.pageData ? { pageData: payload.pageData } : {}
|
|
1193
|
+
...payload.pageData ? { pageData: payload.pageData } : {},
|
|
1194
|
+
...payload.pageResources ? { pageResources: payload.pageResources } : {},
|
|
1195
|
+
...payload.pageTaxonomies ? { pageTaxonomies: payload.pageTaxonomies } : {}
|
|
1186
1196
|
};
|
|
1187
1197
|
}
|
|
1188
1198
|
function collectDegraded(payload) {
|
|
@@ -1414,6 +1424,7 @@ function searchSpec(pagination, field, term) {
|
|
|
1414
1424
|
}
|
|
1415
1425
|
|
|
1416
1426
|
// src/index.ts
|
|
1427
|
+
var PAGE_VIEW_HOLD_MS = 1500;
|
|
1417
1428
|
var DWELL_ACTIVITY_IDLE_MS = 2 * 60 * 1e3;
|
|
1418
1429
|
var DWELL_POLL_MS = 5e3;
|
|
1419
1430
|
function readPreviewQueryOverrides() {
|
|
@@ -1484,8 +1495,15 @@ var AmplifyUpSDK = class {
|
|
|
1484
1495
|
this.pendingPageContext = null;
|
|
1485
1496
|
this.attachedPageContext = null;
|
|
1486
1497
|
this.resolvedPageData = null;
|
|
1498
|
+
this.resolvedPageResource = null;
|
|
1487
1499
|
this.resolvedPageRoute = "";
|
|
1488
1500
|
this.resolvedRouteParams = {};
|
|
1501
|
+
/** Path whose delivery response is in flight; page_view for it is held. */
|
|
1502
|
+
this.pendingResolvePath = null;
|
|
1503
|
+
this.heldPageView = null;
|
|
1504
|
+
this.resolvedPageTaxonomies = null;
|
|
1505
|
+
/** Path the taxonomies above were resolved for. */
|
|
1506
|
+
this.resolvedTaxonomiesPath = null;
|
|
1489
1507
|
this.historyHooksInstalled = false;
|
|
1490
1508
|
this.pageEngagementState = {
|
|
1491
1509
|
reached: /* @__PURE__ */ new Set(),
|
|
@@ -2016,31 +2034,65 @@ var AmplifyUpSDK = class {
|
|
|
2016
2034
|
* Apply published pageData (from /v1/resolve) so field validation and
|
|
2017
2035
|
* mapped page fields can run.
|
|
2018
2036
|
*/
|
|
2019
|
-
applyResolvedPageData(pageData, pageRoute, routeParams) {
|
|
2037
|
+
applyResolvedPageData(pageData, pageRoute, routeParams, pageResources, pageTaxonomies) {
|
|
2020
2038
|
this.resolvedPageData = pageData || null;
|
|
2039
|
+
this.resolvedPageTaxonomies = pageTaxonomies || null;
|
|
2040
|
+
this.resolvedTaxonomiesPath = this.pendingResolvePath;
|
|
2021
2041
|
if (pageRoute) this.resolvedPageRoute = pageRoute;
|
|
2022
2042
|
if (routeParams) this.resolvedRouteParams = routeParams;
|
|
2043
|
+
const firstResourceName = pageData?.resources?.[0]?.name;
|
|
2044
|
+
const resolvedForPage = (firstResourceName ? pageResources?.[firstResourceName] : void 0) || (pageResources ? Object.values(pageResources)[0] : void 0);
|
|
2045
|
+
this.resolvedPageResource = resolvedForPage || null;
|
|
2023
2046
|
this.recomputeAttachedContext();
|
|
2024
2047
|
}
|
|
2025
2048
|
recomputeAttachedContext() {
|
|
2026
2049
|
if (!this.pendingPageContext) {
|
|
2027
|
-
this.attachedPageContext =
|
|
2028
|
-
this.resolvedPageData,
|
|
2029
|
-
this.resolvedPageRoute
|
|
2050
|
+
this.attachedPageContext = this.withPageResource(
|
|
2051
|
+
attachStaticPageContext(this.resolvedPageData, this.resolvedPageRoute)
|
|
2030
2052
|
);
|
|
2031
2053
|
setPageResourceFields(null);
|
|
2032
2054
|
return;
|
|
2033
2055
|
}
|
|
2034
|
-
this.attachedPageContext =
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2056
|
+
this.attachedPageContext = this.withPageResource(
|
|
2057
|
+
applyPageContext(this.pendingPageContext, {
|
|
2058
|
+
pageData: this.resolvedPageData,
|
|
2059
|
+
routeParams: this.resolvedRouteParams,
|
|
2060
|
+
pageRoute: this.resolvedPageRoute
|
|
2061
|
+
})
|
|
2062
|
+
);
|
|
2039
2063
|
setPageResourceFields(this.attachedPageContext?.resource?.fields || null);
|
|
2040
2064
|
}
|
|
2065
|
+
/** Stamp the resolved entry onto the context so events carry it. */
|
|
2066
|
+
withPageResource(context) {
|
|
2067
|
+
if (!context || !this.resolvedPageResource) return context;
|
|
2068
|
+
const { entity, providerId, docId } = this.resolvedPageResource;
|
|
2069
|
+
return { ...context, pageResource: { entity, providerId, docId } };
|
|
2070
|
+
}
|
|
2041
2071
|
getAttachedPageContext() {
|
|
2042
2072
|
return this.attachedPageContext;
|
|
2043
2073
|
}
|
|
2074
|
+
/**
|
|
2075
|
+
* The page's delivery response for `path` is on its way. A page_view for the
|
|
2076
|
+
* same path waits for it (up to PAGE_VIEW_HOLD_MS) so it carries the page's
|
|
2077
|
+
* taxonomies.
|
|
2078
|
+
*/
|
|
2079
|
+
beginPageResolve(path) {
|
|
2080
|
+
this.pendingResolvePath = normalizeRoute(path);
|
|
2081
|
+
this.resolvedPageTaxonomies = null;
|
|
2082
|
+
this.resolvedTaxonomiesPath = null;
|
|
2083
|
+
}
|
|
2084
|
+
endPageResolve(path) {
|
|
2085
|
+
if (this.pendingResolvePath !== normalizeRoute(path)) return;
|
|
2086
|
+
this.pendingResolvePath = null;
|
|
2087
|
+
this.flushHeldPageView();
|
|
2088
|
+
}
|
|
2089
|
+
flushHeldPageView() {
|
|
2090
|
+
const held = this.heldPageView;
|
|
2091
|
+
if (!held) return;
|
|
2092
|
+
clearTimeout(held.timer);
|
|
2093
|
+
this.heldPageView = null;
|
|
2094
|
+
this.sendPageView(held.url, held.properties);
|
|
2095
|
+
}
|
|
2044
2096
|
/**
|
|
2045
2097
|
* Track a page view
|
|
2046
2098
|
*/
|
|
@@ -2051,6 +2103,21 @@ var AmplifyUpSDK = class {
|
|
|
2051
2103
|
if (!this.isInitialized()) {
|
|
2052
2104
|
return;
|
|
2053
2105
|
}
|
|
2106
|
+
this.lastTrackedPath = url;
|
|
2107
|
+
if (this.pendingResolvePath && this.pendingResolvePath === normalizeRoute(url)) {
|
|
2108
|
+
this.flushHeldPageView();
|
|
2109
|
+
this.heldPageView = {
|
|
2110
|
+
url,
|
|
2111
|
+
properties,
|
|
2112
|
+
timer: setTimeout(() => this.flushHeldPageView(), PAGE_VIEW_HOLD_MS)
|
|
2113
|
+
};
|
|
2114
|
+
return;
|
|
2115
|
+
}
|
|
2116
|
+
this.flushHeldPageView();
|
|
2117
|
+
this.sendPageView(url, properties);
|
|
2118
|
+
}
|
|
2119
|
+
sendPageView(url, properties) {
|
|
2120
|
+
const taxonomies = this.resolvedTaxonomiesPath && this.resolvedTaxonomiesPath === normalizeRoute(url) ? this.resolvedPageTaxonomies : null;
|
|
2054
2121
|
const instanceId = getInstanceId();
|
|
2055
2122
|
const sessionId = getSessionId();
|
|
2056
2123
|
const pageProperties = {
|
|
@@ -2062,10 +2129,9 @@ var AmplifyUpSDK = class {
|
|
|
2062
2129
|
sessionId,
|
|
2063
2130
|
trackingId: this.config?.trackingId,
|
|
2064
2131
|
// Timestamp is included in event payload
|
|
2065
|
-
...mergeEventContext(properties || {}, this.attachedPageContext)
|
|
2132
|
+
...withPageTaxonomies(mergeEventContext(properties || {}, this.attachedPageContext), taxonomies)
|
|
2066
2133
|
};
|
|
2067
2134
|
this.adapter.page(pageProperties);
|
|
2068
|
-
this.lastTrackedPath = url;
|
|
2069
2135
|
}
|
|
2070
2136
|
/**
|
|
2071
2137
|
* Track an event
|
|
@@ -5512,6 +5578,8 @@ function AmplifyUpProvider({
|
|
|
5512
5578
|
useEffect(() => {
|
|
5513
5579
|
let cancelled = false;
|
|
5514
5580
|
const sdk = getSDK();
|
|
5581
|
+
const heldRoute = isComposerPreview() || config.clientPersonalization !== false ? getActualRoute() : null;
|
|
5582
|
+
if (heldRoute) sdk.beginPageResolve(heldRoute);
|
|
5515
5583
|
const run = async () => {
|
|
5516
5584
|
try {
|
|
5517
5585
|
await sdk.init({
|
|
@@ -5590,7 +5658,9 @@ function AmplifyUpProvider({
|
|
|
5590
5658
|
sdk.applyResolvedPageData(
|
|
5591
5659
|
result.pageConfig.pageData || null,
|
|
5592
5660
|
result.pageConfig.route,
|
|
5593
|
-
extractRouteParams(result.pageConfig.route, actualRoute)
|
|
5661
|
+
extractRouteParams(result.pageConfig.route, actualRoute),
|
|
5662
|
+
result.pageConfig.pageResources || null,
|
|
5663
|
+
result.pageConfig.pageTaxonomies || null
|
|
5594
5664
|
);
|
|
5595
5665
|
}
|
|
5596
5666
|
setInitialized(true);
|
|
@@ -5614,6 +5684,7 @@ function AmplifyUpProvider({
|
|
|
5614
5684
|
setSource(null);
|
|
5615
5685
|
setMeta(null);
|
|
5616
5686
|
} finally {
|
|
5687
|
+
if (heldRoute) sdk.endPageResolve(heldRoute);
|
|
5617
5688
|
if (!cancelled) setLoading(false);
|
|
5618
5689
|
}
|
|
5619
5690
|
};
|