@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.
- package/ES10/index.cjs +256 -41
- package/ES10/index.d.ts +93 -15
- package/ES10/index.js +252 -42
- package/latest/index.cjs +251 -42
- package/latest/index.d.ts +93 -15
- package/latest/index.js +247 -43
- package/package.json +2 -2
- package/server/ES10/index.cjs +256 -41
- package/server/ES10/index.d.ts +93 -15
- package/server/ES10/index.js +252 -42
- package/server/latest/index.cjs +251 -42
- package/server/latest/index.d.ts +93 -15
- package/server/latest/index.js +247 -43
package/latest/index.cjs
CHANGED
|
@@ -82,6 +82,11 @@ $parcel$export(module.exports, "get_session_id", () => $e0a87646d12cb987$export$
|
|
|
82
82
|
$parcel$export(module.exports, "get_cookie", () => $e0a87646d12cb987$export$622991c71a1f52b3);
|
|
83
83
|
$parcel$export(module.exports, "get_tracking_event_context_data", () => $e0a87646d12cb987$export$8c6f26a5b6921b95);
|
|
84
84
|
$parcel$export(module.exports, "set_event_transport", () => $92e75e76b1a9e331$export$83c5d6634ba2a3c5);
|
|
85
|
+
$parcel$export(module.exports, "set_event_api", () => $92e75e76b1a9e331$export$1a4819a80859e92e);
|
|
86
|
+
$parcel$export(module.exports, "get_event_api", () => $92e75e76b1a9e331$export$88fbe329a1d960c8);
|
|
87
|
+
$parcel$export(module.exports, "queue_native_events", () => $92e75e76b1a9e331$export$f72bace509bf62ef);
|
|
88
|
+
$parcel$export(module.exports, "native_purchase_event", () => $cf5d1b4537e0340b$export$aad1b28cf2e0eea6);
|
|
89
|
+
$parcel$export(module.exports, "to_native_event", () => $cf5d1b4537e0340b$export$537c002f32ae6f61);
|
|
85
90
|
$parcel$export(module.exports, "filter_depict_payload", () => $0c84f8e99aac5765$export$72036d950e1fae95);
|
|
86
91
|
$parcel$export(module.exports, "send_depict", () => $0c84f8e99aac5765$export$28cacbd9b4306ffc);
|
|
87
92
|
$parcel$export(module.exports, "foolproof_send_beacon", () => $0c84f8e99aac5765$export$cc3b6ddf805f6156);
|
|
@@ -205,7 +210,7 @@ $parcel$export(module.exports, "version", () => $815f67c61b4c0a42$export$83d89fb
|
|
|
205
210
|
$parcel$export(module.exports, "add_to_version_info", () => $e4a18bf12ad092d9$export$2cefb7e61fcbae00);
|
|
206
211
|
$parcel$export(module.exports, "sync_el_content_with_accessor", () => $35303d72263038db$export$c3f56a35e076f139);
|
|
207
212
|
$parcel$export(module.exports, "use_href_accessor", () => $da35c7e27be2a442$export$e35115e6d0715f77);
|
|
208
|
-
const $815f67c61b4c0a42$export$83d89fbfd8236492 = "2.6.
|
|
213
|
+
const $815f67c61b4c0a42$export$83d89fbfd8236492 = "2.6.23";
|
|
209
214
|
const $7b5e577a60b81e60$export$55fe61489d2c7417 = /*@__PURE__*/(() => process.env.STRIP_DEBUG === "true" ? false : process.env.DEBUG === "true" || process.env.NODE_ENV === "development" || process.env.BUILD_TARGET !== "node" && (globalThis?.document?.currentScript?.dataset?.debug === "true" || globalThis?.localStorage?.getItem?.("debug") === "true"))();
|
|
210
215
|
const $e6c6e7929ea385ae$var$browser_prefix_styling = "color: #fff;";
|
|
211
216
|
let $e6c6e7929ea385ae$var$browser_prefix = "[Depict]";
|
|
@@ -1083,31 +1088,172 @@ class $d10801050840d92b$export$1d9c6fddbff3441f extends $d10801050840d92b$export
|
|
|
1083
1088
|
["open", "error", "message"].forEach(event => this.addEventListener(event, $268cbd9e4ade92db$export$b3bbfd758f11cfa9(() => this.#connection_last_active = +new Date())));
|
|
1084
1089
|
}
|
|
1085
1090
|
}
|
|
1086
|
-
const $4c6861fbcd3a0611$export$362abebb4b313340 = process.env.DEPICT_BASE_URL || "https://api.depict.ai";
|
|
1087
1091
|
|
|
1088
1092
|
/**
|
|
1089
|
-
*
|
|
1090
|
-
*
|
|
1091
|
-
*/
|
|
1092
|
-
|
|
1093
|
-
|
|
1093
|
+
* Where tracking events go: `v3` (the default) posts every event to `/create-events`; `v4` posts each event that the
|
|
1094
|
+
* native events contract can carry to `/v4/{merchant}/events` (NDJSON) and leaves the rest on `/create-events`.
|
|
1095
|
+
*/ /**
|
|
1096
|
+
* One line of `POST /v4/{merchant}/events`, as the strict V4 contract (`Event` in realtime `v4/types`) defines it.
|
|
1097
|
+
* Only these keys are sent.
|
|
1098
|
+
*/ /** The contract's limits, so an event V4 would reject stays on v3 instead of being dropped. */
|
|
1099
|
+
const $cf5d1b4537e0340b$var$EVENT_ID_MAX = 128;
|
|
1100
|
+
const $cf5d1b4537e0340b$var$MARKET_MAX = 128;
|
|
1101
|
+
const $cf5d1b4537e0340b$var$SESSION_ID_MAX = 256;
|
|
1102
|
+
const $cf5d1b4537e0340b$var$PRODUCT_ID_MAX = 500;
|
|
1103
|
+
const $cf5d1b4537e0340b$var$TRACKING_ID_MAX = 1536;
|
|
1104
|
+
const $cf5d1b4537e0340b$var$MERCHANT = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
1105
|
+
/** V4's card tracking id (`d1.<kind>.<request id>.<position>.<product>[.<context>]`); V4 writes no row for others. */
|
|
1106
|
+
const $cf5d1b4537e0340b$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_-]+)?$/;
|
|
1107
|
+
const $cf5d1b4537e0340b$var$CURRENCY = /^[A-Z]{3}$/;
|
|
1108
|
+
const $cf5d1b4537e0340b$var$non_empty = (value, max) => typeof value === "string" && value.length > 0 && value.length <= max;
|
|
1109
|
+
function $cf5d1b4537e0340b$export$637d3149de458a95(tenant) {
|
|
1110
|
+
return typeof tenant === "string" && $cf5d1b4537e0340b$var$MERCHANT.test(tenant) ? tenant : undefined;
|
|
1111
|
+
}
|
|
1112
|
+
function $cf5d1b4537e0340b$export$e7dbc5ffe3253bf0(value) {
|
|
1113
|
+
return typeof value === "string" && value.length <= $cf5d1b4537e0340b$var$TRACKING_ID_MAX && $cf5d1b4537e0340b$var$D1_TRACKING_ID.test(value) ? value : undefined;
|
|
1114
|
+
}
|
|
1115
|
+
function $cf5d1b4537e0340b$export$3ad94ee026666a31(body, ts) {
|
|
1116
|
+
const {
|
|
1117
|
+
deduplication_id: deduplication_id,
|
|
1118
|
+
market: market,
|
|
1119
|
+
session_id: session_id
|
|
1120
|
+
} = body;
|
|
1121
|
+
if (!$cf5d1b4537e0340b$var$non_empty(deduplication_id, $cf5d1b4537e0340b$var$EVENT_ID_MAX) || !$cf5d1b4537e0340b$var$non_empty(market, $cf5d1b4537e0340b$var$MARKET_MAX)) return undefined;
|
|
1122
|
+
if (!$cf5d1b4537e0340b$var$non_empty(session_id, $cf5d1b4537e0340b$var$SESSION_ID_MAX)) return undefined;
|
|
1123
|
+
return {
|
|
1124
|
+
event_id: deduplication_id,
|
|
1125
|
+
market: market,
|
|
1126
|
+
session_id: session_id,
|
|
1127
|
+
ts: ts
|
|
1128
|
+
};
|
|
1094
1129
|
}
|
|
1095
|
-
function $
|
|
1096
|
-
|
|
1130
|
+
function $cf5d1b4537e0340b$export$537c002f32ae6f61(body, ts) {
|
|
1131
|
+
const merchant = $cf5d1b4537e0340b$export$637d3149de458a95(body.tenant);
|
|
1132
|
+
const base = $cf5d1b4537e0340b$export$3ad94ee026666a31(body, ts);
|
|
1133
|
+
if (!merchant || !base) return undefined;
|
|
1134
|
+
const optional = (key, value) => typeof value === "string" && value ? {
|
|
1135
|
+
[key]: value
|
|
1136
|
+
} : {};
|
|
1137
|
+
const context = {
|
|
1138
|
+
...optional("url", body.url),
|
|
1139
|
+
...optional("referrer", body.document_referrer)
|
|
1140
|
+
};
|
|
1141
|
+
// The first result id set, as v3's intake reads it (resultIdOf in realtime): a v3 id there keeps the event on v3.
|
|
1142
|
+
const result_id = body.product_listing_result_id ?? body.recommendation_id ?? body.search_result_id;
|
|
1143
|
+
const tracking_id = $cf5d1b4537e0340b$export$e7dbc5ffe3253bf0(result_id);
|
|
1144
|
+
const has_result_id = result_id != null;
|
|
1145
|
+
const product_id = $cf5d1b4537e0340b$var$non_empty(body.product_id, $cf5d1b4537e0340b$var$PRODUCT_ID_MAX) ? body.product_id : undefined;
|
|
1146
|
+
if (body.product_id != null && !product_id) return undefined;
|
|
1147
|
+
let event;
|
|
1148
|
+
switch (body.type) {
|
|
1149
|
+
case "element_visible":
|
|
1150
|
+
case "click":
|
|
1151
|
+
if (!tracking_id) return undefined;
|
|
1152
|
+
event = {
|
|
1153
|
+
...base,
|
|
1154
|
+
type: body.type === "click" ? "click" : "impression",
|
|
1155
|
+
tracking_id: tracking_id,
|
|
1156
|
+
...context
|
|
1157
|
+
};
|
|
1158
|
+
break;
|
|
1159
|
+
case "add_to_cart":
|
|
1160
|
+
if (has_result_id ? !tracking_id : !product_id) return undefined;
|
|
1161
|
+
event = {
|
|
1162
|
+
...base,
|
|
1163
|
+
type: "add_to_cart",
|
|
1164
|
+
...(tracking_id ? {
|
|
1165
|
+
tracking_id: tracking_id
|
|
1166
|
+
} : {}),
|
|
1167
|
+
...(product_id ? {
|
|
1168
|
+
product_id: product_id
|
|
1169
|
+
} : {}),
|
|
1170
|
+
...context
|
|
1171
|
+
};
|
|
1172
|
+
break;
|
|
1173
|
+
case "page_view":
|
|
1174
|
+
if (!product_id || has_result_id && !tracking_id) return undefined;
|
|
1175
|
+
event = {
|
|
1176
|
+
...base,
|
|
1177
|
+
type: "product_view",
|
|
1178
|
+
product_id: product_id,
|
|
1179
|
+
...(tracking_id ? {
|
|
1180
|
+
tracking_id: tracking_id
|
|
1181
|
+
} : {}),
|
|
1182
|
+
...context
|
|
1183
|
+
};
|
|
1184
|
+
break;
|
|
1185
|
+
default:
|
|
1186
|
+
return undefined;
|
|
1187
|
+
}
|
|
1188
|
+
return {
|
|
1189
|
+
merchant: merchant,
|
|
1190
|
+
event: event
|
|
1191
|
+
};
|
|
1192
|
+
}
|
|
1193
|
+
function $cf5d1b4537e0340b$export$aad1b28cf2e0eea6(data, ts) {
|
|
1194
|
+
const base = $cf5d1b4537e0340b$export$3ad94ee026666a31({
|
|
1195
|
+
deduplication_id: data.event_id,
|
|
1196
|
+
market: data.market,
|
|
1197
|
+
session_id: data.session_id
|
|
1198
|
+
}, ts);
|
|
1199
|
+
if (!base || !$cf5d1b4537e0340b$var$non_empty(data.transaction_id, Infinity) || !$cf5d1b4537e0340b$var$CURRENCY.test(data.currency)) return undefined;
|
|
1200
|
+
const valid_items = data.items.every(item => $cf5d1b4537e0340b$var$non_empty(item.sku, Infinity) && typeof item.price === "number" && Number.isFinite(item.price) && Number.isInteger(item.quantity) && item.quantity > 0);
|
|
1201
|
+
if (!valid_items) return undefined;
|
|
1202
|
+
return {
|
|
1203
|
+
...base,
|
|
1204
|
+
type: "purchase",
|
|
1205
|
+
purchase: {
|
|
1206
|
+
transaction_id: data.transaction_id,
|
|
1207
|
+
currency: data.currency,
|
|
1208
|
+
items: data.items.map(({
|
|
1209
|
+
sku: sku,
|
|
1210
|
+
price: price,
|
|
1211
|
+
quantity: quantity
|
|
1212
|
+
}) => ({
|
|
1213
|
+
sku: sku,
|
|
1214
|
+
price: price,
|
|
1215
|
+
quantity: quantity
|
|
1216
|
+
}))
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
}
|
|
1220
|
+
const $4c6861fbcd3a0611$export$362abebb4b313340 = process.env.DEPICT_BASE_URL || "https://api.depict.ai";
|
|
1221
|
+
function $8506906daf2f2149$export$46cf5f54d4d7518() {
|
|
1222
|
+
try {
|
|
1223
|
+
if (typeof globalThis.crypto?.randomUUID === "function") return globalThis.crypto.randomUUID();
|
|
1224
|
+
const bytes = globalThis.crypto?.getRandomValues(new Uint8Array(16));
|
|
1225
|
+
if (!bytes) return undefined;
|
|
1226
|
+
bytes[6] = bytes[6] & 0x0f | 0x40;
|
|
1227
|
+
bytes[8] = bytes[8] & 0x3f | 0x80;
|
|
1228
|
+
const hex = Array.from(bytes, byte => (byte + 0x100).toString(16).slice(1)).join("");
|
|
1229
|
+
return hex.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5");
|
|
1230
|
+
} catch {
|
|
1231
|
+
return undefined;
|
|
1232
|
+
}
|
|
1097
1233
|
}
|
|
1098
1234
|
|
|
1099
1235
|
/** HTTP is the default; both also sends identical events over a canary socket. */
|
|
1100
1236
|
const $92e75e76b1a9e331$var$MAX_BODY_BYTES = 49152;
|
|
1101
1237
|
const $92e75e76b1a9e331$var$IMPRESSION_DELAY_MS = 250;
|
|
1102
1238
|
let $92e75e76b1a9e331$var$transport = "http";
|
|
1239
|
+
let $92e75e76b1a9e331$var$event_api = "v3";
|
|
1103
1240
|
let $92e75e76b1a9e331$var$socket;
|
|
1104
|
-
let $92e75e76b1a9e331$var$queued_events = [];
|
|
1105
|
-
let $92e75e76b1a9e331$var$queued_bytes = 2;
|
|
1106
1241
|
let $92e75e76b1a9e331$var$flush_timer;
|
|
1107
1242
|
let $92e75e76b1a9e331$var$listening = false;
|
|
1243
|
+
/**
|
|
1244
|
+
* Queued events per endpoint. v3's `/create-events` takes a JSON array; V4's `/v4/{merchant}/events` takes NDJSON.
|
|
1245
|
+
* Both bodies are the events joined by one separator byte, plus v3's two brackets.
|
|
1246
|
+
*/
|
|
1247
|
+
const $92e75e76b1a9e331$var$batches = new Map();
|
|
1108
1248
|
function $92e75e76b1a9e331$export$83c5d6634ba2a3c5(value) {
|
|
1109
1249
|
$92e75e76b1a9e331$var$transport = value === "both" ? "both" : "http";
|
|
1110
1250
|
}
|
|
1251
|
+
function $92e75e76b1a9e331$export$1a4819a80859e92e(value) {
|
|
1252
|
+
$92e75e76b1a9e331$var$event_api = value === "v4" ? "v4" : "v3";
|
|
1253
|
+
}
|
|
1254
|
+
function $92e75e76b1a9e331$export$88fbe329a1d960c8() {
|
|
1255
|
+
return $92e75e76b1a9e331$var$event_api;
|
|
1256
|
+
}
|
|
1111
1257
|
function $92e75e76b1a9e331$var$send_beacon(url, body) {
|
|
1112
1258
|
try {
|
|
1113
1259
|
if (!navigator.sendBeacon(url, new Blob([body], {
|
|
@@ -1117,7 +1263,17 @@ function $92e75e76b1a9e331$var$send_beacon(url, body) {
|
|
|
1117
1263
|
$268cbd9e4ade92db$export$f18d5b0af29128b7(error, "warning");
|
|
1118
1264
|
}
|
|
1119
1265
|
}
|
|
1120
|
-
|
|
1266
|
+
/** V4 answers 200 even when it rejects lines; a rejected line is an event the contract no longer takes. */
|
|
1267
|
+
function $92e75e76b1a9e331$var$check_native_response(response, url) {
|
|
1268
|
+
if (response.status !== 200 || typeof response.json !== "function") return;
|
|
1269
|
+
response.json().then(body => {
|
|
1270
|
+
if (body?.rejected) $268cbd9e4ade92db$export$f18d5b0af29128b7(new Error("V4 rejected tracking events"), "warning", {
|
|
1271
|
+
url: url,
|
|
1272
|
+
...body
|
|
1273
|
+
});
|
|
1274
|
+
}).catch(() => {});
|
|
1275
|
+
}
|
|
1276
|
+
function $92e75e76b1a9e331$var$send_batch(url, body, retried = false, native = false) {
|
|
1121
1277
|
let request;
|
|
1122
1278
|
try {
|
|
1123
1279
|
request = fetch(url, {
|
|
@@ -1134,20 +1290,61 @@ function $92e75e76b1a9e331$var$send_batch(url, body, retried = false) {
|
|
|
1134
1290
|
return;
|
|
1135
1291
|
}
|
|
1136
1292
|
request.then(response => {
|
|
1137
|
-
if (response.status >= 500 && !retried && document.visibilityState === "visible") $92e75e76b1a9e331$var$send_batch(url, body, true);
|
|
1293
|
+
if (response.status >= 500 && !retried && document.visibilityState === "visible") $92e75e76b1a9e331$var$send_batch(url, body, true, native);else if (native) $92e75e76b1a9e331$var$check_native_response(response, url);
|
|
1138
1294
|
}, () => {
|
|
1139
|
-
if (!retried && document.visibilityState === "visible") $92e75e76b1a9e331$var$send_batch(url, body, true);else $92e75e76b1a9e331$var$send_beacon(url, body);
|
|
1295
|
+
if (!retried && document.visibilityState === "visible") $92e75e76b1a9e331$var$send_batch(url, body, true, native);else $92e75e76b1a9e331$var$send_beacon(url, body);
|
|
1140
1296
|
}).catch(error => $268cbd9e4ade92db$export$f18d5b0af29128b7(error, "warning"));
|
|
1141
1297
|
}
|
|
1298
|
+
function $92e75e76b1a9e331$var$flush_batch(url) {
|
|
1299
|
+
const batch = $92e75e76b1a9e331$var$batches.get(url);
|
|
1300
|
+
if (!batch) return;
|
|
1301
|
+
$92e75e76b1a9e331$var$batches.delete(url);
|
|
1302
|
+
$92e75e76b1a9e331$var$send_batch(url, batch.ndjson ? batch.events.join("\n") : `[${batch.events.join(",")}]`, false, batch.ndjson);
|
|
1303
|
+
}
|
|
1142
1304
|
const $92e75e76b1a9e331$var$flush = /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9(() => {
|
|
1143
1305
|
clearTimeout($92e75e76b1a9e331$var$flush_timer);
|
|
1144
1306
|
$92e75e76b1a9e331$var$flush_timer = undefined;
|
|
1145
|
-
|
|
1146
|
-
const body = `[${$92e75e76b1a9e331$var$queued_events.join(",")}]`;
|
|
1147
|
-
$92e75e76b1a9e331$var$queued_events = [];
|
|
1148
|
-
$92e75e76b1a9e331$var$queued_bytes = 2;
|
|
1149
|
-
$92e75e76b1a9e331$var$send_batch(String($e4a18bf12ad092d9$export$fe609f0216e4ebef((0, $4c6861fbcd3a0611$export$362abebb4b313340) + "/create-events")), body);
|
|
1307
|
+
for (const url of [...$92e75e76b1a9e331$var$batches.keys()]) $92e75e76b1a9e331$var$flush_batch(url);
|
|
1150
1308
|
});
|
|
1309
|
+
const $92e75e76b1a9e331$var$v3_url = () => String($e4a18bf12ad092d9$export$fe609f0216e4ebef((0, $4c6861fbcd3a0611$export$362abebb4b313340) + "/create-events"));
|
|
1310
|
+
/** No version params: like the native reads, V4 gets only what its contract defines. */
|
|
1311
|
+
const $92e75e76b1a9e331$var$v4_url = merchant => `${(0, $4c6861fbcd3a0611$export$362abebb4b313340)}/v4/${encodeURIComponent(merchant)}/events`;
|
|
1312
|
+
function $92e75e76b1a9e331$var$listen() {
|
|
1313
|
+
if ($92e75e76b1a9e331$var$listening) return;
|
|
1314
|
+
document.addEventListener("visibilitychange", () => {
|
|
1315
|
+
if (document.visibilityState === "hidden") $92e75e76b1a9e331$var$flush();
|
|
1316
|
+
});
|
|
1317
|
+
window.addEventListener("pagehide", $92e75e76b1a9e331$var$flush);
|
|
1318
|
+
$92e75e76b1a9e331$var$listening = true;
|
|
1319
|
+
}
|
|
1320
|
+
/** Adds one serialized event to its endpoint's batch, sending the batch first if the event wouldn't fit. */
|
|
1321
|
+
function $92e75e76b1a9e331$var$enqueue(url, json, ndjson, type) {
|
|
1322
|
+
const bytes = new Blob([json]).size;
|
|
1323
|
+
const empty_bytes = ndjson ? 0 : 2;
|
|
1324
|
+
if (bytes + empty_bytes > $92e75e76b1a9e331$var$MAX_BODY_BYTES) {
|
|
1325
|
+
$268cbd9e4ade92db$export$f18d5b0af29128b7(new Error("Event exceeds the keepalive body limit"), "warning", {
|
|
1326
|
+
bytes: bytes,
|
|
1327
|
+
type: type
|
|
1328
|
+
});
|
|
1329
|
+
return false;
|
|
1330
|
+
}
|
|
1331
|
+
let batch = $92e75e76b1a9e331$var$batches.get(url);
|
|
1332
|
+
if (batch && batch.bytes + bytes + 1 > $92e75e76b1a9e331$var$MAX_BODY_BYTES) {
|
|
1333
|
+
$92e75e76b1a9e331$var$flush_batch(url);
|
|
1334
|
+
batch = undefined;
|
|
1335
|
+
}
|
|
1336
|
+
if (!batch) $92e75e76b1a9e331$var$batches.set(url, batch = {
|
|
1337
|
+
events: [],
|
|
1338
|
+
bytes: empty_bytes,
|
|
1339
|
+
ndjson: ndjson
|
|
1340
|
+
});
|
|
1341
|
+
batch.bytes += bytes + (batch.events.length ? 1 : 0);
|
|
1342
|
+
batch.events.push(json);
|
|
1343
|
+
return true;
|
|
1344
|
+
}
|
|
1345
|
+
function $92e75e76b1a9e331$var$schedule(immediate) {
|
|
1346
|
+
if (immediate) $92e75e76b1a9e331$var$flush();else if ($92e75e76b1a9e331$var$batches.size && $92e75e76b1a9e331$var$flush_timer === undefined) $92e75e76b1a9e331$var$flush_timer = setTimeout($92e75e76b1a9e331$var$flush, $92e75e76b1a9e331$var$IMPRESSION_DELAY_MS);
|
|
1347
|
+
}
|
|
1151
1348
|
const $92e75e76b1a9e331$var$send_canary = /*@__PURE__*/$268cbd9e4ade92db$export$b3bbfd758f11cfa9(json => {
|
|
1152
1349
|
if (typeof WebSocket !== "function") return;
|
|
1153
1350
|
$92e75e76b1a9e331$var$socket ||= new (0, $d10801050840d92b$export$1d9c6fddbff3441f)("wss://ws.depict.ai/ws/create-events");
|
|
@@ -1159,36 +1356,37 @@ const $92e75e76b1a9e331$var$send_canary = /*@__PURE__*/$268cbd9e4ade92db$export$
|
|
|
1159
1356
|
}, undefined, "warning");
|
|
1160
1357
|
function $92e75e76b1a9e331$export$fb18f6dbe1c6f251(payload) {
|
|
1161
1358
|
if (process.env.DEPICT === "false" || typeof document === "undefined") return;
|
|
1162
|
-
|
|
1163
|
-
document.addEventListener("visibilitychange", () => {
|
|
1164
|
-
if (document.visibilityState === "hidden") $92e75e76b1a9e331$var$flush();
|
|
1165
|
-
});
|
|
1166
|
-
window.addEventListener("pagehide", $92e75e76b1a9e331$var$flush);
|
|
1167
|
-
$92e75e76b1a9e331$var$listening = true;
|
|
1168
|
-
}
|
|
1359
|
+
$92e75e76b1a9e331$var$listen();
|
|
1169
1360
|
let accepted = true;
|
|
1170
1361
|
let immediate = document.visibilityState === "hidden";
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
});
|
|
1362
|
+
const ts = new Date().toISOString();
|
|
1363
|
+
for (const raw of payload) {
|
|
1364
|
+
const event = {
|
|
1365
|
+
...raw,
|
|
1366
|
+
deduplication_id: raw.deduplication_id || $8506906daf2f2149$export$46cf5f54d4d7518()
|
|
1367
|
+
};
|
|
1368
|
+
const native = $92e75e76b1a9e331$var$event_api === "v4" ? $cf5d1b4537e0340b$export$537c002f32ae6f61(event, ts) : undefined;
|
|
1369
|
+
const json = JSON.stringify(native ? native.event : event);
|
|
1370
|
+
const queued = native ? $92e75e76b1a9e331$var$enqueue($92e75e76b1a9e331$var$v4_url(native.merchant), json, true, event.type) : $92e75e76b1a9e331$var$enqueue($92e75e76b1a9e331$var$v3_url(), json, false, event.type);
|
|
1371
|
+
if (!queued) {
|
|
1182
1372
|
accepted = false;
|
|
1183
1373
|
continue;
|
|
1184
1374
|
}
|
|
1185
|
-
if ($92e75e76b1a9e331$var$queued_bytes + bytes + ($92e75e76b1a9e331$var$queued_events.length ? 1 : 0) > $92e75e76b1a9e331$var$MAX_BODY_BYTES) $92e75e76b1a9e331$var$flush();
|
|
1186
|
-
$92e75e76b1a9e331$var$queued_bytes += bytes + ($92e75e76b1a9e331$var$queued_events.length ? 1 : 0);
|
|
1187
|
-
$92e75e76b1a9e331$var$queued_events.push(json);
|
|
1188
1375
|
immediate ||= event.type !== "element_visible";
|
|
1189
|
-
|
|
1376
|
+
// The canary socket is v3's; an event sent to V4 isn't mirrored there.
|
|
1377
|
+
if ($92e75e76b1a9e331$var$transport === "both" && !native) $92e75e76b1a9e331$var$send_canary(json);
|
|
1190
1378
|
}
|
|
1191
|
-
|
|
1379
|
+
$92e75e76b1a9e331$var$schedule(immediate);
|
|
1380
|
+
return accepted;
|
|
1381
|
+
}
|
|
1382
|
+
function $92e75e76b1a9e331$export$f72bace509bf62ef(merchant, events) {
|
|
1383
|
+
if (process.env.DEPICT === "false" || typeof document === "undefined") return;
|
|
1384
|
+
const path_merchant = $cf5d1b4537e0340b$export$637d3149de458a95(merchant);
|
|
1385
|
+
if (!path_merchant) return false;
|
|
1386
|
+
$92e75e76b1a9e331$var$listen();
|
|
1387
|
+
let accepted = true;
|
|
1388
|
+
for (const event of events) accepted = $92e75e76b1a9e331$var$enqueue($92e75e76b1a9e331$var$v4_url(path_merchant), JSON.stringify(event), true, event.type) && accepted;
|
|
1389
|
+
$92e75e76b1a9e331$var$schedule(true);
|
|
1192
1390
|
return accepted;
|
|
1193
1391
|
}
|
|
1194
1392
|
const $0c84f8e99aac5765$var$c = (0, $268cbd9e4ade92db$export$b3bbfd758f11cfa9);
|
|
@@ -1248,6 +1446,17 @@ const $0c84f8e99aac5765$export$28cacbd9b4306ffc = /*@__PURE__*/$0c84f8e99aac5765
|
|
|
1248
1446
|
// filter_depict_payload will only return undefined if process.env.DEPICT === "false"
|
|
1249
1447
|
return $0c84f8e99aac5765$export$608478473a3304a0($0c84f8e99aac5765$export$72036d950e1fae95(payload), use_ws);
|
|
1250
1448
|
});
|
|
1449
|
+
|
|
1450
|
+
/**
|
|
1451
|
+
* Returns a random string
|
|
1452
|
+
* @return A random string, containing a-z, 0-9 and occasionally a dot (`.`)
|
|
1453
|
+
*/
|
|
1454
|
+
function $650b64c1b384c895$export$656831b7e9c341c3() {
|
|
1455
|
+
return (Math.random() * 2e17).toString(36);
|
|
1456
|
+
}
|
|
1457
|
+
function $650b64c1b384c895$export$a6db784f019668ba() {
|
|
1458
|
+
return "x" + $650b64c1b384c895$export$656831b7e9c341c3().replaceAll(".", "");
|
|
1459
|
+
}
|
|
1251
1460
|
let $e0a87646d12cb987$export$61e7e1f11e96692f = () => {
|
|
1252
1461
|
if (typeof document === "undefined") return "server";
|
|
1253
1462
|
let id = "";
|
package/latest/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSX, Accessor } from "solid-js";
|
|
2
|
-
export const version = "2.6.
|
|
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
|
-
*
|
|
223
|
-
*
|
|
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
|
|
226
|
-
|
|
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
|
|
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
|
|
1317
|
+
new (body?: BodyInit | null, init?: ResponseInit): Response;
|
|
1241
1318
|
prototype: Response;
|
|
1242
1319
|
error(): Response;
|
|
1243
|
-
|
|
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) =>
|
|
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():
|
|
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[]
|
|
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>;
|