File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,6 +26,19 @@ const SQLITE_DONE = 101;
2626class 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" ) ;
You can’t perform that action at this time.
0 commit comments