@localazy/cdn-client 1.5.1 → 1.5.3
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 +4 -5
- package/dist/browser/localazy-cdn-client.umd.min.js.map +1 -1
- package/dist/index.d.ts +9 -28
- package/dist/localazy-cdn-client.js +160 -156
- package/dist/localazy-cdn-client.js.map +1 -1
- package/dist/localazy-cdn-client.min.js +4 -5
- package/dist/localazy-cdn-client.min.js.map +1 -1
- package/dist/node/localazy-cdn-client.cjs +160 -156
- package/dist/node/localazy-cdn-client.cjs.map +1 -1
- package/package.json +43 -52
|
@@ -1,6 +1,5 @@
|
|
|
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";var t=Object.defineProperty,s=(e,s,i)=>((
|
|
2
|
-
/* @localazy/cdn-client@1.5.
|
|
3
|
-
* (c)
|
|
4
|
-
* @license MIT */
|
|
5
|
-
class i{constructor(e){s(this,"context"),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)}}const a=e=>"string"==typeof e,l=e=>void 0===e,r=e=>Array.isArray(e),o=e=>"[object Object]"===Object.prototype.toString.call(e),n=e=>[...new Set(e)],c=(e,t)=>{const s={};return e.filter((e=>{const i=t(e);return!Object.hasOwn(s,i)&&(s[i]=!0,!0)}))};class h{constructor(){s(this,"map"),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}}class u{constructor(e){s(this,"context"),s(this,"cacheAdapter"),this.context=e,this.cacheAdapter=new h}setIfMissed(e){const{metafileFile:t,metafileLocale:s,data:i}=e,a=this.keyFromMetafile({metafileFile:t,metafileLocale:s});this.cacheAdapter.has(a)||this.cacheAdapter.set(a,i)}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,i=[...n(t.productFlavors)].sort().join("-");return[this.context.metafile.params.cdnId,t.id,t.file,t.path,t.library,t.module,t.buildType,i,s.locale,s.timestamp.toString()].filter((e=>""!==e)).join("-")}}class p{constructor(e){s(this,"context"),this.context=e}}class f extends p{constructor(){super(...arguments),s(this,"flush",(()=>{this.context.cache.flush()}))}}class d{constructor(e,t){s(this,"language"),s(this,"region"),s(this,"script"),s(this,"isRtl"),s(this,"name"),s(this,"localizedName"),s(this,"uri"),s(this,"timestamp"),s(this,"baseLocale"),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 m{constructor(e){s(this,"id"),s(this,"file"),s(this,"path"),s(this,"library"),s(this,"module"),s(this,"buildType"),s(this,"timestamp"),s(this,"productFlavors"),s(this,"locales"),s(this,"baseUrl"),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 g{constructor(e,t){s(this,"projectUrl"),s(this,"baseLocale"),s(this,"locales"),s(this,"timestamp"),s(this,"files"),s(this,"filesMap"),this.projectUrl=e.projectUrl,this.timestamp=e.timestamp,this.files=g.filesFactory(e.files,e.baseLocale,t),this.filesMap=g.filesMapFactory(this.files),this.locales=g.localesFactory(this.files),this.baseLocale=this.locales.find((e=>e.isBaseLocale))}static createEmpty(e){return new g({projectUrl:"",baseLocale:"",timestamp:0,files:{}},e)}static filesFactory(e,t,s){return Object.keys(e).reduce(((i,a)=>{const l=e[a].locales.map((e=>new d(e,t)));return i.push(new m({...e[a],id:a,locales:l,baseUrl:s.baseUrl})),i}),[])}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 c(t,(e=>e.locale))}}class w{constructor(e){s(this,"options"),this.options=w.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(e){throw new Error('Invalid param: "options.metafile" cannot be parsed as url.')}const s=t.pathname.match(/^\/(.*?)\/(.*?)\.(v2.json|js|ts)$/);if(null===s||4!==s.length)throw new Error('Invalid param: "options.metafile" contains invalid metafile url.');const i=s[1],a=s[2];return{url:e,baseUrl:t.origin,cdnId:i,jsonPath:`/${i}/${a}.v2.json`}}}class x{constructor(e){s(this,"params"),s(this,"parsedData"),s(this,"data"),this.params=new w(e.metafile),this.parsedData=null,this.data=g.createEmpty(this.params)}setMetafile(e){this.parsedData=e,this.data=new g(e,this.params)}}class y{constructor(e){s(this,"context"),this.context=e}createCdnResponse(e){const{requests:t,responses:s,hasSingleFileResponse:i,hasSingleLocaleResponse:a}=e;return 0===s.length?{}:(this.cacheResponses(t,s),i&&a?s[0]:y.transformResponses(e))}cacheResponses(e,t){t.forEach(((t,s)=>{const{metafileFile:i,metafileLocale:a}=e[s];i&&a&&this.context.cache.setIfMissed({metafileFile:i,metafileLocale:a,data:t})}))}static transformResponses(e){const{requests:t,responses:s,hasSingleFileResponse:i}=e;return s.reduce(((e,s,a)=>{const{metafileFile:l,metafileLocale:r}=t[a];return l&&r&&(i?e[r.locale]=s:(e[l.id]||(e[l.id]={}),e[l.id][r.locale]=s)),e}),{})}}class b{constructor(e){s(this,"metafile"),s(this,"cdn"),s(this,"client"),s(this,"api"),s(this,"cache"),s(this,"responseFactory"),this.metafile=e.metafileContext,this.cdn=e.cdn,this.client=e.client,this.api=new i(this),this.cache=new u(this),this.responseFactory=new y(this)}}class F extends p{constructor(){super(...arguments),s(this,"locales",(e=>{const{excludeBaseLocale:t}=e||{},{locales:s}=this.context.metafile.data;return t?s.filter((e=>!e.isBaseLocale)):s})),s(this,"refresh",(async()=>{const e=await this.context.api.fetchMetafile();this.context.metafile.setMetafile(e)})),s(this,"switch",(async e=>{this.context.metafile.params=new w(e.metafile),await this.refresh()}))}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()))}}class L{constructor(e){s(this,"data"),s(this,"context"),this.context=e.context,this.data=e.data||{}}}class M{constructor(e){s(this,"files"),s(this,"localesMap"),s(this,"hasSingleFileResponse"),s(this,"hasSingleLocaleResponse"),s(this,"context"),this.files=[],this.localesMap=new L({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])),i=await Promise.all(t);return this.context.responseFactory.createCdnResponse({requests:s,responses:i,localesMap:this.localesMap,hasSingleFileResponse:this.hasSingleFileResponse,hasSingleLocaleResponse:this.hasSingleLocaleResponse})}getPromises(){return this.files.reduce(((e,t)=>(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 q{constructor(e){s(this,"context"),s(this,"request"),this.context=e,this.request=new M(this.context)}addFiles(e){if(!(o(e)||a(e)||l(e)||r(e)))throw new Error('Invalid param: "request.files" must be object, array, string or undefined.');if(r(e)&&e.forEach((e=>{if(!o(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 m))throw new Error(`File not found: "${e}".`);this.request.files=[t]}else if(l(e))this.request.files=[...this.context.metafile.data.files];else if(r(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(l(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(l(s))throw new Error(`File not found: "${e.id}".`);t=s}return t}));else if(o(e)){this.request.hasSingleFileResponse=!0;const t=this.context.metafile.data.files.find((t=>t.id===e.id));if(l(t))throw new Error(`File not found: "${e.id}".`);this.request.files=[t]}return this}addLocales(e,t){if(!(a(e)||l(e)||r(e)))throw new Error('Invalid param: "request.locales" must be array, string or undefined.');return r(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)):l(e)?this.request.files.reduce(((e,s)=>(e.data[s.id]=t?s.locales.filter((e=>!e.isBaseLocale)):s.locales,e)),this.request.localesMap):r(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 M(this.context),e}}class R{constructor(e){s(this,"baseUrl"),this.baseUrl=e}async get(e){const t=await fetch(`${this.baseUrl}${e}`),s=t.headers.get("content-type"),i="application/json5"===s||"application/json"===s;if(t.status>=400)throw new Error(`Request failed with status code ${t.status}`);let a;return a=i?await t.json():await t.text(),a}}const j=class e{constructor(e){s(this,"metafile"),s(this,"cache"),s(this,"context"),s(this,"fetch",(async e=>{const{files:t,locales:s,excludeBaseLocale:i}=e||{};return new q(this.context).addFiles(t).addLocales(s,i).getCdnRequest().execute()}));const t=new x(e),i=new R(t.params.baseUrl);this.context=new b({metafileContext:t,cdn:this,client:i}),this.metafile=new F(this.context),this.cache=new f(this.context)}static async create(t){if(!t)throw new Error('Invalid param: missing required "options" parameter.');if(!a(t.metafile))throw new Error('Invalid param: "options.metafile" must be string.');const s=new e(t);return await s.metafile.refresh(),s}};s(j,"version","1.5.1");let U=j;e.Api=i,e.CdnBase=p,e.CdnCache=f,e.CdnClient=U,e.CdnMetafile=F,e.Context=b,e.FetchHttpAdapter=R,e.LocalesCache=u,e.LocalesMap=L,e.MemoryCacheAdapter=h,e.MetafileContext=x,e.MetafileData=g,e.MetafileFile=m,e.MetafileLocale=d,e.MetafileParams=w,e.Request=M,e.RequestBuilder=q,e.ResponseFactory=y,e.isArray=r,e.isPlainObject=o,e.isString=a,e.isUndefined=l,e.uniq=n,e.uniqBy=c,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";var t=Object.defineProperty,s=(e,s,i)=>((e,s,i)=>s in e?t(e,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[s]=i)(e,"symbol"!=typeof s?s+"":s,i)
|
|
2
|
+
/* @localazy/cdn-client@1.5.3
|
|
3
|
+
* (c) 2025 Localazy <team@localazy.com>
|
|
4
|
+
* @license MIT */;class i{constructor(e){s(this,"context"),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 a{constructor(){s(this,"map"),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 l=e=>"string"==typeof e,r=e=>void 0===e,o=e=>Array.isArray(e),n=e=>"[object Object]"===Object.prototype.toString.call(e),c=e=>[...new Set(e)],h=(e,t)=>{const s={};return e.filter((e=>{const i=t(e);return!Object.hasOwn(s,i)&&(s[i]=!0,!0)}))};class u{constructor(e){s(this,"context"),s(this,"cacheAdapter"),this.context=e,this.cacheAdapter=new a}setIfMissed(e){const{metafileFile:t,metafileLocale:s,data:i}=e,a=this.keyFromMetafile({metafileFile:t,metafileLocale:s});this.cacheAdapter.has(a)||this.cacheAdapter.set(a,i)}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,i=[...c(t.productFlavors)].sort().join("-");return[this.context.metafile.params.cdnId,t.id,t.file,t.path,t.library,t.module,t.buildType,i,s.locale,s.timestamp.toString()].filter((e=>""!==e)).join("-")}}class d{constructor(e){s(this,"context"),this.context=e}createCdnResponse(e){const{requests:t,responses:s,hasSingleFileResponse:i,hasSingleLocaleResponse:a}=e;return 0===s.length||void 0===s[0]?{}:(this.cacheResponses(t,s),i&&a?s[0]:d.transformResponses(e))}cacheResponses(e,t){t.forEach(((t,s)=>{if(void 0!==e[s]){const{metafileFile:i,metafileLocale:a}=e[s];i&&a&&this.context.cache.setIfMissed({metafileFile:i,metafileLocale:a,data:t})}}))}static transformResponses(e){const{requests:t,responses:s,hasSingleFileResponse:i}=e;return s.reduce(((e,s,a)=>{if(void 0!==t[a]){const{metafileFile:l,metafileLocale:r}=t[a];l&&r&&(i?e[r.locale]=s:(e[l.id]||(e[l.id]={}),e[l.id][r.locale]=s))}return e}),{})}}class f{constructor(e){s(this,"metafile"),s(this,"cdn"),s(this,"client"),s(this,"api"),s(this,"cache"),s(this,"responseFactory"),this.metafile=e.metafileContext,this.cdn=e.cdn,this.client=e.client,this.api=new i(this),this.cache=new u(this),this.responseFactory=new d(this)}}class p{constructor(e){s(this,"id"),s(this,"file"),s(this,"path"),s(this,"library"),s(this,"module"),s(this,"buildType"),s(this,"timestamp"),s(this,"productFlavors"),s(this,"locales"),s(this,"baseUrl"),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 m{constructor(e,t){s(this,"language"),s(this,"region"),s(this,"script"),s(this,"isRtl"),s(this,"name"),s(this,"localizedName"),s(this,"uri"),s(this,"timestamp"),s(this,"baseLocale"),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 g{constructor(e,t){s(this,"projectUrl"),s(this,"baseLocale"),s(this,"locales"),s(this,"timestamp"),s(this,"files"),s(this,"filesMap"),this.projectUrl=e.projectUrl,this.timestamp=e.timestamp,this.files=g.filesFactory(e.files,e.baseLocale,t),this.filesMap=g.filesMapFactory(this.files),this.locales=g.localesFactory(this.files),this.baseLocale=this.locales.find((e=>e.isBaseLocale))}static createEmpty(e){return new g({projectUrl:"",baseLocale:"",timestamp:0,files:{}},e)}static filesFactory(e,t,s){return Object.keys(e).reduce(((i,a)=>{if(void 0!==e[a]){const l=e[a].locales.map((e=>new m(e,t)));i.push(new p({...e[a],id:a,locales:l,baseUrl:s.baseUrl}))}return i}),[])}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 h(t,(e=>e.locale))}}class w{constructor(e){s(this,"options"),this.options=w.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 i=s[1],a=s[2];return{url:e,baseUrl:t.origin,cdnId:i,jsonPath:`/${i}/${a}.v2.json`}}}class x{constructor(e){s(this,"params"),s(this,"parsedData"),s(this,"data"),this.params=new w(e.metafile),this.parsedData=null,this.data=g.createEmpty(this.params)}setMetafile(e){this.parsedData=e,this.data=new g(e,this.params)}}class y{constructor(e){s(this,"baseUrl"),this.baseUrl=e}async get(e){const t=await fetch(`${this.baseUrl}${e}`),s=t.headers.get("content-type"),i="application/json5"===s||"application/json"===s;if(t.status>=400)throw new Error(`Request failed with status code ${t.status.toString()}`);let a;return a=i?await t.json():await t.text(),a}}class b{constructor(e){s(this,"context"),this.context=e}}class F extends b{constructor(){super(...arguments),s(this,"flush",(()=>{this.context.cache.flush()}))}}class L extends b{constructor(){super(...arguments),s(this,"locales",(e=>{const{excludeBaseLocale:t}=e||{},{locales:s}=this.context.metafile.data;return t?s.filter((e=>!e.isBaseLocale)):s})),s(this,"refresh",(async()=>{const e=await this.context.api.fetchMetafile();this.context.metafile.setMetafile(e)})),s(this,"switch",(async e=>{this.context.metafile.params=new w(e.metafile),await this.refresh()}))}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()))}}class M{constructor(e){s(this,"data"),s(this,"context"),this.context=e.context,this.data=e.data||{}}}class q{constructor(e){s(this,"files"),s(this,"localesMap"),s(this,"hasSingleFileResponse"),s(this,"hasSingleLocaleResponse"),s(this,"context"),this.files=[],this.localesMap=new M({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])),i=await Promise.all(t);return this.context.responseFactory.createCdnResponse({requests:s,responses:i,localesMap:this.localesMap,hasSingleFileResponse:this.hasSingleFileResponse,hasSingleLocaleResponse:this.hasSingleLocaleResponse})}getPromises(){return this.files.reduce(((e,t)=>{var s;return void 0!==(null==(s=this.localesMap.data)?void 0:s[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 R{constructor(e){s(this,"context"),s(this,"request"),this.context=e,this.request=new q(this.context)}addFiles(e){if(!(n(e)||l(e)||r(e)||o(e)))throw new Error('Invalid param: "request.files" must be object, array, string or undefined.');if(o(e)&&e.forEach((e=>{if(!n(e)&&!l(e))throw new Error('Invalid param: array "request.files" must contain objects or strings.')})),l(e)){this.request.hasSingleFileResponse=!0;const t=this.context.metafile.data.files.find((t=>t.id===e));if(!(t instanceof p))throw new Error(`File not found: "${e}".`);this.request.files=[t]}else if(r(e))this.request.files=[...this.context.metafile.data.files];else if(o(e))this.request.files=e.map((e=>{let t;if(l(e)){const s=this.context.metafile.data.files.find((t=>t.id===e));if(r(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(r(s))throw new Error(`File not found: "${e.id}".`);t=s}return t}));else if(n(e)){this.request.hasSingleFileResponse=!0;const t=this.context.metafile.data.files.find((t=>t.id===e.id));if(r(t))throw new Error(`File not found: "${e.id}".`);this.request.files=[t]}return this}addLocales(e,t){if(!(l(e)||r(e)||o(e)))throw new Error('Invalid param: "request.locales" must be array, string or undefined.');return o(e)&&e.forEach((e=>{if(!l(e))throw new Error('Invalid param: array "request.locales" must contain strings.')})),l(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)):r(e)?this.request.files.reduce(((e,s)=>(e.data[s.id]=t?s.locales.filter((e=>!e.isBaseLocale)):s.locales,e)),this.request.localesMap):o(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 q(this.context),e}}const v=class e{constructor(e){s(this,"metafile"),s(this,"cache"),s(this,"context"),s(this,"fetch",(async e=>{const{files:t,locales:s,excludeBaseLocale:i}=e||{};return new R(this.context).addFiles(t).addLocales(s,i).getCdnRequest().execute()}));const t=new x(e),i=new y(t.params.baseUrl);this.context=new f({metafileContext:t,cdn:this,client:i}),this.metafile=new L(this.context),this.cache=new F(this.context)}static async create(t){if(!t)throw new Error('Invalid param: missing required "options" parameter.');if(!l(t.metafile))throw new Error('Invalid param: "options.metafile" must be string.');const s=new e(t);return await s.metafile.refresh(),s}};s(v,"version","1.5.3");let j=v;e.Api=i,e.CdnBase=b,e.CdnCache=F,e.CdnClient=j,e.CdnMetafile=L,e.Context=f,e.FetchHttpAdapter=y,e.LocalesCache=u,e.LocalesMap=M,e.MemoryCacheAdapter=a,e.MetafileContext=x,e.MetafileData=g,e.MetafileFile=p,e.MetafileLocale=m,e.MetafileParams=w,e.Request=q,e.RequestBuilder=R,e.ResponseFactory=d,e.isArray=o,e.isPlainObject=n,e.isString=l,e.isUndefined=r,e.uniq=c,e.uniqBy=h,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
|
|
6
5
|
//# 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/utils.ts","../../src/cdn/cache/memory-cache-adapter.ts","../../src/cdn/cache/locales-cache.ts","../../src/cdn/methods/cdn-base.ts","../../src/cdn/methods/cdn-cache.ts","../../src/cdn/metafile/metafile-locale.ts","../../src/cdn/metafile/metafile-file.ts","../../src/cdn/metafile/metafile-data.ts","../../src/cdn/metafile/metafile-params.ts","../../src/cdn/context/metafile-context.ts","../../src/cdn/response/response-factory.ts","../../src/cdn/context/context.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/http/fetch-http-adapter.ts","../../src/cdn/cdn-client.ts"],"sourcesContent":["import { IMetafile } from '@/interfaces/i-metafile';\nimport { ApiLocaleRequest } from '@/types/api-locale-request';\nimport { Context } from '@/cdn/context/context';\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","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 { ICacheAdapter } from '@/interfaces/i-cache-adapter';\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","import { uniq } from '@/cdn/utils';\nimport { ICacheAdapter } from '@/interfaces/i-cache-adapter';\nimport { CacheKeyMetafileOptions } from '@/types/cache-key-metafile-options';\nimport { CacheGetLocalesRequest } from '@/types/cache-get-locales-request';\nimport { CacheHasLocalesRequest } from '@/types/cache-has-locales-request';\nimport { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request';\nimport { MemoryCacheAdapter } from '@/cdn/cache/memory-cache-adapter';\nimport { Context } from '@/cdn/context/context';\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 { Context } from '@/cdn/context/context';\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';\n\nexport class CdnCache extends CdnBase {\n public flush = (): void => {\n this.context.cache.flush();\n };\n}\n","import { CdnLocale } from '@/types/cdn-locale';\nimport { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale';\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 { CdnFile } from '@/types/cdn-file';\nimport { CdnFileLocale } from '@/types/cdn-file-locale';\nimport { MetafileLocale } from '@/cdn/metafile/metafile-locale';\nimport { IMetafileFile } from '@/interfaces/i-metafile-file';\nimport { MetafileFileOptions } from '@/types/metafile-file-options';\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 { uniqBy } from '@/cdn/utils';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params';\nimport { CdnLocale } from '@/types/cdn-locale';\nimport { MetafileLocale } from '@/cdn/metafile/metafile-locale';\nimport { IMetafile } from '@/interfaces/i-metafile';\nimport { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale';\nimport { IMetafileFiles } from '@/interfaces/i-metafile-files';\nimport { MetafileFile } from '@/cdn/metafile/metafile-file';\nimport { MetafileOptions } from '@/types/metafile-options';\nimport { FilesMap } from '@/types/files-map';\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(files: IMetafileFiles, baseLocale: string, params: MetafileParams): MetafileFile[] {\n return Object.keys(files).reduce((acc: MetafileFile[], cur: string) => {\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 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 { IMetafileParams } from '@/interfaces/i-metafile-params';\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 (e) {\n throw new Error('Invalid param: \"options.metafile\" cannot be parsed as url.');\n }\n\n const matches: string[] | null = url.pathname.match(/^\\/(.*?)\\/(.*?)\\.(v2.json|js|ts)$/);\n\n if (matches === null || matches.length !== 4) {\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';\nimport { IMetafile } from '@/interfaces/i-metafile';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params';\nimport { CdnClientOptions } from '@/types/cdn-client-options';\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 { ApiLocaleRequest } from '@/types/api-locale-request';\nimport { Context } from '@/cdn/context/context';\nimport { ResponseFactoryOptions } from '@/types/response-factory-options';\nimport { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request';\nimport { CdnResponse } from '@/types/cdn-response';\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 { requests, responses, hasSingleFileResponse, hasSingleLocaleResponse }: ResponseFactoryOptions = options;\n\n if (responses.length === 0) {\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 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 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 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 // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n acc[metafileFile.id][metafileLocale.locale] = cur;\n }\n }\n\n return acc;\n }, {});\n }\n}\n","import { Api } from '@/cdn/api/api';\nimport { LocalesCache } from '@/cdn/cache/locales-cache';\nimport { CdnClient } from '@/cdn/cdn-client';\nimport { ResponseFactory } from '@/cdn/response/response-factory';\nimport { ContextOptions } from '@/types/context-options';\nimport { MetafileContext } from '@/cdn/context/metafile-context';\nimport { IHttpAdapter } from '@/interfaces/i-http-adapter';\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 { MetafileFile } from '@/cdn/metafile/metafile-file';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params';\nimport { CdnClientOptions } from '@/types/cdn-client-options';\nimport { MetafileData } from '@/cdn/metafile/metafile-data';\nimport { CdnBase } from '@/cdn/methods/cdn-base';\nimport { CdnFile } from '@/types/cdn-file';\nimport { CdnLocalesOptions } from '@/types/cdn-locales-options';\nimport { IMetafile } from '@/interfaces/i-metafile';\nimport { CdnLocale } from '@/types/cdn-locale';\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 ? locales.filter((cdnLocale: CdnLocale): boolean => !cdnLocale.isBaseLocale) : 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 { Context } from '@/cdn/context/context';\nimport { LocalesMapData } from '@/types/locales-map-data';\nimport { LocalesMapOptions } from '@/types/locales-map-options';\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 { Context } from '@/cdn/context/context';\nimport { MetafileFile } from '@/cdn/metafile/metafile-file';\nimport { MetafileLocale } from '@/cdn/metafile/metafile-locale';\nimport { LocalesMap } from '@/cdn/request/locales-map';\nimport { ApiLocaleRequest } from '@/types/api-locale-request';\nimport { CdnResponse } from '@/types/cdn-response';\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((item: [Promise<string | object>, ApiLocaleRequest]) => item[1]);\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((acc: [Promise<string | object>, ApiLocaleRequest][], cur: MetafileFile) => {\n if (this.localesMap.data[cur.id]) {\n acc.push(\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","import { isPlainObject, isArray, isString, isUndefined } from '@/cdn/utils';\nimport { CdnFile } from '@/types/cdn-file';\nimport { MetafileLocale } from '@/cdn/metafile/metafile-locale';\nimport { LocalesMap } from '@/cdn/request/locales-map';\nimport { Context } from '@/cdn/context/context';\nimport { MetafileFile } from '@/cdn/metafile/metafile-file';\nimport { IRequestBuilder } from '@/interfaces/i-request-builder';\nimport { Request } from '@/cdn/request/request';\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): RequestBuilder {\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): RequestBuilder {\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((metafileLocale: MetafileLocale): boolean => !metafileLocale.isBaseLocale)\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 { IHttpAdapter } from '@/interfaces/i-http-adapter';\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 = contentType === 'application/json5' || contentType === 'application/json';\n\n if (response.status >= 400) {\n throw new Error(`Request failed with status code ${response.status}`);\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 { isString } from '@/cdn/utils';\nimport { CdnFetchOptions } from '@/types/cdn-fetch-options';\nimport { CdnResponse } from '@/types/cdn-response';\nimport { CdnCache } from '@/cdn/methods/cdn-cache';\nimport { MetafileContext } from '@/cdn/context/metafile-context';\nimport { Context } from '@/cdn/context/context';\nimport { CdnMetafile } from '@/cdn/methods/cdn-metafile';\nimport { RequestBuilder } from '@/cdn/request/request-builder';\nimport { FetchHttpAdapter } from '@/cdn/http/fetch-http-adapter';\nimport { CdnClientOptions } from '@/types/cdn-client-options';\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","constructor","context","__publicField","this","fetchLocale","options","cache","has","Promise","resolve","get","client","metafileLocale","uri","fetchMetafile","metafile","params","jsonPath","isString","value","isUndefined","isArray","Array","isPlainObject","Object","prototype","toString","call","uniq","array","Set","uniqBy","predicate","seen","filter","item","key","hasOwn","MemoryCacheAdapter","map","Map","set","flush","LocalesCache","cacheAdapter","setIfMissed","metafileFile","data","keyFromMetafile","productFlavors","sort","join","cdnId","id","file","path","library","module","buildType","locale","timestamp","CdnBase","CdnCache","super","arguments","MetafileLocale","baseLocale","language","region","script","isRtl","name","localizedName","isBaseLocale","toCdnLocale","MetafileFile","locales","baseUrl","toCdnFile","MetafileData","projectUrl","files","filesFactory","filesMap","filesMapFactory","localesFactory","find","createEmpty","keys","reduce","acc","cur","push","cdnLocale","MetafileParams","metafileUrl","parseMetafileUrl","url","URL","e","Error","matches","pathname","match","length","tagId","origin","MetafileContext","parsedData","setMetafile","ResponseFactory","createCdnResponse","requests","responses","hasSingleFileResponse","hasSingleLocaleResponse","cacheResponses","transformResponses","forEach","response","index","Context","metafileContext","cdn","api","responseFactory","CdnMetafile","excludeBaseLocale","async","refresh","LocalesMap","Request","localesMap","execute","payload","getPromises","promises","all","request","RequestBuilder","addFiles","i","foundFile","addLocales","includes","getCdnRequest","result","FetchHttpAdapter","fetch","contentType","headers","isJson","status","json","text","_CdnClient","create","CdnClient"],"mappings":";;;;AAIO,MAAMA,EAGX,WAAAC,CAAYC,GAFFC,EAAAC,KAAA,WAGRA,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,GACH,aAAMX,KAAKF,QAAQU,OAAOD,IAAIP,KAAKF,QAAQc,SAASC,OAAOC,SACrE,ECvBW,MAAAC,EAAYC,GAAqD,iBAAVA,EAEvDC,EAAeD,QAAwD,IAAVA,EAE7DE,EAAcF,GAAiCG,MAAMD,QAAQF,GAE7DI,EAAiBJ,GACc,oBAA1CK,OAAOC,UAAUC,SAASC,KAAKR,GAEpBS,EA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AexI,KAAKF,SAC5D2I,SAAS3D,GACT8D,WAAWnE,EAASmD,GAEDkB,gBAAgBZ,aAdhC,MAAAX,EAAmC,IAAIf,EAAgBtG,GACvDM,EAA2B,IAAIwI,EAAiBzB,EAAgB1G,OAAO6D,SAExE1E,KAAAF,QAAU,IAAIwH,EAAQ,CAAEC,kBAAiBC,IAAKxH,KAAMQ,WACzDR,KAAKY,SAAW,IAAI+G,EAAY3H,KAAKF,SACrCE,KAAKG,MAAQ,IAAIwD,EAAS3D,KAAKF,QACjC,CAWA,mBAAoB2J,CAAOvJ,GACzB,IAAKA,EACG,MAAA,IAAI+F,MAAM,wDAGlB,IAAKlF,EAASb,EAAQU,UACd,MAAA,IAAIqF,MAAM,qDAGZ,MAAAuB,EAAiB,IAAIgC,EAAUtJ,GAI9B,aAFDsH,EAAI5G,SAASkH,UAEZN,CACT,GAlCAzH,EAPWyJ,EAOG,UAAU,SAPnB,IAAME,EAANF"}
|
|
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 { Context } from '@/cdn/context/context';\nimport { IMetafile } from '@/interfaces/i-metafile';\nimport { ApiLocaleRequest } from '@/types/api-locale-request';\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 { ICacheAdapter } from '@/interfaces/i-cache-adapter';\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';\nimport { Context } from '@/cdn/context/context';\nimport { uniq } from '@/cdn/utils';\nimport { ICacheAdapter } from '@/interfaces/i-cache-adapter';\nimport { CacheGetLocalesRequest } from '@/types/cache-get-locales-request';\nimport { CacheHasLocalesRequest } from '@/types/cache-has-locales-request';\nimport { CacheKeyMetafileOptions } from '@/types/cache-key-metafile-options';\nimport { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request';\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 { Context } from '@/cdn/context/context';\nimport { ApiLocaleRequest } from '@/types/api-locale-request';\nimport { CacheStoreLocalesRequest } from '@/types/cache-store-locales-request';\nimport { CdnResponse } from '@/types/cdn-response';\nimport { ResponseFactoryOptions } from '@/types/response-factory-options';\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 { requests, responses, hasSingleFileResponse, hasSingleLocaleResponse }: 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';\nimport { LocalesCache } from '@/cdn/cache/locales-cache';\nimport { CdnClient } from '@/cdn/cdn-client';\nimport { MetafileContext } from '@/cdn/context/metafile-context';\nimport { ResponseFactory } from '@/cdn/response/response-factory';\nimport { IHttpAdapter } from '@/interfaces/i-http-adapter';\nimport { ContextOptions } from '@/types/context-options';\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 { MetafileLocale } from '@/cdn/metafile/metafile-locale';\nimport { IMetafileFile } from '@/interfaces/i-metafile-file';\nimport { CdnFile } from '@/types/cdn-file';\nimport { CdnFileLocale } from '@/types/cdn-file-locale';\nimport { MetafileFileOptions } from '@/types/metafile-file-options';\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 { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale';\nimport { CdnLocale } from '@/types/cdn-locale';\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';\nimport { MetafileLocale } from '@/cdn/metafile/metafile-locale';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params';\nimport { uniqBy } from '@/cdn/utils';\nimport { IMetafile } from '@/interfaces/i-metafile';\nimport { IMetafileFileLocale } from '@/interfaces/i-metafile-file-locale';\nimport { IMetafileFiles } from '@/interfaces/i-metafile-files';\nimport { CdnLocale } from '@/types/cdn-locale';\nimport { FilesMap } from '@/types/files-map';\nimport { MetafileOptions } from '@/types/metafile-options';\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(files: IMetafileFiles, baseLocale: string, params: MetafileParams): 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 { IMetafileParams } from '@/interfaces/i-metafile-params';\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';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params';\nimport { IMetafile } from '@/interfaces/i-metafile';\nimport { CdnClientOptions } from '@/types/cdn-client-options';\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 { IHttpAdapter } from '@/interfaces/i-http-adapter';\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 = 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 { Context } from '@/cdn/context/context';\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';\n\nexport class CdnCache extends CdnBase {\n public flush = (): void => {\n this.context.cache.flush();\n };\n}\n","import { MetafileData } from '@/cdn/metafile/metafile-data';\nimport { MetafileFile } from '@/cdn/metafile/metafile-file';\nimport { MetafileParams } from '@/cdn/metafile/metafile-params';\nimport { CdnBase } from '@/cdn/methods/cdn-base';\nimport { IMetafile } from '@/interfaces/i-metafile';\nimport { CdnClientOptions } from '@/types/cdn-client-options';\nimport { CdnFile } from '@/types/cdn-file';\nimport { CdnLocale } from '@/types/cdn-locale';\nimport { CdnLocalesOptions } from '@/types/cdn-locales-options';\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 ? locales.filter((cdnLocale: CdnLocale): boolean => !cdnLocale.isBaseLocale) : 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 { Context } from '@/cdn/context/context';\nimport { LocalesMapData } from '@/types/locales-map-data';\nimport { LocalesMapOptions } from '@/types/locales-map-options';\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 { Context } from '@/cdn/context/context';\nimport { MetafileFile } from '@/cdn/metafile/metafile-file';\nimport { MetafileLocale } from '@/cdn/metafile/metafile-locale';\nimport { LocalesMap } from '@/cdn/request/locales-map';\nimport { ApiLocaleRequest } from '@/types/api-locale-request';\nimport { CdnResponse } from '@/types/cdn-response';\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((item: [Promise<string | object>, ApiLocaleRequest]) => item[1]);\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((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","import { Context } from '@/cdn/context/context';\nimport { MetafileFile } from '@/cdn/metafile/metafile-file';\nimport { MetafileLocale } from '@/cdn/metafile/metafile-locale';\nimport { LocalesMap } from '@/cdn/request/locales-map';\nimport { Request } from '@/cdn/request/request';\nimport { isArray, isPlainObject, isString, isUndefined } from '@/cdn/utils';\nimport { IRequestBuilder } from '@/interfaces/i-request-builder';\nimport { CdnFile } from '@/types/cdn-file';\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((metafileLocale: MetafileLocale): boolean => !metafileLocale.isBaseLocale)\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';\nimport { MetafileContext } from '@/cdn/context/metafile-context';\nimport { FetchHttpAdapter } from '@/cdn/http/fetch-http-adapter';\nimport { CdnCache } from '@/cdn/methods/cdn-cache';\nimport { CdnMetafile } from '@/cdn/methods/cdn-metafile';\nimport { RequestBuilder } from '@/cdn/request/request-builder';\nimport { isString } from '@/cdn/utils';\nimport { CdnClientOptions } from '@/types/cdn-client-options';\nimport { CdnFetchOptions } from '@/types/cdn-fetch-options';\nimport { CdnResponse } from '@/types/cdn-response';\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","constructor","context","__publicField","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","metafileContext","cdn","api","responseFactory","MetafileFile","locales","baseUrl","toCdnFile","isBaseLocale","MetafileLocale","baseLocale","language","region","script","isRtl","name","localizedName","toCdnLocale","MetafileData","projectUrl","files","filesFactory","filesMap","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","super","arguments","CdnMetafile","excludeBaseLocale","async","refresh","LocalesMap","Request","localesMap","execute","payload","getPromises","promises","all","_a","request","RequestBuilder","addFiles","i","foundFile","addLocales","includes","getCdnRequest","_CdnClient","create","CdnClient"],"mappings":";;;mBAIO,MAAMA,EAGX,WAAAC,CAAYC,GAFFC,EAAAC,KAAA,WAGRA,KAAKF,QAAUA,CAAA,CAGjB,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G,MAAM,qDAGZ,MAAAlC,EAAiB,IAAI6E,EAAUtJ,GAI9B,aAFDyE,EAAI/D,SAAS0H,UAEZ3D,CAAA,GAjCT5E,EAPWyJ,EAOG,UAAU,SAPnB,IAAME,EAANF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -168,20 +168,11 @@ export declare type CdnResponse =
|
|
|
168
168
|
/**
|
|
169
169
|
* Map of file IDs with locales map as value.
|
|
170
170
|
*/
|
|
171
|
-
|
|
172
|
-
[fileId: string]: {
|
|
173
|
-
/**
|
|
174
|
-
* Map of locales with file content as value.
|
|
175
|
-
*/
|
|
176
|
-
[locale: string]: object | string;
|
|
177
|
-
};
|
|
178
|
-
}
|
|
171
|
+
Record<string, Record<string, object | string>>
|
|
179
172
|
/**
|
|
180
173
|
* Map of locales with file content as value.
|
|
181
174
|
*/
|
|
182
|
-
|
|
|
183
|
-
[locale: string]: object | string;
|
|
184
|
-
}
|
|
175
|
+
| Record<string, object | string>
|
|
185
176
|
/**
|
|
186
177
|
* File content.
|
|
187
178
|
*/
|
|
@@ -213,9 +204,7 @@ export declare class FetchHttpAdapter implements IHttpAdapter {
|
|
|
213
204
|
get(url: string): Promise<string | object>;
|
|
214
205
|
}
|
|
215
206
|
|
|
216
|
-
export declare type FilesMap =
|
|
217
|
-
[id: string]: MetafileFile;
|
|
218
|
-
};
|
|
207
|
+
export declare type FilesMap = Record<string, MetafileFile>;
|
|
219
208
|
|
|
220
209
|
export declare interface ICacheAdapter<K, V> {
|
|
221
210
|
has: (key: K) => boolean;
|
|
@@ -262,9 +251,7 @@ export declare interface IMetafileFileLocale {
|
|
|
262
251
|
timestamp: number;
|
|
263
252
|
}
|
|
264
253
|
|
|
265
|
-
export declare
|
|
266
|
-
[id: string]: IMetafileFile;
|
|
267
|
-
}
|
|
254
|
+
export declare type IMetafileFiles = Record<string, IMetafileFile>;
|
|
268
255
|
|
|
269
256
|
export declare interface IMetafileParams {
|
|
270
257
|
url: string;
|
|
@@ -287,13 +274,9 @@ export declare const isString: (value: unknown) => value is string;
|
|
|
287
274
|
|
|
288
275
|
export declare const isUndefined: (value: unknown) => value is undefined;
|
|
289
276
|
|
|
290
|
-
export declare type JsonResponse =
|
|
291
|
-
[key: string]: Record<string, object>;
|
|
292
|
-
};
|
|
277
|
+
export declare type JsonResponse = Record<string, Record<string, object>>;
|
|
293
278
|
|
|
294
|
-
export declare type LocaleResponse =
|
|
295
|
-
[locale: string]: JsonResponse;
|
|
296
|
-
};
|
|
279
|
+
export declare type LocaleResponse = Record<string, JsonResponse>;
|
|
297
280
|
|
|
298
281
|
export declare class LocalesCache {
|
|
299
282
|
protected context: Context;
|
|
@@ -312,9 +295,7 @@ export declare class LocalesMap {
|
|
|
312
295
|
constructor(options: LocalesMapOptions);
|
|
313
296
|
}
|
|
314
297
|
|
|
315
|
-
export declare type LocalesMapData =
|
|
316
|
-
[key: string]: MetafileLocale[];
|
|
317
|
-
};
|
|
298
|
+
export declare type LocalesMapData = Record<string, MetafileLocale[]>;
|
|
318
299
|
|
|
319
300
|
export declare type LocalesMapOptions = {
|
|
320
301
|
context: Context;
|
|
@@ -417,8 +398,8 @@ export declare class RequestBuilder implements IRequestBuilder {
|
|
|
417
398
|
protected context: Context;
|
|
418
399
|
protected request: Request_2;
|
|
419
400
|
constructor(context: Context);
|
|
420
|
-
addFiles(files?: (CdnFile | string)[] | CdnFile | string):
|
|
421
|
-
addLocales(locales?: string[] | string, excludeBaseLocale?: boolean):
|
|
401
|
+
addFiles(files?: (CdnFile | string)[] | CdnFile | string): this;
|
|
402
|
+
addLocales(locales?: string[] | string, excludeBaseLocale?: boolean): this;
|
|
422
403
|
getCdnRequest(): Request_2;
|
|
423
404
|
}
|
|
424
405
|
|