@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 +1 -1
- package/dist/index.es.js +56 -48
- package/dist/logger/index.d.ts +3 -1
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
const
|
|
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
|
-
},
|
|
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",
|
|
16
|
-
class
|
|
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
|
|
24
|
-
return
|
|
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
|
|
50
|
-
constructor(t, e, s) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this
|
|
55
|
-
|
|
56
|
-
|
|
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 =
|
|
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
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
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(
|
|
79
|
-
const e =
|
|
80
|
-
return {
|
|
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 =
|
|
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
|
|
98
|
+
const n = i.getInstance();
|
|
91
99
|
try {
|
|
92
|
-
const
|
|
93
|
-
...
|
|
100
|
+
const s = {
|
|
101
|
+
...i.getMandatoryProperties(),
|
|
94
102
|
...e
|
|
95
|
-
},
|
|
103
|
+
}, r = await fetch(n.baseUrl + c.event, {
|
|
96
104
|
method: "POST",
|
|
97
|
-
headers:
|
|
105
|
+
headers: n.requestHeaders,
|
|
98
106
|
body: JSON.stringify({
|
|
99
107
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
100
108
|
event_name: t,
|
|
101
|
-
properties:
|
|
109
|
+
properties: s
|
|
102
110
|
})
|
|
103
111
|
});
|
|
104
|
-
if (
|
|
105
|
-
return await
|
|
106
|
-
} catch (
|
|
107
|
-
console.error("Failed to log event",
|
|
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
|
|
123
|
+
const n = i.getInstance();
|
|
116
124
|
try {
|
|
117
|
-
const
|
|
118
|
-
...
|
|
125
|
+
const s = {
|
|
126
|
+
...i.getMandatoryProperties(),
|
|
119
127
|
...e
|
|
120
|
-
},
|
|
128
|
+
}, r = await fetch(n.baseUrl + c.error, {
|
|
121
129
|
method: "POST",
|
|
122
|
-
headers:
|
|
130
|
+
headers: n.requestHeaders,
|
|
123
131
|
body: JSON.stringify({
|
|
124
132
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
125
133
|
message: t,
|
|
126
|
-
properties:
|
|
134
|
+
properties: s
|
|
127
135
|
})
|
|
128
136
|
});
|
|
129
|
-
if (
|
|
130
|
-
return await
|
|
131
|
-
} catch (
|
|
132
|
-
console.warn("Failed to log error",
|
|
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
|
|
137
|
-
let d =
|
|
144
|
+
a(i, "isDevEnvironment", !1);
|
|
145
|
+
let d = i;
|
|
138
146
|
export {
|
|
139
147
|
d as Logger
|
|
140
148
|
};
|
package/dist/logger/index.d.ts
CHANGED
|
@@ -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.
|
|
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.
|
|
18
|
+
"@wf-financing/embedded-types": "1.1.1"
|
|
19
19
|
},
|
|
20
20
|
"publishConfig": {
|
|
21
21
|
"access": "public"
|