UNPKG

@mondaycom/apps-cli

Version:

A cli tool to manage apps (and monday-code projects) in monday.com

64 lines (63 loc) 2.32 kB
import { Flags } from '@oclif/core'; import { getAppVersionById } from '../services/app-versions-service.js'; import { checkIfAppSupportMultiRegion } from '../services/apps-service.js'; import { PromptService } from '../services/prompt-service.js'; import { Region } from '../types/general/region.js'; import { isANumber } from './validations.js'; export const addRegionToQuery = (query, region) => { if (region) { return { ...query, region }; } return query; }; export const getRegionFromString = (region) => { return region && typeof region === 'string' ? Region[region.toUpperCase()] : undefined; }; export const regionFlag = { region: Flags.string({ char: 'z', description: 'Region to use', options: Object.values(Region), }), }; export function addRegionToFlags(flags) { return { ...flags, ...regionFlag, }; } const regionsPrompt = async () => PromptService.promptList('Choose region', [Region.US, Region.EU, Region.AU, Region.IL], Region.US); export async function chooseRegionIfNeeded(region, options) { if (region) { return region; } const { appId, appVersionId } = options || {}; let isMultiRegionApp = false; let _appId = appId; if (appVersionId && isANumber(appVersionId)) { const appVersion = await getAppVersionById(appVersionId); if (!appVersion) throw new Error(`AppVersion with id ${appVersionId} not found.`); _appId = appVersion.appId; if (appVersion?.mondayCodeConfig?.isMultiRegion) { isMultiRegionApp = true; } } if (!isMultiRegionApp && _appId && isANumber(_appId)) { const isAppSupportMultiRegion = await checkIfAppSupportMultiRegion(_appId); if (isAppSupportMultiRegion) { isMultiRegionApp = true; } } if (!isMultiRegionApp) { return region; } const returnedRegion = await regionsPrompt(); return getRegionFromString(returnedRegion); } export async function chooseSchedulerRegionIfNeeded(region, options) { if (region === Region.IL) { throw new Error('Cloud Scheduler is not available in the IL region. Please use a different region (US, EU, or AU) for scheduler operations.'); } return chooseRegionIfNeeded(region, options); }