@amplifyup/sdk 0.1.75 → 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.js +121 -97
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +121 -97
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.js +121 -97
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +121 -97
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +121 -97
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +121 -97
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/AmplifyRenderer.mjs
CHANGED
|
@@ -11,7 +11,121 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
11
11
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
+
// src/storage.ts
|
|
15
|
+
var INSTANCE_ID_KEY = "amplifyup_instance_id";
|
|
16
|
+
var USER_ID_KEY = "amplifyup_user_id";
|
|
17
|
+
var SESSION_ID_KEY = "amplifyup_session_id";
|
|
18
|
+
var SESSION_ACTIVITY_KEY = "amplifyup_session_activity";
|
|
19
|
+
var VISITOR_FIRST_SEEN_KEY = "amplifyup_visitor_first_seen";
|
|
20
|
+
var ANON_COOKIE_NAME = "amplifyup_anon_id";
|
|
21
|
+
var SESSION_COOKIE_NAME = "amplifyup_session_id";
|
|
22
|
+
var SESSION_IDLE_GAP_MS = 30 * 60 * 1e3;
|
|
23
|
+
function generateGuid() {
|
|
24
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
25
|
+
return crypto.randomUUID();
|
|
26
|
+
}
|
|
27
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
28
|
+
const r = Math.random() * 16 | 0;
|
|
29
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
30
|
+
return v.toString(16);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function readCookie(name) {
|
|
34
|
+
if (typeof document === "undefined") return null;
|
|
35
|
+
const parts = document.cookie.split(";");
|
|
36
|
+
for (const part of parts) {
|
|
37
|
+
const idx = part.indexOf("=");
|
|
38
|
+
if (idx === -1) continue;
|
|
39
|
+
if (part.slice(0, idx).trim() !== name) continue;
|
|
40
|
+
const value = part.slice(idx + 1).trim();
|
|
41
|
+
try {
|
|
42
|
+
return value ? decodeURIComponent(value) : null;
|
|
43
|
+
} catch {
|
|
44
|
+
return value || null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
function writeCookie(name, value, maxAgeSeconds = 31536e3) {
|
|
50
|
+
if (typeof document === "undefined") return;
|
|
51
|
+
document.cookie = `${name}=${encodeURIComponent(value)}; Path=/; Max-Age=${maxAgeSeconds}; SameSite=Lax`;
|
|
52
|
+
}
|
|
53
|
+
function getInstanceId() {
|
|
54
|
+
if (typeof window === "undefined") {
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
const fromCookie = readCookie(ANON_COOKIE_NAME);
|
|
58
|
+
const fromLs = localStorage.getItem(INSTANCE_ID_KEY);
|
|
59
|
+
const instanceId = fromLs || fromCookie || `browser_${generateGuid()}`;
|
|
60
|
+
if (fromLs !== instanceId) {
|
|
61
|
+
localStorage.setItem(INSTANCE_ID_KEY, instanceId);
|
|
62
|
+
}
|
|
63
|
+
if (fromCookie !== instanceId) {
|
|
64
|
+
writeCookie(ANON_COOKIE_NAME, instanceId);
|
|
65
|
+
}
|
|
66
|
+
return instanceId;
|
|
67
|
+
}
|
|
68
|
+
function getUserId() {
|
|
69
|
+
if (typeof window === "undefined") {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
return localStorage.getItem(USER_ID_KEY);
|
|
73
|
+
}
|
|
74
|
+
function getSessionId() {
|
|
75
|
+
if (typeof window === "undefined") {
|
|
76
|
+
return "";
|
|
77
|
+
}
|
|
78
|
+
const now = Date.now();
|
|
79
|
+
const lastActivity = Number(localStorage.getItem(SESSION_ACTIVITY_KEY) || 0);
|
|
80
|
+
const fromCookie = readCookie(SESSION_COOKIE_NAME);
|
|
81
|
+
const fromLs = localStorage.getItem(SESSION_ID_KEY);
|
|
82
|
+
let sessionId = fromLs || fromCookie || "";
|
|
83
|
+
if (!sessionId || lastActivity > 0 && now - lastActivity >= SESSION_IDLE_GAP_MS) {
|
|
84
|
+
sessionId = generateGuid();
|
|
85
|
+
}
|
|
86
|
+
localStorage.setItem(SESSION_ID_KEY, sessionId);
|
|
87
|
+
localStorage.setItem(SESSION_ACTIVITY_KEY, String(now));
|
|
88
|
+
writeCookie(SESSION_COOKIE_NAME, sessionId, Math.floor(SESSION_IDLE_GAP_MS / 1e3));
|
|
89
|
+
return sessionId;
|
|
90
|
+
}
|
|
91
|
+
function getVisitorFirstSeenAt() {
|
|
92
|
+
if (typeof window === "undefined") {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const existing = localStorage.getItem(VISITOR_FIRST_SEEN_KEY);
|
|
97
|
+
if (existing) return existing;
|
|
98
|
+
const firstSeenAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
99
|
+
localStorage.setItem(VISITOR_FIRST_SEEN_KEY, firstSeenAt);
|
|
100
|
+
return firstSeenAt;
|
|
101
|
+
} catch {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function setUserId(userId) {
|
|
106
|
+
if (typeof window === "undefined") {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
localStorage.setItem(USER_ID_KEY, userId);
|
|
110
|
+
}
|
|
111
|
+
function clearIds() {
|
|
112
|
+
if (typeof window === "undefined") {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
localStorage.removeItem(INSTANCE_ID_KEY);
|
|
116
|
+
localStorage.removeItem(USER_ID_KEY);
|
|
117
|
+
localStorage.removeItem(SESSION_ID_KEY);
|
|
118
|
+
localStorage.removeItem(SESSION_ACTIVITY_KEY);
|
|
119
|
+
localStorage.removeItem(VISITOR_FIRST_SEEN_KEY);
|
|
120
|
+
document.cookie = `${ANON_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`;
|
|
121
|
+
document.cookie = `${SESSION_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`;
|
|
122
|
+
}
|
|
123
|
+
|
|
14
124
|
// src/adapters/aws.ts
|
|
125
|
+
function visitorContext() {
|
|
126
|
+
const firstSeenAt = getVisitorFirstSeenAt();
|
|
127
|
+
return firstSeenAt ? { firstSeenAt } : void 0;
|
|
128
|
+
}
|
|
15
129
|
var AWSAdapter = class {
|
|
16
130
|
constructor() {
|
|
17
131
|
this.initialized = false;
|
|
@@ -51,7 +165,9 @@ var AWSAdapter = class {
|
|
|
51
165
|
console.warn("AmplifyUp SDK: AWS configuration missing");
|
|
52
166
|
return;
|
|
53
167
|
}
|
|
54
|
-
const
|
|
168
|
+
const trackingId = eventData?.trackingId || this.config?.trackingId;
|
|
169
|
+
const query = trackingId ? `?tid=${encodeURIComponent(trackingId)}` : "";
|
|
170
|
+
const url = `${this.apiGatewayUrl}${endpoint}${query}`;
|
|
55
171
|
try {
|
|
56
172
|
const response = await fetch(url, {
|
|
57
173
|
method: "POST",
|
|
@@ -113,7 +229,8 @@ var AWSAdapter = class {
|
|
|
113
229
|
page: {
|
|
114
230
|
path: properties.path || properties.url,
|
|
115
231
|
referrer: properties.referrer
|
|
116
|
-
}
|
|
232
|
+
},
|
|
233
|
+
visitor: visitorContext()
|
|
117
234
|
},
|
|
118
235
|
timestamp: properties.timestamp || (/* @__PURE__ */ new Date()).toISOString()
|
|
119
236
|
};
|
|
@@ -151,7 +268,8 @@ var AWSAdapter = class {
|
|
|
151
268
|
...properties
|
|
152
269
|
},
|
|
153
270
|
context: {
|
|
154
|
-
url: properties.url || (typeof window !== "undefined" ? window.location.href : "")
|
|
271
|
+
url: properties.url || (typeof window !== "undefined" ? window.location.href : ""),
|
|
272
|
+
visitor: visitorContext()
|
|
155
273
|
},
|
|
156
274
|
timestamp: properties.timestamp || (/* @__PURE__ */ new Date()).toISOString()
|
|
157
275
|
};
|
|
@@ -207,100 +325,6 @@ var AWSAdapter = class {
|
|
|
207
325
|
}
|
|
208
326
|
};
|
|
209
327
|
|
|
210
|
-
// src/storage.ts
|
|
211
|
-
var INSTANCE_ID_KEY = "amplifyup_instance_id";
|
|
212
|
-
var USER_ID_KEY = "amplifyup_user_id";
|
|
213
|
-
var SESSION_ID_KEY = "amplifyup_session_id";
|
|
214
|
-
var SESSION_ACTIVITY_KEY = "amplifyup_session_activity";
|
|
215
|
-
var ANON_COOKIE_NAME = "amplifyup_anon_id";
|
|
216
|
-
var SESSION_COOKIE_NAME = "amplifyup_session_id";
|
|
217
|
-
var SESSION_IDLE_GAP_MS = 30 * 60 * 1e3;
|
|
218
|
-
function generateGuid() {
|
|
219
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
220
|
-
return crypto.randomUUID();
|
|
221
|
-
}
|
|
222
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
223
|
-
const r = Math.random() * 16 | 0;
|
|
224
|
-
const v = c === "x" ? r : r & 3 | 8;
|
|
225
|
-
return v.toString(16);
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
function readCookie(name) {
|
|
229
|
-
if (typeof document === "undefined") return null;
|
|
230
|
-
const parts = document.cookie.split(";");
|
|
231
|
-
for (const part of parts) {
|
|
232
|
-
const idx = part.indexOf("=");
|
|
233
|
-
if (idx === -1) continue;
|
|
234
|
-
if (part.slice(0, idx).trim() !== name) continue;
|
|
235
|
-
const value = part.slice(idx + 1).trim();
|
|
236
|
-
try {
|
|
237
|
-
return value ? decodeURIComponent(value) : null;
|
|
238
|
-
} catch {
|
|
239
|
-
return value || null;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return null;
|
|
243
|
-
}
|
|
244
|
-
function writeCookie(name, value, maxAgeSeconds = 31536e3) {
|
|
245
|
-
if (typeof document === "undefined") return;
|
|
246
|
-
document.cookie = `${name}=${encodeURIComponent(value)}; Path=/; Max-Age=${maxAgeSeconds}; SameSite=Lax`;
|
|
247
|
-
}
|
|
248
|
-
function getInstanceId() {
|
|
249
|
-
if (typeof window === "undefined") {
|
|
250
|
-
return "";
|
|
251
|
-
}
|
|
252
|
-
const fromCookie = readCookie(ANON_COOKIE_NAME);
|
|
253
|
-
const fromLs = localStorage.getItem(INSTANCE_ID_KEY);
|
|
254
|
-
const instanceId = fromLs || fromCookie || `browser_${generateGuid()}`;
|
|
255
|
-
if (fromLs !== instanceId) {
|
|
256
|
-
localStorage.setItem(INSTANCE_ID_KEY, instanceId);
|
|
257
|
-
}
|
|
258
|
-
if (fromCookie !== instanceId) {
|
|
259
|
-
writeCookie(ANON_COOKIE_NAME, instanceId);
|
|
260
|
-
}
|
|
261
|
-
return instanceId;
|
|
262
|
-
}
|
|
263
|
-
function getUserId() {
|
|
264
|
-
if (typeof window === "undefined") {
|
|
265
|
-
return null;
|
|
266
|
-
}
|
|
267
|
-
return localStorage.getItem(USER_ID_KEY);
|
|
268
|
-
}
|
|
269
|
-
function getSessionId() {
|
|
270
|
-
if (typeof window === "undefined") {
|
|
271
|
-
return "";
|
|
272
|
-
}
|
|
273
|
-
const now = Date.now();
|
|
274
|
-
const lastActivity = Number(localStorage.getItem(SESSION_ACTIVITY_KEY) || 0);
|
|
275
|
-
const fromCookie = readCookie(SESSION_COOKIE_NAME);
|
|
276
|
-
const fromLs = localStorage.getItem(SESSION_ID_KEY);
|
|
277
|
-
let sessionId = fromLs || fromCookie || "";
|
|
278
|
-
if (!sessionId || lastActivity > 0 && now - lastActivity >= SESSION_IDLE_GAP_MS) {
|
|
279
|
-
sessionId = generateGuid();
|
|
280
|
-
}
|
|
281
|
-
localStorage.setItem(SESSION_ID_KEY, sessionId);
|
|
282
|
-
localStorage.setItem(SESSION_ACTIVITY_KEY, String(now));
|
|
283
|
-
writeCookie(SESSION_COOKIE_NAME, sessionId, Math.floor(SESSION_IDLE_GAP_MS / 1e3));
|
|
284
|
-
return sessionId;
|
|
285
|
-
}
|
|
286
|
-
function setUserId(userId) {
|
|
287
|
-
if (typeof window === "undefined") {
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
localStorage.setItem(USER_ID_KEY, userId);
|
|
291
|
-
}
|
|
292
|
-
function clearIds() {
|
|
293
|
-
if (typeof window === "undefined") {
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
localStorage.removeItem(INSTANCE_ID_KEY);
|
|
297
|
-
localStorage.removeItem(USER_ID_KEY);
|
|
298
|
-
localStorage.removeItem(SESSION_ID_KEY);
|
|
299
|
-
localStorage.removeItem(SESSION_ACTIVITY_KEY);
|
|
300
|
-
document.cookie = `${ANON_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`;
|
|
301
|
-
document.cookie = `${SESSION_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
328
|
// src/targets.ts
|
|
305
329
|
var AWS_DEV_API = "https://api-dev.amplifyup.ai";
|
|
306
330
|
var AWS_PROD_API = "https://api.amplifyup.ai";
|