@nuvei-connect/nc-websdk 1.0.8 → 1.0.9
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/dist/cdn-index.js
CHANGED
|
@@ -310,14 +310,14 @@
|
|
|
310
310
|
local: "http://localhost:4000",
|
|
311
311
|
dev3: "https://dev3-non-pci.eastus.cloudapp.azure.com",
|
|
312
312
|
dev2: "https://dev2-non-pci.eastus.cloudapp.azure.com",
|
|
313
|
-
|
|
313
|
+
uat: "https://ignite-preprod.nuvei.com",
|
|
314
314
|
prod: "https://ignite.nuvei.com"
|
|
315
315
|
};
|
|
316
316
|
var DOCUMENT_UTILITY_BASE_URLS = {
|
|
317
317
|
local: "http://localhost:5000",
|
|
318
318
|
dev3: "https://dev3-non-pci.eastus.cloudapp.azure.com",
|
|
319
319
|
dev2: "https://dev2-non-pci.eastus.cloudapp.azure.com",
|
|
320
|
-
|
|
320
|
+
uat: "https://ignite-preprod.nuvei.com",
|
|
321
321
|
prod: "https://ignite.nuvei.com"
|
|
322
322
|
};
|
|
323
323
|
var MODULE_PATHS = {
|
package/dist/cdn-index.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";(()=>{var
|
|
1
|
+
"use strict";(()=>{var U=Object.defineProperty,P=Object.defineProperties;var _=Object.getOwnPropertyDescriptors;var w=Object.getOwnPropertySymbols;var L=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable;var C=(r,e,s)=>e in r?U(r,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[e]=s,f=(r,e)=>{for(var s in e||(e={}))L.call(e,s)&&C(r,s,e[s]);if(w)for(var s of w(e))F.call(e,s)&&C(r,s,e[s]);return r},T=(r,e)=>P(r,_(e));var u=(r,e,s)=>new Promise((t,n)=>{var i=c=>{try{o(s.next(c))}catch(l){n(l)}},a=c=>{try{o(s.throw(c))}catch(l){n(l)}},o=c=>c.done?t(c.value):Promise.resolve(c.value).then(i,a);o((s=s.apply(r,e)).next())});var p=(t=>(t.ONBOARDING_PARTNER="ONBOARDING_PARTNER",t.ONBOARDING_MERCHANT="ONBOARDING_MERCHANT",t.DOC_UTILITY="DOC_UTILITY",t))(p||{});var D=r=>{if(r&&typeof r=="object"){let e=Object.keys(r),s=e.length,t=e.length?"?":"";return e.forEach((n,i)=>{let a=i+1,o=r[n],c=r[e[a]];if(a<s&&I(o)){let l=t+n+"="+o;I(c)?t=l+"&":t=l}else I(o)&&(t=t+n+"="+o)}),t}return""},I=r=>!(r==null||r===""||typeof r=="number"&&Number.isNaN(r)||typeof r=="string"&&r.trim()===""),y=r=>{let e=t=>t!=null&&!(Array.isArray(t)&&t.length===0)&&!(typeof t=="object"&&Object.keys(t).length===0)&&!(typeof t=="string"&&t.trim()==="");if(!r||typeof r!="object")return;let s={};for(let t in r)if(r.hasOwnProperty(t)){let n=r[t];if(e(n))if(Array.isArray(n)){let i=n.filter(a=>e(a)).map(y).filter(a=>e(a));i.length&&(s[t]=i)}else if(typeof n=="object"){let i=y(n);e(i)&&(s[t]=i)}else s[t]=n}return Object.keys(s).length?s:void 0};var K={isSuccess:!1,accessToken:"",accessTokenExpiry:"",refreshToken:"",refreshTokenExpiry:""},W={isSuccess:!1,accessToken:"",accessTokenExpiry:""},g=class{constructor(e,s){this.currentAccessToken="";this.fetchClientSession=()=>u(this,null,function*(){let e=this.getAuthUrl("/auth/micro-frontend/tokens"),s=y({modules:[{name:this.getAuthModuleName()}],referenceId:this.authConfig.referenceId});try{let t=yield fetch(e,{method:"POST",headers:this.getHeaders(),body:JSON.stringify(s)}),n=yield this.parseJsonResponse(t,e,"Frontend AccessToken");return this.currentAccessToken=n.accessToken||"",T(f(f({},K),n),{isSuccess:!0})}catch(t){throw this.createAuthError("Frontend AccessToken",e,t)}});this.refreshClientSession=e=>u(this,null,function*(){let s=this.getAuthUrl("/auth/micro-frontend/tokens/refresh");try{let t=yield fetch(s,{method:"POST",headers:this.getHeaders(),body:JSON.stringify(y(e))}),n=yield this.parseJsonResponse(t,s,"Frontend AccessToken Refresh");return this.currentAccessToken=n.accessToken||this.currentAccessToken,T(f(f({},W),n),{isSuccess:!0})}catch(t){throw this.createAuthError("Frontend AccessToken Refresh",s,t)}});this.destroySession=()=>u(this,null,function*(){if(!this.currentAccessToken)return!0;let e=this.getAuthUrl("/auth/access-token/revoke");try{let s=yield fetch(e,{method:"POST",headers:this.getHeaders(),body:JSON.stringify({accessToken:this.currentAccessToken})});if(!s.ok){let t=yield s.text();throw new Error(`Session revoke failed(Web SDK): ${s.status} ${s.statusText}. URL: ${e}. Response: ${t.slice(0,200)}`)}return this.currentAccessToken="",!0}catch(s){return console.error(this.createAuthError("Session revoke",e,s).message),!1}});this.getAuthModuleName=()=>{switch(this.moduleName){case"ONBOARDING_PARTNER":case"ONBOARDING_MERCHANT":return"ONBOARDING";default:return this.moduleName||""}};this.getHeaders=()=>({Authorization:this.authConfig.authToken||"","Content-Type":"application/json"});this.getAuthUrl=e=>{var t;let s=(t=this.authConfig.authApiUrl)==null?void 0:t.trim();if(!s)throw new Error("authConfig.authApiUrl is required(Web SDK)");return`${s.replace(/\/$/,"")}${e}`};this.parseJsonResponse=(e,s,t)=>u(null,null,function*(){let n=yield e.text();if(!e.ok)throw new Error(`${t} Error Response(Web SDK): ${e.status} ${e.statusText}. URL: ${s}. Response: ${n.slice(0,200)}`);let i=e.headers.get("content-type")||"";if(!i.includes("application/json"))throw new Error(`${t} expected JSON response(Web SDK). URL: ${s}. Content-Type: ${i||"unknown"}. Response: ${n.slice(0,200)}`);try{return JSON.parse(n)}catch(a){throw new Error(`${t} JSON parse failed(Web SDK). URL: ${s}. Response: ${n.slice(0,200)}`)}});this.createAuthError=(e,s,t)=>{if(t instanceof Error&&t.message.includes("(Web SDK)"))return t;let i=(t instanceof Error?t.message:String(t)).includes("Failed to fetch")?" This usually means the browser blocked the request because of CORS, the URL is unreachable, or the request was blocked before a response was returned.":"";return new Error(`${e} Request Failed(Web SDK). URL: ${s}.${i}`)};this.authConfig=e,this.moduleName=s}};function E(r,e){let s=f({},r);for(let t of Object.keys(e))r[t]&&typeof r[t]=="object"&&typeof e[t]=="object"&&!Array.isArray(r[t])&&!Array.isArray(e[t])?s[t]=E(r[t],e[t]):s[t]=e[t];return s}var A={iframeId:"nc-web-sdk-iframe",containerId:"websdk-container",iframeStyle:{width:"100%",height:"100vh",border:"none",display:"block"},sessionValidation:(r,e)=>!r||!e?!1:new Date(e)>new Date,sessionCheckInterval:10*60*1e3,environment:"uat"};var N=r=>{if(!r)return!0;let e;if(r instanceof Date)e=r;else if(typeof r=="number")e=new Date(r);else if(typeof r=="string"){let s=r.trim().replace(" ","T");e=new Date(s)}else return!0;return isNaN(e.getTime())?!0:Date.now()>e.getTime()};var v={local:"http://localhost:4000",dev3:"https://dev3-non-pci.eastus.cloudapp.azure.com",dev2:"https://dev2-non-pci.eastus.cloudapp.azure.com",uat:"https://ignite-preprod.nuvei.com",prod:"https://ignite.nuvei.com"},b={local:"http://localhost:5000",dev3:"https://dev3-non-pci.eastus.cloudapp.azure.com",dev2:"https://dev2-non-pci.eastus.cloudapp.azure.com",uat:"https://ignite-preprod.nuvei.com",prod:"https://ignite.nuvei.com"},$={ONBOARDING_PARTNER:"/_onboarding/partner/application",ONBOARDING_MERCHANT:"/_onboarding/merchant/application",DOC_UTILITY:"/_document-upload"},M="documentRequestId",O="requestId",B=(r="prod")=>{var e;return(e=v[r])!=null?e:v.prod},V=(r="prod")=>{var e;return(e=b[r])!=null?e:b.prod},H=r=>{var e;return(e=$[r])!=null?e:""},q=()=>typeof window=="undefined"?null:new URLSearchParams(window.location.search).get(M),G=()=>typeof window=="undefined"?null:new URLSearchParams(window.location.search).get(O),Q=(r,e,s)=>s.iframeBaseUrl?s.iframeBaseUrl:r==="DOC_UTILITY"?V(e):B(e),x=(r,e)=>{var o,c,l;let s=(o=e.environment)!=null?o:"prod",t=Q(r,s,e),n=H(r),i={};if(r==="DOC_UTILITY"){let d=(c=e.documentRequestId)!=null?c:q();i={[M]:d}}else if(r==="ONBOARDING_MERCHANT"||r==="ONBOARDING_PARTNER"){let d=(l=e.requestId)!=null?l:G();i={[O]:d}}let a=D(i);return`${t}${n}${a}`};var h=class h{constructor(e){this.sdkConfig=f({},A);this.currentIframe=null;this.iframeUrl="";this.isIframeReady=!1;this.messageQueue=[];this.cachedSession=null;this.sessionCheckInterval=null;this.expiryTimeout=null;this.retryAttempts=0;this.MAX_RETRIES=3;this.REFRESH_BUFFER_MS=60*1e3;this.isListeningToIframeEvents=!1;this.isDestroyed=!1;this.initialize=()=>u(this,null,function*(){var e,s;if(this.isDestroyed=!1,!this.componentName)throw new Error("componentName is required to initialize the SDK(Web SDK)");try{let t=yield this.loadComponent(this.componentName);return this.isDestroyed||(yield(e=this.onReady)==null?void 0:e.call(this,this)),t}catch(t){throw(s=this.onError)==null||s.call(this,t),t}});this.loadComponent=e=>u(this,null,function*(){console.log("Component Requested to Load(Web SDK): ",e);try{let s=yield this.getClientSession();if(!this.sdkConfig.sessionValidation(s==null?void 0:s.accessToken,s==null?void 0:s.accessTokenExpiry))throw new Error("Token Validation FailedLoad(Web SDK)");this.iframeUrl=x(e,this.sdkConfig),console.log(`
|
|
2
2
|
Iframe URL(Web SDK): `,this.iframeUrl,`
|
|
3
3
|
`);let t=yield this.createIframeWithSource(this.iframeUrl,e);return this.currentIframe=t,this.updateIframeToken(s.accessToken),t}catch(s){throw this.destroyIframe(),s}});this.destroyIframe=()=>{this.currentIframe&&(this.currentIframe.remove(),this.currentIframe=null),this.stopSessionExpiryCheck()};this.destroy=()=>{this.isDestroyed=!0,this.destroyIframe(),this.messageQueue=[],this.isIframeReady=!1,window.removeEventListener("message",this.handleIframeMessage),this.isListeningToIframeEvents=!1};this.logout=()=>u(this,null,function*(){(yield this.authProvider.destroySession())?(this.stopSessionExpiryCheck(),this.destroyIframe()):console.error("Logout failed(Web SDK)")});this.updateIframeNavigation=e=>{this.enqueueMessage("NAVIGATE",e)};this.sendCustomDataToIframe=e=>{this.enqueueMessage("CUSTOM_DATA",e)};this.getClientSession=()=>u(this,null,function*(){var e,s,t,n;try{if(this.cachedSession&&((t=this.sdkConfig)!=null&&t.sessionValidation((e=this.cachedSession)==null?void 0:e.accessToken,(s=this.cachedSession)==null?void 0:s.accessTokenExpiry)))return this.cachedSession;{let i=yield this.authProvider.fetchClientSession();if(!i.isSuccess)throw new Error("Client Session Fetch Failed(Web SDK)");if(!((n=this.sdkConfig)!=null&&n.sessionValidation(i.accessToken,i.accessTokenExpiry)))throw new Error("Client Session Validation Failed(Web SDK)");return this.cachedSession=i,this.retryAttempts=0,i}}catch(i){throw i}});this.refreshedClientSession=()=>u(this,null,function*(){var e,s;if(!((e=this.cachedSession)!=null&&e.refreshToken)||!this.cachedSession.accessToken)throw console.error("Invalid or missing refreshToken or accessToken in cashed session. Destroying iframe(Web SDK)."),this.destroyIframe(),new Error("No session found(Web SDK)");try{let t=yield this.authProvider.refreshClientSession({accessToken:this.cachedSession.accessToken,refreshToken:this.cachedSession.refreshToken});if(!t.isSuccess)throw console.log("Invalid refresh session token(Called From Web SDK)"),new Error("Refresh Client Session Failed");if(!((s=this.sdkConfig)!=null&&s.sessionValidation(t.accessToken,t.accessTokenExpiry)))throw console.log("Invalid refresh session token(Called From Web SDK)"),new Error("Refresh Client Session Validation Failed");let n=f({},this.cachedSession);return n.accessToken=t.accessToken,n.accessTokenExpiry=t.accessTokenExpiry,this.cachedSession=n,this.retryAttempts=0,t}catch(t){throw console.error("Session Refresh Failed(Web SDK):",t),t}});this.createIframeWithSource=(e,s)=>new Promise((t,n)=>{let i=this.getContainerElement();if(!i)return n(new Error("SDK container not found(Web SDK)"));let a=this.getIframeId(s),o=document.getElementById(a);if(o){console.log(`Iframe with Id: ${a} already exists, reusing it(Web SDK)`),t(o);return}o=document.createElement("iframe"),o.src=e,o.id=a;let c=f({},this.sdkConfig.iframeStyle);c&&Object.assign(o.style,c),o.setAttribute("allow","clipboard-write *"),o.onload=()=>{console.log("Iframe loaded successfully(Web SDK)"),this.startSessionExpiryCheck(),t(o)},o.onerror=()=>{n(new Error("Iframe failed to load(Web SDK)"))},i.appendChild(o)});this.getContainerElement=()=>this.container instanceof HTMLElement?this.container:typeof this.container=="string"?document.querySelector(this.container)||document.getElementById(this.container):document.getElementById(this.sdkConfig.containerId);this.getIframeId=e=>{let s=String(e).toLowerCase().replace(/_/g,"-");return`${this.sdkConfig.iframeId}-${s}`};this.startSessionExpiryCheck=()=>u(this,null,function*(){var o,c;if(N((o=this.cachedSession)==null?void 0:o.refreshTokenExpiry)){console.error("Refresh token is expired. Stopping session expiry check(Web SDK)."),this.destroyIframe();return}let s=new Date,t=(c=this.cachedSession)==null?void 0:c.accessTokenExpiry,n=t?new Date(t):null;if(!n||isNaN(n.getTime())){console.error("Invalid or missing accessTokenExpiry in session. Stopping session expiry check(Web SDK)."),this.destroyIframe();return}let i=n.getTime()-s.getTime()-this.REFRESH_BUFFER_MS,a=()=>u(this,null,function*(){try{if(this.retryAttempts>=this.MAX_RETRIES){console.warn(`Max retry attempts (${this.MAX_RETRIES}) reached. Stopping session check(Web SDK).`),this.stopSessionExpiryCheck(),this.destroyIframe();return}let l=yield this.refreshedClientSession();this.updateIframeToken(l.accessToken),this.retryAttempts=0,this.startSessionExpiryCheck()}catch(l){console.error("Failed to perform session refresh(Web SDK):",l),this.retryAttempts++,this.stopSessionExpiryCheck(),this.expiryTimeout=setTimeout(a,5e3)}});this.stopSessionExpiryCheck(),i<=0?a():this.expiryTimeout=setTimeout(a,i)});this.stopSessionExpiryCheck=()=>{this.expiryTimeout&&(clearTimeout(this.expiryTimeout),this.expiryTimeout=null),this.sessionCheckInterval&&(clearInterval(this.sessionCheckInterval),this.sessionCheckInterval=null)};this.updateIframeToken=e=>{this.enqueueMessage("UPDATE_TOKEN",e)};this.enqueueMessage=(e,s)=>{let t={action:e,source:"NUVEI_WEB_SDK",data:s};if(!this.isIframeReady){console.log("Iframe not ready, queueing message(Web SDK):",t),this.messageQueue.push(t);return}this.postMessageToIframe(t)};this.flushMessageQueue=()=>{for(console.log("Flushing message queue(Web SDK):",this.messageQueue);this.messageQueue.length>0;){let e=this.messageQueue.shift();e&&this.postMessageToIframe(e)}};this.listenToIframeEvents=()=>{this.isListeningToIframeEvents||(window.addEventListener("message",this.handleIframeMessage),this.isListeningToIframeEvents=!0)};this.handleIframeMessage=e=>{if(!this.iframeUrl)return;let s=new URL(this.iframeUrl).origin;if(e.origin!==s)return;let t=e.data;if((t==null?void 0:t.source)==="NUVEI_IFRAME"&&!this.isDestroyed)switch(console.log("Received from iframe:(Web SDK)",t),this.onMessage&&this.onMessage(t),t.action){case"IFRAME_READY":this.handleIframeReady();break;default:break}};this.handleIframeReady=()=>{console.log("Iframe is READY(Web SDK)"),this.isIframeReady=!0,this.flushMessageQueue()};this.postMessageToIframe=e=>{var t;if(!((t=this==null?void 0:this.currentIframe)!=null&&t.contentWindow)){console.warn("Iframe not available(Web SDK)");return}let s=new URL(this.iframeUrl).origin;console.log("Sending message to microfrontend(Web SDK):",e),this.currentIframe.contentWindow.postMessage(e,s)};let{fetchClientSession:s,refreshClientSession:t,destroySession:n,componentName:i,container:a,authConfig:o,config:c,onReady:l,onError:d,onMessage:k}=e;if(o){let S=new g(o,i);this.authProvider={fetchClientSession:s!=null?s:S.fetchClientSession,refreshClientSession:t!=null?t:S.refreshClientSession,destroySession:n!=null?n:S.destroySession}}else if(s&&t&&n)this.authProvider={fetchClientSession:s,refreshClientSession:t,destroySession:n};else throw new Error("authConfig is required when auth callbacks are not fully provided(Web SDK)");this.componentName=i,this.container=a,c&&(this.sdkConfig=E(A,c)),l&&(this.onReady=l),d&&(this.onError=d),k&&(this.onMessage=k),this.listenToIframeEvents()}};h.mount=e=>u(null,null,function*(){let s=new h(e);return yield s.initialize(),s}),h.create=h.mount;var m=h;var R=window;R.NCWebSDK=m;R.NuveiSDK=m;R.ModulesNameEnum=p;})();
|
|
@@ -16,8 +16,8 @@ export declare enum AcknowledgeMessageActionEnum {
|
|
|
16
16
|
export type AcknowledgeMessageActionType = keyof typeof AcknowledgeMessageActionEnum;
|
|
17
17
|
export declare enum EnvironmentEnum {
|
|
18
18
|
LOCAL = "local",
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
DEV3 = "dev3",
|
|
20
|
+
DEV2 = "dev2",
|
|
21
21
|
UAT = "uat",
|
|
22
22
|
PROD = "prod"
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/enums/index.ts"],"names":[],"mappings":"AACA,oBAAY,eAAe;IACzB,kBAAkB,uBAAuB;IACzC,mBAAmB,wBAAwB;IAC3C,WAAW,gBAAgB;CAC5B;AACD,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,eAAe,CAAC;AAG3D,oBAAY,qBAAqB;IAC/B,YAAY,iBAAiB;IAC7B,QAAQ,aAAa;IACrB,WAAW,gBAAgB;CAC5B;AACD,MAAM,MAAM,qBAAqB,GAAG,MAAM,OAAO,qBAAqB,CAAC;AAGvE,oBAAY,4BAA4B;IACtC,YAAY,iBAAiB;CAC9B;AACD,MAAM,MAAM,4BAA4B,GAAG,MAAM,OAAO,4BAA4B,CAAC;AAErF,oBAAY,eAAe;IACzB,KAAK,UAAU;IACf,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/enums/index.ts"],"names":[],"mappings":"AACA,oBAAY,eAAe;IACzB,kBAAkB,uBAAuB;IACzC,mBAAmB,wBAAwB;IAC3C,WAAW,gBAAgB;CAC5B;AACD,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,eAAe,CAAC;AAG3D,oBAAY,qBAAqB;IAC/B,YAAY,iBAAiB;IAC7B,QAAQ,aAAa;IACrB,WAAW,gBAAgB;CAC5B;AACD,MAAM,MAAM,qBAAqB,GAAG,MAAM,OAAO,qBAAqB,CAAC;AAGvE,oBAAY,4BAA4B;IACtC,YAAY,iBAAiB;CAC9B;AACD,MAAM,MAAM,4BAA4B,GAAG,MAAM,OAAO,4BAA4B,CAAC;AAErF,oBAAY,eAAe;IACzB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,IAAI,SAAS;CACd;AACD,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,eAAe,CAAC"}
|
|
@@ -22,8 +22,8 @@ var AcknowledgeMessageActionEnum;
|
|
|
22
22
|
var EnvironmentEnum;
|
|
23
23
|
(function (EnvironmentEnum) {
|
|
24
24
|
EnvironmentEnum["LOCAL"] = "local";
|
|
25
|
-
EnvironmentEnum["
|
|
26
|
-
EnvironmentEnum["
|
|
25
|
+
EnvironmentEnum["DEV3"] = "dev3";
|
|
26
|
+
EnvironmentEnum["DEV2"] = "dev2";
|
|
27
27
|
EnvironmentEnum["UAT"] = "uat";
|
|
28
28
|
EnvironmentEnum["PROD"] = "prod";
|
|
29
29
|
})(EnvironmentEnum || (exports.EnvironmentEnum = EnvironmentEnum = {}));
|
|
@@ -8,14 +8,14 @@ var ENVIRONMENT_BASE_URLS = {
|
|
|
8
8
|
local: 'http://localhost:4000',
|
|
9
9
|
dev3: 'https://dev3-non-pci.eastus.cloudapp.azure.com',
|
|
10
10
|
dev2: 'https://dev2-non-pci.eastus.cloudapp.azure.com',
|
|
11
|
-
|
|
11
|
+
uat: 'https://ignite-preprod.nuvei.com',
|
|
12
12
|
prod: 'https://ignite.nuvei.com',
|
|
13
13
|
};
|
|
14
14
|
var DOCUMENT_UTILITY_BASE_URLS = {
|
|
15
15
|
local: 'http://localhost:5000',
|
|
16
16
|
dev3: 'https://dev3-non-pci.eastus.cloudapp.azure.com',
|
|
17
17
|
dev2: 'https://dev2-non-pci.eastus.cloudapp.azure.com',
|
|
18
|
-
|
|
18
|
+
uat: 'https://ignite-preprod.nuvei.com',
|
|
19
19
|
prod: 'https://ignite.nuvei.com',
|
|
20
20
|
};
|
|
21
21
|
var MODULE_PATHS = (_a = {},
|