-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.js
More file actions
39 lines (34 loc) · 1.21 KB
/
example.js
File metadata and controls
39 lines (34 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
const bir = require('./index');
// Example usage:
// GUS_API_KEY="abcde12345abcde12345" nodejs test.js false regon "00033150100000"
// GUS_API_KEY="abcde12345abcde12345" nodejs test.js false nip "1181985157"
const main = async () => {
if (process.argv.length !== 5) {
console.log(`Usage: ${process.argv[0]} [production=true/false] [nip/regon] [value]`);
process.exit(2);
}
if (!process.env.GUS_API_KEY) {
console.log("Missing environment variable 'GUS_API_KEY'");
process.exit(3);
}
const production = process.argv[2] === 'true';
const type = process.argv[3].toLowerCase() === 'nip' ? 'nip' : 'regon';
const value = process.argv[4];
const client = bir(production);
console.log('SID: ', await client.login(process.env.GUS_API_KEY));
let entity;
if (type === 'nip') {
entity = await client.search_nip(value);
} else {
entity = await client.search_regon(value);
}
console.log('Search: ', entity);
if (entity) {
const report = await client.report(entity.regon14, entity.full_report);
console.log('Report: ', report);
}
};
main().catch(err => {
console.log('Something failed.', err);
});