@adhese/sdk 0.14.1 → 0.16.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.
- package/CHANGELOG.md +21 -0
- package/README.md +0 -1
- package/dist/index.cjs +349 -373
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +220 -289
- package/dist/index.js +351 -375
- package/dist/index.js.map +1 -1
- package/dist/{requestAds.schema-Cb8_FVMb.js → requestAds.schema-Bt7KDWqM.js} +4 -69
- package/dist/requestAds.schema-Bt7KDWqM.js.map +1 -0
- package/dist/requestAds.schema-DvERzWT3.cjs +104 -0
- package/dist/requestAds.schema-DvERzWT3.cjs.map +1 -0
- package/package.json +2 -2
- package/dist/requestAds.schema-Cb8_FVMb.js.map +0 -1
- package/dist/requestAds.schema-D3gd-oXt.cjs +0 -169
- package/dist/requestAds.schema-D3gd-oXt.cjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,71 +3,222 @@ import { Ref, Merge, MaybeRef, UrlString, EventManager } from '@adhese/sdk-share
|
|
|
3
3
|
import * as zod from 'zod';
|
|
4
4
|
import { TypeOf, ZodType } from 'zod';
|
|
5
5
|
|
|
6
|
-
declare
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
declare class Position {
|
|
25
|
-
html: string;
|
|
26
|
-
id: string;
|
|
27
|
-
src: string;
|
|
28
|
-
meta?: Record<string, unknown>;
|
|
29
|
-
config?: Record<string, unknown>;
|
|
30
|
-
constructor(config: {
|
|
31
|
-
id: string;
|
|
32
|
-
src?: string;
|
|
33
|
-
html: string;
|
|
34
|
-
config?: PosConfig;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
declare class PosConfig {
|
|
38
|
-
id: string;
|
|
39
|
-
dest: string;
|
|
40
|
-
constructor(posIDorObj: string | {
|
|
41
|
-
bg?: string;
|
|
42
|
-
css?: string;
|
|
43
|
-
dest?: string;
|
|
44
|
-
h?: number;
|
|
45
|
-
id?: string;
|
|
46
|
-
size?: string;
|
|
47
|
-
tgt?: string;
|
|
48
|
-
w?: number;
|
|
49
|
-
z?: number;
|
|
50
|
-
supports?: Record<string, unknown>;
|
|
51
|
-
}, destID?: string, baseConf?: {
|
|
52
|
-
bg?: string;
|
|
53
|
-
css?: string;
|
|
54
|
-
dest?: string;
|
|
55
|
-
h?: number;
|
|
56
|
-
id?: string;
|
|
57
|
-
size?: string;
|
|
58
|
-
tgt?: string;
|
|
59
|
-
w?: number;
|
|
60
|
-
z?: number;
|
|
61
|
-
supports?: Record<string, unknown>;
|
|
62
|
-
});
|
|
63
|
-
}
|
|
6
|
+
declare function createAsyncHook<Argument = void, Callback extends (arg: Argument) => Argument | void | Promise<Argument | void> = (arg: Argument) => Argument | void | Promise<Argument | void>>(name: string, { onRun, onAdd, }?: {
|
|
7
|
+
onRun?(callbacks?: Set<Callback>): void;
|
|
8
|
+
onAdd?(callbacks?: Set<Callback>): void;
|
|
9
|
+
}): [
|
|
10
|
+
run: (arg: Argument) => Promise<Argument>,
|
|
11
|
+
add: (callback: Callback) => () => void,
|
|
12
|
+
dispose: () => void
|
|
13
|
+
];
|
|
14
|
+
declare function createPassiveHook<Argument = void, Callback extends (arg: Argument) => void | Promise<void> = (arg: Argument) => void | Promise<void>>(name: string, { onRun, onAdd, }?: {
|
|
15
|
+
onRun?(callbacks?: Set<Callback>): void;
|
|
16
|
+
onAdd?(callbacks?: Set<Callback>): void;
|
|
17
|
+
}): [
|
|
18
|
+
run: (arg: Argument) => void,
|
|
19
|
+
add: (callback: Callback) => () => void,
|
|
20
|
+
dispose: () => void
|
|
21
|
+
];
|
|
64
22
|
|
|
65
|
-
type
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
23
|
+
type RenderMode = 'iframe' | 'inline' | 'none';
|
|
24
|
+
type SlotHooks = {
|
|
25
|
+
/**
|
|
26
|
+
* Hook that is called when the format of the slot changes.
|
|
27
|
+
*/
|
|
28
|
+
onBeforeRender: ReturnType<typeof createAsyncHook<AdheseAd>>[1];
|
|
29
|
+
/**
|
|
30
|
+
* Hook that is called when the slot is rendered.
|
|
31
|
+
*/
|
|
32
|
+
onRender: ReturnType<typeof createAsyncHook<AdheseAd>>[1];
|
|
33
|
+
/**
|
|
34
|
+
* Hook that is called before the slot is requested from the server.
|
|
35
|
+
*/
|
|
36
|
+
onBeforeRequest: ReturnType<typeof createAsyncHook<AdheseAd | null>>[1];
|
|
37
|
+
/**
|
|
38
|
+
* Hook that is called when the slot is requested from the server.
|
|
39
|
+
*/
|
|
40
|
+
onRequest: ReturnType<typeof createAsyncHook<AdheseAd>>[1];
|
|
41
|
+
/**
|
|
42
|
+
* Hook that is called when the slot is disposed.
|
|
43
|
+
*/
|
|
44
|
+
onDispose: ReturnType<typeof createPassiveHook>[1];
|
|
45
|
+
};
|
|
46
|
+
type AdheseSlotOptions = {
|
|
47
|
+
/**
|
|
48
|
+
* 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
|
|
49
|
+
* string, it is used as the format code. If the format is an array, the format code is determined by the query
|
|
50
|
+
* detector.
|
|
51
|
+
*/
|
|
52
|
+
format: string | ReadonlyArray<{
|
|
53
|
+
format: string;
|
|
54
|
+
query: string;
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* Type of the slot. On its own has no effect, but can be used by plugins to create different behavior for different
|
|
58
|
+
* types of slots.
|
|
59
|
+
*/
|
|
60
|
+
type?: string;
|
|
61
|
+
/**
|
|
62
|
+
* If we have multiple slots with the same format, we can use this to differentiate between them.
|
|
63
|
+
*/
|
|
64
|
+
slot?: string;
|
|
65
|
+
/**
|
|
66
|
+
* The element that contains the slot. Used to find the correct element on the page to render the ad in.
|
|
67
|
+
*/
|
|
68
|
+
containingElement?: string | HTMLElement;
|
|
69
|
+
/**
|
|
70
|
+
* The parameters that are used to render the ad.
|
|
71
|
+
*/
|
|
72
|
+
parameters?: Record<string, ReadonlyArray<string> | string>;
|
|
73
|
+
/**
|
|
74
|
+
* The Adhese context
|
|
75
|
+
*/
|
|
76
|
+
context: AdheseContext;
|
|
77
|
+
/**
|
|
78
|
+
* The render mode of the slot.
|
|
79
|
+
*
|
|
80
|
+
* - `iframe`: The ad will be rendered in an iframe.
|
|
81
|
+
* - `inline`: The ad will be rendered in the containing element.
|
|
82
|
+
*
|
|
83
|
+
* @default 'iframe'
|
|
84
|
+
*/
|
|
85
|
+
renderMode?: RenderMode;
|
|
86
|
+
/**
|
|
87
|
+
* Special callback that is run when the slot is initialized. It passes the slot context ref object and a special
|
|
88
|
+
* plugin object that contains a set of hooks you can use to hook into different moments of the slots lifecycle.
|
|
89
|
+
*/
|
|
90
|
+
setup?(context: Ref<AdheseSlot | null>, hooks: SlotHooks): void;
|
|
91
|
+
} & ({
|
|
92
|
+
/**
|
|
93
|
+
* If the slot should be lazy loaded. This means that the ad will only be requested when the slot is in the viewport.
|
|
94
|
+
* If `true`, the slot will handle the request itself and render the ad.
|
|
95
|
+
*/
|
|
96
|
+
lazyLoading: true;
|
|
97
|
+
lazyLoadingOptions?: {
|
|
98
|
+
/**
|
|
99
|
+
* The root margin of the intersection observer. This is used to determine when the slot is in the viewport.
|
|
100
|
+
*/
|
|
101
|
+
rootMargin?: string;
|
|
102
|
+
};
|
|
103
|
+
} | {
|
|
104
|
+
lazyLoading?: false;
|
|
105
|
+
lazyLoadingOptions?: never;
|
|
106
|
+
});
|
|
107
|
+
type AdheseSlot = Merge<Omit<AdheseSlotOptions, 'onDispose' | 'context' | 'onFormatChange' | 'format'>, SlotHooks & {
|
|
108
|
+
/**
|
|
109
|
+
* Type of the slot. On its own has no effect, but can be used by plugins to create different behavior for different
|
|
110
|
+
* types of slots.
|
|
111
|
+
*/
|
|
112
|
+
readonly type?: string;
|
|
113
|
+
/**
|
|
114
|
+
* The name of the slot. This is used to identify the slot in the Adhese instance.
|
|
115
|
+
*
|
|
116
|
+
* The name is generated based on the location, format, and slot of the slot.
|
|
117
|
+
*/
|
|
118
|
+
readonly name: string;
|
|
119
|
+
/**
|
|
120
|
+
* The format code of the slot. Used to find the correct element on the page to render the ad in.
|
|
121
|
+
*
|
|
122
|
+
* If the format is a string, it is used as the format code. If the format is an array, the format code is determined
|
|
123
|
+
* by the query detector.
|
|
124
|
+
*
|
|
125
|
+
* When you change the format, the slot will request a new ad from the API automatically.
|
|
126
|
+
*/
|
|
127
|
+
readonly format: string;
|
|
128
|
+
/**
|
|
129
|
+
* The location of the slot. This is the location that is used to determine the current page URL.
|
|
130
|
+
*/
|
|
131
|
+
readonly location: string;
|
|
132
|
+
/**
|
|
133
|
+
* The parameters that are used to render the ad.
|
|
134
|
+
*/
|
|
135
|
+
parameters: Map<string, ReadonlyArray<string> | string>;
|
|
136
|
+
/**
|
|
137
|
+
* Whether the viewability tracking pixel has been fired.
|
|
138
|
+
*/
|
|
139
|
+
readonly isViewabilityTracked: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Whether the impression tracking pixel has been fired.
|
|
142
|
+
*/
|
|
143
|
+
readonly isImpressionTracked: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* The state of the slot is currently in.
|
|
146
|
+
*
|
|
147
|
+
* - `initializing`: The slot is initializing.
|
|
148
|
+
* - `initialized`: The slot is initialized.
|
|
149
|
+
* - `loading`: The slot is loading data from the API
|
|
150
|
+
* - `loaded`: The slot has loaded data from the API and is ready to render
|
|
151
|
+
* - `empty`: The slot has loaded data from the API but the response was empty
|
|
152
|
+
* - `rendering`: The slot is rendering the ad
|
|
153
|
+
* - `rendered`: The slot has rendered the ad
|
|
154
|
+
* - `error`: The slot has encountered an error
|
|
155
|
+
*/
|
|
156
|
+
readonly status: 'initializing' | 'initialized' | 'loading' | 'loaded' | 'empty' | 'rendering' | 'rendered' | 'error';
|
|
157
|
+
/**
|
|
158
|
+
* Is the slot disposed.
|
|
159
|
+
*/
|
|
160
|
+
readonly isDisposed: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* The element that contains the slot.
|
|
163
|
+
*/
|
|
164
|
+
readonly element: HTMLElement | null;
|
|
165
|
+
/**
|
|
166
|
+
* Unique identifier of the slot. ID is generated on initialization and will never change.
|
|
167
|
+
*/
|
|
168
|
+
readonly id: string;
|
|
169
|
+
/**
|
|
170
|
+
* Slot related data fetched from the API.
|
|
171
|
+
*/
|
|
172
|
+
data: AdheseAd | null;
|
|
173
|
+
/**
|
|
174
|
+
* Renders the slot in the containing element. If no data is provided, new data will be requested from the API.
|
|
175
|
+
*/
|
|
176
|
+
render(data?: AdheseAd): Promise<HTMLElement | null>;
|
|
177
|
+
/**
|
|
178
|
+
* Requests a new ad from the API and returns the ad object.
|
|
179
|
+
*/
|
|
180
|
+
request(): Promise<AdheseAd | null>;
|
|
181
|
+
/**
|
|
182
|
+
* Remove the HTML element contents from the dom.
|
|
183
|
+
*/
|
|
184
|
+
cleanElement(): void;
|
|
185
|
+
/**
|
|
186
|
+
* Removes the slot from the DOM and cleans up the slot instance.
|
|
187
|
+
*/
|
|
188
|
+
dispose(): void;
|
|
189
|
+
}>;
|
|
190
|
+
|
|
191
|
+
type AdheseSlotManager = {
|
|
192
|
+
/**
|
|
193
|
+
* Returns all slots that are currently registered and rendered.
|
|
194
|
+
*/
|
|
195
|
+
getAll(): ReadonlyArray<AdheseSlot>;
|
|
196
|
+
/**
|
|
197
|
+
* Adds a new slot to the Adhese instance and renders it.
|
|
198
|
+
*/
|
|
199
|
+
add(slot: Omit<AdheseSlotOptions, 'context'>): Readonly<AdheseSlot>;
|
|
200
|
+
/**
|
|
201
|
+
* Finds all slots in the DOM and adds them to the Adhese instance.
|
|
202
|
+
*/
|
|
203
|
+
findDomSlots(): Promise<ReadonlyArray<AdheseSlot>>;
|
|
204
|
+
/**
|
|
205
|
+
* Returns the slot with the given name.
|
|
206
|
+
*/
|
|
207
|
+
get(name: string): AdheseSlot | undefined;
|
|
208
|
+
/**
|
|
209
|
+
* Removes all slots from the Adhese instance and cleans up the slot manager.
|
|
210
|
+
*/
|
|
69
211
|
dispose(): void;
|
|
70
212
|
};
|
|
213
|
+
type SlotManagerOptions = {
|
|
214
|
+
/**
|
|
215
|
+
* List of initial slots to add to the slot manager.
|
|
216
|
+
*/
|
|
217
|
+
initialSlots?: ReadonlyArray<Merge<Omit<AdheseSlotOptions, 'containingElement' | 'context' | 'lazy'>, {
|
|
218
|
+
containingElement: string;
|
|
219
|
+
}>>;
|
|
220
|
+
context: AdheseContext;
|
|
221
|
+
};
|
|
71
222
|
|
|
72
223
|
declare const baseSchema: zod.ZodObject<{
|
|
73
224
|
adDuration: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
|
|
@@ -133,6 +284,7 @@ declare const baseSchema: zod.ZodObject<{
|
|
|
133
284
|
origin: "JERLICIA" | "DALE";
|
|
134
285
|
slotID: string;
|
|
135
286
|
slotName: string;
|
|
287
|
+
body?: string | Record<string, unknown> | readonly unknown[] | undefined;
|
|
136
288
|
adDuration?: number | undefined;
|
|
137
289
|
adFormat?: string | undefined;
|
|
138
290
|
additionalCreativeTracker?: URL | undefined;
|
|
@@ -144,7 +296,6 @@ declare const baseSchema: zod.ZodObject<{
|
|
|
144
296
|
advertiserId?: string | undefined;
|
|
145
297
|
altText?: string | undefined;
|
|
146
298
|
auctionable?: boolean | "" | undefined;
|
|
147
|
-
body?: string | Record<string, unknown> | readonly unknown[] | undefined;
|
|
148
299
|
clickTag?: URL | undefined;
|
|
149
300
|
comment?: string | undefined;
|
|
150
301
|
creativeName?: string | undefined;
|
|
@@ -185,6 +336,7 @@ declare const baseSchema: zod.ZodObject<{
|
|
|
185
336
|
origin: "JERLICIA" | "DALE";
|
|
186
337
|
slotID: string;
|
|
187
338
|
slotName: string;
|
|
339
|
+
body?: string | undefined;
|
|
188
340
|
adDuration?: string | undefined;
|
|
189
341
|
adFormat?: string | undefined;
|
|
190
342
|
additionalCreativeTracker?: string | undefined;
|
|
@@ -196,7 +348,6 @@ declare const baseSchema: zod.ZodObject<{
|
|
|
196
348
|
advertiserId?: string | undefined;
|
|
197
349
|
altText?: string | undefined;
|
|
198
350
|
auctionable?: boolean | "" | undefined;
|
|
199
|
-
body?: string | undefined;
|
|
200
351
|
clickTag?: string | undefined;
|
|
201
352
|
comment?: string | undefined;
|
|
202
353
|
creativeName?: string | undefined;
|
|
@@ -243,222 +394,6 @@ type AdheseAd<T = string | Record<string, unknown> | ReadonlyArray<unknown>> = O
|
|
|
243
394
|
tag: T | string;
|
|
244
395
|
};
|
|
245
396
|
|
|
246
|
-
declare function createAsyncHook<Argument = void, Callback extends (() => void | Promise<void>) | ((arg: Argument) => Argument | void | Promise<Argument | void>) = Argument extends void ? () => void | Promise<void> : (arg: Argument) => Argument | void | Promise<Argument | void>>(name: string, { onRun, onAdd, }?: {
|
|
247
|
-
onRun?(callbacks?: Set<Callback>): void;
|
|
248
|
-
onAdd?(callbacks?: Set<Callback>): void;
|
|
249
|
-
}): [
|
|
250
|
-
run: Argument extends void ? () => Promise<void> : (arg: Argument) => Promise<Argument>,
|
|
251
|
-
add: (callback: Callback) => () => void,
|
|
252
|
-
dispose: () => void
|
|
253
|
-
];
|
|
254
|
-
declare function createPassiveHook<Argument = void, Callback extends (arg: Argument) => void | Promise<void> = (arg: Argument) => void | Promise<void>>(name: string, { onRun, onAdd, }?: {
|
|
255
|
-
onRun?(callbacks?: Set<Callback>): void;
|
|
256
|
-
onAdd?(callbacks?: Set<Callback>): void;
|
|
257
|
-
}): [
|
|
258
|
-
run: (arg: Argument) => void,
|
|
259
|
-
add: (callback: Callback) => () => void,
|
|
260
|
-
dispose: () => void
|
|
261
|
-
];
|
|
262
|
-
|
|
263
|
-
type RenderMode = 'iframe' | 'inline';
|
|
264
|
-
type AdheseSlotOptions = {
|
|
265
|
-
/**
|
|
266
|
-
* 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
|
|
267
|
-
* string, it is used as the format code. If the format is an array, the format code is determined by the query
|
|
268
|
-
* detector.
|
|
269
|
-
*/
|
|
270
|
-
format: string | ReadonlyArray<{
|
|
271
|
-
format: string;
|
|
272
|
-
query: string;
|
|
273
|
-
}>;
|
|
274
|
-
/**
|
|
275
|
-
* If we have multiple slots with the same format, we can use this to differentiate between them.
|
|
276
|
-
*/
|
|
277
|
-
slot?: string;
|
|
278
|
-
/**
|
|
279
|
-
* The element that contains the slot. Used to find the correct element on the page to render the ad in.
|
|
280
|
-
*/
|
|
281
|
-
containingElement?: string | HTMLElement;
|
|
282
|
-
/**
|
|
283
|
-
* The parameters that are used to render the ad.
|
|
284
|
-
*/
|
|
285
|
-
parameters?: Record<string, ReadonlyArray<string> | string>;
|
|
286
|
-
/**
|
|
287
|
-
* The Adhese context
|
|
288
|
-
*/
|
|
289
|
-
context: AdheseContext;
|
|
290
|
-
/**
|
|
291
|
-
* The render mode of the slot.
|
|
292
|
-
*
|
|
293
|
-
* - `iframe`: The ad will be rendered in an iframe.
|
|
294
|
-
* - `inline`: The ad will be rendered in the containing element.
|
|
295
|
-
*
|
|
296
|
-
* @default 'iframe'
|
|
297
|
-
*/
|
|
298
|
-
renderMode?: RenderMode;
|
|
299
|
-
/**
|
|
300
|
-
* Callback that is called when the slot is disposed.
|
|
301
|
-
*/
|
|
302
|
-
onDispose?(): void;
|
|
303
|
-
/**
|
|
304
|
-
* Callback that is called when the slot is rendered.
|
|
305
|
-
*/
|
|
306
|
-
onRender?(element: HTMLElement): void;
|
|
307
|
-
/**
|
|
308
|
-
* Callback that is called before the ad is rendered. This can be used to modify the ad before it is rendered.
|
|
309
|
-
* Particularly useful for rendering ads with custom HTML if the ad tag contains a JSON object.
|
|
310
|
-
*/
|
|
311
|
-
onBeforeRender?(ad: AdheseAd): AdheseAd | void;
|
|
312
|
-
/**
|
|
313
|
-
* Callback that is called when the viewability of the slot changes.
|
|
314
|
-
*/
|
|
315
|
-
onViewabilityChanged?(isViewable: boolean): void;
|
|
316
|
-
/**
|
|
317
|
-
* Callback that is called when the request for the slot returns an empty response. This can happen for multiple
|
|
318
|
-
* reasons, for example when the slot is not sold to a buyer.
|
|
319
|
-
*/
|
|
320
|
-
onEmpty?(): void;
|
|
321
|
-
/**
|
|
322
|
-
* Special callback that is run when the slot is initialized. It passes the slot context ref object and a special
|
|
323
|
-
* plugin object that contains a set of hooks you can use to hook into different moments of the slots lifecycle.
|
|
324
|
-
*/
|
|
325
|
-
setup?(context: Ref<AdheseSlot | null>, plugin: {
|
|
326
|
-
/**
|
|
327
|
-
* Hook that is called when the slot is rendered.
|
|
328
|
-
*/
|
|
329
|
-
onRender: ReturnType<typeof createAsyncHook<AdheseAd>>[1];
|
|
330
|
-
/**
|
|
331
|
-
* Hook that is called when the slot is requested from the server.
|
|
332
|
-
*/
|
|
333
|
-
onRequest: ReturnType<typeof createAsyncHook<void>>[1];
|
|
334
|
-
/**
|
|
335
|
-
* Hook that is called when the slot is disposed.
|
|
336
|
-
*/
|
|
337
|
-
onDispose: ReturnType<typeof createPassiveHook>[1];
|
|
338
|
-
}): void;
|
|
339
|
-
} & ({
|
|
340
|
-
/**
|
|
341
|
-
* If the slot should be lazy loaded. This means that the ad will only be requested when the slot is in the viewport.
|
|
342
|
-
* If `true`, the slot will handle the request itself and render the ad.
|
|
343
|
-
*/
|
|
344
|
-
lazyLoading: true;
|
|
345
|
-
lazyLoadingOptions?: {
|
|
346
|
-
/**
|
|
347
|
-
* The root margin of the intersection observer. This is used to determine when the slot is in the viewport.
|
|
348
|
-
*/
|
|
349
|
-
rootMargin?: string;
|
|
350
|
-
};
|
|
351
|
-
} | {
|
|
352
|
-
lazyLoading?: false;
|
|
353
|
-
lazyLoadingOptions?: never;
|
|
354
|
-
});
|
|
355
|
-
type AdheseSlot = Merge<Omit<AdheseSlotOptions, 'onDispose' | 'context' | 'onFormatChange' | 'format' | 'setup'>, {
|
|
356
|
-
/**
|
|
357
|
-
* The name of the slot. This is used to identify the slot in the Adhese instance.
|
|
358
|
-
*
|
|
359
|
-
* The name is generated based on the location, format, and slot of the slot.
|
|
360
|
-
*/
|
|
361
|
-
readonly name: string;
|
|
362
|
-
/**
|
|
363
|
-
* The format code of the slot. Used to find the correct element on the page to render the ad in.
|
|
364
|
-
*
|
|
365
|
-
* If the format is a string, it is used as the format code. If the format is an array, the format code is determined
|
|
366
|
-
* by the query detector.
|
|
367
|
-
*
|
|
368
|
-
* When you change the format, the slot will request a new ad from the API automatically.
|
|
369
|
-
*/
|
|
370
|
-
readonly format: string;
|
|
371
|
-
/**
|
|
372
|
-
* The location of the slot. This is the location that is used to determine the current page URL.
|
|
373
|
-
*/
|
|
374
|
-
readonly location: string;
|
|
375
|
-
/**
|
|
376
|
-
* The parameters that are used to render the ad.
|
|
377
|
-
*/
|
|
378
|
-
parameters: Map<string, ReadonlyArray<string> | string>;
|
|
379
|
-
/**
|
|
380
|
-
* Whether the viewability tracking pixel has been fired.
|
|
381
|
-
*/
|
|
382
|
-
readonly isViewabilityTracked: boolean;
|
|
383
|
-
/**
|
|
384
|
-
* Whether the impression tracking pixel has been fired.
|
|
385
|
-
*/
|
|
386
|
-
readonly isImpressionTracked: boolean;
|
|
387
|
-
/**
|
|
388
|
-
* Ad object that is fetched from the API.
|
|
389
|
-
*/
|
|
390
|
-
ad: AdheseAd | null;
|
|
391
|
-
/**
|
|
392
|
-
* The state of the slot is currently in.
|
|
393
|
-
*
|
|
394
|
-
* - `initializing`: The slot is initializing.
|
|
395
|
-
* - `initialized`: The slot is initialized.
|
|
396
|
-
* - `loading`: The slot is loading data from the API
|
|
397
|
-
* - `loaded`: The slot has loaded data from the API and is ready to render
|
|
398
|
-
* - `empty`: The slot has loaded data from the API but the response was empty
|
|
399
|
-
* - `rendering`: The slot is rendering the ad
|
|
400
|
-
* - `rendered`: The slot has rendered the ad
|
|
401
|
-
* - `error`: The slot has encountered an error
|
|
402
|
-
*/
|
|
403
|
-
readonly status: 'initializing' | 'initialized' | 'loading' | 'loaded' | 'empty' | 'rendering' | 'rendered' | 'error';
|
|
404
|
-
/**
|
|
405
|
-
* Is the slot disposed.
|
|
406
|
-
*/
|
|
407
|
-
readonly isDisposed: boolean;
|
|
408
|
-
/**
|
|
409
|
-
* The element that contains the slot.
|
|
410
|
-
*/
|
|
411
|
-
readonly element: HTMLElement | null;
|
|
412
|
-
/**
|
|
413
|
-
* Unique identifier of the slot. ID is generated on initialization and will never change.
|
|
414
|
-
*/
|
|
415
|
-
readonly id: string;
|
|
416
|
-
/**
|
|
417
|
-
* Renders the slot in the containing element. If no ad is provided, a new ad will be requested from the API.
|
|
418
|
-
*/
|
|
419
|
-
render(ad?: AdheseAd): Promise<HTMLElement | null>;
|
|
420
|
-
/**
|
|
421
|
-
* Requests a new ad from the API and returns the ad object.
|
|
422
|
-
*/
|
|
423
|
-
request(): Promise<AdheseAd | null>;
|
|
424
|
-
/**
|
|
425
|
-
* Removes the slot from the DOM and cleans up the slot instance.
|
|
426
|
-
*/
|
|
427
|
-
dispose(): void;
|
|
428
|
-
}>;
|
|
429
|
-
|
|
430
|
-
type AdheseSlotManager = {
|
|
431
|
-
/**
|
|
432
|
-
* Returns all slots that are currently registered and rendered.
|
|
433
|
-
*/
|
|
434
|
-
getAll(): ReadonlyArray<AdheseSlot>;
|
|
435
|
-
/**
|
|
436
|
-
* Adds a new slot to the Adhese instance and renders it.
|
|
437
|
-
*/
|
|
438
|
-
add(slot: Omit<AdheseSlotOptions, 'context'>): Readonly<AdheseSlot>;
|
|
439
|
-
/**
|
|
440
|
-
* Finds all slots in the DOM and adds them to the Adhese instance.
|
|
441
|
-
*/
|
|
442
|
-
findDomSlots(): Promise<ReadonlyArray<AdheseSlot>>;
|
|
443
|
-
/**
|
|
444
|
-
* Returns the slot with the given name.
|
|
445
|
-
*/
|
|
446
|
-
get(name: string): AdheseSlot | undefined;
|
|
447
|
-
/**
|
|
448
|
-
* Removes all slots from the Adhese instance and cleans up the slot manager.
|
|
449
|
-
*/
|
|
450
|
-
dispose(): void;
|
|
451
|
-
};
|
|
452
|
-
type SlotManagerOptions = {
|
|
453
|
-
/**
|
|
454
|
-
* List of initial slots to add to the slot manager.
|
|
455
|
-
*/
|
|
456
|
-
initialSlots?: ReadonlyArray<Merge<Omit<AdheseSlotOptions, 'containingElement' | 'context' | 'lazy'>, {
|
|
457
|
-
containingElement: string;
|
|
458
|
-
}>>;
|
|
459
|
-
context: AdheseContext;
|
|
460
|
-
};
|
|
461
|
-
|
|
462
397
|
type AdRequestOptions = {
|
|
463
398
|
/**
|
|
464
399
|
* Slot you want to fetch the ad for
|
|
@@ -572,10 +507,6 @@ type AdheseOptions = {
|
|
|
572
507
|
* The query detector options for the Adhese instance.
|
|
573
508
|
*/
|
|
574
509
|
queries?: Record<string, string>;
|
|
575
|
-
/**
|
|
576
|
-
* Enable rendering ads in a SafeFrame.
|
|
577
|
-
*/
|
|
578
|
-
safeFrame?: boolean;
|
|
579
510
|
/**
|
|
580
511
|
* The plugins that are used for the Adhese instance. These plugins are called with the Adhese context and run during
|
|
581
512
|
* the initialization of the Adhese instance.
|
|
@@ -659,14 +590,14 @@ type BaseAdhese = {
|
|
|
659
590
|
* Options passed to the Adhese instance.
|
|
660
591
|
*/
|
|
661
592
|
options: Readonly<MergedOptions>;
|
|
662
|
-
/**
|
|
663
|
-
* The SafeFrame instance that is used for rendering ads in a SafeFrame.
|
|
664
|
-
*/
|
|
665
|
-
safeFrame?: SafeFrame;
|
|
666
593
|
/**
|
|
667
594
|
* Is the instance disposed
|
|
668
595
|
*/
|
|
669
596
|
isDisposed: boolean;
|
|
597
|
+
/**
|
|
598
|
+
* Active media query device
|
|
599
|
+
*/
|
|
600
|
+
device: string;
|
|
670
601
|
/**
|
|
671
602
|
* Get a slot by name.
|
|
672
603
|
* @param name The name of the slot.
|
|
@@ -691,7 +622,7 @@ type BaseAdhese = {
|
|
|
691
622
|
*/
|
|
692
623
|
dispose(): void;
|
|
693
624
|
};
|
|
694
|
-
type ReadonlyProps = 'options' | '
|
|
625
|
+
type ReadonlyProps = 'options' | 'isDisposed' | 'logger' | 'events' | 'get' | 'getAll' | 'addSlot' | 'findDomSlots' | 'dispose' | 'slots' | 'device';
|
|
695
626
|
type Adhese = Omit<BaseAdhese, ReadonlyProps> & Readonly<Pick<BaseAdhese, ReadonlyProps>>;
|
|
696
627
|
type AdheseContextState = Omit<BaseAdhese, 'options'> & {
|
|
697
628
|
readonly options: MergedOptions;
|