@flashbacktech/flashbackclient 0.0.50 → 0.0.52
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/api/client.d.ts +2 -0
- package/dist/api/client.js +12 -1
- package/package.json +1 -1
package/dist/api/client.d.ts
CHANGED
|
@@ -14,7 +14,9 @@ export declare class HttpError extends Error {
|
|
|
14
14
|
export declare class ApiClient implements IApiClient {
|
|
15
15
|
private baseURL;
|
|
16
16
|
private headers;
|
|
17
|
+
private debug;
|
|
17
18
|
constructor(baseURL?: string);
|
|
19
|
+
setDebug: (debug: boolean) => void;
|
|
18
20
|
setAuthToken: (token: string | null) => void;
|
|
19
21
|
authenticate: (token: string, provider: ProviderType) => Promise<any>;
|
|
20
22
|
exchangeCode: (code: string, provider: ProviderType) => Promise<OAuth2ResponseDTO>;
|
package/dist/api/client.js
CHANGED
|
@@ -14,6 +14,9 @@ class HttpError extends Error {
|
|
|
14
14
|
exports.HttpError = HttpError;
|
|
15
15
|
class ApiClient {
|
|
16
16
|
constructor(baseURL = 'https://api.flashback.tech') {
|
|
17
|
+
this.setDebug = (debug) => {
|
|
18
|
+
this.debug = debug;
|
|
19
|
+
};
|
|
17
20
|
this.setAuthToken = (token) => {
|
|
18
21
|
if (token) {
|
|
19
22
|
this.headers = {
|
|
@@ -84,7 +87,14 @@ class ApiClient {
|
|
|
84
87
|
headers: this.headers,
|
|
85
88
|
body: data ? JSON.stringify(data) : null,
|
|
86
89
|
};
|
|
87
|
-
const
|
|
90
|
+
const cleanPath = path.startsWith('/') ? path.substring(1) : path;
|
|
91
|
+
if (this.debug) {
|
|
92
|
+
console.log(`DEBUG: ${method} ${cleanPath} ${JSON.stringify(data)}`);
|
|
93
|
+
}
|
|
94
|
+
const response = await fetch(`${this.baseURL}/${cleanPath}`, options);
|
|
95
|
+
if (this.debug) {
|
|
96
|
+
console.log(`DEBUG: ${response.status} ${response.statusText}`);
|
|
97
|
+
}
|
|
88
98
|
// If response is not ok, handle it before trying to parse JSON
|
|
89
99
|
if (!response.ok) {
|
|
90
100
|
let errorData = null;
|
|
@@ -169,6 +179,7 @@ class ApiClient {
|
|
|
169
179
|
this.headers = {
|
|
170
180
|
'Content-Type': 'application/json',
|
|
171
181
|
};
|
|
182
|
+
this.debug = false;
|
|
172
183
|
}
|
|
173
184
|
}
|
|
174
185
|
exports.ApiClient = ApiClient;
|