@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,4 +1,4 @@
1
- import { i as AmplifyUpTarget, y as ListRow } from './types-BGZYaFxP.js';
1
+ import { j as AmplifyUpTarget, z as ListRow } from './types-D4TSd2Yt.js';
2
2
 
3
3
  /**
4
4
  * On-request variant selection (tier 3).
@@ -1,4 +1,4 @@
1
- import { i as AmplifyUpTarget, y as ListRow } from './types-BGZYaFxP.mjs';
1
+ import { j as AmplifyUpTarget, z as ListRow } from './types-D4TSd2Yt.mjs';
2
2
 
3
3
  /**
4
4
  * On-request variant selection (tier 3).
package/dist/react.d.mts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { L as LayoutComponentProps, P as PageConfig, F as Field$1, l as FIELDS_BRAND, c as AmplifyUpConfig, e as AmplifyPageContextInput, C as ContentSource, A as AmplifyContentMeta } from './types-BGZYaFxP.mjs';
3
- export { w as FieldRef, x as Fields, z as ImageValue, y as ListRow, B as PortableRef, Z as ZoneConfig, m as attachFieldEnvelopes, p as composerStoreKey, o as envelopeListRows, v as isBrandedFields, s as isFieldEnvelope, u as isReadOnlyRowField, q as listOwnerFromSpec, t as toFieldEnvelopes } from './types-BGZYaFxP.mjs';
2
+ import { L as LayoutComponentProps, P as PageConfig, F as Field$1, m as FIELDS_BRAND, d as AmplifyUpConfig, f as AmplifyPageContextInput, C as ContentSource, A as AmplifyContentMeta } from './types-D4TSd2Yt.mjs';
3
+ export { x as FieldRef, y as Fields, B as ImageValue, z as ListRow, D as PortableRef, Z as ZoneConfig, o as attachFieldEnvelopes, q as composerStoreKey, p as envelopeListRows, w as isBrandedFields, u as isFieldEnvelope, v as isReadOnlyRowField, s as listOwnerFromSpec, t as toFieldEnvelopes } from './types-D4TSd2Yt.mjs';
4
4
  import react__default, { ReactNode } from 'react';
5
5
  export { AmplifyRenderer } from './AmplifyRenderer.mjs';
6
- export { Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-_SMo6VRf.mjs';
6
+ export { Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-CV8x3oQT.mjs';
7
7
  export { i as isComposerPreview, a as isPreviewRequest, b as isWorkingContentRequest } from './preview-_vHmzRen.mjs';
8
8
 
9
9
  type RenderComponentContext = {
package/dist/react.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { L as LayoutComponentProps, P as PageConfig, F as Field$1, l as FIELDS_BRAND, c as AmplifyUpConfig, e as AmplifyPageContextInput, C as ContentSource, A as AmplifyContentMeta } from './types-BGZYaFxP.js';
3
- export { w as FieldRef, x as Fields, z as ImageValue, y as ListRow, B as PortableRef, Z as ZoneConfig, m as attachFieldEnvelopes, p as composerStoreKey, o as envelopeListRows, v as isBrandedFields, s as isFieldEnvelope, u as isReadOnlyRowField, q as listOwnerFromSpec, t as toFieldEnvelopes } from './types-BGZYaFxP.js';
2
+ import { L as LayoutComponentProps, P as PageConfig, F as Field$1, m as FIELDS_BRAND, d as AmplifyUpConfig, f as AmplifyPageContextInput, C as ContentSource, A as AmplifyContentMeta } from './types-D4TSd2Yt.js';
3
+ export { x as FieldRef, y as Fields, B as ImageValue, z as ListRow, D as PortableRef, Z as ZoneConfig, o as attachFieldEnvelopes, q as composerStoreKey, p as envelopeListRows, w as isBrandedFields, u as isFieldEnvelope, v as isReadOnlyRowField, s as listOwnerFromSpec, t as toFieldEnvelopes } from './types-D4TSd2Yt.js';
4
4
  import react__default, { ReactNode } from 'react';
5
5
  export { AmplifyRenderer } from './AmplifyRenderer.js';
6
- export { Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-NcrxJQvI.js';
6
+ export { Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-B23UsNIv.js';
7
7
  export { i as isComposerPreview, a as isPreviewRequest, b as isWorkingContentRequest } from './preview-_vHmzRen.js';
8
8
 
9
9
  type RenderComponentContext = {
package/dist/react.js CHANGED
@@ -843,6 +843,7 @@ function applyPageContext(input, opts) {
843
843
  }
844
844
  const pageFields = {};
845
845
  for (const pf of opts.pageData?.pageFields || []) {
846
+ if (pf.dataType === "taxonomy") continue;
846
847
  if (pf.source === "static") {
847
848
  if (pf.value !== void 0) pageFields[pf.key] = pf.value;
848
849
  continue;
@@ -865,6 +866,7 @@ function applyPageContext(input, opts) {
865
866
  function staticPageFieldsFromSnapshot(pageData) {
866
867
  const pageFields = {};
867
868
  for (const pf of pageData?.pageFields || []) {
869
+ if (pf.dataType === "taxonomy") continue;
868
870
  if (pf.source === "static" && pf.value !== void 0) {
869
871
  pageFields[pf.key] = pf.value;
870
872
  }
@@ -882,6 +884,11 @@ function attachStaticPageContext(pageData, pageRoute) {
882
884
  pageRoute: pageRoute || ""
883
885
  };
884
886
  }
887
+ function withPageTaxonomies(properties, taxonomies) {
888
+ if (!taxonomies || Object.keys(taxonomies).length === 0) return properties;
889
+ const page = properties.page && typeof properties.page === "object" && !Array.isArray(properties.page) ? properties.page : { fields: {} };
890
+ return { ...properties, page: { ...page, taxonomies } };
891
+ }
885
892
  function mergeEventContext(properties, attached) {
886
893
  if (!attached) return properties;
887
894
  return {
@@ -951,6 +958,27 @@ function hydratePageResourceProps(props, fields) {
951
958
  return out;
952
959
  }
953
960
 
961
+ // src/edge/normalizeRoute.ts
962
+ function normalizeRoute(route) {
963
+ let path = String(route || "").trim();
964
+ if (!path) return "/";
965
+ try {
966
+ if (/^https?:\/\//i.test(path)) {
967
+ path = new URL(path).pathname;
968
+ }
969
+ } catch {
970
+ }
971
+ const q = path.indexOf("?");
972
+ if (q >= 0) path = path.slice(0, q);
973
+ const h = path.indexOf("#");
974
+ if (h >= 0) path = path.slice(0, h);
975
+ if (!path.startsWith("/")) path = `/${path}`;
976
+ if (path.length > 1 && path.endsWith("/")) {
977
+ path = path.replace(/\/+$/, "");
978
+ }
979
+ return path || "/";
980
+ }
981
+
954
982
  // src/page-resource-runtime.ts
955
983
  var pageResourceFields = null;
956
984
  function setPageResourceFields(fields) {
@@ -1048,27 +1076,6 @@ function previewLayoutReady(opts) {
1048
1076
  return true;
1049
1077
  }
1050
1078
 
1051
- // src/edge/normalizeRoute.ts
1052
- function normalizeRoute(route) {
1053
- let path = String(route || "").trim();
1054
- if (!path) return "/";
1055
- try {
1056
- if (/^https?:\/\//i.test(path)) {
1057
- path = new URL(path).pathname;
1058
- }
1059
- } catch {
1060
- }
1061
- const q = path.indexOf("?");
1062
- if (q >= 0) path = path.slice(0, q);
1063
- const h = path.indexOf("#");
1064
- if (h >= 0) path = path.slice(0, h);
1065
- if (!path.startsWith("/")) path = `/${path}`;
1066
- if (path.length > 1 && path.endsWith("/")) {
1067
- path = path.replace(/\/+$/, "");
1068
- }
1069
- return path || "/";
1070
- }
1071
-
1072
1079
  // src/edge/variantKeys.ts
1073
1080
  function serializeVariantKeys(keys) {
1074
1081
  if (!keys) return "";
@@ -1190,7 +1197,8 @@ function mapResolvedToPageConfig(payload) {
1190
1197
  },
1191
1198
  ...payload.eventTracking && payload.eventTracking.length > 0 ? { eventTracking: payload.eventTracking } : {},
1192
1199
  ...payload.pageData ? { pageData: payload.pageData } : {},
1193
- ...payload.pageResources ? { pageResources: payload.pageResources } : {}
1200
+ ...payload.pageResources ? { pageResources: payload.pageResources } : {},
1201
+ ...payload.pageTaxonomies ? { pageTaxonomies: payload.pageTaxonomies } : {}
1194
1202
  };
1195
1203
  }
1196
1204
  function collectDegraded(payload) {
@@ -1422,6 +1430,7 @@ function searchSpec(pagination, field, term) {
1422
1430
  }
1423
1431
 
1424
1432
  // src/index.ts
1433
+ var PAGE_VIEW_HOLD_MS = 1500;
1425
1434
  var DWELL_ACTIVITY_IDLE_MS = 2 * 60 * 1e3;
1426
1435
  var DWELL_POLL_MS = 5e3;
1427
1436
  function readPreviewQueryOverrides() {
@@ -1495,6 +1504,12 @@ var AmplifyUpSDK = class {
1495
1504
  this.resolvedPageResource = null;
1496
1505
  this.resolvedPageRoute = "";
1497
1506
  this.resolvedRouteParams = {};
1507
+ /** Path whose delivery response is in flight; page_view for it is held. */
1508
+ this.pendingResolvePath = null;
1509
+ this.heldPageView = null;
1510
+ this.resolvedPageTaxonomies = null;
1511
+ /** Path the taxonomies above were resolved for. */
1512
+ this.resolvedTaxonomiesPath = null;
1498
1513
  this.historyHooksInstalled = false;
1499
1514
  this.pageEngagementState = {
1500
1515
  reached: /* @__PURE__ */ new Set(),
@@ -2025,8 +2040,10 @@ var AmplifyUpSDK = class {
2025
2040
  * Apply published pageData (from /v1/resolve) so field validation and
2026
2041
  * mapped page fields can run.
2027
2042
  */
2028
- applyResolvedPageData(pageData, pageRoute, routeParams, pageResources) {
2043
+ applyResolvedPageData(pageData, pageRoute, routeParams, pageResources, pageTaxonomies) {
2029
2044
  this.resolvedPageData = pageData || null;
2045
+ this.resolvedPageTaxonomies = pageTaxonomies || null;
2046
+ this.resolvedTaxonomiesPath = this.pendingResolvePath;
2030
2047
  if (pageRoute) this.resolvedPageRoute = pageRoute;
2031
2048
  if (routeParams) this.resolvedRouteParams = routeParams;
2032
2049
  const firstResourceName = pageData?.resources?.[0]?.name;
@@ -2060,6 +2077,28 @@ var AmplifyUpSDK = class {
2060
2077
  getAttachedPageContext() {
2061
2078
  return this.attachedPageContext;
2062
2079
  }
2080
+ /**
2081
+ * The page's delivery response for `path` is on its way. A page_view for the
2082
+ * same path waits for it (up to PAGE_VIEW_HOLD_MS) so it carries the page's
2083
+ * taxonomies.
2084
+ */
2085
+ beginPageResolve(path) {
2086
+ this.pendingResolvePath = normalizeRoute(path);
2087
+ this.resolvedPageTaxonomies = null;
2088
+ this.resolvedTaxonomiesPath = null;
2089
+ }
2090
+ endPageResolve(path) {
2091
+ if (this.pendingResolvePath !== normalizeRoute(path)) return;
2092
+ this.pendingResolvePath = null;
2093
+ this.flushHeldPageView();
2094
+ }
2095
+ flushHeldPageView() {
2096
+ const held = this.heldPageView;
2097
+ if (!held) return;
2098
+ clearTimeout(held.timer);
2099
+ this.heldPageView = null;
2100
+ this.sendPageView(held.url, held.properties);
2101
+ }
2063
2102
  /**
2064
2103
  * Track a page view
2065
2104
  */
@@ -2070,6 +2109,21 @@ var AmplifyUpSDK = class {
2070
2109
  if (!this.isInitialized()) {
2071
2110
  return;
2072
2111
  }
2112
+ this.lastTrackedPath = url;
2113
+ if (this.pendingResolvePath && this.pendingResolvePath === normalizeRoute(url)) {
2114
+ this.flushHeldPageView();
2115
+ this.heldPageView = {
2116
+ url,
2117
+ properties,
2118
+ timer: setTimeout(() => this.flushHeldPageView(), PAGE_VIEW_HOLD_MS)
2119
+ };
2120
+ return;
2121
+ }
2122
+ this.flushHeldPageView();
2123
+ this.sendPageView(url, properties);
2124
+ }
2125
+ sendPageView(url, properties) {
2126
+ const taxonomies = this.resolvedTaxonomiesPath && this.resolvedTaxonomiesPath === normalizeRoute(url) ? this.resolvedPageTaxonomies : null;
2073
2127
  const instanceId = getInstanceId();
2074
2128
  const sessionId = getSessionId();
2075
2129
  const pageProperties = {
@@ -2081,10 +2135,9 @@ var AmplifyUpSDK = class {
2081
2135
  sessionId,
2082
2136
  trackingId: this.config?.trackingId,
2083
2137
  // Timestamp is included in event payload
2084
- ...mergeEventContext(properties || {}, this.attachedPageContext)
2138
+ ...withPageTaxonomies(mergeEventContext(properties || {}, this.attachedPageContext), taxonomies)
2085
2139
  };
2086
2140
  this.adapter.page(pageProperties);
2087
- this.lastTrackedPath = url;
2088
2141
  }
2089
2142
  /**
2090
2143
  * Track an event
@@ -5531,6 +5584,8 @@ function AmplifyUpProvider({
5531
5584
  React3.useEffect(() => {
5532
5585
  let cancelled = false;
5533
5586
  const sdk = getSDK();
5587
+ const heldRoute = isComposerPreview() || config.clientPersonalization !== false ? getActualRoute() : null;
5588
+ if (heldRoute) sdk.beginPageResolve(heldRoute);
5534
5589
  const run = async () => {
5535
5590
  try {
5536
5591
  await sdk.init({
@@ -5610,7 +5665,8 @@ function AmplifyUpProvider({
5610
5665
  result.pageConfig.pageData || null,
5611
5666
  result.pageConfig.route,
5612
5667
  extractRouteParams(result.pageConfig.route, actualRoute),
5613
- result.pageConfig.pageResources || null
5668
+ result.pageConfig.pageResources || null,
5669
+ result.pageConfig.pageTaxonomies || null
5614
5670
  );
5615
5671
  }
5616
5672
  setInitialized(true);
@@ -5634,6 +5690,7 @@ function AmplifyUpProvider({
5634
5690
  setSource(null);
5635
5691
  setMeta(null);
5636
5692
  } finally {
5693
+ if (heldRoute) sdk.endPageResolve(heldRoute);
5637
5694
  if (!cancelled) setLoading(false);
5638
5695
  }
5639
5696
  };