@wf-financing/logger 1.1.3 → 2.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.
package/README.md CHANGED
@@ -10,12 +10,12 @@ The Logger utilizes a global singleton pattern to ensure the instance is shared
10
10
 
11
11
  ```jsx
12
12
  import { Logger } from '@wf-financing/logger';
13
- import { SdkOptionsType } from '@wf-financing/types';
13
+ import { UiSdkOptions } from '@wf-financing/types';
14
14
 
15
15
  const companyToken = 'your-company-token';
16
16
 
17
17
  // Optional: Configure for Sandbox environment
18
- const options: SdkOptionsType = { isSandbox: true };
18
+ const options: UiSdkOptions = { isSandbox: true };
19
19
 
20
20
  // Initialize the singleton
21
21
  Logger.initialize(companyToken, options);
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";var I=Object.defineProperty;var u=(o,t,e)=>t in o?I(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var l=(o,t,e)=>u(o,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p="https://api.wayflyer.com",h="https://sandbox-api.wayflyer.com",w=o=>{try{return JSON.parse(atob(o.split(".")[1]))}catch{return null}},d={"Content-Type":"application/json"},S={event:"/financing/v1/company/event/",error:"/financing/v1/error/"},y="wf_session_v1",f=1800*1e3,m=1440*60*1e3;class v{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>f,r=e-t.createdAt>m;return s||r}mintNewSession(t){return{sessionId:crypto.randomUUID(),createdAt:t,lastActivity:t}}loadSession(){try{const t=sessionStorage.getItem(y);return t?JSON.parse(t):null}catch{return null}}saveSession(t){try{sessionStorage.setItem(y,JSON.stringify(t))}catch{console.warn("Failed to save session context")}}}const n=class n{constructor(t,e){l(this,"baseUrl",null);l(this,"sessionManager");this.companyToken=t,this.baseUrl=e?h:p,this.sessionManager=new v}static getGlobalInstance(){return window.WayflyerLogger||null}static setGlobalInstance(t){window.WayflyerLogger=t}static initialize(t,e){n.getGlobalInstance()&&console.warn("Logger re-initialized");const s=new n(t,e==null?void 0:e.isSandbox);n.setGlobalInstance(s)}static getMandatoryProperties(t){const e=w(t),[s,r]=(e==null?void 0:e.sub.split("|"))||[],a=e==null?void 0:e.user_id;return{partnerId:s,companyId:r,userId:a}}static getInstance(){const t=n.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=n.getInstance(),r=s.sessionManager.getSessionId(),a={...d,Authorization:`Bearer ${s.companyToken}`,"X-Session-ID":r};try{const i={...n.getMandatoryProperties(s.companyToken),...e},c=await fetch(s.baseUrl+S.event,{method:"POST",headers:a,body:JSON.stringify({timestamp:new Date().toISOString(),event_name:t,properties:i})});if(c.status===200)return await c.json()}catch(i){console.error("Failed to log event",i)}}static async logError(t,e){if(this.isDevEnvironment){console.error(t);return}const s=n.getInstance(),r=s.sessionManager.getSessionId(),a={...d,"X-Session-ID":r};try{const i={...n.getMandatoryProperties(s.companyToken),...e},c=await fetch(s.baseUrl+S.error,{method:"POST",headers:a,body:JSON.stringify({timestamp:new Date().toISOString(),message:t,properties:i})});if(c.status===200)return await c.json()}catch(i){console.warn("Failed to log error",i)}}};l(n,"isDevEnvironment",!1);let g=n;exports.Logger=g;
1
+ "use strict";var I=Object.defineProperty;var u=(o,t,e)=>t in o?I(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var l=(o,t,e)=>u(o,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p="https://api.wayflyer.com",h="https://sandbox-api.wayflyer.com",w=o=>{try{return JSON.parse(atob(o.split(".")[1]))}catch{return null}},d={"Content-Type":"application/json"},S={event:"/financing/v1/company/event/",error:"/financing/v1/error/"},y="wf_session_v1",f=1800*1e3,m=1440*60*1e3;class v{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>f,i=e-t.createdAt>m;return s||i}mintNewSession(t){return{sessionId:crypto.randomUUID(),createdAt:t,lastActivity:t}}loadSession(){try{const t=sessionStorage.getItem(y);return t?JSON.parse(t):null}catch{return null}}saveSession(t){try{sessionStorage.setItem(y,JSON.stringify(t))}catch{console.warn("Failed to save session context")}}}const n=class n{constructor(t,e){l(this,"baseUrl",null);l(this,"sessionManager");this.companyToken=t,this.baseUrl=e?h:p,this.sessionManager=new v}static getGlobalInstance(){return window.WayflyerLogger||null}static setGlobalInstance(t){window.WayflyerLogger=t}static initialize(t,e){n.getGlobalInstance()&&console.warn("Logger re-initialized");const s=new n(t,e==null?void 0:e.isSandbox);n.setGlobalInstance(s)}static getMandatoryProperties(t){const e=w(t),[s,i]=(e==null?void 0:e.sub.split("|"))||[],a=e==null?void 0:e.user_id;return{partner_id:s,company_id:i,user_id:a}}static getInstance(){const t=n.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=n.getInstance(),i=s.sessionManager.getSessionId(),a={...d,Authorization:`Bearer ${s.companyToken}`,"X-Session-ID":i};try{const r={...n.getMandatoryProperties(s.companyToken),...e},c=await fetch(s.baseUrl+S.event,{method:"POST",headers:a,body:JSON.stringify({timestamp:new Date().toISOString(),event_name:t,properties:r})});if(c.status===200)return await c.json()}catch(r){console.error("Failed to log event",r)}}static async logError(t,e){if(this.isDevEnvironment){console.error(t);return}const s=n.getInstance(),i=s.sessionManager.getSessionId(),a={...d,"X-Session-ID":i};try{const r={...n.getMandatoryProperties(s.companyToken),...e},c=await fetch(s.baseUrl+S.error,{method:"POST",headers:a,body:JSON.stringify({timestamp:new Date().toISOString(),message:t,properties:r})});if(c.status===200)return await c.json()}catch(r){console.warn("Failed to log error",r)}}};l(n,"isDevEnvironment",!1);let g=n;exports.Logger=g;
package/dist/index.es.js CHANGED
@@ -1,5 +1,5 @@
1
- var y = Object.defineProperty;
2
- var p = (o, t, e) => t in o ? y(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
1
+ var I = Object.defineProperty;
2
+ var p = (o, t, e) => t in o ? I(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
3
3
  var l = (o, t, e) => p(o, typeof t != "symbol" ? t + "" : t, e);
4
4
  const u = "https://api.wayflyer.com", h = "https://sandbox-api.wayflyer.com", w = (o) => {
5
5
  try {
@@ -12,7 +12,7 @@ const u = "https://api.wayflyer.com", h = "https://sandbox-api.wayflyer.com", w
12
12
  }, g = {
13
13
  event: "/financing/v1/company/event/",
14
14
  error: "/financing/v1/error/"
15
- }, I = "wf_session_v1", f = 1800 * 1e3, m = 1440 * 60 * 1e3;
15
+ }, S = "wf_session_v1", f = 1800 * 1e3, m = 1440 * 60 * 1e3;
16
16
  class v {
17
17
  getSessionId() {
18
18
  const t = Date.now();
@@ -20,8 +20,8 @@ class v {
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 > f, r = e - t.createdAt > m;
24
- return s || r;
23
+ const s = e - t.lastActivity > f, i = e - t.createdAt > m;
24
+ return s || i;
25
25
  }
26
26
  mintNewSession(t) {
27
27
  return {
@@ -32,7 +32,7 @@ class v {
32
32
  }
33
33
  loadSession() {
34
34
  try {
35
- const t = sessionStorage.getItem(I);
35
+ const t = sessionStorage.getItem(S);
36
36
  return t ? JSON.parse(t) : null;
37
37
  } catch {
38
38
  return null;
@@ -40,7 +40,7 @@ class v {
40
40
  }
41
41
  saveSession(t) {
42
42
  try {
43
- sessionStorage.setItem(I, JSON.stringify(t));
43
+ sessionStorage.setItem(S, JSON.stringify(t));
44
44
  } catch {
45
45
  console.warn("Failed to save session context");
46
46
  }
@@ -64,8 +64,8 @@ const n = class n {
64
64
  n.setGlobalInstance(s);
65
65
  }
66
66
  static getMandatoryProperties(t) {
67
- const e = w(t), [s, r] = (e == null ? void 0 : e.sub.split("|")) || [], a = e == null ? void 0 : e.user_id;
68
- return { partnerId: s, companyId: r, userId: a };
67
+ const e = w(t), [s, i] = (e == null ? void 0 : e.sub.split("|")) || [], a = e == null ? void 0 : e.user_id;
68
+ return { partner_id: s, company_id: i, user_id: a };
69
69
  }
70
70
  static getInstance() {
71
71
  const t = n.getGlobalInstance();
@@ -75,13 +75,13 @@ const n = class n {
75
75
  }
76
76
  static async logEvent(t, e) {
77
77
  if (this.isDevEnvironment) return;
78
- const s = n.getInstance(), r = s.sessionManager.getSessionId(), a = {
78
+ const s = n.getInstance(), i = s.sessionManager.getSessionId(), a = {
79
79
  ...d,
80
80
  Authorization: `Bearer ${s.companyToken}`,
81
- "X-Session-ID": r
81
+ "X-Session-ID": i
82
82
  };
83
83
  try {
84
- const i = {
84
+ const r = {
85
85
  ...n.getMandatoryProperties(s.companyToken),
86
86
  ...e
87
87
  }, c = await fetch(s.baseUrl + g.event, {
@@ -90,13 +90,13 @@ const n = class n {
90
90
  body: JSON.stringify({
91
91
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
92
92
  event_name: t,
93
- properties: i
93
+ properties: r
94
94
  })
95
95
  });
96
96
  if (c.status === 200)
97
97
  return await c.json();
98
- } catch (i) {
99
- console.error("Failed to log event", i);
98
+ } catch (r) {
99
+ console.error("Failed to log event", r);
100
100
  }
101
101
  }
102
102
  static async logError(t, e) {
@@ -104,12 +104,12 @@ const n = class n {
104
104
  console.error(t);
105
105
  return;
106
106
  }
107
- const s = n.getInstance(), r = s.sessionManager.getSessionId(), a = {
107
+ const s = n.getInstance(), i = s.sessionManager.getSessionId(), a = {
108
108
  ...d,
109
- "X-Session-ID": r
109
+ "X-Session-ID": i
110
110
  };
111
111
  try {
112
- const i = {
112
+ const r = {
113
113
  ...n.getMandatoryProperties(s.companyToken),
114
114
  ...e
115
115
  }, c = await fetch(s.baseUrl + g.error, {
@@ -118,18 +118,18 @@ const n = class n {
118
118
  body: JSON.stringify({
119
119
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
120
120
  message: t,
121
- properties: i
121
+ properties: r
122
122
  })
123
123
  });
124
124
  if (c.status === 200)
125
125
  return await c.json();
126
- } catch (i) {
127
- console.warn("Failed to log error", i);
126
+ } catch (r) {
127
+ console.warn("Failed to log error", r);
128
128
  }
129
129
  }
130
130
  };
131
131
  l(n, "isDevEnvironment", !1);
132
- let S = n;
132
+ let y = n;
133
133
  export {
134
- S as Logger
134
+ y as Logger
135
135
  };
@@ -1,4 +1,4 @@
1
- import { SdkOptionsType } from '@wf-financing/embedded-types';
1
+ import { UiSdkOptions } from '@wf-financing/embedded-types';
2
2
 
3
3
  type Properties = {
4
4
  [key: string]: string | number | null;
@@ -11,7 +11,7 @@ export declare class Logger {
11
11
  private constructor();
12
12
  private static getGlobalInstance;
13
13
  private static setGlobalInstance;
14
- static initialize(companyToken: string, options?: SdkOptionsType): void;
14
+ static initialize(companyToken: string, options?: UiSdkOptions): void;
15
15
  private static getMandatoryProperties;
16
16
  private static getInstance;
17
17
  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": "1.1.3",
3
+ "version": "2.1.0",
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": "0.7.1"
18
+ "@wf-financing/embedded-types": "1.1.0"
19
19
  },
20
20
  "publishConfig": {
21
21
  "access": "public"