6 Commits

14 changed files with 3697 additions and 3013 deletions

View File

@ -18,7 +18,7 @@
Thream's Application Programming Interface (API) to stay close with your friends and communities. Thream's Application Programming Interface (API) to stay close with your friends and communities.
It uses [Thream/file-uploads-api](https://github.com/Thream/file-uploads-api) [v1.0.0](https://github.com/Thream/file-uploads-api/releases/tag/v1.0.0). It uses [Thream/file-uploads-api](https://github.com/Thream/file-uploads-api) [v1.1.0](https://github.com/Thream/file-uploads-api/releases/tag/v1.1.0).
## ⚙️ Getting Started ## ⚙️ Getting Started

6585
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.0.0", "version": "1.1.0",
"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",
@ -33,69 +33,69 @@
"postinstall": "husky install" "postinstall": "husky install"
}, },
"dependencies": { "dependencies": {
"@fastify/cors": "8.0.0",
"@fastify/helmet": "9.1.0",
"@fastify/multipart": "7.1.0",
"@fastify/rate-limit": "7.0.0",
"@fastify/sensible": "5.1.0",
"@fastify/swagger": "7.4.0",
"@prisma/client": "3.12.0", "@prisma/client": "3.12.0",
"@sinclair/typebox": "0.23.4", "@sinclair/typebox": "0.23.5",
"@thream/socketio-jwt": "3.0.0", "@thream/socketio-jwt": "3.0.0",
"axios": "0.26.1", "axios": "0.26.1",
"bcryptjs": "2.4.3", "bcryptjs": "2.4.3",
"dotenv": "16.0.0", "dotenv": "16.0.1",
"ejs": "3.1.6", "ejs": "3.1.8",
"fastify": "3.28.0", "fastify": "4.2.0",
"fastify-cors": "6.0.3",
"fastify-helmet": "7.0.1",
"fastify-multipart": "5.3.1",
"fastify-plugin": "3.0.1", "fastify-plugin": "3.0.1",
"fastify-rate-limit": "5.8.0",
"fastify-sensible": "3.1.2",
"fastify-swagger": "5.1.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.3", "nodemailer": "6.7.5",
"read-pkg": "7.1.0", "read-pkg": "7.1.0",
"socket.io": "4.4.1" "socket.io": "4.5.1"
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "16.2.3", "@commitlint/cli": "17.0.3",
"@commitlint/config-conventional": "16.2.1", "@commitlint/config-conventional": "17.0.3",
"@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.164", "@swc/core": "1.2.207",
"@types/bcryptjs": "2.4.2", "@types/bcryptjs": "2.4.2",
"@types/busboy": "1.5.0", "@types/busboy": "1.5.0",
"@types/ejs": "3.1.0", "@types/ejs": "3.1.1",
"@types/http-errors": "1.8.2", "@types/http-errors": "1.8.2",
"@types/jsonwebtoken": "8.5.8", "@types/jsonwebtoken": "8.5.8",
"@types/ms": "0.7.31", "@types/ms": "0.7.31",
"@types/node": "17.0.23", "@types/node": "18.0.0",
"@types/nodemailer": "6.4.4", "@types/nodemailer": "6.4.4",
"@types/sinon": "10.0.11", "@types/sinon": "10.0.12",
"@types/tap": "15.0.6", "@types/tap": "15.0.7",
"@typescript-eslint/eslint-plugin": "5.18.0", "@typescript-eslint/eslint-plugin": "5.30.0",
"c8": "7.11.0", "c8": "7.11.3",
"concurrently": "7.1.0", "concurrently": "7.2.2",
"cross-env": "7.0.3", "cross-env": "7.0.3",
"editorconfig-checker": "4.0.2", "editorconfig-checker": "4.0.2",
"eslint": "8.12.0", "eslint": "8.18.0",
"eslint-config-conventions": "2.0.0", "eslint-config-conventions": "2.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.0.0", "eslint-plugin-prettier": "4.1.0",
"eslint-plugin-promise": "6.0.0", "eslint-plugin-promise": "6.0.0",
"eslint-plugin-unicorn": "42.0.0", "eslint-plugin-unicorn": "42.0.0",
"husky": "7.0.4", "husky": "8.0.1",
"lint-staged": "12.3.7", "lint-staged": "13.0.3",
"markdownlint-cli": "0.31.1", "markdownlint-cli": "0.31.1",
"nodemon": "2.0.15", "nodemon": "2.0.18",
"plop": "3.0.5", "plop": "3.1.1",
"prettier": "2.6.2", "prettier": "2.7.1",
"prisma": "3.12.0", "prisma": "3.12.0",
"rimraf": "3.0.2", "rimraf": "3.0.2",
"semantic-release": "19.0.2", "semantic-release": "19.0.3",
"sinon": "13.0.1", "sinon": "14.0.0",
"tap": "16.0.1", "tap": "16.3.0",
"typescript": "4.6.3" "typescript": "4.7.4"
} }
} }

View File

@ -1,10 +1,10 @@
import dotenv from 'dotenv' 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 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 { services } from './services/index.js' import { services } from './services/index.js'
import { swaggerOptions } from './tools/configurations/swaggerOptions.js' import { swaggerOptions } from './tools/configurations/swaggerOptions.js'
@ -15,7 +15,11 @@ export const application = fastify({
logger: process.env.NODE_ENV === 'development', logger: process.env.NODE_ENV === 'development',
ajv: { ajv: {
customOptions: { customOptions: {
format: 'full' strict: 'log',
keywords: ['kind', 'modifier'],
formats: {
full: true
}
} }
} }
}) })

View File

@ -1,5 +1,8 @@
import { application } from './application.js' import { application } from './application.js'
import { HOST, PORT } from './tools/configurations/index.js' import { HOST, PORT } from './tools/configurations/index.js'
const address = await application.listen(PORT, HOST) const address = await application.listen({
port: PORT,
host: HOST
})
console.log('\u001B[36m%s\u001B[0m', `🚀 Server listening at ${address}`) console.log('\u001B[36m%s\u001B[0m', `🚀 Server listening at ${address}`)

View File

@ -8,10 +8,10 @@ export const themes = [Type.Literal('light'), Type.Literal('dark')]
export const userSettingsSchema = { export const userSettingsSchema = {
id, id,
language: Type.Union(languages, { default: 'en' }), language: Type.Union(languages),
theme: Type.Union(themes, { default: 'dark' }), theme: Type.Union(themes),
isPublicEmail: Type.Boolean({ default: false }), isPublicEmail: Type.Boolean(),
isPublicGuilds: Type.Boolean({ default: false }), isPublicGuilds: Type.Boolean(),
createdAt: date.createdAt, createdAt: date.createdAt,
updatedAt: date.updatedAt, updatedAt: date.updatedAt,
userId: id userId: id

View File

@ -1,6 +1,6 @@
import { Type, Static } from '@sinclair/typebox' import { Type, Static } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { 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'
import { fastifyErrors } from '../../../../../models/utils.js' import { fastifyErrors } from '../../../../../models/utils.js'

View File

@ -1,6 +1,6 @@
import { Static, Type } from '@sinclair/typebox' import { Static, Type } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { 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'
import { fastifyErrors } from '../../../../models/utils.js' import { fastifyErrors } from '../../../../models/utils.js'

View File

@ -18,7 +18,8 @@ const querySchema = Type.Object({
export type QuerySchemaType = Static<typeof querySchema> export type QuerySchemaType = Static<typeof querySchema>
const getServiceSchema: FastifySchema = { const getServiceSchema: FastifySchema = {
description: 'GET all the public guilds.', description:
'GET all the public guilds (ordered by descending members count).',
tags: ['guilds'] as string[], tags: ['guilds'] as string[],
security: [ security: [
{ {
@ -55,7 +56,11 @@ export const getGuildsPublic: FastifyPluginAsync = async (fastify) => {
} }
const guildsRequest = await prisma.guild.findMany({ const guildsRequest = await prisma.guild.findMany({
...getPaginationOptions(request.query), ...getPaginationOptions(request.query),
orderBy: { createdAt: 'desc' }, orderBy: {
members: {
_count: 'desc'
}
},
...(request.query.search != null && { ...(request.query.search != null && {
where: { where: {
name: { contains: request.query.search } name: { contains: request.query.search }

View File

@ -1,6 +1,6 @@
import { Type } from '@sinclair/typebox' import { Type } from '@sinclair/typebox'
import { FastifyPluginAsync, FastifySchema } from 'fastify' import { 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'
import { fastifyErrors } from '../../../../models/utils.js' import { fastifyErrors } from '../../../../models/utils.js'

View File

@ -1,6 +1,6 @@
import dotenv from 'dotenv' import dotenv from 'dotenv'
import { readPackage } from 'read-pkg' import { readPackage } from 'read-pkg'
import { FastifyDynamicSwaggerOptions } from 'fastify-swagger' import { FastifyDynamicSwaggerOptions } from '@fastify/swagger'
dotenv.config() dotenv.config()
@ -19,8 +19,7 @@ export const swaggerOptions: FastifyDynamicSwaggerOptions = {
{ name: 'guilds' }, { name: 'guilds' },
{ name: 'channels' }, { name: 'channels' },
{ name: 'messages' }, { name: 'messages' },
{ name: 'members' }, { name: 'members' }
{ name: 'uploads' }
], ],
components: { components: {
securitySchemes: { securitySchemes: {

View File

@ -61,5 +61,5 @@ export default fastifyPlugin(
request.user = user request.user = user
}) })
}, },
{ fastify: '3.x' } { fastify: '4.x' }
) )

View File

@ -85,5 +85,5 @@ export default fastifyPlugin(
fastify.io.instance.close() fastify.io.instance.close()
}) })
}, },
{ fastify: '3.x' } { fastify: '4.x' }
) )

View File

@ -3,7 +3,7 @@ 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 { FastifyInstance, FastifyRequest } from 'fastify'
import { Multipart } from 'fastify-multipart' import { Multipart } from '@fastify/multipart'
import { import {
FILE_UPLOADS_API_KEY, FILE_UPLOADS_API_KEY,