storyblok 3.25.2 → 3.26.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
@@ -44,7 +44,7 @@ $ storyblok login
44
44
 
45
45
  **For Both login options you nedd to pass the region**
46
46
 
47
- * `region`: region you would like to work in. Please keep in mind that the region must match the region of your space. You can use `us`, `cn` or `eu`, if left empty, default is `eu`. This region flag will be used for the other cli's commands.
47
+ * `region`: region you would like to work in. Please keep in mind that the region must match the region of your space. You can use `us`, `cn`, `eu`, `ca` and `ap`, if left empty, default is `eu`. This region flag will be used for the other cli's commands.
48
48
 
49
49
  #### Login with token flag
50
50
  You can also add the token directly from the login’s command, like the example below:
@@ -1,4 +1,4 @@
1
- const { LOGIN_URL, SIGNUP_URL } = require('../src/constants')
1
+ const { USERS_ROUTES } = require('../src/constants')
2
2
  const { EMAIL_TEST, PASSWORD_TEST, TOKEN_TEST } = require('../tests/constants')
3
3
 
4
4
  const isCredCorrects = (email, pass) => {
@@ -9,7 +9,7 @@ const axios = {
9
9
  post: jest.fn((path, data) => {
10
10
  const { email, password } = data || {}
11
11
 
12
- if (path === LOGIN_URL && isCredCorrects(email, password)) {
12
+ if (path === USERS_ROUTES.LOGIN && isCredCorrects(email, password)) {
13
13
  return Promise.resolve({
14
14
  data: {
15
15
  access_token: TOKEN_TEST
@@ -17,7 +17,7 @@ const axios = {
17
17
  })
18
18
  }
19
19
 
20
- if (path === SIGNUP_URL && isCredCorrects(email, password)) {
20
+ if (path === USERS_ROUTES.SIGNUP && isCredCorrects(email, password)) {
21
21
  return Promise.resolve({
22
22
  data: {
23
23
  access_token: TOKEN_TEST
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storyblok",
3
- "version": "3.25.2",
3
+ "version": "3.26.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
@@ -492,29 +492,29 @@ program
492
492
  }
493
493
  })
494
494
 
495
- // delete-datasources
495
+ // delete-datasources
496
496
  program
497
- .command(COMMANDS.DELETE_DATASOURCES)
498
- .requiredOption('--space-id <SPACE_ID>', 'Space id')
499
- .option('--by-slug <SLUG>', 'Delete datasources by slug')
500
- .option('--by-name <name>', 'Delete datasources by name')
501
- .action(async (options) => {
502
- console.log(`${chalk.blue('-')} Executing ${COMMANDS.DELETE_DATASOURCES} task`)
503
-
504
- const { spaceId, bySlug, byName } = options
505
-
506
- try {
507
- if (!api.isAuthorized()) {
508
- await api.processLogin()
509
- }
497
+ .command(COMMANDS.DELETE_DATASOURCES)
498
+ .requiredOption('--space-id <SPACE_ID>', 'Space id')
499
+ .option('--by-slug <SLUG>', 'Delete datasources by slug')
500
+ .option('--by-name <name>', 'Delete datasources by name')
501
+ .action(async (options) => {
502
+ console.log(`${chalk.blue('-')} Executing ${COMMANDS.DELETE_DATASOURCES} task`)
510
503
 
511
- api.setSpaceId(spaceId)
504
+ const { spaceId, bySlug, byName } = options
512
505
 
513
- await tasks.deleteDatasources(api, { byName, bySlug })
514
- } catch (e) {
515
- errorHandler(e, COMMANDS.DELETE_DATASOURCES)
516
- }
517
- })
506
+ try {
507
+ if (!api.isAuthorized()) {
508
+ await api.processLogin()
509
+ }
510
+
511
+ api.setSpaceId(spaceId)
512
+
513
+ await tasks.deleteDatasources(api, { byName, bySlug })
514
+ } catch (e) {
515
+ errorHandler(e, COMMANDS.DELETE_DATASOURCES)
516
+ }
517
+ })
518
518
 
519
519
  program.parse(process.argv)
520
520
 
@@ -524,7 +524,7 @@ if (program.rawArgs.length <= 2) {
524
524
 
525
525
  function errorHandler (e, command) {
526
526
  if (/404/.test(e.message)) {
527
- console.log(chalk.yellow('/!\\') + ' If your space was created under US or CN region, you must provide the region us or cn upon login.')
527
+ console.log(chalk.yellow('/!\\') + ' If your space was created under US, CA, AP or CN region, you must provide the region us, ca, ap or cn upon login.')
528
528
  } else {
529
529
  console.log(chalk.red('X') + ' An error occurred when executing the ' + command + ' task: ' + e || e.message)
530
530
  }
package/src/constants.js CHANGED
@@ -1,9 +1,3 @@
1
- const API_URL = 'https://api.storyblok.com/v1/'
2
- const US_API_URL = 'https://api-us.storyblok.com/v1/'
3
- const CN_API_URL = 'https://app.storyblokchina.cn/v1/'
4
- const LOGIN_URL = `${API_URL}users/login`
5
- const SIGNUP_URL = `${API_URL}users/signup`
6
-
7
1
  const SYNC_TYPES = [
8
2
  'folders',
9
3
  'components',
@@ -34,13 +28,43 @@ const DEFAULT_AGENT = {
34
28
  SB_Agent_Version: process.env.npm_package_version || '3.0.0'
35
29
  }
36
30
 
31
+ const REGIONS = {
32
+ cn: {
33
+ key: 'cn',
34
+ name: 'China',
35
+ apiEndpoint: 'https://app.storyblokchina.cn/v1/'
36
+ },
37
+ eu: {
38
+ key: 'eu',
39
+ name: 'Europe',
40
+ apiEndpoint: 'https://api.storyblok.com/v1/'
41
+ },
42
+ us: {
43
+ key: 'us',
44
+ name: 'United States',
45
+ apiEndpoint: 'https://api-us.storyblok.com/v1/'
46
+ },
47
+ ca: {
48
+ key: 'ca',
49
+ name: 'Canada',
50
+ apiEndpoint: 'https://api-ca.storyblok.com/v1/'
51
+ },
52
+ ap: {
53
+ key: 'ap',
54
+ name: 'Australia',
55
+ apiEndpoint: 'https://api-ap.storyblok.com/v1/'
56
+ }
57
+ }
58
+
59
+ const USERS_ROUTES = {
60
+ LOGIN: `${REGIONS.eu.apiEndpoint}users/login`,
61
+ SIGNUP: `${REGIONS.eu.apiEndpoint}users/signup`
62
+ }
63
+
37
64
  module.exports = {
38
- LOGIN_URL,
39
- SIGNUP_URL,
40
- API_URL,
41
65
  SYNC_TYPES,
42
- US_API_URL,
43
- CN_API_URL,
66
+ USERS_ROUTES,
44
67
  COMMANDS,
45
- DEFAULT_AGENT
68
+ DEFAULT_AGENT,
69
+ REGIONS
46
70
  }
@@ -1,4 +1,5 @@
1
1
  const chalk = require('chalk')
2
+ const { REGIONS } = require('../constants')
2
3
  /**
3
4
  * @method listSpaces
4
5
  * @param api - Pass the api instance as a parameter
@@ -7,10 +8,7 @@ const chalk = require('chalk')
7
8
 
8
9
  const listSpaces = async (api, currentRegion) => {
9
10
  const isChinaEnv = currentRegion === 'cn'
10
- const regionOptions = {
11
- eu: 'Europe',
12
- us: 'United States'
13
- }
11
+
14
12
  console.log()
15
13
  console.log(chalk.green('✓') + ' Loading spaces...')
16
14
 
@@ -36,7 +34,8 @@ const listSpaces = async (api, currentRegion) => {
36
34
  return spaces
37
35
  } else {
38
36
  const spacesList = []
39
- for (const key in regionOptions) {
37
+ for (const key in REGIONS) {
38
+ if (key === 'cn') continue
40
39
  spacesList.push(await api.getAllSpacesByRegion(key)
41
40
  .then((res) => {
42
41
  return {
@@ -51,8 +50,9 @@ const listSpaces = async (api, currentRegion) => {
51
50
  return []
52
51
  }
53
52
  spacesList.forEach(region => {
53
+ const regionName = REGIONS[region.key].name
54
54
  console.log()
55
- console.log(`${chalk.blue(' -')} Spaces From ${regionOptions[region.key]} region:`)
55
+ console.log(`${chalk.blue(' -')} Spaces From ${regionName} region:`)
56
56
  region.res.forEach((space) => {
57
57
  console.log(` ${space.name} (id: ${space.id})`)
58
58
  })
@@ -46,7 +46,7 @@ class SyncDatasources {
46
46
  const entriesFirstPage = await this.client.get(`spaces/${spaceId}/datasource_entries/?datasource_id=${datasourceId}${dimensionQuery}`)
47
47
  const entriesRequets = []
48
48
  for (let i = 2; i <= Math.ceil(entriesFirstPage.total / 25); i++) {
49
- entriesRequets.push(await this.client.get(`spaces/${spaceId}/datasource_entries/?datasource_id=${datasourceId}&page=${i}`))
49
+ entriesRequets.push(await this.client.get(`spaces/${spaceId}/datasource_entries?datasource_id=${datasourceId}&page=${i}${dimensionQuery}`))
50
50
  }
51
51
  return entriesFirstPage.data.datasource_entries.concat(...(await Promise.all(entriesRequets)).map(r => r.data.datasource_entries))
52
52
  } catch (err) {
package/src/utils/api.js CHANGED
@@ -5,7 +5,7 @@ const inquirer = require('inquirer')
5
5
 
6
6
  const creds = require('./creds')
7
7
  const getQuestions = require('./get-questions')
8
- const { SIGNUP_URL, API_URL, US_API_URL, CN_API_URL, DEFAULT_AGENT } = require('../constants')
8
+ const { REGIONS, USERS_ROUTES, DEFAULT_AGENT } = require('../constants')
9
9
 
10
10
  module.exports = {
11
11
  accessToken: '',
@@ -39,7 +39,7 @@ module.exports = {
39
39
  },
40
40
 
41
41
  async login (content) {
42
- const { email, password, region } = content
42
+ const { email, password, region = 'eu' } = content
43
43
  try {
44
44
  const response = await axios.post(`${this.apiSwitcher(region)}users/login`, {
45
45
  email: email,
@@ -169,7 +169,7 @@ module.exports = {
169
169
  },
170
170
 
171
171
  signup (email, password, region = 'eu') {
172
- return axios.post(SIGNUP_URL, {
172
+ return axios.post(USERS_ROUTES.SIGNUP, {
173
173
  email: email,
174
174
  password: password,
175
175
  region
@@ -310,12 +310,6 @@ module.exports = {
310
310
  },
311
311
 
312
312
  apiSwitcher (region) {
313
- const apiList = {
314
- us: US_API_URL,
315
- cn: CN_API_URL,
316
- eu: API_URL
317
- }
318
-
319
- return region ? apiList[region] : apiList[this.region]
313
+ return region ? REGIONS[region].apiEndpoint : REGIONS[this.region].apiEndpoint
320
314
  }
321
315
  }
@@ -1,3 +1,4 @@
1
+ const { REGIONS } = require('../constants')
1
2
  const getOptions = (subCommand, argv = {}, api = {}) => {
2
3
  let email = ''
3
4
  const moreOptions = [
@@ -6,17 +7,17 @@ const getOptions = (subCommand, argv = {}, api = {}) => {
6
7
  'push-components',
7
8
  'scaffold'
8
9
  ]
10
+ const regionsPrefixList = Object.keys(REGIONS)
9
11
  const regionInput = {
10
12
  type: 'input',
11
13
  name: 'region',
12
- message: 'Please enter the region you would like to work in (us, eu or cn) - if not set, default is eu:',
14
+ message: `Please enter the region you would like to work in (${regionsPrefixList}) - if not set, default is eu:`,
13
15
  validate: function (value) {
14
- const flagList = ['us', 'cn', 'eu']
15
- if (flagList.indexOf(value) > -1) {
16
+ if (regionsPrefixList.indexOf(value) > -1) {
16
17
  return true
17
18
  }
18
19
 
19
- return 'Please enter a valid region: us, eu or cn'
20
+ return `Please enter a valid region: ${regionsPrefixList}`
20
21
  }
21
22
  }
22
23
 
@@ -1,11 +1,6 @@
1
1
  const { listSpaces } = require('../../src/tasks/')
2
2
  const { FAKE_SPACES } = require('../constants')
3
-
4
- const REGION_FLAGS = {
5
- UNITED_STATES: 'us',
6
- EUROPE: 'eu',
7
- CHINA: 'cn'
8
- }
3
+ const { REGIONS } = require('../../src/constants')
9
4
 
10
5
  describe('Test spaces method', () => {
11
6
  it('Testing list-spaces funtion without api instance', async () => {
@@ -22,28 +17,36 @@ describe('Test spaces method', () => {
22
17
  getAllSpacesByRegion: jest.fn(() => Promise.resolve(FAKE_SPACES()))
23
18
  }
24
19
  expect(
25
- await listSpaces(FAKE_API, REGION_FLAGS.CHINA)
20
+ await listSpaces(FAKE_API, REGIONS.cn.key)
26
21
  ).toEqual(FAKE_SPACES())
27
22
  expect(FAKE_API.getAllSpacesByRegion).toHaveBeenCalled()
28
23
  })
29
24
 
30
- it('Testing list-spaces funtion for Europe and United States regions', async () => {
25
+ it('Testing list-spaces funtion for all regions', async () => {
31
26
  const FAKE_API = {
32
27
  getAllSpacesByRegion: jest.fn(() => Promise.resolve(FAKE_SPACES()))
33
28
  }
34
29
  const response = [
35
30
  {
36
- key: REGION_FLAGS.EUROPE,
31
+ key: REGIONS.eu.key,
32
+ res: [...FAKE_SPACES()]
33
+ },
34
+ {
35
+ key: REGIONS.us.key,
36
+ res: [...FAKE_SPACES()]
37
+ },
38
+ {
39
+ key: REGIONS.ca.key,
37
40
  res: [...FAKE_SPACES()]
38
41
  },
39
42
  {
40
- key: REGION_FLAGS.UNITED_STATES,
43
+ key: REGIONS.ap.key,
41
44
  res: [...FAKE_SPACES()]
42
45
  }
43
46
  ]
44
47
 
45
48
  expect(
46
- await listSpaces(FAKE_API, REGION_FLAGS.EUROPE)
49
+ await listSpaces(FAKE_API, REGIONS.eu.key)
47
50
  ).toEqual(response)
48
51
  })
49
52
  })
@@ -1,7 +1,7 @@
1
1
  const pushComponents = require('../../src/tasks/push-components')
2
2
  const Storyblok = require('storyblok-js-client')
3
3
  const api = require('../../src/utils/api')
4
- const { API_URL } = require('../../src/constants')
4
+ const { REGIONS } = require('../../src/constants')
5
5
 
6
6
  jest.mock('fs')
7
7
  jest.unmock('axios')
@@ -10,7 +10,7 @@ const deleteDocComponent = async () => {
10
10
  if (process.env.STORYBLOK_TOKEN) {
11
11
  const client = new Storyblok({
12
12
  oauthToken: process.env.STORYBLOK_TOKEN
13
- }, API_URL)
13
+ }, REGIONS.eu.apiEndpoint)
14
14
 
15
15
  try {
16
16
  const path = `spaces/${process.env.STORYBLOK_SPACE}/components`
@@ -4,7 +4,7 @@ const path = require('path')
4
4
  const quickstart = require('../../src/tasks/quickstart')
5
5
  const Storyblok = require('storyblok-js-client')
6
6
  const api = require('../../src/utils/api')
7
- const { API_URL } = require('../../src/constants')
7
+ const { REGIONS } = require('../../src/constants')
8
8
 
9
9
  jest.unmock('fs')
10
10
  jest.unmock('axios')
@@ -60,7 +60,7 @@ describe('testing quickstart()', () => {
60
60
 
61
61
  const client = new Storyblok({
62
62
  oauthToken: process.env.STORYBLOK_TOKEN
63
- }, API_URL)
63
+ }, REGIONS.eu.apiEndpoint)
64
64
 
65
65
  const response = await client.get('spaces')
66
66
  const spaces = response.data.spaces
@@ -3,7 +3,7 @@ const fs = require('fs')
3
3
  const scaffold = require('../../src/tasks/scaffold')
4
4
  const Storyblok = require('storyblok-js-client')
5
5
  const api = require('../../src/utils/api')
6
- const { API_URL } = require('../../src/constants')
6
+ const { REGIONS } = require('../../src/constants')
7
7
 
8
8
  jest.mock('fs')
9
9
  jest.unmock('axios')
@@ -12,7 +12,7 @@ const deleteTestComponent = async () => {
12
12
  if (process.env.STORYBLOK_TOKEN) {
13
13
  const client = new Storyblok({
14
14
  oauthToken: process.env.STORYBLOK_TOKEN
15
- }, API_URL)
15
+ }, REGIONS.eu.apiEndpoint)
16
16
 
17
17
  try {
18
18
  const path = `spaces/${process.env.STORYBLOK_SPACE}/components`
@@ -1,6 +1,6 @@
1
1
  const sync = require('../../src/tasks/sync')
2
2
  const Storyblok = require('storyblok-js-client')
3
- const { API_URL } = require('../../src/constants')
3
+ const { REGIONS } = require('../../src/constants')
4
4
 
5
5
  jest.unmock('axios')
6
6
 
@@ -32,7 +32,7 @@ describe('testing sync function', () => {
32
32
 
33
33
  const client = new Storyblok({
34
34
  oauthToken: process.env.STORYBLOK_TOKEN
35
- }, API_URL)
35
+ }, REGIONS.eu.apiEndpoint)
36
36
 
37
37
  const sourceStories = await getData(
38
38
  client,