@depict-ai/utilishared 2.6.21 → 2.6.23

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.
@@ -85,6 +85,11 @@ $parcel$export(module.exports, "get_session_id", () => $335c248bb07a3509$export$
85
85
  $parcel$export(module.exports, "get_cookie", () => $335c248bb07a3509$export$622991c71a1f52b3);
86
86
  $parcel$export(module.exports, "get_tracking_event_context_data", () => $335c248bb07a3509$export$8c6f26a5b6921b95);
87
87
  $parcel$export(module.exports, "set_event_transport", () => $bccbc7bdec4799cf$export$83c5d6634ba2a3c5);
88
+ $parcel$export(module.exports, "set_event_api", () => $bccbc7bdec4799cf$export$1a4819a80859e92e);
89
+ $parcel$export(module.exports, "get_event_api", () => $bccbc7bdec4799cf$export$88fbe329a1d960c8);
90
+ $parcel$export(module.exports, "queue_native_events", () => $bccbc7bdec4799cf$export$f72bace509bf62ef);
91
+ $parcel$export(module.exports, "native_purchase_event", () => $c9b040323c0805db$export$aad1b28cf2e0eea6);
92
+ $parcel$export(module.exports, "to_native_event", () => $c9b040323c0805db$export$537c002f32ae6f61);
88
93
  $parcel$export(module.exports, "filter_depict_payload", () => $49880c4ce4bb7db2$export$72036d950e1fae95);
89
94
  $parcel$export(module.exports, "send_depict", () => $49880c4ce4bb7db2$export$28cacbd9b4306ffc);
90
95
  $parcel$export(module.exports, "foolproof_send_beacon", () => $49880c4ce4bb7db2$export$cc3b6ddf805f6156);
@@ -208,7 +213,7 @@ $parcel$export(module.exports, "version", () => $ce0ab19b284b64fa$export$83d89fb
208
213
  $parcel$export(module.exports, "add_to_version_info", () => $045fb30107c9eecc$export$2cefb7e61fcbae00);
209
214
  $parcel$export(module.exports, "sync_el_content_with_accessor", () => $84d13ab567309a50$export$c3f56a35e076f139);
210
215
  $parcel$export(module.exports, "use_href_accessor", () => $59b7011b96010a8e$export$e35115e6d0715f77);
211
- const $ce0ab19b284b64fa$export$83d89fbfd8236492 = "2.6.21";
216
+ const $ce0ab19b284b64fa$export$83d89fbfd8236492 = "2.6.23";
212
217
  const $9e9538f4aff6f83c$export$55fe61489d2c7417 = /*@__PURE__*/((_globalThis$document, _globalThis$document$, _globalThis$document$2, _globalThis$localStor, _globalThis$localStor2) => process.env.STRIP_DEBUG === "true" ? false : process.env.DEBUG === "true" || process.env.NODE_ENV === "development" || process.env.BUILD_TARGET !== "node" && ((globalThis === null || globalThis === void 0 ? void 0 : (_globalThis$document = globalThis.document) === null || _globalThis$document === void 0 ? void 0 : (_globalThis$document$ = _globalThis$document.currentScript) === null || _globalThis$document$ === void 0 ? void 0 : (_globalThis$document$2 = _globalThis$document$.dataset) === null || _globalThis$document$2 === void 0 ? void 0 : _globalThis$document$2.debug) === "true" || (globalThis === null || globalThis === void 0 ? void 0 : (_globalThis$localStor = globalThis.localStorage) === null || _globalThis$localStor === void 0 ? void 0 : (_globalThis$localStor2 = _globalThis$localStor.getItem) === null || _globalThis$localStor2 === void 0 ? void 0 : _globalThis$localStor2.call(_globalThis$localStor, "debug")) === "true"))();
213
218
  const $7f95f77417d06249$var$browser_prefix_styling = "color: #fff;";
214
219
  let $7f95f77417d06249$var$browser_prefix = "[Depict]";
@@ -1234,31 +1239,177 @@ function $bd0a305620de4c2a$var$_periodic_send2(msg) {
1234
1239
  })().catch(e => $3b52ccc10510b32a$export$f18d5b0af29128b7(e, "error"));
1235
1240
  return () => quit = true;
1236
1241
  }
1237
- const $62869a3ed703f236$export$362abebb4b313340 = process.env.DEPICT_BASE_URL || "https://api.depict.ai";
1238
1242
 
1239
1243
  /**
1240
- * Returns a random string
1241
- * @return A random string, containing a-z, 0-9 and occasionally a dot (`.`)
1242
- */
1243
- function $a13f25507f352177$export$656831b7e9c341c3() {
1244
- return (Math.random() * 2e17).toString(36);
1244
+ * Where tracking events go: `v3` (the default) posts every event to `/create-events`; `v4` posts each event that the
1245
+ * native events contract can carry to `/v4/{merchant}/events` (NDJSON) and leaves the rest on `/create-events`.
1246
+ */ /**
1247
+ * One line of `POST /v4/{merchant}/events`, as the strict V4 contract (`Event` in realtime `v4/types`) defines it.
1248
+ * Only these keys are sent.
1249
+ */ /** The contract's limits, so an event V4 would reject stays on v3 instead of being dropped. */
1250
+ const $c9b040323c0805db$var$EVENT_ID_MAX = 128;
1251
+ const $c9b040323c0805db$var$MARKET_MAX = 128;
1252
+ const $c9b040323c0805db$var$SESSION_ID_MAX = 256;
1253
+ const $c9b040323c0805db$var$PRODUCT_ID_MAX = 500;
1254
+ const $c9b040323c0805db$var$TRACKING_ID_MAX = 1536;
1255
+ const $c9b040323c0805db$var$MERCHANT = /^[a-z0-9][a-z0-9._-]{0,63}$/;
1256
+ /** V4's card tracking id (`d1.<kind>.<request id>.<position>.<product>[.<context>]`); V4 writes no row for others. */
1257
+ const $c9b040323c0805db$var$D1_TRACKING_ID = /^d1\.[slrp]\.[0-9a-f]{32}\.(0|[1-9][0-9]{0,4})\.[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)?$/;
1258
+ const $c9b040323c0805db$var$CURRENCY = /^[A-Z]{3}$/;
1259
+ const $c9b040323c0805db$var$non_empty = (value, max) => typeof value === "string" && value.length > 0 && value.length <= max;
1260
+ function $c9b040323c0805db$export$637d3149de458a95(tenant) {
1261
+ return typeof tenant === "string" && $c9b040323c0805db$var$MERCHANT.test(tenant) ? tenant : undefined;
1262
+ }
1263
+ function $c9b040323c0805db$export$e7dbc5ffe3253bf0(value) {
1264
+ return typeof value === "string" && value.length <= $c9b040323c0805db$var$TRACKING_ID_MAX && $c9b040323c0805db$var$D1_TRACKING_ID.test(value) ? value : undefined;
1265
+ }
1266
+ function $c9b040323c0805db$export$3ad94ee026666a31(body, ts) {
1267
+ const {
1268
+ deduplication_id: deduplication_id,
1269
+ market: market,
1270
+ session_id: session_id
1271
+ } = body;
1272
+ if (!$c9b040323c0805db$var$non_empty(deduplication_id, $c9b040323c0805db$var$EVENT_ID_MAX) || !$c9b040323c0805db$var$non_empty(market, $c9b040323c0805db$var$MARKET_MAX)) return undefined;
1273
+ if (!$c9b040323c0805db$var$non_empty(session_id, $c9b040323c0805db$var$SESSION_ID_MAX)) return undefined;
1274
+ return {
1275
+ event_id: deduplication_id,
1276
+ market: market,
1277
+ session_id: session_id,
1278
+ ts: ts
1279
+ };
1245
1280
  }
1246
- function $a13f25507f352177$export$a6db784f019668ba() {
1247
- return "x" + $a13f25507f352177$export$656831b7e9c341c3().replaceAll(".", "");
1281
+ function $c9b040323c0805db$export$537c002f32ae6f61(body, ts) {
1282
+ var _ref, _body$product_listing;
1283
+ const merchant = $c9b040323c0805db$export$637d3149de458a95(body.tenant);
1284
+ const base = $c9b040323c0805db$export$3ad94ee026666a31(body, ts);
1285
+ if (!merchant || !base) return undefined;
1286
+ const optional = (key, value) => typeof value === "string" && value ? {
1287
+ [key]: value
1288
+ } : {};
1289
+ const context = {
1290
+ ...optional("url", body.url),
1291
+ ...optional("referrer", body.document_referrer)
1292
+ };
1293
+ // The first result id set, as v3's intake reads it (resultIdOf in realtime): a v3 id there keeps the event on v3.
1294
+ const result_id = (_ref = (_body$product_listing = body.product_listing_result_id) !== null && _body$product_listing !== void 0 ? _body$product_listing : body.recommendation_id) !== null && _ref !== void 0 ? _ref : body.search_result_id;
1295
+ const tracking_id = $c9b040323c0805db$export$e7dbc5ffe3253bf0(result_id);
1296
+ const has_result_id = result_id != null;
1297
+ const product_id = $c9b040323c0805db$var$non_empty(body.product_id, $c9b040323c0805db$var$PRODUCT_ID_MAX) ? body.product_id : undefined;
1298
+ if (body.product_id != null && !product_id) return undefined;
1299
+ let event;
1300
+ switch (body.type) {
1301
+ case "element_visible":
1302
+ case "click":
1303
+ if (!tracking_id) return undefined;
1304
+ event = {
1305
+ ...base,
1306
+ type: body.type === "click" ? "click" : "impression",
1307
+ tracking_id: tracking_id,
1308
+ ...context
1309
+ };
1310
+ break;
1311
+ case "add_to_cart":
1312
+ if (has_result_id ? !tracking_id : !product_id) return undefined;
1313
+ event = {
1314
+ ...base,
1315
+ type: "add_to_cart",
1316
+ ...(tracking_id ? {
1317
+ tracking_id: tracking_id
1318
+ } : {}),
1319
+ ...(product_id ? {
1320
+ product_id: product_id
1321
+ } : {}),
1322
+ ...context
1323
+ };
1324
+ break;
1325
+ case "page_view":
1326
+ if (!product_id || has_result_id && !tracking_id) return undefined;
1327
+ event = {
1328
+ ...base,
1329
+ type: "product_view",
1330
+ product_id: product_id,
1331
+ ...(tracking_id ? {
1332
+ tracking_id: tracking_id
1333
+ } : {}),
1334
+ ...context
1335
+ };
1336
+ break;
1337
+ default:
1338
+ return undefined;
1339
+ }
1340
+ return {
1341
+ merchant: merchant,
1342
+ event: event
1343
+ };
1344
+ }
1345
+ function $c9b040323c0805db$export$aad1b28cf2e0eea6(data, ts) {
1346
+ const base = $c9b040323c0805db$export$3ad94ee026666a31({
1347
+ deduplication_id: data.event_id,
1348
+ market: data.market,
1349
+ session_id: data.session_id
1350
+ }, ts);
1351
+ if (!base || !$c9b040323c0805db$var$non_empty(data.transaction_id, Infinity) || !$c9b040323c0805db$var$CURRENCY.test(data.currency)) return undefined;
1352
+ const valid_items = data.items.every(item => $c9b040323c0805db$var$non_empty(item.sku, Infinity) && typeof item.price === "number" && Number.isFinite(item.price) && Number.isInteger(item.quantity) && item.quantity > 0);
1353
+ if (!valid_items) return undefined;
1354
+ return {
1355
+ ...base,
1356
+ type: "purchase",
1357
+ purchase: {
1358
+ transaction_id: data.transaction_id,
1359
+ currency: data.currency,
1360
+ items: data.items.map(_ref2 => {
1361
+ let {
1362
+ sku: sku,
1363
+ price: price,
1364
+ quantity: quantity
1365
+ } = _ref2;
1366
+ return {
1367
+ sku: sku,
1368
+ price: price,
1369
+ quantity: quantity
1370
+ };
1371
+ })
1372
+ }
1373
+ };
1374
+ }
1375
+ const $62869a3ed703f236$export$362abebb4b313340 = process.env.DEPICT_BASE_URL || "https://api.depict.ai";
1376
+ function $974549040d011258$export$46cf5f54d4d7518() {
1377
+ try {
1378
+ var _globalThis$crypto, _globalThis$crypto2;
1379
+ if (typeof ((_globalThis$crypto = globalThis.crypto) === null || _globalThis$crypto === void 0 ? void 0 : _globalThis$crypto.randomUUID) === "function") return globalThis.crypto.randomUUID();
1380
+ const bytes = (_globalThis$crypto2 = globalThis.crypto) === null || _globalThis$crypto2 === void 0 ? void 0 : _globalThis$crypto2.getRandomValues(new Uint8Array(16));
1381
+ if (!bytes) return undefined;
1382
+ bytes[6] = bytes[6] & 0x0f | 0x40;
1383
+ bytes[8] = bytes[8] & 0x3f | 0x80;
1384
+ const hex = Array.from(bytes, byte => (byte + 0x100).toString(16).slice(1)).join("");
1385
+ return hex.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5");
1386
+ } catch {
1387
+ return undefined;
1388
+ }
1248
1389
  }
1249
1390
 
1250
1391
  /** HTTP is the default; both also sends identical events over a canary socket. */
1251
1392
  const $bccbc7bdec4799cf$var$MAX_BODY_BYTES = 49152;
1252
1393
  const $bccbc7bdec4799cf$var$IMPRESSION_DELAY_MS = 250;
1253
1394
  let $bccbc7bdec4799cf$var$transport = "http";
1395
+ let $bccbc7bdec4799cf$var$event_api = "v3";
1254
1396
  let $bccbc7bdec4799cf$var$socket;
1255
- let $bccbc7bdec4799cf$var$queued_events = [];
1256
- let $bccbc7bdec4799cf$var$queued_bytes = 2;
1257
1397
  let $bccbc7bdec4799cf$var$flush_timer;
1258
1398
  let $bccbc7bdec4799cf$var$listening = false;
1399
+ /**
1400
+ * Queued events per endpoint. v3's `/create-events` takes a JSON array; V4's `/v4/{merchant}/events` takes NDJSON.
1401
+ * Both bodies are the events joined by one separator byte, plus v3's two brackets.
1402
+ */
1403
+ const $bccbc7bdec4799cf$var$batches = new Map();
1259
1404
  function $bccbc7bdec4799cf$export$83c5d6634ba2a3c5(value) {
1260
1405
  $bccbc7bdec4799cf$var$transport = value === "both" ? "both" : "http";
1261
1406
  }
1407
+ function $bccbc7bdec4799cf$export$1a4819a80859e92e(value) {
1408
+ $bccbc7bdec4799cf$var$event_api = value === "v4" ? "v4" : "v3";
1409
+ }
1410
+ function $bccbc7bdec4799cf$export$88fbe329a1d960c8() {
1411
+ return $bccbc7bdec4799cf$var$event_api;
1412
+ }
1262
1413
  function $bccbc7bdec4799cf$var$send_beacon(url, body) {
1263
1414
  try {
1264
1415
  if (!navigator.sendBeacon(url, new Blob([body], {
@@ -1268,8 +1419,19 @@ function $bccbc7bdec4799cf$var$send_beacon(url, body) {
1268
1419
  $3b52ccc10510b32a$export$f18d5b0af29128b7(error, "warning");
1269
1420
  }
1270
1421
  }
1422
+ /** V4 answers 200 even when it rejects lines; a rejected line is an event the contract no longer takes. */
1423
+ function $bccbc7bdec4799cf$var$check_native_response(response, url) {
1424
+ if (response.status !== 200 || typeof response.json !== "function") return;
1425
+ response.json().then(body => {
1426
+ if (body !== null && body !== void 0 && body.rejected) $3b52ccc10510b32a$export$f18d5b0af29128b7(new Error("V4 rejected tracking events"), "warning", {
1427
+ url: url,
1428
+ ...body
1429
+ });
1430
+ }).catch(() => {});
1431
+ }
1271
1432
  function $bccbc7bdec4799cf$var$send_batch(url, body) {
1272
1433
  let retried = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1434
+ let native = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
1273
1435
  let request;
1274
1436
  try {
1275
1437
  request = fetch(url, {
@@ -1286,20 +1448,61 @@ function $bccbc7bdec4799cf$var$send_batch(url, body) {
1286
1448
  return;
1287
1449
  }
1288
1450
  request.then(response => {
1289
- if (response.status >= 500 && !retried && document.visibilityState === "visible") $bccbc7bdec4799cf$var$send_batch(url, body, true);
1451
+ if (response.status >= 500 && !retried && document.visibilityState === "visible") $bccbc7bdec4799cf$var$send_batch(url, body, true, native);else if (native) $bccbc7bdec4799cf$var$check_native_response(response, url);
1290
1452
  }, () => {
1291
- if (!retried && document.visibilityState === "visible") $bccbc7bdec4799cf$var$send_batch(url, body, true);else $bccbc7bdec4799cf$var$send_beacon(url, body);
1453
+ if (!retried && document.visibilityState === "visible") $bccbc7bdec4799cf$var$send_batch(url, body, true, native);else $bccbc7bdec4799cf$var$send_beacon(url, body);
1292
1454
  }).catch(error => $3b52ccc10510b32a$export$f18d5b0af29128b7(error, "warning"));
1293
1455
  }
1456
+ function $bccbc7bdec4799cf$var$flush_batch(url) {
1457
+ const batch = $bccbc7bdec4799cf$var$batches.get(url);
1458
+ if (!batch) return;
1459
+ $bccbc7bdec4799cf$var$batches.delete(url);
1460
+ $bccbc7bdec4799cf$var$send_batch(url, batch.ndjson ? batch.events.join("\n") : "[".concat(batch.events.join(","), "]"), false, batch.ndjson);
1461
+ }
1294
1462
  const $bccbc7bdec4799cf$var$flush = /*@__PURE__*/$3b52ccc10510b32a$export$b3bbfd758f11cfa9(() => {
1295
1463
  clearTimeout($bccbc7bdec4799cf$var$flush_timer);
1296
1464
  $bccbc7bdec4799cf$var$flush_timer = undefined;
1297
- if (!$bccbc7bdec4799cf$var$queued_events.length) return;
1298
- const body = "[".concat($bccbc7bdec4799cf$var$queued_events.join(","), "]");
1299
- $bccbc7bdec4799cf$var$queued_events = [];
1300
- $bccbc7bdec4799cf$var$queued_bytes = 2;
1301
- $bccbc7bdec4799cf$var$send_batch(String($045fb30107c9eecc$export$fe609f0216e4ebef((0, $62869a3ed703f236$export$362abebb4b313340) + "/create-events")), body);
1465
+ for (const url of [...$bccbc7bdec4799cf$var$batches.keys()]) $bccbc7bdec4799cf$var$flush_batch(url);
1302
1466
  });
1467
+ const $bccbc7bdec4799cf$var$v3_url = () => String($045fb30107c9eecc$export$fe609f0216e4ebef((0, $62869a3ed703f236$export$362abebb4b313340) + "/create-events"));
1468
+ /** No version params: like the native reads, V4 gets only what its contract defines. */
1469
+ const $bccbc7bdec4799cf$var$v4_url = merchant => "".concat((0, $62869a3ed703f236$export$362abebb4b313340), "/v4/").concat(encodeURIComponent(merchant), "/events");
1470
+ function $bccbc7bdec4799cf$var$listen() {
1471
+ if ($bccbc7bdec4799cf$var$listening) return;
1472
+ document.addEventListener("visibilitychange", () => {
1473
+ if (document.visibilityState === "hidden") $bccbc7bdec4799cf$var$flush();
1474
+ });
1475
+ window.addEventListener("pagehide", $bccbc7bdec4799cf$var$flush);
1476
+ $bccbc7bdec4799cf$var$listening = true;
1477
+ }
1478
+ /** Adds one serialized event to its endpoint's batch, sending the batch first if the event wouldn't fit. */
1479
+ function $bccbc7bdec4799cf$var$enqueue(url, json, ndjson, type) {
1480
+ const bytes = new Blob([json]).size;
1481
+ const empty_bytes = ndjson ? 0 : 2;
1482
+ if (bytes + empty_bytes > $bccbc7bdec4799cf$var$MAX_BODY_BYTES) {
1483
+ $3b52ccc10510b32a$export$f18d5b0af29128b7(new Error("Event exceeds the keepalive body limit"), "warning", {
1484
+ bytes: bytes,
1485
+ type: type
1486
+ });
1487
+ return false;
1488
+ }
1489
+ let batch = $bccbc7bdec4799cf$var$batches.get(url);
1490
+ if (batch && batch.bytes + bytes + 1 > $bccbc7bdec4799cf$var$MAX_BODY_BYTES) {
1491
+ $bccbc7bdec4799cf$var$flush_batch(url);
1492
+ batch = undefined;
1493
+ }
1494
+ if (!batch) $bccbc7bdec4799cf$var$batches.set(url, batch = {
1495
+ events: [],
1496
+ bytes: empty_bytes,
1497
+ ndjson: ndjson
1498
+ });
1499
+ batch.bytes += bytes + (batch.events.length ? 1 : 0);
1500
+ batch.events.push(json);
1501
+ return true;
1502
+ }
1503
+ function $bccbc7bdec4799cf$var$schedule(immediate) {
1504
+ if (immediate) $bccbc7bdec4799cf$var$flush();else if ($bccbc7bdec4799cf$var$batches.size && $bccbc7bdec4799cf$var$flush_timer === undefined) $bccbc7bdec4799cf$var$flush_timer = setTimeout($bccbc7bdec4799cf$var$flush, $bccbc7bdec4799cf$var$IMPRESSION_DELAY_MS);
1505
+ }
1303
1506
  const $bccbc7bdec4799cf$var$send_canary = /*@__PURE__*/$3b52ccc10510b32a$export$b3bbfd758f11cfa9(json => {
1304
1507
  if (typeof WebSocket !== "function") return;
1305
1508
  $bccbc7bdec4799cf$var$socket || ($bccbc7bdec4799cf$var$socket = new (0, $bd0a305620de4c2a$export$1d9c6fddbff3441f)("wss://ws.depict.ai/ws/create-events"));
@@ -1311,36 +1514,37 @@ const $bccbc7bdec4799cf$var$send_canary = /*@__PURE__*/$3b52ccc10510b32a$export$
1311
1514
  }, undefined, "warning");
1312
1515
  function $bccbc7bdec4799cf$export$fb18f6dbe1c6f251(payload) {
1313
1516
  if (process.env.DEPICT === "false" || typeof document === "undefined") return;
1314
- if (!$bccbc7bdec4799cf$var$listening) {
1315
- document.addEventListener("visibilitychange", () => {
1316
- if (document.visibilityState === "hidden") $bccbc7bdec4799cf$var$flush();
1317
- });
1318
- window.addEventListener("pagehide", $bccbc7bdec4799cf$var$flush);
1319
- $bccbc7bdec4799cf$var$listening = true;
1320
- }
1517
+ $bccbc7bdec4799cf$var$listen();
1321
1518
  let accepted = true;
1322
1519
  let immediate = document.visibilityState === "hidden";
1323
- for (const event of payload) {
1324
- const json = JSON.stringify({
1325
- ...event,
1326
- deduplication_id: event.deduplication_id || $a13f25507f352177$export$656831b7e9c341c3()
1327
- });
1328
- const bytes = new Blob([json]).size;
1329
- if (bytes + 2 > $bccbc7bdec4799cf$var$MAX_BODY_BYTES) {
1330
- $3b52ccc10510b32a$export$f18d5b0af29128b7(new Error("Event exceeds the keepalive body limit"), "warning", {
1331
- bytes: bytes,
1332
- type: event.type
1333
- });
1520
+ const ts = new Date().toISOString();
1521
+ for (const raw of payload) {
1522
+ const event = {
1523
+ ...raw,
1524
+ deduplication_id: raw.deduplication_id || $974549040d011258$export$46cf5f54d4d7518()
1525
+ };
1526
+ const native = $bccbc7bdec4799cf$var$event_api === "v4" ? $c9b040323c0805db$export$537c002f32ae6f61(event, ts) : undefined;
1527
+ const json = JSON.stringify(native ? native.event : event);
1528
+ const queued = native ? $bccbc7bdec4799cf$var$enqueue($bccbc7bdec4799cf$var$v4_url(native.merchant), json, true, event.type) : $bccbc7bdec4799cf$var$enqueue($bccbc7bdec4799cf$var$v3_url(), json, false, event.type);
1529
+ if (!queued) {
1334
1530
  accepted = false;
1335
1531
  continue;
1336
1532
  }
1337
- if ($bccbc7bdec4799cf$var$queued_bytes + bytes + ($bccbc7bdec4799cf$var$queued_events.length ? 1 : 0) > $bccbc7bdec4799cf$var$MAX_BODY_BYTES) $bccbc7bdec4799cf$var$flush();
1338
- $bccbc7bdec4799cf$var$queued_bytes += bytes + ($bccbc7bdec4799cf$var$queued_events.length ? 1 : 0);
1339
- $bccbc7bdec4799cf$var$queued_events.push(json);
1340
1533
  immediate || (immediate = event.type !== "element_visible");
1341
- if ($bccbc7bdec4799cf$var$transport === "both") $bccbc7bdec4799cf$var$send_canary(json);
1534
+ // The canary socket is v3's; an event sent to V4 isn't mirrored there.
1535
+ if ($bccbc7bdec4799cf$var$transport === "both" && !native) $bccbc7bdec4799cf$var$send_canary(json);
1342
1536
  }
1343
- if (immediate) $bccbc7bdec4799cf$var$flush();else if ($bccbc7bdec4799cf$var$queued_events.length && $bccbc7bdec4799cf$var$flush_timer === undefined) $bccbc7bdec4799cf$var$flush_timer = setTimeout($bccbc7bdec4799cf$var$flush, $bccbc7bdec4799cf$var$IMPRESSION_DELAY_MS);
1537
+ $bccbc7bdec4799cf$var$schedule(immediate);
1538
+ return accepted;
1539
+ }
1540
+ function $bccbc7bdec4799cf$export$f72bace509bf62ef(merchant, events) {
1541
+ if (process.env.DEPICT === "false" || typeof document === "undefined") return;
1542
+ const path_merchant = $c9b040323c0805db$export$637d3149de458a95(merchant);
1543
+ if (!path_merchant) return false;
1544
+ $bccbc7bdec4799cf$var$listen();
1545
+ let accepted = true;
1546
+ for (const event of events) accepted = $bccbc7bdec4799cf$var$enqueue($bccbc7bdec4799cf$var$v4_url(path_merchant), JSON.stringify(event), true, event.type) && accepted;
1547
+ $bccbc7bdec4799cf$var$schedule(true);
1344
1548
  return accepted;
1345
1549
  }
1346
1550
  const $49880c4ce4bb7db2$var$c = (0, $3b52ccc10510b32a$export$b3bbfd758f11cfa9);
@@ -1406,6 +1610,17 @@ const $49880c4ce4bb7db2$export$28cacbd9b4306ffc = /*@__PURE__*/$49880c4ce4bb7db2
1406
1610
  // filter_depict_payload will only return undefined if process.env.DEPICT === "false"
1407
1611
  return $49880c4ce4bb7db2$export$608478473a3304a0($49880c4ce4bb7db2$export$72036d950e1fae95(payload), use_ws);
1408
1612
  });
1613
+
1614
+ /**
1615
+ * Returns a random string
1616
+ * @return A random string, containing a-z, 0-9 and occasionally a dot (`.`)
1617
+ */
1618
+ function $a13f25507f352177$export$656831b7e9c341c3() {
1619
+ return (Math.random() * 2e17).toString(36);
1620
+ }
1621
+ function $a13f25507f352177$export$a6db784f019668ba() {
1622
+ return "x" + $a13f25507f352177$export$656831b7e9c341c3().replaceAll(".", "");
1623
+ }
1409
1624
  let $335c248bb07a3509$export$61e7e1f11e96692f = () => {
1410
1625
  if (typeof document === "undefined") return "server";
1411
1626
  let id = "";
@@ -1,5 +1,5 @@
1
1
  import { JSX, Accessor } from "solid-js";
2
- export const version = "2.6.21";
2
+ export const version = "2.6.23";
3
3
  export const is_debug: boolean;
4
4
  /**
5
5
  * Sets the prefix of dlog, dwarn, and derror messages in the browser console. Defaults to `[Depict]`.
@@ -217,19 +217,90 @@ export class DepictAPIWS extends AutoReconnectingWS {
217
217
  initial_retry_ms: number;
218
218
  }>]);
219
219
  }
220
- export const base_url: string;
221
220
  /**
222
- * Returns a random string
223
- * @return A random string, containing a-z, 0-9 and occasionally a dot (`.`)
221
+ * Where tracking events go: `v3` (the default) posts every event to `/create-events`; `v4` posts each event that the
222
+ * native events contract can carry to `/v4/{merchant}/events` (NDJSON) and leaves the rest on `/create-events`.
224
223
  */
225
- export function random_string(): string;
226
- export function make_random_classname(): string;
224
+ export type EventApi = "v3" | "v4";
225
+ /**
226
+ * One line of `POST /v4/{merchant}/events`, as the strict V4 contract (`Event` in realtime `v4/types`) defines it.
227
+ * Only these keys are sent.
228
+ */
229
+ export type NativeEvent = {
230
+ event_id: string;
231
+ type: "impression" | "click" | "add_to_cart" | "product_view" | "purchase";
232
+ market: string;
233
+ session_id: string;
234
+ ts: string;
235
+ product_id?: string;
236
+ tracking_id?: string;
237
+ url?: string;
238
+ referrer?: string;
239
+ purchase?: {
240
+ transaction_id: string;
241
+ currency: string;
242
+ items: {
243
+ sku: string;
244
+ price: number;
245
+ quantity: number;
246
+ }[];
247
+ };
248
+ };
249
+ /**
250
+ * Maps a v3 `/create-events` body to a native V4 event, with the merchant it's posted under. Undefined means V4
251
+ * can't take it as v3 did, so it stays on `/create-events`:
252
+ *
253
+ * - `element_visible` → `impression` and `click` → `click`, only with a d1 `recommendation_id`, `search_result_id` or
254
+ * `product_listing_result_id` (the card's V4 `tracking_id`). V4 decodes the kind from the id, so the result
255
+ * field it came in doesn't matter. A v3 result id (from a v3 recommendation, say) stays on v3: V4 writes no row
256
+ * for an id it can't decode.
257
+ * - `add_to_cart` → `add_to_cart`, with the d1 result id or a `product_id` (a PDP button).
258
+ * - `page_view` → `product_view`, only on a PDP (`product_id` set). V4 has no plain page view.
259
+ * - Anything else (`recommendations_inserted`, `purchase` on `/create-events`, errors) has no V4 type.
260
+ *
261
+ * Fields V4 has no place for are not sent: `tenant` (it's the path), `entity_price`, `currency` (outside purchase),
262
+ * `document_width`, `attribution_id`, `click_location`, `ab_test_group`, `variant_ids`, `entity_identifiers`,
263
+ * `recommendation_type`, `error_type`, `detail`.
264
+ */
265
+ export function to_native_event(body: depict_body, ts: string): {
266
+ merchant: string;
267
+ event: NativeEvent;
268
+ } | undefined;
269
+ /**
270
+ * A native purchase event, or undefined when it would break the contract (then the caller keeps v3's
271
+ * `/v2/create-events`).
272
+ */
273
+ export function native_purchase_event(data: {
274
+ event_id: string;
275
+ market?: string;
276
+ session_id?: string;
277
+ transaction_id: string;
278
+ currency: string;
279
+ items: {
280
+ sku: string;
281
+ price: number;
282
+ quantity: number;
283
+ }[];
284
+ }, ts: string): NativeEvent | undefined;
285
+ export const base_url: string;
227
286
  /** HTTP is the default; both also sends identical events over a canary socket. */
228
287
  export type EventTransport = "http" | "both";
229
288
  /** Configure before tracking starts; shared by users of this utilishared module.
230
289
  * Switching to http stops new socket sends but leaves an existing canary socket open.
231
290
  */
232
291
  export function set_event_transport(value: EventTransport): void;
292
+ /**
293
+ * Configure before tracking starts; shared by users of this utilishared module. `v4` sends each event the native
294
+ * events contract can carry to `/v4/{merchant}/events` instead of `/create-events` (see `to_native_event`); `v3`
295
+ * (the default) sends everything to `/create-events`.
296
+ */
297
+ export function set_event_api(value: EventApi): void;
298
+ export function get_event_api(): EventApi;
299
+ /**
300
+ * Sends native V4 events for `merchant` right away (with whatever else is queued), with the same retries and
301
+ * beacon fallback as v3 events. Returns false if the merchant isn't one V4 accepts or an event is too large.
302
+ */
303
+ export function queue_native_events(merchant: string, events: NativeEvent[]): boolean | undefined;
233
304
  export type event_types = "page_view" | "click" | "add_to_cart" | "purchase" | "element_visible";
234
305
  declare const allowed_keys: readonly ["deduplication_id", "tenant", "market", "type", "session_id", "product_id", "entity_identifiers", "url", "entity_price", "currency", "document_referrer", "document_width", "attribution_id", "recommendation_id", "click_location", "ab_test_group", "variant_ids", "transaction_id", "error_type", "detail", "recommendation_type", "search_result_id", "product_listing_result_id"];
235
306
  export type depict_body = Partial<{ [K in (typeof allowed_keys)[number]]: any }>;
@@ -246,6 +317,12 @@ export const foolproof_send_beacon: (url: string, payload: {
246
317
  [key: string]: any;
247
318
  }) => boolean | undefined;
248
319
  export const send_depict: (payload: noisy_depict_payload, use_ws?: boolean | undefined) => boolean | Promise<void | undefined> | undefined;
320
+ /**
321
+ * Returns a random string
322
+ * @return A random string, containing a-z, 0-9 and occasionally a dot (`.`)
323
+ */
324
+ export function random_string(): string;
325
+ export function make_random_classname(): string;
249
326
  export let get_session_id: () => string;
250
327
  export const set_session_id_fn: (newfn: () => string) => (() => string) | undefined;
251
328
  export type TrackingEventContextData = {
@@ -259,10 +336,10 @@ export const get_tracking_event_context_data: () => TrackingEventContextData;
259
336
  * Sends a depict tracking event with prefilled data
260
337
  */
261
338
  export const depict_prefilled: (vars: Partial<{
339
+ currency: any;
262
340
  type: any;
263
341
  detail: any;
264
342
  url: any;
265
- currency: any;
266
343
  deduplication_id: any;
267
344
  tenant: any;
268
345
  market: any;
@@ -286,10 +363,10 @@ export const depict_prefilled: (vars: Partial<{
286
363
  [key: string]: any;
287
364
  }, use_ws?: boolean | undefined) => boolean | Promise<void | undefined> | undefined;
288
365
  export const depict_click: (vars: Partial<{
366
+ currency: any;
289
367
  type: any;
290
368
  detail: any;
291
369
  url: any;
292
- currency: any;
293
370
  deduplication_id: any;
294
371
  tenant: any;
295
372
  market: any;
@@ -313,10 +390,10 @@ export const depict_click: (vars: Partial<{
313
390
  [key: string]: any;
314
391
  }) => boolean | Promise<void | undefined> | undefined;
315
392
  export const depict_add_to_cart: (vars: Partial<{
393
+ currency: any;
316
394
  type: any;
317
395
  detail: any;
318
396
  url: any;
319
- currency: any;
320
397
  deduplication_id: any;
321
398
  tenant: any;
322
399
  market: any;
@@ -434,7 +511,7 @@ export const check_displays: (args_0: {
434
511
  } | Promise<Display[] | {
435
512
  displays: Display[];
436
513
  }>;
437
- min_recs?: number | undefined;
514
+ min_recs?: number;
438
515
  market: string;
439
516
  type: string;
440
517
  product_id: string | string[] | Promise<string> | Promise<string[]> | ((arg0?: string) => string | string[] | Promise<string> | Promise<string[]>) | undefined;
@@ -1237,10 +1314,11 @@ export function navigate_with_next_router(e: MouseEvent, url: string): false | u
1237
1314
  */
1238
1315
  export function fetch_replacer(fetch_proxy_handler: (target: typeof window.fetch, this_arg: typeof window, arguments_list: Parameters<typeof window.fetch>) => Promise<Response | FakeResponse>, unsafe_throw_up?: boolean): Promise<void>;
1239
1316
  declare const FakeResponse_base: {
1240
- new (body?: BodyInit | null | undefined, init?: ResponseInit | undefined): Response;
1317
+ new (body?: BodyInit | null, init?: ResponseInit): Response;
1241
1318
  prototype: Response;
1242
1319
  error(): Response;
1243
- redirect(url: string | URL, status?: number | undefined): Response;
1320
+ json(data: any, init?: ResponseInit): Response;
1321
+ redirect(url: string | URL, status?: number): Response;
1244
1322
  };
1245
1323
  /**
1246
1324
  * This class extends and models the `Response` class as close as possible. Basically the only thing not being identical would be `instance_of_fake_response.constructor` and some other stuff, but nothing connected to how you're usually using a `Response` object.
@@ -1405,7 +1483,7 @@ export function iterable_to_elems(async_iterable: AsyncIterable<ReactiveTemplate
1405
1483
  * @param ...args Any arguments that will also be passed on to the wrapped function. If the wrapped function takes an ElementObserverEvent the disconnector on it will also be called if a context should be "stopped";
1406
1484
  * @return A wrapped function that now executes in a context
1407
1485
  */
1408
- export const prevent_infinite_loop: <A extends any[], B>(cb: (...args: A) => void | B) => (...args: A) => void | B;
1486
+ export const prevent_infinite_loop: <A extends any[], B>(cb: (...args: A) => B | void) => (...args: A) => void | B;
1409
1487
  /**
1410
1488
  * Inserts one or multiple surfaces into the DOM.
1411
1489
  * Will also revert (if verb is `replaceWith`) or remove the inserted elements again if placeholder rendering fails. This happens by a promise inside of the `Surface`s
@@ -1450,7 +1528,7 @@ export function replace_promise_with_native_if_exists_and_enforce(): void;
1450
1528
  * Creates a blank iframe inside <head> and returns window.Promise out of it
1451
1529
  * @return a pristine, unpolyfilled window.Promise
1452
1530
  */
1453
- export function get_iframe_promise(): PromiseConstructor;
1531
+ export function get_iframe_promise(): typeof window.Promise;
1454
1532
  /**
1455
1533
  * Proxies XMLHttpRequest.prototype.open to an open function which also calls the provided `fetch_handler` with useful information as parameter
1456
1534
  * @param fetch_handler A function which is catchified and which's return value is ignored. It gets called every time an XHR request gets opened
@@ -1640,7 +1718,7 @@ export const useExpandingContainer: ({
1640
1718
  ExpandingContainer: ({
1641
1719
  children
1642
1720
  }: {
1643
- children?: Elem | Elem[] | undefined;
1721
+ children?: Elem | Elem[];
1644
1722
  }) => HTMLElement;
1645
1723
  expand: (expanding_delay?: any, time_to_expand?: any) => Promise<Animation | undefined>;
1646
1724
  collapse: (collapsing_delay?: any, time_to_collapse?: any) => Promise<Animation | undefined>;