bedrock-ts-sdk 0.0.7 → 0.0.9

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 CHANGED
@@ -674,6 +674,7 @@ declare class FileService {
674
674
  * @param files - Array of files to upload
675
675
  * @param directoryPath - Optional directory path prefix
676
676
  * @returns Array of uploaded file info
677
+ * @throws FileConflictError if any file path conflicts with non-trashed file
677
678
  */
678
679
  uploadFiles(files: FileInput[], directoryPath?: string): Promise<FileFullInfo[]>;
679
680
  editFileContent(fileInfo: FileFullInfo, newContent: Buffer): Promise<FileFullInfo>;
@@ -713,6 +714,7 @@ declare class FileService {
713
714
  /**
714
715
  * Restore soft-deleted files
715
716
  * @param filePaths - Paths of files to restore
717
+ * @throws FileConflictError if any file path conflicts with non-trashed file
716
718
  */
717
719
  restoreFiles(filePaths: string[]): Promise<void>;
718
720
  /**
@@ -723,6 +725,7 @@ declare class FileService {
723
725
  /**
724
726
  * Move/rename files
725
727
  * @param moves - Array of {oldPath, newPath} objects
728
+ * @throws FileConflictError if any newPath conflicts with non-trashed file
726
729
  */
727
730
  moveFiles(moves: Array<{
728
731
  oldPath: string;
@@ -765,6 +768,12 @@ declare class FileService {
765
768
  * @returns File content as ArrayBuffer
766
769
  */
767
770
  static downloadPublicFile(storeHash: string): Promise<ArrayBuffer>;
771
+ /**
772
+ * Check for path conflicts with non-trashed files
773
+ * @param paths - Paths to check
774
+ * @throws FileConflictError on first conflict
775
+ */
776
+ private checkPathConflicts;
768
777
  private saveFileEntries;
769
778
  private encryptFileMeta;
770
779
  private decryptFileMeta;
package/dist/index.d.ts CHANGED
@@ -674,6 +674,7 @@ declare class FileService {
674
674
  * @param files - Array of files to upload
675
675
  * @param directoryPath - Optional directory path prefix
676
676
  * @returns Array of uploaded file info
677
+ * @throws FileConflictError if any file path conflicts with non-trashed file
677
678
  */
678
679
  uploadFiles(files: FileInput[], directoryPath?: string): Promise<FileFullInfo[]>;
679
680
  editFileContent(fileInfo: FileFullInfo, newContent: Buffer): Promise<FileFullInfo>;
@@ -713,6 +714,7 @@ declare class FileService {
713
714
  /**
714
715
  * Restore soft-deleted files
715
716
  * @param filePaths - Paths of files to restore
717
+ * @throws FileConflictError if any file path conflicts with non-trashed file
716
718
  */
717
719
  restoreFiles(filePaths: string[]): Promise<void>;
718
720
  /**
@@ -723,6 +725,7 @@ declare class FileService {
723
725
  /**
724
726
  * Move/rename files
725
727
  * @param moves - Array of {oldPath, newPath} objects
728
+ * @throws FileConflictError if any newPath conflicts with non-trashed file
726
729
  */
727
730
  moveFiles(moves: Array<{
728
731
  oldPath: string;
@@ -765,6 +768,12 @@ declare class FileService {
765
768
  * @returns File content as ArrayBuffer
766
769
  */
767
770
  static downloadPublicFile(storeHash: string): Promise<ArrayBuffer>;
771
+ /**
772
+ * Check for path conflicts with non-trashed files
773
+ * @param paths - Paths to check
774
+ * @throws FileConflictError on first conflict
775
+ */
776
+ private checkPathConflicts;
768
777
  private saveFileEntries;
769
778
  private encryptFileMeta;
770
779
  private decryptFileMeta;
package/dist/index.js CHANGED
@@ -121,6 +121,14 @@ var FileNotFoundError = class _FileNotFoundError extends FileError {
121
121
  Object.setPrototypeOf(this, _FileNotFoundError.prototype);
122
122
  }
123
123
  };
124
+ var FileConflictError = class _FileConflictError extends FileError {
125
+ constructor(path) {
126
+ super(`File path conflict: ${path} already exists`);
127
+ this.name = "FileConflictError";
128
+ this.code = "FILE_CONFLICT";
129
+ Object.setPrototypeOf(this, _FileConflictError.prototype);
130
+ }
131
+ };
124
132
  var ContactError = class _ContactError extends BedrockError {
125
133
  constructor(message) {
126
134
  super(message, "CONTACT_ERROR");
@@ -670,6 +678,7 @@ var BedrockCore = class _BedrockCore {
670
678
 
671
679
  // src/services/file-service.ts
672
680
  var import_client3 = require("@aleph-sdk/client");
681
+ var import_zod3 = require("zod");
673
682
 
674
683
  // src/crypto/encryption.ts
675
684
  var import_eciesjs2 = require("eciesjs");
@@ -944,21 +953,16 @@ var FileService = class {
944
953
  * @param files - Array of files to upload
945
954
  * @param directoryPath - Optional directory path prefix
946
955
  * @returns Array of uploaded file info
956
+ * @throws FileConflictError if any file path conflicts with non-trashed file
947
957
  */
948
958
  async uploadFiles(files, directoryPath = "") {
949
959
  const aleph = this.core.getAlephService();
950
960
  const publicKey = this.core.getPublicKey();
951
961
  const uploadedFiles = [];
952
- const existingFiles = await this.listFiles();
953
- const filesToUpload = files.filter((file) => {
954
- const filterIn = !existingFiles.some(
955
- (existingFile) => !existingFile.deleted_at && existingFile.path === (directoryPath ? `${directoryPath}${file.path}` : file.path)
956
- );
957
- console.log(`Keeping ${file} in ? ${filterIn ? "yes" : "no"}`);
958
- return filterIn;
959
- });
962
+ const fullPaths = files.map((f) => directoryPath ? `${directoryPath}${f.path}` : f.path);
963
+ await this.checkPathConflicts(fullPaths);
960
964
  try {
961
- for (const file of filesToUpload) {
965
+ for (const file of files) {
962
966
  const key = EncryptionService.generateKey();
963
967
  const iv = EncryptionService.generateIv();
964
968
  let fileBuffer;
@@ -1158,9 +1162,11 @@ var FileService = class {
1158
1162
  /**
1159
1163
  * Restore soft-deleted files
1160
1164
  * @param filePaths - Paths of files to restore
1165
+ * @throws FileConflictError if any file path conflicts with non-trashed file
1161
1166
  */
1162
1167
  async restoreFiles(filePaths) {
1163
1168
  const aleph = this.core.getAlephService();
1169
+ await this.checkPathConflicts(filePaths);
1164
1170
  try {
1165
1171
  for (const path of filePaths) {
1166
1172
  const file = await this.getFile(path);
@@ -1205,10 +1211,18 @@ var FileService = class {
1205
1211
  /**
1206
1212
  * Move/rename files
1207
1213
  * @param moves - Array of {oldPath, newPath} objects
1214
+ * @throws FileConflictError if any newPath conflicts with non-trashed file
1208
1215
  */
1209
1216
  async moveFiles(moves) {
1210
1217
  const aleph = this.core.getAlephService();
1211
1218
  const publicKey = this.core.getPublicKey();
1219
+ const existingFiles = await this.listFiles(false);
1220
+ const existingPaths = new Set(existingFiles.map((f) => f.path));
1221
+ for (const { oldPath, newPath } of moves) {
1222
+ if (existingPaths.has(newPath) && newPath !== oldPath) {
1223
+ throw new FileConflictError(newPath);
1224
+ }
1225
+ }
1212
1226
  try {
1213
1227
  for (const { oldPath, newPath } of moves) {
1214
1228
  const file = await this.getFile(oldPath);
@@ -1359,12 +1373,13 @@ var FileService = class {
1359
1373
  static async fetchPublicFileMeta(postHash) {
1360
1374
  try {
1361
1375
  const client = new import_client3.AlephHttpClient("https://poc-aleph-ccn.reza.dev");
1362
- const post = await client.getPost({
1363
- channels: [ALEPH_GENERAL_CHANNEL],
1364
- types: [POST_TYPES.PUBLIC_FILE],
1365
- hashes: [postHash]
1366
- });
1367
- return PublicFileMetaSchema.parse(post.content);
1376
+ const message = await client.getMessage(postHash);
1377
+ try {
1378
+ return PublicFileMetaSchema.parse(message.content);
1379
+ } catch {
1380
+ const postContent = message.content;
1381
+ return PublicFileMetaSchema.parse(postContent.content);
1382
+ }
1368
1383
  } catch {
1369
1384
  return null;
1370
1385
  }
@@ -1377,7 +1392,16 @@ var FileService = class {
1377
1392
  static async downloadPublicFile(storeHash) {
1378
1393
  try {
1379
1394
  const client = new import_client3.AlephHttpClient("https://poc-aleph-ccn.reza.dev");
1380
- return await client.downloadFile(storeHash);
1395
+ const storeMessage = await client.getMessage(storeHash);
1396
+ const ContentSchema = import_zod3.z.object({
1397
+ address: import_zod3.z.string(),
1398
+ item_type: import_zod3.z.string(),
1399
+ item_hash: import_zod3.z.string(),
1400
+ time: import_zod3.z.number()
1401
+ });
1402
+ const { success, data } = ContentSchema.safeParse(storeMessage.content);
1403
+ if (!success) throw new Error("Invalid STORE message structure");
1404
+ return await client.downloadFile(data.item_hash);
1381
1405
  } catch (error) {
1382
1406
  throw new FileError(`Failed to download public file: ${error.message}`);
1383
1407
  }
@@ -1385,6 +1409,20 @@ var FileService = class {
1385
1409
  // ============================================================================
1386
1410
  // Private helper methods
1387
1411
  // ============================================================================
1412
+ /**
1413
+ * Check for path conflicts with non-trashed files
1414
+ * @param paths - Paths to check
1415
+ * @throws FileConflictError on first conflict
1416
+ */
1417
+ async checkPathConflicts(paths) {
1418
+ const existingFiles = await this.listFiles(false);
1419
+ const existingPaths = new Set(existingFiles.map((f) => f.path));
1420
+ for (const path of paths) {
1421
+ if (existingPaths.has(path)) {
1422
+ throw new FileConflictError(path);
1423
+ }
1424
+ }
1425
+ }
1388
1426
  async saveFileEntries(files) {
1389
1427
  const aleph = this.core.getAlephService();
1390
1428
  const publicKey = this.core.getPublicKey();