kvitton-cli 0.4.2
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/commands/company-info.js +48 -0
- package/dist/commands/convert-currency.js +76 -0
- package/dist/commands/create-entry.js +198 -0
- package/dist/commands/generate-lines.js +140 -0
- package/dist/commands/parse-pdf.js +20 -0
- package/dist/commands/sync-inbox.js +186 -0
- package/dist/commands/sync-journal.js +490 -0
- package/dist/index.js +7394 -0
- package/dist/lib/client.js +10 -0
- package/dist/lib/currency-cache.js +49 -0
- package/dist/lib/env.js +37 -0
- package/package.json +40 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BokioClient } from "integrations-bokio";
|
|
2
|
+
export function createBokioClient(config) {
|
|
3
|
+
if (config.provider !== "bokio" || !config.bokio) {
|
|
4
|
+
throw new Error("Bokio configuration not found");
|
|
5
|
+
}
|
|
6
|
+
return new BokioClient({
|
|
7
|
+
token: config.bokio.token,
|
|
8
|
+
companyId: config.bokio.companyId,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
const CACHE_DIR = ".kvitton/cache";
|
|
4
|
+
const CACHE_FILE = "currency-rates.json";
|
|
5
|
+
function getCachePath(cwd) {
|
|
6
|
+
return join(cwd, CACHE_DIR, CACHE_FILE);
|
|
7
|
+
}
|
|
8
|
+
function ensureCacheDir(cwd) {
|
|
9
|
+
const dir = join(cwd, CACHE_DIR);
|
|
10
|
+
if (!existsSync(dir)) {
|
|
11
|
+
mkdirSync(dir, { recursive: true });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function readCache(cwd) {
|
|
15
|
+
const path = getCachePath(cwd);
|
|
16
|
+
if (!existsSync(path)) {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const content = readFileSync(path, "utf-8");
|
|
21
|
+
return JSON.parse(content);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function writeCache(cwd, data) {
|
|
28
|
+
ensureCacheDir(cwd);
|
|
29
|
+
const path = getCachePath(cwd);
|
|
30
|
+
writeFileSync(path, JSON.stringify(data, null, 2));
|
|
31
|
+
}
|
|
32
|
+
function makeCacheKey(currency, date) {
|
|
33
|
+
return `${currency.toUpperCase()}_${date}`;
|
|
34
|
+
}
|
|
35
|
+
export function getCachedRate(cwd, currency, date) {
|
|
36
|
+
const cache = readCache(cwd);
|
|
37
|
+
const key = makeCacheKey(currency, date);
|
|
38
|
+
return cache[key] ?? null;
|
|
39
|
+
}
|
|
40
|
+
export function setCachedRate(cwd, currency, date, rate, rateDate) {
|
|
41
|
+
const cache = readCache(cwd);
|
|
42
|
+
const key = makeCacheKey(currency, date);
|
|
43
|
+
cache[key] = {
|
|
44
|
+
rate,
|
|
45
|
+
rateDate,
|
|
46
|
+
cachedAt: new Date().toISOString(),
|
|
47
|
+
};
|
|
48
|
+
writeCache(cwd, cache);
|
|
49
|
+
}
|
package/dist/lib/env.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { config } from "dotenv";
|
|
4
|
+
export function loadConfig(cwd = process.cwd()) {
|
|
5
|
+
const envPath = path.join(cwd, ".env");
|
|
6
|
+
if (!fs.existsSync(envPath)) {
|
|
7
|
+
throw new Error("No .env file found. Run this command from a kvitton repository.");
|
|
8
|
+
}
|
|
9
|
+
// Load .env file
|
|
10
|
+
const result = config({ path: envPath });
|
|
11
|
+
if (result.error) {
|
|
12
|
+
throw new Error(`Failed to parse .env file: ${result.error.message}`);
|
|
13
|
+
}
|
|
14
|
+
const provider = process.env.PROVIDER;
|
|
15
|
+
if (!provider) {
|
|
16
|
+
throw new Error("PROVIDER not set in .env file");
|
|
17
|
+
}
|
|
18
|
+
if (provider !== "bokio" && provider !== "fortnox") {
|
|
19
|
+
throw new Error(`Unknown provider: ${provider}. Supported: bokio, fortnox`);
|
|
20
|
+
}
|
|
21
|
+
if (provider === "bokio") {
|
|
22
|
+
const token = process.env.BOKIO_TOKEN;
|
|
23
|
+
const companyId = process.env.BOKIO_COMPANY_ID;
|
|
24
|
+
if (!token) {
|
|
25
|
+
throw new Error("BOKIO_TOKEN not set in .env file");
|
|
26
|
+
}
|
|
27
|
+
if (!companyId) {
|
|
28
|
+
throw new Error("BOKIO_COMPANY_ID not set in .env file");
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
provider: "bokio",
|
|
32
|
+
bokio: { token, companyId },
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// Fortnox support would go here
|
|
36
|
+
throw new Error("Fortnox is not yet supported");
|
|
37
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kvitton-cli",
|
|
3
|
+
"version": "0.4.2",
|
|
4
|
+
"description": "CLI for kvitton bookkeeping repositories",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"kvitton": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": ["dist"],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "bun scripts/build.ts",
|
|
12
|
+
"dev": "tsc --watch",
|
|
13
|
+
"type-check": "tsc --noEmit"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@supabase/supabase-js": "^2.49.1",
|
|
17
|
+
"commander": "^12.1.0",
|
|
18
|
+
"dotenv": "^16.0.0",
|
|
19
|
+
"ora": "^8.1.1",
|
|
20
|
+
"pdf-parse": "^1.1.1",
|
|
21
|
+
"simple-git": "^3.22.0",
|
|
22
|
+
"yaml": "^2.8.2",
|
|
23
|
+
"zod": "^3.24.1"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/bun": "latest",
|
|
27
|
+
"@types/pdf-parse": "^1.1.5",
|
|
28
|
+
"typescript": "^5.0.0",
|
|
29
|
+
"integrations-bokio": "workspace:*",
|
|
30
|
+
"integrations-riksbank": "workspace:*",
|
|
31
|
+
"shared": "workspace:*",
|
|
32
|
+
"sync": "workspace:*"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=18"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
}
|
|
40
|
+
}
|