@flashbacktech/flashbackclient 0.0.16 → 0.0.19
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/README.md +1 -1
- package/dist/api/client.d.ts +7 -0
- package/dist/api/client.js +27 -0
- package/dist/consumer/file/delete.d.ts +3 -0
- package/dist/consumer/file/delete.js +17 -0
- package/dist/consumer/file/getUrl.d.ts +3 -0
- package/dist/consumer/file/getUrl.js +14 -0
- package/dist/consumer/file/index.d.ts +30 -0
- package/dist/consumer/file/index.js +45 -0
- package/dist/consumer/file/types.d.ts +25 -0
- package/dist/consumer/file/types.js +1 -0
- package/dist/consumer/file/upload.d.ts +3 -0
- package/dist/consumer/file/upload.js +69 -0
- package/dist/consumer/index.d.ts +1 -0
- package/dist/consumer/index.js +1 -0
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ npm install @flashbacktech/flashbackclient
|
|
|
17
17
|
### Client Library
|
|
18
18
|
|
|
19
19
|
```typescript
|
|
20
|
-
import { FlashOnStellarClient, StellarNetwork } from '@flashbacktech/flashbackclient/
|
|
20
|
+
import { FlashOnStellarClient, StellarNetwork } from '@flashbacktech/flashbackclient/stellar';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
See the [Stellar README](STELLAR.md) for usage instructions.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
export class ApiClient {
|
|
3
|
+
constructor(baseURL = 'https://api.flashback.tech') {
|
|
4
|
+
this.setAuthToken = (token) => {
|
|
5
|
+
if (token) {
|
|
6
|
+
this.apiClient.defaults.headers.common['Authorization'] = `Bearer ${token}`;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
delete this.apiClient.defaults.headers.common['Authorization'];
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
this.authenticateGoogle = async (token) => {
|
|
13
|
+
const response = await this.apiClient.post('/auth/google', { token });
|
|
14
|
+
return response.data;
|
|
15
|
+
};
|
|
16
|
+
this.authenticateGithub = async (code) => {
|
|
17
|
+
const response = await this.apiClient.post('/auth/github', { code });
|
|
18
|
+
return response.data;
|
|
19
|
+
};
|
|
20
|
+
this.apiClient = axios.create({
|
|
21
|
+
baseURL: baseURL,
|
|
22
|
+
headers: {
|
|
23
|
+
'Content-Type': 'application/json',
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
export async function deleteFile(client, params) {
|
|
3
|
+
try {
|
|
4
|
+
const { data } = await client.delete('/file/', {
|
|
5
|
+
params,
|
|
6
|
+
data: params,
|
|
7
|
+
});
|
|
8
|
+
return data;
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (axios.isAxiosError(error) && error.response?.data) {
|
|
12
|
+
const errorData = error.response.data;
|
|
13
|
+
throw new Error(`Delete failed: ${errorData.message}`);
|
|
14
|
+
}
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
export async function getUrl(client, params) {
|
|
3
|
+
try {
|
|
4
|
+
const { data } = await client.get('/file/', { params });
|
|
5
|
+
return data;
|
|
6
|
+
}
|
|
7
|
+
catch (error) {
|
|
8
|
+
if (axios.isAxiosError(error) && error.response?.data) {
|
|
9
|
+
const errorData = error.response.data;
|
|
10
|
+
throw new Error(`Get URL failed: ${errorData.message}`);
|
|
11
|
+
}
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DeleteParams, DeleteResponse, GetUrlParams, UploadRequest, UploadResponse } from './types';
|
|
2
|
+
export type { DeleteParams, DeleteResponse, GetUrlParams, UploadRequest, UploadResponse };
|
|
3
|
+
export interface StorageClientConfig {
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
timeout?: number;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
export declare class StorageClient {
|
|
9
|
+
private client;
|
|
10
|
+
private readonly config;
|
|
11
|
+
constructor(config: StorageClientConfig);
|
|
12
|
+
/**
|
|
13
|
+
* Upload a file to storage
|
|
14
|
+
* @param params Upload parameters including file data and type
|
|
15
|
+
* @returns Promise with the file URL
|
|
16
|
+
*/
|
|
17
|
+
upload(params: UploadRequest): Promise<UploadResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Get the URL for a file
|
|
20
|
+
* @param params File identifier parameters
|
|
21
|
+
* @returns Promise with the file URL
|
|
22
|
+
*/
|
|
23
|
+
getUrl(params: GetUrlParams): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Delete a file from storage
|
|
26
|
+
* @param params File identifier parameters
|
|
27
|
+
* @returns Promise indicating success
|
|
28
|
+
*/
|
|
29
|
+
delete(params: DeleteParams): Promise<DeleteResponse>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { upload } from './upload';
|
|
3
|
+
import { getUrl } from './getUrl';
|
|
4
|
+
import { deleteFile } from './delete';
|
|
5
|
+
export class StorageClient {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.config = {
|
|
8
|
+
baseUrl: config.baseUrl.replace(/\/$/, ''),
|
|
9
|
+
timeout: config.timeout || 30000,
|
|
10
|
+
headers: {
|
|
11
|
+
'Content-Type': 'application/json',
|
|
12
|
+
...config.headers,
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
this.client = axios.create({
|
|
16
|
+
baseURL: this.config.baseUrl,
|
|
17
|
+
timeout: this.config.timeout,
|
|
18
|
+
headers: this.config.headers,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Upload a file to storage
|
|
23
|
+
* @param params Upload parameters including file data and type
|
|
24
|
+
* @returns Promise with the file URL
|
|
25
|
+
*/
|
|
26
|
+
async upload(params) {
|
|
27
|
+
return upload(this.client, params);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get the URL for a file
|
|
31
|
+
* @param params File identifier parameters
|
|
32
|
+
* @returns Promise with the file URL
|
|
33
|
+
*/
|
|
34
|
+
async getUrl(params) {
|
|
35
|
+
return getUrl(this.client, params);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Delete a file from storage
|
|
39
|
+
* @param params File identifier parameters
|
|
40
|
+
* @returns Promise indicating success
|
|
41
|
+
*/
|
|
42
|
+
async delete(params) {
|
|
43
|
+
return deleteFile(this.client, params);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Buffer, Blob, File } from 'buffer';
|
|
2
|
+
export interface UploadRequest {
|
|
3
|
+
folderId: string;
|
|
4
|
+
fileId: string;
|
|
5
|
+
data: string | Buffer | ArrayBuffer | Blob | File | globalThis.File;
|
|
6
|
+
type: 'base64' | 'binary' | 'multipart';
|
|
7
|
+
}
|
|
8
|
+
export interface UploadResponse {
|
|
9
|
+
url: string;
|
|
10
|
+
}
|
|
11
|
+
export interface GetUrlParams {
|
|
12
|
+
folderId: string;
|
|
13
|
+
fileId: string;
|
|
14
|
+
}
|
|
15
|
+
export interface DeleteParams {
|
|
16
|
+
folderId: string;
|
|
17
|
+
fileId: string;
|
|
18
|
+
}
|
|
19
|
+
export interface DeleteResponse {
|
|
20
|
+
success: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface ErrorResponse {
|
|
23
|
+
error: string;
|
|
24
|
+
message: string;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
//import type { Blob } from 'buffer';
|
|
3
|
+
import { FormData } from 'formdata-node';
|
|
4
|
+
import axios from 'axios';
|
|
5
|
+
export async function upload(client, params) {
|
|
6
|
+
try {
|
|
7
|
+
let url = '';
|
|
8
|
+
switch (params.type) {
|
|
9
|
+
case 'multipart': {
|
|
10
|
+
const formData = new FormData();
|
|
11
|
+
formData.append('type', 'multipart');
|
|
12
|
+
formData.append('folderId', params.folderId);
|
|
13
|
+
formData.append('fileId', params.fileId);
|
|
14
|
+
// If params.data is already a Blob/File, use it directly
|
|
15
|
+
// Otherwise, create a new Blob with the correct type
|
|
16
|
+
const fileBlob = params.data;
|
|
17
|
+
formData.append('file', fileBlob);
|
|
18
|
+
const response = await client.post('/file/', formData, {
|
|
19
|
+
headers: {
|
|
20
|
+
'Content-Type': 'multipart/form-data',
|
|
21
|
+
},
|
|
22
|
+
// Prevent any data transformation
|
|
23
|
+
transformRequest: [(data) => data],
|
|
24
|
+
// Ensure binary data handling
|
|
25
|
+
responseType: 'json',
|
|
26
|
+
maxBodyLength: Infinity,
|
|
27
|
+
maxContentLength: Infinity,
|
|
28
|
+
});
|
|
29
|
+
url = response.data.url;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
case 'binary': {
|
|
33
|
+
// Binary upload
|
|
34
|
+
const response = await client.post('/file/', params.data, {
|
|
35
|
+
headers: {
|
|
36
|
+
'Content-Type': 'application/octet-stream',
|
|
37
|
+
'x-upload-type': 'binary',
|
|
38
|
+
'x-folder-id': params.folderId,
|
|
39
|
+
'x-file-id': params.fileId,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
url = response.data.url;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
case 'base64': {
|
|
46
|
+
const response = await client.post('/file/', {
|
|
47
|
+
type: 'base64',
|
|
48
|
+
folderId: params.folderId,
|
|
49
|
+
fileId: params.fileId,
|
|
50
|
+
data: params.data,
|
|
51
|
+
}, {
|
|
52
|
+
headers: { 'Content-Type': 'application/json' },
|
|
53
|
+
});
|
|
54
|
+
url = response.data.url;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
default:
|
|
58
|
+
throw new Error('Invalid file type');
|
|
59
|
+
}
|
|
60
|
+
return { url };
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (axios.isAxiosError(error) && error.response?.data) {
|
|
64
|
+
const errorData = error.response.data;
|
|
65
|
+
throw new Error(`Upload failed: ${errorData.message}`);
|
|
66
|
+
}
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './file';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './file';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flashbacktech/flashbackclient",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -21,9 +21,11 @@
|
|
|
21
21
|
"pub": "npm run build && npm version patch && npm publish --access public"
|
|
22
22
|
},
|
|
23
23
|
"author": "Javier Ortiz <javier.ortiz@flashback.tech>",
|
|
24
|
-
"license": "
|
|
24
|
+
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@stellar/stellar-sdk": "^13.0.0"
|
|
26
|
+
"@stellar/stellar-sdk": "^13.0.0",
|
|
27
|
+
"axios": "^1.7.9",
|
|
28
|
+
"formdata-node": "^6.0.3"
|
|
27
29
|
},
|
|
28
30
|
"bin": {
|
|
29
31
|
"": "./dist/.min.js"
|
|
@@ -49,7 +51,9 @@
|
|
|
49
51
|
"dist"
|
|
50
52
|
],
|
|
51
53
|
"devDependencies": {
|
|
54
|
+
"@aws-sdk/client-s3": "^3.726.1",
|
|
52
55
|
"@eslint/js": "^8.56.0",
|
|
56
|
+
"@google-cloud/storage": "^7.15.0",
|
|
53
57
|
"@types/jest": "^29.5.14",
|
|
54
58
|
"@types/node": "^22.10.1",
|
|
55
59
|
"@typescript-eslint/eslint-plugin": "^8.17.0",
|