@fileverse/api 0.0.18 → 0.0.20

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.
@@ -2154,9 +2154,9 @@ var init_aes = __esm({
2154
2154
  const nonceLen = EMPTY_BLOCK.slice();
2155
2155
  const view = createView(nonceLen);
2156
2156
  view.setBigUint64(8, BigInt(nonce.length * 8), false);
2157
- const g2 = ghash.create(authKey).update(nonce).update(nonceLen);
2158
- g2.digestInto(counter);
2159
- g2.destroy();
2157
+ const g = ghash.create(authKey).update(nonce).update(nonceLen);
2158
+ g.digestInto(counter);
2159
+ g.destroy();
2160
2160
  }
2161
2161
  const tagMask = ctr32(xk, false, counter, EMPTY_BLOCK);
2162
2162
  return { xk, authKey, counter, tagMask };
@@ -2512,46 +2512,6 @@ var init_file_utils = __esm({
2512
2512
  }
2513
2513
  });
2514
2514
 
2515
- // src/sdk/dom-globals.ts
2516
- function captureDOMGlobals() {
2517
- if (savedGlobals) return;
2518
- savedGlobals = {};
2519
- for (const key of DOM_KEYS) {
2520
- savedGlobals[key] = g[key];
2521
- }
2522
- }
2523
- function removeDOMGlobals() {
2524
- delete g.window;
2525
- delete g.document;
2526
- }
2527
- function restoreDOMGlobals() {
2528
- if (!savedGlobals) return;
2529
- Object.assign(g, savedGlobals);
2530
- }
2531
- var DOM_KEYS, g, savedGlobals;
2532
- var init_dom_globals = __esm({
2533
- "src/sdk/dom-globals.ts"() {
2534
- "use strict";
2535
- init_esm_shims();
2536
- DOM_KEYS = [
2537
- "window",
2538
- "document",
2539
- "navigator",
2540
- "Node",
2541
- "HTMLElement",
2542
- "Text",
2543
- "DOMParser",
2544
- "Element",
2545
- "DocumentFragment",
2546
- "getComputedStyle",
2547
- "MutationObserver",
2548
- "Range"
2549
- ];
2550
- g = globalThis;
2551
- savedGlobals = null;
2552
- }
2553
- });
2554
-
2555
2515
  // src/sdk/file-manager.ts
2556
2516
  import { fromUint8Array as fromUint8Array2, toUint8Array as toUint8Array3 } from "js-base64";
2557
2517
  import { generateAESKey, exportAESKey } from "@fileverse/crypto/webcrypto";
@@ -2564,7 +2524,6 @@ var init_file_manager = __esm({
2564
2524
  init_file_utils();
2565
2525
  init_constants();
2566
2526
  init_constants2();
2567
- init_dom_globals();
2568
2527
  init_infra();
2569
2528
  FileManager = class {
2570
2529
  keyStore;
@@ -2573,14 +2532,6 @@ var init_file_manager = __esm({
2573
2532
  this.keyStore = keyStore;
2574
2533
  this.agentClient = agentClient;
2575
2534
  }
2576
- convertMarkdown(content) {
2577
- restoreDOMGlobals();
2578
- try {
2579
- return markdownToYjs(content);
2580
- } finally {
2581
- removeDOMGlobals();
2582
- }
2583
- }
2584
2535
  createLocks(key, encryptedSecretKey, commentKey) {
2585
2536
  const appLock = {
2586
2537
  lockedFileKey: this.keyStore.encryptData(toUint8Array3(key)),
@@ -2624,7 +2575,7 @@ var init_file_manager = __esm({
2624
2575
  const nonce = toUint8Array3(file2.linkKeyNonce);
2625
2576
  const secretKey = toUint8Array3(file2.secretKey);
2626
2577
  console.log("Got encrypted secret key, nonce, and secret key");
2627
- const yJSContent = this.convertMarkdown(file2.content);
2578
+ const yJSContent = markdownToYjs(file2.content);
2628
2579
  console.log("Generated yjs content");
2629
2580
  const { encryptedFile, key } = await createEncryptedContentFile(yJSContent);
2630
2581
  console.log("Generated encrypted content file");
@@ -2684,7 +2635,7 @@ var init_file_manager = __esm({
2684
2635
  const encryptedSecretKey = file2.linkKey;
2685
2636
  const nonce = toUint8Array3(file2.linkKeyNonce);
2686
2637
  const secretKey = toUint8Array3(file2.secretKey);
2687
- const yjsContent = this.convertMarkdown(file2.content);
2638
+ const yjsContent = markdownToYjs(file2.content);
2688
2639
  const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
2689
2640
  const commentKey = toUint8Array3(file2.commentKey);
2690
2641
  const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
@@ -2733,7 +2684,7 @@ var init_file_manager = __esm({
2733
2684
  const nonce = toUint8Array3(file2.linkKeyNonce);
2734
2685
  const secretKey = toUint8Array3(file2.secretKey);
2735
2686
  logger.debug(`Generating encrypted content file for file ${file2.ddocId} with onChainFileId ${file2.onChainFileId}`);
2736
- const yjsContent = this.convertMarkdown(file2.content);
2687
+ const yjsContent = markdownToYjs(file2.content);
2737
2688
  const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
2738
2689
  const commentKey = toUint8Array3(file2.commentKey);
2739
2690
  const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
@@ -3087,44 +3038,38 @@ var init_eventProcessor = __esm({
3087
3038
  if (!file2) throw new Error(`File ${fileId} not found`);
3088
3039
  if (file2.isDeleted === 1) {
3089
3040
  logger.info(`File ${fileId} is deleted, skipping create submit`);
3090
- return;
3041
+ return null;
3091
3042
  }
3092
3043
  console.log("Submitting new file op");
3093
3044
  const result = await handleNewFileOp(fileId);
3094
3045
  console.log("New file op submitted");
3095
- await EventsModel.setEventPendingOp(event._id, result.userOpHash, {
3096
- metadata: result.metadata
3097
- });
3098
3046
  logger.info(`File ${file2.ddocId} create op submitted (hash: ${result.userOpHash})`);
3099
- break;
3047
+ return { userOpHash: result.userOpHash, pendingPayload: { metadata: result.metadata } };
3100
3048
  }
3101
3049
  case "update": {
3102
3050
  const file2 = await FilesModel.findByIdExcludingDeleted(fileId);
3103
- if (!file2) return;
3104
- if (file2.localVersion <= file2.onchainVersion) return;
3051
+ if (!file2) return null;
3052
+ if (file2.localVersion <= file2.onchainVersion) return null;
3105
3053
  const result = await submitUpdateFileOp(fileId);
3106
- await EventsModel.setEventPendingOp(event._id, result.userOpHash, {
3107
- metadata: result.metadata,
3108
- localVersion: file2.localVersion
3109
- });
3110
3054
  logger.info(`File ${file2.ddocId} update op submitted (hash: ${result.userOpHash})`);
3111
- break;
3055
+ return {
3056
+ userOpHash: result.userOpHash,
3057
+ pendingPayload: { metadata: result.metadata, localVersion: file2.localVersion }
3058
+ };
3112
3059
  }
3113
3060
  case "delete": {
3114
3061
  const file2 = await FilesModel.findByIdIncludingDeleted(fileId);
3115
- if (!file2) return;
3062
+ if (!file2) return null;
3116
3063
  if (file2.isDeleted === 1 && file2.syncStatus === "synced") {
3117
3064
  logger.info(`File ${fileId} deletion already synced, skipping`);
3118
- return;
3065
+ return null;
3119
3066
  }
3120
3067
  if (file2.onChainFileId === null || file2.onChainFileId === void 0) {
3121
- await FilesModel.update(fileId, { syncStatus: "synced", isDeleted: 1 }, file2.portalAddress);
3122
- return;
3068
+ return { noOp: true, fileId, portalAddress: file2.portalAddress };
3123
3069
  }
3124
3070
  const result = await submitDeleteFileOp(fileId);
3125
- await EventsModel.setEventPendingOp(event._id, result.userOpHash, {});
3126
3071
  logger.info(`File ${file2.ddocId} delete op submitted (hash: ${result.userOpHash})`);
3127
- break;
3072
+ return { userOpHash: result.userOpHash, pendingPayload: {} };
3128
3073
  }
3129
3074
  default:
3130
3075
  throw new Error(`Unknown event type: ${type}`);
@@ -4132,30 +4077,17 @@ init_esm_shims();
4132
4077
  // src/cli/fetch-api-key.ts
4133
4078
  init_esm_shims();
4134
4079
  init_constants();
4135
- import axios from "axios";
4136
4080
  import { toUint8Array as toUint8Array6 } from "js-base64";
4137
4081
  import { sha256 } from "viem";
4138
4082
  var fetchApiKeyData = async (apiKey) => {
4139
4083
  try {
4140
4084
  const keyHash = sha256(toUint8Array6(apiKey));
4141
4085
  const fullUrl = BASE_CONFIG.API_URL + `api-access/${keyHash}`;
4142
- const response = await axios.get(fullUrl);
4143
- const { encryptedKeyMaterial, encryptedAppMaterial, id } = response.data;
4086
+ const response = await fetch(fullUrl);
4087
+ const { encryptedKeyMaterial, encryptedAppMaterial, id } = await response.json();
4144
4088
  return { encryptedKeyMaterial, encryptedAppMaterial, id };
4145
4089
  } catch (error48) {
4146
- if (axios.isAxiosError(error48)) {
4147
- if (error48.response?.status === 401) {
4148
- throw new Error("Invalid API key");
4149
- }
4150
- if (error48.response?.status === 404) {
4151
- throw new Error("API key not found");
4152
- }
4153
- if (error48.code === "ECONNREFUSED") {
4154
- throw new Error(`Cannot connect to server at ${BASE_CONFIG.API_URL}`);
4155
- }
4156
- throw new Error(`Server error: ${error48.response?.data?.message || error48.message}`);
4157
- }
4158
- throw error48;
4090
+ throw new Error(`Server error: ${error48.message}`);
4159
4091
  }
4160
4092
  };
4161
4093
 
@@ -18299,11 +18231,6 @@ function createMcpServer(config3) {
18299
18231
  registerTools(server, client);
18300
18232
  return server;
18301
18233
  }
18302
-
18303
- // src/cloudflare.ts
18304
- init_dom_globals();
18305
- captureDOMGlobals();
18306
- removeDOMGlobals();
18307
18234
  export {
18308
18235
  ApiKeysModel,
18309
18236
  EventsModel,