@vizzly/api-client 0.0.25 → 0.0.27

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 FailedToUpdateGlobalLibrary extends Error {
2
+ constructor(message: string);
3
+ }
@@ -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;
@@ -46,8 +46,6 @@ class Authentication {
46
46
  }
47
47
  buildAuthHeaders(acceptedAuthParams) {
48
48
  let usableAuthParams = acceptedAuthParams ? (0, lodash_1.pick)(this.authParams, acceptedAuthParams) : this.authParams;
49
- console.log('usableAuthParams', usableAuthParams);
50
- // let usableAuthParams = this.authParams;
51
49
  if (usableAuthParams.dashboardAccessToken) {
52
50
  return {
53
51
  auth: `Bearer ${usableAuthParams.dashboardAccessToken}`,
@@ -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;
@@ -20,4 +20,5 @@ export declare class DashboardRepository {
20
20
  dashboards: Dashboard[];
21
21
  permissions: DashboardPermission[];
22
22
  }>;
23
+ clearRepo(): void;
23
24
  }
@@ -123,5 +123,8 @@ class DashboardRepository {
123
123
  };
124
124
  });
125
125
  }
126
+ clearRepo() {
127
+ this.repo.clear();
128
+ }
126
129
  }
127
130
  exports.DashboardRepository = DashboardRepository;
@@ -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, Response, UpdateGlobalLibraryParams } from '../types';
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<Response<{
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[];
@@ -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;
@@ -68,8 +69,8 @@ class GlobalLibraryRepository {
68
69
  }
69
70
  updateGlobalLibrary(params) {
70
71
  return __awaiter(this, void 0, void 0, function* () {
71
- const vizzlyApi = this.vizzly.getVizzlyAPI();
72
72
  let updateResponse;
73
+ const vizzlyApi = this.vizzly.getVizzlyAPI();
73
74
  if (this.vizzly.implementationStrategy.shouldPersistViaQueryEngine()) {
74
75
  const vizzlyQueryEngineApi = this.vizzly.getVizzlyQueryEngineAPI();
75
76
  updateResponse = yield vizzlyQueryEngineApi.updateGlobalLibrary(params);
@@ -80,7 +81,10 @@ class GlobalLibraryRepository {
80
81
  if (updateResponse.status === 200) {
81
82
  this.repo.updateItem(updateResponse.body.global_library);
82
83
  }
83
- return updateResponse;
84
+ else {
85
+ throw new FailedToUpdateGlobalLibrary_1.FailedToUpdateGlobalLibrary(`Failed to update the global library ${updateResponse.status}`);
86
+ }
87
+ return updateResponse.body["global_library"];
84
88
  });
85
89
  }
86
90
  getChildGlobalLibrariesByParentGlobalLibraryId(parentGlobalLibraryId) {
@@ -14,4 +14,5 @@ export declare class Repository<StoreType, PermissionType extends {
14
14
  updateItem(newValue: StoreType): void;
15
15
  isPopulated(): boolean;
16
16
  private permissionsAreFresh;
17
+ clear(): void;
17
18
  }
@@ -43,5 +43,9 @@ class Repository {
43
43
  return Permission_1.Permission.validateJwtExpiry(permission.token);
44
44
  });
45
45
  }
46
+ clear() {
47
+ this.storedItems = [];
48
+ this.permissions = [];
49
+ }
46
50
  }
47
51
  exports.Repository = Repository;
@@ -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
  }
@@ -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;
@@ -0,0 +1,5 @@
1
+ import { GlobalLibrary, GlobalLibraryPermission } from '../types';
2
+ export type GlobalLibraryType = {
3
+ global_libraries: GlobalLibrary[];
4
+ permissions: GlobalLibraryPermission[];
5
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizzly/api-client",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "private": false,
5
5
  "license": "NONE",
6
6
  "source": "src/index.ts",