@lightdash/cli 1.154.0 → 1.154.2

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.
@@ -10,6 +10,14 @@ type LoginOptions = {
10
10
  interactive?: boolean;
11
11
  verbose: boolean;
12
12
  };
13
+ /**
14
+ * `LIGHTDASH_API_KEY` takes precedence over the token saved by `lightdash login`,
15
+ * so a login that saves a different token has no effect until the variable is
16
+ * unset. We warn rather than refuse, because `lightdash login --token
17
+ * $LIGHTDASH_API_KEY` is a documented CI pattern — there both tokens are the
18
+ * same and nothing is shadowed.
19
+ */
20
+ export declare const isApiKeyEnvVarShadowing: (token: string | undefined, env?: NodeJS.ProcessEnv) => boolean;
13
21
  export declare const login: (urlInput: string | undefined, options: LoginOptions) => Promise<void>;
14
22
  export {};
15
23
  //# sourceMappingURL=login.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/handlers/login.ts"],"names":[],"mappings":"AAkBA,KAAK,YAAY,GAAG;IAChB,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qCAAqC;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;CACpB,CAAC;AA4JF,eAAO,MAAM,KAAK,aACJ,MAAM,GAAG,SAAS,WACnB,YAAY,kBA2JxB,CAAC"}
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/handlers/login.ts"],"names":[],"mappings":"AAkBA,KAAK,YAAY,GAAG;IAChB,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qCAAqC;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;CACpB,CAAC;AA8CF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,UACzB,MAAM,GAAG,SAAS,QACpB,MAAM,CAAC,UAAU,KACvB,OAAqE,CAAC;AA2HzE,eAAO,MAAM,KAAK,aACJ,MAAM,GAAG,SAAS,WACnB,YAAY,kBAoKxB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.login = void 0;
3
+ exports.login = exports.isApiKeyEnvVarShadowing = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const common_1 = require("@lightdash/common");
6
6
  const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
@@ -54,6 +54,18 @@ const getLoginMethod = (options) => {
54
54
  return 'password';
55
55
  return 'oauth';
56
56
  };
57
+ /**
58
+ * `LIGHTDASH_API_KEY` takes precedence over the token saved by `lightdash login`,
59
+ * so a login that saves a different token has no effect until the variable is
60
+ * unset. We warn rather than refuse, because `lightdash login --token
61
+ * $LIGHTDASH_API_KEY` is a documented CI pattern — there both tokens are the
62
+ * same and nothing is shadowed.
63
+ */
64
+ const isApiKeyEnvVarShadowing = (token, env = process.env) => !!env.LIGHTDASH_API_KEY && env.LIGHTDASH_API_KEY !== token;
65
+ exports.isApiKeyEnvVarShadowing = isApiKeyEnvVarShadowing;
66
+ const apiKeyEnvVarWarning = (when) => styles.warning(when === 'before-login'
67
+ ? `\n⚠️ LIGHTDASH_API_KEY is set and takes precedence over the token saved by \`lightdash login\` (${config_1.configFilePath}).\n Every command will keep using LIGHTDASH_API_KEY until you unset it:\n\n ${styles.bold('unset LIGHTDASH_API_KEY')}\n`
68
+ : ` ⚠️ LIGHTDASH_API_KEY is still set and takes precedence — run ${styles.bold('unset LIGHTDASH_API_KEY')} for this login to take effect.\n`);
57
69
  const loginWithToken = async (url, token) => {
58
70
  const userInfoUrl = new url_1.URL(`/api/v1/user`, url).href;
59
71
  const response = await (0, node_fetch_1.default)(userInfoUrl, {
@@ -161,6 +173,9 @@ const login = async (urlInput, options) => {
161
173
  const cloudServer = url.replace('lightdash.com', 'lightdash.cloud');
162
174
  console.error(`\n${styles.title('Warning')}: Login URL ${styles.secondary(url)} does not match a valid cloud server, perhaps you meant ${styles.secondary(cloudServer)} ?\n`);
163
175
  }
176
+ if ((0, exports.isApiKeyEnvVarShadowing)(options.token)) {
177
+ console.error(apiKeyEnvVarWarning('before-login'));
178
+ }
164
179
  const email = options.email || process.env.LIGHTDASH_CLI_EMAIL;
165
180
  const password = process.env.LIGHTDASH_CLI_PASSWORD;
166
181
  let loginResult;
@@ -213,6 +228,9 @@ const login = async (urlInput, options) => {
213
228
  globalState_1.default.debug(`> Saved config on: ${config_1.configFilePath}`);
214
229
  await (0, config_1.setDefaultUser)(userUuid, organizationUuid);
215
230
  console.error(`\n ✅️ Login successful\n`);
231
+ if ((0, exports.isApiKeyEnvVarShadowing)(token)) {
232
+ console.error(apiKeyEnvVarWarning('after-login'));
233
+ }
216
234
  try {
217
235
  if (options.project) {
218
236
  await (0, setProject_1.setProjectCommand)(undefined, options.project);
@@ -231,7 +249,8 @@ const login = async (urlInput, options) => {
231
249
  }
232
250
  }
233
251
  }
234
- catch {
252
+ catch (e) {
253
+ globalState_1.default.debug(`> Failed to select project: ${(0, common_1.getErrorMessage)(e)}`);
235
254
  console.error('Unable to select projects, try with: ');
236
255
  console.error(`\n ${styles.bold(`⚡️ lightdash config set-project`)}\n`);
237
256
  }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=login.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.test.d.ts","sourceRoot":"","sources":["../../src/handlers/login.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const login_1 = require("./login");
4
+ describe('isApiKeyEnvVarShadowing', () => {
5
+ it('is false when LIGHTDASH_API_KEY is not set', () => {
6
+ expect((0, login_1.isApiKeyEnvVarShadowing)(undefined, {})).toBe(false);
7
+ expect((0, login_1.isApiKeyEnvVarShadowing)('ldpat_from_login', {})).toBe(false);
8
+ });
9
+ it('is true when an interactive login saves a token the env var will shadow', () => {
10
+ expect((0, login_1.isApiKeyEnvVarShadowing)(undefined, {
11
+ LIGHTDASH_API_KEY: 'ldpat_stale_env',
12
+ })).toBe(true);
13
+ });
14
+ it('is false for `lightdash login --token $LIGHTDASH_API_KEY`', () => {
15
+ expect((0, login_1.isApiKeyEnvVarShadowing)('ldpat_ci', {
16
+ LIGHTDASH_API_KEY: 'ldpat_ci',
17
+ })).toBe(false);
18
+ });
19
+ it('is true when --token is a different token to the env var', () => {
20
+ expect((0, login_1.isApiKeyEnvVarShadowing)('ldpat_explicit', {
21
+ LIGHTDASH_API_KEY: 'ldpat_stale_env',
22
+ })).toBe(true);
23
+ });
24
+ });
package/dist/index.js CHANGED
@@ -756,7 +756,9 @@ const errorHandler = (err) => {
756
756
  console.error(`\n💡 Contact your Lightdash administrator to request project creation access or if you believe this is incorrect.\n`);
757
757
  }
758
758
  else if (err.name === 'AuthorizationError') {
759
- console.error(`Looks like you did not authenticate or the personal access token expired.\n\n👀 See https://docs.lightdash.com/guides/cli/cli-authentication for help and examples`);
759
+ console.error(`Looks like you did not authenticate or the personal access token expired.${process.env.LIGHTDASH_API_KEY
760
+ ? `\n\nLIGHTDASH_API_KEY is set, and it takes precedence over the token saved by \`lightdash login\`. If you expected your saved login to be used, run ${styles.bold('unset LIGHTDASH_API_KEY')}.`
761
+ : ''}\n\n👀 See https://docs.lightdash.com/guides/cli/cli-authentication for help and examples`);
760
762
  }
761
763
  else if (!(err instanceof common_1.LightdashError)) {
762
764
  console.error(err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/cli",
3
- "version": "1.154.0",
3
+ "version": "1.154.2",
4
4
  "description": "Lightdash CLI tool",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -42,8 +42,8 @@
42
42
  "unique-names-generator": "4.7.1",
43
43
  "uuid": "11.1.1",
44
44
  "yaml": "2.8.3",
45
- "@lightdash/common": "1.154.0",
46
- "@lightdash/warehouses": "1.154.0"
45
+ "@lightdash/common": "1.154.2",
46
+ "@lightdash/warehouses": "1.154.2"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/inquirer": "8.2.4",