openkbs 0.0.52 → 0.0.53
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/README.md +16 -0
- package/package.json +1 -1
- package/src/actions.js +63 -13
- package/src/index.js +22 -2
- package/src/utils.js +1 -1
- package/version.json +3 -3
package/README.md
CHANGED
|
@@ -374,6 +374,18 @@ export const getActions = (meta) => [
|
|
|
374
374
|
});
|
|
375
375
|
return { data: response, ...meta };
|
|
376
376
|
}],
|
|
377
|
+
|
|
378
|
+
// example: checkVAT("BG123456789")
|
|
379
|
+
[/\/?checkVAT\("(.*)"\)/, async (match) => {
|
|
380
|
+
let response = await openkbs.checkVAT(match[1]);
|
|
381
|
+
return { data: response, ...meta };
|
|
382
|
+
}],
|
|
383
|
+
|
|
384
|
+
// example: getExchangeRates("USD", "EUR,GBP")
|
|
385
|
+
[/\/?getExchangeRates\("(.*)"\s*,\s*"(.*)"\)/, async (match) => {
|
|
386
|
+
let response = await openkbs.getExchangeRates(match[1], match[2]);
|
|
387
|
+
return { data: response, ...meta };
|
|
388
|
+
}],
|
|
377
389
|
];
|
|
378
390
|
```
|
|
379
391
|
|
|
@@ -600,6 +612,10 @@ The `openkbs` object provides a set of utility functions and services to interac
|
|
|
600
612
|
|
|
601
613
|
* **`openkbs.sendMail(email, subject, content)`:** Sends an email to the specified recipient
|
|
602
614
|
|
|
615
|
+
* **`openkbs.checkVAT(vatNumber)`:** Validates a VAT number against official databases
|
|
616
|
+
|
|
617
|
+
* **`openkbs.getExchangeRates(base, symbols)`:** Retrieves current exchange rates
|
|
618
|
+
|
|
603
619
|
* **`openkbs.documentToText(documentURL, params)`:** Extracts text from various document formats.
|
|
604
620
|
|
|
605
621
|
* **`openkbs.imageToText(imageUrl, params)`:** Extracts text from an image.
|
package/package.json
CHANGED
package/src/actions.js
CHANGED
|
@@ -10,7 +10,7 @@ const {
|
|
|
10
10
|
fetchAndSaveSettings, downloadFiles, downloadIcon, updateKB, uploadFiles, generateKey, generateMnemonic,
|
|
11
11
|
reset, bold, red, yellow, green, createKB, saveLocalKBData, listKBs, deleteKBFile,
|
|
12
12
|
deleteKB, buildPackage, replacePlaceholderInFiles, buildNodePackage, initByTemplateAction, modifyKB,
|
|
13
|
-
listKBsSharedWithMe, downloadTemplates
|
|
13
|
+
listKBsSharedWithMe, downloadTemplates, KB_API_URL, makePostRequest
|
|
14
14
|
} = require("./utils");
|
|
15
15
|
|
|
16
16
|
const TEMPLATE_DIR = path.join(os.homedir(), '.openkbs', 'templates');
|
|
@@ -618,18 +618,18 @@ async function updateCliAction() {
|
|
|
618
618
|
try {
|
|
619
619
|
const packageJson = require('../package.json');
|
|
620
620
|
const currentVersion = packageJson.version;
|
|
621
|
-
|
|
621
|
+
|
|
622
622
|
console.log(`Current OpenKBS CLI version: ${currentVersion}`);
|
|
623
623
|
console.log('Checking for updates...');
|
|
624
|
-
|
|
624
|
+
|
|
625
625
|
// Check remote version from S3
|
|
626
626
|
const https = require('https');
|
|
627
627
|
const bucket = 'openkbs-downloads';
|
|
628
628
|
const versionMetadataKey = 'cli/version.json';
|
|
629
|
-
|
|
629
|
+
|
|
630
630
|
let remoteVersionData = null;
|
|
631
631
|
let cliUpdateAvailable = false;
|
|
632
|
-
|
|
632
|
+
|
|
633
633
|
try {
|
|
634
634
|
const fileUrl = `https://${bucket}.s3.amazonaws.com/${versionMetadataKey}`;
|
|
635
635
|
const remoteVersionContent = await new Promise((resolve, reject) => {
|
|
@@ -643,25 +643,25 @@ async function updateCliAction() {
|
|
|
643
643
|
res.on('end', () => resolve(data));
|
|
644
644
|
}).on('error', reject);
|
|
645
645
|
});
|
|
646
|
-
|
|
646
|
+
|
|
647
647
|
remoteVersionData = JSON.parse(remoteVersionContent);
|
|
648
648
|
const remoteVersion = remoteVersionData.version;
|
|
649
|
-
|
|
649
|
+
|
|
650
650
|
// Compare versions using semantic versioning
|
|
651
651
|
if (compareVersions(currentVersion, remoteVersion) < 0) {
|
|
652
652
|
cliUpdateAvailable = true;
|
|
653
653
|
console.log(`New CLI version available: ${remoteVersion}`);
|
|
654
654
|
console.log('Updating automatically...');
|
|
655
|
-
|
|
655
|
+
|
|
656
656
|
// Spawn npm update as detached child process
|
|
657
657
|
const { spawn } = require('child_process');
|
|
658
658
|
const updateProcess = spawn('npm', ['update', '-g', 'openkbs'], {
|
|
659
659
|
detached: true,
|
|
660
660
|
stdio: 'inherit'
|
|
661
661
|
});
|
|
662
|
-
|
|
662
|
+
|
|
663
663
|
updateProcess.unref(); // Allow parent to exit
|
|
664
|
-
|
|
664
|
+
|
|
665
665
|
console.green(`Update started! OpenKBS CLI will be updated to version ${remoteVersion}.`);
|
|
666
666
|
console.log('The update will complete in the background.');
|
|
667
667
|
} else {
|
|
@@ -670,15 +670,63 @@ async function updateCliAction() {
|
|
|
670
670
|
} catch (error) {
|
|
671
671
|
console.red('Error fetching CLI version metadata:', error.message);
|
|
672
672
|
}
|
|
673
|
-
|
|
673
|
+
|
|
674
674
|
// Also update knowledge base silently if it exists
|
|
675
675
|
await updateKnowledgeAction(true);
|
|
676
|
-
|
|
676
|
+
|
|
677
677
|
} catch (error) {
|
|
678
678
|
console.red('Error updating CLI:', error.message);
|
|
679
679
|
}
|
|
680
680
|
}
|
|
681
681
|
|
|
682
|
+
async function publishAction(domain) {
|
|
683
|
+
try {
|
|
684
|
+
const localKBData = await fetchLocalKBData();
|
|
685
|
+
const { kbId } = localKBData;
|
|
686
|
+
if (!kbId) return console.red('No KB found. Please push the KB first using the command "openkbs push".');
|
|
687
|
+
|
|
688
|
+
console.log(`Publishing KB ${kbId} to domain ${domain}...`);
|
|
689
|
+
const res = await fetchKBJWT(kbId);
|
|
690
|
+
|
|
691
|
+
if (!res?.kbToken) return console.red(`KB ${kbId} does not exist on the remote service`);
|
|
692
|
+
|
|
693
|
+
const response = await makePostRequest(KB_API_URL, {
|
|
694
|
+
token: res.kbToken,
|
|
695
|
+
action: 'publish',
|
|
696
|
+
domain: domain
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
console.green(`KB ${kbId} successfully published to ${domain}`);
|
|
700
|
+
return response;
|
|
701
|
+
} catch (error) {
|
|
702
|
+
console.red('Error during publish operation:', error.message);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
async function unpublishAction(domain) {
|
|
707
|
+
try {
|
|
708
|
+
const localKBData = await fetchLocalKBData();
|
|
709
|
+
const { kbId } = localKBData;
|
|
710
|
+
if (!kbId) return console.red('No KB found. Please push the KB first using the command "openkbs push".');
|
|
711
|
+
|
|
712
|
+
console.log(`Unpublishing KB ${kbId} from domain ${domain}...`);
|
|
713
|
+
const res = await fetchKBJWT(kbId);
|
|
714
|
+
|
|
715
|
+
if (!res?.kbToken) return console.red(`KB ${kbId} does not exist on the remote service`);
|
|
716
|
+
|
|
717
|
+
const response = await makePostRequest(KB_API_URL, {
|
|
718
|
+
token: res.kbToken,
|
|
719
|
+
action: 'unpublish',
|
|
720
|
+
domain: domain
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
console.green(`KB ${kbId} successfully unpublished from ${domain}`);
|
|
724
|
+
return response;
|
|
725
|
+
} catch (error) {
|
|
726
|
+
console.red('Error during unpublish operation:', error.message);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
682
730
|
function compareVersions(version1, version2) {
|
|
683
731
|
const parts1 = version1.split('.').map(Number);
|
|
684
732
|
const parts2 = version2.split('.').map(Number);
|
|
@@ -807,5 +855,7 @@ module.exports = {
|
|
|
807
855
|
modifyAction,
|
|
808
856
|
downloadModifyAction,
|
|
809
857
|
updateKnowledgeAction,
|
|
810
|
-
updateCliAction
|
|
858
|
+
updateCliAction,
|
|
859
|
+
publishAction,
|
|
860
|
+
unpublishAction
|
|
811
861
|
};
|
package/src/index.js
CHANGED
|
@@ -13,7 +13,7 @@ const {
|
|
|
13
13
|
deleteFileAction,
|
|
14
14
|
describeAction, deployAction, createByTemplateAction, initByTemplateAction,
|
|
15
15
|
logoutAction, installFrontendPackageAction, modifyAction, downloadModifyAction,
|
|
16
|
-
updateKnowledgeAction, updateCliAction
|
|
16
|
+
updateKnowledgeAction, updateCliAction, publishAction, unpublishAction
|
|
17
17
|
} = require('./actions');
|
|
18
18
|
|
|
19
19
|
|
|
@@ -171,10 +171,30 @@ program
|
|
|
171
171
|
Examples:
|
|
172
172
|
$ openkbs update
|
|
173
173
|
This will check for CLI updates and install them if available.
|
|
174
|
-
|
|
174
|
+
|
|
175
175
|
$ openkbs update knowledge
|
|
176
176
|
This will check if your local .openkbs/knowledge directory is up to date with the remote repository
|
|
177
177
|
and update it if necessary.
|
|
178
178
|
`);
|
|
179
179
|
|
|
180
|
+
program
|
|
181
|
+
.command('publish <domain>')
|
|
182
|
+
.description('Publish KB to a custom domain')
|
|
183
|
+
.action(publishAction)
|
|
184
|
+
.addHelpText('after', `
|
|
185
|
+
Examples:
|
|
186
|
+
$ openkbs publish example.com
|
|
187
|
+
This will publish your KB to the domain example.com
|
|
188
|
+
`);
|
|
189
|
+
|
|
190
|
+
program
|
|
191
|
+
.command('unpublish <domain>')
|
|
192
|
+
.description('Unpublish KB from a custom domain')
|
|
193
|
+
.action(unpublishAction)
|
|
194
|
+
.addHelpText('after', `
|
|
195
|
+
Examples:
|
|
196
|
+
$ openkbs unpublish example.com
|
|
197
|
+
This will unpublish your KB from the domain example.com
|
|
198
|
+
`);
|
|
199
|
+
|
|
180
200
|
program.parse(process.argv);
|
package/src/utils.js
CHANGED
|
@@ -1167,5 +1167,5 @@ module.exports = {
|
|
|
1167
1167
|
listFiles, getUserProfile, getKB, fetchAndSaveSettings, downloadIcon, downloadFiles, updateKB, uploadFiles, generateKey,
|
|
1168
1168
|
generateMnemonic, reset, bold, red, yellow, green, cyan, createKB, getClientJWT, saveLocalKBData, listKBs, deleteKBFile,
|
|
1169
1169
|
deleteKB, buildPackage, replacePlaceholderInFiles, buildNodePackage, initByTemplateAction, modifyKB, listKBsSharedWithMe,
|
|
1170
|
-
downloadTemplates
|
|
1170
|
+
downloadTemplates, makePostRequest
|
|
1171
1171
|
}
|
package/version.json
CHANGED