Socket
Socket
Sign inDemoInstall

@volvo-cars/content-delivery-client

Package Overview
Dependencies
14
Maintainers
9
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.0 to 0.4.1

CHANGELOG.md

226

dist/index.esm.js
import flatten from 'flat';
import { getMarketSite, getMarketSiteByLocale } from '@volvo-cars/market-sites';
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
const canonicalDictionaryNameRegex = /^[A-Za-z0-9]+\.[A-Za-z0-9]+$/;

@@ -48,9 +15,11 @@ function validateCanonicalDictionaryName(canonicalDictionaryName) {

for (const name of canonicalDictionaryNames) {
if (!cache.has(_extends({
name
}, partialCacheKey))) {
if (!cache.has({
name,
...partialCacheKey
})) {
missing.push(name);
} else if (cache.isStale(_extends({
name
}, partialCacheKey))) {
} else if (cache.isStale({
name,
...partialCacheKey
})) {
stale.push(name);

@@ -336,15 +305,17 @@ }

if (typeof window === 'undefined' && typeof ((_fetchOptions = fetchOptions) == null ? void 0 : _fetchOptions.agent) === 'undefined') {
fetchOptions = _extends({}, fetchOptions, {
fetchOptions = { ...fetchOptions,
agent: await getKeepAliveAgent()
});
};
}
const response = await Promise.race([timer.run(), fetch(url.href, _extends({
headers: _extends({
const response = await Promise.race([timer.run(), fetch(url.href, {
headers: {
Accept: `application/vnd.volvocars.api.contentdelivery.${accept}+json`,
'VCC-Api-Key': config.apiKey
}, operationId && {
'VCC-Api-OperationId': operationId
})
}, fetchOptions)).then(response => {
'VCC-Api-Key': config.apiKey,
...(operationId && {
'VCC-Api-OperationId': operationId
})
},
...fetchOptions
}).then(response => {
timer.clear();

@@ -475,7 +446,7 @@ return response;

try {
results = await sendRequest(_extends({}, requestDetails, {
results = await sendRequest({ ...requestDetails,
config,
path: `/dictionaries/${canonicalDictionaryName}`,
accept: 'dictionarysuccessresponse'
}));
});
} catch (error) {

@@ -524,7 +495,7 @@ let message = `Failed fetching dictionary '${canonicalDictionaryName}'`;

try {
results = await sendRequest(_extends({}, requestDetails, {
results = await sendRequest({ ...requestDetails,
config,
path: '/dictionaries',
accept: 'dictionarylistresponse'
}));
});
} catch (error) {

@@ -647,7 +618,7 @@ let message = `Failed fetching dictionaries`;

try {
result = await sendRequest(_extends({}, requestDetails, {
result = await sendRequest({ ...requestDetails,
config,
path: `/entries/${canonicalName}`,
accept: 'entrysuccessresponse'
}));
});
} catch (error) {

@@ -682,7 +653,7 @@ let message = 'Failed fetching entry';

try {
const result = await sendRequest(_extends({}, requestDetails, {
const result = await sendRequest({ ...requestDetails,
config,
path: `/entries`,
accept: 'entrylistitemlistresponse'
}));
});
return traverse(result);

@@ -764,14 +735,13 @@ } catch (error) {

const _excluded = ["dataSource", "environment"];
const getOptionsWithDefaults = (options, config) => {
const {
dataSource,
environment
} = options,
rest = _objectWithoutPropertiesLoose(options, _excluded);
return _extends({
environment,
...rest
} = options;
return {
dataSource: dataSource != null ? dataSource : config.defaultDataSource,
environment: environment != null ? environment : config.defaultEnvironment
}, rest);
environment: environment != null ? environment : config.defaultEnvironment,
...rest
};
};

@@ -819,3 +789,5 @@

if (typeof config.revalidate === 'object') {
config.revalidate = _extends({}, revalidate, config.revalidate);
config.revalidate = { ...revalidate,
...config.revalidate
};
} else {

@@ -850,7 +822,6 @@ config.revalidate = revalidate;

};
const cacheKey = _extends({}, operationDetails, {
const cacheKey = { ...operationDetails,
name: canonicalDictionaryName,
market: options.market
});
};

@@ -907,10 +878,10 @@ if (this.config.revalidate.dictionaries === 0 || !this.dictionariesCache.has(cacheKey)) {

};
const cacheKey = _extends({}, operationDetails, {
const cacheKey = { ...operationDetails,
market: options.market
});
};
if (this.config.revalidate.dictionaries === 0 || canonicalDictionaryNames.some(name => !this.dictionariesCache.has(_extends({
name
}, cacheKey)))) {
if (this.config.revalidate.dictionaries === 0 || canonicalDictionaryNames.some(name => !this.dictionariesCache.has({
name,
...cacheKey
}))) {
try {

@@ -920,5 +891,6 @@ const dictionaries = await fetchDictionaries(canonicalDictionaryNames, this.config, options);

for (const [name, items] of dictionaries) {
this.dictionariesCache.set(_extends({
name
}, cacheKey), items);
this.dictionariesCache.set({
name,
...cacheKey
}, items);
}

@@ -931,5 +903,6 @@

for (const [name, items] of error.data) {
this.dictionariesCache.set(_extends({
name
}, cacheKey), items);
this.dictionariesCache.set({
name,
...cacheKey
}, items);
}

@@ -940,5 +913,6 @@

if (canonicalDictionaryNames.every(name => this.dictionariesCache.has(_extends({
name
}, cacheKey)))) {
if (canonicalDictionaryNames.every(name => this.dictionariesCache.has({
name,
...cacheKey
}))) {
this.logError('dictionaries', operationDetails, error); // Return stale content if everything is now available in the cache

@@ -949,5 +923,6 @@

return [name, (_this$dictionariesCac3 = this.dictionariesCache.get(_extends({
name
}, cacheKey))) != null ? _this$dictionariesCac3 : {}];
return [name, (_this$dictionariesCac3 = this.dictionariesCache.get({
name,
...cacheKey
})) != null ? _this$dictionariesCac3 : {}];
}));

@@ -976,5 +951,6 @@ }

fetchDictionary(canonicalDictionaryName, this.config, options).then(dictionary => {
this.dictionariesCache.set(_extends({
name: canonicalDictionaryName
}, cacheKey), dictionary);
this.dictionariesCache.set({
name: canonicalDictionaryName,
...cacheKey
}, dictionary);
}).catch(error => {

@@ -995,5 +971,6 @@ // Failing to refresh a stale entry is not a fatal error, because

for (const [name, items] of dictionaries) {
this.dictionariesCache.set(_extends({
name
}, cacheKey), items);
this.dictionariesCache.set({
name,
...cacheKey
}, items);
}

@@ -1005,5 +982,6 @@ } catch (error) {

for (const [name, items] of error.data) {
this.dictionariesCache.set(_extends({
name
}, cacheKey), items);
this.dictionariesCache.set({
name,
...cacheKey
}, items);
}

@@ -1019,9 +997,12 @@

return _extends({}, flattenDictionaries(canonicalDictionaryNames.map(name => {
var _this$dictionariesCac4;
return { ...flattenDictionaries(canonicalDictionaryNames.map(name => {
var _this$dictionariesCac4;
return [name, (_this$dictionariesCac4 = this.dictionariesCache.get(_extends({
name
}, cacheKey))) != null ? _this$dictionariesCac4 : {}];
})), await this.localDataClient.getDictionaries(missing, options));
return [name, (_this$dictionariesCac4 = this.dictionariesCache.get({
name,
...cacheKey
})) != null ? _this$dictionariesCac4 : {}];
})),
...(await this.localDataClient.getDictionaries(missing, options))
};
}

@@ -1038,5 +1019,6 @@ }

return [name, (_this$dictionariesCac5 = this.dictionariesCache.get(_extends({
name
}, cacheKey))) != null ? _this$dictionariesCac5 : {}];
return [name, (_this$dictionariesCac5 = this.dictionariesCache.get({
name,
...cacheKey
})) != null ? _this$dictionariesCac5 : {}];
}));

@@ -1055,7 +1037,6 @@ }

};
const cacheKey = _extends({}, operationDetails, {
const cacheKey = { ...operationDetails,
name: 'all',
market: options.market
});
};

@@ -1068,5 +1049,5 @@ if (this.config.revalidate.dictionaries === 0 || !this.dictionariesListCache.has(cacheKey)) {

for (const [name, items] of dictionaries) {
this.dictionariesCache.set(_extends({}, cacheKey, {
this.dictionariesCache.set({ ...cacheKey,
name
}), items);
}, items);
}

@@ -1102,5 +1083,5 @@

for (const [name, items] of dictionaries) {
this.dictionariesCache.set(_extends({}, cacheKey, {
this.dictionariesCache.set({ ...cacheKey,
name
}), items);
}, items);
}

@@ -1129,7 +1110,6 @@

};
const cacheKey = _extends({}, operationDetails, {
const cacheKey = { ...operationDetails,
name: canonicalName,
market: options.market
});
};

@@ -1181,7 +1161,6 @@ if (this.config.revalidate.entries === 0 || !this.entriesCache.has(cacheKey)) {

};
const cacheKey = _extends({}, operationDetails, {
const cacheKey = { ...operationDetails,
name: contentType,
market: options.market
});
};

@@ -1268,10 +1247,7 @@ if (this.config.revalidate.listEntries === 0 || !this.listEntriesCache.has(cacheKey)) {

const _excluded$1 = ["forceLocalData", "fallbackToLocalData"];
function createClient(_ref) {
let {
forceLocalData,
fallbackToLocalData
} = _ref,
config = _objectWithoutPropertiesLoose(_ref, _excluded$1);
function createClient({
forceLocalData,
fallbackToLocalData,
...config
}) {
if (config.dataSource && !config.defaultDataSource) {

@@ -1278,0 +1254,0 @@ config.defaultDataSource = config.dataSource;

@@ -28,35 +28,2 @@ var flatten = require('flat');

function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
const canonicalDictionaryNameRegex = /^[A-Za-z0-9]+\.[A-Za-z0-9]+$/;

@@ -73,9 +40,11 @@ function validateCanonicalDictionaryName(canonicalDictionaryName) {

for (const name of canonicalDictionaryNames) {
if (!cache.has(_extends({
name
}, partialCacheKey))) {
if (!cache.has({
name,
...partialCacheKey
})) {
missing.push(name);
} else if (cache.isStale(_extends({
name
}, partialCacheKey))) {
} else if (cache.isStale({
name,
...partialCacheKey
})) {
stale.push(name);

@@ -361,15 +330,17 @@ }

if (typeof window === 'undefined' && typeof ((_fetchOptions = fetchOptions) == null ? void 0 : _fetchOptions.agent) === 'undefined') {
fetchOptions = _extends({}, fetchOptions, {
fetchOptions = { ...fetchOptions,
agent: await getKeepAliveAgent()
});
};
}
const response = await Promise.race([timer.run(), fetch(url.href, _extends({
headers: _extends({
const response = await Promise.race([timer.run(), fetch(url.href, {
headers: {
Accept: `application/vnd.volvocars.api.contentdelivery.${accept}+json`,
'VCC-Api-Key': config.apiKey
}, operationId && {
'VCC-Api-OperationId': operationId
})
}, fetchOptions)).then(response => {
'VCC-Api-Key': config.apiKey,
...(operationId && {
'VCC-Api-OperationId': operationId
})
},
...fetchOptions
}).then(response => {
timer.clear();

@@ -500,7 +471,7 @@ return response;

try {
results = await sendRequest(_extends({}, requestDetails, {
results = await sendRequest({ ...requestDetails,
config,
path: `/dictionaries/${canonicalDictionaryName}`,
accept: 'dictionarysuccessresponse'
}));
});
} catch (error) {

@@ -549,7 +520,7 @@ let message = `Failed fetching dictionary '${canonicalDictionaryName}'`;

try {
results = await sendRequest(_extends({}, requestDetails, {
results = await sendRequest({ ...requestDetails,
config,
path: '/dictionaries',
accept: 'dictionarylistresponse'
}));
});
} catch (error) {

@@ -672,7 +643,7 @@ let message = `Failed fetching dictionaries`;

try {
result = await sendRequest(_extends({}, requestDetails, {
result = await sendRequest({ ...requestDetails,
config,
path: `/entries/${canonicalName}`,
accept: 'entrysuccessresponse'
}));
});
} catch (error) {

@@ -707,7 +678,7 @@ let message = 'Failed fetching entry';

try {
const result = await sendRequest(_extends({}, requestDetails, {
const result = await sendRequest({ ...requestDetails,
config,
path: `/entries`,
accept: 'entrylistitemlistresponse'
}));
});
return traverse(result);

@@ -789,14 +760,13 @@ } catch (error) {

const _excluded = ["dataSource", "environment"];
const getOptionsWithDefaults = (options, config) => {
const {
dataSource,
environment
} = options,
rest = _objectWithoutPropertiesLoose(options, _excluded);
return _extends({
environment,
...rest
} = options;
return {
dataSource: dataSource != null ? dataSource : config.defaultDataSource,
environment: environment != null ? environment : config.defaultEnvironment
}, rest);
environment: environment != null ? environment : config.defaultEnvironment,
...rest
};
};

@@ -844,3 +814,5 @@

if (typeof config.revalidate === 'object') {
config.revalidate = _extends({}, revalidate, config.revalidate);
config.revalidate = { ...revalidate,
...config.revalidate
};
} else {

@@ -875,7 +847,6 @@ config.revalidate = revalidate;

};
const cacheKey = _extends({}, operationDetails, {
const cacheKey = { ...operationDetails,
name: canonicalDictionaryName,
market: options.market
});
};

@@ -932,10 +903,10 @@ if (this.config.revalidate.dictionaries === 0 || !this.dictionariesCache.has(cacheKey)) {

};
const cacheKey = _extends({}, operationDetails, {
const cacheKey = { ...operationDetails,
market: options.market
});
};
if (this.config.revalidate.dictionaries === 0 || canonicalDictionaryNames.some(name => !this.dictionariesCache.has(_extends({
name
}, cacheKey)))) {
if (this.config.revalidate.dictionaries === 0 || canonicalDictionaryNames.some(name => !this.dictionariesCache.has({
name,
...cacheKey
}))) {
try {

@@ -945,5 +916,6 @@ const dictionaries = await fetchDictionaries(canonicalDictionaryNames, this.config, options);

for (const [name, items] of dictionaries) {
this.dictionariesCache.set(_extends({
name
}, cacheKey), items);
this.dictionariesCache.set({
name,
...cacheKey
}, items);
}

@@ -956,5 +928,6 @@

for (const [name, items] of error.data) {
this.dictionariesCache.set(_extends({
name
}, cacheKey), items);
this.dictionariesCache.set({
name,
...cacheKey
}, items);
}

@@ -965,5 +938,6 @@

if (canonicalDictionaryNames.every(name => this.dictionariesCache.has(_extends({
name
}, cacheKey)))) {
if (canonicalDictionaryNames.every(name => this.dictionariesCache.has({
name,
...cacheKey
}))) {
this.logError('dictionaries', operationDetails, error); // Return stale content if everything is now available in the cache

@@ -974,5 +948,6 @@

return [name, (_this$dictionariesCac3 = this.dictionariesCache.get(_extends({
name
}, cacheKey))) != null ? _this$dictionariesCac3 : {}];
return [name, (_this$dictionariesCac3 = this.dictionariesCache.get({
name,
...cacheKey
})) != null ? _this$dictionariesCac3 : {}];
}));

@@ -1001,5 +976,6 @@ }

fetchDictionary(canonicalDictionaryName, this.config, options).then(dictionary => {
this.dictionariesCache.set(_extends({
name: canonicalDictionaryName
}, cacheKey), dictionary);
this.dictionariesCache.set({
name: canonicalDictionaryName,
...cacheKey
}, dictionary);
}).catch(error => {

@@ -1020,5 +996,6 @@ // Failing to refresh a stale entry is not a fatal error, because

for (const [name, items] of dictionaries) {
this.dictionariesCache.set(_extends({
name
}, cacheKey), items);
this.dictionariesCache.set({
name,
...cacheKey
}, items);
}

@@ -1030,5 +1007,6 @@ } catch (error) {

for (const [name, items] of error.data) {
this.dictionariesCache.set(_extends({
name
}, cacheKey), items);
this.dictionariesCache.set({
name,
...cacheKey
}, items);
}

@@ -1044,9 +1022,12 @@

return _extends({}, flattenDictionaries(canonicalDictionaryNames.map(name => {
var _this$dictionariesCac4;
return { ...flattenDictionaries(canonicalDictionaryNames.map(name => {
var _this$dictionariesCac4;
return [name, (_this$dictionariesCac4 = this.dictionariesCache.get(_extends({
name
}, cacheKey))) != null ? _this$dictionariesCac4 : {}];
})), await this.localDataClient.getDictionaries(missing, options));
return [name, (_this$dictionariesCac4 = this.dictionariesCache.get({
name,
...cacheKey
})) != null ? _this$dictionariesCac4 : {}];
})),
...(await this.localDataClient.getDictionaries(missing, options))
};
}

@@ -1063,5 +1044,6 @@ }

return [name, (_this$dictionariesCac5 = this.dictionariesCache.get(_extends({
name
}, cacheKey))) != null ? _this$dictionariesCac5 : {}];
return [name, (_this$dictionariesCac5 = this.dictionariesCache.get({
name,
...cacheKey
})) != null ? _this$dictionariesCac5 : {}];
}));

@@ -1080,7 +1062,6 @@ }

};
const cacheKey = _extends({}, operationDetails, {
const cacheKey = { ...operationDetails,
name: 'all',
market: options.market
});
};

@@ -1093,5 +1074,5 @@ if (this.config.revalidate.dictionaries === 0 || !this.dictionariesListCache.has(cacheKey)) {

for (const [name, items] of dictionaries) {
this.dictionariesCache.set(_extends({}, cacheKey, {
this.dictionariesCache.set({ ...cacheKey,
name
}), items);
}, items);
}

@@ -1127,5 +1108,5 @@

for (const [name, items] of dictionaries) {
this.dictionariesCache.set(_extends({}, cacheKey, {
this.dictionariesCache.set({ ...cacheKey,
name
}), items);
}, items);
}

@@ -1154,7 +1135,6 @@

};
const cacheKey = _extends({}, operationDetails, {
const cacheKey = { ...operationDetails,
name: canonicalName,
market: options.market
});
};

@@ -1206,7 +1186,6 @@ if (this.config.revalidate.entries === 0 || !this.entriesCache.has(cacheKey)) {

};
const cacheKey = _extends({}, operationDetails, {
const cacheKey = { ...operationDetails,
name: contentType,
market: options.market
});
};

@@ -1293,10 +1272,7 @@ if (this.config.revalidate.listEntries === 0 || !this.listEntriesCache.has(cacheKey)) {

const _excluded$1 = ["forceLocalData", "fallbackToLocalData"];
function createClient(_ref) {
let {
forceLocalData,
fallbackToLocalData
} = _ref,
config = _objectWithoutPropertiesLoose(_ref, _excluded$1);
function createClient({
forceLocalData,
fallbackToLocalData,
...config
}) {
if (config.dataSource && !config.defaultDataSource) {

@@ -1303,0 +1279,0 @@ config.defaultDataSource = config.dataSource;

{
"name": "@volvo-cars/content-delivery-client",
"version": "0.4.0",
"version": "0.4.1",
"license": "UNLICENSED",
"source": "index.ts",
"main": "index.ts",
"main": "dist/index.js",
"publishConfig": {

@@ -31,3 +31,3 @@ "access": "public",

"@types/flat": "^5.0.1",
"@volvo-cars/market-sites": "^1.5.0",
"@volvo-cars/market-sites": "1.6.0",
"flat": "^5.0.0",

@@ -37,9 +37,10 @@ "glob": "^7.0.0"

"devDependencies": {
"@vcc-www/testing": "workspace:*",
"@vcc-www/utils": "workspace:*",
"@volvo-cars/content-management-client": "workspace:*",
"microbundle": "^0.14.2",
"@vcc-www/testing": "0.0.0",
"@vcc-www/utils": "0.0.0",
"@volvo-cars/content-management-client": "0.15.0",
"microbundle": "^0.15.1",
"nock": "^13.0.5",
"typescript": "*"
}
}
},
"module": "dist/index.esm.js"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc