@flashbacktech/flashbackclient 0.0.15 → 0.0.17

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 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/client';
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,70 @@
1
+ import type { Buffer, Blob, File } from 'buffer';
2
+ export interface UploadRequest {
3
+ folderId: string;
4
+ fileId: string;
5
+ data: string | Blob | Buffer | File | ArrayBuffer;
6
+ type: 'base64' | 'binary' | 'multipart';
7
+ }
8
+ export interface UploadResponse {
9
+ url: string;
10
+ }
11
+ export interface GetUrlParams {
12
+ folder_id: string;
13
+ file_id: string;
14
+ }
15
+ export interface DeleteParams {
16
+ folder_id: string;
17
+ file_id: string;
18
+ }
19
+ export interface DeleteResponse {
20
+ success: boolean;
21
+ }
22
+ export interface ErrorResponse {
23
+ error: string;
24
+ message: string;
25
+ }
26
+ interface StorageClientConfig {
27
+ baseUrl: string;
28
+ timeout?: number;
29
+ headers?: Record<string, string>;
30
+ }
31
+ export declare class StorageClient {
32
+ private static instance;
33
+ private client;
34
+ private readonly config;
35
+ private constructor();
36
+ /**
37
+ * Initialize and get the StorageClient instance
38
+ * @param config - Configuration for the storage service
39
+ * @returns StorageClient instance
40
+ */
41
+ static initialize(config: StorageClientConfig): StorageClient;
42
+ /**
43
+ * Get the current instance of StorageClient
44
+ * @throws Error if client hasn't been initialized
45
+ */
46
+ static getInstance(): StorageClient;
47
+ /**
48
+ * Reset the client instance (useful for testing or reconfiguration)
49
+ */
50
+ static reset(): void;
51
+ /**
52
+ * Upload a file to storage
53
+ * @param params Upload parameters including file data and type
54
+ * @returns Promise with the file URL
55
+ */
56
+ upload(params: UploadRequest): Promise<UploadResponse>;
57
+ /**
58
+ * Get the URL for a file
59
+ * @param params File identifier parameters
60
+ * @returns Promise with the file URL
61
+ */
62
+ getUrl(params: GetUrlParams): Promise<UploadResponse>;
63
+ /**
64
+ * Delete a file from storage
65
+ * @param params File identifier parameters
66
+ * @returns Promise indicating success
67
+ */
68
+ delete(params: DeleteParams): Promise<DeleteResponse>;
69
+ }
70
+ export {};
@@ -0,0 +1,143 @@
1
+ import axios from 'axios';
2
+ import { FormData } from 'formdata-node';
3
+ export class StorageClient {
4
+ constructor(config) {
5
+ this.config = {
6
+ baseUrl: config.baseUrl.replace(/\/$/, ''),
7
+ timeout: config.timeout || 30000,
8
+ headers: {
9
+ 'Content-Type': 'application/json',
10
+ ...config.headers,
11
+ },
12
+ };
13
+ this.client = axios.create({
14
+ baseURL: this.config.baseUrl,
15
+ timeout: this.config.timeout,
16
+ headers: this.config.headers,
17
+ });
18
+ }
19
+ /**
20
+ * Initialize and get the StorageClient instance
21
+ * @param config - Configuration for the storage service
22
+ * @returns StorageClient instance
23
+ */
24
+ static initialize(config) {
25
+ if (!StorageClient.instance) {
26
+ StorageClient.instance = new StorageClient(config);
27
+ }
28
+ return StorageClient.instance;
29
+ }
30
+ /**
31
+ * Get the current instance of StorageClient
32
+ * @throws Error if client hasn't been initialized
33
+ */
34
+ static getInstance() {
35
+ if (!StorageClient.instance) {
36
+ throw new Error('StorageClient has not been initialized. Call initialize() first.');
37
+ }
38
+ return StorageClient.instance;
39
+ }
40
+ /**
41
+ * Reset the client instance (useful for testing or reconfiguration)
42
+ */
43
+ static reset() {
44
+ StorageClient.instance = null;
45
+ }
46
+ /**
47
+ * Upload a file to storage
48
+ * @param params Upload parameters including file data and type
49
+ * @returns Promise with the file URL
50
+ */
51
+ async upload(params) {
52
+ try {
53
+ let url = '';
54
+ switch (params.type) {
55
+ case 'multipart': {
56
+ const formData = new FormData();
57
+ formData.append('type', 'multipart');
58
+ formData.append('folderId', params.folderId);
59
+ formData.append('fileId', params.fileId);
60
+ formData.append('file', params.data);
61
+ const response = await this.client.post('/', formData, {
62
+ headers: { 'Content-Type': 'multipart/form-data' },
63
+ // Note: axios will automatically set the correct Content-Type boundary
64
+ });
65
+ url = response.data.url;
66
+ break;
67
+ }
68
+ case 'binary': {
69
+ // Binary upload
70
+ const response = await this.client.post('/', params.data, {
71
+ headers: {
72
+ 'Content-Type': 'application/octet-stream',
73
+ 'x-upload-type': 'binary',
74
+ 'x-folder-id': params.folderId,
75
+ 'x-file-id': params.fileId,
76
+ },
77
+ });
78
+ url = response.data.url;
79
+ break;
80
+ }
81
+ case 'base64': {
82
+ const response = await this.client.post('/', {
83
+ type: 'base64',
84
+ folderId: params.folderId,
85
+ fileId: params.fileId,
86
+ data: params.data,
87
+ }, {
88
+ headers: { 'Content-Type': 'application/json' },
89
+ });
90
+ url = response.data.url;
91
+ break;
92
+ }
93
+ default:
94
+ throw new Error('Invalid file type');
95
+ }
96
+ return { url };
97
+ }
98
+ catch (error) {
99
+ if (axios.isAxiosError(error) && error.response?.data) {
100
+ const errorData = error.response.data;
101
+ throw new Error(`Upload failed: ${errorData.message}`);
102
+ }
103
+ throw error;
104
+ }
105
+ }
106
+ /**
107
+ * Get the URL for a file
108
+ * @param params File identifier parameters
109
+ * @returns Promise with the file URL
110
+ */
111
+ async getUrl(params) {
112
+ try {
113
+ const { data } = await this.client.get('/', { params });
114
+ return data;
115
+ }
116
+ catch (error) {
117
+ if (axios.isAxiosError(error) && error.response?.data) {
118
+ const errorData = error.response.data;
119
+ throw new Error(`Get URL failed: ${errorData.message}`);
120
+ }
121
+ throw error;
122
+ }
123
+ }
124
+ /**
125
+ * Delete a file from storage
126
+ * @param params File identifier parameters
127
+ * @returns Promise indicating success
128
+ */
129
+ async delete(params) {
130
+ try {
131
+ const { data } = await this.client.delete('/', { params });
132
+ return data;
133
+ }
134
+ catch (error) {
135
+ if (axios.isAxiosError(error) && error.response?.data) {
136
+ const errorData = error.response.data;
137
+ throw new Error(`Delete failed: ${errorData.message}`);
138
+ }
139
+ throw error;
140
+ }
141
+ }
142
+ }
143
+ StorageClient.instance = null;
@@ -22,7 +22,7 @@ const create_reservation = async (context, wallet_address, consumer_address, uni
22
22
  return executeReservationTransaction(context, wallet_address, 'create_reservation', [
23
23
  { value: consumer_address, type: 'address' },
24
24
  { value: unit_id, type: 'u32' },
25
- { value: reserved_gb, type: 'u64' },
25
+ { value: reserved_gb, type: 'u32' },
26
26
  { value: is_owner, type: 'bool' },
27
27
  ]);
28
28
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flashbacktech/flashbackclient",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
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": "ISC",
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"