-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
62 lines (57 loc) · 2.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function parseGoogleSpreadsheetKey(keyString) {
if (!keyString || keyString.length === 0) {
console.error('No key string defined!')
return null
}
const newlineToken = '##NEW_LINE##'
const dashesToken = '##DASHES##'
const replaceNewline = string => string.replace(new RegExp(newlineToken, 'g'), '\\n')
const replaseDashes = string => string.replace(new RegExp(dashesToken, 'g'), '-----')
const parseKey = key => replaceNewline(replaseDashes(key))
const spreadsheetPrivateKey = parseKey(keyString)
let parsed
try {
parsed = JSON.parse(`"${spreadsheetPrivateKey}"`)
} catch (error) {
parsed = spreadsheetPrivateKey
}
return parsed
}
const config = {
port: process.env.PORT,
db: process.env.MONGODB_URL,
spreadsheet: {
orders: {
id: process.env.ORDERS_SPREADSHEET_ID,
sheet: process.env.ORDERS_SPREADSHEET_SHEETNAME,
sheetId: 1
},
customers: {
id: process.env.CUSTOMERS_SPREADSHEET_ID,
sheet: process.env.CUSTOMERS_SPREADSHEET_SHEETNAME
},
questions: {
id: process.env.QUESTIONS_SPREADSHEET_ID,
sheet: process.env.QUESTIONS_SPREADSHEET_SHEETNAME
}
},
auth: {
mercadolibre: {
clientId: Number(process.env.MELI_CLIENT_ID),
clientSecret: process.env.MELI_CLIENT_SECRET
},
spreadsheet: {
type: 'service_account',
project_id: 'meli-manager',
private_key_id: process.env.SPREADSHEET_PRIVATE_KEY_ID,
private_key: process.env.SPREADSHEET_PRIVATE_KEY && parseGoogleSpreadsheetKey(process.env.SPREADSHEET_PRIVATE_KEY),
client_email: process.env.SPREADSHEET_CLIENT_EMAIL,
client_id: process.env.SPREADSHEET_CLIENT_ID,
auth_uri: 'https://accounts.google.com/o/oauth2/auth',
token_uri: 'https://accounts.google.com/o/oauth2/token',
auth_provider_x509_cert_url: 'https://www.googleapis.com/oauth2/v1/certs',
client_x509_cert_url: 'https://www.googleapis.com/robot/v1/metadata/x509/meli-spreadsheets-manager%40meli-manager.iam.gserviceaccount.com'
}
}
}
module.exports = config