Skip to content

Commit 545443a

Browse files
committed
fix: synchronize environment variable with constructor argument before database initialization to ensure backup and validation are correctly enabled
1 parent b79d50b commit 545443a

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ const SQLITE_DONE = 101;
2626
class Arkilian {
2727
constructor(apiKey, dbPath = "app.sqlite") {
2828
if (!apiKey) throw new Error("Your API key is required");
29+
// db_init reads ARKILIAN_API_KEY from the environment to decide
30+
// whether to enable backup (src/class.c disables it when the key is
31+
// absent) and to run startup auth validation against the control
32+
// plane. If the JS wrapper calls setApiKey AFTER db_init — as it did
33+
// before — the key arrives too late: backup is already permanently
34+
// disabled for the process and the startup validation never ran, so
35+
// `new Arkilian('your-api-key', 'app.sqlite')` silently ran without
36+
// backup. Sync the env from the constructor argument BEFORE db_init so
37+
// the documented constructor apiKey drives both enablement and
38+
// validation; db_set_api_key then keeps the in-memory key in lockstep.
39+
if (!process.env.ARKILIAN_API_KEY) {
40+
process.env.ARKILIAN_API_KEY = apiKey;
41+
}
2942
this.id = native.db_init(dbPath);
3043
if (!this.id) {
3144
throw new Error("Failed to initialize database");

0 commit comments

Comments
 (0)