@amplifyup/sdk 0.1.40 → 0.1.42

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/react.js CHANGED
@@ -108,6 +108,7 @@ var AWSAdapter = class {
108
108
  const eventData = {
109
109
  type: "page",
110
110
  anonymousId: properties.instanceId,
111
+ sessionId: properties.sessionId,
111
112
  userId: properties.userId,
112
113
  properties: {
113
114
  path: properties.path || properties.url,
@@ -150,6 +151,7 @@ var AWSAdapter = class {
150
151
  type: "track",
151
152
  event: eventName,
152
153
  anonymousId: properties.instanceId,
154
+ sessionId: properties.sessionId,
153
155
  userId: properties.userId,
154
156
  properties: {
155
157
  ...properties
@@ -172,6 +174,7 @@ var AWSAdapter = class {
172
174
  const eventData = {
173
175
  type: "identify",
174
176
  anonymousId: traits.instanceId,
177
+ sessionId: traits.sessionId,
175
178
  traits: {
176
179
  ...traits,
177
180
  ...identifiers ? { identifiers } : {}
@@ -190,6 +193,7 @@ var AWSAdapter = class {
190
193
  const eventData = {
191
194
  type: "set_fields",
192
195
  anonymousId: context.instanceId,
196
+ sessionId: context.sessionId,
193
197
  fields,
194
198
  traits: {
195
199
  instanceId: context.instanceId,
@@ -212,7 +216,11 @@ var AWSAdapter = class {
212
216
  // src/storage.ts
213
217
  var INSTANCE_ID_KEY = "amplifyup_instance_id";
214
218
  var USER_ID_KEY = "amplifyup_user_id";
219
+ var SESSION_ID_KEY = "amplifyup_session_id";
220
+ var SESSION_ACTIVITY_KEY = "amplifyup_session_activity";
215
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;
216
224
  function generateGuid() {
217
225
  if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
218
226
  return crypto.randomUUID();
@@ -239,9 +247,9 @@ function readCookie(name) {
239
247
  }
240
248
  return null;
241
249
  }
242
- function writeCookie(name, value) {
250
+ function writeCookie(name, value, maxAgeSeconds = 31536e3) {
243
251
  if (typeof document === "undefined") return;
244
- document.cookie = `${name}=${encodeURIComponent(value)}; Path=/; Max-Age=31536000; SameSite=Lax`;
252
+ document.cookie = `${name}=${encodeURIComponent(value)}; Path=/; Max-Age=${maxAgeSeconds}; SameSite=Lax`;
245
253
  }
246
254
  function getInstanceId() {
247
255
  if (typeof window === "undefined") {
@@ -264,6 +272,23 @@ function getUserId() {
264
272
  }
265
273
  return localStorage.getItem(USER_ID_KEY);
266
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
+ }
267
292
  function setUserId(userId) {
268
293
  if (typeof window === "undefined") {
269
294
  return;
@@ -276,7 +301,10 @@ function clearIds() {
276
301
  }
277
302
  localStorage.removeItem(INSTANCE_ID_KEY);
278
303
  localStorage.removeItem(USER_ID_KEY);
304
+ localStorage.removeItem(SESSION_ID_KEY);
305
+ localStorage.removeItem(SESSION_ACTIVITY_KEY);
279
306
  document.cookie = `${ANON_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`;
307
+ document.cookie = `${SESSION_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`;
280
308
  }
281
309
 
282
310
  // src/targets.ts
@@ -439,6 +467,7 @@ async function fetchEdgeResolve(options) {
439
467
  params.set("variants", variantParam);
440
468
  } else if (options.anonId) {
441
469
  params.set("anonId", options.anonId);
470
+ if (options.sessionId) params.set("sessionId", options.sessionId);
442
471
  }
443
472
  const fetchFn = options.fetch ?? globalThis.fetch.bind(globalThis);
444
473
  const init = {
@@ -540,6 +569,7 @@ async function fetchContent(options) {
540
569
  trackingId: options.trackingId,
541
570
  route: options.route,
542
571
  anonId: options.variantKeys ? void 0 : options.anonId,
572
+ sessionId: options.variantKeys ? void 0 : options.sessionId,
543
573
  siteId: options.siteId,
544
574
  fetch: options.fetchFn,
545
575
  revalidate: options.revalidate,
@@ -609,6 +639,7 @@ async function fetchEdgeSelect(options) {
609
639
  ...options.trackingId ? { trackingId: options.trackingId } : {},
610
640
  ...options.site ? { site: options.site } : {},
611
641
  anonId: options.anonId,
642
+ ...options.sessionId ? { sessionId: options.sessionId } : {},
612
643
  ...options.zones?.length ? { zones: options.zones } : {},
613
644
  ...options.context ? { context: options.context } : {}
614
645
  })
@@ -637,6 +668,7 @@ async function selectVariants(options) {
637
668
  site: options.site,
638
669
  view: options.view,
639
670
  anonId: options.anonId,
671
+ sessionId: options.sessionId,
640
672
  zones: options.zones,
641
673
  context: options.context,
642
674
  fetch: options.fetch,
@@ -721,7 +753,6 @@ function searchSpec(pagination, field, term) {
721
753
  }
722
754
 
723
755
  // src/index.ts
724
- var SESSION_IDLE_GAP_MS = 30 * 60 * 1e3;
725
756
  var DWELL_ACTIVITY_IDLE_MS = 2 * 60 * 1e3;
726
757
  var DWELL_POLL_MS = 5e3;
727
758
  function readPreviewQueryOverrides() {
@@ -897,6 +928,7 @@ var AmplifyUpSDK = class {
897
928
  if (typeof window === "undefined") return;
898
929
  window.AmplifyUp = {
899
930
  getInstanceId: () => this.getInstanceId(),
931
+ getSessionId: () => this.getSessionId(),
900
932
  getUserId: () => this.getUserId(),
901
933
  getTrackingId: () => this.getTrackingId(),
902
934
  getTarget: () => this.getTarget(),
@@ -1319,12 +1351,14 @@ var AmplifyUpSDK = class {
1319
1351
  return;
1320
1352
  }
1321
1353
  const instanceId = getInstanceId();
1354
+ const sessionId = getSessionId();
1322
1355
  const pageProperties = {
1323
1356
  name: url,
1324
1357
  path: url,
1325
1358
  url: typeof window !== "undefined" ? window.location.href : url,
1326
1359
  referrer: typeof document !== "undefined" ? document.referrer : void 0,
1327
1360
  instanceId,
1361
+ sessionId,
1328
1362
  trackingId: this.config?.trackingId,
1329
1363
  // Timestamp is included in event payload
1330
1364
  ...properties
@@ -1343,8 +1377,10 @@ var AmplifyUpSDK = class {
1343
1377
  return;
1344
1378
  }
1345
1379
  const instanceId = getInstanceId();
1380
+ const sessionId = getSessionId();
1346
1381
  const trackProperties = {
1347
1382
  instanceId,
1383
+ sessionId,
1348
1384
  trackingId: this.config?.trackingId,
1349
1385
  url: typeof window !== "undefined" ? window.location.href : void 0,
1350
1386
  path: properties?.path || (typeof window !== "undefined" ? window.location.pathname : void 0),
@@ -1417,8 +1453,10 @@ var AmplifyUpSDK = class {
1417
1453
  return;
1418
1454
  }
1419
1455
  const instanceId = getInstanceId();
1456
+ const sessionId = getSessionId();
1420
1457
  const identifyTraits = {
1421
1458
  instanceId,
1459
+ sessionId,
1422
1460
  trackingId: this.config?.trackingId,
1423
1461
  ...traits
1424
1462
  };
@@ -1456,6 +1494,7 @@ var AmplifyUpSDK = class {
1456
1494
  if (typeof this.adapter.setProfileFields === "function") {
1457
1495
  this.adapter.setProfileFields(fields, {
1458
1496
  instanceId: instanceId || void 0,
1497
+ sessionId: getSessionId() || void 0,
1459
1498
  trackingId: this.config?.trackingId
1460
1499
  });
1461
1500
  }
@@ -1506,6 +1545,12 @@ var AmplifyUpSDK = class {
1506
1545
  getInstanceId() {
1507
1546
  return getInstanceId();
1508
1547
  }
1548
+ /**
1549
+ * Get session id (30-minute inactivity reset).
1550
+ */
1551
+ getSessionId() {
1552
+ return getSessionId();
1553
+ }
1509
1554
  /**
1510
1555
  * Get user ID
1511
1556
  */
@@ -3222,6 +3267,9 @@ function isReactNodeFallback(fallback) {
3222
3267
  if (fallback == null || fallback === false) return false;
3223
3268
  return !isPlainTextValue(fallback);
3224
3269
  }
3270
+ function classNameIsBlock(className) {
3271
+ return /(?:^|\s)block(?:\s|$)/.test(className || "");
3272
+ }
3225
3273
  function htmlHasVisualChrome(html) {
3226
3274
  return /<(input|button|select|textarea|form|svg|iframe|video|audio|img)\b/i.test(
3227
3275
  html
@@ -3398,7 +3446,8 @@ function ComposerInlineField({
3398
3446
  outlineOffset: "2px",
3399
3447
  minWidth: "1ch",
3400
3448
  minHeight: "1em",
3401
- display: render ? void 0 : "inline",
3449
+ // Do not force `inline` — that overrides Tailwind `block` and parks
3450
+ // an empty-field hint on the same line as a sibling that has a value.
3402
3451
  opacity: showHint ? 0.5 : void 0
3403
3452
  },
3404
3453
  children: showRendered ? value != null && value !== "" && !storedEmpty ? render(value) : fallback ?? idleDisplay : isReactNodeFallback(fallback) && !idleDisplay ? fallback : null
@@ -3522,7 +3571,8 @@ function Field({
3522
3571
  }
3523
3572
  const text = formatFieldValue(fieldValue);
3524
3573
  const showVisualFallback = !text && isReactNodeFallback(fallback);
3525
- if (composerEdit && canInlineEdit(name, fieldValue) && !showVisualFallback) {
3574
+ const emptyBlockField = isComposerEmptyText(fieldValue) && classNameIsBlock(className);
3575
+ if (composerEdit && canInlineEdit(name, fieldValue) && !showVisualFallback && !emptyBlockField) {
3526
3576
  return /* @__PURE__ */ jsxRuntime.jsx(
3527
3577
  ComposerInlineField,
3528
3578
  {
@@ -3535,7 +3585,7 @@ function Field({
3535
3585
  }
3536
3586
  );
3537
3587
  }
3538
- if (fieldValue === void 0 || fieldValue === null) {
3588
+ if (fieldValue === void 0 || fieldValue === null || isComposerEmptyText(fieldValue)) {
3539
3589
  return fallback ? /* @__PURE__ */ jsxRuntime.jsx("span", { className, children: fallback }) : null;
3540
3590
  }
3541
3591
  if (!text) {
@@ -3569,7 +3619,7 @@ function RichText({
3569
3619
  return fallback ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fallback }) : null;
3570
3620
  }
3571
3621
  if (isComposerEmptyText(fieldValue)) {
3572
- if (composerEdit && canInlineEdit(name, fieldValue) && !isReactNodeFallback(fallback)) {
3622
+ if (composerEdit && canInlineEdit(name, fieldValue) && !isReactNodeFallback(fallback) && !classNameIsBlock(className)) {
3573
3623
  return /* @__PURE__ */ jsxRuntime.jsx(
3574
3624
  ComposerInlineField,
3575
3625
  {
@@ -4378,12 +4428,14 @@ function AmplifyUpProvider({ children, config }) {
4378
4428
  }
4379
4429
  let variantKeys;
4380
4430
  const anonId = sdk.getInstanceId();
4431
+ const sessionId = sdk.getSessionId();
4381
4432
  if (!preview && anonId) {
4382
4433
  try {
4383
4434
  const selected = await selectVariants({
4384
4435
  trackingId,
4385
4436
  view: actualRoute,
4386
4437
  anonId,
4438
+ sessionId: sessionId || void 0,
4387
4439
  site: sdk.getSiteId() || void 0,
4388
4440
  edgeUrl
4389
4441
  });
@@ -4396,6 +4448,7 @@ function AmplifyUpProvider({ children, config }) {
4396
4448
  route: actualRoute,
4397
4449
  trackingId,
4398
4450
  anonId: variantKeys ? void 0 : anonId,
4451
+ sessionId: variantKeys ? void 0 : sessionId || void 0,
4399
4452
  siteId: sdk.getSiteId() || null,
4400
4453
  preview,
4401
4454
  orchestratorUrl,