braintree-web
Version:
A suite of tools for integrating Braintree in the browser
1,302 lines (1,246 loc) • 153 kB
JavaScript
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.braintree || (g.braintree = {})).localPayment = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(_dereq_,module,exports){
"use strict";
var scriptPromiseCache = {};
function loadScript(options) {
var scriptLoadPromise;
var stringifiedOptions = JSON.stringify(options);
if (!options.forceScriptReload) {
scriptLoadPromise = scriptPromiseCache[stringifiedOptions];
if (scriptLoadPromise) {
return scriptLoadPromise;
}
}
var script = document.createElement("script");
var attrs = options.dataAttributes || {};
var container = options.container || document.head;
script.src = options.src;
script.id = options.id || "";
script.async = true;
if (options.type) {
script.setAttribute("type", "".concat(options.type));
}
if (options.crossorigin) {
script.setAttribute("crossorigin", "".concat(options.crossorigin));
}
Object.keys(attrs).forEach(function (key) {
script.setAttribute("data-".concat(key), "".concat(attrs[key]));
});
scriptLoadPromise = new Promise(function (resolve, reject) {
script.addEventListener("load", function () {
resolve(script);
});
script.addEventListener("error", function () {
reject(new Error("".concat(options.src, " failed to load.")));
});
script.addEventListener("abort", function () {
reject(new Error("".concat(options.src, " has aborted.")));
});
container.appendChild(script);
});
scriptPromiseCache[stringifiedOptions] = scriptLoadPromise;
return scriptLoadPromise;
}
loadScript.clearCache = function () {
scriptPromiseCache = {};
};
module.exports = loadScript;
},{}],2:[function(_dereq_,module,exports){
module.exports = _dereq_("./dist/load-script");
},{"./dist/load-script":1}],3:[function(_dereq_,module,exports){
"use strict";
module.exports = function isAndroid(ua) {
ua = ua || window.navigator.userAgent;
return /Android/i.test(ua);
};
},{}],4:[function(_dereq_,module,exports){
"use strict";
var isEdge = _dereq_("./is-edge");
var isSamsung = _dereq_("./is-samsung");
var isDuckDuckGo = _dereq_("./is-duckduckgo");
var isOpera = _dereq_("./is-opera");
var isSilk = _dereq_("./is-silk");
module.exports = function isChrome(ua) {
ua = ua || window.navigator.userAgent;
return ((ua.indexOf("Chrome") !== -1 || ua.indexOf("CriOS") !== -1) &&
!isEdge(ua) &&
!isSamsung(ua) &&
!isDuckDuckGo(ua) &&
!isOpera(ua) &&
!isSilk(ua));
};
},{"./is-duckduckgo":5,"./is-edge":6,"./is-opera":13,"./is-samsung":14,"./is-silk":15}],5:[function(_dereq_,module,exports){
"use strict";
module.exports = function isDuckDuckGo(ua) {
ua = ua || window.navigator.userAgent;
return ua.indexOf("DuckDuckGo/") !== -1;
};
},{}],6:[function(_dereq_,module,exports){
"use strict";
module.exports = function isEdge(ua) {
ua = ua || window.navigator.userAgent;
return ua.indexOf("Edge/") !== -1 || ua.indexOf("Edg/") !== -1;
};
},{}],7:[function(_dereq_,module,exports){
"use strict";
module.exports = function isIosFirefox(ua) {
ua = ua || window.navigator.userAgent;
return /FxiOS/i.test(ua);
};
},{}],8:[function(_dereq_,module,exports){
"use strict";
var isIos = _dereq_("./is-ios");
function isGoogleSearchApp(ua) {
return /\bGSA\b/.test(ua);
}
module.exports = function isIosGoogleSearchApp(ua) {
ua = ua || window.navigator.userAgent;
return isIos(ua) && isGoogleSearchApp(ua);
};
},{"./is-ios":11}],9:[function(_dereq_,module,exports){
"use strict";
var isIos = _dereq_("./is-ios");
var isIosGoogleSearchApp = _dereq_("./is-ios-google-search-app");
module.exports = function isIosWebview(ua) {
ua = ua || window.navigator.userAgent;
if (isIos(ua)) {
// The Google Search iOS app is technically a webview and doesn't support popups.
if (isIosGoogleSearchApp(ua)) {
return true;
}
// Historically, a webview could be identified by the presence of AppleWebKit and _no_ presence of Safari after.
return /.+AppleWebKit(?!.*Safari)/i.test(ua);
}
return false;
};
},{"./is-ios":11,"./is-ios-google-search-app":8}],10:[function(_dereq_,module,exports){
"use strict";
var isIosWebview = _dereq_("./is-ios-webview");
module.exports = function isIosWKWebview(ua, statusBarVisible) {
statusBarVisible =
typeof statusBarVisible !== "undefined"
? statusBarVisible
: window.statusbar.visible;
return isIosWebview(ua) && statusBarVisible;
};
},{"./is-ios-webview":9}],11:[function(_dereq_,module,exports){
"use strict";
var isIpadOS = _dereq_("./is-ipados");
module.exports = function isIos(ua, checkIpadOS, document) {
if (checkIpadOS === void 0) { checkIpadOS = true; }
ua = ua || window.navigator.userAgent;
var iOsTest = /iPhone|iPod|iPad/i.test(ua);
return checkIpadOS ? iOsTest || isIpadOS(ua, document) : iOsTest;
};
},{"./is-ipados":12}],12:[function(_dereq_,module,exports){
"use strict";
module.exports = function isIpadOS(ua, document) {
ua = ua || window.navigator.userAgent;
document = document || window.document;
// "ontouchend" is used to determine if a browser is on an iPad, otherwise
// user-agents for iPadOS behave/identify as a desktop browser
return /Mac|iPad/i.test(ua) && "ontouchend" in document;
};
},{}],13:[function(_dereq_,module,exports){
"use strict";
module.exports = function isOpera(ua) {
ua = ua || window.navigator.userAgent;
return (ua.indexOf("OPR/") !== -1 ||
ua.indexOf("Opera/") !== -1 ||
ua.indexOf("OPT/") !== -1);
};
},{}],14:[function(_dereq_,module,exports){
"use strict";
module.exports = function isSamsungBrowser(ua) {
ua = ua || window.navigator.userAgent;
return /SamsungBrowser/i.test(ua);
};
},{}],15:[function(_dereq_,module,exports){
"use strict";
module.exports = function isSilk(ua) {
ua = ua || window.navigator.userAgent;
return ua.indexOf("Silk/") !== -1;
};
},{}],16:[function(_dereq_,module,exports){
"use strict";
var MINIMUM_SUPPORTED_CHROME_IOS_VERSION = 48;
var isAndroid = _dereq_("./is-android");
var isIosFirefox = _dereq_("./is-ios-firefox");
var isIosWebview = _dereq_("./is-ios-webview");
var isChrome = _dereq_("./is-chrome");
var isSamsungBrowser = _dereq_("./is-samsung");
var isDuckDuckGo = _dereq_("./is-duckduckgo");
function isUnsupportedIosChrome(ua) {
ua = ua || window.navigator.userAgent;
var match = ua.match(/CriOS\/(\d+)\./);
if (!match) {
return false;
}
var version = parseInt(match[1], 10);
return version < MINIMUM_SUPPORTED_CHROME_IOS_VERSION;
}
function isOperaMini(ua) {
ua = ua || window.navigator.userAgent;
return ua.indexOf("Opera Mini") > -1;
}
function isAndroidWebview(ua) {
var androidWebviewRegExp = /Version\/[\d.]+/i;
ua = ua || window.navigator.userAgent;
if (isAndroid(ua)) {
return (androidWebviewRegExp.test(ua) && !isOperaMini(ua) && !isDuckDuckGo(ua));
}
return false;
}
function isOldSamsungBrowserOrSamsungWebview(ua) {
return !isChrome(ua) && !isSamsungBrowser(ua) && /samsung/i.test(ua);
}
module.exports = function supportsPopups(ua) {
ua = ua || window.navigator.userAgent;
return !(isIosWebview(ua) ||
isIosFirefox(ua) ||
isAndroidWebview(ua) ||
isOperaMini(ua) ||
isUnsupportedIosChrome(ua) ||
isOldSamsungBrowserOrSamsungWebview(ua));
};
},{"./is-android":3,"./is-chrome":4,"./is-duckduckgo":5,"./is-ios-firefox":7,"./is-ios-webview":9,"./is-samsung":14}],17:[function(_dereq_,module,exports){
module.exports = _dereq_("./dist/is-ios-wkwebview");
},{"./dist/is-ios-wkwebview":10}],18:[function(_dereq_,module,exports){
module.exports = _dereq_("./dist/is-ios");
},{"./dist/is-ios":11}],19:[function(_dereq_,module,exports){
module.exports = _dereq_("./dist/supports-popups");
},{"./dist/supports-popups":16}],20:[function(_dereq_,module,exports){
"use strict";
var GlobalPromise = (typeof Promise !== "undefined"
? Promise // eslint-disable-line no-undef
: null);
var ExtendedPromise = /** @class */ (function () {
function ExtendedPromise(options) {
var _this = this;
if (typeof options === "function") {
this._promise = new ExtendedPromise.Promise(options);
return;
}
this._promise = new ExtendedPromise.Promise(function (resolve, reject) {
_this._resolveFunction = resolve;
_this._rejectFunction = reject;
});
options = options || {};
this._onResolve = options.onResolve || ExtendedPromise.defaultOnResolve;
this._onReject = options.onReject || ExtendedPromise.defaultOnReject;
if (ExtendedPromise.shouldCatchExceptions(options)) {
this._promise.catch(function () {
// prevents unhandled promise rejection warning
// in the console for extended promises that
// that catch the error in an asynchronous manner
});
}
this._resetState();
}
ExtendedPromise.defaultOnResolve = function (result) {
return ExtendedPromise.Promise.resolve(result);
};
ExtendedPromise.defaultOnReject = function (err) {
return ExtendedPromise.Promise.reject(err);
};
ExtendedPromise.setPromise = function (PromiseClass) {
ExtendedPromise.Promise = PromiseClass;
};
ExtendedPromise.shouldCatchExceptions = function (options) {
if (options.hasOwnProperty("suppressUnhandledPromiseMessage")) {
return Boolean(options.suppressUnhandledPromiseMessage);
}
return Boolean(ExtendedPromise.suppressUnhandledPromiseMessage);
};
// start Promise methods documented in:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#Methods
ExtendedPromise.all = function (args) {
return ExtendedPromise.Promise.all(args);
};
ExtendedPromise.allSettled = function (args) {
return ExtendedPromise.Promise.allSettled(args);
};
ExtendedPromise.race = function (args) {
return ExtendedPromise.Promise.race(args);
};
ExtendedPromise.reject = function (arg) {
return ExtendedPromise.Promise.reject(arg);
};
ExtendedPromise.resolve = function (arg) {
return ExtendedPromise.Promise.resolve(arg);
};
ExtendedPromise.prototype.then = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._promise).then.apply(_a, args);
};
ExtendedPromise.prototype.catch = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._promise).catch.apply(_a, args);
};
ExtendedPromise.prototype.resolve = function (arg) {
var _this = this;
if (this.isFulfilled) {
return this;
}
this._setResolved();
ExtendedPromise.Promise.resolve()
.then(function () {
return _this._onResolve(arg);
})
.then(function (argForResolveFunction) {
_this._resolveFunction(argForResolveFunction);
})
.catch(function (err) {
_this._resetState();
_this.reject(err);
});
return this;
};
ExtendedPromise.prototype.reject = function (arg) {
var _this = this;
if (this.isFulfilled) {
return this;
}
this._setRejected();
ExtendedPromise.Promise.resolve()
.then(function () {
return _this._onReject(arg);
})
.then(function (result) {
_this._setResolved();
_this._resolveFunction(result);
})
.catch(function (err) {
return _this._rejectFunction(err);
});
return this;
};
ExtendedPromise.prototype._resetState = function () {
this.isFulfilled = false;
this.isResolved = false;
this.isRejected = false;
};
ExtendedPromise.prototype._setResolved = function () {
this.isFulfilled = true;
this.isResolved = true;
this.isRejected = false;
};
ExtendedPromise.prototype._setRejected = function () {
this.isFulfilled = true;
this.isResolved = false;
this.isRejected = true;
};
ExtendedPromise.Promise = GlobalPromise;
return ExtendedPromise;
}());
module.exports = ExtendedPromise;
},{}],21:[function(_dereq_,module,exports){
"use strict";
var set_attributes_1 = _dereq_("./lib/set-attributes");
var default_attributes_1 = _dereq_("./lib/default-attributes");
var assign_1 = _dereq_("./lib/assign");
module.exports = function createFrame(options) {
if (options === void 0) { options = {}; }
var iframe = document.createElement("iframe");
var config = (0, assign_1.assign)({}, default_attributes_1.defaultAttributes, options);
if (config.style && typeof config.style !== "string") {
(0, assign_1.assign)(iframe.style, config.style);
delete config.style;
}
(0, set_attributes_1.setAttributes)(iframe, config);
if (!iframe.getAttribute("id")) {
iframe.id = iframe.name;
}
return iframe;
};
},{"./lib/assign":22,"./lib/default-attributes":23,"./lib/set-attributes":24}],22:[function(_dereq_,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.assign = void 0;
function assign(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
target) {
var objs = [];
for (var _i = 1; _i < arguments.length; _i++) {
objs[_i - 1] = arguments[_i];
}
objs.forEach(function (obj) {
if (typeof obj !== "object") {
return;
}
Object.keys(obj).forEach(function (key) {
target[key] = obj[key];
});
});
return target;
}
exports.assign = assign;
},{}],23:[function(_dereq_,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultAttributes = void 0;
exports.defaultAttributes = {
src: "about:blank",
frameBorder: 0,
allowtransparency: true,
scrolling: "no",
};
},{}],24:[function(_dereq_,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setAttributes = void 0;
function setAttributes(element,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
attributes) {
for (var key in attributes) {
if (attributes.hasOwnProperty(key)) {
var value = attributes[key];
if (value == null) {
element.removeAttribute(key);
}
else {
element.setAttribute(key, value);
}
}
}
}
exports.setAttributes = setAttributes;
},{}],25:[function(_dereq_,module,exports){
"use strict";
function uuid() {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
var r = (Math.random() * 16) | 0;
var v = c === "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
module.exports = uuid;
},{}],26:[function(_dereq_,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function deferred(fn) {
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
setTimeout(function () {
try {
fn.apply(void 0, args);
}
catch (err) {
/* eslint-disable no-console */
console.log("Error in callback function");
console.log(err);
/* eslint-enable no-console */
}
}, 1);
};
}
exports.deferred = deferred;
},{}],27:[function(_dereq_,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function once(fn) {
var called = false;
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (!called) {
called = true;
fn.apply(void 0, args);
}
};
}
exports.once = once;
},{}],28:[function(_dereq_,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable consistent-return */
function promiseOrCallback(promise, callback) {
if (!callback) {
return promise;
}
promise.then(function (data) { return callback(null, data); }).catch(function (err) { return callback(err); });
}
exports.promiseOrCallback = promiseOrCallback;
},{}],29:[function(_dereq_,module,exports){
"use strict";
var deferred_1 = _dereq_("./lib/deferred");
var once_1 = _dereq_("./lib/once");
var promise_or_callback_1 = _dereq_("./lib/promise-or-callback");
function wrapPromise(fn) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var callback;
var lastArg = args[args.length - 1];
if (typeof lastArg === "function") {
callback = args.pop();
callback = once_1.once(deferred_1.deferred(callback));
}
// I know, I know, this looks bad. But it's a quirk of the library that
// we need to allow passing the this context to the original function
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore: this has an implicit any
return promise_or_callback_1.promiseOrCallback(fn.apply(this, args), callback); // eslint-disable-line no-invalid-this
};
}
wrapPromise.wrapPrototype = function (target, options) {
if (options === void 0) { options = {}; }
var ignoreMethods = options.ignoreMethods || [];
var includePrivateMethods = options.transformPrivateMethods === true;
var methods = Object.getOwnPropertyNames(target.prototype).filter(function (method) {
var isNotPrivateMethod;
var isNonConstructorFunction = method !== "constructor" &&
typeof target.prototype[method] === "function";
var isNotAnIgnoredMethod = ignoreMethods.indexOf(method) === -1;
if (includePrivateMethods) {
isNotPrivateMethod = true;
}
else {
isNotPrivateMethod = method.charAt(0) !== "_";
}
return (isNonConstructorFunction && isNotPrivateMethod && isNotAnIgnoredMethod);
});
methods.forEach(function (method) {
var original = target.prototype[method];
target.prototype[method] = wrapPromise(original);
});
return target;
};
module.exports = wrapPromise;
},{"./lib/deferred":26,"./lib/once":27,"./lib/promise-or-callback":28}],30:[function(_dereq_,module,exports){
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.loadAxo = {}));
})(this, (function (exports) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
var dist = {};
var scriptPromiseCache = {};
function loadScript$1(options) {
var scriptLoadPromise;
var stringifiedOptions = JSON.stringify(options);
if (!options.forceScriptReload) {
scriptLoadPromise = scriptPromiseCache[stringifiedOptions];
if (scriptLoadPromise) {
return scriptLoadPromise;
}
}
var script = document.createElement("script");
var attrs = options.dataAttributes || {};
var container = options.container || document.head;
script.src = options.src;
script.id = options.id || "";
script.async = true;
if (options.type) {
script.setAttribute("type", "".concat(options.type));
}
if (options.crossorigin) {
script.setAttribute("crossorigin", "".concat(options.crossorigin));
}
Object.keys(attrs).forEach(function (key) {
script.setAttribute("data-".concat(key), "".concat(attrs[key]));
});
scriptLoadPromise = new Promise(function (resolve, reject) {
script.addEventListener("load", function () {
resolve(script);
});
script.addEventListener("error", function () {
reject(new Error("".concat(options.src, " failed to load.")));
});
script.addEventListener("abort", function () {
reject(new Error("".concat(options.src, " has aborted.")));
});
container.appendChild(script);
});
scriptPromiseCache[stringifiedOptions] = scriptLoadPromise;
return scriptLoadPromise;
}
loadScript$1.clearCache = function () {
scriptPromiseCache = {};
};
var loadScript_1$1 = loadScript$1;
var loadStylesheet$1 = function loadStylesheet(options) {
var stylesheet = document.querySelector("link[href=\"".concat(options.href, "\"]"));
if (stylesheet) {
return Promise.resolve(stylesheet);
}
stylesheet = document.createElement("link");
var container = options.container || document.head;
stylesheet.setAttribute("rel", "stylesheet");
stylesheet.setAttribute("type", "text/css");
stylesheet.setAttribute("href", options.href);
stylesheet.setAttribute("id", options.id);
if (container.firstChild) {
container.insertBefore(stylesheet, container.firstChild);
}
else {
container.appendChild(stylesheet);
}
return Promise.resolve(stylesheet);
};
Object.defineProperty(dist, "__esModule", { value: true });
dist.loadStylesheet = loadScript_1 = dist.loadScript = void 0;
var loadScript = loadScript_1$1;
var loadScript_1 = dist.loadScript = loadScript;
var loadStylesheet = loadStylesheet$1;
dist.loadStylesheet = loadStylesheet;
var CDNX_PROD = "https://www.paypalobjects.com";
var ASSET_NAME = {
minified: "axo.min",
unminified: "axo",
};
var FL_NAMESPACE = "fastlane";
var ASSET_PATH = "connect-boba";
var LOCALE_PATH = "".concat(ASSET_PATH, "/locales/");
var constants = {
AXO_ASSET_NAME: ASSET_NAME,
AXO_ASSET_PATH: ASSET_PATH,
LOCALE_PATH: LOCALE_PATH,
CDNX_PROD: CDNX_PROD,
};
var AxoSupportedPlatforms = {
BT: "BT",
PPCP: "PPCP",
};
/**
* Checks if the current environment is an AMD environment.
*
* @returns {boolean} True if the environment is AMD, false otherwise.
*/
function isAmdEnv() {
return typeof window.define === "function" && !!window.define.amd;
}
/**
* Checks if the current environment is a RequireJS environment.
*
* @returns {boolean} True if the environment is RequireJS, false otherwise.
*/
function isRequireJsEnv() {
return (isAmdEnv() &&
typeof window.requirejs === "function" &&
typeof window.requirejs.config === "function");
}
/**
* Safely loads BT modules by checking if the module already exists and verifying if versions mismatch
*
* @param loadConfig <BtModuleLoadConfig> Configuration of BT Module to load
* @param version <string> version that should be passed from the client getVersion
* @returns Promise<HTMLScriptElement>
* @returns Promise<true> when BT module with same version already exists
* @returns Promise.reject(err) when BT module already exists but versions mismatch or empty version passed in
*/
function safeLoadBtModule(loadConfig, version, minified) {
var _a, _b;
if (minified === void 0) { minified = true; }
return __awaiter(this, void 0, void 0, function () {
var bt, existingVersion;
return __generator(this, function (_c) {
bt = getBraintree();
if (bt && bt[loadConfig.module]) {
if (version && ((_a = bt[loadConfig.module]) === null || _a === void 0 ? void 0 : _a.VERSION) !== version) {
existingVersion = (_b = bt[loadConfig.module]) === null || _b === void 0 ? void 0 : _b.VERSION;
throw new Error("".concat(loadConfig.module, " already loaded with version ").concat(existingVersion, " cannot load version ").concat(version));
}
else {
return [2 /*return*/, true];
}
}
if (!version) {
throw new Error("Attempted to load ".concat(loadConfig.module, " without specifying version"));
}
return [2 /*return*/, loadBtModule(loadConfig, version, minified)];
});
});
}
/**
* Reads the version and to load the correct version of Bt module
*
* @param loadConfig <BtModuleLoadConfig> Configuration of BT Module to load
* @param version <string> Bt module version
* @returns Promise<HTMLScriptElement> or
*/
function loadBtModule(loadConfig, version, minified) {
if (minified === void 0) { minified = true; }
if (isAmdEnv()) {
var module_1 = minified
? loadConfig.amdModule.minified
: loadConfig.amdModule.unminified;
return new Promise(function (resolve, reject) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window.require([module_1], resolve, reject);
});
}
var script = minified
? loadConfig.script.minified
: loadConfig.script.unminified;
return loadScript_1({
id: "".concat(loadConfig.id, "-").concat(version),
src: "https://js.braintreegateway.com/web/".concat(version, "/js/").concat(script),
});
}
/**
* Looks for the Braintree web sdk on the window object
*
* @returns Braintree web sdk
*/
function getBraintree() {
return window === null || window === void 0 ? void 0 : window.braintree;
}
var _a, _b;
/**
* Maps to the BT module namespace created on the window.braintree object
*/
var BtModule = {
Client: "client",
HostedCardFields: "hostedFields",
};
var BT_NAMESPACE = "braintree";
var BT_ASSET_NAME = (_a = {},
_a[BtModule.Client] = "client",
_a[BtModule.HostedCardFields] = "hosted-fields",
_a);
var btModulesLoadConfig = (_b = {},
_b[BtModule.Client] = {
id: "client",
module: BtModule.Client,
amdModule: {
unminified: "".concat(BT_NAMESPACE, "/").concat(BT_ASSET_NAME[BtModule.Client]),
minified: "".concat(BT_NAMESPACE, "/").concat(BT_ASSET_NAME[BtModule.Client], ".min"),
},
script: {
unminified: "".concat(BT_ASSET_NAME[BtModule.Client], ".js"),
minified: "".concat(BT_ASSET_NAME[BtModule.Client], ".min.js"),
},
},
_b[BtModule.HostedCardFields] = {
id: "hcf",
module: BtModule.HostedCardFields,
amdModule: {
unminified: "".concat(BT_NAMESPACE, "/").concat(BT_ASSET_NAME[BtModule.HostedCardFields]),
minified: "".concat(BT_NAMESPACE, "/").concat(BT_ASSET_NAME[BtModule.HostedCardFields], ".min"),
},
script: {
unminified: "".concat(BT_ASSET_NAME[BtModule.HostedCardFields], ".js"),
minified: "".concat(BT_ASSET_NAME[BtModule.HostedCardFields], ".min.js"),
},
},
_b);
/**
* Loads accelerated checkout components.
* @param options object with a minified parameter to determine if the script that is loaded should be minified or not (defaults to true if)
* @returns an object with metadata with a localeUrl parameter to be read by AXO SDK
*/
function loadAxo(options) {
return __awaiter(this, void 0, void 0, function () {
var btSdkVersion, minified, assetUrl, localeUrl;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
performance.mark("pp_axo_sdk_init_invoked");
btSdkVersion = options.btSdkVersion, minified = options.minified;
assetUrl = getAssetsUrl(options);
localeUrl = getLocaleUrl(options);
if (!(options.platform === AxoSupportedPlatforms.BT)) return [3 /*break*/, 2];
return [4 /*yield*/, Promise.all([
safeLoadBtModule(btModulesLoadConfig.hostedFields, btSdkVersion, minified),
loadAXOScript(assetUrl, minified),
])];
case 1:
_a.sent();
return [3 /*break*/, 5];
case 2:
if (!(options.platform === AxoSupportedPlatforms.PPCP)) return [3 /*break*/, 4];
return [4 /*yield*/, Promise.all([
safeLoadBtModule(btModulesLoadConfig.client, btSdkVersion, minified),
safeLoadBtModule(btModulesLoadConfig.hostedFields, btSdkVersion, minified),
loadAXOScript(assetUrl, minified),
])];
case 3:
_a.sent();
return [3 /*break*/, 5];
case 4: throw new Error("unsupported axo platform");
case 5: return [2 /*return*/, { metadata: { localeUrl: localeUrl } }];
}
});
});
}
/**
* Reads the url and to load the axo bundle script
* @param url (Required) string url for the correct axo asset
* @returns Promise<HTMLScriptElement>
*/
function loadAXOScript(url, minified) {
var _a;
if (minified === void 0) { minified = true; }
if (isAmdEnv()) {
// AMD environment
if (isRequireJsEnv()) {
// Let's configure RequireJS
requirejs.config({
paths: (_a = {},
_a[FL_NAMESPACE] = url,
_a),
});
}
var moduleName_1 = "".concat(FL_NAMESPACE, "/").concat(minified
? constants.AXO_ASSET_NAME.minified
: constants.AXO_ASSET_NAME.unminified);
return new Promise(function (resolve, reject) {
window.require([moduleName_1], resolve, reject);
});
}
// Not an AMD environment
return loadScript_1({
id: "axo-id",
src: url,
forceScriptReload: true,
});
}
/**
* Prepends the domain to the asset url
* @param options object with assetUrl and bundleid parameters to determine which URL to return
* @returns full domain and assets URL as string
*/
function generateAssetUrl(_a) {
var assetUrl = _a.assetUrl, bundleId = _a.bundleId;
return bundleId
? "https://cdn-".concat(bundleId, ".static.engineering.dev.paypalinc.com/").concat(assetUrl)
: "".concat(constants.CDNX_PROD, "/").concat(assetUrl);
}
/**
* Retrieves either the minified or unminified assets URL as specified
* @param options (Optional) object with a minified and metadata with bundleIdOverride parameters to determine which URL to return
* @returns assets URL as string
*/
function getAssetsUrl(options) {
var _a;
var assetName = (options === null || options === void 0 ? void 0 : options.minified) !== false
? constants.AXO_ASSET_NAME.minified
: constants.AXO_ASSET_NAME.unminified;
var assetUrl = isAmdEnv()
? constants.AXO_ASSET_PATH
: "".concat(constants.AXO_ASSET_PATH, "/").concat(assetName, ".js");
return generateAssetUrl({
assetUrl: assetUrl,
bundleId: (_a = options === null || options === void 0 ? void 0 : options.metadata) === null || _a === void 0 ? void 0 : _a.bundleIdOverride,
});
}
/**
* Retrieves the Locales URL, the path to our language files
* @param options (Optional) object with a minified and metadata with bundleIdOverride parameters to determine which URL to return
* @returns locale URL as string
*/
function getLocaleUrl(options) {
var _a;
return generateAssetUrl({
assetUrl: constants.LOCALE_PATH,
bundleId: (_a = options === null || options === void 0 ? void 0 : options.metadata) === null || _a === void 0 ? void 0 : _a.bundleIdOverride,
});
}
exports.constants = constants;
exports.loadAxo = loadAxo;
}));
},{}],31:[function(_dereq_,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Framebus = void 0;
var lib_1 = _dereq_("./lib");
var DefaultPromise = (typeof window !== "undefined" &&
window.Promise);
var Framebus = /** @class */ (function () {
function Framebus(options) {
if (options === void 0) { options = {}; }
this.origin = options.origin || "*";
this.channel = options.channel || "";
this.verifyDomain = options.verifyDomain;
// if a targetFrames configuration is not passed in,
// the default behavior is to broadcast the payload
// to the top level window or to the frame itself.
// By default, the broadcast function will loop through
// all the known siblings and children of the window.
// If a targetFrames array is passed, it will instead
// only broadcast to those specified targetFrames
this.targetFrames = options.targetFrames || [];
this.limitBroadcastToFramesArray = Boolean(options.targetFrames);
this.isDestroyed = false;
this.listeners = [];
this.hasAdditionalChecksForOnListeners = Boolean(this.verifyDomain || this.limitBroadcastToFramesArray);
}
Framebus.setPromise = function (PromiseGlobal) {
Framebus.Promise = PromiseGlobal;
};
Framebus.target = function (options) {
return new Framebus(options);
};
Framebus.prototype.addTargetFrame = function (frame) {
if (!this.limitBroadcastToFramesArray) {
return;
}
this.targetFrames.push(frame);
};
Framebus.prototype.include = function (childWindow) {
if (childWindow == null) {
return false;
}
if (childWindow.Window == null) {
return false;
}
if (childWindow.constructor !== childWindow.Window) {
return false;
}
lib_1.childWindows.push(childWindow);
return true;
};
Framebus.prototype.target = function (options) {
return Framebus.target(options);
};
Framebus.prototype.emit = function (eventName, data, reply) {
if (this.isDestroyed) {
return false;
}
var origin = this.origin;
eventName = this.namespaceEvent(eventName);
if ((0, lib_1.isntString)(eventName)) {
return false;
}
if ((0, lib_1.isntString)(origin)) {
return false;
}
if (typeof data === "function") {
reply = data;
data = undefined; // eslint-disable-line no-undefined
}
var payload = (0, lib_1.packagePayload)(eventName, origin, data, reply);
if (!payload) {
return false;
}
if (this.limitBroadcastToFramesArray) {
this.targetFramesAsWindows().forEach(function (frame) {
(0, lib_1.sendMessage)(frame, payload, origin);
});
}
else {
(0, lib_1.broadcast)(payload, {
origin: origin,
frame: window.top || window.self,
});
}
return true;
};
Framebus.prototype.emitAsPromise = function (eventName, data) {
var _this = this;
return new Framebus.Promise(function (resolve, reject) {
var didAttachListener = _this.emit(eventName, data, function (payload) {
resolve(payload);
});
if (!didAttachListener) {
reject(new Error("Listener not added for \"".concat(eventName, "\"")));
}
});
};
Framebus.prototype.on = function (eventName, originalHandler) {
if (this.isDestroyed) {
return false;
}
// eslint-disable-next-line @typescript-eslint/no-this-alias
var self = this;
var origin = this.origin;
var handler = originalHandler;
eventName = this.namespaceEvent(eventName);
if ((0, lib_1.subscriptionArgsInvalid)(eventName, handler, origin)) {
return false;
}
if (this.hasAdditionalChecksForOnListeners) {
/* eslint-disable no-invalid-this, @typescript-eslint/ban-ts-comment */
handler = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
// @ts-ignore
if (!self.passesVerifyDomainCheck(this && this.origin)) {
return;
}
// @ts-ignore
if (!self.hasMatchingTargetFrame(this && this.source)) {
return;
}
originalHandler.apply(void 0, args);
};
/* eslint-enable no-invalid-this, @typescript-eslint/ban-ts-comment */
}
this.listeners.push({
eventName: eventName,
handler: handler,
originalHandler: originalHandler,
});
lib_1.subscribers[origin] = lib_1.subscribers[origin] || {};
lib_1.subscribers[origin][eventName] = lib_1.subscribers[origin][eventName] || [];
lib_1.subscribers[origin][eventName].push(handler);
return true;
};
Framebus.prototype.off = function (eventName, originalHandler) {
var handler = originalHandler;
if (this.isDestroyed) {
return false;
}
if (this.hasAdditionalChecksForOnListeners) {
for (var i = 0; i < this.listeners.length; i++) {
var listener = this.listeners[i];
if (listener.originalHandler === originalHandler) {
handler = listener.handler;
}
}
}
eventName = this.namespaceEvent(eventName);
var origin = this.origin;
if ((0, lib_1.subscriptionArgsInvalid)(eventName, handler, origin)) {
return false;
}
var subscriberList = lib_1.subscribers[origin] && lib_1.subscribers[origin][eventName];
if (!subscriberList) {
return false;
}
for (var i = 0; i < subscriberList.length; i++) {
if (subscriberList[i] === handler) {
subscriberList.splice(i, 1);
return true;
}
}
return false;
};
Framebus.prototype.teardown = function () {
if (this.isDestroyed) {
return;
}
this.isDestroyed = true;
for (var i = 0; i < this.listeners.length; i++) {
var listener = this.listeners[i];
this.off(listener.eventName, listener.handler);
}
this.listeners.length = 0;
};
Framebus.prototype.passesVerifyDomainCheck = function (origin) {
if (!this.verifyDomain) {
// always pass this check if no verifyDomain option was set
return true;
}
return this.checkOrigin(origin);
};
Framebus.prototype.targetFramesAsWindows = function () {
if (!this.limitBroadcastToFramesArray) {
return [];
}
return this.targetFrames
.map(function (frame) {
// we can't pull off the contentWindow
// when the iframe is originally added
// to the array, because if it is not
// in the DOM at that time, it will have
// a contentWindow of `null`
if (frame instanceof HTMLIFrameElement) {
return frame.contentWindow;
}
return frame;
})
.filter(function (win) {
// just in case an iframe element
// was removed from the DOM
// and the contentWindow property
// is null
return win;
});
};
Framebus.prototype.hasMatchingTargetFrame = function (source) {
if (!this.limitBroadcastToFramesArray) {
// always pass this check if we aren't limiting to the target frames
return true;
}
var matchingFrame = this.targetFramesAsWindows().find(function (frame) {
return frame === source;
});
return Boolean(matchingFrame);
};
Framebus.prototype.checkOrigin = function (postMessageOrigin) {
var merchantHost;
var a = document.createElement("a");
a.href = location.href;
if (a.protocol === "https:") {
merchantHost = a.host.replace(/:443$/, "");
}
else if (a.protocol === "http:") {
merchantHost = a.host.replace(/:80$/, "");
}
else {
merchantHost = a.host;
}
var merchantOrigin = a.protocol + "//" + merchantHost;
if (merchantOrigin === postMessageOrigin) {
return true;
}
if (this.verifyDomain) {
return this.verifyDomain(postMessageOrigin);
}
return true;
};
Framebus.prototype.namespaceEvent = function (eventName) {
if (!this.channel) {
return eventName;
}
return "".concat(this.channel, ":").concat(eventName);
};
Framebus.Promise = DefaultPromise;
return Framebus;
}());
exports.Framebus = Framebus;
},{"./lib":39}],32:[function(_dereq_,module,exports){
"use strict";
var lib_1 = _dereq_("./lib");
var framebus_1 = _dereq_("./framebus");
(0, lib_1.attach)();
module.exports = framebus_1.Framebus;
},{"./framebus":31,"./lib":39}],33:[function(_dereq_,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.detach = exports.attach = void 0;
var _1 = _dereq_("./");
var isAttached = false;
function attach() {
if (isAttached || typeof window === "undefined") {
return;
}
isAttached = true;
window.addEventListener("message", _1.onMessage, false);
}
exports.attach = attach;
// removeIf(production)
function detach() {
isAttached = false;
window.removeEventListener("message", _1.onMessage, false);
}
exports.detach = detach;
// endRemoveIf(production)
},{"./":39}],34:[function(_dereq_,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.broadcastToChildWindows = void 0;
var _1 = _dereq_("./");
function broadcastToChildWindows(payload, origin, source) {
for (var i = _1.childWindows.length - 1; i >= 0; i--) {
var childWindow = _1.childWindows[i];
if (childWindow.closed) {
_1.childWindows.splice(i, 1);
}
else if (source !== childWindow) {
(0, _1.broadcast)(payload, {
origin: origin,
frame: childWindow.top,
});
}
}
}
exports.broadcastToChildWindows = broadcastToChildWindows;
},{"./":39}],35:[function(_dereq_,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.broadcast = void 0;
var _1 = _dereq_("./");
function broadcast(payload, options) {
var i = 0;
var frameToBroadcastTo;
var origin = options.origin, frame = options.frame;
try {
frame.postMessage(payload, origin);
if ((0, _1.hasOpener)(frame) && frame.opener.top !== window.top) {
broadcast(payload, {
origin: origin,
frame: frame.opener.top,
});
}
// previously, our max value was frame.frames.length
// but frames.length inherits from window.length
// which can be overwritten if a developer does
// `var length = value;` outside of a function
// scope, it'll prevent us from looping through
// all the frames. With this, we loop through
// until there are no longer any frames
// eslint-disable-next-line no-cond-assign
while ((frameToBroadcastTo = frame.frames[i])) {
broadcast(payload, {
origin: origin,
frame: frameToBroadcastTo,
});
i++;
}
}
catch (_) {
/* ignored */
}
}
exports.broadcast = broadcast;
},{"./":39}],36:[function(_dereq_,module,exports){
"use