@kubb/agent 4.29.1 → 4.31.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 (70) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/server/chunks/nitro/nitro.mjs +542 -380
  3. package/.output/server/chunks/nitro/nitro.mjs.map +1 -1
  4. package/.output/server/chunks/routes/api/health.get.mjs +3 -1
  5. package/.output/server/chunks/routes/api/health.get.mjs.map +1 -1
  6. package/.output/server/index.mjs +3 -1
  7. package/.output/server/index.mjs.map +1 -1
  8. package/.output/server/node_modules/@kubb/fabric-core/dist/chunk-BVHe6Par.js +22 -0
  9. package/.output/server/node_modules/@kubb/fabric-core/dist/{defaultParser-C1atU7yU.js → defaultParser-BD_N68Bo.js} +3 -2
  10. package/.output/server/node_modules/@kubb/fabric-core/dist/{getRelativePath-BcieQL5M.js → getRelativePath-C4Au07ON.js} +2 -1
  11. package/.output/server/node_modules/@kubb/fabric-core/dist/index.js +8 -4
  12. package/.output/server/node_modules/@kubb/fabric-core/dist/{onProcessExit-CF200hsz.js → onProcessExit-CnZym153.js} +10 -3
  13. package/.output/server/node_modules/@kubb/fabric-core/dist/parsers/typescript.js +2 -1
  14. package/.output/server/node_modules/@kubb/fabric-core/dist/parsers.js +3 -2
  15. package/.output/server/node_modules/@kubb/fabric-core/dist/plugins.js +3 -2
  16. package/.output/server/node_modules/@kubb/fabric-core/package.json +3 -2
  17. package/.output/server/node_modules/@kubb/react-fabric/dist/{chunk-Cnw5r_-A.js → chunk-DbZtQ4qb.js} +5 -1
  18. package/.output/server/node_modules/@kubb/react-fabric/dist/index.js +4 -4
  19. package/.output/server/node_modules/@kubb/react-fabric/dist/{jsx-runtime-Dm7PKVbc.js → jsx-runtime-CZxrhUx8.js} +24 -5
  20. package/.output/server/node_modules/@kubb/react-fabric/dist/jsx-runtime.js +3 -3
  21. package/.output/server/node_modules/@kubb/react-fabric/dist/plugins.js +3 -3
  22. package/.output/server/node_modules/@kubb/react-fabric/dist/{react-D652OKii.js → react-C2cYsofv.js} +87 -26
  23. package/.output/server/node_modules/@kubb/react-fabric/dist/{reactPlugin-BkDkx1cs.js → reactPlugin-DGKBWjiR.js} +1454 -317
  24. package/.output/server/node_modules/@kubb/react-fabric/package.json +4 -3
  25. package/.output/server/node_modules/@logtail/core/dist/cjs/base.js +339 -0
  26. package/.output/server/node_modules/@logtail/core/dist/cjs/index.js +9 -0
  27. package/.output/server/node_modules/@logtail/core/package.json +45 -0
  28. package/.output/server/node_modules/@logtail/node/dist/cjs/context.js +93 -0
  29. package/.output/server/node_modules/@logtail/node/dist/cjs/index.js +6 -0
  30. package/.output/server/node_modules/@logtail/node/dist/cjs/node.js +106 -0
  31. package/.output/server/node_modules/@logtail/node/package.json +53 -0
  32. package/.output/server/node_modules/@logtail/tools/dist/cjs/batch.js +122 -0
  33. package/.output/server/node_modules/@logtail/tools/dist/cjs/burstProtection.js +50 -0
  34. package/.output/server/node_modules/@logtail/tools/dist/cjs/encode.js +12 -0
  35. package/.output/server/node_modules/@logtail/tools/dist/cjs/index.js +41 -0
  36. package/.output/server/node_modules/@logtail/tools/dist/cjs/queue.js +41 -0
  37. package/.output/server/node_modules/@logtail/tools/dist/cjs/throttle.js +67 -0
  38. package/.output/server/node_modules/@logtail/tools/package.json +39 -0
  39. package/.output/server/node_modules/@logtail/types/dist/cjs/types.js +21 -0
  40. package/.output/server/node_modules/@logtail/types/package.json +45 -0
  41. package/.output/server/node_modules/@msgpack/msgpack/dist/CachedKeyDecoder.js +63 -0
  42. package/.output/server/node_modules/@msgpack/msgpack/dist/DecodeError.js +18 -0
  43. package/.output/server/node_modules/@msgpack/msgpack/dist/Decoder.js +583 -0
  44. package/.output/server/node_modules/@msgpack/msgpack/dist/Encoder.js +408 -0
  45. package/.output/server/node_modules/@msgpack/msgpack/dist/ExtData.js +14 -0
  46. package/.output/server/node_modules/@msgpack/msgpack/dist/ExtensionCodec.js +72 -0
  47. package/.output/server/node_modules/@msgpack/msgpack/dist/decode.js +32 -0
  48. package/.output/server/node_modules/@msgpack/msgpack/dist/decodeAsync.js +44 -0
  49. package/.output/server/node_modules/@msgpack/msgpack/dist/encode.js +17 -0
  50. package/.output/server/node_modules/@msgpack/msgpack/dist/index.js +34 -0
  51. package/.output/server/node_modules/@msgpack/msgpack/dist/timestamp.js +104 -0
  52. package/.output/server/node_modules/@msgpack/msgpack/dist/utils/int.js +34 -0
  53. package/.output/server/node_modules/@msgpack/msgpack/dist/utils/prettyByte.js +8 -0
  54. package/.output/server/node_modules/@msgpack/msgpack/dist/utils/stream.js +40 -0
  55. package/.output/server/node_modules/@msgpack/msgpack/dist/utils/typedArrays.js +28 -0
  56. package/.output/server/node_modules/@msgpack/msgpack/dist/utils/utf8.js +167 -0
  57. package/.output/server/node_modules/@msgpack/msgpack/package.json +100 -0
  58. package/.output/server/node_modules/consola/dist/chunks/prompt.mjs +280 -0
  59. package/.output/server/node_modules/consola/dist/core.mjs +512 -0
  60. package/.output/server/node_modules/consola/dist/index.mjs +651 -0
  61. package/.output/server/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +72 -0
  62. package/.output/server/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +288 -0
  63. package/.output/server/node_modules/consola/package.json +136 -0
  64. package/.output/server/node_modules/serialize-error/index.js +154 -0
  65. package/.output/server/node_modules/serialize-error/package.json +41 -0
  66. package/.output/server/node_modules/stack-trace/lib/stack-trace.js +136 -0
  67. package/.output/server/node_modules/stack-trace/package.json +21 -0
  68. package/.output/server/package.json +11 -3
  69. package/README.md +3 -3
  70. package/package.json +23 -18
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/react-fabric",
3
- "version": "0.13.1",
3
+ "version": "0.13.3",
4
4
  "description": "React integration for Kubb's fabric - JSX runtime and component-based code generation with React reconciler for building type-safe generators",
5
5
  "keywords": [
6
6
  "react",
@@ -92,7 +92,8 @@
92
92
  "*.d.cts",
93
93
  "!*.map",
94
94
  "!/**/**.test.**",
95
- "!/**/__tests__/**"
95
+ "!/**/__tests__/**",
96
+ "!/**/__snapshots__/**"
96
97
  ],
97
98
  "size-limit": [
98
99
  {
@@ -105,7 +106,7 @@
105
106
  "react-devtools-core": "6.1.5",
106
107
  "remeda": "^2.33.6",
107
108
  "ws": "8.18.0",
108
- "@kubb/fabric-core": "0.13.1"
109
+ "@kubb/fabric-core": "0.13.3"
109
110
  },
110
111
  "devDependencies": {
111
112
  "@types/react": "^19.2.14",
@@ -0,0 +1,339 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const types_1 = require("@logtail/types");
4
+ const tools_1 = require("@logtail/tools");
5
+ const serialize_error_1 = require("serialize-error");
6
+ // Set default options for Logtail
7
+ const defaultOptions = {
8
+ // Default sync endpoint (protocol + domain)
9
+ endpoint: "https://in.logs.betterstack.com",
10
+ // Maximum number of logs to sync in a single request to Better Stack
11
+ batchSize: 1000,
12
+ // Size of logs (in KiB) to trigger sync to Better Stack (0 to disable)
13
+ batchSizeKiB: 0,
14
+ // Max interval (in milliseconds) before a batch of logs proceeds to syncing
15
+ batchInterval: 1000,
16
+ // Maximum number of times to retry a failed sync request
17
+ retryCount: 3,
18
+ // Minimum number of milliseconds to wait before retrying a failed sync request
19
+ retryBackoff: 100,
20
+ // Maximum number of sync requests to make concurrently
21
+ syncMax: 5,
22
+ // Maximum number of sync requests that can be queued (-1 for unlimited queue)
23
+ syncQueuedMax: 100,
24
+ // Length of the checked window for logs burst protection in milliseconds (0 to disable)
25
+ burstProtectionMilliseconds: 5000,
26
+ // Maximum number of accepted logs in the specified time window (0 to disable)
27
+ burstProtectionMax: 10000,
28
+ // If true, errors when sending logs will be ignored
29
+ // Has precedence over throwExceptions
30
+ ignoreExceptions: false,
31
+ // If true, errors when sending logs will result in a thrown exception
32
+ throwExceptions: false,
33
+ // Maximum depth (number of attribute levels) of a context object
34
+ contextObjectMaxDepth: 50,
35
+ // Produce a warn log when context object max depth is reached
36
+ contextObjectMaxDepthWarn: true,
37
+ // Produce a warning when circular reference is found in context object
38
+ contextObjectCircularRefWarn: true,
39
+ // If true, all logs will be sent to standard console output functions (console.info, console.warn, ...)
40
+ sendLogsToConsoleOutput: false,
41
+ // If true, all logs will be sent to Better Stack
42
+ sendLogsToBetterStack: true,
43
+ // Function to be used to calculate size of logs in bytes (to evaluate batchSizeLimitKiB)
44
+ calculateLogSizeBytes: tools_1.calculateJsonLogSizeBytes,
45
+ };
46
+ /**
47
+ * Logtail core class for logging to the Better Stack service
48
+ */
49
+ class Logtail {
50
+ /* CONSTRUCTOR */
51
+ /**
52
+ * Initializes a new Logtail instance
53
+ *
54
+ * @param sourceToken: string - Private source token for logging to Better Stack
55
+ * @param options?: ILogtailOptions - Optionally specify Logtail options
56
+ */
57
+ constructor(sourceToken, options) {
58
+ // Middleware
59
+ this._middleware = [];
60
+ // Number of logs logged
61
+ this._countLogged = 0;
62
+ // Number of logs successfully synced with Logtail
63
+ this._countSynced = 0;
64
+ // Number of logs that failed to be synced to Logtail
65
+ this._countDropped = 0;
66
+ // First, check we have a valid source token
67
+ if (typeof sourceToken !== "string" || sourceToken === "") {
68
+ throw new Error("Logtail source token missing");
69
+ }
70
+ // Store the source token, to use for syncing with Better Stack
71
+ this._sourceToken = sourceToken;
72
+ // Merge default and user options
73
+ this._options = Object.assign(Object.assign({}, defaultOptions), options);
74
+ // Create a throttler, for sync operations
75
+ const throttle = (0, tools_1.makeThrottle)(this._options.syncMax, this._options.syncQueuedMax);
76
+ // Sync after throttling
77
+ const throttler = throttle((logs) => {
78
+ return this._sync(logs);
79
+ });
80
+ // Burst protection for logging
81
+ this._logBurstProtection = (0, tools_1.makeBurstProtection)(this._options.burstProtectionMilliseconds, this._options.burstProtectionMax, "Logging");
82
+ this.log = this._logBurstProtection(this.log.bind(this));
83
+ // Create a batcher, for aggregating logs by buffer size/interval
84
+ const batcher = (0, tools_1.makeBatch)(this._options.batchSize, this._options.batchInterval, this._options.retryCount, this._options.retryBackoff, this._options.batchSizeKiB * 1024, this._options.calculateLogSizeBytes);
85
+ this._batch = batcher.initPusher((logs) => {
86
+ return throttler(logs);
87
+ });
88
+ this._flush = batcher.flush;
89
+ }
90
+ /* PUBLIC METHODS */
91
+ /**
92
+ * Flush batched logs to Logtail
93
+ */
94
+ async flush() {
95
+ return this._flush();
96
+ }
97
+ /**
98
+ * Number of entries logged
99
+ *
100
+ * @returns number
101
+ */
102
+ get logged() {
103
+ return this._countLogged;
104
+ }
105
+ /**
106
+ * Number of log entries synced with Better Stack
107
+ *
108
+ * @returns number
109
+ */
110
+ get synced() {
111
+ return this._countSynced;
112
+ }
113
+ /**
114
+ * Number of entries dropped
115
+ *
116
+ * @returns number
117
+ */
118
+ get dropped() {
119
+ return this._countDropped;
120
+ }
121
+ /**
122
+ * Log an entry, to be synced with Better Stack
123
+ *
124
+ * @param message: string - Log message
125
+ * @param level (LogLevel) - Level to log at (debug|info|warn|error)
126
+ * @param context: (Context) - Context (optional)
127
+ * @returns Promise<ILogtailLog> after syncing
128
+ */
129
+ async log(message, level = types_1.LogLevel.Info, context = {}) {
130
+ // Wrap context in an object, if it's not already
131
+ if (typeof context !== "object") {
132
+ const wrappedContext = { extra: context };
133
+ context = wrappedContext;
134
+ }
135
+ if (context instanceof Error) {
136
+ const wrappedContext = { error: context };
137
+ context = wrappedContext;
138
+ }
139
+ if (this._options.sendLogsToConsoleOutput) {
140
+ switch (level) {
141
+ case "debug":
142
+ console.debug(message, context);
143
+ break;
144
+ case "info":
145
+ console.info(message, context);
146
+ break;
147
+ case "warn":
148
+ console.warn(message, context);
149
+ break;
150
+ case "error":
151
+ console.error(message, context);
152
+ break;
153
+ default:
154
+ console.log(`[${level.toUpperCase()}]`, message, context);
155
+ break;
156
+ }
157
+ }
158
+ // Check that we have a sync function
159
+ if (typeof this._sync !== "function") {
160
+ throw new Error("No Logtail logger sync function provided");
161
+ }
162
+ // Increment log count
163
+ this._countLogged++;
164
+ // Start building the log message
165
+ let log = Object.assign(Object.assign({
166
+ // Implicit date timestamp
167
+ dt: new Date(),
168
+ // Explicit level
169
+ level }, context), (message instanceof Error ? (0, serialize_error_1.serializeError)(message) : { message }));
170
+ let transformedLog = log;
171
+ for (const middleware of this._middleware) {
172
+ let newTransformedLog = await middleware(transformedLog);
173
+ if (newTransformedLog == null) {
174
+ // Don't push the log if it was filtered out in a middleware
175
+ return transformedLog;
176
+ }
177
+ transformedLog = newTransformedLog;
178
+ }
179
+ // Manually serialize the log data
180
+ transformedLog = this.serialize(transformedLog, this._options.contextObjectMaxDepth);
181
+ if (!this._options.sendLogsToBetterStack) {
182
+ // Return the resulting log before sending it
183
+ return transformedLog;
184
+ }
185
+ try {
186
+ // Push the log through the batcher, and sync
187
+ await this._batch(transformedLog);
188
+ // Increment sync count
189
+ this._countSynced++;
190
+ }
191
+ catch (e) {
192
+ // Increment dropped count
193
+ this._countDropped++;
194
+ // Catch any errors - re-throw if `ignoreExceptions` == false
195
+ if (!this._options.ignoreExceptions) {
196
+ if (this._options.throwExceptions) {
197
+ throw e;
198
+ }
199
+ else {
200
+ // Output to console
201
+ console.error(e);
202
+ }
203
+ }
204
+ }
205
+ // Return the resulting log
206
+ return transformedLog;
207
+ }
208
+ serialize(value, maxDepth, visitedObjects = new WeakSet()) {
209
+ if (value === null || typeof value === "boolean" || typeof value === "number" || typeof value === "string") {
210
+ return value;
211
+ }
212
+ else if (value instanceof Date) {
213
+ // Date instances can be invalid & toISOString() will fail
214
+ if (isNaN(value.getTime())) {
215
+ return value.toString();
216
+ }
217
+ return value.toISOString();
218
+ }
219
+ else if (value instanceof Error) {
220
+ return (0, serialize_error_1.serializeError)(value);
221
+ }
222
+ else if ((typeof value === "object" || Array.isArray(value)) && (maxDepth < 1 || visitedObjects.has(value))) {
223
+ if (visitedObjects.has(value)) {
224
+ if (this._options.contextObjectCircularRefWarn) {
225
+ console.warn(`[Logtail] Found a circular reference when serializing logs. Please do not use circular references in your logs.`);
226
+ }
227
+ return "<omitted circular reference>";
228
+ }
229
+ if (this._options.contextObjectMaxDepthWarn) {
230
+ console.warn(`[Logtail] Max depth of ${this._options.contextObjectMaxDepth} reached when serializing logs. Please do not use excessive object depth in your logs.`);
231
+ }
232
+ return `<omitted context beyond configured max depth: ${this._options.contextObjectMaxDepth}>`;
233
+ }
234
+ else if (Array.isArray(value)) {
235
+ visitedObjects.add(value);
236
+ const serializedArray = value.map((item) => this.serialize(item, maxDepth - 1, visitedObjects));
237
+ visitedObjects.delete(value);
238
+ return serializedArray;
239
+ }
240
+ else if (typeof value === "object") {
241
+ const serializedObject = {};
242
+ visitedObjects.add(value);
243
+ Object.entries(value).forEach((item) => {
244
+ const key = item[0];
245
+ const value = item[1];
246
+ const serializedValue = this.serialize(value, maxDepth - 1, visitedObjects);
247
+ if (serializedValue !== undefined) {
248
+ serializedObject[key] = serializedValue;
249
+ }
250
+ });
251
+ visitedObjects.delete(value);
252
+ return serializedObject;
253
+ }
254
+ else if (typeof value === "undefined") {
255
+ return undefined;
256
+ }
257
+ else {
258
+ return `<omitted unserializable ${typeof value}>`;
259
+ }
260
+ }
261
+ /**
262
+ *
263
+ * Debug level log, to be synced with Better Stack
264
+ *
265
+ * @param message: string - Log message
266
+ * @param context: (Pick<ILogtailLog, "context">) - Context (optional)
267
+ * @returns Promise<ILogtailLog> after syncing
268
+ */
269
+ async debug(message, context = {}) {
270
+ return this.log(message, types_1.LogLevel.Debug, context);
271
+ }
272
+ /**
273
+ *
274
+ * Info level log, to be synced with Better Stack
275
+ *
276
+ * @param message: string - Log message
277
+ * @param context: (Pick<ILogtailLog, "context">) - Context (optional)
278
+ * @returns Promise<ILogtailLog> after syncing
279
+ */
280
+ async info(message, context = {}) {
281
+ return this.log(message, types_1.LogLevel.Info, context);
282
+ }
283
+ /**
284
+ *
285
+ * Warning level log, to be synced with Better Stack
286
+ *
287
+ * @param message: string - Log message
288
+ * @param context: (Pick<ILogtailLog, "context">) - Context (optional)
289
+ * @returns Promise<ILogtailLog> after syncing
290
+ */
291
+ async warn(message, context = {}) {
292
+ return this.log(message, types_1.LogLevel.Warn, context);
293
+ }
294
+ /**
295
+ *
296
+ * Warning level log, to be synced with Better Stack
297
+ *
298
+ * @param message: string - Log message
299
+ * @param context: (Pick<ILogtailLog, "context">) - Context (optional)
300
+ * @returns Promise<ILogtailLog> after syncing
301
+ */
302
+ async error(message, context = {}) {
303
+ return this.log(message, types_1.LogLevel.Error, context);
304
+ }
305
+ /**
306
+ * Sets the sync method - i.e. the final step in the pipeline to get logs
307
+ * over to Better Stack
308
+ *
309
+ * @param fn - Pipeline function to use as sync method
310
+ */
311
+ setSync(fn) {
312
+ this._sync = fn;
313
+ }
314
+ /**
315
+ * Add a middleware function to the logging pipeline
316
+ *
317
+ * @param fn - Function to add to the log pipeline
318
+ * @returns void
319
+ */
320
+ use(fn) {
321
+ this._middleware.push(fn);
322
+ }
323
+ /**
324
+ * Remove a function from the pipeline
325
+ *
326
+ * @param fn - Pipeline function
327
+ * @returns void
328
+ */
329
+ remove(fn) {
330
+ this._middleware = this._middleware.filter((p) => p !== fn);
331
+ }
332
+ }
333
+ class default_1 extends Logtail {
334
+ async log(message, level = types_1.LogLevel.Info, context = {}) {
335
+ return super.log(message, level, context);
336
+ }
337
+ }
338
+ exports.default = default_1;
339
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Base = void 0;
7
+ const base_1 = __importDefault(require("./base"));
8
+ exports.Base = base_1.default;
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@logtail/core",
3
+ "version": "0.5.6",
4
+ "description": "Better Stack logging core (formerly Logtail)",
5
+ "keywords": [
6
+ "Better Stack",
7
+ "Logtail",
8
+ "logger",
9
+ "logging"
10
+ ],
11
+ "author": "Better Stack <hello@betterstack.com>",
12
+ "homepage": "https://github.com/logtail/logtail-js/tree/master/packages/core#readme",
13
+ "license": "ISC",
14
+ "main": "dist/cjs/index.js",
15
+ "module": "dist/es6/index.js",
16
+ "types": "dist/es6/index.d.ts",
17
+ "files": [
18
+ "src",
19
+ "dist"
20
+ ],
21
+ "sideEffects": false,
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/logtail/logtail-js.git"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "scripts": {
30
+ "build:cjs": "tsc",
31
+ "build:es6": "tsc -p tsconfig.es6.json",
32
+ "build": "run-p build:*",
33
+ "prepublishOnly": "npm run build",
34
+ "test": "echo \"Error: run tests from root\" && exit 1"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/logtail/logtail-js/issues"
38
+ },
39
+ "dependencies": {
40
+ "@logtail/tools": "^0.5.6",
41
+ "@logtail/types": "^0.5.6",
42
+ "serialize-error": "8.1.0"
43
+ },
44
+ "gitHead": "6901c2b90af7cf9dda3e7c8be7c145d4d83e72a8"
45
+ }
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getStackContext = getStackContext;
7
+ const path_1 = require("path");
8
+ const stack_trace_1 = __importDefault(require("stack-trace"));
9
+ const mainFile = mainFileName();
10
+ /**
11
+ * Determines the file name and the line number from which the log
12
+ * was initiated (if we're able to tell).
13
+ *
14
+ * @returns Context The caller's filename and the line number
15
+ */
16
+ function getStackContext(logtail, stackContextHint) {
17
+ const stackFrame = getCallingFrame(logtail, stackContextHint);
18
+ if (stackFrame === null)
19
+ return {};
20
+ return {
21
+ context: {
22
+ runtime: {
23
+ file: relativeToMainModule(stackFrame.getFileName()),
24
+ type: stackFrame.getTypeName(),
25
+ method: stackFrame.getMethodName(),
26
+ function: stackFrame.getFunctionName(),
27
+ line: stackFrame.getLineNumber(),
28
+ column: stackFrame.getColumnNumber(),
29
+ },
30
+ system: {
31
+ pid: process.pid,
32
+ main_file: mainFile,
33
+ },
34
+ },
35
+ };
36
+ }
37
+ function getCallingFrame(logtail, stackContextHint) {
38
+ for (let fn of [logtail.warn, logtail.error, logtail.info, logtail.debug, logtail.log]) {
39
+ const stack = stack_trace_1.default.get(fn);
40
+ if ((stack === null || stack === void 0 ? void 0 : stack.length) > 0)
41
+ return getRelevantStackFrame(stack, stackContextHint);
42
+ }
43
+ return null;
44
+ }
45
+ function getRelevantStackFrame(frames, stackContextHint) {
46
+ if (stackContextHint) {
47
+ frames.reverse();
48
+ let index = frames.findIndex((frame) => {
49
+ var _a;
50
+ return (((_a = frame.getFileName()) === null || _a === void 0 ? void 0 : _a.includes(stackContextHint.fileName)) &&
51
+ (stackContextHint.methodNames.includes(frame.getMethodName()) ||
52
+ stackContextHint.methodNames.includes(frame.getFunctionName())));
53
+ });
54
+ if (index > 0) {
55
+ return frames[index - 1];
56
+ }
57
+ if (stackContextHint.required) {
58
+ return null;
59
+ }
60
+ return frames[frames.length - 1];
61
+ }
62
+ return frames[0];
63
+ }
64
+ function relativeToMainModule(fileName) {
65
+ if (typeof fileName !== "string") {
66
+ return null;
67
+ }
68
+ else if (fileName.startsWith("file:/")) {
69
+ const url = new URL(fileName);
70
+ return url.pathname;
71
+ }
72
+ else {
73
+ const rootPath = (0, path_1.dirname)(mainFileName());
74
+ return (0, path_1.relative)(rootPath, fileName);
75
+ }
76
+ }
77
+ function mainFileName() {
78
+ let argv = process === null || process === void 0 ? void 0 : process.argv;
79
+ if (argv === undefined)
80
+ return "";
81
+ // return first js file argument - arg ending in .js
82
+ for (const arg of argv) {
83
+ if (typeof arg !== "string" || arg.startsWith("-")) {
84
+ // break on first option
85
+ break;
86
+ }
87
+ if (arg.endsWith(".js")) {
88
+ return arg;
89
+ }
90
+ }
91
+ return "";
92
+ }
93
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Logtail = void 0;
4
+ const node_1 = require("./node");
5
+ Object.defineProperty(exports, "Logtail", { enumerable: true, get: function () { return node_1.Node; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Node = void 0;
7
+ const msgpack_1 = require("@msgpack/msgpack");
8
+ const node_http_1 = __importDefault(require("node:http"));
9
+ const node_https_1 = __importDefault(require("node:https"));
10
+ const node_zlib_1 = __importDefault(require("node:zlib"));
11
+ const core_1 = require("@logtail/core");
12
+ const context_1 = require("./context");
13
+ class Node extends core_1.Base {
14
+ constructor(sourceToken, options) {
15
+ options = Object.assign({ timeout: 30000 }, options);
16
+ super(sourceToken, options);
17
+ const agent = this.createAgent();
18
+ // Sync function
19
+ const sync = async (logs) => {
20
+ const nodeOptions = this._options;
21
+ const request = this.getHttpModule().request(nodeOptions.endpoint, {
22
+ method: "POST",
23
+ headers: {
24
+ "Content-Type": "application/msgpack",
25
+ "Content-Encoding": "gzip",
26
+ Authorization: `Bearer ${this._sourceToken}`,
27
+ "User-Agent": "logtail-js(node)",
28
+ },
29
+ agent,
30
+ timeout: nodeOptions.timeout > 0 ? nodeOptions.timeout : undefined,
31
+ });
32
+ const response = await new Promise((resolve, reject) => {
33
+ // Setup timeout handler if timeout is configured
34
+ if (nodeOptions.timeout > 0) {
35
+ request.on("timeout", () => {
36
+ request.destroy();
37
+ reject(new Error(`Request timeout after ${nodeOptions.timeout}ms`));
38
+ });
39
+ }
40
+ request.on("response", resolve);
41
+ request.on("error", reject);
42
+ // Compress the logs using gzip
43
+ node_zlib_1.default.gzip(this.encodeAsMsgpack(logs), (err, compressedData) => {
44
+ if (err) {
45
+ reject(err);
46
+ return;
47
+ }
48
+ request.write(compressedData);
49
+ request.end();
50
+ });
51
+ });
52
+ if (response.statusCode && response.statusCode >= 200 && response.statusCode < 300) {
53
+ return logs;
54
+ }
55
+ throw new Error(response.statusMessage);
56
+ };
57
+ // Set the throttled sync function
58
+ this.setSync(sync);
59
+ }
60
+ /**
61
+ * Override `Base` log to enable Node.js streaming
62
+ *
63
+ * @param message: string - Log message
64
+ * @param level (LogLevel) - Level to log at (debug|info|warn|error)
65
+ * @param context: (Context) - Log context for passing structured data
66
+ * @param stackContextHint: (StackContextHint|null) - Info about which methods to consider as origin in context.runtime
67
+ * @returns Promise<ILogtailLog> after syncing
68
+ */
69
+ async log(message, level, context = {}, stackContextHint) {
70
+ // Process/sync the log, per `Base` logic
71
+ context = Object.assign(Object.assign({}, (0, context_1.getStackContext)(this, stackContextHint)), context);
72
+ const processedLog = await super.log(message, level, context);
73
+ // Push the processed log to the stream, for piping
74
+ if (this._writeStream) {
75
+ this._writeStream.write(JSON.stringify(processedLog) + "\n");
76
+ }
77
+ // Return the transformed log
78
+ return processedLog;
79
+ }
80
+ /**
81
+ * Pipe JSON stringified `ILogtailLog` to a stream after syncing
82
+ *
83
+ * @param stream - Writable|Duplex stream
84
+ */
85
+ pipe(stream) {
86
+ this._writeStream = stream;
87
+ return stream;
88
+ }
89
+ encodeAsMsgpack(logs) {
90
+ const encoded = (0, msgpack_1.encode)(logs);
91
+ const buffer = Buffer.from(encoded.buffer, encoded.byteOffset, encoded.byteLength);
92
+ return buffer;
93
+ }
94
+ createAgent() {
95
+ const nodeOptions = this._options;
96
+ const family = nodeOptions.useIPv6 ? 6 : 4;
97
+ return new (this.getHttpModule().Agent)({
98
+ family,
99
+ });
100
+ }
101
+ getHttpModule() {
102
+ return this._options.endpoint.startsWith("https") ? node_https_1.default : node_http_1.default;
103
+ }
104
+ }
105
+ exports.Node = Node;
106
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@logtail/node",
3
+ "version": "0.5.6",
4
+ "description": "Better Stack Node.js logger (formerly Logtail)",
5
+ "keywords": [
6
+ "Better Stack",
7
+ "Logtail",
8
+ "logger",
9
+ "logging",
10
+ "Node"
11
+ ],
12
+ "author": "Better Stack <hello@betterstack.com>",
13
+ "homepage": "https://github.com/logtail/logtail-js/tree/master/packages/node#readme",
14
+ "license": "ISC",
15
+ "main": "dist/cjs/index.js",
16
+ "module": "dist/es6/index.js",
17
+ "types": "dist/es6/index.d.ts",
18
+ "files": [
19
+ "src",
20
+ "dist"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/logtail/logtail-js.git"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "scripts": {
30
+ "build:cjs": "tsc",
31
+ "build:es6": "tsc -p tsconfig.es6.json",
32
+ "build": "run-p build:*",
33
+ "prepublishOnly": "npm run build",
34
+ "test": "echo \"Error: run tests from root\" && exit 1"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/logtail/logtail-js/issues"
38
+ },
39
+ "devDependencies": {
40
+ "@types/fetch-mock": "^7.3.1",
41
+ "@types/nock": "^11.1.0",
42
+ "nock": "^14.0.1"
43
+ },
44
+ "dependencies": {
45
+ "@logtail/core": "^0.5.6",
46
+ "@logtail/types": "^0.5.6",
47
+ "@msgpack/msgpack": "^2.5.1",
48
+ "@types/stack-trace": "^0.0.33",
49
+ "minimatch": "^9.0.5",
50
+ "stack-trace": "0.0.10"
51
+ },
52
+ "gitHead": "6901c2b90af7cf9dda3e7c8be7c145d4d83e72a8"
53
+ }