@wf-financing/ui-sdk 3.4.1 → 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 m=Object.defineProperty,p=(s,e,t)=>e in s?m(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,l=(s,e,t)=>p(s,typeof e!="symbol"?e+"":e,t);const v="https://api.wayflyer.com",I="https://sandbox-api.wayflyer.com",E=s=>{try{return JSON.parse(atob(s.split(".")[1]))}catch{return null}},b={"Content-Type":"application/json"},u={event:"/financing/v1/company/event/",error:"/financing/v1/error/"},y="wf_session_v1",U=1800*1e3,k=1440*60*1e3;class _{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>U,n=t-e.createdAt>k;return i||n}mintNewSession(e){return{sessionId:crypto.randomUUID(),createdAt:e,lastActivity:e}}loadSession(){try{const e=sessionStorage.getItem(y);return e?JSON.parse(e):null}catch{return null}}saveSession(e){try{sessionStorage.setItem(y,JSON.stringify(e))}catch{console.warn("Failed to save session context")}}}const f=class a{constructor(e,t,i){l(this,"baseUrl",null),l(this,"sessionManager"),l(this,"headers"),this.companyToken=e,this.baseUrl=i?I:v,this.sessionManager=new _,this.headers={...b,...t?{"X-SDK-Version":t}:{}}}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){a.getGlobalInstance()&&console.warn("Logger re-initialized");const n=new a(e,t,i==null?void 0:i.isSandbox);a.setGlobalInstance(n)}static getMandatoryProperties(e){const t=E(e),[i,n]=(t==null?void 0:t.sub.split("|"))||[],r=t==null?void 0:t.user_id;return{partner_id:i,company_id:n,user_id:r}}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(i.companyToken),...t},r=await fetch(i.baseUrl+u.event,{method:"POST",headers:i.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),event_name:e,properties:n})});if(r.status===200)return await r.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(i.companyToken),...t},r=await fetch(i.baseUrl+u.error,{method:"POST",headers:i.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),message:e,properties:n})});if(r.status===200)return await r.json()}catch(n){console.warn("Failed to log error",n)}}};l(f,"isDevEnvironment",!1);let o=f;const S=(s,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(s,e)},D="wayflyer-ui-package",A="https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4",g="3.4.1",w="UI_SDK_READY_EVENT",P=async(s,e)=>window.WayflyerUiSdk?S(s,e):new Promise((i,n)=>{const r=document.createElement("script");r.src=A,r.type="module",r.id=D,r.async=!0,r.onerror=()=>{n(new Error(`Failed to load UI SDK script from ${r.src}`))};const d=()=>{const h=S(s,e);i(h)};window.addEventListener(w,d,{once:!0}),setTimeout(()=>{n(new Error("UI SDK initialization timeout exceeded")),window.removeEventListener(w,d)},1e3),document.head.appendChild(r)}),z="ui";let c=null;class L{static async loadSdk(e,t){var n;c??(c=this.getLoadSdkPromise(e,t));const i=await c;return((n=i==null?void 0:i.options)==null?void 0:n.language)!==(t==null?void 0:t.language)?(c=this.getLoadSdkPromise(e,t),await c):i}static async getLoadSdkPromise(e,t){const i=Date.now();try{const n=await P(e,t),r=Date.now()-i;return o.initialize(e,n.sdkVersion,t),o.logEvent("ui_sdk_initialized",{entry_point_version:g,entry_point_type:z,sdk_initialization_latency:r}),n}catch(n){const r=n instanceof Error?n:new Error(String(n));throw o.initialize(e,void 0,t),o.logError(r.message,{entry_point_version:g}),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,24 +1,24 @@
1
- var m = Object.defineProperty, p = (r, e, t) => e in r ? m(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, l = (r, e, t) => p(r, typeof e != "symbol" ? e + "" : e, t);
2
- const v = "https://api.wayflyer.com", I = "https://sandbox-api.wayflyer.com", E = (r) => {
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", 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
- }, u = {
10
+ }, y = {
11
11
  event: "/financing/v1/company/event/",
12
12
  error: "/financing/v1/error/"
13
- }, y = "wf_session_v1", U = 1800 * 1e3, k = 1440 * 60 * 1e3;
14
- class _ {
13
+ }, g = "wf_session_v1", b = 1800 * 1e3, U = 1440 * 60 * 1e3;
14
+ class D {
15
15
  getSessionId() {
16
16
  const e = Date.now();
17
17
  let t = this.loadSession();
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 i = t - e.lastActivity > U, n = t - e.createdAt > k;
21
+ const i = t - e.lastActivity > b, n = t - e.createdAt > U;
22
22
  return i || n;
23
23
  }
24
24
  mintNewSession(e) {
@@ -30,7 +30,7 @@ class _ {
30
30
  }
31
31
  loadSession() {
32
32
  try {
33
- const e = sessionStorage.getItem(y);
33
+ const e = sessionStorage.getItem(g);
34
34
  return e ? JSON.parse(e) : null;
35
35
  } catch {
36
36
  return null;
@@ -38,17 +38,17 @@ class _ {
38
38
  }
39
39
  saveSession(e) {
40
40
  try {
41
- sessionStorage.setItem(y, JSON.stringify(e));
41
+ sessionStorage.setItem(g, JSON.stringify(e));
42
42
  } catch {
43
43
  console.warn("Failed to save session context");
44
44
  }
45
45
  }
46
46
  }
47
- const f = class a {
48
- constructor(e, t, i) {
49
- l(this, "baseUrl", null), l(this, "sessionManager"), l(this, "headers"), this.companyToken = e, this.baseUrl = i ? I : v, this.sessionManager = new _(), this.headers = {
50
- ...b,
51
- ...t ? { "X-SDK-Version": t } : {}
47
+ const h = class a {
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,14 +65,20 @@ const f = class a {
65
65
  static setGlobalInstance(e) {
66
66
  window.WayflyerLogger = e;
67
67
  }
68
- static initialize(e, t, i) {
68
+ static initialize(e, t, i, n) {
69
69
  a.getGlobalInstance() && console.warn("Logger re-initialized");
70
- const n = new a(e, t, i == null ? void 0 : i.isSandbox);
71
- a.setGlobalInstance(n);
70
+ const s = new a(e, t, i, n == null ? void 0 : n.isSandbox);
71
+ a.setGlobalInstance(s);
72
72
  }
73
- static getMandatoryProperties(e) {
74
- const t = E(e), [i, n] = (t == null ? void 0 : t.sub.split("|")) || [], s = t == null ? void 0 : t.user_id;
75
- return { partner_id: i, company_id: n, user_id: s };
73
+ static getMandatoryProperties() {
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
+ return {
76
+ partner_id: d,
77
+ company_id: u,
78
+ user_id: f,
79
+ entry_point_version: n,
80
+ ...t ? { sdk_version: t } : {}
81
+ };
76
82
  }
77
83
  static getInstance() {
78
84
  const e = a.getGlobalInstance();
@@ -85,9 +91,9 @@ const f = class a {
85
91
  const i = a.getInstance();
86
92
  try {
87
93
  const n = {
88
- ...a.getMandatoryProperties(i.companyToken),
94
+ ...a.getMandatoryProperties(),
89
95
  ...t
90
- }, s = await fetch(i.baseUrl + u.event, {
96
+ }, s = await fetch(i.baseUrl + y.event, {
91
97
  method: "POST",
92
98
  headers: i.requestHeaders,
93
99
  body: JSON.stringify({
@@ -110,9 +116,9 @@ const f = class a {
110
116
  const i = a.getInstance();
111
117
  try {
112
118
  const n = {
113
- ...a.getMandatoryProperties(i.companyToken),
119
+ ...a.getMandatoryProperties(),
114
120
  ...t
115
- }, s = await fetch(i.baseUrl + u.error, {
121
+ }, s = await fetch(i.baseUrl + y.error, {
116
122
  method: "POST",
117
123
  headers: i.requestHeaders,
118
124
  body: JSON.stringify({
@@ -128,48 +134,47 @@ const f = class a {
128
134
  }
129
135
  }
130
136
  };
131
- l(f, "isDevEnvironment", !1);
132
- let o = f;
133
- const g = (r, e) => {
137
+ o(h, "isDevEnvironment", !1);
138
+ let l = h;
139
+ const S = (r, e) => {
134
140
  if (!window.WayflyerUiSdk)
135
141
  throw new Error("SDK code was fetched successfully, but WayflyerUiSdk is unavailable on window");
136
142
  const t = window.WayflyerUiSdk;
137
143
  return new t(r, e);
138
- }, D = "wayflyer-ui-package", A = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4", S = "3.4.1", w = "UI_SDK_READY_EVENT", P = async (r, e) => window.WayflyerUiSdk ? g(r, e) : new Promise((i, n) => {
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) => {
139
145
  const s = document.createElement("script");
140
- s.src = A, s.type = "module", s.id = D, s.async = !0, s.onerror = () => {
146
+ s.src = _, s.type = "module", s.id = P, s.async = !0, s.onerror = () => {
141
147
  n(new Error(`Failed to load UI SDK script from ${s.src}`));
142
148
  };
143
149
  const d = () => {
144
- const h = g(r, e);
145
- i(h);
150
+ const u = S(r, e);
151
+ i(u);
146
152
  };
147
- window.addEventListener(w, d, { once: !0 }), setTimeout(() => {
148
- n(new Error("UI SDK initialization timeout exceeded")), window.removeEventListener(w, d);
149
- }, 1e3), document.head.appendChild(s);
150
- }), z = "ui";
153
+ window.addEventListener(A, d, { once: !0 }), document.head.appendChild(s);
154
+ }), N = "ui";
151
155
  let c = null;
152
156
  class L {
153
157
  static async loadSdk(e, t) {
154
- var n;
158
+ var i;
155
159
  c ?? (c = this.getLoadSdkPromise(e, t));
156
- const i = await c;
157
- return ((n = i == null ? void 0 : i.options) == null ? void 0 : n.language) !== (t == null ? void 0 : t.language) ? (c = this.getLoadSdkPromise(e, t), await c) : i;
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
+ }
158
166
  }
159
167
  static async getLoadSdkPromise(e, t) {
160
168
  const i = Date.now();
161
169
  try {
162
- const n = await P(e, t), s = Date.now() - i;
163
- return o.initialize(e, n.sdkVersion, t), o.logEvent("ui_sdk_initialized", {
164
- entry_point_version: S,
165
- entry_point_type: z,
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,
166
173
  sdk_initialization_latency: s
167
174
  }), n;
168
175
  } catch (n) {
169
176
  const s = n instanceof Error ? n : new Error(String(n));
170
- throw o.initialize(e, void 0, t), o.logError(s.message, {
171
- entry_point_version: S
172
- }), n;
177
+ throw l.initialize(e, w, void 0, t), l.logError(s.message), n;
173
178
  }
174
179
  }
175
180
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wf-financing/ui-sdk",
3
- "version": "3.4.1",
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",
@@ -16,7 +16,7 @@
16
16
  ],
17
17
  "dependencies": {
18
18
  "@wf-financing/embedded-types": "1.1.1",
19
- "@wf-financing/logger": "2.2.1"
19
+ "@wf-financing/logger": "2.2.2"
20
20
  },
21
21
  "devDependencies": {
22
22
  "vite": "^6.3.5",