@dasasian/firebase-structured-logger 0.2.0 → 0.3.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.
@@ -1 +1 @@
1
- {"version":3,"file":"errorHandler.d.ts","sourceRoot":"","sources":["../../src/client/errorHandler.ts"],"names":[],"mappings":"AAEA,wBAAgB,uBAAuB,IAAI,IAAI,CAU9C;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE;IAAE,cAAc,EAAE,MAAM,CAAA;CAAE,GACpC,IAAI,CAMN"}
1
+ {"version":3,"file":"errorHandler.d.ts","sourceRoot":"","sources":["../../src/client/errorHandler.ts"],"names":[],"mappings":"AAqBA,wBAAgB,uBAAuB,IAAI,IAAI,CA8B9C;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE;IAAE,cAAc,EAAE,MAAM,CAAA;CAAE,GACpC,IAAI,CAMN"}
@@ -3,14 +3,46 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setupGlobalErrorHandler = setupGlobalErrorHandler;
4
4
  exports.handleReactError = handleReactError;
5
5
  const logger_1 = require("./logger");
6
+ /**
7
+ * A script loaded cross-origin without CORS has its error withheld by the
8
+ * browser: the event fires with `error === null` and only `message`
9
+ * (classically `"Script error."`), `filename`, `lineno` and `colno` are set.
10
+ *
11
+ * Passing that null straight to the logger produced an entry whose message was
12
+ * the literal string "null" — less information than the event carried, and
13
+ * identical for every such error, so they were indistinguishable in Cloud
14
+ * Logging and collapsed into a single signature that duplicate suppression
15
+ * then swallowed. The locator is folded into the message so the entries stay
16
+ * distinct as well as readable.
17
+ */
18
+ function errorFromEvent(event) {
19
+ const where = event.filename
20
+ ? ` (${event.filename}:${event.lineno ?? 0}:${event.colno ?? 0})`
21
+ : '';
22
+ return new Error(`${event.message || 'Cross-origin script error'}${where}`);
23
+ }
6
24
  function setupGlobalErrorHandler() {
7
25
  window.addEventListener('error', (event) => {
8
- console.error('[fsl] Uncaught error:', event.error);
9
- (0, logger_1.getClientLogger)().error(event.error, { errorCategory: 'crash', errorType: 'UncaughtError' });
26
+ if (event.error != null) {
27
+ console.error('[fsl] Uncaught error:', event.error);
28
+ (0, logger_1.getClientLogger)().error(event.error, {
29
+ errorCategory: 'crash',
30
+ errorType: 'UncaughtError',
31
+ });
32
+ return;
33
+ }
34
+ console.error('[fsl] Cross-origin script error:', event.message);
35
+ (0, logger_1.getClientLogger)().error(errorFromEvent(event), { errorCategory: 'crash', errorType: 'CrossOriginError' }, { filename: event.filename, lineno: event.lineno, colno: event.colno });
10
36
  });
11
37
  window.addEventListener('unhandledrejection', (event) => {
12
38
  console.error('[fsl] Unhandled rejection:', event.reason);
13
- (0, logger_1.getClientLogger)().error(event.reason, { errorCategory: 'crash', errorType: 'UnhandledRejection' });
39
+ // A rejection can carry any value, including none at all. `toError` would
40
+ // turn that into Error("undefined"), which says nothing.
41
+ const reason = event.reason ?? new Error('Unhandled promise rejection with no reason');
42
+ (0, logger_1.getClientLogger)().error(reason, {
43
+ errorCategory: 'crash',
44
+ errorType: 'UnhandledRejection',
45
+ });
14
46
  });
15
47
  }
16
48
  function handleReactError(error, errorInfo) {
@@ -1 +1 @@
1
- {"version":3,"file":"errorHandler.js","sourceRoot":"","sources":["../../src/client/errorHandler.ts"],"names":[],"mappings":";;AAEA,0DAUC;AAED,4CASC;AAvBD,qCAA0C;AAE1C,SAAgB,uBAAuB;IACrC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;QACzC,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;QACnD,IAAA,wBAAe,GAAE,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC,CAAA;IAC9F,CAAC,CAAC,CAAA;IAEF,MAA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ian/firebase-structured-logger",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Structured logging for Firebase apps — client, functions, and tools",
5
5
  "license": "MIT",
6
6
  "author": "Dasasian",
@@ -65,7 +65,7 @@
65
65
  "build:watch": "tsc --watch",
66
66
  "clean": "rm -rf dist",
67
67
  "typecheck": "tsc --noEmit",
68
- "test": "tsx tests/logger.ts && tsx tests/breadcrumbs.ts && tsx tests/rateLimiter.ts && tsx tests/errorHandler.ts && FUNCTIONS_EMULATOR=true tsx tests/errorPayload.ts && FUNCTIONS_EMULATOR=true tsx tests/requestLogger.ts && FUNCTIONS_EMULATOR=true tsx tests/handler.ts && FUNCTIONS_EMULATOR=true tsx tests/symbolication.ts && FUNCTIONS_EMULATOR=true tsx tests/publicApi.ts && FUNCTIONS_EMULATOR=true tsx tests/configureTwice.ts",
68
+ "test": "tsx tests/logger.ts && tsx tests/breadcrumbs.ts && tsx tests/rateLimiter.ts && tsx tests/errorHandler.ts && tsx tests/attachments.ts && FUNCTIONS_EMULATOR=true tsx tests/errorPayload.ts && FUNCTIONS_EMULATOR=true tsx tests/requestLogger.ts && FUNCTIONS_EMULATOR=true tsx tests/handler.ts && FUNCTIONS_EMULATOR=true tsx tests/symbolication.ts && FUNCTIONS_EMULATOR=true tsx tests/publicApi.ts && FUNCTIONS_EMULATOR=true tsx tests/configureTwice.ts && tsx tests/productionOutput.ts && tsx tests/handlerSymbolication.ts",
69
69
  "prepublishOnly": "npm run build"
70
70
  },
71
71
  "dependencies": {
@@ -90,14 +90,16 @@
90
90
  }
91
91
  },
92
92
  "devDependencies": {
93
+ "@types/jsdom": "^30.0.0",
93
94
  "@types/node": "^26.2.0",
94
95
  "firebase": "^12.0.0",
95
96
  "firebase-admin": "^14.2.0",
96
97
  "firebase-functions": "^7.0.0",
98
+ "jsdom": "^27.0.1",
97
99
  "tsx": "^4.19.0",
98
100
  "typescript": "~5.9.3"
99
101
  },
100
102
  "engines": {
101
- "node": ">=18"
103
+ "node": ">=22"
102
104
  }
103
105
  }