@ttahub/common 2.1.3 → 2.1.5
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 +1 -1
- package/src/constants.js +17 -0
- package/src/utils.js +26 -2
package/package.json
CHANGED
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,27 @@
|
|
|
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
|
+
|| DISALLOWED_URLS.some((disallowed) => disallowed.url === attempted)
|
|
9
|
+
) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const matches = [...attempted.matchAll(VALID_URL_REGEX)].map(({ groups }) => groups);
|
|
14
|
+
|
|
15
|
+
if (matches?.length !== 1) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const u = new URL(attempted);
|
|
20
|
+
return (u !== '');
|
|
21
|
+
} catch (e) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
2
25
|
|
|
3
26
|
/**
|
|
4
27
|
* Given a list of goal statuses, determine the final status
|
|
@@ -31,5 +54,6 @@ function determineMergeGoalStatus(statuses) {
|
|
|
31
54
|
}
|
|
32
55
|
|
|
33
56
|
module.exports = {
|
|
34
|
-
determineMergeGoalStatus
|
|
57
|
+
determineMergeGoalStatus,
|
|
58
|
+
isValidResourceUrl,
|
|
35
59
|
}
|