@vizzly/api-client 0.0.4 → 0.0.6

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.
@@ -0,0 +1,3 @@
1
+ export declare class FailedToCreateGlobalLibrary extends Error {
2
+ constructor(message: string);
3
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FailedToCreateGlobalLibrary = void 0;
4
+ class FailedToCreateGlobalLibrary extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = 'FailedToCreateGlobalLibrary';
8
+ }
9
+ }
10
+ exports.FailedToCreateGlobalLibrary = FailedToCreateGlobalLibrary;
@@ -0,0 +1,3 @@
1
+ export declare class FailedToDecryptDashboardBeforeClient extends Error {
2
+ constructor();
3
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FailedToDecryptDashboardBeforeClient = void 0;
4
+ class FailedToDecryptDashboardBeforeClient extends Error {
5
+ constructor() {
6
+ super(`Vizzly offers dashboard encryption to keep your dashboard configurations secure.
7
+ Please ensure your Vizzly Query Engine is still setup to manage encrypted dashboards.`);
8
+ this.name = 'FailedToDecryptDashboardBeforeClient';
9
+ }
10
+ }
11
+ exports.FailedToDecryptDashboardBeforeClient = FailedToDecryptDashboardBeforeClient;
@@ -8,3 +8,5 @@ export * from './ValidationError';
8
8
  export * from './SQLPreviewError';
9
9
  export * from './FailedToSetupProject';
10
10
  export * from './FailedToResolveDataSets';
11
+ export * from './FailedToCreateGlobalLibrary';
12
+ export * from './FailedToDecryptDashboardBeforeClient';
@@ -24,3 +24,5 @@ __exportStar(require("./ValidationError"), exports);
24
24
  __exportStar(require("./SQLPreviewError"), exports);
25
25
  __exportStar(require("./FailedToSetupProject"), exports);
26
26
  __exportStar(require("./FailedToResolveDataSets"), exports);
27
+ __exportStar(require("./FailedToCreateGlobalLibrary"), exports);
28
+ __exportStar(require("./FailedToDecryptDashboardBeforeClient"), exports);
@@ -65,7 +65,7 @@ class DashboardManager {
65
65
  const hasThingsToSaveInLibrary = libraryViewsToSave.length > 0 || !!((_b = params.definition) === null || _b === void 0 ? void 0 : _b.customFields);
66
66
  const parentGlobalLibrary = globalLibraries.find((gL) => gL.parent_global_library_id === null);
67
67
  if (!isParent && parentGlobalLibrary && hasThingsToSaveInLibrary && librariesToUpdate.length === 0) {
68
- const createdChildGlobalLibrary = yield globalLibraryRepository.createGlobalLibrary({
68
+ yield globalLibraryRepository.createGlobalLibrary({
69
69
  library: {
70
70
  views: libraryViewsToSave,
71
71
  // No concept of being protected, so only option is to save them all
@@ -74,8 +74,6 @@ class DashboardManager {
74
74
  parentGlobalLibraryId: parentGlobalLibrary.id,
75
75
  permissions: [{ scope: 'read_write' }],
76
76
  });
77
- if (createdChildGlobalLibrary.status != 200)
78
- throw new Error(`Failed to create first child library for user. ${createdChildGlobalLibrary.status}`);
79
77
  }
80
78
  const updatePromises = librariesToUpdate.map((gL) => __awaiter(this, void 0, void 0, function* () {
81
79
  var _d;
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.DashboardRepository = void 0;
13
13
  const DashboardQuotaReached_1 = require("../errors/DashboardQuotaReached");
14
14
  const FailedToCreateDashboard_1 = require("../errors/FailedToCreateDashboard");
15
+ const FailedToDecryptDashboardBeforeClient_1 = require("../errors/FailedToDecryptDashboardBeforeClient");
15
16
  const FailedToFetchDashboardAccessTokens_1 = require("../errors/FailedToFetchDashboardAccessTokens");
16
17
  const FailedToFetchDashboards_1 = require("../errors/FailedToFetchDashboards");
17
18
  const Permission_1 = require("./Permission");
@@ -71,8 +72,14 @@ class DashboardRepository {
71
72
  const vizzlyApi = this.vizzly.getVizzlyAPI();
72
73
  dashboardResponse = yield vizzlyApi.execute(vizzlyApi.buildFetchDashboardsRequest(permissions.map((p) => p.token)));
73
74
  }
74
- if (dashboardResponse.status === 200)
75
+ if (dashboardResponse.status === 200) {
76
+ dashboardResponse.body.found.forEach((dashboard) => {
77
+ if (typeof dashboard.definition === 'string') {
78
+ throw new FailedToDecryptDashboardBeforeClient_1.FailedToDecryptDashboardBeforeClient();
79
+ }
80
+ });
75
81
  return dashboardResponse.body;
82
+ }
76
83
  throw new FailedToFetchDashboards_1.FailedToFetchDashboards(`Failed to fetch dashboards. Got status code ${dashboardResponse.status}.`);
77
84
  });
78
85
  }
@@ -1,20 +1,22 @@
1
- import { GlobalLibrary, GlobalLibraryPermission, UpdateGlobalLibraryParams, nVizzlyApi } from '../types';
1
+ import { CreateGlobalLibraryParams, GlobalLibrary, GlobalLibraryPermission, UpdateGlobalLibraryParams } from '../types';
2
2
  import { Vizzly } from './Vizzly';
3
3
  export declare class GlobalLibraryRepository {
4
4
  private vizzly;
5
5
  private cachedPermissions;
6
6
  constructor(vizzly: Vizzly);
7
- createGlobalLibrary(createParams: nVizzlyApi.CreateGlobalLibraryParams): Promise<import("../types").Response<{
7
+ createGlobalLibrary(createParams: CreateGlobalLibraryParams): Promise<{
8
8
  global_library: GlobalLibrary;
9
9
  permissions: GlobalLibraryPermission[];
10
- }>>;
10
+ }>;
11
11
  fetchGlobalLibraries(): Promise<{
12
12
  found: GlobalLibrary[];
13
13
  }>;
14
14
  fetchGlobalLibraryAccessTokens(): Promise<{
15
15
  permissions: GlobalLibraryPermission[];
16
16
  }>;
17
- updateGlobalLibrary(params: UpdateGlobalLibraryParams): Promise<import("../types").Response<unknown>>;
17
+ updateGlobalLibrary(params: UpdateGlobalLibraryParams): Promise<import("../types").Response<{
18
+ global_library: GlobalLibrary;
19
+ }>>;
18
20
  getChildGlobalLibrariesByParentGlobalLibraryId(parentGlobalLibraryId: string): Promise<GlobalLibrary[]>;
19
21
  static splitParentAndChildGlobalLibraries(globalLibraries: GlobalLibrary[]): {
20
22
  childGlobalLibraries: GlobalLibrary[];
@@ -22,8 +22,13 @@ class GlobalLibraryRepository {
22
22
  createGlobalLibrary(createParams) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
24
  const vizzlyApi = this.vizzly.getVizzlyAPI();
25
- const result = yield vizzlyApi.createGlobalLibrary(createParams);
26
- return result;
25
+ if (this.vizzly.implementationStrategy.shouldPersistViaQueryEngine()) {
26
+ const vizzlyQueryEngineApi = this.vizzly.getVizzlyQueryEngineAPI();
27
+ return yield vizzlyQueryEngineApi.createGlobalLibrary(createParams);
28
+ }
29
+ else {
30
+ return yield vizzlyApi.createGlobalLibrary(createParams);
31
+ }
27
32
  });
28
33
  }
29
34
  fetchGlobalLibraries() {
@@ -53,7 +58,13 @@ class GlobalLibraryRepository {
53
58
  updateGlobalLibrary(params) {
54
59
  return __awaiter(this, void 0, void 0, function* () {
55
60
  const vizzlyApi = this.vizzly.getVizzlyAPI();
56
- return yield vizzlyApi.updateGlobalLibrary(params);
61
+ if (this.vizzly.implementationStrategy.shouldPersistViaQueryEngine()) {
62
+ const vizzlyQueryEngineApi = this.vizzly.getVizzlyQueryEngineAPI();
63
+ return yield vizzlyQueryEngineApi.updateGlobalLibrary(params);
64
+ }
65
+ else {
66
+ return yield vizzlyApi.updateGlobalLibrary(params);
67
+ }
57
68
  });
58
69
  }
59
70
  getChildGlobalLibrariesByParentGlobalLibraryId(parentGlobalLibraryId) {
@@ -1,6 +1,6 @@
1
1
  import { Api } from './Api';
2
2
  import { Authentication } from './Authentication';
3
- import { CreateDashboardParams, GlobalLibrary, GlobalLibraryPermission, Request, UpdateDashboardParams, UpdateGlobalLibraryParams } from '../types';
3
+ import { CreateDashboardParams, CreateGlobalLibraryParams, GlobalLibrary, GlobalLibraryPermission, Request, UpdateDashboardParams, UpdateGlobalLibraryParams } from '../types';
4
4
  import { nVizzlyApi } from '../types';
5
5
  export declare class VizzlyApi extends Api {
6
6
  constructor(auth: Authentication, host?: string);
@@ -8,6 +8,12 @@ export declare class VizzlyApi extends Api {
8
8
  projectAdminOverrideToken: string | undefined;
9
9
  dashboardAccessToken: string;
10
10
  }>;
11
+ fetchGlobalLibraries(params: {
12
+ globalLibraryAccessTokens: string[];
13
+ }): Promise<import("../types").Response<{
14
+ found: GlobalLibrary[];
15
+ not_found: string[];
16
+ }>>;
11
17
  buildFetchGlobalLibrariesRequest(params: {
12
18
  globalLibraryAccessTokens: string[];
13
19
  }): Request<{
@@ -25,11 +31,11 @@ export declare class VizzlyApi extends Api {
25
31
  buildCreateParentDashboardRequest(params: nVizzlyApi.CreateParentDashboardParams): Request<{}>;
26
32
  createParentGlobalLibrary(params: nVizzlyApi.CreateParentGlobalLibraryParams): Promise<import("../types").Response<unknown>>;
27
33
  buildCreateParentGlobalLibraryRequest(params: nVizzlyApi.CreateParentGlobalLibraryParams): Request<{}>;
28
- createGlobalLibrary(params: nVizzlyApi.CreateGlobalLibraryParams): Promise<import("../types").Response<{
34
+ createGlobalLibrary(params: CreateGlobalLibraryParams): Promise<{
29
35
  global_library: GlobalLibrary;
30
36
  permissions: Array<GlobalLibraryPermission>;
31
- }>>;
32
- buildCreateGlobalLibraryRequest(params: nVizzlyApi.CreateGlobalLibraryParams): Request<{}>;
37
+ }>;
38
+ buildCreateGlobalLibraryRequest(params: CreateGlobalLibraryParams): Request<{}>;
33
39
  getProjects(): Promise<import("../types").Response<unknown>>;
34
40
  buildGetProjectsRequest(): Request<{}>;
35
41
  createProjectApiKey(params: nVizzlyApi.CreateProjectApiKeyParams): Promise<import("../types").Response<unknown>>;
@@ -68,7 +74,9 @@ export declare class VizzlyApi extends Api {
68
74
  buildUpdateDashboardRequest(params: UpdateDashboardParams): Request<{}>;
69
75
  updateParentGlobalLibrary(params: nVizzlyApi.UpdateParentGlobalLibraryParams): Promise<import("../types").Response<unknown>>;
70
76
  buildUpdateParentGlobalLibraryRequest(params: nVizzlyApi.UpdateParentGlobalLibraryParams): Request<{}>;
71
- updateGlobalLibrary(params: UpdateGlobalLibraryParams): Promise<import("../types").Response<unknown>>;
77
+ updateGlobalLibrary(params: UpdateGlobalLibraryParams): Promise<import("../types").Response<{
78
+ global_library: GlobalLibrary;
79
+ }>>;
72
80
  buildUpdateGlobalLibraryRequest(params: UpdateGlobalLibraryParams): Request<{}>;
73
81
  updateProjectApiKey(params: nVizzlyApi.UpdateProjectApiKeyParams): Promise<import("../types").Response<unknown>>;
74
82
  buildUpdateProjectApiKeyRequest(params: nVizzlyApi.UpdateProjectApiKeyParams): Request<{}>;
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.VizzlyApi = void 0;
13
13
  const Api_1 = require("./Api");
14
+ const errors_1 = require("../errors");
14
15
  class VizzlyApi extends Api_1.Api {
15
16
  constructor(auth, host = 'https://api.vizzly.co') {
16
17
  super(auth, host);
@@ -25,6 +26,11 @@ class VizzlyApi extends Api_1.Api {
25
26
  },
26
27
  };
27
28
  }
29
+ fetchGlobalLibraries(params) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ return yield this.execute(this.buildFetchGlobalLibrariesRequest(params));
32
+ });
33
+ }
28
34
  buildFetchGlobalLibrariesRequest(params) {
29
35
  return {
30
36
  path: '/api/v2/multi-get-global-library',
@@ -98,7 +104,10 @@ class VizzlyApi extends Api_1.Api {
98
104
  }
99
105
  createGlobalLibrary(params) {
100
106
  return __awaiter(this, void 0, void 0, function* () {
101
- return yield this.execute(this.buildCreateGlobalLibraryRequest(params));
107
+ const result = yield this.execute(this.buildCreateGlobalLibraryRequest(params));
108
+ if (result.status === 200)
109
+ return result.body;
110
+ throw new errors_1.FailedToCreateGlobalLibrary('Failed to create global library');
102
111
  });
103
112
  }
104
113
  buildCreateGlobalLibraryRequest(params) {
@@ -1,6 +1,6 @@
1
1
  import { Api } from './Api';
2
2
  import { Authentication } from './Authentication';
3
- import { nVizzlyQueryEngine, Request, extraHeaders, CreateDashboardParams, UpdateDashboardParams } from '../types';
3
+ import { nVizzlyQueryEngine, Request, extraHeaders, CreateDashboardParams, UpdateDashboardParams, UpdateGlobalLibraryParams, GlobalLibrary, CreateGlobalLibraryParams, GlobalLibraryPermission } from '../types';
4
4
  export declare class VizzlyQueryEngineApi extends Api {
5
5
  constructor(auth: Authentication, host: string, extraHeaders?: extraHeaders);
6
6
  buildCreateDashboardRequest(params: CreateDashboardParams): Request<CreateDashboardParams & {
@@ -41,6 +41,15 @@ export declare class VizzlyQueryEngineApi extends Api {
41
41
  buildSignInWithEmailAndPasswordRequest(params: nVizzlyQueryEngine.SignInWithEmailAndPasswordParams): Request<{}>;
42
42
  status(): Promise<import("../types").Response<unknown>>;
43
43
  buildStatusRequest(): Request<{}>;
44
+ createGlobalLibrary(params: CreateGlobalLibraryParams): Promise<{
45
+ global_library: GlobalLibrary;
46
+ permissions: Array<GlobalLibraryPermission>;
47
+ }>;
48
+ buildCreateGlobalLibraryRequest(params: CreateGlobalLibraryParams): Request<{}>;
49
+ updateGlobalLibrary(params: UpdateGlobalLibraryParams): Promise<import("../types").Response<{
50
+ global_library: GlobalLibrary;
51
+ }>>;
52
+ buildUpdateGlobalLibraryRequest(params: UpdateGlobalLibraryParams): Request<{}>;
44
53
  updateDashboard(params: UpdateDashboardParams): Promise<import("../types").Response<unknown>>;
45
54
  buildUpdateDashboardRequest(params: UpdateDashboardParams): Request<{}>;
46
55
  updateQueryEngineUser(params: nVizzlyQueryEngine.UpdateQueryEngineUserParams): Promise<import("../types").Response<unknown>>;
@@ -14,6 +14,7 @@ const Api_1 = require("./Api");
14
14
  const SQLPreviewError_1 = require("../errors/SQLPreviewError");
15
15
  const FailedToResolveDataSets_1 = require("../errors/FailedToResolveDataSets");
16
16
  const FailedToSetupProject_1 = require("../errors/FailedToSetupProject");
17
+ const errors_1 = require("../errors");
17
18
  class VizzlyQueryEngineApi extends Api_1.Api {
18
19
  constructor(auth, host, extraHeaders) {
19
20
  super(auth, host, extraHeaders);
@@ -260,6 +261,42 @@ class VizzlyQueryEngineApi extends Api_1.Api {
260
261
  body: {},
261
262
  };
262
263
  }
264
+ createGlobalLibrary(params) {
265
+ return __awaiter(this, void 0, void 0, function* () {
266
+ const result = yield this.execute(this.buildCreateGlobalLibraryRequest(params));
267
+ if (result.status === 200)
268
+ return result.body;
269
+ throw new errors_1.FailedToCreateGlobalLibrary(`Failed to create a global library. Got status ${result.status}`);
270
+ });
271
+ }
272
+ buildCreateGlobalLibraryRequest(params) {
273
+ return {
274
+ path: '/api/v1/global-library',
275
+ method: 'post',
276
+ body: {
277
+ dashboardAccessToken: this.auth.getDashboardAccessToken(),
278
+ parentGlobalLibraryId: params.parentGlobalLibraryId,
279
+ library: params.library,
280
+ permissions: params.permissions,
281
+ },
282
+ };
283
+ }
284
+ updateGlobalLibrary(params) {
285
+ return __awaiter(this, void 0, void 0, function* () {
286
+ return yield this.execute(this.buildUpdateGlobalLibraryRequest(params));
287
+ });
288
+ }
289
+ buildUpdateGlobalLibraryRequest(params) {
290
+ return {
291
+ path: '/api/v1/global-library',
292
+ method: 'put',
293
+ body: {
294
+ globalLibrarySessionToken: params.globalLibrarySessionToken,
295
+ deleted: params.deleted,
296
+ library: params.library,
297
+ },
298
+ };
299
+ }
263
300
  updateDashboard(params) {
264
301
  return __awaiter(this, void 0, void 0, function* () {
265
302
  return yield this.execute(this.buildUpdateDashboardRequest(params));
package/dist/types.d.ts CHANGED
@@ -23,6 +23,14 @@ export type UpdateGlobalLibraryParams = {
23
23
  deleted?: boolean;
24
24
  library: GlobalLibrary['library'] | string;
25
25
  };
26
+ export type CreateGlobalLibraryParams = {
27
+ parentGlobalLibraryId: string;
28
+ library: GlobalLibrary['library'] | string;
29
+ permissions: Array<{
30
+ user_reference?: string;
31
+ scope: 'read' | 'read_write';
32
+ }>;
33
+ };
26
34
  export type CreateDashboardParams = {
27
35
  definition: DashboardDefinition | string;
28
36
  /** @deprecated - use `metadata` instead */
@@ -111,14 +119,6 @@ export declare namespace nVizzlyApi {
111
119
  definition: any;
112
120
  projectId: string;
113
121
  };
114
- type CreateGlobalLibraryParams = {
115
- parentGlobalLibraryId: string;
116
- library: any;
117
- permissions: Array<{
118
- user_reference?: string;
119
- scope: 'read' | 'read_write';
120
- }>;
121
- };
122
122
  type CreateParentGlobalLibraryParams = {
123
123
  library: any;
124
124
  projectId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizzly/api-client",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "private": false,
5
5
  "license": "NONE",
6
6
  "source": "src/index.ts",