@mereb/shared-packages 0.0.32 → 0.0.33

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":"splunk-transport.d.ts","sourceRoot":"","sources":["../../src/transports/splunk-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAG5C,KAAK,sBAAsB,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAgCF,wBAA8B,eAAe,CAAC,IAAI,EAAE,sBAAsB,yDAsDzE"}
1
+ {"version":3,"file":"splunk-transport.d.ts","sourceRoot":"","sources":["../../src/transports/splunk-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAG5C,KAAK,sBAAsB,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AA0CF,wBAA8B,eAAe,CAAC,IAAI,EAAE,sBAAsB,yDAsDzE"}
@@ -9,25 +9,31 @@ const warnOnce = () => {
9
9
  }
10
10
  };
11
11
  };
12
- const normalizeChunk = (chunk) => {
13
- if (typeof chunk === 'string')
14
- return chunk;
15
- const candidate = chunk?.toString?.();
16
- return typeof candidate === 'string' ? candidate : null;
17
- };
18
12
  const parsePayload = (chunk, onWarn) => {
19
- const line = normalizeChunk(chunk);
20
- if (!line) {
21
- onWarn('Splunk transport dropped log: non-string chunk');
22
- return null;
13
+ if (chunk != null && typeof chunk === 'object') {
14
+ return { success: true, payload: chunk }; // already structured JSON from pino
23
15
  }
24
- try {
25
- return JSON.parse(line);
16
+ if (typeof chunk === 'string') {
17
+ try {
18
+ return { success: true, payload: JSON.parse(chunk) };
19
+ }
20
+ catch {
21
+ onWarn('Splunk transport dropped log: JSON parse failed');
22
+ return { success: false };
23
+ }
26
24
  }
27
- catch {
28
- onWarn('Splunk transport dropped log: JSON parse failed');
29
- return null;
25
+ const candidate = chunk?.toString?.();
26
+ if (typeof candidate === 'string') {
27
+ try {
28
+ return { success: true, payload: JSON.parse(candidate) };
29
+ }
30
+ catch {
31
+ onWarn('Splunk transport dropped log: JSON parse failed');
32
+ return { success: false };
33
+ }
30
34
  }
35
+ onWarn('Splunk transport dropped log: non-string chunk');
36
+ return { success: false };
31
37
  };
32
38
  export default async function splunkTransport(opts) {
33
39
  const url = opts.url;
@@ -42,8 +48,8 @@ export default async function splunkTransport(opts) {
42
48
  return build(async (stream) => {
43
49
  const warn = warnOnce();
44
50
  for await (const chunk of stream) {
45
- const payload = parsePayload(chunk, warn);
46
- if (payload == null)
51
+ const parsed = parsePayload(chunk, warn);
52
+ if (!parsed.success)
47
53
  continue;
48
54
  const controller = AbortSignal.timeout(timeoutMs);
49
55
  const requestId = randomUUID();
@@ -55,7 +61,7 @@ export default async function splunkTransport(opts) {
55
61
  'X-Splunk-Request-Channel': requestId
56
62
  },
57
63
  body: JSON.stringify({
58
- event: payload,
64
+ event: parsed.payload,
59
65
  index,
60
66
  source,
61
67
  sourcetype
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mereb/shared-packages",
3
- "version": "0.0.32",
3
+ "version": "0.0.33",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",