bedrock-ts-sdk 0.0.3 → 0.0.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.
- package/dist/index.d.mts +10 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.js +116 -250
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +116 -250
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -1
package/dist/index.mjs
CHANGED
|
@@ -116,24 +116,27 @@ var FileMetaEncryptedSchema = z.object({
|
|
|
116
116
|
// Encrypted filename
|
|
117
117
|
path: z.string(),
|
|
118
118
|
// Encrypted path
|
|
119
|
-
key:
|
|
120
|
-
// Encrypted AES key
|
|
121
|
-
iv:
|
|
122
|
-
// Encrypted IV
|
|
123
|
-
store_hash:
|
|
124
|
-
// Aleph STORE hash
|
|
119
|
+
key: z.string(),
|
|
120
|
+
// Encrypted AES key (ECIES encrypted)
|
|
121
|
+
iv: z.string(),
|
|
122
|
+
// Encrypted IV (ECIES encrypted)
|
|
123
|
+
store_hash: z.string(),
|
|
124
|
+
// Encrypted Aleph STORE hash
|
|
125
125
|
size: z.string(),
|
|
126
126
|
// Encrypted size
|
|
127
127
|
created_at: z.string(),
|
|
128
128
|
// Encrypted datetime
|
|
129
129
|
deleted_at: z.string().nullable(),
|
|
130
130
|
// Encrypted datetime or null
|
|
131
|
-
shared_keys: z.record(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
131
|
+
shared_keys: z.record(
|
|
132
|
+
z.string(),
|
|
133
|
+
z.object({
|
|
134
|
+
key: z.string(),
|
|
135
|
+
// Encrypted key for recipient
|
|
136
|
+
iv: z.string()
|
|
137
|
+
// Encrypted IV for recipient
|
|
138
|
+
})
|
|
139
|
+
).default({})
|
|
137
140
|
});
|
|
138
141
|
var FileMetaSchema = z.object({
|
|
139
142
|
name: z.string(),
|
|
@@ -144,10 +147,13 @@ var FileMetaSchema = z.object({
|
|
|
144
147
|
size: z.number(),
|
|
145
148
|
created_at: DatetimeSchema,
|
|
146
149
|
deleted_at: DatetimeSchema.nullable(),
|
|
147
|
-
shared_keys: z.record(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
150
|
+
shared_keys: z.record(
|
|
151
|
+
z.string(),
|
|
152
|
+
z.object({
|
|
153
|
+
key: HexString64Schema,
|
|
154
|
+
iv: HexString32Schema
|
|
155
|
+
})
|
|
156
|
+
).default({})
|
|
151
157
|
});
|
|
152
158
|
var PublicFileMetaSchema = z.object({
|
|
153
159
|
name: z.string(),
|
|
@@ -192,13 +198,15 @@ var FileEntriesAggregateSchema = z.object({
|
|
|
192
198
|
files: z.array(FileEntrySchema).default([])
|
|
193
199
|
});
|
|
194
200
|
var SecurityAggregateSchema = z.object({
|
|
195
|
-
authorizations: z.array(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
201
|
+
authorizations: z.array(
|
|
202
|
+
z.object({
|
|
203
|
+
address: AddressSchema,
|
|
204
|
+
chain: z.string(),
|
|
205
|
+
channels: z.array(z.string()).optional(),
|
|
206
|
+
post_types: z.array(z.string()).optional(),
|
|
207
|
+
aggregate_keys: z.array(z.string()).optional()
|
|
208
|
+
})
|
|
209
|
+
)
|
|
202
210
|
});
|
|
203
211
|
|
|
204
212
|
// src/client/aleph-service.ts
|
|
@@ -811,68 +819,28 @@ var EncryptionService = class {
|
|
|
811
819
|
// ============================================================================
|
|
812
820
|
static async encryptBrowser(data, key, iv) {
|
|
813
821
|
const crypto = CryptoUtils.getCrypto();
|
|
814
|
-
const cryptoKey = await crypto.subtle.importKey(
|
|
815
|
-
"raw",
|
|
816
|
-
key,
|
|
817
|
-
{ name: "AES-CBC" },
|
|
818
|
-
false,
|
|
819
|
-
["encrypt"]
|
|
820
|
-
);
|
|
822
|
+
const cryptoKey = await crypto.subtle.importKey("raw", key, { name: "AES-CBC" }, false, ["encrypt"]);
|
|
821
823
|
const dataBuffer = Buffer.from(data, "utf-8");
|
|
822
|
-
const encrypted = await crypto.subtle.encrypt(
|
|
823
|
-
{ name: "AES-CBC", iv },
|
|
824
|
-
cryptoKey,
|
|
825
|
-
dataBuffer
|
|
826
|
-
);
|
|
824
|
+
const encrypted = await crypto.subtle.encrypt({ name: "AES-CBC", iv }, cryptoKey, dataBuffer);
|
|
827
825
|
return CryptoUtils.bufferToHex(Buffer.from(encrypted));
|
|
828
826
|
}
|
|
829
827
|
static async decryptBrowser(encryptedData, key, iv) {
|
|
830
828
|
const crypto = CryptoUtils.getCrypto();
|
|
831
|
-
const cryptoKey = await crypto.subtle.importKey(
|
|
832
|
-
"raw",
|
|
833
|
-
key,
|
|
834
|
-
{ name: "AES-CBC" },
|
|
835
|
-
false,
|
|
836
|
-
["decrypt"]
|
|
837
|
-
);
|
|
829
|
+
const cryptoKey = await crypto.subtle.importKey("raw", key, { name: "AES-CBC" }, false, ["decrypt"]);
|
|
838
830
|
const encryptedBuffer = CryptoUtils.hexToBuffer(encryptedData);
|
|
839
|
-
const decrypted = await crypto.subtle.decrypt(
|
|
840
|
-
{ name: "AES-CBC", iv },
|
|
841
|
-
cryptoKey,
|
|
842
|
-
encryptedBuffer
|
|
843
|
-
);
|
|
831
|
+
const decrypted = await crypto.subtle.decrypt({ name: "AES-CBC", iv }, cryptoKey, encryptedBuffer);
|
|
844
832
|
return Buffer.from(decrypted).toString("utf-8");
|
|
845
833
|
}
|
|
846
834
|
static async encryptFileBrowser(buffer, key, iv) {
|
|
847
835
|
const crypto = CryptoUtils.getCrypto();
|
|
848
|
-
const cryptoKey = await crypto.subtle.importKey(
|
|
849
|
-
|
|
850
|
-
key,
|
|
851
|
-
{ name: "AES-CBC" },
|
|
852
|
-
false,
|
|
853
|
-
["encrypt"]
|
|
854
|
-
);
|
|
855
|
-
const encrypted = await crypto.subtle.encrypt(
|
|
856
|
-
{ name: "AES-CBC", iv },
|
|
857
|
-
cryptoKey,
|
|
858
|
-
buffer
|
|
859
|
-
);
|
|
836
|
+
const cryptoKey = await crypto.subtle.importKey("raw", key, { name: "AES-CBC" }, false, ["encrypt"]);
|
|
837
|
+
const encrypted = await crypto.subtle.encrypt({ name: "AES-CBC", iv }, cryptoKey, buffer);
|
|
860
838
|
return Buffer.from(encrypted);
|
|
861
839
|
}
|
|
862
840
|
static async decryptFileBrowser(buffer, key, iv) {
|
|
863
841
|
const crypto = CryptoUtils.getCrypto();
|
|
864
|
-
const cryptoKey = await crypto.subtle.importKey(
|
|
865
|
-
|
|
866
|
-
key,
|
|
867
|
-
{ name: "AES-CBC" },
|
|
868
|
-
false,
|
|
869
|
-
["decrypt"]
|
|
870
|
-
);
|
|
871
|
-
const decrypted = await crypto.subtle.decrypt(
|
|
872
|
-
{ name: "AES-CBC", iv },
|
|
873
|
-
cryptoKey,
|
|
874
|
-
buffer
|
|
875
|
-
);
|
|
842
|
+
const cryptoKey = await crypto.subtle.importKey("raw", key, { name: "AES-CBC" }, false, ["decrypt"]);
|
|
843
|
+
const decrypted = await crypto.subtle.decrypt({ name: "AES-CBC", iv }, cryptoKey, buffer);
|
|
876
844
|
return Buffer.from(decrypted);
|
|
877
845
|
}
|
|
878
846
|
};
|
|
@@ -888,10 +856,7 @@ var FileService = class {
|
|
|
888
856
|
async setup() {
|
|
889
857
|
const aleph = this.core.getAlephService();
|
|
890
858
|
try {
|
|
891
|
-
await aleph.fetchAggregate(
|
|
892
|
-
AGGREGATE_KEYS.FILE_ENTRIES,
|
|
893
|
-
FileEntriesAggregateSchema
|
|
894
|
-
);
|
|
859
|
+
await aleph.fetchAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema);
|
|
895
860
|
} catch {
|
|
896
861
|
await aleph.createAggregate(AGGREGATE_KEYS.FILE_ENTRIES, { files: [] });
|
|
897
862
|
}
|
|
@@ -972,10 +937,7 @@ var FileService = class {
|
|
|
972
937
|
const aleph = this.core.getAlephService();
|
|
973
938
|
const privateKey = this.core.getSubAccountPrivateKey();
|
|
974
939
|
try {
|
|
975
|
-
const aggregate = await aleph.fetchAggregate(
|
|
976
|
-
AGGREGATE_KEYS.FILE_ENTRIES,
|
|
977
|
-
FileEntriesAggregateSchema
|
|
978
|
-
);
|
|
940
|
+
const aggregate = await aleph.fetchAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema);
|
|
979
941
|
return aggregate.files.map(({ post_hash, path, shared_with }) => ({
|
|
980
942
|
post_hash,
|
|
981
943
|
path: EncryptionService.decryptEcies(path, privateKey),
|
|
@@ -1102,15 +1064,9 @@ var FileService = class {
|
|
|
1102
1064
|
const aleph = this.core.getAlephService();
|
|
1103
1065
|
try {
|
|
1104
1066
|
const files = await Promise.all(filePaths.map((path) => this.getFile(path)));
|
|
1105
|
-
await aleph.updateAggregate(
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
async (aggregate) => ({
|
|
1109
|
-
files: aggregate.files.filter(
|
|
1110
|
-
(entry) => !files.some((f) => f.post_hash === entry.post_hash)
|
|
1111
|
-
)
|
|
1112
|
-
})
|
|
1113
|
-
);
|
|
1067
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => ({
|
|
1068
|
+
files: aggregate.files.filter((entry) => !files.some((f) => f.post_hash === entry.post_hash))
|
|
1069
|
+
}));
|
|
1114
1070
|
const hashesToForget = files.flatMap((f) => [f.store_hash, f.post_hash]);
|
|
1115
1071
|
await aleph.deleteFiles(hashesToForget);
|
|
1116
1072
|
} catch (error) {
|
|
@@ -1140,15 +1096,11 @@ var FileService = class {
|
|
|
1140
1096
|
}
|
|
1141
1097
|
);
|
|
1142
1098
|
const newEncryptedPath = EncryptionService.encryptEcies(newPath, publicKey);
|
|
1143
|
-
await aleph.updateAggregate(
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
(entry) => entry.post_hash === file.post_hash ? { ...entry, path: newEncryptedPath } : entry
|
|
1149
|
-
)
|
|
1150
|
-
})
|
|
1151
|
-
);
|
|
1099
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => ({
|
|
1100
|
+
files: aggregate.files.map(
|
|
1101
|
+
(entry) => entry.post_hash === file.post_hash ? { ...entry, path: newEncryptedPath } : entry
|
|
1102
|
+
)
|
|
1103
|
+
}));
|
|
1152
1104
|
}
|
|
1153
1105
|
} catch (error) {
|
|
1154
1106
|
throw new FileError(`Failed to move files: ${error.message}`);
|
|
@@ -1163,11 +1115,13 @@ var FileService = class {
|
|
|
1163
1115
|
try {
|
|
1164
1116
|
const sourceFile = await this.getFile(sourcePath);
|
|
1165
1117
|
const content = await this.downloadFile(sourceFile);
|
|
1166
|
-
const [newFile] = await this.uploadFiles([
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1118
|
+
const [newFile] = await this.uploadFiles([
|
|
1119
|
+
{
|
|
1120
|
+
name: newPath.split("/").pop() || newPath,
|
|
1121
|
+
path: newPath,
|
|
1122
|
+
content
|
|
1123
|
+
}
|
|
1124
|
+
]);
|
|
1171
1125
|
return newFile;
|
|
1172
1126
|
} catch (error) {
|
|
1173
1127
|
throw new FileError(`Failed to duplicate file: ${error.message}`);
|
|
@@ -1198,15 +1152,11 @@ var FileService = class {
|
|
|
1198
1152
|
return await this.encryptFileMeta(decryptedMeta);
|
|
1199
1153
|
}
|
|
1200
1154
|
);
|
|
1201
|
-
await aleph.updateAggregate(
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
(entry) => entry.post_hash === file.post_hash ? { ...entry, shared_with: [.../* @__PURE__ */ new Set([...entry.shared_with, contactPublicKey])] } : entry
|
|
1207
|
-
)
|
|
1208
|
-
})
|
|
1209
|
-
);
|
|
1155
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => ({
|
|
1156
|
+
files: aggregate.files.map(
|
|
1157
|
+
(entry) => entry.post_hash === file.post_hash ? { ...entry, shared_with: [.../* @__PURE__ */ new Set([...entry.shared_with, contactPublicKey])] } : entry
|
|
1158
|
+
)
|
|
1159
|
+
}));
|
|
1210
1160
|
} catch (error) {
|
|
1211
1161
|
throw new FileError(`Failed to share file: ${error.message}`);
|
|
1212
1162
|
}
|
|
@@ -1231,15 +1181,11 @@ var FileService = class {
|
|
|
1231
1181
|
return await this.encryptFileMeta(decryptedMeta);
|
|
1232
1182
|
}
|
|
1233
1183
|
);
|
|
1234
|
-
await aleph.updateAggregate(
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
(entry) => entry.post_hash === file.post_hash ? { ...entry, shared_with: entry.shared_with.filter((pk) => pk !== contactPublicKey) } : entry
|
|
1240
|
-
)
|
|
1241
|
-
})
|
|
1242
|
-
);
|
|
1184
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => ({
|
|
1185
|
+
files: aggregate.files.map(
|
|
1186
|
+
(entry) => entry.post_hash === file.post_hash ? { ...entry, shared_with: entry.shared_with.filter((pk) => pk !== contactPublicKey) } : entry
|
|
1187
|
+
)
|
|
1188
|
+
}));
|
|
1243
1189
|
} catch (error) {
|
|
1244
1190
|
throw new FileError(`Failed to unshare file: ${error.message}`);
|
|
1245
1191
|
}
|
|
@@ -1305,40 +1251,32 @@ var FileService = class {
|
|
|
1305
1251
|
async saveFileEntries(files) {
|
|
1306
1252
|
const aleph = this.core.getAlephService();
|
|
1307
1253
|
const publicKey = this.core.getPublicKey();
|
|
1308
|
-
await aleph.updateAggregate(
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
}));
|
|
1317
|
-
return { files: [...aggregate.files, ...newEntries] };
|
|
1318
|
-
}
|
|
1319
|
-
);
|
|
1254
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => {
|
|
1255
|
+
const newEntries = files.map((f) => ({
|
|
1256
|
+
path: EncryptionService.encryptEcies(f.path, publicKey),
|
|
1257
|
+
post_hash: f.post_hash,
|
|
1258
|
+
shared_with: f.shared_with || []
|
|
1259
|
+
}));
|
|
1260
|
+
return { files: [...aggregate.files, ...newEntries] };
|
|
1261
|
+
});
|
|
1320
1262
|
}
|
|
1321
1263
|
async encryptFileMeta(meta) {
|
|
1322
|
-
const key = this.core.getEncryptionKey();
|
|
1323
|
-
const iv = EncryptionService.generateIv();
|
|
1324
1264
|
const publicKey = this.core.getPublicKey();
|
|
1325
1265
|
const fileKey = Buffer.from(meta.key, "hex");
|
|
1326
1266
|
const fileIv = Buffer.from(meta.iv, "hex");
|
|
1327
1267
|
return {
|
|
1328
|
-
name: await EncryptionService.encrypt(meta.name,
|
|
1268
|
+
name: await EncryptionService.encrypt(meta.name, fileKey, fileIv),
|
|
1329
1269
|
path: await EncryptionService.encrypt(meta.path, fileKey, fileIv),
|
|
1330
1270
|
key: EncryptionService.encryptEcies(meta.key, publicKey),
|
|
1331
1271
|
iv: EncryptionService.encryptEcies(meta.iv, publicKey),
|
|
1332
1272
|
store_hash: await EncryptionService.encrypt(meta.store_hash, fileKey, fileIv),
|
|
1333
|
-
size: await EncryptionService.encrypt(meta.size.toString(),
|
|
1334
|
-
created_at: await EncryptionService.encrypt(meta.created_at,
|
|
1273
|
+
size: await EncryptionService.encrypt(meta.size.toString(), fileKey, fileIv),
|
|
1274
|
+
created_at: await EncryptionService.encrypt(meta.created_at, fileKey, fileIv),
|
|
1335
1275
|
deleted_at: await EncryptionService.encrypt(meta.deleted_at ?? "null", fileKey, fileIv),
|
|
1336
1276
|
shared_keys: meta.shared_keys
|
|
1337
1277
|
};
|
|
1338
1278
|
}
|
|
1339
1279
|
async decryptFileMeta(encryptedMeta, privateKey) {
|
|
1340
|
-
const key = this.core.getEncryptionKey();
|
|
1341
|
-
const iv = EncryptionService.generateIv();
|
|
1342
1280
|
const privKey = privateKey || this.core.getSubAccountPrivateKey();
|
|
1343
1281
|
if (!privKey) {
|
|
1344
1282
|
throw new EncryptionError("Private key not available");
|
|
@@ -1349,13 +1287,13 @@ var FileService = class {
|
|
|
1349
1287
|
const fileIv = Buffer.from(decryptedIv, "hex");
|
|
1350
1288
|
const decryptedDeletedAt = await EncryptionService.decrypt(encryptedMeta.deleted_at, fileKey, fileIv);
|
|
1351
1289
|
return {
|
|
1352
|
-
name: await EncryptionService.decrypt(encryptedMeta.name,
|
|
1290
|
+
name: await EncryptionService.decrypt(encryptedMeta.name, fileKey, fileIv),
|
|
1353
1291
|
path: await EncryptionService.decrypt(encryptedMeta.path, fileKey, fileIv),
|
|
1354
1292
|
key: decryptedKey,
|
|
1355
1293
|
iv: decryptedIv,
|
|
1356
1294
|
store_hash: await EncryptionService.decrypt(encryptedMeta.store_hash, fileKey, fileIv),
|
|
1357
|
-
size: parseInt(await EncryptionService.decrypt(encryptedMeta.size,
|
|
1358
|
-
created_at: await EncryptionService.decrypt(encryptedMeta.created_at,
|
|
1295
|
+
size: Number.parseInt(await EncryptionService.decrypt(encryptedMeta.size, fileKey, fileIv)),
|
|
1296
|
+
created_at: await EncryptionService.decrypt(encryptedMeta.created_at, fileKey, fileIv),
|
|
1359
1297
|
deleted_at: decryptedDeletedAt === "null" ? null : decryptedDeletedAt,
|
|
1360
1298
|
shared_keys: encryptedMeta.shared_keys || {}
|
|
1361
1299
|
};
|
|
@@ -1374,10 +1312,7 @@ var ContactService = class {
|
|
|
1374
1312
|
async setup() {
|
|
1375
1313
|
const aleph = this.core.getAlephService();
|
|
1376
1314
|
try {
|
|
1377
|
-
await aleph.fetchAggregate(
|
|
1378
|
-
AGGREGATE_KEYS.CONTACTS,
|
|
1379
|
-
ContactsAggregateSchema
|
|
1380
|
-
);
|
|
1315
|
+
await aleph.fetchAggregate(AGGREGATE_KEYS.CONTACTS, ContactsAggregateSchema);
|
|
1381
1316
|
} catch {
|
|
1382
1317
|
await aleph.createAggregate(AGGREGATE_KEYS.CONTACTS, { contacts: [] });
|
|
1383
1318
|
}
|
|
@@ -1388,10 +1323,7 @@ var ContactService = class {
|
|
|
1388
1323
|
async listContacts() {
|
|
1389
1324
|
const aleph = this.core.getAlephService();
|
|
1390
1325
|
try {
|
|
1391
|
-
const aggregate = await aleph.fetchAggregate(
|
|
1392
|
-
AGGREGATE_KEYS.CONTACTS,
|
|
1393
|
-
ContactsAggregateSchema
|
|
1394
|
-
);
|
|
1326
|
+
const aggregate = await aleph.fetchAggregate(AGGREGATE_KEYS.CONTACTS, ContactsAggregateSchema);
|
|
1395
1327
|
return aggregate.contacts;
|
|
1396
1328
|
} catch (error) {
|
|
1397
1329
|
throw new ContactError(`Failed to fetch contacts: ${error.message}`);
|
|
@@ -1442,13 +1374,9 @@ var ContactService = class {
|
|
|
1442
1374
|
address,
|
|
1443
1375
|
public_key: publicKey
|
|
1444
1376
|
};
|
|
1445
|
-
await aleph.updateAggregate(
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
async (aggregate) => ({
|
|
1449
|
-
contacts: [...aggregate.contacts, newContact]
|
|
1450
|
-
})
|
|
1451
|
-
);
|
|
1377
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.CONTACTS, ContactsAggregateSchema, async (aggregate) => ({
|
|
1378
|
+
contacts: [...aggregate.contacts, newContact]
|
|
1379
|
+
}));
|
|
1452
1380
|
return newContact;
|
|
1453
1381
|
} catch (error) {
|
|
1454
1382
|
if (error instanceof ContactError) {
|
|
@@ -1465,13 +1393,9 @@ var ContactService = class {
|
|
|
1465
1393
|
const aleph = this.core.getAlephService();
|
|
1466
1394
|
try {
|
|
1467
1395
|
await this.getContact(publicKey);
|
|
1468
|
-
await aleph.updateAggregate(
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
async (aggregate) => ({
|
|
1472
|
-
contacts: aggregate.contacts.filter((c) => c.public_key !== publicKey)
|
|
1473
|
-
})
|
|
1474
|
-
);
|
|
1396
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.CONTACTS, ContactsAggregateSchema, async (aggregate) => ({
|
|
1397
|
+
contacts: aggregate.contacts.filter((c) => c.public_key !== publicKey)
|
|
1398
|
+
}));
|
|
1475
1399
|
} catch (error) {
|
|
1476
1400
|
if (error instanceof ContactError) {
|
|
1477
1401
|
throw error;
|
|
@@ -1492,15 +1416,9 @@ var ContactService = class {
|
|
|
1492
1416
|
...existingContact,
|
|
1493
1417
|
name: newName
|
|
1494
1418
|
};
|
|
1495
|
-
await aleph.updateAggregate(
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
async (aggregate) => ({
|
|
1499
|
-
contacts: aggregate.contacts.map(
|
|
1500
|
-
(c) => c.public_key === publicKey ? updatedContact : c
|
|
1501
|
-
)
|
|
1502
|
-
})
|
|
1503
|
-
);
|
|
1419
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.CONTACTS, ContactsAggregateSchema, async (aggregate) => ({
|
|
1420
|
+
contacts: aggregate.contacts.map((c) => c.public_key === publicKey ? updatedContact : c)
|
|
1421
|
+
}));
|
|
1504
1422
|
return updatedContact;
|
|
1505
1423
|
} catch (error) {
|
|
1506
1424
|
if (error instanceof ContactError) {
|
|
@@ -1517,9 +1435,7 @@ var ContactService = class {
|
|
|
1517
1435
|
try {
|
|
1518
1436
|
await this.getContact(publicKey);
|
|
1519
1437
|
const entries = await this.fileService.fetchFileEntries();
|
|
1520
|
-
const sharedEntries = entries.filter(
|
|
1521
|
-
(entry) => entry.shared_with.includes(publicKey)
|
|
1522
|
-
);
|
|
1438
|
+
const sharedEntries = entries.filter((entry) => entry.shared_with.includes(publicKey));
|
|
1523
1439
|
const files = await this.fileService.fetchFilesMetaFromEntries(sharedEntries);
|
|
1524
1440
|
return files;
|
|
1525
1441
|
} catch (error) {
|
|
@@ -1542,9 +1458,7 @@ var ContactService = class {
|
|
|
1542
1458
|
contact.address
|
|
1543
1459
|
// Important: contact's address, not current user's
|
|
1544
1460
|
);
|
|
1545
|
-
const sharedEntries = contactEntries.files.filter(
|
|
1546
|
-
(entry) => entry.shared_with.includes(currentUserPublicKey)
|
|
1547
|
-
);
|
|
1461
|
+
const sharedEntries = contactEntries.files.filter((entry) => entry.shared_with.includes(currentUserPublicKey));
|
|
1548
1462
|
const files = await this.fileService.fetchFilesMetaFromEntries(
|
|
1549
1463
|
sharedEntries,
|
|
1550
1464
|
contact.address
|
|
@@ -1594,10 +1508,7 @@ var KnowledgeBaseService = class {
|
|
|
1594
1508
|
async setup() {
|
|
1595
1509
|
const aleph = this.core.getAlephService();
|
|
1596
1510
|
try {
|
|
1597
|
-
await aleph.fetchAggregate(
|
|
1598
|
-
AGGREGATE_KEYS.KNOWLEDGE_BASES,
|
|
1599
|
-
KnowledgeBasesAggregateSchema
|
|
1600
|
-
);
|
|
1511
|
+
await aleph.fetchAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema);
|
|
1601
1512
|
} catch {
|
|
1602
1513
|
await aleph.createAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, { knowledge_bases: [] });
|
|
1603
1514
|
}
|
|
@@ -1608,10 +1519,7 @@ var KnowledgeBaseService = class {
|
|
|
1608
1519
|
async listKnowledgeBases() {
|
|
1609
1520
|
const aleph = this.core.getAlephService();
|
|
1610
1521
|
try {
|
|
1611
|
-
const aggregate = await aleph.fetchAggregate(
|
|
1612
|
-
AGGREGATE_KEYS.KNOWLEDGE_BASES,
|
|
1613
|
-
KnowledgeBasesAggregateSchema
|
|
1614
|
-
);
|
|
1522
|
+
const aggregate = await aleph.fetchAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema);
|
|
1615
1523
|
return aggregate.knowledge_bases;
|
|
1616
1524
|
} catch (error) {
|
|
1617
1525
|
throw new KnowledgeBaseError(`Failed to fetch knowledge bases: ${error.message}`);
|
|
@@ -1649,13 +1557,9 @@ var KnowledgeBaseService = class {
|
|
|
1649
1557
|
created_at: now,
|
|
1650
1558
|
updated_at: now
|
|
1651
1559
|
};
|
|
1652
|
-
await aleph.updateAggregate(
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
async (aggregate) => ({
|
|
1656
|
-
knowledge_bases: [...aggregate.knowledge_bases, newKb]
|
|
1657
|
-
})
|
|
1658
|
-
);
|
|
1560
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema, async (aggregate) => ({
|
|
1561
|
+
knowledge_bases: [...aggregate.knowledge_bases, newKb]
|
|
1562
|
+
}));
|
|
1659
1563
|
return newKb;
|
|
1660
1564
|
} catch (error) {
|
|
1661
1565
|
if (error instanceof KnowledgeBaseError) {
|
|
@@ -1672,13 +1576,9 @@ var KnowledgeBaseService = class {
|
|
|
1672
1576
|
const aleph = this.core.getAlephService();
|
|
1673
1577
|
try {
|
|
1674
1578
|
await this.getKnowledgeBase(name);
|
|
1675
|
-
await aleph.updateAggregate(
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
async (aggregate) => ({
|
|
1679
|
-
knowledge_bases: aggregate.knowledge_bases.filter((k) => k.name !== name)
|
|
1680
|
-
})
|
|
1681
|
-
);
|
|
1579
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema, async (aggregate) => ({
|
|
1580
|
+
knowledge_bases: aggregate.knowledge_bases.filter((k) => k.name !== name)
|
|
1581
|
+
}));
|
|
1682
1582
|
} catch (error) {
|
|
1683
1583
|
if (error instanceof KnowledgeBaseError) {
|
|
1684
1584
|
throw error;
|
|
@@ -1704,15 +1604,9 @@ var KnowledgeBaseService = class {
|
|
|
1704
1604
|
name: newName,
|
|
1705
1605
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1706
1606
|
};
|
|
1707
|
-
await aleph.updateAggregate(
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
async (aggregate) => ({
|
|
1711
|
-
knowledge_bases: aggregate.knowledge_bases.map(
|
|
1712
|
-
(k) => k.name === oldName ? updatedKb : k
|
|
1713
|
-
)
|
|
1714
|
-
})
|
|
1715
|
-
);
|
|
1607
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema, async (aggregate) => ({
|
|
1608
|
+
knowledge_bases: aggregate.knowledge_bases.map((k) => k.name === oldName ? updatedKb : k)
|
|
1609
|
+
}));
|
|
1716
1610
|
return updatedKb;
|
|
1717
1611
|
} catch (error) {
|
|
1718
1612
|
if (error instanceof KnowledgeBaseError) {
|
|
@@ -1735,15 +1629,9 @@ var KnowledgeBaseService = class {
|
|
|
1735
1629
|
file_paths: filePaths,
|
|
1736
1630
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1737
1631
|
};
|
|
1738
|
-
await aleph.updateAggregate(
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
async (aggregate) => ({
|
|
1742
|
-
knowledge_bases: aggregate.knowledge_bases.map(
|
|
1743
|
-
(k) => k.name === name ? updatedKb : k
|
|
1744
|
-
)
|
|
1745
|
-
})
|
|
1746
|
-
);
|
|
1632
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema, async (aggregate) => ({
|
|
1633
|
+
knowledge_bases: aggregate.knowledge_bases.map((k) => k.name === name ? updatedKb : k)
|
|
1634
|
+
}));
|
|
1747
1635
|
return updatedKb;
|
|
1748
1636
|
} catch (error) {
|
|
1749
1637
|
if (error instanceof KnowledgeBaseError) {
|
|
@@ -1767,15 +1655,9 @@ var KnowledgeBaseService = class {
|
|
|
1767
1655
|
file_paths: updatedFilePaths,
|
|
1768
1656
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1769
1657
|
};
|
|
1770
|
-
await aleph.updateAggregate(
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
async (aggregate) => ({
|
|
1774
|
-
knowledge_bases: aggregate.knowledge_bases.map(
|
|
1775
|
-
(k) => k.name === name ? updatedKb : k
|
|
1776
|
-
)
|
|
1777
|
-
})
|
|
1778
|
-
);
|
|
1658
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema, async (aggregate) => ({
|
|
1659
|
+
knowledge_bases: aggregate.knowledge_bases.map((k) => k.name === name ? updatedKb : k)
|
|
1660
|
+
}));
|
|
1779
1661
|
return updatedKb;
|
|
1780
1662
|
} catch (error) {
|
|
1781
1663
|
if (error instanceof KnowledgeBaseError) {
|
|
@@ -1793,23 +1675,15 @@ var KnowledgeBaseService = class {
|
|
|
1793
1675
|
const aleph = this.core.getAlephService();
|
|
1794
1676
|
try {
|
|
1795
1677
|
const existingKb = await this.getKnowledgeBase(name);
|
|
1796
|
-
const updatedFilePaths = existingKb.file_paths.filter(
|
|
1797
|
-
(path) => !filePaths.includes(path)
|
|
1798
|
-
);
|
|
1678
|
+
const updatedFilePaths = existingKb.file_paths.filter((path) => !filePaths.includes(path));
|
|
1799
1679
|
const updatedKb = {
|
|
1800
1680
|
...existingKb,
|
|
1801
1681
|
file_paths: updatedFilePaths,
|
|
1802
1682
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1803
1683
|
};
|
|
1804
|
-
await aleph.updateAggregate(
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
async (aggregate) => ({
|
|
1808
|
-
knowledge_bases: aggregate.knowledge_bases.map(
|
|
1809
|
-
(k) => k.name === name ? updatedKb : k
|
|
1810
|
-
)
|
|
1811
|
-
})
|
|
1812
|
-
);
|
|
1684
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema, async (aggregate) => ({
|
|
1685
|
+
knowledge_bases: aggregate.knowledge_bases.map((k) => k.name === name ? updatedKb : k)
|
|
1686
|
+
}));
|
|
1813
1687
|
return updatedKb;
|
|
1814
1688
|
} catch (error) {
|
|
1815
1689
|
if (error instanceof KnowledgeBaseError) {
|
|
@@ -1948,11 +1822,7 @@ var BedrockClient = class _BedrockClient {
|
|
|
1948
1822
|
* WARNING: This will delete all user data from Aleph
|
|
1949
1823
|
*/
|
|
1950
1824
|
async resetAllData() {
|
|
1951
|
-
await Promise.all([
|
|
1952
|
-
this.resetFiles(),
|
|
1953
|
-
this.resetContacts(),
|
|
1954
|
-
this.resetKnowledgeBases()
|
|
1955
|
-
]);
|
|
1825
|
+
await Promise.all([this.resetFiles(), this.resetContacts(), this.resetKnowledgeBases()]);
|
|
1956
1826
|
}
|
|
1957
1827
|
/**
|
|
1958
1828
|
* Reset all files
|
|
@@ -1985,11 +1855,7 @@ var BedrockClient = class _BedrockClient {
|
|
|
1985
1855
|
* Setup all services (create aggregates if they don't exist)
|
|
1986
1856
|
*/
|
|
1987
1857
|
async setup() {
|
|
1988
|
-
await Promise.all([
|
|
1989
|
-
this.files.setup(),
|
|
1990
|
-
this.contacts.setup(),
|
|
1991
|
-
this.knowledgeBases.setup()
|
|
1992
|
-
]);
|
|
1858
|
+
await Promise.all([this.files.setup(), this.contacts.setup(), this.knowledgeBases.setup()]);
|
|
1993
1859
|
}
|
|
1994
1860
|
};
|
|
1995
1861
|
|