@wf-financing/logger 2.2.2 → 2.2.3
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 +3 -3
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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:"/
|
|
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/financing",p="https://sandbox-api.wayflyer.com/financing",v=o=>{try{return JSON.parse(atob(o.split(".")[1]))}catch{return null}},w={"Content-Type":"application/json"},l={event:"/v1/company/event/",error:"/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,7 +1,7 @@
|
|
|
1
1
|
var u = Object.defineProperty;
|
|
2
2
|
var h = (o, t, e) => t in o ? u(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
|
|
3
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) => {
|
|
4
|
+
const I = "https://api.wayflyer.com/financing", p = "https://sandbox-api.wayflyer.com/financing", w = (o) => {
|
|
5
5
|
try {
|
|
6
6
|
return JSON.parse(atob(o.split(".")[1]));
|
|
7
7
|
} catch {
|
|
@@ -10,8 +10,8 @@ const I = "https://api.wayflyer.com", p = "https://sandbox-api.wayflyer.com", w
|
|
|
10
10
|
}, v = {
|
|
11
11
|
"Content-Type": "application/json"
|
|
12
12
|
}, c = {
|
|
13
|
-
event: "/
|
|
14
|
-
error: "/
|
|
13
|
+
event: "/v1/company/event/",
|
|
14
|
+
error: "/v1/error/"
|
|
15
15
|
}, l = "wf_session_v1", f = 1800 * 1e3, m = 1440 * 60 * 1e3;
|
|
16
16
|
class b {
|
|
17
17
|
getSessionId() {
|