@peers-app/peers-sdk 0.8.3 → 0.8.4

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.
@@ -129,3 +129,27 @@ rpc_types_1.rpcServerCalls.getFileContents = async (fileId, encoding = 'utf8') =
129
129
  }
130
130
  return Buffer.from(data).toString(encoding);
131
131
  };
132
+ // Get file contents as base64 - useful for binary data like images
133
+ rpc_types_1.rpcServerCalls.getFileContentsBase64 = async (fileId) => {
134
+ const data = await Files().getFileContents(fileId);
135
+ if (data === null) {
136
+ throw new Error(`File not found: ${fileId}`);
137
+ }
138
+ return Buffer.from(data).toString('base64');
139
+ };
140
+ // Save a file from the UI - data should be base64 encoded for binary files
141
+ rpc_types_1.rpcServerCalls.saveFile = async (input) => {
142
+ const fileId = input.fileId || (0, utils_1.newid)();
143
+ const encoding = input.encoding || 'utf8';
144
+ // Convert data to Uint8Array based on encoding
145
+ const dataBuffer = encoding === 'base64'
146
+ ? Buffer.from(input.data, 'base64')
147
+ : Buffer.from(input.data, 'utf8');
148
+ const file = await Files().saveFile({
149
+ fileId,
150
+ name: input.name,
151
+ fileSize: dataBuffer.length,
152
+ mimeType: input.mimeType,
153
+ }, new Uint8Array(dataBuffer));
154
+ return file;
155
+ };
@@ -18,6 +18,20 @@ export declare const rpcServerCalls: {
18
18
  encryptData: ((value: string, groupId?: string) => Promise<string>);
19
19
  tableMethodCall: ((dataContextId: string, tableName: string, methodName: string, ...args: any[]) => Promise<any>);
20
20
  getFileContents: ((fileId: string, encoding?: BufferEncoding) => Promise<string>);
21
+ getFileContentsBase64: ((fileId: string) => Promise<string>);
22
+ saveFile: ((input: {
23
+ name: string;
24
+ mimeType?: string;
25
+ data: string;
26
+ encoding?: "utf8" | "base64";
27
+ fileId?: string;
28
+ }) => Promise<{
29
+ fileId: string;
30
+ name: string;
31
+ fileSize: number;
32
+ fileHash: string;
33
+ mimeType?: string;
34
+ }>);
21
35
  injectUIBundle: ((uiBundleFileId: string) => Promise<void>);
22
36
  resetAllDeviceSyncInfo: (() => Promise<void>);
23
37
  importGroupShare: ((groupShareJson: string) => Promise<string>);
package/dist/rpc-types.js CHANGED
@@ -19,6 +19,10 @@ exports.rpcServerCalls = {
19
19
  tableMethodCall: rpcStub('tableMethodCall'),
20
20
  // TODO lock this down so not all code can get any file contents
21
21
  getFileContents: rpcStub('getFileContents'),
22
+ // Get file contents as base64 - useful for binary data like images
23
+ getFileContentsBase64: rpcStub('getFileContentsBase64'),
24
+ // Save a file from the UI - data should be base64 encoded for binary files
25
+ saveFile: rpcStub('saveFile'),
22
26
  // Inject UI bundle directly into WebView (bypasses slow postMessage for large strings)
23
27
  injectUIBundle: rpcStub('injectUIBundle'),
24
28
  resetAllDeviceSyncInfo: rpcStub('resetAllDeviceSyncInfo'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peers-app/peers-sdk",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/peers-app/peers-sdk.git"