Skip to content

Commit

Permalink
more validation
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-ayoub-segment committed Oct 21, 2024
1 parent ddeee29 commit 4902b18
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const RESERVED_HEADERS = ["x-sg-id", "x-sg-eid", "received", "dkim-signat

export const MAX_CATEGORY_LENGTH = 255

export const MAINIP_POOL_NAME_LENGTH = 2
export const MIN_IP_POOL_NAME_LENGTH = 2

export const MAX_IP_POOL_NAME_LENGTH = 64

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RequestClient, PayloadValidationError } from '@segment/actions-core'
import type { Payload } from './generated-types'
import { sendEmailReq } from './types'
import { RESERVED_HEADERS, MAX_CATEGORY_LENGTH } from './constants'
import { RESERVED_HEADERS, MAX_CATEGORY_LENGTH, MIN_IP_POOL_NAME_LENGTH, MAX_IP_POOL_NAME_LENGTH } from './constants'

export async function send(request: RequestClient, payload: Payload) {
validate(payload)
Expand Down Expand Up @@ -86,5 +86,9 @@ function validate(payload: Payload){
}
}

if(payload.ipPoolName && (payload.ipPoolName.length >= MAX_IP_POOL_NAME_LENGTH || payload.ipPoolName.length <= MIN_IP_POOL_NAME_LENGTH)) {
throw new PayloadValidationError(`IP Pool Name should at least ${MIN_IP_POOL_NAME_LENGTH} characters and at most ${MAX_IP_POOL_NAME_LENGTH} characters in length`)
}

return
}

0 comments on commit 4902b18

Please sign in to comment.