New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

kinto-client

Package Overview
Dependencies
Maintainers
4
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kinto-client - npm Package Compare versions

Comparing version 0.8.2 to 0.8.3

2

dist/kinto-client.min.js

@@ -11,3 +11,3 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.KintoClient = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

},{}],4:[function(require,module,exports){
"use strict";function _interopRequireWildcard(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t["default"]=e,t}function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _applyDecoratedDescriptor(e,t,r,i,s){var n={};return Object.keys(i).forEach(function(e){n[e]=i[e]}),n.enumerable=!!n.enumerable,n.configurable=!!n.configurable,("value"in n||n.initializer)&&(n.writable=!0),n=r.slice().reverse().reduce(function(r,i){return i(e,t,r)||r},n),s&&void 0!==n.initializer&&(n.value=n.initializer?n.initializer.call(s):void 0,n.initializer=void 0),void 0===n.initializer&&(Object.defineProperty(e,t,n),n=null),n}Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=exports.SUPPORTED_PROTOCOL_VERSION=void 0;var _extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e},_createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),_dec,_dec2,_dec3,_dec4,_dec5,_dec6,_desc,_value,_class,_utils=require("./utils"),_http=require("./http"),_http2=_interopRequireDefault(_http),_endpoint=require("./endpoint"),_endpoint2=_interopRequireDefault(_endpoint),_requests=require("./requests"),requests=_interopRequireWildcard(_requests),_batch=require("./batch"),_bucket=require("./bucket"),_bucket2=_interopRequireDefault(_bucket),SUPPORTED_PROTOCOL_VERSION=exports.SUPPORTED_PROTOCOL_VERSION="v1",KintoClientBase=(_dec=(0,_utils.nobatch)("This operation is not supported within a batch operation."),_dec2=(0,_utils.nobatch)("This operation is not supported within a batch operation."),_dec3=(0,_utils.nobatch)("This operation is not supported within a batch operation."),_dec4=(0,_utils.nobatch)("This operation is not supported within a batch operation."),_dec5=(0,_utils.nobatch)("Can't use batch within a batch!"),_dec6=(0,_utils.support)("1.4","2.0"),_class=function(){function e(t){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(_classCallCheck(this,e),"string"!=typeof t||!t.length)throw new Error("Invalid remote URL: "+t);"/"===t[t.length-1]&&(t=t.slice(0,-1)),this._backoffReleaseTime=null,this.defaultReqOptions={bucket:r.bucket||"default",headers:r.headers||{},safe:!!r.safe},this._options=r,this._requests=[],this._isBatch=!!r.batch,this.remote=t,this.serverInfo=null,this.events=r.events;var i=r.requestMode,s=r.timeout;this.http=new _http2["default"](this.events,{requestMode:i,timeout:s}),this._registerHTTPEvents()}return _createClass(e,[{key:"_registerHTTPEvents",value:function(){var e=this;this.events.on("backoff",function(t){e._backoffReleaseTime=t})}},{key:"bucket",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=(0,_utils.omit)(this._getRequestOptions(t),"bucket");return new _bucket2["default"](this,e,r)}},{key:"_getRequestOptions",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return _extends({},this.defaultReqOptions,e,{batch:this._isBatch,headers:_extends({},this.defaultReqOptions.headers,e.headers)})}},{key:"fetchServerInfo",value:function(){var e=this,t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.serverInfo?Promise.resolve(this.serverInfo):this.http.request(this.remote+(0,_endpoint2["default"])("root"),{headers:_extends({},this.defaultReqOptions.headers,t.headers)}).then(function(t){var r=t.json;return e.serverInfo=r,e.serverInfo})}},{key:"fetchServerSettings",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.fetchServerInfo(e).then(function(e){var t=e.settings;return t})}},{key:"fetchServerCapabilities",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.fetchServerInfo(e).then(function(e){var t=e.capabilities;return t})}},{key:"fetchUser",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.fetchServerInfo(e).then(function(e){var t=e.user;return t})}},{key:"fetchHTTPApiVersion",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.fetchServerInfo(e).then(function(e){var t=e.http_api_version;return t})}},{key:"_batchRequests",value:function(e){var t=this,r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=_extends({},this.defaultReqOptions.headers,r.headers);return e.length?this.fetchServerSettings().then(function(s){var n=s.batch_max_requests;if(n&&e.length>n){var o=(0,_utils.partition)(e,n);return(0,_utils.pMap)(o,function(e){return t._batchRequests(e,r)})}return t.execute({path:(0,_endpoint2["default"])("batch"),method:"POST",headers:i,body:{defaults:{headers:i},requests:e}}).then(function(e){var t=e.responses;return t})}):Promise.resolve([])}},{key:"batch",value:function(t){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=new e(this.remote,_extends({},this._options,this._getRequestOptions(r),{batch:!0})),s=void 0,n=void 0;r.bucket&&(s=i.bucket(r.bucket),r.collection&&(n=s.collection(r.collection)));var o=n||s||i;try{t(o)}catch(a){return Promise.reject(a)}return this._batchRequests(i._requests,r).then(function(e){return r.aggregate?(0,_batch.aggregate)(e,i._requests):e})}},{key:"execute",value:function(e){var t=this,r=arguments.length<=1||void 0===arguments[1]?{raw:!1}:arguments[1];if(this._isBatch){this._requests.push(e);var i="This result is generated from within a batch operation and should not be consumed.";return Promise.resolve(r.raw?{json:i}:i)}var s=this.fetchServerSettings().then(function(r){return t.http.request(t.remote+e.path,_extends({},e,{body:JSON.stringify(e.body)}))});return r.raw?s:s.then(function(e){var t=e.json;return t})}},{key:"listBuckets",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.execute({path:(0,_endpoint2["default"])("buckets"),headers:_extends({},this.defaultReqOptions.headers,e.headers)})}},{key:"createBucket",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=this._getRequestOptions(t);return this.execute(requests.createBucket(e,r))}},{key:"deleteBucket",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=this._getRequestOptions(t);return this.execute(requests.deleteBucket((0,_utils.toDataBody)(e),r))}},{key:"deleteBuckets",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=this._getRequestOptions(e);return this.execute(requests.deleteBuckets(t))}},{key:"remote",get:function(){return this._remote},set:function(e){var t=void 0;try{t=e.match(/\/(v\d+)\/?$/)[1]}catch(r){throw new Error("The remote URL must contain the version: "+e)}if(t!==SUPPORTED_PROTOCOL_VERSION)throw new Error("Unsupported protocol version: "+t);this._remote=e,this._version=t}},{key:"version",get:function(){return this._version}},{key:"backoff",get:function(){var e=(new Date).getTime();return this._backoffReleaseTime&&e<this._backoffReleaseTime?this._backoffReleaseTime-e:0}}]),e}(),_applyDecoratedDescriptor(_class.prototype,"fetchServerSettings",[_dec],Object.getOwnPropertyDescriptor(_class.prototype,"fetchServerSettings"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"fetchServerCapabilities",[_dec2],Object.getOwnPropertyDescriptor(_class.prototype,"fetchServerCapabilities"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"fetchUser",[_dec3],Object.getOwnPropertyDescriptor(_class.prototype,"fetchUser"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"fetchHTTPApiVersion",[_dec4],Object.getOwnPropertyDescriptor(_class.prototype,"fetchHTTPApiVersion"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"batch",[_dec5],Object.getOwnPropertyDescriptor(_class.prototype,"batch"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"deleteBuckets",[_dec6],Object.getOwnPropertyDescriptor(_class.prototype,"deleteBuckets"),_class.prototype),_class);exports["default"]=KintoClientBase;
"use strict";function _interopRequireWildcard(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t["default"]=e,t}function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _applyDecoratedDescriptor(e,t,r,i,s){var n={};return Object.keys(i).forEach(function(e){n[e]=i[e]}),n.enumerable=!!n.enumerable,n.configurable=!!n.configurable,("value"in n||n.initializer)&&(n.writable=!0),n=r.slice().reverse().reduce(function(r,i){return i(e,t,r)||r},n),s&&void 0!==n.initializer&&(n.value=n.initializer?n.initializer.call(s):void 0,n.initializer=void 0),void 0===n.initializer&&(Object.defineProperty(e,t,n),n=null),n}Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=exports.SUPPORTED_PROTOCOL_VERSION=void 0;var _extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e},_createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),_dec,_dec2,_dec3,_dec4,_dec5,_dec6,_desc,_value,_class,_utils=require("./utils"),_http=require("./http"),_http2=_interopRequireDefault(_http),_endpoint=require("./endpoint"),_endpoint2=_interopRequireDefault(_endpoint),_requests=require("./requests"),requests=_interopRequireWildcard(_requests),_batch=require("./batch"),_bucket=require("./bucket"),_bucket2=_interopRequireDefault(_bucket),SUPPORTED_PROTOCOL_VERSION=exports.SUPPORTED_PROTOCOL_VERSION="v1",KintoClientBase=(_dec=(0,_utils.nobatch)("This operation is not supported within a batch operation."),_dec2=(0,_utils.nobatch)("This operation is not supported within a batch operation."),_dec3=(0,_utils.nobatch)("This operation is not supported within a batch operation."),_dec4=(0,_utils.nobatch)("This operation is not supported within a batch operation."),_dec5=(0,_utils.nobatch)("Can't use batch within a batch!"),_dec6=(0,_utils.support)("1.4","2.0"),_class=function(){function e(t){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(_classCallCheck(this,e),"string"!=typeof t||!t.length)throw new Error("Invalid remote URL: "+t);"/"===t[t.length-1]&&(t=t.slice(0,-1)),this._backoffReleaseTime=null,this.defaultReqOptions={bucket:r.bucket||"default",headers:r.headers||{},safe:!!r.safe},this._options=r,this._requests=[],this._isBatch=!!r.batch,this.remote=t,this.serverInfo=null,this.events=r.events;var i=r.requestMode,s=r.timeout;this.http=new _http2["default"](this.events,{requestMode:i,timeout:s}),this._registerHTTPEvents()}return _createClass(e,[{key:"_registerHTTPEvents",value:function(){var e=this;this._isBatch||this.events.on("backoff",function(t){e._backoffReleaseTime=t})}},{key:"bucket",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=(0,_utils.omit)(this._getRequestOptions(t),"bucket");return new _bucket2["default"](this,e,r)}},{key:"_getRequestOptions",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return _extends({},this.defaultReqOptions,e,{batch:this._isBatch,headers:_extends({},this.defaultReqOptions.headers,e.headers)})}},{key:"fetchServerInfo",value:function(){var e=this,t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.serverInfo?Promise.resolve(this.serverInfo):this.http.request(this.remote+(0,_endpoint2["default"])("root"),{headers:_extends({},this.defaultReqOptions.headers,t.headers)}).then(function(t){var r=t.json;return e.serverInfo=r,e.serverInfo})}},{key:"fetchServerSettings",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.fetchServerInfo(e).then(function(e){var t=e.settings;return t})}},{key:"fetchServerCapabilities",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.fetchServerInfo(e).then(function(e){var t=e.capabilities;return t})}},{key:"fetchUser",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.fetchServerInfo(e).then(function(e){var t=e.user;return t})}},{key:"fetchHTTPApiVersion",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.fetchServerInfo(e).then(function(e){var t=e.http_api_version;return t})}},{key:"_batchRequests",value:function(e){var t=this,r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=_extends({},this.defaultReqOptions.headers,r.headers);return e.length?this.fetchServerSettings().then(function(s){var n=s.batch_max_requests;if(n&&e.length>n){var o=(0,_utils.partition)(e,n);return(0,_utils.pMap)(o,function(e){return t._batchRequests(e,r)})}return t.execute({path:(0,_endpoint2["default"])("batch"),method:"POST",headers:i,body:{defaults:{headers:i},requests:e}}).then(function(e){var t=e.responses;return t})}):Promise.resolve([])}},{key:"batch",value:function(t){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=new e(this.remote,_extends({},this._options,this._getRequestOptions(r),{batch:!0})),s=void 0,n=void 0;r.bucket&&(s=i.bucket(r.bucket),r.collection&&(n=s.collection(r.collection)));var o=n||s||i;try{t(o)}catch(a){return Promise.reject(a)}return this._batchRequests(i._requests,r).then(function(e){return r.aggregate?(0,_batch.aggregate)(e,i._requests):e})}},{key:"execute",value:function(e){var t=this,r=arguments.length<=1||void 0===arguments[1]?{raw:!1}:arguments[1];if(this._isBatch){this._requests.push(e);var i="This result is generated from within a batch operation and should not be consumed.";return Promise.resolve(r.raw?{json:i}:i)}var s=this.fetchServerSettings().then(function(r){return t.http.request(t.remote+e.path,_extends({},e,{body:JSON.stringify(e.body)}))});return r.raw?s:s.then(function(e){var t=e.json;return t})}},{key:"listBuckets",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.execute({path:(0,_endpoint2["default"])("buckets"),headers:_extends({},this.defaultReqOptions.headers,e.headers)})}},{key:"createBucket",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=this._getRequestOptions(t);return this.execute(requests.createBucket(e,r))}},{key:"deleteBucket",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=this._getRequestOptions(t);return this.execute(requests.deleteBucket((0,_utils.toDataBody)(e),r))}},{key:"deleteBuckets",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=this._getRequestOptions(e);return this.execute(requests.deleteBuckets(t))}},{key:"remote",get:function(){return this._remote},set:function(e){var t=void 0;try{t=e.match(/\/(v\d+)\/?$/)[1]}catch(r){throw new Error("The remote URL must contain the version: "+e)}if(t!==SUPPORTED_PROTOCOL_VERSION)throw new Error("Unsupported protocol version: "+t);this._remote=e,this._version=t}},{key:"version",get:function(){return this._version}},{key:"backoff",get:function(){var e=(new Date).getTime();return this._backoffReleaseTime&&e<this._backoffReleaseTime?this._backoffReleaseTime-e:0}}]),e}(),_applyDecoratedDescriptor(_class.prototype,"fetchServerSettings",[_dec],Object.getOwnPropertyDescriptor(_class.prototype,"fetchServerSettings"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"fetchServerCapabilities",[_dec2],Object.getOwnPropertyDescriptor(_class.prototype,"fetchServerCapabilities"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"fetchUser",[_dec3],Object.getOwnPropertyDescriptor(_class.prototype,"fetchUser"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"fetchHTTPApiVersion",[_dec4],Object.getOwnPropertyDescriptor(_class.prototype,"fetchHTTPApiVersion"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"batch",[_dec5],Object.getOwnPropertyDescriptor(_class.prototype,"batch"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"deleteBuckets",[_dec6],Object.getOwnPropertyDescriptor(_class.prototype,"deleteBuckets"),_class.prototype),_class);exports["default"]=KintoClientBase;

@@ -14,0 +14,0 @@ },{"./batch":5,"./bucket":6,"./endpoint":8,"./http":10,"./requests":12,"./utils":13}],5:[function(require,module,exports){

@@ -7,3 +7,3 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.KintoClient = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

},{}],3:[function(require,module,exports){
"use strict";function _interopRequireWildcard(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t["default"]=e,t}function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _applyDecoratedDescriptor(e,t,r,i,s){var n={};return Object.keys(i).forEach(function(e){n[e]=i[e]}),n.enumerable=!!n.enumerable,n.configurable=!!n.configurable,("value"in n||n.initializer)&&(n.writable=!0),n=r.slice().reverse().reduce(function(r,i){return i(e,t,r)||r},n),s&&void 0!==n.initializer&&(n.value=n.initializer?n.initializer.call(s):void 0,n.initializer=void 0),void 0===n.initializer&&(Object.defineProperty(e,t,n),n=null),n}Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=exports.SUPPORTED_PROTOCOL_VERSION=void 0;var _extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e},_createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),_dec,_dec2,_dec3,_dec4,_dec5,_dec6,_desc,_value,_class,_utils=require("./utils"),_http=require("./http"),_http2=_interopRequireDefault(_http),_endpoint=require("./endpoint"),_endpoint2=_interopRequireDefault(_endpoint),_requests=require("./requests"),requests=_interopRequireWildcard(_requests),_batch=require("./batch"),_bucket=require("./bucket"),_bucket2=_interopRequireDefault(_bucket),SUPPORTED_PROTOCOL_VERSION=exports.SUPPORTED_PROTOCOL_VERSION="v1",KintoClientBase=(_dec=(0,_utils.nobatch)("This operation is not supported within a batch operation."),_dec2=(0,_utils.nobatch)("This operation is not supported within a batch operation."),_dec3=(0,_utils.nobatch)("This operation is not supported within a batch operation."),_dec4=(0,_utils.nobatch)("This operation is not supported within a batch operation."),_dec5=(0,_utils.nobatch)("Can't use batch within a batch!"),_dec6=(0,_utils.support)("1.4","2.0"),_class=function(){function e(t){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(_classCallCheck(this,e),"string"!=typeof t||!t.length)throw new Error("Invalid remote URL: "+t);"/"===t[t.length-1]&&(t=t.slice(0,-1)),this._backoffReleaseTime=null,this.defaultReqOptions={bucket:r.bucket||"default",headers:r.headers||{},safe:!!r.safe},this._options=r,this._requests=[],this._isBatch=!!r.batch,this.remote=t,this.serverInfo=null,this.events=r.events;var i=r.requestMode,s=r.timeout;this.http=new _http2["default"](this.events,{requestMode:i,timeout:s}),this._registerHTTPEvents()}return _createClass(e,[{key:"_registerHTTPEvents",value:function(){var e=this;this.events.on("backoff",function(t){e._backoffReleaseTime=t})}},{key:"bucket",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=(0,_utils.omit)(this._getRequestOptions(t),"bucket");return new _bucket2["default"](this,e,r)}},{key:"_getRequestOptions",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return _extends({},this.defaultReqOptions,e,{batch:this._isBatch,headers:_extends({},this.defaultReqOptions.headers,e.headers)})}},{key:"fetchServerInfo",value:function(){var e=this,t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.serverInfo?Promise.resolve(this.serverInfo):this.http.request(this.remote+(0,_endpoint2["default"])("root"),{headers:_extends({},this.defaultReqOptions.headers,t.headers)}).then(function(t){var r=t.json;return e.serverInfo=r,e.serverInfo})}},{key:"fetchServerSettings",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.fetchServerInfo(e).then(function(e){var t=e.settings;return t})}},{key:"fetchServerCapabilities",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.fetchServerInfo(e).then(function(e){var t=e.capabilities;return t})}},{key:"fetchUser",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.fetchServerInfo(e).then(function(e){var t=e.user;return t})}},{key:"fetchHTTPApiVersion",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.fetchServerInfo(e).then(function(e){var t=e.http_api_version;return t})}},{key:"_batchRequests",value:function(e){var t=this,r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=_extends({},this.defaultReqOptions.headers,r.headers);return e.length?this.fetchServerSettings().then(function(s){var n=s.batch_max_requests;if(n&&e.length>n){var o=(0,_utils.partition)(e,n);return(0,_utils.pMap)(o,function(e){return t._batchRequests(e,r)})}return t.execute({path:(0,_endpoint2["default"])("batch"),method:"POST",headers:i,body:{defaults:{headers:i},requests:e}}).then(function(e){var t=e.responses;return t})}):Promise.resolve([])}},{key:"batch",value:function(t){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=new e(this.remote,_extends({},this._options,this._getRequestOptions(r),{batch:!0})),s=void 0,n=void 0;r.bucket&&(s=i.bucket(r.bucket),r.collection&&(n=s.collection(r.collection)));var o=n||s||i;try{t(o)}catch(a){return Promise.reject(a)}return this._batchRequests(i._requests,r).then(function(e){return r.aggregate?(0,_batch.aggregate)(e,i._requests):e})}},{key:"execute",value:function(e){var t=this,r=arguments.length<=1||void 0===arguments[1]?{raw:!1}:arguments[1];if(this._isBatch){this._requests.push(e);var i="This result is generated from within a batch operation and should not be consumed.";return Promise.resolve(r.raw?{json:i}:i)}var s=this.fetchServerSettings().then(function(r){return t.http.request(t.remote+e.path,_extends({},e,{body:JSON.stringify(e.body)}))});return r.raw?s:s.then(function(e){var t=e.json;return t})}},{key:"listBuckets",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.execute({path:(0,_endpoint2["default"])("buckets"),headers:_extends({},this.defaultReqOptions.headers,e.headers)})}},{key:"createBucket",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=this._getRequestOptions(t);return this.execute(requests.createBucket(e,r))}},{key:"deleteBucket",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=this._getRequestOptions(t);return this.execute(requests.deleteBucket((0,_utils.toDataBody)(e),r))}},{key:"deleteBuckets",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=this._getRequestOptions(e);return this.execute(requests.deleteBuckets(t))}},{key:"remote",get:function(){return this._remote},set:function(e){var t=void 0;try{t=e.match(/\/(v\d+)\/?$/)[1]}catch(r){throw new Error("The remote URL must contain the version: "+e)}if(t!==SUPPORTED_PROTOCOL_VERSION)throw new Error("Unsupported protocol version: "+t);this._remote=e,this._version=t}},{key:"version",get:function(){return this._version}},{key:"backoff",get:function(){var e=(new Date).getTime();return this._backoffReleaseTime&&e<this._backoffReleaseTime?this._backoffReleaseTime-e:0}}]),e}(),_applyDecoratedDescriptor(_class.prototype,"fetchServerSettings",[_dec],Object.getOwnPropertyDescriptor(_class.prototype,"fetchServerSettings"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"fetchServerCapabilities",[_dec2],Object.getOwnPropertyDescriptor(_class.prototype,"fetchServerCapabilities"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"fetchUser",[_dec3],Object.getOwnPropertyDescriptor(_class.prototype,"fetchUser"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"fetchHTTPApiVersion",[_dec4],Object.getOwnPropertyDescriptor(_class.prototype,"fetchHTTPApiVersion"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"batch",[_dec5],Object.getOwnPropertyDescriptor(_class.prototype,"batch"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"deleteBuckets",[_dec6],Object.getOwnPropertyDescriptor(_class.prototype,"deleteBuckets"),_class.prototype),_class);exports["default"]=KintoClientBase;
"use strict";function _interopRequireWildcard(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t["default"]=e,t}function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _applyDecoratedDescriptor(e,t,r,i,s){var n={};return Object.keys(i).forEach(function(e){n[e]=i[e]}),n.enumerable=!!n.enumerable,n.configurable=!!n.configurable,("value"in n||n.initializer)&&(n.writable=!0),n=r.slice().reverse().reduce(function(r,i){return i(e,t,r)||r},n),s&&void 0!==n.initializer&&(n.value=n.initializer?n.initializer.call(s):void 0,n.initializer=void 0),void 0===n.initializer&&(Object.defineProperty(e,t,n),n=null),n}Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=exports.SUPPORTED_PROTOCOL_VERSION=void 0;var _extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e},_createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),_dec,_dec2,_dec3,_dec4,_dec5,_dec6,_desc,_value,_class,_utils=require("./utils"),_http=require("./http"),_http2=_interopRequireDefault(_http),_endpoint=require("./endpoint"),_endpoint2=_interopRequireDefault(_endpoint),_requests=require("./requests"),requests=_interopRequireWildcard(_requests),_batch=require("./batch"),_bucket=require("./bucket"),_bucket2=_interopRequireDefault(_bucket),SUPPORTED_PROTOCOL_VERSION=exports.SUPPORTED_PROTOCOL_VERSION="v1",KintoClientBase=(_dec=(0,_utils.nobatch)("This operation is not supported within a batch operation."),_dec2=(0,_utils.nobatch)("This operation is not supported within a batch operation."),_dec3=(0,_utils.nobatch)("This operation is not supported within a batch operation."),_dec4=(0,_utils.nobatch)("This operation is not supported within a batch operation."),_dec5=(0,_utils.nobatch)("Can't use batch within a batch!"),_dec6=(0,_utils.support)("1.4","2.0"),_class=function(){function e(t){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(_classCallCheck(this,e),"string"!=typeof t||!t.length)throw new Error("Invalid remote URL: "+t);"/"===t[t.length-1]&&(t=t.slice(0,-1)),this._backoffReleaseTime=null,this.defaultReqOptions={bucket:r.bucket||"default",headers:r.headers||{},safe:!!r.safe},this._options=r,this._requests=[],this._isBatch=!!r.batch,this.remote=t,this.serverInfo=null,this.events=r.events;var i=r.requestMode,s=r.timeout;this.http=new _http2["default"](this.events,{requestMode:i,timeout:s}),this._registerHTTPEvents()}return _createClass(e,[{key:"_registerHTTPEvents",value:function(){var e=this;this._isBatch||this.events.on("backoff",function(t){e._backoffReleaseTime=t})}},{key:"bucket",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=(0,_utils.omit)(this._getRequestOptions(t),"bucket");return new _bucket2["default"](this,e,r)}},{key:"_getRequestOptions",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return _extends({},this.defaultReqOptions,e,{batch:this._isBatch,headers:_extends({},this.defaultReqOptions.headers,e.headers)})}},{key:"fetchServerInfo",value:function(){var e=this,t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.serverInfo?Promise.resolve(this.serverInfo):this.http.request(this.remote+(0,_endpoint2["default"])("root"),{headers:_extends({},this.defaultReqOptions.headers,t.headers)}).then(function(t){var r=t.json;return e.serverInfo=r,e.serverInfo})}},{key:"fetchServerSettings",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.fetchServerInfo(e).then(function(e){var t=e.settings;return t})}},{key:"fetchServerCapabilities",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.fetchServerInfo(e).then(function(e){var t=e.capabilities;return t})}},{key:"fetchUser",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.fetchServerInfo(e).then(function(e){var t=e.user;return t})}},{key:"fetchHTTPApiVersion",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.fetchServerInfo(e).then(function(e){var t=e.http_api_version;return t})}},{key:"_batchRequests",value:function(e){var t=this,r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=_extends({},this.defaultReqOptions.headers,r.headers);return e.length?this.fetchServerSettings().then(function(s){var n=s.batch_max_requests;if(n&&e.length>n){var o=(0,_utils.partition)(e,n);return(0,_utils.pMap)(o,function(e){return t._batchRequests(e,r)})}return t.execute({path:(0,_endpoint2["default"])("batch"),method:"POST",headers:i,body:{defaults:{headers:i},requests:e}}).then(function(e){var t=e.responses;return t})}):Promise.resolve([])}},{key:"batch",value:function(t){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=new e(this.remote,_extends({},this._options,this._getRequestOptions(r),{batch:!0})),s=void 0,n=void 0;r.bucket&&(s=i.bucket(r.bucket),r.collection&&(n=s.collection(r.collection)));var o=n||s||i;try{t(o)}catch(a){return Promise.reject(a)}return this._batchRequests(i._requests,r).then(function(e){return r.aggregate?(0,_batch.aggregate)(e,i._requests):e})}},{key:"execute",value:function(e){var t=this,r=arguments.length<=1||void 0===arguments[1]?{raw:!1}:arguments[1];if(this._isBatch){this._requests.push(e);var i="This result is generated from within a batch operation and should not be consumed.";return Promise.resolve(r.raw?{json:i}:i)}var s=this.fetchServerSettings().then(function(r){return t.http.request(t.remote+e.path,_extends({},e,{body:JSON.stringify(e.body)}))});return r.raw?s:s.then(function(e){var t=e.json;return t})}},{key:"listBuckets",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.execute({path:(0,_endpoint2["default"])("buckets"),headers:_extends({},this.defaultReqOptions.headers,e.headers)})}},{key:"createBucket",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=this._getRequestOptions(t);return this.execute(requests.createBucket(e,r))}},{key:"deleteBucket",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=this._getRequestOptions(t);return this.execute(requests.deleteBucket((0,_utils.toDataBody)(e),r))}},{key:"deleteBuckets",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=this._getRequestOptions(e);return this.execute(requests.deleteBuckets(t))}},{key:"remote",get:function(){return this._remote},set:function(e){var t=void 0;try{t=e.match(/\/(v\d+)\/?$/)[1]}catch(r){throw new Error("The remote URL must contain the version: "+e)}if(t!==SUPPORTED_PROTOCOL_VERSION)throw new Error("Unsupported protocol version: "+t);this._remote=e,this._version=t}},{key:"version",get:function(){return this._version}},{key:"backoff",get:function(){var e=(new Date).getTime();return this._backoffReleaseTime&&e<this._backoffReleaseTime?this._backoffReleaseTime-e:0}}]),e}(),_applyDecoratedDescriptor(_class.prototype,"fetchServerSettings",[_dec],Object.getOwnPropertyDescriptor(_class.prototype,"fetchServerSettings"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"fetchServerCapabilities",[_dec2],Object.getOwnPropertyDescriptor(_class.prototype,"fetchServerCapabilities"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"fetchUser",[_dec3],Object.getOwnPropertyDescriptor(_class.prototype,"fetchUser"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"fetchHTTPApiVersion",[_dec4],Object.getOwnPropertyDescriptor(_class.prototype,"fetchHTTPApiVersion"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"batch",[_dec5],Object.getOwnPropertyDescriptor(_class.prototype,"batch"),_class.prototype),_applyDecoratedDescriptor(_class.prototype,"deleteBuckets",[_dec6],Object.getOwnPropertyDescriptor(_class.prototype,"deleteBuckets"),_class.prototype),_class);exports["default"]=KintoClientBase;

@@ -10,0 +10,0 @@ },{"./batch":4,"./bucket":5,"./endpoint":7,"./http":9,"./requests":11,"./utils":12}],4:[function(require,module,exports){

@@ -23,3 +23,3 @@ /*

/*
* Version 0.8.2 - 41f34bb
* Version 0.8.3 - 2af513c
*/

@@ -287,5 +287,8 @@

_registerHTTPEvents() {
this.events.on("backoff", backoffMs => {
this._backoffReleaseTime = backoffMs;
});
// Prevent registering event from a batch client instance
if (!this._isBatch) {
this.events.on("backoff", backoffMs => {
this._backoffReleaseTime = backoffMs;
});
}
}

@@ -292,0 +295,0 @@

@@ -183,5 +183,8 @@ "use strict";

this.events.on("backoff", function (backoffMs) {
_this._backoffReleaseTime = backoffMs;
});
// Prevent registering event from a batch client instance
if (!this._isBatch) {
this.events.on("backoff", function (backoffMs) {
_this._backoffReleaseTime = backoffMs;
});
}
}

@@ -188,0 +191,0 @@

{
"name": "kinto-client",
"version": "0.8.2",
"version": "0.8.3",
"description": "JavaScript HTTP client for the Kinto API.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

Sorry, the diff of this file is too big to display

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