@carecard/validate 2.2.10 → 2.2.11

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/validate.js CHANGED
@@ -185,6 +185,20 @@ const isValidDomainName = (domain) => {
185
185
  return domainRegex.test(domain);
186
186
  };
187
187
 
188
+ const isValidTimestampzString = (str) => {
189
+ if (typeof str !== 'string' || str.length === 0 || str.length > 64) return false;
190
+ // ISO 8601 for UTC or with Offset: 2023-10-27T10:00:00Z or 2023-10-27T10:00:00+02:00
191
+ const timestampzRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/;
192
+ return timestampzRegex.test(str) && !isNaN(Date.parse(str));
193
+ };
194
+
195
+ const isValidTimestampString = (str) => {
196
+ if (typeof str !== 'string' || str.length === 0 || str.length > 64) return false;
197
+ // ISO 8601 without time zone: 2023-10-27T10:00:00 or 2023-10-27T10:00:00.123
198
+ const timestampRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?$/;
199
+ return timestampRegex.test(str) && !isNaN(Date.parse(str));
200
+ };
201
+
188
202
  module.exports = {
189
203
  isImageUrl,
190
204
  isInteger,
@@ -211,5 +225,7 @@ module.exports = {
211
225
  isSafeString,
212
226
  isInStringArray,
213
227
  isCountryCodeString,
214
- isValidDomainName
228
+ isValidDomainName,
229
+ isValidTimestampzString,
230
+ isValidTimestampString
215
231
  };
@@ -14,6 +14,8 @@ const {
14
14
  isValidJsonString,
15
15
  isImageUrl,
16
16
  isValidDomainName,
17
+ isValidTimestampzString,
18
+ isValidTimestampString,
17
19
  } = require('./validate');
18
20
 
19
21
  function validateProperties(obj = {}) {
@@ -148,6 +150,12 @@ function validateProperties(obj = {}) {
148
150
  returnObj[key] = value;
149
151
  }
150
152
  break;
153
+ case 'expires_at':
154
+ case 'expiresAt':
155
+ if (isValidTimestampzString(value) || isValidTimestampString(value)) {
156
+ returnObj[key] = value;
157
+ }
158
+ break;
151
159
  }
152
160
  }
153
161
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carecard/validate",
3
- "version": "2.2.10",
3
+ "version": "2.2.11",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/CareCard-ca/pkg-validate.git"