@gr4vy/secure-fields 1.17.0 → 1.18.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,19 @@
1
+ # v1.18.0 (Tue Jan 30 2024)
2
+
3
+ #### 🚀 Enhancement
4
+
5
+ - task: add click to pay react component [#558](https://github.com/gr4vy/secure-fields/pull/558) ([@luca-gr4vy](https://github.com/luca-gr4vy))
6
+
7
+ #### 🐛 Bug Fix
8
+
9
+ - fix: duplicate events [#566](https://github.com/gr4vy/secure-fields/pull/566) ([@luca-gr4vy](https://github.com/luca-gr4vy))
10
+
11
+ #### Authors: 1
12
+
13
+ - Luca Allievi ([@luca-gr4vy](https://github.com/luca-gr4vy))
14
+
15
+ ---
16
+
1
17
  # v1.17.0 (Wed Jan 24 2024)
2
18
 
3
19
  #### 🚀 Enhancement
package/lib/index.d.ts CHANGED
@@ -48,4 +48,4 @@ declare class SecureFields {
48
48
  addFont(font: string): void;
49
49
  }
50
50
  export { SecureFields, SecureInput };
51
- export type { Config, CombinedEvents, Field, FieldType, FieldEvent, Styles, StylesTuple, FormChangeEventData, } from './types';
51
+ export type { ClickToPayInstance, ClickToPayOptions, Config, CombinedEvents, Field, FieldType, FieldEvent, Styles, StylesTuple, FormChangeEventData, } 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,(function(){return function(){"use strict";var e={d:function(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:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e,t,r,n,o,i,a){try{var c=e[i](a),s=c.value}catch(e){return void r(e)}c.done?t(s):Promise.resolve(s).then(n,o)}e.r(t),e.d(t,{SecureFields:function(){return Y},SecureInput:function(){return E}});class n extends Error{constructor(e){super(e),this.name="UnableToLoadDpaError"}}function o(){var e;return e=function*(e){var t=e.apiBaseUrl,r=e.checkoutSessionId;try{var o="".concat(t,"/digital-wallets/click-to-pay/session"),i=yield fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({checkout_session_id:r})});if(i.ok){var a=yield i.json();return{srcDpaId:a.digital_payment_application_id,dpaName:a.digital_payment_application_name}}throw new n("Unable to load DPA")}catch(e){throw new n("Unable to load DPA")}},o=function(){var t=this,n=arguments;return new Promise((function(o,i){var a=e.apply(t,n);function c(e){r(a,o,i,c,s,"next",e)}function s(e){r(a,o,i,c,s,"throw",e)}c(void 0)}))},o.apply(this,arguments)}var i,a,c,s,l="@gr4vy-secure-fields-debug";!function(e){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"}(i||(i={})),function(e){e.REQUEST_PORT="request-port",e.TRANSFER_PORT="transfer-port"}(a||(a={})),function(e){e.FOCUSED="data-secure-fields-focused",e.INVALID="data-secure-fields-invalid",e.AUTOFILLED="data-secure-fields-autofilled"}(c||(c={})),function(e){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"}(s||(s={}));var d="secure-fields";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 p(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,o,i=[],a=!0,c=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(c)throw o}}return i}}(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 h=new class{subscribe(e,t){this.subscribers.push([e,t])}unsubscribe(e,t){this.subscribers=this.subscribers.filter((r=>{var n=p(r,2),o=n[0],i=n[1];return o!==e||i.toString()!==t.toString()}))}publish(e,t){this.subscribers.forEach((r=>{var n=p(r,2),o=n[0],i=n[1];return setTimeout((()=>o===e?i(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=[]}},y=["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"],f=(e,t)=>e&&(e.style.display=t?"block":"none");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 b(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}var _={debug:!1,level:"log"},v=(e,t,r)=>{var n=b({},_,r),o=n.debug,i=n.level;(o||"true"===localStorage.getItem(l))&&console[i]("Gr4vy - Secure Fields - ".concat(e),t||{})},g=(e,t,r)=>{var n,o;v(e,t,(n=b({},r),o=null!=(o={level:"warn"})?o:{},Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(o)):function(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r.push.apply(r,n)}return r}(Object(o)).forEach((function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(o,e))})),n))},I=e=>(e!=e.toLowerCase()&&(e=e.replace(/[A-Z]/g,(e=>"-"+e.toLowerCase()))),e);function O(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 C=function(){var e=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return Object.entries(t).reduce(((n,o)=>{var i,a,c=(a=2,function(e){if(Array.isArray(e))return e}(i=o)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i=[],a=!0,c=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(c)throw o}}return i}}(i,a)||function(e,t){if(e){if("string"==typeof e)return O(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)?O(e,t):void 0}}(i,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.")}()),s=c[0],l=c[1];return(e=>"[object Object]"===Object.prototype.toString.call(e))(l)?n.push(...e(t[s],"".concat((r+s).match(/[a-zA-Z0-9]+/g).join("-"),"-"))):(s=I(s).replace(/^-/,""),n.push(["--".concat(r).concat(s),l])),n}),[])};return e(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})};function A(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function P(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){A(e,t,r[t])}))}return e}function T(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r.push.apply(r,n)}return r}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}class E{_postMessage(e){this.frame.contentWindow.postMessage(P({channel:d},e),this.frameUrl)}update(e){if(this.frameUrl){this.options=P({},this.options,e);var t=C(P({},this.options.styles,e.styles)),r=T(P({},this.options,e),{styles:t});this._postMessage({type:"update",data:T(P({},r),{styles:t})}),v("Updated field",this.options)}}setPlaceholder(e){this.update({placeholder:e})}setStyles(e){this.update({styles:e})}constructor(e){if(A(this,"frameUrl",void 0),A(this,"parentOrigin",void 0),A(this,"frame",void 0),A(this,"type",void 0),A(this,"options",void 0),A(this,"addEventListener",void 0),A(this,"removeEventListener",void 0),e){var t=e.frameUrl,r=e.parentOrigin,n=e.font,o=e.options.type,i=function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(e.options,["type"]);this.frameUrl=t,this.parentOrigin=r,this.type=o,this.options=i;var a=C(i.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.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)),this.frame.onload=()=>{this._postMessage({type:"update",data:T(P({},this.options),{styles:a})}),v("Added field",this.options)}}}}function L(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=new class{add(e,t){window.addEventListener(e,t),this.listeners.push([e,t])}removeAll(){this.listeners.forEach((e=>{var t,r,n=(r=2,function(e){if(Array.isArray(e))return e}(t=e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i=[],a=!0,c=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(c)throw o}}return i}}(t,r)||function(e,t){if(e){if("string"==typeof e)return L(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)?L(e,t):void 0}}(t,r)||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.")}()),o=n[0],i=n[1];window.removeEventListener(o,i)})),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}};function S(e,t,r,n,o,i,a){try{var c=e[i](a),s=c.value}catch(e){return void r(e)}c.done?t(s):Promise.resolve(s).then(n,o)}function k(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){S(i,n,o,a,c,"next",e)}function c(e){S(i,n,o,a,c,"throw",e)}a(void 0)}))}}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 D(){return D=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},D.apply(this,arguments)}function U(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 j(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r.push.apply(r,n)}return r}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}class Y{static get Events(){return i}static get version(){return"#866fb2e4de535d1b8ec7640c797fff5b487d1b8f"}_addField(e,t){if(!(e="string"==typeof e?document.querySelector(e):e)||!t.frame)return t.addEventListener=()=>{},t.removeEventListener=()=>{},t;var r,n,o=document.createElement("div");return r=e,n=o,Array.from(r.attributes).forEach((e=>{var t=e.name,r=e.value;y.some((e=>new RegExp(e).test(t)))&&n.setAttribute(t,r)})),(o=n).classList.add("secure-fields__input","secure-fields__input--".concat(I(t.type))),o.appendChild(t.frame),e.parentNode.replaceChild(o,e),window.addEventListener("message",(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":h.publish("".concat(t.type,":blur"),e.data.data),o.removeAttribute(c.FOCUSED),v("Field blurred",e.data.data);break;case"focus":h.publish("".concat(t.type,":focus"),e.data.data),o.setAttribute(c.FOCUSED,""),v("Field focused",e.data.data);break;case"input":h.publish("".concat(t.type,":input"),e.data.data),e.data.data.valid?o.removeAttribute(c.INVALID):o.setAttribute(c.INVALID,""),e.data.data.autofilled?o.setAttribute(c.AUTOFILLED,""):o.removeAttribute(c.AUTOFILLED),v("Field input changed",e.data.data)}})),t.addEventListener=this.addEventListener,t.removeEventListener=this.removeEventListener,t}addCardNumberField(e,t){return this.config.paymentMethodId&&g(s.PAYMENT_METHOD_ID_IN_USE,{method:"addCardNumberField"}),this.cardNumber||(this.cardNumber=new E({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:j(U({label:"Card number"},t),{type:"number"})})),this._addField(e,this.cardNumber)}addSecurityCodeField(e,t){return this.securityCode||(this.securityCode=new E({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:j(U({label:"Security code"},this.config.paymentMethodId?{lengths:[3,4]}:{},t),{type:"securityCode"})})),this._addField(e,this.securityCode)}addExpiryDateField(e,t){return this.config.paymentMethodId&&g(s.PAYMENT_METHOD_ID_IN_USE,{method:"addExpiryDateField"}),this.expiryDate||(this.expiryDate=new E({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:j(U({label:"Expiry date"},t),{type:"expiryDate"})})),this._addField(e,this.expiryDate)}addClickToPay(e,t){var r=this;return k((function*(){if(!r.config.paymentMethodId){var n="string"==typeof(null==t?void 0:t.cardForm)?document.querySelector(null==t?void 0:t.cardForm):null==t?void 0:t.cardForm,c="string"==typeof(null==t?void 0:t.signIn)?document.querySelector(null==t?void 0:t.signIn):null==t?void 0:t.signIn;if(f(c,!1),r.clickToPay={element:null,options:t,signIn:function(){var e=k((function*(e){var t=e.email,o=e.mobileNumber,a=r.clickToPay,s=a.element,l=a.options;delete l.email,delete l.mobileNumber,s.innerHTML="",f(c,!1),h.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),f(n,!1),h.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,!1),yield r.addClickToPay(s,U({},l,t?{email:t}:{},o?{mobileNumber:o}:{}))}));return function(t){return e.apply(this,arguments)}}()},!(null==t?void 0:t.srcDpaId)||!(null==t?void 0:t.dpaName))try{var l=r.apiUrl||function(e){return"https://api.".concat("sandbox"===(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"production")?"sandbox.":"").concat(e,".gr4vy.app")}(r.config.gr4vyId,r.config.environment),u=yield function(e){return o.apply(this,arguments)}({apiBaseUrl:l,checkoutSessionId:r.config.sessionId}),p=u.srcDpaId,y=u.dpaName;t.srcDpaId=p,t.dpaName=y}catch(e){return v(e.message),h.publish(i.CLICK_TO_PAY_UNABLE_TO_LOAD_DPA),f(n,!0),h.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,!0),f(r.clickToPay.element,!1),void h.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,!1)}r.clickToPayUrl=window.CLICK_TO_PAY_FRAME_URL||"https://click-to-pay.".concat(r.environmentPath).concat(r.config.gr4vyId,".gr4vy.app"),r.parentOrigin=window.location.origin,r.clickToPayOrigin=new URL(r.clickToPayUrl).origin;var m=D({},function(e){if(null==e)throw new TypeError("Cannot destructure "+e);return e}(t)),b=U({gr4vyId:r.config.gr4vyId,environment:r.config.environment,sessionId:r.config.sessionId},m),_=document.createElement("iframe");_.id="click-to-pay-controller",_.setAttribute("width","100%"),_.setAttribute("frameborder","0"),_.setAttribute("style","height:0px"),_.src="".concat(r.clickToPayUrl,"/click-to-pay.html?parentOrigin=").concat(r.parentOrigin,"&environment=").concat(r.config.environment,"&config=").concat(encodeURIComponent(JSON.stringify(b)));var I=document.createElement("iframe");I.setAttribute("width","0"),I.setAttribute("frameborder","0"),I.setAttribute("style","height:0px"),I.src="".concat(r.frameUrl,"/click-to-pay-encrypt.html?parentOrigin=").concat(r.parentOrigin,"&environment=").concat(r.config.environment,"&config=").concat(encodeURIComponent(JSON.stringify(b)));var O=new MessageChannel,C=!0;if(w.removeAll(),w.add("message",(e=>{switch(e.origin){case r.clickToPayOrigin:switch(e.data.type){case i.RESIZE:_.style.height=e.data.data.height>0?"".concat(e.data.data.height+48,"px"):"0px";break;case i.METHOD_CHANGE:var t=e.data.data.method||"card";(r.method!==t||C)&&(C=!1,r.method=t,h.publish(i.METHOD_CHANGE,e.data.data),v("Method changed",{method:r.method}),r.controller.contentWindow.postMessage({type:"method-change",channel:d},r.frameUrl),f(n,"card"===r.method),h.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,"card"===r.method));break;case i.CLICK_TO_PAY_INITIALIZED:h.publish(i.CLICK_TO_PAY_INITIALIZED,r.clickToPay),v("Click to Pay initialized",r.clickToPay),f(c,!1),h.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),f(r.clickToPay.element,!0),h.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case i.CLICK_TO_PAY_READY:h.publish(i.CLICK_TO_PAY_READY,e.data.data),v("Click to Pay ready"),f(c,!e.data.data.buyerExists),h.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!e.data.data.buyerExists),f(r.clickToPay.element,!0),h.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case i.CLICK_TO_PAY_SIGN_OUT:h.publish(i.CLICK_TO_PAY_SIGN_OUT),v("Click to pay signed out"),f(c,!0),h.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!0);break;case i.CLICK_TO_PAY_ERROR:h.publish(i.CLICK_TO_PAY_ERROR,e.data.data),v("Click to Pay error:",e.data.data),f(c,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(e.data.data.error)),h.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(e.data.data.error)),f(r.clickToPay.element,"UNKNOWN"!==e.data.data.error),h.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,"UNKNOWN"!==e.data.data.error);break;case i.CLICK_TO_PAY_CANCEL:h.publish(i.CLICK_TO_PAY_CANCEL,e.data.data),v("Click to Pay cancelled"),f(c,!0),h.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!0);break;case i.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD:h.publish(i.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD,e.data.data),f(c,!1),h.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),v("Click to Pay checkout with new card initiated");break;case a.REQUEST_PORT:_.contentWindow.postMessage({channel:d,type:a.TRANSFER_PORT},r.clickToPayOrigin,[O.port1])}break;case r.frameUrl:e.data.type===a.REQUEST_PORT&&I.contentWindow.postMessage({channel:d,type:a.TRANSFER_PORT},r.frameUrl,[O.port2])}})),null==t?void 0:t.consentCheckbox){var A="string"==typeof(null==t?void 0:t.consentCheckbox)?document.querySelector(null==t?void 0:t.consentCheckbox):null==t?void 0:t.consentCheckbox;r.method=A.checked?"click-to-pay":"card",v("Method changed",{method:r.method}),A.addEventListener("change",(e=>{var t=e.target;r.clickToPayConsent=t.checked})),w.add("message",(e=>{e.data.type===i.CLICK_TO_PAY_ERROR&&"UNKNOWN"===e.data.data.error&&(r.clickToPayConsent=!1,A.checked=!1)}))}if(null==t?void 0:t.learnMoreLink){var P="string"==typeof(null==t?void 0:t.learnMoreLink)?document.querySelector(null==t?void 0:t.learnMoreLink):null==t?void 0:t.learnMoreLink;P.style.visibility="hidden",w.add("message",(e=>{e.data.type===i.CLICK_TO_PAY_INITIALIZED&&(P.style.visibility="visible",P.addEventListener("click",(()=>{_.contentWindow.postMessage({type:"show-learn-more",channel:d},r.clickToPayOrigin)})))}))}return(e="string"==typeof e?document.querySelector(e):e).appendChild(_),e.appendChild(I),r.clickToPay.element=e,r.clickToPayController=_,r.clickToPay}g(s.PAYMENT_METHOD_ID_IN_USE,{method:"addClickToPay"})}))()}addEventListener(e,t){var r=this.type,n="".concat(this.constructor===E?"".concat(r,":"):"").concat(e);h.subscribe(n,t)}removeEventListener(e,t){var r=this.type,n="".concat(this.constructor===E?"".concat(r,":"):"").concat(e);h.unsubscribe(n,t)}submit(){var e=t=>{var r=[this.frameUrl,this.clickToPayOrigin].includes(t.origin),n=t.data.channel===d,o=["success","error"].includes(t.data.type);if(r&&n&&o){switch(t.data.type){case"success":h.publish(i.CARD_VAULT_SUCCESS),v("Payment method tokenized successfully");break;case"error":h.publish(i.CARD_VAULT_FAILURE,t.data),v("Failed to update checkout session",t.data.data)}window.removeEventListener("message",e)}};window.addEventListener("message",e),"click-to-pay"===this.method||"card"===this.method&&this.clickToPayController&&!0===this.clickToPayConsent?this.clickToPayController.contentWindow.postMessage({type:"submit",channel:d},this.clickToPayUrl):this.controller.contentWindow.postMessage({type:"submit",channel:d,data:{method:this.config.paymentMethodId?"id":"card"}},this.frameUrl)}setDebug(e){localStorage.setItem(l,String(e))}addFont(e){this.font=e.replace(/\s/g,"+")}constructor(e){N(this,"config",void 0),N(this,"controller",void 0),N(this,"frameUrl",void 0),N(this,"apiUrl",void 0),N(this,"parentOrigin",void 0),N(this,"font",void 0),N(this,"cardNumber",void 0),N(this,"securityCode",void 0),N(this,"expiryDate",void 0),N(this,"method","card"),N(this,"clickToPay",void 0),N(this,"clickToPayController",void 0),N(this,"clickToPayUrl",void 0),N(this,"clickToPayOrigin",void 0),N(this,"environmentPath",void 0),N(this,"clickToPayConsent",!1),this.config=U({environment:"production"},e),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;var t=U({parentOrigin:this.parentOrigin,sessionId:this.config.sessionId,gr4vyId:this.config.gr4vyId,environment:this.config.environment},this.config.paymentMethodId?{paymentMethodId:this.config.paymentMethodId}:{});this.controller=document.createElement("iframe"),this.controller.id="controller",this.controller.src=((e,t)=>"".concat(e,"?").concat(new URLSearchParams(t).toString()))("".concat(this.frameUrl,"/controller.html"),t),this.controller.style.position="absolute",this.controller.style.left="-9999999px",document.body.appendChild(this.controller),this.config.paymentMethodId&&(this.cardNumber=new E,this.expiryDate=new E),v("Initialized",j(U({},this.config),{version:Y.version,frameUrl:this.frameUrl,parentOrigin:this.parentOrigin})),window.addEventListener("message",(e=>{if(e.origin===this.frameUrl)switch(e.data.type){case"ready":var t=U({version:Y.version},this.config);h.publish(i.READY,t),v("Ready",t);break;case"form-change":h.publish(i.FORM_CHANGE,e.data.data),v("Form change",e.data.data)}}))}}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,(function(){return function(){"use strict";var e={d:function(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:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e,t,r,n,o,i,a){try{var c=e[i](a),s=c.value}catch(e){return void r(e)}c.done?t(s):Promise.resolve(s).then(n,o)}e.r(t),e.d(t,{SecureFields:function(){return Y},SecureInput:function(){return E}});class n extends Error{constructor(e){super(e),this.name="UnableToLoadDpaError"}}function o(){var e;return e=function*(e){var t=e.apiBaseUrl,r=e.checkoutSessionId;try{var o="".concat(t,"/digital-wallets/click-to-pay/session"),i=yield fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({checkout_session_id:r})});if(i.ok){var a=yield i.json();return{srcDpaId:a.digital_payment_application_id,dpaName:a.digital_payment_application_name}}throw new n("Unable to load DPA")}catch(e){throw new n("Unable to load DPA")}},o=function(){var t=this,n=arguments;return new Promise((function(o,i){var a=e.apply(t,n);function c(e){r(a,o,i,c,s,"next",e)}function s(e){r(a,o,i,c,s,"throw",e)}c(void 0)}))},o.apply(this,arguments)}var i,a,c,s,l="@gr4vy-secure-fields-debug";!function(e){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"}(i||(i={})),function(e){e.REQUEST_PORT="request-port",e.TRANSFER_PORT="transfer-port"}(a||(a={})),function(e){e.FOCUSED="data-secure-fields-focused",e.INVALID="data-secure-fields-invalid",e.AUTOFILLED="data-secure-fields-autofilled"}(c||(c={})),function(e){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"}(s||(s={}));var d="secure-fields";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 p(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,o,i=[],a=!0,c=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(c)throw o}}return i}}(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 h=new class{subscribe(e,t){this.subscribers.push([e,t])}unsubscribe(e,t){this.subscribers=this.subscribers.filter((r=>{var n=p(r,2),o=n[0],i=n[1];return o!==e||i.toString()!==t.toString()}))}publish(e,t){this.subscribers.forEach((r=>{var n=p(r,2),o=n[0],i=n[1];return setTimeout((()=>o===e?i(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=[]}},y=["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"],f=(e,t)=>e&&(e.style.display=t?"block":"none");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 b(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}var v={debug:!1,level:"log"},_=(e,t,r)=>{var n=b({},v,r),o=n.debug,i=n.level;(o||"true"===localStorage.getItem(l))&&console[i]("Gr4vy - Secure Fields - ".concat(e),t||{})},g=(e,t,r)=>{var n,o;_(e,t,(n=b({},r),o=null!=(o={level:"warn"})?o:{},Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(o)):function(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r.push.apply(r,n)}return r}(Object(o)).forEach((function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(o,e))})),n))},I=e=>(e!=e.toLowerCase()&&(e=e.replace(/[A-Z]/g,(e=>"-"+e.toLowerCase()))),e);function O(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 C=function(){var e=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return Object.entries(t).reduce(((n,o)=>{var i,a,c=(a=2,function(e){if(Array.isArray(e))return e}(i=o)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i=[],a=!0,c=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(c)throw o}}return i}}(i,a)||function(e,t){if(e){if("string"==typeof e)return O(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)?O(e,t):void 0}}(i,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.")}()),s=c[0],l=c[1];return(e=>"[object Object]"===Object.prototype.toString.call(e))(l)?n.push(...e(t[s],"".concat((r+s).match(/[a-zA-Z0-9]+/g).join("-"),"-"))):(s=I(s).replace(/^-/,""),n.push(["--".concat(r).concat(s),l])),n}),[])};return e(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})};function A(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function P(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){A(e,t,r[t])}))}return e}function T(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r.push.apply(r,n)}return r}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}class E{_postMessage(e){this.frame.contentWindow.postMessage(P({channel:d},e),this.frameUrl)}update(e){if(this.frameUrl){this.options=P({},this.options,e);var t=C(P({},this.options.styles,e.styles)),r=T(P({},this.options,e),{styles:t});this._postMessage({type:"update",data:T(P({},r),{styles:t})}),_("Updated field",this.options)}}setPlaceholder(e){this.update({placeholder:e})}setStyles(e){this.update({styles:e})}constructor(e){if(A(this,"frameUrl",void 0),A(this,"parentOrigin",void 0),A(this,"frame",void 0),A(this,"type",void 0),A(this,"options",void 0),A(this,"addEventListener",void 0),A(this,"removeEventListener",void 0),e){var t=e.frameUrl,r=e.parentOrigin,n=e.font,o=e.options.type,i=function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(e.options,["type"]);this.frameUrl=t,this.parentOrigin=r,this.type=o,this.options=i;var a=C(i.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.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)),this.frame.onload=()=>{this._postMessage({type:"update",data:T(P({},this.options),{styles:a})}),_("Added field",this.options)}}}}function L(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=new class{add(e,t){window.addEventListener(e,t),this.listeners.push([e,t])}removeAll(){this.listeners.forEach((e=>{var t,r,n=(r=2,function(e){if(Array.isArray(e))return e}(t=e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i=[],a=!0,c=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(c)throw o}}return i}}(t,r)||function(e,t){if(e){if("string"==typeof e)return L(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)?L(e,t):void 0}}(t,r)||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.")}()),o=n[0],i=n[1];window.removeEventListener(o,i)})),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}};function S(e,t,r,n,o,i,a){try{var c=e[i](a),s=c.value}catch(e){return void r(e)}c.done?t(s):Promise.resolve(s).then(n,o)}function k(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){S(i,n,o,a,c,"next",e)}function c(e){S(i,n,o,a,c,"throw",e)}a(void 0)}))}}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 D(){return D=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},D.apply(this,arguments)}function U(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 j(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r.push.apply(r,n)}return r}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}class Y{static get Events(){return i}static get version(){return"#fee69721a94e90096d2df10fed0e635d0b14627b"}_addField(e,t){var r;if(!(e="string"==typeof e?document.querySelector(e):e)||!t.frame)return t.addEventListener=()=>{},t.removeEventListener=()=>{},t;var n,o,i=document.createElement("div");return n=e,o=i,Array.from(n.attributes).forEach((e=>{var t=e.name,r=e.value;y.some((e=>new RegExp(e).test(t)))&&o.setAttribute(t,r)})),(i=o).classList.add("secure-fields__input","secure-fields__input--".concat(I(t.type))),i.appendChild(t.frame),null===(r=e.parentNode)||void 0===r||r.replaceChild(i,e),w.add("message",(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":h.publish("".concat(t.type,":blur"),e.data.data),i.removeAttribute(c.FOCUSED),_("Field blurred",e.data.data);break;case"focus":h.publish("".concat(t.type,":focus"),e.data.data),i.setAttribute(c.FOCUSED,""),_("Field focused",e.data.data);break;case"input":h.publish("".concat(t.type,":input"),e.data.data),e.data.data.valid?i.removeAttribute(c.INVALID):i.setAttribute(c.INVALID,""),e.data.data.autofilled?i.setAttribute(c.AUTOFILLED,""):i.removeAttribute(c.AUTOFILLED),_("Field input changed",e.data.data)}})),t.addEventListener=this.addEventListener,t.removeEventListener=this.removeEventListener,t}addCardNumberField(e,t){return this.config.paymentMethodId&&g(s.PAYMENT_METHOD_ID_IN_USE,{method:"addCardNumberField"}),this.cardNumber||(this.cardNumber=new E({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:j(U({label:"Card number"},t),{type:"number"})})),this._addField(e,this.cardNumber)}addSecurityCodeField(e,t){return this.securityCode||(this.securityCode=new E({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:j(U({label:"Security code"},this.config.paymentMethodId?{lengths:[3,4]}:{},t),{type:"securityCode"})})),this._addField(e,this.securityCode)}addExpiryDateField(e,t){return this.config.paymentMethodId&&g(s.PAYMENT_METHOD_ID_IN_USE,{method:"addExpiryDateField"}),this.expiryDate||(this.expiryDate=new E({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:j(U({label:"Expiry date"},t),{type:"expiryDate"})})),this._addField(e,this.expiryDate)}addClickToPay(e,t){var r=this;return k((function*(){if(!r.config.paymentMethodId){var n="string"==typeof(null==t?void 0:t.cardForm)?document.querySelector(null==t?void 0:t.cardForm):null==t?void 0:t.cardForm,c="string"==typeof(null==t?void 0:t.signIn)?document.querySelector(null==t?void 0:t.signIn):null==t?void 0:t.signIn;if(f(c,!1),r.clickToPay={element:null,options:t,signIn:function(){var e=k((function*(e){var t=e.email,o=e.mobileNumber,a=r.clickToPay,s=a.element,l=a.options;delete l.email,delete l.mobileNumber,s.innerHTML="",f(c,!1),h.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),f(n,!1),h.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,!1),yield r.addClickToPay(s,U({},l,t?{email:t}:{},o?{mobileNumber:o}:{}))}));return function(t){return e.apply(this,arguments)}}()},!(null==t?void 0:t.srcDpaId)||!(null==t?void 0:t.dpaName))try{var l=r.apiUrl||function(e){return"https://api.".concat("sandbox"===(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"production")?"sandbox.":"").concat(e,".gr4vy.app")}(r.config.gr4vyId,r.config.environment),u=yield function(e){return o.apply(this,arguments)}({apiBaseUrl:l,checkoutSessionId:r.config.sessionId}),p=u.srcDpaId,y=u.dpaName;t.srcDpaId=p,t.dpaName=y}catch(e){return _(e.message),h.publish(i.CLICK_TO_PAY_UNABLE_TO_LOAD_DPA),f(n,!0),h.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,!0),f(r.clickToPay.element,!1),void h.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,!1)}r.clickToPayUrl=window.CLICK_TO_PAY_FRAME_URL||"https://click-to-pay.".concat(r.environmentPath).concat(r.config.gr4vyId,".gr4vy.app"),r.parentOrigin=window.location.origin,r.clickToPayOrigin=new URL(r.clickToPayUrl).origin;var m=D({},function(e){if(null==e)throw new TypeError("Cannot destructure "+e);return e}(t)),b=U({gr4vyId:r.config.gr4vyId,environment:r.config.environment,sessionId:r.config.sessionId},m),v=document.createElement("iframe");v.id="click-to-pay-controller",v.setAttribute("width","100%"),v.setAttribute("frameborder","0"),v.setAttribute("style","height:0px"),v.src="".concat(r.clickToPayUrl,"/click-to-pay.html?parentOrigin=").concat(r.parentOrigin,"&environment=").concat(r.config.environment,"&config=").concat(encodeURIComponent(JSON.stringify(b)));var I=document.createElement("iframe");I.setAttribute("width","0"),I.setAttribute("frameborder","0"),I.setAttribute("style","height:0px"),I.src="".concat(r.frameUrl,"/click-to-pay-encrypt.html?parentOrigin=").concat(r.parentOrigin,"&environment=").concat(r.config.environment,"&config=").concat(encodeURIComponent(JSON.stringify(b)));var O=new MessageChannel,C=!0;if(w.removeAll(),w.add("message",(e=>{switch(e.origin){case r.clickToPayOrigin:switch(e.data.type){case i.RESIZE:v.style.height=e.data.data.height>0?"".concat(e.data.data.height+48,"px"):"0px";break;case i.METHOD_CHANGE:var t=e.data.data.method||"card";(r.method!==t||C)&&(C=!1,r.method=t,h.publish(i.METHOD_CHANGE,e.data.data),_("Method changed",{method:r.method}),r.controller.contentWindow.postMessage({type:"method-change",channel:d},r.frameUrl),f(n,"card"===r.method),h.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,"card"===r.method));break;case i.CLICK_TO_PAY_INITIALIZED:h.publish(i.CLICK_TO_PAY_INITIALIZED,r.clickToPay),_("Click to Pay initialized",r.clickToPay),f(c,!1),h.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),f(r.clickToPay.element,!0),h.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case i.CLICK_TO_PAY_READY:h.publish(i.CLICK_TO_PAY_READY,e.data.data),_("Click to Pay ready"),f(c,!e.data.data.buyerExists),h.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!e.data.data.buyerExists),f(r.clickToPay.element,!0),h.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case i.CLICK_TO_PAY_SIGN_OUT:h.publish(i.CLICK_TO_PAY_SIGN_OUT),_("Click to pay signed out"),f(c,!0),h.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!0);break;case i.CLICK_TO_PAY_ERROR:h.publish(i.CLICK_TO_PAY_ERROR,e.data.data),_("Click to Pay error:",e.data.data),f(c,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(e.data.data.error)),h.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(e.data.data.error)),f(r.clickToPay.element,"UNKNOWN"!==e.data.data.error),h.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,"UNKNOWN"!==e.data.data.error);break;case i.CLICK_TO_PAY_CANCEL:h.publish(i.CLICK_TO_PAY_CANCEL,e.data.data),_("Click to Pay cancelled"),f(c,!0),h.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!0);break;case i.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD:h.publish(i.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD,e.data.data),f(c,!1),h.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),_("Click to Pay checkout with new card initiated");break;case a.REQUEST_PORT:v.contentWindow.postMessage({channel:d,type:a.TRANSFER_PORT},r.clickToPayOrigin,[O.port1])}break;case r.frameUrl:e.data.type===a.REQUEST_PORT&&I.contentWindow.postMessage({channel:d,type:a.TRANSFER_PORT},r.frameUrl,[O.port2])}})),null==t?void 0:t.consentCheckbox){var A="string"==typeof(null==t?void 0:t.consentCheckbox)?document.querySelector(null==t?void 0:t.consentCheckbox):null==t?void 0:t.consentCheckbox;r.method=A.checked?"click-to-pay":"card",_("Method changed",{method:r.method}),A.addEventListener("change",(e=>{var t=e.target;r.clickToPayConsent=t.checked})),w.add("message",(e=>{e.data.type===i.CLICK_TO_PAY_ERROR&&"UNKNOWN"===e.data.data.error&&(r.clickToPayConsent=!1,A.checked=!1)}))}if(null==t?void 0:t.learnMoreLink){var P="string"==typeof(null==t?void 0:t.learnMoreLink)?document.querySelector(null==t?void 0:t.learnMoreLink):null==t?void 0:t.learnMoreLink;P.style.visibility="hidden",w.add("message",(e=>{e.data.type===i.CLICK_TO_PAY_INITIALIZED&&(P.style.visibility="visible",P.addEventListener("click",(()=>{v.contentWindow.postMessage({type:"show-learn-more",channel:d},r.clickToPayOrigin)})))}))}return(e="string"==typeof e?document.querySelector(e):e).appendChild(v),e.appendChild(I),r.clickToPay.element=e,r.clickToPayController=v,r.clickToPay}g(s.PAYMENT_METHOD_ID_IN_USE,{method:"addClickToPay"})}))()}addEventListener(e,t){var r=this.type,n="".concat(this.constructor===E?"".concat(r,":"):"").concat(e);h.subscribe(n,t)}removeEventListener(e,t){var r=this.type,n="".concat(this.constructor===E?"".concat(r,":"):"").concat(e);h.unsubscribe(n,t)}submit(){var e=t=>{var r=[this.frameUrl,this.clickToPayOrigin].includes(t.origin),n=t.data.channel===d,o=["success","error"].includes(t.data.type);if(r&&n&&o){switch(t.data.type){case"success":h.publish(i.CARD_VAULT_SUCCESS),_("Payment method tokenized successfully");break;case"error":h.publish(i.CARD_VAULT_FAILURE,t.data),_("Failed to update checkout session",t.data.data)}window.removeEventListener("message",e)}};window.addEventListener("message",e),"click-to-pay"===this.method||"card"===this.method&&this.clickToPayController&&!0===this.clickToPayConsent?this.clickToPayController.contentWindow.postMessage({type:"submit",channel:d},this.clickToPayUrl):this.controller.contentWindow.postMessage({type:"submit",channel:d,data:{method:this.config.paymentMethodId?"id":"card"}},this.frameUrl)}setDebug(e){localStorage.setItem(l,String(e))}addFont(e){this.font=e.replace(/\s/g,"+")}constructor(e){var t;N(this,"config",void 0),N(this,"controller",void 0),N(this,"frameUrl",void 0),N(this,"apiUrl",void 0),N(this,"parentOrigin",void 0),N(this,"font",void 0),N(this,"cardNumber",void 0),N(this,"securityCode",void 0),N(this,"expiryDate",void 0),N(this,"method","card"),N(this,"clickToPay",void 0),N(this,"clickToPayController",void 0),N(this,"clickToPayUrl",void 0),N(this,"clickToPayOrigin",void 0),N(this,"environmentPath",void 0),N(this,"clickToPayConsent",!1),this.config=U({environment:"production"},e),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;var r=U({parentOrigin:this.parentOrigin,sessionId:this.config.sessionId,gr4vyId:this.config.gr4vyId,environment:this.config.environment},this.config.paymentMethodId?{paymentMethodId:this.config.paymentMethodId}:{});null===(t=document.body.querySelector("iframe#controller[src*=secure-fields]"))||void 0===t||t.remove(),this.controller=document.createElement("iframe"),this.controller.id="controller",this.controller.src=((e,t)=>"".concat(e,"?").concat(new URLSearchParams(t).toString()))("".concat(this.frameUrl,"/controller.html"),r),this.controller.style.position="absolute",this.controller.style.left="-9999999px",document.body.appendChild(this.controller),this.config.paymentMethodId&&(this.cardNumber=new E,this.expiryDate=new E),_("Initialized",j(U({},this.config),{version:Y.version,frameUrl:this.frameUrl,parentOrigin:this.parentOrigin})),w.removeAll(),w.add("message",(e=>{if(e.origin===this.frameUrl)switch(e.data.type){case"ready":var t=U({version:Y.version},this.config);h.publish(i.READY,t),_("Ready",t);break;case"form-change":h.publish(i.FORM_CHANGE,e.data.data),_("Form change",e.data.data)}}))}}return t}()}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gr4vy/secure-fields",
3
- "version": "1.17.0",
3
+ "version": "1.18.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
  "publishConfig": {
57
57
  "access": "public"
58
58
  },
59
- "gitHead": "866fb2e4de535d1b8ec7640c797fff5b487d1b8f"
59
+ "gitHead": "fee69721a94e90096d2df10fed0e635d0b14627b"
60
60
  }