ledgit-cli 0.3.0 → 0.4.0
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/index.js +53 -16
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -54944,7 +54944,7 @@ async function selectInboxProvider() {
|
|
|
54944
54944
|
message: "Select your inbox provider:",
|
|
54945
54945
|
choices: [
|
|
54946
54946
|
{
|
|
54947
|
-
name: "
|
|
54947
|
+
name: "Moatless inbox (email receipts to @inbox.moatless.ai)",
|
|
54948
54948
|
value: "ledgit"
|
|
54949
54949
|
},
|
|
54950
54950
|
{ name: "Bokio inbox", value: "bokio" }
|
|
@@ -54980,14 +54980,24 @@ async function connectLedgitInbox(options = {}) {
|
|
|
54980
54980
|
try {
|
|
54981
54981
|
const accessToken = await existingConfig.ledgit.getAccessToken();
|
|
54982
54982
|
if (accessToken) {
|
|
54983
|
-
console.log(" Already authenticated with
|
|
54984
|
-
|
|
54983
|
+
console.log(" Already authenticated with Moatless");
|
|
54984
|
+
let inboxEmail;
|
|
54985
|
+
try {
|
|
54986
|
+
const client2 = new LedgitClient({
|
|
54987
|
+
getAccessToken: async () => accessToken,
|
|
54988
|
+
silent: true
|
|
54989
|
+
});
|
|
54990
|
+
const companyInfo2 = await client2.getCompanyInfo();
|
|
54991
|
+
inboxEmail = companyInfo2.inboxEmail;
|
|
54992
|
+
} catch {
|
|
54993
|
+
}
|
|
54994
|
+
return { auth0Token: { access_token: accessToken, expires_in: 0, token_type: "Bearer" }, inboxEmail };
|
|
54985
54995
|
}
|
|
54986
54996
|
} catch {
|
|
54987
54997
|
}
|
|
54988
54998
|
}
|
|
54989
54999
|
console.log(`
|
|
54990
|
-
|
|
55000
|
+
Moatless inbox requires authentication via moatless.ai
|
|
54991
55001
|
`);
|
|
54992
55002
|
try {
|
|
54993
55003
|
const auth0Token = await authenticateAuth0({
|
|
@@ -55002,25 +55012,32 @@ async function connectLedgitInbox(options = {}) {
|
|
|
55002
55012
|
if (saveTokenTo) {
|
|
55003
55013
|
saveAuth0Token(auth0Token, false, saveTokenTo);
|
|
55004
55014
|
}
|
|
55015
|
+
const client2 = new LedgitClient({
|
|
55016
|
+
getAccessToken: async () => auth0Token.access_token,
|
|
55017
|
+
silent: true
|
|
55018
|
+
});
|
|
55005
55019
|
let inboxEmail;
|
|
55006
55020
|
if (companyInfo) {
|
|
55007
|
-
const
|
|
55008
|
-
getAccessToken: async () => auth0Token.access_token,
|
|
55009
|
-
silent: true
|
|
55010
|
-
});
|
|
55011
|
-
const registerSpinner = ora2("Registering company with Ledgit...").start();
|
|
55021
|
+
const registerSpinner = ora2("Registering company with Moatless...").start();
|
|
55012
55022
|
try {
|
|
55013
55023
|
const companyResult = await client2.createCompany({
|
|
55014
55024
|
name: companyInfo.name,
|
|
55015
55025
|
organizationNumber: companyInfo.organizationNumber ?? ""
|
|
55016
55026
|
});
|
|
55017
55027
|
inboxEmail = companyResult.inboxEmail;
|
|
55018
|
-
registerSpinner.succeed(`
|
|
55028
|
+
registerSpinner.succeed(`Registered with inbox: ${inboxEmail}`);
|
|
55019
55029
|
} catch (error) {
|
|
55020
55030
|
registerSpinner.fail("Failed to register company");
|
|
55021
55031
|
console.error(error instanceof Error ? error.message : "Unknown error");
|
|
55022
55032
|
}
|
|
55023
55033
|
}
|
|
55034
|
+
if (!inboxEmail) {
|
|
55035
|
+
try {
|
|
55036
|
+
const companyInfo2 = await client2.getCompanyInfo();
|
|
55037
|
+
inboxEmail = companyInfo2.inboxEmail;
|
|
55038
|
+
} catch {
|
|
55039
|
+
}
|
|
55040
|
+
}
|
|
55024
55041
|
return { auth0Token, inboxEmail };
|
|
55025
55042
|
} catch (error) {
|
|
55026
55043
|
console.error(`
|
|
@@ -55028,12 +55045,13 @@ async function connectLedgitInbox(options = {}) {
|
|
|
55028
55045
|
return null;
|
|
55029
55046
|
}
|
|
55030
55047
|
}
|
|
55031
|
-
async function setupInboxProvider(cwd, existingConfig) {
|
|
55048
|
+
async function setupInboxProvider(cwd, existingConfig, options) {
|
|
55032
55049
|
const inboxProvider = await selectInboxProvider();
|
|
55033
55050
|
if (inboxProvider === "ledgit") {
|
|
55034
55051
|
const result = await connectLedgitInbox({
|
|
55035
55052
|
saveTokenTo: cwd,
|
|
55036
|
-
existingConfig
|
|
55053
|
+
existingConfig,
|
|
55054
|
+
companyInfo: options?.companyInfo
|
|
55037
55055
|
});
|
|
55038
55056
|
if (!result) {
|
|
55039
55057
|
return null;
|
|
@@ -55089,12 +55107,22 @@ async function syncInboxCommand(options = {}) {
|
|
|
55089
55107
|
spinner.fail(error instanceof Error ? error.message : "Unknown error");
|
|
55090
55108
|
process.exit(1);
|
|
55091
55109
|
}
|
|
55092
|
-
let inboxProvider = config3.inboxProvider
|
|
55110
|
+
let inboxProvider = config3.inboxProvider;
|
|
55093
55111
|
if (!inboxProvider) {
|
|
55094
55112
|
console.log(source_default.yellow(`
|
|
55095
55113
|
No inbox provider configured.
|
|
55096
55114
|
`));
|
|
55097
|
-
|
|
55115
|
+
let companyInfo;
|
|
55116
|
+
if (config3.bokio) {
|
|
55117
|
+
const bokioClient = createBokioClient(config3);
|
|
55118
|
+
const info = await bokioClient.getCompanyInformation();
|
|
55119
|
+
companyInfo = { name: info.name, organizationNumber: info.organizationNumber ?? undefined };
|
|
55120
|
+
} else if (config3.ledgit) {
|
|
55121
|
+
const ledgitClient = createLedgitClient(config3);
|
|
55122
|
+
const info = await ledgitClient.getCompanyInfo();
|
|
55123
|
+
companyInfo = { name: info.name };
|
|
55124
|
+
}
|
|
55125
|
+
const result = await setupInboxProvider(cwd, config3, { companyInfo });
|
|
55098
55126
|
if (!result) {
|
|
55099
55127
|
console.log(source_default.red(` Failed to setup inbox provider.
|
|
55100
55128
|
`));
|
|
@@ -55103,8 +55131,13 @@ async function syncInboxCommand(options = {}) {
|
|
|
55103
55131
|
config3 = await loadConfig(cwd);
|
|
55104
55132
|
inboxProvider = result.inboxProvider;
|
|
55105
55133
|
console.log(source_default.green(`
|
|
55106
|
-
Inbox provider set to: ${inboxProvider}
|
|
55134
|
+
Inbox provider set to: ${inboxProvider}`));
|
|
55135
|
+
if (result.inboxEmail) {
|
|
55136
|
+
console.log(source_default.green(` Inbox email: ${result.inboxEmail}
|
|
55107
55137
|
`));
|
|
55138
|
+
} else {
|
|
55139
|
+
console.log();
|
|
55140
|
+
}
|
|
55108
55141
|
}
|
|
55109
55142
|
if (inboxProvider === "ledgit") {
|
|
55110
55143
|
await syncLedgitInbox(cwd, options);
|
|
@@ -55275,8 +55308,10 @@ async function syncLedgitInbox(cwd, options = {}) {
|
|
|
55275
55308
|
const config3 = await loadConfig(cwd);
|
|
55276
55309
|
const client2 = createLedgitClient(config3);
|
|
55277
55310
|
const validateSpinner = ora3("Connecting to Ledgit...").start();
|
|
55311
|
+
let inboxEmail;
|
|
55278
55312
|
try {
|
|
55279
55313
|
const companyInfo = await client2.getCompanyInfo();
|
|
55314
|
+
inboxEmail = companyInfo.inboxEmail;
|
|
55280
55315
|
validateSpinner.succeed(`Connected to: ${companyInfo.name}`);
|
|
55281
55316
|
} catch (error) {
|
|
55282
55317
|
validateSpinner.fail("Failed to connect to Ledgit");
|
|
@@ -55349,11 +55384,13 @@ async function syncLedgitInbox(cwd, options = {}) {
|
|
|
55349
55384
|
}
|
|
55350
55385
|
}
|
|
55351
55386
|
}
|
|
55387
|
+
const inboxEmailLine = inboxEmail ? `
|
|
55388
|
+
- Inbox: ${inboxEmail}` : "";
|
|
55352
55389
|
console.log(`
|
|
55353
55390
|
|
|
55354
55391
|
Sync complete!
|
|
55355
55392
|
- ${newCount} new inbox items downloaded
|
|
55356
|
-
- ${existingCount} already existed locally
|
|
55393
|
+
- ${existingCount} already existed locally${inboxEmailLine}
|
|
55357
55394
|
`);
|
|
55358
55395
|
}
|
|
55359
55396
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ledgit-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "CLI for ledgit bookkeeping repositories",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"@moatless/api-client": "^0.1.2",
|
|
26
26
|
"@moatless/bokio-client": "^0.1.2",
|
|
27
27
|
"@moatless/bookkeeping": "^0.2.0",
|
|
28
|
-
"@moatless/bookkeeping-types": "
|
|
28
|
+
"@moatless/bookkeeping-types": "^0.2.0",
|
|
29
29
|
"@moatless/fortnox-client": "^0.1.2",
|
|
30
|
-
"@moatless/ledgit-client": "
|
|
30
|
+
"@moatless/ledgit-client": "^0.2.0",
|
|
31
31
|
"@moatless/riksbank-client": "^0.1.2",
|
|
32
32
|
"@moatless/telemetry": "^0.1.2",
|
|
33
33
|
"chalk": "^5.6.2",
|