aboutsummaryrefslogtreecommitdiff
path: root/node_modules/algoliasearch/src/browser
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/algoliasearch/src/browser')
-rw-r--r--node_modules/algoliasearch/src/browser/builds/algoliasearch.angular.js201
-rw-r--r--node_modules/algoliasearch/src/browser/builds/algoliasearch.jquery.js147
-rw-r--r--node_modules/algoliasearch/src/browser/builds/algoliasearch.js6
-rw-r--r--node_modules/algoliasearch/src/browser/builds/algoliasearchLite.js6
-rw-r--r--node_modules/algoliasearch/src/browser/createAlgoliasearch.js233
-rw-r--r--node_modules/algoliasearch/src/browser/inline-headers.js15
-rw-r--r--node_modules/algoliasearch/src/browser/jsonp-request.js126
-rw-r--r--node_modules/algoliasearch/src/browser/migration-layer/is-using-latest.js23
-rw-r--r--node_modules/algoliasearch/src/browser/migration-layer/load-v2.js50
-rw-r--r--node_modules/algoliasearch/src/browser/migration-layer/old-globals.js26
-rw-r--r--node_modules/algoliasearch/src/browser/migration-layer/script.js25
11 files changed, 858 insertions, 0 deletions
diff --git a/node_modules/algoliasearch/src/browser/builds/algoliasearch.angular.js b/node_modules/algoliasearch/src/browser/builds/algoliasearch.angular.js
new file mode 100644
index 00000000..c1db3343
--- /dev/null
+++ b/node_modules/algoliasearch/src/browser/builds/algoliasearch.angular.js
@@ -0,0 +1,201 @@
+'use strict';
+
+// 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 forEach = require('foreach');
+
+var AlgoliaSearch = require('../../AlgoliaSearch');
+var errors = require('../../errors');
+var inlineHeaders = require('../inline-headers');
+var jsonpRequest = require('../jsonp-request');
+var places = require('../../places.js');
+
+// expose original algoliasearch fn in window
+window.algoliasearch = require('./algoliasearch');
+
+if (process.env.NODE_ENV === 'debug') {
+ require('debug').enable('algoliasearch*');
+}
+
+window.angular.module('algoliasearch', [])
+ .service('algolia', ['$http', '$q', '$timeout', function algoliaSearchService($http, $q, $timeout) {
+ function algoliasearch(applicationID, apiKey, opts) {
+ var cloneDeep = require('../../clone.js');
+
+ opts = cloneDeep(opts || {});
+
+ opts._ua = opts._ua || algoliasearch.ua;
+
+ return new AlgoliaSearchAngular(applicationID, apiKey, opts);
+ }
+
+ algoliasearch.version = require('../../version.js');
+ algoliasearch.ua = 'Algolia for AngularJS ' + algoliasearch.version;
+ algoliasearch.initPlaces = places(algoliasearch);
+
+ // we expose into window no matter how we are used, this will allow
+ // us to easily debug any website running algolia
+ window.__algolia = {
+ debug: require('debug'),
+ algoliasearch: algoliasearch
+ };
+
+ function AlgoliaSearchAngular() {
+ // call AlgoliaSearch constructor
+ AlgoliaSearch.apply(this, arguments);
+ }
+
+ inherits(AlgoliaSearchAngular, AlgoliaSearch);
+
+ AlgoliaSearchAngular.prototype._request = function request(url, opts) {
+ // Support most Angular.js versions by using $q.defer() instead
+ // of the new $q() constructor everywhere we need a promise
+ var deferred = $q.defer();
+ var resolve = deferred.resolve;
+ var reject = deferred.reject;
+
+ var timedOut;
+ var body = opts.body;
+
+ url = inlineHeaders(url, opts.headers);
+
+ var timeoutDeferred = $q.defer();
+ var timeoutPromise = timeoutDeferred.promise;
+
+ $timeout(function timedout() {
+ timedOut = true;
+ // will cancel the xhr
+ timeoutDeferred.resolve('test');
+ reject(new errors.RequestTimeout());
+ }, opts.timeouts.complete);
+
+ var requestHeaders = {};
+
+ // "remove" (set to undefined) possible globally set headers
+ // in $httpProvider.defaults.headers.common
+ // otherwise we might fail sometimes
+ // ref: https://github.com/algolia/algoliasearch-client-js/issues/135
+ forEach(
+ $http.defaults.headers.common,
+ function removeIt(headerValue, headerName) {
+ requestHeaders[headerName] = undefined;
+ }
+ );
+
+ requestHeaders.accept = 'application/json';
+
+ if (body) {
+ if (opts.method === 'POST') {
+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Simple_requests
+ requestHeaders['content-type'] = 'application/x-www-form-urlencoded';
+ } else {
+ requestHeaders['content-type'] = 'application/json';
+ }
+ }
+
+ $http({
+ url: url,
+ method: opts.method,
+ data: body,
+ cache: false,
+ timeout: timeoutPromise,
+ headers: requestHeaders,
+ transformResponse: transformResponse,
+ // if client uses $httpProvider.defaults.withCredentials = true,
+ // we revert it to false to avoid CORS failure
+ withCredentials: false
+ }).then(success, error);
+
+ function success(response) {
+ resolve({
+ statusCode: response.status,
+ headers: response.headers,
+ body: JSON.parse(response.data),
+ responseText: response.data
+ });
+ }
+
+ // we force getting the raw data because we need it so
+ // for cache keys
+ function transformResponse(data) {
+ return data;
+ }
+
+ function error(response) {
+ if (timedOut) {
+ return;
+ }
+
+ // network error
+ if (response.status === 0) {
+ reject(
+ new errors.Network({
+ more: response
+ })
+ );
+ return;
+ }
+
+ resolve({
+ body: JSON.parse(response.data),
+ statusCode: response.status
+ });
+ }
+
+ return deferred.promise;
+ };
+
+ // using IE8 or IE9 we will always end up here
+ // AngularJS does not fallback to XDomainRequest
+ AlgoliaSearchAngular.prototype._request.fallback = function requestFallback(url, opts) {
+ url = inlineHeaders(url, opts.headers);
+
+ var deferred = $q.defer();
+ var resolve = deferred.resolve;
+ var reject = deferred.reject;
+
+ jsonpRequest(url, opts, function jsonpRequestDone(err, content) {
+ if (err) {
+ reject(err);
+ return;
+ }
+
+ resolve(content);
+ });
+
+ return deferred.promise;
+ };
+
+ 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) {
+ var deferred = $q.defer();
+ var resolve = deferred.resolve;
+
+ $timeout(resolve, ms);
+
+ return deferred.promise;
+ },
+ all: function(promises) {
+ return $q.all(promises);
+ }
+ };
+
+ return {
+ Client: function(applicationID, apiKey, options) {
+ return algoliasearch(applicationID, apiKey, options);
+ },
+ ua: algoliasearch.ua,
+ version: algoliasearch.version
+ };
+ }]);
diff --git a/node_modules/algoliasearch/src/browser/builds/algoliasearch.jquery.js b/node_modules/algoliasearch/src/browser/builds/algoliasearch.jquery.js
new file mode 100644
index 00000000..3b8bebb9
--- /dev/null
+++ b/node_modules/algoliasearch/src/browser/builds/algoliasearch.jquery.js
@@ -0,0 +1,147 @@
+'use strict';
+
+// 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 errors = require('../../errors');
+var inlineHeaders = require('../inline-headers');
+var jsonpRequest = require('../jsonp-request');
+var places = require('../../places.js');
+
+// expose original algoliasearch fn in window
+window.algoliasearch = require('./algoliasearch');
+
+if (process.env.NODE_ENV === 'debug') {
+ require('debug').enable('algoliasearch*');
+}
+
+function algoliasearch(applicationID, apiKey, opts) {
+ var cloneDeep = require('../../clone.js');
+
+ opts = cloneDeep(opts || {});
+
+ opts._ua = opts._ua || algoliasearch.ua;
+
+ return new AlgoliaSearchJQuery(applicationID, apiKey, opts);
+}
+
+algoliasearch.version = require('../../version.js');
+algoliasearch.ua = 'Algolia for jQuery ' + algoliasearch.version;
+algoliasearch.initPlaces = places(algoliasearch);
+
+// we expose into window no matter how we are used, this will allow
+// us to easily debug any website running algolia
+window.__algolia = {
+ debug: require('debug'),
+ algoliasearch: algoliasearch
+};
+
+var $ = window.jQuery;
+
+$.algolia = {
+ Client: algoliasearch,
+ ua: algoliasearch.ua,
+ version: algoliasearch.version
+};
+
+function AlgoliaSearchJQuery() {
+ // call AlgoliaSearch constructor
+ AlgoliaSearch.apply(this, arguments);
+}
+
+inherits(AlgoliaSearchJQuery, AlgoliaSearch);
+
+AlgoliaSearchJQuery.prototype._request = function request(url, opts) {
+ return new $.Deferred(function(deferred) {
+ var body = opts.body;
+
+ url = inlineHeaders(url, opts.headers);
+
+ var requestHeaders = {
+ accept: 'application/json'
+ };
+
+ if (body) {
+ if (opts.method === 'POST') {
+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Simple_requests
+ requestHeaders['content-type'] = 'application/x-www-form-urlencoded';
+ } else {
+ requestHeaders['content-type'] = 'application/json';
+ }
+ }
+
+ $.ajax(url, {
+ type: opts.method,
+ timeout: opts.timeouts.complete,
+ dataType: 'json',
+ data: body,
+ headers: requestHeaders,
+ complete: function onComplete(jqXHR, textStatus/* , error*/) {
+ if (textStatus === 'timeout') {
+ deferred.reject(new errors.RequestTimeout());
+ return;
+ }
+
+ if (jqXHR.status === 0) {
+ deferred.reject(
+ new errors.Network({
+ more: jqXHR
+ })
+ );
+ return;
+ }
+
+ deferred.resolve({
+ statusCode: jqXHR.status,
+ body: jqXHR.responseJSON,
+ responseText: jqXHR.responseText,
+ headers: jqXHR.getAllResponseHeaders()
+ });
+ }
+ });
+ }).promise();
+};
+
+// using IE8 or IE9 we will always end up here
+// jQuery does not not fallback to XDomainRequest
+AlgoliaSearchJQuery.prototype._request.fallback = function requestFallback(url, opts) {
+ url = inlineHeaders(url, opts.headers);
+
+ return new $.Deferred(function wrapJsonpRequest(deferred) {
+ jsonpRequest(url, opts, function jsonpRequestDone(err, content) {
+ if (err) {
+ deferred.reject(err);
+ return;
+ }
+
+ deferred.resolve(content);
+ });
+ }).promise();
+};
+
+AlgoliaSearchJQuery.prototype._promise = {
+ reject: function reject(val) {
+ return new $.Deferred(function rejectDeferred(deferred) {
+ deferred.reject(val);
+ }).promise();
+ },
+ resolve: function resolve(val) {
+ return new $.Deferred(function resolveDeferred(deferred) {
+ deferred.resolve(val);
+ }).promise();
+ },
+ delay: function delay(ms) {
+ return new $.Deferred(function delayResolve(deferred) {
+ setTimeout(function resolveDeferred() {
+ deferred.resolve();
+ }, ms);
+ }).promise();
+ },
+ all: function all(promises) {
+ return $.when.apply(null, promises);
+ }
+};
diff --git a/node_modules/algoliasearch/src/browser/builds/algoliasearch.js b/node_modules/algoliasearch/src/browser/builds/algoliasearch.js
new file mode 100644
index 00000000..e8b820db
--- /dev/null
+++ b/node_modules/algoliasearch/src/browser/builds/algoliasearch.js
@@ -0,0 +1,6 @@
+'use strict';
+
+var AlgoliaSearch = require('../../AlgoliaSearch.js');
+var createAlgoliasearch = require('../createAlgoliasearch.js');
+
+module.exports = createAlgoliasearch(AlgoliaSearch);
diff --git a/node_modules/algoliasearch/src/browser/builds/algoliasearchLite.js b/node_modules/algoliasearch/src/browser/builds/algoliasearchLite.js
new file mode 100644
index 00000000..ca0b4b13
--- /dev/null
+++ b/node_modules/algoliasearch/src/browser/builds/algoliasearchLite.js
@@ -0,0 +1,6 @@
+'use strict';
+
+var AlgoliaSearchCore = require('../../AlgoliaSearchCore.js');
+var createAlgoliasearch = require('../createAlgoliasearch.js');
+
+module.exports = createAlgoliasearch(AlgoliaSearchCore, '(lite) ');
diff --git a/node_modules/algoliasearch/src/browser/createAlgoliasearch.js b/node_modules/algoliasearch/src/browser/createAlgoliasearch.js
new file mode 100644
index 00000000..a2a488b8
--- /dev/null
+++ b/node_modules/algoliasearch/src/browser/createAlgoliasearch.js
@@ -0,0 +1,233 @@
+'use strict';
+
+var global = require('global');
+var Promise = global.Promise || require('es6-promise').Promise;
+
+// 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 = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
+ var inherits = require('inherits');
+ var errors = require('../errors');
+ var inlineHeaders = require('./inline-headers');
+ var jsonpRequest = require('./jsonp-request');
+ var places = require('../places.js');
+ uaSuffix = uaSuffix || '';
+
+ if (process.env.NODE_ENV === 'debug') {
+ require('debug').enable('algoliasearch*');
+ }
+
+ function algoliasearch(applicationID, apiKey, opts) {
+ var cloneDeep = require('../clone.js');
+
+ opts = cloneDeep(opts || {});
+
+ opts._ua = opts._ua || algoliasearch.ua;
+
+ return new AlgoliaSearchBrowser(applicationID, apiKey, opts);
+ }
+
+ algoliasearch.version = require('../version.js');
+ algoliasearch.ua = 'Algolia for vanilla JavaScript ' + uaSuffix + algoliasearch.version;
+ algoliasearch.initPlaces = places(algoliasearch);
+
+ // we expose into window no matter how we are used, this will allow
+ // us to easily debug any website running algolia
+ global.__algolia = {
+ debug: require('debug'),
+ algoliasearch: algoliasearch
+ };
+
+ var support = {
+ hasXMLHttpRequest: 'XMLHttpRequest' in global,
+ hasXDomainRequest: 'XDomainRequest' in global
+ };
+
+ if (support.hasXMLHttpRequest) {
+ support.cors = 'withCredentials' in new XMLHttpRequest();
+ }
+
+ function AlgoliaSearchBrowser() {
+ // call AlgoliaSearch constructor
+ AlgoliaSearch.apply(this, arguments);
+ }
+
+ inherits(AlgoliaSearchBrowser, AlgoliaSearch);
+
+ AlgoliaSearchBrowser.prototype._request = function request(url, opts) {
+ return new Promise(function wrapRequest(resolve, reject) {
+ // no cors or XDomainRequest, no request
+ if (!support.cors && !support.hasXDomainRequest) {
+ // very old browser, not supported
+ reject(new errors.Network('CORS not supported'));
+ return;
+ }
+
+ url = inlineHeaders(url, opts.headers);
+
+ var body = opts.body;
+ var req = support.cors ? new XMLHttpRequest() : new XDomainRequest();
+ var reqTimeout;
+ var timedOut;
+ var connected = false;
+
+ reqTimeout = setTimeout(onTimeout, opts.timeouts.connect);
+ // 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 = onProgress;
+ if ('onreadystatechange' in req) req.onreadystatechange = onReadyStateChange;
+ req.onload = onLoad;
+ req.onerror = onError;
+
+ // do not rely on default XHR async flag, as some analytics code like hotjar
+ // breaks it and set it to false by default
+ if (req instanceof XMLHttpRequest) {
+ req.open(opts.method, url, true);
+
+ // The Analytics API never accepts Auth headers as query string
+ // this option exists specifically for them.
+ if (opts.forceAuthHeaders) {
+ req.setRequestHeader(
+ 'x-algolia-application-id',
+ opts.headers['x-algolia-application-id']
+ );
+ req.setRequestHeader(
+ 'x-algolia-api-key',
+ opts.headers['x-algolia-api-key']
+ );
+ }
+ } else {
+ req.open(opts.method, url);
+ }
+
+ // headers are meant to be sent after open
+ if (support.cors) {
+ if (body) {
+ if (opts.method === 'POST') {
+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Simple_requests
+ req.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
+ } else {
+ req.setRequestHeader('content-type', 'application/json');
+ }
+ }
+ req.setRequestHeader('accept', 'application/json');
+ }
+
+ if (body) {
+ req.send(body);
+ } else {
+ req.send();
+ }
+
+ // event object not received in IE8, at least
+ // but we do not use it, still important to note
+ function onLoad(/* event */) {
+ // When browser does not supports req.timeout, we can
+ // have both a load and timeout event, since handled by a dumb setTimeout
+ if (timedOut) {
+ return;
+ }
+
+ clearTimeout(reqTimeout);
+
+ var out;
+
+ try {
+ out = {
+ body: JSON.parse(req.responseText),
+ responseText: req.responseText,
+ statusCode: req.status,
+ // XDomainRequest does not have any response headers
+ headers: req.getAllResponseHeaders && req.getAllResponseHeaders() || {}
+ };
+ } catch (e) {
+ out = new errors.UnparsableJSON({
+ more: req.responseText
+ });
+ }
+
+ if (out instanceof errors.UnparsableJSON) {
+ reject(out);
+ } else {
+ resolve(out);
+ }
+ }
+
+ function onError(event) {
+ if (timedOut) {
+ return;
+ }
+
+ clearTimeout(reqTimeout);
+
+ // error event is trigerred both with XDR/XHR on:
+ // - DNS error
+ // - unallowed cross domain request
+ reject(
+ new errors.Network({
+ more: event
+ })
+ );
+ }
+
+ function onTimeout() {
+ timedOut = true;
+ req.abort();
+
+ reject(new errors.RequestTimeout());
+ }
+
+ function onConnect() {
+ connected = true;
+ clearTimeout(reqTimeout);
+ reqTimeout = setTimeout(onTimeout, opts.timeouts.complete);
+ }
+
+ function onProgress() {
+ if (!connected) onConnect();
+ }
+
+ function onReadyStateChange() {
+ if (!connected && req.readyState > 1) onConnect();
+ }
+ });
+ };
+
+ AlgoliaSearchBrowser.prototype._request.fallback = function requestFallback(url, opts) {
+ url = inlineHeaders(url, opts.headers);
+
+ return new Promise(function wrapJsonpRequest(resolve, reject) {
+ jsonpRequest(url, opts, function jsonpRequestDone(err, content) {
+ if (err) {
+ reject(err);
+ return;
+ }
+
+ resolve(content);
+ });
+ });
+ };
+
+ AlgoliaSearchBrowser.prototype._promise = {
+ reject: function rejectPromise(val) {
+ return Promise.reject(val);
+ },
+ resolve: function resolvePromise(val) {
+ return Promise.resolve(val);
+ },
+ delay: function delayPromise(ms) {
+ return new Promise(function resolveOnTimeout(resolve/* , reject*/) {
+ setTimeout(resolve, ms);
+ });
+ },
+ all: function all(promises) {
+ return Promise.all(promises);
+ }
+ };
+
+ return algoliasearch;
+};
diff --git a/node_modules/algoliasearch/src/browser/inline-headers.js b/node_modules/algoliasearch/src/browser/inline-headers.js
new file mode 100644
index 00000000..7339d38a
--- /dev/null
+++ b/node_modules/algoliasearch/src/browser/inline-headers.js
@@ -0,0 +1,15 @@
+'use strict';
+
+module.exports = inlineHeaders;
+
+var encode = require('querystring-es3/encode');
+
+function inlineHeaders(url, headers) {
+ if (/\?/.test(url)) {
+ url += '&';
+ } else {
+ url += '?';
+ }
+
+ return url + encode(headers);
+}
diff --git a/node_modules/algoliasearch/src/browser/jsonp-request.js b/node_modules/algoliasearch/src/browser/jsonp-request.js
new file mode 100644
index 00000000..1aed7631
--- /dev/null
+++ b/node_modules/algoliasearch/src/browser/jsonp-request.js
@@ -0,0 +1,126 @@
+'use strict';
+
+module.exports = jsonpRequest;
+
+var errors = require('../errors');
+
+var JSONPCounter = 0;
+
+function jsonpRequest(url, opts, cb) {
+ if (opts.method !== 'GET') {
+ cb(new Error('Method ' + opts.method + ' ' + url + ' is not supported by JSONP.'));
+ return;
+ }
+
+ opts.debug('JSONP: start');
+
+ var cbCalled = false;
+ var timedOut = false;
+
+ JSONPCounter += 1;
+ var head = document.getElementsByTagName('head')[0];
+ var script = document.createElement('script');
+ var cbName = 'algoliaJSONP_' + JSONPCounter;
+ var done = false;
+
+ window[cbName] = function(data) {
+ removeGlobals();
+
+ if (timedOut) {
+ opts.debug('JSONP: Late answer, ignoring');
+ return;
+ }
+
+ cbCalled = true;
+
+ clean();
+
+ cb(null, {
+ body: data,
+ responseText: JSON.stringify(data)/* ,
+ // We do not send the statusCode, there's no statusCode in JSONP, it will be
+ // computed using data.status && data.message like with XDR
+ statusCode*/
+ });
+ };
+
+ // add callback by hand
+ url += '&callback=' + cbName;
+
+ // add body params manually
+ if (opts.jsonBody && opts.jsonBody.params) {
+ url += '&' + opts.jsonBody.params;
+ }
+
+ var ontimeout = setTimeout(timeout, opts.timeouts.complete);
+
+ // script onreadystatechange needed only for
+ // <= IE8
+ // https://github.com/angular/angular.js/issues/4523
+ script.onreadystatechange = readystatechange;
+ script.onload = success;
+ script.onerror = error;
+
+ script.async = true;
+ script.defer = true;
+ script.src = url;
+ head.appendChild(script);
+
+ function success() {
+ opts.debug('JSONP: success');
+
+ if (done || timedOut) {
+ return;
+ }
+
+ done = true;
+
+ // script loaded but did not call the fn => script loading error
+ if (!cbCalled) {
+ opts.debug('JSONP: Fail. Script loaded but did not call the callback');
+ clean();
+ cb(new errors.JSONPScriptFail());
+ }
+ }
+
+ function readystatechange() {
+ if (this.readyState === 'loaded' || this.readyState === 'complete') {
+ success();
+ }
+ }
+
+ function clean() {
+ clearTimeout(ontimeout);
+ script.onload = null;
+ script.onreadystatechange = null;
+ script.onerror = null;
+ head.removeChild(script);
+ }
+
+ function removeGlobals() {
+ try {
+ delete window[cbName];
+ delete window[cbName + '_loaded'];
+ } catch (e) {
+ window[cbName] = window[cbName + '_loaded'] = undefined;
+ }
+ }
+
+ function timeout() {
+ opts.debug('JSONP: Script timeout');
+ timedOut = true;
+ clean();
+ cb(new errors.RequestTimeout());
+ }
+
+ function error() {
+ opts.debug('JSONP: Script error');
+
+ if (done || timedOut) {
+ return;
+ }
+
+ clean();
+ cb(new errors.JSONPScriptError());
+ }
+}
diff --git a/node_modules/algoliasearch/src/browser/migration-layer/is-using-latest.js b/node_modules/algoliasearch/src/browser/migration-layer/is-using-latest.js
new file mode 100644
index 00000000..f8e29d4e
--- /dev/null
+++ b/node_modules/algoliasearch/src/browser/migration-layer/is-using-latest.js
@@ -0,0 +1,23 @@
+'use strict';
+
+// this module helps finding if the current page is using
+// the cdn.jsdelivr.net/algoliasearch/latest/$BUILDNAME.min.js version
+
+module.exports = isUsingLatest;
+
+function isUsingLatest(buildName) {
+ var toFind = new RegExp('cdn\\.jsdelivr\\.net/algoliasearch/latest/' +
+ buildName.replace('.', '\\.') + // algoliasearch, algoliasearch.angular
+ '(?:\\.min)?\\.js$'); // [.min].js
+
+ var scripts = document.getElementsByTagName('script');
+ var found = false;
+ for (var currentScript = 0, nbScripts = scripts.length; currentScript < nbScripts; currentScript++) {
+ if (scripts[currentScript].src && toFind.test(scripts[currentScript].src)) {
+ found = true;
+ break;
+ }
+ }
+
+ return found;
+}
diff --git a/node_modules/algoliasearch/src/browser/migration-layer/load-v2.js b/node_modules/algoliasearch/src/browser/migration-layer/load-v2.js
new file mode 100644
index 00000000..b3470baa
--- /dev/null
+++ b/node_modules/algoliasearch/src/browser/migration-layer/load-v2.js
@@ -0,0 +1,50 @@
+'use strict';
+
+module.exports = loadV2;
+
+function loadV2(buildName) {
+ var loadScript = require('load-script');
+ var v2ScriptUrl = '//cdn.jsdelivr.net/algoliasearch/2/' + buildName + '.min.js';
+
+ var message = '-- AlgoliaSearch `latest` warning --\n' +
+ 'Warning, you are using the `latest` version string from jsDelivr to load the AlgoliaSearch library.\n' +
+ 'Using `latest` is no more recommended, you should load //cdn.jsdelivr.net/algoliasearch/2/algoliasearch.min.js\n\n' +
+ 'Also, we updated the AlgoliaSearch JavaScript client to V3. If you want to upgrade,\n' +
+ 'please read our migration guide at https://github.com/algolia/algoliasearch-client-js/wiki/Migration-guide-from-2.x.x-to-3.x.x\n' +
+ '-- /AlgoliaSearch `latest` warning --';
+
+ if (window.console) {
+ if (window.console.warn) {
+ window.console.warn(message);
+ } else if (window.console.log) {
+ window.console.log(message);
+ }
+ }
+
+ // If current script loaded asynchronously,
+ // it will load the script with DOMElement
+ // otherwise, it will load the script with document.write
+ try {
+ // why \x3c? http://stackoverflow.com/a/236106/147079
+ document.write('\x3Cscript>window.ALGOLIA_SUPPORTS_DOCWRITE = true\x3C/script>');
+
+ if (window.ALGOLIA_SUPPORTS_DOCWRITE === true) {
+ document.write('\x3Cscript src="' + v2ScriptUrl + '">\x3C/script>');
+ scriptLoaded('document.write')();
+ } else {
+ loadScript(v2ScriptUrl, scriptLoaded('DOMElement'));
+ }
+ } catch (e) {
+ loadScript(v2ScriptUrl, scriptLoaded('DOMElement'));
+ }
+}
+
+function scriptLoaded(method) {
+ return function log() {
+ var message = 'AlgoliaSearch: loaded V2 script using ' + method;
+
+ if (window.console && window.console.log) {
+ window.console.log(message);
+ }
+ };
+}
diff --git a/node_modules/algoliasearch/src/browser/migration-layer/old-globals.js b/node_modules/algoliasearch/src/browser/migration-layer/old-globals.js
new file mode 100644
index 00000000..1f40c0d2
--- /dev/null
+++ b/node_modules/algoliasearch/src/browser/migration-layer/old-globals.js
@@ -0,0 +1,26 @@
+'use strict';
+
+/* eslint no-unused-vars: [2, {"vars": "local"}] */
+
+module.exports = oldGlobals;
+
+// put old window.AlgoliaSearch.. into window. again so that
+// users upgrading to V3 without changing their code, will be warned
+function oldGlobals() {
+ var message = '-- AlgoliaSearch V2 => V3 error --\n' +
+ 'You are trying to use a new version of the AlgoliaSearch JavaScript client with an old notation.\n' +
+ 'Please read our migration guide at https://github.com/algolia/algoliasearch-client-js/wiki/Migration-guide-from-2.x.x-to-3.x.x\n' +
+ '-- /AlgoliaSearch V2 => V3 error --';
+
+ window.AlgoliaSearch = function() {
+ throw new Error(message);
+ };
+
+ window.AlgoliaSearchHelper = function() {
+ throw new Error(message);
+ };
+
+ window.AlgoliaExplainResults = function() {
+ throw new Error(message);
+ };
+}
diff --git a/node_modules/algoliasearch/src/browser/migration-layer/script.js b/node_modules/algoliasearch/src/browser/migration-layer/script.js
new file mode 100644
index 00000000..9d12315f
--- /dev/null
+++ b/node_modules/algoliasearch/src/browser/migration-layer/script.js
@@ -0,0 +1,25 @@
+'use strict';
+
+// This script will be browserified and prepended to the normal build
+// directly in window, not wrapped in any module definition
+// To avoid cases where we are loaded with /latest/ along with
+migrationLayer(process.env.ALGOLIA_BUILDNAME);
+
+// Now onto the V2 related code:
+// If the client is using /latest/$BUILDNAME.min.js, load V2 of the library
+//
+// Otherwise, setup a migration layer that will throw on old constructors like
+// new AlgoliaSearch().
+// So that users upgrading from v2 to v3 will have a clear information
+// message on what to do if they did not read the migration guide
+function migrationLayer(buildName) {
+ var isUsingLatest = require('./is-using-latest');
+ var loadV2 = require('./load-v2');
+ var oldGlobals = require('./old-globals');
+
+ if (isUsingLatest(buildName)) {
+ loadV2(buildName);
+ } else {
+ oldGlobals();
+ }
+}