@transact-open-ux/core
Version:
Provides utility methods to integrate with the Transact Platform
3 lines (2 loc) • 7.33 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("fast-xml-parser"),require("pako"),require("axios")):"function"==typeof define&&define.amd?define(["exports","fast-xml-parser","pako","axios"],t):t((e=e||self)["transact-open-ux-core"]={},e.fastXmlParser,e.pako,e.axios)}(this,function(e,t,r,o){"use strict";function n(e,t,r,o){return new(r||(r=Promise))(function(n,a){function i(e){try{c(o.next(e))}catch(e){a(e)}}function s(e){try{c(o.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):new r(function(t){t(e.value)}).then(i,s)}c((o=o.apply(e,t||[])).next())})}r=r&&r.hasOwnProperty("default")?r.default:r,o=o&&o.hasOwnProperty("default")?o.default:o;const a={'"':""","&":"&","'":"'","<":"<",">":">"},i={"&":"&","'":"'",">":">","<":"<",""":'"'},s=(e,r=!1)=>{return new t.j2xParser({format:r,ignoreAttributes:!0,indentBy:" ",supressEmptyNode:!0,tagValueProcessor:e=>(e=>null==e?"":e.toString().replace(/([&"'<>])/g,(e,t)=>a[t]))(e)}).parse(e)},c={decodeHTMLchar:!0,tagValueProcessor:e=>(e=>null==e?"":e.replace(/("|&|'|<|>)/g,(e,t)=>i[t]))(e)},d=e=>{const r=t.parse(e,c);return r.hasOwnProperty("AvokaSmartForm")?r.AvokaSmartForm:r},l=e=>{return Array.prototype.map.call(e,e=>String.fromCharCode(e)).join("")},m=e=>{const t=new Uint8Array(e.length);return Array.prototype.forEach.call(e,(e,r)=>{t[r]=e.charCodeAt(0)}),t},u=e=>{const t=(e=>{return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(e,t)=>String.fromCharCode(parseInt(t,16)))})(e);return m(t)},p=e=>{return(e=>{const t=e.replace(/(.)/g,(e,t)=>{let r=t.charCodeAt(0).toString(16).toUpperCase();return r.length<2&&(r=`0${r}`),`%${r}`});return decodeURIComponent(t)})(l(e))},f=(()=>"object"==typeof document&&"string"==typeof document.cookie)(),y=e=>f?decodeURIComponent(document.cookie.replace(new RegExp(`(?:(?:^|.*;)\\s*${encodeURIComponent(e).replace(/[-.+*]/g,"\\$&")}\\s*\\=\\s*([^;]*).*$)|^.*$`),"$1"))||void 0:null,h=(e="",t,r)=>{const o=e.split(".");let n=t,a=o.shift();for(;a;){if(void 0===n)return t;0===o.length?n[a]=r:(Object.prototype.hasOwnProperty.call(n,a)||(n[a]={}),n=n[a]),a=o.shift()}return t},w=e=>{"string"==typeof e&&(window.onbeforeunload=null,window.location.replace(e))},v=()=>{const e={};return window&&window.location&&window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,(t,r,o)=>(e[r]=o,o)),e},g=e=>v()[e]||null,b=(e,t)=>JSON.stringify(e,(e,t)=>{if(!e.match(/^\$/))return t},!!t&&"\t"),C=(e={})=>{Object.keys(e).forEach(t=>{void 0!==e[t]&&null!==e[t]||delete e[t]})},A=window.crypto&&(window.crypto.subtle||window.crypto.webkitSubtle),S=window.msCrypto&&window.msCrypto.subtle,P=A||S,E=(e,t,r)=>{const o=e;S?(o.onerror=r,o.oncomplete=e=>{const r=e.target.result;t(r)}):A&&o.then(e=>{t(e)}).catch(r)},k=(e,t)=>t?P?new Promise((o,n)=>{try{const a=P.generateKey({length:128,name:"AES-CBC"},!0,["encrypt","decrypt"]);E(a,a=>{const i=P.exportKey("raw",a);E(i,i=>{const s=u(e),c=r.deflate(s),d=u(t.substring(16)),m=P.encrypt({iv:d,name:"AES-CBC"},a,c);E(m,e=>{const r=u(t),n=new Uint8Array(r.byteLength+i.byteLength+e.byteLength);n.set(new Uint8Array(r),0),n.set(new Uint8Array(i),r.byteLength),n.set(new Uint8Array(e),r.byteLength+i.byteLength);const a=(e=>{const t=l(e);return btoa(t)})(n);o(a)},n)},n)},n)}catch(e){n(e)}}):e:Promise.reject(new Error("requestKey not found.")),x=e=>{if(!P)throw new Error("Browser does not support data encryption!");return new Promise((t,o)=>{try{const n=(e=>{const t=atob(e);return m(t)})(e),a=n.subarray(16,32),i=n.subarray(32,48),s=n.subarray(48),c=P.importKey("raw",i,"AES-CBC",!1,["decrypt"]);E(c,e=>{const n=P.decrypt({iv:a,name:"AES-CBC"},e,s);E(n,e=>{const o=new Uint8Array(e),n=r.inflate(o),a=p(n);t(a)},o)},o)}catch(e){o(e)}})};const U="development"===process.env.NODE_ENV,F=window.openUxConfig||{};let{endpoint:O="http://localhost:9999/app",requestKey:j=y("requestKey")}=F;const q=!!F.isReceipt;let N,R=!U;const K=(e,t)=>s({AvokaSmartForm:JSON.parse(b(e))},t);const D=()=>!!g("trackingCode");function I(e,t,r,a,i){return n(this,void 0,void 0,function*(){t&&C(t),r&&C(r);const s={options:t,parameters:r,requestKey:j,type:e},c=JSON.stringify(s),l={};a&&(l.fileAttachment=a);try{"object"==typeof i&&(l.formData=N?yield k(K(i),j):K(i)),l.command=R?yield k(c,j):c;const e=yield function(e,t,r){return n(this,void 0,void 0,function*(){const n=new FormData,a="string"==typeof r?JSON.parse(r):r;Object.keys(a).forEach(e=>{n.append(e,a[e])});try{return(yield o({data:n,method:e,url:t})).data}catch(e){const t=e.response.data;return Promise.reject(t)}})}("post",O,l),{formData:t,revisionNumber:r,redirectUrl:a}=e;return t&&(e.formData=yield function(e){return n(this,void 0,void 0,function*(){const t="string"==typeof e&&-1===e.indexOf("<")&&-1===e.indexOf("%"),r=t?yield x(e):e;return R&&!t&&(R=!1),"boolean"!=typeof N&&t&&(N=!0),d(r.trim())})}(t)),a&&w(a),void 0!==r&&h("SFMData.SystemProfile.RevisionNumber",e.formData||i,r),e}catch(e){return Promise.reject(e)}})}const L=()=>I("formInit");e.formError=(e,t)=>I("formError",{context:t,stacktrace:e},void 0,void 0),e.formFunction=(e,t,r,o)=>I("formFunction",{milestone:r,serviceName:e,serviceVersion:t},o),e.formIneligible=(e,t)=>I("formIneligible",{milestone:t},void 0,void 0,e),e.formInit=L,e.formLoad=function(e,t,r){return n(this,void 0,void 0,function*(){try{const o=yield I("formLoad",{saveChallengeAnswer:e,trackingCode:t},r),{error:n,validationErrors:a}=o;if(!a&&!n&&("function"==typeof window.callPhantom&&setTimeout(()=>{window.callPhantom({completed:!0})},4e3),q||L().catch(e=>e),t&&D()&&"function"==typeof window.history.replaceState)){const e=window.location.href.split("?trackingCode")[0];window.history.replaceState("","",e)}return o}catch(e){return e}})},e.formNew=function(e,t,r,o){return n(this,void 0,void 0,function*(){if(!e)throw new Error("The requestUrl is required, i.e. https://apps.mybank.com/web-plugin/app/");if(!t&&!o)throw new Error("You must supply a formCode OR a trackingCode");try{O=e,j&&(j=void 0);const n=yield I("formNew",{formCode:t,formVersion:r,trackingCode:o},void 0,void 0,void 0);return j=n.requestKey,n}catch(e){return Promise.reject(e)}})},e.formStart=(e,t)=>I("formStart",{milestone:t},void 0,void 0,e),e.formUpdate=(e,t,r,o,n,a,i,s,c)=>I("formUpdate",{addAttachmentFile:s,addAttachmentManually:a,emailAddress:o,milestone:n,removeAttachment:i,sendEmailSavedForm:r,userSaved:t},void 0,c,e),e.getDataFromPath=(e="",t)=>{const r=e&&e.split(".");let o,n=t;for(;r&&r.length;)if(void 0===(n=n[o=r.shift()]))return n;return n},e.getDataXml=K,e.getUrlQueryParam=g,e.getUrlQueryParams=v,e.isReceipt=q,e.isSaveChallengeRequired=D,e.jsonify=b,e.makeAddAttachmentFile=(e,t,r,o,n,a)=>({attachmentKey:t,attachmentName:r,description:o,fileTypes:a,maxSize:n,path:e}),e.makeAddAttachmentManually=(e,t,r)=>({attachmentKey:t,attachmentName:r,path:e}),e.makeRemoveAttachment=e=>({attachmentKey:e}),e.redirect=w,e.setDataFromPath=h,e.userCancel=(e,t)=>I("userCancel",{milestone:t},void 0,void 0,e),e.userSave=(e,t,r,o,n)=>I("userSave",{emailAddress:o,milestone:n,sendEmailSavedForm:t,sendEmailShareForm:r},void 0,void 0,e),e.userSubmit=(e,t,r,o)=>I("userSubmit",{emailAddress:r,milestone:o,sendEmailFormReceipt:t},void 0,void 0,e),Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=open-ux-core.min.js.map