@adhese/sdk 0.15.0 → 0.16.1
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 +348 -315
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +224 -219
- package/dist/index.js +349 -316
- package/dist/index.js.map +1 -1
- package/dist/{requestAds.schema-Cb8_FVMb.js → requestAds.schema-DbGNhzE_.js} +4 -69
- package/dist/requestAds.schema-DbGNhzE_.js.map +1 -0
- package/dist/requestAds.schema-lenvDWpb.cjs +104 -0
- package/dist/requestAds.schema-lenvDWpb.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,6 +3,223 @@ 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 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
|
+
];
|
|
22
|
+
|
|
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
|
+
*/
|
|
211
|
+
dispose(): void;
|
|
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
|
+
};
|
|
222
|
+
|
|
6
223
|
declare const baseSchema: zod.ZodObject<{
|
|
7
224
|
adDuration: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodLiteral<"">]>, number | undefined, string>>;
|
|
8
225
|
adFormat: zod.ZodOptional<zod.ZodString>;
|
|
@@ -67,6 +284,7 @@ declare const baseSchema: zod.ZodObject<{
|
|
|
67
284
|
origin: "JERLICIA" | "DALE";
|
|
68
285
|
slotID: string;
|
|
69
286
|
slotName: string;
|
|
287
|
+
body?: string | Record<string, unknown> | readonly unknown[] | undefined;
|
|
70
288
|
adDuration?: number | undefined;
|
|
71
289
|
adFormat?: string | undefined;
|
|
72
290
|
additionalCreativeTracker?: URL | undefined;
|
|
@@ -78,7 +296,6 @@ declare const baseSchema: zod.ZodObject<{
|
|
|
78
296
|
advertiserId?: string | undefined;
|
|
79
297
|
altText?: string | undefined;
|
|
80
298
|
auctionable?: boolean | "" | undefined;
|
|
81
|
-
body?: string | Record<string, unknown> | readonly unknown[] | undefined;
|
|
82
299
|
clickTag?: URL | undefined;
|
|
83
300
|
comment?: string | undefined;
|
|
84
301
|
creativeName?: string | undefined;
|
|
@@ -119,6 +336,7 @@ declare const baseSchema: zod.ZodObject<{
|
|
|
119
336
|
origin: "JERLICIA" | "DALE";
|
|
120
337
|
slotID: string;
|
|
121
338
|
slotName: string;
|
|
339
|
+
body?: string | undefined;
|
|
122
340
|
adDuration?: string | undefined;
|
|
123
341
|
adFormat?: string | undefined;
|
|
124
342
|
additionalCreativeTracker?: string | undefined;
|
|
@@ -130,7 +348,6 @@ declare const baseSchema: zod.ZodObject<{
|
|
|
130
348
|
advertiserId?: string | undefined;
|
|
131
349
|
altText?: string | undefined;
|
|
132
350
|
auctionable?: boolean | "" | undefined;
|
|
133
|
-
body?: string | undefined;
|
|
134
351
|
clickTag?: string | undefined;
|
|
135
352
|
comment?: string | undefined;
|
|
136
353
|
creativeName?: string | undefined;
|
|
@@ -177,222 +394,6 @@ type AdheseAd<T = string | Record<string, unknown> | ReadonlyArray<unknown>> = O
|
|
|
177
394
|
tag: T | string;
|
|
178
395
|
};
|
|
179
396
|
|
|
180
|
-
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, }?: {
|
|
181
|
-
onRun?(callbacks?: Set<Callback>): void;
|
|
182
|
-
onAdd?(callbacks?: Set<Callback>): void;
|
|
183
|
-
}): [
|
|
184
|
-
run: Argument extends void ? () => Promise<void> : (arg: Argument) => Promise<Argument>,
|
|
185
|
-
add: (callback: Callback) => () => void,
|
|
186
|
-
dispose: () => void
|
|
187
|
-
];
|
|
188
|
-
declare function createPassiveHook<Argument = void, Callback extends (arg: Argument) => void | Promise<void> = (arg: Argument) => void | Promise<void>>(name: string, { onRun, onAdd, }?: {
|
|
189
|
-
onRun?(callbacks?: Set<Callback>): void;
|
|
190
|
-
onAdd?(callbacks?: Set<Callback>): void;
|
|
191
|
-
}): [
|
|
192
|
-
run: (arg: Argument) => void,
|
|
193
|
-
add: (callback: Callback) => () => void,
|
|
194
|
-
dispose: () => void
|
|
195
|
-
];
|
|
196
|
-
|
|
197
|
-
type RenderMode = 'iframe' | 'inline' | 'none';
|
|
198
|
-
type AdheseSlotOptions = {
|
|
199
|
-
/**
|
|
200
|
-
* 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
|
|
201
|
-
* string, it is used as the format code. If the format is an array, the format code is determined by the query
|
|
202
|
-
* detector.
|
|
203
|
-
*/
|
|
204
|
-
format: string | ReadonlyArray<{
|
|
205
|
-
format: string;
|
|
206
|
-
query: string;
|
|
207
|
-
}>;
|
|
208
|
-
/**
|
|
209
|
-
* If we have multiple slots with the same format, we can use this to differentiate between them.
|
|
210
|
-
*/
|
|
211
|
-
slot?: string;
|
|
212
|
-
/**
|
|
213
|
-
* The element that contains the slot. Used to find the correct element on the page to render the ad in.
|
|
214
|
-
*/
|
|
215
|
-
containingElement?: string | HTMLElement;
|
|
216
|
-
/**
|
|
217
|
-
* The parameters that are used to render the ad.
|
|
218
|
-
*/
|
|
219
|
-
parameters?: Record<string, ReadonlyArray<string> | string>;
|
|
220
|
-
/**
|
|
221
|
-
* The Adhese context
|
|
222
|
-
*/
|
|
223
|
-
context: AdheseContext;
|
|
224
|
-
/**
|
|
225
|
-
* The render mode of the slot.
|
|
226
|
-
*
|
|
227
|
-
* - `iframe`: The ad will be rendered in an iframe.
|
|
228
|
-
* - `inline`: The ad will be rendered in the containing element.
|
|
229
|
-
*
|
|
230
|
-
* @default 'iframe'
|
|
231
|
-
*/
|
|
232
|
-
renderMode?: RenderMode;
|
|
233
|
-
/**
|
|
234
|
-
* Callback that is called when the slot is disposed.
|
|
235
|
-
*/
|
|
236
|
-
onDispose?(): void;
|
|
237
|
-
/**
|
|
238
|
-
* Callback that is called when the slot is rendered.
|
|
239
|
-
*/
|
|
240
|
-
onRender?(element: HTMLElement): void;
|
|
241
|
-
/**
|
|
242
|
-
* Callback that is called before the ad is rendered. This can be used to modify the ad before it is rendered.
|
|
243
|
-
* Particularly useful for rendering ads with custom HTML if the ad tag contains a JSON object.
|
|
244
|
-
*/
|
|
245
|
-
onBeforeRender?(ad: AdheseAd): AdheseAd | void;
|
|
246
|
-
/**
|
|
247
|
-
* Callback that is called when the viewability of the slot changes.
|
|
248
|
-
*/
|
|
249
|
-
onViewabilityChanged?(isViewable: boolean): void;
|
|
250
|
-
/**
|
|
251
|
-
* Callback that is called when the request for the slot returns an empty response. This can happen for multiple
|
|
252
|
-
* reasons, for example when the slot is not sold to a buyer.
|
|
253
|
-
*/
|
|
254
|
-
onEmpty?(): void;
|
|
255
|
-
/**
|
|
256
|
-
* Special callback that is run when the slot is initialized. It passes the slot context ref object and a special
|
|
257
|
-
* plugin object that contains a set of hooks you can use to hook into different moments of the slots lifecycle.
|
|
258
|
-
*/
|
|
259
|
-
setup?(context: Ref<AdheseSlot | null>, plugin: {
|
|
260
|
-
/**
|
|
261
|
-
* Hook that is called when the slot is rendered.
|
|
262
|
-
*/
|
|
263
|
-
onRender: ReturnType<typeof createAsyncHook<AdheseAd>>[1];
|
|
264
|
-
/**
|
|
265
|
-
* Hook that is called when the slot is requested from the server.
|
|
266
|
-
*/
|
|
267
|
-
onRequest: ReturnType<typeof createAsyncHook<void>>[1];
|
|
268
|
-
/**
|
|
269
|
-
* Hook that is called when the slot is disposed.
|
|
270
|
-
*/
|
|
271
|
-
onDispose: ReturnType<typeof createPassiveHook>[1];
|
|
272
|
-
}): void;
|
|
273
|
-
} & ({
|
|
274
|
-
/**
|
|
275
|
-
* If the slot should be lazy loaded. This means that the ad will only be requested when the slot is in the viewport.
|
|
276
|
-
* If `true`, the slot will handle the request itself and render the ad.
|
|
277
|
-
*/
|
|
278
|
-
lazyLoading: true;
|
|
279
|
-
lazyLoadingOptions?: {
|
|
280
|
-
/**
|
|
281
|
-
* The root margin of the intersection observer. This is used to determine when the slot is in the viewport.
|
|
282
|
-
*/
|
|
283
|
-
rootMargin?: string;
|
|
284
|
-
};
|
|
285
|
-
} | {
|
|
286
|
-
lazyLoading?: false;
|
|
287
|
-
lazyLoadingOptions?: never;
|
|
288
|
-
});
|
|
289
|
-
type AdheseSlot = Merge<Omit<AdheseSlotOptions, 'onDispose' | 'context' | 'onFormatChange' | 'format' | 'setup'>, {
|
|
290
|
-
/**
|
|
291
|
-
* The name of the slot. This is used to identify the slot in the Adhese instance.
|
|
292
|
-
*
|
|
293
|
-
* The name is generated based on the location, format, and slot of the slot.
|
|
294
|
-
*/
|
|
295
|
-
readonly name: string;
|
|
296
|
-
/**
|
|
297
|
-
* The format code of the slot. Used to find the correct element on the page to render the ad in.
|
|
298
|
-
*
|
|
299
|
-
* If the format is a string, it is used as the format code. If the format is an array, the format code is determined
|
|
300
|
-
* by the query detector.
|
|
301
|
-
*
|
|
302
|
-
* When you change the format, the slot will request a new ad from the API automatically.
|
|
303
|
-
*/
|
|
304
|
-
readonly format: string;
|
|
305
|
-
/**
|
|
306
|
-
* The location of the slot. This is the location that is used to determine the current page URL.
|
|
307
|
-
*/
|
|
308
|
-
readonly location: string;
|
|
309
|
-
/**
|
|
310
|
-
* The parameters that are used to render the ad.
|
|
311
|
-
*/
|
|
312
|
-
parameters: Map<string, ReadonlyArray<string> | string>;
|
|
313
|
-
/**
|
|
314
|
-
* Whether the viewability tracking pixel has been fired.
|
|
315
|
-
*/
|
|
316
|
-
readonly isViewabilityTracked: boolean;
|
|
317
|
-
/**
|
|
318
|
-
* Whether the impression tracking pixel has been fired.
|
|
319
|
-
*/
|
|
320
|
-
readonly isImpressionTracked: boolean;
|
|
321
|
-
/**
|
|
322
|
-
* Ad object that is fetched from the API.
|
|
323
|
-
*/
|
|
324
|
-
ad: AdheseAd | null;
|
|
325
|
-
/**
|
|
326
|
-
* The state of the slot is currently in.
|
|
327
|
-
*
|
|
328
|
-
* - `initializing`: The slot is initializing.
|
|
329
|
-
* - `initialized`: The slot is initialized.
|
|
330
|
-
* - `loading`: The slot is loading data from the API
|
|
331
|
-
* - `loaded`: The slot has loaded data from the API and is ready to render
|
|
332
|
-
* - `empty`: The slot has loaded data from the API but the response was empty
|
|
333
|
-
* - `rendering`: The slot is rendering the ad
|
|
334
|
-
* - `rendered`: The slot has rendered the ad
|
|
335
|
-
* - `error`: The slot has encountered an error
|
|
336
|
-
*/
|
|
337
|
-
readonly status: 'initializing' | 'initialized' | 'loading' | 'loaded' | 'empty' | 'rendering' | 'rendered' | 'error';
|
|
338
|
-
/**
|
|
339
|
-
* Is the slot disposed.
|
|
340
|
-
*/
|
|
341
|
-
readonly isDisposed: boolean;
|
|
342
|
-
/**
|
|
343
|
-
* The element that contains the slot.
|
|
344
|
-
*/
|
|
345
|
-
readonly element: HTMLElement | null;
|
|
346
|
-
/**
|
|
347
|
-
* Unique identifier of the slot. ID is generated on initialization and will never change.
|
|
348
|
-
*/
|
|
349
|
-
readonly id: string;
|
|
350
|
-
/**
|
|
351
|
-
* Renders the slot in the containing element. If no ad is provided, a new ad will be requested from the API.
|
|
352
|
-
*/
|
|
353
|
-
render(ad?: AdheseAd): Promise<HTMLElement | null>;
|
|
354
|
-
/**
|
|
355
|
-
* Requests a new ad from the API and returns the ad object.
|
|
356
|
-
*/
|
|
357
|
-
request(): Promise<AdheseAd | null>;
|
|
358
|
-
/**
|
|
359
|
-
* Removes the slot from the DOM and cleans up the slot instance.
|
|
360
|
-
*/
|
|
361
|
-
dispose(): void;
|
|
362
|
-
}>;
|
|
363
|
-
|
|
364
|
-
type AdheseSlotManager = {
|
|
365
|
-
/**
|
|
366
|
-
* Returns all slots that are currently registered and rendered.
|
|
367
|
-
*/
|
|
368
|
-
getAll(): ReadonlyArray<AdheseSlot>;
|
|
369
|
-
/**
|
|
370
|
-
* Adds a new slot to the Adhese instance and renders it.
|
|
371
|
-
*/
|
|
372
|
-
add(slot: Omit<AdheseSlotOptions, 'context'>): Readonly<AdheseSlot>;
|
|
373
|
-
/**
|
|
374
|
-
* Finds all slots in the DOM and adds them to the Adhese instance.
|
|
375
|
-
*/
|
|
376
|
-
findDomSlots(): Promise<ReadonlyArray<AdheseSlot>>;
|
|
377
|
-
/**
|
|
378
|
-
* Returns the slot with the given name.
|
|
379
|
-
*/
|
|
380
|
-
get(name: string): AdheseSlot | undefined;
|
|
381
|
-
/**
|
|
382
|
-
* Removes all slots from the Adhese instance and cleans up the slot manager.
|
|
383
|
-
*/
|
|
384
|
-
dispose(): void;
|
|
385
|
-
};
|
|
386
|
-
type SlotManagerOptions = {
|
|
387
|
-
/**
|
|
388
|
-
* List of initial slots to add to the slot manager.
|
|
389
|
-
*/
|
|
390
|
-
initialSlots?: ReadonlyArray<Merge<Omit<AdheseSlotOptions, 'containingElement' | 'context' | 'lazy'>, {
|
|
391
|
-
containingElement: string;
|
|
392
|
-
}>>;
|
|
393
|
-
context: AdheseContext;
|
|
394
|
-
};
|
|
395
|
-
|
|
396
397
|
type AdRequestOptions = {
|
|
397
398
|
/**
|
|
398
399
|
* Slot you want to fetch the ad for
|
|
@@ -593,6 +594,10 @@ type BaseAdhese = {
|
|
|
593
594
|
* Is the instance disposed
|
|
594
595
|
*/
|
|
595
596
|
isDisposed: boolean;
|
|
597
|
+
/**
|
|
598
|
+
* Active media query device
|
|
599
|
+
*/
|
|
600
|
+
device: string;
|
|
596
601
|
/**
|
|
597
602
|
* Get a slot by name.
|
|
598
603
|
* @param name The name of the slot.
|
|
@@ -617,7 +622,7 @@ type BaseAdhese = {
|
|
|
617
622
|
*/
|
|
618
623
|
dispose(): void;
|
|
619
624
|
};
|
|
620
|
-
type ReadonlyProps = 'options' | 'isDisposed' | 'logger' | 'events' | 'get' | 'getAll' | 'addSlot' | 'findDomSlots' | 'dispose' | 'slots';
|
|
625
|
+
type ReadonlyProps = 'options' | 'isDisposed' | 'logger' | 'events' | 'get' | 'getAll' | 'addSlot' | 'findDomSlots' | 'dispose' | 'slots' | 'device';
|
|
621
626
|
type Adhese = Omit<BaseAdhese, ReadonlyProps> & Readonly<Pick<BaseAdhese, ReadonlyProps>>;
|
|
622
627
|
type AdheseContextState = Omit<BaseAdhese, 'options'> & {
|
|
623
628
|
readonly options: MergedOptions;
|