@carecard/validate 3.3.0 → 3.5.0
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/.prettierrc.js +0 -2
- package/index.d.ts +4 -1
- package/lib/validate.js +6 -0
- package/lib/validateProperties.js +13 -4
- package/package.json +9 -4
- package/readme.md +24 -23
package/.prettierrc.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -108,7 +108,7 @@ export interface ValidateNewUserRoleRequestPayload extends Record<string, unknow
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
|
-
* Normalizes and validates
|
|
111
|
+
* Normalizes and validates an institutions.new_user_role_request payload.
|
|
112
112
|
* Only student, intern, and volunteer are accepted. When scope is required,
|
|
113
113
|
* both institution_id and campus_id must be provided.
|
|
114
114
|
*/
|
|
@@ -127,6 +127,8 @@ export const isValidJsonString: BoolValidator;
|
|
|
127
127
|
export const isValidIntegerString: BoolValidator;
|
|
128
128
|
/** Checks if the string is a valid UUID. */
|
|
129
129
|
export const isValidUuidString: BoolValidator;
|
|
130
|
+
/** Checks if the string is a valid lowercase 8-character CareCard ID. */
|
|
131
|
+
export const isCcIdString: BoolValidator;
|
|
130
132
|
/** Checks if the string contains only alphanumeric characters, spaces, underscores, or hyphens. */
|
|
131
133
|
export const isCharactersString: BoolValidator;
|
|
132
134
|
/** Checks if the string is a valid street address format. */
|
|
@@ -198,6 +200,7 @@ export const validate: {
|
|
|
198
200
|
isValidJsonString: typeof isValidJsonString;
|
|
199
201
|
isValidIntegerString: typeof isValidIntegerString;
|
|
200
202
|
isValidUuidString: typeof isValidUuidString;
|
|
203
|
+
isCcIdString: typeof isCcIdString;
|
|
201
204
|
isCharactersString: typeof isCharactersString;
|
|
202
205
|
isStreetString: typeof isStreetString;
|
|
203
206
|
isNameString: typeof isNameString;
|
package/lib/validate.js
CHANGED
|
@@ -31,6 +31,11 @@ const isValidUuidString = str => {
|
|
|
31
31
|
return uuidRegex.test(str);
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
+
const isCcIdString = str => {
|
|
35
|
+
if (typeof str !== 'string') return false;
|
|
36
|
+
return /^[a-z0-9]{8}$/.test(str);
|
|
37
|
+
};
|
|
38
|
+
|
|
34
39
|
const isCharactersString = str => {
|
|
35
40
|
if (str === undefined || typeof str !== 'string' || str.length === 0 || str.length > 1000) return false;
|
|
36
41
|
return /^[\da-zA-Z _-]+$/.test(str);
|
|
@@ -241,6 +246,7 @@ module.exports = {
|
|
|
241
246
|
isValidJsonString,
|
|
242
247
|
isValidIntegerString,
|
|
243
248
|
isValidUuidString,
|
|
249
|
+
isCcIdString,
|
|
244
250
|
isCharactersString,
|
|
245
251
|
isStreetString,
|
|
246
252
|
isNameString,
|
|
@@ -4,6 +4,7 @@ const {
|
|
|
4
4
|
isPhoneNumber,
|
|
5
5
|
isUrlSafeString,
|
|
6
6
|
isValidUuidString,
|
|
7
|
+
isCcIdString,
|
|
7
8
|
isSimplePasswordString,
|
|
8
9
|
isPasswordString,
|
|
9
10
|
isString6To16CharacterLong,
|
|
@@ -166,8 +167,12 @@ function validateProperties(obj = {}) {
|
|
|
166
167
|
case 'campusId':
|
|
167
168
|
case 'program_id':
|
|
168
169
|
case 'programId':
|
|
169
|
-
case '
|
|
170
|
-
case '
|
|
170
|
+
case 'program_requirement_for_user_id':
|
|
171
|
+
case 'programRequirementForUserId':
|
|
172
|
+
case 'document_item_status_id':
|
|
173
|
+
case 'documentItemStatusId':
|
|
174
|
+
case 'requirement_item_id':
|
|
175
|
+
case 'requirementItemId':
|
|
171
176
|
case 'program_document_id':
|
|
172
177
|
case 'programDocumentId':
|
|
173
178
|
case 'id':
|
|
@@ -191,6 +196,12 @@ function validateProperties(obj = {}) {
|
|
|
191
196
|
returnObj[key] = value;
|
|
192
197
|
}
|
|
193
198
|
break;
|
|
199
|
+
case 'cc_id':
|
|
200
|
+
case 'ccId':
|
|
201
|
+
if (isCcIdString(value)) {
|
|
202
|
+
returnObj[key] = value;
|
|
203
|
+
}
|
|
204
|
+
break;
|
|
194
205
|
case 'requested_by_name':
|
|
195
206
|
case 'requestedByName':
|
|
196
207
|
case 'document_description':
|
|
@@ -296,8 +307,6 @@ function validateProperties(obj = {}) {
|
|
|
296
307
|
returnObj[key] = value;
|
|
297
308
|
}
|
|
298
309
|
break;
|
|
299
|
-
case 'document_required_by_date':
|
|
300
|
-
case 'documentRequiredByDate':
|
|
301
310
|
case 'effective_start_date':
|
|
302
311
|
case 'effectiveStartDate':
|
|
303
312
|
case 'effective_end_date':
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carecard/validate",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/CareCard-ca/pkg-validate.git"
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
"license": "ISC",
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/mocha": "10.0.10",
|
|
30
|
-
"@types/node": "25.9.
|
|
30
|
+
"@types/node": "25.9.3",
|
|
31
31
|
"eslint": "9.39.4",
|
|
32
32
|
"husky": "9.1.7",
|
|
33
|
-
"lint-staged": "17.0.
|
|
33
|
+
"lint-staged": "17.0.7",
|
|
34
34
|
"mocha": "11.7.6",
|
|
35
35
|
"nyc": "18.0.0",
|
|
36
|
-
"prettier": "3.8.
|
|
36
|
+
"prettier": "3.8.4",
|
|
37
37
|
"ts-node": "10.9.2",
|
|
38
38
|
"typescript": "6.0.3"
|
|
39
39
|
},
|
|
@@ -51,5 +51,10 @@
|
|
|
51
51
|
"functions": 100,
|
|
52
52
|
"lines": 100,
|
|
53
53
|
"statements": 100
|
|
54
|
+
},
|
|
55
|
+
"overrides": {
|
|
56
|
+
"diff": "8.0.4",
|
|
57
|
+
"serialize-javascript": "7.0.5",
|
|
58
|
+
"js-yaml": "4.2.0"
|
|
54
59
|
}
|
|
55
60
|
}
|
package/readme.md
CHANGED
|
@@ -96,29 +96,30 @@ validateProperties(input);
|
|
|
96
96
|
Keys are matched exactly. Both snake_case and camelCase variants are listed
|
|
97
97
|
where the package supports both.
|
|
98
98
|
|
|
99
|
-
| Validator | Keys
|
|
100
|
-
| --------------------------------------------------------- |
|
|
101
|
-
| `isNameString` | `first_name`, `firstName`, `last_name`, `lastName`, `username`, `new_status`, `newStatus`, `description`, `comment`, `status`, `name`, `title`, `brand`, `short_description`, `shortDescription`, `college_name`, `collegeName`, `campus_name`, `campusName`, `role`, `role_id`, `roleId`, `campus`, `institution_name`, `institutionName`, `program_name`, `programName`, `role_name`, `roleName`, `document_name`, `documentName`, `document_required_for_role_name`, `documentRequiredForRoleName`, `reason`, `entity_type`, `entityType`, `action_type`, `actionType`, `city`, `state`, `country`, `type`
|
|
102
|
-
| `isStreetString` | `street`
|
|
103
|
-
| `isCharactersString` | `postal_code`, `postalCode`, `period`
|
|
104
|
-
| `isBoolValue` | `is_primary`, `isPrimary`, `active`, `document_optional`, `documentOptional`
|
|
105
|
-
| `isSafeSearchString` | `search_string`, `searchString`
|
|
106
|
-
| `isString6To16CharacterLong` and `isSimplePasswordString` | `password`, `new_password`, `newPassword`
|
|
107
|
-
| `isString6To16CharacterLong` and `isPasswordString` | `strong_password`, `strongPassword`
|
|
108
|
-
| `isEmailString` | `email`
|
|
109
|
-
| `isPhoneNumber` | `phone_number`, `phoneNumber`
|
|
110
|
-
| `isCountryCodeString` | `country_code`, `countryCode`
|
|
111
|
-
| `isUrlSafeString` | `token`, `email_confirm_token`, `emailConfirmToken`, `verification_token`, `verificationToken`
|
|
112
|
-
| `isValidUuidString` | `uuid`, `item_id`, `itemId`, `user_id`, `userId`, `address_id`, `addressId`, `image_id`, `imageId`, `order_id`, `orderId`, `category_id`, `categoryId`, `parent_id`, `parentId`, `college_id`, `collegeId`, `campus_id`, `campusId`, `program_id`, `programId`, `
|
|
113
|
-
| `
|
|
114
|
-
| `
|
|
115
|
-
| `isValidJsonString
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
118
|
-
| `
|
|
119
|
-
| `
|
|
120
|
-
| `
|
|
121
|
-
| `
|
|
99
|
+
| Validator | Keys |
|
|
100
|
+
| --------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
101
|
+
| `isNameString` | `first_name`, `firstName`, `last_name`, `lastName`, `username`, `new_status`, `newStatus`, `description`, `comment`, `status`, `name`, `title`, `brand`, `short_description`, `shortDescription`, `college_name`, `collegeName`, `campus_name`, `campusName`, `role`, `role_id`, `roleId`, `campus`, `institution_name`, `institutionName`, `program_name`, `programName`, `role_name`, `roleName`, `document_name`, `documentName`, `document_required_for_role_name`, `documentRequiredForRoleName`, `reason`, `entity_type`, `entityType`, `action_type`, `actionType`, `city`, `state`, `country`, `type` |
|
|
102
|
+
| `isStreetString` | `street` |
|
|
103
|
+
| `isCharactersString` | `postal_code`, `postalCode`, `period` |
|
|
104
|
+
| `isBoolValue` | `is_primary`, `isPrimary`, `active`, `document_optional`, `documentOptional` |
|
|
105
|
+
| `isSafeSearchString` | `search_string`, `searchString` |
|
|
106
|
+
| `isString6To16CharacterLong` and `isSimplePasswordString` | `password`, `new_password`, `newPassword` |
|
|
107
|
+
| `isString6To16CharacterLong` and `isPasswordString` | `strong_password`, `strongPassword` |
|
|
108
|
+
| `isEmailString` | `email` |
|
|
109
|
+
| `isPhoneNumber` | `phone_number`, `phoneNumber` |
|
|
110
|
+
| `isCountryCodeString` | `country_code`, `countryCode` |
|
|
111
|
+
| `isUrlSafeString` | `token`, `email_confirm_token`, `emailConfirmToken`, `verification_token`, `verificationToken` |
|
|
112
|
+
| `isValidUuidString` | `uuid`, `item_id`, `itemId`, `user_id`, `userId`, `address_id`, `addressId`, `image_id`, `imageId`, `order_id`, `orderId`, `category_id`, `categoryId`, `parent_id`, `parentId`, `college_id`, `collegeId`, `campus_id`, `campusId`, `program_id`, `programId`, `program_requirement_for_user_id`, `programRequirementForUserId`, `document_item_status_id`, `documentItemStatusId`, `requirement_item_id`, `requirementItemId`, `program_document_id`, `programDocumentId`, `id`, `institution_id`, `institutionId`, `role_assignment_id`, `roleAssignmentId`, `user_role_id`, `userRoleId`, `phone_number_id`, `phoneNumberId`, `entity_id`, `entityId`, `changed_by`, `changedBy`, `request_id`, `requestId` |
|
|
113
|
+
| `isCcIdString` | `cc_id`, `ccId` |
|
|
114
|
+
| `isValidIntegerString` | `offset_number`, `offsetNumber`, `number_of_orders`, `numberOfOrders`, `price`, `from`, `number`, `limit`, `offset` |
|
|
115
|
+
| `isValidJsonString` on the raw value | `about` |
|
|
116
|
+
| `isValidJsonString(JSON.stringify(value))` | `weight`, `dimensions`, `permission`, `scope_data`, `scopeData`, `meta_data`, `metaData` |
|
|
117
|
+
| `isTextString` | `document_description`, `documentDescription`, `nick_name`, `nickName`, `requested_by_name`, `requestedByName`, `requested_by_email`, `requestedByEmail`, `requested_by_phone`, `requestedByPhone`, `approved_by_name`, `approvedByName`, `approved_by_email`, `approvedByEmail`, `approved_by_phone`, `approvedByPhone` |
|
|
118
|
+
| `isValidArrayOfStrings` | `aliases` |
|
|
119
|
+
| `isImageUrl` or `isValidUrl` | `image_url`, `imageUrl`, `website`, `file_url`, `fileUrl` |
|
|
120
|
+
| `isValidDomainName` | `domain_name`, `domainName`, `domain`, `email_domain`, `emailDomain`, `email_domain_name`, `emailDomainName` |
|
|
121
|
+
| `isValidTimestampzString` or `isValidTimestampString` | `expires_at`, `expiresAt`, `start_time`, `startTime`, `end_time`, `endTime` |
|
|
122
|
+
| `isValidDateString` | `effective_start_date`, `effectiveStartDate`, `effective_end_date`, `effectiveEndDate`, `valid_until_date`, `validUntilDate`, `renew_date`, `renewDate` |
|
|
122
123
|
|
|
123
124
|
## `validateWhitelistProperties(inputObject, requiredProperties, options)`
|
|
124
125
|
|