Skip to content

Commit 310e526

Browse files
committed
Various improvements
1 parent f5740b8 commit 310e526

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/model.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ export default class QuidRequests {
1111
private verbose: boolean;
1212
private headers: HeadersInit;
1313
private credentials: string | null;
14+
private accessTokenUri: string | null;
1415

1516
public constructor({ quidUri, serverUri, namespace, timeouts = {
1617
accessToken: "20m",
1718
refreshToken: "24h"
18-
}, credentials = "include", verbose = false }: QuidParams) {
19+
},
20+
credentials = "include",
21+
verbose = false,
22+
accessTokenUri = null }: QuidParams) {
1923
this.quidUri = quidUri;
2024
this.serverUri = serverUri;
2125
this.namespace = namespace;
@@ -25,18 +29,18 @@ export default class QuidRequests {
2529
this.headers = {
2630
'Content-Type': 'application/json',
2731
} as HeadersInit;
32+
this.accessTokenUri = accessTokenUri;
2833
if (verbose) {
2934
console.log("Initializing QuidRequests", this.quidUri);
3035
}
31-
console.log("INIT CREDS", this.credentials)
3236
}
3337

34-
async get<T>(url: string): Promise<T> {
35-
return this._request<T>(url, "get");
38+
async get<T = Record<string, any>>(url: string): Promise<T> {
39+
return await this._request<T>(url, "get");
3640
}
3741

38-
async post<T>(url: string): Promise<T> {
39-
return this._request<T>(url, "post");
42+
async post<T = Record<string, any>>(url: string, payload: Record<string, any> | Array<any>): Promise<T> {
43+
return await this._request<T>(url, "post", payload);
4044
}
4145

4246
async login(username: string, password: string) {
@@ -68,7 +72,7 @@ export default class QuidRequests {
6872
}
6973
this.refreshToken = t.token;
7074
} catch (e) {
71-
throw new Error(e);
75+
throw new Error(`${e}`);
7276
}
7377
}
7478

@@ -142,15 +146,20 @@ export default class QuidRequests {
142146
console.log("RESP NOT OK", response);
143147
throw new Error(response.statusText)
144148
}
145-
return await response.json() as T;
149+
const data = await response.json() as T;
150+
//console.log("DATa", data);
151+
return data
146152
}
147153

148154
private async _getAccessToken(): Promise<number> {
149155
const payload = {
150156
namespace: this.namespace,
151157
refresh_token: this.refreshToken, // eslint-disable-line
152158
}
153-
const url = this.quidUri + "/token/access/" + this.timeouts.accessToken;
159+
let url = this.quidUri + "/token/access/" + this.timeouts.accessToken;
160+
if (this.accessTokenUri !== null) {
161+
url = this.accessTokenUri
162+
}
154163
if (this.verbose) {
155164
console.log("Getting an access token from", url, payload)
156165
}

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ interface QuidParams {
55
timeouts: Record<string, string>;
66
credentials?: string | null;
77
verbose: boolean;
8+
accessTokenUri?: string | null;
89
}
910

1011
interface QuidLoginParams {

0 commit comments

Comments
 (0)