@stripe/stripe-js
Advanced tools
Comparing version 1.0.0-beta.4 to 1.0.0-beta.5
@@ -1,52 +0,40 @@ | ||
var V3_URL = 'https://js.stripe.com/v3'; // Execute our own script injection after a tick to give users time to | ||
// do their own script injection. | ||
var stripePromise = Promise.resolve().then(function () { | ||
if (typeof window === 'undefined') { | ||
// Resolve to null when imported server side. This makes the module | ||
// safe to import in an isomorphic code base. | ||
return null; | ||
} | ||
if (window.Stripe) { | ||
return window.Stripe; | ||
} | ||
var script = document.querySelector("script[src=\"".concat(V3_URL, "\"]")); | ||
if (!script) { | ||
script = document.createElement('script'); | ||
const V3_URL = 'https://js.stripe.com/v3'; | ||
const injectScript = () => { | ||
const script = document.createElement('script'); | ||
script.src = V3_URL; | ||
var headOrBody = document.head || document.body; | ||
const headOrBody = document.head || document.body; | ||
if (!headOrBody) { | ||
throw new Error('Expected document.body not to be null. Stripe.js requires a <body> element.'); | ||
throw new Error('Expected document.body not to be null. Stripe.js requires a <body> element.'); | ||
} | ||
headOrBody.appendChild(script); | ||
} | ||
return new Promise(function (resolve, reject) { | ||
script.addEventListener('load', function () { | ||
if (window.Stripe) { | ||
resolve(window.Stripe); | ||
} else { | ||
reject(new Error('Failed to load Stripe.js')); | ||
} | ||
return script; | ||
}; | ||
// Execute our own script injection after a tick to give users time to | ||
// do their own script injection. | ||
const stripePromise = Promise.resolve().then(() => { | ||
if (typeof window === 'undefined') { | ||
// Resolve to null when imported server side. This makes the module | ||
// safe to import in an isomorphic code base. | ||
return null; | ||
} | ||
if (window.Stripe) { | ||
return window.Stripe; | ||
} | ||
const script = document.querySelector(`script[src="${V3_URL}"]`) || injectScript(); | ||
return new Promise((resolve, reject) => { | ||
script.addEventListener('load', () => { | ||
if (window.Stripe) { | ||
resolve(window.Stripe); | ||
} | ||
else { | ||
reject(new Error('Failed to load Stripe.js')); | ||
} | ||
}); | ||
script.addEventListener('error', () => { | ||
reject(new Error('Failed to load Stripe.js')); | ||
}); | ||
}); | ||
script.addEventListener('error', function () { | ||
reject(new Error('Failed to load Stripe.js')); | ||
}); | ||
}); | ||
}); | ||
var loadStripe = function loadStripe() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
const loadStripe = (...args) => stripePromise.then((maybeStripe) => maybeStripe ? maybeStripe(...args) : null); | ||
return stripePromise.then(function (maybeStripe) { | ||
return maybeStripe ? maybeStripe.apply(void 0, args) : null; | ||
}); | ||
}; | ||
export { loadStripe }; |
@@ -5,53 +5,41 @@ 'use strict'; | ||
var V3_URL = 'https://js.stripe.com/v3'; // Execute our own script injection after a tick to give users time to | ||
// do their own script injection. | ||
var stripePromise = Promise.resolve().then(function () { | ||
if (typeof window === 'undefined') { | ||
// Resolve to null when imported server side. This makes the module | ||
// safe to import in an isomorphic code base. | ||
return null; | ||
} | ||
if (window.Stripe) { | ||
return window.Stripe; | ||
} | ||
var script = document.querySelector("script[src=\"".concat(V3_URL, "\"]")); | ||
if (!script) { | ||
script = document.createElement('script'); | ||
const V3_URL = 'https://js.stripe.com/v3'; | ||
const injectScript = () => { | ||
const script = document.createElement('script'); | ||
script.src = V3_URL; | ||
var headOrBody = document.head || document.body; | ||
const headOrBody = document.head || document.body; | ||
if (!headOrBody) { | ||
throw new Error('Expected document.body not to be null. Stripe.js requires a <body> element.'); | ||
throw new Error('Expected document.body not to be null. Stripe.js requires a <body> element.'); | ||
} | ||
headOrBody.appendChild(script); | ||
} | ||
return new Promise(function (resolve, reject) { | ||
script.addEventListener('load', function () { | ||
if (window.Stripe) { | ||
resolve(window.Stripe); | ||
} else { | ||
reject(new Error('Failed to load Stripe.js')); | ||
} | ||
return script; | ||
}; | ||
// Execute our own script injection after a tick to give users time to | ||
// do their own script injection. | ||
const stripePromise = Promise.resolve().then(() => { | ||
if (typeof window === 'undefined') { | ||
// Resolve to null when imported server side. This makes the module | ||
// safe to import in an isomorphic code base. | ||
return null; | ||
} | ||
if (window.Stripe) { | ||
return window.Stripe; | ||
} | ||
const script = document.querySelector(`script[src="${V3_URL}"]`) || injectScript(); | ||
return new Promise((resolve, reject) => { | ||
script.addEventListener('load', () => { | ||
if (window.Stripe) { | ||
resolve(window.Stripe); | ||
} | ||
else { | ||
reject(new Error('Failed to load Stripe.js')); | ||
} | ||
}); | ||
script.addEventListener('error', () => { | ||
reject(new Error('Failed to load Stripe.js')); | ||
}); | ||
}); | ||
script.addEventListener('error', function () { | ||
reject(new Error('Failed to load Stripe.js')); | ||
}); | ||
}); | ||
}); | ||
var loadStripe = function loadStripe() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
const loadStripe = (...args) => stripePromise.then((maybeStripe) => maybeStripe ? maybeStripe(...args) : null); | ||
return stripePromise.then(function (maybeStripe) { | ||
return maybeStripe ? maybeStripe.apply(void 0, args) : null; | ||
}); | ||
}; | ||
exports.loadStripe = loadStripe; |
{ | ||
"name": "@stripe/stripe-js", | ||
"version": "1.0.0-beta.4", | ||
"version": "1.0.0-beta.5", | ||
"description": "Stripe.js loading utility", | ||
@@ -8,10 +8,15 @@ "main": "dist/stripe.js", | ||
"jsnext:main": "dist/stripe.esm.js", | ||
"types": "types/index.d.ts", | ||
"scripts": { | ||
"test": "jest", | ||
"lint": "eslint src", | ||
"build": "yarn lint && yarn rollup -c", | ||
"test:versions": "./tests/versions/scripts/test.sh", | ||
"test:types": "tsc -p ./tests/types", | ||
"lint": "eslint '{src,types}/**/*.{ts,js}' && yarn prettier-list-different", | ||
"typecheck": "tsc", | ||
"build": "yarn clean && yarn rollup -c", | ||
"clean": "rimraf dist", | ||
"prettier": "prettier './**/*.js' './**/*.css' './**/*.md' --write", | ||
"prettier-list-different": "prettier './**/*.js' './**/*.css' './**/*.md' --list-different", | ||
"prepublish": "yarn run clean && yarn run build" | ||
"ci": "yarn lint && yarn test && yarn test:versions && yarn test:types && yarn typecheck && yarn build", | ||
"prepublish": "yarn ci", | ||
"prettier": "prettier './**/*.{js,ts,md,html,css}' --write", | ||
"prettier-list-different": "prettier './**/*.{js,ts,md,html,css}' --list-different" | ||
}, | ||
@@ -28,3 +33,4 @@ "keywords": [ | ||
"dist", | ||
"src" | ||
"src", | ||
"types" | ||
], | ||
@@ -34,6 +40,8 @@ "devDependencies": { | ||
"@babel/preset-env": "^7.7.1", | ||
"@types/jest": "^24.0.25", | ||
"@typescript-eslint/eslint-plugin": "^2.15.0", | ||
"@typescript-eslint/parser": "^2.15.0", | ||
"babel-eslint": "^10.0.3", | ||
"babel-jest": "^24.9.0", | ||
"eslint": "6.6.0", | ||
"eslint-config-airbnb-base": "^14.0.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-prettier": "^6.8.0", | ||
@@ -46,5 +54,8 @@ "eslint-plugin-import": "^2.18.2", | ||
"rimraf": "^2.6.2", | ||
"rollup": "^1.27.0", | ||
"rollup-plugin-babel": "^4.3.3" | ||
"rollup": "^1.29.0", | ||
"rollup-plugin-babel": "^4.3.3", | ||
"rollup-plugin-typescript2": "^0.25.3", | ||
"ts-jest": "^24.3.0", | ||
"typescript": "^3.7.4" | ||
} | ||
} |
@@ -45,2 +45,20 @@ # Stripe.js ES Module | ||
## TypeScript support | ||
This package includes TypeScript declarations for Stripe.js. We support projects | ||
using TypeScript versions >= 3.1. | ||
Some methods in Stripe.js accept and return objects from the | ||
[Stripe API](https://stripe.com/docs/api). The type declarations in | ||
`@stripe/stripe-js` for these objects in will always track the | ||
[latest version](https://stripe.com/docs/api/versioning) of the Stripe API. If | ||
you would like to use these types but are using an older version of the Stripe | ||
API, we recommend | ||
[updating to the latest version](https://stripe.com/docs/upgrades#how-can-i-upgrade-my-api), | ||
or ignoring and overriding the type definitions as necessary. | ||
Note that we may release new [minor and patch](https://semver.org/) versions of | ||
`@stripe/stripe-js` with small but backwards-incompatible fixes to the type | ||
declarations. These changes will not affect Stripe.js itself. | ||
## Ensuring Stripe.js is available everywhere | ||
@@ -47,0 +65,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
154757
33
3830
108
20
2