@sixb/client 0.1.20 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/activity-attribution.d.ts +29 -0
- package/dist/activity-attribution.d.ts.map +1 -0
- package/dist/activity-tracker.d.ts +105 -0
- package/dist/activity-tracker.d.ts.map +1 -0
- package/dist/browser.d.ts +2 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +513 -11
- package/dist/browser.js.map +6 -4
- package/dist/{chunk-g05ar78c.js → chunk-3b154p8n.js} +3 -3
- package/dist/{chunk-tkjkrcdt.js → chunk-3f2pjdzk.js} +155 -2
- package/dist/chunk-3f2pjdzk.js.map +19 -0
- package/dist/{chunk-awbb496e.js → chunk-9wd8x2em.js} +1 -1
- package/dist/{chunk-3aa3m9z6.js → chunk-ana8rtgb.js} +2 -2
- package/dist/{chunk-95bnb04n.js → chunk-qdq5gfqx.js} +1 -1
- package/dist/{chunk-12s8gbwj.js → chunk-s5zamywm.js} +2 -2
- package/dist/generated/@tanstack/react-query.gen.d.ts +2281 -591
- package/dist/generated/@tanstack/react-query.gen.d.ts.map +1 -1
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/generated/sdk.gen.d.ts +89 -1
- package/dist/generated/sdk.gen.d.ts.map +1 -1
- package/dist/generated/types.gen.d.ts +1669 -448
- package/dist/generated/types.gen.d.ts.map +1 -1
- package/dist/hooks.js +299 -6
- package/dist/hooks.js.map +3 -3
- package/dist/index.js +40 -6
- package/dist/index.js.map +1 -1
- package/dist/logs.js +3 -3
- package/dist/models.js +36 -2
- package/dist/models.js.map +1 -1
- package/dist/query.js +3 -3
- package/package.json +2 -2
- package/src/activity-attribution.ts +211 -0
- package/src/activity-tracker.ts +527 -0
- package/src/browser.ts +14 -1
- package/src/generated/@tanstack/react-query.gen.ts +580 -0
- package/src/generated/index.ts +101 -0
- package/src/generated/sdk.gen.ts +389 -0
- package/src/generated/types.gen.ts +2405 -1090
- package/dist/chunk-tkjkrcdt.js.map +0 -19
- /package/dist/{chunk-g05ar78c.js.map → chunk-3b154p8n.js.map} +0 -0
- /package/dist/{chunk-awbb496e.js.map → chunk-9wd8x2em.js.map} +0 -0
- /package/dist/{chunk-3aa3m9z6.js.map → chunk-ana8rtgb.js.map} +0 -0
- /package/dist/{chunk-95bnb04n.js.map → chunk-qdq5gfqx.js.map} +0 -0
- /package/dist/{chunk-12s8gbwj.js.map → chunk-s5zamywm.js.map} +0 -0
package/dist/browser.js
CHANGED
|
@@ -1,23 +1,515 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
import {
|
|
3
|
+
client2,
|
|
4
|
+
getAuthSession2,
|
|
5
|
+
exchangeSharedAccess2,
|
|
6
|
+
getSharedAccessSession2,
|
|
7
|
+
signOutSharedAccess2,
|
|
8
|
+
getActivityCaptureConfig2,
|
|
9
|
+
captureActivity2
|
|
10
|
+
} from "./chunk-3f2pjdzk.js";
|
|
2
11
|
import {
|
|
3
12
|
normalizeSixbApiBaseUrl2,
|
|
4
13
|
assertSharedAccessGrantId,
|
|
5
14
|
markClientSharedAuthority,
|
|
6
15
|
getClientSharedGrantId
|
|
7
16
|
} from "./chunk-j9t5h44d.js";
|
|
8
|
-
import {
|
|
9
|
-
client2,
|
|
10
|
-
getAuthSession2,
|
|
11
|
-
exchangeSharedAccess2,
|
|
12
|
-
getSharedAccessSession2,
|
|
13
|
-
signOutSharedAccess2
|
|
14
|
-
} from "./chunk-tkjkrcdt.js";
|
|
15
17
|
import {
|
|
16
18
|
SIXB_CSRF_TOKEN_RESPONSE_HEADER_NAME2,
|
|
17
19
|
SixbApiError2,
|
|
18
20
|
isSixbApiError2,
|
|
19
21
|
configureSixbClient2
|
|
20
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-9wd8x2em.js";
|
|
23
|
+
|
|
24
|
+
// src/activity-attribution.ts
|
|
25
|
+
var MAX_AGE_MS = 30 * 60000;
|
|
26
|
+
var MAX_STORED_LENGTH = 2048;
|
|
27
|
+
var HOSTNAME = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
28
|
+
var CONTROL_CHARACTERS = /[\x00-\x1f\x7f]/;
|
|
29
|
+
var UTM_KEYS = ["source", "medium", "campaign"];
|
|
30
|
+
var ATTRIBUTION_KEYS = [...UTM_KEYS, "referrer"];
|
|
31
|
+
function readActivityAttribution(href, referrer, apiBaseUrl) {
|
|
32
|
+
const url = new URL(href);
|
|
33
|
+
const utm = {};
|
|
34
|
+
let malformed = false;
|
|
35
|
+
for (const key of UTM_KEYS) {
|
|
36
|
+
const raw = url.searchParams.get(`utm_${key}`);
|
|
37
|
+
const value = label(raw);
|
|
38
|
+
if (value !== undefined) {
|
|
39
|
+
utm[key] = value;
|
|
40
|
+
} else if (raw?.trim()) {
|
|
41
|
+
malformed = true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (Object.keys(utm).length > 0) {
|
|
45
|
+
return utm;
|
|
46
|
+
}
|
|
47
|
+
if (malformed) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
return externalReferrer(referrer, [url.hostname, new URL(apiBaseUrl).hostname]);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
class ActivityArrival {
|
|
54
|
+
storage;
|
|
55
|
+
key;
|
|
56
|
+
now;
|
|
57
|
+
attribution;
|
|
58
|
+
constructor(storage, key, current, now = Date.now) {
|
|
59
|
+
this.storage = storage;
|
|
60
|
+
this.key = key;
|
|
61
|
+
this.now = now;
|
|
62
|
+
const pending = this.takePending();
|
|
63
|
+
const hasCampaign = UTM_KEYS.some((key) => current?.[key] !== undefined);
|
|
64
|
+
this.attribution = hasCampaign ? current : pending ?? current;
|
|
65
|
+
}
|
|
66
|
+
preserve() {
|
|
67
|
+
if (this.attribution === undefined) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
this.storage?.setItem(this.key, JSON.stringify({ at: this.now(), attribution: this.attribution }));
|
|
72
|
+
} catch {}
|
|
73
|
+
}
|
|
74
|
+
takePending() {
|
|
75
|
+
try {
|
|
76
|
+
const raw = this.storage?.getItem(this.key);
|
|
77
|
+
this.storage?.removeItem(this.key);
|
|
78
|
+
if (!raw || raw.length > MAX_STORED_LENGTH) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const value = JSON.parse(raw);
|
|
82
|
+
if (!value || typeof value !== "object" || !("at" in value) || !("attribution" in value) || typeof value.at !== "number") {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const age = this.now() - value.at;
|
|
86
|
+
return age >= 0 && age < MAX_AGE_MS ? storedAttribution(value.attribution) : undefined;
|
|
87
|
+
} catch {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
var arrival;
|
|
93
|
+
function prepareActivityArrival(apiBaseUrl, scope) {
|
|
94
|
+
arrival = undefined;
|
|
95
|
+
if (typeof window === "undefined") {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
let storage = null;
|
|
99
|
+
try {
|
|
100
|
+
storage = window.sessionStorage;
|
|
101
|
+
} catch {}
|
|
102
|
+
try {
|
|
103
|
+
arrival = new ActivityArrival(storage, `sixb:activity-arrival:${JSON.stringify([apiBaseUrl, scope])}`, readActivityAttribution(window.location.href, document.referrer, apiBaseUrl));
|
|
104
|
+
} catch {}
|
|
105
|
+
}
|
|
106
|
+
function preserveSixbActivityArrival() {
|
|
107
|
+
arrival?.preserve();
|
|
108
|
+
}
|
|
109
|
+
function takeActivityArrival() {
|
|
110
|
+
const value = arrival?.attribution;
|
|
111
|
+
if (arrival) {
|
|
112
|
+
arrival.attribution = {};
|
|
113
|
+
}
|
|
114
|
+
return value;
|
|
115
|
+
}
|
|
116
|
+
function clearActivityArrival() {
|
|
117
|
+
arrival = undefined;
|
|
118
|
+
}
|
|
119
|
+
function label(value) {
|
|
120
|
+
if (typeof value !== "string") {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const text = value.trim();
|
|
124
|
+
return text && text.length <= 100 && !CONTROL_CHARACTERS.test(text) ? text : undefined;
|
|
125
|
+
}
|
|
126
|
+
function externalReferrer(referrer, ownHosts) {
|
|
127
|
+
try {
|
|
128
|
+
const previous = new URL(referrer);
|
|
129
|
+
const hostname = previous.hostname;
|
|
130
|
+
if ((previous.protocol === "http:" || previous.protocol === "https:") && !ownHosts.includes(hostname) && hostname.length <= 253 && HOSTNAME.test(hostname)) {
|
|
131
|
+
return { referrer: hostname };
|
|
132
|
+
}
|
|
133
|
+
} catch {}
|
|
134
|
+
return {};
|
|
135
|
+
}
|
|
136
|
+
function storedAttribution(value) {
|
|
137
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (Object.keys(value).some((key) => !ATTRIBUTION_KEYS.some((field) => field === key))) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const result = {};
|
|
144
|
+
for (const key of ATTRIBUTION_KEYS) {
|
|
145
|
+
const raw = Reflect.get(value, key);
|
|
146
|
+
if (raw === undefined) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (typeof raw !== "string") {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const valid = key === "referrer" ? raw.length > 0 && raw.length <= 253 && HOSTNAME.test(raw) : label(raw) === raw;
|
|
153
|
+
if (!valid) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
result[key] = raw;
|
|
157
|
+
}
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// src/activity-tracker.ts
|
|
162
|
+
class ActivityDeliveryError extends Error {
|
|
163
|
+
status;
|
|
164
|
+
retryAfterMs;
|
|
165
|
+
name = "ActivityDeliveryError";
|
|
166
|
+
constructor(status, retryAfterMs) {
|
|
167
|
+
super(`[SixbClient] Activity delivery was refused with status ${status}.`);
|
|
168
|
+
this.status = status;
|
|
169
|
+
this.retryAfterMs = retryAfterMs;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
var MAX_QUEUE = 100;
|
|
173
|
+
var MAX_BATCH = 20;
|
|
174
|
+
var MAX_AGE_MS2 = 60000;
|
|
175
|
+
var MAX_ATTEMPTS = 3;
|
|
176
|
+
var REQUEST_TIMEOUT_MS = 1e4;
|
|
177
|
+
var FLUSH_DELAY_MS = 500;
|
|
178
|
+
var PULSE_INTERVAL_MS = 30000;
|
|
179
|
+
var INPUT_EVENTS = ["pointerdown", "keydown", "touchstart", "scroll"];
|
|
180
|
+
var TRACK_ATTRIBUTE = "data-sixb-track";
|
|
181
|
+
var COALESCE_MS = 1000;
|
|
182
|
+
var MAX_REPORTED_NAMES = 20;
|
|
183
|
+
var REPORTED_NAME_LENGTH = 40;
|
|
184
|
+
var INTERACTION_NAME_PATTERN = /^(?!.*\d{4})[a-z][a-z0-9_-]{0,39}(?:\.[a-z][a-z0-9_-]{0,39})*$/;
|
|
185
|
+
var INTERACTION_NAME_MAX_LENGTH = 100;
|
|
186
|
+
|
|
187
|
+
class ActivityTracker {
|
|
188
|
+
options;
|
|
189
|
+
abort = new AbortController;
|
|
190
|
+
now;
|
|
191
|
+
warn;
|
|
192
|
+
enabled = false;
|
|
193
|
+
idleTimeoutMs = 30 * 60000;
|
|
194
|
+
route = null;
|
|
195
|
+
queue = [];
|
|
196
|
+
flushTimer;
|
|
197
|
+
pulseTimer;
|
|
198
|
+
pending;
|
|
199
|
+
failedAttempts = 0;
|
|
200
|
+
throttledUntil = 0;
|
|
201
|
+
active = false;
|
|
202
|
+
hiddenNavigation = false;
|
|
203
|
+
lastInputAt = 0;
|
|
204
|
+
arrivalSent = false;
|
|
205
|
+
invalidNames = new Set;
|
|
206
|
+
moreInvalidNames = false;
|
|
207
|
+
lastInteraction;
|
|
208
|
+
constructor(options) {
|
|
209
|
+
this.options = options;
|
|
210
|
+
this.now = options.now ?? Date.now;
|
|
211
|
+
this.warn = options.warn ?? ((message) => console.warn(message));
|
|
212
|
+
this.start();
|
|
213
|
+
}
|
|
214
|
+
page(route) {
|
|
215
|
+
this.route = route;
|
|
216
|
+
this.hiddenNavigation = route !== null;
|
|
217
|
+
if (!this.enabled || !this.visible() || route === null) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
this.hiddenNavigation = false;
|
|
221
|
+
this.active = false;
|
|
222
|
+
this.lastInputAt = this.now();
|
|
223
|
+
this.enqueue("page.view");
|
|
224
|
+
}
|
|
225
|
+
interaction(name) {
|
|
226
|
+
if (this.now() - this.lastInputAt >= this.idleTimeoutMs) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
this.record(name);
|
|
230
|
+
}
|
|
231
|
+
dispose() {
|
|
232
|
+
this.enabled = false;
|
|
233
|
+
this.abort.abort();
|
|
234
|
+
clearTimeout(this.flushTimer);
|
|
235
|
+
clearInterval(this.pulseTimer);
|
|
236
|
+
for (const type of INPUT_EVENTS) {
|
|
237
|
+
this.options.document?.removeEventListener(type, this.onInput, { capture: true });
|
|
238
|
+
}
|
|
239
|
+
this.options.document?.removeEventListener("click", this.onClick, { capture: true });
|
|
240
|
+
this.options.document?.removeEventListener("visibilitychange", this.onVisibility);
|
|
241
|
+
this.queue = [];
|
|
242
|
+
}
|
|
243
|
+
flush() {
|
|
244
|
+
clearTimeout(this.flushTimer);
|
|
245
|
+
this.flushTimer = undefined;
|
|
246
|
+
if (this.pending) {
|
|
247
|
+
return this.pending;
|
|
248
|
+
}
|
|
249
|
+
this.pending = this.sendBatch().finally(() => {
|
|
250
|
+
this.pending = undefined;
|
|
251
|
+
if (this.queue.length > 0 && !this.abort.signal.aborted) {
|
|
252
|
+
this.schedule(this.nextDelay());
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
return this.pending;
|
|
256
|
+
}
|
|
257
|
+
nextDelay() {
|
|
258
|
+
const throttled = this.throttledUntil - this.now();
|
|
259
|
+
if (throttled > 0) {
|
|
260
|
+
return throttled;
|
|
261
|
+
}
|
|
262
|
+
return this.failedAttempts > 0 ? retryDelay(this.failedAttempts) : FLUSH_DELAY_MS;
|
|
263
|
+
}
|
|
264
|
+
async start() {
|
|
265
|
+
let config;
|
|
266
|
+
try {
|
|
267
|
+
config = await this.request((signal) => this.options.load(signal));
|
|
268
|
+
} catch {
|
|
269
|
+
if (!this.abort.signal.aborted) {
|
|
270
|
+
this.warn("[SixbClient] Activity capture settings are unavailable; this visit is not recorded.");
|
|
271
|
+
}
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (this.abort.signal.aborted || !config.enabled) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
this.enabled = true;
|
|
278
|
+
this.idleTimeoutMs = config.idleTimeoutMs;
|
|
279
|
+
for (const type of INPUT_EVENTS) {
|
|
280
|
+
this.options.document?.addEventListener(type, this.onInput, { capture: true, passive: true });
|
|
281
|
+
}
|
|
282
|
+
this.options.document?.addEventListener("click", this.onClick, { capture: true, passive: true });
|
|
283
|
+
this.options.document?.addEventListener("visibilitychange", this.onVisibility);
|
|
284
|
+
this.pulseTimer = setInterval(this.onPulse, PULSE_INTERVAL_MS);
|
|
285
|
+
if (this.route !== null) {
|
|
286
|
+
this.page(this.route);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
onPulse = () => {
|
|
290
|
+
if (this.active && this.visible()) {
|
|
291
|
+
this.active = false;
|
|
292
|
+
this.enqueue("visit.activity");
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
onInput = (event) => {
|
|
296
|
+
if (!event.isTrusted || !this.visible()) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const resumed = this.now() - this.lastInputAt >= this.idleTimeoutMs;
|
|
300
|
+
this.lastInputAt = this.now();
|
|
301
|
+
if (resumed) {
|
|
302
|
+
this.active = false;
|
|
303
|
+
this.enqueue("visit.activity");
|
|
304
|
+
} else {
|
|
305
|
+
this.active = true;
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
onClick = (event) => {
|
|
309
|
+
if (!event.isTrusted) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
const path = event.composedPath();
|
|
313
|
+
const markedAt = path.findIndex((target) => isElement(target) && target.hasAttribute(TRACK_ATTRIBUTE));
|
|
314
|
+
const marked = path[markedAt];
|
|
315
|
+
if (!isElement(marked)) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const within = path.slice(0, markedAt + 1).filter(isElement);
|
|
319
|
+
if (within.some((element) => isDisabled(element) || forwardsClick(element, marked, path))) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
this.lastInputAt = this.now();
|
|
323
|
+
this.active = false;
|
|
324
|
+
this.record(marked.getAttribute(TRACK_ATTRIBUTE) ?? "");
|
|
325
|
+
};
|
|
326
|
+
record(name) {
|
|
327
|
+
if (!this.enabled || !this.visible() || this.route === null) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
if (!isInteractionName(name)) {
|
|
331
|
+
this.invalidName(name);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const now = this.now();
|
|
335
|
+
if (this.lastInteraction?.name === name && now - this.lastInteraction.at < COALESCE_MS) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
this.lastInteraction = { name, at: now };
|
|
339
|
+
this.push((route) => ({ id: crypto.randomUUID(), type: "ui.interaction", name, route }));
|
|
340
|
+
}
|
|
341
|
+
onVisibility = () => {
|
|
342
|
+
if (this.visible()) {
|
|
343
|
+
this.lastInputAt = this.now();
|
|
344
|
+
this.active = false;
|
|
345
|
+
this.enqueue(this.hiddenNavigation ? "page.view" : "visit.activity");
|
|
346
|
+
this.hiddenNavigation = false;
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
if (this.active) {
|
|
350
|
+
this.active = false;
|
|
351
|
+
this.enqueue("visit.activity");
|
|
352
|
+
}
|
|
353
|
+
this.flush();
|
|
354
|
+
};
|
|
355
|
+
visible() {
|
|
356
|
+
return this.options.document?.visibilityState === "visible";
|
|
357
|
+
}
|
|
358
|
+
enqueue(type) {
|
|
359
|
+
this.push((route) => ({ id: crypto.randomUUID(), type, route, ...this.nextAttribution() }));
|
|
360
|
+
}
|
|
361
|
+
push(build) {
|
|
362
|
+
if (!this.enabled || this.route === null || this.abort.signal.aborted) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (this.queue.length >= MAX_QUEUE) {
|
|
366
|
+
this.dropped(1);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
this.queue.push({ event: build(this.route), queuedAt: this.now() });
|
|
370
|
+
this.schedule(FLUSH_DELAY_MS);
|
|
371
|
+
}
|
|
372
|
+
nextAttribution() {
|
|
373
|
+
const first = !this.arrivalSent;
|
|
374
|
+
this.arrivalSent = true;
|
|
375
|
+
if (!first) {
|
|
376
|
+
return { attribution: {} };
|
|
377
|
+
}
|
|
378
|
+
return this.options.attribution === undefined ? {} : { attribution: this.options.attribution };
|
|
379
|
+
}
|
|
380
|
+
schedule(delay) {
|
|
381
|
+
if (this.flushTimer !== undefined) {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
this.flushTimer = setTimeout(() => {
|
|
385
|
+
this.flushTimer = undefined;
|
|
386
|
+
this.flush();
|
|
387
|
+
}, delay);
|
|
388
|
+
}
|
|
389
|
+
async sendBatch() {
|
|
390
|
+
if (!this.enabled || this.abort.signal.aborted) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
const fresh = this.queue.filter((item) => this.now() - item.queuedAt <= MAX_AGE_MS2);
|
|
394
|
+
if (fresh.length < this.queue.length) {
|
|
395
|
+
this.dropped(this.queue.length - fresh.length);
|
|
396
|
+
this.queue = fresh;
|
|
397
|
+
}
|
|
398
|
+
const batch = this.queue.slice(0, MAX_BATCH);
|
|
399
|
+
if (batch.length === 0 || this.now() < this.throttledUntil) {
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
try {
|
|
403
|
+
await this.request((signal) => this.options.send(batch.map((item) => item.event), signal));
|
|
404
|
+
if (this.abort.signal.aborted) {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
this.queue.splice(0, batch.length);
|
|
408
|
+
this.failedAttempts = 0;
|
|
409
|
+
} catch (error) {
|
|
410
|
+
if (this.abort.signal.aborted) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (error instanceof ActivityDeliveryError && error.status === 429) {
|
|
414
|
+
this.throttledUntil = this.now() + Math.min(error.retryAfterMs ?? MAX_AGE_MS2, MAX_AGE_MS2);
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
if (error instanceof ActivityDeliveryError && error.status >= 400 && error.status < 500) {
|
|
418
|
+
this.queue.splice(0, batch.length);
|
|
419
|
+
this.dropped(batch.length);
|
|
420
|
+
this.failedAttempts = 0;
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
this.failedAttempts++;
|
|
424
|
+
if (this.failedAttempts >= MAX_ATTEMPTS) {
|
|
425
|
+
this.queue.splice(0, batch.length);
|
|
426
|
+
this.dropped(batch.length);
|
|
427
|
+
this.failedAttempts = 0;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
async request(run) {
|
|
432
|
+
const controller = new AbortController;
|
|
433
|
+
const abort = () => controller.abort();
|
|
434
|
+
this.abort.signal.addEventListener("abort", abort, { once: true });
|
|
435
|
+
const timeout = setTimeout(abort, REQUEST_TIMEOUT_MS);
|
|
436
|
+
try {
|
|
437
|
+
return await run(controller.signal);
|
|
438
|
+
} finally {
|
|
439
|
+
clearTimeout(timeout);
|
|
440
|
+
this.abort.signal.removeEventListener("abort", abort);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
invalidName(name) {
|
|
444
|
+
if (this.invalidNames.has(name)) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
if (this.invalidNames.size >= MAX_REPORTED_NAMES) {
|
|
448
|
+
if (!this.moreInvalidNames) {
|
|
449
|
+
this.moreInvalidNames = true;
|
|
450
|
+
this.warn("[SixbClient] More interaction names are invalid; they are not reported.");
|
|
451
|
+
}
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
const text = String(name);
|
|
455
|
+
const shown = text.length > REPORTED_NAME_LENGTH ? `${text.slice(0, REPORTED_NAME_LENGTH)}\u2026` : text;
|
|
456
|
+
this.invalidNames.add(name);
|
|
457
|
+
this.warn(`[SixbClient] ${JSON.stringify(shown)} is not an interaction name, so it is not recorded. Use lowercase dotted identifiers such as "invoices.export".`);
|
|
458
|
+
}
|
|
459
|
+
dropped(count) {
|
|
460
|
+
this.warn(`[SixbClient] Activity capture dropped ${count} event(s); visit history may be incomplete.`);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
function isInteractionName(value) {
|
|
464
|
+
return typeof value === "string" && value.length <= INTERACTION_NAME_MAX_LENGTH && INTERACTION_NAME_PATTERN.test(value);
|
|
465
|
+
}
|
|
466
|
+
function isElement(value) {
|
|
467
|
+
return typeof value === "object" && value !== null && typeof Reflect.get(value, "hasAttribute") === "function";
|
|
468
|
+
}
|
|
469
|
+
function isDisabled(element) {
|
|
470
|
+
return element.getAttribute("aria-disabled") === "true" || element.matches(":disabled");
|
|
471
|
+
}
|
|
472
|
+
function forwardsClick(element, marked, path) {
|
|
473
|
+
const control = Reflect.get(element, "control");
|
|
474
|
+
return element.tagName === "LABEL" && isElement(control) && marked.contains(control) && !path.includes(control);
|
|
475
|
+
}
|
|
476
|
+
function retryDelay(failedAttempts) {
|
|
477
|
+
return Math.min(1e4, 1000 * 2 ** failedAttempts);
|
|
478
|
+
}
|
|
479
|
+
function retryAfterMs(value) {
|
|
480
|
+
const seconds = value === null ? Number.NaN : Number(value);
|
|
481
|
+
return Number.isFinite(seconds) && seconds >= 0 ? seconds * 1000 : undefined;
|
|
482
|
+
}
|
|
483
|
+
var active;
|
|
484
|
+
var shownRoute = null;
|
|
485
|
+
function startSixbActivityCapture() {
|
|
486
|
+
const attribution = takeActivityArrival();
|
|
487
|
+
active?.dispose();
|
|
488
|
+
active = new ActivityTracker({
|
|
489
|
+
attribution,
|
|
490
|
+
document: typeof document === "undefined" ? null : document,
|
|
491
|
+
load: async (signal) => (await getActivityCaptureConfig2({ signal, throwOnError: true })).data,
|
|
492
|
+
send: async (events, signal) => {
|
|
493
|
+
const { response } = await captureActivity2({ body: { events }, signal, keepalive: true });
|
|
494
|
+
if (!response.ok) {
|
|
495
|
+
throw new ActivityDeliveryError(response.status, retryAfterMs(response.headers.get("retry-after")));
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
active.page(shownRoute);
|
|
500
|
+
}
|
|
501
|
+
function recordSixbPageView(route) {
|
|
502
|
+
shownRoute = route;
|
|
503
|
+
active?.page(route);
|
|
504
|
+
}
|
|
505
|
+
function trackSixbEvent(name) {
|
|
506
|
+
active?.interaction(name);
|
|
507
|
+
}
|
|
508
|
+
function stopSixbActivityCapture() {
|
|
509
|
+
clearActivityArrival();
|
|
510
|
+
active?.dispose();
|
|
511
|
+
active = undefined;
|
|
512
|
+
}
|
|
21
513
|
// src/browser.ts
|
|
22
514
|
var SESSION_ACTIVITY_HEADER_NAME = "x-sixb-session-activity";
|
|
23
515
|
var SESSION_ACTIVITY_HEADER_VALUE = "1";
|
|
@@ -44,6 +536,7 @@ function readSixbBrowserRuntimeConfig(defaults = {}) {
|
|
|
44
536
|
}
|
|
45
537
|
function configureSixbBrowserClient(config, options = {}) {
|
|
46
538
|
activeBrowserController?.dispose();
|
|
539
|
+
prepareActivityArrival(config.api.baseUrl, "app");
|
|
47
540
|
let csrfToken = null;
|
|
48
541
|
let disposed = false;
|
|
49
542
|
let redirectStarted = false;
|
|
@@ -77,6 +570,7 @@ function configureSixbBrowserClient(config, options = {}) {
|
|
|
77
570
|
if (typeof window !== "undefined")
|
|
78
571
|
window.location.assign(url);
|
|
79
572
|
});
|
|
573
|
+
preserveSixbActivityArrival();
|
|
80
574
|
redirect(createSixbSignInUrl(config, currentUrl));
|
|
81
575
|
} catch {
|
|
82
576
|
redirectStarted = false;
|
|
@@ -94,6 +588,7 @@ function configureSixbBrowserClient(config, options = {}) {
|
|
|
94
588
|
if (disposed)
|
|
95
589
|
return;
|
|
96
590
|
disposed = true;
|
|
591
|
+
stopSixbActivityCapture();
|
|
97
592
|
csrfToken = null;
|
|
98
593
|
disposeActivity();
|
|
99
594
|
client2.interceptors.response.eject(authResponseInterceptorId);
|
|
@@ -109,6 +604,7 @@ function configureSixbBrowserClient(config, options = {}) {
|
|
|
109
604
|
function configureSixbSharedBrowserClient(config, options) {
|
|
110
605
|
activeBrowserController?.dispose();
|
|
111
606
|
assertSharedAccessGrantId(options.grantId);
|
|
607
|
+
prepareActivityArrival(config.api.baseUrl, `share:${options.grantId}`);
|
|
112
608
|
const previousConfig = client2.getConfig();
|
|
113
609
|
const previousSharedAuthority = getClientSharedGrantId(client2);
|
|
114
610
|
let csrfToken = null;
|
|
@@ -170,6 +666,7 @@ function configureSixbSharedBrowserClient(config, options) {
|
|
|
170
666
|
if (disposed)
|
|
171
667
|
return;
|
|
172
668
|
disposed = true;
|
|
669
|
+
stopSixbActivityCapture();
|
|
173
670
|
csrfToken = null;
|
|
174
671
|
disposeActivity();
|
|
175
672
|
client2.interceptors.response.eject(responseInterceptorId);
|
|
@@ -276,7 +773,7 @@ function isAuthRedirectExcludedRequest(config, request) {
|
|
|
276
773
|
const apiUrl = new URL(normalizeSixbApiBaseUrl2(config.api.baseUrl), requestUrl);
|
|
277
774
|
const apiPath = apiUrl.pathname.replace(/\/+$/, "");
|
|
278
775
|
const method = request.method.toUpperCase();
|
|
279
|
-
return requestUrl.origin === apiUrl.origin && (method === "GET" && requestUrl.pathname === `${apiPath}/api/auth/session` || method === "POST" && requestUrl.pathname === `${apiPath}/api/auth/sign-out`);
|
|
776
|
+
return requestUrl.origin === apiUrl.origin && (method === "GET" && requestUrl.pathname === `${apiPath}/api/auth/session` || method === "POST" && requestUrl.pathname === `${apiPath}/api/auth/sign-out` || method === "GET" && requestUrl.pathname === `${apiPath}/api/activity/capture-config` || method === "POST" && requestUrl.pathname === `${apiPath}/api/activity/events`);
|
|
280
777
|
}
|
|
281
778
|
function isSixbAuthPage(config, currentUrl) {
|
|
282
779
|
try {
|
|
@@ -300,6 +797,7 @@ async function requireSixbBrowserAuthSession(config, controller, options = {}) {
|
|
|
300
797
|
}
|
|
301
798
|
const returnTo = options.returnTo ?? window.location.href;
|
|
302
799
|
const redirect = options.redirect ?? ((url) => window.location.assign(url));
|
|
800
|
+
preserveSixbActivityArrival();
|
|
303
801
|
redirect(createSixbSignInUrl(config, returnTo));
|
|
304
802
|
return data;
|
|
305
803
|
}
|
|
@@ -314,9 +812,13 @@ export {
|
|
|
314
812
|
configureSixbSharedBrowserClient,
|
|
315
813
|
createSixbSignInUrl,
|
|
316
814
|
isSixbApiError2 as isSixbApiError,
|
|
815
|
+
preserveSixbActivityArrival,
|
|
317
816
|
readSixbBrowserRuntimeConfig,
|
|
817
|
+
recordSixbPageView,
|
|
318
818
|
renderSixbBrowserRuntimeScript,
|
|
319
|
-
requireSixbBrowserAuthSession
|
|
819
|
+
requireSixbBrowserAuthSession,
|
|
820
|
+
startSixbActivityCapture,
|
|
821
|
+
trackSixbEvent
|
|
320
822
|
};
|
|
321
823
|
|
|
322
|
-
//# debugId=
|
|
824
|
+
//# debugId=0F17B9B7FABC47AA64756E2164756E21
|