@joeygrable94/utm-src-pub-validators 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@joeygrable94/utm-src-pub-validators",
3
+ "description": "Schema Validator for UTM.Src.Pub types",
4
+ "version": "0.0.3",
5
+ "author": "Joey Grable <joey@getcommunity.com> (https://joeygrable.com)",
6
+ "contributors": [],
7
+ "main": "src/index.ts",
8
+ "files": [
9
+ "src"
10
+ ],
11
+ "peerDependencies": {
12
+ "valibot": "^1.1.0"
13
+ },
14
+ "keywords": [],
15
+ "license": "ISC",
16
+ "private": false,
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "repository": "joeygrable94/utm-src-pub-validators.git",
21
+ "type": "module",
22
+ "scripts": {
23
+ "publish-manual": "npm publish"
24
+ }
25
+ }
@@ -0,0 +1,50 @@
1
+ // Generics
2
+ export const LIMIT_MIN_LABEL = 1
3
+ export const LIMIT_MAX_LABEL = 255
4
+ export const LIMIT_MIN_VALUE = 1
5
+ export const LIMIT_MAX_VALUE = 255
6
+ export const LIMIT_MAX_DESCRIPTION = 1024
7
+ // Users
8
+ export const LIMIT_MIN_USERNAME = 3
9
+ export const LIMIT_MAX_USERNAME = 255
10
+ export const LIMIT_MIN_EMAIL = 5
11
+ export const LIMIT_MAX_EMAIL = 255
12
+ export const LIMIT_MIN_PASSWORD = 8
13
+ export const LIMIT_MAX_PASSWORD = 255
14
+ export const LIMIT_MAX_PROVIDER = 255
15
+ // Strapi
16
+ export const LIMIT_MIN_NAME = 2
17
+ export const LIMIT_MAX_NAME = 255
18
+ export const LIMIT_MIN_PRODUCT_ID = 2
19
+ export const LIMIT_MAX_PRODUCT_ID = 64
20
+ export const LIMIT_MIN_PRICE_ID = 2
21
+ export const LIMIT_MAX_PRICE_ID = 64
22
+ export const LIMIT_MIN_UNIT_AMOUNT = 0
23
+ export const LIMIT_MIN_UNIT_TERM_IN_MONTHS = 1
24
+ export const LIMIT_MAX_UNIT_TERM_IN_MONTHS = 12
25
+ // URLs
26
+ export const LIMIT_MIN_DESTINATION = 10
27
+ export const LIMIT_MAX_DESTINATION = 2048
28
+ export const LIMIT_MIN_DOMAIN = 10
29
+ export const LIMIT_MAX_DOMAIN = 253
30
+ export const LIMIT_MIN_PATH = 1
31
+ export const LIMIT_MAX_PATH = 2038
32
+ export const LIMIT_MIN_QUERY = 1
33
+ export const LIMIT_MAX_QUERY = 2038
34
+ export const LIMIT_MIN_FRAGMENT = 1
35
+ export const LIMIT_MAX_FRAGMENT = 2038
36
+ // UTM Parameters
37
+ export const LIMIT_MIN_UTM_SOURCE = 1
38
+ export const LIMIT_MAX_UTM_SOURCE = 2026
39
+ export const LIMIT_MIN_UTM_MEDIUM = 1
40
+ export const LIMIT_MAX_UTM_MEDIUM = 2026
41
+ export const LIMIT_MIN_UTM_CAMPAIGN = 1
42
+ export const LIMIT_MAX_UTM_CAMPAIGN = 2024
43
+ export const LIMIT_MIN_UTM_CREATIVE_FORMAT = 1
44
+ export const LIMIT_MAX_UTM_CREATIVE_FORMAT = 2017
45
+ export const LIMIT_MIN_UTM_CONTENT = 1
46
+ export const LIMIT_MAX_UTM_CONTENT = 2025
47
+ export const LIMIT_MIN_UTM_TERM = 1
48
+ export const LIMIT_MAX_UTM_TERM = 2028
49
+ export const LIMIT_MIN_UTM_ID = 1
50
+ export const LIMIT_MAX_UTM_ID = 2030
@@ -0,0 +1,8 @@
1
+ // Generics
2
+ export const REGEX_VALUE = /^[a-zA-Z0-9._-]+$/
3
+ export const ERROR_MESSAGE_REGEX_VALUE = `can only contain letters, numbers, and the special characters: - _ .`
4
+
5
+ export const REGEX_DOMAIN =
6
+ /^(?=.{1,253}$)(?!\-)((xn--)?[a-zA-Z0-9]{1,59}(-[a-zA-Z0-9]{1,62})?\.)+([a-zA-Z]{2,63}|xn--[a-zA-Z0-9]{2,59})$/
7
+
8
+ export const ERROR_MESSAGE_REGEX_DOMAIN = 'please provide a valid domain name'
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ export * from './constants-limits'
2
+ export * from './constants-regex'
3
+ export * from './utilities'
4
+ export * from './validators-generics'
5
+ export * from './validators-groups'
6
+ export * from './validators-stripe'
7
+ export * from './validators-urls'
8
+ export * from './validators-users'
9
+ export * from './validators-utm-params'
@@ -0,0 +1,64 @@
1
+ import * as v from 'valibot'
2
+
3
+ function omitUndefined<T extends Record<string, any>>(obj: T): Partial<T> {
4
+ const result: Partial<T> = {}
5
+ for (const key in obj) {
6
+ if (obj[key] !== undefined) {
7
+ result[key] = obj[key]
8
+ }
9
+ }
10
+ return result
11
+ }
12
+
13
+ type ValidateAndCleanSuccess<T> = {
14
+ data: Partial<T>
15
+ error: null
16
+ errors: null
17
+ }
18
+
19
+ type ValidateAndCleanFailure<T> = {
20
+ data: null
21
+ error: string
22
+ errors: Record<string, string>
23
+ }
24
+
25
+ type ValidateAndCleanResult<T> = ValidateAndCleanSuccess<T> | ValidateAndCleanFailure<T>
26
+
27
+ export function validateAndClean<T>(
28
+ schema: v.BaseSchema<T, Partial<T>, v.BaseIssue<T>>,
29
+ input: unknown
30
+ ): ValidateAndCleanResult<T> {
31
+ try {
32
+ const parsed = v.parse(schema, input)
33
+ const cleaned = omitUndefined(parsed)
34
+ return { data: cleaned, error: null, errors: null }
35
+ } catch (err: unknown) {
36
+ if (err instanceof v.ValiError) {
37
+ const errors: Record<string, string> = {}
38
+ for (const issue of err.issues) {
39
+ const field = issue.path?.[0]?.key || 'unknown'
40
+ errors[field] = issue.message
41
+ }
42
+ return { data: null, error: null, errors }
43
+ }
44
+ let errorMessage = 'Unknown error'
45
+ if (err instanceof Error) {
46
+ errorMessage = err.message
47
+ } else {
48
+ errorMessage = String(err)
49
+ }
50
+ return { data: null, error: errorMessage, errors: null }
51
+ }
52
+ }
53
+
54
+ export function isValidationSuccess<T>(
55
+ result: ValidateAndCleanResult<T>
56
+ ): result is ValidateAndCleanSuccess<T> {
57
+ return result.error === null && result.errors === null
58
+ }
59
+
60
+ export function isValidationFailure<T>(
61
+ result: ValidateAndCleanResult<T>
62
+ ): result is ValidateAndCleanFailure<T> {
63
+ return result.error !== null || result.errors !== null
64
+ }
@@ -0,0 +1,90 @@
1
+ import * as v from 'valibot'
2
+ import {
3
+ LIMIT_MAX_LABEL,
4
+ LIMIT_MIN_LABEL,
5
+ LIMIT_MAX_VALUE,
6
+ LIMIT_MIN_VALUE,
7
+ LIMIT_MAX_DESCRIPTION,
8
+ LIMIT_MIN_NAME,
9
+ LIMIT_MAX_NAME
10
+ } from './constants-limits'
11
+ import { ERROR_MESSAGE_REGEX_VALUE, REGEX_VALUE } from './constants-regex'
12
+
13
+ // reference id for relationships
14
+ export const IsValidReferenceId = v.object({
15
+ id: v.number('please provide a valid id number')
16
+ })
17
+
18
+ // cost
19
+ export const IsValidCost = v.pipe(
20
+ v.number('please enter a cost value'),
21
+ v.minValue(0),
22
+ v.maxValue(
23
+ 1000000,
24
+ 'your campaign cost exceeds our $1 million dollar limit, please contact us for enterprise solutions'
25
+ )
26
+ )
27
+ export const IsValidOrUndefinedCost = v.undefinedable(IsValidCost)
28
+
29
+ // label
30
+ export const IsValidLabel = v.pipe(
31
+ v.string('please provide a label'),
32
+ v.trim(),
33
+ v.minLength(
34
+ LIMIT_MIN_LABEL,
35
+ `the label is too short, it must be at least ${LIMIT_MIN_LABEL} characters`
36
+ ),
37
+ v.maxLength(
38
+ LIMIT_MAX_LABEL,
39
+ `the label is too long, it must be ${LIMIT_MAX_LABEL} characters or less`
40
+ )
41
+ )
42
+ export const IsValidOrUndefinedLabel = v.undefinedable(IsValidLabel)
43
+
44
+ // value
45
+ export const IsValidValue = v.pipe(
46
+ v.string('please provide a value'),
47
+ v.trim(),
48
+ v.minLength(
49
+ LIMIT_MIN_VALUE,
50
+ `the value is too short, it must be at least ${LIMIT_MIN_VALUE} characters`
51
+ ),
52
+ v.maxLength(
53
+ LIMIT_MAX_VALUE,
54
+ `the value is too long, it must be ${LIMIT_MAX_VALUE} characters or less`
55
+ ),
56
+ v.regex(REGEX_VALUE, `the value ${ERROR_MESSAGE_REGEX_VALUE}`)
57
+ )
58
+ export const IsValidOrUndefinedValue = v.undefinedable(IsValidValue)
59
+
60
+ // description (optional)
61
+ export const IsValidDescription = v.nullable(
62
+ v.pipe(
63
+ v.string('the description must be a string'),
64
+ v.trim(),
65
+ v.maxLength(
66
+ LIMIT_MAX_DESCRIPTION,
67
+ `the description is too long, it must be ${LIMIT_MAX_DESCRIPTION} characters or less`
68
+ )
69
+ )
70
+ )
71
+ export const IsValidOrUndefinedDescription = v.optional(IsValidDescription)
72
+
73
+ // is_active
74
+ export const IsValidIsActive = v.boolean('isActive must be a boolean')
75
+ export const IsValidOrUndefinedIsActive = v.undefinedable(IsValidIsActive)
76
+
77
+ // name
78
+ export const IsValidName = v.pipe(
79
+ v.string('please provide a name'),
80
+ v.trim(),
81
+ v.minLength(
82
+ LIMIT_MIN_NAME,
83
+ `the name is too short, it must be at least ${LIMIT_MIN_NAME} characters`
84
+ ),
85
+ v.maxLength(
86
+ LIMIT_MAX_NAME,
87
+ `the name is too long, it must be ${LIMIT_MAX_NAME} characters or less`
88
+ )
89
+ )
90
+ export const IsValidOrUndefinedName = v.undefinedable(IsValidName)
@@ -0,0 +1,15 @@
1
+ import * as v from 'valibot'
2
+
3
+ export const IsValidApplyValueTo = v.picklist([
4
+ 'source',
5
+ 'medium',
6
+ 'campaign',
7
+ 'content',
8
+ 'creative',
9
+ 'term',
10
+ 'id'
11
+ ])
12
+ export const IsValidOrUndefinedApplyValueTo = v.nullable(IsValidApplyValueTo)
13
+
14
+ export const IsValidApplyValueAs = v.picklist(['prefix', 'suffix'])
15
+ export const IsValidOrUndefinedApplyValueAs = v.nullable(IsValidApplyValueAs)
@@ -0,0 +1,65 @@
1
+ import * as v from 'valibot'
2
+ import {
3
+ LIMIT_MIN_PRICE_ID,
4
+ LIMIT_MAX_PRICE_ID,
5
+ LIMIT_MIN_UNIT_AMOUNT,
6
+ LIMIT_MIN_UNIT_TERM_IN_MONTHS,
7
+ LIMIT_MAX_UNIT_TERM_IN_MONTHS,
8
+ LIMIT_MIN_PRODUCT_ID,
9
+ LIMIT_MAX_PRODUCT_ID
10
+ } from './constants-limits'
11
+
12
+ // product_id
13
+ export const IsValidProductId = v.pipe(
14
+ v.string('please provide a product_id'),
15
+ v.trim(),
16
+ v.minLength(
17
+ LIMIT_MIN_PRODUCT_ID,
18
+ `the product_id is too short, it must be at least ${LIMIT_MIN_PRODUCT_ID} characters`
19
+ ),
20
+ v.maxLength(
21
+ LIMIT_MAX_PRODUCT_ID,
22
+ `the product_id is too long, it must be ${LIMIT_MAX_PRODUCT_ID} characters or less`
23
+ )
24
+ )
25
+ export const IsValidOrUndefinedProductId = v.undefinedable(IsValidProductId)
26
+
27
+ // price_id
28
+ export const IsValidPriceId = v.pipe(
29
+ v.string('please provide a price_id'),
30
+ v.trim(),
31
+ v.minLength(
32
+ LIMIT_MIN_PRICE_ID,
33
+ `the price_id is too short, it must be at least ${LIMIT_MIN_PRICE_ID} characters`
34
+ ),
35
+ v.maxLength(
36
+ LIMIT_MAX_PRICE_ID,
37
+ `the price_id is too long, it must be ${LIMIT_MAX_PRICE_ID} characters or less`
38
+ )
39
+ )
40
+ export const IsValidOrUndefinedPriceId = v.undefinedable(IsValidPriceId)
41
+
42
+ // unit_amount
43
+ export const IsValidUnitAmount = v.pipe(
44
+ v.number('please provide a unit_amount'),
45
+ v.minValue(
46
+ LIMIT_MIN_UNIT_AMOUNT,
47
+ `the unit_amount must be a decimal greater than or equal to ${LIMIT_MIN_UNIT_AMOUNT}`
48
+ )
49
+ )
50
+ export const IsValidOrUndefinedUnitAmount = v.undefinedable(IsValidUnitAmount)
51
+
52
+ export const IsValidUnitTermInMonths = v.pipe(
53
+ v.number('please provide a unit_term_in_months'),
54
+ v.minValue(
55
+ LIMIT_MIN_UNIT_TERM_IN_MONTHS,
56
+ `the unit_term_in_months must be an integer greater than or equal to ${LIMIT_MIN_UNIT_TERM_IN_MONTHS}`
57
+ ),
58
+ v.maxValue(
59
+ LIMIT_MAX_UNIT_TERM_IN_MONTHS,
60
+ `the unit_term_in_months must be an integer less than or equal to ${LIMIT_MAX_UNIT_TERM_IN_MONTHS}`
61
+ )
62
+ )
63
+ export const IsValidOrUndefinedUnitTermInMonths = v.undefinedable(
64
+ IsValidUnitTermInMonths
65
+ )
@@ -0,0 +1,98 @@
1
+ import * as v from 'valibot'
2
+ import {
3
+ LIMIT_MAX_DESTINATION,
4
+ LIMIT_MAX_DOMAIN,
5
+ LIMIT_MAX_FRAGMENT,
6
+ LIMIT_MAX_PATH,
7
+ LIMIT_MAX_QUERY,
8
+ LIMIT_MIN_DESTINATION,
9
+ LIMIT_MIN_DOMAIN,
10
+ LIMIT_MIN_FRAGMENT,
11
+ LIMIT_MIN_PATH,
12
+ LIMIT_MIN_QUERY
13
+ } from './constants-limits'
14
+ import { ERROR_MESSAGE_REGEX_DOMAIN, REGEX_DOMAIN } from './constants-regex'
15
+
16
+ // destination
17
+ export const IsValidUrlDestination = v.pipe(
18
+ v.string('please provide a url destination'),
19
+ v.trim(),
20
+ v.minLength(
21
+ LIMIT_MIN_DESTINATION,
22
+ `the url destination is too short, it must be at least ${LIMIT_MIN_DESTINATION} characters`
23
+ ),
24
+ v.maxLength(
25
+ LIMIT_MAX_DESTINATION,
26
+ `the url destination is too long, it must be ${LIMIT_MAX_DESTINATION} characters or less`
27
+ ),
28
+ v.url('please provide a valid url')
29
+ )
30
+ export const IsValidOrUndefinedUrlDestination = v.nullable(IsValidUrlDestination)
31
+
32
+ // protocol
33
+ export const IsValidUrlProtocol = v.picklist(
34
+ ['http', 'https'],
35
+ 'please provide a valid url protocol'
36
+ )
37
+ export const IsValidOrUndefinedUrlProtocol = v.nullable(IsValidUrlProtocol)
38
+
39
+ // domain
40
+ export const IsValidUrlDomain = v.pipe(
41
+ v.string('please provide a domain'),
42
+ v.trim(),
43
+ v.minLength(
44
+ LIMIT_MIN_DOMAIN,
45
+ `the domain is too short, it must be at least ${LIMIT_MIN_DOMAIN} characters`
46
+ ),
47
+ v.maxLength(
48
+ LIMIT_MAX_DOMAIN,
49
+ `the domain is too long, it must be ${LIMIT_MAX_DOMAIN} characters or less`
50
+ ),
51
+ v.regex(REGEX_DOMAIN, ERROR_MESSAGE_REGEX_DOMAIN)
52
+ )
53
+ export const IsValidOrUndefinedUrlDomain = v.nullable(IsValidUrlDomain)
54
+
55
+ // path
56
+ export const IsValidUrlPath = v.pipe(
57
+ v.string('please provide a url path'),
58
+ v.trim(),
59
+ v.minLength(
60
+ LIMIT_MIN_PATH,
61
+ `the url path is too short, it must be at least ${LIMIT_MIN_PATH} characters`
62
+ ),
63
+ v.maxLength(
64
+ LIMIT_MAX_PATH,
65
+ `the url path is too long, it must be ${LIMIT_MAX_PATH} characters or less`
66
+ )
67
+ )
68
+ export const IsValidOrUndefinedUrlPath = v.nullable(IsValidUrlPath)
69
+
70
+ // query
71
+ export const IsValidUrlQuery = v.pipe(
72
+ v.string('please provide a url query'),
73
+ v.trim(),
74
+ v.minLength(
75
+ LIMIT_MIN_QUERY,
76
+ `the url query is too short, it must be at least ${LIMIT_MIN_QUERY} characters`
77
+ ),
78
+ v.maxLength(
79
+ LIMIT_MAX_QUERY,
80
+ `the url query is too long, it must be ${LIMIT_MAX_QUERY} characters or less`
81
+ )
82
+ )
83
+ export const IsValidOrUndefinedUrlQuery = v.nullable(IsValidUrlQuery)
84
+
85
+ // fragment
86
+ export const IsValidUrlFragment = v.pipe(
87
+ v.string('please provide a url hash/fragment'),
88
+ v.trim(),
89
+ v.minLength(
90
+ LIMIT_MIN_FRAGMENT,
91
+ `the url hash/fragment is too short, it must be at least ${LIMIT_MIN_FRAGMENT} characters`
92
+ ),
93
+ v.maxLength(
94
+ LIMIT_MAX_FRAGMENT,
95
+ `the url hash/fragment is too long, it must be ${LIMIT_MAX_FRAGMENT} characters or less`
96
+ )
97
+ )
98
+ export const IsValidOrUndefinedUrlFragment = v.nullable(IsValidUrlFragment)
@@ -0,0 +1,71 @@
1
+ import * as v from 'valibot'
2
+ import {
3
+ LIMIT_MAX_EMAIL,
4
+ LIMIT_MAX_PASSWORD,
5
+ LIMIT_MAX_PROVIDER,
6
+ LIMIT_MAX_USERNAME,
7
+ LIMIT_MIN_EMAIL,
8
+ LIMIT_MIN_PASSWORD,
9
+ LIMIT_MIN_USERNAME
10
+ } from './constants-limits'
11
+ import { ERROR_MESSAGE_REGEX_VALUE, REGEX_VALUE } from './constants-regex'
12
+
13
+ export const IsValidUsername = v.pipe(
14
+ v.string('please provide a username'),
15
+ v.trim(),
16
+ v.minLength(
17
+ LIMIT_MIN_USERNAME,
18
+ `your username is too short, it must be at least ${LIMIT_MIN_USERNAME} characters`
19
+ ),
20
+ v.maxLength(
21
+ LIMIT_MAX_USERNAME,
22
+ `your username is too long, it must be ${LIMIT_MAX_USERNAME} characters or less`
23
+ ),
24
+ v.regex(REGEX_VALUE, `your username ${ERROR_MESSAGE_REGEX_VALUE}`)
25
+ )
26
+ export const IsValidOrUndefinedUsername = v.undefinedable(IsValidUsername)
27
+
28
+ export const IsValidEmail = v.pipe(
29
+ v.string('please provide an email'),
30
+ v.trim(),
31
+ v.minLength(
32
+ LIMIT_MIN_EMAIL,
33
+ `your email is too short, it must be at least ${LIMIT_MIN_EMAIL} characters`
34
+ ),
35
+ v.maxLength(
36
+ LIMIT_MAX_EMAIL,
37
+ `your email is too long, it must be ${LIMIT_MAX_EMAIL} characters or less`
38
+ ),
39
+ v.email('please provide a valid email address')
40
+ )
41
+ export const IsValidOrUndefinedEmail = v.undefinedable(IsValidEmail)
42
+
43
+ export const IsValidPassword = v.pipe(
44
+ v.string('a password is required'),
45
+ v.trim(),
46
+ v.minLength(
47
+ LIMIT_MIN_PASSWORD,
48
+ `your password is too short, it must be at least ${LIMIT_MIN_PASSWORD} characters`
49
+ ),
50
+ v.maxLength(
51
+ LIMIT_MAX_PASSWORD,
52
+ `your password is too long, it must be ${LIMIT_MAX_PASSWORD} characters or less`
53
+ )
54
+ )
55
+ export const IsValidOrUndefinedPassword = v.undefinedable(IsValidPassword)
56
+
57
+ export const IsValidProvider = v.pipe(
58
+ v.string('please enter a provider'),
59
+ v.trim(),
60
+ v.maxLength(
61
+ LIMIT_MAX_PROVIDER,
62
+ `the provider string is too long, it must be ${LIMIT_MAX_PROVIDER} characters or less`
63
+ )
64
+ )
65
+ export const IsValidOrUndefinedProvider = v.undefinedable(IsValidProvider)
66
+
67
+ export const IsValidConfirmed = v.boolean()
68
+ export const IsValidOrUndefinedConfirmed = v.undefinedable(IsValidConfirmed)
69
+
70
+ export const IsValidBlocked = v.boolean()
71
+ export const IsValidOrUndefinedBlocked = v.undefinedable(IsValidBlocked)
@@ -0,0 +1,132 @@
1
+ import * as v from 'valibot'
2
+ import {
3
+ LIMIT_MAX_UTM_CAMPAIGN,
4
+ LIMIT_MAX_UTM_CREATIVE_FORMAT,
5
+ LIMIT_MAX_UTM_MEDIUM,
6
+ LIMIT_MAX_UTM_SOURCE,
7
+ LIMIT_MIN_UTM_CAMPAIGN,
8
+ LIMIT_MIN_UTM_CREATIVE_FORMAT,
9
+ LIMIT_MIN_UTM_MEDIUM,
10
+ LIMIT_MIN_UTM_SOURCE,
11
+ LIMIT_MIN_UTM_CONTENT,
12
+ LIMIT_MAX_UTM_CONTENT,
13
+ LIMIT_MIN_UTM_TERM,
14
+ LIMIT_MAX_UTM_TERM,
15
+ LIMIT_MIN_UTM_ID,
16
+ LIMIT_MAX_UTM_ID
17
+ } from './constants-limits'
18
+ import { ERROR_MESSAGE_REGEX_VALUE, REGEX_VALUE } from './constants-regex'
19
+
20
+ // utm_source
21
+ export const IsValidUrlUtmSource = v.pipe(
22
+ v.string(),
23
+ v.trim(),
24
+ v.minLength(
25
+ LIMIT_MIN_UTM_SOURCE,
26
+ `the utm_source is too short, it must be at least ${LIMIT_MIN_UTM_SOURCE} characters`
27
+ ),
28
+ v.maxLength(
29
+ LIMIT_MAX_UTM_SOURCE,
30
+ `the utm_source is too long, it must be ${LIMIT_MAX_UTM_SOURCE} characters or less`
31
+ ),
32
+ v.regex(REGEX_VALUE, `utm_source ${ERROR_MESSAGE_REGEX_VALUE}`)
33
+ )
34
+ export const IsValidOrUndefinedUrlUtmSource = v.nullable(IsValidUrlUtmSource)
35
+
36
+ // utm_medium
37
+ export const IsValidUrlUtmMedium = v.pipe(
38
+ v.string(),
39
+ v.trim(),
40
+ v.minLength(
41
+ LIMIT_MIN_UTM_MEDIUM,
42
+ `the utm_medium is too short, it must be at least ${LIMIT_MIN_UTM_MEDIUM} characters`
43
+ ),
44
+ v.maxLength(
45
+ LIMIT_MAX_UTM_MEDIUM,
46
+ `the utm_medium is too long, it must be ${LIMIT_MAX_UTM_MEDIUM} characters or less`
47
+ ),
48
+ v.regex(REGEX_VALUE, `utm_medium ${ERROR_MESSAGE_REGEX_VALUE}`)
49
+ )
50
+ export const IsValidOrUndefinedUrlUtmMedium = v.nullable(IsValidUrlUtmMedium)
51
+
52
+ // utm_campaign
53
+ export const IsValidUrlUtmCampaign = v.pipe(
54
+ v.string(),
55
+ v.trim(),
56
+ v.minLength(
57
+ LIMIT_MIN_UTM_CAMPAIGN,
58
+ `the utm_campaign is too short, it must be at least ${LIMIT_MIN_UTM_CAMPAIGN} characters`
59
+ ),
60
+ v.maxLength(
61
+ LIMIT_MAX_UTM_CAMPAIGN,
62
+ `the utm_campaign is too long, it must be ${LIMIT_MAX_UTM_CAMPAIGN} characters or less`
63
+ ),
64
+ v.regex(REGEX_VALUE, `utm_campaign ${ERROR_MESSAGE_REGEX_VALUE}`)
65
+ )
66
+ export const IsValidOrUndefinedUrlUtmCampaign = v.nullable(IsValidUrlUtmCampaign)
67
+
68
+ // utm_creative_format
69
+ export const IsValidUrlUtmCreativeFormat = v.pipe(
70
+ v.string(),
71
+ v.trim(),
72
+ v.minLength(
73
+ LIMIT_MIN_UTM_CREATIVE_FORMAT,
74
+ `the utm_creative_format is too short, it must be at least ${LIMIT_MIN_UTM_CREATIVE_FORMAT} characters`
75
+ ),
76
+ v.maxLength(
77
+ LIMIT_MAX_UTM_CREATIVE_FORMAT,
78
+ `the utm_creative_format is too long, it must be ${LIMIT_MAX_UTM_CREATIVE_FORMAT} characters or less`
79
+ ),
80
+ v.regex(REGEX_VALUE, `utm_creative_format ${ERROR_MESSAGE_REGEX_VALUE}`)
81
+ )
82
+ export const IsValidOrUndefinedUrlUtmCreativeFormat = v.nullable(
83
+ IsValidUrlUtmCreativeFormat
84
+ )
85
+
86
+ // utm_content
87
+ export const IsValidUrlUtmContent = v.pipe(
88
+ v.string(),
89
+ v.trim(),
90
+ v.minLength(
91
+ LIMIT_MIN_UTM_CONTENT,
92
+ `the utm_content is too short, it must be at least ${LIMIT_MIN_UTM_CONTENT} characters`
93
+ ),
94
+ v.maxLength(
95
+ LIMIT_MAX_UTM_CONTENT,
96
+ `the utm_content is too long, it must be ${LIMIT_MAX_UTM_CONTENT} characters or less`
97
+ ),
98
+ v.regex(REGEX_VALUE, `utm_content ${ERROR_MESSAGE_REGEX_VALUE}`)
99
+ )
100
+ export const IsValidOrUndefinedUrlUtmContent = v.nullable(IsValidUrlUtmContent)
101
+
102
+ // utm_term
103
+ export const IsValidUrlUtmTerm = v.pipe(
104
+ v.string(),
105
+ v.trim(),
106
+ v.minLength(
107
+ LIMIT_MIN_UTM_TERM,
108
+ `the utm_term is too short, it must be at least ${LIMIT_MIN_UTM_TERM} characters`
109
+ ),
110
+ v.maxLength(
111
+ LIMIT_MAX_UTM_TERM,
112
+ `the utm_term is too long, it must be ${LIMIT_MAX_UTM_TERM} characters or less`
113
+ ),
114
+ v.regex(REGEX_VALUE, `utm_term ${ERROR_MESSAGE_REGEX_VALUE}`)
115
+ )
116
+ export const IsValidOrUndefinedUrlUtmTerm = v.nullable(IsValidUrlUtmTerm)
117
+
118
+ // utm_id
119
+ export const IsValidUrlUtmId = v.pipe(
120
+ v.string(),
121
+ v.trim(),
122
+ v.minLength(
123
+ LIMIT_MIN_UTM_ID,
124
+ `the utm_id is too short, it must be at least ${LIMIT_MIN_UTM_ID} characters`
125
+ ),
126
+ v.maxLength(
127
+ LIMIT_MAX_UTM_ID,
128
+ `the utm_id is too long, it must be ${LIMIT_MAX_UTM_ID} characters or less`
129
+ ),
130
+ v.regex(REGEX_VALUE, `utm_id ${ERROR_MESSAGE_REGEX_VALUE}`)
131
+ )
132
+ export const IsValidOrUndefinedUrlUtmId = v.nullable(IsValidUrlUtmId)