bkper 3.1.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/lib/auth/keys.json +12 -0
- package/lib/auth/local-auth-service.d.ts +5 -0
- package/lib/auth/local-auth-service.d.ts.map +1 -0
- package/lib/auth/local-auth-service.js +75 -0
- package/lib/auth/local-auth-service.js.map +1 -0
- package/lib/cli.d.ts +3 -0
- package/lib/cli.d.ts.map +1 -0
- package/lib/cli.js +56 -0
- package/lib/cli.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +19 -0
- package/lib/index.js.map +1 -0
- package/package.json +4 -1
- package/bun.lockb +0 -0
- package/src/auth/keys.json +0 -12
- package/src/auth/local-auth-service.ts +0 -79
- package/src/cli.ts +0 -53
- package/src/index.ts +0 -11
- package/tsconfig.json +0 -27
|
@@ -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 @@
|
|
|
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","sourceRoot":"","sources":["../../src/auth/local-auth-service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAQ,EAAC,YAAY,EAAC,MAAM,0BAA0B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ib/cli.d.ts
ADDED
package/lib/cli.d.ts.map
ADDED
|
@@ -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,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AC,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 @@
|
|
|
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
|
package/lib/index.js.map
ADDED
|
@@ -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.1.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Node.js command line client for Bkper",
|
|
5
5
|
"bin": {
|
|
6
6
|
"bkper": "./lib/cli.js"
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
"module": "./lib/index.js",
|
|
15
15
|
"types": "./lib/index.d.ts",
|
|
16
16
|
"type": "module",
|
|
17
|
+
"files": [
|
|
18
|
+
"lib/**/*"
|
|
19
|
+
],
|
|
17
20
|
"scripts": {
|
|
18
21
|
"clean": "rm -rf ./lib & rm -rf ./node_modules & wait",
|
|
19
22
|
"prebuild": "bun install",
|
package/bun.lockb
DELETED
|
Binary file
|
package/src/auth/keys.json
DELETED
|
@@ -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,79 +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
|
-
import { createRequire } from "module";
|
|
6
|
-
import { fileURLToPath } from 'url';
|
|
7
|
-
import path from 'path';
|
|
8
|
-
|
|
9
|
-
const require = createRequire(import.meta.url);
|
|
10
|
-
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
|
|
11
|
-
const __dirname = path.dirname(__filename); // get the name of the directory
|
|
12
|
-
|
|
13
|
-
const keys = require(`${__dirname}/keys.json`);
|
|
14
|
-
|
|
15
|
-
let storedCredentials: Credentials;
|
|
16
|
-
|
|
17
|
-
const storedCredentialsPath = `${os.homedir}/.bkper-credentials.json`;
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
let credentialsJson = fs.readFileSync(storedCredentialsPath, 'utf8');
|
|
21
|
-
storedCredentials = JSON.parse(credentialsJson);
|
|
22
|
-
} catch (err) {
|
|
23
|
-
console.log('No local credentials found.');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export async function login() {
|
|
27
|
-
if (storedCredentials) {
|
|
28
|
-
console.log('Bkper already logged in.');
|
|
29
|
-
}
|
|
30
|
-
await getOAuthToken();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function logout() {
|
|
34
|
-
if (fs.existsSync(storedCredentialsPath)) {
|
|
35
|
-
fs.rmSync(storedCredentialsPath);
|
|
36
|
-
}
|
|
37
|
-
console.log('Bkper logged out.');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function isLoggedIn() {
|
|
41
|
-
return storedCredentials != null;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export async function getOAuthToken(): Promise<string> {
|
|
45
|
-
|
|
46
|
-
let localAuth: OAuth2Client
|
|
47
|
-
|
|
48
|
-
if (storedCredentials) {
|
|
49
|
-
localAuth = new OAuth2Client(
|
|
50
|
-
keys.installed.client_id,
|
|
51
|
-
keys.installed.client_secret,
|
|
52
|
-
keys.installed.redirect_uris[0]
|
|
53
|
-
);
|
|
54
|
-
localAuth.setCredentials(storedCredentials);
|
|
55
|
-
} else {
|
|
56
|
-
localAuth = await authenticate({
|
|
57
|
-
scopes: ['https://www.googleapis.com/auth/userinfo.email'],
|
|
58
|
-
keyfilePath: `${__dirname}/keys.json`,
|
|
59
|
-
});
|
|
60
|
-
storeCredentials(localAuth.credentials);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
localAuth.on('tokens', (tokens) => {
|
|
64
|
-
if (tokens.refresh_token) {
|
|
65
|
-
// store the refresh_token in my database!
|
|
66
|
-
storeCredentials(tokens)
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
let token = await localAuth.getAccessToken();
|
|
71
|
-
|
|
72
|
-
return token.token || '';
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function storeCredentials(credentials: Credentials) {
|
|
77
|
-
storedCredentials = credentials;
|
|
78
|
-
fs.writeFileSync(storedCredentialsPath, JSON.stringify(credentials, null, 4), 'utf8');
|
|
79
|
-
}
|
package/src/cli.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { App, Bkper } from 'bkper-js';
|
|
4
|
-
import program from 'commander';
|
|
5
|
-
import fs from 'fs';
|
|
6
|
-
import { login, logout } from './auth/local-auth-service.js';
|
|
7
|
-
import { getBkperLocalConfig } from './index.js';
|
|
8
|
-
|
|
9
|
-
program
|
|
10
|
-
.command('login')
|
|
11
|
-
.description('Login Bkper')
|
|
12
|
-
.action(async () => {
|
|
13
|
-
await login()
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
program
|
|
17
|
-
.command('logout')
|
|
18
|
-
.description('Logout Bkper')
|
|
19
|
-
.action((todo) => {
|
|
20
|
-
logout()
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
program
|
|
24
|
-
.command('app')
|
|
25
|
-
.description('Create/Update an App')
|
|
26
|
-
.option('-u, --update', 'Update the App')
|
|
27
|
-
.option('-c, --create', 'Create a new App')
|
|
28
|
-
.action(async (options) => {
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
Bkper.setConfig(getBkperLocalConfig())
|
|
32
|
-
const json: bkper.App = JSON.parse(fs.readFileSync('./bkperapp.json', 'utf8'));
|
|
33
|
-
let app = new App(json)
|
|
34
|
-
.setReadme(fs.readFileSync('./README.md', 'utf8'))
|
|
35
|
-
.setClientSecret(process.env.BKPER_CLIENT_SECRET)
|
|
36
|
-
.setDeveloperEmail(process.env.BKPER_DEVELOPER_EMAIL)
|
|
37
|
-
.setUserEmails(process.env.BKPER_USER_EMAILS);
|
|
38
|
-
if (options.update) {
|
|
39
|
-
app = await app.update();
|
|
40
|
-
console.log(`Updated ${app.getId()} sucessfully.`)
|
|
41
|
-
} else if (options.create) {
|
|
42
|
-
app = await app.create();
|
|
43
|
-
console.log(`Created ${app.getId()} sucessfully.`)
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
} catch (err) {
|
|
47
|
-
console.log(err)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
program.parse(process.argv);
|
package/src/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Config } from 'bkper-js';
|
|
2
|
-
import { getOAuthToken } from './auth/local-auth-service.js';
|
|
3
|
-
import dotenv from 'dotenv';
|
|
4
|
-
dotenv.config()
|
|
5
|
-
|
|
6
|
-
export function getBkperLocalConfig(): Config {
|
|
7
|
-
return {
|
|
8
|
-
apiKeyProvider: async () => process.env.BKPER_API_KEY || '',
|
|
9
|
-
oauthTokenProvider: () => getOAuthToken()
|
|
10
|
-
}
|
|
11
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./node_modules/gts/tsconfig-google.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "src",
|
|
5
|
-
"outDir": "lib",
|
|
6
|
-
"module": "ESNext",
|
|
7
|
-
"moduleResolution": "Node",
|
|
8
|
-
"resolveJsonModule": true,
|
|
9
|
-
"typeRoots" : ["node_modules/@bkper", "node_modules/@types" ],
|
|
10
|
-
"strict": true,
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"target": "es2015",
|
|
13
|
-
"declaration": true,
|
|
14
|
-
"sourceMap": true,
|
|
15
|
-
"declarationMap": true
|
|
16
|
-
},
|
|
17
|
-
"include": [
|
|
18
|
-
"src/**/*.json",
|
|
19
|
-
"src/**/*.ts",
|
|
20
|
-
"test/**/*.ts"
|
|
21
|
-
],
|
|
22
|
-
"exclude": [
|
|
23
|
-
"./test/",
|
|
24
|
-
"./node_modules/",
|
|
25
|
-
"./lib/"
|
|
26
|
-
]
|
|
27
|
-
}
|