@tracelog/lib 0.0.3 → 0.0.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/browser/tracelog.js +458 -445
- package/dist/cjs/constants/api.constants.d.ts +0 -1
- package/dist/cjs/constants/api.constants.js +1 -2
- package/dist/cjs/managers/sender.manager.js +22 -5
- package/dist/esm/constants/api.constants.d.ts +0 -1
- package/dist/esm/constants/api.constants.js +0 -1
- package/dist/esm/managers/sender.manager.js +23 -6
- package/package.json +1 -1
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_CONFIG = exports.DEFAULT_API_CONFIG =
|
|
3
|
+
exports.DEFAULT_CONFIG = exports.DEFAULT_API_CONFIG = void 0;
|
|
4
4
|
const limits_constants_1 = require("./limits.constants");
|
|
5
5
|
const timing_constants_1 = require("./timing.constants");
|
|
6
|
-
exports.API_BASE_URL = 'https://api.tracelog.io';
|
|
7
6
|
exports.DEFAULT_API_CONFIG = {
|
|
8
7
|
samplingRate: limits_constants_1.DEFAULT_SAMPLING_RATE,
|
|
9
8
|
tags: [],
|
|
@@ -86,6 +86,8 @@ class SenderManager extends state_manager_1.StateManager {
|
|
|
86
86
|
try {
|
|
87
87
|
const response = await fetch(url, {
|
|
88
88
|
method: 'POST',
|
|
89
|
+
mode: 'cors',
|
|
90
|
+
credentials: 'omit',
|
|
89
91
|
headers: {
|
|
90
92
|
'Content-Type': 'application/json',
|
|
91
93
|
},
|
|
@@ -94,7 +96,13 @@ class SenderManager extends state_manager_1.StateManager {
|
|
|
94
96
|
return response.ok;
|
|
95
97
|
}
|
|
96
98
|
catch (error) {
|
|
97
|
-
|
|
99
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
100
|
+
const isCorsError = errorMessage.includes('CORS') || errorMessage.includes('NotSameOrigin') || errorMessage.includes('blocked');
|
|
101
|
+
logging_1.debugLog.error('SenderManager', 'Failed to send events async', {
|
|
102
|
+
error: errorMessage,
|
|
103
|
+
isCorsError,
|
|
104
|
+
url: url.replace(/\/\/[^/]+/, '//[DOMAIN]'),
|
|
105
|
+
});
|
|
98
106
|
return false;
|
|
99
107
|
}
|
|
100
108
|
}
|
|
@@ -113,24 +121,33 @@ class SenderManager extends state_manager_1.StateManager {
|
|
|
113
121
|
return navigator.sendBeacon(url, payload);
|
|
114
122
|
}
|
|
115
123
|
sendSyncXHR(url, payload) {
|
|
124
|
+
const xhr = new XMLHttpRequest();
|
|
116
125
|
try {
|
|
117
|
-
const xhr = new XMLHttpRequest();
|
|
118
126
|
xhr.open('POST', url, false);
|
|
119
127
|
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
128
|
+
xhr.withCredentials = false;
|
|
120
129
|
xhr.timeout = constants_1.SYNC_XHR_TIMEOUT_MS;
|
|
121
130
|
xhr.send(payload);
|
|
122
131
|
return xhr.status >= 200 && xhr.status < 300;
|
|
123
132
|
}
|
|
124
133
|
catch (error) {
|
|
125
|
-
|
|
134
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
135
|
+
const isCorsError = errorMessage.includes('CORS') || errorMessage.includes('NotSameOrigin') || errorMessage.includes('blocked');
|
|
136
|
+
logging_1.debugLog.error('SenderManager', 'Sync XHR failed', {
|
|
137
|
+
error: errorMessage,
|
|
138
|
+
isCorsError,
|
|
139
|
+
status: xhr.status ?? 'unknown',
|
|
140
|
+
url: url.replace(/\/\/[^/]+/, '//[DOMAIN]'),
|
|
141
|
+
});
|
|
126
142
|
return false;
|
|
127
143
|
}
|
|
128
144
|
}
|
|
129
145
|
prepareRequest(body) {
|
|
130
146
|
const useLocalServer = this.get('config').id === types_1.SpecialProjectId.HttpLocal;
|
|
131
|
-
const baseUrl = useLocalServer ? window.location.origin :
|
|
147
|
+
const baseUrl = useLocalServer ? window.location.origin : this.get('apiUrl');
|
|
148
|
+
const url = `${baseUrl}/collect`;
|
|
132
149
|
return {
|
|
133
|
-
url
|
|
150
|
+
url,
|
|
134
151
|
payload: JSON.stringify(body),
|
|
135
152
|
};
|
|
136
153
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_SAMPLING_RATE } from './limits.constants';
|
|
2
2
|
import { DEFAULT_SESSION_TIMEOUT_MS } from './timing.constants';
|
|
3
|
-
export const API_BASE_URL = 'https://api.tracelog.io';
|
|
4
3
|
export const DEFAULT_API_CONFIG = {
|
|
5
4
|
samplingRate: DEFAULT_SAMPLING_RATE,
|
|
6
5
|
tags: [],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { QUEUE_KEY, RETRY_BACKOFF_INITIAL, RETRY_BACKOFF_MAX, RATE_LIMIT_INTERVAL, EVENT_EXPIRY_HOURS, SYNC_XHR_TIMEOUT_MS,
|
|
1
|
+
import { QUEUE_KEY, RETRY_BACKOFF_INITIAL, RETRY_BACKOFF_MAX, RATE_LIMIT_INTERVAL, EVENT_EXPIRY_HOURS, SYNC_XHR_TIMEOUT_MS, } from '../constants';
|
|
2
2
|
import { SpecialProjectId, Mode } from '../types';
|
|
3
3
|
import { debugLog } from '../utils/logging';
|
|
4
4
|
import { StateManager } from './state.manager';
|
|
@@ -83,6 +83,8 @@ export class SenderManager extends StateManager {
|
|
|
83
83
|
try {
|
|
84
84
|
const response = await fetch(url, {
|
|
85
85
|
method: 'POST',
|
|
86
|
+
mode: 'cors',
|
|
87
|
+
credentials: 'omit',
|
|
86
88
|
headers: {
|
|
87
89
|
'Content-Type': 'application/json',
|
|
88
90
|
},
|
|
@@ -91,7 +93,13 @@ export class SenderManager extends StateManager {
|
|
|
91
93
|
return response.ok;
|
|
92
94
|
}
|
|
93
95
|
catch (error) {
|
|
94
|
-
|
|
96
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
97
|
+
const isCorsError = errorMessage.includes('CORS') || errorMessage.includes('NotSameOrigin') || errorMessage.includes('blocked');
|
|
98
|
+
debugLog.error('SenderManager', 'Failed to send events async', {
|
|
99
|
+
error: errorMessage,
|
|
100
|
+
isCorsError,
|
|
101
|
+
url: url.replace(/\/\/[^/]+/, '//[DOMAIN]'),
|
|
102
|
+
});
|
|
95
103
|
return false;
|
|
96
104
|
}
|
|
97
105
|
}
|
|
@@ -110,24 +118,33 @@ export class SenderManager extends StateManager {
|
|
|
110
118
|
return navigator.sendBeacon(url, payload);
|
|
111
119
|
}
|
|
112
120
|
sendSyncXHR(url, payload) {
|
|
121
|
+
const xhr = new XMLHttpRequest();
|
|
113
122
|
try {
|
|
114
|
-
const xhr = new XMLHttpRequest();
|
|
115
123
|
xhr.open('POST', url, false);
|
|
116
124
|
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
125
|
+
xhr.withCredentials = false;
|
|
117
126
|
xhr.timeout = SYNC_XHR_TIMEOUT_MS;
|
|
118
127
|
xhr.send(payload);
|
|
119
128
|
return xhr.status >= 200 && xhr.status < 300;
|
|
120
129
|
}
|
|
121
130
|
catch (error) {
|
|
122
|
-
|
|
131
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
132
|
+
const isCorsError = errorMessage.includes('CORS') || errorMessage.includes('NotSameOrigin') || errorMessage.includes('blocked');
|
|
133
|
+
debugLog.error('SenderManager', 'Sync XHR failed', {
|
|
134
|
+
error: errorMessage,
|
|
135
|
+
isCorsError,
|
|
136
|
+
status: xhr.status ?? 'unknown',
|
|
137
|
+
url: url.replace(/\/\/[^/]+/, '//[DOMAIN]'),
|
|
138
|
+
});
|
|
123
139
|
return false;
|
|
124
140
|
}
|
|
125
141
|
}
|
|
126
142
|
prepareRequest(body) {
|
|
127
143
|
const useLocalServer = this.get('config').id === SpecialProjectId.HttpLocal;
|
|
128
|
-
const baseUrl = useLocalServer ? window.location.origin :
|
|
144
|
+
const baseUrl = useLocalServer ? window.location.origin : this.get('apiUrl');
|
|
145
|
+
const url = `${baseUrl}/collect`;
|
|
129
146
|
return {
|
|
130
|
-
url
|
|
147
|
+
url,
|
|
131
148
|
payload: JSON.stringify(body),
|
|
132
149
|
};
|
|
133
150
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tracelog/lib",
|
|
3
3
|
"description": "JavaScript library for web analytics and real-time event tracking",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.5",
|
|
6
6
|
"main": "./dist/cjs/public-api.js",
|
|
7
7
|
"module": "./dist/esm/public-api.js",
|
|
8
8
|
"types": "./dist/esm/public-api.d.ts",
|