bkper 3.0.0 → 3.1.1

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 CHANGED
@@ -52,6 +52,130 @@ You can add a ```.env``` file at the root of your project with those variables a
52
52
 
53
53
  > WARNING: Never upload variables to the source code repository.
54
54
 
55
+
56
+ ### ```./bkperapp.json``` Reference
57
+
58
+ ```json
59
+ {
60
+
61
+ /* App basic configuration */
62
+ "id": "The App agent id. It can NOT be changed after the App created.",
63
+ "name": "The name of the App or Bot.",
64
+ "logoUrl": "Set your logo url from public host. Best fit 200x200 px. Use https://",
65
+
66
+ /* Context menu configuration */
67
+ "menuUrl": "The menu url to open in the popup window. See reference bellow.",
68
+ "menuUrlDev": "The menu url to open in the popup window, when opened by the developer user.",
69
+ "menuText": "The context menu call to action.",
70
+ "menuPopupWidth": "500 //width in pixels. Default to 80% of screen width.",
71
+ "menuPopupHeight": "300 //height in pixels. Default to 90% of screen height.",
72
+
73
+ /* Bot events configuration */
74
+ "events": [
75
+ "TRANSACTION_POSTED",
76
+ "TRANSACTION_CHECKED",
77
+ "TRANSACTION_UNCHECKED",
78
+ "TRANSACTION_UPDATED",
79
+ "TRANSACTION_DELETED",
80
+ "TRANSACTION_RESTORED",
81
+ "ACCOUNT_CREATED",
82
+ "ACCOUNT_UPDATED",
83
+ "ACCOUNT_DELETED",
84
+ "GROUP_CREATED",
85
+ "GROUP_UPDATED",
86
+ "GROUP_DELETED",
87
+ "FILE_CREATED",
88
+ "BOOK_UPDATED"
89
+ ],
90
+
91
+ "filePatterns": [
92
+ "The file patterns the Bot is capable of process. It accepts wildcard. E.g.",
93
+ "radiusbank*.ofx",
94
+ "-*.qif"
95
+ ],
96
+
97
+
98
+ /* Bot configuration only when additional scopes, other than email, is needed */
99
+ /* If not specified, a default valid token with the email scope is sent in the http header */
100
+ "clientId": "The Client ID from GCP project Web Application OAuth Credential",
101
+ "scopes": [
102
+ "The Google OAuth scopes used. E.g.",
103
+ "https://www.googleapis.com/auth/userinfo.email",
104
+ "https://www.googleapis.com/auth/script.external_request"
105
+ ],
106
+
107
+ /* Google Apps Script bot configuration */
108
+ "scriptId": "The Google Apps Script ID",
109
+ "deploymentId": "The Google Apps Script API Deployment ID",
110
+
111
+ /* Webhook bot configuration */
112
+ "webhookUrl": "The production webhook url",
113
+ "webhookUrlDev": "The development webhook url",
114
+
115
+ /* Schema to provide autocompletion */
116
+ "propertiesSchema": {
117
+ "book": {
118
+ "keys": [
119
+ "key1",
120
+ "key2"
121
+ ],
122
+ "values": [
123
+ "value2",
124
+ "value2"
125
+ ]
126
+ },
127
+ "group": {
128
+ "keys": [
129
+ "key1",
130
+ "key2"
131
+ ],
132
+ "values": [
133
+ "value2",
134
+ "value2"
135
+ ]
136
+ },
137
+ "account": {
138
+ "keys": [
139
+ "key1",
140
+ "key2"
141
+ ],
142
+ "values": [
143
+ "value2",
144
+ "value2"
145
+ ]
146
+ },
147
+ "transaction": {
148
+ "keys": [
149
+ "key1",
150
+ "key2"
151
+ ],
152
+ "values": [
153
+ "value2",
154
+ "value2"
155
+ ]
156
+ }
157
+ }
158
+ }
159
+
160
+ ```
161
+
162
+ #### Accepted expressions in menuUrl property:
163
+ - ```${book.id}``` - the current book id
164
+ - ```${book.properties.xxxxx}``` - any property value from the current book
165
+ - ```${transactions.query}``` - the current query being executed on transactions list
166
+ - ```${transactions.ids}``` - the ids of selected transactions, splitted by comma
167
+ - ```${account.id}``` - the current account being filterd
168
+ - ```${account.properties.xxxxx}``` - any property value from the current account being filtered
169
+ - ```${group.id}``` - the current group being filterd
170
+ - ```${group.properties.xxxxx}``` - any property value from the current group being filtered
171
+
172
+ #### Example:
173
+
174
+ ```json
175
+ "menuUrl": "https://app.bkper.com/b/#transactions:bookId=${book.id}"
176
+ ```
177
+
178
+
55
179
  ## Documentation
56
180
 
57
181
  - [Developer Docs](https://bkper.com/docs)
@@ -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,5 @@
1
+ export declare function login(): Promise<void>;
2
+ export declare function logout(): void;
3
+ export declare function isLoggedIn(): boolean;
4
+ export declare function getOAuthToken(): Promise<string>;
5
+ //# sourceMappingURL=local-auth-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-auth-service.d.ts","sourceRoot":"","sources":["../../src/auth/local-auth-service.ts"],"names":[],"mappings":"AAyBA,wBAAsB,KAAK,kBAK1B;AAED,wBAAgB,MAAM,SAKrB;AAED,wBAAgB,UAAU,YAEzB;AAED,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CA8BnD"}
@@ -0,0 +1,75 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { authenticate } from '@google-cloud/local-auth';
11
+ import fs from 'fs';
12
+ import { OAuth2Client } from "google-auth-library";
13
+ import os from 'os';
14
+ import { createRequire } from "module";
15
+ import { fileURLToPath } from 'url';
16
+ import path from 'path';
17
+ const require = createRequire(import.meta.url);
18
+ const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
19
+ const __dirname = path.dirname(__filename); // get the name of the directory
20
+ const keys = require(`${__dirname}/keys.json`);
21
+ let storedCredentials;
22
+ const storedCredentialsPath = `${os.homedir}/.bkper-credentials.json`;
23
+ try {
24
+ let credentialsJson = fs.readFileSync(storedCredentialsPath, 'utf8');
25
+ storedCredentials = JSON.parse(credentialsJson);
26
+ }
27
+ catch (err) {
28
+ console.log('No local credentials found.');
29
+ }
30
+ export 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
+ export function logout() {
39
+ if (fs.existsSync(storedCredentialsPath)) {
40
+ fs.rmSync(storedCredentialsPath);
41
+ }
42
+ console.log('Bkper logged out.');
43
+ }
44
+ export function isLoggedIn() {
45
+ return storedCredentials != null;
46
+ }
47
+ export function getOAuthToken() {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ let localAuth;
50
+ if (storedCredentials) {
51
+ localAuth = new OAuth2Client(keys.installed.client_id, keys.installed.client_secret, keys.installed.redirect_uris[0]);
52
+ localAuth.setCredentials(storedCredentials);
53
+ }
54
+ else {
55
+ localAuth = yield authenticate({
56
+ scopes: ['https://www.googleapis.com/auth/userinfo.email'],
57
+ keyfilePath: `${__dirname}/keys.json`,
58
+ });
59
+ storeCredentials(localAuth.credentials);
60
+ }
61
+ localAuth.on('tokens', (tokens) => {
62
+ if (tokens.refresh_token) {
63
+ // store the refresh_token in my database!
64
+ storeCredentials(tokens);
65
+ }
66
+ });
67
+ let token = yield localAuth.getAccessToken();
68
+ return token.token || '';
69
+ });
70
+ }
71
+ function storeCredentials(credentials) {
72
+ storedCredentials = credentials;
73
+ fs.writeFileSync(storedCredentialsPath, JSON.stringify(credentials, null, 4), 'utf8');
74
+ }
75
+ //# sourceMappingURL=local-auth-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-auth-service.js","sourceRo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CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AACxF,CAAC"}
package/lib/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/lib/cli.js ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env node
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
+ import { App, Bkper } from 'bkper-js';
12
+ import program from 'commander';
13
+ import fs from 'fs';
14
+ import { login, logout } from './auth/local-auth-service.js';
15
+ import { getBkperLocalConfig } from './index.js';
16
+ program
17
+ .command('login')
18
+ .description('Login Bkper')
19
+ .action(() => __awaiter(void 0, void 0, void 0, function* () {
20
+ yield login();
21
+ }));
22
+ program
23
+ .command('logout')
24
+ .description('Logout Bkper')
25
+ .action((todo) => {
26
+ logout();
27
+ });
28
+ program
29
+ .command('app')
30
+ .description('Create/Update an App')
31
+ .option('-u, --update', 'Update the App')
32
+ .option('-c, --create', 'Create a new App')
33
+ .action((options) => __awaiter(void 0, void 0, void 0, function* () {
34
+ try {
35
+ Bkper.setConfig(getBkperLocalConfig());
36
+ const json = 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 = yield app.update();
44
+ console.log(`Updated ${app.getId()} sucessfully.`);
45
+ }
46
+ else if (options.create) {
47
+ app = yield app.create();
48
+ console.log(`Created ${app.getId()} sucessfully.`);
49
+ }
50
+ }
51
+ catch (err) {
52
+ console.log(err);
53
+ }
54
+ }));
55
+ program.parse(process.argv);
56
+ //# sourceMappingURL=cli.js.map
package/lib/cli.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;AAEA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,OAAO,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO;KACJ,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CAAC,aAAa,CAAC;KAC1B,MAAM,CAAC,GAAS,EAAE;IACjB,MAAM,KAAK,EAAE,CAAA;AACf,CAAC,CAAA,CAAC,CAAC;AAEL,OAAO;KACJ,OAAO,CAAC,QAAQ,CAAC;KACjB,WAAW,CAAC,cAAc,CAAC;KAC3B,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;IACf,MAAM,EAAE,CAAA;AACV,CAAC,CAAC,CAAC;AAEL,OAAO;KACJ,OAAO,CAAC,KAAK,CAAC;KACd,WAAW,CAAC,sBAAsB,CAAC;KACnC,MAAM,CAAC,cAAc,EAAE,gBAAgB,CAAC;KACxC,MAAM,CAAC,cAAc,EAAE,kBAAkB,CAAC;KAC1C,MAAM,CAAC,CAAO,OAAO,EAAE,EAAE;IAExB,IAAI,CAAC;QACF,KAAK,CAAC,SAAS,CAAC,mBAAmB,EAAE,CAAC,CAAA;QACtC,MAAM,IAAI,GAAc,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC,CAAC;QAC/E,IAAI,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC;aACrB,SAAS,CAAC,EAAE,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;aACjD,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;aAChD,iBAAiB,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC;aACpD,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAChD,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACnB,GAAG,GAAG,MAAM,GAAG,CAAC,MAAM,EAAE,CAAC;YACzB,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,CAAC,KAAK,EAAE,eAAe,CAAC,CAAA;QACpD,CAAC;aAAM,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YAC1B,GAAG,GAAG,MAAM,GAAG,CAAC,MAAM,EAAE,CAAC;YACzB,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,CAAC,KAAK,EAAE,eAAe,CAAC,CAAA;QAEpD,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAClB,CAAC;AAEH,CAAC,CAAA,CAAC,CAAC;AAGL,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { Config } from 'bkper-js';
2
+ export declare function getBkperLocalConfig(): Config;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAKlC,wBAAgB,mBAAmB,IAAI,MAAM,CAK5C"}
package/lib/index.js ADDED
@@ -0,0 +1,19 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { getOAuthToken } from './auth/local-auth-service.js';
11
+ import dotenv from 'dotenv';
12
+ dotenv.config();
13
+ export function getBkperLocalConfig() {
14
+ return {
15
+ apiKeyProvider: () => __awaiter(this, void 0, void 0, function* () { return process.env.BKPER_API_KEY || ''; }),
16
+ oauthTokenProvider: () => getOAuthToken()
17
+ };
18
+ }
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,MAAM,CAAC,MAAM,EAAE,CAAA;AAEf,MAAM,UAAU,mBAAmB;IACjC,OAAO;QACL,cAAc,EAAE,GAAS,EAAE,gDAAC,OAAA,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,EAAE,CAAA,GAAA;QAC3D,kBAAkB,EAAE,GAAG,EAAE,CAAC,aAAa,EAAE;KAC1C,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper",
3
- "version": "3.0.0",
3
+ "version": "3.1.1",
4
4
  "description": "Node.js command line client for Bkper",
5
5
  "bin": {
6
6
  "bkper": "./lib/cli.js"
@@ -10,13 +10,20 @@
10
10
  "author": "mael <mael@bkper.com>",
11
11
  "license": "Apache-2.0",
12
12
  "private": false,
13
+ "main": "./lib/index.js",
14
+ "module": "./lib/index.js",
15
+ "types": "./lib/index.d.ts",
16
+ "type": "module",
17
+ "files": [
18
+ "lib/**/*"
19
+ ],
13
20
  "scripts": {
14
21
  "clean": "rm -rf ./lib & rm -rf ./node_modules & wait",
22
+ "prebuild": "bun install",
15
23
  "build": "run-s build:*",
16
24
  "build:clean": "gts clean",
17
25
  "build:compile": "tsc",
18
- "build:cleanup": "rimraf lib/**/*.map lib/*.map lib/**/*.d.ts lib/*.d.ts",
19
- "build:clean-dist": "rimraf dist",
26
+ "prewatch": "bun run build",
20
27
  "watch": "tsc -w",
21
28
  "patch": "yarn version --patch",
22
29
  "minor": "yarn version --minor",
@@ -26,7 +33,7 @@
26
33
  },
27
34
  "dependencies": {
28
35
  "@google-cloud/local-auth": "^3.0.1",
29
- "bkper-js": "^1.0.0",
36
+ "bkper-js": "^1.1.0",
30
37
  "commander": "^6.2.1",
31
38
  "dotenv": "^8.2.0",
32
39
  "google-auth-library": "^9.14.0"
package/bun.lockb DELETED
Binary file
@@ -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,73 +0,0 @@
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 DELETED
@@ -1,57 +0,0 @@
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 DELETED
@@ -1,25 +0,0 @@
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
- }