File tree 6 files changed +35
-16
lines changed
6 files changed +35
-16
lines changed Original file line number Diff line number Diff line change 10
10
"author" :
" mael <[email protected] >" ,
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" ,
13
17
"scripts" : {
14
18
"clean" : " rm -rf ./lib & rm -rf ./node_modules & wait" ,
19
+ "prebuild" : " bun install" ,
15
20
"build" : " run-s build:*" ,
16
21
"build:clean" : " gts clean" ,
17
22
"build:compile" : " tsc" ,
18
- "build:cleanup" : " rimraf lib/**/*.map lib/*.map lib/**/*.d.ts lib/*.d.ts" ,
19
- "build:clean-dist" : " rimraf dist" ,
23
+ "prewatch" : " bun run build" ,
20
24
"watch" : " tsc -w" ,
21
25
"patch" : " yarn version --patch" ,
22
26
"minor" : " yarn version --minor" ,
26
30
},
27
31
"dependencies" : {
28
32
"@google-cloud/local-auth" : " ^3.0.1" ,
29
- "bkper-js" : " ^1.0 .0" ,
33
+ "bkper-js" : " ^1.1 .0" ,
30
34
"commander" : " ^6.2.1" ,
31
35
"dotenv" : " ^8.2.0" ,
32
36
"google-auth-library" : " ^9.14.0"
Original file line number Diff line number Diff line change @@ -2,6 +2,13 @@ import {authenticate} from '@google-cloud/local-auth';
2
2
import fs from 'fs' ;
3
3
import { Credentials , OAuth2Client } from "google-auth-library" ;
4
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
5
12
6
13
const keys = require ( `${ __dirname } /keys.json` ) ;
7
14
@@ -56,14 +63,13 @@ export async function getOAuthToken(): Promise<string> {
56
63
localAuth . on ( 'tokens' , ( tokens ) => {
57
64
if ( tokens . refresh_token ) {
58
65
// store the refresh_token in my database!
59
- console . log ( tokens . refresh_token ) ;
60
66
storeCredentials ( tokens )
61
67
}
62
68
} ) ;
63
69
64
70
let token = await localAuth . getAccessToken ( ) ;
65
71
66
- return token . token ;
72
+ return token . token || '' ;
67
73
68
74
}
69
75
Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env node
2
2
3
- import program from 'commander' ;
4
- import { getOAuthToken , login , logout } from './auth/local-auth-service' ;
5
3
import { App , Bkper } from 'bkper-js' ;
6
- var fs = require ( 'fs' ) ;
7
- require ( 'dotenv' ) . config ( ) ;
8
-
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' ;
9
8
10
9
program
11
10
. command ( 'login' )
@@ -29,10 +28,7 @@ program
29
28
. action ( async ( options ) => {
30
29
31
30
try {
32
- Bkper . setConfig ( {
33
- apiKeyProvider : async ( ) => process . env . BKPER_API_KEY ,
34
- oauthTokenProvider : ( ) => getOAuthToken ( )
35
- } )
31
+ Bkper . setConfig ( getBkperLocalConfig ( ) )
36
32
const json : bkper . App = JSON . parse ( fs . readFileSync ( './bkperapp.json' , 'utf8' ) ) ;
37
33
let app = new App ( json )
38
34
. setReadme ( fs . readFileSync ( './README.md' , 'utf8' ) )
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 3
3
"compilerOptions" : {
4
4
"rootDir" : " src" ,
5
5
"outDir" : " lib" ,
6
+ "module" : " ESNext" ,
7
+ "moduleResolution" : " Node" ,
8
+ "resolveJsonModule" : true ,
6
9
"typeRoots" : [" node_modules/@bkper" , " node_modules/@types" ],
7
- "strict" : false ,
10
+ "strict" : true ,
8
11
"esModuleInterop" : true ,
9
12
"target" : " es2015" ,
10
- "resolveJsonModule" : true ,
11
13
"declaration" : true ,
12
14
"sourceMap" : true ,
13
15
"declarationMap" : true
You can’t perform that action at this time.
0 commit comments