@loghead/core 0.1.10 → 0.1.11

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_main.js CHANGED
@@ -65,6 +65,10 @@ async function main() {
65
65
  const s = await db.createStream(argv.project, argv.type, argv.name, config);
66
66
  console.log(`Stream created: ${s.id}`);
67
67
  console.log(`Token: ${s.token}`);
68
+ })
69
+ .command("token <streamId>", "Get token for stream", {}, async (argv) => {
70
+ const token = await auth.createStreamToken(argv.streamId);
71
+ console.log(`Token: ${token}`);
68
72
  });
69
73
  })
70
74
  .demandCommand(1)
package/dist/db/client.js CHANGED
@@ -39,9 +39,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.db = void 0;
40
40
  const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
41
41
  const sqliteVec = __importStar(require("sqlite-vec"));
42
+ const path_1 = __importDefault(require("path"));
42
43
  const dotenv_1 = __importDefault(require("dotenv"));
43
44
  dotenv_1.default.config();
44
45
  const dbPath = process.env.LOGHEAD_DB_PATH || "loghead.db";
46
+ console.log(`[DB] Using database at: ${path_1.default.resolve(dbPath)}`);
45
47
  const db = new better_sqlite3_1.default(dbPath);
46
48
  exports.db = db;
47
49
  // Load sqlite-vec extension
@@ -49,6 +49,7 @@ class AuthService {
49
49
  if (!this.secretKey)
50
50
  throw new Error("Auth not initialized");
51
51
  try {
52
+ // console.log(`[Auth] Verifying token with secret: ${this.secretKey.substring(0, 10)}...`);
52
53
  const payload = jsonwebtoken_1.default.verify(token, this.secretKey, { issuer: "loghead", algorithms: ["HS512"] });
53
54
  if (!payload.sub)
54
55
  return null;
@@ -56,6 +57,10 @@ class AuthService {
56
57
  }
57
58
  catch (e) {
58
59
  console.error("Token verification failed:", e);
60
+ if (e instanceof Error && e.message === "invalid signature") {
61
+ console.error("[Auth] Secret key mismatch. Ensure the server is using the same database (and secret) as when the token was generated.");
62
+ console.error(`[Auth] Current secret starts with: ${this.secretKey?.substring(0, 8)}...`);
63
+ }
59
64
  return null;
60
65
  }
61
66
  }
@@ -89,7 +89,8 @@ class DbService {
89
89
  return;
90
90
  }
91
91
  const vectorJson = JSON.stringify(embedding);
92
- client_1.db.prepare("INSERT INTO vec_logs(rowid, embedding) VALUES (?, ?)").run(rowid, vectorJson);
92
+ // Explicitly cast rowid to BigInt to ensure better-sqlite3 binds it as an INTEGER
93
+ client_1.db.prepare("INSERT INTO vec_logs(rowid, embedding) VALUES (?, ?)").run(BigInt(rowid), vectorJson);
93
94
  }
94
95
  });
95
96
  try {
package/dist/ui/main.js CHANGED
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.startTui = startTui;
7
+ const auth_1 = require("../services/auth");
7
8
  const inquirer_1 = __importDefault(require("inquirer"));
8
9
  const chalk_1 = __importDefault(require("chalk"));
9
10
  let title = `
@@ -123,6 +124,7 @@ async function startTui(db, token) {
123
124
  message: "Action",
124
125
  choices: [
125
126
  { name: "View logs", value: "view_logs" },
127
+ { name: "Get token", value: "get_token" },
126
128
  { name: "Delete stream", value: "delete_stream" },
127
129
  { name: chalk_1.default.yellow("Back"), value: "back" }
128
130
  ],
@@ -130,6 +132,18 @@ async function startTui(db, token) {
130
132
  }]);
131
133
  if (action === "back")
132
134
  break;
135
+ if (action === "get_token") {
136
+ const auth = new auth_1.AuthService();
137
+ const token = await auth.createStreamToken(streamId);
138
+ console.log(chalk_1.default.green(`\nToken for ${stream?.name}:`));
139
+ console.log(chalk_1.default.bold.yellow(`${token}\n`));
140
+ await inquirer_1.default.prompt([{
141
+ type: "input",
142
+ name: "continue",
143
+ message: "Press enter to continue...",
144
+ prefix: "💡"
145
+ }]);
146
+ }
133
147
  if (action === "delete_stream") {
134
148
  const { confirm } = await inquirer_1.default.prompt([{
135
149
  type: "confirm",
@@ -153,6 +167,7 @@ async function startTui(db, token) {
153
167
  console.log(`${chalk_1.default.dim(log.timestamp)} ${log.content}`);
154
168
  });
155
169
  }
170
+ console.log("\n");
156
171
  await inquirer_1.default.prompt([{
157
172
  type: "input",
158
173
  name: "return",
package/loghead.db CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loghead/core",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "Core API and Database for Loghead",
5
5
  "repository": {
6
6
  "type": "git",
package/src/cli_main.ts CHANGED
@@ -66,6 +66,10 @@ async function main() {
66
66
  const s = await db.createStream(argv.project, argv.type as string, argv.name as string, config);
67
67
  console.log(`Stream created: ${s.id}`);
68
68
  console.log(`Token: ${s.token}`);
69
+ })
70
+ .command("token <streamId>", "Get token for stream", {}, async (argv) => {
71
+ const token = await auth.createStreamToken(argv.streamId as string);
72
+ console.log(`Token: ${token}`);
69
73
  });
70
74
  })
71
75
  .demandCommand(1)
package/src/db/client.ts CHANGED
@@ -6,6 +6,7 @@ import dotenv from "dotenv";
6
6
  dotenv.config();
7
7
 
8
8
  const dbPath = process.env.LOGHEAD_DB_PATH || "loghead.db";
9
+ console.log(`[DB] Using database at: ${path.resolve(dbPath)}`);
9
10
 
10
11
  const db = new Database(dbPath);
11
12
 
@@ -58,11 +58,16 @@ export class AuthService {
58
58
  if (!this.secretKey) throw new Error("Auth not initialized");
59
59
 
60
60
  try {
61
+ // console.log(`[Auth] Verifying token with secret: ${this.secretKey.substring(0, 10)}...`);
61
62
  const payload = jwt.verify(token, this.secretKey, { issuer: "loghead", algorithms: ["HS512"] }) as jwt.JwtPayload;
62
63
  if (!payload.sub) return null;
63
64
  return { streamId: payload.sub };
64
65
  } catch (e) {
65
66
  console.error("Token verification failed:", e);
67
+ if (e instanceof Error && e.message === "invalid signature") {
68
+ console.error("[Auth] Secret key mismatch. Ensure the server is using the same database (and secret) as when the token was generated.");
69
+ console.error(`[Auth] Current secret starts with: ${this.secretKey?.substring(0, 8)}...`);
70
+ }
66
71
  return null;
67
72
  }
68
73
  }
@@ -102,7 +102,8 @@ export class DbService {
102
102
  return;
103
103
  }
104
104
  const vectorJson = JSON.stringify(embedding);
105
- (db.prepare("INSERT INTO vec_logs(rowid, embedding) VALUES (?, ?)") as unknown as DbAny).run(rowid, vectorJson);
105
+ // Explicitly cast rowid to BigInt to ensure better-sqlite3 binds it as an INTEGER
106
+ (db.prepare("INSERT INTO vec_logs(rowid, embedding) VALUES (?, ?)") as unknown as DbAny).run(BigInt(rowid), vectorJson);
106
107
  }
107
108
  });
108
109
 
package/src/ui/main.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { DbService } from "../services/db";
2
+ import { AuthService } from "../services/auth";
2
3
  import inquirer from "inquirer";
3
4
  import chalk from "chalk";
4
5
 
@@ -134,6 +135,7 @@ export async function startTui(db: DbService, token: string) {
134
135
  message: "Action",
135
136
  choices: [
136
137
  { name: "View logs", value: "view_logs" },
138
+ { name: "Get token", value: "get_token" },
137
139
  { name: "Delete stream", value: "delete_stream" },
138
140
  { name: chalk.yellow("Back"), value: "back" }
139
141
  ],
@@ -142,6 +144,20 @@ export async function startTui(db: DbService, token: string) {
142
144
 
143
145
  if (action === "back") break;
144
146
 
147
+ if (action === "get_token") {
148
+ const auth = new AuthService();
149
+ const token = await auth.createStreamToken(streamId);
150
+ console.log(chalk.green(`\nToken for ${stream?.name}:`));
151
+ console.log(chalk.bold.yellow(`${token}\n`));
152
+
153
+ await inquirer.prompt([{
154
+ type: "input",
155
+ name: "continue",
156
+ message: "Press enter to continue...",
157
+ prefix: "💡"
158
+ }]);
159
+ }
160
+
145
161
  if (action === "delete_stream") {
146
162
  const { confirm } = await inquirer.prompt([{
147
163
  type: "confirm",
@@ -167,6 +183,7 @@ export async function startTui(db: DbService, token: string) {
167
183
  });
168
184
  }
169
185
 
186
+ console.log("\n");
170
187
  await inquirer.prompt([{
171
188
  type: "input",
172
189
  name: "return",