@wf-financing/headless-sdk 4.3.3 → 4.3.4

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/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var f=(r=>(r.GENERIC_OFFER="generic_offer",r.INDICATIVE_OFFER="indicative_offer",r.CONTINUE_APPLICATION="continue_application",r))(f||{}),v=Object.defineProperty,E=(r,e,s)=>e in r?v(r,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[e]=s,o=(r,e,s)=>E(r,typeof e!="symbol"?e+"":e,s);const m="https://api.wayflyer.com",I="https://sandbox-api.wayflyer.com",k=r=>{try{return JSON.parse(atob(r.split(".")[1]))}catch{return null}},b={"Content-Type":"application/json"},S={event:"/financing/v1/company/event/",error:"/financing/v1/error/"},u="wf_session_v1",D=1800*1e3,H=1440*60*1e3;class A{getSessionId(){const e=Date.now();let s=this.loadSession();return(!s||this.isSessionExpired(s,e))&&(s=this.mintNewSession(e)),s.lastActivity=e,this.saveSession(s),s.sessionId}isSessionExpired(e,s){const i=s-e.lastActivity>D,t=s-e.createdAt>H;return i||t}mintNewSession(e){return{sessionId:crypto.randomUUID(),createdAt:e,lastActivity:e}}loadSession(){try{const e=sessionStorage.getItem(u);return e?JSON.parse(e):null}catch{return null}}saveSession(e){try{sessionStorage.setItem(u,JSON.stringify(e))}catch{console.warn("Failed to save session context")}}}const h=class a{constructor(e,s,i,t){o(this,"baseUrl",null),o(this,"sessionManager"),o(this,"headers"),o(this,"entryPointVersion"),o(this,"sdkVersion"),this.companyToken=e,this.baseUrl=t?I:m,this.sessionManager=new A,this.entryPointVersion=s,this.sdkVersion=i,this.headers={...b,...i?{"X-SDK-Version":i}:{}}}get requestHeaders(){const e=a.getInstance(),s=e.sessionManager.getSessionId();return{Authorization:`Bearer ${e.companyToken}`,"X-Session-ID":s,...e.headers}}static getGlobalInstance(){return window.WayflyerLogger||null}static setGlobalInstance(e){window.WayflyerLogger=e}static initialize(e,s,i,t){a.getGlobalInstance()&&console.warn("Logger re-initialized");const n=new a(e,s,i,t==null?void 0:t.isSandbox);a.setGlobalInstance(n)}static getMandatoryProperties(){const e=a.getInstance(),{sdkVersion:s,companyToken:i,entryPointVersion:t}=e,n=k(i),[l,y]=(n==null?void 0:n.sub.split("|"))||[],p=n==null?void 0:n.user_id;return{partner_id:l,company_id:y,user_id:p,entry_point_version:t,...s?{sdk_version:s}:{}}}static getInstance(){const e=a.getGlobalInstance();if(!e)throw new Error("Logger not initialized. Call initialize() first.");return e}static async logEvent(e,s){if(this.isDevEnvironment)return;const i=a.getInstance();try{const t={...a.getMandatoryProperties(),...s},n=await fetch(i.baseUrl+S.event,{method:"POST",headers:i.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),event_name:e,properties:t})});if(n.status===200)return await n.json()}catch(t){console.error("Failed to log event",t)}}static async logError(e,s){if(this.isDevEnvironment){console.error(e);return}const i=a.getInstance();try{const t={...a.getMandatoryProperties(),...s},n=await fetch(i.baseUrl+S.error,{method:"POST",headers:i.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),message:e,properties:t})});if(n.status===200)return await n.json()}catch(t){console.warn("Failed to log error",t)}}};o(h,"isDevEnvironment",!1);let d=h;const _="wayflyer-headless-sdk",P="https://embedded-finance-frontend.vercel.app/npm/@wf-financing/headless@3",w="4.3.3",g=(r,e)=>{if(!window.WayflyerHeadlessSdk)throw new Error("SDK code was fetched successfully, but WayflyerHeadlessSdk is unavailable on window");const s=window.WayflyerHeadlessSdk;return window.waylflyerHeadlessSdk||(window.waylflyerHeadlessSdk=new s(r,e)),window.waylflyerHeadlessSdk},O="HEADLESS_SDK_READY_EVENT",N=async(r,e)=>window.WayflyerHeadlessSdk?g(r,e):new Promise((i,t)=>{const n=document.createElement("script");n.src=P,n.type="module",n.id=_,n.async=!0,n.onerror=()=>{t(new Error(`Failed to load headless SDK script from ${n.src}`))};const l=()=>{const y=g(r,e);i(y)};window.addEventListener(O,l,{once:!0}),document.head.appendChild(n)}),L="headless";let c=null;class T{static loadSdk(e,s){return c||(c=this.getHeadlessSdkPromise(e,s),c)}static async getHeadlessSdkPromise(e,s){const i=Date.now();try{const t=await N(e,s),n=Date.now()-i,l=t.sdkVersion;return d.initialize(e,w,l,s),d.logEvent("headless_sdk_initialized",{entry_point_type:L,sdk_initialization_latency:n}),t}catch(t){const n=t instanceof Error?t:new Error(String(t));throw d.initialize(e,w,void 0,s),d.logError(n.message),t}}}exports.CtaStateType=f;exports.WayflyerHeadlessSdk=T;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var f=(r=>(r.GENERIC_OFFER="generic_offer",r.INDICATIVE_OFFER="indicative_offer",r.CONTINUE_APPLICATION="continue_application",r))(f||{}),v=Object.defineProperty,E=(r,e,s)=>e in r?v(r,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[e]=s,o=(r,e,s)=>E(r,typeof e!="symbol"?e+"":e,s);const m="https://api.wayflyer.com/financing",I="https://sandbox-api.wayflyer.com/financing",k=r=>{try{return JSON.parse(atob(r.split(".")[1]))}catch{return null}},b={"Content-Type":"application/json"},S={event:"/v1/company/event/",error:"/v1/error/"},u="wf_session_v1",D=1800*1e3,H=1440*60*1e3;class A{getSessionId(){const e=Date.now();let s=this.loadSession();return(!s||this.isSessionExpired(s,e))&&(s=this.mintNewSession(e)),s.lastActivity=e,this.saveSession(s),s.sessionId}isSessionExpired(e,s){const i=s-e.lastActivity>D,t=s-e.createdAt>H;return i||t}mintNewSession(e){return{sessionId:crypto.randomUUID(),createdAt:e,lastActivity:e}}loadSession(){try{const e=sessionStorage.getItem(u);return e?JSON.parse(e):null}catch{return null}}saveSession(e){try{sessionStorage.setItem(u,JSON.stringify(e))}catch{console.warn("Failed to save session context")}}}const h=class a{constructor(e,s,i,t){o(this,"baseUrl",null),o(this,"sessionManager"),o(this,"headers"),o(this,"entryPointVersion"),o(this,"sdkVersion"),this.companyToken=e,this.baseUrl=t?I:m,this.sessionManager=new A,this.entryPointVersion=s,this.sdkVersion=i,this.headers={...b,...i?{"X-SDK-Version":i}:{}}}get requestHeaders(){const e=a.getInstance(),s=e.sessionManager.getSessionId();return{Authorization:`Bearer ${e.companyToken}`,"X-Session-ID":s,...e.headers}}static getGlobalInstance(){return window.WayflyerLogger||null}static setGlobalInstance(e){window.WayflyerLogger=e}static initialize(e,s,i,t){a.getGlobalInstance()&&console.warn("Logger re-initialized");const n=new a(e,s,i,t==null?void 0:t.isSandbox);a.setGlobalInstance(n)}static getMandatoryProperties(){const e=a.getInstance(),{sdkVersion:s,companyToken:i,entryPointVersion:t}=e,n=k(i),[l,y]=(n==null?void 0:n.sub.split("|"))||[],p=n==null?void 0:n.user_id;return{partner_id:l,company_id:y,user_id:p,entry_point_version:t,...s?{sdk_version:s}:{}}}static getInstance(){const e=a.getGlobalInstance();if(!e)throw new Error("Logger not initialized. Call initialize() first.");return e}static async logEvent(e,s){if(this.isDevEnvironment)return;const i=a.getInstance();try{const t={...a.getMandatoryProperties(),...s},n=await fetch(i.baseUrl+S.event,{method:"POST",headers:i.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),event_name:e,properties:t})});if(n.status===200)return await n.json()}catch(t){console.error("Failed to log event",t)}}static async logError(e,s){if(this.isDevEnvironment){console.error(e);return}const i=a.getInstance();try{const t={...a.getMandatoryProperties(),...s},n=await fetch(i.baseUrl+S.error,{method:"POST",headers:i.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),message:e,properties:t})});if(n.status===200)return await n.json()}catch(t){console.warn("Failed to log error",t)}}};o(h,"isDevEnvironment",!1);let d=h;const _="wayflyer-headless-sdk",P="https://embedded-finance-frontend.vercel.app/npm/@wf-financing/headless@3",w="4.3.4",g=(r,e)=>{if(!window.WayflyerHeadlessSdk)throw new Error("SDK code was fetched successfully, but WayflyerHeadlessSdk is unavailable on window");const s=window.WayflyerHeadlessSdk;return window.waylflyerHeadlessSdk||(window.waylflyerHeadlessSdk=new s(r,e)),window.waylflyerHeadlessSdk},O="HEADLESS_SDK_READY_EVENT",N=async(r,e)=>window.WayflyerHeadlessSdk?g(r,e):new Promise((i,t)=>{const n=document.createElement("script");n.src=P,n.type="module",n.id=_,n.async=!0,n.onerror=()=>{t(new Error(`Failed to load headless SDK script from ${n.src}`))};const l=()=>{const y=g(r,e);i(y)};window.addEventListener(O,l,{once:!0}),document.head.appendChild(n)}),L="headless";let c=null;class T{static loadSdk(e,s){return c||(c=this.getHeadlessSdkPromise(e,s),c)}static async getHeadlessSdkPromise(e,s){const i=Date.now();try{const t=await N(e,s),n=Date.now()-i,l=t.sdkVersion;return d.initialize(e,w,l,s),d.logEvent("headless_sdk_initialized",{entry_point_type:L,sdk_initialization_latency:n}),t}catch(t){const n=t instanceof Error?t:new Error(String(t));throw d.initialize(e,w,void 0,s),d.logError(n.message),t}}}exports.CtaStateType=f;exports.WayflyerHeadlessSdk=T;
package/dist/index.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  var p = /* @__PURE__ */ ((r) => (r.GENERIC_OFFER = "generic_offer", r.INDICATIVE_OFFER = "indicative_offer", r.CONTINUE_APPLICATION = "continue_application", r))(p || {}), E = Object.defineProperty, v = (r, e, s) => e in r ? E(r, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : r[e] = s, o = (r, e, s) => v(r, typeof e != "symbol" ? e + "" : e, s);
2
- const m = "https://api.wayflyer.com", I = "https://sandbox-api.wayflyer.com", k = (r) => {
2
+ const m = "https://api.wayflyer.com/financing", I = "https://sandbox-api.wayflyer.com/financing", k = (r) => {
3
3
  try {
4
4
  return JSON.parse(atob(r.split(".")[1]));
5
5
  } catch {
@@ -8,8 +8,8 @@ const m = "https://api.wayflyer.com", I = "https://sandbox-api.wayflyer.com", k
8
8
  }, b = {
9
9
  "Content-Type": "application/json"
10
10
  }, S = {
11
- event: "/financing/v1/company/event/",
12
- error: "/financing/v1/error/"
11
+ event: "/v1/company/event/",
12
+ error: "/v1/error/"
13
13
  }, u = "wf_session_v1", D = 1800 * 1e3, H = 1440 * 60 * 1e3;
14
14
  class A {
15
15
  getSessionId() {
@@ -136,7 +136,7 @@ const h = class a {
136
136
  };
137
137
  o(h, "isDevEnvironment", !1);
138
138
  let d = h;
139
- const _ = "wayflyer-headless-sdk", P = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/headless@3", w = "4.3.3", g = (r, e) => {
139
+ const _ = "wayflyer-headless-sdk", P = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/headless@3", w = "4.3.4", g = (r, e) => {
140
140
  if (!window.WayflyerHeadlessSdk)
141
141
  throw new Error("SDK code was fetched successfully, but WayflyerHeadlessSdk is unavailable on window");
142
142
  const s = window.WayflyerHeadlessSdk;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wf-financing/headless-sdk",
3
- "version": "4.3.3",
3
+ "version": "4.3.4",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -16,7 +16,7 @@
16
16
  ],
17
17
  "dependencies": {
18
18
  "@wf-financing/embedded-types": "1.1.1",
19
- "@wf-financing/logger": "2.2.2"
19
+ "@wf-financing/logger": "2.2.3"
20
20
  },
21
21
  "devDependencies": {
22
22
  "vite": "^6.3.5",