@amos.com/amos-js 0.10.5 → 0.10.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/dist/index.mjs +28 -28
- package/package.json +1 -1
- package/src/apple-pay.ts +7 -0
- package/src/google-pay.ts +7 -0
- package/src/payment-method-form.ts +5 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=`data-amos-apple-pay-waiting`;function t({onCancel:t}){let n=document.querySelector(`[${e}]`);if(n)return n;let r=document.createElement(`div`);r.setAttribute(e,`true`),r.setAttribute(`role`,`dialog`),r.setAttribute(`aria-modal`,`true`),r.setAttribute(`aria-labelledby`,`amos-apple-pay-waiting-title`),Object.assign(r.style,{position:`fixed`,inset:`0`,zIndex:`2147483646`,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:`24px`,boxSizing:`border-box`,background:`rgba(0, 0, 0, 0.55)`,fontFamily:`-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif`});let i=document.createElement(`div`);Object.assign(i.style,{width:`100%`,maxWidth:`360px`,borderRadius:`12px`,background:`#fff`,padding:`28px 24px 20px`,boxSizing:`border-box`,textAlign:`center`,boxShadow:`0 12px 40px rgba(0, 0, 0, 0.25)`});let a=document.createElement(`div`);a.setAttribute(`aria-hidden`,`true`),Object.assign(a.style,{display:`inline-flex`,alignItems:`center`,justifyContent:`center`,gap:`6px`,marginBottom:`16px`,fontSize:`28px`,fontWeight:`600`,letterSpacing:`-0.02em`,color:`#000`,lineHeight:`1`}),a.innerHTML=`<svg width="22" height="26" viewBox="0 0 814 1000" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path d="M788.1 340.9c-5.8 4.5-108.2 62.2-108.2 190.5 0 148.4 130.3 200.9 134.2 202.2-.6 3.2-20.7 71.9-68.7 141.9-42.8 61.6-87.5 123.1-155.5 123.1s-85.5-39.5-164-39.5c-76.5 0-103.7 40.8-165.9 40.8s-105.6-57-155.5-127C46.7 790.7 0 663 0 541.8c0-194.4 126.4-297.5 250.8-297.5 66.1 0 121.2 43.4 162.7 43.4 39.5 0 101.1-46 176.3-46 28.5 0 130.9 2.6 198.3 99.2zm-234-181.5c31.1-36.9 53.1-88.1 53.1-139.3 0-7.1-.6-14.3-1.9-20.1-50.6 1.9-110.8 33.7-147.1 75.8-28.5 32.4-55.1 83.6-55.1 135.5 0 7.8 1.3 15.6 1.9 18.1 3.2.6 8.4 1.3 13.6 1.3 45.4 0 102.5-30.4 135.5-71.3z"/></svg><span>Pay</span>`;let o=document.createElement(`p`);o.id=`amos-apple-pay-waiting-title`,Object.assign(o.style,{margin:`0 0 20px`,fontSize:`15px`,lineHeight:`1.45`,color:`#1a1a1a`}),o.textContent=`Complete your payment in the open Apple Pay window, or close Apple Pay to continue paying another way.`;let s=document.createElement(`button`);return s.type=`button`,s.textContent=`Cancel payment`,Object.assign(s.style,{display:`block`,width:`100%`,border:`none`,borderRadius:`8px`,padding:`12px 16px`,background:`#2c2c2e`,color:`#fff`,fontSize:`15px`,fontWeight:`500`,cursor:`pointer`}),s.addEventListener(`click`,t),i.append(a,o,s),r.append(i),document.body.append(r),r}function n(){document.querySelector(`[${e}]`)?.remove()}function r(e){let[t=``,n=``,r=``]=e?.split(`.`)??[],i=typeof atob==`function`?atob:e=>Buffer.from(e,`base64`).toString(`utf8`);return{header:JSON.parse(i(t)),payload:JSON.parse(i(n)),signature:r}}function i(e){let{env:t=`sandbox`}=r(e).payload;switch(t){case`production`:return`https://embed.amos.com`;case`sandbox`:return`https://embed-sandbox.amos.com`;default:return`https://embed-sandbox.amos.com`}}var a=new WeakMap;function o(e,t){a.set(e,t)}function s(e){if(e)return a.get(e)}function c(e){e&&a.delete(e)}function l(e){return e}function u(e){return new URL(e.src).origin}function d(e){e?.contentWindow&&e.contentWindow.postMessage(l({type:`PARENT_ACKNOWLEDGED_IFRAME_READY`}),u(e))}function f({iframe:e,appearance:t={}}){e?.contentWindow&&e.contentWindow.postMessage(l({type:`UPDATE_APPEARANCE`,appearance:t}),u(e))}function p({iframe:e,props:t,height:n}){e?.contentWindow&&e.contentWindow.postMessage(l({type:`UPDATE_APPLE_PAY_BUTTON`,height:n,props:t}),u(e))}function m({iframe:e,props:t,height:n}){e?.contentWindow&&e.contentWindow.postMessage(l({type:`UPDATE_GOOGLE_PAY_BUTTON`,height:n,props:t}),u(e))}function h({iframe:e,amount:t}){e?.contentWindow&&e.contentWindow.postMessage(l({type:`UPDATE_AMOUNT`,amount:t}),u(e))}function g({iframe:e,merchantName:t}){e?.contentWindow&&e.contentWindow.postMessage(l({type:`UPDATE_MERCHANT_NAME`,merchantName:t}),u(e))}function _({iframe:e}){let t=s(e);if(t?.requiresVerification)return Promise.resolve(!!t.plaid);let n=crypto.randomUUID();return new Promise(t=>{e?.contentWindow&&e.contentWindow.postMessage(l({type:`VALIDATE_FORM`,requestId:n}),u(e));let r=setTimeout(()=>{window.removeEventListener(`message`,i),t(!1)},5e3);function i(e){e.data.type===`VALIDATE_FORM`&&e.data.requestId===n&&(window.removeEventListener(`message`,i),clearTimeout(r),t(e.data.isValid??!1))}window.addEventListener(`message`,i)})}var v=1e4;function ee({iframe:e}){let t=crypto.randomUUID();return new Promise((n,r)=>{if(!e?.contentWindow){r(Error(`Bank form is not ready.`));return}let i=e.contentWindow;i.postMessage(l({type:`CREATE_PLAID_LINK_TOKEN`,requestId:t}),u(e));let a=setTimeout(()=>{window.removeEventListener(`message`,o),r(Error(`Timed out waiting for Plaid Link token.`))},v);function o(e){if(e.source===i&&e.data.type===`PLAID_LINK_TOKEN`&&e.data.requestId===t){if(window.removeEventListener(`message`,o),clearTimeout(a),e.data.link_token){n(e.data.link_token);return}r(Error(e.data.error??`Could not create Plaid Link token.`))}}window.addEventListener(`message`,o)})}function y({iframe:e}){s(e)?.clearLinked?.(),b(e)}function b(e){e?.contentWindow&&e.contentWindow.postMessage(l({type:`RESET_FORM`}),u(e))}function x({iframe:e,type:t,token:n,id:r}){let i=s(e),a=i?.plaid;i?.requiresVerification&&!a&&b(e),e.contentWindow?.postMessage(l({type:t,token:n,id:r,...a?{plaid:a}:{}}),u(e))}function S({iframe:e,token:t}){if(!e?.contentWindow)return;let{payment_intent_id:n}=r(t).payload;x({iframe:e,type:`CONFIRM_PAYMENT_INTENT`,token:t,id:n??void 0})}function C({iframe:e,token:t}){if(!e?.contentWindow)return;let{setup_intent_id:n}=r(t).payload;x({iframe:e,type:`CONFIRM_SETUP_INTENT`,token:t,id:n??void 0})}function w({iframe:e,result:t}){e?.contentWindow&&e.contentWindow.postMessage(l({type:`CONFIRMATION_RESULT`,result:t}),u(e))}function T(e){return`${i(e)}/iframe/apple-pay?token=${e}`}function E(){return`48px`}function D(e){e.contentWindow?.postMessage(l({type:`APPLE_PAY_CANCEL`}),u(e))}function O(e,{height:r=`48px`,...i}){let a={...i,height:r};function
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=`data-amos-apple-pay-waiting`;function t({onCancel:t}){let n=document.querySelector(`[${e}]`);if(n)return n;let r=document.createElement(`div`);r.setAttribute(e,`true`),r.setAttribute(`role`,`dialog`),r.setAttribute(`aria-modal`,`true`),r.setAttribute(`aria-labelledby`,`amos-apple-pay-waiting-title`),Object.assign(r.style,{position:`fixed`,inset:`0`,zIndex:`2147483646`,display:`flex`,alignItems:`center`,justifyContent:`center`,padding:`24px`,boxSizing:`border-box`,background:`rgba(0, 0, 0, 0.55)`,fontFamily:`-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif`});let i=document.createElement(`div`);Object.assign(i.style,{width:`100%`,maxWidth:`360px`,borderRadius:`12px`,background:`#fff`,padding:`28px 24px 20px`,boxSizing:`border-box`,textAlign:`center`,boxShadow:`0 12px 40px rgba(0, 0, 0, 0.25)`});let a=document.createElement(`div`);a.setAttribute(`aria-hidden`,`true`),Object.assign(a.style,{display:`inline-flex`,alignItems:`center`,justifyContent:`center`,gap:`6px`,marginBottom:`16px`,fontSize:`28px`,fontWeight:`600`,letterSpacing:`-0.02em`,color:`#000`,lineHeight:`1`}),a.innerHTML=`<svg width="22" height="26" viewBox="0 0 814 1000" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path d="M788.1 340.9c-5.8 4.5-108.2 62.2-108.2 190.5 0 148.4 130.3 200.9 134.2 202.2-.6 3.2-20.7 71.9-68.7 141.9-42.8 61.6-87.5 123.1-155.5 123.1s-85.5-39.5-164-39.5c-76.5 0-103.7 40.8-165.9 40.8s-105.6-57-155.5-127C46.7 790.7 0 663 0 541.8c0-194.4 126.4-297.5 250.8-297.5 66.1 0 121.2 43.4 162.7 43.4 39.5 0 101.1-46 176.3-46 28.5 0 130.9 2.6 198.3 99.2zm-234-181.5c31.1-36.9 53.1-88.1 53.1-139.3 0-7.1-.6-14.3-1.9-20.1-50.6 1.9-110.8 33.7-147.1 75.8-28.5 32.4-55.1 83.6-55.1 135.5 0 7.8 1.3 15.6 1.9 18.1 3.2.6 8.4 1.3 13.6 1.3 45.4 0 102.5-30.4 135.5-71.3z"/></svg><span>Pay</span>`;let o=document.createElement(`p`);o.id=`amos-apple-pay-waiting-title`,Object.assign(o.style,{margin:`0 0 20px`,fontSize:`15px`,lineHeight:`1.45`,color:`#1a1a1a`}),o.textContent=`Complete your payment in the open Apple Pay window, or close Apple Pay to continue paying another way.`;let s=document.createElement(`button`);return s.type=`button`,s.textContent=`Cancel payment`,Object.assign(s.style,{display:`block`,width:`100%`,border:`none`,borderRadius:`8px`,padding:`12px 16px`,background:`#2c2c2e`,color:`#fff`,fontSize:`15px`,fontWeight:`500`,cursor:`pointer`}),s.addEventListener(`click`,t),i.append(a,o,s),r.append(i),document.body.append(r),r}function n(){document.querySelector(`[${e}]`)?.remove()}function r(e){let[t=``,n=``,r=``]=e?.split(`.`)??[],i=typeof atob==`function`?atob:e=>Buffer.from(e,`base64`).toString(`utf8`);return{header:JSON.parse(i(t)),payload:JSON.parse(i(n)),signature:r}}function i(e){let{env:t=`sandbox`}=r(e).payload;switch(t){case`production`:return`https://embed.amos.com`;case`sandbox`:return`https://embed-sandbox.amos.com`;default:return`https://embed-sandbox.amos.com`}}var a=new WeakMap;function o(e,t){a.set(e,t)}function s(e){if(e)return a.get(e)}function c(e){e&&a.delete(e)}function l(e){return e}function u(e){return new URL(e.src).origin}function d(e){e?.contentWindow&&e.contentWindow.postMessage(l({type:`PARENT_ACKNOWLEDGED_IFRAME_READY`}),u(e))}function f({iframe:e,appearance:t={}}){e?.contentWindow&&e.contentWindow.postMessage(l({type:`UPDATE_APPEARANCE`,appearance:t}),u(e))}function p({iframe:e,props:t,height:n}){e?.contentWindow&&e.contentWindow.postMessage(l({type:`UPDATE_APPLE_PAY_BUTTON`,height:n,props:t}),u(e))}function m({iframe:e,props:t,height:n}){e?.contentWindow&&e.contentWindow.postMessage(l({type:`UPDATE_GOOGLE_PAY_BUTTON`,height:n,props:t}),u(e))}function h({iframe:e,amount:t}){e?.contentWindow&&e.contentWindow.postMessage(l({type:`UPDATE_AMOUNT`,amount:t}),u(e))}function g({iframe:e,merchantName:t}){e?.contentWindow&&e.contentWindow.postMessage(l({type:`UPDATE_MERCHANT_NAME`,merchantName:t}),u(e))}function _({iframe:e}){let t=s(e);if(t?.requiresVerification)return Promise.resolve(!!t.plaid);let n=crypto.randomUUID();return new Promise(t=>{e?.contentWindow&&e.contentWindow.postMessage(l({type:`VALIDATE_FORM`,requestId:n}),u(e));let r=setTimeout(()=>{window.removeEventListener(`message`,i),t(!1)},5e3);function i(e){e.data.type===`VALIDATE_FORM`&&e.data.requestId===n&&(window.removeEventListener(`message`,i),clearTimeout(r),t(e.data.isValid??!1))}window.addEventListener(`message`,i)})}var v=1e4;function ee({iframe:e}){let t=crypto.randomUUID();return new Promise((n,r)=>{if(!e?.contentWindow){r(Error(`Bank form is not ready.`));return}let i=e.contentWindow;i.postMessage(l({type:`CREATE_PLAID_LINK_TOKEN`,requestId:t}),u(e));let a=setTimeout(()=>{window.removeEventListener(`message`,o),r(Error(`Timed out waiting for Plaid Link token.`))},v);function o(e){if(e.source===i&&e.data.type===`PLAID_LINK_TOKEN`&&e.data.requestId===t){if(window.removeEventListener(`message`,o),clearTimeout(a),e.data.link_token){n(e.data.link_token);return}r(Error(e.data.error??`Could not create Plaid Link token.`))}}window.addEventListener(`message`,o)})}function y({iframe:e}){s(e)?.clearLinked?.(),b(e)}function b(e){e?.contentWindow&&e.contentWindow.postMessage(l({type:`RESET_FORM`}),u(e))}function x({iframe:e,type:t,token:n,id:r}){let i=s(e),a=i?.plaid;i?.requiresVerification&&!a&&b(e),e.contentWindow?.postMessage(l({type:t,token:n,id:r,...a?{plaid:a}:{}}),u(e))}function S({iframe:e,token:t}){if(!e?.contentWindow)return;let{payment_intent_id:n}=r(t).payload;x({iframe:e,type:`CONFIRM_PAYMENT_INTENT`,token:t,id:n??void 0})}function C({iframe:e,token:t}){if(!e?.contentWindow)return;let{setup_intent_id:n}=r(t).payload;x({iframe:e,type:`CONFIRM_SETUP_INTENT`,token:t,id:n??void 0})}function w({iframe:e,result:t}){e?.contentWindow&&e.contentWindow.postMessage(l({type:`CONFIRMATION_RESULT`,result:t}),u(e))}function T(e){return`${i(e)}/iframe/apple-pay?token=${e}`}function E(){return`48px`}function D(e){e.contentWindow?.postMessage(l({type:`APPLE_PAY_CANCEL`}),u(e))}function O(e,{height:r=`48px`,...i}){let a={...i,height:r},o=!1;function s(){h({iframe:e,amount:a.amount})}function c(){g({iframe:e,merchantName:a.merchantName})}function l(){p({iframe:e,height:a.height??`48px`,props:a.buttonProps??{}})}function u(r){if(r.source===e.contentWindow)switch(r.data.type){case`IFRAME_READY`:o=!0,d(e),f({iframe:e,appearance:{}}),s(),c(),l();break;case`UPDATE_HEIGHT`:a.onHeightChange?.(r.data.height);break;case`UPDATE_APPEARANCE`:f({iframe:e,appearance:r.data.appearance});break;case`UPDATED_APPEARANCE`:a.onAppearanceReady?.();break;case`APPLE_PAY_WINDOW_OPEN`:t({onCancel:()=>{D(e),n()}});break;case`APPLE_PAY_WINDOW_CLOSE`:n();break;case`CREATE_PAYMENT_INTENT`:a.onInitiatePaymentIntentRequest({paymentIntentCreateAttributes:r.data.paymentIntentCreateAttributes,customerCreateAttributes:r.data.customerCreateAttributes}).then(t=>{S({iframe:e,token:t})}).catch(e=>{n(),a.onResult({status:`failed`,errorMessage:e instanceof Error?e.message:`Unknown error`})});break;case`CONFIRMATION_RESULT`:n(),a.onResult(r.data.result)}}return window.addEventListener(`message`,u),{update(e){let t=`amount`in e,n=`merchantName`in e,r=`height`in e||`buttonProps`in e;a={...a,...e},o&&(t&&s(),n&&c(),r&&l())},destroy(){window.removeEventListener(`message`,u),n()}}}var k=`amos-js-form-skeleton-styles`,te={"--accent":`oklch(0.97 0 0)`,"--radius":`0.625rem`,"--input-height":`2.25rem`,"--floating-input-height":`3.25rem`,"--field-gap":`1rem`,"--control-gap":`0.5rem`,"--label-font-size":`0.875rem`},ne=`
|
|
2
2
|
.amos-js-form-skeleton {
|
|
3
3
|
box-sizing: border-box;
|
|
4
4
|
container-type: inline-size;
|
|
@@ -65,7 +65,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=`data-a
|
|
|
65
65
|
animation: none;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
`;function A(){if(document.getElementById(k))return;let e=document.createElement(`style`);e.id=k,e.textContent=ne,document.head.appendChild(e)}function j(e,t){for(let[t,n]of Object.entries(te))e.style.setProperty(t,n);let n=t?.themeVariables;if(n)for(let[t,r]of Object.entries(n))typeof r==`string`&&r.trim()!==``&&e.style.setProperty(t,r.trim())}function M(e,t){let n=document.createElement(`div`);if(n.className=e,t)for(let e of t)n.appendChild(e);return n}function N(e,t){let n=M(`amos-js-form-skeleton-field`);t!==void 0&&(n.style.flexGrow=String(t)),e===`above`&&n.appendChild(M(`amos-js-form-skeleton-label`));let r=M(`amos-js-form-skeleton-input`);return e===`floating`&&r.classList.add(`amos-js-form-skeleton-input-floating`),n.appendChild(r),n}function P(e,t){return M(t?`amos-js-form-skeleton-row-stack`:`amos-js-form-skeleton-row`,e)}function re({labels:e,requirement:t,wrapCountryZip:n}){return t===`full`?[N(e),N(e),P([N(e,1.4),N(e,.7),N(e,.8)],!1),N(e)]:[P([N(e),N(e)],n)]}function ie(e){let t=e.appearance?.labels??`above`,n=e.billingAddressRequirement??`country`;if(e.kind===`card`){let r=[N(t),P([N(t),N(t)],!1)];return e.additionalFields?.cardholderName&&r.push(N(t)),r.push(...re({labels:t,requirement:n,wrapCountryZip:!1})),r}return[N(t),P([N(t),N(t)],!0),N(t),P([N(`above`),N(`above`)],!0),...re({labels:t,requirement:n,wrapCountryZip:!0})]}function ae(e){A();let t=M(`amos-js-form-skeleton`);t.setAttribute(`aria-hidden`,`true`);function n(e){j(t,e.appearance),t.replaceChildren(...ie(e))}return n(e),{element:t,update:n}}function F(e){A();let t=M(`amos-js-form-skeleton-input amos-js-wallet-skeleton`);t.setAttribute(`aria-hidden`,`true`);function n(e){j(t,void 0),t.style.height=e.height,t.style.borderRadius=e.borderRadius??`4px`}return n(e),{element:t,update:n}}function I(e){if(typeof e==`number`&&Number.isFinite(e))return`${e}px`;if(typeof e==`string`&&e.trim()!==``)return e.trim()}function L({iframeStyle:e,buttonProps:t}){return I(e?.borderRadius)??I(t?.buttonRadius)??I(t?.style?.borderRadius)??I(t?.style?.[`--apple-pay-button-border-radius`])??`4px`}function R(e){return`${i(e)}/iframe/google-pay?token=${e}`}function z(){return`48px`}function B(e,{height:t=`48px`,...n}){let r={...n,height:t};function
|
|
68
|
+
`;function A(){if(document.getElementById(k))return;let e=document.createElement(`style`);e.id=k,e.textContent=ne,document.head.appendChild(e)}function j(e,t){for(let[t,n]of Object.entries(te))e.style.setProperty(t,n);let n=t?.themeVariables;if(n)for(let[t,r]of Object.entries(n))typeof r==`string`&&r.trim()!==``&&e.style.setProperty(t,r.trim())}function M(e,t){let n=document.createElement(`div`);if(n.className=e,t)for(let e of t)n.appendChild(e);return n}function N(e,t){let n=M(`amos-js-form-skeleton-field`);t!==void 0&&(n.style.flexGrow=String(t)),e===`above`&&n.appendChild(M(`amos-js-form-skeleton-label`));let r=M(`amos-js-form-skeleton-input`);return e===`floating`&&r.classList.add(`amos-js-form-skeleton-input-floating`),n.appendChild(r),n}function P(e,t){return M(t?`amos-js-form-skeleton-row-stack`:`amos-js-form-skeleton-row`,e)}function re({labels:e,requirement:t,wrapCountryZip:n}){return t===`full`?[N(e),N(e),P([N(e,1.4),N(e,.7),N(e,.8)],!1),N(e)]:[P([N(e),N(e)],n)]}function ie(e){let t=e.appearance?.labels??`above`,n=e.billingAddressRequirement??`country`;if(e.kind===`card`){let r=[N(t),P([N(t),N(t)],!1)];return e.additionalFields?.cardholderName&&r.push(N(t)),r.push(...re({labels:t,requirement:n,wrapCountryZip:!1})),r}return[N(t),P([N(t),N(t)],!0),N(t),P([N(`above`),N(`above`)],!0),...re({labels:t,requirement:n,wrapCountryZip:!0})]}function ae(e){A();let t=M(`amos-js-form-skeleton`);t.setAttribute(`aria-hidden`,`true`);function n(e){j(t,e.appearance),t.replaceChildren(...ie(e))}return n(e),{element:t,update:n}}function F(e){A();let t=M(`amos-js-form-skeleton-input amos-js-wallet-skeleton`);t.setAttribute(`aria-hidden`,`true`);function n(e){j(t,void 0),t.style.height=e.height,t.style.borderRadius=e.borderRadius??`4px`}return n(e),{element:t,update:n}}function I(e){if(typeof e==`number`&&Number.isFinite(e))return`${e}px`;if(typeof e==`string`&&e.trim()!==``)return e.trim()}function L({iframeStyle:e,buttonProps:t}){return I(e?.borderRadius)??I(t?.buttonRadius)??I(t?.style?.borderRadius)??I(t?.style?.[`--apple-pay-button-border-radius`])??`4px`}function R(e){return`${i(e)}/iframe/google-pay?token=${e}`}function z(){return`48px`}function B(e,{height:t=`48px`,...n}){let r={...n,height:t},i=!1;function a(){h({iframe:e,amount:r.amount})}function o(){g({iframe:e,merchantName:r.merchantName})}function s(){m({iframe:e,height:r.height??`48px`,props:r.buttonProps??{}})}function c(t){if(t.source===e.contentWindow)switch(t.data.type){case`IFRAME_READY`:i=!0,d(e),f({iframe:e,appearance:{}}),a(),o(),s();break;case`UPDATE_HEIGHT`:r.onHeightChange?.(t.data.height);break;case`UPDATE_APPEARANCE`:f({iframe:e,appearance:t.data.appearance});break;case`UPDATED_APPEARANCE`:r.onAppearanceReady?.();break;case`CREATE_PAYMENT_INTENT`:r.onInitiatePaymentIntentRequest({paymentIntentCreateAttributes:t.data.paymentIntentCreateAttributes,customerCreateAttributes:t.data.customerCreateAttributes}).then(t=>{S({iframe:e,token:t})}).catch(e=>{r.onResult({status:`failed`,errorMessage:e instanceof Error?e.message:`Unknown error`})});break;case`CONFIRMATION_RESULT`:r.onResult(t.data.result)}}return window.addEventListener(`message`,c),{update(e){let t=`amount`in e,n=`merchantName`in e,c=`height`in e||`buttonProps`in e;r={...r,...e},i&&(t&&a(),n&&o(),c&&s())},destroy(){window.removeEventListener(`message`,c)}}}function oe({paymentData:e}){return{paymentMethod:{type:`googlepay`,billing_address_attributes:{name:e.shippingAddress?.name,address_line1:e.shippingAddress?.address1,address_line2:e.shippingAddress?.address2,city:e.shippingAddress?.locality,state:e.shippingAddress?.administrativeArea,postal_code:e.shippingAddress?.postalCode,country:e.shippingAddress?.countryCode,email:e.email,phone:e.shippingAddress?.phoneNumber},card_profile_attributes:{wallet_payload:e.paymentMethodData.tokenizationData.token}}}}var V={country:212,full:452},se=80,H={country:400,full:640};function U(e,t={cardholderName:!1},n=`country`){let r=Object.entries(t).filter(([,e])=>e).map(([e])=>e).join(`,`),a=new URLSearchParams({token:e,additionalFields:r,billingAddressRequirement:n});return`${i(e)}/iframe/card?${a}`}function W(e,t=`country`,n=`payment`){let r=new URLSearchParams({token:e,billingAddressRequirement:t});return n===`setup`&&r.set(`intent`,`setup`),`${i(e)}/iframe/bank?${r}`}function G(e={cardholderName:!1},t=`country`){return`${(V[t]??V.country)+(e.cardholderName?se:0)}px`}function K(e=`country`){return`${H[e]??H.country}px`}function q(e,t){let n={...t},r=!1;function i(t){if(t.source===e.contentWindow)switch(t.data.type){case`IFRAME_READY`:r=!0,d(e),f({iframe:e,appearance:n.appearance});break;case`UPDATE_HEIGHT`:n.onHeightChange?.(t.data.height);break;case`UPDATE_APPEARANCE`:f({iframe:e,appearance:t.data.appearance});break;case`UPDATED_APPEARANCE`:n.onAppearanceReady?.();break;case`FORM_VALIDITY_CHANGE`:if(s(e)?.requiresVerification)break;n.onValidityChange?.({isValid:t.data.isValid});break;case`CARD_BRAND_CHANGE`:n.onCardBrandChanged?.({brand:t.data.brand});break;case`CONFIRMATION_RESULT`:n.onResult(t.data.result)}}return window.addEventListener(`message`,i),{update(t){let i=`appearance`in t;n={...n,...t},i&&r&&f({iframe:e,appearance:n.appearance})},destroy(){window.removeEventListener(`message`,i)}}}var J=`https://cdn.plaid.com/link/v2/stable/link-initialize.js`;function Y({amount:e,achThreshold:t}){return t!=null&&(e??0)>=t}function ce(e){if(e==null)return;let t=e.trim();if(t===``)return;let n=Number(t.replace(/[^\d.]/g,``));if(Number.isFinite(n))return Math.round(n*100)}function le(e){return e.account_id??e.account?.id??e.accounts?.[0]?.id}function ue(e){let t=e.account??e.accounts?.[0];return{bankName:e.institution?.name??`Bank account`,last4:t?.mask??``}}var X;function de(){for(let e of document.querySelectorAll(`script[src="${J}"]`))e.remove()}function fe(){return typeof window>`u`?Promise.reject(Error(`Plaid Link requires a browser`)):window.Plaid?Promise.resolve():X||(de(),X=new Promise((e,t)=>{let n=document.createElement(`script`);n.src=J,n.async=!0;let r=e=>{n.remove(),X=void 0,t(Error(e))};n.addEventListener(`load`,()=>{if(window.Plaid){e();return}r(`Plaid Link failed to initialize`)},{once:!0}),n.addEventListener(`error`,()=>r(`Failed to load Plaid Link`),{once:!0}),document.head.append(n)}),X)}async function pe({token:e,onSuccess:t,onExit:n,signal:r}){if(await fe(),r?.aborted)return()=>{};if(!window.Plaid)throw Error(`Plaid Link failed to initialize`);let i=window.Plaid.create({token:e,onSuccess:t,onExit:e=>{n?.(e)}});return r?.aborted?(i.destroy(),()=>{}):(i.open(),()=>{i.destroy()})}var me=`amos-js-plaid-bank-ui-styles`,he=`
|
|
69
69
|
.amos-js-plaid-panel {
|
|
70
70
|
box-sizing: border-box;
|
|
71
71
|
color: var(--foreground, oklch(0.145 0 0));
|
package/dist/index.mjs
CHANGED
|
@@ -241,33 +241,33 @@ function O(e, { height: r = "48px", ...i }) {
|
|
|
241
241
|
let a = {
|
|
242
242
|
...i,
|
|
243
243
|
height: r
|
|
244
|
-
};
|
|
245
|
-
function
|
|
244
|
+
}, o = !1;
|
|
245
|
+
function s() {
|
|
246
246
|
h({
|
|
247
247
|
iframe: e,
|
|
248
248
|
amount: a.amount
|
|
249
249
|
});
|
|
250
250
|
}
|
|
251
|
-
function
|
|
251
|
+
function c() {
|
|
252
252
|
g({
|
|
253
253
|
iframe: e,
|
|
254
254
|
merchantName: a.merchantName
|
|
255
255
|
});
|
|
256
256
|
}
|
|
257
|
-
function
|
|
257
|
+
function l() {
|
|
258
258
|
p({
|
|
259
259
|
iframe: e,
|
|
260
260
|
height: a.height ?? "48px",
|
|
261
261
|
props: a.buttonProps ?? {}
|
|
262
262
|
});
|
|
263
263
|
}
|
|
264
|
-
function
|
|
264
|
+
function u(r) {
|
|
265
265
|
if (r.source === e.contentWindow) switch (r.data.type) {
|
|
266
266
|
case "IFRAME_READY":
|
|
267
|
-
d(e), f({
|
|
267
|
+
o = !0, d(e), f({
|
|
268
268
|
iframe: e,
|
|
269
269
|
appearance: {}
|
|
270
|
-
}),
|
|
270
|
+
}), s(), c(), l();
|
|
271
271
|
break;
|
|
272
272
|
case "UPDATE_HEIGHT":
|
|
273
273
|
a.onHeightChange?.(r.data.height);
|
|
@@ -308,16 +308,16 @@ function O(e, { height: r = "48px", ...i }) {
|
|
|
308
308
|
case "CONFIRMATION_RESULT": n(), a.onResult(r.data.result);
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
|
-
return window.addEventListener("message",
|
|
311
|
+
return window.addEventListener("message", u), {
|
|
312
312
|
update(e) {
|
|
313
313
|
let t = "amount" in e, n = "merchantName" in e, r = "height" in e || "buttonProps" in e;
|
|
314
314
|
a = {
|
|
315
315
|
...a,
|
|
316
316
|
...e
|
|
317
|
-
}, t &&
|
|
317
|
+
}, o && (t && s(), n && c(), r && l());
|
|
318
318
|
},
|
|
319
319
|
destroy() {
|
|
320
|
-
window.removeEventListener("message",
|
|
320
|
+
window.removeEventListener("message", u), n();
|
|
321
321
|
}
|
|
322
322
|
};
|
|
323
323
|
}
|
|
@@ -433,33 +433,33 @@ function B(e, { height: t = "48px", ...n }) {
|
|
|
433
433
|
let r = {
|
|
434
434
|
...n,
|
|
435
435
|
height: t
|
|
436
|
-
};
|
|
437
|
-
function
|
|
436
|
+
}, i = !1;
|
|
437
|
+
function a() {
|
|
438
438
|
h({
|
|
439
439
|
iframe: e,
|
|
440
440
|
amount: r.amount
|
|
441
441
|
});
|
|
442
442
|
}
|
|
443
|
-
function
|
|
443
|
+
function o() {
|
|
444
444
|
g({
|
|
445
445
|
iframe: e,
|
|
446
446
|
merchantName: r.merchantName
|
|
447
447
|
});
|
|
448
448
|
}
|
|
449
|
-
function
|
|
449
|
+
function s() {
|
|
450
450
|
m({
|
|
451
451
|
iframe: e,
|
|
452
452
|
height: r.height ?? "48px",
|
|
453
453
|
props: r.buttonProps ?? {}
|
|
454
454
|
});
|
|
455
455
|
}
|
|
456
|
-
function
|
|
456
|
+
function c(t) {
|
|
457
457
|
if (t.source === e.contentWindow) switch (t.data.type) {
|
|
458
458
|
case "IFRAME_READY":
|
|
459
|
-
d(e), f({
|
|
459
|
+
i = !0, d(e), f({
|
|
460
460
|
iframe: e,
|
|
461
461
|
appearance: {}
|
|
462
|
-
}),
|
|
462
|
+
}), a(), o(), s();
|
|
463
463
|
break;
|
|
464
464
|
case "UPDATE_HEIGHT":
|
|
465
465
|
r.onHeightChange?.(t.data.height);
|
|
@@ -492,16 +492,16 @@ function B(e, { height: t = "48px", ...n }) {
|
|
|
492
492
|
case "CONFIRMATION_RESULT": r.onResult(t.data.result);
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
|
-
return window.addEventListener("message",
|
|
495
|
+
return window.addEventListener("message", c), {
|
|
496
496
|
update(e) {
|
|
497
|
-
let t = "amount" in e, n = "merchantName" in e,
|
|
497
|
+
let t = "amount" in e, n = "merchantName" in e, c = "height" in e || "buttonProps" in e;
|
|
498
498
|
r = {
|
|
499
499
|
...r,
|
|
500
500
|
...e
|
|
501
|
-
}, t &&
|
|
501
|
+
}, i && (t && a(), n && o(), c && s());
|
|
502
502
|
},
|
|
503
503
|
destroy() {
|
|
504
|
-
window.removeEventListener("message",
|
|
504
|
+
window.removeEventListener("message", c);
|
|
505
505
|
}
|
|
506
506
|
};
|
|
507
507
|
}
|
|
@@ -553,11 +553,11 @@ function K(e = "country") {
|
|
|
553
553
|
return `${H[e] ?? H.country}px`;
|
|
554
554
|
}
|
|
555
555
|
function q(e, t) {
|
|
556
|
-
let n = { ...t };
|
|
557
|
-
function
|
|
556
|
+
let n = { ...t }, r = !1;
|
|
557
|
+
function i(t) {
|
|
558
558
|
if (t.source === e.contentWindow) switch (t.data.type) {
|
|
559
559
|
case "IFRAME_READY":
|
|
560
|
-
d(e), f({
|
|
560
|
+
r = !0, d(e), f({
|
|
561
561
|
iframe: e,
|
|
562
562
|
appearance: n.appearance
|
|
563
563
|
});
|
|
@@ -584,19 +584,19 @@ function q(e, t) {
|
|
|
584
584
|
case "CONFIRMATION_RESULT": n.onResult(t.data.result);
|
|
585
585
|
}
|
|
586
586
|
}
|
|
587
|
-
return window.addEventListener("message",
|
|
587
|
+
return window.addEventListener("message", i), {
|
|
588
588
|
update(t) {
|
|
589
|
-
let
|
|
589
|
+
let i = "appearance" in t;
|
|
590
590
|
n = {
|
|
591
591
|
...n,
|
|
592
592
|
...t
|
|
593
|
-
}, r && f({
|
|
593
|
+
}, i && r && f({
|
|
594
594
|
iframe: e,
|
|
595
595
|
appearance: n.appearance
|
|
596
596
|
});
|
|
597
597
|
},
|
|
598
598
|
destroy() {
|
|
599
|
-
window.removeEventListener("message",
|
|
599
|
+
window.removeEventListener("message", i);
|
|
600
600
|
}
|
|
601
601
|
};
|
|
602
602
|
}
|
package/package.json
CHANGED
package/src/apple-pay.ts
CHANGED
|
@@ -132,6 +132,9 @@ export function attachApplePayButtonListeners(
|
|
|
132
132
|
...options,
|
|
133
133
|
height,
|
|
134
134
|
};
|
|
135
|
+
// React calls `update()` on first paint, before the iframe has left
|
|
136
|
+
// about:blank. Queue until IFRAME_READY so postMessage targetOrigin matches.
|
|
137
|
+
let ready = false;
|
|
135
138
|
|
|
136
139
|
function pushAmount() {
|
|
137
140
|
sendUpdateAmount({ iframe, amount: current.amount });
|
|
@@ -157,6 +160,7 @@ export function attachApplePayButtonListeners(
|
|
|
157
160
|
|
|
158
161
|
switch (event.data.type) {
|
|
159
162
|
case "IFRAME_READY":
|
|
163
|
+
ready = true;
|
|
160
164
|
sendParentReadyMessage(iframe);
|
|
161
165
|
sendUpdateAppearance({ iframe, appearance: {} });
|
|
162
166
|
pushAmount();
|
|
@@ -224,6 +228,9 @@ export function attachApplePayButtonListeners(
|
|
|
224
228
|
const hadMerchantName = "merchantName" in patch;
|
|
225
229
|
const hadButtonProps = "height" in patch || "buttonProps" in patch;
|
|
226
230
|
current = { ...current, ...patch };
|
|
231
|
+
if (!ready) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
227
234
|
if (hadAmount) {
|
|
228
235
|
pushAmount();
|
|
229
236
|
}
|
package/src/google-pay.ts
CHANGED
|
@@ -118,6 +118,9 @@ export function attachGooglePayButtonListeners(
|
|
|
118
118
|
...options,
|
|
119
119
|
height,
|
|
120
120
|
};
|
|
121
|
+
// React calls `update()` on first paint, before the iframe has left
|
|
122
|
+
// about:blank. Queue until IFRAME_READY so postMessage targetOrigin matches.
|
|
123
|
+
let ready = false;
|
|
121
124
|
|
|
122
125
|
function pushAmount() {
|
|
123
126
|
sendUpdateAmount({ iframe, amount: current.amount });
|
|
@@ -142,6 +145,7 @@ export function attachGooglePayButtonListeners(
|
|
|
142
145
|
|
|
143
146
|
switch (event.data.type) {
|
|
144
147
|
case "IFRAME_READY":
|
|
148
|
+
ready = true;
|
|
145
149
|
sendParentReadyMessage(iframe);
|
|
146
150
|
sendUpdateAppearance({ iframe, appearance: {} });
|
|
147
151
|
pushAmount();
|
|
@@ -194,6 +198,9 @@ export function attachGooglePayButtonListeners(
|
|
|
194
198
|
const hadMerchantName = "merchantName" in patch;
|
|
195
199
|
const hadButtonProps = "height" in patch || "buttonProps" in patch;
|
|
196
200
|
current = { ...current, ...patch };
|
|
201
|
+
if (!ready) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
197
204
|
if (hadAmount) {
|
|
198
205
|
pushAmount();
|
|
199
206
|
}
|
|
@@ -194,6 +194,9 @@ export function attachPaymentMethodFormListeners(
|
|
|
194
194
|
options: PaymentMethodFormListenerOptions,
|
|
195
195
|
): PaymentMethodFormController {
|
|
196
196
|
let current = { ...options };
|
|
197
|
+
// React calls `update()` on first paint, before the iframe has left
|
|
198
|
+
// about:blank. Queue until IFRAME_READY so postMessage targetOrigin matches.
|
|
199
|
+
let ready = false;
|
|
197
200
|
|
|
198
201
|
function handleMessage(event: MessageEvent<Message>) {
|
|
199
202
|
if (event.source !== iframe.contentWindow) {
|
|
@@ -202,6 +205,7 @@ export function attachPaymentMethodFormListeners(
|
|
|
202
205
|
|
|
203
206
|
switch (event.data.type) {
|
|
204
207
|
case "IFRAME_READY":
|
|
208
|
+
ready = true;
|
|
205
209
|
sendParentReadyMessage(iframe);
|
|
206
210
|
sendUpdateAppearance({ iframe, appearance: current.appearance });
|
|
207
211
|
break;
|
|
@@ -241,7 +245,7 @@ export function attachPaymentMethodFormListeners(
|
|
|
241
245
|
update(patch) {
|
|
242
246
|
const hadAppearance = "appearance" in patch;
|
|
243
247
|
current = { ...current, ...patch };
|
|
244
|
-
if (hadAppearance) {
|
|
248
|
+
if (hadAppearance && ready) {
|
|
245
249
|
sendUpdateAppearance({ iframe, appearance: current.appearance });
|
|
246
250
|
}
|
|
247
251
|
},
|