@flashbacktech/flashbackclient 0.0.40 → 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.
@@ -6,9 +6,21 @@ 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
+ */
19
+ refreshToken: (refreshToken: string, provider: ProviderType) => Promise<any>;
9
20
  private authenticateWeb3Stellar;
10
21
  private authenticateGoogle;
11
22
  private authenticateGithub;
23
+ private refreshTokenGoogle;
12
24
  createStorageUnit: (data: CreateUnitRequest) => Promise<CreateUnitResponse>;
13
25
  getStorageUnits: () => Promise<GetUnitsResponse>;
14
26
  createRepo: (data: CreateRepoRequest) => Promise<CreateRepoResponse>;
@@ -30,6 +30,53 @@ 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
+ */
69
+ this.refreshToken = async (refreshToken, provider) => {
70
+ switch (provider) {
71
+ case interfaces_1.ProviderType.GOOGLE:
72
+ return this.refreshTokenGoogle(refreshToken);
73
+ case interfaces_1.ProviderType.GITHUB:
74
+ // TODO: Implement refresh token for Github
75
+ throw new Error('Not implemented');
76
+ default:
77
+ throw new Error(`Unsupported provider: ${provider}`);
78
+ }
79
+ };
33
80
  this.authenticateWeb3Stellar = async (token) => {
34
81
  throw new Error('Not implemented');
35
82
  };
@@ -59,6 +106,18 @@ class ApiClient {
59
106
  const ret = await response.json();
60
107
  return ret;
61
108
  };
109
+ this.refreshTokenGoogle = async (refreshToken) => {
110
+ const response = await fetch(`${this.baseURL}/auth/google/refresh`, {
111
+ method: 'POST',
112
+ headers: this.headers,
113
+ body: JSON.stringify({ refresh_token: refreshToken }),
114
+ });
115
+ if (!response.ok) {
116
+ throw new Error(`HTTP error! status: ${response.status}`);
117
+ }
118
+ const ret = await response.json();
119
+ return ret;
120
+ };
62
121
  this.createStorageUnit = async (data) => {
63
122
  const response = await fetch(`${this.baseURL}/unit`, {
64
123
  method: 'POST',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flashbacktech/flashbackclient",
3
- "version": "0.0.40",
3
+ "version": "0.0.42",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },