Skip to content

Commit a7da207

Browse files
committed
fix: remove reliance on non-standard predicate in type indexes
See also: solid/type-indexes#29 solidcouch/solidcouch#135 And somehow also switch to ESM, change tsconfig, and switch to vitest
1 parent 4597e88 commit a7da207

27 files changed

+791
-359
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
dist
22
apidocs
3+
vitest.config.ts

.mocharc.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "simple-email-notifications",
33
"version": "0.0.1",
4+
"type": "module",
45
"main": "dist/index.js",
56
"scripts": {
67
"start": "yarn build && node dist/index.js",
78
"build": "rm -rf dist && tsc --project tsconfig.production.json && yarn copy-hbs",
89
"copy-hbs": "cp src/templates/*.hbs dist/templates && cp src/templates/*.css dist/templates",
910
"format": "prettier 'src/**/*.ts' '**/*.{md,yml,yaml,json}' --write",
1011
"lint": "eslint . --ext .ts",
11-
"test": "mocha",
12+
"test": "NODE_ENV=vitest vitest",
1213
"generate-key": "openssl ecparam -name prime256v1 -genkey -noout -out ecdsa-p256-private.pem",
1314
"generate-api-docs": "tsc && node dist/generate-api-docs.js"
1415
},
@@ -17,7 +18,6 @@
1718
"@solid/community-server": "^7.0.2",
1819
"@types/chai": "^4.3.5",
1920
"@types/maildev": "^0.0.7",
20-
"@types/mocha": "^10.0.1",
2121
"@types/sinon": "^10.0.15",
2222
"@typescript-eslint/eslint-plugin": "^6.0.0",
2323
"@typescript-eslint/parser": "^6.19.0",
@@ -30,19 +30,19 @@
3030
"eslint-plugin-import": "^2.29.1",
3131
"eslint-plugin-prettier": "^5.0.0",
3232
"maildev": "^2.1.0",
33-
"mocha": "^10.2.0",
3433
"msw": "^2.0.14",
3534
"prettier": "^3.0.0",
3635
"puppeteer": "^22.2.0",
3736
"sinon": "^15.2.0",
3837
"swagger-autogen": "^2.23.6",
39-
"ts-node": "^10.9.1"
38+
"ts-node": "^10.9.1",
39+
"vitest": "^3.0.4"
4040
},
4141
"dependencies": {
4242
"@koa/bodyparser": "^5.0.0",
4343
"@koa/cors": "^4.0.0",
4444
"@koa/router": "^12.0.0",
45-
"@ldhop/core": "^0.0.0-alpha.1",
45+
"@ldhop/core": "^0.1.0",
4646
"@solid/access-token-verifier": "^2.0.5",
4747
"@types/co-body": "^6.1.0",
4848
"@types/fs-extra": "^11.0.4",
@@ -53,7 +53,7 @@
5353
"@types/koa__router": "^12.0.0",
5454
"@types/lodash": "^4.14.196",
5555
"@types/n3": "^1.16.0",
56-
"@types/node": "^20.4.2",
56+
"@types/node": "^22.12.0",
5757
"@types/nodemailer": "^6.4.9",
5858
"ajv": "^8.12.0",
5959
"ajv-formats": "^2.1.1",
@@ -71,5 +71,6 @@
7171
"nodemailer": "^6.9.4",
7272
"rdf-namespaces": "^1.11.0",
7373
"typescript": "^5.1.6"
74-
}
74+
},
75+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
7576
}

src/app.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import bodyParser from '@koa/bodyparser'
1+
import { bodyParser } from '@koa/bodyparser'
22
import cors from '@koa/cors'
33
import Router from '@koa/router'
44
import Koa from 'koa'
55
import helmet from 'koa-helmet'
66
import serve from 'koa-static'
7-
import { allowedGroups, isBehindProxy } from './config'
7+
import { allowedGroups, isBehindProxy } from './config/index.js'
88
import {
99
checkVerificationLink,
1010
finishIntegration,
1111
initializeIntegration,
12-
} from './controllers/integration'
13-
import { notification } from './controllers/notification'
14-
import { getStatus } from './controllers/status'
12+
} from './controllers/integration.js'
13+
import { notification } from './controllers/notification.js'
14+
import { getStatus } from './controllers/status.js'
1515
import {
1616
authorizeGroups,
1717
checkGroupMembership,
18-
} from './middlewares/authorizeGroup'
19-
import { solidAuth } from './middlewares/solidAuth'
20-
import { validateBody } from './middlewares/validate'
21-
import * as schema from './schema'
18+
} from './middlewares/authorizeGroup.js'
19+
import { solidAuth } from './middlewares/solidAuth.js'
20+
import { validateBody } from './middlewares/validate.js'
21+
import * as schema from './schema.js'
2222

2323
const app = new Koa()
2424
app.proxy = isBehindProxy

src/config/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import SMTPTransport from 'nodemailer/lib/smtp-transport'
55
// either via .env file, or via environment variables directly (depends on your setup)
66

77
// server base url, e.g. to construct correct email verification links
8-
export const baseUrl = process.env.BASE_URL ?? 'http://localhost:3005'
8+
// export const baseUrl = process.env.BASE_URL ?? 'http://localhost:3005'
9+
export const port: number = +(process.env.PORT ?? 3005)
10+
11+
export const baseUrl =
12+
process.env.NODE_ENV === 'vitest' || !process.env.BASE_URL
13+
? `http://localhost:${port}`
14+
: process.env.BASE_URL
915

1016
export const appName = process.env.APP_NAME ?? 'Tired.bike'
1117

@@ -51,8 +57,6 @@ export const smtpTransportOptions: SMTPTransport.Options = {
5157
export const emailSender =
5258
process.env.EMAIL_SENDER ?? 'noreply@notifications.tired.bike'
5359

54-
export const port: number = +(process.env.PORT ?? 3005)
55-
5660
// email verification expiration in seconds (1 hour)
5761
export const emailVerificationExpiration = 3600
5862

src/controllers/integration.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { readFile } from 'fs-extra'
21
import * as jsonwebtoken from 'jsonwebtoken'
3-
import { JsonWebTokenError, TokenExpiredError } from 'jsonwebtoken'
42
import { Middleware } from 'koa'
5-
import { pick } from 'lodash'
6-
import * as config from '../config'
7-
import { sendMail } from '../services/mailerService'
8-
import { generateHtmlMessage } from '../templates/generateMessage'
9-
import { findWritableSettings, getBotFetch } from '../utils'
3+
import pick from 'lodash/pick.js'
4+
import { readFile } from 'node:fs/promises'
5+
import * as config from '../config/index.js'
6+
import { sendMail } from '../services/mailerService.js'
7+
import { generateHtmlMessage } from '../templates/generateMessage.js'
8+
import { findWritableSettings, getBotFetch } from '../utils.js'
9+
10+
const { JsonWebTokenError, TokenExpiredError } = jsonwebtoken
1011

1112
export const initializeIntegration: Middleware<{
1213
user: string

src/controllers/notification.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { DefaultContext, Middleware } from 'koa'
2-
import { appName, emailSender } from '../config'
3-
import { sendMail } from '../services/mailerService'
4-
import { generateHtmlMessage } from '../templates/generateMessage'
5-
import { getVerifiedEmails } from './status'
2+
import { appName, emailSender } from '../config/index.js'
3+
import { sendMail } from '../services/mailerService.js'
4+
import { generateHtmlMessage } from '../templates/generateMessage.js'
5+
import { getVerifiedEmails } from './status.js'
66

77
export type GoodBody = {
88
'@context': 'https://www.w3.org/ns/activitystreams'

src/controllers/status.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { readFile } from 'fs-extra'
2-
import { verify } from 'jsonwebtoken'
1+
import * as jsonwebtoken from 'jsonwebtoken'
32
import type { DefaultContext, DefaultState, Middleware } from 'koa'
4-
import * as config from '../config'
5-
import { findEmailVerificationTokens } from '../utils'
3+
import { readFile } from 'node:fs/promises'
4+
import * as config from '../config/index.js'
5+
import { findEmailVerificationTokens } from '../utils.js'
66

77
export const getVerifiedEmails = async (webId: string) => {
88
const tokens = await findEmailVerificationTokens(webId)
@@ -12,7 +12,7 @@ export const getVerifiedEmails = async (webId: string) => {
1212
const verifiedEmails = tokens
1313
.map(token => {
1414
try {
15-
return verify(token, pem) as {
15+
return jsonwebtoken.verify(token, pem) as {
1616
webId: string
1717
email: string
1818
emailVerified: boolean

src/generate-api-docs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// https://swagger-autogen.github.io/docs/getting-started/advanced-usage#openapi-3x
22
import swaggerAutogen from 'swagger-autogen'
3-
import { init, notification } from './schema'
3+
import { init, notification } from './schema.js'
44

55
const doc = {
66
info: {

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import app from './app'
2-
import { port } from './config'
1+
import app from './app.js'
2+
import { port } from './config/index.js'
33

44
app.listen(port, () => {
55
// eslint-disable-next-line no-console

0 commit comments

Comments
 (0)