@lightdash/cli 2.603.1 → 2.603.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.
@@ -1 +1 @@
1
- {"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../src/handlers/preview.ts"],"names":[],"mappings":"AACA,OAAO,EACH,+BAA+B,EAQlC,MAAM,mBAAmB,CAAC;AAoB3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAalD,KAAK,qBAAqB,GAAG,iBAAiB,GAAG;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;IACtB,kBAAkB,EAAE,+BAA+B,CAAC;IACpD,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,wBAAwB,EAAE,OAAO,CAAC;IAClC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAoBF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,CAAC;IACrC,wBAAwB,EAAE,OAAO,CAAC;IAClC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAoBF,KAAK,yBAAyB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;CACpB,CAAC;AA2GF,eAAO,MAAM,cAAc,oBACN,qBAAqB,KACvC,OAAO,CAAC,IAAI,CAoTd,CAAC;AAkKF,eAAO,MAAM,mBAAmB,oBACX,qBAAqB,KACvC,OAAO,CAAC,IAAI,CA2Qd,CAAC;AAEF,eAAO,MAAM,kBAAkB,YAClB,yBAAyB,KACnC,OAAO,CAAC,IAAI,CA2Cd,CAAC"}
@@ -320,6 +320,45 @@ const previewHandler = async (originalOptions) => {
320
320
  await cleanupProject(executionId, project.projectUuid, previewStartTime);
321
321
  };
322
322
  exports.previewHandler = previewHandler;
323
+ const withCurrentSettings = (credentials, current) => {
324
+ if (!current || current.type !== credentials.type)
325
+ return credentials;
326
+ const defined = Object.fromEntries(Object.entries(credentials).filter(([, value]) => value !== undefined));
327
+ return { ...current, ...defined };
328
+ };
329
+ const resolveSourceConnection = async (project, sourceOption, upstreamProjectUuid) => {
330
+ if (project.connectionRoute !== 'multi') {
331
+ return { sourceUuid: undefined, connection: { kind: 'primary' } };
332
+ }
333
+ const sourceUuid = await (0, sourceSelection_1.resolveProjectSourceUuid)(project.projectUuid, sourceOption, upstreamProjectUuid);
334
+ if (!sourceUuid)
335
+ return { sourceUuid, connection: { kind: 'primary' } };
336
+ let bindings;
337
+ try {
338
+ bindings = await (0, apiClient_1.lightdashApi)({
339
+ method: 'GET',
340
+ url: `/api/v1/projects/${project.projectUuid}/warehouse-connections/dbt-sources/bindings`,
341
+ body: undefined,
342
+ });
343
+ }
344
+ catch {
345
+ return { sourceUuid, connection: { kind: 'unknown', sourceUuid } };
346
+ }
347
+ const boundConnectionUuid = bindings.sources.find((item) => item.projectDbtSourceUuid === sourceUuid)?.warehouseConnectionUuid ?? null;
348
+ if (boundConnectionUuid === null) {
349
+ return { sourceUuid, connection: { kind: 'primary' } };
350
+ }
351
+ const boundConnection = bindings.connections.find((item) => item.warehouseConnectionUuid === boundConnectionUuid);
352
+ if (!boundConnection) {
353
+ return { sourceUuid, connection: { kind: 'unknown', sourceUuid } };
354
+ }
355
+ return {
356
+ sourceUuid,
357
+ connection: boundConnection.isOriginal
358
+ ? { kind: 'primary' }
359
+ : { kind: 'extra', connection: boundConnection },
360
+ };
361
+ };
323
362
  // Credentials resolved locally (AWS SSO, Snowflake SSO) expire, so a re-run
324
363
  // with the same name pushes freshly resolved ones into the existing preview.
325
364
  const refreshPreviewWarehouseCredentials = async (projectUuid, options, upstreamProjectUuid) => {
@@ -346,43 +385,26 @@ const refreshPreviewWarehouseCredentials = async (projectUuid, options, upstream
346
385
  return;
347
386
  }
348
387
  const project = await (0, refresh_1.getProject)(projectUuid);
349
- let connection;
350
- if (project.connectionRoute === 'multi') {
351
- const sourceUuid = await (0, sourceSelection_1.resolveProjectSourceUuid)(projectUuid, options.source, upstreamProjectUuid);
352
- if (sourceUuid) {
353
- const keepStoredCredentials = () => console.error(styles.warning(`Could not read which connection source ${options.source ?? sourceUuid} uses; keeping the warehouse credentials already stored on the preview.`));
354
- let bindings;
355
- try {
356
- bindings = await (0, apiClient_1.lightdashApi)({
357
- method: 'GET',
358
- url: `/api/v1/projects/${projectUuid}/warehouse-connections/dbt-sources/bindings`,
359
- body: undefined,
360
- });
361
- }
362
- catch {
363
- keepStoredCredentials();
364
- return;
365
- }
366
- const boundConnectionUuid = bindings.sources.find((item) => item.projectDbtSourceUuid === sourceUuid)?.warehouseConnectionUuid ?? null;
367
- if (boundConnectionUuid !== null) {
368
- const boundConnection = bindings.connections.find((item) => item.warehouseConnectionUuid === boundConnectionUuid);
369
- if (!boundConnection) {
370
- keepStoredCredentials();
371
- return;
372
- }
373
- connection = boundConnection.isOriginal
374
- ? undefined
375
- : boundConnection;
376
- }
377
- }
388
+ const { connection: sourceConnection } = await resolveSourceConnection(project, options.source, upstreamProjectUuid);
389
+ if (sourceConnection.kind === 'unknown') {
390
+ console.error(styles.warning(`Could not read which connection source ${options.source ?? sourceConnection.sourceUuid} uses; keeping the warehouse credentials already stored on the preview.`));
391
+ return;
378
392
  }
393
+ const connection = sourceConnection.kind === 'extra'
394
+ ? sourceConnection.connection
395
+ : undefined;
379
396
  const spinner = globalState_1.default.startSpinner(connection
380
397
  ? ` Refreshing warehouse credentials for "${connection.name}"...`
381
398
  : ' Refreshing warehouse credentials...');
382
399
  try {
383
400
  if (connection) {
401
+ const current = await (0, apiClient_1.lightdashApi)({
402
+ method: 'GET',
403
+ url: `/api/v1/projects/${projectUuid}/warehouse-connections/${connection.warehouseConnectionUuid}`,
404
+ body: undefined,
405
+ });
384
406
  const body = {
385
- warehouseConnection: loaded.credentials,
407
+ warehouseConnection: withCurrentSettings(loaded.credentials, current.warehouseConnection),
386
408
  };
387
409
  await (0, apiClient_1.lightdashApi)({
388
410
  method: 'PATCH',
@@ -447,7 +469,10 @@ const startPreviewHandler = async (originalOptions) => {
447
469
  warehouseCredentials: projectTypeConfig.warehouseCredentials,
448
470
  }, config.context?.project);
449
471
  // Update
450
- const previewSettings = await (0, timestampConversion_1.getProjectDeploySettings)(options.disableTimestampConversion, previewProject.projectUuid, undefined);
472
+ const previewSource = await resolveSourceConnection(await (0, refresh_1.getProject)(previewProject.projectUuid), options.source, config.context?.project);
473
+ const previewSettings = await (0, timestampConversion_1.getProjectDeploySettings)(options.disableTimestampConversion, previewProject.projectUuid, previewSource.connection.kind === 'unknown'
474
+ ? undefined
475
+ : previewSource.sourceUuid);
451
476
  options.disableTimestampConversion =
452
477
  previewSettings.disableTimestampConversion;
453
478
  const { explores, isProjectComplete } = await (0, compile_1.compileProject)(options);
@@ -478,14 +503,26 @@ const startPreviewHandler = async (originalOptions) => {
478
503
  else {
479
504
  console.error(`\n${styles.success('✔')} Copying charts and dashboards from "${config.context?.projectName || 'source project'}"`);
480
505
  }
506
+ const upstreamProjectUuid = config.context?.project;
507
+ const upstreamSourceConnection = upstreamProjectUuid &&
508
+ projectTypeConfig.warehouseCredentials !== false &&
509
+ (0, warehouseConnection_1.getWarehouseCredentialsSource)({
510
+ ...options,
511
+ warehouseCredentials: projectTypeConfig.warehouseCredentials,
512
+ }).source === 'profiles'
513
+ ? (await resolveSourceConnection(await (0, refresh_1.getProject)(upstreamProjectUuid), options.source, upstreamProjectUuid)).connection
514
+ : { kind: 'primary' };
515
+ const keepsUpstreamPrimary = upstreamSourceConnection.kind !== 'primary';
481
516
  // Create
482
517
  const results = await (0, createProject_1.createProject)({
483
518
  ...options,
484
519
  name: projectName,
485
520
  type: common_1.ProjectType.PREVIEW,
486
- upstreamProjectUuid: config.context?.project,
521
+ upstreamProjectUuid,
487
522
  copyContent: !options.skipCopyContent,
488
- warehouseCredentials: projectTypeConfig.warehouseCredentials,
523
+ warehouseCredentials: keepsUpstreamPrimary
524
+ ? false
525
+ : projectTypeConfig.warehouseCredentials,
489
526
  expiresIn: options.expiresIn
490
527
  ? parseInt(options.expiresIn, 10)
491
528
  : undefined,
@@ -510,7 +547,20 @@ const startPreviewHandler = async (originalOptions) => {
510
547
  name: options.name,
511
548
  },
512
549
  });
513
- if (options.disableTimestampConversion === undefined) {
550
+ if (keepsUpstreamPrimary) {
551
+ await refreshPreviewWarehouseCredentials(project.projectUuid, {
552
+ ...options,
553
+ warehouseCredentials: projectTypeConfig.warehouseCredentials,
554
+ }, upstreamProjectUuid);
555
+ }
556
+ const previewSource = upstreamProjectUuid
557
+ ? await resolveSourceConnection(await (0, refresh_1.getProject)(project.projectUuid), options.source, upstreamProjectUuid)
558
+ : undefined;
559
+ if (options.disableTimestampConversion === undefined &&
560
+ previewSource?.connection.kind === 'extra') {
561
+ options.disableTimestampConversion = (await (0, timestampConversion_1.getProjectDeploySettings)(undefined, project.projectUuid, previewSource.sourceUuid)).disableTimestampConversion;
562
+ }
563
+ else if (options.disableTimestampConversion === undefined) {
514
564
  options.disableTimestampConversion =
515
565
  (0, timestampConversion_1.getDisableTimestampConversionFromProject)(project.warehouseConnection);
516
566
  globalState_1.default.debug(`> Using disable-timestamp-conversion=${String(options.disableTimestampConversion ?? false)} from preview project settings`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/cli",
3
- "version": "2.603.1",
3
+ "version": "2.603.2",
4
4
  "description": "Lightdash CLI tool",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -22,8 +22,8 @@
22
22
  "@actions/core": "1.11.1",
23
23
  "@aws-sdk/credential-providers": "3.995.0",
24
24
  "@casl/ability": "6.8.0",
25
- "@lightdash/common": "2.603.1",
26
- "@lightdash/warehouses": "2.603.1",
25
+ "@lightdash/common": "2.603.2",
26
+ "@lightdash/warehouses": "2.603.2",
27
27
  "@sidvind/better-ajv-errors": "7.0.0",
28
28
  "@types/columnify": "1.5.1",
29
29
  "ajv": "8.18.0",