Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@commercetools/api-request-builder

Package Overview
Dependencies
Maintainers
7
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commercetools/api-request-builder - npm Package Compare versions

Comparing version 4.0.2 to 4.1.0

LICENSE

389

dist/commercetools-api-request-builder.cjs.js

@@ -5,2 +5,36 @@ 'use strict';

function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
}
return target;
}
/**

@@ -16,6 +50,5 @@ * NOTE:

var create = 'create';
var update = 'update';
// `delete` is a reserved word in JavaScript
var update = 'update'; // `delete` is a reserved word in JavaScript
var del = 'delete';
/**

@@ -27,2 +60,3 @@ * NOTE:

*/
var query = 'query';

@@ -238,3 +272,2 @@ var queryOne = 'queryOne';

/* */
/**

@@ -245,2 +278,3 @@ * Return the default parameters for building a query string.

*/
function getDefaultQueryParams() {

@@ -253,3 +287,4 @@ return {

perPage: null,
sort: []
sort: [],
withTotal: null
},

@@ -268,3 +303,2 @@ location: {

}
/**

@@ -275,2 +309,3 @@ * Return the default parameters for building a query search string.

*/
function getDefaultSearchParams() {

@@ -283,3 +318,4 @@ return {

perPage: null,
sort: []
sort: [],
withTotal: null
},

@@ -298,3 +334,2 @@ search: {

}
/**

@@ -305,8 +340,8 @@ * Set the default parameters given the current service object.

*/
function setDefaultParams() {
this.params.expand = getDefaultQueryParams().expand;
if (this.features.includes(queryOne)) this.params.id = getDefaultQueryParams().id;
if (this.features.indexOf(queryOne) !== -1) this.params.id = getDefaultQueryParams().id;
if (this.features.indexOf(query) !== -1) {
if (this.features.includes(query)) {
this.params.pagination = getDefaultQueryParams().pagination;

@@ -316,3 +351,3 @@ this.params.query = getDefaultQueryParams().query;

if (this.features.indexOf(search) !== -1) {
if (this.features.includes(search)) {
this.params.pagination = getDefaultSearchParams().pagination;

@@ -322,5 +357,4 @@ this.params.search = getDefaultSearchParams().search;

if (this.features.indexOf(queryLocation) !== -1) this.params.location = getDefaultQueryParams().location;
if (this.features.indexOf(suggest) !== -1) this.params.searchKeywords = [];
if (this.features.includes(queryLocation)) this.params.location = getDefaultQueryParams().location;
if (this.features.includes(suggest)) this.params.searchKeywords = [];
}

@@ -331,3 +365,2 @@

};
/**

@@ -338,2 +371,4 @@ * Set the supplied parameters given the current service object.

*/
function setParams(params) {

@@ -343,24 +378,20 @@ var _this = this;

// verify params
var knownKeys = ['expand', 'id', 'key', 'customerId', 'cartId', 'sort', 'page', 'perPage', 'staged', 'priceCurrency', 'priceCountry', 'priceCustomerGroup', 'priceChannel', 'text', 'fuzzy', 'fuzzyLevel', 'markMatchingVariants', 'facet', 'filter', 'filterByQuery', 'filterByFacets', 'searchKeywords', 'where', 'whereOperator', 'version', 'country', 'currency', 'state', 'dataErasure'];
var knownKeys = ['expand', 'id', 'key', 'customerId', 'cartId', 'sort', 'page', 'perPage', 'staged', 'priceCurrency', 'priceCountry', 'priceCustomerGroup', 'priceChannel', 'text', 'fuzzy', 'fuzzyLevel', 'markMatchingVariants', 'facet', 'filter', 'filterByQuery', 'filterByFacets', 'searchKeywords', 'where', 'whereOperator', 'version', 'country', 'currency', 'state', 'dataErasure', 'withTotal'];
Object.keys(params).forEach(function (key) {
if (!(knownKeys.indexOf(key) !== -1)) throw new Error('Unknown key "' + key + '"');
});
if (!knownKeys.includes(key)) throw new Error("Unknown key \"".concat(key, "\""));
}); // query-expand
// query-expand
if (params.expand) params.expand.forEach(function (expansion) {
_this.expand(expansion);
});
}); // query-id
// query-id
if (hasKey(params, 'id')) this.byId(params.id);
if (hasKey(params, 'key')) this.byKey(params.key);
if (hasKey(params, 'customerId')) this.byCustomerId(params.customerId);
if (hasKey(params, 'cartId')) this.byCartId(params.cartId);
if (hasKey(params, 'cartId')) this.byCartId(params.cartId); // query-location
// query-location
if (hasKey(params, 'country')) this.byCountry(params.country);
if (hasKey(params, 'currency')) this.byCurrency(params.currency);
if (hasKey(params, 'state')) this.byState(params.state);
if (hasKey(params, 'state')) this.byState(params.state); // query-page
// query-page
if (params.sort) params.sort.forEach(function (sortDesc) {

@@ -370,5 +401,4 @@ _this.sort(sortDesc.by, sortDesc.direction === 'asc');

if (hasKey(params, 'page')) this.page(params.page);
if (hasKey(params, 'perPage')) this.perPage(params.perPage);
if (hasKey(params, 'perPage')) this.perPage(params.perPage); // query-projection
// query-projection
if (hasKey(params, 'staged')) this.staged(params.staged);

@@ -378,9 +408,10 @@ if (hasKey(params, 'priceCurrency')) this.priceCurrency(params.priceCurrency);

if (hasKey(params, 'priceCustomerGroup')) this.priceCustomerGroup(params.priceCustomerGroup);
if (hasKey(params, 'priceChannel')) this.priceChannel(params.priceChannel);
if (hasKey(params, 'priceChannel')) this.priceChannel(params.priceChannel); // query-search
// query-search
if (params.text) this.text(params.text.value, params.text.language);
if (params.fuzzy) this.fuzzy(); // boolean switch
if (hasKey(params, 'fuzzyLevel')) this.fuzzyLevel(params.fuzzyLevel);
if (params.markMatchingVariants) this.markMatchingVariants(); // boolean switch
if (params.facet) params.facet.forEach(function (facet) {

@@ -397,20 +428,18 @@ _this.facet(facet);

_this.filterByFacets(facet);
});
}); // query-suggest
// query-suggest
if (params.searchKeywords) params.searchKeywords.forEach(function (searchKeyword) {
_this.searchKeywords(searchKeyword.value, searchKeyword.language);
});
}); // query
// query
if (params.where) params.where.forEach(function (predicate) {
_this.where(predicate);
});
if (hasKey(params, 'whereOperator')) this.whereOperator(params.whereOperator);
if (hasKey(params, 'whereOperator')) this.whereOperator(params.whereOperator); // version
// version
if (hasKey(params, 'version')) this.withVersion(params.version);
if (hasKey(params, 'version')) this.withVersion(params.version); // dataErasure
// dataErasure
if (hasKey(params, 'dataErasure')) this.withFullDataErasure();
if (hasKey(params, 'dataErasure')) this.withFullDataErasure(); // withTotal
if (hasKey(params, 'withTotal')) this.withTotal(params.withTotal);
}

@@ -427,5 +456,3 @@

var forceEnumerable = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var clone = {};
Object.keys(object).forEach(function (key) {

@@ -437,3 +464,2 @@ Object.defineProperty(clone, key, {

});
return clone;

@@ -453,3 +479,2 @@ }

if (!params) throw new Error('Missing options object to build query string.');
var query = params.query,

@@ -470,21 +495,12 @@ pagination = params.pagination,

dataErasure = params.dataErasure;
var queryString = [];
if (customerId) queryString.push('customerId=' + customerId);
if (cartId) queryString.push('cartId=' + cartId);
if (typeof staged === 'boolean') queryString.push('staged=' + staged.toString());
if (priceCurrency) queryString.push('priceCurrency=' + priceCurrency);
if (priceCountry) queryString.push('priceCountry=' + priceCountry);
if (priceCustomerGroup) queryString.push('priceCustomerGroup=' + priceCustomerGroup);
if (priceChannel) queryString.push('priceChannel=' + priceChannel);
if (customerId) queryString.push("customerId=".concat(customerId));
if (cartId) queryString.push("cartId=".concat(cartId));
if (typeof staged === 'boolean') queryString.push("staged=".concat(staged.toString()));
if (priceCurrency) queryString.push("priceCurrency=".concat(priceCurrency));
if (priceCountry) queryString.push("priceCountry=".concat(priceCountry));
if (priceCustomerGroup) queryString.push("priceCustomerGroup=".concat(priceCustomerGroup));
if (priceChannel) queryString.push("priceChannel=".concat(priceChannel));
if (expand && expand.length) queryString = queryString.concat(expand.map(function (e) {
return 'expand=' + e;
return "expand=".concat(e);
}));

@@ -495,5 +511,4 @@

where = query.where;
var whereParams = where.join(encodeURIComponent(' ' + operator + ' '));
if (whereParams) queryString.push('where=' + whereParams);
var whereParams = where.join(encodeURIComponent(" ".concat(operator, " ")));
if (whereParams) queryString.push("where=".concat(whereParams));
}

@@ -505,6 +520,5 @@

state = location.state;
if (country) queryString.push('country=' + country);
if (currency) queryString.push('currency=' + currency);
if (state) queryString.push('state=' + state);
if (country) queryString.push("country=".concat(country));
if (currency) queryString.push("currency=".concat(currency));
if (state) queryString.push("state=".concat(state));
}

@@ -515,13 +529,16 @@

perPage = pagination.perPage,
sort = pagination.sort;
sort = pagination.sort,
withTotal = pagination.withTotal;
if (typeof perPage === 'number') queryString.push("limit=".concat(perPage));
if (typeof perPage === 'number') queryString.push('limit=' + perPage);
if (page) {
var limitParam = perPage || 20;
var offsetParam = limitParam * (page - 1);
queryString.push('offset=' + offsetParam);
queryString.push("offset=".concat(offsetParam));
}
if (sort && sort.length) queryString = queryString.concat(sort.map(function (s) {
return 'sort=' + s;
return "sort=".concat(s);
}));
if (typeof withTotal === 'boolean') queryString.push("withTotal=".concat(String(withTotal)));
}

@@ -538,20 +555,17 @@

filterByFacets = search.filterByFacets;
if (text) queryString.push('text.' + text.lang + '=' + text.value);
if (text) queryString.push("text.".concat(text.lang, "=").concat(text.value));
if (fuzzy) queryString.push('fuzzy=true');
if (fuzzyLevel) queryString.push('fuzzyLevel=' + fuzzyLevel);
queryString.push('markMatchingVariants=' + markMatchingVariants.toString());
if (fuzzyLevel) queryString.push("fuzzyLevel=".concat(fuzzyLevel));
queryString.push("markMatchingVariants=".concat(markMatchingVariants.toString()));
facet.forEach(function (f) {
return queryString.push('facet=' + f);
return queryString.push("facet=".concat(f));
});
filter.forEach(function (f) {
return queryString.push('filter=' + f);
return queryString.push("filter=".concat(f));
});
filterByQuery.forEach(function (f) {
return queryString.push('filter.query=' + f);
return queryString.push("filter.query=".concat(f));
});
filterByFacets.forEach(function (f) {
return queryString.push('filter.facets=' + f);
return queryString.push("filter.facets=".concat(f));
});

@@ -561,9 +575,6 @@ }

if (searchKeywords) searchKeywords.forEach(function (f) {
return queryString.push('searchKeywords.' + f.lang + '=' + f.value);
return queryString.push("searchKeywords.".concat(f.lang, "=").concat(f.value));
});
if (version) queryString.push('version=' + version);
if (version) queryString.push("version=".concat(version));
if (dataErasure) queryString.push(dataErasure);
return queryString.join('&');

@@ -573,2 +584,3 @@ }

/* */
/**

@@ -583,3 +595,2 @@ * Set the `version` number to the internal state of the service instance

*/
function withVersion(version) {

@@ -592,2 +603,3 @@ if (typeof version !== 'number') throw new Error('A resource version is missing or invalid');

/* */
/**

@@ -604,3 +616,2 @@ * Set the `dataErasure` option to the internal state of the service instance

*/
function withFullDataErasure() {

@@ -621,3 +632,2 @@ this.params.dataErasure = 'dataErasure=true';

if (!predicate) throw new Error('Required argument for `where` is missing');
var encodedPredicate = encodeURIComponent(predicate);

@@ -627,3 +637,2 @@ this.params.query.where.push(encodedPredicate);

}
/**

@@ -637,6 +646,6 @@ * Set the logical operator to combine multiple query predicates

*/
function whereOperator(operator) {
if (!operator) throw new Error('Required argument for `whereOperator` is missing');
if (!(operator === 'and' || operator === 'or')) throw new Error('Required argument for `whereOperator` is invalid, ' + 'allowed values are (`and`, `or`)');
this.params.query.operator = operator;

@@ -652,2 +661,3 @@ return this;

/* */
/**

@@ -664,9 +674,6 @@ * Set the given `id` to the internal state of the service instance.

if (this.params.customerId) throw new Error('A customerId for this resource has already been set. ' + 'You cannot use both `byId` and `byCustomerId`.');
if (this.params.cartId) throw new Error('A cartId for this resource has already been set. ' + 'You cannot use both `byId` and `byCartId`.');
this.params.id = id;
return this;
}
/**

@@ -679,10 +686,9 @@ * Set the given `key` to the internal state of the service instance.

*/
function byKey(key) {
if (!key) throw new Error('Required argument for `byKey` is missing');
if (this.params.id) throw new Error('An ID for this resource has already been set. ' + 'You cannot use both `byId` and `byKey`.');
this.params.key = key;
return this;
}
/**

@@ -696,10 +702,9 @@ * Set the given `id` to the `customerId`internal state of the service instance.

*/
function byCustomerId(custId) {
if (!custId) throw new Error('Required argument for `byCustomerId` is missing');
if (this.params.id) throw new Error('An ID for this resource has already been set. ' + 'You cannot use both `byId` and `byCustomerId`.');
this.params.customerId = custId;
return this;
}
/**

@@ -713,6 +718,6 @@ * Set the given `id` to the `cartId` internal state of the service instance.

*/
function byCartId(cartId) {
if (!cartId) throw new Error('Required argument for `byCartId` is missing');
if (this.params.id) throw new Error('An ID for this resource has already been set. ' + 'You cannot use both `byId` and `byCartId`.');
this.params.cartId = cartId;

@@ -739,7 +744,5 @@ return this;

if (!value) throw new Error('Required argument for `byCountry` is missing');
this.params.location.country = value;
return this;
}
/**

@@ -752,12 +755,10 @@ * Set the given `currency` param used for selection by currency.

*/
function byCurrency(value) {
if (!value) throw new Error('Required argument for `byCurrency` is missing');
if (!value) throw new Error('Required argument for `byCurrency` is missing'); // logic to verify country has been set
// logic to verify country has been set
if (!this.params.location.country) throw new Error('A `country` for this resource has not been set. ' + 'You must set the country in order to use the `byCurrency` method.');
this.params.location.currency = value;
return this;
}
/**

@@ -770,8 +771,7 @@ * Set the given `state` param used for selection by state.

*/
function byState(value) {
if (!value) throw new Error('Required argument for `byState` is missing');
if (!value) throw new Error('Required argument for `byState` is missing'); // logic to verify country has been set
// logic to verify country has been set
if (!this.params.location.country) throw new Error('A `country` for this resource has not been set. ' + 'You must set the country in order to use the `byState` method.');
this.params.location.state = value;

@@ -788,2 +788,3 @@ return this;

/* */
/**

@@ -803,6 +804,5 @@ * Set the

if (!value) throw new Error('Required argument for `expand` is missing');
var encodedPath = encodeURIComponent(value); // Note: this goes to base `params`, not `params.query`
// to be compatible with search.
var encodedPath = encodeURIComponent(value);
// Note: this goes to base `params`, not `params.query`
// to be compatible with search.
this.params.expand.push(encodedPath);

@@ -817,2 +817,3 @@ return this;

/* */
/**

@@ -833,11 +834,8 @@ * Set the sort expression for the query, if the related endpoint supports it.

var ascending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
if (!sortPath) throw new Error('Required argument for `sort` is missing');
var direction = ascending ? 'asc' : 'desc';
var encodedSort = encodeURIComponent(sortPath + ' ' + direction);
var encodedSort = encodeURIComponent("".concat(sortPath, " ").concat(direction));
this.params.pagination.sort.push(encodedSort);
return this;
}
/**

@@ -851,11 +849,9 @@ * Set the page number to be requested from the complete query result

*/
function page(value) {
if (typeof value !== 'number' && !value) throw new Error('Required argument for `page` is missing or invalid');
if (typeof value !== 'number' || value < 1) throw new Error('Required argument for `page` must be a number >= 1');
this.params.pagination.page = value;
return this;
}
/**

@@ -870,18 +866,32 @@ * Set the number of results to be returned from a query result

*/
function perPage(value) {
if (typeof value !== 'number' && !value) throw new Error('Required argument for `perPage` is missing or invalid');
if (typeof value !== 'number' || value < 0) throw new Error('Required argument for `perPage` must be a number >= 0');
this.params.pagination.perPage = value;
return this;
}
/**
* Set whether or not the total should be calculated (and included) in the result
* of a paginated query result.
*
* @param {boolean} value - indicating if the total should be included or not
*/
function withTotal() {
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (typeof value !== 'boolean') throw new Error('Required argument for `withTotal` is missing or invalid');
this.params.pagination.withTotal = value;
return this;
}
var queryPage = /*#__PURE__*/Object.freeze({
sort: sort,
page: page,
perPage: perPage
perPage: perPage,
withTotal: withTotal
});
/* */
/**

@@ -896,7 +906,5 @@ * Define whether to get the staged or current projection

var shouldFetchStaged = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
this.params.staged = shouldFetchStaged;
return this;
}
/**

@@ -909,2 +917,3 @@ * Define whether to set price Selection or not

*/
function priceCurrency(value) {

@@ -914,3 +923,2 @@ this.params.priceCurrency = value;

}
/**

@@ -924,2 +932,3 @@ * Define whether to set price Selection or not

*/
function priceCountry(value) {

@@ -929,3 +938,2 @@ this.params.priceCountry = value;

}
/**

@@ -939,2 +947,3 @@ * Define whether to set price Selection or not

*/
function priceCustomerGroup(value) {

@@ -944,3 +953,2 @@ this.params.priceCustomerGroup = value;

}
/**

@@ -954,2 +962,3 @@ * Define whether to set price Selection or not

*/
function priceChannel(value) {

@@ -969,2 +978,3 @@ this.params.priceChannel = value;

/* */
/**

@@ -987,4 +997,6 @@ * Define a Suggestion used for matching tokens for product projections,

if (!value || !lang) throw new Error('Required arguments for `searchKeywords` are missing');
this.params.searchKeywords.push({ lang: lang, value: encodeURIComponent(value) });
this.params.searchKeywords.push({
lang: lang,
value: encodeURIComponent(value)
});
return this;

@@ -998,2 +1010,3 @@ }

/* */
/**

@@ -1011,7 +1024,8 @@ * Set the given `text` param used for full-text search.

if (!value || !lang) throw new Error('Required arguments for `text` are missing');
this.params.search.text = { lang: lang, value: encodeURIComponent(value) };
this.params.search.text = {
lang: lang,
value: encodeURIComponent(value)
};
return this;
}
/**

@@ -1022,2 +1036,3 @@ * Define whether to enable the fuzzy search.

*/
function fuzzy() {

@@ -1027,3 +1042,2 @@ this.params.search.fuzzy = true;

}
/**

@@ -1036,2 +1050,3 @@ * Define the level of the fuzzy search

*/
function fuzzyLevel(value) {

@@ -1042,3 +1057,2 @@ if (!value) throw new Error('Required argument for `fuzzyLevel` is missing');

}
/**

@@ -1049,2 +1063,3 @@ * Define whether to enable markMatchingVariants

*/
function markMatchingVariants() {

@@ -1054,3 +1069,2 @@ this.params.search.markMatchingVariants = true;

}
/**

@@ -1064,5 +1078,5 @@ * Set the given `facet` filter used for calculating statistical counts.

*/
function facet(value) {
if (!value) throw new Error('Required argument for `facet` is missing');
var encodedFacet = encodeURIComponent(value);

@@ -1072,3 +1086,2 @@ this.params.search.facet.push(encodedFacet);

}
/**

@@ -1082,5 +1095,5 @@ * Set the given `filter` param used for filtering search results.

*/
function filter(value) {
if (!value) throw new Error('Required argument for `filter` is missing');
var encodedFilter = encodeURIComponent(value);

@@ -1090,3 +1103,2 @@ this.params.search.filter.push(encodedFilter);

}
/**

@@ -1100,5 +1112,5 @@ * Set the given `filter.query` param used for filtering search results.

*/
function filterByQuery(value) {
if (!value) throw new Error('Required argument for `filterByQuery` is missing');
var encodedFilter = encodeURIComponent(value);

@@ -1108,3 +1120,2 @@ this.params.search.filterByQuery.push(encodedFilter);

}
/**

@@ -1118,5 +1129,5 @@ * Set the given `filter.facets` param used for filtering search results.

*/
function filterByFacets(value) {
if (!value) throw new Error('Required argument for `filterByFacets` is missing');
var encodedFilter = encodeURIComponent(value);

@@ -1138,38 +1149,7 @@ this.params.search.filterByFacets.push(encodedFilter);

var defineProperty = function (obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
};
var _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;
};
/* */
var requiredDefinitionProps = ['type', 'endpoint', 'features'];
function getIdOrKey(params) {
if (params.id) return '/' + params.id;
if (params.key) return '/key=' + params.key;
if (params.id) return "/".concat(params.id);
if (params.key) return "/key=".concat(params.key);
return '';

@@ -1180,19 +1160,12 @@ }

var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
if (!definition) throw new Error('Cannot create a service without its definition.');
requiredDefinitionProps.forEach(function (key) {
if (!definition[key]) throw new Error('Definition is missing required parameter ' + key + '.');
if (!definition[key]) throw new Error("Definition is missing required parameter ".concat(key, "."));
});
if (!Array.isArray(definition.features) || !definition.features.length) throw new Error('Definition requires `features` to be a non empty array.');
if (!options) throw new Error('No project defined. Please enter a project key');
var type = definition.type,
endpoint = definition.endpoint,
features = definition.features;
return classify(_extends({
return classify(_objectSpread({
type: type,

@@ -1203,23 +1176,14 @@ features: features,

withFullDataErasure: withFullDataErasure
}, features.reduce(function (acc, feature) {
if (feature === query) return _extends({}, acc, query$1, queryPage);
if (feature === queryOne) return _extends({}, acc, queryId);
if (feature === queryLocation) return _extends({}, acc, queryLocation$1);
if (feature === queryExpand) return _extends({}, acc, queryExpand$1);
if (feature === search) return _extends({}, acc, querySearch, queryPage, {
if (feature === query) return _objectSpread({}, acc, query$1, queryPage);
if (feature === queryOne) return _objectSpread({}, acc, queryId);
if (feature === queryLocation) return _objectSpread({}, acc, queryLocation$1);
if (feature === queryExpand) return _objectSpread({}, acc, queryExpand$1);
if (feature === search) return _objectSpread({}, acc, querySearch, queryPage, {
params: getDefaultSearchParams()
});
if (feature === suggest) return _extends({}, acc, querySearch, queryPage, querySuggest);
if (feature === projection) return _extends({}, acc, queryProjection);
if (feature === suggest) return _objectSpread({}, acc, querySearch, queryPage, querySuggest);
if (feature === projection) return _objectSpread({}, acc, queryProjection);
return acc;
}, {}), {
// Call this method to get the built request URI

@@ -1229,19 +1193,14 @@ // Pass some options to further configure the URI:

build: function build() {
var uriOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { withProjectKey: true };
var uriOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
withProjectKey: true
};
var withProjectKey = uriOptions.withProjectKey;
var queryParams = buildQueryString(this.params);
var uri = (withProjectKey ? '/' + options : '') + endpoint +
// TODO this can lead to invalid URIs as getIdOrKey can return
var uri = (withProjectKey ? "/".concat(options) : '') + endpoint + // TODO this can lead to invalid URIs as getIdOrKey can return
// "/?customerId", so there can be multiple question marks,
// same for when `queryParams` and `version` are present
getIdOrKey(this.params) + (queryParams ? '?' + queryParams : '');
getIdOrKey(this.params) + (queryParams ? "?".concat(queryParams) : '');
setDefaultParams.call(this);
return uri;
},
// Call this method to parse an object as params

@@ -1255,5 +1214,2 @@ parse: function parse(params) {

/* */
// pass an options argument of type object containing
// the `projectkey` (string) and `customServices` (object)

@@ -1275,12 +1231,13 @@ // The projectKey property is required

// }
function createRequestBuilder() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var allServices = _extends({}, services, options.customServices);
var allServices = _objectSpread({}, services, options.customServices);
return Object.keys(allServices).reduce(
// a return type object is not allowed in flow due to a bug (https://github.com/facebook/flow/issues/5182)
return Object.keys(allServices).reduce( // a return type object is not allowed in flow due to a bug (https://github.com/facebook/flow/issues/5182)
/* eslint-disable-next-line */
function (acc, key) {
return _extends({}, acc, defineProperty({}, key, createService(allServices[key], options.projectKey)));
return _objectSpread({}, acc, _defineProperty({}, key, createService(allServices[key], options.projectKey)));
}, {});

@@ -1287,0 +1244,0 @@ }

@@ -0,1 +1,35 @@

function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
}
return target;
}
/**

@@ -11,6 +45,5 @@ * NOTE:

var create = 'create';
var update = 'update';
// `delete` is a reserved word in JavaScript
var update = 'update'; // `delete` is a reserved word in JavaScript
var del = 'delete';
/**

@@ -22,2 +55,3 @@ * NOTE:

*/
var query = 'query';

@@ -233,3 +267,2 @@ var queryOne = 'queryOne';

/* */
/**

@@ -240,2 +273,3 @@ * Return the default parameters for building a query string.

*/
function getDefaultQueryParams() {

@@ -248,3 +282,4 @@ return {

perPage: null,
sort: []
sort: [],
withTotal: null
},

@@ -263,3 +298,2 @@ location: {

}
/**

@@ -270,2 +304,3 @@ * Return the default parameters for building a query search string.

*/
function getDefaultSearchParams() {

@@ -278,3 +313,4 @@ return {

perPage: null,
sort: []
sort: [],
withTotal: null
},

@@ -293,3 +329,2 @@ search: {

}
/**

@@ -300,8 +335,8 @@ * Set the default parameters given the current service object.

*/
function setDefaultParams() {
this.params.expand = getDefaultQueryParams().expand;
if (this.features.includes(queryOne)) this.params.id = getDefaultQueryParams().id;
if (this.features.indexOf(queryOne) !== -1) this.params.id = getDefaultQueryParams().id;
if (this.features.indexOf(query) !== -1) {
if (this.features.includes(query)) {
this.params.pagination = getDefaultQueryParams().pagination;

@@ -311,3 +346,3 @@ this.params.query = getDefaultQueryParams().query;

if (this.features.indexOf(search) !== -1) {
if (this.features.includes(search)) {
this.params.pagination = getDefaultSearchParams().pagination;

@@ -317,5 +352,4 @@ this.params.search = getDefaultSearchParams().search;

if (this.features.indexOf(queryLocation) !== -1) this.params.location = getDefaultQueryParams().location;
if (this.features.indexOf(suggest) !== -1) this.params.searchKeywords = [];
if (this.features.includes(queryLocation)) this.params.location = getDefaultQueryParams().location;
if (this.features.includes(suggest)) this.params.searchKeywords = [];
}

@@ -326,3 +360,2 @@

};
/**

@@ -333,2 +366,4 @@ * Set the supplied parameters given the current service object.

*/
function setParams(params) {

@@ -338,24 +373,20 @@ var _this = this;

// verify params
var knownKeys = ['expand', 'id', 'key', 'customerId', 'cartId', 'sort', 'page', 'perPage', 'staged', 'priceCurrency', 'priceCountry', 'priceCustomerGroup', 'priceChannel', 'text', 'fuzzy', 'fuzzyLevel', 'markMatchingVariants', 'facet', 'filter', 'filterByQuery', 'filterByFacets', 'searchKeywords', 'where', 'whereOperator', 'version', 'country', 'currency', 'state', 'dataErasure'];
var knownKeys = ['expand', 'id', 'key', 'customerId', 'cartId', 'sort', 'page', 'perPage', 'staged', 'priceCurrency', 'priceCountry', 'priceCustomerGroup', 'priceChannel', 'text', 'fuzzy', 'fuzzyLevel', 'markMatchingVariants', 'facet', 'filter', 'filterByQuery', 'filterByFacets', 'searchKeywords', 'where', 'whereOperator', 'version', 'country', 'currency', 'state', 'dataErasure', 'withTotal'];
Object.keys(params).forEach(function (key) {
if (!(knownKeys.indexOf(key) !== -1)) throw new Error('Unknown key "' + key + '"');
});
if (!knownKeys.includes(key)) throw new Error("Unknown key \"".concat(key, "\""));
}); // query-expand
// query-expand
if (params.expand) params.expand.forEach(function (expansion) {
_this.expand(expansion);
});
}); // query-id
// query-id
if (hasKey(params, 'id')) this.byId(params.id);
if (hasKey(params, 'key')) this.byKey(params.key);
if (hasKey(params, 'customerId')) this.byCustomerId(params.customerId);
if (hasKey(params, 'cartId')) this.byCartId(params.cartId);
if (hasKey(params, 'cartId')) this.byCartId(params.cartId); // query-location
// query-location
if (hasKey(params, 'country')) this.byCountry(params.country);
if (hasKey(params, 'currency')) this.byCurrency(params.currency);
if (hasKey(params, 'state')) this.byState(params.state);
if (hasKey(params, 'state')) this.byState(params.state); // query-page
// query-page
if (params.sort) params.sort.forEach(function (sortDesc) {

@@ -365,5 +396,4 @@ _this.sort(sortDesc.by, sortDesc.direction === 'asc');

if (hasKey(params, 'page')) this.page(params.page);
if (hasKey(params, 'perPage')) this.perPage(params.perPage);
if (hasKey(params, 'perPage')) this.perPage(params.perPage); // query-projection
// query-projection
if (hasKey(params, 'staged')) this.staged(params.staged);

@@ -373,9 +403,10 @@ if (hasKey(params, 'priceCurrency')) this.priceCurrency(params.priceCurrency);

if (hasKey(params, 'priceCustomerGroup')) this.priceCustomerGroup(params.priceCustomerGroup);
if (hasKey(params, 'priceChannel')) this.priceChannel(params.priceChannel);
if (hasKey(params, 'priceChannel')) this.priceChannel(params.priceChannel); // query-search
// query-search
if (params.text) this.text(params.text.value, params.text.language);
if (params.fuzzy) this.fuzzy(); // boolean switch
if (hasKey(params, 'fuzzyLevel')) this.fuzzyLevel(params.fuzzyLevel);
if (params.markMatchingVariants) this.markMatchingVariants(); // boolean switch
if (params.facet) params.facet.forEach(function (facet) {

@@ -392,20 +423,18 @@ _this.facet(facet);

_this.filterByFacets(facet);
});
}); // query-suggest
// query-suggest
if (params.searchKeywords) params.searchKeywords.forEach(function (searchKeyword) {
_this.searchKeywords(searchKeyword.value, searchKeyword.language);
});
}); // query
// query
if (params.where) params.where.forEach(function (predicate) {
_this.where(predicate);
});
if (hasKey(params, 'whereOperator')) this.whereOperator(params.whereOperator);
if (hasKey(params, 'whereOperator')) this.whereOperator(params.whereOperator); // version
// version
if (hasKey(params, 'version')) this.withVersion(params.version);
if (hasKey(params, 'version')) this.withVersion(params.version); // dataErasure
// dataErasure
if (hasKey(params, 'dataErasure')) this.withFullDataErasure();
if (hasKey(params, 'dataErasure')) this.withFullDataErasure(); // withTotal
if (hasKey(params, 'withTotal')) this.withTotal(params.withTotal);
}

@@ -422,5 +451,3 @@

var forceEnumerable = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var clone = {};
Object.keys(object).forEach(function (key) {

@@ -432,3 +459,2 @@ Object.defineProperty(clone, key, {

});
return clone;

@@ -448,3 +474,2 @@ }

if (!params) throw new Error('Missing options object to build query string.');
var query = params.query,

@@ -465,21 +490,12 @@ pagination = params.pagination,

dataErasure = params.dataErasure;
var queryString = [];
if (customerId) queryString.push('customerId=' + customerId);
if (cartId) queryString.push('cartId=' + cartId);
if (typeof staged === 'boolean') queryString.push('staged=' + staged.toString());
if (priceCurrency) queryString.push('priceCurrency=' + priceCurrency);
if (priceCountry) queryString.push('priceCountry=' + priceCountry);
if (priceCustomerGroup) queryString.push('priceCustomerGroup=' + priceCustomerGroup);
if (priceChannel) queryString.push('priceChannel=' + priceChannel);
if (customerId) queryString.push("customerId=".concat(customerId));
if (cartId) queryString.push("cartId=".concat(cartId));
if (typeof staged === 'boolean') queryString.push("staged=".concat(staged.toString()));
if (priceCurrency) queryString.push("priceCurrency=".concat(priceCurrency));
if (priceCountry) queryString.push("priceCountry=".concat(priceCountry));
if (priceCustomerGroup) queryString.push("priceCustomerGroup=".concat(priceCustomerGroup));
if (priceChannel) queryString.push("priceChannel=".concat(priceChannel));
if (expand && expand.length) queryString = queryString.concat(expand.map(function (e) {
return 'expand=' + e;
return "expand=".concat(e);
}));

@@ -490,5 +506,4 @@

where = query.where;
var whereParams = where.join(encodeURIComponent(' ' + operator + ' '));
if (whereParams) queryString.push('where=' + whereParams);
var whereParams = where.join(encodeURIComponent(" ".concat(operator, " ")));
if (whereParams) queryString.push("where=".concat(whereParams));
}

@@ -500,6 +515,5 @@

state = location.state;
if (country) queryString.push('country=' + country);
if (currency) queryString.push('currency=' + currency);
if (state) queryString.push('state=' + state);
if (country) queryString.push("country=".concat(country));
if (currency) queryString.push("currency=".concat(currency));
if (state) queryString.push("state=".concat(state));
}

@@ -510,13 +524,16 @@

perPage = pagination.perPage,
sort = pagination.sort;
sort = pagination.sort,
withTotal = pagination.withTotal;
if (typeof perPage === 'number') queryString.push("limit=".concat(perPage));
if (typeof perPage === 'number') queryString.push('limit=' + perPage);
if (page) {
var limitParam = perPage || 20;
var offsetParam = limitParam * (page - 1);
queryString.push('offset=' + offsetParam);
queryString.push("offset=".concat(offsetParam));
}
if (sort && sort.length) queryString = queryString.concat(sort.map(function (s) {
return 'sort=' + s;
return "sort=".concat(s);
}));
if (typeof withTotal === 'boolean') queryString.push("withTotal=".concat(String(withTotal)));
}

@@ -533,20 +550,17 @@

filterByFacets = search.filterByFacets;
if (text) queryString.push('text.' + text.lang + '=' + text.value);
if (text) queryString.push("text.".concat(text.lang, "=").concat(text.value));
if (fuzzy) queryString.push('fuzzy=true');
if (fuzzyLevel) queryString.push('fuzzyLevel=' + fuzzyLevel);
queryString.push('markMatchingVariants=' + markMatchingVariants.toString());
if (fuzzyLevel) queryString.push("fuzzyLevel=".concat(fuzzyLevel));
queryString.push("markMatchingVariants=".concat(markMatchingVariants.toString()));
facet.forEach(function (f) {
return queryString.push('facet=' + f);
return queryString.push("facet=".concat(f));
});
filter.forEach(function (f) {
return queryString.push('filter=' + f);
return queryString.push("filter=".concat(f));
});
filterByQuery.forEach(function (f) {
return queryString.push('filter.query=' + f);
return queryString.push("filter.query=".concat(f));
});
filterByFacets.forEach(function (f) {
return queryString.push('filter.facets=' + f);
return queryString.push("filter.facets=".concat(f));
});

@@ -556,9 +570,6 @@ }

if (searchKeywords) searchKeywords.forEach(function (f) {
return queryString.push('searchKeywords.' + f.lang + '=' + f.value);
return queryString.push("searchKeywords.".concat(f.lang, "=").concat(f.value));
});
if (version) queryString.push('version=' + version);
if (version) queryString.push("version=".concat(version));
if (dataErasure) queryString.push(dataErasure);
return queryString.join('&');

@@ -568,2 +579,3 @@ }

/* */
/**

@@ -578,3 +590,2 @@ * Set the `version` number to the internal state of the service instance

*/
function withVersion(version) {

@@ -587,2 +598,3 @@ if (typeof version !== 'number') throw new Error('A resource version is missing or invalid');

/* */
/**

@@ -599,3 +611,2 @@ * Set the `dataErasure` option to the internal state of the service instance

*/
function withFullDataErasure() {

@@ -616,3 +627,2 @@ this.params.dataErasure = 'dataErasure=true';

if (!predicate) throw new Error('Required argument for `where` is missing');
var encodedPredicate = encodeURIComponent(predicate);

@@ -622,3 +632,2 @@ this.params.query.where.push(encodedPredicate);

}
/**

@@ -632,6 +641,6 @@ * Set the logical operator to combine multiple query predicates

*/
function whereOperator(operator) {
if (!operator) throw new Error('Required argument for `whereOperator` is missing');
if (!(operator === 'and' || operator === 'or')) throw new Error('Required argument for `whereOperator` is invalid, ' + 'allowed values are (`and`, `or`)');
this.params.query.operator = operator;

@@ -647,2 +656,3 @@ return this;

/* */
/**

@@ -659,9 +669,6 @@ * Set the given `id` to the internal state of the service instance.

if (this.params.customerId) throw new Error('A customerId for this resource has already been set. ' + 'You cannot use both `byId` and `byCustomerId`.');
if (this.params.cartId) throw new Error('A cartId for this resource has already been set. ' + 'You cannot use both `byId` and `byCartId`.');
this.params.id = id;
return this;
}
/**

@@ -674,10 +681,9 @@ * Set the given `key` to the internal state of the service instance.

*/
function byKey(key) {
if (!key) throw new Error('Required argument for `byKey` is missing');
if (this.params.id) throw new Error('An ID for this resource has already been set. ' + 'You cannot use both `byId` and `byKey`.');
this.params.key = key;
return this;
}
/**

@@ -691,10 +697,9 @@ * Set the given `id` to the `customerId`internal state of the service instance.

*/
function byCustomerId(custId) {
if (!custId) throw new Error('Required argument for `byCustomerId` is missing');
if (this.params.id) throw new Error('An ID for this resource has already been set. ' + 'You cannot use both `byId` and `byCustomerId`.');
this.params.customerId = custId;
return this;
}
/**

@@ -708,6 +713,6 @@ * Set the given `id` to the `cartId` internal state of the service instance.

*/
function byCartId(cartId) {
if (!cartId) throw new Error('Required argument for `byCartId` is missing');
if (this.params.id) throw new Error('An ID for this resource has already been set. ' + 'You cannot use both `byId` and `byCartId`.');
this.params.cartId = cartId;

@@ -734,7 +739,5 @@ return this;

if (!value) throw new Error('Required argument for `byCountry` is missing');
this.params.location.country = value;
return this;
}
/**

@@ -747,12 +750,10 @@ * Set the given `currency` param used for selection by currency.

*/
function byCurrency(value) {
if (!value) throw new Error('Required argument for `byCurrency` is missing');
if (!value) throw new Error('Required argument for `byCurrency` is missing'); // logic to verify country has been set
// logic to verify country has been set
if (!this.params.location.country) throw new Error('A `country` for this resource has not been set. ' + 'You must set the country in order to use the `byCurrency` method.');
this.params.location.currency = value;
return this;
}
/**

@@ -765,8 +766,7 @@ * Set the given `state` param used for selection by state.

*/
function byState(value) {
if (!value) throw new Error('Required argument for `byState` is missing');
if (!value) throw new Error('Required argument for `byState` is missing'); // logic to verify country has been set
// logic to verify country has been set
if (!this.params.location.country) throw new Error('A `country` for this resource has not been set. ' + 'You must set the country in order to use the `byState` method.');
this.params.location.state = value;

@@ -783,2 +783,3 @@ return this;

/* */
/**

@@ -798,6 +799,5 @@ * Set the

if (!value) throw new Error('Required argument for `expand` is missing');
var encodedPath = encodeURIComponent(value); // Note: this goes to base `params`, not `params.query`
// to be compatible with search.
var encodedPath = encodeURIComponent(value);
// Note: this goes to base `params`, not `params.query`
// to be compatible with search.
this.params.expand.push(encodedPath);

@@ -812,2 +812,3 @@ return this;

/* */
/**

@@ -828,11 +829,8 @@ * Set the sort expression for the query, if the related endpoint supports it.

var ascending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
if (!sortPath) throw new Error('Required argument for `sort` is missing');
var direction = ascending ? 'asc' : 'desc';
var encodedSort = encodeURIComponent(sortPath + ' ' + direction);
var encodedSort = encodeURIComponent("".concat(sortPath, " ").concat(direction));
this.params.pagination.sort.push(encodedSort);
return this;
}
/**

@@ -846,11 +844,9 @@ * Set the page number to be requested from the complete query result

*/
function page(value) {
if (typeof value !== 'number' && !value) throw new Error('Required argument for `page` is missing or invalid');
if (typeof value !== 'number' || value < 1) throw new Error('Required argument for `page` must be a number >= 1');
this.params.pagination.page = value;
return this;
}
/**

@@ -865,18 +861,32 @@ * Set the number of results to be returned from a query result

*/
function perPage(value) {
if (typeof value !== 'number' && !value) throw new Error('Required argument for `perPage` is missing or invalid');
if (typeof value !== 'number' || value < 0) throw new Error('Required argument for `perPage` must be a number >= 0');
this.params.pagination.perPage = value;
return this;
}
/**
* Set whether or not the total should be calculated (and included) in the result
* of a paginated query result.
*
* @param {boolean} value - indicating if the total should be included or not
*/
function withTotal() {
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (typeof value !== 'boolean') throw new Error('Required argument for `withTotal` is missing or invalid');
this.params.pagination.withTotal = value;
return this;
}
var queryPage = /*#__PURE__*/Object.freeze({
sort: sort,
page: page,
perPage: perPage
perPage: perPage,
withTotal: withTotal
});
/* */
/**

@@ -891,7 +901,5 @@ * Define whether to get the staged or current projection

var shouldFetchStaged = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
this.params.staged = shouldFetchStaged;
return this;
}
/**

@@ -904,2 +912,3 @@ * Define whether to set price Selection or not

*/
function priceCurrency(value) {

@@ -909,3 +918,2 @@ this.params.priceCurrency = value;

}
/**

@@ -919,2 +927,3 @@ * Define whether to set price Selection or not

*/
function priceCountry(value) {

@@ -924,3 +933,2 @@ this.params.priceCountry = value;

}
/**

@@ -934,2 +942,3 @@ * Define whether to set price Selection or not

*/
function priceCustomerGroup(value) {

@@ -939,3 +948,2 @@ this.params.priceCustomerGroup = value;

}
/**

@@ -949,2 +957,3 @@ * Define whether to set price Selection or not

*/
function priceChannel(value) {

@@ -964,2 +973,3 @@ this.params.priceChannel = value;

/* */
/**

@@ -982,4 +992,6 @@ * Define a Suggestion used for matching tokens for product projections,

if (!value || !lang) throw new Error('Required arguments for `searchKeywords` are missing');
this.params.searchKeywords.push({ lang: lang, value: encodeURIComponent(value) });
this.params.searchKeywords.push({
lang: lang,
value: encodeURIComponent(value)
});
return this;

@@ -993,2 +1005,3 @@ }

/* */
/**

@@ -1006,7 +1019,8 @@ * Set the given `text` param used for full-text search.

if (!value || !lang) throw new Error('Required arguments for `text` are missing');
this.params.search.text = { lang: lang, value: encodeURIComponent(value) };
this.params.search.text = {
lang: lang,
value: encodeURIComponent(value)
};
return this;
}
/**

@@ -1017,2 +1031,3 @@ * Define whether to enable the fuzzy search.

*/
function fuzzy() {

@@ -1022,3 +1037,2 @@ this.params.search.fuzzy = true;

}
/**

@@ -1031,2 +1045,3 @@ * Define the level of the fuzzy search

*/
function fuzzyLevel(value) {

@@ -1037,3 +1052,2 @@ if (!value) throw new Error('Required argument for `fuzzyLevel` is missing');

}
/**

@@ -1044,2 +1058,3 @@ * Define whether to enable markMatchingVariants

*/
function markMatchingVariants() {

@@ -1049,3 +1064,2 @@ this.params.search.markMatchingVariants = true;

}
/**

@@ -1059,5 +1073,5 @@ * Set the given `facet` filter used for calculating statistical counts.

*/
function facet(value) {
if (!value) throw new Error('Required argument for `facet` is missing');
var encodedFacet = encodeURIComponent(value);

@@ -1067,3 +1081,2 @@ this.params.search.facet.push(encodedFacet);

}
/**

@@ -1077,5 +1090,5 @@ * Set the given `filter` param used for filtering search results.

*/
function filter(value) {
if (!value) throw new Error('Required argument for `filter` is missing');
var encodedFilter = encodeURIComponent(value);

@@ -1085,3 +1098,2 @@ this.params.search.filter.push(encodedFilter);

}
/**

@@ -1095,5 +1107,5 @@ * Set the given `filter.query` param used for filtering search results.

*/
function filterByQuery(value) {
if (!value) throw new Error('Required argument for `filterByQuery` is missing');
var encodedFilter = encodeURIComponent(value);

@@ -1103,3 +1115,2 @@ this.params.search.filterByQuery.push(encodedFilter);

}
/**

@@ -1113,5 +1124,5 @@ * Set the given `filter.facets` param used for filtering search results.

*/
function filterByFacets(value) {
if (!value) throw new Error('Required argument for `filterByFacets` is missing');
var encodedFilter = encodeURIComponent(value);

@@ -1133,38 +1144,7 @@ this.params.search.filterByFacets.push(encodedFilter);

var defineProperty = function (obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
};
var _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;
};
/* */
var requiredDefinitionProps = ['type', 'endpoint', 'features'];
function getIdOrKey(params) {
if (params.id) return '/' + params.id;
if (params.key) return '/key=' + params.key;
if (params.id) return "/".concat(params.id);
if (params.key) return "/key=".concat(params.key);
return '';

@@ -1175,19 +1155,12 @@ }

var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
if (!definition) throw new Error('Cannot create a service without its definition.');
requiredDefinitionProps.forEach(function (key) {
if (!definition[key]) throw new Error('Definition is missing required parameter ' + key + '.');
if (!definition[key]) throw new Error("Definition is missing required parameter ".concat(key, "."));
});
if (!Array.isArray(definition.features) || !definition.features.length) throw new Error('Definition requires `features` to be a non empty array.');
if (!options) throw new Error('No project defined. Please enter a project key');
var type = definition.type,
endpoint = definition.endpoint,
features = definition.features;
return classify(_extends({
return classify(_objectSpread({
type: type,

@@ -1198,23 +1171,14 @@ features: features,

withFullDataErasure: withFullDataErasure
}, features.reduce(function (acc, feature) {
if (feature === query) return _extends({}, acc, query$1, queryPage);
if (feature === queryOne) return _extends({}, acc, queryId);
if (feature === queryLocation) return _extends({}, acc, queryLocation$1);
if (feature === queryExpand) return _extends({}, acc, queryExpand$1);
if (feature === search) return _extends({}, acc, querySearch, queryPage, {
if (feature === query) return _objectSpread({}, acc, query$1, queryPage);
if (feature === queryOne) return _objectSpread({}, acc, queryId);
if (feature === queryLocation) return _objectSpread({}, acc, queryLocation$1);
if (feature === queryExpand) return _objectSpread({}, acc, queryExpand$1);
if (feature === search) return _objectSpread({}, acc, querySearch, queryPage, {
params: getDefaultSearchParams()
});
if (feature === suggest) return _extends({}, acc, querySearch, queryPage, querySuggest);
if (feature === projection) return _extends({}, acc, queryProjection);
if (feature === suggest) return _objectSpread({}, acc, querySearch, queryPage, querySuggest);
if (feature === projection) return _objectSpread({}, acc, queryProjection);
return acc;
}, {}), {
// Call this method to get the built request URI

@@ -1224,19 +1188,14 @@ // Pass some options to further configure the URI:

build: function build() {
var uriOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { withProjectKey: true };
var uriOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
withProjectKey: true
};
var withProjectKey = uriOptions.withProjectKey;
var queryParams = buildQueryString(this.params);
var uri = (withProjectKey ? '/' + options : '') + endpoint +
// TODO this can lead to invalid URIs as getIdOrKey can return
var uri = (withProjectKey ? "/".concat(options) : '') + endpoint + // TODO this can lead to invalid URIs as getIdOrKey can return
// "/?customerId", so there can be multiple question marks,
// same for when `queryParams` and `version` are present
getIdOrKey(this.params) + (queryParams ? '?' + queryParams : '');
getIdOrKey(this.params) + (queryParams ? "?".concat(queryParams) : '');
setDefaultParams.call(this);
return uri;
},
// Call this method to parse an object as params

@@ -1250,5 +1209,2 @@ parse: function parse(params) {

/* */
// pass an options argument of type object containing
// the `projectkey` (string) and `customServices` (object)

@@ -1270,12 +1226,13 @@ // The projectKey property is required

// }
function createRequestBuilder() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var allServices = _extends({}, services, options.customServices);
var allServices = _objectSpread({}, services, options.customServices);
return Object.keys(allServices).reduce(
// a return type object is not allowed in flow due to a bug (https://github.com/facebook/flow/issues/5182)
return Object.keys(allServices).reduce( // a return type object is not allowed in flow due to a bug (https://github.com/facebook/flow/issues/5182)
/* eslint-disable-next-line */
function (acc, key) {
return _extends({}, acc, defineProperty({}, key, createService(allServices[key], options.projectKey)));
return _objectSpread({}, acc, _defineProperty({}, key, createService(allServices[key], options.projectKey)));
}, {});

@@ -1282,0 +1239,0 @@ }

@@ -7,2 +7,36 @@ (function (global, factory) {

function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
}
return target;
}
/**

@@ -18,6 +52,5 @@ * NOTE:

var create = 'create';
var update = 'update';
// `delete` is a reserved word in JavaScript
var update = 'update'; // `delete` is a reserved word in JavaScript
var del = 'delete';
/**

@@ -29,2 +62,3 @@ * NOTE:

*/
var query = 'query';

@@ -240,3 +274,2 @@ var queryOne = 'queryOne';

/* */
/**

@@ -247,2 +280,3 @@ * Return the default parameters for building a query string.

*/
function getDefaultQueryParams() {

@@ -255,3 +289,4 @@ return {

perPage: null,
sort: []
sort: [],
withTotal: null
},

@@ -270,3 +305,2 @@ location: {

}
/**

@@ -277,2 +311,3 @@ * Return the default parameters for building a query search string.

*/
function getDefaultSearchParams() {

@@ -285,3 +320,4 @@ return {

perPage: null,
sort: []
sort: [],
withTotal: null
},

@@ -300,3 +336,2 @@ search: {

}
/**

@@ -307,8 +342,8 @@ * Set the default parameters given the current service object.

*/
function setDefaultParams() {
this.params.expand = getDefaultQueryParams().expand;
if (this.features.includes(queryOne)) this.params.id = getDefaultQueryParams().id;
if (this.features.indexOf(queryOne) !== -1) this.params.id = getDefaultQueryParams().id;
if (this.features.indexOf(query) !== -1) {
if (this.features.includes(query)) {
this.params.pagination = getDefaultQueryParams().pagination;

@@ -318,3 +353,3 @@ this.params.query = getDefaultQueryParams().query;

if (this.features.indexOf(search) !== -1) {
if (this.features.includes(search)) {
this.params.pagination = getDefaultSearchParams().pagination;

@@ -324,5 +359,4 @@ this.params.search = getDefaultSearchParams().search;

if (this.features.indexOf(queryLocation) !== -1) this.params.location = getDefaultQueryParams().location;
if (this.features.indexOf(suggest) !== -1) this.params.searchKeywords = [];
if (this.features.includes(queryLocation)) this.params.location = getDefaultQueryParams().location;
if (this.features.includes(suggest)) this.params.searchKeywords = [];
}

@@ -333,3 +367,2 @@

};
/**

@@ -340,2 +373,4 @@ * Set the supplied parameters given the current service object.

*/
function setParams(params) {

@@ -345,24 +380,20 @@ var _this = this;

// verify params
var knownKeys = ['expand', 'id', 'key', 'customerId', 'cartId', 'sort', 'page', 'perPage', 'staged', 'priceCurrency', 'priceCountry', 'priceCustomerGroup', 'priceChannel', 'text', 'fuzzy', 'fuzzyLevel', 'markMatchingVariants', 'facet', 'filter', 'filterByQuery', 'filterByFacets', 'searchKeywords', 'where', 'whereOperator', 'version', 'country', 'currency', 'state', 'dataErasure'];
var knownKeys = ['expand', 'id', 'key', 'customerId', 'cartId', 'sort', 'page', 'perPage', 'staged', 'priceCurrency', 'priceCountry', 'priceCustomerGroup', 'priceChannel', 'text', 'fuzzy', 'fuzzyLevel', 'markMatchingVariants', 'facet', 'filter', 'filterByQuery', 'filterByFacets', 'searchKeywords', 'where', 'whereOperator', 'version', 'country', 'currency', 'state', 'dataErasure', 'withTotal'];
Object.keys(params).forEach(function (key) {
if (!(knownKeys.indexOf(key) !== -1)) throw new Error('Unknown key "' + key + '"');
});
if (!knownKeys.includes(key)) throw new Error("Unknown key \"".concat(key, "\""));
}); // query-expand
// query-expand
if (params.expand) params.expand.forEach(function (expansion) {
_this.expand(expansion);
});
}); // query-id
// query-id
if (hasKey(params, 'id')) this.byId(params.id);
if (hasKey(params, 'key')) this.byKey(params.key);
if (hasKey(params, 'customerId')) this.byCustomerId(params.customerId);
if (hasKey(params, 'cartId')) this.byCartId(params.cartId);
if (hasKey(params, 'cartId')) this.byCartId(params.cartId); // query-location
// query-location
if (hasKey(params, 'country')) this.byCountry(params.country);
if (hasKey(params, 'currency')) this.byCurrency(params.currency);
if (hasKey(params, 'state')) this.byState(params.state);
if (hasKey(params, 'state')) this.byState(params.state); // query-page
// query-page
if (params.sort) params.sort.forEach(function (sortDesc) {

@@ -372,5 +403,4 @@ _this.sort(sortDesc.by, sortDesc.direction === 'asc');

if (hasKey(params, 'page')) this.page(params.page);
if (hasKey(params, 'perPage')) this.perPage(params.perPage);
if (hasKey(params, 'perPage')) this.perPage(params.perPage); // query-projection
// query-projection
if (hasKey(params, 'staged')) this.staged(params.staged);

@@ -380,9 +410,10 @@ if (hasKey(params, 'priceCurrency')) this.priceCurrency(params.priceCurrency);

if (hasKey(params, 'priceCustomerGroup')) this.priceCustomerGroup(params.priceCustomerGroup);
if (hasKey(params, 'priceChannel')) this.priceChannel(params.priceChannel);
if (hasKey(params, 'priceChannel')) this.priceChannel(params.priceChannel); // query-search
// query-search
if (params.text) this.text(params.text.value, params.text.language);
if (params.fuzzy) this.fuzzy(); // boolean switch
if (hasKey(params, 'fuzzyLevel')) this.fuzzyLevel(params.fuzzyLevel);
if (params.markMatchingVariants) this.markMatchingVariants(); // boolean switch
if (params.facet) params.facet.forEach(function (facet) {

@@ -399,20 +430,18 @@ _this.facet(facet);

_this.filterByFacets(facet);
});
}); // query-suggest
// query-suggest
if (params.searchKeywords) params.searchKeywords.forEach(function (searchKeyword) {
_this.searchKeywords(searchKeyword.value, searchKeyword.language);
});
}); // query
// query
if (params.where) params.where.forEach(function (predicate) {
_this.where(predicate);
});
if (hasKey(params, 'whereOperator')) this.whereOperator(params.whereOperator);
if (hasKey(params, 'whereOperator')) this.whereOperator(params.whereOperator); // version
// version
if (hasKey(params, 'version')) this.withVersion(params.version);
if (hasKey(params, 'version')) this.withVersion(params.version); // dataErasure
// dataErasure
if (hasKey(params, 'dataErasure')) this.withFullDataErasure();
if (hasKey(params, 'dataErasure')) this.withFullDataErasure(); // withTotal
if (hasKey(params, 'withTotal')) this.withTotal(params.withTotal);
}

@@ -429,5 +458,3 @@

var forceEnumerable = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var clone = {};
Object.keys(object).forEach(function (key) {

@@ -439,3 +466,2 @@ Object.defineProperty(clone, key, {

});
return clone;

@@ -455,3 +481,2 @@ }

if (!params) throw new Error('Missing options object to build query string.');
var query = params.query,

@@ -472,21 +497,12 @@ pagination = params.pagination,

dataErasure = params.dataErasure;
var queryString = [];
if (customerId) queryString.push('customerId=' + customerId);
if (cartId) queryString.push('cartId=' + cartId);
if (typeof staged === 'boolean') queryString.push('staged=' + staged.toString());
if (priceCurrency) queryString.push('priceCurrency=' + priceCurrency);
if (priceCountry) queryString.push('priceCountry=' + priceCountry);
if (priceCustomerGroup) queryString.push('priceCustomerGroup=' + priceCustomerGroup);
if (priceChannel) queryString.push('priceChannel=' + priceChannel);
if (customerId) queryString.push("customerId=".concat(customerId));
if (cartId) queryString.push("cartId=".concat(cartId));
if (typeof staged === 'boolean') queryString.push("staged=".concat(staged.toString()));
if (priceCurrency) queryString.push("priceCurrency=".concat(priceCurrency));
if (priceCountry) queryString.push("priceCountry=".concat(priceCountry));
if (priceCustomerGroup) queryString.push("priceCustomerGroup=".concat(priceCustomerGroup));
if (priceChannel) queryString.push("priceChannel=".concat(priceChannel));
if (expand && expand.length) queryString = queryString.concat(expand.map(function (e) {
return 'expand=' + e;
return "expand=".concat(e);
}));

@@ -497,5 +513,4 @@

where = query.where;
var whereParams = where.join(encodeURIComponent(' ' + operator + ' '));
if (whereParams) queryString.push('where=' + whereParams);
var whereParams = where.join(encodeURIComponent(" ".concat(operator, " ")));
if (whereParams) queryString.push("where=".concat(whereParams));
}

@@ -507,6 +522,5 @@

state = location.state;
if (country) queryString.push('country=' + country);
if (currency) queryString.push('currency=' + currency);
if (state) queryString.push('state=' + state);
if (country) queryString.push("country=".concat(country));
if (currency) queryString.push("currency=".concat(currency));
if (state) queryString.push("state=".concat(state));
}

@@ -517,13 +531,16 @@

perPage = pagination.perPage,
sort = pagination.sort;
sort = pagination.sort,
withTotal = pagination.withTotal;
if (typeof perPage === 'number') queryString.push("limit=".concat(perPage));
if (typeof perPage === 'number') queryString.push('limit=' + perPage);
if (page) {
var limitParam = perPage || 20;
var offsetParam = limitParam * (page - 1);
queryString.push('offset=' + offsetParam);
queryString.push("offset=".concat(offsetParam));
}
if (sort && sort.length) queryString = queryString.concat(sort.map(function (s) {
return 'sort=' + s;
return "sort=".concat(s);
}));
if (typeof withTotal === 'boolean') queryString.push("withTotal=".concat(String(withTotal)));
}

@@ -540,20 +557,17 @@

filterByFacets = search.filterByFacets;
if (text) queryString.push('text.' + text.lang + '=' + text.value);
if (text) queryString.push("text.".concat(text.lang, "=").concat(text.value));
if (fuzzy) queryString.push('fuzzy=true');
if (fuzzyLevel) queryString.push('fuzzyLevel=' + fuzzyLevel);
queryString.push('markMatchingVariants=' + markMatchingVariants.toString());
if (fuzzyLevel) queryString.push("fuzzyLevel=".concat(fuzzyLevel));
queryString.push("markMatchingVariants=".concat(markMatchingVariants.toString()));
facet.forEach(function (f) {
return queryString.push('facet=' + f);
return queryString.push("facet=".concat(f));
});
filter.forEach(function (f) {
return queryString.push('filter=' + f);
return queryString.push("filter=".concat(f));
});
filterByQuery.forEach(function (f) {
return queryString.push('filter.query=' + f);
return queryString.push("filter.query=".concat(f));
});
filterByFacets.forEach(function (f) {
return queryString.push('filter.facets=' + f);
return queryString.push("filter.facets=".concat(f));
});

@@ -563,9 +577,6 @@ }

if (searchKeywords) searchKeywords.forEach(function (f) {
return queryString.push('searchKeywords.' + f.lang + '=' + f.value);
return queryString.push("searchKeywords.".concat(f.lang, "=").concat(f.value));
});
if (version) queryString.push('version=' + version);
if (version) queryString.push("version=".concat(version));
if (dataErasure) queryString.push(dataErasure);
return queryString.join('&');

@@ -575,2 +586,3 @@ }

/* */
/**

@@ -585,3 +597,2 @@ * Set the `version` number to the internal state of the service instance

*/
function withVersion(version) {

@@ -594,2 +605,3 @@ if (typeof version !== 'number') throw new Error('A resource version is missing or invalid');

/* */
/**

@@ -606,3 +618,2 @@ * Set the `dataErasure` option to the internal state of the service instance

*/
function withFullDataErasure() {

@@ -623,3 +634,2 @@ this.params.dataErasure = 'dataErasure=true';

if (!predicate) throw new Error('Required argument for `where` is missing');
var encodedPredicate = encodeURIComponent(predicate);

@@ -629,3 +639,2 @@ this.params.query.where.push(encodedPredicate);

}
/**

@@ -639,6 +648,6 @@ * Set the logical operator to combine multiple query predicates

*/
function whereOperator(operator) {
if (!operator) throw new Error('Required argument for `whereOperator` is missing');
if (!(operator === 'and' || operator === 'or')) throw new Error('Required argument for `whereOperator` is invalid, ' + 'allowed values are (`and`, `or`)');
this.params.query.operator = operator;

@@ -654,2 +663,3 @@ return this;

/* */
/**

@@ -666,9 +676,6 @@ * Set the given `id` to the internal state of the service instance.

if (this.params.customerId) throw new Error('A customerId for this resource has already been set. ' + 'You cannot use both `byId` and `byCustomerId`.');
if (this.params.cartId) throw new Error('A cartId for this resource has already been set. ' + 'You cannot use both `byId` and `byCartId`.');
this.params.id = id;
return this;
}
/**

@@ -681,10 +688,9 @@ * Set the given `key` to the internal state of the service instance.

*/
function byKey(key) {
if (!key) throw new Error('Required argument for `byKey` is missing');
if (this.params.id) throw new Error('An ID for this resource has already been set. ' + 'You cannot use both `byId` and `byKey`.');
this.params.key = key;
return this;
}
/**

@@ -698,10 +704,9 @@ * Set the given `id` to the `customerId`internal state of the service instance.

*/
function byCustomerId(custId) {
if (!custId) throw new Error('Required argument for `byCustomerId` is missing');
if (this.params.id) throw new Error('An ID for this resource has already been set. ' + 'You cannot use both `byId` and `byCustomerId`.');
this.params.customerId = custId;
return this;
}
/**

@@ -715,6 +720,6 @@ * Set the given `id` to the `cartId` internal state of the service instance.

*/
function byCartId(cartId) {
if (!cartId) throw new Error('Required argument for `byCartId` is missing');
if (this.params.id) throw new Error('An ID for this resource has already been set. ' + 'You cannot use both `byId` and `byCartId`.');
this.params.cartId = cartId;

@@ -741,7 +746,5 @@ return this;

if (!value) throw new Error('Required argument for `byCountry` is missing');
this.params.location.country = value;
return this;
}
/**

@@ -754,12 +757,10 @@ * Set the given `currency` param used for selection by currency.

*/
function byCurrency(value) {
if (!value) throw new Error('Required argument for `byCurrency` is missing');
if (!value) throw new Error('Required argument for `byCurrency` is missing'); // logic to verify country has been set
// logic to verify country has been set
if (!this.params.location.country) throw new Error('A `country` for this resource has not been set. ' + 'You must set the country in order to use the `byCurrency` method.');
this.params.location.currency = value;
return this;
}
/**

@@ -772,8 +773,7 @@ * Set the given `state` param used for selection by state.

*/
function byState(value) {
if (!value) throw new Error('Required argument for `byState` is missing');
if (!value) throw new Error('Required argument for `byState` is missing'); // logic to verify country has been set
// logic to verify country has been set
if (!this.params.location.country) throw new Error('A `country` for this resource has not been set. ' + 'You must set the country in order to use the `byState` method.');
this.params.location.state = value;

@@ -790,2 +790,3 @@ return this;

/* */
/**

@@ -805,6 +806,5 @@ * Set the

if (!value) throw new Error('Required argument for `expand` is missing');
var encodedPath = encodeURIComponent(value); // Note: this goes to base `params`, not `params.query`
// to be compatible with search.
var encodedPath = encodeURIComponent(value);
// Note: this goes to base `params`, not `params.query`
// to be compatible with search.
this.params.expand.push(encodedPath);

@@ -819,2 +819,3 @@ return this;

/* */
/**

@@ -835,11 +836,8 @@ * Set the sort expression for the query, if the related endpoint supports it.

var ascending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
if (!sortPath) throw new Error('Required argument for `sort` is missing');
var direction = ascending ? 'asc' : 'desc';
var encodedSort = encodeURIComponent(sortPath + ' ' + direction);
var encodedSort = encodeURIComponent("".concat(sortPath, " ").concat(direction));
this.params.pagination.sort.push(encodedSort);
return this;
}
/**

@@ -853,11 +851,9 @@ * Set the page number to be requested from the complete query result

*/
function page(value) {
if (typeof value !== 'number' && !value) throw new Error('Required argument for `page` is missing or invalid');
if (typeof value !== 'number' || value < 1) throw new Error('Required argument for `page` must be a number >= 1');
this.params.pagination.page = value;
return this;
}
/**

@@ -872,18 +868,32 @@ * Set the number of results to be returned from a query result

*/
function perPage(value) {
if (typeof value !== 'number' && !value) throw new Error('Required argument for `perPage` is missing or invalid');
if (typeof value !== 'number' || value < 0) throw new Error('Required argument for `perPage` must be a number >= 0');
this.params.pagination.perPage = value;
return this;
}
/**
* Set whether or not the total should be calculated (and included) in the result
* of a paginated query result.
*
* @param {boolean} value - indicating if the total should be included or not
*/
function withTotal() {
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (typeof value !== 'boolean') throw new Error('Required argument for `withTotal` is missing or invalid');
this.params.pagination.withTotal = value;
return this;
}
var queryPage = /*#__PURE__*/Object.freeze({
sort: sort,
page: page,
perPage: perPage
perPage: perPage,
withTotal: withTotal
});
/* */
/**

@@ -898,7 +908,5 @@ * Define whether to get the staged or current projection

var shouldFetchStaged = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
this.params.staged = shouldFetchStaged;
return this;
}
/**

@@ -911,2 +919,3 @@ * Define whether to set price Selection or not

*/
function priceCurrency(value) {

@@ -916,3 +925,2 @@ this.params.priceCurrency = value;

}
/**

@@ -926,2 +934,3 @@ * Define whether to set price Selection or not

*/
function priceCountry(value) {

@@ -931,3 +940,2 @@ this.params.priceCountry = value;

}
/**

@@ -941,2 +949,3 @@ * Define whether to set price Selection or not

*/
function priceCustomerGroup(value) {

@@ -946,3 +955,2 @@ this.params.priceCustomerGroup = value;

}
/**

@@ -956,2 +964,3 @@ * Define whether to set price Selection or not

*/
function priceChannel(value) {

@@ -971,2 +980,3 @@ this.params.priceChannel = value;

/* */
/**

@@ -989,4 +999,6 @@ * Define a Suggestion used for matching tokens for product projections,

if (!value || !lang) throw new Error('Required arguments for `searchKeywords` are missing');
this.params.searchKeywords.push({ lang: lang, value: encodeURIComponent(value) });
this.params.searchKeywords.push({
lang: lang,
value: encodeURIComponent(value)
});
return this;

@@ -1000,2 +1012,3 @@ }

/* */
/**

@@ -1013,7 +1026,8 @@ * Set the given `text` param used for full-text search.

if (!value || !lang) throw new Error('Required arguments for `text` are missing');
this.params.search.text = { lang: lang, value: encodeURIComponent(value) };
this.params.search.text = {
lang: lang,
value: encodeURIComponent(value)
};
return this;
}
/**

@@ -1024,2 +1038,3 @@ * Define whether to enable the fuzzy search.

*/
function fuzzy() {

@@ -1029,3 +1044,2 @@ this.params.search.fuzzy = true;

}
/**

@@ -1038,2 +1052,3 @@ * Define the level of the fuzzy search

*/
function fuzzyLevel(value) {

@@ -1044,3 +1059,2 @@ if (!value) throw new Error('Required argument for `fuzzyLevel` is missing');

}
/**

@@ -1051,2 +1065,3 @@ * Define whether to enable markMatchingVariants

*/
function markMatchingVariants() {

@@ -1056,3 +1071,2 @@ this.params.search.markMatchingVariants = true;

}
/**

@@ -1066,5 +1080,5 @@ * Set the given `facet` filter used for calculating statistical counts.

*/
function facet(value) {
if (!value) throw new Error('Required argument for `facet` is missing');
var encodedFacet = encodeURIComponent(value);

@@ -1074,3 +1088,2 @@ this.params.search.facet.push(encodedFacet);

}
/**

@@ -1084,5 +1097,5 @@ * Set the given `filter` param used for filtering search results.

*/
function filter(value) {
if (!value) throw new Error('Required argument for `filter` is missing');
var encodedFilter = encodeURIComponent(value);

@@ -1092,3 +1105,2 @@ this.params.search.filter.push(encodedFilter);

}
/**

@@ -1102,5 +1114,5 @@ * Set the given `filter.query` param used for filtering search results.

*/
function filterByQuery(value) {
if (!value) throw new Error('Required argument for `filterByQuery` is missing');
var encodedFilter = encodeURIComponent(value);

@@ -1110,3 +1122,2 @@ this.params.search.filterByQuery.push(encodedFilter);

}
/**

@@ -1120,5 +1131,5 @@ * Set the given `filter.facets` param used for filtering search results.

*/
function filterByFacets(value) {
if (!value) throw new Error('Required argument for `filterByFacets` is missing');
var encodedFilter = encodeURIComponent(value);

@@ -1140,38 +1151,7 @@ this.params.search.filterByFacets.push(encodedFilter);

var defineProperty = function (obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
};
var _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;
};
/* */
var requiredDefinitionProps = ['type', 'endpoint', 'features'];
function getIdOrKey(params) {
if (params.id) return '/' + params.id;
if (params.key) return '/key=' + params.key;
if (params.id) return "/".concat(params.id);
if (params.key) return "/key=".concat(params.key);
return '';

@@ -1182,19 +1162,12 @@ }

var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
if (!definition) throw new Error('Cannot create a service without its definition.');
requiredDefinitionProps.forEach(function (key) {
if (!definition[key]) throw new Error('Definition is missing required parameter ' + key + '.');
if (!definition[key]) throw new Error("Definition is missing required parameter ".concat(key, "."));
});
if (!Array.isArray(definition.features) || !definition.features.length) throw new Error('Definition requires `features` to be a non empty array.');
if (!options) throw new Error('No project defined. Please enter a project key');
var type = definition.type,
endpoint = definition.endpoint,
features = definition.features;
return classify(_extends({
return classify(_objectSpread({
type: type,

@@ -1205,23 +1178,14 @@ features: features,

withFullDataErasure: withFullDataErasure
}, features.reduce(function (acc, feature) {
if (feature === query) return _extends({}, acc, query$1, queryPage);
if (feature === queryOne) return _extends({}, acc, queryId);
if (feature === queryLocation) return _extends({}, acc, queryLocation$1);
if (feature === queryExpand) return _extends({}, acc, queryExpand$1);
if (feature === search) return _extends({}, acc, querySearch, queryPage, {
if (feature === query) return _objectSpread({}, acc, query$1, queryPage);
if (feature === queryOne) return _objectSpread({}, acc, queryId);
if (feature === queryLocation) return _objectSpread({}, acc, queryLocation$1);
if (feature === queryExpand) return _objectSpread({}, acc, queryExpand$1);
if (feature === search) return _objectSpread({}, acc, querySearch, queryPage, {
params: getDefaultSearchParams()
});
if (feature === suggest) return _extends({}, acc, querySearch, queryPage, querySuggest);
if (feature === projection) return _extends({}, acc, queryProjection);
if (feature === suggest) return _objectSpread({}, acc, querySearch, queryPage, querySuggest);
if (feature === projection) return _objectSpread({}, acc, queryProjection);
return acc;
}, {}), {
// Call this method to get the built request URI

@@ -1231,19 +1195,14 @@ // Pass some options to further configure the URI:

build: function build() {
var uriOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { withProjectKey: true };
var uriOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
withProjectKey: true
};
var withProjectKey = uriOptions.withProjectKey;
var queryParams = buildQueryString(this.params);
var uri = (withProjectKey ? '/' + options : '') + endpoint +
// TODO this can lead to invalid URIs as getIdOrKey can return
var uri = (withProjectKey ? "/".concat(options) : '') + endpoint + // TODO this can lead to invalid URIs as getIdOrKey can return
// "/?customerId", so there can be multiple question marks,
// same for when `queryParams` and `version` are present
getIdOrKey(this.params) + (queryParams ? '?' + queryParams : '');
getIdOrKey(this.params) + (queryParams ? "?".concat(queryParams) : '');
setDefaultParams.call(this);
return uri;
},
// Call this method to parse an object as params

@@ -1257,5 +1216,2 @@ parse: function parse(params) {

/* */
// pass an options argument of type object containing
// the `projectkey` (string) and `customServices` (object)

@@ -1277,12 +1233,13 @@ // The projectKey property is required

// }
function createRequestBuilder() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var allServices = _extends({}, services, options.customServices);
var allServices = _objectSpread({}, services, options.customServices);
return Object.keys(allServices).reduce(
// a return type object is not allowed in flow due to a bug (https://github.com/facebook/flow/issues/5182)
return Object.keys(allServices).reduce( // a return type object is not allowed in flow due to a bug (https://github.com/facebook/flow/issues/5182)
/* eslint-disable-next-line */
function (acc, key) {
return _extends({}, acc, defineProperty({}, key, createService(allServices[key], options.projectKey)));
return _objectSpread({}, acc, _defineProperty({}, key, createService(allServices[key], options.projectKey)));
}, {});

@@ -1289,0 +1246,0 @@ }

@@ -1,2 +0,2 @@

!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(e.CommercetoolsApiRequestBuilder={})}(this,function(e){"use strict";var r="create",t="update",s="delete",i="query",a="queryOne",u="queryExpand",c="queryLocation",p="search",h="projection",f="suggest",n=Object.freeze({create:r,update:t,del:s,query:i,queryOne:a,queryExpand:u,queryLocation:c,search:p,projection:h,suggest:f}),d={login:{type:"login",endpoint:"/login",features:[r]},cartDiscounts:{type:"cart-discounts",endpoint:"/cart-discounts",features:[r,t,s,i,a,u]},carts:{type:"carts",endpoint:"/carts",features:[r,t,s,i,a,u]},categories:{type:"categories",endpoint:"/categories",features:[r,t,s,i,a,u]},channels:{type:"channels",endpoint:"/channels",features:[r,t,s,i,a,u]},customerGroups:{type:"customer-groups",endpoint:"/customer-groups",features:[r,t,s,i,a,u]},customers:{type:"customers",endpoint:"/customers",features:[r,t,s,i,a,u]},customersPassword:{type:"customers-password",endpoint:"/customers/password",features:[r]},customersPasswordToken:{type:"customers-password-token",endpoint:"/customers/password-token",features:[r,a]},customersPasswordReset:{type:"customers-password-reset",endpoint:"/customers/password/reset",features:[r]},customersEmailVerificationToken:{type:"customers-email-verification-token",endpoint:"/customers/customers/email-token",features:[r,a]},customersEmailVerification:{type:"customers-email-verification",endpoint:"/customers/customers/email/confirm",features:[r]},customObjects:{type:"custom-objects",endpoint:"/custom-objects",features:[r,t,s,i,a]},discountCodes:{type:"discount-codes",endpoint:"/discount-codes",features:[r,t,s,i,a,u]},extensions:{type:"extensions",endpoint:"/extensions",features:[r,t,s,i,a,u]},inventory:{type:"inventory",endpoint:"/inventory",features:[r,t,s,i,a,u]},messages:{type:"messages",endpoint:"/messages",features:[i,a,u]},myCarts:{type:"my-carts",endpoint:"/me/carts",features:[r,t,s,i,a,u]},myOrders:{type:"my-orders",endpoint:"/me/orders",features:[r,t,s,i,a,u]},orders:{type:"orders",endpoint:"/orders",features:[r,t,s,i,a,u]},orderImport:{type:"orderImport",endpoint:"/orders/import",features:[r,i]},payments:{type:"payments",endpoint:"/payments",features:[r,t,s,i,a,u]},productDiscounts:{type:"product-discounts",endpoint:"/product-discounts",features:[r,t,s,i,a,u]},productProjections:{type:"product-projections",endpoint:"/product-projections",features:[i,a,u,h]},productProjectionsSearch:{type:"product-projections-search",endpoint:"/product-projections/search",features:[p,a,u,h]},productProjectionsSuggest:{type:"product-projections-suggest",endpoint:"/product-projections/suggest",features:[p,f,a,h]},products:{type:"products",endpoint:"/products",features:[r,t,s,i,a,u]},productTypes:{type:"product-types",endpoint:"/product-types",features:[r,t,s,i,a,u]},project:{type:"project",endpoint:"/",features:[t,i]},reviews:{type:"reviews",endpoint:"/reviews",features:[r,t,s,i,a,u]},shippingMethods:{type:"shipping-methods",endpoint:"/shipping-methods",features:[r,t,s,i,a,u,c]},shoppingLists:{type:"shopping-lists",endpoint:"/shopping-lists",features:[r,t,s,i,a,u]},states:{type:"states",endpoint:"/states",features:[r,t,s,i,a,u]},subscriptions:{type:"subscriptions",endpoint:"/subscriptions",features:[r,t,s,i,a,u]},taxCategories:{type:"tax-categories",endpoint:"/tax-categories",features:[r,t,s,i,a,u]},types:{type:"types",endpoint:"/types",features:[r,t,s,i,a,u]},zones:{type:"zones",endpoint:"/zones",features:[r,t,s,i,a,u]}};var y=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)};function m(e){if("number"!=typeof e)throw new Error("A resource version is missing or invalid");return this.params.version=e,this}function l(){return this.params.dataErasure="dataErasure=true",this}var g=Object.freeze({where:function(e){if(!e)throw new Error("Required argument for `where` is missing");var r=encodeURIComponent(e);return this.params.query.where.push(r),this},whereOperator:function(e){if(!e)throw new Error("Required argument for `whereOperator` is missing");if("and"!==e&&"or"!==e)throw new Error("Required argument for `whereOperator` is invalid, allowed values are (`and`, `or`)");return this.params.query.operator=e,this}});var w=Object.freeze({byId:function(e){if(!e)throw new Error("Required argument for `byId` is missing");if(this.params.key)throw new Error("A key for this resource has already been set. You cannot use both `byKey` and `byId`.");if(this.params.customerId)throw new Error("A customerId for this resource has already been set. You cannot use both `byId` and `byCustomerId`.");if(this.params.cartId)throw new Error("A cartId for this resource has already been set. You cannot use both `byId` and `byCartId`.");return this.params.id=e,this},byKey:function(e){if(!e)throw new Error("Required argument for `byKey` is missing");if(this.params.id)throw new Error("An ID for this resource has already been set. You cannot use both `byId` and `byKey`.");return this.params.key=e,this},byCustomerId:function(e){if(!e)throw new Error("Required argument for `byCustomerId` is missing");if(this.params.id)throw new Error("An ID for this resource has already been set. You cannot use both `byId` and `byCustomerId`.");return this.params.customerId=e,this},byCartId:function(e){if(!e)throw new Error("Required argument for `byCartId` is missing");if(this.params.id)throw new Error("An ID for this resource has already been set. You cannot use both `byId` and `byCartId`.");return this.params.cartId=e,this}});var b=Object.freeze({byCountry:function(e){if(!e)throw new Error("Required argument for `byCountry` is missing");return this.params.location.country=e,this},byCurrency:function(e){if(!e)throw new Error("Required argument for `byCurrency` is missing");if(!this.params.location.country)throw new Error("A `country` for this resource has not been set. You must set the country in order to use the `byCurrency` method.");return this.params.location.currency=e,this},byState:function(e){if(!e)throw new Error("Required argument for `byState` is missing");if(!this.params.location.country)throw new Error("A `country` for this resource has not been set. You must set the country in order to use the `byState` method.");return this.params.location.state=e,this}});var v=Object.freeze({expand:function(e){if(!e)throw new Error("Required argument for `expand` is missing");var r=encodeURIComponent(e);return this.params.expand.push(r),this}});var E=Object.freeze({sort:function(e){var r=!(1<arguments.length&&void 0!==arguments[1])||arguments[1];if(!e)throw new Error("Required argument for `sort` is missing");var t=encodeURIComponent(e+" "+(r?"asc":"desc"));return this.params.pagination.sort.push(t),this},page:function(e){if("number"!=typeof e&&!e)throw new Error("Required argument for `page` is missing or invalid");if("number"!=typeof e||e<1)throw new Error("Required argument for `page` must be a number >= 1");return this.params.pagination.page=e,this},perPage:function(e){if("number"!=typeof e&&!e)throw new Error("Required argument for `perPage` is missing or invalid");if("number"!=typeof e||e<0)throw new Error("Required argument for `perPage` must be a number >= 0");return this.params.pagination.perPage=e,this}});var C=Object.freeze({staged:function(){var e=0<arguments.length&&void 0!==arguments[0]&&arguments[0];return this.params.staged=e,this},priceCurrency:function(e){return this.params.priceCurrency=e,this},priceCountry:function(e){return this.params.priceCountry=e,this},priceCustomerGroup:function(e){return this.params.priceCustomerGroup=e,this},priceChannel:function(e){return this.params.priceChannel=e,this}});var z=Object.freeze({searchKeywords:function(e,r){if(!e||!r)throw new Error("Required arguments for `searchKeywords` are missing");return this.params.searchKeywords.push({lang:r,value:encodeURIComponent(e)}),this}});var I=Object.freeze({text:function(e,r){if(!e||!r)throw new Error("Required arguments for `text` are missing");return this.params.search.text={lang:r,value:encodeURIComponent(e)},this},fuzzy:function(){return this.params.search.fuzzy=!0,this},fuzzyLevel:function(e){if(!e)throw new Error("Required argument for `fuzzyLevel` is missing");return this.params.search.fuzzyLevel=e,this},markMatchingVariants:function(){return this.params.search.markMatchingVariants=!0,this},facet:function(e){if(!e)throw new Error("Required argument for `facet` is missing");var r=encodeURIComponent(e);return this.params.search.facet.push(r),this},filter:function(e){if(!e)throw new Error("Required argument for `filter` is missing");var r=encodeURIComponent(e);return this.params.search.filter.push(r),this},filterByQuery:function(e){if(!e)throw new Error("Required argument for `filterByQuery` is missing");var r=encodeURIComponent(e);return this.params.search.filterByQuery.push(r),this},filterByFacets:function(e){if(!e)throw new Error("Required argument for `filterByFacets` is missing");var r=encodeURIComponent(e);return this.params.search.filterByFacets.push(r),this}}),j=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s])}return e},q=["type","endpoint","features"];function x(r){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"";if(!r)throw new Error("Cannot create a service without its definition.");if(q.forEach(function(e){if(!r[e])throw new Error("Definition is missing required parameter "+e+".")}),!Array.isArray(r.features)||!r.features.length)throw new Error("Definition requires `features` to be a non empty array.");if(!n)throw new Error("No project defined. Please enter a project key");var e=r.type,o=r.endpoint,t=r.features;return function(r){var t=1<arguments.length&&void 0!==arguments[1]&&arguments[1],s={};return Object.keys(r).forEach(function(e){Object.defineProperty(s,e,{value:r[e],enumerable:!!t||"function"==typeof r[e]})}),s}(j({type:e,features:t,params:{id:null,expand:[],pagination:{page:null,perPage:null,sort:[]},location:{currency:"",country:"",state:""},query:{operator:"and",where:[]},searchKeywords:[]},withVersion:m,withFullDataErasure:l},t.reduce(function(e,r){return r===i?j({},e,g,E):r===a?j({},e,w):r===c?j({},e,b):r===u?j({},e,v):r===p?j({},e,I,E,{params:{expand:[],searchKeywords:[],pagination:{page:null,perPage:null,sort:[]},search:{facet:[],filter:[],filterByQuery:[],filterByFacets:[],fuzzy:!1,fuzzyLevel:0,markMatchingVariants:!1,text:null}}}):r===f?j({},e,I,E,z):r===h?j({},e,C):e},{}),{build:function(){var e,r=(0<arguments.length&&void 0!==arguments[0]?arguments[0]:{withProjectKey:!0}).withProjectKey,t=function(e){if(!e)throw new Error("Missing options object to build query string.");var r=e.query,t=e.pagination,s=e.search,n=e.expand,o=e.staged,i=e.priceCurrency,a=e.priceCountry,u=e.priceCustomerGroup,c=e.priceChannel,p=e.searchKeywords,h=e.version,f=e.customerId,d=e.cartId,y=e.location,m=e.dataErasure,l=[];if(f&&l.push("customerId="+f),d&&l.push("cartId="+d),"boolean"==typeof o&&l.push("staged="+o.toString()),i&&l.push("priceCurrency="+i),a&&l.push("priceCountry="+a),u&&l.push("priceCustomerGroup="+u),c&&l.push("priceChannel="+c),n&&n.length&&(l=l.concat(n.map(function(e){return"expand="+e}))),r){var g=r.operator,w=r.where.join(encodeURIComponent(" "+g+" "));w&&l.push("where="+w)}if(y){var b=y.country,v=y.currency,E=y.state;b&&l.push("country="+b),v&&l.push("currency="+v),E&&l.push("state="+E)}if(t){var C=t.page,z=t.perPage,I=t.sort;if("number"==typeof z&&l.push("limit="+z),C){var j=(z||20)*(C-1);l.push("offset="+j)}I&&I.length&&(l=l.concat(I.map(function(e){return"sort="+e})))}if(s){var q=s.text,x=s.fuzzy,O=s.fuzzyLevel,R=s.markMatchingVariants,k=s.facet,P=s.filter,B=s.filterByQuery,K=s.filterByFacets;q&&l.push("text."+q.lang+"="+q.value),x&&l.push("fuzzy=true"),O&&l.push("fuzzyLevel="+O),l.push("markMatchingVariants="+R.toString()),k.forEach(function(e){return l.push("facet="+e)}),P.forEach(function(e){return l.push("filter="+e)}),B.forEach(function(e){return l.push("filter.query="+e)}),K.forEach(function(e){return l.push("filter.facets="+e)})}return p&&p.forEach(function(e){return l.push("searchKeywords."+e.lang+"="+e.value)}),h&&l.push("version="+h),m&&l.push(m),l.join("&")}(this.params),s=(r?"/"+n:"")+o+((e=this.params).id?"/"+e.id:e.key?"/key="+e.key:"")+(t?"?"+t:"");return function(){this.params.expand=[],-1!==this.features.indexOf(a)&&(this.params.id=null),-1!==this.features.indexOf(i)&&(this.params.pagination={page:null,perPage:null,sort:[]},this.params.query={operator:"and",where:[]}),-1!==this.features.indexOf(p)&&(this.params.pagination={page:null,perPage:null,sort:[]},this.params.search={facet:[],filter:[],filterByQuery:[],filterByFacets:[],fuzzy:!1,fuzzyLevel:0,markMatchingVariants:!1,text:null}),-1!==this.features.indexOf(c)&&(this.params.location={currency:"",country:"",state:""}),-1!==this.features.indexOf(f)&&(this.params.searchKeywords=[])}.call(this),s},parse:function(e){return function(e){var r=this,t=["expand","id","key","customerId","cartId","sort","page","perPage","staged","priceCurrency","priceCountry","priceCustomerGroup","priceChannel","text","fuzzy","fuzzyLevel","markMatchingVariants","facet","filter","filterByQuery","filterByFacets","searchKeywords","where","whereOperator","version","country","currency","state","dataErasure"];Object.keys(e).forEach(function(e){if(-1===t.indexOf(e))throw new Error('Unknown key "'+e+'"')}),e.expand&&e.expand.forEach(function(e){r.expand(e)}),y(e,"id")&&this.byId(e.id),y(e,"key")&&this.byKey(e.key),y(e,"customerId")&&this.byCustomerId(e.customerId),y(e,"cartId")&&this.byCartId(e.cartId),y(e,"country")&&this.byCountry(e.country),y(e,"currency")&&this.byCurrency(e.currency),y(e,"state")&&this.byState(e.state),e.sort&&e.sort.forEach(function(e){r.sort(e.by,"asc"===e.direction)}),y(e,"page")&&this.page(e.page),y(e,"perPage")&&this.perPage(e.perPage),y(e,"staged")&&this.staged(e.staged),y(e,"priceCurrency")&&this.priceCurrency(e.priceCurrency),y(e,"priceCountry")&&this.priceCountry(e.priceCountry),y(e,"priceCustomerGroup")&&this.priceCustomerGroup(e.priceCustomerGroup),y(e,"priceChannel")&&this.priceChannel(e.priceChannel),e.text&&this.text(e.text.value,e.text.language),e.fuzzy&&this.fuzzy(),y(e,"fuzzyLevel")&&this.fuzzyLevel(e.fuzzyLevel),e.markMatchingVariants&&this.markMatchingVariants(),e.facet&&e.facet.forEach(function(e){r.facet(e)}),e.filter&&e.filter.forEach(function(e){r.filter(e)}),e.filterByQuery&&e.filterByQuery.forEach(function(e){r.filterByQuery(e)}),e.filterByFacets&&e.filterByFacets.forEach(function(e){r.filterByFacets(e)}),e.searchKeywords&&e.searchKeywords.forEach(function(e){r.searchKeywords(e.value,e.language)}),e.where&&e.where.forEach(function(e){r.where(e)}),y(e,"whereOperator")&&this.whereOperator(e.whereOperator),y(e,"version")&&this.withVersion(e.version),y(e,"dataErasure")&&this.withFullDataErasure()}.call(this,e),this}}))}e.features=n,e.createRequestBuilder=function(){var o=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},i=j({},d,o.customServices);return Object.keys(i).reduce(function(e,r){return j({},e,(t={},n=x(i[s=r],o.projectKey),s in t?Object.defineProperty(t,s,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[s]=n,t));var t,s,n},{})},Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(e.CommercetoolsApiRequestBuilder={})}(this,function(e){"use strict";function i(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function o(r){for(var e=1;e<arguments.length;e++){var t=null!=arguments[e]?arguments[e]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.forEach(function(e){i(r,e,t[e])})}return r}for(var r=require("./es6.array.iterator"),t=require("./_object-keys"),n=require("./_redefine"),s=require("./_global"),a=require("./_hide"),u=require("./_iterators"),c=require("./_wks"),p=c("iterator"),f=c("toStringTag"),h=u.Array,d={CSSRuleList:!0,CSSStyleDeclaration:!1,CSSValueList:!1,ClientRectList:!1,DOMRectList:!1,DOMStringList:!1,DOMTokenList:!0,DataTransferItemList:!1,FileList:!1,HTMLAllCollection:!1,HTMLCollection:!1,HTMLFormElement:!1,HTMLSelectElement:!1,MediaList:!0,MimeTypeArray:!1,NamedNodeMap:!1,NodeList:!0,PaintRequestList:!1,Plugin:!1,PluginArray:!1,SVGLengthList:!1,SVGNumberList:!1,SVGPathSegList:!1,SVGPointList:!1,SVGStringList:!1,SVGTransformList:!1,SourceBufferList:!1,StyleSheetList:!0,TextTrackCueList:!1,TextTrackList:!1,TouchList:!1},y=t(d),l=0;l<y.length;l++){var m,g=y[l],w=d[g],b=s[g],v=b&&b.prototype;if(v&&(v[p]||a(v,p,h),v[f]||a(v,f,g),u[g]=h,w))for(m in r)v[m]||n(v,m,r[m],!0)}var q=require("./_add-to-unscopables"),E=require("./_iter-step"),C=require("./_iterators"),_=require("./_to-iobject");module.exports=require("./_iter-define")(Array,"Array",function(e,r){this._t=_(e),this._i=0,this._k=r},function(){var e=this._t,r=this._k,t=this._i++;return!e||t>=e.length?(this._t=void 0,E(1)):E(0,"keys"==r?t:"values"==r?e[t]:[t,e[t]])},"values"),C.Arguments=C.Array,q("keys"),q("values"),q("entries");var j=require("./_to-object"),x=require("./_object-keys");require("./_object-sap")("keys",function(){return function(e){return x(j(e))}});var z=require("./_global"),I=require("./_inherit-if-required"),R=require("./_object-dp").f,k=require("./_object-gopn").f,L=require("./_is-regexp"),O=require("./_flags"),P=z.RegExp,S=P,T=P.prototype,B=/a/g,A=/a/g,M=new P(B)!==B;if(require("./_descriptors")&&(!M||require("./_fails")(function(){return A[require("./_wks")("match")]=!1,P(B)!=B||P(A)==A||"/a/i"!=P(B,"i")}))){P=function(e,r){var t=this instanceof P,n=L(e),i=void 0===r;return!t&&n&&e.constructor===P&&i?e:I(M?new S(n&&!i?e.source:e,r):S((n=e instanceof P)?e.source:e,n&&i?O.call(e):r),t?this:T,P)};for(var K=function(r){r in P||R(P,r,{configurable:!0,get:function(){return S[r]},set:function(e){S[r]=e}})},V=k(S),F=0;V.length>F;)K(V[F++]);(T.constructor=P).prototype=T,require("./_redefine")(z,"RegExp",P)}require("./_set-species")("RegExp"),require("./_fix-re-wks")("search",1,function(n,i,e){return[function(e){var r=n(this),t=null==e?void 0:e[i];return void 0!==t?t.call(e,r):new RegExp(e)[i](String(r))},e]});var D="create",G="update",U="delete",Q="query",Y="queryOne",N="queryExpand",H="queryLocation",J="search",W="projection",X="suggest",Z=Object.freeze({create:D,update:G,del:U,query:Q,queryOne:Y,queryExpand:N,queryLocation:H,search:J,projection:W,suggest:X}),$={login:{type:"login",endpoint:"/login",features:[D]},cartDiscounts:{type:"cart-discounts",endpoint:"/cart-discounts",features:[D,G,U,Q,Y,N]},carts:{type:"carts",endpoint:"/carts",features:[D,G,U,Q,Y,N]},categories:{type:"categories",endpoint:"/categories",features:[D,G,U,Q,Y,N]},channels:{type:"channels",endpoint:"/channels",features:[D,G,U,Q,Y,N]},customerGroups:{type:"customer-groups",endpoint:"/customer-groups",features:[D,G,U,Q,Y,N]},customers:{type:"customers",endpoint:"/customers",features:[D,G,U,Q,Y,N]},customersPassword:{type:"customers-password",endpoint:"/customers/password",features:[D]},customersPasswordToken:{type:"customers-password-token",endpoint:"/customers/password-token",features:[D,Y]},customersPasswordReset:{type:"customers-password-reset",endpoint:"/customers/password/reset",features:[D]},customersEmailVerificationToken:{type:"customers-email-verification-token",endpoint:"/customers/customers/email-token",features:[D,Y]},customersEmailVerification:{type:"customers-email-verification",endpoint:"/customers/customers/email/confirm",features:[D]},customObjects:{type:"custom-objects",endpoint:"/custom-objects",features:[D,G,U,Q,Y]},discountCodes:{type:"discount-codes",endpoint:"/discount-codes",features:[D,G,U,Q,Y,N]},extensions:{type:"extensions",endpoint:"/extensions",features:[D,G,U,Q,Y,N]},inventory:{type:"inventory",endpoint:"/inventory",features:[D,G,U,Q,Y,N]},messages:{type:"messages",endpoint:"/messages",features:[Q,Y,N]},myCarts:{type:"my-carts",endpoint:"/me/carts",features:[D,G,U,Q,Y,N]},myOrders:{type:"my-orders",endpoint:"/me/orders",features:[D,G,U,Q,Y,N]},orders:{type:"orders",endpoint:"/orders",features:[D,G,U,Q,Y,N]},orderImport:{type:"orderImport",endpoint:"/orders/import",features:[D,Q]},payments:{type:"payments",endpoint:"/payments",features:[D,G,U,Q,Y,N]},productDiscounts:{type:"product-discounts",endpoint:"/product-discounts",features:[D,G,U,Q,Y,N]},productProjections:{type:"product-projections",endpoint:"/product-projections",features:[Q,Y,N,W]},productProjectionsSearch:{type:"product-projections-search",endpoint:"/product-projections/search",features:[J,Y,N,W]},productProjectionsSuggest:{type:"product-projections-suggest",endpoint:"/product-projections/suggest",features:[J,X,Y,W]},products:{type:"products",endpoint:"/products",features:[D,G,U,Q,Y,N]},productTypes:{type:"product-types",endpoint:"/product-types",features:[D,G,U,Q,Y,N]},project:{type:"project",endpoint:"/",features:[G,Q]},reviews:{type:"reviews",endpoint:"/reviews",features:[D,G,U,Q,Y,N]},shippingMethods:{type:"shipping-methods",endpoint:"/shipping-methods",features:[D,G,U,Q,Y,N,H]},shoppingLists:{type:"shopping-lists",endpoint:"/shopping-lists",features:[D,G,U,Q,Y,N]},states:{type:"states",endpoint:"/states",features:[D,G,U,Q,Y,N]},subscriptions:{type:"subscriptions",endpoint:"/subscriptions",features:[D,G,U,Q,Y,N]},taxCategories:{type:"tax-categories",endpoint:"/tax-categories",features:[D,G,U,Q,Y,N]},types:{type:"types",endpoint:"/types",features:[D,G,U,Q,Y,N]},zones:{type:"zones",endpoint:"/zones",features:[D,G,U,Q,Y,N]}},ee=require("./_export"),re=require("./_a-function"),te=require("./_to-object"),ne=require("./_fails"),ie=[].sort,se=[1,2,3];ee(ee.P+ee.F*(ne(function(){se.sort(void 0)})||!ne(function(){se.sort(null)})||!require("./_strict-method")(ie)),"Array",{sort:function(e){return void 0===e?ie.call(te(this)):ie.call(te(this),re(e))}});var oe=require("./_export"),ae=require("./_array-includes")(!0);oe(oe.P,"Array",{includes:function(e){return ae(this,e,1<arguments.length?arguments[1]:void 0)}}),require("./_add-to-unscopables")("includes");var ue=require("./_export"),ce=require("./_string-context"),pe="includes";ue(ue.P+ue.F*require("./_fails-is-regexp")(pe),"String",{includes:function(e){return!!~ce(this,e,pe).indexOf(e,1<arguments.length?arguments[1]:void 0)}});var fe=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)};require("./_fix-re-wks")("match",1,function(n,i,e){return[function(e){var r=n(this),t=null==e?void 0:e[i];return void 0!==t?t.call(e,r):new RegExp(e)[i](String(r))},e]});var he=require("./_object-dp").f,de=Function.prototype,ye=/^\s*function ([^ (]*)/;"name"in de||require("./_descriptors")&&he(de,"name",{configurable:!0,get:function(){try{return(""+this).match(ye)[1]}catch(e){return""}}}),require("./_descriptors")&&"g"!=/./g.flags&&require("./_object-dp").f(RegExp.prototype,"flags",{configurable:!0,get:require("./_flags")}),require("./es6.regexp.flags");var le=require("./_an-object"),me=require("./_flags"),ge=require("./_descriptors"),we="toString",be=/./[we],ve=function(e){require("./_redefine")(RegExp.prototype,we,e,!0)};function qe(e){if("number"!=typeof e)throw new Error("A resource version is missing or invalid");return this.params.version=e,this}function Ee(){return this.params.dataErasure="dataErasure=true",this}require("./_fails")(function(){return"/a/b"!=be.call({source:"a",flags:"b"})})?ve(function(){var e=le(this);return"/".concat(e.source,"/","flags"in e?e.flags:!ge&&e instanceof RegExp?me.call(e):void 0)}):be.name!=we&&ve(function(){return be.call(this)});var Ce=Object.freeze({where:function(e){if(!e)throw new Error("Required argument for `where` is missing");var r=encodeURIComponent(e);return this.params.query.where.push(r),this},whereOperator:function(e){if(!e)throw new Error("Required argument for `whereOperator` is missing");if("and"!==e&&"or"!==e)throw new Error("Required argument for `whereOperator` is invalid, allowed values are (`and`, `or`)");return this.params.query.operator=e,this}});var _e=Object.freeze({byId:function(e){if(!e)throw new Error("Required argument for `byId` is missing");if(this.params.key)throw new Error("A key for this resource has already been set. You cannot use both `byKey` and `byId`.");if(this.params.customerId)throw new Error("A customerId for this resource has already been set. You cannot use both `byId` and `byCustomerId`.");if(this.params.cartId)throw new Error("A cartId for this resource has already been set. You cannot use both `byId` and `byCartId`.");return this.params.id=e,this},byKey:function(e){if(!e)throw new Error("Required argument for `byKey` is missing");if(this.params.id)throw new Error("An ID for this resource has already been set. You cannot use both `byId` and `byKey`.");return this.params.key=e,this},byCustomerId:function(e){if(!e)throw new Error("Required argument for `byCustomerId` is missing");if(this.params.id)throw new Error("An ID for this resource has already been set. You cannot use both `byId` and `byCustomerId`.");return this.params.customerId=e,this},byCartId:function(e){if(!e)throw new Error("Required argument for `byCartId` is missing");if(this.params.id)throw new Error("An ID for this resource has already been set. You cannot use both `byId` and `byCartId`.");return this.params.cartId=e,this}});var je=Object.freeze({byCountry:function(e){if(!e)throw new Error("Required argument for `byCountry` is missing");return this.params.location.country=e,this},byCurrency:function(e){if(!e)throw new Error("Required argument for `byCurrency` is missing");if(!this.params.location.country)throw new Error("A `country` for this resource has not been set. You must set the country in order to use the `byCurrency` method.");return this.params.location.currency=e,this},byState:function(e){if(!e)throw new Error("Required argument for `byState` is missing");if(!this.params.location.country)throw new Error("A `country` for this resource has not been set. You must set the country in order to use the `byState` method.");return this.params.location.state=e,this}});var xe=Object.freeze({expand:function(e){if(!e)throw new Error("Required argument for `expand` is missing");var r=encodeURIComponent(e);return this.params.expand.push(r),this}});var ze=Object.freeze({sort:function(e){var r=!(1<arguments.length&&void 0!==arguments[1])||arguments[1];if(!e)throw new Error("Required argument for `sort` is missing");var t=r?"asc":"desc",n=encodeURIComponent("".concat(e," ").concat(t));return this.params.pagination.sort.push(n),this},page:function(e){if("number"!=typeof e&&!e)throw new Error("Required argument for `page` is missing or invalid");if("number"!=typeof e||e<1)throw new Error("Required argument for `page` must be a number >= 1");return this.params.pagination.page=e,this},perPage:function(e){if("number"!=typeof e&&!e)throw new Error("Required argument for `perPage` is missing or invalid");if("number"!=typeof e||e<0)throw new Error("Required argument for `perPage` must be a number >= 0");return this.params.pagination.perPage=e,this},withTotal:function(){var e=!(0<arguments.length&&void 0!==arguments[0])||arguments[0];if("boolean"!=typeof e)throw new Error("Required argument for `withTotal` is missing or invalid");return this.params.pagination.withTotal=e,this}});var Ie=Object.freeze({staged:function(){var e=0<arguments.length&&void 0!==arguments[0]&&arguments[0];return this.params.staged=e,this},priceCurrency:function(e){return this.params.priceCurrency=e,this},priceCountry:function(e){return this.params.priceCountry=e,this},priceCustomerGroup:function(e){return this.params.priceCustomerGroup=e,this},priceChannel:function(e){return this.params.priceChannel=e,this}});var Re=Object.freeze({searchKeywords:function(e,r){if(!e||!r)throw new Error("Required arguments for `searchKeywords` are missing");return this.params.searchKeywords.push({lang:r,value:encodeURIComponent(e)}),this}});var ke=Object.freeze({text:function(e,r){if(!e||!r)throw new Error("Required arguments for `text` are missing");return this.params.search.text={lang:r,value:encodeURIComponent(e)},this},fuzzy:function(){return this.params.search.fuzzy=!0,this},fuzzyLevel:function(e){if(!e)throw new Error("Required argument for `fuzzyLevel` is missing");return this.params.search.fuzzyLevel=e,this},markMatchingVariants:function(){return this.params.search.markMatchingVariants=!0,this},facet:function(e){if(!e)throw new Error("Required argument for `facet` is missing");var r=encodeURIComponent(e);return this.params.search.facet.push(r),this},filter:function(e){if(!e)throw new Error("Required argument for `filter` is missing");var r=encodeURIComponent(e);return this.params.search.filter.push(r),this},filterByQuery:function(e){if(!e)throw new Error("Required argument for `filterByQuery` is missing");var r=encodeURIComponent(e);return this.params.search.filterByQuery.push(r),this},filterByFacets:function(e){if(!e)throw new Error("Required argument for `filterByFacets` is missing");var r=encodeURIComponent(e);return this.params.search.filterByFacets.push(r),this}}),Le=["type","endpoint","features"];function Oe(r){var i=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"";if(!r)throw new Error("Cannot create a service without its definition.");if(Le.forEach(function(e){if(!r[e])throw new Error("Definition is missing required parameter ".concat(e,"."))}),!Array.isArray(r.features)||!r.features.length)throw new Error("Definition requires `features` to be a non empty array.");if(!i)throw new Error("No project defined. Please enter a project key");var e=r.type,s=r.endpoint,t=r.features;return function(r){var t=1<arguments.length&&void 0!==arguments[1]&&arguments[1],n={};return Object.keys(r).forEach(function(e){Object.defineProperty(n,e,{value:r[e],enumerable:!!t||"function"==typeof r[e]})}),n}(o({type:e,features:t,params:{id:null,expand:[],pagination:{page:null,perPage:null,sort:[],withTotal:null},location:{currency:"",country:"",state:""},query:{operator:"and",where:[]},searchKeywords:[]},withVersion:qe,withFullDataErasure:Ee},t.reduce(function(e,r){return r===Q?o({},e,Ce,ze):r===Y?o({},e,_e):r===H?o({},e,je):r===N?o({},e,xe):r===J?o({},e,ke,ze,{params:{expand:[],searchKeywords:[],pagination:{page:null,perPage:null,sort:[],withTotal:null},search:{facet:[],filter:[],filterByQuery:[],filterByFacets:[],fuzzy:!1,fuzzyLevel:0,markMatchingVariants:!1,text:null}}}):r===X?o({},e,ke,ze,Re):r===W?o({},e,Ie):e},{}),{build:function(){var e,r=(0<arguments.length&&void 0!==arguments[0]?arguments[0]:{withProjectKey:!0}).withProjectKey,t=function(e){if(!e)throw new Error("Missing options object to build query string.");var r=e.query,t=e.pagination,n=e.search,i=e.expand,s=e.staged,o=e.priceCurrency,a=e.priceCountry,u=e.priceCustomerGroup,c=e.priceChannel,p=e.searchKeywords,f=e.version,h=e.customerId,d=e.cartId,y=e.location,l=e.dataErasure,m=[];if(h&&m.push("customerId=".concat(h)),d&&m.push("cartId=".concat(d)),"boolean"==typeof s&&m.push("staged=".concat(s.toString())),o&&m.push("priceCurrency=".concat(o)),a&&m.push("priceCountry=".concat(a)),u&&m.push("priceCustomerGroup=".concat(u)),c&&m.push("priceChannel=".concat(c)),i&&i.length&&(m=m.concat(i.map(function(e){return"expand=".concat(e)}))),r){var g=r.operator,w=r.where.join(encodeURIComponent(" ".concat(g," ")));w&&m.push("where=".concat(w))}if(y){var b=y.country,v=y.currency,q=y.state;b&&m.push("country=".concat(b)),v&&m.push("currency=".concat(v)),q&&m.push("state=".concat(q))}if(t){var E=t.page,C=t.perPage,_=t.sort,j=t.withTotal;if("number"==typeof C&&m.push("limit=".concat(C)),E){var x=(C||20)*(E-1);m.push("offset=".concat(x))}_&&_.length&&(m=m.concat(_.map(function(e){return"sort=".concat(e)}))),"boolean"==typeof j&&m.push("withTotal=".concat(String(j)))}if(n){var z=n.text,I=n.fuzzy,R=n.fuzzyLevel,k=n.markMatchingVariants,L=n.facet,O=n.filter,P=n.filterByQuery,S=n.filterByFacets;z&&m.push("text.".concat(z.lang,"=").concat(z.value)),I&&m.push("fuzzy=true"),R&&m.push("fuzzyLevel=".concat(R)),m.push("markMatchingVariants=".concat(k.toString())),L.forEach(function(e){return m.push("facet=".concat(e))}),O.forEach(function(e){return m.push("filter=".concat(e))}),P.forEach(function(e){return m.push("filter.query=".concat(e))}),S.forEach(function(e){return m.push("filter.facets=".concat(e))})}return p&&p.forEach(function(e){return m.push("searchKeywords.".concat(e.lang,"=").concat(e.value))}),f&&m.push("version=".concat(f)),l&&m.push(l),m.join("&")}(this.params),n=(r?"/".concat(i):"")+s+((e=this.params).id?"/".concat(e.id):e.key?"/key=".concat(e.key):"")+(t?"?".concat(t):"");return function(){this.params.expand=[],this.features.includes(Y)&&(this.params.id=null),this.features.includes(Q)&&(this.params.pagination={page:null,perPage:null,sort:[],withTotal:null},this.params.query={operator:"and",where:[]}),this.features.includes(J)&&(this.params.pagination={page:null,perPage:null,sort:[],withTotal:null},this.params.search={facet:[],filter:[],filterByQuery:[],filterByFacets:[],fuzzy:!1,fuzzyLevel:0,markMatchingVariants:!1,text:null}),this.features.includes(H)&&(this.params.location={currency:"",country:"",state:""}),this.features.includes(X)&&(this.params.searchKeywords=[])}.call(this),n},parse:function(e){return function(e){var r=this,t=["expand","id","key","customerId","cartId","sort","page","perPage","staged","priceCurrency","priceCountry","priceCustomerGroup","priceChannel","text","fuzzy","fuzzyLevel","markMatchingVariants","facet","filter","filterByQuery","filterByFacets","searchKeywords","where","whereOperator","version","country","currency","state","dataErasure","withTotal"];Object.keys(e).forEach(function(e){if(!t.includes(e))throw new Error('Unknown key "'.concat(e,'"'))}),e.expand&&e.expand.forEach(function(e){r.expand(e)}),fe(e,"id")&&this.byId(e.id),fe(e,"key")&&this.byKey(e.key),fe(e,"customerId")&&this.byCustomerId(e.customerId),fe(e,"cartId")&&this.byCartId(e.cartId),fe(e,"country")&&this.byCountry(e.country),fe(e,"currency")&&this.byCurrency(e.currency),fe(e,"state")&&this.byState(e.state),e.sort&&e.sort.forEach(function(e){r.sort(e.by,"asc"===e.direction)}),fe(e,"page")&&this.page(e.page),fe(e,"perPage")&&this.perPage(e.perPage),fe(e,"staged")&&this.staged(e.staged),fe(e,"priceCurrency")&&this.priceCurrency(e.priceCurrency),fe(e,"priceCountry")&&this.priceCountry(e.priceCountry),fe(e,"priceCustomerGroup")&&this.priceCustomerGroup(e.priceCustomerGroup),fe(e,"priceChannel")&&this.priceChannel(e.priceChannel),e.text&&this.text(e.text.value,e.text.language),e.fuzzy&&this.fuzzy(),fe(e,"fuzzyLevel")&&this.fuzzyLevel(e.fuzzyLevel),e.markMatchingVariants&&this.markMatchingVariants(),e.facet&&e.facet.forEach(function(e){r.facet(e)}),e.filter&&e.filter.forEach(function(e){r.filter(e)}),e.filterByQuery&&e.filterByQuery.forEach(function(e){r.filterByQuery(e)}),e.filterByFacets&&e.filterByFacets.forEach(function(e){r.filterByFacets(e)}),e.searchKeywords&&e.searchKeywords.forEach(function(e){r.searchKeywords(e.value,e.language)}),e.where&&e.where.forEach(function(e){r.where(e)}),fe(e,"whereOperator")&&this.whereOperator(e.whereOperator),fe(e,"version")&&this.withVersion(e.version),fe(e,"dataErasure")&&this.withFullDataErasure(),fe(e,"withTotal")&&this.withTotal(e.withTotal)}.call(this,e),this}}))}e.features=Z,e.createRequestBuilder=function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n=o({},$,t.customServices);return Object.keys(n).reduce(function(e,r){return o({},e,i({},r,Oe(n[r],t.projectKey)))},{})},Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=commercetools-api-request-builder.umd.min.js.map

@@ -7,3 +7,3 @@ {

"name": "@commercetools/api-request-builder",
"version": "4.0.2",
"version": "4.1.0",
"description": "Helper functions to construct API requests URI for the commercetools platform in a declarative way.",

@@ -38,3 +38,4 @@ "keywords": [

"build:cjs": "cross-env NODE_ENV=rollup rollup -c ../../rollup.config.js -f cjs -n CommercetoolsApiRequestBuilder -i src/index.js -o dist/commercetools-api-request-builder.cjs.js"
}
},
"gitHead": "5846dc1df83dead39c0b4f4c1db2921e3e0f0dad"
}

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc