@disconetwork/core 0.0.6 → 0.0.7

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/index.js CHANGED
@@ -1,11 +1,642 @@
1
1
  "use client";
2
- import { a as DiscoApiError, c as DiscoValidationError, d as zRecommendationsBody, f as zRecommendationsResponse2, l as isAbortError, n as transformRequest, o as DiscoError, r as transformResponse, s as DiscoNetworkError, t as TrackingManager, u as envFromApiKey } from "./TrackingManager-_IENEPuL.js";
2
+ import { a as DiscoError, c as isAbortError, d as zRecommendationsResponse2, i as DiscoApiError, l as envFromApiKey, n as transformResponse, o as DiscoNetworkError, s as DiscoValidationError, t as transformRequest, u as zRecommendationsBody } from "./recommendationsTransforms-BDrxhOzv.js";
3
3
  import * as z from "zod/v4";
4
4
  import { ZodError } from "zod/v4";
5
5
  //#region src/api/generated/recommendations/core/bodySerializer.gen.ts
6
+ const jsonBodySerializer$1 = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
7
+ //#endregion
8
+ //#region src/api/generated/recommendations/core/serverSentEvents.gen.ts
9
+ function createSseClient$1({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) {
10
+ let lastEventId;
11
+ const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
12
+ const createStream = async function* () {
13
+ let retryDelay = sseDefaultRetryDelay ?? 3e3;
14
+ let attempt = 0;
15
+ const signal = options.signal ?? new AbortController().signal;
16
+ while (true) {
17
+ if (signal.aborted) break;
18
+ attempt++;
19
+ const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
20
+ if (lastEventId !== void 0) headers.set("Last-Event-ID", lastEventId);
21
+ try {
22
+ const requestInit = {
23
+ redirect: "follow",
24
+ ...options,
25
+ body: options.serializedBody,
26
+ headers,
27
+ signal
28
+ };
29
+ let request = new Request(url, requestInit);
30
+ if (onRequest) request = await onRequest(url, requestInit);
31
+ const response = await (options.fetch ?? globalThis.fetch)(request);
32
+ if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
33
+ if (!response.body) throw new Error("No body in SSE response");
34
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
35
+ let buffer = "";
36
+ const abortHandler = () => {
37
+ try {
38
+ reader.cancel();
39
+ } catch {}
40
+ };
41
+ signal.addEventListener("abort", abortHandler);
42
+ try {
43
+ while (true) {
44
+ const { done, value } = await reader.read();
45
+ if (done) break;
46
+ buffer += value;
47
+ buffer = buffer.replace(/\r\n?/g, "\n");
48
+ const chunks = buffer.split("\n\n");
49
+ buffer = chunks.pop() ?? "";
50
+ for (const chunk of chunks) {
51
+ const lines = chunk.split("\n");
52
+ const dataLines = [];
53
+ let eventName;
54
+ for (const line of lines) if (line.startsWith("data:")) dataLines.push(line.replace(/^data:\s*/, ""));
55
+ else if (line.startsWith("event:")) eventName = line.replace(/^event:\s*/, "");
56
+ else if (line.startsWith("id:")) lastEventId = line.replace(/^id:\s*/, "");
57
+ else if (line.startsWith("retry:")) {
58
+ const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
59
+ if (!Number.isNaN(parsed)) retryDelay = parsed;
60
+ }
61
+ let data;
62
+ let parsedJson = false;
63
+ if (dataLines.length) {
64
+ const rawData = dataLines.join("\n");
65
+ try {
66
+ data = JSON.parse(rawData);
67
+ parsedJson = true;
68
+ } catch {
69
+ data = rawData;
70
+ }
71
+ }
72
+ if (parsedJson) {
73
+ if (responseValidator) await responseValidator(data);
74
+ if (responseTransformer) data = await responseTransformer(data);
75
+ }
76
+ onSseEvent?.({
77
+ data,
78
+ event: eventName,
79
+ id: lastEventId,
80
+ retry: retryDelay
81
+ });
82
+ if (dataLines.length) yield data;
83
+ }
84
+ }
85
+ } finally {
86
+ signal.removeEventListener("abort", abortHandler);
87
+ reader.releaseLock();
88
+ }
89
+ break;
90
+ } catch (error) {
91
+ onSseError?.(error);
92
+ if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) break;
93
+ await sleep(Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4));
94
+ }
95
+ }
96
+ };
97
+ return { stream: createStream() };
98
+ }
99
+ //#endregion
100
+ //#region src/api/generated/recommendations/core/pathSerializer.gen.ts
101
+ const separatorArrayExplode$1 = (style) => {
102
+ switch (style) {
103
+ case "label": return ".";
104
+ case "matrix": return ";";
105
+ case "simple": return ",";
106
+ default: return "&";
107
+ }
108
+ };
109
+ const separatorArrayNoExplode$1 = (style) => {
110
+ switch (style) {
111
+ case "form": return ",";
112
+ case "pipeDelimited": return "|";
113
+ case "spaceDelimited": return "%20";
114
+ default: return ",";
115
+ }
116
+ };
117
+ const separatorObjectExplode$1 = (style) => {
118
+ switch (style) {
119
+ case "label": return ".";
120
+ case "matrix": return ";";
121
+ case "simple": return ",";
122
+ default: return "&";
123
+ }
124
+ };
125
+ const serializeArrayParam$1 = ({ allowReserved, explode, name, style, value }) => {
126
+ if (!explode) {
127
+ const joinedValues = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode$1(style));
128
+ switch (style) {
129
+ case "label": return `.${joinedValues}`;
130
+ case "matrix": return `;${name}=${joinedValues}`;
131
+ case "simple": return joinedValues;
132
+ default: return `${name}=${joinedValues}`;
133
+ }
134
+ }
135
+ const separator = separatorArrayExplode$1(style);
136
+ const joinedValues = value.map((v) => {
137
+ if (style === "label" || style === "simple") return allowReserved ? v : encodeURIComponent(v);
138
+ return serializePrimitiveParam$1({
139
+ allowReserved,
140
+ name,
141
+ value: v
142
+ });
143
+ }).join(separator);
144
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
145
+ };
146
+ const serializePrimitiveParam$1 = ({ allowReserved, name, value }) => {
147
+ if (value === void 0 || value === null) return "";
148
+ if (typeof value === "object") throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
149
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
150
+ };
151
+ const serializeObjectParam$1 = ({ allowReserved, explode, name, style, value, valueOnly }) => {
152
+ if (value instanceof Date) return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
153
+ if (style !== "deepObject" && !explode) {
154
+ let values = [];
155
+ Object.entries(value).forEach(([key, v]) => {
156
+ values = [
157
+ ...values,
158
+ key,
159
+ allowReserved ? v : encodeURIComponent(v)
160
+ ];
161
+ });
162
+ const joinedValues = values.join(",");
163
+ switch (style) {
164
+ case "form": return `${name}=${joinedValues}`;
165
+ case "label": return `.${joinedValues}`;
166
+ case "matrix": return `;${name}=${joinedValues}`;
167
+ default: return joinedValues;
168
+ }
169
+ }
170
+ const separator = separatorObjectExplode$1(style);
171
+ const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam$1({
172
+ allowReserved,
173
+ name: style === "deepObject" ? `${name}[${key}]` : key,
174
+ value: v
175
+ })).join(separator);
176
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
177
+ };
178
+ //#endregion
179
+ //#region src/api/generated/recommendations/core/utils.gen.ts
180
+ const PATH_PARAM_RE$1 = /\{[^{}]+\}/g;
181
+ const defaultPathSerializer$1 = ({ path, url: _url }) => {
182
+ let url = _url;
183
+ const matches = _url.match(PATH_PARAM_RE$1);
184
+ if (matches) for (const match of matches) {
185
+ let explode = false;
186
+ let name = match.substring(1, match.length - 1);
187
+ let style = "simple";
188
+ if (name.endsWith("*")) {
189
+ explode = true;
190
+ name = name.substring(0, name.length - 1);
191
+ }
192
+ if (name.startsWith(".")) {
193
+ name = name.substring(1);
194
+ style = "label";
195
+ } else if (name.startsWith(";")) {
196
+ name = name.substring(1);
197
+ style = "matrix";
198
+ }
199
+ const value = path[name];
200
+ if (value === void 0 || value === null) continue;
201
+ if (Array.isArray(value)) {
202
+ url = url.replace(match, serializeArrayParam$1({
203
+ explode,
204
+ name,
205
+ style,
206
+ value
207
+ }));
208
+ continue;
209
+ }
210
+ if (typeof value === "object") {
211
+ url = url.replace(match, serializeObjectParam$1({
212
+ explode,
213
+ name,
214
+ style,
215
+ value,
216
+ valueOnly: true
217
+ }));
218
+ continue;
219
+ }
220
+ if (style === "matrix") {
221
+ url = url.replace(match, `;${serializePrimitiveParam$1({
222
+ name,
223
+ value
224
+ })}`);
225
+ continue;
226
+ }
227
+ const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
228
+ url = url.replace(match, replaceValue);
229
+ }
230
+ return url;
231
+ };
232
+ const getUrl$1 = ({ baseUrl, path, query, querySerializer, url: _url }) => {
233
+ const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
234
+ let url = (baseUrl ?? "") + pathUrl;
235
+ if (path) url = defaultPathSerializer$1({
236
+ path,
237
+ url
238
+ });
239
+ let search = query ? querySerializer(query) : "";
240
+ if (search.startsWith("?")) search = search.substring(1);
241
+ if (search) url += `?${search}`;
242
+ return url;
243
+ };
244
+ function getValidRequestBody$1(options) {
245
+ const hasBody = options.body !== void 0;
246
+ if (hasBody && options.bodySerializer) {
247
+ if ("serializedBody" in options) return options.serializedBody !== void 0 && options.serializedBody !== "" ? options.serializedBody : null;
248
+ return options.body !== "" ? options.body : null;
249
+ }
250
+ if (hasBody) return options.body;
251
+ }
252
+ //#endregion
253
+ //#region src/api/generated/recommendations/core/auth.gen.ts
254
+ const getAuthToken$1 = async (auth, callback) => {
255
+ const token = typeof callback === "function" ? await callback(auth) : callback;
256
+ if (!token) return;
257
+ if (auth.scheme === "bearer") return `Bearer ${token}`;
258
+ if (auth.scheme === "basic") return `Basic ${btoa(token)}`;
259
+ return token;
260
+ };
261
+ //#endregion
262
+ //#region src/api/generated/recommendations/client/utils.gen.ts
263
+ const createQuerySerializer$1 = ({ parameters = {}, ...args } = {}) => {
264
+ const querySerializer = (queryParams) => {
265
+ const search = [];
266
+ if (queryParams && typeof queryParams === "object") for (const name in queryParams) {
267
+ const value = queryParams[name];
268
+ if (value === void 0 || value === null) continue;
269
+ const options = parameters[name] || args;
270
+ if (Array.isArray(value)) {
271
+ const serializedArray = serializeArrayParam$1({
272
+ allowReserved: options.allowReserved,
273
+ explode: true,
274
+ name,
275
+ style: "form",
276
+ value,
277
+ ...options.array
278
+ });
279
+ if (serializedArray) search.push(serializedArray);
280
+ } else if (typeof value === "object") {
281
+ const serializedObject = serializeObjectParam$1({
282
+ allowReserved: options.allowReserved,
283
+ explode: true,
284
+ name,
285
+ style: "deepObject",
286
+ value,
287
+ ...options.object
288
+ });
289
+ if (serializedObject) search.push(serializedObject);
290
+ } else {
291
+ const serializedPrimitive = serializePrimitiveParam$1({
292
+ allowReserved: options.allowReserved,
293
+ name,
294
+ value
295
+ });
296
+ if (serializedPrimitive) search.push(serializedPrimitive);
297
+ }
298
+ }
299
+ return search.join("&");
300
+ };
301
+ return querySerializer;
302
+ };
303
+ /**
304
+ * Infers parseAs value from provided Content-Type header.
305
+ */
306
+ const getParseAs$1 = (contentType) => {
307
+ if (!contentType) return "stream";
308
+ const cleanContent = contentType.split(";")[0]?.trim();
309
+ if (!cleanContent) return;
310
+ if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) return "json";
311
+ if (cleanContent === "multipart/form-data") return "formData";
312
+ if ([
313
+ "application/",
314
+ "audio/",
315
+ "image/",
316
+ "video/"
317
+ ].some((type) => cleanContent.startsWith(type))) return "blob";
318
+ if (cleanContent.startsWith("text/")) return "text";
319
+ };
320
+ const checkForExistence$1 = (options, name) => {
321
+ if (!name) return false;
322
+ if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) return true;
323
+ return false;
324
+ };
325
+ async function setAuthParams$1(options) {
326
+ for (const auth of options.security ?? []) {
327
+ if (checkForExistence$1(options, auth.name)) continue;
328
+ const token = await getAuthToken$1(auth, options.auth);
329
+ if (!token) continue;
330
+ const name = auth.name ?? "Authorization";
331
+ switch (auth.in) {
332
+ case "query":
333
+ if (!options.query) options.query = {};
334
+ options.query[name] = token;
335
+ break;
336
+ case "cookie":
337
+ options.headers.append("Cookie", `${name}=${token}`);
338
+ break;
339
+ default:
340
+ options.headers.set(name, token);
341
+ break;
342
+ }
343
+ }
344
+ }
345
+ const buildUrl$1 = (options) => getUrl$1({
346
+ baseUrl: options.baseUrl,
347
+ path: options.path,
348
+ query: options.query,
349
+ querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer$1(options.querySerializer),
350
+ url: options.url
351
+ });
352
+ const mergeConfigs$1 = (a, b) => {
353
+ const config = {
354
+ ...a,
355
+ ...b
356
+ };
357
+ if (config.baseUrl?.endsWith("/")) config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
358
+ config.headers = mergeHeaders$1(a.headers, b.headers);
359
+ return config;
360
+ };
361
+ const headersEntries$1 = (headers) => {
362
+ const entries = [];
363
+ headers.forEach((value, key) => {
364
+ entries.push([key, value]);
365
+ });
366
+ return entries;
367
+ };
368
+ const mergeHeaders$1 = (...headers) => {
369
+ const mergedHeaders = new Headers();
370
+ for (const header of headers) {
371
+ if (!header) continue;
372
+ const iterator = header instanceof Headers ? headersEntries$1(header) : Object.entries(header);
373
+ for (const [key, value] of iterator) if (value === null) mergedHeaders.delete(key);
374
+ else if (Array.isArray(value)) for (const v of value) mergedHeaders.append(key, v);
375
+ else if (value !== void 0) mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
376
+ }
377
+ return mergedHeaders;
378
+ };
379
+ var Interceptors$1 = class {
380
+ fns = [];
381
+ clear() {
382
+ this.fns = [];
383
+ }
384
+ eject(id) {
385
+ const index = this.getInterceptorIndex(id);
386
+ if (this.fns[index]) this.fns[index] = null;
387
+ }
388
+ exists(id) {
389
+ const index = this.getInterceptorIndex(id);
390
+ return Boolean(this.fns[index]);
391
+ }
392
+ getInterceptorIndex(id) {
393
+ if (typeof id === "number") return this.fns[id] ? id : -1;
394
+ return this.fns.indexOf(id);
395
+ }
396
+ update(id, fn) {
397
+ const index = this.getInterceptorIndex(id);
398
+ if (this.fns[index]) {
399
+ this.fns[index] = fn;
400
+ return id;
401
+ }
402
+ return false;
403
+ }
404
+ use(fn) {
405
+ this.fns.push(fn);
406
+ return this.fns.length - 1;
407
+ }
408
+ };
409
+ const createInterceptors$1 = () => ({
410
+ error: new Interceptors$1(),
411
+ request: new Interceptors$1(),
412
+ response: new Interceptors$1()
413
+ });
414
+ const defaultQuerySerializer$1 = createQuerySerializer$1({
415
+ allowReserved: false,
416
+ array: {
417
+ explode: true,
418
+ style: "form"
419
+ },
420
+ object: {
421
+ explode: true,
422
+ style: "deepObject"
423
+ }
424
+ });
425
+ const defaultHeaders$1 = { "Content-Type": "application/json" };
426
+ const createConfig$1 = (override = {}) => ({
427
+ ...jsonBodySerializer$1,
428
+ headers: defaultHeaders$1,
429
+ parseAs: "auto",
430
+ querySerializer: defaultQuerySerializer$1,
431
+ ...override
432
+ });
433
+ //#endregion
434
+ //#region src/api/generated/recommendations/client/client.gen.ts
435
+ const createClient$1 = (config = {}) => {
436
+ let _config = mergeConfigs$1(createConfig$1(), config);
437
+ const getConfig = () => ({ ..._config });
438
+ const setConfig = (config) => {
439
+ _config = mergeConfigs$1(_config, config);
440
+ return getConfig();
441
+ };
442
+ const interceptors = createInterceptors$1();
443
+ const beforeRequest = async (options) => {
444
+ const opts = {
445
+ ..._config,
446
+ ...options,
447
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
448
+ headers: mergeHeaders$1(_config.headers, options.headers),
449
+ serializedBody: void 0
450
+ };
451
+ if (opts.security) await setAuthParams$1(opts);
452
+ if (opts.requestValidator) await opts.requestValidator(opts);
453
+ if (opts.body !== void 0 && opts.bodySerializer) opts.serializedBody = opts.bodySerializer(opts.body);
454
+ if (opts.body === void 0 || opts.serializedBody === "") opts.headers.delete("Content-Type");
455
+ const resolvedOpts = opts;
456
+ return {
457
+ opts: resolvedOpts,
458
+ url: buildUrl$1(resolvedOpts)
459
+ };
460
+ };
461
+ const request = async (options) => {
462
+ const throwOnError = options.throwOnError ?? _config.throwOnError;
463
+ const responseStyle = options.responseStyle ?? _config.responseStyle;
464
+ let request;
465
+ let response;
466
+ try {
467
+ const { opts, url } = await beforeRequest(options);
468
+ const requestInit = {
469
+ redirect: "follow",
470
+ ...opts,
471
+ body: getValidRequestBody$1(opts)
472
+ };
473
+ request = new Request(url, requestInit);
474
+ for (const fn of interceptors.request.fns) if (fn) request = await fn(request, opts);
475
+ const _fetch = opts.fetch;
476
+ response = await _fetch(request);
477
+ for (const fn of interceptors.response.fns) if (fn) response = await fn(response, request, opts);
478
+ const result = {
479
+ request,
480
+ response
481
+ };
482
+ if (response.ok) {
483
+ const parseAs = (opts.parseAs === "auto" ? getParseAs$1(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
484
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
485
+ let emptyData;
486
+ switch (parseAs) {
487
+ case "arrayBuffer":
488
+ case "blob":
489
+ case "text":
490
+ emptyData = await response[parseAs]();
491
+ break;
492
+ case "formData":
493
+ emptyData = new FormData();
494
+ break;
495
+ case "stream":
496
+ emptyData = response.body;
497
+ break;
498
+ default:
499
+ emptyData = {};
500
+ break;
501
+ }
502
+ return opts.responseStyle === "data" ? emptyData : {
503
+ data: emptyData,
504
+ ...result
505
+ };
506
+ }
507
+ let data;
508
+ switch (parseAs) {
509
+ case "arrayBuffer":
510
+ case "blob":
511
+ case "formData":
512
+ case "text":
513
+ data = await response[parseAs]();
514
+ break;
515
+ case "json": {
516
+ const text = await response.text();
517
+ data = text ? JSON.parse(text) : {};
518
+ break;
519
+ }
520
+ case "stream": return opts.responseStyle === "data" ? response.body : {
521
+ data: response.body,
522
+ ...result
523
+ };
524
+ }
525
+ if (parseAs === "json") {
526
+ if (opts.responseValidator) await opts.responseValidator(data);
527
+ if (opts.responseTransformer) data = await opts.responseTransformer(data);
528
+ }
529
+ return opts.responseStyle === "data" ? data : {
530
+ data,
531
+ ...result
532
+ };
533
+ }
534
+ const textError = await response.text();
535
+ let jsonError;
536
+ try {
537
+ jsonError = JSON.parse(textError);
538
+ } catch {}
539
+ throw jsonError ?? textError;
540
+ } catch (error) {
541
+ let finalError = error;
542
+ for (const fn of interceptors.error.fns) if (fn) finalError = await fn(finalError, response, request, options);
543
+ finalError = finalError || {};
544
+ if (throwOnError) throw finalError;
545
+ return responseStyle === "data" ? void 0 : {
546
+ error: finalError,
547
+ request,
548
+ response
549
+ };
550
+ }
551
+ };
552
+ const makeMethodFn = (method) => (options) => request({
553
+ ...options,
554
+ method
555
+ });
556
+ const makeSseFn = (method) => async (options) => {
557
+ const { opts, url } = await beforeRequest(options);
558
+ return createSseClient$1({
559
+ ...opts,
560
+ body: opts.body,
561
+ method,
562
+ onRequest: async (url, init) => {
563
+ let request = new Request(url, init);
564
+ for (const fn of interceptors.request.fns) if (fn) request = await fn(request, opts);
565
+ return request;
566
+ },
567
+ serializedBody: getValidRequestBody$1(opts),
568
+ url
569
+ });
570
+ };
571
+ const _buildUrl = (options) => buildUrl$1({
572
+ ..._config,
573
+ ...options
574
+ });
575
+ return {
576
+ buildUrl: _buildUrl,
577
+ connect: makeMethodFn("CONNECT"),
578
+ delete: makeMethodFn("DELETE"),
579
+ get: makeMethodFn("GET"),
580
+ getConfig,
581
+ head: makeMethodFn("HEAD"),
582
+ interceptors,
583
+ options: makeMethodFn("OPTIONS"),
584
+ patch: makeMethodFn("PATCH"),
585
+ post: makeMethodFn("POST"),
586
+ put: makeMethodFn("PUT"),
587
+ request,
588
+ setConfig,
589
+ sse: {
590
+ connect: makeSseFn("CONNECT"),
591
+ delete: makeSseFn("DELETE"),
592
+ get: makeSseFn("GET"),
593
+ head: makeSseFn("HEAD"),
594
+ options: makeSseFn("OPTIONS"),
595
+ patch: makeSseFn("PATCH"),
596
+ post: makeSseFn("POST"),
597
+ put: makeSseFn("PUT"),
598
+ trace: makeSseFn("TRACE")
599
+ },
600
+ trace: makeMethodFn("TRACE")
601
+ };
602
+ };
603
+ //#endregion
604
+ //#region src/api/generated/recommendations/client.gen.ts
605
+ const client$1 = createClient$1(createConfig$1());
606
+ //#endregion
607
+ //#region src/api/generated/recommendations/sdk.gen.ts
608
+ /**
609
+ * Recommendations
610
+ *
611
+ * Unified recommendations endpoint.
612
+ *
613
+ * Accepts scoped PUBLIC keys (PUBLISHER or PUBLISHER_CHANNEL link level) and
614
+ * legacy partner API keys. The controller operates in channel mode when the
615
+ * auth context wraps a CmosPublisherContext, direct mode otherwise.
616
+ */
617
+ const recommendations = (options) => (options.client ?? client$1).post({
618
+ requestValidator: async (data) => await z.object({
619
+ body: zRecommendationsBody,
620
+ path: z.never().optional(),
621
+ query: z.never().optional()
622
+ }).parseAsync(data),
623
+ responseValidator: async (data) => await zRecommendationsResponse2.parseAsync(data),
624
+ security: [{
625
+ name: "x-api-key",
626
+ type: "apiKey"
627
+ }],
628
+ url: "/recommendations",
629
+ ...options,
630
+ headers: {
631
+ "Content-Type": "application/json",
632
+ ...options.headers
633
+ }
634
+ });
635
+ //#endregion
636
+ //#region src/api/generated/events/core/bodySerializer.gen.ts
6
637
  const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
7
638
  //#endregion
8
- //#region src/api/generated/recommendations/core/serverSentEvents.gen.ts
639
+ //#region src/api/generated/events/core/serverSentEvents.gen.ts
9
640
  function createSseClient({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) {
10
641
  let lastEventId;
11
642
  const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
@@ -97,7 +728,7 @@ function createSseClient({ onRequest, onSseError, onSseEvent, responseTransforme
97
728
  return { stream: createStream() };
98
729
  }
99
730
  //#endregion
100
- //#region src/api/generated/recommendations/core/pathSerializer.gen.ts
731
+ //#region src/api/generated/events/core/pathSerializer.gen.ts
101
732
  const separatorArrayExplode = (style) => {
102
733
  switch (style) {
103
734
  case "label": return ".";
@@ -176,7 +807,7 @@ const serializeObjectParam = ({ allowReserved, explode, name, style, value, valu
176
807
  return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
177
808
  };
178
809
  //#endregion
179
- //#region src/api/generated/recommendations/core/utils.gen.ts
810
+ //#region src/api/generated/events/core/utils.gen.ts
180
811
  const PATH_PARAM_RE = /\{[^{}]+\}/g;
181
812
  const defaultPathSerializer = ({ path, url: _url }) => {
182
813
  let url = _url;
@@ -250,7 +881,7 @@ function getValidRequestBody(options) {
250
881
  if (hasBody) return options.body;
251
882
  }
252
883
  //#endregion
253
- //#region src/api/generated/recommendations/core/auth.gen.ts
884
+ //#region src/api/generated/events/core/auth.gen.ts
254
885
  const getAuthToken = async (auth, callback) => {
255
886
  const token = typeof callback === "function" ? await callback(auth) : callback;
256
887
  if (!token) return;
@@ -259,7 +890,7 @@ const getAuthToken = async (auth, callback) => {
259
890
  return token;
260
891
  };
261
892
  //#endregion
262
- //#region src/api/generated/recommendations/client/utils.gen.ts
893
+ //#region src/api/generated/events/client/utils.gen.ts
263
894
  const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
264
895
  const querySerializer = (queryParams) => {
265
896
  const search = [];
@@ -431,7 +1062,7 @@ const createConfig = (override = {}) => ({
431
1062
  ...override
432
1063
  });
433
1064
  //#endregion
434
- //#region src/api/generated/recommendations/client/client.gen.ts
1065
+ //#region src/api/generated/events/client/client.gen.ts
435
1066
  const createClient = (config = {}) => {
436
1067
  let _config = mergeConfigs(createConfig(), config);
437
1068
  const getConfig = () => ({ ..._config });
@@ -601,38 +1232,6 @@ const createClient = (config = {}) => {
601
1232
  };
602
1233
  };
603
1234
  //#endregion
604
- //#region src/api/generated/recommendations/client.gen.ts
605
- const client = createClient(createConfig());
606
- //#endregion
607
- //#region src/api/generated/recommendations/sdk.gen.ts
608
- /**
609
- * Recommendations
610
- *
611
- * Unified recommendations endpoint.
612
- *
613
- * Accepts scoped PUBLIC keys (PUBLISHER or PUBLISHER_CHANNEL link level) and
614
- * legacy partner API keys. The controller operates in channel mode when the
615
- * auth context wraps a CmosPublisherContext, direct mode otherwise.
616
- */
617
- const recommendations = (options) => (options.client ?? client).post({
618
- requestValidator: async (data) => await z.object({
619
- body: zRecommendationsBody,
620
- path: z.never().optional(),
621
- query: z.never().optional()
622
- }).parseAsync(data),
623
- responseValidator: async (data) => await zRecommendationsResponse2.parseAsync(data),
624
- security: [{
625
- name: "x-api-key",
626
- type: "apiKey"
627
- }],
628
- url: "/recommendations",
629
- ...options,
630
- headers: {
631
- "Content-Type": "application/json",
632
- ...options.headers
633
- }
634
- });
635
- //#endregion
636
1235
  //#region src/api/index.ts
637
1236
  /**
638
1237
  * Build a dedicated, per-instance recommendations transport client from an
@@ -641,6 +1240,9 @@ const recommendations = (options) => (options.client ?? client).post({
641
1240
  * caller's responsibility (see `env.ts` / `config.ts`), so there is a single
642
1241
  * owner of key → env → config resolution rather than one per client.
643
1242
  *
1243
+ * Pass the **gateway root** as `baseUrl` — the SDK appends the operation path
1244
+ * (`/recommendations`), so it must not be included.
1245
+ *
644
1246
  * Pass the returned client to the generated `recommendations()` SDK function
645
1247
  * via its `client` option, e.g.:
646
1248
  *
@@ -657,6 +1259,26 @@ const recommendations = (options) => (options.client ?? client).post({
657
1259
  * each key's base URL and auth isolated, so multiple clients can coexist.
658
1260
  */
659
1261
  function createRecommendationsClient(config) {
1262
+ return createClient$1(createConfig$1({
1263
+ baseUrl: config.baseUrl,
1264
+ headers: config.headers,
1265
+ ...config.fetch ? { fetch: config.fetch } : {}
1266
+ }));
1267
+ }
1268
+ /**
1269
+ * Build a per-instance events transport client for the generated events SDK,
1270
+ * mirroring {@link createRecommendationsClient}. Pure transport: callers own
1271
+ * env → URL/header resolution (see `config.ts` / `env.ts`).
1272
+ *
1273
+ * Unlike recommendations, the events SDK posts to `/`, so pass the **full events
1274
+ * URL** as `baseUrl` (e.g. `${GATEWAY_BASE_URL[env]}/events`), not the gateway
1275
+ * origin. The SDK reuses an `x-api-key` header from `headers` for its declared
1276
+ * security rather than re-deriving a token.
1277
+ *
1278
+ * Pass the returned client to the generated `eventsPost()` via its `client`
1279
+ * option (this is what `DiscoClient.createTrackingManager` does internally).
1280
+ */
1281
+ function createEventsClient(config) {
660
1282
  return createClient(createConfig({
661
1283
  baseUrl: config.baseUrl,
662
1284
  headers: config.headers,
@@ -664,6 +1286,227 @@ function createRecommendationsClient(config) {
664
1286
  }));
665
1287
  }
666
1288
  //#endregion
1289
+ //#region src/api/generated/events/client.gen.ts
1290
+ const client = createClient(createConfig());
1291
+ //#endregion
1292
+ //#region src/api/generated/events/zod.gen.ts
1293
+ /**
1294
+ * AdvertiserEventProperties
1295
+ */
1296
+ const zAdvertiserEventProperties = z.object({
1297
+ email: z.string().nullish(),
1298
+ email_hash: z.string().nullish(),
1299
+ click_id: z.string().nullish(),
1300
+ custom_metadata: z.record(z.string(), z.unknown()).nullish()
1301
+ });
1302
+ z.object({
1303
+ event_name: z.string(),
1304
+ account_id: z.uuid(),
1305
+ event_datetime: z.iso.datetime().nullish(),
1306
+ event_properties: zAdvertiserEventProperties
1307
+ });
1308
+ /**
1309
+ * BrandClickInitiatingTarget
1310
+ */
1311
+ const zBrandClickInitiatingTarget = z.enum([
1312
+ "INLINE_ACTION_BUTTON",
1313
+ "INLINE_ASSET_TILE",
1314
+ "SCROLLABLE_SLOT_TILE"
1315
+ ]);
1316
+ /**
1317
+ * BrandDisplayInitiatingTarget
1318
+ */
1319
+ const zBrandDisplayInitiatingTarget = z.enum(["INLINE_SLOT", "SCROLLABLE_SLOT"]);
1320
+ /**
1321
+ * BrandEventProperties
1322
+ */
1323
+ const zBrandEventProperties = z.object({
1324
+ offer_id: z.uuid(),
1325
+ advertiser_id: z.uuid(),
1326
+ insertion_id: z.string()
1327
+ });
1328
+ /**
1329
+ * DisplayMode
1330
+ */
1331
+ const zDisplayMode = z.enum([
1332
+ "OVERLAY",
1333
+ "FULLSCREEN",
1334
+ "PULLUP",
1335
+ "INLINE"
1336
+ ]);
1337
+ /**
1338
+ * ElementClickInitiatingTarget
1339
+ */
1340
+ const zElementClickInitiatingTarget = z.enum([
1341
+ "INLINE_NAV_FORWARD",
1342
+ "INLINE_NAV_BACKWARD",
1343
+ "EXPLICIT_NAV_FORWARD",
1344
+ "EXPLICIT_NAV_BACKWARD",
1345
+ "INLINE_FOOTER_DISCO",
1346
+ "INLINE_FOOTER_PRIVACY",
1347
+ "CLOSE_BUTTON",
1348
+ "CLOSE_BACKDROP",
1349
+ "OPEN_OVERLAY"
1350
+ ]);
1351
+ /**
1352
+ * LogLevel
1353
+ */
1354
+ const zLogLevel = z.enum(["ERROR", "WARNING"]);
1355
+ /**
1356
+ * LogSource
1357
+ */
1358
+ const zLogSource = z.enum(["IOS_SDK", "ANDROID_SDK"]);
1359
+ z.object({
1360
+ level: zLogLevel,
1361
+ message: z.string(),
1362
+ context: z.record(z.string(), z.unknown()).nullish(),
1363
+ source: zLogSource
1364
+ });
1365
+ /**
1366
+ * ProductDisplayInitiatingTarget
1367
+ */
1368
+ const zProductDisplayInitiatingTarget = z.enum(["INLINE_TILE"]);
1369
+ /**
1370
+ * ProductProperties
1371
+ */
1372
+ const zProductProperties = z.object({ product_id: z.string() });
1373
+ /**
1374
+ * ValidationError
1375
+ */
1376
+ const zValidationError = z.object({
1377
+ loc: z.array(z.union([z.string(), z.int()])),
1378
+ msg: z.string(),
1379
+ type: z.string()
1380
+ });
1381
+ z.object({ detail: z.array(zValidationError).optional() });
1382
+ /**
1383
+ * View
1384
+ */
1385
+ const zView = z.enum([
1386
+ "ORDER_STATUS",
1387
+ "CHECKOUT",
1388
+ "THANK_YOU",
1389
+ "POST_ORDER",
1390
+ "ORDER_TRACKING",
1391
+ "SUPPORT_CENTER"
1392
+ ]);
1393
+ /**
1394
+ * PlacementDetailsOptional
1395
+ */
1396
+ const zPlacementDetailsOptional = z.object({
1397
+ display_mode: zDisplayMode.nullish(),
1398
+ layout_id: z.string().nullish(),
1399
+ view: zView.nullish()
1400
+ });
1401
+ /**
1402
+ * BrandClickRequest
1403
+ */
1404
+ const zBrandClickRequest = z.object({
1405
+ brand_properties: zBrandEventProperties,
1406
+ event_name: z.literal("BRAND_CLICK"),
1407
+ event_datetime: z.iso.datetime(),
1408
+ session_id: z.uuid(),
1409
+ placement_details: zPlacementDetailsOptional.nullish(),
1410
+ initiating_target: zBrandClickInitiatingTarget,
1411
+ asset_id: z.string().nullish()
1412
+ });
1413
+ /**
1414
+ * BrandDisplayRequest
1415
+ */
1416
+ const zBrandDisplayRequest = z.object({
1417
+ brand_properties: zBrandEventProperties,
1418
+ event_name: z.enum(["BRAND_DISPLAY", "BRAND_VIEW"]),
1419
+ event_datetime: z.iso.datetime(),
1420
+ session_id: z.uuid(),
1421
+ placement_details: zPlacementDetailsOptional.nullish(),
1422
+ initiating_target: zBrandDisplayInitiatingTarget
1423
+ });
1424
+ /**
1425
+ * ElementClickRequest
1426
+ */
1427
+ const zElementClickRequest = z.object({
1428
+ event_name: z.literal("ELEMENT_CLICK"),
1429
+ event_datetime: z.iso.datetime(),
1430
+ session_id: z.uuid(),
1431
+ placement_details: zPlacementDetailsOptional.nullish(),
1432
+ initiating_target: zElementClickInitiatingTarget,
1433
+ brand_properties: zBrandEventProperties.nullish()
1434
+ });
1435
+ /**
1436
+ * ProductClickRequest
1437
+ */
1438
+ const zProductClickRequest = z.object({
1439
+ product_properties: zProductProperties,
1440
+ brand_properties: zBrandEventProperties,
1441
+ event_name: z.literal("PRODUCT_CLICK"),
1442
+ event_datetime: z.iso.datetime(),
1443
+ session_id: z.uuid(),
1444
+ placement_details: zPlacementDetailsOptional.nullish(),
1445
+ initiating_target: zProductDisplayInitiatingTarget
1446
+ });
1447
+ /**
1448
+ * ProductDisplayRequest
1449
+ */
1450
+ const zProductDisplayRequest = z.object({
1451
+ product_properties: zProductProperties,
1452
+ brand_properties: zBrandEventProperties,
1453
+ event_name: z.enum(["PRODUCT_DISPLAY", "PRODUCT_VIEW"]),
1454
+ event_datetime: z.iso.datetime(),
1455
+ session_id: z.uuid(),
1456
+ placement_details: zPlacementDetailsOptional.nullish(),
1457
+ initiating_target: zProductDisplayInitiatingTarget
1458
+ });
1459
+ /**
1460
+ * WidgetEventRequest
1461
+ */
1462
+ const zWidgetEventRequest = z.object({
1463
+ event_name: z.enum([
1464
+ "WIDGET_LOAD",
1465
+ "WIDGET_DISPLAY",
1466
+ "WIDGET_VIEW"
1467
+ ]),
1468
+ event_datetime: z.iso.datetime(),
1469
+ session_id: z.uuid(),
1470
+ placement_details: zPlacementDetailsOptional.nullish()
1471
+ });
1472
+ const zEventsPostBody = z.union([
1473
+ z.object({ event_name: z.union([
1474
+ z.literal("WIDGET_DISPLAY"),
1475
+ z.literal("WIDGET_LOAD"),
1476
+ z.literal("WIDGET_VIEW")
1477
+ ]) }).and(zWidgetEventRequest),
1478
+ z.object({ event_name: z.literal("ELEMENT_CLICK") }).and(zElementClickRequest),
1479
+ z.object({ event_name: z.union([z.literal("BRAND_DISPLAY"), z.literal("BRAND_VIEW")]) }).and(zBrandDisplayRequest),
1480
+ z.object({ event_name: z.literal("BRAND_CLICK") }).and(zBrandClickRequest),
1481
+ z.object({ event_name: z.union([z.literal("PRODUCT_DISPLAY"), z.literal("PRODUCT_VIEW")]) }).and(zProductDisplayRequest),
1482
+ z.object({ event_name: z.literal("PRODUCT_CLICK") }).and(zProductClickRequest)
1483
+ ]);
1484
+ //#endregion
1485
+ //#region src/api/generated/events/sdk.gen.ts
1486
+ /**
1487
+ * Events
1488
+ *
1489
+ * The root endpoint manages requests to the partners API events/ endpoint. The root is
1490
+ * used instead of specifying a path because routing is handled via API Gateway.
1491
+ */
1492
+ const eventsPost = (options) => (options.client ?? client).post({
1493
+ requestValidator: async (data) => await z.object({
1494
+ body: zEventsPostBody,
1495
+ path: z.never().optional(),
1496
+ query: z.never().optional()
1497
+ }).parseAsync(data),
1498
+ security: [{
1499
+ name: "x-api-key",
1500
+ type: "apiKey"
1501
+ }],
1502
+ url: "/",
1503
+ ...options,
1504
+ headers: {
1505
+ "Content-Type": "application/json",
1506
+ ...options.headers
1507
+ }
1508
+ });
1509
+ //#endregion
667
1510
  //#region src/config.ts
668
1511
  /**
669
1512
  * Per-environment base URL for the partners API gateway. Both the
@@ -695,6 +1538,91 @@ function authHeaders(config) {
695
1538
  };
696
1539
  }
697
1540
  //#endregion
1541
+ //#region src/events/eventMapping.ts
1542
+ /**
1543
+ * Map a friendly camelCase {@link EventPayload} to the snake_case wire body the
1544
+ * events service expects ({@link EventRequest}), stamping `session_id` and the
1545
+ * occurrence time. Pure: no IO, no state — same input, same output.
1546
+ *
1547
+ * `event_datetime` is emitted as ISO-8601 with a `Z` suffix, the format the
1548
+ * events service validates (`z.iso.datetime()` rejects numeric offsets). This
1549
+ * differs from the legacy proxy tracker, which emits `+00:00`; the two services
1550
+ * validate datetimes differently, so they don't share this mapper.
1551
+ */
1552
+ function toEventRequest(event, ctx) {
1553
+ const session_id = ctx.sessionId;
1554
+ const event_datetime = (ctx.now?.() ?? /* @__PURE__ */ new Date()).toISOString();
1555
+ const placement_details = toPlacement(event.placement);
1556
+ switch (event.type) {
1557
+ case "BRAND_CLICK": return {
1558
+ event_name: event.type,
1559
+ session_id,
1560
+ event_datetime,
1561
+ placement_details,
1562
+ brand_properties: toBrand(event.brand),
1563
+ initiating_target: event.target,
1564
+ asset_id: event.assetId
1565
+ };
1566
+ case "BRAND_DISPLAY":
1567
+ case "BRAND_VIEW": return {
1568
+ event_name: event.type,
1569
+ session_id,
1570
+ event_datetime,
1571
+ placement_details,
1572
+ brand_properties: toBrand(event.brand),
1573
+ initiating_target: event.target
1574
+ };
1575
+ case "PRODUCT_CLICK": return {
1576
+ event_name: event.type,
1577
+ session_id,
1578
+ event_datetime,
1579
+ placement_details,
1580
+ brand_properties: toBrand(event.brand),
1581
+ product_properties: { product_id: event.product.productId },
1582
+ initiating_target: event.target
1583
+ };
1584
+ case "PRODUCT_DISPLAY":
1585
+ case "PRODUCT_VIEW": return {
1586
+ event_name: event.type,
1587
+ session_id,
1588
+ event_datetime,
1589
+ placement_details,
1590
+ brand_properties: toBrand(event.brand),
1591
+ product_properties: { product_id: event.product.productId },
1592
+ initiating_target: event.target
1593
+ };
1594
+ case "ELEMENT_CLICK": return {
1595
+ event_name: event.type,
1596
+ session_id,
1597
+ event_datetime,
1598
+ placement_details,
1599
+ initiating_target: event.target,
1600
+ brand_properties: event.brand ? toBrand(event.brand) : void 0
1601
+ };
1602
+ default: return {
1603
+ event_name: event.type,
1604
+ session_id,
1605
+ event_datetime,
1606
+ placement_details
1607
+ };
1608
+ }
1609
+ }
1610
+ function toBrand(brand) {
1611
+ return {
1612
+ offer_id: brand.offerId,
1613
+ advertiser_id: brand.advertiserId,
1614
+ insertion_id: brand.insertionId
1615
+ };
1616
+ }
1617
+ function toPlacement(placement) {
1618
+ if (!placement) return void 0;
1619
+ return {
1620
+ display_mode: placement.displayMode,
1621
+ view: placement.view,
1622
+ layout_id: placement.layoutId
1623
+ };
1624
+ }
1625
+ //#endregion
698
1626
  //#region src/external/DiscoClient.ts
699
1627
  /**
700
1628
  * Typed client for the Disco recommendations API — calls
@@ -711,19 +1639,21 @@ function authHeaders(config) {
711
1639
  */
712
1640
  var DiscoClient = class {
713
1641
  #recommendationsClient;
714
- #eventsUrl;
715
- #apiKey;
1642
+ #eventsClient;
716
1643
  #fetch;
717
1644
  constructor(config) {
718
1645
  const env = envFromApiKey(config.apiKey);
719
- this.#apiKey = config.apiKey;
720
- this.#eventsUrl = `${GATEWAY_BASE_URL[env]}/events`;
721
1646
  this.#fetch = config.fetch ?? globalThis.fetch.bind(globalThis);
722
1647
  this.#recommendationsClient = createRecommendationsClient({
723
1648
  baseUrl: GATEWAY_BASE_URL[env],
724
1649
  headers: authHeaders(config),
725
1650
  fetch: this.#fetch
726
1651
  });
1652
+ this.#eventsClient = createEventsClient({
1653
+ baseUrl: `${GATEWAY_BASE_URL[env]}/events`,
1654
+ headers: { "x-api-key": config.apiKey },
1655
+ fetch: this.#fetch
1656
+ });
727
1657
  }
728
1658
  /**
729
1659
  * Fetch recommendations for the given request.
@@ -767,16 +1697,60 @@ var DiscoClient = class {
767
1697
  /**
768
1698
  * Create an events tracker bound to a recommendations session (the
769
1699
  * `sessionId` from a `getRecommendations` response). Posts to the external
770
- * `/events` endpoint with this client's `x-api-key`.
1700
+ * `/events` endpoint with this client's `x-api-key`, via the generated events
1701
+ * SDK (`eventsPost`).
1702
+ *
1703
+ * This is the **raw** tracker — it sends every call, fire-and-forget (never
1704
+ * throws; failures are logged). Impression dedup is a render-lifecycle policy
1705
+ * applied a layer up (the React layer wraps this with `withImpressionDedupe`),
1706
+ * not baked into the core client.
771
1707
  */
772
- createTrackingManager = (sessionId, options) => new TrackingManager({
773
- sessionId,
774
- endpoint: this.#eventsUrl,
775
- headers: { "x-api-key": this.#apiKey },
776
- fetch: options?.fetch ?? this.#fetch
777
- });
1708
+ createTrackingManager = (sessionId, options) => {
1709
+ const fetchOverride = options?.fetch;
1710
+ return { track: (event) => {
1711
+ eventsPost({
1712
+ client: this.#eventsClient,
1713
+ body: toEventRequest(event, { sessionId }),
1714
+ keepalive: true,
1715
+ ...fetchOverride ? { fetch: fetchOverride } : {}
1716
+ }).then((result) => {
1717
+ if (result.error) console.error("Event tracking failed:", result.error);
1718
+ });
1719
+ } };
1720
+ };
778
1721
  };
779
1722
  //#endregion
780
- export { DiscoApiError, DiscoClient, DiscoError, DiscoNetworkError, DiscoValidationError };
1723
+ //#region src/events/dedupe.ts
1724
+ /**
1725
+ * Impression events that fire repeatedly from rendering surfaces (intersection
1726
+ * observers, re-renders) and should be sent at most once per session.
1727
+ */
1728
+ const DEDUPED_EVENTS = new Set([
1729
+ "WIDGET_DISPLAY",
1730
+ "WIDGET_VIEW",
1731
+ "BRAND_DISPLAY",
1732
+ "BRAND_VIEW"
1733
+ ]);
1734
+ /**
1735
+ * Wrap an {@link EventTracker} so repeat impressions are suppressed within the
1736
+ * session: a given (event type, insertionId) is forwarded once, then dropped.
1737
+ *
1738
+ * Dedup is a delivery *policy*, not transport — kept as an explicit, opt-in
1739
+ * decorator so suppression is never a surprise. State (the seen-set) lives in
1740
+ * the wrapper; create one per session-bound tracker to scope dedup per session.
1741
+ */
1742
+ function withImpressionDedupe(inner) {
1743
+ const seen = /* @__PURE__ */ new Set();
1744
+ return { track(event) {
1745
+ if (DEDUPED_EVENTS.has(event.type)) {
1746
+ const key = event.type + ("brand" in event && event.brand ? event.brand.insertionId : "widget");
1747
+ if (seen.has(key)) return;
1748
+ seen.add(key);
1749
+ }
1750
+ inner.track(event);
1751
+ } };
1752
+ }
1753
+ //#endregion
1754
+ export { DiscoApiError, DiscoClient, DiscoError, DiscoNetworkError, DiscoValidationError, withImpressionDedupe };
781
1755
 
782
1756
  //# sourceMappingURL=index.js.map