Skip to content

Commit

Permalink
refactor: clean up main project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Mar 9, 2024
1 parent 2b4ea7c commit e8bfbf8
Show file tree
Hide file tree
Showing 31 changed files with 137 additions and 120 deletions.
2 changes: 1 addition & 1 deletion libs/api/core/data-access/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './lib/helpers/ellipsify'
export * from './lib/api-core-data-access.module'
export * from './lib/api-core.data-access.module'
export * from './lib/api-core.service'
export * from './lib/dto/paging.input'
export * from './lib/entity/app-config.entity'
Expand Down
45 changes: 0 additions & 45 deletions libs/api/core/data-access/src/lib/api-core-data-access.module.ts

This file was deleted.

20 changes: 20 additions & 0 deletions libs/api/core/data-access/src/lib/api-core.data-access.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Module } from '@nestjs/common'
import { ScheduleModule } from '@nestjs/schedule'
import { ServeStaticModule } from '@nestjs/serve-static'
import { ApiCoreProvisionService } from './api-core-provision.service'
import { ApiCoreService } from './api-core.service'
import { ApiCoreConfigModule } from './config/api-core-config.module'
import { ApiCoreGraphQLModule } from './graphql/api-core-graphql.module'
import { serveStaticFactory } from './helpers/serve-static-factory'

@Module({
imports: [
ApiCoreConfigModule,
ApiCoreGraphQLModule,
ScheduleModule.forRoot(),
ServeStaticModule.forRootAsync({ useFactory: serveStaticFactory() }),
],
providers: [ApiCoreService, ApiCoreProvisionService],
exports: [ApiCoreService],
})
export class ApiCoreDataAccessModule {}
2 changes: 1 addition & 1 deletion libs/api/core/data-access/src/lib/api-core.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common'
import { IdentityProvider } from '@prisma/client'
import { ApiCoreConfigService } from './api-core-config.service'
import { ApiCorePrismaClient, prismaClient } from './api-core-prisma-client'
import { ApiCoreConfigService } from './config/api-core-config.service'
import { slugifyId } from './helpers/slugify-id'

@Injectable()
Expand Down
19 changes: 19 additions & 0 deletions libs/api/core/data-access/src/lib/config/api-core-config.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Module } from '@nestjs/common'
import { ConfigModule } from '@nestjs/config'

import { ApiCoreConfigService } from './api-core-config.service'
import { configuration } from './configuration'
import { validationSchema } from './validation-schema'

@Module({
imports: [
ConfigModule.forRoot({
cache: true,
load: [configuration],
validationSchema,
}),
],
providers: [ApiCoreConfigService],
exports: [ApiCoreConfigService],
})
export class ApiCoreConfigModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Injectable, Logger } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { IdentityProvider } from '@prisma/client'
import { CookieOptions } from 'express-serve-static-core'
import { ApiCoreConfig } from './config/configuration'
import { AppConfig } from './entity/app-config.entity'
import { AppConfig } from '../entity/app-config.entity'
import { ApiCoreConfig } from './configuration'

@Injectable()
export class ApiCoreConfigService {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo'
import { Module } from '@nestjs/common'
import { GraphQLModule } from '@nestjs/graphql'
import { AppContext } from '../entity/app-context'
import { join } from 'path'

@Module({
imports: [
GraphQLModule.forRoot<ApolloDriverConfig>({
autoSchemaFile: join(process.cwd(), 'api-schema.graphql'),
sortSchema: true,
driver: ApolloDriver,
introspection: process.env['GRAPHQL_PLAYGROUND']?.toLowerCase() === 'true',
playground: {
settings: {
'request.credentials': 'include',
},
},
resolvers: {
// JSON: GraphQLJSON,
},
context: ({ req, res }: AppContext) => ({ req, res }),
}),
],
})
export class ApiCoreGraphQLModule {}
6 changes: 3 additions & 3 deletions libs/api/identity/data-access/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './lib/api-admin-identity.service'
export * from './lib/api-identity-data-access.module'
export * from './lib/api-identity-data-admin.service'
export * from './lib/api-identity.data-access.module'
export * from './lib/api-identity.service'
export * from './lib/api-user-identity.service'
export * from './lib/api-identity-data-user.service'
export * from './lib/dto/admin-create-identity.input'
export * from './lib/dto/admin-find-many-identity.input'
export * from './lib/dto/link-identity-input'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AdminCreateIdentityInput } from './dto/admin-create-identity.input'
import { AdminFindManyIdentityInput } from './dto/admin-find-many-identity.input'

@Injectable()
export class ApiAdminIdentityService {
export class ApiIdentityDataAdminService {
constructor(private readonly core: ApiCoreService) {}

async createIdentity(input: AdminCreateIdentityInput): Promise<PrismaIdentity> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { Injectable, Logger } from '@nestjs/common'
import { IdentityProvider, UserRole, UserStatus } from '@prisma/client'
import { ApiAuthService } from '@pubkey-stack/api-auth-data-access'
import {
ApiCoreService,
BaseContext,
ellipsify,
getRequestDetails,
slugifyId,
} from '@pubkey-stack/api-core-data-access'
import { ApiIdentitySolanaService } from './api-identity-solana.service'
import { RequestIdentityChallengeInput } from './dto/request-identity-challenge.input'
import { VerifyIdentityChallengeInput } from './dto/verify-identity-challenge-input'
import { sha256 } from './helpers/sha256'
import { ApiSolanaIdentityService } from './api-solana-identity.service'
import { ApiAuthService } from '@pubkey-stack/api-auth-data-access'
import { IdentityProvider, UserRole, UserStatus } from '@prisma/client'

@Injectable()
export class ApiAnonIdentityService {
private readonly logger = new Logger(ApiAnonIdentityService.name)
export class ApiIdentityDataAnonService {
private readonly logger = new Logger(ApiIdentityDataAnonService.name)
constructor(
private readonly auth: ApiAuthService,
private readonly core: ApiCoreService,
private readonly solana: ApiSolanaIdentityService,
private readonly solana: ApiIdentitySolanaService,
) {}

async requestIdentityChallenge(ctx: BaseContext, { provider, providerId }: RequestIdentityChallengeInput) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import { Injectable, Logger } from '@nestjs/common'
import { Identity as PrismaIdentity } from '@prisma/client'
import { ApiCoreService, BaseContext, getRequestDetails } from '@pubkey-stack/api-core-data-access'
import { verifySignature } from '@pubkeyapp/solana-verify-wallet'
import { ApiSolanaIdentityService } from './api-solana-identity.service'
import { ApiIdentitySolanaService } from './api-identity-solana.service'
import { LinkIdentityInput } from './dto/link-identity-input'
import { RequestIdentityChallengeInput } from './dto/request-identity-challenge.input'
import { UserFindManyIdentityInput } from './dto/user-find-many-identity-input'
import { VerifyIdentityChallengeInput } from './dto/verify-identity-challenge-input'
import { sha256 } from './helpers/sha256'

@Injectable()
export class ApiUserIdentityService {
private readonly logger = new Logger(ApiUserIdentityService.name)
constructor(private readonly core: ApiCoreService, private readonly solana: ApiSolanaIdentityService) {}
export class ApiIdentityDataUserService {
private readonly logger = new Logger(ApiIdentityDataUserService.name)
constructor(private readonly core: ApiCoreService, private readonly solana: ApiIdentitySolanaService) {}

async deleteIdentity(userId: string, identityId: string): Promise<boolean> {
const found = await this.core.data.identity.findFirst({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Injectable, Logger } from '@nestjs/common'
import { IdentityProvider } from '@prisma/client'
import { ApiCoreService, BaseContext, getRequestDetails } from '@pubkey-stack/api-core-data-access'
import { PublicKey } from '@solana/web3.js'
import { verifySignature } from '@pubkeyapp/solana-verify-wallet'
import { PublicKey } from '@solana/web3.js'

@Injectable()
export class ApiSolanaIdentityService {
private readonly logger = new Logger(ApiSolanaIdentityService.name)
export class ApiIdentitySolanaService {
private readonly logger = new Logger(ApiIdentitySolanaService.name)
constructor(private readonly core: ApiCoreService) {}

ensureLinkProvider(provider: IdentityProvider) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Module } from '@nestjs/common'
import { ApiAuthDataAccessModule } from '@pubkey-stack/api-auth-data-access'
import { ApiCoreDataAccessModule } from '@pubkey-stack/api-core-data-access'
import { ApiAdminIdentityService } from './api-admin-identity.service'
import { ApiUserIdentityService } from './api-user-identity.service'
import { ApiIdentityDataAdminService } from './api-identity-data-admin.service'
import { ApiIdentityDataAnonService } from './api-identity-data-anon.service'
import { ApiIdentityDataUserService } from './api-identity-data-user.service'
import { ApiIdentitySolanaService } from './api-identity-solana.service'
import { ApiIdentityService } from './api-identity.service'
import { ApiAnonIdentityService } from './api-anon-identity.service'
import { ApiSolanaIdentityService } from './api-solana-identity.service'

@Module({
imports: [ApiAuthDataAccessModule, ApiCoreDataAccessModule],
providers: [
ApiAdminIdentityService,
ApiAnonIdentityService,
ApiIdentityDataAdminService,
ApiIdentityDataAnonService,
ApiIdentityService,
ApiSolanaIdentityService,
ApiUserIdentityService,
ApiIdentitySolanaService,
ApiIdentityDataUserService,
],
exports: [ApiIdentityService],
})
Expand Down
12 changes: 6 additions & 6 deletions libs/api/identity/data-access/src/lib/api-identity.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Injectable } from '@nestjs/common'

import { ApiAdminIdentityService } from './api-admin-identity.service'
import { ApiUserIdentityService } from './api-user-identity.service'
import { ApiAnonIdentityService } from './api-anon-identity.service'
import { ApiIdentityDataAdminService } from './api-identity-data-admin.service'
import { ApiIdentityDataAnonService } from './api-identity-data-anon.service'
import { ApiIdentityDataUserService } from './api-identity-data-user.service'

@Injectable()
export class ApiIdentityService {
constructor(
readonly admin: ApiAdminIdentityService,
readonly anon: ApiAnonIdentityService,
readonly user: ApiUserIdentityService,
readonly admin: ApiIdentityDataAdminService,
readonly anon: ApiIdentityDataAnonService,
readonly user: ApiIdentityDataUserService,
) {}
}
2 changes: 1 addition & 1 deletion libs/api/identity/feature/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './lib/api-identity-feature.module'
export * from './lib/api-identity.feature.module'
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {

@Resolver()
@UseGuards(ApiAuthGraphQLAdminGuard)
export class ApiAdminIdentityResolver {
export class ApiIdentityAdminResolver {
constructor(private readonly service: ApiIdentityService) {}

@Mutation(() => Identity, { nullable: true })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@pubkey-stack/api-identity-data-access'

@Resolver()
export class ApiAnonIdentityResolver {
export class ApiIdentityAnonResolver {
constructor(private readonly service: ApiIdentityService) {}

@Query(() => IdentityChallenge, { nullable: true })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {

@Resolver()
@UseGuards(ApiAuthGraphQLUserGuard)
export class ApiUserIdentityResolver {
export class ApiIdentityUserResolver {
constructor(private readonly service: ApiIdentityService) {}

@Mutation(() => Boolean, { nullable: true })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Module } from '@nestjs/common'
import { ApiIdentityDataAccessModule } from '@pubkey-stack/api-identity-data-access'
import { ApiAdminIdentityResolver } from './api-admin-identity.resolver'
import { ApiIdentityAdminResolver } from './api-identity-admin.resolver'
import { ApiIdentityAnonResolver } from './api-identity-anon.resolver'
import { ApiIdentityUserResolver } from './api-identity-user.resolver'
import { ApiIdentityResolver } from './api-identity.resolver'
import { ApiUserIdentityResolver } from './api-user-identity.resolver'
import { ApiAnonIdentityResolver } from './api-anon-identity.resolver'

@Module({
imports: [ApiIdentityDataAccessModule],
providers: [ApiAdminIdentityResolver, ApiAnonIdentityResolver, ApiIdentityResolver, ApiUserIdentityResolver],
providers: [ApiIdentityAdminResolver, ApiIdentityAnonResolver, ApiIdentityResolver, ApiIdentityUserResolver],
})
export class ApiIdentityFeatureModule {}
3 changes: 1 addition & 2 deletions libs/api/user/data-access/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
export * from './lib/api-user-data-access.module'
export * from './lib/api-user.data-access.module'
export * from './lib/api-user.service'
export * from './lib/dto/admin-create-user.input'
export * from './lib/dto/admin-find-many-user.input'
export * from './lib/dto/admin-update-user.input'
export * from './lib/dto/user-find-many-user.input'
export * from './lib/dto/user-update-user.input'
export * from './lib/entity/user-paging.entity'
export * from './lib/entity/user-role.enum'
export * from './lib/entity/user-status.enum'
export * from './lib/entity/user.entity'
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { ApiCoreService, hashPassword, slugifyId } from '@pubkey-stack/api-core-
import { AdminCreateUserInput } from './dto/admin-create-user.input'
import { AdminFindManyUserInput } from './dto/admin-find-many-user.input'
import { AdminUpdateUserInput } from './dto/admin-update-user.input'
import { UserPaging } from './entity/user-paging.entity'
import { getAdminUserWhereInput } from './helpers/get-admin-user-where.input'
import { UserPaging } from './entity/user.entity'
import { getUserWhereAdminInput } from './helpers/get-user-where-admin.input'

@Injectable()
export class ApiAdminUserService {
private readonly logger = new Logger(ApiAdminUserService.name)
export class ApiUserDataAdminService {
private readonly logger = new Logger(ApiUserDataAdminService.name)
constructor(private readonly core: ApiCoreService) {}

async createUser(input: AdminCreateUserInput): Promise<PrismaUser> {
Expand Down Expand Up @@ -46,7 +46,7 @@ export class ApiAdminUserService {
return this.core.data.user
.paginate({
orderBy: { createdAt: 'desc' },
where: getAdminUserWhereInput(input),
where: getUserWhereAdminInput(input),
include: { identities: { orderBy: [{ provider: 'asc' }, { providerId: 'asc' }] } },
})
.withPages({ limit: input.limit, page: input.page })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { Injectable, Logger } from '@nestjs/common'
import { ApiCoreService } from '@pubkey-stack/api-core-data-access'
import { UserFindManyUserInput } from './dto/user-find-many-user.input'
import { UserUpdateUserInput } from './dto/user-update-user.input'
import { UserPaging } from './entity/user-paging.entity'
import { getUserUserWhereInput } from './helpers/get-user-user-where.input'
import { UserPaging } from './entity/user.entity'
import { getUserWhereUserInput } from './helpers/get-user-where-user.input'

@Injectable()
export class ApiUserUserService {
private readonly logger = new Logger(ApiUserUserService.name)
export class ApiUserDataUserService {
private readonly logger = new Logger(ApiUserDataUserService.name)
constructor(private readonly core: ApiCoreService) {}

async findManyUser(input: UserFindManyUserInput): Promise<UserPaging> {
return this.core.data.user
.paginate({
orderBy: { createdAt: 'desc' },
where: getUserUserWhereInput(input),
where: getUserWhereUserInput(input),
})
.withPages({ limit: input.limit, page: input.page })
.then(([data, meta]) => ({ data, meta }))
Expand Down
Loading

0 comments on commit e8bfbf8

Please sign in to comment.