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