@ttahub/common 2.1.2 → 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/README.md +0 -3
- package/package.json +1 -1
- package/src/constants.js +49 -1
- package/src/utils.js +19 -1
package/README.md
CHANGED
package/package.json
CHANGED
package/src/constants.js
CHANGED
|
@@ -311,7 +311,7 @@ const GOAL_STATUS = {
|
|
|
311
311
|
|
|
312
312
|
exports.GOAL_STATUS = GOAL_STATUS;
|
|
313
313
|
|
|
314
|
-
const SUPPORT_TYPES = [
|
|
314
|
+
const SUPPORT_TYPES = [
|
|
315
315
|
'Introducing',
|
|
316
316
|
'Planning',
|
|
317
317
|
'Implementing',
|
|
@@ -333,3 +333,51 @@ const GROUP_SHARED_WITH = {
|
|
|
333
333
|
};
|
|
334
334
|
|
|
335
335
|
exports.GROUP_SHARED_WITH = GROUP_SHARED_WITH;
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* A list of reasons that a CLOSED goal can be reopened.
|
|
339
|
+
*/
|
|
340
|
+
const REOPEN_CLOSED_REASONS = {
|
|
341
|
+
ACCIDENTALLY_CLOSED: 'Accidentally closed',
|
|
342
|
+
RECIPIENT_REQUEST: 'Recipient request to restart the work',
|
|
343
|
+
PS_REQUEST: 'PS request to restart the work',
|
|
344
|
+
NEW_RECIPIENT_STAFF_REQUEST: 'New recipient staff request similar work',
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* A list of reasons that a SUSPENDED goal can be reopened.
|
|
349
|
+
*/
|
|
350
|
+
const REOPEN_SUSPENDED_REASONS = {};
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* REOPEN_REASONS is a map of FROM status to an array of
|
|
354
|
+
* possible TO statuses.
|
|
355
|
+
*/
|
|
356
|
+
const REOPEN_REASONS = {
|
|
357
|
+
[GOAL_STATUS.CLOSED]: REOPEN_CLOSED_REASONS,
|
|
358
|
+
[GOAL_STATUS.SUSPENDED]: REOPEN_SUSPENDED_REASONS,
|
|
359
|
+
|
|
360
|
+
INFERRED: {
|
|
361
|
+
OBJECTIVE_REOPEN: 'Objective Reopen',
|
|
362
|
+
IMPORTED_FROM_SMARTSHEET: 'Imported from Smartsheet',
|
|
363
|
+
},
|
|
364
|
+
};
|
|
365
|
+
|
|
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
|
|
@@ -32,4 +49,5 @@ function determineMergeGoalStatus(statuses) {
|
|
|
32
49
|
|
|
33
50
|
module.exports = {
|
|
34
51
|
determineMergeGoalStatus,
|
|
52
|
+
isValidResourceUrl,
|
|
35
53
|
}
|