Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

contentful-batch-libs

Package Overview
Dependencies
Maintainers
3
Versions
111
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contentful-batch-libs - npm Package Compare versions

Comparing version 9.1.0 to 9.2.0

dist/add-sequence-header.js

31

dist/get-entity-name.js

@@ -1,5 +0,13 @@

import { get } from 'lodash';
"use strict";
export default function getEntityName(entity) {
const name = get(entity, 'name');
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getEntityName;
var _lodash = require("lodash");
function getEntityName(entity) {
const name = (0, _lodash.get)(entity, 'name');
if (name) {

@@ -9,3 +17,4 @@ return attachId(name, entity);

const titleField = get(entity, 'fields.title');
const titleField = (0, _lodash.get)(entity, 'fields.title');
if (titleField) {

@@ -16,3 +25,4 @@ const locales = Object.keys(titleField);

const nameField = get(entity, 'fields.name');
const nameField = (0, _lodash.get)(entity, 'fields.name');
if (nameField) {

@@ -23,3 +33,4 @@ const locales = Object.keys(nameField);

const id = get(entity, 'sys.id');
const id = (0, _lodash.get)(entity, 'sys.id');
if (id) {

@@ -33,7 +44,11 @@ return id;

function attachId(val, entity) {
const id = get(entity, 'sys.id');
const id = (0, _lodash.get)(entity, 'sys.id');
if (id) {
return `${val} (${id})`;
}
return val;
}
}
module.exports = exports.default;

@@ -1,13 +0,20 @@

import { logToTaskOutput, formatLogMessageOneLine } from './logging';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.wrapTask = wrapTask;
var _logging = require("./logging");
// Set up log emitter listening from SDK, proper error catching and throwing of SDK errors
export function wrapTask(func) {
function wrapTask(func) {
return (ctx, task) => {
const teardownTaskListeners = logToTaskOutput(task);
const teardownTaskListeners = (0, _logging.logToTaskOutput)(task);
return func(ctx, task).then(() => {
teardownTaskListeners();
}).catch(error => {
teardownTaskListeners();
// Format message as human readable listr output
const formattedMessage = formatLogMessageOneLine({
teardownTaskListeners(); // Format message as human readable listr output
const formattedMessage = (0, _logging.formatLogMessageOneLine)({
ts: new Date().toJSON(),

@@ -17,5 +24,4 @@ level: 'error',

});
const enrichedError = new Error(formattedMessage);
const enrichedError = new Error(formattedMessage); // Attach original error object for error log
// Attach original error object for error log
enrichedError.originalError = error;

@@ -22,0 +28,0 @@ throw enrichedError;

@@ -1,17 +0,38 @@

import EventEmitter from 'events';
"use strict";
import bfj from 'bfj';
import { isObject } from 'lodash';
import figures from 'figures';
import moment from 'moment';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.displayErrorLog = displayErrorLog;
exports.formatLogMessageLogfile = formatLogMessageLogfile;
exports.formatLogMessageOneLine = formatLogMessageOneLine;
exports.logEmitter = void 0;
exports.logToTaskOutput = logToTaskOutput;
exports.setupLogging = setupLogging;
exports.writeErrorLogFile = writeErrorLogFile;
import getEntityName from './get-entity-name';
var _events = _interopRequireDefault(require("events"));
export const logEmitter = new EventEmitter();
var _bfj = _interopRequireDefault(require("bfj"));
var _lodash = require("lodash");
var _figures = _interopRequireDefault(require("figures"));
var _moment = _interopRequireDefault(require("moment"));
var _getEntityName = _interopRequireDefault(require("./get-entity-name"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const logEmitter = new _events.default();
exports.logEmitter = logEmitter;
function extractErrorInformation(error) {
const source = error.originalError || error;
try {
const data = JSON.parse(source.message);
if (isObject(data)) {
if ((0, _lodash.isObject)(data)) {
return data;

@@ -24,13 +45,19 @@ }

export function formatLogMessageOneLine(logMessage) {
const { level } = logMessage;
function formatLogMessageOneLine(logMessage) {
const {
level
} = logMessage;
if (!level) {
return logMessage.toString().replace(/\s+/g, ' ');
}
if (level === 'info') {
return logMessage.info;
}
if (level === 'warning') {
return logMessage.warning;
}
try {

@@ -40,2 +67,3 @@ // Display enhanced API error message when available

const data = extractErrorInformation(logMessage.error);
if ('status' in data || 'statusText' in data) {

@@ -45,8 +73,11 @@ const status = [data.status, data.statusText].filter(a => a).join(' - ');

}
if ('message' in data) {
errorOutput.push(`Message: ${data.message}`);
}
if ('entity' in data) {
errorOutput.push(`Entity: ${getEntityName(data.entity)}`);
errorOutput.push(`Entity: ${(0, _getEntityName.default)(data.entity)}`);
}
if ('details' in data && 'errors' in data.details) {

@@ -56,5 +87,7 @@ const errorList = data.details.errors.map(error => error.details || error.name);

}
if ('requestId' in data) {
errorOutput.push(`Request ID: ${data.requestId}`);
}
return `${logMessage.error.name}: ${errorOutput.join(' - ')}`;

@@ -67,7 +100,11 @@ } catch (err) {

export function formatLogMessageLogfile(logMessage) {
const { level } = logMessage;
function formatLogMessageLogfile(logMessage) {
const {
level
} = logMessage;
if (level === 'info' || level === 'warning') {
return logMessage;
}
if (!logMessage.error) {

@@ -77,6 +114,9 @@ // Enhance node errors to logMessage format

}
try {
// Enhance error with extracted API error log
const data = extractErrorInformation(logMessage.error);
const errorOutput = Object.assign({}, logMessage.error, { data });
const errorOutput = Object.assign({}, logMessage.error, {
data
});
delete errorOutput.message;

@@ -89,6 +129,6 @@ logMessage.error = errorOutput;

}
}
} // Listr attaches the whole context to error messages.
// Remove it to avoid error log file pollution.
// Listr attaches the whole context to error messages.
// Remove it to avoid error log file pollution.
if (typeof logMessage.error === 'object' && 'context' in logMessage.error) {

@@ -99,6 +139,6 @@ delete logMessage.error.context;

return logMessage;
}
} // Display all errors
// Display all errors
export function displayErrorLog(errorLog) {
function displayErrorLog(errorLog) {
if (errorLog.length) {

@@ -108,15 +148,13 @@ const warningsCount = errorLog.filter(error => Object.prototype.hasOwnProperty.call(error, 'warning')).length;

console.log(`\n\nThe following ${errorsCount} errors and ${warningsCount} warnings occurred:\n`);
errorLog.map(logMessage => `${moment(logMessage.ts).format('HH:mm:SS')} - ${formatLogMessageOneLine(logMessage)}`).map(logMessage => console.log(logMessage));
errorLog.map(logMessage => `${(0, _moment.default)(logMessage.ts).format('HH:mm:SS')} - ${formatLogMessageOneLine(logMessage)}`).map(logMessage => console.log(logMessage));
return;
}
console.log('No errors or warnings occurred');
}
} // Write all log messages instead of infos to the error log file
// Write all log messages instead of infos to the error log file
export function writeErrorLogFile(destination, errorLog) {
function writeErrorLogFile(destination, errorLog) {
const logFileData = errorLog.map(formatLogMessageLogfile);
return bfj.write(destination, logFileData, {
return _bfj.default.write(destination, logFileData, {
circular: 'ignore',

@@ -131,6 +169,6 @@ space: 2

});
}
} // Init listeners for log messages, transform them into proper format and logs/displays them
// Init listeners for log messages, transform them into proper format and logs/displays them
export function setupLogging(log) {
function setupLogging(log) {
function errorLogger(level, error) {

@@ -142,5 +180,7 @@ const logMessage = {

};
if (level !== 'info') {
log.push(logMessage);
}
logEmitter.emit('display', logMessage);

@@ -152,12 +192,12 @@ }

logEmitter.addListener('error', error => errorLogger('error', error));
}
} // Format log message to display them as task status
// Format log message to display them as task status
export function logToTaskOutput(task) {
function logToTaskOutput(task) {
function logToTask(logMessage) {
const content = formatLogMessageOneLine(logMessage);
const symbols = {
info: figures.tick,
warning: figures.warning,
error: figures.cross
info: _figures.default.tick,
warning: _figures.default.warning,
error: _figures.default.cross
};

@@ -168,5 +208,3 @@ task.output = `${symbols[logMessage.level]} ${content}`.trim();

const startTime = Date.now();
logEmitter.on('display', logToTask);
return () => {

@@ -173,0 +211,0 @@ const seconds = Math.ceil((Date.now() - startTime) / 1000);

@@ -1,6 +0,22 @@

import { URL, format } from 'url';
import { toInteger } from 'lodash';
import HttpsProxyAgent from 'https-proxy-agent';
"use strict";
function serializeAuth({ username, password } = {}) {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.agentFromProxy = agentFromProxy;
exports.proxyObjectToString = proxyObjectToString;
exports.proxyStringToObject = proxyStringToObject;
var _url = require("url");
var _lodash = require("lodash");
var _httpsProxyAgent = _interopRequireDefault(require("https-proxy-agent"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function serializeAuth({
username,
password
} = {}) {
if (!username) {

@@ -17,3 +33,3 @@ return '';

export function proxyStringToObject(proxyString) {
function proxyStringToObject(proxyString) {
if (!proxyString.startsWith('http')) {

@@ -23,8 +39,6 @@ return proxyStringToObject(`http://${proxyString}`);

const parsedUrl = new URL(proxyString);
const parsedUrl = new _url.URL(proxyString);
const host = parsedUrl.hostname;
const portString = parsedUrl.port;
const protocol = parsedUrl.protocol;
const auth = {

@@ -34,7 +48,11 @@ username: parsedUrl.username,

};
const port = toInteger(portString);
const port = (0, _lodash.toInteger)(portString);
const isHttps = protocol === 'https:';
if (!auth.username) {
return { host, port, isHttps };
return {
host,
port,
isHttps
};
}

@@ -50,16 +68,23 @@

export function proxyObjectToString(proxyObject) {
const { host: hostname, port, auth: authObject } = proxyObject;
function proxyObjectToString(proxyObject) {
const {
host: hostname,
port,
auth: authObject
} = proxyObject;
const auth = serializeAuth(authObject);
const formatted = (0, _url.format)({
hostname,
port,
auth
}); // Ugly fix for Node 6 vs Node 8 behavior
const formatted = format({ hostname, port, auth });
// Ugly fix for Node 6 vs Node 8 behavior
return formatted.replace(/^\/\//, '');
}
export function agentFromProxy(proxy) {
function agentFromProxy(proxy) {
if (!proxy) {
return {};
}
['http_proxy', 'https_proxy'].forEach(envStr => {

@@ -69,5 +94,11 @@ delete process.env[envStr];

});
const { host, port } = proxy;
const agent = new HttpsProxyAgent({ host, port });
const {
host,
port
} = proxy;
const agent = new _httpsProxyAgent.default({
host,
port
});
return agent;
}
{
"name": "contentful-batch-libs",
"version": "9.1.0",
"version": "9.2.0",
"description": "Library modules used by contentful batch utility CLI tools.",
"main": "dist/index.js",
"engines": {
"node": ">=6"
"node": ">=12"
},

@@ -29,11 +29,13 @@ "scripts": {

"lodash": "^4.17.21",
"moment": "^2.29.1"
"moment": "^2.29.1",
"uuid": "^8.3.2"
},
"devDependencies": {
"@babel/cli": "^7.16.0",
"@babel/core": "^7.16.0",
"@babel/preset-env": "^7.16.4",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.2",
"babel-jest": "^27.3.1",
"babel-plugin-add-module-exports": "^1.0.4",
"babel-preset-env": "^1.7.0",
"cz-conventional-changelog": "^3.3.0",

@@ -40,0 +42,0 @@ "eslint": "^8.3.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc