Skip to content

Commit d9ab8ce

Browse files
chore: eslint cleanup and code changes accordingly (#586)
1 parent 9787b88 commit d9ab8ce

File tree

260 files changed

+1416
-1516
lines changed

Some content is hidden

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

260 files changed

+1416
-1516
lines changed

.eslintrc.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,40 @@
44
module.exports = {
55
root: true,
66
parser: '@typescript-eslint/parser',
7-
plugins: ['@typescript-eslint', 'prettier', 'drizzle', '@u22n/custom'],
8-
extends: ['prettier', 'plugin:drizzle/all'],
7+
plugins: ['@typescript-eslint', 'drizzle'],
8+
parserOptions: {
9+
project: true
10+
},
11+
extends: [
12+
'plugin:drizzle/all',
13+
'plugin:@typescript-eslint/recommended-type-checked',
14+
'plugin:@typescript-eslint/stylistic-type-checked'
15+
],
916
rules: {
10-
semi: [2, 'always']
17+
'@typescript-eslint/array-type': 'off',
18+
'@typescript-eslint/consistent-type-definitions': 'off',
19+
'@typescript-eslint/consistent-type-imports': [
20+
'warn',
21+
{ prefer: 'type-imports', fixStyle: 'inline-type-imports' }
22+
],
23+
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
24+
'@typescript-eslint/require-await': 'off',
25+
'@typescript-eslint/no-misused-promises': [
26+
'error',
27+
{ checksVoidReturn: { attributes: false } }
28+
],
29+
'no-console': ['error', { allow: ['info', 'warn', 'trace', 'error'] }]
1130
},
1231
overrides: [
1332
{
14-
files: ['*'],
15-
rules: {
16-
'no-console': [
17-
'error',
18-
{
19-
allow: ['info', 'warn', 'trace', 'error']
20-
}
21-
]
22-
}
33+
files: ['./packages/database/**/*'],
34+
plugins: ['@u22n/custom'],
35+
rules: { '@u22n/custom/table-needs-org-id': 'error' }
2336
},
2437
{
25-
files: ['./packages/database/**/*'],
26-
rules: {
27-
'@u22n/custom/table-needs-org-id': 'error'
28-
}
38+
files: ['./apps/web/**/*'],
39+
extends: ['next/core-web-vitals'],
40+
rules: { 'react/no-children-prop': ['warn', { allowFunctions: true }] }
2941
}
3042
]
3143
};

apps/mail-bridge/app.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
import { env } from './env';
2-
import { db } from '@u22n/database';
3-
import { trpcMailBridgeRouter } from './trpc';
4-
import { eventApi } from './postal-routes/events';
5-
import { inboundApi } from './postal-routes/inbound';
6-
import { signatureMiddleware } from './postal-routes/signature-middleware';
7-
import { opentelemetry } from '@u22n/otel/hono';
8-
import type { Ctx, TRPCContext } from './ctx';
91
import {
102
createHonoApp,
113
setupErrorHandlers,
@@ -15,6 +7,14 @@ import {
157
setupRuntime,
168
setupTrpcHandler
179
} from '@u22n/hono';
10+
import { signatureMiddleware } from './postal-routes/signature-middleware';
11+
import { inboundApi } from './postal-routes/inbound';
12+
import { eventApi } from './postal-routes/events';
13+
import { opentelemetry } from '@u22n/otel/hono';
14+
import { trpcMailBridgeRouter } from './trpc';
15+
import type { Ctx, TRPCContext } from './ctx';
16+
import { db } from '@u22n/database';
17+
import { env } from './env';
1818

1919
const processCleanup: Array<() => Promise<void>> = [];
2020

apps/mail-bridge/ctx.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { db } from '@u22n/database';
2-
import type { env } from './env';
31
import type { Context } from '@u22n/hono/helpers';
42
import type { HonoContext } from '@u22n/hono';
3+
import type { db } from '@u22n/database';
4+
import type { env } from './env';
55

66
export type Ctx = HonoContext;
77

apps/mail-bridge/postal-db/functions.ts

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
import { connection as rawMySqlConnection, postalDB } from '.';
1+
import {
2+
lookupCNAME,
3+
lookupMX,
4+
lookupTXT,
5+
buildDkimRecord,
6+
buildSpfRecord,
7+
parseDkim,
8+
parseSpfIncludes,
9+
parseDmarc,
10+
buildDmarcRecord
11+
} from '@u22n/utils/dns';
212
import {
313
organizations,
414
domains,
@@ -9,25 +19,15 @@ import {
919
httpEndpoints,
1020
routes
1121
} from './schema';
12-
import { randomUUID } from 'node:crypto';
1322
import {
1423
generateDKIMKeyPair,
1524
generatePublicKey,
1625
getUniqueDKIMSelector,
1726
randomAlphaNumeric
1827
} from './generators';
28+
import { connection as rawMySqlConnection, postalDB } from '.';
1929
import { and, eq, sql } from 'drizzle-orm';
20-
import {
21-
lookupCNAME,
22-
lookupMX,
23-
lookupTXT,
24-
buildDkimRecord,
25-
buildSpfRecord,
26-
parseDkim,
27-
parseSpfIncludes,
28-
parseDmarc,
29-
buildDmarcRecord
30-
} from '@u22n/utils/dns';
30+
import { randomUUID } from 'node:crypto';
3131
import { env } from '../env';
3232

3333
export type CreateOrgInput = {
@@ -125,7 +125,7 @@ export type GetDomainDNSRecordsOutput =
125125
export async function getDomainDNSRecords(
126126
domainId: string,
127127
postalServerUrl: string,
128-
forceReverify: boolean = false
128+
forceReverify = false
129129
): Promise<GetDomainDNSRecordsOutput> {
130130
const domainInfo = await postalDB.query.domains.findFirst({
131131
where: eq(domains.uuid, domainId)
@@ -204,27 +204,27 @@ export async function getDomainDNSRecords(
204204

205205
const spfDomains = txtRecords.success
206206
? parseSpfIncludes(
207-
txtRecords.data.find((_) => _.startsWith('v=spf1')) || ''
207+
txtRecords.data.find((_) => _.startsWith('v=spf1')) ?? ''
208208
)
209209
: null;
210210
records.spf.name = '@';
211211
records.spf.extraSenders =
212212
(spfDomains &&
213213
spfDomains.includes.filter((x) => x !== `_spf.${dnsRootUrl}`).length >
214-
0) ||
214+
0) ??
215215
false;
216216

217217
// We need to resolve duplicate entries incase the spf record is already included, so that we don't have duplicate entries
218218
const allSenders = Array.from(
219219
new Set([
220220
`_spf.${dnsRootUrl}`,
221-
...(records.spf.extraSenders ? spfDomains?.includes || [] : [])
221+
...(records.spf.extraSenders ? spfDomains?.includes ?? [] : [])
222222
]).values()
223223
);
224224

225225
records.spf.value = buildSpfRecord(allSenders, '~all');
226226
records.spf.valid =
227-
(spfDomains && spfDomains.includes.includes(`_spf.${dnsRootUrl}`)) || false;
227+
spfDomains?.includes.includes(`_spf.${dnsRootUrl}`) ?? false;
228228

229229
if (!records.spf.valid || domainInfo.spfStatus !== 'OK' || forceReverify) {
230230
await postalDB
@@ -262,13 +262,9 @@ export async function getDomainDNSRecords(
262262
.where(eq(domains.uuid, domainId));
263263
} else {
264264
const domainKey = parseDkim(
265-
domainKeyRecords.data.find((_) => _.startsWith('v=DKIM1')) || ''
265+
domainKeyRecords.data.find((_) => _.startsWith('v=DKIM1')) ?? ''
266266
);
267-
if (
268-
!domainKey ||
269-
domainKey['h'] !== 'sha256' ||
270-
domainKey['p'] !== publicKey
271-
) {
267+
if (!domainKey || domainKey.h !== 'sha256' || domainKey.p !== publicKey) {
272268
records.dkim.valid = false;
273269
await postalDB
274270
.update(domains)
@@ -350,11 +346,11 @@ export async function getDomainDNSRecords(
350346
const dmarcRecord = await lookupTXT(`_dmarc.${domainInfo.name}`);
351347
if (dmarcRecord.success && dmarcRecord.data.length > 0) {
352348
const dmarcValues = parseDmarc(
353-
dmarcRecord.data.find((_) => _.startsWith('v=DMARC1')) || ''
349+
dmarcRecord.data.find((_) => _.startsWith('v=DMARC1')) ?? ''
354350
);
355351
if (dmarcValues) {
356352
records.dmarc.policy =
357-
(dmarcValues['p'] as 'reject' | 'quarantine' | 'none') || null;
353+
(dmarcValues.p as 'reject' | 'quarantine' | 'none') || null;
358354
}
359355
}
360356
records.dmarc.name = '_dmarc';
@@ -524,7 +520,7 @@ export async function setMailServerRouteForDomain(
524520
id: true
525521
}
526522
});
527-
if (!domainQuery || !domainQuery.id) {
523+
if (!domainQuery?.id) {
528524
throw new Error('Domain not found');
529525
}
530526
const domainId = domainQuery.id;

apps/mail-bridge/postal-db/generators.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {
33
createPublicKey
44
} from 'node:crypto';
55
import { customAlphabet } from 'nanoid';
6+
import { domains } from './schema';
7+
import { eq } from 'drizzle-orm';
68
import { promisify } from 'util';
79
import { postalDB } from '.';
8-
import { eq } from 'drizzle-orm';
9-
import { domains } from './schema';
1010

1111
export const randomAlphaNumeric = customAlphabet(
1212
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'

apps/mail-bridge/postal-db/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { activePostalServer, env } from '../env';
12
import { drizzle } from 'drizzle-orm/mysql2';
23
import mysql from 'mysql2/promise';
34
import * as schema from './schema';
4-
import { activePostalServer, env } from '../env';
55

66
const isLocal = env.MAILBRIDGE_LOCAL_MODE;
77
export const connection = mysql.createPool({

apps/mail-bridge/postal-routes/inbound.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import {
22
postalMessageSchema,
33
mailParamsSchema
44
} from '../queue/mail-processor/schemas';
5-
import type { Ctx } from '../ctx';
65
import { mailProcessorQueue } from '../queue/mail-processor';
7-
import { createHonoApp } from '@u22n/hono';
86
import { zValidator } from '@u22n/hono/helpers';
7+
import { createHonoApp } from '@u22n/hono';
8+
import type { Ctx } from '../ctx';
99

1010
export const inboundApi = createHonoApp<Ctx>();
1111

apps/mail-bridge/postal-routes/signature-middleware.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { env } from '../env';
21
import { validatePostalWebhookSignature } from '../utils/validatePostalWebhookSignature';
3-
import type { Ctx } from '../ctx';
42
import { createMiddleware } from '@u22n/hono/helpers';
53
import { getTracer } from '@u22n/otel/helpers';
64
import { flatten } from '@u22n/otel/exports';
5+
import type { Ctx } from '../ctx';
6+
import { env } from '../env';
77

88
const middlewareTracer = getTracer('mail-bridge/hono/middleware');
99

@@ -15,7 +15,7 @@ export const signatureMiddleware = createMiddleware<Ctx>(async (c, next) =>
1515
span?.recordException(new Error(`Method not allowed, ${c.req.method}`));
1616
return c.json({ message: 'Method not allowed' }, 405);
1717
}
18-
const body = await c.req.json().catch(() => ({}));
18+
const body = (await c.req.json().catch(() => ({}))) as unknown;
1919
const signature = c.req.header('x-postal-signature');
2020
if (!signature) {
2121
span?.recordException(new Error('Missing signature'));

apps/mail-bridge/queue/mail-processor/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Queue } from 'bullmq';
2-
import { env } from '../../env';
31
import type { MailParamsSchema, PostalMessageSchema } from './schemas';
2+
import { env } from '../../env';
3+
import { Queue } from 'bullmq';
44

55
const { host, username, password, port } = new URL(
66
env.DB_REDIS_CONNECTION_STRING

0 commit comments

Comments
 (0)