Socket
Socket
Sign inDemoInstall

@stripe/stripe-js

Package Overview
Dependencies
Maintainers
17
Versions
127
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stripe/stripe-js - npm Package Compare versions

Comparing version 3.0.9 to 3.0.10

dist/stripe.js

21

package.json
{
"name": "@stripe/stripe-js",
"version": "3.0.9",
"version": "3.0.10",
"description": "Stripe.js loading utility",
"repository": "github:stripe/stripe-js",
"main": "lib/index.js",
"module": "lib/index.mjs",
"jsnext:main": "lib/index.mjs",
"types": "lib/index.d.ts",
"typings": "lib/index.d.ts",
"main": "dist/stripe.js",
"module": "dist/stripe.mjs",
"jsnext:main": "dist/stripe.mjs",
"types": "dist/index.d.ts",
"typings": "dist/index.d.ts",
"scripts": {

@@ -17,4 +17,3 @@ "test": "yarn lint && yarn test:unit && yarn test:types && yarn typecheck",

"typecheck": "tsc",
"copy-types": "./scripts/copy-types",
"build": "yarn clean && yarn rollup -c && yarn copy-types",
"build": "yarn clean && yarn rollup -c",
"clean": "rimraf dist",

@@ -35,5 +34,4 @@ "prepublishOnly": "echo \"\nPlease use ./scripts/publish instead\n\" && exit 1",

"dist",
"lib",
"pure",
"src"
"src",
"pure"
],

@@ -63,2 +61,3 @@ "engines": {

"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-typescript2": "^0.25.3",

@@ -65,0 +64,0 @@ "ts-jest": "^24.3.0",

@@ -1,1 +0,204 @@

module.exports = require('../dist/pure');
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _typeof(obj) {
"@babel/helpers - typeof";
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
return typeof obj;
};
} else {
_typeof = function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}
return _typeof(obj);
}
var V3_URL = 'https://js.stripe.com/v3';
var V3_URL_REGEX = /^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/;
var EXISTING_SCRIPT_MESSAGE = 'loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used';
var findScript = function findScript() {
var scripts = document.querySelectorAll("script[src^=\"".concat(V3_URL, "\"]"));
for (var i = 0; i < scripts.length; i++) {
var script = scripts[i];
if (!V3_URL_REGEX.test(script.src)) {
continue;
}
return script;
}
return null;
};
var injectScript = function injectScript(params) {
var queryString = params && !params.advancedFraudSignals ? '?advancedFraudSignals=false' : '';
var script = document.createElement('script');
script.src = "".concat(V3_URL).concat(queryString);
var headOrBody = document.head || document.body;
if (!headOrBody) {
throw new Error('Expected document.body not to be null. Stripe.js requires a <body> element.');
}
headOrBody.appendChild(script);
return script;
};
var registerWrapper = function registerWrapper(stripe, startTime) {
if (!stripe || !stripe._registerWrapper) {
return;
}
stripe._registerWrapper({
name: 'stripe-js',
version: "3.0.10",
startTime: startTime
});
};
var stripePromise = null;
var onErrorListener = null;
var onLoadListener = null;
var onError = function onError(reject) {
return function () {
reject(new Error('Failed to load Stripe.js'));
};
};
var onLoad = function onLoad(resolve, reject) {
return function () {
if (window.Stripe) {
resolve(window.Stripe);
} else {
reject(new Error('Stripe.js not available'));
}
};
};
var loadScript = function loadScript(params) {
// Ensure that we only attempt to load Stripe.js at most once
if (stripePromise !== null) {
return stripePromise;
}
stripePromise = new Promise(function (resolve, reject) {
if (typeof window === 'undefined' || typeof document === 'undefined') {
// Resolve to null when imported server side. This makes the module
// safe to import in an isomorphic code base.
resolve(null);
return;
}
if (window.Stripe && params) {
console.warn(EXISTING_SCRIPT_MESSAGE);
}
if (window.Stripe) {
resolve(window.Stripe);
return;
}
try {
var script = findScript();
if (script && params) {
console.warn(EXISTING_SCRIPT_MESSAGE);
} else if (!script) {
script = injectScript(params);
} else if (script && onLoadListener !== null && onErrorListener !== null) {
var _script$parentNode;
// remove event listeners
script.removeEventListener('load', onLoadListener);
script.removeEventListener('error', onErrorListener); // if script exists, but we are reloading due to an error,
// reload script to trigger 'load' event
(_script$parentNode = script.parentNode) === null || _script$parentNode === void 0 ? void 0 : _script$parentNode.removeChild(script);
script = injectScript(params);
}
onLoadListener = onLoad(resolve, reject);
onErrorListener = onError(reject);
script.addEventListener('load', onLoadListener);
script.addEventListener('error', onErrorListener);
} catch (error) {
reject(error);
return;
}
}); // Resets stripePromise on error
return stripePromise["catch"](function (error) {
stripePromise = null;
return Promise.reject(error);
});
};
var initStripe = function initStripe(maybeStripe, args, startTime) {
if (maybeStripe === null) {
return null;
}
var stripe = maybeStripe.apply(undefined, args);
registerWrapper(stripe, startTime);
return stripe;
}; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
var validateLoadParams = function validateLoadParams(params) {
var errorMessage = "invalid load parameters; expected object of shape\n\n {advancedFraudSignals: boolean}\n\nbut received\n\n ".concat(JSON.stringify(params), "\n");
if (params === null || _typeof(params) !== 'object') {
throw new Error(errorMessage);
}
if (Object.keys(params).length === 1 && typeof params.advancedFraudSignals === 'boolean') {
return params;
}
throw new Error(errorMessage);
};
var loadParams;
var loadStripeCalled = false;
var loadStripe = function loadStripe() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
loadStripeCalled = true;
var startTime = Date.now();
return loadScript(loadParams).then(function (maybeStripe) {
return initStripe(maybeStripe, args, startTime);
});
};
loadStripe.setLoadParameters = function (params) {
// we won't throw an error if setLoadParameters is called with the same values as before
if (loadStripeCalled && loadParams) {
var validatedParams = validateLoadParams(params);
var parameterKeys = Object.keys(validatedParams);
var sameParameters = parameterKeys.reduce(function (previousValue, currentValue) {
var _loadParams;
return previousValue && params[currentValue] === ((_loadParams = loadParams) === null || _loadParams === void 0 ? void 0 : _loadParams[currentValue]);
}, true);
if (sameParameters) {
return;
}
}
if (loadStripeCalled) {
throw new Error('You cannot change load parameters after calling loadStripe');
}
loadParams = validateLoadParams(params);
};
exports.loadStripe = loadStripe;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc