obsidian-sync-mcp 0.7.1 → 0.7.3

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.
@@ -6,8 +6,10 @@ import {
6
6
  } from "./chunk-SGLPTZJA.js";
7
7
  import {
8
8
  __reExport,
9
- parseFrontmatterAndLinks
10
- } from "./chunk-43MP6CJE.js";
9
+ isValidNotePath,
10
+ parseFrontmatterAndLinks,
11
+ validateNotePath
12
+ } from "./chunk-VR63UUCB.js";
11
13
 
12
14
  // lib/livesync-commonlib/src/common/types.ts
13
15
  import {
@@ -10000,15 +10002,63 @@ function classifyIds(ids) {
10000
10002
  return obfuscated > 0 ? "obfuscated" : "plain";
10001
10003
  }
10002
10004
 
10005
+ // src/couchdb-preflight.ts
10006
+ function databaseUrl(url, database) {
10007
+ const u = new URL(url);
10008
+ u.username = "";
10009
+ u.password = "";
10010
+ u.hash = "";
10011
+ u.pathname = `${u.pathname.replace(/\/+$/, "")}/${encodeURIComponent(database)}`;
10012
+ return u.toString();
10013
+ }
10014
+ function networkReason(err) {
10015
+ if (err instanceof Error) {
10016
+ if (err.name === "TimeoutError") return "no response (timed out)";
10017
+ const cause = err.cause;
10018
+ if (cause instanceof Error) return cause.message || String(cause.code ?? cause.name);
10019
+ return err.message;
10020
+ }
10021
+ return String(err);
10022
+ }
10023
+ async function checkDatabase(target, options = {}) {
10024
+ const { fetchImpl = fetch, timeoutMs = 1e4 } = options;
10025
+ if (!target.database) {
10026
+ throw new Error("COUCHDB_DATABASE is empty. Set it to the name of your LiveSync database.");
10027
+ }
10028
+ const url = databaseUrl(target.url, target.database);
10029
+ const token = Buffer.from(`${target.username}:${target.password}`).toString("base64");
10030
+ const headers = { Accept: "application/json", Authorization: `Basic ${token}` };
10031
+ let res;
10032
+ try {
10033
+ res = await fetchImpl(url, { headers, signal: AbortSignal.timeout(timeoutMs) });
10034
+ } catch (err) {
10035
+ throw new Error(`Cannot reach CouchDB at ${url}: ${networkReason(err)}.`);
10036
+ }
10037
+ await res.body?.cancel();
10038
+ if (res.ok) return;
10039
+ if (res.status === 404) {
10040
+ throw new Error(
10041
+ `CouchDB database "${target.database}" does not exist at ${url}. This server never creates databases; check COUCHDB_DATABASE.`
10042
+ );
10043
+ }
10044
+ if (res.status === 401 || res.status === 403) {
10045
+ throw new Error(
10046
+ `CouchDB at ${url} refused access to database "${target.database}" (HTTP ${res.status}). Check COUCHDB_USER and COUCHDB_PASSWORD, and that the user is a member of the database.`
10047
+ );
10048
+ }
10049
+ throw new Error(`CouchDB at ${url} returned HTTP ${res.status} for database "${target.database}".`);
10050
+ }
10051
+
10003
10052
  // src/vault.ts
10004
10053
  var Vault = class _Vault {
10054
+ // Created in init(): constructing it starts connecting, and PouchDB would
10055
+ // create a missing database, so the existence check has to come first.
10005
10056
  manipulator;
10006
10057
  passphrase;
10007
10058
  config;
10008
10059
  constructor(config) {
10009
10060
  this.config = config;
10010
10061
  this.passphrase = config.passphrase;
10011
- this.manipulator = new DirectFileManipulator(_Vault.buildOptions(config, !!config.obfuscatePaths));
10012
10062
  }
10013
10063
  static buildOptions(config, obfuscatePaths) {
10014
10064
  return {
@@ -10025,6 +10075,13 @@ var Vault = class _Vault {
10025
10075
  };
10026
10076
  }
10027
10077
  async init() {
10078
+ await checkDatabase({
10079
+ url: this.config.couchdbUrl,
10080
+ database: this.config.database,
10081
+ username: this.config.couchdbUser,
10082
+ password: this.config.couchdbPassword
10083
+ });
10084
+ this.manipulator = new DirectFileManipulator(_Vault.buildOptions(this.config, !!this.config.obfuscatePaths));
10028
10085
  await this.manipulator.ready.promise;
10029
10086
  await this.reconcileObfuscation();
10030
10087
  }
@@ -10088,11 +10145,11 @@ var Vault = class _Vault {
10088
10145
  await this.manipulator.close();
10089
10146
  }
10090
10147
  static mdFilter(meta) {
10091
- return (meta.path ?? "").endsWith(".md");
10148
+ return isValidNotePath(meta.path ?? "");
10092
10149
  }
10093
10150
  static docToChange(doc, callback, seq) {
10094
10151
  const path = doc.path ?? "";
10095
- if (!path.endsWith(".md")) return;
10152
+ if (!isValidNotePath(path)) return;
10096
10153
  const content = deriveContent(doc);
10097
10154
  callback(path, content, content === null ? void 0 : doc.mtime, seq);
10098
10155
  }
@@ -10122,7 +10179,7 @@ var Vault = class _Vault {
10122
10179
  continue;
10123
10180
  }
10124
10181
  }
10125
- if (!path.endsWith(".md") && !meta.deleted) continue;
10182
+ if (!isValidNotePath(path) && !meta.deleted) continue;
10126
10183
  const doc = await this.manipulator.getByMeta(meta).catch(() => null);
10127
10184
  if (doc) _Vault.docToChange(doc, callback);
10128
10185
  }
@@ -10144,9 +10201,7 @@ var Vault = class _Vault {
10144
10201
  );
10145
10202
  }
10146
10203
  validatePath(path) {
10147
- if (!path || path.startsWith("/") || path.includes("\0") || path.includes("..") || path.length > 1e3) {
10148
- throw new Error("Invalid path");
10149
- }
10204
+ validateNotePath(path);
10150
10205
  }
10151
10206
  async readNote(path) {
10152
10207
  this.validatePath(path);
@@ -10210,7 +10265,7 @@ var Vault = class _Vault {
10210
10265
  const entry = doc;
10211
10266
  if (entry.deleted) continue;
10212
10267
  const notePath = entry.path ?? "";
10213
- if (!notePath.endsWith(".md")) continue;
10268
+ if (!isValidNotePath(notePath)) continue;
10214
10269
  if (folder && !notePath.startsWith(folder)) continue;
10215
10270
  results.push({ path: notePath, mtime: entry.mtime ?? 0 });
10216
10271
  }
@@ -10220,4 +10275,4 @@ var Vault = class _Vault {
10220
10275
  export {
10221
10276
  Vault
10222
10277
  };
10223
- //# sourceMappingURL=vault-YGHHZZZQ.js.map
10278
+ //# sourceMappingURL=vault-EJSNMND5.js.map