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/dist/index.mjs CHANGED
@@ -1,3 +1,163 @@
1
- var a=class extends Error{status;code;errors;constructor(e,t,s,r=[]){super(s),this.name="LynkowError",this.status=e,this.code=t,this.errors=r;}};function v(o){switch(o){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 L(o,e){let t;try{t=await fetch(o,e);}catch(p){throw new a(0,"NETWORK_ERROR","Network error: Unable to reach the server",[{message:p instanceof Error?p.message:"Unknown error"}])}if(t.ok)return t.json();let s={};try{s=await t.json();}catch{}let r=v(t.status),i=s.error||s.message||`HTTP error: ${t.status}`,O=s.errors||[{message:i}];throw new a(t.status,r,i,O)}function P(o){let e=new URLSearchParams;for(let[t,s]of Object.entries(o))s!=null&&s!==""&&e.append(t,String(s));return e.toString()}var n=class{config;constructor(e){this.config=e;}buildEndpointUrl(e,t){let s=`${this.config.baseUrl}/public/${this.config.siteId}${e}`;if(t&&Object.keys(t).length>0){let r=P(t);return `${s}?${r}`}return s}async get(e,t,s){let r=s?.locale||this.config.locale,i=r?{...t,locale:r}:t,O=this.buildEndpointUrl(e,i),p=this.mergeFetchOptions(s?.fetchOptions);return L(O,{method:"GET",...p})}async post(e,t,s){let r=this.buildEndpointUrl(e),i=this.mergeFetchOptions(s?.fetchOptions);return L(r,{method:"POST",...i,headers:{"Content-Type":"application/json",...i.headers},body:JSON.stringify(t)})}async getText(e,t){let s=this.buildEndpointUrl(e),r=this.mergeFetchOptions(t?.fetchOptions),i=await fetch(s,{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 g=class extends n{async list(e,t){let s={};return e?.page&&(s.page=e.page),e?.perPage&&(s.perPage=e.perPage),e?.category&&(s.category=e.category),e?.tag&&(s.tag=e.tag),e?.search&&(s.search=e.search),e?.sort&&(s.sort=e.sort),e?.order&&(s.order=e.order),e?.locale&&(s.locale=e.locale),this.get("/contents",s,t)}async getBySlug(e,t){return this.get(`/contents/slug/${encodeURIComponent(e)}`,void 0,t)}};var m=class extends n{async list(e){return this.get("/categories",void 0,e)}async tree(e){return this.get("/categories/tree",void 0,e)}async getBySlug(e,t){let s={};return t?.page&&(s.page=t.page),t?.perPage&&(s.limit=t.perPage),this.get(`/categories/${encodeURIComponent(e)}`,s,t)}};var c=class extends n{async list(e){return this.get("/tags",void 0,e)}};var R=class extends n{async list(e){return this.get("/pages",void 0,e)}async getBySlug(e,t){return (await this.get(`/pages/${encodeURIComponent(e)}`,void 0,t)).data}async getByPath(e,t){return (await this.get("/page-by-path",{path:e},t)).data}async getJsonLd(e,t){return (await this.get(`/pages/${encodeURIComponent(e)}/json-ld`,void 0,t)).data}};var u=class extends n{async siteConfig(e){return this.get("/site-config",void 0,e)}async global(e,t){return this.get(`/global/${encodeURIComponent(e)}`,void 0,t)}};function l(o){return {_hp:"",_ts:o}}var y=class extends n{sessionStartTime;constructor(e){super(e),this.sessionStartTime=Date.now();}async getBySlug(e){return (await this.get(`/forms/${encodeURIComponent(e)}`)).data}async submit(e,t,s){let r=l(this.sessionStartTime),i={...t,...r};return s?.recaptchaToken&&(i._recaptcha_token=s.recaptchaToken),this.post(`/forms/${encodeURIComponent(e)}/submit`,i,s)}};var d=class extends n{sessionStartTime;constructor(e){super(e),this.sessionStartTime=Date.now();}async list(e,t){let s={};return e?.page&&(s.page=e.page),e?.perPage&&(s.perPage=e.perPage),e?.minRating&&(s.minRating=e.minRating),e?.maxRating&&(s.maxRating=e.maxRating),e?.sort&&(s.sort=e.sort),e?.order&&(s.order=e.order),this.get("/reviews",s,t)}async getBySlug(e){return (await this.get(`/reviews/${encodeURIComponent(e)}`)).data}async settings(){return this.get("/reviews/settings")}async submit(e,t){let s=l(this.sessionStartTime),r={...e,...s};return t?.recaptchaToken&&(r._recaptcha_token=t.recaptchaToken),this.post("/reviews",r,t)}};var f=class extends n{async getConfig(){return (await this.get("/site")).data}};var C=class extends n{async list(e){return this.get("/legal",void 0,e)}async getByType(e,t){return (await this.get(`/legal/${e}`,void 0,t)).data}};var h=class extends n{async getConfig(){return (await this.get("/cookie-consent/config")).data}async logConsent(e,t){return this.post("/cookie-consent/log",{preferences:e},t)}};var w=class extends n{async sitemap(e){return this.getText("/sitemap.xml",e)}async robots(e){return this.getText("/robots.txt",e)}};var S=class extends n{async list(e){return this.get("/paths",void 0,e)}async resolve(e,t){return this.get("/resolve",{path:e},t)}async matchRedirect(e,t){try{return (await this.get("/redirects/match",{path:e},t)).data}catch(s){if(s instanceof a&&s.status===404)return null;throw s}}};var B="https://api.lynkow.com";function k(o){if(!o.siteId)throw new Error("Lynkow SDK: siteId is required");let e={siteId:o.siteId,baseUrl:(o.baseUrl||B).replace(/\/$/,""),locale:o.locale,fetchOptions:o.fetchOptions||{}};return {contents:new g(e),categories:new m(e),tags:new c(e),pages:new R(e),blocks:new u(e),forms:new y(e),reviews:new d(e),site:new f(e),legal:new C(e),cookies:new h(e),seo:new w(e),paths:new S(e)}}function b(o){return o.type==="content"}function x(o){return o.type==="category"}function T(o){return o instanceof a}
2
- export{a as LynkowError,k as createLynkowClient,x as isCategoryResolve,b as isContentResolve,T as isLynkowError};//# sourceMappingURL=index.mjs.map
1
+ var y=class o extends Error{name="LynkowError";code;status;details;cause;constructor(e,t,n,r,s){super(e),this.code=t,this.status=n,this.details=r,this.cause=s,Error.captureStackTrace&&Error.captureStackTrace(this,o);}static async fromResponse(e){let t=e.status,n=`HTTP ${t}`,r;try{let i=await e.json();i.errors&&Array.isArray(i.errors)?(r=i.errors,n=i.errors[0]?.message||n):i.error?n=i.error:i.message&&(n=i.message);}catch{n=e.statusText||n;}let s=o.statusToCode(t);return new o(n,s,t,r)}static fromNetworkError(e){return e.name==="AbortError"?new o("Request timed out","TIMEOUT",void 0,void 0,e):e.name==="TypeError"?new o("Network error - please check your connection","NETWORK_ERROR",void 0,void 0,e):new o(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 ce(o){return o instanceof y}function le(o){switch(o){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 H(o,e){let t;try{t=await fetch(o,e);}catch(p){throw new y("Network error: Unable to reach the server","NETWORK_ERROR",0,[{message:p instanceof Error?p.message:"Unknown error"}])}if(t.ok)return t.json();let n={};try{n=await t.json();}catch{}let r=le(t.status),s=n.error||n.message||`HTTP error: ${t.status}`,i=n.errors||[{message:s}];throw new y(s,r,t.status,i)}function X(o){let e=new URLSearchParams;for(let[t,n]of Object.entries(o))n!=null&&n!==""&&e.append(t,String(n));return e.toString()}var l={SHORT:300*1e3,MEDIUM:600*1e3},g=class{config;cache;constructor(e){this.config=e,this.cache=e.cache;}buildEndpointUrl(e,t){let n=`${this.config.baseUrl}/public/${this.config.siteId}${e}`;if(t&&Object.keys(t).length>0){let r=X(t);return `${n}?${r}`}return n}async get(e,t,n){let r=n?.locale||this.config.locale,s=r?{...t,locale:r}:t,i=this.buildEndpointUrl(e,s),p=this.mergeFetchOptions(n?.fetchOptions);return H(i,{method:"GET",...p})}async getWithCache(e,t,n,r,s=l.SHORT){return this.cache?this.cache.getOrSet(e,()=>this.get(t,n,r),s):this.get(t,n,r)}invalidateCache(e){this.cache?.invalidate(e);}async post(e,t,n){let r=this.buildEndpointUrl(e),s=this.mergeFetchOptions(n?.fetchOptions);return H(r,{method:"POST",...s,headers:{"Content-Type":"application/json",...s.headers},body:JSON.stringify(t)})}async getText(e,t){let n=this.buildEndpointUrl(e),r=this.mergeFetchOptions(t?.fetchOptions),s=await fetch(n,{method:"GET",...r});if(!s.ok)throw new Error(`HTTP error: ${s.status}`);return s.text()}mergeFetchOptions(e){return {...this.config.fetchOptions,...e,headers:{...this.config.fetchOptions.headers,...e?.headers}}}};var K="contents_",R=class extends g{async list(e,t){let n={};e?.page&&(n.page=e.page),e?.perPage&&(n.perPage=e.perPage),e?.category&&(n.category=e.category),e?.tag&&(n.tag=e.tag),e?.search&&(n.search=e.search),e?.sort&&(n.sort=e.sort),e?.order&&(n.order=e.order),e?.locale&&(n.locale=e.locale);let r=`${K}list_${JSON.stringify(e||{})}`;return this.getWithCache(r,"/contents",n,t,l.SHORT)}async getBySlug(e,t){let n=t?.locale||this.config.locale,r=`${K}slug_${e}_${n||"default"}`;return this.getWithCache(r,`/contents/slug/${encodeURIComponent(e)}`,void 0,t,l.SHORT)}clearCache(){this.invalidateCache(K);}};var _="categories_",E=class extends g{async list(e){let t=e?.locale||this.config.locale,n=`${_}list_${t||"default"}`;return this.getWithCache(n,"/categories",void 0,e,l.SHORT)}async tree(e){let t=e?.locale||this.config.locale,n=`${_}tree_${t||"default"}`;return this.getWithCache(n,"/categories/tree",void 0,e,l.SHORT)}async getBySlug(e,t){let n={};t?.page&&(n.page=t.page),t?.perPage&&(n.limit=t.perPage);let r=`${_}slug_${e}_${JSON.stringify(t||{})}`;return this.getWithCache(r,`/categories/${encodeURIComponent(e)}`,n,t,l.SHORT)}clearCache(){this.invalidateCache(_);}};var J="tags_",b=class extends g{async list(e){let t=e?.locale||this.config.locale,n=`${J}list_${t||"default"}`;return this.getWithCache(n,"/tags",void 0,e,l.SHORT)}clearCache(){this.invalidateCache(J);}};var k="pages_",x=class extends g{async list(e){let t=e?.locale||this.config.locale,n={};e?.tag&&(n.tag=e.tag);let r=`${k}list_${t||"default"}_${e?.tag||"all"}`;return this.getWithCache(r,"/pages",n,e,l.SHORT)}async getBySlug(e,t){let n=t?.locale||this.config.locale,r=`${k}slug_${e}_${n||"default"}`;return (await this.getWithCache(r,`/pages/${encodeURIComponent(e)}`,void 0,t,l.SHORT)).data}async getByPath(e,t){let n=t?.locale||this.config.locale,r=`${k}path_${e}_${n||"default"}`;return (await this.getWithCache(r,"/page-by-path",{path:e},t,l.SHORT)).data}async getJsonLd(e,t){let n=t?.locale||this.config.locale,r=`${k}jsonld_${e}_${n||"default"}`;return (await this.getWithCache(r,`/pages/${encodeURIComponent(e)}/json-ld`,void 0,t,l.SHORT)).data}clearCache(){this.invalidateCache(k);}};var q="globals_",L=class extends g{async siteConfig(e){let t=e?.locale||this.config.locale,n=`${q}siteconfig_${t||"default"}`;return this.getWithCache(n,"/site-config",void 0,e,l.MEDIUM)}async getBySlug(e,t){let n=t?.locale||this.config.locale,r=`${q}${e}_${n||"default"}`;return this.getWithCache(r,`/global/${encodeURIComponent(e)}`,void 0,t,l.MEDIUM)}async global(e,t){return this.getBySlug(e,t)}clearCache(){this.invalidateCache(q);}};function F(o){return {_hp:"",_ts:o}}var Q="forms_",T=class extends g{sessionStartTime;constructor(e){super(e),this.sessionStartTime=Date.now();}async getBySlug(e){let t=`${Q}${e}`;return (await this.getWithCache(t,`/forms/${encodeURIComponent(e)}`,void 0,void 0,l.MEDIUM)).data}async submit(e,t,n){let r=F(this.sessionStartTime),s={...t,...r};return n?.recaptchaToken&&(s._recaptcha_token=n.recaptchaToken),this.post(`/forms/${encodeURIComponent(e)}/submit`,s,n)}clearCache(){this.invalidateCache(Q);}};var S="reviews_",O=class extends g{sessionStartTime;constructor(e){super(e),this.sessionStartTime=Date.now();}async list(e,t){let n={};e?.page&&(n.page=e.page),e?.perPage&&(n.perPage=e.perPage),e?.minRating&&(n.minRating=e.minRating),e?.maxRating&&(n.maxRating=e.maxRating),e?.sort&&(n.sort=e.sort),e?.order&&(n.order=e.order);let r=`${S}list_${JSON.stringify(e||{})}`;return this.getWithCache(r,"/reviews",n,t,l.SHORT)}async getBySlug(e){let t=`${S}slug_${e}`;return (await this.getWithCache(t,`/reviews/${encodeURIComponent(e)}`,void 0,void 0,l.SHORT)).data}async settings(){let e=`${S}settings`;return this.getWithCache(e,"/reviews/settings",void 0,void 0,l.MEDIUM)}async submit(e,t){let n=F(this.sessionStartTime),r={...e,...n};t?.recaptchaToken&&(r._recaptcha_token=t.recaptchaToken);let s=await this.post("/reviews",r,t);return this.invalidateCache(S),s}clearCache(){this.invalidateCache(S);}};var Y="site_",P=class extends g{async getConfig(){let e=`${Y}config`;return (await this.getWithCache(e,"/site",void 0,void 0,l.MEDIUM)).data}clearCache(){this.invalidateCache(Y);}};var M="legal_",I=class extends g{async list(e){let t=e?.locale||this.config.locale,n=`${M}list_${t||"default"}`;return (await this.getWithCache(n,"/pages",{tag:"legal"},e,l.SHORT)).data}async getBySlug(e,t){let n=t?.locale||this.config.locale,r=`${M}slug_${e}_${n||"default"}`;return (await this.getWithCache(r,`/pages/${encodeURIComponent(e)}`,void 0,t,l.SHORT)).data}clearCache(){this.invalidateCache(M);}};var Z="cookies_",B=class extends g{async getConfig(){let e=`${Z}config`;return (await this.getWithCache(e,"/cookie-consent/config",void 0,void 0,l.MEDIUM)).data}async logConsent(e,t){return this.post("/cookie-consent/log",{preferences:e},t)}clearCache(){this.invalidateCache(Z);}};var A=class extends g{async sitemap(e){return this.getText("/sitemap.xml",e)}async robots(e){return this.getText("/robots.txt",e)}};var W="paths_",$=class extends g{async list(e){let t=e?.locale||this.config.locale,n=`${W}list_${t||"all"}`;return this.getWithCache(n,"/paths",void 0,e,l.SHORT)}async resolve(e,t){let n=t?.locale||this.config.locale,r=`${W}resolve_${e}_${n||"default"}`;return this.getWithCache(r,"/resolve",{path:e},t,l.SHORT)}async matchRedirect(e,t){try{return (await this.get("/redirects/match",{path:e},t)).data}catch(n){if(n instanceof y&&n.status===404)return null;throw n}}clearCache(){this.invalidateCache(W);}};var a=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",pe=!a;function de(o,e){return a?o():e}async function ge(o,e){return a?o():e}var z="lynkow-tracker",D=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(z)){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 n=document.createElement("script");n.id=z,n.src=this.getTrackerUrl(),n.async=true,n.setAttribute("data-site-id",this.config.siteId),this.config.baseUrl&&n.setAttribute("data-api-url",this.config.baseUrl),n.onload=()=>{this.loading=false,setTimeout(()=>{window.LynkowAnalytics?e():t(new Error("Tracker script loaded but LynkowAnalytics not found"));},0);},n.onerror=()=>{this.loading=false,t(new Error("Failed to load tracker script"));},document.head.appendChild(n);}),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(z)?.remove(),this.initialized=false,this.loadPromise=null;}};var j="_lkw_consent",G={necessary:true,analytics:false,marketing:false,preferences:false},N=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 n=await t.json();return this.configCache=n.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(),n=document.createElement("div");n.innerHTML=this.createPreferencesHTML(e,t),this.preferencesElement=n.firstElementChild,document.body.appendChild(this.preferencesElement),this.attachPreferencesEvents(e);}));}getCategories(){return a?this.getStoredConsent()||{...G}:{...G}}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 n={...this.getCategories(),...e,necessary:true};this.saveConsent(n),this.logConsent(n);}reset(){if(a){try{localStorage.removeItem(j);}catch{}this.events.emit("consent-changed",{...G}),this.show();}}createBannerHTML(e){let t=e.position||"bottom",n=e.theme||"light",r={bottom:"bottom: 0; left: 0; right: 0;",top:"top: 0; left: 0; right: 0;","bottom-left":"bottom: 20px; left: 20px; max-width: 400px;","bottom-right":"bottom: 20px; right: 20px; max-width: 400px;"},s=n==="dark",i=s?"#1a1a1a":"#ffffff",p=s?"#ffffff":"#1a1a1a",u=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
+ <div id="lynkow-consent-banner" style="
3
+ position: fixed;
4
+ ${r[t]}
5
+ z-index: 99999;
6
+ padding: 20px;
7
+ background: ${i};
8
+ color: ${p};
9
+ box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
10
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
11
+ font-size: 14px;
12
+ ">
13
+ <div style="max-width: 1200px; margin: 0 auto;">
14
+ <h3 style="margin: 0 0 10px 0; font-size: 16px;">${u.title}</h3>
15
+ <p style="margin: 0 0 15px 0; line-height: 1.5;">
16
+ ${u.description}
17
+ </p>
18
+ <div style="display: flex; gap: 10px; flex-wrap: wrap;">
19
+ <button id="lynkow-consent-accept" style="
20
+ padding: 10px 20px;
21
+ background: #0066cc;
22
+ color: white;
23
+ border: none;
24
+ border-radius: 4px;
25
+ cursor: pointer;
26
+ font-size: 14px;
27
+ ">${u.acceptAll}</button>
28
+ <button id="lynkow-consent-reject" style="
29
+ padding: 10px 20px;
30
+ background: transparent;
31
+ color: inherit;
32
+ border: 1px solid currentColor;
33
+ border-radius: 4px;
34
+ cursor: pointer;
35
+ font-size: 14px;
36
+ ">${u.rejectAll}</button>
37
+ <button id="lynkow-consent-preferences" style="
38
+ padding: 10px 20px;
39
+ background: transparent;
40
+ color: inherit;
41
+ border: none;
42
+ cursor: pointer;
43
+ font-size: 14px;
44
+ text-decoration: underline;
45
+ ">${u.customize}</button>
46
+ </div>
47
+ </div>
48
+ </div>
49
+ `}createPreferencesHTML(e,t){let r=(e.theme||"light")==="dark",s=r?"#1a1a1a":"#ffffff",i=r?"#ffffff":"#1a1a1a",p=e.texts||{title:"Preferences de cookies",save:"Enregistrer"},h=(e.categories||[]).map(d=>`
50
+ <label style="display: flex; align-items: flex-start; gap: 10px; margin: 15px 0; cursor: ${d.required?"not-allowed":"pointer"};">
51
+ <input
52
+ type="checkbox"
53
+ name="${d.id}"
54
+ ${t[d.id]?"checked":""}
55
+ ${d.required?"disabled checked":""}
56
+ style="width: 18px; height: 18px; margin-top: 2px;"
57
+ />
58
+ <div style="flex: 1;">
59
+ <strong style="opacity: ${d.required?"0.6":"1"};">
60
+ ${d.name}${d.required?" (requis)":""}
61
+ </strong>
62
+ <p style="margin: 5px 0 0 0; font-size: 13px; opacity: 0.8;">
63
+ ${d.description}
64
+ </p>
65
+ </div>
66
+ </label>
67
+ `).join("");return `
68
+ <div id="lynkow-consent-preferences-modal" style="
69
+ position: fixed;
70
+ top: 0;
71
+ left: 0;
72
+ right: 0;
73
+ bottom: 0;
74
+ z-index: 100000;
75
+ background: rgba(0,0,0,0.5);
76
+ display: flex;
77
+ align-items: center;
78
+ justify-content: center;
79
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
80
+ ">
81
+ <div style="
82
+ background: ${s};
83
+ color: ${i};
84
+ padding: 30px;
85
+ border-radius: 8px;
86
+ max-width: 500px;
87
+ width: 90%;
88
+ max-height: 80vh;
89
+ overflow-y: auto;
90
+ ">
91
+ <h2 style="margin: 0 0 20px 0; font-size: 20px;">${p.title||"Preferences de cookies"}</h2>
92
+
93
+ <form id="lynkow-consent-form">
94
+ ${h}
95
+
96
+ <div style="display: flex; gap: 10px; margin-top: 25px; padding-top: 20px; border-top: 1px solid rgba(128,128,128,0.3);">
97
+ <button type="submit" style="
98
+ padding: 10px 20px;
99
+ background: #0066cc;
100
+ color: white;
101
+ border: none;
102
+ border-radius: 4px;
103
+ cursor: pointer;
104
+ font-size: 14px;
105
+ ">${p.save||"Enregistrer"}</button>
106
+ <button type="button" id="lynkow-consent-close" style="
107
+ padding: 10px 20px;
108
+ background: transparent;
109
+ color: inherit;
110
+ border: 1px solid currentColor;
111
+ border-radius: 4px;
112
+ cursor: pointer;
113
+ font-size: 14px;
114
+ ">Annuler</button>
115
+ </div>
116
+ </form>
117
+ </div>
118
+ </div>
119
+ `}attachBannerEvents(){let e=document.getElementById("lynkow-consent-accept"),t=document.getElementById("lynkow-consent-reject"),n=document.getElementById("lynkow-consent-preferences");e?.addEventListener("click",()=>{this.acceptAll();}),t?.addEventListener("click",()=>{this.rejectAll();}),n?.addEventListener("click",()=>{this.showPreferences();});}attachPreferencesEvents(e){let t=document.getElementById("lynkow-consent-form"),n=document.getElementById("lynkow-consent-close"),r=document.getElementById("lynkow-consent-preferences-modal");t?.addEventListener("submit",s=>{s.preventDefault();let i=new FormData(t),p={necessary:true,analytics:i.has("analytics"),marketing:i.has("marketing"),preferences:i.has("preferences")};this.setCategories(p),this.hide(),this.preferencesElement?.remove(),this.preferencesElement=null;}),n?.addEventListener("click",()=>{this.preferencesElement?.remove(),this.preferencesElement=null;}),r?.addEventListener("click",s=>{s.target===r&&(this.preferencesElement?.remove(),this.preferencesElement=null);});}destroy(){this.hide(),this.preferencesElement?.remove(),this.preferencesElement=null;}};var v="lynkow-badge",V="lynkow-badge-styles",ue=`
120
+ #${v} {
121
+ position: fixed;
122
+ bottom: 16px;
123
+ right: 16px;
124
+ background: #1a1a1a;
125
+ color: #888;
126
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
127
+ font-size: 11px;
128
+ padding: 6px 10px;
129
+ border-radius: 4px;
130
+ text-decoration: none;
131
+ opacity: 0.7;
132
+ transition: opacity 0.2s, color 0.2s;
133
+ z-index: 9999;
134
+ line-height: 1;
135
+ }
136
+
137
+ #${v}:hover {
138
+ opacity: 1;
139
+ color: #fff;
140
+ }
141
+
142
+ @media (max-width: 480px) {
143
+ #${v} {
144
+ bottom: 10px;
145
+ right: 10px;
146
+ font-size: 10px;
147
+ padding: 5px 8px;
148
+ }
149
+ }
150
+
151
+ @media (prefers-color-scheme: light) {
152
+ #${v} {
153
+ background: #f5f5f5;
154
+ color: #666;
155
+ }
156
+
157
+ #${v}:hover {
158
+ color: #1a1a1a;
159
+ }
160
+ }
161
+ `,U=class{badgeElement=null;injectStyles(){if(document.getElementById(V))return;let e=document.createElement("style");e.id=V,e.textContent=ue,document.head.appendChild(e);}inject(){if(!a||document.getElementById(v))return;this.injectStyles();let e=document.createElement("a");e.id=v,e.href="https://lynkow.com?ref=badge",e.target="_blank",e.rel="noopener noreferrer",e.textContent="Powered by Lynkow",e.setAttribute("aria-label","Powered by Lynkow - Visit lynkow.com"),document.body.appendChild(e),this.badgeElement=e;}remove(){a&&(this.badgeElement?.remove(),this.badgeElement=null,document.getElementById(V)?.remove());}isVisible(){return a?document.getElementById(v)!==null:false}destroy(){this.remove();}};var fe=300*1e3,me="lynkow_cache_",w=new Map;function ee(o={}){let e=o.defaultTtl??fe,t=o.prefix??me;function n(d){return `${t}${d}`}function r(d){return Date.now()>d.expiresAt}function s(d){let c=n(d);if(a)try{let m=localStorage.getItem(c);if(!m)return null;let C=JSON.parse(m);return r(C)?(localStorage.removeItem(c),null):C.value}catch{return null}let f=w.get(c);return f?r(f)?(w.delete(c),null):f.value:null}function i(d,c,f=e){let m=n(d),C={value:c,expiresAt:Date.now()+f};if(a){try{localStorage.setItem(m,JSON.stringify(C));}catch{}return}w.set(m,C);}function p(d){let c=n(d);if(a){try{localStorage.removeItem(c);}catch{}return}w.delete(c);}function u(d){if(a){try{let c=[];for(let f=0;f<localStorage.length;f++){let m=localStorage.key(f);m&&m.startsWith(t)&&(!d||m.includes(d))&&c.push(m);}c.forEach(f=>localStorage.removeItem(f));}catch{}return}if(d)for(let c of w.keys())c.startsWith(t)&&c.includes(d)&&w.delete(c);else for(let c of w.keys())c.startsWith(t)&&w.delete(c);}async function h(d,c,f=e){let m=s(d);if(m!==null)return m;let C=await c();return i(d,C,f),C}return {get:s,set:i,remove:p,invalidate:u,getOrSet:h}}function te(o){let e=o.prefix||"[Lynkow]";return {debug(...t){o.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,...n){switch(t){case "debug":this.debug(...n);break;case "info":this.info(...n);break;case "warn":this.warn(...n);break;case "error":this.error(...n);break}}}}function ne(){let o=new Map;function e(i,p){return o.has(i)||o.set(i,new Set),o.get(i).add(p),()=>t(i,p)}function t(i,p){let u=o.get(i);u&&u.delete(p);}function n(i,p){let u=o.get(i);if(u)for(let h of u)try{h(p);}catch(d){console.error(`[Lynkow] Error in event listener for "${i}":`,d);}}function r(i,p){let u=(h=>{t(i,u),p(h);});return e(i,u)}function s(i){i?o.delete(i):o.clear();}return {on:e,off:t,emit:n,once:r,removeAllListeners:s}}var oe="lynkow_locale";function re(o,e){if(!a)return e;let t=he();if(t&&o.includes(t))return t;let n=ye(o);if(n)return n;let r=document.documentElement.lang;if(r){let s=r.split("-")[0]?.toLowerCase();if(s&&o.includes(s))return s}return e}function he(){if(!a)return null;try{return localStorage.getItem(oe)}catch{return null}}function se(o){if(a)try{localStorage.setItem(oe,o);}catch{}}function ye(o){if(!a)return null;let t=window.location.pathname.split("/").filter(Boolean);if(t.length>0){let n=t[0]?.toLowerCase();if(n&&o.includes(n))return n}return null}function ie(o,e){return e.includes(o)}var ae="https://api.lynkow.com";function Ce(o){if(!o.siteId)throw new Error("Lynkow SDK: siteId is required");let e=ee(),t=te({debug:o.debug??false}),n=ne(),r=(o.baseUrl||ae).replace(/\/$/,""),s={siteId:o.siteId,baseUrl:r,locale:o.locale,fetchOptions:o.fetchOptions||{},cache:e},i={locale:o.locale||"fr",availableLocales:["fr"],siteConfig:null,initialized:false},p={contents:new R(s),categories:new E(s),tags:new b(s),pages:new x(s),blocks:new L(s),forms:new T(s),reviews:new O(s),site:new P(s),legal:new I(s),cookies:new B(s),seo:new A(s),paths:new $(s),analytics:new D(s),consent:new N(s,n),branding:new U};function u(c){s.locale=c;}async function h(){if(!i.initialized)try{let c=await p.site.getConfig();i.siteConfig=c;let f=c.defaultLocale||"fr";if(i.availableLocales=c.enabledLocales||[f],a&&!o.locale){let m=re(i.availableLocales,f);i.locale=m,u(m);}i.initialized=!0,t.debug("Client initialized",{locale:i.locale,availableLocales:i.availableLocales}),a&&(p.analytics.init(),p.consent.hasConsented()||p.consent.show(),c.showBranding&&p.branding.inject()),n.emit("ready",void 0);}catch(c){t.error("Failed to initialize client",c),n.emit("error",c);}}return a&&setTimeout(()=>h(),0),{...p,globals:p.blocks,config:Object.freeze({siteId:o.siteId,baseUrl:r,debug:o.debug??false}),get locale(){return i.locale},get availableLocales(){return [...i.availableLocales]},setLocale(c){if(!ie(c,i.availableLocales)){t.warn(`Locale "${c}" is not available. Available: ${i.availableLocales.join(", ")}`);return}c!==i.locale&&(i.locale=c,u(c),a&&se(c),e.invalidate(),n.emit("locale-changed",c),t.debug("Locale changed to",c));},clearCache(){e.invalidate(),t.debug("Cache cleared");},destroy(){p.analytics.destroy(),p.consent.destroy(),p.branding.destroy(),e.invalidate(),n.removeAllListeners(),t.debug("Client destroyed");},on(c,f){return n.on(c,f)}}}function ve(o){if(!o.siteId)throw new Error("Lynkow SDK: siteId is required");let e={siteId:o.siteId,baseUrl:(o.baseUrl||ae).replace(/\/$/,""),locale:o.locale,fetchOptions:o.fetchOptions||{}};return {contents:new R(e),categories:new E(e),tags:new b(e),pages:new x(e),blocks:new L(e),forms:new T(e),reviews:new O(e),site:new P(e),legal:new I(e),cookies:new B(e),seo:new A(e),paths:new $(e)}}function we(o){return o.type==="content"}function Re(o){return o.type==="category"}
162
+ export{y as LynkowError,de as browserOnly,ge as browserOnlyAsync,Ce as createClient,ve as createLynkowClient,a as isBrowser,Re as isCategoryResolve,we as isContentResolve,ce as isLynkowError,pe as isServer};//# sourceMappingURL=index.mjs.map
3
163
  //# sourceMappingURL=index.mjs.map