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
8
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 3.4.1 to 3.5.0

90

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

@@ -8,2 +8,3 @@ 'use strict';

var queryExpand = 'queryExpand';
var queryLocation = 'queryLocation';
var search = 'search';

@@ -17,2 +18,3 @@ var projection = 'projection';

queryExpand: queryExpand,
queryLocation: queryLocation,
search: search,

@@ -142,3 +144,3 @@ projection: projection,

endpoint: '/shipping-methods',
features: [query, queryOne, queryExpand]
features: [query, queryOne, queryExpand, queryLocation]
},

@@ -193,2 +195,7 @@ shoppingLists: {

},
location: {
currency: '',
country: '',
state: ''
},
query: {

@@ -251,2 +258,4 @@ operator: 'and',

if (this.features.indexOf(queryLocation) !== -1) this.params.location = getDefaultQueryParams().location;
if (this.features.indexOf(projection) !== -1) this.params.staged = true;

@@ -270,3 +279,3 @@

// 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'];
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'];
Object.keys(params).forEach(function (key) {

@@ -287,2 +296,7 @@ if (!(knownKeys.indexOf(key) !== -1)) throw new Error('Unknown key "' + key + '"');

// 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);
// query-page

@@ -381,3 +395,4 @@ if (params.sort) params.sort.forEach(function (sortDesc) {

customerId = params.customerId,
cartId = params.cartId;
cartId = params.cartId,
location = params.location;

@@ -412,2 +427,12 @@ var queryString = [];

if (location) {
var country = location.country,
currency = location.currency,
state = location.state;
if (country) queryString.push('country=' + country);
if (currency) queryString.push('currency=' + currency);
if (state) queryString.push('state=' + state);
}
if (pagination) {

@@ -596,3 +621,58 @@ var page = pagination.page,

/* */
/**
* Set the given `country` param used for selection by country
*
* @param {string} value - A two-digit country code as per ISO 3166-1 alpha-2
* @return {Object} The instance of the service, can be chained.
*/
function byCountry(value) {
if (!value) throw new Error('Required argument for `byCountry` is missing');
this.params.location.country = value;
return this;
}
/**
* Set the given `currency` param used for selection by currency.
*
* @param {string} value - The currency code compliant to ISO 4217
* Can only be used with country parameter
* @return {Object} The instance of the service, can be chained.
*/
function byCurrency(value) {
if (!value) throw new Error('Required argument for `byCurrency` is missing');
// 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;
}
/**
* Set the given `state` param used for selection by state.
*
* @param {string} value - A string representing State name
* Can only be used with country parameter
* @return {Object} The instance of the service, can be chained.
*/
function byState(value) {
if (!value) throw new Error('Required argument for `byState` is missing');
// 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;
return this;
}
var queryLocation$1 = Object.freeze({
byCountry: byCountry,
byCurrency: byCurrency,
byState: byState
});
/* */
/**
* Set the

@@ -982,2 +1062,4 @@ * [ExpansionPath](http://dev.sphere.io/http-api.html#reference-expansion)

if (feature === queryLocation) return _extends({}, acc, queryLocation$1);
if (feature === queryExpand) return _extends({}, acc, queryExpand$1);

@@ -1008,3 +1090,3 @@

// TODO this can lead to invalid URIs as getIdOrKey can return
// "/?customerId", so there can be multiple questionmarks,
// "/?customerId", so there can be multiple question marks,
// same for when `queryParams` and `version` are present

@@ -1011,0 +1093,0 @@ getIdOrKey(this.params) + (queryParams ? '?' + queryParams : '');

var query = 'query';
var queryOne = 'queryOne';
var queryExpand = 'queryExpand';
var queryLocation = 'queryLocation';
var search = 'search';

@@ -12,2 +13,3 @@ var projection = 'projection';

queryExpand: queryExpand,
queryLocation: queryLocation,
search: search,

@@ -137,3 +139,3 @@ projection: projection,

endpoint: '/shipping-methods',
features: [query, queryOne, queryExpand]
features: [query, queryOne, queryExpand, queryLocation]
},

@@ -188,2 +190,7 @@ shoppingLists: {

},
location: {
currency: '',
country: '',
state: ''
},
query: {

@@ -246,2 +253,4 @@ operator: 'and',

if (this.features.indexOf(queryLocation) !== -1) this.params.location = getDefaultQueryParams().location;
if (this.features.indexOf(projection) !== -1) this.params.staged = true;

@@ -265,3 +274,3 @@

// 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'];
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'];
Object.keys(params).forEach(function (key) {

@@ -282,2 +291,7 @@ if (!(knownKeys.indexOf(key) !== -1)) throw new Error('Unknown key "' + key + '"');

// 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);
// query-page

@@ -376,3 +390,4 @@ if (params.sort) params.sort.forEach(function (sortDesc) {

customerId = params.customerId,
cartId = params.cartId;
cartId = params.cartId,
location = params.location;

@@ -407,2 +422,12 @@ var queryString = [];

if (location) {
var country = location.country,
currency = location.currency,
state = location.state;
if (country) queryString.push('country=' + country);
if (currency) queryString.push('currency=' + currency);
if (state) queryString.push('state=' + state);
}
if (pagination) {

@@ -591,3 +616,58 @@ var page = pagination.page,

/* */
/**
* Set the given `country` param used for selection by country
*
* @param {string} value - A two-digit country code as per ISO 3166-1 alpha-2
* @return {Object} The instance of the service, can be chained.
*/
function byCountry(value) {
if (!value) throw new Error('Required argument for `byCountry` is missing');
this.params.location.country = value;
return this;
}
/**
* Set the given `currency` param used for selection by currency.
*
* @param {string} value - The currency code compliant to ISO 4217
* Can only be used with country parameter
* @return {Object} The instance of the service, can be chained.
*/
function byCurrency(value) {
if (!value) throw new Error('Required argument for `byCurrency` is missing');
// 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;
}
/**
* Set the given `state` param used for selection by state.
*
* @param {string} value - A string representing State name
* Can only be used with country parameter
* @return {Object} The instance of the service, can be chained.
*/
function byState(value) {
if (!value) throw new Error('Required argument for `byState` is missing');
// 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;
return this;
}
var queryLocation$1 = Object.freeze({
byCountry: byCountry,
byCurrency: byCurrency,
byState: byState
});
/* */
/**
* Set the

@@ -977,2 +1057,4 @@ * [ExpansionPath](http://dev.sphere.io/http-api.html#reference-expansion)

if (feature === queryLocation) return _extends({}, acc, queryLocation$1);
if (feature === queryExpand) return _extends({}, acc, queryExpand$1);

@@ -1003,3 +1085,3 @@

// TODO this can lead to invalid URIs as getIdOrKey can return
// "/?customerId", so there can be multiple questionmarks,
// "/?customerId", so there can be multiple question marks,
// same for when `queryParams` and `version` are present

@@ -1006,0 +1088,0 @@ getIdOrKey(this.params) + (queryParams ? '?' + queryParams : '');

@@ -10,2 +10,3 @@ (function (global, factory) {

var queryExpand = 'queryExpand';
var queryLocation = 'queryLocation';
var search = 'search';

@@ -19,2 +20,3 @@ var projection = 'projection';

queryExpand: queryExpand,
queryLocation: queryLocation,
search: search,

@@ -144,3 +146,3 @@ projection: projection,

endpoint: '/shipping-methods',
features: [query, queryOne, queryExpand]
features: [query, queryOne, queryExpand, queryLocation]
},

@@ -195,2 +197,7 @@ shoppingLists: {

},
location: {
currency: '',
country: '',
state: ''
},
query: {

@@ -253,2 +260,4 @@ operator: 'and',

if (this.features.indexOf(queryLocation) !== -1) this.params.location = getDefaultQueryParams().location;
if (this.features.indexOf(projection) !== -1) this.params.staged = true;

@@ -272,3 +281,3 @@

// 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'];
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'];
Object.keys(params).forEach(function (key) {

@@ -289,2 +298,7 @@ if (!(knownKeys.indexOf(key) !== -1)) throw new Error('Unknown key "' + key + '"');

// 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);
// query-page

@@ -383,3 +397,4 @@ if (params.sort) params.sort.forEach(function (sortDesc) {

customerId = params.customerId,
cartId = params.cartId;
cartId = params.cartId,
location = params.location;

@@ -414,2 +429,12 @@ var queryString = [];

if (location) {
var country = location.country,
currency = location.currency,
state = location.state;
if (country) queryString.push('country=' + country);
if (currency) queryString.push('currency=' + currency);
if (state) queryString.push('state=' + state);
}
if (pagination) {

@@ -598,3 +623,58 @@ var page = pagination.page,

/* */
/**
* Set the given `country` param used for selection by country
*
* @param {string} value - A two-digit country code as per ISO 3166-1 alpha-2
* @return {Object} The instance of the service, can be chained.
*/
function byCountry(value) {
if (!value) throw new Error('Required argument for `byCountry` is missing');
this.params.location.country = value;
return this;
}
/**
* Set the given `currency` param used for selection by currency.
*
* @param {string} value - The currency code compliant to ISO 4217
* Can only be used with country parameter
* @return {Object} The instance of the service, can be chained.
*/
function byCurrency(value) {
if (!value) throw new Error('Required argument for `byCurrency` is missing');
// 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;
}
/**
* Set the given `state` param used for selection by state.
*
* @param {string} value - A string representing State name
* Can only be used with country parameter
* @return {Object} The instance of the service, can be chained.
*/
function byState(value) {
if (!value) throw new Error('Required argument for `byState` is missing');
// 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;
return this;
}
var queryLocation$1 = Object.freeze({
byCountry: byCountry,
byCurrency: byCurrency,
byState: byState
});
/* */
/**
* Set the

@@ -984,2 +1064,4 @@ * [ExpansionPath](http://dev.sphere.io/http-api.html#reference-expansion)

if (feature === queryLocation) return _extends({}, acc, queryLocation$1);
if (feature === queryExpand) return _extends({}, acc, queryExpand$1);

@@ -1010,3 +1092,3 @@

// TODO this can lead to invalid URIs as getIdOrKey can return
// "/?customerId", so there can be multiple questionmarks,
// "/?customerId", so there can be multiple question marks,
// same for when `queryParams` and `version` are present

@@ -1013,0 +1095,0 @@ getIdOrKey(this.params) + (queryParams ? '?' + queryParams : '');

2

dist/commercetools-api-request-builder.umd.min.js

@@ -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";function r(e){if("number"!=typeof e)throw new Error("A resource version is missing or invalid");return this.params.version=e,this}function t(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(!e)throw new Error("Cannot create a service without its definition.");if(C.forEach(function(r){if(!e[r])throw new Error("Definition is missing required parameter "+r+".")}),!Array.isArray(e.features)||!e.features.length)throw new Error("Definition requires `features` to be a non empty array.");if(!t)throw new Error("No project defined. Please enter a project key");var p=e.type,c=e.endpoint,b=e.features;return function(e){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],t={};return Object.keys(e).forEach(function(n){Object.defineProperty(t,n,{value:e[n],enumerable:!!r||"function"==typeof e[n]})}),t}(v({type:p,features:b,params:{id:null,expand:[],pagination:{page:null,perPage:null,sort:[]},query:{operator:"and",where:[]},searchKeywords:[]},withVersion:r},b.reduce(function(e,r){return r===n?v({},e,h,m):r===s?v({},e,d):r===i?v({},e,y):r===o?v({},e,w,m,{params:{expand:[],searchKeywords:[],staged:!0,pagination:{page:null,perPage:null,sort:[]},search:{facet:[],filter:[],filterByQuery:[],filterByFacets:[],fuzzy:!1,fuzzyLevel:0,markMatchingVariants:!1,text:null}}}):r===u?v({},e,w,m,l):r===a?v({},e,g):e},{}),{build:function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{withProjectKey:!0}).withProjectKey,r=function(e){if(!e)throw new Error("Missing options object to build query string.");var r=e.query,t=e.pagination,n=e.search,s=e.expand,i=e.staged,o=e.priceCurrency,a=e.priceCountry,u=e.priceCustomerGroup,p=e.priceChannel,c=e.searchKeywords,f=e.version,h=e.customerId,d=e.cartId,y=[];if(h&&y.push("customerId="+h),d&&y.push("cartId="+d),"boolean"==typeof i&&y.push("staged="+i.toString()),o&&y.push("priceCurrency="+o),a&&y.push("priceCountry="+a),u&&y.push("priceCustomerGroup="+u),p&&y.push("priceChannel="+p),s&&s.length&&(y=y.concat(s.map(function(e){return"expand="+e}))),r){var m=r.operator,g=r.where.join(encodeURIComponent(" "+m+" "));g&&y.push("where="+g)}if(t){var l=t.page,w=t.perPage,b=t.sort;if("number"==typeof w&&y.push("limit="+w),l){var v=(w||20)*(l-1);y.push("offset="+v)}b&&b.length&&(y=y.concat(b.map(function(e){return"sort="+e})))}if(n){var C=n.text,z=n.fuzzy,E=n.fuzzyLevel,I=n.markMatchingVariants,j=n.facet,x=n.filter,q=n.filterByQuery,O=n.filterByFacets;C&&y.push("text."+C.lang+"="+C.value),z&&y.push("fuzzy=true"),E&&y.push("fuzzyLevel="+E),y.push("markMatchingVariants="+I.toString()),j.forEach(function(e){return y.push("facet="+e)}),x.forEach(function(e){return y.push("filter="+e)}),q.forEach(function(e){return y.push("filter.query="+e)}),O.forEach(function(e){return y.push("filter.facets="+e)})}return c&&c.forEach(function(e){return y.push("searchKeywords."+e.lang+"="+e.value)}),f&&y.push("version="+f),y.join("&")}(this.params),i=(e?"/"+t:"")+c+function(e){return e.id?"/"+e.id:e.key?"/key="+e.key:""}(this.params)+(r?"?"+r:"");return function(){this.params.expand=[],-1!==this.features.indexOf(s)&&(this.params.id=null),-1!==this.features.indexOf(n)&&(this.params.pagination={page:null,perPage:null,sort:[]},this.params.query={operator:"and",where:[]}),-1!==this.features.indexOf(o)&&(this.params.staged=!0,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(a)&&(this.params.staged=!0),-1!==this.features.indexOf(u)&&(this.params.searchKeywords=[])}.call(this),i},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"];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)}),f(e,"id")&&this.byId(e.id),f(e,"key")&&this.byKey(e.key),f(e,"customerId")&&this.byCustomerId(e.customerId),f(e,"cartId")&&this.byCartId(e.cartId),e.sort&&e.sort.forEach(function(e){r.sort(e.by,"asc"===e.direction)}),f(e,"page")&&this.page(e.page),f(e,"perPage")&&this.perPage(e.perPage),f(e,"staged")&&this.staged(e.staged),f(e,"priceCurrency")&&this.priceCurrency(e.priceCurrency),f(e,"priceCountry")&&this.priceCountry(e.priceCountry),f(e,"priceCustomerGroup")&&this.priceCustomerGroup(e.priceCustomerGroup),f(e,"priceChannel")&&this.priceChannel(e.priceChannel),e.text&&this.text(e.text.value,e.text.language),e.fuzzy&&this.fuzzy(),f(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)}),f(e,"whereOperator")&&this.whereOperator(e.whereOperator),f(e,"version")&&this.withVersion(e.version)}.call(this,e),this}}))}var n="query",s="queryOne",i="queryExpand",o="search",a="projection",u="suggest",p=Object.freeze({query:n,queryOne:s,queryExpand:i,search:o,projection:a,suggest:u}),c={cartDiscounts:{type:"cart-discounts",endpoint:"/cart-discounts",features:[n,s,i]},carts:{type:"carts",endpoint:"/carts",features:[n,s,i]},categories:{type:"categories",endpoint:"/categories",features:[n,s,i]},channels:{type:"channels",endpoint:"/channels",features:[n,s,i]},customerGroups:{type:"customer-groups",endpoint:"/customer-groups",features:[n,s,i]},customers:{type:"customers",endpoint:"/customers",features:[n,s,i]},customObjects:{type:"custom-objects",endpoint:"/custom-objects",features:[n,s]},discountCodes:{type:"discount-codes",endpoint:"/discount-codes",features:[n,s,i]},inventory:{type:"inventory",endpoint:"/inventory",features:[n,s,i]},messages:{type:"messages",endpoint:"/messages",features:[n,s,i]},myCarts:{type:"my-carts",endpoint:"/me/carts",features:[n,s,i]},myOrders:{type:"my-orders",endpoint:"/me/orders",features:[n,s,i]},orders:{type:"orders",endpoint:"/orders",features:[n,s,i]},orderImport:{type:"orderImport",endpoint:"/orders/import",features:[n]},payments:{type:"payments",endpoint:"/payments",features:[n,s,i]},productDiscounts:{type:"product-discounts",endpoint:"/product-discounts",features:[n,s,i]},productProjections:{type:"product-projections",endpoint:"/product-projections",features:[n,s,i,a]},productProjectionsSearch:{type:"product-projections-search",endpoint:"/product-projections/search",features:[o,s,i,a]},productProjectionsSuggest:{type:"product-projections-suggest",endpoint:"/product-projections/suggest",features:[o,u,s,a]},products:{type:"products",endpoint:"/products",features:[n,s,i]},productTypes:{type:"product-types",endpoint:"/product-types",features:[n,s,i]},project:{type:"project",endpoint:"/",features:[n]},reviews:{type:"reviews",endpoint:"/reviews",features:[n,s,i]},shippingMethods:{type:"shipping-methods",endpoint:"/shipping-methods",features:[n,s,i]},shoppingLists:{type:"shopping-lists",endpoint:"/shopping-lists",features:[n,s,i]},states:{type:"states",endpoint:"/states",features:[n,s,i]},subscriptions:{type:"subscriptions",endpoint:"/subscriptions",features:[n,s,i]},taxCategories:{type:"tax-categories",endpoint:"/tax-categories",features:[n,s,i]},types:{type:"types",endpoint:"/types",features:[n,s,i]},zones:{type:"zones",endpoint:"/zones",features:[n,s,i]}},f=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},h=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}}),d=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}}),y=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}}),m=Object.freeze({sort:function(e){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(!e)throw new Error("Required argument for `sort` is missing");var t=r?"asc":"desc",n=encodeURIComponent(e+" "+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}}),g=Object.freeze({staged:function(){var e=!(arguments.length>0&&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}}),l=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}}),w=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}}),b=function(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e},v=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},C=["type","endpoint","features"];e.features=p,e.createRequestBuilder=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=v({},c,e.customServices);return Object.keys(r).reduce(function(n,s){return v({},n,b({},s,t(r[s],e.projectKey)))},{})},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 r(e){if("number"!=typeof e)throw new Error("A resource version is missing or invalid");return this.params.version=e,this}function t(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(!e)throw new Error("Cannot create a service without its definition.");if(z.forEach(function(r){if(!e[r])throw new Error("Definition is missing required parameter "+r+".")}),!Array.isArray(e.features)||!e.features.length)throw new Error("Definition requires `features` to be a non empty array.");if(!t)throw new Error("No project defined. Please enter a project key");var p=e.type,h=e.endpoint,C=e.features;return function(e){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],t={};return Object.keys(e).forEach(function(n){Object.defineProperty(t,n,{value:e[n],enumerable:!!r||"function"==typeof e[n]})}),t}(E({type:p,features:C,params:{id:null,expand:[],pagination:{page:null,perPage:null,sort:[]},location:{currency:"",country:"",state:""},query:{operator:"and",where:[]},searchKeywords:[]},withVersion:r},C.reduce(function(e,r){return r===n?E({},e,y,l):r===s?E({},e,d):r===o?E({},e,m):r===i?E({},e,g):r===a?E({},e,v,l,{params:{expand:[],searchKeywords:[],staged:!0,pagination:{page:null,perPage:null,sort:[]},search:{facet:[],filter:[],filterByQuery:[],filterByFacets:[],fuzzy:!1,fuzzyLevel:0,markMatchingVariants:!1,text:null}}}):r===c?E({},e,v,l,b):r===u?E({},e,w):e},{}),{build:function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{withProjectKey:!0}).withProjectKey,r=function(e){if(!e)throw new Error("Missing options object to build query string.");var r=e.query,t=e.pagination,n=e.search,s=e.expand,i=e.staged,o=e.priceCurrency,a=e.priceCountry,u=e.priceCustomerGroup,c=e.priceChannel,p=e.searchKeywords,h=e.version,f=e.customerId,y=e.cartId,d=e.location,m=[];if(f&&m.push("customerId="+f),y&&m.push("cartId="+y),"boolean"==typeof i&&m.push("staged="+i.toString()),o&&m.push("priceCurrency="+o),a&&m.push("priceCountry="+a),u&&m.push("priceCustomerGroup="+u),c&&m.push("priceChannel="+c),s&&s.length&&(m=m.concat(s.map(function(e){return"expand="+e}))),r){var g=r.operator,l=r.where.join(encodeURIComponent(" "+g+" "));l&&m.push("where="+l)}if(d){var w=d.country,b=d.currency,v=d.state;w&&m.push("country="+w),b&&m.push("currency="+b),v&&m.push("state="+v)}if(t){var C=t.page,E=t.perPage,z=t.sort;if("number"==typeof E&&m.push("limit="+E),C){var I=(E||20)*(C-1);m.push("offset="+I)}z&&z.length&&(m=m.concat(z.map(function(e){return"sort="+e})))}if(n){var j=n.text,q=n.fuzzy,x=n.fuzzyLevel,O=n.markMatchingVariants,R=n.facet,k=n.filter,P=n.filterByQuery,B=n.filterByFacets;j&&m.push("text."+j.lang+"="+j.value),q&&m.push("fuzzy=true"),x&&m.push("fuzzyLevel="+x),m.push("markMatchingVariants="+O.toString()),R.forEach(function(e){return m.push("facet="+e)}),k.forEach(function(e){return m.push("filter="+e)}),P.forEach(function(e){return m.push("filter.query="+e)}),B.forEach(function(e){return m.push("filter.facets="+e)})}return p&&p.forEach(function(e){return m.push("searchKeywords."+e.lang+"="+e.value)}),h&&m.push("version="+h),m.join("&")}(this.params),i=(e?"/"+t:"")+h+function(e){return e.id?"/"+e.id:e.key?"/key="+e.key:""}(this.params)+(r?"?"+r:"");return function(){this.params.expand=[],-1!==this.features.indexOf(s)&&(this.params.id=null),-1!==this.features.indexOf(n)&&(this.params.pagination={page:null,perPage:null,sort:[]},this.params.query={operator:"and",where:[]}),-1!==this.features.indexOf(a)&&(this.params.staged=!0,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(o)&&(this.params.location={currency:"",country:"",state:""}),-1!==this.features.indexOf(u)&&(this.params.staged=!0),-1!==this.features.indexOf(c)&&(this.params.searchKeywords=[])}.call(this),i},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"];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)}),f(e,"id")&&this.byId(e.id),f(e,"key")&&this.byKey(e.key),f(e,"customerId")&&this.byCustomerId(e.customerId),f(e,"cartId")&&this.byCartId(e.cartId),f(e,"country")&&this.byCountry(e.country),f(e,"currency")&&this.byCurrency(e.currency),f(e,"state")&&this.byState(e.state),e.sort&&e.sort.forEach(function(e){r.sort(e.by,"asc"===e.direction)}),f(e,"page")&&this.page(e.page),f(e,"perPage")&&this.perPage(e.perPage),f(e,"staged")&&this.staged(e.staged),f(e,"priceCurrency")&&this.priceCurrency(e.priceCurrency),f(e,"priceCountry")&&this.priceCountry(e.priceCountry),f(e,"priceCustomerGroup")&&this.priceCustomerGroup(e.priceCustomerGroup),f(e,"priceChannel")&&this.priceChannel(e.priceChannel),e.text&&this.text(e.text.value,e.text.language),e.fuzzy&&this.fuzzy(),f(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)}),f(e,"whereOperator")&&this.whereOperator(e.whereOperator),f(e,"version")&&this.withVersion(e.version)}.call(this,e),this}}))}var n="query",s="queryOne",i="queryExpand",o="queryLocation",a="search",u="projection",c="suggest",p=Object.freeze({query:n,queryOne:s,queryExpand:i,queryLocation:o,search:a,projection:u,suggest:c}),h={cartDiscounts:{type:"cart-discounts",endpoint:"/cart-discounts",features:[n,s,i]},carts:{type:"carts",endpoint:"/carts",features:[n,s,i]},categories:{type:"categories",endpoint:"/categories",features:[n,s,i]},channels:{type:"channels",endpoint:"/channels",features:[n,s,i]},customerGroups:{type:"customer-groups",endpoint:"/customer-groups",features:[n,s,i]},customers:{type:"customers",endpoint:"/customers",features:[n,s,i]},customObjects:{type:"custom-objects",endpoint:"/custom-objects",features:[n,s]},discountCodes:{type:"discount-codes",endpoint:"/discount-codes",features:[n,s,i]},inventory:{type:"inventory",endpoint:"/inventory",features:[n,s,i]},messages:{type:"messages",endpoint:"/messages",features:[n,s,i]},myCarts:{type:"my-carts",endpoint:"/me/carts",features:[n,s,i]},myOrders:{type:"my-orders",endpoint:"/me/orders",features:[n,s,i]},orders:{type:"orders",endpoint:"/orders",features:[n,s,i]},orderImport:{type:"orderImport",endpoint:"/orders/import",features:[n]},payments:{type:"payments",endpoint:"/payments",features:[n,s,i]},productDiscounts:{type:"product-discounts",endpoint:"/product-discounts",features:[n,s,i]},productProjections:{type:"product-projections",endpoint:"/product-projections",features:[n,s,i,u]},productProjectionsSearch:{type:"product-projections-search",endpoint:"/product-projections/search",features:[a,s,i,u]},productProjectionsSuggest:{type:"product-projections-suggest",endpoint:"/product-projections/suggest",features:[a,c,s,u]},products:{type:"products",endpoint:"/products",features:[n,s,i]},productTypes:{type:"product-types",endpoint:"/product-types",features:[n,s,i]},project:{type:"project",endpoint:"/",features:[n]},reviews:{type:"reviews",endpoint:"/reviews",features:[n,s,i]},shippingMethods:{type:"shipping-methods",endpoint:"/shipping-methods",features:[n,s,i,o]},shoppingLists:{type:"shopping-lists",endpoint:"/shopping-lists",features:[n,s,i]},states:{type:"states",endpoint:"/states",features:[n,s,i]},subscriptions:{type:"subscriptions",endpoint:"/subscriptions",features:[n,s,i]},taxCategories:{type:"tax-categories",endpoint:"/tax-categories",features:[n,s,i]},types:{type:"types",endpoint:"/types",features:[n,s,i]},zones:{type:"zones",endpoint:"/zones",features:[n,s,i]}},f=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},y=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}}),d=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}}),m=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}}),g=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}}),l=Object.freeze({sort:function(e){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(!e)throw new Error("Required argument for `sort` is missing");var t=r?"asc":"desc",n=encodeURIComponent(e+" "+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}}),w=Object.freeze({staged:function(){var e=!(arguments.length>0&&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}}),b=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}}),v=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}}),C=function(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e},E=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},z=["type","endpoint","features"];e.features=p,e.createRequestBuilder=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=E({},h,e.customServices);return Object.keys(r).reduce(function(n,s){return E({},n,C({},s,t(r[s],e.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": "3.4.1",
"version": "3.5.0",
"description": "Helper functions to construct API requests URI for the commercetools platform in a declarative way.",

@@ -10,0 +10,0 @@ "keywords": [

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