@sap-ux/odata-service-inquirer 0.5.59 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/error-handler/error-handler.d.ts +25 -3
  2. package/dist/error-handler/error-handler.js +154 -52
  3. package/dist/i18n.js +15 -3
  4. package/dist/index.d.ts +2 -2
  5. package/dist/index.js +1 -3
  6. package/dist/prompts/connectionValidator.d.ts +63 -12
  7. package/dist/prompts/connectionValidator.js +196 -38
  8. package/dist/prompts/datasources/sap-system/abap-on-btp/questions.d.ts +2 -1
  9. package/dist/prompts/datasources/sap-system/abap-on-btp/questions.js +3 -1
  10. package/dist/prompts/datasources/sap-system/abap-on-prem/questions.d.ts +9 -11
  11. package/dist/prompts/datasources/sap-system/abap-on-prem/questions.js +21 -55
  12. package/dist/prompts/datasources/sap-system/credentials/questions.d.ts +21 -0
  13. package/dist/prompts/datasources/sap-system/credentials/questions.js +123 -0
  14. package/dist/prompts/datasources/sap-system/new-system/questions.d.ts +4 -26
  15. package/dist/prompts/datasources/sap-system/new-system/questions.js +18 -168
  16. package/dist/prompts/datasources/sap-system/new-system/types.d.ts +0 -10
  17. package/dist/prompts/datasources/sap-system/service-selection/index.d.ts +3 -0
  18. package/dist/prompts/datasources/sap-system/service-selection/index.js +19 -0
  19. package/dist/prompts/datasources/sap-system/service-selection/questions.d.ts +15 -0
  20. package/dist/prompts/datasources/sap-system/service-selection/questions.js +146 -0
  21. package/dist/prompts/datasources/sap-system/service-selection/service-helper.d.ts +71 -0
  22. package/dist/prompts/datasources/sap-system/service-selection/service-helper.js +281 -0
  23. package/dist/prompts/datasources/sap-system/service-selection/types.d.ts +11 -0
  24. package/dist/prompts/datasources/sap-system/service-selection/types.js +3 -0
  25. package/dist/prompts/datasources/sap-system/system-selection/index.d.ts +2 -0
  26. package/dist/prompts/datasources/sap-system/system-selection/index.js +18 -0
  27. package/dist/prompts/datasources/sap-system/system-selection/prompt-helpers.d.ts +44 -0
  28. package/dist/prompts/datasources/sap-system/system-selection/prompt-helpers.js +190 -0
  29. package/dist/prompts/datasources/sap-system/system-selection/questions.d.ts +40 -0
  30. package/dist/prompts/datasources/sap-system/system-selection/questions.js +181 -0
  31. package/dist/prompts/datasources/sap-system/validators.d.ts +8 -0
  32. package/dist/prompts/datasources/sap-system/validators.js +17 -0
  33. package/dist/prompts/datasources/service-url/questions.js +2 -2
  34. package/dist/prompts/datasources/service-url/validators.js +5 -6
  35. package/dist/prompts/prompt-helpers.d.ts +1 -2
  36. package/dist/prompts/prompt-helpers.js +2 -11
  37. package/dist/prompts/prompts.js +5 -34
  38. package/dist/prompts/validators.d.ts +1 -1
  39. package/dist/prompts/validators.js +1 -1
  40. package/dist/translations/odata-service-inquirer.i18n.json +36 -15
  41. package/dist/types.d.ts +57 -10
  42. package/dist/types.js +7 -1
  43. package/dist/utils/index.d.ts +12 -3
  44. package/dist/utils/index.js +27 -5
  45. package/package.json +6 -6
  46. package/dist/prompts/datasources/sap-system/new-system/service-helper.d.ts +0 -43
  47. package/dist/prompts/datasources/sap-system/new-system/service-helper.js +0 -175
@@ -0,0 +1,21 @@
1
+ import type { Answers, Question } from 'inquirer';
2
+ import type { ConnectionValidator } from '../../../connectionValidator';
3
+ export declare enum BasicCredentialsPromptNames {
4
+ systemUsername = "systemUsername",
5
+ systemPassword = "systemPassword"
6
+ }
7
+ /**
8
+ * Re-usable credentials prompts for connection to systems using basic auth.
9
+ *
10
+ * @param connectionValidator
11
+ * @param promptNamespace
12
+ * @param sapClient
13
+ * @param sapClient.sapClient the sapClient value to be used along with the credentials validation
14
+ * @param sapClient.isValid validation of credentials is deferred until a valid sapClient is provided or undefined
15
+ * @returns the credentials prompts
16
+ */
17
+ export declare function getCredentialsPrompts<T extends Answers>(connectionValidator: ConnectionValidator, promptNamespace?: string, sapClient?: {
18
+ sapClient: string | undefined;
19
+ isValid: boolean;
20
+ }): Question<T>[];
21
+ //# sourceMappingURL=questions.d.ts.map
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BasicCredentialsPromptNames = void 0;
4
+ exports.getCredentialsPrompts = getCredentialsPrompts;
5
+ const btp_utils_1 = require("@sap-ux/btp-utils");
6
+ const i18n_1 = require("../../../../i18n");
7
+ const types_1 = require("../../../../types");
8
+ const utils_1 = require("../../../../utils");
9
+ var BasicCredentialsPromptNames;
10
+ (function (BasicCredentialsPromptNames) {
11
+ BasicCredentialsPromptNames["systemUsername"] = "systemUsername";
12
+ BasicCredentialsPromptNames["systemPassword"] = "systemPassword";
13
+ })(BasicCredentialsPromptNames || (exports.BasicCredentialsPromptNames = BasicCredentialsPromptNames = {}));
14
+ /**
15
+ * Re-usable credentials prompts for connection to systems using basic auth.
16
+ *
17
+ * @param connectionValidator
18
+ * @param promptNamespace
19
+ * @param sapClient
20
+ * @param sapClient.sapClient the sapClient value to be used along with the credentials validation
21
+ * @param sapClient.isValid validation of credentials is deferred until a valid sapClient is provided or undefined
22
+ * @returns the credentials prompts
23
+ */
24
+ function getCredentialsPrompts(connectionValidator, promptNamespace, sapClient) {
25
+ const usernamePromptName = `${promptNamespace ? promptNamespace + ':' : ''}${BasicCredentialsPromptNames.systemUsername}`;
26
+ const passwordPromptName = `${promptNamespace ? promptNamespace + ':' : ''}${BasicCredentialsPromptNames.systemPassword}`;
27
+ // Optimization to prevent re-checking of auth
28
+ let authRequired;
29
+ return [
30
+ {
31
+ when: async () => {
32
+ authRequired = await connectionValidator.isAuthRequired();
33
+ return connectionValidator.systemAuthType === 'basic' && authRequired;
34
+ },
35
+ type: 'input',
36
+ name: usernamePromptName,
37
+ message: (0, i18n_1.t)('prompts.systemUsername.message'),
38
+ guiOptions: {
39
+ mandatory: true
40
+ },
41
+ default: '',
42
+ validate: (user) => user?.length > 0
43
+ },
44
+ {
45
+ when: () => connectionValidator.systemAuthType === 'basic' && authRequired,
46
+ type: 'password',
47
+ guiOptions: {
48
+ mandatory: true,
49
+ applyDefaultWhenDirty: true // Reset when the system changes, this avoids automatic reauth with the existing creds if the user changes the system selection
50
+ },
51
+ guiType: 'login',
52
+ name: passwordPromptName,
53
+ message: (0, i18n_1.t)('prompts.systemPassword.message'),
54
+ mask: '*',
55
+ default: '',
56
+ validate: async (password, answers) => {
57
+ if (!(connectionValidator.validatedUrl &&
58
+ answers?.[usernamePromptName] &&
59
+ password &&
60
+ (sapClient?.isValid || !sapClient))) {
61
+ return false;
62
+ }
63
+ // We may have a previously selected system
64
+ const selectedSystem = answers?.[types_1.promptNames.systemSelection];
65
+ let selectedSystemClient;
66
+ let isSystem = true;
67
+ if (selectedSystem?.type === 'backendSystem') {
68
+ selectedSystemClient = selectedSystem.system?.client;
69
+ }
70
+ else if (selectedSystem?.type === 'destination') {
71
+ // Note no need to set the client as its specified by the destination itself
72
+ const destination = selectedSystem.system;
73
+ if ((0, btp_utils_1.isFullUrlDestination)(destination) || (0, btp_utils_1.isPartialUrlDestination)(destination)) {
74
+ isSystem = false;
75
+ }
76
+ }
77
+ const { valResult } = await connectionValidator.validateAuth(connectionValidator.validatedUrl, answers?.[usernamePromptName], password, {
78
+ sapClient: sapClient?.sapClient || selectedSystemClient,
79
+ isSystem
80
+ });
81
+ if (valResult === true && connectionValidator.serviceProvider) {
82
+ updatePromptStateWithConnectedSystem(connectionValidator.serviceProvider, selectedSystem, {
83
+ username: answers?.[usernamePromptName],
84
+ password: password
85
+ });
86
+ return true;
87
+ }
88
+ return valResult;
89
+ }
90
+ }
91
+ ];
92
+ }
93
+ /**
94
+ * Updates the prompt state with the connected system.
95
+ *
96
+ * @param serviceProvider the connected system service provider which is used to update the prompt state
97
+ * @param selectedSystem the selected system, either a backend system or a destination
98
+ * @param credentials
99
+ * @param credentials.username the username
100
+ * @param credentials.password the password
101
+ */
102
+ function updatePromptStateWithConnectedSystem(serviceProvider, selectedSystem, { username, password }) {
103
+ utils_1.PromptState.odataService.connectedSystem = {
104
+ serviceProvider
105
+ };
106
+ // Update the existing backend system with the new credentials that may be used to update in the store.
107
+ if (selectedSystem?.type === 'backendSystem') {
108
+ const backendSystem = selectedSystem.system;
109
+ // Have the credentials changed..
110
+ if (backendSystem.username !== username || backendSystem.password !== password) {
111
+ utils_1.PromptState.odataService.connectedSystem.backendSystem = Object.assign(backendSystem, {
112
+ username: username,
113
+ password,
114
+ newOrUpdated: true
115
+ });
116
+ }
117
+ // If the connection is successful and a destination was selected, assign the connected destination to the prompt state.
118
+ }
119
+ else if (selectedSystem?.type === 'destination') {
120
+ utils_1.PromptState.odataService.connectedSystem.destination = selectedSystem.system;
121
+ }
122
+ }
123
+ //# sourceMappingURL=questions.js.map
@@ -1,11 +1,13 @@
1
+ /**
2
+ * New system prompting questions for re-use in multiple sap-system datasource prompt sets.
3
+ */
1
4
  import { type InputQuestion } from '@sap-ux/inquirer-common';
2
5
  import type { OdataVersion } from '@sap-ux/odata-service-writer';
3
6
  import type { Answers, Question } from 'inquirer';
4
- import type { OdataServiceAnswers, OdataServicePromptOptions, SapSystemType } from '../../../../types';
7
+ import type { OdataServicePromptOptions, SapSystemType } from '../../../../types';
5
8
  import { promptNames } from '../../../../types';
6
9
  import type { ConnectionValidator } from '../../../connectionValidator';
7
10
  import { newSystemPromptNames } from './types';
8
- export declare const newSystemChoiceValue = "!@\u00A3*&937newSystem*X~qy^";
9
11
  /**
10
12
  * Internal only answers to service URL prompting not returned with OdataServiceAnswers.
11
13
  */
@@ -13,12 +15,6 @@ export interface NewSystemAnswers {
13
15
  [newSystemPromptNames.newSystemType]?: SapSystemType;
14
16
  [promptNames.userSystemName]?: string;
15
17
  }
16
- declare const systemSelectionPromptNames: {
17
- readonly system: "system";
18
- };
19
- export interface SystemSelectionAnswer extends OdataServiceAnswers {
20
- [systemSelectionPromptNames.system]?: string;
21
- }
22
18
  /**
23
19
  * Provides prompts that allow the creation of a new system connection.
24
20
  *
@@ -45,22 +41,4 @@ export declare function getSystemUrlQuestion<T extends Answers>(connectValidator
45
41
  * @returns the new system name prompt
46
42
  */
47
43
  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>[];
65
- export {};
66
44
  //# sourceMappingURL=questions.d.ts.map
@@ -1,37 +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
- exports.newSystemChoiceValue = void 0;
7
3
  exports.getNewSystemQuestions = getNewSystemQuestions;
8
4
  exports.getSystemUrlQuestion = getSystemUrlQuestion;
9
5
  exports.getUserSystemNameQuestion = getUserSystemNameQuestion;
10
- exports.getSelectedServiceLabel = getSelectedServiceLabel;
11
- exports.getSystemServiceQuestion = getSystemServiceQuestion;
12
- const yeoman_ui_types_1 = require("@sap-devx/yeoman-ui-types");
13
- const axios_extension_1 = require("@sap-ux/axios-extension");
6
+ /**
7
+ * New system prompting questions for re-use in multiple sap-system datasource prompt sets.
8
+ */
14
9
  const inquirer_common_1 = require("@sap-ux/inquirer-common");
15
10
  const store_1 = require("@sap-ux/store");
16
11
  const i18n_1 = require("../../../../i18n");
17
12
  const types_1 = require("../../../../types");
18
13
  const utils_1 = require("../../../../utils");
14
+ const questions_1 = require("../abap-on-btp/questions");
15
+ const questions_2 = require("../abap-on-prem/questions");
19
16
  const prompt_helpers_1 = require("../prompt-helpers");
20
17
  const validators_1 = require("../validators");
21
- const service_helper_1 = require("./service-helper");
22
18
  const types_2 = require("./types");
23
- const questions_1 = require("../abap-on-prem/questions");
24
- const questions_2 = require("../abap-on-btp/questions");
25
- const logger_helper_1 = __importDefault(require("../../../logger-helper"));
26
- const prompt_helpers_2 = require("../../../prompt-helpers");
27
- const error_handler_1 = require("../../../../error-handler/error-handler");
28
- // New system choice value is a hard to guess string to avoid conflicts with existing system names or user named systems
29
- // since it will be used as a new system value in the system selection prompt.
30
- exports.newSystemChoiceValue = '!@£*&937newSystem*X~qy^';
31
- const cliServicePromptName = 'cliServiceSelection';
32
- const systemSelectionPromptNames = {
33
- system: 'system'
34
- };
35
19
  /**
36
20
  * Convert the system connection scheme (Service Key, Rentrance Ticket, etc) to the store specific authentication type.
37
21
  * Note the absence of CF Discovery, in this case the service key file (UAA) is also used for the Abap connectivity.
@@ -69,8 +53,8 @@ function getNewSystemQuestions(promptOptions) {
69
53
  message: (0, i18n_1.t)('prompts.newSystemType.message')
70
54
  }
71
55
  ];
72
- questions.push(...(0, inquirer_common_1.withCondition)((0, questions_1.getAbapOnPremQuestions)(promptOptions), (answers) => answers.newSystemType === 'abapOnPrem'));
73
- questions.push(...(0, inquirer_common_1.withCondition)((0, questions_2.getAbapOnBTPSystemQuestions)(promptOptions), (answers) => answers.newSystemType === 'abapOnBtp'));
56
+ questions.push(...(0, inquirer_common_1.withCondition)((0, questions_2.getAbapOnPremQuestions)(promptOptions), (answers) => answers.newSystemType === 'abapOnPrem'));
57
+ questions.push(...(0, inquirer_common_1.withCondition)((0, questions_1.getAbapOnBTPSystemQuestions)(promptOptions), (answers) => answers.newSystemType === 'abapOnBtp'));
74
58
  return questions;
75
59
  }
76
60
  /**
@@ -97,11 +81,16 @@ function getSystemUrlQuestion(connectValidator, promptNamespace, requiredOdataVe
97
81
  isSystem: true,
98
82
  odataVersion: (0, utils_1.convertODataVersionType)(requiredOdataVersion)
99
83
  });
100
- // If basic auth not required we should have an active connection
101
- if (valResult === true && !connectValidator.validity.authRequired && connectValidator.serviceProvider) {
102
- utils_1.PromptState.odataService.connectedSystem = {
103
- serviceProvider: connectValidator.serviceProvider
104
- };
84
+ // If basic auth not required we should have an active connection (could be a re-entrance ticket supported system url)
85
+ if (valResult === true) {
86
+ if (!connectValidator.validity.authRequired && connectValidator.serviceProvider) {
87
+ utils_1.PromptState.odataService.connectedSystem = {
88
+ serviceProvider: connectValidator.serviceProvider
89
+ };
90
+ }
91
+ else {
92
+ connectValidator.systemAuthType = 'basic';
93
+ }
105
94
  }
106
95
  return valResult;
107
96
  }
@@ -169,6 +158,7 @@ function getUserSystemNameQuestion(connectValidator, promptNamespace) {
169
158
  refreshToken: connectValidator.refreshToken
170
159
  });
171
160
  utils_1.PromptState.odataService.connectedSystem.backendSystem = backendSystem;
161
+ utils_1.PromptState.odataService.connectedSystem.backendSystem.newOrUpdated = true;
172
162
  }
173
163
  }
174
164
  return isValid;
@@ -176,144 +166,4 @@ function getUserSystemNameQuestion(connectValidator, promptNamespace) {
176
166
  };
177
167
  return newSystemNamePrompt;
178
168
  }
179
- /**
180
- * Create a value for the service selection prompt message, which may include thge active connected user name.
181
- *
182
- * @param username The connected user name
183
- * @returns The service selection prompt message
184
- */
185
- function getSelectedServiceLabel(username) {
186
- let message = (0, i18n_1.t)('prompts.systemService.message');
187
- if (username) {
188
- message = message.concat(` ${(0, i18n_1.t)('texts.forUserName', { username })}`);
189
- }
190
- return message;
191
- }
192
- /**
193
- * Get the service selection prompt for a system connection. The service selection prompt is used to select a service from the system catalog.
194
- *
195
- * @param connectValidator A reference to the active connection validator, used to validate the service selection and retrieve service details.
196
- * @param promptNamespace The namespace for the prompt, used to identify the prompt instance and namespaced answers.
197
- * This is used to avoid conflicts with other prompts of the same types.
198
- * @param promptOptions Options for the service selection prompt see {@link OdataServicePromptOptions}
199
- * @returns the service selection prompt
200
- */
201
- function getSystemServiceQuestion(connectValidator, promptNamespace, promptOptions) {
202
- let serviceChoices = [];
203
- // Prevent re-requesting services repeatedly by only requesting them once and when the system or client is changed
204
- let previousSystemUrl;
205
- let previousClient;
206
- let previousService;
207
- const requiredOdataVersion = promptOptions?.serviceSelection?.requiredOdataVersion;
208
- const newSystemServiceQuestion = {
209
- when: () => connectValidator.validity.authenticated || connectValidator.validity.authRequired === false,
210
- name: `${promptNamespace}:${types_1.promptNames.serviceSelection}`,
211
- type: promptOptions?.serviceSelection?.useAutoComplete ? 'autocomplete' : 'list',
212
- message: () => getSelectedServiceLabel(connectValidator.connectedUserName),
213
- guiOptions: {
214
- breadcrumb: (0, i18n_1.t)('prompts.systemService.breadcrumb'),
215
- mandatory: true,
216
- applyDefaultWhenDirty: true
217
- },
218
- source: (prevAnswers, input) => (0, inquirer_common_1.searchChoices)(input, serviceChoices),
219
- choices: async () => {
220
- if (serviceChoices.length === 0 ||
221
- previousSystemUrl !== connectValidator.validatedUrl ||
222
- previousClient !== connectValidator.validatedClient) {
223
- let catalogs = [];
224
- if (requiredOdataVersion && connectValidator.catalogs[requiredOdataVersion]) {
225
- catalogs.push(connectValidator.catalogs[requiredOdataVersion]);
226
- }
227
- else {
228
- catalogs = Object.values(connectValidator.catalogs).filter((cat) => cat !== undefined);
229
- }
230
- previousSystemUrl = connectValidator.validatedUrl;
231
- previousClient = connectValidator.validatedClient;
232
- serviceChoices = await (0, service_helper_1.getServiceChoices)(catalogs);
233
- }
234
- return serviceChoices;
235
- },
236
- additionalMessages: (selectedService) => getSelectedServiceMessage(serviceChoices, selectedService, connectValidator, requiredOdataVersion),
237
- default: () => (0, utils_1.getDefaultChoiceIndex)(serviceChoices),
238
- // Warning: only executes in YUI not cli
239
- validate: async (service) => {
240
- if (!connectValidator.validatedUrl) {
241
- return false;
242
- }
243
- // if no choices are available and an error is present, return the error message
244
- if (serviceChoices.length === 0 && prompt_helpers_2.errorHandler.hasError()) {
245
- return error_handler_1.ErrorHandler.getHelpForError(error_handler_1.ERROR_TYPE.SERVICES_UNAVAILABLE) ?? false;
246
- }
247
- // Dont re-request the same service details
248
- if (service && previousService?.servicePath !== service.servicePath) {
249
- previousService = service;
250
- return (0, service_helper_1.getServiceDetails)(service, connectValidator);
251
- }
252
- return true;
253
- }
254
- };
255
- const questions = [newSystemServiceQuestion];
256
- // Only for CLI use as `list` prompt validation does not run on CLI
257
- if ((0, utils_1.getHostEnvironment)() === types_1.hostEnvironment.cli) {
258
- questions.push({
259
- when: async (answers) => {
260
- const selectedService = answers?.[`${promptNamespace}:${types_1.promptNames.serviceSelection}`];
261
- if (selectedService && connectValidator.validatedUrl) {
262
- const result = await (0, service_helper_1.getServiceDetails)(selectedService, connectValidator);
263
- if (typeof result === 'string') {
264
- logger_helper_1.default.logger.error(result);
265
- throw new Error(result);
266
- }
267
- }
268
- if (serviceChoices.length === 0 && prompt_helpers_2.errorHandler.hasError()) {
269
- const noServicesError = error_handler_1.ErrorHandler.getHelpForError(error_handler_1.ERROR_TYPE.SERVICES_UNAVAILABLE).toString();
270
- throw new Error(noServicesError);
271
- }
272
- return false;
273
- },
274
- name: `${promptNamespace}:${cliServicePromptName}`
275
- });
276
- }
277
- return questions;
278
- }
279
- /**
280
- * Get the service selection prompt additional message. This prompt will make an additional call to the system backend
281
- * to retrieve the service type and display a warning message if the service type is not UI.
282
- *
283
- * @param serviceChoices a list of service choices
284
- * @param selectedService the selected service
285
- * @param connectValidator the connection validator
286
- * @param requiredOdataVersion the required OData version for the service
287
- * @returns the service selection prompt additional message
288
- */
289
- async function getSelectedServiceMessage(serviceChoices, selectedService, connectValidator, requiredOdataVersion) {
290
- if (serviceChoices?.length === 0) {
291
- if (requiredOdataVersion) {
292
- return {
293
- message: (0, i18n_1.t)('prompts.warnings.noServicesAvailableForOdataVersion', {
294
- odataVersion: requiredOdataVersion
295
- }),
296
- severity: yeoman_ui_types_1.Severity.warning
297
- };
298
- }
299
- else {
300
- return {
301
- message: (0, i18n_1.t)('prompts.warnings.noServicesAvailable'),
302
- severity: yeoman_ui_types_1.Severity.warning
303
- };
304
- }
305
- }
306
- if (selectedService) {
307
- let serviceType = selectedService.serviceType;
308
- if (selectedService.serviceODataVersion === axios_extension_1.ODataVersion.v2) {
309
- serviceType = await (0, service_helper_1.getServiceType)(selectedService.servicePath, selectedService.serviceType, connectValidator.catalogs[axios_extension_1.ODataVersion.v2]);
310
- }
311
- if (serviceType && serviceType !== axios_extension_1.ServiceType.UI) {
312
- return {
313
- message: (0, i18n_1.t)('prompts.warnings.nonUIServiceTypeWarningMessage', { serviceType: 'A2X' }),
314
- severity: yeoman_ui_types_1.Severity.warning
315
- };
316
- }
317
- }
318
- }
319
169
  //# sourceMappingURL=questions.js.map
@@ -1,13 +1,3 @@
1
- import type { ODataVersion } from '@sap-ux/axios-extension';
2
- /**
3
- * Sap System service answer
4
- */
5
- export type ServiceAnswer = {
6
- servicePath: string;
7
- serviceODataVersion: ODataVersion;
8
- toString: () => string;
9
- serviceType?: string;
10
- };
11
1
  export declare const newSystemPromptNames: {
12
2
  readonly newSystemType: "newSystemType";
13
3
  readonly newSystemUrl: "newSystemUrl";
@@ -0,0 +1,3 @@
1
+ export * from './questions';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./questions"), exports);
18
+ __exportStar(require("./types"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,15 @@
1
+ import type { Question } from 'inquirer';
2
+ import type { OdataServicePromptOptions } from '../../../../types';
3
+ import type { ConnectionValidator } from '../../../connectionValidator';
4
+ import { type ServiceAnswer } from './types';
5
+ /**
6
+ * Get the service selection prompt for an Abap system connection (on-prem or on-btp). The service selection prompt is used to select a service from the system catalog.
7
+ *
8
+ * @param connectValidator A reference to the active connection validator, used to validate the service selection and retrieve service details.
9
+ * @param promptNamespace The namespace for the prompt, used to identify the prompt instance and namespaced answers.
10
+ * This is used to avoid conflicts with other prompts of the same types.
11
+ * @param promptOptions Options for the service selection prompt see {@link OdataServicePromptOptions}
12
+ * @returns the service selection prompt
13
+ */
14
+ export declare function getSystemServiceQuestion(connectValidator: ConnectionValidator, promptNamespace: string, promptOptions?: OdataServicePromptOptions): Question<ServiceAnswer>[];
15
+ //# sourceMappingURL=questions.d.ts.map
@@ -0,0 +1,146 @@
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.getSystemServiceQuestion = getSystemServiceQuestion;
7
+ const inquirer_common_1 = require("@sap-ux/inquirer-common");
8
+ const odata_service_writer_1 = require("@sap-ux/odata-service-writer");
9
+ const error_handler_1 = require("../../../../error-handler/error-handler");
10
+ const i18n_1 = require("../../../../i18n");
11
+ const types_1 = require("../../../../types");
12
+ const utils_1 = require("../../../../utils");
13
+ const logger_helper_1 = __importDefault(require("../../../logger-helper"));
14
+ const prompt_helpers_1 = require("../../../prompt-helpers");
15
+ const service_helper_1 = require("../service-selection/service-helper");
16
+ const cliServicePromptName = 'cliServiceSelection';
17
+ /**
18
+ * Get the service selection prompt for an Abap system connection (on-prem or on-btp). The service selection prompt is used to select a service from the system catalog.
19
+ *
20
+ * @param connectValidator A reference to the active connection validator, used to validate the service selection and retrieve service details.
21
+ * @param promptNamespace The namespace for the prompt, used to identify the prompt instance and namespaced answers.
22
+ * This is used to avoid conflicts with other prompts of the same types.
23
+ * @param promptOptions Options for the service selection prompt see {@link OdataServicePromptOptions}
24
+ * @returns the service selection prompt
25
+ */
26
+ function getSystemServiceQuestion(connectValidator, promptNamespace, promptOptions) {
27
+ let serviceChoices = [];
28
+ // Prevent re-requesting services repeatedly by only requesting them once and when the system or client is changed
29
+ let previousSystemUrl;
30
+ let previousClient;
31
+ let previousService;
32
+ const requiredOdataVersion = promptOptions?.serviceSelection?.requiredOdataVersion;
33
+ const systemServiceQuestion = {
34
+ when: () => connectValidator.validity.authenticated || connectValidator.validity.authRequired === false,
35
+ name: `${promptNamespace}:${types_1.promptNames.serviceSelection}`,
36
+ type: promptOptions?.serviceSelection?.useAutoComplete ? 'autocomplete' : 'list',
37
+ message: () => (0, service_helper_1.getSelectedServiceLabel)(connectValidator.connectedUserName),
38
+ guiOptions: {
39
+ breadcrumb: (0, i18n_1.t)('prompts.systemService.breadcrumb'),
40
+ mandatory: true,
41
+ applyDefaultWhenDirty: true
42
+ },
43
+ source: (prevAnswers, input) => (0, inquirer_common_1.searchChoices)(input, serviceChoices),
44
+ // SystemSelectionAnswers should not be needed here in the interest of keeping these prompts decoupled but TelemetryHelper is used here and it requires the previously selected destination
45
+ choices: async (answers) => {
46
+ if (serviceChoices.length === 0 ||
47
+ previousSystemUrl !== connectValidator.validatedUrl ||
48
+ previousClient !== connectValidator.validatedClient) {
49
+ // if we have a catalog, use it to list services
50
+ if (connectValidator.catalogs[odata_service_writer_1.OdataVersion.v2] || connectValidator.catalogs[odata_service_writer_1.OdataVersion.v4]) {
51
+ serviceChoices = await createServiceChoicesFromCatalog(connectValidator.catalogs, requiredOdataVersion);
52
+ previousSystemUrl = connectValidator.validatedUrl;
53
+ previousClient = connectValidator.validatedClient;
54
+ // Telemetry event for successful service listing using a destination
55
+ if (answers?.[`${types_1.promptNames.systemSelection}`]?.type === 'destination') {
56
+ (0, service_helper_1.sendDestinationServiceSuccessTelemetryEvent)(answers?.[`${types_1.promptNames.systemSelection}`]?.system);
57
+ }
58
+ }
59
+ else if (connectValidator.odataService && connectValidator.validatedUrl) {
60
+ // We have connected to a service endpoint, use this service as the only choice
61
+ const serviceUrl = new URL(connectValidator.destinationUrl ?? connectValidator.validatedUrl);
62
+ serviceChoices = [
63
+ {
64
+ name: serviceUrl.toString(),
65
+ value: {
66
+ servicePath: serviceUrl.pathname
67
+ }
68
+ }
69
+ ];
70
+ // Telemetry event for successful service listing using a destination
71
+ if (answers?.[`${types_1.promptNames.systemSelection}`]?.type === 'destination') {
72
+ (0, service_helper_1.sendDestinationServiceSuccessTelemetryEvent)(answers?.[`${types_1.promptNames.systemSelection}`]?.system);
73
+ }
74
+ }
75
+ else {
76
+ logger_helper_1.default.logger.error((0, i18n_1.t)('error.noCatalogOrServiceAvailable'));
77
+ }
78
+ }
79
+ return serviceChoices;
80
+ },
81
+ additionalMessages: (selectedService) => (0, service_helper_1.getSelectedServiceMessage)(serviceChoices, selectedService, connectValidator, requiredOdataVersion),
82
+ default: () => (0, utils_1.getDefaultChoiceIndex)(serviceChoices),
83
+ // Warning: only executes in YUI and cli when automcomplete is used
84
+ validate: async (service) => {
85
+ let serviceAnswer = service;
86
+ // Autocomplete passes the entire choice object as the answer, so we need to extract the value
87
+ if (promptOptions?.serviceSelection?.useAutoComplete && service.value) {
88
+ serviceAnswer = service.value;
89
+ }
90
+ if (!connectValidator.validatedUrl) {
91
+ return false;
92
+ }
93
+ // if no choices are available and an error is present, return the error message
94
+ if (serviceChoices.length === 0 && prompt_helpers_1.errorHandler.hasError()) {
95
+ return error_handler_1.ErrorHandler.getHelpForError(error_handler_1.ERROR_TYPE.SERVICES_UNAVAILABLE) ?? false;
96
+ }
97
+ // Dont re-request the same service details
98
+ if (serviceAnswer && previousService?.servicePath !== serviceAnswer.servicePath) {
99
+ previousService = serviceAnswer;
100
+ return await (0, service_helper_1.getServiceDetails)(serviceAnswer, connectValidator, requiredOdataVersion);
101
+ }
102
+ return true;
103
+ }
104
+ };
105
+ const questions = [systemServiceQuestion];
106
+ // Only for CLI use as `list` prompt validation does not run on CLI unless autocomplete plugin is used
107
+ if ((0, utils_1.getHostEnvironment)() === types_1.hostEnvironment.cli && !promptOptions?.serviceSelection?.useAutoComplete) {
108
+ questions.push({
109
+ when: async (answers) => {
110
+ const selectedService = answers?.[`${promptNamespace}:${types_1.promptNames.serviceSelection}`];
111
+ if (selectedService && connectValidator.validatedUrl) {
112
+ const result = await (0, service_helper_1.getServiceDetails)(selectedService, connectValidator);
113
+ if (typeof result === 'string') {
114
+ logger_helper_1.default.logger.error(result);
115
+ throw new Error(result);
116
+ }
117
+ }
118
+ if (serviceChoices.length === 0 && prompt_helpers_1.errorHandler.hasError()) {
119
+ const noServicesError = error_handler_1.ErrorHandler.getHelpForError(error_handler_1.ERROR_TYPE.SERVICES_UNAVAILABLE).toString();
120
+ throw new Error(noServicesError);
121
+ }
122
+ return false;
123
+ },
124
+ name: `${promptNamespace}:${cliServicePromptName}`
125
+ });
126
+ }
127
+ return questions;
128
+ }
129
+ /**
130
+ * Create service choices from the catalog.
131
+ *
132
+ * @param availableCatalogs catalogs that can be used to list services
133
+ * @param requiredOdataVersion the required OData version to list services for, if not provided all available catalogs will be used
134
+ * @returns service choices
135
+ */
136
+ async function createServiceChoicesFromCatalog(availableCatalogs, requiredOdataVersion) {
137
+ let catalogs = [];
138
+ if (requiredOdataVersion && availableCatalogs[requiredOdataVersion]) {
139
+ catalogs.push(availableCatalogs[requiredOdataVersion]);
140
+ }
141
+ else {
142
+ catalogs = Object.values(availableCatalogs).filter((cat) => cat !== undefined);
143
+ }
144
+ return await (0, service_helper_1.getServiceChoices)(catalogs);
145
+ }
146
+ //# sourceMappingURL=questions.js.map