chore(hooks): turn on prettier hook for typescript

This commit is contained in:
Phil Booth 2019-08-16 07:12:35 +01:00
Родитель 8d087d850d
Коммит 7e69761f05
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 36FBB106F9C32516
9 изменённых файлов: 108 добавлений и 94 удалений

Просмотреть файл

@ -74,6 +74,10 @@
"prettier --write",
"git add"
],
"*.ts": [
"prettier --write",
"git add"
],
"*.css": [
"prettier --write",
"git add"

Просмотреть файл

@ -1,8 +1,5 @@
{
"extends": [
"tslint:recommended",
"tslint-config-prettier"
],
"extends": ["tslint:recommended", "tslint-config-prettier"],
"rulesDirectory": ["tslint-plugin-prettier"],
"rules": {
"interface-name": [true, "never-prefix"],

Просмотреть файл

@ -1,11 +1,7 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
@ -19,7 +15,5 @@
"noEmit": true,
"jsx": "preserve"
},
"include": [
"src"
]
"include": ["src"]
}

Просмотреть файл

@ -11,61 +11,61 @@ const conf = convict({
default: 'oidc-claim-id-token-email',
doc: 'Authentication header that should be logged for the user',
env: 'AUTH_HEADER',
format: String
format: String,
},
authdbUrl: {
default: 'http://localhost:8000',
doc: 'fxa-auth-db-mysql url',
env: 'AUTHDB_URL',
format: String
format: String,
},
env: {
default: 'production',
doc: 'The current node.js environment',
env: 'NODE_ENV',
format: ['development', 'stage', 'production']
format: ['development', 'stage', 'production'],
},
listen: {
host: {
default: '127.0.0.1',
doc: 'The ip address the server should bind',
env: 'IP_ADDRESS',
format: 'ipaddress'
format: 'ipaddress',
},
port: {
default: 7100,
doc: 'The port the server should bind',
env: 'PORT',
format: 'port'
format: 'port',
},
publicUrl: {
default: 'http://127.0.0.1:3031',
env: 'PUBLIC_URL',
format: 'url'
}
format: 'url',
},
},
logging: {
app: { default: 'fxa-support-panel' },
fmt: {
default: 'heka',
env: 'LOGGING_FORMAT',
format: ['heka', 'pretty']
format: ['heka', 'pretty'],
},
level: {
default: 'info',
env: 'LOG_LEVEL'
env: 'LOG_LEVEL',
},
routes: {
enabled: {
default: true,
doc: 'Enable route logging. Set to false to trimming CI logs.',
env: 'ENABLE_ROUTE_LOGGING'
env: 'ENABLE_ROUTE_LOGGING',
},
format: {
default: 'default_fxa',
format: ['default_fxa', 'dev_fxa', 'default', 'dev', 'short', 'tiny']
}
}
format: ['default_fxa', 'dev_fxa', 'default', 'dev', 'short', 'tiny'],
},
},
},
security: {
csp: {
@ -73,10 +73,10 @@ const conf = convict({
default: 'none',
doc:
'https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors',
env: 'CSP_FRAME_ANCESTORS'
}
}
}
env: 'CSP_FRAME_ANCESTORS',
},
},
},
});
// handle configuration files. you can specify a CSV list of configuration

Просмотреть файл

@ -29,7 +29,7 @@ const queryValidator = joi
.string()
.required()
.hex()
.length(32)
.length(32),
})
.required();
@ -95,22 +95,31 @@ class SupportController {
const uid = query.uid;
const requestTicket = query.requestTicket || 'ticket-unknown';
const opts = {
json: true
json: true,
};
// This is the user who is asking for the information:
this.logger.info('infoRequest', {
authUser: request.headers[this.config.authHeader.toLowerCase()],
requestTicket,
uid
uid,
});
let account: AccountResponse;
let devices: DevicesResponse;
let subscriptions: SubscriptionResponse;
try {
[account, devices, subscriptions] = await P.all([
requests.get({ ...opts, url: `${this.config.authdbUrl}/account/${uid}` }),
requests.get({ ...opts, url: `${this.config.authdbUrl}/account/${uid}/devices` }),
requests.get({ ...opts, url: `${this.config.authdbUrl}/account/${uid}/subscriptions` })
requests.get({
...opts,
url: `${this.config.authdbUrl}/account/${uid}`,
}),
requests.get({
...opts,
url: `${this.config.authdbUrl}/account/${uid}/devices`,
}),
requests.get({
...opts,
url: `${this.config.authdbUrl}/account/${uid}/subscriptions`,
}),
]);
} catch (err) {
this.logger.error('infoFetch', { err });
@ -122,7 +131,7 @@ class SupportController {
totpResponse = await requests.get({
json: true,
resolveWithFullResponse: true,
url: `${this.config.authdbUrl}/totp/${uid}`
url: `${this.config.authdbUrl}/totp/${uid}`,
});
totpEnabled = (totpResponse.body as TotpTokenResponse).enabled;
} catch (err) {
@ -137,21 +146,29 @@ class SupportController {
const context: PanelTemplateContext = {
created: String(new Date(account.createdAt)),
devices: devices.map(d => {
return { name: d.name, type: d.type, created: String(new Date(d.createdAt)) };
return {
created: String(new Date(d.createdAt)),
name: d.name,
type: d.type,
};
}),
email: account.email,
emailVerified: !!account.emailVerified,
locale: account.locale,
subscriptionStatus: hasSubscriptions,
twoFactorAuth: totpEnabled,
uid
uid,
};
const payload = this.template(context);
return h.response(payload).code(200);
}
}
export function init(logger: Logger, config: SupportConfig, server: hapi.Server) {
export function init(
logger: Logger,
config: SupportConfig,
server: hapi.Server
) {
let rootDir;
// Check to see if we're running in a compiled form for prod/dev or testing
if (__dirname.includes('/dist/')) {
@ -163,7 +180,7 @@ export function init(logger: Logger, config: SupportConfig, server: hapi.Server)
}
const templateDir = path.join(rootDir, 'lib', 'templates');
const pageTemplate = fs.readFileSync(path.join(templateDir, 'index.html'), {
encoding: 'UTF-8'
encoding: 'UTF-8',
});
const template = handlebars.compile(pageTemplate);
@ -174,17 +191,17 @@ export function init(logger: Logger, config: SupportConfig, server: hapi.Server)
{
handler: supportController.heartbeat,
method: 'GET',
path: '/__lbheartbeat__'
path: '/__lbheartbeat__',
},
{
method: 'GET',
options: {
handler: supportController.displayUser,
validate: {
query: queryValidator as hapiJoi.ObjectSchema
}
query: queryValidator as hapiJoi.ObjectSchema,
},
},
path: '/',
},
path: '/'
}
]);
}

Просмотреть файл

@ -20,7 +20,10 @@ export type ServerConfig = api.SupportConfig & {
};
};
export async function init(serverConfig: ServerConfig, logger: Logger): Promise<hapi.Server> {
export async function init(
serverConfig: ServerConfig,
logger: Logger
): Promise<hapi.Server> {
const server = new hapi.Server({
debug: serverConfig.env === 'production' ? false : { request: ['error'] },
host: serverConfig.listen.host,
@ -30,19 +33,19 @@ export async function init(serverConfig: ServerConfig, logger: Logger): Promise<
hsts: {
includeSubDomains: true,
maxAge: 31536000,
preload: false
preload: false,
},
xss: true,
},
},
xss: true
}
}
});
await server.register([
Scooter,
{
options: Config.get('security.csp'),
plugin: Blankie
}
plugin: Blankie,
},
]);
api.init(logger, serverConfig, server);

Просмотреть файл

@ -16,7 +16,7 @@ import {
AccountResponse,
DevicesResponse,
SubscriptionResponse,
TotpTokenResponse
TotpTokenResponse,
} from '../../lib/api';
import * as supportServer from '../../lib/server';
@ -42,27 +42,27 @@ function createDefaults(): MockCallsResponse {
createdAt: now,
email: 'test@example.com',
emailVerified: true,
locale: 'en-us'
locale: 'en-us',
},
status: 200
status: 200,
},
devices: {
response: [],
status: 200
status: 200,
},
subscriptions: {
response: [],
status: 200
status: 200,
},
totp: {
response: {
enabled: true,
epoch: now,
sharedSecret: '',
verified: true
verified: true,
},
status: 200,
},
status: 200
}
};
}
@ -95,8 +95,8 @@ describe('Support Controller', () => {
env: 'development',
listen: {
host: 'localhost',
port: 8099
}
port: 8099,
},
},
logger
);
@ -111,7 +111,7 @@ describe('Support Controller', () => {
it('has a heartbeat', async () => {
const result = await server.inject({
method: 'GET',
url: '/__lbheartbeat__'
url: '/__lbheartbeat__',
});
cassert.equal(result.statusCode, 200);
});
@ -124,10 +124,10 @@ describe('Support Controller', () => {
const getWithUrl = (url: string): Promise<hapi.ServerInjectResponse> => {
return server.inject({
headers: {
testing: 'example@example.com'
testing: 'example@example.com',
},
method: 'GET',
url
url,
});
};
@ -160,7 +160,9 @@ describe('Support Controller', () => {
});
it('rejects a uid that is too long', async () => {
const result = await getWithUrl('/?uid=4a0f70e0e32a435e8066d353e8577d22a');
const result = await getWithUrl(
'/?uid=4a0f70e0e32a435e8066d353e8577d22a'
);
cassert.equal(result.statusCode, 400);
assertValidateErrorMessage(result.payload);
});
@ -198,10 +200,10 @@ describe('Support Controller', () => {
mockCalls(createDefaults());
const result = await server.inject({
headers: {
testing: 'example@example.com'
testing: 'example@example.com',
},
method: 'GET',
url: `/?uid=${uid}`
url: `/?uid=${uid}`,
});
cassert.equal(result.statusCode, 200);
const calls = (logger.info as SinonSpy).getCalls();
@ -211,8 +213,8 @@ describe('Support Controller', () => {
{
authUser: 'example@example.com',
requestTicket: 'ticket-unknown',
uid: '4a0f70e0e32a435e8066d353e8577d2a'
}
uid: '4a0f70e0e32a435e8066d353e8577d2a',
},
]);
});
@ -222,7 +224,7 @@ describe('Support Controller', () => {
mockCalls(defaults);
let result = await server.inject({
method: 'GET',
url: `/?uid=${uid}`
url: `/?uid=${uid}`,
});
cassert.equal(result.statusCode, 500);
@ -232,7 +234,7 @@ describe('Support Controller', () => {
mockCalls(defaults);
result = await server.inject({
method: 'GET',
url: `/?uid=${uid}`
url: `/?uid=${uid}`,
});
cassert.equal(result.statusCode, 500);
});
@ -243,10 +245,12 @@ describe('Support Controller', () => {
mockCalls(defaults);
const result = await server.inject({
method: 'GET',
url: `/?uid=${uid}`
url: `/?uid=${uid}`,
});
cassert.equal(result.statusCode, 200);
const payloadMatch = result.payload.match(/2FA enabled\?<\/th>\s*<td>\s*no/g);
const payloadMatch = result.payload.match(
/2FA enabled\?<\/th>\s*<td>\s*no/g
);
cassert.isTrue(payloadMatch && payloadMatch.length === 1);
});
@ -256,7 +260,7 @@ describe('Support Controller', () => {
mockCalls(defaults);
const result = await server.inject({
method: 'GET',
url: `/?uid=${uid}`
url: `/?uid=${uid}`,
});
cassert.equal(result.statusCode, 500);
});

Просмотреть файл

@ -18,7 +18,5 @@
"./test/**/*",
"./types/**/*"
],
"exclude": [
"node_modules"
]
"exclude": ["node_modules"]
}

Просмотреть файл

@ -1,8 +1,5 @@
{
"extends": [
"tslint:recommended",
"tslint-config-prettier"
],
"extends": ["tslint:recommended", "tslint-config-prettier"],
"rulesDirectory": ["tslint-plugin-prettier"],
"rules": {
"interface-name": [true, "never-prefix"],