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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/error-handler/error-handler.d.ts +2 -2
  2. package/dist/error-handler/error-handler.js +4 -4
  3. package/dist/index.d.ts +2 -12
  4. package/dist/index.js +3 -20
  5. package/dist/prompts/connectionValidator.d.ts +121 -27
  6. package/dist/prompts/connectionValidator.js +231 -36
  7. package/dist/prompts/datasources/sap-system/abap-on-btp/cf-helper.d.ts +9 -0
  8. package/dist/prompts/datasources/sap-system/abap-on-btp/cf-helper.js +55 -0
  9. package/dist/prompts/datasources/sap-system/abap-on-btp/questions.d.ts +34 -0
  10. package/dist/prompts/datasources/sap-system/abap-on-btp/questions.js +213 -0
  11. package/dist/prompts/datasources/sap-system/abap-on-prem/questions.d.ts +7 -16
  12. package/dist/prompts/datasources/sap-system/abap-on-prem/questions.js +16 -164
  13. package/dist/prompts/datasources/sap-system/new-system/questions.d.ts +36 -5
  14. package/dist/prompts/datasources/sap-system/new-system/questions.js +229 -37
  15. package/dist/prompts/datasources/sap-system/{abap-on-prem → new-system}/service-helper.d.ts +11 -1
  16. package/dist/prompts/datasources/sap-system/{abap-on-prem → new-system}/service-helper.js +30 -1
  17. package/dist/prompts/datasources/sap-system/new-system/types.d.ts +16 -0
  18. package/dist/prompts/datasources/sap-system/new-system/types.js +9 -0
  19. package/dist/prompts/datasources/sap-system/prompt-helpers.d.ts +3 -3
  20. package/dist/prompts/datasources/sap-system/prompt-helpers.js +4 -4
  21. package/dist/prompts/datasources/sap-system/validators.d.ts +10 -1
  22. package/dist/prompts/datasources/sap-system/validators.js +27 -2
  23. package/dist/prompts/datasources/service-url/questions.js +20 -8
  24. package/dist/prompts/datasources/service-url/validators.d.ts +4 -4
  25. package/dist/prompts/datasources/service-url/validators.js +4 -6
  26. package/dist/prompts/prompts.js +6 -9
  27. package/dist/translations/odata-service-inquirer.i18n.json +24 -4
  28. package/dist/types.d.ts +13 -3
  29. package/dist/types.js +5 -1
  30. package/dist/utils/index.d.ts +17 -0
  31. package/dist/utils/index.js +29 -1
  32. package/package.json +2 -1
@@ -123,8 +123,8 @@ export declare class ErrorHandler {
123
123
  * Used by validate functions to report in-line user friendly errors.
124
124
  * Checks if there is an existing error.
125
125
  *
126
- * @param error optional, if provided get the end user message that it maps to, otherwise get the previous error message
127
- * @param reset optional, resets the previous error state if true
126
+ * @param error optional, if provided get the end user message that it maps to, otherwise get the previous error message, if a boolean is passed it will be interpreted as `reset`.
127
+ * @param reset optional, resets the previous error state if true, if error is omitted reset may be passed as the first argument
128
128
  * @param fallback optional, return the message of the specified ERROR_TYPE if no previous end user message and no error specified
129
129
  * @returns The error message
130
130
  */
@@ -314,21 +314,21 @@ class ErrorHandler {
314
314
  * Used by validate functions to report in-line user friendly errors.
315
315
  * Checks if there is an existing error.
316
316
  *
317
- * @param error optional, if provided get the end user message that it maps to, otherwise get the previous error message
318
- * @param reset optional, resets the previous error state if true
317
+ * @param error optional, if provided get the end user message that it maps to, otherwise get the previous error message, if a boolean is passed it will be interpreted as `reset`.
318
+ * @param reset optional, resets the previous error state if true, if error is omitted reset may be passed as the first argument
319
319
  * @param fallback optional, return the message of the specified ERROR_TYPE if no previous end user message and no error specified
320
320
  * @returns The error message
321
321
  */
322
322
  getErrorMsg(error, reset, fallback) {
323
323
  let errorMsg;
324
- if (error) {
324
+ if (error && typeof error !== 'boolean') {
325
325
  errorMsg = ErrorHandler.mapErrorToMsg(error).errorMsg;
326
326
  }
327
327
  // Get previous error message
328
328
  if (!errorMsg) {
329
329
  errorMsg = this.currentErrorMsg ?? (fallback ? ErrorHandler.getErrorMsgFromType(fallback) : undefined);
330
330
  }
331
- if (reset) {
331
+ if (error === true || reset) {
332
332
  this.currentErrorMsg = null;
333
333
  this.currentErrorType = null;
334
334
  }
package/dist/index.d.ts CHANGED
@@ -2,11 +2,9 @@ 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 type { Question } from 'inquirer';
6
5
  import { ERROR_TYPE, ErrorHandler } from './error-handler/error-handler';
7
- import type { AbapOnPremAnswers } from './prompts/datasources/sap-system/abap-on-prem/questions';
8
6
  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
+ import { DatasourceType, promptNames, type CapRuntime, type CapService, type OdataServiceAnswers, type OdataServicePromptOptions, type OdataServiceQuestion, type SapSystemType } from './types';
10
8
  /**
11
9
  * Get the inquirer prompts for odata service.
12
10
  *
@@ -33,13 +31,5 @@ declare function getPrompts(promptOptions?: OdataServicePromptOptions, logger?:
33
31
  * @returns the prompt answers
34
32
  */
35
33
  declare function prompt(adapter: InquirerAdapter, promptOptions?: OdataServicePromptOptions, logger?: Logger, enableGuidedAnswers?: boolean, telemetryClient?: ToolsSuiteTelemetryClient, isYUI?: boolean): Promise<OdataServiceAnswers>;
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
+ export { DatasourceType, ERROR_TYPE, ErrorHandler, OdataVersion, getPrompts, newSystemChoiceValue, prompt, promptNames, type CapRuntime, type CapService, type InquirerAdapter, type OdataServiceAnswers, type OdataServicePromptOptions, type SapSystemType };
45
35
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ 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.newSystemChoiceValue = exports.promptNames = exports.prompt = exports.getPrompts = exports.getAbapOnPremSystemPrompts = exports.OdataVersion = exports.DatasourceType = void 0;
6
+ exports.promptNames = exports.prompt = exports.newSystemChoiceValue = exports.getPrompts = exports.OdataVersion = exports.ErrorHandler = exports.ERROR_TYPE = exports.DatasourceType = void 0;
7
7
  const odata_service_writer_1 = require("@sap-ux/odata-service-writer");
8
8
  Object.defineProperty(exports, "OdataVersion", { enumerable: true, get: function () { return odata_service_writer_1.OdataVersion; } });
9
9
  const inquirer_autocomplete_prompt_1 = __importDefault(require("inquirer-autocomplete-prompt"));
@@ -12,9 +12,8 @@ Object.defineProperty(exports, "ERROR_TYPE", { enumerable: true, get: function (
12
12
  Object.defineProperty(exports, "ErrorHandler", { enumerable: true, get: function () { return error_handler_1.ErrorHandler; } });
13
13
  const i18n_1 = require("./i18n");
14
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; } });
15
+ const questions_1 = require("./prompts/datasources/sap-system/new-system/questions");
16
+ Object.defineProperty(exports, "newSystemChoiceValue", { enumerable: true, get: function () { return questions_1.newSystemChoiceValue; } });
18
17
  const logger_helper_1 = __importDefault(require("./prompts/logger-helper"));
19
18
  const types_1 = require("./types");
20
19
  Object.defineProperty(exports, "DatasourceType", { enumerable: true, get: function () { return types_1.DatasourceType; } });
@@ -71,20 +70,4 @@ async function prompt(adapter, promptOptions, logger, enableGuidedAnswers, telem
71
70
  return answers;
72
71
  }
73
72
  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;
90
73
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
1
  import type { IValidationLink } from '@sap-devx/yeoman-ui-types';
2
- import type { AxiosRequestConfig, CatalogService, ODataService, ServiceProvider } from '@sap-ux/axios-extension';
2
+ import type { AxiosRequestConfig, CatalogService, ODataService, ServiceInfo, ServiceProvider } from '@sap-ux/axios-extension';
3
3
  import { ODataVersion } from '@sap-ux/axios-extension';
4
4
  /**
5
5
  * Structure to store validity information about url to be validated.
@@ -12,11 +12,13 @@ interface Validity {
12
12
  canSkipCertError?: boolean;
13
13
  }
14
14
  type ValidationResult = string | boolean | IValidationLink;
15
+ export type SystemAuthType = 'serviceKey' | 'reentranceTicket' | 'basic' | 'unknown';
15
16
  /**
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
- *
17
+ * Class that can be used to determine the connectivity using a service url, system url, or service info (UAA Key details) or reentrance ticket.
18
+ * This will determine if if the service/catalog is reachable, authentication is required and generates ting messages to guide the user.
19
+ * Certain types of certificate errors can be ignored if required. However, the end-user should be warned about the risks using a prompt message.
20
+ * Catalog requests may be made multiple times for the same url, but the underlying connectivity module (@sap-ux/axios-extension) will cache the results to avoid repeated network requests.
21
+ * The class also stores the current connection state, including the service provider, odata service, and catalog services.
20
22
  */
21
23
  export declare class ConnectionValidator {
22
24
  readonly validity: Validity;
@@ -27,29 +29,87 @@ export declare class ConnectionValidator {
27
29
  private _axiosConfig;
28
30
  private _catalogV2;
29
31
  private _catalogV4;
32
+ private _systemAuthType;
33
+ private _serviceInfo;
34
+ private _connectedUserName;
35
+ private _connectedSystemName;
36
+ private _refreshToken;
30
37
  /**
31
38
  * Getter for the axios configuration.
32
39
  *
33
40
  * @returns the axios configuration
34
41
  */
35
- get axiosConfig(): AxiosRequestConfig;
42
+ get axiosConfig(): AxiosRequestConfig | undefined;
36
43
  /**
37
44
  * Get the odata service instance.
38
45
  *
39
46
  * @returns the odata service instance
40
47
  */
41
- get odataService(): ODataService;
48
+ get odataService(): ODataService | undefined;
42
49
  /**
43
50
  * Get the catalogs for the odata versions. Note that one of these may not be defined where a specific odata version is required.
44
51
  *
45
52
  * @returns the catalog services for each the odata versions
46
53
  */
47
- get catalogs(): Record<ODataVersion, CatalogService>;
54
+ get catalogs(): Record<ODataVersion, CatalogService | undefined>;
48
55
  /**
49
56
  *
50
57
  * @returns the current connections service provider
51
58
  */
52
- get serviceProvider(): ServiceProvider;
59
+ get serviceProvider(): ServiceProvider | undefined;
60
+ /**
61
+ * The auth type used to create an authenticated connection to the system.
62
+ *
63
+ * @returns the system auth type
64
+ */
65
+ get systemAuthType(): SystemAuthType | undefined;
66
+ /**
67
+ * The auth type used to create an authenticated connection to the system.
68
+ *
69
+ * @param value the system auth type
70
+ */
71
+ set systemAuthType(value: SystemAuthType);
72
+ /**
73
+ * Get the validated url. This is the url that has been successfully validated (not necessarily connected). Use validity to check if the url is reachable.
74
+ *
75
+ * @returns the validated url
76
+ */
77
+ get validatedUrl(): string | undefined;
78
+ /**
79
+ * Get the service info used to connect to the system.
80
+ *
81
+ * @returns the service info
82
+ */
83
+ get serviceInfo(): ServiceInfo | undefined;
84
+ /**
85
+ * Set the service info used to connect to the system.
86
+ *
87
+ * @param serviceInfo the service info
88
+ */
89
+ set serviceInfo(serviceInfo: ServiceInfo);
90
+ /**
91
+ * Get the connected user name.
92
+ *
93
+ * @returns the connected user name
94
+ */
95
+ get connectedUserName(): string | undefined;
96
+ /**
97
+ * Get the refresh token.
98
+ *
99
+ * @returns the refresh token
100
+ */
101
+ get refreshToken(): string | undefined;
102
+ /**
103
+ * Get the connected system name. If previously set this will be used, otherwise the name is determined
104
+ * by the system auth type, or the validated url.
105
+ *
106
+ * @returns the connected system name
107
+ */
108
+ get connectedSystemName(): string | undefined;
109
+ /**
110
+ *
111
+ */
112
+ set connectedSystemName(value: string | undefined);
53
113
  /**
54
114
  * Calls a given service or system url to test its reachability and authentication requirements.
55
115
  * If the url is a system url, it will attempt to use the catalog service to get the service info.
@@ -63,7 +123,7 @@ export declare class ConnectionValidator {
63
123
  * @param options.odataVersion if specified will restrict catalog requests to only the specified odata version
64
124
  * @returns the status code or error returned by the connection attempt
65
125
  */
66
- private checkSapService;
126
+ private checkSapServiceUrl;
67
127
  /**
68
128
  * Create the axios configuration object for the service or system connection.
69
129
  *
@@ -80,22 +140,56 @@ export declare class ConnectionValidator {
80
140
  * @param axiosConfig the axios request configuration
81
141
  * @param servicePath the service path without the origin
82
142
  */
83
- private createServiceConnection;
143
+ private createOdataServiceConnection;
144
+ resetConnectionState(): void;
84
145
  /**
85
- * Create the connection for a system url. The system url should be provided as a base url axios config property.
146
+ * Create the connection for a system url, the specified axios config or the specified service info.
86
147
  *
87
- * @param axiosConfig the axios request configuration
88
- * @param odataVersion the odata version to restrict the catalog requests if only a specific version is required
148
+ * @param connectConfig the connection configuration
149
+ * @param connectConfig.axiosConfig the axios request configuration
150
+ * @param connectConfig.url the system url
151
+ * @param connectConfig.serviceInfo the service info
152
+ * @param connectConfig.odataVersion the odata version to restrict the catalog requests if only a specific version is required
89
153
  */
90
154
  private createSystemConnection;
91
155
  /**
92
- * Validates the service url format as well as its reachability.
156
+ * Check if we should attempt to use the v4 catalog service as a fallback.
157
+ *
158
+ * @param statusCode http status code, if not provided will return false as we cannot determine the reason for v2 catalog request failure
159
+ * @returns true if we should attempt the v4 catalog service
160
+ */
161
+ private shouldAttemptV4Catalog;
162
+ /**
163
+ * Callback for when the refresh token changes.
164
+ *
165
+ * @param refreshToken the new refresh token
166
+ */
167
+ private refreshTokenChangedCb;
168
+ /**
169
+ * Get the service provider for the Abap on Cloud environment.
93
170
  *
94
- * @param serviceUrl the odata service url to validate
171
+ * @param url the system url
172
+ * @param serviceInfo the service info
173
+ * @returns the service provider
174
+ */
175
+ private getAbapOnCloudServiceProvider;
176
+ /**
177
+ * Validate the system connectivity with the specified service info (containing UAA details).
178
+ *
179
+ * @param serviceInfo the service info containing the UAA details
180
+ * @param odataVersion the odata version to restrict the catalog requests if only a specific version is required
181
+ * @returns true if the system is reachable, false if not, or an error message string
182
+ */
183
+ validateServiceInfo(serviceInfo: ServiceInfo, odataVersion?: ODataVersion): Promise<ValidationResult>;
184
+ /**
185
+ * Validates the system or service url format as well as its reachability.
186
+ *
187
+ * @param serviceUrl the url to validate, may be a system or service url.
188
+ * Note that if systemAuthType is specified, the url will be treated as a system url (only the origin will be considered)
95
189
  * @param options options for the connection validation
96
190
  * @param options.ignoreCertError ignore some certificate errors
97
- * @param options.forceReValidation force re-validation of the url even if the same url has been prevously validated
98
- * @param options.isSystem if true, the url will be treated as a system url rather than a service url
191
+ * @param options.forceReValidation force re-validation of the url
192
+ * @param options.isSystem if true, the url will be treated as a system url rather than a service url, this value is retained for subsequent calls
99
193
  * @param options.odataVersion if specified will restrict catalog requests to only the specified odata version
100
194
  * @returns true if the url is reachable, false if not, or an error message string
101
195
  */
@@ -106,11 +200,11 @@ export declare class ConnectionValidator {
106
200
  odataVersion?: ODataVersion;
107
201
  }): Promise<ValidationResult>;
108
202
  /**
109
- * Translate the status code into a validation result.
203
+ * Converts the http status code into 'validty' and returns true if the status code indicates that the URL was reachable.
110
204
  * Sets the instance validity state based on the status code.
111
205
  *
112
206
  * @param status a http request status code used to determine the validation result
113
- * @returns true if the url is reachable, false if not, or an error message string
207
+ * @returns true, if the status code indicates the url is reachable, false if not, or an error message string
114
208
  */
115
209
  private getValidationResultFromStatusCode;
116
210
  /**
@@ -131,14 +225,14 @@ export declare class ConnectionValidator {
131
225
  * Check whether basic auth is required for the given url, or for the previously validated url if none specified.
132
226
  * This will also set the validity state for the url. This will not validate the URL.
133
227
  *
134
- * @param urlString - the url to validate, if not provided the previously validated url will be used
135
- * @param client - optional, sap client code, if not provided the previously validated client will be used
136
- * @param ignoreCertError
228
+ * @param urlString the url to validate, if not provided the previously validated url will be used
229
+ * @param client optional, sap client code, if not provided the previously validated client will be used
230
+ * @param ignoreCertError ignore some certificate errors
137
231
  * @returns true if basic auth is required, false if not
138
232
  */
139
- isAuthRequired(urlString?: string | undefined, client?: string | undefined, ignoreCertError?: boolean): Promise<boolean>;
233
+ isAuthRequired(urlString?: string | undefined, client?: string | undefined, ignoreCertError?: boolean): Promise<boolean | undefined>;
140
234
  /**
141
- * Test the connectivity with the specified service url using the provided credentials.
235
+ * Test the connectivity with the specified service url using the provided credentials (basic authentication).
142
236
  *
143
237
  * @param url the url to validate
144
238
  * @param username user name
@@ -150,11 +244,11 @@ export declare class ConnectionValidator {
150
244
  * @param options.odataVersion if specified will restrict catalog requests to only the specified odata version
151
245
  * @returns true if the authentication is successful, false if not, or an error message string
152
246
  */
153
- validateAuth(url: string, username: string, password: string, { ignoreCertError, isSystem, sapClient, odataVersion }?: {
247
+ validateAuth(url: string, username: string, password: string, { ignoreCertError, sapClient, odataVersion, isSystem }?: {
154
248
  ignoreCertError?: boolean;
155
- isSystem?: boolean;
156
249
  odataVersion?: ODataVersion;
157
250
  sapClient?: string;
251
+ isSystem?: boolean;
158
252
  }): Promise<ValidationResult>;
159
253
  /**
160
254
  * Reset the validity state.