@amplifyup/sdk 0.1.74 → 0.1.76
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 +197 -100
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +197 -100
- 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 +199 -122
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +199 -122
- 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 +204 -123
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +204 -123
- 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/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,
|
|
3
|
-
export {
|
|
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-
|
|
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,
|
|
3
|
-
export {
|
|
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-
|
|
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
|
@@ -17,7 +17,121 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
17
17
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
+
// src/storage.ts
|
|
21
|
+
var INSTANCE_ID_KEY = "amplifyup_instance_id";
|
|
22
|
+
var USER_ID_KEY = "amplifyup_user_id";
|
|
23
|
+
var SESSION_ID_KEY = "amplifyup_session_id";
|
|
24
|
+
var SESSION_ACTIVITY_KEY = "amplifyup_session_activity";
|
|
25
|
+
var VISITOR_FIRST_SEEN_KEY = "amplifyup_visitor_first_seen";
|
|
26
|
+
var ANON_COOKIE_NAME = "amplifyup_anon_id";
|
|
27
|
+
var SESSION_COOKIE_NAME = "amplifyup_session_id";
|
|
28
|
+
var SESSION_IDLE_GAP_MS = 30 * 60 * 1e3;
|
|
29
|
+
function generateGuid() {
|
|
30
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
31
|
+
return crypto.randomUUID();
|
|
32
|
+
}
|
|
33
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
34
|
+
const r = Math.random() * 16 | 0;
|
|
35
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
36
|
+
return v.toString(16);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function readCookie(name) {
|
|
40
|
+
if (typeof document === "undefined") return null;
|
|
41
|
+
const parts = document.cookie.split(";");
|
|
42
|
+
for (const part of parts) {
|
|
43
|
+
const idx = part.indexOf("=");
|
|
44
|
+
if (idx === -1) continue;
|
|
45
|
+
if (part.slice(0, idx).trim() !== name) continue;
|
|
46
|
+
const value = part.slice(idx + 1).trim();
|
|
47
|
+
try {
|
|
48
|
+
return value ? decodeURIComponent(value) : null;
|
|
49
|
+
} catch {
|
|
50
|
+
return value || null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
function writeCookie(name, value, maxAgeSeconds = 31536e3) {
|
|
56
|
+
if (typeof document === "undefined") return;
|
|
57
|
+
document.cookie = `${name}=${encodeURIComponent(value)}; Path=/; Max-Age=${maxAgeSeconds}; SameSite=Lax`;
|
|
58
|
+
}
|
|
59
|
+
function getInstanceId() {
|
|
60
|
+
if (typeof window === "undefined") {
|
|
61
|
+
return "";
|
|
62
|
+
}
|
|
63
|
+
const fromCookie = readCookie(ANON_COOKIE_NAME);
|
|
64
|
+
const fromLs = localStorage.getItem(INSTANCE_ID_KEY);
|
|
65
|
+
const instanceId = fromLs || fromCookie || `browser_${generateGuid()}`;
|
|
66
|
+
if (fromLs !== instanceId) {
|
|
67
|
+
localStorage.setItem(INSTANCE_ID_KEY, instanceId);
|
|
68
|
+
}
|
|
69
|
+
if (fromCookie !== instanceId) {
|
|
70
|
+
writeCookie(ANON_COOKIE_NAME, instanceId);
|
|
71
|
+
}
|
|
72
|
+
return instanceId;
|
|
73
|
+
}
|
|
74
|
+
function getUserId() {
|
|
75
|
+
if (typeof window === "undefined") {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return localStorage.getItem(USER_ID_KEY);
|
|
79
|
+
}
|
|
80
|
+
function getSessionId() {
|
|
81
|
+
if (typeof window === "undefined") {
|
|
82
|
+
return "";
|
|
83
|
+
}
|
|
84
|
+
const now = Date.now();
|
|
85
|
+
const lastActivity = Number(localStorage.getItem(SESSION_ACTIVITY_KEY) || 0);
|
|
86
|
+
const fromCookie = readCookie(SESSION_COOKIE_NAME);
|
|
87
|
+
const fromLs = localStorage.getItem(SESSION_ID_KEY);
|
|
88
|
+
let sessionId = fromLs || fromCookie || "";
|
|
89
|
+
if (!sessionId || lastActivity > 0 && now - lastActivity >= SESSION_IDLE_GAP_MS) {
|
|
90
|
+
sessionId = generateGuid();
|
|
91
|
+
}
|
|
92
|
+
localStorage.setItem(SESSION_ID_KEY, sessionId);
|
|
93
|
+
localStorage.setItem(SESSION_ACTIVITY_KEY, String(now));
|
|
94
|
+
writeCookie(SESSION_COOKIE_NAME, sessionId, Math.floor(SESSION_IDLE_GAP_MS / 1e3));
|
|
95
|
+
return sessionId;
|
|
96
|
+
}
|
|
97
|
+
function getVisitorFirstSeenAt() {
|
|
98
|
+
if (typeof window === "undefined") {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const existing = localStorage.getItem(VISITOR_FIRST_SEEN_KEY);
|
|
103
|
+
if (existing) return existing;
|
|
104
|
+
const firstSeenAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
105
|
+
localStorage.setItem(VISITOR_FIRST_SEEN_KEY, firstSeenAt);
|
|
106
|
+
return firstSeenAt;
|
|
107
|
+
} catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function setUserId(userId) {
|
|
112
|
+
if (typeof window === "undefined") {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
localStorage.setItem(USER_ID_KEY, userId);
|
|
116
|
+
}
|
|
117
|
+
function clearIds() {
|
|
118
|
+
if (typeof window === "undefined") {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
localStorage.removeItem(INSTANCE_ID_KEY);
|
|
122
|
+
localStorage.removeItem(USER_ID_KEY);
|
|
123
|
+
localStorage.removeItem(SESSION_ID_KEY);
|
|
124
|
+
localStorage.removeItem(SESSION_ACTIVITY_KEY);
|
|
125
|
+
localStorage.removeItem(VISITOR_FIRST_SEEN_KEY);
|
|
126
|
+
document.cookie = `${ANON_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`;
|
|
127
|
+
document.cookie = `${SESSION_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`;
|
|
128
|
+
}
|
|
129
|
+
|
|
20
130
|
// src/adapters/aws.ts
|
|
131
|
+
function visitorContext() {
|
|
132
|
+
const firstSeenAt = getVisitorFirstSeenAt();
|
|
133
|
+
return firstSeenAt ? { firstSeenAt } : void 0;
|
|
134
|
+
}
|
|
21
135
|
var AWSAdapter = class {
|
|
22
136
|
constructor() {
|
|
23
137
|
this.initialized = false;
|
|
@@ -57,7 +171,9 @@ var AWSAdapter = class {
|
|
|
57
171
|
console.warn("AmplifyUp SDK: AWS configuration missing");
|
|
58
172
|
return;
|
|
59
173
|
}
|
|
60
|
-
const
|
|
174
|
+
const trackingId = eventData?.trackingId || this.config?.trackingId;
|
|
175
|
+
const query = trackingId ? `?tid=${encodeURIComponent(trackingId)}` : "";
|
|
176
|
+
const url = `${this.apiGatewayUrl}${endpoint}${query}`;
|
|
61
177
|
try {
|
|
62
178
|
const response = await fetch(url, {
|
|
63
179
|
method: "POST",
|
|
@@ -119,7 +235,8 @@ var AWSAdapter = class {
|
|
|
119
235
|
page: {
|
|
120
236
|
path: properties.path || properties.url,
|
|
121
237
|
referrer: properties.referrer
|
|
122
|
-
}
|
|
238
|
+
},
|
|
239
|
+
visitor: visitorContext()
|
|
123
240
|
},
|
|
124
241
|
timestamp: properties.timestamp || (/* @__PURE__ */ new Date()).toISOString()
|
|
125
242
|
};
|
|
@@ -157,7 +274,8 @@ var AWSAdapter = class {
|
|
|
157
274
|
...properties
|
|
158
275
|
},
|
|
159
276
|
context: {
|
|
160
|
-
url: properties.url || (typeof window !== "undefined" ? window.location.href : "")
|
|
277
|
+
url: properties.url || (typeof window !== "undefined" ? window.location.href : ""),
|
|
278
|
+
visitor: visitorContext()
|
|
161
279
|
},
|
|
162
280
|
timestamp: properties.timestamp || (/* @__PURE__ */ new Date()).toISOString()
|
|
163
281
|
};
|
|
@@ -213,100 +331,6 @@ var AWSAdapter = class {
|
|
|
213
331
|
}
|
|
214
332
|
};
|
|
215
333
|
|
|
216
|
-
// src/storage.ts
|
|
217
|
-
var INSTANCE_ID_KEY = "amplifyup_instance_id";
|
|
218
|
-
var USER_ID_KEY = "amplifyup_user_id";
|
|
219
|
-
var SESSION_ID_KEY = "amplifyup_session_id";
|
|
220
|
-
var SESSION_ACTIVITY_KEY = "amplifyup_session_activity";
|
|
221
|
-
var ANON_COOKIE_NAME = "amplifyup_anon_id";
|
|
222
|
-
var SESSION_COOKIE_NAME = "amplifyup_session_id";
|
|
223
|
-
var SESSION_IDLE_GAP_MS = 30 * 60 * 1e3;
|
|
224
|
-
function generateGuid() {
|
|
225
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
226
|
-
return crypto.randomUUID();
|
|
227
|
-
}
|
|
228
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
229
|
-
const r = Math.random() * 16 | 0;
|
|
230
|
-
const v = c === "x" ? r : r & 3 | 8;
|
|
231
|
-
return v.toString(16);
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
function readCookie(name) {
|
|
235
|
-
if (typeof document === "undefined") return null;
|
|
236
|
-
const parts = document.cookie.split(";");
|
|
237
|
-
for (const part of parts) {
|
|
238
|
-
const idx = part.indexOf("=");
|
|
239
|
-
if (idx === -1) continue;
|
|
240
|
-
if (part.slice(0, idx).trim() !== name) continue;
|
|
241
|
-
const value = part.slice(idx + 1).trim();
|
|
242
|
-
try {
|
|
243
|
-
return value ? decodeURIComponent(value) : null;
|
|
244
|
-
} catch {
|
|
245
|
-
return value || null;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
return null;
|
|
249
|
-
}
|
|
250
|
-
function writeCookie(name, value, maxAgeSeconds = 31536e3) {
|
|
251
|
-
if (typeof document === "undefined") return;
|
|
252
|
-
document.cookie = `${name}=${encodeURIComponent(value)}; Path=/; Max-Age=${maxAgeSeconds}; SameSite=Lax`;
|
|
253
|
-
}
|
|
254
|
-
function getInstanceId() {
|
|
255
|
-
if (typeof window === "undefined") {
|
|
256
|
-
return "";
|
|
257
|
-
}
|
|
258
|
-
const fromCookie = readCookie(ANON_COOKIE_NAME);
|
|
259
|
-
const fromLs = localStorage.getItem(INSTANCE_ID_KEY);
|
|
260
|
-
const instanceId = fromLs || fromCookie || `browser_${generateGuid()}`;
|
|
261
|
-
if (fromLs !== instanceId) {
|
|
262
|
-
localStorage.setItem(INSTANCE_ID_KEY, instanceId);
|
|
263
|
-
}
|
|
264
|
-
if (fromCookie !== instanceId) {
|
|
265
|
-
writeCookie(ANON_COOKIE_NAME, instanceId);
|
|
266
|
-
}
|
|
267
|
-
return instanceId;
|
|
268
|
-
}
|
|
269
|
-
function getUserId() {
|
|
270
|
-
if (typeof window === "undefined") {
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
return localStorage.getItem(USER_ID_KEY);
|
|
274
|
-
}
|
|
275
|
-
function getSessionId() {
|
|
276
|
-
if (typeof window === "undefined") {
|
|
277
|
-
return "";
|
|
278
|
-
}
|
|
279
|
-
const now = Date.now();
|
|
280
|
-
const lastActivity = Number(localStorage.getItem(SESSION_ACTIVITY_KEY) || 0);
|
|
281
|
-
const fromCookie = readCookie(SESSION_COOKIE_NAME);
|
|
282
|
-
const fromLs = localStorage.getItem(SESSION_ID_KEY);
|
|
283
|
-
let sessionId = fromLs || fromCookie || "";
|
|
284
|
-
if (!sessionId || lastActivity > 0 && now - lastActivity >= SESSION_IDLE_GAP_MS) {
|
|
285
|
-
sessionId = generateGuid();
|
|
286
|
-
}
|
|
287
|
-
localStorage.setItem(SESSION_ID_KEY, sessionId);
|
|
288
|
-
localStorage.setItem(SESSION_ACTIVITY_KEY, String(now));
|
|
289
|
-
writeCookie(SESSION_COOKIE_NAME, sessionId, Math.floor(SESSION_IDLE_GAP_MS / 1e3));
|
|
290
|
-
return sessionId;
|
|
291
|
-
}
|
|
292
|
-
function setUserId(userId) {
|
|
293
|
-
if (typeof window === "undefined") {
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
localStorage.setItem(USER_ID_KEY, userId);
|
|
297
|
-
}
|
|
298
|
-
function clearIds() {
|
|
299
|
-
if (typeof window === "undefined") {
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
localStorage.removeItem(INSTANCE_ID_KEY);
|
|
303
|
-
localStorage.removeItem(USER_ID_KEY);
|
|
304
|
-
localStorage.removeItem(SESSION_ID_KEY);
|
|
305
|
-
localStorage.removeItem(SESSION_ACTIVITY_KEY);
|
|
306
|
-
document.cookie = `${ANON_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`;
|
|
307
|
-
document.cookie = `${SESSION_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
334
|
// src/targets.ts
|
|
311
335
|
var AWS_DEV_API = "https://api-dev.amplifyup.ai";
|
|
312
336
|
var AWS_PROD_API = "https://api.amplifyup.ai";
|
|
@@ -843,6 +867,7 @@ function applyPageContext(input, opts) {
|
|
|
843
867
|
}
|
|
844
868
|
const pageFields = {};
|
|
845
869
|
for (const pf of opts.pageData?.pageFields || []) {
|
|
870
|
+
if (pf.dataType === "taxonomy") continue;
|
|
846
871
|
if (pf.source === "static") {
|
|
847
872
|
if (pf.value !== void 0) pageFields[pf.key] = pf.value;
|
|
848
873
|
continue;
|
|
@@ -865,6 +890,7 @@ function applyPageContext(input, opts) {
|
|
|
865
890
|
function staticPageFieldsFromSnapshot(pageData) {
|
|
866
891
|
const pageFields = {};
|
|
867
892
|
for (const pf of pageData?.pageFields || []) {
|
|
893
|
+
if (pf.dataType === "taxonomy") continue;
|
|
868
894
|
if (pf.source === "static" && pf.value !== void 0) {
|
|
869
895
|
pageFields[pf.key] = pf.value;
|
|
870
896
|
}
|
|
@@ -882,6 +908,11 @@ function attachStaticPageContext(pageData, pageRoute) {
|
|
|
882
908
|
pageRoute: pageRoute || ""
|
|
883
909
|
};
|
|
884
910
|
}
|
|
911
|
+
function withPageTaxonomies(properties, taxonomies) {
|
|
912
|
+
if (!taxonomies || Object.keys(taxonomies).length === 0) return properties;
|
|
913
|
+
const page = properties.page && typeof properties.page === "object" && !Array.isArray(properties.page) ? properties.page : { fields: {} };
|
|
914
|
+
return { ...properties, page: { ...page, taxonomies } };
|
|
915
|
+
}
|
|
885
916
|
function mergeEventContext(properties, attached) {
|
|
886
917
|
if (!attached) return properties;
|
|
887
918
|
return {
|
|
@@ -951,6 +982,27 @@ function hydratePageResourceProps(props, fields) {
|
|
|
951
982
|
return out;
|
|
952
983
|
}
|
|
953
984
|
|
|
985
|
+
// src/edge/normalizeRoute.ts
|
|
986
|
+
function normalizeRoute(route) {
|
|
987
|
+
let path = String(route || "").trim();
|
|
988
|
+
if (!path) return "/";
|
|
989
|
+
try {
|
|
990
|
+
if (/^https?:\/\//i.test(path)) {
|
|
991
|
+
path = new URL(path).pathname;
|
|
992
|
+
}
|
|
993
|
+
} catch {
|
|
994
|
+
}
|
|
995
|
+
const q = path.indexOf("?");
|
|
996
|
+
if (q >= 0) path = path.slice(0, q);
|
|
997
|
+
const h = path.indexOf("#");
|
|
998
|
+
if (h >= 0) path = path.slice(0, h);
|
|
999
|
+
if (!path.startsWith("/")) path = `/${path}`;
|
|
1000
|
+
if (path.length > 1 && path.endsWith("/")) {
|
|
1001
|
+
path = path.replace(/\/+$/, "");
|
|
1002
|
+
}
|
|
1003
|
+
return path || "/";
|
|
1004
|
+
}
|
|
1005
|
+
|
|
954
1006
|
// src/page-resource-runtime.ts
|
|
955
1007
|
var pageResourceFields = null;
|
|
956
1008
|
function setPageResourceFields(fields) {
|
|
@@ -1048,27 +1100,6 @@ function previewLayoutReady(opts) {
|
|
|
1048
1100
|
return true;
|
|
1049
1101
|
}
|
|
1050
1102
|
|
|
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
1103
|
// src/edge/variantKeys.ts
|
|
1073
1104
|
function serializeVariantKeys(keys) {
|
|
1074
1105
|
if (!keys) return "";
|
|
@@ -1190,7 +1221,8 @@ function mapResolvedToPageConfig(payload) {
|
|
|
1190
1221
|
},
|
|
1191
1222
|
...payload.eventTracking && payload.eventTracking.length > 0 ? { eventTracking: payload.eventTracking } : {},
|
|
1192
1223
|
...payload.pageData ? { pageData: payload.pageData } : {},
|
|
1193
|
-
...payload.pageResources ? { pageResources: payload.pageResources } : {}
|
|
1224
|
+
...payload.pageResources ? { pageResources: payload.pageResources } : {},
|
|
1225
|
+
...payload.pageTaxonomies ? { pageTaxonomies: payload.pageTaxonomies } : {}
|
|
1194
1226
|
};
|
|
1195
1227
|
}
|
|
1196
1228
|
function collectDegraded(payload) {
|
|
@@ -1422,6 +1454,7 @@ function searchSpec(pagination, field, term) {
|
|
|
1422
1454
|
}
|
|
1423
1455
|
|
|
1424
1456
|
// src/index.ts
|
|
1457
|
+
var PAGE_VIEW_HOLD_MS = 1500;
|
|
1425
1458
|
var DWELL_ACTIVITY_IDLE_MS = 2 * 60 * 1e3;
|
|
1426
1459
|
var DWELL_POLL_MS = 5e3;
|
|
1427
1460
|
function readPreviewQueryOverrides() {
|
|
@@ -1495,6 +1528,12 @@ var AmplifyUpSDK = class {
|
|
|
1495
1528
|
this.resolvedPageResource = null;
|
|
1496
1529
|
this.resolvedPageRoute = "";
|
|
1497
1530
|
this.resolvedRouteParams = {};
|
|
1531
|
+
/** Path whose delivery response is in flight; page_view for it is held. */
|
|
1532
|
+
this.pendingResolvePath = null;
|
|
1533
|
+
this.heldPageView = null;
|
|
1534
|
+
this.resolvedPageTaxonomies = null;
|
|
1535
|
+
/** Path the taxonomies above were resolved for. */
|
|
1536
|
+
this.resolvedTaxonomiesPath = null;
|
|
1498
1537
|
this.historyHooksInstalled = false;
|
|
1499
1538
|
this.pageEngagementState = {
|
|
1500
1539
|
reached: /* @__PURE__ */ new Set(),
|
|
@@ -2025,8 +2064,10 @@ var AmplifyUpSDK = class {
|
|
|
2025
2064
|
* Apply published pageData (from /v1/resolve) so field validation and
|
|
2026
2065
|
* mapped page fields can run.
|
|
2027
2066
|
*/
|
|
2028
|
-
applyResolvedPageData(pageData, pageRoute, routeParams, pageResources) {
|
|
2067
|
+
applyResolvedPageData(pageData, pageRoute, routeParams, pageResources, pageTaxonomies) {
|
|
2029
2068
|
this.resolvedPageData = pageData || null;
|
|
2069
|
+
this.resolvedPageTaxonomies = pageTaxonomies || null;
|
|
2070
|
+
this.resolvedTaxonomiesPath = this.pendingResolvePath;
|
|
2030
2071
|
if (pageRoute) this.resolvedPageRoute = pageRoute;
|
|
2031
2072
|
if (routeParams) this.resolvedRouteParams = routeParams;
|
|
2032
2073
|
const firstResourceName = pageData?.resources?.[0]?.name;
|
|
@@ -2060,6 +2101,28 @@ var AmplifyUpSDK = class {
|
|
|
2060
2101
|
getAttachedPageContext() {
|
|
2061
2102
|
return this.attachedPageContext;
|
|
2062
2103
|
}
|
|
2104
|
+
/**
|
|
2105
|
+
* The page's delivery response for `path` is on its way. A page_view for the
|
|
2106
|
+
* same path waits for it (up to PAGE_VIEW_HOLD_MS) so it carries the page's
|
|
2107
|
+
* taxonomies.
|
|
2108
|
+
*/
|
|
2109
|
+
beginPageResolve(path) {
|
|
2110
|
+
this.pendingResolvePath = normalizeRoute(path);
|
|
2111
|
+
this.resolvedPageTaxonomies = null;
|
|
2112
|
+
this.resolvedTaxonomiesPath = null;
|
|
2113
|
+
}
|
|
2114
|
+
endPageResolve(path) {
|
|
2115
|
+
if (this.pendingResolvePath !== normalizeRoute(path)) return;
|
|
2116
|
+
this.pendingResolvePath = null;
|
|
2117
|
+
this.flushHeldPageView();
|
|
2118
|
+
}
|
|
2119
|
+
flushHeldPageView() {
|
|
2120
|
+
const held = this.heldPageView;
|
|
2121
|
+
if (!held) return;
|
|
2122
|
+
clearTimeout(held.timer);
|
|
2123
|
+
this.heldPageView = null;
|
|
2124
|
+
this.sendPageView(held.url, held.properties);
|
|
2125
|
+
}
|
|
2063
2126
|
/**
|
|
2064
2127
|
* Track a page view
|
|
2065
2128
|
*/
|
|
@@ -2070,6 +2133,21 @@ var AmplifyUpSDK = class {
|
|
|
2070
2133
|
if (!this.isInitialized()) {
|
|
2071
2134
|
return;
|
|
2072
2135
|
}
|
|
2136
|
+
this.lastTrackedPath = url;
|
|
2137
|
+
if (this.pendingResolvePath && this.pendingResolvePath === normalizeRoute(url)) {
|
|
2138
|
+
this.flushHeldPageView();
|
|
2139
|
+
this.heldPageView = {
|
|
2140
|
+
url,
|
|
2141
|
+
properties,
|
|
2142
|
+
timer: setTimeout(() => this.flushHeldPageView(), PAGE_VIEW_HOLD_MS)
|
|
2143
|
+
};
|
|
2144
|
+
return;
|
|
2145
|
+
}
|
|
2146
|
+
this.flushHeldPageView();
|
|
2147
|
+
this.sendPageView(url, properties);
|
|
2148
|
+
}
|
|
2149
|
+
sendPageView(url, properties) {
|
|
2150
|
+
const taxonomies = this.resolvedTaxonomiesPath && this.resolvedTaxonomiesPath === normalizeRoute(url) ? this.resolvedPageTaxonomies : null;
|
|
2073
2151
|
const instanceId = getInstanceId();
|
|
2074
2152
|
const sessionId = getSessionId();
|
|
2075
2153
|
const pageProperties = {
|
|
@@ -2081,10 +2159,9 @@ var AmplifyUpSDK = class {
|
|
|
2081
2159
|
sessionId,
|
|
2082
2160
|
trackingId: this.config?.trackingId,
|
|
2083
2161
|
// Timestamp is included in event payload
|
|
2084
|
-
...mergeEventContext(properties || {}, this.attachedPageContext)
|
|
2162
|
+
...withPageTaxonomies(mergeEventContext(properties || {}, this.attachedPageContext), taxonomies)
|
|
2085
2163
|
};
|
|
2086
2164
|
this.adapter.page(pageProperties);
|
|
2087
|
-
this.lastTrackedPath = url;
|
|
2088
2165
|
}
|
|
2089
2166
|
/**
|
|
2090
2167
|
* Track an event
|
|
@@ -5531,6 +5608,8 @@ function AmplifyUpProvider({
|
|
|
5531
5608
|
React3.useEffect(() => {
|
|
5532
5609
|
let cancelled = false;
|
|
5533
5610
|
const sdk = getSDK();
|
|
5611
|
+
const heldRoute = isComposerPreview() || config.clientPersonalization !== false ? getActualRoute() : null;
|
|
5612
|
+
if (heldRoute) sdk.beginPageResolve(heldRoute);
|
|
5534
5613
|
const run = async () => {
|
|
5535
5614
|
try {
|
|
5536
5615
|
await sdk.init({
|
|
@@ -5610,7 +5689,8 @@ function AmplifyUpProvider({
|
|
|
5610
5689
|
result.pageConfig.pageData || null,
|
|
5611
5690
|
result.pageConfig.route,
|
|
5612
5691
|
extractRouteParams(result.pageConfig.route, actualRoute),
|
|
5613
|
-
result.pageConfig.pageResources || null
|
|
5692
|
+
result.pageConfig.pageResources || null,
|
|
5693
|
+
result.pageConfig.pageTaxonomies || null
|
|
5614
5694
|
);
|
|
5615
5695
|
}
|
|
5616
5696
|
setInitialized(true);
|
|
@@ -5634,6 +5714,7 @@ function AmplifyUpProvider({
|
|
|
5634
5714
|
setSource(null);
|
|
5635
5715
|
setMeta(null);
|
|
5636
5716
|
} finally {
|
|
5717
|
+
if (heldRoute) sdk.endPageResolve(heldRoute);
|
|
5637
5718
|
if (!cancelled) setLoading(false);
|
|
5638
5719
|
}
|
|
5639
5720
|
};
|