-
Notifications
You must be signed in to change notification settings - Fork 0
/
FamilySearch.min.js
1 lines (1 loc) · 8.83 KB
/
FamilySearch.min.js
1
var FamilySearch=function(e){function t(n){if(o[n])return o[n].exports;var r=o[n]={exports:{},id:n,loaded:!1};return e[n].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var o={};return t.m=e,t.c=o,t.p="",t(0)}([function(e,t,o){function n(e){return function(t,o,n){"function"==typeof o&&(n=o,o={}),o.method=e,this.request(t,o,n)}}var r=o(1),i=o(2),s=o(3),a=o(4),c=o(5),u=o(12),d=function(e){if(this.appKey=e.appKey,this.environment=e.environment||"integration",this.redirectUri=e.redirectUri,this.tokenCookie=e.tokenCookie||"FS_AUTH_TOKEN",this.maxThrottledRetries=e.maxThrottledRetries||10,this.saveAccessToken=e.saveAccessToken===!0,this.middleware={request:[c.url,c.defaultAcceptHeader,c.authorizationHeader,c.disableAutomaticRedirects,c.body],response:[u.redirect,u.throttling,u.json]},Array.isArray(e.pendingModifications)&&e.pendingModifications.length>0&&this.addRequestMiddleware(c.pendingModifications(e.pendingModifications)),this.saveAccessToken)if(e.accessToken)this.setAccessToken(e.accessToken);else{var t=r.getItem(this.tokenCookie);t&&(this.accessToken=t)}};d.prototype.oauthRedirect=function(e){window.location.href=this.oauthRedirectURL(e)},d.prototype.oauthRedirectURL=function(e){var t=this.identHost()+"/cis-web/oauth2/v3/authorization?response_type=code&client_id="+this.appKey+"&redirect_uri="+this.redirectUri;return e&&(t+="&state="+e),t},d.prototype.oauthResponse=function(e,t){1===arguments.length&&(t=e,e=void 0);var o=a.getParameterByName("state");if(e&&e!==o)return!1;var n=a.getParameterByName("code");return!!n&&(this.oauthToken(n,t),!0)},d.prototype.oauthToken=function(e,t){var o=this;o.post(o.identHost()+"/cis-web/oauth2/v3/token",{body:{grant_type:"authorization_code",code:e,client_id:o.appKey},headers:{"Content-Type":"application/x-www-form-urlencoded"}},function(e,n){o.processOauthResponse(e,n,t)})},d.prototype.oauthPassword=function(e,t,o){var n=this;this.post(this.identHost()+"/cis-web/oauth2/v3/token",{body:{grant_type:"password",client_id:this.appKey,username:e,password:t},headers:{"Content-Type":"application/x-www-form-urlencoded"}},function(e,t){n.processOauthResponse(e,t,o)})},d.prototype.processOauthResponse=function(e,t,o){t&&200===t.statusCode&&t.data&&this.setAccessToken(t.data.access_token),o&&setTimeout(function(){o(e,t)})},d.prototype.setAccessToken=function(e){return this.accessToken=e,this.saveAccessToken&&r.setItem(this.tokenCookie,e,86400),this},d.prototype.getAccessToken=function(){return this.accessToken},d.prototype.deleteAccessToken=function(){return this.accessToken=void 0,this.saveAccessToken&&r.removeItem(this.tokenCookie),this},d.prototype.addRequestMiddleware=function(e){return this.middleware.request.push(e),this},d.prototype.addResponseMiddleware=function(e){return this.middleware.response.push(e),this},d.prototype.get=n("GET"),d.prototype.post=n("POST"),d.prototype.head=n("HEAD"),d.prototype.delete=n("DELETE"),d.prototype.request=function(e,t,o){"function"==typeof t&&(o=t,t={}),this._execute(new i(e,t,o),o)},d.prototype._execute=function(e,t){function o(o,r){o?setTimeout(function(){t(o)}):n._runResponseMiddleware(e,r,function(e){setTimeout(function(){e?t(e):t(void 0,r)})})}var n=this;n._runRequestMiddleware(e,function(t,n){t||n?o(t,n):s(e,o)})},d.prototype._runRequestMiddleware=function(e,t){var o=this;a.asyncEach(this.middleware.request,function(n,r){n(o,e,function(e,o){e||o?t(e,o):r()})},t)},d.prototype._runResponseMiddleware=function(e,t,o){var n=this;a.asyncEach(this.middleware.response,function(r,i){r(n,e,t,function(e,t){e?o(e):"undefined"==typeof t&&i()})},o)},d.prototype.identHost=function(){switch(this.environment){case"production":return"https://ident.familysearch.org";case"beta":return"https://identbeta.familysearch.org";default:return"https://integration.familysearch.org"}},d.prototype.platformHost=function(){switch(this.environment){case"production":return"https://familysearch.org";case"beta":return"https://beta.familysearch.org";default:return"https://integration.familysearch.org"}},e.exports=d},function(e,t,o){!function(t){e.exports=t()}(function(){var e={getItem:function(e){return e?decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*"+encodeURIComponent(e).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*([^;]*).*$)|^.*$"),"$1"))||null:null},setItem:function(e,t,o,n,r,i){if(!e||/^(?:expires|max\-age|path|domain|secure)$/i.test(e))return!1;var s="";if(o)switch(o.constructor){case Number:s=o===1/0?"; expires=Fri, 31 Dec 9999 23:59:59 GMT":"; max-age="+o;break;case String:s="; expires="+o;break;case Date:s="; expires="+o.toUTCString()}return document.cookie=encodeURIComponent(e)+"="+encodeURIComponent(t)+s+(r?"; domain="+r:"")+(n?"; path="+n:"")+(i?"; secure":""),!0},removeItem:function(e,t,o){return!!this.hasItem(e)&&(document.cookie=encodeURIComponent(e)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT"+(o?"; domain="+o:"")+(t?"; path="+t:""),!0)},hasItem:function(e){return!!e&&new RegExp("(?:^|;\\s*)"+encodeURIComponent(e).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(document.cookie)},keys:function(){for(var e=document.cookie.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g,"").split(/\s*(?:\=[^;]*)?;\s*/),t=e.length,o=0;o<t;o++)e[o]=decodeURIComponent(e[o]);return e}};return e})},function(e,t){var o=function(e,t,o){this.url=e,this.callback=o||function(){},this.method="GET",this.headers={},this.retries=0,this.options={};var n;for(n in t)if(t.hasOwnProperty(n))switch(n){case"method":case"body":case"retries":this[n]=t[n];break;case"headers":this.headers=JSON.parse(JSON.stringify(t.headers));break;default:this.options[n]=t[n]}};o.prototype.hasHeader=function(e){return"undefined"!=typeof this.headers[e]},o.prototype.setHeader=function(e,t){return this.headers[e]=t,this},o.prototype.getHeader=function(e){return this.headers[e]},o.prototype.getHeaders=function(){return this.headers},o.prototype.isPlatform=function(){return this.url.indexOf("/platform/")!==-1},e.exports=o},function(e,t){function o(e,t){for(var o,r={};o=n.exec(e.getAllResponseHeaders());)r[o[1].toLowerCase()]=o[2];return{statusCode:e.status,statusText:e.statusText,headers:r,originalUrl:t.url,effectiveUrl:t.url,redirected:!1,requestMethod:t.method,requestHeaders:t.headers,body:e.responseText,retries:0,throttled:!1}}var n=/^(.*?):[ \t]*([^\r\n]*)$/gm;e.exports=function(e,t){var n=new XMLHttpRequest;n.open(e.method,e.url);var r=e.getHeaders();for(var i in r)r.hasOwnProperty(i)&&n.setRequestHeader(i,r[i]);n.onload=function(){var r=o(n,e);setTimeout(function(){t(null,r)})},n.onerror=function(e){setTimeout(function(){t(e)})},n.send(e.body)}},function(e,t){e.exports={urlEncode:function(e){var t=[];for(var o in e)e.hasOwnProperty(o)&&t.push(encodeURIComponent(o)+"="+encodeURIComponent(e[o]));return t.join("&")},getParameterByName:function(e){var t=RegExp("[?&]"+e+"=([^&]*)").exec(window.location.search);return t&&decodeURIComponent(t[1].replace(/\+/g," "))},asyncEach:function(e,t,o){function n(r){r===e.length?setTimeout(o):t(e[r],function(){setTimeout(function(){n(++r)})})}n(0)}}},function(e,t,o){e.exports={authorizationHeader:o(6),body:o(7),defaultAcceptHeader:o(8),disableAutomaticRedirects:o(9),pendingModifications:o(10),url:o(11)}},function(e,t){e.exports=function(e,t,o){!t.hasHeader("Authorization")&&e.getAccessToken()&&t.isPlatform()&&t.setHeader("Authorization","Bearer "+e.getAccessToken()),o()}},function(e,t,o){var n=o(4);e.exports=function(e,t,o){!t.body||"POST"!==t.method&&"PUT"!==t.method||(!t.hasHeader("Content-Type")&&t.isPlatform()&&t.setHeader("Content-Type","application/x-fs-v1+json"),"string"!=typeof t.body&&(t.hasHeader("Content-Type")&&t.getHeader("Content-Type").indexOf("json")!==-1?t.body=JSON.stringify(t.body):t.body=n.urlEncode(t.body))),o()}},function(e,t){e.exports=function(e,t,o){!t.hasHeader("Accept")&&t.isPlatform()&&t.setHeader("Accept","application/x-fs-v1+json"),o()}},function(e,t){e.exports=function(e,t,o){!t.hasHeader("X-Expect-Override")&&t.isPlatform()&&t.setHeader("X-Expect-Override","200-ok"),o()}},function(e,t){e.exports=function(e){var t=e.join(",");return function(e,o,n){o.headers["X-FS-Feature-Tag"]=t,n()}}},function(e,t){e.exports=function(e,t,o){t.url.indexOf("https://")===-1&&(t.url=e.platformHost()+t.url),o()}},function(e,t,o){e.exports={json:o(13),redirect:o(14),throttling:o(15)}},function(e,t){e.exports=function(e,t,o,n){var r=o.headers["content-type"];if(r&&r.indexOf("json")!==-1)try{o.data=JSON.parse(o.body)}catch(e){}n()}},function(e,t){e.exports=function(e,t,o,n){var r=o.headers.location;if(t.options.followRedirect&&r&&r!==t.url){var i=t.url;return t.url=o.headers.location,e._execute(t,function(e,o){o&&(o.originalUrl=i,o.redirected=!0),setTimeout(function(){t.callback(e,o)})}),n(void 0,!0)}n()}},function(e,t){e.exports=function(e,t,o,n){if(429===o.statusCode&&t.retries<e.maxThrottledRetries){var r=1e3*parseInt(o.headers.retry,10)||1e3;return setTimeout(function(){e._execute(t,function(e,o){o.throttled=!0,o.retries=++t.retries,setTimeout(function(){t.callback(e,o)})})},r),n(void 0,!0)}n()}}]);