@stripe/stripe-js
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -29,3 +29,3 @@ var V3_URL = 'https://js.stripe.com/v3'; | ||
var script = document.querySelector("script[src=\"".concat(V3_URL, "\"]")) || injectScript(); | ||
var script = document.querySelector("script[src=\"".concat(V3_URL, "\"], script[src=\"").concat(V3_URL, "/\"]")) || injectScript(); | ||
return new Promise(function (resolve, reject) { | ||
@@ -32,0 +32,0 @@ script.addEventListener('load', function () { |
@@ -33,3 +33,3 @@ 'use strict'; | ||
var script = document.querySelector("script[src=\"".concat(V3_URL, "\"]")) || injectScript(); | ||
var script = document.querySelector("script[src=\"".concat(V3_URL, "\"], script[src=\"").concat(V3_URL, "/\"]")) || injectScript(); | ||
return new Promise(function (resolve, reject) { | ||
@@ -36,0 +36,0 @@ script.addEventListener('load', function () { |
{ | ||
"name": "@stripe/stripe-js", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Stripe.js loading utility", | ||
@@ -12,3 +12,3 @@ "main": "dist/stripe.js", | ||
"test:versions": "./tests/versions/scripts/test.sh", | ||
"test:types": "tsc -p ./tests/types", | ||
"test:types": "tsc -p ./tests/types && jest --roots '<rootDir>/tests/types'", | ||
"lint": "eslint '{src,types}/**/*.{ts,js}' && yarn prettier-list-different", | ||
@@ -15,0 +15,0 @@ "typecheck": "tsc", |
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const dispatchScriptEvent = (eventType: string): void => { | ||
const script = document.querySelector( | ||
const injectedScript = document.querySelector( | ||
'script[src="https://js.stripe.com/v3"]' | ||
); | ||
if (!script) { | ||
if (!injectedScript) { | ||
throw new Error('could not find Stripe.js script element'); | ||
} | ||
script.dispatchEvent(new Event(eventType)); | ||
injectedScript.dispatchEvent(new Event(eventType)); | ||
}; | ||
@@ -18,3 +18,3 @@ | ||
const script = document.querySelector( | ||
'script[src="https://js.stripe.com/v3"]' | ||
'script[src="https://js.stripe.com/v3"], script[src="https://js.stripe.com/v3/"]' | ||
); | ||
@@ -54,14 +54,34 @@ if (script && script.parentElement) { | ||
it('does not inject a duplicate script when one is already present', () => { | ||
require('./index'); | ||
describe('does not inject a duplicate script when one is already present', () => { | ||
test('when the script does not have a trailing slash', () => { | ||
require('./index'); | ||
const script = document.createElement('script'); | ||
script.src = 'https://js.stripe.com/v3'; | ||
document.body.appendChild(script); | ||
const script = document.createElement('script'); | ||
script.src = 'https://js.stripe.com/v3'; | ||
document.body.appendChild(script); | ||
return new Promise((resolve) => setTimeout(resolve)).then(() => { | ||
expect( | ||
document.querySelectorAll('script[src="https://js.stripe.com/v3"]') | ||
).toHaveLength(1); | ||
return Promise.resolve().then(() => { | ||
expect( | ||
document.querySelectorAll( | ||
'script[src="https://js.stripe.com/v3"], script[src="https://js.stripe.com/v3/"]' | ||
) | ||
).toHaveLength(1); | ||
}); | ||
}); | ||
test('when the script has a trailing slash', () => { | ||
require('./index'); | ||
const script = document.createElement('script'); | ||
script.src = 'https://js.stripe.com/v3/'; | ||
document.body.appendChild(script); | ||
return Promise.resolve().then(() => { | ||
expect( | ||
document.querySelectorAll( | ||
'script[src="https://js.stripe.com/v3"], script[src="https://js.stripe.com/v3/"]' | ||
) | ||
).toHaveLength(1); | ||
}); | ||
}); | ||
}); | ||
@@ -68,0 +88,0 @@ |
@@ -39,3 +39,5 @@ // eslint-disable-next-line @typescript-eslint/triple-slash-reference | ||
const script: HTMLScriptElement = | ||
document.querySelector(`script[src="${V3_URL}"]`) || injectScript(); | ||
document.querySelector( | ||
`script[src="${V3_URL}"], script[src="${V3_URL}/"]` | ||
) || injectScript(); | ||
@@ -42,0 +44,0 @@ return new Promise((resolve, reject) => { |
@@ -29,2 +29,7 @@ ///<reference path='./base.d.ts' /> | ||
/** | ||
* Triggered when the escape key is pressed within the element. | ||
*/ | ||
on(eventType: 'escape', handler: () => any): StripeAuBankAccountElement; | ||
/** | ||
* Updates the options the `AuBankAccountElement` was initialized with. | ||
@@ -31,0 +36,0 @@ * Updates are merged into the existing configuration. |
@@ -29,2 +29,7 @@ ///<reference path='./base.d.ts' /> | ||
/** | ||
* Triggered when the escape key is pressed within the element. | ||
*/ | ||
on(eventType: 'escape', handler: () => any): StripeCardCvcElement; | ||
/** | ||
* Updates the options the `CardCvcElement` was initialized with. | ||
@@ -31,0 +36,0 @@ * Updates are merged into the existing configuration. |
@@ -29,2 +29,7 @@ ///<reference path='./base.d.ts' /> | ||
/** | ||
* Triggered when the escape key is pressed within the element. | ||
*/ | ||
on(eventType: 'escape', handler: () => any): StripeCardExpiryElement; | ||
/** | ||
* Updates the options the `CardExpiryElement` was initialized with. | ||
@@ -31,0 +36,0 @@ * Updates are merged into the existing configuration. |
@@ -29,2 +29,7 @@ ///<reference path='./base.d.ts' /> | ||
/** | ||
* Triggered when the escape key is pressed within the element. | ||
*/ | ||
on(eventType: 'escape', handler: () => any): StripeCardNumberElement; | ||
/** | ||
* Updates the options the `CardNumberElement` was initialized with. | ||
@@ -31,0 +36,0 @@ * Updates are merged into the existing configuration. |
@@ -29,2 +29,7 @@ ///<reference path='./base.d.ts' /> | ||
/** | ||
* Triggered when the escape key is pressed within the element. | ||
*/ | ||
on(eventType: 'escape', handler: () => any): StripeCardElement; | ||
/** | ||
* Updates the options the `CardElement` was initialized with. | ||
@@ -31,0 +36,0 @@ * Updates are merged into the existing configuration. |
@@ -29,2 +29,7 @@ ///<reference path='./base.d.ts' /> | ||
/** | ||
* Triggered when the escape key is pressed within the element. | ||
*/ | ||
on(eventType: 'escape', handler: () => any): StripeFpxBankElement; | ||
/** | ||
* Updates the options the `FpxBankElement` was initialized with. | ||
@@ -31,0 +36,0 @@ * Updates are merged into the existing configuration. |
@@ -29,2 +29,7 @@ ///<reference path='./base.d.ts' /> | ||
/** | ||
* Triggered when the escape key is pressed within the element. | ||
*/ | ||
on(eventType: 'escape', handler: () => any): StripeIbanElement; | ||
/** | ||
* Updates the options the `IbanElement` was initialized with. | ||
@@ -31,0 +36,0 @@ * Updates are merged into the existing configuration. |
@@ -29,2 +29,7 @@ ///<reference path='./base.d.ts' /> | ||
/** | ||
* Triggered when the escape key is pressed within the element. | ||
*/ | ||
on(eventType: 'escape', handler: () => any): StripeIdealBankElement; | ||
/** | ||
* Updates the options the `IdealBankElement` was initialized with. | ||
@@ -31,0 +36,0 @@ * Updates are merged into the existing configuration. |
@@ -255,19 +255,19 @@ ///<reference path='./checkout.d.ts' /> | ||
/** | ||
* Use `stripe.createToken` to convert information collected by card elements into a single-use [Token](https://stripe.com/docs/api#tokens) that you safely pass to your server to use in an API call. | ||
* Use `stripe.createToken` to convert information collected by an `IbanElement` into a single-use [Token](https://stripe.com/docs/api#tokens) that you safely pass to your server to use in an API call. | ||
* | ||
* @docs https://stripe.com/docs/js/tokens_sources/create_token?type=cardElement | ||
* @docs https://stripe.com/docs/js/tokens_sources/create_token?type=ibanElement | ||
*/ | ||
createToken( | ||
tokenType: StripeCardElement | StripeCardNumberElement, | ||
data?: CreateTokenCardData | ||
tokenType: StripeIbanElement, | ||
data: CreateTokenIbanData | ||
): Promise<{token?: Token; error?: StripeError}>; | ||
/** | ||
* Use `stripe.createToken` to convert information collected by an `IbanElement` into a single-use [Token](https://stripe.com/docs/api#tokens) that you safely pass to your server to use in an API call. | ||
* Use `stripe.createToken` to convert information collected by card elements into a single-use [Token](https://stripe.com/docs/api#tokens) that you safely pass to your server to use in an API call. | ||
* | ||
* @docs https://stripe.com/docs/js/tokens_sources/create_token?type=ibanElement | ||
* @docs https://stripe.com/docs/js/tokens_sources/create_token?type=cardElement | ||
*/ | ||
createToken( | ||
tokenType: StripeIbanElement, | ||
data: CreateTokenIbanData | ||
tokenType: StripeCardElement | StripeCardNumberElement, | ||
data?: CreateTokenCardData | ||
): Promise<{token?: Token; error?: StripeError}>; | ||
@@ -274,0 +274,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
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
170898
4255