@sap-ux/odata-service-inquirer 0.4.9 → 0.5.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 (24) hide show
  1. package/dist/index.d.ts +14 -3
  2. package/dist/index.js +30 -5
  3. package/dist/prompts/connectionValidator.d.ts +160 -0
  4. package/dist/prompts/{datasources/service-url/connectionValidator.js → connectionValidator.js} +145 -41
  5. package/dist/prompts/datasources/sap-system/abap-on-prem/questions.d.ts +44 -0
  6. package/dist/prompts/datasources/sap-system/abap-on-prem/questions.js +253 -0
  7. package/dist/prompts/datasources/sap-system/abap-on-prem/service-helper.d.ts +33 -0
  8. package/dist/prompts/datasources/sap-system/abap-on-prem/service-helper.js +122 -0
  9. package/dist/prompts/datasources/sap-system/new-system/questions.d.ts +35 -0
  10. package/dist/prompts/datasources/sap-system/new-system/questions.js +107 -0
  11. package/dist/prompts/datasources/sap-system/prompt-helpers.d.ts +9 -0
  12. package/dist/prompts/datasources/sap-system/prompt-helpers.js +37 -0
  13. package/dist/prompts/datasources/sap-system/validators.d.ts +8 -0
  14. package/dist/prompts/datasources/sap-system/validators.js +36 -0
  15. package/dist/prompts/datasources/service-url/questions.js +14 -5
  16. package/dist/prompts/datasources/service-url/validators.d.ts +1 -1
  17. package/dist/prompts/datasources/service-url/validators.js +2 -2
  18. package/dist/prompts/logger-helper.js +5 -4
  19. package/dist/prompts/prompts.js +10 -4
  20. package/dist/translations/odata-service-inquirer.i18n.json +48 -3
  21. package/dist/types.d.ts +45 -11
  22. package/dist/types.js +8 -0
  23. package/package.json +6 -3
  24. package/dist/prompts/datasources/service-url/connectionValidator.d.ts +0 -99
package/dist/index.d.ts CHANGED
@@ -2,8 +2,11 @@ import { type InquirerAdapter } from '@sap-ux/inquirer-common';
2
2
  import { type Logger } from '@sap-ux/logger';
3
3
  import { OdataVersion } from '@sap-ux/odata-service-writer';
4
4
  import { type ToolsSuiteTelemetryClient } from '@sap-ux/telemetry';
5
- import { ErrorHandler, ERROR_TYPE } from './error-handler/error-handler';
6
- import { DatasourceType, promptNames, type CapRuntime, type CapService, type OdataServiceAnswers, type OdataServicePromptOptions, type OdataServiceQuestion } from './types';
5
+ import type { Question } from 'inquirer';
6
+ import { ERROR_TYPE, ErrorHandler } from './error-handler/error-handler';
7
+ import type { AbapOnPremAnswers } from './prompts/datasources/sap-system/abap-on-prem/questions';
8
+ import { newSystemChoiceValue } from './prompts/datasources/sap-system/new-system/questions';
9
+ import { DatasourceType, promptNames, type CapRuntime, type CapService, type OdataServiceAnswers, type OdataServicePromptOptions, type OdataServiceQuestion, type SapSystemType, type SystemNamePromptOptions } from './types';
7
10
  /**
8
11
  * Get the inquirer prompts for odata service.
9
12
  *
@@ -30,5 +33,13 @@ declare function getPrompts(promptOptions?: OdataServicePromptOptions, logger?:
30
33
  * @returns the prompt answers
31
34
  */
32
35
  declare function prompt(adapter: InquirerAdapter, promptOptions?: OdataServicePromptOptions, logger?: Logger, enableGuidedAnswers?: boolean, telemetryClient?: ToolsSuiteTelemetryClient, isYUI?: boolean): Promise<OdataServiceAnswers>;
33
- export { DatasourceType, OdataVersion, getPrompts, prompt, promptNames, type CapRuntime, type CapService, type InquirerAdapter, type OdataServiceAnswers, type OdataServicePromptOptions, ERROR_TYPE, ErrorHandler };
36
+ /**
37
+ * Get the prompts for an abap on premise system. This can be used to create a new system connection.
38
+ *
39
+ * @param systemNamePromptOptions options for the system name prompt see {@link SystemNamePromptOptions}
40
+ * @param logger a logger compatible with the {@link Logger} interface
41
+ * @returns questions for creating a new abap on prem system connection
42
+ */
43
+ declare function getAbapOnPremSystemPrompts(systemNamePromptOptions: SystemNamePromptOptions, logger?: Logger): Promise<Question<AbapOnPremAnswers>[]>;
44
+ export { DatasourceType, OdataVersion, getAbapOnPremSystemPrompts, getPrompts, prompt, promptNames, type CapRuntime, type CapService, type InquirerAdapter, type OdataServiceAnswers, type OdataServicePromptOptions, type SapSystemType, newSystemChoiceValue, ERROR_TYPE, ErrorHandler };
34
45
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -3,20 +3,23 @@ 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.ErrorHandler = exports.ERROR_TYPE = exports.promptNames = exports.prompt = exports.getPrompts = exports.OdataVersion = exports.DatasourceType = void 0;
7
- const logger_1 = require("@sap-ux/logger");
6
+ exports.ErrorHandler = exports.ERROR_TYPE = exports.newSystemChoiceValue = exports.promptNames = exports.prompt = exports.getPrompts = exports.getAbapOnPremSystemPrompts = exports.OdataVersion = exports.DatasourceType = void 0;
8
7
  const odata_service_writer_1 = require("@sap-ux/odata-service-writer");
9
8
  Object.defineProperty(exports, "OdataVersion", { enumerable: true, get: function () { return odata_service_writer_1.OdataVersion; } });
9
+ const inquirer_autocomplete_prompt_1 = __importDefault(require("inquirer-autocomplete-prompt"));
10
10
  const error_handler_1 = require("./error-handler/error-handler");
11
- Object.defineProperty(exports, "ErrorHandler", { enumerable: true, get: function () { return error_handler_1.ErrorHandler; } });
12
11
  Object.defineProperty(exports, "ERROR_TYPE", { enumerable: true, get: function () { return error_handler_1.ERROR_TYPE; } });
12
+ Object.defineProperty(exports, "ErrorHandler", { enumerable: true, get: function () { return error_handler_1.ErrorHandler; } });
13
+ const i18n_1 = require("./i18n");
13
14
  const prompts_1 = require("./prompts");
15
+ const questions_1 = require("./prompts/datasources/sap-system/abap-on-prem/questions");
16
+ const questions_2 = require("./prompts/datasources/sap-system/new-system/questions");
17
+ Object.defineProperty(exports, "newSystemChoiceValue", { enumerable: true, get: function () { return questions_2.newSystemChoiceValue; } });
14
18
  const logger_helper_1 = __importDefault(require("./prompts/logger-helper"));
15
19
  const types_1 = require("./types");
16
20
  Object.defineProperty(exports, "DatasourceType", { enumerable: true, get: function () { return types_1.DatasourceType; } });
17
21
  Object.defineProperty(exports, "promptNames", { enumerable: true, get: function () { return types_1.promptNames; } });
18
22
  const utils_1 = require("./utils");
19
- const i18n_1 = require("./i18n");
20
23
  /**
21
24
  * Get the inquirer prompts for odata service.
22
25
  *
@@ -30,7 +33,9 @@ const i18n_1 = require("./i18n");
30
33
  async function getPrompts(promptOptions, logger, enableGuidedAnswers = false, telemetryClient, isYUI = false) {
31
34
  // prompt texts must be loaded before the prompts are created, wait for the i18n bundle to be initialized
32
35
  await (0, i18n_1.initI18nOdataServiceInquirer)();
33
- logger_helper_1.default.logger = logger ?? new logger_1.ToolsLogger({ logPrefix: '@sap-ux/odata-service-inquirer' });
36
+ if (logger) {
37
+ logger_helper_1.default.logger = logger;
38
+ }
34
39
  error_handler_1.ErrorHandler.logger = logger_helper_1.default.logger;
35
40
  error_handler_1.ErrorHandler.guidedAnswersEnabled = enableGuidedAnswers;
36
41
  utils_1.PromptState.isYUI = isYUI;
@@ -54,6 +59,10 @@ exports.getPrompts = getPrompts;
54
59
  * @returns the prompt answers
55
60
  */
56
61
  async function prompt(adapter, promptOptions, logger, enableGuidedAnswers, telemetryClient, isYUI = false) {
62
+ if (adapter?.promptModule && promptOptions?.serviceSelection?.useAutoComplete) {
63
+ const pm = adapter.promptModule;
64
+ pm.registerPrompt('autocomplete', inquirer_autocomplete_prompt_1.default);
65
+ }
57
66
  const odataServicePrompts = (await getPrompts(promptOptions, logger, enableGuidedAnswers, telemetryClient, isYUI))
58
67
  .prompts;
59
68
  const answers = await adapter.prompt(odataServicePrompts);
@@ -62,4 +71,20 @@ async function prompt(adapter, promptOptions, logger, enableGuidedAnswers, telem
62
71
  return answers;
63
72
  }
64
73
  exports.prompt = prompt;
74
+ /**
75
+ * Get the prompts for an abap on premise system. This can be used to create a new system connection.
76
+ *
77
+ * @param systemNamePromptOptions options for the system name prompt see {@link SystemNamePromptOptions}
78
+ * @param logger a logger compatible with the {@link Logger} interface
79
+ * @returns questions for creating a new abap on prem system connection
80
+ */
81
+ async function getAbapOnPremSystemPrompts(systemNamePromptOptions, logger) {
82
+ if (logger) {
83
+ logger_helper_1.default.logger = logger;
84
+ }
85
+ // prompt texts must be loaded before the prompts are created, wait for the i18n bundle to be initialized
86
+ await (0, i18n_1.initI18nOdataServiceInquirer)();
87
+ return (0, questions_1.getAbapOnPremSystemQuestions)(systemNamePromptOptions);
88
+ }
89
+ exports.getAbapOnPremSystemPrompts = getAbapOnPremSystemPrompts;
65
90
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,160 @@
1
+ import type { IValidationLink } from '@sap-devx/yeoman-ui-types';
2
+ import type { AxiosRequestConfig, CatalogService, ODataService, ServiceProvider } from '@sap-ux/axios-extension';
3
+ import { ODataVersion } from '@sap-ux/axios-extension';
4
+ /**
5
+ * Structure to store validity information about url to be validated.
6
+ */
7
+ interface Validity {
8
+ urlFormat?: boolean;
9
+ reachable?: boolean;
10
+ authRequired?: boolean;
11
+ authenticated?: boolean;
12
+ canSkipCertError?: boolean;
13
+ }
14
+ type ValidationResult = string | boolean | IValidationLink;
15
+ /**
16
+ * Class that validates the connection to a service url or catalog url.
17
+ * This will determine if authentication is required and if the service/catalog is reachable, generating messages to guide the user.
18
+ * It is optimized for re-validation of the same url, so that the validation is not repeated if not required.
19
+ *
20
+ */
21
+ export declare class ConnectionValidator {
22
+ readonly validity: Validity;
23
+ private _validatedUrl;
24
+ private _odataService;
25
+ private _serviceProvider;
26
+ private _axiosConfig;
27
+ private _catalogV2;
28
+ private _catalogV4;
29
+ /**
30
+ * Getter for the axios configuration.
31
+ *
32
+ * @returns the axios configuration
33
+ */
34
+ get axiosConfig(): AxiosRequestConfig;
35
+ /**
36
+ * Get the odata service instance.
37
+ *
38
+ * @returns the odata service instance
39
+ */
40
+ get odataService(): ODataService;
41
+ /**
42
+ * Get the catalogs for the odata versions. Note that one of these may not be defined where a specific odata version is required.
43
+ *
44
+ * @returns the catalog services for each the odata versions
45
+ */
46
+ get catalogs(): Record<ODataVersion, CatalogService>;
47
+ /**
48
+ *
49
+ * @returns the current connections service provider
50
+ */
51
+ get serviceProvider(): ServiceProvider;
52
+ /**
53
+ * Calls a given service or system url to test its reachability and authentication requirements.
54
+ * If the url is a system url, it will attempt to use the catalog service to get the service info.
55
+ *
56
+ * @param url a service url (<protocol://<host>:<port>/<service-path>) or a system url (<protocol://<host>:<port>)
57
+ * @param username optional username
58
+ * @param password optional password
59
+ * @param options options for the connection validation
60
+ * @param options.ignoreCertError ignore some certificate errors
61
+ * @param options.isSystem if true, the url will be treated as a system url rather than a service url
62
+ * @param options.odataVersion if specified will restrict catalog requests to only the specified odata version
63
+ * @returns the status code or error returned by the connection attempt
64
+ */
65
+ private checkSapService;
66
+ /**
67
+ * Create the axios configuration object for the service or system connection.
68
+ *
69
+ * @param url the service or system url
70
+ * @param ignoreCertError if true the config will be set to ignore cert errors
71
+ * @param username provided for basic authentication
72
+ * @param password provided for basic authentication
73
+ * @returns the axios configuration object
74
+ */
75
+ private createAxiosConfig;
76
+ /**
77
+ * Create the connection for a service url. The base url should be provided with the axios config property.
78
+ *
79
+ * @param axiosConfig the axios request configuration
80
+ * @param servicePath the service path without the origin
81
+ */
82
+ private createServiceConnection;
83
+ /**
84
+ * Create the connection for a system url. The system url should be provided as a base url axios config property.
85
+ *
86
+ * @param axiosConfig the axios request configuration
87
+ * @param odataVersion the odata version to restrict the catalog requests if only a specific version is required
88
+ */
89
+ private createSystemConnection;
90
+ /**
91
+ * Validates the service url format as well as its reachability.
92
+ *
93
+ * @param serviceUrl the odata service url to validate
94
+ * @param options options for the connection validation
95
+ * @param options.ignoreCertError ignore some certificate errors
96
+ * @param options.forceReValidation force re-validation of the url
97
+ * @param options.isSystem if true, the url will be treated as a system url rather than a service url
98
+ * @param options.odataVersion if specified will restrict catalog requests to only the specified odata version
99
+ * @returns true if the url is reachable, false if not, or an error message string
100
+ */
101
+ validateUrl(serviceUrl: string, { ignoreCertError, forceReValidation, isSystem, odataVersion }?: {
102
+ ignoreCertError?: boolean;
103
+ forceReValidation?: boolean;
104
+ isSystem?: boolean;
105
+ odataVersion?: ODataVersion;
106
+ }): Promise<ValidationResult>;
107
+ /**
108
+ * Translate the status code into a validation result.
109
+ * Sets the instance validity state based on the status code.
110
+ *
111
+ * @param status a http request status code used to determine the validation result
112
+ * @returns true if the url is reachable, false if not, or an error message string
113
+ */
114
+ private getValidationResultFromStatusCode;
115
+ /**
116
+ * Is a string nil or whitespace only.
117
+ *
118
+ * @param url the string to test
119
+ * @returns true if the string is nil or whitespace
120
+ */
121
+ private isEmptyString;
122
+ /**
123
+ * Tests if the url has already been validated.
124
+ *
125
+ * @param url the full url to test for previous validation
126
+ * @returns true if the url has already been validated
127
+ */
128
+ private isUrlValidated;
129
+ /**
130
+ * Test the connectivity with the specified service url using the provided credentials.
131
+ *
132
+ * @param url the url to validate
133
+ * @param username user name
134
+ * @param password password
135
+ * @param options options for the connection authentication validation
136
+ * @param options.ignoreCertError ignore some certificate errors
137
+ * @param options.isSystem if true, the url will be treated as a system url rather than a service url
138
+ * @param options.sapClient the sap client to use for the connection
139
+ * @param options.odataVersion if specified will restrict catalog requests to only the specified odata version
140
+ * @returns true if the authentication is successful, false if not, or an error message string
141
+ */
142
+ validateAuth(url: string, username: string, password: string, { ignoreCertError, isSystem, sapClient, odataVersion }?: {
143
+ ignoreCertError?: boolean;
144
+ isSystem?: boolean;
145
+ odataVersion?: ODataVersion;
146
+ sapClient?: string;
147
+ }): Promise<ValidationResult>;
148
+ /**
149
+ * Reset the validity state.
150
+ */
151
+ private resetValidity;
152
+ /**
153
+ * Set the rejectUnauthorized option of the global https agent.
154
+ *
155
+ * @param rejectUnauthorized - true to reject unauthorized certificates, false to accept them
156
+ */
157
+ static setGlobalRejectUnauthorized(rejectUnauthorized: boolean): void;
158
+ }
159
+ export {};
160
+ //# sourceMappingURL=connectionValidator.d.ts.map
@@ -4,13 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ConnectionValidator = void 0;
7
+ const axios_extension_1 = require("@sap-ux/axios-extension");
7
8
  const btp_utils_1 = require("@sap-ux/btp-utils");
8
- const error_handler_1 = require("../../../error-handler/error-handler");
9
- const prompt_helpers_1 = require("../../prompt-helpers");
10
- const i18n_1 = require("../../../i18n");
11
9
  const https_1 = __importDefault(require("https"));
12
- const logger_helper_1 = __importDefault(require("../../logger-helper"));
13
- const axios_extension_1 = require("@sap-ux/axios-extension");
10
+ const error_handler_1 = require("../error-handler/error-handler");
11
+ const i18n_1 = require("../i18n");
12
+ const types_1 = require("../types");
13
+ const logger_helper_1 = __importDefault(require("./logger-helper"));
14
+ const prompt_helpers_1 = require("./prompt-helpers");
14
15
  // Cert errors that may be ignored by prompt user
15
16
  const ignorableCertErrors = [error_handler_1.ERROR_TYPE.CERT_SELF_SIGNED, error_handler_1.ERROR_TYPE.CERT_SELF_SIGNED_CERT_IN_CHAIN];
16
17
  /**
@@ -23,7 +24,10 @@ class ConnectionValidator {
23
24
  validity = {};
24
25
  _validatedUrl;
25
26
  _odataService;
27
+ _serviceProvider;
26
28
  _axiosConfig;
29
+ _catalogV2;
30
+ _catalogV4;
27
31
  /**
28
32
  * Getter for the axios configuration.
29
33
  *
@@ -41,15 +45,37 @@ class ConnectionValidator {
41
45
  return this._odataService;
42
46
  }
43
47
  /**
44
- * Calls a given service url to test its reachability and authentication requirements.
48
+ * Get the catalogs for the odata versions. Note that one of these may not be defined where a specific odata version is required.
49
+ *
50
+ * @returns the catalog services for each the odata versions
51
+ */
52
+ get catalogs() {
53
+ return {
54
+ [axios_extension_1.ODataVersion.v2]: this._catalogV2,
55
+ [axios_extension_1.ODataVersion.v4]: this._catalogV4
56
+ };
57
+ }
58
+ /**
45
59
  *
46
- * @param url a service url (<protocol://<host>:<port>/<service-path>)
60
+ * @returns the current connections service provider
61
+ */
62
+ get serviceProvider() {
63
+ return this._serviceProvider;
64
+ }
65
+ /**
66
+ * Calls a given service or system url to test its reachability and authentication requirements.
67
+ * If the url is a system url, it will attempt to use the catalog service to get the service info.
68
+ *
69
+ * @param url a service url (<protocol://<host>:<port>/<service-path>) or a system url (<protocol://<host>:<port>)
47
70
  * @param username optional username
48
71
  * @param password optional password
49
- * @param [ignoreCertError] optional, ignore some certificate errors
72
+ * @param options options for the connection validation
73
+ * @param options.ignoreCertError ignore some certificate errors
74
+ * @param options.isSystem if true, the url will be treated as a system url rather than a service url
75
+ * @param options.odataVersion if specified will restrict catalog requests to only the specified odata version
50
76
  * @returns the status code or error returned by the connection attempt
51
77
  */
52
- async checkSapService(url, username, password, ignoreCertError = false) {
78
+ async checkSapService(url, username, password, { ignoreCertError = false, isSystem = false, odataVersion } = {}) {
53
79
  const isBAS = (0, btp_utils_1.isAppStudio)();
54
80
  try {
55
81
  // Auto add trailing '/' to path
@@ -62,23 +88,15 @@ class ConnectionValidator {
62
88
  if (isBAS) {
63
89
  url.searchParams.append('saml2', 'disabled');
64
90
  }
65
- let axiosConfig = {
66
- params: url.searchParams,
67
- ignoreCertErrors: ignoreCertError,
68
- cookies: ''
69
- };
70
- if (username && password) {
71
- axiosConfig = Object.assign(axiosConfig, {
72
- auth: {
73
- username,
74
- password
75
- }
76
- });
91
+ const axiosConfig = this.createAxiosConfig(url, ignoreCertError, username, password);
92
+ // If system, use catalog service to get the services info
93
+ if (isSystem) {
94
+ await this.createSystemConnection(axiosConfig, odataVersion);
95
+ }
96
+ else {
97
+ // Full service URL
98
+ await this.createServiceConnection(axiosConfig, url.pathname);
77
99
  }
78
- this._axiosConfig = axiosConfig;
79
- this._odataService = (0, axios_extension_1.createServiceForUrl)(url.origin + url.pathname, this._axiosConfig);
80
- logger_helper_1.default.attachAxiosLogger(this._odataService.interceptors);
81
- await this._odataService.get('');
82
100
  return 200;
83
101
  }
84
102
  catch (e) {
@@ -99,15 +117,86 @@ class ConnectionValidator {
99
117
  ConnectionValidator.setGlobalRejectUnauthorized(true);
100
118
  }
101
119
  }
120
+ /**
121
+ * Create the axios configuration object for the service or system connection.
122
+ *
123
+ * @param url the service or system url
124
+ * @param ignoreCertError if true the config will be set to ignore cert errors
125
+ * @param username provided for basic authentication
126
+ * @param password provided for basic authentication
127
+ * @returns the axios configuration object
128
+ */
129
+ createAxiosConfig(url, ignoreCertError, username, password) {
130
+ let axiosConfig = {
131
+ params: Object.fromEntries(url.searchParams),
132
+ ignoreCertErrors: ignoreCertError,
133
+ cookies: '',
134
+ baseURL: url.origin
135
+ };
136
+ if (username && password) {
137
+ axiosConfig = Object.assign(axiosConfig, {
138
+ auth: {
139
+ username,
140
+ password
141
+ }
142
+ });
143
+ }
144
+ return axiosConfig;
145
+ }
146
+ /**
147
+ * Create the connection for a service url. The base url should be provided with the axios config property.
148
+ *
149
+ * @param axiosConfig the axios request configuration
150
+ * @param servicePath the service path without the origin
151
+ */
152
+ async createServiceConnection(axiosConfig, servicePath) {
153
+ this._axiosConfig = axiosConfig;
154
+ this._serviceProvider = (0, axios_extension_1.create)(this._axiosConfig);
155
+ this._odataService = this._serviceProvider.service(servicePath);
156
+ logger_helper_1.default.attachAxiosLogger(this._serviceProvider.interceptors);
157
+ await this._odataService.get('');
158
+ }
159
+ /**
160
+ * Create the connection for a system url. The system url should be provided as a base url axios config property.
161
+ *
162
+ * @param axiosConfig the axios request configuration
163
+ * @param odataVersion the odata version to restrict the catalog requests if only a specific version is required
164
+ */
165
+ async createSystemConnection(axiosConfig, odataVersion) {
166
+ this._axiosConfig = axiosConfig;
167
+ this._serviceProvider = (0, axios_extension_1.createForAbap)(this._axiosConfig);
168
+ logger_helper_1.default.attachAxiosLogger(this._serviceProvider.interceptors);
169
+ if (!odataVersion || odataVersion === axios_extension_1.ODataVersion.v2) {
170
+ this._catalogV2 = this._serviceProvider.catalog(axios_extension_1.ODataVersion.v2);
171
+ }
172
+ if (!odataVersion || odataVersion === axios_extension_1.ODataVersion.v4) {
173
+ this._catalogV4 = this._serviceProvider.catalog(axios_extension_1.ODataVersion.v4);
174
+ }
175
+ try {
176
+ this._catalogV2 ? await this._catalogV2.listServices() : await this._catalogV4.listServices();
177
+ }
178
+ catch (error) {
179
+ // We will try the v4 catalog if v2 returns a 404
180
+ if (error.response?.status === 404 && this._catalogV4) {
181
+ await this._catalogV4.listServices();
182
+ }
183
+ else {
184
+ throw error;
185
+ }
186
+ }
187
+ }
102
188
  /**
103
189
  * Validates the service url format as well as its reachability.
104
190
  *
105
191
  * @param serviceUrl the odata service url to validate
106
- * @param ignoreCertError ignore some certificate errors
107
- * @param forceReValidation force re-validation of the url
192
+ * @param options options for the connection validation
193
+ * @param options.ignoreCertError ignore some certificate errors
194
+ * @param options.forceReValidation force re-validation of the url
195
+ * @param options.isSystem if true, the url will be treated as a system url rather than a service url
196
+ * @param options.odataVersion if specified will restrict catalog requests to only the specified odata version
108
197
  * @returns true if the url is reachable, false if not, or an error message string
109
198
  */
110
- async validateUrl(serviceUrl, ignoreCertError = false, forceReValidation = false) {
199
+ async validateUrl(serviceUrl, { ignoreCertError = false, forceReValidation = false, isSystem = false, odataVersion } = {}) {
111
200
  if (this.isEmptyString(serviceUrl)) {
112
201
  this.resetValidity();
113
202
  return false;
@@ -121,7 +210,11 @@ class ConnectionValidator {
121
210
  return (0, i18n_1.t)('errors.invalidUrl');
122
211
  }
123
212
  // Ignore path if a system url
124
- const status = await this.checkSapService(url, undefined, undefined, ignoreCertError);
213
+ const status = await this.checkSapService(url, undefined, undefined, {
214
+ ignoreCertError,
215
+ isSystem,
216
+ odataVersion
217
+ });
125
218
  logger_helper_1.default.logger.debug(`ConnectionValidator.validateUrl() - status: ${status}; url: ${serviceUrl}`);
126
219
  this.validity.urlFormat = true;
127
220
  this._validatedUrl = serviceUrl;
@@ -143,7 +236,7 @@ class ConnectionValidator {
143
236
  * Sets the instance validity state based on the status code.
144
237
  *
145
238
  * @param status a http request status code used to determine the validation result
146
- * @returns
239
+ * @returns true if the url is reachable, false if not, or an error message string
147
240
  */
148
241
  getValidationResultFromStatusCode(status) {
149
242
  if (status === 200) {
@@ -199,24 +292,35 @@ class ConnectionValidator {
199
292
  /**
200
293
  * Test the connectivity with the specified service url using the provided credentials.
201
294
  *
202
- * @param serviceUrl optional, the service url to validate
295
+ * @param url the url to validate
203
296
  * @param username user name
204
297
  * @param password password
205
- * @param ignoreCertError optional, ignore some certificate errors
298
+ * @param options options for the connection authentication validation
299
+ * @param options.ignoreCertError ignore some certificate errors
300
+ * @param options.isSystem if true, the url will be treated as a system url rather than a service url
301
+ * @param options.sapClient the sap client to use for the connection
302
+ * @param options.odataVersion if specified will restrict catalog requests to only the specified odata version
206
303
  * @returns true if the authentication is successful, false if not, or an error message string
207
304
  */
208
- async validateAuth(serviceUrl, username, password, ignoreCertError = false) {
209
- if (!serviceUrl) {
210
- return false;
211
- }
212
- if (!this.validity.reachable) {
305
+ async validateAuth(url, username, password, { ignoreCertError = false, isSystem = false, sapClient, odataVersion } = {}) {
306
+ if (!url) {
213
307
  return false;
214
308
  }
215
309
  try {
216
- const url = new URL(serviceUrl);
217
- this.validity.authenticated =
218
- (await this.checkSapService(url, username, password, ignoreCertError)) === 200;
219
- return this.validity.authenticated === true ? true : (0, i18n_1.t)('errors.authenticationFailed');
310
+ const urlObject = new URL(url);
311
+ if (sapClient) {
312
+ urlObject.searchParams.append(types_1.SAP_CLIENT_KEY, sapClient);
313
+ }
314
+ const status = await this.checkSapService(urlObject, username, password, {
315
+ ignoreCertError,
316
+ isSystem,
317
+ odataVersion
318
+ });
319
+ const valResult = this.getValidationResultFromStatusCode(status);
320
+ if (valResult === true && this.validity.authenticated === true) {
321
+ return true;
322
+ }
323
+ return valResult;
220
324
  }
221
325
  catch (error) {
222
326
  return prompt_helpers_1.errorHandler.getErrorMsg(error) ?? false;
@@ -0,0 +1,44 @@
1
+ import { ODataVersion } from '@sap-ux/axios-extension';
2
+ import { OdataVersion } from '@sap-ux/odata-service-writer';
3
+ import type { Question } from 'inquirer';
4
+ import { promptNames, type OdataServiceAnswers, type OdataServicePromptOptions, type SystemNamePromptOptions } from '../../../../types';
5
+ import { ConnectionValidator } from '../../../connectionValidator';
6
+ import type { NewSystemAnswers } from '../new-system/questions';
7
+ export declare enum abapOnPremInternalPromptNames {
8
+ systemUrl = "systemUrl",
9
+ sapClient = "sapClient",
10
+ systemUsername = "abapSystemUsername",
11
+ systemPassword = "abapSystemPassword"
12
+ }
13
+ export interface AbapOnPremAnswers extends Partial<OdataServiceAnswers>, NewSystemAnswers {
14
+ [abapOnPremInternalPromptNames.systemUrl]?: string;
15
+ [abapOnPremInternalPromptNames.systemUsername]?: string;
16
+ [abapOnPremInternalPromptNames.systemPassword]?: string;
17
+ [promptNames.serviceSelection]?: ServiceAnswer;
18
+ }
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
+ /**
29
+ * Get the Abap on-premise datasource questions.
30
+ *
31
+ * @param promptOptions options for prompts. Applicable options are: {@link ServiceSelectionPromptOptions}, {@link SystemNamePromptOptions}
32
+ * @returns property questions for the Abap on-premise datasource
33
+ */
34
+ export declare function getAbapOnPremQuestions(promptOptions?: OdataServicePromptOptions): Question<AbapOnPremAnswers>[];
35
+ /**
36
+ * Gets the Abap on-premise system questions.
37
+ *
38
+ * @param systemNamePromptOptions options for the system name prompt see {@link SystemNamePromptOptions}
39
+ * @param connectionValidator reference to the existing connection validator, a new one will be created otherwise
40
+ * @param requiredOdataVersion the required OData version for the service, this will be used to narrow the catalog service connections
41
+ * @returns the Abap on-premise system questions
42
+ */
43
+ export declare function getAbapOnPremSystemQuestions(systemNamePromptOptions?: SystemNamePromptOptions, connectionValidator?: ConnectionValidator, requiredOdataVersion?: OdataVersion): Question<AbapOnPremAnswers>[];
44
+ //# sourceMappingURL=questions.d.ts.map