@tellescope/validation 1.6.2 → 1.7.0
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 +22 -8
- package/lib/cjs/validation.d.ts.map +1 -1
- package/lib/cjs/validation.js +121 -71
- package/lib/cjs/validation.js.map +1 -1
- package/lib/esm/validation.d.ts +22 -8
- package/lib/esm/validation.d.ts.map +1 -1
- package/lib/esm/validation.js +116 -66
- package/lib/esm/validation.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/validation.ts +132 -67
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,
|
|
@@ -1038,6 +1045,67 @@ export const exactMatchValidatorOptional = <T extends string | null>(matches: T[
|
|
|
1038
1045
|
})
|
|
1039
1046
|
export const exactMatchListValidator = <T extends string | null>(matches: T[]) => listValidator(exactMatchValidator(matches))
|
|
1040
1047
|
|
|
1048
|
+
export const VALID_STATES: string[] = [
|
|
1049
|
+
"AK",
|
|
1050
|
+
"AL",
|
|
1051
|
+
"AR",
|
|
1052
|
+
"AS",
|
|
1053
|
+
"AZ",
|
|
1054
|
+
"CA",
|
|
1055
|
+
"CO",
|
|
1056
|
+
"CT",
|
|
1057
|
+
"DC",
|
|
1058
|
+
"DE",
|
|
1059
|
+
"FL",
|
|
1060
|
+
"GA",
|
|
1061
|
+
"GU",
|
|
1062
|
+
"HI",
|
|
1063
|
+
"IA",
|
|
1064
|
+
"ID",
|
|
1065
|
+
"IL",
|
|
1066
|
+
"IN",
|
|
1067
|
+
"KS",
|
|
1068
|
+
"KY",
|
|
1069
|
+
"LA",
|
|
1070
|
+
"MA",
|
|
1071
|
+
"MD",
|
|
1072
|
+
"ME",
|
|
1073
|
+
"MI",
|
|
1074
|
+
"MN",
|
|
1075
|
+
"MO",
|
|
1076
|
+
"MP",
|
|
1077
|
+
"MS",
|
|
1078
|
+
"MT",
|
|
1079
|
+
"NC",
|
|
1080
|
+
"ND",
|
|
1081
|
+
"NE",
|
|
1082
|
+
"NH",
|
|
1083
|
+
"NJ",
|
|
1084
|
+
"NM",
|
|
1085
|
+
"NV",
|
|
1086
|
+
"NY",
|
|
1087
|
+
"OH",
|
|
1088
|
+
"OK",
|
|
1089
|
+
"OR",
|
|
1090
|
+
"PA",
|
|
1091
|
+
"PR",
|
|
1092
|
+
"RI",
|
|
1093
|
+
"SC",
|
|
1094
|
+
"SD",
|
|
1095
|
+
"TN",
|
|
1096
|
+
"TX",
|
|
1097
|
+
"UM",
|
|
1098
|
+
"UT",
|
|
1099
|
+
"VA",
|
|
1100
|
+
"VI",
|
|
1101
|
+
"VT",
|
|
1102
|
+
"WA",
|
|
1103
|
+
"WI",
|
|
1104
|
+
"WV",
|
|
1105
|
+
"WY",
|
|
1106
|
+
]
|
|
1107
|
+
export const stateValidator = exactMatchValidator(VALID_STATES)
|
|
1108
|
+
|
|
1041
1109
|
export const journeysValidator: ValidatorDefinition<Indexable> = {
|
|
1042
1110
|
validate: (options={}) => build_validator(
|
|
1043
1111
|
(journeys) => {
|
|
@@ -1239,11 +1307,13 @@ const _FORM_FIELD_TYPES: { [K in FormFieldType]: any } = {
|
|
|
1239
1307
|
"Question Group": '',
|
|
1240
1308
|
"Table Input": '',
|
|
1241
1309
|
description: '',
|
|
1310
|
+
Address: '',
|
|
1242
1311
|
}
|
|
1243
1312
|
export const FORM_FIELD_TYPES = Object.keys(_FORM_FIELD_TYPES) as FormFieldType[]
|
|
1244
1313
|
export const formFieldTypeValidator = exactMatchValidator<FormFieldType>(FORM_FIELD_TYPES)
|
|
1245
1314
|
|
|
1246
1315
|
export const FORM_FIELD_VALIDATORS_BY_TYPE: { [K in FormFieldType | 'userEmail' | 'phoneNumber']: (value?: FormResponseValueAnswer[keyof FormResponseValueAnswer], options?: any, isOptional?: boolean) => any } = {
|
|
1316
|
+
'Address': objectAnyFieldsAnyValuesValidator.validate(),
|
|
1247
1317
|
'description': g => '',
|
|
1248
1318
|
'Table Input': (g) => Array.isArray(g) ? g : [],
|
|
1249
1319
|
'Question Group': (g) => Array.isArray(g) ? g : [],
|
|
@@ -1529,6 +1599,16 @@ export const formResponseAnswerValidator = orValidator<{ [K in FormFieldType]: F
|
|
|
1529
1599
|
id: mongoIdStringRequired,
|
|
1530
1600
|
}))
|
|
1531
1601
|
}),
|
|
1602
|
+
"Address": objectValidator<FormResponseAnswerAddress>({
|
|
1603
|
+
type: exactMatchValidator(['Address']),
|
|
1604
|
+
value: objectValidator<FormResponseAnswerAddress['value']>({
|
|
1605
|
+
addressLineOne: stringValidator1000,
|
|
1606
|
+
addressLineTwo: stringValidator1000Optional,
|
|
1607
|
+
city: stringValidator1000,
|
|
1608
|
+
state: stateValidator,
|
|
1609
|
+
zipCode: stringValidator100
|
|
1610
|
+
})
|
|
1611
|
+
}),
|
|
1532
1612
|
"Table Input": objectValidator<FormResponseAnswerTable>({
|
|
1533
1613
|
type: exactMatchValidator(['Table Input']),
|
|
1534
1614
|
value: listValidatorOptionalOrEmptyOk( // optional to support optional Table Input questions
|
|
@@ -2397,67 +2477,6 @@ export const genericUnitWithQuantityValidator = objectValidator<GenericQuantityW
|
|
|
2397
2477
|
unit: stringValidator1000,
|
|
2398
2478
|
})
|
|
2399
2479
|
|
|
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
2480
|
export const stateCredentialValidator = objectValidator<StateCredentialInfo>({
|
|
2462
2481
|
expiresAt: dateValidatorOptional,
|
|
2463
2482
|
state: stateValidator,
|
|
@@ -2543,6 +2562,44 @@ export const calendarEventPortalSettingsValidator = objectValidator<CalendarEven
|
|
|
2543
2562
|
hideUsers: booleanValidatorOptional,
|
|
2544
2563
|
})
|
|
2545
2564
|
|
|
2565
|
+
const _AUTOMATION_TRIGGER_EVENT_TYPES: { [K in AutomationTriggerEventType]: any } = {
|
|
2566
|
+
"Form Submitted": true,
|
|
2567
|
+
}
|
|
2568
|
+
export const AUTOMATION_TRIGGER_EVENT_TYPES = Object.keys(_AUTOMATION_TRIGGER_EVENT_TYPES) as AutomationTriggerEventType[]
|
|
2569
|
+
|
|
2570
|
+
export const automationTriggerEventValidator = orValidator<{ [K in AutomationTriggerEventType]: AutomationTriggerEvents[K] } >({
|
|
2571
|
+
"Form Submitted": objectValidator<AutomationTriggerEvents["Form Submitted"]>({
|
|
2572
|
+
type: exactMatchValidator(['Form Submitted']),
|
|
2573
|
+
info: objectValidator<AutomationTriggerEvents['Form Submitted']['info']>({
|
|
2574
|
+
formId: mongoIdStringRequired,
|
|
2575
|
+
}),
|
|
2576
|
+
conditions: optionalEmptyObjectValidator,
|
|
2577
|
+
// info: objectValidator<AutomationTriggerEvents['Form Submitted']['conditions']>({ }),
|
|
2578
|
+
}),
|
|
2579
|
+
})
|
|
2580
|
+
|
|
2581
|
+
const _AUTOMATION_TRIGGER_ACTION_TYPES: { [K in AutomationTriggerActionType]: any } = {
|
|
2582
|
+
"Add To Journey": true,
|
|
2583
|
+
}
|
|
2584
|
+
export const AUTOMATION_TRIGGER_ACTION_TYPES = Object.keys(_AUTOMATION_TRIGGER_ACTION_TYPES) as AutomationTriggerActionType[]
|
|
2585
|
+
|
|
2586
|
+
export const automationTriggerActionValidator = orValidator<{ [K in AutomationTriggerActionType]: AutomationTriggerActions[K] } >({
|
|
2587
|
+
"Add To Journey": objectValidator<AutomationTriggerActions["Add To Journey"]>({
|
|
2588
|
+
type: exactMatchValidator(['Add To Journey']),
|
|
2589
|
+
info: objectValidator<AutomationTriggerActions['Add To Journey']['info']>({
|
|
2590
|
+
journeyId: mongoIdStringRequired,
|
|
2591
|
+
}),
|
|
2592
|
+
}),
|
|
2593
|
+
})
|
|
2594
|
+
|
|
2595
|
+
|
|
2596
|
+
const _AUTOMATION_TRIGGER_STATUSES: { [K in AutomationTriggerStatus]: any } = {
|
|
2597
|
+
Active: true,
|
|
2598
|
+
Inactive: true,
|
|
2599
|
+
}
|
|
2600
|
+
export const AUTOMATION_TRIGGER_STATUSES = Object.keys(_AUTOMATION_TRIGGER_STATUSES) as AutomationTriggerStatus[]
|
|
2601
|
+
export const automatioNTriggerStatusValidator = exactMatchValidator<AutomationTriggerStatus>(AUTOMATION_TRIGGER_STATUSES)
|
|
2602
|
+
|
|
2546
2603
|
// for each model name, this should be optional, but when a model name is provided, all CRUD fields should be required
|
|
2547
2604
|
// if this changes (e.g. CRUD fields are made optional), must merge better in authentication.ts in API
|
|
2548
2605
|
export const accessPermissionValidator = objectValidator<AccessForResource>({
|
|
@@ -2606,12 +2663,14 @@ export const accessPermissionsValidator = objectValidator<AccessPermissions>({
|
|
|
2606
2663
|
phone_calls: accessPermissionValidator,
|
|
2607
2664
|
background_errors: accessPermissionValidator,
|
|
2608
2665
|
enduser_views: accessPermissionValidator,
|
|
2666
|
+
automation_triggers: accessPermissionValidator,
|
|
2609
2667
|
|
|
2610
2668
|
// deprecated but for backwards compatibility
|
|
2611
2669
|
apiKeys: accessPermissionValidator,
|
|
2612
2670
|
})
|
|
2613
2671
|
|
|
2614
2672
|
export const organizationLimitsValidator = objectValidator<OrganizationLimits>({
|
|
2673
|
+
automation_triggers: numberValidatorOptional,
|
|
2615
2674
|
background_errors: numberValidatorOptional,
|
|
2616
2675
|
enduser_views: numberValidatorOptional,
|
|
2617
2676
|
availability_blocks: numberValidatorOptional,
|
|
@@ -2729,11 +2788,23 @@ export const integrationTitleValidator = exactMatchValidator<IntegrationsTitleTy
|
|
|
2729
2788
|
OUTLOOK_INTEGRATIONS_TITLE,
|
|
2730
2789
|
])
|
|
2731
2790
|
|
|
2791
|
+
const _LIST_QUERY_QUALIFIERS: { [K in ListQueryQualifier]: any} = {
|
|
2792
|
+
"One Of": '',
|
|
2793
|
+
"All Of": "",
|
|
2794
|
+
}
|
|
2795
|
+
export const LIST_QUERY_QUALIFIERS = Object.keys(_LIST_QUERY_QUALIFIERS) as ListQueryQualifier[]
|
|
2796
|
+
export const listQueryQualifiersValidator = exactMatchValidator<ListQueryQualifier>(LIST_QUERY_QUALIFIERS)
|
|
2797
|
+
|
|
2798
|
+
|
|
2732
2799
|
export const analyticsQueryValidator = orValidator<{ [K in AnalyticsQueryType]: AnalyticsQueryForType[K] } >({
|
|
2733
2800
|
Endusers: objectValidator<AnalyticsQueryForType['Endusers']>({
|
|
2734
2801
|
resource: exactMatchValidator<'Endusers'>(['Endusers']),
|
|
2735
2802
|
filter: objectValidator<AnalyticsQueryFilterForType['Endusers']>({
|
|
2736
2803
|
activeSince: dateOptionalOrEmptyStringValidator,
|
|
2804
|
+
"Submitted Forms": objectValidator<AnalyticsQueryFilterForType['Endusers']['Submitted Forms']>({
|
|
2805
|
+
qualifier: listQueryQualifiersValidator,
|
|
2806
|
+
formIds: listOfMongoIdStringValidator,
|
|
2807
|
+
}, { isOptional: true })
|
|
2737
2808
|
}, { isOptional: true, emptyOk: true }),
|
|
2738
2809
|
info: orValidator<{ [K in keyof AnalyticsQueryInfoForType['Endusers']]: AnalyticsQueryInfoForType['Endusers'][K] }>({
|
|
2739
2810
|
"Total": objectValidator<AnalyticsQueryInfoForType['Endusers']['Total']>({
|
|
@@ -2744,12 +2815,6 @@ export const analyticsQueryValidator = orValidator<{ [K in AnalyticsQueryType]:
|
|
|
2744
2815
|
method: exactMatchValidator<"Percentage">(['Percentage']),
|
|
2745
2816
|
parameters: optionalEmptyObjectValidator,
|
|
2746
2817
|
}),
|
|
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
2818
|
})
|
|
2754
2819
|
}),
|
|
2755
2820
|
"Calendar Events": objectValidator<AnalyticsQueryForType['Calendar Events']>({
|