@databricks/sql 1.13.0 → 1.14.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.
Files changed (57) hide show
  1. package/dist/DBSQLClient.d.ts +8 -0
  2. package/dist/DBSQLClient.js +25 -0
  3. package/dist/DBSQLClient.js.map +1 -1
  4. package/dist/DBSQLSession.js +4 -0
  5. package/dist/DBSQLSession.js.map +1 -1
  6. package/dist/contracts/IClientContext.d.ts +7 -0
  7. package/dist/contracts/IDBSQLClient.d.ts +6 -0
  8. package/dist/contracts/IDBSQLSession.d.ts +6 -0
  9. package/dist/index.d.ts +2 -0
  10. package/dist/index.js +8 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/telemetry/CircuitBreaker.d.ts +73 -0
  13. package/dist/telemetry/CircuitBreaker.js +176 -0
  14. package/dist/telemetry/CircuitBreaker.js.map +1 -0
  15. package/dist/telemetry/DatabricksTelemetryExporter.d.ts +76 -0
  16. package/dist/telemetry/DatabricksTelemetryExporter.js +324 -0
  17. package/dist/telemetry/DatabricksTelemetryExporter.js.map +1 -0
  18. package/dist/telemetry/ExceptionClassifier.js +12 -0
  19. package/dist/telemetry/ExceptionClassifier.js.map +1 -1
  20. package/dist/telemetry/FeatureFlagCache.d.ts +61 -0
  21. package/dist/telemetry/FeatureFlagCache.js +208 -0
  22. package/dist/telemetry/FeatureFlagCache.js.map +1 -0
  23. package/dist/telemetry/MetricsAggregator.d.ts +72 -0
  24. package/dist/telemetry/MetricsAggregator.js +375 -0
  25. package/dist/telemetry/MetricsAggregator.js.map +1 -0
  26. package/dist/telemetry/TelemetryClient.d.ts +41 -0
  27. package/dist/telemetry/TelemetryClient.js +64 -0
  28. package/dist/telemetry/TelemetryClient.js.map +1 -0
  29. package/dist/telemetry/TelemetryClientProvider.d.ts +67 -0
  30. package/dist/telemetry/TelemetryClientProvider.js +148 -0
  31. package/dist/telemetry/TelemetryClientProvider.js.map +1 -0
  32. package/dist/telemetry/TelemetryEventEmitter.d.ts +93 -0
  33. package/dist/telemetry/TelemetryEventEmitter.js +172 -0
  34. package/dist/telemetry/TelemetryEventEmitter.js.map +1 -0
  35. package/dist/telemetry/telemetryUtils.d.ts +56 -0
  36. package/dist/telemetry/telemetryUtils.js +222 -0
  37. package/dist/telemetry/telemetryUtils.js.map +1 -0
  38. package/dist/telemetry/types.d.ts +37 -4
  39. package/dist/telemetry/types.js +15 -5
  40. package/dist/telemetry/types.js.map +1 -1
  41. package/dist/telemetry/urlUtils.d.ts +22 -0
  42. package/dist/telemetry/urlUtils.js +35 -0
  43. package/dist/telemetry/urlUtils.js.map +1 -0
  44. package/dist/utils/agentDetector.d.ts +20 -0
  45. package/dist/utils/agentDetector.js +39 -0
  46. package/dist/utils/agentDetector.js.map +1 -0
  47. package/dist/utils/buildUserAgentString.js +7 -1
  48. package/dist/utils/buildUserAgentString.js.map +1 -1
  49. package/dist/utils/index.d.ts +2 -1
  50. package/dist/utils/index.js +3 -1
  51. package/dist/utils/index.js.map +1 -1
  52. package/dist/utils/queryTags.d.ts +12 -0
  53. package/dist/utils/queryTags.js +35 -0
  54. package/dist/utils/queryTags.js.map +1 -0
  55. package/dist/version.d.ts +1 -1
  56. package/dist/version.js +1 -1
  57. package/package.json +1 -1
@@ -0,0 +1,148 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ const IDBSQLLogger_1 = require("../contracts/IDBSQLLogger");
22
+ const TelemetryClient_1 = __importDefault(require("./TelemetryClient"));
23
+ // Soft cap on distinct host entries. Above this the provider warns once so a
24
+ // misconfigured caller (per-request hosts, unnormalized aliases) is visible in
25
+ // logs rather than silently growing the map.
26
+ const MAX_CLIENTS_SOFT_LIMIT = 128;
27
+ /**
28
+ * Manages one telemetry client per host.
29
+ * Prevents rate limiting by sharing clients across connections to the same host.
30
+ * Instance-based (not singleton), stored in DBSQLClient.
31
+ *
32
+ * Reference counts are incremented and decremented synchronously, and
33
+ * `close()` is sync today, so there is no await between map mutation and
34
+ * client teardown. The map entry is removed before `close()` runs so a
35
+ * concurrent `getOrCreateClient` call for the same host gets a fresh
36
+ * instance rather than receiving this closing one. When `close()` becomes
37
+ * async (e.g. HTTP flush in [5/7]) the flow will need to `await` after the
38
+ * delete to preserve the same invariant.
39
+ */
40
+ class TelemetryClientProvider {
41
+ constructor(context) {
42
+ this.context = context;
43
+ this.softLimitWarned = false;
44
+ this.clients = new Map();
45
+ const logger = context.getLogger();
46
+ logger.log(IDBSQLLogger_1.LogLevel.debug, 'Created TelemetryClientProvider');
47
+ }
48
+ /**
49
+ * Canonicalize host so aliases (scheme, default port, trailing slash, case,
50
+ * trailing dot, surrounding whitespace) map to the same entry. Kept to a
51
+ * lightweight lexical normalization — `buildTelemetryUrl` still performs
52
+ * the strict security validation when a request is actually built.
53
+ */
54
+ static normalizeHostKey(host) {
55
+ return host
56
+ .trim()
57
+ .toLowerCase()
58
+ .replace(/^https?:\/\//, '')
59
+ .replace(/\/+$/, '')
60
+ .replace(/\.$/, '')
61
+ .replace(/:443$/, '');
62
+ }
63
+ /**
64
+ * Gets or creates a telemetry client for the specified host.
65
+ * Increments the reference count for the client.
66
+ *
67
+ * @param host The host identifier (e.g., "workspace.cloud.databricks.com")
68
+ * @returns The telemetry client for the host
69
+ */
70
+ getOrCreateClient(host) {
71
+ const logger = this.context.getLogger();
72
+ const key = TelemetryClientProvider.normalizeHostKey(host);
73
+ let holder = this.clients.get(key);
74
+ if (!holder) {
75
+ const client = new TelemetryClient_1.default(this.context, key);
76
+ holder = {
77
+ client,
78
+ refCount: 0,
79
+ };
80
+ this.clients.set(key, holder);
81
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Created new TelemetryClient for host: ${host}`);
82
+ if (!this.softLimitWarned && this.clients.size > MAX_CLIENTS_SOFT_LIMIT) {
83
+ this.softLimitWarned = true;
84
+ logger.log(IDBSQLLogger_1.LogLevel.warn, `TelemetryClientProvider has ${this.clients.size} distinct hosts — possible alias or leak`);
85
+ }
86
+ }
87
+ holder.refCount += 1;
88
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `TelemetryClient reference count for ${host}: ${holder.refCount}`);
89
+ return holder.client;
90
+ }
91
+ /**
92
+ * Releases a telemetry client for the specified host.
93
+ * Decrements the reference count and closes the client when it reaches zero.
94
+ *
95
+ * @param host The host identifier
96
+ */
97
+ releaseClient(host) {
98
+ const logger = this.context.getLogger();
99
+ const key = TelemetryClientProvider.normalizeHostKey(host);
100
+ const holder = this.clients.get(key);
101
+ if (!holder) {
102
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `No TelemetryClient found for host: ${host}`);
103
+ return;
104
+ }
105
+ // Guard against double-release: a caller releasing more times than it got
106
+ // would otherwise drive refCount negative and close a client another
107
+ // caller is still holding. Warn loudly and refuse to decrement further.
108
+ if (holder.refCount <= 0) {
109
+ logger.log(IDBSQLLogger_1.LogLevel.warn, `Unbalanced release for TelemetryClient host: ${host}`);
110
+ return;
111
+ }
112
+ holder.refCount -= 1;
113
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `TelemetryClient reference count for ${host}: ${holder.refCount}`);
114
+ // Close and remove client when reference count reaches zero.
115
+ // Remove from map before calling close so a concurrent getOrCreateClient
116
+ // creates a fresh client rather than receiving this closing one.
117
+ if (holder.refCount <= 0) {
118
+ this.clients.delete(key);
119
+ try {
120
+ holder.client.close();
121
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Closed and removed TelemetryClient for host: ${host}`);
122
+ }
123
+ catch (error) {
124
+ const msg = error instanceof Error ? error.message : String(error);
125
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Error releasing TelemetryClient: ${msg}`);
126
+ }
127
+ }
128
+ }
129
+ /**
130
+ * @internal Exposed for testing only.
131
+ */
132
+ getRefCount(host) {
133
+ const holder = this.clients.get(TelemetryClientProvider.normalizeHostKey(host));
134
+ return holder ? holder.refCount : 0;
135
+ }
136
+ /**
137
+ * @internal Exposed for testing only.
138
+ */
139
+ getActiveClients() {
140
+ const result = new Map();
141
+ for (const [host, holder] of this.clients.entries()) {
142
+ result.set(host, holder.client);
143
+ }
144
+ return result;
145
+ }
146
+ }
147
+ exports.default = TelemetryClientProvider;
148
+ //# sourceMappingURL=TelemetryClientProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TelemetryClientProvider.js","sourceRoot":"","sources":["../../lib/telemetry/TelemetryClientProvider.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAGH,4DAAqD;AACrD,wEAAgD;AAWhD,6EAA6E;AAC7E,+EAA+E;AAC/E,6CAA6C;AAC7C,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAEnC;;;;;;;;;;;;GAYG;AACH,MAAM,uBAAuB;IAK3B,YAAoB,OAAuB;QAAvB,YAAO,GAAP,OAAO,CAAgB;QAFnC,oBAAe,GAAG,KAAK,CAAC;QAG9B,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;QACnC,MAAM,CAAC,GAAG,CAAC,uBAAQ,CAAC,KAAK,EAAE,iCAAiC,CAAC,CAAC;IAChE,CAAC;IAED;;;;;OAKG;IACK,MAAM,CAAC,gBAAgB,CAAC,IAAY;QAC1C,OAAO,IAAI;aACR,IAAI,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M,CAAC,KAAK,CAAC,CAAC;gBACnE,MAAM,CAAC,GAAG,CAAC,uBAAQ,CAAC,KAAK,EAAE,oCAAoC,GAAG,EAAE,CAAC,CAAC;aACvE;SACF;IACH,CAAC;IAED;;OAEG;IACH,WAAW,CAAC,IAAY;QACtB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;QAChF,OAAO,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,MAAM,MAAM,GAAG,IAAI,GAAG,EAA2B,CAAC;QAClD,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE;YACnD,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;SACjC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,kBAAe,uBAAuB,CAAC"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Copyright (c) 2025 Databricks Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /// <reference types="node" />
17
+ import { EventEmitter } from 'events';
18
+ import IClientContext from '../contracts/IClientContext';
19
+ import { DriverConfiguration } from './types';
20
+ /**
21
+ * EventEmitter for driver telemetry.
22
+ * Emits events at key driver operations.
23
+ *
24
+ * CRITICAL REQUIREMENT: ALL exceptions must be caught and logged at LogLevel.debug ONLY
25
+ * (never warn/error) to avoid customer anxiety. NO console logging allowed - only IDBSQLLogger.
26
+ *
27
+ * All emit methods are wrapped in try-catch blocks that swallow exceptions completely.
28
+ * Event emission respects the telemetryEnabled flag from context config.
29
+ */
30
+ export default class TelemetryEventEmitter extends EventEmitter {
31
+ private context;
32
+ private enabled;
33
+ constructor(context: IClientContext);
34
+ /**
35
+ * Emit a connection open event.
36
+ *
37
+ * @param data Connection event data including sessionId, workspaceId, and driverConfig
38
+ */
39
+ emitConnectionOpen(data: {
40
+ sessionId: string;
41
+ workspaceId: string;
42
+ driverConfig: DriverConfiguration;
43
+ }): void;
44
+ /**
45
+ * Emit a statement start event.
46
+ *
47
+ * @param data Statement start data including statementId, sessionId, and operationType
48
+ */
49
+ emitStatementStart(data: {
50
+ statementId: string;
51
+ sessionId: string;
52
+ operationType?: string;
53
+ }): void;
54
+ /**
55
+ * Emit a statement complete event.
56
+ *
57
+ * @param data Statement completion data including latency, result format, and metrics
58
+ */
59
+ emitStatementComplete(data: {
60
+ statementId: string;
61
+ sessionId: string;
62
+ latencyMs?: number;
63
+ resultFormat?: string;
64
+ chunkCount?: number;
65
+ bytesDownloaded?: number;
66
+ pollCount?: number;
67
+ }): void;
68
+ /**
69
+ * Emit a CloudFetch chunk download event.
70
+ *
71
+ * @param data CloudFetch chunk data including chunk index, latency, bytes, and compression
72
+ */
73
+ emitCloudFetchChunk(data: {
74
+ statementId: string;
75
+ chunkIndex: number;
76
+ latencyMs?: number;
77
+ bytes: number;
78
+ compressed?: boolean;
79
+ }): void;
80
+ /**
81
+ * Emit an error event.
82
+ *
83
+ * @param data Error event data including error details and terminal status
84
+ */
85
+ emitError(data: {
86
+ statementId?: string;
87
+ sessionId?: string;
88
+ errorName: string;
89
+ errorMessage: string;
90
+ errorStack?: string;
91
+ isTerminal: boolean;
92
+ }): void;
93
+ }
@@ -0,0 +1,172 @@
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
+ const events_1 = require("events");
19
+ const IDBSQLLogger_1 = require("../contracts/IDBSQLLogger");
20
+ const types_1 = require("./types");
21
+ /**
22
+ * EventEmitter for driver telemetry.
23
+ * Emits events at key driver operations.
24
+ *
25
+ * CRITICAL REQUIREMENT: ALL exceptions must be caught and logged at LogLevel.debug ONLY
26
+ * (never warn/error) to avoid customer anxiety. NO console logging allowed - only IDBSQLLogger.
27
+ *
28
+ * All emit methods are wrapped in try-catch blocks that swallow exceptions completely.
29
+ * Event emission respects the telemetryEnabled flag from context config.
30
+ */
31
+ class TelemetryEventEmitter extends events_1.EventEmitter {
32
+ constructor(context) {
33
+ var _a;
34
+ super();
35
+ this.context = context;
36
+ // Check if telemetry is enabled from config
37
+ // Default to false for safe rollout
38
+ const config = context.getConfig();
39
+ this.enabled = (_a = config.telemetryEnabled) !== null && _a !== void 0 ? _a : false;
40
+ }
41
+ /**
42
+ * Emit a connection open event.
43
+ *
44
+ * @param data Connection event data including sessionId, workspaceId, and driverConfig
45
+ */
46
+ emitConnectionOpen(data) {
47
+ if (!this.enabled)
48
+ return;
49
+ const logger = this.context.getLogger();
50
+ try {
51
+ const event = {
52
+ eventType: types_1.TelemetryEventType.CONNECTION_OPEN,
53
+ timestamp: Date.now(),
54
+ sessionId: data.sessionId,
55
+ workspaceId: data.workspaceId,
56
+ driverConfig: data.driverConfig,
57
+ };
58
+ this.emit(types_1.TelemetryEventType.CONNECTION_OPEN, event);
59
+ }
60
+ catch (error) {
61
+ // Swallow all exceptions - log at debug level only
62
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Error emitting connection event: ${error.message}`);
63
+ }
64
+ }
65
+ /**
66
+ * Emit a statement start event.
67
+ *
68
+ * @param data Statement start data including statementId, sessionId, and operationType
69
+ */
70
+ emitStatementStart(data) {
71
+ if (!this.enabled)
72
+ return;
73
+ const logger = this.context.getLogger();
74
+ try {
75
+ const event = {
76
+ eventType: types_1.TelemetryEventType.STATEMENT_START,
77
+ timestamp: Date.now(),
78
+ statementId: data.statementId,
79
+ sessionId: data.sessionId,
80
+ operationType: data.operationType,
81
+ };
82
+ this.emit(types_1.TelemetryEventType.STATEMENT_START, event);
83
+ }
84
+ catch (error) {
85
+ // Swallow all exceptions - log at debug level only
86
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Error emitting statement start: ${error.message}`);
87
+ }
88
+ }
89
+ /**
90
+ * Emit a statement complete event.
91
+ *
92
+ * @param data Statement completion data including latency, result format, and metrics
93
+ */
94
+ emitStatementComplete(data) {
95
+ if (!this.enabled)
96
+ return;
97
+ const logger = this.context.getLogger();
98
+ try {
99
+ const event = {
100
+ eventType: types_1.TelemetryEventType.STATEMENT_COMPLETE,
101
+ timestamp: Date.now(),
102
+ statementId: data.statementId,
103
+ sessionId: data.sessionId,
104
+ latencyMs: data.latencyMs,
105
+ resultFormat: data.resultFormat,
106
+ chunkCount: data.chunkCount,
107
+ bytesDownloaded: data.bytesDownloaded,
108
+ pollCount: data.pollCount,
109
+ };
110
+ this.emit(types_1.TelemetryEventType.STATEMENT_COMPLETE, event);
111
+ }
112
+ catch (error) {
113
+ // Swallow all exceptions - log at debug level only
114
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Error emitting statement complete: ${error.message}`);
115
+ }
116
+ }
117
+ /**
118
+ * Emit a CloudFetch chunk download event.
119
+ *
120
+ * @param data CloudFetch chunk data including chunk index, latency, bytes, and compression
121
+ */
122
+ emitCloudFetchChunk(data) {
123
+ if (!this.enabled)
124
+ return;
125
+ const logger = this.context.getLogger();
126
+ try {
127
+ const event = {
128
+ eventType: types_1.TelemetryEventType.CLOUDFETCH_CHUNK,
129
+ timestamp: Date.now(),
130
+ statementId: data.statementId,
131
+ chunkIndex: data.chunkIndex,
132
+ latencyMs: data.latencyMs,
133
+ bytes: data.bytes,
134
+ compressed: data.compressed,
135
+ };
136
+ this.emit(types_1.TelemetryEventType.CLOUDFETCH_CHUNK, event);
137
+ }
138
+ catch (error) {
139
+ // Swallow all exceptions - log at debug level only
140
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Error emitting cloudfetch chunk: ${error.message}`);
141
+ }
142
+ }
143
+ /**
144
+ * Emit an error event.
145
+ *
146
+ * @param data Error event data including error details and terminal status
147
+ */
148
+ emitError(data) {
149
+ if (!this.enabled)
150
+ return;
151
+ const logger = this.context.getLogger();
152
+ try {
153
+ const event = {
154
+ eventType: types_1.TelemetryEventType.ERROR,
155
+ timestamp: Date.now(),
156
+ statementId: data.statementId,
157
+ sessionId: data.sessionId,
158
+ errorName: data.errorName,
159
+ errorMessage: data.errorMessage,
160
+ errorStack: data.errorStack,
161
+ isTerminal: data.isTerminal,
162
+ };
163
+ this.emit(types_1.TelemetryEventType.ERROR, event);
164
+ }
165
+ catch (error) {
166
+ // Swallow all exceptions - log at debug level only
167
+ logger.log(IDBSQLLogger_1.LogLevel.debug, `Error emitting error event: ${error.message}`);
168
+ }
169
+ }
170
+ }
171
+ exports.default = TelemetryEventEmitter;
172
+ //# sourceMappingURL=TelemetryEventEmitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TelemetryEventEmitter.js","sourceRoot":"","sources":["../../lib/telemetry/TelemetryEventEmitter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAEH,mCAAsC;AAEtC,4DAAqD;AACrD,mCAAkF;AAElF;;;;;;;;;GASG;AACH,MAAqB,qBAAsB,SAAQ,qBAAY;IAG7D,YAA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AQ,CAAC,KAAK,EAAE,+BAA+B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;SAC5E;IACH,CAAC;CACF;AAhKD,wCAgKC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Copyright (c) 2025 Databricks Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Build an HTTPS telemetry URL from a host and a path.
18
+ *
19
+ * Refuses anything beyond a bare `host[:port]` so a compromised or mistyped
20
+ * host cannot redirect the authenticated request to an attacker-controlled
21
+ * endpoint. Defeated historical bypasses include:
22
+ * - protocol-relative prefix: `//attacker.com`
23
+ * - zero-width / ASCII whitespace in the host
24
+ * - userinfo (`user:pass@host`)
25
+ * - path/query/fragment
26
+ * - CRLF (header injection on some fetch backends)
27
+ * - loopback / link-local / RFC1918 / cloud-metadata addresses
28
+ *
29
+ * Returns `null` when the host fails any check; callers drop the batch.
30
+ */
31
+ export declare function buildTelemetryUrl(host: string, path: string): string | null;
32
+ /**
33
+ * Strips common secret shapes from a free-form error string and caps length.
34
+ * Applied before anything is shipped off-box. Redaction happens before
35
+ * truncation so a long stack cannot bury a secret past the cap; truncation
36
+ * then runs a second pass to catch anything that appeared only in the tail.
37
+ */
38
+ export declare function redactSensitive(value: string | undefined, maxLen?: number): string;
39
+ /**
40
+ * Normalises any `HeadersInit` shape (`Headers`, `[string,string][]`, or
41
+ * `Record<string, string>`) into a plain string dictionary. Non-string
42
+ * values are dropped. Shared by the exporter and FeatureFlagCache so there
43
+ * is one source of truth for auth-header handling.
44
+ */
45
+ export declare function normalizeHeaders(raw: unknown): Record<string, string>;
46
+ /**
47
+ * Case-insensitive check for a non-empty `Authorization` header.
48
+ */
49
+ export declare function hasAuthorization(headers: Record<string, string>): boolean;
50
+ /**
51
+ * Returns a safe `process_name` value: the basename of the first whitespace-
52
+ * delimited token, with trailing whitespace trimmed. This defeats both the
53
+ * absolute-path PII leak (`/home/<user>/app.js`) and the argv-leak shape
54
+ * (`node --db-password=X app.js`) that some producers pass in.
55
+ */
56
+ export declare function sanitizeProcessName(name: string | undefined): string;