@vizzly/api-client 0.0.12 → 0.0.14
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/FailedToFetchVizzlyConfig.d.ts +3 -0
- package/dist/errors/FailedToFetchVizzlyConfig.js +10 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/models/Api.js +3 -2
- package/dist/models/Authentication.d.ts +1 -0
- package/dist/models/Authentication.js +3 -24
- package/dist/models/Monitor.d.ts +3 -0
- package/dist/models/Monitor.js +28 -0
- package/dist/models/VizzlyApi.d.ts +12 -3
- package/dist/models/VizzlyApi.js +8 -1
- package/dist/models/VizzlyApiClientLogger.d.ts +15 -0
- package/dist/models/VizzlyApiClientLogger.js +29 -0
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FailedToFetchVizzlyConfig = void 0;
|
|
4
|
+
class FailedToFetchVizzlyConfig extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'FailedToFetchVizzlyConfig';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.FailedToFetchVizzlyConfig = FailedToFetchVizzlyConfig;
|
package/dist/errors/index.d.ts
CHANGED
package/dist/errors/index.js
CHANGED
|
@@ -27,3 +27,4 @@ __exportStar(require("./FailedToResolveDataSets"), exports);
|
|
|
27
27
|
__exportStar(require("./FailedToCreateGlobalLibrary"), exports);
|
|
28
28
|
__exportStar(require("./FailedToDecryptDashboardBeforeClient"), exports);
|
|
29
29
|
__exportStar(require("./FailedToUpdateDashboard"), exports);
|
|
30
|
+
__exportStar(require("./FailedToFetchVizzlyConfig"), exports);
|
package/dist/index.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ export * from './models/VizzlyAppApi';
|
|
|
4
4
|
export * from './models/VizzlyQueryEngineApi';
|
|
5
5
|
export * from './models/Authentication';
|
|
6
6
|
export * from './models/ImplementationStrategy';
|
|
7
|
+
export * from './models/VizzlyApiClientLogger';
|
|
7
8
|
export * from './types';
|
|
8
9
|
export * as Errors from './errors';
|
package/dist/index.js
CHANGED
|
@@ -33,5 +33,6 @@ __exportStar(require("./models/VizzlyAppApi"), exports);
|
|
|
33
33
|
__exportStar(require("./models/VizzlyQueryEngineApi"), exports);
|
|
34
34
|
__exportStar(require("./models/Authentication"), exports);
|
|
35
35
|
__exportStar(require("./models/ImplementationStrategy"), exports);
|
|
36
|
+
__exportStar(require("./models/VizzlyApiClientLogger"), exports);
|
|
36
37
|
__exportStar(require("./types"), exports);
|
|
37
38
|
exports.Errors = __importStar(require("./errors"));
|
package/dist/models/Api.js
CHANGED
|
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.Api = void 0;
|
|
16
16
|
const isomorphic_fetch_1 = __importDefault(require("isomorphic-fetch"));
|
|
17
|
+
const Monitor_1 = require("./Monitor");
|
|
17
18
|
class Api {
|
|
18
19
|
constructor(auth, host, extraHeaders = () => ({})) {
|
|
19
20
|
this.host = host;
|
|
@@ -26,8 +27,8 @@ class Api {
|
|
|
26
27
|
const authHeaders = this.auth.buildAuthHeaders();
|
|
27
28
|
const customHeaders = Object.assign(Object.assign({}, (request.headers || {})), (this.extraHeaders() || {}));
|
|
28
29
|
const path = `${this.host}${request.path}`;
|
|
29
|
-
|
|
30
|
-
const res = yield (
|
|
30
|
+
const timedFetch = Monitor_1.Monitor.timeRequest(request.method, path, isomorphic_fetch_1.default);
|
|
31
|
+
const res = yield timedFetch(path, {
|
|
31
32
|
method: request.method,
|
|
32
33
|
headers: Object.assign(Object.assign({ 'Content-Type': 'application/json', Accept: 'application/json' }, authHeaders), customHeaders),
|
|
33
34
|
redirect: 'follow',
|
|
@@ -3,6 +3,7 @@ export declare class Authentication {
|
|
|
3
3
|
private authParams;
|
|
4
4
|
constructor(authParams: AuthParams);
|
|
5
5
|
updateAuthParams(authParams: Partial<AuthParams>): void;
|
|
6
|
+
clearAuthParams(): void;
|
|
6
7
|
getQueryEngineAccessToken(): string;
|
|
7
8
|
getProjectAdminOverrideToken(): string | undefined;
|
|
8
9
|
getDashboardAccessToken(): string;
|
|
@@ -9,6 +9,9 @@ class Authentication {
|
|
|
9
9
|
updateAuthParams(authParams) {
|
|
10
10
|
this.authParams = Object.assign(Object.assign({}, this.authParams), authParams);
|
|
11
11
|
}
|
|
12
|
+
clearAuthParams() {
|
|
13
|
+
this.authParams = {};
|
|
14
|
+
}
|
|
12
15
|
getQueryEngineAccessToken() {
|
|
13
16
|
if (!this.authParams.queryEngineAccessToken)
|
|
14
17
|
throw new MissingAuthParameter_1.MissingAuthParameter('queryEngineAccessToken');
|
|
@@ -64,30 +67,6 @@ class Authentication {
|
|
|
64
67
|
auth: `Bearer ${this.authParams.appSessionToken}`,
|
|
65
68
|
};
|
|
66
69
|
}
|
|
67
|
-
// Try without this extra logic to fetch the project tokens...
|
|
68
|
-
// else if (request.preFetchProjectAccessTokens && (config.useCookieAuth || !!config.appSessionAuthToken)) {
|
|
69
|
-
// logDebug(
|
|
70
|
-
// 'Fetching project access token from the Vizzly API',
|
|
71
|
-
// request.preFetchProjectAccessTokens.projectId,
|
|
72
|
-
// 'Filtering by',
|
|
73
|
-
// request.preFetchProjectAccessTokens.resourceFilters
|
|
74
|
-
// );
|
|
75
|
-
// const accessToken = await getProjectAccessToken(httpClient(config))(
|
|
76
|
-
// request.preFetchProjectAccessTokens.projectId,
|
|
77
|
-
// config.appSessionAuthToken,
|
|
78
|
-
// request.preFetchProjectAccessTokens.resourceFilters
|
|
79
|
-
// );
|
|
80
|
-
// if (accessToken) {
|
|
81
|
-
// logDebug('Project access token received.');
|
|
82
|
-
// return {
|
|
83
|
-
// auth: `Bearer ${accessToken}`,
|
|
84
|
-
// };
|
|
85
|
-
// } else {
|
|
86
|
-
// logDebug('Failed to receive project access token.');
|
|
87
|
-
// }
|
|
88
|
-
// } else {
|
|
89
|
-
// logDebug('Not pre-fetching project access token.');
|
|
90
|
-
// }
|
|
91
70
|
return {};
|
|
92
71
|
}
|
|
93
72
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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.Monitor = void 0;
|
|
13
|
+
const VizzlyApiClientLogger_1 = require("./VizzlyApiClientLogger");
|
|
14
|
+
class Monitor {
|
|
15
|
+
static timeRequest(method, path, asyncFunction) {
|
|
16
|
+
return function (...args) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const start = performance.now();
|
|
19
|
+
const result = yield asyncFunction(...args);
|
|
20
|
+
const stop = performance.now();
|
|
21
|
+
const duration = stop - start;
|
|
22
|
+
VizzlyApiClientLogger_1.VizzlyApiClientLogger.debug(`[@vizzly/api-client timing] ${method.toUpperCase()} ${path} - ${duration.toFixed(2)}ms`);
|
|
23
|
+
return result;
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.Monitor = Monitor;
|
|
@@ -42,7 +42,9 @@ export declare class VizzlyApi extends Api {
|
|
|
42
42
|
buildCreateGlobalLibraryRequest(params: CreateGlobalLibraryParams): Request<{}>;
|
|
43
43
|
getProjects(): Promise<import("../types").Response<unknown>>;
|
|
44
44
|
buildGetProjectsRequest(): Request<{}>;
|
|
45
|
-
createProjectApiKey(params: nVizzlyApi.CreateProjectApiKeyParams): Promise<import("../types").Response<
|
|
45
|
+
createProjectApiKey(params: nVizzlyApi.CreateProjectApiKeyParams): Promise<import("../types").Response<{
|
|
46
|
+
api_key: string;
|
|
47
|
+
}>>;
|
|
46
48
|
buildCreateProjectApiKeyRequest(params: nVizzlyApi.CreateProjectApiKeyParams): Request<{}>;
|
|
47
49
|
createQueryEngineUser(params: nVizzlyApi.CreateQueryEngineUserParams): Promise<import("../types").Response<unknown>>;
|
|
48
50
|
buildCreateQueryEngineUserRequest(params: nVizzlyApi.CreateQueryEngineUserParams): Request<{}>;
|
|
@@ -61,13 +63,20 @@ export declare class VizzlyApi extends Api {
|
|
|
61
63
|
buildGetManagedQueryEngineKeyPairRequest(params: nVizzlyApi.GetManagedQueryEngineKeyPairParams): Request<{}>;
|
|
62
64
|
getProject(params: nVizzlyApi.GetProjectParams): Promise<import("../types").Response<unknown>>;
|
|
63
65
|
buildGetProjectRequest(params: nVizzlyApi.GetProjectParams): Request<{}>;
|
|
64
|
-
getProjectAccessToken(params: nVizzlyApi.GetProjectAccessTokenParams): Promise<import("../types").Response<
|
|
66
|
+
getProjectAccessToken(params: nVizzlyApi.GetProjectAccessTokenParams): Promise<import("../types").Response<{
|
|
67
|
+
token: {
|
|
68
|
+
max_age: number;
|
|
69
|
+
token: string;
|
|
70
|
+
};
|
|
71
|
+
}>>;
|
|
65
72
|
buildGetProjectAccessTokenRequest(params: nVizzlyApi.GetProjectAccessTokenParams): Request<{}>;
|
|
66
73
|
getQueryEngineUser(params: nVizzlyApi.GetQueryEngineUserParams): Promise<import("../types").Response<unknown>>;
|
|
67
74
|
buildGetQueryEngineUserRequest(params: nVizzlyApi.GetQueryEngineUserParams): Request<{}>;
|
|
68
75
|
getTeamMembers(params: nVizzlyApi.GetTeamMembers): Promise<import("../types").Response<unknown>>;
|
|
69
76
|
buildGetTeamMembersRequest(params: nVizzlyApi.GetTeamMembers): Request<{}>;
|
|
70
|
-
getVizzlyConfig(params: nVizzlyApi.GetVizzlyConfigParams): Promise<
|
|
77
|
+
getVizzlyConfig(params: nVizzlyApi.GetVizzlyConfigParams): Promise<{
|
|
78
|
+
encryptedConfig: string | null;
|
|
79
|
+
}>;
|
|
71
80
|
buildGetVizzlyConfigRequest(params: nVizzlyApi.GetVizzlyConfigParams): Request<{}>;
|
|
72
81
|
saveConnection(params: nVizzlyApi.SaveConnectionParams): Promise<import("../types").Response<unknown>>;
|
|
73
82
|
buildSaveConnectionRequest(params: nVizzlyApi.SaveConnectionParams): Request<{}>;
|
package/dist/models/VizzlyApi.js
CHANGED
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.VizzlyApi = void 0;
|
|
13
13
|
const Api_1 = require("./Api");
|
|
14
14
|
const errors_1 = require("../errors");
|
|
15
|
+
const FailedToFetchVizzlyConfig_1 = require("../errors/FailedToFetchVizzlyConfig");
|
|
15
16
|
class VizzlyApi extends Api_1.Api {
|
|
16
17
|
constructor(auth, host = 'https://api.vizzly.co') {
|
|
17
18
|
super(auth, host);
|
|
@@ -303,7 +304,13 @@ class VizzlyApi extends Api_1.Api {
|
|
|
303
304
|
}
|
|
304
305
|
getVizzlyConfig(params) {
|
|
305
306
|
return __awaiter(this, void 0, void 0, function* () {
|
|
306
|
-
|
|
307
|
+
const response = yield this.execute(this.buildGetVizzlyConfigRequest(params));
|
|
308
|
+
if (response.status === 200) {
|
|
309
|
+
return {
|
|
310
|
+
encryptedConfig: response.body.encrypted_config,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
throw new FailedToFetchVizzlyConfig_1.FailedToFetchVizzlyConfig(`Failed to fetch the config containing data sets from the Vizzly API. Got status ${response.status}`);
|
|
307
314
|
});
|
|
308
315
|
}
|
|
309
316
|
buildGetVizzlyConfigRequest(params) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type LoggerBackend = {
|
|
2
|
+
debug: (...args: any) => void;
|
|
3
|
+
info: (...args: any) => void;
|
|
4
|
+
warning: (...args: any) => void;
|
|
5
|
+
error: (...args: any) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare class VizzlyApiClientLogger {
|
|
8
|
+
private static backend;
|
|
9
|
+
static setBackend(backend: LoggerBackend): void;
|
|
10
|
+
static debug(...args: any): void;
|
|
11
|
+
static info(...args: any): void;
|
|
12
|
+
static warning(...args: any): void;
|
|
13
|
+
static error(...args: any): void;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VizzlyApiClientLogger = void 0;
|
|
4
|
+
class VizzlyApiClientLogger {
|
|
5
|
+
static setBackend(backend) {
|
|
6
|
+
this.backend = backend;
|
|
7
|
+
}
|
|
8
|
+
static debug(...args) {
|
|
9
|
+
if (VizzlyApiClientLogger.backend) {
|
|
10
|
+
VizzlyApiClientLogger.backend.debug(...args);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
static info(...args) {
|
|
14
|
+
if (VizzlyApiClientLogger.backend) {
|
|
15
|
+
VizzlyApiClientLogger.backend.info(...args);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
static warning(...args) {
|
|
19
|
+
if (VizzlyApiClientLogger.backend) {
|
|
20
|
+
VizzlyApiClientLogger.backend.warning(...args);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
static error(...args) {
|
|
24
|
+
if (VizzlyApiClientLogger.backend) {
|
|
25
|
+
VizzlyApiClientLogger.backend.error(...args);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.VizzlyApiClientLogger = VizzlyApiClientLogger;
|