Skip to content

Commit

Permalink
Merge pull request #32 from storyblok/revert-31-temp-skip-cn
Browse files Browse the repository at this point in the history
Introduce new regions: CN, AP, CA
  • Loading branch information
Lisi Linhart authored Dec 15, 2023
2 parents 5c78599 + 0b7331f commit 0431f87
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ OPTIONS
-h, --help show CLI help
-k, --key=key Storyblok Access Token
-p, --packagemanager=packagemanager Package manager to use (yarn or npm)
-r, --region=region Space region (EU, US). The support for the China region will be introduced in the next release.
-r, --region=region Space region (e.g. eu-central-1, us-east-1, cn-north-1, ca-central-1, ap-southeast-2)
-v, --version show CLI version
~~~

Expand Down
13 changes: 7 additions & 6 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 or US)',
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
throw new Error(`Please provide a valid region via '-r' parameter : ${possibleRegionValues.join(', ')}`)
}

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
23 changes: 20 additions & 3 deletions src/lib/regions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +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 - 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
4 changes: 2 additions & 2 deletions test/commands/default.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ describe('Launch command', () => {

test
.stdout({print: false})
.command(['default', '--folder=mytestdir', '--packagemanager=npm', '--framework=astro', '--region=EU', '--key=TEST'])
.command(['default', '--folder=mytestdir', '--packagemanager=npm', '--framework=astro', '--region=YOLO', '--key=TEST'])
.it('with wrong region', async ctx => {
expect(ctx.stdout).to.contain('the space is located in a region outside')
expect(ctx.stdout).to.contain('Please provide a valid region')
})
})
8 changes: 4 additions & 4 deletions test/unit/regions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ describe('Regions', function () {
it('contains US', function () {
assert.equal(Object.keys(regions).includes('US'), true)
})
it('not contains CN', function () {
assert.equal(Object.keys(regions).includes('CN'), false)
it('contains CN', function () {
assert.equal(Object.keys(regions).includes('CN'), true)
})
it('contains 2 regions', function () {
assert.equal(Object.keys(regions).length, 2)
it('contains 5 regions', function () {
assert.equal(Object.keys(regions).length, 5)
})
})

0 comments on commit 0431f87

Please sign in to comment.