Socket
Socket
Sign inDemoInstall

@hubspot/cms-lib

Package Overview
Dependencies
15
Maintainers
13
Versions
115
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.1-beta.10 to 2.2.1-beta.0

44

__tests__/errorHandlers.js
const { StatusCodeError } = require('request-promise-native/errors');
const { getPortalConfig } = require('../lib/config');
const { getAccountConfig } = require('../lib/config');
const { fetchScopeData } = require('../api/localDevAuth/authenticated');

@@ -61,3 +61,3 @@ const {

const errorContext = Object.freeze({
portalId: 12345,
accountId: 12345,
});

@@ -115,14 +115,14 @@

expect(logger.logs[LOG_LEVEL.ERROR]).toEqual([
'The request for "a/b/c" in portal 12345 failed.',
'The request in portal 12345 was not found.',
'The request failed because "a/b/c" was not found in portal 12345.',
'Unable to upload "new.js". The update failed because "a/b/c" was not found in portal 12345.',
'Unable to upload "new.js". The post failed because "a/b/c" was not found in portal 12345.',
'The delete failed because "a/b/c" was not found in portal 12345.',
'The delete of "a/b/c" in portal 12345 failed due to a server error. Please try again or visit https://help.hubspot.com/ to submit a ticket or contact HubSpot Support if the issue persists.',
'The request for "a/b/c" in portal 12345 failed due to a server error. Please try again or visit https://help.hubspot.com/ to submit a ticket or contact HubSpot Support if the issue persists.',
'Unable to upload "new.js". The post to "a/b/c" in portal 12345 failed due to a server error. Please try again or visit https://help.hubspot.com/ to submit a ticket or contact HubSpot Support if the issue persists.',
'The request for "a/b/c" in portal 12345 could not be handled at this time. Please try again or visit https://help.hubspot.com/ to submit a ticket or contact HubSpot Support if the issue persists.',
'The post failed because "a/b/c" was not found in portal 12345.',
'The request failed because "a/b/c" was not found in portal 12345. Meaningful message from server.',
'The request for "a/b/c" in account 12345 failed.',
'The request in account 12345 was not found.',
'The request failed because "a/b/c" was not found in account 12345.',
'Unable to upload "new.js". The update failed because "a/b/c" was not found in account 12345.',
'Unable to upload "new.js". The post failed because "a/b/c" was not found in account 12345.',
'The delete failed because "a/b/c" was not found in account 12345.',
'The delete of "a/b/c" in account 12345 failed due to a server error. Please try again or visit https://help.hubspot.com/ to submit a ticket or contact HubSpot Support if the issue persists.',
'The request for "a/b/c" in account 12345 failed due to a server error. Please try again or visit https://help.hubspot.com/ to submit a ticket or contact HubSpot Support if the issue persists.',
'Unable to upload "new.js". The post to "a/b/c" in account 12345 failed due to a server error. Please try again or visit https://help.hubspot.com/ to submit a ticket or contact HubSpot Support if the issue persists.',
'The request for "a/b/c" in account 12345 could not be handled at this time. Please try again or visit https://help.hubspot.com/ to submit a ticket or contact HubSpot Support if the issue persists.',
'The post failed because "a/b/c" was not found in account 12345.',
'The request failed because "a/b/c" was not found in account 12345. Meaningful message from server.',
]);

@@ -193,8 +193,8 @@ });

describe('logServerlessApiErrorInstance', () => {
const portalId = 123;
const accountId = 123;
const logErrorSpy = jest.spyOn(logger, 'error');
beforeEach(() => {
logger.clear();
getPortalConfig.mockReturnValue({
portalId,
getAccountConfig.mockReturnValue({
accountId,
authType: 'personalaccesskey',

@@ -211,7 +211,7 @@ personalAccessKey: 'let-me-in',

await logServerlessFunctionApiErrorInstance(
portalId,
accountId,
error,
new ApiErrorContext({
request: 'add secret',
portalId,
accountId,
})

@@ -229,3 +229,3 @@ );

Promise.resolve({
portalId,
accountId,
userId: 456,

@@ -251,7 +251,7 @@ scopeGroup: 'cms.functions.read_write',

await logServerlessFunctionApiErrorInstance(
portalId,
accountId,
error,
new ApiErrorContext({
request: 'add secret',
portalId,
accountId,
})

@@ -258,0 +258,0 @@ );

@@ -24,7 +24,7 @@ const { uploadFolder } = require('../fileManager');

const portalId = 123;
const accountId = 123;
const src = 'folder';
const dest = 'folder';
await uploadFolder(portalId, src, dest, { cwd: '/home/tom' });
await uploadFolder(accountId, src, dest, { cwd: '/home/tom' });

@@ -34,3 +34,3 @@ expect(uploadFile).toReturnTimes(4);

files.forEach((file, index) => {
expect(uploadFile).nthCalledWith(index + 1, portalId, file, file);
expect(uploadFile).nthCalledWith(index + 1, accountId, file, file);
});

@@ -37,0 +37,0 @@ });

@@ -199,7 +199,7 @@ const path = require('path');

describe('fetchFolderFromApi()', () => {
const portalId = 67890;
const accountId = 67890;
describe('fetch folder', () => {
const input = {
portalId,
accountId,
src: '1234',

@@ -227,3 +227,3 @@ };

const input = {
portalId,
accountId,
src: 'cms-theme-boilerplate/modules/Card section.module',

@@ -256,3 +256,3 @@ };

const input = {
portalId,
accountId,
src: '/',

@@ -259,0 +259,0 @@ };

@@ -5,3 +5,3 @@ const requestPN = require('request-promise-native');

const moment = require('moment');
const { getAndLoadConfigIfNeeded, getPortalConfig } = require('../lib/config');
const { getAndLoadConfigIfNeeded, getAccountConfig } = require('../lib/config');
const { ENVIRONMENTS } = require('../lib/constants');

@@ -24,3 +24,3 @@ const http = require('../http');

getAndLoadConfigIfNeeded.mockReset();
getPortalConfig.mockReset();
getAccountConfig.mockReset();
});

@@ -33,3 +33,3 @@ describe('getOctetStream()', () => {

{
id: 123,
portalId: 123,
apiKey: 'abc',

@@ -39,4 +39,4 @@ },

});
getPortalConfig.mockReturnValue({
id: 123,
getAccountConfig.mockReturnValue({
portalId: 123,
apiKey: 'abc',

@@ -113,3 +113,3 @@ });

getAndLoadConfigIfNeeded.mockReturnValue({
portals: [],
accounts: [],
});

@@ -127,3 +127,3 @@

httpUseLocalhost: true,
portals: [],
accounts: [],
});

@@ -142,4 +142,4 @@

const accessToken = 'let-me-in';
const portal = {
id: 123,
const account = {
portalId: 123,
authType: 'oauth2',

@@ -158,5 +158,5 @@ clientId: 'd996372f-2b53-30d3-9c3b-4fdde4bce3a2',

getAndLoadConfigIfNeeded.mockReturnValue({
portals: [portal],
accounts: [account],
});
getPortalConfig.mockReturnValue(portal);
getAccountConfig.mockReturnValue(account);
await http.get(123, {

@@ -183,4 +183,4 @@ uri: 'some/endpoint/path',

const accessToken = 'let-me-in';
const portal = {
id: 123,
const account = {
portalId: 123,
authType: 'personalaccesskey',

@@ -198,5 +198,5 @@ personalAccessKey: 'some-secret',

getAndLoadConfigIfNeeded.mockReturnValue({
portals: [portal],
accounts: [account],
});
getPortalConfig.mockReturnValue(portal);
getAccountConfig.mockReturnValue(account);
await http.get(123, {

@@ -225,5 +225,5 @@ uri: 'some/endpoint/path',

httpTimeout: 1000,
portals: [
accounts: [
{
id: 123,
portalId: 123,
apiKey: 'abc',

@@ -233,4 +233,4 @@ },

});
getPortalConfig.mockReturnValue({
id: 123,
getAccountConfig.mockReturnValue({
portalId: 123,
apiKey: 'abc',

@@ -237,0 +237,0 @@ });

@@ -17,3 +17,3 @@ const fs = require('fs-extra');

it('downloads hubdb table', async () => {
const portalId = 123;
const accountId = 123;
const tableId = 456;

@@ -28,3 +28,3 @@ const destPath = 'tmp.json';

const { filePath } = await downloadHubDbTable(portalId, tableId, destPath);
const { filePath } = await downloadHubDbTable(accountId, tableId, destPath);
const fileOutput = JSON.parse(fs.outputFile.mock.results[0].value);

@@ -49,3 +49,3 @@

it('uploads hubdb table', async () => {
const portalId = 123;
const accountId = 123;
const srcPath = 'tmp.json';

@@ -61,3 +61,3 @@ const projectCwd = '/home/tom/projects';

const table = await createHubDbTable(portalId, `${projectCwd}/${srcPath}`);
const table = await createHubDbTable(accountId, `${projectCwd}/${srcPath}`);

@@ -64,0 +64,0 @@ describe('has the correct number of rows', () => {

const moment = require('moment');
const { getAndLoadConfigIfNeeded, getPortalConfig } = require('../lib/config');
const { getAndLoadConfigIfNeeded, getAccountConfig } = require('../lib/config');
const { fetchAccessToken } = require('../api/localDevAuth/unauthenticated');

@@ -15,5 +15,5 @@ const { ENVIRONMENTS } = require('../lib/constants');

it('refreshes access token when access token is missing', async () => {
const portalId = 123;
const portal = {
portalId,
const accountId = 123;
const account = {
accountId,
authType: 'personalaccesskey',

@@ -23,5 +23,5 @@ personalAccessKey: 'let-me-in',

getAndLoadConfigIfNeeded.mockReturnValue({
portals: [portal],
accounts: [account],
});
getPortalConfig.mockReturnValue(portal);
getAccountConfig.mockReturnValue(account);

@@ -37,13 +37,13 @@ const freshAccessToken = 'fresh-token';

scopeGroups: ['content'],
hubId: portalId,
hubId: accountId,
userId: 456,
})
);
const accessToken = await accessTokenForPersonalAccessKey(portalId);
const accessToken = await accessTokenForPersonalAccessKey(accountId);
expect(accessToken).toEqual(freshAccessToken);
});
it('uses portalId when refreshing token', async () => {
const portalId = 123;
const portal = {
portalId,
it('uses accountId when refreshing token', async () => {
const accountId = 123;
const account = {
accountId,
authType: 'personalaccesskey',

@@ -53,17 +53,17 @@ personalAccessKey: 'let-me-in',

getAndLoadConfigIfNeeded.mockReturnValue({
portals: [portal],
accounts: [account],
});
getPortalConfig.mockReturnValue(portal);
getAccountConfig.mockReturnValue(account);
await accessTokenForPersonalAccessKey(portalId);
await accessTokenForPersonalAccessKey(accountId);
expect(fetchAccessToken).toHaveBeenCalledWith(
'let-me-in',
ENVIRONMENTS.PROD,
portalId
accountId
);
});
it('refreshes access token when the existing token is expired', async () => {
const portalId = 123;
const portal = {
portalId,
const accountId = 123;
const account = {
accountId,
authType: 'personalaccesskey',

@@ -81,5 +81,5 @@ personalAccessKey: 'let-me-in',

getAndLoadConfigIfNeeded.mockReturnValue({
portals: [portal],
accounts: [account],
});
getPortalConfig.mockReturnValue(portal);
getAccountConfig.mockReturnValue(account);

@@ -95,15 +95,15 @@ const freshAccessToken = 'fresh-token';

scopeGroups: ['content'],
hubId: portalId,
hubId: accountId,
userId: 456,
})
);
const accessToken = await accessTokenForPersonalAccessKey(portalId);
const accessToken = await accessTokenForPersonalAccessKey(accountId);
expect(accessToken).toEqual(freshAccessToken);
});
it('refreshes access tokens multiple times', async () => {
const portalId = 123;
const accountId = 123;
const accessKey = 'let-me-in';
const userId = 456;
const mockPortal = (expiresAt, accessToken) => ({
portalId,
const mockAccount = (expiresAt, accessToken) => ({
accountId,
authType: 'personalaccesskey',

@@ -118,3 +118,3 @@ personalAccessKey: accessKey,

});
const initialPortalConfig = mockPortal(
const initialAccountConfig = mockAccount(
moment()

@@ -126,5 +126,5 @@ .subtract(2, 'hours')

getAndLoadConfigIfNeeded.mockReturnValueOnce({
portals: [initialPortalConfig],
accounts: [initialAccountConfig],
});
getPortalConfig.mockReturnValueOnce(initialPortalConfig);
getAccountConfig.mockReturnValueOnce(initialAccountConfig);

@@ -142,3 +142,3 @@ const firstAccessToken = 'fresh-token';

scopeGroups: ['content'],
hubId: portalId,
hubId: accountId,
userId,

@@ -148,6 +148,6 @@ })

const firstRefreshedAccessToken = await accessTokenForPersonalAccessKey(
portalId
accountId
);
expect(firstRefreshedAccessToken).toEqual(firstAccessToken);
const updatedPortalConfig = mockPortal(
const updatedAccountConfig = mockAccount(
moment(expiresAtMillis).toISOString(),

@@ -157,5 +157,5 @@ firstAccessToken

getAndLoadConfigIfNeeded.mockReturnValueOnce({
portals: [updatedPortalConfig],
accounts: [updatedAccountConfig],
});
getPortalConfig.mockReturnValueOnce(updatedPortalConfig);
getAccountConfig.mockReturnValueOnce(updatedAccountConfig);

@@ -169,3 +169,3 @@ const secondAccessToken = 'another-fresh-token';

scopeGroups: ['content'],
hubId: portalId,
hubId: accountId,
userId,

@@ -176,3 +176,3 @@ })

const secondRefreshedAccessToken = await accessTokenForPersonalAccessKey(
portalId
accountId
);

@@ -179,0 +179,0 @@ expect(secondRefreshedAccessToken).toEqual(secondAccessToken);

@@ -148,3 +148,3 @@ const fileMapper = jest.genMockFromModule('../fileMapper');

fileMapper.download = jest.fn(async (portalId, filepath) => {
fileMapper.download = jest.fn(async (accountId, filepath) => {
if (filepath === '@root') {

@@ -151,0 +151,0 @@ return allRequestData;

const http = require('../http');
const BLOGS_API_PATH = 'blogs/v3';
async function fetchBlogs(portalId, query = {}) {
return http.get(portalId, {
async function fetchBlogs(accountId, query = {}) {
return http.get(accountId, {
uri: `${BLOGS_API_PATH}/blogs`,

@@ -7,0 +7,0 @@ query,

const http = require('../http');
const CONTENT_API_PATH = 'content/api/v4';
async function fetchContent(portalId, query = {}) {
return http.get(portalId, {
async function fetchContent(accountId, query = {}) {
return http.get(accountId, {
uri: `${CONTENT_API_PATH}/contents`,

@@ -7,0 +7,0 @@ query,

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

const createObject = (portalId, objectTypeId, filePath) =>
http.post(portalId, {
const createObject = (accountId, objectTypeId, filePath) =>
http.post(accountId, {
uri: `${CUSTOM_OBJECTS_API_PATH}/${objectTypeId}`,

@@ -13,4 +13,4 @@ body: JSON.parse(fs.readFileSync(filePath, 'utf-8')),

const updateObject = async (portalId, objectTypeId, filePath) =>
http.post(portalId, {
const updateObject = async (accountId, objectTypeId, filePath) =>
http.post(accountId, {
uri: `${CUSTOM_OBJECTS_API_PATH}/${objectTypeId}`,

@@ -20,19 +20,19 @@ body: JSON.parse(fs.readFileSync(filePath, 'utf-8')),

const fetchObject = async (portalId, objectTypeId, instanceId) =>
http.get(portalId, {
const fetchObject = async (accountId, objectTypeId, instanceId) =>
http.get(accountId, {
uri: `${CUSTOM_OBJECTS_API_PATH}/${objectTypeId}/${instanceId}`,
});
const fetchObjects = async (portalId, objectTypeId) =>
http.get(portalId, {
const fetchObjects = async (accountId, objectTypeId) =>
http.get(accountId, {
uri: `${CUSTOM_OBJECTS_API_PATH}/${objectTypeId}`,
});
const archiveObject = async (portalId, objectTypeId, instanceId) =>
http.delete(portalId, {
const archiveObject = async (accountId, objectTypeId, instanceId) =>
http.delete(accountId, {
uri: `${CUSTOM_OBJECTS_API_PATH}/${objectTypeId}/${instanceId}`,
});
const searchObjects = async (portalId, objectTypeId, filePath) =>
http.post(portalId, {
const searchObjects = async (accountId, objectTypeId, filePath) =>
http.post(accountId, {
uri: `${CUSTOM_OBJECTS_API_PATH}/${objectTypeId}/search`,

@@ -42,4 +42,4 @@ body: JSON.parse(fs.readFileSync(filePath, 'utf-8')),

const batchCreateObjects = (portalId, objectTypeId, filePath) =>
http.post(portalId, {
const batchCreateObjects = (accountId, objectTypeId, filePath) =>
http.post(accountId, {
uri: `${CUSTOM_OBJECTS_API_PATH}/${objectTypeId}/batch/create`,

@@ -46,0 +46,0 @@ body: JSON.parse(fs.readFileSync(filePath, 'utf-8')),

@@ -7,7 +7,7 @@ const http = require('../http');

* @async
* @param {number} portalId
* @param {number} accountId
* @returns {Promise}
*/
async function fetchMenus(portalId, query = {}) {
return http.get(portalId, {
async function fetchMenus(accountId, query = {}) {
return http.get(accountId, {
uri: `${DESIGN_MANAGER_API_PATH}/menus`,

@@ -20,7 +20,7 @@ query,

* @async
* @param {number} portalId
* @param {number} accountId
* @returns {Promise}
*/
async function fetchBuiltinMapping(portalId) {
return http.get(portalId, {
async function fetchBuiltinMapping(accountId) {
return http.get(accountId, {
uri: `${DESIGN_MANAGER_API_PATH}/widgets/builtin-mapping`,

@@ -27,0 +27,0 @@ });

@@ -7,3 +7,3 @@ const fs = require('fs');

async function uploadFile(portalId, src, dest) {
async function uploadFile(accountId, src, dest) {
const directory = path.dirname(dest);

@@ -20,3 +20,3 @@ const filename = path.basename(dest);

return http.post(portalId, {
return http.post(accountId, {
uri: `${FILE_MANAGER_API_PATH}/files`,

@@ -30,4 +30,4 @@ qs: {

async function fetchStat(portalId, src) {
return http.get(portalId, {
async function fetchStat(accountId, src) {
return http.get(accountId, {
uri: `${FILE_MANAGER_API_PATH}/files/stat/${src}`,

@@ -37,4 +37,4 @@ });

async function fetchFiles(portalId, folderId, { offset, archived }) {
return http.get(portalId, {
async function fetchFiles(accountId, folderId, { offset, archived }) {
return http.get(accountId, {
uri: `${FILE_MANAGER_API_PATH}/files/`,

@@ -50,4 +50,4 @@ qs: {

async function fetchFolders(portalId, folderId) {
return http.get(portalId, {
async function fetchFolders(accountId, folderId) {
return http.get(accountId, {
uri: `${FILE_MANAGER_API_PATH}/folders/`,

@@ -54,0 +54,0 @@ qs: {

@@ -6,3 +6,3 @@ const fs = require('fs-extra');

const { getCwd } = require('../path');
const { getEnv, getPortalConfig } = require('../lib/config');
const { getEnv, getAccountConfig } = require('../lib/config');
const { logger } = require('../logger');

@@ -49,3 +49,3 @@

* @async
* @param {number} portalId
* @param {number} accountId
* @param {string} src

@@ -56,4 +56,4 @@ * @param {string} dest

*/
async function upload(portalId, src, dest, options = {}) {
return http.post(portalId, {
async function upload(accountId, src, dest, options = {}) {
return http.post(accountId, {
uri: `${FILE_MAPPER_API_PATH}/upload/${encodeURIComponent(dest)}`,

@@ -71,3 +71,3 @@ formData: {

* @async
* @param {number} portalId
* @param {number} accountId
* @param {number} moduleId

@@ -77,4 +77,4 @@ * @param {object} options

*/
async function fetchModule(portalId, moduleId, options = {}) {
return http.get(portalId, {
async function fetchModule(accountId, moduleId, options = {}) {
return http.get(accountId, {
uri: `${FILE_MAPPER_API_PATH}/modules/${moduleId}`,

@@ -89,3 +89,3 @@ ...options,

* @async
* @param {number} portalId
* @param {number} accountId
* @param {string} filePath

@@ -96,5 +96,5 @@ * @param {stream.Writable} destination

*/
async function fetchFileStream(portalId, filePath, destination, options = {}) {
async function fetchFileStream(accountId, filePath, destination, options = {}) {
const response = await http.getOctetStream(
portalId,
accountId,
{

@@ -113,3 +113,3 @@ uri: `${FILE_MAPPER_API_PATH}/stream/${encodeURIComponent(filePath)}`,

* @async
* @param {number} portalId
* @param {number} accountId
* @param {string} filepath

@@ -119,4 +119,4 @@ * @param {object} options

*/
async function download(portalId, filepath, options = {}) {
return http.get(portalId, {
async function download(accountId, filepath, options = {}) {
return http.get(accountId, {
uri: `${FILE_MAPPER_API_PATH}/download/${encodeURIComponent(filepath)}`,

@@ -131,3 +131,3 @@ ...options,

* @async
* @param {number} portalId
* @param {number} accountId
* @param {string} filepath

@@ -137,4 +137,4 @@ * @param {object} options

*/
async function downloadDefault(portalId, filepath, options = {}) {
return http.get(portalId, {
async function downloadDefault(accountId, filepath, options = {}) {
return http.get(accountId, {
uri: `${FILE_MAPPER_API_PATH}/download-default/${filepath}`,

@@ -149,3 +149,3 @@ ...options,

* @async
* @param {number} portalId
* @param {number} accountId
* @param {string} filePath

@@ -155,4 +155,4 @@ * @param {object} options

*/
async function deleteFile(portalId, filePath, options = {}) {
return http.delete(portalId, {
async function deleteFile(accountId, filePath, options = {}) {
return http.delete(accountId, {
uri: `${FILE_MAPPER_API_PATH}/delete/${filePath}`,

@@ -168,3 +168,3 @@ ...options,

* @async
* @param {number} portalId
* @param {number} accountId
* @param {string} folderPath

@@ -174,7 +174,7 @@ * @param {object} options

*/
async function deleteFolder(portalId, folderPath, options = {}) {
async function deleteFolder(accountId, folderPath, options = {}) {
logger.warn(
'`cms-lib/api/fileMapper#deleteFolder()` is deprecated. Use `cms-lib/api/fileMapper#deleteFile()` instead.'
);
return http.delete(portalId, {
return http.delete(accountId, {
uri: `${FILE_MAPPER_API_PATH}/delete/folder/${folderPath}`,

@@ -191,5 +191,5 @@ ...options,

*/
async function trackUsage(eventName, eventClass, meta = {}, portalId) {
async function trackUsage(eventName, eventClass, meta = {}, accountId) {
const usageEvent = {
portalId,
accountId,
eventName,

@@ -200,7 +200,7 @@ eventClass,

const path = `${FILE_MAPPER_API_PATH}/cms-cli-usage`;
const portalConfig = portalId && getPortalConfig(portalId);
const accountConfig = accountId && getAccountConfig(accountId);
if (portalConfig && portalConfig.authType === 'personalaccesskey') {
if (accountConfig && accountConfig.authType === 'personalaccesskey') {
logger.debug('Sending usage event to authenticated endpoint');
return http.post(portalId, {
return http.post(accountId, {
uri: `${path}/authenticated`,

@@ -212,3 +212,3 @@ body: usageEvent,

const env = getEnv(portalId);
const env = getEnv(accountId);
const requestOptions = http.getRequestOptions(

@@ -215,0 +215,0 @@ { env },

@@ -5,4 +5,4 @@ const http = require('../http');

async function getFunctionByPath(portalId, functionPath) {
return http.get(portalId, {
async function getFunctionByPath(accountId, functionPath) {
return http.get(accountId, {
uri: `${FUNCTION_API_PATH}/function/by-path/${functionPath}`,

@@ -12,4 +12,4 @@ });

async function getRoutes(portalId) {
return http.get(portalId, {
async function getRoutes(accountId) {
return http.get(accountId, {
uri: `${FUNCTION_API_PATH}/routes`,

@@ -16,0 +16,0 @@ });

const http = require('../http');
const HUBDB_API_PATH = 'cms/v3/hubdb';
async function fetchTables(portalId) {
return http.get(portalId, {
async function fetchTables(accountId) {
return http.get(accountId, {
uri: `${HUBDB_API_PATH}/tables`,

@@ -10,4 +10,4 @@ });

async function fetchTable(portalId, tableId) {
return http.get(portalId, {
async function fetchTable(accountId, tableId) {
return http.get(accountId, {
uri: `${HUBDB_API_PATH}/tables/${tableId}`,

@@ -17,4 +17,4 @@ });

async function createTable(portalId, schema) {
return http.post(portalId, {
async function createTable(accountId, schema) {
return http.post(accountId, {
uri: `${HUBDB_API_PATH}/tables`,

@@ -25,4 +25,4 @@ body: schema,

async function updateTable(portalId, tableId, schema) {
return http.patch(portalId, {
async function updateTable(accountId, tableId, schema) {
return http.patch(accountId, {
uri: `${HUBDB_API_PATH}/tables/${tableId}/draft`,

@@ -33,4 +33,4 @@ body: schema,

async function publishTable(portalId, tableId) {
return http.post(portalId, {
async function publishTable(accountId, tableId) {
return http.post(accountId, {
uri: `${HUBDB_API_PATH}/tables/${tableId}/draft/push-live`,

@@ -40,4 +40,4 @@ });

async function deleteTable(portalId, tableId) {
return http.delete(portalId, {
async function deleteTable(accountId, tableId) {
return http.delete(accountId, {
uri: `${HUBDB_API_PATH}/tables/${tableId}`,

@@ -47,4 +47,4 @@ });

async function updateRows(portalId, tableId, rows) {
return http.post(portalId, {
async function updateRows(accountId, tableId, rows) {
return http.post(accountId, {
uri: `${HUBDB_API_PATH}/tables/${tableId}/rows/draft/batch/update`,

@@ -55,4 +55,4 @@ body: rows,

async function createRows(portalId, tableId, rows) {
return http.post(portalId, {
async function createRows(accountId, tableId, rows) {
return http.post(accountId, {
uri: `${HUBDB_API_PATH}/tables/${tableId}/rows/draft/batch/create`,

@@ -63,4 +63,4 @@ body: { inputs: rows },

async function fetchRows(portalId, tableId, query = {}) {
return http.get(portalId, {
async function fetchRows(accountId, tableId, query = {}) {
return http.get(accountId, {
uri: `${HUBDB_API_PATH}/tables/${tableId}/rows/draft`,

@@ -71,4 +71,4 @@ query,

async function deleteRows(portalId, tableId, rowIds) {
return http.post(portalId, {
async function deleteRows(accountId, tableId, rowIds) {
return http.post(accountId, {
uri: `${HUBDB_API_PATH}/tables/${tableId}/rows/draft/batch/purge`,

@@ -75,0 +75,0 @@ body: { inputs: rowIds },

const http = require('../../http');
async function fetchScopeData(portalId, scopeGroup) {
return http.get(portalId, {
async function fetchScopeData(accountId, scopeGroup) {
return http.get(accountId, {
uri: `localdevauth/v1/auth/check-scopes`,

@@ -6,0 +6,0 @@ query: {

@@ -5,6 +5,6 @@ const http = require('../http');

async function getFunctionLogs(portalId, functionId, query = {}) {
async function getFunctionLogs(accountId, functionId, query = {}) {
const { limit = 5 } = query;
return http.get(portalId, {
return http.get(accountId, {
uri: `${RESULTS_API_PATH}/${functionId}`,

@@ -17,4 +17,4 @@ query: {

async function getLatestFunctionLog(portalId, functionId) {
return http.get(portalId, {
async function getLatestFunctionLog(accountId, functionId) {
return http.get(accountId, {
uri: `${RESULTS_API_PATH}/${functionId}/latest`,

@@ -21,0 +21,0 @@ });

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

const createSchema = (portalId, filePath) =>
http.post(portalId, {
const createSchema = (accountId, filePath) =>
http.post(accountId, {
uri: SCHEMA_API_PATH,

@@ -13,4 +13,4 @@ body: JSON.parse(fs.readFileSync(filePath, 'utf-8')),

const updateSchema = async (portalId, schemaObjectType, filePath) =>
http.patch(portalId, {
const updateSchema = async (accountId, schemaObjectType, filePath) =>
http.patch(accountId, {
uri: `${SCHEMA_API_PATH}/${schemaObjectType}`,

@@ -20,14 +20,14 @@ body: JSON.parse(fs.readFileSync(filePath, 'utf-8')),

const fetchSchema = async (portalId, schemaObjectType) =>
http.get(portalId, {
const fetchSchema = async (accountId, schemaObjectType) =>
http.get(accountId, {
uri: `${SCHEMA_API_PATH}/${schemaObjectType}`,
});
const fetchSchemas = async portalId =>
http.get(portalId, {
const fetchSchemas = async accountId =>
http.get(accountId, {
uri: SCHEMA_API_PATH,
});
const deleteSchema = async (portalId, schemaObjectType) =>
http.delete(portalId, {
const deleteSchema = async (accountId, schemaObjectType) =>
http.delete(accountId, {
uri: `${SCHEMA_API_PATH}/${schemaObjectType}`,

@@ -34,0 +34,0 @@ });

@@ -5,4 +5,4 @@ const http = require('../http');

async function addSecret(portalId, key, value) {
return http.post(portalId, {
async function addSecret(accountId, key, value) {
return http.post(accountId, {
uri: SECRETS_API_PATH,

@@ -16,4 +16,4 @@ body: {

async function updateSecret(portalId, key, value) {
return http.put(portalId, {
async function updateSecret(accountId, key, value) {
return http.put(accountId, {
uri: SECRETS_API_PATH,

@@ -27,4 +27,4 @@ body: {

async function deleteSecret(portalId, key) {
return http.delete(portalId, {
async function deleteSecret(accountId, key) {
return http.delete(accountId, {
uri: `${SECRETS_API_PATH}/${key}`,

@@ -34,4 +34,4 @@ });

async function fetchSecrets(portalId) {
return http.get(portalId, {
async function fetchSecrets(accountId) {
return http.get(accountId, {
uri: `${SECRETS_API_PATH}`,

@@ -38,0 +38,0 @@ });

@@ -7,3 +7,3 @@ const http = require('../http');

* @async
* @param {number} portalId
* @param {number} accountId
* @param {string} sourceCode

@@ -13,4 +13,4 @@ * @param {object} hublValidationOptions

*/
async function validateHubl(portalId, sourceCode, hublValidationOptions) {
return http.post(portalId, {
async function validateHubl(accountId, sourceCode, hublValidationOptions) {
return http.post(accountId, {
uri: HUBL_VALIDATE_API_PATH,

@@ -17,0 +17,0 @@ body: {

@@ -57,6 +57,6 @@ const path = require('path');

async function downloadModule(portalId, moduleId, dest) {
async function downloadModule(accountId, moduleId, dest) {
let response;
try {
response = await fetchModule(portalId, moduleId);
response = await fetchModule(accountId, moduleId);
} catch (error) {

@@ -75,4 +75,4 @@ logger.error('Failed to download %s', moduleId);

async function downloadBuiltinModules(portalId, dest) {
const builtinMappings = await fetchBuiltinMapping(portalId);
async function downloadBuiltinModules(accountId, dest) {
const builtinMappings = await fetchBuiltinMapping(accountId);
const downloaded = new Set();

@@ -85,3 +85,3 @@ Object.values(builtinMappings).forEach(moduleId => {

downloaded.add(moduleId);
downloadModule(portalId, moduleId, dest);
downloadModule(accountId, moduleId, dest);
logger.error('Failed to download %s', moduleId);

@@ -88,0 +88,0 @@ });

const { logger } = require('../logger');
const { getPortalConfig } = require('../lib/config');
const { getAccountConfig } = require('../lib/config');
const {

@@ -125,3 +125,3 @@ SCOPE_GROUPS,

: action;
messageDetail = `${request} in portal ${context.portalId}`;
messageDetail = `${request} in account ${context.accountId}`;
}

@@ -145,3 +145,3 @@ const errorMessage = [];

errorMessage.push(
`The ${action} failed because "${context.request}" was not found in portal ${context.portalId}.`
`The ${action} failed because "${context.request}" was not found in account ${context.accountId}.`
);

@@ -205,5 +205,5 @@ } else {

async function verifyAccessKeyAndUserAccess(portalId, scopeGroup) {
const portalConfig = getPortalConfig(portalId);
const { authType } = portalConfig;
async function verifyAccessKeyAndUserAccess(accountId, scopeGroup) {
const accountConfig = getAccountConfig(accountId);
const { authType } = accountConfig;
if (authType !== PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {

@@ -215,3 +215,3 @@ return;

try {
scopesData = await fetchScopeData(portalId, scopeGroup);
scopesData = await fetchScopeData(accountId, scopeGroup);
} catch (e) {

@@ -247,9 +247,13 @@ logger.debug('Error verifying access');

*
* @param {int} portalId
* @param {int} accountId
* @param {Error|SystemError|Object} error
* @param {ApiErrorContext} context
*/
async function logServerlessFunctionApiErrorInstance(portalId, error, context) {
async function logServerlessFunctionApiErrorInstance(
accountId,
error,
context
) {
if (isMissingScopeError(error)) {
await verifyAccessKeyAndUserAccess(portalId, SCOPE_GROUPS.functions);
await verifyAccessKeyAndUserAccess(accountId, SCOPE_GROUPS.functions);
return;

@@ -256,0 +260,0 @@ }

@@ -12,3 +12,3 @@ const { HubSpotAuthError } = require('../lib/models/Errors');

/** @type {number} */
this.portalId = props.portalId;
this.accountId = props.accountId;
}

@@ -15,0 +15,0 @@ }

@@ -32,3 +32,3 @@ const fs = require('fs-extra');

*
* @param {number} portalId
* @param {number} accountId
* @param {string} src

@@ -38,3 +38,3 @@ * @param {string} dest

*/
async function uploadFolder(portalId, src, dest, { cwd }) {
async function uploadFolder(accountId, src, dest, { cwd }) {
const regex = new RegExp(`^${escapeRegExp(src)}`);

@@ -51,9 +51,9 @@ const files = await walk(src);

logger.debug(
'Uploading files from "%s" to "%s" in the File Manager of portal %s',
'Uploading files from "%s" to "%s" in the File Manager of account %s',
file,
destPath,
portalId
accountId
);
try {
await uploadFile(portalId, file, destPath);
await uploadFile(accountId, file, destPath);
logger.log('Uploaded file "%s" to "%s"', file, destPath);

@@ -68,3 +68,3 @@ } catch (error) {

new ApiErrorContext({
portalId,
accountId,
request: destPath,

@@ -98,3 +98,3 @@ payload: file,

*
* @param {number} portalId
* @param {number} accountId
* @param {object} file

@@ -104,3 +104,3 @@ * @param {string} dest

*/
async function downloadFile(portalId, file, dest, options) {
async function downloadFile(accountId, file, dest, options) {
const fileName = `${file.name}.${file.extension}`;

@@ -118,3 +118,3 @@ const destPath = convertToLocalFileSystemPath(path.join(dest, fileName));

destPath,
portalId,
accountId,
write: true,

@@ -136,3 +136,3 @@ })

await http.getOctetStream(
portalId,
accountId,
{

@@ -152,6 +152,6 @@ baseUrl: file.url,

*
* @param {number} portalId
* @param {number} accountId
* @param {string} folderPath
*/
async function fetchAllPagedFiles(portalId, folderId, { includeArchived }) {
async function fetchAllPagedFiles(accountId, folderId, { includeArchived }) {
let totalFiles = null;

@@ -162,3 +162,3 @@ let files = [];

while (totalFiles === null || count < totalFiles) {
const response = await fetchFiles(portalId, folderId, {
const response = await fetchFiles(accountId, folderId, {
offset,

@@ -181,3 +181,3 @@ archived: includeArchived,

*
* @param {number} portalId
* @param {number} accountId
* @param {object} folder

@@ -187,12 +187,12 @@ * @param {string} dest

*/
async function fetchFolderContents(portalId, folder, dest, options) {
const files = await fetchAllPagedFiles(portalId, folder.id, options);
async function fetchFolderContents(accountId, folder, dest, options) {
const files = await fetchAllPagedFiles(accountId, folder.id, options);
for (const file of files) {
await downloadFile(portalId, file, dest, options);
await downloadFile(accountId, file, dest, options);
}
const { objects: folders } = await fetchFolders(portalId, folder.id);
const { objects: folders } = await fetchFolders(accountId, folder.id);
for (const folder of folders) {
const nestedFolder = path.join(dest, folder.name);
await fetchFolderContents(portalId, folder, nestedFolder, options);
await fetchFolderContents(accountId, folder, nestedFolder, options);
}

@@ -204,3 +204,3 @@ }

*
* @param {number} portalId
* @param {number} accountId
* @param {string} src

@@ -211,3 +211,3 @@ * @param {string} dest

*/
async function downloadFolder(portalId, src, dest, folder, options) {
async function downloadFolder(accountId, src, dest, folder, options) {
try {

@@ -219,8 +219,8 @@ const rootPath =

logger.log(
'Fetching folder from "%s" to "%s" in the File Manager of portal %s',
'Fetching folder from "%s" to "%s" in the File Manager of account %s',
src,
rootPath,
portalId
accountId
);
await fetchFolderContents(portalId, folder, rootPath, options);
await fetchFolderContents(accountId, folder, rootPath, options);
logger.success(

@@ -239,3 +239,3 @@ 'Completed fetch of folder "%s" to "%s" from the File Manager',

*
* @param {number} portalId
* @param {number} accountId
* @param {string} src

@@ -246,3 +246,3 @@ * @param {string} dest

*/
async function downloadSingleFile(portalId, src, dest, file, options) {
async function downloadSingleFile(accountId, src, dest, file, options) {
if (!options.includeArchived && file.archived) {

@@ -262,8 +262,8 @@ logger.error(

logger.log(
'Fetching file from "%s" to "%s" in the File Manager of portal %s',
'Fetching file from "%s" to "%s" in the File Manager of account %s',
src,
dest,
portalId
accountId
);
await downloadFile(portalId, file, dest, options);
await downloadFile(accountId, file, dest, options);
logger.success(

@@ -282,3 +282,3 @@ 'Completed fetch of file "%s" to "%s" from the File Manager',

*
* @param {number} portalId
* @param {number} accountId
* @param {string} src

@@ -288,13 +288,13 @@ * @param {string} dest

*/
async function downloadFileOrFolder(portalId, src, dest, options) {
async function downloadFileOrFolder(accountId, src, dest, options) {
if (src === '/') {
await downloadFolder(portalId, src, dest, '', options);
await downloadFolder(accountId, src, dest, '', options);
} else {
try {
const { file, folder } = await fetchStat(portalId, src);
const { file, folder } = await fetchStat(accountId, src);
if (file) {
downloadSingleFile(portalId, src, dest, file, options);
downloadSingleFile(accountId, src, dest, file, options);
} else if (folder) {
downloadFolder(portalId, src, dest, folder, options);
downloadFolder(accountId, src, dest, folder, options);
}

@@ -306,3 +306,3 @@ } catch (err) {

request: src,
portalId,
accountId,
})

@@ -309,0 +309,0 @@ );

@@ -169,3 +169,3 @@ const fs = require('fs-extra');

* @typedef {Object} FileMapperInputArguments
* @property {number} portalId
* @property {number} accountId
* @property {string} src

@@ -223,3 +223,3 @@ * @property {string} dest

filepath,
portalId: input.portalId,
accountId: input.accountId,
write: true,

@@ -269,6 +269,6 @@ })

}
const { portalId } = input;
const { accountId } = input;
try {
const node = await fetchFileStream(portalId, srcPath, filepath, {
const node = await fetchFileStream(accountId, srcPath, filepath, {
qs: getFileMapperApiQueryFromMode(input.mode),

@@ -281,3 +281,3 @@ });

new ApiErrorContext({
portalId,
accountId,
request: srcPath,

@@ -322,3 +322,3 @@ })

filepath,
portalId: input.portalId,
accountId: input.accountId,
write: true,

@@ -398,3 +398,3 @@ })

async function fetchFolderFromApi(input) {
const { portalId, src, mode } = input;
const { accountId, src, mode } = input;
const { isRoot, isFolder, isHubspot } = getTypeDataFromPath(src);

@@ -408,8 +408,8 @@ if (!isFolder) {

const node = isHubspot
? await downloadDefault(portalId, srcPath, { qs })
: await download(portalId, srcPath, { qs });
? await downloadDefault(accountId, srcPath, { qs })
: await download(accountId, srcPath, { qs });
logger.log(
'Fetched "%s" from portal %d from the Desing Manager successfully',
'Fetched "%s" from account %d from the Design Manager successfully',
src,
portalId
accountId
);

@@ -424,3 +424,3 @@ return node;

new ApiErrorContext({
portalId,
accountId,
request: src,

@@ -427,0 +427,0 @@ })

const request = require('request');
const requestPN = require('request-promise-native');
const fs = require('fs-extra');
const { getPortalConfig } = require('./lib/config');
const { getAccountConfig } = require('./lib/config');
const { getRequestOptions } = require('./http/requestOptions');

@@ -14,5 +14,5 @@ const { accessTokenForPersonalAccessKey } = require('./personalAccessKey');

const withOauth = async (portalId, portalConfig, requestOptions) => {
const withOauth = async (accountId, accountConfig, requestOptions) => {
const { headers } = requestOptions;
const oauth = getOauthManager(portalId, portalConfig);
const oauth = getOauthManager(accountId, accountConfig);
const accessToken = await oauth.accessToken();

@@ -29,8 +29,8 @@ return {

const withPersonalAccessKey = async (
portalId,
portalConfig,
accountId,
accountConfig,
requestOptions
) => {
const { headers } = requestOptions;
const accessToken = await accessTokenForPersonalAccessKey(portalId);
const accessToken = await accessTokenForPersonalAccessKey(accountId);
return {

@@ -57,7 +57,7 @@ ...requestOptions,

const withAuth = async (portalId, options) => {
const portalConfig = getPortalConfig(portalId);
const { env, authType, apiKey } = portalConfig;
const withAuth = async (accountId, options) => {
const accountConfig = getAccountConfig(accountId);
const { env, authType, apiKey } = accountConfig;
const requestOptions = withPortalId(
portalId,
accountId,
getRequestOptions({ env }, options)

@@ -67,7 +67,7 @@ );

if (authType === 'personalaccesskey') {
return withPersonalAccessKey(portalId, portalConfig, requestOptions);
return withPersonalAccessKey(accountId, accountConfig, requestOptions);
}
if (authType === 'oauth2') {
return withOauth(portalId, portalConfig, requestOptions);
return withOauth(accountId, accountConfig, requestOptions);
}

@@ -96,26 +96,26 @@ const { qs } = requestOptions;

const getRequest = async (portalId, options) => {
const getRequest = async (accountId, options) => {
const { query, ...rest } = options;
const requestOptions = addQueryParams(rest, query);
return requestPN.get(await withAuth(portalId, requestOptions));
return requestPN.get(await withAuth(accountId, requestOptions));
};
const postRequest = async (portalId, options) => {
return requestPN.post(await withAuth(portalId, options));
const postRequest = async (accountId, options) => {
return requestPN.post(await withAuth(accountId, options));
};
const putRequest = async (portalId, options) => {
return requestPN.put(await withAuth(portalId, options));
const putRequest = async (accountId, options) => {
return requestPN.put(await withAuth(accountId, options));
};
const patchRequest = async (portalId, options) => {
return requestPN.patch(await withAuth(portalId, options));
const patchRequest = async (accountId, options) => {
return requestPN.patch(await withAuth(accountId, options));
};
const deleteRequest = async (portalId, options) => {
return requestPN.del(await withAuth(portalId, options));
const deleteRequest = async (accountId, options) => {
return requestPN.del(await withAuth(accountId, options));
};
const createGetRequestStream = ({ contentType }) => async (
portalId,
accountId,
options,

@@ -132,3 +132,3 @@ filepath

filepath,
portalId,
accountId,
write: true,

@@ -146,3 +146,3 @@ })

try {
const { headers, ...opts } = await withAuth(portalId, requestOptions);
const { headers, ...opts } = await withAuth(accountId, requestOptions);
const req = request.get({

@@ -149,0 +149,0 @@ ...opts,

@@ -35,3 +35,3 @@ const path = require('path');

async function addRowsToHubDbTable(portalId, tableId, rows) {
async function addRowsToHubDbTable(accountId, tableId, rows) {
const rowsToUpdate = rows.map(row => {

@@ -49,6 +49,6 @@ const values = row.values;

if (rowsToUpdate.length > 0) {
await createRows(portalId, tableId, rowsToUpdate);
await createRows(accountId, tableId, rowsToUpdate);
}
const { rowCount } = await publishTable(portalId, tableId);
const { rowCount } = await publishTable(accountId, tableId);

@@ -61,3 +61,3 @@ return {

async function createHubDbTable(portalId, src) {
async function createHubDbTable(accountId, src) {
validateJsonFile(src);

@@ -67,8 +67,8 @@

const { rows, ...schema } = table;
const { columns, id } = await createTable(portalId, schema);
const { columns, id } = await createTable(accountId, schema);
return addRowsToHubDbTable(portalId, id, rows, columns);
return addRowsToHubDbTable(accountId, id, rows, columns);
}
async function updateHubDbTable(portalId, tableId, src) {
async function updateHubDbTable(accountId, tableId, src) {
validateJsonFile(src);

@@ -79,3 +79,3 @@

return updateTable(portalId, tableId, schema);
return updateTable(accountId, tableId, schema);
}

@@ -132,4 +132,4 @@

async function downloadHubDbTable(portalId, tableId, dest) {
const table = await fetchTable(portalId, tableId);
async function downloadHubDbTable(accountId, tableId, dest) {
const table = await fetchTable(accountId, tableId);

@@ -149,3 +149,3 @@ dest = path.resolve(getCwd(), dest || `${table.name}.hubdb.json`);

while (totalRows === null || count < totalRows) {
const response = await fetchRows(portalId, tableId, { offset });
const response = await fetchRows(accountId, tableId, { offset });
if (totalRows === null) {

@@ -170,3 +170,3 @@ totalRows = response.total;

async function clearHubDbTableRows(portalId, tableId) {
async function clearHubDbTableRows(accountId, tableId) {
let totalRows = null;

@@ -177,3 +177,3 @@ let rows = [];

while (totalRows === null || count < totalRows) {
const response = await fetchRows(portalId, tableId, { offset });
const response = await fetchRows(accountId, tableId, { offset });
if (totalRows === null) {

@@ -188,3 +188,3 @@ totalRows = response.total;

}
await deleteRows(portalId, tableId, rows);
await deleteRows(accountId, tableId, rows);

@@ -191,0 +191,0 @@ return {

@@ -6,8 +6,8 @@ const { ALLOWED_EXTENSIONS, Mode, DEFAULT_MODE } = require('./lib/constants');

getConfig,
getPortalId,
getPortalConfig,
getAccountId,
getAccountConfig,
findConfig,
loadConfig,
loadConfigFromEnvironment,
updatePortalConfig,
updateAccountConfig,
validateConfig,

@@ -30,5 +30,8 @@ isTrackingAllowed,

loadConfigFromEnvironment,
getPortalConfig,
getPortalId,
updatePortalConfig,
getAccountConfig,
getAccountId,
getPortalConfig: getAccountConfig,
getPortalId: getAccountId,
updateAccountConfig,
updatePortalConfig: updateAccountConfig,
uploadFolder,

@@ -35,0 +38,0 @@ validateConfig,

const {
setConfig,
getAndLoadConfigIfNeeded,
getOrderedAccount,
getConfig,
getPortalConfig,
getPortalId,
updateDefaultPortal,
updatePortalConfig,
getConfigAccounts,
getConfigDefaultAccount,
getConfigAccountId,
getAccountConfig,
getAccountId,
getOrderedConfig,
updateDefaultAccount,
updateAccountConfig,
validateConfig,

@@ -21,9 +26,17 @@ deleteEmptyConfigFile,

name: 'API',
portalId: 1111,
accountId: 1111,
authType: 'apikey',
apiKey: 'secret',
};
const LEGACY_API_KEY_CONFIG = (() => {
const legacyObj = { ...API_KEY_CONFIG };
legacyObj.portalId = legacyObj.accountId + 1;
delete legacyObj.accountId;
return legacyObj;
})();
const OAUTH2_CONFIG = {
name: 'OAUTH2',
portalId: 2222,
accountId: 2222,
authType: 'oauth2',

@@ -41,5 +54,13 @@ auth: {

};
const LEGACY_OAUTH2_CONFIG = (() => {
const legacyObj = { ...OAUTH2_CONFIG };
legacyObj.portalId = legacyObj.accountId + 1;
delete legacyObj.accountId;
return legacyObj;
})();
const PERSONAL_ACCESS_KEY_CONFIG = {
name: 'PERSONALACCESSKEY',
portalId: 3333,
accountId: 3333,
authType: 'personalaccesskey',

@@ -56,6 +77,13 @@ auth: {

const PORTALS = [API_KEY_CONFIG, OAUTH2_CONFIG, PERSONAL_ACCESS_KEY_CONFIG];
const LEGACY_PERSONAL_ACCESS_KEY_CONFIG = (() => {
const legacyObj = { ...PERSONAL_ACCESS_KEY_CONFIG };
legacyObj.portalId = legacyObj.accountId + 1;
delete legacyObj.accountId;
return legacyObj;
})();
const getPortalByAuthType = (config, authType) => {
return config.portals.filter(portal => portal.authType === authType)[0];
const ACCOUNTS = [API_KEY_CONFIG, OAUTH2_CONFIG, PERSONAL_ACCESS_KEY_CONFIG];
const getAccountByAuthType = (config, authType) => {
return config.accounts.filter(account => account.authType === authType)[0];
};

@@ -66,4 +94,4 @@

const CONFIG = {
defaultPortal: PORTALS[0].name,
portals: PORTALS,
defaultAccount: ACCOUNTS[0].name,
accounts: ACCOUNTS,
};

@@ -79,37 +107,37 @@ beforeEach(() => {

describe('getPortalId method', () => {
describe('getAccountId method', () => {
beforeEach(() => {
process.env = {};
setConfig({
defaultPortal: PERSONAL_ACCESS_KEY_CONFIG.name,
portals: PORTALS,
defaultAccount: PERSONAL_ACCESS_KEY_CONFIG.name,
accounts: ACCOUNTS,
});
});
it('returns portalId from config when a name is passed', () => {
expect(getPortalId(OAUTH2_CONFIG.name)).toEqual(OAUTH2_CONFIG.portalId);
it('returns accountId from config when a name is passed', () => {
expect(getAccountId(OAUTH2_CONFIG.name)).toEqual(OAUTH2_CONFIG.accountId);
});
it('returns portalId from config when a string id is passed', () => {
expect(getPortalId(OAUTH2_CONFIG.portalId.toString())).toEqual(
OAUTH2_CONFIG.portalId
it('returns accountId from config when a string id is passed', () => {
expect(getAccountId(OAUTH2_CONFIG.accountId.toString())).toEqual(
OAUTH2_CONFIG.accountId
);
});
it('returns portalId from config when a numeric id is passed', () => {
expect(getPortalId(OAUTH2_CONFIG.portalId)).toEqual(
OAUTH2_CONFIG.portalId
it('returns accountId from config when a numeric id is passed', () => {
expect(getAccountId(OAUTH2_CONFIG.accountId)).toEqual(
OAUTH2_CONFIG.accountId
);
});
it('returns defaultPortal from config', () => {
expect(getPortalId()).toEqual(PERSONAL_ACCESS_KEY_CONFIG.portalId);
it('returns defaultAccount from config', () => {
expect(getAccountId()).toEqual(PERSONAL_ACCESS_KEY_CONFIG.accountId);
});
});
describe('updateDefaultPortal method', () => {
const myPortalName = 'Foo';
describe('updateDefaultAccount method', () => {
const myAccountName = 'Foo';
beforeEach(() => {
updateDefaultPortal(myPortalName);
updateDefaultAccount(myAccountName);
});
it('sets the defaultPortal in the config', () => {
expect(getConfig().defaultPortal).toEqual(myPortalName);
it('sets the defaultAccount in the config', () => {
expect(getConfig().defaultAccount).toEqual(myAccountName);
});

@@ -122,3 +150,3 @@ });

it('does not delete config file if there are contents', () => {
fs.__setReadFile('defaultPortal: Foo');
fs.__setReadFile('defaultAccount: Foo');
fs.__setExistsValue(true);

@@ -141,6 +169,6 @@ fs.unlinkSync = jest.fn();

describe('updatePortalConfig method', () => {
describe('updateAccountConfig method', () => {
const CONFIG = {
defaultPortal: PORTALS[0].name,
portals: PORTALS,
defaultAccount: ACCOUNTS[0].name,
accounts: ACCOUNTS,
};

@@ -157,3 +185,3 @@

delete modifiedPersonalAccessKeyConfig.env;
updatePortalConfig(modifiedPersonalAccessKeyConfig);
updateAccountConfig(modifiedPersonalAccessKeyConfig);

@@ -169,6 +197,6 @@ expect(getConfig().env).toBeFalsy();

};
updatePortalConfig(modifiedPersonalAccessKeyConfig);
updateAccountConfig(modifiedPersonalAccessKeyConfig);
expect(
getPortalByAuthType(
getAccountByAuthType(
getConfig(),

@@ -183,4 +211,4 @@ modifiedPersonalAccessKeyConfig.authType

setConfig({
defaultPortal: PERSONAL_ACCESS_KEY_CONFIG.name,
portals: [{ ...PERSONAL_ACCESS_KEY_CONFIG, env }],
defaultAccount: PERSONAL_ACCESS_KEY_CONFIG.name,
accounts: [{ ...PERSONAL_ACCESS_KEY_CONFIG, env }],
});

@@ -191,6 +219,6 @@ const modifiedPersonalAccessKeyConfig = {

delete modifiedPersonalAccessKeyConfig.env;
updatePortalConfig(modifiedPersonalAccessKeyConfig);
updateAccountConfig(modifiedPersonalAccessKeyConfig);
expect(
getPortalByAuthType(
getAccountByAuthType(
getConfig(),

@@ -206,4 +234,4 @@ modifiedPersonalAccessKeyConfig.authType

setConfig({
defaultPortal: PERSONAL_ACCESS_KEY_CONFIG.name,
portals: [{ ...PERSONAL_ACCESS_KEY_CONFIG, env: previousEnv }],
defaultAccount: PERSONAL_ACCESS_KEY_CONFIG.name,
accounts: [{ ...PERSONAL_ACCESS_KEY_CONFIG, env: previousEnv }],
});

@@ -214,6 +242,6 @@ const modifiedPersonalAccessKeyConfig = {

};
updatePortalConfig(modifiedPersonalAccessKeyConfig);
updateAccountConfig(modifiedPersonalAccessKeyConfig);
expect(
getPortalByAuthType(
getAccountByAuthType(
getConfig(),

@@ -230,3 +258,3 @@ modifiedPersonalAccessKeyConfig.authType

delete modifiedPersonalAccessKeyConfig.name;
updatePortalConfig(modifiedPersonalAccessKeyConfig);
updateAccountConfig(modifiedPersonalAccessKeyConfig);

@@ -242,6 +270,6 @@ expect(getConfig().name).toBeFalsy();

};
updatePortalConfig(modifiedPersonalAccessKeyConfig);
updateAccountConfig(modifiedPersonalAccessKeyConfig);
expect(
getPortalByAuthType(
getAccountByAuthType(
getConfig(),

@@ -256,4 +284,4 @@ modifiedPersonalAccessKeyConfig.authType

setConfig({
defaultPortal: PERSONAL_ACCESS_KEY_CONFIG.name,
portals: [{ ...PERSONAL_ACCESS_KEY_CONFIG, name }],
defaultAccount: PERSONAL_ACCESS_KEY_CONFIG.name,
accounts: [{ ...PERSONAL_ACCESS_KEY_CONFIG, name }],
});

@@ -264,6 +292,6 @@ const modifiedPersonalAccessKeyConfig = {

delete modifiedPersonalAccessKeyConfig.name;
updatePortalConfig(modifiedPersonalAccessKeyConfig);
updateAccountConfig(modifiedPersonalAccessKeyConfig);
expect(
getPortalByAuthType(
getAccountByAuthType(
getConfig(),

@@ -279,4 +307,4 @@ modifiedPersonalAccessKeyConfig.authType

setConfig({
defaultPortal: PERSONAL_ACCESS_KEY_CONFIG.name,
portals: [{ ...PERSONAL_ACCESS_KEY_CONFIG, env: previousName }],
defaultAccount: PERSONAL_ACCESS_KEY_CONFIG.name,
accounts: [{ ...PERSONAL_ACCESS_KEY_CONFIG, env: previousName }],
});

@@ -287,6 +315,6 @@ const modifiedPersonalAccessKeyConfig = {

};
updatePortalConfig(modifiedPersonalAccessKeyConfig);
updateAccountConfig(modifiedPersonalAccessKeyConfig);
expect(
getPortalByAuthType(
getAccountByAuthType(
getConfig(),

@@ -300,8 +328,8 @@ modifiedPersonalAccessKeyConfig.authType

describe('validateConfig method', () => {
const DEFAULT_PORTAL = PORTALS[0].name;
const DEFAULT_PORTAL = ACCOUNTS[0].name;
it('allows valid config', () => {
setConfig({
defaultPortal: DEFAULT_PORTAL,
portals: PORTALS,
defaultAccount: DEFAULT_PORTAL,
accounts: ACCOUNTS,
});

@@ -311,6 +339,6 @@ expect(validateConfig()).toEqual(true);

it('does not allow duplicate portalIds', () => {
it('does not allow duplicate accountIds', () => {
setConfig({
defaultPortal: DEFAULT_PORTAL,
portals: [...PORTALS, PORTALS[0]],
defaultAccount: DEFAULT_PORTAL,
accounts: [...ACCOUNTS, ACCOUNTS[0]],
});

@@ -322,8 +350,8 @@ expect(validateConfig()).toEqual(false);

setConfig({
defaultPortal: DEFAULT_PORTAL,
portals: [
...PORTALS,
defaultAccount: DEFAULT_PORTAL,
accounts: [
...ACCOUNTS,
{
...PORTALS[0],
portalId: 123456789,
...ACCOUNTS[0],
accountId: 123456789,
},

@@ -337,6 +365,6 @@ ],

setConfig({
defaultPortal: DEFAULT_PORTAL,
portals: [
defaultAccount: DEFAULT_PORTAL,
accounts: [
{
...PORTALS[0],
...ACCOUNTS[0],
name: 'A NAME WITH SPACES',

@@ -349,12 +377,12 @@ },

it('allows multiple portals with no name', () => {
it('allows multiple accounts with no name', () => {
setConfig({
defaultPortal: DEFAULT_PORTAL,
portals: [
defaultAccount: DEFAULT_PORTAL,
accounts: [
{
...PORTALS[0],
...ACCOUNTS[0],
name: null,
},
{
...PORTALS[1],
...ACCOUNTS[1],
name: null,

@@ -386,3 +414,3 @@ },

const {
portalId,
accountId,
auth: {

@@ -394,7 +422,7 @@ clientId,

} = OAUTH2_CONFIG;
let portalConfig;
let accountConfig;
beforeEach(() => {
process.env = {
HUBSPOT_PORTAL_ID: portalId,
HUBSPOT_PORTAL_ID: accountId,
HUBSPOT_CLIENT_ID: clientId,

@@ -405,3 +433,3 @@ HUBSPOT_CLIENT_SECRET: clientSecret,

getAndLoadConfigIfNeeded({ useEnv: true });
portalConfig = getPortalConfig(portalId);
accountConfig = getAccountConfig(accountId);
});

@@ -413,20 +441,20 @@

it('creates a portal config', () => {
expect(portalConfig).toBeTruthy();
it('creates a account config', () => {
expect(accountConfig).toBeTruthy();
});
it('properly loads portal id value', () => {
expect(portalConfig.portalId).toEqual(portalId);
it('properly loads account id value', () => {
expect(accountConfig.accountId).toEqual(accountId);
});
it('properly loads client id value', () => {
expect(portalConfig.auth.clientId).toEqual(clientId);
expect(accountConfig.auth.clientId).toEqual(clientId);
});
it('properly loads client secret value', () => {
expect(portalConfig.auth.clientSecret).toEqual(clientSecret);
expect(accountConfig.auth.clientSecret).toEqual(clientSecret);
});
it('properly loads refresh token value', () => {
expect(portalConfig.auth.tokenInfo.refreshToken).toEqual(refreshToken);
expect(accountConfig.auth.tokenInfo.refreshToken).toEqual(refreshToken);
});

@@ -436,12 +464,12 @@ });

describe('apikey environment variable config', () => {
const { portalId, apiKey } = API_KEY_CONFIG;
let portalConfig;
const { accountId, apiKey } = API_KEY_CONFIG;
let accountConfig;
beforeEach(() => {
process.env = {
HUBSPOT_PORTAL_ID: portalId,
HUBSPOT_PORTAL_ID: accountId,
HUBSPOT_API_KEY: apiKey,
};
getAndLoadConfigIfNeeded({ useEnv: true });
portalConfig = getPortalConfig(portalId);
accountConfig = getAccountConfig(accountId);
});

@@ -453,12 +481,12 @@

it('creates a portal config', () => {
expect(portalConfig).toBeTruthy();
it('creates a account config', () => {
expect(accountConfig).toBeTruthy();
});
it('properly loads portal id value', () => {
expect(portalConfig.portalId).toEqual(portalId);
it('properly loads account id value', () => {
expect(accountConfig.accountId).toEqual(accountId);
});
it('properly loads api key value', () => {
expect(portalConfig.apiKey).toEqual(apiKey);
expect(accountConfig.apiKey).toEqual(apiKey);
});

@@ -468,12 +496,12 @@ });

describe('personalaccesskey environment variable config', () => {
const { portalId, personalAccessKey } = PERSONAL_ACCESS_KEY_CONFIG;
let portalConfig;
const { accountId, personalAccessKey } = PERSONAL_ACCESS_KEY_CONFIG;
let accountConfig;
beforeEach(() => {
process.env = {
HUBSPOT_PORTAL_ID: portalId,
HUBSPOT_PORTAL_ID: accountId,
HUBSPOT_PERSONAL_ACCESS_KEY: personalAccessKey,
};
getAndLoadConfigIfNeeded({ useEnv: true });
portalConfig = getPortalConfig(portalId);
accountConfig = getAccountConfig(accountId);
});

@@ -485,12 +513,12 @@

it('creates a portal config', () => {
expect(portalConfig).toBeTruthy();
it('creates a account config', () => {
expect(accountConfig).toBeTruthy();
});
it('properly loads portal id value', () => {
expect(portalConfig.portalId).toEqual(portalId);
it('properly loads account id value', () => {
expect(accountConfig.accountId).toEqual(accountId);
});
it('properly loads personal access key value', () => {
expect(portalConfig.personalAccessKey).toEqual(personalAccessKey);
expect(accountConfig.personalAccessKey).toEqual(personalAccessKey);
});

@@ -585,2 +613,378 @@ });

});
describe('legacy accounts (portals)', () => {
const LEGACY_ACCOUNTS = [
LEGACY_API_KEY_CONFIG,
LEGACY_OAUTH2_CONFIG,
LEGACY_PERSONAL_ACCESS_KEY_CONFIG,
];
const COMBINED_ACCOUNTS = [
Object.assign({}, API_KEY_CONFIG, LEGACY_API_KEY_CONFIG),
Object.assign({}, OAUTH2_CONFIG, LEGACY_OAUTH2_CONFIG),
Object.assign(
{},
PERSONAL_ACCESS_KEY_CONFIG,
LEGACY_PERSONAL_ACCESS_KEY_CONFIG
),
];
describe('getConfigAccounts', () => {
it('supports legacy configs', () => {
expect(
getConfigAccounts({ portals: [{ portalId: 'foo' }] })[0].portalId
).toEqual('foo');
});
it('supports combined configs, and favors accounts over portals', () => {
const config = {
portals: [{ portalId: 'foo' }],
accounts: [{ accountId: 'bar' }],
};
expect(getConfigAccounts(config)[0].portalId).toBeUndefined();
expect(getConfigAccounts(config)[0].accountId).toEqual('bar');
});
});
describe('getConfigDefaultAccount', () => {
it('supports legacy configs', () => {
expect(
getConfigDefaultAccount({
defaultPortal: 'fooPortal',
})
).toEqual('fooPortal');
});
it('supports combined configs, and favors accounts over portals', () => {
expect(
getConfigDefaultAccount({
defaultPortal: 'fooPortal',
defaultAccount: 'fooAccount',
})
).toEqual('fooAccount');
});
});
describe('getConfigAccountId', () => {
it('supports legacy configs', () => {
expect(
getConfigAccountId({
portalId: 'fooPortal',
})
).toEqual('fooPortal');
});
it('supports combined configs, and favors accounts over portals', () => {
expect(
getConfigAccountId({
portalId: 'fooPortal',
accountId: 'fooAccount',
})
).toEqual('fooAccount');
});
});
describe('getOrderedAccount', () => {
it('supports legacy portalId', () => {
expect(
getOrderedAccount({
portalId: '123',
name: 'this should go before',
})
).toMatchInlineSnapshot(`
Object {
"authType": undefined,
"env": undefined,
"name": "this should go before",
"portalId": "123",
}
`);
});
it('supports combined configs', () => {
expect(
getOrderedAccount({
portalId: '123',
accountId: '123',
name: 'this should go before',
})
).toMatchInlineSnapshot(`
Object {
"accountId": "123",
"authType": undefined,
"env": undefined,
"name": "this should go before",
"portalId": "123",
}
`);
});
});
describe('getOrderedConfig', () => {
it('supports legacy portal', () => {
expect(
getOrderedConfig({
defaultPortal: LEGACY_PERSONAL_ACCESS_KEY_CONFIG.portalId,
accounts: [LEGACY_PERSONAL_ACCESS_KEY_CONFIG],
})
).toMatchInlineSnapshot(`
Object {
"accounts": Array [
Object {
"auth": Object {
"scopes": Array [
"content",
],
"tokenInfo": Object {
"accessToken": "fakePersonalAccessKeyAccessToken",
"expiresAt": "2020-01-01T00:00:00.000Z",
},
},
"authType": "personalaccesskey",
"env": undefined,
"name": "PERSONALACCESSKEY",
"personalAccessKey": "fakePersonalAccessKey",
"portalId": 3334,
},
],
"allowsUsageTracking": undefined,
"defaultMode": undefined,
"defaultPortal": 3334,
"httpTimeout": undefined,
}
`);
});
it('supports combined', () => {
expect(
getOrderedConfig({
defaultAccount: PERSONAL_ACCESS_KEY_CONFIG.accountId,
defaultPortal: LEGACY_PERSONAL_ACCESS_KEY_CONFIG.portalId,
accounts: [
Object.assign(
{},
PERSONAL_ACCESS_KEY_CONFIG,
LEGACY_PERSONAL_ACCESS_KEY_CONFIG
),
],
})
).toMatchInlineSnapshot(`
Object {
"accounts": Array [
Object {
"accountId": 3333,
"auth": Object {
"scopes": Array [
"content",
],
"tokenInfo": Object {
"accessToken": "fakePersonalAccessKeyAccessToken",
"expiresAt": "2020-01-01T00:00:00.000Z",
},
},
"authType": "personalaccesskey",
"env": undefined,
"name": "PERSONALACCESSKEY",
"personalAccessKey": "fakePersonalAccessKey",
"portalId": 3334,
},
],
"allowsUsageTracking": undefined,
"defaultAccount": 3333,
"defaultMode": undefined,
"defaultPortal": 3334,
"httpTimeout": undefined,
}
`);
});
});
describe('getAccountConfig', () => {
describe('portalId', () => {
beforeEach(() => {
const CONFIG = {
portals: LEGACY_ACCOUNTS,
};
setConfig(CONFIG);
});
it('supports portalId', () => {
expect(getAccountConfig(2222)).toMatchInlineSnapshot(`undefined`);
});
});
describe('combined', () => {
beforeEach(() => {
const CONFIG = {
portals: COMBINED_ACCOUNTS,
};
setConfig(CONFIG);
});
it('favors account over portal', () => {
expect(getAccountConfig(2222)).toMatchInlineSnapshot(`
Object {
"accountId": 2222,
"auth": Object {
"clientId": "fakeClientId",
"clientSecret": "fakeClientSecret",
"scopes": Array [
"content",
],
"tokenInfo": Object {
"accessToken": "fakeOauthAccessToken",
"expiresAt": "2020-01-01T00:00:00.000Z",
"refreshToken": "fakeOauthRefreshToken",
},
},
"authType": "oauth2",
"name": "OAUTH2",
"portalId": 2223,
}
`);
});
});
});
describe('getAccountId', () => {
describe('portalId', () => {
beforeEach(() => {
const CONFIG = {
portals: LEGACY_ACCOUNTS,
};
setConfig(CONFIG);
});
it('supports portalId', () => {
expect(getAccountId(LEGACY_API_KEY_CONFIG.name)).toEqual(
LEGACY_API_KEY_CONFIG.portalId
);
});
});
describe('combination', () => {
beforeEach(() => {
const CONFIG = {
portals: COMBINED_ACCOUNTS,
};
setConfig(CONFIG);
});
it('favors account over portal', () => {
expect(getAccountId(COMBINED_ACCOUNTS[0].name)).toEqual(
COMBINED_ACCOUNTS[0].accountId
);
});
});
});
describe('updateAccountConfig', () => {
describe('portalId', () => {
beforeEach(() => {
const CONFIG = {
portals: LEGACY_ACCOUNTS,
};
setConfig(CONFIG);
});
it('supports portalId', () => {
expect(
updateAccountConfig(
Object.assign({}, LEGACY_API_KEY_CONFIG, { portalId: 999 })
)
).toMatchInlineSnapshot(`
Object {
"apiKey": "secret",
"auth": undefined,
"authType": "apikey",
"defaultMode": undefined,
"env": undefined,
"name": "API",
"personalAccessKey": undefined,
"portalId": 999,
}
`);
});
});
describe('combination', () => {
beforeEach(() => {
const CONFIG = {
portals: LEGACY_ACCOUNTS,
};
setConfig(CONFIG);
});
it('supports combination, adds both', () => {
expect(
updateAccountConfig(
Object.assign({}, COMBINED_ACCOUNTS[0], { portalId: 999 })
)
).toMatchInlineSnapshot(`
Object {
"accountId": 1111,
"apiKey": "secret",
"auth": undefined,
"authType": "apikey",
"defaultMode": undefined,
"env": undefined,
"name": "API",
"personalAccessKey": undefined,
"portalId": 999,
}
`);
});
});
});
describe('updateDefaultAccount', () => {
describe('legacy', () => {
beforeEach(() => {
const CONFIG = {
defaultPortal: 9999,
portals: LEGACY_ACCOUNTS,
};
setConfig(CONFIG);
});
it('supports defaultPortal', () => {
updateDefaultAccount(LEGACY_ACCOUNTS[0].portalId);
expect(getConfigDefaultAccount()).toEqual(
LEGACY_ACCOUNTS[0].portalId
);
});
});
});
describe('getConfigVariablesFromEnv', () => {
describe('legacy', () => {
beforeEach(() => {
const CONFIG = {
defaultAccount: 8888,
defaultPortal: 9999,
portals: COMBINED_ACCOUNTS,
};
setConfig(CONFIG);
});
it('supports both defaultPortal and defaultAccount', () => {
updateDefaultAccount(LEGACY_ACCOUNTS[0].portalId);
expect(getConfig().defaultAccount).toEqual(
LEGACY_ACCOUNTS[0].portalId
);
expect(getConfig().defaultPortal).toEqual(
LEGACY_ACCOUNTS[0].portalId
);
});
});
});
});
});

@@ -30,3 +30,3 @@ const { uploadFolder } = require('../uploadFolder');

const portalId = 123;
const accountId = 123;
const src = 'folder';

@@ -48,3 +48,3 @@ const dest = 'folder';

await uploadFolder(portalId, src, dest, { mode: 'publish', cwd });
await uploadFolder(accountId, src, dest, { mode: 'publish', cwd });

@@ -54,3 +54,3 @@ expect(upload).toReturnTimes(10);

uploadedFilesInOrder.forEach((file, index) => {
expect(upload).nthCalledWith(index + 1, portalId, file, file, {
expect(upload).nthCalledWith(index + 1, accountId, file, file, {
qs: { buffer: false },

@@ -57,0 +57,0 @@ });

@@ -37,2 +37,20 @@ const fs = require('fs-extra');

const getConfigAccounts = config => {
const __config = config || getConfig();
if (!__config) return;
return __config.accounts || __config.portals;
};
const getConfigDefaultAccount = config => {
const __config = config || getConfig();
if (!__config) return;
return __config.defaultAccount || __config.defaultPortal;
};
const getConfigAccountId = config => {
const __config = config || getConfig();
if (!__config) return;
return __config.accountId || __config.portalId;
};
/**

@@ -47,20 +65,23 @@ * @returns {boolean}

}
if (!Array.isArray(config.portals)) {
logger.error('config.portals[] is not defined');
const accounts = getConfigAccounts();
if (!Array.isArray(accounts)) {
logger.error('config.accounts[] is not defined');
return false;
}
const portalIdsHash = {};
const portalNamesHash = {};
return config.portals.every(cfg => {
const accountIdsHash = {};
const accountNamesHash = {};
return accounts.every(cfg => {
if (!cfg) {
logger.error('config.portals[] has an empty entry');
logger.error('config.accounts[] has an empty entry');
return false;
}
if (!cfg.portalId) {
logger.error('config.portals[] has an entry missing portalId');
const accountId = getConfigAccountId(cfg);
if (!accountId) {
logger.error('config.accounts[] has an entry missing accountId');
return false;
}
if (portalIdsHash[cfg.portalId]) {
if (accountIdsHash[accountId]) {
logger.error(
`config.portals[] has multiple entries with portalId=${cfg.portalId}`
`config.accounts[] has multiple entries with accountId=${accountId}`
);

@@ -71,5 +92,5 @@ return false;

if (cfg.name) {
if (portalNamesHash[cfg.name]) {
if (accountNamesHash[cfg.name]) {
logger.error(
`config.name has multiple entries with portalId=${cfg.portalId}`
`config.name has multiple entries with accountId=${accountId}`
);

@@ -82,6 +103,6 @@ return false;

}
portalNamesHash[cfg.name] = cfg;
accountNamesHash[cfg.name] = cfg;
}
portalIdsHash[cfg.portalId] = cfg;
accountIdsHash[accountId] = cfg;
return true;

@@ -91,18 +112,27 @@ });

const portalNameExistsInConfig = name => {
const accountNameExistsInConfig = name => {
const config = getConfig();
const accounts = getConfigAccounts();
if (!config || !Array.isArray(config.portals)) {
if (!config || !Array.isArray(accounts)) {
return false;
}
return config.portals.some(cfg => cfg.name && cfg.name === name);
return accounts.some(cfg => cfg.name && cfg.name === name);
};
const getOrderedPortal = unorderedPortal => {
const { name, portalId, env, authType, ...rest } = unorderedPortal;
const getOrderedAccount = unorderedAccount => {
const {
name,
accountId,
portalId,
env,
authType,
...rest
} = unorderedAccount;
return {
name,
portalId,
...(accountId && { accountId }),
...(portalId && { portalId }),
env,

@@ -116,2 +146,3 @@ authType,

const {
defaultAccount,
defaultPortal,

@@ -121,2 +152,3 @@ defaultMode,

allowsUsageTracking,
accounts,
portals,

@@ -127,7 +159,8 @@ ...rest

return {
defaultPortal,
...(defaultAccount && { defaultAccount }),
...(defaultPortal && { defaultPortal }),
defaultMode,
httpTimeout,
allowsUsageTracking,
portals: portals.map(getOrderedPortal),
accounts: (accounts || portals).map(getOrderedAccount),
...rest,

@@ -322,3 +355,3 @@ };

_config = {
portals: [],
accounts: [],
};

@@ -383,8 +416,8 @@ }

const config = getAndLoadConfigIfNeeded();
const portalId = getPortalId(nameOrId);
const accountId = getAccountId(nameOrId);
if (portalId) {
const portalConfig = getPortalConfig(portalId);
if (portalConfig.env) {
env = portalConfig.env;
if (accountId) {
const accountConfig = getAccountConfig(accountId);
if (accountConfig.env) {
env = accountConfig.env;
}

@@ -397,25 +430,27 @@ } else if (config && config.env) {

const getPortalConfig = portalId => {
const config = getAndLoadConfigIfNeeded();
return config.portals.find(portal => portal.portalId === portalId);
};
const getAccountConfig = accountId =>
getConfigAccounts(getAndLoadConfigIfNeeded()).find(
account => account.accountId === accountId || account.portalId === accountId
);
/*
* Returns a portalId from the config if it exists, else returns null
* Returns a accountId from the config if it exists, else returns null
*/
const getPortalId = nameOrId => {
const getAccountId = nameOrId => {
const config = getAndLoadConfigIfNeeded();
let name;
let portalId;
let portal;
let accountId;
let account;
if (!nameOrId) {
if (config && config.defaultPortal) {
name = config.defaultPortal;
const defaultAccount = getConfigDefaultAccount(config);
if (defaultAccount) {
name = defaultAccount;
}
} else {
if (typeof nameOrId === 'number') {
portalId = nameOrId;
accountId = nameOrId;
} else if (/^\d+$/.test(nameOrId)) {
portalId = parseInt(nameOrId, 10);
accountId = parseInt(nameOrId, 10);
} else {

@@ -426,10 +461,11 @@ name = nameOrId;

const accounts = getConfigAccounts(config);
if (name) {
portal = config.portals.find(p => p.name === name);
} else if (portalId) {
portal = config.portals.find(p => p.portalId === portalId);
account = accounts.find(p => p.name === name);
} else if (accountId) {
account = accounts.find(p => [p.accountId, p.portalId].includes(accountId));
}
if (portal) {
return portal.portalId;
if (account) {
return account.accountId || account.portalId;
}

@@ -443,4 +479,5 @@

*/
const updatePortalConfig = configOptions => {
const updateAccountConfig = configOptions => {
const {
accountId: _accountId,
portalId,

@@ -458,9 +495,10 @@ authType,

} = configOptions;
const accountId = _accountId || portalId;
if (!portalId) {
throw new Error('A portalId is required to update the config');
if (!accountId) {
throw new Error('An accountId is required to update the config');
}
const config = getAndLoadConfigIfNeeded();
const portalConfig = getPortalConfig(portalId);
const accountConfig = getAccountConfig(accountId);

@@ -470,3 +508,3 @@ let auth;

auth = {
...(portalConfig ? portalConfig.auth : {}),
...(accountConfig ? accountConfig.auth : {}),
clientId,

@@ -479,11 +517,12 @@ clientSecret,

const env = getValidEnv(environment || (portalConfig && portalConfig.env), {
const env = getValidEnv(environment || (accountConfig && accountConfig.env), {
maskedProductionValue: undefined,
});
const mode = defaultMode && defaultMode.toLowerCase();
const nextPortalConfig = {
...portalConfig,
name: name || (portalConfig && portalConfig.name),
const nextAccountConfig = {
...accountConfig,
name: name || (accountConfig && accountConfig.name),
env,
portalId,
...(_accountId && { accountId: _accountId }),
...(portalId && { portalId }),
authType,

@@ -496,15 +535,16 @@ auth,

if (portalConfig) {
logger.debug(`Updating config for ${portalId}`);
const index = config.portals.indexOf(portalConfig);
config.portals[index] = nextPortalConfig;
let accounts = getConfigAccounts(config);
if (accountConfig) {
logger.debug(`Updating config for ${accountId}`);
const index = accounts.indexOf(accountConfig);
accounts[index] = nextAccountConfig;
} else {
logger.debug(`Adding config entry for ${portalId}`);
if (config.portals) {
config.portals.push(nextPortalConfig);
logger.debug(`Adding config entry for ${accountId}`);
if (accounts) {
accounts.push(nextAccountConfig);
} else {
config.portals = [nextPortalConfig];
accounts = [nextAccountConfig];
}
}
return nextPortalConfig;
return nextAccountConfig;
};

@@ -515,9 +555,9 @@

*/
const updateDefaultPortal = defaultPortal => {
const updateDefaultAccount = defaultAccount => {
if (
!defaultPortal ||
(typeof defaultPortal !== 'number' && typeof defaultPortal !== 'string')
!defaultAccount ||
(typeof defaultAccount !== 'number' && typeof defaultAccount !== 'string')
) {
throw new Error(
'A defaultPortal with value of number or string is required to update the config'
'A defaultAccount with value of number or string is required to update the config'
);

@@ -527,3 +567,10 @@ }

const config = getAndLoadConfigIfNeeded();
config.defaultPortal = defaultPortal;
if (config.defaultAccount) {
config.defaultAccount = defaultAccount;
}
// Keep for backcompat
if (config.defaultPortal) {
config.defaultPortal = defaultAccount;
}
setDefaultConfigPathIfUnset();

@@ -575,3 +622,9 @@ writeConfig();

personalAccessKey: env[ENVIRONMENT_VARIABLES.HUBSPOT_PERSONAL_ACCESS_KEY],
portalId: parseInt(env[ENVIRONMENT_VARIABLES.HUBSPOT_PORTAL_ID], 10),
accountId: parseInt(
env[
ENVIRONMENT_VARIABLES.HUBSPOT_PORTAL_ID ||
ENVIRONMENT_VARIABLES.HUBSPOT_ACCOUNT_ID
],
10
),
refreshToken: env[ENVIRONMENT_VARIABLES.HUBSPOT_REFRESH_TOKEN],

@@ -582,8 +635,8 @@ env: getValidEnv(env[ENVIRONMENT_VARIABLES.HUBSPOT_ENVIRONMENT]),

const generatePersonalAccessKeyConfig = (portalId, personalAccessKey, env) => {
const generatePersonalAccessKeyConfig = (accountId, personalAccessKey, env) => {
return {
portals: [
accounts: [
{
authType: PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
portalId,
accountId,
personalAccessKey,

@@ -597,3 +650,3 @@ env,

const generateOauthConfig = (
portalId,
accountId,
clientId,

@@ -606,6 +659,6 @@ clientSecret,

return {
portals: [
accounts: [
{
authType: OAUTH_AUTH_METHOD.value,
portalId,
accountId,
auth: {

@@ -625,8 +678,8 @@ clientId,

const generateApiKeyConfig = (portalId, apiKey, env) => {
const generateApiKeyConfig = (accountId, apiKey, env) => {
return {
portals: [
accounts: [
{
authType: API_KEY_AUTH_METHOD.value,
portalId,
accountId,
apiKey,

@@ -645,3 +698,3 @@ env,

personalAccessKey,
portalId,
accountId,
refreshToken,

@@ -651,3 +704,3 @@ env,

if (!portalId) {
if (!accountId) {
return;

@@ -657,6 +710,6 @@ }

if (personalAccessKey) {
return generatePersonalAccessKeyConfig(portalId, personalAccessKey, env);
return generatePersonalAccessKeyConfig(accountId, personalAccessKey, env);
} else if (clientId && clientSecret && refreshToken) {
return generateOauthConfig(
portalId,
accountId,
clientId,

@@ -669,3 +722,3 @@ clientSecret,

} else if (apiKey) {
return generateApiKeyConfig(portalId, apiKey, env);
return generateApiKeyConfig(accountId, apiKey, env);
} else {

@@ -682,6 +735,6 @@ return;

}
const { portalId } = getConfigVariablesFromEnv();
const { accountId } = getConfigVariablesFromEnv();
logger.debug(
`Loaded config from enviroment variables for portal ${portalId}`
`Loaded config from environment variables for account ${accountId}`
);

@@ -697,3 +750,8 @@

getConfig,
getConfigAccounts,
getConfigDefaultAccount,
getConfigAccountId,
getConfigPath,
getOrderedAccount,
getOrderedConfig,
setConfig,

@@ -704,6 +762,6 @@ setConfigPath,

loadConfigFromEnvironment,
getPortalConfig,
getPortalId,
updatePortalConfig,
updateDefaultPortal,
getAccountConfig,
getAccountId,
updateAccountConfig,
updateDefaultAccount,
createEmptyConfigFile,

@@ -715,3 +773,3 @@ deleteEmptyConfigFile,

configFilenameIsIgnoredByGitignore,
portalNameExistsInConfig,
accountNameExistsInConfig,
};

@@ -87,2 +87,3 @@ const ENVIRONMENTS = {

HUBSPOT_PORTAL_ID: 'HUBSPOT_PORTAL_ID',
HUBSPOT_ACCOUNT_ID: 'HUBSPOT_ACCOUNT_ID',
HUBSPOT_REFRESH_TOKEN: 'HUBSPOT_REFRESH_TOKEN',

@@ -89,0 +90,0 @@ HUBSPOT_ENVIRONMENT: 'HUBSPOT_ENVIRONMENT',

@@ -12,3 +12,3 @@ const request = require('request-promise-native');

{
portalId,
accountId,
clientId,

@@ -28,3 +28,3 @@ clientSecret,

this.tokenInfo = tokenInfo;
this.portalId = portalId;
this.accountId = accountId;
this.env = getValidEnv(environment, true);

@@ -40,3 +40,3 @@ this.logger = logger;

throw new Error(
`The portal ${this.portalId} has not been authenticated with Oauth2`
`The account ${this.accountId} has not been authenticated with Oauth2`
);

@@ -57,3 +57,3 @@ }

this.logger.debug(
`Fetching access token for portalId ${this.portalId} for clientId ${this.clientId}`
`Fetching access token for accountId ${this.accountId} for clientId ${this.clientId}`
);

@@ -83,3 +83,3 @@ try {

this.logger.debug(
`Persisting updated tokenInfo for portalId ${this.portalId} for clientId ${this.clientId}`
`Persisting updated tokenInfo for accountId ${this.accountId} for clientId ${this.clientId}`
);

@@ -99,3 +99,3 @@ this.writeTokenInfo(this.tokenInfo);

this.logger.debug(
`Waiting for access token for portalId ${this.portalId} for clientId ${this.clientId} to be fetched`
`Waiting for access token for accountId ${this.accountId} for clientId ${this.clientId} to be fetched`
);

@@ -138,5 +138,5 @@ await this.refreshTokenRequest;

static fromConfig(portalId, portalConfig, logger, writeTokenInfo) {
const { env, auth, ...rest } = portalConfig;
if (portalConfig) {
static fromConfig(accountId, accountConfig, logger, writeTokenInfo) {
const { env, auth, ...rest } = accountConfig;
if (accountConfig) {
return new OAuth2Manager(

@@ -153,3 +153,3 @@ {

throw new Error(
`Portal Id ${portalId} not found in the config. Did you authorize?`
`Account Id ${accountId} not found in the config. Did you authorize?`
);

@@ -156,0 +156,0 @@ }

@@ -52,3 +52,3 @@ const path = require('path');

*
* @param {number} portalId
* @param {number} accountId
* @param {string} src

@@ -58,3 +58,3 @@ * @param {string} dest

*/
async function uploadFolder(portalId, src, dest, { mode, cwd }) {
async function uploadFolder(accountId, src, dest, { mode, cwd }) {
const regex = new RegExp(`^${escapeRegExp(src)}`);

@@ -85,3 +85,3 @@ const apiOptions = {

try {
await upload(portalId, file, destPath, apiOptions);
await upload(accountId, file, destPath, apiOptions);
logger.log('Uploaded file "%s" to "%s"', file, destPath);

@@ -121,3 +121,3 @@ } catch (error) {

try {
await upload(portalId, file, destPath, apiOptions);
await upload(accountId, file, destPath, apiOptions);
logger.log('Uploaded file "%s" to "%s"', file, destPath);

@@ -132,3 +132,3 @@ } catch (error) {

new ApiErrorContext({
portalId,
accountId,
request: destPath,

@@ -135,0 +135,0 @@ payload: file,

@@ -24,3 +24,3 @@ const path = require('path');

function uploadFile(portalId, file, dest, { mode, cwd }) {
function uploadFile(accountId, file, dest, { mode, cwd }) {
if (!isAllowedExtension(file)) {

@@ -40,3 +40,3 @@ logger.debug(`Skipping ${file} due to unsupported extension`);

return queue.add(() => {
return upload(portalId, file, dest, apiOptions)
return upload(accountId, file, dest, apiOptions)
.then(() => {

@@ -49,3 +49,3 @@ logger.log(`Uploaded file ${file} to ${dest}`);

logger.debug('Retrying to upload file "%s" to "%s"', file, dest);
return upload(portalId, file, dest, apiOptions).catch(error => {
return upload(accountId, file, dest, apiOptions).catch(error => {
logger.error(uploadFailureMessage);

@@ -55,3 +55,3 @@ logApiUploadErrorInstance(

new ApiErrorContext({
portalId,
accountId,
request: dest,

@@ -66,3 +66,3 @@ payload: file,

async function deleteRemoteFile(portalId, filePath, remoteFilePath, { cwd }) {
async function deleteRemoteFile(accountId, filePath, remoteFilePath, { cwd }) {
if (shouldIgnoreFile(filePath, cwd)) {

@@ -75,3 +75,3 @@ logger.debug(`Skipping ${filePath} due to an ignore rule`);

return queue.add(() => {
return deleteFile(portalId, remoteFilePath)
return deleteFile(accountId, remoteFilePath)
.then(() => {

@@ -85,3 +85,3 @@ logger.log(`Deleted file ${remoteFilePath}`);

new ApiErrorContext({
portalId,
accountId,
request: remoteFilePath,

@@ -95,3 +95,3 @@ })

function watch(
portalId,
accountId,
src,

@@ -119,6 +119,6 @@ dest,

// Use uploadFolder so that failures of initial upload are retried
uploadFolder(portalId, src, dest, { mode, cwd })
uploadFolder(accountId, src, dest, { mode, cwd })
.then(() => {
logger.success(
`Completed uploading files in ${src} to ${dest} in ${portalId}`
`Completed uploading files in ${src} to ${dest} in ${accountId}`
);

@@ -128,6 +128,6 @@ })

logger.error(
`Initial uploading of folder "${src}" to "${dest} in portal ${portalId} failed`
`Initial uploading of folder "${src}" to "${dest} in account ${accountId} failed`
);
logErrorInstance(error, {
portalId,
accountId,
});

@@ -143,3 +143,3 @@ });

const destPath = getDesignManagerPath(filePath);
const uploadPromise = uploadFile(portalId, filePath, destPath, {
const uploadPromise = uploadFile(accountId, filePath, destPath, {
mode,

@@ -162,5 +162,10 @@ cwd,

queue.add(() => {
const deletePromise = deleteRemoteFile(portalId, filePath, remotePath, {
cwd,
})
const deletePromise = deleteRemoteFile(
accountId,
filePath,
remotePath,
{
cwd,
}
)
.then(() => {

@@ -174,3 +179,3 @@ logger.log('Deleted %s "%s"', type, remotePath);

new ApiErrorContext({
portalId,
accountId,
request: remotePath,

@@ -191,3 +196,3 @@ })

const destPath = getDesignManagerPath(filePath);
const uploadPromise = uploadFile(portalId, filePath, destPath, {
const uploadPromise = uploadFile(accountId, filePath, destPath, {
mode,

@@ -194,0 +199,0 @@ cwd,

const OAuth2Manager = require('./lib/models/OAuth2Manager');
const { updatePortalConfig, writeConfig } = require('./lib/config');
const { updateAccountConfig, writeConfig } = require('./lib/config');
const { logger, logErrorInstance } = require('./logger');

@@ -8,12 +8,12 @@ const { AUTH_METHODS } = require('./lib/constants');

const writeOauthTokenInfo = (portalConfig, tokenInfo) => {
const { portalId, authType, auth, env, name, apiKey } = portalConfig;
const writeOauthTokenInfo = (AccountConfig, tokenInfo) => {
const { accountId, authType, auth, env, name, apiKey } = AccountConfig;
logger.debug(`Updating Oauth2 token info for portalId: ${portalId}`);
logger.debug(`Updating Oauth2 token info for accountId: ${accountId}`);
updatePortalConfig({
updateAccountConfig({
name,
apiKey,
environment: env,
portalId,
accountId,
authType,

@@ -26,22 +26,22 @@ ...auth,

const getOauthManager = (portalId, portalConfig) => {
if (!oauthManagers.has(portalId)) {
const getOauthManager = (accountId, accountConfig) => {
if (!oauthManagers.has(accountId)) {
const writeTokenInfo = tokenInfo => {
writeOauthTokenInfo(portalConfig, tokenInfo);
writeOauthTokenInfo(accountConfig, tokenInfo);
};
oauthManagers.set(
portalId,
OAuth2Manager.fromConfig(portalId, portalConfig, logger, writeTokenInfo)
accountId,
OAuth2Manager.fromConfig(accountId, accountConfig, logger, writeTokenInfo)
);
}
return oauthManagers.get(portalId);
return oauthManagers.get(accountId);
};
const addOauthToPortalConfig = (portalId, oauth) => {
const addOauthToAccountConfig = (accountId, oauth) => {
logger.log('Updating configuration');
try {
updatePortalConfig({
updateAccountConfig({
...oauth.toObj(),
authType: AUTH_METHODS.oauth.value,
portalId,
accountId,
});

@@ -57,3 +57,3 @@ writeConfig();

getOauthManager,
addOauthToPortalConfig,
addOauthToAccountConfig,
};
{
"name": "@hubspot/cms-lib",
"version": "2.1.1-beta.10",
"version": "2.2.1-beta.0",
"description": "Library for working with the HubSpot CMS",

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

},
"gitHead": "56f5b034ce6ceaf8259c78ccf34ed8b67f2863db"
"gitHead": "107557ac93c35dbb84e4d5292d50849a241db660"
}

@@ -5,5 +5,5 @@ const moment = require('moment');

getEnv,
getPortalConfig,
updatePortalConfig,
updateDefaultPortal,
getAccountConfig,
updateAccountConfig,
updateDefaultAccount,
writeConfig,

@@ -28,7 +28,7 @@ } = require('./lib/config');

env = ENVIRONMENTS.PROD,
portalId
accountId
) {
let response;
try {
response = await fetchAccessToken(personalAccessKey, env, portalId);
response = await fetchAccessToken(personalAccessKey, env, accountId);
} catch (e) {

@@ -49,3 +49,3 @@ if (e.response) {

return {
portalId: response.hubId,
accountId: response.hubId,
accessToken: response.oauthAccessToken,

@@ -59,3 +59,3 @@ expiresAt: moment(response.expiresAtMillis),

async function refreshAccessToken(
portalId,
accountId,
personalAccessKey,

@@ -67,9 +67,9 @@ env = ENVIRONMENTS.PROD

env,
portalId
accountId
);
const config = getPortalConfig(portalId);
const config = getAccountConfig(accountId);
updatePortalConfig({
updateAccountConfig({
...config,
portalId,
accountId,
tokenInfo: {

@@ -85,3 +85,3 @@ accessToken,

async function getNewAccessToken(portalId, personalAccessKey, expiresAt, env) {
async function getNewAccessToken(accountId, personalAccessKey, expiresAt, env) {
const key = getRefreshKey(personalAccessKey, expiresAt);

@@ -94,3 +94,3 @@ if (refreshRequests.has(key)) {

const refreshAccessPromise = refreshAccessToken(
portalId,
accountId,
personalAccessKey,

@@ -112,4 +112,4 @@ env

async function accessTokenForPersonalAccessKey(portalId) {
const { auth, personalAccessKey, env } = getPortalConfig(portalId);
async function accessTokenForPersonalAccessKey(accountId) {
const { auth, personalAccessKey, env } = getAccountConfig(accountId);
const authTokenInfo = auth && auth.tokenInfo;

@@ -125,3 +125,3 @@ const authDataExists = authTokenInfo && auth.tokenInfo.accessToken;

return getNewAccessToken(
portalId,
accountId,
personalAccessKey,

@@ -137,3 +137,3 @@ authTokenInfo && authTokenInfo.expiresAt,

/**
* Adds a portal to the config using authType: personalAccessKey
* Adds a account to the config using authType: personalAccessKey
*

@@ -143,11 +143,11 @@ * @param {object} configData Data containing personalAccessKey and name properties

* @param {string} configData.name Unique name to identify this config entry
* @param {boolean} makeDefault option to make the portal being added to the config the default portal
* @param {boolean} makeDefault option to make the account being added to the config the default account
*/
const updateConfigWithPersonalAccessKey = async (configData, makeDefault) => {
const { personalAccessKey, name, env } = configData;
const portalEnv = env || getEnv(name);
const accountEnv = env || getEnv(name);
let token;
try {
token = await getAccessToken(personalAccessKey, portalEnv);
token = await getAccessToken(personalAccessKey, accountEnv);
} catch (err) {

@@ -157,9 +157,9 @@ logErrorInstance(err);

}
const { portalId, accessToken, expiresAt } = token;
const { accountId, accessToken, expiresAt } = token;
const updatedConfig = updatePortalConfig({
portalId,
const updatedConfig = updateAccountConfig({
accountId,
personalAccessKey,
name,
environment: getValidEnv(portalEnv, true),
environment: getValidEnv(accountEnv, true),
authType: PERSONAL_ACCESS_KEY_AUTH_METHOD.value,

@@ -171,3 +171,3 @@ tokenInfo: { accessToken, expiresAt },

if (makeDefault) {
updateDefaultPortal(name);
updateDefaultAccount(name);
}

@@ -174,0 +174,0 @@

@@ -64,9 +64,9 @@ const fs = require('fs-extra');

const listSchemas = async portalId => {
const response = await fetchSchemas(portalId);
const listSchemas = async accountId => {
const response = await fetchSchemas(accountId);
logSchemas(response.results);
};
const downloadSchemas = async (portalId, dest) => {
const response = await fetchSchemas(portalId);
const downloadSchemas = async (accountId, dest) => {
const response = await fetchSchemas(accountId);
logSchemas(response.results);

@@ -81,4 +81,4 @@

const downloadSchema = async (portalId, schemaObjectType, dest) => {
const response = await fetchSchema(portalId, schemaObjectType);
const downloadSchema = async (accountId, schemaObjectType, dest) => {
const response = await fetchSchema(accountId, schemaObjectType);
writeSchemaToDisk(response, dest);

@@ -85,0 +85,0 @@ };

@@ -10,3 +10,3 @@ const fs = require('fs-extra');

* @async
* @param {number} portalId
* @param {number} accountId
* @param {string} filepath

@@ -17,3 +17,3 @@ * @param {function} callback - Optional

*/
async function lint(portalId, filepath, callback) {
async function lint(accountId, filepath, callback) {
const stats = await fs.stat(filepath);

@@ -36,3 +36,3 @@ const files = stats.isDirectory() ? await walk(filepath) : [filepath];

}
const validation = await validateHubl(portalId, source);
const validation = await validateHubl(accountId, source);
const result = {

@@ -39,0 +39,0 @@ file,

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc