@functionland/react-native-fula 1.55.12 → 1.55.15

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.
@@ -1,175 +1,177 @@
1
- import { NativeModules, Platform } from 'react-native';
2
-
3
- interface FulaNativeModule {
4
- registerLifecycleListener: () => Promise<void>;
5
- initFula: (
6
- identity: string, //Private key of did identity
7
- storePath: string, //You can leave empty
8
- bloxAddr: string, //Blox multiadddr needs to be manually entered now
9
- exchange: string, //set to 'noope' for testing
10
- autoFlush: boolean, //set to false always unless you know what you are doing. This is to write actions to disk explicitly after each write
11
- rootCid: string | null, //if you have the latest rootCid you can send it and it generates the private_ref for filesystem
12
- useRelay: boolean | null, // if true it forces the use of relay
13
- refresh: boolean // if true it forces to refresh the fula object
14
- ) => Promise<{ peerId: string; rootCid: string }>;
15
- newClient: (
16
- identity: string, //Private key of did identity
17
- storePath: string, //You can leave empty
18
- bloxAddr: string, //Blox multiadddr needs to be manually entered now
19
- exchange: string, //set to 'noope' for testing
20
- autoFlush: boolean, //set to false always unless you know what you are doing. This is to write actions to disk explicitly after each write
21
- useRelay: boolean | null, // if true it forces the use of relay
22
- refresh: boolean // if true it forces to refresh the fula object
23
- ) => Promise<string>;
24
- isReady: (filesystemCheck: boolean) => Promise<boolean>;
25
- logout: (identity: string, storePath: string) => Promise<boolean>;
26
- checkFailedActions: (retry: boolean, timeout: number) => Promise<boolean>;
27
- listFailedActions: (cids: string[]) => Promise<string[]>;
28
- listRecentCidsAsString: () => Promise<string[]>;
29
- listRecentCidsAsStringWithChildren: () => Promise<string[]>;
30
- clearCidsFromRecent: (cids: string[]) => Promise<boolean>;
31
- checkConnection: (timeout: number) => Promise<boolean>;
32
- get: (key: string) => Promise<string>;
33
- has: (key: Uint8Array) => Promise<boolean>;
34
- push: () => Promise<string>;
35
- put: (content: string, codec: string) => Promise<string>;
36
- mkdir: (path: string) => Promise<string>;
37
- writeFileContent: (path: string, content: string) => Promise<string>;
38
- writeFile: (
39
- fulaTargetFilename: string,
40
- localFilename: string
41
- ) => Promise<string>;
42
- ls: (path: string) => Promise<string>;
43
- rm: (path: string) => Promise<string>;
44
- cp: (sourcePath: string, targetPath: string) => Promise<string>;
45
- mv: (sourcePath: string, targetPath: string) => Promise<string>;
46
- readFile: (
47
- fulaTargetFilename: string,
48
- localFilename: string
49
- ) => Promise<string>;
50
- readFileContent: (path: string) => Promise<string>;
51
- setAuth: (peerId: string, allow: boolean) => Promise<boolean>;
52
-
53
- shutdown: () => Promise<void>;
54
-
55
- testData: (identity: string, bloxAddr: string) => Promise<string>;
56
-
57
- //Blockchain related functions
58
- createAccount: (seed: string) => Promise<string>;
59
- checkAccountExists: (account: string) => Promise<string>;
60
- accountFund: (account: string) => Promise<string>;
61
- createPool: (seed: string, poolName: string) => Promise<string>;
62
- listPools: () => Promise<string>;
63
- joinPool: (poolID: string) => Promise<string>;
64
- leavePool: (poolID: string) => Promise<string>;
65
- cancelPoolJoin: (poolID: string) => Promise<string>;
66
- listPoolJoinRequests: (poolID: string) => Promise<string>;
67
- votePoolJoinRequest: (
68
- seed: string,
69
- poolID: number,
70
- account: string,
71
- accept: boolean
72
- ) => Promise<string>;
73
- batchUploadManifest: (
74
- cid: string[],
75
- poolID: string,
76
- replicationFactor: string
77
- ) => Promise<string>;
78
- replicateInPool: (
79
- cid: string[],
80
- account: string,
81
- poolID: string
82
- ) => Promise<string>;
83
- newStoreRequest: (
84
- seed: string,
85
- poolID: number,
86
- uploader: string,
87
- cid: string
88
- ) => Promise<string>;
89
- listAvailableReplicationRequests: (poolID: string) => Promise<string>;
90
- removeReplicationRequest: (
91
- seed: string,
92
- poolID: number,
93
- cid: string
94
- ) => Promise<string>;
95
- removeStorer: (
96
- seed: string,
97
- storer: string,
98
- poolID: number,
99
- cid: string
100
- ) => Promise<string>;
101
- removeStoredReplication: (
102
- seed: string,
103
- uploader: string,
104
- poolID: number,
105
- cid: string
106
- ) => Promise<string>;
107
-
108
- //On Blox calls for chain
109
- //Hardware
110
- assetsBalance: (
111
- account: string,
112
- assetId: string,
113
- classId: string
114
- ) => Promise<string>;
115
- transferToFula: (
116
- amount: string,
117
- wallet: string,
118
- chain: string
119
- ) => Promise<string>;
120
- getAccount: () => Promise<string>;
121
-
122
- //Hardware
123
- eraseBlData: () => Promise<string>;
124
- fetchContainerLogs: (
125
- containerName: string,
126
- tailCount: string
127
- ) => Promise<string>;
128
- findBestAndTargetInLogs: (
129
- containerName: string,
130
- tailCount: string
131
- ) => Promise<string>;
132
- getFolderSize: (folderPath: string) => Promise<string>;
133
- getDatastoreSize: () => Promise<string>;
134
- bloxFreeSpace: () => Promise<string>;
135
- wifiRemoveall: () => Promise<string>;
136
- reboot: () => Promise<string>;
137
- partition: () => Promise<string>;
138
-
139
- // Plugin related functions
140
- listPlugins: () => Promise<string>;
141
- listActivePlugins: () => Promise<string>;
142
- installPlugin: (pluginName: string, params: string) => Promise<string>;
143
- uninstallPlugin: (pluginName: string) => Promise<string>;
144
- showPluginStatus: (pluginName: string, lines: number) => Promise<string>;
145
- getInstallOutput: (pluginName: string, params: string) => Promise<string>;
146
- getInstallStatus: (pluginName: string) => Promise<string>;
147
- updatePlugin: (pluginName: string) => Promise<string>;
148
- deleteDsLock: () => Promise<void>;
149
-
150
- //AI
151
- chatWithAI: (aiModel: string, userMessage: string) => Promise<string>;
152
- getChatChunk: (streamID: string) => Promise<string>;
153
- streamChunks: (streamID: string) => Promise<void>;
154
-
155
-
156
- }
157
-
158
- const LINKING_ERROR =
159
- `The package 'react-native-fula/Fula' doesn't seem to be linked. Make sure: \n\n` +
160
- Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
161
- '- You rebuilt the app after installing the package\n' +
162
- '- You are not using Expo managed workflow\n';
163
-
164
- const Fula = NativeModules.FulaModule
165
- ? NativeModules.FulaModule
166
- : new Proxy(
167
- {},
168
- {
169
- get() {
170
- throw new Error(LINKING_ERROR);
171
- },
172
- }
173
- );
174
-
175
- export default Fula as FulaNativeModule;
1
+ import { NativeModules, Platform } from 'react-native';
2
+
3
+ interface FulaNativeModule {
4
+ registerLifecycleListener: () => Promise<void>;
5
+ initFula: (
6
+ identity: string, //Private key of did identity
7
+ storePath: string, //You can leave empty
8
+ bloxAddr: string, //Blox multiadddr needs to be manually entered now
9
+ exchange: string, //set to 'noope' for testing
10
+ autoFlush: boolean, //set to false always unless you know what you are doing. This is to write actions to disk explicitly after each write
11
+ rootCid: string | null, //if you have the latest rootCid you can send it and it generates the private_ref for filesystem
12
+ useRelay: boolean | null, // if true it forces the use of relay
13
+ refresh: boolean // if true it forces to refresh the fula object
14
+ ) => Promise<{ peerId: string; rootCid: string }>;
15
+ newClient: (
16
+ identity: string, //Private key of did identity
17
+ storePath: string, //You can leave empty
18
+ bloxAddr: string, //Blox multiadddr needs to be manually entered now
19
+ exchange: string, //set to 'noope' for testing
20
+ autoFlush: boolean, //set to false always unless you know what you are doing. This is to write actions to disk explicitly after each write
21
+ useRelay: boolean | null, // if true it forces the use of relay
22
+ refresh: boolean // if true it forces to refresh the fula object
23
+ ) => Promise<string>;
24
+ isReady: (filesystemCheck: boolean) => Promise<boolean>;
25
+ logout: (identity: string, storePath: string) => Promise<boolean>;
26
+ checkFailedActions: (retry: boolean, timeout: number) => Promise<boolean>;
27
+ listFailedActions: (cids: string[]) => Promise<string[]>;
28
+ listRecentCidsAsString: () => Promise<string[]>;
29
+ listRecentCidsAsStringWithChildren: () => Promise<string[]>;
30
+ clearCidsFromRecent: (cids: string[]) => Promise<boolean>;
31
+ checkConnection: (timeout: number) => Promise<boolean>;
32
+ get: (key: string) => Promise<string>;
33
+ has: (key: Uint8Array) => Promise<boolean>;
34
+ push: () => Promise<string>;
35
+ put: (content: string, codec: string) => Promise<string>;
36
+ mkdir: (path: string) => Promise<string>;
37
+ writeFileContent: (path: string, content: string) => Promise<string>;
38
+ writeFile: (
39
+ fulaTargetFilename: string,
40
+ localFilename: string
41
+ ) => Promise<string>;
42
+ ls: (path: string) => Promise<string>;
43
+ rm: (path: string) => Promise<string>;
44
+ cp: (sourcePath: string, targetPath: string) => Promise<string>;
45
+ mv: (sourcePath: string, targetPath: string) => Promise<string>;
46
+ readFile: (
47
+ fulaTargetFilename: string,
48
+ localFilename: string
49
+ ) => Promise<string>;
50
+ readFileContent: (path: string) => Promise<string>;
51
+ setAuth: (peerId: string, allow: boolean) => Promise<boolean>;
52
+
53
+ shutdown: () => Promise<void>;
54
+
55
+ testData: (identity: string, bloxAddr: string) => Promise<string>;
56
+
57
+ //Blockchain related functions
58
+ createAccount: (seed: string) => Promise<string>;
59
+ checkAccountExists: (account: string) => Promise<string>;
60
+ accountFund: (account: string) => Promise<string>;
61
+ createPool: (seed: string, poolName: string) => Promise<string>;
62
+ listPools: () => Promise<string>;
63
+ joinPool: (poolID: string) => Promise<string>;
64
+ leavePool: (poolID: string) => Promise<string>;
65
+ joinPoolWithChain: (poolID: string, chainName: string) => Promise<string>;
66
+ leavePoolWithChain: (poolID: string, chainName: string) => Promise<string>;
67
+ cancelPoolJoin: (poolID: string) => Promise<string>;
68
+ listPoolJoinRequests: (poolID: string) => Promise<string>;
69
+ votePoolJoinRequest: (
70
+ seed: string,
71
+ poolID: number,
72
+ account: string,
73
+ accept: boolean
74
+ ) => Promise<string>;
75
+ batchUploadManifest: (
76
+ cid: string[],
77
+ poolID: string,
78
+ replicationFactor: string
79
+ ) => Promise<string>;
80
+ replicateInPool: (
81
+ cid: string[],
82
+ account: string,
83
+ poolID: string
84
+ ) => Promise<string>;
85
+ newStoreRequest: (
86
+ seed: string,
87
+ poolID: number,
88
+ uploader: string,
89
+ cid: string
90
+ ) => Promise<string>;
91
+ listAvailableReplicationRequests: (poolID: string) => Promise<string>;
92
+ removeReplicationRequest: (
93
+ seed: string,
94
+ poolID: number,
95
+ cid: string
96
+ ) => Promise<string>;
97
+ removeStorer: (
98
+ seed: string,
99
+ storer: string,
100
+ poolID: number,
101
+ cid: string
102
+ ) => Promise<string>;
103
+ removeStoredReplication: (
104
+ seed: string,
105
+ uploader: string,
106
+ poolID: number,
107
+ cid: string
108
+ ) => Promise<string>;
109
+
110
+ //On Blox calls for chain
111
+ //Hardware
112
+ assetsBalance: (
113
+ account: string,
114
+ assetId: string,
115
+ classId: string
116
+ ) => Promise<string>;
117
+ transferToFula: (
118
+ amount: string,
119
+ wallet: string,
120
+ chain: string
121
+ ) => Promise<string>;
122
+ getAccount: () => Promise<string>;
123
+
124
+ //Hardware
125
+ eraseBlData: () => Promise<string>;
126
+ fetchContainerLogs: (
127
+ containerName: string,
128
+ tailCount: string
129
+ ) => Promise<string>;
130
+ findBestAndTargetInLogs: (
131
+ containerName: string,
132
+ tailCount: string
133
+ ) => Promise<string>;
134
+ getFolderSize: (folderPath: string) => Promise<string>;
135
+ getDatastoreSize: () => Promise<string>;
136
+ bloxFreeSpace: () => Promise<string>;
137
+ wifiRemoveall: () => Promise<string>;
138
+ reboot: () => Promise<string>;
139
+ partition: () => Promise<string>;
140
+
141
+ // Plugin related functions
142
+ listPlugins: () => Promise<string>;
143
+ listActivePlugins: () => Promise<string>;
144
+ installPlugin: (pluginName: string, params: string) => Promise<string>;
145
+ uninstallPlugin: (pluginName: string) => Promise<string>;
146
+ showPluginStatus: (pluginName: string, lines: number) => Promise<string>;
147
+ getInstallOutput: (pluginName: string, params: string) => Promise<string>;
148
+ getInstallStatus: (pluginName: string) => Promise<string>;
149
+ updatePlugin: (pluginName: string) => Promise<string>;
150
+ deleteDsLock: () => Promise<void>;
151
+
152
+ //AI
153
+ chatWithAI: (aiModel: string, userMessage: string) => Promise<string>;
154
+ getChatChunk: (streamID: string) => Promise<string>;
155
+ streamChunks: (streamID: string) => Promise<void>;
156
+
157
+
158
+ }
159
+
160
+ const LINKING_ERROR =
161
+ `The package 'react-native-fula/Fula' doesn't seem to be linked. Make sure: \n\n` +
162
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
163
+ '- You rebuilt the app after installing the package\n' +
164
+ '- You are not using Expo managed workflow\n';
165
+
166
+ const Fula = NativeModules.FulaModule
167
+ ? NativeModules.FulaModule
168
+ : new Proxy(
169
+ {},
170
+ {
171
+ get() {
172
+ throw new Error(LINKING_ERROR);
173
+ },
174
+ }
175
+ );
176
+
177
+ export default Fula as FulaNativeModule;
@@ -182,6 +182,78 @@ export const leavePool = (poolID: number): Promise<BType.PoolLeaveResponse> => {
182
182
  return res1;
183
183
  };
184
184
 
185
+ /*
186
+ joinPoolWithChain: This function takes two arguments: poolID and chainName. The poolID is the ID of the pool to join, and the chainName specifies the blockchain network to use for the operation. The function returns a promise of an object that contains the account and poolID.
187
+ */
188
+ export const joinPoolWithChain = (poolID: number, chainName: string): Promise<BType.PoolJoinResponse> => {
189
+ console.log('joinPoolWithChain in react-native started', poolID, chainName);
190
+
191
+ // Validate inputs
192
+ if (typeof poolID !== 'number' || poolID <= 0) {
193
+ return Promise.reject(new Error('Pool ID must be a positive number'));
194
+ }
195
+
196
+ if (typeof chainName !== 'string' || chainName.trim().length === 0) {
197
+ return Promise.reject(new Error('Chain name must be a non-empty string'));
198
+ }
199
+
200
+ let res1 = Fula.joinPoolWithChain(poolID.toString(), chainName.trim())
201
+ .then((res) => {
202
+ try {
203
+ let jsonRes: BType.PoolJoinResponse = JSON.parse(res);
204
+ return jsonRes;
205
+ } catch (e) {
206
+ try {
207
+ return JSON.parse(res);
208
+ } catch (e2) {
209
+ console.error('Error parsing res in joining pool with chain:', e);
210
+ return res; // Return raw response if parsing fails
211
+ }
212
+ }
213
+ })
214
+ .catch((err) => {
215
+ console.error('Error joining pool with chain:', err);
216
+ throw err; // Rethrow the error to maintain the rejection state
217
+ });
218
+ return res1;
219
+ };
220
+
221
+ /*
222
+ leavePoolWithChain: This function takes two arguments: poolID and chainName. The poolID is the ID of the pool to leave, and the chainName specifies the blockchain network to use for the operation. The function returns a promise of an object that contains the account and poolID.
223
+ */
224
+ export const leavePoolWithChain = (poolID: number, chainName: string): Promise<BType.PoolLeaveResponse> => {
225
+ console.log('leavePoolWithChain in react-native started', poolID, chainName);
226
+
227
+ // Validate inputs
228
+ if (typeof poolID !== 'number' || poolID <= 0) {
229
+ return Promise.reject(new Error('Pool ID must be a positive number'));
230
+ }
231
+
232
+ if (typeof chainName !== 'string' || chainName.trim().length === 0) {
233
+ return Promise.reject(new Error('Chain name must be a non-empty string'));
234
+ }
235
+
236
+ let res1 = Fula.leavePoolWithChain(poolID.toString(), chainName.trim())
237
+ .then((res) => {
238
+ try {
239
+ let jsonRes: BType.PoolLeaveResponse = JSON.parse(res);
240
+ return jsonRes;
241
+ } catch (e) {
242
+ try {
243
+ return JSON.parse(res);
244
+ } catch (e2) {
245
+ console.error('Error parsing res in leaving pool with chain:', e);
246
+ return res; // Return raw response if parsing fails
247
+ }
248
+ }
249
+ })
250
+ .catch((err) => {
251
+ console.error('Error leaving pool with chain:', err);
252
+ throw err; // Rethrow the error to maintain the rejection state
253
+ });
254
+ return res1;
255
+ };
256
+
185
257
  export const cancelPoolJoin = (
186
258
  poolID: number
187
259
  ): Promise<BType.PoolCancelJoinResponse> => {