@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.
Files changed (52) hide show
  1. package/README.md +405 -0
  2. package/bin/run +5 -0
  3. package/bin/run.cmd +3 -0
  4. package/oclif.manifest.json +1 -0
  5. package/package.json +67 -0
  6. package/src/commands/base.js +38 -0
  7. package/src/commands/exec-data/delete.js +161 -0
  8. package/src/commands/jobs/create.js +100 -0
  9. package/src/commands/jobs/delete.js +97 -0
  10. package/src/commands/template/copy/status.js +66 -0
  11. package/src/commands/template/copy.js +191 -0
  12. package/src/config/index.js +40 -0
  13. package/src/index.js +1 -0
  14. package/src/services/client/admin.js +81 -0
  15. package/src/services/client/copy-template-status-client-fn.js +18 -0
  16. package/src/services/client/create-template-client-fn.js +19 -0
  17. package/src/services/client/field-data.js +29 -0
  18. package/src/services/client/helpers/create-user-agent-header.js +13 -0
  19. package/src/services/client/helpers/create-wi-platform-header.js +3 -0
  20. package/src/services/client/index.js +11 -0
  21. package/src/services/client/mothership-client-fn.js +15 -0
  22. package/src/services/exec-data/delete-fn.js +41 -0
  23. package/src/services/exec-data/index.js +9 -0
  24. package/src/services/helpers/convert-kebab-case-to-camel-case.js +6 -0
  25. package/src/services/helpers/custom-exception.js +12 -0
  26. package/src/services/helpers/delay-resolve.js +8 -0
  27. package/src/services/helpers/serial-async-csv-reader.js +53 -0
  28. package/src/services/jobs/create-fn.js +106 -0
  29. package/src/services/jobs/delete-fn.js +175 -0
  30. package/src/services/jobs/index.js +11 -0
  31. package/src/services/render/helper/std-err-log.js +4 -0
  32. package/src/services/render/helper/translations.js +107 -0
  33. package/src/services/render/index.js +15 -0
  34. package/src/services/render/render-copy-template-success-fn.js +22 -0
  35. package/src/services/render/render-exception-fn.js +37 -0
  36. package/src/services/render/render-statuses-fn.js +51 -0
  37. package/src/services/template_copy/create-lambda-payload.js +36 -0
  38. package/src/services/template_copy/get-auth-token-fn.js +33 -0
  39. package/src/services/template_copy/get-config-from-path.js +13 -0
  40. package/src/services/template_copy/getConfigFromFlagsAndPrompts/convert-inputs-to-config-format.js +9 -0
  41. package/src/services/template_copy/getConfigFromFlagsAndPrompts/create-questions-for-prompt.js +129 -0
  42. package/src/services/template_copy/getConfigFromFlagsAndPrompts/find-missing-required-flags.js +30 -0
  43. package/src/services/template_copy/getConfigFromFlagsAndPrompts/index.js +24 -0
  44. package/src/services/template_copy/helpers/config-json.schema.js +79 -0
  45. package/src/services/template_copy/helpers/config-to-payload.map.js +37 -0
  46. package/src/services/template_copy/helpers/prompt-to-config.map.js +64 -0
  47. package/src/services/template_copy/index.js +21 -0
  48. package/src/services/template_copy/send-copy-template-request-fn.js +21 -0
  49. package/src/services/template_copy/validate-config-json-fn.js +19 -0
  50. package/src/services/template_status/get-status-fn.js +30 -0
  51. package/src/services/template_status/index.js +11 -0
  52. package/src/services/template_status/prompt.js +34 -0
@@ -0,0 +1,64 @@
1
+ const _reduce = require('lodash/reduce');
2
+
3
+ const convertKebabToCamel = require('../../helpers/convert-kebab-case-to-camel-case.js');
4
+
5
+ // Mapping from flag names to option property names
6
+ // This ensures prompts produce the same property names as flags
7
+ const optionFlagToPropertyMap = {
8
+ 'include-procedure-types': 'includeProcedureTypes',
9
+ 'include-input-triggers': 'includeInputTriggers',
10
+ 'include-applets': 'includeApplets',
11
+ 'include-metadata': 'includeMetadata',
12
+ 'include-refsheets': 'includeRefSheets',
13
+ };
14
+
15
+ // This needs to work with prompt and flags...
16
+ // NOTE: flags are kebab case while config keys are camel case
17
+ module.exports = {
18
+ 'template-ids': {
19
+ key: 'templateIds',
20
+ transform(templateIds) {
21
+ return templateIds.split(',');
22
+ },
23
+ },
24
+ 'reference-sheet-set-ids': {
25
+ key: 'referenceSheetSetIds',
26
+ transform(referenceSheetSetIds) {
27
+ return referenceSheetSetIds.split(',');
28
+ },
29
+ },
30
+ 'src-team-id': 'source.teamId',
31
+ 'src-email': 'source.email',
32
+ 'src-password': 'source.password',
33
+ 'src-api-base': 'source.apiBase',
34
+ 'dest-team-id': 'destination.teamId',
35
+ 'dest-email': 'destination.email',
36
+ 'dest-password': 'destination.password',
37
+ 'dest-api-base': 'destination.apiBase',
38
+ 'should-publish-templates': 'shouldPublishTemplates',
39
+ 'include-procedure-types': 'options.includeProcedureTypes', // from flag only
40
+ 'include-input-triggers': 'options.includeInputTriggers', // from flag only
41
+ 'include-applets': 'options.includeApplets', // from flag only
42
+ 'include-metadata': 'options.includeMetadata', // from flag only
43
+ 'include-refsheets': 'options.includeRefSheets', // from flag only
44
+ options: {
45
+ // from prompt only
46
+ key: 'options',
47
+ transform(sourceVal, sourceObj, destinationObj) {
48
+ // if options already set by flags, don't overwrite it
49
+ if (destinationObj.options) {
50
+ return destinationObj.options;
51
+ }
52
+ return _reduce(
53
+ sourceVal,
54
+ (mem, option) => {
55
+ // Use explicit mapping to ensure property names match what flags produce
56
+ const propertyName = optionFlagToPropertyMap[option] || convertKebabToCamel(option);
57
+ mem[propertyName] = true;
58
+ return mem;
59
+ },
60
+ {},
61
+ );
62
+ },
63
+ },
64
+ };
@@ -0,0 +1,21 @@
1
+ const getConfigFromPath = require('./get-config-from-path.js')
2
+ const createLambdaPayloadFromConfig = require('./create-lambda-payload.js')
3
+ const getAuthTokenFn = require('./get-auth-token-fn.js')
4
+ const sendCopyTemplateRequestFn = require('./send-copy-template-request-fn.js')
5
+ const validateConfigJsonFn = require('./validate-config-json-fn.js')
6
+ const getConfigFromFlagsAndPrompts = require('./getConfigFromFlagsAndPrompts')
7
+
8
+ module.exports = function (deps) {
9
+ const getAuthToken = getAuthTokenFn(deps)
10
+ const sendCopyTemplateRequest = sendCopyTemplateRequestFn(deps)
11
+ const validateConfigJson = validateConfigJsonFn(deps)
12
+
13
+ return {
14
+ getConfigFromPath,
15
+ createLambdaPayloadFromConfig,
16
+ getAuthToken,
17
+ sendCopyTemplateRequest,
18
+ validateConfigJson,
19
+ getConfigFromFlagsAndPrompts,
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ const _get = require('lodash/get')
2
+
3
+ const CustomException = require('../helpers/custom-exception.js')
4
+
5
+ module.exports = function ({copyTemplateClient}) {
6
+ return async function ({lambdaPayload}) {
7
+ try {
8
+ const {headers} = await copyTemplateClient.post({
9
+ json: lambdaPayload,
10
+ })
11
+ return _get(headers, ['status-report-id'])
12
+ } catch (error) {
13
+ const statusReportId = _get(error, ['response', 'headers', 'status-report-id'])
14
+ if (statusReportId) {
15
+ throw new CustomException({name: 'COPY_FAILED', cause: error, info: {lambdaPayload, statusReportId}})
16
+ } else {
17
+ throw new CustomException({name: 'COPY_REQUEST_FAILED', cause: error, info: {lambdaPayload}})
18
+ }
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,19 @@
1
+ const Ajv = require('ajv')
2
+
3
+ const createPayloadSchema = require('./helpers/config-json.schema.js')
4
+ const CustomException = require('../helpers/custom-exception.js')
5
+
6
+ module.exports = function () {
7
+ const payloadSchema = createPayloadSchema()
8
+
9
+ return function ({config}) {
10
+ // Validate config
11
+ const ajv = new Ajv()
12
+
13
+ const valid = ajv.validate(payloadSchema, config)
14
+ if (!valid) {
15
+ throw new CustomException({name: 'FAIL_CONFIG_VALIDATION', info: {errors: ajv.errors}})
16
+ }
17
+ return valid
18
+ }
19
+ }
@@ -0,0 +1,30 @@
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 (deps) {
7
+ const {copyTemplateStatusClient} = deps
8
+
9
+ return async ({statusReportId, templateId}) => {
10
+ let url
11
+ if (statusReportId) {
12
+ url = path.join('requests', statusReportId)
13
+ } else if (templateId) {
14
+ url = path.join('templates', templateId)
15
+ }
16
+
17
+ let response
18
+ try {
19
+ response = await copyTemplateStatusClient.get(url)
20
+ } catch (error) {
21
+ throw new CustomException({name: 'STATUS_REQUEST_FAILED', cause: error, info: {statusReportId, templateId}})
22
+ }
23
+
24
+ if (_get(response, ['body', 'Count']) === 0) {
25
+ throw new CustomException({name: 'NO_STATUSES_FOUND', info: {statusReportId, templateId}})
26
+ }
27
+
28
+ return response.body
29
+ }
30
+ }
@@ -0,0 +1,11 @@
1
+ const getStatusFn = require('./get-status-fn.js')
2
+ const prompt = require('./prompt.js')
3
+
4
+ module.exports = function (deps) {
5
+ const getStatus = getStatusFn(deps)
6
+
7
+ return {
8
+ getStatus,
9
+ prompt,
10
+ }
11
+ }
@@ -0,0 +1,34 @@
1
+ const inquirer = require('inquirer')
2
+
3
+ const STATUS_REPORT_ID_DISPLAY = 'Status Report ID'
4
+ const TEMPLATE_ID_DISPLAY = 'Template ID'
5
+ const STATUS_REPORT_ID = 'status-report-id'
6
+ const TEMPLATE_ID = 'template-id'
7
+
8
+ module.exports = async function () {
9
+ const {type} = await inquirer.prompt([{
10
+ type: 'list',
11
+ message: 'What type of status do you want to retrieve?',
12
+ name: 'type',
13
+ choices: [{name: STATUS_REPORT_ID_DISPLAY, value: STATUS_REPORT_ID}, {name: TEMPLATE_ID_DISPLAY, value: TEMPLATE_ID}],
14
+ }])
15
+
16
+ const answer = await inquirer.prompt([
17
+ {
18
+ name: type,
19
+ message: convertValueToDisplay(type),
20
+ },
21
+ ])
22
+
23
+ return answer
24
+ }
25
+
26
+ // Helper Function
27
+ function convertValueToDisplay(flag) {
28
+ switch (flag) {
29
+ case STATUS_REPORT_ID:
30
+ return STATUS_REPORT_ID_DISPLAY
31
+ case TEMPLATE_ID:
32
+ return TEMPLATE_ID_DISPLAY
33
+ }
34
+ }