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

@commercetools/sdk-client

Package Overview
Dependencies
Maintainers
9
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commercetools/sdk-client - npm Package Compare versions

Comparing version 1.5.4 to 1.5.5

35

dist/commercetools-sdk-client.cjs.js

@@ -7,4 +7,4 @@ 'use strict';

var http = require('http');
var qs = _interopDefault(require('querystring'));
var http = require('http');

@@ -41,22 +41,2 @@ function validate(funcName, request) {

var slicedToArray = function () {

@@ -100,14 +80,2 @@ function sliceIterator(arr, i) {

var toConsumableArray = function (arr) {

@@ -124,2 +92,3 @@ if (Array.isArray(arr)) {

/* */
function compose() {

@@ -126,0 +95,0 @@ for (var _len = arguments.length, funcs = Array(_len), _key = 0; _key < _len; _key++) {

@@ -0,3 +1,3 @@

import { METHODS } from 'http';
import qs from 'querystring';
import { METHODS } from 'http';

@@ -34,22 +34,2 @@ function validate(funcName, request) {

var slicedToArray = function () {

@@ -93,14 +73,2 @@ function sliceIterator(arr, i) {

var toConsumableArray = function (arr) {

@@ -117,2 +85,3 @@ if (Array.isArray(arr)) {

/* */
function compose() {

@@ -119,0 +88,0 @@ for (var _len = arguments.length, funcs = Array(_len), _key = 0; _key < _len; _key++) {

387

dist/commercetools-sdk-client.umd.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('querystring'), require('http')) :
typeof define === 'function' && define.amd ? define(['exports', 'querystring', 'http'], factory) :
(factory((global.CommercetoolsSdkClient = {}),global.qs,global.http));
}(this, (function (exports,qs,http) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('http'), require('querystring')) :
typeof define === 'function' && define.amd ? define(['exports', 'http', 'querystring'], factory) :
(factory((global.CommercetoolsSdkClient = {}),global.http,global.qs));
}(this, (function (exports,http,qs) { 'use strict';
qs = qs && qs.hasOwnProperty('default') ? qs['default'] : qs;
qs = qs && qs.hasOwnProperty('default') ? qs['default'] : qs;
function validate(funcName, request) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { allowedMethods: http.METHODS };
function validate(funcName, request) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { allowedMethods: http.METHODS };
if (!request)
// eslint-disable-next-line max-len
throw new Error('The "' + funcName + '" function requires a "Request" object as an argument. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest');
if (!request)
// eslint-disable-next-line max-len
throw new Error('The "' + funcName + '" function requires a "Request" object as an argument. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest');
if (typeof request.uri !== 'string')
// eslint-disable-next-line max-len
throw new Error('The "' + funcName + '" Request object requires a valid uri. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest');
if (typeof request.uri !== 'string')
// eslint-disable-next-line max-len
throw new Error('The "' + funcName + '" Request object requires a valid uri. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest');
if (!(options.allowedMethods.indexOf(request.method) !== -1))
// eslint-disable-next-line max-len
throw new Error('The "' + funcName + '" Request object requires a valid method. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest');
}
if (!(options.allowedMethods.indexOf(request.method) !== -1))
// eslint-disable-next-line max-len
throw new Error('The "' + funcName + '" Request object requires a valid method. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest');
}
var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
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];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
}
return target;
};
return target;
};
var slicedToArray = function () {
function sliceIterator(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
var slicedToArray = function () {
function sliceIterator(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"]) _i["return"]();
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
if (_d) throw _e;
try {
if (!_n && _i["return"]) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
return _arr;
}
return function (arr, i) {
if (Array.isArray(arr)) {
return arr;
} else if (Symbol.iterator in Object(arr)) {
return sliceIterator(arr, i);
} else {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
};
}();
return function (arr, i) {
var toConsumableArray = function (arr) {
if (Array.isArray(arr)) {
return arr;
} else if (Symbol.iterator in Object(arr)) {
return sliceIterator(arr, i);
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
return arr2;
} else {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
return Array.from(arr);
}
};
}();
/* */
function compose() {
for (var _len = arguments.length, funcs = Array(_len), _key = 0; _key < _len; _key++) {
funcs[_key] = arguments[_key];
}
// eslint-disable-next-line no-param-reassign
funcs = funcs.filter(function (func) {
return typeof func === 'function';
});
if (funcs.length === 1) return funcs[0];
var toConsumableArray = function (arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
return arr2;
} else {
return Array.from(arr);
return funcs.reduce(function (a, b) {
return function () {
return a(b.apply(undefined, arguments));
};
});
}
};
/* */
function compose() {
for (var _len = arguments.length, funcs = Array(_len), _key = 0; _key < _len; _key++) {
funcs[_key] = arguments[_key];
}
function createClient(options) {
if (!options) throw new Error('Missing required options');
// eslint-disable-next-line no-param-reassign
funcs = funcs.filter(function (func) {
return typeof func === 'function';
});
if (options.middlewares && !Array.isArray(options.middlewares)) throw new Error('Middlewares should be an array');
if (funcs.length === 1) return funcs[0];
if (!options.middlewares || !Array.isArray(options.middlewares) || !options.middlewares.length) throw new Error('You need to provide at least one middleware');
return funcs.reduce(function (a, b) {
return function () {
return a(b.apply(undefined, arguments));
};
});
}
return {
/*
Given a request object,
*/
execute: function execute(request) {
validate('exec', request);
function createClient(options) {
if (!options) throw new Error('Missing required options');
return new Promise(function (resolve, reject) {
var resolver = function resolver(rq, rs) {
// Note: pick the promise `resolve` and `reject` function from
// the response object. This is not necessary the same function
// given from the `new Promise` constructor, as middlewares could
// override those functions for custom behaviours.
if (rs.error) rs.reject(rs.error);else {
var resObj = {
body: rs.body || {},
statusCode: rs.statusCode
};
if (rs.headers) resObj.headers = rs.headers;
if (rs.request) resObj.request = rs.request;
rs.resolve(resObj);
}
};
if (options.middlewares && !Array.isArray(options.middlewares)) throw new Error('Middlewares should be an array');
if (!options.middlewares || !Array.isArray(options.middlewares) || !options.middlewares.length) throw new Error('You need to provide at least one middleware');
return {
/*
Given a request object,
*/
execute: function execute(request) {
validate('exec', request);
return new Promise(function (resolve, reject) {
var resolver = function resolver(rq, rs) {
// Note: pick the promise `resolve` and `reject` function from
// the response object. This is not necessary the same function
// given from the `new Promise` constructor, as middlewares could
// override those functions for custom behaviours.
if (rs.error) rs.reject(rs.error);else {
var resObj = {
body: rs.body || {},
statusCode: rs.statusCode
};
if (rs.headers) resObj.headers = rs.headers;
if (rs.request) resObj.request = rs.request;
rs.resolve(resObj);
}
};
var dispatch = compose.apply(undefined, toConsumableArray(options.middlewares))(resolver);
dispatch(request,
// Initial response shape
{
resolve: resolve,
reject: reject,
body: undefined,
error: undefined
var dispatch = compose.apply(undefined, toConsumableArray(options.middlewares))(resolver);
dispatch(request,
// Initial response shape
{
resolve: resolve,
reject: reject,
body: undefined,
error: undefined
});
});
});
},
process: function process(request, fn, processOpt) {
var _this = this;
},
process: function process(request, fn, processOpt) {
var _this = this;
validate('process', request, { allowedMethods: ['GET'] });
validate('process', request, { allowedMethods: ['GET'] });
if (typeof fn !== 'function')
// eslint-disable-next-line max-len
throw new Error('The "process" function accepts a "Function" as a second argument that returns a Promise. See https://commercetools.github.io/nodejs/sdk/api/sdkClient.html#processrequest-processfn-options');
if (typeof fn !== 'function')
// eslint-disable-next-line max-len
throw new Error('The "process" function accepts a "Function" as a second argument that returns a Promise. See https://commercetools.github.io/nodejs/sdk/api/sdkClient.html#processrequest-processfn-options');
// Set default process options
var opt = _extends({
total: Number.POSITIVE_INFINITY,
accumulate: true
}, processOpt);
return new Promise(function (resolve, reject) {
var _request$uri$split = request.uri.split('?'),
_request$uri$split2 = slicedToArray(_request$uri$split, 2),
path = _request$uri$split2[0],
queryString = _request$uri$split2[1];
// Set default process options
var opt = _extends({
total: Number.POSITIVE_INFINITY,
accumulate: true
}, processOpt);
return new Promise(function (resolve, reject) {
var _request$uri$split = request.uri.split('?'),
_request$uri$split2 = slicedToArray(_request$uri$split, 2),
path = _request$uri$split2[0],
queryString = _request$uri$split2[1];
var requestQuery = _extends({}, qs.parse(queryString));
var query = _extends({
// defaults
limit: 20
}, requestQuery);
var requestQuery = _extends({}, qs.parse(queryString));
var query = _extends({
// defaults
limit: 20
}, requestQuery);
var itemsToGet = opt.total;
var processPage = function processPage(lastId) {
var acc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
var itemsToGet = opt.total;
var processPage = function processPage(lastId) {
var acc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
// Use the lesser value between limit and itemsToGet in query
var limit = query.limit < itemsToGet ? query.limit : itemsToGet;
var originalQueryString = qs.stringify(_extends({}, query, { limit: limit }));
// Use the lesser value between limit and itemsToGet in query
var limit = query.limit < itemsToGet ? query.limit : itemsToGet;
var originalQueryString = qs.stringify(_extends({}, query, { limit: limit }));
var enhancedQuery = _extends({
sort: 'id asc',
withTotal: false
}, lastId ? { where: 'id > "' + lastId + '"' } : {});
var enhancedQueryString = qs.stringify(enhancedQuery);
var enhancedRequest = _extends({}, request, {
uri: path + '?' + enhancedQueryString + '&' + originalQueryString
});
var enhancedQuery = _extends({
sort: 'id asc',
withTotal: false
}, lastId ? { where: 'id > "' + lastId + '"' } : {});
var enhancedQueryString = qs.stringify(enhancedQuery);
var enhancedRequest = _extends({}, request, {
uri: path + '?' + enhancedQueryString + '&' + originalQueryString
});
_this.execute(enhancedRequest).then(function (payload) {
fn(payload).then(function (result) {
var resultsLength = payload.body.results.length;
var accumulated = void 0;
if (opt.accumulate) accumulated = acc.concat(result || []);
_this.execute(enhancedRequest).then(function (payload) {
fn(payload).then(function (result) {
var resultsLength = payload.body.results.length;
var accumulated = void 0;
if (opt.accumulate) accumulated = acc.concat(result || []);
itemsToGet -= resultsLength;
// If there are no more items to get, it means the total number
// of items in the original request have been fetched so we
// resolve the promise.
// Also, if we get less results in a page then the limit set it
// means that there are no more pages and that we can finally
// resolve the promise.
if (resultsLength < query.limit || !itemsToGet) {
resolve(accumulated || []);
return;
}
itemsToGet -= resultsLength;
// If there are no more items to get, it means the total number
// of items in the original request have been fetched so we
// resolve the promise.
// Also, if we get less results in a page then the limit set it
// means that there are no more pages and that we can finally
// resolve the promise.
if (resultsLength < query.limit || !itemsToGet) {
resolve(accumulated || []);
return;
}
var last = payload.body.results[resultsLength - 1];
var newLastId = last && last.id;
processPage(newLastId, accumulated);
var last = payload.body.results[resultsLength - 1];
var newLastId = last && last.id;
processPage(newLastId, accumulated);
}).catch(reject);
}).catch(reject);
}).catch(reject);
};
};
// Start iterating through pages
processPage();
});
}
};
}
// Start iterating through pages
processPage();
});
}
};
}
// eslint-disable-next-line import/prefer-default-export
// eslint-disable-next-line import/prefer-default-export
exports.createClient = createClient;
exports.createClient = createClient;
Object.defineProperty(exports, '__esModule', { value: true });
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=commercetools-sdk-client.umd.js.map

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

!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("querystring"),require("http")):"function"==typeof define&&define.amd?define(["exports","querystring","http"],r):r(e.CommercetoolsSdkClient={},e.qs,e.http)}(this,function(e,r,t){"use strict";function o(e,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{allowedMethods:t.METHODS};if(!r)throw new Error('The "'+e+'" function requires a "Request" object as an argument. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest');if("string"!=typeof r.uri)throw new Error('The "'+e+'" Request object requires a valid uri. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest');if(-1===o.allowedMethods.indexOf(r.method))throw new Error('The "'+e+'" Request object requires a valid method. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest')}r=r&&r.hasOwnProperty("default")?r.default:r;var n=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},i=function(){return function(e,r){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,r){var t=[],o=!0,n=!1,i=void 0;try{for(var s,a=e[Symbol.iterator]();!(o=(s=a.next()).done)&&(t.push(s.value),!r||t.length!==r);o=!0);}catch(e){n=!0,i=e}finally{try{!o&&a.return&&a.return()}finally{if(n)throw i}}return t}(e,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),s=function(e){if(Array.isArray(e)){for(var r=0,t=Array(e.length);r<e.length;r++)t[r]=e[r];return t}return Array.from(e)};e.createClient=function(e){if(!e)throw new Error("Missing required options");if(e.middlewares&&!Array.isArray(e.middlewares))throw new Error("Middlewares should be an array");if(!e.middlewares||!Array.isArray(e.middlewares)||!e.middlewares.length)throw new Error("You need to provide at least one middleware");return{execute:function(r){return o("exec",r),new Promise(function(t,o){(function(){for(var e=arguments.length,r=Array(e),t=0;t<e;t++)r[t]=arguments[t];return 1===(r=r.filter(function(e){return"function"==typeof e})).length?r[0]:r.reduce(function(e,r){return function(){return e(r.apply(void 0,arguments))}})}).apply(void 0,s(e.middlewares))(function(e,r){if(r.error)r.reject(r.error);else{var t={body:r.body||{},statusCode:r.statusCode};r.headers&&(t.headers=r.headers),r.request&&(t.request=r.request),r.resolve(t)}})(r,{resolve:t,reject:o,body:void 0,error:void 0})})},process:function(e,t,s){var a=this;if(o("process",e,{allowedMethods:["GET"]}),"function"!=typeof t)throw new Error('The "process" function accepts a "Function" as a second argument that returns a Promise. See https://commercetools.github.io/nodejs/sdk/api/sdkClient.html#processrequest-processfn-options');var u=n({total:Number.POSITIVE_INFINITY,accumulate:!0},s);return new Promise(function(o,s){var l=e.uri.split("?"),c=i(l,2),d=c[0],f=c[1],h=n({},r.parse(f)),y=n({limit:20},h),m=u.total;!function i(l){var c=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],f=y.limit<m?y.limit:m,h=r.stringify(n({},y,{limit:f})),p=n({sort:"id asc",withTotal:!1},l?{where:'id > "'+l+'"'}:{}),w=r.stringify(p),v=n({},e,{uri:d+"?"+w+"&"+h});a.execute(v).then(function(e){t(e).then(function(r){var t=e.body.results.length,n=void 0;if(u.accumulate&&(n=c.concat(r||[])),m-=t,t<y.limit||!m)o(n||[]);else{var s=e.body.results[t-1],a=s&&s.id;i(a,n)}}).catch(s)}).catch(s)}()})}}},Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("http"),require("querystring")):"function"==typeof define&&define.amd?define(["exports","http","querystring"],r):r(e.CommercetoolsSdkClient={},e.http,e.qs)}(this,function(e,o,w){"use strict";function r(e,r){var t=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{allowedMethods:o.METHODS};if(!r)throw new Error('The "'+e+'" function requires a "Request" object as an argument. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest');if("string"!=typeof r.uri)throw new Error('The "'+e+'" Request object requires a valid uri. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest');if(-1===t.allowedMethods.indexOf(r.method))throw new Error('The "'+e+'" Request object requires a valid method. See https://commercetools.github.io/nodejs/sdk/Glossary.html#clientrequest')}w=w&&w.hasOwnProperty("default")?w.default:w;var v=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},n=function(e,r){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,r){var t=[],o=!0,n=!1,i=void 0;try{for(var s,a=e[Symbol.iterator]();!(o=(s=a.next()).done)&&(t.push(s.value),!r||t.length!==r);o=!0);}catch(e){n=!0,i=e}finally{try{!o&&a.return&&a.return()}finally{if(n)throw i}}return t}(e,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")},i=function(e){if(Array.isArray(e)){for(var r=0,t=Array(e.length);r<e.length;r++)t[r]=e[r];return t}return Array.from(e)};e.createClient=function(o){if(!o)throw new Error("Missing required options");if(o.middlewares&&!Array.isArray(o.middlewares))throw new Error("Middlewares should be an array");if(!o.middlewares||!Array.isArray(o.middlewares)||!o.middlewares.length)throw new Error("You need to provide at least one middleware");return{execute:function(t){return r("exec",t),new Promise(function(e,r){(function(){for(var e=arguments.length,r=Array(e),t=0;t<e;t++)r[t]=arguments[t];return 1===(r=r.filter(function(e){return"function"==typeof e})).length?r[0]:r.reduce(function(e,r){return function(){return e(r.apply(void 0,arguments))}})}).apply(void 0,i(o.middlewares))(function(e,r){if(r.error)r.reject(r.error);else{var t={body:r.body||{},statusCode:r.statusCode};r.headers&&(t.headers=r.headers),r.request&&(t.request=r.request),r.resolve(t)}})(t,{resolve:e,reject:r,body:void 0,error:void 0})})},process:function(h,y,e){var m=this;if(r("process",h,{allowedMethods:["GET"]}),"function"!=typeof y)throw new Error('The "process" function accepts a "Function" as a second argument that returns a Promise. See https://commercetools.github.io/nodejs/sdk/api/sdkClient.html#processrequest-processfn-options');var p=v({total:Number.POSITIVE_INFINITY,accumulate:!0},e);return new Promise(function(u,l){var e=h.uri.split("?"),r=n(e,2),c=r[0],t=r[1],o=v({},w.parse(t)),d=v({limit:20},o),f=p.total;!function s(e){var a=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[],r=d.limit<f?d.limit:f,t=w.stringify(v({},d,{limit:r})),o=v({sort:"id asc",withTotal:!1},e?{where:'id > "'+e+'"'}:{}),n=w.stringify(o),i=v({},h,{uri:c+"?"+n+"&"+t});m.execute(i).then(function(i){y(i).then(function(e){var r=i.body.results.length,t=void 0;if(p.accumulate&&(t=a.concat(e||[])),f-=r,r<d.limit||!f)u(t||[]);else{var o=i.body.results[r-1],n=o&&o.id;s(n,t)}}).catch(l)}).catch(l)}()})}}},Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=commercetools-sdk-client.umd.min.js.map

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

"name": "@commercetools/sdk-client",
"version": "1.5.4",
"version": "1.5.5",
"description": "SDK Client for usage of commercetools platform API",

@@ -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