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

@stripe/stripe-js

Package Overview
Dependencies
Maintainers
8
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 1.2.0 to 1.3.0

7

dist/stripe.esm.js

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

} else {
reject(new Error('Failed to load Stripe.js'));
reject(new Error('Stripe.js not available'));
}

@@ -44,2 +44,6 @@ });

});
var loadCalled = false;
stripePromise["catch"](function (err) {
if (!loadCalled) console.warn(err);
});
var loadStripe = function loadStripe() {

@@ -50,2 +54,3 @@ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {

loadCalled = true;
return stripePromise.then(function (maybeStripe) {

@@ -52,0 +57,0 @@ return maybeStripe ? maybeStripe.apply(void 0, args) : null;

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

} else {
reject(new Error('Failed to load Stripe.js'));
reject(new Error('Stripe.js not available'));
}

@@ -48,2 +48,6 @@ });

});
var loadCalled = false;
stripePromise["catch"](function (err) {
if (!loadCalled) console.warn(err);
});
var loadStripe = function loadStripe() {

@@ -54,2 +58,3 @@ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {

loadCalled = true;
return stripePromise.then(function (maybeStripe) {

@@ -56,0 +61,0 @@ return maybeStripe ? maybeStripe.apply(void 0, args) : null;

4

package.json
{
"name": "@stripe/stripe-js",
"version": "1.2.0",
"version": "1.3.0",
"description": "Stripe.js loading utility",

@@ -18,3 +18,3 @@ "main": "dist/stripe.js",

"ci": "yarn lint && yarn test && yarn test:versions && yarn test:types && yarn typecheck && yarn build",
"prepublish": "yarn ci",
"prepublishOnly": "yarn ci",
"prettier": "prettier './**/*.{js,ts,md,html,css}' --write",

@@ -21,0 +21,0 @@ "prettier-list-different": "prettier './**/*.{js,ts,md,html,css}' --list-different"

@@ -88,39 +88,57 @@ /* eslint-disable @typescript-eslint/no-var-requires */

describe('loadStripe', () => {
it('resolves loadStripe with Stripe object', () => {
beforeEach(() => {
jest.spyOn(console, 'warn').mockReturnValue();
});
it('resolves loadStripe with Stripe object', async () => {
const {loadStripe} = require('./index');
const stripePromise = loadStripe('pk_test_foo');
return new Promise((resolve) => setTimeout(resolve)).then(() => {
window.Stripe = jest.fn((key) => ({key})) as any;
dispatchScriptEvent('load');
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'});
});
return expect(stripePromise).resolves.toEqual({key: 'pk_test_foo'});
});
it('rejects when the script fails', () => {
it('rejects when the script fails', async () => {
const {loadStripe} = require('./index');
const stripePromise = loadStripe('pk_test_foo');
return Promise.resolve().then(() => {
dispatchScriptEvent('error');
await Promise.resolve();
dispatchScriptEvent('error');
return expect(stripePromise).rejects.toEqual(
new Error('Failed to load Stripe.js')
);
});
await expect(stripePromise).rejects.toEqual(
new Error('Failed to load Stripe.js')
);
expect(console.warn).not.toHaveBeenCalled();
});
it('rejects when Stripe is not added to the window for some reason', () => {
it('does not cause unhandled rejects when the script fails', async () => {
require('./index');
await Promise.resolve();
dispatchScriptEvent('error');
// Turn the task loop to make sure the internal promise handler has been invoked
await new Promise((resolve) => setImmediate(resolve));
expect(console.warn).toHaveBeenCalledWith(
new Error('Failed to load Stripe.js')
);
});
it('rejects when Stripe is not added to the window for some reason', async () => {
const {loadStripe} = require('./index');
const stripePromise = loadStripe('pk_test_foo');
return Promise.resolve().then(() => {
dispatchScriptEvent('load');
return expect(stripePromise).rejects.toEqual(
new Error('Failed to load Stripe.js')
);
});
await Promise.resolve();
dispatchScriptEvent('load');
return expect(stripePromise).rejects.toEqual(
new Error('Stripe.js not available')
);
});
});
});

@@ -48,3 +48,3 @@ // eslint-disable-next-line @typescript-eslint/triple-slash-reference

} else {
reject(new Error('Failed to load Stripe.js'));
reject(new Error('Stripe.js not available'));
}

@@ -60,7 +60,16 @@ });

let loadCalled = false;
stripePromise.catch((err) => {
if (!loadCalled) console.warn(err);
});
export const loadStripe = (
...args: Parameters<StripeConstructor>
): Promise<StripeInstance | null> =>
stripePromise.then((maybeStripe) =>
): Promise<StripeInstance | null> => {
loadCalled = true;
return stripePromise.then((maybeStripe) =>
maybeStripe ? maybeStripe(...args) : null
);
};

@@ -63,2 +63,14 @@ declare module '@stripe/stripe-js' {

/**
* Provides configuration for Checkout to collect a shipping address from a customer.
*/
shippingAddressCollection?: {
/**
* An array of two-letter ISO country codes representing which countries
* Checkout should provide as options for shipping locations. The codes are
* expected to be uppercase. Unsupported country codes: AS, CX, CC, CU, HM, IR, KP, MH, FM, NF, MP, PW, SD, SY, UM, VI.
*/
allowedCountries: string[];
};
/**
* The [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag) of the locale to display Checkout in.

@@ -77,2 +89,3 @@ * Default is `auto` (Stripe detects the locale of the browser).

| 'ja'
| 'ms'
| 'nb'

@@ -82,2 +95,3 @@ | 'nl'

| 'pt'
| 'pt-BR'
| 'sv'

@@ -84,0 +98,0 @@ | 'zh';

@@ -232,4 +232,6 @@ ///<reference path='./elements/card.d.ts' />

| 'nl'
| 'no'
| 'pl'
| 'pt'
| 'pt-BR'
| 'ru'

@@ -236,0 +238,0 @@ | 'sv'

@@ -394,5 +394,8 @@ ///<reference path='./checkout.d.ts' />

| 'ms'
| 'nb'
| 'nl'
| 'no'
| 'pl'
| 'pt'
| 'pt-BR'
| 'ru'

@@ -399,0 +402,0 @@ | 'sv'

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