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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 3.35.1
4
+ >2019-10-08
5
+
6
+ * FIX: extra comma on node v8 engine (#790)
7
+
8
+ ## 3.35.0
9
+ >2019-09-26
10
+
11
+ * FEAT(remaining-validity): adds remaining valitity method (#778)
12
+ * `client.getSecuredApiKeyRemainingValidity('securedAPIKey')`: Gets remaining validity seconds of an secured API Key
13
+ * FEAT(unit-testing-relevance): adds unit testing relevance methods (#777)
14
+ * `index.findObject(hit => hit.firstname == 'Jimmie')`: Find an object by the given condition
15
+ * `index.getObjectPosition(results, 'a-unique-identifier')`: Retrieve the given object position in the given results set
16
+ * FEAT(adds-assign-user-ids): adds assignUserIDs method and tests (#783)
17
+ * `client.assignUserIDs({ cluster: 'c1-test', userIDs: ['some-user-1', 'some-user-2'] })`: Assign a array of userIDs to a cluster
18
+
19
+ ## 3.34.0
20
+ >2019-08-29
21
+
22
+ * FEAT(index-exists): adds exists method into index (#773)
23
+ * `index.exist()`: returns whether an index exists or not
24
+
25
+ ## 3.33.0
26
+ >2019-05-09
27
+
28
+ * FEAT(api-keys): add restore api key method (#754)
29
+ * `client.restoreApiKey('APIKEY')`: restore a deleted API key
30
+ * see also https://www.algolia.com/doc/api-reference/api-methods/restore-api-key
31
+ * FIX(ua): change the User-Agent to use the new specs lib (version) (#747)
32
+
3
33
  ## 3.32.1
4
34
  >2019-03-14
5
35
 
@@ -712,7 +742,7 @@ allow more flexible proxy/keepAlive agents in some more complex environments
712
742
  Added description, referers, queryParameters
713
743
  ref: https://www.algolia.com/changes#released-##
714
744
  >2015-05-08
715
-
745
+
716
746
  * fix: IE11 xhr cache was fixed by adding cache-control: no-cache in API headers
717
747
  * test: add integration testing and rework the travis tasks
718
748
 
package/README.md CHANGED
@@ -1,360 +1,81 @@
1
- # Algolia Search API Client for JavaScript
2
-
3
- [Algolia Search](https://www.algolia.com) is a hosted full-text, numerical, and faceted search engine capable of delivering realtime results from the first keystroke.
4
- The **Algolia Search API Client for JavaScript** lets you easily use the [Algolia Search REST API](https://www.algolia.com/doc/rest-api/search) from your JavaScript code.
5
-
6
- [![Version][version-svg]][package-url] [![Build Status][travis-svg]][travis-url] [![License][license-image]][license-url] [![Downloads][downloads-image]][downloads-url] [![jsDelivr Hits][jsdelivr-badge]][jsdelivr-hits]
7
-
8
- [![Browser tests][browser-test-matrix]][browser-test-url]
9
-
10
- [travis-svg]: https://img.shields.io/travis/algolia/algoliasearch-client-javascript/master.svg?style=flat-square
11
- [travis-url]: https://travis-ci.org/algolia/algoliasearch-client-javascript
12
- [jsdelivr-badge]: https://data.jsdelivr.com/v1/package/npm/algoliasearch/badge
13
- [jsdelivr-hits]: https://www.jsdelivr.com/package/npm/algoliasearch
14
- [license-image]: https://img.shields.io/badge/license-MIT-green.svg?style=flat-square
15
- [license-url]: LICENSE.txt
16
- [downloads-image]: https://img.shields.io/npm/dm/algoliasearch.svg?style=flat-square
17
- [downloads-url]: http://npm-stat.com/charts.html?package=algoliasearch
18
- [browser-test-matrix]: https://saucelabs.com/browser-matrix/algoliasearch-js.svg
19
- [browser-test-url]: https://saucelabs.com/u/algoliasearch-js
20
- [version-svg]: https://img.shields.io/npm/v/algoliasearch.svg?style=flat-square
21
- [package-url]: https://npmjs.org/package/algoliasearch
22
-
23
-
24
- The JavaScript client works both on the frontend (browsers) or on the backend (Node.js) with the same API.
25
-
26
- The backend (Node.js) API can be used to index your data using your Algolia admin API keys.
27
-
28
- Our JavaScript library is [UMD](https://github.com/umdjs/umd) compatible, you can
29
- use it with any module loader.
30
-
31
- When not using any module loader, it will export an `algoliasearch` function in the `window` object.
32
-
33
-
34
-
35
-
36
- ## API Documentation
37
-
38
- You can find the full reference on [Algolia's website](https://www.algolia.com/doc/api-client/javascript/).
39
-
40
-
41
- ## Table of Contents
42
-
43
-
44
- 1. **[Install](#install)**
45
-
46
- * [Frontend](#frontend)
47
- * [Node.js / React Native / Browserify / webpack](#nodejs--react-native--browserify--webpack)
48
- * [TypeScript typings](#typescript-typings)
49
- * [NativeScript](#nativescript)
50
- * [Bower](#bower)
51
- * [<script> tag using CDNs](#script-tag-using-cdns)
52
- * [Search only/lite client](#search-onlylite-client)
53
-
54
- 1. **[Quick Start](#quick-start)**
55
-
56
- * [Initialize the client](#initialize-the-client)
57
- * [Push data](#push-data)
58
- * [Search](#search)
59
- * [Configure](#configure)
60
- * [Client options](#client-options)
61
- * [Callback convention](#callback-convention)
62
- * [Promises](#promises)
63
- * [Request strategy](#request-strategy)
64
- * [Cache](#cache)
65
- * [Proxy support](#proxy-support)
66
- * [Keep-alive](#keep-alive)
67
- * [Debugging](#debugging)
68
-
69
- 1. **[Getting Help](#getting-help)**
70
-
71
-
72
-
73
-
74
-
75
- # Getting Started
76
-
77
-
78
-
79
- ## Install
80
-
81
- #### Frontend
82
-
83
- You can either use a package manager like npm or include a `<script>` tag.
84
-
85
- #### Node.js / React Native / Browserify / webpack
86
-
87
- We are [browserify](http://browserify.org/)able and [webpack](http://webpack.github.io/) friendly.
88
-
89
- ```sh
90
- npm install algoliasearch --save
91
- ```
92
-
93
- #### TypeScript typings
94
-
95
- For Typescript typings, we provide the definition file via [typings](https://github.com/typings/typings)
96
-
97
- ```sh
98
- npm install --save @types/algoliasearch
99
- ```
100
-
101
- #### NativeScript
102
-
103
- ```sh
104
- tns plugin add nativescript-algolia
105
- ```
106
- #### Bower
107
-
108
- ```sh
109
- bower install algoliasearch -S
110
- ```
111
-
112
- #### &lt;script&gt; tag using CDNs
113
-
114
- ##### Recommended: jsDelivr.com
115
-
116
- [jsDelivr](http://www.jsdelivr.com/about.php) is a global CDN delivery for JavaScript libraries.
117
-
118
- To include the latest releases and all upcoming features and patches, use this:
119
-
120
- ```html
121
- <script src="https://cdn.jsdelivr.net/algoliasearch/3/algoliasearch.min.js"></script>
122
- ```
123
-
124
- ##### Other CDNS
125
-
126
- We recommend using jsDelivr, but `algoliasearch` is also available at:
127
- - [CDNJS](https://cdnjs.com/libraries/algoliasearch)
128
- - [unpkg](https://unpkg.com): https://unpkg.com/algoliasearch@3/dist/algoliasearch.min.js
129
-
130
- #### Search only/lite client
131
-
132
- We have a lightweight build available that can only do searches. Use it when filesize
133
- is important to you or if you like to include only what you need.
134
-
135
- Find it on jsDelivr:
136
-
137
- ```html
138
- <script src="https://cdn.jsdelivr.net/algoliasearch/3/algoliasearchLite.min.js"></script>
139
- ```
140
-
141
- ## Quick Start
142
-
143
- In 30 seconds, this quick start tutorial will show you how to index and search objects.
144
-
145
- ### Initialize the client
146
-
147
- You first need to initialize the client. For that you need your **Application ID** and **API Key**.
148
- You can find both of them on [your Algolia account](https://www.algolia.com/api-keys).
149
-
150
- ```js
151
- // var algoliasearch = require('algoliasearch');
152
- // var algoliasearch = require('algoliasearch/reactnative');
153
- // var algoliasearch = require('algoliasearch/lite');
154
- // or just use algoliasearch if you are using a <script> tag
155
- // if you are using AMD module loader, algoliasearch will not be defined in window,
156
- // but in the AMD modules of the page
157
-
158
- var client = algoliasearch('applicationID', 'apiKey');
159
- ```
160
-
161
- ### Push data
162
-
163
- Without any prior configuration, you can start indexing [500 contacts](https://github.com/algolia/datasets-public/blob/master/contacts/contacts.json) in the `contacts` index using the following code:
164
-
165
- > for this use: [**admin** API key](https://www.algolia.com/doc/guides/security/api-keys/#admin-api-key) in client instantiation
166
-
167
- ```js
168
- var index = client.initIndex('contacts');
169
- var contactsJSON = require('./contacts.json');
170
-
171
- index.addObjects(contactsJSON, function(err, content) {
172
- if (err) {
173
- console.error(err);
174
- }
175
- });
176
- ```
177
-
178
- ### Search
179
-
180
- You can now search for contacts using firstname, lastname, company, etc. (even with typos):
181
-
182
- > for this use: [**search only** API key](https://www.algolia.com/doc/guides/security/api-keys/#search-only-api-key) in client instantiation
183
-
184
- ```js
185
- // firstname
186
- index.search('jimmie', function(err, content) {
187
- console.log(content.hits);
188
- });
189
-
190
- // firstname with typo
191
- index.search('jimie', function(err, content) {
192
- console.log(content.hits);
193
- });
194
-
195
- // a company
196
- index.search('california paint', function(err, content) {
197
- console.log(content.hits);
198
- });
199
-
200
- // a firstname & company
201
- index.search('jimmie paint', function(err, content) {
202
- console.log(content.hits);
203
- });
204
- ```
205
-
206
- ### Configure
207
-
208
- Settings can be customized to tune the search behavior. For example, you can add a custom sort by number of followers to the already great built-in relevance:
209
-
210
- > for this use: [**admin** API key](https://www.algolia.com/doc/guides/security/api-keys/#admin-api-key) in client instantiation
211
-
212
- ```js
213
- index.setSettings({
214
- 'customRanking': ['desc(followers)']
215
- }, function(err, content) {
216
- console.log(content);
217
- });
218
- ```
219
-
220
- You can also configure the list of attributes you want to index by order of importance (first = most important):
221
-
222
- **Note:** Since the engine is designed to suggest results as you type, you'll generally search by prefix.
223
- In this case the order of attributes is very important to decide which hit is the best:
224
-
225
- ```js
226
- index.setSettings({
227
- 'searchableAttributes': [
228
- 'lastname',
229
- 'firstname',
230
- 'company',
231
- 'email',
232
- 'city',
233
- 'address'
234
- ]
235
- }, function(err, content) {
236
- console.log(content);
237
- });
1
+ <p align="center">
2
+ <a href="https://www.algolia.com">
3
+ <img alt="Algolia for JavaScript" src="https://raw.githubusercontent.com/algolia/algoliasearch-client-common/master/banners/javascript.png" >
4
+ </a>
5
+
6
+ <h4 align="center">The perfect starting point to integrate <a href="https://algolia.com" target="_blank">Algolia</a> within your JavaScript project</h4>
7
+
8
+ <p align="center">
9
+ <a href="https://travis-ci.org/algolia/algoliasearch-client-javascript"><img src="https://img.shields.io/travis/algolia/algoliasearch-client-javascript/master.svg" alt="Build Status"></img></a>
10
+ <a href="https://npmjs.org/package/algoliasearch"><img src="https://img.shields.io/npm/v/algoliasearch.svg?style=flat-square" alt="NPM version"></img></a>
11
+ <a href="http://npm-stat.com/charts.html?package=algoliasearch"><img src="https://img.shields.io/npm/dm/algoliasearch.svg?style=flat-square" alt="NPM downloads"></a>
12
+ <a href="https://www.jsdelivr.com/package/npm/algoliasearch"><img src="https://data.jsdelivr.com/v1/package/npm/algoliasearch/badge" alt="jsDelivr Downloads"></img></a>
13
+ <a href="LICENSE.txt"><img src="https://img.shields.io/badge/license-MIT-green.svg?style=flat-square" alt="License"></a>
14
+ </p>
15
+ </p>
16
+
17
+ <p align="center">
18
+ <a href="https://www.algolia.com/doc/api-client/getting-started/install/javascript/" target="_blank">Documentation</a> •
19
+ <a href="https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/" target="_blank">InstantSearch</a> •
20
+ <a href="https://discourse.algolia.com" target="_blank">Community Forum</a> •
21
+ <a href="http://stackoverflow.com/questions/tagged/algolia" target="_blank">Stack Overflow</a> •
22
+ <a href="https://github.com/algolia/algoliasearch-client-javascript/issues" target="_blank">Report a bug</a> •
23
+ <a href="https://www.algolia.com/support" target="_blank">Support</a>
24
+ </p>
25
+
26
+ ## Features
27
+
28
+ - Thin & **minimal low-level HTTP client** to interact with Algolia's API
29
+ - Works both on the **browser** and **node.js**
30
+ - **UMD compatible**, you can use it with any module loader
31
+ - Contains type definitions: **[@types/algoliasearch](https://www.npmjs.com/package/@types/algoliasearch)**
32
+
33
+ ## 💡 Getting Started
34
+
35
+ First, install Algolia JavaScript API Client via the [npm](https://www.npmjs.com/get-npm) package manager:
36
+
37
+ ```bash
38
+ npm install --save algoliasearch
238
39
  ```
239
40
 
240
- ### Client options
241
-
242
- In most situations, there is no need to tune the options. We provide this list to be
243
- transparent with our users.
244
-
245
- - `timeout` (Number) timeout for requests to our servers, in milliseconds
246
- + in Node.js this is an inactivity timeout. Defaults to 15s
247
- + in the browser, this is a global timeout. Defaults to 2s (incremental)
248
- - `protocol` (String) protocol to use when communicating with algolia
249
- + in the browser, we use the page protocol by default
250
- + in Node.js it's https by default
251
- + possible values: 'http:', 'https:'
252
- - `hosts.read` ([String]) array of read hosts to use to call Algolia servers, computed automatically
253
- - `hosts.write` ([String]) array of write hosts to use to call Algolia servers, computed automatically
254
- - `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.
255
- - `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.
256
-
257
- To pass an option, use:
41
+ Then, create objects on your index:
258
42
 
259
43
  ```js
260
- var client = algoliasearch(applicationId, apiKey, {
261
- timeout: 4000
262
- })
263
- ```
264
-
265
- ### Callback convention
266
-
267
- Every API call takes a callback as last parameter. This callback will then be called with two arguments:
268
-
269
- 1. **error**: null or an [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) object. More info on the error can be find in `error.message`.
270
- 2. **content**: the object containing the answer from the server, it's a JavaScript object
271
-
272
- ### Promises
273
-
274
- **If you do not provide a callback**, you will get a promise (but never both).
275
-
276
- Promises are the [native Promise implementation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise).
277
-
278
- We use [jakearchibald/es6-promise](https://github.com/stefanpenner/es6-promise) as a polyfill when needed.
279
-
280
- ### Request strategy
281
-
282
- The request strategy used by the JavaScript client includes:
283
-
284
- - On the browser:
285
- + [CORS](https://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing#Browser_support) for modern browsers
286
- + [XDomainRequest](https://msdn.microsoft.com/en-us/library/ie/cc288060%28v=vs.85%29.aspx) for IE <= 10
287
- + [JSONP](https://en.wikipedia.org/wiki/JSONP) in any situation where Ajax requests are unavailable or blocked.
288
- - Node.js:
289
- + native [`http` module](https://nodejs.org/api/)
290
-
291
- Connections are always `keep-alive`.
292
-
293
- ### Cache
294
-
295
- **Browser only**
296
-
297
- To avoid performing the same API calls twice **search** results will be stored
298
- in a `cache` that will be tied to your JavaScript `client` and `index` objects.
299
- Whenever a call for a specific query (and filters) is made, we store the results
300
- in a local cache. If you ever call the exact same query again, we read the
301
- results from the cache instead of doing an API call.
302
-
303
- This is particularly useful when your users are deleting characters from their
304
- current query, to avoid useless API calls. Because it is stored as a simple
305
- JavaScript object in memory, the cache is automatically reset whenever you
306
- reload the page.
307
-
308
- It is never automatically purged, nor can it be completely disabled. Instead, we
309
- provide the `index.clearCache()` (or `client.clearCache()` if you're using the
310
- [Search multiple indices](#search-multiple-indices) method that you can call to reset it.
311
-
312
- ### Proxy support
313
-
314
- **Node.js only**
315
-
316
- If you are behind a proxy, just set `HTTP_PROXY` or `HTTPS_PROXY` environment variables before starting your Node.js program.
317
-
318
- ```sh
319
- HTTP_PROXY=http://someproxy.com:9320 node main.js
44
+ const algoliasearch = require('algoliasearch');
45
+
46
+ const client = algoliasearch('YourApplicationID', 'YourAdminAPIKey');
47
+ const index = client.initIndex('your_index_name');
48
+
49
+ const objects = [{
50
+ objectID: 1,
51
+ name: 'Foo'
52
+ }];
53
+
54
+ index
55
+ .saveObjects(objects)
56
+ .then(({ objectIDs }) => {
57
+ console.log(objectIDs);
58
+ })
59
+ .catch(err => {
60
+ console.log(err);
61
+ });
320
62
  ```
321
63
 
322
- ### Keep-alive
323
-
324
- **Node.js only**
325
-
326
- Keep-alive is activated by default.
327
-
328
- Because of the nature of keepalive connections, your process will hang even if you do not do any more command using the `client`.
329
-
330
- To fix this, we expose a `client.destroy()` method that will terminate all remaining alive connections.
331
-
332
- You should call this method when you are finished working with the AlgoliaSearch API. So that your process will exit gently.
333
-
334
- **Note: keep-alive is still always activated in browsers, this is a native behavior of browsers.**
335
-
336
- ### Debugging
337
-
338
- The client will send you errors when a method call fails for some reasons.
339
-
340
- You can get detailed debugging information:
64
+ Finally, let's actually search using the `search` method:
341
65
 
342
66
  ```js
343
- index.search('something', function searchDone(err) {
344
- if (err) {
345
- console.log(err.message);
346
- console.log(err.debugData);
347
- return;
348
- }
349
- });
67
+ index
68
+ .search('Fo')
69
+ .then(({ hits }) => {
70
+ console.log(hits);
71
+ })
72
+ .catch(err => {
73
+ console.log(err);
74
+ });
350
75
  ```
351
76
 
352
- `err.debugData` contains the array of requests parameters that were used to issue requests.
353
-
354
- ## Getting Help
355
-
356
- - **Need help**? Ask a question to the [Algolia Community](https://discourse.algolia.com/) or on [Stack Overflow](http://stackoverflow.com/questions/tagged/algolia).
357
- - **Found a bug?** You can open a [GitHub issue](https://github.com/algolia/algoliasearch-client-javascript/issues).
358
-
77
+ For full documentation, visit the **[online documentation](https://www.algolia.com/doc/api-client/getting-started/install/javascript/)**.
359
78
 
79
+ ## 📄 License
360
80
 
81
+ Algolia JavaScript API Client is an open-sourced software licensed under the [MIT license](LICENSE.txt).
package/bower.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "algoliasearch",
3
- "version": "3.32.1",
3
+ "version": "3.35.1",
4
4
  "homepage": "https://github.com/algolia/algoliasearch-client-js",
5
5
  "authors": [
6
6
  "Algolia Team <support@algolia.com>"