@flashbacktech/flashbackclient 0.1.39 → 0.1.41
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/stellarv2/client/index.d.ts +1 -6
- package/dist/stellarv2/client/index.js +24 -10
- package/dist/stellarv2/wallet/transaction.js +0 -53
- package/package.json +1 -1
- package/dist/api/types.d.ts +0 -89
- package/dist/api/types.js +0 -20
- package/dist/consumer/file/delete.d.ts +0 -3
- package/dist/consumer/file/delete.js +0 -23
- package/dist/consumer/file/getUrl.d.ts +0 -3
- package/dist/consumer/file/getUrl.js +0 -20
- package/dist/consumer/file/index.d.ts +0 -30
- package/dist/consumer/file/index.js +0 -52
- package/dist/consumer/file/types.d.ts +0 -25
- package/dist/consumer/file/types.js +0 -2
- package/dist/consumer/file/upload.d.ts +0 -3
- package/dist/consumer/file/upload.js +0 -75
- package/dist/consumer/index.d.ts +0 -1
- package/dist/consumer/index.js +0 -17
- package/dist/stellar/client.d.ts +0 -282
- package/dist/stellar/client.js +0 -453
- package/dist/stellar/consumer.d.ts +0 -10
- package/dist/stellar/consumer.js +0 -86
- package/dist/stellar/decorator.d.ts +0 -1
- package/dist/stellar/decorator.js +0 -33
- package/dist/stellar/index.d.ts +0 -4
- package/dist/stellar/index.js +0 -5
- package/dist/stellar/models.d.ts +0 -55
- package/dist/stellar/models.js +0 -2
- package/dist/stellar/provider.d.ts +0 -10
- package/dist/stellar/provider.js +0 -86
- package/dist/stellar/reservation.d.ts +0 -8
- package/dist/stellar/reservation.js +0 -61
- package/dist/stellar/stats.d.ts +0 -4
- package/dist/stellar/stats.js +0 -12
- package/dist/stellar/transaction.d.ts +0 -24
- package/dist/stellar/transaction.js +0 -138
- package/dist/stellar/unit.d.ts +0 -12
- package/dist/stellar/unit.js +0 -100
- package/dist/stellarv2/bucket.d.ts +0 -111
- package/dist/stellarv2/bucket.js +0 -262
- package/dist/stellarv2/client.d.ts +0 -134
- package/dist/stellarv2/client.js +0 -240
- package/dist/stellarv2/consumer.d.ts +0 -60
- package/dist/stellarv2/consumer.js +0 -145
- package/dist/stellarv2/deal.d.ts +0 -160
- package/dist/stellarv2/deal.js +0 -357
- package/dist/stellarv2/funding.d.ts +0 -46
- package/dist/stellarv2/funding.js +0 -86
- package/dist/stellarv2/provider.d.ts +0 -72
- package/dist/stellarv2/provider.js +0 -174
- package/dist/stellarv2/transaction.d.ts +0 -36
- package/dist/stellarv2/transaction.js +0 -168
|
@@ -82,12 +82,6 @@ export declare class FlashOnStellarClientV2 {
|
|
|
82
82
|
* @returns Promise resolving to the update result
|
|
83
83
|
*/
|
|
84
84
|
setStableAssetAddress(stable_asset_address: string): Promise<boolean>;
|
|
85
|
-
/**
|
|
86
|
-
* Upgrades the contract (owner only)
|
|
87
|
-
* @param new_wasm_hash - Hash of the new WASM bytecode
|
|
88
|
-
* @returns Promise resolving to the upgrade result
|
|
89
|
-
*/
|
|
90
|
-
upgrade(new_wasm_hash: string): Promise<boolean>;
|
|
91
85
|
/**
|
|
92
86
|
* Gets system statistics
|
|
93
87
|
* @returns Promise resolving to system statistics
|
|
@@ -110,6 +104,7 @@ export declare class FlashOnStellarClientV2 {
|
|
|
110
104
|
deals: any[];
|
|
111
105
|
activeDeals: any[];
|
|
112
106
|
} | null>;
|
|
107
|
+
registerAsConsumerProvider(address: string, description: string): Promise<void>;
|
|
113
108
|
/**
|
|
114
109
|
* Gets comprehensive information about a consumer including their deals
|
|
115
110
|
* @param consumer_id - Address of the consumer
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FlashOnStellarClientV2 = void 0;
|
|
4
|
+
const transaction_1 = require("../wallet/transaction");
|
|
4
5
|
const consumer_1 = require("./consumer");
|
|
5
6
|
const provider_1 = require("./provider");
|
|
6
7
|
const bucket_1 = require("./bucket");
|
|
7
8
|
const deal_1 = require("./deal");
|
|
8
9
|
const funding_1 = require("./funding");
|
|
10
|
+
const decorator_1 = require("../utils/decorator");
|
|
9
11
|
/**
|
|
10
12
|
* Main client class for interacting with the FlashOnStellar V2 system
|
|
11
13
|
* This client provides methods for managing providers, consumers, buckets, and deals
|
|
@@ -105,16 +107,6 @@ class FlashOnStellarClientV2 {
|
|
|
105
107
|
// Implementation depends on the transaction layer
|
|
106
108
|
throw new Error('setStableAssetAddress not implemented - requires transaction layer implementation');
|
|
107
109
|
}
|
|
108
|
-
/**
|
|
109
|
-
* Upgrades the contract (owner only)
|
|
110
|
-
* @param new_wasm_hash - Hash of the new WASM bytecode
|
|
111
|
-
* @returns Promise resolving to the upgrade result
|
|
112
|
-
*/
|
|
113
|
-
async upgrade(new_wasm_hash) {
|
|
114
|
-
// This would call the upgrade() method on the contract
|
|
115
|
-
// Implementation depends on the transaction layer
|
|
116
|
-
throw new Error('upgrade not implemented - requires transaction layer implementation');
|
|
117
|
-
}
|
|
118
110
|
/**
|
|
119
111
|
* Gets system statistics
|
|
120
112
|
* @returns Promise resolving to system statistics
|
|
@@ -179,6 +171,28 @@ class FlashOnStellarClientV2 {
|
|
|
179
171
|
return null;
|
|
180
172
|
}
|
|
181
173
|
}
|
|
174
|
+
async registerAsConsumerProvider(address, description) {
|
|
175
|
+
const provider_id = address;
|
|
176
|
+
const consumer_id = address;
|
|
177
|
+
(0, decorator_1.withSignature)(async (address, description) => {
|
|
178
|
+
await (0, transaction_1.executeMultiWalletTransactions)(this.getContext(), address, [
|
|
179
|
+
{
|
|
180
|
+
method: "register_consumer",
|
|
181
|
+
additionalArgs: [
|
|
182
|
+
{ value: consumer_id, type: 'address' },
|
|
183
|
+
{ value: description, type: 'string' }
|
|
184
|
+
]
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
method: "register_provider",
|
|
188
|
+
additionalArgs: [
|
|
189
|
+
{ value: provider_id, type: 'address' },
|
|
190
|
+
{ value: description, type: 'string' }
|
|
191
|
+
]
|
|
192
|
+
}
|
|
193
|
+
]);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
182
196
|
/**
|
|
183
197
|
* Gets comprehensive information about a consumer including their deals
|
|
184
198
|
* @param consumer_id - Address of the consumer
|
|
@@ -42,9 +42,7 @@ const getServer = (network) => {
|
|
|
42
42
|
serverUrl = "https://rpc.stellar.org";
|
|
43
43
|
break;
|
|
44
44
|
}
|
|
45
|
-
console.log(`!!!Creating Soroban RPC server for network: ${network.network}, URL: ${serverUrl}`);
|
|
46
45
|
// For Stellar SDK v13+, we need to handle the allowHttp issue
|
|
47
|
-
// Try different approaches to create the server
|
|
48
46
|
let server;
|
|
49
47
|
// Approach 1: Try with allowHttp option
|
|
50
48
|
try {
|
|
@@ -56,57 +54,6 @@ const getServer = (network) => {
|
|
|
56
54
|
catch (error) {
|
|
57
55
|
console.log(`Failed with allowHttp: true:`, error instanceof Error ? error.message : String(error));
|
|
58
56
|
}
|
|
59
|
-
// Approach 1.5: Try with allowHttp as a boolean string
|
|
60
|
-
try {
|
|
61
|
-
console.log(`Attempting to create server with allowHttp: "true"`);
|
|
62
|
-
server = new stellar_sdk_2.rpc.Server(serverUrl, { allowHttp: "true" });
|
|
63
|
-
console.log(`Soroban RPC server created successfully with allowHttp: "true"`);
|
|
64
|
-
return server;
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
console.log(`Failed with allowHttp: "true":`, error instanceof Error ? error.message : String(error));
|
|
68
|
-
}
|
|
69
|
-
// Approach 1.6: Try with allowHttp as a number
|
|
70
|
-
try {
|
|
71
|
-
console.log(`Attempting to create server with allowHttp: 1`);
|
|
72
|
-
server = new stellar_sdk_2.rpc.Server(serverUrl, { allowHttp: 1 });
|
|
73
|
-
console.log(`Soroban RPC server created successfully with allowHttp: 1`);
|
|
74
|
-
return server;
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
console.log(`Failed with allowHttp: 1:`, error instanceof Error ? error.message : String(error));
|
|
78
|
-
}
|
|
79
|
-
// Approach 3: Try without any options
|
|
80
|
-
try {
|
|
81
|
-
console.log(`Attempting to create server without options`);
|
|
82
|
-
server = new stellar_sdk_2.rpc.Server(serverUrl);
|
|
83
|
-
console.log(`Soroban RPC server created successfully without options`);
|
|
84
|
-
return server;
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
console.log(`Failed without options:`, error instanceof Error ? error.message : String(error));
|
|
88
|
-
}
|
|
89
|
-
// Approach 4: Try with empty options
|
|
90
|
-
try {
|
|
91
|
-
console.log(`Attempting to create server with empty options`);
|
|
92
|
-
server = new stellar_sdk_2.rpc.Server(serverUrl, {});
|
|
93
|
-
console.log(`Soroban RPC server created successfully with empty options`);
|
|
94
|
-
return server;
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
console.log(`Failed with empty options:`, error instanceof Error ? error.message : String(error));
|
|
98
|
-
}
|
|
99
|
-
// Approach 5: Try with a different URL format (without protocol)
|
|
100
|
-
try {
|
|
101
|
-
console.log(`Attempting to create server with URL without protocol`);
|
|
102
|
-
const urlWithoutProtocol = serverUrl.replace('https://', '');
|
|
103
|
-
server = new stellar_sdk_2.rpc.Server(urlWithoutProtocol, { allowHttp: true });
|
|
104
|
-
console.log(`Soroban RPC server created successfully with URL without protocol`);
|
|
105
|
-
return server;
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
console.log(`Failed with URL without protocol:`, error instanceof Error ? error.message : String(error));
|
|
109
|
-
}
|
|
110
57
|
// If all approaches fail, throw a comprehensive error
|
|
111
58
|
throw new Error(`Failed to create Soroban RPC server for ${network.network} at ${serverUrl}. All configuration attempts failed.`);
|
|
112
59
|
};
|
package/package.json
CHANGED
package/dist/api/types.d.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/api/types.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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 = {}));
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.deleteFile = deleteFile;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
async function deleteFile(client, params) {
|
|
9
|
-
try {
|
|
10
|
-
const { data } = await client.delete('/file/', {
|
|
11
|
-
params,
|
|
12
|
-
data: params,
|
|
13
|
-
});
|
|
14
|
-
return data;
|
|
15
|
-
}
|
|
16
|
-
catch (error) {
|
|
17
|
-
if (axios_1.default.isAxiosError(error) && error.response?.data) {
|
|
18
|
-
const errorData = error.response.data;
|
|
19
|
-
throw new Error(`Delete failed: ${errorData.message}`);
|
|
20
|
-
}
|
|
21
|
-
throw error;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getUrl = getUrl;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
async function getUrl(client, params) {
|
|
9
|
-
try {
|
|
10
|
-
const { data } = await client.get('/file/', { params });
|
|
11
|
-
return data;
|
|
12
|
-
}
|
|
13
|
-
catch (error) {
|
|
14
|
-
if (axios_1.default.isAxiosError(error) && error.response?.data) {
|
|
15
|
-
const errorData = error.response.data;
|
|
16
|
-
throw new Error(`Get URL failed: ${errorData.message}`);
|
|
17
|
-
}
|
|
18
|
-
throw error;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.StorageClient = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const upload_1 = require("./upload");
|
|
9
|
-
const getUrl_1 = require("./getUrl");
|
|
10
|
-
const delete_1 = require("./delete");
|
|
11
|
-
class StorageClient {
|
|
12
|
-
constructor(config) {
|
|
13
|
-
this.config = {
|
|
14
|
-
baseUrl: config.baseUrl.replace(/\/$/, ''),
|
|
15
|
-
timeout: config.timeout || 30000,
|
|
16
|
-
headers: {
|
|
17
|
-
'Content-Type': 'application/json',
|
|
18
|
-
...config.headers,
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
this.client = axios_1.default.create({
|
|
22
|
-
baseURL: this.config.baseUrl,
|
|
23
|
-
timeout: this.config.timeout,
|
|
24
|
-
headers: this.config.headers,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Upload a file to storage
|
|
29
|
-
* @param params Upload parameters including file data and type
|
|
30
|
-
* @returns Promise with the file URL
|
|
31
|
-
*/
|
|
32
|
-
async upload(params) {
|
|
33
|
-
return (0, upload_1.upload)(this.client, params);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Get the URL for a file
|
|
37
|
-
* @param params File identifier parameters
|
|
38
|
-
* @returns Promise with the file URL
|
|
39
|
-
*/
|
|
40
|
-
async getUrl(params) {
|
|
41
|
-
return (0, getUrl_1.getUrl)(this.client, params);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Delete a file from storage
|
|
45
|
-
* @param params File identifier parameters
|
|
46
|
-
* @returns Promise indicating success
|
|
47
|
-
*/
|
|
48
|
-
async delete(params) {
|
|
49
|
-
return (0, delete_1.deleteFile)(this.client, params);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.StorageClient = StorageClient;
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.upload = upload;
|
|
7
|
-
/// <reference lib="dom" />
|
|
8
|
-
//import type { Blob } from 'buffer';
|
|
9
|
-
const formdata_node_1 = require("formdata-node");
|
|
10
|
-
const axios_1 = __importDefault(require("axios"));
|
|
11
|
-
async function upload(client, params) {
|
|
12
|
-
try {
|
|
13
|
-
let url = '';
|
|
14
|
-
switch (params.type) {
|
|
15
|
-
case 'multipart': {
|
|
16
|
-
const formData = new formdata_node_1.FormData();
|
|
17
|
-
formData.append('type', 'multipart');
|
|
18
|
-
formData.append('folderId', params.folderId);
|
|
19
|
-
formData.append('fileId', params.fileId);
|
|
20
|
-
// If params.data is already a Blob/File, use it directly
|
|
21
|
-
// Otherwise, create a new Blob with the correct type
|
|
22
|
-
const fileBlob = params.data;
|
|
23
|
-
formData.append('file', fileBlob);
|
|
24
|
-
const response = await client.post('/file/', formData, {
|
|
25
|
-
headers: {
|
|
26
|
-
'Content-Type': 'multipart/form-data',
|
|
27
|
-
},
|
|
28
|
-
// Prevent any data transformation
|
|
29
|
-
transformRequest: [(data) => data],
|
|
30
|
-
// Ensure binary data handling
|
|
31
|
-
responseType: 'json',
|
|
32
|
-
maxBodyLength: Infinity,
|
|
33
|
-
maxContentLength: Infinity,
|
|
34
|
-
});
|
|
35
|
-
url = response.data.url;
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
case 'binary': {
|
|
39
|
-
// Binary upload
|
|
40
|
-
const response = await client.post('/file/', params.data, {
|
|
41
|
-
headers: {
|
|
42
|
-
'Content-Type': 'application/octet-stream',
|
|
43
|
-
'x-upload-type': 'binary',
|
|
44
|
-
'x-folder-id': params.folderId,
|
|
45
|
-
'x-file-id': params.fileId,
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
url = response.data.url;
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
case 'base64': {
|
|
52
|
-
const response = await client.post('/file/', {
|
|
53
|
-
type: 'base64',
|
|
54
|
-
folderId: params.folderId,
|
|
55
|
-
fileId: params.fileId,
|
|
56
|
-
data: params.data,
|
|
57
|
-
}, {
|
|
58
|
-
headers: { 'Content-Type': 'application/json' },
|
|
59
|
-
});
|
|
60
|
-
url = response.data.url;
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
default:
|
|
64
|
-
throw new Error('Invalid file type');
|
|
65
|
-
}
|
|
66
|
-
return { url };
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
if (axios_1.default.isAxiosError(error) && error.response?.data) {
|
|
70
|
-
const errorData = error.response.data;
|
|
71
|
-
throw new Error(`Upload failed: ${errorData.message}`);
|
|
72
|
-
}
|
|
73
|
-
throw error;
|
|
74
|
-
}
|
|
75
|
-
}
|
package/dist/consumer/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './file';
|
package/dist/consumer/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./file"), exports);
|