@lightdash/cli 0.2100.0 → 0.2101.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.
@@ -23,6 +23,10 @@ const snowflakeSchema = {
23
23
  type: 'string',
24
24
  nullable: true,
25
25
  },
26
+ authenticator: {
27
+ type: 'string',
28
+ nullable: true,
29
+ },
26
30
  private_key_path: {
27
31
  type: 'string',
28
32
  nullable: true,
@@ -96,6 +100,18 @@ const convertSnowflakeSchema = async (target) => {
96
100
  if (target.private_key) {
97
101
  privateKey = target.private_key;
98
102
  }
103
+ // Determine authentication type based on authenticator field or credentials present
104
+ let authenticationType;
105
+ if (target.authenticator &&
106
+ target.authenticator.toLowerCase() === 'externalbrowser') {
107
+ authenticationType = common_1.SnowflakeAuthenticationType.EXTERNAL_BROWSER;
108
+ }
109
+ else if (privateKey) {
110
+ authenticationType = common_1.SnowflakeAuthenticationType.PRIVATE_KEY;
111
+ }
112
+ else {
113
+ authenticationType = common_1.SnowflakeAuthenticationType.PASSWORD;
114
+ }
99
115
  return {
100
116
  type: common_1.WarehouseTypes.SNOWFLAKE,
101
117
  account: target.account,
@@ -103,9 +119,7 @@ const convertSnowflakeSchema = async (target) => {
103
119
  password: target.password,
104
120
  privateKey,
105
121
  privateKeyPass: target.private_key_passphrase,
106
- authenticationType: privateKey
107
- ? common_1.SnowflakeAuthenticationType.PRIVATE_KEY
108
- : common_1.SnowflakeAuthenticationType.PASSWORD,
122
+ authenticationType,
109
123
  role: target.role,
110
124
  warehouse: target.warehouse,
111
125
  database: target.database,
@@ -5,12 +5,32 @@ exports.default = getWarehouseClient;
5
5
  const tslib_1 = require("tslib");
6
6
  const common_1 = require("@lightdash/common");
7
7
  const warehouses_1 = require("@lightdash/warehouses");
8
+ const crypto_1 = tslib_1.__importDefault(require("crypto"));
8
9
  const execa_1 = tslib_1.__importDefault(require("execa"));
9
10
  const path_1 = tslib_1.__importDefault(require("path"));
10
11
  const config_1 = require("../../config");
11
12
  const profile_1 = require("../../dbt/profile");
12
13
  const globalState_1 = tslib_1.__importDefault(require("../../globalState"));
13
14
  const apiClient_1 = require("./apiClient");
15
+ /**
16
+ * Cache warehouse clients to avoid repeated authentication prompts
17
+ * Currently used for:
18
+ * - Snowflake external browser auth (avoids opening multiple browser tabs)
19
+ */
20
+ const warehouseClientCache = new Map();
21
+ /**
22
+ * Generates a unique cache key for warehouse credentials by hashing the credentials
23
+ */
24
+ function getWarehouseClientCacheKey(credentials) {
25
+ // Create a hash of the stringified credentials
26
+ // This provides a unique key regardless of warehouse type
27
+ const credentialsString = JSON.stringify(credentials);
28
+ const hash = crypto_1.default
29
+ .createHash('sha256')
30
+ .update(credentialsString)
31
+ .digest('hex');
32
+ return hash;
33
+ }
14
34
  const getTableSchema = async ({ projectUuid, tableName, schemaName, databaseName, }) => (0, apiClient_1.lightdashApi)({
15
35
  method: 'GET',
16
36
  url: `/api/v1/projects/${projectUuid}/sqlRunner/fields?tableName=${tableName}&schemaName=${schemaName}&databaseName=${databaseName}`,
@@ -197,12 +217,22 @@ async function getWarehouseClient(options) {
197
217
  });
198
218
  globalState_1.default.debug(`> Using target ${target.type}`);
199
219
  credentials = await (0, profile_1.warehouseCredentialsFromDbtTarget)(target);
200
- warehouseClient = (0, warehouses_1.warehouseClientFromCredentials)({
201
- ...credentials,
202
- startOfWeek: (0, common_1.isWeekDay)(options.startOfWeek)
203
- ? options.startOfWeek
204
- : undefined,
205
- });
220
+ // Check if we should use cached client (e.g., for auth methods requiring user interaction)
221
+ const cacheKey = getWarehouseClientCacheKey(credentials);
222
+ if (warehouseClientCache.has(cacheKey)) {
223
+ globalState_1.default.debug(`> Reusing cached warehouse client (${credentials.type})`);
224
+ warehouseClient = warehouseClientCache.get(cacheKey);
225
+ }
226
+ else {
227
+ globalState_1.default.debug(`> Creating new warehouse client to cache (${credentials.type})`);
228
+ warehouseClient = (0, warehouses_1.warehouseClientFromCredentials)({
229
+ ...credentials,
230
+ startOfWeek: (0, common_1.isWeekDay)(options.startOfWeek)
231
+ ? options.startOfWeek
232
+ : undefined,
233
+ });
234
+ warehouseClientCache.set(cacheKey, warehouseClient);
235
+ }
206
236
  }
207
237
  return {
208
238
  warehouseClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/cli",
3
- "version": "0.2100.0",
3
+ "version": "0.2101.0",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "lightdash": "dist/index.js"
@@ -33,8 +33,8 @@
33
33
  "parse-node-version": "^2.0.0",
34
34
  "unique-names-generator": "^4.7.1",
35
35
  "uuid": "^11.0.3",
36
- "@lightdash/common": "0.2100.0",
37
- "@lightdash/warehouses": "0.2100.0"
36
+ "@lightdash/warehouses": "0.2101.0",
37
+ "@lightdash/common": "0.2101.0"
38
38
  },
39
39
  "description": "Lightdash CLI tool",
40
40
  "devDependencies": {