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

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 +114 -27
  6. package/dist/prompts/connectionValidator.js +206 -34
  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
@@ -3,29 +3,47 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getUserSystemNameQuestion = exports.getNewSystemQuestions = exports.newSystemChoiceValue = void 0;
7
- /**
8
- * New system prompting questions for re-use in multiple sap-system datasource prompt sets.
9
- */
6
+ exports.getSystemServiceQuestion = exports.getSelectedServiceLabel = exports.getUserSystemNameQuestion = exports.getSystemUrlQuestion = exports.getNewSystemQuestions = exports.newSystemChoiceValue = void 0;
10
7
  const yeoman_ui_types_1 = require("@sap-devx/yeoman-ui-types");
8
+ const axios_extension_1 = require("@sap-ux/axios-extension");
11
9
  const inquirer_common_1 = require("@sap-ux/inquirer-common");
12
10
  const store_1 = require("@sap-ux/store");
13
11
  const i18n_1 = require("../../../../i18n");
14
12
  const types_1 = require("../../../../types");
15
13
  const utils_1 = require("../../../../utils");
16
- const logger_helper_1 = __importDefault(require("../../../logger-helper"));
17
- const questions_1 = require("../abap-on-prem/questions");
18
14
  const prompt_helpers_1 = require("../prompt-helpers");
19
15
  const validators_1 = require("../validators");
16
+ const service_helper_1 = require("./service-helper");
17
+ const types_2 = require("./types");
18
+ const questions_1 = require("../abap-on-prem/questions");
19
+ const questions_2 = require("../abap-on-btp/questions");
20
+ const logger_helper_1 = __importDefault(require("../../../logger-helper"));
20
21
  // New system choice value is a hard to guess string to avoid conflicts with existing system names or user named systems
21
22
  // since it will be used as a new system value in the system selection prompt.
22
23
  exports.newSystemChoiceValue = '!@£*&937newSystem*X~qy^';
23
- const newSystemPromptNames = {
24
- newSystemType: 'newSystemType'
25
- };
24
+ const cliServicePromptName = 'cliServiceSelection';
26
25
  const systemSelectionPromptNames = {
27
26
  system: 'system'
28
27
  };
28
+ /**
29
+ * Convert the system connection scheme (Service Key, Rentrance Ticket, etc) to the store specific authentication type.
30
+ * Note the absence of CF Discovery, in this case the service key file (UAA) is also used for the Abap connectivity.
31
+ *
32
+ * @param systemAuthType The system authentication type
33
+ * @returns The store specific authentication type
34
+ */
35
+ function systemAuthTypeToAuthenticationType(systemAuthType) {
36
+ switch (systemAuthType) {
37
+ case 'serviceKey':
38
+ return store_1.AuthenticationType.OAuth2RefreshToken;
39
+ case 'reentranceTicket':
40
+ return store_1.AuthenticationType.ReentranceTicket;
41
+ case 'basic':
42
+ return store_1.AuthenticationType.Basic;
43
+ default:
44
+ return undefined;
45
+ }
46
+ }
29
47
  /**
30
48
  * Provides prompts that allow the creation of a new system connection.
31
49
  *
@@ -36,52 +54,91 @@ function getNewSystemQuestions(promptOptions) {
36
54
  const questions = [
37
55
  {
38
56
  type: 'list',
39
- name: newSystemPromptNames.newSystemType,
57
+ name: types_2.newSystemPromptNames.newSystemType,
40
58
  choices: [
41
59
  { name: (0, i18n_1.t)('prompts.newSystemType.choiceAbapOnBtp'), value: 'abapOnBtp' },
42
60
  { name: (0, i18n_1.t)('prompts.newSystemType.choiceAbapOnPrem'), value: 'abapOnPrem' }
43
61
  ],
44
- message: (0, i18n_1.t)('prompts.newSystemType.message'),
45
- additionalMessages: (systemType) => {
46
- if (['abapOnBtp'].includes(systemType)) {
47
- logger_helper_1.default.logger?.warn((0, i18n_1.t)('prompts.systemType.notYetImplementedWarningMessage', { systemType }));
48
- return {
49
- message: (0, i18n_1.t)('prompts.systemType.notYetImplementedWarningMessage', { systemType }),
50
- severity: yeoman_ui_types_1.Severity.warning
51
- };
52
- }
53
- }
62
+ message: (0, i18n_1.t)('prompts.newSystemType.message')
54
63
  }
55
64
  ];
56
65
  questions.push(...(0, inquirer_common_1.withCondition)((0, questions_1.getAbapOnPremQuestions)(promptOptions), (answers) => answers.newSystemType === 'abapOnPrem'));
66
+ questions.push(...(0, inquirer_common_1.withCondition)((0, questions_2.getAbapOnBTPSystemQuestions)(promptOptions), (answers) => answers.newSystemType === 'abapOnBtp'));
57
67
  return questions;
58
68
  }
59
69
  exports.getNewSystemQuestions = getNewSystemQuestions;
70
+ /**
71
+ * Get the system url prompt. The system url prompt is used to connect to a new system using the user input system url.
72
+ *
73
+ * @param connectValidator a connection validator instance used to validate the system url
74
+ * @param promptNamespace The namespace for the prompt, used to identify the prompt instance and namespaced answers.
75
+ * @param requiredOdataVersion The required OData version for the system connection, only catalogs supporting the specifc odata version will be used.
76
+ * @returns the system url prompt
77
+ */
78
+ function getSystemUrlQuestion(connectValidator, promptNamespace, requiredOdataVersion) {
79
+ const promptName = `${promptNamespace ? promptNamespace + ':' : ''}${types_2.newSystemPromptNames.newSystemUrl}`;
80
+ const newSystemUrlQuestion = {
81
+ type: 'input',
82
+ name: promptName,
83
+ message: (0, i18n_1.t)('prompts.systemUrl.message'),
84
+ guiOptions: {
85
+ hint: (0, i18n_1.t)('prompts.systemUrl.description'),
86
+ mandatory: true,
87
+ breadcrumb: true
88
+ },
89
+ validate: async (url) => {
90
+ const valResult = await connectValidator.validateUrl(url, {
91
+ isSystem: true,
92
+ odataVersion: (0, utils_1.convertODataVersionType)(requiredOdataVersion)
93
+ });
94
+ // If basic auth not required we should have an active connection
95
+ if (valResult === true && !connectValidator.validity.authRequired && connectValidator.serviceProvider) {
96
+ utils_1.PromptState.odataService.connectedSystem = {
97
+ serviceProvider: connectValidator.serviceProvider
98
+ };
99
+ }
100
+ return valResult;
101
+ }
102
+ };
103
+ return newSystemUrlQuestion;
104
+ }
105
+ exports.getSystemUrlQuestion = getSystemUrlQuestion;
60
106
  /**
61
107
  * Get a prompt for new system name.
62
108
  *
109
+ * @param connectValidator A reference to the active connection validator,
110
+ * at prompt execution time the connection properties will be used to create a new BackendSystem, set into the PromptState.odataService.connectedSystem
111
+ * @param promptNamespace The namespace for the prompt, used to identify the prompt instance and namespaced answers.
112
+ * 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.
63
113
  * @returns the new system name prompt
64
114
  */
65
- function getUserSystemNameQuestion() {
115
+ function getUserSystemNameQuestion(connectValidator, promptNamespace) {
66
116
  let defaultSystemName;
67
117
  let userModifiedSystemName = false;
118
+ const promptNamespacePart = `${promptNamespace ? promptNamespace + ':' : ''}`;
119
+ const promptName = `${promptNamespacePart}${types_1.promptNames.userSystemName}`;
68
120
  const newSystemNamePrompt = {
69
121
  type: 'input',
70
122
  guiOptions: {
71
123
  hint: (0, i18n_1.t)('prompts.systemName.hint'),
72
124
  applyDefaultWhenDirty: true,
73
- breadcrumb: true
125
+ breadcrumb: true,
126
+ mandatory: true
74
127
  },
75
- name: types_1.promptNames.userSystemName,
128
+ name: promptName,
76
129
  message: (0, i18n_1.t)('prompts.systemName.message'),
77
- default: async (answers) => {
78
- if (answers.newSystemType === 'abapOnPrem' && answers.systemUrl && !userModifiedSystemName) {
79
- defaultSystemName = await (0, prompt_helpers_1.suggestSystemName)(answers.systemUrl, answers.sapClient);
130
+ default: async () => {
131
+ const systemName = connectValidator.connectedSystemName;
132
+ if (systemName && !userModifiedSystemName) {
133
+ defaultSystemName = await (0, prompt_helpers_1.suggestSystemName)(systemName, connectValidator.axiosConfig?.params?.sapClient);
80
134
  return defaultSystemName;
81
135
  }
82
- return answers.userSystemName;
136
+ return defaultSystemName;
83
137
  },
84
- validate: async (systemName, answers) => {
138
+ validate: async (systemName) => {
139
+ if (!systemName) {
140
+ return false;
141
+ }
85
142
  let isValid = false;
86
143
  // Dont validate the suggested default system name
87
144
  if (systemName === defaultSystemName) {
@@ -89,18 +146,23 @@ function getUserSystemNameQuestion() {
89
146
  }
90
147
  else {
91
148
  userModifiedSystemName = true;
149
+ defaultSystemName = systemName;
92
150
  isValid = await (0, validators_1.validateSystemName)(systemName);
93
151
  }
94
152
  if (isValid === true) {
95
- // Not the default system name, so the user modified
96
- const backendSystem = new store_1.BackendSystem({
97
- name: systemName,
98
- url: answers.systemUrl,
99
- client: answers.sapClient,
100
- username: answers.abapSystemUsername,
101
- password: answers.abapSystemPassword
102
- });
103
- if (utils_1.PromptState.odataService.connectedSystem) {
153
+ // Update or create the BackendSystem with the new system details for persistent storage
154
+ if (connectValidator.validatedUrl && utils_1.PromptState.odataService.connectedSystem) {
155
+ const backendSystem = new store_1.BackendSystem({
156
+ authenticationType: systemAuthTypeToAuthenticationType(connectValidator.systemAuthType),
157
+ name: systemName,
158
+ url: connectValidator.validatedUrl,
159
+ client: connectValidator.axiosConfig?.params?.[types_1.SAP_CLIENT_KEY],
160
+ username: connectValidator.axiosConfig?.auth?.username,
161
+ password: connectValidator.axiosConfig?.auth?.password,
162
+ serviceKeys: connectValidator.serviceInfo,
163
+ userDisplayName: connectValidator.connectedUserName,
164
+ refreshToken: connectValidator.refreshToken
165
+ });
104
166
  utils_1.PromptState.odataService.connectedSystem.backendSystem = backendSystem;
105
167
  }
106
168
  }
@@ -110,4 +172,134 @@ function getUserSystemNameQuestion() {
110
172
  return newSystemNamePrompt;
111
173
  }
112
174
  exports.getUserSystemNameQuestion = getUserSystemNameQuestion;
175
+ /**
176
+ * Create a value for the service selection prompt message, which may include thge active connected user name.
177
+ *
178
+ * @param username The connected user name
179
+ * @returns The service selection prompt message
180
+ */
181
+ function getSelectedServiceLabel(username) {
182
+ let message = (0, i18n_1.t)('prompts.systemService.message');
183
+ if (username) {
184
+ message = message.concat(` ${(0, i18n_1.t)('texts.forUserName', { username })}`);
185
+ }
186
+ return message;
187
+ }
188
+ exports.getSelectedServiceLabel = getSelectedServiceLabel;
189
+ /**
190
+ * Get the service selection prompt for a system connection. The service selection prompt is used to select a service from the system catalog.
191
+ *
192
+ * @param connectValidator A reference to the active connection validator, used to validate the service selection and retrieve service details.
193
+ * @param promptNamespace The namespace for the prompt, used to identify the prompt instance and namespaced answers.
194
+ * This is used to avoid conflicts with other prompts of the same types.
195
+ * @param promptOptions Options for the service selection prompt see {@link OdataServicePromptOptions}
196
+ * @returns the service selection prompt
197
+ */
198
+ function getSystemServiceQuestion(connectValidator, promptNamespace, promptOptions) {
199
+ let serviceChoices = [];
200
+ // Prevent re-requesting services repeatedly by only requesting them once and when the system is changed
201
+ let previousSystemUrl;
202
+ let previousService;
203
+ const requiredOdataVersion = promptOptions?.serviceSelection?.requiredOdataVersion;
204
+ const newSystemServiceQuestion = {
205
+ when: () => connectValidator.validity.authenticated || connectValidator.validity.authRequired === false,
206
+ name: `${promptNamespace}:${types_1.promptNames.serviceSelection}`,
207
+ type: promptOptions?.serviceSelection?.useAutoComplete ? 'autocomplete' : 'list',
208
+ message: () => getSelectedServiceLabel(connectValidator.connectedUserName),
209
+ guiOptions: {
210
+ breadcrumb: (0, i18n_1.t)('prompts.systemService.breadcrumb'),
211
+ mandatory: true,
212
+ applyDefaultWhenDirty: true
213
+ },
214
+ source: (prevAnswers, input) => (0, inquirer_common_1.searchChoices)(input, serviceChoices),
215
+ choices: async () => {
216
+ if (serviceChoices.length === 0 || previousSystemUrl !== connectValidator.validatedUrl) {
217
+ let catalogs = [];
218
+ if (requiredOdataVersion && connectValidator.catalogs[requiredOdataVersion]) {
219
+ catalogs.push(connectValidator.catalogs[requiredOdataVersion]);
220
+ }
221
+ else {
222
+ catalogs = Object.values(connectValidator.catalogs).filter((cat) => cat !== undefined);
223
+ }
224
+ previousSystemUrl = connectValidator.validatedUrl;
225
+ serviceChoices = await (0, service_helper_1.getServiceChoices)(catalogs);
226
+ }
227
+ return serviceChoices;
228
+ },
229
+ additionalMessages: (selectedService) => getSelectedServiceMessage(serviceChoices, selectedService, connectValidator, requiredOdataVersion),
230
+ default: () => (0, utils_1.getDefaultChoiceIndex)(serviceChoices),
231
+ // Warning: only executes in YUI not cli
232
+ validate: async (service) => {
233
+ if (!connectValidator.validatedUrl) {
234
+ return false;
235
+ }
236
+ // Dont re-request the same service details
237
+ if (service && previousService?.servicePath !== service.servicePath) {
238
+ previousService = service;
239
+ return (0, service_helper_1.getServiceDetails)(service, connectValidator);
240
+ }
241
+ return true;
242
+ }
243
+ };
244
+ const questions = [newSystemServiceQuestion];
245
+ // Only for CLI use as `list` prompt validation does not run on CLI
246
+ if ((0, utils_1.getHostEnvironment)() === types_1.hostEnvironment.cli) {
247
+ questions.push({
248
+ when: async (answers) => {
249
+ const selectedService = answers?.[`${promptNamespace}:${types_1.promptNames.serviceSelection}`];
250
+ if (selectedService && connectValidator.validatedUrl) {
251
+ const result = await (0, service_helper_1.getServiceDetails)(selectedService, connectValidator);
252
+ if (typeof result === 'string') {
253
+ logger_helper_1.default.logger.error(result);
254
+ throw new Error(result);
255
+ }
256
+ }
257
+ return false;
258
+ },
259
+ name: `${promptNamespace}:${cliServicePromptName}`
260
+ });
261
+ }
262
+ return questions;
263
+ }
264
+ exports.getSystemServiceQuestion = getSystemServiceQuestion;
265
+ /**
266
+ * Get the service selection prompt additional message. This prompt will make an additional call to the system backend
267
+ * to retrieve the service type and display a warning message if the service type is not UI.
268
+ *
269
+ * @param serviceChoices a list of service choices
270
+ * @param selectedService the selected service
271
+ * @param connectValidator the connection validator
272
+ * @param requiredOdataVersion the required OData version for the service
273
+ * @returns the service selection prompt additional message
274
+ */
275
+ async function getSelectedServiceMessage(serviceChoices, selectedService, connectValidator, requiredOdataVersion) {
276
+ if (serviceChoices?.length === 0) {
277
+ if (requiredOdataVersion) {
278
+ return {
279
+ message: (0, i18n_1.t)('prompts.warnings.noServicesAvailableForOdataVersion', {
280
+ odataVersion: requiredOdataVersion
281
+ }),
282
+ severity: yeoman_ui_types_1.Severity.warning
283
+ };
284
+ }
285
+ else {
286
+ return {
287
+ message: (0, i18n_1.t)('prompts.warnings.noServicesAvailable'),
288
+ severity: yeoman_ui_types_1.Severity.warning
289
+ };
290
+ }
291
+ }
292
+ if (selectedService) {
293
+ let serviceType = selectedService.serviceType;
294
+ if (selectedService.serviceODataVersion === axios_extension_1.ODataVersion.v2) {
295
+ serviceType = await (0, service_helper_1.getServiceType)(selectedService.servicePath, selectedService.serviceType, connectValidator.catalogs[axios_extension_1.ODataVersion.v2]);
296
+ }
297
+ if (serviceType && serviceType !== axios_extension_1.ServiceType.UI) {
298
+ return {
299
+ message: (0, i18n_1.t)('prompts.warnings.nonUIServiceTypeWarningMessage', { serviceType: 'A2X' }),
300
+ severity: yeoman_ui_types_1.Severity.warning
301
+ };
302
+ }
303
+ }
304
+ }
113
305
  //# sourceMappingURL=questions.js.map
@@ -1,6 +1,7 @@
1
1
  import { ServiceType, type Annotations, type CatalogService, type V2CatalogService, type ServiceProvider } from '@sap-ux/axios-extension';
2
2
  import type { ListChoiceOptions } from 'inquirer';
3
- import type { ServiceAnswer } from './questions';
3
+ import type { ServiceAnswer } from './types';
4
+ import type { ConnectionValidator } from '../../../connectionValidator';
4
5
  /**
5
6
  * Get the service choices from the specified catalogs.
6
7
  *
@@ -30,4 +31,13 @@ export declare function getServiceMetadata(servicePath: string, catalog: Catalog
30
31
  * @returns service type
31
32
  */
32
33
  export declare function getServiceType(servicePath: string, serviceType: string | undefined, catalog: V2CatalogService): Promise<ServiceType | undefined>;
34
+ /**
35
+ * Requests and sets the service details to the PromptState.odataService properties.
36
+ * If an error occurs, the error message is returned for use in validators.
37
+ *
38
+ * @param service the specific service to get details for
39
+ * @param connectionValidator a reference to the connection validator which has an active connection to the backend
40
+ * @returns true if successful, setting the PromptState.odataService properties, or an error message indicating why the service details could not be retrieved.
41
+ */
42
+ export declare function getServiceDetails(service: ServiceAnswer, connectionValidator: ConnectionValidator): Promise<string | boolean>;
33
43
  //# sourceMappingURL=service-helper.d.ts.map
@@ -3,10 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getServiceType = exports.getServiceMetadata = exports.getServiceChoices = void 0;
6
+ exports.getServiceDetails = exports.getServiceType = exports.getServiceMetadata = exports.getServiceChoices = void 0;
7
7
  const axios_extension_1 = require("@sap-ux/axios-extension");
8
8
  const i18n_1 = require("../../../../i18n");
9
9
  const logger_helper_1 = __importDefault(require("../../../logger-helper"));
10
+ const utils_1 = require("../../../../utils");
11
+ const odata_service_writer_1 = require("@sap-ux/odata-service-writer");
10
12
  // Service ids continaining these paths should not be offered as UI compatible services
11
13
  const nonUIServicePaths = ['/IWBEP/COMMON/'];
12
14
  /**
@@ -119,4 +121,31 @@ async function getServiceType(servicePath, serviceType, catalog) {
119
121
  return resolvedServiceType ?? serviceType;
120
122
  }
121
123
  exports.getServiceType = getServiceType;
124
+ /**
125
+ * Requests and sets the service details to the PromptState.odataService properties.
126
+ * If an error occurs, the error message is returned for use in validators.
127
+ *
128
+ * @param service the specific service to get details for
129
+ * @param connectionValidator a reference to the connection validator which has an active connection to the backend
130
+ * @returns true if successful, setting the PromptState.odataService properties, or an error message indicating why the service details could not be retrieved.
131
+ */
132
+ async function getServiceDetails(service, connectionValidator) {
133
+ const serviceCatalog = connectionValidator.catalogs[service.serviceODataVersion];
134
+ if (!serviceCatalog || !connectionValidator.serviceProvider) {
135
+ logger_helper_1.default.logger.error('ConenctionValidator is not initialized');
136
+ return false;
137
+ }
138
+ const serviceResult = await getServiceMetadata(service.servicePath, serviceCatalog, connectionValidator.serviceProvider);
139
+ if (typeof serviceResult === 'string') {
140
+ return serviceResult;
141
+ }
142
+ utils_1.PromptState.odataService.annotations = serviceResult?.annotations;
143
+ utils_1.PromptState.odataService.metadata = serviceResult?.metadata;
144
+ utils_1.PromptState.odataService.odataVersion =
145
+ service.serviceODataVersion === axios_extension_1.ODataVersion.v2 ? odata_service_writer_1.OdataVersion.v2 : odata_service_writer_1.OdataVersion.v4;
146
+ utils_1.PromptState.odataService.servicePath = service.servicePath;
147
+ utils_1.PromptState.odataService.origin = connectionValidator.validatedUrl;
148
+ return true;
149
+ }
150
+ exports.getServiceDetails = getServiceDetails;
122
151
  //# sourceMappingURL=service-helper.js.map
@@ -0,0 +1,16 @@
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
+ export declare const newSystemPromptNames: {
12
+ readonly newSystemType: "newSystemType";
13
+ readonly newSystemUrl: "newSystemUrl";
14
+ readonly newSystemAuthType: "newSystemAuthType";
15
+ };
16
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.newSystemPromptNames = void 0;
4
+ exports.newSystemPromptNames = {
5
+ newSystemType: 'newSystemType',
6
+ newSystemUrl: 'newSystemUrl',
7
+ newSystemAuthType: 'newSystemAuthType'
8
+ };
9
+ //# sourceMappingURL=types.js.map
@@ -1,9 +1,9 @@
1
1
  /**
2
- * Provides a system name suggestion based on the system URL, system ID, and client, validating the name is unique against the secure store.
2
+ * Provides a system name suggestion based on the passed system name and client, validating the name is unique against the secure store.
3
3
  *
4
- * @param systemUrl the system URL origin
4
+ * @param systemName the system name to use as a base for the suggestion
5
5
  * @param client the sap client to use for the system
6
6
  * @returns a unique system name suggestion
7
7
  */
8
- export declare function suggestSystemName(systemUrl: string, client?: string): Promise<string>;
8
+ export declare function suggestSystemName(systemName: string, client?: string): Promise<string>;
9
9
  //# sourceMappingURL=prompt-helpers.d.ts.map
@@ -4,14 +4,14 @@ exports.suggestSystemName = void 0;
4
4
  const i18n_1 = require("../../../i18n");
5
5
  const validators_1 = require("./validators");
6
6
  /**
7
- * Provides a system name suggestion based on the system URL, system ID, and client, validating the name is unique against the secure store.
7
+ * Provides a system name suggestion based on the passed system name and client, validating the name is unique against the secure store.
8
8
  *
9
- * @param systemUrl the system URL origin
9
+ * @param systemName the system name to use as a base for the suggestion
10
10
  * @param client the sap client to use for the system
11
11
  * @returns a unique system name suggestion
12
12
  */
13
- async function suggestSystemName(systemUrl, client) {
14
- const initialSystemName = systemUrl + (client ? (0, i18n_1.t)('texts.suggestedSystemNameClient', { client }) : '');
13
+ async function suggestSystemName(systemName, client) {
14
+ const initialSystemName = systemName + (client ? (0, i18n_1.t)('texts.suggestedSystemNameClient', { client }) : '');
15
15
  if ((await (0, validators_1.validateSystemName)(initialSystemName)) === true) {
16
16
  return initialSystemName;
17
17
  }
@@ -1,7 +1,16 @@
1
+ import type { ServiceInfo } from '@sap-ux/btp-utils';
1
2
  /**
2
3
  * Validates that the system name does not exist yet.
3
4
  *
4
5
  * @param systemName a system name to validate
5
6
  * @returns true if the name is valid, otherwise an error message
6
- */ export declare function validateSystemName(systemName: string): Promise<boolean | string>;
7
+ */
8
+ export declare function validateSystemName(systemName: string): Promise<boolean | string>;
9
+ /**
10
+ * Validates the existence and content of the file at the given path and returns the service key info if valid.
11
+ *
12
+ * @param path path to a service key file
13
+ * @returns the service key info if the file is valid, otherwise an error message
14
+ */
15
+ export declare function validateServiceKey(path: string): string | ServiceInfo | boolean;
7
16
  //# sourceMappingURL=validators.d.ts.map
@@ -3,10 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.validateSystemName = void 0;
6
+ exports.validateServiceKey = exports.validateSystemName = void 0;
7
7
  const i18n_1 = require("../../../i18n");
8
8
  const store_1 = require("@sap-ux/store");
9
9
  const logger_helper_1 = __importDefault(require("../../logger-helper"));
10
+ const fs_1 = require("fs");
10
11
  /**
11
12
  * Check if the system name is already in use.
12
13
  *
@@ -22,7 +23,8 @@ async function isSystemNameInUse(systemName) {
22
23
  *
23
24
  * @param systemName a system name to validate
24
25
  * @returns true if the name is valid, otherwise an error message
25
- */ async function validateSystemName(systemName) {
26
+ */
27
+ async function validateSystemName(systemName) {
26
28
  if (!systemName) {
27
29
  return (0, i18n_1.t)('prompts.systemName.emptySystemNameWarning');
28
30
  }
@@ -35,4 +37,27 @@ async function isSystemNameInUse(systemName) {
35
37
  }
36
38
  }
37
39
  exports.validateSystemName = validateSystemName;
40
+ /**
41
+ * Validates the existence and content of the file at the given path and returns the service key info if valid.
42
+ *
43
+ * @param path path to a service key file
44
+ * @returns the service key info if the file is valid, otherwise an error message
45
+ */
46
+ function validateServiceKey(path) {
47
+ if (!path) {
48
+ return false;
49
+ }
50
+ try {
51
+ const serviceKeys = (0, fs_1.readFileSync)(path, 'utf8');
52
+ const serviceInfo = JSON.parse(serviceKeys);
53
+ if (!serviceInfo.url || !serviceInfo.uaa || !serviceInfo.catalogs) {
54
+ return (0, i18n_1.t)('prompts.serviceKey.incompleteServiceKeyInfo');
55
+ }
56
+ return serviceInfo;
57
+ }
58
+ catch (error) {
59
+ return error.name === 'SyntaxError' ? (0, i18n_1.t)('prompts.serviceKey.unparseableServiceKey') : error.message;
60
+ }
61
+ }
62
+ exports.validateServiceKey = validateServiceKey;
38
63
  //# sourceMappingURL=validators.js.map
@@ -36,8 +36,11 @@ function getServiceUrlPrompt(connectValidator, requiredVersion) {
36
36
  return true;
37
37
  }
38
38
  if (urlValidationState === true) {
39
- if (!connectValidator.validity.authRequired) {
40
- return (0, validators_1.validateService)(url, connectValidator, requiredVersion);
39
+ if (!connectValidator.validity.authRequired && connectValidator.odataService) {
40
+ return (0, validators_1.validateService)(url, {
41
+ odataService: connectValidator.odataService,
42
+ abapServiceProvider: connectValidator.serviceProvider
43
+ }, requiredVersion);
41
44
  }
42
45
  return true;
43
46
  }
@@ -76,8 +79,11 @@ function getIgnoreCertErrorsPrompt(connectValidator, requiredVersion) {
76
79
  forceReValidation: true
77
80
  });
78
81
  if (validUrl === true) {
79
- if (!connectValidator.validity.authRequired) {
80
- return (0, validators_1.validateService)(serviceUrl, connectValidator, requiredVersion, ignoreCertError);
82
+ if (!connectValidator.validity.authRequired && connectValidator.odataService) {
83
+ return (0, validators_1.validateService)(serviceUrl, {
84
+ odataService: connectValidator.odataService,
85
+ abapServiceProvider: connectValidator.serviceProvider
86
+ }, requiredVersion, ignoreCertError);
81
87
  }
82
88
  return true;
83
89
  }
@@ -113,9 +119,12 @@ function getCliIgnoreCertValidatePrompt(connectValidator, requiredVersion) {
113
119
  if (validUrl !== true) {
114
120
  throw new Error(validUrl.toString()); // exit
115
121
  }
116
- if (!connectValidator.validity.authRequired) {
122
+ if (!connectValidator.validity.authRequired && connectValidator.odataService) {
117
123
  // Will log on CLI
118
- const validService = await (0, validators_1.validateService)(serviceUrl, connectValidator, requiredVersion, true);
124
+ const validService = await (0, validators_1.validateService)(serviceUrl, {
125
+ odataService: connectValidator.odataService,
126
+ abapServiceProvider: connectValidator.serviceProvider
127
+ }, requiredVersion, true);
119
128
  if (validService !== true) {
120
129
  throw new Error((0, i18n_1.t)('errors.exitingGeneration', { exitReason: validService.toString() }));
121
130
  }
@@ -171,8 +180,11 @@ function getPasswordPrompt(connectValidator, requiredVersion) {
171
180
  ignoreCertError,
172
181
  sapClient
173
182
  });
174
- if (validAuth === true) {
175
- return (0, validators_1.validateService)(serviceUrl, connectValidator, requiredVersion, ignoreCertError);
183
+ if (validAuth === true && connectValidator.odataService) {
184
+ return (0, validators_1.validateService)(serviceUrl, {
185
+ odataService: connectValidator.odataService,
186
+ abapServiceProvider: connectValidator.serviceProvider
187
+ }, requiredVersion, ignoreCertError);
176
188
  }
177
189
  return validAuth;
178
190
  }
@@ -1,4 +1,4 @@
1
- import { type AxiosRequestConfig, type ODataService } from '@sap-ux/axios-extension';
1
+ import type { AbapServiceProvider, ODataService } from '@sap-ux/axios-extension';
2
2
  import type { OdataVersion } from '@sap-ux/odata-service-writer';
3
3
  /**
4
4
  * Validates that a service specified by the service url is accessible, has the required version and returns valid metadata.
@@ -7,13 +7,13 @@ import type { OdataVersion } from '@sap-ux/odata-service-writer';
7
7
  * @param url the full odata service url including query parameters
8
8
  * @param connectionConfig the connection configuration to use for the validation, a subset of the ConnectionValidator properties
9
9
  * @param connectionConfig.odataService the odata service instance used to retrieve the metadata (as used by ConnectionValidator)
10
- * @param connectionConfig.axiosConfig the axios config to use for the annotations request (as used by ConnectionValidator)
10
+ * @param connectionConfig.abapServiceProvider the abap service provider instance used to retrieve annotations (as used by ConnectionValidator)
11
11
  * @param requiredVersion if specified and the service odata version does not match this version, an error is returned
12
12
  * @param ignoreCertError if true some certificate errors are ignored
13
13
  * @returns true if a valid odata service was returned, false or an error message string otherwise
14
14
  */
15
- export declare function validateService(url: string, { odataService, axiosConfig }: {
15
+ export declare function validateService(url: string, { odataService, abapServiceProvider }: {
16
16
  odataService: ODataService;
17
- axiosConfig: AxiosRequestConfig;
17
+ abapServiceProvider: AbapServiceProvider;
18
18
  }, requiredVersion?: OdataVersion | undefined, ignoreCertError?: boolean): Promise<boolean | string>;
19
19
  //# sourceMappingURL=validators.d.ts.map