@vizzly/api-client 0.0.12 → 0.0.13
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.js +3 -2
- package/dist/models/Monitor.d.ts +3 -0
- package/dist/models/Monitor.js +28 -0
- package/dist/models/VizzlyApiClientLogger.d.ts +15 -0
- package/dist/models/VizzlyApiClientLogger.js +29 -0
- package/package.json +1 -1
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',
|
|
@@ -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;
|
|
@@ -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;
|