@localazy/cdn-client 1.5.7 → 1.5.9
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/browser/localazy-cdn-client.umd.min.js +1 -4
- package/dist/browser/localazy-cdn-client.umd.min.js.map +1 -1
- package/dist/localazy-cdn-client.js +1 -4
- package/dist/localazy-cdn-client.js.map +1 -1
- package/dist/localazy-cdn-client.min.js +1 -4
- package/dist/localazy-cdn-client.min.js.map +1 -1
- package/dist/node/localazy-cdn-client.cjs +1 -4
- package/dist/node/localazy-cdn-client.cjs.map +1 -1
- package/package.json +11 -11
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).LocalazyCDN={})}(this,(function(e){"use strict";
|
|
2
|
-
/* @localazy/cdn-client@1.5.7
|
|
3
|
-
* (c) 2025 Localazy <team@localazy.com>
|
|
4
|
-
* @license MIT */class t{context;constructor(e){this.context=e}async fetchLocale(e){return this.context.cache.has(e)?new Promise((t=>{t(this.context.cache.get(e))})):this.context.client.get(e.metafileLocale.uri)}async fetchMetafile(){return await this.context.client.get(this.context.metafile.params.jsonPath)}}class s{map;constructor(){this.map=new Map}get(e){return this.map.get(e)}has(e){return this.map.has(e)}set(e,t){this.map.set(e,t)}flush(){this.map=new Map}}const a=e=>"string"==typeof e,i=e=>void 0===e,l=e=>Array.isArray(e),r=e=>"[object Object]"===Object.prototype.toString.call(e),o=e=>[...new Set(e)],n=(e,t)=>{const s={};return e.filter((e=>{const a=t(e);return!Object.hasOwn(s,a)&&(s[a]=!0,!0)}))};class c{context;cacheAdapter;constructor(e){this.context=e,this.cacheAdapter=new s}setIfMissed(e){const{metafileFile:t,metafileLocale:s,data:a}=e,i=this.keyFromMetafile({metafileFile:t,metafileLocale:s});this.cacheAdapter.has(i)||this.cacheAdapter.set(i,a)}has(e){const t=this.keyFromMetafile(e);return this.cacheAdapter.has(t)}get(e){const t=this.keyFromMetafile(e);return this.cacheAdapter.get(t)}flush(){this.cacheAdapter.flush()}keyFromMetafile(e){const{metafileFile:t,metafileLocale:s}=e,a=[...o(t.productFlavors)].sort().join("-");return[this.context.metafile.params.cdnId,t.id,t.file,t.path,t.library,t.module,t.buildType,a,s.locale,s.timestamp.toString()].filter((e=>""!==e)).join("-")}}class h{context;constructor(e){this.context=e}createCdnResponse(e){const{requests:t,responses:s,hasSingleFileResponse:a,hasSingleLocaleResponse:i}=e;return 0===s.length||void 0===s[0]?{}:(this.cacheResponses(t,s),a&&i?s[0]:h.transformResponses(e))}cacheResponses(e,t){t.forEach(((t,s)=>{if(void 0!==e[s]){const{metafileFile:a,metafileLocale:i}=e[s];a&&i&&this.context.cache.setIfMissed({metafileFile:a,metafileLocale:i,data:t})}}))}static transformResponses(e){const{requests:t,responses:s,hasSingleFileResponse:a}=e;return s.reduce(((e,s,i)=>{if(void 0!==t[i]){const{metafileFile:l,metafileLocale:r}=t[i];l&&r&&(a?e[r.locale]=s:(e[l.id]||(e[l.id]={}),e[l.id][r.locale]=s))}return e}),{})}}class u{metafile;cdn;client;api;cache;responseFactory;constructor(e){this.metafile=e.metafileContext,this.cdn=e.cdn,this.client=e.client,this.api=new t(this),this.cache=new c(this),this.responseFactory=new h(this)}}class d{id;file;path;library;module;buildType;timestamp;productFlavors;locales;baseUrl;constructor(e){this.id=e.id,this.file=e.file,this.path=e.path,this.library=e.library,this.module=e.module,this.buildType=e.buildType,this.timestamp=e.timestamp,this.productFlavors=e.productFlavors,this.locales=e.locales,this.baseUrl=e.baseUrl}toCdnFile(){return{id:this.id,file:this.file,path:this.path,library:this.library,module:this.module,buildType:this.buildType,productFlavors:this.productFlavors,locales:this.locales.map((e=>({locale:e.locale,isBaseLocale:e.isBaseLocale,uri:`${this.baseUrl}${e.uri}`})))}}}class f{language;region;script;isRtl;name;localizedName;uri;timestamp;baseLocale;constructor(e,t){this.language=e.language,this.region=e.region,this.script=e.script,this.isRtl=e.isRtl,this.name=e.name,this.localizedName=e.localizedName,this.uri=e.uri,this.timestamp=e.timestamp,this.baseLocale=t}get locale(){return this.language&&this.region&&this.script?`${this.language}_${this.region}#${this.script}`:this.language&&this.script?`${this.language}#${this.script}`:this.language&&this.region?`${this.language}_${this.region}`:this.language}get isBaseLocale(){return this.locale===this.baseLocale}toCdnLocale(){return{locale:this.locale,isBaseLocale:this.isBaseLocale,language:this.language,region:this.region,script:this.script,isRtl:this.isRtl,name:this.name,localizedName:this.localizedName}}}class p{projectUrl;baseLocale;locales;timestamp;files;filesMap;constructor(e,t){this.projectUrl=e.projectUrl,this.timestamp=e.timestamp,this.files=p.filesFactory(e.files,e.baseLocale,t),this.filesMap=p.filesMapFactory(this.files),this.locales=p.localesFactory(this.files),this.baseLocale=this.locales.find((e=>e.isBaseLocale))}static createEmpty(e){return new p({projectUrl:"",baseLocale:"",timestamp:0,files:{}},e)}static filesFactory(e,t,s){return Object.keys(e).reduce(((a,i)=>{if(void 0!==e[i]){const l=e[i].locales.map((e=>new f(e,t)));a.push(new d({...e[i],id:i,locales:l,baseUrl:s.baseUrl}))}return a}),[])}static filesMapFactory(e){return e.reduce(((e,t)=>(e[t.id]=t,e)),{})}static localesFactory(e){const t=e.reduce(((e,t)=>(e.push(...t.locales.map((e=>e.toCdnLocale()))),e)),[]);return n(t,(e=>e.locale))}}class m{options;constructor(e){this.options=m.parseMetafileUrl(e)}get url(){return this.options.url}get baseUrl(){return this.options.baseUrl}get cdnId(){return this.options.cdnId}get jsonPath(){return this.options.jsonPath}static parseMetafileUrl(e){let t;try{t=new URL(e)}catch{throw new Error('Invalid param: "options.metafile" cannot be parsed as url.')}const s=/^\/(.*?)\/(.*?)\.(v2.json|js|ts)$/.exec(t.pathname);if(null===s||4!==s.length||void 0===s[1]||void 0===s[2])throw new Error('Invalid param: "options.metafile" contains invalid metafile url.');const a=s[1],i=s[2];return{url:e,baseUrl:t.origin,cdnId:a,jsonPath:`/${a}/${i}.v2.json`}}}class g{params;parsedData;data;constructor(e){this.params=new m(e.metafile),this.parsedData=null,this.data=p.createEmpty(this.params)}setMetafile(e){this.parsedData=e,this.data=new p(e,this.params)}}class w{baseUrl;constructor(e){this.baseUrl=e}async get(e){const t=await fetch(`${this.baseUrl}${e}`),s=t.headers.get("content-type"),a="application/json5"===s||"application/json"===s;if(t.status>=400)throw new Error(`Request failed with status code ${t.status.toString()}`);let i;return i=a?await t.json():await t.text(),i}}class x{context;constructor(e){this.context=e}}class y extends x{flush=()=>{this.context.cache.flush()}}class b extends x{get projectUrl(){return this.context.metafile.data.projectUrl}get baseLocale(){return this.context.metafile.data.baseLocale}get url(){return this.context.metafile.params.url}get files(){return this.context.metafile.data.files.map((e=>e.toCdnFile()))}locales=e=>{const{excludeBaseLocale:t}=e||{},{locales:s}=this.context.metafile.data;return t?s.filter((e=>!e.isBaseLocale)):s};refresh=async()=>{const e=await this.context.api.fetchMetafile();this.context.metafile.setMetafile(e)};switch=async e=>{this.context.metafile.params=new m(e.metafile),await this.refresh()}}class F{data;context;constructor(e){this.context=e.context,this.data=e.data||{}}}class L{files;localesMap;hasSingleFileResponse;hasSingleLocaleResponse;context;constructor(e){this.files=[],this.localesMap=new F({context:e}),this.hasSingleFileResponse=!1,this.hasSingleLocaleResponse=!1,this.context=e}async execute(){const e=this.getPromises(),t=e.map((e=>e[0])),s=e.map((e=>e[1])),a=await Promise.all(t);return this.context.responseFactory.createCdnResponse({requests:s,responses:a,localesMap:this.localesMap,hasSingleFileResponse:this.hasSingleFileResponse,hasSingleLocaleResponse:this.hasSingleLocaleResponse})}getPromises(){return this.files.reduce(((e,t)=>(void 0!==this.localesMap.data?.[t.id]&&e.push(...this.localesMap.data[t.id].map((e=>{const s={metafileFile:t,metafileLocale:e};return[this.context.api.fetchLocale(s),s]}))),e)),[])}}class M{context;request;constructor(e){this.context=e,this.request=new L(this.context)}addFiles(e){if(!(r(e)||a(e)||i(e)||l(e)))throw new Error('Invalid param: "request.files" must be object, array, string or undefined.');if(l(e)&&e.forEach((e=>{if(!r(e)&&!a(e))throw new Error('Invalid param: array "request.files" must contain objects or strings.')})),a(e)){this.request.hasSingleFileResponse=!0;const t=this.context.metafile.data.files.find((t=>t.id===e));if(!(t instanceof d))throw new Error(`File not found: "${e}".`);this.request.files=[t]}else if(i(e))this.request.files=[...this.context.metafile.data.files];else if(l(e))this.request.files=e.map((e=>{let t;if(a(e)){const s=this.context.metafile.data.files.find((t=>t.id===e));if(i(s))throw new Error(`File not found: "${e}".`);t=s}else{const s=this.context.metafile.data.files.find((t=>t.id===e.id));if(i(s))throw new Error(`File not found: "${e.id}".`);t=s}return t}));else if(r(e)){this.request.hasSingleFileResponse=!0;const t=this.context.metafile.data.files.find((t=>t.id===e.id));if(i(t))throw new Error(`File not found: "${e.id}".`);this.request.files=[t]}return this}addLocales(e,t){if(!(a(e)||i(e)||l(e)))throw new Error('Invalid param: "request.locales" must be array, string or undefined.');return l(e)&&e.forEach((e=>{if(!a(e))throw new Error('Invalid param: array "request.locales" must contain strings.')})),a(e)?(this.request.hasSingleLocaleResponse=!0,this.request.files.reduce(((t,s)=>(t.data[s.id]=s.locales.filter((t=>t.locale===e)),t)),this.request.localesMap)):i(e)?this.request.files.reduce(((e,s)=>(e.data[s.id]=t?s.locales.filter((e=>!e.isBaseLocale)):s.locales,e)),this.request.localesMap):l(e)&&this.request.files.reduce(((t,s)=>(t.data[s.id]=s.locales.filter((t=>e.includes(t.locale))),t)),this.request.localesMap),this}getCdnRequest(){const e=this.request;return this.request=new L(this.context),e}}class q{metafile;cache;context;static version="1.5.7";constructor(e){const t=new g(e),s=new w(t.params.baseUrl);this.context=new u({metafileContext:t,cdn:this,client:s}),this.metafile=new b(this.context),this.cache=new y(this.context)}fetch=async e=>{const{files:t,locales:s,excludeBaseLocale:a}=e||{};return new M(this.context).addFiles(t).addLocales(s,a).getCdnRequest().execute()};static async create(e){if(!e)throw new Error('Invalid param: missing required "options" parameter.');if(!a(e.metafile))throw new Error('Invalid param: "options.metafile" must be string.');const t=new q(e);return await t.metafile.refresh(),t}}e.Api=t,e.CdnBase=x,e.CdnCache=y,e.CdnClient=q,e.CdnMetafile=b,e.Context=u,e.FetchHttpAdapter=w,e.LocalesCache=c,e.LocalesMap=F,e.MemoryCacheAdapter=s,e.MetafileContext=g,e.MetafileData=p,e.MetafileFile=d,e.MetafileLocale=f,e.MetafileParams=m,e.Request=L,e.RequestBuilder=M,e.ResponseFactory=h,e.isArray=l,e.isPlainObject=r,e.isString=a,e.isUndefined=i,e.uniq=o,e.uniqBy=n,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).LocalazyCDN={})}(this,(function(e){"use strict";class t{context;constructor(e){this.context=e}async fetchLocale(e){return this.context.cache.has(e)?new Promise((t=>{t(this.context.cache.get(e))})):this.context.client.get(e.metafileLocale.uri)}async fetchMetafile(){return await this.context.client.get(this.context.metafile.params.jsonPath)}}class s{map;constructor(){this.map=new Map}get(e){return this.map.get(e)}has(e){return this.map.has(e)}set(e,t){this.map.set(e,t)}flush(){this.map=new Map}}const a=e=>"string"==typeof e,i=e=>void 0===e,l=e=>Array.isArray(e),r=e=>"[object Object]"===Object.prototype.toString.call(e),o=e=>[...new Set(e)],n=(e,t)=>{const s={};return e.filter((e=>{const a=t(e);return!Object.hasOwn(s,a)&&(s[a]=!0,!0)}))};class c{context;cacheAdapter;constructor(e){this.context=e,this.cacheAdapter=new s}setIfMissed(e){const{metafileFile:t,metafileLocale:s,data:a}=e,i=this.keyFromMetafile({metafileFile:t,metafileLocale:s});this.cacheAdapter.has(i)||this.cacheAdapter.set(i,a)}has(e){const t=this.keyFromMetafile(e);return this.cacheAdapter.has(t)}get(e){const t=this.keyFromMetafile(e);return this.cacheAdapter.get(t)}flush(){this.cacheAdapter.flush()}keyFromMetafile(e){const{metafileFile:t,metafileLocale:s}=e,a=[...o(t.productFlavors)].sort().join("-");return[this.context.metafile.params.cdnId,t.id,t.file,t.path,t.library,t.module,t.buildType,a,s.locale,s.timestamp.toString()].filter((e=>""!==e)).join("-")}}class h{context;constructor(e){this.context=e}createCdnResponse(e){const{requests:t,responses:s,hasSingleFileResponse:a,hasSingleLocaleResponse:i}=e;return 0===s.length||void 0===s[0]?{}:(this.cacheResponses(t,s),a&&i?s[0]:h.transformResponses(e))}cacheResponses(e,t){t.forEach(((t,s)=>{if(void 0!==e[s]){const{metafileFile:a,metafileLocale:i}=e[s];a&&i&&this.context.cache.setIfMissed({metafileFile:a,metafileLocale:i,data:t})}}))}static transformResponses(e){const{requests:t,responses:s,hasSingleFileResponse:a}=e;return s.reduce(((e,s,i)=>{if(void 0!==t[i]){const{metafileFile:l,metafileLocale:r}=t[i];l&&r&&(a?e[r.locale]=s:(e[l.id]||(e[l.id]={}),e[l.id][r.locale]=s))}return e}),{})}}class u{metafile;cdn;client;api;cache;responseFactory;constructor(e){this.metafile=e.metafileContext,this.cdn=e.cdn,this.client=e.client,this.api=new t(this),this.cache=new c(this),this.responseFactory=new h(this)}}class d{id;file;path;library;module;buildType;timestamp;productFlavors;locales;baseUrl;constructor(e){this.id=e.id,this.file=e.file,this.path=e.path,this.library=e.library,this.module=e.module,this.buildType=e.buildType,this.timestamp=e.timestamp,this.productFlavors=e.productFlavors,this.locales=e.locales,this.baseUrl=e.baseUrl}toCdnFile(){return{id:this.id,file:this.file,path:this.path,library:this.library,module:this.module,buildType:this.buildType,productFlavors:this.productFlavors,locales:this.locales.map((e=>({locale:e.locale,isBaseLocale:e.isBaseLocale,uri:`${this.baseUrl}${e.uri}`})))}}}class f{language;region;script;isRtl;name;localizedName;uri;timestamp;baseLocale;constructor(e,t){this.language=e.language,this.region=e.region,this.script=e.script,this.isRtl=e.isRtl,this.name=e.name,this.localizedName=e.localizedName,this.uri=e.uri,this.timestamp=e.timestamp,this.baseLocale=t}get locale(){return this.language&&this.region&&this.script?`${this.language}_${this.region}#${this.script}`:this.language&&this.script?`${this.language}#${this.script}`:this.language&&this.region?`${this.language}_${this.region}`:this.language}get isBaseLocale(){return this.locale===this.baseLocale}toCdnLocale(){return{locale:this.locale,isBaseLocale:this.isBaseLocale,language:this.language,region:this.region,script:this.script,isRtl:this.isRtl,name:this.name,localizedName:this.localizedName}}}class p{projectUrl;baseLocale;locales;timestamp;files;filesMap;constructor(e,t){this.projectUrl=e.projectUrl,this.timestamp=e.timestamp,this.files=p.filesFactory(e.files,e.baseLocale,t),this.filesMap=p.filesMapFactory(this.files),this.locales=p.localesFactory(this.files),this.baseLocale=this.locales.find((e=>e.isBaseLocale))}static createEmpty(e){return new p({projectUrl:"",baseLocale:"",timestamp:0,files:{}},e)}static filesFactory(e,t,s){return Object.keys(e).reduce(((a,i)=>{if(void 0!==e[i]){const l=e[i].locales.map((e=>new f(e,t)));a.push(new d({...e[i],id:i,locales:l,baseUrl:s.baseUrl}))}return a}),[])}static filesMapFactory(e){return e.reduce(((e,t)=>(e[t.id]=t,e)),{})}static localesFactory(e){const t=e.reduce(((e,t)=>(e.push(...t.locales.map((e=>e.toCdnLocale()))),e)),[]);return n(t,(e=>e.locale))}}class m{options;constructor(e){this.options=m.parseMetafileUrl(e)}get url(){return this.options.url}get baseUrl(){return this.options.baseUrl}get cdnId(){return this.options.cdnId}get jsonPath(){return this.options.jsonPath}static parseMetafileUrl(e){let t;try{t=new URL(e)}catch{throw new Error('Invalid param: "options.metafile" cannot be parsed as url.')}const s=/^\/(.*?)\/(.*?)\.(v2.json|js|ts)$/.exec(t.pathname);if(null===s||4!==s.length||void 0===s[1]||void 0===s[2])throw new Error('Invalid param: "options.metafile" contains invalid metafile url.');const a=s[1],i=s[2];return{url:e,baseUrl:t.origin,cdnId:a,jsonPath:`/${a}/${i}.v2.json`}}}class g{params;parsedData;data;constructor(e){this.params=new m(e.metafile),this.parsedData=null,this.data=p.createEmpty(this.params)}setMetafile(e){this.parsedData=e,this.data=new p(e,this.params)}}class w{baseUrl;constructor(e){this.baseUrl=e}async get(e){const t=await fetch(`${this.baseUrl}${e}`),s=t.headers.get("content-type"),a="application/json5"===s||"application/json"===s;if(t.status>=400)throw new Error(`Request failed with status code ${t.status.toString()}`);let i;return i=a?await t.json():await t.text(),i}}class x{context;constructor(e){this.context=e}}class y extends x{flush=()=>{this.context.cache.flush()}}class b extends x{get projectUrl(){return this.context.metafile.data.projectUrl}get baseLocale(){return this.context.metafile.data.baseLocale}get url(){return this.context.metafile.params.url}get files(){return this.context.metafile.data.files.map((e=>e.toCdnFile()))}locales=e=>{const{excludeBaseLocale:t}=e||{},{locales:s}=this.context.metafile.data;return t?s.filter((e=>!e.isBaseLocale)):s};refresh=async()=>{const e=await this.context.api.fetchMetafile();this.context.metafile.setMetafile(e)};switch=async e=>{this.context.metafile.params=new m(e.metafile),await this.refresh()}}class F{data;context;constructor(e){this.context=e.context,this.data=e.data||{}}}class L{files;localesMap;hasSingleFileResponse;hasSingleLocaleResponse;context;constructor(e){this.files=[],this.localesMap=new F({context:e}),this.hasSingleFileResponse=!1,this.hasSingleLocaleResponse=!1,this.context=e}async execute(){const e=this.getPromises(),t=e.map((e=>e[0])),s=e.map((e=>e[1])),a=await Promise.all(t);return this.context.responseFactory.createCdnResponse({requests:s,responses:a,localesMap:this.localesMap,hasSingleFileResponse:this.hasSingleFileResponse,hasSingleLocaleResponse:this.hasSingleLocaleResponse})}getPromises(){return this.files.reduce(((e,t)=>(void 0!==this.localesMap.data?.[t.id]&&e.push(...this.localesMap.data[t.id].map((e=>{const s={metafileFile:t,metafileLocale:e};return[this.context.api.fetchLocale(s),s]}))),e)),[])}}class M{context;request;constructor(e){this.context=e,this.request=new L(this.context)}addFiles(e){if(!(r(e)||a(e)||i(e)||l(e)))throw new Error('Invalid param: "request.files" must be object, array, string or undefined.');if(l(e)&&e.forEach((e=>{if(!r(e)&&!a(e))throw new Error('Invalid param: array "request.files" must contain objects or strings.')})),a(e)){this.request.hasSingleFileResponse=!0;const t=this.context.metafile.data.files.find((t=>t.id===e));if(!(t instanceof d))throw new Error(`File not found: "${e}".`);this.request.files=[t]}else if(i(e))this.request.files=[...this.context.metafile.data.files];else if(l(e))this.request.files=e.map((e=>{let t;if(a(e)){const s=this.context.metafile.data.files.find((t=>t.id===e));if(i(s))throw new Error(`File not found: "${e}".`);t=s}else{const s=this.context.metafile.data.files.find((t=>t.id===e.id));if(i(s))throw new Error(`File not found: "${e.id}".`);t=s}return t}));else if(r(e)){this.request.hasSingleFileResponse=!0;const t=this.context.metafile.data.files.find((t=>t.id===e.id));if(i(t))throw new Error(`File not found: "${e.id}".`);this.request.files=[t]}return this}addLocales(e,t){if(!(a(e)||i(e)||l(e)))throw new Error('Invalid param: "request.locales" must be array, string or undefined.');return l(e)&&e.forEach((e=>{if(!a(e))throw new Error('Invalid param: array "request.locales" must contain strings.')})),a(e)?(this.request.hasSingleLocaleResponse=!0,this.request.files.reduce(((t,s)=>(t.data[s.id]=s.locales.filter((t=>t.locale===e)),t)),this.request.localesMap)):i(e)?this.request.files.reduce(((e,s)=>(e.data[s.id]=t?s.locales.filter((e=>!e.isBaseLocale)):s.locales,e)),this.request.localesMap):l(e)&&this.request.files.reduce(((t,s)=>(t.data[s.id]=s.locales.filter((t=>e.includes(t.locale))),t)),this.request.localesMap),this}getCdnRequest(){const e=this.request;return this.request=new L(this.context),e}}class q{metafile;cache;context;static version="1.5.9";constructor(e){const t=new g(e),s=new w(t.params.baseUrl);this.context=new u({metafileContext:t,cdn:this,client:s}),this.metafile=new b(this.context),this.cache=new y(this.context)}fetch=async e=>{const{files:t,locales:s,excludeBaseLocale:a}=e||{};return new M(this.context).addFiles(t).addLocales(s,a).getCdnRequest().execute()};static async create(e){if(!e)throw new Error('Invalid param: missing required "options" parameter.');if(!a(e.metafile))throw new Error('Invalid param: "options.metafile" must be string.');const t=new q(e);return await t.metafile.refresh(),t}}e.Api=t,e.CdnBase=x,e.CdnCache=y,e.CdnClient=q,e.CdnMetafile=b,e.Context=u,e.FetchHttpAdapter=w,e.LocalesCache=c,e.LocalesMap=F,e.MemoryCacheAdapter=s,e.MetafileContext=g,e.MetafileData=p,e.MetafileFile=d,e.MetafileLocale=f,e.MetafileParams=m,e.Request=L,e.RequestBuilder=M,e.ResponseFactory=h,e.isArray=l,e.isPlainObject=r,e.isString=a,e.isUndefined=i,e.uniq=o,e.uniqBy=n,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
|
|
5
2
|
//# sourceMappingURL=localazy-cdn-client.umd.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localazy-cdn-client.umd.min.js","sources":["../../src/cdn/api/api.ts","../../src/cdn/cache/memory-cache-adapter.ts","../../src/cdn/utils.ts","../../src/cdn/cache/locales-cache.ts","../../src/cdn/response/response-factory.ts","../../src/cdn/context/context.ts","../../src/cdn/metafile/metafile-file.ts","../../src/cdn/metafile/metafile-locale.ts","../../src/cdn/metafile/metafile-data.ts","../../src/cdn/metafile/metafile-params.ts","../../src/cdn/context/metafile-context.ts","../../src/cdn/http/fetch-http-adapter.ts","../../src/cdn/methods/cdn-base.ts","../../src/cdn/methods/cdn-cache.ts","../../src/cdn/methods/cdn-metafile.ts","../../src/cdn/request/locales-map.ts","../../src/cdn/request/request.ts","../../src/cdn/request/request-builder.ts","../../src/cdn/cdn-client.ts"],"sourcesContent":["import type { Context } from '@/cdn/context/context.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\n\nexport class Api {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n\n public async fetchLocale(options: ApiLocaleRequest): Promise<object | string> {\n if (this.context.cache.has(options)) {\n return new Promise((resolve): void => {\n resolve(this.context.cache.get(options) as object | string);\n });\n }\n\n return this.context.client.get(options.metafileLocale.uri);\n }\n\n public async fetchMetafile(): Promise<IMetafile> {\n return (await this.context.client.get(this.context.metafile.params.jsonPath)) as IMetafile;\n }\n}\n","import type { ICacheAdapter } from '@/interfaces/i-cache-adapter.js';\n\nexport class MemoryCacheAdapter<K, V> implements ICacheAdapter<K, V> {\n protected map: Map<K, V>;\n\n constructor() {\n this.map = new Map();\n }\n\n public get(key: K): V | undefined {\n return this.map.get(key);\n }\n\n public has(key: K): boolean {\n return this.map.has(key);\n }\n\n public set(key: K, value: V): void {\n this.map.set(key, value);\n }\n\n public flush(): void {\n this.map = new Map();\n }\n}\n","export const isString = (value: unknown): value is string => typeof value === 'string';\n\nexport const isUndefined = (value: unknown): value is undefined => typeof value === 'undefined';\n\nexport const isArray = <T>(value: unknown): value is T[] => Array.isArray(value);\n\nexport const isPlainObject = (value: unknown): value is Record<string, unknown> =>\n Object.prototype.toString.call(value) === '[object Object]';\n\nexport const uniq = <T>(array: T[]): T[] => [...new Set(array)];\n\nexport const uniqBy = <T>(array: T[], predicate: (item: T) => string): T[] => {\n const seen: Record<string, boolean> = {};\n\n return array.filter((item: T): boolean => {\n const key: string = predicate(item);\n\n if (!Object.hasOwn(seen, key)) {\n seen[key] = true;\n\n return true;\n }\n\n return false;\n });\n};\n","import { MemoryCacheAdapter } from '@/cdn/cache/memory-cache-adapter.js';\nimport type { Context } from '@/cdn/context/context.js';\nimport { uniq } from '@/cdn/utils.js';\nimport type { ICacheAdapter } from '@/interfaces/i-cache-adapter.js';\nimport type { CacheGetLocalesRequest } from '@/types/cache-get-locales-request.js';\nimport type { CacheHasLocalesRequest } from '@/types/cache-has-locales-request.js';\nimport type { CacheKeyMetafileOptions } from '@/types/cache-key-metafile-options.js';\nimport type { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request.js';\n\nexport class LocalesCache {\n protected context: Context;\n\n protected cacheAdapter: ICacheAdapter<string, object | string>;\n\n constructor(context: Context) {\n this.context = context;\n this.cacheAdapter = new MemoryCacheAdapter();\n }\n\n public setIfMissed(options: CacheStoreLocalesRequest): void {\n const { metafileFile, metafileLocale, data }: CacheStoreLocalesRequest = options;\n\n const key: string = this.keyFromMetafile({\n metafileFile,\n metafileLocale,\n });\n\n if (!this.cacheAdapter.has(key)) {\n this.cacheAdapter.set(key, data);\n }\n }\n\n public has(options: CacheHasLocalesRequest): boolean {\n const key: string = this.keyFromMetafile(options);\n\n return this.cacheAdapter.has(key);\n }\n\n public get(options: CacheGetLocalesRequest): object | string | undefined {\n const key: string = this.keyFromMetafile(options);\n\n return this.cacheAdapter.get(key);\n }\n\n public flush(): void {\n this.cacheAdapter.flush();\n }\n\n protected keyFromMetafile(options: CacheKeyMetafileOptions): string {\n const { metafileFile, metafileLocale }: CacheKeyMetafileOptions = options;\n const productFlavors: string = [...uniq(metafileFile.productFlavors)].sort().join('-');\n\n const indices: string[] = [\n this.context.metafile.params.cdnId,\n metafileFile.id,\n metafileFile.file,\n metafileFile.path,\n metafileFile.library,\n metafileFile.module,\n metafileFile.buildType,\n productFlavors,\n metafileLocale.locale,\n metafileLocale.timestamp.toString(),\n ];\n\n return indices.filter((key: string): boolean => key !== '').join('-');\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\nimport type { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\nimport type { ResponseFactoryOptions } from '@/types/response-factory-options.js';\n\nexport class ResponseFactory {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n\n public createCdnResponse(options: ResponseFactoryOptions): CdnResponse {\n const {\n requests,\n responses,\n hasSingleFileResponse,\n hasSingleLocaleResponse,\n }: ResponseFactoryOptions = options;\n\n if (responses.length === 0 || typeof responses[0] === 'undefined') {\n return {};\n }\n\n this.cacheResponses(requests, responses);\n\n return hasSingleFileResponse && hasSingleLocaleResponse\n ? responses[0]\n : ResponseFactory.transformResponses(options);\n }\n\n protected cacheResponses(requests: ApiLocaleRequest[], responses: (object | string)[]): void {\n responses.forEach((response: object | string, index: number): void => {\n if (typeof requests[index] !== 'undefined') {\n const { metafileFile, metafileLocale }: Partial<CacheStoreLocalesRequest> = requests[index];\n\n if (metafileFile && metafileLocale) {\n this.context.cache.setIfMissed({ metafileFile, metafileLocale, data: response });\n }\n }\n });\n }\n\n protected static transformResponses(options: ResponseFactoryOptions): CdnResponse {\n const { requests, responses, hasSingleFileResponse }: ResponseFactoryOptions = options;\n\n return responses.reduce((acc: CdnResponse, cur: object | string, index: number) => {\n if (typeof requests[index] !== 'undefined') {\n const { metafileFile, metafileLocale }: Partial<CacheStoreLocalesRequest> = requests[index];\n\n if (metafileFile && metafileLocale) {\n if (hasSingleFileResponse) {\n // @ts-expect-error fix output type\n acc[metafileLocale.locale] = cur;\n } else {\n // @ts-expect-error fix output type\n if (!acc[metafileFile.id]) {\n // @ts-expect-error fix output type\n acc[metafileFile.id] = {};\n }\n\n // @ts-expect-error fix output type\n acc[metafileFile.id][metafileLocale.locale] = cur;\n }\n }\n }\n\n return acc;\n }, {});\n }\n}\n","import { Api } from '@/cdn/api/api.js';\nimport { LocalesCache } from '@/cdn/cache/locales-cache.js';\nimport type { CdnClient } from '@/cdn/cdn-client.js';\nimport type { MetafileContext } from '@/cdn/context/metafile-context.js';\nimport { ResponseFactory } from '@/cdn/response/response-factory.js';\nimport type { IHttpAdapter } from '@/interfaces/i-http-adapter.js';\nimport type { ContextOptions } from '@/types/context-options.js';\n\nexport class Context {\n public metafile: MetafileContext;\n\n public cdn: CdnClient;\n\n public client: IHttpAdapter;\n\n public api: Api;\n\n public cache: LocalesCache;\n\n public responseFactory: ResponseFactory;\n\n constructor(options: ContextOptions) {\n this.metafile = options.metafileContext;\n this.cdn = options.cdn;\n this.client = options.client;\n this.api = new Api(this);\n this.cache = new LocalesCache(this);\n this.responseFactory = new ResponseFactory(this);\n }\n}\n","import type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { IMetafileFile } from '@/interfaces/i-metafile-file.js';\nimport type { CdnFileLocale } from '@/types/cdn-file-locale.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\nimport type { MetafileFileOptions } from '@/types/metafile-file-options.js';\n\nexport class MetafileFile implements Omit<IMetafileFile, 'locales'> {\n public id: string;\n\n public file: string;\n\n public path: string;\n\n public library: string;\n\n public module: string;\n\n public buildType: string;\n\n public timestamp: number;\n\n public productFlavors: string[];\n\n public locales: MetafileLocale[];\n\n protected baseUrl: string;\n\n constructor(options: MetafileFileOptions) {\n this.id = options.id;\n this.file = options.file;\n this.path = options.path;\n this.library = options.library;\n this.module = options.module;\n this.buildType = options.buildType;\n this.timestamp = options.timestamp;\n this.productFlavors = options.productFlavors;\n this.locales = options.locales;\n this.baseUrl = options.baseUrl;\n }\n\n public toCdnFile(): CdnFile {\n return {\n id: this.id,\n file: this.file,\n path: this.path,\n library: this.library,\n module: this.module,\n buildType: this.buildType,\n productFlavors: this.productFlavors,\n locales: this.locales.map(\n (locale: MetafileLocale): CdnFileLocale => ({\n locale: locale.locale,\n isBaseLocale: locale.isBaseLocale,\n uri: `${this.baseUrl}${locale.uri}`,\n }),\n ),\n };\n }\n}\n","import type { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\n\nexport class MetafileLocale implements IMetafileFileLocale {\n public language: string;\n\n public region: string;\n\n public script: string;\n\n public isRtl: boolean;\n\n public name: string;\n\n public localizedName: string;\n\n public uri: string;\n\n public timestamp: number;\n\n protected baseLocale: string;\n\n constructor(options: IMetafileFileLocale, baseLocale: string) {\n this.language = options.language;\n this.region = options.region;\n this.script = options.script;\n this.isRtl = options.isRtl;\n this.name = options.name;\n this.localizedName = options.localizedName;\n this.uri = options.uri;\n this.timestamp = options.timestamp;\n this.baseLocale = baseLocale;\n }\n\n get locale(): string {\n if (this.language && this.region && this.script) {\n return `${this.language}_${this.region}#${this.script}`;\n }\n\n if (this.language && this.script) {\n return `${this.language}#${this.script}`;\n }\n\n if (this.language && this.region) {\n return `${this.language}_${this.region}`;\n }\n\n return this.language;\n }\n\n get isBaseLocale(): boolean {\n return this.locale === this.baseLocale;\n }\n\n public toCdnLocale(): CdnLocale {\n return {\n locale: this.locale,\n isBaseLocale: this.isBaseLocale,\n language: this.language,\n region: this.region,\n script: this.script,\n isRtl: this.isRtl,\n name: this.name,\n localizedName: this.localizedName,\n };\n }\n}\n","import { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport { uniqBy } from '@/cdn/utils.js';\nimport type { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale.js';\nimport type { IMetafileFiles } from '@/interfaces/i-metafile-files.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\nimport type { FilesMap } from '@/types/files-map.js';\nimport type { MetafileOptions } from '@/types/metafile-options.js';\n\nexport class MetafileData implements Omit<IMetafile, 'files' | 'baseLocale'> {\n public projectUrl: string;\n\n public baseLocale: CdnLocale;\n\n public locales: CdnLocale[];\n\n public timestamp: number;\n\n public files: MetafileFile[];\n\n public filesMap: FilesMap;\n\n constructor(options: MetafileOptions, params: MetafileParams) {\n this.projectUrl = options.projectUrl;\n this.timestamp = options.timestamp;\n this.files = MetafileData.filesFactory(options.files, options.baseLocale, params);\n this.filesMap = MetafileData.filesMapFactory(this.files);\n this.locales = MetafileData.localesFactory(this.files);\n this.baseLocale = this.locales.find((locale: CdnLocale) => locale.isBaseLocale) as CdnLocale;\n }\n\n public static createEmpty(params: MetafileParams): MetafileData {\n return new MetafileData(\n {\n projectUrl: '',\n baseLocale: '',\n timestamp: 0,\n files: {},\n },\n params,\n );\n }\n\n protected static filesFactory(\n files: IMetafileFiles,\n baseLocale: string,\n params: MetafileParams,\n ): MetafileFile[] {\n return Object.keys(files).reduce((acc: MetafileFile[], cur: string) => {\n if (typeof files[cur] !== 'undefined') {\n const locales: MetafileLocale[] = files[cur].locales.map(\n (locale: IMetafileFileLocale) => new MetafileLocale(locale, baseLocale),\n );\n\n acc.push(\n new MetafileFile({\n ...files[cur],\n id: cur,\n locales,\n baseUrl: params.baseUrl,\n }),\n );\n }\n\n return acc;\n }, []);\n }\n\n protected static filesMapFactory(files: MetafileFile[]): FilesMap {\n return files.reduce((acc: FilesMap, cur: MetafileFile) => {\n acc[cur.id] = cur;\n\n return acc;\n }, {});\n }\n\n protected static localesFactory(files: MetafileFile[]): CdnLocale[] {\n const locales: CdnLocale[] = files.reduce((acc: CdnLocale[], cur: MetafileFile) => {\n acc.push(...cur.locales.map((locale: MetafileLocale): CdnLocale => locale.toCdnLocale()));\n return acc;\n }, []);\n\n return uniqBy(locales, (cdnLocale: CdnLocale): string => cdnLocale.locale);\n }\n}\n","import type { IMetafileParams } from '@/interfaces/i-metafile-params.js';\n\nexport class MetafileParams implements IMetafileParams {\n protected options: IMetafileParams;\n\n constructor(metafileUrl: string) {\n this.options = MetafileParams.parseMetafileUrl(metafileUrl);\n }\n\n get url(): string {\n return this.options.url;\n }\n\n get baseUrl(): string {\n return this.options.baseUrl;\n }\n\n get cdnId(): string {\n return this.options.cdnId;\n }\n\n get jsonPath(): string {\n return this.options.jsonPath;\n }\n\n protected static parseMetafileUrl(metafileUrl: string): IMetafileParams {\n let url: URL;\n\n try {\n url = new URL(metafileUrl);\n } catch {\n throw new Error('Invalid param: \"options.metafile\" cannot be parsed as url.');\n }\n\n const matches: string[] | null = /^\\/(.*?)\\/(.*?)\\.(v2.json|js|ts)$/.exec(url.pathname);\n\n if (\n matches === null ||\n matches.length !== 4 ||\n typeof matches[1] === 'undefined' ||\n typeof matches[2] === 'undefined'\n ) {\n throw new Error('Invalid param: \"options.metafile\" contains invalid metafile url.');\n }\n\n const cdnId: string = matches[1];\n const tagId: string = matches[2];\n\n return {\n url: metafileUrl,\n baseUrl: url.origin,\n cdnId,\n jsonPath: `/${cdnId}/${tagId}.v2.json`,\n };\n }\n}\n","import { MetafileData } from '@/cdn/metafile/metafile-data.js';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\n\nexport class MetafileContext {\n public params: MetafileParams;\n\n public parsedData: IMetafile | null;\n\n public data: MetafileData;\n\n constructor(options: CdnClientOptions) {\n this.params = new MetafileParams(options.metafile);\n this.parsedData = null;\n this.data = MetafileData.createEmpty(this.params);\n }\n\n public setMetafile(metafile: IMetafile): void {\n this.parsedData = metafile;\n\n this.data = new MetafileData(metafile, this.params);\n }\n}\n","import type { IHttpAdapter } from '@/interfaces/i-http-adapter.js';\n\nexport class FetchHttpAdapter implements IHttpAdapter {\n protected baseUrl: string;\n\n constructor(baseUrl: string) {\n this.baseUrl = baseUrl;\n }\n\n async get(url: string): Promise<string | object> {\n const response: Response = await fetch(`${this.baseUrl}${url}`);\n const contentType: string | null = response.headers.get('content-type');\n const isJson: boolean =\n contentType === 'application/json5' || contentType === 'application/json';\n\n if (response.status >= 400) {\n throw new Error(`Request failed with status code ${response.status.toString()}`);\n }\n\n let result: string | object;\n\n if (isJson) {\n result = (await response.json()) as object;\n } else {\n result = await response.text();\n }\n\n return result;\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\n\nexport abstract class CdnBase {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n}\n","import { CdnBase } from '@/cdn/methods/cdn-base.js';\n\nexport class CdnCache extends CdnBase {\n public flush = (): void => {\n this.context.cache.flush();\n };\n}\n","import type { MetafileData } from '@/cdn/metafile/metafile-data.js';\nimport type { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport { CdnBase } from '@/cdn/methods/cdn-base.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\nimport type { CdnLocalesOptions } from '@/types/cdn-locales-options.js';\n\nexport class CdnMetafile extends CdnBase {\n get projectUrl(): string {\n return this.context.metafile.data.projectUrl;\n }\n\n get baseLocale(): CdnLocale {\n return this.context.metafile.data.baseLocale;\n }\n\n get url(): string {\n return this.context.metafile.params.url;\n }\n\n get files(): CdnFile[] {\n return this.context.metafile.data.files.map((file: MetafileFile): CdnFile => file.toCdnFile());\n }\n\n public locales = (options?: CdnLocalesOptions): CdnLocale[] => {\n const { excludeBaseLocale }: CdnLocalesOptions = options || {};\n const { locales }: MetafileData = this.context.metafile.data;\n\n return excludeBaseLocale\n ? locales.filter((cdnLocale: CdnLocale): boolean => !cdnLocale.isBaseLocale)\n : locales;\n };\n\n public refresh = async (): Promise<void> => {\n const response: IMetafile = await this.context.api.fetchMetafile();\n\n this.context.metafile.setMetafile(response);\n };\n\n public switch = async (options: CdnClientOptions): Promise<void> => {\n this.context.metafile.params = new MetafileParams(options.metafile);\n\n await this.refresh();\n };\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { LocalesMapData } from '@/types/locales-map-data.js';\nimport type { LocalesMapOptions } from '@/types/locales-map-options.js';\n\nexport class LocalesMap {\n public data: LocalesMapData;\n\n protected context: Context;\n\n constructor(options: LocalesMapOptions) {\n this.context = options.context;\n this.data = options.data || {};\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport { LocalesMap } from '@/cdn/request/locales-map.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\n\nexport class Request {\n public files: MetafileFile[];\n\n public localesMap: LocalesMap;\n\n public hasSingleFileResponse: boolean;\n\n public hasSingleLocaleResponse: boolean;\n\n protected context: Context;\n\n constructor(context: Context) {\n this.files = [];\n this.localesMap = new LocalesMap({ context });\n this.hasSingleFileResponse = false;\n this.hasSingleLocaleResponse = false;\n this.context = context;\n }\n\n public async execute(): Promise<CdnResponse> {\n const payload: [Promise<string | object>, ApiLocaleRequest][] = this.getPromises();\n const promises: Promise<string | object>[] = payload.map(\n (item: [Promise<string | object>, ApiLocaleRequest]) => item[0],\n );\n const requests: ApiLocaleRequest[] = payload.map(\n (item: [Promise<string | object>, ApiLocaleRequest]) => item[1],\n );\n const responses: (string | object)[] = await Promise.all(promises);\n\n return this.context.responseFactory.createCdnResponse({\n requests,\n responses,\n localesMap: this.localesMap,\n hasSingleFileResponse: this.hasSingleFileResponse,\n hasSingleLocaleResponse: this.hasSingleLocaleResponse,\n });\n }\n\n protected getPromises(): [Promise<string | object>, ApiLocaleRequest][] {\n return this.files.reduce(\n (acc: [Promise<string | object>, ApiLocaleRequest][], cur: MetafileFile) => {\n if (typeof this.localesMap.data?.[cur.id] !== 'undefined') {\n acc.push(\n // @ts-expect-error TODO fix type\n ...this.localesMap.data[cur.id].map(\n (metafileLocale: MetafileLocale): [Promise<string | object>, ApiLocaleRequest] => {\n const request: ApiLocaleRequest = {\n metafileFile: cur,\n metafileLocale,\n };\n\n return [this.context.api.fetchLocale(request), request];\n },\n ),\n );\n }\n return acc;\n },\n [],\n );\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { LocalesMap } from '@/cdn/request/locales-map.js';\nimport { Request } from '@/cdn/request/request.js';\nimport { isArray, isPlainObject, isString, isUndefined } from '@/cdn/utils.js';\nimport type { IRequestBuilder } from '@/interfaces/i-request-builder.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\n\nexport class RequestBuilder implements IRequestBuilder {\n protected context: Context;\n\n protected request: Request;\n\n constructor(context: Context) {\n this.context = context;\n this.request = new Request(this.context);\n }\n\n public addFiles(files?: (CdnFile | string)[] | CdnFile | string): this {\n if (!(isPlainObject(files) || isString(files) || isUndefined(files) || isArray(files))) {\n throw new Error('Invalid param: \"request.files\" must be object, array, string or undefined.');\n }\n\n if (isArray(files)) {\n files.forEach((i: CdnFile | string): void => {\n if (!(isPlainObject(i) || isString(i))) {\n throw new Error('Invalid param: array \"request.files\" must contain objects or strings.');\n }\n });\n }\n\n if (isString(files)) {\n this.request.hasSingleFileResponse = true;\n\n const file: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === files,\n );\n\n if (!(file instanceof MetafileFile)) {\n throw new Error(`File not found: \"${files}\".`);\n }\n\n this.request.files = [file];\n } else if (isUndefined(files)) {\n this.request.files = [...this.context.metafile.data.files];\n } else if (isArray(files)) {\n this.request.files = files.map((file: CdnFile | string): MetafileFile => {\n let metafileFile: MetafileFile;\n\n if (isString(file)) {\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === file,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${file}\".`);\n }\n\n metafileFile = foundFile;\n } else {\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === file.id,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${file.id}\".`);\n }\n\n metafileFile = foundFile;\n }\n\n return metafileFile;\n });\n } else if (isPlainObject(files)) {\n this.request.hasSingleFileResponse = true;\n\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === files.id,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${files.id}\".`);\n }\n\n this.request.files = [foundFile];\n }\n\n return this;\n }\n\n public addLocales(locales?: string[] | string, excludeBaseLocale?: boolean): this {\n if (!(isString(locales) || isUndefined(locales) || isArray(locales))) {\n throw new Error('Invalid param: \"request.locales\" must be array, string or undefined.');\n }\n\n if (isArray(locales)) {\n locales.forEach((i: MetafileFile | string): void => {\n if (!isString(i)) {\n throw new Error('Invalid param: array \"request.locales\" must contain strings.');\n }\n });\n }\n\n if (isString(locales)) {\n this.request.hasSingleLocaleResponse = true;\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = cur.locales.filter(\n (metafileLocale: MetafileLocale): boolean => metafileLocale.locale === locales,\n );\n\n return acc;\n }, this.request.localesMap);\n } else if (isUndefined(locales)) {\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = excludeBaseLocale\n ? cur.locales.filter(\n (metafileLocale: MetafileLocale): boolean => !metafileLocale.isBaseLocale,\n )\n : cur.locales;\n\n return acc;\n }, this.request.localesMap);\n } else if (isArray(locales)) {\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = cur.locales.filter((metafileLocale: MetafileLocale) =>\n locales.includes(metafileLocale.locale),\n );\n\n return acc;\n }, this.request.localesMap);\n }\n\n return this;\n }\n\n public getCdnRequest(): Request {\n const result: Request = this.request;\n this.request = new Request(this.context);\n return result;\n }\n}\n","import { Context } from '@/cdn/context/context.js';\nimport { MetafileContext } from '@/cdn/context/metafile-context.js';\nimport { FetchHttpAdapter } from '@/cdn/http/fetch-http-adapter.js';\nimport { CdnCache } from '@/cdn/methods/cdn-cache.js';\nimport { CdnMetafile } from '@/cdn/methods/cdn-metafile.js';\nimport { RequestBuilder } from '@/cdn/request/request-builder.js';\nimport { isString } from '@/cdn/utils.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\nimport type { CdnFetchOptions } from '@/types/cdn-fetch-options.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\n\nexport class CdnClient {\n public metafile: CdnMetafile;\n\n public cache: CdnCache;\n\n protected context: Context;\n\n public static version = '__CLIENT_VERSION__';\n\n protected constructor(options: CdnClientOptions) {\n const metafileContext: MetafileContext = new MetafileContext(options);\n const client: FetchHttpAdapter = new FetchHttpAdapter(metafileContext.params.baseUrl);\n\n this.context = new Context({ metafileContext, cdn: this, client });\n this.metafile = new CdnMetafile(this.context);\n this.cache = new CdnCache(this.context);\n }\n\n public fetch = async (options?: CdnFetchOptions): Promise<CdnResponse> => {\n const { files, locales, excludeBaseLocale }: CdnFetchOptions = options || {};\n const requestBuilder: RequestBuilder = new RequestBuilder(this.context)\n .addFiles(files)\n .addLocales(locales, excludeBaseLocale);\n\n return requestBuilder.getCdnRequest().execute();\n };\n\n public static async create(options: CdnClientOptions): Promise<CdnClient> {\n if (!options) {\n throw new Error('Invalid param: missing required \"options\" parameter.');\n }\n\n if (!isString(options.metafile)) {\n throw new Error('Invalid param: \"options.metafile\" must be string.');\n }\n\n const cdn: CdnClient = new CdnClient(options);\n\n await cdn.metafile.refresh();\n\n return cdn;\n }\n}\n"],"names":["Api","context","constructor","this","fetchLocale","options","cache","has","Promise","resolve","get","client","metafileLocale","uri","fetchMetafile","metafile","params","jsonPath","MemoryCacheAdapter","map","Map","key","set","value","flush","isString","isUndefined","isArray","Array","isPlainObject","Object","prototype","toString","call","uniq","array","Set","uniqBy","predicate","seen","filter","item","hasOwn","LocalesCache","cacheAdapter","setIfMissed","metafileFile","data","keyFromMetafile","productFlavors","sort","join","cdnId","id","file","path","library","module","buildType","locale","timestamp","ResponseFactory","createCdnResponse","requests","responses","hasSingleFileResponse","hasSingleLocaleResponse","length","cacheResponses","transformResponses","forEach","response","index","reduce","acc","cur","Context","cdn","api","responseFactory","metafileContext","MetafileFile","locales","baseUrl","toCdnFile","isBaseLocale","MetafileLocale","language","region","script","isRtl","name","localizedName","baseLocale","toCdnLocale","MetafileData","projectUrl","files","filesMap","filesFactory","filesMapFactory","localesFactory","find","createEmpty","keys","push","cdnLocale","MetafileParams","metafileUrl","parseMetafileUrl","url","URL","Error","matches","exec","pathname","tagId","origin","MetafileContext","parsedData","setMetafile","FetchHttpAdapter","fetch","contentType","headers","isJson","status","result","json","text","CdnBase","CdnCache","CdnMetafile","excludeBaseLocale","refresh","async","switch","LocalesMap","Request","localesMap","execute","payload","getPromises","promises","all","request","RequestBuilder","addFiles","i","foundFile","addLocales","includes","getCdnRequest","CdnClient","static","create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H,EAAYjI,KAAKF,SACrCE,KAAKG,MAAQ,IAAI6H,EAAShI,KAAKF,QACjC,CAEOyH,MAAQa,MAAOlI,IACpB,MAAM4F,MAAEA,EAAAf,QAAOA,EAAAmD,kBAASA,GAAuChI,GAAW,CAAA,EAK1E,OAJuC,IAAI6I,EAAe/I,KAAKF,SAC5DkJ,SAASlD,GACTqD,WAAWpE,EAASmD,GAEDmB,gBAAgBZ,SAAA,EAGxC,mBAAoBe,CAAOtJ,GACzB,IAAKA,EACH,MAAM,IAAI2G,MAAM,wDAGlB,IAAKvF,EAASpB,EAAQU,UACpB,MAAM,IAAIiG,MAAM,qDAGlB,MAAMnC,EAAiB,IAAI4E,EAAUpJ,GAIrC,aAFMwE,EAAI9D,SAASuH,UAEZzD,CACT"}
|
|
1
|
+
{"version":3,"file":"localazy-cdn-client.umd.min.js","sources":["../../src/cdn/api/api.ts","../../src/cdn/cache/memory-cache-adapter.ts","../../src/cdn/utils.ts","../../src/cdn/cache/locales-cache.ts","../../src/cdn/response/response-factory.ts","../../src/cdn/context/context.ts","../../src/cdn/metafile/metafile-file.ts","../../src/cdn/metafile/metafile-locale.ts","../../src/cdn/metafile/metafile-data.ts","../../src/cdn/metafile/metafile-params.ts","../../src/cdn/context/metafile-context.ts","../../src/cdn/http/fetch-http-adapter.ts","../../src/cdn/methods/cdn-base.ts","../../src/cdn/methods/cdn-cache.ts","../../src/cdn/methods/cdn-metafile.ts","../../src/cdn/request/locales-map.ts","../../src/cdn/request/request.ts","../../src/cdn/request/request-builder.ts","../../src/cdn/cdn-client.ts"],"sourcesContent":["import type { Context } from '@/cdn/context/context.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\n\nexport class Api {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n\n public async fetchLocale(options: ApiLocaleRequest): Promise<object | string> {\n if (this.context.cache.has(options)) {\n return new Promise((resolve): void => {\n resolve(this.context.cache.get(options) as object | string);\n });\n }\n\n return this.context.client.get(options.metafileLocale.uri);\n }\n\n public async fetchMetafile(): Promise<IMetafile> {\n return (await this.context.client.get(this.context.metafile.params.jsonPath)) as IMetafile;\n }\n}\n","import type { ICacheAdapter } from '@/interfaces/i-cache-adapter.js';\n\nexport class MemoryCacheAdapter<K, V> implements ICacheAdapter<K, V> {\n protected map: Map<K, V>;\n\n constructor() {\n this.map = new Map();\n }\n\n public get(key: K): V | undefined {\n return this.map.get(key);\n }\n\n public has(key: K): boolean {\n return this.map.has(key);\n }\n\n public set(key: K, value: V): void {\n this.map.set(key, value);\n }\n\n public flush(): void {\n this.map = new Map();\n }\n}\n","export const isString = (value: unknown): value is string => typeof value === 'string';\n\nexport const isUndefined = (value: unknown): value is undefined => typeof value === 'undefined';\n\nexport const isArray = <T>(value: unknown): value is T[] => Array.isArray(value);\n\nexport const isPlainObject = (value: unknown): value is Record<string, unknown> =>\n Object.prototype.toString.call(value) === '[object Object]';\n\nexport const uniq = <T>(array: T[]): T[] => [...new Set(array)];\n\nexport const uniqBy = <T>(array: T[], predicate: (item: T) => string): T[] => {\n const seen: Record<string, boolean> = {};\n\n return array.filter((item: T): boolean => {\n const key: string = predicate(item);\n\n if (!Object.hasOwn(seen, key)) {\n seen[key] = true;\n\n return true;\n }\n\n return false;\n });\n};\n","import { MemoryCacheAdapter } from '@/cdn/cache/memory-cache-adapter.js';\nimport type { Context } from '@/cdn/context/context.js';\nimport { uniq } from '@/cdn/utils.js';\nimport type { ICacheAdapter } from '@/interfaces/i-cache-adapter.js';\nimport type { CacheGetLocalesRequest } from '@/types/cache-get-locales-request.js';\nimport type { CacheHasLocalesRequest } from '@/types/cache-has-locales-request.js';\nimport type { CacheKeyMetafileOptions } from '@/types/cache-key-metafile-options.js';\nimport type { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request.js';\n\nexport class LocalesCache {\n protected context: Context;\n\n protected cacheAdapter: ICacheAdapter<string, object | string>;\n\n constructor(context: Context) {\n this.context = context;\n this.cacheAdapter = new MemoryCacheAdapter();\n }\n\n public setIfMissed(options: CacheStoreLocalesRequest): void {\n const { metafileFile, metafileLocale, data }: CacheStoreLocalesRequest = options;\n\n const key: string = this.keyFromMetafile({\n metafileFile,\n metafileLocale,\n });\n\n if (!this.cacheAdapter.has(key)) {\n this.cacheAdapter.set(key, data);\n }\n }\n\n public has(options: CacheHasLocalesRequest): boolean {\n const key: string = this.keyFromMetafile(options);\n\n return this.cacheAdapter.has(key);\n }\n\n public get(options: CacheGetLocalesRequest): object | string | undefined {\n const key: string = this.keyFromMetafile(options);\n\n return this.cacheAdapter.get(key);\n }\n\n public flush(): void {\n this.cacheAdapter.flush();\n }\n\n protected keyFromMetafile(options: CacheKeyMetafileOptions): string {\n const { metafileFile, metafileLocale }: CacheKeyMetafileOptions = options;\n const productFlavors: string = [...uniq(metafileFile.productFlavors)].sort().join('-');\n\n const indices: string[] = [\n this.context.metafile.params.cdnId,\n metafileFile.id,\n metafileFile.file,\n metafileFile.path,\n metafileFile.library,\n metafileFile.module,\n metafileFile.buildType,\n productFlavors,\n metafileLocale.locale,\n metafileLocale.timestamp.toString(),\n ];\n\n return indices.filter((key: string): boolean => key !== '').join('-');\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\nimport type { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\nimport type { ResponseFactoryOptions } from '@/types/response-factory-options.js';\n\nexport class ResponseFactory {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n\n public createCdnResponse(options: ResponseFactoryOptions): CdnResponse {\n const {\n requests,\n responses,\n hasSingleFileResponse,\n hasSingleLocaleResponse,\n }: ResponseFactoryOptions = options;\n\n if (responses.length === 0 || typeof responses[0] === 'undefined') {\n return {};\n }\n\n this.cacheResponses(requests, responses);\n\n return hasSingleFileResponse && hasSingleLocaleResponse\n ? responses[0]\n : ResponseFactory.transformResponses(options);\n }\n\n protected cacheResponses(requests: ApiLocaleRequest[], responses: (object | string)[]): void {\n responses.forEach((response: object | string, index: number): void => {\n if (typeof requests[index] !== 'undefined') {\n const { metafileFile, metafileLocale }: Partial<CacheStoreLocalesRequest> = requests[index];\n\n if (metafileFile && metafileLocale) {\n this.context.cache.setIfMissed({ metafileFile, metafileLocale, data: response });\n }\n }\n });\n }\n\n protected static transformResponses(options: ResponseFactoryOptions): CdnResponse {\n const { requests, responses, hasSingleFileResponse }: ResponseFactoryOptions = options;\n\n return responses.reduce((acc: CdnResponse, cur: object | string, index: number) => {\n if (typeof requests[index] !== 'undefined') {\n const { metafileFile, metafileLocale }: Partial<CacheStoreLocalesRequest> = requests[index];\n\n if (metafileFile && metafileLocale) {\n if (hasSingleFileResponse) {\n // @ts-expect-error fix output type\n acc[metafileLocale.locale] = cur;\n } else {\n // @ts-expect-error fix output type\n if (!acc[metafileFile.id]) {\n // @ts-expect-error fix output type\n acc[metafileFile.id] = {};\n }\n\n // @ts-expect-error fix output type\n acc[metafileFile.id][metafileLocale.locale] = cur;\n }\n }\n }\n\n return acc;\n }, {});\n }\n}\n","import { Api } from '@/cdn/api/api.js';\nimport { LocalesCache } from '@/cdn/cache/locales-cache.js';\nimport type { CdnClient } from '@/cdn/cdn-client.js';\nimport type { MetafileContext } from '@/cdn/context/metafile-context.js';\nimport { ResponseFactory } from '@/cdn/response/response-factory.js';\nimport type { IHttpAdapter } from '@/interfaces/i-http-adapter.js';\nimport type { ContextOptions } from '@/types/context-options.js';\n\nexport class Context {\n public metafile: MetafileContext;\n\n public cdn: CdnClient;\n\n public client: IHttpAdapter;\n\n public api: Api;\n\n public cache: LocalesCache;\n\n public responseFactory: ResponseFactory;\n\n constructor(options: ContextOptions) {\n this.metafile = options.metafileContext;\n this.cdn = options.cdn;\n this.client = options.client;\n this.api = new Api(this);\n this.cache = new LocalesCache(this);\n this.responseFactory = new ResponseFactory(this);\n }\n}\n","import type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { IMetafileFile } from '@/interfaces/i-metafile-file.js';\nimport type { CdnFileLocale } from '@/types/cdn-file-locale.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\nimport type { MetafileFileOptions } from '@/types/metafile-file-options.js';\n\nexport class MetafileFile implements Omit<IMetafileFile, 'locales'> {\n public id: string;\n\n public file: string;\n\n public path: string;\n\n public library: string;\n\n public module: string;\n\n public buildType: string;\n\n public timestamp: number;\n\n public productFlavors: string[];\n\n public locales: MetafileLocale[];\n\n protected baseUrl: string;\n\n constructor(options: MetafileFileOptions) {\n this.id = options.id;\n this.file = options.file;\n this.path = options.path;\n this.library = options.library;\n this.module = options.module;\n this.buildType = options.buildType;\n this.timestamp = options.timestamp;\n this.productFlavors = options.productFlavors;\n this.locales = options.locales;\n this.baseUrl = options.baseUrl;\n }\n\n public toCdnFile(): CdnFile {\n return {\n id: this.id,\n file: this.file,\n path: this.path,\n library: this.library,\n module: this.module,\n buildType: this.buildType,\n productFlavors: this.productFlavors,\n locales: this.locales.map(\n (locale: MetafileLocale): CdnFileLocale => ({\n locale: locale.locale,\n isBaseLocale: locale.isBaseLocale,\n uri: `${this.baseUrl}${locale.uri}`,\n }),\n ),\n };\n }\n}\n","import type { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\n\nexport class MetafileLocale implements IMetafileFileLocale {\n public language: string;\n\n public region: string;\n\n public script: string;\n\n public isRtl: boolean;\n\n public name: string;\n\n public localizedName: string;\n\n public uri: string;\n\n public timestamp: number;\n\n protected baseLocale: string;\n\n constructor(options: IMetafileFileLocale, baseLocale: string) {\n this.language = options.language;\n this.region = options.region;\n this.script = options.script;\n this.isRtl = options.isRtl;\n this.name = options.name;\n this.localizedName = options.localizedName;\n this.uri = options.uri;\n this.timestamp = options.timestamp;\n this.baseLocale = baseLocale;\n }\n\n get locale(): string {\n if (this.language && this.region && this.script) {\n return `${this.language}_${this.region}#${this.script}`;\n }\n\n if (this.language && this.script) {\n return `${this.language}#${this.script}`;\n }\n\n if (this.language && this.region) {\n return `${this.language}_${this.region}`;\n }\n\n return this.language;\n }\n\n get isBaseLocale(): boolean {\n return this.locale === this.baseLocale;\n }\n\n public toCdnLocale(): CdnLocale {\n return {\n locale: this.locale,\n isBaseLocale: this.isBaseLocale,\n language: this.language,\n region: this.region,\n script: this.script,\n isRtl: this.isRtl,\n name: this.name,\n localizedName: this.localizedName,\n };\n }\n}\n","import { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport { uniqBy } from '@/cdn/utils.js';\nimport type { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale.js';\nimport type { IMetafileFiles } from '@/interfaces/i-metafile-files.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\nimport type { FilesMap } from '@/types/files-map.js';\nimport type { MetafileOptions } from '@/types/metafile-options.js';\n\nexport class MetafileData implements Omit<IMetafile, 'files' | 'baseLocale'> {\n public projectUrl: string;\n\n public baseLocale: CdnLocale;\n\n public locales: CdnLocale[];\n\n public timestamp: number;\n\n public files: MetafileFile[];\n\n public filesMap: FilesMap;\n\n constructor(options: MetafileOptions, params: MetafileParams) {\n this.projectUrl = options.projectUrl;\n this.timestamp = options.timestamp;\n this.files = MetafileData.filesFactory(options.files, options.baseLocale, params);\n this.filesMap = MetafileData.filesMapFactory(this.files);\n this.locales = MetafileData.localesFactory(this.files);\n this.baseLocale = this.locales.find((locale: CdnLocale) => locale.isBaseLocale) as CdnLocale;\n }\n\n public static createEmpty(params: MetafileParams): MetafileData {\n return new MetafileData(\n {\n projectUrl: '',\n baseLocale: '',\n timestamp: 0,\n files: {},\n },\n params,\n );\n }\n\n protected static filesFactory(\n files: IMetafileFiles,\n baseLocale: string,\n params: MetafileParams,\n ): MetafileFile[] {\n return Object.keys(files).reduce((acc: MetafileFile[], cur: string) => {\n if (typeof files[cur] !== 'undefined') {\n const locales: MetafileLocale[] = files[cur].locales.map(\n (locale: IMetafileFileLocale) => new MetafileLocale(locale, baseLocale),\n );\n\n acc.push(\n new MetafileFile({\n ...files[cur],\n id: cur,\n locales,\n baseUrl: params.baseUrl,\n }),\n );\n }\n\n return acc;\n }, []);\n }\n\n protected static filesMapFactory(files: MetafileFile[]): FilesMap {\n return files.reduce((acc: FilesMap, cur: MetafileFile) => {\n acc[cur.id] = cur;\n\n return acc;\n }, {});\n }\n\n protected static localesFactory(files: MetafileFile[]): CdnLocale[] {\n const locales: CdnLocale[] = files.reduce((acc: CdnLocale[], cur: MetafileFile) => {\n acc.push(...cur.locales.map((locale: MetafileLocale): CdnLocale => locale.toCdnLocale()));\n return acc;\n }, []);\n\n return uniqBy(locales, (cdnLocale: CdnLocale): string => cdnLocale.locale);\n }\n}\n","import type { IMetafileParams } from '@/interfaces/i-metafile-params.js';\n\nexport class MetafileParams implements IMetafileParams {\n protected options: IMetafileParams;\n\n constructor(metafileUrl: string) {\n this.options = MetafileParams.parseMetafileUrl(metafileUrl);\n }\n\n get url(): string {\n return this.options.url;\n }\n\n get baseUrl(): string {\n return this.options.baseUrl;\n }\n\n get cdnId(): string {\n return this.options.cdnId;\n }\n\n get jsonPath(): string {\n return this.options.jsonPath;\n }\n\n protected static parseMetafileUrl(metafileUrl: string): IMetafileParams {\n let url: URL;\n\n try {\n url = new URL(metafileUrl);\n } catch {\n throw new Error('Invalid param: \"options.metafile\" cannot be parsed as url.');\n }\n\n const matches: string[] | null = /^\\/(.*?)\\/(.*?)\\.(v2.json|js|ts)$/.exec(url.pathname);\n\n if (\n matches === null ||\n matches.length !== 4 ||\n typeof matches[1] === 'undefined' ||\n typeof matches[2] === 'undefined'\n ) {\n throw new Error('Invalid param: \"options.metafile\" contains invalid metafile url.');\n }\n\n const cdnId: string = matches[1];\n const tagId: string = matches[2];\n\n return {\n url: metafileUrl,\n baseUrl: url.origin,\n cdnId,\n jsonPath: `/${cdnId}/${tagId}.v2.json`,\n };\n }\n}\n","import { MetafileData } from '@/cdn/metafile/metafile-data.js';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\n\nexport class MetafileContext {\n public params: MetafileParams;\n\n public parsedData: IMetafile | null;\n\n public data: MetafileData;\n\n constructor(options: CdnClientOptions) {\n this.params = new MetafileParams(options.metafile);\n this.parsedData = null;\n this.data = MetafileData.createEmpty(this.params);\n }\n\n public setMetafile(metafile: IMetafile): void {\n this.parsedData = metafile;\n\n this.data = new MetafileData(metafile, this.params);\n }\n}\n","import type { IHttpAdapter } from '@/interfaces/i-http-adapter.js';\n\nexport class FetchHttpAdapter implements IHttpAdapter {\n protected baseUrl: string;\n\n constructor(baseUrl: string) {\n this.baseUrl = baseUrl;\n }\n\n async get(url: string): Promise<string | object> {\n const response: Response = await fetch(`${this.baseUrl}${url}`);\n const contentType: string | null = response.headers.get('content-type');\n const isJson: boolean =\n contentType === 'application/json5' || contentType === 'application/json';\n\n if (response.status >= 400) {\n throw new Error(`Request failed with status code ${response.status.toString()}`);\n }\n\n let result: string | object;\n\n if (isJson) {\n result = (await response.json()) as object;\n } else {\n result = await response.text();\n }\n\n return result;\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\n\nexport abstract class CdnBase {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n}\n","import { CdnBase } from '@/cdn/methods/cdn-base.js';\n\nexport class CdnCache extends CdnBase {\n public flush = (): void => {\n this.context.cache.flush();\n };\n}\n","import type { MetafileData } from '@/cdn/metafile/metafile-data.js';\nimport type { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport { CdnBase } from '@/cdn/methods/cdn-base.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\nimport type { CdnLocalesOptions } from '@/types/cdn-locales-options.js';\n\nexport class CdnMetafile extends CdnBase {\n get projectUrl(): string {\n return this.context.metafile.data.projectUrl;\n }\n\n get baseLocale(): CdnLocale {\n return this.context.metafile.data.baseLocale;\n }\n\n get url(): string {\n return this.context.metafile.params.url;\n }\n\n get files(): CdnFile[] {\n return this.context.metafile.data.files.map((file: MetafileFile): CdnFile => file.toCdnFile());\n }\n\n public locales = (options?: CdnLocalesOptions): CdnLocale[] => {\n const { excludeBaseLocale }: CdnLocalesOptions = options || {};\n const { locales }: MetafileData = this.context.metafile.data;\n\n return excludeBaseLocale\n ? locales.filter((cdnLocale: CdnLocale): boolean => !cdnLocale.isBaseLocale)\n : locales;\n };\n\n public refresh = async (): Promise<void> => {\n const response: IMetafile = await this.context.api.fetchMetafile();\n\n this.context.metafile.setMetafile(response);\n };\n\n public switch = async (options: CdnClientOptions): Promise<void> => {\n this.context.metafile.params = new MetafileParams(options.metafile);\n\n await this.refresh();\n };\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { LocalesMapData } from '@/types/locales-map-data.js';\nimport type { LocalesMapOptions } from '@/types/locales-map-options.js';\n\nexport class LocalesMap {\n public data: LocalesMapData;\n\n protected context: Context;\n\n constructor(options: LocalesMapOptions) {\n this.context = options.context;\n this.data = options.data || {};\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport { LocalesMap } from '@/cdn/request/locales-map.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\n\nexport class Request {\n public files: MetafileFile[];\n\n public localesMap: LocalesMap;\n\n public hasSingleFileResponse: boolean;\n\n public hasSingleLocaleResponse: boolean;\n\n protected context: Context;\n\n constructor(context: Context) {\n this.files = [];\n this.localesMap = new LocalesMap({ context });\n this.hasSingleFileResponse = false;\n this.hasSingleLocaleResponse = false;\n this.context = context;\n }\n\n public async execute(): Promise<CdnResponse> {\n const payload: [Promise<string | object>, ApiLocaleRequest][] = this.getPromises();\n const promises: Promise<string | object>[] = payload.map(\n (item: [Promise<string | object>, ApiLocaleRequest]) => item[0],\n );\n const requests: ApiLocaleRequest[] = payload.map(\n (item: [Promise<string | object>, ApiLocaleRequest]) => item[1],\n );\n const responses: (string | object)[] = await Promise.all(promises);\n\n return this.context.responseFactory.createCdnResponse({\n requests,\n responses,\n localesMap: this.localesMap,\n hasSingleFileResponse: this.hasSingleFileResponse,\n hasSingleLocaleResponse: this.hasSingleLocaleResponse,\n });\n }\n\n protected getPromises(): [Promise<string | object>, ApiLocaleRequest][] {\n return this.files.reduce(\n (acc: [Promise<string | object>, ApiLocaleRequest][], cur: MetafileFile) => {\n if (typeof this.localesMap.data?.[cur.id] !== 'undefined') {\n acc.push(\n // @ts-expect-error TODO fix type\n ...this.localesMap.data[cur.id].map(\n (metafileLocale: MetafileLocale): [Promise<string | object>, ApiLocaleRequest] => {\n const request: ApiLocaleRequest = {\n metafileFile: cur,\n metafileLocale,\n };\n\n return [this.context.api.fetchLocale(request), request];\n },\n ),\n );\n }\n return acc;\n },\n [],\n );\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { LocalesMap } from '@/cdn/request/locales-map.js';\nimport { Request } from '@/cdn/request/request.js';\nimport { isArray, isPlainObject, isString, isUndefined } from '@/cdn/utils.js';\nimport type { IRequestBuilder } from '@/interfaces/i-request-builder.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\n\nexport class RequestBuilder implements IRequestBuilder {\n protected context: Context;\n\n protected request: Request;\n\n constructor(context: Context) {\n this.context = context;\n this.request = new Request(this.context);\n }\n\n public addFiles(files?: (CdnFile | string)[] | CdnFile | string): this {\n if (!(isPlainObject(files) || isString(files) || isUndefined(files) || isArray(files))) {\n throw new Error('Invalid param: \"request.files\" must be object, array, string or undefined.');\n }\n\n if (isArray(files)) {\n files.forEach((i: CdnFile | string): void => {\n if (!(isPlainObject(i) || isString(i))) {\n throw new Error('Invalid param: array \"request.files\" must contain objects or strings.');\n }\n });\n }\n\n if (isString(files)) {\n this.request.hasSingleFileResponse = true;\n\n const file: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === files,\n );\n\n if (!(file instanceof MetafileFile)) {\n throw new Error(`File not found: \"${files}\".`);\n }\n\n this.request.files = [file];\n } else if (isUndefined(files)) {\n this.request.files = [...this.context.metafile.data.files];\n } else if (isArray(files)) {\n this.request.files = files.map((file: CdnFile | string): MetafileFile => {\n let metafileFile: MetafileFile;\n\n if (isString(file)) {\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === file,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${file}\".`);\n }\n\n metafileFile = foundFile;\n } else {\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === file.id,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${file.id}\".`);\n }\n\n metafileFile = foundFile;\n }\n\n return metafileFile;\n });\n } else if (isPlainObject(files)) {\n this.request.hasSingleFileResponse = true;\n\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === files.id,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${files.id}\".`);\n }\n\n this.request.files = [foundFile];\n }\n\n return this;\n }\n\n public addLocales(locales?: string[] | string, excludeBaseLocale?: boolean): this {\n if (!(isString(locales) || isUndefined(locales) || isArray(locales))) {\n throw new Error('Invalid param: \"request.locales\" must be array, string or undefined.');\n }\n\n if (isArray(locales)) {\n locales.forEach((i: MetafileFile | string): void => {\n if (!isString(i)) {\n throw new Error('Invalid param: array \"request.locales\" must contain strings.');\n }\n });\n }\n\n if (isString(locales)) {\n this.request.hasSingleLocaleResponse = true;\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = cur.locales.filter(\n (metafileLocale: MetafileLocale): boolean => metafileLocale.locale === locales,\n );\n\n return acc;\n }, this.request.localesMap);\n } else if (isUndefined(locales)) {\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = excludeBaseLocale\n ? cur.locales.filter(\n (metafileLocale: MetafileLocale): boolean => !metafileLocale.isBaseLocale,\n )\n : cur.locales;\n\n return acc;\n }, this.request.localesMap);\n } else if (isArray(locales)) {\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = cur.locales.filter((metafileLocale: MetafileLocale) =>\n locales.includes(metafileLocale.locale),\n );\n\n return acc;\n }, this.request.localesMap);\n }\n\n return this;\n }\n\n public getCdnRequest(): Request {\n const result: Request = this.request;\n this.request = new Request(this.context);\n return result;\n }\n}\n","import { Context } from '@/cdn/context/context.js';\nimport { MetafileContext } from '@/cdn/context/metafile-context.js';\nimport { FetchHttpAdapter } from '@/cdn/http/fetch-http-adapter.js';\nimport { CdnCache } from '@/cdn/methods/cdn-cache.js';\nimport { CdnMetafile } from '@/cdn/methods/cdn-metafile.js';\nimport { RequestBuilder } from '@/cdn/request/request-builder.js';\nimport { isString } from '@/cdn/utils.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\nimport type { CdnFetchOptions } from '@/types/cdn-fetch-options.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\n\nexport class CdnClient {\n public metafile: CdnMetafile;\n\n public cache: CdnCache;\n\n protected context: Context;\n\n public static version = '__CLIENT_VERSION__';\n\n protected constructor(options: CdnClientOptions) {\n const metafileContext: MetafileContext = new MetafileContext(options);\n const client: FetchHttpAdapter = new FetchHttpAdapter(metafileContext.params.baseUrl);\n\n this.context = new Context({ metafileContext, cdn: this, client });\n this.metafile = new CdnMetafile(this.context);\n this.cache = new CdnCache(this.context);\n }\n\n public fetch = async (options?: CdnFetchOptions): Promise<CdnResponse> => {\n const { files, locales, excludeBaseLocale }: CdnFetchOptions = options || {};\n const requestBuilder: RequestBuilder = new RequestBuilder(this.context)\n .addFiles(files)\n .addLocales(locales, excludeBaseLocale);\n\n return requestBuilder.getCdnRequest().execute();\n };\n\n public static async create(options: CdnClientOptions): Promise<CdnClient> {\n if (!options) {\n throw new Error('Invalid param: missing required \"options\" parameter.');\n }\n\n if (!isString(options.metafile)) {\n throw new Error('Invalid param: \"options.metafile\" must be string.');\n }\n\n const cdn: CdnClient = new CdnClient(options);\n\n await cdn.metafile.refresh();\n\n return cdn;\n }\n}\n"],"names":["Api","context","constructor","this","fetchLocale","options","cache","has","Promise","resolve","get","client","metafileLocale","uri","fetchMetafile","metafile","params","jsonPath","MemoryCacheAdapter","map","Map","key","set","value","flush","isString","isUndefined","isArray","Array","isPlainObject","Object","prototype","toString","call","uniq","array","Set","uniqBy","predicate","seen","filter","item","hasOwn","LocalesCache","cacheAdapter","setIfMissed","metafileFile","data","keyFromMetafile","productFlavors","sort","join","cdnId","id","file","path","library","module","buildType","locale","timestamp","ResponseFactory","createCdnResponse","requests","responses","hasSingleFileResponse","hasSingleLocaleResponse","length","cacheResponses","transformResponses","forEach","response","index","reduce","acc","cur","Context","cdn","api","responseFactory","metafileContext","MetafileFile","locales","baseUrl","toCdnFile","isBaseLocale","MetafileLocale","language","region","script","isRtl","name","localizedName","baseLocale","toCdnLocale","MetafileData","projectUrl","files","filesMap","filesFactory","filesMapFactory","localesFactory","find","createEmpty","keys","push","cdnLocale","MetafileParams","metafileUrl","parseMetafileUrl","url","URL","Error","matches","exec","pathname","tagId","origin","MetafileContext","parsedData","setMetafile","FetchHttpAdapter","fetch","contentType","headers","isJson","status","result","json","text","CdnBase","CdnCache","CdnMetafile","excludeBaseLocale","refresh","async","switch","LocalesMap","Request","localesMap","execute","payload","getPromises","promises","all","request","RequestBuilder","addFiles","i","foundFile","addLocales","includes","getCdnRequest","CdnClient","static","create"],"mappings":"mPAIO,MAAMA,EACDC,QAEV,WAAAC,CAAYD,GACVE,KAAKF,QAAUA,CACjB,CAEA,iBAAaG,CAAYC,GACvB,OAAIF,KAAKF,QAAQK,MAAMC,IAAIF,GAClB,IAAIG,SAASC,IAClBA,EAAQN,KAAKF,QAAQK,MAAMI,IAAIL,GAA2B,IAIvDF,KAAKF,QAAQU,OAAOD,IAAIL,EAAQO,eAAeC,IACxD,CAEA,mBAAaC,GACX,aAAcX,KAAKF,QAAQU,OAAOD,IAAIP,KAAKF,QAAQc,SAASC,OAAOC,SACrE,ECrBK,MAAMC,EACDC,IAEV,WAAAjB,GACEC,KAAKgB,QAAUC,GACjB,CAEO,GAAAV,CAAIW,GACT,OAAOlB,KAAKgB,IAAIT,IAAIW,EACtB,CAEO,GAAAd,CAAIc,GACT,OAAOlB,KAAKgB,IAAIZ,IAAIc,EACtB,CAEO,GAAAC,CAAID,EAAQE,GACjBpB,KAAKgB,IAAIG,IAAID,EAAKE,EACpB,CAEO,KAAAC,GACLrB,KAAKgB,QAAUC,GACjB,ECvBK,MAAMK,EAAYF,GAAqD,iBAAVA,EAEvDG,EAAeH,QAAwD,IAAVA,EAE7DI,EAAcJ,GAAiCK,MAAMD,QAAQJ,GAE7DM,EAAiBN,GACc,oBAA1CO,OAAOC,UAAUC,SAASC,KAAKV,GAEpBW,EAAWC,GAAoB,IAAI,IAAIC,IAAID,IAE3CE,EAAS,CAAIF,EAAYG,KACpC,MAAMC,EAAgC,CAAA,EAEtC,OAAOJ,EAAMK,QAAQC,IACnB,MAAMpB,EAAciB,EAAUG,GAE9B,OAAKX,OAAOY,OAAOH,EAAMlB,KACvBkB,EAAKlB,IAAO,GAEL,EAGF,GACR,ECfI,MAAMsB,EACD1C,QAEA2C,aAEV,WAAA1C,CAAYD,GACVE,KAAKF,QAA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mE,SAE7EhF,KAAKF,QAAU,IAAI2E,EAAQ,CAAEI,kBAAiBH,IAAK1E,KAAMQ,WACzDR,KAAKY,SAAW,IAAIqH,EAAYjI,KAAKF,SACrCE,KAAKG,MAAQ,IAAI6H,EAAShI,KAAKF,QACjC,CAEOyH,MAAQa,MAAOlI,IACpB,MAAM4F,MAAEA,EAAAf,QAAOA,EAAAmD,kBAASA,GAAuChI,GAAW,CAAA,EAK1E,OAJuC,IAAI6I,EAAe/I,KAAKF,SAC5DkJ,SAASlD,GACTqD,WAAWpE,EAASmD,GAEDmB,gBAAgBZ,SAAA,EAGxC,mBAAoBe,CAAOtJ,GACzB,IAAKA,EACH,MAAM,IAAI2G,MAAM,wDAGlB,IAAKvF,EAASpB,EAAQU,UACpB,MAAM,IAAIiG,MAAM,qDAGlB,MAAMnC,EAAiB,IAAI4E,EAAUpJ,GAIrC,aAFMwE,EAAI9D,SAASuH,UAEZzD,CACT"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/* @localazy/cdn-client@1.5.7
|
|
2
|
-
* (c) 2025 Localazy <team@localazy.com>
|
|
3
|
-
* @license MIT */
|
|
4
1
|
class Api {
|
|
5
2
|
context;
|
|
6
3
|
constructor(context) {
|
|
@@ -591,7 +588,7 @@ class CdnClient {
|
|
|
591
588
|
metafile;
|
|
592
589
|
cache;
|
|
593
590
|
context;
|
|
594
|
-
static version = "1.5.
|
|
591
|
+
static version = "1.5.9";
|
|
595
592
|
constructor(options) {
|
|
596
593
|
const metafileContext = new MetafileContext(options);
|
|
597
594
|
const client = new FetchHttpAdapter(metafileContext.params.baseUrl);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localazy-cdn-client.js","sources":["../src/cdn/api/api.ts","../src/cdn/cache/memory-cache-adapter.ts","../src/cdn/utils.ts","../src/cdn/cache/locales-cache.ts","../src/cdn/response/response-factory.ts","../src/cdn/context/context.ts","../src/cdn/metafile/metafile-file.ts","../src/cdn/metafile/metafile-locale.ts","../src/cdn/metafile/metafile-data.ts","../src/cdn/metafile/metafile-params.ts","../src/cdn/context/metafile-context.ts","../src/cdn/http/fetch-http-adapter.ts","../src/cdn/methods/cdn-base.ts","../src/cdn/methods/cdn-cache.ts","../src/cdn/methods/cdn-metafile.ts","../src/cdn/request/locales-map.ts","../src/cdn/request/request.ts","../src/cdn/request/request-builder.ts","../src/cdn/cdn-client.ts"],"sourcesContent":["import type { Context } from '@/cdn/context/context.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\n\nexport class Api {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n\n public async fetchLocale(options: ApiLocaleRequest): Promise<object | string> {\n if (this.context.cache.has(options)) {\n return new Promise((resolve): void => {\n resolve(this.context.cache.get(options) as object | string);\n });\n }\n\n return this.context.client.get(options.metafileLocale.uri);\n }\n\n public async fetchMetafile(): Promise<IMetafile> {\n return (await this.context.client.get(this.context.metafile.params.jsonPath)) as IMetafile;\n }\n}\n","import type { ICacheAdapter } from '@/interfaces/i-cache-adapter.js';\n\nexport class MemoryCacheAdapter<K, V> implements ICacheAdapter<K, V> {\n protected map: Map<K, V>;\n\n constructor() {\n this.map = new Map();\n }\n\n public get(key: K): V | undefined {\n return this.map.get(key);\n }\n\n public has(key: K): boolean {\n return this.map.has(key);\n }\n\n public set(key: K, value: V): void {\n this.map.set(key, value);\n }\n\n public flush(): void {\n this.map = new Map();\n }\n}\n","export const isString = (value: unknown): value is string => typeof value === 'string';\n\nexport const isUndefined = (value: unknown): value is undefined => typeof value === 'undefined';\n\nexport const isArray = <T>(value: unknown): value is T[] => Array.isArray(value);\n\nexport const isPlainObject = (value: unknown): value is Record<string, unknown> =>\n Object.prototype.toString.call(value) === '[object Object]';\n\nexport const uniq = <T>(array: T[]): T[] => [...new Set(array)];\n\nexport const uniqBy = <T>(array: T[], predicate: (item: T) => string): T[] => {\n const seen: Record<string, boolean> = {};\n\n return array.filter((item: T): boolean => {\n const key: string = predicate(item);\n\n if (!Object.hasOwn(seen, key)) {\n seen[key] = true;\n\n return true;\n }\n\n return false;\n });\n};\n","import { MemoryCacheAdapter } from '@/cdn/cache/memory-cache-adapter.js';\nimport type { Context } from '@/cdn/context/context.js';\nimport { uniq } from '@/cdn/utils.js';\nimport type { ICacheAdapter } from '@/interfaces/i-cache-adapter.js';\nimport type { CacheGetLocalesRequest } from '@/types/cache-get-locales-request.js';\nimport type { CacheHasLocalesRequest } from '@/types/cache-has-locales-request.js';\nimport type { CacheKeyMetafileOptions } from '@/types/cache-key-metafile-options.js';\nimport type { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request.js';\n\nexport class LocalesCache {\n protected context: Context;\n\n protected cacheAdapter: ICacheAdapter<string, object | string>;\n\n constructor(context: Context) {\n this.context = context;\n this.cacheAdapter = new MemoryCacheAdapter();\n }\n\n public setIfMissed(options: CacheStoreLocalesRequest): void {\n const { metafileFile, metafileLocale, data }: CacheStoreLocalesRequest = options;\n\n const key: string = this.keyFromMetafile({\n metafileFile,\n metafileLocale,\n });\n\n if (!this.cacheAdapter.has(key)) {\n this.cacheAdapter.set(key, data);\n }\n }\n\n public has(options: CacheHasLocalesRequest): boolean {\n const key: string = this.keyFromMetafile(options);\n\n return this.cacheAdapter.has(key);\n }\n\n public get(options: CacheGetLocalesRequest): object | string | undefined {\n const key: string = this.keyFromMetafile(options);\n\n return this.cacheAdapter.get(key);\n }\n\n public flush(): void {\n this.cacheAdapter.flush();\n }\n\n protected keyFromMetafile(options: CacheKeyMetafileOptions): string {\n const { metafileFile, metafileLocale }: CacheKeyMetafileOptions = options;\n const productFlavors: string = [...uniq(metafileFile.productFlavors)].sort().join('-');\n\n const indices: string[] = [\n this.context.metafile.params.cdnId,\n metafileFile.id,\n metafileFile.file,\n metafileFile.path,\n metafileFile.library,\n metafileFile.module,\n metafileFile.buildType,\n productFlavors,\n metafileLocale.locale,\n metafileLocale.timestamp.toString(),\n ];\n\n return indices.filter((key: string): boolean => key !== '').join('-');\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\nimport type { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\nimport type { ResponseFactoryOptions } from '@/types/response-factory-options.js';\n\nexport class ResponseFactory {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n\n public createCdnResponse(options: ResponseFactoryOptions): CdnResponse {\n const {\n requests,\n responses,\n hasSingleFileResponse,\n hasSingleLocaleResponse,\n }: ResponseFactoryOptions = options;\n\n if (responses.length === 0 || typeof responses[0] === 'undefined') {\n return {};\n }\n\n this.cacheResponses(requests, responses);\n\n return hasSingleFileResponse && hasSingleLocaleResponse\n ? responses[0]\n : ResponseFactory.transformResponses(options);\n }\n\n protected cacheResponses(requests: ApiLocaleRequest[], responses: (object | string)[]): void {\n responses.forEach((response: object | string, index: number): void => {\n if (typeof requests[index] !== 'undefined') {\n const { metafileFile, metafileLocale }: Partial<CacheStoreLocalesRequest> = requests[index];\n\n if (metafileFile && metafileLocale) {\n this.context.cache.setIfMissed({ metafileFile, metafileLocale, data: response });\n }\n }\n });\n }\n\n protected static transformResponses(options: ResponseFactoryOptions): CdnResponse {\n const { requests, responses, hasSingleFileResponse }: ResponseFactoryOptions = options;\n\n return responses.reduce((acc: CdnResponse, cur: object | string, index: number) => {\n if (typeof requests[index] !== 'undefined') {\n const { metafileFile, metafileLocale }: Partial<CacheStoreLocalesRequest> = requests[index];\n\n if (metafileFile && metafileLocale) {\n if (hasSingleFileResponse) {\n // @ts-expect-error fix output type\n acc[metafileLocale.locale] = cur;\n } else {\n // @ts-expect-error fix output type\n if (!acc[metafileFile.id]) {\n // @ts-expect-error fix output type\n acc[metafileFile.id] = {};\n }\n\n // @ts-expect-error fix output type\n acc[metafileFile.id][metafileLocale.locale] = cur;\n }\n }\n }\n\n return acc;\n }, {});\n }\n}\n","import { Api } from '@/cdn/api/api.js';\nimport { LocalesCache } from '@/cdn/cache/locales-cache.js';\nimport type { CdnClient } from '@/cdn/cdn-client.js';\nimport type { MetafileContext } from '@/cdn/context/metafile-context.js';\nimport { ResponseFactory } from '@/cdn/response/response-factory.js';\nimport type { IHttpAdapter } from '@/interfaces/i-http-adapter.js';\nimport type { ContextOptions } from '@/types/context-options.js';\n\nexport class Context {\n public metafile: MetafileContext;\n\n public cdn: CdnClient;\n\n public client: IHttpAdapter;\n\n public api: Api;\n\n public cache: LocalesCache;\n\n public responseFactory: ResponseFactory;\n\n constructor(options: ContextOptions) {\n this.metafile = options.metafileContext;\n this.cdn = options.cdn;\n this.client = options.client;\n this.api = new Api(this);\n this.cache = new LocalesCache(this);\n this.responseFactory = new ResponseFactory(this);\n }\n}\n","import type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { IMetafileFile } from '@/interfaces/i-metafile-file.js';\nimport type { CdnFileLocale } from '@/types/cdn-file-locale.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\nimport type { MetafileFileOptions } from '@/types/metafile-file-options.js';\n\nexport class MetafileFile implements Omit<IMetafileFile, 'locales'> {\n public id: string;\n\n public file: string;\n\n public path: string;\n\n public library: string;\n\n public module: string;\n\n public buildType: string;\n\n public timestamp: number;\n\n public productFlavors: string[];\n\n public locales: MetafileLocale[];\n\n protected baseUrl: string;\n\n constructor(options: MetafileFileOptions) {\n this.id = options.id;\n this.file = options.file;\n this.path = options.path;\n this.library = options.library;\n this.module = options.module;\n this.buildType = options.buildType;\n this.timestamp = options.timestamp;\n this.productFlavors = options.productFlavors;\n this.locales = options.locales;\n this.baseUrl = options.baseUrl;\n }\n\n public toCdnFile(): CdnFile {\n return {\n id: this.id,\n file: this.file,\n path: this.path,\n library: this.library,\n module: this.module,\n buildType: this.buildType,\n productFlavors: this.productFlavors,\n locales: this.locales.map(\n (locale: MetafileLocale): CdnFileLocale => ({\n locale: locale.locale,\n isBaseLocale: locale.isBaseLocale,\n uri: `${this.baseUrl}${locale.uri}`,\n }),\n ),\n };\n }\n}\n","import type { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\n\nexport class MetafileLocale implements IMetafileFileLocale {\n public language: string;\n\n public region: string;\n\n public script: string;\n\n public isRtl: boolean;\n\n public name: string;\n\n public localizedName: string;\n\n public uri: string;\n\n public timestamp: number;\n\n protected baseLocale: string;\n\n constructor(options: IMetafileFileLocale, baseLocale: string) {\n this.language = options.language;\n this.region = options.region;\n this.script = options.script;\n this.isRtl = options.isRtl;\n this.name = options.name;\n this.localizedName = options.localizedName;\n this.uri = options.uri;\n this.timestamp = options.timestamp;\n this.baseLocale = baseLocale;\n }\n\n get locale(): string {\n if (this.language && this.region && this.script) {\n return `${this.language}_${this.region}#${this.script}`;\n }\n\n if (this.language && this.script) {\n return `${this.language}#${this.script}`;\n }\n\n if (this.language && this.region) {\n return `${this.language}_${this.region}`;\n }\n\n return this.language;\n }\n\n get isBaseLocale(): boolean {\n return this.locale === this.baseLocale;\n }\n\n public toCdnLocale(): CdnLocale {\n return {\n locale: this.locale,\n isBaseLocale: this.isBaseLocale,\n language: this.language,\n region: this.region,\n script: this.script,\n isRtl: this.isRtl,\n name: this.name,\n localizedName: this.localizedName,\n };\n }\n}\n","import { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport { uniqBy } from '@/cdn/utils.js';\nimport type { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale.js';\nimport type { IMetafileFiles } from '@/interfaces/i-metafile-files.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\nimport type { FilesMap } from '@/types/files-map.js';\nimport type { MetafileOptions } from '@/types/metafile-options.js';\n\nexport class MetafileData implements Omit<IMetafile, 'files' | 'baseLocale'> {\n public projectUrl: string;\n\n public baseLocale: CdnLocale;\n\n public locales: CdnLocale[];\n\n public timestamp: number;\n\n public files: MetafileFile[];\n\n public filesMap: FilesMap;\n\n constructor(options: MetafileOptions, params: MetafileParams) {\n this.projectUrl = options.projectUrl;\n this.timestamp = options.timestamp;\n this.files = MetafileData.filesFactory(options.files, options.baseLocale, params);\n this.filesMap = MetafileData.filesMapFactory(this.files);\n this.locales = MetafileData.localesFactory(this.files);\n this.baseLocale = this.locales.find((locale: CdnLocale) => locale.isBaseLocale) as CdnLocale;\n }\n\n public static createEmpty(params: MetafileParams): MetafileData {\n return new MetafileData(\n {\n projectUrl: '',\n baseLocale: '',\n timestamp: 0,\n files: {},\n },\n params,\n );\n }\n\n protected static filesFactory(\n files: IMetafileFiles,\n baseLocale: string,\n params: MetafileParams,\n ): MetafileFile[] {\n return Object.keys(files).reduce((acc: MetafileFile[], cur: string) => {\n if (typeof files[cur] !== 'undefined') {\n const locales: MetafileLocale[] = files[cur].locales.map(\n (locale: IMetafileFileLocale) => new MetafileLocale(locale, baseLocale),\n );\n\n acc.push(\n new MetafileFile({\n ...files[cur],\n id: cur,\n locales,\n baseUrl: params.baseUrl,\n }),\n );\n }\n\n return acc;\n }, []);\n }\n\n protected static filesMapFactory(files: MetafileFile[]): FilesMap {\n return files.reduce((acc: FilesMap, cur: MetafileFile) => {\n acc[cur.id] = cur;\n\n return acc;\n }, {});\n }\n\n protected static localesFactory(files: MetafileFile[]): CdnLocale[] {\n const locales: CdnLocale[] = files.reduce((acc: CdnLocale[], cur: MetafileFile) => {\n acc.push(...cur.locales.map((locale: MetafileLocale): CdnLocale => locale.toCdnLocale()));\n return acc;\n }, []);\n\n return uniqBy(locales, (cdnLocale: CdnLocale): string => cdnLocale.locale);\n }\n}\n","import type { IMetafileParams } from '@/interfaces/i-metafile-params.js';\n\nexport class MetafileParams implements IMetafileParams {\n protected options: IMetafileParams;\n\n constructor(metafileUrl: string) {\n this.options = MetafileParams.parseMetafileUrl(metafileUrl);\n }\n\n get url(): string {\n return this.options.url;\n }\n\n get baseUrl(): string {\n return this.options.baseUrl;\n }\n\n get cdnId(): string {\n return this.options.cdnId;\n }\n\n get jsonPath(): string {\n return this.options.jsonPath;\n }\n\n protected static parseMetafileUrl(metafileUrl: string): IMetafileParams {\n let url: URL;\n\n try {\n url = new URL(metafileUrl);\n } catch {\n throw new Error('Invalid param: \"options.metafile\" cannot be parsed as url.');\n }\n\n const matches: string[] | null = /^\\/(.*?)\\/(.*?)\\.(v2.json|js|ts)$/.exec(url.pathname);\n\n if (\n matches === null ||\n matches.length !== 4 ||\n typeof matches[1] === 'undefined' ||\n typeof matches[2] === 'undefined'\n ) {\n throw new Error('Invalid param: \"options.metafile\" contains invalid metafile url.');\n }\n\n const cdnId: string = matches[1];\n const tagId: string = matches[2];\n\n return {\n url: metafileUrl,\n baseUrl: url.origin,\n cdnId,\n jsonPath: `/${cdnId}/${tagId}.v2.json`,\n };\n }\n}\n","import { MetafileData } from '@/cdn/metafile/metafile-data.js';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\n\nexport class MetafileContext {\n public params: MetafileParams;\n\n public parsedData: IMetafile | null;\n\n public data: MetafileData;\n\n constructor(options: CdnClientOptions) {\n this.params = new MetafileParams(options.metafile);\n this.parsedData = null;\n this.data = MetafileData.createEmpty(this.params);\n }\n\n public setMetafile(metafile: IMetafile): void {\n this.parsedData = metafile;\n\n this.data = new MetafileData(metafile, this.params);\n }\n}\n","import type { IHttpAdapter } from '@/interfaces/i-http-adapter.js';\n\nexport class FetchHttpAdapter implements IHttpAdapter {\n protected baseUrl: string;\n\n constructor(baseUrl: string) {\n this.baseUrl = baseUrl;\n }\n\n async get(url: string): Promise<string | object> {\n const response: Response = await fetch(`${this.baseUrl}${url}`);\n const contentType: string | null = response.headers.get('content-type');\n const isJson: boolean =\n contentType === 'application/json5' || contentType === 'application/json';\n\n if (response.status >= 400) {\n throw new Error(`Request failed with status code ${response.status.toString()}`);\n }\n\n let result: string | object;\n\n if (isJson) {\n result = (await response.json()) as object;\n } else {\n result = await response.text();\n }\n\n return result;\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\n\nexport abstract class CdnBase {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n}\n","import { CdnBase } from '@/cdn/methods/cdn-base.js';\n\nexport class CdnCache extends CdnBase {\n public flush = (): void => {\n this.context.cache.flush();\n };\n}\n","import type { MetafileData } from '@/cdn/metafile/metafile-data.js';\nimport type { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport { CdnBase } from '@/cdn/methods/cdn-base.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\nimport type { CdnLocalesOptions } from '@/types/cdn-locales-options.js';\n\nexport class CdnMetafile extends CdnBase {\n get projectUrl(): string {\n return this.context.metafile.data.projectUrl;\n }\n\n get baseLocale(): CdnLocale {\n return this.context.metafile.data.baseLocale;\n }\n\n get url(): string {\n return this.context.metafile.params.url;\n }\n\n get files(): CdnFile[] {\n return this.context.metafile.data.files.map((file: MetafileFile): CdnFile => file.toCdnFile());\n }\n\n public locales = (options?: CdnLocalesOptions): CdnLocale[] => {\n const { excludeBaseLocale }: CdnLocalesOptions = options || {};\n const { locales }: MetafileData = this.context.metafile.data;\n\n return excludeBaseLocale\n ? locales.filter((cdnLocale: CdnLocale): boolean => !cdnLocale.isBaseLocale)\n : locales;\n };\n\n public refresh = async (): Promise<void> => {\n const response: IMetafile = await this.context.api.fetchMetafile();\n\n this.context.metafile.setMetafile(response);\n };\n\n public switch = async (options: CdnClientOptions): Promise<void> => {\n this.context.metafile.params = new MetafileParams(options.metafile);\n\n await this.refresh();\n };\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { LocalesMapData } from '@/types/locales-map-data.js';\nimport type { LocalesMapOptions } from '@/types/locales-map-options.js';\n\nexport class LocalesMap {\n public data: LocalesMapData;\n\n protected context: Context;\n\n constructor(options: LocalesMapOptions) {\n this.context = options.context;\n this.data = options.data || {};\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport { LocalesMap } from '@/cdn/request/locales-map.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\n\nexport class Request {\n public files: MetafileFile[];\n\n public localesMap: LocalesMap;\n\n public hasSingleFileResponse: boolean;\n\n public hasSingleLocaleResponse: boolean;\n\n protected context: Context;\n\n constructor(context: Context) {\n this.files = [];\n this.localesMap = new LocalesMap({ context });\n this.hasSingleFileResponse = false;\n this.hasSingleLocaleResponse = false;\n this.context = context;\n }\n\n public async execute(): Promise<CdnResponse> {\n const payload: [Promise<string | object>, ApiLocaleRequest][] = this.getPromises();\n const promises: Promise<string | object>[] = payload.map(\n (item: [Promise<string | object>, ApiLocaleRequest]) => item[0],\n );\n const requests: ApiLocaleRequest[] = payload.map(\n (item: [Promise<string | object>, ApiLocaleRequest]) => item[1],\n );\n const responses: (string | object)[] = await Promise.all(promises);\n\n return this.context.responseFactory.createCdnResponse({\n requests,\n responses,\n localesMap: this.localesMap,\n hasSingleFileResponse: this.hasSingleFileResponse,\n hasSingleLocaleResponse: this.hasSingleLocaleResponse,\n });\n }\n\n protected getPromises(): [Promise<string | object>, ApiLocaleRequest][] {\n return this.files.reduce(\n (acc: [Promise<string | object>, ApiLocaleRequest][], cur: MetafileFile) => {\n if (typeof this.localesMap.data?.[cur.id] !== 'undefined') {\n acc.push(\n // @ts-expect-error TODO fix type\n ...this.localesMap.data[cur.id].map(\n (metafileLocale: MetafileLocale): [Promise<string | object>, ApiLocaleRequest] => {\n const request: ApiLocaleRequest = {\n metafileFile: cur,\n metafileLocale,\n };\n\n return [this.context.api.fetchLocale(request), request];\n },\n ),\n );\n }\n return acc;\n },\n [],\n );\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { LocalesMap } from '@/cdn/request/locales-map.js';\nimport { Request } from '@/cdn/request/request.js';\nimport { isArray, isPlainObject, isString, isUndefined } from '@/cdn/utils.js';\nimport type { IRequestBuilder } from '@/interfaces/i-request-builder.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\n\nexport class RequestBuilder implements IRequestBuilder {\n protected context: Context;\n\n protected request: Request;\n\n constructor(context: Context) {\n this.context = context;\n this.request = new Request(this.context);\n }\n\n public addFiles(files?: (CdnFile | string)[] | CdnFile | string): this {\n if (!(isPlainObject(files) || isString(files) || isUndefined(files) || isArray(files))) {\n throw new Error('Invalid param: \"request.files\" must be object, array, string or undefined.');\n }\n\n if (isArray(files)) {\n files.forEach((i: CdnFile | string): void => {\n if (!(isPlainObject(i) || isString(i))) {\n throw new Error('Invalid param: array \"request.files\" must contain objects or strings.');\n }\n });\n }\n\n if (isString(files)) {\n this.request.hasSingleFileResponse = true;\n\n const file: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === files,\n );\n\n if (!(file instanceof MetafileFile)) {\n throw new Error(`File not found: \"${files}\".`);\n }\n\n this.request.files = [file];\n } else if (isUndefined(files)) {\n this.request.files = [...this.context.metafile.data.files];\n } else if (isArray(files)) {\n this.request.files = files.map((file: CdnFile | string): MetafileFile => {\n let metafileFile: MetafileFile;\n\n if (isString(file)) {\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === file,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${file}\".`);\n }\n\n metafileFile = foundFile;\n } else {\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === file.id,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${file.id}\".`);\n }\n\n metafileFile = foundFile;\n }\n\n return metafileFile;\n });\n } else if (isPlainObject(files)) {\n this.request.hasSingleFileResponse = true;\n\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === files.id,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${files.id}\".`);\n }\n\n this.request.files = [foundFile];\n }\n\n return this;\n }\n\n public addLocales(locales?: string[] | string, excludeBaseLocale?: boolean): this {\n if (!(isString(locales) || isUndefined(locales) || isArray(locales))) {\n throw new Error('Invalid param: \"request.locales\" must be array, string or undefined.');\n }\n\n if (isArray(locales)) {\n locales.forEach((i: MetafileFile | string): void => {\n if (!isString(i)) {\n throw new Error('Invalid param: array \"request.locales\" must contain strings.');\n }\n });\n }\n\n if (isString(locales)) {\n this.request.hasSingleLocaleResponse = true;\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = cur.locales.filter(\n (metafileLocale: MetafileLocale): boolean => metafileLocale.locale === locales,\n );\n\n return acc;\n }, this.request.localesMap);\n } else if (isUndefined(locales)) {\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = excludeBaseLocale\n ? cur.locales.filter(\n (metafileLocale: MetafileLocale): boolean => !metafileLocale.isBaseLocale,\n )\n : cur.locales;\n\n return acc;\n }, this.request.localesMap);\n } else if (isArray(locales)) {\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = cur.locales.filter((metafileLocale: MetafileLocale) =>\n locales.includes(metafileLocale.locale),\n );\n\n return acc;\n }, this.request.localesMap);\n }\n\n return this;\n }\n\n public getCdnRequest(): Request {\n const result: Request = this.request;\n this.request = new Request(this.context);\n return result;\n }\n}\n","import { Context } from '@/cdn/context/context.js';\nimport { MetafileContext } from '@/cdn/context/metafile-context.js';\nimport { FetchHttpAdapter } from '@/cdn/http/fetch-http-adapter.js';\nimport { CdnCache } from '@/cdn/methods/cdn-cache.js';\nimport { CdnMetafile } from '@/cdn/methods/cdn-metafile.js';\nimport { RequestBuilder } from '@/cdn/request/request-builder.js';\nimport { isString } from '@/cdn/utils.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\nimport type { CdnFetchOptions } from '@/types/cdn-fetch-options.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\n\nexport class CdnClient {\n public metafile: CdnMetafile;\n\n public cache: CdnCache;\n\n protected context: Context;\n\n public static version = '__CLIENT_VERSION__';\n\n protected constructor(options: CdnClientOptions) {\n const metafileContext: MetafileContext = new MetafileContext(options);\n const client: FetchHttpAdapter = new FetchHttpAdapter(metafileContext.params.baseUrl);\n\n this.context = new Context({ metafileContext, cdn: this, client });\n this.metafile = new CdnMetafile(this.context);\n this.cache = new CdnCache(this.context);\n }\n\n public fetch = async (options?: CdnFetchOptions): Promise<CdnResponse> => {\n const { files, locales, excludeBaseLocale }: CdnFetchOptions = options || {};\n const requestBuilder: RequestBuilder = new RequestBuilder(this.context)\n .addFiles(files)\n .addLocales(locales, excludeBaseLocale);\n\n return requestBuilder.getCdnRequest().execute();\n };\n\n public static async create(options: CdnClientOptions): Promise<CdnClient> {\n if (!options) {\n throw new Error('Invalid param: missing required \"options\" parameter.');\n }\n\n if (!isString(options.metafile)) {\n throw new Error('Invalid param: \"options.metafile\" must be string.');\n }\n\n const cdn: CdnClient = new CdnClient(options);\n\n await cdn.metafile.refresh();\n\n return cdn;\n }\n}\n"],"names":[],"mappings":";;;AAIO,MAAM,IAAI;AAAA,EACL;AAAA,EAEV,YAAY,SAAkB;AAC5B,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAa,YAAY,SAAqD;AAC5E,QAAI,KAAK,QAAQ,MAAM,IAAI,OAAO,GAAG;AACnC,aAAO,IAAI,QAAQ,CAAC,Y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QAAQ;AACjE,SAAK,WAAW,IAAI,YAAY,KAAK,OAAO;AAC5C,SAAK,QAAQ,IAAI,SAAS,KAAK,OAAO;AAAA,EACxC;AAAA,EAEO,QAAQ,OAAO,YAAoD;AACxE,UAAM,EAAE,OAAO,SAAS,kBAAA,IAAuC,WAAW,CAAA;AAC1E,UAAM,iBAAiC,IAAI,eAAe,KAAK,OAAO,EACnE,SAAS,KAAK,EACd,WAAW,SAAS,iBAAiB;AAExC,WAAO,eAAe,cAAA,EAAgB,QAAA;AAAA,EACxC;AAAA,EAEA,aAAoB,OAAO,SAA+C;AACxE,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI,MAAM,sDAAsD;AAAA,IACxE;AAEA,QAAI,CAAC,SAAS,QAAQ,QAAQ,GAAG;AAC/B,YAAM,IAAI,MAAM,mDAAmD;AAAA,IACrE;AAEA,UAAM,MAAiB,IAAI,UAAU,OAAO;AAE5C,UAAM,IAAI,SAAS,QAAA;AAEnB,WAAO;AAAA,EACT;AACF;"}
|
|
1
|
+
{"version":3,"file":"localazy-cdn-client.js","sources":["../src/cdn/api/api.ts","../src/cdn/cache/memory-cache-adapter.ts","../src/cdn/utils.ts","../src/cdn/cache/locales-cache.ts","../src/cdn/response/response-factory.ts","../src/cdn/context/context.ts","../src/cdn/metafile/metafile-file.ts","../src/cdn/metafile/metafile-locale.ts","../src/cdn/metafile/metafile-data.ts","../src/cdn/metafile/metafile-params.ts","../src/cdn/context/metafile-context.ts","../src/cdn/http/fetch-http-adapter.ts","../src/cdn/methods/cdn-base.ts","../src/cdn/methods/cdn-cache.ts","../src/cdn/methods/cdn-metafile.ts","../src/cdn/request/locales-map.ts","../src/cdn/request/request.ts","../src/cdn/request/request-builder.ts","../src/cdn/cdn-client.ts"],"sourcesContent":["import type { Context } from '@/cdn/context/context.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\n\nexport class Api {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n\n public async fetchLocale(options: ApiLocaleRequest): Promise<object | string> {\n if (this.context.cache.has(options)) {\n return new Promise((resolve): void => {\n resolve(this.context.cache.get(options) as object | string);\n });\n }\n\n return this.context.client.get(options.metafileLocale.uri);\n }\n\n public async fetchMetafile(): Promise<IMetafile> {\n return (await this.context.client.get(this.context.metafile.params.jsonPath)) as IMetafile;\n }\n}\n","import type { ICacheAdapter } from '@/interfaces/i-cache-adapter.js';\n\nexport class MemoryCacheAdapter<K, V> implements ICacheAdapter<K, V> {\n protected map: Map<K, V>;\n\n constructor() {\n this.map = new Map();\n }\n\n public get(key: K): V | undefined {\n return this.map.get(key);\n }\n\n public has(key: K): boolean {\n return this.map.has(key);\n }\n\n public set(key: K, value: V): void {\n this.map.set(key, value);\n }\n\n public flush(): void {\n this.map = new Map();\n }\n}\n","export const isString = (value: unknown): value is string => typeof value === 'string';\n\nexport const isUndefined = (value: unknown): value is undefined => typeof value === 'undefined';\n\nexport const isArray = <T>(value: unknown): value is T[] => Array.isArray(value);\n\nexport const isPlainObject = (value: unknown): value is Record<string, unknown> =>\n Object.prototype.toString.call(value) === '[object Object]';\n\nexport const uniq = <T>(array: T[]): T[] => [...new Set(array)];\n\nexport const uniqBy = <T>(array: T[], predicate: (item: T) => string): T[] => {\n const seen: Record<string, boolean> = {};\n\n return array.filter((item: T): boolean => {\n const key: string = predicate(item);\n\n if (!Object.hasOwn(seen, key)) {\n seen[key] = true;\n\n return true;\n }\n\n return false;\n });\n};\n","import { MemoryCacheAdapter } from '@/cdn/cache/memory-cache-adapter.js';\nimport type { Context } from '@/cdn/context/context.js';\nimport { uniq } from '@/cdn/utils.js';\nimport type { ICacheAdapter } from '@/interfaces/i-cache-adapter.js';\nimport type { CacheGetLocalesRequest } from '@/types/cache-get-locales-request.js';\nimport type { CacheHasLocalesRequest } from '@/types/cache-has-locales-request.js';\nimport type { CacheKeyMetafileOptions } from '@/types/cache-key-metafile-options.js';\nimport type { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request.js';\n\nexport class LocalesCache {\n protected context: Context;\n\n protected cacheAdapter: ICacheAdapter<string, object | string>;\n\n constructor(context: Context) {\n this.context = context;\n this.cacheAdapter = new MemoryCacheAdapter();\n }\n\n public setIfMissed(options: CacheStoreLocalesRequest): void {\n const { metafileFile, metafileLocale, data }: CacheStoreLocalesRequest = options;\n\n const key: string = this.keyFromMetafile({\n metafileFile,\n metafileLocale,\n });\n\n if (!this.cacheAdapter.has(key)) {\n this.cacheAdapter.set(key, data);\n }\n }\n\n public has(options: CacheHasLocalesRequest): boolean {\n const key: string = this.keyFromMetafile(options);\n\n return this.cacheAdapter.has(key);\n }\n\n public get(options: CacheGetLocalesRequest): object | string | undefined {\n const key: string = this.keyFromMetafile(options);\n\n return this.cacheAdapter.get(key);\n }\n\n public flush(): void {\n this.cacheAdapter.flush();\n }\n\n protected keyFromMetafile(options: CacheKeyMetafileOptions): string {\n const { metafileFile, metafileLocale }: CacheKeyMetafileOptions = options;\n const productFlavors: string = [...uniq(metafileFile.productFlavors)].sort().join('-');\n\n const indices: string[] = [\n this.context.metafile.params.cdnId,\n metafileFile.id,\n metafileFile.file,\n metafileFile.path,\n metafileFile.library,\n metafileFile.module,\n metafileFile.buildType,\n productFlavors,\n metafileLocale.locale,\n metafileLocale.timestamp.toString(),\n ];\n\n return indices.filter((key: string): boolean => key !== '').join('-');\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\nimport type { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\nimport type { ResponseFactoryOptions } from '@/types/response-factory-options.js';\n\nexport class ResponseFactory {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n\n public createCdnResponse(options: ResponseFactoryOptions): CdnResponse {\n const {\n requests,\n responses,\n hasSingleFileResponse,\n hasSingleLocaleResponse,\n }: ResponseFactoryOptions = options;\n\n if (responses.length === 0 || typeof responses[0] === 'undefined') {\n return {};\n }\n\n this.cacheResponses(requests, responses);\n\n return hasSingleFileResponse && hasSingleLocaleResponse\n ? responses[0]\n : ResponseFactory.transformResponses(options);\n }\n\n protected cacheResponses(requests: ApiLocaleRequest[], responses: (object | string)[]): void {\n responses.forEach((response: object | string, index: number): void => {\n if (typeof requests[index] !== 'undefined') {\n const { metafileFile, metafileLocale }: Partial<CacheStoreLocalesRequest> = requests[index];\n\n if (metafileFile && metafileLocale) {\n this.context.cache.setIfMissed({ metafileFile, metafileLocale, data: response });\n }\n }\n });\n }\n\n protected static transformResponses(options: ResponseFactoryOptions): CdnResponse {\n const { requests, responses, hasSingleFileResponse }: ResponseFactoryOptions = options;\n\n return responses.reduce((acc: CdnResponse, cur: object | string, index: number) => {\n if (typeof requests[index] !== 'undefined') {\n const { metafileFile, metafileLocale }: Partial<CacheStoreLocalesRequest> = requests[index];\n\n if (metafileFile && metafileLocale) {\n if (hasSingleFileResponse) {\n // @ts-expect-error fix output type\n acc[metafileLocale.locale] = cur;\n } else {\n // @ts-expect-error fix output type\n if (!acc[metafileFile.id]) {\n // @ts-expect-error fix output type\n acc[metafileFile.id] = {};\n }\n\n // @ts-expect-error fix output type\n acc[metafileFile.id][metafileLocale.locale] = cur;\n }\n }\n }\n\n return acc;\n }, {});\n }\n}\n","import { Api } from '@/cdn/api/api.js';\nimport { LocalesCache } from '@/cdn/cache/locales-cache.js';\nimport type { CdnClient } from '@/cdn/cdn-client.js';\nimport type { MetafileContext } from '@/cdn/context/metafile-context.js';\nimport { ResponseFactory } from '@/cdn/response/response-factory.js';\nimport type { IHttpAdapter } from '@/interfaces/i-http-adapter.js';\nimport type { ContextOptions } from '@/types/context-options.js';\n\nexport class Context {\n public metafile: MetafileContext;\n\n public cdn: CdnClient;\n\n public client: IHttpAdapter;\n\n public api: Api;\n\n public cache: LocalesCache;\n\n public responseFactory: ResponseFactory;\n\n constructor(options: ContextOptions) {\n this.metafile = options.metafileContext;\n this.cdn = options.cdn;\n this.client = options.client;\n this.api = new Api(this);\n this.cache = new LocalesCache(this);\n this.responseFactory = new ResponseFactory(this);\n }\n}\n","import type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { IMetafileFile } from '@/interfaces/i-metafile-file.js';\nimport type { CdnFileLocale } from '@/types/cdn-file-locale.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\nimport type { MetafileFileOptions } from '@/types/metafile-file-options.js';\n\nexport class MetafileFile implements Omit<IMetafileFile, 'locales'> {\n public id: string;\n\n public file: string;\n\n public path: string;\n\n public library: string;\n\n public module: string;\n\n public buildType: string;\n\n public timestamp: number;\n\n public productFlavors: string[];\n\n public locales: MetafileLocale[];\n\n protected baseUrl: string;\n\n constructor(options: MetafileFileOptions) {\n this.id = options.id;\n this.file = options.file;\n this.path = options.path;\n this.library = options.library;\n this.module = options.module;\n this.buildType = options.buildType;\n this.timestamp = options.timestamp;\n this.productFlavors = options.productFlavors;\n this.locales = options.locales;\n this.baseUrl = options.baseUrl;\n }\n\n public toCdnFile(): CdnFile {\n return {\n id: this.id,\n file: this.file,\n path: this.path,\n library: this.library,\n module: this.module,\n buildType: this.buildType,\n productFlavors: this.productFlavors,\n locales: this.locales.map(\n (locale: MetafileLocale): CdnFileLocale => ({\n locale: locale.locale,\n isBaseLocale: locale.isBaseLocale,\n uri: `${this.baseUrl}${locale.uri}`,\n }),\n ),\n };\n }\n}\n","import type { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\n\nexport class MetafileLocale implements IMetafileFileLocale {\n public language: string;\n\n public region: string;\n\n public script: string;\n\n public isRtl: boolean;\n\n public name: string;\n\n public localizedName: string;\n\n public uri: string;\n\n public timestamp: number;\n\n protected baseLocale: string;\n\n constructor(options: IMetafileFileLocale, baseLocale: string) {\n this.language = options.language;\n this.region = options.region;\n this.script = options.script;\n this.isRtl = options.isRtl;\n this.name = options.name;\n this.localizedName = options.localizedName;\n this.uri = options.uri;\n this.timestamp = options.timestamp;\n this.baseLocale = baseLocale;\n }\n\n get locale(): string {\n if (this.language && this.region && this.script) {\n return `${this.language}_${this.region}#${this.script}`;\n }\n\n if (this.language && this.script) {\n return `${this.language}#${this.script}`;\n }\n\n if (this.language && this.region) {\n return `${this.language}_${this.region}`;\n }\n\n return this.language;\n }\n\n get isBaseLocale(): boolean {\n return this.locale === this.baseLocale;\n }\n\n public toCdnLocale(): CdnLocale {\n return {\n locale: this.locale,\n isBaseLocale: this.isBaseLocale,\n language: this.language,\n region: this.region,\n script: this.script,\n isRtl: this.isRtl,\n name: this.name,\n localizedName: this.localizedName,\n };\n }\n}\n","import { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport { uniqBy } from '@/cdn/utils.js';\nimport type { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale.js';\nimport type { IMetafileFiles } from '@/interfaces/i-metafile-files.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\nimport type { FilesMap } from '@/types/files-map.js';\nimport type { MetafileOptions } from '@/types/metafile-options.js';\n\nexport class MetafileData implements Omit<IMetafile, 'files' | 'baseLocale'> {\n public projectUrl: string;\n\n public baseLocale: CdnLocale;\n\n public locales: CdnLocale[];\n\n public timestamp: number;\n\n public files: MetafileFile[];\n\n public filesMap: FilesMap;\n\n constructor(options: MetafileOptions, params: MetafileParams) {\n this.projectUrl = options.projectUrl;\n this.timestamp = options.timestamp;\n this.files = MetafileData.filesFactory(options.files, options.baseLocale, params);\n this.filesMap = MetafileData.filesMapFactory(this.files);\n this.locales = MetafileData.localesFactory(this.files);\n this.baseLocale = this.locales.find((locale: CdnLocale) => locale.isBaseLocale) as CdnLocale;\n }\n\n public static createEmpty(params: MetafileParams): MetafileData {\n return new MetafileData(\n {\n projectUrl: '',\n baseLocale: '',\n timestamp: 0,\n files: {},\n },\n params,\n );\n }\n\n protected static filesFactory(\n files: IMetafileFiles,\n baseLocale: string,\n params: MetafileParams,\n ): MetafileFile[] {\n return Object.keys(files).reduce((acc: MetafileFile[], cur: string) => {\n if (typeof files[cur] !== 'undefined') {\n const locales: MetafileLocale[] = files[cur].locales.map(\n (locale: IMetafileFileLocale) => new MetafileLocale(locale, baseLocale),\n );\n\n acc.push(\n new MetafileFile({\n ...files[cur],\n id: cur,\n locales,\n baseUrl: params.baseUrl,\n }),\n );\n }\n\n return acc;\n }, []);\n }\n\n protected static filesMapFactory(files: MetafileFile[]): FilesMap {\n return files.reduce((acc: FilesMap, cur: MetafileFile) => {\n acc[cur.id] = cur;\n\n return acc;\n }, {});\n }\n\n protected static localesFactory(files: MetafileFile[]): CdnLocale[] {\n const locales: CdnLocale[] = files.reduce((acc: CdnLocale[], cur: MetafileFile) => {\n acc.push(...cur.locales.map((locale: MetafileLocale): CdnLocale => locale.toCdnLocale()));\n return acc;\n }, []);\n\n return uniqBy(locales, (cdnLocale: CdnLocale): string => cdnLocale.locale);\n }\n}\n","import type { IMetafileParams } from '@/interfaces/i-metafile-params.js';\n\nexport class MetafileParams implements IMetafileParams {\n protected options: IMetafileParams;\n\n constructor(metafileUrl: string) {\n this.options = MetafileParams.parseMetafileUrl(metafileUrl);\n }\n\n get url(): string {\n return this.options.url;\n }\n\n get baseUrl(): string {\n return this.options.baseUrl;\n }\n\n get cdnId(): string {\n return this.options.cdnId;\n }\n\n get jsonPath(): string {\n return this.options.jsonPath;\n }\n\n protected static parseMetafileUrl(metafileUrl: string): IMetafileParams {\n let url: URL;\n\n try {\n url = new URL(metafileUrl);\n } catch {\n throw new Error('Invalid param: \"options.metafile\" cannot be parsed as url.');\n }\n\n const matches: string[] | null = /^\\/(.*?)\\/(.*?)\\.(v2.json|js|ts)$/.exec(url.pathname);\n\n if (\n matches === null ||\n matches.length !== 4 ||\n typeof matches[1] === 'undefined' ||\n typeof matches[2] === 'undefined'\n ) {\n throw new Error('Invalid param: \"options.metafile\" contains invalid metafile url.');\n }\n\n const cdnId: string = matches[1];\n const tagId: string = matches[2];\n\n return {\n url: metafileUrl,\n baseUrl: url.origin,\n cdnId,\n jsonPath: `/${cdnId}/${tagId}.v2.json`,\n };\n }\n}\n","import { MetafileData } from '@/cdn/metafile/metafile-data.js';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\n\nexport class MetafileContext {\n public params: MetafileParams;\n\n public parsedData: IMetafile | null;\n\n public data: MetafileData;\n\n constructor(options: CdnClientOptions) {\n this.params = new MetafileParams(options.metafile);\n this.parsedData = null;\n this.data = MetafileData.createEmpty(this.params);\n }\n\n public setMetafile(metafile: IMetafile): void {\n this.parsedData = metafile;\n\n this.data = new MetafileData(metafile, this.params);\n }\n}\n","import type { IHttpAdapter } from '@/interfaces/i-http-adapter.js';\n\nexport class FetchHttpAdapter implements IHttpAdapter {\n protected baseUrl: string;\n\n constructor(baseUrl: string) {\n this.baseUrl = baseUrl;\n }\n\n async get(url: string): Promise<string | object> {\n const response: Response = await fetch(`${this.baseUrl}${url}`);\n const contentType: string | null = response.headers.get('content-type');\n const isJson: boolean =\n contentType === 'application/json5' || contentType === 'application/json';\n\n if (response.status >= 400) {\n throw new Error(`Request failed with status code ${response.status.toString()}`);\n }\n\n let result: string | object;\n\n if (isJson) {\n result = (await response.json()) as object;\n } else {\n result = await response.text();\n }\n\n return result;\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\n\nexport abstract class CdnBase {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n}\n","import { CdnBase } from '@/cdn/methods/cdn-base.js';\n\nexport class CdnCache extends CdnBase {\n public flush = (): void => {\n this.context.cache.flush();\n };\n}\n","import type { MetafileData } from '@/cdn/metafile/metafile-data.js';\nimport type { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport { CdnBase } from '@/cdn/methods/cdn-base.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\nimport type { CdnLocalesOptions } from '@/types/cdn-locales-options.js';\n\nexport class CdnMetafile extends CdnBase {\n get projectUrl(): string {\n return this.context.metafile.data.projectUrl;\n }\n\n get baseLocale(): CdnLocale {\n return this.context.metafile.data.baseLocale;\n }\n\n get url(): string {\n return this.context.metafile.params.url;\n }\n\n get files(): CdnFile[] {\n return this.context.metafile.data.files.map((file: MetafileFile): CdnFile => file.toCdnFile());\n }\n\n public locales = (options?: CdnLocalesOptions): CdnLocale[] => {\n const { excludeBaseLocale }: CdnLocalesOptions = options || {};\n const { locales }: MetafileData = this.context.metafile.data;\n\n return excludeBaseLocale\n ? locales.filter((cdnLocale: CdnLocale): boolean => !cdnLocale.isBaseLocale)\n : locales;\n };\n\n public refresh = async (): Promise<void> => {\n const response: IMetafile = await this.context.api.fetchMetafile();\n\n this.context.metafile.setMetafile(response);\n };\n\n public switch = async (options: CdnClientOptions): Promise<void> => {\n this.context.metafile.params = new MetafileParams(options.metafile);\n\n await this.refresh();\n };\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { LocalesMapData } from '@/types/locales-map-data.js';\nimport type { LocalesMapOptions } from '@/types/locales-map-options.js';\n\nexport class LocalesMap {\n public data: LocalesMapData;\n\n protected context: Context;\n\n constructor(options: LocalesMapOptions) {\n this.context = options.context;\n this.data = options.data || {};\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport { LocalesMap } from '@/cdn/request/locales-map.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\n\nexport class Request {\n public files: MetafileFile[];\n\n public localesMap: LocalesMap;\n\n public hasSingleFileResponse: boolean;\n\n public hasSingleLocaleResponse: boolean;\n\n protected context: Context;\n\n constructor(context: Context) {\n this.files = [];\n this.localesMap = new LocalesMap({ context });\n this.hasSingleFileResponse = false;\n this.hasSingleLocaleResponse = false;\n this.context = context;\n }\n\n public async execute(): Promise<CdnResponse> {\n const payload: [Promise<string | object>, ApiLocaleRequest][] = this.getPromises();\n const promises: Promise<string | object>[] = payload.map(\n (item: [Promise<string | object>, ApiLocaleRequest]) => item[0],\n );\n const requests: ApiLocaleRequest[] = payload.map(\n (item: [Promise<string | object>, ApiLocaleRequest]) => item[1],\n );\n const responses: (string | object)[] = await Promise.all(promises);\n\n return this.context.responseFactory.createCdnResponse({\n requests,\n responses,\n localesMap: this.localesMap,\n hasSingleFileResponse: this.hasSingleFileResponse,\n hasSingleLocaleResponse: this.hasSingleLocaleResponse,\n });\n }\n\n protected getPromises(): [Promise<string | object>, ApiLocaleRequest][] {\n return this.files.reduce(\n (acc: [Promise<string | object>, ApiLocaleRequest][], cur: MetafileFile) => {\n if (typeof this.localesMap.data?.[cur.id] !== 'undefined') {\n acc.push(\n // @ts-expect-error TODO fix type\n ...this.localesMap.data[cur.id].map(\n (metafileLocale: MetafileLocale): [Promise<string | object>, ApiLocaleRequest] => {\n const request: ApiLocaleRequest = {\n metafileFile: cur,\n metafileLocale,\n };\n\n return [this.context.api.fetchLocale(request), request];\n },\n ),\n );\n }\n return acc;\n },\n [],\n );\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { LocalesMap } from '@/cdn/request/locales-map.js';\nimport { Request } from '@/cdn/request/request.js';\nimport { isArray, isPlainObject, isString, isUndefined } from '@/cdn/utils.js';\nimport type { IRequestBuilder } from '@/interfaces/i-request-builder.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\n\nexport class RequestBuilder implements IRequestBuilder {\n protected context: Context;\n\n protected request: Request;\n\n constructor(context: Context) {\n this.context = context;\n this.request = new Request(this.context);\n }\n\n public addFiles(files?: (CdnFile | string)[] | CdnFile | string): this {\n if (!(isPlainObject(files) || isString(files) || isUndefined(files) || isArray(files))) {\n throw new Error('Invalid param: \"request.files\" must be object, array, string or undefined.');\n }\n\n if (isArray(files)) {\n files.forEach((i: CdnFile | string): void => {\n if (!(isPlainObject(i) || isString(i))) {\n throw new Error('Invalid param: array \"request.files\" must contain objects or strings.');\n }\n });\n }\n\n if (isString(files)) {\n this.request.hasSingleFileResponse = true;\n\n const file: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === files,\n );\n\n if (!(file instanceof MetafileFile)) {\n throw new Error(`File not found: \"${files}\".`);\n }\n\n this.request.files = [file];\n } else if (isUndefined(files)) {\n this.request.files = [...this.context.metafile.data.files];\n } else if (isArray(files)) {\n this.request.files = files.map((file: CdnFile | string): MetafileFile => {\n let metafileFile: MetafileFile;\n\n if (isString(file)) {\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === file,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${file}\".`);\n }\n\n metafileFile = foundFile;\n } else {\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === file.id,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${file.id}\".`);\n }\n\n metafileFile = foundFile;\n }\n\n return metafileFile;\n });\n } else if (isPlainObject(files)) {\n this.request.hasSingleFileResponse = true;\n\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === files.id,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${files.id}\".`);\n }\n\n this.request.files = [foundFile];\n }\n\n return this;\n }\n\n public addLocales(locales?: string[] | string, excludeBaseLocale?: boolean): this {\n if (!(isString(locales) || isUndefined(locales) || isArray(locales))) {\n throw new Error('Invalid param: \"request.locales\" must be array, string or undefined.');\n }\n\n if (isArray(locales)) {\n locales.forEach((i: MetafileFile | string): void => {\n if (!isString(i)) {\n throw new Error('Invalid param: array \"request.locales\" must contain strings.');\n }\n });\n }\n\n if (isString(locales)) {\n this.request.hasSingleLocaleResponse = true;\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = cur.locales.filter(\n (metafileLocale: MetafileLocale): boolean => metafileLocale.locale === locales,\n );\n\n return acc;\n }, this.request.localesMap);\n } else if (isUndefined(locales)) {\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = excludeBaseLocale\n ? cur.locales.filter(\n (metafileLocale: MetafileLocale): boolean => !metafileLocale.isBaseLocale,\n )\n : cur.locales;\n\n return acc;\n }, this.request.localesMap);\n } else if (isArray(locales)) {\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = cur.locales.filter((metafileLocale: MetafileLocale) =>\n locales.includes(metafileLocale.locale),\n );\n\n return acc;\n }, this.request.localesMap);\n }\n\n return this;\n }\n\n public getCdnRequest(): Request {\n const result: Request = this.request;\n this.request = new Request(this.context);\n return result;\n }\n}\n","import { Context } from '@/cdn/context/context.js';\nimport { MetafileContext } from '@/cdn/context/metafile-context.js';\nimport { FetchHttpAdapter } from '@/cdn/http/fetch-http-adapter.js';\nimport { CdnCache } from '@/cdn/methods/cdn-cache.js';\nimport { CdnMetafile } from '@/cdn/methods/cdn-metafile.js';\nimport { RequestBuilder } from '@/cdn/request/request-builder.js';\nimport { isString } from '@/cdn/utils.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\nimport type { CdnFetchOptions } from '@/types/cdn-fetch-options.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\n\nexport class CdnClient {\n public metafile: CdnMetafile;\n\n public cache: CdnCache;\n\n protected context: Context;\n\n public static version = '__CLIENT_VERSION__';\n\n protected constructor(options: CdnClientOptions) {\n const metafileContext: MetafileContext = new MetafileContext(options);\n const client: FetchHttpAdapter = new FetchHttpAdapter(metafileContext.params.baseUrl);\n\n this.context = new Context({ metafileContext, cdn: this, client });\n this.metafile = new CdnMetafile(this.context);\n this.cache = new CdnCache(this.context);\n }\n\n public fetch = async (options?: CdnFetchOptions): Promise<CdnResponse> => {\n const { files, locales, excludeBaseLocale }: CdnFetchOptions = options || {};\n const requestBuilder: RequestBuilder = new RequestBuilder(this.context)\n .addFiles(files)\n .addLocales(locales, excludeBaseLocale);\n\n return requestBuilder.getCdnRequest().execute();\n };\n\n public static async create(options: CdnClientOptions): Promise<CdnClient> {\n if (!options) {\n throw new Error('Invalid param: missing required \"options\" parameter.');\n }\n\n if (!isString(options.metafile)) {\n throw new Error('Invalid param: \"options.metafile\" must be string.');\n }\n\n const cdn: CdnClient = new CdnClient(options);\n\n await cdn.metafile.refresh();\n\n return cdn;\n }\n}\n"],"names":[],"mappings":"AAIO,MAAM,IAAI;AAAA,EACL;AAAA,EAEV,YAAY,SAAkB;AAC5B,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAa,YAAY,SAAqD;AAC5E,QAAI,KAAK,QAAQ,MAAM,IAAI,OAAO,GAAG;AACnC,aAAO,IAAI,QAAQ,CAAC,YAAkB;AACpC,gBAAQ,KAAK,QAAQ,MAAM,IAAI,OAAO,CAAoB;AAAA,MAC5D,CAAC;AAAA,IACH;AAEA,WAAO,KAAK,QAAQ,OAAO,IAAI,QAAQ,eAAe,GAAG;AAAA,EAC3D;AAAA,EAEA,MAAa,gBAAoC;AAC/C,WAAQ,MAAM,KAAK,QAAQ,OAAO,IAAI,KAAK,QAAQ,SAAS,OAAO,QAAQ;AAAA,EAC7E;AACF;ACtBO,MAAM,mBAAwD;AAAA,EACzD;AAAA,EAEV,cAAc;AACZ,SAAK,0BAAU,IAAA;AAAA,EACjB;AAAA,EAEO,IAAI,KAAuB;A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AAM,IAAI,MAAM,sDAAsD;AAAA,IACxE;AAEA,QAAI,CAAC,SAAS,QAAQ,QAAQ,GAAG;AAC/B,YAAM,IAAI,MAAM,mDAAmD;AAAA,IACrE;AAEA,UAAM,MAAiB,IAAI,UAAU,OAAO;AAE5C,UAAM,IAAI,SAAS,QAAA;AAEnB,WAAO;AAAA,EACT;AACF;"}
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
/* @localazy/cdn-client@1.5.7
|
|
2
|
-
* (c) 2025 Localazy <team@localazy.com>
|
|
3
|
-
* @license MIT */
|
|
4
|
-
class e{context;constructor(e){this.context=e}async fetchLocale(e){return this.context.cache.has(e)?new Promise((t=>{t(this.context.cache.get(e))})):this.context.client.get(e.metafileLocale.uri)}async fetchMetafile(){return await this.context.client.get(this.context.metafile.params.jsonPath)}}class t{map;constructor(){this.map=new Map}get(e){return this.map.get(e)}has(e){return this.map.has(e)}set(e,t){this.map.set(e,t)}flush(){this.map=new Map}}const s=e=>"string"==typeof e,a=e=>void 0===e,i=e=>Array.isArray(e),l=e=>"[object Object]"===Object.prototype.toString.call(e),r=e=>[...new Set(e)],o=(e,t)=>{const s={};return e.filter((e=>{const a=t(e);return!Object.hasOwn(s,a)&&(s[a]=!0,!0)}))};class c{context;cacheAdapter;constructor(e){this.context=e,this.cacheAdapter=new t}setIfMissed(e){const{metafileFile:t,metafileLocale:s,data:a}=e,i=this.keyFromMetafile({metafileFile:t,metafileLocale:s});this.cacheAdapter.has(i)||this.cacheAdapter.set(i,a)}has(e){const t=this.keyFromMetafile(e);return this.cacheAdapter.has(t)}get(e){const t=this.keyFromMetafile(e);return this.cacheAdapter.get(t)}flush(){this.cacheAdapter.flush()}keyFromMetafile(e){const{metafileFile:t,metafileLocale:s}=e,a=[...r(t.productFlavors)].sort().join("-");return[this.context.metafile.params.cdnId,t.id,t.file,t.path,t.library,t.module,t.buildType,a,s.locale,s.timestamp.toString()].filter((e=>""!==e)).join("-")}}class n{context;constructor(e){this.context=e}createCdnResponse(e){const{requests:t,responses:s,hasSingleFileResponse:a,hasSingleLocaleResponse:i}=e;return 0===s.length||void 0===s[0]?{}:(this.cacheResponses(t,s),a&&i?s[0]:n.transformResponses(e))}cacheResponses(e,t){t.forEach(((t,s)=>{if(void 0!==e[s]){const{metafileFile:a,metafileLocale:i}=e[s];a&&i&&this.context.cache.setIfMissed({metafileFile:a,metafileLocale:i,data:t})}}))}static transformResponses(e){const{requests:t,responses:s,hasSingleFileResponse:a}=e;return s.reduce(((e,s,i)=>{if(void 0!==t[i]){const{metafileFile:l,metafileLocale:r}=t[i];l&&r&&(a?e[r.locale]=s:(e[l.id]||(e[l.id]={}),e[l.id][r.locale]=s))}return e}),{})}}class h{metafile;cdn;client;api;cache;responseFactory;constructor(t){this.metafile=t.metafileContext,this.cdn=t.cdn,this.client=t.client,this.api=new e(this),this.cache=new c(this),this.responseFactory=new n(this)}}class u{id;file;path;library;module;buildType;timestamp;productFlavors;locales;baseUrl;constructor(e){this.id=e.id,this.file=e.file,this.path=e.path,this.library=e.library,this.module=e.module,this.buildType=e.buildType,this.timestamp=e.timestamp,this.productFlavors=e.productFlavors,this.locales=e.locales,this.baseUrl=e.baseUrl}toCdnFile(){return{id:this.id,file:this.file,path:this.path,library:this.library,module:this.module,buildType:this.buildType,productFlavors:this.productFlavors,locales:this.locales.map((e=>({locale:e.locale,isBaseLocale:e.isBaseLocale,uri:`${this.baseUrl}${e.uri}`})))}}}class p{language;region;script;isRtl;name;localizedName;uri;timestamp;baseLocale;constructor(e,t){this.language=e.language,this.region=e.region,this.script=e.script,this.isRtl=e.isRtl,this.name=e.name,this.localizedName=e.localizedName,this.uri=e.uri,this.timestamp=e.timestamp,this.baseLocale=t}get locale(){return this.language&&this.region&&this.script?`${this.language}_${this.region}#${this.script}`:this.language&&this.script?`${this.language}#${this.script}`:this.language&&this.region?`${this.language}_${this.region}`:this.language}get isBaseLocale(){return this.locale===this.baseLocale}toCdnLocale(){return{locale:this.locale,isBaseLocale:this.isBaseLocale,language:this.language,region:this.region,script:this.script,isRtl:this.isRtl,name:this.name,localizedName:this.localizedName}}}class d{projectUrl;baseLocale;locales;timestamp;files;filesMap;constructor(e,t){this.projectUrl=e.projectUrl,this.timestamp=e.timestamp,this.files=d.filesFactory(e.files,e.baseLocale,t),this.filesMap=d.filesMapFactory(this.files),this.locales=d.localesFactory(this.files),this.baseLocale=this.locales.find((e=>e.isBaseLocale))}static createEmpty(e){return new d({projectUrl:"",baseLocale:"",timestamp:0,files:{}},e)}static filesFactory(e,t,s){return Object.keys(e).reduce(((a,i)=>{if(void 0!==e[i]){const l=e[i].locales.map((e=>new p(e,t)));a.push(new u({...e[i],id:i,locales:l,baseUrl:s.baseUrl}))}return a}),[])}static filesMapFactory(e){return e.reduce(((e,t)=>(e[t.id]=t,e)),{})}static localesFactory(e){const t=e.reduce(((e,t)=>(e.push(...t.locales.map((e=>e.toCdnLocale()))),e)),[]);return o(t,(e=>e.locale))}}class f{options;constructor(e){this.options=f.parseMetafileUrl(e)}get url(){return this.options.url}get baseUrl(){return this.options.baseUrl}get cdnId(){return this.options.cdnId}get jsonPath(){return this.options.jsonPath}static parseMetafileUrl(e){let t;try{t=new URL(e)}catch{throw new Error('Invalid param: "options.metafile" cannot be parsed as url.')}const s=/^\/(.*?)\/(.*?)\.(v2.json|js|ts)$/.exec(t.pathname);if(null===s||4!==s.length||void 0===s[1]||void 0===s[2])throw new Error('Invalid param: "options.metafile" contains invalid metafile url.');const a=s[1],i=s[2];return{url:e,baseUrl:t.origin,cdnId:a,jsonPath:`/${a}/${i}.v2.json`}}}class m{params;parsedData;data;constructor(e){this.params=new f(e.metafile),this.parsedData=null,this.data=d.createEmpty(this.params)}setMetafile(e){this.parsedData=e,this.data=new d(e,this.params)}}class g{baseUrl;constructor(e){this.baseUrl=e}async get(e){const t=await fetch(`${this.baseUrl}${e}`),s=t.headers.get("content-type"),a="application/json5"===s||"application/json"===s;if(t.status>=400)throw new Error(`Request failed with status code ${t.status.toString()}`);let i;return i=a?await t.json():await t.text(),i}}class w{context;constructor(e){this.context=e}}class x extends w{flush=()=>{this.context.cache.flush()}}class y extends w{get projectUrl(){return this.context.metafile.data.projectUrl}get baseLocale(){return this.context.metafile.data.baseLocale}get url(){return this.context.metafile.params.url}get files(){return this.context.metafile.data.files.map((e=>e.toCdnFile()))}locales=e=>{const{excludeBaseLocale:t}=e||{},{locales:s}=this.context.metafile.data;return t?s.filter((e=>!e.isBaseLocale)):s};refresh=async()=>{const e=await this.context.api.fetchMetafile();this.context.metafile.setMetafile(e)};switch=async e=>{this.context.metafile.params=new f(e.metafile),await this.refresh()}}class b{data;context;constructor(e){this.context=e.context,this.data=e.data||{}}}class F{files;localesMap;hasSingleFileResponse;hasSingleLocaleResponse;context;constructor(e){this.files=[],this.localesMap=new b({context:e}),this.hasSingleFileResponse=!1,this.hasSingleLocaleResponse=!1,this.context=e}async execute(){const e=this.getPromises(),t=e.map((e=>e[0])),s=e.map((e=>e[1])),a=await Promise.all(t);return this.context.responseFactory.createCdnResponse({requests:s,responses:a,localesMap:this.localesMap,hasSingleFileResponse:this.hasSingleFileResponse,hasSingleLocaleResponse:this.hasSingleLocaleResponse})}getPromises(){return this.files.reduce(((e,t)=>(void 0!==this.localesMap.data?.[t.id]&&e.push(...this.localesMap.data[t.id].map((e=>{const s={metafileFile:t,metafileLocale:e};return[this.context.api.fetchLocale(s),s]}))),e)),[])}}class L{context;request;constructor(e){this.context=e,this.request=new F(this.context)}addFiles(e){if(!(l(e)||s(e)||a(e)||i(e)))throw new Error('Invalid param: "request.files" must be object, array, string or undefined.');if(i(e)&&e.forEach((e=>{if(!l(e)&&!s(e))throw new Error('Invalid param: array "request.files" must contain objects or strings.')})),s(e)){this.request.hasSingleFileResponse=!0;const t=this.context.metafile.data.files.find((t=>t.id===e));if(!(t instanceof u))throw new Error(`File not found: "${e}".`);this.request.files=[t]}else if(a(e))this.request.files=[...this.context.metafile.data.files];else if(i(e))this.request.files=e.map((e=>{let t;if(s(e)){const s=this.context.metafile.data.files.find((t=>t.id===e));if(a(s))throw new Error(`File not found: "${e}".`);t=s}else{const s=this.context.metafile.data.files.find((t=>t.id===e.id));if(a(s))throw new Error(`File not found: "${e.id}".`);t=s}return t}));else if(l(e)){this.request.hasSingleFileResponse=!0;const t=this.context.metafile.data.files.find((t=>t.id===e.id));if(a(t))throw new Error(`File not found: "${e.id}".`);this.request.files=[t]}return this}addLocales(e,t){if(!(s(e)||a(e)||i(e)))throw new Error('Invalid param: "request.locales" must be array, string or undefined.');return i(e)&&e.forEach((e=>{if(!s(e))throw new Error('Invalid param: array "request.locales" must contain strings.')})),s(e)?(this.request.hasSingleLocaleResponse=!0,this.request.files.reduce(((t,s)=>(t.data[s.id]=s.locales.filter((t=>t.locale===e)),t)),this.request.localesMap)):a(e)?this.request.files.reduce(((e,s)=>(e.data[s.id]=t?s.locales.filter((e=>!e.isBaseLocale)):s.locales,e)),this.request.localesMap):i(e)&&this.request.files.reduce(((t,s)=>(t.data[s.id]=s.locales.filter((t=>e.includes(t.locale))),t)),this.request.localesMap),this}getCdnRequest(){const e=this.request;return this.request=new F(this.context),e}}class R{metafile;cache;context;static version="1.5.7";constructor(e){const t=new m(e),s=new g(t.params.baseUrl);this.context=new h({metafileContext:t,cdn:this,client:s}),this.metafile=new y(this.context),this.cache=new x(this.context)}fetch=async e=>{const{files:t,locales:s,excludeBaseLocale:a}=e||{};return new L(this.context).addFiles(t).addLocales(s,a).getCdnRequest().execute()};static async create(e){if(!e)throw new Error('Invalid param: missing required "options" parameter.');if(!s(e.metafile))throw new Error('Invalid param: "options.metafile" must be string.');const t=new R(e);return await t.metafile.refresh(),t}}export{e as Api,w as CdnBase,x as CdnCache,R as CdnClient,y as CdnMetafile,h as Context,g as FetchHttpAdapter,c as LocalesCache,b as LocalesMap,t as MemoryCacheAdapter,m as MetafileContext,d as MetafileData,u as MetafileFile,p as MetafileLocale,f as MetafileParams,F as Request,L as RequestBuilder,n as ResponseFactory,i as isArray,l as isPlainObject,s as isString,a as isUndefined,r as uniq,o as uniqBy};
|
|
1
|
+
class e{context;constructor(e){this.context=e}async fetchLocale(e){return this.context.cache.has(e)?new Promise((t=>{t(this.context.cache.get(e))})):this.context.client.get(e.metafileLocale.uri)}async fetchMetafile(){return await this.context.client.get(this.context.metafile.params.jsonPath)}}class t{map;constructor(){this.map=new Map}get(e){return this.map.get(e)}has(e){return this.map.has(e)}set(e,t){this.map.set(e,t)}flush(){this.map=new Map}}const s=e=>"string"==typeof e,a=e=>void 0===e,i=e=>Array.isArray(e),l=e=>"[object Object]"===Object.prototype.toString.call(e),r=e=>[...new Set(e)],o=(e,t)=>{const s={};return e.filter((e=>{const a=t(e);return!Object.hasOwn(s,a)&&(s[a]=!0,!0)}))};class c{context;cacheAdapter;constructor(e){this.context=e,this.cacheAdapter=new t}setIfMissed(e){const{metafileFile:t,metafileLocale:s,data:a}=e,i=this.keyFromMetafile({metafileFile:t,metafileLocale:s});this.cacheAdapter.has(i)||this.cacheAdapter.set(i,a)}has(e){const t=this.keyFromMetafile(e);return this.cacheAdapter.has(t)}get(e){const t=this.keyFromMetafile(e);return this.cacheAdapter.get(t)}flush(){this.cacheAdapter.flush()}keyFromMetafile(e){const{metafileFile:t,metafileLocale:s}=e,a=[...r(t.productFlavors)].sort().join("-");return[this.context.metafile.params.cdnId,t.id,t.file,t.path,t.library,t.module,t.buildType,a,s.locale,s.timestamp.toString()].filter((e=>""!==e)).join("-")}}class n{context;constructor(e){this.context=e}createCdnResponse(e){const{requests:t,responses:s,hasSingleFileResponse:a,hasSingleLocaleResponse:i}=e;return 0===s.length||void 0===s[0]?{}:(this.cacheResponses(t,s),a&&i?s[0]:n.transformResponses(e))}cacheResponses(e,t){t.forEach(((t,s)=>{if(void 0!==e[s]){const{metafileFile:a,metafileLocale:i}=e[s];a&&i&&this.context.cache.setIfMissed({metafileFile:a,metafileLocale:i,data:t})}}))}static transformResponses(e){const{requests:t,responses:s,hasSingleFileResponse:a}=e;return s.reduce(((e,s,i)=>{if(void 0!==t[i]){const{metafileFile:l,metafileLocale:r}=t[i];l&&r&&(a?e[r.locale]=s:(e[l.id]||(e[l.id]={}),e[l.id][r.locale]=s))}return e}),{})}}class h{metafile;cdn;client;api;cache;responseFactory;constructor(t){this.metafile=t.metafileContext,this.cdn=t.cdn,this.client=t.client,this.api=new e(this),this.cache=new c(this),this.responseFactory=new n(this)}}class u{id;file;path;library;module;buildType;timestamp;productFlavors;locales;baseUrl;constructor(e){this.id=e.id,this.file=e.file,this.path=e.path,this.library=e.library,this.module=e.module,this.buildType=e.buildType,this.timestamp=e.timestamp,this.productFlavors=e.productFlavors,this.locales=e.locales,this.baseUrl=e.baseUrl}toCdnFile(){return{id:this.id,file:this.file,path:this.path,library:this.library,module:this.module,buildType:this.buildType,productFlavors:this.productFlavors,locales:this.locales.map((e=>({locale:e.locale,isBaseLocale:e.isBaseLocale,uri:`${this.baseUrl}${e.uri}`})))}}}class p{language;region;script;isRtl;name;localizedName;uri;timestamp;baseLocale;constructor(e,t){this.language=e.language,this.region=e.region,this.script=e.script,this.isRtl=e.isRtl,this.name=e.name,this.localizedName=e.localizedName,this.uri=e.uri,this.timestamp=e.timestamp,this.baseLocale=t}get locale(){return this.language&&this.region&&this.script?`${this.language}_${this.region}#${this.script}`:this.language&&this.script?`${this.language}#${this.script}`:this.language&&this.region?`${this.language}_${this.region}`:this.language}get isBaseLocale(){return this.locale===this.baseLocale}toCdnLocale(){return{locale:this.locale,isBaseLocale:this.isBaseLocale,language:this.language,region:this.region,script:this.script,isRtl:this.isRtl,name:this.name,localizedName:this.localizedName}}}class d{projectUrl;baseLocale;locales;timestamp;files;filesMap;constructor(e,t){this.projectUrl=e.projectUrl,this.timestamp=e.timestamp,this.files=d.filesFactory(e.files,e.baseLocale,t),this.filesMap=d.filesMapFactory(this.files),this.locales=d.localesFactory(this.files),this.baseLocale=this.locales.find((e=>e.isBaseLocale))}static createEmpty(e){return new d({projectUrl:"",baseLocale:"",timestamp:0,files:{}},e)}static filesFactory(e,t,s){return Object.keys(e).reduce(((a,i)=>{if(void 0!==e[i]){const l=e[i].locales.map((e=>new p(e,t)));a.push(new u({...e[i],id:i,locales:l,baseUrl:s.baseUrl}))}return a}),[])}static filesMapFactory(e){return e.reduce(((e,t)=>(e[t.id]=t,e)),{})}static localesFactory(e){const t=e.reduce(((e,t)=>(e.push(...t.locales.map((e=>e.toCdnLocale()))),e)),[]);return o(t,(e=>e.locale))}}class f{options;constructor(e){this.options=f.parseMetafileUrl(e)}get url(){return this.options.url}get baseUrl(){return this.options.baseUrl}get cdnId(){return this.options.cdnId}get jsonPath(){return this.options.jsonPath}static parseMetafileUrl(e){let t;try{t=new URL(e)}catch{throw new Error('Invalid param: "options.metafile" cannot be parsed as url.')}const s=/^\/(.*?)\/(.*?)\.(v2.json|js|ts)$/.exec(t.pathname);if(null===s||4!==s.length||void 0===s[1]||void 0===s[2])throw new Error('Invalid param: "options.metafile" contains invalid metafile url.');const a=s[1],i=s[2];return{url:e,baseUrl:t.origin,cdnId:a,jsonPath:`/${a}/${i}.v2.json`}}}class m{params;parsedData;data;constructor(e){this.params=new f(e.metafile),this.parsedData=null,this.data=d.createEmpty(this.params)}setMetafile(e){this.parsedData=e,this.data=new d(e,this.params)}}class g{baseUrl;constructor(e){this.baseUrl=e}async get(e){const t=await fetch(`${this.baseUrl}${e}`),s=t.headers.get("content-type"),a="application/json5"===s||"application/json"===s;if(t.status>=400)throw new Error(`Request failed with status code ${t.status.toString()}`);let i;return i=a?await t.json():await t.text(),i}}class w{context;constructor(e){this.context=e}}class x extends w{flush=()=>{this.context.cache.flush()}}class y extends w{get projectUrl(){return this.context.metafile.data.projectUrl}get baseLocale(){return this.context.metafile.data.baseLocale}get url(){return this.context.metafile.params.url}get files(){return this.context.metafile.data.files.map((e=>e.toCdnFile()))}locales=e=>{const{excludeBaseLocale:t}=e||{},{locales:s}=this.context.metafile.data;return t?s.filter((e=>!e.isBaseLocale)):s};refresh=async()=>{const e=await this.context.api.fetchMetafile();this.context.metafile.setMetafile(e)};switch=async e=>{this.context.metafile.params=new f(e.metafile),await this.refresh()}}class b{data;context;constructor(e){this.context=e.context,this.data=e.data||{}}}class F{files;localesMap;hasSingleFileResponse;hasSingleLocaleResponse;context;constructor(e){this.files=[],this.localesMap=new b({context:e}),this.hasSingleFileResponse=!1,this.hasSingleLocaleResponse=!1,this.context=e}async execute(){const e=this.getPromises(),t=e.map((e=>e[0])),s=e.map((e=>e[1])),a=await Promise.all(t);return this.context.responseFactory.createCdnResponse({requests:s,responses:a,localesMap:this.localesMap,hasSingleFileResponse:this.hasSingleFileResponse,hasSingleLocaleResponse:this.hasSingleLocaleResponse})}getPromises(){return this.files.reduce(((e,t)=>(void 0!==this.localesMap.data?.[t.id]&&e.push(...this.localesMap.data[t.id].map((e=>{const s={metafileFile:t,metafileLocale:e};return[this.context.api.fetchLocale(s),s]}))),e)),[])}}class L{context;request;constructor(e){this.context=e,this.request=new F(this.context)}addFiles(e){if(!(l(e)||s(e)||a(e)||i(e)))throw new Error('Invalid param: "request.files" must be object, array, string or undefined.');if(i(e)&&e.forEach((e=>{if(!l(e)&&!s(e))throw new Error('Invalid param: array "request.files" must contain objects or strings.')})),s(e)){this.request.hasSingleFileResponse=!0;const t=this.context.metafile.data.files.find((t=>t.id===e));if(!(t instanceof u))throw new Error(`File not found: "${e}".`);this.request.files=[t]}else if(a(e))this.request.files=[...this.context.metafile.data.files];else if(i(e))this.request.files=e.map((e=>{let t;if(s(e)){const s=this.context.metafile.data.files.find((t=>t.id===e));if(a(s))throw new Error(`File not found: "${e}".`);t=s}else{const s=this.context.metafile.data.files.find((t=>t.id===e.id));if(a(s))throw new Error(`File not found: "${e.id}".`);t=s}return t}));else if(l(e)){this.request.hasSingleFileResponse=!0;const t=this.context.metafile.data.files.find((t=>t.id===e.id));if(a(t))throw new Error(`File not found: "${e.id}".`);this.request.files=[t]}return this}addLocales(e,t){if(!(s(e)||a(e)||i(e)))throw new Error('Invalid param: "request.locales" must be array, string or undefined.');return i(e)&&e.forEach((e=>{if(!s(e))throw new Error('Invalid param: array "request.locales" must contain strings.')})),s(e)?(this.request.hasSingleLocaleResponse=!0,this.request.files.reduce(((t,s)=>(t.data[s.id]=s.locales.filter((t=>t.locale===e)),t)),this.request.localesMap)):a(e)?this.request.files.reduce(((e,s)=>(e.data[s.id]=t?s.locales.filter((e=>!e.isBaseLocale)):s.locales,e)),this.request.localesMap):i(e)&&this.request.files.reduce(((t,s)=>(t.data[s.id]=s.locales.filter((t=>e.includes(t.locale))),t)),this.request.localesMap),this}getCdnRequest(){const e=this.request;return this.request=new F(this.context),e}}class R{metafile;cache;context;static version="1.5.9";constructor(e){const t=new m(e),s=new g(t.params.baseUrl);this.context=new h({metafileContext:t,cdn:this,client:s}),this.metafile=new y(this.context),this.cache=new x(this.context)}fetch=async e=>{const{files:t,locales:s,excludeBaseLocale:a}=e||{};return new L(this.context).addFiles(t).addLocales(s,a).getCdnRequest().execute()};static async create(e){if(!e)throw new Error('Invalid param: missing required "options" parameter.');if(!s(e.metafile))throw new Error('Invalid param: "options.metafile" must be string.');const t=new R(e);return await t.metafile.refresh(),t}}export{e as Api,w as CdnBase,x as CdnCache,R as CdnClient,y as CdnMetafile,h as Context,g as FetchHttpAdapter,c as LocalesCache,b as LocalesMap,t as MemoryCacheAdapter,m as MetafileContext,d as MetafileData,u as MetafileFile,p as MetafileLocale,f as MetafileParams,F as Request,L as RequestBuilder,n as ResponseFactory,i as isArray,l as isPlainObject,s as isString,a as isUndefined,r as uniq,o as uniqBy};
|
|
5
2
|
//# sourceMappingURL=localazy-cdn-client.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localazy-cdn-client.min.js","sources":["../src/cdn/api/api.ts","../src/cdn/cache/memory-cache-adapter.ts","../src/cdn/utils.ts","../src/cdn/cache/locales-cache.ts","../src/cdn/response/response-factory.ts","../src/cdn/context/context.ts","../src/cdn/metafile/metafile-file.ts","../src/cdn/metafile/metafile-locale.ts","../src/cdn/metafile/metafile-data.ts","../src/cdn/metafile/metafile-params.ts","../src/cdn/context/metafile-context.ts","../src/cdn/http/fetch-http-adapter.ts","../src/cdn/methods/cdn-base.ts","../src/cdn/methods/cdn-cache.ts","../src/cdn/methods/cdn-metafile.ts","../src/cdn/request/locales-map.ts","../src/cdn/request/request.ts","../src/cdn/request/request-builder.ts","../src/cdn/cdn-client.ts"],"sourcesContent":["import type { Context } from '@/cdn/context/context.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\n\nexport class Api {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n\n public async fetchLocale(options: ApiLocaleRequest): Promise<object | string> {\n if (this.context.cache.has(options)) {\n return new Promise((resolve): void => {\n resolve(this.context.cache.get(options) as object | string);\n });\n }\n\n return this.context.client.get(options.metafileLocale.uri);\n }\n\n public async fetchMetafile(): Promise<IMetafile> {\n return (await this.context.client.get(this.context.metafile.params.jsonPath)) as IMetafile;\n }\n}\n","import type { ICacheAdapter } from '@/interfaces/i-cache-adapter.js';\n\nexport class MemoryCacheAdapter<K, V> implements ICacheAdapter<K, V> {\n protected map: Map<K, V>;\n\n constructor() {\n this.map = new Map();\n }\n\n public get(key: K): V | undefined {\n return this.map.get(key);\n }\n\n public has(key: K): boolean {\n return this.map.has(key);\n }\n\n public set(key: K, value: V): void {\n this.map.set(key, value);\n }\n\n public flush(): void {\n this.map = new Map();\n }\n}\n","export const isString = (value: unknown): value is string => typeof value === 'string';\n\nexport const isUndefined = (value: unknown): value is undefined => typeof value === 'undefined';\n\nexport const isArray = <T>(value: unknown): value is T[] => Array.isArray(value);\n\nexport const isPlainObject = (value: unknown): value is Record<string, unknown> =>\n Object.prototype.toString.call(value) === '[object Object]';\n\nexport const uniq = <T>(array: T[]): T[] => [...new Set(array)];\n\nexport const uniqBy = <T>(array: T[], predicate: (item: T) => string): T[] => {\n const seen: Record<string, boolean> = {};\n\n return array.filter((item: T): boolean => {\n const key: string = predicate(item);\n\n if (!Object.hasOwn(seen, key)) {\n seen[key] = true;\n\n return true;\n }\n\n return false;\n });\n};\n","import { MemoryCacheAdapter } from '@/cdn/cache/memory-cache-adapter.js';\nimport type { Context } from '@/cdn/context/context.js';\nimport { uniq } from '@/cdn/utils.js';\nimport type { ICacheAdapter } from '@/interfaces/i-cache-adapter.js';\nimport type { CacheGetLocalesRequest } from '@/types/cache-get-locales-request.js';\nimport type { CacheHasLocalesRequest } from '@/types/cache-has-locales-request.js';\nimport type { CacheKeyMetafileOptions } from '@/types/cache-key-metafile-options.js';\nimport type { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request.js';\n\nexport class LocalesCache {\n protected context: Context;\n\n protected cacheAdapter: ICacheAdapter<string, object | string>;\n\n constructor(context: Context) {\n this.context = context;\n this.cacheAdapter = new MemoryCacheAdapter();\n }\n\n public setIfMissed(options: CacheStoreLocalesRequest): void {\n const { metafileFile, metafileLocale, data }: CacheStoreLocalesRequest = options;\n\n const key: string = this.keyFromMetafile({\n metafileFile,\n metafileLocale,\n });\n\n if (!this.cacheAdapter.has(key)) {\n this.cacheAdapter.set(key, data);\n }\n }\n\n public has(options: CacheHasLocalesRequest): boolean {\n const key: string = this.keyFromMetafile(options);\n\n return this.cacheAdapter.has(key);\n }\n\n public get(options: CacheGetLocalesRequest): object | string | undefined {\n const key: string = this.keyFromMetafile(options);\n\n return this.cacheAdapter.get(key);\n }\n\n public flush(): void {\n this.cacheAdapter.flush();\n }\n\n protected keyFromMetafile(options: CacheKeyMetafileOptions): string {\n const { metafileFile, metafileLocale }: CacheKeyMetafileOptions = options;\n const productFlavors: string = [...uniq(metafileFile.productFlavors)].sort().join('-');\n\n const indices: string[] = [\n this.context.metafile.params.cdnId,\n metafileFile.id,\n metafileFile.file,\n metafileFile.path,\n metafileFile.library,\n metafileFile.module,\n metafileFile.buildType,\n productFlavors,\n metafileLocale.locale,\n metafileLocale.timestamp.toString(),\n ];\n\n return indices.filter((key: string): boolean => key !== '').join('-');\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\nimport type { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\nimport type { ResponseFactoryOptions } from '@/types/response-factory-options.js';\n\nexport class ResponseFactory {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n\n public createCdnResponse(options: ResponseFactoryOptions): CdnResponse {\n const {\n requests,\n responses,\n hasSingleFileResponse,\n hasSingleLocaleResponse,\n }: ResponseFactoryOptions = options;\n\n if (responses.length === 0 || typeof responses[0] === 'undefined') {\n return {};\n }\n\n this.cacheResponses(requests, responses);\n\n return hasSingleFileResponse && hasSingleLocaleResponse\n ? responses[0]\n : ResponseFactory.transformResponses(options);\n }\n\n protected cacheResponses(requests: ApiLocaleRequest[], responses: (object | string)[]): void {\n responses.forEach((response: object | string, index: number): void => {\n if (typeof requests[index] !== 'undefined') {\n const { metafileFile, metafileLocale }: Partial<CacheStoreLocalesRequest> = requests[index];\n\n if (metafileFile && metafileLocale) {\n this.context.cache.setIfMissed({ metafileFile, metafileLocale, data: response });\n }\n }\n });\n }\n\n protected static transformResponses(options: ResponseFactoryOptions): CdnResponse {\n const { requests, responses, hasSingleFileResponse }: ResponseFactoryOptions = options;\n\n return responses.reduce((acc: CdnResponse, cur: object | string, index: number) => {\n if (typeof requests[index] !== 'undefined') {\n const { metafileFile, metafileLocale }: Partial<CacheStoreLocalesRequest> = requests[index];\n\n if (metafileFile && metafileLocale) {\n if (hasSingleFileResponse) {\n // @ts-expect-error fix output type\n acc[metafileLocale.locale] = cur;\n } else {\n // @ts-expect-error fix output type\n if (!acc[metafileFile.id]) {\n // @ts-expect-error fix output type\n acc[metafileFile.id] = {};\n }\n\n // @ts-expect-error fix output type\n acc[metafileFile.id][metafileLocale.locale] = cur;\n }\n }\n }\n\n return acc;\n }, {});\n }\n}\n","import { Api } from '@/cdn/api/api.js';\nimport { LocalesCache } from '@/cdn/cache/locales-cache.js';\nimport type { CdnClient } from '@/cdn/cdn-client.js';\nimport type { MetafileContext } from '@/cdn/context/metafile-context.js';\nimport { ResponseFactory } from '@/cdn/response/response-factory.js';\nimport type { IHttpAdapter } from '@/interfaces/i-http-adapter.js';\nimport type { ContextOptions } from '@/types/context-options.js';\n\nexport class Context {\n public metafile: MetafileContext;\n\n public cdn: CdnClient;\n\n public client: IHttpAdapter;\n\n public api: Api;\n\n public cache: LocalesCache;\n\n public responseFactory: ResponseFactory;\n\n constructor(options: ContextOptions) {\n this.metafile = options.metafileContext;\n this.cdn = options.cdn;\n this.client = options.client;\n this.api = new Api(this);\n this.cache = new LocalesCache(this);\n this.responseFactory = new ResponseFactory(this);\n }\n}\n","import type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { IMetafileFile } from '@/interfaces/i-metafile-file.js';\nimport type { CdnFileLocale } from '@/types/cdn-file-locale.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\nimport type { MetafileFileOptions } from '@/types/metafile-file-options.js';\n\nexport class MetafileFile implements Omit<IMetafileFile, 'locales'> {\n public id: string;\n\n public file: string;\n\n public path: string;\n\n public library: string;\n\n public module: string;\n\n public buildType: string;\n\n public timestamp: number;\n\n public productFlavors: string[];\n\n public locales: MetafileLocale[];\n\n protected baseUrl: string;\n\n constructor(options: MetafileFileOptions) {\n this.id = options.id;\n this.file = options.file;\n this.path = options.path;\n this.library = options.library;\n this.module = options.module;\n this.buildType = options.buildType;\n this.timestamp = options.timestamp;\n this.productFlavors = options.productFlavors;\n this.locales = options.locales;\n this.baseUrl = options.baseUrl;\n }\n\n public toCdnFile(): CdnFile {\n return {\n id: this.id,\n file: this.file,\n path: this.path,\n library: this.library,\n module: this.module,\n buildType: this.buildType,\n productFlavors: this.productFlavors,\n locales: this.locales.map(\n (locale: MetafileLocale): CdnFileLocale => ({\n locale: locale.locale,\n isBaseLocale: locale.isBaseLocale,\n uri: `${this.baseUrl}${locale.uri}`,\n }),\n ),\n };\n }\n}\n","import type { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\n\nexport class MetafileLocale implements IMetafileFileLocale {\n public language: string;\n\n public region: string;\n\n public script: string;\n\n public isRtl: boolean;\n\n public name: string;\n\n public localizedName: string;\n\n public uri: string;\n\n public timestamp: number;\n\n protected baseLocale: string;\n\n constructor(options: IMetafileFileLocale, baseLocale: string) {\n this.language = options.language;\n this.region = options.region;\n this.script = options.script;\n this.isRtl = options.isRtl;\n this.name = options.name;\n this.localizedName = options.localizedName;\n this.uri = options.uri;\n this.timestamp = options.timestamp;\n this.baseLocale = baseLocale;\n }\n\n get locale(): string {\n if (this.language && this.region && this.script) {\n return `${this.language}_${this.region}#${this.script}`;\n }\n\n if (this.language && this.script) {\n return `${this.language}#${this.script}`;\n }\n\n if (this.language && this.region) {\n return `${this.language}_${this.region}`;\n }\n\n return this.language;\n }\n\n get isBaseLocale(): boolean {\n return this.locale === this.baseLocale;\n }\n\n public toCdnLocale(): CdnLocale {\n return {\n locale: this.locale,\n isBaseLocale: this.isBaseLocale,\n language: this.language,\n region: this.region,\n script: this.script,\n isRtl: this.isRtl,\n name: this.name,\n localizedName: this.localizedName,\n };\n }\n}\n","import { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport { uniqBy } from '@/cdn/utils.js';\nimport type { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale.js';\nimport type { IMetafileFiles } from '@/interfaces/i-metafile-files.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\nimport type { FilesMap } from '@/types/files-map.js';\nimport type { MetafileOptions } from '@/types/metafile-options.js';\n\nexport class MetafileData implements Omit<IMetafile, 'files' | 'baseLocale'> {\n public projectUrl: string;\n\n public baseLocale: CdnLocale;\n\n public locales: CdnLocale[];\n\n public timestamp: number;\n\n public files: MetafileFile[];\n\n public filesMap: FilesMap;\n\n constructor(options: MetafileOptions, params: MetafileParams) {\n this.projectUrl = options.projectUrl;\n this.timestamp = options.timestamp;\n this.files = MetafileData.filesFactory(options.files, options.baseLocale, params);\n this.filesMap = MetafileData.filesMapFactory(this.files);\n this.locales = MetafileData.localesFactory(this.files);\n this.baseLocale = this.locales.find((locale: CdnLocale) => locale.isBaseLocale) as CdnLocale;\n }\n\n public static createEmpty(params: MetafileParams): MetafileData {\n return new MetafileData(\n {\n projectUrl: '',\n baseLocale: '',\n timestamp: 0,\n files: {},\n },\n params,\n );\n }\n\n protected static filesFactory(\n files: IMetafileFiles,\n baseLocale: string,\n params: MetafileParams,\n ): MetafileFile[] {\n return Object.keys(files).reduce((acc: MetafileFile[], cur: string) => {\n if (typeof files[cur] !== 'undefined') {\n const locales: MetafileLocale[] = files[cur].locales.map(\n (locale: IMetafileFileLocale) => new MetafileLocale(locale, baseLocale),\n );\n\n acc.push(\n new MetafileFile({\n ...files[cur],\n id: cur,\n locales,\n baseUrl: params.baseUrl,\n }),\n );\n }\n\n return acc;\n }, []);\n }\n\n protected static filesMapFactory(files: MetafileFile[]): FilesMap {\n return files.reduce((acc: FilesMap, cur: MetafileFile) => {\n acc[cur.id] = cur;\n\n return acc;\n }, {});\n }\n\n protected static localesFactory(files: MetafileFile[]): CdnLocale[] {\n const locales: CdnLocale[] = files.reduce((acc: CdnLocale[], cur: MetafileFile) => {\n acc.push(...cur.locales.map((locale: MetafileLocale): CdnLocale => locale.toCdnLocale()));\n return acc;\n }, []);\n\n return uniqBy(locales, (cdnLocale: CdnLocale): string => cdnLocale.locale);\n }\n}\n","import type { IMetafileParams } from '@/interfaces/i-metafile-params.js';\n\nexport class MetafileParams implements IMetafileParams {\n protected options: IMetafileParams;\n\n constructor(metafileUrl: string) {\n this.options = MetafileParams.parseMetafileUrl(metafileUrl);\n }\n\n get url(): string {\n return this.options.url;\n }\n\n get baseUrl(): string {\n return this.options.baseUrl;\n }\n\n get cdnId(): string {\n return this.options.cdnId;\n }\n\n get jsonPath(): string {\n return this.options.jsonPath;\n }\n\n protected static parseMetafileUrl(metafileUrl: string): IMetafileParams {\n let url: URL;\n\n try {\n url = new URL(metafileUrl);\n } catch {\n throw new Error('Invalid param: \"options.metafile\" cannot be parsed as url.');\n }\n\n const matches: string[] | null = /^\\/(.*?)\\/(.*?)\\.(v2.json|js|ts)$/.exec(url.pathname);\n\n if (\n matches === null ||\n matches.length !== 4 ||\n typeof matches[1] === 'undefined' ||\n typeof matches[2] === 'undefined'\n ) {\n throw new Error('Invalid param: \"options.metafile\" contains invalid metafile url.');\n }\n\n const cdnId: string = matches[1];\n const tagId: string = matches[2];\n\n return {\n url: metafileUrl,\n baseUrl: url.origin,\n cdnId,\n jsonPath: `/${cdnId}/${tagId}.v2.json`,\n };\n }\n}\n","import { MetafileData } from '@/cdn/metafile/metafile-data.js';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\n\nexport class MetafileContext {\n public params: MetafileParams;\n\n public parsedData: IMetafile | null;\n\n public data: MetafileData;\n\n constructor(options: CdnClientOptions) {\n this.params = new MetafileParams(options.metafile);\n this.parsedData = null;\n this.data = MetafileData.createEmpty(this.params);\n }\n\n public setMetafile(metafile: IMetafile): void {\n this.parsedData = metafile;\n\n this.data = new MetafileData(metafile, this.params);\n }\n}\n","import type { IHttpAdapter } from '@/interfaces/i-http-adapter.js';\n\nexport class FetchHttpAdapter implements IHttpAdapter {\n protected baseUrl: string;\n\n constructor(baseUrl: string) {\n this.baseUrl = baseUrl;\n }\n\n async get(url: string): Promise<string | object> {\n const response: Response = await fetch(`${this.baseUrl}${url}`);\n const contentType: string | null = response.headers.get('content-type');\n const isJson: boolean =\n contentType === 'application/json5' || contentType === 'application/json';\n\n if (response.status >= 400) {\n throw new Error(`Request failed with status code ${response.status.toString()}`);\n }\n\n let result: string | object;\n\n if (isJson) {\n result = (await response.json()) as object;\n } else {\n result = await response.text();\n }\n\n return result;\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\n\nexport abstract class CdnBase {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n}\n","import { CdnBase } from '@/cdn/methods/cdn-base.js';\n\nexport class CdnCache extends CdnBase {\n public flush = (): void => {\n this.context.cache.flush();\n };\n}\n","import type { MetafileData } from '@/cdn/metafile/metafile-data.js';\nimport type { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport { CdnBase } from '@/cdn/methods/cdn-base.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\nimport type { CdnLocalesOptions } from '@/types/cdn-locales-options.js';\n\nexport class CdnMetafile extends CdnBase {\n get projectUrl(): string {\n return this.context.metafile.data.projectUrl;\n }\n\n get baseLocale(): CdnLocale {\n return this.context.metafile.data.baseLocale;\n }\n\n get url(): string {\n return this.context.metafile.params.url;\n }\n\n get files(): CdnFile[] {\n return this.context.metafile.data.files.map((file: MetafileFile): CdnFile => file.toCdnFile());\n }\n\n public locales = (options?: CdnLocalesOptions): CdnLocale[] => {\n const { excludeBaseLocale }: CdnLocalesOptions = options || {};\n const { locales }: MetafileData = this.context.metafile.data;\n\n return excludeBaseLocale\n ? locales.filter((cdnLocale: CdnLocale): boolean => !cdnLocale.isBaseLocale)\n : locales;\n };\n\n public refresh = async (): Promise<void> => {\n const response: IMetafile = await this.context.api.fetchMetafile();\n\n this.context.metafile.setMetafile(response);\n };\n\n public switch = async (options: CdnClientOptions): Promise<void> => {\n this.context.metafile.params = new MetafileParams(options.metafile);\n\n await this.refresh();\n };\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { LocalesMapData } from '@/types/locales-map-data.js';\nimport type { LocalesMapOptions } from '@/types/locales-map-options.js';\n\nexport class LocalesMap {\n public data: LocalesMapData;\n\n protected context: Context;\n\n constructor(options: LocalesMapOptions) {\n this.context = options.context;\n this.data = options.data || {};\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport { LocalesMap } from '@/cdn/request/locales-map.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\n\nexport class Request {\n public files: MetafileFile[];\n\n public localesMap: LocalesMap;\n\n public hasSingleFileResponse: boolean;\n\n public hasSingleLocaleResponse: boolean;\n\n protected context: Context;\n\n constructor(context: Context) {\n this.files = [];\n this.localesMap = new LocalesMap({ context });\n this.hasSingleFileResponse = false;\n this.hasSingleLocaleResponse = false;\n this.context = context;\n }\n\n public async execute(): Promise<CdnResponse> {\n const payload: [Promise<string | object>, ApiLocaleRequest][] = this.getPromises();\n const promises: Promise<string | object>[] = payload.map(\n (item: [Promise<string | object>, ApiLocaleRequest]) => item[0],\n );\n const requests: ApiLocaleRequest[] = payload.map(\n (item: [Promise<string | object>, ApiLocaleRequest]) => item[1],\n );\n const responses: (string | object)[] = await Promise.all(promises);\n\n return this.context.responseFactory.createCdnResponse({\n requests,\n responses,\n localesMap: this.localesMap,\n hasSingleFileResponse: this.hasSingleFileResponse,\n hasSingleLocaleResponse: this.hasSingleLocaleResponse,\n });\n }\n\n protected getPromises(): [Promise<string | object>, ApiLocaleRequest][] {\n return this.files.reduce(\n (acc: [Promise<string | object>, ApiLocaleRequest][], cur: MetafileFile) => {\n if (typeof this.localesMap.data?.[cur.id] !== 'undefined') {\n acc.push(\n // @ts-expect-error TODO fix type\n ...this.localesMap.data[cur.id].map(\n (metafileLocale: MetafileLocale): [Promise<string | object>, ApiLocaleRequest] => {\n const request: ApiLocaleRequest = {\n metafileFile: cur,\n metafileLocale,\n };\n\n return [this.context.api.fetchLocale(request), request];\n },\n ),\n );\n }\n return acc;\n },\n [],\n );\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { LocalesMap } from '@/cdn/request/locales-map.js';\nimport { Request } from '@/cdn/request/request.js';\nimport { isArray, isPlainObject, isString, isUndefined } from '@/cdn/utils.js';\nimport type { IRequestBuilder } from '@/interfaces/i-request-builder.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\n\nexport class RequestBuilder implements IRequestBuilder {\n protected context: Context;\n\n protected request: Request;\n\n constructor(context: Context) {\n this.context = context;\n this.request = new Request(this.context);\n }\n\n public addFiles(files?: (CdnFile | string)[] | CdnFile | string): this {\n if (!(isPlainObject(files) || isString(files) || isUndefined(files) || isArray(files))) {\n throw new Error('Invalid param: \"request.files\" must be object, array, string or undefined.');\n }\n\n if (isArray(files)) {\n files.forEach((i: CdnFile | string): void => {\n if (!(isPlainObject(i) || isString(i))) {\n throw new Error('Invalid param: array \"request.files\" must contain objects or strings.');\n }\n });\n }\n\n if (isString(files)) {\n this.request.hasSingleFileResponse = true;\n\n const file: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === files,\n );\n\n if (!(file instanceof MetafileFile)) {\n throw new Error(`File not found: \"${files}\".`);\n }\n\n this.request.files = [file];\n } else if (isUndefined(files)) {\n this.request.files = [...this.context.metafile.data.files];\n } else if (isArray(files)) {\n this.request.files = files.map((file: CdnFile | string): MetafileFile => {\n let metafileFile: MetafileFile;\n\n if (isString(file)) {\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === file,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${file}\".`);\n }\n\n metafileFile = foundFile;\n } else {\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === file.id,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${file.id}\".`);\n }\n\n metafileFile = foundFile;\n }\n\n return metafileFile;\n });\n } else if (isPlainObject(files)) {\n this.request.hasSingleFileResponse = true;\n\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === files.id,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${files.id}\".`);\n }\n\n this.request.files = [foundFile];\n }\n\n return this;\n }\n\n public addLocales(locales?: string[] | string, excludeBaseLocale?: boolean): this {\n if (!(isString(locales) || isUndefined(locales) || isArray(locales))) {\n throw new Error('Invalid param: \"request.locales\" must be array, string or undefined.');\n }\n\n if (isArray(locales)) {\n locales.forEach((i: MetafileFile | string): void => {\n if (!isString(i)) {\n throw new Error('Invalid param: array \"request.locales\" must contain strings.');\n }\n });\n }\n\n if (isString(locales)) {\n this.request.hasSingleLocaleResponse = true;\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = cur.locales.filter(\n (metafileLocale: MetafileLocale): boolean => metafileLocale.locale === locales,\n );\n\n return acc;\n }, this.request.localesMap);\n } else if (isUndefined(locales)) {\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = excludeBaseLocale\n ? cur.locales.filter(\n (metafileLocale: MetafileLocale): boolean => !metafileLocale.isBaseLocale,\n )\n : cur.locales;\n\n return acc;\n }, this.request.localesMap);\n } else if (isArray(locales)) {\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = cur.locales.filter((metafileLocale: MetafileLocale) =>\n locales.includes(metafileLocale.locale),\n );\n\n return acc;\n }, this.request.localesMap);\n }\n\n return this;\n }\n\n public getCdnRequest(): Request {\n const result: Request = this.request;\n this.request = new Request(this.context);\n return result;\n }\n}\n","import { Context } from '@/cdn/context/context.js';\nimport { MetafileContext } from '@/cdn/context/metafile-context.js';\nimport { FetchHttpAdapter } from '@/cdn/http/fetch-http-adapter.js';\nimport { CdnCache } from '@/cdn/methods/cdn-cache.js';\nimport { CdnMetafile } from '@/cdn/methods/cdn-metafile.js';\nimport { RequestBuilder } from '@/cdn/request/request-builder.js';\nimport { isString } from '@/cdn/utils.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\nimport type { CdnFetchOptions } from '@/types/cdn-fetch-options.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\n\nexport class CdnClient {\n public metafile: CdnMetafile;\n\n public cache: CdnCache;\n\n protected context: Context;\n\n public static version = '__CLIENT_VERSION__';\n\n protected constructor(options: CdnClientOptions) {\n const metafileContext: MetafileContext = new MetafileContext(options);\n const client: FetchHttpAdapter = new FetchHttpAdapter(metafileContext.params.baseUrl);\n\n this.context = new Context({ metafileContext, cdn: this, client });\n this.metafile = new CdnMetafile(this.context);\n this.cache = new CdnCache(this.context);\n }\n\n public fetch = async (options?: CdnFetchOptions): Promise<CdnResponse> => {\n const { files, locales, excludeBaseLocale }: CdnFetchOptions = options || {};\n const requestBuilder: RequestBuilder = new RequestBuilder(this.context)\n .addFiles(files)\n .addLocales(locales, excludeBaseLocale);\n\n return requestBuilder.getCdnRequest().execute();\n };\n\n public static async create(options: CdnClientOptions): Promise<CdnClient> {\n if (!options) {\n throw new Error('Invalid param: missing required \"options\" parameter.');\n }\n\n if (!isString(options.metafile)) {\n throw new Error('Invalid param: \"options.metafile\" must be string.');\n }\n\n const cdn: CdnClient = new CdnClient(options);\n\n await cdn.metafile.refresh();\n\n return cdn;\n }\n}\n"],"names":["Api","context","constructor","this","fetchLocale","options","cache","has","Promise","resolve","get","client","metafileLocale","uri","fetchMetafile","metafile","params","jsonPath","MemoryCacheAdapter","map","Map","key","set","value","flush","isString","isUndefined","isArray","Array","isPlainObject","Object","prototype","toString","call","uniq","array","Set","uniqBy","predicate","seen","filter","item","hasOwn","LocalesCache","cacheAdapter","setIfMissed","metafileFile","data","keyFromMetafile","productFlavors","sort","join","cdnId","id","file","path","library","module","buildType","locale","timestamp","ResponseFactory","createCdnResponse","requests","responses","hasSingleFileResponse","hasSingleLocaleResponse","length","cacheResponses","transformResponses","forEach","response","index","reduce","acc","cur","Context","cdn","api","responseFactory","metafileContext","MetafileFile","locales","baseUrl","toCdnFile","isBaseLocale","MetafileLocale","language","region","script","isRtl","name","localizedName","baseLocale","toCdnLocale","MetafileData","projectUrl","files","filesMap","filesFactory","filesMapFactory","localesFactory","find","createEmpty","keys","push","cdnLocale","MetafileParams","metafileUrl","parseMetafileUrl","url","URL","Error","matches","exec","pathname","tagId","origin","MetafileContext","parsedData","setMetafile","FetchHttpAdapter","fetch","contentType","headers","isJson","status","result","json","text","CdnBase","CdnCache","CdnMetafile","excludeBaseLocale","refresh","async","switch","LocalesMap","Request","localesMap","execute","payload","getPromises","promises","all","request","RequestBuilder","addFiles","i","foundFile","addLocales","includes","getCdnRequest","CdnClient","static","create"],"mappings":";;;AAIO,MAAMA,EACDC,QAEV,WAAAC,CAAYD,GACVE,KAAKF,QAAUA,CACjB,CAEA,iBAAaG,CAAYC,GACvB,OAAIF,KAAKF,QAAQK,MAAMC,IAAIF,GAClB,IAAIG,SAASC,IAClBA,EAAQN,KAAKF,QAAQK,MAAMI,IAAIL,GAA2B,IAIvDF,KAAKF,QAAQU,OAAOD,IAAIL,EAAQO,eAAeC,IACxD,CAEA,mBAAaC,GACX,aAAcX,KAAKF,QAAQU,OAAOD,IAAIP,KAAKF,QAAQc,SAASC,OAAOC,SACrE,ECrBK,MAAMC,EACDC,IAEV,WAAAjB,GACEC,KAAKgB,QAAUC,GACjB,CAEO,GAAAV,CAAIW,GACT,OAAOlB,KAAKgB,IAAIT,IAAIW,EACtB,CAEO,GAAAd,CAAIc,GACT,OAAOlB,KAAKgB,IAAIZ,IAAIc,EACtB,CAEO,GAAAC,CAAID,EAAQE,GACjBpB,KAAKgB,IAAIG,IAAID,EAAKE,EACpB,CAEO,KAAAC,GACLrB,KAAKg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EAAQuD,IACjB/E,KAAK8I,QAAQhD,MAAMxB,QAAO,CAACC,EAAiBC,KAC1CD,EAAI3B,KAAK4B,EAAItB,IAAMsB,EAAIO,QAAQ1C,QAAQ5B,GACrCsE,EAAQqE,SAAS3I,EAAe+C,UAG3Be,IACNvE,KAAK8I,QAAQN,YAGXxI,IACT,CAEO,aAAAqJ,GACL,MAAMzB,EAAkB5H,KAAK8I,QAE7B,OADA9I,KAAK8I,QAAU,IAAIP,EAAQvI,KAAKF,SACzB8H,CACT,ECjIK,MAAM0B,EACJ1I,SAEAT,MAEGL,QAEVyJ,eAAwB,QAEd,WAAAxJ,CAAYG,GACpB,MAAM2E,EAAmC,IAAIsC,EAAgBjH,GACvDM,EAA2B,IAAI8G,EAAiBzC,EAAgBhE,OAAOmE,SAE7EhF,KAAKF,QAAU,IAAI2E,EAAQ,CAAEI,kBAAiBH,IAAK1E,KAAMQ,WACzDR,KAAKY,SAAW,IAAIqH,EAAYjI,KAAKF,SACrCE,KAAKG,MAAQ,IAAI6H,EAAShI,KAAKF,QACjC,CAEOyH,MAAQa,MAAOlI,IACpB,MAAM4F,MAAEA,EAAAf,QAAOA,EAAAmD,kBAASA,GAAuChI,GAAW,CAAA,EAK1E,OAJuC,IAAI6I,EAAe/I,KAAKF,SAC5DkJ,SAASlD,GACTqD,WAAWpE,EAASmD,GAEDmB,gBAAgBZ,SAAA,EAGxC,mBAAoBe,CAAOtJ,GACzB,IAAKA,EACH,MAAM,IAAI2G,MAAM,wDAGlB,IAAKvF,EAASpB,EAAQU,UACpB,MAAM,IAAIiG,MAAM,qDAGlB,MAAMnC,EAAiB,IAAI4E,EAAUpJ,GAIrC,aAFMwE,EAAI9D,SAASuH,UAEZzD,CACT"}
|
|
1
|
+
{"version":3,"file":"localazy-cdn-client.min.js","sources":["../src/cdn/api/api.ts","../src/cdn/cache/memory-cache-adapter.ts","../src/cdn/utils.ts","../src/cdn/cache/locales-cache.ts","../src/cdn/response/response-factory.ts","../src/cdn/context/context.ts","../src/cdn/metafile/metafile-file.ts","../src/cdn/metafile/metafile-locale.ts","../src/cdn/metafile/metafile-data.ts","../src/cdn/metafile/metafile-params.ts","../src/cdn/context/metafile-context.ts","../src/cdn/http/fetch-http-adapter.ts","../src/cdn/methods/cdn-base.ts","../src/cdn/methods/cdn-cache.ts","../src/cdn/methods/cdn-metafile.ts","../src/cdn/request/locales-map.ts","../src/cdn/request/request.ts","../src/cdn/request/request-builder.ts","../src/cdn/cdn-client.ts"],"sourcesContent":["import type { Context } from '@/cdn/context/context.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\n\nexport class Api {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n\n public async fetchLocale(options: ApiLocaleRequest): Promise<object | string> {\n if (this.context.cache.has(options)) {\n return new Promise((resolve): void => {\n resolve(this.context.cache.get(options) as object | string);\n });\n }\n\n return this.context.client.get(options.metafileLocale.uri);\n }\n\n public async fetchMetafile(): Promise<IMetafile> {\n return (await this.context.client.get(this.context.metafile.params.jsonPath)) as IMetafile;\n }\n}\n","import type { ICacheAdapter } from '@/interfaces/i-cache-adapter.js';\n\nexport class MemoryCacheAdapter<K, V> implements ICacheAdapter<K, V> {\n protected map: Map<K, V>;\n\n constructor() {\n this.map = new Map();\n }\n\n public get(key: K): V | undefined {\n return this.map.get(key);\n }\n\n public has(key: K): boolean {\n return this.map.has(key);\n }\n\n public set(key: K, value: V): void {\n this.map.set(key, value);\n }\n\n public flush(): void {\n this.map = new Map();\n }\n}\n","export const isString = (value: unknown): value is string => typeof value === 'string';\n\nexport const isUndefined = (value: unknown): value is undefined => typeof value === 'undefined';\n\nexport const isArray = <T>(value: unknown): value is T[] => Array.isArray(value);\n\nexport const isPlainObject = (value: unknown): value is Record<string, unknown> =>\n Object.prototype.toString.call(value) === '[object Object]';\n\nexport const uniq = <T>(array: T[]): T[] => [...new Set(array)];\n\nexport const uniqBy = <T>(array: T[], predicate: (item: T) => string): T[] => {\n const seen: Record<string, boolean> = {};\n\n return array.filter((item: T): boolean => {\n const key: string = predicate(item);\n\n if (!Object.hasOwn(seen, key)) {\n seen[key] = true;\n\n return true;\n }\n\n return false;\n });\n};\n","import { MemoryCacheAdapter } from '@/cdn/cache/memory-cache-adapter.js';\nimport type { Context } from '@/cdn/context/context.js';\nimport { uniq } from '@/cdn/utils.js';\nimport type { ICacheAdapter } from '@/interfaces/i-cache-adapter.js';\nimport type { CacheGetLocalesRequest } from '@/types/cache-get-locales-request.js';\nimport type { CacheHasLocalesRequest } from '@/types/cache-has-locales-request.js';\nimport type { CacheKeyMetafileOptions } from '@/types/cache-key-metafile-options.js';\nimport type { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request.js';\n\nexport class LocalesCache {\n protected context: Context;\n\n protected cacheAdapter: ICacheAdapter<string, object | string>;\n\n constructor(context: Context) {\n this.context = context;\n this.cacheAdapter = new MemoryCacheAdapter();\n }\n\n public setIfMissed(options: CacheStoreLocalesRequest): void {\n const { metafileFile, metafileLocale, data }: CacheStoreLocalesRequest = options;\n\n const key: string = this.keyFromMetafile({\n metafileFile,\n metafileLocale,\n });\n\n if (!this.cacheAdapter.has(key)) {\n this.cacheAdapter.set(key, data);\n }\n }\n\n public has(options: CacheHasLocalesRequest): boolean {\n const key: string = this.keyFromMetafile(options);\n\n return this.cacheAdapter.has(key);\n }\n\n public get(options: CacheGetLocalesRequest): object | string | undefined {\n const key: string = this.keyFromMetafile(options);\n\n return this.cacheAdapter.get(key);\n }\n\n public flush(): void {\n this.cacheAdapter.flush();\n }\n\n protected keyFromMetafile(options: CacheKeyMetafileOptions): string {\n const { metafileFile, metafileLocale }: CacheKeyMetafileOptions = options;\n const productFlavors: string = [...uniq(metafileFile.productFlavors)].sort().join('-');\n\n const indices: string[] = [\n this.context.metafile.params.cdnId,\n metafileFile.id,\n metafileFile.file,\n metafileFile.path,\n metafileFile.library,\n metafileFile.module,\n metafileFile.buildType,\n productFlavors,\n metafileLocale.locale,\n metafileLocale.timestamp.toString(),\n ];\n\n return indices.filter((key: string): boolean => key !== '').join('-');\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\nimport type { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\nimport type { ResponseFactoryOptions } from '@/types/response-factory-options.js';\n\nexport class ResponseFactory {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n\n public createCdnResponse(options: ResponseFactoryOptions): CdnResponse {\n const {\n requests,\n responses,\n hasSingleFileResponse,\n hasSingleLocaleResponse,\n }: ResponseFactoryOptions = options;\n\n if (responses.length === 0 || typeof responses[0] === 'undefined') {\n return {};\n }\n\n this.cacheResponses(requests, responses);\n\n return hasSingleFileResponse && hasSingleLocaleResponse\n ? responses[0]\n : ResponseFactory.transformResponses(options);\n }\n\n protected cacheResponses(requests: ApiLocaleRequest[], responses: (object | string)[]): void {\n responses.forEach((response: object | string, index: number): void => {\n if (typeof requests[index] !== 'undefined') {\n const { metafileFile, metafileLocale }: Partial<CacheStoreLocalesRequest> = requests[index];\n\n if (metafileFile && metafileLocale) {\n this.context.cache.setIfMissed({ metafileFile, metafileLocale, data: response });\n }\n }\n });\n }\n\n protected static transformResponses(options: ResponseFactoryOptions): CdnResponse {\n const { requests, responses, hasSingleFileResponse }: ResponseFactoryOptions = options;\n\n return responses.reduce((acc: CdnResponse, cur: object | string, index: number) => {\n if (typeof requests[index] !== 'undefined') {\n const { metafileFile, metafileLocale }: Partial<CacheStoreLocalesRequest> = requests[index];\n\n if (metafileFile && metafileLocale) {\n if (hasSingleFileResponse) {\n // @ts-expect-error fix output type\n acc[metafileLocale.locale] = cur;\n } else {\n // @ts-expect-error fix output type\n if (!acc[metafileFile.id]) {\n // @ts-expect-error fix output type\n acc[metafileFile.id] = {};\n }\n\n // @ts-expect-error fix output type\n acc[metafileFile.id][metafileLocale.locale] = cur;\n }\n }\n }\n\n return acc;\n }, {});\n }\n}\n","import { Api } from '@/cdn/api/api.js';\nimport { LocalesCache } from '@/cdn/cache/locales-cache.js';\nimport type { CdnClient } from '@/cdn/cdn-client.js';\nimport type { MetafileContext } from '@/cdn/context/metafile-context.js';\nimport { ResponseFactory } from '@/cdn/response/response-factory.js';\nimport type { IHttpAdapter } from '@/interfaces/i-http-adapter.js';\nimport type { ContextOptions } from '@/types/context-options.js';\n\nexport class Context {\n public metafile: MetafileContext;\n\n public cdn: CdnClient;\n\n public client: IHttpAdapter;\n\n public api: Api;\n\n public cache: LocalesCache;\n\n public responseFactory: ResponseFactory;\n\n constructor(options: ContextOptions) {\n this.metafile = options.metafileContext;\n this.cdn = options.cdn;\n this.client = options.client;\n this.api = new Api(this);\n this.cache = new LocalesCache(this);\n this.responseFactory = new ResponseFactory(this);\n }\n}\n","import type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { IMetafileFile } from '@/interfaces/i-metafile-file.js';\nimport type { CdnFileLocale } from '@/types/cdn-file-locale.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\nimport type { MetafileFileOptions } from '@/types/metafile-file-options.js';\n\nexport class MetafileFile implements Omit<IMetafileFile, 'locales'> {\n public id: string;\n\n public file: string;\n\n public path: string;\n\n public library: string;\n\n public module: string;\n\n public buildType: string;\n\n public timestamp: number;\n\n public productFlavors: string[];\n\n public locales: MetafileLocale[];\n\n protected baseUrl: string;\n\n constructor(options: MetafileFileOptions) {\n this.id = options.id;\n this.file = options.file;\n this.path = options.path;\n this.library = options.library;\n this.module = options.module;\n this.buildType = options.buildType;\n this.timestamp = options.timestamp;\n this.productFlavors = options.productFlavors;\n this.locales = options.locales;\n this.baseUrl = options.baseUrl;\n }\n\n public toCdnFile(): CdnFile {\n return {\n id: this.id,\n file: this.file,\n path: this.path,\n library: this.library,\n module: this.module,\n buildType: this.buildType,\n productFlavors: this.productFlavors,\n locales: this.locales.map(\n (locale: MetafileLocale): CdnFileLocale => ({\n locale: locale.locale,\n isBaseLocale: locale.isBaseLocale,\n uri: `${this.baseUrl}${locale.uri}`,\n }),\n ),\n };\n }\n}\n","import type { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\n\nexport class MetafileLocale implements IMetafileFileLocale {\n public language: string;\n\n public region: string;\n\n public script: string;\n\n public isRtl: boolean;\n\n public name: string;\n\n public localizedName: string;\n\n public uri: string;\n\n public timestamp: number;\n\n protected baseLocale: string;\n\n constructor(options: IMetafileFileLocale, baseLocale: string) {\n this.language = options.language;\n this.region = options.region;\n this.script = options.script;\n this.isRtl = options.isRtl;\n this.name = options.name;\n this.localizedName = options.localizedName;\n this.uri = options.uri;\n this.timestamp = options.timestamp;\n this.baseLocale = baseLocale;\n }\n\n get locale(): string {\n if (this.language && this.region && this.script) {\n return `${this.language}_${this.region}#${this.script}`;\n }\n\n if (this.language && this.script) {\n return `${this.language}#${this.script}`;\n }\n\n if (this.language && this.region) {\n return `${this.language}_${this.region}`;\n }\n\n return this.language;\n }\n\n get isBaseLocale(): boolean {\n return this.locale === this.baseLocale;\n }\n\n public toCdnLocale(): CdnLocale {\n return {\n locale: this.locale,\n isBaseLocale: this.isBaseLocale,\n language: this.language,\n region: this.region,\n script: this.script,\n isRtl: this.isRtl,\n name: this.name,\n localizedName: this.localizedName,\n };\n }\n}\n","import { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport { uniqBy } from '@/cdn/utils.js';\nimport type { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale.js';\nimport type { IMetafileFiles } from '@/interfaces/i-metafile-files.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\nimport type { FilesMap } from '@/types/files-map.js';\nimport type { MetafileOptions } from '@/types/metafile-options.js';\n\nexport class MetafileData implements Omit<IMetafile, 'files' | 'baseLocale'> {\n public projectUrl: string;\n\n public baseLocale: CdnLocale;\n\n public locales: CdnLocale[];\n\n public timestamp: number;\n\n public files: MetafileFile[];\n\n public filesMap: FilesMap;\n\n constructor(options: MetafileOptions, params: MetafileParams) {\n this.projectUrl = options.projectUrl;\n this.timestamp = options.timestamp;\n this.files = MetafileData.filesFactory(options.files, options.baseLocale, params);\n this.filesMap = MetafileData.filesMapFactory(this.files);\n this.locales = MetafileData.localesFactory(this.files);\n this.baseLocale = this.locales.find((locale: CdnLocale) => locale.isBaseLocale) as CdnLocale;\n }\n\n public static createEmpty(params: MetafileParams): MetafileData {\n return new MetafileData(\n {\n projectUrl: '',\n baseLocale: '',\n timestamp: 0,\n files: {},\n },\n params,\n );\n }\n\n protected static filesFactory(\n files: IMetafileFiles,\n baseLocale: string,\n params: MetafileParams,\n ): MetafileFile[] {\n return Object.keys(files).reduce((acc: MetafileFile[], cur: string) => {\n if (typeof files[cur] !== 'undefined') {\n const locales: MetafileLocale[] = files[cur].locales.map(\n (locale: IMetafileFileLocale) => new MetafileLocale(locale, baseLocale),\n );\n\n acc.push(\n new MetafileFile({\n ...files[cur],\n id: cur,\n locales,\n baseUrl: params.baseUrl,\n }),\n );\n }\n\n return acc;\n }, []);\n }\n\n protected static filesMapFactory(files: MetafileFile[]): FilesMap {\n return files.reduce((acc: FilesMap, cur: MetafileFile) => {\n acc[cur.id] = cur;\n\n return acc;\n }, {});\n }\n\n protected static localesFactory(files: MetafileFile[]): CdnLocale[] {\n const locales: CdnLocale[] = files.reduce((acc: CdnLocale[], cur: MetafileFile) => {\n acc.push(...cur.locales.map((locale: MetafileLocale): CdnLocale => locale.toCdnLocale()));\n return acc;\n }, []);\n\n return uniqBy(locales, (cdnLocale: CdnLocale): string => cdnLocale.locale);\n }\n}\n","import type { IMetafileParams } from '@/interfaces/i-metafile-params.js';\n\nexport class MetafileParams implements IMetafileParams {\n protected options: IMetafileParams;\n\n constructor(metafileUrl: string) {\n this.options = MetafileParams.parseMetafileUrl(metafileUrl);\n }\n\n get url(): string {\n return this.options.url;\n }\n\n get baseUrl(): string {\n return this.options.baseUrl;\n }\n\n get cdnId(): string {\n return this.options.cdnId;\n }\n\n get jsonPath(): string {\n return this.options.jsonPath;\n }\n\n protected static parseMetafileUrl(metafileUrl: string): IMetafileParams {\n let url: URL;\n\n try {\n url = new URL(metafileUrl);\n } catch {\n throw new Error('Invalid param: \"options.metafile\" cannot be parsed as url.');\n }\n\n const matches: string[] | null = /^\\/(.*?)\\/(.*?)\\.(v2.json|js|ts)$/.exec(url.pathname);\n\n if (\n matches === null ||\n matches.length !== 4 ||\n typeof matches[1] === 'undefined' ||\n typeof matches[2] === 'undefined'\n ) {\n throw new Error('Invalid param: \"options.metafile\" contains invalid metafile url.');\n }\n\n const cdnId: string = matches[1];\n const tagId: string = matches[2];\n\n return {\n url: metafileUrl,\n baseUrl: url.origin,\n cdnId,\n jsonPath: `/${cdnId}/${tagId}.v2.json`,\n };\n }\n}\n","import { MetafileData } from '@/cdn/metafile/metafile-data.js';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\n\nexport class MetafileContext {\n public params: MetafileParams;\n\n public parsedData: IMetafile | null;\n\n public data: MetafileData;\n\n constructor(options: CdnClientOptions) {\n this.params = new MetafileParams(options.metafile);\n this.parsedData = null;\n this.data = MetafileData.createEmpty(this.params);\n }\n\n public setMetafile(metafile: IMetafile): void {\n this.parsedData = metafile;\n\n this.data = new MetafileData(metafile, this.params);\n }\n}\n","import type { IHttpAdapter } from '@/interfaces/i-http-adapter.js';\n\nexport class FetchHttpAdapter implements IHttpAdapter {\n protected baseUrl: string;\n\n constructor(baseUrl: string) {\n this.baseUrl = baseUrl;\n }\n\n async get(url: string): Promise<string | object> {\n const response: Response = await fetch(`${this.baseUrl}${url}`);\n const contentType: string | null = response.headers.get('content-type');\n const isJson: boolean =\n contentType === 'application/json5' || contentType === 'application/json';\n\n if (response.status >= 400) {\n throw new Error(`Request failed with status code ${response.status.toString()}`);\n }\n\n let result: string | object;\n\n if (isJson) {\n result = (await response.json()) as object;\n } else {\n result = await response.text();\n }\n\n return result;\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\n\nexport abstract class CdnBase {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n}\n","import { CdnBase } from '@/cdn/methods/cdn-base.js';\n\nexport class CdnCache extends CdnBase {\n public flush = (): void => {\n this.context.cache.flush();\n };\n}\n","import type { MetafileData } from '@/cdn/metafile/metafile-data.js';\nimport type { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport { CdnBase } from '@/cdn/methods/cdn-base.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\nimport type { CdnLocalesOptions } from '@/types/cdn-locales-options.js';\n\nexport class CdnMetafile extends CdnBase {\n get projectUrl(): string {\n return this.context.metafile.data.projectUrl;\n }\n\n get baseLocale(): CdnLocale {\n return this.context.metafile.data.baseLocale;\n }\n\n get url(): string {\n return this.context.metafile.params.url;\n }\n\n get files(): CdnFile[] {\n return this.context.metafile.data.files.map((file: MetafileFile): CdnFile => file.toCdnFile());\n }\n\n public locales = (options?: CdnLocalesOptions): CdnLocale[] => {\n const { excludeBaseLocale }: CdnLocalesOptions = options || {};\n const { locales }: MetafileData = this.context.metafile.data;\n\n return excludeBaseLocale\n ? locales.filter((cdnLocale: CdnLocale): boolean => !cdnLocale.isBaseLocale)\n : locales;\n };\n\n public refresh = async (): Promise<void> => {\n const response: IMetafile = await this.context.api.fetchMetafile();\n\n this.context.metafile.setMetafile(response);\n };\n\n public switch = async (options: CdnClientOptions): Promise<void> => {\n this.context.metafile.params = new MetafileParams(options.metafile);\n\n await this.refresh();\n };\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { LocalesMapData } from '@/types/locales-map-data.js';\nimport type { LocalesMapOptions } from '@/types/locales-map-options.js';\n\nexport class LocalesMap {\n public data: LocalesMapData;\n\n protected context: Context;\n\n constructor(options: LocalesMapOptions) {\n this.context = options.context;\n this.data = options.data || {};\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport { LocalesMap } from '@/cdn/request/locales-map.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\n\nexport class Request {\n public files: MetafileFile[];\n\n public localesMap: LocalesMap;\n\n public hasSingleFileResponse: boolean;\n\n public hasSingleLocaleResponse: boolean;\n\n protected context: Context;\n\n constructor(context: Context) {\n this.files = [];\n this.localesMap = new LocalesMap({ context });\n this.hasSingleFileResponse = false;\n this.hasSingleLocaleResponse = false;\n this.context = context;\n }\n\n public async execute(): Promise<CdnResponse> {\n const payload: [Promise<string | object>, ApiLocaleRequest][] = this.getPromises();\n const promises: Promise<string | object>[] = payload.map(\n (item: [Promise<string | object>, ApiLocaleRequest]) => item[0],\n );\n const requests: ApiLocaleRequest[] = payload.map(\n (item: [Promise<string | object>, ApiLocaleRequest]) => item[1],\n );\n const responses: (string | object)[] = await Promise.all(promises);\n\n return this.context.responseFactory.createCdnResponse({\n requests,\n responses,\n localesMap: this.localesMap,\n hasSingleFileResponse: this.hasSingleFileResponse,\n hasSingleLocaleResponse: this.hasSingleLocaleResponse,\n });\n }\n\n protected getPromises(): [Promise<string | object>, ApiLocaleRequest][] {\n return this.files.reduce(\n (acc: [Promise<string | object>, ApiLocaleRequest][], cur: MetafileFile) => {\n if (typeof this.localesMap.data?.[cur.id] !== 'undefined') {\n acc.push(\n // @ts-expect-error TODO fix type\n ...this.localesMap.data[cur.id].map(\n (metafileLocale: MetafileLocale): [Promise<string | object>, ApiLocaleRequest] => {\n const request: ApiLocaleRequest = {\n metafileFile: cur,\n metafileLocale,\n };\n\n return [this.context.api.fetchLocale(request), request];\n },\n ),\n );\n }\n return acc;\n },\n [],\n );\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { LocalesMap } from '@/cdn/request/locales-map.js';\nimport { Request } from '@/cdn/request/request.js';\nimport { isArray, isPlainObject, isString, isUndefined } from '@/cdn/utils.js';\nimport type { IRequestBuilder } from '@/interfaces/i-request-builder.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\n\nexport class RequestBuilder implements IRequestBuilder {\n protected context: Context;\n\n protected request: Request;\n\n constructor(context: Context) {\n this.context = context;\n this.request = new Request(this.context);\n }\n\n public addFiles(files?: (CdnFile | string)[] | CdnFile | string): this {\n if (!(isPlainObject(files) || isString(files) || isUndefined(files) || isArray(files))) {\n throw new Error('Invalid param: \"request.files\" must be object, array, string or undefined.');\n }\n\n if (isArray(files)) {\n files.forEach((i: CdnFile | string): void => {\n if (!(isPlainObject(i) || isString(i))) {\n throw new Error('Invalid param: array \"request.files\" must contain objects or strings.');\n }\n });\n }\n\n if (isString(files)) {\n this.request.hasSingleFileResponse = true;\n\n const file: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === files,\n );\n\n if (!(file instanceof MetafileFile)) {\n throw new Error(`File not found: \"${files}\".`);\n }\n\n this.request.files = [file];\n } else if (isUndefined(files)) {\n this.request.files = [...this.context.metafile.data.files];\n } else if (isArray(files)) {\n this.request.files = files.map((file: CdnFile | string): MetafileFile => {\n let metafileFile: MetafileFile;\n\n if (isString(file)) {\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === file,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${file}\".`);\n }\n\n metafileFile = foundFile;\n } else {\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === file.id,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${file.id}\".`);\n }\n\n metafileFile = foundFile;\n }\n\n return metafileFile;\n });\n } else if (isPlainObject(files)) {\n this.request.hasSingleFileResponse = true;\n\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === files.id,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${files.id}\".`);\n }\n\n this.request.files = [foundFile];\n }\n\n return this;\n }\n\n public addLocales(locales?: string[] | string, excludeBaseLocale?: boolean): this {\n if (!(isString(locales) || isUndefined(locales) || isArray(locales))) {\n throw new Error('Invalid param: \"request.locales\" must be array, string or undefined.');\n }\n\n if (isArray(locales)) {\n locales.forEach((i: MetafileFile | string): void => {\n if (!isString(i)) {\n throw new Error('Invalid param: array \"request.locales\" must contain strings.');\n }\n });\n }\n\n if (isString(locales)) {\n this.request.hasSingleLocaleResponse = true;\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = cur.locales.filter(\n (metafileLocale: MetafileLocale): boolean => metafileLocale.locale === locales,\n );\n\n return acc;\n }, this.request.localesMap);\n } else if (isUndefined(locales)) {\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = excludeBaseLocale\n ? cur.locales.filter(\n (metafileLocale: MetafileLocale): boolean => !metafileLocale.isBaseLocale,\n )\n : cur.locales;\n\n return acc;\n }, this.request.localesMap);\n } else if (isArray(locales)) {\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = cur.locales.filter((metafileLocale: MetafileLocale) =>\n locales.includes(metafileLocale.locale),\n );\n\n return acc;\n }, this.request.localesMap);\n }\n\n return this;\n }\n\n public getCdnRequest(): Request {\n const result: Request = this.request;\n this.request = new Request(this.context);\n return result;\n }\n}\n","import { Context } from '@/cdn/context/context.js';\nimport { MetafileContext } from '@/cdn/context/metafile-context.js';\nimport { FetchHttpAdapter } from '@/cdn/http/fetch-http-adapter.js';\nimport { CdnCache } from '@/cdn/methods/cdn-cache.js';\nimport { CdnMetafile } from '@/cdn/methods/cdn-metafile.js';\nimport { RequestBuilder } from '@/cdn/request/request-builder.js';\nimport { isString } from '@/cdn/utils.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\nimport type { CdnFetchOptions } from '@/types/cdn-fetch-options.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\n\nexport class CdnClient {\n public metafile: CdnMetafile;\n\n public cache: CdnCache;\n\n protected context: Context;\n\n public static version = '__CLIENT_VERSION__';\n\n protected constructor(options: CdnClientOptions) {\n const metafileContext: MetafileContext = new MetafileContext(options);\n const client: FetchHttpAdapter = new FetchHttpAdapter(metafileContext.params.baseUrl);\n\n this.context = new Context({ metafileContext, cdn: this, client });\n this.metafile = new CdnMetafile(this.context);\n this.cache = new CdnCache(this.context);\n }\n\n public fetch = async (options?: CdnFetchOptions): Promise<CdnResponse> => {\n const { files, locales, excludeBaseLocale }: CdnFetchOptions = options || {};\n const requestBuilder: RequestBuilder = new RequestBuilder(this.context)\n .addFiles(files)\n .addLocales(locales, excludeBaseLocale);\n\n return requestBuilder.getCdnRequest().execute();\n };\n\n public static async create(options: CdnClientOptions): Promise<CdnClient> {\n if (!options) {\n throw new Error('Invalid param: missing required \"options\" parameter.');\n }\n\n if (!isString(options.metafile)) {\n throw new Error('Invalid param: \"options.metafile\" must be string.');\n }\n\n const cdn: CdnClient = new CdnClient(options);\n\n await cdn.metafile.refresh();\n\n return cdn;\n }\n}\n"],"names":["Api","context","constructor","this","fetchLocale","options","cache","has","Promise","resolve","get","client","metafileLocale","uri","fetchMetafile","metafile","params","jsonPath","MemoryCacheAdapter","map","Map","key","set","value","flush","isString","isUndefined","isArray","Array","isPlainObject","Object","prototype","toString","call","uniq","array","Set","uniqBy","predicate","seen","filter","item","hasOwn","LocalesCache","cacheAdapter","setIfMissed","metafileFile","data","keyFromMetafile","productFlavors","sort","join","cdnId","id","file","path","library","module","buildType","locale","timestamp","ResponseFactory","createCdnResponse","requests","responses","hasSingleFileResponse","hasSingleLocaleResponse","length","cacheResponses","transformResponses","forEach","response","index","reduce","acc","cur","Context","cdn","api","responseFactory","metafileContext","MetafileFile","locales","baseUrl","toCdnFile","isBaseLocale","MetafileLocale","language","region","script","isRtl","name","localizedName","baseLocale","toCdnLocale","MetafileData","projectUrl","files","filesMap","filesFactory","filesMapFactory","localesFactory","find","createEmpty","keys","push","cdnLocale","MetafileParams","metafileUrl","parseMetafileUrl","url","URL","Error","matches","exec","pathname","tagId","origin","MetafileContext","parsedData","setMetafile","FetchHttpAdapter","fetch","contentType","headers","isJson","status","result","json","text","CdnBase","CdnCache","CdnMetafile","excludeBaseLocale","refresh","async","switch","LocalesMap","Request","localesMap","execute","payload","getPromises","promises","all","request","RequestBuilder","addFiles","i","foundFile","addLocales","includes","getCdnRequest","CdnClient","static","create"],"mappings":"AAIO,MAAMA,EACDC,QAEV,WAAAC,CAAYD,GACVE,KAAKF,QAAUA,CACjB,CAEA,iBAAaG,CAAYC,GACvB,OAAIF,KAAKF,QAAQK,MAAMC,IAAIF,GAClB,IAAIG,SAASC,IAClBA,EAAQN,KAAKF,QAAQK,MAAMI,IAAIL,GAA2B,IAIvDF,KAAKF,QAAQU,OAAOD,IAAIL,EAAQO,eAAeC,IACxD,CAEA,mBAAaC,GACX,aAAcX,KAAKF,QAAQU,OAAOD,IAAIP,KAAKF,QAAQc,SAASC,OAAOC,SACrE,ECrBK,MAAMC,EACDC,IAEV,WAAAjB,GACEC,KAAKgB,QAAUC,GACjB,CAEO,GAAAV,CAAIW,GACT,OAAOlB,KAAKgB,IAAIT,IAAIW,EACtB,CAEO,GAAAd,CAAIc,GACT,OAAOlB,KAAKgB,IAAIZ,IAAIc,EACtB,CAEO,GAAAC,CAAID,EA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
-
* (c) 2025 Localazy <team@localazy.com>
|
|
4
|
-
* @license MIT */
|
|
5
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
3
|
class Api {
|
|
7
4
|
context;
|
|
@@ -593,7 +590,7 @@ class CdnClient {
|
|
|
593
590
|
metafile;
|
|
594
591
|
cache;
|
|
595
592
|
context;
|
|
596
|
-
static version = "1.5.
|
|
593
|
+
static version = "1.5.9";
|
|
597
594
|
constructor(options) {
|
|
598
595
|
const metafileContext = new MetafileContext(options);
|
|
599
596
|
const client = new FetchHttpAdapter(metafileContext.params.baseUrl);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localazy-cdn-client.cjs","sources":["../../src/cdn/api/api.ts","../../src/cdn/cache/memory-cache-adapter.ts","../../src/cdn/utils.ts","../../src/cdn/cache/locales-cache.ts","../../src/cdn/response/response-factory.ts","../../src/cdn/context/context.ts","../../src/cdn/metafile/metafile-file.ts","../../src/cdn/metafile/metafile-locale.ts","../../src/cdn/metafile/metafile-data.ts","../../src/cdn/metafile/metafile-params.ts","../../src/cdn/context/metafile-context.ts","../../src/cdn/http/fetch-http-adapter.ts","../../src/cdn/methods/cdn-base.ts","../../src/cdn/methods/cdn-cache.ts","../../src/cdn/methods/cdn-metafile.ts","../../src/cdn/request/locales-map.ts","../../src/cdn/request/request.ts","../../src/cdn/request/request-builder.ts","../../src/cdn/cdn-client.ts"],"sourcesContent":["import type { Context } from '@/cdn/context/context.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\n\nexport class Api {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n\n public async fetchLocale(options: ApiLocaleRequest): Promise<object | string> {\n if (this.context.cache.has(options)) {\n return new Promise((resolve): void => {\n resolve(this.context.cache.get(options) as object | string);\n });\n }\n\n return this.context.client.get(options.metafileLocale.uri);\n }\n\n public async fetchMetafile(): Promise<IMetafile> {\n return (await this.context.client.get(this.context.metafile.params.jsonPath)) as IMetafile;\n }\n}\n","import type { ICacheAdapter } from '@/interfaces/i-cache-adapter.js';\n\nexport class MemoryCacheAdapter<K, V> implements ICacheAdapter<K, V> {\n protected map: Map<K, V>;\n\n constructor() {\n this.map = new Map();\n }\n\n public get(key: K): V | undefined {\n return this.map.get(key);\n }\n\n public has(key: K): boolean {\n return this.map.has(key);\n }\n\n public set(key: K, value: V): void {\n this.map.set(key, value);\n }\n\n public flush(): void {\n this.map = new Map();\n }\n}\n","export const isString = (value: unknown): value is string => typeof value === 'string';\n\nexport const isUndefined = (value: unknown): value is undefined => typeof value === 'undefined';\n\nexport const isArray = <T>(value: unknown): value is T[] => Array.isArray(value);\n\nexport const isPlainObject = (value: unknown): value is Record<string, unknown> =>\n Object.prototype.toString.call(value) === '[object Object]';\n\nexport const uniq = <T>(array: T[]): T[] => [...new Set(array)];\n\nexport const uniqBy = <T>(array: T[], predicate: (item: T) => string): T[] => {\n const seen: Record<string, boolean> = {};\n\n return array.filter((item: T): boolean => {\n const key: string = predicate(item);\n\n if (!Object.hasOwn(seen, key)) {\n seen[key] = true;\n\n return true;\n }\n\n return false;\n });\n};\n","import { MemoryCacheAdapter } from '@/cdn/cache/memory-cache-adapter.js';\nimport type { Context } from '@/cdn/context/context.js';\nimport { uniq } from '@/cdn/utils.js';\nimport type { ICacheAdapter } from '@/interfaces/i-cache-adapter.js';\nimport type { CacheGetLocalesRequest } from '@/types/cache-get-locales-request.js';\nimport type { CacheHasLocalesRequest } from '@/types/cache-has-locales-request.js';\nimport type { CacheKeyMetafileOptions } from '@/types/cache-key-metafile-options.js';\nimport type { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request.js';\n\nexport class LocalesCache {\n protected context: Context;\n\n protected cacheAdapter: ICacheAdapter<string, object | string>;\n\n constructor(context: Context) {\n this.context = context;\n this.cacheAdapter = new MemoryCacheAdapter();\n }\n\n public setIfMissed(options: CacheStoreLocalesRequest): void {\n const { metafileFile, metafileLocale, data }: CacheStoreLocalesRequest = options;\n\n const key: string = this.keyFromMetafile({\n metafileFile,\n metafileLocale,\n });\n\n if (!this.cacheAdapter.has(key)) {\n this.cacheAdapter.set(key, data);\n }\n }\n\n public has(options: CacheHasLocalesRequest): boolean {\n const key: string = this.keyFromMetafile(options);\n\n return this.cacheAdapter.has(key);\n }\n\n public get(options: CacheGetLocalesRequest): object | string | undefined {\n const key: string = this.keyFromMetafile(options);\n\n return this.cacheAdapter.get(key);\n }\n\n public flush(): void {\n this.cacheAdapter.flush();\n }\n\n protected keyFromMetafile(options: CacheKeyMetafileOptions): string {\n const { metafileFile, metafileLocale }: CacheKeyMetafileOptions = options;\n const productFlavors: string = [...uniq(metafileFile.productFlavors)].sort().join('-');\n\n const indices: string[] = [\n this.context.metafile.params.cdnId,\n metafileFile.id,\n metafileFile.file,\n metafileFile.path,\n metafileFile.library,\n metafileFile.module,\n metafileFile.buildType,\n productFlavors,\n metafileLocale.locale,\n metafileLocale.timestamp.toString(),\n ];\n\n return indices.filter((key: string): boolean => key !== '').join('-');\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\nimport type { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\nimport type { ResponseFactoryOptions } from '@/types/response-factory-options.js';\n\nexport class ResponseFactory {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n\n public createCdnResponse(options: ResponseFactoryOptions): CdnResponse {\n const {\n requests,\n responses,\n hasSingleFileResponse,\n hasSingleLocaleResponse,\n }: ResponseFactoryOptions = options;\n\n if (responses.length === 0 || typeof responses[0] === 'undefined') {\n return {};\n }\n\n this.cacheResponses(requests, responses);\n\n return hasSingleFileResponse && hasSingleLocaleResponse\n ? responses[0]\n : ResponseFactory.transformResponses(options);\n }\n\n protected cacheResponses(requests: ApiLocaleRequest[], responses: (object | string)[]): void {\n responses.forEach((response: object | string, index: number): void => {\n if (typeof requests[index] !== 'undefined') {\n const { metafileFile, metafileLocale }: Partial<CacheStoreLocalesRequest> = requests[index];\n\n if (metafileFile && metafileLocale) {\n this.context.cache.setIfMissed({ metafileFile, metafileLocale, data: response });\n }\n }\n });\n }\n\n protected static transformResponses(options: ResponseFactoryOptions): CdnResponse {\n const { requests, responses, hasSingleFileResponse }: ResponseFactoryOptions = options;\n\n return responses.reduce((acc: CdnResponse, cur: object | string, index: number) => {\n if (typeof requests[index] !== 'undefined') {\n const { metafileFile, metafileLocale }: Partial<CacheStoreLocalesRequest> = requests[index];\n\n if (metafileFile && metafileLocale) {\n if (hasSingleFileResponse) {\n // @ts-expect-error fix output type\n acc[metafileLocale.locale] = cur;\n } else {\n // @ts-expect-error fix output type\n if (!acc[metafileFile.id]) {\n // @ts-expect-error fix output type\n acc[metafileFile.id] = {};\n }\n\n // @ts-expect-error fix output type\n acc[metafileFile.id][metafileLocale.locale] = cur;\n }\n }\n }\n\n return acc;\n }, {});\n }\n}\n","import { Api } from '@/cdn/api/api.js';\nimport { LocalesCache } from '@/cdn/cache/locales-cache.js';\nimport type { CdnClient } from '@/cdn/cdn-client.js';\nimport type { MetafileContext } from '@/cdn/context/metafile-context.js';\nimport { ResponseFactory } from '@/cdn/response/response-factory.js';\nimport type { IHttpAdapter } from '@/interfaces/i-http-adapter.js';\nimport type { ContextOptions } from '@/types/context-options.js';\n\nexport class Context {\n public metafile: MetafileContext;\n\n public cdn: CdnClient;\n\n public client: IHttpAdapter;\n\n public api: Api;\n\n public cache: LocalesCache;\n\n public responseFactory: ResponseFactory;\n\n constructor(options: ContextOptions) {\n this.metafile = options.metafileContext;\n this.cdn = options.cdn;\n this.client = options.client;\n this.api = new Api(this);\n this.cache = new LocalesCache(this);\n this.responseFactory = new ResponseFactory(this);\n }\n}\n","import type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { IMetafileFile } from '@/interfaces/i-metafile-file.js';\nimport type { CdnFileLocale } from '@/types/cdn-file-locale.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\nimport type { MetafileFileOptions } from '@/types/metafile-file-options.js';\n\nexport class MetafileFile implements Omit<IMetafileFile, 'locales'> {\n public id: string;\n\n public file: string;\n\n public path: string;\n\n public library: string;\n\n public module: string;\n\n public buildType: string;\n\n public timestamp: number;\n\n public productFlavors: string[];\n\n public locales: MetafileLocale[];\n\n protected baseUrl: string;\n\n constructor(options: MetafileFileOptions) {\n this.id = options.id;\n this.file = options.file;\n this.path = options.path;\n this.library = options.library;\n this.module = options.module;\n this.buildType = options.buildType;\n this.timestamp = options.timestamp;\n this.productFlavors = options.productFlavors;\n this.locales = options.locales;\n this.baseUrl = options.baseUrl;\n }\n\n public toCdnFile(): CdnFile {\n return {\n id: this.id,\n file: this.file,\n path: this.path,\n library: this.library,\n module: this.module,\n buildType: this.buildType,\n productFlavors: this.productFlavors,\n locales: this.locales.map(\n (locale: MetafileLocale): CdnFileLocale => ({\n locale: locale.locale,\n isBaseLocale: locale.isBaseLocale,\n uri: `${this.baseUrl}${locale.uri}`,\n }),\n ),\n };\n }\n}\n","import type { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\n\nexport class MetafileLocale implements IMetafileFileLocale {\n public language: string;\n\n public region: string;\n\n public script: string;\n\n public isRtl: boolean;\n\n public name: string;\n\n public localizedName: string;\n\n public uri: string;\n\n public timestamp: number;\n\n protected baseLocale: string;\n\n constructor(options: IMetafileFileLocale, baseLocale: string) {\n this.language = options.language;\n this.region = options.region;\n this.script = options.script;\n this.isRtl = options.isRtl;\n this.name = options.name;\n this.localizedName = options.localizedName;\n this.uri = options.uri;\n this.timestamp = options.timestamp;\n this.baseLocale = baseLocale;\n }\n\n get locale(): string {\n if (this.language && this.region && this.script) {\n return `${this.language}_${this.region}#${this.script}`;\n }\n\n if (this.language && this.script) {\n return `${this.language}#${this.script}`;\n }\n\n if (this.language && this.region) {\n return `${this.language}_${this.region}`;\n }\n\n return this.language;\n }\n\n get isBaseLocale(): boolean {\n return this.locale === this.baseLocale;\n }\n\n public toCdnLocale(): CdnLocale {\n return {\n locale: this.locale,\n isBaseLocale: this.isBaseLocale,\n language: this.language,\n region: this.region,\n script: this.script,\n isRtl: this.isRtl,\n name: this.name,\n localizedName: this.localizedName,\n };\n }\n}\n","import { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport { uniqBy } from '@/cdn/utils.js';\nimport type { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale.js';\nimport type { IMetafileFiles } from '@/interfaces/i-metafile-files.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\nimport type { FilesMap } from '@/types/files-map.js';\nimport type { MetafileOptions } from '@/types/metafile-options.js';\n\nexport class MetafileData implements Omit<IMetafile, 'files' | 'baseLocale'> {\n public projectUrl: string;\n\n public baseLocale: CdnLocale;\n\n public locales: CdnLocale[];\n\n public timestamp: number;\n\n public files: MetafileFile[];\n\n public filesMap: FilesMap;\n\n constructor(options: MetafileOptions, params: MetafileParams) {\n this.projectUrl = options.projectUrl;\n this.timestamp = options.timestamp;\n this.files = MetafileData.filesFactory(options.files, options.baseLocale, params);\n this.filesMap = MetafileData.filesMapFactory(this.files);\n this.locales = MetafileData.localesFactory(this.files);\n this.baseLocale = this.locales.find((locale: CdnLocale) => locale.isBaseLocale) as CdnLocale;\n }\n\n public static createEmpty(params: MetafileParams): MetafileData {\n return new MetafileData(\n {\n projectUrl: '',\n baseLocale: '',\n timestamp: 0,\n files: {},\n },\n params,\n );\n }\n\n protected static filesFactory(\n files: IMetafileFiles,\n baseLocale: string,\n params: MetafileParams,\n ): MetafileFile[] {\n return Object.keys(files).reduce((acc: MetafileFile[], cur: string) => {\n if (typeof files[cur] !== 'undefined') {\n const locales: MetafileLocale[] = files[cur].locales.map(\n (locale: IMetafileFileLocale) => new MetafileLocale(locale, baseLocale),\n );\n\n acc.push(\n new MetafileFile({\n ...files[cur],\n id: cur,\n locales,\n baseUrl: params.baseUrl,\n }),\n );\n }\n\n return acc;\n }, []);\n }\n\n protected static filesMapFactory(files: MetafileFile[]): FilesMap {\n return files.reduce((acc: FilesMap, cur: MetafileFile) => {\n acc[cur.id] = cur;\n\n return acc;\n }, {});\n }\n\n protected static localesFactory(files: MetafileFile[]): CdnLocale[] {\n const locales: CdnLocale[] = files.reduce((acc: CdnLocale[], cur: MetafileFile) => {\n acc.push(...cur.locales.map((locale: MetafileLocale): CdnLocale => locale.toCdnLocale()));\n return acc;\n }, []);\n\n return uniqBy(locales, (cdnLocale: CdnLocale): string => cdnLocale.locale);\n }\n}\n","import type { IMetafileParams } from '@/interfaces/i-metafile-params.js';\n\nexport class MetafileParams implements IMetafileParams {\n protected options: IMetafileParams;\n\n constructor(metafileUrl: string) {\n this.options = MetafileParams.parseMetafileUrl(metafileUrl);\n }\n\n get url(): string {\n return this.options.url;\n }\n\n get baseUrl(): string {\n return this.options.baseUrl;\n }\n\n get cdnId(): string {\n return this.options.cdnId;\n }\n\n get jsonPath(): string {\n return this.options.jsonPath;\n }\n\n protected static parseMetafileUrl(metafileUrl: string): IMetafileParams {\n let url: URL;\n\n try {\n url = new URL(metafileUrl);\n } catch {\n throw new Error('Invalid param: \"options.metafile\" cannot be parsed as url.');\n }\n\n const matches: string[] | null = /^\\/(.*?)\\/(.*?)\\.(v2.json|js|ts)$/.exec(url.pathname);\n\n if (\n matches === null ||\n matches.length !== 4 ||\n typeof matches[1] === 'undefined' ||\n typeof matches[2] === 'undefined'\n ) {\n throw new Error('Invalid param: \"options.metafile\" contains invalid metafile url.');\n }\n\n const cdnId: string = matches[1];\n const tagId: string = matches[2];\n\n return {\n url: metafileUrl,\n baseUrl: url.origin,\n cdnId,\n jsonPath: `/${cdnId}/${tagId}.v2.json`,\n };\n }\n}\n","import { MetafileData } from '@/cdn/metafile/metafile-data.js';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\n\nexport class MetafileContext {\n public params: MetafileParams;\n\n public parsedData: IMetafile | null;\n\n public data: MetafileData;\n\n constructor(options: CdnClientOptions) {\n this.params = new MetafileParams(options.metafile);\n this.parsedData = null;\n this.data = MetafileData.createEmpty(this.params);\n }\n\n public setMetafile(metafile: IMetafile): void {\n this.parsedData = metafile;\n\n this.data = new MetafileData(metafile, this.params);\n }\n}\n","import type { IHttpAdapter } from '@/interfaces/i-http-adapter.js';\n\nexport class FetchHttpAdapter implements IHttpAdapter {\n protected baseUrl: string;\n\n constructor(baseUrl: string) {\n this.baseUrl = baseUrl;\n }\n\n async get(url: string): Promise<string | object> {\n const response: Response = await fetch(`${this.baseUrl}${url}`);\n const contentType: string | null = response.headers.get('content-type');\n const isJson: boolean =\n contentType === 'application/json5' || contentType === 'application/json';\n\n if (response.status >= 400) {\n throw new Error(`Request failed with status code ${response.status.toString()}`);\n }\n\n let result: string | object;\n\n if (isJson) {\n result = (await response.json()) as object;\n } else {\n result = await response.text();\n }\n\n return result;\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\n\nexport abstract class CdnBase {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n}\n","import { CdnBase } from '@/cdn/methods/cdn-base.js';\n\nexport class CdnCache extends CdnBase {\n public flush = (): void => {\n this.context.cache.flush();\n };\n}\n","import type { MetafileData } from '@/cdn/metafile/metafile-data.js';\nimport type { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport { CdnBase } from '@/cdn/methods/cdn-base.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\nimport type { CdnLocalesOptions } from '@/types/cdn-locales-options.js';\n\nexport class CdnMetafile extends CdnBase {\n get projectUrl(): string {\n return this.context.metafile.data.projectUrl;\n }\n\n get baseLocale(): CdnLocale {\n return this.context.metafile.data.baseLocale;\n }\n\n get url(): string {\n return this.context.metafile.params.url;\n }\n\n get files(): CdnFile[] {\n return this.context.metafile.data.files.map((file: MetafileFile): CdnFile => file.toCdnFile());\n }\n\n public locales = (options?: CdnLocalesOptions): CdnLocale[] => {\n const { excludeBaseLocale }: CdnLocalesOptions = options || {};\n const { locales }: MetafileData = this.context.metafile.data;\n\n return excludeBaseLocale\n ? locales.filter((cdnLocale: CdnLocale): boolean => !cdnLocale.isBaseLocale)\n : locales;\n };\n\n public refresh = async (): Promise<void> => {\n const response: IMetafile = await this.context.api.fetchMetafile();\n\n this.context.metafile.setMetafile(response);\n };\n\n public switch = async (options: CdnClientOptions): Promise<void> => {\n this.context.metafile.params = new MetafileParams(options.metafile);\n\n await this.refresh();\n };\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { LocalesMapData } from '@/types/locales-map-data.js';\nimport type { LocalesMapOptions } from '@/types/locales-map-options.js';\n\nexport class LocalesMap {\n public data: LocalesMapData;\n\n protected context: Context;\n\n constructor(options: LocalesMapOptions) {\n this.context = options.context;\n this.data = options.data || {};\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport { LocalesMap } from '@/cdn/request/locales-map.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\n\nexport class Request {\n public files: MetafileFile[];\n\n public localesMap: LocalesMap;\n\n public hasSingleFileResponse: boolean;\n\n public hasSingleLocaleResponse: boolean;\n\n protected context: Context;\n\n constructor(context: Context) {\n this.files = [];\n this.localesMap = new LocalesMap({ context });\n this.hasSingleFileResponse = false;\n this.hasSingleLocaleResponse = false;\n this.context = context;\n }\n\n public async execute(): Promise<CdnResponse> {\n const payload: [Promise<string | object>, ApiLocaleRequest][] = this.getPromises();\n const promises: Promise<string | object>[] = payload.map(\n (item: [Promise<string | object>, ApiLocaleRequest]) => item[0],\n );\n const requests: ApiLocaleRequest[] = payload.map(\n (item: [Promise<string | object>, ApiLocaleRequest]) => item[1],\n );\n const responses: (string | object)[] = await Promise.all(promises);\n\n return this.context.responseFactory.createCdnResponse({\n requests,\n responses,\n localesMap: this.localesMap,\n hasSingleFileResponse: this.hasSingleFileResponse,\n hasSingleLocaleResponse: this.hasSingleLocaleResponse,\n });\n }\n\n protected getPromises(): [Promise<string | object>, ApiLocaleRequest][] {\n return this.files.reduce(\n (acc: [Promise<string | object>, ApiLocaleRequest][], cur: MetafileFile) => {\n if (typeof this.localesMap.data?.[cur.id] !== 'undefined') {\n acc.push(\n // @ts-expect-error TODO fix type\n ...this.localesMap.data[cur.id].map(\n (metafileLocale: MetafileLocale): [Promise<string | object>, ApiLocaleRequest] => {\n const request: ApiLocaleRequest = {\n metafileFile: cur,\n metafileLocale,\n };\n\n return [this.context.api.fetchLocale(request), request];\n },\n ),\n );\n }\n return acc;\n },\n [],\n );\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { LocalesMap } from '@/cdn/request/locales-map.js';\nimport { Request } from '@/cdn/request/request.js';\nimport { isArray, isPlainObject, isString, isUndefined } from '@/cdn/utils.js';\nimport type { IRequestBuilder } from '@/interfaces/i-request-builder.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\n\nexport class RequestBuilder implements IRequestBuilder {\n protected context: Context;\n\n protected request: Request;\n\n constructor(context: Context) {\n this.context = context;\n this.request = new Request(this.context);\n }\n\n public addFiles(files?: (CdnFile | string)[] | CdnFile | string): this {\n if (!(isPlainObject(files) || isString(files) || isUndefined(files) || isArray(files))) {\n throw new Error('Invalid param: \"request.files\" must be object, array, string or undefined.');\n }\n\n if (isArray(files)) {\n files.forEach((i: CdnFile | string): void => {\n if (!(isPlainObject(i) || isString(i))) {\n throw new Error('Invalid param: array \"request.files\" must contain objects or strings.');\n }\n });\n }\n\n if (isString(files)) {\n this.request.hasSingleFileResponse = true;\n\n const file: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === files,\n );\n\n if (!(file instanceof MetafileFile)) {\n throw new Error(`File not found: \"${files}\".`);\n }\n\n this.request.files = [file];\n } else if (isUndefined(files)) {\n this.request.files = [...this.context.metafile.data.files];\n } else if (isArray(files)) {\n this.request.files = files.map((file: CdnFile | string): MetafileFile => {\n let metafileFile: MetafileFile;\n\n if (isString(file)) {\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === file,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${file}\".`);\n }\n\n metafileFile = foundFile;\n } else {\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === file.id,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${file.id}\".`);\n }\n\n metafileFile = foundFile;\n }\n\n return metafileFile;\n });\n } else if (isPlainObject(files)) {\n this.request.hasSingleFileResponse = true;\n\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === files.id,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${files.id}\".`);\n }\n\n this.request.files = [foundFile];\n }\n\n return this;\n }\n\n public addLocales(locales?: string[] | string, excludeBaseLocale?: boolean): this {\n if (!(isString(locales) || isUndefined(locales) || isArray(locales))) {\n throw new Error('Invalid param: \"request.locales\" must be array, string or undefined.');\n }\n\n if (isArray(locales)) {\n locales.forEach((i: MetafileFile | string): void => {\n if (!isString(i)) {\n throw new Error('Invalid param: array \"request.locales\" must contain strings.');\n }\n });\n }\n\n if (isString(locales)) {\n this.request.hasSingleLocaleResponse = true;\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = cur.locales.filter(\n (metafileLocale: MetafileLocale): boolean => metafileLocale.locale === locales,\n );\n\n return acc;\n }, this.request.localesMap);\n } else if (isUndefined(locales)) {\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = excludeBaseLocale\n ? cur.locales.filter(\n (metafileLocale: MetafileLocale): boolean => !metafileLocale.isBaseLocale,\n )\n : cur.locales;\n\n return acc;\n }, this.request.localesMap);\n } else if (isArray(locales)) {\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = cur.locales.filter((metafileLocale: MetafileLocale) =>\n locales.includes(metafileLocale.locale),\n );\n\n return acc;\n }, this.request.localesMap);\n }\n\n return this;\n }\n\n public getCdnRequest(): Request {\n const result: Request = this.request;\n this.request = new Request(this.context);\n return result;\n }\n}\n","import { Context } from '@/cdn/context/context.js';\nimport { MetafileContext } from '@/cdn/context/metafile-context.js';\nimport { FetchHttpAdapter } from '@/cdn/http/fetch-http-adapter.js';\nimport { CdnCache } from '@/cdn/methods/cdn-cache.js';\nimport { CdnMetafile } from '@/cdn/methods/cdn-metafile.js';\nimport { RequestBuilder } from '@/cdn/request/request-builder.js';\nimport { isString } from '@/cdn/utils.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\nimport type { CdnFetchOptions } from '@/types/cdn-fetch-options.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\n\nexport class CdnClient {\n public metafile: CdnMetafile;\n\n public cache: CdnCache;\n\n protected context: Context;\n\n public static version = '__CLIENT_VERSION__';\n\n protected constructor(options: CdnClientOptions) {\n const metafileContext: MetafileContext = new MetafileContext(options);\n const client: FetchHttpAdapter = new FetchHttpAdapter(metafileContext.params.baseUrl);\n\n this.context = new Context({ metafileContext, cdn: this, client });\n this.metafile = new CdnMetafile(this.context);\n this.cache = new CdnCache(this.context);\n }\n\n public fetch = async (options?: CdnFetchOptions): Promise<CdnResponse> => {\n const { files, locales, excludeBaseLocale }: CdnFetchOptions = options || {};\n const requestBuilder: RequestBuilder = new RequestBuilder(this.context)\n .addFiles(files)\n .addLocales(locales, excludeBaseLocale);\n\n return requestBuilder.getCdnRequest().execute();\n };\n\n public static async create(options: CdnClientOptions): Promise<CdnClient> {\n if (!options) {\n throw new Error('Invalid param: missing required \"options\" parameter.');\n }\n\n if (!isString(options.metafile)) {\n throw new Error('Invalid param: \"options.metafile\" must be string.');\n }\n\n const cdn: CdnClient = new CdnClient(options);\n\n await cdn.metafile.refresh();\n\n return cdn;\n }\n}\n"],"names":[],"mappings":";;;;;AAIO,MAAM,IAAI;AAAA,EACL;AAAA,EAEV,YAAY,SAAkB;AAC5B,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAa,YAAY,SAAqD;AAC5E,QAAI,KAAK,QAAQ,MAAM,IAAI,OAAO,GAAG;AACnC,aAAO,IAAI,QAAQ,CAAC,YAAkB;AACpC,gBAAQ,KAAK,QAAQ,MAAM,IAAI,OAAO,CAAoB;AAAA,MAC5D,CAAC;AAAA,IACH;AAEA,WAAO,KAAK,QAAQ,OAAO,IAAI,QAAQ,eAAe,GAAG;AAAA,EAC3D;AAAA,EAEA,MAAa,gBAAoC;AAC/C,WAAQ,MAAM,KAAK,QAAQ,OAAO,IAAI,KAAK,QAAQ,SAAS,OAAO,QAAQ;AAAA,EAC7E;AACF;ACtBO,MAAM,mBAAwD;AAAA,EACzD;AAAA,EAEV,cAAc;AACZ,SAAK,0BAAU,IAAA;AAAA,EACjB;AAAA,EAEO,IAAI,KAAuB;AAChC,WAAO,KAAK,IAAI,IAAI,GAAG;AAAA,EACzB;AAAA,EAEO,IAAI,KAAiB;AAC1B,WAAO,KAAK,IAAI,IAAI,GAAG;AAAA,EACzB;AAAA,EAEO,IAAI,KAAQ,OAAgB;AACjC,SAAK,IAAI,IAAI,KAAK,KAAK;AAAA,EACz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nB,WAAO;AAAA,EACT;AACF;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"localazy-cdn-client.cjs","sources":["../../src/cdn/api/api.ts","../../src/cdn/cache/memory-cache-adapter.ts","../../src/cdn/utils.ts","../../src/cdn/cache/locales-cache.ts","../../src/cdn/response/response-factory.ts","../../src/cdn/context/context.ts","../../src/cdn/metafile/metafile-file.ts","../../src/cdn/metafile/metafile-locale.ts","../../src/cdn/metafile/metafile-data.ts","../../src/cdn/metafile/metafile-params.ts","../../src/cdn/context/metafile-context.ts","../../src/cdn/http/fetch-http-adapter.ts","../../src/cdn/methods/cdn-base.ts","../../src/cdn/methods/cdn-cache.ts","../../src/cdn/methods/cdn-metafile.ts","../../src/cdn/request/locales-map.ts","../../src/cdn/request/request.ts","../../src/cdn/request/request-builder.ts","../../src/cdn/cdn-client.ts"],"sourcesContent":["import type { Context } from '@/cdn/context/context.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\n\nexport class Api {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n\n public async fetchLocale(options: ApiLocaleRequest): Promise<object | string> {\n if (this.context.cache.has(options)) {\n return new Promise((resolve): void => {\n resolve(this.context.cache.get(options) as object | string);\n });\n }\n\n return this.context.client.get(options.metafileLocale.uri);\n }\n\n public async fetchMetafile(): Promise<IMetafile> {\n return (await this.context.client.get(this.context.metafile.params.jsonPath)) as IMetafile;\n }\n}\n","import type { ICacheAdapter } from '@/interfaces/i-cache-adapter.js';\n\nexport class MemoryCacheAdapter<K, V> implements ICacheAdapter<K, V> {\n protected map: Map<K, V>;\n\n constructor() {\n this.map = new Map();\n }\n\n public get(key: K): V | undefined {\n return this.map.get(key);\n }\n\n public has(key: K): boolean {\n return this.map.has(key);\n }\n\n public set(key: K, value: V): void {\n this.map.set(key, value);\n }\n\n public flush(): void {\n this.map = new Map();\n }\n}\n","export const isString = (value: unknown): value is string => typeof value === 'string';\n\nexport const isUndefined = (value: unknown): value is undefined => typeof value === 'undefined';\n\nexport const isArray = <T>(value: unknown): value is T[] => Array.isArray(value);\n\nexport const isPlainObject = (value: unknown): value is Record<string, unknown> =>\n Object.prototype.toString.call(value) === '[object Object]';\n\nexport const uniq = <T>(array: T[]): T[] => [...new Set(array)];\n\nexport const uniqBy = <T>(array: T[], predicate: (item: T) => string): T[] => {\n const seen: Record<string, boolean> = {};\n\n return array.filter((item: T): boolean => {\n const key: string = predicate(item);\n\n if (!Object.hasOwn(seen, key)) {\n seen[key] = true;\n\n return true;\n }\n\n return false;\n });\n};\n","import { MemoryCacheAdapter } from '@/cdn/cache/memory-cache-adapter.js';\nimport type { Context } from '@/cdn/context/context.js';\nimport { uniq } from '@/cdn/utils.js';\nimport type { ICacheAdapter } from '@/interfaces/i-cache-adapter.js';\nimport type { CacheGetLocalesRequest } from '@/types/cache-get-locales-request.js';\nimport type { CacheHasLocalesRequest } from '@/types/cache-has-locales-request.js';\nimport type { CacheKeyMetafileOptions } from '@/types/cache-key-metafile-options.js';\nimport type { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request.js';\n\nexport class LocalesCache {\n protected context: Context;\n\n protected cacheAdapter: ICacheAdapter<string, object | string>;\n\n constructor(context: Context) {\n this.context = context;\n this.cacheAdapter = new MemoryCacheAdapter();\n }\n\n public setIfMissed(options: CacheStoreLocalesRequest): void {\n const { metafileFile, metafileLocale, data }: CacheStoreLocalesRequest = options;\n\n const key: string = this.keyFromMetafile({\n metafileFile,\n metafileLocale,\n });\n\n if (!this.cacheAdapter.has(key)) {\n this.cacheAdapter.set(key, data);\n }\n }\n\n public has(options: CacheHasLocalesRequest): boolean {\n const key: string = this.keyFromMetafile(options);\n\n return this.cacheAdapter.has(key);\n }\n\n public get(options: CacheGetLocalesRequest): object | string | undefined {\n const key: string = this.keyFromMetafile(options);\n\n return this.cacheAdapter.get(key);\n }\n\n public flush(): void {\n this.cacheAdapter.flush();\n }\n\n protected keyFromMetafile(options: CacheKeyMetafileOptions): string {\n const { metafileFile, metafileLocale }: CacheKeyMetafileOptions = options;\n const productFlavors: string = [...uniq(metafileFile.productFlavors)].sort().join('-');\n\n const indices: string[] = [\n this.context.metafile.params.cdnId,\n metafileFile.id,\n metafileFile.file,\n metafileFile.path,\n metafileFile.library,\n metafileFile.module,\n metafileFile.buildType,\n productFlavors,\n metafileLocale.locale,\n metafileLocale.timestamp.toString(),\n ];\n\n return indices.filter((key: string): boolean => key !== '').join('-');\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\nimport type { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\nimport type { ResponseFactoryOptions } from '@/types/response-factory-options.js';\n\nexport class ResponseFactory {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n\n public createCdnResponse(options: ResponseFactoryOptions): CdnResponse {\n const {\n requests,\n responses,\n hasSingleFileResponse,\n hasSingleLocaleResponse,\n }: ResponseFactoryOptions = options;\n\n if (responses.length === 0 || typeof responses[0] === 'undefined') {\n return {};\n }\n\n this.cacheResponses(requests, responses);\n\n return hasSingleFileResponse && hasSingleLocaleResponse\n ? responses[0]\n : ResponseFactory.transformResponses(options);\n }\n\n protected cacheResponses(requests: ApiLocaleRequest[], responses: (object | string)[]): void {\n responses.forEach((response: object | string, index: number): void => {\n if (typeof requests[index] !== 'undefined') {\n const { metafileFile, metafileLocale }: Partial<CacheStoreLocalesRequest> = requests[index];\n\n if (metafileFile && metafileLocale) {\n this.context.cache.setIfMissed({ metafileFile, metafileLocale, data: response });\n }\n }\n });\n }\n\n protected static transformResponses(options: ResponseFactoryOptions): CdnResponse {\n const { requests, responses, hasSingleFileResponse }: ResponseFactoryOptions = options;\n\n return responses.reduce((acc: CdnResponse, cur: object | string, index: number) => {\n if (typeof requests[index] !== 'undefined') {\n const { metafileFile, metafileLocale }: Partial<CacheStoreLocalesRequest> = requests[index];\n\n if (metafileFile && metafileLocale) {\n if (hasSingleFileResponse) {\n // @ts-expect-error fix output type\n acc[metafileLocale.locale] = cur;\n } else {\n // @ts-expect-error fix output type\n if (!acc[metafileFile.id]) {\n // @ts-expect-error fix output type\n acc[metafileFile.id] = {};\n }\n\n // @ts-expect-error fix output type\n acc[metafileFile.id][metafileLocale.locale] = cur;\n }\n }\n }\n\n return acc;\n }, {});\n }\n}\n","import { Api } from '@/cdn/api/api.js';\nimport { LocalesCache } from '@/cdn/cache/locales-cache.js';\nimport type { CdnClient } from '@/cdn/cdn-client.js';\nimport type { MetafileContext } from '@/cdn/context/metafile-context.js';\nimport { ResponseFactory } from '@/cdn/response/response-factory.js';\nimport type { IHttpAdapter } from '@/interfaces/i-http-adapter.js';\nimport type { ContextOptions } from '@/types/context-options.js';\n\nexport class Context {\n public metafile: MetafileContext;\n\n public cdn: CdnClient;\n\n public client: IHttpAdapter;\n\n public api: Api;\n\n public cache: LocalesCache;\n\n public responseFactory: ResponseFactory;\n\n constructor(options: ContextOptions) {\n this.metafile = options.metafileContext;\n this.cdn = options.cdn;\n this.client = options.client;\n this.api = new Api(this);\n this.cache = new LocalesCache(this);\n this.responseFactory = new ResponseFactory(this);\n }\n}\n","import type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { IMetafileFile } from '@/interfaces/i-metafile-file.js';\nimport type { CdnFileLocale } from '@/types/cdn-file-locale.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\nimport type { MetafileFileOptions } from '@/types/metafile-file-options.js';\n\nexport class MetafileFile implements Omit<IMetafileFile, 'locales'> {\n public id: string;\n\n public file: string;\n\n public path: string;\n\n public library: string;\n\n public module: string;\n\n public buildType: string;\n\n public timestamp: number;\n\n public productFlavors: string[];\n\n public locales: MetafileLocale[];\n\n protected baseUrl: string;\n\n constructor(options: MetafileFileOptions) {\n this.id = options.id;\n this.file = options.file;\n this.path = options.path;\n this.library = options.library;\n this.module = options.module;\n this.buildType = options.buildType;\n this.timestamp = options.timestamp;\n this.productFlavors = options.productFlavors;\n this.locales = options.locales;\n this.baseUrl = options.baseUrl;\n }\n\n public toCdnFile(): CdnFile {\n return {\n id: this.id,\n file: this.file,\n path: this.path,\n library: this.library,\n module: this.module,\n buildType: this.buildType,\n productFlavors: this.productFlavors,\n locales: this.locales.map(\n (locale: MetafileLocale): CdnFileLocale => ({\n locale: locale.locale,\n isBaseLocale: locale.isBaseLocale,\n uri: `${this.baseUrl}${locale.uri}`,\n }),\n ),\n };\n }\n}\n","import type { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\n\nexport class MetafileLocale implements IMetafileFileLocale {\n public language: string;\n\n public region: string;\n\n public script: string;\n\n public isRtl: boolean;\n\n public name: string;\n\n public localizedName: string;\n\n public uri: string;\n\n public timestamp: number;\n\n protected baseLocale: string;\n\n constructor(options: IMetafileFileLocale, baseLocale: string) {\n this.language = options.language;\n this.region = options.region;\n this.script = options.script;\n this.isRtl = options.isRtl;\n this.name = options.name;\n this.localizedName = options.localizedName;\n this.uri = options.uri;\n this.timestamp = options.timestamp;\n this.baseLocale = baseLocale;\n }\n\n get locale(): string {\n if (this.language && this.region && this.script) {\n return `${this.language}_${this.region}#${this.script}`;\n }\n\n if (this.language && this.script) {\n return `${this.language}#${this.script}`;\n }\n\n if (this.language && this.region) {\n return `${this.language}_${this.region}`;\n }\n\n return this.language;\n }\n\n get isBaseLocale(): boolean {\n return this.locale === this.baseLocale;\n }\n\n public toCdnLocale(): CdnLocale {\n return {\n locale: this.locale,\n isBaseLocale: this.isBaseLocale,\n language: this.language,\n region: this.region,\n script: this.script,\n isRtl: this.isRtl,\n name: this.name,\n localizedName: this.localizedName,\n };\n }\n}\n","import { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport { uniqBy } from '@/cdn/utils.js';\nimport type { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale.js';\nimport type { IMetafileFiles } from '@/interfaces/i-metafile-files.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\nimport type { FilesMap } from '@/types/files-map.js';\nimport type { MetafileOptions } from '@/types/metafile-options.js';\n\nexport class MetafileData implements Omit<IMetafile, 'files' | 'baseLocale'> {\n public projectUrl: string;\n\n public baseLocale: CdnLocale;\n\n public locales: CdnLocale[];\n\n public timestamp: number;\n\n public files: MetafileFile[];\n\n public filesMap: FilesMap;\n\n constructor(options: MetafileOptions, params: MetafileParams) {\n this.projectUrl = options.projectUrl;\n this.timestamp = options.timestamp;\n this.files = MetafileData.filesFactory(options.files, options.baseLocale, params);\n this.filesMap = MetafileData.filesMapFactory(this.files);\n this.locales = MetafileData.localesFactory(this.files);\n this.baseLocale = this.locales.find((locale: CdnLocale) => locale.isBaseLocale) as CdnLocale;\n }\n\n public static createEmpty(params: MetafileParams): MetafileData {\n return new MetafileData(\n {\n projectUrl: '',\n baseLocale: '',\n timestamp: 0,\n files: {},\n },\n params,\n );\n }\n\n protected static filesFactory(\n files: IMetafileFiles,\n baseLocale: string,\n params: MetafileParams,\n ): MetafileFile[] {\n return Object.keys(files).reduce((acc: MetafileFile[], cur: string) => {\n if (typeof files[cur] !== 'undefined') {\n const locales: MetafileLocale[] = files[cur].locales.map(\n (locale: IMetafileFileLocale) => new MetafileLocale(locale, baseLocale),\n );\n\n acc.push(\n new MetafileFile({\n ...files[cur],\n id: cur,\n locales,\n baseUrl: params.baseUrl,\n }),\n );\n }\n\n return acc;\n }, []);\n }\n\n protected static filesMapFactory(files: MetafileFile[]): FilesMap {\n return files.reduce((acc: FilesMap, cur: MetafileFile) => {\n acc[cur.id] = cur;\n\n return acc;\n }, {});\n }\n\n protected static localesFactory(files: MetafileFile[]): CdnLocale[] {\n const locales: CdnLocale[] = files.reduce((acc: CdnLocale[], cur: MetafileFile) => {\n acc.push(...cur.locales.map((locale: MetafileLocale): CdnLocale => locale.toCdnLocale()));\n return acc;\n }, []);\n\n return uniqBy(locales, (cdnLocale: CdnLocale): string => cdnLocale.locale);\n }\n}\n","import type { IMetafileParams } from '@/interfaces/i-metafile-params.js';\n\nexport class MetafileParams implements IMetafileParams {\n protected options: IMetafileParams;\n\n constructor(metafileUrl: string) {\n this.options = MetafileParams.parseMetafileUrl(metafileUrl);\n }\n\n get url(): string {\n return this.options.url;\n }\n\n get baseUrl(): string {\n return this.options.baseUrl;\n }\n\n get cdnId(): string {\n return this.options.cdnId;\n }\n\n get jsonPath(): string {\n return this.options.jsonPath;\n }\n\n protected static parseMetafileUrl(metafileUrl: string): IMetafileParams {\n let url: URL;\n\n try {\n url = new URL(metafileUrl);\n } catch {\n throw new Error('Invalid param: \"options.metafile\" cannot be parsed as url.');\n }\n\n const matches: string[] | null = /^\\/(.*?)\\/(.*?)\\.(v2.json|js|ts)$/.exec(url.pathname);\n\n if (\n matches === null ||\n matches.length !== 4 ||\n typeof matches[1] === 'undefined' ||\n typeof matches[2] === 'undefined'\n ) {\n throw new Error('Invalid param: \"options.metafile\" contains invalid metafile url.');\n }\n\n const cdnId: string = matches[1];\n const tagId: string = matches[2];\n\n return {\n url: metafileUrl,\n baseUrl: url.origin,\n cdnId,\n jsonPath: `/${cdnId}/${tagId}.v2.json`,\n };\n }\n}\n","import { MetafileData } from '@/cdn/metafile/metafile-data.js';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\n\nexport class MetafileContext {\n public params: MetafileParams;\n\n public parsedData: IMetafile | null;\n\n public data: MetafileData;\n\n constructor(options: CdnClientOptions) {\n this.params = new MetafileParams(options.metafile);\n this.parsedData = null;\n this.data = MetafileData.createEmpty(this.params);\n }\n\n public setMetafile(metafile: IMetafile): void {\n this.parsedData = metafile;\n\n this.data = new MetafileData(metafile, this.params);\n }\n}\n","import type { IHttpAdapter } from '@/interfaces/i-http-adapter.js';\n\nexport class FetchHttpAdapter implements IHttpAdapter {\n protected baseUrl: string;\n\n constructor(baseUrl: string) {\n this.baseUrl = baseUrl;\n }\n\n async get(url: string): Promise<string | object> {\n const response: Response = await fetch(`${this.baseUrl}${url}`);\n const contentType: string | null = response.headers.get('content-type');\n const isJson: boolean =\n contentType === 'application/json5' || contentType === 'application/json';\n\n if (response.status >= 400) {\n throw new Error(`Request failed with status code ${response.status.toString()}`);\n }\n\n let result: string | object;\n\n if (isJson) {\n result = (await response.json()) as object;\n } else {\n result = await response.text();\n }\n\n return result;\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\n\nexport abstract class CdnBase {\n protected context: Context;\n\n constructor(context: Context) {\n this.context = context;\n }\n}\n","import { CdnBase } from '@/cdn/methods/cdn-base.js';\n\nexport class CdnCache extends CdnBase {\n public flush = (): void => {\n this.context.cache.flush();\n };\n}\n","import type { MetafileData } from '@/cdn/metafile/metafile-data.js';\nimport type { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params.js';\nimport { CdnBase } from '@/cdn/methods/cdn-base.js';\nimport type { IMetafile } from '@/interfaces/i-metafile.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\nimport type { CdnLocale } from '@/types/cdn-locale.js';\nimport type { CdnLocalesOptions } from '@/types/cdn-locales-options.js';\n\nexport class CdnMetafile extends CdnBase {\n get projectUrl(): string {\n return this.context.metafile.data.projectUrl;\n }\n\n get baseLocale(): CdnLocale {\n return this.context.metafile.data.baseLocale;\n }\n\n get url(): string {\n return this.context.metafile.params.url;\n }\n\n get files(): CdnFile[] {\n return this.context.metafile.data.files.map((file: MetafileFile): CdnFile => file.toCdnFile());\n }\n\n public locales = (options?: CdnLocalesOptions): CdnLocale[] => {\n const { excludeBaseLocale }: CdnLocalesOptions = options || {};\n const { locales }: MetafileData = this.context.metafile.data;\n\n return excludeBaseLocale\n ? locales.filter((cdnLocale: CdnLocale): boolean => !cdnLocale.isBaseLocale)\n : locales;\n };\n\n public refresh = async (): Promise<void> => {\n const response: IMetafile = await this.context.api.fetchMetafile();\n\n this.context.metafile.setMetafile(response);\n };\n\n public switch = async (options: CdnClientOptions): Promise<void> => {\n this.context.metafile.params = new MetafileParams(options.metafile);\n\n await this.refresh();\n };\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { LocalesMapData } from '@/types/locales-map-data.js';\nimport type { LocalesMapOptions } from '@/types/locales-map-options.js';\n\nexport class LocalesMap {\n public data: LocalesMapData;\n\n protected context: Context;\n\n constructor(options: LocalesMapOptions) {\n this.context = options.context;\n this.data = options.data || {};\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport type { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport { LocalesMap } from '@/cdn/request/locales-map.js';\nimport type { ApiLocaleRequest } from '@/types/api-locale-request.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\n\nexport class Request {\n public files: MetafileFile[];\n\n public localesMap: LocalesMap;\n\n public hasSingleFileResponse: boolean;\n\n public hasSingleLocaleResponse: boolean;\n\n protected context: Context;\n\n constructor(context: Context) {\n this.files = [];\n this.localesMap = new LocalesMap({ context });\n this.hasSingleFileResponse = false;\n this.hasSingleLocaleResponse = false;\n this.context = context;\n }\n\n public async execute(): Promise<CdnResponse> {\n const payload: [Promise<string | object>, ApiLocaleRequest][] = this.getPromises();\n const promises: Promise<string | object>[] = payload.map(\n (item: [Promise<string | object>, ApiLocaleRequest]) => item[0],\n );\n const requests: ApiLocaleRequest[] = payload.map(\n (item: [Promise<string | object>, ApiLocaleRequest]) => item[1],\n );\n const responses: (string | object)[] = await Promise.all(promises);\n\n return this.context.responseFactory.createCdnResponse({\n requests,\n responses,\n localesMap: this.localesMap,\n hasSingleFileResponse: this.hasSingleFileResponse,\n hasSingleLocaleResponse: this.hasSingleLocaleResponse,\n });\n }\n\n protected getPromises(): [Promise<string | object>, ApiLocaleRequest][] {\n return this.files.reduce(\n (acc: [Promise<string | object>, ApiLocaleRequest][], cur: MetafileFile) => {\n if (typeof this.localesMap.data?.[cur.id] !== 'undefined') {\n acc.push(\n // @ts-expect-error TODO fix type\n ...this.localesMap.data[cur.id].map(\n (metafileLocale: MetafileLocale): [Promise<string | object>, ApiLocaleRequest] => {\n const request: ApiLocaleRequest = {\n metafileFile: cur,\n metafileLocale,\n };\n\n return [this.context.api.fetchLocale(request), request];\n },\n ),\n );\n }\n return acc;\n },\n [],\n );\n }\n}\n","import type { Context } from '@/cdn/context/context.js';\nimport { MetafileFile } from '@/cdn/metafile/metafile-file.js';\nimport type { MetafileLocale } from '@/cdn/metafile/metafile-locale.js';\nimport type { LocalesMap } from '@/cdn/request/locales-map.js';\nimport { Request } from '@/cdn/request/request.js';\nimport { isArray, isPlainObject, isString, isUndefined } from '@/cdn/utils.js';\nimport type { IRequestBuilder } from '@/interfaces/i-request-builder.js';\nimport type { CdnFile } from '@/types/cdn-file.js';\n\nexport class RequestBuilder implements IRequestBuilder {\n protected context: Context;\n\n protected request: Request;\n\n constructor(context: Context) {\n this.context = context;\n this.request = new Request(this.context);\n }\n\n public addFiles(files?: (CdnFile | string)[] | CdnFile | string): this {\n if (!(isPlainObject(files) || isString(files) || isUndefined(files) || isArray(files))) {\n throw new Error('Invalid param: \"request.files\" must be object, array, string or undefined.');\n }\n\n if (isArray(files)) {\n files.forEach((i: CdnFile | string): void => {\n if (!(isPlainObject(i) || isString(i))) {\n throw new Error('Invalid param: array \"request.files\" must contain objects or strings.');\n }\n });\n }\n\n if (isString(files)) {\n this.request.hasSingleFileResponse = true;\n\n const file: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === files,\n );\n\n if (!(file instanceof MetafileFile)) {\n throw new Error(`File not found: \"${files}\".`);\n }\n\n this.request.files = [file];\n } else if (isUndefined(files)) {\n this.request.files = [...this.context.metafile.data.files];\n } else if (isArray(files)) {\n this.request.files = files.map((file: CdnFile | string): MetafileFile => {\n let metafileFile: MetafileFile;\n\n if (isString(file)) {\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === file,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${file}\".`);\n }\n\n metafileFile = foundFile;\n } else {\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === file.id,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${file.id}\".`);\n }\n\n metafileFile = foundFile;\n }\n\n return metafileFile;\n });\n } else if (isPlainObject(files)) {\n this.request.hasSingleFileResponse = true;\n\n const foundFile: MetafileFile | undefined = this.context.metafile.data.files.find(\n (i: MetafileFile): boolean => i.id === files.id,\n );\n\n if (isUndefined(foundFile)) {\n throw new Error(`File not found: \"${files.id}\".`);\n }\n\n this.request.files = [foundFile];\n }\n\n return this;\n }\n\n public addLocales(locales?: string[] | string, excludeBaseLocale?: boolean): this {\n if (!(isString(locales) || isUndefined(locales) || isArray(locales))) {\n throw new Error('Invalid param: \"request.locales\" must be array, string or undefined.');\n }\n\n if (isArray(locales)) {\n locales.forEach((i: MetafileFile | string): void => {\n if (!isString(i)) {\n throw new Error('Invalid param: array \"request.locales\" must contain strings.');\n }\n });\n }\n\n if (isString(locales)) {\n this.request.hasSingleLocaleResponse = true;\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = cur.locales.filter(\n (metafileLocale: MetafileLocale): boolean => metafileLocale.locale === locales,\n );\n\n return acc;\n }, this.request.localesMap);\n } else if (isUndefined(locales)) {\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = excludeBaseLocale\n ? cur.locales.filter(\n (metafileLocale: MetafileLocale): boolean => !metafileLocale.isBaseLocale,\n )\n : cur.locales;\n\n return acc;\n }, this.request.localesMap);\n } else if (isArray(locales)) {\n this.request.files.reduce((acc: LocalesMap, cur: MetafileFile) => {\n acc.data[cur.id] = cur.locales.filter((metafileLocale: MetafileLocale) =>\n locales.includes(metafileLocale.locale),\n );\n\n return acc;\n }, this.request.localesMap);\n }\n\n return this;\n }\n\n public getCdnRequest(): Request {\n const result: Request = this.request;\n this.request = new Request(this.context);\n return result;\n }\n}\n","import { Context } from '@/cdn/context/context.js';\nimport { MetafileContext } from '@/cdn/context/metafile-context.js';\nimport { FetchHttpAdapter } from '@/cdn/http/fetch-http-adapter.js';\nimport { CdnCache } from '@/cdn/methods/cdn-cache.js';\nimport { CdnMetafile } from '@/cdn/methods/cdn-metafile.js';\nimport { RequestBuilder } from '@/cdn/request/request-builder.js';\nimport { isString } from '@/cdn/utils.js';\nimport type { CdnClientOptions } from '@/types/cdn-client-options.js';\nimport type { CdnFetchOptions } from '@/types/cdn-fetch-options.js';\nimport type { CdnResponse } from '@/types/cdn-response.js';\n\nexport class CdnClient {\n public metafile: CdnMetafile;\n\n public cache: CdnCache;\n\n protected context: Context;\n\n public static version = '__CLIENT_VERSION__';\n\n protected constructor(options: CdnClientOptions) {\n const metafileContext: MetafileContext = new MetafileContext(options);\n const client: FetchHttpAdapter = new FetchHttpAdapter(metafileContext.params.baseUrl);\n\n this.context = new Context({ metafileContext, cdn: this, client });\n this.metafile = new CdnMetafile(this.context);\n this.cache = new CdnCache(this.context);\n }\n\n public fetch = async (options?: CdnFetchOptions): Promise<CdnResponse> => {\n const { files, locales, excludeBaseLocale }: CdnFetchOptions = options || {};\n const requestBuilder: RequestBuilder = new RequestBuilder(this.context)\n .addFiles(files)\n .addLocales(locales, excludeBaseLocale);\n\n return requestBuilder.getCdnRequest().execute();\n };\n\n public static async create(options: CdnClientOptions): Promise<CdnClient> {\n if (!options) {\n throw new Error('Invalid param: missing required \"options\" parameter.');\n }\n\n if (!isString(options.metafile)) {\n throw new Error('Invalid param: \"options.metafile\" must be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K,OAAO;AACvC,WAAO;AAAA,EACT;AACF;AClIO,MAAM,UAAU;AAAA,EACd;AAAA,EAEA;AAAA,EAEG;AAAA,EAEV,OAAc,UAAU;AAAA,EAEd,YAAY,SAA2B;AAC/C,UAAM,kBAAmC,IAAI,gBAAgB,OAAO;AACpE,UAAM,SAA2B,IAAI,iBAAiB,gBAAgB,OAAO,OAAO;AAEpF,SAAK,UAAU,IAAI,QAAQ,EAAE,iBAAiB,KAAK,MAAM,QAAQ;AACjE,SAAK,WAAW,IAAI,YAAY,KAAK,OAAO;AAC5C,SAAK,QAAQ,IAAI,SAAS,KAAK,OAAO;AAAA,EACxC;AAAA,EAEO,QAAQ,OAAO,YAAoD;AACxE,UAAM,EAAE,OAAO,SAAS,kBAAA,IAAuC,WAAW,CAAA;AAC1E,UAAM,iBAAiC,IAAI,eAAe,KAAK,OAAO,EACnE,SAAS,KAAK,EACd,WAAW,SAAS,iBAAiB;AAExC,WAAO,eAAe,cAAA,EAAgB,QAAA;AAAA,EACxC;AAAA,EAEA,aAAoB,OAAO,SAA+C;AACxE,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI,MAAM,sDAAsD;AAAA,IACxE;AAEA,QAAI,CAAC,SAAS,QAAQ,QAAQ,GAAG;AAC/B,YAAM,IAAI,MAAM,mDAAmD;AAAA,IACrE;AAEA,UAAM,MAAiB,IAAI,UAAU,OAAO;AAE5C,UAAM,IAAI,SAAS,QAAA;AAEnB,WAAO;AAAA,EACT;AACF;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@localazy/cdn-client",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.9",
|
|
4
4
|
"description": "Node.js module that allows you to easily interact with the Localazy CDN.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Localazy",
|
|
@@ -72,31 +72,31 @@
|
|
|
72
72
|
},
|
|
73
73
|
"prettier": "@localazy/prettier-config",
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@localazy/conventional-changelog-preset": "^1.3.
|
|
75
|
+
"@localazy/conventional-changelog-preset": "^1.3.3",
|
|
76
76
|
"@localazy/eslint-config": "^1.3.0",
|
|
77
77
|
"@localazy/prettier-config": "^1.2.0",
|
|
78
78
|
"@localazy/tsconfig": "^1.1.1",
|
|
79
79
|
"@rollup/plugin-terser": "^0.4.4",
|
|
80
80
|
"@types/isomorphic-fetch": "^0.0.39",
|
|
81
|
-
"@types/node": "^22.
|
|
82
|
-
"@vitest/coverage-v8": "^
|
|
83
|
-
"@vitest/ui": "^
|
|
81
|
+
"@types/node": "^22.19.0",
|
|
82
|
+
"@vitest/coverage-v8": "^4.0.7",
|
|
83
|
+
"@vitest/ui": "^4.0.7",
|
|
84
84
|
"conventional-changelog": "^5.1.0",
|
|
85
85
|
"conventional-changelog-cli": "^4.1.0",
|
|
86
86
|
"conventional-changelog-writer": "github:localazy/conventional-changelog-writer",
|
|
87
87
|
"conventional-recommended-bump": "^9.0.0",
|
|
88
|
-
"eslint": "^9.
|
|
89
|
-
"fetch-mock": "^12.
|
|
88
|
+
"eslint": "^9.39.1",
|
|
89
|
+
"fetch-mock": "^12.6.0",
|
|
90
90
|
"husky": "^9.1.7",
|
|
91
91
|
"isomorphic-fetch": "^3.0.0",
|
|
92
92
|
"prettier": "^3.6.2",
|
|
93
93
|
"reexport": "^1.4.1",
|
|
94
|
-
"typescript": "^5.9.
|
|
95
|
-
"unplugin-replace": "^0.6.
|
|
96
|
-
"vite": "^7.1
|
|
94
|
+
"typescript": "^5.9.3",
|
|
95
|
+
"unplugin-replace": "^0.6.2",
|
|
96
|
+
"vite": "^7.2.1",
|
|
97
97
|
"vite-bundle-visualizer": "^1.2.1",
|
|
98
98
|
"vite-plugin-dts": "^4.5.4",
|
|
99
|
-
"vitest": "^
|
|
99
|
+
"vitest": "^4.0.7"
|
|
100
100
|
},
|
|
101
101
|
"packageManager": "npm@10.9.3",
|
|
102
102
|
"engines": {
|