lynkow 3.5.0 → 3.6.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/dist/index.d.mts +39 -6
- package/dist/index.d.ts +39 -6
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1214,6 +1214,37 @@ interface ReviewSubmitData {
|
|
|
1214
1214
|
content: string;
|
|
1215
1215
|
}
|
|
1216
1216
|
|
|
1217
|
+
/**
|
|
1218
|
+
* Locale info with display name and flag
|
|
1219
|
+
*/
|
|
1220
|
+
interface LocaleInfo {
|
|
1221
|
+
/** Locale code (e.g., 'fr', 'en') */
|
|
1222
|
+
code: string;
|
|
1223
|
+
/** Display name (e.g., 'Français', 'English') */
|
|
1224
|
+
name: string;
|
|
1225
|
+
/** Flag emoji (e.g., '🇫🇷', '🇬🇧') */
|
|
1226
|
+
flag: string;
|
|
1227
|
+
}
|
|
1228
|
+
/**
|
|
1229
|
+
* i18n configuration for language switching
|
|
1230
|
+
*/
|
|
1231
|
+
interface I18nConfig {
|
|
1232
|
+
/** Whether multi-language is enabled */
|
|
1233
|
+
enabled: boolean;
|
|
1234
|
+
/** Default locale code */
|
|
1235
|
+
default: string;
|
|
1236
|
+
/** Available locales with display info */
|
|
1237
|
+
locales: LocaleInfo[];
|
|
1238
|
+
/** Whether to show language switcher */
|
|
1239
|
+
switcher: boolean;
|
|
1240
|
+
/** Language detection settings */
|
|
1241
|
+
detection: {
|
|
1242
|
+
enabled: boolean;
|
|
1243
|
+
order: string[];
|
|
1244
|
+
cookieName: string;
|
|
1245
|
+
cookieMaxAge: number;
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
1217
1248
|
/**
|
|
1218
1249
|
* Public site configuration
|
|
1219
1250
|
*/
|
|
@@ -1231,17 +1262,19 @@ interface SiteConfig {
|
|
|
1231
1262
|
/** Favicon URL */
|
|
1232
1263
|
faviconUrl: string | null;
|
|
1233
1264
|
/** Timezone */
|
|
1234
|
-
timezone: string;
|
|
1265
|
+
timezone: string | null;
|
|
1235
1266
|
/** Default locale */
|
|
1236
1267
|
defaultLocale: string;
|
|
1237
|
-
/**
|
|
1238
|
-
multiLanguageEnabled: boolean;
|
|
1239
|
-
/** Available locales */
|
|
1268
|
+
/** Available locales (codes only) */
|
|
1240
1269
|
enabledLocales: string[];
|
|
1241
|
-
/**
|
|
1242
|
-
|
|
1270
|
+
/** Rich i18n configuration (names, flags, detection) */
|
|
1271
|
+
i18n: I18nConfig;
|
|
1243
1272
|
/** Show branding badge (free plan) */
|
|
1244
1273
|
showBranding: boolean;
|
|
1274
|
+
/** Analytics configuration */
|
|
1275
|
+
analytics: {
|
|
1276
|
+
consentMode: 'opt-in' | 'opt-out' | 'disabled';
|
|
1277
|
+
};
|
|
1245
1278
|
}
|
|
1246
1279
|
|
|
1247
1280
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1214,6 +1214,37 @@ interface ReviewSubmitData {
|
|
|
1214
1214
|
content: string;
|
|
1215
1215
|
}
|
|
1216
1216
|
|
|
1217
|
+
/**
|
|
1218
|
+
* Locale info with display name and flag
|
|
1219
|
+
*/
|
|
1220
|
+
interface LocaleInfo {
|
|
1221
|
+
/** Locale code (e.g., 'fr', 'en') */
|
|
1222
|
+
code: string;
|
|
1223
|
+
/** Display name (e.g., 'Français', 'English') */
|
|
1224
|
+
name: string;
|
|
1225
|
+
/** Flag emoji (e.g., '🇫🇷', '🇬🇧') */
|
|
1226
|
+
flag: string;
|
|
1227
|
+
}
|
|
1228
|
+
/**
|
|
1229
|
+
* i18n configuration for language switching
|
|
1230
|
+
*/
|
|
1231
|
+
interface I18nConfig {
|
|
1232
|
+
/** Whether multi-language is enabled */
|
|
1233
|
+
enabled: boolean;
|
|
1234
|
+
/** Default locale code */
|
|
1235
|
+
default: string;
|
|
1236
|
+
/** Available locales with display info */
|
|
1237
|
+
locales: LocaleInfo[];
|
|
1238
|
+
/** Whether to show language switcher */
|
|
1239
|
+
switcher: boolean;
|
|
1240
|
+
/** Language detection settings */
|
|
1241
|
+
detection: {
|
|
1242
|
+
enabled: boolean;
|
|
1243
|
+
order: string[];
|
|
1244
|
+
cookieName: string;
|
|
1245
|
+
cookieMaxAge: number;
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
1217
1248
|
/**
|
|
1218
1249
|
* Public site configuration
|
|
1219
1250
|
*/
|
|
@@ -1231,17 +1262,19 @@ interface SiteConfig {
|
|
|
1231
1262
|
/** Favicon URL */
|
|
1232
1263
|
faviconUrl: string | null;
|
|
1233
1264
|
/** Timezone */
|
|
1234
|
-
timezone: string;
|
|
1265
|
+
timezone: string | null;
|
|
1235
1266
|
/** Default locale */
|
|
1236
1267
|
defaultLocale: string;
|
|
1237
|
-
/**
|
|
1238
|
-
multiLanguageEnabled: boolean;
|
|
1239
|
-
/** Available locales */
|
|
1268
|
+
/** Available locales (codes only) */
|
|
1240
1269
|
enabledLocales: string[];
|
|
1241
|
-
/**
|
|
1242
|
-
|
|
1270
|
+
/** Rich i18n configuration (names, flags, detection) */
|
|
1271
|
+
i18n: I18nConfig;
|
|
1243
1272
|
/** Show branding badge (free plan) */
|
|
1244
1273
|
showBranding: boolean;
|
|
1274
|
+
/** Analytics configuration */
|
|
1275
|
+
analytics: {
|
|
1276
|
+
consentMode: 'opt-in' | 'opt-out' | 'disabled';
|
|
1277
|
+
};
|
|
1245
1278
|
}
|
|
1246
1279
|
|
|
1247
1280
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var C=class n extends Error{name="LynkowError";code;status;details;cause;constructor(e,t,o,r,i){super(e),this.code=t,this.status=o,this.details=r,this.cause=i,Error.captureStackTrace&&Error.captureStackTrace(this,n);}static async fromResponse(e){let t=e.status,o=`HTTP ${t}`,r;try{let s=await e.json();s.errors&&Array.isArray(s.errors)?(r=s.errors,o=s.errors[0]?.message||o):s.error?o=s.error:s.message&&(o=s.message);}catch{o=e.statusText||o;}let i=n.statusToCode(t);return new n(o,i,t,r)}static fromNetworkError(e){return e.name==="AbortError"?new n("Request timed out","TIMEOUT",void 0,void 0,e):e.name==="TypeError"?new n("Network error - please check your connection","NETWORK_ERROR",void 0,void 0,e):new n(e.message||"Unknown error","UNKNOWN",void 0,void 0,e)}static statusToCode(e){switch(e){case 400:return "VALIDATION_ERROR";case 401:return "UNAUTHORIZED";case 403:return "FORBIDDEN";case 404:return "NOT_FOUND";case 429:return "RATE_LIMITED";default:return "UNKNOWN"}}toJSON(){return {name:this.name,message:this.message,code:this.code,status:this.status,details:this.details}}};function de(n){return n instanceof C}function ge(n){switch(n){case 400:return "BAD_REQUEST";case 401:return "UNAUTHORIZED";case 403:return "FORBIDDEN";case 404:return "NOT_FOUND";case 422:return "VALIDATION_ERROR";case 429:return "TOO_MANY_REQUESTS";case 503:return "SERVICE_UNAVAILABLE";default:return "INTERNAL_ERROR"}}async function K(n,e){let t;try{t=await fetch(n,e);}catch(l){throw new C("Network error: Unable to reach the server","NETWORK_ERROR",0,[{message:l instanceof Error?l.message:"Unknown error"}])}if(t.ok)return t.json();let o={};try{o=await t.json();}catch{}let r=ge(t.status),i=o.error||o.message||`HTTP error: ${t.status}`,s=o.errors||[{message:i}];throw new C(i,r,t.status,s)}function Q(n){let e=new URLSearchParams;for(let[t,o]of Object.entries(n))o!=null&&o!==""&&e.append(t,String(o));return e.toString()}var p={SHORT:300*1e3,MEDIUM:600*1e3},u=class{config;cache;constructor(e){this.config=e,this.cache=e.cache;}buildEndpointUrl(e,t){let o=`${this.config.baseUrl}/public/${this.config.siteId}${e}`;if(t&&Object.keys(t).length>0){let r=Q(t);return `${o}?${r}`}return o}async get(e,t,o){let r=o?.locale||this.config.locale,i=r?{...t,locale:r}:t,s=this.buildEndpointUrl(e,i),l=this.mergeFetchOptions(o?.fetchOptions);return K(s,{method:"GET",...l})}async getWithCache(e,t,o,r,i=p.SHORT){return this.cache?this.cache.getOrSet(e,()=>this.get(t,o,r),i):this.get(t,o,r)}invalidateCache(e){this.cache?.invalidate(e);}async post(e,t,o){let r=this.buildEndpointUrl(e),i=this.mergeFetchOptions(o?.fetchOptions);return K(r,{method:"POST",...i,headers:{"Content-Type":"application/json",...i.headers},body:JSON.stringify(t)})}async getText(e,t){let o=this.buildEndpointUrl(e),r=this.mergeFetchOptions(t?.fetchOptions),i=await fetch(o,{method:"GET",...r});if(!i.ok)throw new Error(`HTTP error: ${i.status}`);return i.text()}mergeFetchOptions(e){return {...this.config.fetchOptions,...e,headers:{...this.config.fetchOptions.headers,...e?.headers}}}};var M="contents_",R=class extends u{async list(e,t){let o={};e?.page&&(o.page=e.page),e?.perPage&&(o.perPage=e.perPage),e?.category&&(o.category=e.category),e?.tag&&(o.tag=e.tag),e?.search&&(o.search=e.search),e?.sort&&(o.sort=e.sort),e?.order&&(o.order=e.order),e?.locale&&(o.locale=e.locale);let r=`${M}list_${JSON.stringify(e||{})}`;return this.getWithCache(r,"/contents",o,t,p.SHORT)}async getBySlug(e,t){let o=t?.locale||this.config.locale,r=`${M}slug_${e}_${o||"default"}`;return this.getWithCache(r,`/contents/slug/${encodeURIComponent(e)}`,void 0,t,p.SHORT)}clearCache(){this.invalidateCache(M);}};var D="categories_",k=class extends u{async list(e){let t=e?.locale||this.config.locale,o=`${D}list_${t||"default"}`;return this.getWithCache(o,"/categories",void 0,e,p.SHORT)}async tree(e){let t=e?.locale||this.config.locale,o=`${D}tree_${t||"default"}`;return this.getWithCache(o,"/categories/tree",void 0,e,p.SHORT)}async getBySlug(e,t){let o={};t?.page&&(o.page=t.page),t?.perPage&&(o.limit=t.perPage);let r=`${D}slug_${e}_${JSON.stringify(t||{})}`;return this.getWithCache(r,`/categories/${encodeURIComponent(e)}`,o,t,p.SHORT)}clearCache(){this.invalidateCache(D);}};var Z="tags_",x=class extends u{async list(e){let t=e?.locale||this.config.locale,o=`${Z}list_${t||"default"}`;return this.getWithCache(o,"/tags",void 0,e,p.SHORT)}clearCache(){this.invalidateCache(Z);}};var E="pages_",L=class extends u{async list(e){let t=e?.locale||this.config.locale,o={};e?.tag&&(o.tag=e.tag);let r=`${E}list_${t||"default"}_${e?.tag||"all"}`;return this.getWithCache(r,"/pages",o,e,p.SHORT)}async getBySlug(e,t){let o=t?.locale||this.config.locale,r=`${E}slug_${e}_${o||"default"}`;return (await this.getWithCache(r,`/pages/${encodeURIComponent(e)}`,void 0,t,p.SHORT)).data}async getByPath(e,t){let o=t?.locale||this.config.locale,r=`${E}path_${e}_${o||"default"}`;return (await this.getWithCache(r,"/page-by-path",{path:e},t,p.SHORT)).data}async getJsonLd(e,t){let o=t?.locale||this.config.locale,r=`${E}jsonld_${e}_${o||"default"}`;return (await this.getWithCache(r,`/pages/${encodeURIComponent(e)}/json-ld`,void 0,t,p.SHORT)).data}clearCache(){this.invalidateCache(E);}};var z="globals_",T=class extends u{async siteConfig(e){let t=e?.locale||this.config.locale,o=`${z}siteconfig_${t||"default"}`;return this.getWithCache(o,"/site-config",void 0,e,p.MEDIUM)}async getBySlug(e,t){let o=t?.locale||this.config.locale,r=`${z}${e}_${o||"default"}`;return this.getWithCache(r,`/global/${encodeURIComponent(e)}`,void 0,t,p.MEDIUM)}async global(e,t){return this.getBySlug(e,t)}clearCache(){this.invalidateCache(z);}};function N(n){return {_hp:"",_ts:n}}var ee="forms_",S=class extends u{sessionStartTime;constructor(e){super(e),this.sessionStartTime=Date.now();}async getBySlug(e){let t=`${ee}${e}`;return (await this.getWithCache(t,`/forms/${encodeURIComponent(e)}`,void 0,void 0,p.MEDIUM)).data}async submit(e,t,o){let r=N(this.sessionStartTime),i={data:t,honeypot:r._hp,...r};return o?.recaptchaToken&&(i.recaptchaToken=o.recaptchaToken),this.post(`/forms/${encodeURIComponent(e)}/submit`,i,o)}clearCache(){this.invalidateCache(ee);}};var O="reviews_",P=class extends u{sessionStartTime;constructor(e){super(e),this.sessionStartTime=Date.now();}async list(e,t){let o={};e?.page&&(o.page=e.page),e?.perPage&&(o.perPage=e.perPage),e?.minRating&&(o.minRating=e.minRating),e?.maxRating&&(o.maxRating=e.maxRating),e?.sort&&(o.sort=e.sort),e?.order&&(o.order=e.order);let r=`${O}list_${JSON.stringify(e||{})}`;return this.getWithCache(r,"/reviews",o,t,p.SHORT)}async getBySlug(e){let t=`${O}slug_${e}`;return (await this.getWithCache(t,`/reviews/${encodeURIComponent(e)}`,void 0,void 0,p.SHORT)).data}async settings(){let e=`${O}settings`;return this.getWithCache(e,"/reviews/settings",void 0,void 0,p.MEDIUM)}async submit(e,t){let o=N(this.sessionStartTime),r={...e,...o};t?.recaptchaToken&&(r._recaptcha_token=t.recaptchaToken);let i=await this.post("/reviews",r,t);return this.invalidateCache(O),i}clearCache(){this.invalidateCache(O);}};var te="site_",B=class extends u{async getConfig(){let e=`${te}config`;return (await this.getWithCache(e,"/site",void 0,void 0,p.MEDIUM)).data}clearCache(){this.invalidateCache(te);}};var W="legal_",I=class extends u{async list(e){let t=e?.locale||this.config.locale,o=`${W}list_${t||"default"}`;return (await this.getWithCache(o,"/pages",{tag:"legal"},e,p.SHORT)).data}async getBySlug(e,t){let o=t?.locale||this.config.locale,r=`${W}slug_${e}_${o||"default"}`;return (await this.getWithCache(r,`/pages/${encodeURIComponent(e)}`,void 0,t,p.SHORT)).data}clearCache(){this.invalidateCache(W);}};var oe="cookies_",$=class extends u{async getConfig(){let e=`${oe}config`;return (await this.getWithCache(e,"/cookie-consent/config",void 0,void 0,p.MEDIUM)).data}async logConsent(e,t){return this.post("/cookie-consent/log",{preferences:e},t)}clearCache(){this.invalidateCache(oe);}};var A=class extends u{async sitemap(e){return this.getText("/sitemap.xml",e)}async robots(e){return this.getText("/robots.txt",e)}};var j="paths_",_=class extends u{async list(e){let t=e?.locale||this.config.locale,o=`${j}list_${t||"all"}`;return this.getWithCache(o,"/paths",void 0,e,p.SHORT)}async resolve(e,t){let o=t?.locale||this.config.locale,r=`${j}resolve_${e}_${o||"default"}`;return this.getWithCache(r,"/resolve",{path:e},t,p.SHORT)}async matchRedirect(e,t){try{return (await this.get("/redirects/match",{path:e},t)).data}catch(o){if(o instanceof C&&o.status===404)return null;throw o}}clearCache(){this.invalidateCache(j);}};var a=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",ue=!a;function me(n,e){return a?n():e}async function fe(n,e){return a?n():e}var G="lynkow-tracker",U=class{config;enabled=true;initialized=false;loading=false;loadPromise=null;constructor(e){this.config=e;}getTrackerUrl(){return `${this.config.baseUrl}/analytics/tracker.js`}loadTracker(){return !a||window.LynkowAnalytics?Promise.resolve():this.loadPromise?this.loadPromise:(this.loading=true,this.loadPromise=new Promise((e,t)=>{if(document.getElementById(G)){let r=setInterval(()=>{window.LynkowAnalytics&&(clearInterval(r),this.loading=false,e());},50);setTimeout(()=>{clearInterval(r),this.loading=false,t(new Error("Tracker script load timeout"));},1e4);return}let o=document.createElement("script");o.id=G,o.src=this.getTrackerUrl(),o.async=true,o.setAttribute("data-site-id",this.config.siteId),this.config.baseUrl&&o.setAttribute("data-api-url",this.config.baseUrl),o.onload=()=>{this.loading=false,setTimeout(()=>{window.LynkowAnalytics?e():t(new Error("Tracker script loaded but LynkowAnalytics not found"));},0);},o.onerror=()=>{this.loading=false,t(new Error("Failed to load tracker script"));},document.head.appendChild(o);}),this.loadPromise)}async init(){if(!(!a||this.initialized))try{await this.loadTracker(),window.LynkowAnalytics&&!this.initialized&&(this.initialized=!0);}catch(e){console.error("[Lynkow] Failed to initialize analytics:",e);}}async trackEvent(e){!a||!this.enabled||(await this.init(),window.LynkowAnalytics&&window.LynkowAnalytics.track(e));}async trackFunnelStep(e){!a||!this.enabled||(await this.init(),window.LynkowAnalytics&&window.LynkowAnalytics.trackFunnel(e.funnelId,e.stepNumber,e.stepName,e.funnelName));}async trackPageview(e){!a||!this.enabled||(await this.init(),window.LynkowAnalytics&&window.LynkowAnalytics.track({type:"pageview",path:e?.path||window.location.pathname,title:e?.title||document.title,referrer:e?.referrer||document.referrer}));}enable(){this.enabled=true;}disable(){this.enabled=false;}isEnabled(){return this.enabled}isInitialized(){return this.initialized&&!!window.LynkowAnalytics}getTracker(){if(a)return window.LynkowAnalytics}destroy(){if(!a)return;document.getElementById(G)?.remove(),this.initialized=false,this.loadPromise=null;}};var J="_lkw_consent",V={necessary:true,analytics:false,marketing:false,preferences:false},H=class{config;events;bannerElement=null;preferencesElement=null;configCache=null;constructor(e,t){this.config=e,this.events=t;}async getConfig(){if(this.configCache)return this.configCache;let e=`${this.config.baseUrl}/public/${this.config.siteId}/cookie-consent/config`,t=await fetch(e,{method:"GET",headers:{"Content-Type":"application/json"},...this.config.fetchOptions});if(!t.ok)throw new Error(`Failed to fetch consent config: ${t.status}`);let o=await t.json();return this.configCache=o.data,this.configCache}async logConsent(e){let t=`${this.config.baseUrl}/public/${this.config.siteId}/cookie-consent/log`;await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({preferences:e}),...this.config.fetchOptions}).catch(()=>{});}getStoredConsent(){if(!a)return null;try{let e=localStorage.getItem(J);if(e){let t=JSON.parse(e);return t.choices?t.choices:t}}catch{}return null}saveConsent(e){if(a){try{localStorage.setItem(J,JSON.stringify({choices:e}));}catch{}this.events.emit("consent-changed",e),document.dispatchEvent(new CustomEvent("lynkow:consent:update",{detail:e}));}}show(){a&&(this.bannerElement||this.getConfig().then(e=>{if(!e.enabled)return;let t=document.createElement("div");t.innerHTML=this.createBannerHTML(e),this.bannerElement=t.firstElementChild,document.body.appendChild(this.bannerElement),this.attachBannerEvents();}));}hide(){a&&(this.bannerElement?.remove(),this.bannerElement=null);}showPreferences(){a&&(this.preferencesElement||this.getConfig().then(e=>{let t=this.getCategories(),o=document.createElement("div");o.innerHTML=this.createPreferencesHTML(e,t),this.preferencesElement=o.firstElementChild,document.body.appendChild(this.preferencesElement),this.attachPreferencesEvents(e);}));}getCategories(){return a?this.getStoredConsent()||{...V}:{...V}}hasConsented(){return a?this.getStoredConsent()!==null:false}acceptAll(){if(!a)return;let e={necessary:true,analytics:true,marketing:true,preferences:true};this.saveConsent(e),this.logConsent(e),this.hide();}rejectAll(){if(!a)return;let e={necessary:true,analytics:false,marketing:false,preferences:false};this.saveConsent(e),this.logConsent(e),this.hide();}setCategories(e){if(!a)return;let o={...this.getCategories(),...e,necessary:true};this.saveConsent(o),this.logConsent(o);}reset(){if(a){try{localStorage.removeItem(J);}catch{}this.events.emit("consent-changed",{...V}),this.show();}}createBannerHTML(e){let t=e.position||"bottom",o=e.theme||"light",r=e.layout||"banner",i=e.primaryColor||"#0066cc",s=e.borderRadius??8,l={bottom:"bottom: 0; left: 0; right: 0;",top:"top: 0; left: 0; right: 0;","bottom-left":"bottom: 0; left: 0; right: 0;","bottom-right":"bottom: 0; left: 0; right: 0;",center:"top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 500px; width: calc(100% - 40px);"},f={bottom:`bottom: 20px; left: 50%; transform: translateX(-50%); max-width: 500px; width: calc(100% - 40px); border-radius: ${s}px;`,top:`top: 20px; left: 50%; transform: translateX(-50%); max-width: 500px; width: calc(100% - 40px); border-radius: ${s}px;`,"bottom-left":`bottom: 20px; left: 20px; max-width: 400px; border-radius: ${s}px;`,"bottom-right":`bottom: 20px; right: 20px; max-width: 400px; border-radius: ${s}px;`,center:`top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 500px; width: calc(100% - 40px); border-radius: ${s}px;`},h={center:`top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 500px; width: calc(100% - 40px); border-radius: ${s}px;`,bottom:`top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 500px; width: calc(100% - 40px); border-radius: ${s}px;`,top:`top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 500px; width: calc(100% - 40px); border-radius: ${s}px;`,"bottom-left":`top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 500px; width: calc(100% - 40px); border-radius: ${s}px;`,"bottom-right":`top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 500px; width: calc(100% - 40px); border-radius: ${s}px;`},g;r==="floating"?g=f:r==="modal"?g=h:g=l;let c=g[t]||g.bottom||"",d=o==="dark",m=d?"#1a1a1a":"#ffffff",y=d?"#ffffff":"#1a1a1a",b=e.texts||{title:"Nous utilisons des cookies",description:"Ce site utilise des cookies pour ameliorer votre experience.",acceptAll:"Accepter tout",rejectAll:"Refuser",customize:"Personnaliser"};return `
|
|
1
|
+
'use strict';var C=class n extends Error{name="LynkowError";code;status;details;cause;constructor(e,t,o,r,i){super(e),this.code=t,this.status=o,this.details=r,this.cause=i,Error.captureStackTrace&&Error.captureStackTrace(this,n);}static async fromResponse(e){let t=e.status,o=`HTTP ${t}`,r;try{let s=await e.json();s.errors&&Array.isArray(s.errors)?(r=s.errors,o=s.errors[0]?.message||o):s.error?o=s.error:s.message&&(o=s.message);}catch{o=e.statusText||o;}let i=n.statusToCode(t);return new n(o,i,t,r)}static fromNetworkError(e){return e.name==="AbortError"?new n("Request timed out","TIMEOUT",void 0,void 0,e):e.name==="TypeError"?new n("Network error - please check your connection","NETWORK_ERROR",void 0,void 0,e):new n(e.message||"Unknown error","UNKNOWN",void 0,void 0,e)}static statusToCode(e){switch(e){case 400:return "VALIDATION_ERROR";case 401:return "UNAUTHORIZED";case 403:return "FORBIDDEN";case 404:return "NOT_FOUND";case 429:return "RATE_LIMITED";default:return "UNKNOWN"}}toJSON(){return {name:this.name,message:this.message,code:this.code,status:this.status,details:this.details}}};function de(n){return n instanceof C}function ge(n){switch(n){case 400:return "BAD_REQUEST";case 401:return "UNAUTHORIZED";case 403:return "FORBIDDEN";case 404:return "NOT_FOUND";case 422:return "VALIDATION_ERROR";case 429:return "TOO_MANY_REQUESTS";case 503:return "SERVICE_UNAVAILABLE";default:return "INTERNAL_ERROR"}}async function K(n,e){let t;try{t=await fetch(n,e);}catch(l){throw new C("Network error: Unable to reach the server","NETWORK_ERROR",0,[{message:l instanceof Error?l.message:"Unknown error"}])}if(t.ok)return t.json();let o={};try{o=await t.json();}catch{}let r=ge(t.status),i=o.error||o.message||`HTTP error: ${t.status}`,s=o.errors||[{message:i}];throw new C(i,r,t.status,s)}function Q(n){let e=new URLSearchParams;for(let[t,o]of Object.entries(n))o!=null&&o!==""&&e.append(t,String(o));return e.toString()}var p={SHORT:300*1e3,MEDIUM:600*1e3},u=class{config;cache;constructor(e){this.config=e,this.cache=e.cache;}buildEndpointUrl(e,t){let o=`${this.config.baseUrl}/public/${this.config.siteId}${e}`;if(t&&Object.keys(t).length>0){let r=Q(t);return `${o}?${r}`}return o}async get(e,t,o){let r=o?.locale||this.config.locale,i=r?{...t,locale:r}:t,s=this.buildEndpointUrl(e,i),l=this.mergeFetchOptions(o?.fetchOptions);return K(s,{method:"GET",...l})}async getWithCache(e,t,o,r,i=p.SHORT){return this.cache?this.cache.getOrSet(e,()=>this.get(t,o,r),i):this.get(t,o,r)}invalidateCache(e){this.cache?.invalidate(e);}async post(e,t,o){let r=this.buildEndpointUrl(e),i=this.mergeFetchOptions(o?.fetchOptions);return K(r,{method:"POST",...i,headers:{"Content-Type":"application/json",...i.headers},body:JSON.stringify(t)})}async getText(e,t){let o=this.buildEndpointUrl(e),r=this.mergeFetchOptions(t?.fetchOptions),i=await fetch(o,{method:"GET",...r});if(!i.ok)throw new Error(`HTTP error: ${i.status}`);return i.text()}mergeFetchOptions(e){return {...this.config.fetchOptions,...e,headers:{...this.config.fetchOptions.headers,...e?.headers}}}};var M="contents_",R=class extends u{async list(e,t){let o={};e?.page&&(o.page=e.page),e?.perPage&&(o.perPage=e.perPage),e?.category&&(o.category=e.category),e?.tag&&(o.tag=e.tag),e?.search&&(o.search=e.search),e?.sort&&(o.sort=e.sort),e?.order&&(o.order=e.order),e?.locale&&(o.locale=e.locale);let r=`${M}list_${JSON.stringify(e||{})}`;return this.getWithCache(r,"/contents",o,t,p.SHORT)}async getBySlug(e,t){let o=t?.locale||this.config.locale,r=`${M}slug_${e}_${o||"default"}`;return this.getWithCache(r,`/contents/slug/${encodeURIComponent(e)}`,void 0,t,p.SHORT)}clearCache(){this.invalidateCache(M);}};var D="categories_",k=class extends u{async list(e){let t=e?.locale||this.config.locale,o=`${D}list_${t||"default"}`;return this.getWithCache(o,"/categories",void 0,e,p.SHORT)}async tree(e){let t=e?.locale||this.config.locale,o=`${D}tree_${t||"default"}`;return this.getWithCache(o,"/categories/tree",void 0,e,p.SHORT)}async getBySlug(e,t){let o={};t?.page&&(o.page=t.page),t?.perPage&&(o.limit=t.perPage);let r=`${D}slug_${e}_${JSON.stringify(t||{})}`;return this.getWithCache(r,`/categories/${encodeURIComponent(e)}`,o,t,p.SHORT)}clearCache(){this.invalidateCache(D);}};var Z="tags_",x=class extends u{async list(e){let t=e?.locale||this.config.locale,o=`${Z}list_${t||"default"}`;return this.getWithCache(o,"/tags",void 0,e,p.SHORT)}clearCache(){this.invalidateCache(Z);}};var E="pages_",L=class extends u{async list(e){let t=e?.locale||this.config.locale,o={};e?.tag&&(o.tag=e.tag);let r=`${E}list_${t||"default"}_${e?.tag||"all"}`;return this.getWithCache(r,"/pages",o,e,p.SHORT)}async getBySlug(e,t){let o=t?.locale||this.config.locale,r=`${E}slug_${e}_${o||"default"}`;return (await this.getWithCache(r,`/pages/${encodeURIComponent(e)}`,void 0,t,p.SHORT)).data}async getByPath(e,t){let o=t?.locale||this.config.locale,r=`${E}path_${e}_${o||"default"}`;return (await this.getWithCache(r,"/page-by-path",{path:e},t,p.SHORT)).data}async getJsonLd(e,t){let o=t?.locale||this.config.locale,r=`${E}jsonld_${e}_${o||"default"}`;return (await this.getWithCache(r,`/pages/${encodeURIComponent(e)}/json-ld`,void 0,t,p.SHORT)).data}clearCache(){this.invalidateCache(E);}};var z="globals_",T=class extends u{async siteConfig(e){let t=e?.locale||this.config.locale,o=`${z}siteconfig_${t||"default"}`;return this.getWithCache(o,"/site-config",void 0,e,p.MEDIUM)}async getBySlug(e,t){let o=t?.locale||this.config.locale,r=`${z}${e}_${o||"default"}`;return this.getWithCache(r,`/global/${encodeURIComponent(e)}`,void 0,t,p.MEDIUM)}async global(e,t){return this.getBySlug(e,t)}clearCache(){this.invalidateCache(z);}};function N(n){return {_hp:"",_ts:n}}var ee="forms_",S=class extends u{sessionStartTime;constructor(e){super(e),this.sessionStartTime=Date.now();}async getBySlug(e){let t=`${ee}${e}`;return (await this.getWithCache(t,`/forms/${encodeURIComponent(e)}`,void 0,void 0,p.MEDIUM)).data}async submit(e,t,o){let r=N(this.sessionStartTime),i={data:t,honeypot:r._hp,...r};return o?.recaptchaToken&&(i.recaptchaToken=o.recaptchaToken),this.post(`/forms/${encodeURIComponent(e)}/submit`,i,o)}clearCache(){this.invalidateCache(ee);}};var O="reviews_",P=class extends u{sessionStartTime;constructor(e){super(e),this.sessionStartTime=Date.now();}async list(e,t){let o={};e?.page&&(o.page=e.page),e?.perPage&&(o.perPage=e.perPage),e?.minRating&&(o.minRating=e.minRating),e?.maxRating&&(o.maxRating=e.maxRating),e?.sort&&(o.sort=e.sort),e?.order&&(o.order=e.order);let r=`${O}list_${JSON.stringify(e||{})}`;return this.getWithCache(r,"/reviews",o,t,p.SHORT)}async getBySlug(e){let t=`${O}slug_${e}`;return (await this.getWithCache(t,`/reviews/${encodeURIComponent(e)}`,void 0,void 0,p.SHORT)).data}async settings(){let e=`${O}settings`;return this.getWithCache(e,"/reviews/settings",void 0,void 0,p.MEDIUM)}async submit(e,t){let o=N(this.sessionStartTime),r={...e,...o};t?.recaptchaToken&&(r._recaptcha_token=t.recaptchaToken);let i=await this.post("/reviews",r,t);return this.invalidateCache(O),i}clearCache(){this.invalidateCache(O);}};var te="site_",I=class extends u{async getConfig(){let e=`${te}config`;return (await this.getWithCache(e,"/site",void 0,void 0,p.MEDIUM)).data}clearCache(){this.invalidateCache(te);}};var W="legal_",B=class extends u{async list(e){let t=e?.locale||this.config.locale,o=`${W}list_${t||"default"}`;return (await this.getWithCache(o,"/pages",{tag:"legal"},e,p.SHORT)).data}async getBySlug(e,t){let o=t?.locale||this.config.locale,r=`${W}slug_${e}_${o||"default"}`;return (await this.getWithCache(r,`/pages/${encodeURIComponent(e)}`,void 0,t,p.SHORT)).data}clearCache(){this.invalidateCache(W);}};var oe="cookies_",$=class extends u{async getConfig(){let e=`${oe}config`;return (await this.getWithCache(e,"/cookie-consent/config",void 0,void 0,p.MEDIUM)).data}async logConsent(e,t){return this.post("/cookie-consent/log",{preferences:e},t)}clearCache(){this.invalidateCache(oe);}};var A=class extends u{async sitemap(e){return this.getText("/sitemap.xml",e)}async robots(e){return this.getText("/robots.txt",e)}};var j="paths_",_=class extends u{async list(e){let t=e?.locale||this.config.locale,o=`${j}list_${t||"all"}`;return this.getWithCache(o,"/paths",void 0,e,p.SHORT)}async resolve(e,t){let o=t?.locale||this.config.locale,r=`${j}resolve_${e}_${o||"default"}`;return this.getWithCache(r,"/resolve",{path:e},t,p.SHORT)}async matchRedirect(e,t){try{return (await this.get("/redirects/match",{path:e},t)).data}catch(o){if(o instanceof C&&o.status===404)return null;throw o}}clearCache(){this.invalidateCache(j);}};var a=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",ue=!a;function me(n,e){return a?n():e}async function fe(n,e){return a?n():e}var G="lynkow-tracker",U=class{config;enabled=true;initialized=false;loading=false;loadPromise=null;constructor(e){this.config=e;}getTrackerUrl(){return `${this.config.baseUrl}/analytics/tracker.js`}loadTracker(){return !a||window.LynkowAnalytics?Promise.resolve():this.loadPromise?this.loadPromise:(this.loading=true,this.loadPromise=new Promise((e,t)=>{if(document.getElementById(G)){let r=setInterval(()=>{window.LynkowAnalytics&&(clearInterval(r),this.loading=false,e());},50);setTimeout(()=>{clearInterval(r),this.loading=false,t(new Error("Tracker script load timeout"));},1e4);return}let o=document.createElement("script");o.id=G,o.src=this.getTrackerUrl(),o.async=true,o.setAttribute("data-site-id",this.config.siteId),this.config.baseUrl&&o.setAttribute("data-api-url",this.config.baseUrl),o.onload=()=>{this.loading=false,setTimeout(()=>{window.LynkowAnalytics?e():t(new Error("Tracker script loaded but LynkowAnalytics not found"));},0);},o.onerror=()=>{this.loading=false,t(new Error("Failed to load tracker script"));},document.head.appendChild(o);}),this.loadPromise)}async init(){if(!(!a||this.initialized))try{await this.loadTracker(),window.LynkowAnalytics&&!this.initialized&&(this.initialized=!0);}catch(e){console.error("[Lynkow] Failed to initialize analytics:",e);}}async trackEvent(e){!a||!this.enabled||(await this.init(),window.LynkowAnalytics&&window.LynkowAnalytics.track(e));}async trackFunnelStep(e){!a||!this.enabled||(await this.init(),window.LynkowAnalytics&&window.LynkowAnalytics.trackFunnel(e.funnelId,e.stepNumber,e.stepName,e.funnelName));}async trackPageview(e){!a||!this.enabled||(await this.init(),window.LynkowAnalytics&&window.LynkowAnalytics.track({type:"pageview",path:e?.path||window.location.pathname,title:e?.title||document.title,referrer:e?.referrer||document.referrer}));}enable(){this.enabled=true;}disable(){this.enabled=false;}isEnabled(){return this.enabled}isInitialized(){return this.initialized&&!!window.LynkowAnalytics}getTracker(){if(a)return window.LynkowAnalytics}destroy(){if(!a)return;document.getElementById(G)?.remove(),this.initialized=false,this.loadPromise=null;}};var J="_lkw_consent",V={necessary:true,analytics:false,marketing:false,preferences:false},H=class{config;events;bannerElement=null;preferencesElement=null;configCache=null;constructor(e,t){this.config=e,this.events=t;}async getConfig(){if(this.configCache)return this.configCache;let e=`${this.config.baseUrl}/public/${this.config.siteId}/cookie-consent/config`,t=await fetch(e,{method:"GET",headers:{"Content-Type":"application/json"},...this.config.fetchOptions});if(!t.ok)throw new Error(`Failed to fetch consent config: ${t.status}`);let o=await t.json();return this.configCache=o.data,this.configCache}async logConsent(e){let t=`${this.config.baseUrl}/public/${this.config.siteId}/cookie-consent/log`;await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({preferences:e}),...this.config.fetchOptions}).catch(()=>{});}getStoredConsent(){if(!a)return null;try{let e=localStorage.getItem(J);if(e){let t=JSON.parse(e);return t.choices?t.choices:t}}catch{}return null}saveConsent(e){if(a){try{localStorage.setItem(J,JSON.stringify({choices:e}));}catch{}this.events.emit("consent-changed",e),document.dispatchEvent(new CustomEvent("lynkow:consent:update",{detail:e}));}}show(){a&&(this.bannerElement||this.getConfig().then(e=>{if(!e.enabled)return;let t=document.createElement("div");t.innerHTML=this.createBannerHTML(e),this.bannerElement=t.firstElementChild,document.body.appendChild(this.bannerElement),this.attachBannerEvents();}));}hide(){a&&(this.bannerElement?.remove(),this.bannerElement=null);}showPreferences(){a&&(this.preferencesElement||this.getConfig().then(e=>{let t=this.getCategories(),o=document.createElement("div");o.innerHTML=this.createPreferencesHTML(e,t),this.preferencesElement=o.firstElementChild,document.body.appendChild(this.preferencesElement),this.attachPreferencesEvents(e);}));}getCategories(){return a?this.getStoredConsent()||{...V}:{...V}}hasConsented(){return a?this.getStoredConsent()!==null:false}acceptAll(){if(!a)return;let e={necessary:true,analytics:true,marketing:true,preferences:true};this.saveConsent(e),this.logConsent(e),this.hide();}rejectAll(){if(!a)return;let e={necessary:true,analytics:false,marketing:false,preferences:false};this.saveConsent(e),this.logConsent(e),this.hide();}setCategories(e){if(!a)return;let o={...this.getCategories(),...e,necessary:true};this.saveConsent(o),this.logConsent(o);}reset(){if(a){try{localStorage.removeItem(J);}catch{}this.events.emit("consent-changed",{...V}),this.show();}}createBannerHTML(e){let t=e.position||"bottom",o=e.theme||"light",r=e.layout||"banner",i=e.primaryColor||"#0066cc",s=e.borderRadius??8,l={bottom:"bottom: 0; left: 0; right: 0;",top:"top: 0; left: 0; right: 0;","bottom-left":"bottom: 0; left: 0; right: 0;","bottom-right":"bottom: 0; left: 0; right: 0;",center:"top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 500px; width: calc(100% - 40px);"},f={bottom:`bottom: 20px; left: 50%; transform: translateX(-50%); max-width: 500px; width: calc(100% - 40px); border-radius: ${s}px;`,top:`top: 20px; left: 50%; transform: translateX(-50%); max-width: 500px; width: calc(100% - 40px); border-radius: ${s}px;`,"bottom-left":`bottom: 20px; left: 20px; max-width: 400px; border-radius: ${s}px;`,"bottom-right":`bottom: 20px; right: 20px; max-width: 400px; border-radius: ${s}px;`,center:`top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 500px; width: calc(100% - 40px); border-radius: ${s}px;`},h={center:`top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 500px; width: calc(100% - 40px); border-radius: ${s}px;`,bottom:`top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 500px; width: calc(100% - 40px); border-radius: ${s}px;`,top:`top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 500px; width: calc(100% - 40px); border-radius: ${s}px;`,"bottom-left":`top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 500px; width: calc(100% - 40px); border-radius: ${s}px;`,"bottom-right":`top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 500px; width: calc(100% - 40px); border-radius: ${s}px;`},g;r==="floating"?g=f:r==="modal"?g=h:g=l;let c=g[t]||g.bottom||"",d=o==="dark",m=d?"#1a1a1a":"#ffffff",y=d?"#ffffff":"#1a1a1a",b=e.texts||{title:"Nous utilisons des cookies",description:"Ce site utilise des cookies pour ameliorer votre experience.",acceptAll:"Accepter tout",rejectAll:"Refuser",customize:"Personnaliser"};return `
|
|
2
2
|
${r==="modal"?`
|
|
3
3
|
<div id="lynkow-consent-backdrop" style="
|
|
4
4
|
position: fixed;
|
|
@@ -285,6 +285,6 @@
|
|
|
285
285
|
color: #1a1a1a;
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
|
-
`,F=class{initialized=false;observer=null;injectStyles(){if(!a||document.getElementById(Y))return;let e=document.createElement("style");e.id=Y,e.textContent=we,document.head.appendChild(e);}async handleCopyClick(e){let t=e.closest(".code-block");if(!t)return;let o=t.querySelector("code");if(!o)return;let r=o.textContent||"";try{await navigator.clipboard.writeText(r),e.classList.add("copied"),e.innerHTML=Ce,setTimeout(()=>{e.classList.remove("copied"),e.innerHTML=ye;},2e3);}catch(i){console.error("Lynkow SDK: Failed to copy code",i);}}bindCodeBlockCopy(){if(!a)return;document.querySelectorAll("[data-copy-code]").forEach(t=>{t.dataset.lynkowBound||(t.dataset.lynkowBound="true",t.addEventListener("click",o=>{o.preventDefault(),this.handleCopyClick(t);}));});}init(){a&&(this.injectStyles(),this.bindCodeBlockCopy(),this.observer||(this.observer=new MutationObserver(e=>{let t=false;for(let o of e)if(o.addedNodes.length>0){t=true;break}t&&this.bindCodeBlockCopy();}),this.observer.observe(document.body,{childList:true,subtree:true})),this.initialized=true);}isInitialized(){return this.initialized}destroy(){a&&(this.observer&&(this.observer.disconnect(),this.observer=null),document.getElementById(Y)?.remove(),this.initialized=false);}};var ve=300*1e3,be="lynkow_cache_",v=new Map;function ne(n={}){let e=n.defaultTtl??ve,t=n.prefix??be;function o(g){return `${t}${g}`}function r(g){return Date.now()>g.expiresAt}function i(g){let c=o(g);if(a)try{let m=localStorage.getItem(c);if(!m)return null;let y=JSON.parse(m);return r(y)?(localStorage.removeItem(c),null):y.value}catch{return null}let d=v.get(c);return d?r(d)?(v.delete(c),null):d.value:null}function s(g,c,d=e){let m=o(g),y={value:c,expiresAt:Date.now()+d};if(a){try{localStorage.setItem(m,JSON.stringify(y));}catch{}return}v.set(m,y);}function l(g){let c=o(g);if(a){try{localStorage.removeItem(c);}catch{}return}v.delete(c);}function f(g){if(a){try{let c=[];for(let d=0;d<localStorage.length;d++){let m=localStorage.key(d);m&&m.startsWith(t)&&(!g||m.includes(g))&&c.push(m);}c.forEach(d=>localStorage.removeItem(d));}catch{}return}if(g)for(let c of v.keys())c.startsWith(t)&&c.includes(g)&&v.delete(c);else for(let c of v.keys())c.startsWith(t)&&v.delete(c);}async function h(g,c,d=e){let m=i(g);if(m!==null)return m;let y=await c();return s(g,y,d),y}return {get:i,set:s,remove:l,invalidate:f,getOrSet:h}}function re(n){let e=n.prefix||"[Lynkow]";return {debug(...t){n.debug&&console.debug(e,...t);},info(...t){console.info(e,...t);},warn(...t){console.warn(e,...t);},error(...t){console.error(e,...t);},log(t,...o){switch(t){case "debug":this.debug(...o);break;case "info":this.info(...o);break;case "warn":this.warn(...o);break;case "error":this.error(...o);break}}}}function se(){let n=new Map;function e(s,l){return n.has(s)||n.set(s,new Set),n.get(s).add(l),()=>t(s,l)}function t(s,l){let f=n.get(s);f&&f.delete(l);}function o(s,l){let f=n.get(s);if(f)for(let h of f)try{h(l);}catch(g){console.error(`[Lynkow] Error in event listener for "${s}":`,g);}}function r(s,l){let f=(h=>{t(s,f),l(h);});return e(s,f)}function i(s){s?n.delete(s):n.clear();}return {on:e,off:t,emit:o,once:r,removeAllListeners:i}}var ie="lynkow_locale";function ae(n,e){if(!a)return e;let t=Re();if(t&&n.includes(t))return t;let o=ke(n);if(o)return o;let r=document.documentElement.lang;if(r){let i=r.split("-")[0]?.toLowerCase();if(i&&n.includes(i))return i}return e}function Re(){if(!a)return null;try{return localStorage.getItem(ie)}catch{return null}}function ce(n){if(a)try{localStorage.setItem(ie,n);}catch{}}function ke(n){if(!a)return null;let t=window.location.pathname.split("/").filter(Boolean);if(t.length>0){let o=t[0]?.toLowerCase();if(o&&n.includes(o))return o}return null}function le(n,e){return e.includes(n)}var pe="https://api.lynkow.com";function xe(n){if(!n.siteId)throw new Error("Lynkow SDK: siteId is required");let e=ne(),t=re({debug:n.debug??false}),o=se(),r=(n.baseUrl||pe).replace(/\/$/,""),i={siteId:n.siteId,baseUrl:r,locale:n.locale,fetchOptions:n.fetchOptions||{},cache:e},s={locale:n.locale||"fr",availableLocales:["fr"],siteConfig:null,initialized:false},l={contents:new R(i),categories:new k(i),tags:new x(i),pages:new L(i),blocks:new T(i),forms:new S(i),reviews:new P(i),site:new
|
|
288
|
+
`,F=class{initialized=false;observer=null;injectStyles(){if(!a||document.getElementById(Y))return;let e=document.createElement("style");e.id=Y,e.textContent=we,document.head.appendChild(e);}async handleCopyClick(e){let t=e.closest(".code-block");if(!t)return;let o=t.querySelector("code");if(!o)return;let r=o.textContent||"";try{await navigator.clipboard.writeText(r),e.classList.add("copied"),e.innerHTML=Ce,setTimeout(()=>{e.classList.remove("copied"),e.innerHTML=ye;},2e3);}catch(i){console.error("Lynkow SDK: Failed to copy code",i);}}bindCodeBlockCopy(){if(!a)return;document.querySelectorAll("[data-copy-code]").forEach(t=>{t.dataset.lynkowBound||(t.dataset.lynkowBound="true",t.addEventListener("click",o=>{o.preventDefault(),this.handleCopyClick(t);}));});}init(){a&&(this.injectStyles(),this.bindCodeBlockCopy(),this.observer||(this.observer=new MutationObserver(e=>{let t=false;for(let o of e)if(o.addedNodes.length>0){t=true;break}t&&this.bindCodeBlockCopy();}),this.observer.observe(document.body,{childList:true,subtree:true})),this.initialized=true);}isInitialized(){return this.initialized}destroy(){a&&(this.observer&&(this.observer.disconnect(),this.observer=null),document.getElementById(Y)?.remove(),this.initialized=false);}};var ve=300*1e3,be="lynkow_cache_",v=new Map;function ne(n={}){let e=n.defaultTtl??ve,t=n.prefix??be;function o(g){return `${t}${g}`}function r(g){return Date.now()>g.expiresAt}function i(g){let c=o(g);if(a)try{let m=localStorage.getItem(c);if(!m)return null;let y=JSON.parse(m);return r(y)?(localStorage.removeItem(c),null):y.value}catch{return null}let d=v.get(c);return d?r(d)?(v.delete(c),null):d.value:null}function s(g,c,d=e){let m=o(g),y={value:c,expiresAt:Date.now()+d};if(a){try{localStorage.setItem(m,JSON.stringify(y));}catch{}return}v.set(m,y);}function l(g){let c=o(g);if(a){try{localStorage.removeItem(c);}catch{}return}v.delete(c);}function f(g){if(a){try{let c=[];for(let d=0;d<localStorage.length;d++){let m=localStorage.key(d);m&&m.startsWith(t)&&(!g||m.includes(g))&&c.push(m);}c.forEach(d=>localStorage.removeItem(d));}catch{}return}if(g)for(let c of v.keys())c.startsWith(t)&&c.includes(g)&&v.delete(c);else for(let c of v.keys())c.startsWith(t)&&v.delete(c);}async function h(g,c,d=e){let m=i(g);if(m!==null)return m;let y=await c();return s(g,y,d),y}return {get:i,set:s,remove:l,invalidate:f,getOrSet:h}}function re(n){let e=n.prefix||"[Lynkow]";return {debug(...t){n.debug&&console.debug(e,...t);},info(...t){console.info(e,...t);},warn(...t){console.warn(e,...t);},error(...t){console.error(e,...t);},log(t,...o){switch(t){case "debug":this.debug(...o);break;case "info":this.info(...o);break;case "warn":this.warn(...o);break;case "error":this.error(...o);break}}}}function se(){let n=new Map;function e(s,l){return n.has(s)||n.set(s,new Set),n.get(s).add(l),()=>t(s,l)}function t(s,l){let f=n.get(s);f&&f.delete(l);}function o(s,l){let f=n.get(s);if(f)for(let h of f)try{h(l);}catch(g){console.error(`[Lynkow] Error in event listener for "${s}":`,g);}}function r(s,l){let f=(h=>{t(s,f),l(h);});return e(s,f)}function i(s){s?n.delete(s):n.clear();}return {on:e,off:t,emit:o,once:r,removeAllListeners:i}}var ie="lynkow_locale";function ae(n,e){if(!a)return e;let t=Re();if(t&&n.includes(t))return t;let o=ke(n);if(o)return o;let r=document.documentElement.lang;if(r){let i=r.split("-")[0]?.toLowerCase();if(i&&n.includes(i))return i}return e}function Re(){if(!a)return null;try{return localStorage.getItem(ie)}catch{return null}}function ce(n){if(a)try{localStorage.setItem(ie,n);}catch{}}function ke(n){if(!a)return null;let t=window.location.pathname.split("/").filter(Boolean);if(t.length>0){let o=t[0]?.toLowerCase();if(o&&n.includes(o))return o}return null}function le(n,e){return e.includes(n)}var pe="https://api.lynkow.com";function xe(n){if(!n.siteId)throw new Error("Lynkow SDK: siteId is required");let e=ne(),t=re({debug:n.debug??false}),o=se(),r=(n.baseUrl||pe).replace(/\/$/,""),i={siteId:n.siteId,baseUrl:r,locale:n.locale,fetchOptions:n.fetchOptions||{},cache:e},s={locale:n.locale||"fr",availableLocales:["fr"],siteConfig:null,initialized:false},l={contents:new R(i),categories:new k(i),tags:new x(i),pages:new L(i),blocks:new T(i),forms:new S(i),reviews:new P(i),site:new I(i),legal:new B(i),cookies:new $(i),seo:new A(i),paths:new _(i),analytics:new U(i),consent:new H(i,o),branding:new q,enhancements:new F};function f(c){i.locale=c;}async function h(){if(!s.initialized)try{let c=await l.site.getConfig();s.siteConfig=c;let d=c.defaultLocale||"fr";if(s.availableLocales=c.enabledLocales||[d],a&&!n.locale){let m=ae(s.availableLocales,d);s.locale=m,f(m);}s.initialized=!0,t.debug("Client initialized",{locale:s.locale,availableLocales:s.availableLocales}),a&&(l.analytics.init(),l.consent.hasConsented()||l.consent.show(),c.showBranding&&l.branding.inject(),l.enhancements.init()),o.emit("ready",void 0);}catch(c){t.error("Failed to initialize client",c),o.emit("error",c);}}return a&&setTimeout(()=>h(),0),{...l,globals:l.blocks,config:Object.freeze({siteId:n.siteId,baseUrl:r,debug:n.debug??false}),get locale(){return s.locale},get availableLocales(){return [...s.availableLocales]},setLocale(c){if(!le(c,s.availableLocales)){t.warn(`Locale "${c}" is not available. Available: ${s.availableLocales.join(", ")}`);return}c!==s.locale&&(s.locale=c,f(c),a&&ce(c),e.invalidate(),o.emit("locale-changed",c),t.debug("Locale changed to",c));},clearCache(){e.invalidate(),t.debug("Cache cleared");},destroy(){l.analytics.destroy(),l.consent.destroy(),l.branding.destroy(),l.enhancements.destroy(),e.invalidate(),o.removeAllListeners(),t.debug("Client destroyed");},on(c,d){return o.on(c,d)}}}function Ee(n){if(!n.siteId)throw new Error("Lynkow SDK: siteId is required");let e={siteId:n.siteId,baseUrl:(n.baseUrl||pe).replace(/\/$/,""),locale:n.locale,fetchOptions:n.fetchOptions||{}};return {contents:new R(e),categories:new k(e),tags:new x(e),pages:new L(e),blocks:new T(e),forms:new S(e),reviews:new P(e),site:new I(e),legal:new B(e),cookies:new $(e),seo:new A(e),paths:new _(e)}}function Le(n){return n.type==="content"}function Te(n){return n.type==="category"}
|
|
289
289
|
exports.EnhancementsService=F;exports.LynkowError=C;exports.browserOnly=me;exports.browserOnlyAsync=fe;exports.createClient=xe;exports.createLynkowClient=Ee;exports.isBrowser=a;exports.isCategoryResolve=Te;exports.isContentResolve=Le;exports.isLynkowError=de;exports.isServer=ue;//# sourceMappingURL=index.js.map
|
|
290
290
|
//# sourceMappingURL=index.js.map
|