feat: add build
Some checks failed
Build and release / Build (push) Failing after 2m19s
Build and release / update-release-draft (push) Has been skipped
Build and release / Release (push) Has been skipped

This commit is contained in:
Morten Olsen
2025-10-16 22:07:56 +02:00
parent 11828da073
commit d57a6b4bc0
19 changed files with 267 additions and 23 deletions

View File

@@ -1,8 +1,9 @@
import { type FastifyPluginAsync } from 'fastify';
import { z } from 'zod';
import { manageEndpoints } from './endpoints/endpoints.manage.ts';
import { authPlugin } from './plugins/plugins.auth.ts';
import { messageEndpoints } from './endpoints/endpoints.message.ts';
import { z } from 'zod';
const api: FastifyPluginAsync = async (fastify) => {
fastify.route({

View File

@@ -1,8 +1,9 @@
import type { FastifyPluginAsyncZod } from 'fastify-type-provider-zod';
import { z } from 'zod';
import { JwtAuth } from '#root/auth/auth.jwt.ts';
import { statementSchema } from '#root/auth/auth.schemas.ts';
import { Config } from '#root/config/config.ts';
import type { FastifyPluginAsyncZod } from 'fastify-type-provider-zod';
import { z } from 'zod';
const manageEndpoints: FastifyPluginAsyncZod = async (fastify) => {
const config = fastify.services.get(Config);

View File

@@ -1,8 +1,9 @@
import { Config } from '#root/config/config.ts';
import { MqttServer } from '#root/server/server.ts';
import type { FastifyPluginAsyncZod } from 'fastify-type-provider-zod';
import { z } from 'zod';
import { Config } from '#root/config/config.ts';
import { MqttServer } from '#root/server/server.ts';
const messageEndpoints: FastifyPluginAsyncZod = async (fastify) => {
const config = fastify.services.get(Config);

View File

@@ -1,6 +1,7 @@
import { SessionProvider } from '#root/services/sessions/sessions.provider.ts';
import type { FastifyPluginAsyncZod } from 'fastify-type-provider-zod';
import { SessionProvider } from '#root/services/sessions/sessions.provider.ts';
const authPlugin: FastifyPluginAsyncZod = async (fastify) => {
fastify.addHook('onRequest', async (req, reply) => {
const authProvider = req.headers['x-auth-provider'];

View File

@@ -1,8 +1,9 @@
import type { Services } from '#root/utils/services.ts';
import { Config } from '#root/config/config.ts';
import type { AuthProvider } from './auth.provider.ts';
import { ADMIN_STATEMENTS } from './auth.consts.ts';
import type { Services } from '#root/utils/services.ts';
import { Config } from '#root/config/config.ts';
class AdminAuth implements AuthProvider {
#services: Services;

View File

@@ -2,10 +2,10 @@ import jwt from 'jsonwebtoken';
import type { Statement } from './auth.schemas.ts';
import type { AuthProvider } from './auth.provider.ts';
import { ADMIN_STATEMENTS, READER_STATEMENTS, WRITER_STATEMENTS } from './auth.consts.ts';
import type { Services } from '#root/utils/services.ts';
import { Config } from '#root/config/config.ts';
import { ADMIN_STATEMENTS, READER_STATEMENTS, WRITER_STATEMENTS } from './auth.consts.ts';
class OidcAuth implements AuthProvider {
#services: Services;

View File

@@ -59,7 +59,7 @@ class Config {
}
public get tcp() {
const enabled = (process.env.TCP_ENABLED = 'true');
const enabled = process.env.TCP_ENABLED === 'true';
const port = process.env.TCP_PORT ? parseInt(process.env.TCP_PORT) : 1883;
return {
enabled,

View File

@@ -2,13 +2,7 @@ import tcp from 'node:net';
import type { IncomingMessage } from 'node:http';
import swagger from '@fastify/swagger';
import type { ZodTypeProvider } from 'fastify-type-provider-zod';
import {
jsonSchemaTransform,
createJsonSchemaTransform,
serializerCompiler,
validatorCompiler,
} from 'fastify-type-provider-zod';
import { jsonSchemaTransform, serializerCompiler, validatorCompiler } from 'fastify-type-provider-zod';
import scalar from '@scalar/fastify-api-reference';
import {
type AuthenticateHandler,
@@ -21,14 +15,14 @@ import aedes from 'aedes';
import fastify, { type FastifyInstance } from 'fastify';
import fastifyWebSocket from '@fastify/websocket';
import { createWebSocketStream } from 'ws';
import fastifySensible from '@fastify/sensible';
import { api } from '../api/api.ts';
import { TopicsHandler } from '#root/topics/topics.handler.ts';
import type { Services } from '#root/utils/services.ts';
import { destroy, type Services } from '#root/utils/services.ts';
import { Session } from '#root/services/sessions/sessions.session.ts';
import { SessionProvider } from '#root/services/sessions/sessions.provider.ts';
import fastifySensible from '@fastify/sensible';
import { Config } from '#root/config/config.ts';
type Aedes = ReturnType<typeof aedes.createBroker>;
@@ -188,6 +182,25 @@ class MqttServer {
}
return this.#tcp;
};
[destroy] = async () => {
if (this.#http) {
const http = await this.#http;
await http.close();
}
await new Promise<void>((resolve, reject) => {
if (this.#tcp) {
this.#tcp.close((err) => {
if (err) {
return reject(err);
}
resolve();
});
} else {
resolve();
}
});
};
}
export { MqttServer };

View File

@@ -1,6 +1,7 @@
import type { AuthProvider } from '#root/auth/auth.provider.ts';
import { Session } from './sessions.session.ts';
import type { AuthProvider } from '#root/auth/auth.provider.ts';
class SessionProvider {
#handlers: Map<string, AuthProvider>;