@amos.com/amos-js 0.10.1 → 0.10.3
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/README.md +17 -4
- package/dist/index.js +3 -3
- package/dist/index.mjs +334 -267
- package/dist/jwt.d.ts +4 -0
- package/dist/log.d.ts +12 -0
- package/dist/mount.d.ts +15 -1
- package/dist/payment-method-form.d.ts +4 -1
- package/dist/types.d.ts +15 -4
- package/package.json +5 -5
- package/src/jwt.ts +25 -0
- package/src/log.ts +74 -0
- package/src/messaging.ts +19 -0
- package/src/mount.ts +17 -2
- package/src/payment-method-form.ts +7 -0
- package/src/plaid-bank-ui.ts +11 -0
- package/src/types.ts +16 -4
package/README.md
CHANGED
|
@@ -173,7 +173,7 @@ Setup intents are used to save payment methods for future use (e.g. recurring pa
|
|
|
173
173
|
- On the client, call `confirmSetupIntent({ iframe, token })` instead of `confirmPaymentIntent({ iframe, token })`.
|
|
174
174
|
- The same `onResult` callback is used; succeeded setup intents arrive as `{ status: "succeeded", intent: "setup", setupIntent }`.
|
|
175
175
|
|
|
176
|
-
The same `mountAmosCreditCardPaymentMethodForm` / `mountAmosBankAccountPaymentMethodForm` controllers support both payment intents and setup intents — they are differentiated by which confirmation function you call.
|
|
176
|
+
The same `mountAmosCreditCardPaymentMethodForm` / `mountAmosBankAccountPaymentMethodForm` controllers support both payment intents and setup intents — they are differentiated by which confirmation function you call. For bank setup, pass `intent: "setup"` so Connect / Plaid is always shown (no merchant ACH threshold lookup).
|
|
177
177
|
|
|
178
178
|
## Understanding PCI DSS compliance requirements
|
|
179
179
|
|
|
@@ -298,9 +298,10 @@ When the charge meets the merchant’s ACH verification threshold, the SDK hides
|
|
|
298
298
|
|
|
299
299
|
**Additional `options` (ACH verification):**
|
|
300
300
|
|
|
301
|
-
- `amount` (`string`, major-currency decimal, e.g. `"50.00"`, **required**, defaults to `"0"`) — same format as Google Pay / Apple Pay. Compared to the threshold the iframe fetches (cents). Pass `"0"` (the default) on open-amount forms until the customer enters a charge — 0 is typically under the threshold, so Connect stays hidden. Pass `amount` and `update({ amount })` when it changes.
|
|
301
|
+
- `amount` (`string`, major-currency decimal, e.g. `"50.00"`, **required**, defaults to `"0"`) — same format as Google Pay / Apple Pay. Compared to the threshold the iframe fetches (cents). Pass `"0"` (the default) on open-amount forms until the customer enters a charge — 0 is typically under the threshold, so Connect stays hidden. Pass `amount` and `update({ amount })` when it changes.
|
|
302
|
+
- `intent` (`"payment" | "setup"`, defaults to `"payment"`) — `"setup"` always shows Connect / Plaid (no merchant ACH threshold lookup), unless the render token disables verification. Use this when saving a bank account for later charges.
|
|
302
303
|
|
|
303
|
-
Compare locally once the iframe posts `ACH_THRESHOLD`: Plaid when the amount (converted to cents, default `0`) is `>= achThreshold`. No threshold (or `null`) keeps the manual bank form. If `amount` later drops under the threshold, Plaid credentials are dropped and the iframe form is shown again.
|
|
304
|
+
Compare locally once the iframe posts `ACH_THRESHOLD`: Plaid when `requireVerification` is true (setup intents), or when the amount (converted to cents, default `0`) is `>= achThreshold`. No threshold (or `null`) keeps the manual bank form. Render tokens with Plaid verification disabled never require Connect. If `amount` later drops under the threshold, Plaid credentials are dropped and the iframe form is shown again.
|
|
304
305
|
|
|
305
306
|
```ts
|
|
306
307
|
import { mountAmosBankAccountPaymentMethodForm } from "@amos.com/amos-js";
|
|
@@ -316,6 +317,18 @@ const bank = mountAmosBankAccountPaymentMethodForm("#bank-form", {
|
|
|
316
317
|
bank.update({ amount: "25.00" });
|
|
317
318
|
```
|
|
318
319
|
|
|
320
|
+
Setup (always Connect, no merchant lookup):
|
|
321
|
+
|
|
322
|
+
```ts
|
|
323
|
+
mountAmosBankAccountPaymentMethodForm("#bank-form", {
|
|
324
|
+
renderToken,
|
|
325
|
+
intent: "setup",
|
|
326
|
+
onResult: (result) => {
|
|
327
|
+
/* … */
|
|
328
|
+
},
|
|
329
|
+
});
|
|
330
|
+
```
|
|
331
|
+
|
|
319
332
|
`validateForm` / `confirmPaymentIntent` / `confirmSetupIntent` stay iframe-based. When Plaid succeeded, confirm sends `payment_method.plaid` (`public_token`, `account_id`) and does not require typed account numbers.
|
|
320
333
|
|
|
321
334
|
**CSP:** the parent page must allow Plaid’s script and frames, for example `script-src https://cdn.plaid.com` and `frame-src https://cdn.plaid.com https://*.plaid.com`. Amos never loads `PLAID_SECRET` / `PLAID_CLIENT_ID` in the SDK or embed iframe.
|
|
@@ -424,7 +437,7 @@ Advanced helpers exposed for integrators that need to construct or inspect the m
|
|
|
424
437
|
- **`onResult` is not settlement proof**: `onResult` tells you when to stop waiting (e.g. dismiss a spinner). Verify payment or setup success on your backend via webhooks. On `status: "incomplete"`, unlock your UI — the customer can fix fields in the iframe and retry. Use `result.reason` (`"field_errors"` or `"validation_failed"`) to distinguish recoverable states.
|
|
425
438
|
- **Same components for payment vs setup intents**: `mountAmosCreditCardPaymentMethodForm` and `mountAmosBankAccountPaymentMethodForm` support both payment intents and setup intents. The flow differs only by which server call you make and which confirmation function you use. Handle both outcomes via `onResult`.
|
|
426
439
|
- **Amount format**: for `mountAmosGooglePayButton`, `mountAmosApplePayButton`, and `mountAmosBankAccountPaymentMethodForm`, `amount` is a major-currency decimal string (e.g. `"50.00"` for $50.00). For `components["schemas"]["CreatePaymentIntentInput"]` on the server (card/bank create, and the object the wallet iframe sends to `onInitiatePaymentIntentRequest`), `amount` is a number in cents (e.g. `5000`).
|
|
427
|
-
- **Plaid Link (ACH verification)**: load `cdn.plaid.com` from the **parent** document (see CSP above). Merchants do not proxy Pay API; the bank iframe fetches the ACH threshold and mints link tokens. Confirm still goes through the bank iframe so Amos can attach `plaid` to the payment method.
|
|
440
|
+
- **Plaid Link (ACH verification)**: load `cdn.plaid.com` from the **parent** document (see CSP above). Merchants do not proxy Pay API; the bank iframe fetches the ACH threshold for payment intents and mints link tokens. Setup intents skip the merchant lookup and always require Plaid unless the render token disables verification. Confirm still goes through the bank iframe so Amos can attach `plaid` to the payment method.
|
|
428
441
|
- **Apple Pay waiting overlay**: on browsers where Apple's QR handoff opens in a popup (non-Safari), `mountAmosApplePayButton` shows a fixed full-viewport overlay on the host page until payment completes, the popup closes, or the user clicks **Cancel payment**. Avoid stacking other fixed UI above it.
|
|
429
442
|
- **Browser-only**: the mount and messaging helpers require `window` and the DOM. They are not safe to call during server-side rendering — call them from client-side code only (for example, inside a `useEffect`-like hook in your framework of choice).
|
|
430
443
|
|
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
|
|
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(){if(typeof window>`u`)return!1;let{hostname:e}=window.location;return e===`localhost`||e.endsWith(`.localhost`)}function a(e){if(i())return`https://embed.localhost`;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`}}function o(e){return e}var s=new Set([`authorization`,`cookie`,`set-cookie`,`x-api-key`]),c=new Set([`authorization`,`encrypted_account_number`,`link_token`,`public_token`,`token`]);function l(e){let t={};for(let[n,r]of Object.entries(e))t[n]=s.has(n.toLowerCase())?`[REDACTED]`:r;return t}function u(e){if(Array.isArray(e))return e.map(u);if(typeof e==`object`&&e){let t={};for(let[n,r]of Object.entries(e))t[n]=c.has(n)?`[REDACTED]`:u(r);return t}return e}function d({iframe:e,message:t,endpoint:n,headers:r={},body:i}){e.contentWindow?.postMessage(o({type:`PARENT_INFO_LOG`,message:t,endpoint:n,headers:l(r),body:u(i)}),new URL(e.src).origin)}var f=new WeakMap;function p(e,t){f.set(e,t)}function m(e){if(e)return f.get(e)}function h(e){e&&f.delete(e)}function g(e){return new URL(e.src).origin}function _(e){e?.contentWindow&&e.contentWindow.postMessage(o({type:`PARENT_ACKNOWLEDGED_IFRAME_READY`}),g(e))}function v({iframe:e,appearance:t={}}){e?.contentWindow&&e.contentWindow.postMessage(o({type:`UPDATE_APPEARANCE`,appearance:t}),g(e))}function y({iframe:e,props:t,height:n}){e?.contentWindow&&e.contentWindow.postMessage(o({type:`UPDATE_APPLE_PAY_BUTTON`,height:n,props:t}),g(e))}function b({iframe:e,props:t,height:n}){e?.contentWindow&&e.contentWindow.postMessage(o({type:`UPDATE_GOOGLE_PAY_BUTTON`,height:n,props:t}),g(e))}function x({iframe:e,amount:t}){e?.contentWindow&&e.contentWindow.postMessage(o({type:`UPDATE_AMOUNT`,amount:t}),g(e))}function S({iframe:e,merchantName:t}){e?.contentWindow&&e.contentWindow.postMessage(o({type:`UPDATE_MERCHANT_NAME`,merchantName:t}),g(e))}function C({iframe:e}){let t=m(e);if(t?.requiresVerification)return Promise.resolve(!!t.plaid);let n=crypto.randomUUID();return new Promise(t=>{e?.contentWindow&&e.contentWindow.postMessage(o({type:`VALIDATE_FORM`,requestId:n}),g(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 w=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(o({type:`CREATE_PLAID_LINK_TOKEN`,requestId:t}),g(e));let a=setTimeout(()=>{window.removeEventListener(`message`,s),r(Error(`Timed out waiting for Plaid Link token.`))},w);function s(e){if(e.source===i&&e.data.type===`PLAID_LINK_TOKEN`&&e.data.requestId===t){if(window.removeEventListener(`message`,s),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`,s)})}function T({iframe:e}){m(e)?.clearLinked?.(),E(e)}function E(e){e?.contentWindow&&e.contentWindow.postMessage(o({type:`RESET_FORM`}),g(e))}function D({iframe:e,type:t,token:n,id:r}){let i=m(e),a=i?.plaid;i?.requiresVerification&&!a&&E(e);let s=g(e);d({iframe:e,message:t===`CONFIRM_PAYMENT_INTENT`?`confirmPaymentIntent`:`confirmSetupIntent`,endpoint:t===`CONFIRM_PAYMENT_INTENT`?`POST /embed/payment_intents/{id}/confirm_with_payment_method`:`POST /embed/setup_intents/{id}/confirm_with_payment_method`,headers:{origin:window.location.origin,"iframe-origin":s},body:{id:r,token:n,...a?{plaid:a}:{}}}),e.contentWindow?.postMessage(o({type:t,token:n,id:r,...a?{plaid:a}:{}}),g(e))}function O({iframe:e,token:t}){if(!e?.contentWindow)return;let{payment_intent_id:n}=r(t).payload;D({iframe:e,type:`CONFIRM_PAYMENT_INTENT`,token:t,id:n??void 0})}function k({iframe:e,token:t}){if(!e?.contentWindow)return;let{setup_intent_id:n}=r(t).payload;D({iframe:e,type:`CONFIRM_SETUP_INTENT`,token:t,id:n??void 0})}function A({iframe:e,result:t}){e?.contentWindow&&e.contentWindow.postMessage(o({type:`CONFIRMATION_RESULT`,result:t}),g(e))}function te(e){return`${a(e)}/iframe/apple-pay?token=${e}`}function j(){return`48px`}function ne(e){e.contentWindow?.postMessage(o({type:`APPLE_PAY_CANCEL`}),g(e))}function M(e,{height:r=`48px`,...i}){let a={...i,height:r};function o(){x({iframe:e,amount:a.amount})}function s(){S({iframe:e,merchantName:a.merchantName})}function c(){y({iframe:e,height:a.height??`48px`,props:a.buttonProps??{}})}function l(r){if(r.source===e.contentWindow)switch(r.data.type){case`IFRAME_READY`:_(e),v({iframe:e,appearance:{}}),o(),s(),c();break;case`UPDATE_HEIGHT`:a.onHeightChange?.(r.data.height);break;case`UPDATE_APPEARANCE`:v({iframe:e,appearance:r.data.appearance});break;case`UPDATED_APPEARANCE`:a.onAppearanceReady?.();break;case`APPLE_PAY_WINDOW_OPEN`:t({onCancel:()=>{ne(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=>{O({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`,l),{update(e){let t=`amount`in e,n=`merchantName`in e,r=`height`in e||`buttonProps`in e;a={...a,...e},t&&o(),n&&s(),r&&c()},destroy(){window.removeEventListener(`message`,l),n()}}}var N=`amos-js-form-skeleton-styles`,re={"--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`},ie=`
|
|
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
|
|
68
|
+
`;function P(){if(document.getElementById(N))return;let e=document.createElement(`style`);e.id=N,e.textContent=ie,document.head.appendChild(e)}function ae(e,t){for(let[t,n]of Object.entries(re))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 F(e,t){let n=document.createElement(`div`);if(n.className=e,t)for(let e of t)n.appendChild(e);return n}function I(e,t){let n=F(`amos-js-form-skeleton-field`);t!==void 0&&(n.style.flexGrow=String(t)),e===`above`&&n.appendChild(F(`amos-js-form-skeleton-label`));let r=F(`amos-js-form-skeleton-input`);return e===`floating`&&r.classList.add(`amos-js-form-skeleton-input-floating`),n.appendChild(r),n}function L(e,t){return F(t?`amos-js-form-skeleton-row-stack`:`amos-js-form-skeleton-row`,e)}function R({labels:e,requirement:t,wrapCountryZip:n}){return t===`full`?[I(e),I(e),L([I(e,1.4),I(e,.7),I(e,.8)],!1),I(e)]:[L([I(e),I(e)],n)]}function oe(e){let t=e.appearance?.labels??`above`,n=e.billingAddressRequirement??`country`;if(e.kind===`card`){let r=[I(t),L([I(t),I(t)],!1)];return e.additionalFields?.cardholderName&&r.push(I(t)),r.push(...R({labels:t,requirement:n,wrapCountryZip:!1})),r}return[I(t),L([I(t),I(t)],!0),I(t),L([I(`above`),I(`above`)],!0),...R({labels:t,requirement:n,wrapCountryZip:!0})]}function z(e){P();let t=F(`amos-js-form-skeleton`);t.setAttribute(`aria-hidden`,`true`);function n(e){ae(t,e.appearance),t.replaceChildren(...oe(e))}return n(e),{element:t,update:n}}function B(e){P();let t=F(`amos-js-form-skeleton-input amos-js-wallet-skeleton`);t.setAttribute(`aria-hidden`,`true`);function n(e){ae(t,void 0),t.style.height=e.height,t.style.borderRadius=e.borderRadius??`4px`}return n(e),{element:t,update:n}}function V(e){if(typeof e==`number`&&Number.isFinite(e))return`${e}px`;if(typeof e==`string`&&e.trim()!==``)return e.trim()}function H({iframeStyle:e,buttonProps:t}){return V(e?.borderRadius)??V(t?.buttonRadius)??V(t?.style?.borderRadius)??V(t?.style?.[`--apple-pay-button-border-radius`])??`4px`}function U(e){return`${a(e)}/iframe/google-pay?token=${e}`}function W(){return`48px`}function G(e,{height:t=`48px`,...n}){let r={...n,height:t};function i(){x({iframe:e,amount:r.amount})}function a(){S({iframe:e,merchantName:r.merchantName})}function o(){b({iframe:e,height:r.height??`48px`,props:r.buttonProps??{}})}function s(t){if(t.source===e.contentWindow)switch(t.data.type){case`IFRAME_READY`:_(e),v({iframe:e,appearance:{}}),i(),a(),o();break;case`UPDATE_HEIGHT`:r.onHeightChange?.(t.data.height);break;case`UPDATE_APPEARANCE`:v({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=>{O({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`,s),{update(e){let t=`amount`in e,n=`merchantName`in e,s=`height`in e||`buttonProps`in e;r={...r,...e},t&&i(),n&&a(),s&&o()},destroy(){window.removeEventListener(`message`,s)}}}function se({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 K={country:212,full:452},ce=80,q={country:400,full:640};function J(e,t={cardholderName:!1},n=`country`){let r=Object.entries(t).filter(([,e])=>e).map(([e])=>e).join(`,`),i=new URLSearchParams({token:e,additionalFields:r,billingAddressRequirement:n});return`${a(e)}/iframe/card?${i}`}function Y(e,t=`country`,n=`payment`){let r=new URLSearchParams({token:e,billingAddressRequirement:t});return n===`setup`&&r.set(`intent`,`setup`),`${a(e)}/iframe/bank?${r}`}function le(e={cardholderName:!1},t=`country`){return`${(K[t]??K.country)+(e.cardholderName?ce:0)}px`}function ue(e=`country`){return`${q[e]??q.country}px`}function de(e,t){let n={...t};function r(t){if(t.source===e.contentWindow)switch(t.data.type){case`IFRAME_READY`:_(e),v({iframe:e,appearance:n.appearance});break;case`UPDATE_HEIGHT`:n.onHeightChange?.(t.data.height);break;case`UPDATE_APPEARANCE`:v({iframe:e,appearance:t.data.appearance});break;case`UPDATED_APPEARANCE`:n.onAppearanceReady?.();break;case`FORM_VALIDITY_CHANGE`:if(m(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`,r),{update(t){let r=`appearance`in t;n={...n,...t},r&&v({iframe:e,appearance:n.appearance})},destroy(){window.removeEventListener(`message`,r)}}}var fe=`https://cdn.plaid.com/link/v2/stable/link-initialize.js`;function pe({amount:e,achThreshold:t}){return t!=null&&(e??0)>=t}function me(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 he(e){return e.account_id??e.account?.id??e.accounts?.[0]?.id}function ge(e){let t=e.account??e.accounts?.[0];return{bankName:e.institution?.name??`Bank account`,last4:t?.mask??``}}var X;function _e(){for(let e of document.querySelectorAll(`script[src="${fe}"]`))e.remove()}function ve(){return typeof window>`u`?Promise.reject(Error(`Plaid Link requires a browser`)):window.Plaid?Promise.resolve():X||(_e(),X=new Promise((e,t)=>{let n=document.createElement(`script`);n.src=fe,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 ye({token:e,onSuccess:t,onExit:n,signal:r}){if(await ve(),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 be=`amos-js-plaid-bank-ui-styles`,xe=`
|
|
69
69
|
.amos-js-plaid-panel {
|
|
70
70
|
box-sizing: border-box;
|
|
71
71
|
color: var(--foreground, oklch(0.145 0 0));
|
|
@@ -171,4 +171,4 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=`data-a
|
|
|
171
171
|
transition: none;
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
`;function
|
|
174
|
+
`;function Se(){if(document.getElementById(be))return;let e=document.createElement(`style`);e.id=be,e.textContent=xe,document.head.append(e)}function Ce(e,t,n){for(let t of n)e.style.removeProperty(t);n.length=0;let r=t?.themeVariables;if(r)for(let[t,i]of Object.entries(r))typeof i==`string`&&i.trim()!==``&&(e.style.setProperty(t,i.trim()),n.push(t))}function we({host:e,iframe:t,options:n}){Se();let r={...n,amount:n.amount??`0`},i=[],a=!1,o,s=!1,c,l=!1,u,f,m=new AbortController,g,_=document.createElement(`div`);_.className=`amos-js-plaid-panel`,_.setAttribute(`data-amos-plaid-panel`,`true`),_.dataset.mode=`hidden`,Ce(_,r.appearance,i);let v=document.createElement(`button`);v.type=`button`,v.className=`amos-js-plaid-connect`,v.textContent=`Connect bank account`,v.setAttribute(`data-testid`,`amos-plaid-connect`);let y=document.createElement(`div`);y.className=`amos-js-plaid-linked`;let b=document.createElement(`span`);b.className=`amos-js-plaid-linked-name`;let x=document.createElement(`span`);x.className=`amos-js-plaid-linked-meta`;let S=document.createElement(`button`);S.type=`button`,S.className=`amos-js-plaid-disconnect`,S.textContent=`Disconnect`,S.setAttribute(`aria-label`,`Disconnect bank account`);let C=document.createElement(`p`);C.className=`amos-js-plaid-error`,C.setAttribute(`role`,`alert`),y.append(b,x,S),_.append(v,y,C),e.append(_);let w=t.parentElement;function T(e){C.textContent=e??``}function E(){return a?s?!0:pe({amount:me(r.amount),achThreshold:o}):!1}function D(){let e=!!g;u!==e&&(u=e,r.onValidityChange?.({isValid:e}))}function O(){let e=E();if(p(t,{requiresVerification:e,plaid:e?g?.credentials:void 0,clearLinked:k}),!e){_.dataset.mode=`hidden`,w&&(w.style.display=``),u=void 0;return}_.dataset.mode=g?`linked`:`connect`,w&&(w.style.display=`none`),g&&(b.textContent=g.bankName,x.textContent=g.last4?`****${g.last4}`:`Connected`),D()}function k(){g=void 0,c=void 0,f?.(),f=void 0,T(void 0),O()}function A(e){if(e.source===t.contentWindow&&e.data.type===`ACH_THRESHOLD`){if(a=!0,o=e.data.achThreshold??void 0,s=e.data.requireVerification===!0,d({iframe:t,message:`merchant ach_threshold`,endpoint:`ACH_THRESHOLD`,headers:{origin:e.origin},body:{achThreshold:o,requireVerification:s}}),g&&!E()){k();return}O()}}return window.addEventListener(`message`,A),O(),S.addEventListener(`click`,()=>{k()}),v.addEventListener(`click`,()=>{(async()=>{if(!(m.signal.aborted||l)){l=!0,v.disabled=!0,T(void 0);try{if(c||=await ee({iframe:t}),m.signal.aborted)return;let e=c;f?.(),f=await ye({token:e,signal:m.signal,onSuccess:(e,t)=>{if(m.signal.aborted)return;let n=he(t);if(!n){T(`Select a bank account to continue.`);return}let r=ge(t);g={credentials:{public_token:e,account_id:n},bankName:r.bankName,last4:r.last4},c=void 0,O()},onExit:e=>{m.signal.aborted||e?.error_code===`INVALID_LINK_TOKEN`&&(c=void 0)}}),m.signal.aborted&&(f(),f=void 0)}catch(e){if(c=void 0,m.signal.aborted)return;T(e instanceof Error?e.message:`Could not connect bank.`)}finally{l=!1,m.signal.aborted||(v.disabled=!1)}}})()}),{update(e){if(`amount`in e&&(r.amount=e.amount??`0`),`onValidityChange`in e&&(r.onValidityChange=e.onValidityChange),`appearance`in e&&(r.appearance=e.appearance,Ce(_,r.appearance,i)),g&&!E()){k();return}O()},destroy(){m.abort(),window.removeEventListener(`message`,A),f?.(),f=void 0,h(t),_.remove()}}}function Z(e){if(typeof e==`string`){let t=document.querySelector(e);if(!(t instanceof HTMLElement))throw Error(`[amos-js] Container "${e}" did not match any HTMLElement.`);return t}return e}var Q={width:`calc(100% + 8px)`,transition:`opacity 150ms ease-in, height 200ms ease-in-out`,margin:`0 -4px`,opacity:`0`,border:`0`},Te={width:`100%`,transition:`height 200ms ease-in-out`,margin:`0`,opacity:`0`,border:`0`},Ee={position:`absolute`,top:`0`,left:`0`,width:`100%`,height:`100%`,margin:`0`,opacity:`0`,transition:`none`,pointerEvents:`none`},De={position:`absolute`,top:`0`,left:`-4px`,width:`calc(100% + 8px)`,height:`100%`,margin:`0`,transition:`none`,pointerEvents:`none`};function $({src:e,title:t,name:n,height:r,allow:i,className:a,style:o=Q}){let s=document.createElement(`iframe`);return s.src=e,s.title=t,s.name=n,s.setAttribute(`role`,`presentation`),s.scrolling=`no`,i&&(s.allow=i),a!=null&&(s.className=a),Object.assign(s.style,o,{height:r}),s}function Oe({host:e,iframe:t,listenerOptions:n,skeletonOptions:r}){let i=document.createElement(`div`);i.style.position=`relative`,i.style.width=`100%`,i.setAttribute(`aria-busy`,`true`);let a=z(r);Object.assign(t.style,De),i.append(a.element,t),e.appendChild(i);let o=!1,s=!1,c,l=r.appearance,u,d;function f(){return i.getBoundingClientRect().height}function p(){return c?Number.parseFloat(c):NaN}function m(){if(o)return;o=!0,d!==void 0&&(clearTimeout(d),d=void 0);let e=f(),n=p(),r=Number.isFinite(n)?Math.max(n,e):e;t.style.transition=`none`,t.style.position=``,t.style.top=``,t.style.left=``,t.style.margin=Q.margin??``,t.style.height=`${r}px`,t.style.opacity=`1`,t.style.pointerEvents=``,a.element.remove(),i.removeAttribute(`aria-busy`),u=setTimeout(()=>{t.style.transition=`height 200ms ease-in-out`},400)}function h(){if(o||!s)return;let e=p(),t=f();Number.isFinite(e)&&e>=t-2&&m()}let g=de(t,{...n,onHeightChange:e=>{c=e,o?t.style.height=e:h(),n.onHeightChange?.(e)},onAppearanceReady:()=>{s=!0,h(),!o&&d===void 0&&(d=setTimeout(()=>{m()},1500)),n.onAppearanceReady?.()}});return{iframe:t,update(e){g.update(e),!o&&`appearance`in e&&(l=e.appearance,a.update({...r,appearance:l}))},destroy(){u!==void 0&&clearTimeout(u),d!==void 0&&clearTimeout(d),g.destroy(),i.remove()}}}function ke({host:e,iframe:t,listenerOptions:n,iframeStyle:r,attachListeners:i}){let a={height:n.height??`48px`,borderRadius:H({iframeStyle:r,buttonProps:n.buttonProps})},o=B(a),s=document.createElement(`div`);s.style.position=`relative`,s.style.width=`100%`,s.style.height=a.height,s.style.overflow=`hidden`,s.setAttribute(`aria-busy`,`true`),Object.assign(t.style,Ee),t.style.height=`100%`,s.append(o.element,t),e.appendChild(s);let c=!1,l=!1,u,d=n;function f(){c||(c=!0,u!==void 0&&(clearTimeout(u),u=void 0),t.style.opacity=`1`,t.style.pointerEvents=``,o.element.remove(),s.removeAttribute(`aria-busy`))}function p(){c||!l||f()}let m=i(t,{...n,onHeightChange:e=>{d.onHeightChange?.(e)},onAppearanceReady:()=>{l=!0,p(),d.onAppearanceReady?.()}});return u=setTimeout(()=>{f()},1500),{iframe:t,update(e){d={...d,...e};let t={...e};delete t.onAppearanceReady,delete t.onHeightChange,m.update(t),a={height:d.height??a.height,borderRadius:H({iframeStyle:r,buttonProps:d.buttonProps})},s.style.height=a.height,c||o.update(a)},destroy(){u!==void 0&&clearTimeout(u),m.destroy(),s.remove()}}}function Ae(e,t){let n=Z(e),{renderToken:r,additionalFields:i={cardholderName:!1},billingAddressRequirement:a=`country`,...o}=t;return Oe({host:n,iframe:$({src:J(r,i,a),title:`Secure credit card payment method form powered by Amos`,name:`amos-credit-card-payment-method-form`,height:le(i,a)}),listenerOptions:o,skeletonOptions:{kind:`card`,appearance:o.appearance,additionalFields:i,billingAddressRequirement:a}})}function je(e,t){let n=Z(e),{renderToken:r,billingAddressRequirement:i=`country`,amount:a=`0`,intent:o=`payment`,...s}=t,c=$({src:Y(r,i,o),title:`Secure bank account payment method form powered by Amos`,name:`amos-bank-account-payment-method-form`,height:ue(i)}),l=Oe({host:n,iframe:c,listenerOptions:s,skeletonOptions:{kind:`bank`,appearance:s.appearance,billingAddressRequirement:i}}),u=we({host:n,iframe:c,options:{amount:a,appearance:s.appearance,onValidityChange:s.onValidityChange}});return{iframe:c,update(e){l.update(e),u.update(e)},destroy(){u.destroy(),l.destroy()}}}function Me(e,t){let n=Z(e),{renderToken:r,iframeClassName:i,iframeStyle:a,...o}=t,s=$({src:U(r),title:`Secure Google Pay button powered by Amos`,name:`amos-google-pay-button`,height:o.height??W(),allow:`payment`,className:i,style:Te});return Object.assign(s.style,a),ke({host:n,iframe:s,listenerOptions:o,iframeStyle:a,attachListeners:G})}function Ne(e,t){let n=Z(e),{renderToken:r,iframeClassName:i,iframeStyle:a,...o}=t,s=$({src:te(r),title:`Secure Apple Pay button powered by Amos`,name:`amos-apple-pay-button`,height:o.height??j(),allow:`payment`,className:i,style:Te});return Object.assign(s.style,a),ke({host:n,iframe:s,listenerOptions:o,iframeStyle:a,attachListeners:M})}exports.SKELETON_STYLES=ie,exports.attachApplePayButtonListeners=M,exports.attachGooglePayButtonListeners=G,exports.attachPaymentMethodFormListeners=de,exports.confirmPaymentIntent=O,exports.confirmSetupIntent=k,exports.createMessage=o,exports.createPaymentMethodFormSkeleton=z,exports.createWalletButtonSkeleton=B,exports.decodeJwt=r,exports.ensureSkeletonStyles=P,exports.formatGooglePayPaymentData=se,exports.getApplePayButtonInitialHeight=j,exports.getApplePayButtonSrc=te,exports.getBankAccountFormInitialHeight=ue,exports.getBankAccountFormSrc=Y,exports.getCreditCardFormInitialHeight=le,exports.getCreditCardFormSrc=J,exports.getEmbedOrigin=a,exports.getGooglePayButtonInitialHeight=W,exports.getGooglePayButtonSrc=U,exports.linkedBankLabelFromMetadata=ge,exports.loadPlaidScript=ve,exports.mountAmosApplePayButton=Ne,exports.mountAmosBankAccountPaymentMethodForm=je,exports.mountAmosCreditCardPaymentMethodForm=Ae,exports.mountAmosGooglePayButton=Me,exports.openPlaidLink=ye,exports.plaidAccountIdFromMetadata=he,exports.requiresAchVerification=pe,exports.resetForm=T,exports.resolveWalletButtonSkeletonBorderRadius=H,exports.sendConfirmationResult=A,exports.sendParentReadyMessage=_,exports.updateAmount=x,exports.updateAppearance=v,exports.updateApplePayButton=y,exports.updateGooglePayButton=b,exports.updateMerchantName=S,exports.validateForm=C;
|