@tellescope/validation 1.6.1 → 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/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,
@@ -953,8 +960,8 @@ export const numberValidatorBuilder: ValidatorBuilder<number, { lower: number, u
953
960
  })
954
961
 
955
962
  export const nonNegNumberValidator = numberValidatorBuilder({ lower: 0, upper: 10000000000000 }) // max is 2286 in UTC MS
956
- export const numberValidator = numberValidatorBuilder({ lower: -100000000, upper: 10000000000000 }) // max is 2286 in UTC MS
957
- export const numberValidatorOptional = numberValidatorBuilder({ lower: -100000000, upper: 10000000000000, isOptional: true, emptyStringOk: true }) // max is 2286 in UTC MS
963
+ export const numberValidator = numberValidatorBuilder({ lower: -10000000000000, upper: 10000000000000 }) // max is 2286 in UTC MS
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
 
960
967
  export const numberOrStringValidatorOptional = orValidator({
@@ -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
@@ -2141,12 +2221,25 @@ export const integrationAuthenticationsValidator = objectValidator<IntegrationAu
2141
2221
  }),
2142
2222
  })
2143
2223
 
2224
+ const _TABLE_INPUT_TYPES: { [K in TableInputChoiceType]: any } = {
2225
+ Date: '',
2226
+ Text: '',
2227
+ Select: '',
2228
+ }
2229
+ export const TABLE_INPUT_TYPES = Object.keys(_TABLE_INPUT_TYPES) as TableInputChoiceType[]
2230
+ export const tableInputTypesValidator = exactMatchValidator<TableInputChoiceType>(TABLE_INPUT_TYPES)
2231
+
2144
2232
  export const tableInputChoiceValidator = orValidator<{ [K in TableInputChoiceType]: TableInputChoices[K] }>({
2145
2233
  Text: objectValidator<TableInputChoices['Text']>({
2146
2234
  type: exactMatchValidator<'Text'>(['Text']),
2147
2235
  label: stringValidator1000,
2148
2236
  info: optionalEmptyObjectValidator,
2149
2237
  }),
2238
+ Date: objectValidator<TableInputChoices['Date']>({
2239
+ type: exactMatchValidator<'Date'>(['Date']),
2240
+ label: stringValidator1000,
2241
+ info: optionalEmptyObjectValidator,
2242
+ }),
2150
2243
  Select: objectValidator<TableInputChoices['Select']>({
2151
2244
  type: exactMatchValidator<'Select'>(['Select']),
2152
2245
  label: stringValidator1000,
@@ -2384,67 +2477,6 @@ export const genericUnitWithQuantityValidator = objectValidator<GenericQuantityW
2384
2477
  unit: stringValidator1000,
2385
2478
  })
2386
2479
 
2387
- export const VALID_STATES: string[] = [
2388
- "AK",
2389
- "AL",
2390
- "AR",
2391
- "AS",
2392
- "AZ",
2393
- "CA",
2394
- "CO",
2395
- "CT",
2396
- "DC",
2397
- "DE",
2398
- "FL",
2399
- "GA",
2400
- "GU",
2401
- "HI",
2402
- "IA",
2403
- "ID",
2404
- "IL",
2405
- "IN",
2406
- "KS",
2407
- "KY",
2408
- "LA",
2409
- "MA",
2410
- "MD",
2411
- "ME",
2412
- "MI",
2413
- "MN",
2414
- "MO",
2415
- "MP",
2416
- "MS",
2417
- "MT",
2418
- "NC",
2419
- "ND",
2420
- "NE",
2421
- "NH",
2422
- "NJ",
2423
- "NM",
2424
- "NV",
2425
- "NY",
2426
- "OH",
2427
- "OK",
2428
- "OR",
2429
- "PA",
2430
- "PR",
2431
- "RI",
2432
- "SC",
2433
- "SD",
2434
- "TN",
2435
- "TX",
2436
- "UM",
2437
- "UT",
2438
- "VA",
2439
- "VI",
2440
- "VT",
2441
- "WA",
2442
- "WI",
2443
- "WV",
2444
- "WY",
2445
- ]
2446
- export const stateValidator = exactMatchValidator(VALID_STATES)
2447
-
2448
2480
  export const stateCredentialValidator = objectValidator<StateCredentialInfo>({
2449
2481
  expiresAt: dateValidatorOptional,
2450
2482
  state: stateValidator,
@@ -2530,6 +2562,44 @@ export const calendarEventPortalSettingsValidator = objectValidator<CalendarEven
2530
2562
  hideUsers: booleanValidatorOptional,
2531
2563
  })
2532
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
+
2533
2603
  // for each model name, this should be optional, but when a model name is provided, all CRUD fields should be required
2534
2604
  // if this changes (e.g. CRUD fields are made optional), must merge better in authentication.ts in API
2535
2605
  export const accessPermissionValidator = objectValidator<AccessForResource>({
@@ -2593,12 +2663,14 @@ export const accessPermissionsValidator = objectValidator<AccessPermissions>({
2593
2663
  phone_calls: accessPermissionValidator,
2594
2664
  background_errors: accessPermissionValidator,
2595
2665
  enduser_views: accessPermissionValidator,
2666
+ automation_triggers: accessPermissionValidator,
2596
2667
 
2597
2668
  // deprecated but for backwards compatibility
2598
2669
  apiKeys: accessPermissionValidator,
2599
2670
  })
2600
2671
 
2601
2672
  export const organizationLimitsValidator = objectValidator<OrganizationLimits>({
2673
+ automation_triggers: numberValidatorOptional,
2602
2674
  background_errors: numberValidatorOptional,
2603
2675
  enduser_views: numberValidatorOptional,
2604
2676
  availability_blocks: numberValidatorOptional,
@@ -2716,11 +2788,23 @@ export const integrationTitleValidator = exactMatchValidator<IntegrationsTitleTy
2716
2788
  OUTLOOK_INTEGRATIONS_TITLE,
2717
2789
  ])
2718
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
+
2719
2799
  export const analyticsQueryValidator = orValidator<{ [K in AnalyticsQueryType]: AnalyticsQueryForType[K] } >({
2720
2800
  Endusers: objectValidator<AnalyticsQueryForType['Endusers']>({
2721
2801
  resource: exactMatchValidator<'Endusers'>(['Endusers']),
2722
2802
  filter: objectValidator<AnalyticsQueryFilterForType['Endusers']>({
2723
2803
  activeSince: dateOptionalOrEmptyStringValidator,
2804
+ "Submitted Forms": objectValidator<AnalyticsQueryFilterForType['Endusers']['Submitted Forms']>({
2805
+ qualifier: listQueryQualifiersValidator,
2806
+ formIds: listOfMongoIdStringValidator,
2807
+ }, { isOptional: true })
2724
2808
  }, { isOptional: true, emptyOk: true }),
2725
2809
  info: orValidator<{ [K in keyof AnalyticsQueryInfoForType['Endusers']]: AnalyticsQueryInfoForType['Endusers'][K] }>({
2726
2810
  "Total": objectValidator<AnalyticsQueryInfoForType['Endusers']['Total']>({
@@ -2731,12 +2815,6 @@ export const analyticsQueryValidator = orValidator<{ [K in AnalyticsQueryType]:
2731
2815
  method: exactMatchValidator<"Percentage">(['Percentage']),
2732
2816
  parameters: optionalEmptyObjectValidator,
2733
2817
  }),
2734
- "Submitted Forms": objectValidator<AnalyticsQueryInfoForType['Endusers']['Submitted Forms']>({
2735
- method: exactMatchValidator<"Submitted Forms">(['Submitted Forms']),
2736
- parameters: objectValidator<AnalyticsQueryInfoForType['Endusers']['Submitted Forms']['parameters']>({
2737
- formIds: listOfMongoIdStringValidator,
2738
- }),
2739
- }),
2740
2818
  })
2741
2819
  }),
2742
2820
  "Calendar Events": objectValidator<AnalyticsQueryForType['Calendar Events']>({