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

kuzzle-sdk

Package Overview
Dependencies
Maintainers
1
Versions
178
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kuzzle-sdk - npm Package Compare versions

Comparing version 1.4.2 to 1.4.3

2

dist/kuzzle.min.js

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

// Official Javascript SDK for Kuzzle v1.4.1 - License: Apache-2.0
// Official Javascript SDK for Kuzzle v1.4.2 - License: Apache-2.0
!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){!function(c){"use strict";function d(){var a=c.crypto||c.msCrypto;if(!j&&a&&a.getRandomValues)try{var b=new Uint8Array(16);m=j=function(){return a.getRandomValues(b),b},j()}catch(d){}if(!j){var e=new Array(16);k=j=function(){for(var a,b=0;16>b;b++)0===(3&b)&&(a=4294967296*Math.random()),e[b]=a>>>((3&b)<<3)&255;return e},"undefined"!=typeof console&&console.warn&&console.warn("[SECURITY] node-uuid: crypto not usable, falling back to insecure Math.random()")}}function e(){if("function"==typeof a)try{var b=a("crypto").randomBytes;l=j=b&&function(){return b(16)},j()}catch(c){}}function f(a,b,c){var d=b&&c||0,e=0;for(b=b||[],a.toLowerCase().replace(/[0-9a-f]{2}/g,function(a){16>e&&(b[d+e++]=q[a])});16>e;)b[d+e++]=0;return b}function g(a,b){var c=b||0,d=p;return d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]}function h(a,b,c){var d=b&&c||0,e=b||[];a=a||{};var f=null!=a.clockseq?a.clockseq:u,h=null!=a.msecs?a.msecs:(new Date).getTime(),i=null!=a.nsecs?a.nsecs:w+1,j=h-v+(i-w)/1e4;if(0>j&&null==a.clockseq&&(f=f+1&16383),(0>j||h>v)&&null==a.nsecs&&(i=0),i>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");v=h,w=i,u=f,h+=122192928e5;var k=(1e4*(268435455&h)+i)%4294967296;e[d++]=k>>>24&255,e[d++]=k>>>16&255,e[d++]=k>>>8&255,e[d++]=255&k;var l=h/4294967296*1e4&268435455;e[d++]=l>>>8&255,e[d++]=255&l,e[d++]=l>>>24&15|16,e[d++]=l>>>16&255,e[d++]=f>>>8|128,e[d++]=255&f;for(var m=a.node||t,n=0;6>n;n++)e[d+n]=m[n];return b?b:g(e)}function i(a,b,c){var d=b&&c||0;"string"==typeof a&&(b="binary"===a?new o(16):null,a=null),a=a||{};var e=a.random||(a.rng||j)();if(e[6]=15&e[6]|64,e[8]=63&e[8]|128,b)for(var f=0;16>f;f++)b[d+f]=e[f];return b||g(e)}var j,k,l,m,n;c?d():e();for(var o="function"==typeof Buffer?Buffer:Array,p=[],q={},r=0;256>r;r++)p[r]=(r+256).toString(16).substr(1),q[p[r]]=r;var s=j(),t=[1|s[0],s[1],s[2],s[3],s[4],s[5]],u=16383&(s[6]<<8|s[7]),v=0,w=0,x=i;x.v1=h,x.v4=i,x.parse=f,x.unparse=g,x.BufferClass=o,x._rng=j,x._mathRNG=k,x._nodeRNG=l,x._whatwgRNG=m,"undefined"!=typeof b&&b.exports?b.exports=x:"function"==typeof define&&define.amd?define(function(){return x}):(n=c.uuid,x.noConflict=function(){return c.uuid=n,x},c.uuid=x)}("undefined"!=typeof window?window:null)},{}],2:[function(a,b,c){function d(){var a=this,b=Date.now(),c=-1;a.queueTTL>0&&(a.offlineQueue.forEach(function(d,e){d.ts<b-a.queueTTL&&(c=e)}),-1!==c&&a.offlineQueue.splice(0,c+1)),a.queueMaxSize>0&&a.offlineQueue.length>a.queueMaxSize&&a.offlineQueue.splice(0,a.offlineQueue.length-a.queueMaxSize)}function e(a,b){var c=Date.now(),d=this;(void 0!==d.jwtToken||b)&&d.socket.once(a.requestId,function(c){c.error&&"Token expired"===c.error.message&&(d.jwtToken=void 0,d.emitEvent("jwtTokenExpired",a,b)),b&&b(c.error,c)}),d.socket.emit("kuzzle",a),d.requestHistory[a.requestId]=c,Object.keys(d.requestHistory).forEach(function(a){d.requestHistory[a]<c-1e4&&delete d.requestHistory[a]})}function f(){var a=this;a.offlineQueue.length>0?(e.call(a,a.offlineQueue[0].query,a.offlineQueue[0].cb),a.offlineQueue.shift(),setTimeout(function(){f.call(a)},Math.max(0,a.replayInterval))):a.queuing=!1}function g(){var a=this;Object.keys(a.subscriptions).forEach(function(b){Object.keys(a.subscriptions[b]).forEach(function(c){var d=a.subscriptions[b][c];d.renew(d.callback)})})}var h=a("node-uuid"),i=a("./kuzzleDataCollection");b.exports=Kuzzle=function(b,c,d){var e=this;if(!(this instanceof Kuzzle))return new Kuzzle(b,c,d);if(d||"function"!=typeof c||(d=c,c=null),!b||""===b)throw new Error("URL argument missing");return Object.defineProperties(this,{collections:{value:{},writable:!0},connectCB:{value:d},eventListeners:{value:{connected:{lastEmitted:null,listeners:[]},error:{lastEmitted:null,listeners:[]},disconnected:{lastEmitted:null,listeners:[]},reconnected:{lastEmitted:null,listeners:[]},jwtTokenExpired:{lastEmitted:null,listeners:[]}}},eventTimeout:{value:200},io:{value:null,writable:!0},queuing:{value:!1,writable:!0},requestHistory:{value:{},writable:!0},socket:{value:null,writable:!0},state:{value:"initializing",writable:!0},subscriptions:{value:{pending:{}},writable:!0},autoReconnect:{value:c&&"boolean"==typeof c.autoReconnect?c.autoReconnect:!0,enumerable:!0},defaultIndex:{value:c&&"string"==typeof c.defaultIndex?c.defaultIndex:void 0,writable:!0,enumerable:!0},reconnectionDelay:{value:c&&"number"==typeof c.reconnectionDelay?c.reconnectionDelay:1e3,enumerable:!0},url:{value:b,enumerable:!0},autoQueue:{value:!1,enumerable:!0,writable:!0},autoReplay:{value:!1,enumerable:!0,writable:!0},autoResubscribe:{value:!0,enumerable:!0,writable:!0},headers:{value:{},enumerable:!0,writable:!0},metadata:{value:{},enumerable:!0,writable:!0},offlineQueue:{value:[],enumerable:!0,writable:!0},queueFilter:{value:null,enumerable:!0,writable:!0},queueMaxSize:{value:500,enumerable:!0,writable:!0},queueTTL:{value:12e4,enumerable:!0,writable:!0},replayInterval:{value:10,enumerable:!0,writable:!0},jwtToken:{value:void 0,enumerable:!0,writable:!0}}),"undefined"!=typeof window&&window.io?this.io=window.io:this.io=a("socket.io-client"),c&&(Object.keys(c).forEach(function(a){e.hasOwnProperty(a)&&Object.getOwnPropertyDescriptor(e,a).writable&&(e[a]=c[a])}),"auto"===c.offlineMode&&this.autoReconnect&&(this.autoQueue=this.autoReplay=this.autoResubscribe=!0)),Object.defineProperty(this,"isValid",{value:function(){if("disconnected"===e.state)throw new Error("This Kuzzle object has been invalidated. Did you try to access it after a disconnect call?")}}),Object.defineProperty(this,"addHeaders",{value:function(a,b){return Object.keys(b).forEach(function(c){a[c]||(a[c]=b[c])}),a}}),Object.defineProperty(this,"callbackRequired",{value:function(a,b){if(!b||"function"!=typeof b)throw new Error(a+": a callback argument is required for read queries")}}),Object.defineProperty(this,"emitEvent",{value:function(a){var b=Date.now(),c=Array.prototype.slice.call(arguments,1);return this.eventListeners[a].lastEmitted&&this.eventListeners[a].lastEmitted>=b-this.eventTimeout?!1:(this.eventListeners[a].listeners.forEach(function(a){a.fn.apply(this,c)}),void(this.eventListeners[a].lastEmitted=b))}}),c&&c.connect&&"auto"!==c.connect?this.state="ready":this.connect(),this.bluebird?this.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["getAllStatistics","getServerInfo","getStatistics","listCollections","listIndexes","login","logout","now","query","checkToken","whoAmI"];return d&&-1!==e.indexOf(a)}}):this},Kuzzle.prototype.connect=function(){var a=this;return-1===["initializing","ready","disconnected","error","offline"].indexOf(this.state)?(a.connectCB&&a.connectCB(null,a),a):(a.state="connecting",a.socket=a.io(a.url,{reconnection:a.autoReconnect,reconnectionDelay:a.reconnectionDelay,forceNew:!0}),a.socket.once("connect",function(){a.state="connected",g.call(a),f.call(a),a.emitEvent("connected"),a.connectCB&&a.connectCB(null,a)}),a.socket.on("connect_error",function(b){a.state="error",a.emitEvent("error"),a.connectCB&&a.connectCB(b)}),a.socket.on("disconnect",function(){a.state="offline",a.autoReconnect||a.disconnect(),a.autoQueue&&(a.queuing=!0),a.emitEvent("disconnected")}),a.socket.on("reconnect",function(){a.state="connected",a.autoResubscribe&&g.call(a),a.autoReplay&&(d.call(a),f.call(a)),a.emitEvent("reconnected")}),this)},Kuzzle.prototype.setJwtToken=function(a){return this.jwtToken=a,this},Kuzzle.prototype.getJwtToken=function(){return this.jwtToken},Kuzzle.prototype.login=function(a,b,c,d){var e=this,f={strategy:a};return d||"function"!=typeof c||(d=c,c=null),Object.keys(b).forEach(function(a){f[a]=b[a]}),-1!==["number","string"].indexOf(typeof c)&&(f.expiresIn=c),this.query({controller:"auth",action:"login"},{body:f},{queuable:!1},function(a,b){if(null===a)e.setJwtToken(b.result.jwt),g.call(e),"function"==typeof d&&d(null,e);else{if("function"!=typeof d)throw new Error(a.message);d(a)}}),e},Kuzzle.prototype.logout=function(a){var b=this,c={action:"logout",controller:"auth",requestId:h.v4(),body:{}};return this.query({controller:"auth",action:"logout"},c,{queuable:!1},function(c){null===c?(b.setJwtToken(void 0),"function"==typeof a&&a(null,b)):"function"==typeof a&&a(c)}),b},Kuzzle.prototype.checkToken=function(a,b){var c=this,d={body:{token:a}};return this.callbackRequired("Kuzzle.checkToken",b),this.query({controller:"auth",action:"checkToken"},d,{},b),c},Kuzzle.prototype.whoAmI=function(a){var b=this;return this.callbackRequired("Kuzzle.whoAmI",a),this.query({controller:"auth",action:"getCurrentUser"},{},{},a),b},Kuzzle.prototype.addListener=function(a,b){var c,d=Object.keys(this.eventListeners),e=typeof b;if(this.isValid(),-1===d.indexOf(a))throw new Error("["+a+"] is not a known event. Known events: "+d.toString());if("function"!==e)throw new Error("Invalid listener type: expected a function, got a "+e);return c=h.v1(),this.eventListeners[a].listeners.push({id:c,fn:b}),c},Kuzzle.prototype.getAllStatistics=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.getAllStatistics",b),this.query({controller:"admin",action:"getAllStats"},{},a,function(a,c){return a?b(a):void b(null,c.result.hits)}),this},Kuzzle.prototype.getStatistics=function(a,b,c){var d;return c||(1===arguments.length?(c=arguments[0],b=null,a=null):(c=arguments[1],"object"==typeof arguments[0]?(b=arguments[0],a=null):(a=arguments[0],b=null))),d=function(b,d){return b?c(b):void(a?c(null,d.result.hits):c(null,[d.result]))},this.callbackRequired("Kuzzle.getStatistics",c),a?this.query({controller:"admin",action:"getStats"},{body:{startTime:a}},b,d):this.query({controller:"admin",action:"getLastStats"},{},b,d),this},Kuzzle.prototype.dataCollectionFactory=function(a,b,c){if(this.isValid(),1===arguments.length?(b=arguments[0],a=this.defaultIndex):2===arguments.length&&"object"==typeof b&&(c=b,b=a,a=this.defaultIndex),!a)throw new Error("Unable to create a new data collection object: no index specified");return this.collections[a]||(this.collections[a]={}),this.collections[a][b]||(this.collections[a][b]=new i(this,a,b,c)),this.collections[a][b]},Kuzzle.prototype.flushQueue=function(){return this.offlineQueue=[],this},Kuzzle.prototype.listCollections=function(){var a,b,c,d="all",e=Array.prototype.slice.call(arguments);if(e.forEach(function(d){switch(typeof d){case"string":a=d;break;case"object":b=d;break;case"function":c=d}}),!a){if(!this.defaultIndex)throw new Error("Kuzzle.listCollections: index required");a=this.defaultIndex}return this.callbackRequired("Kuzzle.listCollections",c),b&&b.type&&(d=b.type),this.query({index:a,controller:"read",action:"listCollections"},{body:{type:d}},b,function(a,b){return a?c(a):c(null,b.result.collections)}),this},Kuzzle.prototype.listIndexes=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.listIndexes",b),this.query({controller:"read",action:"listIndexes"},{},a,function(a,c){return a?b(a):b(null,c.result.indexes)}),this},Kuzzle.prototype.disconnect=function(){var a;this.logout(),this.state="disconnected",this.socket.close(),this.socket=null;for(a in this.collections)this.collections.hasOwnProperty(a)&&delete this.collections[a]},Kuzzle.prototype.getServerInfo=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.getServerInfo",b),this.query({controller:"read",action:"serverInfo"},{},a,function(a,c){return a?b(a):void b(null,c.result.serverInfo)}),this},Kuzzle.prototype.now=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.now",b),this.query({controller:"read",action:"now"},{},a,function(a,c){return a?b(a):void b(null,c.result.now)}),this},Kuzzle.prototype.query=function(a,b,c,f){var g,i={action:a.action,controller:a.controller,metadata:this.metadata},j=this;if(this.isValid(),f||"function"!=typeof c||(f=c,c=null),c&&(c.metadata&&Object.keys(c.metadata).forEach(function(a){i.metadata[a]=c.metadata[a]}),c.queuable===!1&&"offline"===j.state))return j;b.metadata&&Object.keys(b.metadata).forEach(function(a){i.metadata[a]=b.metadata[a]});for(g in b)"metadata"!==g&&b.hasOwnProperty(g)&&(i[g]=b[g]);return i=j.addHeaders(i,this.headers),void 0!==j.jwtToken&&(i.headers=i.headers||{},i.headers.authorization="Bearer "+j.jwtToken),a.collection&&(i.collection=a.collection),a.index&&(i.index=a.index),i.requestId||(i.requestId=h.v4()),"connected"===j.state||c&&c.queuable===!1?"connected"===j.state?e.call(this,i,f):f&&f(new Error("Unable to execute request: not connected to a Kuzzle server.\nDiscarded request: "+i)):(j.queuing||-1!==["initializing","connecting"].indexOf(j.state))&&(d.call(this,i,f),j.queueFilter?j.queueFilter(i)&&j.offlineQueue.push({ts:Date.now(),query:i,cb:f}):j.offlineQueue.push({ts:Date.now(),query:i,cb:f})),j},Kuzzle.prototype.removeAllListeners=function(a){var b=Object.keys(this.eventListeners),c=this;if(a){if(-1===b.indexOf(a))throw new Error("["+a+"] is not a known event. Known events: "+b.toString());this.eventListeners[a].listeners=[]}else b.forEach(function(a){c.eventListeners[a].listeners=[]})},Kuzzle.prototype.removeListener=function(a,b){var c=Object.keys(this.eventListeners),d=this;if(-1===c.indexOf(a))throw new Error("["+a+"] is not a known event. Known events: "+c.toString());this.eventListeners[a].listeners.forEach(function(c,e){c.id===b&&d.eventListeners[a].listeners.splice(e,1)})},Kuzzle.prototype.replayQueue=function(){return"offline"===this.state||this.autoReplay||(d.call(this),f.call(this)),this},Kuzzle.prototype.setDefaultIndex=function(a){if("string"!=typeof a)throw new Error("Invalid default index: ["+a+"] (an index name is expected)");if(0===a.length)throw new Error("Cannot set an empty index as the default index");return this.defaultIndex=a,this},Kuzzle.prototype.setHeaders=function(a,b){var c=this;if("object"!=typeof a||Array.isArray(a))throw new Error("Expected a content object, received a "+typeof a);return b?c.headers=a:Object.keys(a).forEach(function(b){c.headers[b]=a[b]}),c},Kuzzle.prototype.startQueuing=function(){return"offline"!==this.state||this.autoQueue||(this.queuing=!0),this},Kuzzle.prototype.stopQueuing=function(){return"offline"!==this.state||this.autoQueue||(this.queuing=!1),this}},{"./kuzzleDataCollection":3,"node-uuid":1,"socket.io-client":void 0}],3:[function(a,b,c){function d(a,b,c){if(!b||!c)throw new Error("The KuzzleDataCollection object constructor needs an index and a collection arguments");return Object.defineProperties(this,{collection:{value:c,enumerable:!0},index:{value:b,enumerable:!0},kuzzle:{value:a,enumerable:!0},headers:{value:JSON.parse(JSON.stringify(a.headers)),enumerable:!0,writable:!0}}),Object.defineProperty(this,"buildQueryArgs",{value:function(a,b){return{controller:a,action:b,collection:this.collection,index:this.index}}}),this.kuzzle.bluebird?this.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["publishMessage","setHeaders","subscribe"];return d&&-1===e.indexOf(a)}}):this}var e=a("./kuzzleDocument"),f=a("./kuzzleDataMapping"),g=a("./kuzzleRoom");d.prototype.advancedSearch=function(a,b,c){var d,f=this;return c||"function"!=typeof b||(c=b,b=null),f.kuzzle.callbackRequired("KuzzleDataCollection.advancedSearch",c),d=f.kuzzle.addHeaders({body:a},this.headers),f.kuzzle.query(this.buildQueryArgs("read","search"),d,b,function(a,b){var d=[];return a?c(a):(b.result.hits.forEach(function(a){var b=new e(f,a._id,a._source);b.version=a._version,d.push(b)}),void c(null,{total:b.result.total,documents:d}))}),this},d.prototype.count=function(a,b,c){var d;return c||"function"!=typeof b||(c=b,b=null),this.kuzzle.callbackRequired("KuzzleDataCollection.count",c),d=this.kuzzle.addHeaders({body:a},this.headers),this.kuzzle.query(this.buildQueryArgs("read","count"),d,b,function(a,b){return a?c(a):void c(null,b.result.count)}),this},d.prototype.create=function(a,b){var c={};return b||"function"!=typeof a||(b=a,a=null),c=this.kuzzle.addHeaders(c,this.headers),this.kuzzle.query(this.buildQueryArgs("write","createCollection"),c,a,b),this},d.prototype.createDocument=function(a,b,c,d){var f=this,g={},h="create";return a&&"string"!=typeof a&&(d=c,c=b,b=a,a=null),d||"function"!=typeof c||(d=c,c=null),b instanceof e?g=b.toJSON():g.body=b,c&&(h=c.updateIfExist?"createOrReplace":"create"),a&&(g._id=a),g.persist=!0,g=f.kuzzle.addHeaders(g,f.headers),d?f.kuzzle.query(this.buildQueryArgs("write",h),g,c,function(a,b){var c;return a?d(a):(c=new e(f,b.result._id,b.result._source),c.version=b.result._version,void d(null,c))}):f.kuzzle.query(this.buildQueryArgs("write",h),g,c),this},d.prototype["delete"]=function(a,b){var c={};return b||"function"!=typeof a||(b=a,a=null),c=this.kuzzle.addHeaders(c,this.headers),this.kuzzle.query(this.buildQueryArgs("admin","deleteCollection"),c,a,b),this},d.prototype.deleteDocument=function(a,b,c){var d,e={};return"string"==typeof a?(e._id=a,d="delete"):(e.body=a,d="deleteByQuery"),c||"function"!=typeof b||(c=b,b=null),e=this.kuzzle.addHeaders(e,this.headers),c?this.kuzzle.query(this.buildQueryArgs("write",d),e,b,function(a,b){return a?c(a):void("delete"===d?c(null,[b.result._id]):c(null,b.result.ids))}):this.kuzzle.query(this.buildQueryArgs("write",d),e,b),this},d.prototype.fetchDocument=function(a,b,c){var d={_id:a},f=this;return c||"function"!=typeof b||(c=b,b=null),f.kuzzle.callbackRequired("KuzzleDataCollection.fetch",c),d=f.kuzzle.addHeaders(d,this.headers),f.kuzzle.query(this.buildQueryArgs("read","get"),d,b,function(a,b){var d;return a?c(a):(d=new e(f,b.result._id,b.result._source),d.version=b.result._version,void c(null,d))}),this},d.prototype.fetchAllDocuments=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.kuzzle.callbackRequired("KuzzleDataCollection.fetchAll",b),this.advancedSearch({},a,b),this},d.prototype.getMapping=function(a,b){var c;return b||"function"!=typeof a||(b=a,a=null),this.kuzzle.callbackRequired("KuzzleDataCollection.getMapping",b),c=new f(this),c.refresh(a,b),this},d.prototype.publishMessage=function(a,b){var c={};return a instanceof e?c=a.toJSON():c.body=a,c=this.kuzzle.addHeaders(c,this.headers),this.kuzzle.query(this.buildQueryArgs("write","publish"),c,b),this},d.prototype.replaceDocument=function(a,b,c,d){var f=this,g={_id:a,body:b};return d||"function"!=typeof c||(d=c,c=null),g=f.kuzzle.addHeaders(g,this.headers),d?f.kuzzle.query(this.buildQueryArgs("write","createOrReplace"),g,c,function(a,b){var c;return a?d(a):(c=new e(f,b.result._id,b.result._source),c.version=b.result._version,void d(null,c))}):f.kuzzle.query(this.buildQueryArgs("write","createOrReplace"),g,c),this},d.prototype.subscribe=function(a,b,c){var d;return c||"function"!=typeof b||(c=b,b=null),this.kuzzle.callbackRequired("KuzzleDataCollection.subscribe",c),d=new g(this,b),d.renew(a,c)},d.prototype.truncate=function(a,b){var c={};return b||"function"!=typeof a||(b=a,a=null),c=this.kuzzle.addHeaders(c,this.headers),this.kuzzle.query(this.buildQueryArgs("admin","truncateCollection"),c,a,b),this},d.prototype.updateDocument=function(a,b,c,d){var f={_id:a,body:b},g=this;return d||"function"!=typeof c||(d=c,c=null),f=g.kuzzle.addHeaders(f,this.headers),d?g.kuzzle.query(this.buildQueryArgs("write","update"),f,c,function(a,b){var c;return a?d(a):(c=new e(g,b.result._id),void c.refresh(d))}):g.kuzzle.query(this.buildQueryArgs("write","update"),f,c),g},d.prototype.documentFactory=function(a,b){return new e(this,a,b)},d.prototype.roomFactory=function(a){return new g(this,a)},d.prototype.dataMappingFactory=function(a){return new f(this,a)},d.prototype.setHeaders=function(a,b){return this.kuzzle.setHeaders.call(this,a,b),this},b.exports=d},{"./kuzzleDataMapping":4,"./kuzzleDocument":5,"./kuzzleRoom":6}],4:[function(a,b,c){function d(a,b){return Object.defineProperties(this,{collection:{value:a,eunmerable:!0},kuzzle:{value:a.kuzzle,enumerable:!0},headers:{value:JSON.parse(JSON.stringify(a.headers)),enumerable:!0,writable:!0},mapping:{value:b||{},enumerable:!0,writable:!0}}),this.kuzzle.bluebird?this.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["set","setHeaders"];return d&&-1===e.indexOf(a)}}):this}d.prototype.apply=function(a,b){var c=this,d=this.kuzzle.addHeaders({body:{properties:this.mapping}},this.headers);return b||"function"!=typeof a||(b=a,a=null),c.kuzzle.query(this.collection.buildQueryArgs("admin","updateMapping"),d,a,function(d){return d?b?b(d):!1:void c.refresh(a,b)}),this},d.prototype.refresh=function(a,b){var c=this,d=this.kuzzle.addHeaders({},this.headers);return b||"function"!=typeof a||(b=a,a=null),this.kuzzle.query(this.collection.buildQueryArgs("admin","getMapping"),d,a,function(a,d){return a?b?b(a):!1:d.result[c.collection.index]?d.result[c.collection.index].mappings[c.collection.collection]?(c.mapping=d.result[c.collection.index].mappings[c.collection.collection].properties,void(b&&b(null,c))):b?b(new Error("No mapping found for collection "+c.collection.collection)):!1:b?b(new Error("No mapping found for index "+c.collection.index)):!1}),this},d.prototype.set=function(a,b){return this.mapping[a]=b,this},d.prototype.setHeaders=function(a,b){return this.kuzzle.setHeaders.call(this,a,b),this},b.exports=d},{}],5:[function(a,b,c){function d(a,b,c){return Object.defineProperties(this,{queue:{value:[],writable:!0},refreshing:{value:!1,writable:!0},collection:{value:a.collection,enumerable:!0},dataCollection:{value:a,enumerable:!0},kuzzle:{value:a.kuzzle,enumerable:!0},id:{value:void 0,enumerable:!0,writable:!0},content:{value:{},writable:!0,enumerable:!0},headers:{value:JSON.parse(JSON.stringify(a.headers)),enumerable:!0,writable:!0},version:{value:void 0,enumerable:!0,writable:!0}}),!c&&b&&"object"==typeof b&&(c=b,b=null),c&&(c._version&&(this.version=c._version,delete c._version),this.setContent(c,!0)),b&&Object.defineProperty(this,"id",{value:b,enumerable:!0}),this.kuzzle.bluebird?this.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["delete","refresh","save"];return d&&-1!==e.indexOf(a)}}):this}function e(){for(var a;this.queue.length>0;)a=this.queue.shift(),this[a.action].apply(this,a.args)}d.prototype.toJSON=function(){var a={};return this.id&&(a._id=this.id),a.body=this.content,a._version=this.version,a=this.kuzzle.addHeaders(a,this.headers)},d.prototype.toString=function(){return JSON.stringify(this.toJSON())},d.prototype["delete"]=function(a,b){var c=this;if(b||"function"!=typeof a||(b=a,a=null),this.refreshing)return this.queue.push({action:"delete",args:[a,b]}),this;if(!this.id)throw new Error("KuzzleDocument.delete: cannot delete a document without a document ID");return b?this.kuzzle.query(this.dataCollection.buildQueryArgs("write","delete"),this.toJSON(),a,function(a){return a?b(a):void b(null,c)}):this.kuzzle.query(this.dataCollection.buildQueryArgs("write","delete"),this.toJSON(),a),this},d.prototype.refresh=function(a,b){var c=this;if(b||"function"!=typeof a||(b=a,a=null),this.refreshing)return this.queue.push({action:"refresh",args:[a,b]}),this;if(!c.id)throw new Error("KuzzleDocument.refresh: cannot retrieve a document if no ID has been provided");return c.refreshing=!0,c.kuzzle.query(c.dataCollection.buildQueryArgs("read","get"),{_id:c.id},a,function(a,d){return a?(c.refreshing=!1,c.queue=[],b?b(a):!1):(c.version=d.result._version,c.content=d.result._source,b&&b(null,c),c.refreshing=!1,void e.call(c))}),this},d.prototype.save=function(a,b){var c=this.toJSON(),d=this;return a&&void 0===b&&"function"==typeof a&&(b=a,a=null),d.refreshing?(d.queue.push({action:"save",args:[a,b]}),d):(c.persist=!0,d.kuzzle.query(this.dataCollection.buildQueryArgs("write","createOrReplace"),c,a,function(a,c){return a?b?b(a):!1:(d.id=c.result._id,d.version=c.result._version,void(b&&b(null,d)))}),d)},d.prototype.publish=function(a){var b=this.toJSON();return this.refreshing?(this.queue.push({action:"publish",args:[a]}),this):(this.kuzzle.query(this.dataCollection.buildQueryArgs("write","publish"),b,a),this)},d.prototype.setContent=function(a,b){var c=this;return this.refreshing?(this.queue.push({action:"setContent",args:[a,b]}),this):(b?this.content=a:Object.keys(a).forEach(function(b){c.content[b]=a[b]}),this)},d.prototype.subscribe=function(a,b){var c;if(a&&!b&&"function"==typeof a&&(b=a,a=null),this.kuzzle.callbackRequired("KuzzleDocument.subscribe",b),!this.id)throw new Error("KuzzleDocument.subscribe: cannot subscribe to a document if no ID has been provided");return c={ids:{values:[this.id]}},this.dataCollection.subscribe(c,a,b)},d.prototype.setHeaders=function(a,b){return this.kuzzle.setHeaders.call(this,a,b),this},b.exports=d},{}],6:[function(a,b,c){function d(a,b){return Object.defineProperties(this,{callback:{value:null,writable:!0},channel:{value:null,writable:!0},id:{value:g.v4()},lastRenewal:{value:null,writable:!0},notifier:{value:null,writable:!0},queue:{value:[],writable:!0},renewalDelay:{value:500},scope:{value:b&&b.scope?b.scope:"all"},state:{value:b&&b.state?b.state:"done"},subscribing:{value:!1,writable:!0},users:{value:b&&b.users?b.users:"none"},collection:{value:a,enumerable:!0},kuzzle:{value:a.kuzzle,enumerable:!0},filters:{value:null,enumerable:!0,writable:!0},headers:{value:JSON.parse(JSON.stringify(a.headers)),enumerable:!0,writable:!0},metadata:{value:b&&b.metadata?b.metadata:{},enumerable:!0,writable:!0},roomId:{value:null,enumerable:!0,writable:!0},subscribeToSelf:{value:b&&"boolean"==typeof b.subscribeToSelf?b.subscribeToSelf:!0,enumerable:!0,writable:!0}}),this.kuzzle.bluebird?this.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["count"];return d&&-1!==e.indexOf(a)}}):this}function e(a){return a.error?this.callback(a.error):"jwtTokenExpired"===a.action?(this.kuzzle.jwtToken=void 0,this.kuzzle.emitEvent("jwtTokenExpired")):void(this.kuzzle.requestHistory[a.requestId]?(this.subscribeToSelf&&this.callback(null,a),delete this.kuzzle.requestHistory[a.requestId]):this.callback(null,a))}function f(){for(var a;this.queue.length>0;)a=this.queue.shift(),this[a.action].apply(this,a.args)}var g=a("node-uuid");d.prototype.count=function(a){var b;return this.kuzzle.callbackRequired("KuzzleRoom.count",a),b=this.kuzzle.addHeaders({body:{roomId:this.roomId}},this.headers),this.subscribing?(this.queue.push({action:"count",args:[a]}),this):(this.kuzzle.query(this.collection.buildQueryArgs("subscribe","count"),b,function(b,c){return b?a(b):void a(null,c.result.count)}),this)},d.prototype.renew=function(a,b){var c=Date.now(),d={scope:this.scope,state:this.state,users:this.users},g=this;return!b&&a&&"function"==typeof a&&(b=a,a=null),g.lastRenewal&&c-g.lastRenewal<=g.renewalDelay?g:(g.lastRenewal=c,a&&(g.filters=a),"connected"!==g.kuzzle.state?(g.callback=b,g.kuzzle.subscriptions.pending[g.id]=g,g):g.subscribing?(g.queue.push({action:"renew",args:[a,b]}),g):(g.kuzzle.callbackRequired("KuzzleRoom.renew",b),g.unsubscribe(),g.roomId=null,g.subscribing=!0,g.callback=b,g.kuzzle.subscriptions.pending[g.id]=g,d.body=g.filters,d=g.kuzzle.addHeaders(d,this.headers),g.kuzzle.query(g.collection.buildQueryArgs("subscribe","on"),d,{metadata:g.metadata},function(a,b){if(delete g.kuzzle.subscriptions.pending[g.id],g.subscribing=!1,a)throw g.queue=[],new Error("Error during Kuzzle subscription: "+a.message);g.roomId=b.result.roomId,g.channel=b.result.channel,g.kuzzle.subscriptions[g.roomId]||(g.kuzzle.subscriptions[g.roomId]={}),g.kuzzle.subscriptions[g.roomId][g.id]=g,g.notifier=e.bind(g),g.kuzzle.socket.on(g.channel,g.notifier),f.call(g)}),g))},d.prototype.unsubscribe=function(){var a,b=this,c=b.roomId;return b.subscribing?(b.queue.push({action:"unsubscribe",args:[]}),b):(c&&(b.kuzzle.socket.off(b.channel,this.notifier),1===Object.keys(b.kuzzle.subscriptions[c]).length?(delete b.kuzzle.subscriptions[c],0===Object.keys(b.kuzzle.subscriptions.pending).length?b.kuzzle.query(b.collection.buildQueryArgs("subscribe","off"),{body:{roomId:c}}):a=setInterval(function(){0===Object.keys(b.kuzzle.subscriptions.pending).length&&(b.kuzzle.subscriptions[c]||b.kuzzle.query(b.collection.buildQueryArgs("subscribe","off"),{body:{roomId:c}}),clearInterval(a))},100)):delete b.kuzzle.subscriptions[c][b.id],b.roomId=null),b)},d.prototype.setHeaders=function(a,b){return this.kuzzle.setHeaders.call(this,a,b),this},b.exports=d},{"node-uuid":1}]},{},[2]);
//# sourceMappingURL=kuzzle.min.map
{
"name": "kuzzle-sdk",
"version": "1.4.2",
"version": "1.4.3",
"description": "Official Javascript SDK for Kuzzle",

@@ -5,0 +5,0 @@ "author": "The Kuzzle Team <support@kuzzle.io>",

@@ -175,4 +175,2 @@ var

self.lastRenewal = now;
if (filters) {

@@ -217,2 +215,3 @@ self.filters = filters;

self.lastRenewal = now;
self.roomId = response.result.roomId;

@@ -219,0 +218,0 @@ self.channel = response.result.channel;

@@ -147,4 +147,8 @@ var

it('should send the right query to Kuzzle', function () {
var
before = Date.now();
should(room.renew({}, function () {})).be.exactly(room);
should(emitted).be.true();
should(room.lastRenewal).be.within(before, Date.now());
});

@@ -190,2 +194,3 @@

should(dequeued).be.false();
should(room.lastRenewal).be.null();
should(room.queue).be.empty();

@@ -200,2 +205,3 @@ });

should(emitted).be.false();
should(room.lastRenewal).be.null();
should(kuzzle.subscriptions.pending[room.id]).be.eql(room);

@@ -212,3 +218,3 @@ done();

kuzzle.query = function () { renewals++; arguments[3](null, result); }
kuzzle.query = function () { renewals++; arguments[3](null, result); };
room.renew({}, function () {});

@@ -215,0 +221,0 @@ after = Date.now();

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

// Official Javascript SDK for Kuzzle v1.4.2 - License: Apache-2.0
!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){!function(c){"use strict";function d(){var a=c.crypto||c.msCrypto;if(!j&&a&&a.getRandomValues)try{var b=new Uint8Array(16);m=j=function(){return a.getRandomValues(b),b},j()}catch(d){}if(!j){var e=new Array(16);k=j=function(){for(var a,b=0;16>b;b++)0===(3&b)&&(a=4294967296*Math.random()),e[b]=a>>>((3&b)<<3)&255;return e},"undefined"!=typeof console&&console.warn&&console.warn("[SECURITY] node-uuid: crypto not usable, falling back to insecure Math.random()")}}function e(){if("function"==typeof a)try{var b=a("crypto").randomBytes;l=j=b&&function(){return b(16)},j()}catch(c){}}function f(a,b,c){var d=b&&c||0,e=0;for(b=b||[],a.toLowerCase().replace(/[0-9a-f]{2}/g,function(a){16>e&&(b[d+e++]=q[a])});16>e;)b[d+e++]=0;return b}function g(a,b){var c=b||0,d=p;return d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]}function h(a,b,c){var d=b&&c||0,e=b||[];a=a||{};var f=null!=a.clockseq?a.clockseq:u,h=null!=a.msecs?a.msecs:(new Date).getTime(),i=null!=a.nsecs?a.nsecs:w+1,j=h-v+(i-w)/1e4;if(0>j&&null==a.clockseq&&(f=f+1&16383),(0>j||h>v)&&null==a.nsecs&&(i=0),i>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");v=h,w=i,u=f,h+=122192928e5;var k=(1e4*(268435455&h)+i)%4294967296;e[d++]=k>>>24&255,e[d++]=k>>>16&255,e[d++]=k>>>8&255,e[d++]=255&k;var l=h/4294967296*1e4&268435455;e[d++]=l>>>8&255,e[d++]=255&l,e[d++]=l>>>24&15|16,e[d++]=l>>>16&255,e[d++]=f>>>8|128,e[d++]=255&f;for(var m=a.node||t,n=0;6>n;n++)e[d+n]=m[n];return b?b:g(e)}function i(a,b,c){var d=b&&c||0;"string"==typeof a&&(b="binary"===a?new o(16):null,a=null),a=a||{};var e=a.random||(a.rng||j)();if(e[6]=15&e[6]|64,e[8]=63&e[8]|128,b)for(var f=0;16>f;f++)b[d+f]=e[f];return b||g(e)}var j,k,l,m,n;c?d():e();for(var o="function"==typeof Buffer?Buffer:Array,p=[],q={},r=0;256>r;r++)p[r]=(r+256).toString(16).substr(1),q[p[r]]=r;var s=j(),t=[1|s[0],s[1],s[2],s[3],s[4],s[5]],u=16383&(s[6]<<8|s[7]),v=0,w=0,x=i;x.v1=h,x.v4=i,x.parse=f,x.unparse=g,x.BufferClass=o,x._rng=j,x._mathRNG=k,x._nodeRNG=l,x._whatwgRNG=m,"undefined"!=typeof b&&b.exports?b.exports=x:"function"==typeof define&&define.amd?define(function(){return x}):(n=c.uuid,x.noConflict=function(){return c.uuid=n,x},c.uuid=x)}("undefined"!=typeof window?window:null)},{}],2:[function(a,b,c){function d(){var a=this,b=Date.now(),c=-1;a.queueTTL>0&&(a.offlineQueue.forEach(function(d,e){d.ts<b-a.queueTTL&&(c=e)}),-1!==c&&a.offlineQueue.splice(0,c+1)),a.queueMaxSize>0&&a.offlineQueue.length>a.queueMaxSize&&a.offlineQueue.splice(0,a.offlineQueue.length-a.queueMaxSize)}function e(a,b){var c=Date.now(),d=this;(void 0!==d.jwtToken||b)&&d.socket.once(a.requestId,function(c){c.error&&"Token expired"===c.error.message&&(d.jwtToken=void 0,d.emitEvent("jwtTokenExpired",a,b)),b&&b(c.error,c)}),d.socket.emit("kuzzle",a),d.requestHistory[a.requestId]=c,Object.keys(d.requestHistory).forEach(function(a){d.requestHistory[a]<c-1e4&&delete d.requestHistory[a]})}function f(){var a=this;a.offlineQueue.length>0?(e.call(a,a.offlineQueue[0].query,a.offlineQueue[0].cb),a.offlineQueue.shift(),setTimeout(function(){f.call(a)},Math.max(0,a.replayInterval))):a.queuing=!1}function g(){var a=this;Object.keys(a.subscriptions).forEach(function(b){Object.keys(a.subscriptions[b]).forEach(function(c){var d=a.subscriptions[b][c];d.renew(d.callback)})})}var h=a("node-uuid"),i=a("./kuzzleDataCollection");b.exports=Kuzzle=function(b,c,d){var e=this;if(!(this instanceof Kuzzle))return new Kuzzle(b,c,d);if(d||"function"!=typeof c||(d=c,c=null),!b||""===b)throw new Error("URL argument missing");return Object.defineProperties(this,{collections:{value:{},writable:!0},connectCB:{value:d},eventListeners:{value:{connected:{lastEmitted:null,listeners:[]},error:{lastEmitted:null,listeners:[]},disconnected:{lastEmitted:null,listeners:[]},reconnected:{lastEmitted:null,listeners:[]},jwtTokenExpired:{lastEmitted:null,listeners:[]}}},eventTimeout:{value:200},io:{value:null,writable:!0},queuing:{value:!1,writable:!0},requestHistory:{value:{},writable:!0},socket:{value:null,writable:!0},state:{value:"initializing",writable:!0},subscriptions:{value:{pending:{}},writable:!0},autoReconnect:{value:c&&"boolean"==typeof c.autoReconnect?c.autoReconnect:!0,enumerable:!0},defaultIndex:{value:c&&"string"==typeof c.defaultIndex?c.defaultIndex:void 0,writable:!0,enumerable:!0},reconnectionDelay:{value:c&&"number"==typeof c.reconnectionDelay?c.reconnectionDelay:1e3,enumerable:!0},url:{value:b,enumerable:!0},autoQueue:{value:!1,enumerable:!0,writable:!0},autoReplay:{value:!1,enumerable:!0,writable:!0},autoResubscribe:{value:!0,enumerable:!0,writable:!0},headers:{value:{},enumerable:!0,writable:!0},metadata:{value:{},enumerable:!0,writable:!0},offlineQueue:{value:[],enumerable:!0,writable:!0},queueFilter:{value:null,enumerable:!0,writable:!0},queueMaxSize:{value:500,enumerable:!0,writable:!0},queueTTL:{value:12e4,enumerable:!0,writable:!0},replayInterval:{value:10,enumerable:!0,writable:!0},jwtToken:{value:void 0,enumerable:!0,writable:!0}}),"undefined"!=typeof window&&window.io?this.io=window.io:this.io=a("socket.io-client"),c&&(Object.keys(c).forEach(function(a){e.hasOwnProperty(a)&&Object.getOwnPropertyDescriptor(e,a).writable&&(e[a]=c[a])}),"auto"===c.offlineMode&&this.autoReconnect&&(this.autoQueue=this.autoReplay=this.autoResubscribe=!0)),Object.defineProperty(this,"isValid",{value:function(){if("disconnected"===e.state)throw new Error("This Kuzzle object has been invalidated. Did you try to access it after a disconnect call?")}}),Object.defineProperty(this,"addHeaders",{value:function(a,b){return Object.keys(b).forEach(function(c){a[c]||(a[c]=b[c])}),a}}),Object.defineProperty(this,"callbackRequired",{value:function(a,b){if(!b||"function"!=typeof b)throw new Error(a+": a callback argument is required for read queries")}}),Object.defineProperty(this,"emitEvent",{value:function(a){var b=Date.now(),c=Array.prototype.slice.call(arguments,1);return this.eventListeners[a].lastEmitted&&this.eventListeners[a].lastEmitted>=b-this.eventTimeout?!1:(this.eventListeners[a].listeners.forEach(function(a){a.fn.apply(this,c)}),void(this.eventListeners[a].lastEmitted=b))}}),c&&c.connect&&"auto"!==c.connect?this.state="ready":this.connect(),this.bluebird?this.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["getAllStatistics","getServerInfo","getStatistics","listCollections","listIndexes","login","logout","now","query","checkToken","whoAmI"];return d&&-1!==e.indexOf(a)}}):this},Kuzzle.prototype.connect=function(){var a=this;return-1===["initializing","ready","disconnected","error","offline"].indexOf(this.state)?(a.connectCB&&a.connectCB(null,a),a):(a.state="connecting",a.socket=a.io(a.url,{reconnection:a.autoReconnect,reconnectionDelay:a.reconnectionDelay,forceNew:!0}),a.socket.once("connect",function(){a.state="connected",g.call(a),f.call(a),a.emitEvent("connected"),a.connectCB&&a.connectCB(null,a)}),a.socket.on("connect_error",function(b){a.state="error",a.emitEvent("error"),a.connectCB&&a.connectCB(b)}),a.socket.on("disconnect",function(){a.state="offline",a.autoReconnect||a.disconnect(),a.autoQueue&&(a.queuing=!0),a.emitEvent("disconnected")}),a.socket.on("reconnect",function(){a.state="connected",a.autoResubscribe&&g.call(a),a.autoReplay&&(d.call(a),f.call(a)),a.emitEvent("reconnected")}),this)},Kuzzle.prototype.setJwtToken=function(a){return this.jwtToken=a,this},Kuzzle.prototype.getJwtToken=function(){return this.jwtToken},Kuzzle.prototype.login=function(a,b,c,d){var e=this,f={strategy:a};return d||"function"!=typeof c||(d=c,c=null),Object.keys(b).forEach(function(a){f[a]=b[a]}),-1!==["number","string"].indexOf(typeof c)&&(f.expiresIn=c),this.query({controller:"auth",action:"login"},{body:f},{queuable:!1},function(a,b){if(null===a)e.setJwtToken(b.result.jwt),g.call(e),"function"==typeof d&&d(null,e);else{if("function"!=typeof d)throw new Error(a.message);d(a)}}),e},Kuzzle.prototype.logout=function(a){var b=this,c={action:"logout",controller:"auth",requestId:h.v4(),body:{}};return this.query({controller:"auth",action:"logout"},c,{queuable:!1},function(c){null===c?(b.setJwtToken(void 0),"function"==typeof a&&a(null,b)):"function"==typeof a&&a(c)}),b},Kuzzle.prototype.checkToken=function(a,b){var c=this,d={body:{token:a}};return this.callbackRequired("Kuzzle.checkToken",b),this.query({controller:"auth",action:"checkToken"},d,{},b),c},Kuzzle.prototype.whoAmI=function(a){var b=this;return this.callbackRequired("Kuzzle.whoAmI",a),this.query({controller:"auth",action:"getCurrentUser"},{},{},a),b},Kuzzle.prototype.addListener=function(a,b){var c,d=Object.keys(this.eventListeners),e=typeof b;if(this.isValid(),-1===d.indexOf(a))throw new Error("["+a+"] is not a known event. Known events: "+d.toString());if("function"!==e)throw new Error("Invalid listener type: expected a function, got a "+e);return c=h.v1(),this.eventListeners[a].listeners.push({id:c,fn:b}),c},Kuzzle.prototype.getAllStatistics=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.getAllStatistics",b),this.query({controller:"admin",action:"getAllStats"},{},a,function(a,c){return a?b(a):void b(null,c.result.hits)}),this},Kuzzle.prototype.getStatistics=function(a,b,c){var d;return c||(1===arguments.length?(c=arguments[0],b=null,a=null):(c=arguments[1],"object"==typeof arguments[0]?(b=arguments[0],a=null):(a=arguments[0],b=null))),d=function(b,d){return b?c(b):void(a?c(null,d.result.hits):c(null,[d.result]))},this.callbackRequired("Kuzzle.getStatistics",c),a?this.query({controller:"admin",action:"getStats"},{body:{startTime:a}},b,d):this.query({controller:"admin",action:"getLastStats"},{},b,d),this},Kuzzle.prototype.dataCollectionFactory=function(a,b,c){if(this.isValid(),1===arguments.length?(b=arguments[0],a=this.defaultIndex):2===arguments.length&&"object"==typeof b&&(c=b,b=a,a=this.defaultIndex),!a)throw new Error("Unable to create a new data collection object: no index specified");return this.collections[a]||(this.collections[a]={}),this.collections[a][b]||(this.collections[a][b]=new i(this,a,b,c)),this.collections[a][b]},Kuzzle.prototype.flushQueue=function(){return this.offlineQueue=[],this},Kuzzle.prototype.listCollections=function(){var a,b,c,d="all",e=Array.prototype.slice.call(arguments);if(e.forEach(function(d){switch(typeof d){case"string":a=d;break;case"object":b=d;break;case"function":c=d}}),!a){if(!this.defaultIndex)throw new Error("Kuzzle.listCollections: index required");a=this.defaultIndex}return this.callbackRequired("Kuzzle.listCollections",c),b&&b.type&&(d=b.type),this.query({index:a,controller:"read",action:"listCollections"},{body:{type:d}},b,function(a,b){return a?c(a):c(null,b.result.collections)}),this},Kuzzle.prototype.listIndexes=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.listIndexes",b),this.query({controller:"read",action:"listIndexes"},{},a,function(a,c){return a?b(a):b(null,c.result.indexes)}),this},Kuzzle.prototype.disconnect=function(){var a;this.logout(),this.state="disconnected",this.socket.close(),this.socket=null;for(a in this.collections)this.collections.hasOwnProperty(a)&&delete this.collections[a]},Kuzzle.prototype.getServerInfo=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.getServerInfo",b),this.query({controller:"read",action:"serverInfo"},{},a,function(a,c){return a?b(a):void b(null,c.result.serverInfo)}),this},Kuzzle.prototype.now=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.now",b),this.query({controller:"read",action:"now"},{},a,function(a,c){return a?b(a):void b(null,c.result.now)}),this},Kuzzle.prototype.query=function(a,b,c,f){var g,i={action:a.action,controller:a.controller,metadata:this.metadata},j=this;if(this.isValid(),f||"function"!=typeof c||(f=c,c=null),c&&(c.metadata&&Object.keys(c.metadata).forEach(function(a){i.metadata[a]=c.metadata[a]}),c.queuable===!1&&"offline"===j.state))return j;b.metadata&&Object.keys(b.metadata).forEach(function(a){i.metadata[a]=b.metadata[a]});for(g in b)"metadata"!==g&&b.hasOwnProperty(g)&&(i[g]=b[g]);return i=j.addHeaders(i,this.headers),void 0!==j.jwtToken&&(i.headers=i.headers||{},i.headers.authorization="Bearer "+j.jwtToken),a.collection&&(i.collection=a.collection),a.index&&(i.index=a.index),i.requestId||(i.requestId=h.v4()),"connected"===j.state||c&&c.queuable===!1?"connected"===j.state?e.call(this,i,f):f&&f(new Error("Unable to execute request: not connected to a Kuzzle server.\nDiscarded request: "+i)):(j.queuing||-1!==["initializing","connecting"].indexOf(j.state))&&(d.call(this,i,f),j.queueFilter?j.queueFilter(i)&&j.offlineQueue.push({ts:Date.now(),query:i,cb:f}):j.offlineQueue.push({ts:Date.now(),query:i,cb:f})),j},Kuzzle.prototype.removeAllListeners=function(a){var b=Object.keys(this.eventListeners),c=this;if(a){if(-1===b.indexOf(a))throw new Error("["+a+"] is not a known event. Known events: "+b.toString());this.eventListeners[a].listeners=[]}else b.forEach(function(a){c.eventListeners[a].listeners=[]})},Kuzzle.prototype.removeListener=function(a,b){var c=Object.keys(this.eventListeners),d=this;if(-1===c.indexOf(a))throw new Error("["+a+"] is not a known event. Known events: "+c.toString());this.eventListeners[a].listeners.forEach(function(c,e){c.id===b&&d.eventListeners[a].listeners.splice(e,1)})},Kuzzle.prototype.replayQueue=function(){return"offline"===this.state||this.autoReplay||(d.call(this),f.call(this)),this},Kuzzle.prototype.setDefaultIndex=function(a){if("string"!=typeof a)throw new Error("Invalid default index: ["+a+"] (an index name is expected)");if(0===a.length)throw new Error("Cannot set an empty index as the default index");return this.defaultIndex=a,this},Kuzzle.prototype.setHeaders=function(a,b){var c=this;if("object"!=typeof a||Array.isArray(a))throw new Error("Expected a content object, received a "+typeof a);return b?c.headers=a:Object.keys(a).forEach(function(b){c.headers[b]=a[b]}),c},Kuzzle.prototype.startQueuing=function(){return"offline"!==this.state||this.autoQueue||(this.queuing=!0),this},Kuzzle.prototype.stopQueuing=function(){return"offline"!==this.state||this.autoQueue||(this.queuing=!1),this}},{"./kuzzleDataCollection":3,"node-uuid":1,"socket.io-client":void 0}],3:[function(a,b,c){function d(a,b,c){if(!b||!c)throw new Error("The KuzzleDataCollection object constructor needs an index and a collection arguments");return Object.defineProperties(this,{collection:{value:c,enumerable:!0},index:{value:b,enumerable:!0},kuzzle:{value:a,enumerable:!0},headers:{value:JSON.parse(JSON.stringify(a.headers)),enumerable:!0,writable:!0}}),Object.defineProperty(this,"buildQueryArgs",{value:function(a,b){return{controller:a,action:b,collection:this.collection,index:this.index}}}),this.kuzzle.bluebird?this.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["publishMessage","setHeaders","subscribe"];return d&&-1===e.indexOf(a)}}):this}var e=a("./kuzzleDocument"),f=a("./kuzzleDataMapping"),g=a("./kuzzleRoom");d.prototype.advancedSearch=function(a,b,c){var d,f=this;return c||"function"!=typeof b||(c=b,b=null),f.kuzzle.callbackRequired("KuzzleDataCollection.advancedSearch",c),d=f.kuzzle.addHeaders({body:a},this.headers),f.kuzzle.query(this.buildQueryArgs("read","search"),d,b,function(a,b){var d=[];return a?c(a):(b.result.hits.forEach(function(a){var b=new e(f,a._id,a._source);b.version=a._version,d.push(b)}),void c(null,{total:b.result.total,documents:d}))}),this},d.prototype.count=function(a,b,c){var d;return c||"function"!=typeof b||(c=b,b=null),this.kuzzle.callbackRequired("KuzzleDataCollection.count",c),d=this.kuzzle.addHeaders({body:a},this.headers),this.kuzzle.query(this.buildQueryArgs("read","count"),d,b,function(a,b){return a?c(a):void c(null,b.result.count)}),this},d.prototype.create=function(a,b){var c={};return b||"function"!=typeof a||(b=a,a=null),c=this.kuzzle.addHeaders(c,this.headers),this.kuzzle.query(this.buildQueryArgs("write","createCollection"),c,a,b),this},d.prototype.createDocument=function(a,b,c,d){var f=this,g={},h="create";return a&&"string"!=typeof a&&(d=c,c=b,b=a,a=null),d||"function"!=typeof c||(d=c,c=null),b instanceof e?g=b.toJSON():g.body=b,c&&(h=c.updateIfExist?"createOrReplace":"create"),a&&(g._id=a),g.persist=!0,g=f.kuzzle.addHeaders(g,f.headers),d?f.kuzzle.query(this.buildQueryArgs("write",h),g,c,function(a,b){var c;return a?d(a):(c=new e(f,b.result._id,b.result._source),c.version=b.result._version,void d(null,c))}):f.kuzzle.query(this.buildQueryArgs("write",h),g,c),this},d.prototype["delete"]=function(a,b){var c={};return b||"function"!=typeof a||(b=a,a=null),c=this.kuzzle.addHeaders(c,this.headers),this.kuzzle.query(this.buildQueryArgs("admin","deleteCollection"),c,a,b),this},d.prototype.deleteDocument=function(a,b,c){var d,e={};return"string"==typeof a?(e._id=a,d="delete"):(e.body=a,d="deleteByQuery"),c||"function"!=typeof b||(c=b,b=null),e=this.kuzzle.addHeaders(e,this.headers),c?this.kuzzle.query(this.buildQueryArgs("write",d),e,b,function(a,b){return a?c(a):void("delete"===d?c(null,[b.result._id]):c(null,b.result.ids))}):this.kuzzle.query(this.buildQueryArgs("write",d),e,b),this},d.prototype.fetchDocument=function(a,b,c){var d={_id:a},f=this;return c||"function"!=typeof b||(c=b,b=null),f.kuzzle.callbackRequired("KuzzleDataCollection.fetch",c),d=f.kuzzle.addHeaders(d,this.headers),f.kuzzle.query(this.buildQueryArgs("read","get"),d,b,function(a,b){var d;return a?c(a):(d=new e(f,b.result._id,b.result._source),d.version=b.result._version,void c(null,d))}),this},d.prototype.fetchAllDocuments=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.kuzzle.callbackRequired("KuzzleDataCollection.fetchAll",b),this.advancedSearch({},a,b),this},d.prototype.getMapping=function(a,b){var c;return b||"function"!=typeof a||(b=a,a=null),this.kuzzle.callbackRequired("KuzzleDataCollection.getMapping",b),c=new f(this),c.refresh(a,b),this},d.prototype.publishMessage=function(a,b){var c={};return a instanceof e?c=a.toJSON():c.body=a,c=this.kuzzle.addHeaders(c,this.headers),this.kuzzle.query(this.buildQueryArgs("write","publish"),c,b),this},d.prototype.replaceDocument=function(a,b,c,d){var f=this,g={_id:a,body:b};return d||"function"!=typeof c||(d=c,c=null),g=f.kuzzle.addHeaders(g,this.headers),d?f.kuzzle.query(this.buildQueryArgs("write","createOrReplace"),g,c,function(a,b){var c;return a?d(a):(c=new e(f,b.result._id,b.result._source),c.version=b.result._version,void d(null,c))}):f.kuzzle.query(this.buildQueryArgs("write","createOrReplace"),g,c),this},d.prototype.subscribe=function(a,b,c){var d;return c||"function"!=typeof b||(c=b,b=null),this.kuzzle.callbackRequired("KuzzleDataCollection.subscribe",c),d=new g(this,b),d.renew(a,c)},d.prototype.truncate=function(a,b){var c={};return b||"function"!=typeof a||(b=a,a=null),c=this.kuzzle.addHeaders(c,this.headers),this.kuzzle.query(this.buildQueryArgs("admin","truncateCollection"),c,a,b),this},d.prototype.updateDocument=function(a,b,c,d){var f={_id:a,body:b},g=this;return d||"function"!=typeof c||(d=c,c=null),f=g.kuzzle.addHeaders(f,this.headers),d?g.kuzzle.query(this.buildQueryArgs("write","update"),f,c,function(a,b){var c;return a?d(a):(c=new e(g,b.result._id),void c.refresh(d))}):g.kuzzle.query(this.buildQueryArgs("write","update"),f,c),g},d.prototype.documentFactory=function(a,b){return new e(this,a,b)},d.prototype.roomFactory=function(a){return new g(this,a)},d.prototype.dataMappingFactory=function(a){return new f(this,a)},d.prototype.setHeaders=function(a,b){return this.kuzzle.setHeaders.call(this,a,b),this},b.exports=d},{"./kuzzleDataMapping":4,"./kuzzleDocument":5,"./kuzzleRoom":6}],4:[function(a,b,c){function d(a,b){return Object.defineProperties(this,{collection:{value:a,eunmerable:!0},kuzzle:{value:a.kuzzle,enumerable:!0},headers:{value:JSON.parse(JSON.stringify(a.headers)),enumerable:!0,writable:!0},mapping:{value:b||{},enumerable:!0,writable:!0}}),this.kuzzle.bluebird?this.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["set","setHeaders"];return d&&-1===e.indexOf(a)}}):this}d.prototype.apply=function(a,b){var c=this,d=this.kuzzle.addHeaders({body:{properties:this.mapping}},this.headers);return b||"function"!=typeof a||(b=a,a=null),c.kuzzle.query(this.collection.buildQueryArgs("admin","updateMapping"),d,a,function(d){return d?b?b(d):!1:void c.refresh(a,b)}),this},d.prototype.refresh=function(a,b){var c=this,d=this.kuzzle.addHeaders({},this.headers);return b||"function"!=typeof a||(b=a,a=null),this.kuzzle.query(this.collection.buildQueryArgs("admin","getMapping"),d,a,function(a,d){return a?b?b(a):!1:d.result[c.collection.index]?d.result[c.collection.index].mappings[c.collection.collection]?(c.mapping=d.result[c.collection.index].mappings[c.collection.collection].properties,void(b&&b(null,c))):b?b(new Error("No mapping found for collection "+c.collection.collection)):!1:b?b(new Error("No mapping found for index "+c.collection.index)):!1}),this},d.prototype.set=function(a,b){return this.mapping[a]=b,this},d.prototype.setHeaders=function(a,b){return this.kuzzle.setHeaders.call(this,a,b),this},b.exports=d},{}],5:[function(a,b,c){function d(a,b,c){return Object.defineProperties(this,{queue:{value:[],writable:!0},refreshing:{value:!1,writable:!0},collection:{value:a.collection,enumerable:!0},dataCollection:{value:a,enumerable:!0},kuzzle:{value:a.kuzzle,enumerable:!0},id:{value:void 0,enumerable:!0,writable:!0},content:{value:{},writable:!0,enumerable:!0},headers:{value:JSON.parse(JSON.stringify(a.headers)),enumerable:!0,writable:!0},version:{value:void 0,enumerable:!0,writable:!0}}),!c&&b&&"object"==typeof b&&(c=b,b=null),c&&(c._version&&(this.version=c._version,delete c._version),this.setContent(c,!0)),b&&Object.defineProperty(this,"id",{value:b,enumerable:!0}),this.kuzzle.bluebird?this.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["delete","refresh","save"];return d&&-1!==e.indexOf(a)}}):this}function e(){for(var a;this.queue.length>0;)a=this.queue.shift(),this[a.action].apply(this,a.args)}d.prototype.toJSON=function(){var a={};return this.id&&(a._id=this.id),a.body=this.content,a._version=this.version,a=this.kuzzle.addHeaders(a,this.headers)},d.prototype.toString=function(){return JSON.stringify(this.toJSON())},d.prototype["delete"]=function(a,b){var c=this;if(b||"function"!=typeof a||(b=a,a=null),this.refreshing)return this.queue.push({action:"delete",args:[a,b]}),this;if(!this.id)throw new Error("KuzzleDocument.delete: cannot delete a document without a document ID");return b?this.kuzzle.query(this.dataCollection.buildQueryArgs("write","delete"),this.toJSON(),a,function(a){return a?b(a):void b(null,c)}):this.kuzzle.query(this.dataCollection.buildQueryArgs("write","delete"),this.toJSON(),a),this},d.prototype.refresh=function(a,b){var c=this;if(b||"function"!=typeof a||(b=a,a=null),this.refreshing)return this.queue.push({action:"refresh",args:[a,b]}),this;if(!c.id)throw new Error("KuzzleDocument.refresh: cannot retrieve a document if no ID has been provided");return c.refreshing=!0,c.kuzzle.query(c.dataCollection.buildQueryArgs("read","get"),{_id:c.id},a,function(a,d){return a?(c.refreshing=!1,c.queue=[],b?b(a):!1):(c.version=d.result._version,c.content=d.result._source,b&&b(null,c),c.refreshing=!1,void e.call(c))}),this},d.prototype.save=function(a,b){var c=this.toJSON(),d=this;return a&&void 0===b&&"function"==typeof a&&(b=a,a=null),d.refreshing?(d.queue.push({action:"save",args:[a,b]}),d):(c.persist=!0,d.kuzzle.query(this.dataCollection.buildQueryArgs("write","createOrReplace"),c,a,function(a,c){return a?b?b(a):!1:(d.id=c.result._id,d.version=c.result._version,void(b&&b(null,d)))}),d)},d.prototype.publish=function(a){var b=this.toJSON();return this.refreshing?(this.queue.push({action:"publish",args:[a]}),this):(this.kuzzle.query(this.dataCollection.buildQueryArgs("write","publish"),b,a),this)},d.prototype.setContent=function(a,b){var c=this;return this.refreshing?(this.queue.push({action:"setContent",args:[a,b]}),this):(b?this.content=a:Object.keys(a).forEach(function(b){c.content[b]=a[b]}),this)},d.prototype.subscribe=function(a,b){var c;if(a&&!b&&"function"==typeof a&&(b=a,a=null),this.kuzzle.callbackRequired("KuzzleDocument.subscribe",b),!this.id)throw new Error("KuzzleDocument.subscribe: cannot subscribe to a document if no ID has been provided");return c={ids:{values:[this.id]}},this.dataCollection.subscribe(c,a,b)},d.prototype.setHeaders=function(a,b){return this.kuzzle.setHeaders.call(this,a,b),this},b.exports=d},{}],6:[function(a,b,c){function d(a,b){return Object.defineProperties(this,{callback:{value:null,writable:!0},channel:{value:null,writable:!0},id:{value:g.v4()},lastRenewal:{value:null,writable:!0},notifier:{value:null,writable:!0},queue:{value:[],writable:!0},renewalDelay:{value:500},scope:{value:b&&b.scope?b.scope:"all"},state:{value:b&&b.state?b.state:"done"},subscribing:{value:!1,writable:!0},users:{value:b&&b.users?b.users:"none"},collection:{value:a,enumerable:!0},kuzzle:{value:a.kuzzle,enumerable:!0},filters:{value:null,enumerable:!0,writable:!0},headers:{value:JSON.parse(JSON.stringify(a.headers)),enumerable:!0,writable:!0},metadata:{value:b&&b.metadata?b.metadata:{},enumerable:!0,writable:!0},roomId:{value:null,enumerable:!0,writable:!0},subscribeToSelf:{value:b&&"boolean"==typeof b.subscribeToSelf?b.subscribeToSelf:!0,enumerable:!0,writable:!0}}),this.kuzzle.bluebird?this.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["count"];return d&&-1!==e.indexOf(a)}}):this}function e(a){return a.error?this.callback(a.error):"jwtTokenExpired"===a.action?(this.kuzzle.jwtToken=void 0,this.kuzzle.emitEvent("jwtTokenExpired")):void(this.kuzzle.requestHistory[a.requestId]?(this.subscribeToSelf&&this.callback(null,a),delete this.kuzzle.requestHistory[a.requestId]):this.callback(null,a))}function f(){for(var a;this.queue.length>0;)a=this.queue.shift(),this[a.action].apply(this,a.args)}var g=a("node-uuid");d.prototype.count=function(a){var b;return this.kuzzle.callbackRequired("KuzzleRoom.count",a),b=this.kuzzle.addHeaders({body:{roomId:this.roomId}},this.headers),this.subscribing?(this.queue.push({action:"count",args:[a]}),this):(this.kuzzle.query(this.collection.buildQueryArgs("subscribe","count"),b,function(b,c){return b?a(b):void a(null,c.result.count)}),this)},d.prototype.renew=function(a,b){var c=Date.now(),d={scope:this.scope,state:this.state,users:this.users},g=this;return!b&&a&&"function"==typeof a&&(b=a,a=null),g.lastRenewal&&c-g.lastRenewal<=g.renewalDelay?g:(g.lastRenewal=c,a&&(g.filters=a),"connected"!==g.kuzzle.state?(g.callback=b,g.kuzzle.subscriptions.pending[g.id]=g,g):g.subscribing?(g.queue.push({action:"renew",args:[a,b]}),g):(g.kuzzle.callbackRequired("KuzzleRoom.renew",b),g.unsubscribe(),g.roomId=null,g.subscribing=!0,g.callback=b,g.kuzzle.subscriptions.pending[g.id]=g,d.body=g.filters,d=g.kuzzle.addHeaders(d,this.headers),g.kuzzle.query(g.collection.buildQueryArgs("subscribe","on"),d,{metadata:g.metadata},function(a,b){if(delete g.kuzzle.subscriptions.pending[g.id],g.subscribing=!1,a)throw g.queue=[],new Error("Error during Kuzzle subscription: "+a.message);g.roomId=b.result.roomId,g.channel=b.result.channel,g.kuzzle.subscriptions[g.roomId]||(g.kuzzle.subscriptions[g.roomId]={}),g.kuzzle.subscriptions[g.roomId][g.id]=g,g.notifier=e.bind(g),g.kuzzle.socket.on(g.channel,g.notifier),f.call(g)}),g))},d.prototype.unsubscribe=function(){var a,b=this,c=b.roomId;return b.subscribing?(b.queue.push({action:"unsubscribe",args:[]}),b):(c&&(b.kuzzle.socket.off(b.channel,this.notifier),1===Object.keys(b.kuzzle.subscriptions[c]).length?(delete b.kuzzle.subscriptions[c],0===Object.keys(b.kuzzle.subscriptions.pending).length?b.kuzzle.query(b.collection.buildQueryArgs("subscribe","off"),{body:{roomId:c}}):a=setInterval(function(){0===Object.keys(b.kuzzle.subscriptions.pending).length&&(b.kuzzle.subscriptions[c]||b.kuzzle.query(b.collection.buildQueryArgs("subscribe","off"),{body:{roomId:c}}),clearInterval(a))},100)):delete b.kuzzle.subscriptions[c][b.id],b.roomId=null),b)},d.prototype.setHeaders=function(a,b){return this.kuzzle.setHeaders.call(this,a,b),this},b.exports=d},{"node-uuid":1}]},{},[2]);
// Official Javascript SDK for Kuzzle v1.4.3 - License: Apache-2.0
!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){!function(c){"use strict";function d(){var a=c.crypto||c.msCrypto;if(!j&&a&&a.getRandomValues)try{var b=new Uint8Array(16);m=j=function(){return a.getRandomValues(b),b},j()}catch(d){}if(!j){var e=new Array(16);k=j=function(){for(var a,b=0;16>b;b++)0===(3&b)&&(a=4294967296*Math.random()),e[b]=a>>>((3&b)<<3)&255;return e},"undefined"!=typeof console&&console.warn&&console.warn("[SECURITY] node-uuid: crypto not usable, falling back to insecure Math.random()")}}function e(){if("function"==typeof a)try{var b=a("crypto").randomBytes;l=j=b&&function(){return b(16)},j()}catch(c){}}function f(a,b,c){var d=b&&c||0,e=0;for(b=b||[],a.toLowerCase().replace(/[0-9a-f]{2}/g,function(a){16>e&&(b[d+e++]=q[a])});16>e;)b[d+e++]=0;return b}function g(a,b){var c=b||0,d=p;return d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]}function h(a,b,c){var d=b&&c||0,e=b||[];a=a||{};var f=null!=a.clockseq?a.clockseq:u,h=null!=a.msecs?a.msecs:(new Date).getTime(),i=null!=a.nsecs?a.nsecs:w+1,j=h-v+(i-w)/1e4;if(0>j&&null==a.clockseq&&(f=f+1&16383),(0>j||h>v)&&null==a.nsecs&&(i=0),i>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");v=h,w=i,u=f,h+=122192928e5;var k=(1e4*(268435455&h)+i)%4294967296;e[d++]=k>>>24&255,e[d++]=k>>>16&255,e[d++]=k>>>8&255,e[d++]=255&k;var l=h/4294967296*1e4&268435455;e[d++]=l>>>8&255,e[d++]=255&l,e[d++]=l>>>24&15|16,e[d++]=l>>>16&255,e[d++]=f>>>8|128,e[d++]=255&f;for(var m=a.node||t,n=0;6>n;n++)e[d+n]=m[n];return b?b:g(e)}function i(a,b,c){var d=b&&c||0;"string"==typeof a&&(b="binary"===a?new o(16):null,a=null),a=a||{};var e=a.random||(a.rng||j)();if(e[6]=15&e[6]|64,e[8]=63&e[8]|128,b)for(var f=0;16>f;f++)b[d+f]=e[f];return b||g(e)}var j,k,l,m,n;c?d():e();for(var o="function"==typeof Buffer?Buffer:Array,p=[],q={},r=0;256>r;r++)p[r]=(r+256).toString(16).substr(1),q[p[r]]=r;var s=j(),t=[1|s[0],s[1],s[2],s[3],s[4],s[5]],u=16383&(s[6]<<8|s[7]),v=0,w=0,x=i;x.v1=h,x.v4=i,x.parse=f,x.unparse=g,x.BufferClass=o,x._rng=j,x._mathRNG=k,x._nodeRNG=l,x._whatwgRNG=m,"undefined"!=typeof b&&b.exports?b.exports=x:"function"==typeof define&&define.amd?define(function(){return x}):(n=c.uuid,x.noConflict=function(){return c.uuid=n,x},c.uuid=x)}("undefined"!=typeof window?window:null)},{}],2:[function(a,b,c){function d(){var a=this,b=Date.now(),c=-1;a.queueTTL>0&&(a.offlineQueue.forEach(function(d,e){d.ts<b-a.queueTTL&&(c=e)}),-1!==c&&a.offlineQueue.splice(0,c+1)),a.queueMaxSize>0&&a.offlineQueue.length>a.queueMaxSize&&a.offlineQueue.splice(0,a.offlineQueue.length-a.queueMaxSize)}function e(a,b){var c=Date.now(),d=this;(void 0!==d.jwtToken||b)&&d.socket.once(a.requestId,function(c){c.error&&"Token expired"===c.error.message&&(d.jwtToken=void 0,d.emitEvent("jwtTokenExpired",a,b)),b&&b(c.error,c)}),d.socket.emit("kuzzle",a),d.requestHistory[a.requestId]=c,Object.keys(d.requestHistory).forEach(function(a){d.requestHistory[a]<c-1e4&&delete d.requestHistory[a]})}function f(){var a=this;a.offlineQueue.length>0?(e.call(a,a.offlineQueue[0].query,a.offlineQueue[0].cb),a.offlineQueue.shift(),setTimeout(function(){f.call(a)},Math.max(0,a.replayInterval))):a.queuing=!1}function g(){var a=this;Object.keys(a.subscriptions).forEach(function(b){Object.keys(a.subscriptions[b]).forEach(function(c){var d=a.subscriptions[b][c];d.renew(d.callback)})})}var h=a("node-uuid"),i=a("./kuzzleDataCollection");b.exports=Kuzzle=function(b,c,d){var e=this;if(!(this instanceof Kuzzle))return new Kuzzle(b,c,d);if(d||"function"!=typeof c||(d=c,c=null),!b||""===b)throw new Error("URL argument missing");return Object.defineProperties(this,{collections:{value:{},writable:!0},connectCB:{value:d},eventListeners:{value:{connected:{lastEmitted:null,listeners:[]},error:{lastEmitted:null,listeners:[]},disconnected:{lastEmitted:null,listeners:[]},reconnected:{lastEmitted:null,listeners:[]},jwtTokenExpired:{lastEmitted:null,listeners:[]}}},eventTimeout:{value:200},io:{value:null,writable:!0},queuing:{value:!1,writable:!0},requestHistory:{value:{},writable:!0},socket:{value:null,writable:!0},state:{value:"initializing",writable:!0},subscriptions:{value:{pending:{}},writable:!0},autoReconnect:{value:c&&"boolean"==typeof c.autoReconnect?c.autoReconnect:!0,enumerable:!0},defaultIndex:{value:c&&"string"==typeof c.defaultIndex?c.defaultIndex:void 0,writable:!0,enumerable:!0},reconnectionDelay:{value:c&&"number"==typeof c.reconnectionDelay?c.reconnectionDelay:1e3,enumerable:!0},url:{value:b,enumerable:!0},autoQueue:{value:!1,enumerable:!0,writable:!0},autoReplay:{value:!1,enumerable:!0,writable:!0},autoResubscribe:{value:!0,enumerable:!0,writable:!0},headers:{value:{},enumerable:!0,writable:!0},metadata:{value:{},enumerable:!0,writable:!0},offlineQueue:{value:[],enumerable:!0,writable:!0},queueFilter:{value:null,enumerable:!0,writable:!0},queueMaxSize:{value:500,enumerable:!0,writable:!0},queueTTL:{value:12e4,enumerable:!0,writable:!0},replayInterval:{value:10,enumerable:!0,writable:!0},jwtToken:{value:void 0,enumerable:!0,writable:!0}}),"undefined"!=typeof window&&window.io?this.io=window.io:this.io=a("socket.io-client"),c&&(Object.keys(c).forEach(function(a){e.hasOwnProperty(a)&&Object.getOwnPropertyDescriptor(e,a).writable&&(e[a]=c[a])}),"auto"===c.offlineMode&&this.autoReconnect&&(this.autoQueue=this.autoReplay=this.autoResubscribe=!0)),Object.defineProperty(this,"isValid",{value:function(){if("disconnected"===e.state)throw new Error("This Kuzzle object has been invalidated. Did you try to access it after a disconnect call?")}}),Object.defineProperty(this,"addHeaders",{value:function(a,b){return Object.keys(b).forEach(function(c){a[c]||(a[c]=b[c])}),a}}),Object.defineProperty(this,"callbackRequired",{value:function(a,b){if(!b||"function"!=typeof b)throw new Error(a+": a callback argument is required for read queries")}}),Object.defineProperty(this,"emitEvent",{value:function(a){var b=Date.now(),c=Array.prototype.slice.call(arguments,1);return this.eventListeners[a].lastEmitted&&this.eventListeners[a].lastEmitted>=b-this.eventTimeout?!1:(this.eventListeners[a].listeners.forEach(function(a){a.fn.apply(this,c)}),void(this.eventListeners[a].lastEmitted=b))}}),c&&c.connect&&"auto"!==c.connect?this.state="ready":this.connect(),this.bluebird?this.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["getAllStatistics","getServerInfo","getStatistics","listCollections","listIndexes","login","logout","now","query","checkToken","whoAmI"];return d&&-1!==e.indexOf(a)}}):this},Kuzzle.prototype.connect=function(){var a=this;return-1===["initializing","ready","disconnected","error","offline"].indexOf(this.state)?(a.connectCB&&a.connectCB(null,a),a):(a.state="connecting",a.socket=a.io(a.url,{reconnection:a.autoReconnect,reconnectionDelay:a.reconnectionDelay,forceNew:!0}),a.socket.once("connect",function(){a.state="connected",g.call(a),f.call(a),a.emitEvent("connected"),a.connectCB&&a.connectCB(null,a)}),a.socket.on("connect_error",function(b){a.state="error",a.emitEvent("error"),a.connectCB&&a.connectCB(b)}),a.socket.on("disconnect",function(){a.state="offline",a.autoReconnect||a.disconnect(),a.autoQueue&&(a.queuing=!0),a.emitEvent("disconnected")}),a.socket.on("reconnect",function(){a.state="connected",a.autoResubscribe&&g.call(a),a.autoReplay&&(d.call(a),f.call(a)),a.emitEvent("reconnected")}),this)},Kuzzle.prototype.setJwtToken=function(a){return this.jwtToken=a,this},Kuzzle.prototype.getJwtToken=function(){return this.jwtToken},Kuzzle.prototype.login=function(a,b,c,d){var e=this,f={strategy:a};return d||"function"!=typeof c||(d=c,c=null),Object.keys(b).forEach(function(a){f[a]=b[a]}),-1!==["number","string"].indexOf(typeof c)&&(f.expiresIn=c),this.query({controller:"auth",action:"login"},{body:f},{queuable:!1},function(a,b){if(null===a)e.setJwtToken(b.result.jwt),g.call(e),"function"==typeof d&&d(null,e);else{if("function"!=typeof d)throw new Error(a.message);d(a)}}),e},Kuzzle.prototype.logout=function(a){var b=this,c={action:"logout",controller:"auth",requestId:h.v4(),body:{}};return this.query({controller:"auth",action:"logout"},c,{queuable:!1},function(c){null===c?(b.setJwtToken(void 0),"function"==typeof a&&a(null,b)):"function"==typeof a&&a(c)}),b},Kuzzle.prototype.checkToken=function(a,b){var c=this,d={body:{token:a}};return this.callbackRequired("Kuzzle.checkToken",b),this.query({controller:"auth",action:"checkToken"},d,{},b),c},Kuzzle.prototype.whoAmI=function(a){var b=this;return this.callbackRequired("Kuzzle.whoAmI",a),this.query({controller:"auth",action:"getCurrentUser"},{},{},a),b},Kuzzle.prototype.addListener=function(a,b){var c,d=Object.keys(this.eventListeners),e=typeof b;if(this.isValid(),-1===d.indexOf(a))throw new Error("["+a+"] is not a known event. Known events: "+d.toString());if("function"!==e)throw new Error("Invalid listener type: expected a function, got a "+e);return c=h.v1(),this.eventListeners[a].listeners.push({id:c,fn:b}),c},Kuzzle.prototype.getAllStatistics=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.getAllStatistics",b),this.query({controller:"admin",action:"getAllStats"},{},a,function(a,c){return a?b(a):void b(null,c.result.hits)}),this},Kuzzle.prototype.getStatistics=function(a,b,c){var d;return c||(1===arguments.length?(c=arguments[0],b=null,a=null):(c=arguments[1],"object"==typeof arguments[0]?(b=arguments[0],a=null):(a=arguments[0],b=null))),d=function(b,d){return b?c(b):void(a?c(null,d.result.hits):c(null,[d.result]))},this.callbackRequired("Kuzzle.getStatistics",c),a?this.query({controller:"admin",action:"getStats"},{body:{startTime:a}},b,d):this.query({controller:"admin",action:"getLastStats"},{},b,d),this},Kuzzle.prototype.dataCollectionFactory=function(a,b,c){if(this.isValid(),1===arguments.length?(b=arguments[0],a=this.defaultIndex):2===arguments.length&&"object"==typeof b&&(c=b,b=a,a=this.defaultIndex),!a)throw new Error("Unable to create a new data collection object: no index specified");return this.collections[a]||(this.collections[a]={}),this.collections[a][b]||(this.collections[a][b]=new i(this,a,b,c)),this.collections[a][b]},Kuzzle.prototype.flushQueue=function(){return this.offlineQueue=[],this},Kuzzle.prototype.listCollections=function(){var a,b,c,d="all",e=Array.prototype.slice.call(arguments);if(e.forEach(function(d){switch(typeof d){case"string":a=d;break;case"object":b=d;break;case"function":c=d}}),!a){if(!this.defaultIndex)throw new Error("Kuzzle.listCollections: index required");a=this.defaultIndex}return this.callbackRequired("Kuzzle.listCollections",c),b&&b.type&&(d=b.type),this.query({index:a,controller:"read",action:"listCollections"},{body:{type:d}},b,function(a,b){return a?c(a):c(null,b.result.collections)}),this},Kuzzle.prototype.listIndexes=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.listIndexes",b),this.query({controller:"read",action:"listIndexes"},{},a,function(a,c){return a?b(a):b(null,c.result.indexes)}),this},Kuzzle.prototype.disconnect=function(){var a;this.logout(),this.state="disconnected",this.socket.close(),this.socket=null;for(a in this.collections)this.collections.hasOwnProperty(a)&&delete this.collections[a]},Kuzzle.prototype.getServerInfo=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.getServerInfo",b),this.query({controller:"read",action:"serverInfo"},{},a,function(a,c){return a?b(a):void b(null,c.result.serverInfo)}),this},Kuzzle.prototype.now=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.now",b),this.query({controller:"read",action:"now"},{},a,function(a,c){return a?b(a):void b(null,c.result.now)}),this},Kuzzle.prototype.query=function(a,b,c,f){var g,i={action:a.action,controller:a.controller,metadata:this.metadata},j=this;if(this.isValid(),f||"function"!=typeof c||(f=c,c=null),c&&(c.metadata&&Object.keys(c.metadata).forEach(function(a){i.metadata[a]=c.metadata[a]}),c.queuable===!1&&"offline"===j.state))return j;b.metadata&&Object.keys(b.metadata).forEach(function(a){i.metadata[a]=b.metadata[a]});for(g in b)"metadata"!==g&&b.hasOwnProperty(g)&&(i[g]=b[g]);return i=j.addHeaders(i,this.headers),void 0!==j.jwtToken&&(i.headers=i.headers||{},i.headers.authorization="Bearer "+j.jwtToken),a.collection&&(i.collection=a.collection),a.index&&(i.index=a.index),i.requestId||(i.requestId=h.v4()),"connected"===j.state||c&&c.queuable===!1?"connected"===j.state?e.call(this,i,f):f&&f(new Error("Unable to execute request: not connected to a Kuzzle server.\nDiscarded request: "+i)):(j.queuing||-1!==["initializing","connecting"].indexOf(j.state))&&(d.call(this,i,f),j.queueFilter?j.queueFilter(i)&&j.offlineQueue.push({ts:Date.now(),query:i,cb:f}):j.offlineQueue.push({ts:Date.now(),query:i,cb:f})),j},Kuzzle.prototype.removeAllListeners=function(a){var b=Object.keys(this.eventListeners),c=this;if(a){if(-1===b.indexOf(a))throw new Error("["+a+"] is not a known event. Known events: "+b.toString());this.eventListeners[a].listeners=[]}else b.forEach(function(a){c.eventListeners[a].listeners=[]})},Kuzzle.prototype.removeListener=function(a,b){var c=Object.keys(this.eventListeners),d=this;if(-1===c.indexOf(a))throw new Error("["+a+"] is not a known event. Known events: "+c.toString());this.eventListeners[a].listeners.forEach(function(c,e){c.id===b&&d.eventListeners[a].listeners.splice(e,1)})},Kuzzle.prototype.replayQueue=function(){return"offline"===this.state||this.autoReplay||(d.call(this),f.call(this)),this},Kuzzle.prototype.setDefaultIndex=function(a){if("string"!=typeof a)throw new Error("Invalid default index: ["+a+"] (an index name is expected)");if(0===a.length)throw new Error("Cannot set an empty index as the default index");return this.defaultIndex=a,this},Kuzzle.prototype.setHeaders=function(a,b){var c=this;if("object"!=typeof a||Array.isArray(a))throw new Error("Expected a content object, received a "+typeof a);return b?c.headers=a:Object.keys(a).forEach(function(b){c.headers[b]=a[b]}),c},Kuzzle.prototype.startQueuing=function(){return"offline"!==this.state||this.autoQueue||(this.queuing=!0),this},Kuzzle.prototype.stopQueuing=function(){return"offline"!==this.state||this.autoQueue||(this.queuing=!1),this}},{"./kuzzleDataCollection":3,"node-uuid":1,"socket.io-client":void 0}],3:[function(a,b,c){function d(a,b,c){if(!b||!c)throw new Error("The KuzzleDataCollection object constructor needs an index and a collection arguments");return Object.defineProperties(this,{collection:{value:c,enumerable:!0},index:{value:b,enumerable:!0},kuzzle:{value:a,enumerable:!0},headers:{value:JSON.parse(JSON.stringify(a.headers)),enumerable:!0,writable:!0}}),Object.defineProperty(this,"buildQueryArgs",{value:function(a,b){return{controller:a,action:b,collection:this.collection,index:this.index}}}),this.kuzzle.bluebird?this.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["publishMessage","setHeaders","subscribe"];return d&&-1===e.indexOf(a)}}):this}var e=a("./kuzzleDocument"),f=a("./kuzzleDataMapping"),g=a("./kuzzleRoom");d.prototype.advancedSearch=function(a,b,c){var d,f=this;return c||"function"!=typeof b||(c=b,b=null),f.kuzzle.callbackRequired("KuzzleDataCollection.advancedSearch",c),d=f.kuzzle.addHeaders({body:a},this.headers),f.kuzzle.query(this.buildQueryArgs("read","search"),d,b,function(a,b){var d=[];return a?c(a):(b.result.hits.forEach(function(a){var b=new e(f,a._id,a._source);b.version=a._version,d.push(b)}),void c(null,{total:b.result.total,documents:d}))}),this},d.prototype.count=function(a,b,c){var d;return c||"function"!=typeof b||(c=b,b=null),this.kuzzle.callbackRequired("KuzzleDataCollection.count",c),d=this.kuzzle.addHeaders({body:a},this.headers),this.kuzzle.query(this.buildQueryArgs("read","count"),d,b,function(a,b){return a?c(a):void c(null,b.result.count)}),this},d.prototype.create=function(a,b){var c={};return b||"function"!=typeof a||(b=a,a=null),c=this.kuzzle.addHeaders(c,this.headers),this.kuzzle.query(this.buildQueryArgs("write","createCollection"),c,a,b),this},d.prototype.createDocument=function(a,b,c,d){var f=this,g={},h="create";return a&&"string"!=typeof a&&(d=c,c=b,b=a,a=null),d||"function"!=typeof c||(d=c,c=null),b instanceof e?g=b.toJSON():g.body=b,c&&(h=c.updateIfExist?"createOrReplace":"create"),a&&(g._id=a),g.persist=!0,g=f.kuzzle.addHeaders(g,f.headers),d?f.kuzzle.query(this.buildQueryArgs("write",h),g,c,function(a,b){var c;return a?d(a):(c=new e(f,b.result._id,b.result._source),c.version=b.result._version,void d(null,c))}):f.kuzzle.query(this.buildQueryArgs("write",h),g,c),this},d.prototype["delete"]=function(a,b){var c={};return b||"function"!=typeof a||(b=a,a=null),c=this.kuzzle.addHeaders(c,this.headers),this.kuzzle.query(this.buildQueryArgs("admin","deleteCollection"),c,a,b),this},d.prototype.deleteDocument=function(a,b,c){var d,e={};return"string"==typeof a?(e._id=a,d="delete"):(e.body=a,d="deleteByQuery"),c||"function"!=typeof b||(c=b,b=null),e=this.kuzzle.addHeaders(e,this.headers),c?this.kuzzle.query(this.buildQueryArgs("write",d),e,b,function(a,b){return a?c(a):void("delete"===d?c(null,[b.result._id]):c(null,b.result.ids))}):this.kuzzle.query(this.buildQueryArgs("write",d),e,b),this},d.prototype.fetchDocument=function(a,b,c){var d={_id:a},f=this;return c||"function"!=typeof b||(c=b,b=null),f.kuzzle.callbackRequired("KuzzleDataCollection.fetch",c),d=f.kuzzle.addHeaders(d,this.headers),f.kuzzle.query(this.buildQueryArgs("read","get"),d,b,function(a,b){var d;return a?c(a):(d=new e(f,b.result._id,b.result._source),d.version=b.result._version,void c(null,d))}),this},d.prototype.fetchAllDocuments=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.kuzzle.callbackRequired("KuzzleDataCollection.fetchAll",b),this.advancedSearch({},a,b),this},d.prototype.getMapping=function(a,b){var c;return b||"function"!=typeof a||(b=a,a=null),this.kuzzle.callbackRequired("KuzzleDataCollection.getMapping",b),c=new f(this),c.refresh(a,b),this},d.prototype.publishMessage=function(a,b){var c={};return a instanceof e?c=a.toJSON():c.body=a,c=this.kuzzle.addHeaders(c,this.headers),this.kuzzle.query(this.buildQueryArgs("write","publish"),c,b),this},d.prototype.replaceDocument=function(a,b,c,d){var f=this,g={_id:a,body:b};return d||"function"!=typeof c||(d=c,c=null),g=f.kuzzle.addHeaders(g,this.headers),d?f.kuzzle.query(this.buildQueryArgs("write","createOrReplace"),g,c,function(a,b){var c;return a?d(a):(c=new e(f,b.result._id,b.result._source),c.version=b.result._version,void d(null,c))}):f.kuzzle.query(this.buildQueryArgs("write","createOrReplace"),g,c),this},d.prototype.subscribe=function(a,b,c){var d;return c||"function"!=typeof b||(c=b,b=null),this.kuzzle.callbackRequired("KuzzleDataCollection.subscribe",c),d=new g(this,b),d.renew(a,c)},d.prototype.truncate=function(a,b){var c={};return b||"function"!=typeof a||(b=a,a=null),c=this.kuzzle.addHeaders(c,this.headers),this.kuzzle.query(this.buildQueryArgs("admin","truncateCollection"),c,a,b),this},d.prototype.updateDocument=function(a,b,c,d){var f={_id:a,body:b},g=this;return d||"function"!=typeof c||(d=c,c=null),f=g.kuzzle.addHeaders(f,this.headers),d?g.kuzzle.query(this.buildQueryArgs("write","update"),f,c,function(a,b){var c;return a?d(a):(c=new e(g,b.result._id),void c.refresh(d))}):g.kuzzle.query(this.buildQueryArgs("write","update"),f,c),g},d.prototype.documentFactory=function(a,b){return new e(this,a,b)},d.prototype.roomFactory=function(a){return new g(this,a)},d.prototype.dataMappingFactory=function(a){return new f(this,a)},d.prototype.setHeaders=function(a,b){return this.kuzzle.setHeaders.call(this,a,b),this},b.exports=d},{"./kuzzleDataMapping":4,"./kuzzleDocument":5,"./kuzzleRoom":6}],4:[function(a,b,c){function d(a,b){return Object.defineProperties(this,{collection:{value:a,eunmerable:!0},kuzzle:{value:a.kuzzle,enumerable:!0},headers:{value:JSON.parse(JSON.stringify(a.headers)),enumerable:!0,writable:!0},mapping:{value:b||{},enumerable:!0,writable:!0}}),this.kuzzle.bluebird?this.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["set","setHeaders"];return d&&-1===e.indexOf(a)}}):this}d.prototype.apply=function(a,b){var c=this,d=this.kuzzle.addHeaders({body:{properties:this.mapping}},this.headers);return b||"function"!=typeof a||(b=a,a=null),c.kuzzle.query(this.collection.buildQueryArgs("admin","updateMapping"),d,a,function(d){return d?b?b(d):!1:void c.refresh(a,b)}),this},d.prototype.refresh=function(a,b){var c=this,d=this.kuzzle.addHeaders({},this.headers);return b||"function"!=typeof a||(b=a,a=null),this.kuzzle.query(this.collection.buildQueryArgs("admin","getMapping"),d,a,function(a,d){return a?b?b(a):!1:d.result[c.collection.index]?d.result[c.collection.index].mappings[c.collection.collection]?(c.mapping=d.result[c.collection.index].mappings[c.collection.collection].properties,void(b&&b(null,c))):b?b(new Error("No mapping found for collection "+c.collection.collection)):!1:b?b(new Error("No mapping found for index "+c.collection.index)):!1}),this},d.prototype.set=function(a,b){return this.mapping[a]=b,this},d.prototype.setHeaders=function(a,b){return this.kuzzle.setHeaders.call(this,a,b),this},b.exports=d},{}],5:[function(a,b,c){function d(a,b,c){return Object.defineProperties(this,{queue:{value:[],writable:!0},refreshing:{value:!1,writable:!0},collection:{value:a.collection,enumerable:!0},dataCollection:{value:a,enumerable:!0},kuzzle:{value:a.kuzzle,enumerable:!0},id:{value:void 0,enumerable:!0,writable:!0},content:{value:{},writable:!0,enumerable:!0},headers:{value:JSON.parse(JSON.stringify(a.headers)),enumerable:!0,writable:!0},version:{value:void 0,enumerable:!0,writable:!0}}),!c&&b&&"object"==typeof b&&(c=b,b=null),c&&(c._version&&(this.version=c._version,delete c._version),this.setContent(c,!0)),b&&Object.defineProperty(this,"id",{value:b,enumerable:!0}),this.kuzzle.bluebird?this.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["delete","refresh","save"];return d&&-1!==e.indexOf(a)}}):this}function e(){for(var a;this.queue.length>0;)a=this.queue.shift(),this[a.action].apply(this,a.args)}d.prototype.toJSON=function(){var a={};return this.id&&(a._id=this.id),a.body=this.content,a._version=this.version,a=this.kuzzle.addHeaders(a,this.headers)},d.prototype.toString=function(){return JSON.stringify(this.toJSON())},d.prototype["delete"]=function(a,b){var c=this;if(b||"function"!=typeof a||(b=a,a=null),this.refreshing)return this.queue.push({action:"delete",args:[a,b]}),this;if(!this.id)throw new Error("KuzzleDocument.delete: cannot delete a document without a document ID");return b?this.kuzzle.query(this.dataCollection.buildQueryArgs("write","delete"),this.toJSON(),a,function(a){return a?b(a):void b(null,c)}):this.kuzzle.query(this.dataCollection.buildQueryArgs("write","delete"),this.toJSON(),a),this},d.prototype.refresh=function(a,b){var c=this;if(b||"function"!=typeof a||(b=a,a=null),this.refreshing)return this.queue.push({action:"refresh",args:[a,b]}),this;if(!c.id)throw new Error("KuzzleDocument.refresh: cannot retrieve a document if no ID has been provided");return c.refreshing=!0,c.kuzzle.query(c.dataCollection.buildQueryArgs("read","get"),{_id:c.id},a,function(a,d){return a?(c.refreshing=!1,c.queue=[],b?b(a):!1):(c.version=d.result._version,c.content=d.result._source,b&&b(null,c),c.refreshing=!1,void e.call(c))}),this},d.prototype.save=function(a,b){var c=this.toJSON(),d=this;return a&&void 0===b&&"function"==typeof a&&(b=a,a=null),d.refreshing?(d.queue.push({action:"save",args:[a,b]}),d):(c.persist=!0,d.kuzzle.query(this.dataCollection.buildQueryArgs("write","createOrReplace"),c,a,function(a,c){return a?b?b(a):!1:(d.id=c.result._id,d.version=c.result._version,void(b&&b(null,d)))}),d)},d.prototype.publish=function(a){var b=this.toJSON();return this.refreshing?(this.queue.push({action:"publish",args:[a]}),this):(this.kuzzle.query(this.dataCollection.buildQueryArgs("write","publish"),b,a),this)},d.prototype.setContent=function(a,b){var c=this;return this.refreshing?(this.queue.push({action:"setContent",args:[a,b]}),this):(b?this.content=a:Object.keys(a).forEach(function(b){c.content[b]=a[b]}),this)},d.prototype.subscribe=function(a,b){var c;if(a&&!b&&"function"==typeof a&&(b=a,a=null),this.kuzzle.callbackRequired("KuzzleDocument.subscribe",b),!this.id)throw new Error("KuzzleDocument.subscribe: cannot subscribe to a document if no ID has been provided");return c={ids:{values:[this.id]}},this.dataCollection.subscribe(c,a,b)},d.prototype.setHeaders=function(a,b){return this.kuzzle.setHeaders.call(this,a,b),this},b.exports=d},{}],6:[function(a,b,c){function d(a,b){return Object.defineProperties(this,{callback:{value:null,writable:!0},channel:{value:null,writable:!0},id:{value:g.v4()},lastRenewal:{value:null,writable:!0},notifier:{value:null,writable:!0},queue:{value:[],writable:!0},renewalDelay:{value:500},scope:{value:b&&b.scope?b.scope:"all"},state:{value:b&&b.state?b.state:"done"},subscribing:{value:!1,writable:!0},users:{value:b&&b.users?b.users:"none"},collection:{value:a,enumerable:!0},kuzzle:{value:a.kuzzle,enumerable:!0},filters:{value:null,enumerable:!0,writable:!0},headers:{value:JSON.parse(JSON.stringify(a.headers)),enumerable:!0,writable:!0},metadata:{value:b&&b.metadata?b.metadata:{},enumerable:!0,writable:!0},roomId:{value:null,enumerable:!0,writable:!0},subscribeToSelf:{value:b&&"boolean"==typeof b.subscribeToSelf?b.subscribeToSelf:!0,enumerable:!0,writable:!0}}),this.kuzzle.bluebird?this.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["count"];return d&&-1!==e.indexOf(a)}}):this}function e(a){return a.error?this.callback(a.error):"jwtTokenExpired"===a.action?(this.kuzzle.jwtToken=void 0,this.kuzzle.emitEvent("jwtTokenExpired")):void(this.kuzzle.requestHistory[a.requestId]?(this.subscribeToSelf&&this.callback(null,a),delete this.kuzzle.requestHistory[a.requestId]):this.callback(null,a))}function f(){for(var a;this.queue.length>0;)a=this.queue.shift(),this[a.action].apply(this,a.args)}var g=a("node-uuid");d.prototype.count=function(a){var b;return this.kuzzle.callbackRequired("KuzzleRoom.count",a),b=this.kuzzle.addHeaders({body:{roomId:this.roomId}},this.headers),this.subscribing?(this.queue.push({action:"count",args:[a]}),this):(this.kuzzle.query(this.collection.buildQueryArgs("subscribe","count"),b,function(b,c){return b?a(b):void a(null,c.result.count)}),this)},d.prototype.renew=function(a,b){var c=Date.now(),d={scope:this.scope,state:this.state,users:this.users},g=this;return!b&&a&&"function"==typeof a&&(b=a,a=null),g.lastRenewal&&c-g.lastRenewal<=g.renewalDelay?g:(a&&(g.filters=a),"connected"!==g.kuzzle.state?(g.callback=b,g.kuzzle.subscriptions.pending[g.id]=g,g):g.subscribing?(g.queue.push({action:"renew",args:[a,b]}),g):(g.kuzzle.callbackRequired("KuzzleRoom.renew",b),g.unsubscribe(),g.roomId=null,g.subscribing=!0,g.callback=b,g.kuzzle.subscriptions.pending[g.id]=g,d.body=g.filters,d=g.kuzzle.addHeaders(d,this.headers),g.kuzzle.query(g.collection.buildQueryArgs("subscribe","on"),d,{metadata:g.metadata},function(a,b){if(delete g.kuzzle.subscriptions.pending[g.id],g.subscribing=!1,a)throw g.queue=[],new Error("Error during Kuzzle subscription: "+a.message);g.lastRenewal=c,g.roomId=b.result.roomId,g.channel=b.result.channel,g.kuzzle.subscriptions[g.roomId]||(g.kuzzle.subscriptions[g.roomId]={}),g.kuzzle.subscriptions[g.roomId][g.id]=g,g.notifier=e.bind(g),g.kuzzle.socket.on(g.channel,g.notifier),f.call(g)}),g))},d.prototype.unsubscribe=function(){var a,b=this,c=b.roomId;return b.subscribing?(b.queue.push({action:"unsubscribe",args:[]}),b):(c&&(b.kuzzle.socket.off(b.channel,this.notifier),1===Object.keys(b.kuzzle.subscriptions[c]).length?(delete b.kuzzle.subscriptions[c],0===Object.keys(b.kuzzle.subscriptions.pending).length?b.kuzzle.query(b.collection.buildQueryArgs("subscribe","off"),{body:{roomId:c}}):a=setInterval(function(){0===Object.keys(b.kuzzle.subscriptions.pending).length&&(b.kuzzle.subscriptions[c]||b.kuzzle.query(b.collection.buildQueryArgs("subscribe","off"),{body:{roomId:c}}),clearInterval(a))},100)):delete b.kuzzle.subscriptions[c][b.id],b.roomId=null),b)},d.prototype.setHeaders=function(a,b){return this.kuzzle.setHeaders.call(this,a,b),this},b.exports=d},{"node-uuid":1}]},{},[2]);
//# sourceMappingURL=kuzzle.min.map
{
"name": "kuzzle-sdk",
"version": "1.4.2",
"version": "1.4.3",
"description": "Official Javascript SDK for Kuzzle",

@@ -5,0 +5,0 @@ "author": "The Kuzzle Team <support@kuzzle.io>",

@@ -175,4 +175,2 @@ var

self.lastRenewal = now;
if (filters) {

@@ -217,2 +215,3 @@ self.filters = filters;

self.lastRenewal = now;
self.roomId = response.result.roomId;

@@ -219,0 +218,0 @@ self.channel = response.result.channel;

@@ -147,4 +147,8 @@ var

it('should send the right query to Kuzzle', function () {
var
before = Date.now();
should(room.renew({}, function () {})).be.exactly(room);
should(emitted).be.true();
should(room.lastRenewal).be.within(before, Date.now());
});

@@ -190,2 +194,3 @@

should(dequeued).be.false();
should(room.lastRenewal).be.null();
should(room.queue).be.empty();

@@ -200,2 +205,3 @@ });

should(emitted).be.false();
should(room.lastRenewal).be.null();
should(kuzzle.subscriptions.pending[room.id]).be.eql(room);

@@ -212,3 +218,3 @@ done();

kuzzle.query = function () { renewals++; arguments[3](null, result); }
kuzzle.query = function () { renewals++; arguments[3](null, result); };
room.renew({}, function () {});

@@ -215,0 +221,0 @@ after = Date.now();

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

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

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