@vizzly/api-client 0.0.20 → 0.0.23
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/FailedToCreateQueryEngineUser.d.ts +3 -0
- package/dist/errors/FailedToCreateQueryEngineUser.js +10 -0
- package/dist/errors/FailedToFetchProject.d.ts +3 -0
- package/dist/errors/FailedToFetchProject.js +10 -0
- package/dist/errors/FailedToFetchProjects.d.ts +3 -0
- package/dist/errors/FailedToFetchProjects.js +10 -0
- package/dist/errors/FailedToFetchQueryEngineUser.d.ts +3 -0
- package/dist/errors/FailedToFetchQueryEngineUser.js +10 -0
- package/dist/errors/FailedToFetchTeamMembers.d.ts +3 -0
- package/dist/errors/FailedToFetchTeamMembers.js +10 -0
- package/dist/errors/FailedToSaveProjectEncryptedEncryptionSecret.d.ts +3 -0
- package/dist/errors/FailedToSaveProjectEncryptedEncryptionSecret.js +10 -0
- package/dist/errors/FailedToUpdateQueryEngineUser.d.ts +3 -0
- package/dist/errors/FailedToUpdateQueryEngineUser.js +10 -0
- package/dist/errors/ProjectEncryptedSecretAlreadySaved.d.ts +3 -0
- package/dist/errors/ProjectEncryptedSecretAlreadySaved.js +10 -0
- package/dist/errors/index.d.ts +7 -0
- package/dist/errors/index.js +7 -0
- package/dist/models/DashboardRepository.d.ts +1 -0
- package/dist/models/DashboardRepository.js +34 -19
- package/dist/models/GlobalLibraryRepository.d.ts +2 -2
- package/dist/models/GlobalLibraryRepository.js +33 -18
- package/dist/models/Permission.d.ts +1 -0
- package/dist/models/Permission.js +20 -0
- package/dist/models/Repository.d.ts +17 -0
- package/dist/models/Repository.js +47 -0
- package/dist/models/VizzlyApi.d.ts +15 -7
- package/dist/models/VizzlyApi.js +41 -6
- package/dist/types/project.d.ts +69 -0
- package/dist/types/project.js +2 -0
- package/dist/types/team.d.ts +11 -0
- package/dist/types/team.js +2 -0
- package/dist/types/user.d.ts +15 -0
- package/dist/types/user.js +2 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.js +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FailedToCreateQueryEngineUser = void 0;
|
|
4
|
+
class FailedToCreateQueryEngineUser extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'FailedToCreateQueryEngineUser';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.FailedToCreateQueryEngineUser = FailedToCreateQueryEngineUser;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FailedToFetchProject = void 0;
|
|
4
|
+
class FailedToFetchProject extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'FailedToFetchProject';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.FailedToFetchProject = FailedToFetchProject;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FailedToFetchProjects = void 0;
|
|
4
|
+
class FailedToFetchProjects extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'FailedToFetchProjects';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.FailedToFetchProjects = FailedToFetchProjects;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FailedToFetchQueryEngineUser = void 0;
|
|
4
|
+
class FailedToFetchQueryEngineUser extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'FailedToFetchQueryEngineUser';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.FailedToFetchQueryEngineUser = FailedToFetchQueryEngineUser;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FailedToFetchTeamMembers = void 0;
|
|
4
|
+
class FailedToFetchTeamMembers extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'FailedToFetchTeamMembers';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.FailedToFetchTeamMembers = FailedToFetchTeamMembers;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FailedToSaveProjectEncryptedEncryptionSecret = void 0;
|
|
4
|
+
class FailedToSaveProjectEncryptedEncryptionSecret extends Error {
|
|
5
|
+
constructor(projectId) {
|
|
6
|
+
super(`Failed to save project encrypted encryption secret for ${projectId}`);
|
|
7
|
+
this.name = 'FailedToSaveProjectEncryptedEncryptionSecret';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.FailedToSaveProjectEncryptedEncryptionSecret = FailedToSaveProjectEncryptedEncryptionSecret;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FailedToUpdateQueryEngineUser = void 0;
|
|
4
|
+
class FailedToUpdateQueryEngineUser extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'FailedToUpdateQueryEngineUser';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.FailedToUpdateQueryEngineUser = FailedToUpdateQueryEngineUser;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProjectEncryptedSecretAlreadySaved = void 0;
|
|
4
|
+
class ProjectEncryptedSecretAlreadySaved extends Error {
|
|
5
|
+
constructor(projectId) {
|
|
6
|
+
super(`Project encrypted encryption secret already exists for ${projectId}`);
|
|
7
|
+
this.name = 'ProjectEncryptedSecretAlreadySaved';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.ProjectEncryptedSecretAlreadySaved = ProjectEncryptedSecretAlreadySaved;
|
package/dist/errors/index.d.ts
CHANGED
|
@@ -14,3 +14,10 @@ export * from './FailedToUpdateDashboard';
|
|
|
14
14
|
export * from './FailedToFetchVizzlyConfig';
|
|
15
15
|
export * from './ConnectionDoesNotExistOnProject';
|
|
16
16
|
export * from './FailedToFetchConnection';
|
|
17
|
+
export * from './FailedToFetchProject';
|
|
18
|
+
export * from './FailedToFetchProjects';
|
|
19
|
+
export * from './FailedToFetchTeamMembers';
|
|
20
|
+
export * from './FailedToCreateQueryEngineUser';
|
|
21
|
+
export * from './FailedToFetchQueryEngineUser';
|
|
22
|
+
export * from './ProjectEncryptedSecretAlreadySaved';
|
|
23
|
+
export * from './FailedToSaveProjectEncryptedEncryptionSecret';
|
package/dist/errors/index.js
CHANGED
|
@@ -30,3 +30,10 @@ __exportStar(require("./FailedToUpdateDashboard"), exports);
|
|
|
30
30
|
__exportStar(require("./FailedToFetchVizzlyConfig"), exports);
|
|
31
31
|
__exportStar(require("./ConnectionDoesNotExistOnProject"), exports);
|
|
32
32
|
__exportStar(require("./FailedToFetchConnection"), exports);
|
|
33
|
+
__exportStar(require("./FailedToFetchProject"), exports);
|
|
34
|
+
__exportStar(require("./FailedToFetchProjects"), exports);
|
|
35
|
+
__exportStar(require("./FailedToFetchTeamMembers"), exports);
|
|
36
|
+
__exportStar(require("./FailedToCreateQueryEngineUser"), exports);
|
|
37
|
+
__exportStar(require("./FailedToFetchQueryEngineUser"), exports);
|
|
38
|
+
__exportStar(require("./ProjectEncryptedSecretAlreadySaved"), exports);
|
|
39
|
+
__exportStar(require("./FailedToSaveProjectEncryptedEncryptionSecret"), exports);
|
|
@@ -2,6 +2,7 @@ import { CreateDashboardParams, Dashboard, DashboardFromAPI, DashboardPermission
|
|
|
2
2
|
import { Vizzly } from './Vizzly';
|
|
3
3
|
export declare class DashboardRepository {
|
|
4
4
|
private vizzly;
|
|
5
|
+
private repo;
|
|
5
6
|
constructor(vizzly: Vizzly);
|
|
6
7
|
createDashboard(createParams: CreateDashboardParams): Promise<{
|
|
7
8
|
dashboard: Dashboard;
|
|
@@ -16,9 +16,12 @@ const FailedToDecryptDashboardBeforeClient_1 = require("../errors/FailedToDecryp
|
|
|
16
16
|
const FailedToFetchDashboardAccessTokens_1 = require("../errors/FailedToFetchDashboardAccessTokens");
|
|
17
17
|
const FailedToUpdateDashboard_1 = require("../errors/FailedToUpdateDashboard");
|
|
18
18
|
const Permission_1 = require("./Permission");
|
|
19
|
+
const Repository_1 = require("./Repository");
|
|
19
20
|
class DashboardRepository {
|
|
21
|
+
// private repo: { dashboards: Dashboard[]; permissions: DashboardPermission[] } | null;
|
|
20
22
|
constructor(vizzly) {
|
|
21
23
|
this.vizzly = vizzly;
|
|
24
|
+
this.repo = new Repository_1.Repository('id');
|
|
22
25
|
}
|
|
23
26
|
createDashboard(createParams) {
|
|
24
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -33,8 +36,10 @@ class DashboardRepository {
|
|
|
33
36
|
}
|
|
34
37
|
if (builtDashboard.status === 200) {
|
|
35
38
|
const formattedPermissions = builtDashboard.body.permissions.map(Permission_1.Permission.formatDashboardPermission);
|
|
39
|
+
const embellishedDashboard = DashboardRepository.embellishDashboardFromAPI(builtDashboard.body.dashboard, formattedPermissions);
|
|
40
|
+
this.repo.addItem(embellishedDashboard, formattedPermissions);
|
|
36
41
|
return {
|
|
37
|
-
dashboard:
|
|
42
|
+
dashboard: embellishedDashboard,
|
|
38
43
|
permissions: formattedPermissions,
|
|
39
44
|
};
|
|
40
45
|
}
|
|
@@ -59,11 +64,15 @@ class DashboardRepository {
|
|
|
59
64
|
updatedDashboard = yield vizzlyApi.execute(vizzlyApi.buildUpdateDashboardRequest(params));
|
|
60
65
|
}
|
|
61
66
|
if (updatedDashboard.status === 200) {
|
|
62
|
-
|
|
67
|
+
const embellishedDashboard = DashboardRepository.embellishDashboardFromAPI(updatedDashboard.body.dashboard, [
|
|
63
68
|
params.dashboardPermission,
|
|
64
69
|
]);
|
|
70
|
+
this.repo.updateItem(embellishedDashboard);
|
|
71
|
+
return embellishedDashboard;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
throw new FailedToUpdateDashboard_1.FailedToUpdateDashboard(`Failed to update dashboard, got status ${updatedDashboard.status}`);
|
|
65
75
|
}
|
|
66
|
-
throw new FailedToUpdateDashboard_1.FailedToUpdateDashboard(`Failed to update dashboard, got status ${updatedDashboard.status}`);
|
|
67
76
|
});
|
|
68
77
|
}
|
|
69
78
|
fetchDashboards(params) {
|
|
@@ -85,26 +94,32 @@ class DashboardRepository {
|
|
|
85
94
|
fetchDashboardAccessTokens(params) {
|
|
86
95
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87
96
|
let accessTokens;
|
|
88
|
-
if (this.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
if (!this.repo.isPopulated()) {
|
|
98
|
+
if (this.vizzly.implementationStrategy.shouldPersistViaQueryEngine()) {
|
|
99
|
+
const vizzlyQueryEngineApi = this.vizzly.getVizzlyQueryEngineAPI();
|
|
100
|
+
accessTokens = yield vizzlyQueryEngineApi.execute(vizzlyQueryEngineApi.buildFetchDashboardAccessTokensRequest(params));
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const vizzlyApi = this.vizzly.getVizzlyAPI();
|
|
104
|
+
accessTokens = yield vizzlyApi.execute(vizzlyApi.buildFetchDashboardAccessTokensRequest(params));
|
|
105
|
+
}
|
|
106
|
+
if (accessTokens.status === 200) {
|
|
107
|
+
const formattedPermissions = accessTokens.body.permissions.map(Permission_1.Permission.formatDashboardPermission);
|
|
108
|
+
const embellishedDashboards = accessTokens.body.dashboards.map((dashboard) => {
|
|
100
109
|
if (typeof dashboard.definition === 'string')
|
|
101
110
|
throw new FailedToDecryptDashboardBeforeClient_1.FailedToDecryptDashboardBeforeClient();
|
|
102
111
|
return DashboardRepository.embellishDashboardFromAPI(dashboard, formattedPermissions);
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
}
|
|
112
|
+
});
|
|
113
|
+
this.repo.initRepo(embellishedDashboards, formattedPermissions);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
throw new FailedToFetchDashboardAccessTokens_1.FailedToFetchDashboardAccessTokens('Failed to fetch dashboard access tokens.');
|
|
117
|
+
}
|
|
106
118
|
}
|
|
107
|
-
|
|
119
|
+
return {
|
|
120
|
+
dashboards: this.repo.getRepo().storedItems,
|
|
121
|
+
permissions: this.repo.getRepo().permissions,
|
|
122
|
+
};
|
|
108
123
|
});
|
|
109
124
|
}
|
|
110
125
|
}
|
|
@@ -2,11 +2,11 @@ import { CreateGlobalLibraryParams, GlobalLibrary, GlobalLibraryPermission, Requ
|
|
|
2
2
|
import { Vizzly } from './Vizzly';
|
|
3
3
|
export declare class GlobalLibraryRepository {
|
|
4
4
|
private vizzly;
|
|
5
|
-
private
|
|
5
|
+
private repo;
|
|
6
6
|
constructor(vizzly: Vizzly);
|
|
7
7
|
createGlobalLibrary(createParams: CreateGlobalLibraryParams): Promise<{
|
|
8
|
-
global_library: GlobalLibrary;
|
|
9
8
|
permissions: GlobalLibraryPermission[];
|
|
9
|
+
global_library: GlobalLibrary;
|
|
10
10
|
}>;
|
|
11
11
|
fetchGlobalLibraries(params?: RequestParams): Promise<{
|
|
12
12
|
global_libraries: GlobalLibrary[];
|
|
@@ -13,21 +13,25 @@ exports.GlobalLibraryRepository = void 0;
|
|
|
13
13
|
const lodash_1 = require("lodash");
|
|
14
14
|
const Permission_1 = require("./Permission");
|
|
15
15
|
const FailedToFetchGlobalLibraryAccessTokens_1 = require("../errors/FailedToFetchGlobalLibraryAccessTokens");
|
|
16
|
+
const Repository_1 = require("./Repository");
|
|
16
17
|
class GlobalLibraryRepository {
|
|
17
18
|
constructor(vizzly) {
|
|
18
|
-
this.cachedPermissions = { permissions: [] };
|
|
19
19
|
this.vizzly = vizzly;
|
|
20
|
+
this.repo = new Repository_1.Repository('id');
|
|
20
21
|
}
|
|
21
22
|
createGlobalLibrary(createParams) {
|
|
22
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
24
|
const vizzlyApi = this.vizzly.getVizzlyAPI();
|
|
25
|
+
let globalLibrary;
|
|
24
26
|
if (this.vizzly.implementationStrategy.shouldPersistViaQueryEngine()) {
|
|
25
27
|
const vizzlyQueryEngineApi = this.vizzly.getVizzlyQueryEngineAPI();
|
|
26
|
-
|
|
28
|
+
globalLibrary = yield vizzlyQueryEngineApi.createGlobalLibrary(createParams);
|
|
27
29
|
}
|
|
28
30
|
else {
|
|
29
|
-
|
|
31
|
+
globalLibrary = yield vizzlyApi.createGlobalLibrary(createParams);
|
|
30
32
|
}
|
|
33
|
+
this.repo.addItem(globalLibrary.global_library, globalLibrary.permissions);
|
|
34
|
+
return globalLibrary;
|
|
31
35
|
});
|
|
32
36
|
}
|
|
33
37
|
fetchGlobalLibraries(params) {
|
|
@@ -40,32 +44,43 @@ class GlobalLibraryRepository {
|
|
|
40
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
45
|
const vizzlyApi = this.vizzly.getVizzlyAPI();
|
|
42
46
|
let accessTokens;
|
|
43
|
-
if (this.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
47
|
+
if (!this.repo.isPopulated()) {
|
|
48
|
+
if (this.vizzly.implementationStrategy.shouldPersistViaQueryEngine()) {
|
|
49
|
+
const vizzlyQueryEngineApi = this.vizzly.getVizzlyQueryEngineAPI();
|
|
50
|
+
accessTokens = yield vizzlyQueryEngineApi.fetchGlobalLibraryAccessTokens(params);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
accessTokens = yield vizzlyApi.fetchGlobalLibraryAccessTokens(params);
|
|
54
|
+
}
|
|
55
|
+
if (accessTokens.status === 200) {
|
|
56
|
+
const formattedPermissions = accessTokens.body.permissions.map(Permission_1.Permission.formatGlobalLibraryPermission);
|
|
57
|
+
this.repo.initRepo(accessTokens.body.global_libraries, formattedPermissions);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
throw new FailedToFetchGlobalLibraryAccessTokens_1.FailedToFetchGlobalLibraryAccessTokens('Failed to load access tokens for the global library.');
|
|
61
|
+
}
|
|
55
62
|
}
|
|
56
|
-
|
|
63
|
+
return {
|
|
64
|
+
global_libraries: this.repo.getRepo().storedItems,
|
|
65
|
+
permissions: this.repo.getRepo().permissions,
|
|
66
|
+
};
|
|
57
67
|
});
|
|
58
68
|
}
|
|
59
69
|
updateGlobalLibrary(params) {
|
|
60
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
71
|
const vizzlyApi = this.vizzly.getVizzlyAPI();
|
|
72
|
+
let updateResponse;
|
|
62
73
|
if (this.vizzly.implementationStrategy.shouldPersistViaQueryEngine()) {
|
|
63
74
|
const vizzlyQueryEngineApi = this.vizzly.getVizzlyQueryEngineAPI();
|
|
64
|
-
|
|
75
|
+
updateResponse = yield vizzlyQueryEngineApi.updateGlobalLibrary(params);
|
|
65
76
|
}
|
|
66
77
|
else {
|
|
67
|
-
|
|
78
|
+
updateResponse = yield vizzlyApi.updateGlobalLibrary(params);
|
|
79
|
+
}
|
|
80
|
+
if (updateResponse.status === 200) {
|
|
81
|
+
this.repo.updateItem(updateResponse.body.global_library);
|
|
68
82
|
}
|
|
83
|
+
return updateResponse;
|
|
69
84
|
});
|
|
70
85
|
}
|
|
71
86
|
getChildGlobalLibrariesByParentGlobalLibraryId(parentGlobalLibraryId) {
|
|
@@ -7,4 +7,5 @@ export declare class Permission {
|
|
|
7
7
|
scope: 'read' | 'read_write';
|
|
8
8
|
}): DashboardPermission;
|
|
9
9
|
static formatGlobalLibraryPermission(permission: GlobalLibraryPermissionFromAPI): GlobalLibraryPermission;
|
|
10
|
+
static validateJwtExpiry(token: string, freshnessBufferInSeconds?: number): boolean;
|
|
10
11
|
}
|
|
@@ -18,5 +18,25 @@ class Permission {
|
|
|
18
18
|
globalLibraryId: permission.global_library_id,
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
+
static validateJwtExpiry(token, freshnessBufferInSeconds = 10) {
|
|
22
|
+
try {
|
|
23
|
+
// Split the token into its parts
|
|
24
|
+
const [_header, payload, _signature] = token.split('.');
|
|
25
|
+
// Decode the payload (Base64 decoding)
|
|
26
|
+
const decodedPayload = Buffer.from(payload, 'base64').toString('utf-8');
|
|
27
|
+
const payloadObj = JSON.parse(decodedPayload);
|
|
28
|
+
// Get the expiration time from the payload
|
|
29
|
+
const expirationTime = payloadObj.exp;
|
|
30
|
+
// Get the current timestamp
|
|
31
|
+
const currentTimestamp = Math.floor(Date.now() / 1000);
|
|
32
|
+
// Check if the token has expired
|
|
33
|
+
const hasExpired = expirationTime < currentTimestamp + freshnessBufferInSeconds;
|
|
34
|
+
return !hasExpired;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
// Token decoding or validation failed
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
21
41
|
}
|
|
22
42
|
exports.Permission = Permission;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class Repository<StoreType, PermissionType extends {
|
|
2
|
+
token: string;
|
|
3
|
+
}> {
|
|
4
|
+
private storedItems;
|
|
5
|
+
private permissions;
|
|
6
|
+
private itemKey;
|
|
7
|
+
constructor(itemKey: keyof StoreType);
|
|
8
|
+
getRepo(): {
|
|
9
|
+
storedItems: StoreType[];
|
|
10
|
+
permissions: PermissionType[];
|
|
11
|
+
};
|
|
12
|
+
initRepo(storedItems: Array<StoreType>, permissions: Array<PermissionType>): void;
|
|
13
|
+
addItem(item: StoreType, permissions: PermissionType[]): void;
|
|
14
|
+
updateItem(newValue: StoreType): void;
|
|
15
|
+
isPopulated(): boolean;
|
|
16
|
+
private permissionsAreFresh;
|
|
17
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Repository = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const Permission_1 = require("./Permission");
|
|
6
|
+
class Repository {
|
|
7
|
+
constructor(itemKey) {
|
|
8
|
+
this.itemKey = itemKey;
|
|
9
|
+
this.storedItems = [];
|
|
10
|
+
this.permissions = [];
|
|
11
|
+
}
|
|
12
|
+
getRepo() {
|
|
13
|
+
return {
|
|
14
|
+
storedItems: this.storedItems,
|
|
15
|
+
permissions: this.permissions,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
initRepo(storedItems, permissions) {
|
|
19
|
+
this.storedItems = storedItems;
|
|
20
|
+
this.permissions = permissions;
|
|
21
|
+
}
|
|
22
|
+
addItem(item, permissions) {
|
|
23
|
+
// Can only add an item to the store that has been
|
|
24
|
+
// initialized using initRepo
|
|
25
|
+
if (this.isPopulated()) {
|
|
26
|
+
this.storedItems = [...this.storedItems, item];
|
|
27
|
+
this.permissions = [...this.permissions, ...permissions];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
updateItem(newValue) {
|
|
31
|
+
this.storedItems = this.storedItems.map((item) => {
|
|
32
|
+
if (item[this.itemKey] == newValue[this.itemKey])
|
|
33
|
+
return newValue;
|
|
34
|
+
return item;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
isPopulated() {
|
|
38
|
+
const populated = this.storedItems.length > 0 || this.permissions.length > 0;
|
|
39
|
+
return populated && this.permissionsAreFresh();
|
|
40
|
+
}
|
|
41
|
+
permissionsAreFresh() {
|
|
42
|
+
return (0, lodash_1.every)(this.permissions, (permission) => {
|
|
43
|
+
return Permission_1.Permission.validateJwtExpiry(permission.token);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.Repository = Repository;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Api } from './Api';
|
|
2
2
|
import { Authentication } from './Authentication';
|
|
3
|
-
import { CreateDashboardParams, CreateGlobalLibraryParams, GlobalLibrary, GlobalLibraryPermission, GlobalLibraryPermissionFromAPI, Request, RequestParams, UpdateDashboardParams, UpdateDashboardResponseBody, UpdateGlobalLibraryParams } from '../types';
|
|
3
|
+
import { CreateDashboardParams, CreateGlobalLibraryParams, GlobalLibrary, GlobalLibraryPermission, GlobalLibraryPermissionFromAPI, QueryEngineUserFromAPI, Request, RequestParams, TeamMemberFromAPI, UpdateDashboardParams, UpdateDashboardResponseBody, UpdateGlobalLibraryParams } from '../types';
|
|
4
4
|
import { nVizzlyApi } from '../types';
|
|
5
|
+
import { ProjectFromAPI } from '../types/project';
|
|
5
6
|
export declare class VizzlyApi extends Api {
|
|
6
7
|
constructor(auth: Authentication, host?: string);
|
|
7
8
|
buildFetchDashboardAccessTokensRequest(params?: RequestParams): Request<{
|
|
@@ -42,13 +43,15 @@ export declare class VizzlyApi extends Api {
|
|
|
42
43
|
permissions: Array<GlobalLibraryPermission>;
|
|
43
44
|
}>;
|
|
44
45
|
buildCreateGlobalLibraryRequest(params: RequestParams<CreateGlobalLibraryParams>): Request<{}>;
|
|
45
|
-
getProjects(params?: RequestParams): Promise<
|
|
46
|
+
getProjects(params?: RequestParams): Promise<{
|
|
47
|
+
projects: Array<ProjectFromAPI>;
|
|
48
|
+
}>;
|
|
46
49
|
buildGetProjectsRequest(params?: RequestParams): Request<{}>;
|
|
47
50
|
createProjectApiKey(params: RequestParams<nVizzlyApi.CreateProjectApiKeyParams>): Promise<import("../types").Response<{
|
|
48
51
|
api_key: string;
|
|
49
52
|
}>>;
|
|
50
53
|
buildCreateProjectApiKeyRequest(params: RequestParams<nVizzlyApi.CreateProjectApiKeyParams>): Request<{}>;
|
|
51
|
-
createQueryEngineUser(params: RequestParams<nVizzlyApi.CreateQueryEngineUserParams>): Promise<
|
|
54
|
+
createQueryEngineUser(params: RequestParams<nVizzlyApi.CreateQueryEngineUserParams>): Promise<QueryEngineUserFromAPI>;
|
|
52
55
|
buildCreateQueryEngineUserRequest(params: RequestParams<nVizzlyApi.CreateQueryEngineUserParams>): Request<{}>;
|
|
53
56
|
buildCreateSelfHostedDynamicQueryEngineProjectRequest(params?: RequestParams): Request<{}>;
|
|
54
57
|
buildCreateSelfHostedInBrowserProjectRequest(params?: RequestParams): Request<{}>;
|
|
@@ -65,7 +68,9 @@ export declare class VizzlyApi extends Api {
|
|
|
65
68
|
buildGetConnectionRequest(params: RequestParams<nVizzlyApi.GetConnectionParams>): Request<{}>;
|
|
66
69
|
getManagedQueryEngineKeyPair(params: RequestParams<nVizzlyApi.GetManagedQueryEngineKeyPairParams>): Promise<import("../types").Response<unknown>>;
|
|
67
70
|
buildGetManagedQueryEngineKeyPairRequest(params: RequestParams<nVizzlyApi.GetManagedQueryEngineKeyPairParams>): Request<{}>;
|
|
68
|
-
getProject(params: RequestParams<nVizzlyApi.GetProjectParams>): Promise<
|
|
71
|
+
getProject(params: RequestParams<nVizzlyApi.GetProjectParams>): Promise<{
|
|
72
|
+
project: ProjectFromAPI;
|
|
73
|
+
}>;
|
|
69
74
|
buildGetProjectRequest(params: RequestParams<nVizzlyApi.GetProjectParams>): Request<{}>;
|
|
70
75
|
getProjectAccessToken(params: RequestParams<nVizzlyApi.GetProjectAccessTokenParams>): Promise<import("../types").Response<{
|
|
71
76
|
token: {
|
|
@@ -74,9 +79,11 @@ export declare class VizzlyApi extends Api {
|
|
|
74
79
|
};
|
|
75
80
|
}>>;
|
|
76
81
|
buildGetProjectAccessTokenRequest(params: RequestParams<nVizzlyApi.GetProjectAccessTokenParams>): Request<{}>;
|
|
77
|
-
getQueryEngineUser(params: RequestParams<nVizzlyApi.GetQueryEngineUserParams>): Promise<
|
|
82
|
+
getQueryEngineUser(params: RequestParams<nVizzlyApi.GetQueryEngineUserParams>): Promise<QueryEngineUserFromAPI>;
|
|
78
83
|
buildGetQueryEngineUserRequest(params: RequestParams<nVizzlyApi.GetQueryEngineUserParams>): Request<{}>;
|
|
79
|
-
getTeamMembers(params: RequestParams<nVizzlyApi.GetTeamMembers>): Promise<
|
|
84
|
+
getTeamMembers(params: RequestParams<nVizzlyApi.GetTeamMembers>): Promise<{
|
|
85
|
+
team_members: Array<TeamMemberFromAPI>;
|
|
86
|
+
}>;
|
|
80
87
|
buildGetTeamMembersRequest(params: RequestParams<nVizzlyApi.GetTeamMembers>): Request<{}>;
|
|
81
88
|
getVizzlyConfig(params: RequestParams<nVizzlyApi.GetVizzlyConfigParams>): Promise<{
|
|
82
89
|
encryptedConfig: string | null;
|
|
@@ -84,6 +91,7 @@ export declare class VizzlyApi extends Api {
|
|
|
84
91
|
buildGetVizzlyConfigRequest(params: RequestParams<nVizzlyApi.GetVizzlyConfigParams>): Request<{}>;
|
|
85
92
|
saveConnection(params: RequestParams<nVizzlyApi.SaveConnectionParams>): Promise<import("../types").Response<unknown>>;
|
|
86
93
|
buildSaveConnectionRequest(params: RequestParams<nVizzlyApi.SaveConnectionParams>): Request<{}>;
|
|
94
|
+
saveEncryptedProjectEncryptionSecret(params: RequestParams<nVizzlyApi.SaveEncryptedProjectEncryptionSecretParams>): Promise<boolean>;
|
|
87
95
|
buildSaveEncryptedProjectEncryptionSecretRequest(params: RequestParams<nVizzlyApi.SaveEncryptedProjectEncryptionSecretParams>): Request<{}>;
|
|
88
96
|
saveScheduledReport(params: RequestParams<nVizzlyApi.SaveScheduledReportParams>): Promise<import("../types").Response<unknown>>;
|
|
89
97
|
buildSaveScheduledReportRequest(params: RequestParams<nVizzlyApi.SaveScheduledReportParams>): Request<{}>;
|
|
@@ -97,6 +105,6 @@ export declare class VizzlyApi extends Api {
|
|
|
97
105
|
buildUpdateGlobalLibraryRequest(params: RequestParams<UpdateGlobalLibraryParams>): Request<{}>;
|
|
98
106
|
updateProjectApiKey(params: RequestParams<nVizzlyApi.UpdateProjectApiKeyParams>): Promise<import("../types").Response<unknown>>;
|
|
99
107
|
buildUpdateProjectApiKeyRequest(params: RequestParams<nVizzlyApi.UpdateProjectApiKeyParams>): Request<{}>;
|
|
100
|
-
updateQueryEngineUser(params: RequestParams<nVizzlyApi.UpdateQueryEngineUserParams>): Promise<
|
|
108
|
+
updateQueryEngineUser(params: RequestParams<nVizzlyApi.UpdateQueryEngineUserParams>): Promise<boolean>;
|
|
101
109
|
buildUpdateQueryEngineUserRequest(params: RequestParams<nVizzlyApi.UpdateQueryEngineUserParams>): Request<{}>;
|
|
102
110
|
}
|
package/dist/models/VizzlyApi.js
CHANGED
|
@@ -15,6 +15,10 @@ const errors_1 = require("../errors");
|
|
|
15
15
|
const FailedToFetchVizzlyConfig_1 = require("../errors/FailedToFetchVizzlyConfig");
|
|
16
16
|
const ConnectionDoesNotExistOnProject_1 = require("../errors/ConnectionDoesNotExistOnProject");
|
|
17
17
|
const FailedToFetchConnection_1 = require("../errors/FailedToFetchConnection");
|
|
18
|
+
const FailedToFetchProject_1 = require("../errors/FailedToFetchProject");
|
|
19
|
+
const FailedToUpdateQueryEngineUser_1 = require("../errors/FailedToUpdateQueryEngineUser");
|
|
20
|
+
const FailedToSaveProjectEncryptedEncryptionSecret_1 = require("../errors/FailedToSaveProjectEncryptedEncryptionSecret");
|
|
21
|
+
const ProjectEncryptedSecretAlreadySaved_1 = require("../errors/ProjectEncryptedSecretAlreadySaved");
|
|
18
22
|
class VizzlyApi extends Api_1.Api {
|
|
19
23
|
constructor(auth, host = 'https://api.vizzly.co') {
|
|
20
24
|
super(auth, host);
|
|
@@ -140,7 +144,10 @@ class VizzlyApi extends Api_1.Api {
|
|
|
140
144
|
}
|
|
141
145
|
getProjects(params) {
|
|
142
146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
-
|
|
147
|
+
const response = yield this.execute(this.buildGetProjectsRequest(params));
|
|
148
|
+
if (response.status === 200)
|
|
149
|
+
return { projects: response.body.projects };
|
|
150
|
+
throw new errors_1.FailedToFetchProjects(`Failed to fetch projects. Got status ${response.status}`);
|
|
144
151
|
});
|
|
145
152
|
}
|
|
146
153
|
buildGetProjectsRequest(params) {
|
|
@@ -168,7 +175,10 @@ class VizzlyApi extends Api_1.Api {
|
|
|
168
175
|
}
|
|
169
176
|
createQueryEngineUser(params) {
|
|
170
177
|
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
-
|
|
178
|
+
const response = yield this.execute(this.buildCreateQueryEngineUserRequest(params));
|
|
179
|
+
if (response.status === 200)
|
|
180
|
+
return response.body.query_engine_user;
|
|
181
|
+
throw new errors_1.FailedToCreateQueryEngineUser(`Failed to create query engine user. Got status ${response.status}`);
|
|
172
182
|
});
|
|
173
183
|
}
|
|
174
184
|
buildCreateQueryEngineUserRequest(params) {
|
|
@@ -287,7 +297,10 @@ class VizzlyApi extends Api_1.Api {
|
|
|
287
297
|
}
|
|
288
298
|
getProject(params) {
|
|
289
299
|
return __awaiter(this, void 0, void 0, function* () {
|
|
290
|
-
|
|
300
|
+
const getProjectResponse = yield this.execute(this.buildGetProjectRequest(params));
|
|
301
|
+
if (getProjectResponse.status === 200)
|
|
302
|
+
return getProjectResponse.body;
|
|
303
|
+
throw new FailedToFetchProject_1.FailedToFetchProject(`Failed to fetch project. Got status ${getProjectResponse.status}`);
|
|
291
304
|
});
|
|
292
305
|
}
|
|
293
306
|
buildGetProjectRequest(params) {
|
|
@@ -314,7 +327,10 @@ class VizzlyApi extends Api_1.Api {
|
|
|
314
327
|
}
|
|
315
328
|
getQueryEngineUser(params) {
|
|
316
329
|
return __awaiter(this, void 0, void 0, function* () {
|
|
317
|
-
|
|
330
|
+
const response = yield this.execute(this.buildGetQueryEngineUserRequest(params));
|
|
331
|
+
if (response.status === 200)
|
|
332
|
+
return response.body.query_engine_user;
|
|
333
|
+
throw new errors_1.FailedToFetchQueryEngineUser(`Failed to fetch query engine user. Got status ${response.status}`);
|
|
318
334
|
});
|
|
319
335
|
}
|
|
320
336
|
buildGetQueryEngineUserRequest(params) {
|
|
@@ -326,7 +342,10 @@ class VizzlyApi extends Api_1.Api {
|
|
|
326
342
|
}
|
|
327
343
|
getTeamMembers(params) {
|
|
328
344
|
return __awaiter(this, void 0, void 0, function* () {
|
|
329
|
-
|
|
345
|
+
const response = yield this.execute(this.buildGetTeamMembersRequest(params));
|
|
346
|
+
if (response.status === 200)
|
|
347
|
+
return response.body;
|
|
348
|
+
throw new errors_1.FailedToFetchTeamMembers(`Failed to fetch team members. Got status ${response.status}`);
|
|
330
349
|
});
|
|
331
350
|
}
|
|
332
351
|
buildGetTeamMembersRequest(params) {
|
|
@@ -371,6 +390,19 @@ class VizzlyApi extends Api_1.Api {
|
|
|
371
390
|
abortSignal: params.abortSignal,
|
|
372
391
|
};
|
|
373
392
|
}
|
|
393
|
+
saveEncryptedProjectEncryptionSecret(params) {
|
|
394
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
395
|
+
const response = yield this.execute(this.buildSaveEncryptedProjectEncryptionSecretRequest(params));
|
|
396
|
+
if (response.status === 200)
|
|
397
|
+
return true;
|
|
398
|
+
if (response.status == 400 && !params.allowRotation) {
|
|
399
|
+
// We're not allowing rotation, so we are trying to set the first encrypted secret, but
|
|
400
|
+
// one already exists.
|
|
401
|
+
throw new ProjectEncryptedSecretAlreadySaved_1.ProjectEncryptedSecretAlreadySaved(params.projectId);
|
|
402
|
+
}
|
|
403
|
+
throw new FailedToSaveProjectEncryptedEncryptionSecret_1.FailedToSaveProjectEncryptedEncryptionSecret(params.projectId);
|
|
404
|
+
});
|
|
405
|
+
}
|
|
374
406
|
buildSaveEncryptedProjectEncryptionSecretRequest(params) {
|
|
375
407
|
return {
|
|
376
408
|
path: `/api/v3/project/${params.projectId}/encrypted-encryption-secret`,
|
|
@@ -469,7 +501,10 @@ class VizzlyApi extends Api_1.Api {
|
|
|
469
501
|
}
|
|
470
502
|
updateQueryEngineUser(params) {
|
|
471
503
|
return __awaiter(this, void 0, void 0, function* () {
|
|
472
|
-
|
|
504
|
+
const response = yield this.execute(this.buildUpdateQueryEngineUserRequest(params));
|
|
505
|
+
if (response.status === 200)
|
|
506
|
+
return true;
|
|
507
|
+
throw new FailedToUpdateQueryEngineUser_1.FailedToUpdateQueryEngineUser(`Failed to update query engine user. Got status ${response.status}`);
|
|
473
508
|
});
|
|
474
509
|
}
|
|
475
510
|
buildUpdateQueryEngineUserRequest(params) {
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { DashboardFromAPI, GlobalLibrary } from '../types';
|
|
2
|
+
export type ProjectType = 'instant_dashboard' | 'self_hosted' | 'managed_query_engine' | 'in_browser' | 'dynamic_self_hosted_query_engine';
|
|
3
|
+
export type ProjectFromAPI = {
|
|
4
|
+
instant_dashboard_id: string | null;
|
|
5
|
+
managed_query_engine_id: string | null;
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
type: ProjectType;
|
|
9
|
+
created_at: Date;
|
|
10
|
+
share_links?: ShareLink[];
|
|
11
|
+
parent_dashboards: DashboardFromAPI[];
|
|
12
|
+
parent_global_libraries: GlobalLibrary[];
|
|
13
|
+
key_pairs: RawKeyPair[];
|
|
14
|
+
encrypted_encryption_secret: string | null;
|
|
15
|
+
query_engine_users: Array<{
|
|
16
|
+
id: string;
|
|
17
|
+
/** Hashed and encrypted using the encryption secret on the query engine */
|
|
18
|
+
password: string | null;
|
|
19
|
+
user: {
|
|
20
|
+
id: string;
|
|
21
|
+
email: string;
|
|
22
|
+
first_name: string;
|
|
23
|
+
last_name: string;
|
|
24
|
+
};
|
|
25
|
+
}>;
|
|
26
|
+
config_store: {
|
|
27
|
+
id: string;
|
|
28
|
+
versions: Array<{
|
|
29
|
+
id: string;
|
|
30
|
+
created_at: string;
|
|
31
|
+
updated_at: string;
|
|
32
|
+
}>;
|
|
33
|
+
};
|
|
34
|
+
connections: Array<{
|
|
35
|
+
id: string;
|
|
36
|
+
created_at: string;
|
|
37
|
+
updated_at: string;
|
|
38
|
+
disabled: boolean;
|
|
39
|
+
}>;
|
|
40
|
+
api_keys: Array<{
|
|
41
|
+
id: string;
|
|
42
|
+
created_at: string;
|
|
43
|
+
disabled: boolean;
|
|
44
|
+
}>;
|
|
45
|
+
deleted: boolean;
|
|
46
|
+
data_upload: {
|
|
47
|
+
created_at: string;
|
|
48
|
+
id: string;
|
|
49
|
+
updated_at: string;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
type ShareLink = {
|
|
53
|
+
id: string;
|
|
54
|
+
token: string;
|
|
55
|
+
active: boolean;
|
|
56
|
+
created_at: string;
|
|
57
|
+
title: string;
|
|
58
|
+
email: string | null;
|
|
59
|
+
};
|
|
60
|
+
type RawKeyPair = {
|
|
61
|
+
id: string;
|
|
62
|
+
uploaded_by: string;
|
|
63
|
+
public_key: string;
|
|
64
|
+
organisation_id: string;
|
|
65
|
+
uploaded_at: string;
|
|
66
|
+
updated_at: string;
|
|
67
|
+
disabled: boolean;
|
|
68
|
+
};
|
|
69
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type QueryEngineUserFromAPI = {
|
|
2
|
+
id: string;
|
|
3
|
+
password: string | null;
|
|
4
|
+
user: UserFromAPI;
|
|
5
|
+
};
|
|
6
|
+
export type UserFromAPI = {
|
|
7
|
+
active: boolean;
|
|
8
|
+
department: string;
|
|
9
|
+
email: string;
|
|
10
|
+
first_name: string;
|
|
11
|
+
id: string;
|
|
12
|
+
is_email_verified: boolean;
|
|
13
|
+
is_vizz: boolean;
|
|
14
|
+
last_name: string;
|
|
15
|
+
};
|
package/dist/types.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ import { VizzlyApi } from './models/VizzlyApi';
|
|
|
3
3
|
import { VizzlyAppApi } from './models/VizzlyAppApi';
|
|
4
4
|
import { DashboardDefinition, DashboardFromAPI } from './types/dashboard';
|
|
5
5
|
export * from './types/dashboard';
|
|
6
|
+
export * from './types/project';
|
|
7
|
+
export * from './types/team';
|
|
8
|
+
export * from './types/user';
|
|
6
9
|
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
7
10
|
export type UpdateDashboardResponseBody = {
|
|
8
11
|
dashboard: DashboardFromAPI;
|
package/dist/types.js
CHANGED
|
@@ -15,3 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./types/dashboard"), exports);
|
|
18
|
+
__exportStar(require("./types/project"), exports);
|
|
19
|
+
__exportStar(require("./types/team"), exports);
|
|
20
|
+
__exportStar(require("./types/user"), exports);
|