@agenticmail/api 0.5.56 → 0.5.58

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.
Files changed (2) hide show
  1. package/dist/index.js +35 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -309,7 +309,7 @@ function createAccountRoutes(accountManager, db, config) {
309
309
  res.status(201).json(sanitizeAgent(agent));
310
310
  } catch (err) {
311
311
  const msg = err.message ?? "";
312
- if (msg.includes("UNIQUE") || msg.includes("unique") || msg.includes("already exists") || msg.includes("duplicate")) {
312
+ if (msg.includes("UNIQUE") || msg.includes("unique") || msg.includes("already exists") || msg.includes("duplicate") || msg.includes("fieldAlreadyExists") || msg.toLowerCase().includes("alreadyexists")) {
313
313
  res.status(409).json({ error: `Agent "${name}" already exists` });
314
314
  return;
315
315
  }
@@ -3492,7 +3492,40 @@ function buildWhereClause(where) {
3492
3492
  function nowExpr(dialect) {
3493
3493
  return dialect === "postgres" ? "NOW()" : "datetime('now')";
3494
3494
  }
3495
- function createStorageRoutes(db, accountManager, config, dialect = "sqlite") {
3495
+ function adaptBetterSqlite(raw) {
3496
+ if (raw && typeof raw.run === "function" && typeof raw.get === "function" && typeof raw.all === "function") {
3497
+ return raw;
3498
+ }
3499
+ const exec = (sql, params) => {
3500
+ if (!params || params.length === 0) {
3501
+ raw.exec(sql);
3502
+ return;
3503
+ }
3504
+ raw.prepare(sql).run(...params);
3505
+ };
3506
+ return {
3507
+ run(sql, params) {
3508
+ const trimmed = sql.trim().toUpperCase();
3509
+ const isDDL = trimmed.startsWith("CREATE") || trimmed.startsWith("ALTER") || trimmed.startsWith("DROP") || trimmed.startsWith("PRAGMA");
3510
+ if (isDDL && (!params || params.length === 0)) {
3511
+ raw.exec(sql);
3512
+ return;
3513
+ }
3514
+ exec(sql, params);
3515
+ },
3516
+ get(sql, params) {
3517
+ const stmt = raw.prepare(sql);
3518
+ return params && params.length > 0 ? stmt.get(...params) : stmt.get();
3519
+ },
3520
+ all(sql, params) {
3521
+ const stmt = raw.prepare(sql);
3522
+ const rows = params && params.length > 0 ? stmt.all(...params) : stmt.all();
3523
+ return rows;
3524
+ }
3525
+ };
3526
+ }
3527
+ function createStorageRoutes(rawDb, accountManager, config, dialect = "sqlite") {
3528
+ const db = adaptBetterSqlite(rawDb);
3496
3529
  const router = Router11();
3497
3530
  function getAgent(req, res) {
3498
3531
  const agent = req.agent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agenticmail/api",
3
- "version": "0.5.56",
3
+ "version": "0.5.58",
4
4
  "description": "REST API server for AgenticMail — email and SMS endpoints for AI agents",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",