Skip to content

Commit

Permalink
feat: add new regions
Browse files Browse the repository at this point in the history
  • Loading branch information
Lisi Linhart committed Dec 15, 2023
1 parent 3c73604 commit 1b17037
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
11 changes: 6 additions & 5 deletions src/commands/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 = ''
Expand All @@ -107,7 +108,7 @@ export default class CreateStoryblokAppCommand extends Command {
)
}

if (spaceRegion && ['US'].includes(spaceRegion)) {
if (spaceRegion && isValidRegion) {
regionParam = `?region=${selectedRegion.value}`
}

Expand Down
5 changes: 4 additions & 1 deletion src/lib/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
21 changes: 16 additions & 5 deletions src/lib/regions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1b17037

Please sign in to comment.