@flashbacktech/flashbackclient 0.0.41 → 0.0.42
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 +10 -0
- package/dist/api/client.js +36 -0
- package/package.json +1 -1
package/dist/api/client.d.ts
CHANGED
|
@@ -6,6 +6,16 @@ export declare class ApiClient implements IApiClient {
|
|
|
6
6
|
constructor(baseURL?: string);
|
|
7
7
|
setAuthToken: (token: string | null) => void;
|
|
8
8
|
authenticate: (token: string, provider: ProviderType) => Promise<any>;
|
|
9
|
+
exchangeCode: (code: string, provider: ProviderType) => Promise<any>;
|
|
10
|
+
private exchangeGoogleCode;
|
|
11
|
+
private exchangeGithubCode;
|
|
12
|
+
private exchangeWeb3StellarCode;
|
|
13
|
+
/**
|
|
14
|
+
* Refresh the token for the given provider
|
|
15
|
+
* @param refreshToken - The refresh token to use
|
|
16
|
+
* @param provider - The provider to refresh the token for
|
|
17
|
+
* @returns The refreshed token
|
|
18
|
+
*/
|
|
9
19
|
refreshToken: (refreshToken: string, provider: ProviderType) => Promise<any>;
|
|
10
20
|
private authenticateWeb3Stellar;
|
|
11
21
|
private authenticateGoogle;
|
package/dist/api/client.js
CHANGED
|
@@ -30,6 +30,42 @@ class ApiClient {
|
|
|
30
30
|
throw new Error(`Unsupported provider: ${provider}`);
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
|
+
this.exchangeCode = async (code, provider) => {
|
|
34
|
+
switch (provider) {
|
|
35
|
+
case interfaces_1.ProviderType.GOOGLE:
|
|
36
|
+
return this.exchangeGoogleCode(code);
|
|
37
|
+
case interfaces_1.ProviderType.GITHUB:
|
|
38
|
+
return this.exchangeGithubCode(code);
|
|
39
|
+
case interfaces_1.ProviderType.WEB3_STELLAR:
|
|
40
|
+
return this.exchangeWeb3StellarCode(code);
|
|
41
|
+
default:
|
|
42
|
+
throw new Error(`Unsupported provider: ${provider}`);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
this.exchangeGoogleCode = async (code) => {
|
|
46
|
+
const response = await fetch(`${this.baseURL}/auth/google/exchange`, {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: this.headers,
|
|
49
|
+
body: JSON.stringify({ code }),
|
|
50
|
+
});
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
53
|
+
}
|
|
54
|
+
const ret = await response.json();
|
|
55
|
+
return ret;
|
|
56
|
+
};
|
|
57
|
+
this.exchangeGithubCode = async (code) => {
|
|
58
|
+
throw new Error('Not implemented');
|
|
59
|
+
};
|
|
60
|
+
this.exchangeWeb3StellarCode = async (code) => {
|
|
61
|
+
throw new Error('Not implemented');
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Refresh the token for the given provider
|
|
65
|
+
* @param refreshToken - The refresh token to use
|
|
66
|
+
* @param provider - The provider to refresh the token for
|
|
67
|
+
* @returns The refreshed token
|
|
68
|
+
*/
|
|
33
69
|
this.refreshToken = async (refreshToken, provider) => {
|
|
34
70
|
switch (provider) {
|
|
35
71
|
case interfaces_1.ProviderType.GOOGLE:
|