'use strict';
-const path = require('path');
-const { name: packageName, version: packageVersion } = require('../package');
-
-const libraryIdentifier = `${packageName}@${packageVersion}`;
-
/**
- * Return a function which combines a part of the filename with a scope, for use in logging.
- * @param {string} filename
+ * @typedef {object} GotResponse
+ * @property {Buffer|string} body response body
+ * @property {Array} redirectUrls followed redirect urls
+ * @property {number=} retryCount retries
+ * @property {object=} timings timings object
+ * @property {object=} timings.phases timing phases object
+ * @property {number=} timings.phases.total timing total ms
*/
-const fileScope = (filename) => {
- const shortFilename = path.basename(filename, '.js');
- const fScope = (shortFilename === 'index') ? path.basename(path.dirname(filename)) : shortFilename;
- return (scope) => [libraryIdentifier, fScope, scope].join(':');
-}
-
-
/**
* Pick out useful got response fields.
- * @param {GotResponse} res
- * @returns {Object}
+ * @param {GotResponse} res response
+ * @returns {object} filtered response
*/
const gotResponseLogData = (res) => {
const data = pick(res, [
'statusMessage',
'headers',
'body',
+ 'url',
+ 'error',
]);
if (typeof res.body === 'string') {
data.body = logTruncate(data.body, 100);
/**
* Limit length of string to keep logs sane
- * @param {String} str
- * @param {Number} len
- * @returns {String}
+ * @param {string} str string
+ * @param {number} len length
+ * @returns {string} truncated string
*/
const logTruncate = (str, len) => {
if (typeof str !== 'string' || str.toString().length <= len) {
/**
* Return a new object with selected props.
- * @param {Object} obj
- * @param {String[]} props
+ * @param {object} obj object
+ * @param {string[]} props list of properties
+ * @returns {object} filtered object
*/
const pick = (obj, props) => {
return props.reduce((acc, prop) => {
/**
* Return a set containing non-shared items between two sets.
- * @param {Set} a
- * @param {Set} b
- * @returns {Set}
+ * @param {Set} a set a
+ * @param {Set} b set b
+ * @returns {Set} set difference
*/
const setSymmetricDifference = (a, b) => {
const d = new Set(a);
/**
* URL objects have weird names.
- * @param {String} component
- * @returns {String}
+ * @param {string} component url component name
+ * @returns {string} translated url component name
*/
const properURLComponentName = (component) => {
// eslint-disable-next-line security/detect-object-injection
hash: 'fragment',
protocol: 'scheme',
}[component] || component;
-}
+};
module.exports = {
- fileScope,
gotResponseLogData,
logTruncate,
pick,
setSymmetricDifference,
properURLComponentName,
-};
\ No newline at end of file
+};