Skip to content

Commit d34b3b3

Browse files
committed
Run prettier across the repo
``` npm run format ```
1 parent 038e358 commit d34b3b3

83 files changed

Lines changed: 5083 additions & 5491 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app.ts

Lines changed: 259 additions & 275 deletions
Large diffs are not rendered by default.

get_google_oauth.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ const readline = require('readline');
33
const {google} = require('googleapis');
44

55
const SCOPES = [
6-
'https://www.googleapis.com/auth/admin.directory.group.member'
7-
,'https://www.googleapis.com/auth/admin.directory.group'
8-
,'https://mail.google.com/'
9-
,'https://www.googleapis.com/auth/gmail.modify'
10-
,'https://www.googleapis.com/auth/gmail.compose'
11-
,'https://www.googleapis.com/auth/gmail.send'
6+
'https://www.googleapis.com/auth/admin.directory.group.member',
7+
'https://www.googleapis.com/auth/admin.directory.group',
8+
'https://mail.google.com/',
9+
'https://www.googleapis.com/auth/gmail.modify',
10+
'https://www.googleapis.com/auth/gmail.compose',
11+
'https://www.googleapis.com/auth/gmail.send',
1212
];
1313

14-
1514
// Load client secrets from a local file.
1615
fs.readFile('google-credentials.json', (err, content) => {
1716
if (err) return console.log('Error loading client secret file:', err);
@@ -28,7 +27,10 @@ fs.readFile('google-credentials.json', (err, content) => {
2827
function authorize(credentials) {
2928
const {client_secret, client_id, redirect_uris} = credentials.installed;
3029
const oAuth2Client = new google.auth.OAuth2(
31-
client_id, client_secret, redirect_uris[0] );
30+
client_id,
31+
client_secret,
32+
redirect_uris[0],
33+
);
3234

3335
getNewToken(oAuth2Client);
3436
}

google_auth.ts

Lines changed: 53 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
import * as googleAuth from 'google-auth-library';
2-
import { Credentials } from 'google-auth-library/build/src/auth/credentials';
2+
import {Credentials} from 'google-auth-library/build/src/auth/credentials';
33
import * as fs from 'fs';
44
import * as readline from 'readline';
55

6-
7-
// TODO
6+
// TODO
87
// * Get credentials from file in config.yaml -> google_credentials_file
98
// * Generate auth URL
109
// * Wait for user to come back with code
1110
// * Take code and get the access token
1211
// * Dump credentials data to file
1312
// * Have main app read from the seprate file, rather than config.yaml
14-
// * Have main app update access, refresh, and expiration configs
13+
// * Have main app update access, refresh, and expiration configs
1514
// automatically
1615
const scopes: Array<string> = [
17-
'https://www.googleapis.com/auth/admin.directory.group.member'
18-
,'https://www.googleapis.com/auth/admin.directory.group'
19-
,'https://mail.google.com/'
20-
,'https://www.googleapis.com/auth/gmail.modify'
21-
,'https://www.googleapis.com/auth/gmail.compose'
22-
,'https://www.googleapis.com/auth/gmail.send'
16+
'https://www.googleapis.com/auth/admin.directory.group.member',
17+
'https://www.googleapis.com/auth/admin.directory.group',
18+
'https://mail.google.com/',
19+
'https://www.googleapis.com/auth/gmail.modify',
20+
'https://www.googleapis.com/auth/gmail.compose',
21+
'https://www.googleapis.com/auth/gmail.send',
2322
];
2423

25-
2624
/**
2725
* Step 0: Create OAuth2 credentials at the Google Console (make sure to download JSON, not only just get key and secret)
2826
*/
@@ -32,78 +30,68 @@ const scopes: Array<string> = [
3230
*/
3331

3432
export function getAuthorizeUrl(
35-
credentials
36-
,callback: (err: any, url: string) => any
33+
credentials,
34+
callback: (err: any, url: string) => any,
3735
): void {
3836
const oauth2Client = new googleAuth.OAuth2Client(
39-
credentials.installed.client_id
40-
,credentials.installed.client_secret
41-
,credentials.installed.redirect_uris[0]
37+
credentials.installed.client_id,
38+
credentials.installed.client_secret,
39+
credentials.installed.redirect_uris[0],
4240
);
4341

44-
const authUrl = oauth2Client.generateAuthUrl({
45-
access_type: 'offline',
46-
scope: scopes
47-
});
42+
const authUrl = oauth2Client.generateAuthUrl({
43+
access_type: 'offline',
44+
scope: scopes,
45+
});
4846

49-
callback(null, authUrl);
47+
callback(null, authUrl);
5048
}
5149

52-
5350
/**
5451
* Step 2: Get auth token
5552
*/
5653

57-
5854
export function getAccessToken(
59-
code
60-
,credentials
61-
,callback: (err: any, token?: Credentials | null) => any): void
62-
{
55+
code,
56+
credentials,
57+
callback: (err: any, token?: Credentials | null) => any,
58+
): void {
6359
const oauth2Client = new googleAuth.OAuth2Client(
64-
credentials.installed.client_id
65-
,credentials.installed.client_secret
66-
,credentials.installed.redirect_uris[0]
60+
credentials.installed.client_id,
61+
credentials.installed.client_secret,
62+
credentials.installed.redirect_uris[0],
6763
);
6864

69-
oauth2Client.getToken( code, (err, token) => {
70-
if(err) return console.log(err);
65+
oauth2Client.getToken(code, (err, token) => {
66+
if (err) return console.log(err);
7167

72-
callback(null, token);
73-
});
68+
callback(null, token);
69+
});
7470
}
7571

76-
77-
fs.readFile( 'google-credentials.json', (err, content) => {
72+
fs.readFile('google-credentials.json', (err, content) => {
7873
if (err) return console.log('Error loading client secret file:', err);
79-
let credentials = JSON.parse( content.toString() );
80-
81-
getAuthorizeUrl(
82-
credentials
83-
,(err, url) => {
84-
if(err) return console.log(err);
85-
console.log("Auth url is: ", url);
86-
87-
let rl = readline.createInterface({
88-
input: process.stdin
89-
,output: process.stdout
74+
let credentials = JSON.parse(content.toString());
75+
76+
getAuthorizeUrl(credentials, (err, url) => {
77+
if (err) return console.log(err);
78+
console.log('Auth url is: ', url);
79+
80+
let rl = readline.createInterface({
81+
input: process.stdin,
82+
output: process.stdout,
83+
});
84+
85+
rl.question('Input token: ', token => {
86+
getAccessToken(token, credentials, (err, access) => {
87+
if (err) return console.log(err);
88+
//console.log("Auth token is: ", token);
89+
console.log('google_client_token: ' + token);
90+
console.log('google_access_token: ' + access['access_token']);
91+
console.log('google_token_type: ' + access['token_type']);
92+
console.log('google_refresh_token: ' + access['refresh_token']);
93+
console.log('google_expires_date: ' + access['expiry_date']);
9094
});
91-
92-
rl.question( "Input token: ", (token) => {
93-
getAccessToken( token, credentials, (err, access) => {
94-
if(err) return console.log(err);
95-
//console.log("Auth token is: ", token);
96-
console.log( "google_client_token: " + token );
97-
console.log( "google_access_token: "
98-
+ access['access_token'] );
99-
console.log( "google_token_type: "
100-
+ access['token_type'] );
101-
console.log( "google_refresh_token: "
102-
+ access['refresh_token'] );
103-
console.log( "google_expires_date: "
104-
+ access['expiry_date'] );
105-
});
106-
});
107-
}
108-
);
95+
});
96+
});
10997
});

node.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
declare module "short-uuid";
1+
declare module 'short-uuid';

src/config.ts

Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,98 @@
1-
import * as fs from "fs";
2-
import * as yaml from "js-yaml";
1+
import * as fs from 'fs';
2+
import * as yaml from 'js-yaml';
33
// import * as env from 'env-var';
4-
import * as nconf from "nconf";
5-
import nconf_yaml from "nconf-yaml";
4+
import * as nconf from 'nconf';
5+
import nconf_yaml from 'nconf-yaml';
66

77
interface AppConfig {
8-
port: number,
9-
deployment_type: "dev" | "prod",
10-
log_file: string,
11-
log_level: "debug" | "info" | "warn" | "error",
8+
port: number;
9+
deployment_type: 'dev' | 'prod';
10+
log_file: string;
11+
log_level: 'debug' | 'info' | 'warn' | 'error';
1212
}
1313

1414
interface PasswordConfig {
15-
preferred_password_crypt_method: string,
15+
preferred_password_crypt_method: string;
1616
}
1717

1818
interface SessionConfig {
19-
session_secret: string,
20-
session_length_sec: number
19+
session_secret: string;
20+
session_length_sec: number;
2121
}
2222

2323
interface WildApricotConfig {
24-
wa_api_client: string,
25-
wa_api_secret: string,
26-
wa_account_id: number,
24+
wa_api_client: string;
25+
wa_api_secret: string;
26+
wa_account_id: number;
2727
}
2828

2929
// TODO: Add Google and Email configuration
3030

3131
interface DatabaseConfig {
32-
db_user: string,
33-
db_password: string,
34-
db_name: string,
35-
db_host: string,
36-
db_port: number,
37-
db_ssl: boolean,
38-
};
32+
db_user: string;
33+
db_password: string;
34+
db_name: string;
35+
db_host: string;
36+
db_port: number;
37+
db_ssl: boolean;
38+
}
3939

4040
type Config = AppConfig & PasswordConfig & DatabaseConfig & WildApricotConfig;
4141

4242
const appConfigDefaults = {
4343
port: 3001,
44-
deployment_type: "dev",
45-
log_file: "dev.log",
46-
log_level: "info"
47-
}
44+
deployment_type: 'dev',
45+
log_file: 'dev.log',
46+
log_level: 'info',
47+
};
4848

4949
const passwordConfigDefaults = {
50-
preferred_password_crypt_method: "bcrypt_10"
50+
preferred_password_crypt_method: 'bcrypt_10',
5151
};
5252

5353
const sessionConfigDefaults = {
54-
session_secret: "xxxx",
54+
session_secret: 'xxxx',
5555
session_length_sec: 3600000,
56-
}
56+
};
5757

5858
const wildApricotConfigDefaults = {
59-
wa_api_client: "",
60-
wa_api_secret: "",
59+
wa_api_client: '',
60+
wa_api_secret: '',
6161
wa_account_id: 0,
62-
}
62+
};
6363

6464
const databaseConfigDefaults = {
65-
db_user: "bodgery",
66-
db_password: "",
67-
db_name: "bodgery_members",
68-
db_host: "localhost",
65+
db_user: 'bodgery',
66+
db_password: '',
67+
db_name: 'bodgery_members',
68+
db_host: 'localhost',
6969
db_port: 5432,
70-
db_ssl: false
71-
}
72-
70+
db_ssl: false,
71+
};
7372

74-
export default function(): Config {
75-
return nconf.argv({
76-
port: {
77-
description: "Port to listen on",
78-
alias: "p",
79-
type: "number"
80-
}
81-
}).env({
82-
lowerCase: true,
83-
parseValues: true,
84-
}).file({
85-
file: 'config.yaml',
86-
format: nconf_yaml,
87-
})
88-
.defaults({
89-
...appConfigDefaults,
90-
...passwordConfigDefaults,
91-
...sessionConfigDefaults,
92-
...databaseConfigDefaults,
93-
...wildApricotConfigDefaults,
94-
}).get()
73+
export default function (): Config {
74+
return nconf
75+
.argv({
76+
port: {
77+
description: 'Port to listen on',
78+
alias: 'p',
79+
type: 'number',
80+
},
81+
})
82+
.env({
83+
lowerCase: true,
84+
parseValues: true,
85+
})
86+
.file({
87+
file: 'config.yaml',
88+
format: nconf_yaml,
89+
})
90+
.defaults({
91+
...appConfigDefaults,
92+
...passwordConfigDefaults,
93+
...sessionConfigDefaults,
94+
...databaseConfigDefaults,
95+
...wildApricotConfigDefaults,
96+
})
97+
.get();
9598
}

0 commit comments

Comments
 (0)