Skip to content

Commit cb10a16

Browse files
committed
chore: removed unnecessary type declarations
1 parent 2bc1d9c commit cb10a16

Some content is hidden

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

70 files changed

+465
-537
lines changed

.eslintrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"no-extra-semi": "off",
3030
"@typescript-eslint/no-extra-semi": "error",
3131
"@typescript-eslint/no-empty-interface": "warn",
32-
"@typescript-eslint/no-inferrable-types": "off",
32+
"@typescript-eslint/no-inferrable-types": "error",
3333
"@typescript-eslint/explicit-function-return-type": "error",
3434
"one-var": [
3535
"error",

src/cache.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { config, disabledFeatures } from '@/config-manager';
44

55
let client: redis.RedisClientType;
66

7-
const memoryCache: { [key: string]: Buffer } = {};
7+
const memoryCache: Record<string, Buffer> = {};
88

9-
const LOCAL_CDN_BASE: string = `${__dirname}/../cdn`;
9+
const LOCAL_CDN_BASE = `${__dirname}/../cdn`;
1010

1111
export async function connect(): Promise<void> {
1212
if (!disabledFeatures.redis) {
@@ -26,12 +26,12 @@ export async function setCachedFile(fileName: string, value: Buffer): Promise<vo
2626
}
2727

2828
export async function getCachedFile(fileName: string, encoding?: BufferEncoding): Promise<Buffer> {
29-
let cachedFile: Buffer = Buffer.alloc(0);
29+
let cachedFile = Buffer.alloc(0);
3030

3131
if (disabledFeatures.redis) {
3232
cachedFile = memoryCache[fileName] || null;
3333
} else {
34-
const redisValue: string | null = await client.get(fileName);
34+
const redisValue = await client.get(fileName);
3535
if (redisValue) {
3636
cachedFile = Buffer.from(redisValue, encoding);
3737
}
@@ -43,11 +43,11 @@ export async function getCachedFile(fileName: string, encoding?: BufferEncoding)
4343
// * Local CDN cache functions
4444

4545
export async function getLocalCDNFile(name: string, encoding?: BufferEncoding): Promise<Buffer> {
46-
let file: Buffer = await getCachedFile(`local_cdn:${name}`, encoding);
46+
let file = await getCachedFile(`local_cdn:${name}`, encoding);
4747

4848
if (file === null) {
4949
if (await fs.pathExists(`${LOCAL_CDN_BASE}/${name}`)) {
50-
const fileBuffer: string | Buffer = await fs.readFile(`${LOCAL_CDN_BASE}/${name}`, { encoding });
50+
const fileBuffer = await fs.readFile(`${LOCAL_CDN_BASE}/${name}`, { encoding });
5151
file = Buffer.from(fileBuffer);
5252
await setLocalCDNFile(name, file);
5353
}

src/config-manager.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import fs from 'fs-extra';
22
import mongoose from 'mongoose';
33
import dotenv from 'dotenv';
44
import { LOG_INFO, LOG_WARN, LOG_ERROR } from '@/logger';
5-
import { Config, DisabledFeatures } from '@/types/common/config';
5+
import { Config } from '@/types/common/config';
66

77
dotenv.config();
88

9-
export const disabledFeatures: DisabledFeatures = {
9+
export const disabledFeatures = {
1010
redis: false,
1111
email: false,
1212
captcha: false,

src/database.ts

+19-22
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@ import { Server } from '@/models/server';
77
import { LOG_ERROR } from '@/logger';
88
import { config } from '@/config-manager';
99
import { HydratedPNIDDocument } from '@/types/mongoose/pnid';
10-
import { IDevice } from '@/types/mongoose/device';
1110
import { IDeviceAttribute } from '@/types/mongoose/device-attribute';
1211
import { HydratedServerDocument } from '@/types/mongoose/server';
13-
import { Token } from '@/types/common/token';
1412
import { PNIDProfile } from '@/types/services/nnas/pnid-profile';
1513
import { ConnectionData } from '@/types/services/api/connection-data';
1614
import { ConnectionResponse } from '@/types/services/api/connection-response';
1715
import { DiscordConnectionData } from '@/types/services/api/discord-connection-data';
1816

19-
const connection_string: string = config.mongoose.connection_string;
20-
const options: mongoose.ConnectOptions = config.mongoose.options;
17+
const connection_string = config.mongoose.connection_string;
18+
const options = config.mongoose.options;
2119

2220
// TODO: Extend this later with more settings
23-
const discordConnectionSchema: joi.ObjectSchema = joi.object({
21+
const discordConnectionSchema = joi.object({
2422
id: joi.string()
2523
});
2624

@@ -79,19 +77,19 @@ export async function getPNIDByBasicAuth(token: string): Promise<HydratedPNIDDoc
7977

8078
// * Wii U sends Basic auth as `username password`, where the password may not have spaces
8179
// * This is not to spec, but that is the consoles fault not ours
82-
const decoded: string = Buffer.from(token, 'base64').toString();
83-
const parts: string[] = decoded.split(' ');
80+
const decoded = Buffer.from(token, 'base64').toString();
81+
const parts = decoded.split(' ');
8482

85-
const username: string = parts[0];
86-
const password: string = parts[1];
83+
const username = parts[0];
84+
const password = parts[1];
8785

88-
const pnid: HydratedPNIDDocument | null = await getPNIDByUsername(username);
86+
const pnid = await getPNIDByUsername(username);
8987

9088
if (!pnid) {
9189
return null;
9290
}
9391

94-
const hashedPassword: string = nintendoPasswordHash(password, pnid.pid);
92+
const hashedPassword = nintendoPasswordHash(password, pnid.pid);
9593

9694
if (!bcrypt.compareSync(hashedPassword, pnid.password)) {
9795
return null;
@@ -104,13 +102,12 @@ export async function getPNIDByTokenAuth(token: string): Promise<HydratedPNIDDoc
104102
verifyConnected();
105103

106104
try {
107-
const decryptedToken: Buffer = decryptToken(Buffer.from(token, 'hex'));
108-
const unpackedToken: Token = unpackToken(decryptedToken);
109-
110-
const pnid: HydratedPNIDDocument | null = await getPNIDByPID(unpackedToken.pid);
105+
const decryptedToken = decryptToken(Buffer.from(token, 'hex'));
106+
const unpackedToken = unpackToken(decryptedToken);
107+
const pnid = await getPNIDByPID(unpackedToken.pid);
111108

112109
if (pnid) {
113-
const expireTime: number = Math.floor((Number(unpackedToken.expire_time) / 1000));
110+
const expireTime = Math.floor((Number(unpackedToken.expire_time) / 1000));
114111

115112
if (Math.floor(Date.now() / 1000) > expireTime) {
116113
return null;
@@ -128,13 +125,13 @@ export async function getPNIDByTokenAuth(token: string): Promise<HydratedPNIDDoc
128125
export async function getPNIDProfileJSONByPID(pid: number): Promise<PNIDProfile | null> {
129126
verifyConnected();
130127

131-
const pnid: HydratedPNIDDocument | null = await getPNIDByPID(pid);
128+
const pnid = await getPNIDByPID(pid);
132129

133130
if (!pnid) {
134131
return null;
135132
}
136133

137-
const device: IDevice = pnid.devices[0]; // * Just grab the first device
134+
const device = pnid.devices[0]; // * Just grab the first device
138135
let device_attributes: {
139136
device_attribute: {
140137
name: string;
@@ -145,9 +142,9 @@ export async function getPNIDProfileJSONByPID(pid: number): Promise<PNIDProfile
145142

146143
if (device) {
147144
device_attributes = device.device_attributes.map((attribute: IDeviceAttribute) => {
148-
const name: string = attribute.name;
149-
const value: string = attribute.value;
150-
const created_date: string | undefined = attribute.created_date;
145+
const name = attribute.name;
146+
const value = attribute.value;
147+
const created_date = attribute.created_date;
151148

152149
return {
153150
device_attribute: {
@@ -237,7 +234,7 @@ export async function addPNIDConnection(pnid: HydratedPNIDDocument, data: Connec
237234
}
238235

239236
export async function addPNIDConnectionDiscord(pnid: HydratedPNIDDocument, data: DiscordConnectionData): Promise<ConnectionResponse> {
240-
const valid: joi.ValidationResult = discordConnectionSchema.validate(data);
237+
const valid = discordConnectionSchema.validate(data);
241238

242239
if (valid.error) {
243240
return {

src/logger.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import colors from 'colors';
33

44
colors.enable();
55

6-
const root: string = process.env.PN_ACT_LOGGER_PATH ? process.env.PN_ACT_LOGGER_PATH : `${__dirname}/..`;
6+
const root = process.env.PN_ACT_LOGGER_PATH ? process.env.PN_ACT_LOGGER_PATH : `${__dirname}/..`;
77
fs.ensureDirSync(`${root}/logs`);
88

99
const streams = {
@@ -15,31 +15,31 @@ const streams = {
1515
} as const;
1616

1717
export function LOG_SUCCESS(input: string): void {
18-
const time: Date = new Date();
18+
const time = new Date();
1919
input = `[${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}] [SUCCESS]: ${input}`;
2020
streams.success.write(`${input}\n`);
2121

2222
console.log(`${input}`.green.bold);
2323
}
2424

2525
export function LOG_ERROR(input: string): void {
26-
const time: Date = new Date();
26+
const time = new Date();
2727
input = `[${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}] [ERROR]: ${input}`;
2828
streams.error.write(`${input}\n`);
2929

3030
console.log(`${input}`.red.bold);
3131
}
3232

3333
export function LOG_WARN(input: string): void {
34-
const time: Date = new Date();
34+
const time = new Date();
3535
input = `[${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}] [WARN]: ${input}`;
3636
streams.warn.write(`${input}\n`);
3737

3838
console.log(`${input}`.yellow.bold);
3939
}
4040

4141
export function LOG_INFO(input: string): void {
42-
const time: Date = new Date();
42+
const time = new Date();
4343
input = `[${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}] [INFO]: ${input}`;
4444
streams.info.write(`${input}\n`);
4545

src/mailer.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import * as aws from '@aws-sdk/client-ses';
55
import { config, disabledFeatures } from '@/config-manager';
66
import { MailerOptions } from '@/types/common/mailer-options';
77

8-
const genericEmailTemplate: string = fs.readFileSync(path.join(__dirname, './assets/emails/genericTemplate.html'), 'utf8');
9-
const confirmationEmailTemplate: string = fs.readFileSync(path.join(__dirname, './assets/emails/confirmationTemplate.html'), 'utf8');
8+
const genericEmailTemplate = fs.readFileSync(path.join(__dirname, './assets/emails/genericTemplate.html'), 'utf8');
9+
const confirmationEmailTemplate = fs.readFileSync(path.join(__dirname, './assets/emails/confirmationTemplate.html'), 'utf8');
1010

1111
let transporter: nodemailer.Transporter;
1212

@@ -32,7 +32,7 @@ export async function sendMail(options: MailerOptions): Promise<void> {
3232
if (!disabledFeatures.email) {
3333
const { to, subject, username, paragraph, preview, text, link, confirmation } = options;
3434

35-
let html: string = confirmation ? confirmationEmailTemplate : genericEmailTemplate;
35+
let html = confirmation ? confirmationEmailTemplate : genericEmailTemplate;
3636

3737
html = html.replace(/{{username}}/g, username);
3838
html = html.replace(/{{paragraph}}/g, paragraph || '');
@@ -43,7 +43,7 @@ export async function sendMail(options: MailerOptions): Promise<void> {
4343
if (link) {
4444
const { href, text } = link;
4545

46-
const button: string = `<tr><td width="100%" height="16px" style="line-height: 16px;">&nbsp;</td></tr><tr><td class="confirm-link" bgcolor="#673db6" style="font-size: 14px; font-weight: 700; border-radius: 10px; padding: 12px" align="center"><a href="${href}" style="text-decoration: none; color: #ffffff; " width="100%">${text}</a></td></tr>`;
46+
const button = `<tr><td width="100%" height="16px" style="line-height: 16px;">&nbsp;</td></tr><tr><td class="confirm-link" bgcolor="#673db6" style="font-size: 14px; font-weight: 700; border-radius: 10px; padding: 12px" align="center"><a href="${href}" style="text-decoration: none; color: #ffffff; " width="100%">${text}</a></td></tr>`;
4747
html = html.replace(/<!--{{buttonPlaceholder}}-->/g, button);
4848
}
4949

src/middleware/api.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import express from 'express';
22
import { getValueFromHeaders } from '@/util';
33
import { getPNIDByTokenAuth } from '@/database';
4-
import { HydratedPNIDDocument } from '@/types/mongoose/pnid';
54

65
async function APIMiddleware(request: express.Request, _response: express.Response, next: express.NextFunction): Promise<void> {
7-
const authHeader: string | undefined = getValueFromHeaders(request.headers, 'authorization');
6+
const authHeader = getValueFromHeaders(request.headers, 'authorization');
87

98
if (!authHeader || !(authHeader.startsWith('Bearer'))) {
109
return next();
1110
}
1211

1312
try {
14-
const token: string = authHeader.split(' ')[1];
15-
const pnid: HydratedPNIDDocument | null = await getPNIDByTokenAuth(token);
13+
const token = authHeader.split(' ')[1];
14+
const pnid = await getPNIDByTokenAuth(token);
1615

1716
request.pnid = pnid;
1817
} catch (error) {

src/middleware/cemu.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import express from 'express';
22

33
function CemuMiddleware(request: express.Request, _response: express.Response, next: express.NextFunction): void {
4-
const subdomain: string = request.subdomains.reverse().join('.');
4+
const subdomain = request.subdomains.reverse().join('.');
55

66
request.isCemu = subdomain === 'c.account';
77

src/middleware/client-header.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import express from 'express';
22
import xmlbuilder from 'xmlbuilder';
33
import { getValueFromHeaders } from '@/util';
44

5-
const VALID_CLIENT_ID_SECRET_PAIRS: { [key: string]: string } = {
5+
const VALID_CLIENT_ID_SECRET_PAIRS: Record<string, string> = {
66
// * 'Key' is the client ID, 'Value' is the client secret
77
'a2efa818a34fa16b8afbc8a74eba3eda': 'c91cdb5658bd4954ade78533a339cf9a', // * Possibly WiiU exclusive?
88
'daf6227853bcbdce3d75baee8332b': '3eff548eac636e2bf45bb7b375e7b6b0', // * Possibly 3DS exclusive?
@@ -14,8 +14,8 @@ function nintendoClientHeaderCheck(request: express.Request, response: express.R
1414
response.set('Server', 'Nintendo 3DS (http)');
1515
response.set('X-Nintendo-Date', new Date().getTime().toString());
1616

17-
const clientId: string | undefined = getValueFromHeaders(request.headers, 'x-nintendo-client-id');
18-
const clientSecret: string | undefined = getValueFromHeaders(request.headers, 'x-nintendo-client-secret');
17+
const clientId = getValueFromHeaders(request.headers, 'x-nintendo-client-id');
18+
const clientSecret = getValueFromHeaders(request.headers, 'x-nintendo-client-secret');
1919

2020
if (
2121
!clientId ||

src/middleware/console-status-verification.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import express from 'express';
33
import xmlbuilder from 'xmlbuilder';
44
import { Device } from '@/models/device';
55
import { getValueFromHeaders } from '@/util';
6-
import { HydratedDeviceDocument } from '@/types/mongoose/device';
76

87
async function consoleStatusVerificationMiddleware(request: express.Request, response: express.Response, next: express.NextFunction): Promise<void> {
98
if (!request.certificate || !request.certificate.valid) {
@@ -17,7 +16,7 @@ async function consoleStatusVerificationMiddleware(request: express.Request, res
1716
return;
1817
}
1918

20-
const deviceIDHeader: string | undefined = getValueFromHeaders(request.headers, 'x-nintendo-device-id');
19+
const deviceIDHeader = getValueFromHeaders(request.headers, 'x-nintendo-device-id');
2120

2221
if (!deviceIDHeader) {
2322
response.status(400).send(xmlbuilder.create({
@@ -30,7 +29,7 @@ async function consoleStatusVerificationMiddleware(request: express.Request, res
3029
return;
3130
}
3231

33-
const deviceID: number = Number(deviceIDHeader);
32+
const deviceID = Number(deviceIDHeader);
3433

3534
if (isNaN(deviceID)) {
3635
response.status(400).send(xmlbuilder.create({
@@ -43,7 +42,7 @@ async function consoleStatusVerificationMiddleware(request: express.Request, res
4342
return;
4443
}
4544

46-
const serialNumber: string | undefined = getValueFromHeaders(request.headers, 'x-nintendo-serial-number');
45+
const serialNumber = getValueFromHeaders(request.headers, 'x-nintendo-serial-number');
4746

4847
// TODO - Verify serial numbers somehow?
4948
// * This is difficult to do safely because serial numbers are
@@ -72,7 +71,7 @@ async function consoleStatusVerificationMiddleware(request: express.Request, res
7271
// * This is kinda temp for now. Needs to be redone to handle linking this data to existing 3DS devices in the DB
7372
// TODO - 3DS consoles are created in the NASC middleware. They need special handling to link them up with the data in the NNID API!
7473
if (request.certificate.consoleType === 'wiiu') {
75-
const certificateDeviceID: number = parseInt(request.certificate.certificateName.slice(2), 16);
74+
const certificateDeviceID = parseInt(request.certificate.certificateName.slice(2), 16);
7675

7776
if (deviceID !== certificateDeviceID) {
7877
// TODO - Change this to a different error
@@ -88,9 +87,9 @@ async function consoleStatusVerificationMiddleware(request: express.Request, res
8887
}
8988

9089
// * Only store a hash of the certificate in case of a breach
91-
const certificateHash: string = crypto.createHash('sha256').update(request.certificate._certificate).digest('base64');
90+
const certificateHash = crypto.createHash('sha256').update(request.certificate._certificate).digest('base64');
9291

93-
let device: HydratedDeviceDocument | null = await Device.findOne({
92+
let device = await Device.findOne({
9493
certificate_hash: certificateHash,
9594
});
9695

src/middleware/device-certificate.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import NintendoCertificate from '@/nintendo-certificate';
33
import { getValueFromHeaders } from '@/util';
44

55
function deviceCertificateMiddleware(request: express.Request, _response: express.Response, next: express.NextFunction): void {
6-
const certificate: string | undefined = getValueFromHeaders(request.headers, 'x-nintendo-device-cert');
6+
const certificate = getValueFromHeaders(request.headers, 'x-nintendo-device-cert');
77

88
if (!certificate) {
99
return next();

0 commit comments

Comments
 (0)