-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/shayel/add support for multi region param interactive #96
Changes from all commits
800aafd
84126b4
310a510
c38c0cf
a4b8c01
4bf68ed
ad74aca
ef76d45
f4d3a52
50e7ff3
16bc19f
c0971e7
0f160bc
0b0c293
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { APP_VERSION_STATUS } from 'consts/app-versions'; | ||
import { listAppVersionsByAppIdUrl } from 'consts/urls'; | ||
import { getAppVersionsByAppIdUrl, listAppVersionsByAppIdUrl } from 'consts/urls'; | ||
import { execute } from 'services/api-service'; | ||
import { listAppVersionsSchema } from 'services/schemas/app-versions-schemas'; | ||
import { getAppVersionSchema, listAppVersionsSchema } from 'services/schemas/app-versions-schemas'; | ||
import logger from 'src/utils/logger'; | ||
import { HttpError } from 'types/errors'; | ||
import { AppId } from 'types/general'; | ||
import { AppId, AppVersionId } from 'types/general'; | ||
import { HttpMethodTypes } from 'types/services/api-service'; | ||
import { AppVersion, ListAppVersionsResponse } from 'types/services/app-versions-service'; | ||
import { AppVersion, GetAppVersionResponse, ListAppVersionsResponse } from 'types/services/app-versions-service'; | ||
import { appsUrlBuilder } from 'utils/urls-builder'; | ||
|
||
export const listAppVersionsByAppId = async (appId: AppId): Promise<Array<AppVersion>> => { | ||
|
@@ -51,3 +51,28 @@ export const defaultVersionByAppId = async (appId: AppId, useLiveVersion = false | |
|
||
return validVersion; | ||
}; | ||
|
||
export const getAppVersionById = async (appVersionId: AppVersionId): Promise<AppVersion> => { | ||
try { | ||
const path = getAppVersionsByAppIdUrl(appVersionId); | ||
const url = appsUrlBuilder(path); | ||
logger.debug(`fetching logs url: ${url}`); | ||
const response = await execute<GetAppVersionResponse>( | ||
{ | ||
url, | ||
headers: { Accept: 'application/json' }, | ||
method: HttpMethodTypes.GET, | ||
}, | ||
getAppVersionSchema, | ||
); | ||
|
||
return response.appVersion; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you say it's returning an array this is a new endpoint that returns a single app version by id |
||
} catch (error: any) { | ||
if (error instanceof HttpError) { | ||
logger.error(error.message); | ||
throw error; | ||
} | ||
|
||
throw new Error('Failed to list app versions.'); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import { z } from 'zod'; | |
|
||
import { APP_VERSION_STATUS } from 'consts/app-versions'; | ||
import { baseResponseHttpMetaDataSchema } from 'services/schemas/api-service-schemas'; | ||
import { mondayCodeConfigSchema } from 'services/schemas/apps-service-schemas'; | ||
import { appIdSchema, appVersionIdSchema } from 'services/schemas/general-schemas'; | ||
|
||
export const appVersionSchema = z.object({ | ||
|
@@ -10,10 +11,17 @@ export const appVersionSchema = z.object({ | |
versionNumber: z.string(), | ||
appId: appIdSchema, | ||
status: z.nativeEnum(APP_VERSION_STATUS), | ||
mondayCodeConfig: mondayCodeConfigSchema, | ||
}); | ||
|
||
export const listAppVersionsSchema = z | ||
.object({ | ||
appVersions: z.array(appVersionSchema), | ||
}) | ||
.merge(baseResponseHttpMetaDataSchema); | ||
|
||
export const getAppVersionSchema = z | ||
.object({ | ||
appVersion: appVersionSchema, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment - version? versions? |
||
}) | ||
.merge(baseResponseHttpMetaDataSchema); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { z } from 'zod'; | ||
|
||
import { appVersionSchema, listAppVersionsSchema } from 'services/schemas/app-versions-schemas'; | ||
import { appVersionSchema, getAppVersionSchema, listAppVersionsSchema } from 'services/schemas/app-versions-schemas'; | ||
|
||
export type AppVersion = z.infer<typeof appVersionSchema>; | ||
export type GetAppVersionResponse = z.infer<typeof getAppVersionSchema>; | ||
export type ListAppVersionsResponse = z.infer<typeof listAppVersionsSchema>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { Flags } from '@oclif/core'; | ||
|
||
import { getAppVersionById } from 'services/app-versions-service'; | ||
import { checkIfAppSupportMultiRegion } from 'services/apps-service'; | ||
import { PromptService } from 'services/prompt-service'; | ||
import { Region } from 'types/general/region'; | ||
import { Permissions } from 'types/utils/permissions'; | ||
import { isPermitted } from 'utils/permissions'; | ||
import { isANumber } from 'utils/validations'; | ||
|
||
export const addRegionToQuery = (query: object | undefined, region?: Region) => { | ||
if (region) { | ||
|
@@ -34,3 +38,43 @@ export function addRegionToFlags<T>(flags: T): T { | |
|
||
return flags; | ||
} | ||
|
||
const regionsPrompt = async () => | ||
PromptService.promptList('Choose region', [Region.US, Region.EU, Region.AU], Region.US); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this use US as default? if so, why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. US is the auto-selected option for the prompt There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wdym? lets talk about this: @ShayElkana |
||
|
||
export async function chooseRegionIfNeeded( | ||
region?: Region, | ||
options?: { appId?: number; appVersionId?: number }, | ||
): Promise<Region | undefined> { | ||
if (region || !isPermitted(Permissions.MCODE_MULTI_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); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong log
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? it's for --verbose
we already have something like this
@maorb-dev