@hubspot/cms-lib
Advanced tools
Comparing version 2.0.0-beta.2 to 2.0.0
const moment = require('moment'); | ||
const { getAndLoadConfigIfNeeded, getPortalConfig } = require('../lib/config'); | ||
const { fetchAccessToken } = require('../api/localDevAuth'); | ||
const { fetchAccessToken } = require('../api/localDevAuth/unauthenticated'); | ||
const { ENVIRONMENTS } = require('../lib/constants'); | ||
@@ -10,3 +10,3 @@ | ||
jest.mock('../logger'); | ||
jest.mock('../api/localDevAuth'); | ||
jest.mock('../api/localDevAuth/unauthenticated'); | ||
@@ -13,0 +13,0 @@ describe('personalAccessKey', () => { |
@@ -17,2 +17,6 @@ const { HubSpotAuthError } = require('@hubspot/api-auth-lib/Errors'); | ||
const isFatalError = err => err instanceof HubSpotAuthError; | ||
const isMissingScopeError = err => | ||
err.name === 'StatusCodeError' && | ||
err.statusCode === 403 && | ||
err.error.category === 'MISSING_SCOPES'; | ||
const contactSupportString = | ||
@@ -304,2 +308,45 @@ 'Please try again or visit https://help.hubspot.com/ to submit a ticket or contact HubSpot Support if the issue persists.'; | ||
/** | ||
* Logs a message for an error instance resulting from API interaction | ||
* related to serverless function. | ||
* | ||
* @param {Error|SystemError|Object} error | ||
* @param {ApiErrorContext} context | ||
*/ | ||
function logServerlessFunctionApiErrorInstance(error, scopesData, context) { | ||
if (!scopesData) { | ||
return; | ||
} | ||
if (isMissingScopeError(error)) { | ||
const { portalScopesInGroup, userScopesInGroup } = scopesData; | ||
if (!portalScopesInGroup.length) { | ||
logger.error( | ||
'Your account does not have access to this action. Talk to an account admin to request it.' | ||
); | ||
return; | ||
} | ||
if (!portalScopesInGroup.every(s => userScopesInGroup.includes(s))) { | ||
logger.error( | ||
"You don't have access to this action. Ask an account admin to change your permissions in Users & Teams settings." | ||
); | ||
return; | ||
} else { | ||
logger.error( | ||
'Your access key does not allow this action. Please generate a new access key by running "hs auth personalaccesskey".' | ||
); | ||
return; | ||
} | ||
} | ||
// StatusCodeError | ||
if (isApiStatusCodeError(error)) { | ||
logApiStatusCodeError(error, context); | ||
return; | ||
} | ||
logErrorInstance(error, context); | ||
} | ||
module.exports = { | ||
@@ -315,2 +362,3 @@ ErrorContext, | ||
logFileSystemErrorInstance, | ||
logServerlessFunctionApiErrorInstance, | ||
}; |
@@ -90,2 +90,6 @@ const ENVIRONMENTS = { | ||
const SCOPE_GROUPS = { | ||
functions: 'cms.functions.read_write', | ||
}; | ||
module.exports = { | ||
@@ -108,2 +112,3 @@ Mode, | ||
ENVIRONMENT_VARIABLES, | ||
SCOPE_GROUPS, | ||
}; |
{ | ||
"name": "@hubspot/cms-lib", | ||
"version": "2.0.0-beta.2", | ||
"version": "2.0.0", | ||
"description": "Library for working with the HubSpot CMS", | ||
@@ -34,3 +34,3 @@ "license": "Apache-2.0", | ||
}, | ||
"gitHead": "3a35a937f255ad1934694aca25cc96a351713f2f" | ||
"gitHead": "16b34f98fff4688a6442623bc8d645e994f14395" | ||
} |
@@ -16,3 +16,3 @@ const moment = require('moment'); | ||
} = require('./lib/constants'); | ||
const { fetchAccessToken } = require('./api/localDevAuth'); | ||
const { fetchAccessToken } = require('./api/localDevAuth/unauthenticated'); | ||
const { logErrorInstance } = require('./errorHandlers'); | ||
@@ -19,0 +19,0 @@ |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
209694
72
6877
1
0