@flashbacktech/flashbackclient 0.0.41 → 0.0.43
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 +11 -1
- package/dist/api/client.js +36 -0
- package/dist/api/index.d.ts +3 -2
- package/dist/api/index.js +4 -2
- package/dist/api/interfaces.d.ts +1 -1
- package/dist/api/types/auth.d.ts +12 -0
- package/dist/api/types/auth.js +2 -0
- package/dist/api/types/storage.d.ts +89 -0
- package/dist/api/types/storage.js +20 -0
- package/package.json +1 -1
package/dist/api/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CreateUnitRequest, CreateUnitResponse, CreateRepoRequest, CreateRepoResponse, CreateRepoKeyRequest, CreateRepoKeyResponse, GetUnitsResponse, GetReposResponse, GetRepoKeysResponse } from './types';
|
|
1
|
+
import { CreateUnitRequest, CreateUnitResponse, CreateRepoRequest, CreateRepoResponse, CreateRepoKeyRequest, CreateRepoKeyResponse, GetUnitsResponse, GetReposResponse, GetRepoKeysResponse } from './types/storage';
|
|
2
2
|
import { IApiClient, ProviderType } from './interfaces';
|
|
3
3
|
export declare class ApiClient implements IApiClient {
|
|
4
4
|
private baseURL;
|
|
@@ -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:
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ApiClient } from './client';
|
|
2
|
-
import * as ApiTypes from './types';
|
|
2
|
+
import * as ApiTypes from './types/storage';
|
|
3
|
+
import * as AuthTypes from './types/auth';
|
|
3
4
|
import * as ApiInterfaces from './interfaces';
|
|
4
|
-
export { ApiClient, ApiTypes, ApiInterfaces };
|
|
5
|
+
export { ApiClient, ApiTypes, AuthTypes, ApiInterfaces };
|
package/dist/api/index.js
CHANGED
|
@@ -33,10 +33,12 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.ApiInterfaces = exports.ApiTypes = exports.ApiClient = void 0;
|
|
36
|
+
exports.ApiInterfaces = exports.AuthTypes = exports.ApiTypes = exports.ApiClient = void 0;
|
|
37
37
|
const client_1 = require("./client");
|
|
38
38
|
Object.defineProperty(exports, "ApiClient", { enumerable: true, get: function () { return client_1.ApiClient; } });
|
|
39
|
-
const ApiTypes = __importStar(require("./types"));
|
|
39
|
+
const ApiTypes = __importStar(require("./types/storage"));
|
|
40
40
|
exports.ApiTypes = ApiTypes;
|
|
41
|
+
const AuthTypes = __importStar(require("./types/auth"));
|
|
42
|
+
exports.AuthTypes = AuthTypes;
|
|
41
43
|
const ApiInterfaces = __importStar(require("./interfaces"));
|
|
42
44
|
exports.ApiInterfaces = ApiInterfaces;
|
package/dist/api/interfaces.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CreateUnitRequest, CreateUnitResponse, CreateRepoRequest, CreateRepoResponse, CreateRepoKeyRequest, CreateRepoKeyResponse, GetUnitsResponse, GetReposResponse, GetRepoKeysResponse } from "./types";
|
|
1
|
+
import { CreateUnitRequest, CreateUnitResponse, CreateRepoRequest, CreateRepoResponse, CreateRepoKeyRequest, CreateRepoKeyResponse, GetUnitsResponse, GetReposResponse, GetRepoKeysResponse } from "./types/storage";
|
|
2
2
|
export declare enum ProviderType {
|
|
3
3
|
GOOGLE = "GOOGLE",
|
|
4
4
|
GITHUB = "GITHUB",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface AuthState {
|
|
2
|
+
user: {
|
|
3
|
+
email: string;
|
|
4
|
+
name: string;
|
|
5
|
+
imageUrl: string;
|
|
6
|
+
} | null;
|
|
7
|
+
token: string | null;
|
|
8
|
+
accessToken: string | null;
|
|
9
|
+
refreshToken?: string | null;
|
|
10
|
+
expiresAt?: number | null;
|
|
11
|
+
provider?: 'google' | 'github';
|
|
12
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export declare enum StorageType {
|
|
2
|
+
S3 = "S3",
|
|
3
|
+
GCS = "GCS",
|
|
4
|
+
AZURE = "AZURE"
|
|
5
|
+
}
|
|
6
|
+
export declare enum AccessType {
|
|
7
|
+
READ = "READ",
|
|
8
|
+
WRITE = "WRITE",
|
|
9
|
+
ADMIN = "ADMIN"
|
|
10
|
+
}
|
|
11
|
+
export declare enum ModeType {
|
|
12
|
+
NORMAL = "NORMAL",
|
|
13
|
+
MIRROR = "MIRROR"
|
|
14
|
+
}
|
|
15
|
+
export interface CreateUnitRequest {
|
|
16
|
+
name: string;
|
|
17
|
+
bucket: string;
|
|
18
|
+
storageType: StorageType;
|
|
19
|
+
key: string;
|
|
20
|
+
secret: string;
|
|
21
|
+
endpoint?: string;
|
|
22
|
+
regionId?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface CreateUnitResponse {
|
|
25
|
+
success: boolean;
|
|
26
|
+
unitId: string;
|
|
27
|
+
}
|
|
28
|
+
export interface RepoUnitInfo {
|
|
29
|
+
id: string;
|
|
30
|
+
folder: string;
|
|
31
|
+
}
|
|
32
|
+
export interface CreateRepoRequest {
|
|
33
|
+
name: string;
|
|
34
|
+
storageType: StorageType;
|
|
35
|
+
mode: ModeType;
|
|
36
|
+
repoUnits: RepoUnitInfo[];
|
|
37
|
+
}
|
|
38
|
+
export interface CreateRepoResponse {
|
|
39
|
+
success: boolean;
|
|
40
|
+
repoId: string;
|
|
41
|
+
}
|
|
42
|
+
export interface CreateRepoKeyRequest {
|
|
43
|
+
repoId: string;
|
|
44
|
+
name: string;
|
|
45
|
+
accessType: AccessType;
|
|
46
|
+
}
|
|
47
|
+
export interface CreateRepoKeyResponse {
|
|
48
|
+
success: boolean;
|
|
49
|
+
id: string;
|
|
50
|
+
key: string;
|
|
51
|
+
secret: string;
|
|
52
|
+
}
|
|
53
|
+
export interface StorageRepo {
|
|
54
|
+
id: string;
|
|
55
|
+
name: string;
|
|
56
|
+
storageType: StorageType;
|
|
57
|
+
mode: ModeType;
|
|
58
|
+
repoUnits: RepoUnitInfo[];
|
|
59
|
+
apiKeys: ApiKey[];
|
|
60
|
+
}
|
|
61
|
+
export interface ApiKey {
|
|
62
|
+
id: string;
|
|
63
|
+
name: string;
|
|
64
|
+
accessType: AccessType;
|
|
65
|
+
key: string;
|
|
66
|
+
secret: string;
|
|
67
|
+
}
|
|
68
|
+
export interface StorageUnit {
|
|
69
|
+
id: string;
|
|
70
|
+
name: string;
|
|
71
|
+
bucket: string;
|
|
72
|
+
storageType: StorageType;
|
|
73
|
+
key: string;
|
|
74
|
+
secret: string;
|
|
75
|
+
endpoint?: string;
|
|
76
|
+
regionId?: string;
|
|
77
|
+
}
|
|
78
|
+
export interface GetUnitsResponse {
|
|
79
|
+
success: boolean;
|
|
80
|
+
units: StorageUnit[];
|
|
81
|
+
}
|
|
82
|
+
export interface GetReposResponse {
|
|
83
|
+
success: boolean;
|
|
84
|
+
repos: StorageRepo[];
|
|
85
|
+
}
|
|
86
|
+
export interface GetRepoKeysResponse {
|
|
87
|
+
success: boolean;
|
|
88
|
+
keys: ApiKey[];
|
|
89
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModeType = exports.AccessType = exports.StorageType = void 0;
|
|
4
|
+
var StorageType;
|
|
5
|
+
(function (StorageType) {
|
|
6
|
+
StorageType["S3"] = "S3";
|
|
7
|
+
StorageType["GCS"] = "GCS";
|
|
8
|
+
StorageType["AZURE"] = "AZURE";
|
|
9
|
+
})(StorageType || (exports.StorageType = StorageType = {}));
|
|
10
|
+
var AccessType;
|
|
11
|
+
(function (AccessType) {
|
|
12
|
+
AccessType["READ"] = "READ";
|
|
13
|
+
AccessType["WRITE"] = "WRITE";
|
|
14
|
+
AccessType["ADMIN"] = "ADMIN";
|
|
15
|
+
})(AccessType || (exports.AccessType = AccessType = {}));
|
|
16
|
+
var ModeType;
|
|
17
|
+
(function (ModeType) {
|
|
18
|
+
ModeType["NORMAL"] = "NORMAL";
|
|
19
|
+
ModeType["MIRROR"] = "MIRROR";
|
|
20
|
+
})(ModeType || (exports.ModeType = ModeType = {}));
|