@databricks/sql 1.13.0 → 1.15.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.
- package/README.md +12 -0
- package/dist/DBSQLClient.d.ts +107 -0
- package/dist/DBSQLClient.js +470 -0
- package/dist/DBSQLClient.js.map +1 -1
- package/dist/DBSQLOperation.d.ts +32 -1
- package/dist/DBSQLOperation.js +138 -29
- package/dist/DBSQLOperation.js.map +1 -1
- package/dist/DBSQLSession.d.ts +1 -0
- package/dist/DBSQLSession.js +43 -12
- package/dist/DBSQLSession.js.map +1 -1
- package/dist/connection/auth/DatabricksOAuth/OAuthManager.js +10 -6
- package/dist/connection/auth/DatabricksOAuth/OAuthManager.js.map +1 -1
- package/dist/contracts/IClientContext.d.ts +36 -0
- package/dist/contracts/IDBSQLClient.d.ts +90 -0
- package/dist/contracts/IDBSQLSession.d.ts +6 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/result/CloudFetchResultHandler.d.ts +8 -1
- package/dist/result/CloudFetchResultHandler.js +28 -2
- package/dist/result/CloudFetchResultHandler.js.map +1 -1
- package/dist/result/RowSetProvider.d.ts +8 -1
- package/dist/result/RowSetProvider.js +110 -1
- package/dist/result/RowSetProvider.js.map +1 -1
- package/dist/telemetry/CircuitBreaker.d.ts +73 -0
- package/dist/telemetry/CircuitBreaker.js +176 -0
- package/dist/telemetry/CircuitBreaker.js.map +1 -0
- package/dist/telemetry/DatabricksTelemetryExporter.d.ts +76 -0
- package/dist/telemetry/DatabricksTelemetryExporter.js +358 -0
- package/dist/telemetry/DatabricksTelemetryExporter.js.map +1 -0
- package/dist/telemetry/ExceptionClassifier.js +12 -0
- package/dist/telemetry/ExceptionClassifier.js.map +1 -1
- package/dist/telemetry/FeatureFlagCache.d.ts +61 -0
- package/dist/telemetry/FeatureFlagCache.js +214 -0
- package/dist/telemetry/FeatureFlagCache.js.map +1 -0
- package/dist/telemetry/MetricsAggregator.d.ts +110 -0
- package/dist/telemetry/MetricsAggregator.js +610 -0
- package/dist/telemetry/MetricsAggregator.js.map +1 -0
- package/dist/telemetry/TelemetryClient.d.ts +121 -0
- package/dist/telemetry/TelemetryClient.js +296 -0
- package/dist/telemetry/TelemetryClient.js.map +1 -0
- package/dist/telemetry/TelemetryClientProvider.d.ts +62 -0
- package/dist/telemetry/TelemetryClientProvider.js +154 -0
- package/dist/telemetry/TelemetryClientProvider.js.map +1 -0
- package/dist/telemetry/TelemetryEventEmitter.d.ts +119 -0
- package/dist/telemetry/TelemetryEventEmitter.js +151 -0
- package/dist/telemetry/TelemetryEventEmitter.js.map +1 -0
- package/dist/telemetry/telemetryTypeMappers.d.ts +25 -0
- package/dist/telemetry/telemetryTypeMappers.js +72 -0
- package/dist/telemetry/telemetryTypeMappers.js.map +1 -0
- package/dist/telemetry/telemetryUtils.d.ts +70 -0
- package/dist/telemetry/telemetryUtils.js +273 -0
- package/dist/telemetry/telemetryUtils.js.map +1 -0
- package/dist/telemetry/types.d.ts +70 -5
- package/dist/telemetry/types.js +19 -6
- package/dist/telemetry/types.js.map +1 -1
- package/dist/utils/agentDetector.d.ts +20 -0
- package/dist/utils/agentDetector.js +39 -0
- package/dist/utils/agentDetector.js.map +1 -0
- package/dist/utils/buildUserAgentString.js +7 -1
- package/dist/utils/buildUserAgentString.js.map +1 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/queryTags.d.ts +12 -0
- package/dist/utils/queryTags.js +35 -0
- package/dist/utils/queryTags.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Databricks Contributors
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.safeEmit = exports.sanitizeProcessName = exports.hasAuthorization = exports.normalizeHeaders = exports.redactSensitive = exports.buildTelemetryUrl = void 0;
|
|
19
|
+
const IDBSQLLogger_1 = require("../contracts/IDBSQLLogger");
|
|
20
|
+
/**
|
|
21
|
+
* Hosts we always refuse to send authenticated telemetry to. Targeted at the
|
|
22
|
+
* `/api/2.0/sql/telemetry-ext` exfil vector: an attacker-influenced `host`
|
|
23
|
+
* (env var, tampered config, etc.) must not be able to redirect the Bearer
|
|
24
|
+
* token to a loopback/IMDS/RFC1918 endpoint.
|
|
25
|
+
*/
|
|
26
|
+
const BLOCKED_HOST_PATTERNS = [
|
|
27
|
+
/^(?:127\.|0\.|10\.|169\.254\.|172\.(?:1[6-9]|2[0-9]|3[01])\.|192\.168\.)/,
|
|
28
|
+
/^(?:localhost|metadata\.google\.internal|metadata\.azure\.com)$/i,
|
|
29
|
+
/^\[?::1\]?$/,
|
|
30
|
+
/^\[?(?:fc|fd)[0-9a-f]{2}:/i,
|
|
31
|
+
/^\[?::ffff:(?:127|10|0|169\.254)\./i,
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
* Build an HTTPS telemetry URL from a host and a path.
|
|
35
|
+
*
|
|
36
|
+
* Refuses anything beyond a bare `host[:port]` so a compromised or mistyped
|
|
37
|
+
* host cannot redirect the authenticated request to an attacker-controlled
|
|
38
|
+
* endpoint. Defeated historical bypasses include:
|
|
39
|
+
* - protocol-relative prefix: `//attacker.com`
|
|
40
|
+
* - zero-width / ASCII whitespace in the host
|
|
41
|
+
* - userinfo (`user:pass@host`)
|
|
42
|
+
* - path/query/fragment
|
|
43
|
+
* - CRLF (header injection on some fetch backends)
|
|
44
|
+
* - loopback / link-local / RFC1918 / cloud-metadata addresses
|
|
45
|
+
*
|
|
46
|
+
* Returns `null` when the host fails any check; callers drop the batch.
|
|
47
|
+
*/
|
|
48
|
+
function buildTelemetryUrl(host, path) {
|
|
49
|
+
if (typeof host !== 'string' || host.length === 0) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
// Reject ASCII whitespace + common zero-width/BOM codepoints that JS `\s`
|
|
53
|
+
// does not cover but `new URL` silently strips.
|
|
54
|
+
if (/[\s\u200b-\u200f\u2060\ufeff]/.test(host)) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
const cleanHost = host.replace(/^https?:\/\//, '').replace(/\/+$/, '');
|
|
58
|
+
if (cleanHost.length === 0) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
// Reject anything that looks like userinfo / path / protocol-relative
|
|
62
|
+
// prefix before URL parsing. `new URL('https://' + '//x')` would otherwise
|
|
63
|
+
// normalise the doubled slash and accept `x` as the host.
|
|
64
|
+
if (/[/\\@]/.test(cleanHost)) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
let parsed;
|
|
68
|
+
try {
|
|
69
|
+
parsed = new URL(`https://${cleanHost}`);
|
|
70
|
+
}
|
|
71
|
+
catch (_a) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
if (parsed.pathname !== '/' ||
|
|
75
|
+
parsed.search !== '' ||
|
|
76
|
+
parsed.hash !== '' ||
|
|
77
|
+
parsed.username !== '' ||
|
|
78
|
+
parsed.password !== '') {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
// Defence in depth: ensure `new URL` did not silently rewrite the host we
|
|
82
|
+
// validated (e.g. by stripping a codepoint we missed above). `new URL`
|
|
83
|
+
// normalises away the default :443 for https, so compare using the
|
|
84
|
+
// port-stripped hostname instead of .host.
|
|
85
|
+
const expectedHost = cleanHost.toLowerCase().replace(/:443$/, '');
|
|
86
|
+
const actualHost = parsed.host.toLowerCase().replace(/:443$/, '');
|
|
87
|
+
if (actualHost !== expectedHost) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
if (BLOCKED_HOST_PATTERNS.some((r) => r.test(parsed.hostname))) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
return `https://${parsed.host}${path}`;
|
|
94
|
+
}
|
|
95
|
+
exports.buildTelemetryUrl = buildTelemetryUrl;
|
|
96
|
+
/**
|
|
97
|
+
* Prefixes the Databricks driver uses for internal token formats. Kept in
|
|
98
|
+
* sync with `lib/utils/buildUserAgentString.ts`'s `redactInternalToken`.
|
|
99
|
+
* Extending one list should extend the other.
|
|
100
|
+
*/
|
|
101
|
+
const DATABRICKS_TOKEN_PREFIXES = ['dkea', 'dskea', 'dapi', 'dsapi', 'dose'];
|
|
102
|
+
const SECRET_PATTERNS = [
|
|
103
|
+
// `Authorization: Bearer <token>` / `Bearer <token>` anywhere in a stack.
|
|
104
|
+
[/Bearer\s+[A-Za-z0-9._\-+/=]+/gi, 'Bearer <REDACTED>'],
|
|
105
|
+
// `Authorization: Basic <base64>`.
|
|
106
|
+
[/Basic\s+[A-Za-z0-9+/=]+/gi, 'Basic <REDACTED>'],
|
|
107
|
+
// URL userinfo: `https://user:pass@host/…`.
|
|
108
|
+
[/([a-z][a-z0-9+.-]*:\/\/)[^/\s:@]+:[^/\s@]+@/gi, '$1<REDACTED>@'],
|
|
109
|
+
// Databricks PATs / service-token prefixes without `Bearer`, e.g.
|
|
110
|
+
// `token is dapi0123…` — appears in error stacks that echo the raw value.
|
|
111
|
+
[new RegExp(`\\b(?:${DATABRICKS_TOKEN_PREFIXES.join('|')})[A-Za-z0-9]{8,}`, 'g'), '<REDACTED>'],
|
|
112
|
+
// JWTs (three base64url segments separated by dots).
|
|
113
|
+
[/\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/g, '<REDACTED_JWT>'],
|
|
114
|
+
// JSON-encoded secrets: `"client_secret":"..."`, `"access_token":"..."` etc.
|
|
115
|
+
[
|
|
116
|
+
/"(password|token|client_secret|refresh_token|access_token|id_token|secret|api[_-]?key|apikey)"\s*:\s*"[^"]*"/gi,
|
|
117
|
+
'"$1":"<REDACTED>"',
|
|
118
|
+
],
|
|
119
|
+
// Form-URL-encoded / key=value secrets.
|
|
120
|
+
[
|
|
121
|
+
/\b(token|password|client_secret|refresh_token|access_token|id_token|secret|api[_-]?key|apikey)=[^\s&"']+/gi,
|
|
122
|
+
'$1=<REDACTED>',
|
|
123
|
+
],
|
|
124
|
+
// OS-username-bearing filesystem paths in error stacks. `/home/<user>/`,
|
|
125
|
+
// `/Users/<user>/`, `C:\Users\<user>\`. Stack traces routinely echo the
|
|
126
|
+
// running user's home directory which leaks both the OS account name and
|
|
127
|
+
// application directory layout.
|
|
128
|
+
[/\/(?:home|Users)\/[^/\s)\]]+\//g, '/<HOMEDIR>/'],
|
|
129
|
+
[/[A-Za-z]:\\Users\\[^\\\s)\]]+\\/g, '<WINHOMEDIR>\\'],
|
|
130
|
+
// macOS temp/scratch directories (`/private/var/folders/<bucket>/<id>/...`)
|
|
131
|
+
// and `/var/folders/...`. The `<bucket>/<id>` segments are derived from the
|
|
132
|
+
// user identity so we redact through to the next path separator.
|
|
133
|
+
[/\/(?:private\/)?var\/folders\/[^/\s)\]]+\/[^/\s)\]]+\//g, '/<MACTMP>/'],
|
|
134
|
+
// Linux service / container layouts that routinely encode app or tenant
|
|
135
|
+
// names: `/var/lib/<service>/`, `/opt/<dir>/`, `/srv/<dir>/`, container
|
|
136
|
+
// `/app/<dir>/` (common on Lambda/k8s/Cloud Run). The replacement keeps
|
|
137
|
+
// the leading anchor so dashboards can still group by "var/lib vs opt".
|
|
138
|
+
[/\/var\/lib\/[^/\s)\]]+\//g, '/var/lib/<APP>/'],
|
|
139
|
+
[/\/opt\/[^/\s)\]]+\//g, '/opt/<APP>/'],
|
|
140
|
+
[/\/srv\/[^/\s)\]]+\//g, '/srv/<APP>/'],
|
|
141
|
+
[/\/app\/[^/\s)\]]+\//g, '/app/<APP>/'],
|
|
142
|
+
// Windows UNC paths `\\server\share\...` — the server and share names
|
|
143
|
+
// routinely leak internal hostnames or fileshare names.
|
|
144
|
+
[/\\\\[^\\/\s)\]]+\\[^\\/\s)\]]+\\/g, '\\\\<UNC>\\'],
|
|
145
|
+
];
|
|
146
|
+
/**
|
|
147
|
+
* Strips common secret shapes from a free-form error string and caps length.
|
|
148
|
+
* Applied before anything is shipped off-box. Redaction happens before
|
|
149
|
+
* truncation so a long stack cannot bury a secret past the cap; truncation
|
|
150
|
+
* then runs a second pass to catch anything that appeared only in the tail.
|
|
151
|
+
*/
|
|
152
|
+
function redactSensitive(value, maxLen = 2048) {
|
|
153
|
+
if (!value) {
|
|
154
|
+
return '';
|
|
155
|
+
}
|
|
156
|
+
let redacted = value;
|
|
157
|
+
for (const [pattern, replacement] of SECRET_PATTERNS) {
|
|
158
|
+
redacted = redacted.replace(pattern, replacement);
|
|
159
|
+
}
|
|
160
|
+
if (redacted.length > maxLen) {
|
|
161
|
+
redacted = `${redacted.slice(0, maxLen)}…[truncated]`;
|
|
162
|
+
for (const [pattern, replacement] of SECRET_PATTERNS) {
|
|
163
|
+
redacted = redacted.replace(pattern, replacement);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return redacted;
|
|
167
|
+
}
|
|
168
|
+
exports.redactSensitive = redactSensitive;
|
|
169
|
+
/**
|
|
170
|
+
* Normalises any `HeadersInit` shape (`Headers`, `[string,string][]`, or
|
|
171
|
+
* `Record<string, string>`) into a plain string dictionary. Non-string
|
|
172
|
+
* values are dropped. Shared by the exporter and FeatureFlagCache so there
|
|
173
|
+
* is one source of truth for auth-header handling.
|
|
174
|
+
*/
|
|
175
|
+
function normalizeHeaders(raw) {
|
|
176
|
+
if (!raw || typeof raw !== 'object') {
|
|
177
|
+
return {};
|
|
178
|
+
}
|
|
179
|
+
// Avoid importing node-fetch here; use structural check.
|
|
180
|
+
if (typeof raw.forEach === 'function' && !Array.isArray(raw)) {
|
|
181
|
+
const out = {};
|
|
182
|
+
raw.forEach((value, key) => {
|
|
183
|
+
if (typeof key === 'string' && typeof value === 'string') {
|
|
184
|
+
out[key] = value;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
if (Array.isArray(raw)) {
|
|
190
|
+
const out = {};
|
|
191
|
+
for (const entry of raw) {
|
|
192
|
+
if (Array.isArray(entry) && entry.length === 2 && typeof entry[0] === 'string' && typeof entry[1] === 'string') {
|
|
193
|
+
const [key, value] = entry;
|
|
194
|
+
out[key] = value;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return out;
|
|
198
|
+
}
|
|
199
|
+
const out = {};
|
|
200
|
+
for (const [k, v] of Object.entries(raw)) {
|
|
201
|
+
if (typeof v === 'string') {
|
|
202
|
+
out[k] = v;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return out;
|
|
206
|
+
}
|
|
207
|
+
exports.normalizeHeaders = normalizeHeaders;
|
|
208
|
+
/**
|
|
209
|
+
* Case-insensitive check for a non-empty `Authorization` header.
|
|
210
|
+
*/
|
|
211
|
+
function hasAuthorization(headers) {
|
|
212
|
+
for (const key of Object.keys(headers)) {
|
|
213
|
+
if (key.toLowerCase() === 'authorization' && headers[key]) {
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
exports.hasAuthorization = hasAuthorization;
|
|
220
|
+
/**
|
|
221
|
+
* Returns a safe `process_name` value: the basename of the first whitespace-
|
|
222
|
+
* delimited token, with trailing whitespace trimmed. This defeats both the
|
|
223
|
+
* absolute-path PII leak (`/home/<user>/app.js`) and the argv-leak shape
|
|
224
|
+
* (`node --db-password=X app.js`) that some producers pass in.
|
|
225
|
+
*/
|
|
226
|
+
function sanitizeProcessName(name) {
|
|
227
|
+
if (!name) {
|
|
228
|
+
return '';
|
|
229
|
+
}
|
|
230
|
+
const trimmed = name.trim();
|
|
231
|
+
if (trimmed.length === 0) {
|
|
232
|
+
return '';
|
|
233
|
+
}
|
|
234
|
+
// Drop argv tail: anything after the first whitespace — argv[0] shouldn't
|
|
235
|
+
// contain spaces, but producers sometimes pass `argv.join(' ')`.
|
|
236
|
+
const firstToken = trimmed.split(/\s/, 1)[0];
|
|
237
|
+
if (!firstToken) {
|
|
238
|
+
return '';
|
|
239
|
+
}
|
|
240
|
+
const lastSep = Math.max(firstToken.lastIndexOf('/'), firstToken.lastIndexOf('\\'));
|
|
241
|
+
return lastSep < 0 ? firstToken : firstToken.slice(lastSep + 1);
|
|
242
|
+
}
|
|
243
|
+
exports.sanitizeProcessName = sanitizeProcessName;
|
|
244
|
+
/**
|
|
245
|
+
* Run a telemetry emit at a call site, swallowing all exceptions and logging
|
|
246
|
+
* at debug level. Replaces the copy-pasted try/catch + getTelemetryEmitter?.()
|
|
247
|
+
* scaffold at every emit site. Telemetry must never break the driver.
|
|
248
|
+
*
|
|
249
|
+
* The type-only imports keep this helper free of runtime cycles:
|
|
250
|
+
* `IClientContext` imports `TelemetryEventEmitter` only as a type, and this
|
|
251
|
+
* helper does the same, so there's no value-level cycle. A typo like
|
|
252
|
+
* `emitter.emiitConnectionOpen(...)` is now a TS compile error instead of a
|
|
253
|
+
* swallowed runtime exception.
|
|
254
|
+
*/
|
|
255
|
+
function safeEmit(context, fn) {
|
|
256
|
+
var _a, _b;
|
|
257
|
+
try {
|
|
258
|
+
const emitter = (_a = context.getTelemetryEmitter) === null || _a === void 0 ? void 0 : _a.call(context);
|
|
259
|
+
if (emitter) {
|
|
260
|
+
fn(emitter);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
catch (err) {
|
|
264
|
+
try {
|
|
265
|
+
context.getLogger().log(IDBSQLLogger_1.LogLevel.debug, `Telemetry emit error: ${(_b = err === null || err === void 0 ? void 0 : err.message) !== null && _b !== void 0 ? _b : err}`);
|
|
266
|
+
}
|
|
267
|
+
catch (_c) {
|
|
268
|
+
// swallow logger errors too — telemetry never breaks the driver
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
exports.safeEmit = safeEmit;
|
|
273
|
+
//# sourceMappingURL=telemetryUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetryUtils.js","sourceRoot":"","sources":["../../lib/telemetry/telemetryUtils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAIH,4DAAqD;AAErD;;;;;GAKG;AACH,MAAM,qBAAqB,GAAa;IACtC,0EAA0E;IAC1E,kEAAkE;IAClE,aAAa;IACb,4BAA4B;IAC5B,qCAAqC;CACtC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,SAAgB,iBAAiB,CAAC,IAAY,EAAE,IAAY;IAC1D,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QACjD,OAAO,IAAI,CAAC;KACb;IAED,0EAA0E;IAC1E,gDAAgD;IAChD,IAAI,+BAA+B,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QAC9C,OAAO,IAAI,CAAC;KACb;IAED,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACvE,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;QAC1B,OAAO,IAAI,CAAC;KACb;IAED,sEAAsE;IACtE,2EAA2E;IAC3E,0DAA0D;IAC1D,IAAI,QAAQ,CAAC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AAC;IACpF,OAAO,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;AAClE,CAAC;AAhBD,kDAgBC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,QAAQ,CAAC,OAAuB,EAAE,EAA4C;;IAC5F,IAAI;QACF,MAAM,OAAO,GAAG,MAAA,OAAO,CAAC,mBAAmB,uDAAI,CAAC;QAChD,IAAI,OAAO,EAAE;YACX,EAAE,CAAC,OAAO,CAAC,CAAC;SACb;KACF;IAAC,OAAO,GAAQ,EAAE;QACjB,IAAI;YACF,OAAO,CAAC,SAAS,EAAE,CAAC,GAAG,CAAC,uBAAQ,CAAC,KAAK,EAAE,yBAAyB,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,mCAAI,GAAG,EAAE,CAAC,CAAC;SACzF;QAAC,WAAM;YACN,gEAAgE;SACjE;KACF;AACH,CAAC;AAbD,4BAaC"}
|
|
@@ -13,15 +13,20 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
/**
|
|
17
|
+
* Driver name constant for telemetry
|
|
18
|
+
*/
|
|
19
|
+
export declare const DRIVER_NAME = "nodejs-sql-driver";
|
|
16
20
|
/**
|
|
17
21
|
* Event types emitted by the telemetry system
|
|
18
22
|
*/
|
|
19
23
|
export declare enum TelemetryEventType {
|
|
20
24
|
CONNECTION_OPEN = "connection.open",
|
|
25
|
+
CONNECTION_CLOSE = "connection.close",
|
|
21
26
|
STATEMENT_START = "statement.start",
|
|
22
27
|
STATEMENT_COMPLETE = "statement.complete",
|
|
23
28
|
CLOUDFETCH_CHUNK = "cloudfetch.chunk",
|
|
24
|
-
ERROR = "error"
|
|
29
|
+
ERROR = "telemetry.error"
|
|
25
30
|
}
|
|
26
31
|
/**
|
|
27
32
|
* Configuration for telemetry components
|
|
@@ -33,25 +38,46 @@ export interface TelemetryConfiguration {
|
|
|
33
38
|
batchSize?: number;
|
|
34
39
|
/** Interval in milliseconds to flush metrics */
|
|
35
40
|
flushIntervalMs?: number;
|
|
36
|
-
/** Maximum retry attempts for export */
|
|
41
|
+
/** Maximum retry attempts for export (attempts *after* the initial call) */
|
|
37
42
|
maxRetries?: number;
|
|
43
|
+
/** Minimum backoff delay in ms for retry backoff */
|
|
44
|
+
backoffBaseMs?: number;
|
|
45
|
+
/** Maximum backoff delay in ms (includes jitter) */
|
|
46
|
+
backoffMaxMs?: number;
|
|
47
|
+
/** Upper bound of added jitter in ms */
|
|
48
|
+
backoffJitterMs?: number;
|
|
38
49
|
/** Whether to use authenticated export endpoint */
|
|
39
50
|
authenticatedExport?: boolean;
|
|
40
51
|
/** Circuit breaker failure threshold */
|
|
41
52
|
circuitBreakerThreshold?: number;
|
|
42
53
|
/** Circuit breaker timeout in milliseconds */
|
|
43
54
|
circuitBreakerTimeout?: number;
|
|
55
|
+
/** Maximum number of pending metrics buffered before dropping oldest */
|
|
56
|
+
maxPendingMetrics?: number;
|
|
57
|
+
/** Maximum number of error events buffered per statement before dropping oldest */
|
|
58
|
+
maxErrorsPerStatement?: number;
|
|
59
|
+
/** TTL in ms after which abandoned statement aggregations are evicted */
|
|
60
|
+
statementTtlMs?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Maximum wall-clock time `close()` will wait for the final flush HTTP POST
|
|
63
|
+
* before abandoning it and returning. Bounds shutdown latency so callers
|
|
64
|
+
* doing `await client.close(); process.exit(0)` are not held up by a
|
|
65
|
+
* misbehaving telemetry endpoint.
|
|
66
|
+
*/
|
|
67
|
+
closeTimeoutMs?: number;
|
|
68
|
+
/** Hard cap on per-statement aggregation map size; oldest evicted on overflow. */
|
|
69
|
+
maxStatementMetrics?: number;
|
|
44
70
|
}
|
|
45
71
|
/**
|
|
46
72
|
* Default telemetry configuration values
|
|
47
73
|
*/
|
|
48
|
-
export declare const DEFAULT_TELEMETRY_CONFIG: Required<TelemetryConfiguration
|
|
74
|
+
export declare const DEFAULT_TELEMETRY_CONFIG: Readonly<Required<TelemetryConfiguration>>;
|
|
49
75
|
/**
|
|
50
76
|
* Runtime telemetry event emitted by the driver
|
|
51
77
|
*/
|
|
52
78
|
export interface TelemetryEvent {
|
|
53
79
|
/** Type of the event */
|
|
54
|
-
eventType: TelemetryEventType
|
|
80
|
+
eventType: TelemetryEventType;
|
|
55
81
|
/** Timestamp when the event occurred (milliseconds since epoch) */
|
|
56
82
|
timestamp: number;
|
|
57
83
|
/** Session ID for correlation */
|
|
@@ -84,6 +110,8 @@ export interface TelemetryEvent {
|
|
|
84
110
|
errorName?: string;
|
|
85
111
|
/** Error message */
|
|
86
112
|
errorMessage?: string;
|
|
113
|
+
/** Stack trace, captured at emission site; redacted before export */
|
|
114
|
+
errorStack?: string;
|
|
87
115
|
/** Whether the error is terminal (non-retryable) */
|
|
88
116
|
isTerminal?: boolean;
|
|
89
117
|
}
|
|
@@ -101,22 +129,34 @@ export interface TelemetryMetric {
|
|
|
101
129
|
statementId?: string;
|
|
102
130
|
/** Workspace ID */
|
|
103
131
|
workspaceId?: string;
|
|
104
|
-
/** Driver configuration (
|
|
132
|
+
/** Driver configuration (included in all metrics for context) */
|
|
105
133
|
driverConfig?: DriverConfiguration;
|
|
106
134
|
/** Execution latency in milliseconds */
|
|
107
135
|
latencyMs?: number;
|
|
136
|
+
/** Type of operation (SELECT, INSERT, etc.) */
|
|
137
|
+
operationType?: string;
|
|
108
138
|
/** Result format (inline, cloudfetch, arrow) */
|
|
109
139
|
resultFormat?: string;
|
|
110
140
|
/** Number of result chunks */
|
|
111
141
|
chunkCount?: number;
|
|
142
|
+
/** Latency of the first chunk fetch in milliseconds */
|
|
143
|
+
chunkInitialLatencyMs?: number;
|
|
144
|
+
/** Latency of the slowest chunk fetch in milliseconds */
|
|
145
|
+
chunkSlowestLatencyMs?: number;
|
|
146
|
+
/** Sum of all chunk fetch latencies in milliseconds */
|
|
147
|
+
chunkSumLatencyMs?: number;
|
|
112
148
|
/** Total bytes downloaded */
|
|
113
149
|
bytesDownloaded?: number;
|
|
114
150
|
/** Number of poll operations */
|
|
115
151
|
pollCount?: number;
|
|
152
|
+
/** Whether compression was used */
|
|
153
|
+
compressed?: boolean;
|
|
116
154
|
/** Error name/type */
|
|
117
155
|
errorName?: string;
|
|
118
156
|
/** Error message */
|
|
119
157
|
errorMessage?: string;
|
|
158
|
+
/** Stack trace, captured at emission site; redacted before export */
|
|
159
|
+
errorStack?: string;
|
|
120
160
|
}
|
|
121
161
|
/**
|
|
122
162
|
* Driver configuration metadata collected once per connection
|
|
@@ -132,6 +172,21 @@ export interface DriverConfiguration {
|
|
|
132
172
|
platform: string;
|
|
133
173
|
/** OS version */
|
|
134
174
|
osVersion: string;
|
|
175
|
+
/** OS architecture (x64, arm64, etc.) */
|
|
176
|
+
osArch: string;
|
|
177
|
+
/** Runtime vendor (Node.js Foundation) */
|
|
178
|
+
runtimeVendor: string;
|
|
179
|
+
/** Locale name (e.g., en_US) */
|
|
180
|
+
localeName: string;
|
|
181
|
+
/** Character set encoding (e.g., UTF-8) */
|
|
182
|
+
charSetEncoding: string;
|
|
183
|
+
/**
|
|
184
|
+
* Process name. Producers MUST pass only a basename (no absolute path) —
|
|
185
|
+
* `sanitizeProcessName()` is applied at export time as a defence in depth.
|
|
186
|
+
*/
|
|
187
|
+
processName: string;
|
|
188
|
+
/** Authentication type (pat, external-browser, oauth-m2m, custom) */
|
|
189
|
+
authType: string;
|
|
135
190
|
/** Whether CloudFetch is enabled */
|
|
136
191
|
cloudFetchEnabled: boolean;
|
|
137
192
|
/** Whether LZ4 compression is enabled */
|
|
@@ -146,6 +201,10 @@ export interface DriverConfiguration {
|
|
|
146
201
|
retryMaxAttempts: number;
|
|
147
202
|
/** Number of concurrent CloudFetch downloads */
|
|
148
203
|
cloudFetchConcurrentDownloads: number;
|
|
204
|
+
/** HTTP path for API calls */
|
|
205
|
+
httpPath?: string;
|
|
206
|
+
/** Whether metric view metadata is enabled */
|
|
207
|
+
enableMetricViewMetadata?: boolean;
|
|
149
208
|
}
|
|
150
209
|
/**
|
|
151
210
|
* Per-statement metrics aggregated from multiple events
|
|
@@ -169,6 +228,12 @@ export interface StatementMetrics {
|
|
|
169
228
|
resultFormat?: string;
|
|
170
229
|
/** Number of CloudFetch chunks downloaded */
|
|
171
230
|
chunkCount: number;
|
|
231
|
+
/** Latency of the first chunk fetch in milliseconds */
|
|
232
|
+
chunkInitialLatencyMs?: number;
|
|
233
|
+
/** Latency of the slowest chunk fetch in milliseconds */
|
|
234
|
+
chunkSlowestLatencyMs?: number;
|
|
235
|
+
/** Sum of all chunk fetch latencies in milliseconds */
|
|
236
|
+
chunkSumLatencyMs?: number;
|
|
172
237
|
/** Total bytes downloaded */
|
|
173
238
|
totalBytesDownloaded: number;
|
|
174
239
|
/** Whether compression was used */
|
package/dist/telemetry/types.js
CHANGED
|
@@ -15,28 +15,41 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.DEFAULT_TELEMETRY_CONFIG = exports.TelemetryEventType = void 0;
|
|
18
|
+
exports.DEFAULT_TELEMETRY_CONFIG = exports.TelemetryEventType = exports.DRIVER_NAME = void 0;
|
|
19
|
+
/**
|
|
20
|
+
* Driver name constant for telemetry
|
|
21
|
+
*/
|
|
22
|
+
exports.DRIVER_NAME = 'nodejs-sql-driver';
|
|
19
23
|
/**
|
|
20
24
|
* Event types emitted by the telemetry system
|
|
21
25
|
*/
|
|
22
26
|
var TelemetryEventType;
|
|
23
27
|
(function (TelemetryEventType) {
|
|
24
28
|
TelemetryEventType["CONNECTION_OPEN"] = "connection.open";
|
|
29
|
+
TelemetryEventType["CONNECTION_CLOSE"] = "connection.close";
|
|
25
30
|
TelemetryEventType["STATEMENT_START"] = "statement.start";
|
|
26
31
|
TelemetryEventType["STATEMENT_COMPLETE"] = "statement.complete";
|
|
27
32
|
TelemetryEventType["CLOUDFETCH_CHUNK"] = "cloudfetch.chunk";
|
|
28
|
-
TelemetryEventType["ERROR"] = "error";
|
|
33
|
+
TelemetryEventType["ERROR"] = "telemetry.error";
|
|
29
34
|
})(TelemetryEventType = exports.TelemetryEventType || (exports.TelemetryEventType = {}));
|
|
30
35
|
/**
|
|
31
36
|
* Default telemetry configuration values
|
|
32
37
|
*/
|
|
33
|
-
exports.DEFAULT_TELEMETRY_CONFIG = {
|
|
34
|
-
enabled:
|
|
38
|
+
exports.DEFAULT_TELEMETRY_CONFIG = Object.freeze({
|
|
39
|
+
enabled: true,
|
|
35
40
|
batchSize: 100,
|
|
36
41
|
flushIntervalMs: 5000,
|
|
37
42
|
maxRetries: 3,
|
|
43
|
+
backoffBaseMs: 100,
|
|
44
|
+
backoffMaxMs: 1000,
|
|
45
|
+
backoffJitterMs: 100,
|
|
38
46
|
authenticatedExport: true,
|
|
39
47
|
circuitBreakerThreshold: 5,
|
|
40
|
-
circuitBreakerTimeout: 60000,
|
|
41
|
-
|
|
48
|
+
circuitBreakerTimeout: 60000,
|
|
49
|
+
maxPendingMetrics: 500,
|
|
50
|
+
maxErrorsPerStatement: 50,
|
|
51
|
+
statementTtlMs: 60 * 60 * 1000,
|
|
52
|
+
closeTimeoutMs: 2000,
|
|
53
|
+
maxStatementMetrics: 5000, // hard cap for the per-statement aggregation map
|
|
54
|
+
});
|
|
42
55
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../lib/telemetry/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH;;GAEG;AACH,IAAY,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../lib/telemetry/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH;;GAEG;AACU,QAAA,WAAW,GAAG,mBAAmB,CAAC;AAE/C;;GAEG;AACH,IAAY,kBAOX;AAPD,WAAY,kBAAkB;IAC5B,yDAAmC,CAAA;IACnC,2DAAqC,CAAA;IACrC,yDAAmC,CAAA;IACnC,+DAAyC,CAAA;IACzC,2DAAqC,CAAA;IACrC,+CAAyB,CAAA;AAC3B,CAAC,EAPW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAO7B;AAyDD;;GAEG;AACU,QAAA,wBAAwB,GAA+C,MAAM,CAAC,MAAM,CAAC;IAChG,OAAO,EAAE,IAAI;IACb,SAAS,EAAE,GAAG;IACd,eAAe,EAAE,IAAI;IACrB,UAAU,EAAE,CAAC;IACb,aAAa,EAAE,GAAG;IAClB,YAAY,EAAE,IAAI;IAClB,eAAe,EAAE,GAAG;IACpB,mBAAmB,EAAE,IAAI;IACzB,uBAAuB,EAAE,CAAC;IAC1B,qBAAqB,EAAE,KAAK;IAC5B,iBAAiB,EAAE,GAAG;IACtB,qBAAqB,EAAE,EAAE;IACzB,cAAc,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;IAC9B,cAAc,EAAE,IAAI;IACpB,mBAAmB,EAAE,IAAI,EAAE,iDAAiD;CAC7E,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects whether the Node.js SQL driver is being invoked by an AI coding agent
|
|
3
|
+
* by checking for well-known environment variables that agents set in their
|
|
4
|
+
* spawned shell processes.
|
|
5
|
+
*
|
|
6
|
+
* Detection only succeeds when exactly one agent environment variable is present,
|
|
7
|
+
* to avoid ambiguous attribution when multiple agent environments overlap.
|
|
8
|
+
*
|
|
9
|
+
* Adding a new agent requires only a new entry in `knownAgents`.
|
|
10
|
+
*
|
|
11
|
+
* References for each environment variable:
|
|
12
|
+
* - ANTIGRAVITY_AGENT: Closed source. Google Antigravity sets this variable.
|
|
13
|
+
* - CLAUDECODE: https://github.com/anthropics/claude-code (sets CLAUDECODE=1)
|
|
14
|
+
* - CLINE_ACTIVE: https://github.com/cline/cline (shipped in v3.24.0)
|
|
15
|
+
* - CODEX_CI: https://github.com/openai/codex (part of UNIFIED_EXEC_ENV array in codex-rs)
|
|
16
|
+
* - CURSOR_AGENT: Closed source. Referenced in a gist by johnlindquist.
|
|
17
|
+
* - GEMINI_CLI: https://google-gemini.github.io/gemini-cli/docs/tools/shell.html (sets GEMINI_CLI=1)
|
|
18
|
+
* - OPENCODE: https://github.com/opencode-ai/opencode (sets OPENCODE=1)
|
|
19
|
+
*/
|
|
20
|
+
export default function detectAgent(env?: Record<string, string | undefined>): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Detects whether the Node.js SQL driver is being invoked by an AI coding agent
|
|
4
|
+
* by checking for well-known environment variables that agents set in their
|
|
5
|
+
* spawned shell processes.
|
|
6
|
+
*
|
|
7
|
+
* Detection only succeeds when exactly one agent environment variable is present,
|
|
8
|
+
* to avoid ambiguous attribution when multiple agent environments overlap.
|
|
9
|
+
*
|
|
10
|
+
* Adding a new agent requires only a new entry in `knownAgents`.
|
|
11
|
+
*
|
|
12
|
+
* References for each environment variable:
|
|
13
|
+
* - ANTIGRAVITY_AGENT: Closed source. Google Antigravity sets this variable.
|
|
14
|
+
* - CLAUDECODE: https://github.com/anthropics/claude-code (sets CLAUDECODE=1)
|
|
15
|
+
* - CLINE_ACTIVE: https://github.com/cline/cline (shipped in v3.24.0)
|
|
16
|
+
* - CODEX_CI: https://github.com/openai/codex (part of UNIFIED_EXEC_ENV array in codex-rs)
|
|
17
|
+
* - CURSOR_AGENT: Closed source. Referenced in a gist by johnlindquist.
|
|
18
|
+
* - GEMINI_CLI: https://google-gemini.github.io/gemini-cli/docs/tools/shell.html (sets GEMINI_CLI=1)
|
|
19
|
+
* - OPENCODE: https://github.com/opencode-ai/opencode (sets OPENCODE=1)
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
const knownAgents = [
|
|
23
|
+
{ envVar: 'ANTIGRAVITY_AGENT', product: 'antigravity' },
|
|
24
|
+
{ envVar: 'CLAUDECODE', product: 'claude-code' },
|
|
25
|
+
{ envVar: 'CLINE_ACTIVE', product: 'cline' },
|
|
26
|
+
{ envVar: 'CODEX_CI', product: 'codex' },
|
|
27
|
+
{ envVar: 'CURSOR_AGENT', product: 'cursor' },
|
|
28
|
+
{ envVar: 'GEMINI_CLI', product: 'gemini-cli' },
|
|
29
|
+
{ envVar: 'OPENCODE', product: 'opencode' },
|
|
30
|
+
];
|
|
31
|
+
function detectAgent(env = process.env) {
|
|
32
|
+
const detected = knownAgents.filter((a) => env[a.envVar]).map((a) => a.product);
|
|
33
|
+
if (detected.length === 1) {
|
|
34
|
+
return detected[0];
|
|
35
|
+
}
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
exports.default = detectAgent;
|
|
39
|
+
//# sourceMappingURL=agentDetector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentDetector.js","sourceRoot":"","sources":["../../lib/utils/agentDetector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;AAEH,MAAM,WAAW,GAA+C;IAC9D,EAAE,MAAM,EAAE,mBAAmB,EAAE,OAAO,EAAE,aAAa,EAAE;IACvD,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE;IAChD,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,EAAE;IAC5C,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE;IACxC,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE;IAC7C,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE;IAC/C,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE;CAC5C,CAAC;AAEF,SAAwB,WAAW,CAAC,MAA0C,OAAO,CAAC,GAAG;IACvF,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAEhF,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;QACzB,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;KACpB;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAPD,8BAOC"}
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const os_1 = __importDefault(require("os"));
|
|
7
7
|
const version_1 = __importDefault(require("../version"));
|
|
8
|
+
const agentDetector_1 = __importDefault(require("./agentDetector"));
|
|
8
9
|
const productName = 'NodejsDatabricksSqlConnector';
|
|
9
10
|
function getNodeVersion() {
|
|
10
11
|
return `Node.js ${process.versions.node}`;
|
|
@@ -26,7 +27,12 @@ function buildUserAgentString(userAgentEntry) {
|
|
|
26
27
|
userAgentEntry = redactInternalToken(userAgentEntry);
|
|
27
28
|
}
|
|
28
29
|
const extra = [userAgentEntry, getNodeVersion(), getOperatingSystemVersion()].filter(Boolean);
|
|
29
|
-
|
|
30
|
+
let ua = `${productName}/${version_1.default} (${extra.join('; ')})`;
|
|
31
|
+
const agentProduct = (0, agentDetector_1.default)();
|
|
32
|
+
if (agentProduct) {
|
|
33
|
+
ua += ` agent/${agentProduct}`;
|
|
34
|
+
}
|
|
35
|
+
return ua;
|
|
30
36
|
}
|
|
31
37
|
exports.default = buildUserAgentString;
|
|
32
38
|
//# sourceMappingURL=buildUserAgentString.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildUserAgentString.js","sourceRoot":"","sources":["../../lib/utils/buildUserAgentString.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,yDAAwC;
|
|
1
|
+
{"version":3,"file":"buildUserAgentString.js","sourceRoot":"","sources":["../../lib/utils/buildUserAgentString.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,yDAAwC;AACxC,oEAA0C;AAE1C,MAAM,WAAW,GAAG,8BAA8B,CAAC;AAEnD,SAAS,cAAc;IACrB,OAAO,WAAW,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;AAC5C,CAAC;AAED,SAAS,yBAAyB;IAChC,OAAO,GAAG,YAAE,CAAC,IAAI,EAAE,IAAI,YAAE,CAAC,OAAO,EAAE,EAAE,CAAC;AACxC,CAAC;AAED,SAAS,mBAAmB,CAAC,cAAsB;IACjD,MAAM,qBAAqB,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACzE,KAAK,MAAM,MAAM,IAAI,qBAAqB,EAAE;QAC1C,IAAI,cAAc,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;YACrC,OAAO,YAAY,CAAC;SACrB;KACF;IACD,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,SAAwB,oBAAoB,CAAC,cAAuB;IAClE,IAAI,cAAc,EAAE;QAClB,cAAc,GAAG,mBAAmB,CAAC,cAAc,CAAC,CAAC;KACtD;IAED,MAAM,KAAK,GAAG,CAAC,cAAc,EAAE,cAAc,EAAE,EAAE,yBAAyB,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC9F,IAAI,EAAE,GAAG,GAAG,WAAW,IAAI,iBAAc,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;IAElE,MAAM,YAAY,GAAG,IAAA,uBAAW,GAAE,CAAC;IACnC,IAAI,YAAY,EAAE;QAChB,EAAE,IAAI,UAAU,YAAY,EAAE,CAAC;KAChC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAdD,uCAcC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ import buildUserAgentString from './buildUserAgentString';
|
|
|
3
3
|
import formatProgress, { ProgressUpdateTransformer } from './formatProgress';
|
|
4
4
|
import LZ4 from './lz4';
|
|
5
5
|
import * as ProtocolVersion from './protocolVersion';
|
|
6
|
-
|
|
6
|
+
import serializeQueryTags from './queryTags';
|
|
7
|
+
export { definedOrError, buildUserAgentString, formatProgress, ProgressUpdateTransformer, LZ4, ProtocolVersion, serializeQueryTags, };
|
package/dist/utils/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.ProtocolVersion = exports.LZ4 = exports.ProgressUpdateTransformer = exports.formatProgress = exports.buildUserAgentString = exports.definedOrError = void 0;
|
|
29
|
+
exports.serializeQueryTags = exports.ProtocolVersion = exports.LZ4 = exports.ProgressUpdateTransformer = exports.formatProgress = exports.buildUserAgentString = exports.definedOrError = void 0;
|
|
30
30
|
const definedOrError_1 = __importDefault(require("./definedOrError"));
|
|
31
31
|
exports.definedOrError = definedOrError_1.default;
|
|
32
32
|
const buildUserAgentString_1 = __importDefault(require("./buildUserAgentString"));
|
|
@@ -38,4 +38,6 @@ const lz4_1 = __importDefault(require("./lz4"));
|
|
|
38
38
|
exports.LZ4 = lz4_1.default;
|
|
39
39
|
const ProtocolVersion = __importStar(require("./protocolVersion"));
|
|
40
40
|
exports.ProtocolVersion = ProtocolVersion;
|
|
41
|
+
const queryTags_1 = __importDefault(require("./queryTags"));
|
|
42
|
+
exports.serializeQueryTags = queryTags_1.default;
|
|
41
43
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sEAA8C;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sEAA8C;AAQ5C,yBARK,wBAAc,CAQL;AAPhB,kFAA0D;AAQxD,+BARK,8BAAoB,CAQL;AAPtB,mEAA6E;AAQ3E,yBARK,wBAAc,CAQL;AACd,0GATuB,0CAAyB,OASvB;AAR3B,gDAAwB;AAStB,cATK,aAAG,CASL;AARL,mEAAqD;AASnD,0CAAe;AARjB,4DAA6C;AAS3C,6BATK,mBAAkB,CASL"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serializes a query tags dictionary into a string for use in confOverlay.
|
|
3
|
+
*
|
|
4
|
+
* Format: comma-separated key:value pairs, e.g. "key1:value1,key2:value2"
|
|
5
|
+
* - If a value is null or undefined, the key is included without a colon or value
|
|
6
|
+
* - Backslashes in keys are escaped; other special characters in keys are not escaped
|
|
7
|
+
* - Special characters (backslash, colon, comma) in values are backslash-escaped
|
|
8
|
+
*
|
|
9
|
+
* @param queryTags - dictionary of query tag key-value pairs
|
|
10
|
+
* @returns serialized string, or undefined if input is empty/null/undefined
|
|
11
|
+
*/
|
|
12
|
+
export default function serializeQueryTags(queryTags: Record<string, string | null | undefined> | null | undefined): string | undefined;
|