tina4-nodejs 3.13.165 → 3.13.166

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.
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Connection URL credentials: the ONE redaction rule, shared by every path
3
+ * that can put a connection string in front of a human (GHSA-h2mr-m3v3-cq8c).
4
+ * Its parsing half - the ONE userinfo splitter every parser uses - is the
5
+ * sibling connectionUrl.ts, which takes its port-versus-password test from
6
+ * here so the two halves cannot drift.
7
+ *
8
+ * IMPORTS NOTHING, on purpose. @tina4/orm imports it (databaseUrl.ts) and so
9
+ * does @tina4/core (the websocket backplane, the boot log, the dev admin) - a
10
+ * leaf module is the only place both can reach without a cycle.
11
+ *
12
+ * THE RULE
13
+ * - The authority starts after `scheme://`, `scheme:/` or `scheme//`.
14
+ * - Userinfo ends at the LAST `@` on the line; the password starts at the
15
+ * first `:` after the authority start. A `/`, `?` or `#` before that `:`
16
+ * means the text is a path, not a password.
17
+ * - With no `@`, a non-numeric "port" is the password: it is masked to the end
18
+ * of the line, keeping a trailing `?key=value` query.
19
+ * - Parsers refuse a URL without `scheme://`, or whose `@` count differs from
20
+ * what the parser took as userinfo, with a GENERIC message that never
21
+ * echoes the value and never chains an error that does.
22
+ * - Scheme, user and host stay visible, so the line is still useful.
23
+ *
24
+ * Why this replaced the old rules: they cut the authority at the first `/`, `?`
25
+ * or `#`, or split userinfo at the first `@`, so `postgres://u:Pq1/Rs2@h/db`,
26
+ * `postgres:/u:pw@h/db`, `postgres://u:pw` and `postgres://u:pw@h:notaport/db`
27
+ * all printed the password - in redacted log lines, in "invalid URL" errors
28
+ * that named `u:Pq1` as the host, and in driver errors downstream.
29
+ *
30
+ * KNOWN LIMITS (unmaskable by any rule):
31
+ * - A host-less URL whose password is all digits (`postgres://u:123/x`) is a
32
+ * valid URL with port 123, so the digits are shown.
33
+ * - A host-less URL whose password holds an unencoded `@`
34
+ * (`postgres://u:Pq1@Rs2`) is a valid URL whose HOST is `Rs2`; the tail
35
+ * after the `@` is shown as the host.
36
+ * Over-redaction is accepted instead: a second `@` later on the same line
37
+ * (`... failed for admin@corp`) masks up to it, hiding a host, never showing a
38
+ * password.
39
+ */
40
+ /** The single mask. One spelling, so grepping for it finds every redaction. */
41
+ export declare const REDACTED = "***";
42
+ /**
43
+ * True when the text after a host-less `x:digits` cannot be what follows a
44
+ * port - a `#fragment`, or a `?query` that is not `key=value` pairs - so the
45
+ * digits are the start of a password (`postgres://u:12?Pq1Rs2`).
46
+ */
47
+ export declare function digitLedPassword(afterPort: string): boolean;
48
+ /**
49
+ * Remove every password from an arbitrary connection string or message.
50
+ *
51
+ * THE single redaction primitive. It works on RAW text - valid or malformed, a
52
+ * URL, an ODBC DSN, or an error message that embeds either - so error paths can
53
+ * use it too. `postgres://u:pw@host/db` becomes `postgres://u:***@host/db`.
54
+ */
55
+ export declare function redactCredentials(raw: string): string;
56
+ /**
57
+ * Like redactCredentials(), but drops the whole userinfo (`user:pass@`) rather
58
+ * than masking the password - for the boot log, which names the database
59
+ * target and nothing about who connects to it.
60
+ */
61
+ export declare function stripCredentials(raw: string): string;
@@ -12,22 +12,10 @@
12
12
  * key, byte-identical in all four.
13
13
  */
14
14
  import { inspect } from "node:util";
15
+ import { redactCredentials } from "../../core/src/urlRedaction.js";
15
16
  /** The canonical engine names. Aliases resolve to these ONCE, at parse. */
16
17
  export type DatabaseEngine = "sqlite" | "postgres" | "mysql" | "mssql" | "firebird" | "mongodb" | "odbc";
17
- /**
18
- * Remove every credential from an arbitrary connection string.
19
- *
20
- * THE single redaction primitive. It works on a RAW string - valid or
21
- * malformed, a URL or an ODBC DSN - so the error paths can use it too, and it
22
- * is what `toSafeString()` calls for the odbc form rather than hand-rolling a
23
- * second, weaker rule.
24
- *
25
- * It cannot be complete on a string with no recognisable credential structure
26
- * (`notaurl-with-hunter2` has nothing to key off), which is exactly why the
27
- * invalid-URL error reports the scheme and host instead of any form of the
28
- * input. Redaction is for strings we can parse enough to redact.
29
- */
30
- export declare function redactCredentials(raw: string): string;
18
+ export { redactCredentials };
31
19
  /**
32
20
  * DISPLAY REDACTS, FIDELITY DOES NOT. JSON.stringify, util.inspect, String() and
33
21
  * toSafeString() replace the password with the redaction marker, so a log line, a
@@ -109,17 +97,28 @@ export declare class DatabaseUrl {
109
97
  */
110
98
  private static parseSqlite;
111
99
  /**
112
- * mssql and firebird: the URL class does not know these schemes, so they are
113
- * matched directly.
100
+ * mssql and firebird: `host[:port]/database`, split by the shared splitter.
114
101
  *
115
- * The captured path keeps its own leading slash when the URL had two, which is
102
+ * These used to be one regex each that split userinfo at the FIRST `@` and
103
+ * the password at the first `/`, so `mssql://u:p@ss@h/db` connected to a host
104
+ * named `ss@h` and printed it in the driver's error.
105
+ *
106
+ * The database keeps its own leading slash when the URL had two, which is
116
107
  * how the documented absolute Firebird form survives. The old code did
117
108
  * `"/" + match[5]`, ADDING a slash - so an absolute path came back with two
118
109
  * and a relative path was silently made absolute. Verified against live
119
110
  * Firebird 5.0.4: the driver takes one or two leading slashes and rejects a
120
111
  * relative path outright.
121
112
  */
122
- private static parseRegexForm;
123
- /** postgres / mysql / mongodb, via the URL class. */
113
+ private static parsePathForm;
114
+ /**
115
+ * postgres / mysql / mongodb.
116
+ *
117
+ * Userinfo comes from the shared splitter (the last-`@` rule), never from the
118
+ * URL class: `new URL()` cuts a password at its first `/`, `?` or `#`, reads
119
+ * `postgres:/u:pw@h` as a path, and throws a TypeError whose `.input` is the
120
+ * whole URL. The class only sees a credential-free rebuild, for the host,
121
+ * port and path it already normalises the way every corpus row expects.
122
+ */
124
123
  private static parseStandard;
125
124
  }
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Graph connection URL parser — the DatabaseUrl sibling for graph engines.
3
+ *
4
+ * Parse a graph connection URL into its parts, the same way DatabaseUrl does for
5
+ * SQL. `engine` is the CANONICAL name the factory selects an adapter by; a scheme
6
+ * alias (bolt/neo4j/memgraph all speak Bolt/Cypher and share ONE adapter) resolves
7
+ * to its engine here. See tina4-documentation/plan/v3/features/139-graph-databases.md.
8
+ */
9
+ import { inspect } from "node:util";
1
10
  /** The canonical graph engine names. */
2
11
  export type GraphEngine = "ultipa" | "bolt" | "arango";
3
12
  /** A parsed graph URL: engine, host, port, graph, credentials, params. */
@@ -14,6 +23,15 @@ export declare class GraphUrl {
14
23
  readonly params: Record<string, string>;
15
24
  readonly useTls: boolean;
16
25
  constructor(url: string);
26
+ /**
27
+ * What `JSON.stringify` emits, directly or as one field of a logged object.
28
+ * `password` and `raw` both hold the secret, so the default dump printed it
29
+ * twice (GHSA-h2mr-m3v3-cq8c). DatabaseUrl guards the same way; PHP has
30
+ * __debugInfo/jsonSerialize and Ruby a redacted #inspect.
31
+ */
32
+ toJSON(): Record<string, unknown>;
33
+ /** What `console.log(url)` / `util.inspect(url)` print. */
34
+ [inspect.custom](): string;
17
35
  /** host:port/graph — for messages, never carrying credentials. */
18
36
  getDsn(): string;
19
37
  static fromEnv(envKey?: string): GraphUrl | null;