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