@clickhouse/client
Advanced tools
Comparing version 1.9.1 to 1.10.0
@@ -8,2 +8,3 @@ "use strict"; | ||
const client_common_1 = require("@clickhouse/client-common"); | ||
const client_common_2 = require("@clickhouse/client-common"); | ||
const crypto_1 = __importDefault(require("crypto")); | ||
@@ -59,3 +60,11 @@ const stream_1 = __importDefault(require("stream")); | ||
}); | ||
this.defaultAuthHeader = `Basic ${Buffer.from(`${params.username}:${params.password}`).toString('base64')}`; | ||
if (params.auth.type === 'Credentials') { | ||
this.defaultAuthHeader = `Basic ${Buffer.from(`${params.auth.username}:${params.auth.password}`).toString('base64')}`; | ||
} | ||
else if (params.auth.type === 'JWT') { | ||
this.defaultAuthHeader = `Bearer ${params.auth.access_token}`; | ||
} | ||
else { | ||
throw new Error(`Unknown auth type: ${params.auth.type}`); | ||
} | ||
this.defaultHeaders = { | ||
@@ -75,3 +84,3 @@ ...(params.http_headers ?? {}), | ||
method: 'GET', | ||
url: (0, client_common_1.transformUrl)({ url: this.params.url, pathname: '/ping' }), | ||
url: (0, client_common_2.transformUrl)({ url: this.params.url, pathname: '/ping' }), | ||
abort_signal: abortController.signal, | ||
@@ -100,4 +109,4 @@ headers: this.buildRequestHeaders(), | ||
const query_id = this.getQueryId(params.query_id); | ||
const clickhouse_settings = (0, client_common_1.withHttpSettings)(params.clickhouse_settings, this.params.compression.decompress_response); | ||
const searchParams = (0, client_common_1.toSearchParams)({ | ||
const clickhouse_settings = (0, client_common_2.withHttpSettings)(params.clickhouse_settings, this.params.compression.decompress_response); | ||
const searchParams = (0, client_common_2.toSearchParams)({ | ||
database: this.params.database, | ||
@@ -116,3 +125,3 @@ query_params: params.query_params, | ||
method: 'POST', | ||
url: (0, client_common_1.transformUrl)({ url: this.params.url, searchParams }), | ||
url: (0, client_common_2.transformUrl)({ url: this.params.url, searchParams }), | ||
body: params.query, | ||
@@ -150,3 +159,3 @@ abort_signal: controller.signal, | ||
const query_id = this.getQueryId(params.query_id); | ||
const searchParams = (0, client_common_1.toSearchParams)({ | ||
const searchParams = (0, client_common_2.toSearchParams)({ | ||
database: this.params.database, | ||
@@ -164,3 +173,3 @@ clickhouse_settings: params.clickhouse_settings, | ||
method: 'POST', | ||
url: (0, client_common_1.transformUrl)({ url: this.params.url, searchParams }), | ||
url: (0, client_common_2.transformUrl)({ url: this.params.url, searchParams }), | ||
body: params.values, | ||
@@ -214,15 +223,25 @@ abort_signal: controller.signal, | ||
buildRequestHeaders(params) { | ||
if (this.params.set_basic_auth_header) { | ||
if ((0, client_common_1.isJWTAuth)(params?.auth)) { | ||
return { | ||
...this.defaultHeaders, | ||
Authorization: params?.auth !== undefined | ||
? `Basic ${Buffer.from(`${params.auth.username}:${params.auth.password}`).toString('base64')}` | ||
: this.defaultAuthHeader, | ||
Authorization: `Bearer ${params.auth.access_token}`, | ||
}; | ||
} | ||
else { | ||
return { | ||
...this.defaultHeaders, | ||
}; | ||
if (this.params.set_basic_auth_header) { | ||
if ((0, client_common_1.isCredentialsAuth)(params?.auth)) { | ||
return { | ||
...this.defaultHeaders, | ||
Authorization: `Basic ${Buffer.from(`${params.auth.username}:${params.auth.password}`).toString('base64')}`, | ||
}; | ||
} | ||
else { | ||
return { | ||
...this.defaultHeaders, | ||
Authorization: this.defaultAuthHeader, | ||
}; | ||
} | ||
} | ||
return { | ||
...this.defaultHeaders, | ||
}; | ||
} | ||
@@ -301,3 +320,3 @@ getQueryId(query_id) { | ||
const sendQueryInParams = params.values !== undefined; | ||
const clickhouse_settings = (0, client_common_1.withHttpSettings)(params.clickhouse_settings, this.params.compression.decompress_response); | ||
const clickhouse_settings = (0, client_common_2.withHttpSettings)(params.clickhouse_settings, this.params.compression.decompress_response); | ||
const toSearchParamsOptions = { | ||
@@ -312,3 +331,3 @@ query: sendQueryInParams ? params.query : undefined, | ||
}; | ||
const searchParams = (0, client_common_1.toSearchParams)(toSearchParamsOptions); | ||
const searchParams = (0, client_common_2.toSearchParams)(toSearchParamsOptions); | ||
const { controller, controllerCleanup } = this.getAbortController(params); | ||
@@ -325,3 +344,3 @@ const tryDecompressResponseStream = params.op === 'Exec' | ||
method: 'POST', | ||
url: (0, client_common_1.transformUrl)({ url: this.params.url, searchParams }), | ||
url: (0, client_common_2.transformUrl)({ url: this.params.url, searchParams }), | ||
body: sendQueryInParams ? params.values : params.query, | ||
@@ -363,3 +382,3 @@ abort_signal: controller.signal, | ||
// otherwise, we can occasionally get an expired socket, see https://github.com/ClickHouse/clickhouse-js/issues/294 | ||
await (0, client_common_1.sleep)(0); | ||
await (0, client_common_2.sleep)(0); | ||
return new Promise((resolve, reject) => { | ||
@@ -377,3 +396,3 @@ const start = Date.now(); | ||
// even if the stream decompression is disabled, we have to decompress it in case of an error | ||
const isFailedResponse = !(0, client_common_1.isSuccessfulResponse)(_response.statusCode); | ||
const isFailedResponse = !(0, client_common_2.isSuccessfulResponse)(_response.statusCode); | ||
if (tryDecompressResponseStream || isFailedResponse) { | ||
@@ -392,3 +411,3 @@ const decompressionResult = (0, compression_1.decompressResponse)(_response, this.logger); | ||
const errorMessage = await (0, utils_1.getAsText)(responseStream); | ||
reject((0, client_common_1.parseError)(errorMessage)); | ||
reject((0, client_common_2.parseError)(errorMessage)); | ||
} | ||
@@ -395,0 +414,0 @@ catch (err) { |
@@ -1,2 +0,2 @@ | ||
import type { BaseQueryParams } from '@clickhouse/client-common'; | ||
import { type BaseQueryParams } from '@clickhouse/client-common'; | ||
import type Http from 'http'; | ||
@@ -3,0 +3,0 @@ import type { NodeConnectionParams, RequestParams } from './node_base_connection'; |
@@ -8,2 +8,3 @@ "use strict"; | ||
const client_common_1 = require("@clickhouse/client-common"); | ||
const client_common_2 = require("@clickhouse/client-common"); | ||
const https_1 = __importDefault(require("https")); | ||
@@ -24,7 +25,20 @@ const node_base_connection_1 = require("./node_base_connection"); | ||
if (this.params.tls !== undefined) { | ||
const headers = { | ||
...this.defaultHeaders, | ||
'X-ClickHouse-User': params?.auth?.username ?? this.params.username, | ||
'X-ClickHouse-Key': params?.auth?.password ?? this.params.password, | ||
}; | ||
if (this.params.auth.type === 'JWT') { | ||
throw new Error('JWT auth is not supported with HTTPS connection using custom certificates'); | ||
} | ||
let headers; | ||
if ((0, client_common_1.isCredentialsAuth)(params?.auth)) { | ||
headers = { | ||
...this.defaultHeaders, | ||
'X-ClickHouse-User': params.auth.username, | ||
'X-ClickHouse-Key': params.auth.password, | ||
}; | ||
} | ||
else { | ||
headers = { | ||
...this.defaultHeaders, | ||
'X-ClickHouse-User': this.params.auth.username, | ||
'X-ClickHouse-Key': this.params.auth.password, | ||
}; | ||
} | ||
const tlsType = this.params.tls.type; | ||
@@ -46,3 +60,3 @@ switch (tlsType) { | ||
createClientRequest(params) { | ||
const headers = (0, client_common_1.withCompressionHeaders)({ | ||
const headers = (0, client_common_2.withCompressionHeaders)({ | ||
headers: params.headers, | ||
@@ -49,0 +63,0 @@ enable_request_compression: params.enable_request_compression, |
@@ -7,2 +7,2 @@ export { NodeClickHouseClient as ClickHouseClient, type QueryResult, } from './client'; | ||
/** Re-export @clickhouse/client-common types */ | ||
export { type BaseClickHouseClientConfigOptions, type BaseQueryParams, type QueryParams, type ExecParams, type InsertParams, type InsertValues, type CommandParams, type CommandResult, type ExecResult, type InsertResult, type DataFormat, type RawDataFormat, type JSONDataFormat, type StreamableDataFormat, type StreamableJSONDataFormat, type SingleDocumentJSONFormat, type Logger, type LogParams, type ErrorLogParams, type WarnLogParams, type ClickHouseSettings, type MergeTreeSettings, type Row, type ResponseJSON, type InputJSON, type InputJSONObjectEachRow, type BaseResultSet, type PingResult, ClickHouseError, ClickHouseLogLevel, SettingsMap, SupportedJSONFormats, SupportedRawFormats, StreamableFormats, StreamableJSONFormats, SingleDocumentJSONFormats, RecordsJSONFormats, type SimpleColumnType, type ParsedColumnSimple, type ParsedColumnEnum, type ParsedColumnFixedString, type ParsedColumnNullable, type ParsedColumnDecimal, type ParsedColumnDateTime, type ParsedColumnDateTime64, type ParsedColumnArray, type ParsedColumnTuple, type ParsedColumnMap, type ParsedColumnType, parseColumnType, SimpleColumnTypes, type ProgressRow, isProgressRow, type RowOrProgress, TupleParam, } from '@clickhouse/client-common'; | ||
export { type BaseClickHouseClientConfigOptions, type BaseQueryParams, type QueryParams, type ExecParams, type InsertParams, type InsertValues, type CommandParams, type CommandResult, type ExecResult, type InsertResult, type DataFormat, type RawDataFormat, type JSONDataFormat, type StreamableDataFormat, type StreamableJSONDataFormat, type SingleDocumentJSONFormat, type Logger, type LogParams, type ErrorLogParams, type WarnLogParams, type ClickHouseSettings, type MergeTreeSettings, type Row, type ResponseJSON, type InputJSON, type InputJSONObjectEachRow, type BaseResultSet, type PingResult, ClickHouseError, ClickHouseLogLevel, SettingsMap, SupportedJSONFormats, SupportedRawFormats, StreamableFormats, StreamableJSONFormats, SingleDocumentJSONFormats, RecordsJSONFormats, type SimpleColumnType, type ParsedColumnSimple, type ParsedColumnEnum, type ParsedColumnFixedString, type ParsedColumnNullable, type ParsedColumnDecimal, type ParsedColumnDateTime, type ParsedColumnDateTime64, type ParsedColumnArray, type ParsedColumnTuple, type ParsedColumnMap, type ParsedColumnType, parseColumnType, SimpleColumnTypes, type ProgressRow, isProgressRow, type RowOrProgress, type ClickHouseAuth, type ClickHouseJWTAuth, type ClickHouseCredentialsAuth, TupleParam, } from '@clickhouse/client-common'; |
@@ -1,2 +0,2 @@ | ||
declare const _default: "1.9.1"; | ||
declare const _default: "1.10.0"; | ||
export default _default; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = '1.9.1'; | ||
exports.default = '1.10.0'; | ||
//# sourceMappingURL=version.js.map |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://clickhouse.com", | ||
"version": "1.9.1", | ||
"version": "1.10.0", | ||
"license": "Apache-2.0", | ||
@@ -27,4 +27,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@clickhouse/client-common": "1.9.1" | ||
"@clickhouse/client-common": "1.10.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
116863
1537
+ Added@clickhouse/client-common@1.10.0(transitive)
- Removed@clickhouse/client-common@1.9.1(transitive)