From 1b17037da99f3b1c7123820d881e293f2c8dc0b4 Mon Sep 17 00:00:00 2001 From: Lisi Linhart Date: Fri, 15 Dec 2023 10:55:22 +0100 Subject: [PATCH] feat: add new regions --- src/commands/default.ts | 11 ++++++----- src/lib/prompts.ts | 5 ++++- src/lib/regions.ts | 21 ++++++++++++++++----- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/commands/default.ts b/src/commands/default.ts index 05b2803..9ea8be4 100644 --- a/src/commands/default.ts +++ b/src/commands/default.ts @@ -24,7 +24,7 @@ export default class CreateStoryblokAppCommand extends Command { key: Flags.string({char: 'k', description: 'Storyblok Access Token'}), region: Flags.string({ char: 'r', - description: 'Space region (EU, US or CN)', + description: 'Space region (eu-central-1, us-east-1, cn-north-1, ca-central-1, ap-southeast-2)', }), folder: Flags.string({ char: 'd', @@ -90,11 +90,12 @@ export default class CreateStoryblokAppCommand extends Command { // region const spaceRegion: string = flags?.region || region // EU , US or CN let selectedRegion: Region | undefined - if (Object.keys(regions).includes(spaceRegion)) { - selectedRegion = regions[spaceRegion] + const possibleRegionValues = Object.values(regions).map(r => r.value) + const isValidRegion = possibleRegionValues.includes(spaceRegion) + if (isValidRegion) { + selectedRegion = Object.values(regions).find(r => r.value === spaceRegion) } else { throw new Error(`Please provide a valid region via '-r' parameter : ${Object.keys(regions).join(', ')}`) - return 2 } let regionParam = '' @@ -107,7 +108,7 @@ export default class CreateStoryblokAppCommand extends Command { ) } - if (spaceRegion && ['US'].includes(spaceRegion)) { + if (spaceRegion && isValidRegion) { regionParam = `?region=${selectedRegion.value}` } diff --git a/src/lib/prompts.ts b/src/lib/prompts.ts index 7d181a2..16b0549 100644 --- a/src/lib/prompts.ts +++ b/src/lib/prompts.ts @@ -32,7 +32,10 @@ export default [ message: 'Space Region (optional, EU is used by default):', default: 'EU', prefix: '🌍', - choices: Object.keys(regions), + choices: Object.values(regions).map(r => ({ + name: r.name, + value: r.value, + })), }, { type: 'input', diff --git a/src/lib/regions.ts b/src/lib/regions.ts index 48b8b47..5003e8c 100644 --- a/src/lib/regions.ts +++ b/src/lib/regions.ts @@ -15,25 +15,36 @@ type RegionMap = { const regions: RegionMap = { EU: { - name: 'EU', + name: 'EU - Europe', value: 'eu-central-1', apiEndpoint: 'https://api.storyblok.com/v2/cdn/', urlUi: 'https://app.storyblok.com', }, US: { - name: 'US', + name: 'US - United States', value: 'us-east-1', apiEndpoint: 'https://api-us.storyblok.com/v2/cdn/', urlUi: 'https://app.storyblok.com', }, CN: { - name: 'CN', - value: '', + name: 'CN - China', + value: 'cn-north-1', apiEndpoint: 'https://app.storyblokchina.cn/v2/cdn/', urlUi: 'https://app.storyblokchina.cn/fe/editor_v2', }, - + CA: { + name: 'CA - Canada', + value: 'ca-central-1', + apiEndpoint: 'https://api-ca.storyblok.com/v2/cdn/', + urlUi: 'https://app.storyblok.com', + }, + AP: { + name: 'AP - Australia', + value: 'ap-southeast-2', + apiEndpoint: 'https://api-ap.storyblok.com/v2/cdn/', + urlUi: 'https://app.storyblok.com', + }, } export default regions