algoliasearch 3.32.1 → 3.35.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- /*! algoliasearch 3.32.1 | © 2014, 2015 Algolia SAS | github.com/algolia/algoliasearch-client-js */
1
+ /*! algoliasearch 3.35.1 | © 2014, 2015 Algolia SAS | github.com/algolia/algoliasearch-client-js */
2
2
  (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){
3
3
 
4
4
  module.exports = function load (src, opts, cb) {
@@ -3054,6 +3054,27 @@ AlgoliaSearch.prototype.deleteApiKey = function(key, callback) {
3054
3054
  });
3055
3055
  };
3056
3056
 
3057
+ /**
3058
+ * Restore a deleted API key
3059
+ *
3060
+ * @param {String} key - The key to restore
3061
+ * @param {Function} callback - The result callback called with two arguments
3062
+ * error: null or Error('message')
3063
+ * content: the server answer with the restored API key
3064
+ * @return {Promise|undefined} Returns a promise if no callback given
3065
+ * @example
3066
+ * client.restoreApiKey('APIKEY')
3067
+ * @see {@link https://www.algolia.com/doc/rest-api/search/#restore-api-key|Algolia REST API Documentation}
3068
+ */
3069
+ AlgoliaSearch.prototype.restoreApiKey = function(key, callback) {
3070
+ return this._jsonRequest({
3071
+ method: 'POST',
3072
+ url: '/1/keys/' + key + '/restore',
3073
+ hostType: 'write',
3074
+ callback: callback
3075
+ });
3076
+ };
3077
+
3057
3078
  /*
3058
3079
  @deprecated see client.addApiKey
3059
3080
  */
@@ -3334,6 +3355,31 @@ AlgoliaSearch.prototype.assignUserID = function(data, callback) {
3334
3355
  });
3335
3356
  };
3336
3357
 
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
+
3337
3383
  /**
3338
3384
  * Get the top userIDs
3339
3385
  *
@@ -3520,6 +3566,7 @@ AlgoliaSearch.prototype.disableRateLimitForward = notImplemented;
3520
3566
  AlgoliaSearch.prototype.useSecuredAPIKey = notImplemented;
3521
3567
  AlgoliaSearch.prototype.disableSecuredAPIKey = notImplemented;
3522
3568
  AlgoliaSearch.prototype.generateSecuredApiKey = notImplemented;
3569
+ AlgoliaSearch.prototype.getSecuredApiKeyRemainingValidity = notImplemented;
3523
3570
 
3524
3571
  function notImplemented() {
3525
3572
  var message = 'Not implemented in this environment.\n' +
@@ -3703,8 +3750,10 @@ AlgoliaSearchCore.prototype.unsetExtraHeader = function(name) {
3703
3750
  * @param algoliaAgent the agent to add
3704
3751
  */
3705
3752
  AlgoliaSearchCore.prototype.addAlgoliaAgent = function(algoliaAgent) {
3706
- if (this._ua.indexOf(';' + algoliaAgent) === -1) {
3707
- this._ua += ';' + algoliaAgent;
3753
+ var algoliaAgentWithDelimiter = '; ' + algoliaAgent;
3754
+
3755
+ if (this._ua.indexOf(algoliaAgentWithDelimiter) === -1) {
3756
+ this._ua += algoliaAgentWithDelimiter;
3708
3757
  }
3709
3758
  };
3710
3759
 
@@ -4100,7 +4149,7 @@ AlgoliaSearchCore.prototype._computeRequestHeaders = function(options) {
4100
4149
  var forEach = require(5);
4101
4150
 
4102
4151
  var ua = options.additionalUA ?
4103
- this._ua + ';' + options.additionalUA :
4152
+ this._ua + '; ' + options.additionalUA :
4104
4153
  this._ua;
4105
4154
 
4106
4155
  var requestHeaders = {
@@ -5402,6 +5451,91 @@ Index.prototype.batchRules = function(rules, opts, callback) {
5402
5451
  });
5403
5452
  };
5404
5453
 
5454
+ Index.prototype.exists = function(callback) {
5455
+ var result = this.getSettings().then(function() {
5456
+ return true;
5457
+ }).catch(function(err) {
5458
+ if (err instanceof errors.AlgoliaSearchError && err.statusCode === 404) {
5459
+ return false;
5460
+ }
5461
+
5462
+ throw err;
5463
+ });
5464
+
5465
+ if (typeof callback !== 'function') {
5466
+ return result;
5467
+ }
5468
+
5469
+ result.then(function(res) {
5470
+ callback(null, res);
5471
+ }).catch(function(err) {
5472
+ callback(err);
5473
+ });
5474
+ };
5475
+
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
+
5405
5539
  /*
5406
5540
  * Set settings for this index
5407
5541
  *
@@ -6219,7 +6353,11 @@ window.angular.module('algoliasearch', [])
6219
6353
  }
6220
6354
 
6221
6355
  algoliasearch.version = require(38);
6222
- algoliasearch.ua = 'Algolia for AngularJS ' + algoliasearch.version;
6356
+
6357
+ algoliasearch.ua =
6358
+ 'Algolia for JavaScript (' + algoliasearch.version + '); ' +
6359
+ 'AngularJS (' + window.angular.version.full + ')';
6360
+
6223
6361
  algoliasearch.initPlaces = places(algoliasearch);
6224
6362
 
6225
6363
  // we expose into window no matter how we are used, this will allow
@@ -6392,7 +6530,7 @@ window.angular.module('algoliasearch', [])
6392
6530
  var AlgoliaSearch = require(16);
6393
6531
  var createAlgoliasearch = require(23);
6394
6532
 
6395
- module.exports = createAlgoliasearch(AlgoliaSearch);
6533
+ module.exports = createAlgoliasearch(AlgoliaSearch, 'Browser');
6396
6534
 
6397
6535
  },{"16":16,"23":23}],23:[function(require,module,exports){
6398
6536
  (function (process){
@@ -6427,7 +6565,10 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
6427
6565
  }
6428
6566
 
6429
6567
  algoliasearch.version = require(38);
6430
- algoliasearch.ua = 'Algolia for vanilla JavaScript ' + uaSuffix + algoliasearch.version;
6568
+
6569
+ algoliasearch.ua =
6570
+ 'Algolia for JavaScript (' + algoliasearch.version + '); ' + uaSuffix;
6571
+
6431
6572
  algoliasearch.initPlaces = places(algoliasearch);
6432
6573
 
6433
6574
  // we expose into window no matter how we are used, this will allow
@@ -7033,10 +7174,18 @@ module.exports = {
7033
7174
  'JSONPScriptFail',
7034
7175
  '<script> was loaded but did not call our provided callback'
7035
7176
  ),
7177
+ ValidUntilNotFound: createCustomError(
7178
+ 'ValidUntilNotFound',
7179
+ 'The SecuredAPIKey does not have a validUntil parameter.'
7180
+ ),
7036
7181
  JSONPScriptError: createCustomError(
7037
7182
  'JSONPScriptError',
7038
7183
  '<script> unable to load due to an `error` event on it'
7039
7184
  ),
7185
+ ObjectNotFound: createCustomError(
7186
+ 'ObjectNotFound',
7187
+ 'Object not found'
7188
+ ),
7040
7189
  Unknown: createCustomError(
7041
7190
  'Unknown',
7042
7191
  'Unknown error occured'
@@ -7244,6 +7393,6 @@ function cleanup() {
7244
7393
  },{"1":1}],38:[function(require,module,exports){
7245
7394
  'use strict';
7246
7395
 
7247
- module.exports = '3.32.1';
7396
+ module.exports = '3.35.1';
7248
7397
 
7249
7398
  },{}]},{},[21]);