@adhese/sdk 0.1.0

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.
@@ -0,0 +1,734 @@
1
+ import * as zod from 'zod';
2
+ import { TypeOf, ZodType } from 'zod';
3
+
4
+ /**
5
+ * Merge two types together. The resulting type will have all properties of both types, but if a property is present in
6
+ * both types, the type of the second type will be used.
7
+ */
8
+ type Merge<T, U> = Omit<T, keyof U> & U;
9
+
10
+ /**
11
+ * Type that represents a URL string that starts with `http://` or `https://`.
12
+ */
13
+ type UrlString = `https://${string}.${string}` | `http://${string}.${string}`;
14
+
15
+ type Event<T> = {
16
+ /**
17
+ * The listeners for this event. This is a set of functions that will be called when the event is dispatched.
18
+ */
19
+ listeners: Set<(data: T) => void | Promise<void>>;
20
+ /**
21
+ * Dispatches the event to all listeners. This is a synchronous operation.
22
+ * @param data
23
+ */
24
+ dispatch(data: T): void;
25
+ /**
26
+ * Dispatches the event to all listeners. This is an asynchronous operation.
27
+ * @param data
28
+ */
29
+ dispatchAsync(data: T): Promise<void>;
30
+ /**
31
+ * Adds a listener to the event.
32
+ * @param listener
33
+ */
34
+ addListener(listener: (data: T) => void | Promise<void>): void;
35
+ /**
36
+ * Removes a listener from the event.
37
+ * @param listener
38
+ */
39
+ removeListener(listener: (data: T) => void | Promise<void>): void;
40
+ };
41
+ type EventManagerGroup<Events extends Record<string, unknown>> = {
42
+ [Key in keyof Events]: Readonly<Event<Events[Key]>>;
43
+ };
44
+ type EventManager<Events extends Record<string, unknown>> = {
45
+ /**
46
+ * Disposes of all listeners and clears the event manager. After calling this method, the event manager is no longer usable.
47
+ */
48
+ dispose(): void;
49
+ } & EventManagerGroup<Events>;
50
+ /**
51
+ * Creates a new event manager with the given event names.
52
+ *
53
+ * @typeParam Events The events that the event manager will handle and their data types.
54
+ */
55
+ declare function createEventManager<Events extends Record<Name, unknown>, Name extends Readonly<string | number | symbol> = keyof Events>(): EventManager<Events>;
56
+
57
+ type SlotManager = {
58
+ /**
59
+ * Returns all slots that are currently registered and rendered.
60
+ */
61
+ getAll(): ReadonlyArray<AdheseSlot>;
62
+ /**
63
+ * Adds a new slot to the Adhese instance and renders it.
64
+ */
65
+ add(slot: Omit<AdheseSlotOptions, 'context'>): Promise<Readonly<AdheseSlot>>;
66
+ /**
67
+ * Finds all slots in the DOM and adds them to the Adhese instance.
68
+ */
69
+ findDomSlots(): Promise<ReadonlyArray<AdheseSlot>>;
70
+ /**
71
+ * Returns the slot with the given name.
72
+ */
73
+ get(name: string): AdheseSlot | undefined;
74
+ /**
75
+ * Removes all slots from the Adhese instance and cleans up the slot manager.
76
+ */
77
+ dispose(): void;
78
+ };
79
+ type SlotManagerOptions = {
80
+ /**
81
+ * List of initial slots to add to the slot manager.
82
+ */
83
+ initialSlots?: ReadonlyArray<Merge<Omit<AdheseSlotOptions, 'containingElement' | 'context' | 'lazy'>, {
84
+ containingElement: string;
85
+ }>>;
86
+ context: AdheseContext;
87
+ };
88
+
89
+ declare const baseAdResponseScheme: zod.ZodObject<{
90
+ adDuration: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
91
+ adDuration2nd: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
92
+ adDuration3rd: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
93
+ adDuration4th: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
94
+ adDuration5th: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
95
+ adDuration6th: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
96
+ adFormat: zod.ZodOptional<zod.ZodString>;
97
+ adType: zod.ZodString;
98
+ additionalCreativeTracker: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, URL | undefined, string>>;
99
+ additionalViewableTracker: zod.ZodOptional<zod.ZodString>;
100
+ adspaceEnd: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, Date | undefined, string>>;
101
+ adspaceId: zod.ZodOptional<zod.ZodString>;
102
+ adspaceKey: zod.ZodOptional<zod.ZodString>;
103
+ adspaceStart: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, Date | undefined, string>>;
104
+ advertiserId: zod.ZodOptional<zod.ZodString>;
105
+ altText: zod.ZodOptional<zod.ZodString>;
106
+ auctionable: zod.ZodOptional<zod.ZodUnion<[zod.ZodBoolean, zod.ZodLiteral<"">]>>;
107
+ body: zod.ZodOptional<zod.ZodString>;
108
+ clickTag: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, URL | undefined, string>>;
109
+ comment: zod.ZodOptional<zod.ZodString>;
110
+ creativeName: zod.ZodOptional<zod.ZodString>;
111
+ deliveryGroupId: zod.ZodOptional<zod.ZodString>;
112
+ deliveryMultiples: zod.ZodOptional<zod.ZodString>;
113
+ dm: zod.ZodOptional<zod.ZodString>;
114
+ ext: zod.ZodOptional<zod.ZodString>;
115
+ extension: zod.ZodOptional<zod.ZodObject<{
116
+ mediaType: zod.ZodString;
117
+ prebid: zod.ZodOptional<zod.ZodUnknown>;
118
+ }, "strip", zod.ZodTypeAny, {
119
+ mediaType: string;
120
+ prebid?: unknown;
121
+ }, {
122
+ mediaType: string;
123
+ prebid?: unknown;
124
+ }>>;
125
+ extraField1: zod.ZodOptional<zod.ZodString>;
126
+ extraField2: zod.ZodOptional<zod.ZodString>;
127
+ height: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
128
+ height3rd: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
129
+ height4th: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
130
+ height5th: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
131
+ height6th: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
132
+ heightLarge: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
133
+ id: zod.ZodOptional<zod.ZodString>;
134
+ impressionCounter: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, URL | undefined, string>>;
135
+ libId: zod.ZodOptional<zod.ZodString>;
136
+ orderId: zod.ZodOptional<zod.ZodString>;
137
+ orderName: zod.ZodOptional<zod.ZodString>;
138
+ orderProperty: zod.ZodOptional<zod.ZodString>;
139
+ origin: zod.ZodOptional<zod.ZodString>;
140
+ originData: zod.ZodOptional<zod.ZodUnknown>;
141
+ poolPath: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, URL | undefined, string>>;
142
+ preview: zod.ZodOptional<zod.ZodUnion<[zod.ZodBoolean, zod.ZodLiteral<"">]>>;
143
+ priority: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
144
+ share: zod.ZodOptional<zod.ZodString>;
145
+ slotID: zod.ZodString;
146
+ slotName: zod.ZodString;
147
+ swfSrc: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, URL | undefined, string>>;
148
+ swfSrc2nd: zod.ZodOptional<zod.ZodString>;
149
+ swfSrc3rd: zod.ZodOptional<zod.ZodString>;
150
+ swfSrc4th: zod.ZodOptional<zod.ZodString>;
151
+ swfSrc5th: zod.ZodOptional<zod.ZodString>;
152
+ swfSrc6th: zod.ZodOptional<zod.ZodString>;
153
+ tag: zod.ZodString;
154
+ tagUrl: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, URL | undefined, string>>;
155
+ timeStamp: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, Date | undefined, string>>;
156
+ trackedImpressionCounter: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, URL | undefined, string>>;
157
+ tracker: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, URL | undefined, string>>;
158
+ trackingUrl: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, URL | undefined, string>>;
159
+ url: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, URL | undefined, string>>;
160
+ viewableImpressionCounter: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, URL | undefined, string>>;
161
+ width: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
162
+ width3rd: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
163
+ width4th: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
164
+ width5th: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
165
+ width6th: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
166
+ widthLarge: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
167
+ }, "strip", zod.ZodTypeAny, {
168
+ adType: string;
169
+ slotID: string;
170
+ slotName: string;
171
+ tag: string;
172
+ adDuration?: number | undefined;
173
+ adDuration2nd?: number | undefined;
174
+ adDuration3rd?: number | undefined;
175
+ adDuration4th?: number | undefined;
176
+ adDuration5th?: number | undefined;
177
+ adDuration6th?: number | undefined;
178
+ adFormat?: string | undefined;
179
+ additionalCreativeTracker?: URL | undefined;
180
+ additionalViewableTracker?: string | undefined;
181
+ adspaceEnd?: Date | undefined;
182
+ adspaceId?: string | undefined;
183
+ adspaceKey?: string | undefined;
184
+ adspaceStart?: Date | undefined;
185
+ advertiserId?: string | undefined;
186
+ altText?: string | undefined;
187
+ auctionable?: boolean | "" | undefined;
188
+ body?: string | undefined;
189
+ clickTag?: URL | undefined;
190
+ comment?: string | undefined;
191
+ creativeName?: string | undefined;
192
+ deliveryGroupId?: string | undefined;
193
+ deliveryMultiples?: string | undefined;
194
+ dm?: string | undefined;
195
+ ext?: string | undefined;
196
+ extension?: {
197
+ mediaType: string;
198
+ prebid?: unknown;
199
+ } | undefined;
200
+ extraField1?: string | undefined;
201
+ extraField2?: string | undefined;
202
+ height?: number | undefined;
203
+ height3rd?: number | undefined;
204
+ height4th?: number | undefined;
205
+ height5th?: number | undefined;
206
+ height6th?: number | undefined;
207
+ heightLarge?: number | undefined;
208
+ id?: string | undefined;
209
+ impressionCounter?: URL | undefined;
210
+ libId?: string | undefined;
211
+ orderId?: string | undefined;
212
+ orderName?: string | undefined;
213
+ orderProperty?: string | undefined;
214
+ origin?: string | undefined;
215
+ originData?: unknown;
216
+ poolPath?: URL | undefined;
217
+ preview?: boolean | "" | undefined;
218
+ priority?: number | undefined;
219
+ share?: string | undefined;
220
+ swfSrc?: URL | undefined;
221
+ swfSrc2nd?: string | undefined;
222
+ swfSrc3rd?: string | undefined;
223
+ swfSrc4th?: string | undefined;
224
+ swfSrc5th?: string | undefined;
225
+ swfSrc6th?: string | undefined;
226
+ tagUrl?: URL | undefined;
227
+ timeStamp?: Date | undefined;
228
+ trackedImpressionCounter?: URL | undefined;
229
+ tracker?: URL | undefined;
230
+ trackingUrl?: URL | undefined;
231
+ url?: URL | undefined;
232
+ viewableImpressionCounter?: URL | undefined;
233
+ width?: number | undefined;
234
+ width3rd?: number | undefined;
235
+ width4th?: number | undefined;
236
+ width5th?: number | undefined;
237
+ width6th?: number | undefined;
238
+ widthLarge?: number | undefined;
239
+ }, {
240
+ adType: string;
241
+ slotID: string;
242
+ slotName: string;
243
+ tag: string;
244
+ adDuration?: string | undefined;
245
+ adDuration2nd?: string | undefined;
246
+ adDuration3rd?: string | undefined;
247
+ adDuration4th?: string | undefined;
248
+ adDuration5th?: string | undefined;
249
+ adDuration6th?: string | undefined;
250
+ adFormat?: string | undefined;
251
+ additionalCreativeTracker?: string | undefined;
252
+ additionalViewableTracker?: string | undefined;
253
+ adspaceEnd?: string | undefined;
254
+ adspaceId?: string | undefined;
255
+ adspaceKey?: string | undefined;
256
+ adspaceStart?: string | undefined;
257
+ advertiserId?: string | undefined;
258
+ altText?: string | undefined;
259
+ auctionable?: boolean | "" | undefined;
260
+ body?: string | undefined;
261
+ clickTag?: string | undefined;
262
+ comment?: string | undefined;
263
+ creativeName?: string | undefined;
264
+ deliveryGroupId?: string | undefined;
265
+ deliveryMultiples?: string | undefined;
266
+ dm?: string | undefined;
267
+ ext?: string | undefined;
268
+ extension?: {
269
+ mediaType: string;
270
+ prebid?: unknown;
271
+ } | undefined;
272
+ extraField1?: string | undefined;
273
+ extraField2?: string | undefined;
274
+ height?: string | undefined;
275
+ height3rd?: string | undefined;
276
+ height4th?: string | undefined;
277
+ height5th?: string | undefined;
278
+ height6th?: string | undefined;
279
+ heightLarge?: string | undefined;
280
+ id?: string | undefined;
281
+ impressionCounter?: string | undefined;
282
+ libId?: string | undefined;
283
+ orderId?: string | undefined;
284
+ orderName?: string | undefined;
285
+ orderProperty?: string | undefined;
286
+ origin?: string | undefined;
287
+ originData?: unknown;
288
+ poolPath?: string | undefined;
289
+ preview?: boolean | "" | undefined;
290
+ priority?: string | undefined;
291
+ share?: string | undefined;
292
+ swfSrc?: string | undefined;
293
+ swfSrc2nd?: string | undefined;
294
+ swfSrc3rd?: string | undefined;
295
+ swfSrc4th?: string | undefined;
296
+ swfSrc5th?: string | undefined;
297
+ swfSrc6th?: string | undefined;
298
+ tagUrl?: string | undefined;
299
+ timeStamp?: string | undefined;
300
+ trackedImpressionCounter?: string | undefined;
301
+ tracker?: string | undefined;
302
+ trackingUrl?: string | undefined;
303
+ url?: string | undefined;
304
+ viewableImpressionCounter?: string | undefined;
305
+ width?: string | undefined;
306
+ width3rd?: string | undefined;
307
+ width4th?: string | undefined;
308
+ width5th?: string | undefined;
309
+ width6th?: string | undefined;
310
+ widthLarge?: string | undefined;
311
+ }>;
312
+ type AdResponse = TypeOf<typeof baseAdResponseScheme> & {
313
+ additionalCreatives?: ReadonlyArray<AdResponse> | string;
314
+ };
315
+ declare const adResponseSchema: ZodType<AdResponse>;
316
+ type Ad = TypeOf<typeof adResponseSchema> & {
317
+ additionalCreatives?: ReadonlyArray<Ad> | string;
318
+ };
319
+
320
+ type RenderMode = 'iframe' | 'inline';
321
+ type AdheseSlotOptions = {
322
+ /**
323
+ * The format code of the slot. Used to find the correct element on the page to render the ad in. If the format is a
324
+ * string, it is used as the format code. If the format is an array, the format code is determined by the query
325
+ * detector.
326
+ */
327
+ format: string | ReadonlyArray<{
328
+ format: string;
329
+ query: string;
330
+ }>;
331
+ /**
332
+ * If we have multiple slots with the same format, we can use this to differentiate between them.
333
+ */
334
+ slot?: string;
335
+ /**
336
+ * The element that contains the slot. Used to find the correct element on the page to render the ad in.
337
+ */
338
+ containingElement?: string | HTMLElement;
339
+ /**
340
+ * The parameters that are used to render the ad.
341
+ */
342
+ parameters?: Record<string, ReadonlyArray<string> | string>;
343
+ /**
344
+ * The Adhese context
345
+ */
346
+ context: AdheseContext;
347
+ /**
348
+ * The render mode of the slot.
349
+ *
350
+ * - `iframe`: The ad will be rendered in an iframe.
351
+ * - `inline`: The ad will be rendered in the containing element.
352
+ *
353
+ * @default 'iframe'
354
+ */
355
+ renderMode?: RenderMode;
356
+ /**
357
+ * Callback that is called when the slot is disposed.
358
+ */
359
+ onDispose?(): void;
360
+ /**
361
+ * Callback that is called when the format of the slot changes.
362
+ */
363
+ onNameChange?(newName: string, oldName: string): void;
364
+ } & ({
365
+ /**
366
+ * If the slot should be lazy loaded. This means that the ad will only be requested when the slot is in the viewport.
367
+ * If `true`, the slot will handle the request itself and render the ad.
368
+ */
369
+ lazyLoading: true;
370
+ lazyLoadingOptions?: {
371
+ /**
372
+ * The root margin of the intersection observer. This is used to determine when the slot is in the viewport.
373
+ */
374
+ rootMargin?: string;
375
+ };
376
+ } | {
377
+ lazyLoading?: false;
378
+ lazyLoadingOptions?: never;
379
+ });
380
+ type AdheseSlot = Merge<Omit<AdheseSlotOptions, 'onDispose' | 'context' | 'onFormatChange' | 'format'>, {
381
+ /**
382
+ * The location of the slot. This is the location that is used to determine the current page URL.
383
+ */
384
+ location: string;
385
+ /**
386
+ * The parameters that are used to render the ad.
387
+ */
388
+ parameters: Map<string, ReadonlyArray<string> | string>;
389
+ /**
390
+ * Renders the slot in the containing element. If no ad is provided, a new ad will be requested from the API.
391
+ */
392
+ render(ad?: Ad): Promise<HTMLElement>;
393
+ /**
394
+ * Returns the rendered element.
395
+ */
396
+ getElement(): HTMLElement | null;
397
+ /**
398
+ * Returns the name of the slot.
399
+ */
400
+ getName(): string;
401
+ /**
402
+ * Returns the ad that is to be rendered in the slot or is currently rendered in the slot.
403
+ */
404
+ getAd(): Ad | null;
405
+ /**
406
+ * Sets the ad that is to be rendered in the slot. If the slot is in the viewport, the ad will be rendered immediately.
407
+ */
408
+ setAd(ad: Ad): Promise<void>;
409
+ /**
410
+ * Returns whether the viewability tracking pixel has been fired.
411
+ */
412
+ isViewabilityTracked(): boolean;
413
+ /**
414
+ * Returns whether the impression tracking pixel has been fired.
415
+ */
416
+ isImpressionTracked(): boolean;
417
+ /**
418
+ * Sets the format of the slot. This is used to change the format of the slot after it has been created.
419
+ */
420
+ setFormat(format: string): Promise<void>;
421
+ /**
422
+ * Returns the format of the slot.
423
+ */
424
+ getFormat(): string;
425
+ /**
426
+ * Removes the slot from the DOM and cleans up the slot instance.
427
+ */
428
+ dispose(): void;
429
+ }>;
430
+
431
+ type AdRequestOptions = {
432
+ /**
433
+ * List of slots you want to fetch the ad for
434
+ */
435
+ slots: ReadonlyArray<Pick<AdheseSlot, 'getName' | 'parameters'>>;
436
+ /**
437
+ * Host that you want to fetch the ads from
438
+ */
439
+ host: UrlString;
440
+ /**
441
+ * The Adhese account name.
442
+ */
443
+ account: string;
444
+ /**
445
+ * Request method to use for the requestAds
446
+ *
447
+ * @default 'POST'
448
+ */
449
+ method?: 'GET' | 'POST' | 'get' | 'post';
450
+ /**
451
+ * The parameters that are used for all ads.
452
+ */
453
+ parameters?: Map<string, ReadonlyArray<string> | string>;
454
+ context: Partial<Adhese>;
455
+ };
456
+
457
+ declare class MapWithEvents<T, U> extends Map<T, U> {
458
+ private readonly listeners;
459
+ addEventListener(listener: () => void): void;
460
+ removeEventListener(listener: () => void): void;
461
+ set(key: T, value: U): this;
462
+ clear(): void;
463
+ delete(key: T): boolean;
464
+ /**
465
+ * Remove all listeners and clear the map.
466
+ */
467
+ dispose(): void;
468
+ }
469
+
470
+ /**
471
+ * A log entry saved by the logger
472
+ */
473
+ type Log<T extends string> = {
474
+ /**
475
+ * The scope of the logger that created this log entry
476
+ */
477
+ scope: string;
478
+ /**
479
+ * The log level of this log entry
480
+ */
481
+ level: T;
482
+ /**
483
+ * The message of this log entry
484
+ */
485
+ message: string;
486
+ /**
487
+ * The attributes of this log entry
488
+ */
489
+ attributes?: unknown;
490
+ /**
491
+ * The timestamp of this log entry
492
+ */
493
+ timestamp: number;
494
+ id: string;
495
+ };
496
+ type LogFunction = (message: string, attributes?: unknown) => void;
497
+ type Logger<T extends string> = {
498
+ [key in T]: LogFunction;
499
+ } & {
500
+ /**
501
+ * The scope of the logger
502
+ */
503
+ readonly scope: string;
504
+ /**
505
+ * The event manager of the logger
506
+ */
507
+ events: ReturnType<typeof createEventManager<{
508
+ log: Log<T>;
509
+ reset: void;
510
+ }>>;
511
+ /**
512
+ * Set the minimum log level threshold
513
+ */
514
+ setMinLogLevelThreshold(level: T): void;
515
+ /**
516
+ * Reset the minimum log level threshold to the default value
517
+ */
518
+ resetMinLogLevelThreshold(): void;
519
+ /**
520
+ * Get the current minimum log level threshold
521
+ */
522
+ getMinLogLevelThreshold(): T;
523
+ /**
524
+ * Get the logs that were created by this logger
525
+ */
526
+ getLogs(): ReadonlyArray<Log<T>>;
527
+ /**
528
+ * Reset the logs that were created by this logger
529
+ */
530
+ resetLogs(): void;
531
+ };
532
+
533
+ declare const logger: Logger<"error" | "debug" | "trace" | "info" | "warn">;
534
+
535
+ type AdheseOptions = {
536
+ /**
537
+ * The Adhese account name.
538
+ */
539
+ account: string;
540
+ /**
541
+ * The url that is used to connect to the Adhese ad server. Pass a custom URL if you want to use your own domain for
542
+ * the connection.
543
+ *
544
+ * @default 'https://ads-{{account}}.adhese.com'
545
+ */
546
+ host?: UrlString;
547
+ /**
548
+ * The url that is used to connect to the Adhese pool server. Pass a custom URL if you want to use your own domain for
549
+ * the connection.
550
+ *
551
+ * @default 'https://pool-{{account}}.adhese.com'
552
+ */
553
+ poolHost?: UrlString;
554
+ /**
555
+ * The page location. This is used to determine the current page location identifier.
556
+ *
557
+ * @default location.pathname
558
+ */
559
+ location?: string;
560
+ /**
561
+ * The requestAds type to use for the Adhese API requests. This can be either `GET` or `POST`. `POST` is the default
562
+ * and offers the most options. `GET` is more limited as it needs pass its data as search parameters but can be used
563
+ * in environments where `POST` requests are not allowed.
564
+ *
565
+ * @default 'POST'
566
+ */
567
+ requestType?: 'GET' | 'POST';
568
+ /**
569
+ * Enable debug logging.
570
+ *
571
+ * @default false
572
+ */
573
+ debug?: boolean;
574
+ /**
575
+ * Find all slots in the DOM and add them to the Adhese instance during initialization.
576
+ *
577
+ * @default false
578
+ */
579
+ findDomSlotsOnLoad?: boolean;
580
+ /**
581
+ * Additional parameters to send with each request. Make sure that the keys of a parameter only contain `2` characters.
582
+ */
583
+ parameters?: Record<string, ReadonlyArray<string> | string>;
584
+ /**
585
+ * The consent type to use for the Adhese API requests. This can be either `true` or `false`. `false` is the default and
586
+ * will send all consent data to the Adhese API. `false` will send no consent data to the Adhese API.
587
+ *
588
+ * @default false
589
+ */
590
+ consent?: boolean;
591
+ /**
592
+ * Will log the `document.referrer` to the Adhese API in a BASE64 string with the `re` parameter.
593
+ *
594
+ * @default true
595
+ */
596
+ logReferrer?: boolean;
597
+ /**
598
+ * Will log the `window.location.href` to the Adhese API in a BASE64 string with the `ur` parameter.
599
+ *
600
+ * @default true
601
+ */
602
+ logUrl?: boolean;
603
+ /**
604
+ * If `true`, ads will be rendered immediately after they are fetched from the API. If `false`, ads will only be
605
+ * rendered when the slot is in the viewport.
606
+ *
607
+ * @default false
608
+ */
609
+ eagerRendering?: boolean;
610
+ /**
611
+ * The query detector options for the Adhese instance.
612
+ */
613
+ queries?: Record<string, string>;
614
+ } & ({
615
+ viewabilityTracking?: true;
616
+ /**
617
+ * Options for the viewability tracking of the ads. If `true` or `undefined`, the default viewability tracking options will be used.
618
+ *
619
+ * @default true
620
+ */
621
+ viewabilityTrackingOptions?: {
622
+ /**
623
+ * Fraction of the ad that needs to be in the viewport for the ad to be considered viewable.
624
+ *
625
+ * @default 0.2
626
+ */
627
+ threshold?: number;
628
+ /**
629
+ * The duration the ad needs to be in the viewport for the ad to be considered viewable in milliseconds.
630
+ *
631
+ * @default 1000
632
+ */
633
+ duration?: number;
634
+ /**
635
+ * The margin around the viewport where the ad is considered viewable.
636
+ *
637
+ * @default '0px'
638
+ */
639
+ rootMargin?: string;
640
+ };
641
+ } | {
642
+ viewabilityTracking?: false;
643
+ viewabilityTrackingOptions?: never;
644
+ }) & Pick<SlotManagerOptions, 'initialSlots'>;
645
+ type MergedOptions = Merge<AdheseOptions, Required<Pick<AdheseOptions, 'host' | 'poolHost' | 'location' | 'requestType' | 'debug' | 'initialSlots' | 'findDomSlotsOnLoad' | 'consent' | 'logUrl' | 'logReferrer' | 'eagerRendering' | 'viewabilityTracking'>>>;
646
+ type AdheseEvents = {
647
+ locationChange: string;
648
+ consentChange: boolean;
649
+ addSlot: AdheseSlot;
650
+ removeSlot: AdheseSlot;
651
+ changeSlots: ReadonlyArray<AdheseSlot>;
652
+ responseReceived: ReadonlyArray<Ad>;
653
+ requestAd: AdRequestOptions;
654
+ requestError: Error;
655
+ previewReceived: ReadonlyArray<Ad>;
656
+ parametersChange: Map<string, ReadonlyArray<string> | string>;
657
+ };
658
+ type Adhese = Omit<AdheseOptions, 'location' | 'parameters' | 'consent'> & Merge<SlotManager, {
659
+ /**
660
+ * The parameters that are used for all ads.
661
+ */
662
+ parameters: MapWithEvents<string, ReadonlyArray<string> | string>;
663
+ /**
664
+ * The event manager for the Adhese instance.
665
+ */
666
+ events: EventManager<AdheseEvents>;
667
+ /**
668
+ * Returns the current page location.
669
+ */
670
+ getLocation(): string;
671
+ /**
672
+ * Sets the current page location.
673
+ */
674
+ setLocation(location: string): void;
675
+ /**
676
+ * Returns the current consent type.
677
+ */
678
+ getConsent(): boolean;
679
+ /**
680
+ * Sets the current consent type.
681
+ */
682
+ setConsent(consent: boolean): void;
683
+ /**
684
+ * Adds a new slot to the Adhese instance and renders it.
685
+ */
686
+ addSlot(slot: Omit<AdheseSlotOptions, 'location' | 'context'>): Promise<Readonly<AdheseSlot>>;
687
+ /**
688
+ * Finds all slots in the DOM and adds them to the Adhese instance.
689
+ */
690
+ findDomSlots(): Promise<ReadonlyArray<AdheseSlot>>;
691
+ /**
692
+ * Removes all slots from the Adhese instance and cleans up the Adhese instance.
693
+ *
694
+ * After calling this method, the Adhese instance is no longer usable.
695
+ */
696
+ dispose(): void;
697
+ /**
698
+ * Toggles the debug mode of the Adhese instance.
699
+ */
700
+ toggleDebug(): Promise<boolean>;
701
+ }>;
702
+ type AdheseContext = Partial<Pick<Adhese, 'events' | 'getAll' | 'get' | 'parameters'>> & {
703
+ location: string;
704
+ consent: boolean;
705
+ options: Readonly<MergedOptions>;
706
+ logger: typeof logger;
707
+ debug: boolean;
708
+ };
709
+
710
+ /**
711
+ * Creates an Adhese instance. This instance is your main entry point to the Adhese API.
712
+ *
713
+ * @param options
714
+ * @param options.account The Adhese account name.
715
+ * @param options.host The url that is used to connect to the Adhese ad server. Pass a custom URL if you want to use
716
+ * your own domain for the connection.
717
+ * @param options.poolHost The url that is used to connect to the Adhese pool server. Pass a custom URL if you want to
718
+ * use your own domain for the connection.
719
+ * @param options.location The page location. This is used to determine the current page location identifier.
720
+ * @param options.requestType The requestAds type to use for the Adhese API requests. This can be either `GET` or
721
+ * `POST`. `POST` is the default and offers the most options. `GET` is more limited as it needs pass its data as search
722
+ * parameters but can be used in environments where `POST` requests are not allowed.
723
+ * @param options.debug Enable debug logging.
724
+ * @param options.initialSlots The initial slots to add to the Adhese instance.
725
+ * @param options.findDomSlotsOnLoad Find all slots in the DOM and add them to the Adhese instance during
726
+ * initialization.
727
+ * @param options.parameters Base parameters that are used for all ads.
728
+ * @param options.consent The consent type to use for the Adhese API requests. This can be either `all` or `none`.
729
+ *
730
+ * @return Promise<Adhese> The Adhese instance.
731
+ */
732
+ declare function createAdhese(options: AdheseOptions): Promise<Readonly<Adhese>>;
733
+
734
+ export { type Ad, type AdRequestOptions, type Adhese, type AdheseContext, type AdheseOptions, type AdheseSlot, type AdheseSlotOptions, createAdhese };