@vizzly/api-client 0.0.34 → 0.0.36
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/index.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ export * from './models/VizzlyQueryEngineApi';
|
|
|
5
5
|
export * from './models/Authentication';
|
|
6
6
|
export * from './models/ImplementationStrategy';
|
|
7
7
|
export * from './models/VizzlyApiClientLogger';
|
|
8
|
+
export * from './models/Path';
|
|
8
9
|
export * from './types';
|
|
9
10
|
export * as Errors from './errors';
|
package/dist/index.js
CHANGED
|
@@ -34,5 +34,6 @@ __exportStar(require("./models/VizzlyQueryEngineApi"), exports);
|
|
|
34
34
|
__exportStar(require("./models/Authentication"), exports);
|
|
35
35
|
__exportStar(require("./models/ImplementationStrategy"), exports);
|
|
36
36
|
__exportStar(require("./models/VizzlyApiClientLogger"), exports);
|
|
37
|
+
__exportStar(require("./models/Path"), exports);
|
|
37
38
|
__exportStar(require("./types"), exports);
|
|
38
39
|
exports.Errors = __importStar(require("./errors"));
|
package/dist/models/Api.js
CHANGED
|
@@ -16,6 +16,7 @@ exports.Api = void 0;
|
|
|
16
16
|
const isomorphic_fetch_1 = __importDefault(require("isomorphic-fetch"));
|
|
17
17
|
const Monitor_1 = require("./Monitor");
|
|
18
18
|
const VizzlyApiClientLogger_1 = require("./VizzlyApiClientLogger");
|
|
19
|
+
const Path_1 = require("./Path");
|
|
19
20
|
class Api {
|
|
20
21
|
constructor(auth, host, extraHeaders = () => ({})) {
|
|
21
22
|
this.host = host;
|
|
@@ -27,7 +28,7 @@ class Api {
|
|
|
27
28
|
var _a, _b;
|
|
28
29
|
const authHeaders = this.auth.buildAuthHeaders(request.acceptedAuthParams);
|
|
29
30
|
const customHeaders = Object.assign(Object.assign({}, (request.headers || {})), (this.extraHeaders() || {}));
|
|
30
|
-
const path =
|
|
31
|
+
const path = Path_1.Path.buildPath(this.host, request.path);
|
|
31
32
|
const timedFetch = Monitor_1.Monitor.timeRequest(request.method, path, isomorphic_fetch_1.default);
|
|
32
33
|
const res = yield timedFetch(path, {
|
|
33
34
|
method: request.method,
|
|
@@ -41,7 +42,7 @@ class Api {
|
|
|
41
42
|
const queryEngineRequestId = res.headers.get('vizzly-query-engine-request-id') || '-';
|
|
42
43
|
const vizzlyApiRequestId = res.headers.get('x-request-id') || '-';
|
|
43
44
|
if (res.status === 500) {
|
|
44
|
-
|
|
45
|
+
VizzlyApiClientLogger_1.VizzlyApiClientLogger.debug(`[TRACING] QE; ${queryEngineRequestId} - API; ${vizzlyApiRequestId}`);
|
|
45
46
|
}
|
|
46
47
|
VizzlyApiClientLogger_1.VizzlyApiClientLogger.debug(`[TRACING] QE; ${queryEngineRequestId} - API; ${vizzlyApiRequestId}`);
|
|
47
48
|
return { body: body, status: res.status, headers: res.headers };
|
|
@@ -50,7 +51,8 @@ class Api {
|
|
|
50
51
|
originApp() {
|
|
51
52
|
const isServer = !(typeof window != 'undefined' && window.document);
|
|
52
53
|
if (isServer) {
|
|
53
|
-
const
|
|
54
|
+
const testApp = process.env['NODE_ENV'] === 'test' ? 'tests' : '';
|
|
55
|
+
const origin = process.env['VIZZLY_ORIGIN_APP'] || testApp || '';
|
|
54
56
|
if (origin == '')
|
|
55
57
|
return '';
|
|
56
58
|
return ` (${origin})`;
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.DashboardManager = void 0;
|
|
13
13
|
const lodash_1 = require("lodash");
|
|
14
14
|
const GlobalLibraryRepository_1 = require("./GlobalLibraryRepository");
|
|
15
|
+
const VizzlyApiClientLogger_1 = require("./VizzlyApiClientLogger");
|
|
15
16
|
class DashboardManager {
|
|
16
17
|
constructor(vizzly) {
|
|
17
18
|
this.vizzly = vizzly;
|
|
@@ -77,7 +78,7 @@ class DashboardManager {
|
|
|
77
78
|
var _d;
|
|
78
79
|
const writePermission = globalLibraryPermissions.find((permission) => permission.globalLibraryId === gL.id && permission.scope === 'read_write');
|
|
79
80
|
if (!writePermission)
|
|
80
|
-
|
|
81
|
+
VizzlyApiClientLogger_1.VizzlyApiClientLogger.error('No write permission found.');
|
|
81
82
|
if (writePermission) {
|
|
82
83
|
yield globalLibraryRepository.updateGlobalLibrary({
|
|
83
84
|
globalLibrarySessionToken: writePermission.token,
|
|
@@ -47,7 +47,6 @@ class DashboardRepository {
|
|
|
47
47
|
throw new DashboardQuotaReached_1.DashboardQuotaReached(`Dashboard quota reached; ${JSON.stringify(builtDashboard.body)}`);
|
|
48
48
|
}
|
|
49
49
|
if (builtDashboard.status != 200) {
|
|
50
|
-
console.log();
|
|
51
50
|
throw new FailedToCreateDashboard_1.FailedToCreateDashboard(`Failed to create the dashboard from POST /api/v2/dashboard. Got ${builtDashboard.status}`);
|
|
52
51
|
}
|
|
53
52
|
throw new FailedToCreateDashboard_1.FailedToCreateDashboard(`Unknown failure. Got status ${builtDashboard.status}`);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class Path {
|
|
2
|
+
static removeAnyWrappingForwardSlash(str: string): string;
|
|
3
|
+
static baseIsValid(base: string): boolean;
|
|
4
|
+
static buildPath(basePath: string, route: string): string;
|
|
5
|
+
static addQueryParam(absoluteUrl: string, key: string, value: string): string;
|
|
6
|
+
static hasHashtag(absoluteUrl: string): boolean;
|
|
7
|
+
static setVizzlyHashtagValue(absoluteUrl: string, value: string): string;
|
|
8
|
+
static getVizzlyHashtagValue(absoluteUrl: string): string | null;
|
|
9
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Path = void 0;
|
|
4
|
+
class Path {
|
|
5
|
+
static removeAnyWrappingForwardSlash(str) {
|
|
6
|
+
if (str.startsWith('/')) {
|
|
7
|
+
return Path.removeAnyWrappingForwardSlash(str.slice(1));
|
|
8
|
+
}
|
|
9
|
+
if (str.endsWith('/')) {
|
|
10
|
+
return Path.removeAnyWrappingForwardSlash(str.slice(0, -1));
|
|
11
|
+
}
|
|
12
|
+
return str;
|
|
13
|
+
}
|
|
14
|
+
static baseIsValid(base) {
|
|
15
|
+
return base.startsWith('https://') || base.startsWith('http://') || base.startsWith('.');
|
|
16
|
+
}
|
|
17
|
+
static buildPath(basePath, route) {
|
|
18
|
+
const trimmedBase = Path.removeAnyWrappingForwardSlash(basePath);
|
|
19
|
+
const trimmedRoute = Path.removeAnyWrappingForwardSlash(route);
|
|
20
|
+
const prefix = Path.baseIsValid(basePath) ? '' : '/';
|
|
21
|
+
if (trimmedBase == '' && trimmedRoute == '')
|
|
22
|
+
return '/';
|
|
23
|
+
if (trimmedRoute == '')
|
|
24
|
+
return `${prefix}${trimmedBase}`;
|
|
25
|
+
if (trimmedBase != '' && trimmedRoute != '')
|
|
26
|
+
return `${prefix}${trimmedBase}/${trimmedRoute}`;
|
|
27
|
+
return `${prefix}${trimmedRoute}`;
|
|
28
|
+
}
|
|
29
|
+
static addQueryParam(absoluteUrl, key, value) {
|
|
30
|
+
const [beforeHash, afterHash] = absoluteUrl.split('#');
|
|
31
|
+
const [before, after] = beforeHash.split('?');
|
|
32
|
+
var searchParams = new URLSearchParams(after);
|
|
33
|
+
searchParams.set(key, value);
|
|
34
|
+
var newUrlWithQueryParam = before + '?' + searchParams.toString() + (afterHash ? `#${afterHash}` : '');
|
|
35
|
+
return newUrlWithQueryParam;
|
|
36
|
+
}
|
|
37
|
+
static hasHashtag(absoluteUrl) {
|
|
38
|
+
return absoluteUrl.includes('#');
|
|
39
|
+
}
|
|
40
|
+
static setVizzlyHashtagValue(absoluteUrl, value) {
|
|
41
|
+
return `${absoluteUrl}#vizzly_${value}`;
|
|
42
|
+
}
|
|
43
|
+
static getVizzlyHashtagValue(absoluteUrl) {
|
|
44
|
+
return absoluteUrl.split('#vizzly_')[1] || null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.Path = Path;
|