@vizzly/api-client 0.0.24 → 0.0.26

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.
@@ -25,7 +25,7 @@ class Api {
25
25
  execute(request) {
26
26
  return __awaiter(this, void 0, void 0, function* () {
27
27
  var _a;
28
- const authHeaders = this.auth.buildAuthHeaders();
28
+ const authHeaders = this.auth.buildAuthHeaders(request.acceptedAuthParams);
29
29
  const customHeaders = Object.assign(Object.assign({}, (request.headers || {})), (this.extraHeaders() || {}));
30
30
  const path = `${this.host}${request.path}`;
31
31
  const timedFetch = Monitor_1.Monitor.timeRequest(request.method, path, isomorphic_fetch_1.default);
@@ -40,6 +40,9 @@ class Api {
40
40
  let body = ((_a = res.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.includes('json')) ? yield res.json() : res.text();
41
41
  const queryEngineRequestId = res.headers.get('vizzly-query-engine-request-id') || '-';
42
42
  const vizzlyApiRequestId = res.headers.get('x-request-id') || '-';
43
+ if (res.status === 500) {
44
+ console.log(`[TRACING] QE; ${queryEngineRequestId} - API; ${vizzlyApiRequestId}`, authHeaders);
45
+ }
43
46
  VizzlyApiClientLogger_1.VizzlyApiClientLogger.debug(`[TRACING] QE; ${queryEngineRequestId} - API; ${vizzlyApiRequestId}`);
44
47
  return { body: body, status: res.status, headers: res.headers };
45
48
  });
@@ -1,4 +1,4 @@
1
- import { AuthParams } from '../types';
1
+ import { AuthParams, Request } from '../types';
2
2
  export declare class Authentication {
3
3
  private authParams;
4
4
  constructor(authParams: AuthParams);
@@ -11,7 +11,7 @@ export declare class Authentication {
11
11
  getDataAccessToken(): string;
12
12
  getProjectApiKey(): string;
13
13
  getProjectAccessToken(): string;
14
- buildAuthHeaders(): {
14
+ buildAuthHeaders(acceptedAuthParams: Request<{}>['acceptedAuthParams']): {
15
15
  [key: string]: string;
16
16
  };
17
17
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Authentication = void 0;
4
+ const lodash_1 = require("lodash");
4
5
  const MissingAuthParameter_1 = require("../errors/MissingAuthParameter");
5
6
  class Authentication {
6
7
  constructor(authParams) {
@@ -43,28 +44,29 @@ class Authentication {
43
44
  throw new MissingAuthParameter_1.MissingAuthParameter('projectAccessToken');
44
45
  return this.authParams.projectAccessToken;
45
46
  }
46
- buildAuthHeaders() {
47
- if (this.authParams.dashboardAccessToken) {
47
+ buildAuthHeaders(acceptedAuthParams) {
48
+ let usableAuthParams = acceptedAuthParams ? (0, lodash_1.pick)(this.authParams, acceptedAuthParams) : this.authParams;
49
+ if (usableAuthParams.dashboardAccessToken) {
48
50
  return {
49
- auth: `Bearer ${this.authParams.dashboardAccessToken}`,
51
+ auth: `Bearer ${usableAuthParams.dashboardAccessToken}`,
50
52
  };
51
53
  }
52
54
  // If a project access token has been set on the config, use that instead
53
55
  // of fetching one. This is most likely used on the managed query-engine where we
54
56
  // pass the project access token through in a request header.
55
- if (this.authParams.projectAccessToken) {
57
+ if (usableAuthParams.projectAccessToken) {
56
58
  return {
57
- auth: `Bearer ${this.authParams.projectAccessToken}`,
59
+ auth: `Bearer ${usableAuthParams.projectAccessToken}`,
58
60
  };
59
61
  }
60
- if (this.authParams.projectApiKey) {
62
+ if (usableAuthParams.projectApiKey) {
61
63
  return {
62
- auth: `Api-Key ${this.authParams.projectApiKey}`,
64
+ auth: `Api-Key ${usableAuthParams.projectApiKey}`,
63
65
  };
64
66
  }
65
- if (this.authParams.appSessionToken) {
67
+ if (usableAuthParams.appSessionToken) {
66
68
  return {
67
- auth: `Bearer ${this.authParams.appSessionToken}`,
69
+ auth: `Bearer ${usableAuthParams.appSessionToken}`,
68
70
  };
69
71
  }
70
72
  return {};
@@ -47,6 +47,7 @@ class DashboardRepository {
47
47
  throw new DashboardQuotaReached_1.DashboardQuotaReached(`Dashboard quota reached; ${JSON.stringify(builtDashboard.body)}`);
48
48
  }
49
49
  if (builtDashboard.status != 200) {
50
+ console.log();
50
51
  throw new FailedToCreateDashboard_1.FailedToCreateDashboard(`Failed to create the dashboard from POST /api/v2/dashboard. Got ${builtDashboard.status}`);
51
52
  }
52
53
  throw new FailedToCreateDashboard_1.FailedToCreateDashboard(`Unknown failure. Got status ${builtDashboard.status}`);
@@ -305,6 +305,7 @@ class VizzlyApi extends Api_1.Api {
305
305
  path: `/api/v3/project/${params.projectId}`,
306
306
  method: 'get',
307
307
  abortSignal: params.abortSignal,
308
+ acceptedAuthParams: ['projectApiKey', 'projectAccessToken'],
308
309
  };
309
310
  }
310
311
  getProjectAccessToken(params) {
package/dist/types.d.ts CHANGED
@@ -2,6 +2,7 @@ import { VizzlyQueryEngineApi } from './models/VizzlyQueryEngineApi';
2
2
  import { VizzlyApi } from './models/VizzlyApi';
3
3
  import { VizzlyAppApi } from './models/VizzlyAppApi';
4
4
  import { DashboardDefinition, DashboardFromAPI } from './types/dashboard';
5
+ import { UserFromAPI } from './types/user';
5
6
  export * from './types/dashboard';
6
7
  export * from './types/project';
7
8
  export * from './types/team';
@@ -23,6 +24,7 @@ export type Request<T> = {
23
24
  headers?: {
24
25
  [key: string]: string;
25
26
  };
27
+ acceptedAuthParams?: Array<keyof AuthParams>;
26
28
  };
27
29
  export type UpdateGlobalLibraryParams = {
28
30
  globalLibrarySessionToken: string;
@@ -299,15 +301,7 @@ export type RawOrganisation = {
299
301
  };
300
302
  };
301
303
  export type GetSelfResponse = {
302
- user: {
303
- id: string;
304
- is_email_verified: boolean;
305
- email: string;
306
- first_name: string;
307
- last_name: string;
308
- is_vizz: boolean;
309
- department: 'product_management' | 'project_management' | 'sales' | 'marketing' | 'engineering' | 'analyst' | 'c-suite';
310
- };
304
+ user: UserFromAPI;
311
305
  organisation: RawOrganisation;
312
306
  default_organisation: RawOrganisation;
313
307
  team_memberships: Array<RawTeamMember>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizzly/api-client",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "private": false,
5
5
  "license": "NONE",
6
6
  "source": "src/index.ts",