7 Commits

89 changed files with 2172 additions and 2156 deletions

View File

@ -1,2 +1 @@
ARG VARIANT="16" FROM mcr.microsoft.com/devcontainers/javascript-node:18
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}

View File

@ -12,7 +12,7 @@ services:
- 'host.docker.internal:host-gateway' - 'host.docker.internal:host-gateway'
thream-database: thream-database:
image: 'postgres:14.5' image: 'postgres:15.0'
environment: environment:
POSTGRES_USER: 'user' POSTGRES_USER: 'user'
POSTGRES_PASSWORD: 'password' POSTGRES_PASSWORD: 'password'

View File

@ -1,21 +1,22 @@
COMPOSE_PROJECT_NAME=thream-api
NODE_ENV=development
API_URL=http://localhost:8080 API_URL=http://localhost:8080
HOST=0.0.0.0 COMPOSE_PROJECT_NAME=thream-api
PORT=8080
DATABASE_URL=postgresql://user:password@thream-database:5432/thream DATABASE_URL=postgresql://user:password@thream-database:5432/thream
DISCORD_CLIENT_ID=
DISCORD_CLIENT_SECRET=
EMAIL_HOST=thream-maildev EMAIL_HOST=thream-maildev
EMAIL_PASSWORD=password EMAIL_PASSWORD=password
EMAIL_PORT=25 EMAIL_PORT=25
EMAIL_USER=no-reply@thream.fr EMAIL_USER=no-reply@thream.fr
FILE_UPLOADS_API_KEY=apiKeySecret FILE_UPLOADS_API_KEY=apiKeySecret
FILE_UPLOADS_API_URL=http://host.docker.internal:8000 FILE_UPLOADS_API_URL=http://host.docker.internal:8000
DISCORD_CLIENT_ID=
DISCORD_CLIENT_SECRET=
GITHUB_CLIENT_ID= GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET= GITHUB_CLIENT_SECRET=
GOOGLE_CLIENT_ID= GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET= GOOGLE_CLIENT_SECRET=
HOST=0.0.0.0
JWT_ACCESS_EXPIRES_IN=15 minutes JWT_ACCESS_EXPIRES_IN=15 minutes
# You can generate JWT secrets with the `npm run generate:jwt-secret` command.
JWT_ACCESS_SECRET=accessTokenSecret JWT_ACCESS_SECRET=accessTokenSecret
JWT_REFRESH_SECRET=refreshTokenSecret JWT_REFRESH_SECRET=refreshTokenSecret
NODE_ENV=development
PORT=8080

View File

@ -19,7 +19,7 @@ jobs:
- uses: 'actions/checkout@v3.0.0' - uses: 'actions/checkout@v3.0.0'
- name: 'Initialize CodeQL' - name: 'Initialize CodeQL'
uses: 'github/codeql-action/init@v1' uses: 'github/codeql-action/init@v2'
with: with:
languages: ${{ matrix.language }} languages: ${{ matrix.language }}

View File

@ -10,12 +10,12 @@ jobs:
build: build:
runs-on: 'ubuntu-latest' runs-on: 'ubuntu-latest'
steps: steps:
- uses: 'actions/checkout@v3.0.0' - uses: 'actions/checkout@v3.1.0'
- name: 'Use Node.js' - name: 'Use Node.js'
uses: 'actions/setup-node@v3.0.0' uses: 'actions/setup-node@v3.5.1'
with: with:
node-version: '16.x' node-version: '18.x'
cache: 'npm' cache: 'npm'
- name: 'Install' - name: 'Install'

View File

@ -10,12 +10,12 @@ jobs:
lint: lint:
runs-on: 'ubuntu-latest' runs-on: 'ubuntu-latest'
steps: steps:
- uses: 'actions/checkout@v3.0.0' - uses: 'actions/checkout@v3.1.0'
- name: 'Use Node.js' - name: 'Use Node.js'
uses: 'actions/setup-node@v3.0.0' uses: 'actions/setup-node@v3.5.1'
with: with:
node-version: '16.x' node-version: '18.x'
cache: 'npm' cache: 'npm'
- name: 'Install' - name: 'Install'

View File

@ -8,7 +8,7 @@ jobs:
release: release:
runs-on: 'ubuntu-latest' runs-on: 'ubuntu-latest'
steps: steps:
- uses: 'actions/checkout@v3.0.0' - uses: 'actions/checkout@v3.1.0'
with: with:
fetch-depth: 0 fetch-depth: 0
persist-credentials: false persist-credentials: false
@ -21,9 +21,9 @@ jobs:
git-commit-gpgsign: true git-commit-gpgsign: true
- name: 'Use Node.js' - name: 'Use Node.js'
uses: 'actions/setup-node@v3.0.0' uses: 'actions/setup-node@v3.5.1'
with: with:
node-version: '16.x' node-version: '18.x'
cache: 'npm' cache: 'npm'
- name: 'Install' - name: 'Install'

View File

@ -10,12 +10,12 @@ jobs:
test: test:
runs-on: 'ubuntu-latest' runs-on: 'ubuntu-latest'
steps: steps:
- uses: 'actions/checkout@v3.0.0' - uses: 'actions/checkout@v3.1.0'
- name: 'Use Node.js' - name: 'Use Node.js'
uses: 'actions/setup-node@v3.0.0' uses: 'actions/setup-node@v3.5.1'
with: with:
node-version: '16.x' node-version: '18.x'
cache: 'npm' cache: 'npm'
- name: 'Install' - name: 'Install'

View File

@ -58,9 +58,9 @@ Scopes define what part of the code changed.
### Examples ### Examples
```sh ```sh
git commit -m "feat(services): add POST /users/signup" git commit -m "feat: add POST /users/signup"
git commit -m "docs(readme): update installation process" git commit -m "docs(readme): update installation process"
git commit -m "fix(services): should emit events to connected users" git commit -m "fix: should emit events to connected users"
``` ```
## Directory Structure ## Directory Structure
@ -120,3 +120,5 @@ The folders after `src/services` : is the real path of the routes in the API exc
folders starting and ending with `__` like `__test__` or `__utils__`. folders starting and ending with `__` like `__test__` or `__utils__`.
The filenames correspond to the HTTP methods used (`get`, `post`, `put`, `delete`). The filenames correspond to the HTTP methods used (`get`, `post`, `put`, `delete`).
You can generate the boilerplate code for a new service with the `npm run generate` command.

View File

@ -1,23 +1,21 @@
FROM node:16.17.0 AS dependencies FROM node:18.12.1 AS dependencies
WORKDIR /usr/src/app WORKDIR /usr/src/app
COPY ./package*.json ./ COPY ./package*.json ./
RUN npm install RUN npm install
FROM node:16.17.0 AS builder FROM node:18.12.1 AS builder
WORKDIR /usr/src/app WORKDIR /usr/src/app
COPY --from=dependencies /usr/src/app/node_modules ./node_modules COPY --from=dependencies /usr/src/app/node_modules ./node_modules
COPY ./ ./ COPY ./ ./
RUN npm run prisma:generate && npm run build RUN npm run prisma:generate && npm run build
FROM node:16.17.0 AS runner FROM node:18.12.1 AS runner
WORKDIR /usr/src/app WORKDIR /usr/src/app
ENV NODE_ENV=production ENV NODE_ENV=production
COPY --from=builder /usr/src/app/node_modules ./node_modules COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/start.sh ./docker-start.sh
COPY --from=builder /usr/src/app/package.json ./package.json COPY --from=builder /usr/src/app/package.json ./package.json
COPY --from=builder /usr/src/app/email ./email COPY --from=builder /usr/src/app/email ./email
COPY --from=builder /usr/src/app/build ./build COPY --from=builder /usr/src/app/build ./build
COPY --from=builder /usr/src/app/prisma ./prisma COPY --from=builder /usr/src/app/prisma ./prisma
COPY --from=builder /usr/src/app/uploads ./uploads
USER node USER node
CMD ["./docker-start.sh"] CMD ["node", "build/index.js"]

View File

@ -49,6 +49,8 @@ the root of the project (see `.env.example`).
### Local Development environment ### Local Development environment
Recommended to use [VSCode: Remote development in Containers](https://code.visualstudio.com/docs/remote/containers-tutorial).
#### Setup the database #### Setup the database
```sh ```sh
@ -76,18 +78,6 @@ npm run dev
npm run prisma:studio npm run prisma:studio
``` ```
### Production environment with [Docker](https://www.docker.com/)
```sh
# Setup and run all the services for you
docker-compose up --build
```
#### Services started
- API : `http://localhost:8080`
- [PostgreSQL database](https://www.postgresql.org/)
## 💡 Contributing ## 💡 Contributing
Anyone can help to improve the project, submit a Feature Request, a bug report or Anyone can help to improve the project, submit a Feature Request, a bug report or

View File

@ -1,29 +0,0 @@
version: '3.0'
services:
thream-api:
container_name: ${COMPOSE_PROJECT_NAME}
build:
context: './'
env_file:
- '.env'
ports:
- '${PORT}:${PORT}'
depends_on:
- 'thream-database'
volumes:
- './uploads:/usr/src/app/uploads'
restart: 'unless-stopped'
thream-database:
container_name: 'thream-database'
image: 'postgres:14.2'
environment:
POSTGRES_USER: 'user'
POSTGRES_PASSWORD: 'password'
POSTGRES_DB: 'thream'
volumes:
- 'database-volume:/var/lib/postgresql/data'
restart: 'unless-stopped'
volumes:
database-volume:

View File

@ -1,4 +0,0 @@
#!/bin/bash
npm run prisma:migrate:deploy
node build/index.js

3703
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@thream/api", "name": "@thream/api",
"version": "1.2.0", "version": "1.2.2",
"description": "Thream's application programming interface to stay close with your friends and communities.", "description": "Thream's application programming interface to stay close with your friends and communities.",
"private": true, "private": true,
"type": "module", "type": "module",
@ -18,6 +18,7 @@
"start": "node build/index.js", "start": "node build/index.js",
"dev": "concurrently -k -n \"TypeScript,Node\" -p \"[{name}]\" -c \"blue,green\" \"npm run build:dev\" \"cross-env NODE_ENV=development nodemon build/index.js\"", "dev": "concurrently -k -n \"TypeScript,Node\" -p \"[{name}]\" -c \"blue,green\" \"npm run build:dev\" \"cross-env NODE_ENV=development nodemon build/index.js\"",
"generate": "plop", "generate": "plop",
"generate:jwt-secret": "node ./build/scripts/generate-jwt-secret.js",
"lint:commit": "commitlint", "lint:commit": "commitlint",
"lint:editorconfig": "editorconfig-checker", "lint:editorconfig": "editorconfig-checker",
"lint:markdown": "markdownlint-cli2", "lint:markdown": "markdownlint-cli2",
@ -34,70 +35,71 @@
"postinstall": "husky install" "postinstall": "husky install"
}, },
"dependencies": { "dependencies": {
"@fastify/cors": "8.1.0", "@fastify/cors": "8.2.0",
"@fastify/helmet": "9.1.0", "@fastify/helmet": "10.0.2",
"@fastify/multipart": "7.1.1", "@fastify/multipart": "7.3.0",
"@fastify/rate-limit": "7.3.0", "@fastify/rate-limit": "7.5.0",
"@fastify/sensible": "5.1.1", "@fastify/sensible": "5.1.1",
"@fastify/swagger": "7.4.1", "@fastify/swagger": "8.1.0",
"@prisma/client": "4.2.1", "@fastify/swagger-ui": "1.2.0",
"@sinclair/typebox": "0.24.28", "@prisma/client": "4.5.0",
"@thream/socketio-jwt": "3.0.0", "@sinclair/typebox": "0.25.3",
"axios": "0.26.1", "@thream/socketio-jwt": "3.0.1",
"axios": "1.1.3",
"bcryptjs": "2.4.3", "bcryptjs": "2.4.3",
"dotenv": "16.0.1", "dotenv": "16.0.3",
"ejs": "3.1.8", "ejs": "3.1.8",
"fastify": "4.5.3", "fastify": "4.9.2",
"fastify-plugin": "4.2.1", "fastify-plugin": "4.3.0",
"form-data": "4.0.0", "form-data": "4.0.0",
"http-errors": "2.0.0", "http-errors": "2.0.0",
"jsonwebtoken": "8.5.1", "jsonwebtoken": "8.5.1",
"ms": "2.1.3", "ms": "2.1.3",
"nodemailer": "6.7.8", "nodemailer": "6.8.0",
"read-pkg": "7.1.0", "read-pkg": "7.1.0",
"socket.io": "4.5.1" "socket.io": "4.5.3"
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "17.1.2", "@commitlint/cli": "17.2.0",
"@commitlint/config-conventional": "17.1.0", "@commitlint/config-conventional": "17.2.0",
"@saithodev/semantic-release-backmerge": "2.1.2", "@saithodev/semantic-release-backmerge": "2.1.2",
"@semantic-release/git": "10.0.1", "@semantic-release/git": "10.0.1",
"@swc/cli": "0.1.57", "@swc/cli": "0.1.57",
"@swc/core": "1.2.244", "@swc/core": "1.3.14",
"@types/bcryptjs": "2.4.2", "@types/bcryptjs": "2.4.2",
"@types/busboy": "1.5.0", "@types/busboy": "1.5.0",
"@types/ejs": "3.1.1", "@types/ejs": "3.1.1",
"@types/http-errors": "1.8.2", "@types/http-errors": "1.8.2",
"@types/jsonwebtoken": "8.5.9", "@types/jsonwebtoken": "8.5.9",
"@types/ms": "0.7.31", "@types/ms": "0.7.31",
"@types/node": "18.7.13", "@types/node": "18.11.9",
"@types/nodemailer": "6.4.5", "@types/nodemailer": "6.4.6",
"@types/sinon": "10.0.13", "@types/sinon": "10.0.13",
"@types/tap": "15.0.7", "@types/tap": "15.0.7",
"@typescript-eslint/eslint-plugin": "5.35.1", "@typescript-eslint/eslint-plugin": "5.42.1",
"@typescript-eslint/parser": "5.35.1", "@typescript-eslint/parser": "5.42.1",
"c8": "7.12.0", "c8": "7.12.0",
"concurrently": "7.3.0", "concurrently": "7.5.0",
"cross-env": "7.0.3", "cross-env": "7.0.3",
"editorconfig-checker": "4.0.2", "editorconfig-checker": "4.0.2",
"eslint": "8.23.0", "eslint": "8.27.0",
"eslint-config-conventions": "3.0.0", "eslint-config-conventions": "5.0.0",
"eslint-config-prettier": "8.5.0", "eslint-config-prettier": "8.5.0",
"eslint-plugin-import": "2.26.0", "eslint-plugin-import": "2.26.0",
"eslint-plugin-prettier": "4.2.1", "eslint-plugin-prettier": "4.2.1",
"eslint-plugin-promise": "6.0.1", "eslint-plugin-promise": "6.1.1",
"eslint-plugin-unicorn": "43.0.2", "eslint-plugin-unicorn": "44.0.2",
"husky": "8.0.1", "husky": "8.0.2",
"lint-staged": "13.0.3", "lint-staged": "13.0.3",
"markdownlint-cli2": "0.5.1", "markdownlint-cli2": "0.5.1",
"nodemon": "2.0.19", "nodemon": "2.0.20",
"plop": "3.1.1", "plop": "3.1.1",
"prettier": "2.7.1", "prettier": "2.7.1",
"prisma": "4.2.1", "prisma": "4.5.0",
"rimraf": "3.0.2", "rimraf": "3.0.2",
"semantic-release": "19.0.5", "semantic-release": "19.0.5",
"sinon": "14.0.0", "sinon": "14.0.2",
"tap": "16.3.0", "tap": "16.3.0",
"typescript": "4.8.2" "typescript": "4.8.4"
} }
} }

View File

@ -1,8 +1,9 @@
import { User } from '@prisma/client' import type { User } from '@prisma/client'
import sinon from 'sinon' import sinon from 'sinon'
import { refreshTokenExample } from '../../models/RefreshToken.js' import { refreshTokenExample } from '../../models/RefreshToken.js'
import { userExample, UserJWT } from '../../models/User.js' import type { UserJWT } from '../../models/User.js'
import { userExample } from '../../models/User.js'
import { userSettingsExample } from '../../models/UserSettings.js' import { userSettingsExample } from '../../models/UserSettings.js'
import { import {
generateAccessToken, generateAccessToken,

View File

@ -2,15 +2,17 @@ import dotenv from 'dotenv'
import fastify from 'fastify' import fastify from 'fastify'
import fastifyCors from '@fastify/cors' import fastifyCors from '@fastify/cors'
import fastifySwagger from '@fastify/swagger' import fastifySwagger from '@fastify/swagger'
import fastifySwaggerUI from '@fastify/swagger-ui'
import fastifyHelmet from '@fastify/helmet' import fastifyHelmet from '@fastify/helmet'
import fastifyRateLimit from '@fastify/rate-limit' import fastifyRateLimit from '@fastify/rate-limit'
import fastifySensible from '@fastify/sensible' import fastifySensible from '@fastify/sensible'
import { readPackage } from 'read-pkg'
import { services } from './services/index.js' import { services } from './services/index.js'
import { swaggerOptions } from './tools/configurations/swaggerOptions.js'
import fastifySocketIo from './tools/plugins/socket-io.js' import fastifySocketIo from './tools/plugins/socket-io.js'
dotenv.config() dotenv.config()
const packageJSON = await readPackage()
export const application = fastify({ export const application = fastify({
logger: process.env.NODE_ENV === 'development', logger: process.env.NODE_ENV === 'development',
ajv: { ajv: {
@ -39,5 +41,35 @@ await application.register(fastifyRateLimit, {
max: 200, max: 200,
timeWindow: '1 minute' timeWindow: '1 minute'
}) })
await application.register(fastifySwagger, swaggerOptions) await application.register(fastifySwagger, {
openapi: {
info: {
title: packageJSON.name,
description: packageJSON.description,
version: packageJSON.version
},
tags: [
{ name: 'users' },
{ name: 'oauth2' },
{ name: 'guilds' },
{ name: 'channels' },
{ name: 'messages' },
{ name: 'members' }
],
components: {
securitySchemes: {
bearerAuth: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT'
}
}
}
},
hideUntagged: true
})
await application.register(fastifySwaggerUI, {
routePrefix: '/documentation',
staticCSP: true
})
await application.register(services) await application.register(services)

View File

@ -1,5 +1,5 @@
import { application } from './application.js' import { application } from './application.js'
import { HOST, PORT } from './tools/configurations/index.js' import { HOST, PORT } from './tools/configurations.js'
const address = await application.listen({ const address = await application.listen({
port: PORT, port: PORT,

View File

@ -1,5 +1,5 @@
import { Type } from '@sinclair/typebox' import { Type } from '@sinclair/typebox'
import { Channel } from '@prisma/client' import type { Channel } from '@prisma/client'
import { date, id } from './utils.js' import { date, id } from './utils.js'
import { guildExample } from './Guild.js' import { guildExample } from './Guild.js'

View File

@ -1,4 +1,4 @@
import { Guild } from '@prisma/client' import type { Guild } from '@prisma/client'
import { Type } from '@sinclair/typebox' import { Type } from '@sinclair/typebox'
import { date, id } from './utils.js' import { date, id } from './utils.js'

View File

@ -1,5 +1,5 @@
import { Type } from '@sinclair/typebox' import { Type } from '@sinclair/typebox'
import { Member } from '@prisma/client' import type { Member } from '@prisma/client'
import { date, id } from './utils.js' import { date, id } from './utils.js'
import { guildExample } from './Guild.js' import { guildExample } from './Guild.js'

View File

@ -1,4 +1,4 @@
import { Message } from '@prisma/client' import type { Message } from '@prisma/client'
import { Type } from '@sinclair/typebox' import { Type } from '@sinclair/typebox'
import { date, id } from './utils.js' import { date, id } from './utils.js'

View File

@ -5,12 +5,12 @@ import { date, id } from './utils.js'
export const providers = ['Google', 'GitHub', 'Discord'] as const export const providers = ['Google', 'GitHub', 'Discord'] as const
export const strategies = [...providers, 'Local'] as const export const strategies = [...providers, 'Local'] as const
export const strategiesTypebox = strategies.map((strategy) => export const strategiesTypebox = strategies.map((strategy) => {
Type.Literal(strategy) return Type.Literal(strategy)
) })
export const providersTypebox = providers.map((provider) => export const providersTypebox = providers.map((provider) => {
Type.Literal(provider) return Type.Literal(provider)
) })
export type ProviderOAuth = typeof providers[number] export type ProviderOAuth = typeof providers[number]
export type AuthenticationStrategy = typeof strategies[number] export type AuthenticationStrategy = typeof strategies[number]

View File

@ -1,4 +1,4 @@
import { RefreshToken } from '@prisma/client' import type { RefreshToken } from '@prisma/client'
import { Type } from '@sinclair/typebox' import { Type } from '@sinclair/typebox'
import { userExample } from './User.js' import { userExample } from './User.js'

View File

@ -1,7 +1,9 @@
import { User } from '@prisma/client' import type { User } from '@prisma/client'
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { Type } from '@sinclair/typebox'
import { AuthenticationStrategy, strategiesTypebox } from './OAuth.js' import type { AuthenticationStrategy } from './OAuth.js'
import { strategiesTypebox } from './OAuth.js'
import { userSettingsSchema } from './UserSettings.js' import { userSettingsSchema } from './UserSettings.js'
import { date, id } from './utils.js' import { date, id } from './utils.js'

View File

@ -1,5 +1,6 @@
import { UserSetting } from '@prisma/client' import type { UserSetting } from '@prisma/client'
import { Type, Static } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { Type } from '@sinclair/typebox'
import { date, id } from './utils.js' import { date, id } from './utils.js'

View File

@ -34,7 +34,7 @@ export const fastifyErrorsSchema = {
404: { 404: {
statusCode: Type.Literal(404), statusCode: Type.Literal(404),
error: Type.Literal('Not Found'), error: Type.Literal('Not Found'),
message: Type.Literal('Not Found') message: Type.String()
}, },
431: { 431: {
statusCode: Type.Literal(431), statusCode: Type.Literal(431),

View File

@ -0,0 +1,3 @@
import crypto from 'node:crypto'
console.log(crypto.randomBytes(256).toString('base64'))

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js' import { fastifyErrors } from '../../../models/utils.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js' import { fastifyErrors } from '../../../models/utils.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../../tools/database/prisma.js' import prisma from '../../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../../models/utils.js' import { fastifyErrors } from '../../../../models/utils.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../../tools/database/prisma.js' import prisma from '../../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../../models/utils.js' import { fastifyErrors } from '../../../../models/utils.js'

View File

@ -1,5 +1,6 @@
import { Type, Static } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import fastifyMultipart from '@fastify/multipart' import fastifyMultipart from '@fastify/multipart'
import prisma from '../../../../../tools/database/prisma.js' import prisma from '../../../../../tools/database/prisma.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js' import { fastifyErrors } from '../../../models/utils.js'

View File

@ -1,4 +1,4 @@
import { FastifyPluginAsync } from 'fastify' import type { FastifyPluginAsync } from 'fastify'
import { deleteChannelService } from './[channelId]/delete.js' import { deleteChannelService } from './[channelId]/delete.js'
import { getChannelByIdService } from './[channelId]/get.js' import { getChannelByIdService } from './[channelId]/get.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../../tools/database/prisma.js' import prisma from '../../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../../models/utils.js' import { fastifyErrors } from '../../../../models/utils.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../../tools/database/prisma.js' import prisma from '../../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../../models/utils.js' import { fastifyErrors } from '../../../../models/utils.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js' import { fastifyErrors } from '../../../models/utils.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js' import { fastifyErrors } from '../../../models/utils.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import fastifyMultipart from '@fastify/multipart' import fastifyMultipart from '@fastify/multipart'
import authenticateUser from '../../../../tools/plugins/authenticateUser.js' import authenticateUser from '../../../../tools/plugins/authenticateUser.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../../tools/database/prisma.js' import prisma from '../../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../../models/utils.js' import { fastifyErrors } from '../../../../models/utils.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../../../tools/database/prisma.js' import prisma from '../../../../../tools/database/prisma.js'
import { import {

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../../../tools/database/prisma.js' import prisma from '../../../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../../../models/utils.js' import { fastifyErrors } from '../../../../../models/utils.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js' import { fastifyErrors } from '../../../models/utils.js'

View File

@ -1,5 +1,6 @@
import { Type, Static } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../tools/database/prisma.js' import prisma from '../../tools/database/prisma.js'
import { fastifyErrors, id } from '../../models/utils.js' import { fastifyErrors, id } from '../../models/utils.js'

View File

@ -1,4 +1,4 @@
import { FastifyPluginAsync } from 'fastify' import type { FastifyPluginAsync } from 'fastify'
import { getGuilds } from './get.js' import { getGuilds } from './get.js'
import { postGuilds } from './post.js' import { postGuilds } from './post.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../tools/database/prisma.js' import prisma from '../../tools/database/prisma.js'
import { fastifyErrors } from '../../models/utils.js' import { fastifyErrors } from '../../models/utils.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js' import { fastifyErrors } from '../../../models/utils.js'

View File

@ -1,4 +1,4 @@
import { FastifyPluginAsync } from 'fastify' import type { FastifyPluginAsync } from 'fastify'
import { usersService } from './users/index.js' import { usersService } from './users/index.js'
import { guildsService } from './guilds/index.js' import { guildsService } from './guilds/index.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js' import { fastifyErrors } from '../../../models/utils.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js' import { fastifyErrors } from '../../../models/utils.js'

View File

@ -1,4 +1,4 @@
import { FastifyPluginAsync } from 'fastify' import type { FastifyPluginAsync } from 'fastify'
import { deleteMessageService } from './[messageId]/delete.js' import { deleteMessageService } from './[messageId]/delete.js'
import { putMessageService } from './[messageId]/put.js' import { putMessageService } from './[messageId]/put.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js' import { fastifyErrors } from '../../../models/utils.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js' import { fastifyErrors } from '../../../models/utils.js'

View File

@ -1,4 +1,4 @@
import { FastifyPluginAsync, FastifySchema } from 'fastify' import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js' import { fastifyErrors } from '../../../models/utils.js'

View File

@ -1,5 +1,5 @@
import { Type } from '@sinclair/typebox' import { Type } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import fastifyMultipart from '@fastify/multipart' import fastifyMultipart from '@fastify/multipart'
import authenticateUser from '../../../../tools/plugins/authenticateUser.js' import authenticateUser from '../../../../tools/plugins/authenticateUser.js'

View File

@ -1,15 +1,16 @@
import { randomUUID } from 'node:crypto' import { randomUUID } from 'node:crypto'
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js' import { fastifyErrors } from '../../../models/utils.js'
import authenticateUser from '../../../tools/plugins/authenticateUser.js' import authenticateUser from '../../../tools/plugins/authenticateUser.js'
import { userCurrentSchema, userSchema } from '../../../models/User.js' import { userCurrentSchema, userSchema } from '../../../models/User.js'
import { sendEmail } from '../../../tools/email/sendEmail.js' import { sendEmail } from '../../../tools/email/sendEmail.js'
import { API_URL } from '../../../tools/configurations/index.js' import { API_URL } from '../../../tools/configurations.js'
import { Language, Theme } from '../../../models/UserSettings.js' import type { Language, Theme } from '../../../models/UserSettings.js'
import { parseStringNullish } from '../../../tools/utils/parseStringNullish.js' import { parseStringNullish } from '../../../tools/utils/parseStringNullish.js'
const bodyPutServiceSchema = Type.Object({ const bodyPutServiceSchema = Type.Object({
@ -136,7 +137,9 @@ export const putCurrentUser: FastifyPluginAsync = async (fastify) => {
}) })
await fastify.io.emitToAuthorizedUsers({ await fastify.io.emitToAuthorizedUsers({
event: 'users', event: 'users',
isAuthorizedCallback: () => true, isAuthorizedCallback: () => {
return true
},
payload: { payload: {
action: 'update', action: 'update',
item: user item: user

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../../tools/database/prisma.js' import prisma from '../../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../../models/utils.js' import { fastifyErrors } from '../../../../models/utils.js'

View File

@ -1,4 +1,4 @@
import { FastifyPluginAsync } from 'fastify' import type { FastifyPluginAsync } from 'fastify'
import { postSignupUser } from './signup/post.js' import { postSignupUser } from './signup/post.js'
import { getConfirmEmail } from './confirm-email/get.js' import { getConfirmEmail } from './confirm-email/get.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../../tools/database/prisma.js' import prisma from '../../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../../models/utils.js' import { fastifyErrors } from '../../../../models/utils.js'
@ -55,7 +56,9 @@ export const deleteProviderService: FastifyPluginAsync = async (fastify) => {
if (user.current.password != null) { if (user.current.password != null) {
strategies.push('Local') strategies.push('Local')
} }
const oauthProvider = OAuths.find((oauth) => oauth.provider === provider) const oauthProvider = OAuths.find((oauth) => {
return oauth.provider === provider
})
if (oauthProvider == null) { if (oauthProvider == null) {
throw fastify.httpErrors.notFound('You are not using this provider') throw fastify.httpErrors.notFound('You are not using this provider')
} }

View File

@ -1,7 +1,8 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import { API_URL } from '../../../../../tools/configurations/index.js' import { API_URL } from '../../../../../tools/configurations.js'
import { fastifyErrors } from '../../../../../models/utils.js' import { fastifyErrors } from '../../../../../models/utils.js'
import { DISCORD_BASE_URL, DISCORD_CLIENT_ID } from '../__utils__/utils.js' import { DISCORD_BASE_URL, DISCORD_CLIENT_ID } from '../__utils__/utils.js'
import authenticateUser from '../../../../../tools/plugins/authenticateUser.js' import authenticateUser from '../../../../../tools/plugins/authenticateUser.js'

View File

@ -1,7 +1,8 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import { API_URL } from '../../../../../tools/configurations/index.js' import { API_URL } from '../../../../../tools/configurations.js'
import { fastifyErrors } from '../../../../../models/utils.js' import { fastifyErrors } from '../../../../../models/utils.js'
import { discordStrategy, getDiscordUserData } from '../__utils__/utils.js' import { discordStrategy, getDiscordUserData } from '../__utils__/utils.js'
import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js' import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js'

View File

@ -1,7 +1,8 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import { API_URL } from '../../../../../tools/configurations/index.js' import { API_URL } from '../../../../../tools/configurations.js'
import { fastifyErrors } from '../../../../../models/utils.js' import { fastifyErrors } from '../../../../../models/utils.js'
import { discordStrategy, getDiscordUserData } from '../__utils__/utils.js' import { discordStrategy, getDiscordUserData } from '../__utils__/utils.js'
import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js' import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js'

View File

@ -1,7 +1,8 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import { API_URL } from '../../../../../tools/configurations/index.js' import { API_URL } from '../../../../../tools/configurations.js'
import { fastifyErrors } from '../../../../../models/utils.js' import { fastifyErrors } from '../../../../../models/utils.js'
import { DISCORD_BASE_URL, DISCORD_CLIENT_ID } from '../__utils__/utils.js' import { DISCORD_BASE_URL, DISCORD_CLIENT_ID } from '../__utils__/utils.js'

View File

@ -1,7 +1,8 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import { API_URL } from '../../../../../tools/configurations/index.js' import { API_URL } from '../../../../../tools/configurations.js'
import { fastifyErrors } from '../../../../../models/utils.js' import { fastifyErrors } from '../../../../../models/utils.js'
import { GITHUB_BASE_URL, GITHUB_CLIENT_ID } from '../__utils__/utils.js' import { GITHUB_BASE_URL, GITHUB_CLIENT_ID } from '../__utils__/utils.js'
import authenticateUser from '../../../../../tools/plugins/authenticateUser.js' import authenticateUser from '../../../../../tools/plugins/authenticateUser.js'

View File

@ -1,7 +1,8 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import { API_URL } from '../../../../../tools/configurations/index.js' import { API_URL } from '../../../../../tools/configurations.js'
import { fastifyErrors } from '../../../../../models/utils.js' import { fastifyErrors } from '../../../../../models/utils.js'
import { githubStrategy, getGitHubUserData } from '../__utils__/utils.js' import { githubStrategy, getGitHubUserData } from '../__utils__/utils.js'
import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js' import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js'

View File

@ -1,7 +1,8 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import { API_URL } from '../../../../../tools/configurations/index.js' import { API_URL } from '../../../../../tools/configurations.js'
import { fastifyErrors } from '../../../../../models/utils.js' import { fastifyErrors } from '../../../../../models/utils.js'
import { githubStrategy, getGitHubUserData } from '../__utils__/utils.js' import { githubStrategy, getGitHubUserData } from '../__utils__/utils.js'
import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js' import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js'

View File

@ -1,7 +1,8 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import { API_URL } from '../../../../../tools/configurations/index.js' import { API_URL } from '../../../../../tools/configurations.js'
import { fastifyErrors } from '../../../../../models/utils.js' import { fastifyErrors } from '../../../../../models/utils.js'
import { GITHUB_BASE_URL, GITHUB_CLIENT_ID } from '../__utils__/utils.js' import { GITHUB_BASE_URL, GITHUB_CLIENT_ID } from '../__utils__/utils.js'

View File

@ -1,7 +1,8 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import { API_URL } from '../../../../../tools/configurations/index.js' import { API_URL } from '../../../../../tools/configurations.js'
import { fastifyErrors } from '../../../../../models/utils.js' import { fastifyErrors } from '../../../../../models/utils.js'
import { GOOGLE_BASE_URL, GOOGLE_CLIENT_ID } from '../__utils__/utils.js' import { GOOGLE_BASE_URL, GOOGLE_CLIENT_ID } from '../__utils__/utils.js'
import authenticateUser from '../../../../../tools/plugins/authenticateUser.js' import authenticateUser from '../../../../../tools/plugins/authenticateUser.js'

View File

@ -1,7 +1,8 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import { API_URL } from '../../../../../tools/configurations/index.js' import { API_URL } from '../../../../../tools/configurations.js'
import { fastifyErrors } from '../../../../../models/utils.js' import { fastifyErrors } from '../../../../../models/utils.js'
import { googleStrategy, getGoogleUserData } from '../__utils__/utils.js' import { googleStrategy, getGoogleUserData } from '../__utils__/utils.js'
import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js' import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js'

View File

@ -1,7 +1,8 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import { API_URL } from '../../../../../tools/configurations/index.js' import { API_URL } from '../../../../../tools/configurations.js'
import { fastifyErrors } from '../../../../../models/utils.js' import { fastifyErrors } from '../../../../../models/utils.js'
import { googleStrategy, getGoogleUserData } from '../__utils__/utils.js' import { googleStrategy, getGoogleUserData } from '../__utils__/utils.js'
import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js' import { buildQueryURL } from '../../../../../tools/utils/buildQueryURL.js'

View File

@ -1,7 +1,8 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import { API_URL } from '../../../../../tools/configurations/index.js' import { API_URL } from '../../../../../tools/configurations.js'
import { fastifyErrors } from '../../../../../models/utils.js' import { fastifyErrors } from '../../../../../models/utils.js'
import { GOOGLE_BASE_URL, GOOGLE_CLIENT_ID } from '../__utils__/utils.js' import { GOOGLE_BASE_URL, GOOGLE_CLIENT_ID } from '../__utils__/utils.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import jwt from 'jsonwebtoken' import jwt from 'jsonwebtoken'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'
@ -9,8 +10,8 @@ import {
jwtSchema, jwtSchema,
expiresIn expiresIn
} from '../../../tools/utils/jwtToken.js' } from '../../../tools/utils/jwtToken.js'
import { UserRefreshJWT } from '../../../models/User.js' import type { UserRefreshJWT } from '../../../models/User.js'
import { JWT_REFRESH_SECRET } from '../../../tools/configurations/index.js' import { JWT_REFRESH_SECRET } from '../../../tools/configurations.js'
const bodyPostRefreshTokenSchema = Type.Object({ const bodyPostRefreshTokenSchema = Type.Object({
refreshToken: jwtSchema.refreshToken refreshToken: jwtSchema.refreshToken

View File

@ -1,14 +1,15 @@
import { randomUUID } from 'node:crypto' import { randomUUID } from 'node:crypto'
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import ms from 'ms' import ms from 'ms'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js' import { fastifyErrors } from '../../../models/utils.js'
import { userSchema } from '../../../models/User.js' import { userSchema } from '../../../models/User.js'
import { sendEmail } from '../../../tools/email/sendEmail.js' import { sendEmail } from '../../../tools/email/sendEmail.js'
import { Language, Theme } from '../../../models/UserSettings.js' import type { Language, Theme } from '../../../models/UserSettings.js'
const queryPostResetPasswordSchema = Type.Object({ const queryPostResetPasswordSchema = Type.Object({
redirectURI: Type.String({ format: 'uri-reference' }) redirectURI: Type.String({ format: 'uri-reference' })

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import bcrypt from 'bcryptjs' import bcrypt from 'bcryptjs'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'

View File

@ -1,5 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import bcrypt from 'bcryptjs' import bcrypt from 'bcryptjs'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'

View File

@ -5,7 +5,7 @@ import jwt from 'jsonwebtoken'
import { application } from '../../../../application.js' import { application } from '../../../../application.js'
import prisma from '../../../../tools/database/prisma.js' import prisma from '../../../../tools/database/prisma.js'
import { refreshTokenExample } from '../../../../models/RefreshToken.js' import { refreshTokenExample } from '../../../../models/RefreshToken.js'
import { UserRefreshJWT } from '../../../../models/User.js' import type { UserRefreshJWT } from '../../../../models/User.js'
await tap.test('POST /users/signout', async (t) => { await tap.test('POST /users/signout', async (t) => {
t.afterEach(() => { t.afterEach(() => {

View File

@ -1,5 +1,5 @@
import { Type } from '@sinclair/typebox' import { Type } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js' import { fastifyErrors } from '../../../models/utils.js'

View File

@ -1,11 +1,12 @@
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { Type } from '@sinclair/typebox'
import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import jwt from 'jsonwebtoken' import jwt from 'jsonwebtoken'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js' import { fastifyErrors } from '../../../models/utils.js'
import { JWT_REFRESH_SECRET } from '../../../tools/configurations/index.js' import { JWT_REFRESH_SECRET } from '../../../tools/configurations.js'
import { UserRefreshJWT } from '../../../models/User.js' import type { UserRefreshJWT } from '../../../models/User.js'
import { jwtSchema } from '../../../tools/utils/jwtToken.js' import { jwtSchema } from '../../../tools/utils/jwtToken.js'
const bodyPostSignoutSchema = Type.Object({ const bodyPostSignoutSchema = Type.Object({

View File

@ -1,18 +1,16 @@
import { randomUUID } from 'node:crypto' import { randomUUID } from 'node:crypto'
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { Type } from '@sinclair/typebox'
import bcrypt from 'bcryptjs' import bcrypt from 'bcryptjs'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import type { FastifyPluginAsync, FastifySchema } from 'fastify'
import prisma from '../../../tools/database/prisma.js' import prisma from '../../../tools/database/prisma.js'
import { fastifyErrors } from '../../../models/utils.js' import { fastifyErrors } from '../../../models/utils.js'
import { import type { BodyUserSchemaType } from '../../../models/User.js'
bodyUserSchema, import { bodyUserSchema, userPublicSchema } from '../../../models/User.js'
BodyUserSchemaType,
userPublicSchema
} from '../../../models/User.js'
import { sendEmail } from '../../../tools/email/sendEmail.js' import { sendEmail } from '../../../tools/email/sendEmail.js'
import { API_URL } from '../../../tools/configurations/index.js' import { API_URL } from '../../../tools/configurations.js'
const queryPostSignupSchema = Type.Object({ const queryPostSignupSchema = Type.Object({
redirectURI: Type.Optional(Type.String({ format: 'uri-reference' })) redirectURI: Type.Optional(Type.String({ format: 'uri-reference' }))

View File

@ -18,7 +18,7 @@ export const JWT_REFRESH_SECRET =
export const JWT_ACCESS_EXPIRES_IN = export const JWT_ACCESS_EXPIRES_IN =
process.env.JWT_ACCESS_EXPIRES_IN ?? '15 minutes' process.env.JWT_ACCESS_EXPIRES_IN ?? '15 minutes'
export const SRC_URL = new URL('../../', import.meta.url) export const SRC_URL = new URL('../', import.meta.url)
export const ROOT_URL = new URL('../', SRC_URL) export const ROOT_URL = new URL('../', SRC_URL)
export const EMAIL_URL = new URL('./email/', ROOT_URL) export const EMAIL_URL = new URL('./email/', ROOT_URL)
export const EMAIL_TEMPLATE_URL = new URL('./email-template.ejs', EMAIL_URL) export const EMAIL_TEMPLATE_URL = new URL('./email-template.ejs', EMAIL_URL)

View File

@ -1,38 +0,0 @@
import dotenv from 'dotenv'
import { readPackage } from 'read-pkg'
import { FastifyDynamicSwaggerOptions } from '@fastify/swagger'
dotenv.config()
const packageJSON = await readPackage()
export const swaggerOptions: FastifyDynamicSwaggerOptions = {
routePrefix: '/documentation',
openapi: {
info: {
title: packageJSON.name,
description: packageJSON.description,
version: packageJSON.version
},
tags: [
{ name: 'users' },
{ name: 'oauth2' },
{ name: 'guilds' },
{ name: 'channels' },
{ name: 'messages' },
{ name: 'members' }
],
components: {
securitySchemes: {
bearerAuth: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT'
}
}
}
},
exposeRoute: true,
staticCSP: true,
hideUntagged: true
}

View File

@ -1,5 +1,6 @@
import { Prisma } from '@prisma/client' import type { Prisma } from '@prisma/client'
import { Static, Type } from '@sinclair/typebox' import type { Static } from '@sinclair/typebox'
import { Type } from '@sinclair/typebox'
export const queryPaginationSchema = { export const queryPaginationSchema = {
/** Maximum number of items to return */ /** Maximum number of items to return */

View File

@ -3,11 +3,8 @@ import { URL, fileURLToPath } from 'node:url'
import ejs from 'ejs' import ejs from 'ejs'
import { Language, Theme } from '../../models/UserSettings.js' import type { Language, Theme } from '../../models/UserSettings.js'
import { import { EMAIL_LOCALES_URL, EMAIL_TEMPLATE_URL } from '../configurations.js'
EMAIL_LOCALES_URL,
EMAIL_TEMPLATE_URL
} from '../configurations/index.js'
import { emailTransporter, EMAIL_INFO } from './emailTransporter.js' import { emailTransporter, EMAIL_INFO } from './emailTransporter.js'
interface EmailTranslation { interface EmailTranslation {

View File

@ -3,8 +3,8 @@ import httpErrors from 'http-errors'
import jwt from 'jsonwebtoken' import jwt from 'jsonwebtoken'
import prisma from '../database/prisma.js' import prisma from '../database/prisma.js'
import { UserJWT, UserRequest } from '../../models/User.js' import type { UserJWT, UserRequest } from '../../models/User.js'
import { JWT_ACCESS_SECRET } from '../configurations/index.js' import { JWT_ACCESS_SECRET } from '../configurations.js'
const { Unauthorized, Forbidden, BadRequest } = httpErrors const { Unauthorized, Forbidden, BadRequest } = httpErrors

View File

@ -1,9 +1,10 @@
import fastifyPlugin from 'fastify-plugin' import fastifyPlugin from 'fastify-plugin'
import { Server as SocketIoServer, ServerOptions } from 'socket.io' import type { ServerOptions } from 'socket.io'
import { Server as SocketIoServer } from 'socket.io'
import { authorize } from '@thream/socketio-jwt' import { authorize } from '@thream/socketio-jwt'
import prisma from '../database/prisma.js' import prisma from '../database/prisma.js'
import { JWT_ACCESS_SECRET } from '../configurations/index.js' import { JWT_ACCESS_SECRET } from '../configurations.js'
interface EmitEventOptions { interface EmitEventOptions {
event: string event: string

View File

@ -1,12 +1,12 @@
import type { ResponseJWT } from './jwtToken.js'
import { import {
expiresIn, expiresIn,
generateAccessToken, generateAccessToken,
generateRefreshToken, generateRefreshToken
ResponseJWT
} from './jwtToken.js' } from './jwtToken.js'
import prisma from '../database/prisma.js' import prisma from '../database/prisma.js'
import { ProviderOAuth } from '../../models/OAuth.js' import type { ProviderOAuth } from '../../models/OAuth.js'
import { UserRequest } from '../../models/User.js' import type { UserRequest } from '../../models/User.js'
interface ProviderData { interface ProviderData {
name: string name: string

View File

@ -5,12 +5,12 @@ import jwt from 'jsonwebtoken'
import ms from 'ms' import ms from 'ms'
import prisma from '../database/prisma.js' import prisma from '../database/prisma.js'
import { UserJWT } from '../../models/User.js' import type { UserJWT } from '../../models/User.js'
import { import {
JWT_ACCESS_EXPIRES_IN, JWT_ACCESS_EXPIRES_IN,
JWT_ACCESS_SECRET, JWT_ACCESS_SECRET,
JWT_REFRESH_SECRET JWT_REFRESH_SECRET
} from '../configurations/index.js' } from '../configurations.js'
export interface ResponseJWT { export interface ResponseJWT {
accessToken: string accessToken: string

View File

@ -2,13 +2,13 @@ import fs from 'node:fs'
import axios from 'axios' import axios from 'axios'
import FormData from 'form-data' import FormData from 'form-data'
import { FastifyInstance, FastifyRequest } from 'fastify' import type { FastifyInstance, FastifyRequest } from 'fastify'
import { Multipart } from '@fastify/multipart' import type { SavedMultipartFile } from '@fastify/multipart'
import { import {
FILE_UPLOADS_API_KEY, FILE_UPLOADS_API_KEY,
FILE_UPLOADS_API_URL FILE_UPLOADS_API_URL
} from '../configurations/index.js' } from '../configurations.js'
export const fileUploadAPI = axios.create({ export const fileUploadAPI = axios.create({
baseURL: FILE_UPLOADS_API_URL, baseURL: FILE_UPLOADS_API_URL,
@ -35,7 +35,7 @@ export const uploadFile = async (
options: UploadFileOptions options: UploadFileOptions
): Promise<UploadFileResult> => { ): Promise<UploadFileResult> => {
const { fastify, request, folderInUploadsFolder } = options const { fastify, request, folderInUploadsFolder } = options
let files: Multipart[] = [] let files: SavedMultipartFile[] = []
try { try {
files = await request.saveRequestFiles({ files = await request.saveRequestFiles({
limits: { limits: {