@volvo-cars/content-delivery-client
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -1,2 +0,2 @@ | ||
import e from"flat";import{getMarketSite as t,getMarketSiteByLocale as n}from"@volvo-cars/market-sites";function r(){return(r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function i(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,o(e,t)}function a(e){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function o(e,t){return(o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function l(e,t,n){return(l=c()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&o(i,n.prototype),i}).apply(null,arguments)}function u(e){var t="function"==typeof Map?new Map:void 0;return(u=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return l(e,arguments,a(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),o(n,e)})(e)}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function f(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var d=function(){function e(e){this.lastUpdated=new Map,this.values=new Map,this.revalidateMs=1e3*e}var t=e.prototype;return t.set=function(e,t){var n=h(e);this.lastUpdated.set(n,Date.now()),this.values.set(n,t)},t.has=function(e){return this.values.has(h(e))},t.get=function(e){return this.values.get(h(e))},t.isStale=function(e){var t=h(e);return!!this.lastUpdated.has(t)&&(0===this.revalidateMs||Date.now()-this.lastUpdated.get(t)>=this.revalidateMs)},e}();function h(e){return["name","locale","environment","market","dataSource"].map(function(t){return e[t]||"-"}).join("|")}var v={AE:"AE",BA:"Bosnia",GB:"UK",HK:"HongKong",MK:"Macedonia",US:"US",XA:"armoured-cars"},m=["AM","AO","BW","ID","KE","LK","MM","MZ","NA","TN","UZ","XA","XP","ZM","ZW"],p=function(e){function t(t,n,r){var i;return(i=e.call(this,t)||this).name="RequestError",i.status=n,i.url=r,i}return i(t,e),t}(u(Error)),y=function(e){function t(t){var n;return(n=e.call(this,"Timed out after "+t+" seconds")||this).name="TimeoutError",n.timeout=t,n}return i(t,e),t}(u(Error)),g=function(e){function t(t,n,r){var i,a=n.applicationId,o=n.dataSource,c=n.locale,l=n.environment,u=n.operationId,s=n.market;return(i=e.call(this,t+" in "+c+" @ "+o+" '"+(l||"live")+"'")||this).name="ContentDeliveryError",i.errors=[],i.applicationId=a,i.dataSource=o,i.operationId=u,i.locale=c,s&&(i.market=s),i.environment=l,r&&(i.errors=Array.isArray(r)?[].concat(r):Array.isArray(r.errors)?[].concat(r.errors,[r]):[r]),i}return i(t,e),t}(u(Error)),S=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).name="DictionaryNotFoundError",t}return i(t,e),t}(g),w=function(){function e(e){this.timeout=e}var t=e.prototype;return t.run=function(){var e=this;if(this.timeoutId)throw new Error("Can only run once");return new Promise(function(t,n){e.timeout&&(e.timeoutId=setTimeout(function(){n(new y(e.timeout))},1e3*e.timeout))})},t.clear=function(){this.timeoutId&&clearTimeout(this.timeoutId)},e}(),C=function(e){var i=e.applicationId,a=e.dataSource,o=e.path,c=e.market,l=void 0!==c&&c,u=e.locale,s=e.accept,f=e.environment,d=void 0===f?"live":f,h=e.apiKey,y=e.operationId,g=e.contentType,S=e.timeout;try{var C=new w(S),P=new URL(E);if(P.pathname+="/"+i+o,P.searchParams.set("Locale",u),a&&P.searchParams.set("DataSource",a),"authoringPreview"===d&&P.searchParams.set("preview","true"),P.searchParams.set("environment",d),l){var D=function(e){var n=t(e);if(n.regionCode&&n.marketName){var r=v[n.regionCode]||n.marketName.replace(/\s/g,"");return m.includes(n.regionCode)&&(r="minisites/"+r),r}}(n(u).siteSlug);D&&P.searchParams.set("market",D)}return g&&P.searchParams.set("contentType",g),Promise.resolve(Promise.race([C.run(),fetch(P.href,{headers:r({Accept:"application/vnd.volvocars.api.contentdelivery."+s+"+json","VCC-Api-Key":h},y&&{"VCC-Api-OperationId":y})}).then(function(e){return C.clear(),e},function(e){throw C.clear(),e})])).then(function(e){return Promise.resolve(e.json()).then(function(t){if(e.ok&&"data"in t&&200===t.status)return t.data;throw new p("error"in t?t.error.message:t.message,e.status,e.url)})})}catch(e){return Promise.reject(e)}},E="https://gw.consumer.api.volvocars.com/content-delivery/v1/applications";function P(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var D=function(e,t){try{return Promise.resolve(function(e,t){try{var n,i=function(e){if(0===n.length)throw new S("Empty dictionaries response",a);return n},a={applicationId:e.applicationId,dataSource:t.dataSource||e.defaultDataSource,operationId:t.operationId,locale:t.locale,environment:t.environment,timeout:t.timeout},o=P(function(){return Promise.resolve(C(r({},a,{apiKey:e.apiKey,path:"/dictionaries",accept:"dictionarylistresponse"}))).then(function(e){n=e})},function(t){var n="Failed fetching dictionaries";if(t instanceof p){if(404===t.status)throw new g("Application "+e.applicationId+" not found",a,t);n+=" '"+t.status+": "+t.message+"'"}else t.message&&(n+=" ("+t.message+")");throw new g(n,a,t)});return Promise.resolve(o&&o.then?o.then(i):i())}catch(e){return Promise.reject(e)}}(e,t)).then(function(e){return e.map(function(e){return[e.namespace+"."+e.name,e.items]})})}catch(e){return Promise.reject(e)}},b=function(e,t,n){try{var r=[];return Promise.resolve(Promise.all(e.map(function(e){try{var i,a=function(t){return[e,i]},o=P(function(){return Promise.resolve(I(e,t,n)).then(function(e){i=e})},function(e){if("DictionaryNotFoundError"!==e.name)throw e;r.push(e)});return Promise.resolve(o&&o.then?o.then(a):a())}catch(e){return Promise.reject(e)}}))).then(function(e){var i,a=e.filter(function(e){return!!e[1]});if(r.length>0)throw(i=1===r.length?r[0]:new S(r.length+" dictionaries not found",{applicationId:t.applicationId,dataSource:n.dataSource||t.defaultDataSource,operationId:n.operationId,locale:n.locale,environment:n.environment},r)).data=a,i;return a})}catch(e){return Promise.reject(e)}},I=function(e,t,n){return function(e,t,n){try{var i,a=function(e){return i.items},o={applicationId:t.applicationId,dataSource:n.dataSource||t.defaultDataSource,operationId:n.operationId,locale:n.locale,environment:n.environment,timeout:n.timeout,market:n.market},c=P(function(){return Promise.resolve(C(r({},o,{apiKey:t.apiKey,path:"/dictionaries/"+e,accept:"dictionarysuccessresponse"}))).then(function(e){i=e})},function(n){var r="Failed fetching dictionary '"+e+"'";if(n instanceof p){if(404===n.status){if("Resource not found"===n.message)throw new g("Application "+t.applicationId+" not found",o,n);if(n.message.includes(e))throw new S("Dictionary not found: "+n.message,o,n)}r+=" '"+n.status+": "+n.message+"'"}else n.message&&(r+=" ("+n.message+")");throw new g(r,o,n)});return Promise.resolve(c&&c.then?c.then(a):a())}catch(e){return Promise.reject(e)}}(e,t,n)},R=/^[A-Za-z0-9]+\.[A-Za-z0-9]+$/;function k(e){if(!R.test(e))throw Error("Canonical dictionary names are only allowed in the format 'namespace.name'. No special characters allowed.")}var j=function e(t){var n,r,i,a,o,c,l,u,s,f,d,h,v,m,p,y,g,S;return"object"==typeof t&&t?null!=t&&null!=(n=t.file)&&n.mediaType||null!=t&&null!=(r=t.file)&&r.details?null!=(i=t)&&null!=(a=i.file)&&a.url?null!=i&&null!=(o=i.file)&&null!=(c=o.mediaType)&&c.includes("image")?{src:(null==i||null==(s=i.file)?void 0:s.url)||"",alt:(null==i||null==(f=i.file)||null==(d=f.details)||null==(h=d.image)?void 0:h.alt)||"",title:(null==i?void 0:i.title)||"",description:(null==i?void 0:i.description)||"",width:(null==i||null==(v=i.file)||null==(m=v.details)||null==(p=m.image)?void 0:p.width)||0,height:(null==i||null==(y=i.file)||null==(g=y.details)||null==(S=g.image)?void 0:S.height)||0}:{mimeType:(null==i||null==(l=i.file)?void 0:l.mediaType)||"",src:(null==i||null==(u=i.file)?void 0:u.url)||"",title:(null==i?void 0:i.title)||"",description:(null==i?void 0:i.description)||""}:null:Array.isArray(t)?t.map(e):Object.entries(t).reduce(function(n,r){var i,a=r[0],o=r[1];return"fields"!==a&&"renderingParams"!==a||"object"!=typeof o||Array.isArray(o)||!o?"object"==typeof o&&"sys"!==a?("contentType"===a&&"sys"in t&&(o.sysId=t.sys.id),n[a]=e(o)):"sys"!==a&&(n["uri"===a?"href":a]=A(o)):"EditorialComponent"===(null==t||null==(i=t.contentType)?void 0:i.type)&&"fields"===a?n.content=e(o):Object.entries(o).forEach(function(t){n[t[0]]=e(t[1])}),n},{}):A(t)};function A(e){return"true"===e||"false"!==e&&(void 0===e?null:e)}var O=function(e,t,n){try{var i,a=function(e){return j(i)},o={applicationId:t.applicationId,dataSource:n.dataSource||t.defaultDataSource,operationId:n.operationId,locale:n.locale,environment:n.environment,market:n.market,timeout:n.timeout},c=function(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(function(){return Promise.resolve(C(r({},o,{apiKey:t.apiKey,path:"/entries/"+e,accept:"entrysuccessresponse"}))).then(function(e){i=e})},function(e){var t="Failed fetching entry";throw e instanceof p?t+=" '"+e.status+": "+e.message+"'":e.message&&(t+=" ("+e.message+")"),new g(t,o,e)});return Promise.resolve(c&&c.then?c.then(a):a())}catch(e){return Promise.reject(e)}},T=function(e,t,n){try{var i={applicationId:t.applicationId,dataSource:n.dataSource||t.defaultDataSource,operationId:n.operationId,locale:n.locale,environment:n.environment,market:n.market,contentType:e};return Promise.resolve(function(e,n){try{var a=Promise.resolve(C(r({},i,{apiKey:t.apiKey,path:"/entries",accept:"entrylistitemlistresponse"}))).then(j)}catch(e){return n(e)}return a&&a.then?a.then(void 0,n):a}(0,function(e){var t="Failed fetching entries list";throw e instanceof p?t+=" '"+e.status+": "+e.message+"'":e.message&&(t+=" ("+e.message+")"),new g(t,i,e)}))}catch(e){return Promise.reject(e)}};function F(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var L=function(){function e(e,t){this.pendingRevalidations=0,this.dictionariesRevalidate=60,this.entriesRevalidate=60,this.listEntriesRevalidate=60,this.config=e,this.applicationId=e.applicationId,this.defaultDataSource=e.defaultDataSource,this.localDataClient=t,"number"==typeof e.revalidate?(this.dictionariesRevalidate=e.revalidate,this.entriesRevalidate=e.revalidate,this.listEntriesRevalidate=e.revalidate):"object"==typeof e.revalidate&&e.revalidate&&("number"==typeof e.revalidate.dictionaries&&(this.dictionariesRevalidate=e.revalidate.dictionaries),"number"==typeof e.revalidate.entries&&(this.entriesRevalidate=e.revalidate.entries),"number"==typeof e.revalidate.listEntries&&(this.listEntriesRevalidate=e.revalidate.listEntries)),this.dictionariesCache=new d(this.dictionariesRevalidate),this.dictionariesListCache=new d(this.dictionariesRevalidate),this.entriesCache=new d(this.entriesRevalidate),this.listEntriesCache=new d(this.listEntriesRevalidate)}var t,n=e.prototype;return n.getDictionary=function(e,t){try{var n,r=this,i=function(i){return n?i:(r.dictionariesCache.isStale(c)&&(r.pendingRevalidations++,I(e,r.config,t).then(function(e){r.dictionariesCache.set(c,e)}).catch(function(e){r.logError("dictionaries",{locale:a},e)}).finally(function(){r.pendingRevalidations--})),K([[e,r.dictionariesCache.get(c)]]))},a=t.locale;k(e);var o=t.dataSource||r.config.defaultDataSource,c={locale:a,dataSource:o,name:e,environment:t.environment,market:t.market},l=function(){if(0===r.dictionariesRevalidate||!r.dictionariesCache.has(c))return F(function(){return Promise.resolve(I(e,r.config,t)).then(function(t){return r.dictionariesCache.set(c,t),n=1,K([[e,t]])})},function(i){function l(e){throw i}if(r.dictionariesCache.has(c))return r.logError("dictionaries",{locale:a,dataSource:o},i),n=1,K([[e,r.dictionariesCache.get(c)]]);var u=function(){if("DictionaryNotFoundError"===i.name&&r.localDataClient)return r.logError("dictionaries",{locale:a,dataSource:o},i),r.logFallback(),n=1,Promise.resolve(r.localDataClient.getDictionary(e,t))}();return u&&u.then?u.then(l):l()})}();return Promise.resolve(l&&l.then?l.then(i):i(l))}catch(e){return Promise.reject(e)}},n.getDictionaries=function(e,t){try{var n,i=this,a=function(a){var u;if(n)return a;function s(t){return u?t:K(e.map(function(e){return[e,i.dictionariesCache.get(r({name:e},l))]}))}var d=function(e,t,n){for(var i,a=[],o=[],c=f(e);!(i=c()).done;){var l=i.value;t.has(r({name:l},n))?t.isStale(r({name:l},n))&&o.push(l):a.push(l)}return{missing:a,stale:o}}(e,i.dictionariesCache,l),h=d.missing;d.stale.forEach(function(e){i.pendingRevalidations++,I(e,i.config,t).then(function(t){i.dictionariesCache.set(r({name:e},l),t)}).catch(function(e){i.logError("dictionaries",{locale:o,dataSource:c},e)}).finally(function(){i.pendingRevalidations--})});var v=function(){if(h.length>0)return F(function(){return Promise.resolve(b(h,i.config,t)).then(function(e){for(var t,n=f(e);!(t=n()).done;){var a=t.value,o=a[1];i.dictionariesCache.set(r({name:a[0]},l),o)}})},function(n){function a(e){throw n}var s=function(){if("DictionaryNotFoundError"===n.name){if(Array.isArray(n.data)){for(var a,s=f(n.data);!(a=s()).done;){var d=a.value,v=d[1];i.dictionariesCache.set(r({name:d[0]},l),v)}n.data=K(n.data)}return function(){if(i.localDataClient)return i.logError("dictionaries",{locale:o,dataSource:c},n),i.logFallback(),u=1,Promise.resolve(i.localDataClient.getDictionaries(h,t)).then(function(t){return r({},K(e.map(function(e){return[e,i.dictionariesCache.get(r({name:e},l))]})),t)})}()}}();return s&&s.then?s.then(a):a()})}();return v&&v.then?v.then(s):s(v)},o=t.locale;e.forEach(k);var c=t.dataSource||i.config.defaultDataSource,l={locale:o,dataSource:c,environment:t.environment,market:t.market},u=function(){if(0===i.dictionariesRevalidate||e.some(function(e){return!i.dictionariesCache.has(r({name:e},l))}))return F(function(){return Promise.resolve(b(e,i.config,t)).then(function(e){for(var t,a=f(e);!(t=a()).done;){var o=t.value,c=o[1];i.dictionariesCache.set(r({name:o[0]},l),c)}return n=1,K(e)})},function(a){function u(e){throw a}if("DictionaryNotFoundError"===a.name&&Array.isArray(a.data)){for(var s,d=f(a.data);!(s=d()).done;){var h=s.value,v=h[1];i.dictionariesCache.set(r({name:h[0]},l),v)}a.data=K(a.data)}if(e.every(function(e){return i.dictionariesCache.has(r({name:e},l))}))return i.logError("dictionaries",{locale:o,dataSource:c},a),n=1,K(e.map(function(e){return[e,i.dictionariesCache.get(r({name:e},l))]}));var m=function(){if("DictionaryNotFoundError"===a.name&&i.localDataClient)return i.logError("dictionaries",{locale:o,dataSource:c},a),i.logFallback(),n=1,Promise.resolve(i.localDataClient.getDictionaries(e,t))}();return m&&m.then?m.then(u):u()})}();return Promise.resolve(u&&u.then?u.then(a):a(u))}catch(e){return Promise.reject(e)}},n.getAllDictionaries=function(e){try{var t,n=this,i=function(i){return t?i:(n.dictionariesListCache.isStale(c)&&(n.pendingRevalidations++,D(n.config,e).then(function(e){for(var t,i=f(e);!(t=i()).done;){var a=t.value,o=a[1];n.dictionariesCache.set(r({},c,{name:a[0]}),o)}n.dictionariesListCache.set(c,e)}).catch(function(e){n.logError("dictionaries",{locale:a,dataSource:o},e)}).finally(function(){n.pendingRevalidations--})),K(n.dictionariesListCache.get(c)))},a=e.locale,o=e.dataSource||n.config.defaultDataSource,c={name:"all",locale:a,dataSource:o,environment:e.environment,market:e.market},l=function(){if(0===n.dictionariesRevalidate||!n.dictionariesListCache.has(c))return F(function(){return Promise.resolve(D(n.config,e)).then(function(e){if(e.length>0){for(var i,a=f(e);!(i=a()).done;){var o=i.value,l=o[1];n.dictionariesCache.set(r({},c,{name:o[0]}),l)}n.dictionariesListCache.set(c,e)}return t=1,K(e)})},function(r){function i(e){throw r}if(n.dictionariesListCache.has(c))return n.logError("dictionaries",{locale:a,dataSource:o},r),t=1,K(n.dictionariesListCache.get(c));var l=function(){if("DictionaryNotFoundError"===r.name&&n.localDataClient)return n.logError("dictionaries",{locale:a,dataSource:o},r),n.logFallback(),t=1,Promise.resolve(n.localDataClient.getAllDictionaries(e))}();return l&&l.then?l.then(i):i()})}();return Promise.resolve(l&&l.then?l.then(i):i(l))}catch(e){return Promise.reject(e)}},n.getEntry=function(e,t){try{var n,r=this,i=function(i){return n?i:(r.entriesCache.isStale(c)&&(r.pendingRevalidations++,O(e,r.config,t).then(function(e){r.entriesCache.set(c,e)}).catch(function(e){r.logError("entries",{locale:a,dataSource:o},e)}).finally(function(){r.pendingRevalidations--})),r.entriesCache.get(c))},a=t.locale,o=t.dataSource||r.config.defaultDataSource,c={locale:a,dataSource:o,name:e,environment:t.environment,market:t.market},l=function(){if(!r.entriesCache||!r.entriesCache.has(c))return F(function(){return Promise.resolve(O(e,r.config,t)).then(function(e){return r.entriesCache&&r.entriesCache.set(c,e),n=1,e})},function(e){throw r.logError("entries",{locale:a,dataSource:o},e),e})}();return Promise.resolve(l&&l.then?l.then(i):i(l))}catch(e){return Promise.reject(e)}},n.listEntries=function(e,t){try{var n,r=this,i=function(i){return n?i:(r.listEntriesCache.isStale(c)&&(r.pendingRevalidations++,T(e,r.config,t).then(function(e){r.listEntriesCache.set(c,e)}).catch(function(e){r.logError("list-entries",{locale:a,dataSource:o},e)}).finally(function(){r.pendingRevalidations--})),r.listEntriesCache.get(c))},a=t.locale,o=t.dataSource||r.config.defaultDataSource,c={locale:a,dataSource:o,name:e,environment:t.environment,market:t.market},l=function(){if(!r.listEntriesCache||!r.listEntriesCache.has(c))return F(function(){return Promise.resolve(T(e,r.config,t)).then(function(e){return r.listEntriesCache&&r.listEntriesCache.set(c,e),n=1,e})},function(e){throw r.logError("list-entries",{locale:a,dataSource:o},e),e})}();return Promise.resolve(l&&l.then?l.then(i):i(l))}catch(e){return Promise.reject(e)}},n.logError=function(e,t,n){"test"!==process.env.NODE_ENV&&(console.log("Failed fetching "+e+" for locale '"+t.locale+"' in dataSource '"+t.dataSource+"'."),console.log(n))},n.logFallback=function(){"test"!==process.env.NODE_ENV&&console.log("Falling back to local data...")},(t=[{key:"isValidating",get:function(){return this.pendingRevalidations>0}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(e.prototype,t),e}();function K(t){return e(Object.fromEntries(t))}var N=["forceLocalData","fallbackToLocalData"];function M(e){var t=e.forceLocalData,n=e.fallbackToLocalData,r=function(e,t){if(null==e)return{};var n,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)t.indexOf(n=a[r])>=0||(i[n]=e[n]);return i}(e,N);if(r.dataSource&&!r.defaultDataSource&&(r.defaultDataSource=r.dataSource),"undefined"!=typeof window){if(t)throw new Error("The 'forceLocalData' option is only available in SSR.");if(n)throw new Error("The 'fallbackToLocalData' option is only available in SSR.")}else{var i=require("./LocalDataClient").LocalDataClient;if(t)return new i(r);if(n)return new L(r,new i(r))}return new L(r)}export{g as ContentDeliveryError,S as DictionaryNotFoundError,M as createClient}; | ||
import e from"flat";import{getMarketSite as t,getMarketSiteByLocale as n}from"@volvo-cars/market-sites";function r(){return(r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function i(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,a(e,t)}function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function a(e,t){return(a=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function s(e,t,n){return(s=c()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&a(i,n.prototype),i}).apply(null,arguments)}function l(e){var t="function"==typeof Map?new Map:void 0;return(l=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return s(e,arguments,o(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),a(n,e)})(e)}function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function f(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return u(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?u(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var d=/^[A-Za-z0-9]+\.[A-Za-z0-9]+$/;function h(e){if(!d.test(e))throw Error("Canonical dictionary names are only allowed in the format 'namespace.name'. No special characters allowed.")}var v=function(){function e(e){if(this.isValidating=!1,!e.path)throw new TypeError("'path' to local fallback content missing in config. Required when using local data options.");this.config=e,this.applicationId=e.applicationId,this.defaultDataSource=e.defaultDataSource}var t=e.prototype;return t.getDictionary=function(e,t){try{var n=this;return h(e),Promise.resolve(import("./getLocalDictionaries-b29fe9c6.js")).then(function(t){var r=n.flattenDictionaries;return Promise.resolve((0,t.getLocalDictionary)(e,n.config.path)).then(function(t){var i;return r.call(n,((i={})[e]=t,i))})})}catch(e){return Promise.reject(e)}},t.getDictionaries=function(e,t){try{var n=this;return Promise.resolve(import("./getLocalDictionaries-b29fe9c6.js")).then(function(t){var r=t.getLocalDictionaries;e.forEach(h);var i=n.flattenDictionaries;return Promise.resolve(r(e,n.config.path)).then(function(e){return i.call(n,Object.fromEntries(e))})})}catch(e){return Promise.reject(e)}},t.getAllDictionaries=function(e){try{var t=this;return Promise.resolve(import("./getLocalDictionaries-b29fe9c6.js")).then(function(e){var n=t.flattenDictionaries;return Promise.resolve((0,e.getLocalDictionaries)([],t.config.path)).then(function(e){return n.call(t,Object.fromEntries(e))})})}catch(e){return Promise.reject(e)}},t.getEntry=function(e,t){return Promise.resolve({})},t.listEntries=function(e,t){return Promise.resolve([])},t.flattenDictionaries=function(e){try{return Promise.resolve(import("flat")).then(function(t){return(0,t.default)(e)})}catch(e){return Promise.reject(e)}},e}(),m=function(){function e(e){this.lastUpdated=new Map,this.values=new Map,this.revalidateMs=1e3*e}var t=e.prototype;return t.set=function(e,t){var n=p(e);this.lastUpdated.set(n,Date.now()),this.values.set(n,t)},t.has=function(e){return this.values.has(p(e))},t.get=function(e){return this.values.get(p(e))},t.isStale=function(e){var t=p(e);return!!this.lastUpdated.has(t)&&(0===this.revalidateMs||Date.now()-this.lastUpdated.get(t)>=this.revalidateMs)},e}();function p(e){return["name","locale","environment","market","dataSource"].map(function(t){return e[t]||"-"}).join("|")}var g,y={AE:"AE",BA:"Bosnia",GB:"UK",HK:"HongKong",MK:"Macedonia",US:"US",XA:"armoured-cars"},S=["AM","AO","BW","ID","KE","LK","MM","MZ","NA","TN","UZ","XA","XP","ZM","ZW"],P=function(e){function t(t,n,r){var i;return(i=e.call(this,t)||this).name="RequestError",i.status=n,i.url=r,i}return i(t,e),t}(l(Error)),w=function(e){function t(t){var n;return(n=e.call(this,"Timed out after "+t+" seconds")||this).name="TimeoutError",n.timeout=t,n}return i(t,e),t}(l(Error)),E=function(e){function t(t,n,r){var i,o=n.applicationId,a=n.dataSource,c=n.locale,s=n.environment,l=n.operationId,u=n.market;return(i=e.call(this,t+" in "+c+" @ "+a+" '"+(s||"live")+"'")||this).name="ContentDeliveryError",i.errors=[],i.applicationId=o,i.dataSource=a,i.operationId=l,i.locale=c,u&&(i.market=u),i.environment=s,r&&(i.errors=Array.isArray(r)?[].concat(r):Array.isArray(r.errors)?[].concat(r.errors,[r]):[r]),i}return i(t,e),t}(l(Error)),C=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).name="DictionaryNotFoundError",t}return i(t,e),t}(E),D=function(){function e(e){this.timeout=e}var t=e.prototype;return t.run=function(){var e=this;if(this.timeoutId)throw new Error("Can only run once");return new Promise(function(t,n){e.timeout&&(e.timeoutId=setTimeout(function(){n(new w(e.timeout))},1e3*e.timeout))})},t.clear=function(){this.timeoutId&&clearTimeout(this.timeoutId)},e}(),b=function(e){var i=e.applicationId,o=e.dataSource,a=e.path,c=e.market,s=void 0!==c&&c,l=e.locale,u=e.accept,f=e.environment,d=void 0===f?"live":f,h=e.operationId,v=e.contentType,m=e.timeout,p=e.config;try{var w=function(){return Promise.resolve(Promise.race([E.run(),fetch(C.href,r({headers:r({Accept:"application/vnd.volvocars.api.contentdelivery."+u+"+json","VCC-Api-Key":p.apiKey},h&&{"VCC-Api-OperationId":h})},I)).then(function(e){return E.clear(),e},function(e){throw E.clear(),e})])).then(function(e){return Promise.resolve(e.json()).then(function(t){if(e.ok&&"data"in t&&200===t.status)return t.data;throw new P("error"in t?t.error.message:t.message,e.status,e.url)})})},E=new D(m),C=new URL(j);if(C.pathname+="/"+i+a,C.searchParams.set("Locale",l),o&&C.searchParams.set("DataSource",o),"authoringPreview"===d&&C.searchParams.set("preview","true"),C.searchParams.set("environment",d),s){var b=function(e){var n=t(e);if(n.regionCode&&n.marketName){var r=y[n.regionCode]||n.marketName.replace(/\s/g,"");return S.includes(n.regionCode)&&(r="minisites/"+r),r}}(n(l).siteSlug);b&&C.searchParams.set("market",b)}v&&C.searchParams.set("contentType",v);var I=p.fetchOptions,k=function(){var e;if("undefined"==typeof window&&void 0===(null==(e=I)?void 0:e.agent))return Promise.resolve(function(){try{var e=function(){if(!g)return Promise.resolve(import("https")).then(function(e){g=new(0,e.Agent)({keepAlive:!0,maxSockets:40,maxFreeSockets:10})})}();return Promise.resolve(e&&e.then?e.then(function(){return g}):g)}catch(e){return Promise.reject(e)}}()).then(function(e){I=r({},I,{agent:e})})}();return Promise.resolve(k&&k.then?k.then(w):w())}catch(e){return Promise.reject(e)}},j="https://gw.consumer.api.volvocars.com/content-delivery/v1/applications";function I(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var k=function(e,t){try{return Promise.resolve(function(e,t){try{var n,i=function(e){if(0===n.length)throw new C("Empty dictionaries response",o);return n},o={applicationId:e.applicationId,dataSource:t.dataSource||e.defaultDataSource,operationId:t.operationId,locale:t.locale,environment:t.environment,timeout:t.timeout},a=I(function(){return Promise.resolve(b(r({},o,{config:e,path:"/dictionaries",accept:"dictionarylistresponse"}))).then(function(e){n=e})},function(t){var n="Failed fetching dictionaries";if(t instanceof P){if(404===t.status)throw new E("Application "+e.applicationId+" not found",o,t);n+=" '"+t.status+": "+t.message+"'"}else t.message&&(n+=" ("+t.message+")");throw new E(n,o,t)});return Promise.resolve(a&&a.then?a.then(i):i())}catch(e){return Promise.reject(e)}}(e,t)).then(function(e){return e.map(function(e){return[e.namespace+"."+e.name,e.items]})})}catch(e){return Promise.reject(e)}},R=function(e,t,n){try{var r=[];return Promise.resolve(Promise.all(e.map(function(e){try{var i,o=function(t){return[e,i]},a=I(function(){return Promise.resolve(A(e,t,n)).then(function(e){i=e})},function(e){if("DictionaryNotFoundError"!==e.name)throw e;r.push(e)});return Promise.resolve(a&&a.then?a.then(o):o())}catch(e){return Promise.reject(e)}}))).then(function(e){var i,o=e.filter(function(e){return!!e[1]});if(r.length>0)throw(i=1===r.length?r[0]:new C(r.length+" dictionaries not found",{applicationId:t.applicationId,dataSource:n.dataSource||t.defaultDataSource,operationId:n.operationId,locale:n.locale,environment:n.environment},r)).data=o,i;return o})}catch(e){return Promise.reject(e)}},A=function(e,t,n){return function(e,t,n){try{var i,o=function(e){return i.items},a={applicationId:t.applicationId,dataSource:n.dataSource||t.defaultDataSource,operationId:n.operationId,locale:n.locale,environment:n.environment,timeout:n.timeout,market:n.market},c=I(function(){return Promise.resolve(b(r({},a,{config:t,path:"/dictionaries/"+e,accept:"dictionarysuccessresponse"}))).then(function(e){i=e})},function(n){var r="Failed fetching dictionary '"+e+"'";if(n instanceof P){if(404===n.status){if("Resource not found"===n.message)throw new E("Application "+t.applicationId+" not found",a,n);if(n.message.includes(e))throw new C("Dictionary not found: "+n.message,a,n)}r+=" '"+n.status+": "+n.message+"'"}else n.message&&(r+=" ("+n.message+")");throw new E(r,a,n)});return Promise.resolve(c&&c.then?c.then(o):o())}catch(e){return Promise.reject(e)}}(e,t,n)},O=function e(t){var n,r,i,o,a,c,s,l,u,f,d,h,v,m,p,g,y,S;return"object"==typeof t&&t?null!=t&&null!=(n=t.file)&&n.mediaType||null!=t&&null!=(r=t.file)&&r.details?null!=(i=t)&&null!=(o=i.file)&&o.url?null!=i&&null!=(a=i.file)&&null!=(c=a.mediaType)&&c.includes("image")?{src:(null==i||null==(u=i.file)?void 0:u.url)||"",alt:(null==i||null==(f=i.file)||null==(d=f.details)||null==(h=d.image)?void 0:h.alt)||"",title:(null==i?void 0:i.title)||"",description:(null==i?void 0:i.description)||"",width:(null==i||null==(v=i.file)||null==(m=v.details)||null==(p=m.image)?void 0:p.width)||0,height:(null==i||null==(g=i.file)||null==(y=g.details)||null==(S=y.image)?void 0:S.height)||0}:{mimeType:(null==i||null==(s=i.file)?void 0:s.mediaType)||"",src:(null==i||null==(l=i.file)?void 0:l.url)||"",title:(null==i?void 0:i.title)||"",description:(null==i?void 0:i.description)||""}:null:Array.isArray(t)?t.map(e):Object.entries(t).reduce(function(n,r){var i,o=r[0],a=r[1];return"fields"!==o&&"renderingParams"!==o||"object"!=typeof a||Array.isArray(a)||!a?"object"==typeof a&&"sys"!==o?("contentType"===o&&"sys"in t&&(a.sysId=t.sys.id),n[o]=e(a)):"sys"!==o&&(n["uri"===o?"href":o]=L(a)):"EditorialComponent"===(null==t||null==(i=t.contentType)?void 0:i.type)&&"fields"===o?n.content=e(a):Object.entries(a).forEach(function(t){n[t[0]]=e(t[1])}),n},{}):L(t)};function L(e){return"true"===e||"false"!==e&&(void 0===e?null:e)}var T=function(e,t,n){try{var i,o=function(e){return O(i)},a={applicationId:t.applicationId,dataSource:n.dataSource||t.defaultDataSource,operationId:n.operationId,locale:n.locale,environment:n.environment,market:n.market,timeout:n.timeout},c=function(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(function(){return Promise.resolve(b(r({},a,{config:t,path:"/entries/"+e,accept:"entrysuccessresponse"}))).then(function(e){i=e})},function(e){var t="Failed fetching entry";throw e instanceof P?t+=" '"+e.status+": "+e.message+"'":e.message&&(t+=" ("+e.message+")"),new E(t,a,e)});return Promise.resolve(c&&c.then?c.then(o):o())}catch(e){return Promise.reject(e)}},F=function(e,t,n){try{var i={applicationId:t.applicationId,dataSource:n.dataSource||t.defaultDataSource,operationId:n.operationId,locale:n.locale,environment:n.environment,market:n.market,contentType:e};return Promise.resolve(function(e,n){try{var o=Promise.resolve(b(r({},i,{config:t,path:"/entries",accept:"entrylistitemlistresponse"}))).then(O)}catch(e){return n(e)}return o&&o.then?o.then(void 0,n):o}(0,function(e){var t="Failed fetching entries list";throw e instanceof P?t+=" '"+e.status+": "+e.message+"'":e.message&&(t+=" ("+e.message+")"),new E(t,i,e)}))}catch(e){return Promise.reject(e)}};function N(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var M=function(){function e(e,t){this.pendingRevalidations=0,this.dictionariesRevalidate=60,this.entriesRevalidate=60,this.listEntriesRevalidate=60,this.config=e,this.applicationId=e.applicationId,this.defaultDataSource=e.defaultDataSource,this.localDataClient=t,"number"==typeof e.revalidate?(this.dictionariesRevalidate=e.revalidate,this.entriesRevalidate=e.revalidate,this.listEntriesRevalidate=e.revalidate):"object"==typeof e.revalidate&&e.revalidate&&("number"==typeof e.revalidate.dictionaries&&(this.dictionariesRevalidate=e.revalidate.dictionaries),"number"==typeof e.revalidate.entries&&(this.entriesRevalidate=e.revalidate.entries),"number"==typeof e.revalidate.listEntries&&(this.listEntriesRevalidate=e.revalidate.listEntries)),this.dictionariesCache=new m(this.dictionariesRevalidate),this.dictionariesListCache=new m(this.dictionariesRevalidate),this.entriesCache=new m(this.entriesRevalidate),this.listEntriesCache=new m(this.listEntriesRevalidate)}var t,n=e.prototype;return n.getDictionary=function(e,t){try{var n,r=this,i=function(i){return n?i:(r.dictionariesCache.isStale(c)&&(r.pendingRevalidations++,A(e,r.config,t).then(function(e){r.dictionariesCache.set(c,e)}).catch(function(e){r.logError("dictionaries",{locale:o},e)}).finally(function(){r.pendingRevalidations--})),U([[e,r.dictionariesCache.get(c)]]))},o=t.locale;h(e);var a=t.dataSource||r.config.defaultDataSource,c={locale:o,dataSource:a,name:e,environment:t.environment,market:t.market},s=function(){if(0===r.dictionariesRevalidate||!r.dictionariesCache.has(c))return N(function(){return Promise.resolve(A(e,r.config,t)).then(function(t){return r.dictionariesCache.set(c,t),n=1,U([[e,t]])})},function(i){function s(e){throw i}if(r.dictionariesCache.has(c))return r.logError("dictionaries",{locale:o,dataSource:a},i),n=1,U([[e,r.dictionariesCache.get(c)]]);var l=function(){if("DictionaryNotFoundError"===i.name&&r.localDataClient)return r.logError("dictionaries",{locale:o,dataSource:a},i),r.logFallback(),n=1,Promise.resolve(r.localDataClient.getDictionary(e,t))}();return l&&l.then?l.then(s):s()})}();return Promise.resolve(s&&s.then?s.then(i):i(s))}catch(e){return Promise.reject(e)}},n.getDictionaries=function(e,t){try{var n,i=this,o=function(o){var l;if(n)return o;function u(t){return l?t:U(e.map(function(e){return[e,i.dictionariesCache.get(r({name:e},s))]}))}var d=function(e,t,n){for(var i,o=[],a=[],c=f(e);!(i=c()).done;){var s=i.value;t.has(r({name:s},n))?t.isStale(r({name:s},n))&&a.push(s):o.push(s)}return{missing:o,stale:a}}(e,i.dictionariesCache,s),h=d.missing;d.stale.forEach(function(e){i.pendingRevalidations++,A(e,i.config,t).then(function(t){i.dictionariesCache.set(r({name:e},s),t)}).catch(function(e){i.logError("dictionaries",{locale:a,dataSource:c},e)}).finally(function(){i.pendingRevalidations--})});var v=function(){if(h.length>0)return N(function(){return Promise.resolve(R(h,i.config,t)).then(function(e){for(var t,n=f(e);!(t=n()).done;){var o=t.value,a=o[1];i.dictionariesCache.set(r({name:o[0]},s),a)}})},function(n){function o(e){throw n}var u=function(){if("DictionaryNotFoundError"===n.name){if(Array.isArray(n.data)){for(var o,u=f(n.data);!(o=u()).done;){var d=o.value,v=d[1];i.dictionariesCache.set(r({name:d[0]},s),v)}n.data=U(n.data)}return function(){if(i.localDataClient)return i.logError("dictionaries",{locale:a,dataSource:c},n),i.logFallback(),l=1,Promise.resolve(i.localDataClient.getDictionaries(h,t)).then(function(t){return r({},U(e.map(function(e){return[e,i.dictionariesCache.get(r({name:e},s))]})),t)})}()}}();return u&&u.then?u.then(o):o()})}();return v&&v.then?v.then(u):u(v)},a=t.locale;e.forEach(h);var c=t.dataSource||i.config.defaultDataSource,s={locale:a,dataSource:c,environment:t.environment,market:t.market},l=function(){if(0===i.dictionariesRevalidate||e.some(function(e){return!i.dictionariesCache.has(r({name:e},s))}))return N(function(){return Promise.resolve(R(e,i.config,t)).then(function(e){for(var t,o=f(e);!(t=o()).done;){var a=t.value,c=a[1];i.dictionariesCache.set(r({name:a[0]},s),c)}return n=1,U(e)})},function(o){function l(e){throw o}if("DictionaryNotFoundError"===o.name&&Array.isArray(o.data)){for(var u,d=f(o.data);!(u=d()).done;){var h=u.value,v=h[1];i.dictionariesCache.set(r({name:h[0]},s),v)}o.data=U(o.data)}if(e.every(function(e){return i.dictionariesCache.has(r({name:e},s))}))return i.logError("dictionaries",{locale:a,dataSource:c},o),n=1,U(e.map(function(e){return[e,i.dictionariesCache.get(r({name:e},s))]}));var m=function(){if("DictionaryNotFoundError"===o.name&&i.localDataClient)return i.logError("dictionaries",{locale:a,dataSource:c},o),i.logFallback(),n=1,Promise.resolve(i.localDataClient.getDictionaries(e,t))}();return m&&m.then?m.then(l):l()})}();return Promise.resolve(l&&l.then?l.then(o):o(l))}catch(e){return Promise.reject(e)}},n.getAllDictionaries=function(e){try{var t,n=this,i=function(i){return t?i:(n.dictionariesListCache.isStale(c)&&(n.pendingRevalidations++,k(n.config,e).then(function(e){for(var t,i=f(e);!(t=i()).done;){var o=t.value,a=o[1];n.dictionariesCache.set(r({},c,{name:o[0]}),a)}n.dictionariesListCache.set(c,e)}).catch(function(e){n.logError("dictionaries",{locale:o,dataSource:a},e)}).finally(function(){n.pendingRevalidations--})),U(n.dictionariesListCache.get(c)))},o=e.locale,a=e.dataSource||n.config.defaultDataSource,c={name:"all",locale:o,dataSource:a,environment:e.environment,market:e.market},s=function(){if(0===n.dictionariesRevalidate||!n.dictionariesListCache.has(c))return N(function(){return Promise.resolve(k(n.config,e)).then(function(e){if(e.length>0){for(var i,o=f(e);!(i=o()).done;){var a=i.value,s=a[1];n.dictionariesCache.set(r({},c,{name:a[0]}),s)}n.dictionariesListCache.set(c,e)}return t=1,U(e)})},function(r){function i(e){throw r}if(n.dictionariesListCache.has(c))return n.logError("dictionaries",{locale:o,dataSource:a},r),t=1,U(n.dictionariesListCache.get(c));var s=function(){if("DictionaryNotFoundError"===r.name&&n.localDataClient)return n.logError("dictionaries",{locale:o,dataSource:a},r),n.logFallback(),t=1,Promise.resolve(n.localDataClient.getAllDictionaries(e))}();return s&&s.then?s.then(i):i()})}();return Promise.resolve(s&&s.then?s.then(i):i(s))}catch(e){return Promise.reject(e)}},n.getEntry=function(e,t){try{var n,r=this,i=function(i){return n?i:(r.entriesCache.isStale(c)&&(r.pendingRevalidations++,T(e,r.config,t).then(function(e){r.entriesCache.set(c,e)}).catch(function(e){r.logError("entries",{locale:o,dataSource:a},e)}).finally(function(){r.pendingRevalidations--})),r.entriesCache.get(c))},o=t.locale,a=t.dataSource||r.config.defaultDataSource,c={locale:o,dataSource:a,name:e,environment:t.environment,market:t.market},s=function(){if(!r.entriesCache||!r.entriesCache.has(c))return N(function(){return Promise.resolve(T(e,r.config,t)).then(function(e){return r.entriesCache&&r.entriesCache.set(c,e),n=1,e})},function(e){throw r.logError("entries",{locale:o,dataSource:a},e),e})}();return Promise.resolve(s&&s.then?s.then(i):i(s))}catch(e){return Promise.reject(e)}},n.listEntries=function(e,t){try{var n,r=this,i=function(i){return n?i:(r.listEntriesCache.isStale(c)&&(r.pendingRevalidations++,F(e,r.config,t).then(function(e){r.listEntriesCache.set(c,e)}).catch(function(e){r.logError("list-entries",{locale:o,dataSource:a},e)}).finally(function(){r.pendingRevalidations--})),r.listEntriesCache.get(c))},o=t.locale,a=t.dataSource||r.config.defaultDataSource,c={locale:o,dataSource:a,name:e,environment:t.environment,market:t.market},s=function(){if(!r.listEntriesCache||!r.listEntriesCache.has(c))return N(function(){return Promise.resolve(F(e,r.config,t)).then(function(e){return r.listEntriesCache&&r.listEntriesCache.set(c,e),n=1,e})},function(e){throw r.logError("list-entries",{locale:o,dataSource:a},e),e})}();return Promise.resolve(s&&s.then?s.then(i):i(s))}catch(e){return Promise.reject(e)}},n.logError=function(e,t,n){"test"!==process.env.NODE_ENV&&(console.log("Failed fetching "+e+" for locale '"+t.locale+"' in dataSource '"+t.dataSource+"'."),console.log(n))},n.logFallback=function(){"test"!==process.env.NODE_ENV&&console.log("Falling back to local data...")},(t=[{key:"isValidating",get:function(){return this.pendingRevalidations>0}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(e.prototype,t),e}();function U(t){return e(Object.fromEntries(t))}var _=["forceLocalData","fallbackToLocalData"];function x(e){var t=e.forceLocalData,n=e.fallbackToLocalData,r=function(e,t){if(null==e)return{};var n,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)t.indexOf(n=o[r])>=0||(i[n]=e[n]);return i}(e,_);if(r.dataSource&&!r.defaultDataSource&&(r.defaultDataSource=r.dataSource),"undefined"!=typeof window){if(t)throw new Error("The 'forceLocalData' option is only available in SSR.");if(n)throw new Error("The 'fallbackToLocalData' option is only available in SSR.")}else{if(t)return new v(r);if(n)return new M(r,new v(r))}return new M(r)}export{E as ContentDeliveryError,C as DictionaryNotFoundError,x as createClient}; | ||
//# sourceMappingURL=content-delivery-client.esm.js.map |
@@ -1,2 +0,2 @@ | ||
var e=require("flat"),t=require("@volvo-cars/market-sites");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(e);function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function a(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,c(e,t)}function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function u(e,t,n){return(u=l()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&c(i,n.prototype),i}).apply(null,arguments)}function s(e){var t="function"==typeof Map?new Map:void 0;return(s=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return u(e,arguments,o(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),c(n,e)})(e)}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function d(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?f(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var h=function(){function e(e){this.lastUpdated=new Map,this.values=new Map,this.revalidateMs=1e3*e}var t=e.prototype;return t.set=function(e,t){var n=v(e);this.lastUpdated.set(n,Date.now()),this.values.set(n,t)},t.has=function(e){return this.values.has(v(e))},t.get=function(e){return this.values.get(v(e))},t.isStale=function(e){var t=v(e);return!!this.lastUpdated.has(t)&&(0===this.revalidateMs||Date.now()-this.lastUpdated.get(t)>=this.revalidateMs)},e}();function v(e){return["name","locale","environment","market","dataSource"].map(function(t){return e[t]||"-"}).join("|")}var m={AE:"AE",BA:"Bosnia",GB:"UK",HK:"HongKong",MK:"Macedonia",US:"US",XA:"armoured-cars"},p=["AM","AO","BW","ID","KE","LK","MM","MZ","NA","TN","UZ","XA","XP","ZM","ZW"],y=function(e){function t(t,n,r){var i;return(i=e.call(this,t)||this).name="RequestError",i.status=n,i.url=r,i}return a(t,e),t}(s(Error)),g=function(e){function t(t){var n;return(n=e.call(this,"Timed out after "+t+" seconds")||this).name="TimeoutError",n.timeout=t,n}return a(t,e),t}(s(Error)),S=function(e){function t(t,n,r){var i,a=n.applicationId,o=n.dataSource,c=n.locale,l=n.environment,u=n.operationId,s=n.market;return(i=e.call(this,t+" in "+c+" @ "+o+" '"+(l||"live")+"'")||this).name="ContentDeliveryError",i.errors=[],i.applicationId=a,i.dataSource=o,i.operationId=u,i.locale=c,s&&(i.market=s),i.environment=l,r&&(i.errors=Array.isArray(r)?[].concat(r):Array.isArray(r.errors)?[].concat(r.errors,[r]):[r]),i}return a(t,e),t}(s(Error)),w=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).name="DictionaryNotFoundError",t}return a(t,e),t}(S),C=function(){function e(e){this.timeout=e}var t=e.prototype;return t.run=function(){var e=this;if(this.timeoutId)throw new Error("Can only run once");return new Promise(function(t,n){e.timeout&&(e.timeoutId=setTimeout(function(){n(new g(e.timeout))},1e3*e.timeout))})},t.clear=function(){this.timeoutId&&clearTimeout(this.timeoutId)},e}(),E=function(e){var n=e.applicationId,r=e.dataSource,a=e.path,o=e.market,c=void 0!==o&&o,l=e.locale,u=e.accept,s=e.environment,f=void 0===s?"live":s,d=e.apiKey,h=e.operationId,v=e.contentType,g=e.timeout;try{var S=new C(g),w=new URL(P);if(w.pathname+="/"+n+a,w.searchParams.set("Locale",l),r&&w.searchParams.set("DataSource",r),"authoringPreview"===f&&w.searchParams.set("preview","true"),w.searchParams.set("environment",f),c){var E=function(e){var n=t.getMarketSite(e);if(n.regionCode&&n.marketName){var r=m[n.regionCode]||n.marketName.replace(/\s/g,"");return p.includes(n.regionCode)&&(r="minisites/"+r),r}}(t.getMarketSiteByLocale(l).siteSlug);E&&w.searchParams.set("market",E)}return v&&w.searchParams.set("contentType",v),Promise.resolve(Promise.race([S.run(),fetch(w.href,{headers:i({Accept:"application/vnd.volvocars.api.contentdelivery."+u+"+json","VCC-Api-Key":d},h&&{"VCC-Api-OperationId":h})}).then(function(e){return S.clear(),e},function(e){throw S.clear(),e})])).then(function(e){return Promise.resolve(e.json()).then(function(t){if(e.ok&&"data"in t&&200===t.status)return t.data;throw new y("error"in t?t.error.message:t.message,e.status,e.url)})})}catch(e){return Promise.reject(e)}},P="https://gw.consumer.api.volvocars.com/content-delivery/v1/applications";function D(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var b=function(e,t){try{return Promise.resolve(function(e,t){try{var n,r=function(e){if(0===n.length)throw new w("Empty dictionaries response",a);return n},a={applicationId:e.applicationId,dataSource:t.dataSource||e.defaultDataSource,operationId:t.operationId,locale:t.locale,environment:t.environment,timeout:t.timeout},o=D(function(){return Promise.resolve(E(i({},a,{apiKey:e.apiKey,path:"/dictionaries",accept:"dictionarylistresponse"}))).then(function(e){n=e})},function(t){var n="Failed fetching dictionaries";if(t instanceof y){if(404===t.status)throw new S("Application "+e.applicationId+" not found",a,t);n+=" '"+t.status+": "+t.message+"'"}else t.message&&(n+=" ("+t.message+")");throw new S(n,a,t)});return Promise.resolve(o&&o.then?o.then(r):r())}catch(e){return Promise.reject(e)}}(e,t)).then(function(e){return e.map(function(e){return[e.namespace+"."+e.name,e.items]})})}catch(e){return Promise.reject(e)}},I=function(e,t,n){try{var r=[];return Promise.resolve(Promise.all(e.map(function(e){try{var i,a=function(t){return[e,i]},o=D(function(){return Promise.resolve(k(e,t,n)).then(function(e){i=e})},function(e){if("DictionaryNotFoundError"!==e.name)throw e;r.push(e)});return Promise.resolve(o&&o.then?o.then(a):a())}catch(e){return Promise.reject(e)}}))).then(function(e){var i,a=e.filter(function(e){return!!e[1]});if(r.length>0)throw(i=1===r.length?r[0]:new w(r.length+" dictionaries not found",{applicationId:t.applicationId,dataSource:n.dataSource||t.defaultDataSource,operationId:n.operationId,locale:n.locale,environment:n.environment},r)).data=a,i;return a})}catch(e){return Promise.reject(e)}},k=function(e,t,n){return function(e,t,n){try{var r,a=function(e){return r.items},o={applicationId:t.applicationId,dataSource:n.dataSource||t.defaultDataSource,operationId:n.operationId,locale:n.locale,environment:n.environment,timeout:n.timeout,market:n.market},c=D(function(){return Promise.resolve(E(i({},o,{apiKey:t.apiKey,path:"/dictionaries/"+e,accept:"dictionarysuccessresponse"}))).then(function(e){r=e})},function(n){var r="Failed fetching dictionary '"+e+"'";if(n instanceof y){if(404===n.status){if("Resource not found"===n.message)throw new S("Application "+t.applicationId+" not found",o,n);if(n.message.includes(e))throw new w("Dictionary not found: "+n.message,o,n)}r+=" '"+n.status+": "+n.message+"'"}else n.message&&(r+=" ("+n.message+")");throw new S(r,o,n)});return Promise.resolve(c&&c.then?c.then(a):a())}catch(e){return Promise.reject(e)}}(e,t,n)},R=/^[A-Za-z0-9]+\.[A-Za-z0-9]+$/;function j(e){if(!R.test(e))throw Error("Canonical dictionary names are only allowed in the format 'namespace.name'. No special characters allowed.")}var A=function e(t){var n,r,i,a,o,c,l,u,s,f,d,h,v,m,p,y,g,S;return"object"==typeof t&&t?null!=t&&null!=(n=t.file)&&n.mediaType||null!=t&&null!=(r=t.file)&&r.details?null!=(i=t)&&null!=(a=i.file)&&a.url?null!=i&&null!=(o=i.file)&&null!=(c=o.mediaType)&&c.includes("image")?{src:(null==i||null==(s=i.file)?void 0:s.url)||"",alt:(null==i||null==(f=i.file)||null==(d=f.details)||null==(h=d.image)?void 0:h.alt)||"",title:(null==i?void 0:i.title)||"",description:(null==i?void 0:i.description)||"",width:(null==i||null==(v=i.file)||null==(m=v.details)||null==(p=m.image)?void 0:p.width)||0,height:(null==i||null==(y=i.file)||null==(g=y.details)||null==(S=g.image)?void 0:S.height)||0}:{mimeType:(null==i||null==(l=i.file)?void 0:l.mediaType)||"",src:(null==i||null==(u=i.file)?void 0:u.url)||"",title:(null==i?void 0:i.title)||"",description:(null==i?void 0:i.description)||""}:null:Array.isArray(t)?t.map(e):Object.entries(t).reduce(function(n,r){var i,a=r[0],o=r[1];return"fields"!==a&&"renderingParams"!==a||"object"!=typeof o||Array.isArray(o)||!o?"object"==typeof o&&"sys"!==a?("contentType"===a&&"sys"in t&&(o.sysId=t.sys.id),n[a]=e(o)):"sys"!==a&&(n["uri"===a?"href":a]=O(o)):"EditorialComponent"===(null==t||null==(i=t.contentType)?void 0:i.type)&&"fields"===a?n.content=e(o):Object.entries(o).forEach(function(t){n[t[0]]=e(t[1])}),n},{}):O(t)};function O(e){return"true"===e||"false"!==e&&(void 0===e?null:e)}var F=function(e,t,n){try{var r,a=function(e){return A(r)},o={applicationId:t.applicationId,dataSource:n.dataSource||t.defaultDataSource,operationId:n.operationId,locale:n.locale,environment:n.environment,market:n.market,timeout:n.timeout},c=function(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(function(){return Promise.resolve(E(i({},o,{apiKey:t.apiKey,path:"/entries/"+e,accept:"entrysuccessresponse"}))).then(function(e){r=e})},function(e){var t="Failed fetching entry";throw e instanceof y?t+=" '"+e.status+": "+e.message+"'":e.message&&(t+=" ("+e.message+")"),new S(t,o,e)});return Promise.resolve(c&&c.then?c.then(a):a())}catch(e){return Promise.reject(e)}},T=function(e,t,n){try{var r={applicationId:t.applicationId,dataSource:n.dataSource||t.defaultDataSource,operationId:n.operationId,locale:n.locale,environment:n.environment,market:n.market,contentType:e};return Promise.resolve(function(e,n){try{var a=Promise.resolve(E(i({},r,{apiKey:t.apiKey,path:"/entries",accept:"entrylistitemlistresponse"}))).then(A)}catch(e){return n(e)}return a&&a.then?a.then(void 0,n):a}(0,function(e){var t="Failed fetching entries list";throw e instanceof y?t+=" '"+e.status+": "+e.message+"'":e.message&&(t+=" ("+e.message+")"),new S(t,r,e)}))}catch(e){return Promise.reject(e)}};function L(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var M=function(){function e(e,t){this.pendingRevalidations=0,this.dictionariesRevalidate=60,this.entriesRevalidate=60,this.listEntriesRevalidate=60,this.config=e,this.applicationId=e.applicationId,this.defaultDataSource=e.defaultDataSource,this.localDataClient=t,"number"==typeof e.revalidate?(this.dictionariesRevalidate=e.revalidate,this.entriesRevalidate=e.revalidate,this.listEntriesRevalidate=e.revalidate):"object"==typeof e.revalidate&&e.revalidate&&("number"==typeof e.revalidate.dictionaries&&(this.dictionariesRevalidate=e.revalidate.dictionaries),"number"==typeof e.revalidate.entries&&(this.entriesRevalidate=e.revalidate.entries),"number"==typeof e.revalidate.listEntries&&(this.listEntriesRevalidate=e.revalidate.listEntries)),this.dictionariesCache=new h(this.dictionariesRevalidate),this.dictionariesListCache=new h(this.dictionariesRevalidate),this.entriesCache=new h(this.entriesRevalidate),this.listEntriesCache=new h(this.listEntriesRevalidate)}var t,n=e.prototype;return n.getDictionary=function(e,t){try{var n,r=this,i=function(i){return n?i:(r.dictionariesCache.isStale(c)&&(r.pendingRevalidations++,k(e,r.config,t).then(function(e){r.dictionariesCache.set(c,e)}).catch(function(e){r.logError("dictionaries",{locale:a},e)}).finally(function(){r.pendingRevalidations--})),N([[e,r.dictionariesCache.get(c)]]))},a=t.locale;j(e);var o=t.dataSource||r.config.defaultDataSource,c={locale:a,dataSource:o,name:e,environment:t.environment,market:t.market},l=function(){if(0===r.dictionariesRevalidate||!r.dictionariesCache.has(c))return L(function(){return Promise.resolve(k(e,r.config,t)).then(function(t){return r.dictionariesCache.set(c,t),n=1,N([[e,t]])})},function(i){function l(e){throw i}if(r.dictionariesCache.has(c))return r.logError("dictionaries",{locale:a,dataSource:o},i),n=1,N([[e,r.dictionariesCache.get(c)]]);var u=function(){if("DictionaryNotFoundError"===i.name&&r.localDataClient)return r.logError("dictionaries",{locale:a,dataSource:o},i),r.logFallback(),n=1,Promise.resolve(r.localDataClient.getDictionary(e,t))}();return u&&u.then?u.then(l):l()})}();return Promise.resolve(l&&l.then?l.then(i):i(l))}catch(e){return Promise.reject(e)}},n.getDictionaries=function(e,t){try{var n,r=this,a=function(a){var u;if(n)return a;function s(t){return u?t:N(e.map(function(e){return[e,r.dictionariesCache.get(i({name:e},l))]}))}var f=function(e,t,n){for(var r,a=[],o=[],c=d(e);!(r=c()).done;){var l=r.value;t.has(i({name:l},n))?t.isStale(i({name:l},n))&&o.push(l):a.push(l)}return{missing:a,stale:o}}(e,r.dictionariesCache,l),h=f.missing;f.stale.forEach(function(e){r.pendingRevalidations++,k(e,r.config,t).then(function(t){r.dictionariesCache.set(i({name:e},l),t)}).catch(function(e){r.logError("dictionaries",{locale:o,dataSource:c},e)}).finally(function(){r.pendingRevalidations--})});var v=function(){if(h.length>0)return L(function(){return Promise.resolve(I(h,r.config,t)).then(function(e){for(var t,n=d(e);!(t=n()).done;){var a=t.value,o=a[1];r.dictionariesCache.set(i({name:a[0]},l),o)}})},function(n){function a(e){throw n}var s=function(){if("DictionaryNotFoundError"===n.name){if(Array.isArray(n.data)){for(var a,s=d(n.data);!(a=s()).done;){var f=a.value,v=f[1];r.dictionariesCache.set(i({name:f[0]},l),v)}n.data=N(n.data)}return function(){if(r.localDataClient)return r.logError("dictionaries",{locale:o,dataSource:c},n),r.logFallback(),u=1,Promise.resolve(r.localDataClient.getDictionaries(h,t)).then(function(t){return i({},N(e.map(function(e){return[e,r.dictionariesCache.get(i({name:e},l))]})),t)})}()}}();return s&&s.then?s.then(a):a()})}();return v&&v.then?v.then(s):s(v)},o=t.locale;e.forEach(j);var c=t.dataSource||r.config.defaultDataSource,l={locale:o,dataSource:c,environment:t.environment,market:t.market},u=function(){if(0===r.dictionariesRevalidate||e.some(function(e){return!r.dictionariesCache.has(i({name:e},l))}))return L(function(){return Promise.resolve(I(e,r.config,t)).then(function(e){for(var t,a=d(e);!(t=a()).done;){var o=t.value,c=o[1];r.dictionariesCache.set(i({name:o[0]},l),c)}return n=1,N(e)})},function(a){function u(e){throw a}if("DictionaryNotFoundError"===a.name&&Array.isArray(a.data)){for(var s,f=d(a.data);!(s=f()).done;){var h=s.value,v=h[1];r.dictionariesCache.set(i({name:h[0]},l),v)}a.data=N(a.data)}if(e.every(function(e){return r.dictionariesCache.has(i({name:e},l))}))return r.logError("dictionaries",{locale:o,dataSource:c},a),n=1,N(e.map(function(e){return[e,r.dictionariesCache.get(i({name:e},l))]}));var m=function(){if("DictionaryNotFoundError"===a.name&&r.localDataClient)return r.logError("dictionaries",{locale:o,dataSource:c},a),r.logFallback(),n=1,Promise.resolve(r.localDataClient.getDictionaries(e,t))}();return m&&m.then?m.then(u):u()})}();return Promise.resolve(u&&u.then?u.then(a):a(u))}catch(e){return Promise.reject(e)}},n.getAllDictionaries=function(e){try{var t,n=this,r=function(r){return t?r:(n.dictionariesListCache.isStale(c)&&(n.pendingRevalidations++,b(n.config,e).then(function(e){for(var t,r=d(e);!(t=r()).done;){var a=t.value,o=a[1];n.dictionariesCache.set(i({},c,{name:a[0]}),o)}n.dictionariesListCache.set(c,e)}).catch(function(e){n.logError("dictionaries",{locale:a,dataSource:o},e)}).finally(function(){n.pendingRevalidations--})),N(n.dictionariesListCache.get(c)))},a=e.locale,o=e.dataSource||n.config.defaultDataSource,c={name:"all",locale:a,dataSource:o,environment:e.environment,market:e.market},l=function(){if(0===n.dictionariesRevalidate||!n.dictionariesListCache.has(c))return L(function(){return Promise.resolve(b(n.config,e)).then(function(e){if(e.length>0){for(var r,a=d(e);!(r=a()).done;){var o=r.value,l=o[1];n.dictionariesCache.set(i({},c,{name:o[0]}),l)}n.dictionariesListCache.set(c,e)}return t=1,N(e)})},function(r){function i(e){throw r}if(n.dictionariesListCache.has(c))return n.logError("dictionaries",{locale:a,dataSource:o},r),t=1,N(n.dictionariesListCache.get(c));var l=function(){if("DictionaryNotFoundError"===r.name&&n.localDataClient)return n.logError("dictionaries",{locale:a,dataSource:o},r),n.logFallback(),t=1,Promise.resolve(n.localDataClient.getAllDictionaries(e))}();return l&&l.then?l.then(i):i()})}();return Promise.resolve(l&&l.then?l.then(r):r(l))}catch(e){return Promise.reject(e)}},n.getEntry=function(e,t){try{var n,r=this,i=function(i){return n?i:(r.entriesCache.isStale(c)&&(r.pendingRevalidations++,F(e,r.config,t).then(function(e){r.entriesCache.set(c,e)}).catch(function(e){r.logError("entries",{locale:a,dataSource:o},e)}).finally(function(){r.pendingRevalidations--})),r.entriesCache.get(c))},a=t.locale,o=t.dataSource||r.config.defaultDataSource,c={locale:a,dataSource:o,name:e,environment:t.environment,market:t.market},l=function(){if(!r.entriesCache||!r.entriesCache.has(c))return L(function(){return Promise.resolve(F(e,r.config,t)).then(function(e){return r.entriesCache&&r.entriesCache.set(c,e),n=1,e})},function(e){throw r.logError("entries",{locale:a,dataSource:o},e),e})}();return Promise.resolve(l&&l.then?l.then(i):i(l))}catch(e){return Promise.reject(e)}},n.listEntries=function(e,t){try{var n,r=this,i=function(i){return n?i:(r.listEntriesCache.isStale(c)&&(r.pendingRevalidations++,T(e,r.config,t).then(function(e){r.listEntriesCache.set(c,e)}).catch(function(e){r.logError("list-entries",{locale:a,dataSource:o},e)}).finally(function(){r.pendingRevalidations--})),r.listEntriesCache.get(c))},a=t.locale,o=t.dataSource||r.config.defaultDataSource,c={locale:a,dataSource:o,name:e,environment:t.environment,market:t.market},l=function(){if(!r.listEntriesCache||!r.listEntriesCache.has(c))return L(function(){return Promise.resolve(T(e,r.config,t)).then(function(e){return r.listEntriesCache&&r.listEntriesCache.set(c,e),n=1,e})},function(e){throw r.logError("list-entries",{locale:a,dataSource:o},e),e})}();return Promise.resolve(l&&l.then?l.then(i):i(l))}catch(e){return Promise.reject(e)}},n.logError=function(e,t,n){"test"!==process.env.NODE_ENV&&(console.log("Failed fetching "+e+" for locale '"+t.locale+"' in dataSource '"+t.dataSource+"'."),console.log(n))},n.logFallback=function(){"test"!==process.env.NODE_ENV&&console.log("Falling back to local data...")},(t=[{key:"isValidating",get:function(){return this.pendingRevalidations>0}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(e.prototype,t),e}();function N(e){return r.default(Object.fromEntries(e))}var K=["forceLocalData","fallbackToLocalData"];exports.ContentDeliveryError=S,exports.DictionaryNotFoundError=w,exports.createClient=function(e){var t=e.forceLocalData,n=e.fallbackToLocalData,r=function(e,t){if(null==e)return{};var n,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)t.indexOf(n=a[r])>=0||(i[n]=e[n]);return i}(e,K);if(r.dataSource&&!r.defaultDataSource&&(r.defaultDataSource=r.dataSource),"undefined"!=typeof window){if(t)throw new Error("The 'forceLocalData' option is only available in SSR.");if(n)throw new Error("The 'fallbackToLocalData' option is only available in SSR.")}else{var i=require("./LocalDataClient").LocalDataClient;if(t)return new i(r);if(n)return new M(r,new i(r))}return new M(r)}; | ||
var e=require("flat"),t=require("@volvo-cars/market-sites");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function r(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,t}var i=n(e);function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function a(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,u(e,t)}function c(e){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function s(e,t,n){return(s=l()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&u(i,n.prototype),i}).apply(null,arguments)}function f(e){var t="function"==typeof Map?new Map:void 0;return(f=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return s(e,arguments,c(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),u(n,e)})(e)}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function h(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var v=/^[A-Za-z0-9]+\.[A-Za-z0-9]+$/;function m(e){if(!v.test(e))throw Error("Canonical dictionary names are only allowed in the format 'namespace.name'. No special characters allowed.")}var p=function(){function e(e){if(this.isValidating=!1,!e.path)throw new TypeError("'path' to local fallback content missing in config. Required when using local data options.");this.config=e,this.applicationId=e.applicationId,this.defaultDataSource=e.defaultDataSource}var t=e.prototype;return t.getDictionary=function(e,t){try{var n=this;return m(e),Promise.resolve(Promise.resolve().then(function(){return require("./getLocalDictionaries-336a0fe5.js")})).then(function(t){var r=n.flattenDictionaries;return Promise.resolve((0,t.getLocalDictionary)(e,n.config.path)).then(function(t){var i;return r.call(n,((i={})[e]=t,i))})})}catch(e){return Promise.reject(e)}},t.getDictionaries=function(e,t){try{var n=this;return Promise.resolve(Promise.resolve().then(function(){return require("./getLocalDictionaries-336a0fe5.js")})).then(function(t){var r=t.getLocalDictionaries;e.forEach(m);var i=n.flattenDictionaries;return Promise.resolve(r(e,n.config.path)).then(function(e){return i.call(n,Object.fromEntries(e))})})}catch(e){return Promise.reject(e)}},t.getAllDictionaries=function(e){try{var t=this;return Promise.resolve(Promise.resolve().then(function(){return require("./getLocalDictionaries-336a0fe5.js")})).then(function(e){var n=t.flattenDictionaries;return Promise.resolve((0,e.getLocalDictionaries)([],t.config.path)).then(function(e){return n.call(t,Object.fromEntries(e))})})}catch(e){return Promise.reject(e)}},t.getEntry=function(e,t){return Promise.resolve({})},t.listEntries=function(e,t){return Promise.resolve([])},t.flattenDictionaries=function(e){try{return Promise.resolve(Promise.resolve().then(function(){return r(require("flat"))})).then(function(t){return(0,t.default)(e)})}catch(e){return Promise.reject(e)}},e}(),g=function(){function e(e){this.lastUpdated=new Map,this.values=new Map,this.revalidateMs=1e3*e}var t=e.prototype;return t.set=function(e,t){var n=y(e);this.lastUpdated.set(n,Date.now()),this.values.set(n,t)},t.has=function(e){return this.values.has(y(e))},t.get=function(e){return this.values.get(y(e))},t.isStale=function(e){var t=y(e);return!!this.lastUpdated.has(t)&&(0===this.revalidateMs||Date.now()-this.lastUpdated.get(t)>=this.revalidateMs)},e}();function y(e){return["name","locale","environment","market","dataSource"].map(function(t){return e[t]||"-"}).join("|")}var P,S={AE:"AE",BA:"Bosnia",GB:"UK",HK:"HongKong",MK:"Macedonia",US:"US",XA:"armoured-cars"},w=["AM","AO","BW","ID","KE","LK","MM","MZ","NA","TN","UZ","XA","XP","ZM","ZW"],E=function(e){function t(t,n,r){var i;return(i=e.call(this,t)||this).name="RequestError",i.status=n,i.url=r,i}return a(t,e),t}(f(Error)),D=function(e){function t(t){var n;return(n=e.call(this,"Timed out after "+t+" seconds")||this).name="TimeoutError",n.timeout=t,n}return a(t,e),t}(f(Error)),C=function(e){function t(t,n,r){var i,o=n.applicationId,a=n.dataSource,c=n.locale,u=n.environment,l=n.operationId,s=n.market;return(i=e.call(this,t+" in "+c+" @ "+a+" '"+(u||"live")+"'")||this).name="ContentDeliveryError",i.errors=[],i.applicationId=o,i.dataSource=a,i.operationId=l,i.locale=c,s&&(i.market=s),i.environment=u,r&&(i.errors=Array.isArray(r)?[].concat(r):Array.isArray(r.errors)?[].concat(r.errors,[r]):[r]),i}return a(t,e),t}(f(Error)),b=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).name="DictionaryNotFoundError",t}return a(t,e),t}(C),j=function(){function e(e){this.timeout=e}var t=e.prototype;return t.run=function(){var e=this;if(this.timeoutId)throw new Error("Can only run once");return new Promise(function(t,n){e.timeout&&(e.timeoutId=setTimeout(function(){n(new D(e.timeout))},1e3*e.timeout))})},t.clear=function(){this.timeoutId&&clearTimeout(this.timeoutId)},e}(),k=function(e){var n=e.applicationId,i=e.dataSource,a=e.path,c=e.market,u=void 0!==c&&c,l=e.locale,s=e.accept,f=e.environment,d=void 0===f?"live":f,h=e.operationId,v=e.contentType,m=e.timeout,p=e.config;try{var g=function(){return Promise.resolve(Promise.race([y.run(),fetch(D.href,o({headers:o({Accept:"application/vnd.volvocars.api.contentdelivery."+s+"+json","VCC-Api-Key":p.apiKey},h&&{"VCC-Api-OperationId":h})},b)).then(function(e){return y.clear(),e},function(e){throw y.clear(),e})])).then(function(e){return Promise.resolve(e.json()).then(function(t){if(e.ok&&"data"in t&&200===t.status)return t.data;throw new E("error"in t?t.error.message:t.message,e.status,e.url)})})},y=new j(m),D=new URL(I);if(D.pathname+="/"+n+a,D.searchParams.set("Locale",l),i&&D.searchParams.set("DataSource",i),"authoringPreview"===d&&D.searchParams.set("preview","true"),D.searchParams.set("environment",d),u){var C=function(e){var n=t.getMarketSite(e);if(n.regionCode&&n.marketName){var r=S[n.regionCode]||n.marketName.replace(/\s/g,"");return w.includes(n.regionCode)&&(r="minisites/"+r),r}}(t.getMarketSiteByLocale(l).siteSlug);C&&D.searchParams.set("market",C)}v&&D.searchParams.set("contentType",v);var b=p.fetchOptions,k=function(){var e;if("undefined"==typeof window&&void 0===(null==(e=b)?void 0:e.agent))return Promise.resolve(function(){try{var e=function(){if(!P)return Promise.resolve(Promise.resolve().then(function(){return r(require("https"))})).then(function(e){P=new(0,e.Agent)({keepAlive:!0,maxSockets:40,maxFreeSockets:10})})}();return Promise.resolve(e&&e.then?e.then(function(){return P}):P)}catch(e){return Promise.reject(e)}}()).then(function(e){b=o({},b,{agent:e})})}();return Promise.resolve(k&&k.then?k.then(g):g())}catch(e){return Promise.reject(e)}},I="https://gw.consumer.api.volvocars.com/content-delivery/v1/applications";function R(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var A=function(e,t){try{return Promise.resolve(function(e,t){try{var n,r=function(e){if(0===n.length)throw new b("Empty dictionaries response",i);return n},i={applicationId:e.applicationId,dataSource:t.dataSource||e.defaultDataSource,operationId:t.operationId,locale:t.locale,environment:t.environment,timeout:t.timeout},a=R(function(){return Promise.resolve(k(o({},i,{config:e,path:"/dictionaries",accept:"dictionarylistresponse"}))).then(function(e){n=e})},function(t){var n="Failed fetching dictionaries";if(t instanceof E){if(404===t.status)throw new C("Application "+e.applicationId+" not found",i,t);n+=" '"+t.status+": "+t.message+"'"}else t.message&&(n+=" ("+t.message+")");throw new C(n,i,t)});return Promise.resolve(a&&a.then?a.then(r):r())}catch(e){return Promise.reject(e)}}(e,t)).then(function(e){return e.map(function(e){return[e.namespace+"."+e.name,e.items]})})}catch(e){return Promise.reject(e)}},O=function(e,t,n){try{var r=[];return Promise.resolve(Promise.all(e.map(function(e){try{var i,o=function(t){return[e,i]},a=R(function(){return Promise.resolve(L(e,t,n)).then(function(e){i=e})},function(e){if("DictionaryNotFoundError"!==e.name)throw e;r.push(e)});return Promise.resolve(a&&a.then?a.then(o):o())}catch(e){return Promise.reject(e)}}))).then(function(e){var i,o=e.filter(function(e){return!!e[1]});if(r.length>0)throw(i=1===r.length?r[0]:new b(r.length+" dictionaries not found",{applicationId:t.applicationId,dataSource:n.dataSource||t.defaultDataSource,operationId:n.operationId,locale:n.locale,environment:n.environment},r)).data=o,i;return o})}catch(e){return Promise.reject(e)}},L=function(e,t,n){return function(e,t,n){try{var r,i=function(e){return r.items},a={applicationId:t.applicationId,dataSource:n.dataSource||t.defaultDataSource,operationId:n.operationId,locale:n.locale,environment:n.environment,timeout:n.timeout,market:n.market},c=R(function(){return Promise.resolve(k(o({},a,{config:t,path:"/dictionaries/"+e,accept:"dictionarysuccessresponse"}))).then(function(e){r=e})},function(n){var r="Failed fetching dictionary '"+e+"'";if(n instanceof E){if(404===n.status){if("Resource not found"===n.message)throw new C("Application "+t.applicationId+" not found",a,n);if(n.message.includes(e))throw new b("Dictionary not found: "+n.message,a,n)}r+=" '"+n.status+": "+n.message+"'"}else n.message&&(r+=" ("+n.message+")");throw new C(r,a,n)});return Promise.resolve(c&&c.then?c.then(i):i())}catch(e){return Promise.reject(e)}}(e,t,n)},F=function e(t){var n,r,i,o,a,c,u,l,s,f,d,h,v,m,p,g,y,P;return"object"==typeof t&&t?null!=t&&null!=(n=t.file)&&n.mediaType||null!=t&&null!=(r=t.file)&&r.details?null!=(i=t)&&null!=(o=i.file)&&o.url?null!=i&&null!=(a=i.file)&&null!=(c=a.mediaType)&&c.includes("image")?{src:(null==i||null==(s=i.file)?void 0:s.url)||"",alt:(null==i||null==(f=i.file)||null==(d=f.details)||null==(h=d.image)?void 0:h.alt)||"",title:(null==i?void 0:i.title)||"",description:(null==i?void 0:i.description)||"",width:(null==i||null==(v=i.file)||null==(m=v.details)||null==(p=m.image)?void 0:p.width)||0,height:(null==i||null==(g=i.file)||null==(y=g.details)||null==(P=y.image)?void 0:P.height)||0}:{mimeType:(null==i||null==(u=i.file)?void 0:u.mediaType)||"",src:(null==i||null==(l=i.file)?void 0:l.url)||"",title:(null==i?void 0:i.title)||"",description:(null==i?void 0:i.description)||""}:null:Array.isArray(t)?t.map(e):Object.entries(t).reduce(function(n,r){var i,o=r[0],a=r[1];return"fields"!==o&&"renderingParams"!==o||"object"!=typeof a||Array.isArray(a)||!a?"object"==typeof a&&"sys"!==o?("contentType"===o&&"sys"in t&&(a.sysId=t.sys.id),n[o]=e(a)):"sys"!==o&&(n["uri"===o?"href":o]=T(a)):"EditorialComponent"===(null==t||null==(i=t.contentType)?void 0:i.type)&&"fields"===o?n.content=e(a):Object.entries(a).forEach(function(t){n[t[0]]=e(t[1])}),n},{}):T(t)};function T(e){return"true"===e||"false"!==e&&(void 0===e?null:e)}var M=function(e,t,n){try{var r,i=function(e){return F(r)},a={applicationId:t.applicationId,dataSource:n.dataSource||t.defaultDataSource,operationId:n.operationId,locale:n.locale,environment:n.environment,market:n.market,timeout:n.timeout},c=function(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(function(){return Promise.resolve(k(o({},a,{config:t,path:"/entries/"+e,accept:"entrysuccessresponse"}))).then(function(e){r=e})},function(e){var t="Failed fetching entry";throw e instanceof E?t+=" '"+e.status+": "+e.message+"'":e.message&&(t+=" ("+e.message+")"),new C(t,a,e)});return Promise.resolve(c&&c.then?c.then(i):i())}catch(e){return Promise.reject(e)}},N=function(e,t,n){try{var r={applicationId:t.applicationId,dataSource:n.dataSource||t.defaultDataSource,operationId:n.operationId,locale:n.locale,environment:n.environment,market:n.market,contentType:e};return Promise.resolve(function(e,n){try{var i=Promise.resolve(k(o({},r,{config:t,path:"/entries",accept:"entrylistitemlistresponse"}))).then(F)}catch(e){return n(e)}return i&&i.then?i.then(void 0,n):i}(0,function(e){var t="Failed fetching entries list";throw e instanceof E?t+=" '"+e.status+": "+e.message+"'":e.message&&(t+=" ("+e.message+")"),new C(t,r,e)}))}catch(e){return Promise.reject(e)}};function _(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var x=function(){function e(e,t){this.pendingRevalidations=0,this.dictionariesRevalidate=60,this.entriesRevalidate=60,this.listEntriesRevalidate=60,this.config=e,this.applicationId=e.applicationId,this.defaultDataSource=e.defaultDataSource,this.localDataClient=t,"number"==typeof e.revalidate?(this.dictionariesRevalidate=e.revalidate,this.entriesRevalidate=e.revalidate,this.listEntriesRevalidate=e.revalidate):"object"==typeof e.revalidate&&e.revalidate&&("number"==typeof e.revalidate.dictionaries&&(this.dictionariesRevalidate=e.revalidate.dictionaries),"number"==typeof e.revalidate.entries&&(this.entriesRevalidate=e.revalidate.entries),"number"==typeof e.revalidate.listEntries&&(this.listEntriesRevalidate=e.revalidate.listEntries)),this.dictionariesCache=new g(this.dictionariesRevalidate),this.dictionariesListCache=new g(this.dictionariesRevalidate),this.entriesCache=new g(this.entriesRevalidate),this.listEntriesCache=new g(this.listEntriesRevalidate)}var t,n=e.prototype;return n.getDictionary=function(e,t){try{var n,r=this,i=function(i){return n?i:(r.dictionariesCache.isStale(c)&&(r.pendingRevalidations++,L(e,r.config,t).then(function(e){r.dictionariesCache.set(c,e)}).catch(function(e){r.logError("dictionaries",{locale:o},e)}).finally(function(){r.pendingRevalidations--})),U([[e,r.dictionariesCache.get(c)]]))},o=t.locale;m(e);var a=t.dataSource||r.config.defaultDataSource,c={locale:o,dataSource:a,name:e,environment:t.environment,market:t.market},u=function(){if(0===r.dictionariesRevalidate||!r.dictionariesCache.has(c))return _(function(){return Promise.resolve(L(e,r.config,t)).then(function(t){return r.dictionariesCache.set(c,t),n=1,U([[e,t]])})},function(i){function u(e){throw i}if(r.dictionariesCache.has(c))return r.logError("dictionaries",{locale:o,dataSource:a},i),n=1,U([[e,r.dictionariesCache.get(c)]]);var l=function(){if("DictionaryNotFoundError"===i.name&&r.localDataClient)return r.logError("dictionaries",{locale:o,dataSource:a},i),r.logFallback(),n=1,Promise.resolve(r.localDataClient.getDictionary(e,t))}();return l&&l.then?l.then(u):u()})}();return Promise.resolve(u&&u.then?u.then(i):i(u))}catch(e){return Promise.reject(e)}},n.getDictionaries=function(e,t){try{var n,r=this,i=function(i){var l;if(n)return i;function s(t){return l?t:U(e.map(function(e){return[e,r.dictionariesCache.get(o({name:e},u))]}))}var f=function(e,t,n){for(var r,i=[],a=[],c=h(e);!(r=c()).done;){var u=r.value;t.has(o({name:u},n))?t.isStale(o({name:u},n))&&a.push(u):i.push(u)}return{missing:i,stale:a}}(e,r.dictionariesCache,u),d=f.missing;f.stale.forEach(function(e){r.pendingRevalidations++,L(e,r.config,t).then(function(t){r.dictionariesCache.set(o({name:e},u),t)}).catch(function(e){r.logError("dictionaries",{locale:a,dataSource:c},e)}).finally(function(){r.pendingRevalidations--})});var v=function(){if(d.length>0)return _(function(){return Promise.resolve(O(d,r.config,t)).then(function(e){for(var t,n=h(e);!(t=n()).done;){var i=t.value,a=i[1];r.dictionariesCache.set(o({name:i[0]},u),a)}})},function(n){function i(e){throw n}var s=function(){if("DictionaryNotFoundError"===n.name){if(Array.isArray(n.data)){for(var i,s=h(n.data);!(i=s()).done;){var f=i.value,v=f[1];r.dictionariesCache.set(o({name:f[0]},u),v)}n.data=U(n.data)}return function(){if(r.localDataClient)return r.logError("dictionaries",{locale:a,dataSource:c},n),r.logFallback(),l=1,Promise.resolve(r.localDataClient.getDictionaries(d,t)).then(function(t){return o({},U(e.map(function(e){return[e,r.dictionariesCache.get(o({name:e},u))]})),t)})}()}}();return s&&s.then?s.then(i):i()})}();return v&&v.then?v.then(s):s(v)},a=t.locale;e.forEach(m);var c=t.dataSource||r.config.defaultDataSource,u={locale:a,dataSource:c,environment:t.environment,market:t.market},l=function(){if(0===r.dictionariesRevalidate||e.some(function(e){return!r.dictionariesCache.has(o({name:e},u))}))return _(function(){return Promise.resolve(O(e,r.config,t)).then(function(e){for(var t,i=h(e);!(t=i()).done;){var a=t.value,c=a[1];r.dictionariesCache.set(o({name:a[0]},u),c)}return n=1,U(e)})},function(i){function l(e){throw i}if("DictionaryNotFoundError"===i.name&&Array.isArray(i.data)){for(var s,f=h(i.data);!(s=f()).done;){var d=s.value,v=d[1];r.dictionariesCache.set(o({name:d[0]},u),v)}i.data=U(i.data)}if(e.every(function(e){return r.dictionariesCache.has(o({name:e},u))}))return r.logError("dictionaries",{locale:a,dataSource:c},i),n=1,U(e.map(function(e){return[e,r.dictionariesCache.get(o({name:e},u))]}));var m=function(){if("DictionaryNotFoundError"===i.name&&r.localDataClient)return r.logError("dictionaries",{locale:a,dataSource:c},i),r.logFallback(),n=1,Promise.resolve(r.localDataClient.getDictionaries(e,t))}();return m&&m.then?m.then(l):l()})}();return Promise.resolve(l&&l.then?l.then(i):i(l))}catch(e){return Promise.reject(e)}},n.getAllDictionaries=function(e){try{var t,n=this,r=function(r){return t?r:(n.dictionariesListCache.isStale(c)&&(n.pendingRevalidations++,A(n.config,e).then(function(e){for(var t,r=h(e);!(t=r()).done;){var i=t.value,a=i[1];n.dictionariesCache.set(o({},c,{name:i[0]}),a)}n.dictionariesListCache.set(c,e)}).catch(function(e){n.logError("dictionaries",{locale:i,dataSource:a},e)}).finally(function(){n.pendingRevalidations--})),U(n.dictionariesListCache.get(c)))},i=e.locale,a=e.dataSource||n.config.defaultDataSource,c={name:"all",locale:i,dataSource:a,environment:e.environment,market:e.market},u=function(){if(0===n.dictionariesRevalidate||!n.dictionariesListCache.has(c))return _(function(){return Promise.resolve(A(n.config,e)).then(function(e){if(e.length>0){for(var r,i=h(e);!(r=i()).done;){var a=r.value,u=a[1];n.dictionariesCache.set(o({},c,{name:a[0]}),u)}n.dictionariesListCache.set(c,e)}return t=1,U(e)})},function(r){function o(e){throw r}if(n.dictionariesListCache.has(c))return n.logError("dictionaries",{locale:i,dataSource:a},r),t=1,U(n.dictionariesListCache.get(c));var u=function(){if("DictionaryNotFoundError"===r.name&&n.localDataClient)return n.logError("dictionaries",{locale:i,dataSource:a},r),n.logFallback(),t=1,Promise.resolve(n.localDataClient.getAllDictionaries(e))}();return u&&u.then?u.then(o):o()})}();return Promise.resolve(u&&u.then?u.then(r):r(u))}catch(e){return Promise.reject(e)}},n.getEntry=function(e,t){try{var n,r=this,i=function(i){return n?i:(r.entriesCache.isStale(c)&&(r.pendingRevalidations++,M(e,r.config,t).then(function(e){r.entriesCache.set(c,e)}).catch(function(e){r.logError("entries",{locale:o,dataSource:a},e)}).finally(function(){r.pendingRevalidations--})),r.entriesCache.get(c))},o=t.locale,a=t.dataSource||r.config.defaultDataSource,c={locale:o,dataSource:a,name:e,environment:t.environment,market:t.market},u=function(){if(!r.entriesCache||!r.entriesCache.has(c))return _(function(){return Promise.resolve(M(e,r.config,t)).then(function(e){return r.entriesCache&&r.entriesCache.set(c,e),n=1,e})},function(e){throw r.logError("entries",{locale:o,dataSource:a},e),e})}();return Promise.resolve(u&&u.then?u.then(i):i(u))}catch(e){return Promise.reject(e)}},n.listEntries=function(e,t){try{var n,r=this,i=function(i){return n?i:(r.listEntriesCache.isStale(c)&&(r.pendingRevalidations++,N(e,r.config,t).then(function(e){r.listEntriesCache.set(c,e)}).catch(function(e){r.logError("list-entries",{locale:o,dataSource:a},e)}).finally(function(){r.pendingRevalidations--})),r.listEntriesCache.get(c))},o=t.locale,a=t.dataSource||r.config.defaultDataSource,c={locale:o,dataSource:a,name:e,environment:t.environment,market:t.market},u=function(){if(!r.listEntriesCache||!r.listEntriesCache.has(c))return _(function(){return Promise.resolve(N(e,r.config,t)).then(function(e){return r.listEntriesCache&&r.listEntriesCache.set(c,e),n=1,e})},function(e){throw r.logError("list-entries",{locale:o,dataSource:a},e),e})}();return Promise.resolve(u&&u.then?u.then(i):i(u))}catch(e){return Promise.reject(e)}},n.logError=function(e,t,n){"test"!==process.env.NODE_ENV&&(console.log("Failed fetching "+e+" for locale '"+t.locale+"' in dataSource '"+t.dataSource+"'."),console.log(n))},n.logFallback=function(){"test"!==process.env.NODE_ENV&&console.log("Falling back to local data...")},(t=[{key:"isValidating",get:function(){return this.pendingRevalidations>0}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(e.prototype,t),e}();function U(e){return i.default(Object.fromEntries(e))}var q=["forceLocalData","fallbackToLocalData"];exports.ContentDeliveryError=C,exports.DictionaryNotFoundError=b,exports.createClient=function(e){var t=e.forceLocalData,n=e.fallbackToLocalData,r=function(e,t){if(null==e)return{};var n,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)t.indexOf(n=o[r])>=0||(i[n]=e[n]);return i}(e,q);if(r.dataSource&&!r.defaultDataSource&&(r.defaultDataSource=r.dataSource),"undefined"!=typeof window){if(t)throw new Error("The 'forceLocalData' option is only available in SSR.");if(n)throw new Error("The 'fallbackToLocalData' option is only available in SSR.")}else{if(t)return new p(r);if(n)return new x(r,new p(r))}return new x(r)}; | ||
//# sourceMappingURL=content-delivery-client.js.map |
@@ -1,3 +0,5 @@ | ||
import { FlattenedDictionaries } from './dictionaries/types'; | ||
import { ContentType, ListEntriesResponseData } from './entries/types'; | ||
/// <reference types="node" /> | ||
import type { Agent } from 'https'; | ||
import type { FlattenedDictionaries } from './dictionaries/types'; | ||
import type { ContentType, ListEntriesResponseData } from './entries/types'; | ||
export declare type ContentEnvironment = 'live' | 'authoringPreview' | 'master'; | ||
@@ -35,2 +37,9 @@ declare type ContentDeliveryDataSource = 'dotcom-sitecore-test' | 'dotcom-sitecore-qa' | 'dotcom-sitecore-prod' | string; | ||
}; | ||
/** | ||
* Options to pass through to fetch. By default includes a Keep-Alive https Agent in Node.js. | ||
* Pass `agent: null` or a custom `https.Agent` instance to disable the default agent. | ||
*/ | ||
fetchOptions?: { | ||
agent?: Agent | null; | ||
} & Record<string, any>; | ||
}; | ||
@@ -37,0 +46,0 @@ export declare type CreateClientOptions = ClientConfig & { |
@@ -1,6 +0,6 @@ | ||
import { ClientConfig } from '..'; | ||
import { GetOptions } from '../ContentDeliveryClient'; | ||
import { Dictionary } from './types'; | ||
import type { ClientConfig } from '..'; | ||
import type { GetOptions } from '../ContentDeliveryClient'; | ||
import type { Dictionary } from './types'; | ||
export declare function fetchDictionary(canonicalDictionaryName: string, config: ClientConfig, options: GetOptions): Promise<Dictionary['items']>; | ||
export declare function fetchDictionaries(canonicalDictionaryNames: string[], config: ClientConfig, options: GetOptions): Promise<[string, Dictionary['items']][]>; | ||
export declare function fetchAllDictionaries(config: ClientConfig, options: GetOptions): Promise<[string, Dictionary['items']][]>; |
@@ -1,3 +0,3 @@ | ||
import { ContentEnvironment } from '../ContentDeliveryClient'; | ||
import { Cache } from '../utils/Cache'; | ||
import type { ContentEnvironment } from '../ContentDeliveryClient'; | ||
import type { Cache } from '../utils/Cache'; | ||
export declare function validateCanonicalDictionaryName(canonicalDictionaryName: string): void; | ||
@@ -4,0 +4,0 @@ export declare function sortCanonicalDictionaryNames(canonicalDictionaryNames: string[], cache: Cache, partialCacheKey: { |
@@ -1,3 +0,3 @@ | ||
import { ContentType } from '../entries/types'; | ||
import type { ContentEnvironment } from '../ContentDeliveryClient'; | ||
import type { ContentType } from '../entries/types'; | ||
import type { ContentEnvironment, ClientConfig } from '../ContentDeliveryClient'; | ||
export declare type RequestDetails = { | ||
@@ -13,7 +13,8 @@ applicationId: string; | ||
}; | ||
export declare type SendRequestOptions = { | ||
declare type SendRequestOptions = { | ||
config: ClientConfig; | ||
path: string; | ||
accept: string; | ||
apiKey: string; | ||
}; | ||
export declare function sendRequest<Results>({ applicationId, dataSource, path, market, locale, accept, environment, apiKey, operationId, contentType, timeout, }: RequestDetails & SendRequestOptions): Promise<Results>; | ||
export declare function sendRequest<Results>({ applicationId, dataSource, path, market, locale, accept, environment, operationId, contentType, timeout, config, }: RequestDetails & SendRequestOptions): Promise<Results>; | ||
export {}; |
@@ -7,3 +7,3 @@ { | ||
"name": "@volvo-cars/content-delivery-client", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"publishConfig": { | ||
@@ -15,5 +15,5 @@ "access": "public" | ||
"@volvo-cars/market-sites": "^1.1.0", | ||
"flat": "5.0.1", | ||
"nock": "^13.0.5" | ||
"flat": "^5.0.0", | ||
"glob": "^7.0.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
415882
25
665
4
11
12
+ Addedglob@^7.0.0
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedflat@5.0.2(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removednock@^13.0.5
- Removeddebug@4.3.5(transitive)
- Removedflat@5.0.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedms@2.1.2(transitive)
- Removednock@13.5.4(transitive)
- Removedpropagate@2.0.1(transitive)
Updatedflat@^5.0.0