Utils.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. "use strict";
  2. function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
  3. function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
  4. function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
  5. function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
  6. function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
  7. /**
  8. * utils.js
  9. * @file General purpose utilities
  10. * @description General purpose utilities.
  11. */
  12. const path = require('path');
  13. const fs = require('fs').promises;
  14. /**
  15. * The general purpose utilities.
  16. */
  17. class Utils {
  18. /**
  19. * @function getLocalizedPath
  20. * @description Returns a localized file path accoring to the locale.
  21. *
  22. * Localized files are searched in subfolders of a given path, e.g.
  23. *
  24. * root/
  25. * ├── base/ // base path to files
  26. * │ ├── example.html // default file
  27. * │ └── de/ // de language folder
  28. * │ │ └── example.html // de localized file
  29. * │ └── de-AT/ // de-AT locale folder
  30. * │ │ └── example.html // de-AT localized file
  31. *
  32. * Files are matched with the locale in the following order:
  33. * 1. Locale match, e.g. locale `de-AT` matches file in folder `de-AT`.
  34. * 2. Language match, e.g. locale `de-AT` matches file in folder `de`.
  35. * 3. Default; file in base folder is returned.
  36. *
  37. * @param {String} defaultPath The absolute file path, which is also
  38. * the default path returned if localization is not available.
  39. * @param {String} locale The locale.
  40. * @returns {Promise<Object>} The object contains:
  41. * - `path`: The path to the localized file, or the original path if
  42. * localization is not available.
  43. * - `subdir`: The subdirectory of the localized file, or undefined if
  44. * there is no matching localized file.
  45. */
  46. static async getLocalizedPath(defaultPath, locale) {
  47. // Get file name and paths
  48. const file = path.basename(defaultPath);
  49. const basePath = path.dirname(defaultPath);
  50. // If locale is not set return default file
  51. if (!locale) {
  52. return {
  53. path: defaultPath
  54. };
  55. }
  56. // Check file for locale exists
  57. const localePath = path.join(basePath, locale, file);
  58. const localeFileExists = await Utils.fileExists(localePath);
  59. // If file for locale exists return file
  60. if (localeFileExists) {
  61. return {
  62. path: localePath,
  63. subdir: locale
  64. };
  65. }
  66. // Check file for language exists
  67. const language = locale.split('-')[0];
  68. const languagePath = path.join(basePath, language, file);
  69. const languageFileExists = await Utils.fileExists(languagePath);
  70. // If file for language exists return file
  71. if (languageFileExists) {
  72. return {
  73. path: languagePath,
  74. subdir: language
  75. };
  76. }
  77. // Return default file
  78. return {
  79. path: defaultPath
  80. };
  81. }
  82. /**
  83. * @function fileExists
  84. * @description Checks whether a file exists.
  85. * @param {String} path The file path.
  86. * @returns {Promise<Boolean>} Is true if the file can be accessed, false otherwise.
  87. */
  88. static async fileExists(path) {
  89. try {
  90. await fs.access(path);
  91. return true;
  92. } catch (e) {
  93. return false;
  94. }
  95. }
  96. /**
  97. * @function isPath
  98. * @description Evaluates whether a string is a file path (as opposed to a URL for example).
  99. * @param {String} s The string to evaluate.
  100. * @returns {Boolean} Returns true if the evaluated string is a path.
  101. */
  102. static isPath(s) {
  103. return /(^\/)|(^\.\/)|(^\.\.\/)/.test(s);
  104. }
  105. /**
  106. * Flattens an object and crates new keys with custom delimiters.
  107. * @param {Object} obj The object to flatten.
  108. * @param {String} [delimiter='.'] The delimiter of the newly generated keys.
  109. * @param {Object} result
  110. * @returns {Object} The flattened object.
  111. **/
  112. static flattenObject(obj, parentKey, delimiter = '.', result = {}) {
  113. for (const key in obj) {
  114. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  115. const newKey = parentKey ? parentKey + delimiter + key : key;
  116. if (typeof obj[key] === 'object' && obj[key] !== null) {
  117. this.flattenObject(obj[key], newKey, delimiter, result);
  118. } else {
  119. result[newKey] = obj[key];
  120. }
  121. }
  122. }
  123. return result;
  124. }
  125. /**
  126. * Determines whether an object is a Promise.
  127. * @param {any} object The object to validate.
  128. * @returns {Boolean} Returns true if the object is a promise.
  129. */
  130. static isPromise(object) {
  131. return object instanceof Promise;
  132. }
  133. /**
  134. * Creates an object with all permutations of the original keys.
  135. * For example, this definition:
  136. * ```
  137. * {
  138. * a: [true, false],
  139. * b: [1, 2],
  140. * c: ['x']
  141. * }
  142. * ```
  143. * permutates to:
  144. * ```
  145. * [
  146. * { a: true, b: 1, c: 'x' },
  147. * { a: true, b: 2, c: 'x' },
  148. * { a: false, b: 1, c: 'x' },
  149. * { a: false, b: 2, c: 'x' }
  150. * ]
  151. * ```
  152. * @param {Object} object The object to permutate.
  153. * @param {Integer} [index=0] The current key index.
  154. * @param {Object} [current={}] The current result entry being composed.
  155. * @param {Array} [results=[]] The resulting array of permutations.
  156. */
  157. static getObjectKeyPermutations(object, index = 0, current = {}, results = []) {
  158. const keys = Object.keys(object);
  159. const key = keys[index];
  160. const values = object[key];
  161. for (const value of values) {
  162. current[key] = value;
  163. const nextIndex = index + 1;
  164. if (nextIndex < keys.length) {
  165. Utils.getObjectKeyPermutations(object, nextIndex, current, results);
  166. } else {
  167. const result = Object.assign({}, current);
  168. results.push(result);
  169. }
  170. }
  171. return results;
  172. }
  173. /**
  174. * Validates parameters and throws if a parameter is invalid.
  175. * Example parameter types syntax:
  176. * ```
  177. * {
  178. * parameterName: {
  179. * t: 'boolean',
  180. * v: isBoolean,
  181. * o: true
  182. * },
  183. * ...
  184. * }
  185. * ```
  186. * @param {Object} params The parameters to validate.
  187. * @param {Array<Object>} types The parameter types used for validation.
  188. * @param {Object} types.t The parameter type; used for error message, not for validation.
  189. * @param {Object} types.v The function to validate the parameter value.
  190. * @param {Boolean} [types.o=false] Is true if the parameter is optional.
  191. */
  192. static validateParams(params, types) {
  193. for (const key of Object.keys(params)) {
  194. const type = types[key];
  195. const isOptional = !!type.o;
  196. const param = params[key];
  197. if (!(isOptional && param == null) && !type.v(param)) {
  198. throw `Invalid parameter ${key} must be of type ${type.t} but is ${typeof param}`;
  199. }
  200. }
  201. }
  202. /**
  203. * Computes the relative date based on a string.
  204. * @param {String} text The string to interpret the date from.
  205. * @param {Date} now The date the string is comparing against.
  206. * @returns {Object} The relative date object.
  207. **/
  208. static relativeTimeToDate(text, now = new Date()) {
  209. text = text.toLowerCase();
  210. let parts = text.split(' ');
  211. // Filter out whitespace
  212. parts = parts.filter(part => part !== '');
  213. const future = parts[0] === 'in';
  214. const past = parts[parts.length - 1] === 'ago';
  215. if (!future && !past && text !== 'now') {
  216. return {
  217. status: 'error',
  218. info: "Time should either start with 'in' or end with 'ago'"
  219. };
  220. }
  221. if (future && past) {
  222. return {
  223. status: 'error',
  224. info: "Time cannot have both 'in' and 'ago'"
  225. };
  226. }
  227. // strip the 'ago' or 'in'
  228. if (future) {
  229. parts = parts.slice(1);
  230. } else {
  231. // past
  232. parts = parts.slice(0, parts.length - 1);
  233. }
  234. if (parts.length % 2 !== 0 && text !== 'now') {
  235. return {
  236. status: 'error',
  237. info: 'Invalid time string. Dangling unit or number.'
  238. };
  239. }
  240. const pairs = [];
  241. while (parts.length) {
  242. pairs.push([parts.shift(), parts.shift()]);
  243. }
  244. let seconds = 0;
  245. for (const [num, interval] of pairs) {
  246. const val = Number(num);
  247. if (!Number.isInteger(val)) {
  248. return {
  249. status: 'error',
  250. info: `'${num}' is not an integer.`
  251. };
  252. }
  253. switch (interval) {
  254. case 'yr':
  255. case 'yrs':
  256. case 'year':
  257. case 'years':
  258. seconds += val * 31536000; // 365 * 24 * 60 * 60
  259. break;
  260. case 'wk':
  261. case 'wks':
  262. case 'week':
  263. case 'weeks':
  264. seconds += val * 604800; // 7 * 24 * 60 * 60
  265. break;
  266. case 'd':
  267. case 'day':
  268. case 'days':
  269. seconds += val * 86400; // 24 * 60 * 60
  270. break;
  271. case 'hr':
  272. case 'hrs':
  273. case 'hour':
  274. case 'hours':
  275. seconds += val * 3600; // 60 * 60
  276. break;
  277. case 'min':
  278. case 'mins':
  279. case 'minute':
  280. case 'minutes':
  281. seconds += val * 60;
  282. break;
  283. case 'sec':
  284. case 'secs':
  285. case 'second':
  286. case 'seconds':
  287. seconds += val;
  288. break;
  289. default:
  290. return {
  291. status: 'error',
  292. info: `Invalid interval: '${interval}'`
  293. };
  294. }
  295. }
  296. const milliseconds = seconds * 1000;
  297. if (future) {
  298. return {
  299. status: 'success',
  300. info: 'future',
  301. result: new Date(now.valueOf() + milliseconds)
  302. };
  303. } else if (past) {
  304. return {
  305. status: 'success',
  306. info: 'past',
  307. result: new Date(now.valueOf() - milliseconds)
  308. };
  309. } else {
  310. return {
  311. status: 'success',
  312. info: 'present',
  313. result: new Date(now.valueOf())
  314. };
  315. }
  316. }
  317. /**
  318. * Deep-scans an object for a matching key/value definition.
  319. * @param {Object} obj The object to scan.
  320. * @param {String | undefined} key The key to match, or undefined if only the value should be matched.
  321. * @param {any | undefined} value The value to match, or undefined if only the key should be matched.
  322. * @returns {Boolean} True if a match was found, false otherwise.
  323. */
  324. static objectContainsKeyValue(obj, key, value) {
  325. const isMatch = (a, b) => typeof a === 'string' && new RegExp(b).test(a) || a === b;
  326. const isKeyMatch = k => isMatch(k, key);
  327. const isValueMatch = v => isMatch(v, value);
  328. for (const [k, v] of Object.entries(obj)) {
  329. if (key !== undefined && value === undefined && isKeyMatch(k)) {
  330. return true;
  331. } else if (key === undefined && value !== undefined && isValueMatch(v)) {
  332. return true;
  333. } else if (key !== undefined && value !== undefined && isKeyMatch(k) && isValueMatch(v)) {
  334. return true;
  335. }
  336. if (['[object Object]', '[object Array]'].includes(Object.prototype.toString.call(v))) {
  337. return Utils.objectContainsKeyValue(v, key, value);
  338. }
  339. }
  340. return false;
  341. }
  342. static checkProhibitedKeywords(config, data) {
  343. if (config !== null && config !== void 0 && config.requestKeywordDenylist) {
  344. // Scan request data for denied keywords
  345. for (const keyword of config.requestKeywordDenylist) {
  346. const match = Utils.objectContainsKeyValue(data, keyword.key, keyword.value);
  347. if (match) {
  348. throw `Prohibited keyword in request data: ${JSON.stringify(keyword)}.`;
  349. }
  350. }
  351. }
  352. }
  353. /**
  354. * Moves the nested keys of a specified key in an object to the root of the object.
  355. *
  356. * @param {Object} obj The object to modify.
  357. * @param {String} key The key whose nested keys will be moved to root.
  358. * @returns {Object} The modified object, or the original object if no modification happened.
  359. * @example
  360. * const obj = {
  361. * a: 1,
  362. * b: {
  363. * c: 2,
  364. * d: 3
  365. * },
  366. * e: 4
  367. * };
  368. * addNestedKeysToRoot(obj, 'b');
  369. * console.log(obj);
  370. * // Output: { a: 1, e: 4, c: 2, d: 3 }
  371. */
  372. static addNestedKeysToRoot(obj, key) {
  373. if (obj[key] && typeof obj[key] === 'object') {
  374. // Add nested keys to root
  375. Object.assign(obj, _objectSpread({}, obj[key]));
  376. // Delete original nested key
  377. delete obj[key];
  378. }
  379. return obj;
  380. }
  381. }
  382. module.exports = Utils;
  383. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJwYXRoIiwicmVxdWlyZSIsImZzIiwicHJvbWlzZXMiLCJVdGlscyIsImdldExvY2FsaXplZFBhdGgiLCJkZWZhdWx0UGF0aCIsImxvY2FsZSIsImZpbGUiLCJiYXNlbmFtZSIsImJhc2VQYXRoIiwiZGlybmFtZSIsImxvY2FsZVBhdGgiLCJqb2luIiwibG9jYWxlRmlsZUV4aXN0cyIsImZpbGVFeGlzdHMiLCJzdWJkaXIiLCJsYW5ndWFnZSIsInNwbGl0IiwibGFuZ3VhZ2VQYXRoIiwibGFuZ3VhZ2VGaWxlRXhpc3RzIiwiYWNjZXNzIiwiZSIsImlzUGF0aCIsInMiLCJ0ZXN0IiwiZmxhdHRlbk9iamVjdCIsIm9iaiIsInBhcmVudEtleSIsImRlbGltaXRlciIsInJlc3VsdCIsImtleSIsIk9iamVjdCIsInByb3RvdHlwZSIsImhhc093blByb3BlcnR5IiwiY2FsbCIsIm5ld0tleSIsImlzUHJvbWlzZSIsIm9iamVjdCIsIlByb21pc2UiLCJnZXRPYmplY3RLZXlQZXJtdXRhdGlvbnMiLCJpbmRleCIsImN1cnJlbnQiLCJyZXN1bHRzIiwia2V5cyIsInZhbHVlcyIsInZhbHVlIiwibmV4dEluZGV4IiwibGVuZ3RoIiwiYXNzaWduIiwicHVzaCIsInZhbGlkYXRlUGFyYW1zIiwicGFyYW1zIiwidHlwZXMiLCJ0eXBlIiwiaXNPcHRpb25hbCIsIm8iLCJwYXJhbSIsInYiLCJ0IiwicmVsYXRpdmVUaW1lVG9EYXRlIiwidGV4dCIsIm5vdyIsIkRhdGUiLCJ0b0xvd2VyQ2FzZSIsInBhcnRzIiwiZmlsdGVyIiwicGFydCIsImZ1dHVyZSIsInBhc3QiLCJzdGF0dXMiLCJp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ICBzZWNvbmRzICs9IHZhbCAqIDg2NDAwOyAvLyAyNCAqIDYwICogNjBcbiAgICAgICAgICBicmVhaztcblxuICAgICAgICBjYXNlICdocic6XG4gICAgICAgIGNhc2UgJ2hycyc6XG4gICAgICAgIGNhc2UgJ2hvdXInOlxuICAgICAgICBjYXNlICdob3Vycyc6XG4gICAgICAgICAgc2Vjb25kcyArPSB2YWwgKiAzNjAwOyAvLyA2MCAqIDYwXG4gICAgICAgICAgYnJlYWs7XG5cbiAgICAgICAgY2FzZSAnbWluJzpcbiAgICAgICAgY2FzZSAnbWlucyc6XG4gICAgICAgIGNhc2UgJ21pbnV0ZSc6XG4gICAgICAgIGNhc2UgJ21pbnV0ZXMnOlxuICAgICAgICAgIHNlY29uZHMgKz0gdmFsICogNjA7XG4gICAgICAgICAgYnJlYWs7XG5cbiAgICAgICAgY2FzZSAnc2VjJzpcbiAgICAgICAgY2FzZSAnc2Vjcyc6XG4gICAgICAgIGNhc2UgJ3NlY29uZCc6XG4gICAgICAgIGNhc2UgJ3NlY29uZHMnOlxuICAgICAgICAgIHNlY29uZHMgKz0gdmFsO1xuICAgICAgICAgIGJyZWFrO1xuXG4gICAgICAgIGRlZmF1bHQ6XG4gICAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgIHN0YXR1czogJ2Vycm9yJyxcbiAgICAgICAgICAgIGluZm86IGBJbnZhbGlkIGludGVydmFsOiAnJHtpbnRlcnZhbH0nYCxcbiAgICAgICAgICB9O1xuICAgICAgfVxuICAgIH1cblxuICAgIGNvbnN0IG1pbGxpc2Vjb25kcyA9IHNlY29uZHMgKiAxMDAwO1xuICAgIGlmIChmdXR1cmUpIHtcbiAgICAgIHJldHVybiB7XG4gICAgICAgIHN0YXR1czogJ3N1Y2Nlc3MnLFxuICAgICAgICBpbmZvOiAnZnV0dXJlJyxcbiAgICAgICAgcmVzdWx0OiBuZXcgRGF0ZShub3cudmFsdWVPZigpICsgbWlsbGlzZWNvbmRzKSxcbiAgICAgIH07X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