bizzabo-api
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -6,3 +6,2 @@ export interface Token { | ||
export declare class Authentication { | ||
private baseAuthUrl; | ||
private clientId; | ||
@@ -12,4 +11,7 @@ private accountId; | ||
private apiAudience; | ||
private readonly instance; | ||
constructor(clientId: string, clientSecret: string, accountId: number, apiAudience?: string, baseAuthUrl?: string); | ||
getToken(): Promise<Token>; | ||
private _handleRequest; | ||
private _handleError; | ||
} |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -47,3 +58,13 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
if (baseAuthUrl === void 0) { baseAuthUrl = DEFAULT_AUTH_BASE_URL; } | ||
this.baseAuthUrl = baseAuthUrl; | ||
this._handleRequest = function (config) { | ||
var fixedHeaders = { | ||
'User-Agent': "Bizzabo-JS-Sdk-V1", | ||
}; | ||
var headers = __assign(__assign({}, config.headers), fixedHeaders); | ||
return __assign(__assign({}, config), { headers: headers }); | ||
}; | ||
this._handleError = function (error) { | ||
console.error(error.response.data); | ||
return Promise.reject(JSON.stringify(error.response.data)); | ||
}; | ||
this.clientId = clientId; | ||
@@ -53,10 +74,14 @@ this.accountId = accountId; | ||
this.apiAudience = apiAudience; | ||
this.instance = axios_1.default.create({ | ||
baseURL: baseAuthUrl, | ||
}); | ||
this.instance.interceptors.request.use(this._handleRequest, function (error) { return error; }); | ||
this.instance.interceptors.response.use(function (response) { return response; }, this._handleError); | ||
} | ||
Authentication.prototype.getToken = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var oauthPayload, resp, returnedToken, error_1; | ||
var oauthPayload, resp, returnedToken; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
oauthPayload = { | ||
@@ -69,3 +94,3 @@ grant_type: 'client_credentials', | ||
}; | ||
return [4 /*yield*/, axios_1.default.post("".concat(this.baseAuthUrl, "/oauth/token"), oauthPayload)]; | ||
return [4 /*yield*/, this.instance.post('/oauth/token', oauthPayload)]; | ||
case 1: | ||
@@ -78,7 +103,2 @@ resp = _a.sent(); | ||
}]; | ||
case 2: | ||
error_1 = _a.sent(); | ||
console.error(error_1); | ||
throw Error('Not Authorized'); | ||
case 3: return [2 /*return*/]; | ||
} | ||
@@ -85,0 +105,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
import { AxiosInstance, AxiosResponse, AxiosError } from 'axios'; | ||
import { AxiosInstance, AxiosError } from 'axios'; | ||
import { Token } from './auth/token'; | ||
@@ -9,6 +9,3 @@ export declare abstract class HttpClient { | ||
private _handleRequest; | ||
protected handleResponse: (response: AxiosResponse) => AxiosResponse<any, any>; | ||
protected handleError: (error: AxiosError) => Promise<never>; | ||
private _initializeRequestInterceptor; | ||
private _initializeResponseInterceptor; | ||
} |
@@ -28,15 +28,6 @@ "use strict"; | ||
}; | ||
this.handleResponse = function (response) { | ||
return response; | ||
}; | ||
this.handleError = function (error) { | ||
console.error(error.response.data); | ||
return Promise.reject(error); | ||
return Promise.reject(JSON.stringify(error.response.data)); | ||
}; | ||
this._initializeRequestInterceptor = function () { | ||
_this.instance.interceptors.request.use(_this._handleRequest, _this.handleError); | ||
}; | ||
this._initializeResponseInterceptor = function () { | ||
_this.instance.interceptors.response.use(_this.handleResponse, _this.handleError); | ||
}; | ||
this.instance = axios_1.default.create({ | ||
@@ -48,4 +39,4 @@ baseURL: DEFAULT_API_BASE_URL, | ||
} | ||
this._initializeRequestInterceptor(); | ||
this._initializeResponseInterceptor(); | ||
this.instance.interceptors.request.use(this._handleRequest, function (error) { return error; }); | ||
this.instance.interceptors.response.use(function (response) { return response; }, this.handleError); | ||
} | ||
@@ -52,0 +43,0 @@ HttpClient.prototype.setToken = function (token) { |
{ | ||
"name": "bizzabo-api", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "The Bizzabo API is a Typescript client that allows calling Bizzabo public APIs", | ||
@@ -5,0 +5,0 @@ "author": "Bizzabo", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32523
610