@wf-financing/ui-sdk 3.4.2 → 3.4.3

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 v=Object.defineProperty,m=(r,e,t)=>e in r?v(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,o=(r,e,t)=>m(r,typeof e!="symbol"?e+"":e,t);const p="https://api.wayflyer.com",I="https://sandbox-api.wayflyer.com",b=r=>{try{return JSON.parse(atob(r.split(".")[1]))}catch{return null}},k={"Content-Type":"application/json"},u={event:"/financing/v1/company/event/",error:"/financing/v1/error/"},g="wf_session_v1",E=1800*1e3,U=1440*60*1e3;class P{getSessionId(){const e=Date.now();let t=this.loadSession();return(!t||this.isSessionExpired(t,e))&&(t=this.mintNewSession(e)),t.lastActivity=e,this.saveSession(t),t.sessionId}isSessionExpired(e,t){const s=t-e.lastActivity>E,n=t-e.createdAt>U;return s||n}mintNewSession(e){return{sessionId:crypto.randomUUID(),createdAt:e,lastActivity:e}}loadSession(){try{const e=sessionStorage.getItem(g);return e?JSON.parse(e):null}catch{return null}}saveSession(e){try{sessionStorage.setItem(g,JSON.stringify(e))}catch{console.warn("Failed to save session context")}}}const h=class a{constructor(e,t,s,n){o(this,"baseUrl",null),o(this,"sessionManager"),o(this,"headers"),o(this,"entryPointVersion"),o(this,"sdkVersion"),this.companyToken=e,this.baseUrl=n?I:p,this.sessionManager=new P,this.entryPointVersion=t,this.sdkVersion=s,this.headers={...k,...s?{"X-SDK-Version":s}:{}}}get requestHeaders(){const e=a.getInstance(),t=e.sessionManager.getSessionId();return{Authorization:`Bearer ${e.companyToken}`,"X-Session-ID":t,...e.headers}}static getGlobalInstance(){return window.WayflyerLogger||null}static setGlobalInstance(e){window.WayflyerLogger=e}static initialize(e,t,s,n){a.getGlobalInstance()&&console.warn("Logger re-initialized");const i=new a(e,t,s,n==null?void 0:n.isSandbox);a.setGlobalInstance(i)}static getMandatoryProperties(){const e=a.getInstance(),{sdkVersion:t,companyToken:s,entryPointVersion:n}=e,i=b(s),[d,y]=(i==null?void 0:i.sub.split("|"))||[],f=i==null?void 0:i.user_id;return{partner_id:d,company_id:y,user_id:f,entry_point_version:n,...t?{sdk_version:t}:{}}}static getInstance(){const e=a.getGlobalInstance();if(!e)throw new Error("Logger not initialized. Call initialize() first.");return e}static async logEvent(e,t){if(this.isDevEnvironment)return;const s=a.getInstance();try{const n={...a.getMandatoryProperties(),...t},i=await fetch(s.baseUrl+u.event,{method:"POST",headers:s.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),event_name:e,properties:n})});if(i.status===200)return await i.json()}catch(n){console.error("Failed to log event",n)}}static async logError(e,t){if(this.isDevEnvironment){console.error(e);return}const s=a.getInstance();try{const n={...a.getMandatoryProperties(),...t},i=await fetch(s.baseUrl+u.error,{method:"POST",headers:s.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),message:e,properties:n})});if(i.status===200)return await i.json()}catch(n){console.warn("Failed to log error",n)}}};o(h,"isDevEnvironment",!1);let c=h;const S=(r,e)=>{if(!window.WayflyerUiSdk)throw new Error("SDK code was fetched successfully, but WayflyerUiSdk is unavailable on window");const t=window.WayflyerUiSdk;return new t(r,e)},D="wayflyer-ui-package",_="https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4",w="3.4.2",A="UI_SDK_READY_EVENT",O=async(r,e)=>window.WayflyerUiSdk?S(r,e):new Promise((s,n)=>{const i=document.createElement("script");i.src=_,i.type="module",i.id=D,i.async=!0,i.onerror=()=>{n(new Error(`Failed to load UI SDK script from ${i.src}`))};const d=()=>{const y=S(r,e);s(y)};window.addEventListener(A,d,{once:!0}),document.head.appendChild(i)}),z="ui";let l=null;class L{static async loadSdk(e,t){var n;l??(l=this.getLoadSdkPromise(e,t));const s=await l;return((n=s==null?void 0:s.options)==null?void 0:n.language)!==(t==null?void 0:t.language)?(l=this.getLoadSdkPromise(e,t),await l):s}static async getLoadSdkPromise(e,t){const s=Date.now();try{const n=await O(e,t),i=Date.now()-s;return c.initialize(e,w,n.sdkVersion,t),c.logEvent("ui_sdk_initialized",{entry_point_type:z,sdk_initialization_latency:i}),n}catch(n){const i=n instanceof Error?n:new Error(String(n));throw c.initialize(e,w,void 0,t),c.logError(i.message),n}}}exports.WayflyerUiSdk=L;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var v=Object.defineProperty,m=(r,e,t)=>e in r?v(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,o=(r,e,t)=>m(r,typeof e!="symbol"?e+"":e,t);const p="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"},u={event:"/financing/v1/company/event/",error:"/financing/v1/error/"},S="wf_session_v1",E=1800*1e3,U=1440*60*1e3;class P{getSessionId(){const e=Date.now();let t=this.loadSession();return(!t||this.isSessionExpired(t,e))&&(t=this.mintNewSession(e)),t.lastActivity=e,this.saveSession(t),t.sessionId}isSessionExpired(e,t){const i=t-e.lastActivity>E,n=t-e.createdAt>U;return i||n}mintNewSession(e){return{sessionId:crypto.randomUUID(),createdAt:e,lastActivity:e}}loadSession(){try{const e=sessionStorage.getItem(S);return e?JSON.parse(e):null}catch{return null}}saveSession(e){try{sessionStorage.setItem(S,JSON.stringify(e))}catch{console.warn("Failed to save session context")}}}const h=class a{constructor(e,t,i,n){o(this,"baseUrl",null),o(this,"sessionManager"),o(this,"headers"),o(this,"entryPointVersion"),o(this,"sdkVersion"),this.companyToken=e,this.baseUrl=n?I:p,this.sessionManager=new P,this.entryPointVersion=t,this.sdkVersion=i,this.headers={...b,...i?{"X-SDK-Version":i}:{}}}get requestHeaders(){const e=a.getInstance(),t=e.sessionManager.getSessionId();return{Authorization:`Bearer ${e.companyToken}`,"X-Session-ID":t,...e.headers}}static getGlobalInstance(){return window.WayflyerLogger||null}static setGlobalInstance(e){window.WayflyerLogger=e}static initialize(e,t,i,n){a.getGlobalInstance()&&console.warn("Logger re-initialized");const s=new a(e,t,i,n==null?void 0:n.isSandbox);a.setGlobalInstance(s)}static getMandatoryProperties(){const e=a.getInstance(),{sdkVersion:t,companyToken:i,entryPointVersion:n}=e,s=k(i),[d,y]=(s==null?void 0:s.sub.split("|"))||[],f=s==null?void 0:s.user_id;return{partner_id:d,company_id:y,user_id:f,entry_point_version:n,...t?{sdk_version:t}:{}}}static getInstance(){const e=a.getGlobalInstance();if(!e)throw new Error("Logger not initialized. Call initialize() first.");return e}static async logEvent(e,t){if(this.isDevEnvironment)return;const i=a.getInstance();try{const n={...a.getMandatoryProperties(),...t},s=await fetch(i.baseUrl+u.event,{method:"POST",headers:i.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),event_name:e,properties:n})});if(s.status===200)return await s.json()}catch(n){console.error("Failed to log event",n)}}static async logError(e,t){if(this.isDevEnvironment){console.error(e);return}const i=a.getInstance();try{const n={...a.getMandatoryProperties(),...t},s=await fetch(i.baseUrl+u.error,{method:"POST",headers:i.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),message:e,properties:n})});if(s.status===200)return await s.json()}catch(n){console.warn("Failed to log error",n)}}};o(h,"isDevEnvironment",!1);let l=h;const g=(r,e)=>{if(!window.WayflyerUiSdk)throw new Error("SDK code was fetched successfully, but WayflyerUiSdk is unavailable on window");const t=window.WayflyerUiSdk;return new t(r,e)},D="wayflyer-ui-package",_="https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4",w="3.4.3",A="UI_SDK_READY_EVENT",z=async(r,e)=>window.WayflyerUiSdk?g(r,e):new Promise((i,n)=>{const s=document.createElement("script");s.src=_,s.type="module",s.id=D,s.async=!0,s.onerror=()=>{n(new Error(`Failed to load UI SDK script from ${s.src}`))};const d=()=>{const y=g(r,e);i(y)};window.addEventListener(A,d,{once:!0}),document.head.appendChild(s)}),N="ui";let c=null;class O{static async loadSdk(e,t){var i;c??(c=this.getLoadSdkPromise(e,t));try{const n=await c;return((i=n==null?void 0:n.options)==null?void 0:i.language)!==(t==null?void 0:t.language)||n.companyToken!==e?(c=this.getLoadSdkPromise(e,t),await c):n}catch(n){throw c=null,n}}static async getLoadSdkPromise(e,t){const i=Date.now();try{const n=await z(e,t),s=Date.now()-i;return l.initialize(e,w,n.sdkVersion,t),l.logEvent("ui_sdk_initialized",{entry_point_type:N,sdk_initialization_latency:s}),n}catch(n){const s=n instanceof Error?n:new Error(String(n));throw l.initialize(e,w,void 0,t),l.logError(s.message),n}}}exports.WayflyerUiSdk=O;
package/dist/index.es.js CHANGED
@@ -1,16 +1,16 @@
1
1
  var p = Object.defineProperty, v = (r, e, t) => e in r ? p(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, o = (r, e, t) => v(r, typeof e != "symbol" ? e + "" : e, t);
2
- const m = "https://api.wayflyer.com", I = "https://sandbox-api.wayflyer.com", E = (r) => {
2
+ const m = "https://api.wayflyer.com", I = "https://sandbox-api.wayflyer.com", k = (r) => {
3
3
  try {
4
4
  return JSON.parse(atob(r.split(".")[1]));
5
5
  } catch {
6
6
  return null;
7
7
  }
8
- }, b = {
8
+ }, E = {
9
9
  "Content-Type": "application/json"
10
10
  }, y = {
11
11
  event: "/financing/v1/company/event/",
12
12
  error: "/financing/v1/error/"
13
- }, g = "wf_session_v1", k = 1800 * 1e3, U = 1440 * 60 * 1e3;
13
+ }, g = "wf_session_v1", b = 1800 * 1e3, U = 1440 * 60 * 1e3;
14
14
  class D {
15
15
  getSessionId() {
16
16
  const e = Date.now();
@@ -18,8 +18,8 @@ class D {
18
18
  return (!t || this.isSessionExpired(t, e)) && (t = this.mintNewSession(e)), t.lastActivity = e, this.saveSession(t), t.sessionId;
19
19
  }
20
20
  isSessionExpired(e, t) {
21
- const s = t - e.lastActivity > k, n = t - e.createdAt > U;
22
- return s || n;
21
+ const i = t - e.lastActivity > b, n = t - e.createdAt > U;
22
+ return i || n;
23
23
  }
24
24
  mintNewSession(e) {
25
25
  return {
@@ -45,10 +45,10 @@ class D {
45
45
  }
46
46
  }
47
47
  const h = class a {
48
- constructor(e, t, s, n) {
49
- o(this, "baseUrl", null), o(this, "sessionManager"), o(this, "headers"), o(this, "entryPointVersion"), o(this, "sdkVersion"), this.companyToken = e, this.baseUrl = n ? I : m, this.sessionManager = new D(), this.entryPointVersion = t, this.sdkVersion = s, this.headers = {
50
- ...b,
51
- ...s ? { "X-SDK-Version": s } : {}
48
+ constructor(e, t, i, n) {
49
+ o(this, "baseUrl", null), o(this, "sessionManager"), o(this, "headers"), o(this, "entryPointVersion"), o(this, "sdkVersion"), this.companyToken = e, this.baseUrl = n ? I : m, this.sessionManager = new D(), this.entryPointVersion = t, this.sdkVersion = i, this.headers = {
50
+ ...E,
51
+ ...i ? { "X-SDK-Version": i } : {}
52
52
  };
53
53
  }
54
54
  get requestHeaders() {
@@ -65,13 +65,13 @@ const h = class a {
65
65
  static setGlobalInstance(e) {
66
66
  window.WayflyerLogger = e;
67
67
  }
68
- static initialize(e, t, s, n) {
68
+ static initialize(e, t, i, n) {
69
69
  a.getGlobalInstance() && console.warn("Logger re-initialized");
70
- const i = new a(e, t, s, n == null ? void 0 : n.isSandbox);
71
- a.setGlobalInstance(i);
70
+ const s = new a(e, t, i, n == null ? void 0 : n.isSandbox);
71
+ a.setGlobalInstance(s);
72
72
  }
73
73
  static getMandatoryProperties() {
74
- const e = a.getInstance(), { sdkVersion: t, companyToken: s, entryPointVersion: n } = e, i = E(s), [d, u] = (i == null ? void 0 : i.sub.split("|")) || [], f = i == null ? void 0 : i.user_id;
74
+ const e = a.getInstance(), { sdkVersion: t, companyToken: i, entryPointVersion: n } = e, s = k(i), [d, u] = (s == null ? void 0 : s.sub.split("|")) || [], f = s == null ? void 0 : s.user_id;
75
75
  return {
76
76
  partner_id: d,
77
77
  company_id: u,
@@ -88,22 +88,22 @@ const h = class a {
88
88
  }
89
89
  static async logEvent(e, t) {
90
90
  if (this.isDevEnvironment) return;
91
- const s = a.getInstance();
91
+ const i = a.getInstance();
92
92
  try {
93
93
  const n = {
94
94
  ...a.getMandatoryProperties(),
95
95
  ...t
96
- }, i = await fetch(s.baseUrl + y.event, {
96
+ }, s = await fetch(i.baseUrl + y.event, {
97
97
  method: "POST",
98
- headers: s.requestHeaders,
98
+ headers: i.requestHeaders,
99
99
  body: JSON.stringify({
100
100
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
101
101
  event_name: e,
102
102
  properties: n
103
103
  })
104
104
  });
105
- if (i.status === 200)
106
- return await i.json();
105
+ if (s.status === 200)
106
+ return await s.json();
107
107
  } catch (n) {
108
108
  console.error("Failed to log event", n);
109
109
  }
@@ -113,67 +113,71 @@ const h = class a {
113
113
  console.error(e);
114
114
  return;
115
115
  }
116
- const s = a.getInstance();
116
+ const i = a.getInstance();
117
117
  try {
118
118
  const n = {
119
119
  ...a.getMandatoryProperties(),
120
120
  ...t
121
- }, i = await fetch(s.baseUrl + y.error, {
121
+ }, s = await fetch(i.baseUrl + y.error, {
122
122
  method: "POST",
123
- headers: s.requestHeaders,
123
+ headers: i.requestHeaders,
124
124
  body: JSON.stringify({
125
125
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
126
126
  message: e,
127
127
  properties: n
128
128
  })
129
129
  });
130
- if (i.status === 200)
131
- return await i.json();
130
+ if (s.status === 200)
131
+ return await s.json();
132
132
  } catch (n) {
133
133
  console.warn("Failed to log error", n);
134
134
  }
135
135
  }
136
136
  };
137
137
  o(h, "isDevEnvironment", !1);
138
- let c = h;
138
+ let l = h;
139
139
  const S = (r, e) => {
140
140
  if (!window.WayflyerUiSdk)
141
141
  throw new Error("SDK code was fetched successfully, but WayflyerUiSdk is unavailable on window");
142
142
  const t = window.WayflyerUiSdk;
143
143
  return new t(r, e);
144
- }, P = "wayflyer-ui-package", _ = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4", w = "3.4.2", A = "UI_SDK_READY_EVENT", z = async (r, e) => window.WayflyerUiSdk ? S(r, e) : new Promise((s, n) => {
145
- const i = document.createElement("script");
146
- i.src = _, i.type = "module", i.id = P, i.async = !0, i.onerror = () => {
147
- n(new Error(`Failed to load UI SDK script from ${i.src}`));
144
+ }, P = "wayflyer-ui-package", _ = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4", w = "3.4.3", A = "UI_SDK_READY_EVENT", z = async (r, e) => window.WayflyerUiSdk ? S(r, e) : new Promise((i, n) => {
145
+ const s = document.createElement("script");
146
+ s.src = _, s.type = "module", s.id = P, s.async = !0, s.onerror = () => {
147
+ n(new Error(`Failed to load UI SDK script from ${s.src}`));
148
148
  };
149
149
  const d = () => {
150
150
  const u = S(r, e);
151
- s(u);
151
+ i(u);
152
152
  };
153
- window.addEventListener(A, d, { once: !0 }), document.head.appendChild(i);
154
- }), L = "ui";
155
- let l = null;
156
- class O {
153
+ window.addEventListener(A, d, { once: !0 }), document.head.appendChild(s);
154
+ }), N = "ui";
155
+ let c = null;
156
+ class L {
157
157
  static async loadSdk(e, t) {
158
- var n;
159
- l ?? (l = this.getLoadSdkPromise(e, t));
160
- const s = await l;
161
- return ((n = s == null ? void 0 : s.options) == null ? void 0 : n.language) !== (t == null ? void 0 : t.language) ? (l = this.getLoadSdkPromise(e, t), await l) : s;
158
+ var i;
159
+ c ?? (c = this.getLoadSdkPromise(e, t));
160
+ try {
161
+ const n = await c;
162
+ return ((i = n == null ? void 0 : n.options) == null ? void 0 : i.language) !== (t == null ? void 0 : t.language) || n.companyToken !== e ? (c = this.getLoadSdkPromise(e, t), await c) : n;
163
+ } catch (n) {
164
+ throw c = null, n;
165
+ }
162
166
  }
163
167
  static async getLoadSdkPromise(e, t) {
164
- const s = Date.now();
168
+ const i = Date.now();
165
169
  try {
166
- const n = await z(e, t), i = Date.now() - s;
167
- return c.initialize(e, w, n.sdkVersion, t), c.logEvent("ui_sdk_initialized", {
168
- entry_point_type: L,
169
- sdk_initialization_latency: i
170
+ const n = await z(e, t), s = Date.now() - i;
171
+ return l.initialize(e, w, n.sdkVersion, t), l.logEvent("ui_sdk_initialized", {
172
+ entry_point_type: N,
173
+ sdk_initialization_latency: s
170
174
  }), n;
171
175
  } catch (n) {
172
- const i = n instanceof Error ? n : new Error(String(n));
173
- throw c.initialize(e, w, void 0, t), c.logError(i.message), n;
176
+ const s = n instanceof Error ? n : new Error(String(n));
177
+ throw l.initialize(e, w, void 0, t), l.logError(s.message), n;
174
178
  }
175
179
  }
176
180
  }
177
181
  export {
178
- O as WayflyerUiSdk
182
+ L as WayflyerUiSdk
179
183
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wf-financing/ui-sdk",
3
- "version": "3.4.2",
3
+ "version": "3.4.3",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.es.js",
6
6
  "types": "dist/index.d.ts",