Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ deploy:
skip_cleanup: true
email: support@kuzzle.io
api_key:
secure: DqPwRO+LYFFOgIdZ23Prhw14f1ycsOcOXZsl7tMi4kznwu1PTkWgW+rFyCMoTeV/BxexvzMjAneSqO0plvbZyKOMzNtNCGPUjD49zzdpgkMo4Gc+fwb9AgbqUj3rRROX+106KJsoSRuTzOeuK+Ar7NJNBH1xX+zKkNHd+FaJiPFGwKTcEOguf0ger04NyZUVpzs4YPJDlZdXjXQEdh9EhnvLSUkPXD6cbPuSCMKoOuuUZIWXA3rwOMdId6dLp63NAv0SxCqiCGO82BfRj1pbn3ocqgorGSTI2l4aSHF5IU9WPH/j1WnaLJVgqCbXyALWE7qXwiPc2/IEmQLe4JnkUjY5RLPNppJk1g5lGoM8Wd/21EsGb4jYuLJlTjHhe2qHY2Xki3r0WoZyLzGYlHMNAZaSBDckMssG3LjSWQSqCwKZM4DypdQ16ROALYQELKL/MSQQS+vD+/hgCf8JDIytnEZyHzllbwhBxctWp4UYbjcsS5dh/YJFbNl6Vgf8i9S+RnqxlV96pyHX881vz9ZskpHvMEwgENDNZqGRUzeyM058VlqspL9mq6VbbTiRNneupQAEyeyZ0oadNhy7dG0oOABVAcwpGGDBWXSd3OYGPcWrbTKpiGbH/NAlsC8sXLtA74mGvupkxXSFJRf75KC8bYZrpb6Q6eLGFHB480lomXw=
secure: fyAUrBhmctUri2wPCcdufPME6EyFLpC4OS4wMAmUc7iNNSUl2C9On0HMkmz1JKD/+fMhlFCvQcpD6O8hNThneSqrv/PANAyz9YXblv35W9v1XbYrzm5IWQ4D30+Zg350SK6Wqn4Wr6jZkRXQKhBo8GQ5aLsDdhr7RgRBpw8p6GwDuda41K9cAOh8vbX2u6guOfeJW+jfwfXgwZUl/DEor8XkIJYcVwOF0989FT0urYf28afnxVgaj5XuIyNQMLC0R0KAsbYO0EPDy1O7a34SFUoNVBXPqP+5wYocML6mKNOFtLfvTAfIeErQc6Is3roJvZqMkcu8zzRH+OdbQfa+3+sUTPbxBAaNvcITO/z36QnYh/Swbnfxn0dD5ue2bAXseVpa55fWw0DPOQkcQ3VJ9hHQfMWTn+4EH6lqYEynSJ0KGbHqzm3Qm15fCj0s+vjvs4axGcYEpZlJaTu9o3oHYJTTDfbkk4b7nbKGQ/vDsYFTRL2yRprYlCQ8YoUnDMOB3YHxmRs7Jgxb9lbg8iD5ZMtP1+QIhUMJTI16ruxs88bRvCaTkfdTOGv0qVhgA9a00+G1XMLxCzpvI8wKgo7+GKRPUyvR2bRCQS6mHtbp6beCqPxgzyfGzg8XU09disST7spqH3E8ohWwVfgkjoBlS9+y62iaiwXRsTVXyeGJpac=
on:
repo: kuzzleio/sdk-javascript
branch: master
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Official Kuzzle Javascript SDK
======

This SDK version is compatible with Kuzzle 1.0.0-RC6 and higher

Please use SDK v1.x for earlier versions of Kuzzle.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kuzzle-sdk",
"version": "2.2.2",
"version": "2.3.0",
"description": "Official Javascript SDK for Kuzzle",
"author": "The Kuzzle Team <support@kuzzle.io>",
"repository": {
Expand Down
28 changes: 12 additions & 16 deletions src/kuzzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,15 +534,11 @@ Kuzzle.prototype.logout = function (cb) {
};

this.query({controller: 'auth', action: 'logout'}, request, {queuable: false}, typeof cb !== 'function' ? null : function(error) {
if (error === null) {
self.unsetJwtToken();
cb(null, self);
}
else {
cb(error);
}
cb(error, self);
});

self.unsetJwtToken();

return self;
};

Expand Down Expand Up @@ -858,7 +854,7 @@ Kuzzle.prototype.getAllStatistics = function (options, cb) {

this.callbackRequired('Kuzzle.getAllStatistics', cb);

this.query({controller:'admin', action: 'getAllStats'}, {}, options, function (err, res) {
this.query({controller:'server', action: 'getAllStats'}, {}, options, function (err, res) {
if (err) {
return cb(err);
}
Expand Down Expand Up @@ -908,7 +904,7 @@ Kuzzle.prototype.getStatistics = function (timestamp, options, cb) {
this.callbackRequired('Kuzzle.getStatistics', cb);

body = timestamp ? {body: {startTime: timestamp}} : {};
this.query({controller: 'admin', action: timestamp ? 'getStats' : 'getLastStats'}, body, options, queryCB);
this.query({controller: 'server', action: timestamp ? 'getStats' : 'getLastStats'}, body, options, queryCB);
};

/**
Expand Down Expand Up @@ -1009,7 +1005,7 @@ Kuzzle.prototype.listCollections = function () {
query.body.size = options.size;
}

this.query({index: index, controller: 'read', action: 'listCollections'}, query, options, function (err, res) {
this.query({index: index, controller: 'collection', action: 'list'}, query, options, function (err, res) {
if (err) {
return cb(err);
}
Expand All @@ -1032,7 +1028,7 @@ Kuzzle.prototype.listIndexes = function (options, cb) {

this.callbackRequired('Kuzzle.listIndexes', cb);

this.query({controller: 'read', action: 'listIndexes'}, {}, options, function (err, res) {
this.query({controller: 'index', action: 'list'}, {}, options, function (err, res) {
cb(err, err ? undefined : res.result.indexes);
});
};
Expand Down Expand Up @@ -1068,7 +1064,7 @@ Kuzzle.prototype.getServerInfo = function (options, cb) {

this.callbackRequired('Kuzzle.getServerInfo', cb);

this.query({controller: 'read', action: 'serverInfo'}, {}, options, function (err, res) {
this.query({controller: 'server', action: 'info'}, {}, options, function (err, res) {
if (err) {
return cb(err);
}
Expand Down Expand Up @@ -1112,7 +1108,7 @@ Kuzzle.prototype.refreshIndex = function () {
index = this.defaultIndex;
}

this.query({ index: index, controller: 'admin', action: 'refreshIndex'}, {}, options, cb);
this.query({ index: index, controller: 'index', action: 'refresh'}, {}, options, cb);

return this;
};
Expand Down Expand Up @@ -1152,7 +1148,7 @@ Kuzzle.prototype.getAutoRefresh = function () {
}

this.callbackRequired('Kuzzle.getAutoRefresh', cb);
this.query({ index: index, controller: 'admin', action: 'getAutoRefresh'}, {}, options, cb);
this.query({ index: index, controller: 'index', action: 'getAutoRefresh'}, {}, options, cb);
};

/**
Expand Down Expand Up @@ -1199,7 +1195,7 @@ Kuzzle.prototype.setAutoRefresh = function () {
throw new Error('Kuzzle.setAutoRefresh: autoRefresh value is required');
}

this.query({ index: index, controller: 'admin', action: 'setAutoRefresh'}, { body: { autoRefresh: autoRefresh }}, options, cb);
this.query({ index: index, controller: 'index', action: 'setAutoRefresh'}, { body: { autoRefresh: autoRefresh }}, options, cb);

return this;
};
Expand All @@ -1217,7 +1213,7 @@ Kuzzle.prototype.now = function (options, cb) {

this.callbackRequired('Kuzzle.now', cb);

this.query({controller: 'read', action: 'now'}, {}, options, function (err, res) {
this.query({controller: 'server', action: 'now'}, {}, options, function (err, res) {
cb(err, res && res.result.now);
});
};
Expand Down
20 changes: 10 additions & 10 deletions src/kuzzleDataCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ KuzzleDataCollection.prototype.advancedSearch = function (filters, options, cb)

query = self.kuzzle.addHeaders({body: filters}, this.headers);

self.kuzzle.query(this.buildQueryArgs('read', 'search'), query, options, function (error, result) {
self.kuzzle.query(this.buildQueryArgs('document', 'search'), query, options, function (error, result) {
var
response,
documents = [];
Expand Down Expand Up @@ -151,7 +151,7 @@ KuzzleDataCollection.prototype.count = function (filters, options, cb) {

query = this.kuzzle.addHeaders({body: filters}, this.headers);

this.kuzzle.query(this.buildQueryArgs('read', 'count'), query, options, function (error, result) {
this.kuzzle.query(this.buildQueryArgs('document', 'count'), query, options, function (error, result) {
cb(error, result && result.result.count);
});
};
Expand All @@ -174,7 +174,7 @@ KuzzleDataCollection.prototype.create = function (options, cb) {
}

data = this.kuzzle.addHeaders(data, this.headers);
this.kuzzle.query(this.buildQueryArgs('write', 'createCollection'), data, options, cb);
this.kuzzle.query(this.buildQueryArgs('collection', 'create'), data, options, cb);

return this;
};
Expand Down Expand Up @@ -229,7 +229,7 @@ KuzzleDataCollection.prototype.createDocument = function (id, document, options,

data = self.kuzzle.addHeaders(data, self.headers);

self.kuzzle.query(this.buildQueryArgs('write', action), data, options, cb && function (err, res) {
self.kuzzle.query(this.buildQueryArgs('document', action), data, options, cb && function (err, res) {
var doc;

if (err) {
Expand Down Expand Up @@ -280,7 +280,7 @@ KuzzleDataCollection.prototype.deleteDocument = function (arg, options, cb) {

data = this.kuzzle.addHeaders(data, this.headers);

this.kuzzle.query(this.buildQueryArgs('write', action), data, options, cb && function (err, res) {
this.kuzzle.query(this.buildQueryArgs('document', action), data, options, cb && function (err, res) {
if (err) {
cb(err);
}
Expand Down Expand Up @@ -312,7 +312,7 @@ KuzzleDataCollection.prototype.fetchDocument = function (documentId, options, cb
self.kuzzle.callbackRequired('KuzzleDataCollection.fetch', cb);
data = self.kuzzle.addHeaders(data, this.headers);

self.kuzzle.query(this.buildQueryArgs('read', 'get'), data, options, function (err, res) {
self.kuzzle.query(this.buildQueryArgs('document', 'get'), data, options, function (err, res) {
var document;

if (err) {
Expand Down Expand Up @@ -398,7 +398,7 @@ KuzzleDataCollection.prototype.publishMessage = function (document, options, cb)
}

data = this.kuzzle.addHeaders(data, this.headers);
this.kuzzle.query(this.buildQueryArgs('write', 'publish'), data, options, cb);
this.kuzzle.query(this.buildQueryArgs('realtime', 'publish'), data, options, cb);

return this;
};
Expand Down Expand Up @@ -431,7 +431,7 @@ KuzzleDataCollection.prototype.replaceDocument = function (documentId, content,

data = self.kuzzle.addHeaders(data, this.headers);

self.kuzzle.query(this.buildQueryArgs('write', 'createOrReplace'), data, options, cb && function (err, res) {
self.kuzzle.query(this.buildQueryArgs('document', 'createOrReplace'), data, options, cb && function (err, res) {
var document;

if (err) {
Expand Down Expand Up @@ -492,7 +492,7 @@ KuzzleDataCollection.prototype.truncate = function (options, cb) {
}

data = this.kuzzle.addHeaders(data, this.headers);
this.kuzzle.query(this.buildQueryArgs('admin', 'truncateCollection'), data, options, cb);
this.kuzzle.query(this.buildQueryArgs('collection', 'truncate'), data, options, cb);

return this;
};
Expand Down Expand Up @@ -526,7 +526,7 @@ KuzzleDataCollection.prototype.updateDocument = function (documentId, content, o

data = self.kuzzle.addHeaders(data, this.headers);

self.kuzzle.query(this.buildQueryArgs('write', 'update'), data, options, cb && function (err, res) {
self.kuzzle.query(this.buildQueryArgs('document', 'update'), data, options, cb && function (err, res) {
if (err) {
return cb(err);
}
Expand Down
4 changes: 2 additions & 2 deletions src/kuzzleDataMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ KuzzleDataMapping.prototype.apply = function (options, cb) {
options = null;
}

self.kuzzle.query(this.collection.buildQueryArgs('admin', 'updateMapping'), data, options, function (err) {
self.kuzzle.query(this.collection.buildQueryArgs('collection', 'updateMapping'), data, options, function (err) {
if (err) {
return cb && cb(err);
}
Expand Down Expand Up @@ -103,7 +103,7 @@ KuzzleDataMapping.prototype.refresh = function (options, cb) {
options = null;
}

this.kuzzle.query(this.collection.buildQueryArgs('admin', 'getMapping'), data, options, function (err, res) {
this.kuzzle.query(this.collection.buildQueryArgs('collection', 'getMapping'), data, options, function (err, res) {
if (err) {
return cb ? cb(err) : false;
}
Expand Down
8 changes: 4 additions & 4 deletions src/kuzzleDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ KuzzleDocument.prototype.delete = function (options, cb) {
throw new Error('KuzzleDocument.delete: cannot delete a document without a document ID');
}

this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'delete'), this.serialize(), options, cb && function (err) {
this.kuzzle.query(this.dataCollection.buildQueryArgs('document', 'delete'), this.serialize(), options, cb && function (err) {
cb(err, err ? undefined : self.id);
});
};
Expand All @@ -172,7 +172,7 @@ KuzzleDocument.prototype.refresh = function (options, cb) {

this.kuzzle.callbackRequired('KuzzleDocument.refresh', cb);

self.kuzzle.query(self.dataCollection.buildQueryArgs('read', 'get'), {_id: self.id}, options, function (error, res) {
self.kuzzle.query(self.dataCollection.buildQueryArgs('document', 'get'), {_id: self.id}, options, function (error, res) {
var newDocument;

if (error) {
Expand Down Expand Up @@ -211,7 +211,7 @@ KuzzleDocument.prototype.save = function (options, cb) {
options = null;
}

self.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'createOrReplace'), data, options, function (error, res) {
self.kuzzle.query(this.dataCollection.buildQueryArgs('document', 'createOrReplace'), data, options, function (error, res) {
if (error) {
return cb && cb(error);
}
Expand Down Expand Up @@ -240,7 +240,7 @@ KuzzleDocument.prototype.save = function (options, cb) {
KuzzleDocument.prototype.publish = function (options) {
var data = this.serialize();

this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'publish'), data, options);
this.kuzzle.query(this.dataCollection.buildQueryArgs('realtime', 'publish'), data, options);

return this;
};
Expand Down
8 changes: 4 additions & 4 deletions src/kuzzleRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ KuzzleRoom.prototype.count = function (cb) {
throw new Error('KuzzleRoom.count: cannot count subscriptions on an inactive room');
}

this.kuzzle.query(this.collection.buildQueryArgs('subscribe', 'count'), data, function (err, res) {
this.kuzzle.query(this.collection.buildQueryArgs('realtime', 'count'), data, function (err, res) {
cb(err, res && res.result.count);
});
};
Expand Down Expand Up @@ -213,7 +213,7 @@ KuzzleRoom.prototype.renew = function (filters, notificationCB, cb) {
subscribeQuery.body = self.filters;
subscribeQuery = self.kuzzle.addHeaders(subscribeQuery, this.headers);

self.kuzzle.query(self.collection.buildQueryArgs('subscribe', 'on'), subscribeQuery, {metadata: self.metadata}, function (error, response) {
self.kuzzle.query(self.collection.buildQueryArgs('realtime', 'subscribe'), subscribeQuery, {metadata: self.metadata}, function (error, response) {
delete self.kuzzle.subscriptions.pending[self.id];
self.subscribing = false;

Expand Down Expand Up @@ -267,12 +267,12 @@ KuzzleRoom.prototype.unsubscribe = function () {
delete self.kuzzle.subscriptions[room];

if (Object.keys(self.kuzzle.subscriptions.pending).length === 0) {
self.kuzzle.query(self.collection.buildQueryArgs('subscribe', 'off'), {body: {roomId: room}});
self.kuzzle.query(self.collection.buildQueryArgs('realtime', 'unsubscribe'), {body: {roomId: room}});
} else {
interval = setInterval(function () {
if (Object.keys(self.kuzzle.subscriptions.pending).length === 0) {
if (!self.kuzzle.subscriptions[room]) {
self.kuzzle.query(self.collection.buildQueryArgs('subscribe', 'off'), {body: {roomId: room}});
self.kuzzle.query(self.collection.buildQueryArgs('realtime', 'unsubscribe'), {body: {roomId: room}});
}
clearInterval(interval);
}
Expand Down
12 changes: 9 additions & 3 deletions src/networkWrapper/wrappers/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,17 @@ function WSNode(host, port, ssl) {
* @param {function} callback
*/
this.off = function (roomId, callback) {
var index;
var index = -1;

if (this.listeners[roomId]) {
index = this.listeners[roomId].findIndex(function (listener) {
return listener.fn === callback;
// Array.findIndex is not supported by internet explorer
this.listeners[roomId].some(function (listener, i) {
if (listener.fn === callback) {
index = i;
return true;
}

return false;
});

if (index !== -1) {
Expand Down
8 changes: 3 additions & 5 deletions test/kuzzle/constructor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ describe('Kuzzle constructor', () => {
kuzzle.login('local', loginCredentials);
});

it('should have a empty token in logout callback', function (done) {
it('should have a empty token in logout callback', function () {
var
unsetJwtToken = false,
kuzzle;
Expand All @@ -918,10 +918,8 @@ describe('Kuzzle constructor', () => {
cb(null, {});
};

kuzzle.logout(function() {
should(unsetJwtToken).be.exactly(true);
done();
});
kuzzle.logout(() => {});
should(unsetJwtToken).be.exactly(true);
});

it('should give an error if login query fail to the logout callback if is set', function (done) {
Expand Down
Loading