@vizzly/api-client 0.0.38 → 0.0.39
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.
- package/dist/errors/PermissionDenied.d.ts +3 -0
- package/dist/errors/PermissionDenied.js +9 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/models/DashboardManager.js +17 -17
- package/dist/models/GlobalLibraryManager.d.ts +1 -1
- package/dist/models/GlobalLibraryRepository.d.ts +1 -1
- package/dist/models/GlobalLibraryRepository.js +40 -5
- package/dist/models/VizzlyApi.d.ts +2 -2
- package/dist/models/VizzlyApi.js +3 -1
- package/dist/models/VizzlyQueryEngineApi.d.ts +2 -2
- package/dist/models/VizzlyQueryEngineApi.js +2 -0
- package/package.json +1 -1
package/dist/errors/index.d.ts
CHANGED
package/dist/errors/index.js
CHANGED
|
@@ -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
|
|
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 || !!
|
|
65
|
-
const parentGlobalLibrary = globalLibraries.find((gL) => gL.parent_global_library_id === null);
|
|
66
|
-
if (!isParent && parentGlobalLibrary && hasThingsToSaveInLibrary && librariesToUpdate.length === 0) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
|
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: ((
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
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
|
|
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,
|
|
3
|
+
import { CreateDashboardParams, CreateGlobalLibraryParams, GlobalLibrary, GlobalLibraryPermissionFromAPI, 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<
|
|
43
|
+
permissions: Array<GlobalLibraryPermissionFromAPI>;
|
|
44
44
|
}>;
|
|
45
45
|
buildCreateGlobalLibraryRequest(params: RequestParams<CreateGlobalLibraryParams>): Request<{}>;
|
|
46
46
|
getProjects(params?: RequestParams): Promise<{
|
package/dist/models/VizzlyApi.js
CHANGED
|
@@ -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
|
-
|
|
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) {
|
|
@@ -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,
|
|
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<
|
|
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
|
}
|