Skip to content

Commit cff5f96

Browse files
committed
3.35.0
* FEAT(remaining-validity): adds remaining valitity method (#778) * FEAT(unit-testing-relevance): adds unit testing relevance methods (#777) * FEAT(adds-assign-user-ids): adds assignUserIDs method and tests (#783)
1 parent 1688b1e commit cff5f96

12 files changed

+336
-26
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# CHANGELOG
22

3+
## 3.35.0
4+
>2019-09-26
5+
6+
* FEAT(remaining-validity): adds remaining valitity method (#778)
7+
* `client.getSecuredApiKeyRemainingValidity('securedAPIKey')`: Gets remaining validity seconds of an secured API Key
8+
* FEAT(unit-testing-relevance): adds unit testing relevance methods (#777)
9+
* `index.findObject(hit => hit.firstname == 'Jimmie')`: Find an object by the given condition
10+
* `index.getObjectPosition(results, 'a-unique-identifier')`: Retrieve the given object position in the given results set
11+
* FEAT(adds-assign-user-ids): adds assignUserIDs method and tests (#783)
12+
* `client.assignUserIDs({ cluster: 'c1-test', userIDs: ['some-user-1', 'some-user-2'] })`: Assign a array of userIDs to a cluster
13+
314
## 3.34.0
415
>2019-08-29
516

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "algoliasearch",
3-
"version": "3.34.0",
3+
"version": "3.35.0",
44
"homepage": "https://github.com/algolia/algoliasearch-client-js",
55
"authors": [
66
"Algolia Team <[email protected]>"

dist/algoliasearch.angular.js

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! algoliasearch 3.34.0 | © 2014, 2015 Algolia SAS | github.com/algolia/algoliasearch-client-js */
1+
/*! algoliasearch 3.35.0 | © 2014, 2015 Algolia SAS | github.com/algolia/algoliasearch-client-js */
22
(function(f){var g;if(typeof window!=='undefined'){g=window}else if(typeof self!=='undefined'){g=self}g.ALGOLIA_MIGRATION_LAYER=f()})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
33

44
module.exports = function load (src, opts, cb) {
@@ -3355,6 +3355,31 @@ AlgoliaSearch.prototype.assignUserID = function(data, callback) {
33553355
});
33563356
};
33573357

3358+
/**
3359+
* Assign a array of userIDs to a cluster.
3360+
*
3361+
* @param {Array} data.userIDs The array of userIDs to assign to a new cluster
3362+
* @param {string} data.cluster The cluster to assign the user to
3363+
* @return {Promise|undefined} Returns a promise if no callback given
3364+
* @example
3365+
* client.assignUserIDs({ cluster: 'c1-test', userIDs: ['some-user-1', 'some-user-2'] });
3366+
*/
3367+
AlgoliaSearch.prototype.assignUserIDs = function(data, callback) {
3368+
if (!data.userIDs || !data.cluster) {
3369+
throw new errors.AlgoliaSearchError('You have to provide both an array of userIDs and cluster', data);
3370+
}
3371+
return this._jsonRequest({
3372+
method: 'POST',
3373+
url: '/1/clusters/mapping/batch',
3374+
hostType: 'write',
3375+
body: {
3376+
cluster: data.cluster,
3377+
users: data.userIDs
3378+
},
3379+
callback: callback
3380+
});
3381+
};
3382+
33583383
/**
33593384
* Get the top userIDs
33603385
*
@@ -3541,6 +3566,7 @@ AlgoliaSearch.prototype.disableRateLimitForward = notImplemented;
35413566
AlgoliaSearch.prototype.useSecuredAPIKey = notImplemented;
35423567
AlgoliaSearch.prototype.disableSecuredAPIKey = notImplemented;
35433568
AlgoliaSearch.prototype.generateSecuredApiKey = notImplemented;
3569+
AlgoliaSearch.prototype.getSecuredApiKeyRemainingValidity = notImplemented;
35443570

35453571
function notImplemented() {
35463572
var message = 'Not implemented in this environment.\n' +
@@ -5447,6 +5473,69 @@ Index.prototype.exists = function(callback) {
54475473
});
54485474
};
54495475

5476+
Index.prototype.findObject = function(findCallback, requestOptions, callback) {
5477+
requestOptions = requestOptions === undefined ? {} : requestOptions;
5478+
var paginate = requestOptions.paginate !== undefined ? requestOptions.paginate : true;
5479+
var query = requestOptions.query !== undefined ? requestOptions.query : '';
5480+
5481+
var that = this;
5482+
var page = 0;
5483+
5484+
var paginateLoop = function() {
5485+
requestOptions.page = page;
5486+
5487+
return that.search(query, requestOptions).then(function(result) {
5488+
var hits = result.hits;
5489+
5490+
for (var position = 0; position < hits.length; position++) {
5491+
var hit = hits[position];
5492+
if (findCallback(hit)) {
5493+
return {
5494+
object: hit,
5495+
position: position,
5496+
page: page
5497+
};
5498+
}
5499+
}
5500+
5501+
page += 1;
5502+
5503+
// paginate if option was set and has next page
5504+
if (!paginate || page >= result.nbPages) {
5505+
throw new errors.ObjectNotFound('Object not found');
5506+
}
5507+
5508+
return paginateLoop();
5509+
});
5510+
};
5511+
5512+
var promise = paginateLoop(page);
5513+
5514+
if (callback === undefined) {
5515+
return promise;
5516+
}
5517+
5518+
promise
5519+
.then(function(res) {
5520+
callback(null, res);
5521+
})
5522+
.catch(function(err) {
5523+
callback(err);
5524+
});
5525+
};
5526+
5527+
Index.prototype.getObjectPosition = function(result, objectID) {
5528+
var hits = result.hits;
5529+
5530+
for (var position = 0; position < hits.length; position++) {
5531+
if (hits[position].objectID === objectID) {
5532+
return position;
5533+
}
5534+
}
5535+
5536+
return -1;
5537+
};
5538+
54505539
/*
54515540
* Set settings for this index
54525541
*
@@ -7085,10 +7174,18 @@ module.exports = {
70857174
'JSONPScriptFail',
70867175
'<script> was loaded but did not call our provided callback'
70877176
),
7177+
ValidUntilNotFound: createCustomError(
7178+
'ValidUntilNotFound',
7179+
'The SecuredAPIKey does not have a validUntil parameter.'
7180+
),
70887181
JSONPScriptError: createCustomError(
70897182
'JSONPScriptError',
70907183
'<script> unable to load due to an `error` event on it'
70917184
),
7185+
ObjectNotFound: createCustomError(
7186+
'ObjectNotFound',
7187+
'Object not found'
7188+
),
70927189
Unknown: createCustomError(
70937190
'Unknown',
70947191
'Unknown error occured'
@@ -7296,6 +7393,6 @@ function cleanup() {
72967393
},{"1":1}],38:[function(require,module,exports){
72977394
'use strict';
72987395

7299-
module.exports = '3.34.0';
7396+
module.exports = '3.35.0';
73007397

73017398
},{}]},{},[21]);

dist/algoliasearch.angular.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/algoliasearch.jquery.js

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! algoliasearch 3.34.0 | © 2014, 2015 Algolia SAS | github.com/algolia/algoliasearch-client-js */
1+
/*! algoliasearch 3.35.0 | © 2014, 2015 Algolia SAS | github.com/algolia/algoliasearch-client-js */
22
(function(f){var g;if(typeof window!=='undefined'){g=window}else if(typeof self!=='undefined'){g=self}g.ALGOLIA_MIGRATION_LAYER=f()})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
33

44
module.exports = function load (src, opts, cb) {
@@ -3355,6 +3355,31 @@ AlgoliaSearch.prototype.assignUserID = function(data, callback) {
33553355
});
33563356
};
33573357

3358+
/**
3359+
* Assign a array of userIDs to a cluster.
3360+
*
3361+
* @param {Array} data.userIDs The array of userIDs to assign to a new cluster
3362+
* @param {string} data.cluster The cluster to assign the user to
3363+
* @return {Promise|undefined} Returns a promise if no callback given
3364+
* @example
3365+
* client.assignUserIDs({ cluster: 'c1-test', userIDs: ['some-user-1', 'some-user-2'] });
3366+
*/
3367+
AlgoliaSearch.prototype.assignUserIDs = function(data, callback) {
3368+
if (!data.userIDs || !data.cluster) {
3369+
throw new errors.AlgoliaSearchError('You have to provide both an array of userIDs and cluster', data);
3370+
}
3371+
return this._jsonRequest({
3372+
method: 'POST',
3373+
url: '/1/clusters/mapping/batch',
3374+
hostType: 'write',
3375+
body: {
3376+
cluster: data.cluster,
3377+
users: data.userIDs
3378+
},
3379+
callback: callback
3380+
});
3381+
};
3382+
33583383
/**
33593384
* Get the top userIDs
33603385
*
@@ -3541,6 +3566,7 @@ AlgoliaSearch.prototype.disableRateLimitForward = notImplemented;
35413566
AlgoliaSearch.prototype.useSecuredAPIKey = notImplemented;
35423567
AlgoliaSearch.prototype.disableSecuredAPIKey = notImplemented;
35433568
AlgoliaSearch.prototype.generateSecuredApiKey = notImplemented;
3569+
AlgoliaSearch.prototype.getSecuredApiKeyRemainingValidity = notImplemented;
35443570

35453571
function notImplemented() {
35463572
var message = 'Not implemented in this environment.\n' +
@@ -5447,6 +5473,69 @@ Index.prototype.exists = function(callback) {
54475473
});
54485474
};
54495475

5476+
Index.prototype.findObject = function(findCallback, requestOptions, callback) {
5477+
requestOptions = requestOptions === undefined ? {} : requestOptions;
5478+
var paginate = requestOptions.paginate !== undefined ? requestOptions.paginate : true;
5479+
var query = requestOptions.query !== undefined ? requestOptions.query : '';
5480+
5481+
var that = this;
5482+
var page = 0;
5483+
5484+
var paginateLoop = function() {
5485+
requestOptions.page = page;
5486+
5487+
return that.search(query, requestOptions).then(function(result) {
5488+
var hits = result.hits;
5489+
5490+
for (var position = 0; position < hits.length; position++) {
5491+
var hit = hits[position];
5492+
if (findCallback(hit)) {
5493+
return {
5494+
object: hit,
5495+
position: position,
5496+
page: page
5497+
};
5498+
}
5499+
}
5500+
5501+
page += 1;
5502+
5503+
// paginate if option was set and has next page
5504+
if (!paginate || page >= result.nbPages) {
5505+
throw new errors.ObjectNotFound('Object not found');
5506+
}
5507+
5508+
return paginateLoop();
5509+
});
5510+
};
5511+
5512+
var promise = paginateLoop(page);
5513+
5514+
if (callback === undefined) {
5515+
return promise;
5516+
}
5517+
5518+
promise
5519+
.then(function(res) {
5520+
callback(null, res);
5521+
})
5522+
.catch(function(err) {
5523+
callback(err);
5524+
});
5525+
};
5526+
5527+
Index.prototype.getObjectPosition = function(result, objectID) {
5528+
var hits = result.hits;
5529+
5530+
for (var position = 0; position < hits.length; position++) {
5531+
if (hits[position].objectID === objectID) {
5532+
return position;
5533+
}
5534+
}
5535+
5536+
return -1;
5537+
};
5538+
54505539
/*
54515540
* Set settings for this index
54525541
*
@@ -7031,10 +7120,18 @@ module.exports = {
70317120
'JSONPScriptFail',
70327121
'<script> was loaded but did not call our provided callback'
70337122
),
7123+
ValidUntilNotFound: createCustomError(
7124+
'ValidUntilNotFound',
7125+
'The SecuredAPIKey does not have a validUntil parameter.'
7126+
),
70347127
JSONPScriptError: createCustomError(
70357128
'JSONPScriptError',
70367129
'<script> unable to load due to an `error` event on it'
70377130
),
7131+
ObjectNotFound: createCustomError(
7132+
'ObjectNotFound',
7133+
'Object not found'
7134+
),
70387135
Unknown: createCustomError(
70397136
'Unknown',
70407137
'Unknown error occured'
@@ -7242,6 +7339,6 @@ function cleanup() {
72427339
},{"1":1}],38:[function(require,module,exports){
72437340
'use strict';
72447341

7245-
module.exports = '3.34.0';
7342+
module.exports = '3.35.0';
72467343

72477344
},{}]},{},[21]);

dist/algoliasearch.jquery.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)