Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@stripe/stripe-js

Package Overview
Dependencies
Maintainers
17
Versions
131
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 2.2.2 to 2.3.0

2

dist/pure.esm.js

@@ -57,3 +57,3 @@ function _typeof(obj) {

name: 'stripe-js',
version: "2.2.2",
version: "2.3.0",
startTime: startTime

@@ -60,0 +60,0 @@ });

@@ -61,3 +61,3 @@ 'use strict';

name: 'stripe-js',
version: "2.2.2",
version: "2.3.0",
startTime: startTime

@@ -64,0 +64,0 @@ });

@@ -41,3 +41,3 @@ var V3_URL = 'https://js.stripe.com/v3';

name: 'stripe-js',
version: "2.2.2",
version: "2.3.0",
startTime: startTime

@@ -134,11 +134,25 @@ });

var stripePromise$1;
var loadCalled = false;
var getStripePromise = function getStripePromise() {
if (stripePromise$1) {
return stripePromise$1;
}
stripePromise$1 = loadScript(null)["catch"](function (error) {
// clear cache on error
stripePromise$1 = null;
return Promise.reject(error);
});
return stripePromise$1;
}; // Execute our own script injection after a tick to give users time to do their
// own script injection.
var stripePromise$1 = Promise.resolve().then(function () {
return loadScript(null);
});
var loadCalled = false;
stripePromise$1["catch"](function (err) {
Promise.resolve().then(function () {
return getStripePromise();
})["catch"](function (error) {
if (!loadCalled) {
console.warn(err);
console.warn(error);
}

@@ -152,4 +166,5 @@ });

loadCalled = true;
var startTime = Date.now();
return stripePromise$1.then(function (maybeStripe) {
var startTime = Date.now(); // if previous attempts are unsuccessful, will re-load script
return getStripePromise().then(function (maybeStripe) {
return initStripe(maybeStripe, args, startTime);

@@ -156,0 +171,0 @@ });

@@ -45,3 +45,3 @@ 'use strict';

name: 'stripe-js',
version: "2.2.2",
version: "2.3.0",
startTime: startTime

@@ -138,11 +138,25 @@ });

var stripePromise$1;
var loadCalled = false;
var getStripePromise = function getStripePromise() {
if (stripePromise$1) {
return stripePromise$1;
}
stripePromise$1 = loadScript(null)["catch"](function (error) {
// clear cache on error
stripePromise$1 = null;
return Promise.reject(error);
});
return stripePromise$1;
}; // Execute our own script injection after a tick to give users time to do their
// own script injection.
var stripePromise$1 = Promise.resolve().then(function () {
return loadScript(null);
});
var loadCalled = false;
stripePromise$1["catch"](function (err) {
Promise.resolve().then(function () {
return getStripePromise();
})["catch"](function (error) {
if (!loadCalled) {
console.warn(err);
console.warn(error);
}

@@ -156,4 +170,5 @@ });

loadCalled = true;
var startTime = Date.now();
return stripePromise$1.then(function (maybeStripe) {
var startTime = Date.now(); // if previous attempts are unsuccessful, will re-load script
return getStripePromise().then(function (maybeStripe) {
return initStripe(maybeStripe, args, startTime);

@@ -160,0 +175,0 @@ });

{
"name": "@stripe/stripe-js",
"version": "2.2.2",
"version": "2.3.0",
"description": "Stripe.js loading utility",

@@ -5,0 +5,0 @@ "repository": "github:stripe/stripe-js",

@@ -153,2 +153,64 @@ /* eslint-disable @typescript-eslint/no-var-requires */

});
it('rejects on first load, and succeeds on second load resolving with Stripe object', async () => {
const {loadStripe} = require(requirePath);
// start of first load, expect load failure
let stripePromise = loadStripe('pk_test_foo');
await Promise.resolve();
dispatchScriptEvent('error');
await expect(stripePromise).rejects.toEqual(
new Error('Failed to load Stripe.js')
);
expect(console.warn).not.toHaveBeenCalled();
// start of second load, expect successful load
stripePromise = loadStripe('pk_test_foo');
await new Promise((resolve) => setTimeout(resolve));
window.Stripe = jest.fn((key) => ({key})) as any;
dispatchScriptEvent('load');
return expect(stripePromise).resolves.toEqual({key: 'pk_test_foo'});
});
it('rejects on first load and second load but succeeds on third load resolving with Stripe object', async () => {
const {loadStripe} = require(requirePath);
// start of first load, expect load failure
let stripePromise = loadStripe('pk_test_foo');
await Promise.resolve();
dispatchScriptEvent('error');
await expect(stripePromise).rejects.toEqual(
new Error('Failed to load Stripe.js')
);
expect(console.warn).not.toHaveBeenCalled();
// start of second load, expect load failure
stripePromise = loadStripe('pk_test_foo');
await Promise.resolve();
dispatchScriptEvent('error');
await expect(stripePromise).rejects.toEqual(
new Error('Failed to load Stripe.js')
);
expect(console.warn).not.toHaveBeenCalled();
// start of third load, expect success
stripePromise = loadStripe('pk_test_foo');
await new Promise((resolve) => setTimeout(resolve));
window.Stripe = jest.fn((key) => ({key})) as any;
dispatchScriptEvent('load');
return expect(stripePromise).resolves.toEqual({key: 'pk_test_foo'});
});
});

@@ -155,0 +217,0 @@

@@ -0,15 +1,30 @@

import {StripeConstructor} from '../types';
import {loadScript, initStripe, LoadStripe} from './shared';
// Execute our own script injection after a tick to give users time to do their
// own script injection.
const stripePromise = Promise.resolve().then(() => loadScript(null));
let stripePromise: Promise<StripeConstructor | null> | null;
let loadCalled = false;
stripePromise.catch((err: Error) => {
if (!loadCalled) {
console.warn(err);
const getStripePromise: () => Promise<StripeConstructor | null> = () => {
if (stripePromise) {
return stripePromise;
}
});
stripePromise = loadScript(null).catch((error) => {
// clear cache on error
stripePromise = null;
return Promise.reject(error);
});
return stripePromise;
};
// Execute our own script injection after a tick to give users time to do their
// own script injection.
Promise.resolve()
.then(() => getStripePromise())
.catch((error) => {
if (!loadCalled) {
console.warn(error);
}
});
export const loadStripe: LoadStripe = (...args) => {

@@ -19,5 +34,6 @@ loadCalled = true;

return stripePromise.then((maybeStripe) =>
// if previous attempts are unsuccessful, will re-load script
return getStripePromise().then((maybeStripe) =>
initStripe(maybeStripe, args, startTime)
);
};

@@ -799,2 +799,9 @@ import {

clientSecret?: never;
/**
* The external payment methods to be displayed in the Payment Element that you are already integrated with.
*
* @docs https://stripe.com/docs/js/elements_object/create#stripe_elements-options-externalPaymentMethodTypes
*/
externalPaymentMethodTypes?: string[];
}

@@ -801,0 +808,0 @@

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