@tellescope/validation 1.4.0 → 1.4.3

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