@tellescope/validation 1.3.13 → 1.3.19

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
@@ -115,6 +115,13 @@ import {
115
115
  FormResponseAnswerDate,
116
116
  FormResponseAnswerRanking,
117
117
  FormFieldOptions,
118
+ BlockType,
119
+ Block,
120
+ BlockContentH1,
121
+ BlockContentHTML,
122
+ BlockContentImage,
123
+ BlockContentYoutube,
124
+ BlockContentH2,
118
125
  } from "@tellescope/types-models"
119
126
  import {
120
127
  UserDisplayInfo,
@@ -323,6 +330,10 @@ export const filterCommandsValidator: EscapeBuilder<FilterType> = (o={}) => buil
323
330
  if (!is_object(value)) { throw new Error("Expecting object value for FilterType") }
324
331
 
325
332
  if (value._exists && typeof value._exists === 'boolean' ) return { _exists: value._exists }
333
+ if (value._gt && typeof value._gt === 'number' ) return { _gt: value._gt }
334
+ if (value._gte && typeof value._gte === 'number' ) return { _gte: value._gte }
335
+ if (value._lt && typeof value._lt === 'number' ) return { _lt: value._lt }
336
+ if (value._lte && typeof value._gt === 'number' ) return { _gt: value._gt }
326
337
 
327
338
  if (Object.keys(value).find(k => k.startsWith('$'))) { // ignore any $ injections
328
339
  throw new Error(`Unknown filter value ${JSON.stringify(value)}`)
@@ -1202,7 +1213,7 @@ export const chatAttachmentValidator = objectValidator<ChatAttachment>({
1202
1213
  type: exactMatchValidator<ChatAttachmentType>(['image', 'video', 'file'])(),
1203
1214
  secureName: stringValidator250(),
1204
1215
  })
1205
- export const listOfChatAttachmentsValidator = listValidator(chatAttachmentValidator())
1216
+ export const listOfChatAttachmentsValidator = listValidatorEmptyOk(chatAttachmentValidator())
1206
1217
 
1207
1218
  export const meetingsListValidator = listValidator(objectValidator<{
1208
1219
  id: string,
@@ -1411,6 +1422,7 @@ export const automationActionValidator = orValidator<{ [K in AutomationActionTyp
1411
1422
  export const relatedRecordValidator = objectValidator<RelatedRecord>({
1412
1423
  type: stringValidator100(),
1413
1424
  id: mongoIdStringValidator(),
1425
+ creator: mongoIdStringOptional,
1414
1426
  })
1415
1427
  export const listOfRelatedRecordsValidator = listValidatorEmptyOk(relatedRecordValidator())
1416
1428
 
@@ -1468,6 +1480,8 @@ export const organizationThemeValidator = objectValidator<OrganizationTheme>({
1468
1480
  name: stringValidator250(),
1469
1481
  subdomain: stringValidator250(),
1470
1482
  businessId: mongoIdRequired,
1483
+ faviconURL: stringValidator250(),
1484
+ customPortalURL: stringValidator250(),
1471
1485
  })
1472
1486
 
1473
1487
  const _MANAGED_CONTENT_RECORD_TYPES: { [K in ManagedContentRecordType]: any } = {
@@ -1528,4 +1542,54 @@ export const formFieldOptionsValidator = objectValidator<FormFieldOptions>({
1528
1542
  to: numberValidator({ isOptional: true }),
1529
1543
  other: stringValidator250({ isOptional: true }),
1530
1544
  radio: booleanValidator({ isOptional: true }),
1531
- })
1545
+ })
1546
+
1547
+ export const blockValidator = orValidator<{ [K in BlockType]: Block & { type: K } } >({
1548
+ h1: objectValidator<BlockContentH1>({
1549
+ type: exactMatchValidator(['h1'])(),
1550
+ info: objectValidator<BlockContentH1['info']>({
1551
+ text: stringValidator5000({ emptyStringOk: true }),
1552
+ })(),
1553
+ })(),
1554
+ h2: objectValidator<BlockContentH2>({
1555
+ type: exactMatchValidator(['h2'])(),
1556
+ info: objectValidator<BlockContentH1['info']>({
1557
+ text: stringValidator5000({ emptyStringOk: true }),
1558
+ })(),
1559
+ })(),
1560
+ html: objectValidator<BlockContentHTML>({
1561
+ type: exactMatchValidator(['html'])(),
1562
+ info: objectValidator<BlockContentHTML['info']>({
1563
+ html: stringValidator25000({ emptyStringOk: true }),
1564
+ })(),
1565
+ })(),
1566
+ image: objectValidator<BlockContentImage>({
1567
+ type: exactMatchValidator(['image'])(),
1568
+ info: objectValidator<BlockContentImage['info']>({
1569
+ link: stringValidator5000({ emptyStringOk: true }),
1570
+ height: nonNegNumberValidator({ isOptional: true }),
1571
+ width: nonNegNumberValidator({ isOptional: true }),
1572
+ })(),
1573
+ })(),
1574
+ youtube: objectValidator<BlockContentYoutube>({
1575
+ type: exactMatchValidator(['youtube'])(),
1576
+ info: objectValidator<BlockContentYoutube['info']>({
1577
+ link: stringValidator5000({ emptyStringOk: true }),
1578
+ height: nonNegNumberValidator({ isOptional: true }),
1579
+ width: nonNegNumberValidator({ isOptional: true }),
1580
+ })(),
1581
+ })(),
1582
+ })
1583
+
1584
+ const _BLOCK_TYPES: { [K in BlockType]: any } = {
1585
+ h1: '',
1586
+ h2: '',
1587
+ html: '',
1588
+ image: '',
1589
+ youtube: '',
1590
+ }
1591
+ export const BLOCK_TYPES = Object.keys(_BLOCK_TYPES) as BlockType[]
1592
+ export const blockTypeValidator = exactMatchValidator<BlockType>(BLOCK_TYPES)
1593
+ export const is_block_type = (type: any): type is BlockType => BLOCK_TYPES.includes(type)
1594
+
1595
+ export const blocksValidator = listValidatorEmptyOk(blockValidator())