From 3c7360419afd2e9136948efe78a9dd9ffc2016a8 Mon Sep 17 00:00:00 2001 From: Lisi Linhart Date: Thu, 21 Sep 2023 09:43:12 +0200 Subject: [PATCH 1/5] Revert "chore: region EU and US" --- README.md | 2 +- src/commands/default.ts | 2 +- src/lib/regions.ts | 6 ++++++ test/unit/regions.test.ts | 8 ++++---- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ff6674e..a741409 100644 --- a/README.md +++ b/README.md @@ -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, US or CN) -v, --version show CLI version ~~~ diff --git a/src/commands/default.ts b/src/commands/default.ts index 4dfa214..05b2803 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 or US)', + description: 'Space region (EU, US or CN)', }), folder: Flags.string({ char: 'd', diff --git a/src/lib/regions.ts b/src/lib/regions.ts index 2291c48..48b8b47 100644 --- a/src/lib/regions.ts +++ b/src/lib/regions.ts @@ -27,6 +27,12 @@ const regions: RegionMap = { apiEndpoint: 'https://api-us.storyblok.com/v2/cdn/', urlUi: 'https://app.storyblok.com', }, + CN: { + name: 'CN', + value: '', + apiEndpoint: 'https://app.storyblokchina.cn/v2/cdn/', + urlUi: 'https://app.storyblokchina.cn/fe/editor_v2', + }, } diff --git a/test/unit/regions.test.ts b/test/unit/regions.test.ts index 549c458..a303f6b 100644 --- a/test/unit/regions.test.ts +++ b/test/unit/regions.test.ts @@ -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 3 regions', function () { + assert.equal(Object.keys(regions).length, 3) }) }) From 1b17037da99f3b1c7123820d881e293f2c8dc0b4 Mon Sep 17 00:00:00 2001 From: Lisi Linhart Date: Fri, 15 Dec 2023 10:55:22 +0100 Subject: [PATCH 2/5] 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 From 05add780a45fa523ed0f9f1ca95138ce289b1eb9 Mon Sep 17 00:00:00 2001 From: Lisi Linhart Date: Fri, 15 Dec 2023 11:09:45 +0100 Subject: [PATCH 3/5] chore: update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a741409..be48acd 100644 --- a/README.md +++ b/README.md @@ -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 (e.g. EU, US or CN) + -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 ~~~ From eef666a57b6f2296f53b1d9a8075ce7a5ff4ef06 Mon Sep 17 00:00:00 2001 From: Lisi Linhart Date: Fri, 15 Dec 2023 11:13:39 +0100 Subject: [PATCH 4/5] chore: update regions --- test/unit/regions.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/regions.test.ts b/test/unit/regions.test.ts index a303f6b..d7687fb 100644 --- a/test/unit/regions.test.ts +++ b/test/unit/regions.test.ts @@ -9,7 +9,7 @@ describe('Regions', function () { it('contains CN', function () { assert.equal(Object.keys(regions).includes('CN'), true) }) - it('contains 3 regions', function () { - assert.equal(Object.keys(regions).length, 3) + it('contains 5 regions', function () { + assert.equal(Object.keys(regions).length, 5) }) }) From 0b7331f1878ce6be35fa9795d12071702f9eeb9c Mon Sep 17 00:00:00 2001 From: Lisi Linhart Date: Fri, 15 Dec 2023 11:23:59 +0100 Subject: [PATCH 5/5] fix: unit tests --- src/commands/default.ts | 2 +- test/commands/default.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commands/default.ts b/src/commands/default.ts index 9ea8be4..c1e13c9 100644 --- a/src/commands/default.ts +++ b/src/commands/default.ts @@ -95,7 +95,7 @@ export default class CreateStoryblokAppCommand extends Command { 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(', ')}`) + throw new Error(`Please provide a valid region via '-r' parameter : ${possibleRegionValues.join(', ')}`) } let regionParam = '' diff --git a/test/commands/default.test.ts b/test/commands/default.test.ts index 2e60a7e..a194dcd 100644 --- a/test/commands/default.test.ts +++ b/test/commands/default.test.ts @@ -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') }) })