storyblok 3.16.0 → 3.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,8 +3,6 @@
3
3
  <p align="center">A simple CLI for scaffolding <a href="https://www.storyblok.com" target="_blank">Storyblok</a> projects and fieldtypes.</p>
4
4
  </p>
5
5
 
6
- You found an issue?<br>Tell us about it - <a href="https://github.com/storyblok/storyblok/issues/new">open an issue</a> or look if it was <a href="https://github.com/storyblok/storyblok/issues/">already reported</a>.
7
-
8
6
  [![npm](https://img.shields.io/npm/v/storyblok.svg)](https://www.npmjs.com/package/storyblok)
9
7
  [![npm](https://img.shields.io/npm/dt/storyblok.svg)](ttps://img.shields.io/npm/dt/storyblok.svg)
10
8
  [![GitHub issues](https://img.shields.io/github/issues/storyblok/storyblok.svg?style=flat-square&v=1)](https://github.com/storyblok/storyblok/issues?q=is%3Aopen+is%3Aissue)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storyblok",
3
- "version": "3.16.0",
3
+ "version": "3.17.0",
4
4
  "description": "A simple CLI to start Storyblok from your command line.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/cli.js CHANGED
@@ -435,8 +435,9 @@ program
435
435
  if (!api.isAuthorized()) {
436
436
  await api.processLogin()
437
437
  }
438
+ const { region } = creds.get()
438
439
 
439
- await tasks.listSpaces(api)
440
+ await tasks.listSpaces(api, region)
440
441
  } catch (e) {
441
442
  console.log(chalk.red('X') + ' An error ocurred to listing spaces: ' + e.message)
442
443
  process.exit(1)
@@ -1,35 +1,64 @@
1
1
  const chalk = require('chalk')
2
-
3
2
  /**
4
3
  * @method listSpaces
5
4
  * @param api - Pass the api instance as a parameter
6
5
  * @return {Promise}
7
6
  */
8
7
 
9
- const listSpaces = async (api) => {
8
+ const listSpaces = async (api, currentRegion) => {
9
+ const isChinaEnv = currentRegion === 'cn'
10
+ const regionOptions = {
11
+ eu: 'Europe',
12
+ us: 'United States'
13
+ }
10
14
  console.log()
11
15
  console.log(chalk.green('✓') + ' Loading spaces...')
12
- console.log()
13
16
 
14
17
  if (!api) {
15
18
  console.log(chalk.red('X') + 'Api instance is required to make the request')
16
19
  return []
17
20
  }
18
21
 
19
- const spaces = await api.getAllSpaces()
20
- .then(res => res)
21
- .catch(err => Promise.reject(err))
22
+ if (isChinaEnv) {
23
+ const spaces = await api.getAllSpacesByRegion(currentRegion)
24
+ .then(res => res)
25
+ .catch(err => Promise.reject(err))
22
26
 
23
- if (!spaces) {
24
- console.log(chalk.red('X') + ' No spaces were found for this user ')
25
- return []
26
- }
27
-
28
- spaces.map(space => {
29
- console.log(`${space.name} (id: ${space.id})`)
30
- })
27
+ if (!spaces) {
28
+ console.log(chalk.red('X') + ' No spaces were found for this user ')
29
+ return []
30
+ }
31
+ console.log(chalk.blue(' -') + ' Spaces From China region:')
31
32
 
32
- return spaces
33
+ spaces.map(space => {
34
+ console.log(` ${space.name} (id: ${space.id})`)
35
+ })
36
+ return spaces
37
+ } else {
38
+ const spacesList = []
39
+ for (const key in regionOptions) {
40
+ spacesList.push(await api.getAllSpacesByRegion(key)
41
+ .then((res) => {
42
+ return {
43
+ key,
44
+ res
45
+ }
46
+ })
47
+ .catch(err => Promise.reject(err)))
48
+ }
49
+ if (!spacesList) {
50
+ console.log(chalk.red('X') + ' No spaces were found for this user ')
51
+ return []
52
+ }
53
+ spacesList.forEach(region => {
54
+ console.log()
55
+ console.log(`${chalk.blue(' -')} Spaces From ${regionOptions[region.key]} region:`)
56
+ region.res.forEach((space) => {
57
+ console.log(` ${space.name} (id: ${space.id})`)
58
+ })
59
+ })
60
+ return spacesList
61
+ }
33
62
  }
34
63
 
35
64
  module.exports = listSpaces
@@ -1,6 +1,6 @@
1
1
  const chalk = require('chalk')
2
- const StoryblokClient = require('storyblok-js-client')
3
2
  const { findByProperty } = require('../../utils')
3
+ const api = require('../../utils/api')
4
4
 
5
5
  class SyncComponentGroups {
6
6
  /**
@@ -14,9 +14,7 @@ class SyncComponentGroups {
14
14
  this.sourceComponentGroups = []
15
15
  this.targetComponentGroups = []
16
16
 
17
- this.client = new StoryblokClient({
18
- oauthToken: options.oauthToken
19
- })
17
+ this.client = api.getClient()
20
18
  }
21
19
 
22
20
  async init () {
@@ -1,9 +1,9 @@
1
1
  const chalk = require('chalk')
2
- const StoryblokClient = require('storyblok-js-client')
3
2
  const { find } = require('lodash')
4
3
  const SyncComponentGroups = require('./component-groups')
5
4
  const { findByProperty } = require('../../utils')
6
5
  const PresetsLib = require('../../utils/presets-lib')
6
+ const api = require('../../utils/api')
7
7
 
8
8
  class SyncComponents {
9
9
  /**
@@ -16,9 +16,7 @@ class SyncComponents {
16
16
  this.sourceSpaceId = options.sourceSpaceId
17
17
  this.targetSpaceId = options.targetSpaceId
18
18
  this.oauthToken = options.oauthToken
19
- this.client = new StoryblokClient({
20
- oauthToken: options.oauthToken
21
- })
19
+ this.client = api.getClient()
22
20
  this.presetsLib = new PresetsLib({ oauthToken: options.oauthToken, targetSpaceId: this.targetSpaceId })
23
21
  }
24
22
 
package/src/utils/api.js CHANGED
@@ -240,8 +240,13 @@ module.exports = {
240
240
  return client[method](_path, props)
241
241
  },
242
242
 
243
- async getAllSpaces () {
244
- return await this.getClient()
243
+ async getAllSpacesByRegion (region) {
244
+ const customClient = new Storyblok({
245
+ accessToken: this.accessToken,
246
+ oauthToken: this.oauthToken,
247
+ region
248
+ }, this.apiSwitcher(region))
249
+ return await customClient
245
250
  .get('spaces/', {})
246
251
  .then(res => res.data.spaces || [])
247
252
  .catch(err => Promise.reject(err))
@@ -1,8 +1,8 @@
1
1
  const chalk = require('chalk')
2
- const StoryblokClient = require('storyblok-js-client')
3
2
  const FormData = require('form-data')
4
3
  const axios = require('axios')
5
4
  const { last } = require('lodash')
5
+ const api = require('./api')
6
6
 
7
7
  class PresetsLib {
8
8
  /**
@@ -10,9 +10,7 @@ class PresetsLib {
10
10
  */
11
11
  constructor (options) {
12
12
  this.oauthToken = options.oauthToken
13
- this.client = new StoryblokClient({
14
- oauthToken: options.oauthToken
15
- })
13
+ this.client = api.getClient()
16
14
  this.targetSpaceId = options.targetSpaceId
17
15
  }
18
16
 
@@ -1,6 +1,12 @@
1
1
  const { listSpaces } = require('../../src/tasks/')
2
2
  const { FAKE_SPACES } = require('../constants')
3
3
 
4
+ const REGION_FLAGS = {
5
+ UNITED_STATES: 'us',
6
+ EUROPE: 'eu',
7
+ CHINA: 'cn'
8
+ }
9
+
4
10
  describe('Test spaces method', () => {
5
11
  it('Testing list-spaces funtion without api instance', async () => {
6
12
  try {
@@ -10,13 +16,34 @@ describe('Test spaces method', () => {
10
16
  console.error(e)
11
17
  }
12
18
  })
13
- it('Testing list-spaces funtion with api instance', async () => {
19
+
20
+ it('Testing list-spaces function for China region', async () => {
14
21
  const FAKE_API = {
15
- getAllSpaces: jest.fn(() => Promise.resolve(FAKE_SPACES()))
22
+ getAllSpacesByRegion: jest.fn(() => Promise.resolve(FAKE_SPACES()))
16
23
  }
17
24
  expect(
18
- await listSpaces(FAKE_API)
25
+ await listSpaces(FAKE_API, REGION_FLAGS.CHINA)
19
26
  ).toEqual(FAKE_SPACES())
20
- expect(FAKE_API.getAllSpaces).toHaveBeenCalled()
27
+ expect(FAKE_API.getAllSpacesByRegion).toHaveBeenCalled()
28
+ })
29
+
30
+ it('Testing list-spaces funtion for Europe and United States regions', async () => {
31
+ const FAKE_API = {
32
+ getAllSpacesByRegion: jest.fn(() => Promise.resolve(FAKE_SPACES()))
33
+ }
34
+ const response = [
35
+ {
36
+ key: REGION_FLAGS.EUROPE,
37
+ res: [...FAKE_SPACES()]
38
+ },
39
+ {
40
+ key: REGION_FLAGS.UNITED_STATES,
41
+ res: [...FAKE_SPACES()]
42
+ }
43
+ ]
44
+
45
+ expect(
46
+ await listSpaces(FAKE_API, REGION_FLAGS.EUROPE)
47
+ ).toEqual(response)
21
48
  })
22
49
  })
package/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - 14
4
- after_success:
5
- - npx semantic-release