@actual-app/sync-server 26.11.0 → 26.12.0-nightly.20261104
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/build/app.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as run } from "./chunks/migrations-C3rb5XGz.js";
|
|
2
2
|
//#region app.ts
|
|
3
3
|
run().then(() => {
|
|
4
|
-
import("./chunks/app-
|
|
4
|
+
import("./chunks/app-DdHDpmcN.js").then((app) => app.run());
|
|
5
5
|
}).catch((err) => {
|
|
6
6
|
console.log("Error starting app:", err);
|
|
7
7
|
process.exit(1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actual-server.js","names":[],"sources":["../../bin/actual-server.js"],"sourcesContent":["#!/usr/bin/env node\nimport { existsSync, readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { parseArgs } from 'node:util';\n\nconst args = process.argv;\n\nconst options = {\n help: {\n type: 'boolean',\n short: 'h',\n },\n version: {\n type: 'boolean',\n short: 'v',\n },\n 'reset-password': {\n type: 'boolean',\n },\n config: {\n type: 'string',\n },\n};\n\nconst { values } = parseArgs({\n args,\n options,\n allowPositionals: true,\n});\n\nif (values.help) {\n console.log(\n [\n 'usage: actual-server [options]',\n '',\n 'options:',\n ' --config Path to config file',\n '',\n ' -h --help Print this list and exit.',\n ' -v --version Print the version and exit.',\n '',\n 'Examples:',\n '',\n 'Runs actual-server with default configuration',\n ' actual-server',\n '',\n 'Runs actual-server with custom configuration',\n ' actual-server --config ./config.json',\n ].join('\\n'),\n );\n\n process.exit();\n}\n\nif (values.version) {\n console.log('v' + __APP_VERSION__);\n process.exit();\n}\n\nconst setupDataDir = dataDir => {\n if (process.env.ACTUAL_DATA_DIR) {\n return; // Env variables must not be overwritten\n }\n\n if (dataDir) {\n process.env.ACTUAL_DATA_DIR = dataDir; // Use the dir specified\n } else {\n // Setup defaults\n if (existsSync('./data')) {\n // The default data directory exists - use it\n console.info('Found existing data directory');\n process.env.ACTUAL_DATA_DIR = resolve('./data');\n } else {\n console.info(\n 'Using default data directory. You can specify a custom config with --config',\n );\n process.env.ACTUAL_DATA_DIR = resolve('./');\n }\n\n console.info(`Data directory: ${process.env.ACTUAL_DATA_DIR}`);\n }\n};\n\nif (values.config) {\n const configExists = existsSync(values.config);\n\n if (!configExists) {\n console.log(\n `Please specify a valid config path. The path ${String(values.config)} does not exist.`,\n );\n\n process.exit();\n } else {\n console.log(`Loading config from ${String(values.config)}`);\n const configJson = JSON.parse(readFileSync(values.config, 'utf-8'));\n process.env.ACTUAL_CONFIG_PATH = values.config;\n setupDataDir(configJson.dataDir);\n }\n} else {\n // If no config is specified, check for a default config in the current directory\n const defaultConfigJsonFile = './config.json';\n const configExists = existsSync(defaultConfigJsonFile);\n\n if (configExists) {\n console.info('Found config.json in the current directory');\n const configJson = JSON.parse(readFileSync(defaultConfigJsonFile, 'utf-8'));\n process.env.ACTUAL_CONFIG_PATH = defaultConfigJsonFile;\n setupDataDir(configJson.dataDir);\n } else {\n setupDataDir(); // No default config exists - setup data dir with defaults\n }\n}\n\nif (values['reset-password']) {\n console.info('Running reset password script...');\n await import('../src/scripts/reset-password.js');\n process.exit();\n}\n\n// start the sync server\nvoid import('../app.js');\n"],"mappings":";;;;;AAKA,IAAM,OAAO,QAAQ;AAmBrB,IAAM,EAAE,WAAW,UAAU;CAC3B;CACA,SAAA;EAlBA,MAAM;GACJ,MAAM;GACN,OAAO;EACT;EACA,SAAS;GACP,MAAM;GACN,OAAO;EACT;EACA,kBAAkB,EAChB,MAAM,UACR;EACA,QAAQ,EACN,MAAM,SACR;CAKM;CACN,kBAAkB;AACpB,CAAC;AAED,IAAI,OAAO,MAAM;CACf,QAAQ,IACN;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC,CAAC,KAAK,IAAI,CACb;CAEA,QAAQ,KAAK;AACf;AAEA,IAAI,OAAO,SAAS;CAClB,QAAQ,IAAI,
|
|
1
|
+
{"version":3,"file":"actual-server.js","names":[],"sources":["../../bin/actual-server.js"],"sourcesContent":["#!/usr/bin/env node\nimport { existsSync, readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { parseArgs } from 'node:util';\n\nconst args = process.argv;\n\nconst options = {\n help: {\n type: 'boolean',\n short: 'h',\n },\n version: {\n type: 'boolean',\n short: 'v',\n },\n 'reset-password': {\n type: 'boolean',\n },\n config: {\n type: 'string',\n },\n};\n\nconst { values } = parseArgs({\n args,\n options,\n allowPositionals: true,\n});\n\nif (values.help) {\n console.log(\n [\n 'usage: actual-server [options]',\n '',\n 'options:',\n ' --config Path to config file',\n '',\n ' -h --help Print this list and exit.',\n ' -v --version Print the version and exit.',\n '',\n 'Examples:',\n '',\n 'Runs actual-server with default configuration',\n ' actual-server',\n '',\n 'Runs actual-server with custom configuration',\n ' actual-server --config ./config.json',\n ].join('\\n'),\n );\n\n process.exit();\n}\n\nif (values.version) {\n console.log('v' + __APP_VERSION__);\n process.exit();\n}\n\nconst setupDataDir = dataDir => {\n if (process.env.ACTUAL_DATA_DIR) {\n return; // Env variables must not be overwritten\n }\n\n if (dataDir) {\n process.env.ACTUAL_DATA_DIR = dataDir; // Use the dir specified\n } else {\n // Setup defaults\n if (existsSync('./data')) {\n // The default data directory exists - use it\n console.info('Found existing data directory');\n process.env.ACTUAL_DATA_DIR = resolve('./data');\n } else {\n console.info(\n 'Using default data directory. You can specify a custom config with --config',\n );\n process.env.ACTUAL_DATA_DIR = resolve('./');\n }\n\n console.info(`Data directory: ${process.env.ACTUAL_DATA_DIR}`);\n }\n};\n\nif (values.config) {\n const configExists = existsSync(values.config);\n\n if (!configExists) {\n console.log(\n `Please specify a valid config path. The path ${String(values.config)} does not exist.`,\n );\n\n process.exit();\n } else {\n console.log(`Loading config from ${String(values.config)}`);\n const configJson = JSON.parse(readFileSync(values.config, 'utf-8'));\n process.env.ACTUAL_CONFIG_PATH = values.config;\n setupDataDir(configJson.dataDir);\n }\n} else {\n // If no config is specified, check for a default config in the current directory\n const defaultConfigJsonFile = './config.json';\n const configExists = existsSync(defaultConfigJsonFile);\n\n if (configExists) {\n console.info('Found config.json in the current directory');\n const configJson = JSON.parse(readFileSync(defaultConfigJsonFile, 'utf-8'));\n process.env.ACTUAL_CONFIG_PATH = defaultConfigJsonFile;\n setupDataDir(configJson.dataDir);\n } else {\n setupDataDir(); // No default config exists - setup data dir with defaults\n }\n}\n\nif (values['reset-password']) {\n console.info('Running reset password script...');\n await import('../src/scripts/reset-password.js');\n process.exit();\n}\n\n// start the sync server\nvoid import('../app.js');\n"],"mappings":";;;;;AAKA,IAAM,OAAO,QAAQ;AAmBrB,IAAM,EAAE,WAAW,UAAU;CAC3B;CACA,SAAA;EAlBA,MAAM;GACJ,MAAM;GACN,OAAO;EACT;EACA,SAAS;GACP,MAAM;GACN,OAAO;EACT;EACA,kBAAkB,EAChB,MAAM,UACR;EACA,QAAQ,EACN,MAAM,SACR;CAKM;CACN,kBAAkB;AACpB,CAAC;AAED,IAAI,OAAO,MAAM;CACf,QAAQ,IACN;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC,CAAC,KAAK,IAAI,CACb;CAEA,QAAQ,KAAK;AACf;AAEA,IAAI,OAAO,SAAS;CAClB,QAAQ,IAAI,2BAAqB;CACjC,QAAQ,KAAK;AACf;AAEA,IAAM,gBAAe,YAAW;CAC9B,IAAI,QAAQ,IAAI,iBACd;CAGF,IAAI,SACF,QAAQ,IAAI,kBAAkB;MACzB;EAEL,IAAI,WAAW,QAAQ,GAAG;GAExB,QAAQ,KAAK,+BAA+B;GAC5C,QAAQ,IAAI,kBAAkB,QAAQ,QAAQ;EAChD,OAAO;GACL,QAAQ,KACN,6EACF;GACA,QAAQ,IAAI,kBAAkB,QAAQ,IAAI;EAC5C;EAEA,QAAQ,KAAK,mBAAmB,QAAQ,IAAI,iBAAiB;CAC/D;AACF;AAEA,IAAI,OAAO,QAAQ;CAGjB,IAAI,CAFiB,WAAW,OAAO,MAEvB,GAAG;EACjB,QAAQ,IACN,gDAAgD,OAAO,OAAO,MAAM,EAAE,iBACxE;EAEA,QAAQ,KAAK;CACf,OAAO;EACL,QAAQ,IAAI,uBAAuB,OAAO,OAAO,MAAM,GAAG;EAC1D,MAAM,aAAa,KAAK,MAAM,aAAa,OAAO,QAAQ,OAAO,CAAC;EAClE,QAAQ,IAAI,qBAAqB,OAAO;EACxC,aAAa,WAAW,OAAO;CACjC;AACF,OAAO;CAEL,MAAM,wBAAwB;CAG9B,IAFqB,WAAW,qBAEjB,GAAG;EAChB,QAAQ,KAAK,4CAA4C;EACzD,MAAM,aAAa,KAAK,MAAM,aAAa,uBAAuB,OAAO,CAAC;EAC1E,QAAQ,IAAI,qBAAqB;EACjC,aAAa,WAAW,OAAO;CACjC,OACE,aAAa;AAEjB;AAEA,IAAI,OAAO,mBAAmB;CAC5B,QAAQ,KAAK,kCAAkC;CAC/C,MAAM,OAAO;CACb,QAAQ,KAAK;AACf;AAGK,OAAO"}
|
|
@@ -5331,6 +5331,7 @@ var validateUploadedFile = (groupId, keyId, currentFile) => {
|
|
|
5331
5331
|
var messages_default = "\nCREATE TABLE messages_binary\n (timestamp TEXT PRIMARY KEY,\n is_encrypted BOOLEAN,\n content bytea);\n\nCREATE TABLE messages_merkles\n (id INTEGER PRIMARY KEY,\n merkle TEXT);\n";
|
|
5332
5332
|
//#endregion
|
|
5333
5333
|
//#region src/sync-simple.js
|
|
5334
|
+
var MAX_FUTURE_DRIFT_MS = 3e5;
|
|
5334
5335
|
function getGroupDb(groupId) {
|
|
5335
5336
|
const path = getPathForGroupFile(groupId);
|
|
5336
5337
|
const needsInit = !existsSync(path);
|
|
@@ -5348,7 +5349,12 @@ function addMessages(db, messages) {
|
|
|
5348
5349
|
msg.timestamp,
|
|
5349
5350
|
msg.isEncrypted ? 1 : 0,
|
|
5350
5351
|
Buffer.from(msg.content)
|
|
5351
|
-
]).changes > 0)
|
|
5352
|
+
]).changes > 0) {
|
|
5353
|
+
const timestamp = Timestamp.parse(msg.timestamp);
|
|
5354
|
+
const error = getTimestampError(timestamp);
|
|
5355
|
+
if (error) throw Object.assign(new Error(error), { rejectedReason: error });
|
|
5356
|
+
trie = insert(trie, timestamp);
|
|
5357
|
+
}
|
|
5352
5358
|
}
|
|
5353
5359
|
trie = prune(trie);
|
|
5354
5360
|
db.mutate("INSERT INTO messages_merkles (id, merkle) VALUES (1, ?) ON CONFLICT (id) DO UPDATE SET merkle = ?", [JSON.stringify(trie), JSON.stringify(trie)]);
|
|
@@ -5356,6 +5362,11 @@ function addMessages(db, messages) {
|
|
|
5356
5362
|
});
|
|
5357
5363
|
return returnValue;
|
|
5358
5364
|
}
|
|
5365
|
+
function getTimestampError(timestamp) {
|
|
5366
|
+
if (!timestamp) return "invalid-timestamp";
|
|
5367
|
+
if (timestamp.millis() - Date.now() > MAX_FUTURE_DRIFT_MS) return "clock-drift";
|
|
5368
|
+
return null;
|
|
5369
|
+
}
|
|
5359
5370
|
function getMerkle(db) {
|
|
5360
5371
|
const rows = db.all("SELECT * FROM messages_merkles");
|
|
5361
5372
|
if (rows.length > 0) return JSON.parse(rows[0].merkle);
|
|
@@ -5363,19 +5374,24 @@ function getMerkle(db) {
|
|
|
5363
5374
|
}
|
|
5364
5375
|
function sync(messages, since, groupId) {
|
|
5365
5376
|
const db = getGroupDb(groupId);
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
}
|
|
5378
|
-
}
|
|
5377
|
+
try {
|
|
5378
|
+
const newMessages = db.all(`SELECT * FROM messages_binary
|
|
5379
|
+
WHERE timestamp > ?
|
|
5380
|
+
ORDER BY timestamp`, [since]);
|
|
5381
|
+
return {
|
|
5382
|
+
trie: addMessages(db, messages),
|
|
5383
|
+
newMessages: newMessages.map((msg) => create(MessageEnvelopeSchema, {
|
|
5384
|
+
timestamp: msg.timestamp,
|
|
5385
|
+
isEncrypted: msg.is_encrypted === 1,
|
|
5386
|
+
content: msg.content
|
|
5387
|
+
}))
|
|
5388
|
+
};
|
|
5389
|
+
} catch (e) {
|
|
5390
|
+
if (e.rejectedReason) return { error: e.rejectedReason };
|
|
5391
|
+
throw e;
|
|
5392
|
+
} finally {
|
|
5393
|
+
db.close();
|
|
5394
|
+
}
|
|
5379
5395
|
}
|
|
5380
5396
|
//#endregion
|
|
5381
5397
|
//#region src/util/atomic-write.ts
|
|
@@ -5505,7 +5521,12 @@ app$1.post("/sync", async (req, res) => {
|
|
|
5505
5521
|
res.send(errorMessage);
|
|
5506
5522
|
return;
|
|
5507
5523
|
}
|
|
5508
|
-
const
|
|
5524
|
+
const result = sync(messages, since, groupId);
|
|
5525
|
+
if (result.error) {
|
|
5526
|
+
res.status(400).send(result.error);
|
|
5527
|
+
return;
|
|
5528
|
+
}
|
|
5529
|
+
const { trie, newMessages } = result;
|
|
5509
5530
|
const responsePb = create(SyncResponseSchema, {
|
|
5510
5531
|
merkle: JSON.stringify(trie),
|
|
5511
5532
|
messages: newMessages
|
|
@@ -5776,6 +5797,14 @@ app$1.post("/delete-user-file", (req, res) => {
|
|
|
5776
5797
|
res.send(OK_RESPONSE);
|
|
5777
5798
|
});
|
|
5778
5799
|
//#endregion
|
|
5800
|
+
//#region src/util/server-listen.ts
|
|
5801
|
+
function listen(server, port, hostname, onListening) {
|
|
5802
|
+
server.listen(port, hostname === "::" ? void 0 : hostname, () => {
|
|
5803
|
+
const address = server.address();
|
|
5804
|
+
onListening(address && typeof address === "object" ? address.address : hostname);
|
|
5805
|
+
});
|
|
5806
|
+
}
|
|
5807
|
+
//#endregion
|
|
5779
5808
|
//#region src/app.ts
|
|
5780
5809
|
var debugSensitive = createDebug("actual-sensitive:server");
|
|
5781
5810
|
var app = express();
|
|
@@ -5885,9 +5914,9 @@ function parseHTTPSConfig(value) {
|
|
|
5885
5914
|
if (value.startsWith("-----BEGIN")) return value.replace(/\\n/g, "\n");
|
|
5886
5915
|
return fs.readFileSync(value);
|
|
5887
5916
|
}
|
|
5888
|
-
function sendServerStartedMessage() {
|
|
5917
|
+
function sendServerStartedMessage(address) {
|
|
5889
5918
|
process.parentPort?.postMessage({ type: "server-started" });
|
|
5890
|
-
console.log("Listening on " +
|
|
5919
|
+
console.log("Listening on " + address + ":" + configSchema.get("port") + "...");
|
|
5891
5920
|
}
|
|
5892
5921
|
async function run() {
|
|
5893
5922
|
const portVal = configSchema.get("port");
|
|
@@ -5911,14 +5940,10 @@ async function run() {
|
|
|
5911
5940
|
key: parseHTTPSConfig(configSchema.get("https.key")),
|
|
5912
5941
|
cert: parseHTTPSConfig(configSchema.get("https.cert"))
|
|
5913
5942
|
};
|
|
5914
|
-
https.createServer(httpsOptions, app)
|
|
5915
|
-
|
|
5916
|
-
});
|
|
5917
|
-
} else app.listen(port, hostname, () => {
|
|
5918
|
-
sendServerStartedMessage();
|
|
5919
|
-
});
|
|
5943
|
+
listen(https.createServer(httpsOptions, app), port, hostname, sendServerStartedMessage);
|
|
5944
|
+
} else listen((await import("node:http")).createServer(app), port, hostname, sendServerStartedMessage);
|
|
5920
5945
|
}
|
|
5921
5946
|
//#endregion
|
|
5922
5947
|
export { run };
|
|
5923
5948
|
|
|
5924
|
-
//# sourceMappingURL=app-
|
|
5949
|
+
//# sourceMappingURL=app-DdHDpmcN.js.map
|