lynkow 3.8.71 → 3.8.72

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
@@ -65,6 +65,10 @@ interface ClientConfig {
65
65
 
66
66
  // Optional: Enable debug logging
67
67
  debug?: boolean
68
+
69
+ // Optional: Disable SDK in-memory cache (default: true)
70
+ // Set to false for Next.js ISR with webhook revalidation
71
+ cache?: boolean
68
72
  }
69
73
  ```
70
74
 
@@ -125,6 +129,24 @@ export async function POST(request: Request) {
125
129
 
126
130
  Then configure a webhook in Lynkow to call your revalidate endpoint when content changes.
127
131
 
132
+ #### Option 4: Webhook Revalidation with SDK Cache Disabled
133
+
134
+ Best for production ISR with webhook-driven revalidation:
135
+
136
+ ```typescript
137
+ const lynkow = createClient({
138
+ siteId: process.env.LYNKOW_SITE_ID!,
139
+ cache: false,
140
+ fetchOptions: {
141
+ next: { revalidate: 60 },
142
+ },
143
+ })
144
+ ```
145
+
146
+ By default, the SDK maintains its own in-memory cache (5-30 min TTL) that sits between your code and `fetch()`. When you use `revalidatePath()` or `revalidateTag()` from a webhook handler, Next.js purges its cache, but the SDK may still serve stale data from its internal Map.
147
+
148
+ Setting `cache: false` disables the SDK cache entirely, so every call goes through `fetch()` and is governed solely by Next.js caching. This is the recommended configuration for any deployment that uses webhook revalidation.
149
+
128
150
  ## Browser vs Server
129
151
 
130
152
  The SDK is isomorphic and works on both browser and server environments. Some features are browser-only:
@@ -990,7 +1012,17 @@ interface I18nConfig {
990
1012
 
991
1013
  ## Cache Management
992
1014
 
993
- The SDK caches API responses automatically.
1015
+ The SDK caches API responses in memory (server) or localStorage (browser) by default. For Next.js ISR with webhook revalidation, disable the SDK cache to let Next.js manage caching end-to-end:
1016
+
1017
+ ```typescript
1018
+ const lynkow = createClient({
1019
+ siteId: '...',
1020
+ cache: false, // Disable SDK cache, rely on Next.js fetch cache
1021
+ fetchOptions: { next: { revalidate: 60 } },
1022
+ })
1023
+ ```
1024
+
1025
+ If the SDK cache is enabled (default), you can manage it manually:
994
1026
 
995
1027
  ```typescript
996
1028
  // Clear all cached data
package/dist/index.d.mts CHANGED
@@ -5315,6 +5315,28 @@ interface ClientConfig extends LynkowConfig {
5315
5315
  * @default false
5316
5316
  */
5317
5317
  debug?: boolean;
5318
+ /**
5319
+ * Enable the SDK's in-memory response cache.
5320
+ * When `true` (default), API responses are cached in memory (server) or
5321
+ * localStorage (browser) with TTLs of 5-30 minutes depending on the resource.
5322
+ * Set to `false` for Next.js ISR/SSR deployments where you rely on
5323
+ * `revalidatePath()` / `revalidateTag()` from webhook handlers.
5324
+ * Disabling the SDK cache ensures every render hits `fetch()`, which
5325
+ * lets Next.js control caching and revalidation end-to-end.
5326
+ *
5327
+ * @default true
5328
+ *
5329
+ * @example
5330
+ * ```typescript
5331
+ * // Recommended for Next.js SSR with webhook revalidation
5332
+ * const lynkow = createClient({
5333
+ * siteId: 'your-site-uuid',
5334
+ * cache: false,
5335
+ * fetchOptions: { next: { revalidate: 60 } },
5336
+ * })
5337
+ * ```
5338
+ */
5339
+ cache?: boolean;
5318
5340
  }
5319
5341
  /**
5320
5342
  * Extended client interface for SDK v3
@@ -5335,6 +5357,7 @@ interface Client extends LynkowClient {
5335
5357
  siteId: string;
5336
5358
  baseUrl: string;
5337
5359
  debug: boolean;
5360
+ cache: boolean;
5338
5361
  }>;
5339
5362
  /**
5340
5363
  * Set the current locale
package/dist/index.d.ts CHANGED
@@ -5315,6 +5315,28 @@ interface ClientConfig extends LynkowConfig {
5315
5315
  * @default false
5316
5316
  */
5317
5317
  debug?: boolean;
5318
+ /**
5319
+ * Enable the SDK's in-memory response cache.
5320
+ * When `true` (default), API responses are cached in memory (server) or
5321
+ * localStorage (browser) with TTLs of 5-30 minutes depending on the resource.
5322
+ * Set to `false` for Next.js ISR/SSR deployments where you rely on
5323
+ * `revalidatePath()` / `revalidateTag()` from webhook handlers.
5324
+ * Disabling the SDK cache ensures every render hits `fetch()`, which
5325
+ * lets Next.js control caching and revalidation end-to-end.
5326
+ *
5327
+ * @default true
5328
+ *
5329
+ * @example
5330
+ * ```typescript
5331
+ * // Recommended for Next.js SSR with webhook revalidation
5332
+ * const lynkow = createClient({
5333
+ * siteId: 'your-site-uuid',
5334
+ * cache: false,
5335
+ * fetchOptions: { next: { revalidate: 60 } },
5336
+ * })
5337
+ * ```
5338
+ */
5339
+ cache?: boolean;
5318
5340
  }
5319
5341
  /**
5320
5342
  * Extended client interface for SDK v3
@@ -5335,6 +5357,7 @@ interface Client extends LynkowClient {
5335
5357
  siteId: string;
5336
5358
  baseUrl: string;
5337
5359
  debug: boolean;
5360
+ cache: boolean;
5338
5361
  }>;
5339
5362
  /**
5340
5363
  * Set the current locale
package/dist/index.js CHANGED
@@ -232,6 +232,6 @@
232
232
  color: #1a1a1a;
233
233
  }
234
234
  }
235
- `,M=class{initialized=false;observer=null;pendingFrame=null;handleWidgetResize=e=>{if(!e.data||e.data.type!=="lynkow-widget-resize")return;document.querySelectorAll('iframe[src*="/widgets/calendar/"]').forEach(n=>{n.contentWindow===e.source&&(n.style.height=e.data.height+"px");});};injectStyles(){if(!c||document.getElementById(ee))return;let e=document.createElement("style");e.id=ee,e.textContent=Te,document.head.appendChild(e);}async handleCopyClick(e){let t=e.closest(".code-block");if(!t)return;let n=t.querySelector("code");if(!n)return;let r=n.textContent||"";try{await navigator.clipboard.writeText(r),e.classList.add("copied"),e.innerHTML=Se,setTimeout(()=>{e.classList.remove("copied"),e.innerHTML=xe;},2e3);}catch(o){console.error("Lynkow SDK: Failed to copy code",o);}}bindCodeBlockCopy(){if(!c)return;document.querySelectorAll("[data-copy-code]").forEach(t=>{t.dataset.lynkowBound||(t.dataset.lynkowBound="true",t.addEventListener("click",n=>{n.preventDefault(),this.handleCopyClick(t);}));});}activateScripts(e){if(!c)return;let n=(e instanceof HTMLElement?e:document.body).querySelectorAll("script:not([data-lynkow-activated])"),r=Array.from(n).filter(o=>!o.src&&o.isConnected);r.length!==0&&(document.head.querySelectorAll(`script[${te}]`).forEach(o=>o.remove()),r.forEach(o=>{o.setAttribute("data-lynkow-activated","true");let i=document.createElement("script"),a=o.attributes;for(let p=0;p<a.length;p++){let g=a[p];g&&(g.name==="type"&&g.value==="text/plain"||g.name!=="data-lynkow-activated"&&i.setAttribute(g.name,g.value));}i.textContent=o.textContent,i.setAttribute(te,""),document.head.appendChild(i);}));}init(){!c||this.initialized||(this.injectStyles(),this.bindCodeBlockCopy(),this.activateScripts(),window.addEventListener("message",this.handleWidgetResize),this.observer||(this.observer=new MutationObserver(()=>{this.pendingFrame===null&&(this.pendingFrame=requestAnimationFrame(()=>{this.pendingFrame=null,this.activateScripts(),this.bindCodeBlockCopy();}));}),this.observer.observe(document.body,{childList:true,subtree:true})),this.initialized=true);}isInitialized(){return this.initialized}destroy(){c&&(window.removeEventListener("message",this.handleWidgetResize),this.pendingFrame!==null&&(cancelAnimationFrame(this.pendingFrame),this.pendingFrame=null),this.observer&&(this.observer.disconnect(),this.observer=null),document.getElementById(ee)?.remove(),document.head.querySelectorAll(`script[${te}]`).forEach(e=>e.remove()),this.initialized=false);}};var N=class{srcset(e,t={}){if(!e)return "";let{widths:n=[400,800,1200,1920],fit:r="scale-down",quality:o=80,gravity:i}=t,a=this.parseImageUrl(e);return a?n.map(p=>{let g=[`w=${p}`,`fit=${r}`,"format=auto",`quality=${o}`,i&&`gravity=${i}`].filter(Boolean).join(",");return `${a.cdnBase}/cdn-cgi/image/${g}/${a.relativePath} ${p}w`}).join(", "):""}transform(e,t={}){if(!e)return "";let n=this.parseImageUrl(e);if(!n)return e||"";let r=[t.w&&`w=${t.w}`,t.h&&`h=${t.h}`,`fit=${t.fit||"scale-down"}`,`format=${t.format||"auto"}`,`quality=${t.quality||80}`,t.gravity&&`gravity=${t.gravity}`,t.dpr&&`dpr=${t.dpr}`].filter(Boolean).join(",");return `${n.cdnBase}/cdn-cgi/image/${r}/${n.relativePath}`}parseImageUrl(e){let t=e.indexOf("/cdn-cgi/image/");if(t!==-1){let o=e.substring(0,t),i=e.substring(t+15),a=i.indexOf("/");if(a===-1)return null;let p=i.substring(a+1);return {cdnBase:o,relativePath:p}}let n=e.indexOf("/sites/");if(n!==-1){let o=e.substring(0,n),i=e.substring(n+1);return {cdnBase:o,relativePath:i}}let r=e.indexOf("/avatars/");if(r!==-1){let o=e.substring(0,r),i=e.substring(r+1);return {cdnBase:o,relativePath:i}}return null}};var A=class extends m{async search(e,t){return this.get("/search",{q:e,locale:t?.locale,category:t?.category,tag:t?.tag,page:t?.page,limit:t?.limit},t)}async getConfig(e){return this.getWithCache("search-config","/search/config",void 0,e,d.MEDIUM)}};var Le=300*1e3,Oe="lynkow_cache_",v=new Map;function le(s={}){let e=s.defaultTtl??Le,t=s.prefix??Oe;function n(u){return `${t}${u}`}function r(u){return Date.now()>u.expiresAt}function o(u){let l=n(u);if(c)try{let h=localStorage.getItem(l);if(!h)return null;let y=JSON.parse(h);return r(y)?(localStorage.removeItem(l),null):y.value}catch{return null}let f=v.get(l);return f?r(f)?(v.delete(l),null):f.value:null}function i(u,l,f=e){let h=n(u),y={value:l,expiresAt:Date.now()+f};if(c){try{localStorage.setItem(h,JSON.stringify(y));}catch{}return}v.set(h,y);}function a(u){let l=n(u);if(c){try{localStorage.removeItem(l);}catch{}return}v.delete(l);}function p(u){if(c){try{let l=[];for(let f=0;f<localStorage.length;f++){let h=localStorage.key(f);h&&h.startsWith(t)&&(!u||h.includes(u))&&l.push(h);}l.forEach(f=>localStorage.removeItem(f));}catch{}return}if(u)for(let l of v.keys())l.startsWith(t)&&l.includes(u)&&v.delete(l);else for(let l of v.keys())l.startsWith(t)&&v.delete(l);}async function g(u,l,f=e){let h=o(u);if(h!==null)return h;let y=await l();return i(u,y,f),y}return {get:o,set:i,remove:a,invalidate:p,getOrSet:g}}function de(s){let e=s.prefix||"[Lynkow]";return {debug(...t){s.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 pe(){let s=new Map;function e(i,a){return s.has(i)||s.set(i,new Set),s.get(i).add(a),()=>t(i,a)}function t(i,a){let p=s.get(i);p&&p.delete(a);}function n(i,a){let p=s.get(i);if(p)for(let g of p)try{g(a);}catch(u){console.error(`[Lynkow] Error in event listener for "${i}":`,u);}}function r(i,a){let p=(g=>{t(i,p),a(g);});return e(i,p)}function o(i){i?s.delete(i):s.clear();}return {on:e,off:t,emit:n,once:r,removeAllListeners:o}}var me="lynkow_locale";function ne(s,e){let t=s.toLowerCase();return e.find(n=>n.toLowerCase()===t)??null}function ue(s,e){if(!c)return e;let t=Ie();if(t&&s.includes(t))return t;let n=Pe(s);if(n)return n;let r=document.documentElement.lang;if(r){let o=ne(r,s);if(o)return o;let i=r.split("-")[0]?.toLowerCase();if(i){let a=ne(i,s);if(a)return a}}return e}function Ie(){if(!c)return null;try{return localStorage.getItem(me)}catch{return null}}function ge(s){if(c)try{localStorage.setItem(me,s);}catch{}}function Pe(s){if(!c)return null;let t=window.location.pathname.split("/").filter(Boolean);if(t.length>0){let n=t[0];if(n){let r=ne(n,s);if(r)return r}}return null}function he(s,e){return e.includes(s)}var fe="https://api.lynkow.com";function Be(s){if(!s.siteId)throw new Error("Lynkow SDK: siteId is required");let e=le(),t=de({debug:s.debug??false}),n=pe(),r=(s.baseUrl||fe).replace(/\/$/,""),o={siteId:s.siteId,baseUrl:r,locale:s.locale,fetchOptions:s.fetchOptions||{},cache:e},i={locale:s.locale||"fr",availableLocales:["fr"],siteConfig:null,initialized:false},a={contents:new b(o),categories:new R(o),tags:new E(o),pages:new k(o),blocks:new x(o),forms:new S(o),reviews:new T(o),site:new L(o),legal:new O(o),cookies:new I(o),seo:new P(o),paths:new B(o),analytics:new D(o),consent:new q(o,n),branding:new H(o),enhancements:new M,media:new N,search:new A(o)};function p(l){o.locale=l;}async function g(){if(!i.initialized)try{let l=await a.site.getConfig();i.siteConfig=l;let f=l.defaultLocale||"fr";if(i.availableLocales=l.enabledLocales||[f],c&&!s.locale){let h=ue(i.availableLocales,f);i.locale=h,p(h);}i.initialized=!0,t.debug("Client initialized",{locale:i.locale,availableLocales:i.availableLocales}),c&&(a.analytics.init(),a.consent.hasConsented()||a.consent.show(),l.showBranding&&await a.branding.inject(),a.enhancements.init()),n.emit("ready",void 0);}catch(l){t.error("Failed to initialize client",l),n.emit("error",l);}}return c&&setTimeout(()=>{a.enhancements.init(),g();},0),{...a,globals:a.blocks,config:Object.freeze({siteId:s.siteId,baseUrl:r,debug:s.debug??false}),get locale(){return i.locale},get availableLocales(){return [...i.availableLocales]},setLocale(l){if(!he(l,i.availableLocales)){t.warn(`Locale "${l}" is not available. Available: ${i.availableLocales.join(", ")}`);return}l!==i.locale&&(i.locale=l,p(l),c&&ge(l),e.invalidate(),n.emit("locale-changed",l),t.debug("Locale changed to",l));},clearCache(){e.invalidate(),t.debug("Cache cleared");},destroy(){a.analytics.destroy(),a.consent.destroy(),a.branding.destroy(),a.enhancements.destroy(),e.invalidate(),n.removeAllListeners(),t.debug("Client destroyed");},on(l,f){return n.on(l,f)}}}function $e(s){if(!s.siteId)throw new Error("Lynkow SDK: siteId is required");let e={siteId:s.siteId,baseUrl:(s.baseUrl||fe).replace(/\/$/,""),locale:s.locale,fetchOptions:s.fetchOptions||{}};return {contents:new b(e),categories:new R(e),tags:new E(e),pages:new k(e),blocks:new x(e),forms:new S(e),reviews:new T(e),site:new L(e),legal:new O(e),cookies:new I(e),seo:new P(e),paths:new B(e),search:new A(e)}}function Ae(s){return s.type==="content"}function _e(s){return s.type==="category"}
235
+ `,M=class{initialized=false;observer=null;pendingFrame=null;handleWidgetResize=e=>{if(!e.data||e.data.type!=="lynkow-widget-resize")return;document.querySelectorAll('iframe[src*="/widgets/calendar/"]').forEach(n=>{n.contentWindow===e.source&&(n.style.height=e.data.height+"px");});};injectStyles(){if(!c||document.getElementById(ee))return;let e=document.createElement("style");e.id=ee,e.textContent=Te,document.head.appendChild(e);}async handleCopyClick(e){let t=e.closest(".code-block");if(!t)return;let n=t.querySelector("code");if(!n)return;let r=n.textContent||"";try{await navigator.clipboard.writeText(r),e.classList.add("copied"),e.innerHTML=Se,setTimeout(()=>{e.classList.remove("copied"),e.innerHTML=xe;},2e3);}catch(o){console.error("Lynkow SDK: Failed to copy code",o);}}bindCodeBlockCopy(){if(!c)return;document.querySelectorAll("[data-copy-code]").forEach(t=>{t.dataset.lynkowBound||(t.dataset.lynkowBound="true",t.addEventListener("click",n=>{n.preventDefault(),this.handleCopyClick(t);}));});}activateScripts(e){if(!c)return;let n=(e instanceof HTMLElement?e:document.body).querySelectorAll("script:not([data-lynkow-activated])"),r=Array.from(n).filter(o=>!o.src&&o.isConnected);r.length!==0&&(document.head.querySelectorAll(`script[${te}]`).forEach(o=>o.remove()),r.forEach(o=>{o.setAttribute("data-lynkow-activated","true");let i=document.createElement("script"),a=o.attributes;for(let p=0;p<a.length;p++){let g=a[p];g&&(g.name==="type"&&g.value==="text/plain"||g.name!=="data-lynkow-activated"&&i.setAttribute(g.name,g.value));}i.textContent=o.textContent,i.setAttribute(te,""),document.head.appendChild(i);}));}init(){!c||this.initialized||(this.injectStyles(),this.bindCodeBlockCopy(),this.activateScripts(),window.addEventListener("message",this.handleWidgetResize),this.observer||(this.observer=new MutationObserver(()=>{this.pendingFrame===null&&(this.pendingFrame=requestAnimationFrame(()=>{this.pendingFrame=null,this.activateScripts(),this.bindCodeBlockCopy();}));}),this.observer.observe(document.body,{childList:true,subtree:true})),this.initialized=true);}isInitialized(){return this.initialized}destroy(){c&&(window.removeEventListener("message",this.handleWidgetResize),this.pendingFrame!==null&&(cancelAnimationFrame(this.pendingFrame),this.pendingFrame=null),this.observer&&(this.observer.disconnect(),this.observer=null),document.getElementById(ee)?.remove(),document.head.querySelectorAll(`script[${te}]`).forEach(e=>e.remove()),this.initialized=false);}};var N=class{srcset(e,t={}){if(!e)return "";let{widths:n=[400,800,1200,1920],fit:r="scale-down",quality:o=80,gravity:i}=t,a=this.parseImageUrl(e);return a?n.map(p=>{let g=[`w=${p}`,`fit=${r}`,"format=auto",`quality=${o}`,i&&`gravity=${i}`].filter(Boolean).join(",");return `${a.cdnBase}/cdn-cgi/image/${g}/${a.relativePath} ${p}w`}).join(", "):""}transform(e,t={}){if(!e)return "";let n=this.parseImageUrl(e);if(!n)return e||"";let r=[t.w&&`w=${t.w}`,t.h&&`h=${t.h}`,`fit=${t.fit||"scale-down"}`,`format=${t.format||"auto"}`,`quality=${t.quality||80}`,t.gravity&&`gravity=${t.gravity}`,t.dpr&&`dpr=${t.dpr}`].filter(Boolean).join(",");return `${n.cdnBase}/cdn-cgi/image/${r}/${n.relativePath}`}parseImageUrl(e){let t=e.indexOf("/cdn-cgi/image/");if(t!==-1){let o=e.substring(0,t),i=e.substring(t+15),a=i.indexOf("/");if(a===-1)return null;let p=i.substring(a+1);return {cdnBase:o,relativePath:p}}let n=e.indexOf("/sites/");if(n!==-1){let o=e.substring(0,n),i=e.substring(n+1);return {cdnBase:o,relativePath:i}}let r=e.indexOf("/avatars/");if(r!==-1){let o=e.substring(0,r),i=e.substring(r+1);return {cdnBase:o,relativePath:i}}return null}};var A=class extends m{async search(e,t){return this.get("/search",{q:e,locale:t?.locale,category:t?.category,tag:t?.tag,page:t?.page,limit:t?.limit},t)}async getConfig(e){return this.getWithCache("search-config","/search/config",void 0,e,d.MEDIUM)}};var Le=300*1e3,Oe="lynkow_cache_",v=new Map;function le(s={}){let e=s.defaultTtl??Le,t=s.prefix??Oe;function n(u){return `${t}${u}`}function r(u){return Date.now()>u.expiresAt}function o(u){let l=n(u);if(c)try{let h=localStorage.getItem(l);if(!h)return null;let y=JSON.parse(h);return r(y)?(localStorage.removeItem(l),null):y.value}catch{return null}let f=v.get(l);return f?r(f)?(v.delete(l),null):f.value:null}function i(u,l,f=e){let h=n(u),y={value:l,expiresAt:Date.now()+f};if(c){try{localStorage.setItem(h,JSON.stringify(y));}catch{}return}v.set(h,y);}function a(u){let l=n(u);if(c){try{localStorage.removeItem(l);}catch{}return}v.delete(l);}function p(u){if(c){try{let l=[];for(let f=0;f<localStorage.length;f++){let h=localStorage.key(f);h&&h.startsWith(t)&&(!u||h.includes(u))&&l.push(h);}l.forEach(f=>localStorage.removeItem(f));}catch{}return}if(u)for(let l of v.keys())l.startsWith(t)&&l.includes(u)&&v.delete(l);else for(let l of v.keys())l.startsWith(t)&&v.delete(l);}async function g(u,l,f=e){let h=o(u);if(h!==null)return h;let y=await l();return i(u,y,f),y}return {get:o,set:i,remove:a,invalidate:p,getOrSet:g}}function de(s){let e=s.prefix||"[Lynkow]";return {debug(...t){s.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 pe(){let s=new Map;function e(i,a){return s.has(i)||s.set(i,new Set),s.get(i).add(a),()=>t(i,a)}function t(i,a){let p=s.get(i);p&&p.delete(a);}function n(i,a){let p=s.get(i);if(p)for(let g of p)try{g(a);}catch(u){console.error(`[Lynkow] Error in event listener for "${i}":`,u);}}function r(i,a){let p=(g=>{t(i,p),a(g);});return e(i,p)}function o(i){i?s.delete(i):s.clear();}return {on:e,off:t,emit:n,once:r,removeAllListeners:o}}var me="lynkow_locale";function ne(s,e){let t=s.toLowerCase();return e.find(n=>n.toLowerCase()===t)??null}function ue(s,e){if(!c)return e;let t=Ie();if(t&&s.includes(t))return t;let n=Pe(s);if(n)return n;let r=document.documentElement.lang;if(r){let o=ne(r,s);if(o)return o;let i=r.split("-")[0]?.toLowerCase();if(i){let a=ne(i,s);if(a)return a}}return e}function Ie(){if(!c)return null;try{return localStorage.getItem(me)}catch{return null}}function ge(s){if(c)try{localStorage.setItem(me,s);}catch{}}function Pe(s){if(!c)return null;let t=window.location.pathname.split("/").filter(Boolean);if(t.length>0){let n=t[0];if(n){let r=ne(n,s);if(r)return r}}return null}function he(s,e){return e.includes(s)}var fe="https://api.lynkow.com";function Be(s){if(!s.siteId)throw new Error("Lynkow SDK: siteId is required");let e=s.cache!==false?le():void 0,t=de({debug:s.debug??false}),n=pe(),r=(s.baseUrl||fe).replace(/\/$/,""),o={siteId:s.siteId,baseUrl:r,locale:s.locale,fetchOptions:s.fetchOptions||{},...e?{cache:e}:{}},i={locale:s.locale||"fr",availableLocales:["fr"],siteConfig:null,initialized:false},a={contents:new b(o),categories:new R(o),tags:new E(o),pages:new k(o),blocks:new x(o),forms:new S(o),reviews:new T(o),site:new L(o),legal:new O(o),cookies:new I(o),seo:new P(o),paths:new B(o),analytics:new D(o),consent:new q(o,n),branding:new H(o),enhancements:new M,media:new N,search:new A(o)};function p(l){o.locale=l;}async function g(){if(!i.initialized)try{let l=await a.site.getConfig();i.siteConfig=l;let f=l.defaultLocale||"fr";if(i.availableLocales=l.enabledLocales||[f],c&&!s.locale){let h=ue(i.availableLocales,f);i.locale=h,p(h);}i.initialized=!0,t.debug("Client initialized",{locale:i.locale,availableLocales:i.availableLocales}),c&&(a.analytics.init(),a.consent.hasConsented()||a.consent.show(),l.showBranding&&await a.branding.inject(),a.enhancements.init()),n.emit("ready",void 0);}catch(l){t.error("Failed to initialize client",l),n.emit("error",l);}}return c&&setTimeout(()=>{a.enhancements.init(),g();},0),{...a,globals:a.blocks,config:Object.freeze({siteId:s.siteId,baseUrl:r,debug:s.debug??false,cache:s.cache!==false}),get locale(){return i.locale},get availableLocales(){return [...i.availableLocales]},setLocale(l){if(!he(l,i.availableLocales)){t.warn(`Locale "${l}" is not available. Available: ${i.availableLocales.join(", ")}`);return}l!==i.locale&&(i.locale=l,p(l),c&&ge(l),e?.invalidate(),n.emit("locale-changed",l),t.debug("Locale changed to",l));},clearCache(){e?.invalidate(),t.debug("Cache cleared");},destroy(){a.analytics.destroy(),a.consent.destroy(),a.branding.destroy(),a.enhancements.destroy(),e?.invalidate(),n.removeAllListeners(),t.debug("Client destroyed");},on(l,f){return n.on(l,f)}}}function $e(s){if(!s.siteId)throw new Error("Lynkow SDK: siteId is required");let e={siteId:s.siteId,baseUrl:(s.baseUrl||fe).replace(/\/$/,""),locale:s.locale,fetchOptions:s.fetchOptions||{}};return {contents:new b(e),categories:new R(e),tags:new E(e),pages:new k(e),blocks:new x(e),forms:new S(e),reviews:new T(e),site:new L(e),legal:new O(e),cookies:new I(e),seo:new P(e),paths:new B(e),search:new A(e)}}function Ae(s){return s.type==="content"}function _e(s){return s.type==="category"}
236
236
  exports.AnalyticsService=D;exports.BlocksService=x;exports.BrandingService=H;exports.CategoriesService=R;exports.ConsentService=q;exports.ContentsService=b;exports.CookiesService=I;exports.EnhancementsService=M;exports.FormsService=S;exports.LegalService=O;exports.LynkowError=C;exports.MediaHelperService=N;exports.PagesService=k;exports.PathsService=B;exports.ReviewsService=T;exports.SearchService=A;exports.SeoService=P;exports.SiteService=L;exports.TagsService=E;exports.browserOnly=be;exports.browserOnlyAsync=Re;exports.createClient=Be;exports.createLynkowClient=$e;exports.detectSiteTheme=w;exports.isBrowser=c;exports.isCategoryResolve=_e;exports.isContentResolve=Ae;exports.isLynkowError=Ce;exports.isServer=we;exports.onSiteThemeChange=$;//# sourceMappingURL=index.js.map
237
237
  //# sourceMappingURL=index.js.map