lynkow 3.2.4 → 3.3.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 CHANGED
@@ -410,7 +410,7 @@ const unsubscribe = lynkow.on('consent-changed', (categories) => {
410
410
  console.log('Consent changed:', categories)
411
411
  })
412
412
 
413
- // Unsubscribe when done
413
+ // Unsubscribe when done
414
414
  unsubscribe()
415
415
  ```
416
416
 
package/dist/index.d.mts CHANGED
@@ -763,6 +763,83 @@ interface Tag {
763
763
  locale: string;
764
764
  }
765
765
 
766
+ /**
767
+ * FAQ item detected from content
768
+ */
769
+ interface FaqItem {
770
+ /** Unique ID (8-char MD5 hash of normalized question) */
771
+ id: string;
772
+ /** Question text */
773
+ question: string;
774
+ /** Answer as HTML */
775
+ answerHtml: string;
776
+ /** Answer as plain text */
777
+ answerText: string;
778
+ /** Source of the FAQ */
779
+ source: 'explicit' | 'heading';
780
+ /** Whether this FAQ is enabled for JSON-LD */
781
+ enabled: boolean;
782
+ }
783
+ /**
784
+ * JSON-LD FAQPage schema
785
+ */
786
+ interface JsonLdFaqPage {
787
+ '@context': 'https://schema.org';
788
+ '@type': 'FAQPage';
789
+ mainEntity: Array<{
790
+ '@type': 'Question';
791
+ name: string;
792
+ acceptedAnswer: {
793
+ '@type': 'Answer';
794
+ text: string;
795
+ };
796
+ }>;
797
+ }
798
+ /**
799
+ * JSON-LD Article schema
800
+ */
801
+ interface JsonLdArticle {
802
+ '@context': 'https://schema.org';
803
+ '@type': 'Article';
804
+ headline: string;
805
+ description?: string;
806
+ image?: string;
807
+ datePublished?: string;
808
+ dateModified?: string;
809
+ author?: {
810
+ '@type': 'Person';
811
+ name: string;
812
+ };
813
+ }
814
+ /**
815
+ * Alternate language version
816
+ */
817
+ interface StructuredDataAlternate {
818
+ /** Locale code */
819
+ locale: string;
820
+ /** URL to this version */
821
+ url: string;
822
+ }
823
+ /**
824
+ * Structured data generated for a content
825
+ */
826
+ interface StructuredData {
827
+ /** Format version */
828
+ version: number;
829
+ /** FAQ data */
830
+ faq: {
831
+ /** All detected FAQ items */
832
+ items: FaqItem[];
833
+ /** JSON-LD FAQPage schema (null if no enabled items) */
834
+ jsonLd: JsonLdFaqPage | null;
835
+ };
836
+ /** Article JSON-LD schema */
837
+ article: {
838
+ jsonLd: JsonLdArticle;
839
+ };
840
+ /** Alternate language versions */
841
+ alternates: StructuredDataAlternate[];
842
+ }
766
843
  /**
767
844
  * Content author
768
845
  */
@@ -850,7 +927,7 @@ interface Content extends ContentSummary {
850
927
  /** Open Graph image */
851
928
  ogImage: string | null;
852
929
  /** JSON-LD structured data */
853
- structuredData: Record<string, unknown> | null;
930
+ structuredData: StructuredData | null;
854
931
  /** Article author */
855
932
  author: Author | null;
856
933
  /** Associated categories */
package/dist/index.d.ts CHANGED
@@ -763,6 +763,83 @@ interface Tag {
763
763
  locale: string;
764
764
  }
765
765
 
766
+ /**
767
+ * FAQ item detected from content
768
+ */
769
+ interface FaqItem {
770
+ /** Unique ID (8-char MD5 hash of normalized question) */
771
+ id: string;
772
+ /** Question text */
773
+ question: string;
774
+ /** Answer as HTML */
775
+ answerHtml: string;
776
+ /** Answer as plain text */
777
+ answerText: string;
778
+ /** Source of the FAQ */
779
+ source: 'explicit' | 'heading';
780
+ /** Whether this FAQ is enabled for JSON-LD */
781
+ enabled: boolean;
782
+ }
783
+ /**
784
+ * JSON-LD FAQPage schema
785
+ */
786
+ interface JsonLdFaqPage {
787
+ '@context': 'https://schema.org';
788
+ '@type': 'FAQPage';
789
+ mainEntity: Array<{
790
+ '@type': 'Question';
791
+ name: string;
792
+ acceptedAnswer: {
793
+ '@type': 'Answer';
794
+ text: string;
795
+ };
796
+ }>;
797
+ }
798
+ /**
799
+ * JSON-LD Article schema
800
+ */
801
+ interface JsonLdArticle {
802
+ '@context': 'https://schema.org';
803
+ '@type': 'Article';
804
+ headline: string;
805
+ description?: string;
806
+ image?: string;
807
+ datePublished?: string;
808
+ dateModified?: string;
809
+ author?: {
810
+ '@type': 'Person';
811
+ name: string;
812
+ };
813
+ }
814
+ /**
815
+ * Alternate language version
816
+ */
817
+ interface StructuredDataAlternate {
818
+ /** Locale code */
819
+ locale: string;
820
+ /** URL to this version */
821
+ url: string;
822
+ }
823
+ /**
824
+ * Structured data generated for a content
825
+ */
826
+ interface StructuredData {
827
+ /** Format version */
828
+ version: number;
829
+ /** FAQ data */
830
+ faq: {
831
+ /** All detected FAQ items */
832
+ items: FaqItem[];
833
+ /** JSON-LD FAQPage schema (null if no enabled items) */
834
+ jsonLd: JsonLdFaqPage | null;
835
+ };
836
+ /** Article JSON-LD schema */
837
+ article: {
838
+ jsonLd: JsonLdArticle;
839
+ };
840
+ /** Alternate language versions */
841
+ alternates: StructuredDataAlternate[];
842
+ }
766
843
  /**
767
844
  * Content author
768
845
  */
@@ -850,7 +927,7 @@ interface Content extends ContentSummary {
850
927
  /** Open Graph image */
851
928
  ogImage: string | null;
852
929
  /** JSON-LD structured data */
853
- structuredData: Record<string, unknown> | null;
930
+ structuredData: StructuredData | null;
854
931
  /** Article author */
855
932
  author: Author | null;
856
933
  /** Associated categories */
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';var C=class o extends Error{name="LynkowError";code;status;details;cause;constructor(e,t,n,r,i){super(e),this.code=t,this.status=n,this.details=r,this.cause=i,Error.captureStackTrace&&Error.captureStackTrace(this,o);}static async fromResponse(e){let t=e.status,n=`HTTP ${t}`,r;try{let s=await e.json();s.errors&&Array.isArray(s.errors)?(r=s.errors,n=s.errors[0]?.message||n):s.error?n=s.error:s.message&&(n=s.message);}catch{n=e.statusText||n;}let i=o.statusToCode(t);return new o(n,i,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 le(o){return o instanceof C}function pe(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 K(o,e){let t;try{t=await fetch(o,e);}catch(p){throw new C("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=pe(t.status),i=n.error||n.message||`HTTP error: ${t.status}`,s=n.errors||[{message:i}];throw new C(i,r,t.status,s)}function J(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},u=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=J(t);return `${n}?${r}`}return n}async get(e,t,n){let r=n?.locale||this.config.locale,i=r?{...t,locale:r}:t,s=this.buildEndpointUrl(e,i),p=this.mergeFetchOptions(n?.fetchOptions);return K(s,{method:"GET",...p})}async getWithCache(e,t,n,r,i=l.SHORT){return this.cache?this.cache.getOrSet(e,()=>this.get(t,n,r),i):this.get(t,n,r)}invalidateCache(e){this.cache?.invalidate(e);}async post(e,t,n){let r=this.buildEndpointUrl(e),i=this.mergeFetchOptions(n?.fetchOptions);return K(r,{method:"POST",...i,headers:{"Content-Type":"application/json",...i.headers},body:JSON.stringify(t)})}async getText(e,t){let n=this.buildEndpointUrl(e),r=this.mergeFetchOptions(t?.fetchOptions),i=await fetch(n,{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 q="contents_",b=class extends u{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=`${q}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=`${q}slug_${e}_${n||"default"}`;return this.getWithCache(r,`/contents/slug/${encodeURIComponent(e)}`,void 0,t,l.SHORT)}clearCache(){this.invalidateCache(q);}};var F="categories_",x=class extends u{async list(e){let t=e?.locale||this.config.locale,n=`${F}list_${t||"default"}`;return this.getWithCache(n,"/categories",void 0,e,l.SHORT)}async tree(e){let t=e?.locale||this.config.locale,n=`${F}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=`${F}slug_${e}_${JSON.stringify(t||{})}`;return this.getWithCache(r,`/categories/${encodeURIComponent(e)}`,n,t,l.SHORT)}clearCache(){this.invalidateCache(F);}};var Q="tags_",E=class extends u{async list(e){let t=e?.locale||this.config.locale,n=`${Q}list_${t||"default"}`;return this.getWithCache(n,"/tags",void 0,e,l.SHORT)}clearCache(){this.invalidateCache(Q);}};var k="pages_",L=class extends u{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 M="globals_",T=class extends u{async siteConfig(e){let t=e?.locale||this.config.locale,n=`${M}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=`${M}${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(M);}};function D(o){return {_hp:"",_ts:o}}var Y="forms_",S=class extends u{sessionStartTime;constructor(e){super(e),this.sessionStartTime=Date.now();}async getBySlug(e){let t=`${Y}${e}`;return (await this.getWithCache(t,`/forms/${encodeURIComponent(e)}`,void 0,void 0,l.MEDIUM)).data}async submit(e,t,n){let r=D(this.sessionStartTime),i={data:t,honeypot:r._hp,...r};return n?.recaptchaToken&&(i.recaptchaToken=n.recaptchaToken),this.post(`/forms/${encodeURIComponent(e)}/submit`,i,n)}clearCache(){this.invalidateCache(Y);}};var O="reviews_",P=class extends u{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=`${O}list_${JSON.stringify(e||{})}`;return this.getWithCache(r,"/reviews",n,t,l.SHORT)}async getBySlug(e){let t=`${O}slug_${e}`;return (await this.getWithCache(t,`/reviews/${encodeURIComponent(e)}`,void 0,void 0,l.SHORT)).data}async settings(){let e=`${O}settings`;return this.getWithCache(e,"/reviews/settings",void 0,void 0,l.MEDIUM)}async submit(e,t){let n=D(this.sessionStartTime),r={...e,...n};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 Z="site_",I=class extends u{async getConfig(){let e=`${Z}config`;return (await this.getWithCache(e,"/site",void 0,void 0,l.MEDIUM)).data}clearCache(){this.invalidateCache(Z);}};var W="legal_",$=class extends u{async list(e){let t=e?.locale||this.config.locale,n=`${W}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=`${W}slug_${e}_${n||"default"}`;return (await this.getWithCache(r,`/pages/${encodeURIComponent(e)}`,void 0,t,l.SHORT)).data}clearCache(){this.invalidateCache(W);}};var ee="cookies_",B=class extends u{async getConfig(){let e=`${ee}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(ee);}};var A=class extends u{async sitemap(e){return this.getText("/sitemap.xml",e)}async robots(e){return this.getText("/robots.txt",e)}};var z="paths_",_=class extends u{async list(e){let t=e?.locale||this.config.locale,n=`${z}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=`${z}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 C&&n.status===404)return null;throw n}}clearCache(){this.invalidateCache(z);}};var c=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",de=!c;function ge(o,e){return c?o():e}async function ue(o,e){return c?o():e}var j="lynkow-tracker",N=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 !c||window.LynkowAnalytics?Promise.resolve():this.loadPromise?this.loadPromise:(this.loading=true,this.loadPromise=new Promise((e,t)=>{if(document.getElementById(j)){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=j,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(!(!c||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){!c||!this.enabled||(await this.init(),window.LynkowAnalytics&&window.LynkowAnalytics.track(e));}async trackFunnelStep(e){!c||!this.enabled||(await this.init(),window.LynkowAnalytics&&window.LynkowAnalytics.trackFunnel(e.funnelId,e.stepNumber,e.stepName,e.funnelName));}async trackPageview(e){!c||!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(c)return window.LynkowAnalytics}destroy(){if(!c)return;document.getElementById(j)?.remove(),this.initialized=false,this.loadPromise=null;}};var G="_lkw_consent",X={necessary:true,analytics:false,marketing:false,preferences:false},U=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(!c)return null;try{let e=localStorage.getItem(G);if(e){let t=JSON.parse(e);return t.choices?t.choices:t}}catch{}return null}saveConsent(e){if(c){try{localStorage.setItem(G,JSON.stringify({choices:e}));}catch{}this.events.emit("consent-changed",e),document.dispatchEvent(new CustomEvent("lynkow:consent:update",{detail:e}));}}show(){c&&(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(){c&&(this.bannerElement?.remove(),this.bannerElement=null);}showPreferences(){c&&(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 c?this.getStoredConsent()||{...X}:{...X}}hasConsented(){return c?this.getStoredConsent()!==null:false}acceptAll(){if(!c)return;let e={necessary:true,analytics:true,marketing:true,preferences:true};this.saveConsent(e),this.logConsent(e),this.hide();}rejectAll(){if(!c)return;let e={necessary:true,analytics:false,marketing:false,preferences:false};this.saveConsent(e),this.logConsent(e),this.hide();}setCategories(e){if(!c)return;let n={...this.getCategories(),...e,necessary:true};this.saveConsent(n),this.logConsent(n);}reset(){if(c){try{localStorage.removeItem(G);}catch{}this.events.emit("consent-changed",{...X}),this.show();}}createBannerHTML(e){let t=e.position||"bottom",n=e.theme||"light",r=e.layout||"banner",i=e.primaryColor||"#0066cc",s=e.borderRadius??8,p={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);"},m={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=m:r==="modal"?g=h:g=p;let a=g[t]||g.bottom||"",d=n==="dark",f=d?"#1a1a1a":"#ffffff",y=d?"#ffffff":"#1a1a1a",R=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 o extends Error{name="LynkowError";code;status;details;cause;constructor(e,t,n,r,i){super(e),this.code=t,this.status=n,this.details=r,this.cause=i,Error.captureStackTrace&&Error.captureStackTrace(this,o);}static async fromResponse(e){let t=e.status,n=`HTTP ${t}`,r;try{let s=await e.json();s.errors&&Array.isArray(s.errors)?(r=s.errors,n=s.errors[0]?.message||n):s.error?n=s.error:s.message&&(n=s.message);}catch{n=e.statusText||n;}let i=o.statusToCode(t);return new o(n,i,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 le(o){return o instanceof C}function pe(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 q(o,e){let t;try{t=await fetch(o,e);}catch(p){throw new C("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=pe(t.status),i=n.error||n.message||`HTTP error: ${t.status}`,s=n.errors||[{message:i}];throw new C(i,r,t.status,s)}function V(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},u=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=V(t);return `${n}?${r}`}return n}async get(e,t,n){let r=n?.locale||this.config.locale,i=r?{...t,locale:r}:t,s=this.buildEndpointUrl(e,i),p=this.mergeFetchOptions(n?.fetchOptions);return q(s,{method:"GET",...p})}async getWithCache(e,t,n,r,i=l.SHORT){return this.cache?this.cache.getOrSet(e,()=>this.get(t,n,r),i):this.get(t,n,r)}invalidateCache(e){this.cache?.invalidate(e);}async post(e,t,n){let r=this.buildEndpointUrl(e),i=this.mergeFetchOptions(n?.fetchOptions);return q(r,{method:"POST",...i,headers:{"Content-Type":"application/json",...i.headers},body:JSON.stringify(t)})}async getText(e,t){let n=this.buildEndpointUrl(e),r=this.mergeFetchOptions(t?.fetchOptions),i=await fetch(n,{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 K="contents_",b=class extends u{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 F="categories_",x=class extends u{async list(e){let t=e?.locale||this.config.locale,n=`${F}list_${t||"default"}`;return this.getWithCache(n,"/categories",void 0,e,l.SHORT)}async tree(e){let t=e?.locale||this.config.locale,n=`${F}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=`${F}slug_${e}_${JSON.stringify(t||{})}`;return this.getWithCache(r,`/categories/${encodeURIComponent(e)}`,n,t,l.SHORT)}clearCache(){this.invalidateCache(F);}};var Q="tags_",E=class extends u{async list(e){let t=e?.locale||this.config.locale,n=`${Q}list_${t||"default"}`;return this.getWithCache(n,"/tags",void 0,e,l.SHORT)}clearCache(){this.invalidateCache(Q);}};var k="pages_",L=class extends u{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 M="globals_",T=class extends u{async siteConfig(e){let t=e?.locale||this.config.locale,n=`${M}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=`${M}${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(M);}};function D(o){return {_hp:"",_ts:o}}var Y="forms_",S=class extends u{sessionStartTime;constructor(e){super(e),this.sessionStartTime=Date.now();}async getBySlug(e){let t=`${Y}${e}`;return (await this.getWithCache(t,`/forms/${encodeURIComponent(e)}`,void 0,void 0,l.MEDIUM)).data}async submit(e,t,n){let r=D(this.sessionStartTime),i={data:t,honeypot:r._hp,...r};return n?.recaptchaToken&&(i.recaptchaToken=n.recaptchaToken),this.post(`/forms/${encodeURIComponent(e)}/submit`,i,n)}clearCache(){this.invalidateCache(Y);}};var O="reviews_",P=class extends u{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=`${O}list_${JSON.stringify(e||{})}`;return this.getWithCache(r,"/reviews",n,t,l.SHORT)}async getBySlug(e){let t=`${O}slug_${e}`;return (await this.getWithCache(t,`/reviews/${encodeURIComponent(e)}`,void 0,void 0,l.SHORT)).data}async settings(){let e=`${O}settings`;return this.getWithCache(e,"/reviews/settings",void 0,void 0,l.MEDIUM)}async submit(e,t){let n=D(this.sessionStartTime),r={...e,...n};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 Z="site_",I=class extends u{async getConfig(){let e=`${Z}config`;return (await this.getWithCache(e,"/site",void 0,void 0,l.MEDIUM)).data}clearCache(){this.invalidateCache(Z);}};var W="legal_",$=class extends u{async list(e){let t=e?.locale||this.config.locale,n=`${W}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=`${W}slug_${e}_${n||"default"}`;return (await this.getWithCache(r,`/pages/${encodeURIComponent(e)}`,void 0,t,l.SHORT)).data}clearCache(){this.invalidateCache(W);}};var ee="cookies_",B=class extends u{async getConfig(){let e=`${ee}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(ee);}};var A=class extends u{async sitemap(e){return this.getText("/sitemap.xml",e)}async robots(e){return this.getText("/robots.txt",e)}};var z="paths_",_=class extends u{async list(e){let t=e?.locale||this.config.locale,n=`${z}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=`${z}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 C&&n.status===404)return null;throw n}}clearCache(){this.invalidateCache(z);}};var c=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",de=!c;function ge(o,e){return c?o():e}async function ue(o,e){return c?o():e}var j="lynkow-tracker",N=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 !c||window.LynkowAnalytics?Promise.resolve():this.loadPromise?this.loadPromise:(this.loading=true,this.loadPromise=new Promise((e,t)=>{if(document.getElementById(j)){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=j,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(!(!c||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){!c||!this.enabled||(await this.init(),window.LynkowAnalytics&&window.LynkowAnalytics.track(e));}async trackFunnelStep(e){!c||!this.enabled||(await this.init(),window.LynkowAnalytics&&window.LynkowAnalytics.trackFunnel(e.funnelId,e.stepNumber,e.stepName,e.funnelName));}async trackPageview(e){!c||!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(c)return window.LynkowAnalytics}destroy(){if(!c)return;document.getElementById(j)?.remove(),this.initialized=false,this.loadPromise=null;}};var G="_lkw_consent",X={necessary:true,analytics:false,marketing:false,preferences:false},U=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(!c)return null;try{let e=localStorage.getItem(G);if(e){let t=JSON.parse(e);return t.choices?t.choices:t}}catch{}return null}saveConsent(e){if(c){try{localStorage.setItem(G,JSON.stringify({choices:e}));}catch{}this.events.emit("consent-changed",e),document.dispatchEvent(new CustomEvent("lynkow:consent:update",{detail:e}));}}show(){c&&(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(){c&&(this.bannerElement?.remove(),this.bannerElement=null);}showPreferences(){c&&(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 c?this.getStoredConsent()||{...X}:{...X}}hasConsented(){return c?this.getStoredConsent()!==null:false}acceptAll(){if(!c)return;let e={necessary:true,analytics:true,marketing:true,preferences:true};this.saveConsent(e),this.logConsent(e),this.hide();}rejectAll(){if(!c)return;let e={necessary:true,analytics:false,marketing:false,preferences:false};this.saveConsent(e),this.logConsent(e),this.hide();}setCategories(e){if(!c)return;let n={...this.getCategories(),...e,necessary:true};this.saveConsent(n),this.logConsent(n);}reset(){if(c){try{localStorage.removeItem(G);}catch{}this.events.emit("consent-changed",{...X}),this.show();}}createBannerHTML(e){let t=e.position||"bottom",n=e.theme||"light",r=e.layout||"banner",i=e.primaryColor||"#0066cc",s=e.borderRadius??8,p={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);"},m={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=m:r==="modal"?g=h:g=p;let a=g[t]||g.bottom||"",d=n==="dark",f=d?"#1a1a1a":"#ffffff",y=d?"#ffffff":"#1a1a1a",R=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;
@@ -127,7 +127,7 @@
127
127
  </form>
128
128
  </div>
129
129
  </div>
130
- `}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",i=>{i.preventDefault();let s=new FormData(t),p={necessary:true,analytics:s.has("analytics"),marketing:s.has("marketing"),preferences:s.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",i=>{i.target===r&&(this.preferencesElement?.remove(),this.preferencesElement=null);});}destroy(){this.hide(),this.preferencesElement?.remove(),this.preferencesElement=null;}};var w="lynkow-badge",V="lynkow-badge-styles",fe=`
130
+ `}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",i=>{i.preventDefault();let s=new FormData(t),p={necessary:true,analytics:s.has("analytics"),marketing:s.has("marketing"),preferences:s.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",i=>{i.target===r&&(this.preferencesElement?.remove(),this.preferencesElement=null);});}destroy(){this.hide(),this.preferencesElement?.remove(),this.preferencesElement=null;}};var w="lynkow-badge",J="lynkow-badge-styles",fe=`
131
131
  #${w} {
132
132
  position: fixed;
133
133
  bottom: 16px;
@@ -169,6 +169,6 @@
169
169
  color: #1a1a1a;
170
170
  }
171
171
  }
172
- `,H=class{badgeElement=null;injectStyles(){if(document.getElementById(V))return;let e=document.createElement("style");e.id=V,e.textContent=fe,document.head.appendChild(e);}inject(){if(!c||document.getElementById(w))return;this.injectStyles();let e=document.createElement("a");e.id=w,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(){c&&(this.badgeElement?.remove(),this.badgeElement=null,document.getElementById(V)?.remove());}isVisible(){return c?document.getElementById(w)!==null:false}destroy(){this.remove();}};var me=300*1e3,he="lynkow_cache_",v=new Map;function te(o={}){let e=o.defaultTtl??me,t=o.prefix??he;function n(g){return `${t}${g}`}function r(g){return Date.now()>g.expiresAt}function i(g){let a=n(g);if(c)try{let f=localStorage.getItem(a);if(!f)return null;let y=JSON.parse(f);return r(y)?(localStorage.removeItem(a),null):y.value}catch{return null}let d=v.get(a);return d?r(d)?(v.delete(a),null):d.value:null}function s(g,a,d=e){let f=n(g),y={value:a,expiresAt:Date.now()+d};if(c){try{localStorage.setItem(f,JSON.stringify(y));}catch{}return}v.set(f,y);}function p(g){let a=n(g);if(c){try{localStorage.removeItem(a);}catch{}return}v.delete(a);}function m(g){if(c){try{let a=[];for(let d=0;d<localStorage.length;d++){let f=localStorage.key(d);f&&f.startsWith(t)&&(!g||f.includes(g))&&a.push(f);}a.forEach(d=>localStorage.removeItem(d));}catch{}return}if(g)for(let a of v.keys())a.startsWith(t)&&a.includes(g)&&v.delete(a);else for(let a of v.keys())a.startsWith(t)&&v.delete(a);}async function h(g,a,d=e){let f=i(g);if(f!==null)return f;let y=await a();return s(g,y,d),y}return {get:i,set:s,remove:p,invalidate:m,getOrSet:h}}function ne(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 oe(){let o=new Map;function e(s,p){return o.has(s)||o.set(s,new Set),o.get(s).add(p),()=>t(s,p)}function t(s,p){let m=o.get(s);m&&m.delete(p);}function n(s,p){let m=o.get(s);if(m)for(let h of m)try{h(p);}catch(g){console.error(`[Lynkow] Error in event listener for "${s}":`,g);}}function r(s,p){let m=(h=>{t(s,m),p(h);});return e(s,m)}function i(s){s?o.delete(s):o.clear();}return {on:e,off:t,emit:n,once:r,removeAllListeners:i}}var re="lynkow_locale";function se(o,e){if(!c)return e;let t=ye();if(t&&o.includes(t))return t;let n=Ce(o);if(n)return n;let r=document.documentElement.lang;if(r){let i=r.split("-")[0]?.toLowerCase();if(i&&o.includes(i))return i}return e}function ye(){if(!c)return null;try{return localStorage.getItem(re)}catch{return null}}function ie(o){if(c)try{localStorage.setItem(re,o);}catch{}}function Ce(o){if(!c)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 ae(o,e){return e.includes(o)}var ce="https://api.lynkow.com";function we(o){if(!o.siteId)throw new Error("Lynkow SDK: siteId is required");let e=te(),t=ne({debug:o.debug??false}),n=oe(),r=(o.baseUrl||ce).replace(/\/$/,""),i={siteId:o.siteId,baseUrl:r,locale:o.locale,fetchOptions:o.fetchOptions||{},cache:e},s={locale:o.locale||"fr",availableLocales:["fr"],siteConfig:null,initialized:false},p={contents:new b(i),categories:new x(i),tags:new E(i),pages:new L(i),blocks:new T(i),forms:new S(i),reviews:new P(i),site:new I(i),legal:new $(i),cookies:new B(i),seo:new A(i),paths:new _(i),analytics:new N(i),consent:new U(i,n),branding:new H};function m(a){i.locale=a;}async function h(){if(!s.initialized)try{let a=await p.site.getConfig();s.siteConfig=a;let d=a.defaultLocale||"fr";if(s.availableLocales=a.enabledLocales||[d],c&&!o.locale){let f=se(s.availableLocales,d);s.locale=f,m(f);}s.initialized=!0,t.debug("Client initialized",{locale:s.locale,availableLocales:s.availableLocales}),c&&(p.analytics.init(),p.consent.hasConsented()||p.consent.show(),a.showBranding&&p.branding.inject()),n.emit("ready",void 0);}catch(a){t.error("Failed to initialize client",a),n.emit("error",a);}}return c&&setTimeout(()=>h(),0),{...p,globals:p.blocks,config:Object.freeze({siteId:o.siteId,baseUrl:r,debug:o.debug??false}),get locale(){return s.locale},get availableLocales(){return [...s.availableLocales]},setLocale(a){if(!ae(a,s.availableLocales)){t.warn(`Locale "${a}" is not available. Available: ${s.availableLocales.join(", ")}`);return}a!==s.locale&&(s.locale=a,m(a),c&&ie(a),e.invalidate(),n.emit("locale-changed",a),t.debug("Locale changed to",a));},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(a,d){return n.on(a,d)}}}function ve(o){if(!o.siteId)throw new Error("Lynkow SDK: siteId is required");let e={siteId:o.siteId,baseUrl:(o.baseUrl||ce).replace(/\/$/,""),locale:o.locale,fetchOptions:o.fetchOptions||{}};return {contents:new b(e),categories:new x(e),tags:new E(e),pages:new L(e),blocks:new T(e),forms:new S(e),reviews:new P(e),site:new I(e),legal:new $(e),cookies:new B(e),seo:new A(e),paths:new _(e)}}function Re(o){return o.type==="content"}function be(o){return o.type==="category"}
172
+ `,H=class{badgeElement=null;injectStyles(){if(document.getElementById(J))return;let e=document.createElement("style");e.id=J,e.textContent=fe,document.head.appendChild(e);}inject(){if(!c||document.getElementById(w))return;this.injectStyles();let e=document.createElement("a");e.id=w,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(){c&&(this.badgeElement?.remove(),this.badgeElement=null,document.getElementById(J)?.remove());}isVisible(){return c?document.getElementById(w)!==null:false}destroy(){this.remove();}};var me=300*1e3,he="lynkow_cache_",v=new Map;function te(o={}){let e=o.defaultTtl??me,t=o.prefix??he;function n(g){return `${t}${g}`}function r(g){return Date.now()>g.expiresAt}function i(g){let a=n(g);if(c)try{let f=localStorage.getItem(a);if(!f)return null;let y=JSON.parse(f);return r(y)?(localStorage.removeItem(a),null):y.value}catch{return null}let d=v.get(a);return d?r(d)?(v.delete(a),null):d.value:null}function s(g,a,d=e){let f=n(g),y={value:a,expiresAt:Date.now()+d};if(c){try{localStorage.setItem(f,JSON.stringify(y));}catch{}return}v.set(f,y);}function p(g){let a=n(g);if(c){try{localStorage.removeItem(a);}catch{}return}v.delete(a);}function m(g){if(c){try{let a=[];for(let d=0;d<localStorage.length;d++){let f=localStorage.key(d);f&&f.startsWith(t)&&(!g||f.includes(g))&&a.push(f);}a.forEach(d=>localStorage.removeItem(d));}catch{}return}if(g)for(let a of v.keys())a.startsWith(t)&&a.includes(g)&&v.delete(a);else for(let a of v.keys())a.startsWith(t)&&v.delete(a);}async function h(g,a,d=e){let f=i(g);if(f!==null)return f;let y=await a();return s(g,y,d),y}return {get:i,set:s,remove:p,invalidate:m,getOrSet:h}}function ne(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 oe(){let o=new Map;function e(s,p){return o.has(s)||o.set(s,new Set),o.get(s).add(p),()=>t(s,p)}function t(s,p){let m=o.get(s);m&&m.delete(p);}function n(s,p){let m=o.get(s);if(m)for(let h of m)try{h(p);}catch(g){console.error(`[Lynkow] Error in event listener for "${s}":`,g);}}function r(s,p){let m=(h=>{t(s,m),p(h);});return e(s,m)}function i(s){s?o.delete(s):o.clear();}return {on:e,off:t,emit:n,once:r,removeAllListeners:i}}var re="lynkow_locale";function se(o,e){if(!c)return e;let t=ye();if(t&&o.includes(t))return t;let n=Ce(o);if(n)return n;let r=document.documentElement.lang;if(r){let i=r.split("-")[0]?.toLowerCase();if(i&&o.includes(i))return i}return e}function ye(){if(!c)return null;try{return localStorage.getItem(re)}catch{return null}}function ie(o){if(c)try{localStorage.setItem(re,o);}catch{}}function Ce(o){if(!c)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 ae(o,e){return e.includes(o)}var ce="https://api.lynkow.com";function we(o){if(!o.siteId)throw new Error("Lynkow SDK: siteId is required");let e=te(),t=ne({debug:o.debug??false}),n=oe(),r=(o.baseUrl||ce).replace(/\/$/,""),i={siteId:o.siteId,baseUrl:r,locale:o.locale,fetchOptions:o.fetchOptions||{},cache:e},s={locale:o.locale||"fr",availableLocales:["fr"],siteConfig:null,initialized:false},p={contents:new b(i),categories:new x(i),tags:new E(i),pages:new L(i),blocks:new T(i),forms:new S(i),reviews:new P(i),site:new I(i),legal:new $(i),cookies:new B(i),seo:new A(i),paths:new _(i),analytics:new N(i),consent:new U(i,n),branding:new H};function m(a){i.locale=a;}async function h(){if(!s.initialized)try{let a=await p.site.getConfig();s.siteConfig=a;let d=a.defaultLocale||"fr";if(s.availableLocales=a.enabledLocales||[d],c&&!o.locale){let f=se(s.availableLocales,d);s.locale=f,m(f);}s.initialized=!0,t.debug("Client initialized",{locale:s.locale,availableLocales:s.availableLocales}),c&&(p.analytics.init(),p.consent.hasConsented()||p.consent.show(),a.showBranding&&p.branding.inject()),n.emit("ready",void 0);}catch(a){t.error("Failed to initialize client",a),n.emit("error",a);}}return c&&setTimeout(()=>h(),0),{...p,globals:p.blocks,config:Object.freeze({siteId:o.siteId,baseUrl:r,debug:o.debug??false}),get locale(){return s.locale},get availableLocales(){return [...s.availableLocales]},setLocale(a){if(!ae(a,s.availableLocales)){t.warn(`Locale "${a}" is not available. Available: ${s.availableLocales.join(", ")}`);return}a!==s.locale&&(s.locale=a,m(a),c&&ie(a),e.invalidate(),n.emit("locale-changed",a),t.debug("Locale changed to",a));},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(a,d){return n.on(a,d)}}}function ve(o){if(!o.siteId)throw new Error("Lynkow SDK: siteId is required");let e={siteId:o.siteId,baseUrl:(o.baseUrl||ce).replace(/\/$/,""),locale:o.locale,fetchOptions:o.fetchOptions||{}};return {contents:new b(e),categories:new x(e),tags:new E(e),pages:new L(e),blocks:new T(e),forms:new S(e),reviews:new P(e),site:new I(e),legal:new $(e),cookies:new B(e),seo:new A(e),paths:new _(e)}}function Re(o){return o.type==="content"}function be(o){return o.type==="category"}
173
173
  exports.LynkowError=C;exports.browserOnly=ge;exports.browserOnlyAsync=ue;exports.createClient=we;exports.createLynkowClient=ve;exports.isBrowser=c;exports.isCategoryResolve=be;exports.isContentResolve=Re;exports.isLynkowError=le;exports.isServer=de;//# sourceMappingURL=index.js.map
174
174
  //# sourceMappingURL=index.js.map