@tellescope/validation 1.3.48 → 1.4.1

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