@vizzly/api-client 0.0.38 → 0.0.41

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 PermissionDenied extends Error {
2
+ constructor(message: string);
3
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PermissionDenied = void 0;
4
+ class PermissionDenied extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ }
8
+ }
9
+ exports.PermissionDenied = PermissionDenied;
@@ -21,3 +21,4 @@ export * from './FailedToCreateQueryEngineUser';
21
21
  export * from './FailedToFetchQueryEngineUser';
22
22
  export * from './ProjectEncryptedSecretAlreadySaved';
23
23
  export * from './FailedToSaveProjectEncryptedEncryptionSecret';
24
+ export * from './PermissionDenied';
@@ -37,3 +37,4 @@ __exportStar(require("./FailedToCreateQueryEngineUser"), exports);
37
37
  __exportStar(require("./FailedToFetchQueryEngineUser"), exports);
38
38
  __exportStar(require("./ProjectEncryptedSecretAlreadySaved"), exports);
39
39
  __exportStar(require("./FailedToSaveProjectEncryptedEncryptionSecret"), exports);
40
+ __exportStar(require("./PermissionDenied"), exports);
@@ -25,7 +25,7 @@ class DashboardManager {
25
25
  }
26
26
  update(params) {
27
27
  return __awaiter(this, void 0, void 0, function* () {
28
- var _a, _b, _c;
28
+ var _a;
29
29
  const dashboardRepository = this.vizzly.getDashboardRepository();
30
30
  const globalLibraryRepository = this.vizzly.getGlobalLibraryRepository();
31
31
  const [{ global_libraries: globalLibraries, permissions: globalLibraryPermissions }, { dashboards, permissions: dashboardPermissions },] = yield Promise.all([
@@ -60,22 +60,22 @@ class DashboardManager {
60
60
  const librariesToUpdate = dashboardToUpdate.parent_dashboard_id === null ? parentGlobalLibraries : childGlobalLibraries;
61
61
  // If it's not a parent dashboard, and there are views or custom fields to save, but there are no libraries
62
62
  // then create one first.
63
- const isParent = dashboardToUpdate.parent_dashboard_id === null;
64
- const hasThingsToSaveInLibrary = libraryViewsToSave.length > 0 || !!((_b = params.definition) === null || _b === void 0 ? void 0 : _b.customFields);
65
- const parentGlobalLibrary = globalLibraries.find((gL) => gL.parent_global_library_id === null);
66
- if (!isParent && parentGlobalLibrary && hasThingsToSaveInLibrary && librariesToUpdate.length === 0) {
67
- yield globalLibraryRepository.createGlobalLibrary({
68
- library: {
69
- views: libraryViewsToSave,
70
- // No concept of being protected, so only option is to save them all
71
- customFields: ((_c = params.definition) === null || _c === void 0 ? void 0 : _c.customFields) || {},
72
- },
73
- parentGlobalLibraryId: parentGlobalLibrary.id,
74
- permissions: [{ scope: 'read_write' }],
75
- });
76
- }
63
+ // const isParent = dashboardToUpdate.parent_dashboard_id === null;
64
+ // const hasThingsToSaveInLibrary = libraryViewsToSave.length > 0 || !!params.definition?.customFields;
65
+ // const parentGlobalLibrary = globalLibraries.find((gL) => gL.parent_global_library_id === null);
66
+ // if (!isParent && parentGlobalLibrary && hasThingsToSaveInLibrary && librariesToUpdate.length === 0) {
67
+ // await globalLibraryRepository.createGlobalLibrary({
68
+ // library: {
69
+ // views: libraryViewsToSave,
70
+ // // No concept of being protected, so only option is to save them all
71
+ // customFields: params.definition?.customFields || {},
72
+ // },
73
+ // parentGlobalLibraryId: parentGlobalLibrary!.id,
74
+ // permissions: [{ scope: 'read_write' }],
75
+ // });
76
+ // }
77
77
  const updatePromises = librariesToUpdate.map((gL) => __awaiter(this, void 0, void 0, function* () {
78
- var _d;
78
+ var _b;
79
79
  const writePermission = globalLibraryPermissions.find((permission) => permission.globalLibraryId === gL.id && permission.scope === 'read_write');
80
80
  if (!writePermission)
81
81
  VizzlyApiClientLogger_1.VizzlyApiClientLogger.error('No write permission found.');
@@ -85,7 +85,7 @@ class DashboardManager {
85
85
  library: {
86
86
  views: libraryViewsToSave,
87
87
  // No concept of being protected, so only option is to save them all
88
- customFields: ((_d = params.definition) === null || _d === void 0 ? void 0 : _d.customFields) || {},
88
+ customFields: ((_b = params.definition) === null || _b === void 0 ? void 0 : _b.customFields) || {},
89
89
  },
90
90
  });
91
91
  }
@@ -5,8 +5,8 @@ export declare class GlobalLibraryManager {
5
5
  private vizzly;
6
6
  constructor(vizzly: Vizzly);
7
7
  create(params: RequestParams<CreateGlobalLibraryParams>): Promise<{
8
- permissions: import("../types").GlobalLibraryPermission[];
9
8
  global_library: GlobalLibrary;
9
+ permissions: import("../types").GlobalLibraryPermission[];
10
10
  }>;
11
11
  update(params: RequestParams<UpdateGlobalLibraryParams & {
12
12
  globalLibraryId: string;
@@ -5,8 +5,8 @@ export declare class GlobalLibraryRepository {
5
5
  private repo;
6
6
  constructor(vizzly: Vizzly);
7
7
  createGlobalLibrary(createParams: CreateGlobalLibraryParams): Promise<{
8
- permissions: GlobalLibraryPermission[];
9
8
  global_library: GlobalLibrary;
9
+ permissions: GlobalLibraryPermission[];
10
10
  }>;
11
11
  fetchGlobalLibraries(params?: RequestParams): Promise<{
12
12
  global_libraries: GlobalLibrary[];
@@ -15,6 +15,7 @@ const Permission_1 = require("./Permission");
15
15
  const FailedToFetchGlobalLibraryAccessTokens_1 = require("../errors/FailedToFetchGlobalLibraryAccessTokens");
16
16
  const Repository_1 = require("./Repository");
17
17
  const FailedToUpdateGlobalLibrary_1 = require("../errors/FailedToUpdateGlobalLibrary");
18
+ const errors_1 = require("../errors");
18
19
  class GlobalLibraryRepository {
19
20
  constructor(vizzly) {
20
21
  this.vizzly = vizzly;
@@ -31,15 +32,49 @@ class GlobalLibraryRepository {
31
32
  else {
32
33
  globalLibrary = yield vizzlyApi.createGlobalLibrary(createParams);
33
34
  }
34
- globalLibrary.global_library = GlobalLibraryRepository.upcast(globalLibrary.global_library);
35
- this.repo.addItem(globalLibrary.global_library, globalLibrary.permissions);
36
- return globalLibrary;
35
+ const upcastedLibrary = GlobalLibraryRepository.upcast(globalLibrary.global_library);
36
+ const formattedPermissions = globalLibrary.permissions.map(Permission_1.Permission.formatGlobalLibraryPermission);
37
+ this.repo.addItem(upcastedLibrary, formattedPermissions);
38
+ return {
39
+ global_library: upcastedLibrary,
40
+ permissions: formattedPermissions,
41
+ };
37
42
  });
38
43
  }
39
44
  fetchGlobalLibraries(params) {
40
45
  return __awaiter(this, void 0, void 0, function* () {
41
46
  // Now, we fetch the libraries and the access tokens from the access call.
42
- return yield this.fetchGlobalLibraryAccessTokens(params);
47
+ let libs = yield this.fetchGlobalLibraryAccessTokens(params);
48
+ // Find the parent library.
49
+ const parentLibrary = libs.global_libraries.find((l) => l.parent_global_library_id === null);
50
+ // Find any child library.
51
+ const childLibrary = libs.global_libraries.find((l) => l.parent_global_library_id != null);
52
+ // If libraries have been returned, but no child library exists
53
+ // then create the first and only one.
54
+ if (libs.global_libraries.length > 0 && parentLibrary && !childLibrary) {
55
+ try {
56
+ const created = yield this.createGlobalLibrary({
57
+ parentGlobalLibraryId: parentLibrary.id,
58
+ library: {
59
+ customFields: {},
60
+ views: [],
61
+ },
62
+ permissions: [{ scope: 'read_write' }],
63
+ });
64
+ libs = {
65
+ global_libraries: [...libs.global_libraries, created.global_library],
66
+ permissions: [...libs.permissions, ...created.permissions],
67
+ };
68
+ }
69
+ catch (e) {
70
+ // Only throw if the error is not a permission denied. A permission denied
71
+ // is expected if the user only has `read` access on their identity JWT token.
72
+ if (!(e instanceof errors_1.PermissionDenied)) {
73
+ throw e;
74
+ }
75
+ }
76
+ }
77
+ return libs;
43
78
  });
44
79
  }
45
80
  fetchGlobalLibraryAccessTokens(params) {
@@ -56,7 +91,7 @@ class GlobalLibraryRepository {
56
91
  }
57
92
  if (accessTokens.status === 200) {
58
93
  const formattedPermissions = accessTokens.body.permissions.map(Permission_1.Permission.formatGlobalLibraryPermission);
59
- this.repo.initRepo(accessTokens.body.global_libraries.map(GlobalLibraryRepository.upcast), formattedPermissions);
94
+ this.repo.initRepo(accessTokens.body.global_libraries, formattedPermissions);
60
95
  }
61
96
  else {
62
97
  throw new FailedToFetchGlobalLibraryAccessTokens_1.FailedToFetchGlobalLibraryAccessTokens('Failed to load access tokens for the global library.');
@@ -1,6 +1,6 @@
1
1
  import { Api } from './Api';
2
2
  import { Authentication } from './Authentication';
3
- import { CreateDashboardParams, CreateGlobalLibraryParams, GlobalLibrary, GlobalLibraryPermission, GlobalLibraryPermissionFromAPI, QueryEngineUserFromAPI, Request, RequestParams, TeamMemberFromAPI, UpdateDashboardParams, UpdateDashboardResponseBody, UpdateGlobalLibraryParams } from '../types';
3
+ import { CreateDashboardParams, CreateGlobalLibraryParams, GlobalLibrary, GlobalLibraryPermissionFromAPI, PersistedReport, QueryEngineUserFromAPI, Request, RequestParams, TeamMemberFromAPI, UpdateDashboardParams, UpdateDashboardResponseBody, UpdateGlobalLibraryParams } from '../types';
4
4
  import { nVizzlyApi } from '../types';
5
5
  import { ProjectFromAPI } from '../types/project';
6
6
  export declare class VizzlyApi extends Api {
@@ -40,7 +40,7 @@ export declare class VizzlyApi extends Api {
40
40
  buildCreateParentGlobalLibraryRequest(params: RequestParams<nVizzlyApi.CreateParentGlobalLibraryParams>): Request<{}>;
41
41
  createGlobalLibrary(params: RequestParams<CreateGlobalLibraryParams>): Promise<{
42
42
  global_library: GlobalLibrary;
43
- permissions: Array<GlobalLibraryPermission>;
43
+ permissions: Array<GlobalLibraryPermissionFromAPI>;
44
44
  }>;
45
45
  buildCreateGlobalLibraryRequest(params: RequestParams<CreateGlobalLibraryParams>): Request<{}>;
46
46
  getProjects(params?: RequestParams): Promise<{
@@ -93,7 +93,13 @@ export declare class VizzlyApi extends Api {
93
93
  buildSaveConnectionRequest(params: RequestParams<nVizzlyApi.SaveConnectionParams>): Request<{}>;
94
94
  saveEncryptedProjectEncryptionSecret(params: RequestParams<nVizzlyApi.SaveEncryptedProjectEncryptionSecretParams>): Promise<boolean>;
95
95
  buildSaveEncryptedProjectEncryptionSecretRequest(params: RequestParams<nVizzlyApi.SaveEncryptedProjectEncryptionSecretParams>): Request<{}>;
96
- saveScheduledReport(params: RequestParams<nVizzlyApi.SaveScheduledReportParams>): Promise<import("../types").Response<unknown>>;
96
+ getScheduledReports(params: RequestParams<nVizzlyApi.GetScheduledReportParams>): Promise<import("../types").Response<{
97
+ reports: Array<PersistedReport>;
98
+ }>>;
99
+ buildGetScheduledReports(params: RequestParams<nVizzlyApi.GetScheduledReportParams>): Request<{}>;
100
+ saveScheduledReport(params: RequestParams<nVizzlyApi.SaveScheduledReportParams>): Promise<import("../types").Response<{
101
+ report: PersistedReport;
102
+ }>>;
97
103
  buildSaveScheduledReportRequest(params: RequestParams<nVizzlyApi.SaveScheduledReportParams>): Request<{}>;
98
104
  updateDashboard(params: RequestParams<UpdateDashboardParams>): Promise<import("../types").Response<UpdateDashboardResponseBody>>;
99
105
  buildUpdateDashboardRequest(params: RequestParams<UpdateDashboardParams>): Request<{}>;
@@ -126,7 +126,9 @@ class VizzlyApi extends Api_1.Api {
126
126
  const result = yield this.execute(this.buildCreateGlobalLibraryRequest(params));
127
127
  if (result.status === 200)
128
128
  return result.body;
129
- throw new errors_1.FailedToCreateGlobalLibrary('Failed to create global library');
129
+ if (result.status === 403)
130
+ throw new errors_1.PermissionDenied('Permission denied when creating a global library via the Vizzly API.');
131
+ throw new errors_1.FailedToCreateGlobalLibrary(`Failed to create global library, got status ${result.status}`);
130
132
  });
131
133
  }
132
134
  buildCreateGlobalLibraryRequest(params) {
@@ -420,6 +422,21 @@ class VizzlyApi extends Api_1.Api {
420
422
  acceptedAuthParams: ['projectApiKey', 'projectAccessToken'],
421
423
  };
422
424
  }
425
+ getScheduledReports(params) {
426
+ return __awaiter(this, void 0, void 0, function* () {
427
+ return yield this.execute(this.buildGetScheduledReports(params));
428
+ });
429
+ }
430
+ buildGetScheduledReports(params) {
431
+ return {
432
+ path: '/api/scheduled-report/collect',
433
+ method: 'post',
434
+ body: {
435
+ dashboardAccessToken: params.dashboardAccessToken,
436
+ },
437
+ abortSignal: params.abortSignal,
438
+ };
439
+ }
423
440
  saveScheduledReport(params) {
424
441
  return __awaiter(this, void 0, void 0, function* () {
425
442
  return yield this.execute(this.buildSaveScheduledReportRequest(params));
@@ -431,7 +448,7 @@ class VizzlyApi extends Api_1.Api {
431
448
  method: 'post',
432
449
  body: {
433
450
  cronSchedule: params.cronSchedule,
434
- dashboardAccessToken: this.auth.getDashboardAccessToken(),
451
+ dashboardAccessToken: params.dashboardAccessToken,
435
452
  scheduledReportId: params.scheduledReportId,
436
453
  },
437
454
  abortSignal: params.abortSignal,
@@ -41,6 +41,19 @@ export declare class VizzlyAppApi extends Api {
41
41
  buildStartSignInRequest(params: nVizzlyAppApi.StartSignInParams): Request<{}>;
42
42
  completeSignIn(params: nVizzlyAppApi.CompleteSignInParams): Promise<import("../types").Response<unknown>>;
43
43
  buildCompleteSignInRequest(params: nVizzlyAppApi.CompleteSignInParams): Request<{}>;
44
+ searchUserDashboards(params: nVizzlyAppApi.SearchUserDashboardsParams): Promise<import("../types").Response<{
45
+ search_results: Array<{
46
+ id: string;
47
+ parent_dashboard_id: string | null;
48
+ parent_dashboard_name: string | null;
49
+ scope: 'read' | 'read_write';
50
+ user_reference: string;
51
+ permission_created_at: string;
52
+ dashboard_created_at: string;
53
+ dashboard_updated_at: string;
54
+ }>;
55
+ }>>;
56
+ buildSearchUserDashboardsRequest(params: nVizzlyAppApi.SearchUserDashboardsParams): Request<{}>;
44
57
  signUp(params: nVizzlyAppApi.SignUpParams): Promise<import("../types").Response<unknown>>;
45
58
  buildSignUpRequest(params: nVizzlyAppApi.SignUpParams): Request<{}>;
46
59
  switchOrganisation(params: nVizzlyAppApi.SwitchOrganisationParams): Promise<import("../types").Response<unknown>>;
@@ -266,6 +266,17 @@ class VizzlyAppApi extends Api_1.Api {
266
266
  },
267
267
  };
268
268
  }
269
+ searchUserDashboards(params) {
270
+ return __awaiter(this, void 0, void 0, function* () {
271
+ return yield this.execute(this.buildSearchUserDashboardsRequest(params));
272
+ });
273
+ }
274
+ buildSearchUserDashboardsRequest(params) {
275
+ return {
276
+ path: `/api/v2/project/${params.projectId}/search-user-dashboards?user_reference=${params.userReference}`,
277
+ method: 'get',
278
+ };
279
+ }
269
280
  signUp(params) {
270
281
  return __awaiter(this, void 0, void 0, function* () {
271
282
  return yield this.execute(this.buildSignUpRequest(params));
@@ -1,6 +1,6 @@
1
1
  import { Api } from './Api';
2
2
  import { Authentication } from './Authentication';
3
- import { nVizzlyQueryEngine, Request, extraHeaders, CreateDashboardParams, UpdateDashboardParams, UpdateGlobalLibraryParams, GlobalLibrary, CreateGlobalLibraryParams, GlobalLibraryPermission, GlobalLibraryPermissionFromAPI, RequestParams } from '../types';
3
+ import { nVizzlyQueryEngine, Request, extraHeaders, CreateDashboardParams, UpdateDashboardParams, UpdateGlobalLibraryParams, GlobalLibrary, CreateGlobalLibraryParams, GlobalLibraryPermissionFromAPI, RequestParams } from '../types';
4
4
  export declare class VizzlyQueryEngineApi extends Api {
5
5
  constructor(auth: Authentication, host: string, extraHeaders?: extraHeaders);
6
6
  buildCreateDashboardRequest(params: RequestParams<CreateDashboardParams>): Request<CreateDashboardParams & {
@@ -57,7 +57,7 @@ export declare class VizzlyQueryEngineApi extends Api {
57
57
  buildStatusRequest(params?: RequestParams): Request<{}>;
58
58
  createGlobalLibrary(params: RequestParams<CreateGlobalLibraryParams>): Promise<{
59
59
  global_library: GlobalLibrary;
60
- permissions: Array<GlobalLibraryPermission>;
60
+ permissions: Array<GlobalLibraryPermissionFromAPI>;
61
61
  }>;
62
62
  buildCreateGlobalLibraryRequest(params: RequestParams<CreateGlobalLibraryParams>): Request<{}>;
63
63
  fetchGlobalLibraries(params: RequestParams<{
@@ -310,6 +310,8 @@ class VizzlyQueryEngineApi extends Api_1.Api {
310
310
  const result = yield this.execute(this.buildCreateGlobalLibraryRequest(params));
311
311
  if (result.status === 200)
312
312
  return result.body;
313
+ if (result.status === 403)
314
+ throw new errors_1.PermissionDenied('Permission denied when creating a global library via the Vizzly Query Engine.');
313
315
  throw new errors_1.FailedToCreateGlobalLibrary(`Failed to create a global library. Got status ${result.status}`);
314
316
  });
315
317
  }
package/dist/types.d.ts CHANGED
@@ -11,6 +11,14 @@ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
11
11
  export type UpdateDashboardResponseBody = {
12
12
  dashboard: DashboardFromAPI;
13
13
  };
14
+ export type PersistedReport = {
15
+ id: string;
16
+ dashboard_id: string;
17
+ organisation_id: string;
18
+ schedule: string;
19
+ type: 'scheduled';
20
+ user_reference: string;
21
+ };
14
22
  export type Response<T> = {
15
23
  status: number;
16
24
  headers: Headers;
@@ -126,6 +134,9 @@ export declare namespace nVizzlyQueryEngine {
126
134
  };
127
135
  }
128
136
  export declare namespace nVizzlyApi {
137
+ type GetScheduledReportParams = {
138
+ dashboardAccessToken: string;
139
+ };
129
140
  type CreateParentDashboardParams = {
130
141
  definition: any;
131
142
  projectId: string;
@@ -155,7 +166,8 @@ export declare namespace nVizzlyApi {
155
166
  name?: string;
156
167
  };
157
168
  type SaveScheduledReportParams = {
158
- cronSchedule: string;
169
+ dashboardAccessToken: string;
170
+ cronSchedule: string | null;
159
171
  scheduledReportId: string;
160
172
  };
161
173
  type SaveEncryptedProjectEncryptionSecretParams = {
@@ -204,6 +216,10 @@ export declare namespace nVizzlyApi {
204
216
  };
205
217
  }
206
218
  export declare namespace nVizzlyAppApi {
219
+ type SearchUserDashboardsParams = {
220
+ projectId: string;
221
+ userReference: string;
222
+ };
207
223
  type CreateInstantDashboardParams = {
208
224
  definition: Object;
209
225
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizzly/api-client",
3
- "version": "0.0.38",
3
+ "version": "0.0.41",
4
4
  "private": false,
5
5
  "license": "NONE",
6
6
  "source": "src/index.ts",
@@ -25,7 +25,8 @@
25
25
  "uuid": "^9.0.1"
26
26
  },
27
27
  "scripts": {
28
- "test": "jest",
28
+ "test": ". ./secrets.env && jest",
29
+ "test:ci": "jest",
29
30
  "build": "rm -rf ./dist && tsc",
30
31
  "dev": "tsc -w",
31
32
  "format": "prettier --write ./src/** ./__tests__/**",