@gr4vy/secure-fields 2.3.4 → 2.5.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,33 @@
1
+ # v2.5.0 (Thu May 07 2026)
2
+
3
+ #### 🚀 Enhancement
4
+
5
+ - task: add api scheme detection [#1208](https://github.com/gr4vy/secure-fields/pull/1208) ([@luca-gr4vy](https://github.com/luca-gr4vy))
6
+
7
+ #### 🐛 Bug Fix
8
+
9
+ - task: Add field auto-focus functionality (opt-in) - TA-15759 [#1201](https://github.com/gr4vy/secure-fields/pull/1201) ([@luca-gr4vy](https://github.com/luca-gr4vy) [@GiordanoArman](https://github.com/GiordanoArman))
10
+
11
+ #### Authors: 2
12
+
13
+ - GiordanoArman ([@GiordanoArman](https://github.com/GiordanoArman))
14
+ - Luca Allievi ([@luca-gr4vy](https://github.com/luca-gr4vy))
15
+
16
+ ---
17
+
18
+ # v2.4.0 (Thu Apr 30 2026)
19
+
20
+ #### 🐛 Bug Fix
21
+
22
+ - task: add setautoadvance method [#1169](https://github.com/gr4vy/secure-fields/pull/1169) ([@luca-gr4vy](https://github.com/luca-gr4vy) [@GiordanoArman](https://github.com/GiordanoArman))
23
+
24
+ #### Authors: 2
25
+
26
+ - GiordanoArman ([@GiordanoArman](https://github.com/GiordanoArman))
27
+ - Luca Allievi ([@luca-gr4vy](https://github.com/luca-gr4vy))
28
+
29
+ ---
30
+
1
31
  # v2.3.4 (Tue Apr 21 2026)
2
32
 
3
33
  #### 🐛 Bug Fix
@@ -38,6 +38,7 @@ export declare enum LogMessages {
38
38
  PAYMENT_METHOD_ID_IN_USE = "You're passing a paymentMethodId to use a stored payment method, which means Secure Fields methods `addCardNumber`, `addExpiryDate` and `addClickToPay` are automatically disabled and won't render the related fields",
39
39
  PAYMENT_METHOD_ID_DEPRECATED = "The 'paymentMethodId' prop is deprecated and will be removed in a future version. Please use the 'paymentMethod' prop instead: { paymentMethod: { id: 'your-id', scheme: 'visa' } }",
40
40
  FIELD_PATTERN_IN_USE = "The `pattern` option can't be used on card fields, so it won't be applied here.",
41
+ AUTO_ADVANCE_ENABLED = "autoAdvance is enabled. Auto-advancing focus on field completion can degrade checkout UX (see WCAG 3.2.2). Use with caution.",
41
42
  NO_RECOGNITION_TOKEN = "The recognition token couldn't be obtained or the request took too much time. It is possible that a Click to Pay user was therefore not recognised."
42
43
  }
43
44
  export declare const MESSAGE_CHANNEL = "secure-fields";
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Events } from './constants';
2
2
  import { SecureInput } from './input';
3
- import type { ClickToPayInstance, ClickToPayOptions, CombinedEvents, Config, Field, FieldMaskConfig, ThreeDSecureOptions } from './types';
3
+ import type { AutoAdvanceConfig, ClickToPayInstance, ClickToPayOptions, CombinedEvents, Config, Field, FieldMaskConfig, ThreeDSecureOptions } from './types';
4
4
  declare global {
5
5
  interface Window {
6
6
  SECURE_FIELDS_FRAME_URL?: string;
@@ -24,6 +24,7 @@ declare class SecureFields {
24
24
  private threeDS?;
25
25
  environmentPath: string;
26
26
  private paymentMethodId?;
27
+ private autoAdvance;
27
28
  private controllerReady;
28
29
  private _resolveControllerReady;
29
30
  /**
@@ -42,6 +43,7 @@ declare class SecureFields {
42
43
  updateMethod(value: string, { data }: {
43
44
  data: any;
44
45
  }): void;
46
+ setAutoAdvance(config: AutoAdvanceConfig): void;
45
47
  private _addField;
46
48
  addCardNumberField(element: string | HTMLElement, options?: Omit<Field, 'element' | 'type'>): SecureInput;
47
49
  addSecurityCodeField(element: string | HTMLElement, options?: Omit<Field, 'element' | 'type' | 'maskInput'> & {
@@ -60,4 +62,4 @@ declare class SecureFields {
60
62
  addFont(font: string): void;
61
63
  }
62
64
  export { SecureFields, SecureInput, Events };
63
- export type { ClickToPayInstance, ClickToPayOptions, Config, CombinedEvents, Field, FieldType, FieldEvent, FieldMaskConfig, Styles, StylesTuple, FormChangeEventData, ThreeDSecureOptions, } from './types';
65
+ export type { AutoAdvanceConfig, ClickToPayInstance, ClickToPayOptions, Config, CombinedEvents, Field, FieldType, FieldEvent, FieldMaskConfig, Styles, StylesTuple, FormChangeEventData, ThreeDSecureOptions, } from './types';
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(this,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Events:()=>i,SecureFields:()=>Q,SecureInput:()=>W});var r=(e,t)=>"".concat(e,"?").concat(new URLSearchParams(t).toString()),n="@gr4vy-secure-fields-debug",i=function(e){return e.CARD_VAULT_SUCCESS="card-vault-success",e.CARD_VAULT_FAILURE="card-vault-failure",e.FORM_CHANGE="form-change",e.METHOD_CHANGE="method-change",e.READY="ready",e.RESIZE="resize",e.CLICK_TO_PAY_INITIALIZED="click-to-pay-initialized",e.CLICK_TO_PAY_READY="click-to-pay-ready",e.CLICK_TO_PAY_SIGN_OUT="click-to-pay-sign-out",e.CLICK_TO_PAY_ERROR="click-to-pay-error",e.CLICK_TO_PAY_CANCEL="click-to-pay-cancel",e.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD="click-to-pay-checkout-with-new-card",e.CLICK_TO_PAY_UNABLE_TO_LOAD_DPA="click-to-pay-unable-to-load-dpa",e.CLICK_TO_PAY_VISIBILITY_CHANGE="click-to-pay:visibility-change",e.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE="click-to-pay-card-form:visibility-change",e.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE="click-to-pay-sign-in:visibility-change",e.CLICK_TO_PAY_PROCESSING="click-to-pay-processing",e.CLICK_TO_PAY_AUTHENTICATE="click-to-pay-authenticate",e.CLICK_TO_PAY_AUTHENTICATE_FAILURE="click-to-pay-authenticate-failure",e.THREE_DS_START="three-ds-start",e.THREE_DS_FINISH="three-ds-finish",e}({}),o=function(e){return e.REQUEST_PORT="request-port",e.TRANSFER_PORT="transfer-port",e.REQUEST_RECOGNITION_TOKEN="request-recognition-token",e.REQUEST_RECOGNITION_TOKEN_FAILED="request-recognition-token-failed",e.RECOGNITION_TOKEN="recognition-token",e}({}),a=function(e){return e.FOCUSED="data-secure-fields-focused",e.INVALID="data-secure-fields-invalid",e.AUTOFILLED="data-secure-fields-autofilled",e}({}),s=function(e){return e.PAYMENT_METHOD_ID_IN_USE="You're passing a paymentMethodId to use a stored payment method, which means Secure Fields methods `addCardNumber`, `addExpiryDate` and `addClickToPay` are automatically disabled and won't render the related fields",e.PAYMENT_METHOD_ID_DEPRECATED="The 'paymentMethodId' prop is deprecated and will be removed in a future version. Please use the 'paymentMethod' prop instead: { paymentMethod: { id: 'your-id', scheme: 'visa' } }",e.FIELD_PATTERN_IN_USE="The `pattern` option can't be used on card fields, so it won't be applied here.",e.NO_RECOGNITION_TOKEN="The recognition token couldn't be obtained or the request took too much time. It is possible that a Click to Pay user was therefore not recognised.",e}({}),c="secure-fields",l={number:"addCardNumberField",expiryDate:"addExpiryDateField",securityCode:"addSecurityCodeField"},d=["01","02","03","04","05"];function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o=[],a=!0,s=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==r.return||r.return()}finally{if(s)throw i}}return o}}(e,t)||function(e,t){if(e){if("string"==typeof e)return u(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?u(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var p=new class{subscribe(e,t){this.subscribers.push([e,t])}unsubscribe(e,t){this.subscribers=this.subscribers.filter((r=>{var n=h(r,2),i=n[0],o=n[1];return i!==e||o.toString()!==t.toString()}))}unsubscribeAll(){this.subscribers=[]}publish(e,t){this.subscribers.forEach((r=>{var n=h(r,2),i=n[0],o=n[1];return setTimeout((()=>i===e?o(t):null),0)}))}constructor(){var e,t;t=void 0,(e="subscribers")in this?Object.defineProperty(this,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):this[e]=t,this.subscribers=[]}};function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function f(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o=[],a=!0,s=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==r.return||r.return()}finally{if(s)throw i}}return o}}(e,t)||function(e,t){if(e){if("string"==typeof e)return y(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?y(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var m=new class{add(e,t,r){window.addEventListener(e,t),this.listeners.push([e,t,r])}remove(e,t,r){var n=this.listeners.findIndex((n=>{var i=f(n,3),o=i[0],a=i[1],s=i[2];return o===e&&a.toString()===t.toString()&&s===r}));if(-1!==n){var i=f(this.listeners.splice(n,1),1),o=f(i[0],2),a=o[0],s=o[1];window.removeEventListener(a,s)}}removeAll(){this.listeners.forEach((e=>{var t=f(e,2),r=t[0],n=t[1];window.removeEventListener(r,n)})),this.listeners=[]}constructor(){var e,t;t=[],(e="listeners")in this?Object.defineProperty(this,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):this[e]=t}},b=e=>{var t,r;if(null===(t=document)||void 0===t?void 0:t.cookie)return null===(r="; ".concat(document.cookie).match(";\\s*".concat(e,"=([^;]+)")))||void 0===r?void 0:r[1]},v=["accesskey","autocapitalize","autocomplete","autofocus","aria-.","class","contenteditable","data-.","dir","draggable","enterkeyhint","hidden","id","inert","inputmode","is","itemid","itemprop","itemref","itemscope","itemtype","lang","nonce","onabort","onautocomplete","onautocompleteerror","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncontextmenu","oncuechange","ondblclick","ondrag","ondragend","ondragenter","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onmousewheel","onpause","onplay","onplaying","onprogress","onratechange","onreset","onresize","onscroll","onseeked","onseeking","onselect","onshow","onsort","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle","onvolumechange","onwaiting","popover","role","slot","spellcheck","style","tabindex","title","translate"],_=(e,t)=>e&&(e.style.display=t?"block":"none");function I(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function g(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){I(e,t,r[t])}))}return e}var O={debug:!1,level:"log"},C=(e,t,r)=>{var i=g({},O,r),o=i.debug,a=i.level;(o||"true"===localStorage.getItem(n))&&console[a]("Gr4vy - Secure Fields - ".concat(e),t||{})},E=(e,t,r)=>{var n,i;C(e,t,(n=g({},r),i=null!=(i={level:"warn"})?i:{},Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(i)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(i)).forEach((function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(i,e))})),n))},T=e=>(e!=e.toLowerCase()&&(e=e.replace(/[A-Z]/g,(e=>"-"+e.toLowerCase()))),e);function A(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var P=function(){var e=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return Object.entries(t).reduce(((n,i)=>{var o,a,s=(a=2,function(e){if(Array.isArray(e))return e}(o=i)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o=[],a=!0,s=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==r.return||r.return()}finally{if(s)throw i}}return o}}(o,a)||function(e,t){if(e){if("string"==typeof e)return A(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?A(e,t):void 0}}(o,a)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),c=s[0],l=s[1];return(e=>"[object Object]"===Object.prototype.toString.call(e))(l)?n.push(...e(t[c],"".concat((r+c).match(/[a-zA-Z0-9]+/g).join("-"),"-"))):(c=T(c).replace(/^-/,""),n.push(["--".concat(r).concat(c),l])),n}),[])};return e(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})};function w(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function S(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function N(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){S(e,t,r[t])}))}return e}function k(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}class L{init(e,t){var n;this.challengeWindowSize=d.includes(null==t?void 0:t.challengeWindowSize)?t.challengeWindowSize:"05",this.element="string"==typeof e?document.querySelector(e):e;var i="gr4vy-threeds-flow-controller";null===(n=document.body.querySelector("iframe#".concat(i)))||void 0===n||n.remove();var o=document.createElement("iframe");o.id=i,o.title="ThreeDSecure",o.style.display="block",o.style.border="0px",o.style.padding="0px",o.style.margin="0px",o.style.width="100%",o.style.height="100%",o.src=r(this.secureFields.frameUrl+"/threeds.html",{sessionId:this.secureFields.config.sessionId,parentOrigin:this.secureFields.parentOrigin,gr4vyId:this.secureFields.config.gr4vyId,environment:this.secureFields.config.environment}),this.element.appendChild(o),this.controller=o;var a={type:"three-ds-init",channel:c,data:{challengeWindowSize:this.challengeWindowSize}};return o.addEventListener("load",(()=>{var e;null===(e=o.contentWindow)||void 0===e||e.postMessage(a,this.secureFields.frameUrl)}),{once:!0}),this.secureFields.controller.addEventListener("load",(()=>{this.secureFields.controller.contentWindow.postMessage(a,this.secureFields.frameUrl)}),{once:!0}),m.remove("message",this.listener.bind(this),"three-ds"),m.add("message",this.listener.bind(this),"three-ds"),this}listener(e){return(t=function*(){if(e.origin===this.secureFields.frameUrl){var t=e.data,r=t.type,n=t.data;switch(r){case i.THREE_DS_START:p.publish(i.THREE_DS_START,k(N({},n),{element:this.element})),C("3DS start",e.data.data);break;case i.THREE_DS_FINISH:p.publish(i.THREE_DS_FINISH,k(N({},n),{element:this.element})),C("3DS finish",e.data.data)}}},function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(e){w(o,n,i,a,s,"next",e)}function s(e){w(o,n,i,a,s,"throw",e)}a(void 0)}))}).call(this);var t}constructor(e){S(this,"secureFields",void 0),S(this,"controller",void 0),S(this,"challengeWindowSize",void 0),S(this,"element",void 0),this.secureFields=e}}function D(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}class R extends Error{constructor(e){super(e),this.name="UnableToLoadDpaError"}}function j(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function U(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){j(o,n,i,a,s,"next",e)}function s(e){j(o,n,i,a,s,"throw",e)}a(void 0)}))}}function M(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function F(){return F=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},F.apply(this,arguments)}function Y(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){M(e,t,r[t])}))}return e}class x{_addIframe(e,t,n,i){var o=document.createElement("iframe");return o.id=e,o.title=t,o.setAttribute("width","100%"),o.setAttribute("frameborder","0"),o.setAttribute("style","height:0px"),o.src=r(n,i),o}_attachListeners(){var e=new MessageChannel,t=!0,r=r=>{var n=r.origin,a=r.data,l=a.type,d=a.data;switch(n){case this.origin:switch(l){case i.RESIZE:this.controller.style.height="".concat(d.height>0?d.height+48:0,"px");break;case i.METHOD_CHANGE:var u=d.method||"card";(this.secureFields.method!==u||t)&&(t=!1,this.secureFields.updateMethod(u,{data:d}),_(this.cardForm,"card"===u),p.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,"card"===u));break;case i.CLICK_TO_PAY_INITIALIZED:p.publish(i.CLICK_TO_PAY_INITIALIZED,this.clickToPay),C("Click to Pay initialized",this.clickToPay),_(this.signIn,!1),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),_(this.clickToPay.element,!0),p.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case i.CLICK_TO_PAY_READY:this._buyerExists=d.buyerExists,p.publish(i.CLICK_TO_PAY_READY,d),C("Click to Pay ready"),_(this.signIn,!d.buyerExists),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!d.buyerExists),_(this.clickToPay.element,!0),p.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case i.CLICK_TO_PAY_SIGN_OUT:this.clickToPay.signOut();break;case i.CLICK_TO_PAY_ERROR:p.publish(i.CLICK_TO_PAY_ERROR,d),C("Click to Pay error:",d),_(this.signIn,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(d.error)),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(d.error)),_(this.clickToPay.element,"UNKNOWN"!==d.error),p.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,"UNKNOWN"!==d.error);break;case i.CLICK_TO_PAY_CANCEL:p.publish(i.CLICK_TO_PAY_CANCEL,d),C("Click to Pay cancelled"),this._buyerExists||(_(this.signIn,!0),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!0));break;case i.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD:p.publish(i.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD,d),_(this.signIn,!1),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),C("Click to Pay checkout with new card initiated");break;case i.CLICK_TO_PAY_PROCESSING:_(this.cardForm,!d),p.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,d),C("Click to Pay processing",d);break;case i.CLICK_TO_PAY_AUTHENTICATE:!function(e,t){for(var r=arguments.length,n=new Array(r>2?r-2:0),i=2;i<r;i++)n[i-2]=arguments[i];document.cookie="".concat(e,"=").concat(t,"; path=/; ").concat(n.join("; "))}("recognitionToken",d.recognitionToken,"Secure","SameSite=Strict","MaxAge=15552000");break;case i.CLICK_TO_PAY_AUTHENTICATE_FAILURE:p.publish(i.CLICK_TO_PAY_AUTHENTICATE_FAILURE,d),C("Click to Pay authenticate failure:",d);break;case o.REQUEST_RECOGNITION_TOKEN:this.controller.contentWindow.postMessage({channel:c,type:o.RECOGNITION_TOKEN,data:{recognitionToken:b("recognitionToken")}},this.origin);break;case o.REQUEST_RECOGNITION_TOKEN_FAILED:E(s.NO_RECOGNITION_TOKEN);break;case o.REQUEST_PORT:this.controller.contentWindow.postMessage({channel:c,type:o.TRANSFER_PORT},this.origin,[e.port1])}break;case this.secureFields.frameUrl:l===o.REQUEST_PORT&&this.encrypt.contentWindow.postMessage({channel:c,type:o.TRANSFER_PORT},this.secureFields.frameUrl,[e.port2])}};m.remove("message",r,"click-to-pay"),m.add("message",r,"click-to-pay")}_fetchDPA(e,t){return U((function*(e,t){var r=t.gr4vyId,n=t.environment,o=t.sessionId;try{var a=e||function(e){return"https://api.".concat("sandbox"===(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"production")?"sandbox.":"").concat(e,".gr4vy.app")}(r,n);return yield function(e){return(t=function*(e){var t=e.apiBaseUrl,r=e.checkoutSessionId;try{var n="".concat(t,"/digital-wallets/click-to-pay/session"),i=yield fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({checkout_session_id:r})});if(i.ok){var o=yield i.json();return{srcDpaId:o.digital_payment_application_id,dpaName:o.digital_payment_application_name}}throw new R("Unable to load DPA")}catch(e){throw new R("Unable to load DPA")}},function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(e){D(o,n,i,a,s,"next",e)}function s(e){D(o,n,i,a,s,"throw",e)}a(void 0)}))}).apply(this,arguments);var t}({apiBaseUrl:a,checkoutSessionId:o})}catch(e){return C(e.message),p.publish(i.CLICK_TO_PAY_UNABLE_TO_LOAD_DPA),_(this.cardForm,!0),p.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,!0),_(this.clickToPay.element,!1),void p.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,!1)}})).apply(this,arguments)}_initConsentCheckbox(e){var t=e.checked?"click-to-pay":"card";this.secureFields.updateMethod(t,{data:{method:t}}),e.addEventListener("change",(e=>{var t=e.target;this.consent=t.checked})),m.add("message",(t=>{switch(t.data.type){case i.CLICK_TO_PAY_ERROR:"UNKNOWN"===t.data.data.error&&(this.consent=!1,e.checked=!1);break;case i.METHOD_CHANGE:var r=this._buyerExists&&"card"===t.data.data.method;this.consent=r,e.checked=r}}),"click-to-pay-consent-checkbox")}_setNewCardRememberMe(e){this.controller.contentWindow.postMessage({type:"remember-me-new-card-changed",channel:c,data:{value:e}},this.origin)}_initNewCardRememberMeCheckbox(e){e.addEventListener("change",(e=>{var t=e.target;this._setNewCardRememberMe(t.checked)})),m.add("message",(t=>{switch(t.data.type){case i.CLICK_TO_PAY_INITIALIZED:this._setNewCardRememberMe(e.checked);break;case i.CLICK_TO_PAY_ERROR:"UNKNOWN"===t.data.data.error&&(this._setNewCardRememberMe(!1),e.checked=!1)}}),"click-to-pay-new-card-remember-me-checkbox")}_initLearnMore(e){e.style.visibility="hidden",m.add("message",(t=>{t.data.type===i.CLICK_TO_PAY_INITIALIZED&&(e.style.visibility="visible",e.addEventListener("click",(()=>{this.controller.contentWindow.postMessage({type:"show-learn-more",channel:c},this.origin)})))}),"click-to-pay-learn-more")}init(e,t){return U((function*(){this.cardForm="string"==typeof(null==t?void 0:t.cardForm)?document.querySelector(null==t?void 0:t.cardForm):null==t?void 0:t.cardForm,this.signIn="string"==typeof(null==t?void 0:t.signIn)?document.querySelector(null==t?void 0:t.signIn):null==t?void 0:t.signIn,_(this.signIn,!1);var r=this.secureFields,n=r.apiUrl,o=r.config,a=o.gr4vyId,s=o.environment,c=o.sessionId,l=r.environmentPath;if(this.clickToPay={element:null,options:t,signIn:e=>{var t=e.email,r=e.mobileNumber;return U((function*(){var e=this.clickToPay,n=e.element,o=e.options;delete o.email,delete o.mobileNumber,n.innerHTML="",_(this.signIn,!1),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),_(this.cardForm,!1),p.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,!1),this.secureFields.update("clickToPay",yield this.init(n,Y({},o,t?{email:t}:{},r?{mobileNumber:r}:{})))})).call(this)},signOut:()=>(this._buyerExists=!1,p.publish(i.CLICK_TO_PAY_SIGN_OUT),C("Click to pay signed out"),_(this.signIn,!0),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!0),document.cookie="".concat("recognitionToken","=; path=/; expires=Thu, 01 Jan 1970 00:00:00 UTC;"),this.clickToPay.signIn({email:null,mobileNumber:null}))},!(null==t?void 0:t.srcDpaId)||!(null==t?void 0:t.dpaName)){var d=yield this._fetchDPA(n,{gr4vyId:a,environment:s,sessionId:c});if(!(null==d?void 0:d.srcDpaId)&&!(null==d?void 0:d.dpaName))return;t.srcDpaId=d.srcDpaId,t.dpaName=d.dpaName}this.url=window.CLICK_TO_PAY_FRAME_URL||"https://click-to-pay.".concat(l).concat(a,".gr4vy.app"),this.origin=new URL(this.url).origin;var u=window.location.origin,h=(function(e){if(null==e)throw new TypeError("Cannot destructure "+e)}(t),Y({gr4vyId:a,environment:s,sessionId:c},F({},t)));if(this.controller=this._addIframe("click-to-pay-controller","Click To Pay","".concat(this.url,"/click-to-pay.html"),{parentOrigin:u,environment:s,config:encodeURIComponent(JSON.stringify(h))}),this.encrypt=this._addIframe("click-to-pay-encrypt","Click To Pay Encrypt","".concat(this.secureFields.frameUrl,"/click-to-pay-encrypt.html"),{parentOrigin:u,environment:s,config:encodeURIComponent(JSON.stringify(h))}),this._attachListeners(),null==t?void 0:t.consentCheckbox){var y="string"==typeof(null==t?void 0:t.consentCheckbox)?document.querySelector(null==t?void 0:t.consentCheckbox):null==t?void 0:t.consentCheckbox;y&&this._initConsentCheckbox(y)}if(null==t?void 0:t.rememberMeCheckbox){var f="string"==typeof(null==t?void 0:t.rememberMeCheckbox)?document.querySelector(t.rememberMeCheckbox):null==t?void 0:t.rememberMeCheckbox;f&&this._initNewCardRememberMeCheckbox(f)}if(null==t?void 0:t.learnMoreLink){var m="string"==typeof(null==t?void 0:t.learnMoreLink)?document.querySelector(null==t?void 0:t.learnMoreLink):null==t?void 0:t.learnMoreLink;m&&this._initLearnMore(m)}return(e="string"==typeof e?document.querySelector(e):e).appendChild(this.controller),e.appendChild(this.encrypt),this.clickToPay.element=e,this.clickToPay})).call(this)}constructor(e){M(this,"secureFields",void 0),M(this,"_buyerExists",void 0),M(this,"consent",void 0),M(this,"controller",void 0),M(this,"encrypt",void 0),M(this,"origin",void 0),M(this,"url",void 0),M(this,"cardForm",void 0),M(this,"signIn",void 0),M(this,"clickToPay",void 0),this.secureFields=e,this._buyerExists=!1,this.consent=!1}}function K(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function H(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function G(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){H(e,t,r[t])}))}return e}function V(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}class W{_postMessage(e){return(t=function*(){yield this.ready,this.frame.contentWindow.postMessage(G({channel:c},e),this.frameUrl)},function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(e){K(o,n,i,a,s,"next",e)}function s(e){K(o,n,i,a,s,"throw",e)}a(void 0)}))}).call(this);var t}update(e){if(this.frameUrl){this.options=G({},this.options,e);var t=P(G({},this.options.styles,e.styles)),r=V(G({},this.options,e),{styles:t});this._postMessage({type:"update",data:V(G({},r),{styles:t})}),C("Updated field",this.options)}}setPlaceholder(e){this.update({placeholder:e})}setStyles(e){this.update({styles:e})}clear(){if(this.frameUrl){var e=this.type;this._postMessage({type:"reset",data:{type:e}}),C("Cleared field",{type:e})}}redactValue(){if(this.frameUrl){var e=this.type;this._postMessage({type:"redact-value",data:{type:e}}),C("Redact field",{type:e})}}unredactValue(){if(this.frameUrl){var e=this.type;this._postMessage({type:"unredact-value",data:{type:e}}),C("Unredact field",{type:e})}}constructor(e){if(H(this,"frameUrl",void 0),H(this,"parentOrigin",void 0),H(this,"frame",void 0),H(this,"type",void 0),H(this,"options",void 0),H(this,"addEventListener",void 0),H(this,"removeEventListener",void 0),H(this,"ready",void 0),H(this,"_resolveReady",void 0),e){this.ready=new Promise((e=>{this._resolveReady=e}));var t=e.frameUrl,r=e.parentOrigin,n=e.font,i=e.options,o=i.type,a=function(e,t){if(null==e)return{};var r,n,i,o={};if("undefined"!=typeof Reflect&&Reflect.ownKeys){for(r=Reflect.ownKeys(Object(e)),i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n]);return o}if(o=function(e,t){if(null==e)return{};var r,n,i={},o=Object.getOwnPropertyNames(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r]);return i}(e,t),Object.getOwnPropertySymbols)for(r=Object.getOwnPropertySymbols(e),i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n]);return o}(i,["type"]),s=e.paymentMethodScheme;this.frameUrl=t,this.parentOrigin=r,this.type=o,this.options=a;var c=P(a.styles);this.frame=document.createElement("iframe"),this.frame.id=o,this.frame.src="".concat(t,"/input.html?parentOrigin=").concat(r,"&type=").concat(this.type),this.frame.title="Secure Input",this.frame.style.display="block",this.frame.style.height="100%",this.frame.style.border="none",this.frame.style.width="100%",n&&(this.frame.src+="&font=".concat(n)),s&&(this.frame.src+="&paymentMethodScheme=".concat(s)),this.frame.onload=()=>{this._postMessage({type:"update",data:V(G({},this.options),{styles:c,type:o})}),C("Added field",this.options)}}}}function B(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function q(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function z(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){q(e,t,r[t])}))}return e}function Z(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}class Q{static get Events(){return i}static get version(){return"#428e1b2460c3306e09875c5614de27a7a0c3dc72"}update(e,t){this[e]=t}updateMethod(e,t){var r=t.data;this.update("method",e),p.publish(i.METHOD_CHANGE,r),C("Method changed",{method:e}),this.controller.contentWindow.postMessage({type:"method-change",channel:c},this.frameUrl)}_addField(e,t){if(!(e="string"==typeof e?document.querySelector(e):e)||!t.frame)return t.addEventListener=()=>{},t.removeEventListener=()=>{},t;var r=e.closest("[data-secure-fields-input-group]"),n=null!=r?r:document.createElement("div"),i=e=>{var r;if(e.origin===this.frameUrl&&(null===(r=e.data.data)||void 0===r?void 0:r.id)===t.type)switch(e.data.type){case"blur":p.publish("".concat(t.type,":blur"),e.data.data),n.removeAttribute(a.FOCUSED),C("Field blurred",e.data.data);break;case"focus":p.publish("".concat(t.type,":focus"),e.data.data),n.setAttribute(a.FOCUSED,""),C("Field focused",e.data.data);break;case"input":p.publish("".concat(t.type,":input"),e.data.data),e.data.data.valid?n.removeAttribute(a.INVALID):n.setAttribute(a.INVALID,""),e.data.data.autofilled?n.setAttribute(a.AUTOFILLED,""):n.removeAttribute(a.AUTOFILLED),C("Field input changed",e.data.data);break;case"redacted":p.publish("".concat(t.type,":redacted"),e.data.data),C("Field redacted",e.data.data);break;case"unredacted":p.publish("".concat(t.type,":unredacted"),e.data.data),C("Field unredacted",e.data.data)}};return m.remove("message",i,t.type),m.add("message",i,t.type),t.addEventListener=this.addEventListener,t.removeEventListener=this.removeEventListener,this.controllerReady.then((()=>{var i,o,a,s;i=e,o=n,Array.from(i.attributes).forEach((e=>{var t=e.name,r=e.value;v.some((e=>new RegExp(e).test(t)))&&o.setAttribute(t,r)})),(n=o).classList.add("secure-fields__input","secure-fields__input--".concat(T(t.type))),r?(null===(a=e.parentNode)||void 0===a||a.replaceChild(t.frame,e),r.style.display="inline-flex",r.style.alignItems="center",t.frame.style.minWidth="0"):(null===(s=e.parentNode)||void 0===s||s.replaceChild(n,e),n.appendChild(t.frame)),t._resolveReady()})),t}addCardNumberField(e,t){return this.paymentMethodId&&E(s.PAYMENT_METHOD_ID_IN_USE,{method:"addCardNumberField"}),this.cardNumber||(this.cardNumber=new W({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:Z(z({label:"Card number"},t),{type:"number"})})),this._addField(e,this.cardNumber)}addSecurityCodeField(e,t){var r,n;return this.securityCode||(this.securityCode=new W({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:Z(z({label:"Security code"},this.paymentMethodId&&!(null===(r=this.config.paymentMethod)||void 0===r?void 0:r.scheme)?{lengths:[3,4]}:{},t),{type:"securityCode"}),paymentMethodScheme:null===(n=this.config.paymentMethod)||void 0===n?void 0:n.scheme})),this._addField(e,this.securityCode)}addExpiryDateField(e,t){return this.paymentMethodId&&E(s.PAYMENT_METHOD_ID_IN_USE,{method:"addExpiryDateField"}),this.expiryDate||(this.expiryDate=new W({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:Z(z({label:"Expiry date"},t),{type:"expiryDate"})})),this._addField(e,this.expiryDate)}addField(e,t){if(["number","expiryDate","securityCode"].includes(t.type)){t.pattern&&E(s.FIELD_PATTERN_IN_USE,z({method:"addField"},t)),t.pattern,t.type;var r=function(e,t){if(null==e)return{};var r,n,i,o={};if("undefined"!=typeof Reflect&&Reflect.ownKeys){for(r=Reflect.ownKeys(Object(e)),i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n]);return o}if(o=function(e,t){if(null==e)return{};var r,n,i={},o=Object.getOwnPropertyNames(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r]);return i}(e,t),Object.getOwnPropertySymbols)for(r=Object.getOwnPropertySymbols(e),i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n]);return o}(t,["pattern","type"]);return this[l[t.type]](e,r)}return this.otherFields[t.type]||(this.otherFields=Z(z({},this.otherFields),{[t.type]:new W({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:t})})),this._addField(e,this.otherFields[t.type])}addThreeDSecure(e,t){this.threeDS||(this.threeDS=new L(this),this.threeDS.init(e,t))}addClickToPay(e,t){return(r=function*(){if(!this.paymentMethodId)return this.clickToPayInstance=yield new x(this),this.clickToPay=yield this.clickToPayInstance.init(e,t),this.clickToPay;E(s.PAYMENT_METHOD_ID_IN_USE,{method:"addClickToPay"})},function(){var e=this,t=arguments;return new Promise((function(n,i){var o=r.apply(e,t);function a(e){B(o,n,i,a,s,"next",e)}function s(e){B(o,n,i,a,s,"throw",e)}a(void 0)}))}).call(this);var r}addEventListener(e,t){var r=this.type,n="".concat(this.constructor===W?"".concat(r,":"):"").concat(e);p.subscribe(n,t)}removeEventListener(e,t){var r=this.type,n="".concat(this.constructor===W?"".concat(r,":"):"").concat(e);p.unsubscribe(n,t)}submit(){var e,t,r=e=>{var t,n=[this.frameUrl,null===(t=this.clickToPayInstance)||void 0===t?void 0:t.origin].includes(e.origin),o=e.data.channel===c,a=["success","error"].includes(e.data.type);if(n&&o&&a){switch(e.data.type){case"success":var s;p.publish(i.CARD_VAULT_SUCCESS,e.data.data),(null===(s=e.data.data)||void 0===s?void 0:s.warn)&&(E(e.data.data.warn),delete e.data.data.warn),C("Payment method tokenized successfully",e.data.data);break;case"error":p.publish(i.CARD_VAULT_FAILURE,e.data),C("Failed to update checkout session",e.data.data)}window.removeEventListener("message",r)}};window.addEventListener("message",r),"click-to-pay"===this.method||"card"===this.method&&(null===(e=this.clickToPayInstance)||void 0===e?void 0:e.controller)&&!0===(null===(t=this.clickToPayInstance)||void 0===t?void 0:t.consent)?this.clickToPayInstance.controller.contentWindow.postMessage({type:"submit",channel:c},this.clickToPayInstance.url):this.controller.contentWindow.postMessage({type:"submit",channel:c,data:{method:this.paymentMethodId?"id":"card"}},this.frameUrl)}setDebug(e){localStorage.setItem(n,String(e))}addFont(e){this.font=e.replace(/\s/g,"+")}constructor(e){var t,n;q(this,"config",void 0),q(this,"controller",void 0),q(this,"frameUrl",void 0),q(this,"apiUrl",void 0),q(this,"parentOrigin",void 0),q(this,"font",void 0),q(this,"cardNumber",void 0),q(this,"securityCode",void 0),q(this,"expiryDate",void 0),q(this,"otherFields",{}),q(this,"method","card"),q(this,"clickToPayInstance",void 0),q(this,"clickToPay",void 0),q(this,"threeDS",void 0),q(this,"environmentPath",void 0),q(this,"paymentMethodId",void 0),q(this,"controllerReady",void 0),q(this,"_resolveControllerReady",void 0),p.unsubscribeAll(),this.config=z({environment:"production"},e),this.controllerReady=new Promise((e=>{var t=Date.now();this._resolveControllerReady=()=>e(Date.now()-t)})),this.config.paymentMethodId&&!this.config.paymentMethod&&E(s.PAYMENT_METHOD_ID_DEPRECATED),this.environmentPath="sandbox"===this.config.environment?"sandbox.":"",this.frameUrl=window.SECURE_FIELDS_FRAME_URL||"https://secure-fields.".concat(this.environmentPath).concat(this.config.gr4vyId,".gr4vy.app"),this.parentOrigin=window.location.origin,this.paymentMethodId=(null===(t=this.config.paymentMethod)||void 0===t?void 0:t.id)||this.config.paymentMethodId;var o=z({parentOrigin:this.parentOrigin,sessionId:this.config.sessionId,gr4vyId:this.config.gr4vyId,environment:this.config.environment},this.paymentMethodId?{paymentMethodId:this.paymentMethodId}:{});null===(n=document.body.querySelector("iframe#controller[src*=secure-fields]"))||void 0===n||n.remove(),this.controller=document.createElement("iframe"),this.controller.id="controller",this.controller.src=r("".concat(this.frameUrl,"/controller.html"),o),this.controller.title="Secure Controller",this.controller.style.position="absolute",this.controller.style.left="-9999999px",document.body.appendChild(this.controller),this.paymentMethodId&&(this.cardNumber=new W,this.expiryDate=new W),C("Initialized",Z(z({},this.config),{version:Q.version,frameUrl:this.frameUrl,parentOrigin:this.parentOrigin}));var a=e=>{if(e.origin===this.frameUrl)switch(e.data.type){case"ready":var t=z({version:Q.version},this.config);p.publish(i.READY,t),this._resolveControllerReady(),C("Ready",t);break;case"form-change":p.publish(i.FORM_CHANGE,e.data.data),C("Form change",e.data.data)}};m.remove("message",a,"init"),m.add("message",a,"init"),this.controllerReady.then((e=>C("Loaded controller after ".concat(e," milliseconds"))))}}return t})()));
1
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(this,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Events:()=>i,SecureFields:()=>$,SecureInput:()=>B});var r=(e,t)=>"".concat(e,"?").concat(new URLSearchParams(t).toString()),n="@gr4vy-secure-fields-debug",i=function(e){return e.CARD_VAULT_SUCCESS="card-vault-success",e.CARD_VAULT_FAILURE="card-vault-failure",e.FORM_CHANGE="form-change",e.METHOD_CHANGE="method-change",e.READY="ready",e.RESIZE="resize",e.CLICK_TO_PAY_INITIALIZED="click-to-pay-initialized",e.CLICK_TO_PAY_READY="click-to-pay-ready",e.CLICK_TO_PAY_SIGN_OUT="click-to-pay-sign-out",e.CLICK_TO_PAY_ERROR="click-to-pay-error",e.CLICK_TO_PAY_CANCEL="click-to-pay-cancel",e.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD="click-to-pay-checkout-with-new-card",e.CLICK_TO_PAY_UNABLE_TO_LOAD_DPA="click-to-pay-unable-to-load-dpa",e.CLICK_TO_PAY_VISIBILITY_CHANGE="click-to-pay:visibility-change",e.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE="click-to-pay-card-form:visibility-change",e.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE="click-to-pay-sign-in:visibility-change",e.CLICK_TO_PAY_PROCESSING="click-to-pay-processing",e.CLICK_TO_PAY_AUTHENTICATE="click-to-pay-authenticate",e.CLICK_TO_PAY_AUTHENTICATE_FAILURE="click-to-pay-authenticate-failure",e.THREE_DS_START="three-ds-start",e.THREE_DS_FINISH="three-ds-finish",e}({}),o=function(e){return e.REQUEST_PORT="request-port",e.TRANSFER_PORT="transfer-port",e.REQUEST_RECOGNITION_TOKEN="request-recognition-token",e.REQUEST_RECOGNITION_TOKEN_FAILED="request-recognition-token-failed",e.RECOGNITION_TOKEN="recognition-token",e}({}),a=function(e){return e.FOCUSED="data-secure-fields-focused",e.INVALID="data-secure-fields-invalid",e.AUTOFILLED="data-secure-fields-autofilled",e}({}),s=function(e){return e.PAYMENT_METHOD_ID_IN_USE="You're passing a paymentMethodId to use a stored payment method, which means Secure Fields methods `addCardNumber`, `addExpiryDate` and `addClickToPay` are automatically disabled and won't render the related fields",e.PAYMENT_METHOD_ID_DEPRECATED="The 'paymentMethodId' prop is deprecated and will be removed in a future version. Please use the 'paymentMethod' prop instead: { paymentMethod: { id: 'your-id', scheme: 'visa' } }",e.FIELD_PATTERN_IN_USE="The `pattern` option can't be used on card fields, so it won't be applied here.",e.AUTO_ADVANCE_ENABLED="autoAdvance is enabled. Auto-advancing focus on field completion can degrade checkout UX (see WCAG 3.2.2). Use with caution.",e.NO_RECOGNITION_TOKEN="The recognition token couldn't be obtained or the request took too much time. It is possible that a Click to Pay user was therefore not recognised.",e}({}),c="secure-fields",l={number:"addCardNumberField",expiryDate:"addExpiryDateField",securityCode:"addSecurityCodeField"},d=["01","02","03","04","05"];function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o=[],a=!0,s=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==r.return||r.return()}finally{if(s)throw i}}return o}}(e,t)||function(e,t){if(e){if("string"==typeof e)return u(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?u(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var p=new class{subscribe(e,t){this.subscribers.push([e,t])}unsubscribe(e,t){this.subscribers=this.subscribers.filter((r=>{var n=h(r,2),i=n[0],o=n[1];return i!==e||o.toString()!==t.toString()}))}unsubscribeAll(){this.subscribers=[]}publish(e,t){this.subscribers.forEach((r=>{var n=h(r,2),i=n[0],o=n[1];return setTimeout((()=>i===e?o(t):null),0)}))}constructor(){var e,t;t=void 0,(e="subscribers")in this?Object.defineProperty(this,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):this[e]=t,this.subscribers=[]}};function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function f(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o=[],a=!0,s=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==r.return||r.return()}finally{if(s)throw i}}return o}}(e,t)||function(e,t){if(e){if("string"==typeof e)return y(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?y(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var m=new class{add(e,t,r){window.addEventListener(e,t),this.listeners.push([e,t,r])}remove(e,t,r){var n=this.listeners.findIndex((n=>{var i=f(n,3),o=i[0],a=i[1],s=i[2];return o===e&&a.toString()===t.toString()&&s===r}));if(-1!==n){var i=f(this.listeners.splice(n,1),1),o=f(i[0],2),a=o[0],s=o[1];window.removeEventListener(a,s)}}removeAll(){this.listeners.forEach((e=>{var t=f(e,2),r=t[0],n=t[1];window.removeEventListener(r,n)})),this.listeners=[]}constructor(){var e,t;t=[],(e="listeners")in this?Object.defineProperty(this,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):this[e]=t}},v=["number","expiryDate","securityCode","postalCode"],b=e=>{var t,r;if(null===(t=document)||void 0===t?void 0:t.cookie)return null===(r="; ".concat(document.cookie).match(";\\s*".concat(e,"=([^;]+)")))||void 0===r?void 0:r[1]},_=["accesskey","autocapitalize","autocomplete","autofocus","aria-.","class","contenteditable","data-.","dir","draggable","enterkeyhint","hidden","id","inert","inputmode","is","itemid","itemprop","itemref","itemscope","itemtype","lang","nonce","onabort","onautocomplete","onautocompleteerror","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncontextmenu","oncuechange","ondblclick","ondrag","ondragend","ondragenter","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onmousewheel","onpause","onplay","onplaying","onprogress","onratechange","onreset","onresize","onscroll","onseeked","onseeking","onselect","onshow","onsort","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle","onvolumechange","onwaiting","popover","role","slot","spellcheck","style","tabindex","title","translate"],I=(e,t)=>e&&(e.style.display=t?"block":"none");function g(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function O(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){g(e,t,r[t])}))}return e}var C={debug:!1,level:"log"},E=(e,t,r)=>{var i=O({},C,r),o=i.debug,a=i.level;(o||"true"===localStorage.getItem(n))&&console[a]("Gr4vy - Secure Fields - ".concat(e),t||{})},T=(e,t,r)=>{var n,i;E(e,t,(n=O({},r),i=null!=(i={level:"warn"})?i:{},Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(i)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(i)).forEach((function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(i,e))})),n))},A=e=>(e!=e.toLowerCase()&&(e=e.replace(/[A-Z]/g,(e=>"-"+e.toLowerCase()))),e);function P(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var w=function(){var e=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return Object.entries(t).reduce(((n,i)=>{var o,a,s=(a=2,function(e){if(Array.isArray(e))return e}(o=i)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o=[],a=!0,s=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==r.return||r.return()}finally{if(s)throw i}}return o}}(o,a)||function(e,t){if(e){if("string"==typeof e)return P(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?P(e,t):void 0}}(o,a)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),c=s[0],l=s[1];return(e=>"[object Object]"===Object.prototype.toString.call(e))(l)?n.push(...e(t[c],"".concat((r+c).match(/[a-zA-Z0-9]+/g).join("-"),"-"))):(c=A(c).replace(/^-/,""),n.push(["--".concat(r).concat(c),l])),n}),[])};return e(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})};function S(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function N(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function k(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){N(e,t,r[t])}))}return e}function L(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}class D{init(e,t){var n;this.challengeWindowSize=d.includes(null==t?void 0:t.challengeWindowSize)?t.challengeWindowSize:"05",this.element="string"==typeof e?document.querySelector(e):e;var i="gr4vy-threeds-flow-controller";null===(n=document.body.querySelector("iframe#".concat(i)))||void 0===n||n.remove();var o=document.createElement("iframe");o.id=i,o.title="ThreeDSecure",o.style.display="block",o.style.border="0px",o.style.padding="0px",o.style.margin="0px",o.style.width="100%",o.style.height="100%",o.src=r(this.secureFields.frameUrl+"/threeds.html",{sessionId:this.secureFields.config.sessionId,parentOrigin:this.secureFields.parentOrigin,gr4vyId:this.secureFields.config.gr4vyId,environment:this.secureFields.config.environment}),this.element.appendChild(o),this.controller=o;var a={type:"three-ds-init",channel:c,data:{challengeWindowSize:this.challengeWindowSize}};return o.addEventListener("load",(()=>{var e;null===(e=o.contentWindow)||void 0===e||e.postMessage(a,this.secureFields.frameUrl)}),{once:!0}),this.secureFields.controller.addEventListener("load",(()=>{this.secureFields.controller.contentWindow.postMessage(a,this.secureFields.frameUrl)}),{once:!0}),m.remove("message",this.listener.bind(this),"three-ds"),m.add("message",this.listener.bind(this),"three-ds"),this}listener(e){return(t=function*(){if(e.origin===this.secureFields.frameUrl){var t=e.data,r=t.type,n=t.data;switch(r){case i.THREE_DS_START:p.publish(i.THREE_DS_START,L(k({},n),{element:this.element})),E("3DS start",e.data.data);break;case i.THREE_DS_FINISH:p.publish(i.THREE_DS_FINISH,L(k({},n),{element:this.element})),E("3DS finish",e.data.data)}}},function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(e){S(o,n,i,a,s,"next",e)}function s(e){S(o,n,i,a,s,"throw",e)}a(void 0)}))}).call(this);var t}constructor(e){N(this,"secureFields",void 0),N(this,"controller",void 0),N(this,"challengeWindowSize",void 0),N(this,"element",void 0),this.secureFields=e}}function R(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}class U extends Error{constructor(e){super(e),this.name="UnableToLoadDpaError"}}function j(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function F(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){j(o,n,i,a,s,"next",e)}function s(e){j(o,n,i,a,s,"throw",e)}a(void 0)}))}}function M(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function x(){return x=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},x.apply(this,arguments)}function Y(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){M(e,t,r[t])}))}return e}class K{_addIframe(e,t,n,i){var o=document.createElement("iframe");return o.id=e,o.title=t,o.setAttribute("width","100%"),o.setAttribute("frameborder","0"),o.setAttribute("style","height:0px"),o.src=r(n,i),o}_attachListeners(){var e=new MessageChannel,t=!0,r=r=>{var n=r.origin,a=r.data,l=a.type,d=a.data;switch(n){case this.origin:switch(l){case i.RESIZE:this.controller.style.height="".concat(d.height>0?d.height+48:0,"px");break;case i.METHOD_CHANGE:var u=d.method||"card";(this.secureFields.method!==u||t)&&(t=!1,this.secureFields.updateMethod(u,{data:d}),I(this.cardForm,"card"===u),p.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,"card"===u));break;case i.CLICK_TO_PAY_INITIALIZED:p.publish(i.CLICK_TO_PAY_INITIALIZED,this.clickToPay),E("Click to Pay initialized",this.clickToPay),I(this.signIn,!1),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),I(this.clickToPay.element,!0),p.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case i.CLICK_TO_PAY_READY:this._buyerExists=d.buyerExists,p.publish(i.CLICK_TO_PAY_READY,d),E("Click to Pay ready"),I(this.signIn,!d.buyerExists),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!d.buyerExists),I(this.clickToPay.element,!0),p.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case i.CLICK_TO_PAY_SIGN_OUT:this.clickToPay.signOut();break;case i.CLICK_TO_PAY_ERROR:p.publish(i.CLICK_TO_PAY_ERROR,d),E("Click to Pay error:",d),I(this.signIn,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(d.error)),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(d.error)),I(this.clickToPay.element,"UNKNOWN"!==d.error),p.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,"UNKNOWN"!==d.error);break;case i.CLICK_TO_PAY_CANCEL:p.publish(i.CLICK_TO_PAY_CANCEL,d),E("Click to Pay cancelled"),this._buyerExists||(I(this.signIn,!0),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!0));break;case i.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD:p.publish(i.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD,d),I(this.signIn,!1),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),E("Click to Pay checkout with new card initiated");break;case i.CLICK_TO_PAY_PROCESSING:I(this.cardForm,!d),p.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,d),E("Click to Pay processing",d);break;case i.CLICK_TO_PAY_AUTHENTICATE:!function(e,t){for(var r=arguments.length,n=new Array(r>2?r-2:0),i=2;i<r;i++)n[i-2]=arguments[i];document.cookie="".concat(e,"=").concat(t,"; path=/; ").concat(n.join("; "))}("recognitionToken",d.recognitionToken,"Secure","SameSite=Strict","MaxAge=15552000");break;case i.CLICK_TO_PAY_AUTHENTICATE_FAILURE:p.publish(i.CLICK_TO_PAY_AUTHENTICATE_FAILURE,d),E("Click to Pay authenticate failure:",d);break;case o.REQUEST_RECOGNITION_TOKEN:this.controller.contentWindow.postMessage({channel:c,type:o.RECOGNITION_TOKEN,data:{recognitionToken:b("recognitionToken")}},this.origin);break;case o.REQUEST_RECOGNITION_TOKEN_FAILED:T(s.NO_RECOGNITION_TOKEN);break;case o.REQUEST_PORT:this.controller.contentWindow.postMessage({channel:c,type:o.TRANSFER_PORT},this.origin,[e.port1])}break;case this.secureFields.frameUrl:l===o.REQUEST_PORT&&this.encrypt.contentWindow.postMessage({channel:c,type:o.TRANSFER_PORT},this.secureFields.frameUrl,[e.port2])}};m.remove("message",r,"click-to-pay"),m.add("message",r,"click-to-pay")}_fetchDPA(e,t){return F((function*(e,t){var r=t.gr4vyId,n=t.environment,o=t.sessionId;try{var a=e||function(e){return"https://api.".concat("sandbox"===(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"production")?"sandbox.":"").concat(e,".gr4vy.app")}(r,n);return yield function(e){return(t=function*(e){var t=e.apiBaseUrl,r=e.checkoutSessionId;try{var n="".concat(t,"/digital-wallets/click-to-pay/session"),i=yield fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({checkout_session_id:r})});if(i.ok){var o=yield i.json();return{srcDpaId:o.digital_payment_application_id,dpaName:o.digital_payment_application_name}}throw new U("Unable to load DPA")}catch(e){throw new U("Unable to load DPA")}},function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(e){R(o,n,i,a,s,"next",e)}function s(e){R(o,n,i,a,s,"throw",e)}a(void 0)}))}).apply(this,arguments);var t}({apiBaseUrl:a,checkoutSessionId:o})}catch(e){return E(e.message),p.publish(i.CLICK_TO_PAY_UNABLE_TO_LOAD_DPA),I(this.cardForm,!0),p.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,!0),I(this.clickToPay.element,!1),void p.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,!1)}})).apply(this,arguments)}_initConsentCheckbox(e){var t=e.checked?"click-to-pay":"card";this.secureFields.updateMethod(t,{data:{method:t}}),e.addEventListener("change",(e=>{var t=e.target;this.consent=t.checked})),m.add("message",(t=>{switch(t.data.type){case i.CLICK_TO_PAY_ERROR:"UNKNOWN"===t.data.data.error&&(this.consent=!1,e.checked=!1);break;case i.METHOD_CHANGE:var r=this._buyerExists&&"card"===t.data.data.method;this.consent=r,e.checked=r}}),"click-to-pay-consent-checkbox")}_setNewCardRememberMe(e){this.controller.contentWindow.postMessage({type:"remember-me-new-card-changed",channel:c,data:{value:e}},this.origin)}_initNewCardRememberMeCheckbox(e){e.addEventListener("change",(e=>{var t=e.target;this._setNewCardRememberMe(t.checked)})),m.add("message",(t=>{switch(t.data.type){case i.CLICK_TO_PAY_INITIALIZED:this._setNewCardRememberMe(e.checked);break;case i.CLICK_TO_PAY_ERROR:"UNKNOWN"===t.data.data.error&&(this._setNewCardRememberMe(!1),e.checked=!1)}}),"click-to-pay-new-card-remember-me-checkbox")}_initLearnMore(e){e.style.visibility="hidden",m.add("message",(t=>{t.data.type===i.CLICK_TO_PAY_INITIALIZED&&(e.style.visibility="visible",e.addEventListener("click",(()=>{this.controller.contentWindow.postMessage({type:"show-learn-more",channel:c},this.origin)})))}),"click-to-pay-learn-more")}init(e,t){return F((function*(){this.cardForm="string"==typeof(null==t?void 0:t.cardForm)?document.querySelector(null==t?void 0:t.cardForm):null==t?void 0:t.cardForm,this.signIn="string"==typeof(null==t?void 0:t.signIn)?document.querySelector(null==t?void 0:t.signIn):null==t?void 0:t.signIn,I(this.signIn,!1);var r=this.secureFields,n=r.apiUrl,o=r.config,a=o.gr4vyId,s=o.environment,c=o.sessionId,l=r.environmentPath;if(this.clickToPay={element:null,options:t,signIn:e=>{var t=e.email,r=e.mobileNumber;return F((function*(){var e=this.clickToPay,n=e.element,o=e.options;delete o.email,delete o.mobileNumber,n.innerHTML="",I(this.signIn,!1),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),I(this.cardForm,!1),p.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,!1),this.secureFields.update("clickToPay",yield this.init(n,Y({},o,t?{email:t}:{},r?{mobileNumber:r}:{})))})).call(this)},signOut:()=>(this._buyerExists=!1,p.publish(i.CLICK_TO_PAY_SIGN_OUT),E("Click to pay signed out"),I(this.signIn,!0),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!0),document.cookie="".concat("recognitionToken","=; path=/; expires=Thu, 01 Jan 1970 00:00:00 UTC;"),this.clickToPay.signIn({email:null,mobileNumber:null}))},!(null==t?void 0:t.srcDpaId)||!(null==t?void 0:t.dpaName)){var d=yield this._fetchDPA(n,{gr4vyId:a,environment:s,sessionId:c});if(!(null==d?void 0:d.srcDpaId)&&!(null==d?void 0:d.dpaName))return;t.srcDpaId=d.srcDpaId,t.dpaName=d.dpaName}this.url=window.CLICK_TO_PAY_FRAME_URL||"https://click-to-pay.".concat(l).concat(a,".gr4vy.app"),this.origin=new URL(this.url).origin;var u=window.location.origin,h=(function(e){if(null==e)throw new TypeError("Cannot destructure "+e)}(t),Y({gr4vyId:a,environment:s,sessionId:c},x({},t)));if(this.controller=this._addIframe("click-to-pay-controller","Click To Pay","".concat(this.url,"/click-to-pay.html"),{parentOrigin:u,environment:s,config:encodeURIComponent(JSON.stringify(h))}),this.encrypt=this._addIframe("click-to-pay-encrypt","Click To Pay Encrypt","".concat(this.secureFields.frameUrl,"/click-to-pay-encrypt.html"),{parentOrigin:u,environment:s,config:encodeURIComponent(JSON.stringify(h))}),this._attachListeners(),null==t?void 0:t.consentCheckbox){var y="string"==typeof(null==t?void 0:t.consentCheckbox)?document.querySelector(null==t?void 0:t.consentCheckbox):null==t?void 0:t.consentCheckbox;y&&this._initConsentCheckbox(y)}if(null==t?void 0:t.rememberMeCheckbox){var f="string"==typeof(null==t?void 0:t.rememberMeCheckbox)?document.querySelector(t.rememberMeCheckbox):null==t?void 0:t.rememberMeCheckbox;f&&this._initNewCardRememberMeCheckbox(f)}if(null==t?void 0:t.learnMoreLink){var m="string"==typeof(null==t?void 0:t.learnMoreLink)?document.querySelector(null==t?void 0:t.learnMoreLink):null==t?void 0:t.learnMoreLink;m&&this._initLearnMore(m)}return(e="string"==typeof e?document.querySelector(e):e).appendChild(this.controller),e.appendChild(this.encrypt),this.clickToPay.element=e,this.clickToPay})).call(this)}constructor(e){M(this,"secureFields",void 0),M(this,"_buyerExists",void 0),M(this,"consent",void 0),M(this,"controller",void 0),M(this,"encrypt",void 0),M(this,"origin",void 0),M(this,"url",void 0),M(this,"cardForm",void 0),M(this,"signIn",void 0),M(this,"clickToPay",void 0),this.secureFields=e,this._buyerExists=!1,this.consent=!1}}function H(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function G(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function V(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){G(e,t,r[t])}))}return e}function W(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}class B{_postMessage(e){return(t=function*(){yield this.ready,this.frame.contentWindow.postMessage(V({channel:c},e),this.frameUrl)},function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(e){H(o,n,i,a,s,"next",e)}function s(e){H(o,n,i,a,s,"throw",e)}a(void 0)}))}).call(this);var t}update(e){if(this.frameUrl){this.options=V({},this.options,e);var t=w(V({},this.options.styles,e.styles)),r=W(V({},this.options,e),{styles:t});this._postMessage({type:"update",data:W(V({},r),{styles:t})}),E("Updated field",this.options)}}setPlaceholder(e){this.update({placeholder:e})}setStyles(e){this.update({styles:e})}clear(){if(this.frameUrl){var e=this.type;this._postMessage({type:"reset",data:{type:e}}),E("Cleared field",{type:e})}}focus(){if(this.frameUrl){var e=this.type;this._postMessage({type:"focus",data:{type:e}}),E("Focus field",{type:e})}}redactValue(){if(this.frameUrl){var e=this.type;this._postMessage({type:"redact-value",data:{type:e}}),E("Redact field",{type:e})}}unredactValue(){if(this.frameUrl){var e=this.type;this._postMessage({type:"unredact-value",data:{type:e}}),E("Unredact field",{type:e})}}setEnterKeyHint(e){if(this.frameUrl){var t=this.type;this._postMessage({type:"set-enter-key-hint",data:{type:t,value:e}}),E("Updated enter key hint",{type:t,value:e})}}constructor(e){if(G(this,"frameUrl",void 0),G(this,"parentOrigin",void 0),G(this,"frame",void 0),G(this,"type",void 0),G(this,"options",void 0),G(this,"addEventListener",void 0),G(this,"removeEventListener",void 0),G(this,"ready",void 0),G(this,"_resolveReady",void 0),G(this,"complete",void 0),e){this.ready=new Promise((e=>{this._resolveReady=e}));var t=e.frameUrl,n=e.parentOrigin,i=e.font,o=e.sessionId,a=e.gr4vyId,s=e.environment,c=e.options,l=c.type,d=c.autoFocus,u=function(e,t){if(null==e)return{};var r,n,i,o={};if("undefined"!=typeof Reflect&&Reflect.ownKeys){for(r=Reflect.ownKeys(Object(e)),i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n]);return o}if(o=function(e,t){if(null==e)return{};var r,n,i={},o=Object.getOwnPropertyNames(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r]);return i}(e,t),Object.getOwnPropertySymbols)for(r=Object.getOwnPropertySymbols(e),i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n]);return o}(c,["type","autoFocus"]),h=e.paymentMethodScheme;this.frameUrl=t,this.parentOrigin=n,this.type=l,this.options=u;var p=w(u.styles),y={parentOrigin:n,type:l,sessionId:o,gr4vyId:a,environment:s};this.frame=document.createElement("iframe"),this.frame.id=l,this.frame.src=r("".concat(t,"/input.html"),y),this.frame.title="Secure Input",this.frame.style.display="block",this.frame.style.height="100%",this.frame.style.border="none",this.frame.style.width="100%",i&&(this.frame.src+="&font=".concat(i)),h&&(this.frame.src+="&paymentMethodScheme=".concat(h)),this.frame.onload=()=>{this._postMessage({type:"update",data:W(V({},this.options),{styles:p,type:l})}),E("Added field",this.options),d&&this.focus()}}}}function q(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function z(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Z(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){z(e,t,r[t])}))}return e}function Q(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}function J(e,t){if(null==e)return{};var r,n,i,o={};if("undefined"!=typeof Reflect&&Reflect.ownKeys){for(r=Reflect.ownKeys(Object(e)),i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n]);return o}if(o=function(e,t){if(null==e)return{};var r,n,i={},o=Object.getOwnPropertyNames(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r]);return i}(e,t),Object.getOwnPropertySymbols)for(r=Object.getOwnPropertySymbols(e),i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n]);return o}class ${static get Events(){return i}static get version(){return"#98b8221a9bbaca78d42aba26e7801b5b24958275"}update(e,t){this[e]=t}updateMethod(e,t){var r=t.data;this.update("method",e),p.publish(i.METHOD_CHANGE,r),E("Method changed",{method:e}),this.controller.contentWindow.postMessage({type:"method-change",channel:c},this.frameUrl)}setAutoAdvance(e){e.enabled&&(T(s.AUTO_ADVANCE_ENABLED),this.autoAdvance=(e=>{var t=e.enabled,r=e.secureFields,n=(e=>{if(!(null==e?void 0:e.length))return v;var t=e.filter(((t,r)=>v.includes(t)&&e.indexOf(t)===r)),r=v.filter((e=>!t.includes(e)));return[...t,...r]})(e.fieldOrder),i=e=>e?"number"===e?r.cardNumber:"expiryDate"===e?r.expiryDate:"securityCode"===e?r.securityCode:r.otherFields[e]:null,o=e=>{var t=e.type,r=e.nextIndex,a=null!=r?r:n.indexOf(t);if(!(a<0||a>=n.length-1)){var s=i(n[a+1]);!(null==s?void 0:s.complete)&&(null==s?void 0:s.frame)?s.focus():o({nextIndex:a+1})}};return{get enabled(){return t},get fieldOrder(){return n},updateEnterKeyHint:e=>{var r;if(null==e?void 0:e.frame){var o=n.indexOf(e.type),a=n[o+1],s=a&&(null===(r=i(a))||void 0===r?void 0:r.frame);e.setEnterKeyHint(t&&s?"next":"done")}},trigger:o}})(Q(Z({},e),{secureFields:this})))}_addField(e,t){if(!(e="string"==typeof e?document.querySelector(e):e)||!t.frame)return t.addEventListener=()=>{},t.removeEventListener=()=>{},t;var r=e.closest("[data-secure-fields-input-group]"),n=null!=r?r:document.createElement("div"),i=e=>{var r;if(e.origin===this.frameUrl&&(null===(r=e.data.data)||void 0===r?void 0:r.id)===t.type)switch(e.data.type){case"blur":p.publish("".concat(t.type,":blur"),e.data.data),n.removeAttribute(a.FOCUSED),E("Field blurred",e.data.data);break;case"focus":p.publish("".concat(t.type,":focus"),e.data.data),n.setAttribute(a.FOCUSED,""),E("Field focused",e.data.data);break;case"input":var i,o=e.data.data,s=o.complete,c=o.fromBlur,l=o.isDeleteInputType,d=J(o,["complete","fromBlur","isDeleteInputType"]);p.publish("".concat(t.type,":input"),d),t.complete=s,e.data.data.valid?n.removeAttribute(a.INVALID):n.setAttribute(a.INVALID,""),e.data.data.autofilled?n.setAttribute(a.AUTOFILLED,""):n.removeAttribute(a.AUTOFILLED),(null===(i=this.autoAdvance)||void 0===i?void 0:i.enabled)&&s&&!d.autofilled&&!1===c&&!l&&this.autoAdvance.trigger({type:t.type}),E("Field input changed",d);break;case"redacted":p.publish("".concat(t.type,":redacted"),e.data.data),E("Field redacted",e.data.data);break;case"unredacted":p.publish("".concat(t.type,":unredacted"),e.data.data),E("Field unredacted",e.data.data);break;case"card-details-changed":p.publish("".concat(t.type,":card-details-changed"),e.data.data),E("Card details changed",e.data.data)}};return m.remove("message",i,t.type),m.add("message",i,t.type),t.addEventListener=this.addEventListener,t.removeEventListener=this.removeEventListener,this.controllerReady.then((()=>{var i,o,a,s;i=e,o=n,Array.from(i.attributes).forEach((e=>{var t=e.name,r=e.value;_.some((e=>new RegExp(e).test(t)))&&o.setAttribute(t,r)})),(n=o).classList.add("secure-fields__input","secure-fields__input--".concat(A(t.type))),r?(null===(a=e.parentNode)||void 0===a||a.replaceChild(t.frame,e),r.style.display="inline-flex",r.style.alignItems="center",t.frame.style.minWidth="0"):(null===(s=e.parentNode)||void 0===s||s.replaceChild(n,e),n.appendChild(t.frame)),t._resolveReady(),t.frame.addEventListener("load",(()=>{var e;return null===(e=this.autoAdvance)||void 0===e?void 0:e.updateEnterKeyHint(t)}))})),t}addCardNumberField(e,t){return this.paymentMethodId&&T(s.PAYMENT_METHOD_ID_IN_USE,{method:"addCardNumberField"}),this.cardNumber||(this.cardNumber=new B(Q(Z({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,sessionId:this.config.sessionId,gr4vyId:this.config.gr4vyId,environment:this.config.environment},this.paymentMethodId?{paymentMethodId:this.paymentMethodId}:{}),{options:Q(Z({label:"Card number"},t),{type:"number"})}))),this._addField(e,this.cardNumber)}addSecurityCodeField(e,t){var r,n;return this.securityCode||(this.securityCode=new B({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:Q(Z({label:"Security code"},this.paymentMethodId&&!(null===(r=this.config.paymentMethod)||void 0===r?void 0:r.scheme)?{lengths:[3,4]}:{},t),{type:"securityCode"}),paymentMethodScheme:null===(n=this.config.paymentMethod)||void 0===n?void 0:n.scheme})),this._addField(e,this.securityCode)}addExpiryDateField(e,t){return this.paymentMethodId&&T(s.PAYMENT_METHOD_ID_IN_USE,{method:"addExpiryDateField"}),this.expiryDate||(this.expiryDate=new B({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:Q(Z({label:"Expiry date"},t),{type:"expiryDate"})})),this._addField(e,this.expiryDate)}addField(e,t){if(["number","expiryDate","securityCode"].includes(t.type)){t.pattern&&T(s.FIELD_PATTERN_IN_USE,Z({method:"addField"},t)),t.pattern,t.type;var r=J(t,["pattern","type"]);return this[l[t.type]](e,r)}return this.otherFields[t.type]||(this.otherFields=Q(Z({},this.otherFields),{[t.type]:new B({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:t})})),this._addField(e,this.otherFields[t.type])}addThreeDSecure(e,t){this.threeDS||(this.threeDS=new D(this),this.threeDS.init(e,t))}addClickToPay(e,t){return(r=function*(){if(!this.paymentMethodId)return this.clickToPayInstance=yield new K(this),this.clickToPay=yield this.clickToPayInstance.init(e,t),this.clickToPay;T(s.PAYMENT_METHOD_ID_IN_USE,{method:"addClickToPay"})},function(){var e=this,t=arguments;return new Promise((function(n,i){var o=r.apply(e,t);function a(e){q(o,n,i,a,s,"next",e)}function s(e){q(o,n,i,a,s,"throw",e)}a(void 0)}))}).call(this);var r}addEventListener(e,t){var r=this.type,n="".concat(this.constructor===B?"".concat(r,":"):"").concat(e);p.subscribe(n,t)}removeEventListener(e,t){var r=this.type,n="".concat(this.constructor===B?"".concat(r,":"):"").concat(e);p.unsubscribe(n,t)}submit(){var e,t,r=e=>{var t,n=[this.frameUrl,null===(t=this.clickToPayInstance)||void 0===t?void 0:t.origin].includes(e.origin),o=e.data.channel===c,a=["success","error"].includes(e.data.type);if(n&&o&&a){switch(e.data.type){case"success":var s;p.publish(i.CARD_VAULT_SUCCESS,e.data.data),(null===(s=e.data.data)||void 0===s?void 0:s.warn)&&(T(e.data.data.warn),delete e.data.data.warn),E("Payment method tokenized successfully",e.data.data);break;case"error":p.publish(i.CARD_VAULT_FAILURE,e.data),E("Failed to update checkout session",e.data.data)}window.removeEventListener("message",r)}};window.addEventListener("message",r),"click-to-pay"===this.method||"card"===this.method&&(null===(e=this.clickToPayInstance)||void 0===e?void 0:e.controller)&&!0===(null===(t=this.clickToPayInstance)||void 0===t?void 0:t.consent)?this.clickToPayInstance.controller.contentWindow.postMessage({type:"submit",channel:c},this.clickToPayInstance.url):this.controller.contentWindow.postMessage({type:"submit",channel:c,data:{method:this.paymentMethodId?"id":"card"}},this.frameUrl)}setDebug(e){localStorage.setItem(n,String(e))}addFont(e){this.font=e.replace(/\s/g,"+")}constructor(e){var t,n;z(this,"config",void 0),z(this,"controller",void 0),z(this,"frameUrl",void 0),z(this,"apiUrl",void 0),z(this,"parentOrigin",void 0),z(this,"font",void 0),z(this,"cardNumber",void 0),z(this,"securityCode",void 0),z(this,"expiryDate",void 0),z(this,"otherFields",{}),z(this,"method","card"),z(this,"clickToPayInstance",void 0),z(this,"clickToPay",void 0),z(this,"threeDS",void 0),z(this,"environmentPath",void 0),z(this,"paymentMethodId",void 0),z(this,"autoAdvance",null),z(this,"controllerReady",void 0),z(this,"_resolveControllerReady",void 0),p.unsubscribeAll(),this.config=Z({environment:"production"},e),this.controllerReady=new Promise((e=>{var t=Date.now();this._resolveControllerReady=()=>e(Date.now()-t)})),this.config.paymentMethodId&&!this.config.paymentMethod&&T(s.PAYMENT_METHOD_ID_DEPRECATED),this.environmentPath="sandbox"===this.config.environment?"sandbox.":"",this.frameUrl=window.SECURE_FIELDS_FRAME_URL||"https://secure-fields.".concat(this.environmentPath).concat(this.config.gr4vyId,".gr4vy.app"),this.parentOrigin=window.location.origin,this.paymentMethodId=(null===(t=this.config.paymentMethod)||void 0===t?void 0:t.id)||this.config.paymentMethodId;var o=Z({parentOrigin:this.parentOrigin,sessionId:this.config.sessionId,gr4vyId:this.config.gr4vyId,environment:this.config.environment},this.paymentMethodId?{paymentMethodId:this.paymentMethodId}:{});null===(n=document.body.querySelector("iframe#controller[src*=secure-fields]"))||void 0===n||n.remove(),this.controller=document.createElement("iframe"),this.controller.id="controller",this.controller.src=r("".concat(this.frameUrl,"/controller.html"),o),this.controller.title="Secure Controller",this.controller.style.position="absolute",this.controller.style.left="-9999999px",document.body.appendChild(this.controller),this.paymentMethodId&&(this.cardNumber=new B,this.expiryDate=new B),E("Initialized",Q(Z({},this.config),{version:$.version,frameUrl:this.frameUrl,parentOrigin:this.parentOrigin}));var a=e=>{if(e.origin===this.frameUrl)switch(e.data.type){case"ready":var t=Z({version:$.version},this.config);p.publish(i.READY,t),this._resolveControllerReady(),E("Ready",t);break;case"form-change":p.publish(i.FORM_CHANGE,e.data.data),E("Form change",e.data.data)}};m.remove("message",a,"init"),m.add("message",a,"init"),this.controllerReady.then((e=>E("Loaded controller after ".concat(e," milliseconds"))))}}return t})()));
package/lib/input.d.ts CHANGED
@@ -11,19 +11,23 @@ declare class SecureInput {
11
11
  removeEventListener: EventListener;
12
12
  private ready;
13
13
  _resolveReady: () => void;
14
+ complete: boolean;
14
15
  constructor(config?: Config);
15
16
  _postMessage(message: {
16
17
  type: string;
17
- data: Options & {
18
+ data?: Partial<Options> & {
18
19
  styles?: StylesTuple;
19
20
  type?: string;
21
+ value?: string;
20
22
  };
21
23
  }): Promise<void>;
22
24
  update(data: Options): void;
23
25
  setPlaceholder(placeholder: Options['placeholder']): void;
24
26
  setStyles(styles: Options['styles']): void;
25
27
  clear(): void;
28
+ focus(): void;
26
29
  redactValue(): void;
27
30
  unredactValue(): void;
31
+ setEnterKeyHint(value: 'next' | 'done'): void;
28
32
  }
29
33
  export { SecureInput };
package/lib/types.d.ts CHANGED
@@ -18,10 +18,17 @@ export type InputConfig = {
18
18
  frameUrl: string;
19
19
  parentOrigin: string;
20
20
  font?: string;
21
+ sessionId?: string;
22
+ gr4vyId?: string;
23
+ environment?: string;
21
24
  options: Field;
22
25
  paymentMethodScheme?: string;
23
26
  };
24
27
  export type FieldType = 'number' | 'securityCode' | 'expiryDate' | 'postalCode';
28
+ export type AutoAdvanceConfig = {
29
+ enabled: boolean;
30
+ fieldOrder?: FieldType[];
31
+ };
25
32
  export type FieldMaskConfig = {
26
33
  character?: string;
27
34
  showLastFour?: boolean;
@@ -34,15 +41,20 @@ export type Field = {
34
41
  label?: string;
35
42
  lengths?: Array<number>;
36
43
  size?: number;
44
+ autoFocus?: boolean;
37
45
  maskInput?: boolean | FieldMaskConfig;
38
46
  };
39
- export type FieldEventType = keyof HTMLElementEventMap | 'redacted' | 'unredacted';
47
+ export type FieldEventType = keyof HTMLElementEventMap | 'redacted' | 'unredacted' | 'card-details-changed';
40
48
  export type FieldEvent = {
41
49
  type: FieldEventType;
42
50
  data: Omit<Field, 'type' | 'styles'> & {
43
51
  id: Field['type'];
44
52
  valid: boolean;
45
53
  autofilled: boolean;
54
+ empty: boolean;
55
+ complete?: boolean;
56
+ fromBlur?: boolean;
57
+ isDeleteInputType?: boolean;
46
58
  };
47
59
  };
48
60
  export type CombinedEvents = Events | FieldEventType;
@@ -0,0 +1,16 @@
1
+ import { SecureFields } from "../index";
2
+ import type { SecureInput } from '../input';
3
+ import type { FieldType } from '../types';
4
+ export declare const createAutoAdvance: (config: {
5
+ enabled: boolean;
6
+ fieldOrder?: FieldType[];
7
+ secureFields: SecureFields;
8
+ }) => {
9
+ readonly enabled: boolean;
10
+ readonly fieldOrder: FieldType[];
11
+ updateEnterKeyHint: (input: SecureInput) => void;
12
+ trigger: ({ type, nextIndex, }: {
13
+ type?: FieldType;
14
+ nextIndex?: number;
15
+ }) => void;
16
+ };
@@ -1,3 +1,4 @@
1
+ export * from './auto-advance';
1
2
  export * from './cookies';
2
3
  export * from './copy-element-attributes';
3
4
  export * from './dom';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gr4vy/secure-fields",
3
- "version": "2.3.4",
3
+ "version": "2.5.0",
4
4
  "description": "Gr4vy-hosted secure fields offering advanced theming, PCI compliance, event handling, and more.",
5
5
  "main": "lib/index",
6
6
  "types": "lib/index",
@@ -56,5 +56,5 @@
56
56
  "access": "public",
57
57
  "registry": "https://registry.npmjs.org"
58
58
  },
59
- "gitHead": "428e1b2460c3306e09875c5614de27a7a0c3dc72"
59
+ "gitHead": "98b8221a9bbaca78d42aba26e7801b5b24958275"
60
60
  }