@carecard/validate 3.2.0 → 3.4.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/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 a carecard.new_user_role_request payload.
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,
@@ -191,6 +192,12 @@ function validateProperties(obj = {}) {
191
192
  returnObj[key] = value;
192
193
  }
193
194
  break;
195
+ case 'cc_id':
196
+ case 'ccId':
197
+ if (isCcIdString(value)) {
198
+ returnObj[key] = value;
199
+ }
200
+ break;
194
201
  case 'requested_by_name':
195
202
  case 'requestedByName':
196
203
  case 'document_description':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carecard/validate",
3
- "version": "3.2.0",
3
+ "version": "3.4.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/CareCard-ca/pkg-validate.git"
@@ -38,7 +38,7 @@
38
38
  "typescript": "6.0.3"
39
39
  },
40
40
  "dependencies": {
41
- "@carecard/common-util": "3.1.15"
41
+ "@carecard/common-util": "3.2.0"
42
42
  },
43
43
  "nyc": {
44
44
  "all": true,
package/readme.md CHANGED
@@ -110,6 +110,7 @@ where the package supports both.
110
110
  | `isCountryCodeString` | `country_code`, `countryCode` |
111
111
  | `isUrlSafeString` | `token`, `email_confirm_token`, `emailConfirmToken`, `verification_token`, `verificationToken` |
112
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_document_id`, `programRequirementDocumentId`, `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` |
113
114
  | `isValidIntegerString` | `offset_number`, `offsetNumber`, `number_of_orders`, `numberOfOrders`, `price`, `from`, `number`, `limit`, `offset` |
114
115
  | `isValidJsonString` on the raw value | `about` |
115
116
  | `isValidJsonString(JSON.stringify(value))` | `weight`, `dimensions`, `permission`, `scope_data`, `scopeData`, `meta_data`, `metaData` |