@lavarage/telemetry 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/dist/index.js +16 -9
  2. package/package.json +6 -4
package/dist/index.js CHANGED
@@ -211,17 +211,24 @@ class LavarageTelemetry {
211
211
  if (typeof fetch !== 'undefined') {
212
212
  return fetch;
213
213
  }
214
- // Try to use node-fetch if available (for older Node.js)
215
- try {
216
- // eslint-disable-next-line @typescript-eslint/no-require-imports
217
- const nodeFetch = require('node-fetch');
218
- // Handle both node-fetch v2 (default export) and v3 (named export)
219
- return (nodeFetch.default || nodeFetch);
214
+ // In browser environments, fetch should always be available
215
+ if (typeof window !== 'undefined') {
216
+ throw new Error('fetch is not available in browser environment');
220
217
  }
221
- catch {
222
- // Silently fail - will be caught in flush method
223
- throw new Error('fetch is not available. Please use Node.js 18+ or install node-fetch');
218
+ // Only try to use node-fetch in Node.js environments (for older Node.js versions)
219
+ // This code will be tree-shaken by bundlers for browser builds
220
+ if (typeof require !== 'undefined') {
221
+ try {
222
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
223
+ const nodeFetch = require('node-fetch');
224
+ // Handle both node-fetch v2 (default export) and v3 (named export)
225
+ return (nodeFetch.default || nodeFetch);
226
+ }
227
+ catch {
228
+ // node-fetch not available
229
+ }
224
230
  }
231
+ throw new Error('fetch is not available. Please use Node.js 18+ or install node-fetch');
225
232
  }
226
233
  async flush(useKeepalive = false) {
227
234
  if (this.eventQueue.length === 0) {
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "name": "@lavarage/telemetry",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Production telemetry SDK for Lavarage and partner applications",
5
5
  "main": "dist/index.js",
6
+ "module": "dist/index.js",
6
7
  "types": "dist/index.d.ts",
8
+ "browser": {
9
+ "./dist/index.js": "./dist/index.js",
10
+ "node-fetch": false
11
+ },
7
12
  "scripts": {
8
13
  "build": "tsc",
9
14
  "dev": "tsc --watch",
@@ -13,9 +18,6 @@
13
18
  "keywords": ["telemetry", "analytics", "monitoring", "lavarage"],
14
19
  "author": "Lavarage",
15
20
  "license": "MIT",
16
- "engines": {
17
- "node": ">=18.0.0"
18
- },
19
21
  "peerDependencies": {
20
22
  "node-fetch": "^2.6.0 || ^3.0.0"
21
23
  },