Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel committed Jun 28, 2024
1 parent de82c9b commit f08cb9a
Show file tree
Hide file tree
Showing 39 changed files with 149 additions and 110 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConfigModule } from '@narval/config-module'
import { LoggerService, NullLoggerService } from '@narval/nestjs-shared'
import { AuthorizationRequest } from '@narval/policy-engine-shared'
import { Test, TestingModule } from '@nestjs/testing'
import { MockProxy, mock } from 'jest-mock-extended'
Expand All @@ -14,7 +15,6 @@ import { ChainId } from '../../../../../shared/core/lib/chains.lib'
import { Transfer } from '../../../../../shared/core/type/transfer-tracking.type'
import { TransferTrackingService } from '../../../../../transfer-tracking/core/service/transfer-tracking.service'
import { HistoricalTransferFeedService } from '../../../../core/service/historical-transfer-feed.service'
import { LoggerService, NullLoggerService } from '@narval/nestjs-shared'

describe(HistoricalTransferFeedService.name, () => {
let module: TestingModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import NarCheckbox from '../../_design-system/NarCheckbox'
import NarDialog from '../../_design-system/NarDialog'
import NarInput from '../../_design-system/NarInput'
import useStore from '../../_hooks/useStore'
import {
LOCAL_DATA_STORE_URL,
MANAGED_DATASTORE_BASE_URL,
} from '../../_lib/constants'
import { LOCAL_DATA_STORE_URL, MANAGED_DATASTORE_BASE_URL } from '../../_lib/constants'

interface DataStoreConfigForm {
useAuthServer: boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { CredentialEntity, UserEntity, UserAccountEntity } from '@narval/policy-engine-shared'
import { CredentialEntity, UserAccountEntity, UserEntity } from '@narval/policy-engine-shared'
import { FC, useState } from 'react'
import { v4 as uuid } from 'uuid'
import NarDialog from '../../../_design-system/NarDialog'
Expand Down
4 changes: 3 additions & 1 deletion apps/policy-engine/src/engine/__test__/e2e/client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConfigModule, ConfigService } from '@narval/config-module'
import { EncryptionModuleOptionProvider } from '@narval/encryption-module'
import { secret } from '@narval/nestjs-shared'
import { LoggerService, NullLoggerService, secret } from '@narval/nestjs-shared'
import { DataStoreConfiguration, HttpSource, SourceType } from '@narval/policy-engine-shared'
import {
PrivateKey,
Expand Down Expand Up @@ -62,6 +62,8 @@ describe('Client', () => {
.useValue({
keyring: getTestRawAesKeyring()
})
.overrideProvider(LoggerService)
.useClass(NullLoggerService)
.compile()

app = module.createNestApplication()
Expand Down
3 changes: 3 additions & 0 deletions apps/policy-engine/src/engine/__test__/e2e/evaluation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ConfigModule, ConfigService } from '@narval/config-module'
import { EncryptionModuleOptionProvider } from '@narval/encryption-module'
import { LoggerService, NullLoggerService } from '@narval/nestjs-shared'
import {
Action,
Criterion,
Expand Down Expand Up @@ -73,6 +74,8 @@ describe('Evaluation', () => {
.useValue({
keyring: getTestRawAesKeyring()
})
.overrideProvider(LoggerService)
.useClass(NullLoggerService)
.compile()

app = module.createNestApplication()
Expand Down
7 changes: 5 additions & 2 deletions apps/policy-engine/src/engine/__test__/e2e/provision.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ConfigModule } from '@narval/config-module'
import { secret } from '@narval/nestjs-shared'
import { LoggerService, NullLoggerService, secret } from '@narval/nestjs-shared'
import { INestApplication } from '@nestjs/common'
import { Test, TestingModule } from '@nestjs/testing'
import request from 'supertest'
Expand Down Expand Up @@ -35,7 +35,10 @@ describe('Provision', () => {
}),
EngineModule
]
}).compile()
})
.overrideProvider(LoggerService)
.useClass(NullLoggerService)
.compile()

app = module.createNestApplication()

Expand Down
9 changes: 4 additions & 5 deletions apps/policy-engine/src/engine/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Controller, Get, Logger } from '@nestjs/common'
import { LoggerService } from '@narval/nestjs-shared'
import { Controller, Get } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'

@Controller()
@ApiTags('Application')
export class AppController {
private logger = new Logger(AppController.name)
constructor(private readonly logger: LoggerService) {}

@Get()
healthcheck() {
Expand All @@ -13,9 +14,7 @@ export class AppController {

@Get('/ping')
ping() {
this.logger.log({
message: 'Received ping'
})
this.logger.log('Received ping')

return 'pong'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { HttpModule, LoggerModule, LoggerService, NullLoggerService } from '@narval/nestjs-shared'
import {
EntityData,
EntitySignature,
Expand All @@ -10,7 +11,7 @@ import {
SourceType
} from '@narval/policy-engine-shared'
import { Jwk, PublicKey, getPublicKey, privateKeyToJwk } from '@narval/signature'
import { HttpModule } from '@nestjs/axios'

import { HttpStatus } from '@nestjs/common'
import { Test } from '@nestjs/testing'
import nock from 'nock'
Expand Down Expand Up @@ -38,8 +39,17 @@ describe(DataStoreService.name, () => {

beforeEach(async () => {
const module = await Test.createTestingModule({
imports: [HttpModule],
providers: [DataStoreService, DataStoreRepositoryFactory, HttpDataStoreRepository, FileSystemDataStoreRepository]
imports: [HttpModule.forRoot(), LoggerModule],
providers: [
DataStoreService,
DataStoreRepositoryFactory,
HttpDataStoreRepository,
FileSystemDataStoreRepository,
{
provide: LoggerService,
useClass: NullLoggerService
}
]
}).compile()

service = module.get<DataStoreService>(DataStoreService)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ConfigModule } from '@narval/config-module'
import { EncryptionException, EncryptionService } from '@narval/encryption-module'
import { LoggerModule, LoggerService, NullLoggerService } from '@narval/nestjs-shared'
import { HttpSource, SourceType } from '@narval/policy-engine-shared'
import { Alg, privateKeyToJwk } from '@narval/signature'
import { Test } from '@nestjs/testing'
Expand Down Expand Up @@ -71,6 +72,7 @@ describe(BootstrapService.name, () => {

const module = await Test.createTestingModule({
imports: [
LoggerModule,
ConfigModule.forRoot({
load: [load],
isGlobal: true
Expand All @@ -92,6 +94,10 @@ describe(BootstrapService.name, () => {
{
provide: EncryptionService,
useValue: encryptionServiceMock
},
{
provide: LoggerService,
useClass: NullLoggerService
}
]
}).compile()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EncryptionModule } from '@narval/encryption-module'
import { secret } from '@narval/nestjs-shared'
import { LoggerModule, LoggerService, NullLoggerService, secret } from '@narval/nestjs-shared'
import { DataStoreConfiguration, FIXTURE, HttpSource, SourceType } from '@narval/policy-engine-shared'
import { Alg, getPublicKey, privateKeyToJwk } from '@narval/signature'
import { Test } from '@nestjs/testing'
Expand Down Expand Up @@ -64,6 +64,7 @@ describe(ClientService.name, () => {

const module = await Test.createTestingModule({
imports: [
LoggerModule,
EncryptionModule.register({
keyring: getTestRawAesKeyring()
})
Expand All @@ -83,6 +84,10 @@ describe(ClientService.name, () => {
{
provide: 'SigningService',
useValue: SimpleSigningService
},
{
provide: LoggerService,
useClass: NullLoggerService
}
]
}).compile()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ConfigService } from '@narval/config-module'
import { secret } from '@narval/nestjs-shared'
import { LoggerModule, LoggerService, NullLoggerService, secret } from '@narval/nestjs-shared'
import { Test, TestingModule } from '@nestjs/testing'
import { MockProxy, mock } from 'jest-mock-extended'
import { Config } from '../../../../../policy-engine.config'
Expand Down Expand Up @@ -38,6 +38,7 @@ describe(ProvisionService.name, () => {
configServiceMock = mockConfigService(config)

module = await Test.createTestingModule({
imports: [LoggerModule],
providers: [
ProvisionService,
EngineService,
Expand All @@ -50,6 +51,10 @@ describe(ProvisionService.name, () => {
{
provide: KeyValueRepository,
useClass: InMemoryKeyValueRepository
},
{
provide: LoggerService,
useClass: NullLoggerService
}
]
}).compile()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { EncryptionService } from '@narval/encryption-module'
import { Injectable, Logger } from '@nestjs/common'
import { LoggerService } from '@narval/nestjs-shared'
import { Injectable } from '@nestjs/common'
import { BootstrapException } from '../exception/bootstrap.exception'
import { ClientService } from './client.service'

@Injectable()
export class BootstrapService {
private logger = new Logger(BootstrapService.name)

constructor(
private clientService: ClientService,
private encryptionService: EncryptionService
private encryptionService: EncryptionService,
private readonly logger: LoggerService
) {}

async boot(): Promise<void> {
Expand Down
9 changes: 4 additions & 5 deletions apps/policy-engine/src/engine/core/service/client.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { secret } from '@narval/nestjs-shared'
import { LoggerService, secret } from '@narval/nestjs-shared'
import { DataStoreConfiguration, EntityStore, PolicyStore } from '@narval/policy-engine-shared'
import { hash } from '@narval/signature'
import { HttpStatus, Inject, Injectable, Logger } from '@nestjs/common'
import { HttpStatus, Inject, Injectable } from '@nestjs/common'
import { v4 as uuid } from 'uuid'
import { ApplicationException } from '../../../shared/exception/application.exception'
import { Client } from '../../../shared/type/domain.type'
Expand All @@ -11,12 +11,11 @@ import { SigningService } from './signing.service.interface'

@Injectable()
export class ClientService {
private logger = new Logger(ClientService.name)

constructor(
private clientRepository: ClientRepository,
private dataStoreService: DataStoreService,
@Inject('SigningService') private signingService: SigningService
@Inject('SigningService') private signingService: SigningService,
private readonly logger: LoggerService
) {}

async findById(clientId: string): Promise<Client | null> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { ConfigService } from '@narval/config-module'
import { generateKeyEncryptionKey, generateMasterKey } from '@narval/encryption-module'
import { Injectable, Logger } from '@nestjs/common'
import { LoggerService } from '@narval/nestjs-shared'
import { Injectable } from '@nestjs/common'
import { Config } from '../../../policy-engine.config'
import { Engine } from '../../../shared/type/domain.type'
import { ProvisionException } from '../exception/provision.exception'
import { EngineService } from './engine.service'

@Injectable()
export class ProvisionService {
private logger = new Logger(ProvisionService.name)

// IMPORTANT: The provision service establishes encryption. Therefore, you
// cannot have dependencies that rely on encryption to function. If you do,
// you'll ran into an error due to a missing keyring.
// Any process that requires encryption should be handled in the
// BootstrapService.
constructor(
private configService: ConfigService<Config>,
private engineService: EngineService
private engineService: EngineService,
private readonly logger: LoggerService
) {}

// NOTE: The `adminApiKeyHash` argument is for test convinience in case it
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-var-requires, @nx/enforce-module-boundaries */
import { ConfigService } from '@narval/config-module'
import { LoggerService } from '@narval/nestjs-shared'
import { Alg, Hex, PublicKey, eip191Hash, hexToBase64Url, publicKeyToJwk } from '@narval/signature'
import { HttpStatus, Inject, Injectable, Logger } from '@nestjs/common'
import { HttpStatus, Inject, Injectable } from '@nestjs/common'
import { toHex } from 'viem'
import { Config } from '../../../policy-engine.config'
import { ApplicationException } from '../../../shared/exception/application.exception'
Expand Down Expand Up @@ -47,12 +48,14 @@ const wrapTsmException = (message: string, e: Error) => {

@Injectable()
export class MpcSigningService implements SigningService {
private logger = new Logger(MpcSigningService.name)
private url: string
private apiKey: string
private playerCount: number

constructor(@Inject(ConfigService) private configService: ConfigService<Config>) {
constructor(
@Inject(ConfigService) private configService: ConfigService<Config>,
private readonly logger: LoggerService
) {
const tsm = this.configService.get('tsm')
if (!tsm) {
throw new ApplicationException({
Expand Down
13 changes: 7 additions & 6 deletions apps/policy-engine/src/engine/engine.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConfigService } from '@narval/config-module'
import { EncryptionModule } from '@narval/encryption-module'
import { HttpModule } from '@narval/nestjs-shared'
import { HttpModule, LoggerModule, LoggerService } from '@narval/nestjs-shared'
import { Module, ValidationPipe } from '@nestjs/common'
import { APP_INTERCEPTOR, APP_PIPE } from '@nestjs/core'
import { ZodSerializerInterceptor, ZodValidationPipe } from 'nestjs-zod'
Expand Down Expand Up @@ -28,11 +28,12 @@ import { HttpDataStoreRepository } from './persistence/repository/http-data-stor

@Module({
imports: [
LoggerModule,
HttpModule.forRoot(),
KeyValueModule,
EncryptionModule.registerAsync({
imports: [EngineModule],
inject: [ConfigService, EngineService],
imports: [EngineModule, LoggerModule],
inject: [ConfigService, EngineService, LoggerService],
useClass: EncryptionModuleOptionFactory
})
],
Expand All @@ -44,17 +45,17 @@ import { HttpDataStoreRepository } from './persistence/repository/http-data-stor
DataStoreService,
{
provide: 'SigningService',
useFactory: async (configService: ConfigService<Config>) => {
useFactory: async (configService: ConfigService<Config>, loggerService: LoggerService) => {
const signingProtocol = configService.get('signingProtocol')
if (signingProtocol === 'simple') {
return new SimpleSigningService()
} else if (signingProtocol === 'mpc') {
return new MpcSigningService(configService)
return new MpcSigningService(configService, loggerService)
}

throw new Error('Invalid signing protocol')
},
inject: [ConfigService]
inject: [ConfigService, LoggerService]
},
EngineRepository,
EngineService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpModule } from '@narval/nestjs-shared'
import { HttpModule, LoggerModule, LoggerService, NullLoggerService } from '@narval/nestjs-shared'
import { EntityData, FIXTURE, HttpSource, SourceType } from '@narval/policy-engine-shared'
import { HttpStatus } from '@nestjs/common'
import { Test } from '@nestjs/testing'
Expand All @@ -24,8 +24,14 @@ describe(HttpDataStoreRepository.name, () => {

beforeEach(async () => {
const module = await Test.createTestingModule({
imports: [HttpModule.forRoot()],
providers: [HttpDataStoreRepository]
imports: [HttpModule.forRoot(), LoggerModule],
providers: [
HttpDataStoreRepository,
{
provide: LoggerService,
useClass: NullLoggerService
}
]
}).compile()

repository = module.get<HttpDataStoreRepository>(HttpDataStoreRepository)
Expand Down
Loading

0 comments on commit f08cb9a

Please sign in to comment.