@wf-financing/ui-sdk 3.0.0 → 3.1.0

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.
@@ -0,0 +1 @@
1
+ export declare const APPLICATION_VERSION: string;
@@ -1,2 +1,3 @@
1
1
  export { WAYFLYER_UI_PACKAGE_ID } from './scriptId';
2
2
  export { UI_PACKAGE_URL } from './url';
3
+ export { APPLICATION_VERSION } from './applicationVersion';
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var h=Object.defineProperty,m=(r,e,t)=>e in r?h(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,c=(r,e,t)=>m(r,typeof e!="symbol"?e+"":e,t);const v="https://api.wayflyer.com",I="https://sandbox-api.wayflyer.com",b=r=>{try{return JSON.parse(atob(r.split(".")[1]))}catch{return null}},y={"Content-Type":"application/json"},u={event:"/financing/v1/company/event/",error:"/financing/v1/error/"},g="wf_session_v1",U=1800*1e3,k=1440*60*1e3;class E{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 n=t-e.lastActivity>U,s=t-e.createdAt>k;return n||s}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 p=class i{constructor(e,t){c(this,"baseUrl",null),c(this,"sessionManager"),this.companyToken=e,this.baseUrl=t?I:v,this.sessionManager=new E}static getGlobalInstance(){return window.WayflyerLogger||null}static setGlobalInstance(e){window.WayflyerLogger=e}static initialize(e,t){i.getGlobalInstance()&&console.warn("Logger re-initialized");const n=new i(e,t==null?void 0:t.isSandbox);i.setGlobalInstance(n)}static getMandatoryProperties(e){const t=b(e),[n,s]=(t==null?void 0:t.sub.split("|"))||[],a=t==null?void 0:t.user_id;return{partnerId:n,companyId:s,userId:a}}static getInstance(){const e=i.getGlobalInstance();if(!e)throw new Error("Logger not initialized. Call initialize() first.");return e}static async logEvent(e,t){if(this.isDevEnvironment)return;const n=i.getInstance(),s=n.sessionManager.getSessionId(),a={...y,Authorization:`Bearer ${n.companyToken}`,"X-Session-ID":s};try{const o={...i.getMandatoryProperties(n.companyToken),...t},l=await fetch(n.baseUrl+u.event,{method:"POST",headers:a,body:JSON.stringify({timestamp:new Date().toISOString(),event_name:e,properties:o})});if(l.status===200)return await l.json()}catch(o){console.error("Failed to log event",o)}}static async logError(e,t){if(this.isDevEnvironment){console.error(e);return}const n=i.getInstance(),s=n.sessionManager.getSessionId(),a={...y,"X-Session-ID":s};try{const o={...i.getMandatoryProperties(n.companyToken),...t},l=await fetch(n.baseUrl+u.error,{method:"POST",headers:a,body:JSON.stringify({timestamp:new Date().toISOString(),message:e,properties:o})});if(l.status===200)return await l.json()}catch(o){console.warn("Failed to log error",o)}}};c(p,"isDevEnvironment",!1);let d=p;const S="wayflyer-ui-package",A="https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4",w=(r,e)=>{if(!window.WayflyerUiSdk)throw new Error("Failed to load WayflyerUiSdk from the script.");const t=window.WayflyerUiSdk;return new t(r,e)},f=(r,e,t)=>new Promise((n,s)=>{r.onload=()=>{try{n(w(e,t))}catch(a){s(a)}}}),D=async(r,e)=>{try{const t=document.getElementById(S);if(window.WayflyerUiSdk)return w(r,e);if(t)return f(t,r,e);const n=document.createElement("script");return n.src=A,n.type="module",n.id=S,n.async=!0,n.onerror=()=>d.logError("Failed to load ui SDK script"),document.head.appendChild(n),f(n,r,e)}catch{throw new Error("Failed to load script")}};class O{static async loadSdk(e,t){d.initialize(e,t);const n=await D(e,t);return d.logEvent("ui_sdk_initialized"),n}}exports.WayflyerUiSdk=O;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var m=Object.defineProperty,h=(i,e,t)=>e in i?m(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,l=(i,e,t)=>h(i,typeof e!="symbol"?e+"":e,t);const v="https://api.wayflyer.com",I="https://sandbox-api.wayflyer.com",b=i=>{try{return JSON.parse(atob(i.split(".")[1]))}catch{return null}},y={"Content-Type":"application/json"},u={event:"/financing/v1/company/event/",error:"/financing/v1/error/"},g="wf_session_v1",k=1800*1e3,U=1440*60*1e3;class E{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 n=t-e.lastActivity>k,s=t-e.createdAt>U;return n||s}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 w=class a{constructor(e,t){l(this,"baseUrl",null),l(this,"sessionManager"),this.companyToken=e,this.baseUrl=t?I:v,this.sessionManager=new E}static getGlobalInstance(){return window.WayflyerLogger||null}static setGlobalInstance(e){window.WayflyerLogger=e}static initialize(e,t){a.getGlobalInstance()&&console.warn("Logger re-initialized");const n=new a(e,t==null?void 0:t.isSandbox);a.setGlobalInstance(n)}static getMandatoryProperties(e){const t=b(e),[n,s]=(t==null?void 0:t.sub.split("|"))||[],o=t==null?void 0:t.user_id;return{partner_id:n,company_id:s,user_id:o}}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 n=a.getInstance(),s=n.sessionManager.getSessionId(),o={...y,Authorization:`Bearer ${n.companyToken}`,"X-Session-ID":s};try{const r={...a.getMandatoryProperties(n.companyToken),...t},c=await fetch(n.baseUrl+u.event,{method:"POST",headers:o,body:JSON.stringify({timestamp:new Date().toISOString(),event_name:e,properties:r})});if(c.status===200)return await c.json()}catch(r){console.error("Failed to log event",r)}}static async logError(e,t){if(this.isDevEnvironment){console.error(e);return}const n=a.getInstance(),s=n.sessionManager.getSessionId(),o={...y,"X-Session-ID":s};try{const r={...a.getMandatoryProperties(n.companyToken),...t},c=await fetch(n.baseUrl+u.error,{method:"POST",headers:o,body:JSON.stringify({timestamp:new Date().toISOString(),message:e,properties:r})});if(c.status===200)return await c.json()}catch(r){console.warn("Failed to log error",r)}}};l(w,"isDevEnvironment",!1);let d=w;const p="wayflyer-ui-package",A="https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4",z="3.1.0",f=(i,e)=>{if(!window.WayflyerUiSdk)throw new Error("Failed to load WayflyerUiSdk from the script.");const t=window.WayflyerUiSdk;return new t(i,e)},S=(i,e,t)=>new Promise((n,s)=>{i.onload=()=>{try{n(f(e,t))}catch(o){s(o)}}}),D=async(i,e)=>{try{const t=document.getElementById(p);if(window.WayflyerUiSdk)return f(i,e);if(t)return S(t,i,e);const n=document.createElement("script");return n.src=A,n.type="module",n.id=p,n.async=!0,n.onerror=()=>d.logError("Failed to load ui SDK script"),document.head.appendChild(n),S(n,i,e)}catch{throw new Error("Failed to load script")}};class O{static async loadSdk(e,t){const n=Date.now();d.initialize(e,t);const s=await D(e,t),r=Date.now()-n;return d.logEvent("ui_sdk_initialized",{entry_point_version:z,sdk_version:(s==null?void 0:s.sdkVersion)??"unknown version",sdk_initialization_latency:r}),s}}exports.WayflyerUiSdk=O;
package/dist/index.es.js CHANGED
@@ -1,7 +1,7 @@
1
- var h = Object.defineProperty, m = (r, e, t) => e in r ? h(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, l = (r, e, t) => m(r, typeof e != "symbol" ? e + "" : e, t);
2
- const v = "https://api.wayflyer.com", I = "https://sandbox-api.wayflyer.com", b = (r) => {
1
+ var f = Object.defineProperty, h = (i, e, t) => e in i ? f(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, l = (i, e, t) => h(i, typeof e != "symbol" ? e + "" : e, t);
2
+ const v = "https://api.wayflyer.com", I = "https://sandbox-api.wayflyer.com", k = (i) => {
3
3
  try {
4
- return JSON.parse(atob(r.split(".")[1]));
4
+ return JSON.parse(atob(i.split(".")[1]));
5
5
  } catch {
6
6
  return null;
7
7
  }
@@ -10,15 +10,15 @@ const v = "https://api.wayflyer.com", I = "https://sandbox-api.wayflyer.com", b
10
10
  }, u = {
11
11
  event: "/financing/v1/company/event/",
12
12
  error: "/financing/v1/error/"
13
- }, g = "wf_session_v1", U = 1800 * 1e3, E = 1440 * 60 * 1e3;
14
- class k {
13
+ }, g = "wf_session_v1", b = 1800 * 1e3, E = 1440 * 60 * 1e3;
14
+ class U {
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 n = t - e.lastActivity > U, s = t - e.createdAt > E;
21
+ const n = t - e.lastActivity > b, s = t - e.createdAt > E;
22
22
  return n || s;
23
23
  }
24
24
  mintNewSession(e) {
@@ -44,9 +44,9 @@ class k {
44
44
  }
45
45
  }
46
46
  }
47
- const w = class i {
47
+ const S = class a {
48
48
  constructor(e, t) {
49
- l(this, "baseUrl", null), l(this, "sessionManager"), this.companyToken = e, this.baseUrl = t ? I : v, this.sessionManager = new k();
49
+ l(this, "baseUrl", null), l(this, "sessionManager"), this.companyToken = e, this.baseUrl = t ? I : v, this.sessionManager = new U();
50
50
  }
51
51
  static getGlobalInstance() {
52
52
  return window.WayflyerLogger || null;
@@ -55,44 +55,44 @@ const w = class i {
55
55
  window.WayflyerLogger = e;
56
56
  }
57
57
  static initialize(e, t) {
58
- i.getGlobalInstance() && console.warn("Logger re-initialized");
59
- const n = new i(e, t == null ? void 0 : t.isSandbox);
60
- i.setGlobalInstance(n);
58
+ a.getGlobalInstance() && console.warn("Logger re-initialized");
59
+ const n = new a(e, t == null ? void 0 : t.isSandbox);
60
+ a.setGlobalInstance(n);
61
61
  }
62
62
  static getMandatoryProperties(e) {
63
- const t = b(e), [n, s] = (t == null ? void 0 : t.sub.split("|")) || [], a = t == null ? void 0 : t.user_id;
64
- return { partnerId: n, companyId: s, userId: a };
63
+ const t = k(e), [n, s] = (t == null ? void 0 : t.sub.split("|")) || [], o = t == null ? void 0 : t.user_id;
64
+ return { partner_id: n, company_id: s, user_id: o };
65
65
  }
66
66
  static getInstance() {
67
- const e = i.getGlobalInstance();
67
+ const e = a.getGlobalInstance();
68
68
  if (!e)
69
69
  throw new Error("Logger not initialized. Call initialize() first.");
70
70
  return e;
71
71
  }
72
72
  static async logEvent(e, t) {
73
73
  if (this.isDevEnvironment) return;
74
- const n = i.getInstance(), s = n.sessionManager.getSessionId(), a = {
74
+ const n = a.getInstance(), s = n.sessionManager.getSessionId(), o = {
75
75
  ...y,
76
76
  Authorization: `Bearer ${n.companyToken}`,
77
77
  "X-Session-ID": s
78
78
  };
79
79
  try {
80
- const o = {
81
- ...i.getMandatoryProperties(n.companyToken),
80
+ const r = {
81
+ ...a.getMandatoryProperties(n.companyToken),
82
82
  ...t
83
83
  }, c = await fetch(n.baseUrl + u.event, {
84
84
  method: "POST",
85
- headers: a,
85
+ headers: o,
86
86
  body: JSON.stringify({
87
87
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
88
88
  event_name: e,
89
- properties: o
89
+ properties: r
90
90
  })
91
91
  });
92
92
  if (c.status === 200)
93
93
  return await c.json();
94
- } catch (o) {
95
- console.error("Failed to log event", o);
94
+ } catch (r) {
95
+ console.error("Failed to log event", r);
96
96
  }
97
97
  }
98
98
  static async logError(e, t) {
@@ -100,63 +100,68 @@ const w = class i {
100
100
  console.error(e);
101
101
  return;
102
102
  }
103
- const n = i.getInstance(), s = n.sessionManager.getSessionId(), a = {
103
+ const n = a.getInstance(), s = n.sessionManager.getSessionId(), o = {
104
104
  ...y,
105
105
  "X-Session-ID": s
106
106
  };
107
107
  try {
108
- const o = {
109
- ...i.getMandatoryProperties(n.companyToken),
108
+ const r = {
109
+ ...a.getMandatoryProperties(n.companyToken),
110
110
  ...t
111
111
  }, c = await fetch(n.baseUrl + u.error, {
112
112
  method: "POST",
113
- headers: a,
113
+ headers: o,
114
114
  body: JSON.stringify({
115
115
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
116
116
  message: e,
117
- properties: o
117
+ properties: r
118
118
  })
119
119
  });
120
120
  if (c.status === 200)
121
121
  return await c.json();
122
- } catch (o) {
123
- console.warn("Failed to log error", o);
122
+ } catch (r) {
123
+ console.warn("Failed to log error", r);
124
124
  }
125
125
  }
126
126
  };
127
- l(w, "isDevEnvironment", !1);
128
- let d = w;
129
- const S = "wayflyer-ui-package", A = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4", f = (r, e) => {
127
+ l(S, "isDevEnvironment", !1);
128
+ let d = S;
129
+ const p = "wayflyer-ui-package", A = "https://embedded-finance-frontend.vercel.app/npm/@wf-financing/ui@4", z = "3.1.0", m = (i, e) => {
130
130
  if (!window.WayflyerUiSdk)
131
131
  throw new Error("Failed to load WayflyerUiSdk from the script.");
132
132
  const t = window.WayflyerUiSdk;
133
- return new t(r, e);
134
- }, p = (r, e, t) => new Promise((n, s) => {
135
- r.onload = () => {
133
+ return new t(i, e);
134
+ }, w = (i, e, t) => new Promise((n, s) => {
135
+ i.onload = () => {
136
136
  try {
137
- n(f(e, t));
138
- } catch (a) {
139
- s(a);
137
+ n(m(e, t));
138
+ } catch (o) {
139
+ s(o);
140
140
  }
141
141
  };
142
- }), D = async (r, e) => {
142
+ }), D = async (i, e) => {
143
143
  try {
144
- const t = document.getElementById(S);
144
+ const t = document.getElementById(p);
145
145
  if (window.WayflyerUiSdk)
146
- return f(r, e);
146
+ return m(i, e);
147
147
  if (t)
148
- return p(t, r, e);
148
+ return w(t, i, e);
149
149
  const n = document.createElement("script");
150
- return n.src = A, n.type = "module", n.id = S, n.async = !0, n.onerror = () => d.logError("Failed to load ui SDK script"), document.head.appendChild(n), p(n, r, e);
150
+ return n.src = A, n.type = "module", n.id = p, n.async = !0, n.onerror = () => d.logError("Failed to load ui SDK script"), document.head.appendChild(n), w(n, i, e);
151
151
  } catch {
152
152
  throw new Error("Failed to load script");
153
153
  }
154
154
  };
155
155
  class O {
156
156
  static async loadSdk(e, t) {
157
+ const n = Date.now();
157
158
  d.initialize(e, t);
158
- const n = await D(e, t);
159
- return d.logEvent("ui_sdk_initialized"), n;
159
+ const s = await D(e, t), r = Date.now() - n;
160
+ return d.logEvent("ui_sdk_initialized", {
161
+ entry_point_version: z,
162
+ sdk_version: (s == null ? void 0 : s.sdkVersion) ?? "unknown version",
163
+ sdk_initialization_latency: r
164
+ }), s;
160
165
  }
161
166
  }
162
167
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wf-financing/ui-sdk",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,8 +15,8 @@
15
15
  "dist"
16
16
  ],
17
17
  "dependencies": {
18
- "@wf-financing/embedded-types": "1.0.0",
19
- "@wf-financing/logger": "2.0.0"
18
+ "@wf-financing/embedded-types": "1.1.0",
19
+ "@wf-financing/logger": "2.1.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "vite": "^6.3.5",