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