@suitegeezus/suitecloud-cli 3.1.4

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 (157) hide show
  1. package/CONTRIBUTING.md +7 -0
  2. package/DELTA.md +235 -0
  3. package/README.md +107 -0
  4. package/docs/Command.md +299 -0
  5. package/messages.json +317 -0
  6. package/package.json +51 -0
  7. package/postinstall.js +8 -0
  8. package/resources/FUTC-LICENSE.txt +115 -0
  9. package/src/ApplicationConstants.js +87 -0
  10. package/src/CLI.js +202 -0
  11. package/src/CLIException.js +21 -0
  12. package/src/ExecutionEnvironmentContext.js +39 -0
  13. package/src/SdkExecutionContext.js +90 -0
  14. package/src/SdkExecutor.js +160 -0
  15. package/src/commands/Command.js +158 -0
  16. package/src/commands/account/manageauth/ManageAccountAction.js +126 -0
  17. package/src/commands/account/manageauth/ManageAccountCommand.js +20 -0
  18. package/src/commands/account/manageauth/ManageAccountInputHandler.js +215 -0
  19. package/src/commands/account/manageauth/ManageAccountOutputHandler.js +30 -0
  20. package/src/commands/account/setup/SetupAction.js +39 -0
  21. package/src/commands/account/setup/SetupCommand.js +21 -0
  22. package/src/commands/account/setup/SetupInputHandler.js +169 -0
  23. package/src/commands/account/setup/SetupOutputHandler.js +65 -0
  24. package/src/commands/account/setupci/AccountSetupCiAction.js +58 -0
  25. package/src/commands/account/setupci/AccountSetupCiCommand.js +20 -0
  26. package/src/commands/account/setupci/AccountSetupCiConstants.js +21 -0
  27. package/src/commands/account/setupci/AccountSetupCiOutputHandler.js +40 -0
  28. package/src/commands/account/setupci/AccountSetupCiValidation.js +100 -0
  29. package/src/commands/base/BaseAction.js +37 -0
  30. package/src/commands/base/BaseInputHandler.js +24 -0
  31. package/src/commands/base/BaseOutputHandler.js +30 -0
  32. package/src/commands/custom/hello/Action.js +58 -0
  33. package/src/commands/custom/hello/Command.js +20 -0
  34. package/src/commands/custom/hello/Handler.js +26 -0
  35. package/src/commands/custom/hello/README.md +78 -0
  36. package/src/commands/custom/hook/Action.js +28 -0
  37. package/src/commands/custom/hook/Command.js +22 -0
  38. package/src/commands/custom/hook/InputHandler.js +8 -0
  39. package/src/commands/custom/hook/OutputHandler.js +8 -0
  40. package/src/commands/custom/hook/README.md +32 -0
  41. package/src/commands/file/create/CreateFileAction.js +89 -0
  42. package/src/commands/file/create/CreateFileCommand.js +20 -0
  43. package/src/commands/file/create/CreateFileInputHandler.js +175 -0
  44. package/src/commands/file/create/CreateFileOutputHandler.js +22 -0
  45. package/src/commands/file/import/ImportFilesAction.js +112 -0
  46. package/src/commands/file/import/ImportFilesCommand.js +22 -0
  47. package/src/commands/file/import/ImportFilesInputHandler.js +130 -0
  48. package/src/commands/file/import/ImportFilesOutputHandler.js +53 -0
  49. package/src/commands/file/list/ListFilesAction.js +55 -0
  50. package/src/commands/file/list/ListFilesCommand.js +20 -0
  51. package/src/commands/file/list/ListFilesInputHandler.js +55 -0
  52. package/src/commands/file/list/ListFilesOutputHandler.js +24 -0
  53. package/src/commands/file/upload/UploadFilesAction.js +67 -0
  54. package/src/commands/file/upload/UploadFilesCommand.js +20 -0
  55. package/src/commands/file/upload/UploadFilesInputHandler.js +125 -0
  56. package/src/commands/file/upload/UploadFilesOutputHandler.js +49 -0
  57. package/src/commands/object/create/CreateObjectAction.js +33 -0
  58. package/src/commands/object/create/CreateObjectCommand.js +19 -0
  59. package/src/commands/object/create/CreateObjectInputHandler.js +82 -0
  60. package/src/commands/object/import/ImportObjectsAction.js +225 -0
  61. package/src/commands/object/import/ImportObjectsCommand.js +20 -0
  62. package/src/commands/object/import/ImportObjectsInputHandler.js +310 -0
  63. package/src/commands/object/import/ImportObjectsOutputHandler.js +114 -0
  64. package/src/commands/object/list/ListObjectsAction.js +62 -0
  65. package/src/commands/object/list/ListObjectsCommand.js +20 -0
  66. package/src/commands/object/list/ListObjectsInputHandler.js +148 -0
  67. package/src/commands/object/list/ListObjectsOutputHandler.js +29 -0
  68. package/src/commands/object/update/UpdateAction.js +138 -0
  69. package/src/commands/object/update/UpdateCommand.js +20 -0
  70. package/src/commands/object/update/UpdateInputHandler.js +170 -0
  71. package/src/commands/object/update/UpdateOutputHandler.js +61 -0
  72. package/src/commands/project/adddependencies/AddDependenciesAction.js +55 -0
  73. package/src/commands/project/adddependencies/AddDependenciesCommand.js +19 -0
  74. package/src/commands/project/adddependencies/AddDependenciesOutputHandler.js +114 -0
  75. package/src/commands/project/create/CreateProjectAction.js +370 -0
  76. package/src/commands/project/create/CreateProjectCommand.js +20 -0
  77. package/src/commands/project/create/CreateProjectInputHandler.js +169 -0
  78. package/src/commands/project/create/CreateProjectOutputHandler.js +36 -0
  79. package/src/commands/project/deploy/DeployAction.js +161 -0
  80. package/src/commands/project/deploy/DeployCommand.js +20 -0
  81. package/src/commands/project/deploy/DeployInputHandler.js +100 -0
  82. package/src/commands/project/deploy/DeployOutputHandler.js +49 -0
  83. package/src/commands/project/package/PackageAction.js +59 -0
  84. package/src/commands/project/package/PackageCommand.js +18 -0
  85. package/src/commands/project/package/PackageOutputHandler.js +18 -0
  86. package/src/commands/project/validate/ValidateAction.js +106 -0
  87. package/src/commands/project/validate/ValidateCommand.js +20 -0
  88. package/src/commands/project/validate/ValidateInputHandler.js +92 -0
  89. package/src/commands/project/validate/ValidateOutputHandler.js +74 -0
  90. package/src/core/CommandActionExecutor.js +347 -0
  91. package/src/core/CommandAuthentication.js +13 -0
  92. package/src/core/CommandOptionsValidator.js +42 -0
  93. package/src/core/CommandRegistrationService.js +130 -0
  94. package/src/core/CommandsMetadataService.js +104 -0
  95. package/src/core/extensibility/CLIConfigurationService.js +192 -0
  96. package/src/core/extensibility/CommandUserExtension.js +64 -0
  97. package/src/core/sdksetup/SdkDownloadService.js +109 -0
  98. package/src/core/sdksetup/SdkLicense.js +39 -0
  99. package/src/core/sdksetup/SdkProperties.js +51 -0
  100. package/src/loggers/ConsoleLogger.js +32 -0
  101. package/src/loggers/LoggerFontFormatter.mjs +17 -0
  102. package/src/loggers/LoggerOsConstants.js +12 -0
  103. package/src/loggers/NodeConsoleLogger.js +47 -0
  104. package/src/metadata/CommandGenerators.json +92 -0
  105. package/src/metadata/NodeCommandsMetadata.json +139 -0
  106. package/src/metadata/ObjectTypesMetadata.js +615 -0
  107. package/src/metadata/SdkCommandsMetadata.json +846 -0
  108. package/src/metadata/SdkCommandsMetadataPatch.json +130 -0
  109. package/src/metadata/SuiteScriptModulesMetadata.js +152 -0
  110. package/src/metadata/SuiteScriptTypesMetadata.js +64 -0
  111. package/src/services/AccountFileCabinetService.js +86 -0
  112. package/src/services/EnvironmentInformationService.js +31 -0
  113. package/src/services/ExecutionContextService.js +108 -0
  114. package/src/services/FileCabinetService.js +65 -0
  115. package/src/services/FileSystemService.js +245 -0
  116. package/src/services/NodeTranslationService.js +22 -0
  117. package/src/services/NpmInstallRunner.js +33 -0
  118. package/src/services/ProjectInfoService.js +209 -0
  119. package/src/services/SuiteCloudAuthProxyService.js +469 -0
  120. package/src/services/TranslationKeys.js +506 -0
  121. package/src/services/TranslationService.js +30 -0
  122. package/src/services/actionresult/ActionResult.js +129 -0
  123. package/src/services/actionresult/AuthenticateActionResult.js +85 -0
  124. package/src/services/actionresult/CreateProjectActionResult.js +100 -0
  125. package/src/services/actionresult/DeployActionResult.js +69 -0
  126. package/src/services/actionresult/HelloActionResult.js +13 -0
  127. package/src/services/actionresult/ManageAccountActionResult.js +70 -0
  128. package/src/services/settings/CLISettings.js +46 -0
  129. package/src/services/settings/CLISettingsService.js +132 -0
  130. package/src/suitecloud.js +33 -0
  131. package/src/templates/TemplateKeys.js +25 -0
  132. package/src/templates/objects/commerceextension.xml +9 -0
  133. package/src/templates/projectconfigs/default_gitignore.template +47 -0
  134. package/src/templates/projectconfigs/sdf.config.js +4 -0
  135. package/src/templates/projectconfigs/suitecloud.config.js +4 -0
  136. package/src/templates/scripts/blankscript.js +3 -0
  137. package/src/templates/unittest/jest.config.js.template +7 -0
  138. package/src/templates/unittest/jsconfig.json.template +5 -0
  139. package/src/templates/unittest/package.json.template +12 -0
  140. package/src/templates/unittest/sample-test.js.template +37 -0
  141. package/src/templates/unittest/suitecloud.config.js.template +15 -0
  142. package/src/ui/CliSpinner.js +34 -0
  143. package/src/utils/AccountCredentialsFormatter.js +62 -0
  144. package/src/utils/AccountSpecificValuesUtils.js +55 -0
  145. package/src/utils/ActionResultUtils.js +47 -0
  146. package/src/utils/ApplyInstallationPreferencesUtils.js +41 -0
  147. package/src/utils/AuthenticationUtils.js +262 -0
  148. package/src/utils/CommandUtils.js +50 -0
  149. package/src/utils/CryptoUtils.js +41 -0
  150. package/src/utils/ExceptionUtils.js +33 -0
  151. package/src/utils/FileUtils.js +43 -0
  152. package/src/utils/SdkOperationResult.js +68 -0
  153. package/src/utils/SdkOperationResultUtils.js +20 -0
  154. package/src/utils/ValidationErrorsFormatter.js +23 -0
  155. package/src/utils/http/HttpConstants.js +39 -0
  156. package/src/utils/http/ProxyAgent.js +110 -0
  157. package/src/validation/InteractiveAnswersValidator.js +205 -0
@@ -0,0 +1,62 @@
1
+ /*
2
+ ** Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3
+ ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
+ */
5
+ 'use strict';
6
+
7
+ const { ActionResult } = require('../../../services/actionresult/ActionResult');
8
+ const CommandUtils = require('../../../utils/CommandUtils');
9
+ const executeWithSpinner = require('../../../ui/CliSpinner').executeWithSpinner;
10
+ const BaseAction = require('../../base/BaseAction');
11
+ const NodeTranslationService = require('../../../services/NodeTranslationService');
12
+ const SdkOperationResultUtils = require('../../../utils/SdkOperationResultUtils');
13
+ const SdkExecutionContext = require('../../../SdkExecutionContext');
14
+ const { getProjectDefaultAuthId } = require('../../../utils/AuthenticationUtils');
15
+
16
+ const {
17
+ COMMAND_LISTOBJECTS: { LISTING_OBJECTS },
18
+ } = require('../../../services/TranslationKeys');
19
+
20
+ const COMMAND_PARAMETERS = {
21
+ AUTH_ID: 'authid',
22
+ };
23
+
24
+ module.exports = class ListObjectsAction extends BaseAction {
25
+ constructor(options) {
26
+ super(options);
27
+ }
28
+
29
+ preExecute(params) {
30
+ return params;
31
+ }
32
+
33
+ async execute(params) {
34
+ try {
35
+ const sdkParams = CommandUtils.extractCommandOptions(params, this._commandMetadata);
36
+ if (Array.isArray(sdkParams.type)) {
37
+ sdkParams.type = sdkParams.type.join(' ');
38
+ }
39
+
40
+ const executionContext = SdkExecutionContext.Builder.forCommand(this._commandMetadata.sdkCommand)
41
+ .integration()
42
+ .addParams(sdkParams)
43
+ .build();
44
+
45
+ const actionListObjects = this._sdkExecutor.execute(executionContext);
46
+
47
+ const operationResult = await executeWithSpinner({
48
+ action: actionListObjects,
49
+ message: NodeTranslationService.getMessage(LISTING_OBJECTS),
50
+ });
51
+
52
+ return operationResult.status === SdkOperationResultUtils.STATUS.SUCCESS
53
+ ? ActionResult.Builder.withData(operationResult.data)
54
+ .withResultMessage(operationResult.resultMessage)
55
+ .withCommandParameters(sdkParams)
56
+ .build()
57
+ : ActionResult.Builder.withErrors(operationResult.errorMessages).withCommandParameters(sdkParams).build();
58
+ } catch (error) {
59
+ return ActionResult.Builder.withErrors([error]).build();
60
+ }
61
+ }
62
+ };
@@ -0,0 +1,20 @@
1
+ /*
2
+ ** Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3
+ ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
+ */
5
+ 'use strict';
6
+
7
+ const Command = require('../../Command');
8
+ const ListObjectsAction = require('./ListObjectsAction');
9
+ const ListObjectsInputHandler = require('./ListObjectsInputHandler');
10
+ const ListObjectsOutputHandler = require('./ListObjectsOutputHandler');
11
+
12
+ module.exports = {
13
+ create(options) {
14
+ return Command.Builder.withOptions(options)
15
+ .withAction(ListObjectsAction)
16
+ .withInput(ListObjectsInputHandler)
17
+ .withOutput(ListObjectsOutputHandler)
18
+ .build();
19
+ }
20
+ };
@@ -0,0 +1,148 @@
1
+ /*
2
+ ** Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3
+ ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
+ */
5
+ 'use strict';
6
+
7
+ const { default : { prompt, Separator } } = require('inquirer');
8
+ const CommandUtils = require('../../../utils/CommandUtils');
9
+ const OBJECT_TYPES = require('../../../metadata/ObjectTypesMetadata');
10
+ const ProjectInfoService = require('../../../services/ProjectInfoService');
11
+ const NodeTranslationService = require('../../../services/NodeTranslationService');
12
+ const { PROJECT_SUITEAPP } = require('../../../ApplicationConstants');
13
+ const BaseInputHandler = require('../../base/BaseInputHandler');
14
+ const {
15
+ validateArrayIsNotEmpty,
16
+ validateFieldIsNotEmpty,
17
+ validateSuiteApp,
18
+ showValidationResults,
19
+ } = require('../../../validation/InteractiveAnswersValidator');
20
+ const {
21
+ COMMAND_LISTOBJECTS: { QUESTIONS },
22
+ YES,
23
+ NO,
24
+ } = require('../../../services/TranslationKeys');
25
+
26
+ const COMMAND_QUESTIONS_NAMES = {
27
+ APP_ID: 'appid',
28
+ SCRIPT_ID: 'scriptid',
29
+ SPECIFY_SCRIPT_ID: 'specifyscriptid',
30
+ SPECIFY_SUITEAPP: 'specifysuiteapp',
31
+ TYPE: 'type',
32
+ TYPE_ALL: 'typeall',
33
+ };
34
+
35
+ module.exports = class ListObjectsInputHandler extends BaseInputHandler {
36
+ constructor(options) {
37
+ super(options);
38
+ this._projectInfoService = new ProjectInfoService(this._projectFolder);
39
+ }
40
+
41
+ async getParameters(params) {
42
+ const questions = [];
43
+ //create a class to see type based on manifest.
44
+ if (this._projectInfoService.getProjectType() === PROJECT_SUITEAPP) {
45
+ let message = NodeTranslationService.getMessage(QUESTIONS.SPECIFIC_APPID);
46
+
47
+ const questionSpecificSuiteApp = {
48
+ type: CommandUtils.INQUIRER_TYPES.LIST,
49
+ name: COMMAND_QUESTIONS_NAMES.SPECIFY_SUITEAPP,
50
+ message,
51
+ default: true,
52
+ choices: [
53
+ {
54
+ name: NodeTranslationService.getMessage(YES),
55
+ value: true,
56
+ },
57
+ {
58
+ name: NodeTranslationService.getMessage(NO),
59
+ value: false,
60
+ },
61
+ ],
62
+ validate: (fieldValue) => showValidationResults(fieldValue, validateFieldIsNotEmpty),
63
+ };
64
+ questions.push(questionSpecificSuiteApp);
65
+
66
+ const questionAppId = {
67
+ when: function (response) {
68
+ return response.specifysuiteapp;
69
+ },
70
+ type: CommandUtils.INQUIRER_TYPES.INPUT,
71
+ name: COMMAND_QUESTIONS_NAMES.APP_ID,
72
+ message: NodeTranslationService.getMessage(QUESTIONS.APPID),
73
+ validate: (fieldValue) => showValidationResults(fieldValue, validateSuiteApp),
74
+ };
75
+ questions.push(questionAppId);
76
+ }
77
+
78
+ const questionFilterByCustomObjects = {
79
+ type: CommandUtils.INQUIRER_TYPES.LIST,
80
+ name: COMMAND_QUESTIONS_NAMES.TYPE_ALL,
81
+ message: NodeTranslationService.getMessage(QUESTIONS.SHOW_ALL_CUSTOM_OBJECTS),
82
+ default: true,
83
+ choices: [
84
+ {
85
+ name: NodeTranslationService.getMessage(YES),
86
+ value: true,
87
+ },
88
+ {
89
+ name: NodeTranslationService.getMessage(NO),
90
+ value: false,
91
+ },
92
+ ],
93
+ };
94
+ questions.push(questionFilterByCustomObjects);
95
+
96
+ const questionCustomObjects = {
97
+ when: function (answers) {
98
+ return !answers.typeall;
99
+ },
100
+ type: CommandUtils.INQUIRER_TYPES.CHECKBOX,
101
+ name: COMMAND_QUESTIONS_NAMES.TYPE,
102
+ message: NodeTranslationService.getMessage(QUESTIONS.FILTER_BY_CUSTOM_OBJECTS),
103
+ pageSize: 15,
104
+ choices: [
105
+ ...OBJECT_TYPES.map((customObject) => ({
106
+ name: customObject.name,
107
+ value: customObject.value.type,
108
+ })),
109
+ new Separator(),
110
+ ],
111
+
112
+ validate: (fieldValue) => showValidationResults(fieldValue, validateArrayIsNotEmpty),
113
+ };
114
+
115
+ questions.push(questionCustomObjects);
116
+
117
+ const questionSpecificScriptId = {
118
+ type: CommandUtils.INQUIRER_TYPES.LIST,
119
+ name: COMMAND_QUESTIONS_NAMES.SPECIFY_SCRIPT_ID,
120
+ message: NodeTranslationService.getMessage(QUESTIONS.FILTER_BY_SCRIPT_ID),
121
+ default: false,
122
+ choices: [
123
+ {
124
+ name: NodeTranslationService.getMessage(YES),
125
+ value: true,
126
+ },
127
+ {
128
+ name: NodeTranslationService.getMessage(NO),
129
+ value: false,
130
+ },
131
+ ],
132
+ };
133
+ questions.push(questionSpecificScriptId);
134
+
135
+ const questionScriptId = {
136
+ when: function (response) {
137
+ return response.specifyscriptid;
138
+ },
139
+ type: CommandUtils.INQUIRER_TYPES.INPUT,
140
+ name: COMMAND_QUESTIONS_NAMES.SCRIPT_ID,
141
+ message: NodeTranslationService.getMessage(QUESTIONS.SCRIPT_ID),
142
+ validate: (fieldValue) => showValidationResults(fieldValue, validateFieldIsNotEmpty),
143
+ };
144
+ questions.push(questionScriptId);
145
+ let answers = await prompt(questions);
146
+ return answers;
147
+ }
148
+ };
@@ -0,0 +1,29 @@
1
+ /*
2
+ ** Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3
+ ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
+ */
5
+ 'use strict';
6
+ const NodeTranslationService = require('../../../services/NodeTranslationService');
7
+ const ActionResultUtils = require('../../../utils/ActionResultUtils');
8
+ const BaseOutputHandler = require('../../base/BaseOutputHandler');
9
+
10
+ const {
11
+ COMMAND_LISTOBJECTS: { SUCCESS_OBJECTS_IMPORTED, SUCCESS_NO_OBJECTS },
12
+ } = require('../../../services/TranslationKeys');
13
+
14
+ module.exports = class ListObjectsOutputHandler extends BaseOutputHandler {
15
+ constructor(options) {
16
+ super(options);
17
+ }
18
+
19
+ parse(actionResult) {
20
+ ActionResultUtils.logResultMessage(actionResult, this._log);
21
+ if (Array.isArray(actionResult.data) && actionResult.data.length) {
22
+ this._log.result(NodeTranslationService.getMessage(SUCCESS_OBJECTS_IMPORTED));
23
+ actionResult.data.forEach((object) => this._log.result(`${object.type}:${object.scriptId}`));
24
+ } else {
25
+ this._log.result(NodeTranslationService.getMessage(SUCCESS_NO_OBJECTS));
26
+ }
27
+ return actionResult;
28
+ }
29
+ };
@@ -0,0 +1,138 @@
1
+ /*
2
+ ** Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3
+ ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
+ */
5
+ 'use strict';
6
+
7
+ const BaseAction = require('../../base/BaseAction');
8
+ const { ActionResult } = require('../../../services/actionresult/ActionResult');
9
+ const CommandUtils = require('../../../utils/CommandUtils');
10
+ const NodeTranslationService = require('../../../services/NodeTranslationService');
11
+ const executeWithSpinner = require('../../../ui/CliSpinner').executeWithSpinner;
12
+ const SdkExecutionContext = require('../../../SdkExecutionContext');
13
+ const { STATUS } = require('../../../utils/SdkOperationResultUtils');
14
+ const { getProjectDefaultAuthId } = require('../../../utils/AuthenticationUtils');
15
+
16
+ const {
17
+ COMMAND_UPDATE: { ERRORS, MESSAGES, OUTPUT },
18
+ } = require('../../../services/TranslationKeys');
19
+
20
+ const ANSWERS_NAMES = {
21
+ FILTER_BY_SCRIPT_ID: 'filterByScriptId',
22
+ INCLUDE_CUSTOM_INSTANCES: 'includeinstances',
23
+ OVERWRITE_OBJECTS: 'overwriteObjects',
24
+ SCRIPT_ID_LIST: 'scriptid',
25
+ SCRIPT_ID_FILTER: 'scriptIdFilter',
26
+ };
27
+
28
+ const COMMAND_OPTIONS = {
29
+ AUTH_ID: 'authid',
30
+ PROJECT: 'project',
31
+ SCRIPT_ID: 'scriptid',
32
+ INCLUDE_INSTANCES: 'includeinstances',
33
+ };
34
+ const COMMAND_UPDATE_CUSTOM_RECORD_WITH_INSTANCES = 'updatecustomrecordwithinstances';
35
+ const CUSTOM_RECORD_PREFIX = 'customrecord';
36
+ module.exports = class UpdateAction extends BaseAction {
37
+ constructor(options) {
38
+ super(options);
39
+ }
40
+
41
+ preExecute(params) {
42
+ params[COMMAND_OPTIONS.PROJECT] = CommandUtils.quoteString(this._projectFolder);;
43
+ params[COMMAND_OPTIONS.SCRIPT_ID] = [...new Set(params[ANSWERS_NAMES.SCRIPT_ID_LIST])].join(' ');
44
+ return params;
45
+ }
46
+
47
+ async execute(params) {
48
+ try {
49
+ if (params.hasOwnProperty(ANSWERS_NAMES.OVERWRITE_OBJECTS) && !params[ANSWERS_NAMES.OVERWRITE_OBJECTS]) {
50
+ throw NodeTranslationService.getMessage(MESSAGES.CANCEL_UPDATE);
51
+ }
52
+ let updateCustomRecordsWithInstancesResult = [];
53
+ if (params.hasOwnProperty(COMMAND_OPTIONS.INCLUDE_INSTANCES) && params[COMMAND_OPTIONS.INCLUDE_INSTANCES]) {
54
+ const customRecordScriptIds = params[COMMAND_OPTIONS.SCRIPT_ID].split(' ').filter((scriptId) => this._isCustomRecord(scriptId));
55
+ if (customRecordScriptIds && customRecordScriptIds.length > 0) {
56
+ params[COMMAND_OPTIONS.SCRIPT_ID] = params[COMMAND_OPTIONS.SCRIPT_ID]
57
+ .split(' ')
58
+ .filter((scriptId) => !this._isCustomRecord(scriptId))
59
+ .join(' ');
60
+ updateCustomRecordsWithInstancesResult = await this._updateCustomRecordWithInstances(params, customRecordScriptIds);
61
+ }
62
+
63
+ delete params[COMMAND_OPTIONS.INCLUDE_INSTANCES];
64
+ }
65
+
66
+ if (params[COMMAND_OPTIONS.SCRIPT_ID] === '') {
67
+ // If there are no more objects to update (all were custom records) we already return with only previous messages
68
+ return ActionResult.Builder.withData(updateCustomRecordsWithInstancesResult).build();
69
+ }
70
+
71
+ const sdkParams = CommandUtils.extractCommandOptions(params, this._commandMetadata);
72
+ const updateObjectsResult = await this._updateObjects(sdkParams);
73
+ const allResults = updateCustomRecordsWithInstancesResult.concat(updateObjectsResult.data);
74
+
75
+ return updateObjectsResult.status === STATUS.SUCCESS
76
+ ? ActionResult.Builder.withData(allResults)
77
+ .withResultMessage(updateObjectsResult.resultMessage)
78
+ .withCommandParameters(sdkParams)
79
+ .build()
80
+ : ActionResult.Builder.withErrors(updateObjectsResult.errorMessages).withCommandParameters(sdkParams).build();
81
+ } catch (error) {
82
+ return ActionResult.Builder.withErrors([error]).build();
83
+ }
84
+ }
85
+
86
+ _isCustomRecord(scriptid) {
87
+ return scriptid.startsWith(CUSTOM_RECORD_PREFIX);
88
+ }
89
+
90
+ async _updateCustomRecordWithInstances(params, customRecordScriptIds) {
91
+ this._log.result(NodeTranslationService.getMessage(OUTPUT.UPDATED_CUSTOM_RECORDS));
92
+ const updateWithInstancesResults = [];
93
+
94
+ for (const scriptId of customRecordScriptIds) {
95
+ const updateCustomRecordResult = await this._executeCommandUpdateCustomRecordWithInstances(params, scriptId);
96
+ let resultMessage;
97
+ if (updateCustomRecordResult.status === STATUS.ERROR) {
98
+ resultMessage = updateCustomRecordResult.errorMessages;
99
+ this._log.warning(`${this._log.getPadding(1)}- ${NodeTranslationService.getMessage(ERRORS.CUSTOM_RECORD, scriptId, resultMessage)}`);
100
+ } else {
101
+ resultMessage = updateCustomRecordResult.data;
102
+ this._log.result(`${this._log.getPadding(1)}- ${scriptId}`);
103
+ }
104
+ updateWithInstancesResults.push({
105
+ key: scriptId,
106
+ message: resultMessage,
107
+ type: updateCustomRecordResult.status,
108
+ includeinstances: true,
109
+ });
110
+ }
111
+ return updateWithInstancesResults;
112
+ }
113
+
114
+ async _executeCommandUpdateCustomRecordWithInstances(params, scriptId) {
115
+ const executionContextForUpdate = SdkExecutionContext.Builder.forCommand(COMMAND_UPDATE_CUSTOM_RECORD_WITH_INSTANCES)
116
+ .integration()
117
+ .addParam(COMMAND_OPTIONS.AUTH_ID, params[COMMAND_OPTIONS.AUTH_ID])
118
+ .addParam(COMMAND_OPTIONS.PROJECT, params[COMMAND_OPTIONS.PROJECT])
119
+ .addParam(COMMAND_OPTIONS.SCRIPT_ID, scriptId)
120
+ .build();
121
+ return await executeWithSpinner({
122
+ action: this._sdkExecutor.execute(executionContextForUpdate),
123
+ message: NodeTranslationService.getMessage(MESSAGES.UPDATING_OBJECT_WITH_CUSTOM_INSTANCES, scriptId),
124
+ });
125
+ }
126
+
127
+ async _updateObjects(sdkParams) {
128
+ const executionContextForUpdate = SdkExecutionContext.Builder.forCommand(this._commandMetadata.sdkCommand)
129
+ .integration()
130
+ .addParams(sdkParams)
131
+ .build();
132
+
133
+ return await executeWithSpinner({
134
+ action: this._sdkExecutor.execute(executionContextForUpdate),
135
+ message: NodeTranslationService.getMessage(MESSAGES.UPDATING_OBJECTS),
136
+ });
137
+ }
138
+ };
@@ -0,0 +1,20 @@
1
+ /*
2
+ ** Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3
+ ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
+ */
5
+ 'use strict';
6
+
7
+ const Command = require('../../Command');
8
+ const UpdateAction = require('./UpdateAction');
9
+ const UpdateInputHandler = require('./UpdateInputHandler');
10
+ const UpdateOutputHandler = require('./UpdateOutputHandler');
11
+
12
+ module.exports = {
13
+ create(options) {
14
+ return Command.Builder.withOptions(options)
15
+ .withAction(UpdateAction)
16
+ .withInput(UpdateInputHandler)
17
+ .withOutput(UpdateOutputHandler)
18
+ .build();
19
+ }
20
+ };
@@ -0,0 +1,170 @@
1
+ /*
2
+ ** Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3
+ ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
+ */
5
+ 'use strict';
6
+ const path = require('path');
7
+ const { default : { prompt, Separator } } = require('inquirer');
8
+ const CommandUtils = require('../../../utils/CommandUtils');
9
+ const NodeTranslationService = require('../../../services/NodeTranslationService');
10
+ const FileSystemService = require('../../../services/FileSystemService');
11
+ const BaseInputHandler = require('../../base/BaseInputHandler');
12
+
13
+ const {
14
+ COMMAND_UPDATE: { ERRORS, QUESTIONS, MESSAGES },
15
+ YES,
16
+ NO,
17
+ } = require('../../../services/TranslationKeys');
18
+
19
+ const { validateArrayIsNotEmpty, validateScriptId, showValidationResults } = require('../../../validation/InteractiveAnswersValidator');
20
+
21
+ const { FOLDERS } = require('../../../ApplicationConstants');
22
+ const ANSWERS_NAMES = {
23
+ FILTER_BY_SCRIPT_ID: 'filterByScriptId',
24
+ INCLUDE_CUSTOM_INSTANCES: 'includeinstances',
25
+ OVERWRITE_OBJECTS: 'overwriteObjects',
26
+ SCRIPT_ID_LIST: 'scriptid',
27
+ SCRIPT_ID_FILTER: 'scriptIdFilter',
28
+ };
29
+
30
+ const COMMAND_OPTIONS = {
31
+ AUTH_ID: 'authid',
32
+ INCLUDE_CUSTOM_INSTANCES: 'includeinstances',
33
+ PROJECT: 'project',
34
+ SCRIPT_ID: 'scriptid',
35
+ };
36
+
37
+ const CUSTOM_RECORD_PREFIX = 'customrecord';
38
+
39
+ const MAX_ENTRIES_BEFORE_FILTER = 30;
40
+ const XML_EXTENSION = '.xml';
41
+
42
+ module.exports = class UpdateInputHandler extends BaseInputHandler {
43
+ constructor(options) {
44
+ super(options);
45
+ this._fileSystemService = new FileSystemService();
46
+ }
47
+
48
+ async getParameters(params) {
49
+ const foundXMLFiles = this._searchFilesFromObjectsFolder();
50
+ let filteredObjectsList = await this._getObjectsToSelect(foundXMLFiles);
51
+ const selectedScriptIds = await this._getSelectedScriptIds(filteredObjectsList);
52
+ const customRecordsAndSegments = selectedScriptIds.filter((scriptid) => scriptid.startsWith(CUSTOM_RECORD_PREFIX));
53
+ const includeCustomInstances = await this._includeCustomInstancesQuestion(customRecordsAndSegments);
54
+ const overwriteObjects = await this._overwriteQuestion(includeCustomInstances);
55
+
56
+ return {
57
+ [ANSWERS_NAMES.OVERWRITE_OBJECTS]: overwriteObjects,
58
+ [COMMAND_OPTIONS.SCRIPT_ID]: selectedScriptIds,
59
+ [COMMAND_OPTIONS.INCLUDE_CUSTOM_INSTANCES]: includeCustomInstances,
60
+ };
61
+ }
62
+
63
+ _searchFilesFromObjectsFolder() {
64
+ const pathToObjectsFolder = path.join(this._projectFolder, FOLDERS.OBJECTS);
65
+ const filesInObjectsFolder = this._fileSystemService.getFilesFromDirectory(pathToObjectsFolder);
66
+ const foundXMLFiles = filesInObjectsFolder
67
+ .filter((filename) => filename.endsWith(XML_EXTENSION))
68
+ .map((file) => ({
69
+ name: file.replace(this._projectFolder, '').slice(0, -XML_EXTENSION.length),
70
+ value: path.basename(file, XML_EXTENSION),
71
+ }));
72
+
73
+ if (foundXMLFiles.length === 0) {
74
+ throw NodeTranslationService.getMessage(ERRORS.NO_OBJECTS_IN_PROJECT);
75
+ }
76
+ return foundXMLFiles;
77
+ }
78
+
79
+ async _getObjectsToSelect(foundXMLFiles) {
80
+ if (foundXMLFiles.length > MAX_ENTRIES_BEFORE_FILTER) {
81
+ const filteredObjects = await this._filterObjectsByScriptId(foundXMLFiles);
82
+ if (filteredObjects.length === 0) {
83
+ throw NodeTranslationService.getMessage(MESSAGES.NO_OBJECTS_WITH_SCRIPT_ID_FILTER);
84
+ }
85
+ return filteredObjects;
86
+ } else {
87
+ return foundXMLFiles;
88
+ }
89
+ }
90
+
91
+ async _filterObjectsByScriptId(foundXMLFiles) {
92
+ const filterAnswers = await this._questionFilterByScriptId();
93
+ const filteredObjects = filterAnswers[ANSWERS_NAMES.FILTER_BY_SCRIPT_ID]
94
+ ? foundXMLFiles.filter((element) => element.value.includes(filterAnswers[ANSWERS_NAMES.SCRIPT_ID_FILTER]))
95
+ : foundXMLFiles;
96
+ return filteredObjects;
97
+ }
98
+
99
+ async _getSelectedScriptIds(filteredObjects) {
100
+ filteredObjects.push(new Separator());
101
+ const selectObjectsToUpdateQuestion = {
102
+ type: CommandUtils.INQUIRER_TYPES.CHECKBOX,
103
+ name: ANSWERS_NAMES.SCRIPT_ID_LIST,
104
+ message: NodeTranslationService.getMessage(QUESTIONS.SCRIPT_ID),
105
+ default: 1,
106
+ choices: filteredObjects,
107
+ validate: (fieldValue) => showValidationResults(fieldValue, validateArrayIsNotEmpty),
108
+ };
109
+ const answers = await prompt([selectObjectsToUpdateQuestion]);
110
+
111
+ return answers[ANSWERS_NAMES.SCRIPT_ID_LIST];
112
+ }
113
+
114
+ async _questionFilterByScriptId() {
115
+ return await prompt([
116
+ {
117
+ type: CommandUtils.INQUIRER_TYPES.LIST,
118
+ name: ANSWERS_NAMES.FILTER_BY_SCRIPT_ID,
119
+ message: NodeTranslationService.getMessage(QUESTIONS.FILTER_BY_SCRIPT_ID),
120
+ default: false,
121
+ choices: [
122
+ { name: NodeTranslationService.getMessage(YES), value: true },
123
+ { name: NodeTranslationService.getMessage(NO), value: false },
124
+ ],
125
+ },
126
+ {
127
+ when: (response) => {
128
+ return response[ANSWERS_NAMES.FILTER_BY_SCRIPT_ID];
129
+ },
130
+ type: CommandUtils.INQUIRER_TYPES.INPUT,
131
+ name: ANSWERS_NAMES.SCRIPT_ID_FILTER,
132
+ message: NodeTranslationService.getMessage(QUESTIONS.SCRIPT_ID_FILTER),
133
+ validate: (fieldValue) => showValidationResults(fieldValue, validateScriptId),
134
+ },
135
+ ]);
136
+ }
137
+ async _includeCustomInstancesQuestion(customRecordsAndSegments) {
138
+ const includeCustomInstancesQuestions = {
139
+ when: customRecordsAndSegments.length >= 1,
140
+ type: CommandUtils.INQUIRER_TYPES.LIST,
141
+ name: ANSWERS_NAMES.INCLUDE_CUSTOM_INSTANCES,
142
+ message: NodeTranslationService.getMessage(QUESTIONS.INCLUDE_CUSTOM_INSTANCES),
143
+ default: false,
144
+ choices: [
145
+ { name: NodeTranslationService.getMessage(YES), value: true },
146
+ { name: NodeTranslationService.getMessage(NO), value: false },
147
+ ],
148
+ };
149
+ const answer = await prompt([includeCustomInstancesQuestions]);
150
+ return answer[ANSWERS_NAMES.INCLUDE_CUSTOM_INSTANCES];
151
+ }
152
+
153
+ async _overwriteQuestion(includeCustomInstances) {
154
+ const message = includeCustomInstances
155
+ ? NodeTranslationService.getMessage(QUESTIONS.OVERWRITE_OBJECTS_WITH_CUSTOM_INSTANCES)
156
+ : NodeTranslationService.getMessage(QUESTIONS.OVERWRITE_OBJECTS);
157
+ const overwriteObjectsQuestion = {
158
+ type: CommandUtils.INQUIRER_TYPES.LIST,
159
+ name: ANSWERS_NAMES.OVERWRITE_OBJECTS,
160
+ message: message,
161
+ default: true,
162
+ choices: [
163
+ { name: NodeTranslationService.getMessage(YES), value: true },
164
+ { name: NodeTranslationService.getMessage(NO), value: false },
165
+ ],
166
+ };
167
+ const answers = await prompt([overwriteObjectsQuestion]);
168
+ return answers[ANSWERS_NAMES.OVERWRITE_OBJECTS];
169
+ }
170
+ };
@@ -0,0 +1,61 @@
1
+ /*
2
+ ** Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3
+ ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
+ */
5
+ 'use strict';
6
+ const BaseOutputHandler = require('../../base/BaseOutputHandler');
7
+ const NodeTranslationService = require('../../../services/NodeTranslationService');
8
+
9
+ const {
10
+ CLI,
11
+ COMMAND_UPDATE: { OUTPUT },
12
+ } = require('../../../services/TranslationKeys');
13
+
14
+ const UPDATED_OBJECT_TYPE = {
15
+ SUCCESS: 'SUCCESS',
16
+ };
17
+
18
+ module.exports = class UpdateOutputHandler extends BaseOutputHandler {
19
+ constructor(options) {
20
+ super(options);
21
+ }
22
+
23
+ parse(actionResult) {
24
+ // updated CustomRecordsWithInstances has been already logged during the action execution.
25
+ this._parseUpdateObjects(actionResult);
26
+ this._logNonInteractiveExecForCustomRecordWithInstances(actionResult);
27
+ return actionResult;
28
+ }
29
+
30
+ _parseUpdateObjects(actionResult) {
31
+ const updatedObjects = actionResult.data.filter(
32
+ (element) => element.type === UPDATED_OBJECT_TYPE.SUCCESS && (!element.includeinstances || element.includeinstances === false)
33
+ );
34
+ const noUpdatedObjects = actionResult.data.filter(
35
+ (element) => element.type !== UPDATED_OBJECT_TYPE.SUCCESS && (!element.includeinstances || element.includeinstances === false)
36
+ );
37
+ const sortByKey = (a, b) => (a.key > b.key ? 1 : -1);
38
+
39
+ if (updatedObjects.length > 0) {
40
+ this._log.result(NodeTranslationService.getMessage(OUTPUT.UPDATED_OBJECTS));
41
+ updatedObjects.sort(sortByKey).forEach((updatedObject) => {
42
+ this._log.result(`${this._log.getPadding(1)}- ${updatedObject.key}`);
43
+ });
44
+ }
45
+ if (noUpdatedObjects.length > 0) {
46
+ this._log.warning(NodeTranslationService.getMessage(OUTPUT.NO_UPDATED_OBJECTS));
47
+ noUpdatedObjects.sort(sortByKey).forEach((noUpdatedObject) => {
48
+ this._log.warning(`${this._log.getPadding(1)}- ${noUpdatedObject.key}: ${noUpdatedObject.message}`);
49
+ });
50
+ }
51
+ }
52
+
53
+ _logNonInteractiveExecForCustomRecordWithInstances(actionResult) {
54
+ const objectsWithInstances = actionResult.data.filter((element) => element.includeinstances === true);
55
+
56
+ if (objectsWithInstances.length > 0) {
57
+ const scriptids = objectsWithInstances.map((object) => object.key).sort();
58
+ this._log.info(NodeTranslationService.getMessage(CLI.SHOW_NOT_INTERACTIVE_COMMAND_MESSAGE_CUSTOM_RECORDS, scriptids.join(' ')));
59
+ }
60
+ }
61
+ };