@vizzly/api-client 0.0.26 → 0.0.28
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/FailedToUpdateGlobalLibrary.d.ts +3 -0
- package/dist/errors/FailedToUpdateGlobalLibrary.js +10 -0
- package/dist/models/DashboardManager.js +1 -1
- package/dist/models/DashboardRepository.d.ts +1 -0
- package/dist/models/DashboardRepository.js +3 -0
- package/dist/models/GlobalLibraryManager.d.ts +15 -0
- package/dist/models/GlobalLibraryManager.js +49 -0
- package/dist/models/GlobalLibraryRepository.d.ts +3 -4
- package/dist/models/GlobalLibraryRepository.js +12 -5
- package/dist/models/Repository.d.ts +1 -0
- package/dist/models/Repository.js +4 -0
- package/dist/models/Vizzly.d.ts +3 -0
- package/dist/models/Vizzly.js +5 -0
- package/dist/types/globalLibrary.d.ts +5 -0
- package/dist/types/globalLibrary.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FailedToUpdateGlobalLibrary = void 0;
|
|
4
|
+
class FailedToUpdateGlobalLibrary extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'FailedToUpdateGlobalLibrary';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.FailedToUpdateGlobalLibrary = FailedToUpdateGlobalLibrary;
|
|
@@ -147,7 +147,7 @@ class DashboardManager {
|
|
|
147
147
|
return doMerge((0, lodash_1.cloneDeep)(dashboard.definition.customFields) || {}, (0, lodash_1.cloneDeep)(maybeParentDashboardCustomFields) || {}, ...(0, lodash_1.cloneDeep)(childGlobalLibrariesForDashboard).map((p) => p.library.customFields || {}), ...(0, lodash_1.cloneDeep)(parentGlobalLibrariesForDashboard).map((p) => p.library.customFields || {}));
|
|
148
148
|
}
|
|
149
149
|
static markViewsAsProtected(componentLibrary) {
|
|
150
|
-
return componentLibrary.map((view) => (Object.assign(Object.assign({}, view), { attributes: Object.assign(Object.assign({}, view.attributes), { protectedByOrganisation: true }) })));
|
|
150
|
+
return (componentLibrary || []).map((view) => (Object.assign(Object.assign({}, view), { attributes: Object.assign(Object.assign({}, view.attributes), { protectedByOrganisation: true }) })));
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
exports.DashboardManager = DashboardManager;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Vizzly } from './Vizzly';
|
|
2
|
+
import { CreateGlobalLibraryParams, GlobalLibrary, RequestParams, UpdateGlobalLibraryParams } from '../types';
|
|
3
|
+
import { GlobalLibraryType } from '../types/globalLibrary';
|
|
4
|
+
export declare class GlobalLibraryManager {
|
|
5
|
+
private vizzly;
|
|
6
|
+
constructor(vizzly: Vizzly);
|
|
7
|
+
create(params: RequestParams<CreateGlobalLibraryParams>): Promise<{
|
|
8
|
+
permissions: import("../types").GlobalLibraryPermission[];
|
|
9
|
+
global_library: GlobalLibrary;
|
|
10
|
+
}>;
|
|
11
|
+
update(params: RequestParams<UpdateGlobalLibraryParams & {
|
|
12
|
+
globalLibraryId: string;
|
|
13
|
+
}>): Promise<GlobalLibrary>;
|
|
14
|
+
getGlobalLibraries(params?: RequestParams): Promise<GlobalLibraryType>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.GlobalLibraryManager = void 0;
|
|
13
|
+
class GlobalLibraryManager {
|
|
14
|
+
constructor(vizzly) {
|
|
15
|
+
this.vizzly = vizzly;
|
|
16
|
+
}
|
|
17
|
+
create(params) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const repository = this.vizzly.getGlobalLibraryRepository();
|
|
20
|
+
return yield repository.createGlobalLibrary(params);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
update(params) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const globalLibraryRepository = this.vizzly.getGlobalLibraryRepository();
|
|
26
|
+
const { global_libraries: globalLibraries, permissions: globalLibraryPermissions } = yield globalLibraryRepository.fetchGlobalLibraries(params);
|
|
27
|
+
const globalLibraryToUpdate = globalLibraries.find((gL) => gL.id === params.globalLibraryId);
|
|
28
|
+
if (!globalLibraryToUpdate) {
|
|
29
|
+
throw new Error('Global library not found');
|
|
30
|
+
}
|
|
31
|
+
const writePermission = globalLibraryPermissions.find((permission) => permission.globalLibraryId === params.globalLibraryId && permission.scope === 'read_write');
|
|
32
|
+
if (!writePermission) {
|
|
33
|
+
throw new Error('No write permission for this library');
|
|
34
|
+
}
|
|
35
|
+
const response = yield globalLibraryRepository.updateGlobalLibrary({
|
|
36
|
+
globalLibrarySessionToken: writePermission.token,
|
|
37
|
+
library: params.library,
|
|
38
|
+
});
|
|
39
|
+
return response;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
getGlobalLibraries(params) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const repository = this.vizzly.getGlobalLibraryRepository();
|
|
45
|
+
return yield repository.fetchGlobalLibraries(params);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.GlobalLibraryManager = GlobalLibraryManager;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CreateGlobalLibraryParams, GlobalLibrary, GlobalLibraryPermission, RequestParams,
|
|
1
|
+
import { CreateGlobalLibraryParams, GlobalLibrary, GlobalLibraryPermission, RequestParams, UpdateGlobalLibraryParams } from '../types';
|
|
2
2
|
import { Vizzly } from './Vizzly';
|
|
3
3
|
export declare class GlobalLibraryRepository {
|
|
4
4
|
private vizzly;
|
|
@@ -16,9 +16,7 @@ export declare class GlobalLibraryRepository {
|
|
|
16
16
|
global_libraries: GlobalLibrary[];
|
|
17
17
|
permissions: GlobalLibraryPermission[];
|
|
18
18
|
}>;
|
|
19
|
-
updateGlobalLibrary(params: UpdateGlobalLibraryParams): Promise<
|
|
20
|
-
global_library: GlobalLibrary;
|
|
21
|
-
}>>;
|
|
19
|
+
updateGlobalLibrary(params: UpdateGlobalLibraryParams): Promise<GlobalLibrary>;
|
|
22
20
|
getChildGlobalLibrariesByParentGlobalLibraryId(parentGlobalLibraryId: string): Promise<GlobalLibrary[]>;
|
|
23
21
|
static splitParentAndChildGlobalLibraries(globalLibraries: GlobalLibrary[]): {
|
|
24
22
|
childGlobalLibraries: GlobalLibrary[];
|
|
@@ -31,4 +29,5 @@ export declare class GlobalLibraryRepository {
|
|
|
31
29
|
static mapParentToChildGlobalLibraries(globalLibraries: GlobalLibrary[]): {
|
|
32
30
|
[parentGlobalLibraryId: string]: GlobalLibrary[];
|
|
33
31
|
};
|
|
32
|
+
static upcast(globalLibrary: GlobalLibrary): GlobalLibrary;
|
|
34
33
|
}
|
|
@@ -14,6 +14,7 @@ const lodash_1 = require("lodash");
|
|
|
14
14
|
const Permission_1 = require("./Permission");
|
|
15
15
|
const FailedToFetchGlobalLibraryAccessTokens_1 = require("../errors/FailedToFetchGlobalLibraryAccessTokens");
|
|
16
16
|
const Repository_1 = require("./Repository");
|
|
17
|
+
const FailedToUpdateGlobalLibrary_1 = require("../errors/FailedToUpdateGlobalLibrary");
|
|
17
18
|
class GlobalLibraryRepository {
|
|
18
19
|
constructor(vizzly) {
|
|
19
20
|
this.vizzly = vizzly;
|
|
@@ -30,6 +31,7 @@ class GlobalLibraryRepository {
|
|
|
30
31
|
else {
|
|
31
32
|
globalLibrary = yield vizzlyApi.createGlobalLibrary(createParams);
|
|
32
33
|
}
|
|
34
|
+
globalLibrary.global_library = GlobalLibraryRepository.upcast(globalLibrary.global_library);
|
|
33
35
|
this.repo.addItem(globalLibrary.global_library, globalLibrary.permissions);
|
|
34
36
|
return globalLibrary;
|
|
35
37
|
});
|
|
@@ -54,7 +56,7 @@ class GlobalLibraryRepository {
|
|
|
54
56
|
}
|
|
55
57
|
if (accessTokens.status === 200) {
|
|
56
58
|
const formattedPermissions = accessTokens.body.permissions.map(Permission_1.Permission.formatGlobalLibraryPermission);
|
|
57
|
-
this.repo.initRepo(accessTokens.body.global_libraries, formattedPermissions);
|
|
59
|
+
this.repo.initRepo(accessTokens.body.global_libraries.map(GlobalLibraryRepository.upcast), formattedPermissions);
|
|
58
60
|
}
|
|
59
61
|
else {
|
|
60
62
|
throw new FailedToFetchGlobalLibraryAccessTokens_1.FailedToFetchGlobalLibraryAccessTokens('Failed to load access tokens for the global library.');
|
|
@@ -68,8 +70,8 @@ class GlobalLibraryRepository {
|
|
|
68
70
|
}
|
|
69
71
|
updateGlobalLibrary(params) {
|
|
70
72
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
const vizzlyApi = this.vizzly.getVizzlyAPI();
|
|
72
73
|
let updateResponse;
|
|
74
|
+
const vizzlyApi = this.vizzly.getVizzlyAPI();
|
|
73
75
|
if (this.vizzly.implementationStrategy.shouldPersistViaQueryEngine()) {
|
|
74
76
|
const vizzlyQueryEngineApi = this.vizzly.getVizzlyQueryEngineAPI();
|
|
75
77
|
updateResponse = yield vizzlyQueryEngineApi.updateGlobalLibrary(params);
|
|
@@ -77,10 +79,12 @@ class GlobalLibraryRepository {
|
|
|
77
79
|
else {
|
|
78
80
|
updateResponse = yield vizzlyApi.updateGlobalLibrary(params);
|
|
79
81
|
}
|
|
80
|
-
if (updateResponse.status
|
|
81
|
-
|
|
82
|
+
if (updateResponse.status != 200) {
|
|
83
|
+
throw new FailedToUpdateGlobalLibrary_1.FailedToUpdateGlobalLibrary(`Failed to update the global library ${updateResponse.status}`);
|
|
82
84
|
}
|
|
83
|
-
|
|
85
|
+
const globalLibrary = GlobalLibraryRepository.upcast(updateResponse.body.global_library);
|
|
86
|
+
this.repo.updateItem(globalLibrary);
|
|
87
|
+
return globalLibrary;
|
|
84
88
|
});
|
|
85
89
|
}
|
|
86
90
|
getChildGlobalLibrariesByParentGlobalLibraryId(parentGlobalLibraryId) {
|
|
@@ -123,5 +127,8 @@ class GlobalLibraryRepository {
|
|
|
123
127
|
});
|
|
124
128
|
return mapping;
|
|
125
129
|
}
|
|
130
|
+
static upcast(globalLibrary) {
|
|
131
|
+
return Object.assign(Object.assign({}, globalLibrary), { library: Object.assign({ views: [], customFields: {} }, (globalLibrary.library || {})) });
|
|
132
|
+
}
|
|
126
133
|
}
|
|
127
134
|
exports.GlobalLibraryRepository = GlobalLibraryRepository;
|
package/dist/models/Vizzly.d.ts
CHANGED
|
@@ -3,12 +3,14 @@ import { ImplementationStrategy, PersistDirectToVizzlyApi } from './Implementati
|
|
|
3
3
|
import { DashboardRepository } from './DashboardRepository';
|
|
4
4
|
import { GlobalLibraryRepository } from './GlobalLibraryRepository';
|
|
5
5
|
import { DashboardManager } from './DashboardManager';
|
|
6
|
+
import { GlobalLibraryManager } from './GlobalLibraryManager';
|
|
6
7
|
export declare class Vizzly {
|
|
7
8
|
private APIs;
|
|
8
9
|
implementationStrategy: ImplementationStrategy;
|
|
9
10
|
private dashboardRepository;
|
|
10
11
|
private globalLibraryRepository;
|
|
11
12
|
private dashboardManager;
|
|
13
|
+
private globalLibraryManager;
|
|
12
14
|
constructor(APIs: PartialBy<APIs, 'vizzlyQueryEngineApi'>, implementationStrategy: PersistDirectToVizzlyApi);
|
|
13
15
|
getAPIs(): APIs | PartialBy<APIs, 'vizzlyQueryEngineApi'>;
|
|
14
16
|
getVizzlyAppApi(): import("./VizzlyAppApi").VizzlyAppApi;
|
|
@@ -17,4 +19,5 @@ export declare class Vizzly {
|
|
|
17
19
|
getDashboardRepository(): DashboardRepository;
|
|
18
20
|
getGlobalLibraryRepository(): GlobalLibraryRepository;
|
|
19
21
|
getDashboardManager(): DashboardManager;
|
|
22
|
+
getGlobalLibraryManager(): GlobalLibraryManager;
|
|
20
23
|
}
|
package/dist/models/Vizzly.js
CHANGED
|
@@ -5,6 +5,7 @@ const MissingRequiredVizzlyQueryEngineApi_1 = require("../errors/MissingRequired
|
|
|
5
5
|
const DashboardRepository_1 = require("./DashboardRepository");
|
|
6
6
|
const GlobalLibraryRepository_1 = require("./GlobalLibraryRepository");
|
|
7
7
|
const DashboardManager_1 = require("./DashboardManager");
|
|
8
|
+
const GlobalLibraryManager_1 = require("./GlobalLibraryManager");
|
|
8
9
|
class Vizzly {
|
|
9
10
|
constructor(APIs, implementationStrategy) {
|
|
10
11
|
this.APIs = APIs;
|
|
@@ -12,6 +13,7 @@ class Vizzly {
|
|
|
12
13
|
this.dashboardManager = new DashboardManager_1.DashboardManager(this);
|
|
13
14
|
this.dashboardRepository = new DashboardRepository_1.DashboardRepository(this);
|
|
14
15
|
this.globalLibraryRepository = new GlobalLibraryRepository_1.GlobalLibraryRepository(this);
|
|
16
|
+
this.globalLibraryManager = new GlobalLibraryManager_1.GlobalLibraryManager(this);
|
|
15
17
|
}
|
|
16
18
|
getAPIs() {
|
|
17
19
|
if (this.implementationStrategy.shouldPersistViaQueryEngine() && !this.APIs.vizzlyQueryEngineApi) {
|
|
@@ -37,5 +39,8 @@ class Vizzly {
|
|
|
37
39
|
getDashboardManager() {
|
|
38
40
|
return this.dashboardManager;
|
|
39
41
|
}
|
|
42
|
+
getGlobalLibraryManager() {
|
|
43
|
+
return this.globalLibraryManager;
|
|
44
|
+
}
|
|
40
45
|
}
|
|
41
46
|
exports.Vizzly = Vizzly;
|