@hubspot/cms-lib
Advanced tools
Comparing version 2.2.1-beta.3 to 2.2.1-beta.4
@@ -28,3 +28,3 @@ const { uploadFolder } = require('../fileManager'); | ||
await uploadFolder(accountId, src, dest, { cwd: '/home/tom' }); | ||
await uploadFolder(accountId, src, dest); | ||
@@ -31,0 +31,0 @@ expect(uploadFile).toReturnTimes(4); |
@@ -11,41 +11,39 @@ const { shouldIgnoreFile } = require('../ignoreRules'); | ||
it('ignores node_modules folder', () => { | ||
expect(shouldIgnoreFile(NODE_MODULES_FOLDER, CWD)).toBe(true); | ||
expect(shouldIgnoreFile(NODE_MODULES_FOLDER)).toBe(true); | ||
}); | ||
it('ignores files nested within node_modules folder', () => { | ||
expect(shouldIgnoreFile(NODE_MODULES_FILE, CWD)).toBe(true); | ||
expect(shouldIgnoreFile(NODE_MODULES_FILE)).toBe(true); | ||
}); | ||
it('ignores CLI config files', () => { | ||
expect(shouldIgnoreFile(`${CWD}/hubspot.config.yml`, CWD)).toBe(true); | ||
expect(shouldIgnoreFile(`${CWD}/hubspot.config.yaml`, CWD)).toBe(true); | ||
expect(shouldIgnoreFile(`${CWD}/some/dir/hubspot.config.yml`, CWD)).toBe( | ||
expect(shouldIgnoreFile(`${CWD}/hubspot.config.yml`)).toBe(true); | ||
expect(shouldIgnoreFile(`${CWD}/hubspot.config.yaml`)).toBe(true); | ||
expect(shouldIgnoreFile(`${CWD}/some/dir/hubspot.config.yml`)).toBe(true); | ||
expect(shouldIgnoreFile(`${CWD}/some/dir/hubspot.config.yaml`)).toBe( | ||
true | ||
); | ||
expect(shouldIgnoreFile(`${CWD}/some/dir/hubspot.config.yaml`, CWD)).toBe( | ||
true | ||
); | ||
}); | ||
it('ignores hidden folders', () => { | ||
expect(shouldIgnoreFile(`${REPO_FOLDER}/.hiddenFolder`, CWD)).toBe(true); | ||
expect(shouldIgnoreFile(`${REPO_FOLDER}/.hiddenFolder`)).toBe(true); | ||
}); | ||
it('ignores hidden files', () => { | ||
expect(shouldIgnoreFile(`${REPO_FOLDER}/.hiddenFile.js`, CWD)).toBe(true); | ||
expect(shouldIgnoreFile(`${REPO_FOLDER}/.*`, CWD)).toBe(true); | ||
expect(shouldIgnoreFile(`${REPO_FOLDER}/.hiddenFile.js`)).toBe(true); | ||
expect(shouldIgnoreFile(`${REPO_FOLDER}/.*`)).toBe(true); | ||
}); | ||
it('does not ignore allowed folders', () => { | ||
expect(shouldIgnoreFile(`${REPO_FOLDER}/hiddenFile/`, CWD)).toBe(false); | ||
expect(shouldIgnoreFile(`${REPO_FOLDER}/hiddenFile/`)).toBe(false); | ||
}); | ||
it('does not ignore allowed files', () => { | ||
expect(shouldIgnoreFile(`${REPO_FOLDER}/hiddenFile.js`, CWD)).toBe(false); | ||
expect(shouldIgnoreFile(`${REPO_FOLDER}/hiddenFile.js`)).toBe(false); | ||
}); | ||
it('does not ignore the current folder', () => { | ||
expect(shouldIgnoreFile('.', process.cwd())).toBe(false); | ||
expect(shouldIgnoreFile('.')).toBe(false); | ||
}); | ||
}); | ||
}); |
@@ -5,3 +5,4 @@ const fs = require('fs'); | ||
const FILE_MANAGER_API_PATH = 'filemanager/api/v2'; | ||
const FILE_MANAGER_V2_API_PATH = 'filemanager/api/v2'; | ||
const FILE_MANAGER_V3_API_PATH = 'filemanager/api/v3'; | ||
@@ -13,14 +14,15 @@ async function uploadFile(accountId, src, dest) { | ||
file: fs.createReadStream(src), | ||
file_names: filename, | ||
fileName: filename, | ||
options: JSON.stringify({ | ||
access: 'PUBLIC_INDEXABLE', | ||
overwrite: true, | ||
}), | ||
}; | ||
if (directory && directory !== '.' && directory !== '/') { | ||
formData.folder_paths = directory; | ||
formData.folderPath = directory; | ||
} | ||
return http.post(accountId, { | ||
uri: `${FILE_MANAGER_API_PATH}/files`, | ||
qs: { | ||
overwrite: 'true', | ||
}, | ||
uri: `${FILE_MANAGER_V3_API_PATH}/files/upload`, | ||
formData, | ||
@@ -32,3 +34,3 @@ }); | ||
return http.get(accountId, { | ||
uri: `${FILE_MANAGER_API_PATH}/files/stat/${src}`, | ||
uri: `${FILE_MANAGER_V2_API_PATH}/files/stat/${src}`, | ||
}); | ||
@@ -39,7 +41,7 @@ } | ||
return http.get(accountId, { | ||
uri: `${FILE_MANAGER_API_PATH}/files/`, | ||
uri: `${FILE_MANAGER_V2_API_PATH}/files/`, | ||
qs: { | ||
hidden: 0, | ||
offset: offset, | ||
folder_id: folderId || 'None', | ||
folder_id: folderId, | ||
...(!archived && { archived: 0 }), | ||
@@ -52,6 +54,6 @@ }, | ||
return http.get(accountId, { | ||
uri: `${FILE_MANAGER_API_PATH}/folders/`, | ||
uri: `${FILE_MANAGER_V2_API_PATH}/folders/`, | ||
qs: { | ||
hidden: 0, | ||
parent_folder_id: folderId || 'None', | ||
parent_folder_id: folderId, | ||
}, | ||
@@ -58,0 +60,0 @@ }); |
@@ -37,7 +37,7 @@ const fs = require('fs-extra'); | ||
*/ | ||
async function uploadFolder(accountId, src, dest, { cwd }) { | ||
async function uploadFolder(accountId, src, dest) { | ||
const regex = new RegExp(`^${escapeRegExp(src)}`); | ||
const files = await walk(src); | ||
const filesToUpload = files.filter(createIgnoreFilter(cwd)); | ||
const filesToUpload = files.filter(createIgnoreFilter()); | ||
@@ -107,3 +107,2 @@ const len = filesToUpload.length; | ||
} | ||
try { | ||
@@ -118,3 +117,2 @@ await http.getOctetStream( | ||
); | ||
logger.log(`Wrote file "${destPath}"`); | ||
} catch (err) { | ||
@@ -190,3 +188,3 @@ logErrorInstance(err); | ||
* @param {string} dest | ||
* @param {object} file | ||
* @param {object} folder | ||
* @param {object} options | ||
@@ -196,13 +194,19 @@ */ | ||
try { | ||
const rootPath = | ||
dest === getCwd() | ||
? convertToLocalFileSystemPath(path.resolve(dest, folder.name)) | ||
: dest; | ||
let absolutePath; | ||
if (folder.name) { | ||
absolutePath = convertToLocalFileSystemPath( | ||
path.resolve(getCwd(), dest, folder.name) | ||
); | ||
} else { | ||
absolutePath = convertToLocalFileSystemPath(path.resolve(getCwd(), dest)); | ||
} | ||
logger.log( | ||
'Fetching folder from "%s" to "%s" in the File Manager of account %s', | ||
src, | ||
rootPath, | ||
absolutePath, | ||
accountId | ||
); | ||
await fetchFolderContents(accountId, folder, rootPath, options); | ||
await fetchFolderContents(accountId, folder, absolutePath, options); | ||
logger.success( | ||
@@ -267,22 +271,23 @@ 'Completed fetch of folder "%s" to "%s" from the File Manager', | ||
async function downloadFileOrFolder(accountId, src, dest, options) { | ||
if (src === '/') { | ||
await downloadFolder(accountId, src, dest, '', options); | ||
} else { | ||
try { | ||
try { | ||
if (src == '/') { | ||
// Filemanager API treats 'None' as the root | ||
const rootFolder = { id: 'None' }; | ||
await downloadFolder(accountId, src, dest, rootFolder, options); | ||
} else { | ||
const { file, folder } = await fetchStat(accountId, src); | ||
if (file) { | ||
downloadSingleFile(accountId, src, dest, file, options); | ||
await downloadSingleFile(accountId, src, dest, file, options); | ||
} else if (folder) { | ||
downloadFolder(accountId, src, dest, folder, options); | ||
await downloadFolder(accountId, src, dest, folder, options); | ||
} | ||
} catch (err) { | ||
logApiErrorInstance( | ||
err, | ||
new ApiErrorContext({ | ||
request: src, | ||
accountId, | ||
}) | ||
); | ||
} | ||
} catch (err) { | ||
logApiErrorInstance( | ||
err, | ||
new ApiErrorContext({ | ||
request: src, | ||
accountId, | ||
}) | ||
); | ||
} | ||
@@ -289,0 +294,0 @@ } |
@@ -153,2 +153,7 @@ const request = require('request'); | ||
if (res.statusCode >= 200 && res.statusCode < 300) { | ||
try { | ||
fs.ensureFileSync(filepath); | ||
} catch (err) { | ||
reject(err); | ||
} | ||
const writeStream = fs.createWriteStream(filepath, { | ||
@@ -155,0 +160,0 @@ encoding: 'binary', |
@@ -30,3 +30,3 @@ const fs = require('fs'); | ||
let configPath = null; | ||
let searchDomain = null; | ||
let loaded = false; | ||
@@ -41,3 +41,3 @@ function loadIgnoreConfig() { | ||
ignoreRules.add(fs.readFileSync(file).toString()); | ||
configPath = path.dirname(file); | ||
searchDomain = path.dirname(file); | ||
} | ||
@@ -48,12 +48,13 @@ } | ||
function shouldIgnoreFile(file, cwd) { | ||
function shouldIgnoreFile(file) { | ||
loadIgnoreConfig(); | ||
const relativeTo = configPath || cwd; | ||
const relativeTo = searchDomain || '/'; | ||
const relativePath = path.relative(relativeTo, file); | ||
return !!relativePath && ignoreRules.ignores(relativePath); | ||
} | ||
function createIgnoreFilter(cwd) { | ||
function createIgnoreFilter() { | ||
loadIgnoreConfig(); | ||
return file => !shouldIgnoreFile(file, cwd); | ||
return file => !shouldIgnoreFile(file); | ||
} | ||
@@ -60,0 +61,0 @@ |
const { | ||
setConfig, | ||
getAndLoadConfigIfNeeded, | ||
getOrderedAccount, | ||
getConfig, | ||
getConfigAccounts, | ||
getConfigDefaultAccount, | ||
getConfigAccountId, | ||
getAccountConfig, | ||
getAccountId, | ||
getOrderedConfig, | ||
updateDefaultAccount, | ||
@@ -25,4 +20,4 @@ updateAccountConfig, | ||
const API_KEY_CONFIG = { | ||
portalId: 1111, | ||
name: 'API', | ||
accountId: 1111, | ||
authType: 'apikey', | ||
@@ -32,12 +27,5 @@ 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', | ||
accountId: 2222, | ||
portalId: 2222, | ||
authType: 'oauth2', | ||
@@ -56,12 +44,5 @@ 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', | ||
accountId: 3333, | ||
portalId: 3333, | ||
authType: 'personalaccesskey', | ||
@@ -78,13 +59,6 @@ auth: { | ||
const LEGACY_PERSONAL_ACCESS_KEY_CONFIG = (() => { | ||
const legacyObj = { ...PERSONAL_ACCESS_KEY_CONFIG }; | ||
legacyObj.portalId = legacyObj.accountId + 1; | ||
delete legacyObj.accountId; | ||
return legacyObj; | ||
})(); | ||
const PORTALS = [API_KEY_CONFIG, OAUTH2_CONFIG, PERSONAL_ACCESS_KEY_CONFIG]; | ||
const ACCOUNTS = [API_KEY_CONFIG, OAUTH2_CONFIG, PERSONAL_ACCESS_KEY_CONFIG]; | ||
const getAccountByAuthType = (config, authType) => { | ||
return config.accounts.filter(account => account.authType === authType)[0]; | ||
return config.portals.filter(portal => portal.authType === authType)[0]; | ||
}; | ||
@@ -95,4 +69,4 @@ | ||
const CONFIG = { | ||
defaultAccount: ACCOUNTS[0].name, | ||
accounts: ACCOUNTS, | ||
defaultPortal: PORTALS[0].name, | ||
portals: PORTALS, | ||
}; | ||
@@ -112,21 +86,21 @@ beforeEach(() => { | ||
setConfig({ | ||
defaultAccount: PERSONAL_ACCESS_KEY_CONFIG.name, | ||
accounts: ACCOUNTS, | ||
defaultPortal: PERSONAL_ACCESS_KEY_CONFIG.name, | ||
portals: PORTALS, | ||
}); | ||
}); | ||
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 name is passed', () => { | ||
expect(getAccountId(OAUTH2_CONFIG.name)).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 string id is passed', () => { | ||
expect(getAccountId(OAUTH2_CONFIG.portalId.toString())).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 portalId from config when a numeric id is passed', () => { | ||
expect(getAccountId(OAUTH2_CONFIG.portalId)).toEqual( | ||
OAUTH2_CONFIG.portalId | ||
); | ||
}); | ||
it('returns defaultAccount from config', () => { | ||
expect(getAccountId()).toEqual(PERSONAL_ACCESS_KEY_CONFIG.accountId); | ||
it('returns defaultPortal from config', () => { | ||
expect(getAccountId()).toEqual(PERSONAL_ACCESS_KEY_CONFIG.portalId); | ||
}); | ||
@@ -136,10 +110,10 @@ }); | ||
describe('updateDefaultAccount method', () => { | ||
const myAccountName = 'Foo'; | ||
const myPortalName = 'Foo'; | ||
beforeEach(() => { | ||
updateDefaultAccount(myAccountName); | ||
updateDefaultAccount(myPortalName); | ||
}); | ||
it('sets the defaultAccount in the config', () => { | ||
expect(getConfig().defaultAccount).toEqual(myAccountName); | ||
it('sets the defaultPortal in the config', () => { | ||
expect(getConfig().defaultPortal).toEqual(myPortalName); | ||
}); | ||
@@ -152,3 +126,3 @@ }); | ||
it('does not delete config file if there are contents', () => { | ||
fs.__setReadFile('defaultAccount: Foo'); | ||
fs.__setReadFile('defaultPortal: Foo'); | ||
fs.__setExistsValue(true); | ||
@@ -173,4 +147,4 @@ fs.unlinkSync = jest.fn(); | ||
const CONFIG = { | ||
defaultAccount: ACCOUNTS[0].name, | ||
accounts: ACCOUNTS, | ||
defaultPortal: PORTALS[0].name, | ||
portals: PORTALS, | ||
}; | ||
@@ -211,4 +185,4 @@ | ||
setConfig({ | ||
defaultAccount: PERSONAL_ACCESS_KEY_CONFIG.name, | ||
accounts: [{ ...PERSONAL_ACCESS_KEY_CONFIG, env }], | ||
defaultPortal: PERSONAL_ACCESS_KEY_CONFIG.name, | ||
portals: [{ ...PERSONAL_ACCESS_KEY_CONFIG, env }], | ||
}); | ||
@@ -233,4 +207,4 @@ const modifiedPersonalAccessKeyConfig = { | ||
setConfig({ | ||
defaultAccount: PERSONAL_ACCESS_KEY_CONFIG.name, | ||
accounts: [{ ...PERSONAL_ACCESS_KEY_CONFIG, env: previousEnv }], | ||
defaultPortal: PERSONAL_ACCESS_KEY_CONFIG.name, | ||
portals: [{ ...PERSONAL_ACCESS_KEY_CONFIG, env: previousEnv }], | ||
}); | ||
@@ -280,4 +254,4 @@ const modifiedPersonalAccessKeyConfig = { | ||
setConfig({ | ||
defaultAccount: PERSONAL_ACCESS_KEY_CONFIG.name, | ||
accounts: [{ ...PERSONAL_ACCESS_KEY_CONFIG, name }], | ||
defaultPortal: PERSONAL_ACCESS_KEY_CONFIG.name, | ||
portals: [{ ...PERSONAL_ACCESS_KEY_CONFIG, name }], | ||
}); | ||
@@ -302,4 +276,4 @@ const modifiedPersonalAccessKeyConfig = { | ||
setConfig({ | ||
defaultAccount: PERSONAL_ACCESS_KEY_CONFIG.name, | ||
accounts: [{ ...PERSONAL_ACCESS_KEY_CONFIG, env: previousName }], | ||
defaultPortal: PERSONAL_ACCESS_KEY_CONFIG.name, | ||
portals: [{ ...PERSONAL_ACCESS_KEY_CONFIG, env: previousName }], | ||
}); | ||
@@ -322,8 +296,8 @@ const modifiedPersonalAccessKeyConfig = { | ||
describe('validateConfig method', () => { | ||
const DEFAULT_PORTAL = ACCOUNTS[0].name; | ||
const DEFAULT_PORTAL = PORTALS[0].name; | ||
it('allows valid config', () => { | ||
setConfig({ | ||
defaultAccount: DEFAULT_PORTAL, | ||
accounts: ACCOUNTS, | ||
defaultPortal: DEFAULT_PORTAL, | ||
portals: PORTALS, | ||
}); | ||
@@ -333,6 +307,6 @@ expect(validateConfig()).toEqual(true); | ||
it('does not allow duplicate accountIds', () => { | ||
it('does not allow duplicate portalIds', () => { | ||
setConfig({ | ||
defaultAccount: DEFAULT_PORTAL, | ||
accounts: [...ACCOUNTS, ACCOUNTS[0]], | ||
defaultPortal: DEFAULT_PORTAL, | ||
portals: [...PORTALS, PORTALS[0]], | ||
}); | ||
@@ -344,8 +318,8 @@ expect(validateConfig()).toEqual(false); | ||
setConfig({ | ||
defaultAccount: DEFAULT_PORTAL, | ||
accounts: [ | ||
...ACCOUNTS, | ||
defaultPortal: DEFAULT_PORTAL, | ||
portals: [ | ||
...PORTALS, | ||
{ | ||
...ACCOUNTS[0], | ||
accountId: 123456789, | ||
...PORTALS[0], | ||
portalId: 123456789, | ||
}, | ||
@@ -359,6 +333,6 @@ ], | ||
setConfig({ | ||
defaultAccount: DEFAULT_PORTAL, | ||
accounts: [ | ||
defaultPortal: DEFAULT_PORTAL, | ||
portals: [ | ||
{ | ||
...ACCOUNTS[0], | ||
...PORTALS[0], | ||
name: 'A NAME WITH SPACES', | ||
@@ -371,12 +345,12 @@ }, | ||
it('allows multiple accounts with no name', () => { | ||
it('allows multiple portals with no name', () => { | ||
setConfig({ | ||
defaultAccount: DEFAULT_PORTAL, | ||
accounts: [ | ||
defaultPortal: DEFAULT_PORTAL, | ||
portals: [ | ||
{ | ||
...ACCOUNTS[0], | ||
...PORTALS[0], | ||
name: null, | ||
}, | ||
{ | ||
...ACCOUNTS[1], | ||
...PORTALS[1], | ||
name: null, | ||
@@ -408,3 +382,3 @@ }, | ||
const { | ||
accountId, | ||
portalId, | ||
auth: { | ||
@@ -416,7 +390,7 @@ clientId, | ||
} = OAUTH2_CONFIG; | ||
let accountConfig; | ||
let portalConfig; | ||
beforeEach(() => { | ||
process.env = { | ||
HUBSPOT_PORTAL_ID: accountId, | ||
HUBSPOT_PORTAL_ID: portalId, | ||
HUBSPOT_CLIENT_ID: clientId, | ||
@@ -427,3 +401,3 @@ HUBSPOT_CLIENT_SECRET: clientSecret, | ||
getAndLoadConfigIfNeeded({ useEnv: true }); | ||
accountConfig = getAccountConfig(accountId); | ||
portalConfig = getAccountConfig(portalId); | ||
}); | ||
@@ -435,20 +409,20 @@ | ||
it('creates a account config', () => { | ||
expect(accountConfig).toBeTruthy(); | ||
it('creates a portal config', () => { | ||
expect(portalConfig).toBeTruthy(); | ||
}); | ||
it('properly loads account id value', () => { | ||
expect(accountConfig.accountId).toEqual(accountId); | ||
it('properly loads portal id value', () => { | ||
expect(portalConfig.portalId).toEqual(portalId); | ||
}); | ||
it('properly loads client id value', () => { | ||
expect(accountConfig.auth.clientId).toEqual(clientId); | ||
expect(portalConfig.auth.clientId).toEqual(clientId); | ||
}); | ||
it('properly loads client secret value', () => { | ||
expect(accountConfig.auth.clientSecret).toEqual(clientSecret); | ||
expect(portalConfig.auth.clientSecret).toEqual(clientSecret); | ||
}); | ||
it('properly loads refresh token value', () => { | ||
expect(accountConfig.auth.tokenInfo.refreshToken).toEqual(refreshToken); | ||
expect(portalConfig.auth.tokenInfo.refreshToken).toEqual(refreshToken); | ||
}); | ||
@@ -458,12 +432,12 @@ }); | ||
describe('apikey environment variable config', () => { | ||
const { accountId, apiKey } = API_KEY_CONFIG; | ||
let accountConfig; | ||
const { portalId, apiKey } = API_KEY_CONFIG; | ||
let portalConfig; | ||
beforeEach(() => { | ||
process.env = { | ||
HUBSPOT_PORTAL_ID: accountId, | ||
HUBSPOT_PORTAL_ID: portalId, | ||
HUBSPOT_API_KEY: apiKey, | ||
}; | ||
getAndLoadConfigIfNeeded({ useEnv: true }); | ||
accountConfig = getAccountConfig(accountId); | ||
portalConfig = getAccountConfig(portalId); | ||
}); | ||
@@ -475,12 +449,12 @@ | ||
it('creates a account config', () => { | ||
expect(accountConfig).toBeTruthy(); | ||
it('creates a portal config', () => { | ||
expect(portalConfig).toBeTruthy(); | ||
}); | ||
it('properly loads account id value', () => { | ||
expect(accountConfig.accountId).toEqual(accountId); | ||
it('properly loads portal id value', () => { | ||
expect(portalConfig.portalId).toEqual(portalId); | ||
}); | ||
it('properly loads api key value', () => { | ||
expect(accountConfig.apiKey).toEqual(apiKey); | ||
expect(portalConfig.apiKey).toEqual(apiKey); | ||
}); | ||
@@ -490,12 +464,12 @@ }); | ||
describe('personalaccesskey environment variable config', () => { | ||
const { accountId, personalAccessKey } = PERSONAL_ACCESS_KEY_CONFIG; | ||
let accountConfig; | ||
const { portalId, personalAccessKey } = PERSONAL_ACCESS_KEY_CONFIG; | ||
let portalConfig; | ||
beforeEach(() => { | ||
process.env = { | ||
HUBSPOT_PORTAL_ID: accountId, | ||
HUBSPOT_PORTAL_ID: portalId, | ||
HUBSPOT_PERSONAL_ACCESS_KEY: personalAccessKey, | ||
}; | ||
getAndLoadConfigIfNeeded({ useEnv: true }); | ||
accountConfig = getAccountConfig(accountId); | ||
portalConfig = getAccountConfig(portalId); | ||
}); | ||
@@ -507,12 +481,12 @@ | ||
it('creates a account config', () => { | ||
expect(accountConfig).toBeTruthy(); | ||
it('creates a portal config', () => { | ||
expect(portalConfig).toBeTruthy(); | ||
}); | ||
it('properly loads account id value', () => { | ||
expect(accountConfig.accountId).toEqual(accountId); | ||
it('properly loads portal id value', () => { | ||
expect(portalConfig.portalId).toEqual(portalId); | ||
}); | ||
it('properly loads personal access key value', () => { | ||
expect(accountConfig.personalAccessKey).toEqual(personalAccessKey); | ||
expect(portalConfig.personalAccessKey).toEqual(personalAccessKey); | ||
}); | ||
@@ -607,378 +581,2 @@ }); | ||
}); | ||
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 | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -33,3 +33,2 @@ const { uploadFolder } = require('../uploadFolder'); | ||
const dest = 'folder'; | ||
const cwd = '/home/tom'; | ||
const uploadedFilesInOrder = [ | ||
@@ -48,3 +47,3 @@ 'folder/images/image.png', | ||
await uploadFolder(accountId, src, dest, { mode: 'publish', cwd }); | ||
await uploadFolder(accountId, src, dest, { mode: 'publish' }); | ||
@@ -51,0 +50,0 @@ expect(upload).toReturnTimes(10); |
@@ -40,3 +40,3 @@ const fs = require('fs-extra'); | ||
if (!__config) return; | ||
return __config.accounts || __config.portals; | ||
return __config.portals; | ||
}; | ||
@@ -47,3 +47,3 @@ | ||
if (!__config) return; | ||
return __config.defaultAccount || __config.defaultPortal; | ||
return __config.defaultPortal; | ||
}; | ||
@@ -54,3 +54,3 @@ | ||
if (!__config) return; | ||
return __config.accountId || __config.portalId; | ||
return __config.portalId; | ||
}; | ||
@@ -69,3 +69,3 @@ | ||
if (!Array.isArray(accounts)) { | ||
logger.error('config.accounts[] is not defined'); | ||
logger.error('config.portals[] is not defined'); | ||
return false; | ||
@@ -77,3 +77,3 @@ } | ||
if (!cfg) { | ||
logger.error('config.accounts[] has an empty entry'); | ||
logger.error('config.portals[] has an empty entry'); | ||
return false; | ||
@@ -84,3 +84,3 @@ } | ||
if (!accountId) { | ||
logger.error('config.accounts[] has an entry missing accountId'); | ||
logger.error('config.portals[] has an entry missing portalId'); | ||
return false; | ||
@@ -90,3 +90,3 @@ } | ||
logger.error( | ||
`config.accounts[] has multiple entries with accountId=${accountId}` | ||
`config.portals[] has multiple entries with portalId=${accountId}` | ||
); | ||
@@ -99,3 +99,3 @@ return false; | ||
logger.error( | ||
`config.name has multiple entries with accountId=${accountId}` | ||
`config.name has multiple entries with portalId=${accountId}` | ||
); | ||
@@ -128,14 +128,6 @@ return false; | ||
const getOrderedAccount = unorderedAccount => { | ||
const { | ||
name, | ||
accountId, | ||
portalId, | ||
env, | ||
authType, | ||
...rest | ||
} = unorderedAccount; | ||
const { name, portalId, env, authType, ...rest } = unorderedAccount; | ||
return { | ||
name, | ||
...(accountId && { accountId }), | ||
...(portalId && { portalId }), | ||
@@ -150,3 +142,2 @@ env, | ||
const { | ||
defaultAccount, | ||
defaultPortal, | ||
@@ -156,3 +147,2 @@ defaultMode, | ||
allowsUsageTracking, | ||
accounts, | ||
portals, | ||
@@ -163,3 +153,2 @@ ...rest | ||
return { | ||
...(defaultAccount && { defaultAccount }), | ||
...(defaultPortal && { defaultPortal }), | ||
@@ -169,3 +158,3 @@ defaultMode, | ||
allowsUsageTracking, | ||
accounts: (accounts || portals).map(getOrderedAccount), | ||
portals: portals.map(getOrderedAccount), | ||
...rest, | ||
@@ -360,3 +349,3 @@ }; | ||
_config = { | ||
accounts: [], | ||
portals: [], | ||
}; | ||
@@ -436,7 +425,7 @@ } | ||
getConfigAccounts(getAndLoadConfigIfNeeded()).find( | ||
account => account.accountId === accountId || account.portalId === accountId | ||
account => account.portalId === accountId | ||
); | ||
/* | ||
* Returns a accountId from the config if it exists, else returns null | ||
* Returns a portalId from the config if it exists, else returns null | ||
*/ | ||
@@ -469,7 +458,7 @@ const getAccountId = nameOrId => { | ||
} else if (accountId) { | ||
account = accounts.find(p => [p.accountId, p.portalId].includes(accountId)); | ||
account = accounts.find(p => accountId === p.portalId); | ||
} | ||
if (account) { | ||
return account.accountId || account.portalId; | ||
return account.portalId; | ||
} | ||
@@ -485,3 +474,2 @@ | ||
const { | ||
accountId: _accountId, | ||
portalId, | ||
@@ -499,10 +487,9 @@ authType, | ||
} = configOptions; | ||
const accountId = _accountId || portalId; | ||
if (!accountId) { | ||
throw new Error('An accountId is required to update the config'); | ||
if (!portalId) { | ||
throw new Error('An portalId is required to update the config'); | ||
} | ||
const config = getAndLoadConfigIfNeeded(); | ||
const accountConfig = getAccountConfig(accountId); | ||
const accountConfig = getAccountConfig(portalId); | ||
@@ -528,3 +515,2 @@ let auth; | ||
env, | ||
...(_accountId && { accountId: _accountId }), | ||
...(portalId && { portalId }), | ||
@@ -540,7 +526,7 @@ authType, | ||
if (accountConfig) { | ||
logger.debug(`Updating config for ${accountId}`); | ||
logger.debug(`Updating config for ${portalId}`); | ||
const index = accounts.indexOf(accountConfig); | ||
accounts[index] = nextAccountConfig; | ||
} else { | ||
logger.debug(`Adding config entry for ${accountId}`); | ||
logger.debug(`Adding config entry for ${portalId}`); | ||
if (accounts) { | ||
@@ -552,2 +538,3 @@ accounts.push(nextAccountConfig); | ||
} | ||
return nextAccountConfig; | ||
@@ -565,3 +552,3 @@ }; | ||
throw new Error( | ||
'A defaultAccount with value of number or string is required to update the config' | ||
`A 'defaultPortal' with value of number or string is required to update the config` | ||
); | ||
@@ -571,9 +558,3 @@ } | ||
const config = getAndLoadConfigIfNeeded(); | ||
if (config.defaultAccount) { | ||
config.defaultAccount = defaultAccount; | ||
} | ||
// Keep for backcompat | ||
if (config.defaultPortal) { | ||
config.defaultPortal = defaultAccount; | ||
} | ||
config.defaultPortal = defaultAccount; | ||
@@ -626,9 +607,3 @@ setDefaultConfigPathIfUnset(); | ||
personalAccessKey: env[ENVIRONMENT_VARIABLES.HUBSPOT_PERSONAL_ACCESS_KEY], | ||
accountId: parseInt( | ||
env[ | ||
ENVIRONMENT_VARIABLES.HUBSPOT_PORTAL_ID || | ||
ENVIRONMENT_VARIABLES.HUBSPOT_ACCOUNT_ID | ||
], | ||
10 | ||
), | ||
portalId: parseInt(env[ENVIRONMENT_VARIABLES.HUBSPOT_PORTAL_ID], 10), | ||
refreshToken: env[ENVIRONMENT_VARIABLES.HUBSPOT_REFRESH_TOKEN], | ||
@@ -639,8 +614,8 @@ env: getValidEnv(env[ENVIRONMENT_VARIABLES.HUBSPOT_ENVIRONMENT]), | ||
const generatePersonalAccessKeyConfig = (accountId, personalAccessKey, env) => { | ||
const generatePersonalAccessKeyConfig = (portalId, personalAccessKey, env) => { | ||
return { | ||
accounts: [ | ||
portals: [ | ||
{ | ||
authType: PERSONAL_ACCESS_KEY_AUTH_METHOD.value, | ||
accountId, | ||
portalId, | ||
personalAccessKey, | ||
@@ -654,3 +629,3 @@ env, | ||
const generateOauthConfig = ( | ||
accountId, | ||
portalId, | ||
clientId, | ||
@@ -663,6 +638,6 @@ clientSecret, | ||
return { | ||
accounts: [ | ||
portals: [ | ||
{ | ||
authType: OAUTH_AUTH_METHOD.value, | ||
accountId, | ||
portalId, | ||
auth: { | ||
@@ -682,8 +657,8 @@ clientId, | ||
const generateApiKeyConfig = (accountId, apiKey, env) => { | ||
const generateApiKeyConfig = (portalId, apiKey, env) => { | ||
return { | ||
accounts: [ | ||
portals: [ | ||
{ | ||
authType: API_KEY_AUTH_METHOD.value, | ||
accountId, | ||
portalId, | ||
apiKey, | ||
@@ -702,3 +677,3 @@ env, | ||
personalAccessKey, | ||
accountId, | ||
portalId, | ||
refreshToken, | ||
@@ -708,3 +683,3 @@ env, | ||
if (!accountId) { | ||
if (!portalId) { | ||
return; | ||
@@ -714,6 +689,6 @@ } | ||
if (personalAccessKey) { | ||
return generatePersonalAccessKeyConfig(accountId, personalAccessKey, env); | ||
return generatePersonalAccessKeyConfig(portalId, personalAccessKey, env); | ||
} else if (clientId && clientSecret && refreshToken) { | ||
return generateOauthConfig( | ||
accountId, | ||
portalId, | ||
clientId, | ||
@@ -726,3 +701,3 @@ clientSecret, | ||
} else if (apiKey) { | ||
return generateApiKeyConfig(accountId, apiKey, env); | ||
return generateApiKeyConfig(portalId, apiKey, env); | ||
} else { | ||
@@ -739,6 +714,6 @@ return; | ||
} | ||
const { accountId } = getConfigVariablesFromEnv(); | ||
const { portalId } = getConfigVariablesFromEnv(); | ||
logger.debug( | ||
`Loaded config from environment variables for account ${accountId}` | ||
`Loaded config from environment variables for account ${portalId}` | ||
); | ||
@@ -745,0 +720,0 @@ |
@@ -87,3 +87,2 @@ const ENVIRONMENTS = { | ||
HUBSPOT_PORTAL_ID: 'HUBSPOT_PORTAL_ID', | ||
HUBSPOT_ACCOUNT_ID: 'HUBSPOT_ACCOUNT_ID', | ||
HUBSPOT_REFRESH_TOKEN: 'HUBSPOT_REFRESH_TOKEN', | ||
@@ -90,0 +89,0 @@ HUBSPOT_ENVIRONMENT: 'HUBSPOT_ENVIRONMENT', |
@@ -57,3 +57,3 @@ const path = require('path'); | ||
*/ | ||
async function uploadFolder(accountId, src, dest, { mode, cwd }) { | ||
async function uploadFolder(accountId, src, dest, { mode }) { | ||
const regex = new RegExp(`^${escapeRegExp(src)}`); | ||
@@ -72,3 +72,3 @@ const apiOptions = { | ||
}) | ||
.filter(createIgnoreFilter(cwd)); | ||
.filter(createIgnoreFilter()); | ||
@@ -75,0 +75,0 @@ const filesByType = getFilesByType(allowedFiles); |
@@ -24,3 +24,3 @@ const path = require('path'); | ||
function uploadFile(accountId, file, dest, { mode, cwd }) { | ||
function uploadFile(accountId, file, dest, { mode }) { | ||
if (!isAllowedExtension(file)) { | ||
@@ -30,3 +30,3 @@ logger.debug(`Skipping ${file} due to unsupported extension`); | ||
} | ||
if (shouldIgnoreFile(file, cwd)) { | ||
if (shouldIgnoreFile(file)) { | ||
logger.debug(`Skipping ${file} due to an ignore rule`); | ||
@@ -64,4 +64,4 @@ return; | ||
async function deleteRemoteFile(accountId, filePath, remoteFilePath, { cwd }) { | ||
if (shouldIgnoreFile(filePath, cwd)) { | ||
async function deleteRemoteFile(accountId, filePath, remoteFilePath) { | ||
if (shouldIgnoreFile(filePath)) { | ||
logger.debug(`Skipping ${filePath} due to an ignore rule`); | ||
@@ -90,8 +90,3 @@ return; | ||
function watch( | ||
accountId, | ||
src, | ||
dest, | ||
{ mode, cwd, remove, disableInitial, notify } | ||
) { | ||
function watch(accountId, src, dest, { mode, remove, disableInitial, notify }) { | ||
const regex = new RegExp(`^${escapeRegExp(src)}`); | ||
@@ -105,3 +100,3 @@ | ||
ignoreInitial: true, | ||
ignored: file => shouldIgnoreFile(file, cwd), | ||
ignored: file => shouldIgnoreFile(file), | ||
}); | ||
@@ -116,3 +111,3 @@ | ||
// Use uploadFolder so that failures of initial upload are retried | ||
uploadFolder(accountId, src, dest, { mode, cwd }) | ||
uploadFolder(accountId, src, dest, { mode }) | ||
.then(() => { | ||
@@ -141,3 +136,2 @@ logger.success( | ||
mode, | ||
cwd, | ||
}); | ||
@@ -151,3 +145,3 @@ triggerNotify(notify, 'Added', filePath, uploadPromise); | ||
if (shouldIgnoreFile(filePath, cwd)) { | ||
if (shouldIgnoreFile(filePath)) { | ||
logger.debug(`Skipping ${filePath} due to an ignore rule`); | ||
@@ -159,10 +153,3 @@ return; | ||
queue.add(() => { | ||
const deletePromise = deleteRemoteFile( | ||
accountId, | ||
filePath, | ||
remotePath, | ||
{ | ||
cwd, | ||
} | ||
) | ||
const deletePromise = deleteRemoteFile(accountId, filePath, remotePath) | ||
.then(() => { | ||
@@ -194,3 +181,2 @@ logger.log('Deleted %s "%s"', type, remotePath); | ||
mode, | ||
cwd, | ||
}); | ||
@@ -197,0 +183,0 @@ triggerNotify(notify, 'Changed', filePath, uploadPromise); |
10
oauth.js
@@ -9,5 +9,5 @@ const OAuth2Manager = require('./lib/models/OAuth2Manager'); | ||
const writeOauthTokenInfo = (AccountConfig, tokenInfo) => { | ||
const { accountId, authType, auth, env, name, apiKey } = AccountConfig; | ||
const { portalId, authType, auth, env, name, apiKey } = AccountConfig; | ||
logger.debug(`Updating Oauth2 token info for accountId: ${accountId}`); | ||
logger.debug(`Updating Oauth2 token info for portalId: ${portalId}`); | ||
@@ -18,3 +18,3 @@ updateAccountConfig({ | ||
environment: env, | ||
accountId, | ||
portalId, | ||
authType, | ||
@@ -40,3 +40,3 @@ ...auth, | ||
const addOauthToAccountConfig = (accountId, oauth) => { | ||
const addOauthToAccountConfig = (portalId, oauth) => { | ||
logger.log('Updating configuration'); | ||
@@ -47,3 +47,3 @@ try { | ||
authType: AUTH_METHODS.oauth.value, | ||
accountId, | ||
portalId, | ||
}); | ||
@@ -50,0 +50,0 @@ writeConfig(); |
{ | ||
"name": "@hubspot/cms-lib", | ||
"version": "2.2.1-beta.3", | ||
"version": "2.2.1-beta.4", | ||
"description": "Library for working with the HubSpot CMS", | ||
@@ -34,3 +34,3 @@ "license": "Apache-2.0", | ||
}, | ||
"gitHead": "8958c173115e232ab36ed4661c3da8e080071a21" | ||
"gitHead": "923b4c5c1f2099e75051705ae2541d9f231c650a" | ||
} |
@@ -47,3 +47,3 @@ const moment = require('moment'); | ||
return { | ||
accountId: response.hubId, | ||
portalId: response.hubId, | ||
accessToken: response.oauthAccessToken, | ||
@@ -70,3 +70,3 @@ expiresAt: moment(response.expiresAtMillis), | ||
...config, | ||
accountId, | ||
portalId: accountId, | ||
tokenInfo: { | ||
@@ -148,6 +148,6 @@ accessToken, | ||
} | ||
const { accountId, accessToken, expiresAt } = token; | ||
const { portalId, accessToken, expiresAt } = token; | ||
const updatedConfig = updateAccountConfig({ | ||
accountId, | ||
portalId, | ||
personalAccessKey, | ||
@@ -154,0 +154,0 @@ name, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
279153
8945