algoliasearch 3.25.0 → 3.27.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.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,24 @@
1
1
  CHANGELOG
2
+
3
+ 2018-05-03 3.27.1
4
+ * FIX: `client.searchForFacetValues` in older browsers
5
+ * we use the polyfill implementation of Promise.all now instead of the native in 3.27.0
6
+ * FIX: `index.saveRule` throw when no objectID is given
7
+ * FEAT: deprecate index API key methods in favor of client ones
8
+ * these methods will be removed, since you can add index restrictions to client API keys
9
+
10
+ 2018-04-16 3.27.0
11
+ * FEAT: add client.searchForFacetValues
12
+ * this allows to request multiple search for facet values in a single call
13
+ * note that this will do multiple requests (one per query)
14
+
15
+ 2018-03-21 3.26.0
16
+ * FEAT: allow disabling of dsn
17
+ * in some cases (backend search while you do have global DSN), you want to disable DSN to avoid a round-robin around the whole world if DNS can't be resolved as expected, for example on GCP. (#675)
18
+
19
+ 2018-03-08 3.25.1
20
+ * FIX: fix protocol detection introduced in 3.25.0
21
+
2
22
  2018-03-07 3.25.0
3
23
  * FEAT: use https by default (#670)
4
24
  * for very old devices https can be slow
package/README.md CHANGED
@@ -246,6 +246,7 @@ transparent with our users.
246
246
  - `hosts.read` ([String]) array of read hosts to use to call Algolia servers, computed automatically
247
247
  - `hosts.write` ([String]) array of write hosts to use to call Algolia servers, computed automatically
248
248
  - `httpAgent` ([HttpAgent](https://nodejs.org/api/http.html#http_class_http_agent)) <sup>node-only</sup> Node.js httpAgent instance to use when communicating with Algolia servers.
249
+ - `dsn` ([Boolean=true]) enable or disable DSN (defaults to true). Disable this when you're in a backend situation, but still have worldwide DSN for another (frontend) search.
249
250
 
250
251
  To pass an option, use:
251
252
 
package/bower.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "algoliasearch",
3
- "version": "3.25.0",
3
+ "version": "3.27.1",
4
4
  "homepage": "https://github.com/algolia/algoliasearch-client-js",
5
5
  "authors": [
6
6
  "Algolia Team <support@algolia.com>"
@@ -1,4 +1,4 @@
1
- /*! algoliasearch 3.25.0 | © 2014, 2015 Algolia SAS | github.com/algolia/algoliasearch-client-js */
1
+ /*! algoliasearch 3.27.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) {
@@ -2980,7 +2980,7 @@ AlgoliaSearch.prototype.addUserKey = deprecate(function(acls, params, callback)
2980
2980
  * content: the server answer with the added API key
2981
2981
  * @return {Promise|undefined} Returns a promise if no callback given
2982
2982
  * @example
2983
- * client.addUserKey(['search'], {
2983
+ * client.addApiKey(['search'], {
2984
2984
  * validity: 300,
2985
2985
  * maxQueriesPerIPPerHour: 2000,
2986
2986
  * maxHitsPerQuery: 3,
@@ -3440,7 +3440,6 @@ function AlgoliaSearchCore(applicationID, apiKey, opts) {
3440
3440
 
3441
3441
  opts = opts || {};
3442
3442
 
3443
- var protocol = opts.protocol || 'https:';
3444
3443
  this._timeouts = opts.timeouts || {
3445
3444
  connect: 1 * 1000, // 500ms connect is GPRS latency
3446
3445
  read: 2 * 1000,
@@ -3452,13 +3451,14 @@ function AlgoliaSearchCore(applicationID, apiKey, opts) {
3452
3451
  this._timeouts.connect = this._timeouts.read = this._timeouts.write = opts.timeout;
3453
3452
  }
3454
3453
 
3454
+ var protocol = opts.protocol || 'https:';
3455
3455
  // while we advocate for colon-at-the-end values: 'http:' for `opts.protocol`
3456
3456
  // we also accept `http` and `https`. It's a common error.
3457
3457
  if (!/:$/.test(protocol)) {
3458
3458
  protocol = protocol + ':';
3459
3459
  }
3460
3460
 
3461
- if (opts.protocol !== 'http:' && opts.protocol !== 'https:') {
3461
+ if (protocol !== 'http:' && protocol !== 'https:') {
3462
3462
  throw new errors.AlgoliaSearchError('protocol must be `http:` or `https:` (was `' + opts.protocol + '`)');
3463
3463
  }
3464
3464
 
@@ -3470,7 +3470,8 @@ function AlgoliaSearchCore(applicationID, apiKey, opts) {
3470
3470
  });
3471
3471
 
3472
3472
  // no hosts given, compute defaults
3473
- this.hosts.read = [this.applicationID + '-dsn.algolia.net'].concat(defaultHosts);
3473
+ var mainSuffix = (opts.dsn === false ? '' : '-dsn') + '.algolia.net';
3474
+ this.hosts.read = [this.applicationID + mainSuffix].concat(defaultHosts);
3474
3475
  this.hosts.write = [this.applicationID + '.algolia.net'].concat(defaultHosts);
3475
3476
  } else if (isArray(opts.hosts)) {
3476
3477
  // when passing custom hosts, we need to have a different host index if the number
@@ -3984,6 +3985,70 @@ AlgoliaSearchCore.prototype.search = function(queries, opts, callback) {
3984
3985
  });
3985
3986
  };
3986
3987
 
3988
+ /**
3989
+ * Search for facet values
3990
+ * https://www.algolia.com/doc/rest-api/search#search-for-facet-values
3991
+ * This is the top-level API for SFFV.
3992
+ *
3993
+ * @param {object[]} queries An array of queries to run.
3994
+ * @param {string} queries[].indexName Index name, name of the index to search.
3995
+ * @param {object} queries[].params Query parameters.
3996
+ * @param {string} queries[].params.facetName Facet name, name of the attribute to search for values in.
3997
+ * Must be declared as a facet
3998
+ * @param {string} queries[].params.facetQuery Query for the facet search
3999
+ * @param {string} [queries[].params.*] Any search parameter of Algolia,
4000
+ * see https://www.algolia.com/doc/api-client/javascript/search#search-parameters
4001
+ * Pagination is not supported. The page and hitsPerPage parameters will be ignored.
4002
+ */
4003
+ AlgoliaSearchCore.prototype.searchForFacetValues = function(queries) {
4004
+ var isArray = require(8);
4005
+ var map = require(30);
4006
+
4007
+ var usage = 'Usage: client.searchForFacetValues([{indexName, params: {facetName, facetQuery, ...params}}, ...queries])'; // eslint-disable-line max-len
4008
+
4009
+ if (!isArray(queries)) {
4010
+ throw new Error(usage);
4011
+ }
4012
+
4013
+ var client = this;
4014
+
4015
+ return client._promise.all(map(queries, function performQuery(query) {
4016
+ if (
4017
+ !query ||
4018
+ query.indexName === undefined ||
4019
+ query.params.facetName === undefined ||
4020
+ query.params.facetQuery === undefined
4021
+ ) {
4022
+ throw new Error(usage);
4023
+ }
4024
+
4025
+ var clone = require(25);
4026
+ var omit = require(32);
4027
+
4028
+ var indexName = query.indexName;
4029
+ var params = query.params;
4030
+
4031
+ var facetName = params.facetName;
4032
+ var filteredParams = omit(clone(params), function(keyName) {
4033
+ return keyName === 'facetName';
4034
+ });
4035
+ var searchParameters = client._getSearchParams(filteredParams, '');
4036
+
4037
+ return client._jsonRequest({
4038
+ cache: client.cache,
4039
+ method: 'POST',
4040
+ url:
4041
+ '/1/indexes/' +
4042
+ encodeURIComponent(indexName) +
4043
+ '/facets/' +
4044
+ encodeURIComponent(facetName) +
4045
+ '/query',
4046
+ hostType: 'read',
4047
+ body: {params: searchParameters}
4048
+ });
4049
+ }));
4050
+ };
4051
+
3987
4052
  /**
3988
4053
  * Set the extra security tagFilters header
3989
4054
  * @param {string|array} tags The list of tags defining the current security filters
@@ -4204,7 +4269,7 @@ function removeCredentials(headers) {
4204
4269
  }
4205
4270
 
4206
4271
  }).call(this,require(12))
4207
- },{"1":1,"12":12,"18":18,"25":25,"28":28,"29":29,"30":30,"34":34,"5":5,"8":8}],16:[function(require,module,exports){
4272
+ },{"1":1,"12":12,"18":18,"25":25,"28":28,"29":29,"30":30,"32":32,"34":34,"5":5,"8":8}],16:[function(require,module,exports){
4208
4273
  var inherits = require(7);
4209
4274
  var IndexCore = require(18);
4210
4275
  var deprecate = require(26);
@@ -5006,6 +5071,7 @@ Index.prototype.searchRules = function(params, callback) {
5006
5071
  * Retrieve all the query rules in an index
5007
5072
  * @param [number=100] hitsPerPage The amount of query rules to retrieve per batch
5008
5073
  * @param [function] callback will be called after all query rules are retrieved
5074
+ * error: null or Error('message')
5009
5075
  */
5010
5076
  Index.prototype.exportRules = function(hitsPerPage, callback) {
5011
5077
  return exportData(this.searchRules.bind(this), hitsPerPage, callback);
@@ -5019,6 +5085,10 @@ Index.prototype.saveRule = function(rule, opts, callback) {
5019
5085
  opts = {};
5020
5086
  }
5021
5087
 
5088
+ if (!rule.objectID) {
5089
+ throw new errors.AlgoliaSearchError('Missing or empty objectID field for rule');
5090
+ }
5091
+
5022
5092
  var forwardToReplicas = opts.forwardToReplicas === true ? 'true' : 'false';
5023
5093
 
5024
5094
  return this.as._jsonRequest({
@@ -5191,11 +5261,11 @@ Index.prototype.setSettings = function(settings, opts, callback) {
5191
5261
  };
5192
5262
 
5193
5263
  /*
5194
- @deprecated see index.listApiKeys
5195
- */
5264
+ * @deprecated see client.listApiKeys()
5265
+ */
5196
5266
  Index.prototype.listUserKeys = deprecate(function(callback) {
5197
5267
  return this.listApiKeys(callback);
5198
- }, deprecatedMessage('index.listUserKeys()', 'index.listApiKeys()'));
5268
+ }, deprecatedMessage('index.listUserKeys()', 'client.listApiKeys()'));
5199
5269
 
5200
5270
  /*
5201
5271
  * List all existing API keys to this index
@@ -5203,8 +5273,10 @@ Index.prototype.listUserKeys = deprecate(function(callback) {
5203
5273
  * @param callback the result callback called with two arguments
5204
5274
  * error: null or Error('message')
5205
5275
  * content: the server answer with API keys belonging to the index
5276
+ *
5277
+ * @deprecated see client.listApiKeys()
5206
5278
  */
5207
- Index.prototype.listApiKeys = function(callback) {
5279
+ Index.prototype.listApiKeys = deprecate(function(callback) {
5208
5280
  var indexObj = this;
5209
5281
  return this.as._jsonRequest({
5210
5282
  method: 'GET',
@@ -5212,14 +5284,14 @@ Index.prototype.listApiKeys = function(callback) {
5212
5284
  hostType: 'read',
5213
5285
  callback: callback
5214
5286
  });
5215
- };
5287
+ }, deprecatedMessage('index.listApiKeys()', 'client.listApiKeys()'));
5216
5288
 
5217
5289
  /*
5218
- @deprecated see index.getApiKey
5219
- */
5290
+ * @deprecated see client.getApiKey()
5291
+ */
5220
5292
  Index.prototype.getUserKeyACL = deprecate(function(key, callback) {
5221
5293
  return this.getApiKey(key, callback);
5222
- }, deprecatedMessage('index.getUserKeyACL()', 'index.getApiKey()'));
5294
+ }, deprecatedMessage('index.getUserKeyACL()', 'client.getApiKey()'));
5223
5295
 
5224
5296
 
5225
5297
  /*
@@ -5229,8 +5301,10 @@ Index.prototype.getUserKeyACL = deprecate(function(key, callback) {
5229
5301
  * @param callback the result callback called with two arguments
5230
5302
  * error: null or Error('message')
5231
5303
  * content: the server answer with the right API key
5304
+ *
5305
+ * @deprecated see client.getApiKey()
5232
5306
  */
5233
- Index.prototype.getApiKey = function(key, callback) {
5307
+ Index.prototype.getApiKey = deprecate(function(key, callback) {
5234
5308
  var indexObj = this;
5235
5309
  return this.as._jsonRequest({
5236
5310
  method: 'GET',
@@ -5238,14 +5312,14 @@ Index.prototype.getApiKey = function(key, callback) {
5238
5312
  hostType: 'read',
5239
5313
  callback: callback
5240
5314
  });
5241
- };
5315
+ }, deprecatedMessage('index.getApiKey()', 'client.getApiKey()'));
5242
5316
 
5243
5317
  /*
5244
- @deprecated see index.deleteApiKey
5245
- */
5318
+ * @deprecated see client.deleteApiKey()
5319
+ */
5246
5320
  Index.prototype.deleteUserKey = deprecate(function(key, callback) {
5247
5321
  return this.deleteApiKey(key, callback);
5248
- }, deprecatedMessage('index.deleteUserKey()', 'index.deleteApiKey()'));
5322
+ }, deprecatedMessage('index.deleteUserKey()', 'client.deleteApiKey()'));
5249
5323
 
5250
5324
  /*
5251
5325
  * Delete an existing API key associated to this index
@@ -5254,8 +5328,10 @@ Index.prototype.deleteUserKey = deprecate(function(key, callback) {
5254
5328
  * @param callback the result callback called with two arguments
5255
5329
  * error: null or Error('message')
5256
5330
  * content: the server answer with the deletion date
5331
+ *
5332
+ * @deprecated see client.deleteApiKey()
5257
5333
  */
5258
- Index.prototype.deleteApiKey = function(key, callback) {
5334
+ Index.prototype.deleteApiKey = deprecate(function(key, callback) {
5259
5335
  var indexObj = this;
5260
5336
  return this.as._jsonRequest({
5261
5337
  method: 'DELETE',
@@ -5263,14 +5339,14 @@ Index.prototype.deleteApiKey = function(key, callback) {
5263
5339
  hostType: 'write',
5264
5340
  callback: callback
5265
5341
  });
5266
- };
5342
+ }, deprecatedMessage('index.deleteApiKey()', 'client.deleteApiKey()'));
5267
5343
 
5268
5344
  /*
5269
- @deprecated see index.addApiKey
5270
- */
5345
+ * @deprecated see client.addApiKey()
5346
+ */
5271
5347
  Index.prototype.addUserKey = deprecate(function(acls, params, callback) {
5272
5348
  return this.addApiKey(acls, params, callback);
5273
- }, deprecatedMessage('index.addUserKey()', 'index.addApiKey()'));
5349
+ }, deprecatedMessage('index.addUserKey()', 'client.addApiKey()'));
5274
5350
 
5275
5351
  /*
5276
5352
  * Add a new API key to this index
@@ -5307,8 +5383,10 @@ Index.prototype.addUserKey = deprecate(function(acls, params, callback) {
5307
5383
  * }
5308
5384
  * })
5309
5385
  * @see {@link https://www.algolia.com/doc/rest_api#AddIndexKey|Algolia REST API Documentation}
5386
+ *
5387
+ * @deprecated see client.addApiKey()
5310
5388
  */
5311
- Index.prototype.addApiKey = function(acls, params, callback) {
5389
+ Index.prototype.addApiKey = deprecate(function(acls, params, callback) {
5312
5390
  var isArray = require(8);
5313
5391
  var usage = 'Usage: index.addApiKey(arrayOfAcls[, params, callback])';
5314
5392
 
@@ -5345,21 +5423,21 @@ Index.prototype.addApiKey = function(acls, params, callback) {
5345
5423
  hostType: 'write',
5346
5424
  callback: callback
5347
5425
  });
5348
- };
5426
+ }, deprecatedMessage('index.addApiKey()', 'client.addApiKey()'));
5349
5427
 
5350
5428
  /**
5351
- * @deprecated use index.addApiKey()
5429
+ * @deprecated use client.addApiKey()
5352
5430
  */
5353
5431
  Index.prototype.addUserKeyWithValidity = deprecate(function deprecatedAddUserKeyWithValidity(acls, params, callback) {
5354
5432
  return this.addApiKey(acls, params, callback);
5355
- }, deprecatedMessage('index.addUserKeyWithValidity()', 'index.addApiKey()'));
5433
+ }, deprecatedMessage('index.addUserKeyWithValidity()', 'client.addApiKey()'));
5356
5434
 
5357
5435
  /*
5358
- @deprecated see index.updateApiKey
5359
- */
5436
+ * @deprecated see client.updateApiKey()
5437
+ */
5360
5438
  Index.prototype.updateUserKey = deprecate(function(key, acls, params, callback) {
5361
5439
  return this.updateApiKey(key, acls, params, callback);
5362
- }, deprecatedMessage('index.updateUserKey()', 'index.updateApiKey()'));
5440
+ }, deprecatedMessage('index.updateUserKey()', 'client.updateApiKey()'));
5363
5441
 
5364
5442
  /**
5365
5443
  * Update an existing API key of this index
@@ -5396,8 +5474,10 @@ Index.prototype.updateUserKey = deprecate(function(key, acls, params, callback)
5396
5474
  * }
5397
5475
  * })
5398
5476
  * @see {@link https://www.algolia.com/doc/rest_api#UpdateIndexKey|Algolia REST API Documentation}
5477
+ *
5478
+ * @deprecated see client.updateApiKey()
5399
5479
  */
5400
- Index.prototype.updateApiKey = function(key, acls, params, callback) {
5480
+ Index.prototype.updateApiKey = deprecate(function(key, acls, params, callback) {
5401
5481
  var isArray = require(8);
5402
5482
  var usage = 'Usage: index.updateApiKey(key, arrayOfAcls[, params, callback])';
5403
5483
 
@@ -5434,7 +5514,7 @@ Index.prototype.updateApiKey = function(key, acls, params, callback) {
5434
5514
  hostType: 'write',
5435
5515
  callback: callback
5436
5516
  });
5437
- };
5517
+ }, deprecatedMessage('index.updateApiKey()', 'client.updateApiKey()'));
5438
5518
 
5439
5519
  },{"17":17,"18":18,"25":25,"26":26,"27":27,"28":28,"29":29,"30":30,"31":31,"7":7,"8":8}],17:[function(require,module,exports){
5440
5520
  'use strict';
@@ -6051,6 +6131,9 @@ window.angular.module('algoliasearch', [])
6051
6131
  $timeout(resolve, ms);
6052
6132
 
6053
6133
  return deferred.promise;
6134
+ },
6135
+ all: function(promises) {
6136
+ return $q.all(promises);
6054
6137
  }
6055
6138
  };
6056
6139
 
@@ -6282,6 +6365,9 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
6282
6365
  return new Promise(function resolveOnTimeout(resolve/* , reject*/) {
6283
6366
  setTimeout(resolve, ms);
6284
6367
  });
6368
+ },
6369
+ all: function all(promises) {
6370
+ return Promise.all(promises);
6285
6371
  }
6286
6372
  };
6287
6373
 
@@ -6802,6 +6888,6 @@ function cleanup() {
6802
6888
  },{"1":1}],35:[function(require,module,exports){
6803
6889
  'use strict';
6804
6890
 
6805
- module.exports = '3.25.0';
6891
+ module.exports = '3.27.1';
6806
6892
 
6807
6893
  },{}]},{},[19]);