logixia 2.0.0 → 2.0.6
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.
- package/README.md +172 -2597
- package/dist/async-context-2mbUKhcl.mjs +132 -0
- package/dist/async-context-2mbUKhcl.mjs.map +1 -0
- package/dist/async-context-DUFMDYAr.js +148 -0
- package/dist/async-context-DUFMDYAr.js.map +1 -0
- package/dist/{azure-monitor.transport-CrvfHd9C.js → azure-monitor.transport-Bu4S2I2q.js} +32 -20
- package/dist/azure-monitor.transport-Bu4S2I2q.js.map +1 -0
- package/dist/{azure-monitor.transport-Cn_3Usvu.d.ts → azure-monitor.transport-Bvf7Xegt.d.ts} +3 -6
- package/dist/azure-monitor.transport-Bvf7Xegt.d.ts.map +1 -0
- package/dist/{azure-monitor.transport-CHnjVRF-.mjs → azure-monitor.transport-C1RWAumT.mjs} +27 -15
- package/dist/azure-monitor.transport-C1RWAumT.mjs.map +1 -0
- package/dist/{azure-monitor.transport-D7Da4RAb.d.mts → azure-monitor.transport-CbSHOnNX.d.mts} +3 -6
- package/dist/azure-monitor.transport-CbSHOnNX.d.mts.map +1 -0
- package/dist/azure.d.mts +1 -2
- package/dist/azure.d.ts +1 -2
- package/dist/azure.js +3 -6
- package/dist/azure.mjs +1 -6
- package/dist/{batch-buffer-PGvSgbmd.mjs → batch-buffer-BvXLDPlV.mjs} +21 -7
- package/dist/batch-buffer-BvXLDPlV.mjs.map +1 -0
- package/dist/{batch-buffer-BY-mRWIK.js → batch-buffer-C7Am4Mw-.js} +53 -40
- package/dist/batch-buffer-C7Am4Mw-.js.map +1 -0
- package/dist/browser.d.mts +47 -27
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.d.ts +47 -27
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +464 -62
- package/dist/browser.js.map +1 -1
- package/dist/browser.mjs +465 -65
- package/dist/browser.mjs.map +1 -1
- package/dist/{builder-0gEzRopq.mjs → builder-DhNhvOkt.mjs} +307 -246
- package/dist/builder-DhNhvOkt.mjs.map +1 -0
- package/dist/{builder-D44QktIo.js → builder-yFvJrz7o.js} +435 -399
- package/dist/builder-yFvJrz7o.js.map +1 -0
- package/dist/cli/index.js +216 -125
- package/dist/cloudwatch.d.mts +1 -2
- package/dist/cloudwatch.d.ts +1 -2
- package/dist/cloudwatch.js +3 -7
- package/dist/cloudwatch.mjs +1 -7
- package/dist/{cloudwatch.transport-DsEq633o.d.ts → cloudwatch.transport-CQyT6U91.d.ts} +2 -6
- package/dist/cloudwatch.transport-CQyT6U91.d.ts.map +1 -0
- package/dist/{cloudwatch.transport-BO1ahxw-.js → cloudwatch.transport-Ch1Uae-0.js} +61 -36
- package/dist/cloudwatch.transport-Ch1Uae-0.js.map +1 -0
- package/dist/{cloudwatch.transport-UlyZFWMn.d.mts → cloudwatch.transport-CjVrI6S4.d.mts} +2 -6
- package/dist/cloudwatch.transport-CjVrI6S4.d.mts.map +1 -0
- package/dist/{cloudwatch.transport-DZ6ies7g.mjs → cloudwatch.transport-DZqF2xZO.mjs} +54 -28
- package/dist/cloudwatch.transport-DZqF2xZO.mjs.map +1 -0
- package/dist/{coerce.utils-Cu6IUTgX.mjs → coerce.utils-B_rEudCn.mjs} +3 -4
- package/dist/{coerce.utils-Cu6IUTgX.mjs.map → coerce.utils-B_rEudCn.mjs.map} +1 -1
- package/dist/{coerce.utils-B-LilukN.js → coerce.utils-C1C5sIX0.js} +8 -10
- package/dist/{coerce.utils-B-LilukN.js.map → coerce.utils-C1C5sIX0.js.map} +1 -1
- package/dist/correlation.d.mts +15 -69
- package/dist/correlation.d.mts.map +1 -1
- package/dist/correlation.d.ts +15 -69
- package/dist/correlation.d.ts.map +1 -1
- package/dist/correlation.js +69 -20
- package/dist/correlation.js.map +1 -1
- package/dist/correlation.mjs +67 -17
- package/dist/correlation.mjs.map +1 -1
- package/dist/{entry-fields-BvOLFlJ4.js → entry-fields-BSLkzw18.js} +16 -13
- package/dist/entry-fields-BSLkzw18.js.map +1 -0
- package/dist/{entry-fields-BJkuPnIg.mjs → entry-fields-J1OBi24o.mjs} +11 -7
- package/dist/entry-fields-J1OBi24o.mjs.map +1 -0
- package/dist/gcp.d.mts +1 -2
- package/dist/gcp.d.ts +1 -2
- package/dist/gcp.js +3 -7
- package/dist/gcp.mjs +1 -7
- package/dist/{gcp.transport-B7oc97sG.d.ts → gcp.transport-BCIvdFV-.d.ts} +5 -8
- package/dist/gcp.transport-BCIvdFV-.d.ts.map +1 -0
- package/dist/{gcp.transport-GrJurKo8.d.mts → gcp.transport-D9SdLPwP.d.mts} +5 -8
- package/dist/gcp.transport-D9SdLPwP.d.mts.map +1 -0
- package/dist/{gcp.transport-DBX5TPIy.mjs → gcp.transport-DVCmnA3b.mjs} +59 -16
- package/dist/gcp.transport-DVCmnA3b.mjs.map +1 -0
- package/dist/{gcp.transport-CHV8MGgz.js → gcp.transport-Dy2Lf8FI.js} +64 -22
- package/dist/gcp.transport-Dy2Lf8FI.js.map +1 -0
- package/dist/http-shapes-BnBkJcid.d.mts +32 -0
- package/dist/http-shapes-BnBkJcid.d.mts.map +1 -0
- package/dist/http-shapes-BnBkJcid.d.ts +32 -0
- package/dist/http-shapes-BnBkJcid.d.ts.map +1 -0
- package/dist/{index-3mw5gaCw.d.mts → index-BSTtFcQ6.d.mts} +142 -13
- package/dist/index-BSTtFcQ6.d.mts.map +1 -0
- package/dist/{index-DhIoploR.d.ts → index-CFDGkI8n.d.ts} +142 -13
- package/dist/index-CFDGkI8n.d.ts.map +1 -0
- package/dist/index.d.mts +114 -217
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +113 -216
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +182 -279
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +160 -256
- package/dist/index.mjs.map +1 -1
- package/dist/internal-log-Bg4V1cPg.mjs +170 -0
- package/dist/internal-log-Bg4V1cPg.mjs.map +1 -0
- package/dist/internal-log-By4Govmu.js +223 -0
- package/dist/internal-log-By4Govmu.js.map +1 -0
- package/dist/{logitron-logger-UVeN-mQm.d.ts → logitron-logger-D22Yb61K.d.mts} +121 -100
- package/dist/logitron-logger-D22Yb61K.d.mts.map +1 -0
- package/dist/{logitron-logger-BFDSO8Io.d.mts → logitron-logger-D_MYYrQt.d.ts} +121 -100
- package/dist/logitron-logger-D_MYYrQt.d.ts.map +1 -0
- package/dist/middleware.d.mts +13 -28
- package/dist/middleware.d.mts.map +1 -1
- package/dist/middleware.d.ts +13 -28
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +20 -81
- package/dist/middleware.js.map +1 -1
- package/dist/middleware.mjs +17 -79
- package/dist/middleware.mjs.map +1 -1
- package/dist/nest.d.mts +37 -48
- package/dist/nest.d.mts.map +1 -1
- package/dist/nest.d.ts +37 -48
- package/dist/nest.d.ts.map +1 -1
- package/dist/nest.js +124 -135
- package/dist/nest.js.map +1 -1
- package/dist/nest.mjs +69 -78
- package/dist/nest.mjs.map +1 -1
- package/dist/{transport.manager-BiuCAJd2.mjs → otel-Dt5riXuE.mjs} +275 -117
- package/dist/otel-Dt5riXuE.mjs.map +1 -0
- package/dist/{transport.manager-CXbKKdVE.js → otel-DyeH6DVR.js} +373 -178
- package/dist/otel-DyeH6DVR.js.map +1 -0
- package/dist/own-property-BWkibepN.js +40 -0
- package/dist/own-property-BWkibepN.js.map +1 -0
- package/dist/own-property-CjFw9qwZ.mjs +29 -0
- package/dist/own-property-CjFw9qwZ.mjs.map +1 -0
- package/dist/{trace.utils-CvXgaiQT.mjs → request-trace-BgNykH9M.mjs} +40 -9
- package/dist/request-trace-BgNykH9M.mjs.map +1 -0
- package/dist/{trace.utils-DpBOLDtq.js → request-trace-ByujsUZk.js} +117 -77
- package/dist/request-trace-ByujsUZk.js.map +1 -0
- package/dist/rolldown-runtime-D3PmRqjj.mjs +4 -0
- package/dist/{safe-stringify-DJ66tW5I.mjs → safe-stringify-B5p5ktFe.mjs} +39 -15
- package/dist/safe-stringify-B5p5ktFe.mjs.map +1 -0
- package/dist/{safe-stringify-DWo3aZp_.js → safe-stringify-J3sh-7YM.js} +59 -36
- package/dist/safe-stringify-J3sh-7YM.js.map +1 -0
- package/dist/{search-C4V0OMEn.js → search-CRjhHxe9.js} +319 -92
- package/dist/search-CRjhHxe9.js.map +1 -0
- package/dist/{search-CNh9uVwR.d.ts → search-DA3ft3X5.d.mts} +5 -22
- package/dist/search-DA3ft3X5.d.mts.map +1 -0
- package/dist/{search-BFbu_oVn.mjs → search-DAXKE-P9.mjs} +289 -62
- package/dist/search-DAXKE-P9.mjs.map +1 -0
- package/dist/{search-DXANsQ2n.d.mts → search-DEl3Pe47.d.ts} +5 -22
- package/dist/search-DEl3Pe47.d.ts.map +1 -0
- package/dist/search.d.mts +2 -4
- package/dist/search.d.ts +2 -4
- package/dist/search.js +3 -4
- package/dist/search.mjs +1 -4
- package/dist/secret-config-CmK2wVkr.js +272 -0
- package/dist/secret-config-CmK2wVkr.js.map +1 -0
- package/dist/secret-config-Dhb6pqTU.mjs +210 -0
- package/dist/secret-config-Dhb6pqTU.mjs.map +1 -0
- package/dist/{slack.transport-CXjQYOes.d.ts → slack.transport-BDyENuR0.d.mts} +56 -9
- package/dist/slack.transport-BDyENuR0.d.mts.map +1 -0
- package/dist/{slack.transport-Bzw7sucI.mjs → slack.transport-BTEwsREY.mjs} +263 -31
- package/dist/slack.transport-BTEwsREY.mjs.map +1 -0
- package/dist/{slack.transport-BZzoXDPn.d.mts → slack.transport-C6E0l4kw.d.ts} +56 -9
- package/dist/slack.transport-C6E0l4kw.d.ts.map +1 -0
- package/dist/{slack.transport-BfJRouB2.js → slack.transport-UbYvOdKx.js} +286 -42
- package/dist/slack.transport-UbYvOdKx.js.map +1 -0
- package/dist/testing.d.mts +13 -11
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.d.ts +13 -11
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +41 -7
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +40 -6
- package/dist/testing.mjs.map +1 -1
- package/dist/{transport.types-CGoHpWQR.d.ts → transport.types-CzJq4IrF.d.mts} +14 -5
- package/dist/transport.types-CzJq4IrF.d.mts.map +1 -0
- package/dist/{transport.types-BMnurPcc.d.mts → transport.types-CzJq4IrF.d.ts} +14 -5
- package/dist/transport.types-CzJq4IrF.d.ts.map +1 -0
- package/dist/transports.d.mts +39 -41
- package/dist/transports.d.mts.map +1 -1
- package/dist/transports.d.ts +39 -41
- package/dist/transports.d.ts.map +1 -1
- package/dist/transports.js +19 -22
- package/dist/transports.mjs +7 -13
- package/dist/worker-entry.js +438 -107
- package/dist/worker.d.mts +1 -2
- package/dist/worker.d.ts +1 -2
- package/dist/worker.js +3 -4
- package/dist/worker.mjs +1 -4
- package/dist/{worker.transport-JvGPog3C.d.mts → worker.transport-B9mCQSM1.d.ts} +7 -6
- package/dist/worker.transport-B9mCQSM1.d.ts.map +1 -0
- package/dist/{worker.transport-CdzSZJmw.d.ts → worker.transport-Bl8lFRck.d.mts} +7 -6
- package/dist/worker.transport-Bl8lFRck.d.mts.map +1 -0
- package/dist/{worker.transport-lPxO2MVL.mjs → worker.transport-BmmOKb1-.mjs} +43 -10
- package/dist/worker.transport-BmmOKb1-.mjs.map +1 -0
- package/dist/{worker.transport-BdPxu3PN.js → worker.transport-DxxbqQCG.js} +48 -15
- package/dist/worker.transport-DxxbqQCG.js.map +1 -0
- package/package.json +51 -75
- package/dist/async-context-BzJrbfQs.mjs +0 -72
- package/dist/async-context-BzJrbfQs.mjs.map +0 -1
- package/dist/async-context-DyQQYq3I.js +0 -92
- package/dist/async-context-DyQQYq3I.js.map +0 -1
- package/dist/azure-monitor.transport-CHnjVRF-.mjs.map +0 -1
- package/dist/azure-monitor.transport-Cn_3Usvu.d.ts.map +0 -1
- package/dist/azure-monitor.transport-CrvfHd9C.js.map +0 -1
- package/dist/azure-monitor.transport-D7Da4RAb.d.mts.map +0 -1
- package/dist/batch-buffer-BY-mRWIK.js.map +0 -1
- package/dist/batch-buffer-PGvSgbmd.mjs.map +0 -1
- package/dist/builder-0gEzRopq.mjs.map +0 -1
- package/dist/builder-D44QktIo.js.map +0 -1
- package/dist/chunk-DLSkYcPk.mjs +0 -7
- package/dist/chunk-nOFOJqeH.js +0 -30
- package/dist/cloudwatch.transport-BO1ahxw-.js.map +0 -1
- package/dist/cloudwatch.transport-DZ6ies7g.mjs.map +0 -1
- package/dist/cloudwatch.transport-DsEq633o.d.ts.map +0 -1
- package/dist/cloudwatch.transport-UlyZFWMn.d.mts.map +0 -1
- package/dist/entry-fields-BJkuPnIg.mjs.map +0 -1
- package/dist/entry-fields-BvOLFlJ4.js.map +0 -1
- package/dist/gcp.transport-B7oc97sG.d.ts.map +0 -1
- package/dist/gcp.transport-CHV8MGgz.js.map +0 -1
- package/dist/gcp.transport-DBX5TPIy.mjs.map +0 -1
- package/dist/gcp.transport-GrJurKo8.d.mts.map +0 -1
- package/dist/index-3mw5gaCw.d.mts.map +0 -1
- package/dist/index-DhIoploR.d.ts.map +0 -1
- package/dist/internal-log-BUJYMZbE.js +0 -70
- package/dist/internal-log-BUJYMZbE.js.map +0 -1
- package/dist/internal-log-Cm8SOWSV.mjs +0 -52
- package/dist/internal-log-Cm8SOWSV.mjs.map +0 -1
- package/dist/logitron-logger-BFDSO8Io.d.mts.map +0 -1
- package/dist/logitron-logger-UVeN-mQm.d.ts.map +0 -1
- package/dist/safe-stringify-DJ66tW5I.mjs.map +0 -1
- package/dist/safe-stringify-DWo3aZp_.js.map +0 -1
- package/dist/search-BFbu_oVn.mjs.map +0 -1
- package/dist/search-C4V0OMEn.js.map +0 -1
- package/dist/search-CNh9uVwR.d.ts.map +0 -1
- package/dist/search-DXANsQ2n.d.mts.map +0 -1
- package/dist/slack.transport-BZzoXDPn.d.mts.map +0 -1
- package/dist/slack.transport-BfJRouB2.js.map +0 -1
- package/dist/slack.transport-Bzw7sucI.mjs.map +0 -1
- package/dist/slack.transport-CXjQYOes.d.ts.map +0 -1
- package/dist/trace.utils-CvXgaiQT.mjs.map +0 -1
- package/dist/trace.utils-DpBOLDtq.js.map +0 -1
- package/dist/transport.manager-BiuCAJd2.mjs.map +0 -1
- package/dist/transport.manager-CXbKKdVE.js.map +0 -1
- package/dist/transport.types-BMnurPcc.d.mts.map +0 -1
- package/dist/transport.types-CGoHpWQR.d.ts.map +0 -1
- package/dist/worker.transport-BdPxu3PN.js.map +0 -1
- package/dist/worker.transport-CdzSZJmw.d.ts.map +0 -1
- package/dist/worker.transport-JvGPog3C.d.mts.map +0 -1
- package/dist/worker.transport-lPxO2MVL.mjs.map +0 -1
package/dist/browser.mjs
CHANGED
|
@@ -1,11 +1,301 @@
|
|
|
1
|
-
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
2
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
3
3
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
4
|
-
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function.");
|
|
4
|
+
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
// src/utils/own-property.ts
|
|
7
|
+
/**
|
|
8
|
+
* Copy `value` onto `target[key]` as an own, enumerable data property.
|
|
9
|
+
*
|
|
10
|
+
* Normal keys use a plain assignment, which is the fast path. `__proto__` goes
|
|
11
|
+
* through `Object.defineProperty` so that a key taken from logged or parsed data
|
|
12
|
+
* becomes an own property instead of replacing the object's prototype.
|
|
13
|
+
*/
|
|
14
|
+
function assignOwn(target, key, value) {
|
|
15
|
+
if (key === "__proto__") Object.defineProperty(target, key, {
|
|
16
|
+
value,
|
|
17
|
+
enumerable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
configurable: true
|
|
20
|
+
});
|
|
21
|
+
else target[key] = value;
|
|
22
|
+
}
|
|
23
|
+
// src/utils/sensitive-names.ts
|
|
24
|
+
/**
|
|
25
|
+
* The one list of sensitive names. Log redaction (redact.utils), the HTTP logger
|
|
26
|
+
* middleware and transport secret handling (transports/secret-config) all read it,
|
|
27
|
+
* so the lists cannot drift. No imports: safe from any module, including browser code.
|
|
28
|
+
*/
|
|
29
|
+
/** Field names redacted by name, wherever they appear in logged data. */
|
|
30
|
+
const SENSITIVE_KEY_NAMES = [
|
|
31
|
+
"password",
|
|
32
|
+
"passwd",
|
|
33
|
+
"secret",
|
|
34
|
+
"token",
|
|
35
|
+
"apiKey",
|
|
36
|
+
"api_key",
|
|
37
|
+
"accessToken",
|
|
38
|
+
"access_token",
|
|
39
|
+
"refreshToken",
|
|
40
|
+
"refresh_token",
|
|
41
|
+
"authorization",
|
|
42
|
+
"credentials",
|
|
43
|
+
"privateKey",
|
|
44
|
+
"private_key",
|
|
45
|
+
"clientSecret",
|
|
46
|
+
"client_secret",
|
|
47
|
+
"cookie",
|
|
48
|
+
"set-cookie",
|
|
49
|
+
"x-api-key",
|
|
50
|
+
"session",
|
|
51
|
+
"proxy-authorization",
|
|
52
|
+
"x-auth-token",
|
|
53
|
+
"x-access-token",
|
|
54
|
+
"aws_secret_access_key",
|
|
55
|
+
"awsSecretAccessKey",
|
|
56
|
+
"secretAccessKey"
|
|
57
|
+
];
|
|
58
|
+
/**
|
|
59
|
+
* Extra names that only mean "secret" inside transport configuration, where
|
|
60
|
+
* short words like `key` or `signature` are credentials, not log fields.
|
|
61
|
+
*/
|
|
62
|
+
const TRANSPORT_CONFIG_SECRET_NAMES = [
|
|
63
|
+
"writeKey",
|
|
64
|
+
"apiSecret",
|
|
65
|
+
"connectionString",
|
|
66
|
+
"sessionToken",
|
|
67
|
+
"passphrase",
|
|
68
|
+
"signature",
|
|
69
|
+
"pwd",
|
|
70
|
+
"pfx",
|
|
71
|
+
"cert",
|
|
72
|
+
"key",
|
|
73
|
+
"auth"
|
|
74
|
+
];
|
|
75
|
+
/** Query-string parameters whose values are never logged. */
|
|
76
|
+
const DEFAULT_REDACT_QUERY_PARAMS = [
|
|
77
|
+
"token",
|
|
78
|
+
"access_token",
|
|
79
|
+
"refresh_token",
|
|
80
|
+
"code",
|
|
81
|
+
"password",
|
|
82
|
+
"secret",
|
|
83
|
+
"api_key",
|
|
84
|
+
"apikey",
|
|
85
|
+
"key",
|
|
86
|
+
"signature",
|
|
87
|
+
"sig",
|
|
88
|
+
"auth"
|
|
89
|
+
];
|
|
90
|
+
// src/transports/secret-config.ts
|
|
91
|
+
/**
|
|
92
|
+
* Keeps credentials out of serialized transport output and error text.
|
|
93
|
+
*
|
|
94
|
+
* `protectSecrets()` replaces each listed field with a non-enumerable accessor backed
|
|
95
|
+
* by a WeakMap, whether or not the field is assigned yet, so later assignments (a
|
|
96
|
+
* connection opened on first write, a refreshed token) stay hidden too. It also
|
|
97
|
+
* installs `toJSON()` and a Node inspect hook returning a redacted view: scalar
|
|
98
|
+
* fields stay for debugging, secret-looking keys become '[REDACTED]', URLs lose
|
|
99
|
+
* userinfo, query and fragment. No Node imports, so browser bundles can use it.
|
|
100
|
+
*/
|
|
101
|
+
const REDACTED = "[REDACTED]";
|
|
102
|
+
const INSPECT_CUSTOM = Symbol.for("nodejs.util.inspect.custom");
|
|
103
|
+
const MAX_DEPTH = 4;
|
|
104
|
+
const SCHEME_PREFIX = /^[a-z][a-z0-9+.-]*:\/\//i;
|
|
105
|
+
function normalizeName(name) {
|
|
106
|
+
return name.toLowerCase().replaceAll("-", "").replaceAll("_", "");
|
|
107
|
+
}
|
|
108
|
+
const SECRET_NAMES = [...SENSITIVE_KEY_NAMES, ...TRANSPORT_CONFIG_SECRET_NAMES].map(normalizeName);
|
|
109
|
+
new Set(DEFAULT_REDACT_QUERY_PARAMS.map(normalizeName));
|
|
110
|
+
/** Exact match for short names (`key`, `pfx`), suffix match for longer ones (`azureClientSecret`). */
|
|
111
|
+
function isSecretKey(key) {
|
|
112
|
+
const name = normalizeName(key);
|
|
113
|
+
return SECRET_NAMES.some((n) => name === n || n.length >= 5 && name.endsWith(n));
|
|
114
|
+
}
|
|
115
|
+
function isUrlKey(key) {
|
|
116
|
+
return /url|uri|endpoint|href/i.test(key);
|
|
117
|
+
}
|
|
118
|
+
function isPlainObject(value) {
|
|
119
|
+
const proto = Object.getPrototypeOf(value);
|
|
120
|
+
return proto === Object.prototype || proto === null;
|
|
121
|
+
}
|
|
122
|
+
/** Absolute URL: `scheme://host` only. Relative or unparseable: path kept, query and fragment cut. */
|
|
123
|
+
function redactUrl(raw) {
|
|
124
|
+
if (typeof raw !== "string") return `${raw.protocol}//${raw.host}`;
|
|
125
|
+
if (SCHEME_PREFIX.test(raw)) try {
|
|
126
|
+
const url = new URL(raw);
|
|
127
|
+
return `${url.protocol}//${url.host}`;
|
|
128
|
+
} catch {
|
|
129
|
+
return REDACTED;
|
|
130
|
+
}
|
|
131
|
+
return raw.split(/[?#]/, 1)[0] ?? "";
|
|
132
|
+
}
|
|
133
|
+
function redactHeaders(headers) {
|
|
134
|
+
if (!headers || typeof headers !== "object") return headers;
|
|
135
|
+
return Object.fromEntries(Object.keys(headers).map((name) => [name, REDACTED]));
|
|
136
|
+
}
|
|
137
|
+
/** Redacted deep copy of a config-like value. Never throws, never returns a secret. */
|
|
138
|
+
function redactConfig(value, depth = 0, key = "") {
|
|
139
|
+
var _value$constructor;
|
|
140
|
+
if (value === null || value === void 0) return value;
|
|
141
|
+
if (typeof value === "string") return SCHEME_PREFIX.test(value) || isUrlKey(key) ? redactUrl(value) : value;
|
|
142
|
+
if (typeof value === "number" || typeof value === "boolean") return value;
|
|
143
|
+
if (typeof value === "function") return "[Function]";
|
|
144
|
+
if (typeof value !== "object") return "[Unserializable]";
|
|
145
|
+
if (typeof URL !== "undefined" && value instanceof URL) return redactUrl(value);
|
|
146
|
+
if (Array.isArray(value)) return depth >= MAX_DEPTH ? "[Array]" : value.map((v) => redactConfig(v, depth + 1, key));
|
|
147
|
+
if (!isPlainObject(value) || depth >= MAX_DEPTH) return `[${((_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor.name) ?? "Object"}]`;
|
|
148
|
+
const out = {};
|
|
149
|
+
for (const [name, inner] of Object.entries(value)) if (isSecretKey(name)) assignOwn(out, name, inner === void 0 ? void 0 : REDACTED);
|
|
150
|
+
else if (name.toLowerCase() === "headers") assignOwn(out, name, redactHeaders(inner));
|
|
151
|
+
else assignOwn(out, name, redactConfig(inner, depth + 1, name));
|
|
152
|
+
return out;
|
|
153
|
+
}
|
|
154
|
+
const hiddenKeys = /* @__PURE__ */ new WeakMap();
|
|
155
|
+
const hiddenValues = /* @__PURE__ */ new WeakMap();
|
|
156
|
+
function viewOf(target) {
|
|
157
|
+
var _target$constructor;
|
|
158
|
+
const hidden = hiddenKeys.get(target) ?? /* @__PURE__ */ new Set();
|
|
159
|
+
const values = hiddenValues.get(target);
|
|
160
|
+
const view = { class: (_target$constructor = target.constructor) === null || _target$constructor === void 0 ? void 0 : _target$constructor.name };
|
|
161
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(target), ...hidden])) {
|
|
162
|
+
const inner = hidden.has(key) ? values === null || values === void 0 ? void 0 : values.get(key) : target[key];
|
|
163
|
+
if (isSecretKey(key)) view[key] = inner === void 0 ? void 0 : REDACTED;
|
|
164
|
+
else if (key.toLowerCase() === "headers") view[key] = redactHeaders(inner);
|
|
165
|
+
else if (inner !== null && typeof inner === "object" && !hidden.has(key) && !(inner instanceof URL)) view[key] = "[Object]";
|
|
166
|
+
else if (hidden.has(key) && typeof inner === "string" && !isUrlKey(key)) view[key] = REDACTED;
|
|
167
|
+
else view[key] = redactConfig(inner, 0, key);
|
|
168
|
+
}
|
|
169
|
+
return view;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Hides `keys` on `target` (assigned or not yet) and gives it a redacted `toJSON()` /
|
|
173
|
+
* inspect view. Fields stay readable and writable. Safe to call more than once.
|
|
174
|
+
* Throws when the target cannot carry the protection (frozen or sealed), instead of
|
|
175
|
+
* silently leaving the secret enumerable.
|
|
176
|
+
*/
|
|
177
|
+
function protectSecrets(target, keys) {
|
|
178
|
+
if (!Object.isExtensible(target)) {
|
|
179
|
+
var _target$constructor2;
|
|
180
|
+
throw new TypeError(`protectSecrets: ${((_target$constructor2 = target.constructor) === null || _target$constructor2 === void 0 ? void 0 : _target$constructor2.name) ?? "object"} is not extensible`);
|
|
181
|
+
}
|
|
182
|
+
let hidden = hiddenKeys.get(target);
|
|
183
|
+
let values = hiddenValues.get(target);
|
|
184
|
+
if (!hidden || !values) {
|
|
185
|
+
hidden = /* @__PURE__ */ new Set();
|
|
186
|
+
values = /* @__PURE__ */ new Map();
|
|
187
|
+
hiddenKeys.set(target, hidden);
|
|
188
|
+
hiddenValues.set(target, values);
|
|
189
|
+
const view = () => viewOf(target);
|
|
190
|
+
Object.defineProperty(target, "toJSON", {
|
|
191
|
+
value: view,
|
|
192
|
+
enumerable: false,
|
|
193
|
+
configurable: true
|
|
194
|
+
});
|
|
195
|
+
Object.defineProperty(target, INSPECT_CUSTOM, {
|
|
196
|
+
value: view,
|
|
197
|
+
enumerable: false,
|
|
198
|
+
configurable: true
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
const store = values;
|
|
202
|
+
for (const key of keys) {
|
|
203
|
+
if (hidden.has(key)) continue;
|
|
204
|
+
const desc = Object.getOwnPropertyDescriptor(target, key);
|
|
205
|
+
if (desc && !desc.configurable) throw new TypeError(`protectSecrets: "${key}" is not configurable`);
|
|
206
|
+
if (desc && "value" in desc) store.set(key, desc.value);
|
|
207
|
+
hidden.add(key);
|
|
208
|
+
Object.defineProperty(target, key, {
|
|
209
|
+
enumerable: false,
|
|
210
|
+
configurable: true,
|
|
211
|
+
get: () => store.get(key),
|
|
212
|
+
set: (next) => void store.set(key, next)
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// src/utils/internal-log.ts
|
|
217
|
+
/**
|
|
218
|
+
* Internal logging helpers for use within the logixia library itself.
|
|
219
|
+
*
|
|
220
|
+
* These functions write directly to stderr/stdout without going through
|
|
221
|
+
* LogixiaLogger — this avoids circular dependencies and ensures internal
|
|
222
|
+
* diagnostics still surface even when the logger is misconfigured.
|
|
223
|
+
*
|
|
224
|
+
* Library code must NEVER call console.log/warn/error directly. Use these
|
|
225
|
+
* helpers instead so that internal output can be silenced in tests by setting
|
|
226
|
+
* the LOGIXIA_SILENT_INTERNAL=1 environment variable.
|
|
227
|
+
*/
|
|
228
|
+
/**
|
|
229
|
+
* Read the silence flag on each call rather than caching it at import time, so
|
|
230
|
+
* setting LOGIXIA_SILENT_INTERNAL=1 AFTER the module is first imported (e.g. in
|
|
231
|
+
* a test setup file) still takes effect — the documented test-silencing
|
|
232
|
+
* behavior was previously unreliable because the value was frozen at load.
|
|
233
|
+
*/
|
|
234
|
+
function isSilent() {
|
|
235
|
+
var _process$env;
|
|
236
|
+
if (typeof process !== "undefined" && ((_process$env = process.env) === null || _process$env === void 0 ? void 0 : _process$env.LOGIXIA_SILENT_INTERNAL) === "1") return true;
|
|
237
|
+
const flag = globalThis["LOGIXIA_SILENT_INTERNAL"];
|
|
238
|
+
return flag === "1" || flag === 1 || flag === true;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Write a line to stderr, falling back to the matching console method where
|
|
242
|
+
* `process` is unavailable (browsers, Cloudflare Workers, Deno without Node compat).
|
|
243
|
+
*/
|
|
244
|
+
function writeLine(method, line) {
|
|
245
|
+
var _process$stderr;
|
|
246
|
+
if (typeof process !== "undefined" && typeof ((_process$stderr = process.stderr) === null || _process$stderr === void 0 ? void 0 : _process$stderr.write) === "function") process.stderr.write(`${line}\n`);
|
|
247
|
+
else if (typeof console !== "undefined" && typeof console[method] === "function") console[method](line);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Emit an internal debug/info message to stderr.
|
|
251
|
+
* Use for field-enable/disable notifications that a developer might want to see
|
|
252
|
+
* during development but should not appear in production log streams.
|
|
253
|
+
*/
|
|
254
|
+
function internalLog(message) {
|
|
255
|
+
if (!isSilent()) writeLine("log", `[logixia] ${message}`);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Emit an internal warning to stderr.
|
|
259
|
+
* Use when something is misconfigured but logixia can continue operating.
|
|
260
|
+
*/
|
|
261
|
+
function internalWarn(message) {
|
|
262
|
+
if (!isSilent()) writeLine("warn", `[logixia:warn] ${message}`);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Emit an internal error to stderr.
|
|
266
|
+
* Use when a transport write fails or a serious internal error occurs.
|
|
267
|
+
*/
|
|
268
|
+
function internalError(message, error) {
|
|
269
|
+
if (!isSilent()) {
|
|
270
|
+
let errStr = "";
|
|
271
|
+
if (error instanceof Error) errStr = ` — ${error.message}`;
|
|
272
|
+
else if (error != null) errStr = ` — ${String(error)}`;
|
|
273
|
+
writeLine("error", `[logixia:error] ${message}${errStr}`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
// src/utils/safe-stringify.ts
|
|
277
|
+
/**
|
|
278
|
+
* logixia — robust JSON serialization for log payloads.
|
|
279
|
+
*
|
|
280
|
+
* Modern Winston/Pino already neutralize circular refs to `[Circular]` (via
|
|
281
|
+
* safe-stable-stringify / fast-safe-stringify), so merely "surviving cycles" is
|
|
282
|
+
* not a differentiator. This goes one notch further:
|
|
283
|
+
*
|
|
284
|
+
* - **BigInt** → serialized (as a string by default; JSON.stringify throws on
|
|
285
|
+
* BigInt, which silently breaks logging of e.g. DB bigint ids).
|
|
286
|
+
* - **Deterministic key order** (optional) so identical objects hash/diff equal.
|
|
287
|
+
* - **True decycle** (optional) — replace repeated references with JSONPath
|
|
288
|
+
* `$ref` pointers that round-trip back to the original object graph, instead
|
|
289
|
+
* of the lossy `[Circular]` tag. Useful when you need to reconstruct shared
|
|
290
|
+
* structure downstream.
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```ts
|
|
294
|
+
* safeStringify({ id: 10n, self: obj }); // → BigInt + cycle safe
|
|
295
|
+
* safeStringify(graph, { decycle: true }); // → round-trippable $ref pointers
|
|
296
|
+
* const back = retrocycle(JSON.parse(json)); // → reconstruct shared refs
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
9
299
|
/** Build a JSONPath like `$["a"][0]["b"]` for a decycle pointer. */
|
|
10
300
|
function jsonPath(parts) {
|
|
11
301
|
let path = "$";
|
|
@@ -35,10 +325,7 @@ function safeStringify(value, options = {}) {
|
|
|
35
325
|
const rec = val;
|
|
36
326
|
const keys = deterministic ? Object.keys(rec).sort() : Object.keys(rec);
|
|
37
327
|
const obj = {};
|
|
38
|
-
for (const k of keys)
|
|
39
|
-
if (k === "__proto__" || k === "constructor" || k === "prototype") continue;
|
|
40
|
-
obj[k] = transform(rec[k]);
|
|
41
|
-
}
|
|
328
|
+
for (const k of keys) assignOwn(obj, k, transform(rec[k]));
|
|
42
329
|
out = obj;
|
|
43
330
|
}
|
|
44
331
|
seen.delete(val);
|
|
@@ -63,10 +350,7 @@ function decycleValue(value, bigint = "string") {
|
|
|
63
350
|
if (Array.isArray(val)) return val.map((item, i) => walk(item, [...path, i]));
|
|
64
351
|
const rec = val;
|
|
65
352
|
const obj = {};
|
|
66
|
-
for (const k of Object.keys(rec))
|
|
67
|
-
if (k === "__proto__" || k === "constructor" || k === "prototype") continue;
|
|
68
|
-
obj[k] = walk(rec[k], [...path, k]);
|
|
69
|
-
}
|
|
353
|
+
for (const k of Object.keys(rec)) assignOwn(obj, k, walk(rec[k], [...path, k]));
|
|
70
354
|
return obj;
|
|
71
355
|
};
|
|
72
356
|
return walk(value, []);
|
|
@@ -89,9 +373,9 @@ function stringifyForLog(value) {
|
|
|
89
373
|
}
|
|
90
374
|
}
|
|
91
375
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
376
|
+
// src/utils/otel.ts
|
|
377
|
+
/** W3C trace-flags bit 0: the span is sampled (`TraceFlags.SAMPLED` in the OTel API). */
|
|
378
|
+
const TRACE_FLAG_SAMPLED = 1;
|
|
95
379
|
let _otelApi;
|
|
96
380
|
function tryLoadOtelApi() {
|
|
97
381
|
if (_otelApi !== void 0) return _otelApi;
|
|
@@ -119,7 +403,7 @@ function getActiveOtelContext(opts = {}) {
|
|
|
119
403
|
const ctx = api.context.active();
|
|
120
404
|
const sc = api.trace.getSpanContext(ctx);
|
|
121
405
|
if (!sc || !api.trace.isSpanContextValid(sc)) return void 0;
|
|
122
|
-
const isSampled = (sc.traceFlags &
|
|
406
|
+
const isSampled = (sc.traceFlags & TRACE_FLAG_SAMPLED) === TRACE_FLAG_SAMPLED;
|
|
123
407
|
if (opts.sampledOnly && !isSampled) return void 0;
|
|
124
408
|
return {
|
|
125
409
|
traceId: sc.traceId,
|
|
@@ -155,7 +439,6 @@ function getOtelMetaFields(opts = {}) {
|
|
|
155
439
|
[traceFlagsField]: ctx.traceFlags
|
|
156
440
|
};
|
|
157
441
|
}
|
|
158
|
-
let _bridgeOptions = null;
|
|
159
442
|
/**
|
|
160
443
|
* Initialise the global OTel bridge.
|
|
161
444
|
*
|
|
@@ -169,49 +452,60 @@ let _bridgeOptions = null;
|
|
|
169
452
|
* initOtelBridge();
|
|
170
453
|
* ```
|
|
171
454
|
*/
|
|
172
|
-
function initOtelBridge(opts = {}) {
|
|
173
|
-
_bridgeOptions = opts;
|
|
174
|
-
}
|
|
455
|
+
function initOtelBridge(opts = {}) {}
|
|
175
456
|
/**
|
|
176
457
|
* Disable the OTel bridge (useful for tests).
|
|
177
458
|
*/
|
|
178
|
-
function disableOtelBridge() {
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
//#endregion
|
|
183
|
-
//#region src/utils/internal-log.ts
|
|
459
|
+
function disableOtelBridge() {}
|
|
460
|
+
// src/utils/typed-logger.ts
|
|
184
461
|
/**
|
|
185
|
-
*
|
|
462
|
+
* logixia — TypeScript typed log fields
|
|
186
463
|
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* diagnostics still surface even when the logger is misconfigured.
|
|
464
|
+
* Solves the type-safety gap: standard `Record<string, unknown>` metadata gives
|
|
465
|
+
* zero IDE autocomplete and lets typos slip silently into production logs.
|
|
190
466
|
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
467
|
+
* Two complementary utilities:
|
|
468
|
+
*
|
|
469
|
+
* 1. `createTypedLogger<TFields>()` — wraps any IBaseLogger so that the second
|
|
470
|
+
* argument of every log method is constrained to `TFields` (a typed object).
|
|
471
|
+
* Compile-time safety, zero runtime overhead.
|
|
472
|
+
*
|
|
473
|
+
* 2. `defineLogSchema<TFields>(schema)` — declares expected fields with optional
|
|
474
|
+
* validators. In development (NODE_ENV !== 'production') every log call is
|
|
475
|
+
* validated against the schema and a warning is emitted for missing required
|
|
476
|
+
* fields or type mismatches.
|
|
477
|
+
*
|
|
478
|
+
* @example
|
|
479
|
+
* ```ts
|
|
480
|
+
* import { createTypedLogger, defineLogSchema } from 'logixia';
|
|
481
|
+
*
|
|
482
|
+
* interface OrderFields {
|
|
483
|
+
* orderId: string;
|
|
484
|
+
* userId: string;
|
|
485
|
+
* amount?: number;
|
|
486
|
+
* currency?: string;
|
|
487
|
+
* }
|
|
488
|
+
*
|
|
489
|
+
* const schema = defineLogSchema<OrderFields>({
|
|
490
|
+
* orderId: { type: 'string', required: true },
|
|
491
|
+
* userId: { type: 'string', required: true },
|
|
492
|
+
* amount: { type: 'number' },
|
|
493
|
+
* currency: { type: 'string' },
|
|
494
|
+
* });
|
|
495
|
+
*
|
|
496
|
+
* const orderLogger = createTypedLogger<OrderFields>(baseLogger, schema);
|
|
497
|
+
* await orderLogger.info('Order created', { orderId: 'ord_123', userId: 'usr_456', amount: 99.99 });
|
|
498
|
+
* // ^^^^ fully typed autocomplete ^^^^
|
|
499
|
+
* ```
|
|
200
500
|
*/
|
|
201
|
-
function
|
|
202
|
-
|
|
501
|
+
function isProduction() {
|
|
502
|
+
try {
|
|
503
|
+
return process.env.NODE_ENV === "production";
|
|
504
|
+
} catch {
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
203
507
|
}
|
|
204
508
|
/**
|
|
205
|
-
* Emit an internal warning to stderr.
|
|
206
|
-
* Use when something is misconfigured but logixia can continue operating.
|
|
207
|
-
*/
|
|
208
|
-
function internalWarn(message) {
|
|
209
|
-
if (!isSilent()) process.stderr.write(`[logixia:warn] ${message}\n`);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
//#endregion
|
|
213
|
-
//#region src/utils/typed-logger.ts
|
|
214
|
-
/**
|
|
215
509
|
* Define a typed schema for a category of log entries.
|
|
216
510
|
*
|
|
217
511
|
* Call this once at module initialisation and pass it to `createTypedLogger`.
|
|
@@ -221,7 +515,7 @@ function defineLogSchema(fields) {
|
|
|
221
515
|
return {
|
|
222
516
|
fields,
|
|
223
517
|
validate(payload) {
|
|
224
|
-
if (
|
|
518
|
+
if (isProduction()) return [];
|
|
225
519
|
const warnings = [];
|
|
226
520
|
for (const [key, def] of Object.entries(fields)) {
|
|
227
521
|
const value = payload[key];
|
|
@@ -273,9 +567,42 @@ function createTypedLogger(logger, schema) {
|
|
|
273
567
|
trace: (m, d) => withValidation("trace", (logger.trace ?? logger.debug).bind(logger), m, d)
|
|
274
568
|
};
|
|
275
569
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
570
|
+
// src/browser.ts
|
|
571
|
+
/**
|
|
572
|
+
* logixia — Browser / Edge Runtime entry point
|
|
573
|
+
*
|
|
574
|
+
* This module is the browser-safe subset of logixia. It contains **no**
|
|
575
|
+
* references to Node.js built-ins (`node:fs`, `node:http`, `node:worker_threads`,
|
|
576
|
+
* `node:crypto`, `node:async_hooks`) so it can be bundled for:
|
|
577
|
+
*
|
|
578
|
+
* - Browser (Webpack / Vite / esbuild)
|
|
579
|
+
* - Cloudflare Workers / Vercel Edge Functions
|
|
580
|
+
* - Deno (via ESM import)
|
|
581
|
+
* - Bun (core subset, no file/DB transports)
|
|
582
|
+
*
|
|
583
|
+
* Excluded from this entry: FileTransport, DatabaseTransport, WorkerTransport,
|
|
584
|
+
* CloudWatchTransport, GCPTransport, AzureMonitorTransport, and anything that
|
|
585
|
+
* requires `AsyncLocalStorage`.
|
|
586
|
+
*
|
|
587
|
+
* @example Basic browser usage
|
|
588
|
+
* ```ts
|
|
589
|
+
* import { createBrowserLogger, BrowserConsoleTransport } from 'logixia/browser';
|
|
590
|
+
*
|
|
591
|
+
* const logger = createBrowserLogger({ appName: 'my-app' });
|
|
592
|
+
* logger.info('Page loaded', { url: location.href });
|
|
593
|
+
* ```
|
|
594
|
+
*
|
|
595
|
+
* @example Custom transport in browser
|
|
596
|
+
* ```ts
|
|
597
|
+
* import { createBrowserLogger, BrowserConsoleTransport } from 'logixia/browser';
|
|
598
|
+
*
|
|
599
|
+
* const logger = createBrowserLogger({
|
|
600
|
+
* appName: 'my-app',
|
|
601
|
+
* json: false, // pretty-print in devtools
|
|
602
|
+
* level: 'debug',
|
|
603
|
+
* });
|
|
604
|
+
* ```
|
|
605
|
+
*/
|
|
279
606
|
const LEVEL_ORDER = {
|
|
280
607
|
verbose: 0,
|
|
281
608
|
debug: 1,
|
|
@@ -370,7 +697,7 @@ function validateRemoteUrl(raw) {
|
|
|
370
697
|
try {
|
|
371
698
|
parsed = new URL(raw);
|
|
372
699
|
} catch {
|
|
373
|
-
throw new TypeError(`BrowserRemoteTransport: invalid url
|
|
700
|
+
throw new TypeError(`BrowserRemoteTransport: invalid url [redacted]`);
|
|
374
701
|
}
|
|
375
702
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new TypeError(`BrowserRemoteTransport: url scheme "${parsed.protocol}" is not allowed; use http: or https:`);
|
|
376
703
|
return raw;
|
|
@@ -383,8 +710,33 @@ function validateRemoteUrl(raw) {
|
|
|
383
710
|
function byteLength(s) {
|
|
384
711
|
return new TextEncoder().encode(s).length;
|
|
385
712
|
}
|
|
713
|
+
const FAILURE_REPORT_INTERVAL_MS = 6e4;
|
|
714
|
+
/**
|
|
715
|
+
* Error name/code, HTTP status and host only. The error message is never
|
|
716
|
+
* included: runtimes embed request URLs (absolute or relative) and header
|
|
717
|
+
* values in it.
|
|
718
|
+
*/
|
|
719
|
+
function describeFailure(error, url) {
|
|
720
|
+
let host = "relative endpoint";
|
|
721
|
+
try {
|
|
722
|
+
host = `host ${new URL(url).host}`;
|
|
723
|
+
} catch {}
|
|
724
|
+
const e = error;
|
|
725
|
+
const parts = [];
|
|
726
|
+
if (e && typeof e.name === "string") parts.push(e.name);
|
|
727
|
+
if (e && typeof e.code === "string") parts.push(e.code);
|
|
728
|
+
if (e && typeof e.status === "number") parts.push(`HTTP ${e.status}`);
|
|
729
|
+
parts.push(host);
|
|
730
|
+
return parts.join(" ");
|
|
731
|
+
}
|
|
732
|
+
/** True only in a real browser page, where console noise reaches end users. */
|
|
733
|
+
function isBrowserPage() {
|
|
734
|
+
const g = globalThis;
|
|
735
|
+
return typeof g["window"] !== "undefined" && typeof g["document"] !== "undefined";
|
|
736
|
+
}
|
|
386
737
|
function isKeepaliveError(error) {
|
|
387
|
-
|
|
738
|
+
const message = error === null || error === void 0 ? void 0 : error.message;
|
|
739
|
+
return typeof message === "string" && /keepalive/i.test(message);
|
|
388
740
|
}
|
|
389
741
|
/**
|
|
390
742
|
* Browser transport that batches log entries and sends them to a remote
|
|
@@ -411,12 +763,17 @@ var BrowserRemoteTransport = class {
|
|
|
411
763
|
this.failedFlushCount = 0;
|
|
412
764
|
this.timer = null;
|
|
413
765
|
this.droppedEntries = 0;
|
|
766
|
+
this.reporting = false;
|
|
767
|
+
this.failureReported = false;
|
|
768
|
+
this.silent = options.silent ?? isBrowserPage();
|
|
769
|
+
this.onError = options.onError;
|
|
414
770
|
this.url = validateRemoteUrl(options.url);
|
|
415
771
|
this.headers = options.headers ?? {};
|
|
416
772
|
this.batchSize = options.batchSize ?? 100;
|
|
417
773
|
this.flushIntervalMs = options.flushIntervalMs ?? 5e3;
|
|
418
774
|
this.maxBufferSize = options.maxBufferSize ?? 1e3;
|
|
419
775
|
if (options.level !== void 0) this.level = options.level;
|
|
776
|
+
protectSecrets(this, ["headers", "url"]);
|
|
420
777
|
this.scheduleFlush();
|
|
421
778
|
}
|
|
422
779
|
/**
|
|
@@ -427,15 +784,23 @@ var BrowserRemoteTransport = class {
|
|
|
427
784
|
get dropped() {
|
|
428
785
|
return this.droppedEntries;
|
|
429
786
|
}
|
|
430
|
-
/** Number of flush attempts that failed
|
|
787
|
+
/** Number of flush attempts that failed (network error or non-OK HTTP status). */
|
|
431
788
|
get failedFlushes() {
|
|
432
789
|
return this.failedFlushCount;
|
|
433
790
|
}
|
|
434
|
-
/**
|
|
791
|
+
/**
|
|
792
|
+
* The most recent failure from a flush, if any: the raw fetch error (which on
|
|
793
|
+
* some runtimes embeds the request URL, so do not log it blindly) or an
|
|
794
|
+
* `Error` carrying only the HTTP status.
|
|
795
|
+
*/
|
|
435
796
|
get lastError() {
|
|
436
797
|
return this.lastFlushError;
|
|
437
798
|
}
|
|
438
799
|
write(entry) {
|
|
800
|
+
if (this.reporting) {
|
|
801
|
+
this.droppedEntries += 1;
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
439
804
|
this.batch.push(entry);
|
|
440
805
|
while (this.batch.length > this.maxBufferSize) {
|
|
441
806
|
this.batch.shift();
|
|
@@ -466,10 +831,15 @@ var BrowserRemoteTransport = class {
|
|
|
466
831
|
}
|
|
467
832
|
}
|
|
468
833
|
if (!res.ok) {
|
|
469
|
-
|
|
470
|
-
|
|
834
|
+
const failure = Object.assign(/* @__PURE__ */ new Error(`HTTP ${res.status}`), { status: res.status });
|
|
835
|
+
if (res.status >= 500 || res.status === 429) this.recordFailure(entries, failure);
|
|
836
|
+
else {
|
|
837
|
+
this.droppedEntries += entries.length;
|
|
838
|
+
this.recordFailure([], failure);
|
|
839
|
+
}
|
|
471
840
|
return;
|
|
472
841
|
}
|
|
842
|
+
this.reportRecovery();
|
|
473
843
|
}
|
|
474
844
|
}
|
|
475
845
|
send(body, keepalive) {
|
|
@@ -487,6 +857,34 @@ var BrowserRemoteTransport = class {
|
|
|
487
857
|
this.batch.unshift(...entries);
|
|
488
858
|
this.failedFlushCount += 1;
|
|
489
859
|
this.lastFlushError = error;
|
|
860
|
+
const now = Date.now();
|
|
861
|
+
const shouldReport = this.lastReportAt === void 0 || now - this.lastReportAt >= FAILURE_REPORT_INTERVAL_MS;
|
|
862
|
+
this.guarded(() => {
|
|
863
|
+
if (this.onError) try {
|
|
864
|
+
this.onError(error);
|
|
865
|
+
} catch {}
|
|
866
|
+
if (shouldReport && !this.silent) {
|
|
867
|
+
this.lastReportAt = now;
|
|
868
|
+
this.failureReported = true;
|
|
869
|
+
internalError(`BrowserRemoteTransport flush failed (${describeFailure(error, this.url)})`);
|
|
870
|
+
}
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
reportRecovery() {
|
|
874
|
+
if (!this.failureReported) return;
|
|
875
|
+
this.failureReported = false;
|
|
876
|
+
const now = Date.now();
|
|
877
|
+
if (this.lastRecoveryAt !== void 0 && now - this.lastRecoveryAt < FAILURE_REPORT_INTERVAL_MS) return;
|
|
878
|
+
this.lastRecoveryAt = now;
|
|
879
|
+
this.guarded(() => internalLog("BrowserRemoteTransport delivery recovered"));
|
|
880
|
+
}
|
|
881
|
+
guarded(fn) {
|
|
882
|
+
this.reporting = true;
|
|
883
|
+
try {
|
|
884
|
+
fn();
|
|
885
|
+
} finally {
|
|
886
|
+
this.reporting = false;
|
|
887
|
+
}
|
|
490
888
|
}
|
|
491
889
|
scheduleFlush() {
|
|
492
890
|
if (this.flushIntervalMs <= 0) return;
|
|
@@ -523,7 +921,10 @@ var BrowserLogger = class BrowserLogger {
|
|
|
523
921
|
context: config.context
|
|
524
922
|
};
|
|
525
923
|
if (config.silent) this.transports = [];
|
|
526
|
-
else
|
|
924
|
+
else {
|
|
925
|
+
const builtIn = new BrowserConsoleTransport({ json: this.config.json });
|
|
926
|
+
this.transports = [builtIn, ...config.transports ?? []];
|
|
927
|
+
}
|
|
527
928
|
}
|
|
528
929
|
verbose(message, payload) {
|
|
529
930
|
this.emit("verbose", message, payload);
|
|
@@ -611,7 +1012,6 @@ function createBrowserLogger(config) {
|
|
|
611
1012
|
* ```
|
|
612
1013
|
*/
|
|
613
1014
|
const browserLogger = new BrowserLogger({ appName: "App" });
|
|
614
|
-
|
|
615
|
-
//#endregion
|
|
616
1015
|
export { BrowserConsoleTransport, BrowserLogger, BrowserRemoteTransport, browserLogger, createBrowserLogger, createTypedLogger, defineLogSchema, disableOtelBridge, getActiveOtelContext, getOtelMetaFields, initOtelBridge };
|
|
1016
|
+
|
|
617
1017
|
//# sourceMappingURL=browser.mjs.map
|