@wf-financing/logger 2.2.0 → 2.2.2

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";var g=Object.defineProperty;var u=(o,t,e)=>t in o?g(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var i=(o,t,e)=>u(o,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y="https://api.wayflyer.com",S="https://sandbox-api.wayflyer.com",h=o=>{try{return JSON.parse(atob(o.split(".")[1]))}catch{return null}},I={"Content-Type":"application/json"},l={event:"/financing/v1/company/event/",error:"/financing/v1/error/"},d="wf_session_v1",p=1800*1e3,w=1440*60*1e3;class f{getSessionId(){const t=Date.now();let e=this.loadSession();return(!e||this.isSessionExpired(e,t))&&(e=this.mintNewSession(t)),e.lastActivity=t,this.saveSession(e),e.sessionId}isSessionExpired(t,e){const s=e-t.lastActivity>p,n=e-t.createdAt>w;return s||n}mintNewSession(t){return{sessionId:crypto.randomUUID(),createdAt:t,lastActivity:t}}loadSession(){try{const t=sessionStorage.getItem(d);return t?JSON.parse(t):null}catch{return null}}saveSession(t){try{sessionStorage.setItem(d,JSON.stringify(t))}catch{console.warn("Failed to save session context")}}}const r=class r{constructor(t,e,s){i(this,"baseUrl",null);i(this,"sessionManager");i(this,"headers");this.companyToken=t,this.baseUrl=s?S:y,this.sessionManager=new f,this.headers={...I,...e?{"X-SDK-Version":e}:{}}}get requestHeaders(){const t=r.getInstance(),e=t.sessionManager.getSessionId();return{Authorization:`Bearer ${t.companyToken}`,"X-Session-ID":e,...t.headers}}static getGlobalInstance(){return window.WayflyerLogger||null}static setGlobalInstance(t){window.WayflyerLogger=t}static initialize(t,e,s){r.getGlobalInstance()&&console.warn("Logger re-initialized");const n=new r(t,e,s==null?void 0:s.isSandbox);r.setGlobalInstance(n)}static getMandatoryProperties(t){const e=h(t),[s,n]=(e==null?void 0:e.sub.split("|"))||[],a=e==null?void 0:e.user_id;return{partner_id:s,company_id:n,user_id:a}}static getInstance(){const t=r.getGlobalInstance();if(!t)throw new Error("Logger not initialized. Call initialize() first.");return t}static async logEvent(t,e){if(this.isDevEnvironment)return;const s=r.getInstance();try{const n={...r.getMandatoryProperties(s.companyToken),...e},a=await fetch(s.baseUrl+l.event,{method:"POST",headers:s.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),event_name:t,properties:n})});if(a.status===200)return await a.json()}catch(n){console.error("Failed to log event",n)}}static async logError(t,e){if(this.isDevEnvironment){console.error(t);return}const s=r.getInstance();try{const n={...r.getMandatoryProperties(s.companyToken),...e},a=await fetch(s.baseUrl+l.error,{method:"POST",headers:s.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),message:t,properties:n})});if(a.status===200)return await a.json()}catch(n){console.warn("Failed to log error",n)}}};i(r,"isDevEnvironment",!1);let c=r;exports.Logger=c;
1
+ "use strict";var S=Object.defineProperty;var h=(o,t,e)=>t in o?S(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var a=(o,t,e)=>h(o,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I="https://api.wayflyer.com",p="https://sandbox-api.wayflyer.com",v=o=>{try{return JSON.parse(atob(o.split(".")[1]))}catch{return null}},w={"Content-Type":"application/json"},l={event:"/financing/v1/company/event/",error:"/financing/v1/error/"},d="wf_session_v1",f=1800*1e3,m=1440*60*1e3;class b{getSessionId(){const t=Date.now();let e=this.loadSession();return(!e||this.isSessionExpired(e,t))&&(e=this.mintNewSession(t)),e.lastActivity=t,this.saveSession(e),e.sessionId}isSessionExpired(t,e){const n=e-t.lastActivity>f,s=e-t.createdAt>m;return n||s}mintNewSession(t){return{sessionId:crypto.randomUUID(),createdAt:t,lastActivity:t}}loadSession(){try{const t=sessionStorage.getItem(d);return t?JSON.parse(t):null}catch{return null}}saveSession(t){try{sessionStorage.setItem(d,JSON.stringify(t))}catch{console.warn("Failed to save session context")}}}const i=class i{constructor(t,e,n,s){a(this,"baseUrl",null);a(this,"sessionManager");a(this,"headers");a(this,"entryPointVersion");a(this,"sdkVersion");this.companyToken=t,this.baseUrl=s?p:I,this.sessionManager=new b,this.entryPointVersion=e,this.sdkVersion=n,this.headers={...w,...n?{"X-SDK-Version":n}:{}}}get requestHeaders(){const t=i.getInstance(),e=t.sessionManager.getSessionId();return{Authorization:`Bearer ${t.companyToken}`,"X-Session-ID":e,...t.headers}}static getGlobalInstance(){return window.WayflyerLogger||null}static setGlobalInstance(t){window.WayflyerLogger=t}static initialize(t,e,n,s){i.getGlobalInstance()&&console.warn("Logger re-initialized");const r=new i(t,e,n,s==null?void 0:s.isSandbox);i.setGlobalInstance(r)}static getMandatoryProperties(){const t=i.getInstance(),{sdkVersion:e,companyToken:n,entryPointVersion:s}=t,r=v(n),[g,y]=(r==null?void 0:r.sub.split("|"))||[],u=r==null?void 0:r.user_id;return{partner_id:g,company_id:y,user_id:u,entry_point_version:s,...e?{sdk_version:e}:{}}}static getInstance(){const t=i.getGlobalInstance();if(!t)throw new Error("Logger not initialized. Call initialize() first.");return t}static async logEvent(t,e){if(this.isDevEnvironment)return;const n=i.getInstance();try{const s={...i.getMandatoryProperties(),...e},r=await fetch(n.baseUrl+l.event,{method:"POST",headers:n.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),event_name:t,properties:s})});if(r.status===200)return await r.json()}catch(s){console.error("Failed to log event",s)}}static async logError(t,e){if(this.isDevEnvironment){console.error(t);return}const n=i.getInstance();try{const s={...i.getMandatoryProperties(),...e},r=await fetch(n.baseUrl+l.error,{method:"POST",headers:n.requestHeaders,body:JSON.stringify({timestamp:new Date().toISOString(),message:t,properties:s})});if(r.status===200)return await r.json()}catch(s){console.warn("Failed to log error",s)}}};a(i,"isDevEnvironment",!1);let c=i;exports.Logger=c;
package/dist/index.es.js CHANGED
@@ -1,27 +1,27 @@
1
- var g = Object.defineProperty;
2
- var y = (o, t, e) => t in o ? g(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
3
- var i = (o, t, e) => y(o, typeof t != "symbol" ? t + "" : t, e);
4
- const S = "https://api.wayflyer.com", u = "https://sandbox-api.wayflyer.com", h = (o) => {
1
+ var u = Object.defineProperty;
2
+ var h = (o, t, e) => t in o ? u(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
3
+ var a = (o, t, e) => h(o, typeof t != "symbol" ? t + "" : t, e);
4
+ const I = "https://api.wayflyer.com", p = "https://sandbox-api.wayflyer.com", w = (o) => {
5
5
  try {
6
6
  return JSON.parse(atob(o.split(".")[1]));
7
7
  } catch {
8
8
  return null;
9
9
  }
10
- }, I = {
10
+ }, v = {
11
11
  "Content-Type": "application/json"
12
12
  }, c = {
13
13
  event: "/financing/v1/company/event/",
14
14
  error: "/financing/v1/error/"
15
- }, l = "wf_session_v1", p = 1800 * 1e3, w = 1440 * 60 * 1e3;
16
- class f {
15
+ }, l = "wf_session_v1", f = 1800 * 1e3, m = 1440 * 60 * 1e3;
16
+ class b {
17
17
  getSessionId() {
18
18
  const t = Date.now();
19
19
  let e = this.loadSession();
20
20
  return (!e || this.isSessionExpired(e, t)) && (e = this.mintNewSession(t)), e.lastActivity = t, this.saveSession(e), e.sessionId;
21
21
  }
22
22
  isSessionExpired(t, e) {
23
- const s = e - t.lastActivity > p, n = e - t.createdAt > w;
24
- return s || n;
23
+ const n = e - t.lastActivity > f, s = e - t.createdAt > m;
24
+ return n || s;
25
25
  }
26
26
  mintNewSession(t) {
27
27
  return {
@@ -46,18 +46,20 @@ class f {
46
46
  }
47
47
  }
48
48
  }
49
- const r = class r {
50
- constructor(t, e, s) {
51
- i(this, "baseUrl", null);
52
- i(this, "sessionManager");
53
- i(this, "headers");
54
- this.companyToken = t, this.baseUrl = s ? u : S, this.sessionManager = new f(), this.headers = {
55
- ...I,
56
- ...e ? { "X-SDK-Version": e } : {}
49
+ const i = class i {
50
+ constructor(t, e, n, s) {
51
+ a(this, "baseUrl", null);
52
+ a(this, "sessionManager");
53
+ a(this, "headers");
54
+ a(this, "entryPointVersion");
55
+ a(this, "sdkVersion");
56
+ this.companyToken = t, this.baseUrl = s ? p : I, this.sessionManager = new b(), this.entryPointVersion = e, this.sdkVersion = n, this.headers = {
57
+ ...v,
58
+ ...n ? { "X-SDK-Version": n } : {}
57
59
  };
58
60
  }
59
61
  get requestHeaders() {
60
- const t = r.getInstance(), e = t.sessionManager.getSessionId();
62
+ const t = i.getInstance(), e = t.sessionManager.getSessionId();
61
63
  return {
62
64
  Authorization: `Bearer ${t.companyToken}`,
63
65
  "X-Session-ID": e,
@@ -70,41 +72,47 @@ const r = class r {
70
72
  static setGlobalInstance(t) {
71
73
  window.WayflyerLogger = t;
72
74
  }
73
- static initialize(t, e, s) {
74
- r.getGlobalInstance() && console.warn("Logger re-initialized");
75
- const n = new r(t, e, s == null ? void 0 : s.isSandbox);
76
- r.setGlobalInstance(n);
75
+ static initialize(t, e, n, s) {
76
+ i.getGlobalInstance() && console.warn("Logger re-initialized");
77
+ const r = new i(t, e, n, s == null ? void 0 : s.isSandbox);
78
+ i.setGlobalInstance(r);
77
79
  }
78
- static getMandatoryProperties(t) {
79
- const e = h(t), [s, n] = (e == null ? void 0 : e.sub.split("|")) || [], a = e == null ? void 0 : e.user_id;
80
- return { partner_id: s, company_id: n, user_id: a };
80
+ static getMandatoryProperties() {
81
+ const t = i.getInstance(), { sdkVersion: e, companyToken: n, entryPointVersion: s } = t, r = w(n), [y, g] = (r == null ? void 0 : r.sub.split("|")) || [], S = r == null ? void 0 : r.user_id;
82
+ return {
83
+ partner_id: y,
84
+ company_id: g,
85
+ user_id: S,
86
+ entry_point_version: s,
87
+ ...e ? { sdk_version: e } : {}
88
+ };
81
89
  }
82
90
  static getInstance() {
83
- const t = r.getGlobalInstance();
91
+ const t = i.getGlobalInstance();
84
92
  if (!t)
85
93
  throw new Error("Logger not initialized. Call initialize() first.");
86
94
  return t;
87
95
  }
88
96
  static async logEvent(t, e) {
89
97
  if (this.isDevEnvironment) return;
90
- const s = r.getInstance();
98
+ const n = i.getInstance();
91
99
  try {
92
- const n = {
93
- ...r.getMandatoryProperties(s.companyToken),
100
+ const s = {
101
+ ...i.getMandatoryProperties(),
94
102
  ...e
95
- }, a = await fetch(s.baseUrl + c.event, {
103
+ }, r = await fetch(n.baseUrl + c.event, {
96
104
  method: "POST",
97
- headers: s.requestHeaders,
105
+ headers: n.requestHeaders,
98
106
  body: JSON.stringify({
99
107
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
100
108
  event_name: t,
101
- properties: n
109
+ properties: s
102
110
  })
103
111
  });
104
- if (a.status === 200)
105
- return await a.json();
106
- } catch (n) {
107
- console.error("Failed to log event", n);
112
+ if (r.status === 200)
113
+ return await r.json();
114
+ } catch (s) {
115
+ console.error("Failed to log event", s);
108
116
  }
109
117
  }
110
118
  static async logError(t, e) {
@@ -112,29 +120,29 @@ const r = class r {
112
120
  console.error(t);
113
121
  return;
114
122
  }
115
- const s = r.getInstance();
123
+ const n = i.getInstance();
116
124
  try {
117
- const n = {
118
- ...r.getMandatoryProperties(s.companyToken),
125
+ const s = {
126
+ ...i.getMandatoryProperties(),
119
127
  ...e
120
- }, a = await fetch(s.baseUrl + c.error, {
128
+ }, r = await fetch(n.baseUrl + c.error, {
121
129
  method: "POST",
122
- headers: s.requestHeaders,
130
+ headers: n.requestHeaders,
123
131
  body: JSON.stringify({
124
132
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
125
133
  message: t,
126
- properties: n
134
+ properties: s
127
135
  })
128
136
  });
129
- if (a.status === 200)
130
- return await a.json();
131
- } catch (n) {
132
- console.warn("Failed to log error", n);
137
+ if (r.status === 200)
138
+ return await r.json();
139
+ } catch (s) {
140
+ console.warn("Failed to log error", s);
133
141
  }
134
142
  }
135
143
  };
136
- i(r, "isDevEnvironment", !1);
137
- let d = r;
144
+ a(i, "isDevEnvironment", !1);
145
+ let d = i;
138
146
  export {
139
147
  d as Logger
140
148
  };
@@ -9,11 +9,13 @@ export declare class Logger {
9
9
  private readonly baseUrl;
10
10
  private readonly sessionManager;
11
11
  private readonly headers;
12
+ private readonly entryPointVersion;
13
+ private readonly sdkVersion?;
12
14
  private constructor();
13
15
  private get requestHeaders();
14
16
  private static getGlobalInstance;
15
17
  private static setGlobalInstance;
16
- static initialize(companyToken: string, sdkVersion?: string, options?: UiSdkOptions): void;
18
+ static initialize(companyToken: string, entryPointVersion: string, sdkVersion?: string, options?: UiSdkOptions): void;
17
19
  private static getMandatoryProperties;
18
20
  private static getInstance;
19
21
  static logEvent(event_name: string, options?: Properties): Promise<void | any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wf-financing/logger",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  "dist"
16
16
  ],
17
17
  "dependencies": {
18
- "@wf-financing/embedded-types": "1.1.0"
18
+ "@wf-financing/embedded-types": "1.1.1"
19
19
  },
20
20
  "publishConfig": {
21
21
  "access": "public"