@vizzly/api-client 0.0.33 → 0.0.35
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 +1 -0
- package/dist/index.js +1 -0
- package/dist/models/Api.d.ts +1 -0
- package/dist/models/Api.js +14 -2
- package/dist/models/Path.d.ts +9 -0
- package/dist/models/Path.js +47 -0
- package/package.json +1 -1
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.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ export declare class Api {
|
|
|
6
6
|
protected auth: Authentication;
|
|
7
7
|
constructor(auth: Authentication, host: string, extraHeaders?: () => {});
|
|
8
8
|
execute<ResponseBody>(request: Request<any>): Promise<Response<ResponseBody>>;
|
|
9
|
+
originApp(): string;
|
|
9
10
|
getAuth(): Authentication;
|
|
10
11
|
}
|
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,11 +28,11 @@ 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,
|
|
34
|
-
headers: Object.assign(Object.assign({ 'Content-Type': 'application/json', Accept: 'application/json', 'Vizzly-User-Agent': `${VizzlyApiClientLogger_1.VizzlyApiClientLogger.UserAgentProduct} (Using client ${(_a = require('../../package.json')) === null || _a === void 0 ? void 0 : _a.version})` }, authHeaders), customHeaders),
|
|
35
|
+
headers: Object.assign(Object.assign({ 'Content-Type': 'application/json', Accept: 'application/json', 'Vizzly-User-Agent': `${VizzlyApiClientLogger_1.VizzlyApiClientLogger.UserAgentProduct}${this.originApp()} (Using client ${(_a = require('../../package.json')) === null || _a === void 0 ? void 0 : _a.version})` }, authHeaders), customHeaders),
|
|
35
36
|
redirect: 'follow',
|
|
36
37
|
referrerPolicy: 'no-referrer',
|
|
37
38
|
body: request.body ? JSON.stringify(request.body) : null,
|
|
@@ -47,6 +48,17 @@ class Api {
|
|
|
47
48
|
return { body: body, status: res.status, headers: res.headers };
|
|
48
49
|
});
|
|
49
50
|
}
|
|
51
|
+
originApp() {
|
|
52
|
+
const isServer = !(typeof window != 'undefined' && window.document);
|
|
53
|
+
if (isServer) {
|
|
54
|
+
const testApp = process.env['NODE_ENV'] === 'test' ? 'tests' : '';
|
|
55
|
+
const origin = process.env['VIZZLY_ORIGIN_APP'] || testApp || '';
|
|
56
|
+
if (origin == '')
|
|
57
|
+
return '';
|
|
58
|
+
return ` (${origin})`;
|
|
59
|
+
}
|
|
60
|
+
return '';
|
|
61
|
+
}
|
|
50
62
|
getAuth() {
|
|
51
63
|
return this.auth;
|
|
52
64
|
}
|
|
@@ -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;
|