algoliasearch-rails 1.12.0 → 1.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +4 -0
- data/VERSION +1 -1
- data/vendor/assets/javascripts/algolia/v3/algoliasearch.angular.js +2821 -429
- data/vendor/assets/javascripts/algolia/v3/algoliasearch.angular.min.js +75 -37
- data/vendor/assets/javascripts/algolia/v3/algoliasearch.jquery.js +2801 -412
- data/vendor/assets/javascripts/algolia/v3/algoliasearch.jquery.min.js +75 -37
- data/vendor/assets/javascripts/algolia/v3/algoliasearch.js +1745 -497
- data/vendor/assets/javascripts/algolia/v3/algoliasearch.min.js +71 -49
- metadata +22 -22
@@ -1,37 +1,75 @@
|
|
1
|
-
/*! algoliasearch 3.0
|
2
|
-
(function(
|
3
|
-
typeof require&&require,
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
try{document.write("<script>window.ALGOLIA_SUPPORTS_DOCWRITE = true\x3c/script>"),!0===
|
8
|
-
};
|
9
|
-
}}}).call(this,"undefined"!==typeof global?global:"undefined"!==typeof self?self:"undefined"!==typeof window?window:{})},{}],5:[function(
|
10
|
-
(function e$$0(
|
11
|
-
|
12
|
-
{}],2:[function(l,
|
13
|
-
|
14
|
-
a[
|
15
|
-
|
16
|
-
|
17
|
-
return
|
18
|
-
"
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
d))
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
1
|
+
/*! algoliasearch 3.3.0 | © 2014, 2015 Algolia SAS | github.com/algolia/algoliasearch-client-js */
|
2
|
+
(function(g){var l;"undefined"!==typeof window?l=window:"undefined"!==typeof self&&(l=self);l.ALGOLIA_MIGRATION_LAYER=g()})(function(){return function l(e,h,c){function b(f,p){if(!h[f]){if(!e[f]){var n="function"==typeof require&&require;if(!p&&n)return n(f,!0);if(k)return k(f,!0);n=Error("Cannot find module '"+f+"'");throw n.code="MODULE_NOT_FOUND",n;}n=h[f]={exports:{}};e[f][0].call(n.exports,function(c){var k=e[f][1][c];return b(k?k:c)},n,n.exports,l,e,h,c)}return h[f].exports}for(var k="function"==
|
3
|
+
typeof require&&require,f=0;f<c.length;f++)b(c[f]);return b}({1:[function(l,e,h){function c(f,b){for(var c in b)f.setAttribute(c,b[c])}function b(f,b){f.onload=function(){this.onerror=this.onload=null;b(null,f)};f.onerror=function(){this.onerror=this.onload=null;b(Error("Failed to load "+this.src),f)}}function k(f,b){f.onreadystatechange=function(){if("complete"==this.readyState||"loaded"==this.readyState)this.onreadystatechange=null,b(null,f)}}e.exports=function(f,e,p){var n=document.head||document.getElementsByTagName("head")[0],
|
4
|
+
h=document.createElement("script");"function"===typeof e&&(p=e,e={});e=e||{};p=p||function(){};h.type=e.type||"text/javascript";h.charset=e.charset||"utf8";h.async="async"in e?!!e.async:!0;h.src=f;e.attrs&&c(h,e.attrs);e.text&&(h.text=""+e.text);("onload"in h?b:k)(h,p);h.onload||b(h,p);n.appendChild(h)}},{}],2:[function(l,e,h){e.exports=function(c){c=new RegExp("cdn\\.jsdelivr\\.net/algoliasearch/latest/"+c.replace(".","\\.")+"(?:\\.min)?\\.js$");for(var b=document.getElementsByTagName("script"),
|
5
|
+
k=!1,f=0,e=b.length;f<e;f++)if(b[f].src&&c.test(b[f].src)){k=!0;break}return k}},{}],3:[function(l,e,h){(function(c){function b(b){return function(){var f="AlgoliaSearch: loaded V2 script using "+b;c.console&&c.console.log&&c.console.log(f)}}e.exports=function(k){var f=l(1);k="//cdn.jsdelivr.net/algoliasearch/2/"+k+".min.js";c.console&&(c.console.warn?c.console.warn("-- AlgoliaSearch `latest` warning --\nWarning, you are using the `latest` version string from jsDelivr to load the AlgoliaSearch library.\nUsing `latest` is no more recommended, you should load //cdn.jsdelivr.net/algoliasearch/2/algoliasearch.min.js\n\nAlso, we updated the AlgoliaSearch JavaScript client to V3. If you want to upgrade,\nplease 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 --"):
|
6
|
+
c.console.log&&c.console.log("-- AlgoliaSearch `latest` warning --\nWarning, you are using the `latest` version string from jsDelivr to load the AlgoliaSearch library.\nUsing `latest` is no more recommended, you should load //cdn.jsdelivr.net/algoliasearch/2/algoliasearch.min.js\n\nAlso, we updated the AlgoliaSearch JavaScript client to V3. If you want to upgrade,\nplease 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 --"));
|
7
|
+
try{document.write("<script>window.ALGOLIA_SUPPORTS_DOCWRITE = true\x3c/script>"),!0===c.ALGOLIA_SUPPORTS_DOCWRITE?(document.write('<script src="'+k+'">\x3c/script>'),b("document.write")()):f(k,b("DOMElement"))}catch(e){f(k,b("DOMElement"))}}}).call(this,"undefined"!==typeof global?global:"undefined"!==typeof self?self:"undefined"!==typeof window?window:{})},{1:1}],4:[function(l,e,h){(function(c){e.exports=function(){c.AlgoliaSearch=function(){throw Error("-- AlgoliaSearch V2 => V3 error --\nYou are trying to use a new version of the AlgoliaSearch JavaScript client with an old notation.\nPlease 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 --");
|
8
|
+
};c.AlgoliaSearchHelper=function(){throw Error("-- AlgoliaSearch V2 => V3 error --\nYou are trying to use a new version of the AlgoliaSearch JavaScript client with an old notation.\nPlease 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 --");};AlgoliaExplainResults=function(){throw Error("-- AlgoliaSearch V2 => V3 error --\nYou are trying to use a new version of the AlgoliaSearch JavaScript client with an old notation.\nPlease 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 --");
|
9
|
+
}}}).call(this,"undefined"!==typeof global?global:"undefined"!==typeof self?self:"undefined"!==typeof window?window:{})},{}],5:[function(l,e,h){e=l(2);h=l(3);l=l(4);e("algoliasearch.angular")?h("algoliasearch.angular"):l()},{2:2,3:3,4:4}]},{},[5])(5)});
|
10
|
+
(function e$$0(l,e,h){function c(f,k){if(!e[f]){if(!l[f]){var p="function"==typeof require&&require;if(!k&&p)return p(f,!0);if(b)return b(f,!0);p=Error("Cannot find module '"+f+"'");throw p.code="MODULE_NOT_FOUND",p;}p=e[f]={exports:{}};l[f][0].call(p.exports,function(b){var k=l[f][1][b];return c(k?k:b)},p,p.exports,e$$0,l,e,h)}return e[f].exports}for(var b="function"==typeof require&&require,k=0;k<h.length;k++)c(h[k]);return c})({1:[function(g,l,e){function h(){if(!k){k=!0;for(var f,c=b.length;c;){f=
|
11
|
+
b;b=[];for(var e=-1;++e<c;)f[e]();c=b.length}k=!1}}function c(){}g=l.exports={};var b=[],k=!1;g.nextTick=function(f){b.push(f);k||setTimeout(h,0)};g.title="browser";g.browser=!0;g.env={};g.argv=[];g.version="";g.versions={};g.on=c;g.addListener=c;g.once=c;g.off=c;g.removeListener=c;g.removeAllListeners=c;g.emit=c;g.binding=function(f){throw Error("process.binding is not supported");};g.cwd=function(){return"/"};g.chdir=function(f){throw Error("process.chdir is not supported");};g.umask=function(){return 0}},
|
12
|
+
{}],2:[function(g,l,e){l.exports=function(c,b,k,f){k=k||"=";var e={};if("string"!==typeof c||0===c.length)return e;var p=/\+/g;c=c.split(b||"&");b=1E3;f&&"number"===typeof f.maxKeys&&(b=f.maxKeys);f=c.length;0<b&&f>b&&(f=b);for(b=0;b<f;++b){var n=c[b].replace(p,"%20"),g=n.indexOf(k),l;0<=g?(l=n.substr(0,g),n=n.substr(g+1)):(l=n,n="");l=decodeURIComponent(l);n=decodeURIComponent(n);Object.prototype.hasOwnProperty.call(e,l)?h(e[l])?e[l].push(n):e[l]=[e[l],n]:e[l]=n}return e};var h=Array.isArray||function(c){return"[object Array]"===
|
13
|
+
Object.prototype.toString.call(c)}},{}],3:[function(g,l,e){function h(f,b){if(f.map)return f.map(b);for(var c=[],k=0;k<f.length;k++)c.push(b(f[k],k));return c}var c=function(f){switch(typeof f){case "string":return f;case "boolean":return f?"true":"false";case "number":return isFinite(f)?f:"";default:return""}};l.exports=function(f,e,p,g){e=e||"&";p=p||"=";null===f&&(f=void 0);return"object"===typeof f?h(k(f),function(k){var g=encodeURIComponent(c(k))+p;return b(f[k])?h(f[k],function(a){return g+
|
14
|
+
encodeURIComponent(c(a))}).join(e):g+encodeURIComponent(c(f[k]))}).join(e):g?encodeURIComponent(c(g))+p+encodeURIComponent(c(f)):""};var b=Array.isArray||function(f){return"[object Array]"===Object.prototype.toString.call(f)},k=Object.keys||function(f){var b=[],c;for(c in f)Object.prototype.hasOwnProperty.call(f,c)&&b.push(c);return b}},{}],4:[function(g,l,e){e.decode=e.parse=g(2);e.encode=e.stringify=g(3)},{2:2,3:3}],5:[function(g,l,e){function h(){var b;try{b=c.debug}catch(f){}return b}e=l.exports=
|
15
|
+
g(6);e.log=function(){return"object"===typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)};e.formatArgs=function(){var b=arguments,f=this.useColors;b[0]=(f?"%c":"")+this.namespace+(f?" %c":" ")+b[0]+(f?"%c ":" ")+"+"+e.humanize(this.diff);if(!f)return b;var f="color: "+this.color,b=[b[0],f,"color: inherit"].concat(Array.prototype.slice.call(b,1)),c=0,g=0;b[0].replace(/%[a-z%]/g,function(b){"%%"!==b&&(c++,"%c"===b&&(g=c))});b.splice(g,0,f);return b};e.save=function(b){try{null==
|
16
|
+
b?c.removeItem("debug"):c.debug=b}catch(f){}};e.load=h;e.useColors=function(){return"WebkitAppearance"in document.documentElement.style||window.console&&(console.firebug||console.exception&&console.table)||navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&31<=parseInt(RegExp.$1,10)};var c;if("undefined"!==typeof chrome&&"undefined"!==typeof chrome.storage)c=chrome.storage.local;else a:{try{c=window.localStorage;break a}catch(b){}c=void 0}e.colors="lightseagreen forestgreen goldenrod dodgerblue darkorchid crimson".split(" ");
|
17
|
+
e.formatters.j=function(b){return JSON.stringify(b)};e.enable(h())},{6:6}],6:[function(g,l,e){e=l.exports=function(b){function k(){}function f(){var b=+new Date;f.diff=b-(c||b);f.prev=c;c=f.curr=b;null==f.useColors&&(f.useColors=e.useColors());null==f.color&&f.useColors&&(f.color=e.colors[h++%e.colors.length]);var k=Array.prototype.slice.call(arguments);k[0]=e.coerce(k[0]);"string"!==typeof k[0]&&(k=["%o"].concat(k));var g=0;k[0]=k[0].replace(/%([a-z%])/g,function(b,a){if("%%"===b)return b;g++;var d=
|
18
|
+
e.formatters[a];"function"===typeof d&&(b=d.call(f,k[g]),k.splice(g,1),g--);return b});"function"===typeof e.formatArgs&&(k=e.formatArgs.apply(f,k));(f.log||e.log||console.log.bind(console)).apply(f,k)}k.enabled=!1;f.enabled=!0;var g=e.enabled(b)?f:k;g.namespace=b;return g};e.coerce=function(b){return b instanceof Error?b.stack||b.message:b};e.disable=function(){e.enable("")};e.enable=function(b){e.save(b);for(var c=(b||"").split(/[\s,]+/),f=c.length,g=0;g<f;g++)c[g]&&(b=c[g].replace(/\*/g,".*?"),
|
19
|
+
"-"===b[0]?e.skips.push(new RegExp("^"+b.substr(1)+"$")):e.names.push(new RegExp("^"+b+"$")))};e.enabled=function(b){var c,f;c=0;for(f=e.skips.length;c<f;c++)if(e.skips[c].test(b))return!1;c=0;for(f=e.names.length;c<f;c++)if(e.names[c].test(b))return!0;return!1};e.humanize=g(7);e.names=[];e.skips=[];e.formatters={};var h=0,c},{7:7}],7:[function(g,l,e){function h(b){if(b=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(b)){var c=
|
20
|
+
parseFloat(b[1]);switch((b[2]||"ms").toLowerCase()){case "years":case "year":case "yrs":case "yr":case "y":return 315576E5*c;case "days":case "day":case "d":return 864E5*c;case "hours":case "hour":case "hrs":case "hr":case "h":return 36E5*c;case "minutes":case "minute":case "mins":case "min":case "m":return 6E4*c;case "seconds":case "second":case "secs":case "sec":case "s":return 1E3*c;case "milliseconds":case "millisecond":case "msecs":case "msec":case "ms":return c}}}function c(b,c,f){if(!(b<c))return b<
|
21
|
+
1.5*c?Math.floor(b/c)+" "+f:Math.ceil(b/c)+" "+f+"s"}l.exports=function(b,e){e=e||{};return"string"==typeof b?h(b):e.long?c(b,864E5,"day")||c(b,36E5,"hour")||c(b,6E4,"minute")||c(b,1E3,"second")||b+" ms":864E5<=b?Math.round(b/864E5)+"d":36E5<=b?Math.round(b/36E5)+"h":6E4<=b?Math.round(b/6E4)+"m":1E3<=b?Math.round(b/1E3)+"s":b+"ms"}},{}],8:[function(g,l,e){(function(e,c){(function(){function b(a){return"function"===typeof a}function g(){return function(){e.nextTick(n)}}function f(){var a=0,d=new I(n),
|
22
|
+
m=document.createTextNode("");d.observe(m,{characterData:!0});return function(){m.data=a=++a%2}}function v(){var a=new MessageChannel;a.port1.onmessage=n;return function(){a.port2.postMessage(0)}}function p(){return function(){setTimeout(n,1)}}function n(){for(var a=0;a<z;a+=2)(0,A[a])(A[a+1]),A[a]=void 0,A[a+1]=void 0;z=0}function r(){}function w(a,d,m,b){try{a.call(d,m,b)}catch(c){return c}}function a(a,d,b){B(function(a){var c=!1,f=w(b,d,function(b){c||(c=!0,d!==b?m(a,b):u(a,b))},function(d){c||
|
23
|
+
(c=!0,t(a,d))},"Settle: "+(a._label||" unknown promise"));!c&&f&&(c=!0,t(a,f))},a)}function d(a,d){1===d._state?u(a,d._result):2===a._state?t(a,d._result):C(d,void 0,function(d){m(a,d)},function(d){t(a,d)})}function m(m,c){if(m===c)t(m,new TypeError("You cannot resolve a promise with itself"));else if("function"===typeof c||"object"===typeof c&&null!==c)if(c.constructor===m.constructor)d(m,c);else{var f;try{f=c.then}catch(e){D.error=e,f=D}f===D?t(m,D.error):void 0===f?u(m,c):b(f)?a(m,c,f):u(m,c)}else u(m,
|
24
|
+
c)}function q(a){a._onerror&&a._onerror(a._result);F(a)}function u(a,d){void 0===a._state&&(a._result=d,a._state=1,0!==a._subscribers.length&&B(F,a))}function t(a,d){void 0===a._state&&(a._state=2,a._result=d,B(q,a))}function C(a,d,m,b){var c=a._subscribers,f=c.length;a._onerror=null;c[f]=d;c[f+1]=m;c[f+2]=b;0===f&&a._state&&B(F,a)}function F(a){var d=a._subscribers,m=a._state;if(0!==d.length){for(var b,c,f=a._result,e=0;e<d.length;e+=3)b=d[e],c=d[e+m],b?J(m,b,c,f):c(f);a._subscribers.length=0}}function K(){this.error=
|
25
|
+
null}function J(a,d,c,f){var e=b(c),q,g,k,h;if(e){try{q=c(f)}catch(l){G.error=l,q=G}q===G?(h=!0,g=q.error,q=null):k=!0;if(d===q){t(d,new TypeError("A promises callback cannot return that same promise."));return}}else q=f,k=!0;void 0===d._state&&(e&&k?m(d,q):h?t(d,g):1===a?u(d,q):2===a&&t(d,q))}function N(a,d){try{d(function(d){m(a,d)},function(d){t(a,d)})}catch(b){t(a,b)}}function x(a,d,m,b){this._instanceConstructor=a;this.promise=new a(r,b);this._abortOnReject=m;this._validateInput(d)?(this._input=
|
26
|
+
d,this._remaining=this.length=d.length,this._init(),0===this.length?u(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&u(this.promise,this._result))):t(this.promise,this._validationError())}function y(a){this._id=O++;this._result=this._state=void 0;this._subscribers=[];if(r!==a){if(!b(a))throw new TypeError("You must pass a resolver function as the first argument to the promise constructor");if(!(this instanceof y))throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
|
27
|
+
N(this,a)}}var L=Array.isArray?Array.isArray:function(a){return"[object Array]"===Object.prototype.toString.call(a)},z=0,B=function(a,d){A[z]=a;A[z+1]=d;z+=2;2===z&&M()},E="undefined"!==typeof window?window:{},I=E.MutationObserver||E.WebKitMutationObserver,E="undefined"!==typeof Uint8ClampedArray&&"undefined"!==typeof importScripts&&"undefined"!==typeof MessageChannel,A=Array(1E3),M;M="undefined"!==typeof e&&"[object process]"==={}.toString.call(e)?g():I?f():E?v():p();var D=new K,G=new K;x.prototype._validateInput=
|
28
|
+
function(a){return L(a)};x.prototype._validationError=function(){return Error("Array Methods must be provided an Array")};x.prototype._init=function(){this._result=Array(this.length)};x.prototype._enumerate=function(){for(var a=this.length,d=this.promise,m=this._input,b=0;void 0===d._state&&b<a;b++)this._eachEntry(m[b],b)};x.prototype._eachEntry=function(a,d){var m=this._instanceConstructor;"object"===typeof a&&null!==a?a.constructor===m&&void 0!==a._state?(a._onerror=null,this._settledAt(a._state,
|
29
|
+
d,a._result)):this._willSettleAt(m.resolve(a),d):(this._remaining--,this._result[d]=this._makeResult(1,d,a))};x.prototype._settledAt=function(a,d,m){var b=this.promise;void 0===b._state&&(this._remaining--,this._abortOnReject&&2===a?t(b,m):this._result[d]=this._makeResult(a,d,m));0===this._remaining&&u(b,this._result)};x.prototype._makeResult=function(a,d,m){return m};x.prototype._willSettleAt=function(a,d){var m=this;C(a,void 0,function(a){m._settledAt(1,d,a)},function(a){m._settledAt(2,d,a)})};
|
30
|
+
var O=0;y.all=function(a,d){return(new x(this,a,!0,d)).promise};y.race=function(a,d){function b(a){m(f,a)}function c(a){t(f,a)}var f=new this(r,d);if(!L(a))return t(f,new TypeError("You must pass an array to race.")),f;for(var e=a.length,q=0;void 0===f._state&&q<e;q++)C(this.resolve(a[q]),void 0,b,c);return f};y.resolve=function(a,d){if(a&&"object"===typeof a&&a.constructor===this)return a;var b=new this(r,d);m(b,a);return b};y.reject=function(a,d){var m=new this(r,d);t(m,a);return m};y.prototype=
|
31
|
+
{constructor:y,then:function(a,d){var m=this._state;if(1===m&&!a||2===m&&!d)return this;var b=new this.constructor(r),c=this._result;if(m){var f=arguments[m-1];B(function(){J(m,b,f,c)})}else C(this,b,a,d);return b},"catch":function(a){return this.then(null,a)}};var H={Promise:y,polyfill:function(){var a;a="undefined"!==typeof c?c:"undefined"!==typeof window&&window.document?window:self;"Promise"in a&&"resolve"in a.Promise&&"reject"in a.Promise&&"all"in a.Promise&&"race"in a.Promise&&function(){var d;
|
32
|
+
new a.Promise(function(a){d=a});return b(d)}()||(a.Promise=y)}};"function"===typeof define&&define.amd?define(function(){return H}):"undefined"!==typeof l&&l.exports?l.exports=H:"undefined"!==typeof this&&(this.ES6Promise=H)}).call(this)}).call(this,g(1),"undefined"!==typeof global?global:"undefined"!==typeof self?self:"undefined"!==typeof window?window:{})},{1:1}],9:[function(g,l,e){var h=Object.prototype.hasOwnProperty,c=Object.prototype.toString,b=g(10),k=function(b){if(!b||"[object Object]"!==
|
33
|
+
c.call(b))return!1;var e=h.call(b,"constructor"),g=b.constructor&&b.constructor.prototype&&h.call(b.constructor.prototype,"isPrototypeOf");if(b.constructor&&!e&&!g)return!1;for(var k in b);return void 0===k||h.call(b,k)};l.exports=function v(){var c,e,g,h,a,d=arguments[0],m=1,q=arguments.length,u=!1;if("boolean"===typeof d)u=d,d=arguments[1]||{},m=2;else if("object"!==typeof d&&"function"!==typeof d||null==d)d={};for(;m<q;++m)if(c=arguments[m],null!=c)for(e in c)g=d[e],h=c[e],d!==h&&(u&&h&&(k(h)||
|
34
|
+
(a=b(h)))?(a?(a=!1,g=g&&b(g)?g:[]):g=g&&k(g)?g:{},d[e]=v(u,g,h)):void 0!==h&&(d[e]=h));return d}},{10:10}],10:[function(g,l,e){l.exports=Array.isArray||function(e){return"[object Array]"==Object.prototype.toString.call(e)}},{}],11:[function(g,l,e){var h=Object.prototype.hasOwnProperty,c=Object.prototype.toString;l.exports=function(b,e,f){if("[object Function]"!==c.call(e))throw new TypeError("iterator must be a function");var g=b.length;if(g===+g)for(var l=0;l<g;l++)e.call(f,b[l],l,b);else for(l in b)h.call(b,
|
35
|
+
l)&&e.call(f,b[l],l,b)}},{}],12:[function(g,l,e){l.exports="function"===typeof Object.create?function(e,c){e.super_=c;e.prototype=Object.create(c.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:function(e,c){e.super_=c;var b=function(){};b.prototype=c.prototype;e.prototype=new b;e.prototype.constructor=e}},{}],13:[function(g,l,e){(function(e){function c(a,d,m){var c=g(9);if(!a)throw Error("algoliasearch: Please provide an application ID. Usage: algoliasearch(applicationID, apiKey, opts)");
|
36
|
+
if(!d)throw Error("algoliasearch: Please provide an API key. Usage: algoliasearch(applicationID, apiKey, opts)");this.applicationID=a;this.apiKey=d;a=[this.applicationID+"-1.algolianet.com",this.applicationID+"-2.algolianet.com",this.applicationID+"-3.algolianet.com"];this.hosts={read:[],write:[]};this.hostIndex={read:0,write:0};m=m||{};d=m.protocol||"https:";var f=void 0===m.timeout?2E3:m.timeout;/:$/.test(d)||(d+=":");if("http:"!==m.protocol&&"https:"!==m.protocol)throw Error("algoliasearch: protocol must be `http:` or `https:` (was `"+
|
37
|
+
m.protocol+"`)");m.hosts?(this.hosts.read=c([],m.hosts),this.hosts.write=c([],m.hosts)):(this.hosts.read=[this.applicationID+"-dsn.algolia.net"].concat(a),this.hosts.write=[this.applicationID+".algolia.net"].concat(a));this.hosts.read=b(this.hosts.read,k(d));this.hosts.write=b(this.hosts.write,k(d));this.requestTimeout=f;this.extraHeaders=[];this.cache={};this._ua=m._ua;this._useCache=void 0===m._useCache?!0:m._useCache;this._setTimeout=m._setTimeout;r("init done, %j",this)}function b(a,d){for(var m=
|
38
|
+
[],b=0;b<a.length;++b)m.push(d(a[b],b));return m}function k(a){return function(d){return a+"//"+d.toLowerCase()}}function f(){throw Error("algoliasearch: Not implemented in this environment.\nIf you feel this is a mistake, write to support@algolia.com");}function v(a,d){var b=a.toLowerCase().replace(".","").replace("()","");return"algoliasearch: `"+a+"` was replaced by `"+d+"`. Please see https://github.com/algolia/algoliasearch-client-js/wiki/Deprecated#"+b}function p(a,d){d(a,0)}function n(a,d){var b=
|
39
|
+
!1;return function(){b||(console.log(d),b=!0);return a.apply(this,arguments)}}l.exports=c;"development"===e.env.NODE_ENV&&g(5).enable("algoliasearch*");var r=g(5)("algoliasearch"),w=g(11);c.prototype={deleteIndex:function(a,d){return this._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(a),hostType:"write",callback:d})},moveIndex:function(a,d,b){d={operation:"move",destination:d};return this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(a)+"/operation",body:d,
|
40
|
+
hostType:"write",callback:b})},copyIndex:function(a,d,b){d={operation:"copy",destination:d};return this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(a)+"/operation",body:d,hostType:"write",callback:b})},getLogs:function(a,d,b){if(0===arguments.length||"function"===typeof a)b=a,a=0,d=10;else if(1===arguments.length||"function"===typeof d)b=d,d=10;return this._jsonRequest({method:"GET",url:"/1/logs?offset="+a+"&length="+d,hostType:"read",callback:b})},listIndexes:function(a,d){var b=
|
41
|
+
"";void 0===a||"function"===typeof a?d=a:b="?page="+a;return this._jsonRequest({method:"GET",url:"/1/indexes"+b,hostType:"read",callback:d})},initIndex:function(a){return new this.Index(this,a)},listUserKeys:function(a){return this._jsonRequest({method:"GET",url:"/1/keys",hostType:"read",callback:a})},getUserKeyACL:function(a,d){return this._jsonRequest({method:"GET",url:"/1/keys/"+a,hostType:"read",callback:d})},deleteUserKey:function(a,d){return this._jsonRequest({method:"DELETE",url:"/1/keys/"+
|
42
|
+
a,hostType:"write",callback:d})},addUserKey:function(a,d,b){if(1===arguments.length||"function"===typeof d)b=d,d=null;var c={acl:a};d&&(c.validity=d.validity,c.maxQueriesPerIPPerHour=d.maxQueriesPerIPPerHour,c.maxHitsPerQuery=d.maxHitsPerQuery,c.indexes=d.indexes);return this._jsonRequest({method:"POST",url:"/1/keys",body:c,hostType:"write",callback:b})},addUserKeyWithValidity:n(function(a,d,b){return this.addUserKey(a,d,b)},v("client.addUserKeyWithValidity()","client.addUserKey()")),updateUserKey:function(a,
|
43
|
+
d,b,c){if(2===arguments.length||"function"===typeof b)c=b,b=null;var f={acl:d};b&&(f.validity=b.validity,f.maxQueriesPerIPPerHour=b.maxQueriesPerIPPerHour,f.maxHitsPerQuery=b.maxHitsPerQuery,f.indexes=b.indexes);return this._jsonRequest({method:"PUT",url:"/1/keys/"+a,body:f,hostType:"write",callback:c})},setSecurityTags:function(a){if("[object Array]"===Object.prototype.toString.call(a)){for(var d=[],b=0;b<a.length;++b)if("[object Array]"===Object.prototype.toString.call(a[b])){for(var c=[],f=0;f<
|
44
|
+
a[b].length;++f)c.push(a[b][f]);d.push("("+c.join(",")+")")}else d.push(a[b]);a=d.join(",")}this.securityTags=a},setUserToken:function(a){this.userToken=a},startQueriesBatch:n(function(){this._batch=[]},v("client.startQueriesBatch()","client.search()")),addQueryInBatch:n(function(a,d,b){this._batch.push({indexName:a,query:d,params:b})},v("client.addQueryInBatch()","client.search()")),clearCache:function(){this.cache={}},sendQueriesBatch:n(function(a){return this.search(this._batch,a)},v("client.sendQueriesBatch()",
|
45
|
+
"client.search()")),setRequestTimeout:function(a){a&&(this.requestTimeout=parseInt(a,10))},search:function(a,d){var c=this,f={requests:b(a,function(a){var d="";void 0!==a.query&&(d+="query="+encodeURIComponent(a.query));return{indexName:a.indexName,params:c._getSearchParams(a.params,d)}})};return this._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/*/queries",body:f,hostType:"read",callback:d})},destroy:f,enableRateLimitForward:f,disableRateLimitForward:f,useSecuredAPIKey:f,disableSecuredAPIKey:f,
|
46
|
+
generateSecuredApiKey:f,Index:function(a,d){this.indexName=d;this.as=a;this.typeAheadValueOption=this.typeAheadArgs=null;this.cache={}},setExtraHeader:function(a,d){this.extraHeaders.push({name:a.toLowerCase(),value:d})},_sendQueriesBatch:function(a,d){return this._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/*/queries",body:a,hostType:"read",fallback:{method:"GET",url:"/1/indexes/*",body:{params:function(){for(var d="",b=0;b<a.requests.length;++b)var c="/1/indexes/"+encodeURIComponent(a.requests[b].indexName)+
|
47
|
+
"?"+a.requests[b].params,d=d+(b+"="+encodeURIComponent(c)+"&");return d}()}},callback:d})},_jsonRequest:function(a){function d(g,h){function p(){e.hostIndex[a.hostType]=++e.hostIndex[a.hostType]%e.hosts[a.hostType].length;k+=1;h.timeout=e.requestTimeout*(k+1);return d(g,h)}var n;e._useCache&&(n=a.url);e._useCache&&c&&(n+="_body_"+h.body);if(e._useCache&&f&&void 0!==f[n])return b("serving response from cache"),e._promise.resolve(f[n]);if(k>=e.hosts[a.hostType].length){if(!a.fallback||!e._request.fallback||
|
48
|
+
l)return e._promise.reject(Error("Cannot connect to the AlgoliaSearch API. Send an email to support@algolia.com to report and resolve the issue."));k=0;h.method=a.fallback.method;h.url=a.fallback.url;h.jsonBody=a.fallback.body;h.jsonBody&&(h.body=JSON.stringify(a.fallback.body));h.timeout=e.requestTimeout*(k+1);e.hostIndex[a.hostType]=0;l=e.useFallback=!0;return d(e._request.fallback,h)}return g.call(e,e.hosts[a.hostType][e.hostIndex[a.hostType]]+h.url,{body:c,jsonBody:a.body,method:h.method,headers:e._computeRequestHeaders(),
|
49
|
+
timeout:h.timeout,debug:b}).then(function(a){if(a instanceof Error)return b("error: %s",a.message),p();b("received response: %j",a);var d=a&&a.body&&a.body.message&&a.body.status||a.statusCode||a&&a.body&&200,c=200===d||201===d,d=!c&&4!==Math.floor(d/100)&&1!==Math.floor(d/100);e._useCache&&c&&f&&(f[n]=a.body);return c?a.body:d?p():e._promise.reject(Error(a.body&&a.body.message||"Unknown error"))},function(c){b("error: %s, stack: %s",c.message,c.stack);e.useFallback?(e.hostIndex[a.hostType]=++e.hostIndex[a.hostType]%
|
50
|
+
e.hosts[a.hostType].length,k+=1):k=e.hosts[a.hostType].length;return d(g,h)})}var b=g(5)("algoliasearch:"+a.url),c,f=a.cache,e=this,k=0,l=!1;void 0!==a.body&&(c=JSON.stringify(a.body));b("request start");var h=e.useFallback&&a.fallback,n=h?a.fallback:a,h=d(h?e._request.fallback:e._request,{url:n.url,method:n.method,body:c,jsonBody:a.body,timeout:e.requestTimeout*(k+1)});if(a.callback)h.then(function(d){p(function(){a.callback(null,d)},e._setTimeout||setTimeout)},function(d){p(function(){a.callback(d)},
|
51
|
+
e._setTimeout||setTimeout)});else return h},_getSearchParams:function(a,d){if(this._isUndefined(a)||null===a)return d;for(var b in a)null!==b&&a.hasOwnProperty(b)&&(d+=""===d?"":"&",d+=b+"="+encodeURIComponent("[object Array]"===Object.prototype.toString.call(a[b])?JSON.stringify(a[b]):a[b]));return d},_isUndefined:function(a){return void 0===a},_computeRequestHeaders:function(){var a={"x-algolia-api-key":this.apiKey,"x-algolia-application-id":this.applicationID,"x-user-agent":this._ua};this.userToken&&
|
52
|
+
(a["x-algolia-usertoken"]=this.userToken);this.securityTags&&(a["x-algolia-tagfilters"]=this.securityTags);this.extraHeaders&&w(this.extraHeaders,function(d){a[d.name]=d.value});return a}};c.prototype.Index.prototype={clearCache:function(){this.cache={}},addObject:function(a,d,b){if(1===arguments.length||"function"===typeof d)b=d,d=void 0;return this.as._jsonRequest({method:void 0!==d?"PUT":"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+(void 0!==d?"/"+encodeURIComponent(d):""),body:a,
|
53
|
+
hostType:"write",callback:b})},addObjects:function(a,d){for(var b={requests:[]},c=0;c<a.length;++c)b.requests.push({action:"addObject",body:a[c]});return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/batch",body:b,hostType:"write",callback:d})},getObject:function(a,d,b){if(1===arguments.length||"function"===typeof d)b=d,d=void 0;var c="";if(void 0!==d)for(var c="?attributes=",f=0;f<d.length;++f)0!==f&&(c+=","),c+=d[f];return this.as._jsonRequest({method:"GET",
|
54
|
+
url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/"+encodeURIComponent(a)+c,hostType:"read",callback:b})},getObjects:function(a,d){var c=this,f={requests:b(a,function(a){return{indexName:c.indexName,objectID:a}})};return this.as._jsonRequest({method:"POST",url:"/1/indexes/*/objects",hostType:"read",body:f,callback:d})},partialUpdateObject:function(a,d){return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/"+encodeURIComponent(a.objectID)+"/partial",
|
55
|
+
body:a,hostType:"write",callback:d})},partialUpdateObjects:function(a,d){for(var b={requests:[]},c=0;c<a.length;++c)b.requests.push({action:"partialUpdateObject",objectID:a[c].objectID,body:a[c]});return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/batch",body:b,hostType:"write",callback:d})},saveObject:function(a,d){return this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/"+encodeURIComponent(a.objectID),body:a,
|
56
|
+
hostType:"write",callback:d})},saveObjects:function(a,d){for(var b={requests:[]},c=0;c<a.length;++c)b.requests.push({action:"updateObject",objectID:a[c].objectID,body:a[c]});return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/batch",body:b,hostType:"write",callback:d})},deleteObject:function(a,d){if("function"===typeof a||"string"!==typeof a&&"number"!==typeof a){var b=Error("Cannot delete an object without an objectID");d=a;return"function"===typeof d?
|
57
|
+
d(b):this.as._promise.reject(b)}return this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/"+encodeURIComponent(a),hostType:"write",callback:d})},deleteObjects:function(a,d){var c={requests:b(a,function(a){return{action:"deleteObject",objectID:a,body:{objectID:a}}})};return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/batch",body:c,hostType:"write",callback:d})},deleteByQuery:function(a,d,c){function f(a){return g.waitTask(a.taskID)}
|
58
|
+
function e(){return g.deleteByQuery(a,d)}var g=this,k=g.as;if(1===arguments.length||"function"===typeof d)c=d,d={};d.attributesToRetrieve="objectID";d.hitsPerPage=1E3;this.clearCache();var h=this.search(a,d).then(function(a){if(0===a.nbHits)return a;a=b(a.hits,function(a){return a.objectID});return g.deleteObjects(a).then(f).then(e)});if(!c)return h;h.then(function(){p(function(){c(null)},k._setTimeout||setTimeout)},function(a){p(function(){c(a)},k._setTimeout||setTimeout)})},search:function(a,d,
|
59
|
+
b){if("function"===typeof a&&"object"===typeof d||"object"===typeof b)throw Error("algoliasearch: index.search usage is index.search(query, params, cb)");if(0===arguments.length||"function"===typeof a)b=a,a="";else if(1===arguments.length||"function"===typeof d)b=d,d=void 0;if("object"===typeof a&&null!==a)d=a,a=void 0;else if(void 0===a||null===a)a="";var c="";void 0!==a&&(c+="query="+encodeURIComponent(a));void 0!==d&&(c=this.as._getSearchParams(d,c));return this._search(c,b)},browse:function(a,
|
60
|
+
d,b){if(1===arguments.length||"function"===typeof d)b=d,d=void 0;var c="?page="+a;this.as._isUndefined(d)||(c+="&hitsPerPage="+d);return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/browse"+c,hostType:"read",callback:b})},ttAdapter:function(a){var b=this;return function(c,f){b.search(c,a,function(a,b){a?f(a):f(b.hits)})}},waitTask:function(a,b){var c=this,f=c.as,e=this.as._jsonRequest({method:"GET",hostType:"read",url:"/1/indexes/"+encodeURIComponent(c.indexName)+
|
61
|
+
"/task/"+a}).then(function(b){return"published"!==b.status?c.as._promise.delay(100).then(function(){return c.waitTask(a)}):b});if(!b)return e;e.then(function(a){p(function(){b(null,a)},f._setTimeout||setTimeout)},function(a){p(function(){b(a)},f._setTimeout||setTimeout)})},clearIndex:function(a){return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/clear",hostType:"write",callback:a})},getSettings:function(a){return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+
|
62
|
+
encodeURIComponent(this.indexName)+"/settings",hostType:"read",callback:a})},setSettings:function(a,b){return this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/settings",hostType:"write",body:a,callback:b})},listUserKeys:function(a){return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/keys",hostType:"read",callback:a})},getUserKeyACL:function(a,b){return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(this.indexName)+
|
63
|
+
"/keys/"+a,hostType:"read",callback:b})},deleteUserKey:function(a,b){return this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/keys/"+a,hostType:"write",callback:b})},addUserKey:function(a,b,c){if(1===arguments.length||"function"===typeof b)c=b,b=null;var f={acl:a};b&&(f.validity=b.validity,f.maxQueriesPerIPPerHour=b.maxQueriesPerIPPerHour,f.maxHitsPerQuery=b.maxHitsPerQuery);return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+
|
64
|
+
"/keys",body:f,hostType:"write",callback:c})},addUserKeyWithValidity:n(function(a,b,c){return this.addUserKey(a,b,c)},v("index.addUserKeyWithValidity()","index.addUserKey()")),updateUserKey:function(a,b,c,f){if(2===arguments.length||"function"===typeof c)f=c,c=null;var e={acl:b};c&&(e.validity=c.validity,e.maxQueriesPerIPPerHour=c.maxQueriesPerIPPerHour,e.maxHitsPerQuery=c.maxHitsPerQuery);return this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/keys/"+a,body:e,
|
65
|
+
hostType:"write",callback:f})},_search:function(a,b){return this.as._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:{params:a},hostType:"read",fallback:{method:"GET",url:"/1/indexes/"+encodeURIComponent(this.indexName),body:{params:a}},callback:b})},as:null,indexName:null,typeAheadArgs:null,typeAheadValueOption:null}}).call(this,g(1))},{1:1,11:11,5:5,9:9}],14:[function(g,l,e){l.exports=function(c,b,e){function f(){b.debug("JSONP: success");
|
66
|
+
u||a||(u=!0,w||(b.debug("JSONP: Fail. Script loaded but did not call the callback"),l(),e(Error("Failed to load JSONP script"))))}function g(){"loaded"!==this.readyState&&"complete"!==this.readyState||f()}function l(){clearTimeout(t);m.onload=null;m.onreadystatechange=null;m.onerror=null;d.removeChild(m);try{delete window[q],delete window[q+"_loaded"]}catch(a){window[q]=null,window[q+"_loaded"]=null}}function n(){b.debug("JSONP: Script timeout");a=!0;l();e(Error("Timeout - Could not connect to endpoint "+
|
67
|
+
c))}function r(){b.debug("JSONP: Script error");u||a||(l(),e(Error("Failed to load JSONP script")))}if("GET"!==b.method)e(Error("Method "+b.method+" "+c+" is not supported by JSONP."));else{b.debug("JSONP: start");var w=!1,a=!1;h+=1;var d=document.getElementsByTagName("head")[0],m=document.createElement("script"),q="algoliaJSONP_"+h,u=!1;window[q]=function(b){try{delete window[q]}catch(d){window[q]=void 0}a||(w=!0,l(),e(null,{body:b}))};c+="&callback="+q;b.jsonBody&&b.jsonBody.params&&(c+="&"+b.jsonBody.params);
|
68
|
+
var t=setTimeout(n,b.timeout);m.onreadystatechange=g;m.onload=f;m.onerror=r;m.async=!0;m.defer=!0;m.src=c;d.appendChild(m)}};var h=0},{}],15:[function(g,l,e){(function(e){var c=g(12),b=g(13),k=g(18),f=g(14);window.algoliasearch=g(16);e.angular.module("algoliasearch",[]).service("algolia",["$http","$q","$timeout",function(e,h,l){function r(a,b,c){var f=g(9),e=g(17);c=f(!0,{},c)||{};void 0===c.protocol&&(c.protocol=e());c._ua=r.ua;return new w(a,b,c)}function w(){b.apply(this,arguments)}r.version=g(19);
|
69
|
+
r.ua="Algolia for AngularJS "+r.version;c(w,b);w.prototype._request=function(a,b){return h(function(c,f){var g,t=b.body;a=k(a,b.headers);var r=h(function(f){l(function(){g=!0;f("test");c(Error("Timeout - Could not connect to endpoint "+a))},b.timeout)});e({url:a,method:b.method,data:t,cache:!1,timeout:r}).then(function(a){c({statusCode:a.status,body:a.data})},function(a){g||(0===a.status?f(Error("Network error")):c({body:a.data,statusCode:a.status}))})})};w.prototype._request.fallback=function(a,
|
70
|
+
b){a=k(a,b.headers);return h(function(c,e){f(a,b,function(a,b){a?e(a):c(b)})})};w.prototype._promise={reject:function(a){return h.reject(a)},resolve:function(a){return h.when(a)},delay:function(a){return h(function(b){l(b,a)})}};return{Client:function(a,b,c){return r(a,b,c)},ua:r.ua,version:r.version}}])}).call(this,"undefined"!==typeof global?global:"undefined"!==typeof self?self:"undefined"!==typeof window?window:{})},{12:12,13:13,14:14,16:16,17:17,18:18,19:19,9:9}],16:[function(g,l,e){(function(e){function c(a,
|
71
|
+
f,e){var h=g(9),k=g(17);e=h(!0,{},e)||{};void 0===e.protocol&&(e.protocol=k());e._ua=c.ua;return new b(a,f,e)}function b(){v.apply(this,arguments)}l.exports=c;var k=g(12),f=e.Promise||g(8).Promise,v=g(13),p=g(18),n=g(14);c.version=g(19);c.ua="Algolia for vanilla JavaScript "+c.version;var r="XDomainRequest"in window,w="withCredentials"in new XMLHttpRequest,a="timeout"in new XMLHttpRequest;k(b,v);b.prototype._request=function(b,c){return new f(function(e,f){function g(){if(!x){a||clearTimeout(v);var b=
|
72
|
+
null;try{b=JSON.parse(n.responseText)}catch(c){}e({body:b,statusCode:n.status})}}function h(b){x||(a||clearTimeout(v),f(Error("Could not connect to host, error was:"+b)))}function k(){a||(x=!0,n.abort());e(Error("Timeout - Could not connect to endpoint "+b))}if(w||r){b=p(b,c.headers);var l=c.body,n=w?new XMLHttpRequest:new XDomainRequest,v,x;n instanceof XMLHttpRequest?n.open(c.method,b,!0):n.open(c.method,b);w&&l&&"GET"!==c.method&&n.setRequestHeader("content-type","application/x-www-form-urlencoded");
|
73
|
+
n.onprogress=function(){};n.onload=g;n.onerror=h;a?(n.timeout=c.timeout,n.ontimeout=k):v=setTimeout(k,c.timeout);n.send(l)}else f(Error("CORS not supported"))})};b.prototype._request.fallback=function(a,b){a=p(a,b.headers);return new f(function(c,e){n(a,b,function(a,b){a?e(a):c(b)})})};b.prototype._promise={reject:function(a){return f.reject(a)},resolve:function(a){return f.resolve(a)},delay:function(a){return new f(function(b){setTimeout(b,a)})}}}).call(this,"undefined"!==typeof global?global:"undefined"!==
|
74
|
+
typeof self?self:"undefined"!==typeof window?window:{})},{12:12,13:13,14:14,17:17,18:18,19:19,8:8,9:9}],17:[function(g,l,e){(function(e){l.exports=function(){var c=e.document.location.protocol;"http:"!==c&&"https:"!==c&&(c="http:");return c}}).call(this,"undefined"!==typeof global?global:"undefined"!==typeof self?self:"undefined"!==typeof window?window:{})},{}],18:[function(g,l,e){l.exports=function(c,b){c=/\?/.test(c)?c+"&":c+"?";return c+h.encode(b)};var h=g(4)},{4:4}],19:[function(g,l,e){l.exports=
|
75
|
+
"3.3.0"},{}]},{},[15]);
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/*! algoliasearch 3.0
|
1
|
+
/*! algoliasearch 3.3.0 | © 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) {
|
@@ -260,9 +260,1800 @@ process.chdir = function (dir) {
|
|
260
260
|
process.umask = function() { return 0; };
|
261
261
|
|
262
262
|
},{}],2:[function(require,module,exports){
|
263
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
264
|
+
//
|
265
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
266
|
+
// copy of this software and associated documentation files (the
|
267
|
+
// "Software"), to deal in the Software without restriction, including
|
268
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
269
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
270
|
+
// persons to whom the Software is furnished to do so, subject to the
|
271
|
+
// following conditions:
|
272
|
+
//
|
273
|
+
// The above copyright notice and this permission notice shall be included
|
274
|
+
// in all copies or substantial portions of the Software.
|
275
|
+
//
|
276
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
277
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
278
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
279
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
280
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
281
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
282
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
283
|
+
|
284
|
+
'use strict';
|
285
|
+
|
286
|
+
// If obj.hasOwnProperty has been overridden, then calling
|
287
|
+
// obj.hasOwnProperty(prop) will break.
|
288
|
+
// See: https://github.com/joyent/node/issues/1707
|
289
|
+
function hasOwnProperty(obj, prop) {
|
290
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
291
|
+
}
|
292
|
+
|
293
|
+
module.exports = function(qs, sep, eq, options) {
|
294
|
+
sep = sep || '&';
|
295
|
+
eq = eq || '=';
|
296
|
+
var obj = {};
|
297
|
+
|
298
|
+
if (typeof qs !== 'string' || qs.length === 0) {
|
299
|
+
return obj;
|
300
|
+
}
|
301
|
+
|
302
|
+
var regexp = /\+/g;
|
303
|
+
qs = qs.split(sep);
|
304
|
+
|
305
|
+
var maxKeys = 1000;
|
306
|
+
if (options && typeof options.maxKeys === 'number') {
|
307
|
+
maxKeys = options.maxKeys;
|
308
|
+
}
|
309
|
+
|
310
|
+
var len = qs.length;
|
311
|
+
// maxKeys <= 0 means that we should not limit keys count
|
312
|
+
if (maxKeys > 0 && len > maxKeys) {
|
313
|
+
len = maxKeys;
|
314
|
+
}
|
315
|
+
|
316
|
+
for (var i = 0; i < len; ++i) {
|
317
|
+
var x = qs[i].replace(regexp, '%20'),
|
318
|
+
idx = x.indexOf(eq),
|
319
|
+
kstr, vstr, k, v;
|
320
|
+
|
321
|
+
if (idx >= 0) {
|
322
|
+
kstr = x.substr(0, idx);
|
323
|
+
vstr = x.substr(idx + 1);
|
324
|
+
} else {
|
325
|
+
kstr = x;
|
326
|
+
vstr = '';
|
327
|
+
}
|
328
|
+
|
329
|
+
k = decodeURIComponent(kstr);
|
330
|
+
v = decodeURIComponent(vstr);
|
331
|
+
|
332
|
+
if (!hasOwnProperty(obj, k)) {
|
333
|
+
obj[k] = v;
|
334
|
+
} else if (isArray(obj[k])) {
|
335
|
+
obj[k].push(v);
|
336
|
+
} else {
|
337
|
+
obj[k] = [obj[k], v];
|
338
|
+
}
|
339
|
+
}
|
340
|
+
|
341
|
+
return obj;
|
342
|
+
};
|
343
|
+
|
344
|
+
var isArray = Array.isArray || function (xs) {
|
345
|
+
return Object.prototype.toString.call(xs) === '[object Array]';
|
346
|
+
};
|
347
|
+
|
348
|
+
},{}],3:[function(require,module,exports){
|
349
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
350
|
+
//
|
351
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
352
|
+
// copy of this software and associated documentation files (the
|
353
|
+
// "Software"), to deal in the Software without restriction, including
|
354
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
355
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
356
|
+
// persons to whom the Software is furnished to do so, subject to the
|
357
|
+
// following conditions:
|
358
|
+
//
|
359
|
+
// The above copyright notice and this permission notice shall be included
|
360
|
+
// in all copies or substantial portions of the Software.
|
361
|
+
//
|
362
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
363
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
364
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
365
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
366
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
367
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
368
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
369
|
+
|
370
|
+
'use strict';
|
371
|
+
|
372
|
+
var stringifyPrimitive = function(v) {
|
373
|
+
switch (typeof v) {
|
374
|
+
case 'string':
|
375
|
+
return v;
|
376
|
+
|
377
|
+
case 'boolean':
|
378
|
+
return v ? 'true' : 'false';
|
379
|
+
|
380
|
+
case 'number':
|
381
|
+
return isFinite(v) ? v : '';
|
382
|
+
|
383
|
+
default:
|
384
|
+
return '';
|
385
|
+
}
|
386
|
+
};
|
387
|
+
|
388
|
+
module.exports = function(obj, sep, eq, name) {
|
389
|
+
sep = sep || '&';
|
390
|
+
eq = eq || '=';
|
391
|
+
if (obj === null) {
|
392
|
+
obj = undefined;
|
393
|
+
}
|
394
|
+
|
395
|
+
if (typeof obj === 'object') {
|
396
|
+
return map(objectKeys(obj), function(k) {
|
397
|
+
var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
|
398
|
+
if (isArray(obj[k])) {
|
399
|
+
return map(obj[k], function(v) {
|
400
|
+
return ks + encodeURIComponent(stringifyPrimitive(v));
|
401
|
+
}).join(sep);
|
402
|
+
} else {
|
403
|
+
return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
|
404
|
+
}
|
405
|
+
}).join(sep);
|
406
|
+
|
407
|
+
}
|
408
|
+
|
409
|
+
if (!name) return '';
|
410
|
+
return encodeURIComponent(stringifyPrimitive(name)) + eq +
|
411
|
+
encodeURIComponent(stringifyPrimitive(obj));
|
412
|
+
};
|
413
|
+
|
414
|
+
var isArray = Array.isArray || function (xs) {
|
415
|
+
return Object.prototype.toString.call(xs) === '[object Array]';
|
416
|
+
};
|
417
|
+
|
418
|
+
function map (xs, f) {
|
419
|
+
if (xs.map) return xs.map(f);
|
420
|
+
var res = [];
|
421
|
+
for (var i = 0; i < xs.length; i++) {
|
422
|
+
res.push(f(xs[i], i));
|
423
|
+
}
|
424
|
+
return res;
|
425
|
+
}
|
426
|
+
|
427
|
+
var objectKeys = Object.keys || function (obj) {
|
428
|
+
var res = [];
|
429
|
+
for (var key in obj) {
|
430
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
|
431
|
+
}
|
432
|
+
return res;
|
433
|
+
};
|
434
|
+
|
435
|
+
},{}],4:[function(require,module,exports){
|
436
|
+
'use strict';
|
437
|
+
|
438
|
+
exports.decode = exports.parse = require(2);
|
439
|
+
exports.encode = exports.stringify = require(3);
|
440
|
+
|
441
|
+
},{"2":2,"3":3}],5:[function(require,module,exports){
|
442
|
+
|
443
|
+
/**
|
444
|
+
* This is the web browser implementation of `debug()`.
|
445
|
+
*
|
446
|
+
* Expose `debug()` as the module.
|
447
|
+
*/
|
448
|
+
|
449
|
+
exports = module.exports = require(6);
|
450
|
+
exports.log = log;
|
451
|
+
exports.formatArgs = formatArgs;
|
452
|
+
exports.save = save;
|
453
|
+
exports.load = load;
|
454
|
+
exports.useColors = useColors;
|
455
|
+
|
456
|
+
/**
|
457
|
+
* Use chrome.storage.local if we are in an app
|
458
|
+
*/
|
459
|
+
|
460
|
+
var storage;
|
461
|
+
|
462
|
+
if (typeof chrome !== 'undefined' && typeof chrome.storage !== 'undefined')
|
463
|
+
storage = chrome.storage.local;
|
464
|
+
else
|
465
|
+
storage = localstorage();
|
466
|
+
|
467
|
+
/**
|
468
|
+
* Colors.
|
469
|
+
*/
|
470
|
+
|
471
|
+
exports.colors = [
|
472
|
+
'lightseagreen',
|
473
|
+
'forestgreen',
|
474
|
+
'goldenrod',
|
475
|
+
'dodgerblue',
|
476
|
+
'darkorchid',
|
477
|
+
'crimson'
|
478
|
+
];
|
479
|
+
|
480
|
+
/**
|
481
|
+
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
482
|
+
* and the Firebug extension (any Firefox version) are known
|
483
|
+
* to support "%c" CSS customizations.
|
484
|
+
*
|
485
|
+
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
486
|
+
*/
|
487
|
+
|
488
|
+
function useColors() {
|
489
|
+
// is webkit? http://stackoverflow.com/a/16459606/376773
|
490
|
+
return ('WebkitAppearance' in document.documentElement.style) ||
|
491
|
+
// is firebug? http://stackoverflow.com/a/398120/376773
|
492
|
+
(window.console && (console.firebug || (console.exception && console.table))) ||
|
493
|
+
// is firefox >= v31?
|
494
|
+
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
495
|
+
(navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31);
|
496
|
+
}
|
497
|
+
|
498
|
+
/**
|
499
|
+
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
500
|
+
*/
|
501
|
+
|
502
|
+
exports.formatters.j = function(v) {
|
503
|
+
return JSON.stringify(v);
|
504
|
+
};
|
505
|
+
|
506
|
+
|
507
|
+
/**
|
508
|
+
* Colorize log arguments if enabled.
|
509
|
+
*
|
510
|
+
* @api public
|
511
|
+
*/
|
512
|
+
|
513
|
+
function formatArgs() {
|
514
|
+
var args = arguments;
|
515
|
+
var useColors = this.useColors;
|
516
|
+
|
517
|
+
args[0] = (useColors ? '%c' : '')
|
518
|
+
+ this.namespace
|
519
|
+
+ (useColors ? ' %c' : ' ')
|
520
|
+
+ args[0]
|
521
|
+
+ (useColors ? '%c ' : ' ')
|
522
|
+
+ '+' + exports.humanize(this.diff);
|
523
|
+
|
524
|
+
if (!useColors) return args;
|
525
|
+
|
526
|
+
var c = 'color: ' + this.color;
|
527
|
+
args = [args[0], c, 'color: inherit'].concat(Array.prototype.slice.call(args, 1));
|
528
|
+
|
529
|
+
// the final "%c" is somewhat tricky, because there could be other
|
530
|
+
// arguments passed either before or after the %c, so we need to
|
531
|
+
// figure out the correct index to insert the CSS into
|
532
|
+
var index = 0;
|
533
|
+
var lastC = 0;
|
534
|
+
args[0].replace(/%[a-z%]/g, function(match) {
|
535
|
+
if ('%%' === match) return;
|
536
|
+
index++;
|
537
|
+
if ('%c' === match) {
|
538
|
+
// we only are interested in the *last* %c
|
539
|
+
// (the user may have provided their own)
|
540
|
+
lastC = index;
|
541
|
+
}
|
542
|
+
});
|
543
|
+
|
544
|
+
args.splice(lastC, 0, c);
|
545
|
+
return args;
|
546
|
+
}
|
547
|
+
|
548
|
+
/**
|
549
|
+
* Invokes `console.log()` when available.
|
550
|
+
* No-op when `console.log` is not a "function".
|
551
|
+
*
|
552
|
+
* @api public
|
553
|
+
*/
|
554
|
+
|
555
|
+
function log() {
|
556
|
+
// this hackery is required for IE8/9, where
|
557
|
+
// the `console.log` function doesn't have 'apply'
|
558
|
+
return 'object' === typeof console
|
559
|
+
&& console.log
|
560
|
+
&& Function.prototype.apply.call(console.log, console, arguments);
|
561
|
+
}
|
562
|
+
|
563
|
+
/**
|
564
|
+
* Save `namespaces`.
|
565
|
+
*
|
566
|
+
* @param {String} namespaces
|
567
|
+
* @api private
|
568
|
+
*/
|
569
|
+
|
570
|
+
function save(namespaces) {
|
571
|
+
try {
|
572
|
+
if (null == namespaces) {
|
573
|
+
storage.removeItem('debug');
|
574
|
+
} else {
|
575
|
+
storage.debug = namespaces;
|
576
|
+
}
|
577
|
+
} catch(e) {}
|
578
|
+
}
|
579
|
+
|
580
|
+
/**
|
581
|
+
* Load `namespaces`.
|
582
|
+
*
|
583
|
+
* @return {String} returns the previously persisted debug modes
|
584
|
+
* @api private
|
585
|
+
*/
|
586
|
+
|
587
|
+
function load() {
|
588
|
+
var r;
|
589
|
+
try {
|
590
|
+
r = storage.debug;
|
591
|
+
} catch(e) {}
|
592
|
+
return r;
|
593
|
+
}
|
594
|
+
|
595
|
+
/**
|
596
|
+
* Enable namespaces listed in `localStorage.debug` initially.
|
597
|
+
*/
|
598
|
+
|
599
|
+
exports.enable(load());
|
600
|
+
|
601
|
+
/**
|
602
|
+
* Localstorage attempts to return the localstorage.
|
603
|
+
*
|
604
|
+
* This is necessary because safari throws
|
605
|
+
* when a user disables cookies/localstorage
|
606
|
+
* and you attempt to access it.
|
607
|
+
*
|
608
|
+
* @return {LocalStorage}
|
609
|
+
* @api private
|
610
|
+
*/
|
611
|
+
|
612
|
+
function localstorage(){
|
613
|
+
try {
|
614
|
+
return window.localStorage;
|
615
|
+
} catch (e) {}
|
616
|
+
}
|
617
|
+
|
618
|
+
},{"6":6}],6:[function(require,module,exports){
|
619
|
+
|
620
|
+
/**
|
621
|
+
* This is the common logic for both the Node.js and web browser
|
622
|
+
* implementations of `debug()`.
|
623
|
+
*
|
624
|
+
* Expose `debug()` as the module.
|
625
|
+
*/
|
626
|
+
|
627
|
+
exports = module.exports = debug;
|
628
|
+
exports.coerce = coerce;
|
629
|
+
exports.disable = disable;
|
630
|
+
exports.enable = enable;
|
631
|
+
exports.enabled = enabled;
|
632
|
+
exports.humanize = require(7);
|
633
|
+
|
634
|
+
/**
|
635
|
+
* The currently active debug mode names, and names to skip.
|
636
|
+
*/
|
637
|
+
|
638
|
+
exports.names = [];
|
639
|
+
exports.skips = [];
|
640
|
+
|
641
|
+
/**
|
642
|
+
* Map of special "%n" handling functions, for the debug "format" argument.
|
643
|
+
*
|
644
|
+
* Valid key names are a single, lowercased letter, i.e. "n".
|
645
|
+
*/
|
646
|
+
|
647
|
+
exports.formatters = {};
|
648
|
+
|
649
|
+
/**
|
650
|
+
* Previously assigned color.
|
651
|
+
*/
|
652
|
+
|
653
|
+
var prevColor = 0;
|
654
|
+
|
655
|
+
/**
|
656
|
+
* Previous log timestamp.
|
657
|
+
*/
|
658
|
+
|
659
|
+
var prevTime;
|
660
|
+
|
661
|
+
/**
|
662
|
+
* Select a color.
|
663
|
+
*
|
664
|
+
* @return {Number}
|
665
|
+
* @api private
|
666
|
+
*/
|
667
|
+
|
668
|
+
function selectColor() {
|
669
|
+
return exports.colors[prevColor++ % exports.colors.length];
|
670
|
+
}
|
671
|
+
|
672
|
+
/**
|
673
|
+
* Create a debugger with the given `namespace`.
|
674
|
+
*
|
675
|
+
* @param {String} namespace
|
676
|
+
* @return {Function}
|
677
|
+
* @api public
|
678
|
+
*/
|
679
|
+
|
680
|
+
function debug(namespace) {
|
681
|
+
|
682
|
+
// define the `disabled` version
|
683
|
+
function disabled() {
|
684
|
+
}
|
685
|
+
disabled.enabled = false;
|
686
|
+
|
687
|
+
// define the `enabled` version
|
688
|
+
function enabled() {
|
689
|
+
|
690
|
+
var self = enabled;
|
691
|
+
|
692
|
+
// set `diff` timestamp
|
693
|
+
var curr = +new Date();
|
694
|
+
var ms = curr - (prevTime || curr);
|
695
|
+
self.diff = ms;
|
696
|
+
self.prev = prevTime;
|
697
|
+
self.curr = curr;
|
698
|
+
prevTime = curr;
|
699
|
+
|
700
|
+
// add the `color` if not set
|
701
|
+
if (null == self.useColors) self.useColors = exports.useColors();
|
702
|
+
if (null == self.color && self.useColors) self.color = selectColor();
|
703
|
+
|
704
|
+
var args = Array.prototype.slice.call(arguments);
|
705
|
+
|
706
|
+
args[0] = exports.coerce(args[0]);
|
707
|
+
|
708
|
+
if ('string' !== typeof args[0]) {
|
709
|
+
// anything else let's inspect with %o
|
710
|
+
args = ['%o'].concat(args);
|
711
|
+
}
|
712
|
+
|
713
|
+
// apply any `formatters` transformations
|
714
|
+
var index = 0;
|
715
|
+
args[0] = args[0].replace(/%([a-z%])/g, function(match, format) {
|
716
|
+
// if we encounter an escaped % then don't increase the array index
|
717
|
+
if (match === '%%') return match;
|
718
|
+
index++;
|
719
|
+
var formatter = exports.formatters[format];
|
720
|
+
if ('function' === typeof formatter) {
|
721
|
+
var val = args[index];
|
722
|
+
match = formatter.call(self, val);
|
723
|
+
|
724
|
+
// now we need to remove `args[index]` since it's inlined in the `format`
|
725
|
+
args.splice(index, 1);
|
726
|
+
index--;
|
727
|
+
}
|
728
|
+
return match;
|
729
|
+
});
|
730
|
+
|
731
|
+
if ('function' === typeof exports.formatArgs) {
|
732
|
+
args = exports.formatArgs.apply(self, args);
|
733
|
+
}
|
734
|
+
var logFn = enabled.log || exports.log || console.log.bind(console);
|
735
|
+
logFn.apply(self, args);
|
736
|
+
}
|
737
|
+
enabled.enabled = true;
|
738
|
+
|
739
|
+
var fn = exports.enabled(namespace) ? enabled : disabled;
|
740
|
+
|
741
|
+
fn.namespace = namespace;
|
742
|
+
|
743
|
+
return fn;
|
744
|
+
}
|
745
|
+
|
746
|
+
/**
|
747
|
+
* Enables a debug mode by namespaces. This can include modes
|
748
|
+
* separated by a colon and wildcards.
|
749
|
+
*
|
750
|
+
* @param {String} namespaces
|
751
|
+
* @api public
|
752
|
+
*/
|
753
|
+
|
754
|
+
function enable(namespaces) {
|
755
|
+
exports.save(namespaces);
|
756
|
+
|
757
|
+
var split = (namespaces || '').split(/[\s,]+/);
|
758
|
+
var len = split.length;
|
759
|
+
|
760
|
+
for (var i = 0; i < len; i++) {
|
761
|
+
if (!split[i]) continue; // ignore empty strings
|
762
|
+
namespaces = split[i].replace(/\*/g, '.*?');
|
763
|
+
if (namespaces[0] === '-') {
|
764
|
+
exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
765
|
+
} else {
|
766
|
+
exports.names.push(new RegExp('^' + namespaces + '$'));
|
767
|
+
}
|
768
|
+
}
|
769
|
+
}
|
770
|
+
|
771
|
+
/**
|
772
|
+
* Disable debug output.
|
773
|
+
*
|
774
|
+
* @api public
|
775
|
+
*/
|
776
|
+
|
777
|
+
function disable() {
|
778
|
+
exports.enable('');
|
779
|
+
}
|
780
|
+
|
781
|
+
/**
|
782
|
+
* Returns true if the given mode name is enabled, false otherwise.
|
783
|
+
*
|
784
|
+
* @param {String} name
|
785
|
+
* @return {Boolean}
|
786
|
+
* @api public
|
787
|
+
*/
|
788
|
+
|
789
|
+
function enabled(name) {
|
790
|
+
var i, len;
|
791
|
+
for (i = 0, len = exports.skips.length; i < len; i++) {
|
792
|
+
if (exports.skips[i].test(name)) {
|
793
|
+
return false;
|
794
|
+
}
|
795
|
+
}
|
796
|
+
for (i = 0, len = exports.names.length; i < len; i++) {
|
797
|
+
if (exports.names[i].test(name)) {
|
798
|
+
return true;
|
799
|
+
}
|
800
|
+
}
|
801
|
+
return false;
|
802
|
+
}
|
803
|
+
|
804
|
+
/**
|
805
|
+
* Coerce `val`.
|
806
|
+
*
|
807
|
+
* @param {Mixed} val
|
808
|
+
* @return {Mixed}
|
809
|
+
* @api private
|
810
|
+
*/
|
811
|
+
|
812
|
+
function coerce(val) {
|
813
|
+
if (val instanceof Error) return val.stack || val.message;
|
814
|
+
return val;
|
815
|
+
}
|
816
|
+
|
817
|
+
},{"7":7}],7:[function(require,module,exports){
|
818
|
+
/**
|
819
|
+
* Helpers.
|
820
|
+
*/
|
821
|
+
|
822
|
+
var s = 1000;
|
823
|
+
var m = s * 60;
|
824
|
+
var h = m * 60;
|
825
|
+
var d = h * 24;
|
826
|
+
var y = d * 365.25;
|
827
|
+
|
828
|
+
/**
|
829
|
+
* Parse or format the given `val`.
|
830
|
+
*
|
831
|
+
* Options:
|
832
|
+
*
|
833
|
+
* - `long` verbose formatting [false]
|
834
|
+
*
|
835
|
+
* @param {String|Number} val
|
836
|
+
* @param {Object} options
|
837
|
+
* @return {String|Number}
|
838
|
+
* @api public
|
839
|
+
*/
|
840
|
+
|
841
|
+
module.exports = function(val, options){
|
842
|
+
options = options || {};
|
843
|
+
if ('string' == typeof val) return parse(val);
|
844
|
+
return options.long
|
845
|
+
? long(val)
|
846
|
+
: short(val);
|
847
|
+
};
|
848
|
+
|
849
|
+
/**
|
850
|
+
* Parse the given `str` and return milliseconds.
|
851
|
+
*
|
852
|
+
* @param {String} str
|
853
|
+
* @return {Number}
|
854
|
+
* @api private
|
855
|
+
*/
|
856
|
+
|
857
|
+
function parse(str) {
|
858
|
+
var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str);
|
859
|
+
if (!match) return;
|
860
|
+
var n = parseFloat(match[1]);
|
861
|
+
var type = (match[2] || 'ms').toLowerCase();
|
862
|
+
switch (type) {
|
863
|
+
case 'years':
|
864
|
+
case 'year':
|
865
|
+
case 'yrs':
|
866
|
+
case 'yr':
|
867
|
+
case 'y':
|
868
|
+
return n * y;
|
869
|
+
case 'days':
|
870
|
+
case 'day':
|
871
|
+
case 'd':
|
872
|
+
return n * d;
|
873
|
+
case 'hours':
|
874
|
+
case 'hour':
|
875
|
+
case 'hrs':
|
876
|
+
case 'hr':
|
877
|
+
case 'h':
|
878
|
+
return n * h;
|
879
|
+
case 'minutes':
|
880
|
+
case 'minute':
|
881
|
+
case 'mins':
|
882
|
+
case 'min':
|
883
|
+
case 'm':
|
884
|
+
return n * m;
|
885
|
+
case 'seconds':
|
886
|
+
case 'second':
|
887
|
+
case 'secs':
|
888
|
+
case 'sec':
|
889
|
+
case 's':
|
890
|
+
return n * s;
|
891
|
+
case 'milliseconds':
|
892
|
+
case 'millisecond':
|
893
|
+
case 'msecs':
|
894
|
+
case 'msec':
|
895
|
+
case 'ms':
|
896
|
+
return n;
|
897
|
+
}
|
898
|
+
}
|
899
|
+
|
900
|
+
/**
|
901
|
+
* Short format for `ms`.
|
902
|
+
*
|
903
|
+
* @param {Number} ms
|
904
|
+
* @return {String}
|
905
|
+
* @api private
|
906
|
+
*/
|
907
|
+
|
908
|
+
function short(ms) {
|
909
|
+
if (ms >= d) return Math.round(ms / d) + 'd';
|
910
|
+
if (ms >= h) return Math.round(ms / h) + 'h';
|
911
|
+
if (ms >= m) return Math.round(ms / m) + 'm';
|
912
|
+
if (ms >= s) return Math.round(ms / s) + 's';
|
913
|
+
return ms + 'ms';
|
914
|
+
}
|
915
|
+
|
916
|
+
/**
|
917
|
+
* Long format for `ms`.
|
918
|
+
*
|
919
|
+
* @param {Number} ms
|
920
|
+
* @return {String}
|
921
|
+
* @api private
|
922
|
+
*/
|
923
|
+
|
924
|
+
function long(ms) {
|
925
|
+
return plural(ms, d, 'day')
|
926
|
+
|| plural(ms, h, 'hour')
|
927
|
+
|| plural(ms, m, 'minute')
|
928
|
+
|| plural(ms, s, 'second')
|
929
|
+
|| ms + ' ms';
|
930
|
+
}
|
931
|
+
|
932
|
+
/**
|
933
|
+
* Pluralization helper.
|
934
|
+
*/
|
935
|
+
|
936
|
+
function plural(ms, n, name) {
|
937
|
+
if (ms < n) return;
|
938
|
+
if (ms < n * 1.5) return Math.floor(ms / n) + ' ' + name;
|
939
|
+
return Math.ceil(ms / n) + ' ' + name + 's';
|
940
|
+
}
|
941
|
+
|
942
|
+
},{}],8:[function(require,module,exports){
|
943
|
+
(function (process,global){
|
944
|
+
/*!
|
945
|
+
* @overview es6-promise - a tiny implementation of Promises/A+.
|
946
|
+
* @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
|
947
|
+
* @license Licensed under MIT license
|
948
|
+
* See https://raw.githubusercontent.com/jakearchibald/es6-promise/master/LICENSE
|
949
|
+
* @version 2.0.1
|
950
|
+
*/
|
951
|
+
|
952
|
+
(function() {
|
953
|
+
"use strict";
|
954
|
+
|
955
|
+
function $$utils$$objectOrFunction(x) {
|
956
|
+
return typeof x === 'function' || (typeof x === 'object' && x !== null);
|
957
|
+
}
|
958
|
+
|
959
|
+
function $$utils$$isFunction(x) {
|
960
|
+
return typeof x === 'function';
|
961
|
+
}
|
962
|
+
|
963
|
+
function $$utils$$isMaybeThenable(x) {
|
964
|
+
return typeof x === 'object' && x !== null;
|
965
|
+
}
|
966
|
+
|
967
|
+
var $$utils$$_isArray;
|
968
|
+
|
969
|
+
if (!Array.isArray) {
|
970
|
+
$$utils$$_isArray = function (x) {
|
971
|
+
return Object.prototype.toString.call(x) === '[object Array]';
|
972
|
+
};
|
973
|
+
} else {
|
974
|
+
$$utils$$_isArray = Array.isArray;
|
975
|
+
}
|
976
|
+
|
977
|
+
var $$utils$$isArray = $$utils$$_isArray;
|
978
|
+
var $$utils$$now = Date.now || function() { return new Date().getTime(); };
|
979
|
+
function $$utils$$F() { }
|
980
|
+
|
981
|
+
var $$utils$$o_create = (Object.create || function (o) {
|
982
|
+
if (arguments.length > 1) {
|
983
|
+
throw new Error('Second argument not supported');
|
984
|
+
}
|
985
|
+
if (typeof o !== 'object') {
|
986
|
+
throw new TypeError('Argument must be an object');
|
987
|
+
}
|
988
|
+
$$utils$$F.prototype = o;
|
989
|
+
return new $$utils$$F();
|
990
|
+
});
|
991
|
+
|
992
|
+
var $$asap$$len = 0;
|
993
|
+
|
994
|
+
var $$asap$$default = function asap(callback, arg) {
|
995
|
+
$$asap$$queue[$$asap$$len] = callback;
|
996
|
+
$$asap$$queue[$$asap$$len + 1] = arg;
|
997
|
+
$$asap$$len += 2;
|
998
|
+
if ($$asap$$len === 2) {
|
999
|
+
// If len is 1, that means that we need to schedule an async flush.
|
1000
|
+
// If additional callbacks are queued before the queue is flushed, they
|
1001
|
+
// will be processed by this flush that we are scheduling.
|
1002
|
+
$$asap$$scheduleFlush();
|
1003
|
+
}
|
1004
|
+
};
|
1005
|
+
|
1006
|
+
var $$asap$$browserGlobal = (typeof window !== 'undefined') ? window : {};
|
1007
|
+
var $$asap$$BrowserMutationObserver = $$asap$$browserGlobal.MutationObserver || $$asap$$browserGlobal.WebKitMutationObserver;
|
1008
|
+
|
1009
|
+
// test for web worker but not in IE10
|
1010
|
+
var $$asap$$isWorker = typeof Uint8ClampedArray !== 'undefined' &&
|
1011
|
+
typeof importScripts !== 'undefined' &&
|
1012
|
+
typeof MessageChannel !== 'undefined';
|
1013
|
+
|
1014
|
+
// node
|
1015
|
+
function $$asap$$useNextTick() {
|
1016
|
+
return function() {
|
1017
|
+
process.nextTick($$asap$$flush);
|
1018
|
+
};
|
1019
|
+
}
|
1020
|
+
|
1021
|
+
function $$asap$$useMutationObserver() {
|
1022
|
+
var iterations = 0;
|
1023
|
+
var observer = new $$asap$$BrowserMutationObserver($$asap$$flush);
|
1024
|
+
var node = document.createTextNode('');
|
1025
|
+
observer.observe(node, { characterData: true });
|
1026
|
+
|
1027
|
+
return function() {
|
1028
|
+
node.data = (iterations = ++iterations % 2);
|
1029
|
+
};
|
1030
|
+
}
|
1031
|
+
|
1032
|
+
// web worker
|
1033
|
+
function $$asap$$useMessageChannel() {
|
1034
|
+
var channel = new MessageChannel();
|
1035
|
+
channel.port1.onmessage = $$asap$$flush;
|
1036
|
+
return function () {
|
1037
|
+
channel.port2.postMessage(0);
|
1038
|
+
};
|
1039
|
+
}
|
1040
|
+
|
1041
|
+
function $$asap$$useSetTimeout() {
|
1042
|
+
return function() {
|
1043
|
+
setTimeout($$asap$$flush, 1);
|
1044
|
+
};
|
1045
|
+
}
|
1046
|
+
|
1047
|
+
var $$asap$$queue = new Array(1000);
|
1048
|
+
|
1049
|
+
function $$asap$$flush() {
|
1050
|
+
for (var i = 0; i < $$asap$$len; i+=2) {
|
1051
|
+
var callback = $$asap$$queue[i];
|
1052
|
+
var arg = $$asap$$queue[i+1];
|
1053
|
+
|
1054
|
+
callback(arg);
|
1055
|
+
|
1056
|
+
$$asap$$queue[i] = undefined;
|
1057
|
+
$$asap$$queue[i+1] = undefined;
|
1058
|
+
}
|
1059
|
+
|
1060
|
+
$$asap$$len = 0;
|
1061
|
+
}
|
1062
|
+
|
1063
|
+
var $$asap$$scheduleFlush;
|
1064
|
+
|
1065
|
+
// Decide what async method to use to triggering processing of queued callbacks:
|
1066
|
+
if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
|
1067
|
+
$$asap$$scheduleFlush = $$asap$$useNextTick();
|
1068
|
+
} else if ($$asap$$BrowserMutationObserver) {
|
1069
|
+
$$asap$$scheduleFlush = $$asap$$useMutationObserver();
|
1070
|
+
} else if ($$asap$$isWorker) {
|
1071
|
+
$$asap$$scheduleFlush = $$asap$$useMessageChannel();
|
1072
|
+
} else {
|
1073
|
+
$$asap$$scheduleFlush = $$asap$$useSetTimeout();
|
1074
|
+
}
|
1075
|
+
|
1076
|
+
function $$$internal$$noop() {}
|
1077
|
+
var $$$internal$$PENDING = void 0;
|
1078
|
+
var $$$internal$$FULFILLED = 1;
|
1079
|
+
var $$$internal$$REJECTED = 2;
|
1080
|
+
var $$$internal$$GET_THEN_ERROR = new $$$internal$$ErrorObject();
|
1081
|
+
|
1082
|
+
function $$$internal$$selfFullfillment() {
|
1083
|
+
return new TypeError("You cannot resolve a promise with itself");
|
1084
|
+
}
|
1085
|
+
|
1086
|
+
function $$$internal$$cannotReturnOwn() {
|
1087
|
+
return new TypeError('A promises callback cannot return that same promise.')
|
1088
|
+
}
|
1089
|
+
|
1090
|
+
function $$$internal$$getThen(promise) {
|
1091
|
+
try {
|
1092
|
+
return promise.then;
|
1093
|
+
} catch(error) {
|
1094
|
+
$$$internal$$GET_THEN_ERROR.error = error;
|
1095
|
+
return $$$internal$$GET_THEN_ERROR;
|
1096
|
+
}
|
1097
|
+
}
|
1098
|
+
|
1099
|
+
function $$$internal$$tryThen(then, value, fulfillmentHandler, rejectionHandler) {
|
1100
|
+
try {
|
1101
|
+
then.call(value, fulfillmentHandler, rejectionHandler);
|
1102
|
+
} catch(e) {
|
1103
|
+
return e;
|
1104
|
+
}
|
1105
|
+
}
|
1106
|
+
|
1107
|
+
function $$$internal$$handleForeignThenable(promise, thenable, then) {
|
1108
|
+
$$asap$$default(function(promise) {
|
1109
|
+
var sealed = false;
|
1110
|
+
var error = $$$internal$$tryThen(then, thenable, function(value) {
|
1111
|
+
if (sealed) { return; }
|
1112
|
+
sealed = true;
|
1113
|
+
if (thenable !== value) {
|
1114
|
+
$$$internal$$resolve(promise, value);
|
1115
|
+
} else {
|
1116
|
+
$$$internal$$fulfill(promise, value);
|
1117
|
+
}
|
1118
|
+
}, function(reason) {
|
1119
|
+
if (sealed) { return; }
|
1120
|
+
sealed = true;
|
1121
|
+
|
1122
|
+
$$$internal$$reject(promise, reason);
|
1123
|
+
}, 'Settle: ' + (promise._label || ' unknown promise'));
|
1124
|
+
|
1125
|
+
if (!sealed && error) {
|
1126
|
+
sealed = true;
|
1127
|
+
$$$internal$$reject(promise, error);
|
1128
|
+
}
|
1129
|
+
}, promise);
|
1130
|
+
}
|
1131
|
+
|
1132
|
+
function $$$internal$$handleOwnThenable(promise, thenable) {
|
1133
|
+
if (thenable._state === $$$internal$$FULFILLED) {
|
1134
|
+
$$$internal$$fulfill(promise, thenable._result);
|
1135
|
+
} else if (promise._state === $$$internal$$REJECTED) {
|
1136
|
+
$$$internal$$reject(promise, thenable._result);
|
1137
|
+
} else {
|
1138
|
+
$$$internal$$subscribe(thenable, undefined, function(value) {
|
1139
|
+
$$$internal$$resolve(promise, value);
|
1140
|
+
}, function(reason) {
|
1141
|
+
$$$internal$$reject(promise, reason);
|
1142
|
+
});
|
1143
|
+
}
|
1144
|
+
}
|
1145
|
+
|
1146
|
+
function $$$internal$$handleMaybeThenable(promise, maybeThenable) {
|
1147
|
+
if (maybeThenable.constructor === promise.constructor) {
|
1148
|
+
$$$internal$$handleOwnThenable(promise, maybeThenable);
|
1149
|
+
} else {
|
1150
|
+
var then = $$$internal$$getThen(maybeThenable);
|
1151
|
+
|
1152
|
+
if (then === $$$internal$$GET_THEN_ERROR) {
|
1153
|
+
$$$internal$$reject(promise, $$$internal$$GET_THEN_ERROR.error);
|
1154
|
+
} else if (then === undefined) {
|
1155
|
+
$$$internal$$fulfill(promise, maybeThenable);
|
1156
|
+
} else if ($$utils$$isFunction(then)) {
|
1157
|
+
$$$internal$$handleForeignThenable(promise, maybeThenable, then);
|
1158
|
+
} else {
|
1159
|
+
$$$internal$$fulfill(promise, maybeThenable);
|
1160
|
+
}
|
1161
|
+
}
|
1162
|
+
}
|
1163
|
+
|
1164
|
+
function $$$internal$$resolve(promise, value) {
|
1165
|
+
if (promise === value) {
|
1166
|
+
$$$internal$$reject(promise, $$$internal$$selfFullfillment());
|
1167
|
+
} else if ($$utils$$objectOrFunction(value)) {
|
1168
|
+
$$$internal$$handleMaybeThenable(promise, value);
|
1169
|
+
} else {
|
1170
|
+
$$$internal$$fulfill(promise, value);
|
1171
|
+
}
|
1172
|
+
}
|
1173
|
+
|
1174
|
+
function $$$internal$$publishRejection(promise) {
|
1175
|
+
if (promise._onerror) {
|
1176
|
+
promise._onerror(promise._result);
|
1177
|
+
}
|
1178
|
+
|
1179
|
+
$$$internal$$publish(promise);
|
1180
|
+
}
|
1181
|
+
|
1182
|
+
function $$$internal$$fulfill(promise, value) {
|
1183
|
+
if (promise._state !== $$$internal$$PENDING) { return; }
|
1184
|
+
|
1185
|
+
promise._result = value;
|
1186
|
+
promise._state = $$$internal$$FULFILLED;
|
1187
|
+
|
1188
|
+
if (promise._subscribers.length === 0) {
|
1189
|
+
} else {
|
1190
|
+
$$asap$$default($$$internal$$publish, promise);
|
1191
|
+
}
|
1192
|
+
}
|
1193
|
+
|
1194
|
+
function $$$internal$$reject(promise, reason) {
|
1195
|
+
if (promise._state !== $$$internal$$PENDING) { return; }
|
1196
|
+
promise._state = $$$internal$$REJECTED;
|
1197
|
+
promise._result = reason;
|
1198
|
+
|
1199
|
+
$$asap$$default($$$internal$$publishRejection, promise);
|
1200
|
+
}
|
1201
|
+
|
1202
|
+
function $$$internal$$subscribe(parent, child, onFulfillment, onRejection) {
|
1203
|
+
var subscribers = parent._subscribers;
|
1204
|
+
var length = subscribers.length;
|
1205
|
+
|
1206
|
+
parent._onerror = null;
|
1207
|
+
|
1208
|
+
subscribers[length] = child;
|
1209
|
+
subscribers[length + $$$internal$$FULFILLED] = onFulfillment;
|
1210
|
+
subscribers[length + $$$internal$$REJECTED] = onRejection;
|
1211
|
+
|
1212
|
+
if (length === 0 && parent._state) {
|
1213
|
+
$$asap$$default($$$internal$$publish, parent);
|
1214
|
+
}
|
1215
|
+
}
|
1216
|
+
|
1217
|
+
function $$$internal$$publish(promise) {
|
1218
|
+
var subscribers = promise._subscribers;
|
1219
|
+
var settled = promise._state;
|
1220
|
+
|
1221
|
+
if (subscribers.length === 0) { return; }
|
1222
|
+
|
1223
|
+
var child, callback, detail = promise._result;
|
1224
|
+
|
1225
|
+
for (var i = 0; i < subscribers.length; i += 3) {
|
1226
|
+
child = subscribers[i];
|
1227
|
+
callback = subscribers[i + settled];
|
1228
|
+
|
1229
|
+
if (child) {
|
1230
|
+
$$$internal$$invokeCallback(settled, child, callback, detail);
|
1231
|
+
} else {
|
1232
|
+
callback(detail);
|
1233
|
+
}
|
1234
|
+
}
|
1235
|
+
|
1236
|
+
promise._subscribers.length = 0;
|
1237
|
+
}
|
1238
|
+
|
1239
|
+
function $$$internal$$ErrorObject() {
|
1240
|
+
this.error = null;
|
1241
|
+
}
|
1242
|
+
|
1243
|
+
var $$$internal$$TRY_CATCH_ERROR = new $$$internal$$ErrorObject();
|
1244
|
+
|
1245
|
+
function $$$internal$$tryCatch(callback, detail) {
|
1246
|
+
try {
|
1247
|
+
return callback(detail);
|
1248
|
+
} catch(e) {
|
1249
|
+
$$$internal$$TRY_CATCH_ERROR.error = e;
|
1250
|
+
return $$$internal$$TRY_CATCH_ERROR;
|
1251
|
+
}
|
1252
|
+
}
|
1253
|
+
|
1254
|
+
function $$$internal$$invokeCallback(settled, promise, callback, detail) {
|
1255
|
+
var hasCallback = $$utils$$isFunction(callback),
|
1256
|
+
value, error, succeeded, failed;
|
1257
|
+
|
1258
|
+
if (hasCallback) {
|
1259
|
+
value = $$$internal$$tryCatch(callback, detail);
|
1260
|
+
|
1261
|
+
if (value === $$$internal$$TRY_CATCH_ERROR) {
|
1262
|
+
failed = true;
|
1263
|
+
error = value.error;
|
1264
|
+
value = null;
|
1265
|
+
} else {
|
1266
|
+
succeeded = true;
|
1267
|
+
}
|
1268
|
+
|
1269
|
+
if (promise === value) {
|
1270
|
+
$$$internal$$reject(promise, $$$internal$$cannotReturnOwn());
|
1271
|
+
return;
|
1272
|
+
}
|
1273
|
+
|
1274
|
+
} else {
|
1275
|
+
value = detail;
|
1276
|
+
succeeded = true;
|
1277
|
+
}
|
1278
|
+
|
1279
|
+
if (promise._state !== $$$internal$$PENDING) {
|
1280
|
+
// noop
|
1281
|
+
} else if (hasCallback && succeeded) {
|
1282
|
+
$$$internal$$resolve(promise, value);
|
1283
|
+
} else if (failed) {
|
1284
|
+
$$$internal$$reject(promise, error);
|
1285
|
+
} else if (settled === $$$internal$$FULFILLED) {
|
1286
|
+
$$$internal$$fulfill(promise, value);
|
1287
|
+
} else if (settled === $$$internal$$REJECTED) {
|
1288
|
+
$$$internal$$reject(promise, value);
|
1289
|
+
}
|
1290
|
+
}
|
1291
|
+
|
1292
|
+
function $$$internal$$initializePromise(promise, resolver) {
|
1293
|
+
try {
|
1294
|
+
resolver(function resolvePromise(value){
|
1295
|
+
$$$internal$$resolve(promise, value);
|
1296
|
+
}, function rejectPromise(reason) {
|
1297
|
+
$$$internal$$reject(promise, reason);
|
1298
|
+
});
|
1299
|
+
} catch(e) {
|
1300
|
+
$$$internal$$reject(promise, e);
|
1301
|
+
}
|
1302
|
+
}
|
1303
|
+
|
1304
|
+
function $$$enumerator$$makeSettledResult(state, position, value) {
|
1305
|
+
if (state === $$$internal$$FULFILLED) {
|
1306
|
+
return {
|
1307
|
+
state: 'fulfilled',
|
1308
|
+
value: value
|
1309
|
+
};
|
1310
|
+
} else {
|
1311
|
+
return {
|
1312
|
+
state: 'rejected',
|
1313
|
+
reason: value
|
1314
|
+
};
|
1315
|
+
}
|
1316
|
+
}
|
1317
|
+
|
1318
|
+
function $$$enumerator$$Enumerator(Constructor, input, abortOnReject, label) {
|
1319
|
+
this._instanceConstructor = Constructor;
|
1320
|
+
this.promise = new Constructor($$$internal$$noop, label);
|
1321
|
+
this._abortOnReject = abortOnReject;
|
1322
|
+
|
1323
|
+
if (this._validateInput(input)) {
|
1324
|
+
this._input = input;
|
1325
|
+
this.length = input.length;
|
1326
|
+
this._remaining = input.length;
|
1327
|
+
|
1328
|
+
this._init();
|
1329
|
+
|
1330
|
+
if (this.length === 0) {
|
1331
|
+
$$$internal$$fulfill(this.promise, this._result);
|
1332
|
+
} else {
|
1333
|
+
this.length = this.length || 0;
|
1334
|
+
this._enumerate();
|
1335
|
+
if (this._remaining === 0) {
|
1336
|
+
$$$internal$$fulfill(this.promise, this._result);
|
1337
|
+
}
|
1338
|
+
}
|
1339
|
+
} else {
|
1340
|
+
$$$internal$$reject(this.promise, this._validationError());
|
1341
|
+
}
|
1342
|
+
}
|
1343
|
+
|
1344
|
+
$$$enumerator$$Enumerator.prototype._validateInput = function(input) {
|
1345
|
+
return $$utils$$isArray(input);
|
1346
|
+
};
|
1347
|
+
|
1348
|
+
$$$enumerator$$Enumerator.prototype._validationError = function() {
|
1349
|
+
return new Error('Array Methods must be provided an Array');
|
1350
|
+
};
|
1351
|
+
|
1352
|
+
$$$enumerator$$Enumerator.prototype._init = function() {
|
1353
|
+
this._result = new Array(this.length);
|
1354
|
+
};
|
1355
|
+
|
1356
|
+
var $$$enumerator$$default = $$$enumerator$$Enumerator;
|
1357
|
+
|
1358
|
+
$$$enumerator$$Enumerator.prototype._enumerate = function() {
|
1359
|
+
var length = this.length;
|
1360
|
+
var promise = this.promise;
|
1361
|
+
var input = this._input;
|
1362
|
+
|
1363
|
+
for (var i = 0; promise._state === $$$internal$$PENDING && i < length; i++) {
|
1364
|
+
this._eachEntry(input[i], i);
|
1365
|
+
}
|
1366
|
+
};
|
1367
|
+
|
1368
|
+
$$$enumerator$$Enumerator.prototype._eachEntry = function(entry, i) {
|
1369
|
+
var c = this._instanceConstructor;
|
1370
|
+
if ($$utils$$isMaybeThenable(entry)) {
|
1371
|
+
if (entry.constructor === c && entry._state !== $$$internal$$PENDING) {
|
1372
|
+
entry._onerror = null;
|
1373
|
+
this._settledAt(entry._state, i, entry._result);
|
1374
|
+
} else {
|
1375
|
+
this._willSettleAt(c.resolve(entry), i);
|
1376
|
+
}
|
1377
|
+
} else {
|
1378
|
+
this._remaining--;
|
1379
|
+
this._result[i] = this._makeResult($$$internal$$FULFILLED, i, entry);
|
1380
|
+
}
|
1381
|
+
};
|
1382
|
+
|
1383
|
+
$$$enumerator$$Enumerator.prototype._settledAt = function(state, i, value) {
|
1384
|
+
var promise = this.promise;
|
1385
|
+
|
1386
|
+
if (promise._state === $$$internal$$PENDING) {
|
1387
|
+
this._remaining--;
|
1388
|
+
|
1389
|
+
if (this._abortOnReject && state === $$$internal$$REJECTED) {
|
1390
|
+
$$$internal$$reject(promise, value);
|
1391
|
+
} else {
|
1392
|
+
this._result[i] = this._makeResult(state, i, value);
|
1393
|
+
}
|
1394
|
+
}
|
1395
|
+
|
1396
|
+
if (this._remaining === 0) {
|
1397
|
+
$$$internal$$fulfill(promise, this._result);
|
1398
|
+
}
|
1399
|
+
};
|
1400
|
+
|
1401
|
+
$$$enumerator$$Enumerator.prototype._makeResult = function(state, i, value) {
|
1402
|
+
return value;
|
1403
|
+
};
|
1404
|
+
|
1405
|
+
$$$enumerator$$Enumerator.prototype._willSettleAt = function(promise, i) {
|
1406
|
+
var enumerator = this;
|
1407
|
+
|
1408
|
+
$$$internal$$subscribe(promise, undefined, function(value) {
|
1409
|
+
enumerator._settledAt($$$internal$$FULFILLED, i, value);
|
1410
|
+
}, function(reason) {
|
1411
|
+
enumerator._settledAt($$$internal$$REJECTED, i, reason);
|
1412
|
+
});
|
1413
|
+
};
|
1414
|
+
|
1415
|
+
var $$promise$all$$default = function all(entries, label) {
|
1416
|
+
return new $$$enumerator$$default(this, entries, true /* abort on reject */, label).promise;
|
1417
|
+
};
|
1418
|
+
|
1419
|
+
var $$promise$race$$default = function race(entries, label) {
|
1420
|
+
/*jshint validthis:true */
|
1421
|
+
var Constructor = this;
|
1422
|
+
|
1423
|
+
var promise = new Constructor($$$internal$$noop, label);
|
1424
|
+
|
1425
|
+
if (!$$utils$$isArray(entries)) {
|
1426
|
+
$$$internal$$reject(promise, new TypeError('You must pass an array to race.'));
|
1427
|
+
return promise;
|
1428
|
+
}
|
1429
|
+
|
1430
|
+
var length = entries.length;
|
1431
|
+
|
1432
|
+
function onFulfillment(value) {
|
1433
|
+
$$$internal$$resolve(promise, value);
|
1434
|
+
}
|
1435
|
+
|
1436
|
+
function onRejection(reason) {
|
1437
|
+
$$$internal$$reject(promise, reason);
|
1438
|
+
}
|
1439
|
+
|
1440
|
+
for (var i = 0; promise._state === $$$internal$$PENDING && i < length; i++) {
|
1441
|
+
$$$internal$$subscribe(Constructor.resolve(entries[i]), undefined, onFulfillment, onRejection);
|
1442
|
+
}
|
1443
|
+
|
1444
|
+
return promise;
|
1445
|
+
};
|
1446
|
+
|
1447
|
+
var $$promise$resolve$$default = function resolve(object, label) {
|
1448
|
+
/*jshint validthis:true */
|
1449
|
+
var Constructor = this;
|
1450
|
+
|
1451
|
+
if (object && typeof object === 'object' && object.constructor === Constructor) {
|
1452
|
+
return object;
|
1453
|
+
}
|
1454
|
+
|
1455
|
+
var promise = new Constructor($$$internal$$noop, label);
|
1456
|
+
$$$internal$$resolve(promise, object);
|
1457
|
+
return promise;
|
1458
|
+
};
|
1459
|
+
|
1460
|
+
var $$promise$reject$$default = function reject(reason, label) {
|
1461
|
+
/*jshint validthis:true */
|
1462
|
+
var Constructor = this;
|
1463
|
+
var promise = new Constructor($$$internal$$noop, label);
|
1464
|
+
$$$internal$$reject(promise, reason);
|
1465
|
+
return promise;
|
1466
|
+
};
|
1467
|
+
|
1468
|
+
var $$es6$promise$promise$$counter = 0;
|
1469
|
+
|
1470
|
+
function $$es6$promise$promise$$needsResolver() {
|
1471
|
+
throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
|
1472
|
+
}
|
1473
|
+
|
1474
|
+
function $$es6$promise$promise$$needsNew() {
|
1475
|
+
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
|
1476
|
+
}
|
1477
|
+
|
1478
|
+
var $$es6$promise$promise$$default = $$es6$promise$promise$$Promise;
|
1479
|
+
|
1480
|
+
/**
|
1481
|
+
Promise objects represent the eventual result of an asynchronous operation. The
|
1482
|
+
primary way of interacting with a promise is through its `then` method, which
|
1483
|
+
registers callbacks to receive either a promise’s eventual value or the reason
|
1484
|
+
why the promise cannot be fulfilled.
|
1485
|
+
|
1486
|
+
Terminology
|
1487
|
+
-----------
|
1488
|
+
|
1489
|
+
- `promise` is an object or function with a `then` method whose behavior conforms to this specification.
|
1490
|
+
- `thenable` is an object or function that defines a `then` method.
|
1491
|
+
- `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
|
1492
|
+
- `exception` is a value that is thrown using the throw statement.
|
1493
|
+
- `reason` is a value that indicates why a promise was rejected.
|
1494
|
+
- `settled` the final resting state of a promise, fulfilled or rejected.
|
1495
|
+
|
1496
|
+
A promise can be in one of three states: pending, fulfilled, or rejected.
|
1497
|
+
|
1498
|
+
Promises that are fulfilled have a fulfillment value and are in the fulfilled
|
1499
|
+
state. Promises that are rejected have a rejection reason and are in the
|
1500
|
+
rejected state. A fulfillment value is never a thenable.
|
1501
|
+
|
1502
|
+
Promises can also be said to *resolve* a value. If this value is also a
|
1503
|
+
promise, then the original promise's settled state will match the value's
|
1504
|
+
settled state. So a promise that *resolves* a promise that rejects will
|
1505
|
+
itself reject, and a promise that *resolves* a promise that fulfills will
|
1506
|
+
itself fulfill.
|
1507
|
+
|
1508
|
+
|
1509
|
+
Basic Usage:
|
1510
|
+
------------
|
1511
|
+
|
1512
|
+
```js
|
1513
|
+
var promise = new Promise(function(resolve, reject) {
|
1514
|
+
// on success
|
1515
|
+
resolve(value);
|
1516
|
+
|
1517
|
+
// on failure
|
1518
|
+
reject(reason);
|
1519
|
+
});
|
1520
|
+
|
1521
|
+
promise.then(function(value) {
|
1522
|
+
// on fulfillment
|
1523
|
+
}, function(reason) {
|
1524
|
+
// on rejection
|
1525
|
+
});
|
1526
|
+
```
|
1527
|
+
|
1528
|
+
Advanced Usage:
|
1529
|
+
---------------
|
1530
|
+
|
1531
|
+
Promises shine when abstracting away asynchronous interactions such as
|
1532
|
+
`XMLHttpRequest`s.
|
1533
|
+
|
1534
|
+
```js
|
1535
|
+
function getJSON(url) {
|
1536
|
+
return new Promise(function(resolve, reject){
|
1537
|
+
var xhr = new XMLHttpRequest();
|
1538
|
+
|
1539
|
+
xhr.open('GET', url);
|
1540
|
+
xhr.onreadystatechange = handler;
|
1541
|
+
xhr.responseType = 'json';
|
1542
|
+
xhr.setRequestHeader('Accept', 'application/json');
|
1543
|
+
xhr.send();
|
1544
|
+
|
1545
|
+
function handler() {
|
1546
|
+
if (this.readyState === this.DONE) {
|
1547
|
+
if (this.status === 200) {
|
1548
|
+
resolve(this.response);
|
1549
|
+
} else {
|
1550
|
+
reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
|
1551
|
+
}
|
1552
|
+
}
|
1553
|
+
};
|
1554
|
+
});
|
1555
|
+
}
|
1556
|
+
|
1557
|
+
getJSON('/posts.json').then(function(json) {
|
1558
|
+
// on fulfillment
|
1559
|
+
}, function(reason) {
|
1560
|
+
// on rejection
|
1561
|
+
});
|
1562
|
+
```
|
1563
|
+
|
1564
|
+
Unlike callbacks, promises are great composable primitives.
|
1565
|
+
|
1566
|
+
```js
|
1567
|
+
Promise.all([
|
1568
|
+
getJSON('/posts'),
|
1569
|
+
getJSON('/comments')
|
1570
|
+
]).then(function(values){
|
1571
|
+
values[0] // => postsJSON
|
1572
|
+
values[1] // => commentsJSON
|
1573
|
+
|
1574
|
+
return values;
|
1575
|
+
});
|
1576
|
+
```
|
1577
|
+
|
1578
|
+
@class Promise
|
1579
|
+
@param {function} resolver
|
1580
|
+
Useful for tooling.
|
1581
|
+
@constructor
|
1582
|
+
*/
|
1583
|
+
function $$es6$promise$promise$$Promise(resolver) {
|
1584
|
+
this._id = $$es6$promise$promise$$counter++;
|
1585
|
+
this._state = undefined;
|
1586
|
+
this._result = undefined;
|
1587
|
+
this._subscribers = [];
|
1588
|
+
|
1589
|
+
if ($$$internal$$noop !== resolver) {
|
1590
|
+
if (!$$utils$$isFunction(resolver)) {
|
1591
|
+
$$es6$promise$promise$$needsResolver();
|
1592
|
+
}
|
1593
|
+
|
1594
|
+
if (!(this instanceof $$es6$promise$promise$$Promise)) {
|
1595
|
+
$$es6$promise$promise$$needsNew();
|
1596
|
+
}
|
1597
|
+
|
1598
|
+
$$$internal$$initializePromise(this, resolver);
|
1599
|
+
}
|
1600
|
+
}
|
1601
|
+
|
1602
|
+
$$es6$promise$promise$$Promise.all = $$promise$all$$default;
|
1603
|
+
$$es6$promise$promise$$Promise.race = $$promise$race$$default;
|
1604
|
+
$$es6$promise$promise$$Promise.resolve = $$promise$resolve$$default;
|
1605
|
+
$$es6$promise$promise$$Promise.reject = $$promise$reject$$default;
|
1606
|
+
|
1607
|
+
$$es6$promise$promise$$Promise.prototype = {
|
1608
|
+
constructor: $$es6$promise$promise$$Promise,
|
1609
|
+
|
1610
|
+
/**
|
1611
|
+
The primary way of interacting with a promise is through its `then` method,
|
1612
|
+
which registers callbacks to receive either a promise's eventual value or the
|
1613
|
+
reason why the promise cannot be fulfilled.
|
1614
|
+
|
1615
|
+
```js
|
1616
|
+
findUser().then(function(user){
|
1617
|
+
// user is available
|
1618
|
+
}, function(reason){
|
1619
|
+
// user is unavailable, and you are given the reason why
|
1620
|
+
});
|
1621
|
+
```
|
1622
|
+
|
1623
|
+
Chaining
|
1624
|
+
--------
|
1625
|
+
|
1626
|
+
The return value of `then` is itself a promise. This second, 'downstream'
|
1627
|
+
promise is resolved with the return value of the first promise's fulfillment
|
1628
|
+
or rejection handler, or rejected if the handler throws an exception.
|
1629
|
+
|
1630
|
+
```js
|
1631
|
+
findUser().then(function (user) {
|
1632
|
+
return user.name;
|
1633
|
+
}, function (reason) {
|
1634
|
+
return 'default name';
|
1635
|
+
}).then(function (userName) {
|
1636
|
+
// If `findUser` fulfilled, `userName` will be the user's name, otherwise it
|
1637
|
+
// will be `'default name'`
|
1638
|
+
});
|
1639
|
+
|
1640
|
+
findUser().then(function (user) {
|
1641
|
+
throw new Error('Found user, but still unhappy');
|
1642
|
+
}, function (reason) {
|
1643
|
+
throw new Error('`findUser` rejected and we're unhappy');
|
1644
|
+
}).then(function (value) {
|
1645
|
+
// never reached
|
1646
|
+
}, function (reason) {
|
1647
|
+
// if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
|
1648
|
+
// If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
|
1649
|
+
});
|
1650
|
+
```
|
1651
|
+
If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
|
1652
|
+
|
1653
|
+
```js
|
1654
|
+
findUser().then(function (user) {
|
1655
|
+
throw new PedagogicalException('Upstream error');
|
1656
|
+
}).then(function (value) {
|
1657
|
+
// never reached
|
1658
|
+
}).then(function (value) {
|
1659
|
+
// never reached
|
1660
|
+
}, function (reason) {
|
1661
|
+
// The `PedgagocialException` is propagated all the way down to here
|
1662
|
+
});
|
1663
|
+
```
|
1664
|
+
|
1665
|
+
Assimilation
|
1666
|
+
------------
|
1667
|
+
|
1668
|
+
Sometimes the value you want to propagate to a downstream promise can only be
|
1669
|
+
retrieved asynchronously. This can be achieved by returning a promise in the
|
1670
|
+
fulfillment or rejection handler. The downstream promise will then be pending
|
1671
|
+
until the returned promise is settled. This is called *assimilation*.
|
1672
|
+
|
1673
|
+
```js
|
1674
|
+
findUser().then(function (user) {
|
1675
|
+
return findCommentsByAuthor(user);
|
1676
|
+
}).then(function (comments) {
|
1677
|
+
// The user's comments are now available
|
1678
|
+
});
|
1679
|
+
```
|
1680
|
+
|
1681
|
+
If the assimliated promise rejects, then the downstream promise will also reject.
|
1682
|
+
|
1683
|
+
```js
|
1684
|
+
findUser().then(function (user) {
|
1685
|
+
return findCommentsByAuthor(user);
|
1686
|
+
}).then(function (comments) {
|
1687
|
+
// If `findCommentsByAuthor` fulfills, we'll have the value here
|
1688
|
+
}, function (reason) {
|
1689
|
+
// If `findCommentsByAuthor` rejects, we'll have the reason here
|
1690
|
+
});
|
1691
|
+
```
|
1692
|
+
|
1693
|
+
Simple Example
|
1694
|
+
--------------
|
1695
|
+
|
1696
|
+
Synchronous Example
|
1697
|
+
|
1698
|
+
```javascript
|
1699
|
+
var result;
|
1700
|
+
|
1701
|
+
try {
|
1702
|
+
result = findResult();
|
1703
|
+
// success
|
1704
|
+
} catch(reason) {
|
1705
|
+
// failure
|
1706
|
+
}
|
1707
|
+
```
|
1708
|
+
|
1709
|
+
Errback Example
|
1710
|
+
|
1711
|
+
```js
|
1712
|
+
findResult(function(result, err){
|
1713
|
+
if (err) {
|
1714
|
+
// failure
|
1715
|
+
} else {
|
1716
|
+
// success
|
1717
|
+
}
|
1718
|
+
});
|
1719
|
+
```
|
1720
|
+
|
1721
|
+
Promise Example;
|
1722
|
+
|
1723
|
+
```javascript
|
1724
|
+
findResult().then(function(result){
|
1725
|
+
// success
|
1726
|
+
}, function(reason){
|
1727
|
+
// failure
|
1728
|
+
});
|
1729
|
+
```
|
1730
|
+
|
1731
|
+
Advanced Example
|
1732
|
+
--------------
|
1733
|
+
|
1734
|
+
Synchronous Example
|
1735
|
+
|
1736
|
+
```javascript
|
1737
|
+
var author, books;
|
1738
|
+
|
1739
|
+
try {
|
1740
|
+
author = findAuthor();
|
1741
|
+
books = findBooksByAuthor(author);
|
1742
|
+
// success
|
1743
|
+
} catch(reason) {
|
1744
|
+
// failure
|
1745
|
+
}
|
1746
|
+
```
|
1747
|
+
|
1748
|
+
Errback Example
|
1749
|
+
|
1750
|
+
```js
|
1751
|
+
|
1752
|
+
function foundBooks(books) {
|
1753
|
+
|
1754
|
+
}
|
1755
|
+
|
1756
|
+
function failure(reason) {
|
1757
|
+
|
1758
|
+
}
|
1759
|
+
|
1760
|
+
findAuthor(function(author, err){
|
1761
|
+
if (err) {
|
1762
|
+
failure(err);
|
1763
|
+
// failure
|
1764
|
+
} else {
|
1765
|
+
try {
|
1766
|
+
findBoooksByAuthor(author, function(books, err) {
|
1767
|
+
if (err) {
|
1768
|
+
failure(err);
|
1769
|
+
} else {
|
1770
|
+
try {
|
1771
|
+
foundBooks(books);
|
1772
|
+
} catch(reason) {
|
1773
|
+
failure(reason);
|
1774
|
+
}
|
1775
|
+
}
|
1776
|
+
});
|
1777
|
+
} catch(error) {
|
1778
|
+
failure(err);
|
1779
|
+
}
|
1780
|
+
// success
|
1781
|
+
}
|
1782
|
+
});
|
1783
|
+
```
|
1784
|
+
|
1785
|
+
Promise Example;
|
1786
|
+
|
1787
|
+
```javascript
|
1788
|
+
findAuthor().
|
1789
|
+
then(findBooksByAuthor).
|
1790
|
+
then(function(books){
|
1791
|
+
// found books
|
1792
|
+
}).catch(function(reason){
|
1793
|
+
// something went wrong
|
1794
|
+
});
|
1795
|
+
```
|
1796
|
+
|
1797
|
+
@method then
|
1798
|
+
@param {Function} onFulfilled
|
1799
|
+
@param {Function} onRejected
|
1800
|
+
Useful for tooling.
|
1801
|
+
@return {Promise}
|
1802
|
+
*/
|
1803
|
+
then: function(onFulfillment, onRejection) {
|
1804
|
+
var parent = this;
|
1805
|
+
var state = parent._state;
|
1806
|
+
|
1807
|
+
if (state === $$$internal$$FULFILLED && !onFulfillment || state === $$$internal$$REJECTED && !onRejection) {
|
1808
|
+
return this;
|
1809
|
+
}
|
1810
|
+
|
1811
|
+
var child = new this.constructor($$$internal$$noop);
|
1812
|
+
var result = parent._result;
|
1813
|
+
|
1814
|
+
if (state) {
|
1815
|
+
var callback = arguments[state - 1];
|
1816
|
+
$$asap$$default(function(){
|
1817
|
+
$$$internal$$invokeCallback(state, child, callback, result);
|
1818
|
+
});
|
1819
|
+
} else {
|
1820
|
+
$$$internal$$subscribe(parent, child, onFulfillment, onRejection);
|
1821
|
+
}
|
1822
|
+
|
1823
|
+
return child;
|
1824
|
+
},
|
1825
|
+
|
1826
|
+
/**
|
1827
|
+
`catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
|
1828
|
+
as the catch block of a try/catch statement.
|
1829
|
+
|
1830
|
+
```js
|
1831
|
+
function findAuthor(){
|
1832
|
+
throw new Error('couldn't find that author');
|
1833
|
+
}
|
1834
|
+
|
1835
|
+
// synchronous
|
1836
|
+
try {
|
1837
|
+
findAuthor();
|
1838
|
+
} catch(reason) {
|
1839
|
+
// something went wrong
|
1840
|
+
}
|
1841
|
+
|
1842
|
+
// async with promises
|
1843
|
+
findAuthor().catch(function(reason){
|
1844
|
+
// something went wrong
|
1845
|
+
});
|
1846
|
+
```
|
1847
|
+
|
1848
|
+
@method catch
|
1849
|
+
@param {Function} onRejection
|
1850
|
+
Useful for tooling.
|
1851
|
+
@return {Promise}
|
1852
|
+
*/
|
1853
|
+
'catch': function(onRejection) {
|
1854
|
+
return this.then(null, onRejection);
|
1855
|
+
}
|
1856
|
+
};
|
1857
|
+
|
1858
|
+
var $$es6$promise$polyfill$$default = function polyfill() {
|
1859
|
+
var local;
|
1860
|
+
|
1861
|
+
if (typeof global !== 'undefined') {
|
1862
|
+
local = global;
|
1863
|
+
} else if (typeof window !== 'undefined' && window.document) {
|
1864
|
+
local = window;
|
1865
|
+
} else {
|
1866
|
+
local = self;
|
1867
|
+
}
|
1868
|
+
|
1869
|
+
var es6PromiseSupport =
|
1870
|
+
"Promise" in local &&
|
1871
|
+
// Some of these methods are missing from
|
1872
|
+
// Firefox/Chrome experimental implementations
|
1873
|
+
"resolve" in local.Promise &&
|
1874
|
+
"reject" in local.Promise &&
|
1875
|
+
"all" in local.Promise &&
|
1876
|
+
"race" in local.Promise &&
|
1877
|
+
// Older version of the spec had a resolver object
|
1878
|
+
// as the arg rather than a function
|
1879
|
+
(function() {
|
1880
|
+
var resolve;
|
1881
|
+
new local.Promise(function(r) { resolve = r; });
|
1882
|
+
return $$utils$$isFunction(resolve);
|
1883
|
+
}());
|
1884
|
+
|
1885
|
+
if (!es6PromiseSupport) {
|
1886
|
+
local.Promise = $$es6$promise$promise$$default;
|
1887
|
+
}
|
1888
|
+
};
|
1889
|
+
|
1890
|
+
var es6$promise$umd$$ES6Promise = {
|
1891
|
+
'Promise': $$es6$promise$promise$$default,
|
1892
|
+
'polyfill': $$es6$promise$polyfill$$default
|
1893
|
+
};
|
1894
|
+
|
1895
|
+
/* global define:true module:true window: true */
|
1896
|
+
if (typeof define === 'function' && define['amd']) {
|
1897
|
+
define(function() { return es6$promise$umd$$ES6Promise; });
|
1898
|
+
} else if (typeof module !== 'undefined' && module['exports']) {
|
1899
|
+
module['exports'] = es6$promise$umd$$ES6Promise;
|
1900
|
+
} else if (typeof this !== 'undefined') {
|
1901
|
+
this['ES6Promise'] = es6$promise$umd$$ES6Promise;
|
1902
|
+
}
|
1903
|
+
}).call(this);
|
1904
|
+
}).call(this,require(1),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
1905
|
+
},{"1":1}],9:[function(require,module,exports){
|
1906
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
1907
|
+
var toString = Object.prototype.toString;
|
1908
|
+
var undefined;
|
1909
|
+
|
1910
|
+
var isArray = require(10);
|
1911
|
+
|
1912
|
+
var isPlainObject = function isPlainObject(obj) {
|
1913
|
+
'use strict';
|
1914
|
+
if (!obj || toString.call(obj) !== '[object Object]') {
|
1915
|
+
return false;
|
1916
|
+
}
|
1917
|
+
|
1918
|
+
var has_own_constructor = hasOwn.call(obj, 'constructor');
|
1919
|
+
var has_is_property_of_method = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, 'isPrototypeOf');
|
1920
|
+
// Not own constructor property must be Object
|
1921
|
+
if (obj.constructor && !has_own_constructor && !has_is_property_of_method) {
|
1922
|
+
return false;
|
1923
|
+
}
|
1924
|
+
|
1925
|
+
// Own properties are enumerated firstly, so to speed up,
|
1926
|
+
// if last one is own, then all properties are own.
|
1927
|
+
var key;
|
1928
|
+
for (key in obj) {}
|
1929
|
+
|
1930
|
+
return key === undefined || hasOwn.call(obj, key);
|
1931
|
+
};
|
1932
|
+
|
1933
|
+
module.exports = function extend() {
|
1934
|
+
'use strict';
|
1935
|
+
var options, name, src, copy, copyIsArray, clone,
|
1936
|
+
target = arguments[0],
|
1937
|
+
i = 1,
|
1938
|
+
length = arguments.length,
|
1939
|
+
deep = false;
|
1940
|
+
|
1941
|
+
// Handle a deep copy situation
|
1942
|
+
if (typeof target === 'boolean') {
|
1943
|
+
deep = target;
|
1944
|
+
target = arguments[1] || {};
|
1945
|
+
// skip the boolean and the target
|
1946
|
+
i = 2;
|
1947
|
+
} else if ((typeof target !== 'object' && typeof target !== 'function') || target == null) {
|
1948
|
+
target = {};
|
1949
|
+
}
|
1950
|
+
|
1951
|
+
for (; i < length; ++i) {
|
1952
|
+
options = arguments[i];
|
1953
|
+
// Only deal with non-null/undefined values
|
1954
|
+
if (options != null) {
|
1955
|
+
// Extend the base object
|
1956
|
+
for (name in options) {
|
1957
|
+
src = target[name];
|
1958
|
+
copy = options[name];
|
1959
|
+
|
1960
|
+
// Prevent never-ending loop
|
1961
|
+
if (target === copy) {
|
1962
|
+
continue;
|
1963
|
+
}
|
1964
|
+
|
1965
|
+
// Recurse if we're merging plain objects or arrays
|
1966
|
+
if (deep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) {
|
1967
|
+
if (copyIsArray) {
|
1968
|
+
copyIsArray = false;
|
1969
|
+
clone = src && isArray(src) ? src : [];
|
1970
|
+
} else {
|
1971
|
+
clone = src && isPlainObject(src) ? src : {};
|
1972
|
+
}
|
1973
|
+
|
1974
|
+
// Never move original objects, clone them
|
1975
|
+
target[name] = extend(deep, clone, copy);
|
1976
|
+
|
1977
|
+
// Don't bring in undefined values
|
1978
|
+
} else if (copy !== undefined) {
|
1979
|
+
target[name] = copy;
|
1980
|
+
}
|
1981
|
+
}
|
1982
|
+
}
|
1983
|
+
}
|
1984
|
+
|
1985
|
+
// Return the modified object
|
1986
|
+
return target;
|
1987
|
+
};
|
1988
|
+
|
1989
|
+
|
1990
|
+
},{"10":10}],10:[function(require,module,exports){
|
1991
|
+
module.exports = Array.isArray || function (arr) {
|
1992
|
+
return Object.prototype.toString.call(arr) == '[object Array]';
|
1993
|
+
};
|
1994
|
+
|
1995
|
+
},{}],11:[function(require,module,exports){
|
1996
|
+
|
1997
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
1998
|
+
var toString = Object.prototype.toString;
|
1999
|
+
|
2000
|
+
module.exports = function forEach (obj, fn, ctx) {
|
2001
|
+
if (toString.call(fn) !== '[object Function]') {
|
2002
|
+
throw new TypeError('iterator must be a function');
|
2003
|
+
}
|
2004
|
+
var l = obj.length;
|
2005
|
+
if (l === +l) {
|
2006
|
+
for (var i = 0; i < l; i++) {
|
2007
|
+
fn.call(ctx, obj[i], i, obj);
|
2008
|
+
}
|
2009
|
+
} else {
|
2010
|
+
for (var k in obj) {
|
2011
|
+
if (hasOwn.call(obj, k)) {
|
2012
|
+
fn.call(ctx, obj[k], k, obj);
|
2013
|
+
}
|
2014
|
+
}
|
2015
|
+
}
|
2016
|
+
};
|
2017
|
+
|
2018
|
+
|
2019
|
+
},{}],12:[function(require,module,exports){
|
2020
|
+
if (typeof Object.create === 'function') {
|
2021
|
+
// implementation from standard node.js 'util' module
|
2022
|
+
module.exports = function inherits(ctor, superCtor) {
|
2023
|
+
ctor.super_ = superCtor
|
2024
|
+
ctor.prototype = Object.create(superCtor.prototype, {
|
2025
|
+
constructor: {
|
2026
|
+
value: ctor,
|
2027
|
+
enumerable: false,
|
2028
|
+
writable: true,
|
2029
|
+
configurable: true
|
2030
|
+
}
|
2031
|
+
});
|
2032
|
+
};
|
2033
|
+
} else {
|
2034
|
+
// old school shim for old browsers
|
2035
|
+
module.exports = function inherits(ctor, superCtor) {
|
2036
|
+
ctor.super_ = superCtor
|
2037
|
+
var TempCtor = function () {}
|
2038
|
+
TempCtor.prototype = superCtor.prototype
|
2039
|
+
ctor.prototype = new TempCtor()
|
2040
|
+
ctor.prototype.constructor = ctor
|
2041
|
+
}
|
2042
|
+
}
|
2043
|
+
|
2044
|
+
},{}],13:[function(require,module,exports){
|
263
2045
|
(function (process){
|
264
2046
|
module.exports = AlgoliaSearch;
|
265
2047
|
|
2048
|
+
// default debug activated in dev environments
|
2049
|
+
// this is triggered in package.json, using the envify transform
|
2050
|
+
if (process.env.NODE_ENV === 'development') {
|
2051
|
+
require(5).enable('algoliasearch*');
|
2052
|
+
}
|
2053
|
+
|
2054
|
+
var debug = require(5)('algoliasearch');
|
2055
|
+
var foreach = require(11);
|
2056
|
+
|
266
2057
|
/*
|
267
2058
|
* Algolia Search library initialization
|
268
2059
|
* https://www.algolia.com/
|
@@ -274,74 +2065,80 @@ module.exports = AlgoliaSearch;
|
|
274
2065
|
* @param {string} [opts.protocol='http:'] - The protocol used to query Algolia Search API.
|
275
2066
|
* Set to 'https:' to force using https. Default to document.location.protocol in browsers
|
276
2067
|
* @param {string[]} [opts.hosts=[
|
277
|
-
* this.applicationID + '-1.
|
278
|
-
* this.applicationID + '-2.
|
279
|
-
* this.applicationID + '-3.
|
280
|
-
* ] - The hosts to use for Algolia Search API.
|
281
|
-
* @param {string} [opts.tld='net'] - The tld to use when computing hosts default list
|
2068
|
+
* this.applicationID + '-1.algolianet.com',
|
2069
|
+
* this.applicationID + '-2.algolianet.com',
|
2070
|
+
* this.applicationID + '-3.algolianet.com']
|
2071
|
+
* ] - The hosts to use for Algolia Search API. If you provide them, you will no more benefit from our HA implementation
|
282
2072
|
*/
|
283
|
-
function AlgoliaSearch(applicationID, apiKey, opts
|
2073
|
+
function AlgoliaSearch(applicationID, apiKey, opts) {
|
2074
|
+
var extend = require(9);
|
2075
|
+
|
284
2076
|
var usage = 'Usage: algoliasearch(applicationID, apiKey, opts)';
|
285
2077
|
|
286
2078
|
if (!applicationID) {
|
287
|
-
throw new Error('Please provide an application ID. ' + usage);
|
2079
|
+
throw new Error('algoliasearch: Please provide an application ID. ' + usage);
|
288
2080
|
}
|
289
2081
|
|
290
2082
|
if (!apiKey) {
|
291
|
-
throw new Error('Please provide an API key. ' + usage);
|
2083
|
+
throw new Error('algoliasearch: Please provide an API key. ' + usage);
|
292
2084
|
}
|
293
2085
|
|
294
|
-
|
2086
|
+
this.applicationID = applicationID;
|
2087
|
+
this.apiKey = apiKey;
|
295
2088
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
2089
|
+
var defaultHosts = [
|
2090
|
+
this.applicationID + '-1.algolianet.com',
|
2091
|
+
this.applicationID + '-2.algolianet.com',
|
2092
|
+
this.applicationID + '-3.algolianet.com'
|
2093
|
+
];
|
2094
|
+
this.hosts = {
|
2095
|
+
read: [],
|
2096
|
+
write: []
|
2097
|
+
};
|
301
2098
|
|
302
|
-
|
303
|
-
|
304
|
-
|
2099
|
+
this.hostIndex = {
|
2100
|
+
read: 0,
|
2101
|
+
write: 0
|
2102
|
+
};
|
305
2103
|
|
306
|
-
|
307
|
-
opts.hosts = []; // filled later on, has dependencies
|
308
|
-
}
|
2104
|
+
opts = opts || {};
|
309
2105
|
|
310
|
-
|
311
|
-
|
312
|
-
}
|
2106
|
+
var protocol = opts.protocol || 'https:';
|
2107
|
+
var timeout = opts.timeout === undefined ? 2000 : opts.timeout;
|
313
2108
|
|
314
2109
|
// while we advocate for colon-at-the-end values: 'http:' for `opts.protocol`
|
315
2110
|
// we also accept `http` and `https`. It's a common error.
|
316
|
-
if (!/:$/.test(
|
317
|
-
|
2111
|
+
if (!/:$/.test(protocol)) {
|
2112
|
+
protocol = protocol + ':';
|
318
2113
|
}
|
319
2114
|
|
320
|
-
|
321
|
-
|
322
|
-
opts.hosts = shuffle([
|
323
|
-
applicationID + '-1.algolia.' + opts.tld,
|
324
|
-
applicationID + '-2.algolia.' + opts.tld,
|
325
|
-
applicationID + '-3.algolia.' + opts.tld
|
326
|
-
]);
|
327
|
-
|
328
|
-
// add default dsn host
|
329
|
-
opts.hosts.unshift(applicationID + '-dsn.algolia.' + opts.tld);
|
2115
|
+
if (opts.protocol !== 'http:' && opts.protocol !== 'https:') {
|
2116
|
+
throw new Error('algoliasearch: protocol must be `http:` or `https:` (was `' + opts.protocol + '`)');
|
330
2117
|
}
|
331
2118
|
|
332
|
-
|
333
|
-
|
334
|
-
|
2119
|
+
// no hosts given, add defaults
|
2120
|
+
if (!opts.hosts) {
|
2121
|
+
this.hosts.read = [this.applicationID + '-dsn.algolia.net'].concat(defaultHosts);
|
2122
|
+
this.hosts.write = [this.applicationID + '.algolia.net'].concat(defaultHosts);
|
2123
|
+
} else {
|
2124
|
+
this.hosts.read = extend([], opts.hosts);
|
2125
|
+
this.hosts.write = extend([], opts.hosts);
|
2126
|
+
}
|
335
2127
|
|
336
|
-
|
337
|
-
this.
|
338
|
-
this.hosts =
|
2128
|
+
// add protocol and lowercase hosts
|
2129
|
+
this.hosts.read = map(this.hosts.read, prepareHost(protocol));
|
2130
|
+
this.hosts.write = map(this.hosts.write, prepareHost(protocol));
|
2131
|
+
this.requestTimeout = timeout;
|
339
2132
|
|
340
|
-
this.currentHostIndex = 0;
|
341
|
-
this.requestTimeout = opts.timeout;
|
342
2133
|
this.extraHeaders = [];
|
343
2134
|
this.cache = {};
|
344
|
-
|
2135
|
+
|
2136
|
+
this._ua = opts._ua;
|
2137
|
+
this._useCache = opts._useCache === undefined ? true : opts._useCache;
|
2138
|
+
|
2139
|
+
this._setTimeout = opts._setTimeout;
|
2140
|
+
|
2141
|
+
debug('init done, %j', this);
|
345
2142
|
}
|
346
2143
|
|
347
2144
|
AlgoliaSearch.prototype = {
|
@@ -349,20 +2146,21 @@ AlgoliaSearch.prototype = {
|
|
349
2146
|
* Delete an index
|
350
2147
|
*
|
351
2148
|
* @param indexName the name of index to delete
|
352
|
-
* @param callback the result callback with two arguments
|
2149
|
+
* @param callback the result callback called with two arguments
|
353
2150
|
* error: null or Error('message')
|
354
2151
|
* content: the server answer that contains the task ID
|
355
2152
|
*/
|
356
2153
|
deleteIndex: function(indexName, callback) {
|
357
2154
|
return this._jsonRequest({ method: 'DELETE',
|
358
2155
|
url: '/1/indexes/' + encodeURIComponent(indexName),
|
2156
|
+
hostType: 'write',
|
359
2157
|
callback: callback });
|
360
2158
|
},
|
361
2159
|
/**
|
362
2160
|
* Move an existing index.
|
363
2161
|
* @param srcIndexName the name of index to copy.
|
364
2162
|
* @param dstIndexName the new index name that will contains a copy of srcIndexName (destination will be overriten if it already exist).
|
365
|
-
* @param callback the result callback with two arguments
|
2163
|
+
* @param callback the result callback called with two arguments
|
366
2164
|
* error: null or Error('message')
|
367
2165
|
* content: the server answer that contains the task ID
|
368
2166
|
*/
|
@@ -371,6 +2169,7 @@ AlgoliaSearch.prototype = {
|
|
371
2169
|
return this._jsonRequest({ method: 'POST',
|
372
2170
|
url: '/1/indexes/' + encodeURIComponent(srcIndexName) + '/operation',
|
373
2171
|
body: postObj,
|
2172
|
+
hostType: 'write',
|
374
2173
|
callback: callback });
|
375
2174
|
|
376
2175
|
},
|
@@ -378,7 +2177,7 @@ AlgoliaSearch.prototype = {
|
|
378
2177
|
* Copy an existing index.
|
379
2178
|
* @param srcIndexName the name of index to copy.
|
380
2179
|
* @param dstIndexName the new index name that will contains a copy of srcIndexName (destination will be overriten if it already exist).
|
381
|
-
* @param callback the result callback with two arguments
|
2180
|
+
* @param callback the result callback called with two arguments
|
382
2181
|
* error: null or Error('message')
|
383
2182
|
* content: the server answer that contains the task ID
|
384
2183
|
*/
|
@@ -387,13 +2186,14 @@ AlgoliaSearch.prototype = {
|
|
387
2186
|
return this._jsonRequest({ method: 'POST',
|
388
2187
|
url: '/1/indexes/' + encodeURIComponent(srcIndexName) + '/operation',
|
389
2188
|
body: postObj,
|
2189
|
+
hostType: 'write',
|
390
2190
|
callback: callback });
|
391
2191
|
},
|
392
2192
|
/**
|
393
2193
|
* Return last log entries.
|
394
2194
|
* @param offset Specify the first entry to retrieve (0-based, 0 is the most recent log entry).
|
395
2195
|
* @param length Specify the maximum number of entries to retrieve starting at offset. Maximum allowed value: 1000.
|
396
|
-
* @param callback the result callback with two arguments
|
2196
|
+
* @param callback the result callback called with two arguments
|
397
2197
|
* error: null or Error('message')
|
398
2198
|
* content: the server answer that contains the task ID
|
399
2199
|
*/
|
@@ -411,13 +2211,14 @@ AlgoliaSearch.prototype = {
|
|
411
2211
|
|
412
2212
|
return this._jsonRequest({ method: 'GET',
|
413
2213
|
url: '/1/logs?offset=' + offset + '&length=' + length,
|
2214
|
+
hostType: 'read',
|
414
2215
|
callback: callback });
|
415
2216
|
},
|
416
2217
|
/*
|
417
2218
|
* List all existing indexes (paginated)
|
418
2219
|
*
|
419
2220
|
* @param page The page to retrieve, starting at 0.
|
420
|
-
* @param callback the result callback with two arguments
|
2221
|
+
* @param callback the result callback called with two arguments
|
421
2222
|
* error: null or Error('message')
|
422
2223
|
* content: the server answer with index list
|
423
2224
|
*/
|
@@ -432,6 +2233,7 @@ AlgoliaSearch.prototype = {
|
|
432
2233
|
|
433
2234
|
return this._jsonRequest({ method: 'GET',
|
434
2235
|
url: '/1/indexes' + params,
|
2236
|
+
hostType: 'read',
|
435
2237
|
callback: callback });
|
436
2238
|
},
|
437
2239
|
|
@@ -447,90 +2249,142 @@ AlgoliaSearch.prototype = {
|
|
447
2249
|
/*
|
448
2250
|
* List all existing user keys with their associated ACLs
|
449
2251
|
*
|
450
|
-
* @param callback the result callback with two arguments
|
2252
|
+
* @param callback the result callback called with two arguments
|
451
2253
|
* error: null or Error('message')
|
452
2254
|
* content: the server answer with user keys list
|
453
2255
|
*/
|
454
2256
|
listUserKeys: function(callback) {
|
455
2257
|
return this._jsonRequest({ method: 'GET',
|
456
2258
|
url: '/1/keys',
|
2259
|
+
hostType: 'read',
|
457
2260
|
callback: callback });
|
458
2261
|
},
|
459
2262
|
/*
|
460
2263
|
* Get ACL of a user key
|
461
2264
|
*
|
462
2265
|
* @param key
|
463
|
-
* @param callback the result callback with two arguments
|
2266
|
+
* @param callback the result callback called with two arguments
|
464
2267
|
* error: null or Error('message')
|
465
2268
|
* content: the server answer with user keys list
|
466
2269
|
*/
|
467
2270
|
getUserKeyACL: function(key, callback) {
|
468
2271
|
return this._jsonRequest({ method: 'GET',
|
469
2272
|
url: '/1/keys/' + key,
|
2273
|
+
hostType: 'read',
|
470
2274
|
callback: callback });
|
471
2275
|
},
|
472
2276
|
/*
|
473
2277
|
* Delete an existing user key
|
474
2278
|
* @param key
|
475
|
-
* @param callback the result callback with two arguments
|
2279
|
+
* @param callback the result callback called with two arguments
|
476
2280
|
* error: null or Error('message')
|
477
2281
|
* content: the server answer with user keys list
|
478
2282
|
*/
|
479
2283
|
deleteUserKey: function(key, callback) {
|
480
2284
|
return this._jsonRequest({ method: 'DELETE',
|
481
2285
|
url: '/1/keys/' + key,
|
2286
|
+
hostType: 'write',
|
482
2287
|
callback: callback });
|
483
2288
|
},
|
484
2289
|
/*
|
485
2290
|
* Add an existing user key
|
486
2291
|
*
|
487
|
-
* @param acls
|
488
|
-
*
|
489
|
-
*
|
490
|
-
*
|
491
|
-
*
|
492
|
-
*
|
493
|
-
*
|
494
|
-
*
|
495
|
-
* @param
|
496
|
-
*
|
497
|
-
*
|
2292
|
+
* @param {string[]} acls - The list of ACL for this key. Defined by an array of strings that
|
2293
|
+
* can contains the following values:
|
2294
|
+
* - search: allow to search (https and http)
|
2295
|
+
* - addObject: allows to add/update an object in the index (https only)
|
2296
|
+
* - deleteObject : allows to delete an existing object (https only)
|
2297
|
+
* - deleteIndex : allows to delete index content (https only)
|
2298
|
+
* - settings : allows to get index settings (https only)
|
2299
|
+
* - editSettings : allows to change index settings (https only)
|
2300
|
+
* @param {Object} [params] - Optionnal parameters to set for the key
|
2301
|
+
* @param {number} params.validity - Number of seconds after which the key will be automatically removed (0 means no time limit for this key)
|
2302
|
+
* @param {number} params.maxQueriesPerIPPerHour - Number of API calls allowed from an IP address per hour
|
2303
|
+
* @param {number} params.maxHitsPerQuery - Number of hits this API key can retrieve in one call
|
2304
|
+
* @param {string[]} params.indexes - Allowed targeted indexes for this key
|
2305
|
+
* @param {Function} callback - The result callback called with two arguments
|
2306
|
+
* error: null or Error('message')
|
2307
|
+
* content: the server answer with user keys list
|
2308
|
+
* @return {Promise|undefined} Returns a promise if no callback given
|
498
2309
|
*/
|
499
|
-
addUserKey: function(acls, callback) {
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
2310
|
+
addUserKey: function(acls, params, callback) {
|
2311
|
+
if (arguments.length === 1 || typeof params === 'function') {
|
2312
|
+
callback = params;
|
2313
|
+
params = null;
|
2314
|
+
}
|
2315
|
+
|
2316
|
+
var postObj = {
|
2317
|
+
acl: acls
|
2318
|
+
};
|
2319
|
+
|
2320
|
+
if (params) {
|
2321
|
+
postObj.validity = params.validity;
|
2322
|
+
postObj.maxQueriesPerIPPerHour = params.maxQueriesPerIPPerHour;
|
2323
|
+
postObj.maxHitsPerQuery = params.maxHitsPerQuery;
|
2324
|
+
postObj.indexes = params.indexes;
|
2325
|
+
}
|
2326
|
+
|
2327
|
+
return this._jsonRequest({
|
2328
|
+
method: 'POST',
|
2329
|
+
url: '/1/keys',
|
2330
|
+
body: postObj,
|
2331
|
+
hostType: 'write',
|
2332
|
+
callback: callback
|
2333
|
+
});
|
505
2334
|
},
|
506
|
-
|
2335
|
+
/**
|
507
2336
|
* Add an existing user key
|
508
|
-
*
|
509
|
-
* @param acls the list of ACL for this key. Defined by an array of strings that
|
510
|
-
* can contains the following values:
|
511
|
-
* - search: allow to search (https and http)
|
512
|
-
* - addObject: allows to add/update an object in the index (https only)
|
513
|
-
* - deleteObject : allows to delete an existing object (https only)
|
514
|
-
* - deleteIndex : allows to delete index content (https only)
|
515
|
-
* - settings : allows to get index settings (https only)
|
516
|
-
* - editSettings : allows to change index settings (https only)
|
517
|
-
* @param params.validity the number of seconds after which the key will be automatically removed (0 means no time limit for this key)
|
518
|
-
* @param params.maxQueriesPerIPPerHour Specify the maximum number of API calls allowed from an IP address per hour.
|
519
|
-
* @param params.maxHitsPerQuery Specify the maximum number of hits this API key can retrieve in one call.
|
520
|
-
* @param callback the result callback with two arguments
|
521
|
-
* error: null or Error('message')
|
522
|
-
* content: the server answer with user keys list
|
2337
|
+
* @deprecated Please use client.addUserKey()
|
523
2338
|
*/
|
524
|
-
addUserKeyWithValidity: function(acls, params, callback) {
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
2339
|
+
addUserKeyWithValidity: deprecate(function(acls, params, callback) {
|
2340
|
+
return this.addUserKey(acls, params, callback);
|
2341
|
+
}, deprecatedMessage('client.addUserKeyWithValidity()', 'client.addUserKey()')),
|
2342
|
+
|
2343
|
+
/**
|
2344
|
+
* Update an existing user key
|
2345
|
+
* @param {string} key - The key to update
|
2346
|
+
* @param {string[]} acls - The list of ACL for this key. Defined by an array of strings that
|
2347
|
+
* can contains the following values:
|
2348
|
+
* - search: allow to search (https and http)
|
2349
|
+
* - addObject: allows to add/update an object in the index (https only)
|
2350
|
+
* - deleteObject : allows to delete an existing object (https only)
|
2351
|
+
* - deleteIndex : allows to delete index content (https only)
|
2352
|
+
* - settings : allows to get index settings (https only)
|
2353
|
+
* - editSettings : allows to change index settings (https only)
|
2354
|
+
* @param {Object} [params] - Optionnal parameters to set for the key
|
2355
|
+
* @param {number} params.validity - Number of seconds after which the key will be automatically removed (0 means no time limit for this key)
|
2356
|
+
* @param {number} params.maxQueriesPerIPPerHour - Number of API calls allowed from an IP address per hour
|
2357
|
+
* @param {number} params.maxHitsPerQuery - Number of hits this API key can retrieve in one call
|
2358
|
+
* @param {string[]} params.indexes - Allowed targeted indexes for this key
|
2359
|
+
* @param {Function} callback - The result callback called with two arguments
|
2360
|
+
* error: null or Error('message')
|
2361
|
+
* content: the server answer with user keys list
|
2362
|
+
* @return {Promise|undefined} Returns a promise if no callback given
|
2363
|
+
*/
|
2364
|
+
updateUserKey: function(key, acls, params, callback) {
|
2365
|
+
if (arguments.length === 2 || typeof params === 'function') {
|
2366
|
+
callback = params;
|
2367
|
+
params = null;
|
2368
|
+
}
|
2369
|
+
|
2370
|
+
var putObj = {
|
2371
|
+
acl: acls
|
2372
|
+
};
|
2373
|
+
|
2374
|
+
if (params) {
|
2375
|
+
putObj.validity = params.validity;
|
2376
|
+
putObj.maxQueriesPerIPPerHour = params.maxQueriesPerIPPerHour;
|
2377
|
+
putObj.maxHitsPerQuery = params.maxHitsPerQuery;
|
2378
|
+
putObj.indexes = params.indexes;
|
2379
|
+
}
|
2380
|
+
|
2381
|
+
return this._jsonRequest({
|
2382
|
+
method: 'PUT',
|
2383
|
+
url: '/1/keys/' + key,
|
2384
|
+
body: putObj,
|
2385
|
+
hostType: 'write',
|
2386
|
+
callback: callback
|
2387
|
+
});
|
534
2388
|
},
|
535
2389
|
|
536
2390
|
/**
|
@@ -553,7 +2407,8 @@ AlgoliaSearch.prototype = {
|
|
553
2407
|
}
|
554
2408
|
tags = strTags.join(',');
|
555
2409
|
}
|
556
|
-
|
2410
|
+
|
2411
|
+
this.securityTags = tags;
|
557
2412
|
},
|
558
2413
|
|
559
2414
|
/**
|
@@ -564,59 +2419,41 @@ AlgoliaSearch.prototype = {
|
|
564
2419
|
this.userToken = userToken;
|
565
2420
|
},
|
566
2421
|
|
567
|
-
|
2422
|
+
/**
|
568
2423
|
* Initialize a new batch of search queries
|
2424
|
+
* @deprecated use client.search()
|
569
2425
|
*/
|
570
|
-
startQueriesBatch: function() {
|
571
|
-
this.
|
572
|
-
},
|
573
|
-
|
2426
|
+
startQueriesBatch: deprecate(function() {
|
2427
|
+
this._batch = [];
|
2428
|
+
}, deprecatedMessage('client.startQueriesBatch()', 'client.search()')),
|
2429
|
+
|
2430
|
+
/**
|
574
2431
|
* Add a search query in the batch
|
575
|
-
*
|
576
|
-
* @param query the full text query
|
577
|
-
* @param args (optional) if set, contains an object with query parameters:
|
578
|
-
* - attributes: an array of object attribute names to retrieve
|
579
|
-
* (if not set all attributes are retrieve)
|
580
|
-
* - attributesToHighlight: an array of object attribute names to highlight
|
581
|
-
* (if not set indexed attributes are highlighted)
|
582
|
-
* - minWordSizefor1Typo: the minimum number of characters to accept one typo.
|
583
|
-
* Defaults to 3.
|
584
|
-
* - minWordSizefor2Typos: the minimum number of characters to accept two typos.
|
585
|
-
* Defaults to 7.
|
586
|
-
* - getRankingInfo: if set, the result hits will contain ranking information in
|
587
|
-
* _rankingInfo attribute
|
588
|
-
* - page: (pagination parameter) page to retrieve (zero base). Defaults to 0.
|
589
|
-
* - hitsPerPage: (pagination parameter) number of hits per page. Defaults to 10.
|
2432
|
+
* @deprecated use client.search()
|
590
2433
|
*/
|
591
|
-
addQueryInBatch: function(indexName, query, args) {
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
},
|
598
|
-
|
599
|
-
|
2434
|
+
addQueryInBatch: deprecate(function(indexName, query, args) {
|
2435
|
+
this._batch.push({
|
2436
|
+
indexName: indexName,
|
2437
|
+
query: query,
|
2438
|
+
params: args
|
2439
|
+
});
|
2440
|
+
}, deprecatedMessage('client.addQueryInBatch()', 'client.search()')),
|
2441
|
+
|
2442
|
+
/**
|
2443
|
+
* Clear all queries in client's cache
|
2444
|
+
* @return undefined
|
600
2445
|
*/
|
601
2446
|
clearCache: function() {
|
602
2447
|
this.cache = {};
|
603
2448
|
},
|
604
|
-
|
2449
|
+
|
2450
|
+
/**
|
605
2451
|
* Launch the batch of queries using XMLHttpRequest.
|
606
|
-
*
|
607
|
-
*
|
608
|
-
* @param callback the function that will receive results
|
2452
|
+
* @deprecated use client.search()
|
609
2453
|
*/
|
610
|
-
sendQueriesBatch: function(callback) {
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
for (var i = 0; i < as.batch.length; ++i) {
|
615
|
-
params.requests.push(as.batch[i]);
|
616
|
-
}
|
617
|
-
|
618
|
-
return this._sendQueriesBatch(params, callback);
|
619
|
-
},
|
2454
|
+
sendQueriesBatch: deprecate(function(callback) {
|
2455
|
+
return this.search(this._batch, callback);
|
2456
|
+
}, deprecatedMessage('client.sendQueriesBatch()', 'client.search()')),
|
620
2457
|
|
621
2458
|
/**
|
622
2459
|
* Set the number of milliseconds a request can take before automatically being terminated.
|
@@ -629,6 +2466,53 @@ AlgoliaSearch.prototype = {
|
|
629
2466
|
}
|
630
2467
|
},
|
631
2468
|
|
2469
|
+
/**
|
2470
|
+
* Search through multiple indices at the same time
|
2471
|
+
* @param {Object[]} queries An array of queries you want to run.
|
2472
|
+
* @param {string} queries[].indexName The index name you want to target
|
2473
|
+
* @param {string} [queries[].query] The query to issue on this index. Can also be passed into `params`
|
2474
|
+
* @param {Object} queries[].params Any search param like hitsPerPage, ..
|
2475
|
+
* @param {Function} callback Callback to be called
|
2476
|
+
* @return {Promise|undefined} Returns a promise if no callback given
|
2477
|
+
*/
|
2478
|
+
search: function(queries, callback) {
|
2479
|
+
var client = this;
|
2480
|
+
|
2481
|
+
var postObj = {
|
2482
|
+
requests: map(queries, function prepareRequest(query) {
|
2483
|
+
var params = '';
|
2484
|
+
|
2485
|
+
// allow query.query
|
2486
|
+
// so we are mimicing the index.search(query, params) method
|
2487
|
+
// {indexName:, query:, params:}
|
2488
|
+
if (query.query !== undefined) {
|
2489
|
+
params += 'query=' + encodeURIComponent(query.query)
|
2490
|
+
}
|
2491
|
+
|
2492
|
+
return {
|
2493
|
+
indexName: query.indexName,
|
2494
|
+
params: client._getSearchParams(query.params, params)
|
2495
|
+
};
|
2496
|
+
})
|
2497
|
+
};
|
2498
|
+
|
2499
|
+
return this._jsonRequest({
|
2500
|
+
cache: this.cache,
|
2501
|
+
method: 'POST',
|
2502
|
+
url: '/1/indexes/*/queries',
|
2503
|
+
body: postObj,
|
2504
|
+
hostType: 'read',
|
2505
|
+
callback: callback
|
2506
|
+
});
|
2507
|
+
},
|
2508
|
+
|
2509
|
+
// environment specific methods
|
2510
|
+
destroy: notImplemented,
|
2511
|
+
enableRateLimitForward: notImplemented,
|
2512
|
+
disableRateLimitForward: notImplemented,
|
2513
|
+
useSecuredAPIKey: notImplemented,
|
2514
|
+
disableSecuredAPIKey: notImplemented,
|
2515
|
+
generateSecuredApiKey: notImplemented,
|
632
2516
|
/*
|
633
2517
|
* Index class constructor.
|
634
2518
|
* You should not use this method directly but use initIndex() function
|
@@ -645,11 +2529,11 @@ AlgoliaSearch.prototype = {
|
|
645
2529
|
/**
|
646
2530
|
* Add an extra field to the HTTP request
|
647
2531
|
*
|
648
|
-
* @param
|
2532
|
+
* @param name the header field name
|
649
2533
|
* @param value the header field value
|
650
2534
|
*/
|
651
|
-
setExtraHeader: function(
|
652
|
-
this.extraHeaders.push({
|
2535
|
+
setExtraHeader: function(name, value) {
|
2536
|
+
this.extraHeaders.push({ name: name.toLowerCase(), value: value});
|
653
2537
|
},
|
654
2538
|
|
655
2539
|
_sendQueriesBatch: function(params, callback) {
|
@@ -657,6 +2541,7 @@ AlgoliaSearch.prototype = {
|
|
657
2541
|
method: 'POST',
|
658
2542
|
url: '/1/indexes/*/queries',
|
659
2543
|
body: params,
|
2544
|
+
hostType: 'read',
|
660
2545
|
fallback: {
|
661
2546
|
method: 'GET',
|
662
2547
|
url: '/1/indexes/*',
|
@@ -676,77 +2561,88 @@ AlgoliaSearch.prototype = {
|
|
676
2561
|
* Wrapper that try all hosts to maximize the quality of service
|
677
2562
|
*/
|
678
2563
|
_jsonRequest: function(opts) {
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
// if fallback used and no more tries, return error
|
683
|
-
// fallback parameters are in opts.fallback
|
684
|
-
// call request.fallback or request accordingly, same promise chain otherwise
|
685
|
-
// put callback& params in front if problem
|
2564
|
+
var requestDebug = require(5)('algoliasearch:' + opts.url);
|
2565
|
+
|
2566
|
+
var body;
|
686
2567
|
var cache = opts.cache;
|
687
|
-
var cacheID = opts.url;
|
688
2568
|
var client = this;
|
689
2569
|
var tries = 0;
|
2570
|
+
var usingFallback = false;
|
690
2571
|
|
691
|
-
// as we use POST requests to pass parameters (like query='aa'),
|
692
|
-
// the cacheID must be different between calls
|
693
2572
|
if (opts.body !== undefined) {
|
694
|
-
|
2573
|
+
body = JSON.stringify(opts.body);
|
695
2574
|
}
|
696
2575
|
|
2576
|
+
requestDebug('request start');
|
2577
|
+
|
697
2578
|
function doRequest(requester, reqOpts) {
|
2579
|
+
var cacheID;
|
2580
|
+
|
2581
|
+
if (client._useCache) {
|
2582
|
+
cacheID = opts.url;
|
2583
|
+
}
|
2584
|
+
|
2585
|
+
// as we sometime use POST requests to pass parameters (like query='aa'),
|
2586
|
+
// the cacheID must also include the body to be different between calls
|
2587
|
+
if (client._useCache && body) {
|
2588
|
+
cacheID += '_body_' + reqOpts.body;
|
2589
|
+
}
|
2590
|
+
|
698
2591
|
// handle cache existence
|
699
|
-
if (cache && cache[cacheID] !== undefined) {
|
700
|
-
|
2592
|
+
if (client._useCache && cache && cache[cacheID] !== undefined) {
|
2593
|
+
requestDebug('serving response from cache');
|
2594
|
+
return client._promise.resolve(cache[cacheID]);
|
701
2595
|
}
|
702
2596
|
|
703
|
-
if (tries >= client.hosts.length) {
|
704
|
-
if (!opts.fallback ||
|
2597
|
+
if (tries >= client.hosts[opts.hostType].length) {
|
2598
|
+
if (!opts.fallback || !client._request.fallback || usingFallback) {
|
705
2599
|
// could not get a response even using the fallback if one was available
|
706
|
-
return client.
|
2600
|
+
return client._promise.reject(new Error(
|
707
2601
|
'Cannot connect to the AlgoliaSearch API.' +
|
708
2602
|
' Send an email to support@algolia.com to report and resolve the issue.'
|
709
2603
|
));
|
710
2604
|
}
|
711
2605
|
|
2606
|
+
// let's try the fallback starting from here
|
712
2607
|
tries = 0;
|
2608
|
+
|
2609
|
+
// method, url and body are fallback dependent
|
713
2610
|
reqOpts.method = opts.fallback.method;
|
714
2611
|
reqOpts.url = opts.fallback.url;
|
715
|
-
reqOpts.
|
2612
|
+
reqOpts.jsonBody = opts.fallback.body;
|
2613
|
+
if (reqOpts.jsonBody) {
|
2614
|
+
reqOpts.body = JSON.stringify(opts.fallback.body);
|
2615
|
+
}
|
2616
|
+
|
716
2617
|
reqOpts.timeout = client.requestTimeout * (tries + 1);
|
717
|
-
client.
|
718
|
-
client.
|
2618
|
+
client.hostIndex[opts.hostType] = 0;
|
2619
|
+
client.useFallback = true; // now we will only use JSONP, even on future requests
|
2620
|
+
usingFallback = true; // the current request is now using fallback
|
719
2621
|
return doRequest(client._request.fallback, reqOpts);
|
720
2622
|
}
|
721
2623
|
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
for (var i = 0; i < client.extraHeaders.length; ++i) {
|
736
|
-
url += '&' + client.extraHeaders[i].key + '=' + client.extraHeaders[i].value;
|
737
|
-
}
|
738
|
-
|
739
|
-
return requester(client.hosts[client.currentHostIndex] + url, {
|
740
|
-
body: reqOpts.body,
|
741
|
-
method: reqOpts.method,
|
742
|
-
timeout: reqOpts.timeout
|
743
|
-
})
|
2624
|
+
// `requester` is any of this._request or this._request.fallback
|
2625
|
+
// thus it needs to be called using the client as context
|
2626
|
+
return requester.call(client,
|
2627
|
+
// http(s)://currenthost/url(?qs)
|
2628
|
+
client.hosts[opts.hostType][client.hostIndex[opts.hostType]] + reqOpts.url, {
|
2629
|
+
body: body,
|
2630
|
+
jsonBody: opts.body,
|
2631
|
+
method: reqOpts.method,
|
2632
|
+
headers: client._computeRequestHeaders(),
|
2633
|
+
timeout: reqOpts.timeout,
|
2634
|
+
debug: requestDebug
|
2635
|
+
}
|
2636
|
+
)
|
744
2637
|
.then(function success(httpResponse) {
|
745
2638
|
// timeout case, retry immediately
|
746
2639
|
if (httpResponse instanceof Error) {
|
2640
|
+
requestDebug('error: %s', httpResponse.message);
|
747
2641
|
return retryRequest();
|
748
2642
|
}
|
749
2643
|
|
2644
|
+
requestDebug('received response: %j', httpResponse);
|
2645
|
+
|
750
2646
|
var status =
|
751
2647
|
// When in browser mode, using XDR or JSONP
|
752
2648
|
// We rely on our own API response `status`, only
|
@@ -768,7 +2664,7 @@ AlgoliaSearch.prototype = {
|
|
768
2664
|
var ok = status === 200 || status === 201;
|
769
2665
|
var retry = !ok && Math.floor(status / 100) !== 4 && Math.floor(status / 100) !== 1;
|
770
2666
|
|
771
|
-
if (ok && cache) {
|
2667
|
+
if (client._useCache && ok && cache) {
|
772
2668
|
cache[cacheID] = httpResponse.body;
|
773
2669
|
}
|
774
2670
|
|
@@ -784,24 +2680,38 @@ AlgoliaSearch.prototype = {
|
|
784
2680
|
httpResponse.body && httpResponse.body.message || 'Unknown error'
|
785
2681
|
);
|
786
2682
|
|
787
|
-
return client.
|
2683
|
+
return client._promise.reject(unrecoverableError);
|
788
2684
|
}, tryFallback);
|
789
2685
|
|
790
2686
|
function retryRequest() {
|
791
|
-
client.
|
2687
|
+
client.hostIndex[opts.hostType] = ++client.hostIndex[opts.hostType] % client.hosts[opts.hostType].length;
|
792
2688
|
tries += 1;
|
793
2689
|
reqOpts.timeout = client.requestTimeout * (tries + 1);
|
794
2690
|
return doRequest(requester, reqOpts);
|
795
2691
|
}
|
796
2692
|
|
797
|
-
function tryFallback() {
|
2693
|
+
function tryFallback(err) {
|
2694
|
+
// error cases:
|
2695
|
+
// While not in fallback mode:
|
2696
|
+
// - CORS not supported
|
2697
|
+
// - network error
|
2698
|
+
// While in fallback mode:
|
2699
|
+
// - timeout
|
2700
|
+
// - network error
|
2701
|
+
// - badly formatted JSONP (script loaded, did not call our callback)
|
2702
|
+
// In both cases:
|
2703
|
+
// - uncaught exception occurs (TypeError)
|
2704
|
+
requestDebug('error: %s, stack: %s', err.message, err.stack);
|
2705
|
+
|
2706
|
+
// we were not using the fallback, try now
|
798
2707
|
// if we are switching to fallback right now, set tries to maximum
|
799
|
-
if (!client.
|
800
|
-
// next time doRequest is called, simulate we tried all hosts
|
801
|
-
|
2708
|
+
if (!client.useFallback) {
|
2709
|
+
// next time doRequest is called, simulate we tried all hosts,
|
2710
|
+
// this will force to use the fallback
|
2711
|
+
tries = client.hosts[opts.hostType].length;
|
802
2712
|
} else {
|
803
2713
|
// we were already using the fallback, but something went wrong (script error)
|
804
|
-
client.
|
2714
|
+
client.hostIndex[opts.hostType] = ++client.hostIndex[opts.hostType] % client.hosts[opts.hostType].length;
|
805
2715
|
tries += 1;
|
806
2716
|
}
|
807
2717
|
|
@@ -810,14 +2720,16 @@ AlgoliaSearch.prototype = {
|
|
810
2720
|
}
|
811
2721
|
|
812
2722
|
// we can use a fallback if forced AND fallback parameters are available
|
813
|
-
var useFallback = client.
|
2723
|
+
var useFallback = client.useFallback && opts.fallback;
|
814
2724
|
var requestOptions = useFallback ? opts.fallback : opts;
|
815
2725
|
|
816
2726
|
var promise = doRequest(
|
2727
|
+
// set the requester
|
817
2728
|
useFallback ? client._request.fallback : client._request, {
|
818
2729
|
url: requestOptions.url,
|
819
2730
|
method: requestOptions.method,
|
820
|
-
body:
|
2731
|
+
body: body,
|
2732
|
+
jsonBody: opts.body,
|
821
2733
|
timeout: client.requestTimeout * (tries + 1)
|
822
2734
|
}
|
823
2735
|
);
|
@@ -826,13 +2738,13 @@ AlgoliaSearch.prototype = {
|
|
826
2738
|
// either we are using promises
|
827
2739
|
if (opts.callback) {
|
828
2740
|
promise.then(function okCb(content) {
|
829
|
-
|
2741
|
+
exitPromise(function() {
|
830
2742
|
opts.callback(null, content);
|
831
|
-
});
|
2743
|
+
}, client._setTimeout || setTimeout);
|
832
2744
|
}, function nookCb(err) {
|
833
|
-
|
2745
|
+
exitPromise(function() {
|
834
2746
|
opts.callback(err);
|
835
|
-
});
|
2747
|
+
}, client._setTimeout || setTimeout);
|
836
2748
|
});
|
837
2749
|
} else {
|
838
2750
|
return promise;
|
@@ -854,8 +2766,33 @@ AlgoliaSearch.prototype = {
|
|
854
2766
|
}
|
855
2767
|
return params;
|
856
2768
|
},
|
2769
|
+
|
857
2770
|
_isUndefined: function(obj) {
|
858
2771
|
return obj === void 0;
|
2772
|
+
},
|
2773
|
+
|
2774
|
+
_computeRequestHeaders: function() {
|
2775
|
+
var requestHeaders = {
|
2776
|
+
'x-algolia-api-key': this.apiKey,
|
2777
|
+
'x-algolia-application-id': this.applicationID,
|
2778
|
+
'x-user-agent': this._ua
|
2779
|
+
};
|
2780
|
+
|
2781
|
+
if (this.userToken) {
|
2782
|
+
requestHeaders['x-algolia-usertoken'] = this.userToken;
|
2783
|
+
}
|
2784
|
+
|
2785
|
+
if (this.securityTags) {
|
2786
|
+
requestHeaders['x-algolia-tagfilters'] = this.securityTags;
|
2787
|
+
}
|
2788
|
+
|
2789
|
+
if (this.extraHeaders) {
|
2790
|
+
foreach(this.extraHeaders, function addToRequestHeaders(header) {
|
2791
|
+
requestHeaders[header.name] = header.value;
|
2792
|
+
});
|
2793
|
+
}
|
2794
|
+
|
2795
|
+
return requestHeaders;
|
859
2796
|
}
|
860
2797
|
};
|
861
2798
|
|
@@ -876,7 +2813,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
876
2813
|
* @param content contains the javascript object to add inside the index
|
877
2814
|
* @param objectID (optional) an objectID you want to attribute to this object
|
878
2815
|
* (if the attribute already exist the old object will be overwrite)
|
879
|
-
* @param callback (optional) the result callback with two arguments:
|
2816
|
+
* @param callback (optional) the result callback called with two arguments:
|
880
2817
|
* error: null or Error('message')
|
881
2818
|
* content: the server answer that contains 3 elements: createAt, taskId and objectID
|
882
2819
|
*/
|
@@ -895,6 +2832,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
895
2832
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + // create
|
896
2833
|
(objectID !== undefined ? '/' + encodeURIComponent(objectID) : ''), // update or create
|
897
2834
|
body: content,
|
2835
|
+
hostType: 'write',
|
898
2836
|
callback: callback
|
899
2837
|
});
|
900
2838
|
},
|
@@ -902,7 +2840,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
902
2840
|
* Add several objects
|
903
2841
|
*
|
904
2842
|
* @param objects contains an array of objects to add
|
905
|
-
* @param callback (optional) the result callback with two arguments:
|
2843
|
+
* @param callback (optional) the result callback called with two arguments:
|
906
2844
|
* error: null or Error('message')
|
907
2845
|
* content: the server answer that updateAt and taskID
|
908
2846
|
*/
|
@@ -915,16 +2853,17 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
915
2853
|
postObj.requests.push(request);
|
916
2854
|
}
|
917
2855
|
return this.as._jsonRequest({ method: 'POST',
|
918
|
-
|
919
|
-
|
920
|
-
|
2856
|
+
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/batch',
|
2857
|
+
body: postObj,
|
2858
|
+
hostType: 'write',
|
2859
|
+
callback: callback });
|
921
2860
|
},
|
922
2861
|
/*
|
923
2862
|
* Get an object from this index
|
924
2863
|
*
|
925
2864
|
* @param objectID the unique identifier of the object to retrieve
|
926
2865
|
* @param attrs (optional) if set, contains the array of attribute names to retrieve
|
927
|
-
* @param callback (optional) the result callback with two arguments
|
2866
|
+
* @param callback (optional) the result callback called with two arguments
|
928
2867
|
* error: null or Error('message')
|
929
2868
|
* content: the object to retrieve or the error message if a failure occured
|
930
2869
|
*/
|
@@ -950,6 +2889,33 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
950
2889
|
return this.as._jsonRequest({
|
951
2890
|
method: 'GET',
|
952
2891
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/' + encodeURIComponent(objectID) + params,
|
2892
|
+
hostType: 'read',
|
2893
|
+
callback: callback
|
2894
|
+
});
|
2895
|
+
},
|
2896
|
+
|
2897
|
+
/*
|
2898
|
+
* Get several objects from this index
|
2899
|
+
*
|
2900
|
+
* @param objectIDs the array of unique identifier of objects to retrieve
|
2901
|
+
*/
|
2902
|
+
getObjects: function(objectIDs, callback) {
|
2903
|
+
var indexObj = this;
|
2904
|
+
|
2905
|
+
var body = {
|
2906
|
+
requests: map(objectIDs, function prepareRequest(objectID) {
|
2907
|
+
return {
|
2908
|
+
'indexName': indexObj.indexName,
|
2909
|
+
'objectID': objectID
|
2910
|
+
};
|
2911
|
+
})
|
2912
|
+
};
|
2913
|
+
|
2914
|
+
return this.as._jsonRequest({
|
2915
|
+
method: 'POST',
|
2916
|
+
url: '/1/indexes/*/objects',
|
2917
|
+
hostType: 'read',
|
2918
|
+
body: body,
|
953
2919
|
callback: callback
|
954
2920
|
});
|
955
2921
|
},
|
@@ -959,22 +2925,23 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
959
2925
|
*
|
960
2926
|
* @param partialObject contains the javascript attributes to override, the
|
961
2927
|
* object must contains an objectID attribute
|
962
|
-
* @param callback (optional) the result callback with two arguments:
|
2928
|
+
* @param callback (optional) the result callback called with two arguments:
|
963
2929
|
* error: null or Error('message')
|
964
2930
|
* content: the server answer that contains 3 elements: createAt, taskId and objectID
|
965
2931
|
*/
|
966
2932
|
partialUpdateObject: function(partialObject, callback) {
|
967
2933
|
var indexObj = this;
|
968
2934
|
return this.as._jsonRequest({ method: 'POST',
|
969
|
-
|
970
|
-
|
971
|
-
|
2935
|
+
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/' + encodeURIComponent(partialObject.objectID) + '/partial',
|
2936
|
+
body: partialObject,
|
2937
|
+
hostType: 'write',
|
2938
|
+
callback: callback });
|
972
2939
|
},
|
973
2940
|
/*
|
974
2941
|
* Partially Override the content of several objects
|
975
2942
|
*
|
976
2943
|
* @param objects contains an array of objects to update (each object must contains a objectID attribute)
|
977
|
-
* @param callback (optional) the result callback with two arguments:
|
2944
|
+
* @param callback (optional) the result callback called with two arguments:
|
978
2945
|
* error: null or Error('message')
|
979
2946
|
* content: the server answer that updateAt and taskID
|
980
2947
|
*/
|
@@ -988,30 +2955,32 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
988
2955
|
postObj.requests.push(request);
|
989
2956
|
}
|
990
2957
|
return this.as._jsonRequest({ method: 'POST',
|
991
|
-
|
992
|
-
|
993
|
-
|
2958
|
+
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/batch',
|
2959
|
+
body: postObj,
|
2960
|
+
hostType: 'write',
|
2961
|
+
callback: callback });
|
994
2962
|
},
|
995
2963
|
/*
|
996
2964
|
* Override the content of object
|
997
2965
|
*
|
998
2966
|
* @param object contains the javascript object to save, the object must contains an objectID attribute
|
999
|
-
* @param callback (optional) the result callback with two arguments:
|
2967
|
+
* @param callback (optional) the result callback called with two arguments:
|
1000
2968
|
* error: null or Error('message')
|
1001
2969
|
* content: the server answer that updateAt and taskID
|
1002
2970
|
*/
|
1003
2971
|
saveObject: function(object, callback) {
|
1004
2972
|
var indexObj = this;
|
1005
2973
|
return this.as._jsonRequest({ method: 'PUT',
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
2974
|
+
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/' + encodeURIComponent(object.objectID),
|
2975
|
+
body: object,
|
2976
|
+
hostType: 'write',
|
2977
|
+
callback: callback });
|
1009
2978
|
},
|
1010
2979
|
/*
|
1011
2980
|
* Override the content of several objects
|
1012
2981
|
*
|
1013
2982
|
* @param objects contains an array of objects to update (each object must contains a objectID attribute)
|
1014
|
-
* @param callback (optional) the result callback with two arguments:
|
2983
|
+
* @param callback (optional) the result callback called with two arguments:
|
1015
2984
|
* error: null or Error('message')
|
1016
2985
|
* content: the server answer that updateAt and taskID
|
1017
2986
|
*/
|
@@ -1025,15 +2994,16 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1025
2994
|
postObj.requests.push(request);
|
1026
2995
|
}
|
1027
2996
|
return this.as._jsonRequest({ method: 'POST',
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
2997
|
+
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/batch',
|
2998
|
+
body: postObj,
|
2999
|
+
hostType: 'write',
|
3000
|
+
callback: callback });
|
1031
3001
|
},
|
1032
3002
|
/*
|
1033
3003
|
* Delete an object from the index
|
1034
3004
|
*
|
1035
3005
|
* @param objectID the unique identifier of object to delete
|
1036
|
-
* @param callback (optional) the result callback with two arguments:
|
3006
|
+
* @param callback (optional) the result callback called with two arguments:
|
1037
3007
|
* error: null or Error('message')
|
1038
3008
|
* content: the server answer that contains 3 elements: createAt, taskId and objectID
|
1039
3009
|
*/
|
@@ -1045,13 +3015,118 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1045
3015
|
return callback(err);
|
1046
3016
|
}
|
1047
3017
|
|
1048
|
-
return this.as.
|
3018
|
+
return this.as._promise.reject(err);
|
1049
3019
|
}
|
1050
3020
|
|
1051
3021
|
var indexObj = this;
|
1052
3022
|
return this.as._jsonRequest({ method: 'DELETE',
|
1053
|
-
|
1054
|
-
|
3023
|
+
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/' + encodeURIComponent(objectID),
|
3024
|
+
hostType: 'write',
|
3025
|
+
callback: callback });
|
3026
|
+
},
|
3027
|
+
/*
|
3028
|
+
* Delete several objects from an index
|
3029
|
+
*
|
3030
|
+
* @param objectIDs contains an array of objectID to delete
|
3031
|
+
* @param callback (optional) the result callback called with two arguments:
|
3032
|
+
* error: null or Error('message')
|
3033
|
+
* content: the server answer that contains 3 elements: createAt, taskId and objectID
|
3034
|
+
*/
|
3035
|
+
deleteObjects: function(objectIDs, callback) {
|
3036
|
+
var indexObj = this;
|
3037
|
+
var postObj = {
|
3038
|
+
requests: map(objectIDs, function prepareRequest(objectID) {
|
3039
|
+
return {
|
3040
|
+
action: 'deleteObject',
|
3041
|
+
objectID: objectID,
|
3042
|
+
body: {
|
3043
|
+
objectID: objectID
|
3044
|
+
}
|
3045
|
+
};
|
3046
|
+
})
|
3047
|
+
};
|
3048
|
+
|
3049
|
+
return this.as._jsonRequest({
|
3050
|
+
method: 'POST',
|
3051
|
+
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/batch',
|
3052
|
+
body: postObj,
|
3053
|
+
hostType: 'write',
|
3054
|
+
callback: callback
|
3055
|
+
});
|
3056
|
+
},
|
3057
|
+
/*
|
3058
|
+
* Delete all objects matching a query
|
3059
|
+
*
|
3060
|
+
* @param query the query string
|
3061
|
+
* @param params the optional query parameters
|
3062
|
+
* @param callback (optional) the result callback called with one argument
|
3063
|
+
* error: null or Error('message')
|
3064
|
+
*/
|
3065
|
+
deleteByQuery: function(query, params, callback) {
|
3066
|
+
var indexObj = this;
|
3067
|
+
var client = indexObj.as;
|
3068
|
+
|
3069
|
+
if (arguments.length === 1 || typeof params === 'function') {
|
3070
|
+
callback = params;
|
3071
|
+
params = {};
|
3072
|
+
}
|
3073
|
+
|
3074
|
+
params.attributesToRetrieve = 'objectID';
|
3075
|
+
params.hitsPerPage = 1000;
|
3076
|
+
|
3077
|
+
// when deleting, we should never use cache to get the
|
3078
|
+
// search results
|
3079
|
+
this.clearCache();
|
3080
|
+
|
3081
|
+
// there's a problem in how we use the promise chain,
|
3082
|
+
// see how waitTask is done
|
3083
|
+
var promise = this
|
3084
|
+
.search(query, params)
|
3085
|
+
.then(stopOrDelete);
|
3086
|
+
|
3087
|
+
function stopOrDelete(searchContent) {
|
3088
|
+
// stop here
|
3089
|
+
if (searchContent.nbHits === 0) {
|
3090
|
+
// return indexObj.as._request.resolve();
|
3091
|
+
return searchContent;
|
3092
|
+
}
|
3093
|
+
|
3094
|
+
// continue and do a recursive call
|
3095
|
+
var objectIDs = map(searchContent.hits, function getObjectID(object) {
|
3096
|
+
return object.objectID;
|
3097
|
+
});
|
3098
|
+
|
3099
|
+
return indexObj
|
3100
|
+
.deleteObjects(objectIDs)
|
3101
|
+
.then(waitTask)
|
3102
|
+
.then(deleteByQuery);
|
3103
|
+
}
|
3104
|
+
|
3105
|
+
function waitTask(deleteObjectsContent) {
|
3106
|
+
return indexObj.waitTask(deleteObjectsContent.taskID);
|
3107
|
+
}
|
3108
|
+
|
3109
|
+
function deleteByQuery() {
|
3110
|
+
return indexObj.deleteByQuery(query, params);
|
3111
|
+
}
|
3112
|
+
|
3113
|
+
if (!callback) {
|
3114
|
+
return promise;
|
3115
|
+
}
|
3116
|
+
|
3117
|
+
promise.then(success, failure);
|
3118
|
+
|
3119
|
+
function success() {
|
3120
|
+
exitPromise(function() {
|
3121
|
+
callback(null);
|
3122
|
+
}, client._setTimeout || setTimeout);
|
3123
|
+
}
|
3124
|
+
|
3125
|
+
function failure(err) {
|
3126
|
+
exitPromise(function() {
|
3127
|
+
callback(err);
|
3128
|
+
}, client._setTimeout || setTimeout);
|
3129
|
+
}
|
1055
3130
|
},
|
1056
3131
|
/*
|
1057
3132
|
* Search inside the index using XMLHttpRequest request (Using a POST query to
|
@@ -1117,11 +3192,19 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1117
3192
|
* one is kept and others are removed.
|
1118
3193
|
* - restrictSearchableAttributes: List of attributes you want to use for textual search (must be a subset of the attributesToIndex index setting)
|
1119
3194
|
* either comma separated or as an array
|
1120
|
-
* @param callback the result callback with two arguments:
|
3195
|
+
* @param callback the result callback called with two arguments:
|
1121
3196
|
* error: null or Error('message'). If false, the content contains the error.
|
1122
3197
|
* content: the server answer that contains the list of results.
|
1123
3198
|
*/
|
1124
3199
|
search: function(query, args, callback) {
|
3200
|
+
// warn V2 users on how to search
|
3201
|
+
if (typeof query === 'function' && typeof args === 'object' ||
|
3202
|
+
typeof callback === 'object') {
|
3203
|
+
// .search(query, params, cb)
|
3204
|
+
// .search(cb, params)
|
3205
|
+
throw new Error('algoliasearch: index.search usage is index.search(query, params, cb)');
|
3206
|
+
}
|
3207
|
+
|
1125
3208
|
if (arguments.length === 0 || typeof query === 'function') {
|
1126
3209
|
// .search(), .search(cb)
|
1127
3210
|
callback = query;
|
@@ -1147,6 +3230,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1147
3230
|
}
|
1148
3231
|
|
1149
3232
|
if (args !== undefined) {
|
3233
|
+
// `_getSearchParams` will augment params, do not be fooled by the = versus += from previous if
|
1150
3234
|
params = this.as._getSearchParams(args, params);
|
1151
3235
|
}
|
1152
3236
|
|
@@ -1159,7 +3243,7 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1159
3243
|
* @param page Pagination parameter used to select the page to retrieve.
|
1160
3244
|
* Page is zero-based and defaults to 0. Thus, to retrieve the 10th page you need to set page=9
|
1161
3245
|
* @param hitsPerPage: Pagination parameter used to select the number of hits per page. Defaults to 1000.
|
1162
|
-
* @param callback the result callback with two arguments:
|
3246
|
+
* @param callback the result callback called with two arguments:
|
1163
3247
|
* error: null or Error('message'). If false, the content contains the error.
|
1164
3248
|
* content: the server answer that contains the list of results.
|
1165
3249
|
*/
|
@@ -1176,8 +3260,9 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1176
3260
|
params += '&hitsPerPage=' + hitsPerPage;
|
1177
3261
|
}
|
1178
3262
|
return this.as._jsonRequest({ method: 'GET',
|
1179
|
-
|
1180
|
-
|
3263
|
+
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/browse' + params,
|
3264
|
+
hostType: 'read',
|
3265
|
+
callback: callback });
|
1181
3266
|
},
|
1182
3267
|
|
1183
3268
|
/*
|
@@ -1211,64 +3296,70 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1211
3296
|
// waitTask() must be handled differently from other methods,
|
1212
3297
|
// it's a recursive method using a timeout
|
1213
3298
|
var indexObj = this;
|
3299
|
+
var client = indexObj.as;
|
1214
3300
|
|
1215
3301
|
var promise = this.as._jsonRequest({
|
1216
3302
|
method: 'GET',
|
3303
|
+
hostType: 'read',
|
1217
3304
|
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/task/' + taskID
|
1218
3305
|
}).then(function success(content) {
|
1219
3306
|
if (content.status !== 'published') {
|
1220
|
-
return
|
1221
|
-
|
3307
|
+
return indexObj.as._promise.delay(100).then(function() {
|
3308
|
+
// do not forward the callback, we want the promise
|
3309
|
+
// on next iteration
|
3310
|
+
return indexObj.waitTask(taskID);
|
1222
3311
|
});
|
1223
3312
|
}
|
1224
3313
|
|
1225
|
-
|
1226
|
-
process.nextTick(function() {
|
1227
|
-
callback(null, content);
|
1228
|
-
});
|
1229
|
-
} else {
|
1230
|
-
return content;
|
1231
|
-
}
|
1232
|
-
}, function failure(err) {
|
1233
|
-
if (callback) {
|
1234
|
-
process.nextTick(function() {
|
1235
|
-
callback(err);
|
1236
|
-
});
|
1237
|
-
} else {
|
1238
|
-
return err;
|
1239
|
-
}
|
3314
|
+
return content;
|
1240
3315
|
});
|
1241
3316
|
|
1242
3317
|
if (!callback) {
|
1243
3318
|
return promise;
|
1244
3319
|
}
|
3320
|
+
|
3321
|
+
promise.then(successCb, failureCb);
|
3322
|
+
|
3323
|
+
function successCb(content) {
|
3324
|
+
exitPromise(function() {
|
3325
|
+
callback(null, content);
|
3326
|
+
}, client._setTimeout || setTimeout);
|
3327
|
+
}
|
3328
|
+
|
3329
|
+
function failureCb(err) {
|
3330
|
+
exitPromise(function() {
|
3331
|
+
callback(err);
|
3332
|
+
}, client._setTimeout || setTimeout);
|
3333
|
+
}
|
1245
3334
|
},
|
1246
3335
|
|
1247
3336
|
/*
|
1248
3337
|
* This function deletes the index content. Settings and index specific API keys are kept untouched.
|
1249
3338
|
*
|
1250
|
-
* @param callback (optional) the result callback with two arguments
|
3339
|
+
* @param callback (optional) the result callback called with two arguments
|
1251
3340
|
* error: null or Error('message')
|
1252
3341
|
* content: the settings object or the error message if a failure occured
|
1253
3342
|
*/
|
1254
3343
|
clearIndex: function(callback) {
|
1255
3344
|
var indexObj = this;
|
1256
3345
|
return this.as._jsonRequest({ method: 'POST',
|
1257
|
-
|
1258
|
-
|
3346
|
+
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/clear',
|
3347
|
+
hostType: 'write',
|
3348
|
+
callback: callback });
|
1259
3349
|
},
|
1260
3350
|
/*
|
1261
3351
|
* Get settings of this index
|
1262
3352
|
*
|
1263
|
-
* @param callback (optional) the result callback with two arguments
|
3353
|
+
* @param callback (optional) the result callback called with two arguments
|
1264
3354
|
* error: null or Error('message')
|
1265
3355
|
* content: the settings object or the error message if a failure occured
|
1266
3356
|
*/
|
1267
3357
|
getSettings: function(callback) {
|
1268
3358
|
var indexObj = this;
|
1269
3359
|
return this.as._jsonRequest({ method: 'GET',
|
1270
|
-
|
1271
|
-
|
3360
|
+
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/settings',
|
3361
|
+
hostType: 'read',
|
3362
|
+
callback: callback });
|
1272
3363
|
},
|
1273
3364
|
|
1274
3365
|
/*
|
@@ -1321,57 +3412,61 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1321
3412
|
* - highlightPreTag: (string) Specify the string that is inserted before the highlighted parts in the query result (default to "<em>").
|
1322
3413
|
* - highlightPostTag: (string) Specify the string that is inserted after the highlighted parts in the query result (default to "</em>").
|
1323
3414
|
* - optionalWords: (array of strings) Specify a list of words that should be considered as optional when found in the query.
|
1324
|
-
* @param callback (optional) the result callback with two arguments
|
3415
|
+
* @param callback (optional) the result callback called with two arguments
|
1325
3416
|
* error: null or Error('message')
|
1326
3417
|
* content: the server answer or the error message if a failure occured
|
1327
3418
|
*/
|
1328
3419
|
setSettings: function(settings, callback) {
|
1329
3420
|
var indexObj = this;
|
1330
3421
|
return this.as._jsonRequest({ method: 'PUT',
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
3422
|
+
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/settings',
|
3423
|
+
hostType: 'write',
|
3424
|
+
body: settings,
|
3425
|
+
callback: callback });
|
1334
3426
|
},
|
1335
3427
|
/*
|
1336
3428
|
* List all existing user keys associated to this index
|
1337
3429
|
*
|
1338
|
-
* @param callback the result callback with two arguments
|
3430
|
+
* @param callback the result callback called with two arguments
|
1339
3431
|
* error: null or Error('message')
|
1340
3432
|
* content: the server answer with user keys list
|
1341
3433
|
*/
|
1342
3434
|
listUserKeys: function(callback) {
|
1343
3435
|
var indexObj = this;
|
1344
3436
|
return this.as._jsonRequest({ method: 'GET',
|
1345
|
-
|
1346
|
-
|
3437
|
+
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/keys',
|
3438
|
+
hostType: 'read',
|
3439
|
+
callback: callback });
|
1347
3440
|
},
|
1348
3441
|
/*
|
1349
3442
|
* Get ACL of a user key associated to this index
|
1350
3443
|
*
|
1351
3444
|
* @param key
|
1352
|
-
* @param callback the result callback with two arguments
|
3445
|
+
* @param callback the result callback called with two arguments
|
1353
3446
|
* error: null or Error('message')
|
1354
3447
|
* content: the server answer with user keys list
|
1355
3448
|
*/
|
1356
3449
|
getUserKeyACL: function(key, callback) {
|
1357
3450
|
var indexObj = this;
|
1358
3451
|
return this.as._jsonRequest({ method: 'GET',
|
1359
|
-
|
1360
|
-
|
3452
|
+
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/keys/' + key,
|
3453
|
+
hostType: 'read',
|
3454
|
+
callback: callback });
|
1361
3455
|
},
|
1362
3456
|
/*
|
1363
3457
|
* Delete an existing user key associated to this index
|
1364
3458
|
*
|
1365
3459
|
* @param key
|
1366
|
-
* @param callback the result callback with two arguments
|
3460
|
+
* @param callback the result callback called with two arguments
|
1367
3461
|
* error: null or Error('message')
|
1368
3462
|
* content: the server answer with user keys list
|
1369
3463
|
*/
|
1370
3464
|
deleteUserKey: function(key, callback) {
|
1371
3465
|
var indexObj = this;
|
1372
3466
|
return this.as._jsonRequest({ method: 'DELETE',
|
1373
|
-
|
1374
|
-
|
3467
|
+
url: '/1/indexes/' + encodeURIComponent(indexObj.indexName) + '/keys/' + key,
|
3468
|
+
hostType: 'write',
|
3469
|
+
callback: callback });
|
1375
3470
|
},
|
1376
3471
|
/*
|
1377
3472
|
* Add an existing user key associated to this index
|
@@ -1384,57 +3479,94 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1384
3479
|
* - deleteIndex : allows to delete index content (https only)
|
1385
3480
|
* - settings : allows to get index settings (https only)
|
1386
3481
|
* - editSettings : allows to change index settings (https only)
|
1387
|
-
* @param callback the result callback with two arguments
|
3482
|
+
* @param callback the result callback called with two arguments
|
1388
3483
|
* error: null or Error('message')
|
1389
3484
|
* content: the server answer with user keys list
|
1390
3485
|
*/
|
1391
|
-
addUserKey: function(acls, callback) {
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
3486
|
+
addUserKey: function(acls, params, callback) {
|
3487
|
+
if (arguments.length === 1 || typeof params === 'function') {
|
3488
|
+
callback = params;
|
3489
|
+
params = null;
|
3490
|
+
}
|
3491
|
+
|
3492
|
+
var postObj = {
|
3493
|
+
acl: acls
|
3494
|
+
};
|
3495
|
+
|
3496
|
+
if (params) {
|
3497
|
+
postObj.validity = params.validity;
|
3498
|
+
postObj.maxQueriesPerIPPerHour = params.maxQueriesPerIPPerHour;
|
3499
|
+
postObj.maxHitsPerQuery = params.maxHitsPerQuery;
|
3500
|
+
}
|
3501
|
+
|
3502
|
+
return this.as._jsonRequest({
|
3503
|
+
method: 'POST',
|
3504
|
+
url: '/1/indexes/' + encodeURIComponent(this.indexName) + '/keys',
|
3505
|
+
body: postObj,
|
3506
|
+
hostType: 'write',
|
3507
|
+
callback: callback
|
3508
|
+
});
|
1399
3509
|
},
|
1400
|
-
|
3510
|
+
|
3511
|
+
/**
|
1401
3512
|
* Add an existing user key associated to this index
|
1402
|
-
*
|
1403
|
-
* @param acls the list of ACL for this key. Defined by an array of strings that
|
1404
|
-
* can contains the following values:
|
1405
|
-
* - search: allow to search (https and http)
|
1406
|
-
* - addObject: allows to add/update an object in the index (https only)
|
1407
|
-
* - deleteObject : allows to delete an existing object (https only)
|
1408
|
-
* - deleteIndex : allows to delete index content (https only)
|
1409
|
-
* - settings : allows to get index settings (https only)
|
1410
|
-
* - editSettings : allows to change index settings (https only)
|
1411
|
-
* @param params.validity the number of seconds after which the key will be automatically removed (0 means no time limit for this key)
|
1412
|
-
* @param params.maxQueriesPerIPPerHour Specify the maximum number of API calls allowed from an IP address per hour.
|
1413
|
-
* @param params.maxHitsPerQuery Specify the maximum number of hits this API key can retrieve in one call.
|
1414
|
-
* @param callback the result callback with two arguments
|
1415
|
-
* error: null or Error('message')
|
1416
|
-
* content: the server answer with user keys list
|
3513
|
+
* @deprecated use index.addUserKey()
|
1417
3514
|
*/
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
3515
|
+
addUserKeyWithValidity: deprecate(function(acls, params, callback) {
|
3516
|
+
return this.addUserKey(acls, params, callback);
|
3517
|
+
}, deprecatedMessage('index.addUserKeyWithValidity()', 'index.addUserKey()')),
|
3518
|
+
|
3519
|
+
/**
|
3520
|
+
* Update an existing user key associated to this index
|
3521
|
+
* @param {string} key - The key to update
|
3522
|
+
* @param {string[]} acls - The list of ACL for this key. Defined by an array of strings that
|
3523
|
+
* can contains the following values:
|
3524
|
+
* - search: allow to search (https and http)
|
3525
|
+
* - addObject: allows to add/update an object in the index (https only)
|
3526
|
+
* - deleteObject : allows to delete an existing object (https only)
|
3527
|
+
* - deleteIndex : allows to delete index content (https only)
|
3528
|
+
* - settings : allows to get index settings (https only)
|
3529
|
+
* - editSettings : allows to change index settings (https only)
|
3530
|
+
* @param {Object} [params] - Optionnal parameters to set for the key
|
3531
|
+
* @param {number} params.validity - Number of seconds after which the key will be automatically removed (0 means no time limit for this key)
|
3532
|
+
* @param {number} params.maxQueriesPerIPPerHour - Number of API calls allowed from an IP address per hour
|
3533
|
+
* @param {number} params.maxHitsPerQuery - Number of hits this API key can retrieve in one call
|
3534
|
+
* @param {Function} callback - The result callback called with two arguments
|
3535
|
+
* error: null or Error('message')
|
3536
|
+
* content: the server answer with user keys list
|
3537
|
+
* @return {Promise|undefined} Returns a promise if no callback given
|
3538
|
+
*/
|
3539
|
+
updateUserKey: function(key, acls, params, callback) {
|
3540
|
+
if (arguments.length === 2 || typeof params === 'function') {
|
3541
|
+
callback = params;
|
3542
|
+
params = null;
|
3543
|
+
}
|
3544
|
+
|
3545
|
+
var putObj = {
|
3546
|
+
acl: acls
|
3547
|
+
};
|
3548
|
+
|
3549
|
+
if (params) {
|
3550
|
+
putObj.validity = params.validity;
|
3551
|
+
putObj.maxQueriesPerIPPerHour = params.maxQueriesPerIPPerHour;
|
3552
|
+
putObj.maxHitsPerQuery = params.maxHitsPerQuery;
|
3553
|
+
}
|
3554
|
+
|
3555
|
+
return this.as._jsonRequest({
|
3556
|
+
method: 'PUT',
|
3557
|
+
url: '/1/indexes/' + encodeURIComponent(this.indexName) + '/keys/' + key,
|
3558
|
+
body: putObj,
|
3559
|
+
hostType: 'write',
|
3560
|
+
callback: callback
|
3561
|
+
});
|
3562
|
+
},
|
3563
|
+
|
1433
3564
|
_search: function(params, callback) {
|
1434
3565
|
return this.as._jsonRequest({ cache: this.cache,
|
1435
3566
|
method: 'POST',
|
1436
3567
|
url: '/1/indexes/' + encodeURIComponent(this.indexName) + '/query',
|
1437
3568
|
body: {params: params},
|
3569
|
+
hostType: 'read',
|
1438
3570
|
fallback: {
|
1439
3571
|
method: 'GET',
|
1440
3572
|
url: '/1/indexes/' + encodeURIComponent(this.indexName),
|
@@ -1444,7 +3576,6 @@ AlgoliaSearch.prototype.Index.prototype = {
|
|
1444
3576
|
});
|
1445
3577
|
},
|
1446
3578
|
|
1447
|
-
// internal attributes
|
1448
3579
|
as: null,
|
1449
3580
|
indexName: null,
|
1450
3581
|
typeAheadArgs: null,
|
@@ -1461,110 +3592,53 @@ function map(arr, fn){
|
|
1461
3592
|
return ret;
|
1462
3593
|
}
|
1463
3594
|
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
var currentIndex = array.length
|
1469
|
-
, temporaryValue
|
1470
|
-
, randomIndex
|
1471
|
-
;
|
1472
|
-
|
1473
|
-
// While there remain elements to shuffle...
|
1474
|
-
while (0 !== currentIndex) {
|
1475
|
-
|
1476
|
-
// Pick a remaining element...
|
1477
|
-
randomIndex = Math.floor(Math.random() * currentIndex);
|
1478
|
-
currentIndex -= 1;
|
1479
|
-
|
1480
|
-
// And swap it with the current element.
|
1481
|
-
temporaryValue = array[currentIndex];
|
1482
|
-
array[currentIndex] = array[randomIndex];
|
1483
|
-
array[randomIndex] = temporaryValue;
|
1484
|
-
}
|
1485
|
-
|
1486
|
-
return array;
|
3595
|
+
function prepareHost(protocol) {
|
3596
|
+
return function prepare(host) {
|
3597
|
+
return protocol + '//' + host.toLowerCase();
|
3598
|
+
};
|
1487
3599
|
}
|
1488
3600
|
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
var createAlgoliasearch = require(5);
|
1493
|
-
var JSONPRequest = require(4);
|
1494
|
-
|
1495
|
-
var algoliasearch = createAlgoliasearch(request);
|
1496
|
-
var $ = global.jQuery;
|
1497
|
-
|
1498
|
-
$.algolia = {Client: algoliasearch};
|
1499
|
-
|
1500
|
-
function request(url, opts) {
|
1501
|
-
return $.Deferred(function(deferred) {
|
1502
|
-
var body = null;
|
1503
|
-
|
1504
|
-
if (opts.body !== undefined) {
|
1505
|
-
body = JSON.stringify(opts.body);
|
1506
|
-
}
|
3601
|
+
function notImplemented() {
|
3602
|
+
var message = 'algoliasearch: Not implemented in this environment.\n' +
|
3603
|
+
'If you feel this is a mistake, write to support@algolia.com';
|
1507
3604
|
|
1508
|
-
|
1509
|
-
|
1510
|
-
timeout: opts.timeout,
|
1511
|
-
dataType: 'json',
|
1512
|
-
data: body,
|
1513
|
-
complete: function(jqXHR, textStatus/* , error*/) {
|
1514
|
-
if (textStatus === 'timeout') {
|
1515
|
-
deferred.resolve(new Error('Timeout - Could not connect to endpoint ' + url));
|
1516
|
-
return;
|
1517
|
-
}
|
3605
|
+
throw new Error(message);
|
3606
|
+
}
|
1518
3607
|
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
3608
|
+
function deprecatedMessage(previousUsage, newUsage) {
|
3609
|
+
var githubAnchorLink = previousUsage.toLowerCase()
|
3610
|
+
.replace('.', '')
|
3611
|
+
.replace('()', '');
|
1523
3612
|
|
1524
|
-
|
1525
|
-
|
1526
|
-
body: jqXHR.responseJSON
|
1527
|
-
});
|
1528
|
-
}
|
1529
|
-
});
|
1530
|
-
}).promise();
|
3613
|
+
return 'algoliasearch: `' + previousUsage + '` was replaced by `' +
|
3614
|
+
newUsage + '`. Please see https://github.com/algolia/algoliasearch-client-js/wiki/Deprecated#' + githubAnchorLink
|
1531
3615
|
}
|
1532
3616
|
|
1533
|
-
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
3617
|
+
// Parse cloud does not supports setTimeout
|
3618
|
+
// We do not store a setTimeout reference in the client everytime
|
3619
|
+
// We only fallback to a fake setTimeout when not available
|
3620
|
+
// setTimeout cannot be override globally sadly
|
3621
|
+
function exitPromise(fn, _setTimeout) {
|
3622
|
+
_setTimeout(fn, 0);
|
3623
|
+
}
|
1540
3624
|
|
1541
|
-
|
1542
|
-
|
1543
|
-
}).promise();
|
1544
|
-
};
|
3625
|
+
function deprecate(fn, message) {
|
3626
|
+
var warned = false;
|
1545
3627
|
|
1546
|
-
|
1547
|
-
|
1548
|
-
|
1549
|
-
|
1550
|
-
}
|
3628
|
+
function deprecated() {
|
3629
|
+
if (!warned) {
|
3630
|
+
console.log(message);
|
3631
|
+
warned = true;
|
3632
|
+
}
|
1551
3633
|
|
1552
|
-
|
1553
|
-
|
1554
|
-
deferred.resolve(val);
|
1555
|
-
}).promise();
|
1556
|
-
};
|
3634
|
+
return fn.apply(this, arguments);
|
3635
|
+
}
|
1557
3636
|
|
1558
|
-
|
1559
|
-
|
1560
|
-
setTimeout(function() {
|
1561
|
-
deferred.resolve();
|
1562
|
-
}, ms);
|
1563
|
-
}).promise();
|
1564
|
-
};
|
3637
|
+
return deprecated;
|
3638
|
+
}
|
1565
3639
|
|
1566
|
-
}).call(this,
|
1567
|
-
},{"
|
3640
|
+
}).call(this,require(1))
|
3641
|
+
},{"1":1,"11":11,"5":5,"9":9}],14:[function(require,module,exports){
|
1568
3642
|
module.exports = JSONPRequest;
|
1569
3643
|
|
1570
3644
|
var JSONPCounter = 0;
|
@@ -1575,6 +3649,8 @@ function JSONPRequest(url, opts, cb) {
|
|
1575
3649
|
return;
|
1576
3650
|
}
|
1577
3651
|
|
3652
|
+
opts.debug('JSONP: start');
|
3653
|
+
|
1578
3654
|
var cbCalled = false;
|
1579
3655
|
var timedOut = false;
|
1580
3656
|
|
@@ -1610,9 +3686,9 @@ function JSONPRequest(url, opts, cb) {
|
|
1610
3686
|
// add callback by hand
|
1611
3687
|
url += '&callback=' + cbName;
|
1612
3688
|
|
1613
|
-
// add body params
|
1614
|
-
if (opts.
|
1615
|
-
url += '&' + opts.
|
3689
|
+
// add body params manually
|
3690
|
+
if (opts.jsonBody && opts.jsonBody.params) {
|
3691
|
+
url += '&' + opts.jsonBody.params;
|
1616
3692
|
}
|
1617
3693
|
|
1618
3694
|
var ontimeout = setTimeout(timeout, opts.timeout);
|
@@ -1630,6 +3706,8 @@ function JSONPRequest(url, opts, cb) {
|
|
1630
3706
|
head.appendChild(script);
|
1631
3707
|
|
1632
3708
|
function success() {
|
3709
|
+
opts.debug('JSONP: success');
|
3710
|
+
|
1633
3711
|
if (done || timedOut) {
|
1634
3712
|
return;
|
1635
3713
|
}
|
@@ -1638,6 +3716,7 @@ function JSONPRequest(url, opts, cb) {
|
|
1638
3716
|
|
1639
3717
|
// script loaded but did not call the fn => script loading error
|
1640
3718
|
if (!cbCalled) {
|
3719
|
+
opts.debug('JSONP: Fail. Script loaded but did not call the callback');
|
1641
3720
|
clean();
|
1642
3721
|
cb(new Error('Failed to load JSONP script'));
|
1643
3722
|
}
|
@@ -1666,12 +3745,16 @@ function JSONPRequest(url, opts, cb) {
|
|
1666
3745
|
}
|
1667
3746
|
|
1668
3747
|
function timeout() {
|
3748
|
+
opts.debug('JSONP: Script timeout');
|
3749
|
+
|
1669
3750
|
timedOut = true;
|
1670
3751
|
clean();
|
1671
3752
|
cb(new Error('Timeout - Could not connect to endpoint ' + url));
|
1672
3753
|
}
|
1673
3754
|
|
1674
3755
|
function error() {
|
3756
|
+
opts.debug('JSONP: Script error');
|
3757
|
+
|
1675
3758
|
if (done || timedOut) {
|
1676
3759
|
return;
|
1677
3760
|
}
|
@@ -1681,22 +3764,328 @@ function JSONPRequest(url, opts, cb) {
|
|
1681
3764
|
}
|
1682
3765
|
}
|
1683
3766
|
|
1684
|
-
},{}],
|
1685
|
-
|
1686
|
-
//
|
1687
|
-
// using
|
1688
|
-
|
3767
|
+
},{}],15:[function(require,module,exports){
|
3768
|
+
(function (global){
|
3769
|
+
// This is the jQuery Algolia Search module
|
3770
|
+
// It's using $.ajax to do requests with a JSONP fallback
|
3771
|
+
// jQuery promises are returned
|
3772
|
+
|
3773
|
+
var inherits = require(12);
|
3774
|
+
|
3775
|
+
var AlgoliaSearch = require(13);
|
3776
|
+
var inlineHeaders = require(18);
|
3777
|
+
var JSONPRequest = require(14);
|
3778
|
+
|
3779
|
+
// expose original algoliasearch fn in window
|
3780
|
+
window.algoliasearch = require(16);
|
3781
|
+
|
3782
|
+
function algoliasearch(applicationID, apiKey, opts) {
|
3783
|
+
var extend = require(9);
|
3784
|
+
|
3785
|
+
var getDocumentProtocol = require(17);
|
3786
|
+
|
3787
|
+
opts = extend(true, {}, opts) || {};
|
3788
|
+
|
3789
|
+
if (opts.protocol === undefined) {
|
3790
|
+
opts.protocol = getDocumentProtocol();
|
3791
|
+
}
|
3792
|
+
|
3793
|
+
opts._ua = algoliasearch.ua;
|
3794
|
+
|
3795
|
+
return new AlgoliaSearchJQuery(applicationID, apiKey, opts);
|
3796
|
+
}
|
3797
|
+
|
3798
|
+
algoliasearch.version = require(19);
|
3799
|
+
algoliasearch.ua = 'Algolia for jQuery ' + algoliasearch.version;
|
3800
|
+
|
3801
|
+
var $ = global.jQuery;
|
3802
|
+
|
3803
|
+
$.algolia = {Client: algoliasearch, ua: algoliasearch.ua, version: algoliasearch.version};
|
3804
|
+
|
3805
|
+
function AlgoliaSearchJQuery() {
|
3806
|
+
// call AlgoliaSearch constructor
|
3807
|
+
AlgoliaSearch.apply(this, arguments);
|
3808
|
+
}
|
3809
|
+
|
3810
|
+
inherits(AlgoliaSearchJQuery, AlgoliaSearch);
|
3811
|
+
|
3812
|
+
AlgoliaSearchJQuery.prototype._request = function(url, opts) {
|
3813
|
+
return $.Deferred(function(deferred) {
|
3814
|
+
var body = opts.body;
|
3815
|
+
|
3816
|
+
url = inlineHeaders(url, opts.headers);
|
3817
|
+
|
3818
|
+
$.ajax(url, {
|
3819
|
+
type: opts.method,
|
3820
|
+
timeout: opts.timeout,
|
3821
|
+
dataType: 'json',
|
3822
|
+
data: body,
|
3823
|
+
complete: function(jqXHR, textStatus/* , error*/) {
|
3824
|
+
if (textStatus === 'timeout') {
|
3825
|
+
deferred.resolve(new Error('Timeout - Could not connect to endpoint ' + url));
|
3826
|
+
return;
|
3827
|
+
}
|
3828
|
+
|
3829
|
+
if (jqXHR.status === 0) {
|
3830
|
+
deferred.reject(new Error('Network error'));
|
3831
|
+
return;
|
3832
|
+
}
|
3833
|
+
|
3834
|
+
deferred.resolve({
|
3835
|
+
statusCode: jqXHR.status,
|
3836
|
+
body: jqXHR.responseJSON
|
3837
|
+
});
|
3838
|
+
}
|
3839
|
+
});
|
3840
|
+
}).promise();
|
3841
|
+
};
|
3842
|
+
|
3843
|
+
AlgoliaSearchJQuery.prototype._request.fallback = function(url, opts) {
|
3844
|
+
url = inlineHeaders(url, opts.headers);
|
3845
|
+
|
3846
|
+
return $.Deferred(function(deferred) {
|
3847
|
+
JSONPRequest(url, opts, function JSONPRequestDone(err, content) {
|
3848
|
+
if (err) {
|
3849
|
+
deferred.reject(err);
|
3850
|
+
return;
|
3851
|
+
}
|
3852
|
+
|
3853
|
+
deferred.resolve(content);
|
3854
|
+
});
|
3855
|
+
}).promise();
|
3856
|
+
};
|
3857
|
+
|
3858
|
+
AlgoliaSearchJQuery.prototype._promise = {
|
3859
|
+
reject: function(val) {
|
3860
|
+
return $.Deferred(function(deferred) {
|
3861
|
+
deferred.reject(val);
|
3862
|
+
}).promise();
|
3863
|
+
},
|
3864
|
+
resolve: function(val) {
|
3865
|
+
return $.Deferred(function(deferred) {
|
3866
|
+
deferred.resolve(val);
|
3867
|
+
}).promise();
|
3868
|
+
},
|
3869
|
+
delay: function(ms) {
|
3870
|
+
return $.Deferred(function(deferred) {
|
3871
|
+
setTimeout(function() {
|
3872
|
+
deferred.resolve();
|
3873
|
+
}, ms);
|
3874
|
+
}).promise();
|
3875
|
+
}
|
3876
|
+
};
|
3877
|
+
|
3878
|
+
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
3879
|
+
},{"12":12,"13":13,"14":14,"16":16,"17":17,"18":18,"19":19,"9":9}],16:[function(require,module,exports){
|
3880
|
+
(function (global){
|
3881
|
+
// This is the standalone browser build entry point
|
3882
|
+
// Browser implementation of the Algolia Search JavaScript client,
|
3883
|
+
// using XMLHttpRequest, XDomainRequest and JSONP as fallback
|
3884
|
+
module.exports = algoliasearch;
|
3885
|
+
|
3886
|
+
var inherits = require(12);
|
3887
|
+
var Promise = global.Promise || require(8).Promise;
|
3888
|
+
|
3889
|
+
var AlgoliaSearch = require(13);
|
3890
|
+
var inlineHeaders = require(18);
|
3891
|
+
var JSONPRequest = require(14);
|
3892
|
+
|
3893
|
+
function algoliasearch(applicationID, apiKey, opts) {
|
3894
|
+
var extend = require(9);
|
3895
|
+
|
3896
|
+
var getDocumentProtocol = require(17);
|
3897
|
+
|
3898
|
+
opts = extend(true, {}, opts) || {};
|
3899
|
+
|
3900
|
+
if (opts.protocol === undefined) {
|
3901
|
+
opts.protocol = getDocumentProtocol();
|
3902
|
+
}
|
3903
|
+
|
3904
|
+
opts._ua = algoliasearch.ua;
|
3905
|
+
|
3906
|
+
return new AlgoliaSearchBrowser(applicationID, apiKey, opts);
|
3907
|
+
}
|
3908
|
+
|
3909
|
+
algoliasearch.version = require(19);
|
3910
|
+
algoliasearch.ua = 'Algolia for vanilla JavaScript ' + algoliasearch.version;
|
3911
|
+
|
3912
|
+
var support = {
|
3913
|
+
hasXMLHttpRequest: 'XMLHttpRequest' in window,
|
3914
|
+
hasXDomainRequest: 'XDomainRequest' in window,
|
3915
|
+
cors: 'withCredentials' in new XMLHttpRequest(),
|
3916
|
+
timeout: 'timeout' in new XMLHttpRequest()
|
3917
|
+
};
|
3918
|
+
|
3919
|
+
function AlgoliaSearchBrowser() {
|
3920
|
+
// call AlgoliaSearch constructor
|
3921
|
+
AlgoliaSearch.apply(this, arguments);
|
3922
|
+
}
|
3923
|
+
|
3924
|
+
inherits(AlgoliaSearchBrowser, AlgoliaSearch);
|
3925
|
+
|
3926
|
+
AlgoliaSearchBrowser.prototype._request = function(url, opts) {
|
3927
|
+
return new Promise(function(resolve, reject) {
|
3928
|
+
// no cors or XDomainRequest, no request
|
3929
|
+
if (!support.cors && !support.hasXDomainRequest) {
|
3930
|
+
// very old browser, not supported
|
3931
|
+
reject(new Error('CORS not supported'));
|
3932
|
+
return;
|
3933
|
+
}
|
1689
3934
|
|
1690
|
-
|
1691
|
-
function algoliasearch(applicationID, apiKey, opts) {
|
1692
|
-
var AlgoliaSearch = require(2);
|
3935
|
+
url = inlineHeaders(url, opts.headers);
|
1693
3936
|
|
1694
|
-
|
3937
|
+
var body = opts.body;
|
3938
|
+
var req = support.cors ? new XMLHttpRequest() : new XDomainRequest();
|
3939
|
+
var ontimeout;
|
3940
|
+
var timedOut;
|
3941
|
+
|
3942
|
+
// do not rely on default XHR async flag, as some analytics code like hotjar
|
3943
|
+
// breaks it and set it to false by default
|
3944
|
+
if (req instanceof XMLHttpRequest) {
|
3945
|
+
req.open(opts.method, url, true);
|
3946
|
+
} else {
|
3947
|
+
req.open(opts.method, url);
|
3948
|
+
}
|
3949
|
+
|
3950
|
+
if (support.cors && body && opts.method !== 'GET') {
|
3951
|
+
req.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
|
3952
|
+
}
|
3953
|
+
|
3954
|
+
// we set an empty onprogress listener
|
3955
|
+
// so that XDomainRequest on IE9 is not aborted
|
3956
|
+
// refs:
|
3957
|
+
// - https://github.com/algolia/algoliasearch-client-js/issues/76
|
3958
|
+
// - 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
|
3959
|
+
req.onprogress = function noop() {};
|
3960
|
+
|
3961
|
+
req.onload = load;
|
3962
|
+
req.onerror = error;
|
3963
|
+
|
3964
|
+
if (support.timeout) {
|
3965
|
+
// .timeout supported by both XHR and XDR,
|
3966
|
+
// we do receive timeout event, tested
|
3967
|
+
req.timeout = opts.timeout;
|
3968
|
+
|
3969
|
+
req.ontimeout = timeout;
|
3970
|
+
} else {
|
3971
|
+
ontimeout = setTimeout(timeout, opts.timeout);
|
3972
|
+
}
|
3973
|
+
|
3974
|
+
req.send(body);
|
3975
|
+
|
3976
|
+
// event object not received in IE8, at least
|
3977
|
+
// but we do not use it, still important to note
|
3978
|
+
function load(/*event*/) {
|
3979
|
+
// When browser does not supports req.timeout, we can
|
3980
|
+
// have both a load and timeout event, since handled by a dumb setTimeout
|
3981
|
+
if (timedOut) {
|
3982
|
+
return;
|
3983
|
+
}
|
3984
|
+
|
3985
|
+
if (!support.timeout) {
|
3986
|
+
clearTimeout(ontimeout);
|
3987
|
+
}
|
3988
|
+
|
3989
|
+
var response = null;
|
3990
|
+
|
3991
|
+
try {
|
3992
|
+
response = JSON.parse(req.responseText);
|
3993
|
+
} catch(e) {}
|
3994
|
+
|
3995
|
+
resolve({
|
3996
|
+
body: response,
|
3997
|
+
statusCode: req.status
|
3998
|
+
});
|
3999
|
+
}
|
4000
|
+
|
4001
|
+
function error(event) {
|
4002
|
+
if (timedOut) {
|
4003
|
+
return;
|
4004
|
+
}
|
4005
|
+
|
4006
|
+
if (!support.timeout) {
|
4007
|
+
clearTimeout(ontimeout);
|
4008
|
+
}
|
4009
|
+
|
4010
|
+
// error event is trigerred both with XDR/XHR on:
|
4011
|
+
// - DNS error
|
4012
|
+
// - unallowed cross domain request
|
4013
|
+
reject(new Error('Could not connect to host, error was:' + event));
|
4014
|
+
}
|
4015
|
+
|
4016
|
+
function timeout() {
|
4017
|
+
if (!support.timeout) {
|
4018
|
+
timedOut = true;
|
4019
|
+
req.abort();
|
4020
|
+
}
|
4021
|
+
|
4022
|
+
resolve(new Error('Timeout - Could not connect to endpoint ' + url));
|
4023
|
+
}
|
4024
|
+
|
4025
|
+
});
|
4026
|
+
};
|
4027
|
+
|
4028
|
+
AlgoliaSearchBrowser.prototype._request.fallback = function(url, opts) {
|
4029
|
+
url = inlineHeaders(url, opts.headers);
|
4030
|
+
|
4031
|
+
return new Promise(function(resolve, reject) {
|
4032
|
+
JSONPRequest(url, opts, function JSONPRequestDone(err, content) {
|
4033
|
+
if (err) {
|
4034
|
+
reject(err);
|
4035
|
+
return;
|
4036
|
+
}
|
4037
|
+
|
4038
|
+
resolve(content);
|
4039
|
+
});
|
4040
|
+
});
|
4041
|
+
};
|
4042
|
+
|
4043
|
+
AlgoliaSearchBrowser.prototype._promise = {
|
4044
|
+
reject: function(val) {
|
4045
|
+
return Promise.reject(val);
|
4046
|
+
},
|
4047
|
+
resolve: function(val) {
|
4048
|
+
return Promise.resolve(val);
|
4049
|
+
},
|
4050
|
+
delay: function(ms) {
|
4051
|
+
return new Promise(function(resolve/*, reject*/) {
|
4052
|
+
setTimeout(resolve, ms);
|
4053
|
+
});
|
4054
|
+
}
|
4055
|
+
};
|
4056
|
+
|
4057
|
+
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
4058
|
+
},{"12":12,"13":13,"14":14,"17":17,"18":18,"19":19,"8":8,"9":9}],17:[function(require,module,exports){
|
4059
|
+
(function (global){
|
4060
|
+
module.exports = getDocumentProtocol;
|
4061
|
+
|
4062
|
+
function getDocumentProtocol() {
|
4063
|
+
var protocol = global.document.location.protocol;
|
4064
|
+
|
4065
|
+
// when in `file:` mode (local html file), default to `http:`
|
4066
|
+
if (protocol !== 'http:' && protocol !== 'https:') {
|
4067
|
+
protocol = 'http:';
|
1695
4068
|
}
|
1696
4069
|
|
1697
|
-
|
4070
|
+
return protocol;
|
4071
|
+
}
|
4072
|
+
|
4073
|
+
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
4074
|
+
},{}],18:[function(require,module,exports){
|
4075
|
+
module.exports = inlineHeaders;
|
4076
|
+
|
4077
|
+
var querystring = require(4);
|
4078
|
+
|
4079
|
+
function inlineHeaders(url, headers) {
|
4080
|
+
if (/\?/.test(url)) {
|
4081
|
+
url += '&';
|
4082
|
+
} else {
|
4083
|
+
url += '?';
|
4084
|
+
}
|
1698
4085
|
|
1699
|
-
return
|
4086
|
+
return url + querystring.encode(headers);
|
1700
4087
|
}
|
1701
4088
|
|
1702
|
-
},{"
|
4089
|
+
},{"4":4}],19:[function(require,module,exports){
|
4090
|
+
module.exports="3.3.0"
|
4091
|
+
},{}]},{},[15]);
|