@fileverse/api 0.0.21 → 0.0.23

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/cli/index.js CHANGED
@@ -97,12 +97,7 @@ var init_config = __esm({
97
97
  init_constants();
98
98
  projectEnvPath = path4.join(process.cwd(), "config", ".env");
99
99
  userEnvPath = path4.join(os2.homedir(), ".fileverse", ".env");
100
- if (typeof globalThis.process !== "undefined" && typeof globalThis.process.cwd === "function") {
101
- try {
102
- loadConfig(false);
103
- } catch {
104
- }
105
- }
100
+ loadConfig(false);
106
101
  config = {
107
102
  ...STATIC_CONFIG,
108
103
  get SERVICE_NAME() {
@@ -246,24 +241,12 @@ var init_key_store = __esm({
246
241
  }
247
242
  });
248
243
 
249
- // src/sdk/ucan.ts
250
- import { sign, extractPublicKeyFromSecretKey } from "@stablelib/ed25519";
251
- import { toUint8Array as toUint8Array2 } from "js-base64";
252
- var EDWARDS_DID_PREFIX;
253
- var init_ucan = __esm({
254
- "src/sdk/ucan.ts"() {
255
- "use strict";
256
- init_esm_shims();
257
- EDWARDS_DID_PREFIX = new Uint8Array([237, 1]);
258
- }
259
- });
260
-
261
244
  // src/sdk/auth-token-provider.ts
245
+ import * as ucans from "@ucans/ucans";
262
246
  var init_auth_token_provider = __esm({
263
247
  "src/sdk/auth-token-provider.ts"() {
264
248
  "use strict";
265
249
  init_esm_shims();
266
- init_ucan();
267
250
  }
268
251
  });
269
252
 
@@ -350,12 +333,15 @@ var init_file_encryption = __esm({
350
333
  });
351
334
 
352
335
  // src/sdk/file-utils.ts
336
+ import { getArgon2idHash } from "@fileverse/crypto/argon";
353
337
  import { bytesToBase64, generateRandomBytes as generateRandomBytes2 } from "@fileverse/crypto/utils";
354
338
  import { derivePBKDF2Key, encryptAesCBC } from "@fileverse/crypto/kdf";
355
339
  import { secretBoxEncrypt } from "@fileverse/crypto/nacl";
340
+ import hkdf from "futoin-hkdf";
356
341
  import tweetnacl from "tweetnacl";
357
- import { fromUint8Array, toUint8Array as toUint8Array3 } from "js-base64";
342
+ import { fromUint8Array, toUint8Array as toUint8Array2 } from "js-base64";
358
343
  import { toAESKey, aesEncrypt } from "@fileverse/crypto/webcrypto";
344
+ import axios2 from "axios";
359
345
  import { encodeFunctionData, parseEventLogs } from "viem";
360
346
  var init_file_utils = __esm({
361
347
  "src/sdk/file-utils.ts"() {
@@ -367,7 +353,7 @@ var init_file_utils = __esm({
367
353
  });
368
354
 
369
355
  // src/sdk/file-manager.ts
370
- import { fromUint8Array as fromUint8Array2, toUint8Array as toUint8Array4 } from "js-base64";
356
+ import { fromUint8Array as fromUint8Array2, toUint8Array as toUint8Array3 } from "js-base64";
371
357
  import { generateAESKey, exportAESKey } from "@fileverse/crypto/webcrypto";
372
358
  import { markdownToYjs } from "@fileverse/content-processor";
373
359
  var init_file_manager = __esm({
@@ -382,10 +368,11 @@ var init_file_manager = __esm({
382
368
  });
383
369
 
384
370
  // src/domain/portal/publish.ts
385
- import { fromUint8Array as fromUint8Array3, toUint8Array as toUint8Array5 } from "js-base64";
371
+ import { fromUint8Array as fromUint8Array3, toUint8Array as toUint8Array4 } from "js-base64";
386
372
  import { stringToBytes } from "viem";
387
373
  import { deriveHKDFKey } from "@fileverse/crypto/kdf";
388
374
  import { generateKeyPairFromSeed } from "@stablelib/ed25519";
375
+ import * as ucans2 from "@ucans/ucans";
389
376
  var init_publish = __esm({
390
377
  "src/domain/portal/publish.ts"() {
391
378
  "use strict";
@@ -394,11 +381,9 @@ var init_publish = __esm({
394
381
  init_infra();
395
382
  init_key_store();
396
383
  init_auth_token_provider();
397
- init_ucan();
398
384
  init_smart_agent();
399
385
  init_file_manager();
400
386
  init_config();
401
- init_pimlico_utils();
402
387
  }
403
388
  });
404
389
 
@@ -1115,9 +1100,7 @@ CREATE TABLE IF NOT EXISTS files (
1115
1100
  commentKey TEXT,
1116
1101
  linkKey TEXT,
1117
1102
  linkKeyNonce TEXT,
1118
- link TEXT,
1119
- derivedKey TEXT,
1120
- secretKey TEXT
1103
+ link TEXT
1121
1104
  );
1122
1105
  CREATE INDEX IF NOT EXISTS idx_files_createdAt ON files(createdAt);
1123
1106
  CREATE INDEX IF NOT EXISTS idx_files_syncStatus ON files(syncStatus);
@@ -1148,7 +1131,7 @@ CREATE TABLE IF NOT EXISTS events (
1148
1131
  type TEXT NOT NULL CHECK (type IN ('create', 'update', 'delete')),
1149
1132
  timestamp BIGINT NOT NULL,
1150
1133
  fileId TEXT NOT NULL,
1151
- status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'processing', 'submitted', 'processed', 'failed')),
1134
+ status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'processing', 'processed', 'failed')),
1152
1135
  retryCount INTEGER NOT NULL DEFAULT 0,
1153
1136
  lastError TEXT,
1154
1137
  lockedAt BIGINT,
@@ -1192,17 +1175,30 @@ import { Command } from "commander";
1192
1175
  // src/cli/fetch-api-key.ts
1193
1176
  init_esm_shims();
1194
1177
  init_constants();
1178
+ import axios from "axios";
1195
1179
  import { toUint8Array } from "js-base64";
1196
1180
  import { sha256 } from "viem";
1197
1181
  var fetchApiKeyData = async (apiKey) => {
1198
1182
  try {
1199
1183
  const keyHash = sha256(toUint8Array(apiKey));
1200
1184
  const fullUrl = BASE_CONFIG.API_URL + `api-access/${keyHash}`;
1201
- const response = await fetch(fullUrl);
1202
- const { encryptedKeyMaterial, encryptedAppMaterial, id } = await response.json();
1185
+ const response = await axios.get(fullUrl);
1186
+ const { encryptedKeyMaterial, encryptedAppMaterial, id } = response.data;
1203
1187
  return { encryptedKeyMaterial, encryptedAppMaterial, id };
1204
1188
  } catch (error) {
1205
- throw new Error(`Server error: ${error.message}`);
1189
+ if (axios.isAxiosError(error)) {
1190
+ if (error.response?.status === 401) {
1191
+ throw new Error("Invalid API key");
1192
+ }
1193
+ if (error.response?.status === 404) {
1194
+ throw new Error("API key not found");
1195
+ }
1196
+ if (error.code === "ECONNREFUSED") {
1197
+ throw new Error(`Cannot connect to server at ${BASE_CONFIG.API_URL}`);
1198
+ }
1199
+ throw new Error(`Server error: ${error.response?.data?.message || error.message}`);
1200
+ }
1201
+ throw error;
1206
1202
  }
1207
1203
  };
1208
1204
 
@@ -1393,7 +1389,7 @@ init_saveApiKey();
1393
1389
  init_apikeys_model();
1394
1390
  init_infra();
1395
1391
  import { deriveHKDFKey as deriveHKDFKey2 } from "@fileverse/crypto/hkdf";
1396
- import { toUint8Array as toUint8Array6 } from "js-base64";
1392
+ import { toUint8Array as toUint8Array5 } from "js-base64";
1397
1393
  import { stringToBytes as stringToBytes2 } from "viem";
1398
1394
  import { toAESKey as toAESKey2, aesDecrypt } from "@fileverse/crypto/webcrypto";
1399
1395
  var SAVED_DATA_ENCRYPTION_KEY_INFO = "SAVED_DATA_ENCRYPTION_KEY";
@@ -1418,7 +1414,7 @@ async function initializeWithData(data) {
1418
1414
  }
1419
1415
  var getAesKeyFromApiKey = async (apiKey) => {
1420
1416
  const rawSecret = deriveHKDFKey2(
1421
- toUint8Array6(apiKey),
1417
+ toUint8Array5(apiKey),
1422
1418
  new Uint8Array([0]),
1423
1419
  stringToBytes2(SAVED_DATA_ENCRYPTION_KEY_INFO)
1424
1420
  );
@@ -1429,13 +1425,13 @@ var bytestToJSON = (bytes) => {
1429
1425
  };
1430
1426
  var decryptSavedData = async (apiKey, encryptedData) => {
1431
1427
  const aesKey = await getAesKeyFromApiKey(apiKey);
1432
- const decryptedBytes = await aesDecrypt(aesKey, toUint8Array6(encryptedData));
1428
+ const decryptedBytes = await aesDecrypt(aesKey, toUint8Array5(encryptedData));
1433
1429
  const data = bytestToJSON(decryptedBytes);
1434
1430
  return data;
1435
1431
  };
1436
1432
 
1437
1433
  // src/cli/index.ts
1438
- var program = new Command().name("fileverse-api").description("Run the Fileverse API server").version("0.0.8").option("--apiKey <key>", "API key for authentication").option("--rpcUrl <url>", "RPC URL for blockchain connection").option("--port <port>", "Port to run the server on", "8001").option("--db <path>", "Database path").action(async (options) => {
1434
+ var program = new Command().name("fileverse-api").description("Run the Fileverse API server").version("0.0.23").option("--apiKey <key>", "API key for authentication").option("--rpcUrl <url>", "RPC URL for blockchain connection").option("--port <port>", "Port to run the server on", "8001").option("--db <path>", "Database path").action(async (options) => {
1439
1435
  try {
1440
1436
  console.log("Fileverse API - Starting initialization...\n");
1441
1437
  if (needsPrompting(options)) {
@@ -1483,13 +1479,9 @@ var program = new Command().name("fileverse-api").description("Run the Fileverse
1483
1479
  API Server: http://127.0.0.1:${options.port}
1484
1480
  Worker: Active
1485
1481
 
1486
- MCP: Connect Claude to your Fileverse API:
1487
-
1488
- Via stdio:
1489
- claude mcp add fileverse-api -- fileverse-api-mcp
1482
+ Open this link for CLI and API guide: http://127.0.0.1:${options.port}
1490
1483
 
1491
- Via HTTP:
1492
- claude mcp add --transport http fileverse-api http://127.0.0.1:${options.port}/mcp
1484
+ Share this with your LLM: http://127.0.0.1:${options.port}/llm.txt
1493
1485
 
1494
1486
  Press Ctrl+C to stop.
1495
1487
  `);