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
  *
@@ -6215,7 +6349,11 @@ function algoliasearch(applicationID, apiKey, opts) {
6215
6349
  }
6216
6350
 
6217
6351
  algoliasearch.version = require(38);
6218
- algoliasearch.ua = 'Algolia for jQuery ' + algoliasearch.version;
6352
+
6353
+ algoliasearch.ua =
6354
+ 'Algolia for JavaScript (' + algoliasearch.version + '); ' +
6355
+ 'jQuery (' + window.jQuery().jquery + ')';
6356
+
6219
6357
  algoliasearch.initPlaces = places(algoliasearch);
6220
6358
 
6221
6359
  // we expose into window no matter how we are used, this will allow
@@ -6338,7 +6476,7 @@ AlgoliaSearchJQuery.prototype._promise = {
6338
6476
  var AlgoliaSearch = require(16);
6339
6477
  var createAlgoliasearch = require(23);
6340
6478
 
6341
- module.exports = createAlgoliasearch(AlgoliaSearch);
6479
+ module.exports = createAlgoliasearch(AlgoliaSearch, 'Browser');
6342
6480
 
6343
6481
  },{"16":16,"23":23}],23:[function(require,module,exports){
6344
6482
  (function (process){
@@ -6373,7 +6511,10 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
6373
6511
  }
6374
6512
 
6375
6513
  algoliasearch.version = require(38);
6376
- algoliasearch.ua = 'Algolia for vanilla JavaScript ' + uaSuffix + algoliasearch.version;
6514
+
6515
+ algoliasearch.ua =
6516
+ 'Algolia for JavaScript (' + algoliasearch.version + '); ' + uaSuffix;
6517
+
6377
6518
  algoliasearch.initPlaces = places(algoliasearch);
6378
6519
 
6379
6520
  // we expose into window no matter how we are used, this will allow
@@ -6979,10 +7120,18 @@ module.exports = {
6979
7120
  'JSONPScriptFail',
6980
7121
  '<script> was loaded but did not call our provided callback'
6981
7122
  ),
7123
+ ValidUntilNotFound: createCustomError(
7124
+ 'ValidUntilNotFound',
7125
+ 'The SecuredAPIKey does not have a validUntil parameter.'
7126
+ ),
6982
7127
  JSONPScriptError: createCustomError(
6983
7128
  'JSONPScriptError',
6984
7129
  '<script> unable to load due to an `error` event on it'
6985
7130
  ),
7131
+ ObjectNotFound: createCustomError(
7132
+ 'ObjectNotFound',
7133
+ 'Object not found'
7134
+ ),
6986
7135
  Unknown: createCustomError(
6987
7136
  'Unknown',
6988
7137
  'Unknown error occured'
@@ -7190,6 +7339,6 @@ function cleanup() {
7190
7339
  },{"1":1}],38:[function(require,module,exports){
7191
7340
  'use strict';
7192
7341
 
7193
- module.exports = '3.32.1';
7342
+ module.exports = '3.35.1';
7194
7343
 
7195
7344
  },{}]},{},[21]);