@carecard/validate 3.0.10 → 3.0.13

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.
@@ -0,0 +1,24 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ test:
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+
14
+ - name: Use Node.js
15
+ uses: actions/setup-node@v4
16
+ with:
17
+ node-version: '25'
18
+ cache: 'npm'
19
+
20
+ - name: Install dependencies
21
+ run: npm ci
22
+
23
+ - name: Run tests and coverage
24
+ run: npm run test:All
@@ -0,0 +1,34 @@
1
+ name: Publish to npm
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ permissions:
9
+ id-token: write
10
+ contents: read
11
+
12
+ jobs:
13
+ publish:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - name: Checkout code
17
+ uses: actions/checkout@v4
18
+
19
+ - name: Setup Node.js
20
+ uses: actions/setup-node@v4
21
+ with:
22
+ node-version: '25'
23
+ registry-url: 'https://registry.npmjs.org'
24
+
25
+ - name: Install dependencies
26
+ # Added HUSKY=0 to prevent the husky error in logs
27
+ run: npm ci
28
+ env:
29
+ HUSKY: 0
30
+
31
+ - name: Publish to npm
32
+ run: npm publish --provenance --access public
33
+ env:
34
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -0,0 +1,3 @@
1
+ # Run tests
2
+ npm run test
3
+ npm run test:types
package/index.d.ts CHANGED
@@ -60,6 +60,11 @@ export function isValidTimestampzString(str: any): boolean;
60
60
  /** Checks if the string is a valid ISO 8601 timestamp without time zone. */
61
61
  export function isValidTimestampString(str: any): boolean;
62
62
 
63
+ /** Checks if the string is a valid URL. */
64
+ export function isValidUrl(url: any): boolean;
65
+ /** Checks if the array contains only safe strings. */
66
+ export function isValidArrayOfStrings(arr: any): boolean;
67
+
63
68
  /**
64
69
  * Utility functions for validating various types of strings and values.
65
70
  * @deprecated Use direct imports instead.
@@ -93,4 +98,6 @@ export const validate: {
93
98
  isValidDomainName: typeof isValidDomainName;
94
99
  isValidTimestampzString: typeof isValidTimestampzString;
95
100
  isValidTimestampString: typeof isValidTimestampString;
101
+ isValidUrl: typeof isValidUrl;
102
+ isValidArrayOfStrings: typeof isValidArrayOfStrings;
96
103
  };
package/lib/validate.js CHANGED
@@ -35,7 +35,8 @@ const isValidIntegerString = (str) => {
35
35
 
36
36
  const isValidUuidString = (str) => {
37
37
  if (str === undefined || typeof str !== 'string' || str.length === 0) return false;
38
- return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(str);
38
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
39
+ return uuidRegex.test(str);
39
40
  };
40
41
 
41
42
  const isCharactersString = (str) => {
@@ -144,7 +145,7 @@ const isProvinceString = (inputString) => {
144
145
  };
145
146
 
146
147
  const isBoolValue = (inputValue) => {
147
- return typeof inputValue === 'boolean';
148
+ return typeof inputValue === 'boolean' || inputValue === 'true' || inputValue === 'false';
148
149
  };
149
150
 
150
151
  const isPostalCodeString = (inputString) => {
@@ -199,6 +200,19 @@ const isValidTimestampString = (str) => {
199
200
  return timestampRegex.test(str) && !isNaN(Date.parse(str));
200
201
  };
201
202
 
203
+ const isValidUrl = (url) => {
204
+ if (typeof url !== 'string' || url.length === 0 || url.length > 2048) return false;
205
+ try {
206
+ const parsedUrl = new URL(url);
207
+ return parsedUrl.protocol === 'http:' || parsedUrl.protocol === 'https:';
208
+ } catch {
209
+ return false;
210
+ }
211
+ };
212
+ const isValidArrayOfStrings = (arr) => {
213
+ if (!Array.isArray(arr)) return false;
214
+ return arr.every(isSafeString);
215
+ };
202
216
  module.exports = {
203
217
  isImageUrl,
204
218
  isInteger,
@@ -227,5 +241,7 @@ module.exports = {
227
241
  isCountryCodeString,
228
242
  isValidDomainName,
229
243
  isValidTimestampzString,
230
- isValidTimestampString
244
+ isValidTimestampString,
245
+ isValidUrl,
246
+ isValidArrayOfStrings
231
247
  };
@@ -17,6 +17,8 @@ const {
17
17
  isValidTimestampzString,
18
18
  isValidTimestampString,
19
19
  isBoolValue,
20
+ isValidUrl,
21
+ isValidArrayOfStrings,
20
22
  } = require('./validate');
21
23
 
22
24
  function validateProperties(obj = {}) {
@@ -42,7 +44,20 @@ function validateProperties(obj = {}) {
42
44
  case 'campus_name':
43
45
  case 'campusName':
44
46
  case 'role':
45
- if (isNameString(value)) {
47
+ case 'role_id':
48
+ case 'roleId':
49
+ case 'campus':
50
+ case 'institution_name':
51
+ case 'institutionName':
52
+ case 'program_name':
53
+ case 'programName':
54
+ case 'role_name':
55
+ case 'roleName':
56
+ case 'document_type':
57
+ case 'documentType':
58
+ case 'reason':
59
+ case 'type':
60
+ if (isNameString(value) || (typeof value === 'object' && value !== null)) {
46
61
  returnObj[key] = value;
47
62
  }
48
63
  break;
@@ -104,6 +119,13 @@ function validateProperties(obj = {}) {
104
119
  case 'campusId':
105
120
  case 'program_id':
106
121
  case 'programId':
122
+ case 'id':
123
+ case 'institution_id':
124
+ case 'institutionId':
125
+ case 'role_assignment_id':
126
+ case 'roleAssignmentId':
127
+ case 'user_role_id':
128
+ case 'userRoleId':
107
129
  if (isValidUuidString(value)) {
108
130
  returnObj[key] = value;
109
131
  }
@@ -130,13 +152,25 @@ function validateProperties(obj = {}) {
130
152
  case 'weight':
131
153
  case 'dimensions':
132
154
  case 'permission':
155
+ case 'scope_data':
156
+ case 'scopeData':
157
+ case 'meta_data':
158
+ case 'metaData':
133
159
  if (isValidJsonString(JSON.stringify(value))) {
134
160
  returnObj[key] = value;
135
161
  }
136
162
  break;
163
+ case 'aliases':
164
+ if (isValidArrayOfStrings(value)) {
165
+ returnObj[key] = value;
166
+ }
167
+ break;
137
168
  case 'image_url':
138
169
  case 'imageUrl':
139
- if (isImageUrl(value)) {
170
+ case 'website':
171
+ case 'file_url':
172
+ case 'fileUrl':
173
+ if (isImageUrl(value) || isValidUrl(value)) {
140
174
  returnObj[key] = value;
141
175
  }
142
176
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carecard/validate",
3
- "version": "3.0.10",
3
+ "version": "3.0.13",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/CareCard-ca/pkg-validate.git"
@@ -10,7 +10,9 @@
10
10
  "types": "index.d.ts",
11
11
  "scripts": {
12
12
  "test": "export NODE_ENV=test && mocha --recursive",
13
- "test:types": "tsc --noEmit && mocha -r ts-node/register test/types.test.ts"
13
+ "test:types": "tsc --noEmit && mocha -r ts-node/register test/types.test.ts",
14
+ "test:All": "npm run test && npm run test:types",
15
+ "prepare": "husky"
14
16
  },
15
17
  "keywords": [
16
18
  "validate",
@@ -21,6 +23,7 @@
21
23
  "devDependencies": {
22
24
  "@types/mocha": "10.0.10",
23
25
  "@types/node": "25.5.0",
26
+ "husky": "^9.1.7",
24
27
  "mocha": "11.7.5",
25
28
  "ts-node": "10.9.2",
26
29
  "typescript": "5.9.3"