Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

algoliasearch

Package Overview
Dependencies
Maintainers
3
Versions
389
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

algoliasearch - npm Package Compare versions

Comparing version 3.0.3 to 3.0.4

src/version/browser.js

2

bower.json
{
"name": "algoliasearch",
"version": "3.0.3",
"version": "3.0.4",
"homepage": "https://github.com/algolia/algoliasearch-client-js",

@@ -5,0 +5,0 @@ "authors": [

var algoliasearch = require('./');
// var AlgoliaSearch = require('algolia-search');
var client = algoliasearch('latency', '6be0576ff61c053d5f9a3225e2a90f76');
// var client = new AlgoliaSearch('latency', '6be0576ff61c053d5f9a3225e2a90f76');
var index = client.initIndex('contacts');
index.search('som', console.log);
index.search('som').then(function(content) {
console.log(content);
});
{
"name": "algoliasearch",
"version": "3.0.3",
"version": "3.0.4",
"description": "AlgoliaSearch API JavaScript client",
"main": "index.js",
"browser": "src/browser/builds/algoliasearch.js",
"browser": {
"index.js": "src/browser/builds/algoliasearch.js",
"src/version/index.js": "src/version/browser.js"
},
"scripts": {
"build": "PACKAGE_VERSION=$(json -f package.json version) sh build.sh",
"test": "zuul --phantom --ui tape test/run.js | tap-growl | tap-spec && npm run lint",
"test-ci": "DEBUG=zuul* zuul --tunnel ngrok test/run.js && npm run lint",
"dev": "DEBUG=zuul* zuul --no-coverage --local 8080 --ui tape test/run.js",
"test": "npm run test-phantom | tap-spec && npm run test-node | tap-spec && npm run lint",
"test-node": "node test/run-node.js",
"test-phantom": "zuul --phantom -- test/run-browser.js",
"test-ci-browser": "DEBUG=zuul* zuul --tunnel ngrok -- test/run-browser.js",
"dev": "NODE_ENV=development DEBUG=zuul* zuul --no-coverage --local 8080 -- test/run-browser.js",
"examples": "http-server . -a 0.0.0.0",

@@ -17,2 +22,3 @@ "lint": "eslint --quiet test/"

"transform": [
"envify",
"packageify"

@@ -46,8 +52,15 @@ ]

"dependencies": {
"agentkeepalive": "0.2.4",
"debug": "2.1.3",
"envify": "3.4.0",
"es6-promise": "2.0.1",
"inherits": "2.0.1",
"load-script": "1.0.0",
"packageify": "0.2.2"
"once": "1.3.1",
"packageify": "0.2.2",
"semver": "4.3.2"
},
"devDependencies": {
"angular": "1.3.14",
"async": "0.9.0",
"bowser": "0.7.2",

@@ -61,7 +74,7 @@ "browserify": "9.0.3",

"compression": "1.4.3",
"deumdify": "1.1.0",
"domready": "0.3.0",
"envify": "3.4.0",
"eslint": "0.15.0",
"express": "4.12.1",
"faux-jax": "3.0.1",
"faux-jax": "4.0.0-beta.1",
"http-server": "0.7.5",

@@ -75,4 +88,4 @@ "jQuery-ajaxTransport-XDomainRequest": "git://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest#1.0.4",

"phantomjs": "1.9.15",
"pretty-bytes": "1.0.4",
"sinon": "1.12.2",
"tap-growl": "1.0.5",
"tap-spec": "2.2.1",

@@ -79,0 +92,0 @@ "tape": "3.5.0",

@@ -85,3 +85,3 @@ # Algolia Search API Client for JavaScript

```sh
bower install algoliasearch
bower install algoliasearch -S
```

@@ -207,5 +207,5 @@

Then open either:
- http://127.0.0.1:8081/examples/ to see a list of examples
- http://127.0.0.1:8081/examples/autocomplete.html
- http://127.0.0.1:8081/examples/instantsearch.html
- http://127.0.0.1:8080/examples/ to see a list of examples
- http://127.0.0.1:8080/examples/autocomplete.html
- http://127.0.0.1:8080/examples/instantsearch.html

@@ -212,0 +212,0 @@ To hack and use your own indexes and data, open one of the example file and replace:

module.exports = AlgoliaSearch;
// default debug activated in dev environments
// this is triggered in package.json, using the envify transform
if (process.env.NODE_ENV === 'development') {
require('debug').enable('algoliasearch*');
}
var debug = require('debug')('algoliasearch:AlgoliaSearch');
/*

@@ -20,3 +28,3 @@ * Algolia Search library initialization

*/
function AlgoliaSearch(applicationID, apiKey, opts, _request) {
function AlgoliaSearch(applicationID, apiKey, opts) {
var usage = 'Usage: algoliasearch(applicationID, apiKey, opts)';

@@ -41,3 +49,5 @@

if (opts.protocol === undefined) {
opts.protocol = document && document.location.protocol || 'http:';
var locationProtocol = global.document && global.document.location.protocol;
// our API is only available with http or https. When in file:// mode (local html file), default to http
opts.protocol = (locationProtocol === 'http:' || locationProtocol === 'https:') ? locationProtocol : 'http:';
}

@@ -83,3 +93,2 @@

this.cache = {};
this._request = _request;
}

@@ -440,9 +449,9 @@

if (cache && cache[cacheID] !== undefined) {
return client._request.resolve(cache[cacheID]);
return client._promise.resolve(cache[cacheID]);
}
if (tries >= client.hosts.length) {
if (!opts.fallback || requester === client._request.fallback) {
if (!opts.fallback || !client._request.fallback || requester === client._request.fallback) {
// could not get a response even using the fallback if one was available
return client._request.reject(new Error(
return client._promise.reject(new Error(
'Cannot connect to the AlgoliaSearch API.' +

@@ -459,3 +468,3 @@ ' Send an email to support@algolia.com to report and resolve the issue.'

client.currentHostIndex = 0;
client.forceFallback = true;
client.forceFallback = true; // now we will only use JSONP, even on future requests
return doRequest(client._request.fallback, reqOpts);

@@ -529,3 +538,3 @@ }

return client._request.reject(unrecoverableError);
return client._promise.reject(unrecoverableError);
}, tryFallback);

@@ -540,6 +549,20 @@

function tryFallback() {
function tryFallback(err) {
// error cases:
// While not in fallback mode:
// - CORS not supported
// - network error
// While in fallback mode:
// - timeout
// - network error
// - badly formatted JSONP (script loaded, did not call our callback)
// In both cases:
// - uncaught exception occurs (TypeError)
debug('error: %s, stack: %s', err.message, err.stack);
// we were not using the fallback, try now
// if we are switching to fallback right now, set tries to maximum
if (!client.forceFallback) {
// next time doRequest is called, simulate we tried all hosts
// next time doRequest is called, simulate we tried all hosts,
// this will force to use the fallback
tries = client.hosts.length;

@@ -561,2 +584,3 @@ } else {

var promise = doRequest(
// set the requester
useFallback ? client._request.fallback : client._request, {

@@ -793,3 +817,3 @@ url: requestOptions.url,

return this.as._request.reject(err);
return this.as._promise.reject(err);
}

@@ -966,3 +990,3 @@

if (content.status !== 'published') {
return new indexObj.as._request.delay(100).then(function() {
return new indexObj.as._promise.delay(100).then(function() {
return indexObj.waitTask(taskID, callback);

@@ -969,0 +993,0 @@ });

@@ -1,2 +0,7 @@

var createAlgoliasearch = require('../../create-algoliasearch');
// This is the AngularJS Algolia Search module
// It's using $http to do requests with a JSONP fallback
// $q promises are returned
var inherits = require('inherits');
var AlgoliaSearch = require('../../AlgoliaSearch');
var JSONPRequest = require('../jsonp-request');

@@ -6,3 +11,17 @@

.service('algolia', ['$http', '$q', '$timeout', function ($http, $q, $timeout) {
function request(url, opts) {
function algoliasearch(applicationID, apiKey, opts) {
return new AlgoliaSearchAngular(applicationID, apiKey, opts);
}
algoliasearch.version = require('../../version/');
function AlgoliaSearchAngular() {
// call AlgoliaSearch constructor
AlgoliaSearch.apply(this, arguments);
}
inherits(AlgoliaSearchAngular, AlgoliaSearch);
AlgoliaSearchAngular.prototype._request = function(url, opts) {
return $q(function(resolve, reject) {

@@ -53,5 +72,5 @@ var timedOut;

});
}
};
request.fallback = function(url, opts) {
AlgoliaSearchAngular.prototype._request.fallback = function(url, opts) {
return $q(function(resolve, reject) {

@@ -69,18 +88,17 @@ JSONPRequest(url, opts, function JSONPRequestDone(err, content) {

request.reject = function(val) {
return $q.reject(val);
AlgoliaSearchAngular.prototype._promise = {
reject: function(val) {
return $q.reject(val);
},
resolve: function(val) {
// http://www.bennadel.com/blog/2735-q-when-is-the-missing-q-resolve-method-in-angularjs.htm
return $q.when(val);
},
delay: function(ms) {
return $q(function(resolve/*, reject*/) {
$timeout(resolve, ms);
});
}
};
request.resolve = function(val) {
// http://www.bennadel.com/blog/2735-q-when-is-the-missing-q-resolve-method-in-angularjs.htm
return $q.when(val);
};
request.delay = function(ms) {
return $q(function(resolve/*, reject*/) {
$timeout(resolve, ms);
});
};
var algoliasearch = createAlgoliasearch(request);
return {

@@ -87,0 +105,0 @@ Client: function(applicationID, apiKey, options) {

@@ -1,5 +0,15 @@

var createAlgoliasearch = require('../../create-algoliasearch');
// This is the jQuery Algolia Search module
// It's using $.ajax to do requests with a JSONP fallback
// jQuery promises are returned
var inherits = require('inherits');
var AlgoliaSearch = require('../../AlgoliaSearch');
var JSONPRequest = require('../jsonp-request');
var algoliasearch = createAlgoliasearch(request);
function algoliasearch(applicationID, apiKey, opts) {
return new AlgoliaSearchJQuery(applicationID, apiKey, opts);
}
algoliasearch.version = require('../../version/');
var $ = global.jQuery;

@@ -9,3 +19,10 @@

function request(url, opts) {
function AlgoliaSearchJQuery() {
// call AlgoliaSearch constructor
AlgoliaSearch.apply(this, arguments);
}
inherits(AlgoliaSearchJQuery, AlgoliaSearch);
AlgoliaSearchJQuery.prototype._request = function(url, opts) {
return $.Deferred(function(deferred) {

@@ -41,5 +58,5 @@ var body = null;

}).promise();
}
};
request.fallback = function(url, opts) {
AlgoliaSearchJQuery.prototype._request.fallback = function(url, opts) {
return $.Deferred(function(deferred) {

@@ -57,20 +74,20 @@ JSONPRequest(url, opts, function JSONPRequestDone(err, content) {

request.reject = function(val) {
return $.Deferred(function(deferred) {
deferred.reject(val);
}).promise();
AlgoliaSearchJQuery.prototype._promise = {
reject: function(val) {
return $.Deferred(function(deferred) {
deferred.reject(val);
}).promise();
},
resolve: function(val) {
return $.Deferred(function(deferred) {
deferred.resolve(val);
}).promise();
},
delay: function(ms) {
return $.Deferred(function(deferred) {
setTimeout(function() {
deferred.resolve();
}, ms);
}).promise();
}
};
request.resolve = function(val) {
return $.Deferred(function(deferred) {
deferred.resolve(val);
}).promise();
};
request.delay = function(ms) {
return $.Deferred(function(deferred) {
setTimeout(function() {
deferred.resolve();
}, ms);
}).promise();
};

@@ -1,10 +0,18 @@

// this is the standalone build entry of AlgoliaSearch
var createAlgoliasearch = require('../../create-algoliasearch');
// This is the standalone browser build entry point
// Browser implementation of the Algolia Search JavaScript client,
// using XMLHttpRequest, XDomainRequest and JSONP as fallback
module.exports = algoliasearch;
module.exports = createAlgoliasearch(request);
var inherits = require('inherits');
var Promise = global.Promise || require('es6-promise').Promise;
var AlgoliaSearch = require('../../AlgoliaSearch');
var JSONPRequest = require('../jsonp-request');
function algoliasearch(applicationID, apiKey, opts) {
return new AlgoliaSearchBrowser(applicationID, apiKey, opts);
}
algoliasearch.version = require('../../version/');
var support = {

@@ -17,3 +25,10 @@ hasXMLHttpRequest: 'XMLHttpRequest' in window,

function request(url, opts) {
function AlgoliaSearchBrowser() {
// call AlgoliaSearch constructor
AlgoliaSearch.apply(this, arguments);
}
inherits(AlgoliaSearchBrowser, AlgoliaSearch);
AlgoliaSearchBrowser.prototype._request = function(url, opts) {
return new Promise(function(resolve, reject) {

@@ -44,6 +59,13 @@ // no cors or XDomainRequest, no request

if (support.cors && body && opts.method !== 'GET') {
req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
if (support.cors && body !== null && opts.method !== 'GET') {
req.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
}
// we set an empty onprogress listener
// so that XDomainRequest on IE9 is not aborted
// refs:
// - https://github.com/algolia/algoliasearch-client-js/issues/76
// - https://social.msdn.microsoft.com/Forums/ie/en-US/30ef3add-767c-4436-b8a9-f1ca19b4812e/ie9-rtm-xdomainrequest-issued-requests-may-abort-if-all-event-handlers-not-specified?forum=iewebdevelopment
req.onprogress = function noop() {};
req.onload = load;

@@ -114,5 +136,5 @@ req.onerror = error;

});
}
};
request.fallback = function(url, opts) {
AlgoliaSearchBrowser.prototype._request.fallback = function(url, opts) {
return new Promise(function(resolve, reject) {

@@ -130,14 +152,14 @@ JSONPRequest(url, opts, function JSONPRequestDone(err, content) {

request.reject = function(val) {
return Promise.reject(val);
AlgoliaSearchBrowser.prototype._promise = {
reject: function(val) {
return Promise.reject(val);
},
resolve: function(val) {
return Promise.resolve(val);
},
delay: function(ms) {
return new Promise(function(resolve/*, reject*/) {
setTimeout(resolve, ms);
});
}
};
request.resolve = function(val) {
return Promise.resolve(val);
};
request.delay = function(ms) {
return new Promise(function(resolve/*, reject*/) {
setTimeout(resolve, ms);
});
};

@@ -1,1 +0,133 @@

module.exports = {};
// This is the Node.JS entry point
module.exports = algoliasearch;
var debug = require('debug')('algoliasearch:nodejs');
var https = require('https');
var HttpsAgent = require('agentkeepalive').HttpsAgent;
var inherits = require('inherits');
var once = require('once');
var Promise = global.Promise || require('es6-promise').Promise;
var semver = require('semver');
var url = require('url');
var AlgoliaSearch = require('../../AlgoliaSearch');
// does not work on node < 0.8
if (semver.satisfies(process.version, '<=0.7')) {
throw new Error('Node.js version ' + process.version + ' not supported');
}
var keepAliveAgent;
// node > 0.11.4 has good keepAlive https://github.com/joyent/node/commit/b5b841
if (semver.satisfies(process.version, '<0.11.4')) {
keepAliveAgent = new HttpsAgent();
} else {
// Node.js >= 0.12, io.js >= 1.0.0 have good keepalive support
keepAliveAgent = https.Agent({
keepAlive: true
});
}
function algoliasearch(applicationID, apiKey, opts) {
return new AlgoliaSearchNodeJS(applicationID, apiKey, opts);
}
algoliasearch.version = require('../../version/');
function AlgoliaSearchNodeJS() {
// call AlgoliaSearch constructor
AlgoliaSearch.apply(this, arguments);
}
inherits(AlgoliaSearchNodeJS, AlgoliaSearch);
// node 0.10 => agentkeepalive
// node 0.12 => native keepalive
// iojs => native keepalive
AlgoliaSearchNodeJS.prototype._request = function(rawUrl, opts) {
return new Promise(function doReq(resolve, reject) {
reject = once(reject);
debug('url: %s, opts: %j', rawUrl, opts);
var parsedUrl = url.parse(rawUrl);
var requestOptions = {
hostname: parsedUrl.hostname,
port: parsedUrl.port,
method: opts.method,
path: parsedUrl.path,
agent: keepAliveAgent/*,
// ??
// https://github.com/iojs/io.js/issues/1300
keepAlive: true*/
};
debug('requestOptions: %j', requestOptions);
var req = https.request(requestOptions);
req.setHeader('connection', 'keep-alive');
// socket inactivity timeout
// this is not a global timeout on the request
// BUG: This will hang the program on node < 0.11
// - https://github.com/node-modules/agentkeepalive/issues/17
req.setTimeout(opts.timeout);
req.once('error', error);
req.once('timeout', timeout);
req.once('response', response);
if (opts.body !== undefined) {
req.setHeader('content-type', 'application/json');
req.write(JSON.stringify(opts.body));
}
req.end();
function response(res) {
var chunks = [];
res.on('data', data);
res.once('end', end);
function data(chunk) {
chunks.push(chunk);
}
function end() {
resolve({
statusCode: res.statusCode,
body: JSON.parse(Buffer.concat(chunks))
});
}
}
function error(err) {
debug('Error: %j - %s %j', err, rawUrl, opts);
reject(err);
}
function timeout() {
debug('Timeout %s %j', rawUrl, opts);
req.abort();
reject(new Error('Timeout'));
}
});
};
AlgoliaSearchNodeJS.prototype._promise = {
reject: function(val) {
return Promise.reject(val);
},
resolve: function(val) {
return Promise.resolve(val);
},
delay: function(ms) {
return new Promise(function(resolve/*, reject*/) {
setTimeout(resolve, ms);
});
}
};

@@ -24,8 +24,14 @@ module.exports = computeExpectedRequest;

if (expectedRequest.body !== undefined && !expectedRequest.headers['Content-type']) {
expectedRequest.headers = {
'Content-type': 'application/x-www-form-urlencoded'
};
if (expectedRequest.body === undefined) {
expectedRequest.body = null;
}
if (expectedRequest.body !== null && expectedRequest.method === 'POST' || expectedRequest.method === 'PUT') {
if (process.browser) {
expectedRequest.headers['content-type'] = 'application/x-www-form-urlencoded';
} else {
expectedRequest.headers['content-type'] = 'application/json';
}
}
return expectedRequest;

@@ -36,3 +42,3 @@ }

return {
protocol: document.location.protocol,
protocol: process.browser ? document.location.protocol : 'http:',
host: credentials.applicationID + '-dsn.algolia.net',

@@ -39,0 +45,0 @@ URL: {pathname: '/not-set'},

@@ -11,3 +11,3 @@ module.exports = runTestCase;

var getFakeHitsResponse = require('./get-fake-hits-response');
var testXHRCall = require('./test-xhr-call');
var testMethodCall = require('./test-method-call');

@@ -30,3 +30,3 @@ function runTestCase(testCase) {

t.plan(testXHRCall.assertCount/* + addSubTest*/);
t.plan(testMethodCall.assertCount/* + addSubTest*/);

@@ -46,3 +46,3 @@ // every test case gets it's own credentials

testXHRCall({
testMethodCall({
testCase: testCase,

@@ -49,0 +49,0 @@ methodName: testCase.methodName,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc