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

@hubspot/cms-lib

Package Overview
Dependencies
Maintainers
12
Versions
115
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hubspot/cms-lib - npm Package Compare versions

Comparing version 1.1.8-beta.0 to 1.1.8-beta.1

103

fileManager.js

@@ -15,4 +15,8 @@ const fs = require('fs-extra');

const escapeRegExp = require('./lib/escapeRegExp');
const { convertToUnixPath, convertToLocalFileSystemPath } = require('./path');
const {
getCwd,
convertToUnixPath,
convertToLocalFileSystemPath,
} = require('./path');
const {
ApiErrorContext,

@@ -44,3 +48,8 @@ logApiUploadErrorInstance,

const destPath = convertToUnixPath(path.join(dest, relativePath));
logger.debug('Attempting to upload file "%s" to "%s"', file, destPath);
logger.debug(
'Uploading files from "%s" to "%s" in the File Manager of portal %s',
file,
destPath,
portalId
);
try {

@@ -67,2 +76,20 @@ await uploadFile(portalId, file, destPath);

/**
* @private
* @async
* @param {boolean} input
* @param {string} filepath
* @returns {Promise<boolean}
*/
async function skipExisting(overwrite, filepath) {
if (overwrite) {
return false;
}
if (await fs.pathExists(filepath)) {
logger.log('Skipped existing "%s"', filepath);
return true;
}
return false;
}
/**
*

@@ -72,7 +99,12 @@ * @param {number} portalId

* @param {string} dest
* @param {string} folderPath
* @param {object} options
*/
async function downloadFile(portalId, file, dest, folderPath) {
const relativePath = path.join(folderPath, `${file.name}.${file.extension}`);
const destPath = convertToLocalFileSystemPath(path.join(dest, relativePath));
async function downloadFile(portalId, file, dest, options) {
const fileName = `${file.name}.${file.extension}`;
const destPath = convertToLocalFileSystemPath(path.join(dest, fileName));
if (await skipExisting(options.overwrite, destPath)) {
return;
}
const logFsError = err => {

@@ -107,2 +139,3 @@ logFileSystemErrorInstance(

);
logger.log(`Wrote file "${destPath}"`);
} catch (err) {

@@ -140,15 +173,19 @@ logErrorInstance(err);

* @param {number} portalId
* @param {object} folder
* @param {string} dest
* @param {string} folderPath
* @param {object} options
*/
async function fetchFolderContents(portalId, dest, folderPath) {
const files = await getAllPagedFiles(portalId, folderPath);
async function fetchFolderContents(portalId, folder, dest, options) {
const files = await getAllPagedFiles(portalId, folder.full_path);
for (const file of files) {
await downloadFile(portalId, file, dest, folderPath);
await downloadFile(portalId, file, dest, options);
}
const { objects: folders } = await getFoldersByPath(portalId, folderPath);
const { objects: folders } = await getFoldersByPath(
portalId,
folder.full_path
);
for (const folder of folders) {
await fetchFolderContents(portalId, dest, folder.full_path);
const nestedFolder = path.join(dest, folder.name);
await fetchFolderContents(portalId, folder, nestedFolder, options);
}

@@ -165,10 +202,18 @@ }

*/
async function downloadFileOrFolder(portalId, remotePath, localDest) {
const { file, folder } = await getStat(portalId, remotePath);
async function downloadFileOrFolder(portalId, src, dest, options) {
const { file, folder } = await getStat(portalId, src);
if (file) {
const folderPath = path.dirname(remotePath);
logger.log(
'Fetching file from "%s" to "%s" in the File Manager of portal %s',
src,
dest,
portalId
);
try {
await downloadFile(portalId, file, localDest, folderPath);
logger.log(`File ${remotePath} was downloaded to ${localDest}`);
await downloadFile(portalId, file, dest, options);
logger.success(
'Completed fetch of file "%s" to "%s" from the File Manager',
src,
dest
);
} catch (err) {

@@ -178,7 +223,21 @@ logErrorInstance(err);

} else if (folder) {
logger.log(
'Fetching files from "%s" to "%s" in the File Manager of portal %s',
src,
dest,
portalId
);
try {
await fetchFolderContents(portalId, localDest, folder.full_path);
logger.log(`Folder ${remotePath} was downloaded to ${localDest}`);
const rootPath =
dest === getCwd()
? convertToLocalFileSystemPath(path.resolve(dest, folder.name))
: dest;
await fetchFolderContents(portalId, folder, rootPath, options);
logger.success(
'Completed fetch of folder "%s" to "%s" from the File Manager',
src,
dest
);
} catch (err) {
logErrorInstance(err);
logger.error('Failed fetch of folder "%s" to "%s"', src, dest);
}

@@ -185,0 +244,0 @@ }

{
"name": "@hubspot/cms-lib",
"version": "1.1.8-beta.0",
"version": "1.1.8-beta.1",
"description": "Library for working with the HubSpot CMS",

@@ -34,3 +34,3 @@ "license": "Apache-2.0",

},
"gitHead": "ccf63ec642f6c0980e98ff23187c59098989fe73"
"gitHead": "37b5614bbc6308114b85756e8cad77635e5f8f7a"
}

@@ -1,8 +0,2 @@

const open = require('open');
const moment = require('moment');
const {
promptUser,
PERSONAL_ACCESS_KEY_FLOW,
PERSONAL_ACCESS_KEY,
} = require('@hubspot/cms-cli/lib/prompts');

@@ -17,3 +11,2 @@ const { HubSpotAuthError } = require('@hubspot/api-auth-lib/Errors');

} = require('./lib/config');
const { getHubSpotWebsiteOrigin } = require('./lib/urls');
const { getValidEnv } = require('./lib/environment');

@@ -137,18 +130,2 @@ const {

/**
* Prompts user for portal name, then opens their browser to the shortlink to personal-access-key
*/
const personalAccessKeyPrompt = async ({ env } = {}) => {
const { name } = await promptUser(PERSONAL_ACCESS_KEY_FLOW);
const websiteOrigin = getHubSpotWebsiteOrigin(env || getEnv(name));
open(`${websiteOrigin}/l/personal-access-key`);
const { personalAccessKey } = await promptUser(PERSONAL_ACCESS_KEY);
return {
personalAccessKey,
name,
env,
};
};
/**
* Adds a portal to the config using authType: personalAccessKey

@@ -193,4 +170,3 @@ *

accessTokenForPersonalAccessKey,
personalAccessKeyPrompt,
updateConfigWithPersonalAccessKey,
};
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