Skip to content

Commit

Permalink
fix other DTOs
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel committed Feb 14, 2024
1 parent 6ecd25f commit a2c2cd7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { Action, BaseActionDto, BaseActionRequestDto } from '@narval/authz-shared'
import { ApiProperty } from '@nestjs/swagger'
import { Type } from 'class-transformer'
import { IsArray, IsDefined, IsString, Matches, ValidateNested } from 'class-validator'
import { ArrayNotEmpty, IsDefined, Matches, ValidateNested } from 'class-validator'
import { Policy } from '../../../../../shared/types/policy.type'

export class SetPolicyRulesDto extends BaseActionDto {
@IsDefined()
@IsString()
@Matches(Action.SET_POLICY_RULES)
@ApiProperty()
@ApiProperty({
enum: [Action.SET_POLICY_RULES],
default: Action.SET_POLICY_RULES
})
action: typeof Action.SET_POLICY_RULES

@IsDefined()
@IsArray()
@ArrayNotEmpty()
@Type(() => Policy)
@ValidateNested({ each: true })
@ApiProperty()
@ApiProperty({ type: [Policy] })
data: Policy[]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { ApiProperty } from '@nestjs/swagger'
import { Type } from 'class-transformer'
import { IsDefined, IsString, ValidateNested } from 'class-validator'
import { ArrayNotEmpty, IsDefined, IsString, ValidateNested } from 'class-validator'
import { Policy } from '../../../../../shared/types/policy.type'

export class SetPolicyRulesResponseDto {
@IsDefined()
@IsString()
fileId: string

@IsDefined()
@ArrayNotEmpty()
@Type(() => Policy)
@ValidateNested()
@ApiProperty({ type: () => Policy, isArray: true })
@ValidateNested({ each: true })
@ApiProperty({ type: [Policy] })
policies: Policy[]

constructor(partial: Partial<SetPolicyRulesResponseDto>) {
Expand Down
41 changes: 32 additions & 9 deletions apps/authz/src/shared/types/policy.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
ValueOperators
} from '@narval/authz-shared'
import { Intents } from '@narval/transaction-request-intent'
import { ApiExtraModels, ApiProperty, getSchemaPath } from '@nestjs/swagger'
import { ApiExtraModels, ApiProperty, ApiPropertyOptional, getSchemaPath } from '@nestjs/swagger'
import { Transform, Type, plainToInstance } from 'class-transformer'
import {
IsArray,
Expand Down Expand Up @@ -91,6 +91,7 @@ export type TimeWindow = (typeof TimeWindow)[keyof typeof TimeWindow]

export class AmountCondition {
@IsIn([...Object.values(FiatCurrency), '*'])
@ApiProperty({ enum: [...Object.values(FiatCurrency), '*'] })
currency: FiatCurrency | '*'

@IsEnum(ValueOperators)
Expand All @@ -99,12 +100,13 @@ export class AmountCondition {

@IsNotEmpty()
@IsNumberString()
@ApiProperty({ type: String })
@ApiProperty()
value: string
}

export class ERC1155AmountCondition {
@IsAssetId()
@ApiProperty()
tokenId: AssetId

@IsEnum(ValueOperators)
Expand All @@ -113,38 +115,43 @@ export class ERC1155AmountCondition {

@IsNotEmpty()
@IsNumberString()
@ApiProperty({ type: String })
@ApiProperty()
value: string
}

export class SignMessageCondition {
@IsIn([ValueOperators.EQUAL, IdentityOperators.CONTAINS])
@ApiProperty({ enum: [ValueOperators.EQUAL, IdentityOperators.CONTAINS] })
operator: ValueOperators.EQUAL | IdentityOperators.CONTAINS

@IsNotEmpty()
@IsString()
@ApiProperty({ type: String })
@ApiProperty()
value: string
}

export class SignTypedDataDomainCondition {
@IsOptional()
@IsNotEmptyArrayString()
@IsNumberString({}, { each: true })
@ApiPropertyOptional()
version?: string[]

@IsOptional()
@IsNotEmptyArrayString()
@IsNumberString({}, { each: true })
@ApiPropertyOptional()
chainId?: string[]

@IsOptional()
@IsNotEmptyArrayString()
@ApiPropertyOptional()
name?: string[]

@IsOptional()
@IsNotEmptyArrayString()
@IsHexString({ each: true })
@ApiPropertyOptional()
verifyingContract?: Address[]
}

Expand All @@ -155,93 +162,109 @@ export class PermitDeadlineCondition {

@IsNotEmpty()
@IsNumberString()
@ApiProperty({ type: String })
@ApiProperty()
value: string // timestamp in ms
}

export class ApprovalCondition {
@IsDefined()
@IsNumber()
@ApiProperty()
approvalCount: number

@IsDefined()
@IsBoolean()
@ApiProperty()
countPrincipal: boolean

@IsDefined()
@IsIn(Object.values(EntityType))
@ApiProperty({ enum: Object.values(EntityType) })
@IsEnum(EntityType)
@ApiProperty({ enum: EntityType })
approvalEntityType: EntityType

@IsNotEmptyArrayString()
@ApiProperty()
entityIds: string[]
}

export class SpendingLimitTimeWindow {
@IsEnum(TimeWindow)
@IsOptional()
@ApiPropertyOptional()
type?: TimeWindow

@IsNumber()
@IsOptional()
@ApiPropertyOptional()
value?: number // in seconds

@IsNumber()
@IsOptional()
@ApiPropertyOptional()
startDate?: number // in seconds

@IsNumber()
@IsOptional()
@ApiPropertyOptional()
endDate?: number // in seconds
}

export class SpendingLimitFilters {
@IsNotEmptyArrayString()
@IsAssetId({ each: true })
@IsOptional()
@ApiPropertyOptional()
tokens?: AssetId[]

@IsNotEmptyArrayString()
@IsOptional()
@ApiPropertyOptional()
users?: string[]

@IsNotEmptyArrayString()
@IsAccountId({ each: true })
@IsOptional()
@ApiPropertyOptional()
resources?: AccountId[]

@IsNotEmptyArrayString()
@IsNumberString({}, { each: true })
@IsOptional()
@ApiPropertyOptional()
chains?: string[]

@IsNotEmptyArrayString()
@IsOptional()
@ApiPropertyOptional()
userGroups?: string[]

@IsNotEmptyArrayString()
@IsOptional()
@ApiPropertyOptional()
walletGroups?: string[]
}

export class SpendingLimitCondition {
@IsNotEmpty()
@IsString()
@ApiProperty({ type: String })
@ApiProperty()
limit: string

@IsIn(Object.values(FiatCurrency))
@IsOptional()
@ApiPropertyOptional()
currency?: FiatCurrency

@ValidateNested()
@Type(() => SpendingLimitTimeWindow)
@IsOptional()
@ApiPropertyOptional()
timeWindow?: SpendingLimitTimeWindow

@ValidateNested()
@Type(() => SpendingLimitFilters)
@IsOptional()
@ApiPropertyOptional()
filters?: SpendingLimitFilters
}

Expand Down Expand Up @@ -610,7 +633,7 @@ export type PolicyCriterion =
export class Policy {
@IsNotEmpty()
@IsString()
@ApiProperty({ type: String })
@ApiProperty()
name: string

@IsArray()
Expand Down

0 comments on commit a2c2cd7

Please sign in to comment.