lynkow 2.1.3 → 3.0.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 +270 -13
- package/dist/index.d.mts +671 -82
- package/dist/index.d.ts +671 -82
- package/dist/index.js +162 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +162 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache manager for Lynkow SDK
|
|
3
|
+
* Uses memory cache on server, localStorage on browser
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Cache configuration
|
|
7
|
+
*/
|
|
8
|
+
interface CacheConfig {
|
|
9
|
+
/** Default TTL in milliseconds (default: 5 minutes) */
|
|
10
|
+
defaultTtl?: number;
|
|
11
|
+
/** Storage key prefix */
|
|
12
|
+
prefix?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a cache manager
|
|
16
|
+
*/
|
|
17
|
+
declare function createCache(config?: CacheConfig): {
|
|
18
|
+
get: <T>(key: string) => T | null;
|
|
19
|
+
set: <T>(key: string, value: T, ttl?: number) => void;
|
|
20
|
+
remove: (key: string) => void;
|
|
21
|
+
invalidate: (pattern?: string) => void;
|
|
22
|
+
getOrSet: <T>(key: string, factory: () => Promise<T>, ttl?: number) => Promise<T>;
|
|
23
|
+
};
|
|
24
|
+
type Cache = ReturnType<typeof createCache>;
|
|
25
|
+
|
|
1
26
|
/**
|
|
2
27
|
* Normalized internal configuration
|
|
3
28
|
*/
|
|
@@ -6,12 +31,15 @@ interface InternalConfig {
|
|
|
6
31
|
baseUrl: string;
|
|
7
32
|
locale?: string;
|
|
8
33
|
fetchOptions: RequestInit;
|
|
34
|
+
/** Optional cache manager for caching responses */
|
|
35
|
+
cache?: Cache;
|
|
9
36
|
}
|
|
10
37
|
/**
|
|
11
38
|
* Base service that all specific services inherit from
|
|
12
39
|
*/
|
|
13
40
|
declare abstract class BaseService {
|
|
14
41
|
protected config: InternalConfig;
|
|
42
|
+
protected cache?: Cache;
|
|
15
43
|
constructor(config: InternalConfig);
|
|
16
44
|
/**
|
|
17
45
|
* Builds the full URL for an endpoint
|
|
@@ -21,6 +49,23 @@ declare abstract class BaseService {
|
|
|
21
49
|
* Performs a GET request
|
|
22
50
|
*/
|
|
23
51
|
protected get<T>(path: string, query?: Record<string, unknown>, options?: BaseRequestOptions): Promise<T>;
|
|
52
|
+
/**
|
|
53
|
+
* Performs a cached GET request
|
|
54
|
+
* If cache is available and data exists, returns cached data
|
|
55
|
+
* Otherwise fetches from API and caches the result
|
|
56
|
+
*
|
|
57
|
+
* @param cacheKey - Unique cache key
|
|
58
|
+
* @param path - API endpoint path
|
|
59
|
+
* @param query - Query parameters
|
|
60
|
+
* @param options - Request options
|
|
61
|
+
* @param ttl - Cache TTL in milliseconds (default: SHORT)
|
|
62
|
+
*/
|
|
63
|
+
protected getWithCache<T>(cacheKey: string, path: string, query?: Record<string, unknown>, options?: BaseRequestOptions, ttl?: number): Promise<T>;
|
|
64
|
+
/**
|
|
65
|
+
* Invalidates cache entries matching a pattern
|
|
66
|
+
* @param pattern - Pattern to match cache keys
|
|
67
|
+
*/
|
|
68
|
+
protected invalidateCache(pattern?: string): void;
|
|
24
69
|
/**
|
|
25
70
|
* Performs a POST request
|
|
26
71
|
*/
|
|
@@ -69,6 +114,10 @@ declare class ContentsService extends BaseService {
|
|
|
69
114
|
* ```
|
|
70
115
|
*/
|
|
71
116
|
getBySlug(slug: string, options?: BaseRequestOptions): Promise<Content>;
|
|
117
|
+
/**
|
|
118
|
+
* Clear contents cache
|
|
119
|
+
*/
|
|
120
|
+
clearCache(): void;
|
|
72
121
|
}
|
|
73
122
|
|
|
74
123
|
/**
|
|
@@ -116,6 +165,10 @@ declare class CategoriesService extends BaseService {
|
|
|
116
165
|
* ```
|
|
117
166
|
*/
|
|
118
167
|
getBySlug(slug: string, options?: CategoryOptions & BaseRequestOptions): Promise<CategoryDetailResponse>;
|
|
168
|
+
/**
|
|
169
|
+
* Clear categories cache
|
|
170
|
+
*/
|
|
171
|
+
clearCache(): void;
|
|
119
172
|
}
|
|
120
173
|
|
|
121
174
|
/**
|
|
@@ -134,8 +187,19 @@ declare class TagsService extends BaseService {
|
|
|
134
187
|
* ```
|
|
135
188
|
*/
|
|
136
189
|
list(options?: BaseRequestOptions): Promise<TagsListResponse>;
|
|
190
|
+
/**
|
|
191
|
+
* Clear tags cache
|
|
192
|
+
*/
|
|
193
|
+
clearCache(): void;
|
|
137
194
|
}
|
|
138
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Options for listing pages
|
|
198
|
+
*/
|
|
199
|
+
interface PagesListOptions extends BaseRequestOptions {
|
|
200
|
+
/** Filter pages by tag (e.g., 'legal' for legal documents) */
|
|
201
|
+
tag?: string;
|
|
202
|
+
}
|
|
139
203
|
/**
|
|
140
204
|
* Service for pages (Site Blocks of type "page")
|
|
141
205
|
*/
|
|
@@ -143,15 +207,19 @@ declare class PagesService extends BaseService {
|
|
|
143
207
|
/**
|
|
144
208
|
* Retrieves the list of published pages
|
|
145
209
|
*
|
|
146
|
-
* @param options - Request options (locale)
|
|
210
|
+
* @param options - Request options (locale, tag filter)
|
|
147
211
|
* @returns List of pages
|
|
148
212
|
*
|
|
149
213
|
* @example
|
|
150
214
|
* ```typescript
|
|
215
|
+
* // List all pages
|
|
151
216
|
* const { data } = await lynkow.pages.list()
|
|
217
|
+
*
|
|
218
|
+
* // List legal documents
|
|
219
|
+
* const { data } = await lynkow.pages.list({ tag: 'legal' })
|
|
152
220
|
* ```
|
|
153
221
|
*/
|
|
154
|
-
list(options?:
|
|
222
|
+
list(options?: PagesListOptions): Promise<PagesListResponse>;
|
|
155
223
|
/**
|
|
156
224
|
* Retrieves a page by its slug
|
|
157
225
|
*
|
|
@@ -192,10 +260,15 @@ declare class PagesService extends BaseService {
|
|
|
192
260
|
* ```
|
|
193
261
|
*/
|
|
194
262
|
getJsonLd(slug: string, options?: BaseRequestOptions): Promise<Record<string, unknown>>;
|
|
263
|
+
/**
|
|
264
|
+
* Clear pages cache
|
|
265
|
+
*/
|
|
266
|
+
clearCache(): void;
|
|
195
267
|
}
|
|
196
268
|
|
|
197
269
|
/**
|
|
198
270
|
* Service for global blocks (header, footer, etc.)
|
|
271
|
+
* Also aliased as `globals` in the client
|
|
199
272
|
*/
|
|
200
273
|
declare class BlocksService extends BaseService {
|
|
201
274
|
/**
|
|
@@ -206,7 +279,7 @@ declare class BlocksService extends BaseService {
|
|
|
206
279
|
*
|
|
207
280
|
* @example
|
|
208
281
|
* ```typescript
|
|
209
|
-
* const { data } = await lynkow.
|
|
282
|
+
* const { data } = await lynkow.globals.siteConfig()
|
|
210
283
|
* const header = data.globals['header']
|
|
211
284
|
* const footer = data.globals['footer']
|
|
212
285
|
* ```
|
|
@@ -221,11 +294,19 @@ declare class BlocksService extends BaseService {
|
|
|
221
294
|
*
|
|
222
295
|
* @example
|
|
223
296
|
* ```typescript
|
|
224
|
-
* const { data } = await lynkow.
|
|
297
|
+
* const { data } = await lynkow.globals.getBySlug('header')
|
|
225
298
|
* // data.data contient les donnees du bloc
|
|
226
299
|
* ```
|
|
227
300
|
*/
|
|
301
|
+
getBySlug(slug: string, options?: BaseRequestOptions): Promise<GlobalBlockResponse>;
|
|
302
|
+
/**
|
|
303
|
+
* @deprecated Use `getBySlug()` instead
|
|
304
|
+
*/
|
|
228
305
|
global(slug: string, options?: BaseRequestOptions): Promise<GlobalBlockResponse>;
|
|
306
|
+
/**
|
|
307
|
+
* Clear globals cache
|
|
308
|
+
*/
|
|
309
|
+
clearCache(): void;
|
|
229
310
|
}
|
|
230
311
|
|
|
231
312
|
/**
|
|
@@ -270,6 +351,10 @@ declare class FormsService extends BaseService {
|
|
|
270
351
|
* ```
|
|
271
352
|
*/
|
|
272
353
|
submit(slug: string, data: FormSubmitData, options?: SubmitOptions & BaseRequestOptions): Promise<FormSubmitResponse>;
|
|
354
|
+
/**
|
|
355
|
+
* Clear forms cache
|
|
356
|
+
*/
|
|
357
|
+
clearCache(): void;
|
|
273
358
|
}
|
|
274
359
|
|
|
275
360
|
/**
|
|
@@ -342,6 +427,10 @@ declare class ReviewsService extends BaseService {
|
|
|
342
427
|
* ```
|
|
343
428
|
*/
|
|
344
429
|
submit(data: ReviewSubmitData, options?: SubmitOptions & BaseRequestOptions): Promise<ReviewSubmitResponse>;
|
|
430
|
+
/**
|
|
431
|
+
* Clear reviews cache
|
|
432
|
+
*/
|
|
433
|
+
clearCache(): void;
|
|
345
434
|
}
|
|
346
435
|
|
|
347
436
|
/**
|
|
@@ -360,42 +449,68 @@ declare class SiteService extends BaseService {
|
|
|
360
449
|
* ```
|
|
361
450
|
*/
|
|
362
451
|
getConfig(): Promise<SiteConfig>;
|
|
452
|
+
/**
|
|
453
|
+
* Clear site configuration cache
|
|
454
|
+
*/
|
|
455
|
+
clearCache(): void;
|
|
363
456
|
}
|
|
364
457
|
|
|
365
458
|
/**
|
|
366
|
-
* Service for legal documents
|
|
459
|
+
* Service for accessing legal documents (pages tagged with 'legal')
|
|
460
|
+
*
|
|
461
|
+
* @deprecated Use `pages.list({ tag: 'legal' })` and `pages.getBySlug(slug)` instead.
|
|
462
|
+
* This service will be removed in the next major version.
|
|
463
|
+
*
|
|
464
|
+
* @remarks
|
|
465
|
+
* Legal documents are now regular pages with the 'legal' tag.
|
|
466
|
+
* This service provides convenience methods to access them.
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ```typescript
|
|
470
|
+
* // Deprecated:
|
|
471
|
+
* const docs = await sdk.legal.list()
|
|
472
|
+
* const privacy = await sdk.legal.getBySlug('privacy-policy')
|
|
473
|
+
*
|
|
474
|
+
* // Recommended:
|
|
475
|
+
* const docs = await sdk.pages.list({ tag: 'legal' })
|
|
476
|
+
* const privacy = await sdk.pages.getBySlug('privacy-policy')
|
|
477
|
+
* ```
|
|
367
478
|
*/
|
|
368
479
|
declare class LegalService extends BaseService {
|
|
369
480
|
/**
|
|
370
|
-
*
|
|
481
|
+
* List all legal pages
|
|
371
482
|
*
|
|
372
|
-
* @
|
|
373
|
-
* @returns List of available documents
|
|
483
|
+
* @deprecated Use `pages.list({ tag: 'legal' })` instead
|
|
374
484
|
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
485
|
+
* Returns all published pages that have the 'legal' tag.
|
|
486
|
+
*
|
|
487
|
+
* @param options - Request options (locale)
|
|
488
|
+
* @returns Array of legal documents
|
|
379
489
|
*/
|
|
380
|
-
list(options?: BaseRequestOptions): Promise<
|
|
490
|
+
list(options?: BaseRequestOptions): Promise<LegalDocument[]>;
|
|
381
491
|
/**
|
|
382
|
-
*
|
|
492
|
+
* Get a specific legal page by slug
|
|
383
493
|
*
|
|
384
|
-
* @
|
|
385
|
-
* @param options - Request options (locale)
|
|
386
|
-
* @returns Full legal document
|
|
494
|
+
* @deprecated Use `pages.getBySlug(slug)` instead
|
|
387
495
|
*
|
|
388
|
-
* @
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
|
|
496
|
+
* @param slug - The page slug (e.g., 'privacy-policy', 'terms-of-service')
|
|
497
|
+
* @param options - Request options (locale)
|
|
498
|
+
* @returns The legal document
|
|
499
|
+
* @throws {LynkowError} If the document doesn't exist (404)
|
|
500
|
+
*/
|
|
501
|
+
getBySlug(slug: string, options?: BaseRequestOptions): Promise<LegalDocument>;
|
|
502
|
+
/**
|
|
503
|
+
* Clear legal documents cache
|
|
393
504
|
*/
|
|
394
|
-
|
|
505
|
+
clearCache(): void;
|
|
395
506
|
}
|
|
396
507
|
|
|
397
508
|
/**
|
|
398
509
|
* Service for cookie consent
|
|
510
|
+
*
|
|
511
|
+
* @remarks
|
|
512
|
+
* This service will be expanded into the `consent` module in v3
|
|
513
|
+
* with banner UI and preferences modal support.
|
|
399
514
|
*/
|
|
400
515
|
declare class CookiesService extends BaseService {
|
|
401
516
|
/**
|
|
@@ -428,6 +543,10 @@ declare class CookiesService extends BaseService {
|
|
|
428
543
|
* ```
|
|
429
544
|
*/
|
|
430
545
|
logConsent(preferences: CookiePreferences, options?: BaseRequestOptions): Promise<ConsentLogResponse>;
|
|
546
|
+
/**
|
|
547
|
+
* Clear cookies configuration cache
|
|
548
|
+
*/
|
|
549
|
+
clearCache(): void;
|
|
431
550
|
}
|
|
432
551
|
|
|
433
552
|
/**
|
|
@@ -527,6 +646,10 @@ declare class PathsService extends BaseService {
|
|
|
527
646
|
* ```
|
|
528
647
|
*/
|
|
529
648
|
matchRedirect(path: string, options?: BaseRequestOptions): Promise<Redirect | null>;
|
|
649
|
+
/**
|
|
650
|
+
* Clear paths cache
|
|
651
|
+
*/
|
|
652
|
+
clearCache(): void;
|
|
530
653
|
}
|
|
531
654
|
|
|
532
655
|
/**
|
|
@@ -981,35 +1104,36 @@ interface SiteConfig {
|
|
|
981
1104
|
enabledLocales: string[];
|
|
982
1105
|
/** Additional settings */
|
|
983
1106
|
settings: Record<string, unknown>;
|
|
1107
|
+
/** Show branding badge (free plan) */
|
|
1108
|
+
showBranding: boolean;
|
|
984
1109
|
}
|
|
985
1110
|
|
|
986
1111
|
/**
|
|
987
|
-
*
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
*
|
|
992
|
-
*/
|
|
993
|
-
interface LegalDocumentSummary {
|
|
994
|
-
/** Document type */
|
|
995
|
-
type: LegalDocumentType;
|
|
996
|
-
/** Title */
|
|
997
|
-
title: string;
|
|
998
|
-
/** Update date */
|
|
999
|
-
updatedAt: string;
|
|
1000
|
-
}
|
|
1001
|
-
/**
|
|
1002
|
-
* Full legal document
|
|
1112
|
+
* A legal document (page tagged with 'legal')
|
|
1113
|
+
*
|
|
1114
|
+
* @remarks
|
|
1115
|
+
* Legal documents are now regular pages with the 'legal' tag.
|
|
1116
|
+
* This provides more flexibility in content structure and SEO.
|
|
1003
1117
|
*/
|
|
1004
|
-
interface LegalDocument
|
|
1005
|
-
/**
|
|
1006
|
-
|
|
1007
|
-
/**
|
|
1118
|
+
interface LegalDocument {
|
|
1119
|
+
/** Unique identifier */
|
|
1120
|
+
id: string;
|
|
1121
|
+
/** URL-friendly identifier */
|
|
1122
|
+
slug: string;
|
|
1123
|
+
/** Display name */
|
|
1124
|
+
name: string;
|
|
1125
|
+
/** Locale of the document */
|
|
1008
1126
|
locale: string;
|
|
1009
|
-
/** Document
|
|
1010
|
-
|
|
1011
|
-
/**
|
|
1012
|
-
|
|
1127
|
+
/** Document content (schema-dependent) */
|
|
1128
|
+
data: Record<string, unknown>;
|
|
1129
|
+
/** SEO metadata */
|
|
1130
|
+
seo?: {
|
|
1131
|
+
title?: string | null;
|
|
1132
|
+
description?: string | null;
|
|
1133
|
+
ogImage?: string | null;
|
|
1134
|
+
} | null;
|
|
1135
|
+
/** Last update timestamp */
|
|
1136
|
+
updatedAt: string;
|
|
1013
1137
|
}
|
|
1014
1138
|
|
|
1015
1139
|
/**
|
|
@@ -1209,12 +1333,6 @@ interface ReviewSubmitResponse {
|
|
|
1209
1333
|
status: 'success' | 'pending';
|
|
1210
1334
|
reviewId?: number;
|
|
1211
1335
|
}
|
|
1212
|
-
/**
|
|
1213
|
-
* Legal documents list response
|
|
1214
|
-
*/
|
|
1215
|
-
interface LegalListResponse {
|
|
1216
|
-
data: LegalDocumentSummary[];
|
|
1217
|
-
}
|
|
1218
1336
|
/**
|
|
1219
1337
|
* Consent log response
|
|
1220
1338
|
*/
|
|
@@ -1322,63 +1440,534 @@ interface SubmitOptions {
|
|
|
1322
1440
|
}
|
|
1323
1441
|
|
|
1324
1442
|
/**
|
|
1325
|
-
*
|
|
1443
|
+
* Checks if a resolution response is a content
|
|
1326
1444
|
*/
|
|
1327
|
-
|
|
1445
|
+
declare function isContentResolve(response: ResolveResponse): response is ContentResolveResponse;
|
|
1328
1446
|
/**
|
|
1329
|
-
*
|
|
1447
|
+
* Checks if a resolution response is a category
|
|
1330
1448
|
*/
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1449
|
+
declare function isCategoryResolve(response: ResolveResponse): response is CategoryResolveResponse;
|
|
1450
|
+
|
|
1451
|
+
/**
|
|
1452
|
+
* Analytics module for Lynkow SDK
|
|
1453
|
+
*
|
|
1454
|
+
* Browser-only module that loads and wraps the Lynkow tracker.js
|
|
1455
|
+
* All methods are no-op on server.
|
|
1456
|
+
*/
|
|
1457
|
+
|
|
1458
|
+
/**
|
|
1459
|
+
* Data for tracking pageviews
|
|
1460
|
+
*/
|
|
1461
|
+
interface PageviewData {
|
|
1462
|
+
/** Page path (default: window.location.pathname) */
|
|
1463
|
+
path?: string;
|
|
1464
|
+
/** Page title (default: document.title) */
|
|
1465
|
+
title?: string;
|
|
1466
|
+
/** Referrer URL */
|
|
1467
|
+
referrer?: string;
|
|
1468
|
+
}
|
|
1469
|
+
/**
|
|
1470
|
+
* Data for tracking custom events
|
|
1471
|
+
*/
|
|
1472
|
+
interface EventData {
|
|
1473
|
+
/** Event type */
|
|
1474
|
+
type: string;
|
|
1475
|
+
/** Additional event data */
|
|
1476
|
+
[key: string]: unknown;
|
|
1477
|
+
}
|
|
1478
|
+
/**
|
|
1479
|
+
* Funnel step data
|
|
1480
|
+
*/
|
|
1481
|
+
interface FunnelStepData {
|
|
1482
|
+
/** Funnel identifier */
|
|
1483
|
+
funnelId: string;
|
|
1484
|
+
/** Step number (1-based) */
|
|
1485
|
+
stepNumber: number;
|
|
1486
|
+
/** Step name */
|
|
1487
|
+
stepName: string;
|
|
1488
|
+
/** Funnel name (optional) */
|
|
1489
|
+
funnelName?: string;
|
|
1490
|
+
}
|
|
1491
|
+
/**
|
|
1492
|
+
* LynkowAnalytics global interface (from tracker.js)
|
|
1493
|
+
*/
|
|
1494
|
+
interface LynkowAnalyticsGlobal {
|
|
1495
|
+
init: (siteId: string, options?: {
|
|
1496
|
+
endpoint?: string;
|
|
1497
|
+
}) => void;
|
|
1498
|
+
track: (event: Record<string, unknown>) => void;
|
|
1499
|
+
trackFunnel: (funnelId: string, stepNumber: number, stepName: string, funnelName?: string) => void;
|
|
1500
|
+
}
|
|
1501
|
+
declare global {
|
|
1502
|
+
interface Window {
|
|
1503
|
+
LynkowAnalytics?: LynkowAnalyticsGlobal;
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
/**
|
|
1507
|
+
* Analytics service that loads and wraps the Lynkow tracker.js
|
|
1508
|
+
*
|
|
1509
|
+
* Browser-only. All methods are no-op on server.
|
|
1510
|
+
*/
|
|
1511
|
+
declare class AnalyticsService {
|
|
1512
|
+
private config;
|
|
1513
|
+
private enabled;
|
|
1514
|
+
private initialized;
|
|
1515
|
+
private loading;
|
|
1516
|
+
private loadPromise;
|
|
1517
|
+
constructor(config: InternalConfig);
|
|
1518
|
+
/**
|
|
1519
|
+
* Get the tracker script URL
|
|
1520
|
+
*/
|
|
1521
|
+
private getTrackerUrl;
|
|
1522
|
+
/**
|
|
1523
|
+
* Load the tracker.js script
|
|
1524
|
+
*/
|
|
1525
|
+
private loadTracker;
|
|
1526
|
+
/**
|
|
1527
|
+
* Initialize analytics tracking
|
|
1528
|
+
* Loads the tracker.js script and initializes it
|
|
1529
|
+
*/
|
|
1530
|
+
init(): Promise<void>;
|
|
1531
|
+
/**
|
|
1532
|
+
* Track a custom event
|
|
1533
|
+
*
|
|
1534
|
+
* @example
|
|
1535
|
+
* ```typescript
|
|
1536
|
+
* lynkow.analytics.trackEvent({
|
|
1537
|
+
* type: 'purchase',
|
|
1538
|
+
* productId: 'abc123',
|
|
1539
|
+
* amount: 99.99
|
|
1540
|
+
* })
|
|
1541
|
+
* ```
|
|
1542
|
+
*/
|
|
1543
|
+
trackEvent(event: EventData): Promise<void>;
|
|
1544
|
+
/**
|
|
1545
|
+
* Track a funnel step
|
|
1546
|
+
*
|
|
1547
|
+
* @example
|
|
1548
|
+
* ```typescript
|
|
1549
|
+
* lynkow.analytics.trackFunnelStep({
|
|
1550
|
+
* funnelId: 'checkout',
|
|
1551
|
+
* stepNumber: 2,
|
|
1552
|
+
* stepName: 'payment',
|
|
1553
|
+
* funnelName: 'Checkout Flow'
|
|
1554
|
+
* })
|
|
1555
|
+
* ```
|
|
1556
|
+
*/
|
|
1557
|
+
trackFunnelStep(data: FunnelStepData): Promise<void>;
|
|
1558
|
+
/**
|
|
1559
|
+
* Track a pageview manually
|
|
1560
|
+
* Note: The tracker automatically tracks pageviews, this is for SPA navigation
|
|
1561
|
+
*
|
|
1562
|
+
* @example
|
|
1563
|
+
* ```typescript
|
|
1564
|
+
* // After SPA navigation
|
|
1565
|
+
* lynkow.analytics.trackPageview({ path: '/new-page' })
|
|
1566
|
+
* ```
|
|
1567
|
+
*/
|
|
1568
|
+
trackPageview(data?: PageviewData): Promise<void>;
|
|
1569
|
+
/**
|
|
1570
|
+
* Enable analytics tracking
|
|
1571
|
+
*/
|
|
1572
|
+
enable(): void;
|
|
1573
|
+
/**
|
|
1574
|
+
* Disable analytics tracking
|
|
1575
|
+
*/
|
|
1576
|
+
disable(): void;
|
|
1577
|
+
/**
|
|
1578
|
+
* Check if analytics is enabled
|
|
1579
|
+
*/
|
|
1580
|
+
isEnabled(): boolean;
|
|
1581
|
+
/**
|
|
1582
|
+
* Check if tracker is loaded and initialized
|
|
1583
|
+
*/
|
|
1584
|
+
isInitialized(): boolean;
|
|
1585
|
+
/**
|
|
1586
|
+
* Get the underlying LynkowAnalytics global object
|
|
1587
|
+
* For advanced usage when you need direct access to the tracker
|
|
1588
|
+
*/
|
|
1589
|
+
getTracker(): LynkowAnalyticsGlobal | undefined;
|
|
1590
|
+
/**
|
|
1591
|
+
* Clean up resources (removes the tracker script)
|
|
1592
|
+
*/
|
|
1593
|
+
destroy(): void;
|
|
1338
1594
|
}
|
|
1339
1595
|
|
|
1340
1596
|
/**
|
|
1341
|
-
* Lynkow SDK
|
|
1597
|
+
* Simple event emitter for Lynkow SDK
|
|
1342
1598
|
*/
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1599
|
+
/**
|
|
1600
|
+
* Event types for the SDK
|
|
1601
|
+
*/
|
|
1602
|
+
interface LynkowEvents {
|
|
1603
|
+
ready: void;
|
|
1604
|
+
'locale-changed': string;
|
|
1605
|
+
'consent-changed': Record<string, boolean>;
|
|
1606
|
+
error: Error;
|
|
1351
1607
|
}
|
|
1608
|
+
type EventName = keyof LynkowEvents;
|
|
1609
|
+
/**
|
|
1610
|
+
* Event listener function type
|
|
1611
|
+
*/
|
|
1612
|
+
type EventListener<T> = (data: T) => void;
|
|
1613
|
+
/**
|
|
1614
|
+
* Create an event emitter
|
|
1615
|
+
*/
|
|
1616
|
+
declare function createEventEmitter(): {
|
|
1617
|
+
on: <K extends EventName>(event: K, listener: EventListener<LynkowEvents[K]>) => () => void;
|
|
1618
|
+
off: <K extends EventName>(event: K, listener: EventListener<LynkowEvents[K]>) => void;
|
|
1619
|
+
emit: <K extends EventName>(event: K, data: LynkowEvents[K]) => void;
|
|
1620
|
+
once: <K extends EventName>(event: K, listener: EventListener<LynkowEvents[K]>) => () => void;
|
|
1621
|
+
removeAllListeners: (event?: EventName) => void;
|
|
1622
|
+
};
|
|
1623
|
+
type EventEmitter = ReturnType<typeof createEventEmitter>;
|
|
1352
1624
|
|
|
1353
1625
|
/**
|
|
1354
|
-
*
|
|
1626
|
+
* Consent module for Lynkow SDK
|
|
1627
|
+
*
|
|
1628
|
+
* Hybrid module: API everywhere + UI browser-only
|
|
1355
1629
|
*/
|
|
1356
|
-
|
|
1630
|
+
|
|
1357
1631
|
/**
|
|
1358
|
-
*
|
|
1632
|
+
* Consent categories
|
|
1359
1633
|
*/
|
|
1360
|
-
|
|
1634
|
+
interface ConsentCategories {
|
|
1635
|
+
/** Always true, not modifiable */
|
|
1636
|
+
necessary: boolean;
|
|
1637
|
+
/** Analytics cookies */
|
|
1638
|
+
analytics: boolean;
|
|
1639
|
+
/** Marketing cookies */
|
|
1640
|
+
marketing: boolean;
|
|
1641
|
+
/** Preference cookies */
|
|
1642
|
+
preferences: boolean;
|
|
1643
|
+
}
|
|
1361
1644
|
/**
|
|
1362
|
-
*
|
|
1645
|
+
* Consent service for cookie consent management
|
|
1646
|
+
*
|
|
1647
|
+
* Provides:
|
|
1648
|
+
* - API methods that work everywhere (getConfig, logConsent)
|
|
1649
|
+
* - UI methods that work only in browser (show, hide, acceptAll, etc.)
|
|
1650
|
+
*/
|
|
1651
|
+
declare class ConsentService {
|
|
1652
|
+
private config;
|
|
1653
|
+
private events;
|
|
1654
|
+
private bannerElement;
|
|
1655
|
+
private preferencesElement;
|
|
1656
|
+
private configCache;
|
|
1657
|
+
constructor(config: InternalConfig, events: EventEmitter);
|
|
1658
|
+
/**
|
|
1659
|
+
* Get cookie consent configuration from API
|
|
1660
|
+
*/
|
|
1661
|
+
getConfig(): Promise<CookieConfig>;
|
|
1662
|
+
/**
|
|
1663
|
+
* Log consent to server
|
|
1664
|
+
*/
|
|
1665
|
+
logConsent(preferences: CookiePreferences): Promise<void>;
|
|
1666
|
+
private getStoredConsent;
|
|
1667
|
+
private saveConsent;
|
|
1668
|
+
/**
|
|
1669
|
+
* Show the consent banner
|
|
1670
|
+
*/
|
|
1671
|
+
show(): void;
|
|
1672
|
+
/**
|
|
1673
|
+
* Hide the consent banner
|
|
1674
|
+
*/
|
|
1675
|
+
hide(): void;
|
|
1676
|
+
/**
|
|
1677
|
+
* Show the preferences modal
|
|
1678
|
+
*/
|
|
1679
|
+
showPreferences(): void;
|
|
1680
|
+
/**
|
|
1681
|
+
* Get current consent categories
|
|
1682
|
+
*/
|
|
1683
|
+
getCategories(): ConsentCategories;
|
|
1684
|
+
/**
|
|
1685
|
+
* Check if user has already consented
|
|
1686
|
+
*/
|
|
1687
|
+
hasConsented(): boolean;
|
|
1688
|
+
/**
|
|
1689
|
+
* Accept all cookies
|
|
1690
|
+
*/
|
|
1691
|
+
acceptAll(): void;
|
|
1692
|
+
/**
|
|
1693
|
+
* Reject all optional cookies
|
|
1694
|
+
*/
|
|
1695
|
+
rejectAll(): void;
|
|
1696
|
+
/**
|
|
1697
|
+
* Set specific consent categories
|
|
1698
|
+
*/
|
|
1699
|
+
setCategories(categories: Partial<ConsentCategories>): void;
|
|
1700
|
+
/**
|
|
1701
|
+
* Reset consent and show banner again
|
|
1702
|
+
*/
|
|
1703
|
+
reset(): void;
|
|
1704
|
+
private createBannerHTML;
|
|
1705
|
+
private createPreferencesHTML;
|
|
1706
|
+
private attachBannerEvents;
|
|
1707
|
+
private attachPreferencesEvents;
|
|
1708
|
+
/**
|
|
1709
|
+
* Clean up resources
|
|
1710
|
+
*/
|
|
1711
|
+
destroy(): void;
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
/**
|
|
1715
|
+
* Branding module for Lynkow SDK
|
|
1716
|
+
*
|
|
1717
|
+
* Browser-only module. Displays "Powered by Lynkow" badge for free plan users.
|
|
1718
|
+
*/
|
|
1719
|
+
/**
|
|
1720
|
+
* Branding service for "Powered by Lynkow" badge
|
|
1721
|
+
*
|
|
1722
|
+
* Browser-only. All methods are no-op on server.
|
|
1723
|
+
*/
|
|
1724
|
+
declare class BrandingService {
|
|
1725
|
+
private badgeElement;
|
|
1726
|
+
/**
|
|
1727
|
+
* Inject styles into document head
|
|
1728
|
+
*/
|
|
1729
|
+
private injectStyles;
|
|
1730
|
+
/**
|
|
1731
|
+
* Inject the branding badge into the page
|
|
1732
|
+
*/
|
|
1733
|
+
inject(): void;
|
|
1734
|
+
/**
|
|
1735
|
+
* Remove the branding badge from the page
|
|
1736
|
+
*/
|
|
1737
|
+
remove(): void;
|
|
1738
|
+
/**
|
|
1739
|
+
* Check if the badge is currently visible
|
|
1740
|
+
*/
|
|
1741
|
+
isVisible(): boolean;
|
|
1742
|
+
/**
|
|
1743
|
+
* Clean up resources
|
|
1744
|
+
*/
|
|
1745
|
+
destroy(): void;
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
/**
|
|
1749
|
+
* Lynkow SDK Client
|
|
1750
|
+
* Main entry point for the SDK
|
|
1363
1751
|
*/
|
|
1364
|
-
declare function isLynkowError(error: unknown): error is LynkowError;
|
|
1365
1752
|
|
|
1366
1753
|
/**
|
|
1367
|
-
*
|
|
1754
|
+
* Extended configuration for SDK v3
|
|
1755
|
+
*/
|
|
1756
|
+
interface ClientConfig extends LynkowConfig {
|
|
1757
|
+
/**
|
|
1758
|
+
* Enable debug logging
|
|
1759
|
+
* @default false
|
|
1760
|
+
*/
|
|
1761
|
+
debug?: boolean;
|
|
1762
|
+
}
|
|
1763
|
+
/**
|
|
1764
|
+
* Extended client interface for SDK v3
|
|
1765
|
+
*/
|
|
1766
|
+
interface Client extends LynkowClient {
|
|
1767
|
+
/**
|
|
1768
|
+
* Current locale
|
|
1769
|
+
*/
|
|
1770
|
+
readonly locale: string;
|
|
1771
|
+
/**
|
|
1772
|
+
* Available locales from site configuration
|
|
1773
|
+
*/
|
|
1774
|
+
readonly availableLocales: string[];
|
|
1775
|
+
/**
|
|
1776
|
+
* Client configuration (readonly)
|
|
1777
|
+
*/
|
|
1778
|
+
readonly config: Readonly<{
|
|
1779
|
+
siteId: string;
|
|
1780
|
+
baseUrl: string;
|
|
1781
|
+
debug: boolean;
|
|
1782
|
+
}>;
|
|
1783
|
+
/**
|
|
1784
|
+
* Set the current locale
|
|
1785
|
+
* @param locale - New locale to use
|
|
1786
|
+
*/
|
|
1787
|
+
setLocale(locale: string): void;
|
|
1788
|
+
/**
|
|
1789
|
+
* Clear all cached data
|
|
1790
|
+
*/
|
|
1791
|
+
clearCache(): void;
|
|
1792
|
+
/**
|
|
1793
|
+
* Destroy the client and clean up resources
|
|
1794
|
+
*/
|
|
1795
|
+
destroy(): void;
|
|
1796
|
+
/**
|
|
1797
|
+
* Subscribe to an event
|
|
1798
|
+
* @param event - Event name
|
|
1799
|
+
* @param listener - Event listener
|
|
1800
|
+
* @returns Unsubscribe function
|
|
1801
|
+
*/
|
|
1802
|
+
on<K extends EventName>(event: K, listener: (data: LynkowEvents[K]) => void): () => void;
|
|
1803
|
+
/**
|
|
1804
|
+
* Alias for blocks (v3 naming)
|
|
1805
|
+
* @deprecated Use `globals` instead in v3
|
|
1806
|
+
*/
|
|
1807
|
+
blocks: BlocksService;
|
|
1808
|
+
/**
|
|
1809
|
+
* Global blocks service (v3 naming)
|
|
1810
|
+
*/
|
|
1811
|
+
globals: BlocksService;
|
|
1812
|
+
/**
|
|
1813
|
+
* Analytics service (browser-only)
|
|
1814
|
+
*/
|
|
1815
|
+
analytics: AnalyticsService;
|
|
1816
|
+
/**
|
|
1817
|
+
* Consent service (cookie consent management)
|
|
1818
|
+
*/
|
|
1819
|
+
consent: ConsentService;
|
|
1820
|
+
/**
|
|
1821
|
+
* Branding service (badge for free plan)
|
|
1822
|
+
*/
|
|
1823
|
+
branding: BrandingService;
|
|
1824
|
+
}
|
|
1825
|
+
/**
|
|
1826
|
+
* Creates a Lynkow client instance (SDK v3)
|
|
1368
1827
|
*
|
|
1369
1828
|
* @param config - Client configuration
|
|
1370
1829
|
* @returns Client instance with all services
|
|
1371
1830
|
*
|
|
1372
1831
|
* @example
|
|
1373
1832
|
* ```typescript
|
|
1374
|
-
* const lynkow =
|
|
1833
|
+
* const lynkow = createClient({
|
|
1375
1834
|
* siteId: 'your-site-uuid',
|
|
1376
|
-
* locale: 'fr'
|
|
1835
|
+
* locale: 'fr',
|
|
1836
|
+
* debug: true
|
|
1377
1837
|
* })
|
|
1378
1838
|
*
|
|
1379
1839
|
* const posts = await lynkow.contents.list()
|
|
1380
1840
|
* ```
|
|
1381
1841
|
*/
|
|
1842
|
+
declare function createClient(config: ClientConfig): Client;
|
|
1843
|
+
/**
|
|
1844
|
+
* Creates a Lynkow client instance (legacy naming)
|
|
1845
|
+
*
|
|
1846
|
+
* @deprecated Use `createClient` instead
|
|
1847
|
+
* @param config - Client configuration
|
|
1848
|
+
* @returns Client instance with all services
|
|
1849
|
+
*/
|
|
1382
1850
|
declare function createLynkowClient(config: LynkowConfig): LynkowClient;
|
|
1383
1851
|
|
|
1384
|
-
|
|
1852
|
+
/**
|
|
1853
|
+
* Error handling utilities for Lynkow SDK
|
|
1854
|
+
*/
|
|
1855
|
+
/**
|
|
1856
|
+
* Error codes for Lynkow SDK errors
|
|
1857
|
+
*/
|
|
1858
|
+
type ErrorCode = 'BAD_REQUEST' | 'VALIDATION_ERROR' | 'UNAUTHORIZED' | 'FORBIDDEN' | 'NOT_FOUND' | 'RATE_LIMITED' | 'TOO_MANY_REQUESTS' | 'TIMEOUT' | 'NETWORK_ERROR' | 'INTERNAL_ERROR' | 'SERVICE_UNAVAILABLE' | 'UNKNOWN';
|
|
1859
|
+
/**
|
|
1860
|
+
* API error detail from server response
|
|
1861
|
+
*/
|
|
1862
|
+
interface ApiErrorDetail {
|
|
1863
|
+
message: string;
|
|
1864
|
+
field?: string;
|
|
1865
|
+
code?: string;
|
|
1866
|
+
}
|
|
1867
|
+
/**
|
|
1868
|
+
* Custom error class for Lynkow SDK
|
|
1869
|
+
* Provides structured error information including HTTP status codes and error details
|
|
1870
|
+
*/
|
|
1871
|
+
declare class LynkowError extends Error {
|
|
1872
|
+
/**
|
|
1873
|
+
* Error name (always 'LynkowError')
|
|
1874
|
+
*/
|
|
1875
|
+
readonly name = "LynkowError";
|
|
1876
|
+
/**
|
|
1877
|
+
* Error code for categorization
|
|
1878
|
+
*/
|
|
1879
|
+
readonly code: ErrorCode;
|
|
1880
|
+
/**
|
|
1881
|
+
* HTTP status code (if applicable)
|
|
1882
|
+
*/
|
|
1883
|
+
readonly status?: number;
|
|
1884
|
+
/**
|
|
1885
|
+
* Additional error details from the API
|
|
1886
|
+
*/
|
|
1887
|
+
readonly details?: ApiErrorDetail[];
|
|
1888
|
+
/**
|
|
1889
|
+
* Original error that caused this error (if any)
|
|
1890
|
+
*/
|
|
1891
|
+
readonly cause?: Error;
|
|
1892
|
+
constructor(message: string, code: ErrorCode, status?: number, details?: ApiErrorDetail[], cause?: Error);
|
|
1893
|
+
/**
|
|
1894
|
+
* Create a LynkowError from an HTTP response
|
|
1895
|
+
*/
|
|
1896
|
+
static fromResponse(response: Response): Promise<LynkowError>;
|
|
1897
|
+
/**
|
|
1898
|
+
* Create a LynkowError from a network error
|
|
1899
|
+
*/
|
|
1900
|
+
static fromNetworkError(error: Error): LynkowError;
|
|
1901
|
+
/**
|
|
1902
|
+
* Map HTTP status code to error code
|
|
1903
|
+
*/
|
|
1904
|
+
private static statusToCode;
|
|
1905
|
+
/**
|
|
1906
|
+
* Convert error to a plain object for serialization
|
|
1907
|
+
*/
|
|
1908
|
+
toJSON(): Record<string, unknown>;
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* Type guard to check if an error is a LynkowError
|
|
1912
|
+
*
|
|
1913
|
+
* @example
|
|
1914
|
+
* ```typescript
|
|
1915
|
+
* try {
|
|
1916
|
+
* await lynkow.contents.getBySlug('not-found')
|
|
1917
|
+
* } catch (error) {
|
|
1918
|
+
* if (isLynkowError(error) && error.code === 'NOT_FOUND') {
|
|
1919
|
+
* // Handle 404
|
|
1920
|
+
* }
|
|
1921
|
+
* }
|
|
1922
|
+
* ```
|
|
1923
|
+
*/
|
|
1924
|
+
declare function isLynkowError(error: unknown): error is LynkowError;
|
|
1925
|
+
|
|
1926
|
+
/**
|
|
1927
|
+
* Environment detection utilities
|
|
1928
|
+
* Determines if code is running in browser or server environment
|
|
1929
|
+
*/
|
|
1930
|
+
/**
|
|
1931
|
+
* Check if running in a browser environment
|
|
1932
|
+
*/
|
|
1933
|
+
declare const isBrowser: boolean;
|
|
1934
|
+
/**
|
|
1935
|
+
* Check if running in a server environment (Node.js, Deno, etc.)
|
|
1936
|
+
*/
|
|
1937
|
+
declare const isServer: boolean;
|
|
1938
|
+
/**
|
|
1939
|
+
* Execute a function only in browser environment
|
|
1940
|
+
* Returns the fallback value in server environment
|
|
1941
|
+
*
|
|
1942
|
+
* @param fn - Function to execute in browser
|
|
1943
|
+
* @param fallback - Value to return in server environment
|
|
1944
|
+
* @returns Result of fn() in browser, fallback in server
|
|
1945
|
+
*
|
|
1946
|
+
* @example
|
|
1947
|
+
* ```typescript
|
|
1948
|
+
* const visitorId = browserOnly(
|
|
1949
|
+
* () => localStorage.getItem('visitor_id'),
|
|
1950
|
+
* null
|
|
1951
|
+
* )
|
|
1952
|
+
* ```
|
|
1953
|
+
*/
|
|
1954
|
+
declare function browserOnly<T>(fn: () => T, fallback: T): T;
|
|
1955
|
+
/**
|
|
1956
|
+
* Execute an async function only in browser environment
|
|
1957
|
+
* Returns the fallback value in server environment
|
|
1958
|
+
*
|
|
1959
|
+
* @param fn - Async function to execute in browser
|
|
1960
|
+
* @param fallback - Value to return in server environment
|
|
1961
|
+
* @returns Promise resolving to result of fn() in browser, fallback in server
|
|
1962
|
+
*
|
|
1963
|
+
* @example
|
|
1964
|
+
* ```typescript
|
|
1965
|
+
* const config = await browserOnlyAsync(
|
|
1966
|
+
* () => fetchConfig(),
|
|
1967
|
+
* defaultConfig
|
|
1968
|
+
* )
|
|
1969
|
+
* ```
|
|
1970
|
+
*/
|
|
1971
|
+
declare function browserOnlyAsync<T>(fn: () => Promise<T>, fallback: T): Promise<T>;
|
|
1972
|
+
|
|
1973
|
+
export { type Alternate, type ApiErrorDetail, type Author, type BaseRequestOptions, type CategoriesListResponse, type Category, type CategoryDetail, type CategoryDetailResponse, type CategoryOptions, type CategoryResolveResponse, type CategoryTreeNode, type CategoryTreeResponse, type CategoryWithCount, type Client, type ClientConfig, type ConsentCategories, type ConsentLogResponse, type Content, type ContentBlock, type ContentBody, type ContentResolveResponse, type ContentSummary, type ContentsFilters, type ContentsListResponse, type CookieCategory, type CookieConfig, type CookiePreferences, type CookieTexts, type ErrorCode, type EventData, type EventName, type Form, type FormField, type FormFieldOption, type FormFieldType, type FormFieldValidation, type FormSettings, type FormSubmitData, type FormSubmitResponse, type FunnelStepData, type GlobalBlock, type GlobalBlockResponse, type LegalDocument, type LynkowClient, type LynkowConfig, LynkowError, type LynkowEvents, type Page, type PageSeo, type PageSummary, type PagesListResponse, type PageviewData, type PaginatedResponse, type PaginationMeta, type PaginationOptions, type Path, type PathsListResponse, type Redirect, type ResolveResponse, type Review, type ReviewResponse, type ReviewSettings, type ReviewSubmitData, type ReviewSubmitResponse, type ReviewsFilters, type ReviewsListResponse, type SiteConfig, type SiteConfigResponse, type SortOptions, type SubmitOptions, type Tag, type TagsListResponse, browserOnly, browserOnlyAsync, createClient, createLynkowClient, isBrowser, isCategoryResolve, isContentResolve, isLynkowError, isServer };
|