refs #4823 Added checkConfig function

This commit is contained in:
Guillermo Bonet 2023-05-08 12:18:14 +02:00
parent 1a97f16a11
commit 17533d873f
3 changed files with 21 additions and 5 deletions

View File

@ -28,7 +28,7 @@ npm i
### .env file template
```bash
#FLORIDAY DATA
#FLORIDAY DATA CONFIG
CLIENT_ID = xxxxxxxxxx
CLIENT_SECRET = xxxxxxxxxx
API_KEY = xxxxxxxxxx

View File

@ -9,8 +9,8 @@ const env = process.env;
class Floriday {
async start() {
try {
await utils.checkConfig();
this.tokenExpirationDate = await utils.requestToken(models);
if (!env.API_KEY) throw new Error(`You haven't provided the API key`)
if (JSON.parse(env.SYNC_SEQUENCE)) await utils.syncSequence();
if (JSON.parse(env.SYNC_SUPPLIER)) await utils.syncSuppliers();
if (JSON.parse(env.SYNC_CONN)) await utils.syncConn();

View File

@ -17,9 +17,6 @@ export async function requestToken() {
try {
spinner = ora(`Requesting new token...`).start();
if (!env.CLIENT_ID || !env.CLIENT_SECRET)
throw new Error(`You haven't provided the credentials`)
const clientConfigData = await models.clientConfig.findOne();
let tokenExpirationDate;
@ -96,6 +93,25 @@ export async function getCurrentToken() {
return data.currentToken
}
/**
* Check the floriday data config
*/
export async function checkConfig() {
const spinner = ora(`Checking config...`).start();
const excludedEnvVars = ['VSCODE_GIT_ASKPASS_EXTRA_ARGS'];
const requiredEnvVars = Object.keys(env);
const filteredEnvVars = requiredEnvVars.filter(reqEnvVar => !excludedEnvVars.includes(reqEnvVar));
for (const reqEnvVar of filteredEnvVars) {
if (!process.env[reqEnvVar]) {
spinner.fail();
throw new Error(`You haven't provided the ${reqEnvVar} environment variable`);
}
}
spinner.succeed();
}
/**
* Returns the expiration data of current token
*