@depict-ai/utilishared 2.6.21 → 2.6.22

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.22";
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,6 +1239,139 @@ function $bd0a305620de4c2a$var$_periodic_send2(msg) {
1234
1239
  })().catch(e => $3b52ccc10510b32a$export$f18d5b0af29128b7(e, "error"));
1235
1240
  return () => quit = true;
1236
1241
  }
1242
+
1243
+ /**
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
+ };
1280
+ }
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
+ }
1237
1375
  const $62869a3ed703f236$export$362abebb4b313340 = process.env.DEPICT_BASE_URL || "https://api.depict.ai";
1238
1376
 
1239
1377
  /**
@@ -1251,14 +1389,24 @@ function $a13f25507f352177$export$a6db784f019668ba() {
1251
1389
  const $bccbc7bdec4799cf$var$MAX_BODY_BYTES = 49152;
1252
1390
  const $bccbc7bdec4799cf$var$IMPRESSION_DELAY_MS = 250;
1253
1391
  let $bccbc7bdec4799cf$var$transport = "http";
1392
+ let $bccbc7bdec4799cf$var$event_api = "v3";
1254
1393
  let $bccbc7bdec4799cf$var$socket;
1255
- let $bccbc7bdec4799cf$var$queued_events = [];
1256
- let $bccbc7bdec4799cf$var$queued_bytes = 2;
1257
1394
  let $bccbc7bdec4799cf$var$flush_timer;
1258
1395
  let $bccbc7bdec4799cf$var$listening = false;
1396
+ /**
1397
+ * Queued events per endpoint. v3's `/create-events` takes a JSON array; V4's `/v4/{merchant}/events` takes NDJSON.
1398
+ * Both bodies are the events joined by one separator byte, plus v3's two brackets.
1399
+ */
1400
+ const $bccbc7bdec4799cf$var$batches = new Map();
1259
1401
  function $bccbc7bdec4799cf$export$83c5d6634ba2a3c5(value) {
1260
1402
  $bccbc7bdec4799cf$var$transport = value === "both" ? "both" : "http";
1261
1403
  }
1404
+ function $bccbc7bdec4799cf$export$1a4819a80859e92e(value) {
1405
+ $bccbc7bdec4799cf$var$event_api = value === "v4" ? "v4" : "v3";
1406
+ }
1407
+ function $bccbc7bdec4799cf$export$88fbe329a1d960c8() {
1408
+ return $bccbc7bdec4799cf$var$event_api;
1409
+ }
1262
1410
  function $bccbc7bdec4799cf$var$send_beacon(url, body) {
1263
1411
  try {
1264
1412
  if (!navigator.sendBeacon(url, new Blob([body], {
@@ -1268,8 +1416,19 @@ function $bccbc7bdec4799cf$var$send_beacon(url, body) {
1268
1416
  $3b52ccc10510b32a$export$f18d5b0af29128b7(error, "warning");
1269
1417
  }
1270
1418
  }
1419
+ /** V4 answers 200 even when it rejects lines; a rejected line is an event the contract no longer takes. */
1420
+ function $bccbc7bdec4799cf$var$check_native_response(response, url) {
1421
+ if (response.status !== 200 || typeof response.json !== "function") return;
1422
+ response.json().then(body => {
1423
+ if (body !== null && body !== void 0 && body.rejected) $3b52ccc10510b32a$export$f18d5b0af29128b7(new Error("V4 rejected tracking events"), "warning", {
1424
+ url: url,
1425
+ ...body
1426
+ });
1427
+ }).catch(() => {});
1428
+ }
1271
1429
  function $bccbc7bdec4799cf$var$send_batch(url, body) {
1272
1430
  let retried = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1431
+ let native = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
1273
1432
  let request;
1274
1433
  try {
1275
1434
  request = fetch(url, {
@@ -1286,20 +1445,61 @@ function $bccbc7bdec4799cf$var$send_batch(url, body) {
1286
1445
  return;
1287
1446
  }
1288
1447
  request.then(response => {
1289
- if (response.status >= 500 && !retried && document.visibilityState === "visible") $bccbc7bdec4799cf$var$send_batch(url, body, true);
1448
+ 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
1449
  }, () => {
1291
- if (!retried && document.visibilityState === "visible") $bccbc7bdec4799cf$var$send_batch(url, body, true);else $bccbc7bdec4799cf$var$send_beacon(url, body);
1450
+ if (!retried && document.visibilityState === "visible") $bccbc7bdec4799cf$var$send_batch(url, body, true, native);else $bccbc7bdec4799cf$var$send_beacon(url, body);
1292
1451
  }).catch(error => $3b52ccc10510b32a$export$f18d5b0af29128b7(error, "warning"));
1293
1452
  }
1453
+ function $bccbc7bdec4799cf$var$flush_batch(url) {
1454
+ const batch = $bccbc7bdec4799cf$var$batches.get(url);
1455
+ if (!batch) return;
1456
+ $bccbc7bdec4799cf$var$batches.delete(url);
1457
+ $bccbc7bdec4799cf$var$send_batch(url, batch.ndjson ? batch.events.join("\n") : "[".concat(batch.events.join(","), "]"), false, batch.ndjson);
1458
+ }
1294
1459
  const $bccbc7bdec4799cf$var$flush = /*@__PURE__*/$3b52ccc10510b32a$export$b3bbfd758f11cfa9(() => {
1295
1460
  clearTimeout($bccbc7bdec4799cf$var$flush_timer);
1296
1461
  $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);
1462
+ for (const url of [...$bccbc7bdec4799cf$var$batches.keys()]) $bccbc7bdec4799cf$var$flush_batch(url);
1302
1463
  });
1464
+ const $bccbc7bdec4799cf$var$v3_url = () => String($045fb30107c9eecc$export$fe609f0216e4ebef((0, $62869a3ed703f236$export$362abebb4b313340) + "/create-events"));
1465
+ /** No version params: like the native reads, V4 gets only what its contract defines. */
1466
+ const $bccbc7bdec4799cf$var$v4_url = merchant => "".concat((0, $62869a3ed703f236$export$362abebb4b313340), "/v4/").concat(encodeURIComponent(merchant), "/events");
1467
+ function $bccbc7bdec4799cf$var$listen() {
1468
+ if ($bccbc7bdec4799cf$var$listening) return;
1469
+ document.addEventListener("visibilitychange", () => {
1470
+ if (document.visibilityState === "hidden") $bccbc7bdec4799cf$var$flush();
1471
+ });
1472
+ window.addEventListener("pagehide", $bccbc7bdec4799cf$var$flush);
1473
+ $bccbc7bdec4799cf$var$listening = true;
1474
+ }
1475
+ /** Adds one serialized event to its endpoint's batch, sending the batch first if the event wouldn't fit. */
1476
+ function $bccbc7bdec4799cf$var$enqueue(url, json, ndjson, type) {
1477
+ const bytes = new Blob([json]).size;
1478
+ const empty_bytes = ndjson ? 0 : 2;
1479
+ if (bytes + empty_bytes > $bccbc7bdec4799cf$var$MAX_BODY_BYTES) {
1480
+ $3b52ccc10510b32a$export$f18d5b0af29128b7(new Error("Event exceeds the keepalive body limit"), "warning", {
1481
+ bytes: bytes,
1482
+ type: type
1483
+ });
1484
+ return false;
1485
+ }
1486
+ let batch = $bccbc7bdec4799cf$var$batches.get(url);
1487
+ if (batch && batch.bytes + bytes + 1 > $bccbc7bdec4799cf$var$MAX_BODY_BYTES) {
1488
+ $bccbc7bdec4799cf$var$flush_batch(url);
1489
+ batch = undefined;
1490
+ }
1491
+ if (!batch) $bccbc7bdec4799cf$var$batches.set(url, batch = {
1492
+ events: [],
1493
+ bytes: empty_bytes,
1494
+ ndjson: ndjson
1495
+ });
1496
+ batch.bytes += bytes + (batch.events.length ? 1 : 0);
1497
+ batch.events.push(json);
1498
+ return true;
1499
+ }
1500
+ function $bccbc7bdec4799cf$var$schedule(immediate) {
1501
+ 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);
1502
+ }
1303
1503
  const $bccbc7bdec4799cf$var$send_canary = /*@__PURE__*/$3b52ccc10510b32a$export$b3bbfd758f11cfa9(json => {
1304
1504
  if (typeof WebSocket !== "function") return;
1305
1505
  $bccbc7bdec4799cf$var$socket || ($bccbc7bdec4799cf$var$socket = new (0, $bd0a305620de4c2a$export$1d9c6fddbff3441f)("wss://ws.depict.ai/ws/create-events"));
@@ -1311,36 +1511,37 @@ const $bccbc7bdec4799cf$var$send_canary = /*@__PURE__*/$3b52ccc10510b32a$export$
1311
1511
  }, undefined, "warning");
1312
1512
  function $bccbc7bdec4799cf$export$fb18f6dbe1c6f251(payload) {
1313
1513
  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
- }
1514
+ $bccbc7bdec4799cf$var$listen();
1321
1515
  let accepted = true;
1322
1516
  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
- });
1517
+ const ts = new Date().toISOString();
1518
+ for (const raw of payload) {
1519
+ const event = {
1520
+ ...raw,
1521
+ deduplication_id: raw.deduplication_id || $a13f25507f352177$export$656831b7e9c341c3()
1522
+ };
1523
+ const native = $bccbc7bdec4799cf$var$event_api === "v4" ? $c9b040323c0805db$export$537c002f32ae6f61(event, ts) : undefined;
1524
+ const json = JSON.stringify(native ? native.event : event);
1525
+ 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);
1526
+ if (!queued) {
1334
1527
  accepted = false;
1335
1528
  continue;
1336
1529
  }
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
1530
  immediate || (immediate = event.type !== "element_visible");
1341
- if ($bccbc7bdec4799cf$var$transport === "both") $bccbc7bdec4799cf$var$send_canary(json);
1531
+ // The canary socket is v3's; an event sent to V4 isn't mirrored there.
1532
+ if ($bccbc7bdec4799cf$var$transport === "both" && !native) $bccbc7bdec4799cf$var$send_canary(json);
1342
1533
  }
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);
1534
+ $bccbc7bdec4799cf$var$schedule(immediate);
1535
+ return accepted;
1536
+ }
1537
+ function $bccbc7bdec4799cf$export$f72bace509bf62ef(merchant, events) {
1538
+ if (process.env.DEPICT === "false" || typeof document === "undefined") return;
1539
+ const path_merchant = $c9b040323c0805db$export$637d3149de458a95(merchant);
1540
+ if (!path_merchant) return false;
1541
+ $bccbc7bdec4799cf$var$listen();
1542
+ let accepted = true;
1543
+ for (const event of events) accepted = $bccbc7bdec4799cf$var$enqueue($bccbc7bdec4799cf$var$v4_url(path_merchant), JSON.stringify(event), true, event.type) && accepted;
1544
+ $bccbc7bdec4799cf$var$schedule(true);
1344
1545
  return accepted;
1345
1546
  }
1346
1547
  const $49880c4ce4bb7db2$var$c = (0, $3b52ccc10510b32a$export$b3bbfd758f11cfa9);
@@ -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.22";
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,6 +217,71 @@ export class DepictAPIWS extends AutoReconnectingWS {
217
217
  initial_retry_ms: number;
218
218
  }>]);
219
219
  }
220
+ /**
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`.
223
+ */
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;
220
285
  export const base_url: string;
221
286
  /**
222
287
  * Returns a random string
@@ -230,6 +295,18 @@ export type EventTransport = "http" | "both";
230
295
  * Switching to http stops new socket sends but leaves an existing canary socket open.
231
296
  */
232
297
  export function set_event_transport(value: EventTransport): void;
298
+ /**
299
+ * Configure before tracking starts; shared by users of this utilishared module. `v4` sends each event the native
300
+ * events contract can carry to `/v4/{merchant}/events` instead of `/create-events` (see `to_native_event`); `v3`
301
+ * (the default) sends everything to `/create-events`.
302
+ */
303
+ export function set_event_api(value: EventApi): void;
304
+ export function get_event_api(): EventApi;
305
+ /**
306
+ * Sends native V4 events for `merchant` right away (with whatever else is queued), with the same retries and
307
+ * beacon fallback as v3 events. Returns false if the merchant isn't one V4 accepts or an event is too large.
308
+ */
309
+ export function queue_native_events(merchant: string, events: NativeEvent[]): boolean | undefined;
233
310
  export type event_types = "page_view" | "click" | "add_to_cart" | "purchase" | "element_visible";
234
311
  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
312
  export type depict_body = Partial<{ [K in (typeof allowed_keys)[number]]: any }>;