@databricks/sql 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +6 -0
  2. package/dist/DBSQLClient.d.ts +1 -0
  3. package/dist/DBSQLClient.js +74 -5
  4. package/dist/DBSQLClient.js.map +1 -1
  5. package/dist/ReydenWarehouseCache.d.ts +57 -0
  6. package/dist/ReydenWarehouseCache.js +101 -0
  7. package/dist/ReydenWarehouseCache.js.map +1 -0
  8. package/dist/connection/connections/HttpConnection.js +4 -1
  9. package/dist/connection/connections/HttpConnection.js.map +1 -1
  10. package/dist/connection/contracts/IConnectionOptions.d.ts +2 -1
  11. package/dist/contracts/IClientContext.d.ts +1 -0
  12. package/dist/contracts/IDBSQLClient.d.ts +55 -0
  13. package/dist/errors/StatusError.d.ts +1 -0
  14. package/dist/errors/StatusError.js +1 -0
  15. package/dist/errors/StatusError.js.map +1 -1
  16. package/dist/kernel/KernelAuth.d.ts +106 -24
  17. package/dist/kernel/KernelAuth.js +331 -75
  18. package/dist/kernel/KernelAuth.js.map +1 -1
  19. package/dist/kernel/KernelBackend.d.ts +5 -4
  20. package/dist/kernel/KernelBackend.js +8 -7
  21. package/dist/kernel/KernelBackend.js.map +1 -1
  22. package/dist/kernel/KernelNativeLoader.d.ts +2 -3
  23. package/dist/kernel/KernelNativeLoader.js.map +1 -1
  24. package/dist/kernel/KernelOperationBackend.js +2 -1
  25. package/dist/kernel/KernelOperationBackend.js.map +1 -1
  26. package/dist/kernel/KernelPositionalParams.d.ts +6 -6
  27. package/dist/kernel/KernelPositionalParams.js +11 -15
  28. package/dist/kernel/KernelPositionalParams.js.map +1 -1
  29. package/dist/kernel/KernelSessionBackend.js +4 -5
  30. package/dist/kernel/KernelSessionBackend.js.map +1 -1
  31. package/dist/result/ArrowResultConverter.d.ts +3 -1
  32. package/dist/result/ArrowResultConverter.js +9 -4
  33. package/dist/result/ArrowResultConverter.js.map +1 -1
  34. package/dist/telemetry/telemetryUtils.d.ts +10 -0
  35. package/dist/telemetry/telemetryUtils.js +15 -0
  36. package/dist/telemetry/telemetryUtils.js.map +1 -1
  37. package/dist/thrift-backend/ThriftBackend.d.ts +22 -2
  38. package/dist/thrift-backend/ThriftBackend.js +120 -2
  39. package/dist/thrift-backend/ThriftBackend.js.map +1 -1
  40. package/dist/thrift-backend/ThriftOperationBackend.js +9 -3
  41. package/dist/thrift-backend/ThriftOperationBackend.js.map +1 -1
  42. package/dist/utils/index.d.ts +2 -1
  43. package/dist/utils/index.js +3 -1
  44. package/dist/utils/index.js.map +1 -1
  45. package/dist/utils/normalizePemBytes.d.ts +20 -0
  46. package/dist/utils/normalizePemBytes.js +49 -0
  47. package/dist/utils/normalizePemBytes.js.map +1 -0
  48. package/dist/version.d.ts +1 -1
  49. package/dist/version.js +1 -1
  50. package/native/kernel/README.md +1 -1
  51. package/native/kernel/index.d.ts +1120 -883
  52. package/native/kernel/index.js +653 -265
  53. package/package.json +10 -10
@@ -1,4 +1,7 @@
1
1
  import { ConnectionOptions } from '../contracts/IDBSQLClient';
2
+ import { ClientConfig } from '../contracts/IClientContext';
3
+ import IDBSQLLogger from '../contracts/IDBSQLLogger';
4
+ import { isTelemetryDisabledByEnv } from '../telemetry/telemetryUtils';
2
5
  /**
3
6
  * Shape consumed by the napi-binding's `openSession()` (see
4
7
  * `native/kernel/index.d.ts`). Mirrors `ConnectionOptions` in the binding's
@@ -13,6 +16,10 @@ import { ConnectionOptions } from '../contracts/IDBSQLClient';
13
16
  * everything else (client_id, scopes, callback timeout,
14
17
  * token_url_override) uses kernel defaults.
15
18
  *
19
+ * `static-token` reuses the native PAT bearer-token mode, where federation is
20
+ * always enabled. `enableTokenFederation` is ignored; a non-empty
21
+ * `federationClientId` selects SP-wide WIF and omission selects account-wide.
22
+ *
16
23
  * The `authMode` string literals MUST match the napi-emitted `AuthMode`
17
24
  * variant names verbatim (`'Pat'`, `'OAuthM2m'`, `'OAuthU2m'` — napi-rs's
18
25
  * `#[napi(string_enum)]` without an explicit case option emits the
@@ -78,6 +85,31 @@ export interface KernelSessionDefaults {
78
85
  retryMaxAttempts?: number;
79
86
  retryOverallTimeoutSecs?: number;
80
87
  }
88
+ export interface KernelTelemetryOptions {
89
+ /** Driver/runtime identity forwarded to kernel-owned telemetry. */
90
+ driverName?: string;
91
+ driverVersion?: string;
92
+ runtimeName?: string;
93
+ runtimeVersion?: string;
94
+ runtimeVendor?: string;
95
+ osName?: string;
96
+ osVersion?: string;
97
+ osArch?: string;
98
+ clientAppName?: string;
99
+ localeName?: string;
100
+ charSetEncoding?: string;
101
+ processName?: string;
102
+ /** Kernel-owned telemetry switch and batching. */
103
+ telemetryEnabled?: boolean;
104
+ telemetryBatchSize?: number;
105
+ telemetryFlushIntervalMs?: number;
106
+ telemetryMaxRetries?: number;
107
+ telemetryRetryDelayMs?: number;
108
+ telemetryCloseFlushTimeoutMs?: number;
109
+ telemetryCircuitBreakerEnabled?: boolean;
110
+ telemetryCircuitBreakerThreshold?: number;
111
+ telemetryCircuitBreakerTimeoutMs?: number;
112
+ }
81
113
  /**
82
114
  * TLS options shared across all auth-mode variants. Mirror the napi
83
115
  * binding's `ConnectionOptions.checkServerCertificate` / `.customCaCert`
@@ -163,7 +195,14 @@ export interface KernelProxyOptions {
163
195
  bypassHosts?: string;
164
196
  };
165
197
  }
166
- export type KernelNativeConnectionOptions = KernelSessionDefaults & KernelTlsOptions & KernelHttpOptions & KernelProxyOptions & ({
198
+ export interface KernelFederationOptions {
199
+ /**
200
+ * SP-wide Workload Identity Federation client id. Omitted selects BYOT /
201
+ * account-wide WIF.
202
+ */
203
+ identityFederationClientId?: string;
204
+ }
205
+ export type KernelNativeConnectionOptions = KernelSessionDefaults & KernelTlsOptions & KernelHttpOptions & KernelTelemetryOptions & KernelProxyOptions & KernelFederationOptions & ({
167
206
  hostName: string;
168
207
  httpPath: string;
169
208
  authMode: 'Pat';
@@ -182,6 +221,14 @@ export type KernelNativeConnectionOptions = KernelSessionDefaults & KernelTlsOpt
182
221
  oauthRedirectPort: number;
183
222
  oauthScopes?: Array<string>;
184
223
  oauthClientId?: string;
224
+ tokenCacheEnabled?: boolean;
225
+ } | {
226
+ hostName: string;
227
+ httpPath: string;
228
+ authMode: 'AzureSpM2m';
229
+ azureClientId: string;
230
+ azureClientSecret: string;
231
+ azureTenantId?: string;
185
232
  });
186
233
  /**
187
234
  * Reject inputs that pass `typeof === 'string' && length > 0` but are
@@ -205,11 +252,13 @@ export declare function isBlankOrReserved(s: string): boolean;
205
252
  * master verify toggle is on). Mirrors Python's `tls_verify_hostname`.
206
253
  * - `customCaCert` accepts a PEM string or `Buffer`; normalised to a
207
254
  * `Buffer` via {@link normalizePemBytes}.
208
- * - `clientCertPem` / `clientKeyPem` carry the mutual-TLS client identity.
209
- * They must be supplied **together** — supplying only one is rejected
210
- * here with an actionable error (rather than waiting for the kernel's
211
- * `InvalidArgument` at `openSession`). Each accepts a PEM string or
212
- * `Buffer`, normalised the same way.
255
+ * - `clientCertPem` / `clientKeyPem` (or their public aliases
256
+ * `clientCert` / `clientKey`) carry the mutual-TLS client identity. The
257
+ * internal `*Pem` names win when both are present. They must be supplied
258
+ * **together** — supplying only one is rejected here with an actionable
259
+ * error (rather than waiting for the kernel's `InvalidArgument` at
260
+ * `openSession`). Each accepts a PEM string or `Buffer`, normalised the
261
+ * same way.
213
262
  *
214
263
  * Throws `HiveDriverError` when a cert/key is empty, mis-typed, lacks the
215
264
  * expected PEM header, or when only one half of the mTLS pair is set.
@@ -224,6 +273,10 @@ export declare function buildKernelHttpOptions(options: ConnectionOptions): Kern
224
273
  * - PAT: `authType: 'access-token'` (or undefined, which already means
225
274
  * PAT throughout the existing driver — see
226
275
  * `DBSQLClient.createAuthProvider`).
276
+ * - Static token: `authType: 'static-token'` + `staticToken`. The token is
277
+ * forwarded through the native PAT bearer-token mode, where federation is
278
+ * always enabled. `federationClientId` selects SP-wide WIF; omission
279
+ * selects account-wide WIF. `enableTokenFederation` is ignored.
227
280
  * - OAuth M2M: `authType: 'databricks-oauth'` + `oauthClientId` +
228
281
  * `oauthClientSecret`. Kernel handles OIDC discovery, client_credentials
229
282
  * exchange, and re-auth on expiry internally.
@@ -232,27 +285,38 @@ export declare function buildKernelHttpOptions(options: ConnectionOptions): Kern
232
285
  * a browser, listens on localhost:8030, exchanges the code, persists
233
286
  * to `~/.config/databricks-sql-kernel/oauth/{sha256}.json`).
234
287
  *
235
- * **Flow selection — DELIBERATE DIVERGENCE FROM THRIFT.** Thrift's
288
+ * **Flow selection — MIRRORS THRIFT.** Thrift's
236
289
  * `DBSQLClient.createAuthProvider` (`DBSQLClient.ts:216`) keys off the
237
290
  * *secret* (`oauthClientSecret === undefined ? U2M : M2M`), so a custom
238
- * `oauthClientId` with no secret runs U2M with that id. kernel instead keys
239
- * off `oauthClientId` *presence* (id present → M2M, absent → U2M). The
240
- * trade-off: keying off the id means a caller who set an id but
241
- * typoed/forgot the secret gets the actionable M2M "secret is required"
242
- * error instead of being silently routed to U2M (which would hide their
243
- * intent). The cost is two real behavioural gaps vs Thrift:
244
- * 1. `oauthClientId` + no secret → Thrift runs U2M; kernel throws
245
- * `AuthenticationError` (M2M secret required).
246
- * 2. kernel U2M has NO custom-client-id support — the kernel hardcodes
247
- * `client_id = "databricks-cli"`, and kernel rejects any `oauthClientId`
248
- * on the U2M arm. Thrift U2M honours a custom `clientId`.
249
- * Both are documented limitations of the M0 kernel OAuth surface, not bugs.
291
+ * `oauthClientId` with no secret runs U2M with that id. This adapter keys
292
+ * off the same signal: `oauthClientSecret === undefined` ⇒ U2M, else M2M
293
+ * (see `buildKernelConnectionOptions` below). A custom `oauthClientId` is
294
+ * forwarded verbatim on the U2M arm; when absent the napi binding applies
295
+ * its own default `client_id`. The adapter therefore does NOT throw an M2M
296
+ * "secret required" error for `oauthClientId` + no secret, and does NOT
297
+ * reject a custom `oauthClientId` on U2M — those decisions, if the native
298
+ * binding makes them, happen below the TypeScript layer and are not
299
+ * observable from this repo.
300
+ *
301
+ * Azure (Entra) on the OAuth path. The kernel runs a single, cloud-blind
302
+ * in-house U2M flow and workspace-OIDC M2M; only Entra-direct **M2M** gets a
303
+ * dedicated kernel mode:
304
+ * - **U2M (no secret), any cloud, any `useDatabricksOAuthInAzure`** →
305
+ * `OAuthU2m`. The kernel uses the workspace's OIDC-discovered authorize
306
+ * endpoint (`{host}/oidc/v1/authorize`) verbatim; that in-house
307
+ * workspace-federated flow works against Azure workspaces too (they federate
308
+ * the browser login to Entra server-side — verified E2E). So Azure U2M is
309
+ * NOT special-cased and NOT rejected — it forwards the in-house app
310
+ * (`databricks-sql-connector`) + `sql offline_access`, exactly like AWS/GCP.
311
+ * - **M2M (secret) with `useDatabricksOAuthInAzure: true`** (or non-Azure) →
312
+ * `OAuthM2m` (workspace-OIDC client-credentials).
313
+ * - **M2M (secret) on an Azure host with `useDatabricksOAuthInAzure` absent/
314
+ * `false`** (Entra-direct) → Azure service-principal M2M (`AzureSpM2m`); the
315
+ * Entra SP creds ride `oauthClientId`/`oauthClientSecret`, `azureTenantId`
316
+ * optional (kernel auto-discovers).
317
+ * - On a non-Azure host `useDatabricksOAuthInAzure` is inert.
250
318
  *
251
319
  * Out of scope on the OAuth paths (rejected with a clear error):
252
- * - `azureTenantId` / `useDatabricksOAuthInAzure` → Microsoft Entra
253
- * direct flow. The kernel uses workspace-OIDC discovery (which works
254
- * against Azure workspaces too — they serve `/oidc/.well-known/...`)
255
- * and does not implement the Entra-direct scope-rewrite path.
256
320
  * - `persistence` on M2M → M2M tokens are not cached (re-issuing is
257
321
  * cheap; no refresh token).
258
322
  * - `persistence` on U2M → custom token store is a parity gap;
@@ -266,7 +330,7 @@ export declare function buildKernelHttpOptions(options: ConnectionOptions): Kern
266
330
  *
267
331
  * Throws:
268
332
  * - `AuthenticationError` for missing/blank required credentials.
269
- * - `HiveDriverError` for unsupported auth modes / Azure-direct /
333
+ * - `HiveDriverError` for unsupported auth modes /
270
334
  * custom persistence / ambiguous combinations.
271
335
  */
272
336
  /**
@@ -284,6 +348,24 @@ export declare function buildKernelRetryOptions(config: {
284
348
  retryDelayMin?: number;
285
349
  retryDelayMax?: number;
286
350
  }): Pick<KernelSessionDefaults, 'retryMinWaitSecs' | 'retryMaxWaitSecs' | 'retryMaxAttempts' | 'retryOverallTimeoutSecs'>;
351
+ export { isTelemetryDisabledByEnv };
352
+ /**
353
+ * Build the kernel telemetry options block from the driver's `ClientConfig`.
354
+ *
355
+ * **Always-forward is intentional, mirroring `buildKernelRetryOptions`.** On the
356
+ * real `DBSQLClient` path `getDefaultConfig()` seeds every one of these knobs from
357
+ * `DEFAULT_TELEMETRY_CONFIG`, so they are never `undefined` and always propagate to
358
+ * the kernel's `openSession` — the driver's telemetry-tuning defaults deliberately
359
+ * govern both backends from one `ClientConfig` (same rationale as the retry knobs),
360
+ * rather than letting the kernel's independent defaults apply. The kernel's own
361
+ * `"Omitted ⇒ kernel default"` branch is therefore only reachable via a bare
362
+ * `configOverrides`-style config (e.g. unit tests), not the default-populated one a
363
+ * live client uses. The `Number.isFinite(...) && > 0` guards below are NOT an
364
+ * opt-in gate: they exist to reject a caller-supplied out-of-range value (warning
365
+ * via `warnRejected`) and to tolerate sparse test configs, not to compare against
366
+ * the default.
367
+ */
368
+ export declare function buildKernelTelemetryOptions(config: Pick<ClientConfig, 'telemetryBatchSize' | 'telemetryFlushIntervalMs' | 'telemetryMaxRetries' | 'telemetryBackoffBaseMs' | 'telemetryCloseTimeoutMs' | 'telemetryCircuitBreakerThreshold' | 'telemetryCircuitBreakerTimeout'>, options?: Pick<ConnectionOptions, 'telemetryEnabled'>, logger?: IDBSQLLogger): KernelTelemetryOptions;
287
369
  /**
288
370
  * Map the public `ConnectionOptions.proxy` (`{protocol, host, port, auth}` —
289
371
  * the same shape the Thrift backend accepts) onto the kernel's structured napi