@zeroclickai/offers-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.
- package/README.md +322 -0
- package/dist/index.cjs +12 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +564 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +564 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.iife.js +12 -0
- package/dist/index.iife.js.map +1 -0
- package/dist/index.mjs +12 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +63 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* User identity context provided during initialization
|
|
4
|
+
*/
|
|
5
|
+
interface Identity {
|
|
6
|
+
/** Tenant client user ID */
|
|
7
|
+
userId?: string;
|
|
8
|
+
/** SHA-256 hash of user email address (lowercase, trimmed before hashing) */
|
|
9
|
+
userEmailSha256?: string;
|
|
10
|
+
/** SHA-256 hash of user phone number (E.164 format before hashing) */
|
|
11
|
+
userPhoneNumberSha256?: string;
|
|
12
|
+
/** User locale/language code (e.g., 'en-US') */
|
|
13
|
+
userLocale?: string;
|
|
14
|
+
/** Session identifier for session-level tracking */
|
|
15
|
+
userSessionId?: string;
|
|
16
|
+
/** Tenant-defined grouping ID for analytics segmentation */
|
|
17
|
+
groupingId?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Configuration for initializing the ZeroClick SDK
|
|
21
|
+
*/
|
|
22
|
+
interface ZeroClickConfig {
|
|
23
|
+
/** ZeroClick Tenant Client API key (required for getOffers) */
|
|
24
|
+
apiKey?: string;
|
|
25
|
+
/** User identity context */
|
|
26
|
+
identity?: Identity;
|
|
27
|
+
/** Base URL for the API (defaults to production) */
|
|
28
|
+
baseUrl?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Options for fetching offers (server-side only)
|
|
32
|
+
*/
|
|
33
|
+
interface GetOffersOptions {
|
|
34
|
+
/** Client IP address (required for server-to-server requests) */
|
|
35
|
+
ipAddress: string;
|
|
36
|
+
/** Search query for offers */
|
|
37
|
+
query?: string;
|
|
38
|
+
/** Maximum number of offers to return (default: 1) */
|
|
39
|
+
limit?: number;
|
|
40
|
+
/** Client user agent string */
|
|
41
|
+
userAgent?: string;
|
|
42
|
+
/** Client origin/referer URL */
|
|
43
|
+
origin?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Product availability status
|
|
47
|
+
*/
|
|
48
|
+
type ProductAvailability = 'in_stock' | 'limited' | 'out_of_stock';
|
|
49
|
+
/**
|
|
50
|
+
* Distance unit for location
|
|
51
|
+
*/
|
|
52
|
+
type DistanceUnit = 'km' | 'mi';
|
|
53
|
+
/**
|
|
54
|
+
* Brand information for an offer
|
|
55
|
+
*/
|
|
56
|
+
interface Brand {
|
|
57
|
+
/** Name of the brand */
|
|
58
|
+
name: string;
|
|
59
|
+
/** Description of the brand */
|
|
60
|
+
description: string | null;
|
|
61
|
+
/** URL of the brand's website */
|
|
62
|
+
url: string | null;
|
|
63
|
+
/** URL of the brand's icon or logo */
|
|
64
|
+
iconUrl: string | null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Product information for an offer
|
|
68
|
+
*/
|
|
69
|
+
interface Product {
|
|
70
|
+
/** Product ID */
|
|
71
|
+
productId: string | null;
|
|
72
|
+
/** Stock keeping unit */
|
|
73
|
+
sku: string | null;
|
|
74
|
+
/** Product title */
|
|
75
|
+
title: string;
|
|
76
|
+
/** Product description */
|
|
77
|
+
description: string | null;
|
|
78
|
+
/** Product category */
|
|
79
|
+
category: string | null;
|
|
80
|
+
/** Product subcategory */
|
|
81
|
+
subcategory: string | null;
|
|
82
|
+
/** Product image URL */
|
|
83
|
+
image: string | null;
|
|
84
|
+
/** Product availability status */
|
|
85
|
+
availability: ProductAvailability | null;
|
|
86
|
+
/** Additional product metadata */
|
|
87
|
+
metadata: Record<string, unknown> | null;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Pricing information for an offer
|
|
91
|
+
*/
|
|
92
|
+
interface Price {
|
|
93
|
+
/** Current price amount */
|
|
94
|
+
amount: string | null;
|
|
95
|
+
/** Currency code (e.g., 'USD') */
|
|
96
|
+
currency: string | null;
|
|
97
|
+
/** Original price before discounts */
|
|
98
|
+
originalPrice: string | null;
|
|
99
|
+
/** Discount amount or percentage */
|
|
100
|
+
discount: string | null;
|
|
101
|
+
/** Billing interval for subscriptions (e.g., 'monthly', 'yearly') */
|
|
102
|
+
interval: string | null;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Geographical coordinates
|
|
106
|
+
*/
|
|
107
|
+
interface Coordinates {
|
|
108
|
+
/** Latitude */
|
|
109
|
+
lat: number;
|
|
110
|
+
/** Longitude */
|
|
111
|
+
lng: number;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Location information for an offer
|
|
115
|
+
*/
|
|
116
|
+
interface Location {
|
|
117
|
+
/** Full address as plain text */
|
|
118
|
+
text: string;
|
|
119
|
+
/** Street address */
|
|
120
|
+
address: string | null;
|
|
121
|
+
/** City */
|
|
122
|
+
city: string | null;
|
|
123
|
+
/** State or region */
|
|
124
|
+
state: string | null;
|
|
125
|
+
/** ZIP or postal code */
|
|
126
|
+
zip: number | null;
|
|
127
|
+
/** Distance from user */
|
|
128
|
+
distance: number | null;
|
|
129
|
+
/** Unit of distance measurement */
|
|
130
|
+
distanceUnit: DistanceUnit | null;
|
|
131
|
+
/** Geographical coordinates */
|
|
132
|
+
coordinates: Coordinates | null;
|
|
133
|
+
/** Operating hours */
|
|
134
|
+
hours: string | null;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Media content information for an offer
|
|
138
|
+
*/
|
|
139
|
+
interface Media {
|
|
140
|
+
/** Content title */
|
|
141
|
+
title: string | null;
|
|
142
|
+
/** Content URL */
|
|
143
|
+
url: string | null;
|
|
144
|
+
/** Content description */
|
|
145
|
+
description: string | null;
|
|
146
|
+
/** Type of content (article, video, book, etc.) */
|
|
147
|
+
contentType: string;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Rating information for an offer
|
|
151
|
+
*/
|
|
152
|
+
interface Rating {
|
|
153
|
+
/** Rating value */
|
|
154
|
+
value: number;
|
|
155
|
+
/** Rating scale (e.g., 5 for 5-star, 100 for percentage) */
|
|
156
|
+
scale: number;
|
|
157
|
+
/** Number of ratings */
|
|
158
|
+
count: number | null;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* UI rendering configuration returned by the API
|
|
162
|
+
*/
|
|
163
|
+
interface OfferUI {
|
|
164
|
+
/** Render type discriminator (e.g., 'iframe') */
|
|
165
|
+
type: string;
|
|
166
|
+
/** URL for the UI content (e.g., iframe src) */
|
|
167
|
+
url: string;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* An offer returned from the ZeroClick API
|
|
171
|
+
*/
|
|
172
|
+
interface Offer {
|
|
173
|
+
/** Unique offer ID */
|
|
174
|
+
id: string;
|
|
175
|
+
/** Offer title */
|
|
176
|
+
title: string | null;
|
|
177
|
+
/** Offer subtitle */
|
|
178
|
+
subtitle: string | null;
|
|
179
|
+
/** Detailed content/description */
|
|
180
|
+
content: string | null;
|
|
181
|
+
/** Call to action text */
|
|
182
|
+
cta: string | null;
|
|
183
|
+
/** Click-through URL */
|
|
184
|
+
clickUrl: string;
|
|
185
|
+
/** Raw URL encoded (not for LLM use) */
|
|
186
|
+
rawUrlEncoded: string | null;
|
|
187
|
+
/** Offer image URL */
|
|
188
|
+
imageUrl: string | null;
|
|
189
|
+
/** Additional offer metadata */
|
|
190
|
+
metadata: Record<string, unknown> | null;
|
|
191
|
+
/** Additional context about the offer */
|
|
192
|
+
context: string | null;
|
|
193
|
+
/** Brand information */
|
|
194
|
+
brand: Brand | null;
|
|
195
|
+
/** Product information */
|
|
196
|
+
product: Product | null;
|
|
197
|
+
/** Pricing information */
|
|
198
|
+
price: Price | null;
|
|
199
|
+
/** Location information */
|
|
200
|
+
location: Location | null;
|
|
201
|
+
/** Media content information */
|
|
202
|
+
media: Media | null;
|
|
203
|
+
/** Rating information */
|
|
204
|
+
rating: Rating | null;
|
|
205
|
+
/** UI configuration for iframe rendering (optional) */
|
|
206
|
+
ui?: OfferUI | null;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Context collected and sent with each API request
|
|
210
|
+
*/
|
|
211
|
+
interface RequestContext {
|
|
212
|
+
/** Anonymous ID for user tracking (persisted across sessions) */
|
|
213
|
+
anonymousId: string;
|
|
214
|
+
/** Session ID for this specific session (not persisted) */
|
|
215
|
+
sessionId: string;
|
|
216
|
+
/** SDK version */
|
|
217
|
+
sdkVersion: string;
|
|
218
|
+
/** User agent string */
|
|
219
|
+
userAgent?: string;
|
|
220
|
+
/** Request timestamp (ISO 8601) */
|
|
221
|
+
timestamp: string;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* API error response
|
|
225
|
+
*/
|
|
226
|
+
interface ApiError {
|
|
227
|
+
/** Error message */
|
|
228
|
+
message: string;
|
|
229
|
+
/** HTTP status code */
|
|
230
|
+
status: number;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Iframe theme/mode
|
|
234
|
+
*/
|
|
235
|
+
type IframeMode = 'light' | 'dark';
|
|
236
|
+
/**
|
|
237
|
+
* Style configuration for iframe ad rendering.
|
|
238
|
+
* Allows surfaces to match their host theme (e.g., VS Code color palette).
|
|
239
|
+
* If not provided, the iframe renders a default black/white theme based on mode.
|
|
240
|
+
*/
|
|
241
|
+
interface IframeStyleConfig {
|
|
242
|
+
/** Background color (e.g., '#1a1a2e') */
|
|
243
|
+
background?: string;
|
|
244
|
+
/** Background hover color (e.g., '#252540') */
|
|
245
|
+
backgroundHover?: string;
|
|
246
|
+
/** Border color (e.g., '#333333') */
|
|
247
|
+
borderColor?: string;
|
|
248
|
+
/** Border radius (e.g., '12px') */
|
|
249
|
+
borderRadius?: string;
|
|
250
|
+
/** Button/CTA background color (e.g., '#4a9eff') */
|
|
251
|
+
buttonBackground?: string;
|
|
252
|
+
/** Button/CTA hover background color (e.g., '#3a8eef') */
|
|
253
|
+
buttonBackgroundHover?: string;
|
|
254
|
+
/** Button/CTA text color (e.g., '#ffffff') */
|
|
255
|
+
buttonTextColor?: string;
|
|
256
|
+
/** Primary text color (e.g., '#ffffff') */
|
|
257
|
+
textColor?: string;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Event passed to the onCtaClick callback when a user clicks the CTA
|
|
261
|
+
*/
|
|
262
|
+
interface CtaClickEvent {
|
|
263
|
+
/** The click-through URL */
|
|
264
|
+
url: string;
|
|
265
|
+
/** The offer ID that was clicked */
|
|
266
|
+
offerId: string;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Options for rendering offers as iframes (browser only)
|
|
270
|
+
*/
|
|
271
|
+
interface IframeRenderOptions {
|
|
272
|
+
/** Theme/mode (URL param: m) */
|
|
273
|
+
mode?: IframeMode;
|
|
274
|
+
/** Style configuration to match host surface theme */
|
|
275
|
+
style?: IframeStyleConfig;
|
|
276
|
+
/** CSS width value (e.g., '300px', '100%') */
|
|
277
|
+
width?: string;
|
|
278
|
+
/** CSS height value (e.g., '250px') */
|
|
279
|
+
height?: string;
|
|
280
|
+
/** Sandbox attributes for iframe */
|
|
281
|
+
sandbox?: string;
|
|
282
|
+
/** Base URL for iframe pages (default: 'https://ui.zero.click') */
|
|
283
|
+
baseUrl?: string;
|
|
284
|
+
/**
|
|
285
|
+
* Callback invoked when the user clicks the CTA in the iframe.
|
|
286
|
+
* If not provided, the click message is ignored (native navigation handles it).
|
|
287
|
+
*
|
|
288
|
+
* Use this in environments where popups are blocked (e.g., VS Code webviews):
|
|
289
|
+
* ```typescript
|
|
290
|
+
* onCtaClick: ({ url }) => vscode.env.openExternal(vscode.Uri.parse(url))
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
onCtaClick?: (event: CtaClickEvent) => void;
|
|
294
|
+
/** Enable auto-height: iframe reports its content height and the SDK adjusts the iframe element */
|
|
295
|
+
autoHeight?: boolean;
|
|
296
|
+
/** Minimum height in pixels when autoHeight is enabled (default: 50) */
|
|
297
|
+
minHeight?: number;
|
|
298
|
+
/** Maximum height in pixels when autoHeight is enabled */
|
|
299
|
+
maxHeight?: number;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Message type constant for offer data postMessage
|
|
303
|
+
*/
|
|
304
|
+
declare const OFFER_DATA_MESSAGE_TYPE: "zeroclick:offer-data";
|
|
305
|
+
/**
|
|
306
|
+
* Message type constant for style update postMessage
|
|
307
|
+
*/
|
|
308
|
+
declare const STYLE_UPDATE_MESSAGE_TYPE: "zeroclick:style-update";
|
|
309
|
+
/**
|
|
310
|
+
* Message type constant for CTA click postMessage (iframe → parent)
|
|
311
|
+
*/
|
|
312
|
+
declare const CTA_CLICK_MESSAGE_TYPE: "zeroclick:cta-click";
|
|
313
|
+
/**
|
|
314
|
+
* Message type constant for resize postMessage (iframe → parent)
|
|
315
|
+
*/
|
|
316
|
+
declare const RESIZE_MESSAGE_TYPE: "zeroclick:resize";
|
|
317
|
+
/**
|
|
318
|
+
* PostMessage payload sent from SDK to iframe on initial render
|
|
319
|
+
*/
|
|
320
|
+
interface OfferDataMessage {
|
|
321
|
+
/** Message type identifier */
|
|
322
|
+
type: typeof OFFER_DATA_MESSAGE_TYPE;
|
|
323
|
+
/** Protocol version */
|
|
324
|
+
version: '1.0';
|
|
325
|
+
/** Full offer data */
|
|
326
|
+
offer: Offer;
|
|
327
|
+
/** Style configuration to match host surface theme */
|
|
328
|
+
style?: IframeStyleConfig;
|
|
329
|
+
/** Whether the iframe should report its content height for auto-sizing */
|
|
330
|
+
autoHeight?: boolean;
|
|
331
|
+
/** Message timestamp */
|
|
332
|
+
timestamp: number;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* PostMessage payload sent from SDK to iframe on style update
|
|
336
|
+
*/
|
|
337
|
+
interface StyleUpdateMessage {
|
|
338
|
+
/** Message type identifier */
|
|
339
|
+
type: typeof STYLE_UPDATE_MESSAGE_TYPE;
|
|
340
|
+
/** Protocol version */
|
|
341
|
+
version: '1.0';
|
|
342
|
+
/** Updated style configuration */
|
|
343
|
+
style: IframeStyleConfig;
|
|
344
|
+
/** Message timestamp */
|
|
345
|
+
timestamp: number;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* PostMessage payload sent from iframe to parent when CTA is clicked
|
|
349
|
+
*/
|
|
350
|
+
interface CtaClickMessage {
|
|
351
|
+
/** Message type identifier */
|
|
352
|
+
type: typeof CTA_CLICK_MESSAGE_TYPE;
|
|
353
|
+
/** Protocol version */
|
|
354
|
+
version: '1.0';
|
|
355
|
+
/** The click-through URL */
|
|
356
|
+
url: string;
|
|
357
|
+
/** The offer ID associated with this click */
|
|
358
|
+
offerId: string;
|
|
359
|
+
/** Message timestamp */
|
|
360
|
+
timestamp: number;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* PostMessage payload sent from iframe to parent when content height changes
|
|
364
|
+
*/
|
|
365
|
+
interface ResizeMessage {
|
|
366
|
+
/** Message type identifier */
|
|
367
|
+
type: typeof RESIZE_MESSAGE_TYPE;
|
|
368
|
+
/** Protocol version */
|
|
369
|
+
version: '1.0';
|
|
370
|
+
/** Content height in pixels */
|
|
371
|
+
height: number;
|
|
372
|
+
/** Message timestamp */
|
|
373
|
+
timestamp: number;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Handle returned by renderOffer for controlling a rendered iframe
|
|
377
|
+
*/
|
|
378
|
+
interface RenderHandle {
|
|
379
|
+
/** Send updated style configuration to the iframe via postMessage */
|
|
380
|
+
updateStyle(style: IframeStyleConfig): void;
|
|
381
|
+
/** Remove the iframe from the DOM */
|
|
382
|
+
destroy(): void;
|
|
383
|
+
}
|
|
384
|
+
//#endregion
|
|
385
|
+
//#region src/client.d.ts
|
|
386
|
+
/**
|
|
387
|
+
* ZeroClick SDK client
|
|
388
|
+
*
|
|
389
|
+
* Provides methods for fetching offers (server-side) and tracking impressions (client-side).
|
|
390
|
+
* Must be initialized with `ZeroClick.initialize()` before use.
|
|
391
|
+
*
|
|
392
|
+
* @example
|
|
393
|
+
* ```typescript
|
|
394
|
+
* import { ZeroClick } from '@zeroclickai/offers-sdk';
|
|
395
|
+
*
|
|
396
|
+
* // Initialize once on server startup
|
|
397
|
+
* ZeroClick.initialize({
|
|
398
|
+
* apiKey: 'your-api-key',
|
|
399
|
+
* identity: {
|
|
400
|
+
* userId: 'user-123',
|
|
401
|
+
* userLocale: 'en-US',
|
|
402
|
+
* },
|
|
403
|
+
* });
|
|
404
|
+
*
|
|
405
|
+
* // In your API route handler (server-side only)
|
|
406
|
+
* app.post('/api/offers', async (req, res) => {
|
|
407
|
+
* const offers = await ZeroClick.getOffers({
|
|
408
|
+
* ipAddress: req.ip,
|
|
409
|
+
* userAgent: req.headers['user-agent'],
|
|
410
|
+
* query: 'running shoes',
|
|
411
|
+
* limit: 3
|
|
412
|
+
* });
|
|
413
|
+
* res.json(offers);
|
|
414
|
+
* });
|
|
415
|
+
*
|
|
416
|
+
* // Track impressions (can be called client-side)
|
|
417
|
+
* await ZeroClick.trackOfferImpressions(['offer-123']);
|
|
418
|
+
* ```
|
|
419
|
+
*/
|
|
420
|
+
declare class ZeroClick {
|
|
421
|
+
private static config;
|
|
422
|
+
private static apiClient;
|
|
423
|
+
/**
|
|
424
|
+
* Initialize the ZeroClick SDK
|
|
425
|
+
*
|
|
426
|
+
* @param config - Configuration object containing optional API key and identity
|
|
427
|
+
*/
|
|
428
|
+
static initialize(config?: ZeroClickConfig): void;
|
|
429
|
+
/**
|
|
430
|
+
* Check if the SDK has been initialized
|
|
431
|
+
*/
|
|
432
|
+
static isInitialized(): boolean;
|
|
433
|
+
/**
|
|
434
|
+
* Reset the SDK state (useful for testing)
|
|
435
|
+
*/
|
|
436
|
+
static reset(): void;
|
|
437
|
+
/**
|
|
438
|
+
* Get offers based on intent signals (server-side only)
|
|
439
|
+
*
|
|
440
|
+
* This method must be called from your backend server, not from the browser.
|
|
441
|
+
* Pass the client's IP address from the incoming request.
|
|
442
|
+
*
|
|
443
|
+
* @param options - Options for fetching offers (ipAddress is required)
|
|
444
|
+
* @returns Promise resolving to an array of Offer objects
|
|
445
|
+
* @throws Error if SDK is not initialized
|
|
446
|
+
* @throws Error if apiKey was not provided during initialization
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* ```typescript
|
|
450
|
+
* // In your backend (Express, Next.js API route, etc.)
|
|
451
|
+
* app.post('/api/offers', async (req, res) => {
|
|
452
|
+
* const clientIp = req.ip || req.headers['x-forwarded-for'];
|
|
453
|
+
*
|
|
454
|
+
* const offers = await ZeroClick.getOffers({
|
|
455
|
+
* ipAddress: clientIp,
|
|
456
|
+
* userAgent: req.headers['user-agent'],
|
|
457
|
+
* query: req.body.query,
|
|
458
|
+
* limit: 3,
|
|
459
|
+
* });
|
|
460
|
+
*
|
|
461
|
+
* res.json(offers);
|
|
462
|
+
* });
|
|
463
|
+
* ```
|
|
464
|
+
*/
|
|
465
|
+
static getOffers(options: GetOffersOptions): Promise<Offer[]>;
|
|
466
|
+
/**
|
|
467
|
+
* Track offer impressions
|
|
468
|
+
*
|
|
469
|
+
* @param ids - Array of offer IDs that were displayed to the user
|
|
470
|
+
* @throws Error if SDK is not initialized
|
|
471
|
+
* @throws Error if ids is empty
|
|
472
|
+
*
|
|
473
|
+
* @example
|
|
474
|
+
* ```typescript
|
|
475
|
+
* await ZeroClick.trackOfferImpressions(['offer-123', 'offer-456']);
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
478
|
+
static trackOfferImpressions(ids: string[]): Promise<void>;
|
|
479
|
+
/**
|
|
480
|
+
* Get iframe URL for an offer
|
|
481
|
+
*
|
|
482
|
+
* Returns the iframe source URL from the offer's UI configuration.
|
|
483
|
+
* Returns null if the offer doesn't have iframe rendering configured.
|
|
484
|
+
*
|
|
485
|
+
* @param offer - The offer to get the iframe URL for
|
|
486
|
+
* @returns The iframe URL string, or null if not available
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* ```typescript
|
|
490
|
+
* const url = ZeroClick.getIframeUrl(offer);
|
|
491
|
+
* if (url) {
|
|
492
|
+
* // Use the iframe URL
|
|
493
|
+
* }
|
|
494
|
+
* ```
|
|
495
|
+
*/
|
|
496
|
+
static getIframeUrl(offer: Offer): string | null;
|
|
497
|
+
/**
|
|
498
|
+
* Generate iframe HTML tag for an offer
|
|
499
|
+
*
|
|
500
|
+
* Returns null if the offer doesn't have iframe rendering configured.
|
|
501
|
+
*
|
|
502
|
+
* @param offer - The offer to generate an iframe tag for
|
|
503
|
+
* @param options - Optional rendering options (width, height, sandbox, etc.)
|
|
504
|
+
* @returns HTML string for the iframe element, or null if iframe URL not available
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
* ```typescript
|
|
508
|
+
* const html = ZeroClick.getIframeTag(offer, { width: '300px', height: '250px' });
|
|
509
|
+
* if (html) {
|
|
510
|
+
* container.innerHTML = html;
|
|
511
|
+
* }
|
|
512
|
+
* ```
|
|
513
|
+
*/
|
|
514
|
+
static getIframeTag(offer: Offer, options?: IframeRenderOptions): string | null;
|
|
515
|
+
/**
|
|
516
|
+
* Render an offer into a container element (browser only)
|
|
517
|
+
*
|
|
518
|
+
* Creates an iframe, inserts it into the container, waits for it to load,
|
|
519
|
+
* then sends the offer data via postMessage. Returns a no-op cleanup function
|
|
520
|
+
* if the offer doesn't have iframe rendering configured.
|
|
521
|
+
*
|
|
522
|
+
* @param offer - The offer to render
|
|
523
|
+
* @param container - DOM element or CSS selector string for the container
|
|
524
|
+
* @param options - Optional rendering options (width, height, mode, tenant, etc.)
|
|
525
|
+
* @returns Promise resolving to a cleanup function that removes the iframe
|
|
526
|
+
* @throws Error if not in browser environment
|
|
527
|
+
* @throws Error if container element not found
|
|
528
|
+
*
|
|
529
|
+
* @example
|
|
530
|
+
* ```typescript
|
|
531
|
+
* // Render into a div with id="ad-container"
|
|
532
|
+
* const handle = await ZeroClick.renderOffer(offer, '#ad-container', {
|
|
533
|
+
* width: '300px',
|
|
534
|
+
* height: '250px',
|
|
535
|
+
* mode: 'dark',
|
|
536
|
+
* style: { background: '#1a1a2e', textColor: '#fff', buttonBackground: '#4a9eff' }
|
|
537
|
+
* });
|
|
538
|
+
*
|
|
539
|
+
* // Update style (e.g., on theme change)
|
|
540
|
+
* handle.updateStyle({ background: '#fff', textColor: '#000' });
|
|
541
|
+
*
|
|
542
|
+
* // Later, remove the iframe
|
|
543
|
+
* handle.destroy();
|
|
544
|
+
* ```
|
|
545
|
+
*/
|
|
546
|
+
static renderOffer(offer: Offer, container: HTMLElement | string, options?: IframeRenderOptions): Promise<RenderHandle>;
|
|
547
|
+
/**
|
|
548
|
+
* Ensure the SDK has been initialized
|
|
549
|
+
* @throws Error if not initialized
|
|
550
|
+
*/
|
|
551
|
+
private static ensureInitialized;
|
|
552
|
+
}
|
|
553
|
+
//#endregion
|
|
554
|
+
//#region src/api.d.ts
|
|
555
|
+
/**
|
|
556
|
+
* Custom error class for API errors
|
|
557
|
+
*/
|
|
558
|
+
declare class ZeroClickApiError extends Error {
|
|
559
|
+
readonly status: number;
|
|
560
|
+
constructor(error: ApiError);
|
|
561
|
+
}
|
|
562
|
+
//#endregion
|
|
563
|
+
export { type ApiError, type Brand, CTA_CLICK_MESSAGE_TYPE, type Coordinates, type CtaClickEvent, type CtaClickMessage, type DistanceUnit, type GetOffersOptions, type Identity, type IframeMode, type IframeRenderOptions, type IframeStyleConfig, type Location, type Media, OFFER_DATA_MESSAGE_TYPE, type Offer, type OfferDataMessage, type OfferUI, type Price, type Product, type ProductAvailability, RESIZE_MESSAGE_TYPE, type Rating, type RenderHandle, type RequestContext, type ResizeMessage, STYLE_UPDATE_MESSAGE_TYPE, type StyleUpdateMessage, ZeroClick, ZeroClickApiError, type ZeroClickConfig };
|
|
564
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/client.ts","../src/api.ts"],"mappings":";;AAGA;;UAAiB,QAAA;EAAQ;EAEvB,MAAA;EAEA;EAAA,eAAA;EAIA;EAFA,qBAAA;EAMA;EAJA,UAAA;EAIU;EAFV,aAAA;EAQ8B;EAN9B,UAAA;AAAA;;;;UAMe,eAAA;EAMR;EAJP,MAAA;EAUe;EARf,QAAA,GAAW,QAAA;;EAEX,OAAA;AAAA;;;;UAMe,gBAAA;EAUT;EARN,SAAA;EAcU;EAZV,KAAA;;EAEA,KAAA;EAU6B;EAR7B,SAAA;EAasB;EAXtB,MAAA;AAAA;;AAgBF;;KAVY,mBAAA;;;;KAKA,YAAA;;;;UAKK,KAAA;EAcO;EAZtB,IAAA;EA8BgB;EA5BhB,WAAA;EAcA;EAZA,GAAA;EAgBA;EAdA,OAAA;AAAA;;;;UAMe,OAAA;EAkBL;EAhBV,SAAA;EAgBgB;EAdhB,GAAA;EAoBoB;EAlBpB,KAAA;EAkBoB;EAhBpB,WAAA;EAoBA;EAlBA,QAAA;EAsBA;EApBA,WAAA;EAsBQ;EApBR,KAAA;EA0Be;EAxBf,YAAA,EAAc,mBAAA;;EAEd,QAAA,EAAU,MAAA;AAAA;AAgCZ;;;AAAA,UA1BiB,KAAA;EA4Bf;EA1BA,MAAA;EA8BA;EA5BA,QAAA;EAgCA;EA9BA,aAAA;EAkCA;EAhCA,QAAA;EAkCA;EAhCA,QAAA;AAAA;;;AAwCF;UAlCiB,WAAA;;EAEf,GAAA;EAkCA;EAhCA,GAAA;AAAA;;;;UAMe,QAAA;EAsCM;EApCrB,IAAA;EAoCqB;EAlCrB,OAAA;EAsCA;EApCA,IAAA;EAsCK;EApCL,KAAA;EA0Ce;EAxCf,GAAA;;EAEA,QAA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