@parsable/plugin-author-cli 1.1.1
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 +405 -0
- package/bin/run +5 -0
- package/bin/run.cmd +3 -0
- package/oclif.manifest.json +1 -0
- package/package.json +67 -0
- package/src/commands/base.js +38 -0
- package/src/commands/exec-data/delete.js +161 -0
- package/src/commands/jobs/create.js +100 -0
- package/src/commands/jobs/delete.js +97 -0
- package/src/commands/template/copy/status.js +66 -0
- package/src/commands/template/copy.js +191 -0
- package/src/config/index.js +40 -0
- package/src/index.js +1 -0
- package/src/services/client/admin.js +81 -0
- package/src/services/client/copy-template-status-client-fn.js +18 -0
- package/src/services/client/create-template-client-fn.js +19 -0
- package/src/services/client/field-data.js +29 -0
- package/src/services/client/helpers/create-user-agent-header.js +13 -0
- package/src/services/client/helpers/create-wi-platform-header.js +3 -0
- package/src/services/client/index.js +11 -0
- package/src/services/client/mothership-client-fn.js +15 -0
- package/src/services/exec-data/delete-fn.js +41 -0
- package/src/services/exec-data/index.js +9 -0
- package/src/services/helpers/convert-kebab-case-to-camel-case.js +6 -0
- package/src/services/helpers/custom-exception.js +12 -0
- package/src/services/helpers/delay-resolve.js +8 -0
- package/src/services/helpers/serial-async-csv-reader.js +53 -0
- package/src/services/jobs/create-fn.js +106 -0
- package/src/services/jobs/delete-fn.js +175 -0
- package/src/services/jobs/index.js +11 -0
- package/src/services/render/helper/std-err-log.js +4 -0
- package/src/services/render/helper/translations.js +107 -0
- package/src/services/render/index.js +15 -0
- package/src/services/render/render-copy-template-success-fn.js +22 -0
- package/src/services/render/render-exception-fn.js +37 -0
- package/src/services/render/render-statuses-fn.js +51 -0
- package/src/services/template_copy/create-lambda-payload.js +36 -0
- package/src/services/template_copy/get-auth-token-fn.js +33 -0
- package/src/services/template_copy/get-config-from-path.js +13 -0
- package/src/services/template_copy/getConfigFromFlagsAndPrompts/convert-inputs-to-config-format.js +9 -0
- package/src/services/template_copy/getConfigFromFlagsAndPrompts/create-questions-for-prompt.js +129 -0
- package/src/services/template_copy/getConfigFromFlagsAndPrompts/find-missing-required-flags.js +30 -0
- package/src/services/template_copy/getConfigFromFlagsAndPrompts/index.js +24 -0
- package/src/services/template_copy/helpers/config-json.schema.js +79 -0
- package/src/services/template_copy/helpers/config-to-payload.map.js +37 -0
- package/src/services/template_copy/helpers/prompt-to-config.map.js +64 -0
- package/src/services/template_copy/index.js +21 -0
- package/src/services/template_copy/send-copy-template-request-fn.js +21 -0
- package/src/services/template_copy/validate-config-json-fn.js +19 -0
- package/src/services/template_status/get-status-fn.js +30 -0
- package/src/services/template_status/index.js +11 -0
- package/src/services/template_status/prompt.js +34 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// title, description, and suggestion fields are required
|
|
2
|
+
module.exports = {
|
|
3
|
+
LOGIN_REQUEST_FAILED: {
|
|
4
|
+
title({email, apiBase}) {
|
|
5
|
+
return `Failed to get auth token for ${email} from ${apiBase}!`
|
|
6
|
+
},
|
|
7
|
+
description({cause}) {
|
|
8
|
+
return `${cause}`
|
|
9
|
+
},
|
|
10
|
+
suggestion() {
|
|
11
|
+
return ['Try again.']
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
LOGIN_FAILED: {
|
|
15
|
+
title({email, apiBase}) {
|
|
16
|
+
return `Failed to get auth token for ${email} from ${apiBase}!`
|
|
17
|
+
},
|
|
18
|
+
description({body}) {
|
|
19
|
+
return `${JSON.stringify(body, null, 2)}`
|
|
20
|
+
},
|
|
21
|
+
suggestion() {
|
|
22
|
+
return ['Check that your email, password, and apiBase are correct for source and destination!']
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
COPY_REQUEST_FAILED: {
|
|
26
|
+
title() {
|
|
27
|
+
return 'Copy template request failed!'
|
|
28
|
+
},
|
|
29
|
+
description({cause}) {
|
|
30
|
+
return `${JSON.stringify(cause.response.body, null, 2)}`
|
|
31
|
+
},
|
|
32
|
+
suggestion() {
|
|
33
|
+
return []
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
COPY_FAILED: {
|
|
37
|
+
title() {
|
|
38
|
+
return 'Copy template failed!'
|
|
39
|
+
},
|
|
40
|
+
description({cause}) {
|
|
41
|
+
return `${JSON.stringify(cause.response.body, null, 2)}`
|
|
42
|
+
},
|
|
43
|
+
suggestion() {
|
|
44
|
+
return []
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
FAIL_CONFIG_VALIDATION: {
|
|
48
|
+
title() {
|
|
49
|
+
return 'Config failed validation!'
|
|
50
|
+
},
|
|
51
|
+
description({errors}) {
|
|
52
|
+
return `Validation errors:
|
|
53
|
+
${JSON.stringify(errors, null, 2)}`
|
|
54
|
+
},
|
|
55
|
+
suggestion() {
|
|
56
|
+
return ['parsable-cli help template:copy']
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
NO_SUCH_CONFIG_FILE: {
|
|
60
|
+
title({cause}) {
|
|
61
|
+
return cause
|
|
62
|
+
},
|
|
63
|
+
description() {
|
|
64
|
+
return ''
|
|
65
|
+
},
|
|
66
|
+
suggestion({path}) {
|
|
67
|
+
return [`Check the config file lives at ${path}.`]
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
STATUS_REQUEST_FAILED: {
|
|
71
|
+
title({statusReportId, templateId}) {
|
|
72
|
+
const details = statusReportId ? `status_report_id:${statusReportId}` : `template_id:${templateId}`
|
|
73
|
+
return `Failed to get statuses for ${details}!`
|
|
74
|
+
},
|
|
75
|
+
description({cause}) {
|
|
76
|
+
return `${JSON.stringify(cause.response.body, null, 2)}`
|
|
77
|
+
},
|
|
78
|
+
suggestion() {
|
|
79
|
+
return ['Try again.']
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
NO_STATUSES_FOUND: {
|
|
83
|
+
title({statusReportId, templateId}) {
|
|
84
|
+
const details = statusReportId ? `status_report_id:${statusReportId}` : `template_id:${templateId}`
|
|
85
|
+
return `No statuses found for ${details}!`
|
|
86
|
+
},
|
|
87
|
+
description() {
|
|
88
|
+
return ''
|
|
89
|
+
},
|
|
90
|
+
suggestion({statusReportId, templateId}) {
|
|
91
|
+
const details = statusReportId ? `status_report_id:${statusReportId}` : `template_id:${templateId}`
|
|
92
|
+
|
|
93
|
+
return [`Check that ${details} is correct.`, 'Wait a bit. Maybe the copying process has yet to start.']
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
EXEC_DATA_DELETE_REQUEST_FAILED: {
|
|
97
|
+
title({cause}) {
|
|
98
|
+
return cause
|
|
99
|
+
},
|
|
100
|
+
description({fieldId, jobBaseStepId}) {
|
|
101
|
+
return `error deleting execution data for fieldId=${fieldId} jobBaseStepId=${jobBaseStepId}:`
|
|
102
|
+
},
|
|
103
|
+
suggestion() {
|
|
104
|
+
return ['Confirm parameters are valid and try again']
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const renderExceptionFn = require('./render-exception-fn.js')
|
|
2
|
+
const renderStatusesFn = require('./render-statuses-fn.js')
|
|
3
|
+
const renderCopyTemplateSuccessFn = require('./render-copy-template-success-fn.js')
|
|
4
|
+
|
|
5
|
+
module.exports = function (deps) {
|
|
6
|
+
const renderException = renderExceptionFn(deps)
|
|
7
|
+
const renderStatuses = renderStatusesFn(deps)
|
|
8
|
+
const renderCopyTemplateSuccess = renderCopyTemplateSuccessFn(deps)
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
renderException,
|
|
12
|
+
renderStatuses,
|
|
13
|
+
renderCopyTemplateSuccess,
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const {cli} = require('cli-ux')
|
|
2
|
+
|
|
3
|
+
const stderrLog = require('./helper/std-err-log.js')
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param dynamodb_response {Count: <int>, Items: [{}], ScannedCount: <int>}
|
|
7
|
+
* @param flags
|
|
8
|
+
*/
|
|
9
|
+
module.exports = function ({flags = {}}) {
|
|
10
|
+
return function (statusReportId) {
|
|
11
|
+
stderrLog('')
|
|
12
|
+
cli.table([
|
|
13
|
+
{statusReportId},
|
|
14
|
+
], {statusReportId: {
|
|
15
|
+
header: 'Status Report ID',
|
|
16
|
+
}}, flags)
|
|
17
|
+
stderrLog('')
|
|
18
|
+
stderrLog('Command to view status of copy template request:')
|
|
19
|
+
stderrLog(`parsable-cli template:copy:status --status-report-id ${statusReportId}`)
|
|
20
|
+
stderrLog('')
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const {cli} = require('cli-ux')
|
|
2
|
+
|
|
3
|
+
const translations = require('./helper/translations.js')
|
|
4
|
+
|
|
5
|
+
module.exports = function () {
|
|
6
|
+
return function (customException) {
|
|
7
|
+
const translatedError = translations[customException.message]
|
|
8
|
+
|
|
9
|
+
if (translatedError) {
|
|
10
|
+
const exceptionContent = {...customException.info, cause: customException.cause}
|
|
11
|
+
const errorInput = createErrorInput(exceptionContent, translatedError)
|
|
12
|
+
|
|
13
|
+
cli.error(
|
|
14
|
+
errorInput
|
|
15
|
+
, {
|
|
16
|
+
exit: false,
|
|
17
|
+
code: customException.message,
|
|
18
|
+
suggestions: translatedError.suggestion(exceptionContent),
|
|
19
|
+
},
|
|
20
|
+
)
|
|
21
|
+
} else {
|
|
22
|
+
cli.error(customException, {exit: false})
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Helper Function
|
|
28
|
+
function createErrorInput(exceptionContent, errorTranslation) {
|
|
29
|
+
const errorDescriptionFn = errorTranslation.description
|
|
30
|
+
const errorTitle = errorTranslation.title(exceptionContent)
|
|
31
|
+
const errorDescription = errorDescriptionFn ? errorDescriptionFn(exceptionContent) : ''
|
|
32
|
+
|
|
33
|
+
if (errorDescription) {
|
|
34
|
+
return `${errorTitle}\n${errorDescription}`
|
|
35
|
+
}
|
|
36
|
+
return `${errorTitle}`
|
|
37
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const {cli} = require('cli-ux')
|
|
2
|
+
const _get = require('lodash/get')
|
|
3
|
+
const _mapValues = require('lodash/mapValues')
|
|
4
|
+
|
|
5
|
+
const stderrLog = require('./helper/std-err-log.js')
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param dynamodb_response {Count: <int>, Items: [{}], ScannedCount: <int>}
|
|
9
|
+
* @param flags
|
|
10
|
+
*/
|
|
11
|
+
module.exports = function ({flags = {}}) {
|
|
12
|
+
return function (dynamodbResponse) {
|
|
13
|
+
const items = _get(dynamodbResponse, 'Items', [])
|
|
14
|
+
const data = items.map(item => {
|
|
15
|
+
return _mapValues(item, val => {
|
|
16
|
+
return val.M ? val.M : val.S
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
// NOTE: if the columns change be sure to update the docs in status.js!
|
|
21
|
+
stderrLog('')
|
|
22
|
+
cli.table(data, {
|
|
23
|
+
// eslint-disable-next-line camelcase
|
|
24
|
+
template_id: {
|
|
25
|
+
header: 'Template ID',
|
|
26
|
+
},
|
|
27
|
+
status: {
|
|
28
|
+
header: 'Status',
|
|
29
|
+
},
|
|
30
|
+
result: {
|
|
31
|
+
header: 'Result',
|
|
32
|
+
},
|
|
33
|
+
// eslint-disable-next-line camelcase
|
|
34
|
+
start_timestamp: {
|
|
35
|
+
header: 'Start Timestamp',
|
|
36
|
+
},
|
|
37
|
+
// eslint-disable-next-line camelcase
|
|
38
|
+
end_timestamp: {
|
|
39
|
+
header: 'End Timestamp',
|
|
40
|
+
},
|
|
41
|
+
// eslint-disable-next-line camelcase
|
|
42
|
+
src_team_id: {
|
|
43
|
+
header: 'Source Team ID',
|
|
44
|
+
},
|
|
45
|
+
// eslint-disable-next-line camelcase
|
|
46
|
+
dest_team_id: {
|
|
47
|
+
header: 'Destination Team ID',
|
|
48
|
+
},
|
|
49
|
+
}, flags)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const objectMapper = require('object-mapper')
|
|
2
|
+
|
|
3
|
+
const configToPayloadMap = require('./helpers/config-to-payload.map.js')
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Payload to lambda should look like this:
|
|
7
|
+
* {
|
|
8
|
+
* "templateIds": ["b15c6cf5-4a0a-4978-9ddd-5a1e8459e587"],
|
|
9
|
+
* "include_template_procedure_types": false,
|
|
10
|
+
* "include_template_input_triggers": true,
|
|
11
|
+
* "include_template_applets": false,
|
|
12
|
+
* "include_template_refsheets": true,
|
|
13
|
+
* "include_metadata_values": false,
|
|
14
|
+
* "src_teamId": "3b26ee9a-dc67-42c8-b4a4-b273c1fd6260",
|
|
15
|
+
* "src_auth_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1OTM4ODIwNzcsImlhdCI6MTU5MTI5MDA3NywiaXNzIjoiYXV0aDpwcm9kdWN0aW9uIiwic2VyYTpzaWQiOiIwZmQ2OWNkYy1lOTQ1LTRlNzUtYWMwOS0zMWQ3MjAzOTk5NWQiLCJzZXJhOnRlYW1JZCI6IiIsInNlcmE6dHlwIjoiYXV0aCIsInN1YiI6IjNkN2Y4NWZhLThhNGMtNDMxMC05YzM4LTQyN2RiYjRkYzg3MyJ9.UQHj-nbrmrZul9ZGk02hWaxYlkvfDICwZ7mmd-3eBZQ",
|
|
16
|
+
* "src_apiBase": "https://api.us-west-2.parsable.net:443",
|
|
17
|
+
* "destTeamId": "6e67e9f1-0793-4c1d-931a-696f16076659",
|
|
18
|
+
* "dest_auth_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1OTM4ODIwNzcsImlhdCI6MTU5MTI5MDA3NywiaXNzIjoiYXV0aDpwcm9kdWN0aW9uIiwic2VyYTpzaWQiOiIwZmQ2OWNkYy1lOTQ1LTRlNzUtYWMwOS0zMWQ3MjAzOTk5NWQiLCJzZXJhOnRlYW1JZCI6IiIsInNlcmE6dHlwIjoiYXV0aCIsInN1YiI6IjNkN2Y4NWZhLThhNGMtNDMxMC05YzM4LTQyN2RiYjRkYzg3MyJ9.UQHj-nbrmrZul9ZGk02hWaxYlkvfDICwZ7mmd-3eBZQ",
|
|
19
|
+
* "destApiBase": "https://api.us-west-2.parsable.net:443"
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* @param config
|
|
23
|
+
* @param sourceAuthToken
|
|
24
|
+
* @param destAuthToken
|
|
25
|
+
* @returns {Promise<*>}
|
|
26
|
+
*/
|
|
27
|
+
module.exports = function ({config, sourceAuthToken, destAuthToken}) {
|
|
28
|
+
const prePayload = {...config, sourceAuthToken, destAuthToken}
|
|
29
|
+
|
|
30
|
+
let payload = {
|
|
31
|
+
// eslint-disable-next-line camelcase
|
|
32
|
+
include_template_refsheets: true, // not configurable
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return objectMapper.merge(prePayload, payload, configToPayloadMap)
|
|
36
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const _get = require('lodash/get')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
|
|
4
|
+
const CustomException = require('../helpers/custom-exception.js')
|
|
5
|
+
|
|
6
|
+
module.exports = function ({mothershipClient}) {
|
|
7
|
+
return async function ({email, password, apiBase}) {
|
|
8
|
+
const payload = {
|
|
9
|
+
method: 'login',
|
|
10
|
+
arguments: {
|
|
11
|
+
email,
|
|
12
|
+
password,
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const url = path.join(apiBase, 'api', 'auth')
|
|
17
|
+
|
|
18
|
+
let response
|
|
19
|
+
try {
|
|
20
|
+
response = await mothershipClient.post(url, {
|
|
21
|
+
json: payload,
|
|
22
|
+
})
|
|
23
|
+
} catch (error) {
|
|
24
|
+
throw new CustomException({name: 'LOGIN_REQUEST_FAILED', cause: error, info: {email, apiBase}})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const authToken = _get(response, ['body', 'result', 'success', 'authToken'])
|
|
28
|
+
if (!authToken) {
|
|
29
|
+
throw new CustomException({name: 'LOGIN_FAILED', info: {email, apiBase, body: response.body}})
|
|
30
|
+
}
|
|
31
|
+
return authToken
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const fs = require('fs').promises
|
|
2
|
+
|
|
3
|
+
const CustomException = require('../helpers/custom-exception.js')
|
|
4
|
+
|
|
5
|
+
module.exports = async function ({configPath}) {
|
|
6
|
+
let file
|
|
7
|
+
try {
|
|
8
|
+
file = await fs.readFile(configPath)
|
|
9
|
+
} catch (error) {
|
|
10
|
+
throw new CustomException({name: 'NO_SUCH_CONFIG_FILE', cause: error, info: {path: configPath}})
|
|
11
|
+
}
|
|
12
|
+
return JSON.parse(file.toString())
|
|
13
|
+
}
|
package/src/services/template_copy/getConfigFromFlagsAndPrompts/convert-inputs-to-config-format.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const objectMapper = require('object-mapper')
|
|
2
|
+
const extend = require('deep-extend')
|
|
3
|
+
|
|
4
|
+
const promptToConfig = require('../helpers/prompt-to-config.map.js')
|
|
5
|
+
|
|
6
|
+
module.exports = function ({passedInFlags, answers}) {
|
|
7
|
+
const final = extend({}, passedInFlags, answers)
|
|
8
|
+
return objectMapper(final, promptToConfig)
|
|
9
|
+
}
|
package/src/services/template_copy/getConfigFromFlagsAndPrompts/create-questions-for-prompt.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
const _map = require('lodash/map')
|
|
2
|
+
const _get = require('lodash/get')
|
|
3
|
+
|
|
4
|
+
module.exports = function ({missingRequiredFlagNames, defaultApiBase}) {
|
|
5
|
+
const questions = {
|
|
6
|
+
'template-ids': {
|
|
7
|
+
name: 'template-ids',
|
|
8
|
+
message: 'Template ids from source team to copy (comma-separated):',
|
|
9
|
+
validate: answer => {
|
|
10
|
+
return Boolean(answer)
|
|
11
|
+
},
|
|
12
|
+
type: 'input',
|
|
13
|
+
},
|
|
14
|
+
'reference-sheet-set-ids': {
|
|
15
|
+
name: 'reference-sheet-set-ids',
|
|
16
|
+
message: 'Reference sheet set ids from source team to copy (comma-separated):',
|
|
17
|
+
type: 'input',
|
|
18
|
+
default: '',
|
|
19
|
+
},
|
|
20
|
+
'src-team-id': {
|
|
21
|
+
name: 'src-team-id',
|
|
22
|
+
message: 'Source team id of template(s) to copy from:',
|
|
23
|
+
validate: answer => {
|
|
24
|
+
return Boolean(answer)
|
|
25
|
+
},
|
|
26
|
+
type: 'input',
|
|
27
|
+
},
|
|
28
|
+
'src-email': {
|
|
29
|
+
name: 'src-email',
|
|
30
|
+
message: 'Email of admin user in the source team:',
|
|
31
|
+
validate: answer => {
|
|
32
|
+
return Boolean(answer)
|
|
33
|
+
},
|
|
34
|
+
type: 'input',
|
|
35
|
+
},
|
|
36
|
+
'src-password': {
|
|
37
|
+
name: 'src-password',
|
|
38
|
+
message: 'Password of admin user in the source team:',
|
|
39
|
+
validate: answer => {
|
|
40
|
+
return Boolean(answer)
|
|
41
|
+
},
|
|
42
|
+
type: 'password',
|
|
43
|
+
},
|
|
44
|
+
'src-api-base': {
|
|
45
|
+
name: 'src-api-base',
|
|
46
|
+
message: 'Hostname of the source team environment:',
|
|
47
|
+
validate: answer => {
|
|
48
|
+
return Boolean(answer)
|
|
49
|
+
},
|
|
50
|
+
type: 'input',
|
|
51
|
+
default: defaultApiBase,
|
|
52
|
+
},
|
|
53
|
+
'dest-team-id': {
|
|
54
|
+
name: 'dest-team-id',
|
|
55
|
+
message: 'Destination team id for templates to be copied into:',
|
|
56
|
+
validate: answer => {
|
|
57
|
+
return Boolean(answer)
|
|
58
|
+
},
|
|
59
|
+
type: 'input',
|
|
60
|
+
},
|
|
61
|
+
'dest-email': {
|
|
62
|
+
name: 'dest-email',
|
|
63
|
+
message: 'Email of admin user in the destination team:',
|
|
64
|
+
validate: answer => {
|
|
65
|
+
return Boolean(answer)
|
|
66
|
+
},
|
|
67
|
+
type: 'input',
|
|
68
|
+
},
|
|
69
|
+
'dest-password': {
|
|
70
|
+
name: 'dest-password',
|
|
71
|
+
message: 'Password of admin user in the destination team:',
|
|
72
|
+
validate: answer => {
|
|
73
|
+
return Boolean(answer)
|
|
74
|
+
},
|
|
75
|
+
type: 'password',
|
|
76
|
+
},
|
|
77
|
+
'dest-api-base': {
|
|
78
|
+
name: 'dest-api-base',
|
|
79
|
+
message: 'Hostname of the destination team environment:',
|
|
80
|
+
validate: answer => {
|
|
81
|
+
return Boolean(answer)
|
|
82
|
+
},
|
|
83
|
+
type: 'input',
|
|
84
|
+
default: defaultApiBase,
|
|
85
|
+
},
|
|
86
|
+
'should-publish-templates': {
|
|
87
|
+
name: 'should-publish-templates',
|
|
88
|
+
message: 'Publish copied template immediately:',
|
|
89
|
+
type: 'input',
|
|
90
|
+
validate: answer => {
|
|
91
|
+
return Boolean(answer)
|
|
92
|
+
},
|
|
93
|
+
default: false,
|
|
94
|
+
},
|
|
95
|
+
options: {
|
|
96
|
+
name: 'options',
|
|
97
|
+
message: 'Which template components should we copy as well?',
|
|
98
|
+
type: 'checkbox',
|
|
99
|
+
},
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return _map(missingRequiredFlagNames, flagName => {
|
|
103
|
+
if (Array.isArray(flagName)) {
|
|
104
|
+
const choices = _map(flagName, option => {
|
|
105
|
+
return {
|
|
106
|
+
name: renderOption(option),
|
|
107
|
+
value: option,
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
return {...questions.options, choices}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return questions[flagName] || {name: flagName, type: 'input'}
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Helper Function
|
|
118
|
+
/**
|
|
119
|
+
* include_input_triggers => input triggers
|
|
120
|
+
* @param option
|
|
121
|
+
* @returns {*}
|
|
122
|
+
*/
|
|
123
|
+
function renderOption(option) {
|
|
124
|
+
const renderedOption = _get(option.split('include-'), 1, '')
|
|
125
|
+
// insert a space before all caps
|
|
126
|
+
.replace(/-/g, ' ')
|
|
127
|
+
.trim()
|
|
128
|
+
return renderedOption === '' ? option : renderedOption
|
|
129
|
+
}
|
package/src/services/template_copy/getConfigFromFlagsAndPrompts/find-missing-required-flags.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const _filter = require('lodash/filter')
|
|
2
|
+
const _difference = require('lodash/difference')
|
|
3
|
+
const {cli} = require('cli-ux')
|
|
4
|
+
const _keys = require('lodash/keys')
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param passedInFlagNames
|
|
8
|
+
* @param allPossibleFlagNames
|
|
9
|
+
* @returns Array of flags names that need to be prompted.
|
|
10
|
+
*/
|
|
11
|
+
module.exports = function ({passedInFlagNames, allPossibleFlagNames}) {
|
|
12
|
+
const interactiveFlagNames = _difference(allPossibleFlagNames, ['config', 'json', ..._keys(cli.table.flags())])
|
|
13
|
+
const optionFlagNames = _filter(interactiveFlagNames, matchOptions)
|
|
14
|
+
const requiredFlagNames = _difference(interactiveFlagNames, optionFlagNames)
|
|
15
|
+
const passedInOptionFlagNames = _filter(passedInFlagNames, matchOptions)
|
|
16
|
+
const passedInRequiredFlagNames = _difference(passedInFlagNames, passedInOptionFlagNames)
|
|
17
|
+
const missingRequiredFlagNames = _difference(requiredFlagNames, passedInRequiredFlagNames)
|
|
18
|
+
|
|
19
|
+
// Prompt for which options if no option flags are passed in
|
|
20
|
+
if (passedInOptionFlagNames.length === 0) {
|
|
21
|
+
missingRequiredFlagNames.push(optionFlagNames)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return missingRequiredFlagNames
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Helper Function
|
|
28
|
+
function matchOptions(flag) {
|
|
29
|
+
return flag.match(/^include.*/)
|
|
30
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const inquirer = require('inquirer')
|
|
2
|
+
|
|
3
|
+
const findMissingRequiredFlags = require('./find-missing-required-flags.js')
|
|
4
|
+
const convertInputsToConfigFormat = require('./convert-inputs-to-config-format.js')
|
|
5
|
+
const createQuestionsForPrompt = require('./create-questions-for-prompt.js')
|
|
6
|
+
|
|
7
|
+
module.exports = async function ({passedInFlags, allPossibleFlags, defaultApiBase}) {
|
|
8
|
+
// Deal with flags/prompting
|
|
9
|
+
const allPossibleFlagNames = Object.keys(allPossibleFlags)
|
|
10
|
+
const passedInFlagNames = Object.keys(passedInFlags)
|
|
11
|
+
const missingRequiredFlagNames = findMissingRequiredFlags({passedInFlagNames, allPossibleFlagNames})
|
|
12
|
+
const questions = createQuestionsForPrompt({missingRequiredFlagNames, defaultApiBase})
|
|
13
|
+
|
|
14
|
+
// All non option flags are required
|
|
15
|
+
// if any are missing, prompt
|
|
16
|
+
let answers = {}
|
|
17
|
+
if (missingRequiredFlagNames.length > 0) {
|
|
18
|
+
answers = await inquirer.prompt(questions)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const config = convertInputsToConfigFormat({passedInFlags, answers})
|
|
22
|
+
|
|
23
|
+
return config
|
|
24
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
module.exports = function () {
|
|
2
|
+
return {
|
|
3
|
+
type: 'object',
|
|
4
|
+
definitions: {
|
|
5
|
+
env: {
|
|
6
|
+
description: 'source or destination environment info',
|
|
7
|
+
type: 'object',
|
|
8
|
+
properties: {
|
|
9
|
+
teamId: {
|
|
10
|
+
type: 'string',
|
|
11
|
+
minLength: 1,
|
|
12
|
+
},
|
|
13
|
+
email: {
|
|
14
|
+
type: 'string',
|
|
15
|
+
format: 'email',
|
|
16
|
+
minLength: 1,
|
|
17
|
+
},
|
|
18
|
+
password: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
minLength: 1,
|
|
21
|
+
},
|
|
22
|
+
apiBase: {
|
|
23
|
+
type: 'string',
|
|
24
|
+
format: 'uri',
|
|
25
|
+
minLength: 1,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
required: ['teamId', 'email', 'password', 'apiBase'],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
properties: {
|
|
32
|
+
templateIds: {
|
|
33
|
+
description: 'list of template ids to copy',
|
|
34
|
+
type: 'array',
|
|
35
|
+
items: {
|
|
36
|
+
type: 'string',
|
|
37
|
+
},
|
|
38
|
+
minItems: 1,
|
|
39
|
+
maxItems: 10,
|
|
40
|
+
},
|
|
41
|
+
referenceSheetSetIds: {
|
|
42
|
+
description: 'list of reference sheet set ids to copy',
|
|
43
|
+
type: 'array',
|
|
44
|
+
items: {
|
|
45
|
+
type: 'string',
|
|
46
|
+
},
|
|
47
|
+
minItems: 0,
|
|
48
|
+
maxItems: 10,
|
|
49
|
+
},
|
|
50
|
+
source: {
|
|
51
|
+
$ref: '#/definitions/env',
|
|
52
|
+
},
|
|
53
|
+
destination: {
|
|
54
|
+
$ref: '#/definitions/env',
|
|
55
|
+
},
|
|
56
|
+
options: {
|
|
57
|
+
type: 'object',
|
|
58
|
+
properties: {
|
|
59
|
+
includeMetadata: {
|
|
60
|
+
type: 'boolean',
|
|
61
|
+
},
|
|
62
|
+
includeApplets: {
|
|
63
|
+
type: 'boolean',
|
|
64
|
+
},
|
|
65
|
+
includeInputTriggers: {
|
|
66
|
+
type: 'boolean',
|
|
67
|
+
},
|
|
68
|
+
includeProcedureTypes: {
|
|
69
|
+
type: 'boolean',
|
|
70
|
+
},
|
|
71
|
+
includeRefSheets: {
|
|
72
|
+
type: 'boolean',
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
required: ['templateIds', 'source', 'destination'],
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
templateIds: 'template_ids',
|
|
3
|
+
referenceSheetSetIds: {
|
|
4
|
+
key: 'datasheet_set_ids',
|
|
5
|
+
default: [],
|
|
6
|
+
},
|
|
7
|
+
'source.teamId': 'src_team_id',
|
|
8
|
+
sourceAuthToken: 'src_auth_token',
|
|
9
|
+
'source.apiBase': 'src_api_base',
|
|
10
|
+
'destination.teamId': 'dest_team_id',
|
|
11
|
+
destAuthToken: 'dest_auth_token',
|
|
12
|
+
'destination.apiBase': 'dest_api_base',
|
|
13
|
+
shouldPublishTemplates: {
|
|
14
|
+
key: 'should_publish_template',
|
|
15
|
+
default: false,
|
|
16
|
+
},
|
|
17
|
+
'options.includeProcedureTypes': {
|
|
18
|
+
key: 'include_template_procedure_types',
|
|
19
|
+
default: false,
|
|
20
|
+
},
|
|
21
|
+
'options.includeInputTriggers': {
|
|
22
|
+
key: 'include_template_input_triggers',
|
|
23
|
+
default: false,
|
|
24
|
+
},
|
|
25
|
+
'options.includeApplets': {
|
|
26
|
+
key: 'include_template_applets',
|
|
27
|
+
default: false,
|
|
28
|
+
},
|
|
29
|
+
'options.includeMetadata': {
|
|
30
|
+
key: 'include_metadata_values',
|
|
31
|
+
default: false,
|
|
32
|
+
},
|
|
33
|
+
'options.includeRefSheets': {
|
|
34
|
+
key: 'include_template_refsheets',
|
|
35
|
+
default: false,
|
|
36
|
+
},
|
|
37
|
+
};
|