@tellescope/validation 1.3.48 → 1.4.1

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.
@@ -9,13 +9,29 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { WEBHOOK_MODELS, } from "@tellescope/types-models";
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import { WEBHOOK_MODELS, TIMEZONES, } from "@tellescope/types-models";
13
24
  import v from 'validator';
14
25
  export var isDate = v.isDate, isEmail = v.isEmail, isMobilePhone = v.isMobilePhone, isMongoId = v.isMongoId, isMimeType = v.isMimeType, isURL = v.isURL;
15
26
  // import {
16
27
  // BUSINESS_TYPE,
17
28
  // } from "@tellescope/constants"
18
29
  import { filter_object, is_defined, is_object, is_whitespace, object_is_empty, to_object_id, } from "@tellescope/utilities";
30
+ var EXAMPLE_OBJECT_ID = '60398b0231a295e64f084fd9';
31
+ var getTypeString = function () { return "string"; };
32
+ var getTypeNumber = function () { return "number"; };
33
+ var getExampleString = function () { return 'example string'; };
34
+ var getExampleObjectId = function () { return EXAMPLE_OBJECT_ID; };
19
35
  export var MAX_FILE_SIZE = 25000000; // 25 megabytes in bytes
20
36
  var DEFAULT_MAX_LENGTH = 5000;
21
37
  export var build_validator = function (escapeFunction, options) {
@@ -100,10 +116,10 @@ export var build_validator = function (escapeFunction, options) {
100
116
  return listOf ? escapedValues : escapedValues[0];
101
117
  };
102
118
  };
103
- export var fieldsToValidation = function (fs) {
119
+ export var fieldsToValidationOld = function (fs) {
104
120
  var validation = {};
105
121
  for (var f in fs) {
106
- validation[f] = fs[f].validator({ isOptional: !fs[f].required });
122
+ validation[f] = fs[f].validator.validate({ isOptional: !fs[f].required });
107
123
  }
108
124
  return validation;
109
125
  };
@@ -135,21 +151,25 @@ export var binaryOrValidator = function (f1, f2) { return function (o) {
135
151
  }
136
152
  }, __assign(__assign({}, o), { listOf: false }));
137
153
  }; };
138
- export var orValidator = function (escapeFunctions) { return function (o) {
139
- if (o === void 0) { o = {}; }
140
- return build_validator(function (value) {
141
- for (var field in escapeFunctions) {
142
- var escape_1 = escapeFunctions[field];
143
- try {
144
- return escape_1(value);
145
- }
146
- catch (err) {
147
- continue;
154
+ export var orValidator = function (validators) { return ({
155
+ validate: function (o) {
156
+ if (o === void 0) { o = {}; }
157
+ return build_validator(function (value) {
158
+ for (var field in validators) {
159
+ var escape_1 = validators[field];
160
+ try {
161
+ return escape_1.validate()(value);
162
+ }
163
+ catch (err) {
164
+ continue;
165
+ }
148
166
  }
149
- }
150
- throw "Value does not match any of the expected options";
151
- }, __assign(__assign({}, o), { listOf: false }));
152
- }; };
167
+ throw "Value does not match any of the expected options";
168
+ }, __assign(__assign({}, o), { listOf: false }));
169
+ },
170
+ getExample: function () { return Object.values(validators)[0].getExample(); },
171
+ getType: function () { return [Object.values(validators).map(function (v) { return v.getType(); })]; }
172
+ }); };
153
173
  export var filterCommandsValidator = function (o) {
154
174
  if (o === void 0) { o = {}; }
155
175
  return build_validator(function (value) {
@@ -207,7 +227,7 @@ export var convertCommands = function (operators) {
207
227
  }
208
228
  return filterOperators;
209
229
  };
210
- export var objectValidator = function (i, objectOptions) {
230
+ export var objectValidatorOld = function (i, objectOptions) {
211
231
  if (objectOptions === void 0) { objectOptions = { emptyOk: true }; }
212
232
  return function (o) {
213
233
  if (o === void 0) { o = {}; }
@@ -244,70 +264,134 @@ export var objectValidator = function (i, objectOptions) {
244
264
  }, __assign(__assign({}, o), { isObject: true, listOf: false }));
245
265
  };
246
266
  };
267
+ export var listValidatorOld = function (b) { return function (o) { return build_validator(b, __assign(__assign({}, o), { listOf: true })); }; };
268
+ var exampleObject = function (fields) {
269
+ var examples = {};
270
+ for (var field in fields) {
271
+ examples[field] = fields[field].getExample();
272
+ }
273
+ return examples;
274
+ };
275
+ var typeObject = function (fields) {
276
+ var types = {};
277
+ for (var field in fields) {
278
+ types[field] = fields[field].getType();
279
+ }
280
+ return types;
281
+ };
282
+ export var objectValidator = function (i, objectOptions) {
283
+ if (objectOptions === void 0) { objectOptions = { emptyOk: true }; }
284
+ return ({
285
+ validate: function (o) {
286
+ if (o === void 0) { o = {}; }
287
+ return build_validator(function (object) {
288
+ var _a;
289
+ var emptyOk = (_a = objectOptions.emptyOk) !== null && _a !== void 0 ? _a : true;
290
+ var validated = {};
291
+ if (!is_object(object)) {
292
+ throw new Error("Expected a non-null object by got ".concat(object));
293
+ }
294
+ if (!emptyOk && object_is_empty(object)) {
295
+ throw new Error("Expected a non-empty object");
296
+ }
297
+ // don't throw on unrecognized fields, just ignore/don't validate them
298
+ if (objectOptions.throwOnUnrecognizedField) {
299
+ var unrecognizedFields = [];
300
+ for (var field in object) {
301
+ if (!i[field]) {
302
+ unrecognizedFields.push(field);
303
+ }
304
+ }
305
+ if (unrecognizedFields.length > 0) {
306
+ throw new Error("Got unexpected field(s) [".concat(unrecognizedFields.join(', '), "]"));
307
+ }
308
+ }
309
+ for (var field in i) {
310
+ var value = object[field];
311
+ var escaped = i[field].validate()(value); // may be required
312
+ if (escaped === undefined)
313
+ continue;
314
+ validated[field] = escaped;
315
+ }
316
+ return validated;
317
+ }, __assign(__assign({}, o), { isObject: true, listOf: false, isOptional: !!objectOptions.isOptional || o.isOptional }));
318
+ },
319
+ getExample: function () { return exampleObject(i); },
320
+ getType: function () { return typeObject(i); },
321
+ });
322
+ };
247
323
  export var listOfObjectsValidator = function (i, objectOptions) {
248
324
  if (objectOptions === void 0) { objectOptions = { emptyOk: true }; }
249
- return function (o) {
325
+ return ({
326
+ validate: function (o) {
327
+ if (o === void 0) { o = {}; }
328
+ return build_validator(function (object) {
329
+ var emptyOk = !!objectOptions.emptyOk || o.emptyListOk;
330
+ var validated = {};
331
+ if (!is_object(object)) {
332
+ throw new Error("Expected a non-null object by got ".concat(object));
333
+ }
334
+ if (!emptyOk && object_is_empty(object)) {
335
+ throw new Error("Expected a non-empty object");
336
+ }
337
+ // don't throw on unrecognized fields, just ignore/don't validate them
338
+ // const unrecognizedFields = []
339
+ // for (const field in object) {
340
+ // if (!(i as Indexable)[field]) {
341
+ // unrecognizedFields.push(field)
342
+ // }
343
+ // }
344
+ // if (unrecognizedFields.length > 0) {
345
+ // throw new Error(`Got unexpected field(s) [${unrecognizedFields.join(', ')}]`)
346
+ // }
347
+ for (var field in i) {
348
+ var value = object[field];
349
+ var escaped = i[field].validate()(value); // may be required
350
+ if (escaped === undefined)
351
+ continue;
352
+ validated[field] = escaped;
353
+ }
354
+ return validated;
355
+ }, __assign(__assign({}, o), { isObject: true, listOf: true, emptyListOk: !!objectOptions.emptyOk || o.emptyListOk }));
356
+ },
357
+ getExample: function () { return [exampleObject(i)]; },
358
+ getType: function () { return [typeObject(i)]; } // don't forget list
359
+ });
360
+ };
361
+ export var objectAnyFieldsValidator = function (valueValidator) { return ({
362
+ validate: function (o) {
250
363
  if (o === void 0) { o = {}; }
251
364
  return build_validator(function (object) {
252
- var emptyOk = !!objectOptions.emptyOk || o.emptyListOk;
253
- var validated = {};
254
365
  if (!is_object(object)) {
255
- throw new Error("Expected a non-null object by got ".concat(object));
256
- }
257
- if (!emptyOk && object_is_empty(object)) {
258
- throw new Error("Expected a non-empty object");
259
- }
260
- // don't throw on unrecognized fields, just ignore/don't validate them
261
- // const unrecognizedFields = []
262
- // for (const field in object) {
263
- // if (!(i as Indexable)[field]) {
264
- // unrecognizedFields.push(field)
265
- // }
266
- // }
267
- // if (unrecognizedFields.length > 0) {
268
- // throw new Error(`Got unexpected field(s) [${unrecognizedFields.join(', ')}]`)
269
- // }
270
- for (var field in i) {
271
- var value = object[field];
272
- var escaped = i[field](value); // may be required
273
- if (escaped === undefined)
274
- continue;
275
- validated[field] = escaped;
276
- }
277
- return validated;
278
- }, __assign(__assign({}, o), { isObject: true, listOf: true, emptyListOk: !!objectOptions.emptyOk || o.emptyListOk }));
279
- };
280
- };
281
- export var objectAnyFieldsValidator = function (valueValidator) { return function (o) {
282
- if (o === void 0) { o = {}; }
283
- return build_validator(function (object) {
284
- if (!is_object(object)) {
285
- throw new Error("Expected a non-null object by got ${object}");
286
- }
287
- var validated = {};
288
- for (var field in object) {
289
- if (valueValidator) {
290
- validated[field] = valueValidator(object[field]);
291
- }
292
- else if (typeof object[field] === 'number') {
293
- validated[field] = numberValidator(object[field]);
366
+ throw new Error("Expected a non-null object by got ${object}");
294
367
  }
295
- else if (typeof object[field] === 'string') {
296
- validated[field] = stringValidator(object[field]);
297
- }
298
- else if (object[field] === null) {
299
- validated[field] = null;
300
- }
301
- else {
368
+ var validated = {};
369
+ for (var field in object) {
302
370
  if (valueValidator) {
303
- throw new Error("Field ".concat(field, " is not a string or number"));
371
+ validated[field] = valueValidator.validate()(object[field]);
372
+ }
373
+ else if (typeof object[field] === 'number') {
374
+ validated[field] = numberValidator.validate()(object[field]);
375
+ }
376
+ else if (typeof object[field] === 'string') {
377
+ validated[field] = stringValidator.validate()(object[field]);
378
+ }
379
+ else if (object[field] === null) {
380
+ validated[field] = null;
381
+ }
382
+ else {
383
+ if (valueValidator) {
384
+ throw new Error("Field ".concat(field, " is not a string or number"));
385
+ }
386
+ validated[field] = object[field];
304
387
  }
305
- validated[field] = object[field];
306
388
  }
307
- }
308
- return validated;
309
- }, __assign(__assign({}, o), { isObject: true, listOf: false }));
310
- }; };
389
+ return validated;
390
+ }, __assign(__assign({}, o), { isObject: true, listOf: false }));
391
+ },
392
+ getExample: function () { var _a, _b; return "{ \"key\": ".concat((_b = (_a = valueValidator === null || valueValidator === void 0 ? void 0 : valueValidator.getExample) === null || _a === void 0 ? void 0 : _a.call(valueValidator)) !== null && _b !== void 0 ? _b : '"value"', " }"); },
393
+ getType: function () { var _a, _b; return "{ \"key\": ".concat((_b = (_a = valueValidator === null || valueValidator === void 0 ? void 0 : valueValidator.getType) === null || _a === void 0 ? void 0 : _a.call(valueValidator)) !== null && _b !== void 0 ? _b : 'string', " }"); },
394
+ }); };
311
395
  export var objectAnyFieldsAnyValuesValidator = objectAnyFieldsValidator();
312
396
  export var escapeString = function (o) {
313
397
  if (o === void 0) { o = {}; }
@@ -323,49 +407,134 @@ export var escapeString = function (o) {
323
407
  return string;
324
408
  };
325
409
  };
326
- export var stringValidator = function (o) {
327
- var _a;
328
- if (o === void 0) { o = {}; }
329
- return build_validator(escapeString(o), __assign(__assign({}, o), { maxLength: (_a = o.maxLength) !== null && _a !== void 0 ? _a : 1000, listOf: false }));
410
+ export var stringValidator = {
411
+ validate: function (o) {
412
+ var _a;
413
+ if (o === void 0) { o = {}; }
414
+ return build_validator(escapeString(o), __assign(__assign({}, o), { maxLength: (_a = o.maxLength) !== null && _a !== void 0 ? _a : 1000, listOf: false }));
415
+ },
416
+ getExample: getExampleString,
417
+ getType: getTypeString,
330
418
  };
331
- export var stringValidator100 = function (o) {
332
- if (o === void 0) { o = {}; }
333
- return build_validator(escapeString(o), __assign(__assign({}, o), { maxLength: 100, listOf: false }));
419
+ export var stringValidatorOptional = {
420
+ validate: function (o) {
421
+ var _a;
422
+ if (o === void 0) { o = {}; }
423
+ return build_validator(escapeString(o), __assign(__assign({}, o), { maxLength: (_a = o.maxLength) !== null && _a !== void 0 ? _a : 1000, listOf: false, isOptional: true }));
424
+ },
425
+ getExample: getExampleString,
426
+ getType: getTypeString,
334
427
  };
335
- export var stringValidator250 = function (o) {
336
- if (o === void 0) { o = {}; }
337
- return build_validator(escapeString(o), __assign(__assign({}, o), { maxLength: 250, listOf: false }));
428
+ export var stringValidator100 = {
429
+ validate: function (o) {
430
+ if (o === void 0) { o = {}; }
431
+ return build_validator(escapeString(o), __assign(__assign({}, o), { maxLength: 100, listOf: false }));
432
+ },
433
+ getExample: function () { return 'example string'; },
434
+ getType: function () { return 'string'; }
338
435
  };
339
- export var stringValidator1000 = function (o) {
340
- if (o === void 0) { o = {}; }
341
- return build_validator(escapeString(o), __assign(__assign({}, o), { maxLength: 1000, listOf: false }));
436
+ export var stringValidator250 = {
437
+ validate: function (o) {
438
+ if (o === void 0) { o = {}; }
439
+ return build_validator(escapeString(o), __assign(__assign({}, o), { maxLength: 250, listOf: false }));
440
+ },
441
+ getExample: getExampleString,
442
+ getType: getTypeString,
342
443
  };
343
- export var stringValidator5000 = function (o) {
344
- if (o === void 0) { o = {}; }
345
- return build_validator(escapeString(o), __assign(__assign({}, o), { maxLength: 5000, listOf: false }));
444
+ export var stringValidator1000 = {
445
+ validate: function (o) {
446
+ if (o === void 0) { o = {}; }
447
+ return build_validator(escapeString(o), __assign(__assign({}, o), { maxLength: 1000, listOf: false }));
448
+ },
449
+ getExample: getExampleString,
450
+ getType: getTypeString,
346
451
  };
347
- export var stringValidator25000 = function (o) {
348
- if (o === void 0) { o = {}; }
349
- return build_validator(escapeString(o), __assign(__assign({}, o), { maxLength: 25000, listOf: false }));
452
+ export var stringValidator5000 = {
453
+ validate: function (o) {
454
+ if (o === void 0) { o = {}; }
455
+ return build_validator(escapeString(o), __assign(__assign({}, o), { maxLength: 5000, listOf: false }));
456
+ },
457
+ getExample: getExampleString,
458
+ getType: getTypeString,
350
459
  };
351
- export var SMSMessageValidator = function (o) {
352
- if (o === void 0) { o = {}; }
353
- return build_validator(escapeString(o), __assign(__assign({}, o), { maxLength: 630, listOf: false }));
354
- };
355
- export var listValidator = function (b) { return function (o) { return build_validator(b, __assign(__assign({}, o), { listOf: true })); }; };
356
- export var listValidatorEmptyOk = function (b) { return function (o) { return build_validator(b, __assign(__assign({}, o), { listOf: true, emptyListOk: true })); }; };
357
- export var listOfStringsValidator = listValidator(stringValidator());
358
- export var listOfStringsValidatorEmptyOk = listValidatorEmptyOk(stringValidator());
359
- export var listOfObjectAnyFieldsAnyValuesValidator = listValidator(objectAnyFieldsAnyValuesValidator());
360
- export var booleanValidator = function (options) {
361
- if (options === void 0) { options = {}; }
362
- return build_validator(function (boolean) {
363
- if (boolean !== true && boolean !== false) {
364
- throw new Error(options.errorMessage || "Invalid boolean");
365
- }
366
- return boolean;
367
- }, __assign(__assign({}, options), { isBoolean: true, listOf: false }));
460
+ export var stringValidator5000EmptyOkay = {
461
+ validate: function (o) {
462
+ if (o === void 0) { o = {}; }
463
+ return build_validator(escapeString(o), __assign(__assign({}, o), { maxLength: 5000, listOf: false, emptyStringOk: true }));
464
+ },
465
+ getExample: getExampleString,
466
+ getType: getTypeString,
467
+ };
468
+ export var stringValidator5000Optional = {
469
+ validate: function (o) {
470
+ if (o === void 0) { o = {}; }
471
+ return build_validator(escapeString(o), __assign(__assign({}, o), { maxLength: 5000, listOf: false, isOptional: true, emptyStringOk: true }));
472
+ },
473
+ getExample: getExampleString,
474
+ getType: getTypeString,
475
+ };
476
+ export var stringValidator25000 = {
477
+ validate: function (o) {
478
+ if (o === void 0) { o = {}; }
479
+ return build_validator(escapeString(o), __assign(__assign({}, o), { maxLength: 25000, listOf: false }));
480
+ },
481
+ getExample: getExampleString,
482
+ getType: getTypeString,
483
+ };
484
+ export var stringValidator25000EmptyOkay = {
485
+ validate: function (o) {
486
+ if (o === void 0) { o = {}; }
487
+ return build_validator(escapeString(o), __assign(__assign({}, o), { maxLength: 25000, listOf: false, emptyStringOk: true }));
488
+ },
489
+ getExample: getExampleString,
490
+ getType: getTypeString,
491
+ };
492
+ export var SMSMessageValidator = {
493
+ validate: function (o) {
494
+ if (o === void 0) { o = {}; }
495
+ return build_validator(escapeString(o), __assign(__assign({}, o), { maxLength: 630, listOf: false }));
496
+ },
497
+ getExample: getExampleString,
498
+ getType: getTypeString,
368
499
  };
500
+ export var listValidator = function (b, o) { return ({
501
+ validate: function (o) { return build_validator(b.validate(o), __assign(__assign({}, o), { listOf: true })); },
502
+ getExample: function () { return [b.getExample()]; },
503
+ getType: function () { return [b.getExample()]; },
504
+ }); };
505
+ export var listValidatorEmptyOk = function (b, o) { return ({
506
+ validate: function (o) { return build_validator(b.validate(o), __assign(__assign({}, o), { listOf: true, emptyListOk: true })); },
507
+ getExample: function () { return [b.getExample()]; },
508
+ getType: function () { return [b.getExample()]; },
509
+ }); };
510
+ export var listValidatorOptionalOrEmptyOk = function (b, o) { return ({
511
+ validate: function (o) { return build_validator(b.validate(o), __assign(__assign({}, o), { listOf: true, emptyListOk: true, isOptional: true })); },
512
+ getExample: function () { return [b.getExample()]; },
513
+ getType: function () { return [b.getExample()]; },
514
+ }); };
515
+ export var listOfStringsValidator = listValidator(stringValidator);
516
+ export var listOfStringsValidatorOptionalOrEmptyOk = listValidatorOptionalOrEmptyOk(stringValidator);
517
+ export var listOfStringsValidatorEmptyOk = listValidatorEmptyOk(stringValidator);
518
+ export var listOfObjectAnyFieldsAnyValuesValidator = listValidator(objectAnyFieldsAnyValuesValidator);
519
+ export var booleanValidatorBuilder = function (defaults) { return ({
520
+ validate: function (options) {
521
+ if (options === void 0) { options = {}; }
522
+ return build_validator(function (boolean) {
523
+ if (boolean === 'true')
524
+ return true;
525
+ if (boolean === 'false')
526
+ return false;
527
+ if (typeof boolean !== 'boolean') {
528
+ throw new Error(options.errorMessage || "Invalid boolean");
529
+ }
530
+ return boolean;
531
+ }, __assign(__assign(__assign({}, defaults), options), { isBoolean: true, listOf: false }));
532
+ },
533
+ getExample: function () { return "false"; },
534
+ getType: function () { return "boolean"; },
535
+ }); };
536
+ export var booleanValidator = booleanValidatorBuilder({});
537
+ export var booleanValidatorOptional = booleanValidatorBuilder({ isOptional: true });
369
538
  export var escapeMongoId = function (mongoId) {
370
539
  if (typeof mongoId !== 'string')
371
540
  throw new Error('Expecting string id');
@@ -374,14 +543,22 @@ export var escapeMongoId = function (mongoId) {
374
543
  }
375
544
  return mongoId;
376
545
  };
377
- export var mongoIdValidator = function (o) {
378
- if (o === void 0) { o = {}; }
379
- return build_validator(function (s) { return to_object_id(escapeMongoId(s)); }, __assign(__assign({}, optionsWithDefaults(o)), { maxLength: 100, listOf: false }));
380
- };
381
- export var mongoIdStringValidator = function (o) {
382
- if (o === void 0) { o = {}; }
383
- return build_validator(escapeMongoId, __assign(__assign({}, optionsWithDefaults(o)), { maxLength: 100, listOf: false }));
546
+ export var mongoIdValidator = {
547
+ validate: function (o) {
548
+ if (o === void 0) { o = {}; }
549
+ return build_validator(function (s) { return to_object_id(escapeMongoId(s)); }, __assign(__assign({}, optionsWithDefaults(o)), { maxLength: 100, listOf: false }));
550
+ },
551
+ getType: getTypeString,
552
+ getExample: getExampleObjectId,
384
553
  };
554
+ export var buildMongoIdStringValidator = function (options) { return ({
555
+ validate: function (o) {
556
+ if (o === void 0) { o = {}; }
557
+ return build_validator(escapeMongoId, __assign(__assign({}, optionsWithDefaults(__assign(__assign({}, options), o))), { maxLength: 100, listOf: false }));
558
+ },
559
+ getType: getTypeString,
560
+ getExample: getExampleObjectId,
561
+ }); };
385
562
  export var nullValidator = function (o) {
386
563
  if (o === void 0) { o = {}; }
387
564
  return build_validator(function (v) {
@@ -390,198 +567,286 @@ export var nullValidator = function (o) {
390
567
  return v;
391
568
  }, __assign(__assign({}, o), { listOf: false }));
392
569
  };
393
- export var mongoIdRequired = mongoIdValidator();
394
- export var mongoIdOptional = mongoIdValidator({ isOptional: true });
395
- export var mongoIdStringRequired = mongoIdStringValidator();
396
- export var mongoIdStringOptional = mongoIdStringValidator({ isOptional: true });
397
- export var listOfMongoIdValidator = listValidator(mongoIdValidator());
398
- export var listOfMongoIdStringValidator = listValidator(mongoIdStringValidator());
399
- export var listOfMongoIdStringValidatorEmptyOk = listValidatorEmptyOk(mongoIdStringValidator());
570
+ export var mongoIdRequired = mongoIdValidator.validate();
571
+ export var mongoIdOptional = mongoIdValidator.validate({ isOptional: true });
572
+ export var listOfMongoIdValidator = listValidator(mongoIdValidator);
573
+ export var mongoIdStringRequired = buildMongoIdStringValidator({ isOptional: false });
574
+ export var mongoIdStringOptional = buildMongoIdStringValidator({ isOptional: true });
575
+ export var listOfMongoIdStringValidator = listValidator(mongoIdStringRequired);
576
+ export var listOfMongoIdStringValidatorEmptyOk = listValidatorEmptyOk(mongoIdStringRequired);
400
577
  export var first_letter_capitalized = function (s) {
401
578
  if (s === void 0) { s = ''; }
402
579
  return s.charAt(0).toUpperCase() + s.slice(1);
403
580
  };
404
581
  export var escape_name = function (namestring) { return namestring.replace(/[^a-zA-Z0-9-_ /.]/, '').substring(0, 100); };
405
582
  // enforces first-letter capitalization
406
- export var nameValidator = function (options) {
407
- if (options === void 0) { options = {}; }
408
- return build_validator(function (name) {
409
- if (typeof name !== 'string')
410
- throw new Error('Expecting string value');
411
- name = escape_name(name);
412
- if (!name)
413
- throw new Error("Invalid name");
414
- return first_letter_capitalized(name);
415
- }, __assign(__assign({}, options), { maxLength: 100, trim: true, listOf: false }));
583
+ export var nameValidator = {
584
+ validate: function (options) {
585
+ if (options === void 0) { options = {}; }
586
+ return build_validator(function (name) {
587
+ if (typeof name !== 'string')
588
+ throw new Error('Expecting string value');
589
+ name = escape_name(name);
590
+ if (!name)
591
+ throw new Error("Invalid name");
592
+ return first_letter_capitalized(name);
593
+ }, __assign(__assign({}, options), { maxLength: 100, trim: true, listOf: false }));
594
+ },
595
+ getExample: function () { return 'John'; },
596
+ getType: getTypeString,
416
597
  };
417
- export var emailValidator = function (options) {
418
- if (options === void 0) { options = {}; }
419
- return build_validator(function (email) {
420
- if (typeof email !== 'string')
421
- throw new Error('Expecting string value');
422
- if (!isEmail(email)) {
423
- throw new Error(options.errorMessage || "Invalid email");
424
- }
425
- return email.toLowerCase();
426
- }, __assign(__assign({}, options), { maxLength: 250, listOf: false }));
598
+ export var emailValidator = {
599
+ validate: function (options) {
600
+ if (options === void 0) { options = {}; }
601
+ return build_validator(function (email) {
602
+ if (typeof email !== 'string')
603
+ throw new Error('Expecting string value');
604
+ if (!isEmail(email)) {
605
+ throw new Error(options.errorMessage || "Invalid email");
606
+ }
607
+ return email.toLowerCase();
608
+ }, __assign(__assign({}, options), { maxLength: 250, listOf: false }));
609
+ },
610
+ getExample: function () { return "example@tellescope.com"; },
611
+ getType: getTypeString,
427
612
  };
428
- export var emailValidatorEmptyOkay = function (options) {
429
- if (options === void 0) { options = {}; }
430
- return build_validator(function (email) {
431
- if (typeof email !== 'string')
432
- throw new Error('Expecting string value');
433
- if (!isEmail(email)) {
434
- throw new Error(options.errorMessage || "Invalid email");
435
- }
436
- return email.toLowerCase();
437
- }, __assign(__assign({}, options), { maxLength: 250, emptyStringOk: true, listOf: false }));
613
+ export var emailValidatorOptional = {
614
+ validate: function (options) {
615
+ if (options === void 0) { options = {}; }
616
+ return build_validator(function (email) {
617
+ if (typeof email !== 'string')
618
+ throw new Error('Expecting string value');
619
+ if (!isEmail(email)) {
620
+ throw new Error(options.errorMessage || "Invalid email");
621
+ }
622
+ return email.toLowerCase();
623
+ }, __assign(__assign({}, options), { maxLength: 250, listOf: false, isOptional: true, emptyStringOk: true }));
624
+ },
625
+ getExample: function () { return "example@tellescope.com"; },
626
+ getType: getTypeString,
627
+ };
628
+ export var emailValidatorEmptyOkay = {
629
+ validate: function (options) {
630
+ if (options === void 0) { options = {}; }
631
+ return build_validator(function (email) {
632
+ if (typeof email !== 'string')
633
+ throw new Error('Expecting string value');
634
+ if (!isEmail(email)) {
635
+ throw new Error(options.errorMessage || "Invalid email");
636
+ }
637
+ return email.toLowerCase();
638
+ }, __assign(__assign({}, options), { maxLength: 250, emptyStringOk: true, listOf: false }));
639
+ },
640
+ getExample: function () { return "example@tellescope.com"; },
641
+ getType: getTypeString,
642
+ };
643
+ export var numberValidatorBuilder = function (_a) {
644
+ var lower = _a.lower, upper = _a.upper, higherOptions = __rest(_a, ["lower", "upper"]);
645
+ return ({
646
+ validate: function (options) {
647
+ if (options === void 0) { options = {}; }
648
+ options.isNumber = true;
649
+ return build_validator(function (number) {
650
+ number = Number(number); // ok to throw error!
651
+ if (typeof number !== "number" || isNaN(number)) {
652
+ throw new Error(options.errorMessage || "Not a valid number");
653
+ }
654
+ if (!(lower || upper))
655
+ return number;
656
+ if (!(number >= lower && number <= upper)) {
657
+ throw new Error(options.errorMessage || "Not a valid number for [".concat(lower, "-").concat(upper, "]"));
658
+ }
659
+ return number;
660
+ }, __assign(__assign({}, optionsWithDefaults(__assign(__assign({}, higherOptions), options))), { listOf: false }));
661
+ },
662
+ getExample: function () { return "".concat(lower); },
663
+ getType: getTypeNumber,
664
+ });
438
665
  };
439
- export var numberValidatorBuilder = function (r) { return function (options) {
440
- if (options === void 0) { options = {}; }
441
- options.isNumber = true;
442
- return build_validator(function (number) {
443
- number = Number(number); // ok to throw error!
444
- if (typeof number !== "number" || isNaN(number)) {
445
- throw new Error(options.errorMessage || "Not a valid number");
446
- }
447
- if (!r)
448
- return number;
449
- if (!(number >= r.lower && number <= r.upper)) {
450
- throw new Error(options.errorMessage || "Not a valid number for [".concat(r.lower, "-").concat(r.upper, "]"));
451
- }
452
- return number;
453
- }, __assign(__assign({}, options), { listOf: false }));
454
- }; };
455
666
  export var nonNegNumberValidator = numberValidatorBuilder({ lower: 0, upper: 10000000000000 }); // max is 2286 in UTC MS
456
667
  export var numberValidator = numberValidatorBuilder({ lower: -100000000, upper: 10000000000000 }); // max is 2286 in UTC MS
668
+ export var numberValidatorOptional = numberValidatorBuilder({ lower: -100000000, upper: 10000000000000, isOptional: true, emptyStringOk: true }); // max is 2286 in UTC MS
457
669
  export var fileSizeValidator = numberValidatorBuilder({ lower: 0, upper: MAX_FILE_SIZE });
458
- export var dateValidator = function (options) {
459
- if (options === void 0) { options = {}; }
460
- return build_validator(function (date) {
461
- if (isDate(date))
462
- throw new Error(options.errorMessage || "Invalid date");
463
- return new Date(date);
464
- }, __assign(__assign({}, options), { maxLength: 250, listOf: false }));
670
+ export var dateValidator = {
671
+ validate: function (options) {
672
+ if (options === void 0) { options = {}; }
673
+ return build_validator(function (date) {
674
+ if (isDate(date))
675
+ throw new Error(options.errorMessage || "Invalid date");
676
+ return new Date(date);
677
+ }, __assign(__assign({}, options), { maxLength: 250, listOf: false }));
678
+ },
679
+ getExample: function () { return new Date().toISOString(); },
680
+ getType: function () { return "Date"; },
465
681
  };
466
- export var exactMatchValidator = function (matches) { return function (o) {
467
- if (o === void 0) { o = {}; }
468
- return build_validator(function (match) {
469
- if (matches.filter(function (m) { return m === match; }).length === 0) {
470
- throw new Error("Value must match one of ".concat(matches));
471
- }
472
- return match;
473
- }, __assign(__assign({}, o), { listOf: false }));
474
- }; };
475
- export var exactMatchListValidator = function (matches) { return function (o) {
476
- if (o === void 0) { o = {}; }
477
- return build_validator(function (match) {
478
- if (matches.filter(function (m) { return m === match; }).length === 0) {
479
- throw new Error("Value must match one of ".concat(matches));
480
- }
481
- return match;
482
- }, __assign(__assign({}, o), { listOf: true }));
483
- }; };
484
- export var journeysValidator = function (options) {
485
- if (options === void 0) { options = {}; }
486
- return build_validator(function (journeys) {
487
- if (typeof journeys !== 'object') {
488
- throw new Error('Expecting an object');
489
- }
490
- var mIdValidator = mongoIdValidator();
491
- var stateValidator = stringValidator({ isOptional: true, maxLength: 75, errorMessage: "Journey state names may not exceed 75 characters" });
492
- for (var j in journeys) {
493
- mIdValidator(j);
494
- journeys[j] = stateValidator(journeys[j]);
495
- }
496
- return journeys;
497
- }, __assign(__assign({}, options), { isObject: true, listOf: false }));
682
+ export var dateValidatorOptional = {
683
+ validate: function (options) {
684
+ if (options === void 0) { options = {}; }
685
+ return build_validator(function (date) {
686
+ if (isDate(date))
687
+ throw new Error(options.errorMessage || "Invalid date");
688
+ return new Date(date);
689
+ }, __assign(__assign({}, options), { maxLength: 250, listOf: false, isOptional: true, emptyStringOk: true }));
690
+ },
691
+ getExample: function () { return new Date().toISOString(); },
692
+ getType: function () { return "Date"; },
693
+ };
694
+ export var exactMatchValidator = function (matches) { return ({
695
+ validate: function (o) {
696
+ if (o === void 0) { o = {}; }
697
+ return build_validator(function (match) {
698
+ if (matches.filter(function (m) { return m === match; }).length === 0) {
699
+ throw new Error("Value must match one of ".concat(matches));
700
+ }
701
+ return match;
702
+ }, __assign(__assign({}, o), { listOf: false }));
703
+ },
704
+ getExample: function () { return matches[0]; },
705
+ getType: getTypeString,
706
+ }); };
707
+ export var exactMatchValidatorOptional = function (matches) { return ({
708
+ validate: function (o) {
709
+ if (o === void 0) { o = {}; }
710
+ return build_validator(function (match) {
711
+ if (matches.filter(function (m) { return m === match; }).length === 0) {
712
+ throw new Error("Value must match one of ".concat(matches));
713
+ }
714
+ return match;
715
+ }, __assign(__assign({}, o), { listOf: false, isOptional: true }));
716
+ },
717
+ getExample: function () { return matches[0]; },
718
+ getType: getTypeString,
719
+ }); };
720
+ export var exactMatchListValidator = function (matches) { return listValidator(exactMatchValidator(matches)); };
721
+ export var journeysValidator = {
722
+ validate: function (options) {
723
+ if (options === void 0) { options = {}; }
724
+ return build_validator(function (journeys) {
725
+ if (typeof journeys !== 'object') {
726
+ throw new Error('Expecting an object');
727
+ }
728
+ var mIdValidator = mongoIdValidator.validate();
729
+ var stateValidator = stringValidator.validate({ isOptional: true, maxLength: 75, errorMessage: "Journey state names may not exceed 75 characters" });
730
+ for (var j in journeys) {
731
+ mIdValidator(j);
732
+ journeys[j] = stateValidator(journeys[j]);
733
+ }
734
+ return journeys;
735
+ }, __assign(__assign({}, options), { isObject: true, listOf: false }));
736
+ },
737
+ getExample: function () { return "{ ".concat(EXAMPLE_OBJECT_ID, ": \"status\" }"); },
738
+ getType: function () { return "{ string: string }"; },
498
739
  };
499
740
  export var escape_phone_number = function (p) {
500
741
  if (p === void 0) { p = ''; }
501
742
  return p.replace(/[^\d+]/g, '');
502
743
  };
503
- export var phoneValidator = function (options) {
504
- if (options === void 0) { options = {}; }
505
- return build_validator(function (phone) {
506
- if (typeof phone !== "string")
507
- throw new Error("Expecting phone to be string but got ".concat(phone));
508
- var escaped = escape_phone_number(phone);
509
- if (escaped.length < 10)
510
- throw new Error("Phone number must be at least 10 digits");
511
- escaped = escaped.startsWith('+') ? escaped
512
- : escaped.length === 10 ? '+1' + escaped // assume US country code for now
513
- : "+" + escaped; // assume country code provided, but missing leading +
514
- if (!isMobilePhone(escaped, 'any', { strictMode: true })) {
515
- throw "Invalid phone number";
516
- }
517
- return escaped;
518
- }, __assign(__assign({}, options), { maxLength: 25, listOf: false }));
744
+ export var phoneValidator = {
745
+ validate: function (options) {
746
+ if (options === void 0) { options = {}; }
747
+ return build_validator(function (phone) {
748
+ if (typeof phone !== "string")
749
+ throw new Error("Expecting phone to be string but got ".concat(phone));
750
+ var escaped = escape_phone_number(phone);
751
+ if (escaped.length < 10)
752
+ throw new Error("Phone number must be at least 10 digits");
753
+ escaped = escaped.startsWith('+') ? escaped
754
+ : escaped.length === 10 ? '+1' + escaped // assume US country code for now
755
+ : "+" + escaped; // assume country code provided, but missing leading +
756
+ if (!isMobilePhone(escaped, 'any', { strictMode: true })) {
757
+ throw "Invalid phone number";
758
+ }
759
+ return escaped;
760
+ }, __assign(__assign({}, options), { maxLength: 25, listOf: false }));
761
+ },
762
+ getExample: function () { return "+15555555555"; },
763
+ getType: getTypeString,
519
764
  };
520
- export var phoneValidatorEmptyOkay = function (options) {
521
- if (options === void 0) { options = {}; }
522
- return build_validator(function (phone) {
523
- if (typeof phone !== "string")
524
- throw new Error("Expecting phone to be string but got ".concat(phone));
525
- var escaped = escape_phone_number(phone);
526
- if (escaped.length < 10)
527
- throw new Error("Phone number must be at least 10 digits");
528
- escaped = escaped.startsWith('+') ? escaped
529
- : escaped.length === 10 ? '+1' + escaped // assume US country code for now
530
- : "+" + escaped; // assume country code provided, but missing leading +
531
- if (!isMobilePhone(escaped, 'any', { strictMode: true })) {
532
- throw "Invalid phone number";
533
- }
534
- return escaped;
535
- }, __assign(__assign({}, options), { maxLength: 25, listOf: false, emptyStringOk: true }));
765
+ export var phoneValidatorOptional = {
766
+ validate: function (options) {
767
+ if (options === void 0) { options = {}; }
768
+ return build_validator(function (phone) {
769
+ if (typeof phone !== "string")
770
+ throw new Error("Expecting phone to be string but got ".concat(phone));
771
+ var escaped = escape_phone_number(phone);
772
+ if (escaped.length < 10)
773
+ throw new Error("Phone number must be at least 10 digits");
774
+ escaped = escaped.startsWith('+') ? escaped
775
+ : escaped.length === 10 ? '+1' + escaped // assume US country code for now
776
+ : "+" + escaped; // assume country code provided, but missing leading +
777
+ if (!isMobilePhone(escaped, 'any', { strictMode: true })) {
778
+ throw "Invalid phone number";
779
+ }
780
+ return escaped;
781
+ }, __assign(__assign({}, options), { maxLength: 25, listOf: false, isOptional: true, emptyStringOk: true }));
782
+ },
783
+ getExample: function () { return "+15555555555"; },
784
+ getType: getTypeString,
536
785
  };
537
- export var fileTypeValidator = function (options) {
538
- if (options === void 0) { options = {}; }
539
- return build_validator(function (s) {
540
- if (typeof s !== 'string')
541
- throw new Error("fileType must be a string");
542
- if (!isMimeType(s))
543
- throw new Error("".concat(s, " is not a valid file type"));
544
- return s;
545
- }, __assign(__assign({}, options), { listOf: false }));
546
- };
547
- export var urlValidator = function (options) {
548
- if (options === void 0) { options = {}; }
549
- return build_validator(function (s) {
550
- if (typeof s !== 'string')
551
- throw new Error("URL must be a string");
552
- if (!isURL(s))
553
- throw new Error("".concat(s, " is not a valid URL"));
554
- return s;
555
- }, __assign(__assign({}, options), { listOf: false }));
556
- };
557
- export var safeBase64Validator = function (options) {
558
- if (options === void 0) { options = {}; }
559
- return build_validator(function (sb64) {
560
- if (typeof sb64 !== 'string')
561
- throw new Error("Expecting string");
562
- // https://stackoverflow.com/questions/12930007/how-to-validate-base64-string-using-regex-in-javascript
563
- // regex with = + and / replaced as get_random_base64_URL_safe
564
- if (!/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2}..|[A-Za-z0-9_-]{3}.)?$/.test(sb64)) {
565
- throw "Invalid safe base64";
566
- }
567
- return sb64;
568
- }, __assign(__assign({}, options), { listOf: false }));
786
+ export var fileTypeValidator = {
787
+ validate: function (options) {
788
+ if (options === void 0) { options = {}; }
789
+ return build_validator(function (s) {
790
+ if (typeof s !== 'string')
791
+ throw new Error("fileType must be a string");
792
+ if (!isMimeType(s))
793
+ throw new Error("".concat(s, " is not a valid file type"));
794
+ return s;
795
+ }, __assign(__assign({}, options), { listOf: false }));
796
+ },
797
+ getExample: function () { return 'text/plain'; },
798
+ getType: getTypeString,
569
799
  };
570
- export var subdomainValidator = function (options) {
571
- if (options === void 0) { options = {}; }
572
- return build_validator(function (subdomain) {
573
- if (typeof subdomain !== 'string')
574
- throw new Error("Expecting string value");
575
- subdomain = subdomain.toLowerCase();
576
- if (subdomain.startsWith('-')) {
577
- subdomain = subdomain.substring(1);
578
- }
579
- while (subdomain.endsWith('-')) {
580
- subdomain = subdomain.substring(0, subdomain.length - 1);
581
- }
582
- subdomain = subdomain.replace(/[^a-zA-Z\d-]/g, '');
583
- return subdomain;
584
- }, __assign(__assign({}, options), { maxLength: 50, listOf: false }));
800
+ export var urlValidator = {
801
+ validate: function (options) {
802
+ if (options === void 0) { options = {}; }
803
+ return build_validator(function (s) {
804
+ if (typeof s !== 'string')
805
+ throw new Error("URL must be a string");
806
+ if (!isURL(s))
807
+ throw new Error("".concat(s, " is not a valid URL"));
808
+ return s;
809
+ }, __assign(__assign({}, options), { listOf: false }));
810
+ },
811
+ getExample: function () { return '"https://www.tellescope.com"'; },
812
+ getType: getTypeString,
813
+ };
814
+ export var safeBase64Validator = {
815
+ validate: function (options) {
816
+ if (options === void 0) { options = {}; }
817
+ return build_validator(function (sb64) {
818
+ if (typeof sb64 !== 'string')
819
+ throw new Error("Expecting string");
820
+ // https://stackoverflow.com/questions/12930007/how-to-validate-base64-string-using-regex-in-javascript
821
+ // regex with = + and / replaced as get_random_base64_URL_safe
822
+ if (!/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2}..|[A-Za-z0-9_-]{3}.)?$/.test(sb64)) {
823
+ throw "Invalid safe base64";
824
+ }
825
+ return sb64;
826
+ }, __assign(__assign({}, options), { listOf: false }));
827
+ },
828
+ getExample: function () { return '129vjas0fkj1234jgfmnaef'; },
829
+ getType: getTypeString,
830
+ };
831
+ export var subdomainValidator = {
832
+ validate: function (options) {
833
+ if (options === void 0) { options = {}; }
834
+ return build_validator(function (subdomain) {
835
+ if (typeof subdomain !== 'string')
836
+ throw new Error("Expecting string value");
837
+ subdomain = subdomain.toLowerCase();
838
+ if (subdomain.startsWith('-')) {
839
+ subdomain = subdomain.substring(1);
840
+ }
841
+ while (subdomain.endsWith('-')) {
842
+ subdomain = subdomain.substring(0, subdomain.length - 1);
843
+ }
844
+ subdomain = subdomain.replace(/[^a-zA-Z\d-]/g, '');
845
+ return subdomain;
846
+ }, __assign(__assign({}, options), { maxLength: 50, listOf: false }));
847
+ },
848
+ getExample: function () { return 'example'; },
849
+ getType: getTypeString,
585
850
  };
586
851
  // export const fileResponseValidator: EscapeBuilder<FileResponse> = (options={}) => build_validator(
587
852
  // (file: any) => {
@@ -595,14 +860,14 @@ export var subdomainValidator = function (options) {
595
860
  // { ...options, isObject: true, listOf: false }
596
861
  // )
597
862
  export var fileResponseValidator = objectValidator({
598
- type: exactMatchValidator(['file'])(),
599
- name: stringValidator({ shouldTruncate: true, maxLength: 250 }),
600
- secureName: stringValidator250(),
863
+ type: exactMatchValidator(['file']),
864
+ name: stringValidator1000,
865
+ secureName: stringValidator250,
601
866
  });
602
867
  export var signatureResponseValidator = objectValidator({
603
- type: exactMatchValidator(['signature'])(),
604
- fullName: stringValidator({ maxLength: 100 }),
605
- signed: booleanValidator(),
868
+ type: exactMatchValidator(['signature']),
869
+ fullName: stringValidator100,
870
+ signed: booleanValidator,
606
871
  });
607
872
  var DEFAULT_ENDUSER_FIELDS = [
608
873
  '_id', 'email', 'phone', 'fname', 'lname', 'journeys', 'tags', 'preference'
@@ -632,26 +897,28 @@ var _FORM_FIELD_TYPES = {
632
897
  export var FORM_FIELD_TYPES = Object.keys(_FORM_FIELD_TYPES);
633
898
  export var formFieldTypeValidator = exactMatchValidator(FORM_FIELD_TYPES);
634
899
  export var FORM_FIELD_VALIDATORS_BY_TYPE = {
635
- 'string': stringValidator({ maxLength: 5000, emptyStringOk: true, errorMessage: "Response must not exceed 5000 characters" }),
636
- 'number': numberValidator({ errorMessage: "Response must be a number" }),
637
- 'email': emailValidator(),
638
- // @ts-ignore -- backwards compatibility with old field name for email
639
- 'userEmail': emailValidator(),
640
- 'phone': phoneValidator(),
641
- 'phoneNumber': phoneValidator(),
900
+ 'string': stringValidator.validate({ maxLength: 5000, emptyStringOk: true, errorMessage: "Response must not exceed 5000 characters" }),
901
+ 'number': numberValidator.validate({ errorMessage: "Response must be a number" }),
902
+ 'email': emailValidator.validate(),
903
+ 'userEmail': emailValidator.validate(),
904
+ 'phone': phoneValidator.validate(),
905
+ 'phoneNumber': phoneValidator.validate(),
906
+ "date": dateValidator.validate(),
907
+ "ranking": listOfStringsValidator.validate(),
908
+ "rating": numberValidator.validate(),
642
909
  // fileInfo: FileResponse
643
910
  'file': function (fileInfo, _, isOptional) {
644
911
  if (isOptional && (!fileInfo || object_is_empty(fileInfo))) {
645
912
  return { type: 'file', secureName: null };
646
913
  }
647
- return fileResponseValidator()(fileInfo);
914
+ return fileResponseValidator.validate()(fileInfo);
648
915
  },
649
916
  // sigInfo: SignatureResponse
650
917
  'signature': function (sigInfo, _, isOptional) {
651
918
  if (isOptional && (!sigInfo || object_is_empty(sigInfo))) {
652
919
  return { type: 'signature', signed: null };
653
920
  }
654
- return signatureResponseValidator()(sigInfo);
921
+ return signatureResponseValidator.validate()(sigInfo);
655
922
  },
656
923
  // choiceInfo: { indexes: [], otherText?: string }
657
924
  'multiple_choice': function (choiceInfo, fieldOptions, isOptional) {
@@ -680,81 +947,86 @@ export var FORM_FIELD_VALIDATORS_BY_TYPE = {
680
947
  return parsed;
681
948
  },
682
949
  };
683
- export var fieldsValidator = function (options) {
684
- if (options === void 0) { options = {}; }
685
- return build_validator(function (fields) {
686
- if (!is_object(fields))
687
- throw new Error("Expecting an object");
688
- for (var k in fields) {
689
- if (DEFAULT_ENDUSER_FIELDS.includes(k))
690
- throw new Error("key ".concat(k, " conflicts with a built-in field."));
691
- if (k.startsWith('_'))
692
- throw new Error("Fields that start with '_' are not allowed");
693
- if (is_whitespace(k)) {
694
- delete fields[k];
695
- continue;
696
- }
697
- if (k.length > 32)
698
- throw new Error("key ".concat(k, " is greater than 32 characters"));
699
- var val = fields[k];
700
- if (typeof val === 'string') {
701
- if (val.length > 512)
702
- fields[k] = val.substring(0, 512);
703
- continue;
704
- }
705
- else if (typeof val === 'number' || val === null || typeof val === 'boolean') {
706
- continue; // nothing to restrict on number type yet
707
- }
708
- else if (typeof val === 'object') {
709
- if (JSON.stringify(val).length > 1024)
710
- throw new Error("object value for key ".concat(k, " exceeds the maximum length of 1024 characters in string representation"));
711
- // previous restricted structure for fields object
712
- // try {
713
- // if (val.type && typeof val.type === 'string') { // form responses can be stored as custom fields (form responses is simple array)
714
- // FORM_FIELD_VALIDATORS_BY_TYPE[val.type as keyof typeof FORM_FIELD_VALIDATORS_BY_TYPE](val, undefined as never, undefined as never)
715
- // continue
716
- // }
717
- // if (val.length && typeof val.length === 'number') { // array of strings is ok too, (inclusive of multiple-choice responses)
718
- // if (val.find((s: any) => typeof s !== 'string') !== undefined) {
719
- // throw new Error('List must contain only strings')
720
- // }
721
- // continue
722
- // }
723
- // if (val.value === undefined) throw new Error(`value field is undefined for key ${k}`)
724
- // if (JSON.stringify(val).length > 1024) throw new Error(`object value for key ${k} exceeds the maximum length of 1024 characters in string representation`)
725
- // const escaped = { value: val.value } as Indexable // create new object to omit unrecognized fields
726
- // escaped.title = val.title // optional
727
- // escaped.description = val.description // optional
728
- // fields[k] = escaped
729
- // } catch(err) {
730
- // throw new Error(`object value is invalid JSON for key ${k}`)
731
- // }
732
- }
733
- else {
734
- throw new Error("Expecting value to be a string or object but got ".concat(typeof val, " for key {k}"));
950
+ export var fieldsValidator = {
951
+ validate: function (options) {
952
+ if (options === void 0) { options = {}; }
953
+ return build_validator(function (fields) {
954
+ if (!is_object(fields))
955
+ throw new Error("Expecting an object");
956
+ for (var k in fields) {
957
+ if (DEFAULT_ENDUSER_FIELDS.includes(k))
958
+ throw new Error("key ".concat(k, " conflicts with a built-in field."));
959
+ if (k.startsWith('_'))
960
+ throw new Error("Fields that start with '_' are not allowed");
961
+ if (is_whitespace(k)) {
962
+ delete fields[k];
963
+ continue;
964
+ }
965
+ if (k.length > 32)
966
+ throw new Error("key ".concat(k, " is greater than 32 characters"));
967
+ var val = fields[k];
968
+ if (typeof val === 'string') {
969
+ if (val.length > 512)
970
+ fields[k] = val.substring(0, 512);
971
+ continue;
972
+ }
973
+ else if (typeof val === 'number' || val === null || typeof val === 'boolean') {
974
+ continue; // nothing to restrict on number type yet
975
+ }
976
+ else if (typeof val === 'object') {
977
+ if (JSON.stringify(val).length > 1024)
978
+ throw new Error("object value for key ".concat(k, " exceeds the maximum length of 1024 characters in string representation"));
979
+ // previous restricted structure for fields object
980
+ // try {
981
+ // if (val.type && typeof val.type === 'string') { // form responses can be stored as custom fields (form responses is simple array)
982
+ // FORM_FIELD_VALIDATORS_BY_TYPE[val.type as keyof typeof FORM_FIELD_VALIDATORS_BY_TYPE](val, undefined as never, undefined as never)
983
+ // continue
984
+ // }
985
+ // if (val.length && typeof val.length === 'number') { // array of strings is ok too, (inclusive of multiple-choice responses)
986
+ // if (val.find((s: any) => typeof s !== 'string') !== undefined) {
987
+ // throw new Error('List must contain only strings')
988
+ // }
989
+ // continue
990
+ // }
991
+ // if (val.value === undefined) throw new Error(`value field is undefined for key ${k}`)
992
+ // if (JSON.stringify(val).length > 1024) throw new Error(`object value for key ${k} exceeds the maximum length of 1024 characters in string representation`)
993
+ // const escaped = { value: val.value } as Indexable // create new object to omit unrecognized fields
994
+ // escaped.title = val.title // optional
995
+ // escaped.description = val.description // optional
996
+ // fields[k] = escaped
997
+ // } catch(err) {
998
+ // throw new Error(`object value is invalid JSON for key ${k}`)
999
+ // }
1000
+ }
1001
+ else {
1002
+ throw new Error("Expecting value to be a string or object but got ".concat(typeof val, " for key {k}"));
1003
+ }
735
1004
  }
736
- }
737
- return fields;
738
- }, __assign(__assign({}, options), { isObject: true, listOf: false }));
1005
+ return fields;
1006
+ }, __assign(__assign({}, options), { isObject: true, listOf: false }));
1007
+ },
1008
+ getExample: function () { return "{}"; },
1009
+ getType: function () { return "{}"; },
739
1010
  };
740
1011
  export var preferenceValidator = exactMatchValidator(['email', 'sms', 'call', 'chat']);
741
1012
  export var updateOptionsValidator = objectValidator({
742
- replaceObjectFields: booleanValidator({ isOptional: true }),
743
- });
1013
+ replaceObjectFields: booleanValidatorOptional,
1014
+ }, { isOptional: true });
744
1015
  export var journeyStatePriorityValidator = exactMatchValidator(["Disengaged", "N/A", "Engaged"]);
745
1016
  export var journeyStateValidator = objectValidator({
746
- name: stringValidator100(),
747
- priority: journeyStatePriorityValidator(),
748
- description: stringValidator({ isOptional: true }),
749
- requiresFollowup: booleanValidator({ isOptional: true }),
750
- });
751
- export var journeyStateUpdateValidator = objectValidator({
752
- name: stringValidator100({ isOptional: true }),
753
- priority: journeyStatePriorityValidator({ isOptional: true }),
754
- description: stringValidator({ isOptional: true }),
755
- requiresFollowup: booleanValidator({ isOptional: true }),
1017
+ name: stringValidator100,
1018
+ priority: journeyStatePriorityValidator,
1019
+ description: stringValidatorOptional,
1020
+ requiresFollowup: booleanValidatorOptional, // deprecated
756
1021
  });
757
- export var journeyStatesValidator = listValidator(journeyStateValidator());
1022
+ // deprecated
1023
+ // export const journeyStateUpdateValidator = objectValidator<JourneyState>({
1024
+ // name: stringValidator100({ isOptional: true }),
1025
+ // priority: journeyStatePriorityValidator({ isOptional: true }),
1026
+ // description: stringValidator({ isOptional: true }),
1027
+ // requiresFollowup: booleanValidator({ isOptional: true }),
1028
+ // })
1029
+ export var journeyStatesValidator = listValidator(journeyStateValidator);
758
1030
  export var emailEncodingValidator = exactMatchValidator(['', 'base64']);
759
1031
  export var validateIndexable = function (keyValidator, valueValidator) { return function (o) { return build_validator(function (v) {
760
1032
  if (!is_object(v))
@@ -765,18 +1037,26 @@ export var validateIndexable = function (keyValidator, valueValidator) { return
765
1037
  }
766
1038
  return validated;
767
1039
  }, __assign(__assign({}, o), { isObject: true, listOf: false })); }; };
768
- export var indexableValidator = function (keyValidator, valueValidator) { return (validateIndexable(keyValidator, valueValidator)); };
769
- export var indexableNumberValidator = function (keyValidator, valueValidator) { return (validateIndexable(keyValidator, valueValidator)); };
1040
+ export var indexableValidator = function (keyValidator, valueValidator) { return ({
1041
+ validate: validateIndexable(keyValidator.validate(), valueValidator.validate()),
1042
+ getExample: function () { return "{ ".concat(keyValidator.getExample(), ": ").concat(valueValidator.getExample(), " }"); },
1043
+ getType: function () { return "{ ".concat(keyValidator.getType(), ": ").concat(valueValidator.getType(), " }"); },
1044
+ }); };
1045
+ export var indexableNumberValidator = function (keyValidator, valueValidator) { return ({
1046
+ validate: validateIndexable(keyValidator.validate(), valueValidator.validate()),
1047
+ getExample: function () { return "{ ".concat(keyValidator.getExample(), ": ").concat(valueValidator.getExample(), " }"); },
1048
+ getType: function () { return "{ ".concat(keyValidator.getType(), ": ").concat(valueValidator.getType(), " }"); },
1049
+ }); };
770
1050
  export var rejectionWithMessage = function (o) { return build_validator(function (v) { throw new Error((o === null || o === void 0 ? void 0 : o.errorMessage) || 'This field is not valid'); }, __assign(__assign({}, o), { isOptional: true, listOf: false })); };
771
- export var numberToDateValidator = indexableNumberValidator(numberValidator(), dateValidator());
772
- export var idStringToDateValidator = indexableValidator(mongoIdStringValidator(), dateValidator());
1051
+ export var numberToDateValidator = indexableNumberValidator(numberValidator, dateValidator);
1052
+ export var idStringToDateValidator = indexableValidator(mongoIdStringRequired, dateValidator);
773
1053
  // todo: move preference to FIELD_TYPES with drop-down option in user-facing forms
774
1054
  var FIELD_TYPES = ['string', 'number', 'email', 'phone', 'multiple_choice', 'file', 'signature'];
775
1055
  var VALIDATE_OPTIONS_FOR_FIELD_TYPES = {
776
1056
  'multiple_choice': {
777
- choices: listOfStringsValidator({ maxLength: 100, errorMessage: "Multiple choice options must be under 100 characters, and you must have at least one option." }),
778
- radio: booleanValidator({ errorMessage: "radio must be a boolean" }),
779
- other: booleanValidator({ isOptional: true, errorMessage: "other must be a boolean" }),
1057
+ choices: listOfStringsValidator,
1058
+ radio: booleanValidator,
1059
+ other: booleanValidatorOptional,
780
1060
  REQUIRED: ['choices', 'radio'],
781
1061
  }
782
1062
  };
@@ -819,17 +1099,17 @@ var isFormField = function (f, fieldOptions) {
819
1099
  if (!forUpdate && !field.type)
820
1100
  throw "field.type is required"; // fieldName otherwise given as 'field' in validation for every subfield
821
1101
  if (field.type)
822
- exactMatchValidator(FIELD_TYPES)(field.type);
1102
+ exactMatchValidator(FIELD_TYPES).validate(field.type);
823
1103
  if (!forUpdate && !field.title)
824
1104
  throw "field.title is required"; // fieldName otherwise given as 'field' in validation for every subfield
825
1105
  if (field.title) {
826
- field.title = stringValidator({
1106
+ field.title = stringValidator.validate({
827
1107
  maxLength: 100,
828
1108
  errorMessage: "field title is required and must not exceed 100 characters"
829
1109
  })(field.title);
830
1110
  }
831
1111
  if (!forUpdate || field.description !== undefined) { // don't overwrite description on update with ''
832
- field.description = stringValidator({
1112
+ field.description = stringValidator.validate({
833
1113
  isOptional: true,
834
1114
  maxLength: 500,
835
1115
  errorMessage: "field description must be under 500 characters"
@@ -853,7 +1133,7 @@ var isFormField = function (f, fieldOptions) {
853
1133
  if (validators[k] === undefined) {
854
1134
  throw new Error("Got unexpected option ".concat(k, " for field of type ").concat(INTERNAL_NAME_TO_DISPLAY_FIELD[field.type] || 'Text'));
855
1135
  }
856
- field.options[k] = validators[k](field.options[k]);
1136
+ field.options[k] = validators[k].validate(field.options[k]);
857
1137
  }
858
1138
  }
859
1139
  if (field.intakeField !== undefined) { // allow null to unset intake
@@ -870,58 +1150,59 @@ var isFormField = function (f, fieldOptions) {
870
1150
  // validate optional vs not at endpoint-level
871
1151
  export var formResponseAnswerValidator = orValidator({
872
1152
  email: objectValidator({
873
- type: exactMatchValidator(['email'])(),
874
- value: emailValidator({ isOptional: true, emptyStringOk: true }),
875
- })(),
1153
+ type: exactMatchValidator(['email']),
1154
+ value: emailValidatorOptional,
1155
+ }),
876
1156
  number: objectValidator({
877
- type: exactMatchValidator(['number'])(),
878
- value: numberValidator({ isOptional: true, emptyStringOk: true }),
879
- })(),
1157
+ type: exactMatchValidator(['number']),
1158
+ value: numberValidatorOptional,
1159
+ }),
880
1160
  rating: objectValidator({
881
- type: exactMatchValidator(['rating'])(),
882
- value: numberValidator({ isOptional: true, emptyStringOk: true }),
883
- })(),
1161
+ type: exactMatchValidator(['rating']),
1162
+ value: numberValidatorOptional,
1163
+ }),
884
1164
  phone: objectValidator({
885
- type: exactMatchValidator(['phone'])(),
886
- value: phoneValidator({ isOptional: true, emptyStringOk: true }),
887
- })(),
1165
+ type: exactMatchValidator(['phone']),
1166
+ value: phoneValidatorOptional,
1167
+ }),
888
1168
  string: objectValidator({
889
- type: exactMatchValidator(['string'])(),
890
- value: stringValidator5000({ isOptional: true, emptyStringOk: true }),
891
- })(),
1169
+ type: exactMatchValidator(['string']),
1170
+ value: stringValidator5000Optional,
1171
+ }),
892
1172
  date: objectValidator({
893
- type: exactMatchValidator(['date'])(),
894
- value: dateValidator({ isOptional: true, emptyStringOk: true }),
895
- })(),
1173
+ type: exactMatchValidator(['date']),
1174
+ value: dateValidatorOptional,
1175
+ }),
896
1176
  file: objectValidator({
897
- type: exactMatchValidator(['file'])(),
1177
+ type: exactMatchValidator(['file']),
898
1178
  value: objectValidator({
899
- name: stringValidator5000(),
900
- secureName: stringValidator250(),
901
- }, { emptyOk: false })({ isOptional: true }),
902
- })(),
1179
+ name: stringValidator5000,
1180
+ secureName: stringValidator250,
1181
+ }, { emptyOk: false, isOptional: true }),
1182
+ }),
903
1183
  multiple_choice: objectValidator({
904
- type: exactMatchValidator(['multiple_choice'])(),
905
- value: listOfStringsValidator({ isOptional: true, emptyListOk: true }),
906
- })(),
1184
+ type: exactMatchValidator(['multiple_choice']),
1185
+ value: listOfStringsValidatorEmptyOk,
1186
+ }),
907
1187
  ranking: objectValidator({
908
- type: exactMatchValidator(['ranking'])(),
909
- value: listOfStringsValidator({ isOptional: true, emptyListOk: true }),
910
- })(),
1188
+ type: exactMatchValidator(['ranking']),
1189
+ value: listOfStringsValidatorOptionalOrEmptyOk,
1190
+ }),
911
1191
  signature: objectValidator({
912
- type: exactMatchValidator(['signature'])(),
1192
+ type: exactMatchValidator(['signature']),
913
1193
  value: objectValidator({
914
- fullName: stringValidator250(),
915
- signed: booleanValidator(),
916
- }, { emptyOk: false })({ isOptional: true }),
917
- })(),
1194
+ fullName: stringValidator250,
1195
+ signed: booleanValidator,
1196
+ }, { emptyOk: false, isOptional: true }),
1197
+ }),
918
1198
  });
919
1199
  export var formResponseValidator = objectValidator({
920
1200
  fieldId: mongoIdStringRequired,
921
- fieldTitle: stringValidator5000(),
922
- answer: formResponseAnswerValidator(),
1201
+ fieldTitle: stringValidator5000,
1202
+ fieldDescription: stringValidator5000Optional,
1203
+ answer: formResponseAnswerValidator,
923
1204
  });
924
- export var formResponsesValidator = listValidator(formResponseValidator());
1205
+ export var formResponsesValidator = listValidator(formResponseValidator);
925
1206
  export var intakePhoneValidator = exactMatchValidator(['optional', 'required']);
926
1207
  export var formFieldValidator = function (options, fieldOptions) {
927
1208
  if (options === void 0) { options = {}; }
@@ -973,10 +1254,10 @@ var _CUD = {
973
1254
  export var CUD = Object.keys(_CUD);
974
1255
  export var CUDStringValidator = exactMatchValidator(CUD);
975
1256
  export var CUDValidator = objectValidator({
976
- create: booleanValidator({ isOptional: true }),
977
- update: booleanValidator({ isOptional: true }),
978
- delete: booleanValidator({ isOptional: true }),
979
- });
1257
+ create: booleanValidatorOptional,
1258
+ update: booleanValidatorOptional,
1259
+ delete: booleanValidatorOptional,
1260
+ }, { isOptional: true });
980
1261
  var _UNIT_OF_TIME = {
981
1262
  Days: '',
982
1263
  Hours: '',
@@ -987,58 +1268,58 @@ export var UNITS_OF_TIME = Object.keys(_UNIT_OF_TIME);
987
1268
  export var UnitOfTimeValidator = exactMatchValidator(UNITS_OF_TIME);
988
1269
  var WebhookSubscriptionValidatorObject = {};
989
1270
  for (var model in WEBHOOK_MODELS) {
990
- WebhookSubscriptionValidatorObject[model] = CUDValidator({ listOf: false, isOptional: true });
1271
+ WebhookSubscriptionValidatorObject[model] = CUDValidator;
991
1272
  }
992
1273
  export var WebhookSubscriptionValidator = objectValidator(WebhookSubscriptionValidatorObject, { throwOnUnrecognizedField: true });
993
1274
  export var sessionTypeValidator = exactMatchValidator(['user', 'enduser']);
994
1275
  export var listOfDisplayNameInfo = listValidator(objectValidator({
995
- fname: nameValidator(),
996
- lname: nameValidator(),
997
- id: listOfMongoIdStringValidator(),
998
- })());
1276
+ fname: nameValidator,
1277
+ lname: nameValidator,
1278
+ id: listOfMongoIdStringValidator,
1279
+ }));
999
1280
  export var attendeeInfoValidator = objectValidator({
1000
- AttendeeId: stringValidator(),
1001
- ExternalUserId: mongoIdStringValidator(),
1002
- JoinToken: stringValidator(),
1281
+ AttendeeId: stringValidator,
1282
+ ExternalUserId: mongoIdStringRequired,
1283
+ JoinToken: stringValidator,
1003
1284
  });
1004
1285
  export var attendeeValidator = objectValidator({
1005
- type: sessionTypeValidator(),
1006
- id: mongoIdStringValidator(),
1007
- info: attendeeInfoValidator(),
1286
+ type: sessionTypeValidator,
1287
+ id: mongoIdStringRequired,
1288
+ info: attendeeInfoValidator,
1008
1289
  });
1009
- export var listOfAttendeesValidator = listValidator(attendeeValidator());
1290
+ export var listOfAttendeesValidator = listValidator(attendeeValidator);
1010
1291
  export var meetingInfoValidator = objectValidator({
1011
- Meeting: objectAnyFieldsAnyValuesValidator(),
1292
+ Meeting: objectAnyFieldsAnyValuesValidator,
1012
1293
  });
1013
1294
  export var userIdentityValidator = objectValidator({
1014
- type: sessionTypeValidator(),
1015
- id: mongoIdStringValidator(),
1295
+ type: sessionTypeValidator,
1296
+ id: mongoIdStringRequired,
1016
1297
  });
1017
- export var listOfUserIndentitiesValidator = listValidator(userIdentityValidator());
1298
+ export var listOfUserIndentitiesValidator = listValidator(userIdentityValidator);
1018
1299
  export var chatAttachmentValidator = objectValidator({
1019
- type: exactMatchValidator(['image', 'video', 'file'])(),
1020
- secureName: stringValidator250(),
1300
+ type: exactMatchValidator(['image', 'video', 'file']),
1301
+ secureName: stringValidator250,
1021
1302
  });
1022
- export var listOfChatAttachmentsValidator = listValidatorEmptyOk(chatAttachmentValidator());
1303
+ export var listOfChatAttachmentsValidator = listValidatorEmptyOk(chatAttachmentValidator);
1023
1304
  export var meetingsListValidator = listValidator(objectValidator({
1024
- id: mongoIdStringValidator(),
1025
- updatedAt: stringValidator(),
1026
- status: meetingStatusValidator(),
1027
- })());
1305
+ id: mongoIdStringRequired,
1306
+ updatedAt: stringValidator,
1307
+ status: meetingStatusValidator,
1308
+ }));
1028
1309
  export var userDisplayInfoValidator = objectValidator({
1029
- id: mongoIdRequired,
1030
- createdAt: dateValidator(),
1031
- avatar: stringValidator(),
1032
- fname: nameValidator(),
1033
- lname: nameValidator(),
1034
- lastActive: dateValidator(),
1035
- lastLogout: dateValidator(),
1036
- email: emailValidator(),
1310
+ id: mongoIdStringRequired,
1311
+ createdAt: dateValidator,
1312
+ avatar: stringValidator,
1313
+ fname: nameValidator,
1314
+ lname: nameValidator,
1315
+ lastActive: dateValidator,
1316
+ lastLogout: dateValidator,
1317
+ email: emailValidator,
1037
1318
  });
1038
- export var meetingDisplayInfoValidator = indexableValidator(mongoIdStringRequired, userDisplayInfoValidator());
1319
+ export var meetingDisplayInfoValidator = indexableValidator(mongoIdStringRequired, userDisplayInfoValidator);
1039
1320
  export var chatRoomUserInfoValidator = objectAnyFieldsValidator(objectValidator({
1040
- unreadCount: nonNegNumberValidator(),
1041
- })());
1321
+ unreadCount: nonNegNumberValidator,
1322
+ }));
1042
1323
  var _AUTOMATION_ENDUSER_STATUS = {
1043
1324
  active: '',
1044
1325
  finished: '',
@@ -1073,129 +1354,136 @@ var _MESSAGE_TEMPLATE_MODES = {
1073
1354
  export var MESSAGE_TEMPLATE_MODES = Object.keys(_MESSAGE_TEMPLATE_MODES);
1074
1355
  export var messageTemplateModeValidator = exactMatchValidator(MESSAGE_TEMPLATE_MODES);
1075
1356
  var sharedReminderValidators = {
1076
- msBeforeStartTime: nonNegNumberValidator(),
1077
- didRemind: booleanValidator({ isOptional: true }),
1357
+ msBeforeStartTime: nonNegNumberValidator,
1358
+ didRemind: booleanValidatorOptional,
1078
1359
  };
1079
1360
  export var calendarEventReminderValidator = orValidator({
1080
- webhook: objectValidator(__assign({ info: objectValidator({}, { emptyOk: true })({ isOptional: true }), type: exactMatchValidator(['webhook'])() }, sharedReminderValidators))(),
1361
+ webhook: objectValidator(__assign({ info: objectValidator({}, { emptyOk: true, isOptional: true }), type: exactMatchValidator(['webhook']) }, sharedReminderValidators)),
1081
1362
  'add-to-journey': objectValidator(__assign({ info: objectValidator({
1082
- journeyId: mongoIdRequired,
1083
- })(), type: exactMatchValidator(['add-to-journey'])() }, sharedReminderValidators))(),
1363
+ journeyId: mongoIdStringRequired,
1364
+ }), type: exactMatchValidator(['add-to-journey']) }, sharedReminderValidators)),
1084
1365
  "enduser-notification": objectValidator(__assign({ info: objectValidator({
1085
- templateId: mongoIdOptional,
1086
- }, { emptyOk: true })(), type: exactMatchValidator(['enduser-notification'])() }, sharedReminderValidators))(),
1366
+ templateId: mongoIdStringOptional,
1367
+ }, { emptyOk: true }), type: exactMatchValidator(['enduser-notification']) }, sharedReminderValidators)),
1087
1368
  "user-notification": objectValidator(__assign({ info: objectValidator({
1088
- templateId: mongoIdOptional,
1089
- }, { emptyOk: true })(), type: exactMatchValidator(['user-notification'])() }, sharedReminderValidators))(),
1369
+ templateId: mongoIdStringOptional,
1370
+ }, { emptyOk: true }), type: exactMatchValidator(['user-notification']) }, sharedReminderValidators)),
1090
1371
  });
1091
- export var listOfCalendarEventRemindersValidator = listValidatorEmptyOk(calendarEventReminderValidator());
1372
+ export var listOfCalendarEventRemindersValidator = listValidatorEmptyOk(calendarEventReminderValidator);
1092
1373
  export var cancelConditionsValidator = listOfObjectsValidator({
1093
- type: exactMatchValidator(['formResponse'])(),
1374
+ type: exactMatchValidator(['formResponse']),
1094
1375
  info: objectValidator({
1095
1376
  automationStepId: mongoIdStringRequired,
1096
- }, { emptyOk: false })(),
1377
+ }, { emptyOk: false }),
1097
1378
  });
1379
+ export var cancelConditionsValidatorOptional = listValidatorOptionalOrEmptyOk(objectValidator({
1380
+ type: exactMatchValidator(['formResponse']),
1381
+ info: objectValidator({
1382
+ automationStepId: mongoIdStringRequired,
1383
+ }, { emptyOk: false }),
1384
+ }));
1098
1385
  var delayValidation = {
1099
1386
  automationStepId: mongoIdStringRequired,
1100
- delayInMS: nonNegNumberValidator(),
1101
- delay: nonNegNumberValidator(),
1102
- unit: UnitOfTimeValidator(),
1103
- cancelConditions: cancelConditionsValidator({ isOptional: true, emptyListOk: true, })
1387
+ delayInMS: nonNegNumberValidator,
1388
+ delay: nonNegNumberValidator,
1389
+ unit: UnitOfTimeValidator,
1390
+ cancelConditions: cancelConditionsValidatorOptional,
1104
1391
  };
1105
1392
  export var automationEventValidator = orValidator({
1106
1393
  formResponse: objectValidator({
1107
- type: exactMatchValidator(['formResponse'])(),
1394
+ type: exactMatchValidator(['formResponse']),
1108
1395
  info: objectValidator({
1109
- automationStepId: mongoIdStringValidator(),
1110
- }, { emptyOk: false })(),
1111
- })(),
1396
+ automationStepId: mongoIdStringRequired,
1397
+ }, { emptyOk: false }),
1398
+ }),
1112
1399
  afterAction: objectValidator({
1113
- type: exactMatchValidator(['afterAction'])(),
1114
- info: objectValidator(delayValidation, { emptyOk: false })(),
1115
- })(),
1400
+ type: exactMatchValidator(['afterAction']),
1401
+ info: objectValidator(delayValidation, { emptyOk: false }),
1402
+ }),
1116
1403
  formUnsubmitted: objectValidator({
1117
- type: exactMatchValidator(['formUnsubmitted'])(),
1118
- info: objectValidator(__assign(__assign({}, delayValidation), { automationStepId: mongoIdStringRequired }), { emptyOk: false })(),
1119
- })(),
1404
+ type: exactMatchValidator(['formUnsubmitted']),
1405
+ info: objectValidator(__assign(__assign({}, delayValidation), { automationStepId: mongoIdStringRequired }), { emptyOk: false }),
1406
+ }),
1120
1407
  onJourneyStart: objectValidator({
1121
- type: exactMatchValidator(['onJourneyStart'])(),
1122
- info: objectValidator({}, { emptyOk: true })(),
1123
- })(),
1408
+ type: exactMatchValidator(['onJourneyStart']),
1409
+ info: objectValidator({}, { emptyOk: true }),
1410
+ }),
1124
1411
  ticketCompleted: objectValidator({
1125
- type: exactMatchValidator(['ticketCompleted'])(),
1412
+ type: exactMatchValidator(['ticketCompleted']),
1126
1413
  info: objectValidator({
1127
1414
  automationStepId: mongoIdStringRequired,
1128
- closedForReason: stringValidator({ isOptional: true }),
1129
- }, { emptyOk: false })(),
1130
- })(),
1415
+ closedForReason: stringValidatorOptional,
1416
+ }, { emptyOk: false }),
1417
+ }),
1131
1418
  });
1132
- export var automationEventsValidator = listValidatorEmptyOk(automationEventValidator());
1419
+ export var automationEventsValidator = listValidatorEmptyOk(automationEventValidator);
1133
1420
  export var automationConditionValidator = orValidator({
1134
1421
  atJourneyState: objectValidator({
1135
- type: exactMatchValidator(['atJourneyState'])(),
1136
- info: objectValidator({ state: stringValidator100(), journeyId: mongoIdStringRequired }, { emptyOk: false })(),
1137
- })(),
1422
+ type: exactMatchValidator(['atJourneyState']),
1423
+ info: objectValidator({ state: stringValidator100, journeyId: mongoIdStringRequired }, { emptyOk: false }),
1424
+ }),
1138
1425
  });
1139
- export var listOfAutomationConditionsValidator = listValidatorEmptyOk(automationConditionValidator());
1426
+ export var listOfAutomationConditionsValidator = listValidatorEmptyOk(automationConditionValidator);
1140
1427
  var _SEND_FORM_CHANNELS = {
1141
1428
  Email: '',
1142
1429
  SMS: '',
1143
1430
  };
1144
1431
  export var SEND_FORM_CHANNELS = Object.keys(_SEND_FORM_CHANNELS);
1145
1432
  export var sendFormChannelValidator = exactMatchValidator(SEND_FORM_CHANNELS);
1433
+ export var sendFormChannelValidatorOptional = exactMatchValidatorOptional(SEND_FORM_CHANNELS);
1146
1434
  export var automationActionValidator = orValidator({
1147
1435
  setEnduserStatus: objectValidator({
1148
- type: exactMatchValidator(['setEnduserStatus'])(),
1149
- info: objectValidator({ status: stringValidator250() }, { emptyOk: false })(),
1150
- })(),
1436
+ type: exactMatchValidator(['setEnduserStatus']),
1437
+ info: objectValidator({ status: stringValidator250 }, { emptyOk: false }),
1438
+ }),
1151
1439
  sendEmail: objectValidator({
1152
- type: exactMatchValidator(['sendEmail'])(),
1153
- info: objectValidator({ senderId: mongoIdStringValidator(), templateId: mongoIdStringValidator() }, { emptyOk: false })(),
1154
- })(),
1440
+ type: exactMatchValidator(['sendEmail']),
1441
+ info: objectValidator({ senderId: mongoIdStringRequired, templateId: mongoIdStringRequired }, { emptyOk: false }),
1442
+ }),
1155
1443
  sendSMS: objectValidator({
1156
- type: exactMatchValidator(['sendSMS'])(),
1157
- info: objectValidator({ senderId: mongoIdStringValidator(), templateId: mongoIdStringValidator() }, { emptyOk: false })(),
1158
- })(),
1444
+ type: exactMatchValidator(['sendSMS']),
1445
+ info: objectValidator({ senderId: mongoIdStringRequired, templateId: mongoIdStringRequired }, { emptyOk: false }),
1446
+ }),
1159
1447
  sendForm: objectValidator({
1160
- type: exactMatchValidator(['sendForm'])(),
1448
+ type: exactMatchValidator(['sendForm']),
1161
1449
  info: objectValidator({
1162
- senderId: mongoIdStringValidator(),
1163
- formId: mongoIdStringValidator(),
1164
- channel: sendFormChannelValidator({ isOptional: true }),
1165
- }, { emptyOk: false })(),
1166
- })(),
1450
+ senderId: mongoIdStringRequired,
1451
+ formId: mongoIdStringRequired,
1452
+ channel: sendFormChannelValidatorOptional,
1453
+ }, { emptyOk: false }),
1454
+ }),
1167
1455
  createTicket: objectValidator({
1168
- type: exactMatchValidator(['createTicket'])(),
1456
+ type: exactMatchValidator(['createTicket']),
1169
1457
  info: objectValidator({
1170
- title: stringValidator({ isOptional: false }),
1458
+ title: stringValidatorOptional,
1171
1459
  assignmentStrategy: orValidator({
1172
1460
  'care-team-random': objectValidator({
1173
- type: exactMatchValidator(['care-team-random'])(),
1174
- info: objectValidator({}, { emptyOk: true })(),
1175
- })()
1176
- })(),
1177
- closeReasons: listOfStringsValidator({ isOptional: true, emptyListOk: true }),
1461
+ type: exactMatchValidator(['care-team-random']),
1462
+ info: objectValidator({}, { emptyOk: true }),
1463
+ })
1464
+ }),
1465
+ closeReasons: listOfStringsValidatorOptionalOrEmptyOk,
1178
1466
  defaultAssignee: mongoIdStringRequired,
1179
- }, { emptyOk: false })(),
1180
- })(),
1467
+ }, { emptyOk: false }),
1468
+ }),
1181
1469
  sendWebhook: objectValidator({
1182
- type: exactMatchValidator(['sendWebhook'])(),
1183
- info: objectValidator({ message: stringValidator5000() }, { emptyOk: false })(),
1184
- })(),
1470
+ type: exactMatchValidator(['sendWebhook']),
1471
+ info: objectValidator({ message: stringValidator5000 }, { emptyOk: false }),
1472
+ }),
1185
1473
  });
1186
1474
  export var relatedRecordValidator = objectValidator({
1187
- type: stringValidator100(),
1188
- id: mongoIdStringValidator(),
1475
+ type: stringValidator100,
1476
+ id: mongoIdStringRequired,
1189
1477
  creator: mongoIdStringOptional,
1190
1478
  });
1191
- export var listOfRelatedRecordsValidator = listValidatorEmptyOk(relatedRecordValidator());
1479
+ export var listOfRelatedRecordsValidator = listValidatorEmptyOk(relatedRecordValidator);
1192
1480
  export var searchOptionsValidator = objectValidator({
1193
- query: stringValidator100(),
1481
+ query: stringValidator100,
1194
1482
  });
1195
1483
  export var notificationPreferenceValidator = objectValidator({
1196
- email: booleanValidator({ isOptional: true }),
1484
+ email: booleanValidatorOptional,
1197
1485
  });
1198
- export var notificationPreferencesValidator = objectAnyFieldsValidator(notificationPreferenceValidator());
1486
+ export var notificationPreferencesValidator = objectAnyFieldsValidator(notificationPreferenceValidator);
1199
1487
  export var FHIRObservationCategoryValidator = exactMatchValidator(['vital-signs']);
1200
1488
  var _FHIR_OBSERVATION_STATUS_CODES = {
1201
1489
  "entered-in-error": '',
@@ -1210,37 +1498,37 @@ var _FHIR_OBSERVATION_STATUS_CODES = {
1210
1498
  export var FHIR_OBSERVATION_STATUS_CODES = Object.keys(_FHIR_OBSERVATION_STATUS_CODES);
1211
1499
  export var FHIRObservationStatusCodeValidator = exactMatchValidator(FHIR_OBSERVATION_STATUS_CODES);
1212
1500
  export var FHIRObservationValueValidator = objectValidator({
1213
- unit: stringValidator(),
1214
- value: numberValidator(),
1501
+ unit: stringValidator,
1502
+ value: numberValidator,
1215
1503
  });
1216
1504
  export var previousFormFieldValidator = orValidator({
1217
1505
  root: objectValidator({
1218
- type: exactMatchValidator(['root'])(),
1219
- info: objectValidator({}, { emptyOk: true })(),
1220
- })(),
1506
+ type: exactMatchValidator(['root']),
1507
+ info: objectValidator({}, { emptyOk: true }),
1508
+ }),
1221
1509
  "after": objectValidator({
1222
- type: exactMatchValidator(['after'])(),
1223
- info: objectValidator({ fieldId: mongoIdStringRequired }, { emptyOk: false })(),
1224
- })(),
1510
+ type: exactMatchValidator(['after']),
1511
+ info: objectValidator({ fieldId: mongoIdStringRequired }, { emptyOk: false }),
1512
+ }),
1225
1513
  "previousEquals": objectValidator({
1226
- type: exactMatchValidator(['previousEquals'])(),
1514
+ type: exactMatchValidator(['previousEquals']),
1227
1515
  info: objectValidator({
1228
1516
  fieldId: mongoIdStringRequired,
1229
- equals: stringValidator250(),
1230
- }, { emptyOk: false })(),
1231
- })(),
1517
+ equals: stringValidator250,
1518
+ }, { emptyOk: false }),
1519
+ }),
1232
1520
  });
1233
- export var previousFormFieldsValidator = listValidatorEmptyOk(previousFormFieldValidator());
1521
+ export var previousFormFieldsValidator = listValidatorEmptyOk(previousFormFieldValidator);
1234
1522
  export var portalSettingsValidator = objectValidator({});
1235
1523
  export var organizationThemeValidator = objectValidator({
1236
- logoURL: stringValidator250({ isOptional: true }),
1237
- themeColor: stringValidator250({ isOptional: true }),
1238
- name: stringValidator250(),
1239
- subdomain: stringValidator250(),
1240
- businessId: mongoIdRequired,
1241
- faviconURL: stringValidator250(),
1242
- customPortalURL: stringValidator250(),
1243
- portalSettings: portalSettingsValidator(),
1524
+ logoURL: stringValidatorOptional,
1525
+ themeColor: stringValidatorOptional,
1526
+ name: stringValidator250,
1527
+ subdomain: stringValidator250,
1528
+ businessId: mongoIdStringRequired,
1529
+ faviconURL: stringValidator250,
1530
+ customPortalURL: stringValidator250,
1531
+ portalSettings: portalSettingsValidator,
1244
1532
  });
1245
1533
  var _MANAGED_CONTENT_RECORD_TYPES = {
1246
1534
  Article: '',
@@ -1249,93 +1537,97 @@ var _MANAGED_CONTENT_RECORD_TYPES = {
1249
1537
  };
1250
1538
  export var MANAGED_CONTENT_RECORD_TYPES = Object.keys(_MANAGED_CONTENT_RECORD_TYPES);
1251
1539
  export var managedContentRecordTypeValidator = exactMatchValidator(MANAGED_CONTENT_RECORD_TYPES);
1252
- export var passwordValidator = function (o) { return build_validator(function (password) {
1253
- var _a, _b, _c, _d, _e, _f, _g, _h;
1254
- if (typeof password !== 'string') {
1255
- throw new Error("Password must be a string");
1256
- }
1257
- if (password.length < 8) {
1258
- throw new Error("Password must be at least 8 characters long");
1259
- }
1260
- if (((_b = (_a = password.match(/[a-z]/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) < 1 // 1 lowercase
1261
- || (((_d = (_c = password.match(/[A-Z]/g)) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) < 1 // 1 uppercase
1262
- && ((_f = (_e = password.match(/[0-9]/g)) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : 0) < 1 // 1 number
1263
- && ((_h = (_g = password.match(/[^a-zA-Z0-9]/g)) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0) < 1 // 1 special character
1264
- )) {
1265
- console.error('bad password regex');
1266
- throw new Error('Password must included 1 uppercase letter, 1 number, or 1 symbol');
1267
- }
1268
- return password;
1269
- }, __assign(__assign({}, o), { listOf: false, emptyStringOk: false })); };
1540
+ export var passwordValidator = {
1541
+ getExample: getExampleString,
1542
+ getType: getTypeString,
1543
+ validate: (function (o) { return build_validator(function (password) {
1544
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1545
+ if (typeof password !== 'string') {
1546
+ throw new Error("Password must be a string");
1547
+ }
1548
+ if (password.length < 8) {
1549
+ throw new Error("Password must be at least 8 characters long");
1550
+ }
1551
+ if (((_b = (_a = password.match(/[a-z]/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) < 1 // 1 lowercase
1552
+ || (((_d = (_c = password.match(/[A-Z]/g)) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) < 1 // 1 uppercase
1553
+ && ((_f = (_e = password.match(/[0-9]/g)) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : 0) < 1 // 1 number
1554
+ && ((_h = (_g = password.match(/[^a-zA-Z0-9]/g)) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0) < 1 // 1 special character
1555
+ )) {
1556
+ console.error('bad password regex');
1557
+ throw new Error('Password must included 1 uppercase letter, 1 number, or 1 symbol');
1558
+ }
1559
+ return password;
1560
+ }, __assign(__assign({}, o), { listOf: false, emptyStringOk: false })); }),
1561
+ };
1270
1562
  export var flowchartUIValidator = objectValidator({
1271
- x: numberValidator(),
1272
- y: numberValidator(),
1563
+ x: numberValidator,
1564
+ y: numberValidator,
1273
1565
  }, { emptyOk: true });
1274
1566
  export var integrationAuthenticationsValidator = objectValidator({
1275
- type: exactMatchValidator(['oauth2'])(),
1567
+ type: exactMatchValidator(['oauth2']),
1276
1568
  info: objectValidator({
1277
- access_token: stringValidator250(),
1278
- refresh_token: stringValidator250(),
1279
- scope: stringValidator5000(),
1280
- expiry_date: nonNegNumberValidator(),
1281
- token_type: exactMatchValidator(['Bearer'])(),
1282
- state: stringValidator250({ isOptional: true }),
1283
- email: emailValidator({ isOptional: true }),
1284
- })(),
1569
+ access_token: stringValidator250,
1570
+ refresh_token: stringValidator250,
1571
+ scope: stringValidator5000,
1572
+ expiry_date: nonNegNumberValidator,
1573
+ token_type: exactMatchValidator(['Bearer']),
1574
+ state: stringValidatorOptional,
1575
+ email: emailValidatorOptional,
1576
+ }),
1285
1577
  });
1286
1578
  export var formFieldOptionsValidator = objectValidator({
1287
- choices: listOfStringsValidator({ isOptional: true }),
1288
- from: numberValidator({ isOptional: true }),
1289
- to: numberValidator({ isOptional: true }),
1290
- other: stringValidator250({ isOptional: true }),
1291
- radio: booleanValidator({ isOptional: true }),
1579
+ choices: listOfStringsValidatorOptionalOrEmptyOk,
1580
+ from: numberValidatorOptional,
1581
+ to: numberValidatorOptional,
1582
+ other: stringValidatorOptional,
1583
+ radio: booleanValidatorOptional,
1292
1584
  });
1293
1585
  export var blockValidator = orValidator({
1294
1586
  h1: objectValidator({
1295
- type: exactMatchValidator(['h1'])(),
1587
+ type: exactMatchValidator(['h1']),
1296
1588
  info: objectValidator({
1297
- text: stringValidator5000({ emptyStringOk: true }),
1298
- })(),
1299
- })(),
1589
+ text: stringValidator5000EmptyOkay,
1590
+ }),
1591
+ }),
1300
1592
  h2: objectValidator({
1301
- type: exactMatchValidator(['h2'])(),
1593
+ type: exactMatchValidator(['h2']),
1302
1594
  info: objectValidator({
1303
- text: stringValidator5000({ emptyStringOk: true }),
1304
- })(),
1305
- })(),
1595
+ text: stringValidator5000EmptyOkay,
1596
+ }),
1597
+ }),
1306
1598
  html: objectValidator({
1307
- type: exactMatchValidator(['html'])(),
1599
+ type: exactMatchValidator(['html']),
1308
1600
  info: objectValidator({
1309
- html: stringValidator25000({ emptyStringOk: true }),
1310
- })(),
1311
- })(),
1601
+ html: stringValidator25000EmptyOkay,
1602
+ }),
1603
+ }),
1312
1604
  image: objectValidator({
1313
- type: exactMatchValidator(['image'])(),
1605
+ type: exactMatchValidator(['image']),
1314
1606
  info: objectValidator({
1315
- link: stringValidator5000({ emptyStringOk: true }),
1316
- name: stringValidator250({ isOptional: true, emptyStringOk: true }),
1317
- height: nonNegNumberValidator({ isOptional: true }),
1318
- width: nonNegNumberValidator({ isOptional: true }),
1319
- })(),
1320
- })(),
1607
+ link: stringValidator5000EmptyOkay,
1608
+ name: stringValidatorOptional,
1609
+ height: numberValidatorOptional,
1610
+ width: numberValidatorOptional,
1611
+ }),
1612
+ }),
1321
1613
  pdf: objectValidator({
1322
- type: exactMatchValidator(['pdf'])(),
1614
+ type: exactMatchValidator(['pdf']),
1323
1615
  info: objectValidator({
1324
- link: stringValidator5000({ emptyStringOk: true }),
1325
- name: stringValidator250({ isOptional: true, emptyStringOk: true }),
1326
- height: nonNegNumberValidator({ isOptional: true }),
1327
- width: nonNegNumberValidator({ isOptional: true }),
1328
- })(),
1329
- })(),
1616
+ link: stringValidator5000EmptyOkay,
1617
+ name: stringValidatorOptional,
1618
+ height: numberValidatorOptional,
1619
+ width: numberValidatorOptional,
1620
+ }),
1621
+ }),
1330
1622
  youtube: objectValidator({
1331
- type: exactMatchValidator(['youtube'])(),
1623
+ type: exactMatchValidator(['youtube']),
1332
1624
  info: objectValidator({
1333
- link: stringValidator5000({ emptyStringOk: true }),
1334
- name: stringValidator250({ isOptional: true, emptyStringOk: true }),
1335
- height: nonNegNumberValidator({ isOptional: true }),
1336
- width: nonNegNumberValidator({ isOptional: true }),
1337
- })(),
1338
- })(),
1625
+ link: stringValidator5000EmptyOkay,
1626
+ name: stringValidatorOptional,
1627
+ height: numberValidatorOptional,
1628
+ width: numberValidatorOptional,
1629
+ }),
1630
+ }),
1339
1631
  });
1340
1632
  var _BLOCK_TYPES = {
1341
1633
  h1: '',
@@ -1348,7 +1640,7 @@ var _BLOCK_TYPES = {
1348
1640
  export var BLOCK_TYPES = Object.keys(_BLOCK_TYPES);
1349
1641
  export var blockTypeValidator = exactMatchValidator(BLOCK_TYPES);
1350
1642
  export var is_block_type = function (type) { return BLOCK_TYPES.includes(type); };
1351
- export var blocksValidator = listValidatorEmptyOk(blockValidator());
1643
+ export var blocksValidator = listValidatorEmptyOk(blockValidator);
1352
1644
  var _DATABASE_RECORD_FIELD_TYPES = {
1353
1645
  "string-long": '',
1354
1646
  number: '',
@@ -1374,30 +1666,30 @@ export var is_database_record_field_type = function (type) { return DATABASE_REC
1374
1666
  // })
1375
1667
  // structure as above instead if need unique label or additional config based on type
1376
1668
  export var databaseFieldValidator = objectValidator({
1377
- type: databaseRecordFieldTypeValidator(),
1378
- label: stringValidator250(),
1669
+ type: databaseRecordFieldTypeValidator,
1670
+ label: stringValidator250,
1379
1671
  });
1380
- export var databaseFieldsValidator = listValidator(databaseFieldValidator());
1672
+ export var databaseFieldsValidator = listValidator(databaseFieldValidator);
1381
1673
  export var databaseRecordValueValidator = orValidator({
1382
1674
  string: objectValidator({
1383
- type: exactMatchValidator(['string'])(),
1384
- value: stringValidator1000(),
1385
- })(),
1675
+ type: exactMatchValidator(['string']),
1676
+ value: stringValidator1000,
1677
+ }),
1386
1678
  'string-long': objectValidator({
1387
- type: exactMatchValidator(['string-long'])(),
1388
- value: stringValidator5000(),
1389
- })(),
1679
+ type: exactMatchValidator(['string-long']),
1680
+ value: stringValidator5000,
1681
+ }),
1390
1682
  'number': objectValidator({
1391
- type: exactMatchValidator(['number'])(),
1392
- value: numberValidator(),
1393
- })(),
1683
+ type: exactMatchValidator(['number']),
1684
+ value: numberValidator,
1685
+ }),
1394
1686
  });
1395
- export var databaseRecordValuesValidator = listValidator(databaseRecordValueValidator());
1687
+ export var databaseRecordValuesValidator = listValidator(databaseRecordValueValidator);
1396
1688
  export var organizationAccessValidator = objectValidator({
1397
- create: booleanValidator({ isOptional: true }),
1398
- update: booleanValidator({ isOptional: true }),
1399
- read: booleanValidator({ isOptional: true }),
1400
- delete: booleanValidator({ isOptional: true }),
1689
+ create: booleanValidatorOptional,
1690
+ update: booleanValidatorOptional,
1691
+ read: booleanValidatorOptional,
1692
+ delete: booleanValidatorOptional,
1401
1693
  });
1402
1694
  var _PORTAL_PAGES = {
1403
1695
  "Care Plan": true,
@@ -1405,36 +1697,44 @@ var _PORTAL_PAGES = {
1405
1697
  Education: true,
1406
1698
  Home: true,
1407
1699
  Community: true,
1700
+ Communications: true,
1408
1701
  };
1409
1702
  export var PORTAL_PAGES = Object.keys(_PORTAL_PAGES);
1410
1703
  export var portalPageValidator = exactMatchValidator(PORTAL_PAGES);
1411
1704
  export var portalBlockValidator = orValidator({
1412
1705
  carePlan: objectValidator({
1413
- type: exactMatchValidator(['carePlan'])(),
1414
- info: objectValidator({}, { emptyOk: true })()
1415
- })(),
1706
+ type: exactMatchValidator(['carePlan']),
1707
+ info: objectValidator({}, { emptyOk: true })
1708
+ }),
1416
1709
  education: objectValidator({
1417
- type: exactMatchValidator(['education'])(),
1418
- info: objectValidator({}, { emptyOk: true })()
1419
- })(),
1710
+ type: exactMatchValidator(['education']),
1711
+ info: objectValidator({}, { emptyOk: true })
1712
+ }),
1420
1713
  careTeam: objectValidator({
1421
- type: exactMatchValidator(['careTeam'])(),
1714
+ type: exactMatchValidator(['careTeam']),
1422
1715
  info: objectValidator({
1423
- title: stringValidator(),
1716
+ title: stringValidator,
1424
1717
  // members: listValidatorEmptyOk(
1425
1718
  // objectValidator<CareTeamMemberPortalCustomizationInfo>({
1426
1719
  // title: stringValidator(),
1427
1720
  // role: stringValidator({ isOptional: true }),
1428
1721
  // })()
1429
1722
  // )()
1430
- })()
1431
- })(),
1723
+ })
1724
+ }),
1725
+ text: objectValidator({
1726
+ type: exactMatchValidator(['text']),
1727
+ info: objectValidator({
1728
+ text: stringValidator5000,
1729
+ })
1730
+ }),
1432
1731
  });
1433
- export var portalBlocksValidator = listValidatorEmptyOk(portalBlockValidator());
1732
+ export var portalBlocksValidator = listValidatorEmptyOk(portalBlockValidator);
1434
1733
  var _PORTAL_BLOCK_TYPES = {
1435
1734
  carePlan: '',
1436
1735
  careTeam: '',
1437
1736
  education: '',
1737
+ text: '',
1438
1738
  };
1439
1739
  export var PORTAL_BLOCK_TYPES = Object.keys(_PORTAL_BLOCK_TYPES);
1440
1740
  export var portalTypeValidator = exactMatchValidator(PORTAL_BLOCK_TYPES);
@@ -1442,11 +1742,89 @@ export var enduserTaskForEventValidator = objectValidator({
1442
1742
  id: mongoIdStringRequired,
1443
1743
  enduserId: mongoIdStringRequired,
1444
1744
  });
1445
- export var enduserTasksForEventValidator = listValidatorEmptyOk(enduserTaskForEventValidator());
1745
+ export var enduserTasksForEventValidator = listValidatorEmptyOk(enduserTaskForEventValidator);
1446
1746
  export var enduserFormResponseForEventValidator = objectValidator({
1447
1747
  enduserId: mongoIdStringRequired,
1448
1748
  formId: mongoIdStringRequired,
1449
- accessCode: stringValidator1000(),
1749
+ accessCode: stringValidator1000,
1750
+ });
1751
+ export var enduserFormResponsesForEventValidator = listValidatorEmptyOk(enduserFormResponseForEventValidator);
1752
+ export var VALID_STATES = [
1753
+ "AK",
1754
+ "AL",
1755
+ "AR",
1756
+ "AS",
1757
+ "AZ",
1758
+ "CA",
1759
+ "CO",
1760
+ "CT",
1761
+ "DC",
1762
+ "DE",
1763
+ "FL",
1764
+ "GA",
1765
+ "GU",
1766
+ "HI",
1767
+ "IA",
1768
+ "ID",
1769
+ "IL",
1770
+ "IN",
1771
+ "KS",
1772
+ "KY",
1773
+ "LA",
1774
+ "MA",
1775
+ "MD",
1776
+ "ME",
1777
+ "MI",
1778
+ "MN",
1779
+ "MO",
1780
+ "MP",
1781
+ "MS",
1782
+ "MT",
1783
+ "NC",
1784
+ "ND",
1785
+ "NE",
1786
+ "NH",
1787
+ "NJ",
1788
+ "NM",
1789
+ "NV",
1790
+ "NY",
1791
+ "OH",
1792
+ "OK",
1793
+ "OR",
1794
+ "PA",
1795
+ "PR",
1796
+ "RI",
1797
+ "SC",
1798
+ "SD",
1799
+ "TN",
1800
+ "TX",
1801
+ "UM",
1802
+ "UT",
1803
+ "VA",
1804
+ "VI",
1805
+ "VT",
1806
+ "WA",
1807
+ "WI",
1808
+ "WV",
1809
+ "WY",
1810
+ ];
1811
+ export var stateValidator = exactMatchValidator(VALID_STATES);
1812
+ export var stateCredentialValidator = objectValidator({
1813
+ expiresAt: dateValidatorOptional,
1814
+ state: stateValidator,
1815
+ });
1816
+ export var stateCredentialsValidator = listValidatorEmptyOk(stateCredentialValidator);
1817
+ export var availabilityBlockValidator = objectValidator({
1818
+ durationInMinutes: nonNegNumberValidator,
1819
+ startTimeInMS: nonNegNumberValidator,
1820
+ userId: mongoIdStringRequired,
1821
+ });
1822
+ export var availabilityBlocksValidator = listValidatorEmptyOk(availabilityBlockValidator);
1823
+ export var weeklyAvailabilityValidator = objectValidator({
1824
+ dayOfWeekStartingSundayIndexedByZero: nonNegNumberValidator,
1825
+ endTimeInMinutes: nonNegNumberValidator,
1826
+ startTimeInMinutes: nonNegNumberValidator,
1450
1827
  });
1451
- export var enduserFormResponsesForEventValidator = listValidatorEmptyOk(enduserFormResponseForEventValidator());
1828
+ export var weeklyAvailabilitiesValidator = listValidatorEmptyOk(weeklyAvailabilityValidator);
1829
+ export var timezoneValidator = exactMatchValidator(Object.keys(TIMEZONES));
1452
1830
  //# sourceMappingURL=validation.js.map