@gr4vy/secure-fields 1.15.2 → 1.16.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,48 @@
1
+ # v1.16.0 (Mon Jan 22 2024)
2
+
3
+ #### 🚀 Enhancement
4
+
5
+ - task: implement show hide logic [#557](https://github.com/gr4vy/secure-fields/pull/557) ([@luca-gr4vy](https://github.com/luca-gr4vy))
6
+ - task: add Click to Pay sign-in method [#550](https://github.com/gr4vy/secure-fields/pull/550) ([@luca-gr4vy](https://github.com/luca-gr4vy))
7
+ - task: return Click to Pay instance [#549](https://github.com/gr4vy/secure-fields/pull/549) ([@luca-gr4vy](https://github.com/luca-gr4vy))
8
+
9
+ #### 🐛 Bug Fix
10
+
11
+ - fix: onReady handler not firing [#565](https://github.com/gr4vy/secure-fields/pull/565) ([@luca-gr4vy](https://github.com/luca-gr4vy))
12
+
13
+ #### 🏠 Internal
14
+
15
+ - chore(dev-deps): update dependency dotenv to ^16.3.2 [#563](https://github.com/gr4vy/secure-fields/pull/563) ([@renovate[bot]](https://github.com/renovate[bot]))
16
+ - chore(dev-deps): update dependency css-loader to ^6.9.1 [#562](https://github.com/gr4vy/secure-fields/pull/562) ([@renovate[bot]](https://github.com/renovate[bot]))
17
+ - chore(dev-deps): update dependency typedoc-plugin-missing-exports to ^2.2.0 [#556](https://github.com/gr4vy/secure-fields/pull/556) ([@renovate[bot]](https://github.com/renovate[bot]))
18
+ - chore(dev-deps): update dependency css-loader to ^6.9.0 [#555](https://github.com/gr4vy/secure-fields/pull/555) ([@renovate[bot]](https://github.com/renovate[bot]))
19
+ - chore(dev-deps): update dependency style-loader to ^3.3.4 [#554](https://github.com/gr4vy/secure-fields/pull/554) ([@renovate[bot]](https://github.com/renovate[bot]))
20
+
21
+ #### Authors: 2
22
+
23
+ - [@renovate[bot]](https://github.com/renovate[bot])
24
+ - Luca Allievi ([@luca-gr4vy](https://github.com/luca-gr4vy))
25
+
26
+ ---
27
+
28
+ # v1.15.3 (Thu Jan 11 2024)
29
+
30
+ #### 🐛 Bug Fix
31
+
32
+ - fix: auto-fill amex cuts off security code / allowed digits when paymentMethodId is set [#547](https://github.com/gr4vy/secure-fields/pull/547) ([@luca-gr4vy](https://github.com/luca-gr4vy))
33
+
34
+ #### 🏠 Internal
35
+
36
+ - chore(dev-deps): update dependency typedoc to ^0.25.7 [#546](https://github.com/gr4vy/secure-fields/pull/546) ([@renovate[bot]](https://github.com/renovate[bot]))
37
+ - chore(dev-deps): update dependency csstype to ^3.1.3 [#530](https://github.com/gr4vy/secure-fields/pull/530) ([@renovate[bot]](https://github.com/renovate[bot]))
38
+
39
+ #### Authors: 2
40
+
41
+ - [@renovate[bot]](https://github.com/renovate[bot])
42
+ - Luca Allievi ([@luca-gr4vy](https://github.com/luca-gr4vy))
43
+
44
+ ---
45
+
1
46
  # v1.15.1 (Thu Dec 07 2023)
2
47
 
3
48
  #### 🐛 Bug Fix
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 { CombinedEvents, Config, Field } from './types';
3
+ import type { ClickToPayInstance, ClickToPayOptions, CombinedEvents, Config, Field } from './types';
4
4
  declare global {
5
5
  interface Window {
6
6
  SECURE_FIELDS_FRAME_URL?: string;
@@ -18,6 +18,7 @@ declare class SecureFields {
18
18
  securityCode: SecureInput;
19
19
  expiryDate: SecureInput;
20
20
  method: 'card' | 'click-to-pay';
21
+ clickToPay?: ClickToPayInstance;
21
22
  clickToPayController?: HTMLIFrameElement;
22
23
  clickToPayUrl?: string;
23
24
  clickToPayOrigin?: string;
@@ -39,22 +40,7 @@ declare class SecureFields {
39
40
  addCardNumberField(element: string | HTMLElement, options?: Omit<Field, 'element' | 'type'>): SecureInput;
40
41
  addSecurityCodeField(element: string | HTMLElement, options?: Omit<Field, 'element' | 'type'>): SecureInput;
41
42
  addExpiryDateField(element: string | HTMLElement, options?: Omit<Field, 'element' | 'type'>): SecureInput;
42
- addClickToPay(element: string | HTMLElement, options?: {
43
- srcDpaId?: string;
44
- dpaName?: string;
45
- cardBrands: Array<'mastercard' | 'maestro' | 'visa' | 'amex' | 'discover'>;
46
- dpaLocale: string;
47
- cardForm?: string | HTMLElement;
48
- consentCheckbox?: string | HTMLElement;
49
- learnMoreLink?: string | HTMLElement;
50
- } & ({
51
- email: string;
52
- } | {
53
- mobileNumber: {
54
- countryCode: string;
55
- phoneNumber: string;
56
- };
57
- })): Promise<void>;
43
+ addClickToPay(element: string | HTMLElement, options?: ClickToPayOptions): Promise<ClickToPayInstance>;
58
44
  addEventListener(event: CombinedEvents, callback: (...args: any[]) => void): void;
59
45
  removeEventListener(event: CombinedEvents, callback: (...args: any[]) => void): void;
60
46
  submit(): void;
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 j},SecureInput:function(){return A}});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"}(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"];function f(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function m(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){f(e,t,r[t])}))}return e}var b={debug:!1,level:"log"},v=(e,t,r)=>{var n=m({},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=m({},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))},O=e=>(e!=e.toLowerCase()&&(e=e.replace(/[A-Z]/g,(e=>"-"+e.toLowerCase()))),e);function _(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 _(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)?_(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=O(s).replace(/^-/,""),n.push(["--".concat(r).concat(s),l])),n}),[])};return e(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})};function P(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function w(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){P(e,t,r[t])}))}return e}function E(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 A{_postMessage(e){this.frame.contentWindow.postMessage(w({channel:d},e),this.frameUrl)}update(e){if(this.frameUrl){this.options=w({},this.options,e);var t=C(w({},this.options.styles,e.styles)),r=E(w({},this.options,e),{styles:t});this._postMessage({type:"update",data:E(w({},r),{styles:t})}),v("Updated field",this.options)}}setPlaceholder(e){this.update({placeholder:e})}setStyles(e){this.update({styles:e})}constructor(e){if(P(this,"frameUrl",void 0),P(this,"parentOrigin",void 0),P(this,"frame",void 0),P(this,"type",void 0),P(this,"options",void 0),P(this,"addEventListener",void 0),P(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:E(w({},this.options),{styles:a})}),v("Added field",this.options)}}}}function I(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 T=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 I(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)?I(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 k(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 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 L(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 U(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 j{static get Events(){return i}static get version(){return"#b78007fa72f0957475d4356cf72d862d4de34e9e"}_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(O(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 A({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:U(L({label:"Card number"},t),{type:"number"})})),this._addField(e,this.cardNumber)}addSecurityCodeField(e,t){return this.securityCode||(this.securityCode=new A({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:U(L({label:"Security code"},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 A({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:U(L({label:"Expiry date"},t),{type:"expiryDate"})})),this._addField(e,this.expiryDate)}addClickToPay(e,t){var r,n=this;return(r=function*(){if(n.config.paymentMethodId)g(s.PAYMENT_METHOD_ID_IN_USE,{method:"addClickToPay"});else{if(!(null==t?void 0:t.srcDpaId)||!(null==t?void 0:t.dpaName))try{var r=n.apiUrl||function(e){return"https://api.".concat("sandbox"===(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"production")?"sandbox.":"").concat(e,".gr4vy.app")}(n.config.gr4vyId,n.config.environment),c=yield function(e){return o.apply(this,arguments)}({apiBaseUrl:r,checkoutSessionId:n.config.sessionId}),l=c.srcDpaId,u=c.dpaName;t.srcDpaId=l,t.dpaName=u}catch(e){return v(e.message),void h.publish(i.CLICK_TO_PAY_UNABLE_TO_LOAD_DPA)}n.clickToPayUrl=window.CLICK_TO_PAY_FRAME_URL||"https://click-to-pay.".concat(n.environmentPath).concat(n.config.gr4vyId,".gr4vy.app"),n.parentOrigin=window.location.origin,n.clickToPayOrigin=new URL(n.clickToPayUrl).origin,t.cardForm;var p=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}(t,["cardForm"]),y=L({gr4vyId:n.config.gr4vyId,environment:n.config.environment,sessionId:n.config.sessionId},p),f=document.createElement("iframe");f.setAttribute("width","100%"),f.setAttribute("frameborder","0"),f.setAttribute("style","height:0px"),f.src="".concat(n.clickToPayUrl,"/click-to-pay.html?parentOrigin=").concat(n.parentOrigin,"&environment=").concat(n.config.environment,"&config=").concat(encodeURIComponent(JSON.stringify(y)));var m=document.createElement("iframe");m.setAttribute("width","0"),m.setAttribute("frameborder","0"),m.setAttribute("style","height:0px"),m.src="".concat(n.frameUrl,"/click-to-pay-encrypt.html?parentOrigin=").concat(n.parentOrigin,"&environment=").concat(n.config.environment,"&config=").concat(encodeURIComponent(JSON.stringify(y)));var b=new MessageChannel,O=!0;if(T.removeAll(),T.add("message",(e=>{switch(e.origin){case n.clickToPayOrigin:switch(e.data.type){case i.RESIZE:f.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";(n.method!==t||O)&&(O=!1,n.method=t,h.publish(i.METHOD_CHANGE,e.data.data),v("Method changed",{method:n.method}),n.controller.contentWindow.postMessage({type:"method-change",channel:d},n.frameUrl));break;case i.CLICK_TO_PAY_INITIALIZED:h.publish(i.CLICK_TO_PAY_INITIALIZED),v("Click to Pay initialized");break;case i.CLICK_TO_PAY_READY:h.publish(i.CLICK_TO_PAY_READY,e.data.data),v("Click to Pay ready");break;case i.CLICK_TO_PAY_SIGN_OUT:h.publish(i.CLICK_TO_PAY_SIGN_OUT),v("Click to pay signed out");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);break;case i.CLICK_TO_PAY_CANCEL:h.publish(i.CLICK_TO_PAY_CANCEL,e.data.data),v("Click to Pay cancelled");break;case i.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD:h.publish(i.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD,e.data.data),v("Click to Pay checkout with new card initiated");break;case a.REQUEST_PORT:f.contentWindow.postMessage({channel:d,type:a.TRANSFER_PORT},n.clickToPayOrigin,[b.port1])}break;case n.frameUrl:e.data.type===a.REQUEST_PORT&&m.contentWindow.postMessage({channel:d,type:a.TRANSFER_PORT},n.frameUrl,[b.port2])}})),null==t?void 0:t.consentCheckbox){var _="string"==typeof(null==t?void 0:t.consentCheckbox)?document.querySelector(null==t?void 0:t.consentCheckbox):null==t?void 0:t.consentCheckbox;n.method=_.checked?"click-to-pay":"card",v("Method changed",{method:n.method}),_.addEventListener("change",(e=>{var t=e.target;n.clickToPayConsent=t.checked})),T.add("message",(e=>{e.data.type===i.CLICK_TO_PAY_ERROR&&"UNKNOWN"===e.data.data.error&&(n.clickToPayConsent=!1,_.checked=!1)}))}if(null==t?void 0:t.learnMoreLink){var C="string"==typeof(null==t?void 0:t.learnMoreLink)?document.querySelector(null==t?void 0:t.learnMoreLink):null==t?void 0:t.learnMoreLink;C.style.visibility="hidden",T.add("message",(e=>{e.data.type===i.CLICK_TO_PAY_INITIALIZED&&(C.style.visibility="visible",C.addEventListener("click",(()=>{f.contentWindow.postMessage({type:"show-learn-more",channel:d},n.clickToPayOrigin)})))}))}(e="string"==typeof e?document.querySelector(e):e).appendChild(f),e.appendChild(m),n.clickToPayController=f}},function(){var e=this,t=arguments;return new Promise((function(n,o){var i=r.apply(e,t);function a(e){k(i,n,o,a,c,"next",e)}function c(e){k(i,n,o,a,c,"throw",e)}a(void 0)}))})()}addEventListener(e,t){var r=this.type,n="".concat(this.constructor===A?"".concat(r,":"):"").concat(e);h.subscribe(n,t)}removeEventListener(e,t){var r=this.type,n="".concat(this.constructor===A?"".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){S(this,"config",void 0),S(this,"controller",void 0),S(this,"frameUrl",void 0),S(this,"apiUrl",void 0),S(this,"parentOrigin",void 0),S(this,"font",void 0),S(this,"cardNumber",void 0),S(this,"securityCode",void 0),S(this,"expiryDate",void 0),S(this,"method","card"),S(this,"clickToPayController",void 0),S(this,"clickToPayUrl",void 0),S(this,"clickToPayOrigin",void 0),S(this,"environmentPath",void 0),S(this,"clickToPayConsent",!1),this.config=L({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=L({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 A,this.expiryDate=new A),window.onload=()=>{h.publish(i.READY,L({version:j.version},this.config))},v("Initialized",U(L({},this.config),{version:j.version,frameUrl:this.frameUrl,parentOrigin:this.parentOrigin})),window.addEventListener("message",(e=>{e.origin===this.frameUrl&&"form-change"===e.data.type&&(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 R},SecureInput:function(){return A}});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"}(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"},g=(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||{})},O=(e,t,r)=>{var n,o;g(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))},_=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 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 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}}(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=_(s).replace(/^-/,""),n.push(["--".concat(r).concat(s),l])),n}),[])};return e(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})};function E(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function I(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){E(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,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 A{_postMessage(e){this.frame.contentWindow.postMessage(I({channel:d},e),this.frameUrl)}update(e){if(this.frameUrl){this.options=I({},this.options,e);var t=C(I({},this.options.styles,e.styles)),r=w(I({},this.options,e),{styles:t});this._postMessage({type:"update",data:w(I({},r),{styles:t})}),g("Updated field",this.options)}}setPlaceholder(e){this.update({placeholder:e})}setStyles(e){this.update({styles:e})}constructor(e){if(E(this,"frameUrl",void 0),E(this,"parentOrigin",void 0),E(this,"frame",void 0),E(this,"type",void 0),E(this,"options",void 0),E(this,"addEventListener",void 0),E(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:w(I({},this.options),{styles:a})}),g("Added field",this.options)}}}}function T(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 k=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 T(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)?T(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 L(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 U(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 j(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){U(e,t,r[t])}))}return e}function N(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 R{static get Events(){return i}static get version(){return"#dade6a11464893d5f205102ccf85f5d1dfce5b9d"}_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(_(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),g("Field blurred",e.data.data);break;case"focus":h.publish("".concat(t.type,":focus"),e.data.data),o.setAttribute(c.FOCUSED,""),g("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),g("Field input changed",e.data.data)}})),t.addEventListener=this.addEventListener,t.removeEventListener=this.removeEventListener,t}addCardNumberField(e,t){return this.config.paymentMethodId&&O(s.PAYMENT_METHOD_ID_IN_USE,{method:"addCardNumberField"}),this.cardNumber||(this.cardNumber=new A({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:N(j({label:"Card number"},t),{type:"number"})})),this._addField(e,this.cardNumber)}addSecurityCodeField(e,t){return this.securityCode||(this.securityCode=new A({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:N(j({label:"Security code"},this.config.paymentMethodId?{lengths:[3,4]}:{},t),{type:"securityCode"})})),this._addField(e,this.securityCode)}addExpiryDateField(e,t){return this.config.paymentMethodId&&O(s.PAYMENT_METHOD_ID_IN_USE,{method:"addExpiryDateField"}),this.expiryDate||(this.expiryDate=new A({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:N(j({label:"Expiry date"},t),{type:"expiryDate"})})),this._addField(e,this.expiryDate)}addClickToPay(e,t){var r=this;return L((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=L((function*(e){var t=e.email,o=e.mobileNumber,i=r.clickToPay,a=i.element,s=i.options;delete s.email,delete s.mobileNumber,a.innerHTML="",f(c,!1),f(n,!1),yield r.addClickToPay(a,j({},s,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 g(e.message),h.publish(i.CLICK_TO_PAY_UNABLE_TO_LOAD_DPA),f(n,!0),void f(r.clickToPay.element,!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=j({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 _=document.createElement("iframe");_.setAttribute("width","0"),_.setAttribute("frameborder","0"),_.setAttribute("style","height:0px"),_.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 P=new MessageChannel,C=!0;if(k.removeAll(),k.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),g("Method changed",{method:r.method}),r.controller.contentWindow.postMessage({type:"method-change",channel:d},r.frameUrl),f(n,"card"===r.method));break;case i.CLICK_TO_PAY_INITIALIZED:h.publish(i.CLICK_TO_PAY_INITIALIZED,r.clickToPay),g("Click to Pay initialized",r.clickToPay),f(c,!1),f(r.clickToPay.element,!0);break;case i.CLICK_TO_PAY_READY:h.publish(i.CLICK_TO_PAY_READY,e.data.data),g("Click to Pay ready"),f(c,!e.data.data.buyerExists),f(r.clickToPay.element,!0);break;case i.CLICK_TO_PAY_SIGN_OUT:h.publish(i.CLICK_TO_PAY_SIGN_OUT),g("Click to pay signed out"),f(c,!0);break;case i.CLICK_TO_PAY_ERROR:h.publish(i.CLICK_TO_PAY_ERROR,e.data.data),g("Click to Pay error:",e.data.data),f(c,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(e.data.data.error)),f(r.clickToPay.element,"UNKNOWN"!==e.data.data.error);break;case i.CLICK_TO_PAY_CANCEL:h.publish(i.CLICK_TO_PAY_CANCEL,e.data.data),g("Click to Pay cancelled"),f(c,!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),g("Click to Pay checkout with new card initiated");break;case a.REQUEST_PORT:v.contentWindow.postMessage({channel:d,type:a.TRANSFER_PORT},r.clickToPayOrigin,[P.port1])}break;case r.frameUrl:e.data.type===a.REQUEST_PORT&&_.contentWindow.postMessage({channel:d,type:a.TRANSFER_PORT},r.frameUrl,[P.port2])}})),null==t?void 0:t.consentCheckbox){var E="string"==typeof(null==t?void 0:t.consentCheckbox)?document.querySelector(null==t?void 0:t.consentCheckbox):null==t?void 0:t.consentCheckbox;r.method=E.checked?"click-to-pay":"card",g("Method changed",{method:r.method}),E.addEventListener("change",(e=>{var t=e.target;r.clickToPayConsent=t.checked})),k.add("message",(e=>{e.data.type===i.CLICK_TO_PAY_ERROR&&"UNKNOWN"===e.data.data.error&&(r.clickToPayConsent=!1,E.checked=!1)}))}if(null==t?void 0:t.learnMoreLink){var I="string"==typeof(null==t?void 0:t.learnMoreLink)?document.querySelector(null==t?void 0:t.learnMoreLink):null==t?void 0:t.learnMoreLink;I.style.visibility="hidden",k.add("message",(e=>{e.data.type===i.CLICK_TO_PAY_INITIALIZED&&(I.style.visibility="visible",I.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(_),r.clickToPay.element=e,r.clickToPayController=v,r.clickToPay}O(s.PAYMENT_METHOD_ID_IN_USE,{method:"addClickToPay"})}))()}addEventListener(e,t){var r=this.type,n="".concat(this.constructor===A?"".concat(r,":"):"").concat(e);h.subscribe(n,t)}removeEventListener(e,t){var r=this.type,n="".concat(this.constructor===A?"".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),g("Payment method tokenized successfully");break;case"error":h.publish(i.CARD_VAULT_FAILURE,t.data),g("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){U(this,"config",void 0),U(this,"controller",void 0),U(this,"frameUrl",void 0),U(this,"apiUrl",void 0),U(this,"parentOrigin",void 0),U(this,"font",void 0),U(this,"cardNumber",void 0),U(this,"securityCode",void 0),U(this,"expiryDate",void 0),U(this,"method","card"),U(this,"clickToPay",void 0),U(this,"clickToPayController",void 0),U(this,"clickToPayUrl",void 0),U(this,"clickToPayOrigin",void 0),U(this,"environmentPath",void 0),U(this,"clickToPayConsent",!1),this.config=j({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=j({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 A,this.expiryDate=new A),g("Initialized",N(j({},this.config),{version:R.version,frameUrl:this.frameUrl,parentOrigin:this.parentOrigin})),window.addEventListener("message",(e=>{if(e.origin===this.frameUrl)switch(e.data.type){case"ready":var t=j({version:R.version},this.config);h.publish(i.READY,t),g("Ready",t);break;case"form-change":h.publish(i.FORM_CHANGE,e.data.data),g("Form change",e.data.data)}}))}}return t}()}));
package/lib/types.d.ts CHANGED
@@ -18,6 +18,8 @@ export type Field = {
18
18
  placeholder?: string;
19
19
  styles?: Styles;
20
20
  label?: string;
21
+ lengths?: Array<number>;
22
+ size?: number;
21
23
  };
22
24
  export type FieldEvent = {
23
25
  type: keyof HTMLElementEventMap;
@@ -57,3 +59,23 @@ export type FormChangeEventData = {
57
59
  };
58
60
  complete: boolean;
59
61
  };
62
+ export type ClickToPayOptions = {
63
+ srcDpaId?: string;
64
+ dpaName?: string;
65
+ cardBrands: Array<'mastercard' | 'maestro' | 'visa' | 'amex' | 'discover'>;
66
+ dpaLocale: string;
67
+ cardForm?: string | HTMLElement;
68
+ signIn?: string | HTMLElement;
69
+ consentCheckbox?: string | HTMLElement;
70
+ learnMoreLink?: string | HTMLElement;
71
+ email?: string;
72
+ mobileNumber?: {
73
+ countryCode: string;
74
+ phoneNumber: string;
75
+ };
76
+ };
77
+ export type ClickToPayInstance = {
78
+ element: HTMLElement;
79
+ options: ClickToPayOptions;
80
+ signIn: ({ email, mobileNumber, }: Partial<Pick<ClickToPayOptions, 'email' | 'mobileNumber'>>) => Promise<void>;
81
+ };
@@ -0,0 +1 @@
1
+ export declare const setVisibility: (element: HTMLElement, condition: boolean) => "" | "none" | "block";
@@ -1,4 +1,5 @@
1
1
  export * from './copy-element-attributes';
2
+ export * from './dom';
2
3
  export * from './is';
3
4
  export * from './logger';
4
5
  export * from './strings';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gr4vy/secure-fields",
3
- "version": "1.15.2",
3
+ "version": "1.16.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",
@@ -42,19 +42,19 @@
42
42
  "watch": "webpack watch --config webpack.prod.js"
43
43
  },
44
44
  "devDependencies": {
45
- "css-loader": "^6.8.1",
46
- "csstype": "^3.1.2",
47
- "dotenv": "^16.3.1",
45
+ "css-loader": "^6.9.1",
46
+ "csstype": "^3.1.3",
47
+ "dotenv": "^16.3.2",
48
48
  "msw": "^1.3.2",
49
49
  "node-fetch": "^2.7.0",
50
- "style-loader": "^3.3.3",
50
+ "style-loader": "^3.3.4",
51
51
  "ts-patch": "^2.1.0",
52
- "typedoc": "^0.25.4",
53
- "typedoc-plugin-missing-exports": "^2.1.0",
52
+ "typedoc": "^0.25.7",
53
+ "typedoc-plugin-missing-exports": "^2.2.0",
54
54
  "typescript-transform-paths": "^3.4.6"
55
55
  },
56
56
  "publishConfig": {
57
57
  "access": "public"
58
58
  },
59
- "gitHead": "b78007fa72f0957475d4356cf72d862d4de34e9e"
59
+ "gitHead": "dade6a11464893d5f205102ccf85f5d1dfce5b9d"
60
60
  }