bedrock-ts-sdk 0.0.4 → 0.0.5
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 +4 -4
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +31 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ const client = await BedrockClient.fromPrivateKey('0x...');
|
|
|
34
34
|
// Upload a file
|
|
35
35
|
const files = await client.files.uploadFiles([{
|
|
36
36
|
name: 'hello.txt',
|
|
37
|
-
path: 'documents/hello.txt',
|
|
37
|
+
path: '/documents/hello.txt',
|
|
38
38
|
content: Buffer.from('Hello, Bedrock!'),
|
|
39
39
|
}]);
|
|
40
40
|
|
|
@@ -74,7 +74,7 @@ const buffer = Buffer.from(await file.arrayBuffer());
|
|
|
74
74
|
|
|
75
75
|
await client.files.uploadFiles([{
|
|
76
76
|
name: file.name,
|
|
77
|
-
path:
|
|
77
|
+
path: `/uploads/${file.name}`,
|
|
78
78
|
content: buffer,
|
|
79
79
|
}]);
|
|
80
80
|
```
|
|
@@ -121,12 +121,12 @@ const client = await BedrockClient.fromSignature(
|
|
|
121
121
|
const files = await client.files.uploadFiles([
|
|
122
122
|
{
|
|
123
123
|
name: 'document.pdf',
|
|
124
|
-
path: 'documents/document.pdf',
|
|
124
|
+
path: '/documents/document.pdf',
|
|
125
125
|
content: fileBuffer, // Buffer or File
|
|
126
126
|
},
|
|
127
127
|
{
|
|
128
128
|
name: 'image.jpg',
|
|
129
|
-
path: 'images/image.jpg',
|
|
129
|
+
path: '/images/image.jpg',
|
|
130
130
|
content: imageBuffer,
|
|
131
131
|
},
|
|
132
132
|
]);
|
package/dist/index.d.mts
CHANGED
|
@@ -661,7 +661,7 @@ interface FileInput {
|
|
|
661
661
|
* File service for managing encrypted files
|
|
662
662
|
*/
|
|
663
663
|
declare class FileService {
|
|
664
|
-
private core;
|
|
664
|
+
private readonly core;
|
|
665
665
|
constructor(core: BedrockCore);
|
|
666
666
|
/**
|
|
667
667
|
* Initialize file entries aggregate if it doesn't exist
|
package/dist/index.d.ts
CHANGED
|
@@ -661,7 +661,7 @@ interface FileInput {
|
|
|
661
661
|
* File service for managing encrypted files
|
|
662
662
|
*/
|
|
663
663
|
declare class FileService {
|
|
664
|
-
private core;
|
|
664
|
+
private readonly core;
|
|
665
665
|
constructor(core: BedrockCore);
|
|
666
666
|
/**
|
|
667
667
|
* Initialize file entries aggregate if it doesn't exist
|
package/dist/index.js
CHANGED
|
@@ -1087,10 +1087,10 @@ var FileService = class {
|
|
|
1087
1087
|
try {
|
|
1088
1088
|
for (const path of filePaths) {
|
|
1089
1089
|
const file = await this.getFile(path);
|
|
1090
|
-
await aleph.updatePost(
|
|
1090
|
+
const updatedPost = await aleph.updatePost(
|
|
1091
1091
|
POST_TYPES.FILE,
|
|
1092
1092
|
file.post_hash,
|
|
1093
|
-
[
|
|
1093
|
+
[aleph.getAddress()],
|
|
1094
1094
|
FileMetaEncryptedSchema,
|
|
1095
1095
|
async (encryptedMeta) => {
|
|
1096
1096
|
const decryptedMeta = await this.decryptFileMeta(encryptedMeta);
|
|
@@ -1098,6 +1098,11 @@ var FileService = class {
|
|
|
1098
1098
|
return await this.encryptFileMeta(decryptedMeta);
|
|
1099
1099
|
}
|
|
1100
1100
|
);
|
|
1101
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => ({
|
|
1102
|
+
files: aggregate.files.map(
|
|
1103
|
+
(entry) => entry.post_hash === file.post_hash ? { ...entry, post_hash: updatedPost.item_hash } : entry
|
|
1104
|
+
)
|
|
1105
|
+
}));
|
|
1101
1106
|
}
|
|
1102
1107
|
} catch (error) {
|
|
1103
1108
|
throw new FileError(`Failed to soft delete files: ${error.message}`);
|
|
@@ -1112,10 +1117,10 @@ var FileService = class {
|
|
|
1112
1117
|
try {
|
|
1113
1118
|
for (const path of filePaths) {
|
|
1114
1119
|
const file = await this.getFile(path);
|
|
1115
|
-
await aleph.updatePost(
|
|
1120
|
+
const updatedPost = await aleph.updatePost(
|
|
1116
1121
|
POST_TYPES.FILE,
|
|
1117
1122
|
file.post_hash,
|
|
1118
|
-
[
|
|
1123
|
+
[aleph.getAddress()],
|
|
1119
1124
|
FileMetaEncryptedSchema,
|
|
1120
1125
|
async (encryptedMeta) => {
|
|
1121
1126
|
const decryptedMeta = await this.decryptFileMeta(encryptedMeta);
|
|
@@ -1123,6 +1128,11 @@ var FileService = class {
|
|
|
1123
1128
|
return await this.encryptFileMeta(decryptedMeta);
|
|
1124
1129
|
}
|
|
1125
1130
|
);
|
|
1131
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => ({
|
|
1132
|
+
files: aggregate.files.map(
|
|
1133
|
+
(entry) => entry.post_hash === file.post_hash ? { ...entry, post_hash: updatedPost.item_hash } : entry
|
|
1134
|
+
)
|
|
1135
|
+
}));
|
|
1126
1136
|
}
|
|
1127
1137
|
} catch (error) {
|
|
1128
1138
|
throw new FileError(`Failed to restore files: ${error.message}`);
|
|
@@ -1155,10 +1165,10 @@ var FileService = class {
|
|
|
1155
1165
|
try {
|
|
1156
1166
|
for (const { oldPath, newPath } of moves) {
|
|
1157
1167
|
const file = await this.getFile(oldPath);
|
|
1158
|
-
await aleph.updatePost(
|
|
1168
|
+
const updatedPost = await aleph.updatePost(
|
|
1159
1169
|
POST_TYPES.FILE,
|
|
1160
1170
|
file.post_hash,
|
|
1161
|
-
[
|
|
1171
|
+
[aleph.getAddress()],
|
|
1162
1172
|
FileMetaEncryptedSchema,
|
|
1163
1173
|
async (encryptedMeta) => {
|
|
1164
1174
|
const decryptedMeta = await this.decryptFileMeta(encryptedMeta);
|
|
@@ -1170,7 +1180,7 @@ var FileService = class {
|
|
|
1170
1180
|
const newEncryptedPath = EncryptionService.encryptEcies(newPath, publicKey);
|
|
1171
1181
|
await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => ({
|
|
1172
1182
|
files: aggregate.files.map(
|
|
1173
|
-
(entry) => entry.post_hash === file.post_hash ? { ...entry, path: newEncryptedPath } : entry
|
|
1183
|
+
(entry) => entry.post_hash === file.post_hash ? { ...entry, path: newEncryptedPath, post_hash: updatedPost.item_hash } : entry
|
|
1174
1184
|
)
|
|
1175
1185
|
}));
|
|
1176
1186
|
}
|
|
@@ -1210,10 +1220,10 @@ var FileService = class {
|
|
|
1210
1220
|
const file = await this.getFile(filePath);
|
|
1211
1221
|
const encryptedKey = EncryptionService.encryptEcies(file.key, contactPublicKey);
|
|
1212
1222
|
const encryptedIv = EncryptionService.encryptEcies(file.iv, contactPublicKey);
|
|
1213
|
-
await aleph.updatePost(
|
|
1223
|
+
const updatedPost = await aleph.updatePost(
|
|
1214
1224
|
POST_TYPES.FILE,
|
|
1215
1225
|
file.post_hash,
|
|
1216
|
-
[
|
|
1226
|
+
[aleph.getAddress()],
|
|
1217
1227
|
FileMetaEncryptedSchema,
|
|
1218
1228
|
async (encryptedMeta) => {
|
|
1219
1229
|
const decryptedMeta = await this.decryptFileMeta(encryptedMeta);
|
|
@@ -1226,7 +1236,11 @@ var FileService = class {
|
|
|
1226
1236
|
);
|
|
1227
1237
|
await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => ({
|
|
1228
1238
|
files: aggregate.files.map(
|
|
1229
|
-
(entry) => entry.post_hash === file.post_hash ? {
|
|
1239
|
+
(entry) => entry.post_hash === file.post_hash ? {
|
|
1240
|
+
...entry,
|
|
1241
|
+
post_hash: updatedPost.item_hash,
|
|
1242
|
+
shared_with: [.../* @__PURE__ */ new Set([...entry.shared_with, contactPublicKey])]
|
|
1243
|
+
} : entry
|
|
1230
1244
|
)
|
|
1231
1245
|
}));
|
|
1232
1246
|
} catch (error) {
|
|
@@ -1242,10 +1256,10 @@ var FileService = class {
|
|
|
1242
1256
|
const aleph = this.core.getAlephService();
|
|
1243
1257
|
try {
|
|
1244
1258
|
const file = await this.getFile(filePath);
|
|
1245
|
-
await aleph.updatePost(
|
|
1259
|
+
const updatedPost = await aleph.updatePost(
|
|
1246
1260
|
POST_TYPES.FILE,
|
|
1247
1261
|
file.post_hash,
|
|
1248
|
-
[
|
|
1262
|
+
[aleph.getAddress()],
|
|
1249
1263
|
FileMetaEncryptedSchema,
|
|
1250
1264
|
async (encryptedMeta) => {
|
|
1251
1265
|
const decryptedMeta = await this.decryptFileMeta(encryptedMeta);
|
|
@@ -1255,7 +1269,11 @@ var FileService = class {
|
|
|
1255
1269
|
);
|
|
1256
1270
|
await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => ({
|
|
1257
1271
|
files: aggregate.files.map(
|
|
1258
|
-
(entry) => entry.post_hash === file.post_hash ? {
|
|
1272
|
+
(entry) => entry.post_hash === file.post_hash ? {
|
|
1273
|
+
...entry,
|
|
1274
|
+
post_hash: updatedPost.item_hash,
|
|
1275
|
+
shared_with: entry.shared_with.filter((pk) => pk !== contactPublicKey)
|
|
1276
|
+
} : entry
|
|
1259
1277
|
)
|
|
1260
1278
|
}));
|
|
1261
1279
|
} catch (error) {
|