3 const path
= require('path');
6 * Return a function which combines a part of the filename with a scope, for use in logging.
7 * @param {string} filename
9 const fileScope
= (filename
) => {
10 let fScope
= path
.basename(filename
, '.js');
11 if (fScope
=== 'index') {
12 fScope
= path
.basename(path
.dirname(filename
));
14 return (scope
) => `${fScope}:${scope}`;
19 * Convert Base64 to Base64URL.
20 * @param {String} input
23 const base64ToBase64URL
= (input
) => {
32 * Pick out useful axios response fields.
36 const axiosResponseLogData
= (res
) => {
37 const data
= pick(res
, [
45 data
.data
= logTruncate(data
.data
, 100);
52 * Limit length of string to keep logs sane
57 const logTruncate
= (str
, len
) => {
58 if (typeof str
!== 'string' || str
.toString().length
<= len
) {
61 return str
.toString().slice(0, len
) + `... (${str.toString().length} bytes)`;
66 * Return a new object with selected props.
68 * @param {String[]} props
70 const pick
= (obj
, props
) => {
71 return props
.reduce((acc
, prop
) => {
73 acc
[prop
] = obj
[prop
]; // eslint-disable-line security/detect-object-injection