@tellescope/validation 1.4.0 → 1.4.3

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,6 +9,17 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
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
+ };
12
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;
@@ -16,6 +27,11 @@ export var isDate = v.isDate, isEmail = v.isEmail, isMobilePhone = v.isMobilePho
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,53 +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 getExampleString; },
434
+ getType: function () { return getTypeString; }
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')
364
- return true;
365
- if (boolean === 'false')
366
- return false;
367
- if (typeof boolean !== 'boolean') {
368
- throw new Error(options.errorMessage || "Invalid boolean");
369
- }
370
- return boolean;
371
- }, __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,
372
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,
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 true; },
534
+ getType: function () { return "boolean"; },
535
+ }); };
536
+ export var booleanValidator = booleanValidatorBuilder({});
537
+ export var booleanValidatorOptional = booleanValidatorBuilder({ isOptional: true });
373
538
  export var escapeMongoId = function (mongoId) {
374
539
  if (typeof mongoId !== 'string')
375
540
  throw new Error('Expecting string id');
@@ -378,14 +543,22 @@ export var escapeMongoId = function (mongoId) {
378
543
  }
379
544
  return mongoId;
380
545
  };
381
- export var mongoIdValidator = function (o) {
382
- if (o === void 0) { o = {}; }
383
- return build_validator(function (s) { return to_object_id(escapeMongoId(s)); }, __assign(__assign({}, optionsWithDefaults(o)), { maxLength: 100, listOf: false }));
384
- };
385
- export var mongoIdStringValidator = function (o) {
386
- if (o === void 0) { o = {}; }
387
- 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,
388
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
+ }); };
389
562
  export var nullValidator = function (o) {
390
563
  if (o === void 0) { o = {}; }
391
564
  return build_validator(function (v) {
@@ -394,198 +567,289 @@ export var nullValidator = function (o) {
394
567
  return v;
395
568
  }, __assign(__assign({}, o), { listOf: false }));
396
569
  };
397
- export var mongoIdRequired = mongoIdValidator();
398
- export var mongoIdOptional = mongoIdValidator({ isOptional: true });
399
- export var mongoIdStringRequired = mongoIdStringValidator();
400
- export var mongoIdStringOptional = mongoIdStringValidator({ isOptional: true });
401
- export var listOfMongoIdValidator = listValidator(mongoIdValidator());
402
- export var listOfMongoIdStringValidator = listValidator(mongoIdStringValidator());
403
- 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);
404
577
  export var first_letter_capitalized = function (s) {
405
578
  if (s === void 0) { s = ''; }
406
579
  return s.charAt(0).toUpperCase() + s.slice(1);
407
580
  };
408
581
  export var escape_name = function (namestring) { return namestring.replace(/[^a-zA-Z0-9-_ /.]/, '').substring(0, 100); };
409
582
  // enforces first-letter capitalization
410
- export var nameValidator = function (options) {
411
- if (options === void 0) { options = {}; }
412
- return build_validator(function (name) {
413
- if (typeof name !== 'string')
414
- throw new Error('Expecting string value');
415
- name = escape_name(name);
416
- if (!name)
417
- throw new Error("Invalid name");
418
- return first_letter_capitalized(name);
419
- }, __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,
420
597
  };
421
- export var emailValidator = function (options) {
422
- if (options === void 0) { options = {}; }
423
- return build_validator(function (email) {
424
- if (typeof email !== 'string')
425
- throw new Error('Expecting string value');
426
- if (!isEmail(email)) {
427
- throw new Error(options.errorMessage || "Invalid email");
428
- }
429
- return email.toLowerCase();
430
- }, __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,
431
612
  };
432
- export var emailValidatorEmptyOkay = function (options) {
433
- if (options === void 0) { options = {}; }
434
- return build_validator(function (email) {
435
- if (typeof email !== 'string')
436
- throw new Error('Expecting string value');
437
- if (!isEmail(email)) {
438
- throw new Error(options.errorMessage || "Invalid email");
439
- }
440
- return email.toLowerCase();
441
- }, __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 lower; },
663
+ getType: getTypeNumber,
664
+ });
442
665
  };
443
- export var numberValidatorBuilder = function (r) { return function (options) {
444
- if (options === void 0) { options = {}; }
445
- options.isNumber = true;
446
- return build_validator(function (number) {
447
- number = Number(number); // ok to throw error!
448
- if (typeof number !== "number" || isNaN(number)) {
449
- throw new Error(options.errorMessage || "Not a valid number");
450
- }
451
- if (!r)
452
- return number;
453
- if (!(number >= r.lower && number <= r.upper)) {
454
- throw new Error(options.errorMessage || "Not a valid number for [".concat(r.lower, "-").concat(r.upper, "]"));
455
- }
456
- return number;
457
- }, __assign(__assign({}, options), { listOf: false }));
458
- }; };
459
666
  export var nonNegNumberValidator = numberValidatorBuilder({ lower: 0, upper: 10000000000000 }); // max is 2286 in UTC MS
460
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
461
669
  export var fileSizeValidator = numberValidatorBuilder({ lower: 0, upper: MAX_FILE_SIZE });
462
- export var dateValidator = function (options) {
463
- if (options === void 0) { options = {}; }
464
- return build_validator(function (date) {
465
- if (isDate(date))
466
- throw new Error(options.errorMessage || "Invalid date");
467
- return new Date(date);
468
- }, __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"; },
469
681
  };
470
- export var exactMatchValidator = function (matches) { return function (o) {
471
- if (o === void 0) { o = {}; }
472
- return build_validator(function (match) {
473
- if (matches.filter(function (m) { return m === match; }).length === 0) {
474
- throw new Error("Value must match one of ".concat(matches));
475
- }
476
- return match;
477
- }, __assign(__assign({}, o), { listOf: false }));
478
- }; };
479
- export var exactMatchListValidator = function (matches) { return function (o) {
480
- if (o === void 0) { o = {}; }
481
- return build_validator(function (match) {
482
- if (matches.filter(function (m) { return m === match; }).length === 0) {
483
- throw new Error("Value must match one of ".concat(matches));
484
- }
485
- return match;
486
- }, __assign(__assign({}, o), { listOf: true }));
487
- }; };
488
- export var journeysValidator = function (options) {
489
- if (options === void 0) { options = {}; }
490
- return build_validator(function (journeys) {
491
- if (typeof journeys !== 'object') {
492
- throw new Error('Expecting an object');
493
- }
494
- var mIdValidator = mongoIdValidator();
495
- var stateValidator = stringValidator({ isOptional: true, maxLength: 75, errorMessage: "Journey state names may not exceed 75 characters" });
496
- for (var j in journeys) {
497
- mIdValidator(j);
498
- journeys[j] = stateValidator(journeys[j]);
499
- }
500
- return journeys;
501
- }, __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 () {
738
+ var _a;
739
+ return (_a = {}, _a[EXAMPLE_OBJECT_ID] = "status", _a);
740
+ },
741
+ getType: function () { return ({ string: "string" }); },
502
742
  };
503
743
  export var escape_phone_number = function (p) {
504
744
  if (p === void 0) { p = ''; }
505
745
  return p.replace(/[^\d+]/g, '');
506
746
  };
507
- export var phoneValidator = function (options) {
508
- if (options === void 0) { options = {}; }
509
- return build_validator(function (phone) {
510
- if (typeof phone !== "string")
511
- throw new Error("Expecting phone to be string but got ".concat(phone));
512
- var escaped = escape_phone_number(phone);
513
- if (escaped.length < 10)
514
- throw new Error("Phone number must be at least 10 digits");
515
- escaped = escaped.startsWith('+') ? escaped
516
- : escaped.length === 10 ? '+1' + escaped // assume US country code for now
517
- : "+" + escaped; // assume country code provided, but missing leading +
518
- if (!isMobilePhone(escaped, 'any', { strictMode: true })) {
519
- throw "Invalid phone number";
520
- }
521
- return escaped;
522
- }, __assign(__assign({}, options), { maxLength: 25, listOf: false }));
747
+ export var phoneValidator = {
748
+ validate: function (options) {
749
+ if (options === void 0) { options = {}; }
750
+ return build_validator(function (phone) {
751
+ if (typeof phone !== "string")
752
+ throw new Error("Expecting phone to be string but got ".concat(phone));
753
+ var escaped = escape_phone_number(phone);
754
+ if (escaped.length < 10)
755
+ throw new Error("Phone number must be at least 10 digits");
756
+ escaped = escaped.startsWith('+') ? escaped
757
+ : escaped.length === 10 ? '+1' + escaped // assume US country code for now
758
+ : "+" + escaped; // assume country code provided, but missing leading +
759
+ if (!isMobilePhone(escaped, 'any', { strictMode: true })) {
760
+ throw "Invalid phone number";
761
+ }
762
+ return escaped;
763
+ }, __assign(__assign({}, options), { maxLength: 25, listOf: false }));
764
+ },
765
+ getExample: function () { return "+15555555555"; },
766
+ getType: getTypeString,
523
767
  };
524
- export var phoneValidatorEmptyOkay = function (options) {
525
- if (options === void 0) { options = {}; }
526
- return build_validator(function (phone) {
527
- if (typeof phone !== "string")
528
- throw new Error("Expecting phone to be string but got ".concat(phone));
529
- var escaped = escape_phone_number(phone);
530
- if (escaped.length < 10)
531
- throw new Error("Phone number must be at least 10 digits");
532
- escaped = escaped.startsWith('+') ? escaped
533
- : escaped.length === 10 ? '+1' + escaped // assume US country code for now
534
- : "+" + escaped; // assume country code provided, but missing leading +
535
- if (!isMobilePhone(escaped, 'any', { strictMode: true })) {
536
- throw "Invalid phone number";
537
- }
538
- return escaped;
539
- }, __assign(__assign({}, options), { maxLength: 25, listOf: false, emptyStringOk: true }));
768
+ export var phoneValidatorOptional = {
769
+ validate: function (options) {
770
+ if (options === void 0) { options = {}; }
771
+ return build_validator(function (phone) {
772
+ if (typeof phone !== "string")
773
+ throw new Error("Expecting phone to be string but got ".concat(phone));
774
+ var escaped = escape_phone_number(phone);
775
+ if (escaped.length < 10)
776
+ throw new Error("Phone number must be at least 10 digits");
777
+ escaped = escaped.startsWith('+') ? escaped
778
+ : escaped.length === 10 ? '+1' + escaped // assume US country code for now
779
+ : "+" + escaped; // assume country code provided, but missing leading +
780
+ if (!isMobilePhone(escaped, 'any', { strictMode: true })) {
781
+ throw "Invalid phone number";
782
+ }
783
+ return escaped;
784
+ }, __assign(__assign({}, options), { maxLength: 25, listOf: false, isOptional: true, emptyStringOk: true }));
785
+ },
786
+ getExample: function () { return "+15555555555"; },
787
+ getType: getTypeString,
540
788
  };
541
- export var fileTypeValidator = function (options) {
542
- if (options === void 0) { options = {}; }
543
- return build_validator(function (s) {
544
- if (typeof s !== 'string')
545
- throw new Error("fileType must be a string");
546
- if (!isMimeType(s))
547
- throw new Error("".concat(s, " is not a valid file type"));
548
- return s;
549
- }, __assign(__assign({}, options), { listOf: false }));
550
- };
551
- export var urlValidator = function (options) {
552
- if (options === void 0) { options = {}; }
553
- return build_validator(function (s) {
554
- if (typeof s !== 'string')
555
- throw new Error("URL must be a string");
556
- if (!isURL(s))
557
- throw new Error("".concat(s, " is not a valid URL"));
558
- return s;
559
- }, __assign(__assign({}, options), { listOf: false }));
560
- };
561
- export var safeBase64Validator = function (options) {
562
- if (options === void 0) { options = {}; }
563
- return build_validator(function (sb64) {
564
- if (typeof sb64 !== 'string')
565
- throw new Error("Expecting string");
566
- // https://stackoverflow.com/questions/12930007/how-to-validate-base64-string-using-regex-in-javascript
567
- // regex with = + and / replaced as get_random_base64_URL_safe
568
- if (!/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2}..|[A-Za-z0-9_-]{3}.)?$/.test(sb64)) {
569
- throw "Invalid safe base64";
570
- }
571
- return sb64;
572
- }, __assign(__assign({}, options), { listOf: false }));
789
+ export var fileTypeValidator = {
790
+ validate: function (options) {
791
+ if (options === void 0) { options = {}; }
792
+ return build_validator(function (s) {
793
+ if (typeof s !== 'string')
794
+ throw new Error("fileType must be a string");
795
+ if (!isMimeType(s))
796
+ throw new Error("".concat(s, " is not a valid file type"));
797
+ return s;
798
+ }, __assign(__assign({}, options), { listOf: false }));
799
+ },
800
+ getExample: function () { return 'text/plain'; },
801
+ getType: getTypeString,
573
802
  };
574
- export var subdomainValidator = function (options) {
575
- if (options === void 0) { options = {}; }
576
- return build_validator(function (subdomain) {
577
- if (typeof subdomain !== 'string')
578
- throw new Error("Expecting string value");
579
- subdomain = subdomain.toLowerCase();
580
- if (subdomain.startsWith('-')) {
581
- subdomain = subdomain.substring(1);
582
- }
583
- while (subdomain.endsWith('-')) {
584
- subdomain = subdomain.substring(0, subdomain.length - 1);
585
- }
586
- subdomain = subdomain.replace(/[^a-zA-Z\d-]/g, '');
587
- return subdomain;
588
- }, __assign(__assign({}, options), { maxLength: 50, listOf: false }));
803
+ export var urlValidator = {
804
+ validate: function (options) {
805
+ if (options === void 0) { options = {}; }
806
+ return build_validator(function (s) {
807
+ if (typeof s !== 'string')
808
+ throw new Error("URL must be a string");
809
+ if (!isURL(s))
810
+ throw new Error("".concat(s, " is not a valid URL"));
811
+ return s;
812
+ }, __assign(__assign({}, options), { listOf: false }));
813
+ },
814
+ getExample: function () { return '"https://www.tellescope.com"'; },
815
+ getType: getTypeString,
816
+ };
817
+ export var safeBase64Validator = {
818
+ validate: function (options) {
819
+ if (options === void 0) { options = {}; }
820
+ return build_validator(function (sb64) {
821
+ if (typeof sb64 !== 'string')
822
+ throw new Error("Expecting string");
823
+ // https://stackoverflow.com/questions/12930007/how-to-validate-base64-string-using-regex-in-javascript
824
+ // regex with = + and / replaced as get_random_base64_URL_safe
825
+ if (!/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2}..|[A-Za-z0-9_-]{3}.)?$/.test(sb64)) {
826
+ throw "Invalid safe base64";
827
+ }
828
+ return sb64;
829
+ }, __assign(__assign({}, options), { listOf: false }));
830
+ },
831
+ getExample: function () { return '129vjas0fkj1234jgfmnaef'; },
832
+ getType: getTypeString,
833
+ };
834
+ export var subdomainValidator = {
835
+ validate: function (options) {
836
+ if (options === void 0) { options = {}; }
837
+ return build_validator(function (subdomain) {
838
+ if (typeof subdomain !== 'string')
839
+ throw new Error("Expecting string value");
840
+ subdomain = subdomain.toLowerCase();
841
+ if (subdomain.startsWith('-')) {
842
+ subdomain = subdomain.substring(1);
843
+ }
844
+ while (subdomain.endsWith('-')) {
845
+ subdomain = subdomain.substring(0, subdomain.length - 1);
846
+ }
847
+ subdomain = subdomain.replace(/[^a-zA-Z\d-]/g, '');
848
+ return subdomain;
849
+ }, __assign(__assign({}, options), { maxLength: 50, listOf: false }));
850
+ },
851
+ getExample: function () { return 'example'; },
852
+ getType: getTypeString,
589
853
  };
590
854
  // export const fileResponseValidator: EscapeBuilder<FileResponse> = (options={}) => build_validator(
591
855
  // (file: any) => {
@@ -599,14 +863,14 @@ export var subdomainValidator = function (options) {
599
863
  // { ...options, isObject: true, listOf: false }
600
864
  // )
601
865
  export var fileResponseValidator = objectValidator({
602
- type: exactMatchValidator(['file'])(),
603
- name: stringValidator({ shouldTruncate: true, maxLength: 250 }),
604
- secureName: stringValidator250(),
866
+ type: exactMatchValidator(['file']),
867
+ name: stringValidator1000,
868
+ secureName: stringValidator250,
605
869
  });
606
870
  export var signatureResponseValidator = objectValidator({
607
- type: exactMatchValidator(['signature'])(),
608
- fullName: stringValidator({ maxLength: 100 }),
609
- signed: booleanValidator(),
871
+ type: exactMatchValidator(['signature']),
872
+ fullName: stringValidator100,
873
+ signed: booleanValidator,
610
874
  });
611
875
  var DEFAULT_ENDUSER_FIELDS = [
612
876
  '_id', 'email', 'phone', 'fname', 'lname', 'journeys', 'tags', 'preference'
@@ -636,26 +900,28 @@ var _FORM_FIELD_TYPES = {
636
900
  export var FORM_FIELD_TYPES = Object.keys(_FORM_FIELD_TYPES);
637
901
  export var formFieldTypeValidator = exactMatchValidator(FORM_FIELD_TYPES);
638
902
  export var FORM_FIELD_VALIDATORS_BY_TYPE = {
639
- 'string': stringValidator({ maxLength: 5000, emptyStringOk: true, errorMessage: "Response must not exceed 5000 characters" }),
640
- 'number': numberValidator({ errorMessage: "Response must be a number" }),
641
- 'email': emailValidator(),
642
- // @ts-ignore -- backwards compatibility with old field name for email
643
- 'userEmail': emailValidator(),
644
- 'phone': phoneValidator(),
645
- 'phoneNumber': phoneValidator(),
903
+ 'string': stringValidator.validate({ maxLength: 5000, emptyStringOk: true, errorMessage: "Response must not exceed 5000 characters" }),
904
+ 'number': numberValidator.validate({ errorMessage: "Response must be a number" }),
905
+ 'email': emailValidator.validate(),
906
+ 'userEmail': emailValidator.validate(),
907
+ 'phone': phoneValidator.validate(),
908
+ 'phoneNumber': phoneValidator.validate(),
909
+ "date": dateValidator.validate(),
910
+ "ranking": listOfStringsValidator.validate(),
911
+ "rating": numberValidator.validate(),
646
912
  // fileInfo: FileResponse
647
913
  'file': function (fileInfo, _, isOptional) {
648
914
  if (isOptional && (!fileInfo || object_is_empty(fileInfo))) {
649
915
  return { type: 'file', secureName: null };
650
916
  }
651
- return fileResponseValidator()(fileInfo);
917
+ return fileResponseValidator.validate()(fileInfo);
652
918
  },
653
919
  // sigInfo: SignatureResponse
654
920
  'signature': function (sigInfo, _, isOptional) {
655
921
  if (isOptional && (!sigInfo || object_is_empty(sigInfo))) {
656
922
  return { type: 'signature', signed: null };
657
923
  }
658
- return signatureResponseValidator()(sigInfo);
924
+ return signatureResponseValidator.validate()(sigInfo);
659
925
  },
660
926
  // choiceInfo: { indexes: [], otherText?: string }
661
927
  'multiple_choice': function (choiceInfo, fieldOptions, isOptional) {
@@ -684,81 +950,86 @@ export var FORM_FIELD_VALIDATORS_BY_TYPE = {
684
950
  return parsed;
685
951
  },
686
952
  };
687
- export var fieldsValidator = function (options) {
688
- if (options === void 0) { options = {}; }
689
- return build_validator(function (fields) {
690
- if (!is_object(fields))
691
- throw new Error("Expecting an object");
692
- for (var k in fields) {
693
- if (DEFAULT_ENDUSER_FIELDS.includes(k))
694
- throw new Error("key ".concat(k, " conflicts with a built-in field."));
695
- if (k.startsWith('_'))
696
- throw new Error("Fields that start with '_' are not allowed");
697
- if (is_whitespace(k)) {
698
- delete fields[k];
699
- continue;
700
- }
701
- if (k.length > 32)
702
- throw new Error("key ".concat(k, " is greater than 32 characters"));
703
- var val = fields[k];
704
- if (typeof val === 'string') {
705
- if (val.length > 512)
706
- fields[k] = val.substring(0, 512);
707
- continue;
708
- }
709
- else if (typeof val === 'number' || val === null || typeof val === 'boolean') {
710
- continue; // nothing to restrict on number type yet
711
- }
712
- else if (typeof val === 'object') {
713
- if (JSON.stringify(val).length > 1024)
714
- throw new Error("object value for key ".concat(k, " exceeds the maximum length of 1024 characters in string representation"));
715
- // previous restricted structure for fields object
716
- // try {
717
- // if (val.type && typeof val.type === 'string') { // form responses can be stored as custom fields (form responses is simple array)
718
- // FORM_FIELD_VALIDATORS_BY_TYPE[val.type as keyof typeof FORM_FIELD_VALIDATORS_BY_TYPE](val, undefined as never, undefined as never)
719
- // continue
720
- // }
721
- // if (val.length && typeof val.length === 'number') { // array of strings is ok too, (inclusive of multiple-choice responses)
722
- // if (val.find((s: any) => typeof s !== 'string') !== undefined) {
723
- // throw new Error('List must contain only strings')
724
- // }
725
- // continue
726
- // }
727
- // if (val.value === undefined) throw new Error(`value field is undefined for key ${k}`)
728
- // if (JSON.stringify(val).length > 1024) throw new Error(`object value for key ${k} exceeds the maximum length of 1024 characters in string representation`)
729
- // const escaped = { value: val.value } as Indexable // create new object to omit unrecognized fields
730
- // escaped.title = val.title // optional
731
- // escaped.description = val.description // optional
732
- // fields[k] = escaped
733
- // } catch(err) {
734
- // throw new Error(`object value is invalid JSON for key ${k}`)
735
- // }
736
- }
737
- else {
738
- throw new Error("Expecting value to be a string or object but got ".concat(typeof val, " for key {k}"));
953
+ export var fieldsValidator = {
954
+ validate: function (options) {
955
+ if (options === void 0) { options = {}; }
956
+ return build_validator(function (fields) {
957
+ if (!is_object(fields))
958
+ throw new Error("Expecting an object");
959
+ for (var k in fields) {
960
+ if (DEFAULT_ENDUSER_FIELDS.includes(k))
961
+ throw new Error("key ".concat(k, " conflicts with a built-in field."));
962
+ if (k.startsWith('_'))
963
+ throw new Error("Fields that start with '_' are not allowed");
964
+ if (is_whitespace(k)) {
965
+ delete fields[k];
966
+ continue;
967
+ }
968
+ if (k.length > 32)
969
+ throw new Error("key ".concat(k, " is greater than 32 characters"));
970
+ var val = fields[k];
971
+ if (typeof val === 'string') {
972
+ if (val.length > 512)
973
+ fields[k] = val.substring(0, 512);
974
+ continue;
975
+ }
976
+ else if (typeof val === 'number' || val === null || typeof val === 'boolean') {
977
+ continue; // nothing to restrict on number type yet
978
+ }
979
+ else if (typeof val === 'object') {
980
+ if (JSON.stringify(val).length > 1024)
981
+ throw new Error("object value for key ".concat(k, " exceeds the maximum length of 1024 characters in string representation"));
982
+ // previous restricted structure for fields object
983
+ // try {
984
+ // if (val.type && typeof val.type === 'string') { // form responses can be stored as custom fields (form responses is simple array)
985
+ // FORM_FIELD_VALIDATORS_BY_TYPE[val.type as keyof typeof FORM_FIELD_VALIDATORS_BY_TYPE](val, undefined as never, undefined as never)
986
+ // continue
987
+ // }
988
+ // if (val.length && typeof val.length === 'number') { // array of strings is ok too, (inclusive of multiple-choice responses)
989
+ // if (val.find((s: any) => typeof s !== 'string') !== undefined) {
990
+ // throw new Error('List must contain only strings')
991
+ // }
992
+ // continue
993
+ // }
994
+ // if (val.value === undefined) throw new Error(`value field is undefined for key ${k}`)
995
+ // if (JSON.stringify(val).length > 1024) throw new Error(`object value for key ${k} exceeds the maximum length of 1024 characters in string representation`)
996
+ // const escaped = { value: val.value } as Indexable // create new object to omit unrecognized fields
997
+ // escaped.title = val.title // optional
998
+ // escaped.description = val.description // optional
999
+ // fields[k] = escaped
1000
+ // } catch(err) {
1001
+ // throw new Error(`object value is invalid JSON for key ${k}`)
1002
+ // }
1003
+ }
1004
+ else {
1005
+ throw new Error("Expecting value to be a string or object but got ".concat(typeof val, " for key {k}"));
1006
+ }
739
1007
  }
740
- }
741
- return fields;
742
- }, __assign(__assign({}, options), { isObject: true, listOf: false }));
1008
+ return fields;
1009
+ }, __assign(__assign({}, options), { isObject: true, listOf: false }));
1010
+ },
1011
+ getExample: function () { return "{}"; },
1012
+ getType: function () { return "{}"; },
743
1013
  };
744
1014
  export var preferenceValidator = exactMatchValidator(['email', 'sms', 'call', 'chat']);
745
1015
  export var updateOptionsValidator = objectValidator({
746
- replaceObjectFields: booleanValidator({ isOptional: true }),
747
- });
1016
+ replaceObjectFields: booleanValidatorOptional,
1017
+ }, { isOptional: true });
748
1018
  export var journeyStatePriorityValidator = exactMatchValidator(["Disengaged", "N/A", "Engaged"]);
749
1019
  export var journeyStateValidator = objectValidator({
750
- name: stringValidator100(),
751
- priority: journeyStatePriorityValidator(),
752
- description: stringValidator({ isOptional: true }),
753
- requiresFollowup: booleanValidator({ isOptional: true }),
1020
+ name: stringValidator100,
1021
+ priority: journeyStatePriorityValidator,
1022
+ description: stringValidatorOptional,
1023
+ requiresFollowup: booleanValidatorOptional, // deprecated
754
1024
  });
755
- export var journeyStateUpdateValidator = objectValidator({
756
- name: stringValidator100({ isOptional: true }),
757
- priority: journeyStatePriorityValidator({ isOptional: true }),
758
- description: stringValidator({ isOptional: true }),
759
- requiresFollowup: booleanValidator({ isOptional: true }),
760
- });
761
- export var journeyStatesValidator = listValidator(journeyStateValidator());
1025
+ // deprecated
1026
+ // export const journeyStateUpdateValidator = objectValidator<JourneyState>({
1027
+ // name: stringValidator100({ isOptional: true }),
1028
+ // priority: journeyStatePriorityValidator({ isOptional: true }),
1029
+ // description: stringValidator({ isOptional: true }),
1030
+ // requiresFollowup: booleanValidator({ isOptional: true }),
1031
+ // })
1032
+ export var journeyStatesValidator = listValidator(journeyStateValidator);
762
1033
  export var emailEncodingValidator = exactMatchValidator(['', 'base64']);
763
1034
  export var validateIndexable = function (keyValidator, valueValidator) { return function (o) { return build_validator(function (v) {
764
1035
  if (!is_object(v))
@@ -769,18 +1040,26 @@ export var validateIndexable = function (keyValidator, valueValidator) { return
769
1040
  }
770
1041
  return validated;
771
1042
  }, __assign(__assign({}, o), { isObject: true, listOf: false })); }; };
772
- export var indexableValidator = function (keyValidator, valueValidator) { return (validateIndexable(keyValidator, valueValidator)); };
773
- export var indexableNumberValidator = function (keyValidator, valueValidator) { return (validateIndexable(keyValidator, valueValidator)); };
1043
+ export var indexableValidator = function (keyValidator, valueValidator) { return ({
1044
+ validate: validateIndexable(keyValidator.validate(), valueValidator.validate()),
1045
+ getExample: function () { return "{ ".concat(keyValidator.getExample(), ": ").concat(valueValidator.getExample(), " }"); },
1046
+ getType: function () { return "{ ".concat(keyValidator.getType(), ": ").concat(valueValidator.getType(), " }"); },
1047
+ }); };
1048
+ export var indexableNumberValidator = function (keyValidator, valueValidator) { return ({
1049
+ validate: validateIndexable(keyValidator.validate(), valueValidator.validate()),
1050
+ getExample: function () { return "{ ".concat(keyValidator.getExample(), ": ").concat(valueValidator.getExample(), " }"); },
1051
+ getType: function () { return "{ ".concat(keyValidator.getType(), ": ").concat(valueValidator.getType(), " }"); },
1052
+ }); };
774
1053
  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 })); };
775
- export var numberToDateValidator = indexableNumberValidator(numberValidator(), dateValidator());
776
- export var idStringToDateValidator = indexableValidator(mongoIdStringValidator(), dateValidator());
1054
+ export var numberToDateValidator = indexableNumberValidator(numberValidator, dateValidator);
1055
+ export var idStringToDateValidator = indexableValidator(mongoIdStringRequired, dateValidator);
777
1056
  // todo: move preference to FIELD_TYPES with drop-down option in user-facing forms
778
1057
  var FIELD_TYPES = ['string', 'number', 'email', 'phone', 'multiple_choice', 'file', 'signature'];
779
1058
  var VALIDATE_OPTIONS_FOR_FIELD_TYPES = {
780
1059
  'multiple_choice': {
781
- choices: listOfStringsValidator({ maxLength: 100, errorMessage: "Multiple choice options must be under 100 characters, and you must have at least one option." }),
782
- radio: booleanValidator({ errorMessage: "radio must be a boolean" }),
783
- other: booleanValidator({ isOptional: true, errorMessage: "other must be a boolean" }),
1060
+ choices: listOfStringsValidator,
1061
+ radio: booleanValidator,
1062
+ other: booleanValidatorOptional,
784
1063
  REQUIRED: ['choices', 'radio'],
785
1064
  }
786
1065
  };
@@ -823,17 +1102,17 @@ var isFormField = function (f, fieldOptions) {
823
1102
  if (!forUpdate && !field.type)
824
1103
  throw "field.type is required"; // fieldName otherwise given as 'field' in validation for every subfield
825
1104
  if (field.type)
826
- exactMatchValidator(FIELD_TYPES)(field.type);
1105
+ exactMatchValidator(FIELD_TYPES).validate(field.type);
827
1106
  if (!forUpdate && !field.title)
828
1107
  throw "field.title is required"; // fieldName otherwise given as 'field' in validation for every subfield
829
1108
  if (field.title) {
830
- field.title = stringValidator({
1109
+ field.title = stringValidator.validate({
831
1110
  maxLength: 100,
832
1111
  errorMessage: "field title is required and must not exceed 100 characters"
833
1112
  })(field.title);
834
1113
  }
835
1114
  if (!forUpdate || field.description !== undefined) { // don't overwrite description on update with ''
836
- field.description = stringValidator({
1115
+ field.description = stringValidator.validate({
837
1116
  isOptional: true,
838
1117
  maxLength: 500,
839
1118
  errorMessage: "field description must be under 500 characters"
@@ -857,7 +1136,7 @@ var isFormField = function (f, fieldOptions) {
857
1136
  if (validators[k] === undefined) {
858
1137
  throw new Error("Got unexpected option ".concat(k, " for field of type ").concat(INTERNAL_NAME_TO_DISPLAY_FIELD[field.type] || 'Text'));
859
1138
  }
860
- field.options[k] = validators[k](field.options[k]);
1139
+ field.options[k] = validators[k].validate(field.options[k]);
861
1140
  }
862
1141
  }
863
1142
  if (field.intakeField !== undefined) { // allow null to unset intake
@@ -874,58 +1153,59 @@ var isFormField = function (f, fieldOptions) {
874
1153
  // validate optional vs not at endpoint-level
875
1154
  export var formResponseAnswerValidator = orValidator({
876
1155
  email: objectValidator({
877
- type: exactMatchValidator(['email'])(),
878
- value: emailValidator({ isOptional: true, emptyStringOk: true }),
879
- })(),
1156
+ type: exactMatchValidator(['email']),
1157
+ value: emailValidatorOptional,
1158
+ }),
880
1159
  number: objectValidator({
881
- type: exactMatchValidator(['number'])(),
882
- value: numberValidator({ isOptional: true, emptyStringOk: true }),
883
- })(),
1160
+ type: exactMatchValidator(['number']),
1161
+ value: numberValidatorOptional,
1162
+ }),
884
1163
  rating: objectValidator({
885
- type: exactMatchValidator(['rating'])(),
886
- value: numberValidator({ isOptional: true, emptyStringOk: true }),
887
- })(),
1164
+ type: exactMatchValidator(['rating']),
1165
+ value: numberValidatorOptional,
1166
+ }),
888
1167
  phone: objectValidator({
889
- type: exactMatchValidator(['phone'])(),
890
- value: phoneValidator({ isOptional: true, emptyStringOk: true }),
891
- })(),
1168
+ type: exactMatchValidator(['phone']),
1169
+ value: phoneValidatorOptional,
1170
+ }),
892
1171
  string: objectValidator({
893
- type: exactMatchValidator(['string'])(),
894
- value: stringValidator5000({ isOptional: true, emptyStringOk: true }),
895
- })(),
1172
+ type: exactMatchValidator(['string']),
1173
+ value: stringValidator5000Optional,
1174
+ }),
896
1175
  date: objectValidator({
897
- type: exactMatchValidator(['date'])(),
898
- value: dateValidator({ isOptional: true, emptyStringOk: true }),
899
- })(),
1176
+ type: exactMatchValidator(['date']),
1177
+ value: dateValidatorOptional,
1178
+ }),
900
1179
  file: objectValidator({
901
- type: exactMatchValidator(['file'])(),
1180
+ type: exactMatchValidator(['file']),
902
1181
  value: objectValidator({
903
- name: stringValidator5000(),
904
- secureName: stringValidator250(),
905
- }, { emptyOk: false })({ isOptional: true }),
906
- })(),
1182
+ name: stringValidator5000,
1183
+ secureName: stringValidator250,
1184
+ }, { emptyOk: false, isOptional: true }),
1185
+ }),
907
1186
  multiple_choice: objectValidator({
908
- type: exactMatchValidator(['multiple_choice'])(),
909
- value: listOfStringsValidator({ isOptional: true, emptyListOk: true }),
910
- })(),
1187
+ type: exactMatchValidator(['multiple_choice']),
1188
+ value: listOfStringsValidatorEmptyOk,
1189
+ }),
911
1190
  ranking: objectValidator({
912
- type: exactMatchValidator(['ranking'])(),
913
- value: listOfStringsValidator({ isOptional: true, emptyListOk: true }),
914
- })(),
1191
+ type: exactMatchValidator(['ranking']),
1192
+ value: listOfStringsValidatorOptionalOrEmptyOk,
1193
+ }),
915
1194
  signature: objectValidator({
916
- type: exactMatchValidator(['signature'])(),
1195
+ type: exactMatchValidator(['signature']),
917
1196
  value: objectValidator({
918
- fullName: stringValidator250(),
919
- signed: booleanValidator(),
920
- }, { emptyOk: false })({ isOptional: true }),
921
- })(),
1197
+ fullName: stringValidator250,
1198
+ signed: booleanValidator,
1199
+ }, { emptyOk: false, isOptional: true }),
1200
+ }),
922
1201
  });
923
1202
  export var formResponseValidator = objectValidator({
924
1203
  fieldId: mongoIdStringRequired,
925
- fieldTitle: stringValidator5000(),
926
- answer: formResponseAnswerValidator(),
1204
+ fieldTitle: stringValidator5000,
1205
+ fieldDescription: stringValidator5000Optional,
1206
+ answer: formResponseAnswerValidator,
927
1207
  });
928
- export var formResponsesValidator = listValidator(formResponseValidator());
1208
+ export var formResponsesValidator = listValidator(formResponseValidator);
929
1209
  export var intakePhoneValidator = exactMatchValidator(['optional', 'required']);
930
1210
  export var formFieldValidator = function (options, fieldOptions) {
931
1211
  if (options === void 0) { options = {}; }
@@ -977,10 +1257,10 @@ var _CUD = {
977
1257
  export var CUD = Object.keys(_CUD);
978
1258
  export var CUDStringValidator = exactMatchValidator(CUD);
979
1259
  export var CUDValidator = objectValidator({
980
- create: booleanValidator({ isOptional: true }),
981
- update: booleanValidator({ isOptional: true }),
982
- delete: booleanValidator({ isOptional: true }),
983
- });
1260
+ create: booleanValidatorOptional,
1261
+ update: booleanValidatorOptional,
1262
+ delete: booleanValidatorOptional,
1263
+ }, { isOptional: true });
984
1264
  var _UNIT_OF_TIME = {
985
1265
  Days: '',
986
1266
  Hours: '',
@@ -991,58 +1271,58 @@ export var UNITS_OF_TIME = Object.keys(_UNIT_OF_TIME);
991
1271
  export var UnitOfTimeValidator = exactMatchValidator(UNITS_OF_TIME);
992
1272
  var WebhookSubscriptionValidatorObject = {};
993
1273
  for (var model in WEBHOOK_MODELS) {
994
- WebhookSubscriptionValidatorObject[model] = CUDValidator({ listOf: false, isOptional: true });
1274
+ WebhookSubscriptionValidatorObject[model] = CUDValidator;
995
1275
  }
996
1276
  export var WebhookSubscriptionValidator = objectValidator(WebhookSubscriptionValidatorObject, { throwOnUnrecognizedField: true });
997
1277
  export var sessionTypeValidator = exactMatchValidator(['user', 'enduser']);
998
1278
  export var listOfDisplayNameInfo = listValidator(objectValidator({
999
- fname: nameValidator(),
1000
- lname: nameValidator(),
1001
- id: listOfMongoIdStringValidator(),
1002
- })());
1279
+ fname: nameValidator,
1280
+ lname: nameValidator,
1281
+ id: listOfMongoIdStringValidator,
1282
+ }));
1003
1283
  export var attendeeInfoValidator = objectValidator({
1004
- AttendeeId: stringValidator(),
1005
- ExternalUserId: mongoIdStringValidator(),
1006
- JoinToken: stringValidator(),
1284
+ AttendeeId: stringValidator,
1285
+ ExternalUserId: mongoIdStringRequired,
1286
+ JoinToken: stringValidator,
1007
1287
  });
1008
1288
  export var attendeeValidator = objectValidator({
1009
- type: sessionTypeValidator(),
1010
- id: mongoIdStringValidator(),
1011
- info: attendeeInfoValidator(),
1289
+ type: sessionTypeValidator,
1290
+ id: mongoIdStringRequired,
1291
+ info: attendeeInfoValidator,
1012
1292
  });
1013
- export var listOfAttendeesValidator = listValidator(attendeeValidator());
1293
+ export var listOfAttendeesValidator = listValidator(attendeeValidator);
1014
1294
  export var meetingInfoValidator = objectValidator({
1015
- Meeting: objectAnyFieldsAnyValuesValidator(),
1295
+ Meeting: objectAnyFieldsAnyValuesValidator,
1016
1296
  });
1017
1297
  export var userIdentityValidator = objectValidator({
1018
- type: sessionTypeValidator(),
1019
- id: mongoIdStringValidator(),
1298
+ type: sessionTypeValidator,
1299
+ id: mongoIdStringRequired,
1020
1300
  });
1021
- export var listOfUserIndentitiesValidator = listValidator(userIdentityValidator());
1301
+ export var listOfUserIndentitiesValidator = listValidator(userIdentityValidator);
1022
1302
  export var chatAttachmentValidator = objectValidator({
1023
- type: exactMatchValidator(['image', 'video', 'file'])(),
1024
- secureName: stringValidator250(),
1303
+ type: exactMatchValidator(['image', 'video', 'file']),
1304
+ secureName: stringValidator250,
1025
1305
  });
1026
- export var listOfChatAttachmentsValidator = listValidatorEmptyOk(chatAttachmentValidator());
1306
+ export var listOfChatAttachmentsValidator = listValidatorEmptyOk(chatAttachmentValidator);
1027
1307
  export var meetingsListValidator = listValidator(objectValidator({
1028
- id: mongoIdStringValidator(),
1029
- updatedAt: stringValidator(),
1030
- status: meetingStatusValidator(),
1031
- })());
1308
+ id: mongoIdStringRequired,
1309
+ updatedAt: stringValidator,
1310
+ status: meetingStatusValidator,
1311
+ }));
1032
1312
  export var userDisplayInfoValidator = objectValidator({
1033
- id: mongoIdRequired,
1034
- createdAt: dateValidator(),
1035
- avatar: stringValidator(),
1036
- fname: nameValidator(),
1037
- lname: nameValidator(),
1038
- lastActive: dateValidator(),
1039
- lastLogout: dateValidator(),
1040
- email: emailValidator(),
1313
+ id: mongoIdStringRequired,
1314
+ createdAt: dateValidator,
1315
+ avatar: stringValidator,
1316
+ fname: nameValidator,
1317
+ lname: nameValidator,
1318
+ lastActive: dateValidator,
1319
+ lastLogout: dateValidator,
1320
+ email: emailValidator,
1041
1321
  });
1042
- export var meetingDisplayInfoValidator = indexableValidator(mongoIdStringRequired, userDisplayInfoValidator());
1322
+ export var meetingDisplayInfoValidator = indexableValidator(mongoIdStringRequired, userDisplayInfoValidator);
1043
1323
  export var chatRoomUserInfoValidator = objectAnyFieldsValidator(objectValidator({
1044
- unreadCount: nonNegNumberValidator(),
1045
- })());
1324
+ unreadCount: nonNegNumberValidator,
1325
+ }));
1046
1326
  var _AUTOMATION_ENDUSER_STATUS = {
1047
1327
  active: '',
1048
1328
  finished: '',
@@ -1077,129 +1357,136 @@ var _MESSAGE_TEMPLATE_MODES = {
1077
1357
  export var MESSAGE_TEMPLATE_MODES = Object.keys(_MESSAGE_TEMPLATE_MODES);
1078
1358
  export var messageTemplateModeValidator = exactMatchValidator(MESSAGE_TEMPLATE_MODES);
1079
1359
  var sharedReminderValidators = {
1080
- msBeforeStartTime: nonNegNumberValidator(),
1081
- didRemind: booleanValidator({ isOptional: true }),
1360
+ msBeforeStartTime: nonNegNumberValidator,
1361
+ didRemind: booleanValidatorOptional,
1082
1362
  };
1083
1363
  export var calendarEventReminderValidator = orValidator({
1084
- webhook: objectValidator(__assign({ info: objectValidator({}, { emptyOk: true })({ isOptional: true }), type: exactMatchValidator(['webhook'])() }, sharedReminderValidators))(),
1364
+ webhook: objectValidator(__assign({ info: objectValidator({}, { emptyOk: true, isOptional: true }), type: exactMatchValidator(['webhook']) }, sharedReminderValidators)),
1085
1365
  'add-to-journey': objectValidator(__assign({ info: objectValidator({
1086
- journeyId: mongoIdRequired,
1087
- })(), type: exactMatchValidator(['add-to-journey'])() }, sharedReminderValidators))(),
1366
+ journeyId: mongoIdStringRequired,
1367
+ }), type: exactMatchValidator(['add-to-journey']) }, sharedReminderValidators)),
1088
1368
  "enduser-notification": objectValidator(__assign({ info: objectValidator({
1089
- templateId: mongoIdOptional,
1090
- }, { emptyOk: true })(), type: exactMatchValidator(['enduser-notification'])() }, sharedReminderValidators))(),
1369
+ templateId: mongoIdStringOptional,
1370
+ }, { emptyOk: true }), type: exactMatchValidator(['enduser-notification']) }, sharedReminderValidators)),
1091
1371
  "user-notification": objectValidator(__assign({ info: objectValidator({
1092
- templateId: mongoIdOptional,
1093
- }, { emptyOk: true })(), type: exactMatchValidator(['user-notification'])() }, sharedReminderValidators))(),
1372
+ templateId: mongoIdStringOptional,
1373
+ }, { emptyOk: true }), type: exactMatchValidator(['user-notification']) }, sharedReminderValidators)),
1094
1374
  });
1095
- export var listOfCalendarEventRemindersValidator = listValidatorEmptyOk(calendarEventReminderValidator());
1375
+ export var listOfCalendarEventRemindersValidator = listValidatorEmptyOk(calendarEventReminderValidator);
1096
1376
  export var cancelConditionsValidator = listOfObjectsValidator({
1097
- type: exactMatchValidator(['formResponse'])(),
1377
+ type: exactMatchValidator(['formResponse']),
1098
1378
  info: objectValidator({
1099
1379
  automationStepId: mongoIdStringRequired,
1100
- }, { emptyOk: false })(),
1380
+ }, { emptyOk: false }),
1101
1381
  });
1382
+ export var cancelConditionsValidatorOptional = listValidatorOptionalOrEmptyOk(objectValidator({
1383
+ type: exactMatchValidator(['formResponse']),
1384
+ info: objectValidator({
1385
+ automationStepId: mongoIdStringRequired,
1386
+ }, { emptyOk: false }),
1387
+ }));
1102
1388
  var delayValidation = {
1103
1389
  automationStepId: mongoIdStringRequired,
1104
- delayInMS: nonNegNumberValidator(),
1105
- delay: nonNegNumberValidator(),
1106
- unit: UnitOfTimeValidator(),
1107
- cancelConditions: cancelConditionsValidator({ isOptional: true, emptyListOk: true, })
1390
+ delayInMS: nonNegNumberValidator,
1391
+ delay: nonNegNumberValidator,
1392
+ unit: UnitOfTimeValidator,
1393
+ cancelConditions: cancelConditionsValidatorOptional,
1108
1394
  };
1109
1395
  export var automationEventValidator = orValidator({
1110
1396
  formResponse: objectValidator({
1111
- type: exactMatchValidator(['formResponse'])(),
1397
+ type: exactMatchValidator(['formResponse']),
1112
1398
  info: objectValidator({
1113
- automationStepId: mongoIdStringValidator(),
1114
- }, { emptyOk: false })(),
1115
- })(),
1399
+ automationStepId: mongoIdStringRequired,
1400
+ }, { emptyOk: false }),
1401
+ }),
1116
1402
  afterAction: objectValidator({
1117
- type: exactMatchValidator(['afterAction'])(),
1118
- info: objectValidator(delayValidation, { emptyOk: false })(),
1119
- })(),
1403
+ type: exactMatchValidator(['afterAction']),
1404
+ info: objectValidator(delayValidation, { emptyOk: false }),
1405
+ }),
1120
1406
  formUnsubmitted: objectValidator({
1121
- type: exactMatchValidator(['formUnsubmitted'])(),
1122
- info: objectValidator(__assign(__assign({}, delayValidation), { automationStepId: mongoIdStringRequired }), { emptyOk: false })(),
1123
- })(),
1407
+ type: exactMatchValidator(['formUnsubmitted']),
1408
+ info: objectValidator(__assign(__assign({}, delayValidation), { automationStepId: mongoIdStringRequired }), { emptyOk: false }),
1409
+ }),
1124
1410
  onJourneyStart: objectValidator({
1125
- type: exactMatchValidator(['onJourneyStart'])(),
1126
- info: objectValidator({}, { emptyOk: true })(),
1127
- })(),
1411
+ type: exactMatchValidator(['onJourneyStart']),
1412
+ info: objectValidator({}, { emptyOk: true }),
1413
+ }),
1128
1414
  ticketCompleted: objectValidator({
1129
- type: exactMatchValidator(['ticketCompleted'])(),
1415
+ type: exactMatchValidator(['ticketCompleted']),
1130
1416
  info: objectValidator({
1131
1417
  automationStepId: mongoIdStringRequired,
1132
- closedForReason: stringValidator({ isOptional: true }),
1133
- }, { emptyOk: false })(),
1134
- })(),
1418
+ closedForReason: stringValidatorOptional,
1419
+ }, { emptyOk: false }),
1420
+ }),
1135
1421
  });
1136
- export var automationEventsValidator = listValidatorEmptyOk(automationEventValidator());
1422
+ export var automationEventsValidator = listValidatorEmptyOk(automationEventValidator);
1137
1423
  export var automationConditionValidator = orValidator({
1138
1424
  atJourneyState: objectValidator({
1139
- type: exactMatchValidator(['atJourneyState'])(),
1140
- info: objectValidator({ state: stringValidator100(), journeyId: mongoIdStringRequired }, { emptyOk: false })(),
1141
- })(),
1425
+ type: exactMatchValidator(['atJourneyState']),
1426
+ info: objectValidator({ state: stringValidator100, journeyId: mongoIdStringRequired }, { emptyOk: false }),
1427
+ }),
1142
1428
  });
1143
- export var listOfAutomationConditionsValidator = listValidatorEmptyOk(automationConditionValidator());
1429
+ export var listOfAutomationConditionsValidator = listValidatorEmptyOk(automationConditionValidator);
1144
1430
  var _SEND_FORM_CHANNELS = {
1145
1431
  Email: '',
1146
1432
  SMS: '',
1147
1433
  };
1148
1434
  export var SEND_FORM_CHANNELS = Object.keys(_SEND_FORM_CHANNELS);
1149
1435
  export var sendFormChannelValidator = exactMatchValidator(SEND_FORM_CHANNELS);
1436
+ export var sendFormChannelValidatorOptional = exactMatchValidatorOptional(SEND_FORM_CHANNELS);
1150
1437
  export var automationActionValidator = orValidator({
1151
1438
  setEnduserStatus: objectValidator({
1152
- type: exactMatchValidator(['setEnduserStatus'])(),
1153
- info: objectValidator({ status: stringValidator250() }, { emptyOk: false })(),
1154
- })(),
1439
+ type: exactMatchValidator(['setEnduserStatus']),
1440
+ info: objectValidator({ status: stringValidator250 }, { emptyOk: false }),
1441
+ }),
1155
1442
  sendEmail: objectValidator({
1156
- type: exactMatchValidator(['sendEmail'])(),
1157
- info: objectValidator({ senderId: mongoIdStringValidator(), templateId: mongoIdStringValidator() }, { emptyOk: false })(),
1158
- })(),
1443
+ type: exactMatchValidator(['sendEmail']),
1444
+ info: objectValidator({ senderId: mongoIdStringRequired, templateId: mongoIdStringRequired }, { emptyOk: false }),
1445
+ }),
1159
1446
  sendSMS: objectValidator({
1160
- type: exactMatchValidator(['sendSMS'])(),
1161
- info: objectValidator({ senderId: mongoIdStringValidator(), templateId: mongoIdStringValidator() }, { emptyOk: false })(),
1162
- })(),
1447
+ type: exactMatchValidator(['sendSMS']),
1448
+ info: objectValidator({ senderId: mongoIdStringRequired, templateId: mongoIdStringRequired }, { emptyOk: false }),
1449
+ }),
1163
1450
  sendForm: objectValidator({
1164
- type: exactMatchValidator(['sendForm'])(),
1451
+ type: exactMatchValidator(['sendForm']),
1165
1452
  info: objectValidator({
1166
- senderId: mongoIdStringValidator(),
1167
- formId: mongoIdStringValidator(),
1168
- channel: sendFormChannelValidator({ isOptional: true }),
1169
- }, { emptyOk: false })(),
1170
- })(),
1453
+ senderId: mongoIdStringRequired,
1454
+ formId: mongoIdStringRequired,
1455
+ channel: sendFormChannelValidatorOptional,
1456
+ }, { emptyOk: false }),
1457
+ }),
1171
1458
  createTicket: objectValidator({
1172
- type: exactMatchValidator(['createTicket'])(),
1459
+ type: exactMatchValidator(['createTicket']),
1173
1460
  info: objectValidator({
1174
- title: stringValidator({ isOptional: false }),
1461
+ title: stringValidatorOptional,
1175
1462
  assignmentStrategy: orValidator({
1176
1463
  'care-team-random': objectValidator({
1177
- type: exactMatchValidator(['care-team-random'])(),
1178
- info: objectValidator({}, { emptyOk: true })(),
1179
- })()
1180
- })(),
1181
- closeReasons: listOfStringsValidator({ isOptional: true, emptyListOk: true }),
1464
+ type: exactMatchValidator(['care-team-random']),
1465
+ info: objectValidator({}, { emptyOk: true }),
1466
+ })
1467
+ }),
1468
+ closeReasons: listOfStringsValidatorOptionalOrEmptyOk,
1182
1469
  defaultAssignee: mongoIdStringRequired,
1183
- }, { emptyOk: false })(),
1184
- })(),
1470
+ }, { emptyOk: false }),
1471
+ }),
1185
1472
  sendWebhook: objectValidator({
1186
- type: exactMatchValidator(['sendWebhook'])(),
1187
- info: objectValidator({ message: stringValidator5000() }, { emptyOk: false })(),
1188
- })(),
1473
+ type: exactMatchValidator(['sendWebhook']),
1474
+ info: objectValidator({ message: stringValidator5000 }, { emptyOk: false }),
1475
+ }),
1189
1476
  });
1190
1477
  export var relatedRecordValidator = objectValidator({
1191
- type: stringValidator100(),
1192
- id: mongoIdStringValidator(),
1478
+ type: stringValidator100,
1479
+ id: mongoIdStringRequired,
1193
1480
  creator: mongoIdStringOptional,
1194
1481
  });
1195
- export var listOfRelatedRecordsValidator = listValidatorEmptyOk(relatedRecordValidator());
1482
+ export var listOfRelatedRecordsValidator = listValidatorEmptyOk(relatedRecordValidator);
1196
1483
  export var searchOptionsValidator = objectValidator({
1197
- query: stringValidator100(),
1484
+ query: stringValidator100,
1198
1485
  });
1199
1486
  export var notificationPreferenceValidator = objectValidator({
1200
- email: booleanValidator({ isOptional: true }),
1487
+ email: booleanValidatorOptional,
1201
1488
  });
1202
- export var notificationPreferencesValidator = objectAnyFieldsValidator(notificationPreferenceValidator());
1489
+ export var notificationPreferencesValidator = objectAnyFieldsValidator(notificationPreferenceValidator);
1203
1490
  export var FHIRObservationCategoryValidator = exactMatchValidator(['vital-signs']);
1204
1491
  var _FHIR_OBSERVATION_STATUS_CODES = {
1205
1492
  "entered-in-error": '',
@@ -1214,37 +1501,37 @@ var _FHIR_OBSERVATION_STATUS_CODES = {
1214
1501
  export var FHIR_OBSERVATION_STATUS_CODES = Object.keys(_FHIR_OBSERVATION_STATUS_CODES);
1215
1502
  export var FHIRObservationStatusCodeValidator = exactMatchValidator(FHIR_OBSERVATION_STATUS_CODES);
1216
1503
  export var FHIRObservationValueValidator = objectValidator({
1217
- unit: stringValidator(),
1218
- value: numberValidator(),
1504
+ unit: stringValidator,
1505
+ value: numberValidator,
1219
1506
  });
1220
1507
  export var previousFormFieldValidator = orValidator({
1221
1508
  root: objectValidator({
1222
- type: exactMatchValidator(['root'])(),
1223
- info: objectValidator({}, { emptyOk: true })(),
1224
- })(),
1509
+ type: exactMatchValidator(['root']),
1510
+ info: objectValidator({}, { emptyOk: true }),
1511
+ }),
1225
1512
  "after": objectValidator({
1226
- type: exactMatchValidator(['after'])(),
1227
- info: objectValidator({ fieldId: mongoIdStringRequired }, { emptyOk: false })(),
1228
- })(),
1513
+ type: exactMatchValidator(['after']),
1514
+ info: objectValidator({ fieldId: mongoIdStringRequired }, { emptyOk: false }),
1515
+ }),
1229
1516
  "previousEquals": objectValidator({
1230
- type: exactMatchValidator(['previousEquals'])(),
1517
+ type: exactMatchValidator(['previousEquals']),
1231
1518
  info: objectValidator({
1232
1519
  fieldId: mongoIdStringRequired,
1233
- equals: stringValidator250(),
1234
- }, { emptyOk: false })(),
1235
- })(),
1520
+ equals: stringValidator250,
1521
+ }, { emptyOk: false }),
1522
+ }),
1236
1523
  });
1237
- export var previousFormFieldsValidator = listValidatorEmptyOk(previousFormFieldValidator());
1524
+ export var previousFormFieldsValidator = listValidatorEmptyOk(previousFormFieldValidator);
1238
1525
  export var portalSettingsValidator = objectValidator({});
1239
1526
  export var organizationThemeValidator = objectValidator({
1240
- logoURL: stringValidator250({ isOptional: true }),
1241
- themeColor: stringValidator250({ isOptional: true }),
1242
- name: stringValidator250(),
1243
- subdomain: stringValidator250(),
1244
- businessId: mongoIdRequired,
1245
- faviconURL: stringValidator250(),
1246
- customPortalURL: stringValidator250(),
1247
- portalSettings: portalSettingsValidator(),
1527
+ logoURL: stringValidatorOptional,
1528
+ themeColor: stringValidatorOptional,
1529
+ name: stringValidator250,
1530
+ subdomain: stringValidator250,
1531
+ businessId: mongoIdStringRequired,
1532
+ faviconURL: stringValidator250,
1533
+ customPortalURL: stringValidator250,
1534
+ portalSettings: portalSettingsValidator,
1248
1535
  });
1249
1536
  var _MANAGED_CONTENT_RECORD_TYPES = {
1250
1537
  Article: '',
@@ -1253,93 +1540,97 @@ var _MANAGED_CONTENT_RECORD_TYPES = {
1253
1540
  };
1254
1541
  export var MANAGED_CONTENT_RECORD_TYPES = Object.keys(_MANAGED_CONTENT_RECORD_TYPES);
1255
1542
  export var managedContentRecordTypeValidator = exactMatchValidator(MANAGED_CONTENT_RECORD_TYPES);
1256
- export var passwordValidator = function (o) { return build_validator(function (password) {
1257
- var _a, _b, _c, _d, _e, _f, _g, _h;
1258
- if (typeof password !== 'string') {
1259
- throw new Error("Password must be a string");
1260
- }
1261
- if (password.length < 8) {
1262
- throw new Error("Password must be at least 8 characters long");
1263
- }
1264
- 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
1265
- || (((_d = (_c = password.match(/[A-Z]/g)) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) < 1 // 1 uppercase
1266
- && ((_f = (_e = password.match(/[0-9]/g)) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : 0) < 1 // 1 number
1267
- && ((_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
1268
- )) {
1269
- console.error('bad password regex');
1270
- throw new Error('Password must included 1 uppercase letter, 1 number, or 1 symbol');
1271
- }
1272
- return password;
1273
- }, __assign(__assign({}, o), { listOf: false, emptyStringOk: false })); };
1543
+ export var passwordValidator = {
1544
+ getExample: getExampleString,
1545
+ getType: getTypeString,
1546
+ validate: (function (o) { return build_validator(function (password) {
1547
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1548
+ if (typeof password !== 'string') {
1549
+ throw new Error("Password must be a string");
1550
+ }
1551
+ if (password.length < 8) {
1552
+ throw new Error("Password must be at least 8 characters long");
1553
+ }
1554
+ 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
1555
+ || (((_d = (_c = password.match(/[A-Z]/g)) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) < 1 // 1 uppercase
1556
+ && ((_f = (_e = password.match(/[0-9]/g)) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : 0) < 1 // 1 number
1557
+ && ((_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
1558
+ )) {
1559
+ console.error('bad password regex');
1560
+ throw new Error('Password must included 1 uppercase letter, 1 number, or 1 symbol');
1561
+ }
1562
+ return password;
1563
+ }, __assign(__assign({}, o), { listOf: false, emptyStringOk: false })); }),
1564
+ };
1274
1565
  export var flowchartUIValidator = objectValidator({
1275
- x: numberValidator(),
1276
- y: numberValidator(),
1566
+ x: numberValidator,
1567
+ y: numberValidator,
1277
1568
  }, { emptyOk: true });
1278
1569
  export var integrationAuthenticationsValidator = objectValidator({
1279
- type: exactMatchValidator(['oauth2'])(),
1570
+ type: exactMatchValidator(['oauth2']),
1280
1571
  info: objectValidator({
1281
- access_token: stringValidator250(),
1282
- refresh_token: stringValidator250(),
1283
- scope: stringValidator5000(),
1284
- expiry_date: nonNegNumberValidator(),
1285
- token_type: exactMatchValidator(['Bearer'])(),
1286
- state: stringValidator250({ isOptional: true }),
1287
- email: emailValidator({ isOptional: true }),
1288
- })(),
1572
+ access_token: stringValidator250,
1573
+ refresh_token: stringValidator250,
1574
+ scope: stringValidator5000,
1575
+ expiry_date: nonNegNumberValidator,
1576
+ token_type: exactMatchValidator(['Bearer']),
1577
+ state: stringValidatorOptional,
1578
+ email: emailValidatorOptional,
1579
+ }),
1289
1580
  });
1290
1581
  export var formFieldOptionsValidator = objectValidator({
1291
- choices: listOfStringsValidator({ isOptional: true }),
1292
- from: numberValidator({ isOptional: true }),
1293
- to: numberValidator({ isOptional: true }),
1294
- other: stringValidator250({ isOptional: true }),
1295
- radio: booleanValidator({ isOptional: true }),
1582
+ choices: listOfStringsValidatorOptionalOrEmptyOk,
1583
+ from: numberValidatorOptional,
1584
+ to: numberValidatorOptional,
1585
+ other: stringValidatorOptional,
1586
+ radio: booleanValidatorOptional,
1296
1587
  });
1297
1588
  export var blockValidator = orValidator({
1298
1589
  h1: objectValidator({
1299
- type: exactMatchValidator(['h1'])(),
1590
+ type: exactMatchValidator(['h1']),
1300
1591
  info: objectValidator({
1301
- text: stringValidator5000({ emptyStringOk: true }),
1302
- })(),
1303
- })(),
1592
+ text: stringValidator5000EmptyOkay,
1593
+ }),
1594
+ }),
1304
1595
  h2: objectValidator({
1305
- type: exactMatchValidator(['h2'])(),
1596
+ type: exactMatchValidator(['h2']),
1306
1597
  info: objectValidator({
1307
- text: stringValidator5000({ emptyStringOk: true }),
1308
- })(),
1309
- })(),
1598
+ text: stringValidator5000EmptyOkay,
1599
+ }),
1600
+ }),
1310
1601
  html: objectValidator({
1311
- type: exactMatchValidator(['html'])(),
1602
+ type: exactMatchValidator(['html']),
1312
1603
  info: objectValidator({
1313
- html: stringValidator25000({ emptyStringOk: true }),
1314
- })(),
1315
- })(),
1604
+ html: stringValidator25000EmptyOkay,
1605
+ }),
1606
+ }),
1316
1607
  image: objectValidator({
1317
- type: exactMatchValidator(['image'])(),
1608
+ type: exactMatchValidator(['image']),
1318
1609
  info: objectValidator({
1319
- link: stringValidator5000({ emptyStringOk: true }),
1320
- name: stringValidator250({ isOptional: true, emptyStringOk: true }),
1321
- height: nonNegNumberValidator({ isOptional: true }),
1322
- width: nonNegNumberValidator({ isOptional: true }),
1323
- })(),
1324
- })(),
1610
+ link: stringValidator5000EmptyOkay,
1611
+ name: stringValidatorOptional,
1612
+ height: numberValidatorOptional,
1613
+ width: numberValidatorOptional,
1614
+ }),
1615
+ }),
1325
1616
  pdf: objectValidator({
1326
- type: exactMatchValidator(['pdf'])(),
1617
+ type: exactMatchValidator(['pdf']),
1327
1618
  info: objectValidator({
1328
- link: stringValidator5000({ emptyStringOk: true }),
1329
- name: stringValidator250({ isOptional: true, emptyStringOk: true }),
1330
- height: nonNegNumberValidator({ isOptional: true }),
1331
- width: nonNegNumberValidator({ isOptional: true }),
1332
- })(),
1333
- })(),
1619
+ link: stringValidator5000EmptyOkay,
1620
+ name: stringValidatorOptional,
1621
+ height: numberValidatorOptional,
1622
+ width: numberValidatorOptional,
1623
+ }),
1624
+ }),
1334
1625
  youtube: objectValidator({
1335
- type: exactMatchValidator(['youtube'])(),
1626
+ type: exactMatchValidator(['youtube']),
1336
1627
  info: objectValidator({
1337
- link: stringValidator5000({ emptyStringOk: true }),
1338
- name: stringValidator250({ isOptional: true, emptyStringOk: true }),
1339
- height: nonNegNumberValidator({ isOptional: true }),
1340
- width: nonNegNumberValidator({ isOptional: true }),
1341
- })(),
1342
- })(),
1628
+ link: stringValidator5000EmptyOkay,
1629
+ name: stringValidatorOptional,
1630
+ height: numberValidatorOptional,
1631
+ width: numberValidatorOptional,
1632
+ }),
1633
+ }),
1343
1634
  });
1344
1635
  var _BLOCK_TYPES = {
1345
1636
  h1: '',
@@ -1352,7 +1643,7 @@ var _BLOCK_TYPES = {
1352
1643
  export var BLOCK_TYPES = Object.keys(_BLOCK_TYPES);
1353
1644
  export var blockTypeValidator = exactMatchValidator(BLOCK_TYPES);
1354
1645
  export var is_block_type = function (type) { return BLOCK_TYPES.includes(type); };
1355
- export var blocksValidator = listValidatorEmptyOk(blockValidator());
1646
+ export var blocksValidator = listValidatorEmptyOk(blockValidator);
1356
1647
  var _DATABASE_RECORD_FIELD_TYPES = {
1357
1648
  "string-long": '',
1358
1649
  number: '',
@@ -1378,30 +1669,30 @@ export var is_database_record_field_type = function (type) { return DATABASE_REC
1378
1669
  // })
1379
1670
  // structure as above instead if need unique label or additional config based on type
1380
1671
  export var databaseFieldValidator = objectValidator({
1381
- type: databaseRecordFieldTypeValidator(),
1382
- label: stringValidator250(),
1672
+ type: databaseRecordFieldTypeValidator,
1673
+ label: stringValidator250,
1383
1674
  });
1384
- export var databaseFieldsValidator = listValidator(databaseFieldValidator());
1675
+ export var databaseFieldsValidator = listValidator(databaseFieldValidator);
1385
1676
  export var databaseRecordValueValidator = orValidator({
1386
1677
  string: objectValidator({
1387
- type: exactMatchValidator(['string'])(),
1388
- value: stringValidator1000(),
1389
- })(),
1678
+ type: exactMatchValidator(['string']),
1679
+ value: stringValidator1000,
1680
+ }),
1390
1681
  'string-long': objectValidator({
1391
- type: exactMatchValidator(['string-long'])(),
1392
- value: stringValidator5000(),
1393
- })(),
1682
+ type: exactMatchValidator(['string-long']),
1683
+ value: stringValidator5000,
1684
+ }),
1394
1685
  'number': objectValidator({
1395
- type: exactMatchValidator(['number'])(),
1396
- value: numberValidator(),
1397
- })(),
1686
+ type: exactMatchValidator(['number']),
1687
+ value: numberValidator,
1688
+ }),
1398
1689
  });
1399
- export var databaseRecordValuesValidator = listValidator(databaseRecordValueValidator());
1690
+ export var databaseRecordValuesValidator = listValidator(databaseRecordValueValidator);
1400
1691
  export var organizationAccessValidator = objectValidator({
1401
- create: booleanValidator({ isOptional: true }),
1402
- update: booleanValidator({ isOptional: true }),
1403
- read: booleanValidator({ isOptional: true }),
1404
- delete: booleanValidator({ isOptional: true }),
1692
+ create: booleanValidatorOptional,
1693
+ update: booleanValidatorOptional,
1694
+ read: booleanValidatorOptional,
1695
+ delete: booleanValidatorOptional,
1405
1696
  });
1406
1697
  var _PORTAL_PAGES = {
1407
1698
  "Care Plan": true,
@@ -1413,35 +1704,41 @@ var _PORTAL_PAGES = {
1413
1704
  };
1414
1705
  export var PORTAL_PAGES = Object.keys(_PORTAL_PAGES);
1415
1706
  export var portalPageValidator = exactMatchValidator(PORTAL_PAGES);
1707
+ var _FORM_TYPES = {
1708
+ note: true,
1709
+ enduserFacing: true,
1710
+ };
1711
+ export var FORM_TYPES = Object.keys(_FORM_TYPES);
1712
+ export var formTypeValidator = exactMatchValidator(FORM_TYPES);
1416
1713
  export var portalBlockValidator = orValidator({
1417
1714
  carePlan: objectValidator({
1418
- type: exactMatchValidator(['carePlan'])(),
1419
- info: objectValidator({}, { emptyOk: true })()
1420
- })(),
1715
+ type: exactMatchValidator(['carePlan']),
1716
+ info: objectValidator({}, { emptyOk: true })
1717
+ }),
1421
1718
  education: objectValidator({
1422
- type: exactMatchValidator(['education'])(),
1423
- info: objectValidator({}, { emptyOk: true })()
1424
- })(),
1719
+ type: exactMatchValidator(['education']),
1720
+ info: objectValidator({}, { emptyOk: true })
1721
+ }),
1425
1722
  careTeam: objectValidator({
1426
- type: exactMatchValidator(['careTeam'])(),
1723
+ type: exactMatchValidator(['careTeam']),
1427
1724
  info: objectValidator({
1428
- title: stringValidator(),
1725
+ title: stringValidator,
1429
1726
  // members: listValidatorEmptyOk(
1430
1727
  // objectValidator<CareTeamMemberPortalCustomizationInfo>({
1431
1728
  // title: stringValidator(),
1432
1729
  // role: stringValidator({ isOptional: true }),
1433
1730
  // })()
1434
1731
  // )()
1435
- })()
1436
- })(),
1732
+ })
1733
+ }),
1437
1734
  text: objectValidator({
1438
- type: exactMatchValidator(['text'])(),
1735
+ type: exactMatchValidator(['text']),
1439
1736
  info: objectValidator({
1440
- text: stringValidator5000(),
1441
- })()
1442
- })(),
1737
+ text: stringValidator5000,
1738
+ })
1739
+ }),
1443
1740
  });
1444
- export var portalBlocksValidator = listValidatorEmptyOk(portalBlockValidator());
1741
+ export var portalBlocksValidator = listValidatorEmptyOk(portalBlockValidator);
1445
1742
  var _PORTAL_BLOCK_TYPES = {
1446
1743
  carePlan: '',
1447
1744
  careTeam: '',
@@ -1454,13 +1751,13 @@ export var enduserTaskForEventValidator = objectValidator({
1454
1751
  id: mongoIdStringRequired,
1455
1752
  enduserId: mongoIdStringRequired,
1456
1753
  });
1457
- export var enduserTasksForEventValidator = listValidatorEmptyOk(enduserTaskForEventValidator());
1754
+ export var enduserTasksForEventValidator = listValidatorEmptyOk(enduserTaskForEventValidator);
1458
1755
  export var enduserFormResponseForEventValidator = objectValidator({
1459
1756
  enduserId: mongoIdStringRequired,
1460
1757
  formId: mongoIdStringRequired,
1461
- accessCode: stringValidator1000(),
1758
+ accessCode: stringValidator1000,
1462
1759
  });
1463
- export var enduserFormResponsesForEventValidator = listValidatorEmptyOk(enduserFormResponseForEventValidator());
1760
+ export var enduserFormResponsesForEventValidator = listValidatorEmptyOk(enduserFormResponseForEventValidator);
1464
1761
  export var VALID_STATES = [
1465
1762
  "AK",
1466
1763
  "AL",
@@ -1522,21 +1819,21 @@ export var VALID_STATES = [
1522
1819
  ];
1523
1820
  export var stateValidator = exactMatchValidator(VALID_STATES);
1524
1821
  export var stateCredentialValidator = objectValidator({
1525
- expiresAt: dateValidator({ isOptional: true }),
1526
- state: stateValidator(),
1822
+ expiresAt: dateValidatorOptional,
1823
+ state: stateValidator,
1527
1824
  });
1528
- export var stateCredentialsValidator = listValidatorEmptyOk(stateCredentialValidator());
1825
+ export var stateCredentialsValidator = listValidatorEmptyOk(stateCredentialValidator);
1529
1826
  export var availabilityBlockValidator = objectValidator({
1530
- durationInMinutes: nonNegNumberValidator(),
1531
- startTimeInMS: nonNegNumberValidator(),
1827
+ durationInMinutes: nonNegNumberValidator,
1828
+ startTimeInMS: nonNegNumberValidator,
1532
1829
  userId: mongoIdStringRequired,
1533
1830
  });
1534
- export var availabilityBlocksValidator = listValidatorEmptyOk(availabilityBlockValidator());
1831
+ export var availabilityBlocksValidator = listValidatorEmptyOk(availabilityBlockValidator);
1535
1832
  export var weeklyAvailabilityValidator = objectValidator({
1536
- dayOfWeekStartingSundayIndexedByZero: nonNegNumberValidator(),
1537
- endTimeInMinutes: nonNegNumberValidator(),
1538
- startTimeInMinutes: nonNegNumberValidator(),
1833
+ dayOfWeekStartingSundayIndexedByZero: nonNegNumberValidator,
1834
+ endTimeInMinutes: nonNegNumberValidator,
1835
+ startTimeInMinutes: nonNegNumberValidator,
1539
1836
  });
1540
- export var weeklyAvailabilitiesValidator = listValidatorEmptyOk(weeklyAvailabilityValidator());
1837
+ export var weeklyAvailabilitiesValidator = listValidatorEmptyOk(weeklyAvailabilityValidator);
1541
1838
  export var timezoneValidator = exactMatchValidator(Object.keys(TIMEZONES));
1542
1839
  //# sourceMappingURL=validation.js.map