Skip to content

Commit

Permalink
fix(general): tslint being applied in all sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Mar 11, 2019
1 parent 8fec26c commit c74b3ee
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 47 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"request-promise": "4.2.4",
"request-promise-native": "1.0.7",
"scanf": "^1.0.2",
"sequelize": "4.43.0",
"sequelize": "^4.43.0",
"sequelize-typescript": "0.6.7",
"shx": "0.3.2",
"simple-git": "1.107.0",
Expand Down
20 changes: 9 additions & 11 deletions packages/azuredeployer.gbapp/services/AzureDeployerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ export class AzureDeployerService implements IGBInstallationDeployer {
const req = new WebResource();
req.method = verb;
req.url = url;
req.headers = <HttpHeaders>{};
req.headers['Content-Type'] = 'application/json';
req.headers['accept-language'] = '*';
req.headers.set(' Authorization', `Bearer ${accessToken}`);
req.headers.set('Content-Type', 'application/json');
req.headers.set('accept-language', '*');
req.headers.set('Authorization', `Bearer ${accessToken}`);
req.body = body;

return req;
Expand Down Expand Up @@ -405,10 +404,10 @@ export class AzureDeployerService implements IGBInstallationDeployer {
const req = new WebResource();
req.method = 'POST';
req.url = requestUrl;
req.headers = <HttpHeaders>{};
req.headers = <any>{};
req.headers['Content-Type'] = 'application/json; charset=utf-8';
req.headers['accept-language'] = '*';
req.headers.set('Authorization', `Bearer ${accessToken}`);
(req.headers as any).Authorization = `Bearer ${accessToken}`;
}

/**
Expand Down Expand Up @@ -486,7 +485,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
} catch (error) {
reject(error);
}
}, 20000);
}, 20000);
});
}

Expand Down Expand Up @@ -527,10 +526,9 @@ export class AzureDeployerService implements IGBInstallationDeployer {
const req = new WebResource();
req.method = method;
req.url = `https://${location}.api.cognitive.microsoft.com/luis/api/v2.0/${resource}`;
req.headers = <HttpHeaders>{};
req.headers['Content-Type'] = 'application/json';
req.headers['accept-language'] = '*';
req.headers['Ocp-Apim-Subscription-Key'] = authoringKey;
req.headers.set('Content-Type', 'application/json');
req.headers.set('accept-language', '*');
req.headers.set('Ocp-Apim-Subscription-Key', authoringKey);
req.body = body;
const httpClient = new ServiceClient();

Expand Down
7 changes: 3 additions & 4 deletions packages/core.gbapp/services/GBConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { GBLog } from 'botlib';
* Base configuration for the server like storage.
*/
export class GBConfigService {

public static getServerPort(): number {
if (process.env.port !== undefined) {
return Number(process.env.port);
Expand Down Expand Up @@ -71,7 +70,7 @@ export class GBConfigService {
public static get(key: string): string | undefined {
let value = GBConfigService.tryGet(key);

if (value !== undefined) {
if (value === undefined) {
switch (key) {
case 'CLOUD_USERNAME':
value = undefined;
Expand Down Expand Up @@ -130,9 +129,9 @@ export class GBConfigService {
return value;
}

public static tryGet(key: string) {
public static tryGet(key: string): any {
let value = process.env[`container:${key}`];
if (value !== undefined) {
if (value === undefined) {
value = process.env[key];
}

Expand Down
33 changes: 18 additions & 15 deletions packages/core.gbapp/services/GBCoreService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ STORAGE_SYNC=true

return await ngrok.connect({ port: port });
} else {
GBLog.warn('ngrok executable not found. Check installation or node_modules folder.');
GBLog.warn('ngrok executable not found (only tested on Windows). Check installation or node_modules folder.');

return 'localhost';
}
Expand Down Expand Up @@ -294,19 +294,23 @@ STORAGE_SYNC=true
);
}
} catch (error) {
// Check if storage is empty and needs formatting.
const isInvalidObject = error.parent.number === 208 || error.parent.errno === 1; // MSSQL or SQLITE.
if (isInvalidObject) {
if (GBConfigService.get('STORAGE_SYNC') !== 'true') {
throw new Error(
`Operating storage is out of sync or there is a storage connection error.
if (error.parent === undefined) {
throw new Error(`Cannot connect to operating storage: ${error.message}.`);
} else {
// Check if storage is empty and needs formatting.
const isInvalidObject = error.parent.number === 208 || error.parent.errno === 1; // MSSQL or SQLITE.
if (isInvalidObject) {
if (GBConfigService.get('STORAGE_SYNC') !== 'true') {
throw new Error(
`Operating storage is out of sync or there is a storage connection error.
Try setting STORAGE_SYNC to true in .env file. Error: ${error.message}.`
);
);
} else {
GBLog.info(`Storage is empty. After collecting storage structure from all .gbapps it will get synced.`);
}
} else {
GBLog.info(`Storage is empty. After collecting storage structure from all .gbapps it will get synced.`);
throw new Error(`Cannot connect to operating storage: ${error.message}.`);
}
} else {
throw new Error(`Cannot connect to operating storage: ${error.message}.`);
}
}

Expand Down Expand Up @@ -429,7 +433,7 @@ STORAGE_SYNC=true
const fkcols = args[0];
let fkname = table;
let matches2 = re4.exec(fkcols);
while (matches2 !== undefined) {
while (matches2 !== null) {
fkname += `_${matches2[1]}`;
matches2 = re4.exec(fkcols);
}
Expand Down Expand Up @@ -464,7 +468,7 @@ STORAGE_SYNC=true
const fkcols = args[2];
let fkname = table;
let matches2 = re3.exec(fkcols);
while (matches2 !== undefined) {
while (matches2 !== null) {
fkname += `_${matches2[1]}`;
matches2 = re3.exec(fkcols);
}
Expand All @@ -484,8 +488,7 @@ STORAGE_SYNC=true
*/
private async openStorageFrontier(installationDeployer: IGBInstallationDeployer) {
const group = GBConfigService.get('CLOUD_GROUP');
const serverName = GBConfigService.get('STORAGE_SERVER')
.split('.database.windows.net')[0];
const serverName = GBConfigService.get('STORAGE_SERVER').split('.database.windows.net')[0];
await installationDeployer.openStorageFirewall(group, serverName);
}
}
6 changes: 3 additions & 3 deletions packages/core.gbapp/services/GBDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ export class GBDeployer {
if (additionalPath !== undefined) {
paths = paths.concat(additionalPath.toLowerCase().split(';'));
}
const botPackages: string[] = undefined;
const gbappPackages: string[] = undefined;
let generalPackages: string[];
const botPackages: string[] = [];
const gbappPackages: string[] = [];
let generalPackages: string[] = [];

function doIt(path) {
const isDirectory = source => Fs.lstatSync(source).isDirectory();
Expand Down
2 changes: 1 addition & 1 deletion packages/core.gbapp/services/GBImporterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class GBImporter {

public async importIfNotExistsBotPackage(botId: string, packageName: string, localPath: string) {
const packageJson = JSON.parse(fs.readFileSync(urlJoin(localPath, 'package.json'), 'utf8'));
if (botId !== undefined) {
if (botId === undefined) {
botId = packageJson.botId;
}
const instance = await this.core.loadInstance(botId);
Expand Down
10 changes: 5 additions & 5 deletions packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ export class GBMinService {
GBLog.error(msg);
res.send(msg);
} else {
await this.adminService.setValue(instance.instanceId, 'refreshToken', token.refreshToken);
await this.adminService.setValue(instance.instanceId, 'accessToken', token.accessToken);
await this.adminService.setValue(instance.instanceId, 'expiresOn', token.expiresOn.toString());
await this.adminService.setValue(instance.instanceId, 'AntiCSRFAttackState', undefined);
this.adminService.setValue(instance.instanceId, 'refreshToken', token.refreshToken);
this.adminService.setValue(instance.instanceId, 'accessToken', token.accessToken);
this.adminService.setValue(instance.instanceId, 'expiresOn', token.expiresOn.toString());
this.adminService.setValue(instance.instanceId, 'AntiCSRFAttackState', undefined);
res.redirect(min.instance.botEndpoint);
}
}
Expand Down Expand Up @@ -346,7 +346,7 @@ export class GBMinService {
}

private invokeLoadBot(appPackages: any[], min: GBMinInstance, server: any) {
const sysPackages : IGBPackage[] = undefined;
const sysPackages : IGBPackage[] = [];
// NOTE: A semicolon is necessary before this line.
[
GBCorePackage,
Expand Down
16 changes: 9 additions & 7 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { GBDeployer } from '../packages/core.gbapp/services/GBDeployer';
import { GBImporter } from '../packages/core.gbapp/services/GBImporterService';
import { GBMinService } from '../packages/core.gbapp/services/GBMinService';

const appPackages: IGBPackage[] = undefined;
const appPackages: IGBPackage[] = [];

/**
* General Bots open-core entry point.
Expand All @@ -64,16 +64,13 @@ export class GBServer {
GBLog.info(`The Bot Server is in STARTING mode...`);

// Creates a basic HTTP server that will serve several URL, one for each
// bot instance. This allows the same server to attend multiple Bot on
// the Marketplace until GB get serverless.
// bot instance.

const port = GBConfigService.getServerPort();
const server = express();

server.use(bodyParser.json()); // to support JSON-encoded bodies
server.use(bodyParser.json());
server.use(
bodyParser.urlencoded({
// to support URL-encoded bodies
extended: true
})
);
Expand Down Expand Up @@ -105,6 +102,7 @@ export class GBServer {
try {
await core.initStorage();
} catch (error) {
GBLog.verbose(`Error initializing storage: ${error}`);
bootInstance = await core.createBootInstance(core, azureDeployer, proxyAddress);
await core.initStorage();
}
Expand All @@ -126,7 +124,11 @@ export class GBServer {
'boot.gbot',
'packages/boot.gbot'
);
const fullInstance = { ...packageInstance, ...bootInstance };
if (bootInstance === undefined) {
bootInstance = packageInstance;
}
// tslint:disable-next-line:prefer-object-spread
const fullInstance = Object.assign(packageInstance, bootInstance);
await core.saveInstance(fullInstance);
let instances: IGBInstance[] = await core.loadAllInstances(core, azureDeployer, proxyAddress);
instances = await core.ensureInstances(instances, bootInstance, core);
Expand Down

0 comments on commit c74b3ee

Please sign in to comment.