bkper 2.7.2 → 3.0.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.
Files changed (41) hide show
  1. package/README.md +8 -8
  2. package/bun.lockb +0 -0
  3. package/package.json +9 -32
  4. package/src/auth/keys.json +12 -0
  5. package/src/auth/local-auth-service.ts +73 -0
  6. package/src/cli.ts +57 -0
  7. package/tsconfig.json +25 -0
  8. package/lib/auth/keys.json +0 -12
  9. package/lib/auth/local-auth-service.js +0 -80
  10. package/lib/cli.js +0 -64
  11. package/lib/index.d.ts +0 -1775
  12. package/lib/index.js +0 -42
  13. package/lib/model/Account.js +0 -381
  14. package/lib/model/Amount.js +0 -295
  15. package/lib/model/App.js +0 -95
  16. package/lib/model/Bkper.js +0 -101
  17. package/lib/model/Book.js +0 -713
  18. package/lib/model/Collection.js +0 -43
  19. package/lib/model/Config.js +0 -3
  20. package/lib/model/Connection.js +0 -257
  21. package/lib/model/Enums.js +0 -138
  22. package/lib/model/File.js +0 -124
  23. package/lib/model/Group.js +0 -244
  24. package/lib/model/Integration.js +0 -112
  25. package/lib/model/Transaction.js +0 -715
  26. package/lib/model/TransactionIterator.js +0 -154
  27. package/lib/model/TransactionPage.js +0 -93
  28. package/lib/model/User.js +0 -93
  29. package/lib/service/account-service.js +0 -43
  30. package/lib/service/app-service.js +0 -35
  31. package/lib/service/balances-service.js +0 -21
  32. package/lib/service/book-service.js +0 -37
  33. package/lib/service/connection-service.js +0 -72
  34. package/lib/service/file-service.js +0 -28
  35. package/lib/service/group-service.js +0 -72
  36. package/lib/service/http-api-request.js +0 -169
  37. package/lib/service/integration-service.js +0 -53
  38. package/lib/service/transaction-service.js +0 -115
  39. package/lib/service/user-service.js +0 -21
  40. package/lib/tsdoc-metadata.json +0 -11
  41. package/lib/utils.js +0 -341
package/README.md CHANGED
@@ -1,21 +1,21 @@
1
1
  [Bkper REST API]: https://bkper.com/docs/#rest-apis
2
2
 
3
- [![npm](https://img.shields.io/npm/v/bkper?color=%235889e4)](https://www.npmjs.com/package/bkper)
4
-
5
- Bkper Node.js client provides a simple and secure way to access the [Bkper REST API] on [Node.js](https://nodejs.dev/)
6
-
7
- It also provide a **command line** utility to create and update [Bkper Apps and Bots](https://bkper.com/docs/)
3
+ A **command line** utility to create and update [Bkper Apps and Bots](https://bkper.com/docs/)
8
4
 
9
5
  ## Instalation
10
6
 
11
7
  ### Add the package:
12
8
 
13
9
  ```
14
- npm i -S bkper
10
+ npm i bkper --save-dev
11
+ ```
12
+ or
13
+ ```
14
+ yarn add bkper --dev
15
15
  ```
16
16
  or
17
17
  ```
18
- yarn add bkper
18
+ bun add bkper --dev
19
19
  ```
20
20
 
21
21
  ## Commands
@@ -34,7 +34,7 @@ yarn bkper login
34
34
  ```
35
35
 
36
36
  ### Environment Variables
37
- The following environment variable is necessary in order to communicate with the Bkper REST API:
37
+ The following environment variable is necessary in order to communicate with the [Bkper REST API]:
38
38
 
39
39
  ```
40
40
  BKPER_API_KEY=XXXX
package/bun.lockb ADDED
Binary file
package/package.json CHANGED
@@ -1,12 +1,7 @@
1
1
  {
2
2
  "name": "bkper",
3
- "version": "2.7.2",
4
- "description": "Node.js client for Bkper REST API",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
7
- "files": [
8
- "lib/**/*"
9
- ],
3
+ "version": "3.0.0",
4
+ "description": "Node.js command line client for Bkper",
10
5
  "bin": {
11
6
  "bkper": "./lib/cli.js"
12
7
  },
@@ -16,18 +11,13 @@
16
11
  "license": "Apache-2.0",
17
12
  "private": false,
18
13
  "scripts": {
19
- "test": "env TS_NODE_COMPILER_OPTIONS='{\"rootDir\": \".\" }' mocha -r ts-node/register 'test/**/*.ts'",
20
- "clean": "gts clean",
14
+ "clean": "rm -rf ./lib & rm -rf ./node_modules & wait",
21
15
  "build": "run-s build:*",
22
- "build:clean": "bun clean",
23
- "build:test": "bun run test",
16
+ "build:clean": "gts clean",
24
17
  "build:compile": "tsc",
25
- "build:api": "api-extractor run --local",
26
18
  "build:cleanup": "rimraf lib/**/*.map lib/*.map lib/**/*.d.ts lib/*.d.ts",
27
- "build:dts": "cp dist/bkper-public.d.ts lib/index.d.ts",
28
19
  "build:clean-dist": "rimraf dist",
29
20
  "watch": "tsc -w",
30
- "upgrade:api": "bun upgrade @bkper/bkper-api-types --latest",
31
21
  "patch": "yarn version --patch",
32
22
  "minor": "yarn version --minor",
33
23
  "major": "yarn version --major",
@@ -35,32 +25,19 @@
35
25
  "postversion": "git push --tags && yarn publish --new-version $npm_package_version && git push && echo \"Successfully released version $npm_package_version!\""
36
26
  },
37
27
  "dependencies": {
38
- "@google-cloud/local-auth": "^1.0.0",
39
- "big.js": "^6.0.3",
28
+ "@google-cloud/local-auth": "^3.0.1",
29
+ "bkper-js": "^1.0.0",
40
30
  "commander": "^6.2.1",
41
- "dayjs": "^1.10.3",
42
31
  "dotenv": "^8.2.0",
43
- "gaxios": "^4.3.0",
44
- "google-auth-library": "^6.1.4",
45
- "luxon": "^1.25.0",
46
- "open": "^7.3.1"
32
+ "google-auth-library": "^9.14.0"
47
33
  },
48
34
  "devDependencies": {
49
35
  "@bkper/bkper-api-types": "^5.9.0",
50
- "@microsoft/api-extractor": "^7.12.1",
51
- "@types/big.js": "^6.0.2",
52
- "@types/chai": "^4.2.14",
53
36
  "@types/commander": "^2.12.2",
54
- "@types/luxon": "^1.25.1",
55
- "@types/mocha": "^8.2.0",
56
- "@types/node": "^14.14.20",
57
- "@types/node-fetch": "^2.5.8",
58
- "chai": "^4.2.0",
37
+ "@types/node": "^22.5.1",
59
38
  "gts": "^3.0.3",
60
- "mocha": "^8.2.1",
61
39
  "npm-run-all": "^4.1.5",
62
40
  "rimraf": "^3.0.2",
63
- "ts-node": "^9.1.1",
64
- "typescript": "^4.1.3"
41
+ "typescript": "^5.5.4"
65
42
  }
66
43
  }
@@ -0,0 +1,12 @@
1
+ {
2
+ "installed": {
3
+ "client_id": "360398463400-l3sfmb1tipagc7bfh4tf2eptu1b62g7c.apps.googleusercontent.com",
4
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
5
+ "token_uri": "https://oauth2.googleapis.com/token",
6
+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
7
+ "client_secret": "iQ87o7Y9xks1T0tKC7qmhnPw",
8
+ "redirect_uris": [
9
+ "http://localhost:3000/oauth2callback"
10
+ ]
11
+ }
12
+ }
@@ -0,0 +1,73 @@
1
+ import {authenticate} from '@google-cloud/local-auth';
2
+ import fs from 'fs';
3
+ import { Credentials, OAuth2Client } from "google-auth-library";
4
+ import os from 'os';
5
+
6
+ const keys = require(`${__dirname}/keys.json`);
7
+
8
+ let storedCredentials: Credentials;
9
+
10
+ const storedCredentialsPath = `${os.homedir}/.bkper-credentials.json`;
11
+
12
+ try {
13
+ let credentialsJson = fs.readFileSync(storedCredentialsPath, 'utf8');
14
+ storedCredentials = JSON.parse(credentialsJson);
15
+ } catch (err) {
16
+ console.log('No local credentials found.');
17
+ }
18
+
19
+ export async function login() {
20
+ if (storedCredentials) {
21
+ console.log('Bkper already logged in.');
22
+ }
23
+ await getOAuthToken();
24
+ }
25
+
26
+ export function logout() {
27
+ if (fs.existsSync(storedCredentialsPath)) {
28
+ fs.rmSync(storedCredentialsPath);
29
+ }
30
+ console.log('Bkper logged out.');
31
+ }
32
+
33
+ export function isLoggedIn() {
34
+ return storedCredentials != null;
35
+ }
36
+
37
+ export async function getOAuthToken(): Promise<string> {
38
+
39
+ let localAuth: OAuth2Client
40
+
41
+ if (storedCredentials) {
42
+ localAuth = new OAuth2Client(
43
+ keys.installed.client_id,
44
+ keys.installed.client_secret,
45
+ keys.installed.redirect_uris[0]
46
+ );
47
+ localAuth.setCredentials(storedCredentials);
48
+ } else {
49
+ localAuth = await authenticate({
50
+ scopes: ['https://www.googleapis.com/auth/userinfo.email'],
51
+ keyfilePath: `${__dirname}/keys.json`,
52
+ });
53
+ storeCredentials(localAuth.credentials);
54
+ }
55
+
56
+ localAuth.on('tokens', (tokens) => {
57
+ if (tokens.refresh_token) {
58
+ // store the refresh_token in my database!
59
+ console.log(tokens.refresh_token);
60
+ storeCredentials(tokens)
61
+ }
62
+ });
63
+
64
+ let token = await localAuth.getAccessToken();
65
+
66
+ return token.token;
67
+
68
+ }
69
+
70
+ function storeCredentials(credentials: Credentials) {
71
+ storedCredentials = credentials;
72
+ fs.writeFileSync(storedCredentialsPath, JSON.stringify(credentials, null, 4), 'utf8');
73
+ }
package/src/cli.ts ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env node
2
+
3
+ import program from 'commander';
4
+ import { getOAuthToken, login, logout } from './auth/local-auth-service';
5
+ import { App, Bkper } from 'bkper-js';
6
+ var fs = require('fs');
7
+ require('dotenv').config();
8
+
9
+
10
+ program
11
+ .command('login')
12
+ .description('Login Bkper')
13
+ .action(async () => {
14
+ await login()
15
+ });
16
+
17
+ program
18
+ .command('logout')
19
+ .description('Logout Bkper')
20
+ .action((todo) => {
21
+ logout()
22
+ });
23
+
24
+ program
25
+ .command('app')
26
+ .description('Create/Update an App')
27
+ .option('-u, --update', 'Update the App')
28
+ .option('-c, --create', 'Create a new App')
29
+ .action(async (options) => {
30
+
31
+ try {
32
+ Bkper.setConfig({
33
+ apiKeyProvider: async () => process.env.BKPER_API_KEY,
34
+ oauthTokenProvider: () => getOAuthToken()
35
+ })
36
+ const json: bkper.App = JSON.parse(fs.readFileSync('./bkperapp.json', 'utf8'));
37
+ let app = new App(json)
38
+ .setReadme(fs.readFileSync('./README.md', 'utf8'))
39
+ .setClientSecret(process.env.BKPER_CLIENT_SECRET)
40
+ .setDeveloperEmail(process.env.BKPER_DEVELOPER_EMAIL)
41
+ .setUserEmails(process.env.BKPER_USER_EMAILS);
42
+ if (options.update) {
43
+ app = await app.update();
44
+ console.log(`Updated ${app.getId()} sucessfully.`)
45
+ } else if (options.create) {
46
+ app = await app.create();
47
+ console.log(`Created ${app.getId()} sucessfully.`)
48
+
49
+ }
50
+ } catch (err) {
51
+ console.log(err)
52
+ }
53
+
54
+ });
55
+
56
+
57
+ program.parse(process.argv);
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "extends": "./node_modules/gts/tsconfig-google.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "lib",
6
+ "typeRoots" : ["node_modules/@bkper", "node_modules/@types" ],
7
+ "strict": false,
8
+ "esModuleInterop": true,
9
+ "target": "es2015",
10
+ "resolveJsonModule": true,
11
+ "declaration": true,
12
+ "sourceMap": true,
13
+ "declarationMap": true
14
+ },
15
+ "include": [
16
+ "src/**/*.json",
17
+ "src/**/*.ts",
18
+ "test/**/*.ts"
19
+ ],
20
+ "exclude": [
21
+ "./test/",
22
+ "./node_modules/",
23
+ "./lib/"
24
+ ]
25
+ }
@@ -1,12 +0,0 @@
1
- {
2
- "installed": {
3
- "client_id": "360398463400-l3sfmb1tipagc7bfh4tf2eptu1b62g7c.apps.googleusercontent.com",
4
- "auth_uri": "https://accounts.google.com/o/oauth2/auth",
5
- "token_uri": "https://oauth2.googleapis.com/token",
6
- "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
7
- "client_secret": "iQ87o7Y9xks1T0tKC7qmhnPw",
8
- "redirect_uris": [
9
- "http://localhost:3000/oauth2callback"
10
- ]
11
- }
12
- }
@@ -1,80 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getOAuthToken = exports.isLoggedIn = exports.logout = exports.login = void 0;
16
- const local_auth_1 = require("@google-cloud/local-auth");
17
- const fs_1 = __importDefault(require("fs"));
18
- const google_auth_library_1 = require("google-auth-library");
19
- const os_1 = __importDefault(require("os"));
20
- const keys = require(`${__dirname}/keys.json`);
21
- let storedCredentials;
22
- const storedCredentialsPath = `${os_1.default.homedir}/.bkper-credentials.json`;
23
- try {
24
- let credentialsJson = fs_1.default.readFileSync(storedCredentialsPath, 'utf8');
25
- storedCredentials = JSON.parse(credentialsJson);
26
- }
27
- catch (err) {
28
- console.log('No local credentials found.');
29
- }
30
- function login() {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- if (storedCredentials) {
33
- console.log('Bkper already logged in.');
34
- }
35
- yield getOAuthToken();
36
- });
37
- }
38
- exports.login = login;
39
- function logout() {
40
- if (fs_1.default.existsSync(storedCredentialsPath)) {
41
- fs_1.default.unlinkSync(storedCredentialsPath);
42
- }
43
- console.log('Bkper logged out.');
44
- }
45
- exports.logout = logout;
46
- function isLoggedIn() {
47
- return storedCredentials != null;
48
- }
49
- exports.isLoggedIn = isLoggedIn;
50
- function getOAuthToken() {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- let localAuth;
53
- if (storedCredentials) {
54
- localAuth = new google_auth_library_1.OAuth2Client(keys.installed.client_id, keys.installed.client_secret, keys.installed.redirect_uris[0]);
55
- localAuth.setCredentials(storedCredentials);
56
- }
57
- else {
58
- localAuth = yield local_auth_1.authenticate({
59
- scopes: ['https://www.googleapis.com/auth/userinfo.email'],
60
- keyfilePath: `${__dirname}/keys.json`,
61
- });
62
- storeCredentials(localAuth.credentials);
63
- }
64
- localAuth.on('tokens', (tokens) => {
65
- if (tokens.refresh_token) {
66
- // store the refresh_token in my database!
67
- console.log(tokens.refresh_token);
68
- storeCredentials(tokens);
69
- }
70
- });
71
- let token = yield localAuth.getAccessToken();
72
- return token.token;
73
- });
74
- }
75
- exports.getOAuthToken = getOAuthToken;
76
- function storeCredentials(credentials) {
77
- storedCredentials = credentials;
78
- fs_1.default.writeFileSync(storedCredentialsPath, JSON.stringify(credentials, null, 4), 'utf8');
79
- }
80
- //# sourceMappingURL=local-auth-service.js.map
package/lib/cli.js DELETED
@@ -1,64 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
- return new (P || (P = Promise))(function (resolve, reject) {
6
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
- step((generator = generator.apply(thisArg, _arguments || [])).next());
10
- });
11
- };
12
- var __importDefault = (this && this.__importDefault) || function (mod) {
13
- return (mod && mod.__esModule) ? mod : { "default": mod };
14
- };
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- const commander_1 = __importDefault(require("commander"));
17
- const local_auth_service_1 = require("./auth/local-auth-service");
18
- const Bkper_1 = require("./model/Bkper");
19
- const utils_1 = require("./utils");
20
- const App_1 = require("./model/App");
21
- var fs = require('fs');
22
- require('dotenv').config();
23
- process.env.NODE_ENV = utils_1.NODE_ENV_DEV;
24
- commander_1.default
25
- .command('login')
26
- .description('Login Bkper')
27
- .action(() => __awaiter(void 0, void 0, void 0, function* () {
28
- yield local_auth_service_1.login();
29
- }));
30
- commander_1.default
31
- .command('logout')
32
- .description('Logout Bkper')
33
- .action((todo) => {
34
- local_auth_service_1.logout();
35
- });
36
- commander_1.default
37
- .command('app')
38
- .description('Create/Update an App')
39
- .option('-u, --update', 'Update the App')
40
- .option('-c, --create', 'Create a new App')
41
- .action((options) => __awaiter(void 0, void 0, void 0, function* () {
42
- try {
43
- Bkper_1.Bkper.setConfig({ apiKeyProvider: () => __awaiter(void 0, void 0, void 0, function* () { return process.env.BKPER_API_KEY; }) });
44
- let app = new App_1.App();
45
- app.setJson(JSON.parse(fs.readFileSync('./bkperapp.json', 'utf8')))
46
- .setReadme(fs.readFileSync('./README.md', 'utf8'))
47
- .setClientSecret(process.env.BKPER_CLIENT_SECRET)
48
- .setDeveloperEmail(process.env.BKPER_DEVELOPER_EMAIL)
49
- .setUserEmails(process.env.BKPER_USER_EMAILS);
50
- if (options.update) {
51
- app = yield app.update();
52
- console.log(`Updated ${app.getId()} sucessfully.`);
53
- }
54
- else if (options.create) {
55
- app = yield app.create();
56
- console.log(`Created ${app.getId()} sucessfully.`);
57
- }
58
- }
59
- catch (err) {
60
- console.log(err);
61
- }
62
- }));
63
- commander_1.default.parse(process.argv);
64
- //# sourceMappingURL=cli.js.map