@ttahub/common 2.1.3 → 2.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttahub/common",
3
- "version": "2.1.3",
3
+ "version": "2.1.4",
4
4
  "description": "The purpose of this package is to reduce code duplication between the frontend and backend projects.",
5
5
  "main": "src/index.js",
6
6
  "author": "",
package/src/constants.js CHANGED
@@ -364,3 +364,20 @@ const REOPEN_REASONS = {
364
364
  };
365
365
 
366
366
  exports.REOPEN_REASONS = REOPEN_REASONS;
367
+
368
+ const DISALLOWED_URLS = [{
369
+ url: 'https://eclkc.ohs.acf.hhs.gov/professional-development/individualized-professional-development-ipd-portfolio/course-catalog',
370
+ error: 'This link is no longer accepted in this field. Enter iPD courses used during your TTA session in the other field in this section.',
371
+ }, {
372
+ url: 'https://eclkc.ohs.acf.hhs.gov/professional-development/individualized-professional-development-ipd-portfolio/individualized-professional-development-ipd-portfolio',
373
+ error: 'This link is no longer accepted in this field. Enter iPD courses used during your TTA session in the other field in this section.',
374
+ }, {
375
+ url: 'https://eclkc.ohs.acf.hhs.gov/cas/login',
376
+ error: 'This link is no longer accepted in this field. Enter iPD courses used during your TTA session in the other field in this section.',
377
+ }];
378
+
379
+ exports.DISALLOWED_URLS = DISALLOWED_URLS;
380
+
381
+ const VALID_URL_REGEX = /(?<url>(?<scheme>http(?:s)?):\/\/(?:(?<user>[a-zA-Z0-9._]+)(?:[:](?<password>[a-zA-Z0-9%._\+~#=]+))?[@])?(?:(?:www\.)?(?<host>[-a-zA-Z0-9%._\+~#=]{1,}\.[a-z]{2,6})|(?<ip>(?:[0-9]{1,3}\.){3}[0-9]{1,3}))(?:[:](?<port>[0-9]+))?(?:[\/](?<path>[-a-zA-Z0-9'@:%_\+.,~#&\/=()]*[-a-zA-Z0-9@:%_\+.~#&\/=()])?)?(?:[?](?<query>[-a-zA-Z0-9@:%_\+.~#&\/=()]*))*)/ig;
382
+ exports.VALID_URL_REGEX = VALID_URL_REGEX;
383
+
package/src/utils.js CHANGED
@@ -1,4 +1,21 @@
1
- const { GOAL_STATUS } = require('./constants');
1
+ const { GOAL_STATUS, DISALLOWED_URLS, VALID_URL_REGEX } = require('./constants');
2
+
3
+ function isValidResourceUrl(attempted) {
4
+ try {
5
+ const httpOccurences = (attempted.match(/http/gi) || []).length;
6
+ if (
7
+ httpOccurences !== 1
8
+ || !VALID_URL_REGEX.test(attempted)
9
+ || DISALLOWED_URLS.some((disallowed) => disallowed.url === attempted)
10
+ ) {
11
+ return false;
12
+ }
13
+ const u = new URL(attempted);
14
+ return (u !== '');
15
+ } catch (e) {
16
+ return false;
17
+ }
18
+ };
2
19
 
3
20
  /**
4
21
  * Given a list of goal statuses, determine the final status
@@ -31,5 +48,6 @@ function determineMergeGoalStatus(statuses) {
31
48
  }
32
49
 
33
50
  module.exports = {
34
- determineMergeGoalStatus
51
+ determineMergeGoalStatus,
52
+ isValidResourceUrl,
35
53
  }