@vizzly/api-client 0.0.8 → 0.0.9
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/FailedToUpdateDashboard.d.ts +3 -0
- package/dist/errors/FailedToUpdateDashboard.js +10 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/models/DashboardManager.d.ts +1 -1
- package/dist/models/DashboardManager.js +1 -3
- package/dist/models/DashboardRepository.d.ts +11 -19
- package/dist/models/DashboardRepository.js +25 -4
- package/dist/models/VizzlyApi.js +1 -1
- package/dist/models/VizzlyQueryEngineApi.js +1 -1
- package/dist/types/dashboard.d.ts +8 -1
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FailedToUpdateDashboard = void 0;
|
|
4
|
+
class FailedToUpdateDashboard extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'FailedToUpdateDashboard';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.FailedToUpdateDashboard = FailedToUpdateDashboard;
|
package/dist/errors/index.d.ts
CHANGED
package/dist/errors/index.js
CHANGED
|
@@ -26,3 +26,4 @@ __exportStar(require("./FailedToSetupProject"), exports);
|
|
|
26
26
|
__exportStar(require("./FailedToResolveDataSets"), exports);
|
|
27
27
|
__exportStar(require("./FailedToCreateGlobalLibrary"), exports);
|
|
28
28
|
__exportStar(require("./FailedToDecryptDashboardBeforeClient"), exports);
|
|
29
|
+
__exportStar(require("./FailedToUpdateDashboard"), exports);
|
|
@@ -7,7 +7,7 @@ export declare class DashboardManager {
|
|
|
7
7
|
dashboard: DashboardType;
|
|
8
8
|
permissions: import("../types").DashboardPermission[];
|
|
9
9
|
}>;
|
|
10
|
-
update(params: Omit<UpdateDashboardParams, '
|
|
10
|
+
update(params: Omit<UpdateDashboardParams, 'dashboardPermission' | 'definition'> & {
|
|
11
11
|
dashboardId: string;
|
|
12
12
|
definition?: DashboardDefinition;
|
|
13
13
|
}): Promise<void>;
|
|
@@ -40,9 +40,7 @@ class DashboardManager {
|
|
|
40
40
|
if (!updateDashboardToken)
|
|
41
41
|
throw new Error(`Failed to find update token for dashboard.`);
|
|
42
42
|
// Send the update request.
|
|
43
|
-
|
|
44
|
-
if (dashboardUpdatedResponse.status != 200)
|
|
45
|
-
throw new Error('Failed to update dashboard.');
|
|
43
|
+
yield dashboardRepository.updateDashboard(Object.assign(Object.assign({}, params), { dashboardPermission: updateDashboardToken }));
|
|
46
44
|
// Build the views to store in the libraries
|
|
47
45
|
let libraryViewsToSave = [];
|
|
48
46
|
if ((_a = params.definition) === null || _a === void 0 ? void 0 : _a.componentLibrary) {
|
|
@@ -1,29 +1,21 @@
|
|
|
1
|
-
import { CreateDashboardParams, Dashboard,
|
|
1
|
+
import { CreateDashboardParams, Dashboard, DashboardFromAPI, DashboardPermission, UpdateDashboardParams } from '../types';
|
|
2
2
|
import { Vizzly } from './Vizzly';
|
|
3
|
-
type CreateDashboardResponseBody = {
|
|
4
|
-
dashboard: Dashboard;
|
|
5
|
-
permissions: Array<{
|
|
6
|
-
dashboard_id: string;
|
|
7
|
-
scope: 'read' | 'read_write';
|
|
8
|
-
token: string;
|
|
9
|
-
user_reference: string;
|
|
10
|
-
}>;
|
|
11
|
-
};
|
|
12
|
-
type FetchDashboardsResponseBody = {
|
|
13
|
-
found: Dashboard[];
|
|
14
|
-
not_found: any[];
|
|
15
|
-
};
|
|
16
3
|
export declare class DashboardRepository {
|
|
17
4
|
private vizzly;
|
|
18
5
|
constructor(vizzly: Vizzly);
|
|
19
6
|
createDashboard(createParams: CreateDashboardParams): Promise<{
|
|
20
7
|
dashboard: Dashboard;
|
|
21
|
-
permissions:
|
|
8
|
+
permissions: DashboardPermission[];
|
|
9
|
+
}>;
|
|
10
|
+
updateDashboard(params: UpdateDashboardParams): Promise<Dashboard>;
|
|
11
|
+
fetchDashboards(): Promise<{
|
|
12
|
+
found: Dashboard[];
|
|
13
|
+
not_found: string[];
|
|
22
14
|
}>;
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
static embellishDashboardFromAPI(dashboard: DashboardFromAPI, permissions: DashboardPermission[]): Dashboard;
|
|
16
|
+
static takeHighestPermission(dashboardId: string, permissions: DashboardPermission[]): DashboardPermission;
|
|
17
|
+
static takePermissionsOfScope(dashboardId: string, permissions: DashboardPermission[], scope: 'read' | 'read_write'): DashboardPermission[];
|
|
25
18
|
fetchDashboardAccessTokens(): Promise<{
|
|
26
|
-
permissions:
|
|
19
|
+
permissions: DashboardPermission[];
|
|
27
20
|
}>;
|
|
28
21
|
}
|
|
29
|
-
export {};
|
|
@@ -15,6 +15,7 @@ const FailedToCreateDashboard_1 = require("../errors/FailedToCreateDashboard");
|
|
|
15
15
|
const FailedToDecryptDashboardBeforeClient_1 = require("../errors/FailedToDecryptDashboardBeforeClient");
|
|
16
16
|
const FailedToFetchDashboardAccessTokens_1 = require("../errors/FailedToFetchDashboardAccessTokens");
|
|
17
17
|
const FailedToFetchDashboards_1 = require("../errors/FailedToFetchDashboards");
|
|
18
|
+
const FailedToUpdateDashboard_1 = require("../errors/FailedToUpdateDashboard");
|
|
18
19
|
const Permission_1 = require("./Permission");
|
|
19
20
|
class DashboardRepository {
|
|
20
21
|
constructor(vizzly) {
|
|
@@ -32,9 +33,10 @@ class DashboardRepository {
|
|
|
32
33
|
builtDashboard = yield vizzlyApi.execute(vizzlyApi.buildCreateDashboardRequest(createParams));
|
|
33
34
|
}
|
|
34
35
|
if (builtDashboard.status === 200) {
|
|
36
|
+
const formattedPermissions = builtDashboard.body.permissions.map(Permission_1.Permission.formatDashboardPermission);
|
|
35
37
|
return {
|
|
36
|
-
dashboard: builtDashboard.body.dashboard,
|
|
37
|
-
permissions:
|
|
38
|
+
dashboard: DashboardRepository.embellishDashboardFromAPI(builtDashboard.body.dashboard, formattedPermissions),
|
|
39
|
+
permissions: formattedPermissions,
|
|
38
40
|
};
|
|
39
41
|
}
|
|
40
42
|
if (builtDashboard.status === 422) {
|
|
@@ -57,7 +59,12 @@ class DashboardRepository {
|
|
|
57
59
|
const vizzlyApi = this.vizzly.getVizzlyAPI();
|
|
58
60
|
updatedDashboard = yield vizzlyApi.execute(vizzlyApi.buildUpdateDashboardRequest(params));
|
|
59
61
|
}
|
|
60
|
-
|
|
62
|
+
if (updatedDashboard.status === 200) {
|
|
63
|
+
return DashboardRepository.embellishDashboardFromAPI(updatedDashboard.body.dashboard, [
|
|
64
|
+
params.dashboardPermission,
|
|
65
|
+
]);
|
|
66
|
+
}
|
|
67
|
+
throw new FailedToUpdateDashboard_1.FailedToUpdateDashboard(`Failed to update dashboard, got status ${updatedDashboard.status}`);
|
|
61
68
|
});
|
|
62
69
|
}
|
|
63
70
|
fetchDashboards() {
|
|
@@ -78,11 +85,25 @@ class DashboardRepository {
|
|
|
78
85
|
throw new FailedToDecryptDashboardBeforeClient_1.FailedToDecryptDashboardBeforeClient();
|
|
79
86
|
}
|
|
80
87
|
});
|
|
81
|
-
return
|
|
88
|
+
return {
|
|
89
|
+
found: dashboardResponse.body.found.map((foundDashboard) => DashboardRepository.embellishDashboardFromAPI(foundDashboard, permissions)),
|
|
90
|
+
not_found: dashboardResponse.body.not_found,
|
|
91
|
+
};
|
|
82
92
|
}
|
|
83
93
|
throw new FailedToFetchDashboards_1.FailedToFetchDashboards(`Failed to fetch dashboards. Got status code ${dashboardResponse.status}.`);
|
|
84
94
|
});
|
|
85
95
|
}
|
|
96
|
+
static embellishDashboardFromAPI(dashboard, permissions) {
|
|
97
|
+
return Object.assign(Object.assign({}, dashboard), { permission: DashboardRepository.takeHighestPermission(dashboard.id, permissions) });
|
|
98
|
+
}
|
|
99
|
+
static takeHighestPermission(dashboardId, permissions) {
|
|
100
|
+
const readPermissions = DashboardRepository.takePermissionsOfScope(dashboardId, permissions, 'read');
|
|
101
|
+
const readWritePermissions = DashboardRepository.takePermissionsOfScope(dashboardId, permissions, 'read_write');
|
|
102
|
+
return readWritePermissions[0] || readPermissions[0];
|
|
103
|
+
}
|
|
104
|
+
static takePermissionsOfScope(dashboardId, permissions, scope) {
|
|
105
|
+
return permissions.filter((p) => p.dashboardId === dashboardId && p.scope === scope);
|
|
106
|
+
}
|
|
86
107
|
fetchDashboardAccessTokens() {
|
|
87
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
109
|
const vizzlyApi = this.vizzly.getVizzlyAPI();
|
package/dist/models/VizzlyApi.js
CHANGED
|
@@ -360,7 +360,7 @@ class VizzlyApi extends Api_1.Api {
|
|
|
360
360
|
path: '/api/v2/dashboard',
|
|
361
361
|
method: 'put',
|
|
362
362
|
body: {
|
|
363
|
-
dashboardSessionToken: params.
|
|
363
|
+
dashboardSessionToken: params.dashboardPermission.token,
|
|
364
364
|
definition: params.definition,
|
|
365
365
|
meta: params.metadata || params.meta || {},
|
|
366
366
|
deleted: params.deleted,
|
|
@@ -321,7 +321,7 @@ class VizzlyQueryEngineApi extends Api_1.Api {
|
|
|
321
321
|
path: `/api/v1/dashboard`,
|
|
322
322
|
method: 'put',
|
|
323
323
|
body: {
|
|
324
|
-
dashboardSessionToken: params.
|
|
324
|
+
dashboardSessionToken: params.dashboardPermission.token,
|
|
325
325
|
definition: params.definition,
|
|
326
326
|
meta: params.meta,
|
|
327
327
|
deleted: params.deleted,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { DashboardPermission } from '../types';
|
|
2
|
+
export type DashboardFromAPI = {
|
|
2
3
|
definition: DashboardDefinition;
|
|
3
4
|
created_at: string;
|
|
4
5
|
id: string;
|
|
@@ -8,6 +9,12 @@ export type Dashboard = {
|
|
|
8
9
|
updated_at: string;
|
|
9
10
|
webhook_id: string | null;
|
|
10
11
|
};
|
|
12
|
+
export type Dashboard = DashboardFromAPI & {
|
|
13
|
+
/**
|
|
14
|
+
* Highest permission token for the dashboard.
|
|
15
|
+
*/
|
|
16
|
+
permission: DashboardPermission;
|
|
17
|
+
};
|
|
11
18
|
export type DashboardDefinition = {
|
|
12
19
|
display: any;
|
|
13
20
|
componentLibrary: Array<{
|
package/dist/types.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export type CreateDashboardParamsUnencrypted = Omit<CreateDashboardParams, 'defi
|
|
|
43
43
|
definition: DashboardDefinition;
|
|
44
44
|
};
|
|
45
45
|
export type UpdateDashboardParams = {
|
|
46
|
-
|
|
46
|
+
dashboardPermission: DashboardPermission;
|
|
47
47
|
definition?: DashboardDefinition | string;
|
|
48
48
|
/** @deprecated - use `metadata` instead */
|
|
49
49
|
meta?: any;
|