@nuvei-connect/nc-websdk 1.12.4 → 1.12.5

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/README.md CHANGED
@@ -393,6 +393,7 @@ Each page is responsible for mounting its own SDK component. The partner and mer
393
393
  | `config.environment` | ` "uat" \| "prod"` | `config` inside `NuveiSDK.mount()` | Nuvei environment used by the WebSDK. This value must be provided inside the `config` object. |
394
394
  | `config.requestId` | `string` | `"onboarding-request-123"` | `config` inside `NuveiSDK.mount()` | Optional onboarding application or request identifier. Provide this inside `config` when continuing or loading a specific onboarding request. |
395
395
  | `config.documentRequestId` | `string` | `"document-request-456"` | `config` inside `NuveiSDK.mount()` | Optional Document Utility request identifier. Provide this inside `config` when operating on a specific document request. |
396
+ | `config.initialPath` | `string` | `"/_admin/my-organization"` | `config` inside `NuveiSDK.mount()` | Optional path the iframe opens on, used in place of the module's default path. Use it to open a specific page without first loading the default one. |
396
397
  | `container` | `HTMLElement \| string` | `"nuvei-websdk-container"` | `NuveiSDK.mount()` | DOM element or element ID where the SDK iframe will be rendered. |
397
398
  | `fetchClientSession` | `() => Promise<IClientSession>` | `fetchClientSession` | `NuveiSDK.mount()` | Required callback that requests a client session from your backend. |
398
399
  | `refreshClientSession` | `(params: { refreshToken: string; accessToken: string }) => Promise<IClientRefreshSession>` | `refreshClientSession` | `NuveiSDK.mount()` | Optional callback used to refresh an expired or expiring client session. |
package/dist/cdn-index.js CHANGED
@@ -391,7 +391,7 @@
391
391
  throw new Error("Websdk Environment is not configured");
392
392
  }
393
393
  const baseUrl = getBaseUrl(componentName, environment, config);
394
- const path = getModulePath(componentName);
394
+ const path = config.initialPath || getModulePath(componentName);
395
395
  let queryParams = {};
396
396
  if (componentName === "DOC_UTILITY" /* DOC_UTILITY */) {
397
397
  const documentRequestId = (_a = config.documentRequestId) != null ? _a : getDocumentRequestIdFromUrl();
@@ -1,3 +1,3 @@
1
- "use strict";(()=>{var x=Object.defineProperty,P=Object.defineProperties;var K=Object.getOwnPropertyDescriptors;var v=Object.getOwnPropertySymbols;var L=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable;var w=(r,e,s)=>e in r?x(r,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[e]=s,h=(r,e)=>{for(var s in e||(e={}))L.call(e,s)&&w(r,s,e[s]);if(v)for(var s of v(e))F.call(e,s)&&w(r,s,e[s]);return r},S=(r,e)=>P(r,K(e));var l=(r,e,s)=>new Promise((t,n)=>{var i=c=>{try{o(s.next(c))}catch(u){n(u)}},a=c=>{try{o(s.throw(c))}catch(u){n(u)}},o=c=>c.done?t(c.value):Promise.resolve(c.value).then(i,a);o((s=s.apply(r,e)).next())});var p=(n=>(n.ONBOARDING_PARTNER="ONBOARDING_PARTNER",n.ONBOARDING_MERCHANT="ONBOARDING_MERCHANT",n.DOC_UTILITY="DOC_UTILITY",n.USER_MANAGEMENT="USER_MANAGEMENT",n))(p||{});var C=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&&y(o)){let u=t+n+"="+o;y(c)?t=u+"&":t=u}else y(o)&&(t=t+n+"="+o)}),t}return""},y=r=>!(r==null||r===""||typeof r=="number"&&Number.isNaN(r)||typeof r=="string"&&r.trim()===""),m=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(m).filter(a=>e(a));i.length&&(s[t]=i)}else if(typeof n=="object"){let i=m(n);e(i)&&(s[t]=i)}else s[t]=n}return Object.keys(s).length?s:void 0};var W={isSuccess:!1,accessToken:"",accessTokenExpiry:"",refreshToken:"",refreshTokenExpiry:""},$={isSuccess:!1,accessToken:"",accessTokenExpiry:""},g=class{constructor(e,s){this.currentAccessToken="";this.fetchClientSession=()=>l(this,null,function*(){let e=this.getAuthUrl("/auth/micro-frontend/tokens"),s=m({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||"",S(h(h({},W),n),{isSuccess:!0})}catch(t){throw this.createAuthError("Frontend AccessToken",e,t)}});this.refreshClientSession=e=>l(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(m(e))}),n=yield this.parseJsonResponse(t,s,"Frontend AccessToken Refresh");return this.currentAccessToken=n.accessToken||this.currentAccessToken,S(h(h({},$),n),{isSuccess:!0})}catch(t){throw this.createAuthError("Frontend AccessToken Refresh",s,t)}});this.destroySession=()=>l(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)=>l(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=h({},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 T={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:600*1e3,environment:"uat2"};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 D={local:"http://localhost:4000",dev3:"https://dev3-non-pci.eastus.cloudapp.azure.com",dev2:"https://dev2-non-pci.eastus.cloudapp.azure.com",uat2:"https://ignite-preprod.nuvei.com","prod-na":"https://ignite.nuvei.com","prod-eu":"https://ignite-eu.nuvei.com","dev2-2":"https://dev2-non-pci-2.eastus.cloudapp.azure.com"},M={local:"http://localhost:5000",dev3:"https://dev3-non-pci.eastus.cloudapp.azure.com",dev2:"https://dev2-non-pci.eastus.cloudapp.azure.com",uat2:"https://ignite-preprod.nuvei.com","prod-na":"https://ignite.nuvei.com","prod-eu":"https://ignite-eu.nuvei.com","dev2-2":"https://dev2-non-pci-2.eastus.cloudapp.azure.com"},b={local:"http://localhost:5001",dev3:"https://dev3-non-pci.eastus.cloudapp.azure.com",dev2:"https://dev2-non-pci.eastus.cloudapp.azure.com",uat2:"https://ignite-preprod.nuvei.com","prod-na":"https://ignite.nuvei.com","prod-eu":"https://ignite-eu.nuvei.com","dev2-2":"https://dev2-non-pci-2.eastus.cloudapp.azure.com"},B={ONBOARDING_PARTNER:"/_onboarding/partner/application",ONBOARDING_MERCHANT:"/_onboarding/merchant/application",DOC_UTILITY:"/_document-upload",USER_MANAGEMENT:"/_admin/user-management"},O="documentRequestId",U="requestId",H=r=>{var e;return(e=D[r])!=null?e:D.prod},V=r=>{var e;return(e=M[r])!=null?e:M.prod},q=(r="prod")=>{var e;return(e=b[r])!=null?e:b.prod},G=r=>{var e;return(e=B[r])!=null?e:""},z=()=>typeof window=="undefined"?null:new URLSearchParams(window.location.search).get(O),Q=()=>typeof window=="undefined"?null:new URLSearchParams(window.location.search).get(U),Y=(r,e,s)=>s.iframeBaseUrl?s.iframeBaseUrl:r==="DOC_UTILITY"?V(e):r==="USER_MANAGEMENT"?q(e):H(e),_=(r,e)=>{var o,c;let s=e.environment;if(!s)throw new Error("Websdk Environment is not configured");let t=Y(r,s,e),n=G(r),i={};if(r==="DOC_UTILITY"){let u=(o=e.documentRequestId)!=null?o:z();i={[O]:u}}else if(r==="ONBOARDING_MERCHANT"||r==="ONBOARDING_PARTNER"){let u=(c=e.requestId)!=null?c:Q();i={[U]:u}}let a=C(i);return`${t}${n}${a}`};var d=class d{constructor(e){this.sdkConfig=h({},T);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=()=>l(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=>l(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=_(e,this.sdkConfig),console.log(`
1
+ "use strict";(()=>{var x=Object.defineProperty,P=Object.defineProperties;var K=Object.getOwnPropertyDescriptors;var v=Object.getOwnPropertySymbols;var L=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable;var w=(r,e,s)=>e in r?x(r,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[e]=s,h=(r,e)=>{for(var s in e||(e={}))L.call(e,s)&&w(r,s,e[s]);if(v)for(var s of v(e))F.call(e,s)&&w(r,s,e[s]);return r},S=(r,e)=>P(r,K(e));var l=(r,e,s)=>new Promise((t,n)=>{var i=c=>{try{o(s.next(c))}catch(u){n(u)}},a=c=>{try{o(s.throw(c))}catch(u){n(u)}},o=c=>c.done?t(c.value):Promise.resolve(c.value).then(i,a);o((s=s.apply(r,e)).next())});var p=(n=>(n.ONBOARDING_PARTNER="ONBOARDING_PARTNER",n.ONBOARDING_MERCHANT="ONBOARDING_MERCHANT",n.DOC_UTILITY="DOC_UTILITY",n.USER_MANAGEMENT="USER_MANAGEMENT",n))(p||{});var C=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&&y(o)){let u=t+n+"="+o;y(c)?t=u+"&":t=u}else y(o)&&(t=t+n+"="+o)}),t}return""},y=r=>!(r==null||r===""||typeof r=="number"&&Number.isNaN(r)||typeof r=="string"&&r.trim()===""),m=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(m).filter(a=>e(a));i.length&&(s[t]=i)}else if(typeof n=="object"){let i=m(n);e(i)&&(s[t]=i)}else s[t]=n}return Object.keys(s).length?s:void 0};var W={isSuccess:!1,accessToken:"",accessTokenExpiry:"",refreshToken:"",refreshTokenExpiry:""},$={isSuccess:!1,accessToken:"",accessTokenExpiry:""},g=class{constructor(e,s){this.currentAccessToken="";this.fetchClientSession=()=>l(this,null,function*(){let e=this.getAuthUrl("/auth/micro-frontend/tokens"),s=m({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||"",S(h(h({},W),n),{isSuccess:!0})}catch(t){throw this.createAuthError("Frontend AccessToken",e,t)}});this.refreshClientSession=e=>l(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(m(e))}),n=yield this.parseJsonResponse(t,s,"Frontend AccessToken Refresh");return this.currentAccessToken=n.accessToken||this.currentAccessToken,S(h(h({},$),n),{isSuccess:!0})}catch(t){throw this.createAuthError("Frontend AccessToken Refresh",s,t)}});this.destroySession=()=>l(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)=>l(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=h({},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 T={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:600*1e3,environment:"uat2"};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 D={local:"http://localhost:4000",dev3:"https://dev3-non-pci.eastus.cloudapp.azure.com",dev2:"https://dev2-non-pci.eastus.cloudapp.azure.com",uat2:"https://ignite-preprod.nuvei.com","prod-na":"https://ignite.nuvei.com","prod-eu":"https://ignite-eu.nuvei.com","dev2-2":"https://dev2-non-pci-2.eastus.cloudapp.azure.com"},M={local:"http://localhost:5000",dev3:"https://dev3-non-pci.eastus.cloudapp.azure.com",dev2:"https://dev2-non-pci.eastus.cloudapp.azure.com",uat2:"https://ignite-preprod.nuvei.com","prod-na":"https://ignite.nuvei.com","prod-eu":"https://ignite-eu.nuvei.com","dev2-2":"https://dev2-non-pci-2.eastus.cloudapp.azure.com"},b={local:"http://localhost:5001",dev3:"https://dev3-non-pci.eastus.cloudapp.azure.com",dev2:"https://dev2-non-pci.eastus.cloudapp.azure.com",uat2:"https://ignite-preprod.nuvei.com","prod-na":"https://ignite.nuvei.com","prod-eu":"https://ignite-eu.nuvei.com","dev2-2":"https://dev2-non-pci-2.eastus.cloudapp.azure.com"},B={ONBOARDING_PARTNER:"/_onboarding/partner/application",ONBOARDING_MERCHANT:"/_onboarding/merchant/application",DOC_UTILITY:"/_document-upload",USER_MANAGEMENT:"/_admin/user-management"},O="documentRequestId",U="requestId",H=r=>{var e;return(e=D[r])!=null?e:D.prod},V=r=>{var e;return(e=M[r])!=null?e:M.prod},q=(r="prod")=>{var e;return(e=b[r])!=null?e:b.prod},G=r=>{var e;return(e=B[r])!=null?e:""},z=()=>typeof window=="undefined"?null:new URLSearchParams(window.location.search).get(O),Q=()=>typeof window=="undefined"?null:new URLSearchParams(window.location.search).get(U),Y=(r,e,s)=>s.iframeBaseUrl?s.iframeBaseUrl:r==="DOC_UTILITY"?V(e):r==="USER_MANAGEMENT"?q(e):H(e),_=(r,e)=>{var o,c;let s=e.environment;if(!s)throw new Error("Websdk Environment is not configured");let t=Y(r,s,e),n=e.initialPath||G(r),i={};if(r==="DOC_UTILITY"){let u=(o=e.documentRequestId)!=null?o:z();i={[O]:u}}else if(r==="ONBOARDING_MERCHANT"||r==="ONBOARDING_PARTNER"){let u=(c=e.requestId)!=null?c:Q();i={[U]:u}}let a=C(i);return`${t}${n}${a}`};var d=class d{constructor(e){this.sdkConfig=h({},T);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=()=>l(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=>l(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=_(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=()=>l(this,null,function*(){let e=!0;this.authProvider.destroySession&&(e=yield this.authProvider.destroySession()),e?(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=()=>l(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!=null&&i.accessToken))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=()=>l(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)");if(!this.authProvider.refreshClientSession)throw new Error("refreshClientSession is not provided(Web SDK)");try{let t=yield this.authProvider.refreshClientSession({accessToken:this.cachedSession.accessToken,refreshToken:this.cachedSession.refreshToken});if(!(t!=null&&t.accessToken))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=h({},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=h({},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=()=>l(this,null,function*(){var o,c;if(!this.authProvider.refreshClientSession){console.warn("refreshClientSession not provided, session will not be refreshed automatically(Web SDK)");return}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=()=>l(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 u=yield this.refreshedClientSession();this.updateIframeToken(u.accessToken),this.retryAttempts=0,this.startSessionExpiryCheck()}catch(u){console.error("Failed to perform session refresh(Web SDK):",u),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=>{var n,i,a;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){if(console.log("Received from iframe:(Web SDK)",t),t.action==="CHECK_SESSION_EXPIRY"&&typeof t.requestId=="string"){let o=(n=this.cachedSession)==null?void 0:n.accessTokenExpiry,c=o?new Date(o).getTime():Number.NaN;Number.isFinite(c)&&((a=(i=this.currentIframe)==null?void 0:i.contentWindow)==null||a.postMessage({source:"NUVEI_PORTAL",action:"CHECK_SESSION_EXPIRY_RESULT",requestId:t.requestId,data:{valid:c>Date.now()}},s))}switch(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:u,onError:A,onMessage:k}=e;if(o){let I=new g(o,i);this.authProvider={fetchClientSession:s!=null?s:I.fetchClientSession,refreshClientSession:t!=null?t:I.refreshClientSession,destroySession:n!=null?n:I.destroySession}}else if(typeof s=="function")this.authProvider={fetchClientSession:s,refreshClientSession:t,destroySession:n};else throw new Error("authConfig or fetchClientSession is required to initialize SDK(Web SDK)");this.componentName=i,this.container=a,c&&(this.sdkConfig=E(T,c)),u&&(this.onReady=u),A&&(this.onError=A),k&&(this.onMessage=k),this.listenToIframeEvents()}};d.mount=e=>l(null,null,function*(){let s=new d(e);return yield s.initialize(),s}),d.create=d.mount;var f=d;var R=window;R.NCWebSDK=f;R.NuveiSDK=f;R.ModulesNameEnum=p;})();
@@ -57,6 +57,11 @@ export interface INuveiSdkConfig {
57
57
  iframeBaseUrl?: string;
58
58
  requestId?: string;
59
59
  documentRequestId?: string;
60
+ /**
61
+ * Optional path to open in the iframe instead of the module's default path.
62
+ * It is appended to the module's base URL, e.g. `/_admin/my-organization`.
63
+ */
64
+ initialPath?: string;
60
65
  }
61
66
  export interface HTMLIFrameElement extends HTMLElement {
62
67
  allow: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,MAAM,WAAW,GACnB;IACE,UAAU,EAAE,WAAW,CAAC;IACxB,kBAAkB,CAAC,EAAE,MAAM,OAAO,CAAC,cAAc,CAAC,CAAC;IACnD,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,2BAA2B,KAAK,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAChG,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;CACzC,GACD;IACE,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,kBAAkB,EAAE,MAAM,OAAO,CAAC,cAAc,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dk Environment is not configured");
114
114
  }
115
115
  var baseUrl = getBaseUrl(componentName, environment, config);
116
- var path = (0, exports.getModulePath)(componentName);
116
+ var path = config.initialPath || (0, exports.getModulePath)(componentName);
117
117
  var queryParams = {};
118
118
  if (componentName === enums_1.ModulesNameEnum.DOC_UTILITY) {
119
119
  var documentRequestId = (_c = config.documentRequestId) !== null && _c !== void 0 ? _c : getDocumentRequestIdFromUrl();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuvei-connect/nc-websdk",
3
- "version": "1.12.4",
3
+ "version": "1.12.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",