eh-api-client
Advanced tools
Comparing version 0.49.0 to 0.50.0
@@ -19,2 +19,3 @@ // Type definitions for eh-api-client 0.24.0 | ||
get<T extends any>(options: Options, cb?: Callback<T>): Promise<T>; | ||
get<T extends any>(options: Options, body: unknown, cb?: Callback<T>): Promise<T>; | ||
post<T extends any>(options: Options, cb?: Callback<T>): Promise<T>; | ||
@@ -33,2 +34,3 @@ post<T extends any>(options: Options, body: unknown, cb?: Callback<T>): Promise<T>; | ||
setHeaders(headers: Record<string, string>): void; | ||
setAuthBearerToken(token: string): void | ||
prototype: Client; | ||
@@ -58,2 +60,3 @@ } | ||
getClient(userId: number, app: string): Client; | ||
getClientWithAuthBearerToken(token: string): Client; | ||
getRawClient(): Client; | ||
@@ -60,0 +63,0 @@ get<T extends any>(options: Options, cb?: Callback<T>): Promise<T>; |
14
index.js
@@ -149,3 +149,17 @@ var | ||
/** | ||
* @param {string} token | ||
*/ | ||
Factory.prototype.getClientWithAuthBearerToken = function(token) { | ||
if(!userId) { | ||
userId = 0; | ||
} | ||
var client = new this.Client(this.apiURL); | ||
Factory.setClientProperties(client) | ||
client._factory = this; | ||
client.setAuthBearerToken(token) | ||
return client; | ||
}; | ||
/** | ||
*/ | ||
Factory.prototype.getRawClient = function(options) { | ||
@@ -152,0 +166,0 @@ var client = new this.Client(this.apiURL, options); |
@@ -402,2 +402,10 @@ var | ||
Client.prototype.setAuthBearerToken = function (token) { | ||
if (typeof token !== 'string' || !token) { | ||
throw new Error('token must be a non empty string') | ||
} | ||
this.headers = Object.clone(this.headers) | ||
this.headers['Authorization'] = 'Bearer ' + token | ||
} | ||
methods.forEach(function(method) { | ||
@@ -404,0 +412,0 @@ Client.prototype[method.toLowerCase()] = function() { |
{ | ||
"name": "eh-api-client", | ||
"version": "0.49.0", | ||
"version": "0.50.0", | ||
"description": "Node.js rest client", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
47469
1519