Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 22

- name: Install NPM packages
run: yarn install --frozen-lockfile
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 22

- name: Checkout
uses: actions/checkout@v3
Expand Down
40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,40 @@
"maildev": "^2.1.0",
"msw": "^2.0.14",
"prettier": "^3.0.0",
"puppeteer": "^22.2.0",
"puppeteer": "^24.33.0",
"swagger-autogen": "^2.23.6",
"vitest": "^3.0.4"
"vitest": "^4.0.16"
},
"dependencies": {
"@koa/bodyparser": "^5.0.0",
"@koa/cors": "^4.0.0",
"@koa/router": "^12.0.0",
"@ldhop/core": "^0.1.0",
"@koa/bodyparser": "^6.0.0",
"@koa/cors": "^5.0.0",
"@koa/router": "^15.1.0",
"@ldhop/core": "^1.0.0-alpha.1",
"@solid/access-token-verifier": "^2.0.5",
"@types/co-body": "^6.1.3",
"@types/jsonwebtoken": "^9.0.5",
"@types/koa": "^2.13.7",
"@types/jsonwebtoken": "^9.0.10",
"@types/koa": "^3.0.1",
"@types/koa-static": "^4.0.3",
"@types/koa__cors": "^4.0.1",
"@types/koa__router": "^12.0.0",
"@types/koa__cors": "^5.0.1",
"@types/lodash": "^4.14.196",
"@types/n3": "^1.16.0",
"@types/node": "^22.12.0",
"@types/nodemailer": "^6.4.9",
"@types/nodemailer": "^7.0.4",
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"css-authn": "^0.2.1",
"dotenv": "^16.0.0",
"ajv-formats": "^3.0.1",
"css-authn": "^0.4.0",
"dotenv": "^17.2.3",
"handlebars": "^4.7.8",
"jsonwebtoken": "^9.0.2",
"juice": "^10.0.0",
"koa": "^2.14.2",
"koa-helmet": "^7.0.2",
"helmet": "^8.1.0",
"jsonwebtoken": "^9.0.3",
"juice": "^11.0.3",
"koa": "^3.1.1",
"koa-helmet": "^8.0.3",
"koa-static": "^5.0.0",
"lodash": "^4.17.21",
"n3": "^1.17.0",
"nodemailer": "^6.9.4",
"rdf-namespaces": "^1.11.0",
"nodemailer": "^7.0.11",
"rdf-namespaces": "^1.16.0",
"typescript": "^5.1.6"
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
Expand Down
4 changes: 2 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { bodyParser } from '@koa/bodyparser'
import cors from '@koa/cors'
import Router from '@koa/router'
import { Router } from '@koa/router'
import Koa from 'koa'
import helmet from 'koa-helmet'
import serve from 'koa-static'
Expand Down Expand Up @@ -72,7 +72,7 @@ router
)

app
.use(helmet())
.use(helmet.default())
.use(cors())
.use(
bodyParser({
Expand Down
7 changes: 4 additions & 3 deletions src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Constant } from '@ldhop/core'
import 'dotenv/config'
import SMTPTransport from 'nodemailer/lib/smtp-transport'
import SMTPTransport from 'nodemailer/lib/smtp-transport/index.js'

// the defaults work for tests. you should define your own
// either via .env file, or via environment variables directly (depends on your setup)
Expand All @@ -26,7 +27,7 @@ export const supportEmail = process.env.SUPPORT_EMAIL ?? 'support@tired.bike'
export const mailerCredentials = {
email: process.env.MAILER_IDENTITY_EMAIL ?? 'bot@example',
password: process.env.MAILER_IDENTITY_PASSWORD ?? 'password',
provider: process.env.MAILER_IDENTITY_PROVIDER ?? 'http://localhost:3456',
oidcIssuer: process.env.MAILER_IDENTITY_PROVIDER ?? 'http://localhost:3456',
webId:
process.env.MAILER_IDENTITY_WEBID ??
'http://localhost:3456/bot/profile/card#me',
Expand Down Expand Up @@ -77,7 +78,7 @@ export const jwt = {
}

export const emailDiscoveryType =
process.env.EMAIL_DISCOVERY_TYPE ??
(process.env.EMAIL_DISCOVERY_TYPE as Constant) ??
'http://w3id.org/hospex/ns#PersonalHospexDocument'

export const verificationTokenPredicate =
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const getVerifiedEmails = async (webId: string) => {

export const getStatus: Middleware<
DefaultState,
DefaultContext & { params: { webId: string } }
DefaultContext /* & { params: { webId: string } }*/
> = async ctx => {
const webId = ctx.params.webId

Expand Down
4 changes: 2 additions & 2 deletions src/services/mailerService.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as nodemailer from 'nodemailer'
import Mail from 'nodemailer/lib/mailer'
import { SendMailOptions } from 'nodemailer'
import * as path from 'path'
import { appLogo, smtpTransportOptions } from '../config/index.js'

export const sendMail = async (options: Mail.Options) => {
export const sendMail = async (options: SendMailOptions) => {
const smtpTransport = nodemailer.createTransport(smtpTransportOptions)
await smtpTransport.sendMail({
...options,
Expand Down
4 changes: 2 additions & 2 deletions src/test/integration-start.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fetch from 'cross-fetch'
import Mail from 'nodemailer/lib/mailer'
import type { SendMailOptions } from 'nodemailer'
import {
afterEach,
beforeEach,
Expand All @@ -14,7 +14,7 @@ import * as mailerService from '../services/mailerService.js'
import { authenticatedFetch, otherAuthenticatedFetch } from './setup.js'

describe('Initialize email integration via /init', () => {
let sendMailSpy: MockInstance<(options: Mail.Options) => Promise<void>>
let sendMailSpy: MockInstance<(options: SendMailOptions) => Promise<void>>

beforeEach(() => {
sendMailSpy = vi.spyOn(mailerService, 'sendMail')
Expand Down
51 changes: 20 additions & 31 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fetchRdfDocument, QueryAndStore, RdfQuery } from '@ldhop/core'
import { fetchRdfDocument, LdhopEngine, LdhopQuery, run } from '@ldhop/core'
import { v6, v7 } from 'css-authn'
import { NamedNode, Quad } from 'n3'
import { NamedNode } from 'n3'
import { rdf, rdfs, solid, space } from 'rdf-namespaces'
import * as config from './config/index.js'

Expand All @@ -13,7 +13,15 @@ import * as config from './config/index.js'
* - Find settings in the relevant instance (webId) - space:preferencesFile -> (settings)
* - In the settings, find (webId) - example:emailVerificationToken -> (JWT)
*/
const findEmailQuery: RdfQuery = [
const findEmailQuery: LdhopQuery<
| '?person'
| '?extendedDocument'
| '?publicTypeIndex'
| '?typeRegistration'
| '?typeRegistrationForClass'
| '?classDocument'
| '?settings'
> = [
// Go to person's webId and fetch extended proimage documents, too
{
type: 'match',
Expand Down Expand Up @@ -73,8 +81,9 @@ const findEmailQuery: RdfQuery = [
export const findEmailVerificationTokens = async (webId: string) => {
// initialize knowledge graph and follow your nose through it
// according to the query
const qas = new QueryAndStore(findEmailQuery, { person: new Set([webId]) })
await run(qas)
const qas = new LdhopEngine(findEmailQuery, { '?person': new Set([webId]) })
const botFetch = await getBotFetch()
await run(qas, botFetch)

// Find email verification tokens
const objects = qas.store.getObjects(
Expand All @@ -92,11 +101,14 @@ export const findEmailVerificationTokens = async (webId: string) => {
export const findWritableSettings = async (webId: string) => {
// initialize knowledge graph and follow your nose through it
// according to the query
const qas = new QueryAndStore(findEmailQuery, { person: new Set([webId]) })
await run(qas)
const qas = new LdhopEngine(findEmailQuery, { '?person': new Set([webId]) })
const botFetch = await getBotFetch()
await run(qas, botFetch)

// get uris of settings
const settings = qas.getVariable('settings')
const settings = Array.from(qas.getVariable('?settings'))
.filter(t => t.termType === 'NamedNode')
.map(t => t.value)

// find out which settings the bot can edit
const authBotFetch = await getBotFetch()
Expand Down Expand Up @@ -182,26 +194,3 @@ export const fetchRdf = async (
const { data: quads } = await fetchRdfDocument(uri, authBotFetch)
return quads
}

/**
* Follow your nose through the linked data graph by query
*/
const run = async (qas: QueryAndStore) => {
let missingResources = qas.getMissingResources()

const authFetch = await getBotFetch()

while (missingResources.length > 0) {
let quads: Quad[] = []
const res = missingResources[0]
try {
quads = await fetchRdf(missingResources[0], authFetch)
} catch (e) {
// eslint-disable-next-line no-console
console.error(e)
} finally {
qas.addResource(res, quads)
missingResources = qas.getMissingResources()
}
}
}
6 changes: 1 addition & 5 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ export default defineConfig({
test: {
setupFiles: './src/test/setup.ts',
testTimeout: 10000,
poolOptions: {
// threads: { execArgv: ['--env-file=.env.test'] },
// Or another pool:
// forks: { execArgv: ['--env-file=.env.test'] },
},
// execArgv: ['--env-file=.env.test'],
fileParallelism: false,
},
})
Loading