@tellescope/validation 1.6.2 → 1.7.4
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/lib/cjs/validation.d.ts +23 -8
- package/lib/cjs/validation.d.ts.map +1 -1
- package/lib/cjs/validation.js +127 -73
- package/lib/cjs/validation.js.map +1 -1
- package/lib/esm/validation.d.ts +23 -8
- package/lib/esm/validation.d.ts.map +1 -1
- package/lib/esm/validation.js +122 -68
- package/lib/esm/validation.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/validation.ts +142 -69
package/src/validation.ts
CHANGED
|
@@ -170,6 +170,13 @@ import {
|
|
|
170
170
|
CalendarEventPortalSettings,
|
|
171
171
|
AvailabilityBlock,
|
|
172
172
|
IndexUpdate,
|
|
173
|
+
FormResponseAnswerAddress,
|
|
174
|
+
ListQueryQualifier,
|
|
175
|
+
AutomationTriggerEventType,
|
|
176
|
+
AutomationTriggerEvents,
|
|
177
|
+
AutomationTriggerActionType,
|
|
178
|
+
AutomationTriggerActions,
|
|
179
|
+
AutomationTriggerStatus,
|
|
173
180
|
} from "@tellescope/types-models"
|
|
174
181
|
import {
|
|
175
182
|
DatabaseRecord,
|
|
@@ -957,6 +964,10 @@ export const numberValidator = numberValidatorBuilder({ lower: -10000000000000,
|
|
|
957
964
|
export const numberValidatorOptional = numberValidatorBuilder({ lower: -10000000000000, upper: 10000000000000, isOptional: true, emptyStringOk: true }) // max is 2286 in UTC MS
|
|
958
965
|
export const fileSizeValidator = numberValidatorBuilder({ lower: 0, upper: MAX_FILE_SIZE })
|
|
959
966
|
|
|
967
|
+
export const numberOrStringValidatorEmptyOkay = orValidator({
|
|
968
|
+
number: numberValidator,
|
|
969
|
+
string: stringValidator5000EmptyOkay,
|
|
970
|
+
})
|
|
960
971
|
export const numberOrStringValidatorOptional = orValidator({
|
|
961
972
|
number: numberValidatorOptional,
|
|
962
973
|
string: stringValidatorOptional
|
|
@@ -1038,6 +1049,67 @@ export const exactMatchValidatorOptional = <T extends string | null>(matches: T[
|
|
|
1038
1049
|
})
|
|
1039
1050
|
export const exactMatchListValidator = <T extends string | null>(matches: T[]) => listValidator(exactMatchValidator(matches))
|
|
1040
1051
|
|
|
1052
|
+
export const VALID_STATES: string[] = [
|
|
1053
|
+
"AK",
|
|
1054
|
+
"AL",
|
|
1055
|
+
"AR",
|
|
1056
|
+
"AS",
|
|
1057
|
+
"AZ",
|
|
1058
|
+
"CA",
|
|
1059
|
+
"CO",
|
|
1060
|
+
"CT",
|
|
1061
|
+
"DC",
|
|
1062
|
+
"DE",
|
|
1063
|
+
"FL",
|
|
1064
|
+
"GA",
|
|
1065
|
+
"GU",
|
|
1066
|
+
"HI",
|
|
1067
|
+
"IA",
|
|
1068
|
+
"ID",
|
|
1069
|
+
"IL",
|
|
1070
|
+
"IN",
|
|
1071
|
+
"KS",
|
|
1072
|
+
"KY",
|
|
1073
|
+
"LA",
|
|
1074
|
+
"MA",
|
|
1075
|
+
"MD",
|
|
1076
|
+
"ME",
|
|
1077
|
+
"MI",
|
|
1078
|
+
"MN",
|
|
1079
|
+
"MO",
|
|
1080
|
+
"MP",
|
|
1081
|
+
"MS",
|
|
1082
|
+
"MT",
|
|
1083
|
+
"NC",
|
|
1084
|
+
"ND",
|
|
1085
|
+
"NE",
|
|
1086
|
+
"NH",
|
|
1087
|
+
"NJ",
|
|
1088
|
+
"NM",
|
|
1089
|
+
"NV",
|
|
1090
|
+
"NY",
|
|
1091
|
+
"OH",
|
|
1092
|
+
"OK",
|
|
1093
|
+
"OR",
|
|
1094
|
+
"PA",
|
|
1095
|
+
"PR",
|
|
1096
|
+
"RI",
|
|
1097
|
+
"SC",
|
|
1098
|
+
"SD",
|
|
1099
|
+
"TN",
|
|
1100
|
+
"TX",
|
|
1101
|
+
"UM",
|
|
1102
|
+
"UT",
|
|
1103
|
+
"VA",
|
|
1104
|
+
"VI",
|
|
1105
|
+
"VT",
|
|
1106
|
+
"WA",
|
|
1107
|
+
"WI",
|
|
1108
|
+
"WV",
|
|
1109
|
+
"WY",
|
|
1110
|
+
]
|
|
1111
|
+
export const stateValidator = exactMatchValidator(VALID_STATES)
|
|
1112
|
+
|
|
1041
1113
|
export const journeysValidator: ValidatorDefinition<Indexable> = {
|
|
1042
1114
|
validate: (options={}) => build_validator(
|
|
1043
1115
|
(journeys) => {
|
|
@@ -1116,7 +1188,11 @@ export const fileTypeValidator: ValidatorDefinition<string> = {
|
|
|
1116
1188
|
|
|
1117
1189
|
return s
|
|
1118
1190
|
},
|
|
1119
|
-
{
|
|
1191
|
+
{
|
|
1192
|
+
...options,
|
|
1193
|
+
emptyStringOk: true, // allow empty string for unknown file types
|
|
1194
|
+
listOf: false,
|
|
1195
|
+
}
|
|
1120
1196
|
),
|
|
1121
1197
|
getExample: () => 'text/plain',
|
|
1122
1198
|
getType: getTypeString,
|
|
@@ -1239,11 +1315,13 @@ const _FORM_FIELD_TYPES: { [K in FormFieldType]: any } = {
|
|
|
1239
1315
|
"Question Group": '',
|
|
1240
1316
|
"Table Input": '',
|
|
1241
1317
|
description: '',
|
|
1318
|
+
Address: '',
|
|
1242
1319
|
}
|
|
1243
1320
|
export const FORM_FIELD_TYPES = Object.keys(_FORM_FIELD_TYPES) as FormFieldType[]
|
|
1244
1321
|
export const formFieldTypeValidator = exactMatchValidator<FormFieldType>(FORM_FIELD_TYPES)
|
|
1245
1322
|
|
|
1246
1323
|
export const FORM_FIELD_VALIDATORS_BY_TYPE: { [K in FormFieldType | 'userEmail' | 'phoneNumber']: (value?: FormResponseValueAnswer[keyof FormResponseValueAnswer], options?: any, isOptional?: boolean) => any } = {
|
|
1324
|
+
'Address': objectAnyFieldsAnyValuesValidator.validate(),
|
|
1247
1325
|
'description': g => '',
|
|
1248
1326
|
'Table Input': (g) => Array.isArray(g) ? g : [],
|
|
1249
1327
|
'Question Group': (g) => Array.isArray(g) ? g : [],
|
|
@@ -1529,6 +1607,16 @@ export const formResponseAnswerValidator = orValidator<{ [K in FormFieldType]: F
|
|
|
1529
1607
|
id: mongoIdStringRequired,
|
|
1530
1608
|
}))
|
|
1531
1609
|
}),
|
|
1610
|
+
"Address": objectValidator<FormResponseAnswerAddress>({
|
|
1611
|
+
type: exactMatchValidator(['Address']),
|
|
1612
|
+
value: objectValidator<FormResponseAnswerAddress['value']>({
|
|
1613
|
+
addressLineOne: stringValidator1000,
|
|
1614
|
+
addressLineTwo: stringValidator1000Optional,
|
|
1615
|
+
city: stringValidator1000,
|
|
1616
|
+
state: stateValidator,
|
|
1617
|
+
zipCode: stringValidator100
|
|
1618
|
+
})
|
|
1619
|
+
}),
|
|
1532
1620
|
"Table Input": objectValidator<FormResponseAnswerTable>({
|
|
1533
1621
|
type: exactMatchValidator(['Table Input']),
|
|
1534
1622
|
value: listValidatorOptionalOrEmptyOk( // optional to support optional Table Input questions
|
|
@@ -2393,71 +2481,10 @@ export const enduserFormResponseForEventValidator = objectValidator<EnduserFormR
|
|
|
2393
2481
|
export const enduserFormResponsesForEventValidator = listValidatorEmptyOk(enduserFormResponseForEventValidator)
|
|
2394
2482
|
|
|
2395
2483
|
export const genericUnitWithQuantityValidator = objectValidator<GenericQuantityWithUnit>({
|
|
2396
|
-
value:
|
|
2484
|
+
value: numberOrStringValidatorEmptyOkay,
|
|
2397
2485
|
unit: stringValidator1000,
|
|
2398
2486
|
})
|
|
2399
2487
|
|
|
2400
|
-
export const VALID_STATES: string[] = [
|
|
2401
|
-
"AK",
|
|
2402
|
-
"AL",
|
|
2403
|
-
"AR",
|
|
2404
|
-
"AS",
|
|
2405
|
-
"AZ",
|
|
2406
|
-
"CA",
|
|
2407
|
-
"CO",
|
|
2408
|
-
"CT",
|
|
2409
|
-
"DC",
|
|
2410
|
-
"DE",
|
|
2411
|
-
"FL",
|
|
2412
|
-
"GA",
|
|
2413
|
-
"GU",
|
|
2414
|
-
"HI",
|
|
2415
|
-
"IA",
|
|
2416
|
-
"ID",
|
|
2417
|
-
"IL",
|
|
2418
|
-
"IN",
|
|
2419
|
-
"KS",
|
|
2420
|
-
"KY",
|
|
2421
|
-
"LA",
|
|
2422
|
-
"MA",
|
|
2423
|
-
"MD",
|
|
2424
|
-
"ME",
|
|
2425
|
-
"MI",
|
|
2426
|
-
"MN",
|
|
2427
|
-
"MO",
|
|
2428
|
-
"MP",
|
|
2429
|
-
"MS",
|
|
2430
|
-
"MT",
|
|
2431
|
-
"NC",
|
|
2432
|
-
"ND",
|
|
2433
|
-
"NE",
|
|
2434
|
-
"NH",
|
|
2435
|
-
"NJ",
|
|
2436
|
-
"NM",
|
|
2437
|
-
"NV",
|
|
2438
|
-
"NY",
|
|
2439
|
-
"OH",
|
|
2440
|
-
"OK",
|
|
2441
|
-
"OR",
|
|
2442
|
-
"PA",
|
|
2443
|
-
"PR",
|
|
2444
|
-
"RI",
|
|
2445
|
-
"SC",
|
|
2446
|
-
"SD",
|
|
2447
|
-
"TN",
|
|
2448
|
-
"TX",
|
|
2449
|
-
"UM",
|
|
2450
|
-
"UT",
|
|
2451
|
-
"VA",
|
|
2452
|
-
"VI",
|
|
2453
|
-
"VT",
|
|
2454
|
-
"WA",
|
|
2455
|
-
"WI",
|
|
2456
|
-
"WV",
|
|
2457
|
-
"WY",
|
|
2458
|
-
]
|
|
2459
|
-
export const stateValidator = exactMatchValidator(VALID_STATES)
|
|
2460
|
-
|
|
2461
2488
|
export const stateCredentialValidator = objectValidator<StateCredentialInfo>({
|
|
2462
2489
|
expiresAt: dateValidatorOptional,
|
|
2463
2490
|
state: stateValidator,
|
|
@@ -2543,6 +2570,44 @@ export const calendarEventPortalSettingsValidator = objectValidator<CalendarEven
|
|
|
2543
2570
|
hideUsers: booleanValidatorOptional,
|
|
2544
2571
|
})
|
|
2545
2572
|
|
|
2573
|
+
const _AUTOMATION_TRIGGER_EVENT_TYPES: { [K in AutomationTriggerEventType]: any } = {
|
|
2574
|
+
"Form Submitted": true,
|
|
2575
|
+
}
|
|
2576
|
+
export const AUTOMATION_TRIGGER_EVENT_TYPES = Object.keys(_AUTOMATION_TRIGGER_EVENT_TYPES) as AutomationTriggerEventType[]
|
|
2577
|
+
|
|
2578
|
+
export const automationTriggerEventValidator = orValidator<{ [K in AutomationTriggerEventType]: AutomationTriggerEvents[K] } >({
|
|
2579
|
+
"Form Submitted": objectValidator<AutomationTriggerEvents["Form Submitted"]>({
|
|
2580
|
+
type: exactMatchValidator(['Form Submitted']),
|
|
2581
|
+
info: objectValidator<AutomationTriggerEvents['Form Submitted']['info']>({
|
|
2582
|
+
formId: mongoIdStringRequired,
|
|
2583
|
+
}),
|
|
2584
|
+
conditions: optionalEmptyObjectValidator,
|
|
2585
|
+
// info: objectValidator<AutomationTriggerEvents['Form Submitted']['conditions']>({ }),
|
|
2586
|
+
}),
|
|
2587
|
+
})
|
|
2588
|
+
|
|
2589
|
+
const _AUTOMATION_TRIGGER_ACTION_TYPES: { [K in AutomationTriggerActionType]: any } = {
|
|
2590
|
+
"Add To Journey": true,
|
|
2591
|
+
}
|
|
2592
|
+
export const AUTOMATION_TRIGGER_ACTION_TYPES = Object.keys(_AUTOMATION_TRIGGER_ACTION_TYPES) as AutomationTriggerActionType[]
|
|
2593
|
+
|
|
2594
|
+
export const automationTriggerActionValidator = orValidator<{ [K in AutomationTriggerActionType]: AutomationTriggerActions[K] } >({
|
|
2595
|
+
"Add To Journey": objectValidator<AutomationTriggerActions["Add To Journey"]>({
|
|
2596
|
+
type: exactMatchValidator(['Add To Journey']),
|
|
2597
|
+
info: objectValidator<AutomationTriggerActions['Add To Journey']['info']>({
|
|
2598
|
+
journeyId: mongoIdStringRequired,
|
|
2599
|
+
}),
|
|
2600
|
+
}),
|
|
2601
|
+
})
|
|
2602
|
+
|
|
2603
|
+
|
|
2604
|
+
const _AUTOMATION_TRIGGER_STATUSES: { [K in AutomationTriggerStatus]: any } = {
|
|
2605
|
+
Active: true,
|
|
2606
|
+
Inactive: true,
|
|
2607
|
+
}
|
|
2608
|
+
export const AUTOMATION_TRIGGER_STATUSES = Object.keys(_AUTOMATION_TRIGGER_STATUSES) as AutomationTriggerStatus[]
|
|
2609
|
+
export const automatioNTriggerStatusValidator = exactMatchValidator<AutomationTriggerStatus>(AUTOMATION_TRIGGER_STATUSES)
|
|
2610
|
+
|
|
2546
2611
|
// for each model name, this should be optional, but when a model name is provided, all CRUD fields should be required
|
|
2547
2612
|
// if this changes (e.g. CRUD fields are made optional), must merge better in authentication.ts in API
|
|
2548
2613
|
export const accessPermissionValidator = objectValidator<AccessForResource>({
|
|
@@ -2606,12 +2671,14 @@ export const accessPermissionsValidator = objectValidator<AccessPermissions>({
|
|
|
2606
2671
|
phone_calls: accessPermissionValidator,
|
|
2607
2672
|
background_errors: accessPermissionValidator,
|
|
2608
2673
|
enduser_views: accessPermissionValidator,
|
|
2674
|
+
automation_triggers: accessPermissionValidator,
|
|
2609
2675
|
|
|
2610
2676
|
// deprecated but for backwards compatibility
|
|
2611
2677
|
apiKeys: accessPermissionValidator,
|
|
2612
2678
|
})
|
|
2613
2679
|
|
|
2614
2680
|
export const organizationLimitsValidator = objectValidator<OrganizationLimits>({
|
|
2681
|
+
automation_triggers: numberValidatorOptional,
|
|
2615
2682
|
background_errors: numberValidatorOptional,
|
|
2616
2683
|
enduser_views: numberValidatorOptional,
|
|
2617
2684
|
availability_blocks: numberValidatorOptional,
|
|
@@ -2729,11 +2796,23 @@ export const integrationTitleValidator = exactMatchValidator<IntegrationsTitleTy
|
|
|
2729
2796
|
OUTLOOK_INTEGRATIONS_TITLE,
|
|
2730
2797
|
])
|
|
2731
2798
|
|
|
2799
|
+
const _LIST_QUERY_QUALIFIERS: { [K in ListQueryQualifier]: any} = {
|
|
2800
|
+
"One Of": '',
|
|
2801
|
+
"All Of": "",
|
|
2802
|
+
}
|
|
2803
|
+
export const LIST_QUERY_QUALIFIERS = Object.keys(_LIST_QUERY_QUALIFIERS) as ListQueryQualifier[]
|
|
2804
|
+
export const listQueryQualifiersValidator = exactMatchValidator<ListQueryQualifier>(LIST_QUERY_QUALIFIERS)
|
|
2805
|
+
|
|
2806
|
+
|
|
2732
2807
|
export const analyticsQueryValidator = orValidator<{ [K in AnalyticsQueryType]: AnalyticsQueryForType[K] } >({
|
|
2733
2808
|
Endusers: objectValidator<AnalyticsQueryForType['Endusers']>({
|
|
2734
2809
|
resource: exactMatchValidator<'Endusers'>(['Endusers']),
|
|
2735
2810
|
filter: objectValidator<AnalyticsQueryFilterForType['Endusers']>({
|
|
2736
2811
|
activeSince: dateOptionalOrEmptyStringValidator,
|
|
2812
|
+
"Submitted Forms": objectValidator<AnalyticsQueryFilterForType['Endusers']['Submitted Forms']>({
|
|
2813
|
+
qualifier: listQueryQualifiersValidator,
|
|
2814
|
+
formIds: listOfMongoIdStringValidator,
|
|
2815
|
+
}, { isOptional: true })
|
|
2737
2816
|
}, { isOptional: true, emptyOk: true }),
|
|
2738
2817
|
info: orValidator<{ [K in keyof AnalyticsQueryInfoForType['Endusers']]: AnalyticsQueryInfoForType['Endusers'][K] }>({
|
|
2739
2818
|
"Total": objectValidator<AnalyticsQueryInfoForType['Endusers']['Total']>({
|
|
@@ -2744,12 +2823,6 @@ export const analyticsQueryValidator = orValidator<{ [K in AnalyticsQueryType]:
|
|
|
2744
2823
|
method: exactMatchValidator<"Percentage">(['Percentage']),
|
|
2745
2824
|
parameters: optionalEmptyObjectValidator,
|
|
2746
2825
|
}),
|
|
2747
|
-
"Submitted Forms": objectValidator<AnalyticsQueryInfoForType['Endusers']['Submitted Forms']>({
|
|
2748
|
-
method: exactMatchValidator<"Submitted Forms">(['Submitted Forms']),
|
|
2749
|
-
parameters: objectValidator<AnalyticsQueryInfoForType['Endusers']['Submitted Forms']['parameters']>({
|
|
2750
|
-
formIds: listOfMongoIdStringValidator,
|
|
2751
|
-
}),
|
|
2752
|
-
}),
|
|
2753
2826
|
})
|
|
2754
2827
|
}),
|
|
2755
2828
|
"Calendar Events": objectValidator<AnalyticsQueryForType['Calendar Events']>({
|