Skip to content

Commit

Permalink
Convert lib/sandboxes to TS
Browse files Browse the repository at this point in the history
  • Loading branch information
camden11 committed Jan 10, 2025
1 parent 4576302 commit 680d155
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 129 deletions.
10 changes: 5 additions & 5 deletions commands/sandbox/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const { EXIT_CODES } = require('../../lib/enums/exitCodes');
const { getAccountConfig, getEnv } = require('@hubspot/local-dev-lib/config');
const { uiFeatureHighlight, uiBetaTag } = require('../../lib/ui');
const {
sandboxTypeMap,
SANDBOX_TYPE_MAP,
getAvailableSyncTypes,
syncTypes,
SYNC_TYPES,
validateSandboxUsageLimits,
} = require('../../lib/sandboxes');
const { getValidEnv } = require('@hubspot/local-dev-lib/environment');
Expand Down Expand Up @@ -65,7 +65,7 @@ exports.handler = async options => {
let typePrompt;
let namePrompt;

if ((type && !sandboxTypeMap[type.toLowerCase()]) || !type) {
if ((type && !SANDBOX_TYPE_MAP[type.toLowerCase()]) || !type) {
if (!force) {
typePrompt = await sandboxTypePrompt();
} else {
Expand All @@ -74,7 +74,7 @@ exports.handler = async options => {
}
}
const sandboxType = type
? sandboxTypeMap[type.toLowerCase()]
? SANDBOX_TYPE_MAP[type.toLowerCase()]
: typePrompt.type;

// Check usage limits and exit if parent portal has no available sandboxes for the selected type
Expand Down Expand Up @@ -156,7 +156,7 @@ exports.handler = async options => {

if (!contactRecordsSyncPromptResult) {
availableSyncTasks = availableSyncTasks.filter(
t => t.type !== syncTypes.OBJECT_RECORDS
t => t.type !== SYNC_TYPES.OBJECT_RECORDS
);
}
await handleSyncSandbox(availableSyncTasks);
Expand Down
2 changes: 2 additions & 0 deletions lang/en.lyaml
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,7 @@ en:
failure:
invalidUser: "Couldn't create {{#bold}}{{ accountName }}{{/bold}} because your account has been removed from {{#bold}}{{ parentAccountName }}{{/bold}} or your permission set doesn't allow you to create the sandbox. To update your permissions, contact a super admin in {{#bold}}{{ parentAccountName }}{{/bold}}."
403Gating: "Couldn't create {{#bold}}{{ accountName }}{{/bold}} because {{#bold}}{{ parentAccountName }}{{/bold}} does not have access to development sandboxes. To opt in to the CRM Development Beta and use development sandboxes, visit https://app.hubspot.com/l/product-updates/in-beta?update=13899236."
usageLimitsFetch: "Unable to fetch sandbox usage limits. Please try again."
limit:
developer:
one: "{{#bold}}{{ accountName }}{{/bold}} reached the limit of {{ limit }} development sandbox.
Expand Down Expand Up @@ -1477,6 +1478,7 @@ en:
syncInProgress: "Couldn't run the sync because there's another sync in progress. Wait for the current sync to finish and then try again. To check the sync status, visit the sync activity log: {{ url }}."
notSuperAdmin: "Couldn't run the sync because you are not a super admin in {{ account }}. Ask the account owner for super admin access to the sandbox."
objectNotFound: "Couldn't sync the sandbox because {{#bold}}{{ account }}{{/bold}} may have been deleted through the UI. Run {{#bold}}hs sandbox delete{{/bold}} to remove this account from the config. "
syncTypeFetch: "Unable to fetch available sandbox sync types. Please try again."
errorHandlers:
index:
errorOccurred: "Error: {{ error }}"
Expand Down
9 changes: 6 additions & 3 deletions lib/buildAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ const {
HUBSPOT_ACCOUNT_TYPES,
} = require('@hubspot/local-dev-lib/constants/config');
const { createSandbox } = require('@hubspot/local-dev-lib/api/sandboxHubs');
const { sandboxApiTypeMap, handleSandboxCreateError } = require('./sandboxes');
const {
SANDBOX_API_TYPE_MAP,
handleSandboxCreateError,
} = require('./sandboxes');
const {
handleDeveloperTestAccountCreateError,
} = require('./developerTestAccounts');
Expand Down Expand Up @@ -132,7 +135,7 @@ async function buildNewAccount({
let resultAccountId;
try {
if (isSandbox) {
const sandboxApiType = sandboxApiTypeMap[accountType]; // API expects sandbox type as 1 or 2.
const sandboxApiType = SANDBOX_API_TYPE_MAP[accountType]; // API expects sandbox type as 1 or 2.

const { data } = await createSandbox(accountId, name, sandboxApiType);
result = { name, ...data };
Expand All @@ -159,7 +162,7 @@ async function buildNewAccount({
});

if (isSandbox) {
handleSandboxCreateError({ err, env, accountConfig, name, accountId });
handleSandboxCreateError(err, env, accountConfig, name, accountId);
}
if (isDeveloperTestAccount) {
handleDeveloperTestAccountCreateError(err, env, accountId, portalLimit);
Expand Down
Loading

0 comments on commit 680d155

Please sign in to comment.