@sap-ux/odata-service-inquirer 0.5.28 → 0.5.30

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 (32) hide show
  1. package/dist/error-handler/error-handler.d.ts +2 -2
  2. package/dist/error-handler/error-handler.js +4 -4
  3. package/dist/index.d.ts +2 -12
  4. package/dist/index.js +3 -20
  5. package/dist/prompts/connectionValidator.d.ts +121 -27
  6. package/dist/prompts/connectionValidator.js +231 -36
  7. package/dist/prompts/datasources/sap-system/abap-on-btp/cf-helper.d.ts +9 -0
  8. package/dist/prompts/datasources/sap-system/abap-on-btp/cf-helper.js +55 -0
  9. package/dist/prompts/datasources/sap-system/abap-on-btp/questions.d.ts +34 -0
  10. package/dist/prompts/datasources/sap-system/abap-on-btp/questions.js +213 -0
  11. package/dist/prompts/datasources/sap-system/abap-on-prem/questions.d.ts +7 -16
  12. package/dist/prompts/datasources/sap-system/abap-on-prem/questions.js +16 -164
  13. package/dist/prompts/datasources/sap-system/new-system/questions.d.ts +36 -5
  14. package/dist/prompts/datasources/sap-system/new-system/questions.js +229 -37
  15. package/dist/prompts/datasources/sap-system/{abap-on-prem → new-system}/service-helper.d.ts +11 -1
  16. package/dist/prompts/datasources/sap-system/{abap-on-prem → new-system}/service-helper.js +30 -1
  17. package/dist/prompts/datasources/sap-system/new-system/types.d.ts +16 -0
  18. package/dist/prompts/datasources/sap-system/new-system/types.js +9 -0
  19. package/dist/prompts/datasources/sap-system/prompt-helpers.d.ts +3 -3
  20. package/dist/prompts/datasources/sap-system/prompt-helpers.js +4 -4
  21. package/dist/prompts/datasources/sap-system/validators.d.ts +10 -1
  22. package/dist/prompts/datasources/sap-system/validators.js +27 -2
  23. package/dist/prompts/datasources/service-url/questions.js +20 -8
  24. package/dist/prompts/datasources/service-url/validators.d.ts +4 -4
  25. package/dist/prompts/datasources/service-url/validators.js +4 -6
  26. package/dist/prompts/prompts.js +6 -9
  27. package/dist/translations/odata-service-inquirer.i18n.json +24 -4
  28. package/dist/types.d.ts +13 -3
  29. package/dist/types.js +5 -1
  30. package/dist/utils/index.d.ts +17 -0
  31. package/dist/utils/index.js +29 -1
  32. package/package.json +2 -1
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getCFDiscoverPrompts = exports.getAbapOnBTPSystemQuestions = void 0;
7
+ const yeoman_ui_types_1 = require("@sap-devx/yeoman-ui-types");
8
+ const inquirer_common_1 = require("@sap-ux/inquirer-common");
9
+ const cf_tools_1 = require("@sap/cf-tools");
10
+ const error_handler_1 = require("../../../../error-handler/error-handler");
11
+ const i18n_1 = require("../../../../i18n");
12
+ const types_1 = require("../../../../types");
13
+ const utils_1 = require("../../../../utils");
14
+ const connectionValidator_1 = require("../../../connectionValidator");
15
+ const logger_helper_1 = __importDefault(require("../../../logger-helper"));
16
+ const prompt_helpers_1 = require("../../../prompt-helpers");
17
+ const questions_1 = require("../new-system/questions");
18
+ const types_2 = require("../new-system/types");
19
+ const validators_1 = require("../validators");
20
+ const cf_helper_1 = require("./cf-helper");
21
+ const abapOnBtpPromptNamespace = 'abapOnBtp';
22
+ const systemUrlPromptName = `${abapOnBtpPromptNamespace}:${types_2.newSystemPromptNames.newSystemUrl}`;
23
+ const cliCfAbapServicePromptName = 'cliCfAbapService';
24
+ const abapOnBtpPromptNames = {
25
+ 'abapOnBtpAuthType': 'abapOnBtpAuthType',
26
+ 'serviceKey': 'serviceKey',
27
+ 'cloudFoundryAbapSystem': 'cloudFoundryAbapSystem'
28
+ };
29
+ /**
30
+ * Get the questions for the ABAP on BTP system. The questions will prompt the user for the system type (Cloud Foundry, Service Key, Re-entrance Ticket).
31
+ *
32
+ * @param promptOptions The prompt options which control the service selection and system name]
33
+ * @returns The list of questions for the ABAP on BTP system
34
+ */
35
+ function getAbapOnBTPSystemQuestions(promptOptions) {
36
+ utils_1.PromptState.reset();
37
+ const connectValidator = new connectionValidator_1.ConnectionValidator();
38
+ const questions = [];
39
+ questions.push({
40
+ type: 'list',
41
+ name: abapOnBtpPromptNames.abapOnBtpAuthType,
42
+ choices: [
43
+ { name: (0, i18n_1.t)('prompts.abapOnBTPType.choiceCloudFoundry'), value: 'cloudFoundry' },
44
+ { name: (0, i18n_1.t)('prompts.abapOnBTPType.choiceServiceKey'), value: 'serviceKey' },
45
+ { name: (0, i18n_1.t)('prompts.abapOnBTPType.choiceReentranceTicket'), value: 'reentranceTicket' }
46
+ ],
47
+ message: (0, i18n_1.t)('prompts.abapOnBTPType.message'),
48
+ // Only runs on YUI, but we only need to reset on YUI as the user cannot change previous values on the Yo CLI
49
+ validate: () => {
50
+ connectValidator.resetConnectionState();
51
+ return true;
52
+ }
53
+ });
54
+ // Re-entrance ticket system prompt
55
+ questions.push((0, inquirer_common_1.withCondition)([
56
+ (0, questions_1.getSystemUrlQuestion)(connectValidator, abapOnBtpPromptNamespace, promptOptions?.serviceSelection?.requiredOdataVersion)
57
+ ], (answers) => {
58
+ if (answers?.abapOnBtpAuthType === 'reentranceTicket') {
59
+ connectValidator.systemAuthType = answers.abapOnBtpAuthType;
60
+ return true;
61
+ }
62
+ return false;
63
+ })[0]);
64
+ // Service Key file prompt
65
+ questions.push((0, inquirer_common_1.withCondition)([getServiceKeyPrompt(connectValidator)], (answers) => answers?.abapOnBtpAuthType === 'serviceKey')[0]);
66
+ questions.push(...(0, inquirer_common_1.withCondition)([...getCFDiscoverPrompts(connectValidator)], (answers) => answers?.abapOnBtpAuthType === 'cloudFoundry'));
67
+ // New system store name propmt
68
+ if (promptOptions?.userSystemName?.hide !== true) {
69
+ // New system question will allow user to give the system a user friendly name
70
+ questions.push((0, inquirer_common_1.withCondition)([(0, questions_1.getUserSystemNameQuestion)(connectValidator, abapOnBtpPromptNamespace)], () => !!connectValidator.validatedUrl &&
71
+ connectValidator.validity.reachable === true &&
72
+ (connectValidator.validity.authenticated ?? connectValidator.validity.authRequired !== true))[0]);
73
+ }
74
+ // Service selection prompt
75
+ questions.push(...(0, questions_1.getSystemServiceQuestion)(connectValidator, abapOnBtpPromptNamespace, promptOptions));
76
+ return questions;
77
+ }
78
+ exports.getAbapOnBTPSystemQuestions = getAbapOnBTPSystemQuestions;
79
+ /**
80
+ * Validate the service info for the ABAP on BTP system. This function will validate the service key file and the connection to the ABAP system.
81
+ *
82
+ * @param abapService the abap service as provided by CF tools
83
+ * @param connectionValidator connection validator instance
84
+ * @param isCli validation on CLI ill throw rather than returning a validation message as users cannot change previous answers on CLI
85
+ * @returns true if the service info is valid, a validation message if the service info is invalid, or a validation link if the service info is not validated but some help is available
86
+ */
87
+ async function validateServiceInfo(abapService, connectionValidator, isCli = false) {
88
+ const uaaCreds = await (0, cf_tools_1.apiGetInstanceCredentials)(abapService.label);
89
+ const valResult = await connectionValidator.validateServiceInfo(uaaCreds.credentials);
90
+ if (!isCli && valResult !== true) {
91
+ return valResult;
92
+ }
93
+ // CLI only - we throw to exit as the user cannot change the previous answers
94
+ // Cannot authenticate, nothing can be done
95
+ if (isCli && typeof valResult === 'string') {
96
+ logger_helper_1.default.logger.error(valResult);
97
+ throw new Error(valResult);
98
+ }
99
+ // Cannot authenticate, nothing can be done
100
+ if (isCli && valResult === false) {
101
+ logger_helper_1.default.logger.error(prompt_helpers_1.errorHandler.getErrorMsg() ?? (0, i18n_1.t)('errors.abapServiceAuthenticationFailed'));
102
+ throw new Error((0, i18n_1.t)('errors.abapServiceAuthenticationFailed'));
103
+ }
104
+ // CLI only ^^^
105
+ if (connectionValidator.serviceProvider) {
106
+ // Create a unique connected system name based on the selected ABAP service
107
+ const cfTarget = await (0, cf_tools_1.cfGetTarget)(true);
108
+ connectionValidator.connectedSystemName = `abap-cloud-${abapService.label}-${cfTarget.org}-${cfTarget.space}`
109
+ .replace(/[^\w]/gi, '-')
110
+ .toLowerCase();
111
+ utils_1.PromptState.odataService.connectedSystem = {
112
+ serviceProvider: connectionValidator.serviceProvider
113
+ };
114
+ }
115
+ return true;
116
+ }
117
+ /**
118
+ * Get the Cloud Foundry Abap system discovery prompt. This prompt will list all available ABAP environments in the connected Cloud Foundry space.
119
+ * If the Cloud Foundry connection fails, a warning message will be displayed.
120
+ *
121
+ * @param connectionValidator The connection validator
122
+ * @returns The Cloud Foundry ABAP system discovery prompt
123
+ */
124
+ function getCFDiscoverPrompts(connectionValidator) {
125
+ let choices = [];
126
+ const questions = [
127
+ {
128
+ type: 'list',
129
+ name: abapOnBtpPromptNames.cloudFoundryAbapSystem,
130
+ guiOptions: {
131
+ breadcrumb: true,
132
+ applyDefaultWhenDirty: true
133
+ },
134
+ choices: async () => {
135
+ choices = await (0, cf_helper_1.getABAPInstanceChoices)();
136
+ // Cannot continue if no ABAP environments are found on Yo CLI
137
+ if (choices.length === 0) {
138
+ if ((0, utils_1.getHostEnvironment)() === types_1.hostEnvironment.cli) {
139
+ throw new Error((0, i18n_1.t)('errors.abapEnvsUnavailable'));
140
+ }
141
+ }
142
+ return choices;
143
+ },
144
+ default: () => (0, utils_1.getDefaultChoiceIndex)(choices),
145
+ message: (0, i18n_1.t)('prompts.cloudFoundryAbapSystem.message'),
146
+ validate: async (abapService) => {
147
+ if (abapService) {
148
+ return await validateServiceInfo(abapService, connectionValidator);
149
+ }
150
+ return false;
151
+ },
152
+ additionalMessages: () => {
153
+ const errorType = prompt_helpers_1.errorHandler.getCurrentErrorType();
154
+ if (errorType === error_handler_1.ERROR_TYPE.NO_ABAP_ENVS) {
155
+ const errorMsg = prompt_helpers_1.errorHandler.getErrorMsg(true);
156
+ const seeLogMsg = (0, i18n_1.t)('texts.seeLogForDetails');
157
+ return {
158
+ message: `${errorMsg} ${seeLogMsg}`,
159
+ severity: yeoman_ui_types_1.Severity.warning
160
+ };
161
+ }
162
+ }
163
+ }
164
+ ];
165
+ // Only for CLI use as `list` prompt validation does not run on CLI
166
+ if ((0, utils_1.getHostEnvironment)() === types_1.hostEnvironment.cli) {
167
+ questions.push({
168
+ when: async (answers) => {
169
+ const abapService = answers?.[abapOnBtpPromptNames.cloudFoundryAbapSystem];
170
+ if (abapService) {
171
+ await validateServiceInfo(abapService, connectionValidator, true);
172
+ }
173
+ return false;
174
+ },
175
+ name: cliCfAbapServicePromptName
176
+ });
177
+ }
178
+ return questions;
179
+ }
180
+ exports.getCFDiscoverPrompts = getCFDiscoverPrompts;
181
+ /**
182
+ * Get the service key prompt for the ABAP on BTP system. This prompt will allow the user to select a service key file from the file system.
183
+ *
184
+ * @param connectionValidator a connection validator instance
185
+ * @returns The service key prompt
186
+ */
187
+ function getServiceKeyPrompt(connectionValidator) {
188
+ const question = {
189
+ type: 'input',
190
+ name: abapOnBtpPromptNames.serviceKey,
191
+ message: (0, i18n_1.t)('prompts.serviceKey.message'),
192
+ guiType: 'file-browser',
193
+ guiOptions: {
194
+ hint: (0, i18n_1.t)('prompts.serviceKey.hint'),
195
+ mandatory: true
196
+ },
197
+ validate: async (keyPath) => {
198
+ const serviceKeyValResult = (0, validators_1.validateServiceKey)(keyPath);
199
+ if (typeof serviceKeyValResult === 'string' || typeof serviceKeyValResult === 'boolean') {
200
+ return serviceKeyValResult;
201
+ }
202
+ const connectValResult = await connectionValidator.validateServiceInfo(serviceKeyValResult);
203
+ if (connectValResult === true && connectionValidator.serviceProvider) {
204
+ utils_1.PromptState.odataService.connectedSystem = {
205
+ serviceProvider: connectionValidator.serviceProvider
206
+ };
207
+ }
208
+ return connectValResult;
209
+ }
210
+ };
211
+ return question;
212
+ }
213
+ //# sourceMappingURL=questions.js.map
@@ -1,30 +1,20 @@
1
- import { ODataVersion } from '@sap-ux/axios-extension';
2
- import { OdataVersion } from '@sap-ux/odata-service-writer';
1
+ import type { OdataVersion } from '@sap-ux/odata-service-writer';
3
2
  import type { Question } from 'inquirer';
4
- import { promptNames, type OdataServiceAnswers, type OdataServicePromptOptions, type SystemNamePromptOptions } from '../../../../types';
3
+ import type { OdataServiceAnswers, OdataServicePromptOptions, SystemNamePromptOptions, promptNames } from '../../../../types';
5
4
  import { ConnectionValidator } from '../../../connectionValidator';
6
- import type { NewSystemAnswers } from '../new-system/questions';
5
+ import { type ServiceAnswer } from '../new-system/types';
6
+ declare const systemUrlPromptName: "abapOnPrem:newSystemUrl";
7
7
  export declare enum abapOnPremInternalPromptNames {
8
- systemUrl = "systemUrl",
9
8
  sapClient = "sapClient",
10
9
  systemUsername = "abapSystemUsername",
11
10
  systemPassword = "abapSystemPassword"
12
11
  }
13
- export interface AbapOnPremAnswers extends Partial<OdataServiceAnswers>, NewSystemAnswers {
14
- [abapOnPremInternalPromptNames.systemUrl]?: string;
12
+ interface AbapOnPremAnswers extends Partial<OdataServiceAnswers> {
13
+ [systemUrlPromptName]?: string;
15
14
  [abapOnPremInternalPromptNames.systemUsername]?: string;
16
15
  [abapOnPremInternalPromptNames.systemPassword]?: string;
17
16
  [promptNames.serviceSelection]?: ServiceAnswer;
18
17
  }
19
- /**
20
- * Sap System service answer
21
- */
22
- export type ServiceAnswer = {
23
- servicePath: string;
24
- serviceODataVersion: ODataVersion;
25
- toString: () => string;
26
- serviceType?: string;
27
- };
28
18
  /**
29
19
  * Get the Abap on-premise datasource questions.
30
20
  *
@@ -41,4 +31,5 @@ export declare function getAbapOnPremQuestions(promptOptions?: OdataServicePromp
41
31
  * @returns the Abap on-premise system questions
42
32
  */
43
33
  export declare function getAbapOnPremSystemQuestions(systemNamePromptOptions?: SystemNamePromptOptions, connectionValidator?: ConnectionValidator, requiredOdataVersion?: OdataVersion): Question<AbapOnPremAnswers>[];
34
+ export {};
44
35
  //# sourceMappingURL=questions.d.ts.map
@@ -1,41 +1,21 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getAbapOnPremSystemQuestions = exports.getAbapOnPremQuestions = exports.abapOnPremInternalPromptNames = void 0;
7
- const yeoman_ui_types_1 = require("@sap-devx/yeoman-ui-types");
8
- const axios_extension_1 = require("@sap-ux/axios-extension");
9
4
  const inquirer_common_1 = require("@sap-ux/inquirer-common");
10
- const odata_service_writer_1 = require("@sap-ux/odata-service-writer");
11
5
  const project_input_validator_1 = require("@sap-ux/project-input-validator");
12
6
  const i18n_1 = require("../../../../i18n");
13
- const types_1 = require("../../../../types");
14
7
  const utils_1 = require("../../../../utils");
15
8
  const connectionValidator_1 = require("../../../connectionValidator");
16
- const logger_helper_1 = __importDefault(require("../../../logger-helper"));
17
9
  const questions_1 = require("../new-system/questions");
18
- const service_helper_1 = require("./service-helper");
10
+ const types_1 = require("../new-system/types");
11
+ const abapOnPremPromptNamespace = 'abapOnPrem';
12
+ const systemUrlPromptName = `${abapOnPremPromptNamespace}:${types_1.newSystemPromptNames.newSystemUrl}`;
19
13
  var abapOnPremInternalPromptNames;
20
14
  (function (abapOnPremInternalPromptNames) {
21
- abapOnPremInternalPromptNames["systemUrl"] = "systemUrl";
22
15
  abapOnPremInternalPromptNames["sapClient"] = "sapClient";
23
16
  abapOnPremInternalPromptNames["systemUsername"] = "abapSystemUsername";
24
17
  abapOnPremInternalPromptNames["systemPassword"] = "abapSystemPassword";
25
18
  })(abapOnPremInternalPromptNames || (exports.abapOnPremInternalPromptNames = abapOnPremInternalPromptNames = {}));
26
- const cliServicePromptName = 'cliServicePromptName';
27
- /**
28
- * Convert the odata version type from the prompt (odata-service-writer) type to the axios-extension type.
29
- *
30
- * @param odataVersion The odata version to convert
31
- * @returns The converted odata version
32
- */
33
- function convertODataVersionType(odataVersion) {
34
- if (!odataVersion) {
35
- return undefined;
36
- }
37
- return odataVersion === odata_service_writer_1.OdataVersion.v2 ? axios_extension_1.ODataVersion.v2 : axios_extension_1.ODataVersion.v4;
38
- }
39
19
  /**
40
20
  * Get the Abap on-premise datasource questions.
41
21
  *
@@ -45,97 +25,10 @@ function convertODataVersionType(odataVersion) {
45
25
  function getAbapOnPremQuestions(promptOptions) {
46
26
  utils_1.PromptState.reset();
47
27
  const connectValidator = new connectionValidator_1.ConnectionValidator();
48
- let serviceChoices;
49
- // Prevent re-requesting services repeatedly by only requesting them once and when the system is changed
50
- let previousSystemUrl;
51
- let previousService;
52
28
  // Prompt options
53
29
  const requiredOdataVersion = promptOptions?.serviceSelection?.requiredOdataVersion;
54
30
  const questions = getAbapOnPremSystemQuestions(promptOptions?.userSystemName, connectValidator, requiredOdataVersion);
55
- questions.push({
56
- when: () => connectValidator.validity.authenticated || connectValidator.validity.authRequired === false,
57
- name: types_1.promptNames.serviceSelection,
58
- type: promptOptions?.serviceSelection?.useAutoComplete ? 'autocomplete' : 'list',
59
- message: (0, i18n_1.t)('prompts.systemService.message'),
60
- guiOptions: {
61
- breadcrumb: (0, i18n_1.t)('prompts.systemService.breadcrumb'),
62
- mandatory: true,
63
- applyDefaultWhenDirty: true
64
- },
65
- source: (prevAnswers, input) => (0, inquirer_common_1.searchChoices)(input, serviceChoices),
66
- choices: async (answers) => {
67
- if (!serviceChoices || previousSystemUrl !== answers.systemUrl) {
68
- let catalogs = [];
69
- if (requiredOdataVersion) {
70
- catalogs.push(connectValidator.catalogs[requiredOdataVersion]);
71
- }
72
- else {
73
- catalogs = Object.values(connectValidator.catalogs);
74
- }
75
- previousSystemUrl = answers.systemUrl;
76
- serviceChoices = await (0, service_helper_1.getServiceChoices)(catalogs);
77
- }
78
- return serviceChoices;
79
- },
80
- additionalMessages: async (selectedService) => {
81
- if (serviceChoices?.length === 0) {
82
- if (requiredOdataVersion) {
83
- return {
84
- message: (0, i18n_1.t)('prompts.warnings.noServicesAvailableForOdataVersion', {
85
- odataVersion: requiredOdataVersion
86
- }),
87
- severity: yeoman_ui_types_1.Severity.warning
88
- };
89
- }
90
- else {
91
- return {
92
- message: (0, i18n_1.t)('prompts.warnings.noServicesAvailable'),
93
- severity: yeoman_ui_types_1.Severity.warning
94
- };
95
- }
96
- }
97
- if (selectedService) {
98
- let serviceType = selectedService.serviceType;
99
- if (selectedService.serviceODataVersion === axios_extension_1.ODataVersion.v2) {
100
- serviceType = await (0, service_helper_1.getServiceType)(selectedService.servicePath, selectedService.serviceType, connectValidator.catalogs[axios_extension_1.ODataVersion.v2]);
101
- }
102
- if (serviceType && serviceType !== axios_extension_1.ServiceType.UI) {
103
- return {
104
- message: (0, i18n_1.t)('prompts.warnings.nonUIServiceTypeWarningMessage', { serviceType: 'A2X' }),
105
- severity: yeoman_ui_types_1.Severity.warning
106
- };
107
- }
108
- }
109
- },
110
- default: () => (serviceChoices?.length > 1 ? undefined : 0),
111
- // Warning: only executes in YUI not cli
112
- validate: async (service, { systemUrl } = {}) => {
113
- if (!systemUrl) {
114
- return false;
115
- }
116
- // Dont re-request the same service details
117
- if (service && previousService?.servicePath !== service.servicePath) {
118
- previousService = service;
119
- return getServiceDetails(service, systemUrl, connectValidator);
120
- }
121
- return true;
122
- }
123
- });
124
- // Only for CLI use as `list` prompt validation does not run on CLI
125
- if ((0, utils_1.getHostEnvironment)() === types_1.hostEnvironment.cli) {
126
- questions.push({
127
- when: async (answers) => {
128
- if (answers.serviceSelection && answers.systemUrl) {
129
- const result = await getServiceDetails(answers.serviceSelection, answers.systemUrl, connectValidator);
130
- if (typeof result === 'string') {
131
- logger_helper_1.default.logger.error(result);
132
- }
133
- }
134
- return false;
135
- },
136
- name: cliServicePromptName
137
- });
138
- }
31
+ questions.push(...(0, questions_1.getSystemServiceQuestion)(connectValidator, abapOnPremPromptNamespace, promptOptions));
139
32
  return questions;
140
33
  }
141
34
  exports.getAbapOnPremQuestions = getAbapOnPremQuestions;
@@ -151,28 +44,7 @@ function getAbapOnPremSystemQuestions(systemNamePromptOptions, connectionValidat
151
44
  const connectValidator = connectionValidator ?? new connectionValidator_1.ConnectionValidator();
152
45
  let validClient = true;
153
46
  const questions = [
154
- {
155
- type: 'input',
156
- name: abapOnPremInternalPromptNames.systemUrl,
157
- message: (0, i18n_1.t)('prompts.systemUrl.message'),
158
- guiOptions: {
159
- hint: (0, i18n_1.t)('prompts.systemUrl.description'),
160
- mandatory: true,
161
- breadcrumb: true
162
- },
163
- validate: async (url) => {
164
- const valResult = await connectValidator.validateUrl(url, {
165
- isSystem: true,
166
- odataVersion: convertODataVersionType(requiredOdataVersion)
167
- });
168
- if (valResult === true) {
169
- utils_1.PromptState.odataService.connectedSystem = {
170
- serviceProvider: connectValidator.serviceProvider
171
- };
172
- }
173
- return valResult;
174
- }
175
- },
47
+ (0, questions_1.getSystemUrlQuestion)(connectValidator, abapOnPremPromptNamespace, requiredOdataVersion),
176
48
  {
177
49
  type: 'input',
178
50
  name: abapOnPremInternalPromptNames.sapClient,
@@ -198,6 +70,7 @@ function getAbapOnPremSystemQuestions(systemNamePromptOptions, connectionValidat
198
70
  guiOptions: {
199
71
  mandatory: true
200
72
  },
73
+ default: '',
201
74
  validate: (user) => user?.length > 0
202
75
  },
203
76
  {
@@ -210,53 +83,32 @@ function getAbapOnPremSystemQuestions(systemNamePromptOptions, connectionValidat
210
83
  message: (0, i18n_1.t)('prompts.systemPassword.message'),
211
84
  guiType: 'login',
212
85
  mask: '*',
213
- validate: async (password, { systemUrl, abapSystemUsername, sapClient }) => {
214
- if (!(systemUrl && abapSystemUsername && password && validClient)) {
86
+ default: '',
87
+ validate: async (password, answers) => {
88
+ if (!(connectValidator.validatedUrl && answers.abapSystemUsername && password && validClient)) {
215
89
  return false;
216
90
  }
217
- const valResult = await connectValidator.validateAuth(systemUrl, abapSystemUsername, password, {
218
- isSystem: true,
219
- sapClient
91
+ const valResult = await connectValidator.validateAuth(connectValidator.validatedUrl, answers.abapSystemUsername, password, {
92
+ sapClient: answers.sapClient,
93
+ isSystem: true
220
94
  });
221
- if (valResult === true) {
95
+ if (valResult === true && connectValidator.serviceProvider) {
222
96
  utils_1.PromptState.odataService.connectedSystem = {
223
97
  serviceProvider: connectValidator.serviceProvider
224
98
  };
99
+ return true;
225
100
  }
226
101
  return valResult;
227
102
  }
228
103
  }
229
104
  ];
230
- if (systemNamePromptOptions?.exclude !== true) {
105
+ if (systemNamePromptOptions?.hide !== true) {
231
106
  // New system question will allow user to give the system a user friendly name
232
- questions.push((0, inquirer_common_1.withCondition)([(0, questions_1.getUserSystemNameQuestion)()], (answers) => !!answers.systemUrl &&
107
+ questions.push((0, inquirer_common_1.withCondition)([(0, questions_1.getUserSystemNameQuestion)(connectValidator, abapOnPremPromptNamespace)], (answers) => !!answers?.[systemUrlPromptName] &&
233
108
  connectValidator.validity.reachable === true &&
234
109
  (connectValidator.validity.authenticated || connectValidator.validity.authRequired !== true))[0]);
235
110
  }
236
111
  return questions;
237
112
  }
238
113
  exports.getAbapOnPremSystemQuestions = getAbapOnPremSystemQuestions;
239
- /**
240
- * Requests and sets the service details to the PromptState.odataService properties.
241
- * If an error occurs, the error message is returned for use in validators.
242
- *
243
- * @param service the specific service to get details for
244
- * @param systemUrl the system origin where the service is hosted
245
- * @param connectionValidator a reference to the connection validator
246
- * @returns true if successful, setting the PromptState.odataService properties, or an error message indicating why the service details could not be retrieved.
247
- */
248
- async function getServiceDetails(service, systemUrl, connectionValidator) {
249
- const serviceCatalog = connectionValidator.catalogs[service.serviceODataVersion];
250
- const serviceResult = await (0, service_helper_1.getServiceMetadata)(service.servicePath, serviceCatalog, connectionValidator.serviceProvider);
251
- if (typeof serviceResult === 'string') {
252
- return serviceResult;
253
- }
254
- utils_1.PromptState.odataService.annotations = serviceResult?.annotations;
255
- utils_1.PromptState.odataService.metadata = serviceResult?.metadata;
256
- utils_1.PromptState.odataService.odataVersion =
257
- service.serviceODataVersion === axios_extension_1.ODataVersion.v2 ? odata_service_writer_1.OdataVersion.v2 : odata_service_writer_1.OdataVersion.v4;
258
- utils_1.PromptState.odataService.servicePath = service.servicePath;
259
- utils_1.PromptState.odataService.origin = systemUrl;
260
- return true;
261
- }
262
114
  //# sourceMappingURL=questions.js.map
@@ -1,10 +1,11 @@
1
- import type { InputQuestion, Question } from 'inquirer';
1
+ import { type InputQuestion } from '@sap-ux/inquirer-common';
2
+ import type { OdataVersion } from '@sap-ux/odata-service-writer';
3
+ import type { Answers, Question } from 'inquirer';
2
4
  import type { OdataServiceAnswers, OdataServicePromptOptions, SapSystemType } from '../../../../types';
3
5
  import { promptNames } from '../../../../types';
6
+ import type { ConnectionValidator } from '../../../connectionValidator';
7
+ import { newSystemPromptNames } from './types';
4
8
  export declare const newSystemChoiceValue = "!@\u00A3*&937newSystem*X~qy^";
5
- declare const newSystemPromptNames: {
6
- readonly newSystemType: "newSystemType";
7
- };
8
9
  /**
9
10
  * Internal only answers to service URL prompting not returned with OdataServiceAnswers.
10
11
  */
@@ -25,11 +26,41 @@ export interface SystemSelectionAnswer extends OdataServiceAnswers {
25
26
  * @returns questions for creating a new system connection
26
27
  */
27
28
  export declare function getNewSystemQuestions(promptOptions?: OdataServicePromptOptions): Question<NewSystemAnswers>[];
29
+ /**
30
+ * Get the system url prompt. The system url prompt is used to connect to a new system using the user input system url.
31
+ *
32
+ * @param connectValidator a connection validator instance used to validate the system url
33
+ * @param promptNamespace The namespace for the prompt, used to identify the prompt instance and namespaced answers.
34
+ * @param requiredOdataVersion The required OData version for the system connection, only catalogs supporting the specifc odata version will be used.
35
+ * @returns the system url prompt
36
+ */
37
+ export declare function getSystemUrlQuestion<T extends Answers>(connectValidator: ConnectionValidator, promptNamespace?: string, requiredOdataVersion?: OdataVersion): InputQuestion<T>;
28
38
  /**
29
39
  * Get a prompt for new system name.
30
40
  *
41
+ * @param connectValidator A reference to the active connection validator,
42
+ * at prompt execution time the connection properties will be used to create a new BackendSystem, set into the PromptState.odataService.connectedSystem
43
+ * @param promptNamespace The namespace for the prompt, used to identify the prompt instance and namespaced answers.
44
+ * This prevents conflicts with other prompts of the same types where the same prompt is used by multiple other prompts but cannot share the name.
31
45
  * @returns the new system name prompt
32
46
  */
33
- export declare function getUserSystemNameQuestion(): InputQuestion<NewSystemAnswers>;
47
+ export declare function getUserSystemNameQuestion(connectValidator: ConnectionValidator, promptNamespace?: string): InputQuestion<Partial<NewSystemAnswers>>;
48
+ /**
49
+ * Create a value for the service selection prompt message, which may include thge active connected user name.
50
+ *
51
+ * @param username The connected user name
52
+ * @returns The service selection prompt message
53
+ */
54
+ export declare function getSelectedServiceLabel(username: string | undefined): string;
55
+ /**
56
+ * Get the service selection prompt for a system connection. The service selection prompt is used to select a service from the system catalog.
57
+ *
58
+ * @param connectValidator A reference to the active connection validator, used to validate the service selection and retrieve service details.
59
+ * @param promptNamespace The namespace for the prompt, used to identify the prompt instance and namespaced answers.
60
+ * This is used to avoid conflicts with other prompts of the same types.
61
+ * @param promptOptions Options for the service selection prompt see {@link OdataServicePromptOptions}
62
+ * @returns the service selection prompt
63
+ */
64
+ export declare function getSystemServiceQuestion<T extends Answers>(connectValidator: ConnectionValidator, promptNamespace: string, promptOptions?: OdataServicePromptOptions): Question<T>[];
34
65
  export {};
35
66
  //# sourceMappingURL=questions.d.ts.map