@tellescope/validation 1.224.0 → 1.226.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
@@ -121,6 +121,7 @@ import {
121
121
  StateCredentialInfo,
122
122
  BaseAvailabilityBlock,
123
123
  WeeklyAvailability,
124
+ MonthlyRestriction,
124
125
  Timezone,
125
126
  TIMEZONE_MAP,
126
127
  FormType,
@@ -330,6 +331,8 @@ import {
330
331
  AIDecisionAutomationAction,
331
332
  AssignInboxItemAutomationAction,
332
333
  OnAIDecisionAutomationEvent,
334
+ OnErrorEventInfo,
335
+ OnErrorAutomationEvent,
333
336
  AIContextSource,
334
337
  } from "@tellescope/types-models"
335
338
  import {
@@ -1263,6 +1266,11 @@ export const numberValidator = numberValidatorBuilder({ lower: -10000000000000,
1263
1266
  export const numberValidatorOptional = numberValidatorBuilder({ lower: -10000000000000, upper: 10000000000000, isOptional: true, emptyStringOk: true }) // max is 2286 in UTC MS
1264
1267
  export const listOfNumbersValidatorUniqueOptionalOrEmptyOkay = listValidatorUniqueOptionalEmptyOkay(numberValidator, { isNumber: true })
1265
1268
 
1269
+ // Day of month and time validators for automation events
1270
+ export const numberValidatorMin1Max31 = numberValidatorBuilder({ lower: 1, upper: 31 })
1271
+ export const numberValidatorMin0Max23Optional = numberValidatorBuilder({ lower: 0, upper: 23, isOptional: true })
1272
+ export const numberValidatorMin0Max59Optional = numberValidatorBuilder({ lower: 0, upper: 59, isOptional: true })
1273
+
1266
1274
  export const fileSizeValidator = numberValidatorBuilder({ lower: 0, upper: MAX_FILE_SIZE })
1267
1275
 
1268
1276
  export const numberOrStringValidatorEmptyOkay = orValidator({
@@ -2447,6 +2455,7 @@ const _AUTOMATION_EVENTS: { [K in AutomationEventType]: any } = {
2447
2455
  waitForTrigger: '',
2448
2456
  onCallOutcome: '',
2449
2457
  onAIDecision: '',
2458
+ onError: '',
2450
2459
  }
2451
2460
  export const AUTOMATION_EVENTS = Object.keys(_AUTOMATION_EVENTS) as AutomationEventType[]
2452
2461
  export const automationEventTypeValidator = exactMatchValidator<AutomationEventType>(AUTOMATION_EVENTS)
@@ -2652,6 +2661,11 @@ export const automationEventValidator = orValidator<{ [K in AutomationEventType]
2652
2661
  eventCondition: objectValidator<AfterActionAutomationEvent['info']['eventCondition']>({
2653
2662
  before: booleanValidatorOptional,
2654
2663
  }, { isOptional: true, emptyOk: true }),
2664
+ dayOfMonthCondition: objectValidator<AfterActionAutomationEvent['info']['dayOfMonthCondition']>({
2665
+ dayOfMonth: numberValidatorMin1Max31,
2666
+ hour: numberValidatorMin0Max23Optional,
2667
+ minute: numberValidatorMin0Max59Optional,
2668
+ }, { isOptional: true, emptyOk: true }),
2655
2669
  skipIfDelayPassed: booleanValidatorOptional,
2656
2670
  }, { emptyOk: false }),
2657
2671
  }),
@@ -2696,11 +2710,17 @@ export const automationEventValidator = orValidator<{ [K in AutomationEventType]
2696
2710
  }),
2697
2711
  onAIDecision: objectValidator<OnAIDecisionAutomationEvent>({
2698
2712
  type: exactMatchValidator(['onAIDecision']),
2699
- info: objectValidator<OnAIDecisionAutomationEvent['info']>({
2700
- automationStepId: mongoIdStringRequired,
2713
+ info: objectValidator<OnAIDecisionAutomationEvent['info']>({
2714
+ automationStepId: mongoIdStringRequired,
2701
2715
  outcomes: listOfStringsValidator,
2702
2716
  }, { emptyOk: false }),
2703
2717
  }),
2718
+ onError: objectValidator<OnErrorAutomationEvent>({
2719
+ type: exactMatchValidator(['onError']),
2720
+ info: objectValidator<OnErrorEventInfo>({
2721
+ automationStepId: mongoIdStringRequired,
2722
+ }, { emptyOk: false }),
2723
+ }),
2704
2724
  })
2705
2725
  export const automationEventsValidator = listValidatorEmptyOk(automationEventValidator)
2706
2726
 
@@ -3279,9 +3299,10 @@ export const automationActionValidator = orValidator<{ [K in AutomationActionTyp
3279
3299
  stripeChargeCardOnFile: objectValidator<StripeChargeCardOnFileAutomationAction>({
3280
3300
  ...sharedAutomationActionValidators,
3281
3301
  type: exactMatchValidator(['stripeChargeCardOnFile']),
3282
- info: objectValidator<StripeChargeCardOnFileAutomationAction['info']>({
3302
+ info: objectValidator<StripeChargeCardOnFileAutomationAction['info']>({
3283
3303
  stripeKey: stringValidatorOptionalEmptyOkay,
3284
3304
  priceIds: listOfStringsValidatorEmptyOk,
3305
+ productIds: listOfStringsValidatorOptionalOrEmptyOk,
3285
3306
  subscriptionPriceId: stringValidatorOptionalEmptyOkay,
3286
3307
  }, { emptyOk: false }) // at least tags is required
3287
3308
  }),
@@ -3330,6 +3351,8 @@ export const journeyContextValidator = objectValidator<JourneyContext>({
3330
3351
  fileId: mongoIdStringOptional,
3331
3352
  chatRoomId: mongoIdStringOptional,
3332
3353
  twilioNumber: stringValidatorOptionalEmptyOkay,
3354
+ ticketThreadId: mongoIdStringOptional,
3355
+ ticketThreadCommentId: mongoIdStringOptional,
3333
3356
  })
3334
3357
 
3335
3358
  export const relatedRecordValidator = objectValidator<RelatedRecord>({
@@ -3583,6 +3606,7 @@ export const formFieldOptionsValidator = objectValidator<FormFieldOptions>({
3583
3606
  })),
3584
3607
  validFileTypes: listOfStringsValidatorOptionalOrEmptyOk,
3585
3608
  maxFileSize: numberValidatorOptional,
3609
+ hideFromPortal: booleanValidatorOptional,
3586
3610
  productIds: listOfStringsValidatorOptionalOrEmptyOk,
3587
3611
  chargeImmediately: booleanValidatorOptional,
3588
3612
  signatureUrl: stringValidator5000Optional,
@@ -3656,74 +3680,95 @@ export const formFieldOptionsValidator = objectValidator<FormFieldOptions>({
3656
3680
  allowAddToDatabase: booleanValidatorOptional,
3657
3681
  })
3658
3682
 
3683
+ export const blockStyleValidator = objectValidator({
3684
+ width: numberValidatorOptional,
3685
+ height: numberValidatorOptional,
3686
+ backgroundColor: stringValidatorOptional,
3687
+ borderColor: stringValidatorOptional,
3688
+ borderWidth: numberValidatorOptional,
3689
+ textColor: stringValidatorOptional,
3690
+ }, { isOptional: true, emptyOk: true })
3691
+
3659
3692
  export const blockValidator = orValidator<{ [K in BlockType]: Block & { type: K } } >({
3660
3693
  h1: objectValidator<BlockContentH1>({
3661
3694
  type: exactMatchValidator(['h1']),
3662
3695
  info: objectValidator<BlockContentH1['info']>({
3663
3696
  text: stringValidator5000EmptyOkay,
3664
3697
  }),
3698
+ style: blockStyleValidator,
3665
3699
  }),
3666
3700
  h2: objectValidator<BlockContentH2>({
3667
3701
  type: exactMatchValidator(['h2']),
3668
3702
  info: objectValidator<BlockContentH1['info']>({
3669
3703
  text: stringValidator5000EmptyOkay,
3670
3704
  }),
3705
+ style: blockStyleValidator,
3671
3706
  }),
3672
3707
  html: objectValidator<BlockContentHTML>({
3673
3708
  type: exactMatchValidator(['html']),
3674
3709
  info: objectValidator<BlockContentHTML['info']>({
3675
3710
  html: stringValidator25000EmptyOkay,
3676
3711
  }),
3712
+ style: blockStyleValidator,
3677
3713
  }),
3678
3714
  image: objectValidator<BlockContentImage>({
3679
3715
  type: exactMatchValidator(['image']),
3680
3716
  info: objectValidator<BlockContentImage['info']>({
3681
3717
  link: stringValidator5000EmptyOkay,
3682
3718
  name: stringValidatorOptional,
3719
+ alt: stringValidatorOptional,
3683
3720
  height: numberValidatorOptional,
3684
3721
  maxHeight: numberValidatorOptional,
3685
3722
  width: numberValidatorOptional,
3686
3723
  maxWidth: numberValidatorOptional,
3687
3724
  }),
3725
+ style: blockStyleValidator,
3688
3726
  }),
3689
3727
  pdf: objectValidator<BlockContentPDF>({
3690
3728
  type: exactMatchValidator(['pdf']),
3691
3729
  info: objectValidator<BlockContentPDF['info']>({
3692
3730
  link: stringValidator5000EmptyOkay,
3693
3731
  name: stringValidatorOptional,
3732
+ alt: stringValidatorOptional,
3694
3733
  height: numberValidatorOptional,
3695
3734
  maxHeight: numberValidatorOptional,
3696
3735
  width: numberValidatorOptional,
3697
3736
  maxWidth: numberValidatorOptional,
3698
3737
  }),
3738
+ style: blockStyleValidator,
3699
3739
  }),
3700
3740
  youtube: objectValidator<BlockContentYoutube>({
3701
3741
  type: exactMatchValidator(['youtube']),
3702
3742
  info: objectValidator<BlockContentYoutube['info']>({
3703
3743
  link: stringValidator5000EmptyOkay,
3704
3744
  name: stringValidatorOptional,
3745
+ alt: stringValidatorOptional,
3705
3746
  height: numberValidatorOptional,
3706
3747
  maxHeight: numberValidatorOptional,
3707
3748
  width: numberValidatorOptional,
3708
3749
  maxWidth: numberValidatorOptional,
3709
3750
  }),
3751
+ style: blockStyleValidator,
3710
3752
  }),
3711
3753
  iframe: objectValidator<BlockContentIFrame>({
3712
3754
  type: exactMatchValidator(['iframe']),
3713
3755
  info: objectValidator<BlockContentIFrame['info']>({
3714
3756
  link: stringValidator5000EmptyOkay,
3715
3757
  name: stringValidatorOptional,
3758
+ alt: stringValidatorOptional,
3716
3759
  height: numberValidatorOptional,
3717
3760
  maxHeight: numberValidatorOptional,
3718
3761
  width: numberValidatorOptional,
3719
3762
  maxWidth: numberValidatorOptional,
3720
3763
  }),
3764
+ style: blockStyleValidator,
3721
3765
  }),
3722
3766
  "content-link": objectValidator<BlockContentLink>({
3723
3767
  type: exactMatchValidator(["content-link"]),
3724
3768
  info: objectValidator<BlockContentLink['info']>({
3725
3769
  recordId: mongoIdStringRequired,
3726
3770
  }),
3771
+ style: blockStyleValidator,
3727
3772
  }),
3728
3773
  })
3729
3774
 
@@ -4027,6 +4072,13 @@ export const portalBlockValidator = orValidator<{ [K in PortalBlockType]: Portal
4027
4072
  info: objectValidator<PortalBlockForType['HTML']['info']>({
4028
4073
  html: stringValidator5000,
4029
4074
  })
4075
+ }),
4076
+ pinnedForms: objectValidator<PortalBlockForType['pinnedForms']>({
4077
+ type: exactMatchValidator(['pinnedForms']),
4078
+ info: objectValidator<PortalBlockForType['pinnedForms']['info']>({
4079
+ title: stringValidatorOptional,
4080
+ formIds: listOfMongoIdStringValidatorEmptyOk,
4081
+ })
4030
4082
  }),
4031
4083
  })
4032
4084
  export const portalBlocksValidator = listValidatorEmptyOk(portalBlockValidator)
@@ -4041,6 +4093,7 @@ const _PORTAL_BLOCK_TYPES: { [K in PortalBlockType]: any } = {
4041
4093
  "Manage Subscription Button": '',
4042
4094
  Orders: '',
4043
4095
  HTML: '',
4096
+ pinnedForms: '',
4044
4097
  }
4045
4098
  export const PORTAL_BLOCK_TYPES = Object.keys(_PORTAL_BLOCK_TYPES) as PortalBlockType[]
4046
4099
  export const portalTypeValidator = exactMatchValidator<PortalBlockType>(PORTAL_BLOCK_TYPES)
@@ -4079,6 +4132,27 @@ export const baseAvailabilityBlockValidator = objectValidator<BaseAvailabilityBl
4079
4132
  })
4080
4133
  export const baseAvailabilityBlocksValidator = listValidatorEmptyOk(baseAvailabilityBlockValidator)
4081
4134
 
4135
+ const monthlyOccurrenceValidator: ValidatorDefinition<1 | 2 | 3 | 4 | 5> = {
4136
+ validate: (o={}) => build_validator(
4137
+ (value: JSONType) => {
4138
+ if (![1, 2, 3, 4, 5].includes(value as number)) {
4139
+ throw new Error(`Value must be one of 1, 2, 3, 4, 5`)
4140
+ }
4141
+ return value as 1 | 2 | 3 | 4 | 5
4142
+ },
4143
+ { ...o, listOf: false }
4144
+ ),
4145
+ getExample: () => 1,
4146
+ getType: getTypeString,
4147
+ }
4148
+
4149
+ export const monthlyRestrictionValidator = objectValidator<MonthlyRestriction>({
4150
+ occurrences: listValidator(monthlyOccurrenceValidator),
4151
+ })
4152
+ export const monthlyRestrictionOptionalValidator = objectValidator<MonthlyRestriction>({
4153
+ occurrences: listValidator(monthlyOccurrenceValidator),
4154
+ }, { isOptional: true, emptyOk: true })
4155
+
4082
4156
  export const weeklyAvailabilityValidator = objectValidator<WeeklyAvailability>({
4083
4157
  dayOfWeekStartingSundayIndexedByZero: nonNegNumberValidator,
4084
4158
  endTimeInMinutes: nonNegNumberValidator,
@@ -4090,6 +4164,7 @@ export const weeklyAvailabilityValidator = objectValidator<WeeklyAvailability>({
4090
4164
  intervalInMinutes: numberValidatorOptional,
4091
4165
  priority: numberValidatorOptional,
4092
4166
  bufferStartMinutes: numberValidatorOptional,
4167
+ monthlyRestriction: monthlyRestrictionOptionalValidator,
4093
4168
  })
4094
4169
  export const weeklyAvailabilitiesValidator = listValidatorEmptyOk(weeklyAvailabilityValidator)
4095
4170
 
@@ -4140,6 +4215,7 @@ export const customEnduserFieldValidator = orValidator<{ [K in CustomEnduserFiel
4140
4215
  required: booleanValidatorOptional,
4141
4216
  hiddenFromProfile: booleanValidatorOptional,
4142
4217
  requireConfirmation: booleanValidatorOptional,
4218
+ tags: listOfStringsValidatorOptionalOrEmptyOk,
4143
4219
  }),
4144
4220
  "Multiple Select": objectValidator<CustomEnduserFields['Multiple Select']>({
4145
4221
  type: exactMatchValidator(['Multiple Select']),
@@ -4150,6 +4226,7 @@ export const customEnduserFieldValidator = orValidator<{ [K in CustomEnduserFiel
4150
4226
  required: booleanValidatorOptional,
4151
4227
  hiddenFromProfile: booleanValidatorOptional,
4152
4228
  requireConfirmation: booleanValidatorOptional,
4229
+ tags: listOfStringsValidatorOptionalOrEmptyOk,
4153
4230
  }),
4154
4231
  Text: objectValidator<CustomEnduserFields['Text']>({
4155
4232
  type: exactMatchValidator(['Text']),
@@ -4158,6 +4235,7 @@ export const customEnduserFieldValidator = orValidator<{ [K in CustomEnduserFiel
4158
4235
  required: booleanValidatorOptional,
4159
4236
  hiddenFromProfile: booleanValidatorOptional,
4160
4237
  requireConfirmation: booleanValidatorOptional,
4238
+ tags: listOfStringsValidatorOptionalOrEmptyOk,
4161
4239
  }),
4162
4240
  Number: objectValidator<CustomEnduserFields['Number']>({
4163
4241
  type: exactMatchValidator(['Number']),
@@ -4166,6 +4244,7 @@ export const customEnduserFieldValidator = orValidator<{ [K in CustomEnduserFiel
4166
4244
  required: booleanValidatorOptional,
4167
4245
  hiddenFromProfile: booleanValidatorOptional,
4168
4246
  requireConfirmation: booleanValidatorOptional,
4247
+ tags: listOfStringsValidatorOptionalOrEmptyOk,
4169
4248
  }),
4170
4249
  File: objectValidator<CustomEnduserFields['File']>({
4171
4250
  type: exactMatchValidator(['File']),
@@ -4174,6 +4253,7 @@ export const customEnduserFieldValidator = orValidator<{ [K in CustomEnduserFiel
4174
4253
  required: booleanValidatorOptional,
4175
4254
  hiddenFromProfile: booleanValidatorOptional,
4176
4255
  requireConfirmation: booleanValidatorOptional,
4256
+ tags: listOfStringsValidatorOptionalOrEmptyOk,
4177
4257
  }),
4178
4258
  "Multiple Text": objectValidator<CustomEnduserFields["Multiple Text"]>({
4179
4259
  type: exactMatchValidator(["Multiple Text"]),
@@ -4182,6 +4262,7 @@ export const customEnduserFieldValidator = orValidator<{ [K in CustomEnduserFiel
4182
4262
  required: booleanValidatorOptional,
4183
4263
  hiddenFromProfile: booleanValidatorOptional,
4184
4264
  requireConfirmation: booleanValidatorOptional,
4265
+ tags: listOfStringsValidatorOptionalOrEmptyOk,
4185
4266
  }),
4186
4267
  Date: objectValidator<CustomEnduserFields['Date']>({
4187
4268
  type: exactMatchValidator(['Date']),
@@ -4190,6 +4271,7 @@ export const customEnduserFieldValidator = orValidator<{ [K in CustomEnduserFiel
4190
4271
  required: booleanValidatorOptional,
4191
4272
  hiddenFromProfile: booleanValidatorOptional,
4192
4273
  requireConfirmation: booleanValidatorOptional,
4274
+ tags: listOfStringsValidatorOptionalOrEmptyOk,
4193
4275
  }),
4194
4276
  "Auto Detect": objectValidator<CustomEnduserFields["Auto Detect"]>({
4195
4277
  type: exactMatchValidator(["Auto Detect"]),
@@ -4198,6 +4280,7 @@ export const customEnduserFieldValidator = orValidator<{ [K in CustomEnduserFiel
4198
4280
  required: booleanValidatorOptional,
4199
4281
  hiddenFromProfile: booleanValidatorOptional,
4200
4282
  requireConfirmation: booleanValidatorOptional,
4283
+ tags: listOfStringsValidatorOptionalOrEmptyOk,
4201
4284
  }),
4202
4285
  "Table": objectValidator<CustomEnduserFields["Table"]>({
4203
4286
  type: exactMatchValidator(["Table"]),
@@ -4208,6 +4291,7 @@ export const customEnduserFieldValidator = orValidator<{ [K in CustomEnduserFiel
4208
4291
  required: booleanValidatorOptional,
4209
4292
  hiddenFromProfile: booleanValidatorOptional,
4210
4293
  requireConfirmation: booleanValidatorOptional,
4294
+ tags: listOfStringsValidatorOptionalOrEmptyOk,
4211
4295
  }),
4212
4296
  "Checkbox": objectValidator<CustomEnduserFields["Checkbox"]>({
4213
4297
  type: exactMatchValidator(["Checkbox"]),
@@ -4216,6 +4300,7 @@ export const customEnduserFieldValidator = orValidator<{ [K in CustomEnduserFiel
4216
4300
  required: booleanValidatorOptional,
4217
4301
  hiddenFromProfile: booleanValidatorOptional,
4218
4302
  requireConfirmation: booleanValidatorOptional,
4303
+ tags: listOfStringsValidatorOptionalOrEmptyOk,
4219
4304
  }),
4220
4305
  "Database Select": objectValidator<CustomEnduserFields["Database Select"]>({
4221
4306
  type: exactMatchValidator(["Database Select"]),
@@ -4227,6 +4312,7 @@ export const customEnduserFieldValidator = orValidator<{ [K in CustomEnduserFiel
4227
4312
  required: booleanValidatorOptional,
4228
4313
  hiddenFromProfile: booleanValidatorOptional,
4229
4314
  requireConfirmation: booleanValidatorOptional,
4315
+ tags: listOfStringsValidatorOptionalOrEmptyOk,
4230
4316
  }),
4231
4317
  })
4232
4318
  export const customEnduserFieldsValidatorOptionalOrEmpty = listValidatorOptionalOrEmptyOk(customEnduserFieldValidator)
@@ -4570,6 +4656,7 @@ export const automationTriggerEventValidator = orValidator<{ [K in AutomationTri
4570
4656
  type: exactMatchValidator(['Appointment Rescheduled']),
4571
4657
  info: objectValidator<AutomationTriggerEvents['Appointment Rescheduled']['info']>({
4572
4658
  titles: listOfStringsValidatorOptionalOrEmptyOk,
4659
+ detectManualReschedules: booleanValidatorOptional,
4573
4660
  }),
4574
4661
  conditions: optionalEmptyObjectValidator,
4575
4662
  }),
@@ -4758,6 +4845,7 @@ const _AUTOMATION_TRIGGER_ACTION_TYPES: { [K in AutomationTriggerActionType]: an
4758
4845
  "Reply to Chat": true,
4759
4846
  "Create User Notifications": true,
4760
4847
  "Assign to Incoming Message": true,
4848
+ "Zendesk: Update Ticket Assignee": true,
4761
4849
  }
4762
4850
  export const AUTOMATION_TRIGGER_ACTION_TYPES = Object.keys(_AUTOMATION_TRIGGER_ACTION_TYPES) as AutomationTriggerActionType[]
4763
4851
 
@@ -4880,6 +4968,11 @@ export const automationTriggerActionValidator = orValidator<{ [K in AutomationTr
4880
4968
  maxUsers: numberValidatorOptional,
4881
4969
  }),
4882
4970
  }),
4971
+ "Zendesk: Update Ticket Assignee": objectValidator<AutomationTriggerActions["Zendesk: Update Ticket Assignee"]>({
4972
+ type: exactMatchValidator(['Zendesk: Update Ticket Assignee']),
4973
+ info: objectValidator<AutomationTriggerActions['Zendesk: Update Ticket Assignee']['info']>({
4974
+ }),
4975
+ }),
4883
4976
  })
4884
4977
 
4885
4978
 
@@ -5367,6 +5460,7 @@ export const analyticsQueryValidator = orValidator<{ [K in AnalyticsQueryType]:
5367
5460
  State: booleanValidatorOptional,
5368
5461
  Phone: booleanValidatorOptional,
5369
5462
  "Scheduled By": booleanValidatorOptional,
5463
+ "Completed By": booleanValidatorOptional,
5370
5464
  alsoGroupByHost: booleanValidatorOptional,
5371
5465
  "Cancel Reason": booleanValidatorOptional,
5372
5466
  }, { isOptional: true, emptyOk: true }),