@tellescope/validation 1.3.10 → 1.3.13

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
@@ -111,6 +111,10 @@ import {
111
111
  PreviousFormFieldEqualsInfo,
112
112
  IntegrationAuthentication,
113
113
  OAuth2AuthenticationFields,
114
+ FormResponseAnswerRating,
115
+ FormResponseAnswerDate,
116
+ FormResponseAnswerRanking,
117
+ FormFieldOptions,
114
118
  } from "@tellescope/types-models"
115
119
  import {
116
120
  UserDisplayInfo,
@@ -743,6 +747,9 @@ const _FORM_FIELD_TYPES: { [K in FormFieldType]: any } = {
743
747
  phone: '',
744
748
  signature: '',
745
749
  string: '',
750
+ ranking: '',
751
+ rating: '',
752
+ date: '',
746
753
  }
747
754
  export const FORM_FIELD_TYPES = Object.keys(_FORM_FIELD_TYPES) as FormFieldType[]
748
755
  export const formFieldTypeValidator = exactMatchValidator<FormFieldType>(FORM_FIELD_TYPES)
@@ -1013,40 +1020,53 @@ const isFormField = (f: JSONType, fieldOptions={ forUpdate: false }) => {
1013
1020
  return field
1014
1021
  }
1015
1022
 
1023
+ // validate optional vs not at endpoint-level
1016
1024
  export const formResponseAnswerValidator = orValidator<{ [K in FormFieldType]: FormResponseValueAnswer & { type: K } } >({
1017
1025
  email: objectValidator<FormResponseAnswerEmail>({
1018
1026
  type: exactMatchValidator(['email'])(),
1019
- value: emailValidator(),
1027
+ value: emailValidator({ isOptional: true, emptyStringOk: true }),
1020
1028
  })(),
1021
1029
  number: objectValidator<FormResponseAnswerNumber>({
1022
1030
  type: exactMatchValidator(['number'])(),
1023
- value: numberValidator(),
1031
+ value: numberValidator({ isOptional: true, emptyStringOk: true }),
1032
+ })(),
1033
+ rating: objectValidator<FormResponseAnswerRating>({
1034
+ type: exactMatchValidator(['rating'])(),
1035
+ value: numberValidator({ isOptional: true, emptyStringOk: true }),
1024
1036
  })(),
1025
1037
  phone: objectValidator<FormResponseAnswerPhone>({
1026
1038
  type: exactMatchValidator(['phone'])(),
1027
- value: phoneValidator(),
1039
+ value: phoneValidator({ isOptional: true, emptyStringOk: true }),
1028
1040
  })(),
1029
1041
  string: objectValidator<FormResponseAnswerString>({
1030
1042
  type: exactMatchValidator(['string'])(),
1031
- value: stringValidator5000(),
1043
+ value: stringValidator5000({ isOptional: true, emptyStringOk: true }),
1044
+ })(),
1045
+ date: objectValidator<FormResponseAnswerDate>({
1046
+ type: exactMatchValidator(['date'])(),
1047
+ value: dateValidator({ isOptional: true, emptyStringOk: true }),
1032
1048
  })(),
1033
1049
  file: objectValidator<FormResponseAnswerFile>({
1034
1050
  type: exactMatchValidator(['file'])(),
1035
1051
  value: objectValidator<FormResponseAnswerFileValue>({
1036
1052
  name: stringValidator5000(),
1037
1053
  secureName: stringValidator250(),
1038
- }, { emptyOk: false })(),
1054
+ }, { emptyOk: false })({ isOptional: true }),
1039
1055
  })(),
1040
1056
  multiple_choice: objectValidator<FormResponseAnswerMultipleChoice>({
1041
1057
  type: exactMatchValidator(['multiple_choice'])(),
1042
- value: listOfStringsValidator(),
1058
+ value: listOfStringsValidator({ isOptional: true, emptyListOk: true }),
1059
+ })(),
1060
+ ranking: objectValidator<FormResponseAnswerRanking>({
1061
+ type: exactMatchValidator(['ranking'])(),
1062
+ value: listOfStringsValidator({ isOptional: true, emptyListOk: true }),
1043
1063
  })(),
1044
1064
  signature: objectValidator<FormResponseAnswerSignature>({
1045
1065
  type: exactMatchValidator(['signature'])(),
1046
1066
  value: objectValidator<FormResponseAnswerSignatureValue>({
1047
1067
  fullName: stringValidator250(),
1048
1068
  signed: booleanValidator(),
1049
- }, { emptyOk: false })(),
1069
+ }, { emptyOk: false })({ isOptional: true }),
1050
1070
  })(),
1051
1071
  })
1052
1072
 
@@ -1486,6 +1506,8 @@ export const flowchartUIValidator = objectValidator<FlowchartUI>({
1486
1506
  y: numberValidator(),
1487
1507
  }, { emptyOk: true })
1488
1508
 
1509
+
1510
+
1489
1511
  export const integrationAuthenticationsValidator = objectValidator<IntegrationAuthentication>({
1490
1512
  type: exactMatchValidator(['oauth2'])(),
1491
1513
  info: objectValidator<OAuth2AuthenticationFields>({
@@ -1495,5 +1517,15 @@ export const integrationAuthenticationsValidator = objectValidator<IntegrationAu
1495
1517
  expiry_date: nonNegNumberValidator(),
1496
1518
  token_type: exactMatchValidator<'Bearer'>(['Bearer'])(),
1497
1519
  state: stringValidator250({ isOptional: true }),
1520
+ email: emailValidator({ isOptional: true }),
1498
1521
  })(),
1522
+ })
1523
+
1524
+
1525
+ export const formFieldOptionsValidator = objectValidator<FormFieldOptions>({
1526
+ choices: listOfStringsValidator({ isOptional: true }),
1527
+ from: numberValidator({ isOptional: true }),
1528
+ to: numberValidator({ isOptional: true }),
1529
+ other: stringValidator250({ isOptional: true }),
1530
+ radio: booleanValidator({ isOptional: true }),
1499
1531
  })