Compare commits

..

1 commit

Author SHA1 Message Date
Trenten Vollmer
91c72fe386 feat: begin working on client api and pagination 2024-11-22 23:05:43 -05:00
36 changed files with 268 additions and 1052 deletions

View file

@ -1,39 +0,0 @@
on: [push]
jobs:
build:
runs-on: docker
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to git.kakio.us
uses: docker/login-action@v3.3.0
with:
registry: git.kakio.us
username: kakious
password: ${{ secrets.REPO_PUSH }}
- name: Build and push frontend
uses: docker/build-push-action@v2
with:
context: ./apps/frontend/
file: ./apps/frontend/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
git.kakio.us/kakious/authcore-frontend:latest
git.kakio.us/kakious/authcore-frontend:${{ github.sha }}
- name: Build and push backend
uses: docker/build-push-action@v2
with:
context: ./apps/backend/
file: ./apps/backend/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
git.kakio.us/kakious/authcore-backend:latest
git.kakio.us/kakious/authcore-backend:${{ github.sha }}

View file

@ -1,25 +0,0 @@
FROM node:22-alpine AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
FROM base AS builder-frontend
COPY --from=deps /usr/src/app /usr/src/app
RUN pnpm deploy --target frontend
FROM node:22-alpine AS frontend
WORKDIR /app
COPY --from=base-build /prod/frontend/.next ./.next
COPY --from=base-build /usr/src/app/apps/frontend/public ./.next/standalone/public
ENV NODE_ENV=production
EXPOSE 3000
CMD ["node", ".next/standalone/server.js"]

View file

@ -1,5 +1,5 @@
{
"name": "backend",
"name": "waterwolf-oauth-core",
"version": "0.0.1",
"description": "",
"author": "",
@ -114,4 +114,4 @@
"testEnvironment": "node"
},
"packageManager": "pnpm@9.5.0+sha512.140036830124618d624a2187b50d04289d5a087f326c9edfc0ccd733d76c4f52c3a313d4fc148794a2a9d81553016004e6742e8cf850670268a7387fc220c903"
}
}

View file

@ -20,7 +20,6 @@ import { BullConfigService } from './redis/service/bull-config.service';
import { RedisService } from './redis/service/redis.service';
import { OrganizationModule } from './organization/organization.module';
import { ClientModule } from './client/client.module';
import { ViewModule } from './view/view.module';
@Module({
imports: [
@ -72,7 +71,6 @@ import { ViewModule } from './view/view.module';
AuthModule,
OrganizationModule,
ClientModule,
ViewModule,
],
controllers: [AppController],
providers: [AppService],

View file

@ -5,10 +5,10 @@ import {
InternalServerErrorException,
Logger,
Post,
Query,
Req,
Res,
} from '@nestjs/common';
import { ApiExcludeController } from '@nestjs/swagger';
import { AuthService } from '../services/auth.service';
@ -18,9 +18,10 @@ import { InteractionService } from '../oidc/service/interaction.service';
import { OidcService } from '../oidc/service/core.service';
import { InteractionParams, InteractionSession } from '../oidc/types/interaction.type';
import { User } from '../../database/models/user.model';
import { ApiTags } from '@nestjs/swagger';
@Controller('interaction')
@ApiExcludeController()
@ApiTags('Interaction')
export class InteractionController {
constructor(
private readonly authService: AuthService,
@ -31,7 +32,16 @@ export class InteractionController {
logger = new Logger(InteractionController.name);
@Get(':id')
async getUserInteraction(@Res() res: Response, @Req() req: Request, @CurrentUser() user: User) {
async getUserInteraction(
@Res() res: Response,
@Req() req: Request,
@CurrentUser() user: User,
@Query('id') interactionQuery: string,
) {
if (!req.cookies['_interaction'] || !req.cookies['_interaction.sig'] || !interactionQuery) {
throw new BadRequestException('No Interaction found or invalid Interaction');
}
const details: {
session?: InteractionSession;
uid: string;

View file

@ -1,3 +0,0 @@
export class AuthViewController {
constructor() {}
}

View file

@ -2,12 +2,14 @@ import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { RedisModule } from '../redis/redis.module';
import { DATABASE_ENTITIES } from '../database/database.entities';
import { ClientController } from './controller/client.controller';
import { ClientService } from './service/client.service';
import { OidcClient } from '@server/database/models/oidc_client.model';
@Module({
imports: [TypeOrmModule.forFeature(DATABASE_ENTITIES), RedisModule],
controllers: [],
providers: [],
exports: [],
imports: [TypeOrmModule.forFeature([OidcClient]), RedisModule],
controllers: [ClientController],
providers: [ClientService],
exports: [ClientService],
})
export class ClientModule {}

View file

@ -1,6 +1,14 @@
import { Body, Controller, Delete, Get, Param, Patch, Post, Put, Query } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { ClientService } from '../service/client.service';
@Controller('organization')
@ApiTags('Clients')
export class ClientsController {}
@Controller('client')
@ApiTags('Client')
export class ClientController {
constructor(private readonly clientService: ClientService) {}
@Get()
async getOrganizations() {
return this.clientService.getClients();
}
}

View file

@ -11,5 +11,10 @@ export class ClientService {
private readonly clientRepository: Repository<OidcClient>,
) {}
public async getClients() {}
public async getClients() {
return await this.clientRepository.find();
}
/** Creates a new client, requires the user to be in an org*/
public async createClient() {}
}

View file

@ -0,0 +1,5 @@
export const PAGINATOR_OPTIONS = Symbol('PAGINATOR_OPTIONS');
export const PAGINATOR_REPOSITORY = Symbol('PAGINATOR_REPOSITORY');
export const PAGINATOR_CURSOR_EXTRACTOR = Symbol('PAGINATOR_CURSOR_EXTRACTOR');
export const PAGINATOR_CURSOR_MAKER = Symbol('PAGINATOR_CURSOR_MAKER');
export const PAGINATOR_ORDER = Symbol('PAGINATOR_ORDER');

View file

@ -0,0 +1,36 @@
import type {
InjectionToken,
ModuleMetadata,
OptionalFactoryDependency,
Provider,
Type,
} from '@nestjs/common';
import type { FindOptionsOrder, FindOptionsWhere, ObjectLiteral, Repository } from 'typeorm';
export type CursorMaker<T> = (entity: T) => string | null;
export type CursorExtractor<E> = (cursor: string) => FindOptionsWhere<E>;
export interface PaginatorModuleOptions<EntityType extends ObjectLiteral> {
repository: Repository<EntityType>;
cursorMaker: CursorMaker<EntityType>;
cursorExtractor: CursorExtractor<EntityType>;
order: FindOptionsOrder<EntityType>;
}
export interface PaginatorModuleOptionsFactory<EntityType extends ObjectLiteral> {
createPaginatorOptions():
| Promise<PaginatorModuleOptions<EntityType>>
| PaginatorModuleOptions<EntityType>;
}
export interface PaginatorModuleAsyncOptions<EntityType extends ObjectLiteral>
extends Pick<ModuleMetadata, 'imports'> {
useExisting?: Type<PaginatorModuleOptionsFactory<EntityType>>;
useClass?: Type<PaginatorModuleOptionsFactory<EntityType>>;
useFactory?: (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...args: any[]
) => Promise<PaginatorModuleOptions<EntityType>> | PaginatorModuleOptions<EntityType>;
inject?: (InjectionToken | OptionalFactoryDependency)[];
extraProviders?: Provider[];
}

View file

@ -11,22 +11,50 @@ import { CurrentUser } from '../../auth/decorators/user.decorator';
export class OrganizationController {
constructor(private readonly organizationService: OrganizationService) {}
@ApiOperation({
summary: 'Create organization',
description: 'Create a new organization',
})
@Post()
public async createOrganization(
@Body() body: CreateOrgDto,
@CurrentUser() user: User,
): Promise<any> {
return await this.organizationService.createOrganization(user.id, body);
}
@ApiOperation({
summary: 'Get organizations',
description: 'Get a paginated list of organizations',
})
@Get()
// Admin: Paginated list of organizations.
public async getOrganizations(): Promise<any> {
return await this.organizationService.getOrganizations();
}
@ApiOperation({
summary: 'Get organization by ID',
description: 'Get an organization by its ID',
})
@Get(':id')
public async getOrganization(@Param('id') id: string): Promise<any> {
return await this.organizationService.getOrganizationById(id);
}
@ApiOperation({
summary: 'Get organization members',
description: 'Get a list of members in an organization',
})
@Get(':id/members')
public async getOrganizationMembers(@Param('id') id: string): Promise<any> {
return await this.organizationService.getOrgMembers(id);
}
@ApiOperation({
summary: 'Delete an organization',
description: 'Delete an organization and all associated data.',
})
@Delete(':id')
public async deleteOrganization(@Param('id') id: string): Promise<any> {
return await this.organizationService.deleteOrganization(id);
@ -35,16 +63,14 @@ export class OrganizationController {
@Patch(':id')
public async partialUpdateOrganization(@Param('id') id: string): Promise<any> {}
@ApiOperation({
summary: "Update's an organization's details",
})
@Put(':id')
public async updateOrganization(@Param('id') id: string): Promise<any> {}
@Post()
public async createOrganization(
@Body() body: CreateOrgDto,
@CurrentUser() user: User,
): Promise<any> {
return await this.organizationService.createOrganization(user.id, body);
}
// === Flags ===
// These are normally handled by Waterwolf to enable certain privileges. Ex. Portal Network
/**
* This sets a flag on the organization.

View file

@ -1,68 +0,0 @@
import { Controller, Get, Render, UseGuards } from '@nestjs/common';
import { ApiExcludeController, ApiExcludeEndpoint } from '@nestjs/swagger';
import { ViewLoginGuard } from '../../auth/guard/viewLogin.guard';
import { CurrentUser } from '../../auth/decorators/user.decorator';
import { User } from '../../database/models/user.model';
@ApiExcludeController()
@Controller()
export class ViewController {
@Get('auth/login')
@Render('auth/login')
@ApiExcludeEndpoint()
@UseGuards(ViewLoginGuard)
public async loginView(): Promise<any> {
return {
forgot_password: 'forgot-password',
register: 'register',
login_url: '/auth/login',
//background_image: 'https://waterwolf.club/static/img/portal/portal7.jpg',
};
}
@Get('auth/login/totp')
@Render('auth/login-totp')
@ApiExcludeEndpoint()
@UseGuards(ViewLoginGuard)
public async getLoginTotp(): Promise<any> {
return {
login: 'login',
methods: ['authenticator', 'email'],
};
}
@Get('auth/register')
@Render('auth/register')
@ApiExcludeEndpoint()
@UseGuards(ViewLoginGuard)
public async getRegister(): Promise<any> {
return {
login: 'login',
};
}
@Get('auth/forgot-password')
@UseGuards(ViewLoginGuard)
@Render('auth/forgot-password')
@ApiExcludeEndpoint()
public async getForgotPassword(): Promise<any> {
return {
login: 'login',
};
}
@Get('home')
@Render('home/index')
@ApiExcludeEndpoint()
@UseGuards(ViewLoginGuard)
public async getHomeView(@CurrentUser() user: User): Promise<any> {
return {
user: {
name: user.displayName ?? user.username,
avatar: user.avatar,
email: user.email,
},
};
}
}

View file

@ -1,10 +0,0 @@
import { Module } from '@nestjs/common';
import { ViewController } from './controllers/view.controller';
@Module({
imports: [],
controllers: [ViewController],
providers: [],
exports: [],
})
export class ViewModule {}

View file

@ -14,7 +14,7 @@ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --no-frozen-lockfile; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi
@ -31,7 +31,7 @@ COPY --from=deps /app/node_modules ./node_modules
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
ENV NEXT_TELEMETRY_DISABLED=1
# ENV NEXT_TELEMETRY_DISABLED=1
RUN \
if [ -f yarn.lock ]; then yarn run build; \
@ -46,7 +46,7 @@ WORKDIR /app
ENV NODE_ENV=production
# Uncomment the following line in case you want to disable telemetry during runtime.
ENV NEXT_TELEMETRY_DISABLED=1
# ENV NEXT_TELEMETRY_DISABLED=1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

View file

@ -1,35 +0,0 @@
import type { Metadata } from 'next';
import './globals.css';
import '@mantine/core/styles.css';
import {
createTheme,
ColorSchemeScript,
MantineProvider,
// localStorageColorSchemeManager,
} from '@mantine/core';
export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
};
const theme = createTheme({});
export default async function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<head>
<ColorSchemeScript defaultColorScheme="dark" />
</head>
<body>
<MantineProvider theme={theme} defaultColorScheme="dark">
{children}
</MantineProvider>
</body>
</html>
);
}

View file

@ -1,9 +0,0 @@
import { Center } from '@mantine/core';
export default async function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return <Center h={'100vh'}>{children}</Center>;
}

View file

@ -1,5 +0,0 @@
import LoginCard from './../../../components/auth/login/LoginCard';
export default async function Login() {
return <LoginCard />;
}

View file

@ -1,9 +0,0 @@
'use client';
export default function Providers({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return <>{children}</>;
}

View file

@ -1,2 +0,0 @@
.card {
}

View file

@ -1,17 +0,0 @@
import { Button, Card, Checkbox, Stack, TextInput } from '@mantine/core';
import classes from './LoginCard.module.css';
export default function LoginCard() {
return (
<Card shadow="sm" padding="lg" className={classes.card}>
<Stack gap={20}>
<TextInput label="Email" placeholder="Your email" />
<TextInput label="Password" placeholder="Your password" type="password" />
<Checkbox label="Remember me" variant="outline"></Checkbox>
<Button type="submit" variant="gradient" gradient={{ from: 'blue', to: 'purple', deg: 45 }}>
Login
</Button>
</Stack>
</Card>
);
}

View file

@ -1,32 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
typescript: {
tsconfigPath: './tsconfig.next.json',
},
experimental: {
optimizePackageImports: [
'@mantine/core',
'@mantine/hooks',
'@mantine/dates',
'@mantine/form',
'@mantine/modals',
'@mantine/notifications',
'@mantine/nprogress',
'@mantine/dropzone',
'@mantine/charts',
],
},
output: 'standalone',
async redirects() {
return [
{
source: '/',
destination: '/login',
permanent: true,
},
];
},
};
export default nextConfig;

View file

@ -9,34 +9,19 @@
"lint": "next lint"
},
"dependencies": {
"@mantine/charts": "^7.14.1",
"@mantine/core": "^7.14.1",
"@mantine/dates": "^7.14.1",
"@mantine/dropzone": "^7.14.1",
"@mantine/form": "^7.14.1",
"@mantine/hooks": "^7.14.1",
"@mantine/modals": "^7.14.1",
"@mantine/notifications": "^7.14.1",
"@mantine/nprogress": "^7.14.1",
"dayjs": "^1.11.13",
"frontend": "link:",
"next": "14.2.15",
"react": "^18",
"react-dom": "^18",
"recharts": "2"
"next": "14.2.15"
},
"devDependencies": {
"typescript": "^5",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.2.15",
"postcss": "^8.4.47",
"postcss-preset-mantine": "^1.17.0",
"postcss-simple-vars": "^7.0.1",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5"
"eslint": "^8",
"eslint-config-next": "14.2.15"
},
"files": [".next", "public"],
"packageManager": "pnpm@9.5.0+sha512.140036830124618d624a2187b50d04289d5a087f326c9edfc0ccd733d76c4f52c3a313d4fc148794a2a9d81553016004e6742e8cf850670268a7387fc220c903"
"packageManager": "pnpm@9.5.0+sha512.140036830124618d624a2187b50d04289d5a087f326c9edfc0ccd733d76c4f52c3a313d4fc148794a2a9d81553016004e6742e8cf850670268a7387fc220c903"
}

View file

@ -2,16 +2,6 @@
const config = {
plugins: {
tailwindcss: {},
'postcss-preset-mantine': {},
'postcss-simple-vars': {
variables: {
'mantine-breakpoint-xs': '36em',
'mantine-breakpoint-sm': '48em',
'mantine-breakpoint-md': '62em',
'mantine-breakpoint-lg': '75em',
'mantine-breakpoint-xl': '88em',
},
},
},
};

View file

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View file

@ -0,0 +1,35 @@
import type { Metadata } from "next";
import localFont from "next/font/local";
import "./globals.css";
const geistSans = localFont({
src: "./fonts/GeistVF.woff",
variable: "--font-geist-sans",
weight: "100 900",
});
const geistMono = localFont({
src: "./fonts/GeistMonoVF.woff",
variable: "--font-geist-mono",
weight: "100 900",
});
export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
{children}
</body>
</html>
);
}

View file

@ -0,0 +1,101 @@
import Image from "next/image";
export default function Home() {
return (
<div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]">
<main className="flex flex-col gap-8 row-start-2 items-center sm:items-start">
<Image
className="dark:invert"
src="https://nextjs.org/icons/next.svg"
alt="Next.js logo"
width={180}
height={38}
priority
/>
<ol className="list-inside list-decimal text-sm text-center sm:text-left font-[family-name:var(--font-geist-mono)]">
<li className="mb-2">
Get started by editing{" "}
<code className="bg-black/[.05] dark:bg-white/[.06] px-1 py-0.5 rounded font-semibold">
src/app/page.tsx
</code>
.
</li>
<li>Save and see your changes instantly.</li>
</ol>
<div className="flex gap-4 items-center flex-col sm:flex-row">
<a
className="rounded-full border border-solid border-transparent transition-colors flex items-center justify-center bg-foreground text-background gap-2 hover:bg-[#383838] dark:hover:bg-[#ccc] text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5"
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
className="dark:invert"
src="https://nextjs.org/icons/vercel.svg"
alt="Vercel logomark"
width={20}
height={20}
/>
Deploy now
</a>
<a
className="rounded-full border border-solid border-black/[.08] dark:border-white/[.145] transition-colors flex items-center justify-center hover:bg-[#f2f2f2] dark:hover:bg-[#1a1a1a] hover:border-transparent text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 sm:min-w-44"
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Read our docs
</a>
</div>
</main>
<footer className="row-start-3 flex gap-6 flex-wrap items-center justify-center">
<a
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="https://nextjs.org/icons/file.svg"
alt="File icon"
width={16}
height={16}
/>
Learn
</a>
<a
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="https://nextjs.org/icons/window.svg"
alt="Window icon"
width={16}
height={16}
/>
Examples
</a>
<a
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
href="https://nextjs.org?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="https://nextjs.org/icons/globe.svg"
alt="Globe icon"
width={16}
height={16}
/>
Go to nextjs.org
</a>
</footer>
</div>
);
}

View file

@ -1,16 +1,16 @@
import type { Config } from 'tailwindcss';
import type { Config } from "tailwindcss";
const config: Config = {
content: [
'./pages/**/*.{js,ts,jsx,tsx,mdx}',
'./components/**/*.{js,ts,jsx,tsx,mdx}',
'./app/**/*.{js,ts,jsx,tsx,mdx}',
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {
colors: {
background: 'var(--background)',
foreground: 'var(--foreground)',
background: "var(--background)",
foreground: "var(--foreground)",
},
},
},

View file

@ -4,10 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"dev": "pnpm run --parallel dev",
"build": "pnpm run --parallel build",
"build-frontend": "pnpm run --filter=frontend build",
"build-backend": "pnpm run --filter=backend build"
"dev": "pnpm run --parallel dev"
},
"keywords": [],
"author": "",

739
pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff

View file

@ -11,7 +11,8 @@
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"paths": {
"@server/*": ["./apps/backend/src/*"]
"@server/*": ["./apps/backend/src/*"],
"@web/*": ["./apps/frontend/*"]
}
}
}