storyblok 3.24.1 → 3.25.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 +0 -12
- package/package.json +2 -2
- package/src/cli.js +5 -18
- package/src/constants.js +7 -1
- package/src/tasks/sync.js +1 -6
- package/src/utils/api.js +9 -3
- package/src/utils/index.js +1 -2
- package/src/utils/build-filter-query.js +0 -23
package/README.md
CHANGED
|
@@ -247,10 +247,6 @@ $ storyblok sync --type <COMMAND> --source <SPACE_ID> --target <SPACE_ID>
|
|
|
247
247
|
* `type`: describe the command type to execute. Can be: `folders`, `components`, `stories`, `datasources` or `roles`. It's possible pass multiple types separated by comma (`,`).
|
|
248
248
|
* `source`: the source space to use to sync
|
|
249
249
|
* `target`: the target space to use to sync
|
|
250
|
-
* `starts-with`: sync only stories that starts with the given string
|
|
251
|
-
* `filter`: sync stories based on the given filter. Required Options: Required options: `--keys`, `--operations`, `--values`
|
|
252
|
-
* `keys`: Multiple keys should be separated by comma. Example: `--keys key1,key2`, `--keys key1`
|
|
253
|
-
* `operations`: Operations to be used for filtering. Can be: `is`, `in`, `not_in`, `like`, `not_like`, `any_in_array`, `all_in_array`, `gt_date`, `lt_date`, `gt_int`, `lt_int`, `gt_float`, `lt_float`. Multiple operations should be separated by comma.
|
|
254
250
|
|
|
255
251
|
#### Examples
|
|
256
252
|
|
|
@@ -261,14 +257,6 @@ $ storyblok sync --type components --source 00001 --target 00002
|
|
|
261
257
|
# Sync components and stories from `00001` space to `00002` space
|
|
262
258
|
$ storyblok sync --type components,stories --source 00001 --target 00002
|
|
263
259
|
|
|
264
|
-
# Sync only stories that starts with `myStartsWithString` from `00001` space to `00002` space
|
|
265
|
-
$ storyblok sync --type stories --source 00001 --target 00002 --starts-with myStartsWithString
|
|
266
|
-
|
|
267
|
-
# Sync only stories with a category field like `reference` from `00001` space to `00002` space
|
|
268
|
-
$ storyblok sync --type stories --source 00001 --target 00002 --filter --keys category --operations like --values reference
|
|
269
|
-
|
|
270
|
-
# Sync only stories with a category field like `reference` and a name field not like `demo` from `00001` space to `00002` space
|
|
271
|
-
$ storyblok sync --type stories --source 00001 --target 00002 --filter --keys category,name --operations like,not_like --values reference,demo
|
|
272
260
|
```
|
|
273
261
|
|
|
274
262
|
### quickstart
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "storyblok",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.25.0",
|
|
4
4
|
"description": "A simple CLI to start Storyblok from your command line.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"p-series": "^2.1.0",
|
|
43
43
|
"path": "^0.12.7",
|
|
44
44
|
"simple-uuid": "^0.0.1",
|
|
45
|
-
"storyblok-js-client": "^
|
|
45
|
+
"storyblok-js-client": "^5.12.0",
|
|
46
46
|
"update-notifier": "^5.1.0",
|
|
47
47
|
"xml-js": "^1.6.11"
|
|
48
48
|
},
|
package/src/cli.js
CHANGED
|
@@ -12,7 +12,7 @@ const updateNotifier = require('update-notifier')
|
|
|
12
12
|
const pkg = require('../package.json')
|
|
13
13
|
|
|
14
14
|
const tasks = require('./tasks')
|
|
15
|
-
const { getQuestions, lastStep, api, creds
|
|
15
|
+
const { getQuestions, lastStep, api, creds } = require('./utils')
|
|
16
16
|
const { SYNC_TYPES, COMMANDS } = require('./constants')
|
|
17
17
|
|
|
18
18
|
clear()
|
|
@@ -271,11 +271,6 @@ program
|
|
|
271
271
|
.requiredOption('--type <TYPE>', 'Define what will be sync. Can be components, folders, stories, datasources or roles')
|
|
272
272
|
.requiredOption('--source <SPACE_ID>', 'Source space id')
|
|
273
273
|
.requiredOption('--target <SPACE_ID>', 'Target space id')
|
|
274
|
-
.option('--starts-with <STARTS_WITH>', 'Sync only stories that starts with the given string')
|
|
275
|
-
.option('--filter', 'Enable filter options to sync only stories that match the given filter. Required options: --keys; --operations; --values')
|
|
276
|
-
.option('--keys <KEYS>', 'Field names in your story object which should be used for filtering. Multiple keys should separated by comma.')
|
|
277
|
-
.option('--operations <OPERATIONS>', 'Operations to be used for filtering. Can be: is, in, not_in, like, not_like, any_in_array, all_in_array, gt_date, lt_date, gt_int, lt_int, gt_float, lt_float. Multiple operations should be separated by comma.')
|
|
278
|
-
.option('--values <VALUES>', 'Values to be used for filtering. Any string or number. If you want to use multiple values, separate them with a comma. Multiple values should be separated by comma.')
|
|
279
274
|
.option('--components-groups <UUIDs>', 'Synchronize components based on their group UUIDs separated by commas')
|
|
280
275
|
.action(async (options) => {
|
|
281
276
|
console.log(`${chalk.blue('-')} Sync data between spaces\n`)
|
|
@@ -287,18 +282,15 @@ program
|
|
|
287
282
|
|
|
288
283
|
const {
|
|
289
284
|
type,
|
|
290
|
-
source,
|
|
291
285
|
target,
|
|
292
|
-
|
|
293
|
-
filter,
|
|
294
|
-
keys,
|
|
295
|
-
operations,
|
|
296
|
-
values,
|
|
286
|
+
source,
|
|
297
287
|
componentsGroups
|
|
298
288
|
} = options
|
|
299
289
|
|
|
300
290
|
const _componentsGroups = componentsGroups ? componentsGroups.split(',') : null
|
|
301
291
|
|
|
292
|
+
const token = creds.get().token || null
|
|
293
|
+
|
|
302
294
|
const _types = type.split(',') || []
|
|
303
295
|
_types.forEach(_type => {
|
|
304
296
|
if (!SYNC_TYPES.includes(_type)) {
|
|
@@ -306,16 +298,11 @@ program
|
|
|
306
298
|
}
|
|
307
299
|
})
|
|
308
300
|
|
|
309
|
-
const filterQuery = filter ? buildFilterQuery(keys, operations, values) : undefined
|
|
310
|
-
|
|
311
|
-
const token = creds.get().token || null
|
|
312
301
|
await tasks.sync(_types, {
|
|
313
302
|
api,
|
|
314
303
|
token,
|
|
315
|
-
source,
|
|
316
304
|
target,
|
|
317
|
-
|
|
318
|
-
filterQuery,
|
|
305
|
+
source,
|
|
319
306
|
_componentsGroups
|
|
320
307
|
})
|
|
321
308
|
|
package/src/constants.js
CHANGED
|
@@ -28,6 +28,11 @@ const COMMANDS = {
|
|
|
28
28
|
SYNC: 'sync'
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
const DEFAULT_AGENT = {
|
|
32
|
+
SB_Agent: 'SB-CLI',
|
|
33
|
+
SB_Agent_Version: process.env.npm_package_version || '3.0.0'
|
|
34
|
+
}
|
|
35
|
+
|
|
31
36
|
module.exports = {
|
|
32
37
|
LOGIN_URL,
|
|
33
38
|
SIGNUP_URL,
|
|
@@ -35,5 +40,6 @@ module.exports = {
|
|
|
35
40
|
SYNC_TYPES,
|
|
36
41
|
US_API_URL,
|
|
37
42
|
CN_API_URL,
|
|
38
|
-
COMMANDS
|
|
43
|
+
COMMANDS,
|
|
44
|
+
DEFAULT_AGENT
|
|
39
45
|
}
|
package/src/tasks/sync.js
CHANGED
|
@@ -3,7 +3,6 @@ const chalk = require('chalk')
|
|
|
3
3
|
const SyncComponents = require('./sync-commands/components')
|
|
4
4
|
const SyncDatasources = require('./sync-commands/datasources')
|
|
5
5
|
const { capitalize } = require('../utils')
|
|
6
|
-
const { startsWith } = require('lodash/string')
|
|
7
6
|
|
|
8
7
|
const SyncSpaces = {
|
|
9
8
|
targetComponents: [],
|
|
@@ -15,8 +14,6 @@ const SyncSpaces = {
|
|
|
15
14
|
this.sourceSpaceId = options.source
|
|
16
15
|
this.targetSpaceId = options.target
|
|
17
16
|
this.oauthToken = options.token
|
|
18
|
-
this.startsWith = options.startsWith
|
|
19
|
-
this.filterQuery = options.filterQuery
|
|
20
17
|
this.client = api.getClient()
|
|
21
18
|
this.componentsGroups = options._componentsGroups
|
|
22
19
|
},
|
|
@@ -60,9 +57,7 @@ const SyncSpaces = {
|
|
|
60
57
|
}
|
|
61
58
|
|
|
62
59
|
const all = await this.client.getAll(`spaces/${this.sourceSpaceId}/stories`, {
|
|
63
|
-
story_only: 1
|
|
64
|
-
...(this.startsWith ? { starts_with: this.startsWith } : {}),
|
|
65
|
-
...(this.filterQuery ? { filter_query: this.filterQuery } : {})
|
|
60
|
+
story_only: 1
|
|
66
61
|
})
|
|
67
62
|
|
|
68
63
|
for (let i = 0; i < all.length; i++) {
|
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 } = require('../constants')
|
|
8
|
+
const { SIGNUP_URL, API_URL, US_API_URL, CN_API_URL, DEFAULT_AGENT } = require('../constants')
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
11
|
accessToken: '',
|
|
@@ -20,7 +20,10 @@ module.exports = {
|
|
|
20
20
|
return new Storyblok({
|
|
21
21
|
accessToken: this.accessToken,
|
|
22
22
|
oauthToken: this.oauthToken,
|
|
23
|
-
region: this.region
|
|
23
|
+
region: this.region,
|
|
24
|
+
headers: {
|
|
25
|
+
...DEFAULT_AGENT
|
|
26
|
+
}
|
|
24
27
|
}, this.apiSwitcher(region))
|
|
25
28
|
} catch (error) {
|
|
26
29
|
throw new Error(error)
|
|
@@ -277,7 +280,10 @@ module.exports = {
|
|
|
277
280
|
const customClient = new Storyblok({
|
|
278
281
|
accessToken: this.accessToken,
|
|
279
282
|
oauthToken: this.oauthToken,
|
|
280
|
-
region
|
|
283
|
+
region,
|
|
284
|
+
headers: {
|
|
285
|
+
...DEFAULT_AGENT
|
|
286
|
+
}
|
|
281
287
|
}, this.apiSwitcher(region))
|
|
282
288
|
return await customClient
|
|
283
289
|
.get('spaces/', {})
|
package/src/utils/index.js
CHANGED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const buildFilterQuery = (keys, operations, values) => {
|
|
2
|
-
const operators = ['is', 'in', 'not_in', 'like', 'not_like', 'any_in_array', 'all_in_array', 'gt_date', 'lt_date', 'gt_int', 'lt_int', 'gt_float', 'lt_float']
|
|
3
|
-
if (!keys || !operations || !values) {
|
|
4
|
-
throw new Error('Filter options are required: --keys; --operations; --values')
|
|
5
|
-
}
|
|
6
|
-
const _keys = keys.split(',')
|
|
7
|
-
const _operations = operations.split(',')
|
|
8
|
-
const _values = values.split(',')
|
|
9
|
-
if (_keys.length !== _operations.length || _keys.length !== _values.length) {
|
|
10
|
-
throw new Error('The number of keys, operations and values must be the same')
|
|
11
|
-
}
|
|
12
|
-
const invalidOperators = _operations.filter((o) => !operators.includes(o))
|
|
13
|
-
if (invalidOperators.length) {
|
|
14
|
-
throw new Error('Invalid operator(s) applied for filter: ' + invalidOperators.join(' '))
|
|
15
|
-
}
|
|
16
|
-
const filterQuery = {}
|
|
17
|
-
_keys.forEach((key, index) => {
|
|
18
|
-
filterQuery[key] = { [_operations[index]]: _values[index] }
|
|
19
|
-
})
|
|
20
|
-
return filterQuery
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = buildFilterQuery
|