@mihari/logger-core 0.1.0 → 0.2.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,21 +0,0 @@
1
- import { LogEntry, TransportOptions, TransportResponse, CompressFn } from "@mihari/logger-types";
2
- export declare class HttpTransport {
3
- private readonly token;
4
- private readonly endpoint;
5
- private readonly compression;
6
- private readonly maxRetries;
7
- private compressFn;
8
- constructor(options: TransportOptions);
9
- /**
10
- * Sets the compression function. This allows node and browser
11
- * environments to inject their own gzip implementation.
12
- */
13
- setCompressFn(fn: CompressFn): void;
14
- /**
15
- * Sends an array of log entries to the ingestion endpoint with
16
- * retry logic using exponential backoff.
17
- */
18
- send(logs: readonly LogEntry[]): Promise<TransportResponse>;
19
- private doFetch;
20
- }
21
- //# sourceMappingURL=transport.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAMjG,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAU;IACtC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,UAAU,CAA2B;gBAEjC,OAAO,EAAE,gBAAgB;IAOrC;;;OAGG;IACH,aAAa,CAAC,EAAE,EAAE,UAAU,GAAG,IAAI;IAInC;;;OAGG;IACG,IAAI,CAAC,IAAI,EAAE,SAAS,QAAQ,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC;YAsDnD,OAAO;CAetB"}
package/dist/transport.js DELETED
@@ -1,81 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpTransport = void 0;
4
- const utils_1 = require("./utils");
5
- const DEFAULT_RETRIES = 3;
6
- const RETRY_BASE_DELAY_MS = 1000;
7
- class HttpTransport {
8
- constructor(options) {
9
- this.compressFn = null;
10
- this.token = options.token;
11
- this.endpoint = options.endpoint.replace(/\/+$/, "");
12
- this.compression = options.compression ?? true;
13
- this.maxRetries = options.retries ?? DEFAULT_RETRIES;
14
- }
15
- /**
16
- * Sets the compression function. This allows node and browser
17
- * environments to inject their own gzip implementation.
18
- */
19
- setCompressFn(fn) {
20
- this.compressFn = fn;
21
- }
22
- /**
23
- * Sends an array of log entries to the ingestion endpoint with
24
- * retry logic using exponential backoff.
25
- */
26
- async send(logs) {
27
- const payload = JSON.stringify(logs);
28
- let body = payload;
29
- const headers = {
30
- "Authorization": `Bearer ${this.token}`,
31
- "Content-Type": "application/json",
32
- };
33
- if (this.compression && this.compressFn) {
34
- const encoded = new TextEncoder().encode(payload);
35
- body = await this.compressFn(encoded);
36
- headers["Content-Encoding"] = "gzip";
37
- }
38
- let lastError = null;
39
- for (let attempt = 0; attempt < this.maxRetries; attempt++) {
40
- try {
41
- const response = await this.doFetch(body, headers);
42
- if (response.status === 202) {
43
- return response.json;
44
- }
45
- if (response.status === 401) {
46
- throw new Error("Invalid or missing authentication token");
47
- }
48
- if (response.status === 400) {
49
- throw new Error("No valid logs found");
50
- }
51
- throw new Error(`Unexpected response status: ${response.status}`);
52
- }
53
- catch (err) {
54
- lastError = err instanceof Error ? err : new Error(String(err));
55
- // Do not retry auth or validation errors
56
- if (lastError.message === "Invalid or missing authentication token" ||
57
- lastError.message === "No valid logs found") {
58
- throw lastError;
59
- }
60
- if (attempt < this.maxRetries - 1) {
61
- const delay = RETRY_BASE_DELAY_MS * Math.pow(2, attempt);
62
- await (0, utils_1.sleep)(delay);
63
- }
64
- }
65
- }
66
- throw lastError ?? new Error("Transport failed after retries");
67
- }
68
- async doFetch(body, headers) {
69
- // Use global fetch (available in Node 18+ and all modern browsers)
70
- const res = await fetch(`${this.endpoint}`, {
71
- method: "POST",
72
- headers,
73
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
- body: body,
75
- });
76
- const json = await res.json().catch(() => ({}));
77
- return { status: res.status, json };
78
- }
79
- }
80
- exports.HttpTransport = HttpTransport;
81
- //# sourceMappingURL=transport.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":";;;AACA,mCAAgC;AAEhC,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAEjC,MAAa,aAAa;IAOxB,YAAY,OAAyB;QAF7B,eAAU,GAAsB,IAAI,CAAC;QAG3C,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACrD,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,IAAI,CAAC;QAC/C,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,OAAO,IAAI,eAAe,CAAC;IACvD,CAAC;IAED;;;OAGG;IACH,aAAa,CAAC,EAAc;QAC1B,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI,CAAC,IAAyB;QAClC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,IAAI,GAAwB,OAAO,CAAC;QACxC,MAAM,OAAO,GAA2B;YACtC,eAAe,EAAE,UAAU,IAAI,CAAC,KAAK,EAAE;YACvC,cAAc,EAAE,kBAAkB;SACnC,CAAC;QAEF,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACxC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,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BAAmB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;oBACzD,MAAM,IAAA,aAAK,EAAC,KAAK,CAAC,CAAC;gBACrB,CAAC;YACH,CAAC;QACH,CAAC;QAED,MAAM,SAAS,IAAI,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACjE,CAAC;IAEO,KAAK,CAAC,OAAO,CACnB,IAAyB,EACzB,OAA+B;QAE/B,mEAAmE;QACnE,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,EAAE;YAC1C,MAAM,EAAE,MAAM;YACd,OAAO;YACP,8DAA8D;YAC9D,IAAI,EAAE,IAAW;SAClB,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAChD,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC;IACtC,CAAC;CACF;AA/FD,sCA+FC"}
package/dist/utils.d.ts DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * Returns the current timestamp in ISO 8601 format.
3
- */
4
- export declare function isoTimestamp(): string;
5
- /**
6
- * Detects whether the current runtime is a browser environment.
7
- */
8
- export declare function isBrowser(): boolean;
9
- /**
10
- * Detects whether the current runtime is Node.js.
11
- */
12
- export declare function isNode(): boolean;
13
- /**
14
- * Waits for the specified number of milliseconds.
15
- */
16
- export declare function sleep(ms: number): Promise<void>;
17
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAMnC;AAED;;GAEG;AACH,wBAAgB,MAAM,IAAI,OAAO,CAMhC;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C"}
package/dist/utils.js DELETED
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isoTimestamp = isoTimestamp;
4
- exports.isBrowser = isBrowser;
5
- exports.isNode = isNode;
6
- exports.sleep = sleep;
7
- /**
8
- * Returns the current timestamp in ISO 8601 format.
9
- */
10
- function isoTimestamp() {
11
- return new Date().toISOString();
12
- }
13
- /**
14
- * Detects whether the current runtime is a browser environment.
15
- */
16
- function isBrowser() {
17
- return (typeof globalThis !== "undefined" &&
18
- typeof globalThis.window !== "undefined" &&
19
- typeof globalThis.document !== "undefined");
20
- }
21
- /**
22
- * Detects whether the current runtime is Node.js.
23
- */
24
- function isNode() {
25
- return (typeof process !== "undefined" &&
26
- process.versions != null &&
27
- process.versions.node != null);
28
- }
29
- /**
30
- * Waits for the specified number of milliseconds.
31
- */
32
- function sleep(ms) {
33
- return new Promise((resolve) => setTimeout(resolve, ms));
34
- }
35
- //# sourceMappingURL=utils.js.map
package/dist/utils.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AAGA,oCAEC;AAKD,8BAMC;AAKD,wBAMC;AAKD,sBAEC;AAlCD;;GAEG;AACH,SAAgB,YAAY;IAC1B,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,SAAgB,SAAS;IACvB,OAAO,CACL,OAAO,UAAU,KAAK,WAAW;QACjC,OAAQ,UAAsC,CAAC,MAAM,KAAK,WAAW;QACrE,OAAQ,UAAsC,CAAC,QAAQ,KAAK,WAAW,CACxE,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,MAAM;IACpB,OAAO,CACL,OAAO,OAAO,KAAK,WAAW;QAC9B,OAAO,CAAC,QAAQ,IAAI,IAAI;QACxB,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,IAAI,CAC9B,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,KAAK,CAAC,EAAU;IAC9B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
package/src/index.ts DELETED
@@ -1,15 +0,0 @@
1
- export { MihariClient } from "./client";
2
- export { HttpTransport } from "./transport";
3
- export { Batcher } from "./batcher";
4
- export type { FlushCallback } from "./batcher";
5
- export { isoTimestamp, isBrowser, isNode, sleep } from "./utils";
6
- export {
7
- LogLevel,
8
- LogEntry,
9
- MihariConfig,
10
- TransportOptions,
11
- BatchOptions,
12
- TransportResponse,
13
- TransportError,
14
- CompressFn,
15
- } from "@mihari/logger-types";