.ts
TypeScript
(application/typescript)
import { FastifyRequest } from "fastify";
import {
  ServiceApiContract,
  ServiceDependencies,
} from "@ethicdevs/react-monolith";
// generated via script[generate:prisma]
import { User } from "@prisma/client";

export interface AuthServiceCreateUserDTO {
  emailAddress: string;
  username: string;
  password: string;
}

export interface AuthServiceAPI extends ServiceApiContract {
  compareUserPasswordHashes(a: string, b: string): boolean;
  createUser(dto: AuthServiceCreateUserDTO): Promise<User>;
  isExistingUsername(username: string): Promise<boolean>; // implemented.
  isExistingUserUid(userUid: string): boolean;
  findUserByUsername(username: string): void;
  findUserByUid(userUid: string): void;
  sendUserEmailAddressV8nEmail(args: unknown[]): void;
  validateUserEmailAddress(
    userUid: string,
    emailAddress: string
  ): Promise<void>;
}

export interface AuthServiceDeps extends ServiceDependencies {
  // i.e. to access request decorators, one may pass request as a dependency
  //      to this service and all the methods within it would have access to
  //      a reference to it (i.e; database, cache, another service, etc...)
  request: FastifyRequest;
}