Created
November 6, 2019 03:45
-
-
Save shermozle/7726cbacc2d60a1ea1cc7b990d1c8129 to your computer and use it in GitHub Desktop.
BBC unminified https://mybbc.files.bbci.co.uk/s/id/account-idcta/1.23.4/modules/idcta-v2/dist/idcta-1.min.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define("idcta-v2/logger", [], function() { | |
var e = {}; | |
return e.logCaughtError = function(e) { | |
window.console && e.message && console.log(e) | |
}, e.logMessage = function(e) { | |
document.cookie.match(new RegExp("ckns_debugtoken=([^;]+)")) && (window.tokenRefeshLog = window.tokenRefeshLog || [], window.tokenRefeshLog.push(e)) | |
}, e | |
}), define("idcta-v2/optional", ["idcta-v2/logger"], function(e) { | |
var t = {}; | |
return t.load = function(t, r, n) { | |
r([t], n, function(t) { | |
var r = t.requireModules && t.requireModules[0]; | |
e.logCaughtError("Could not load optional module: " + r), n(null) | |
}) | |
}, t | |
}), define("idcta-v2/istats", ["idcta-v2/optional!istats-1"], function(e) { | |
return e || { | |
getSite: function() {}, | |
_getLabels: function() { | |
return { | |
app_name: "", | |
prod_name: "" | |
} | |
} | |
} | |
}), define("idcta-v2/apiUtils", ["idcta-v2/es6-promise", "idcta-v2/istats", "idcta-v2/logger"], function(e, t, r) { | |
function n(e, t) { | |
var r = e.split("#"), | |
n = r[0], | |
o = r[1], | |
i = n.split("?"), | |
s = i[1], | |
a = s ? s.split("&").reduce(function(e, t) { | |
var r = t.split("="), | |
n = r[0], | |
o = r[1]; | |
return e[n] = o, e | |
}, {}) : {}, | |
c = Object.assign({}, a, t), | |
u = Object.keys(c).map(function(e) { | |
return e + "=" + c[e] | |
}).join("&"), | |
g = u ? i[0] + "?" + u : i[0]; | |
return o ? g + "#" + o : g | |
} | |
function o(e, t) { | |
var r = t.substring(0, t.indexOf("=") + 1); | |
if (e.indexOf(r) > -1) return e; | |
var n = e.split("#"), | |
o = e.indexOf("?") > -1 ? "&" : "?"; | |
return n.length > 1 ? n[0] + o + t + "#" + n[1] : e + o + t | |
} | |
function i() { | |
var e = { | |
context: "", | |
userOrigin: "" | |
}; | |
try { | |
var n = t.getSite(); | |
if (n) { | |
var o = n.split(" ").shift(); | |
return { | |
context: o, | |
userOrigin: o | |
} | |
} | |
var i = t._getLabels(); | |
if (i) { | |
var s = i.app_name || i.prod_name, | |
o = s ? s.split(" ").shift() : ""; | |
return { | |
context: o, | |
userOrigin: o | |
} | |
} | |
return e | |
} catch (t) { | |
return r.logCaughtError(t), e | |
} | |
} | |
function s() { | |
return i() | |
} | |
function a() { | |
var e = { | |
context: "", | |
userOrigin: "" | |
}; | |
return window.bbcpage && window.bbcpage.getDestination ? window.bbcpage.getDestination().then(function(t) { | |
if (t) { | |
return { | |
context: t.replace(/_TEST$/, "").replace(/_PS$/, "").replace(/_GNL$/, ""), | |
userOrigin: t | |
} | |
} | |
return e | |
}) : u.Promise.resolve(e) | |
} | |
function c() { | |
this.promise = {}, this.resolver = {} | |
} | |
var u = {}; | |
return u.verifyEndpointUrl = function(e, t) { | |
try { | |
!1 !== t && (t = !0); | |
if (/https?:\/\/(((www|ssl)(\.int|\.test|\.stage)?)|(pal\.sandbox\.dev))\.bbc\.(co\.uk|com)/.test(e)) return /(\.com|\.co\.uk)\/.+/.test(e) && (e = e.split(/(\.com|\.co\.uk)\/.+/)[0] + e.split(/(\.com|\.co\.uk)\/.+/)[1]), e; | |
var n = ""; | |
"https" == e.slice(0, 5) ? (n += (t ? "https://" : "") + "ssl.", e.indexOf(".sandbox.") > -1 && (n += "sandbox.dev.")) : (n += t ? "http://" : "", e.indexOf(".sandbox.") > -1 ? n += "pal.sandbox.dev." : n += "www."); | |
for (var o = ["int", "test", "stage"], i = 0; i < o.length; i++) e.indexOf("." + o[i] + ".") > -1 && (n += o[i] + "."); | |
return /\.co\.uk/.test(e) ? n += "bbc.co.uk" : n += "bbc.com", n | |
} catch (e) { | |
r.logCaughtError(e) | |
} | |
}, u.alignTldWithHostname = function(e, t) { | |
try { | |
var n = t || window.location.hostname, | |
o = n.split(/(\.com|\.co\.uk)$/)[1], | |
i = e.split(/(\.com|\.co\.uk)\/.+/)[1]; | |
return i !== o && void 0 !== o && (e = e.replace(i, o)), e | |
} catch (e) { | |
r.logCaughtError(e) | |
} | |
}, u.appendProductToCtaElement = function(e) { | |
var t = "", | |
r = "", | |
n = e.getAttribute("href"); | |
if (n && (-1 === n.indexOf("userOrigin=") || -1 === n.indexOf("context="))) return u.getProductNameAsync().then(function(n) { | |
if (void 0 !== n && "" !== n) { | |
t = "userOrigin=" + n.userOrigin, r = "context=" + n.context; | |
var i = e.getAttribute("href"), | |
s = u.parseUrl(i); | |
if (s) { | |
var a = (u.parseQueryString(s.search), s.pathname); - 1 === s.pathname.indexOf("/") && (a = "/" + s.pathname), e.setAttribute("href", s.protocol + "//" + s.host + a + o(o(s.search, t), r) + s.hash) | |
} | |
} | |
}) | |
}, u.appendQueryParameters = n, u.addQueryParameter = o, u.getProductName = s, u.getProductNameAsync = a, u.Promise = function() { | |
try { | |
return "undefined" != typeof Promise ? Promise : e.Promise | |
} catch (e) { | |
r.logCaughtError(e) | |
} | |
}(), u.loadUrlInHiddenIframe = function(e, t, n) { | |
try { | |
return new u.Promise(function(o, i) { | |
r.logMessage('Creating iframe {src: "' + e + '", timeout: ' + t + (n ? ', expectedPostMessages: ["' + n.join('", "') + '"]}' : "}")); | |
var s = document.createElement("iframe"); | |
s.scrolling = "no", s.frameborder = "0", s.width = "0px", s.height = "0px", s.border = "0px", s.style.display = "none", s.style.frameBorder = "0px", s.style.borderStyle = "none"; | |
var a = null, | |
c = function(e) { | |
var t = e.message ? "message" : "data"; | |
return e.origin.match(/\.bbc\.(co\.uk|com)(:[0-9]+)*$/) && -1 != n.indexOf(e[t]) ? (r.logMessage('Iframe received message "' + e[t] + '", resolving'), g(), o(e[t])) : void r.logMessage('Iframe received unexpected message "' + e[t] + '", ignoring') | |
}, | |
g = function() { | |
a && clearTimeout(a), n && u.removeEventListener("message", c), document.body.removeChild(s) | |
}; | |
n ? u.addEventListener("message", c) : s.onload = function() { | |
return r.logMessage('Iframe with src "' + e + '" loading complete'), g(), o() | |
}, t && (a = setTimeout(function() { | |
return r.logMessage("Iframe with src " + e + " timed out after " + t + " milli seconds"), g(), i() | |
}, t)), s.src = e, document.body.appendChild(s) | |
}) | |
} catch (e) { | |
r.logCaughtError(e) | |
} | |
}, u.addEventListener = function(e, t, r) { | |
u.addEventListenerTo(window, e, t, r) | |
}, u.addEventListenerTo = function(e, t, n, o) { | |
try { | |
return e.addEventListener ? e.addEventListener(t, n, o) : (t = "message" == t ? "onmessage" : t, e.attachEvent(t, n)) | |
} catch (e) { | |
r.logCaughtError(e) | |
} | |
}, u.removeEventListener = function(e, t) { | |
u.removeEventListenerFrom(window, e, t) | |
}, u.removeEventListenerFrom = function(e, t, n) { | |
try { | |
return e.removeEventListener ? e.removeEventListener(t, n) : (t = "message" == t ? "onmessage" : t, e.detachEvent(t, n)) | |
} catch (e) { | |
r.logCaughtError(e) | |
} | |
}, u.getEnvFromUrl = function() { | |
try { | |
var e = window.location.href; | |
return e.indexOf(".sandbox.") > -1 ? ".sandbox.dev" : e.indexOf(".int.") > -1 ? ".int" : e.indexOf(".test.") > -1 ? ".test" : e.indexOf(".stage.") > -1 ? ".stage" : "" | |
} catch (e) { | |
r.logCaughtError(e) | |
} | |
}, u.parseUrl = function(e) { | |
try { | |
var t = document.createElement("a"); | |
return t.href = e, t.query = t.search ? u.parseQueryString(t.search) : {}, t | |
} catch (e) { | |
r.logCaughtError(e) | |
} | |
}, u.parseQueryString = function(e) { | |
try { | |
"?" === e.charAt(0) && (e = e.substring(1)); | |
for (var t = {}, n = e.split("&"), o = 0; o < n.length; o++) { | |
var i = n[o].split("="); | |
t[decodeURIComponent(i[0])] = decodeURIComponent(i[1] || "") | |
} | |
return t | |
} catch (e) { | |
r.logCaughtError(e) | |
} | |
}, u.timestampInFuture = function(e) { | |
try { | |
return e > (new Date).getTime() | |
} catch (e) { | |
r.logCaughtError(e) | |
} | |
}, u.timestampExpired = function(e) { | |
try { | |
return e < (new Date).getTime() | |
} catch (e) { | |
r.logCaughtError(e) | |
} | |
}, u.generateFutureTimestamp = function(e) { | |
try { | |
e = e || 36e5; | |
var t = new Date; | |
return t.setTime(t.getTime() + e), t.getTime() | |
} catch (e) { | |
r.logCaughtError(e) | |
} | |
}, r.logCaughtError = function(e) { | |
window.console && e.message && console.log(e) | |
}, r.logMessage = function(e) { | |
document.cookie.match(new RegExp("ckns_debugtoken=([^;]+)")) && (window.tokenRefeshLog = window.tokenRefeshLog || [], window.tokenRefeshLog.push(e)) | |
}, c.prototype.isSet = function(e) { | |
return void 0 !== this.resolver[e] | |
}, c.prototype.set = function(e, t) { | |
this.resolver[e] = t | |
}, c.prototype.get = function(e) { | |
function t() { | |
var t = r.resolver[e]; | |
return "function" != typeof t ? u.Promise.reject(new TypeError("Promise resolver " + t + " is not a function for key " + e)) : new u.Promise(t).then(function(t) { | |
return delete r.promise[e], delete r.pending, t | |
}, function(t) { | |
throw delete r.promise[e], delete r.pending, t | |
}) | |
} | |
var r = this; | |
return this.promise[e] ? this.promise[e] : this.pending ? (this.promise[e] = this.pending.then(t, t), this.pending = this.promise[e], this.promise[e]) : (this.promise[e] = t(), this.pending = this.promise[e], this.promise[e]) | |
}, u.PromisePool = c, u | |
}), define("idcta-v2/id-config", ["idcta-v2/config", "idcta-v2/translations", "idcta-v2/apiUtils", "idcta-v2/logger"], function(e, t, r, n) { | |
function o(e, t) { | |
if (t) { | |
var r = new Error("Deprecation warning: accessing the property '" + e + "' is deprecated and will be removed in a future version. Use '.getConfigAsync()' instead."); | |
console.warn(r), n.logMessage(r.message) | |
} | |
} | |
function i(n, i) { | |
var a = { | |
context: n.context, | |
userOrigin: n.userOrigin | |
}; | |
return { | |
get announce_url() { | |
return o("announce_url", i), r.alignTldWithHostname(e.announce_url) | |
}, | |
get "bbcid-v5" () { | |
return o("bbcid-v5", i), e["bbcid-v5"] | |
}, | |
get child_parent_linking_url() { | |
return o("child_parent_linking_url", i), e.child_parent_linking_url | |
}, | |
get "id-availability" () { | |
return o("id-availability", i), e["id-availability"] | |
}, | |
get identity() { | |
return o("identity", i), { | |
cookieAgeDays: e.identity.cookieAgeDays, | |
accessTokenCookieName: e.identity.accessTokenCookieName, | |
idSignedInCookieName: e.identity.idSignedInCookieName | |
} | |
}, | |
get identityTokenExchangeUrl() { | |
return o("identityTokenExchangeUrl", i), r.alignTldWithHostname(e.identityTokenExchangeUrl) | |
}, | |
get privacy_settings_url() { | |
return o("privacy_settings_url", i), e.privacy_settings_url | |
}, | |
get ptrt() { | |
return o("ptrt", i), window.location.href | |
}, | |
get register_url() { | |
return o("register_url", i), r.appendQueryParameters(r.alignTldWithHostname(e.register_url), a) | |
}, | |
get settings_url() { | |
return o("settings_url", i), r.appendQueryParameters(e.settings_url, a) | |
}, | |
get signin_url() { | |
return o("signin_url", i), r.appendQueryParameters(r.alignTldWithHostname(e.signin_url), a) | |
}, | |
get signout_url() { | |
return o("signout_url", i), r.appendQueryParameters(e.signout_url, a) | |
}, | |
get status_url() { | |
return o("status_url", i), r.appendQueryParameters(e.status_url, a) | |
}, | |
get tld() { | |
return o("tld", i), s | |
}, | |
get tokenRefresh() { | |
return o("tokenRefresh", i), e.tokenRefresh || !1 | |
}, | |
get tokenRefresh_signout_url() { | |
return o("tokenRefresh_signout_url", i), r.alignTldWithHostname(e.tokenRefresh_signout_url) | |
}, | |
get tokenRefresh_url() { | |
return o("tokenRefresh_url", i), r.alignTldWithHostname(e.tokenRefresh_url) | |
}, | |
get translation_signedin() { | |
return o("translation_signedin", i), t.translation_statusbar_signedin | |
}, | |
get translation_signedout() { | |
return o("translation_signedout", i), t.translation_statusbar_signedout | |
} | |
} | |
} | |
var s = function() { | |
var e = window.location.host.split("."); | |
return "co" === e[e.length - 2] && "uk" === e[e.length - 1] ? e[e.length - 3] + ".co.uk" : e[e.length - 2] + "." + e[e.length - 1] | |
}(), | |
a = i(r.getProductName(), !0), | |
c = r.getProductNameAsync().then(i); | |
return a.getConfigAsync = function() { | |
return c | |
}, a.getDomain = function() { | |
return s | |
}, a.getIdentity = function() { | |
return e.identity | |
}, a.getFeatureDecisions = function() { | |
return e.features | |
}, a.getConfig = function() { | |
return o("getConfig", !0), a | |
}, a | |
}), define("idcta-v2/idCookie", ["idcta-v2/id-config", "idcta-v2/logger"], function(e, t) { | |
function r() { | |
try { | |
return a ? (a.refreshCookie(), a) : a = new s | |
} catch (e) { | |
t.logCaughtError(e) | |
} | |
} | |
function n(e) { | |
try { | |
a = e | |
} catch (e) { | |
t.logCaughtError(e) | |
} | |
} | |
function o(e) { | |
try { | |
var t = window.atob(e), | |
r = t.lastIndexOf("}"), | |
n = t.substring(0, r + 1); | |
return JSON.parse(n) | |
} catch (e) { | |
return null | |
} | |
} | |
function i(e, r, n, o) { | |
try { | |
r = r || ""; | |
var i = ""; | |
if (n) { | |
var s = new Date; | |
s.setTime(s.getTime() + n), i = "Expires=" + s.toUTCString() + "; " | |
} | |
r = o ? window.btoa(r) : r, document.cookie = e + "=" + r + "; " + i + "Domain=" + g + "; Path=/" | |
} catch (e) { | |
t.logCaughtError(e) | |
} | |
} | |
function s() { | |
function e() { | |
var e = new RegExp(d + "=([\\w]+)"), | |
t = document.cookie.match(e); | |
if (!t) return void a(); | |
var r = o(t[1]); | |
if (!r || !n(r) || s(r)) return void a(); | |
c.valid = !0, c.displayname = r.dn, c.timestamp = r["jwt-exp"] | |
} | |
function r() { | |
var e = c.cookieAgeDays * u; | |
return (new Date).getTime() - c.timestamp >= e | |
} | |
function n(e) { | |
return e.hasOwnProperty("ps") && e.hasOwnProperty("jwt-exp") && e.hasOwnProperty("tkn-exp") && (e.hy || e.hasOwnProperty("ses-exp")) | |
} | |
function s(e) { | |
var t = (new Date).getTime(); | |
return (e["jwt-exp"] || 0) <= t | |
} | |
function a() { | |
c.valid = !1, c.id = "", c.username = "~", c.displayname = "", c.timestamp = "" | |
} | |
var c = this; | |
this.valid = !1, this.id = "", this.username = "~", this.displayname = "", this.timestamp = "", this.cookieAgeDays = l, this.isIdv5On = !0, this.refreshCookie = function() { | |
try { | |
e() | |
} catch (e) { | |
t.logCaughtError(e) | |
} | |
}, this.hasCookie = function() { | |
try { | |
return r() && a(), c.valid | |
} catch (e) { | |
t.logCaughtError(e) | |
} | |
}, this.hasAccessTokenExpired = function() { | |
try { | |
var e = this.getUserDetailsFromCookie(); | |
if (!e) return !0; | |
var r = (new Date).getTime(); | |
return (e["tkn-exp"] || 0) <= r | |
} catch (e) { | |
t.logCaughtError(e) | |
} | |
}, this.hasJwtTokenExpired = function() { | |
try { | |
var e = this.getUserDetailsFromCookie(); | |
if (!e) return !0; | |
var r = (new Date).getTime(); | |
return (e["jwt-exp"] || 0) <= r | |
} catch (e) { | |
t.logCaughtError(e) | |
} | |
}, this.isHybridApp = function() { | |
try { | |
var e = this.getUserDetailsFromCookie(); | |
return !!e && (e.hy || !1) | |
} catch (e) { | |
t.logCaughtError(e) | |
} | |
}, this.getError = function() { | |
try { | |
var e = this.getUserDetailsFromCookie(); | |
return e ? e.ec || null : null | |
} catch (e) { | |
t.logCaughtError(e) | |
} | |
}, this.getIdFromCookie = function() { | |
try { | |
var e = this.getUserDetailsFromCookie(); | |
return e ? e.ps : null | |
} catch (e) { | |
t.logCaughtError(e) | |
} | |
}, this.getHidFromCookie = function() { | |
return this.getCookie(f) || this.getCookie(m) | |
}, this.isPersonalisationEnabled = function() { | |
try { | |
var e = this.getUserDetailsFromCookie(); | |
return e && e.ep | |
} catch (e) { | |
return t.logCaughtError(e), !1 | |
} | |
}, this.getUserDetailsFromCookie = function() { | |
try { | |
if (!this.hasCookie()) return null; | |
var e = new RegExp(d + "=([\\w]+)"), | |
r = document.cookie.match(e); | |
if (!r) return null; | |
var i = decodeURIComponent(r[1]).split("|"), | |
s = o(i.toString()); | |
return s && n(s) ? s : null | |
} catch (e) { | |
t.logCaughtError(e) | |
} | |
}, this.getNameFromCookie = function() { | |
try { | |
return this.hasCookie() && (c.displayname && "" !== c.displayname) ? c.displayname.replace(/\+/g, " ") : null | |
} catch (e) { | |
t.logCaughtError(e) | |
} | |
}, this.getAccessToken = function() { | |
try { | |
if (!this.hasCookie()) return null; | |
var e = new RegExp(h + "=([^;]*)"), | |
r = document.cookie.match(e); | |
return null !== r ? r[1] : null | |
} catch (e) { | |
t.logCaughtError(e) | |
} | |
}, this.getCookie = function(e, r) { | |
try { | |
var n = new RegExp(e + "=([^\\s;]*)"), | |
i = document.cookie.match(n); | |
if (!i) return null; | |
if (!0 !== r) return i[1]; | |
return o(decodeURIComponent(i[1])) | |
} catch (e) { | |
t.logCaughtError(e) | |
} | |
}, this.setCknsIdCookieProperty = function(e, r) { | |
try { | |
var n = this.getUserDetailsFromCookie(); | |
if (!n) return; | |
r ? n[e] = r : delete n[e]; | |
var o = n["jwt-exp"] ? n["jwt-exp"] : u * l; | |
i(d, JSON.stringify(n), o, !0) | |
} catch (e) { | |
t.logCaughtError(e) | |
} | |
}, this.unsetCookie = function(e) { | |
try { | |
document.cookie = e + "=; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Domain=" + g + "; Path=/" | |
} catch (e) { | |
t.logCaughtError(e) | |
} | |
}, | |
function() { | |
e() | |
}() | |
} | |
var a, c = {}, | |
u = 864e5, | |
g = e.getDomain(), | |
d = e.getIdentity() && e.getIdentity().idSignedInCookieName ? e.getIdentity().idSignedInCookieName : "ckns_id", | |
l = e.getIdentity() && e.getIdentity().cookieAgeDays ? e.getIdentity().cookieAgeDays : 730, | |
h = e.getIdentity() && e.getIdentity().accessTokenCookieName ? e.getIdentity().accessTokenCookieName : "ckns_atkn", | |
f = "ckns_sylphid", | |
m = "ckpf_sylphid"; | |
return c.getInstance = r, c.setInstance = n, c | |
}), define("idcta-v2/tokenRefresh", ["idcta-v2/id-config", "idcta-v2/idCookie", "idcta-v2/apiUtils", "idcta-v2/logger"], function(e, t, r, n) { | |
function o(o, a) { | |
var c = t.getInstance(), | |
u = new Date, | |
d = u.getTime(); | |
n.logMessage("Token refresh " + d + " starting [" + u + "]"); | |
try { | |
if (!c.hasCookie()) return n.logMessage("Token refresh " + d + " rejected as ckns_id cookie is missing, invalid or expired!"), r.Promise.reject(new i); | |
if (c.isHybridApp()) return n.logMessage("Token refresh " + d + " rejected, hybrid app detected"), r.Promise.reject(new s); | |
var k = c.getError(); | |
if (k && r.timestampInFuture(k.retryAfter)) return n.logMessage("Token refresh " + d + " rejected as there is error in cookie { code: " + k.code + ', message: "' + k.message + '", retryAfter: ' + k.retryAfter + "}"), r.Promise.reject(k); | |
if (!0 !== o && !c.hasAccessTokenExpired()) return n.logMessage("Token refresh " + d + " resolved without action as token has not expired"), r.Promise.resolve(); | |
o && n.logMessage("Token refresh " + d + " forced even though token may not have expired"), h.isSet(a) ? n.logMessage("Token refresh " + d + " reusing existing promise in progress for " + a) : h.set(a, function(t, n) { | |
e.getConfigAsync().then(function(e) { | |
var t = e.tokenRefresh_url; | |
t = a ? r.alignTldWithHostname(t, a) : t, t = r.addQueryParameter(t, "tr=" + d); | |
var n = e.announce_url || ""; | |
return n = a ? r.alignTldWithHostname(n, a) : n, n = r.addQueryParameter(n, "tr=" + d), n = encodeURIComponent(n), t = t.replace(e.announce_url, n), r.loadUrlInHiddenIframe(t, g, l) | |
}).then(t, n) | |
}); | |
var C = function() { | |
n.logMessage("Token refresh " + d + " complete.") | |
}, | |
w = function(e) { | |
throw n.logMessage("Token refresh " + d + " failed with error { code: " + e.code + ', message: "' + e.message + '", retryAfter: ' + e.retryAfter + "}"), e | |
}; | |
return h.get(a).then(null, f).then(m).then(p).then(null, v).then(null, y).then(C, w) | |
} catch (e) { | |
n.logCaughtError(e) | |
} | |
} | |
function i() { | |
this.code = 401, this.message = "Invalid session" | |
} | |
function s() { | |
this.code = 401, this.message = "Unauthorised" | |
} | |
function a(e) { | |
this.code = 500, this.message = "Unauthorised", this.retryAfter = e || (new Date).getTime() + d | |
} | |
function c(e) { | |
this.code = 408, this.message = "Request timeout", this.retryAfter = e || (new Date).getTime() + d | |
} | |
function u(e) { | |
h = e | |
} | |
var g = 15e3, | |
d = 15e3, | |
l = ["bbcidv5_token_success", "error", "invalid"], | |
h = new r.PromisePool, | |
f = function() { | |
return e.getConfigAsync().then(function(e) { | |
var r = (new Date).getTime() + (e.tokenRefresh ? d : 36e5), | |
o = new c(r); | |
throw t.getInstance().setCknsIdCookieProperty("ec", o), n.logMessage("Token refresh - timed out, error added to cookie, if cookie exists { code: " + o.code + ', message: "' + o.message + '", retryAfter: ' + o.retryAfter + "}"), o | |
}) | |
}, | |
m = function(e) { | |
if ("invalid" !== e) return e; | |
throw n.logMessage("Token refresh - invalid session error"), new i | |
}, | |
p = function(e) { | |
if ("bbcidv5_token_success" === e) return e; | |
var r = t.getInstance().getError(); | |
throw r ? n.logMessage("Token refresh - unsuccessful, throwing error from cookie { code: " + r.code + ', message: "' + r.message + '", retryAfter: ' + r.retryAfter + "}") : n.logMessage("Token refresh - unsuccessful, no error found in cookie"), r | |
}, | |
v = function(e) { | |
if (e) throw e; | |
throw e = new a, t.getInstance().setCknsIdCookieProperty("ec", e), n.logMessage("Token refresh - Internal service error, error added to cookie, if cookie exists { code: " + e.code + ', message: "' + e.message + '", retryAfter: ' + e.retryAfter + "}"), e | |
}, | |
y = function(e) { | |
if (e.code != (new i).code) throw e; | |
throw n.logMessage("Token refresh - Invalid session error, error added to cookie { code: " + e.code + ', message: "' + e.message + '", retryAfter: ' + e.retryAfter + "}"), e | |
}; | |
i.prototype.name = "InvalidSessionError", s.prototype.name = "UnauthorisedError", a.prototype.name = "InternalServiceError", c.prototype.name = "RequestTimeoutError"; | |
var k = {}; | |
return k.refreshAccessToken = o, k.setPromisePool = u, k.RETRY_AFTER_SHORT = d, k.RETRY_AFTER_LONG = 36e5, k.MESSAGE_SUCCESS = "bbcidv5_token_success", k.MESSAGE_ERROR = "error", k.MESSAGE_INVALID = "invalid", k.RETRY_AFTER_SHORT = d, k.RETRY_AFTER_LONG = 36e5, k | |
}), define("idcta-v2/idcta-1", ["idcta-v2/idCookie", "idcta-v2/apiUtils", "idcta-v2/tokenRefresh", "idcta-v2/logger", "idcta-v2/id-config"], function(e, t, r, n, o) { | |
function i(t) { | |
"PS_ACCOUNT_TEST" === t && requirejs(["idcta-v2/signInPrompt"], function(t) { | |
e.getInstance().hasCookie() ? t.deleteCookie() : t.initialise() | |
}) | |
} | |
function s(t) { | |
try { | |
this.id = t.id, this.element = document.getElementById(t.id), this.states = t.states; | |
var r = this; | |
f.ctas[r.id] = r, !0 === t.publiclyCacheable && (e.getInstance().hasCookie() ? c(r) : r.element.getElementsByTagName("span")[0].innerText = r.states.unauthorised.signedout) | |
} catch (e) { | |
n.logCaughtError(e) | |
} | |
} | |
function a(e) { | |
var r = document.querySelectorAll("#" + e), | |
n = function() { | |
t.appendProductToCtaElement(this) | |
}; | |
if (r.length) | |
for (var o = 0; o < r.length; o++) | |
for (var i = r[o].getElementsByTagName("a"), s = 0; s < i.length; s++) t.addEventListenerTo(i[s], "click", n, !1) | |
} | |
function c(t) { | |
if (t.states.authorised) { | |
var r = e.getInstance().getNameFromCookie(), | |
n = t.states.authorised.anonymous; | |
r && (n = t.states.authorised.name.replace("{name}", r)), t.element.getElementsByTagName("span")[0].innerText = n | |
} else t.element.parentNode && t.element.parentNode.removeChild(t.element) | |
} | |
function u(e, t) { | |
try { | |
return e = !0 === e, r.refreshAccessToken(e, t) | |
} catch (e) { | |
n.logCaughtError(e) | |
} | |
} | |
function g() { | |
try { | |
return f.initiateTokenRefresh().then(function() { | |
return !0 | |
}, function() { | |
throw !1 | |
}) | |
} catch (e) { | |
n.logCaughtError(e) | |
} | |
} | |
function d(e, r, o) { | |
try { | |
var i = document.querySelector("#" + e + " span"), | |
s = ["small", "medium", "large"], | |
a = ["blue", "white"]; | |
s.indexOf(r) > -1 && (i.className = i.className.replace(/small|medium|large/g, r)), a.indexOf(o) > -1 && (i.className = i.className.replace(/blue|white/g, o)); | |
var c = document.querySelectorAll("#" + e + " span a"); | |
for (var u in c) c.hasOwnProperty(u) && t.appendProductToCtaElement(c[u]) | |
} catch (e) { | |
n.logCaughtError(e) | |
} | |
} | |
function l(e, r) { | |
try { | |
var o = document.querySelectorAll("#" + e + " a"); | |
if (!o.length) throw "No cta elements found with provided Id"; | |
for (var i in o) | |
if (o.hasOwnProperty(i)) { | |
var s = o[i].getAttribute("href"), | |
a = decodeURIComponent(s).match(/ptrt\=([a-zA-Z:\/\/\_\\0-9.-]*)&?/).pop(); | |
a = encodeURIComponent(a); | |
var c = s.substring(0, s.indexOf(a)), | |
u = s.substring(s.indexOf(a) + a.length); | |
o[i].setAttribute("href", c + r + u), t.appendProductToCtaElement(o[i]) | |
} | |
} catch (e) { | |
n.logCaughtError(e) | |
} | |
} | |
function h() { | |
try { | |
var t = {}, | |
r = e.getInstance(); | |
if (!r.hasCookie()) return t; | |
if (t.bbc_identity = "1", !r.isPersonalisationEnabled()) return t; | |
var o = r.getHidFromCookie(); | |
return o && (t.bbc_hid = o), t | |
} catch (e) { | |
return n.logCaughtError(e), {} | |
} | |
} | |
var f = { | |
signals: {}, | |
ctas: {} | |
}; | |
const m = o.getFeatureDecisions(); | |
return window.bbcpage && m.showUsiModal && window.bbcpage.getDestination().then(function(e) { | |
i(e) | |
}), f.Cta = s, f.modifyCta = d, f.modifyPtrt = l, f.addUserOrigin = a, f.initiateTokenRefresh = u, f.initiateUserUplift = g, f.getIStatsLabels = h, f.hasCookie = function() { | |
return e.getInstance().hasCookie() | |
}, f.getCookieInstance = function() { | |
return e.getInstance() | |
}, f.getIdFromCookie = function() { | |
return e.getInstance().getIdFromCookie() | |
}, f.getUserDetailsFromCookie = function() { | |
return e.getInstance().getUserDetailsFromCookie() | |
}, f.getNameFromCookie = function() { | |
return e.getInstance().getNameFromCookie() | |
}, f.getAccessToken = function(t) { | |
return e.getInstance().getAccessToken(t) | |
}, f | |
}); | |
//# sourceMappingURL=idcta-1.js.map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment