@sap-ux/odata-service-inquirer 0.5.60 → 0.6.1

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 (50) hide show
  1. package/dist/i18n.js +15 -3
  2. package/dist/index.d.ts +3 -3
  3. package/dist/index.js +10 -9
  4. package/dist/prompts/connectionValidator.d.ts +63 -12
  5. package/dist/prompts/connectionValidator.js +208 -50
  6. package/dist/prompts/datasources/cap-project/questions.js +2 -1
  7. package/dist/prompts/datasources/sap-system/abap-on-btp/questions.d.ts +3 -2
  8. package/dist/prompts/datasources/sap-system/abap-on-btp/questions.js +10 -10
  9. package/dist/prompts/datasources/sap-system/abap-on-prem/questions.d.ts +9 -11
  10. package/dist/prompts/datasources/sap-system/abap-on-prem/questions.js +21 -55
  11. package/dist/prompts/datasources/sap-system/credentials/questions.d.ts +21 -0
  12. package/dist/prompts/datasources/sap-system/credentials/questions.js +123 -0
  13. package/dist/prompts/datasources/sap-system/new-system/questions.d.ts +4 -26
  14. package/dist/prompts/datasources/sap-system/new-system/questions.js +18 -168
  15. package/dist/prompts/datasources/sap-system/new-system/types.d.ts +0 -10
  16. package/dist/prompts/datasources/sap-system/service-selection/index.d.ts +3 -0
  17. package/dist/prompts/datasources/sap-system/service-selection/index.js +19 -0
  18. package/dist/prompts/datasources/sap-system/service-selection/questions.d.ts +15 -0
  19. package/dist/prompts/datasources/sap-system/service-selection/questions.js +146 -0
  20. package/dist/prompts/datasources/sap-system/service-selection/service-helper.d.ts +71 -0
  21. package/dist/prompts/datasources/sap-system/service-selection/service-helper.js +282 -0
  22. package/dist/prompts/datasources/sap-system/service-selection/types.d.ts +11 -0
  23. package/dist/prompts/datasources/sap-system/service-selection/types.js +3 -0
  24. package/dist/prompts/datasources/sap-system/system-selection/index.d.ts +2 -0
  25. package/dist/prompts/datasources/sap-system/system-selection/index.js +18 -0
  26. package/dist/prompts/datasources/sap-system/system-selection/prompt-helpers.d.ts +44 -0
  27. package/dist/prompts/datasources/sap-system/system-selection/prompt-helpers.js +190 -0
  28. package/dist/prompts/datasources/sap-system/system-selection/questions.d.ts +40 -0
  29. package/dist/prompts/datasources/sap-system/system-selection/questions.js +182 -0
  30. package/dist/prompts/datasources/sap-system/validators.d.ts +8 -0
  31. package/dist/prompts/datasources/sap-system/validators.js +17 -0
  32. package/dist/prompts/datasources/service-url/questions.js +4 -3
  33. package/dist/prompts/datasources/service-url/validators.js +8 -9
  34. package/dist/prompts/prompt-helpers.d.ts +2 -3
  35. package/dist/prompts/prompt-helpers.js +4 -13
  36. package/dist/prompts/prompts.js +5 -34
  37. package/dist/prompts/validators.d.ts +1 -1
  38. package/dist/prompts/validators.js +1 -1
  39. package/dist/translations/odata-service-inquirer.i18n.json +25 -37
  40. package/dist/types.d.ts +57 -45
  41. package/dist/types.js +7 -41
  42. package/dist/utils/index.d.ts +5 -18
  43. package/dist/utils/index.js +10 -55
  44. package/package.json +10 -9
  45. package/dist/error-handler/error-handler.d.ts +0 -184
  46. package/dist/error-handler/error-handler.js +0 -465
  47. package/dist/prompts/datasources/sap-system/abap-on-btp/cf-helper.d.ts +0 -9
  48. package/dist/prompts/datasources/sap-system/abap-on-btp/cf-helper.js +0 -54
  49. package/dist/prompts/datasources/sap-system/new-system/service-helper.d.ts +0 -43
  50. package/dist/prompts/datasources/sap-system/new-system/service-helper.js +0 -175
@@ -1,184 +0,0 @@
1
- import { type Logger } from '@sap-ux/logger';
2
- import { ValidationLink } from '../types';
3
- /**
4
- * Constants specific to error handling
5
- */
6
- export declare enum ERROR_TYPE {
7
- AUTH = "AUTH",
8
- AUTH_TIMEOUT = "AUTH_TIMEOUT",
9
- REDIRECT = "REDIRECT",
10
- CERT = "CERT",// General cert error
11
- CERT_SELF_SIGNED = "CERT_SELF_SIGNED",
12
- CERT_UKNOWN_OR_INVALID = "CERT_UKNOWN_OR_INVALID",
13
- CERT_EXPIRED = "CERT_EXPIRED",
14
- CERT_SELF_SIGNED_CERT_IN_CHAIN = "CERT_SELF_SIGNED_CERT_IN_CHAIN",
15
- UNKNOWN = "UNKNOWN",
16
- INVALID_URL = "INVALID_URL",
17
- TIMEOUT = "TIMEOUT",
18
- CONNECTION = "CONNECTION",
19
- SERVICES_UNAVAILABLE = "SERVICES_UNAVAILABLE",// All services
20
- SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE",// Specific service
21
- NO_ABAP_ENVS = "NO_ABAP_ENVS",
22
- CATALOG_SERVICE_NOT_ACTIVE = "CATALOG_SERVICE_NOT_ACTIVE",
23
- NO_SUCH_HOST = "NO_SUCH_HOST",
24
- NOT_FOUND = "NOT_FOUND",
25
- ODATA_URL_NOT_FOUND = "ODATA_URL_NOT_FOUND",
26
- BAD_GATEWAY = "BAD_GATEWAY",// Can be caused by either local issue or endpoint configuration
27
- INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR",
28
- DESTINATION_BAD_GATEWAY_503 = "DESTINATION_BAD_GATEWAY_503",// Caused by endpoint using a firewall or proxy
29
- DESTINATION_UNAVAILABLE = "DESTINATION_UNAVAILABLE",
30
- DESTINATION_NOT_FOUND = "DESTINATION_NOT_FOUND",
31
- DESTINATION_MISCONFIGURED = "DESTINATION_MISCONFIGURED",
32
- NO_V2_SERVICES = "NO_V2_SERVICES",
33
- NO_V4_SERVICES = "NO_V4_SERVICES"
34
- }
35
- export declare const ERROR_MAP: Record<ERROR_TYPE, RegExp[]>;
36
- type ValidationLinkOrString = string | ValidationLink;
37
- /**
38
- * Maps errors to end-user messages using some basic root cause analysis based on regex matching.
39
- * This class will also log errors and provide help links for validation errors in some limited use cases.
40
- */
41
- export declare class ErrorHandler {
42
- /** The last error message generated */
43
- private currentErrorMsg;
44
- /** The last error message type generated if determined */
45
- private currentErrorType;
46
- private static _guidedAnswersEnabled;
47
- private static _logger;
48
- private static readonly _errorMsg;
49
- /**
50
- * Get the Guided Answers (help) node for the specified error type.
51
- *
52
- * @param errorType The error type for which a help node (help content id) may be returned
53
- * @returns The Guided Answers node for the specified error type
54
- */
55
- private static readonly getHelpNode;
56
- /**
57
- * Find an error property for mapping to a general error type from most to least significant.
58
- *
59
- * @param error any type of error or object that has an error code, status, name or message
60
- * @returns a value that can be used to look up a general error type
61
- */
62
- private static findErrorValueForMapping;
63
- /**
64
- * Create an instance of the ErrorHandler.
65
- *
66
- * @param logger the logger instance to use
67
- * @param enableGuidedAnswers if true, the end user validation errors will include guided answers to provide help
68
- */
69
- constructor(logger?: Logger, enableGuidedAnswers?: boolean);
70
- /**
71
- * Get Guided Answers (context help) enabled value.
72
- *
73
- * @returns true if Guided Answers is enabled
74
- */
75
- static get guidedAnswersEnabled(): boolean;
76
- /**
77
- * Toggle Guided Answers (context help) for validation errors.
78
- */
79
- static set guidedAnswersEnabled(value: boolean);
80
- /**
81
- * Set the logger to be used for error messages.
82
- *
83
- * @param logger the logger instance to use
84
- */
85
- static set logger(logger: Logger);
86
- /**
87
- * Get the logger used for error messages.
88
- *
89
- * @returns the logger instance
90
- */
91
- static get logger(): Logger;
92
- /**
93
- * Tests if the error is a general certificate error.
94
- *
95
- * @param status the error type
96
- * @returns true if the error is a general certificate error
97
- */
98
- static isCertError(status: string | number): boolean;
99
- /**
100
- * Get the error type for the specified error, mapping status code, error code, error name, error message to a few general error types.
101
- *
102
- * @param error the error, string or status code to get the type for
103
- * @returns the error type
104
- */
105
- static getErrorType(error: string | number | Error): ERROR_TYPE;
106
- /**
107
- * Maps errors to a few generic types, log a detailed error.
108
- *
109
- * @param error If the error is a string this will be logged as is. Otherwise it will be mapped to a general error internally, possibly retained and logged.
110
- * @param userMsg If provided this will be set as the userErrorMsg instead of an error to msg map
111
- * this allows a message more relevant to the context of where the error was generated to be used.
112
- * @param retainError Defaults to true to retain the error state.
113
- * @returns A user-friendly message for display in-line
114
- */
115
- logErrorMsgs(error: unknown, userMsg?: string, retainError?: boolean): string;
116
- /**
117
- * Maps an error to a user-friendly message. The specified error may by a string (e.g. error message), number (e.g. status code), Error, or Axios error.
118
- *
119
- * @param error The error to map
120
- * @returns The mapped error message and error type
121
- */
122
- private static mapErrorToMsg;
123
- /**
124
- * Used by validate functions to report in-line user friendly errors.
125
- * Checks if there is an existing error.
126
- *
127
- * @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`.
128
- * @param reset optional, resets the previous error state if true, if error is omitted reset may be passed as the first argument
129
- * @param fallback optional, return the message of the specified ERROR_TYPE if no previous end user message and no error specified
130
- * @returns The error message
131
- */
132
- getErrorMsg(error?: any, reset?: boolean, fallback?: ERROR_TYPE): string | undefined;
133
- /**
134
- * Used by validate functions to report in-line user friendly errors messages with help links.
135
- * If the error type is unknown, this will find a mapped error type and return the help (ValidationLink) if it exists.
136
- * If an error is not provided the current error state will be used. This does not log the message to the console.
137
- *
138
- * @param error optional, if provided get the help link message that it maps to, otherwise get the previously logged error message help link
139
- * @param reset optional, resets the previous error state if true
140
- * @returns An instance of @see {ValidationLink}
141
- */
142
- getValidationErrorHelp(error?: any, reset?: boolean): ValidationLinkOrString | undefined;
143
- /**
144
- * Get the error message for the specified error type.
145
- *
146
- * @param errorType The error type for which the message may be returned
147
- * @param error optional, if provided may be used to get generate a more specific error message, or be included in the message
148
- * @returns The error message for the specified error type
149
- */
150
- static getErrorMsgFromType(errorType: ERROR_TYPE, error?: any): string | undefined;
151
- /**
152
- * Checks if there is an existing error.
153
- *
154
- * @param reset - resets the current error state
155
- * @returns true if there is an existing error
156
- */
157
- hasError(reset?: boolean): boolean;
158
- /**
159
- * Sets the current error state.
160
- *
161
- * @param errorType - the error type
162
- * @param error - the original error, if any
163
- */
164
- setCurrentError(errorType: ERROR_TYPE, error?: any): void;
165
- /**
166
- * Gets the current error type state.
167
- *
168
- * @param reset - resets the current error state
169
- * @returns The current error type
170
- */
171
- getCurrentErrorType(reset?: boolean): ERROR_TYPE | null;
172
- /**
173
- * Maps an error type to a validation link if help (Guided Answers topic) is available for the specified error.
174
- * Otherwise the specified error message is returned. To retrieve the previous error state @see getValidationErrorHelp.
175
- * Use this (getHelpForError) if the error type is known.
176
- *
177
- * @param errorType - the error type to be mapped to help link
178
- * @param errorMsg - the message to appear with the help link
179
- * @returns A validation help link or help link message
180
- */
181
- static getHelpForError(errorType: ERROR_TYPE, errorMsg?: string): ValidationLinkOrString | undefined;
182
- }
183
- export {};
184
- //# sourceMappingURL=error-handler.d.ts.map
@@ -1,465 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ErrorHandler = exports.ERROR_MAP = exports.ERROR_TYPE = void 0;
4
- const btp_utils_1 = require("@sap-ux/btp-utils");
5
- const logger_1 = require("@sap-ux/logger");
6
- const i18n_1 = require("../i18n");
7
- const types_1 = require("../types");
8
- const utils_1 = require("../utils");
9
- const guided_answers_helper_1 = require("@sap-ux/guided-answers-helper");
10
- const teleEventGALinkCreated = 'GA_LINK_CREATED';
11
- /**
12
- * Constants specific to error handling
13
- */
14
- var ERROR_TYPE;
15
- (function (ERROR_TYPE) {
16
- ERROR_TYPE["AUTH"] = "AUTH";
17
- ERROR_TYPE["AUTH_TIMEOUT"] = "AUTH_TIMEOUT";
18
- ERROR_TYPE["REDIRECT"] = "REDIRECT";
19
- ERROR_TYPE["CERT"] = "CERT";
20
- ERROR_TYPE["CERT_SELF_SIGNED"] = "CERT_SELF_SIGNED";
21
- ERROR_TYPE["CERT_UKNOWN_OR_INVALID"] = "CERT_UKNOWN_OR_INVALID";
22
- ERROR_TYPE["CERT_EXPIRED"] = "CERT_EXPIRED";
23
- ERROR_TYPE["CERT_SELF_SIGNED_CERT_IN_CHAIN"] = "CERT_SELF_SIGNED_CERT_IN_CHAIN";
24
- ERROR_TYPE["UNKNOWN"] = "UNKNOWN";
25
- ERROR_TYPE["INVALID_URL"] = "INVALID_URL";
26
- ERROR_TYPE["TIMEOUT"] = "TIMEOUT";
27
- ERROR_TYPE["CONNECTION"] = "CONNECTION";
28
- ERROR_TYPE["SERVICES_UNAVAILABLE"] = "SERVICES_UNAVAILABLE";
29
- ERROR_TYPE["SERVICE_UNAVAILABLE"] = "SERVICE_UNAVAILABLE";
30
- ERROR_TYPE["NO_ABAP_ENVS"] = "NO_ABAP_ENVS";
31
- ERROR_TYPE["CATALOG_SERVICE_NOT_ACTIVE"] = "CATALOG_SERVICE_NOT_ACTIVE";
32
- ERROR_TYPE["NO_SUCH_HOST"] = "NO_SUCH_HOST";
33
- ERROR_TYPE["NOT_FOUND"] = "NOT_FOUND";
34
- ERROR_TYPE["ODATA_URL_NOT_FOUND"] = "ODATA_URL_NOT_FOUND";
35
- ERROR_TYPE["BAD_GATEWAY"] = "BAD_GATEWAY";
36
- ERROR_TYPE["INTERNAL_SERVER_ERROR"] = "INTERNAL_SERVER_ERROR";
37
- ERROR_TYPE["DESTINATION_BAD_GATEWAY_503"] = "DESTINATION_BAD_GATEWAY_503";
38
- ERROR_TYPE["DESTINATION_UNAVAILABLE"] = "DESTINATION_UNAVAILABLE";
39
- ERROR_TYPE["DESTINATION_NOT_FOUND"] = "DESTINATION_NOT_FOUND";
40
- ERROR_TYPE["DESTINATION_MISCONFIGURED"] = "DESTINATION_MISCONFIGURED";
41
- ERROR_TYPE["NO_V2_SERVICES"] = "NO_V2_SERVICES";
42
- ERROR_TYPE["NO_V4_SERVICES"] = "NO_V4_SERVICES";
43
- })(ERROR_TYPE || (exports.ERROR_TYPE = ERROR_TYPE = {}));
44
- // Used to match regex expressions to error messages, etc. providing a way to return a consistent
45
- // single error and error msg for multiple errors
46
- exports.ERROR_MAP = {
47
- [ERROR_TYPE.AUTH]: [
48
- /401/,
49
- /403/,
50
- /Incorrect credentials were provided to login/, // API Hub error msg
51
- /Unable to retrieve SAP Business Accelerator Hub key/ // API Hub error msg
52
- ],
53
- [ERROR_TYPE.AUTH_TIMEOUT]: [/UAATimeoutError/],
54
- [ERROR_TYPE.TIMEOUT]: [/Timeout/],
55
- [ERROR_TYPE.CERT]: [], // General cert error, unspecified root cause
56
- [ERROR_TYPE.CERT_UKNOWN_OR_INVALID]: [
57
- /UNABLE_TO_GET_ISSUER_CERT/,
58
- /UNABLE_TO_GET_ISSUER_CERT_LOCALLY/,
59
- /unable to get local issuer certificate/
60
- ],
61
- [ERROR_TYPE.CERT_EXPIRED]: [/CERT_HAS_EXPIRED/],
62
- [ERROR_TYPE.CERT_SELF_SIGNED]: [/DEPTH_ZERO_SELF_SIGNED_CERT/],
63
- [ERROR_TYPE.CERT_SELF_SIGNED_CERT_IN_CHAIN]: [/SELF_SIGNED_CERT_IN_CHAIN/],
64
- [ERROR_TYPE.UNKNOWN]: [],
65
- [ERROR_TYPE.CONNECTION]: [/ENOTFOUND/, /ECONNRESET/, /ECONNREFUSED/, /ConnectionError/],
66
- [ERROR_TYPE.SERVICES_UNAVAILABLE]: [],
67
- [ERROR_TYPE.SERVICE_UNAVAILABLE]: [/503/],
68
- [ERROR_TYPE.INVALID_URL]: [/Invalid URL/, /ERR_INVALID_URL/],
69
- [ERROR_TYPE.REDIRECT]: [/3[\d][\d]/],
70
- [ERROR_TYPE.NO_ABAP_ENVS]: [],
71
- [ERROR_TYPE.CATALOG_SERVICE_NOT_ACTIVE]: [
72
- /\/IWBEP\/CM_V4_COS\/014/,
73
- /\/IWFND\/CM_V4_COS\/021/,
74
- /Service group '\/IWFND\/CONFIG' not published/
75
- ],
76
- [ERROR_TYPE.NO_SUCH_HOST]: [/no such host/],
77
- [ERROR_TYPE.NOT_FOUND]: [/404/],
78
- [ERROR_TYPE.ODATA_URL_NOT_FOUND]: [],
79
- [ERROR_TYPE.INTERNAL_SERVER_ERROR]: [/500/],
80
- [ERROR_TYPE.BAD_GATEWAY]: [/502/],
81
- [ERROR_TYPE.DESTINATION_BAD_GATEWAY_503]: [],
82
- [ERROR_TYPE.DESTINATION_UNAVAILABLE]: [],
83
- [ERROR_TYPE.DESTINATION_NOT_FOUND]: [],
84
- [ERROR_TYPE.DESTINATION_MISCONFIGURED]: [],
85
- [ERROR_TYPE.NO_V2_SERVICES]: [],
86
- [ERROR_TYPE.NO_V4_SERVICES]: []
87
- };
88
- /**
89
- * Maps errors to end-user messages using some basic root cause analysis based on regex matching.
90
- * This class will also log errors and provide help links for validation errors in some limited use cases.
91
- */
92
- class ErrorHandler {
93
- /** The last error message generated */
94
- currentErrorMsg;
95
- /** The last error message type generated if determined */
96
- currentErrorType;
97
- static _guidedAnswersEnabled;
98
- static _logger;
99
- // Get the required localized parameterized error message
100
- // Note that these are general fallback end-user error messages.
101
- // More specific error messages can be used at the point of error generation.
102
- static _errorMsg = (error) => ({
103
- [ERROR_TYPE.CERT]: (0, i18n_1.t)('errors.certificateError', { error }),
104
- [ERROR_TYPE.CERT_EXPIRED]: (0, i18n_1.t)('errors.urlCertValidationError', { certErrorReason: (0, i18n_1.t)('texts.anExpiredCert') }),
105
- [ERROR_TYPE.CERT_SELF_SIGNED]: (0, i18n_1.t)('errors.urlCertValidationError', {
106
- certErrorReason: (0, i18n_1.t)('texts.aSelfSignedCert')
107
- }),
108
- [ERROR_TYPE.CERT_UKNOWN_OR_INVALID]: (0, i18n_1.t)('errors.urlCertValidationError', {
109
- certErrorReason: (0, i18n_1.t)('texts.anUnknownOrInvalidCert')
110
- }),
111
- [ERROR_TYPE.CERT_SELF_SIGNED_CERT_IN_CHAIN]: (0, i18n_1.t)('errors.urlCertValidationError', {
112
- certErrorReason: (0, i18n_1.t)('texts.anUntrustedRootCert')
113
- }),
114
- [ERROR_TYPE.AUTH]: (0, i18n_1.t)('errors.authenticationFailed', { error }),
115
- [ERROR_TYPE.AUTH_TIMEOUT]: (0, i18n_1.t)('errors.authenticationTimeout'),
116
- [ERROR_TYPE.TIMEOUT]: (0, i18n_1.t)('errors.timeout, { error }'),
117
- [ERROR_TYPE.INVALID_URL]: (0, i18n_1.t)('errors.invalidUrl'),
118
- [ERROR_TYPE.CONNECTION]: (0, i18n_1.t)('errors.connectionError', {
119
- error: error?.message || JSON.stringify(error)
120
- }),
121
- [ERROR_TYPE.UNKNOWN]: (0, i18n_1.t)('errors.unknownError', {
122
- error: error?.message || JSON.stringify(error)
123
- }),
124
- [ERROR_TYPE.SERVICES_UNAVAILABLE]: (0, i18n_1.t)('errors.servicesUnavailable'),
125
- [ERROR_TYPE.SERVICE_UNAVAILABLE]: (0, i18n_1.t)('errors.serviceUnavailable'),
126
- [ERROR_TYPE.CATALOG_SERVICE_NOT_ACTIVE]: (0, i18n_1.t)('errors.catalogServiceNotActive'),
127
- [ERROR_TYPE.INTERNAL_SERVER_ERROR]: (0, i18n_1.t)('errors.internalServerError', { error: error?.message }),
128
- [ERROR_TYPE.NOT_FOUND]: (0, i18n_1.t)('errors.urlNotFound'),
129
- [ERROR_TYPE.ODATA_URL_NOT_FOUND]: (0, i18n_1.t)('errors.odataServiceUrlNotFound'),
130
- [ERROR_TYPE.BAD_GATEWAY]: (0, i18n_1.t)('errors.badGateway'),
131
- [ERROR_TYPE.DESTINATION_UNAVAILABLE]: (0, i18n_1.t)('errors.destinationUnavailable'),
132
- [ERROR_TYPE.DESTINATION_NOT_FOUND]: (0, i18n_1.t)('errors.destinationNotFound'),
133
- [ERROR_TYPE.DESTINATION_MISCONFIGURED]: (0, i18n_1.t)('errors.destinationMisconfigured'),
134
- [ERROR_TYPE.NO_V2_SERVICES]: (0, i18n_1.t)('errors.noServicesAvailable', { version: '2' }),
135
- [ERROR_TYPE.NO_V4_SERVICES]: (0, i18n_1.t)('errors.noServicesAvailable', { version: '4' }),
136
- [ERROR_TYPE.DESTINATION_BAD_GATEWAY_503]: (0, i18n_1.t)('errors.destinationUnavailable'),
137
- [ERROR_TYPE.REDIRECT]: (0, i18n_1.t)('errors.redirectError'),
138
- [ERROR_TYPE.NO_SUCH_HOST]: (0, i18n_1.t)('errors.noSuchHostError'),
139
- [ERROR_TYPE.NO_ABAP_ENVS]: (0, i18n_1.t)('errors.abapEnvsUnavailable')
140
- });
141
- /**
142
- * Get the Guided Answers (help) node for the specified error type.
143
- *
144
- * @param errorType The error type for which a help node (help content id) may be returned
145
- * @returns The Guided Answers node for the specified error type
146
- */
147
- static getHelpNode = (errorType) => {
148
- const errorToHelp = {
149
- [ERROR_TYPE.SERVICES_UNAVAILABLE]: (0, btp_utils_1.isAppStudio)()
150
- ? guided_answers_helper_1.HELP_NODES.BAS_CATALOG_SERVICES_REQUEST_FAILED
151
- : undefined,
152
- [ERROR_TYPE.CERT]: guided_answers_helper_1.HELP_NODES.CERTIFICATE_ERROR,
153
- [ERROR_TYPE.CERT_SELF_SIGNED]: guided_answers_helper_1.HELP_NODES.CERTIFICATE_ERROR,
154
- [ERROR_TYPE.CERT_UKNOWN_OR_INVALID]: guided_answers_helper_1.HELP_NODES.CERTIFICATE_ERROR,
155
- [ERROR_TYPE.CERT_SELF_SIGNED_CERT_IN_CHAIN]: guided_answers_helper_1.HELP_NODES.CERTIFICATE_ERROR,
156
- [ERROR_TYPE.DESTINATION_MISCONFIGURED]: guided_answers_helper_1.HELP_NODES.DESTINATION_MISCONFIGURED,
157
- [ERROR_TYPE.DESTINATION_UNAVAILABLE]: guided_answers_helper_1.HELP_NODES.DESTINATION_UNAVAILABLE,
158
- [ERROR_TYPE.DESTINATION_NOT_FOUND]: guided_answers_helper_1.HELP_NODES.DESTINATION_NOT_FOUND,
159
- [ERROR_TYPE.BAD_GATEWAY]: guided_answers_helper_1.HELP_NODES.BAD_GATEWAY,
160
- [ERROR_TYPE.DESTINATION_BAD_GATEWAY_503]: guided_answers_helper_1.HELP_NODES.DESTINATION_BAD_GATEWAY_503,
161
- [ERROR_TYPE.NO_V4_SERVICES]: guided_answers_helper_1.HELP_NODES.NO_V4_SERVICES,
162
- [ERROR_TYPE.AUTH]: undefined,
163
- [ERROR_TYPE.AUTH_TIMEOUT]: undefined,
164
- [ERROR_TYPE.REDIRECT]: undefined,
165
- [ERROR_TYPE.CERT_EXPIRED]: undefined,
166
- [ERROR_TYPE.UNKNOWN]: undefined,
167
- [ERROR_TYPE.INVALID_URL]: undefined,
168
- [ERROR_TYPE.CONNECTION]: undefined,
169
- [ERROR_TYPE.SERVICE_UNAVAILABLE]: undefined,
170
- [ERROR_TYPE.NO_ABAP_ENVS]: undefined,
171
- [ERROR_TYPE.CATALOG_SERVICE_NOT_ACTIVE]: undefined,
172
- [ERROR_TYPE.NO_SUCH_HOST]: undefined,
173
- [ERROR_TYPE.NOT_FOUND]: undefined,
174
- [ERROR_TYPE.ODATA_URL_NOT_FOUND]: undefined,
175
- [ERROR_TYPE.INTERNAL_SERVER_ERROR]: undefined,
176
- [ERROR_TYPE.NO_V2_SERVICES]: undefined,
177
- [ERROR_TYPE.TIMEOUT]: undefined
178
- };
179
- return errorToHelp[errorType];
180
- };
181
- /**
182
- * Find an error property for mapping to a general error type from most to least significant.
183
- *
184
- * @param error any type of error or object that has an error code, status, name or message
185
- * @returns a value that can be used to look up a general error type
186
- */
187
- static findErrorValueForMapping = (error) => error.response?.data?.error?.code ||
188
- error.response?.status ||
189
- error.response?.data ||
190
- error.code ||
191
- (['TypeError', 'Error'].includes(error.name) ? error.message : error.name) || // For generic error types use the message otherwise the name is more relevant
192
- error.message ||
193
- error;
194
- /**
195
- * Create an instance of the ErrorHandler.
196
- *
197
- * @param logger the logger instance to use
198
- * @param enableGuidedAnswers if true, the end user validation errors will include guided answers to provide help
199
- */
200
- constructor(logger, enableGuidedAnswers = false) {
201
- ErrorHandler._logger = logger ?? new logger_1.ToolsLogger({ logPrefix: '@sap-ux/odata-service-inquirer' });
202
- ErrorHandler.guidedAnswersEnabled = enableGuidedAnswers;
203
- }
204
- /**
205
- * Get Guided Answers (context help) enabled value.
206
- *
207
- * @returns true if Guided Answers is enabled
208
- */
209
- static get guidedAnswersEnabled() {
210
- return ErrorHandler._guidedAnswersEnabled;
211
- }
212
- /**
213
- * Toggle Guided Answers (context help) for validation errors.
214
- */
215
- static set guidedAnswersEnabled(value) {
216
- ErrorHandler._guidedAnswersEnabled = value;
217
- }
218
- /**
219
- * Set the logger to be used for error messages.
220
- *
221
- * @param logger the logger instance to use
222
- */
223
- static set logger(logger) {
224
- ErrorHandler._logger = logger;
225
- }
226
- /**
227
- * Get the logger used for error messages.
228
- *
229
- * @returns the logger instance
230
- */
231
- static get logger() {
232
- return ErrorHandler._logger;
233
- }
234
- /**
235
- * Tests if the error is a general certificate error.
236
- *
237
- * @param status the error type
238
- * @returns true if the error is a general certificate error
239
- */
240
- static isCertError(status) {
241
- return [
242
- ERROR_TYPE.CERT,
243
- ERROR_TYPE.CERT_EXPIRED,
244
- ERROR_TYPE.CERT_SELF_SIGNED,
245
- ERROR_TYPE.CERT_UKNOWN_OR_INVALID,
246
- ERROR_TYPE.CERT_SELF_SIGNED_CERT_IN_CHAIN
247
- ].includes(ErrorHandler.getErrorType(status));
248
- }
249
- /**
250
- * Get the error type for the specified error, mapping status code, error code, error name, error message to a few general error types.
251
- *
252
- * @param error the error, string or status code to get the type for
253
- * @returns the error type
254
- */
255
- static getErrorType(error) {
256
- let errorValueToFind = error;
257
- if (error instanceof Error) {
258
- errorValueToFind = ErrorHandler.findErrorValueForMapping(error);
259
- }
260
- return Object.keys(ERROR_TYPE).find((errorCodeType) => {
261
- return exports.ERROR_MAP[errorCodeType].find((exp) => exp.test(errorValueToFind.toString()));
262
- }, {});
263
- }
264
- /**
265
- * Maps errors to a few generic types, log a detailed error.
266
- *
267
- * @param error If the error is a string this will be logged as is. Otherwise it will be mapped to a general error internally, possibly retained and logged.
268
- * @param userMsg If provided this will be set as the userErrorMsg instead of an error to msg map
269
- * this allows a message more relevant to the context of where the error was generated to be used.
270
- * @param retainError Defaults to true to retain the error state.
271
- * @returns A user-friendly message for display in-line
272
- */
273
- logErrorMsgs(error, userMsg, retainError = true) {
274
- let resolvedError = {
275
- errorMsg: '',
276
- errorType: ERROR_TYPE.UNKNOWN
277
- };
278
- // Overloaded to allow ERROR_TYPE for convenience
279
- if (Object.values(ERROR_TYPE).includes(error)) {
280
- const errorType = error;
281
- resolvedError.errorMsg = ErrorHandler.getErrorMsgFromType(errorType) ?? errorType.toString();
282
- resolvedError.errorType = errorType;
283
- }
284
- else if (typeof error === 'string') {
285
- resolvedError.errorMsg = error;
286
- }
287
- else {
288
- resolvedError = ErrorHandler.mapErrorToMsg(error);
289
- }
290
- ErrorHandler._logger.error(userMsg ? `${userMsg} ${resolvedError.errorMsg}` : resolvedError.errorMsg);
291
- if (retainError) {
292
- this.currentErrorMsg = userMsg ?? resolvedError.errorMsg;
293
- this.currentErrorType = resolvedError.errorType;
294
- }
295
- return resolvedError.errorMsg;
296
- }
297
- /**
298
- * Maps an error to a user-friendly message. The specified error may by a string (e.g. error message), number (e.g. status code), Error, or Axios error.
299
- *
300
- * @param error The error to map
301
- * @returns The mapped error message and error type
302
- */
303
- static mapErrorToMsg(error) {
304
- let errorType;
305
- if (Object.values(ERROR_TYPE).includes(error)) {
306
- errorType = error;
307
- }
308
- else {
309
- // Map error type using more to less specific information if available
310
- errorType = ErrorHandler.getErrorType(this.findErrorValueForMapping(error)) ?? ERROR_TYPE.UNKNOWN;
311
- }
312
- return {
313
- errorMsg: ErrorHandler._errorMsg(error)[errorType],
314
- errorType
315
- };
316
- }
317
- /**
318
- * Used by validate functions to report in-line user friendly errors.
319
- * Checks if there is an existing error.
320
- *
321
- * @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`.
322
- * @param reset optional, resets the previous error state if true, if error is omitted reset may be passed as the first argument
323
- * @param fallback optional, return the message of the specified ERROR_TYPE if no previous end user message and no error specified
324
- * @returns The error message
325
- */
326
- getErrorMsg(error, reset, fallback) {
327
- let errorMsg;
328
- if (error && typeof error !== 'boolean') {
329
- errorMsg = ErrorHandler.mapErrorToMsg(error).errorMsg;
330
- }
331
- // Get previous error message
332
- if (!errorMsg) {
333
- errorMsg = this.currentErrorMsg ?? (fallback ? ErrorHandler.getErrorMsgFromType(fallback) : undefined);
334
- }
335
- if (error === true || reset) {
336
- this.currentErrorMsg = null;
337
- this.currentErrorType = null;
338
- }
339
- return errorMsg;
340
- }
341
- /**
342
- * Used by validate functions to report in-line user friendly errors messages with help links.
343
- * If the error type is unknown, this will find a mapped error type and return the help (ValidationLink) if it exists.
344
- * If an error is not provided the current error state will be used. This does not log the message to the console.
345
- *
346
- * @param error optional, if provided get the help link message that it maps to, otherwise get the previously logged error message help link
347
- * @param reset optional, resets the previous error state if true
348
- * @returns An instance of @see {ValidationLink}
349
- */
350
- getValidationErrorHelp(error, reset = false) {
351
- let errorHelp;
352
- let errorMsg;
353
- if (error) {
354
- const resolvedError = ErrorHandler.mapErrorToMsg(error);
355
- if (resolvedError.errorType !== ERROR_TYPE.UNKNOWN) {
356
- errorHelp = ErrorHandler.getHelpForError(resolvedError.errorType, resolvedError.errorMsg);
357
- }
358
- }
359
- else if (!error) {
360
- errorMsg = this.currentErrorMsg ?? '';
361
- if (this.currentErrorType) {
362
- errorHelp = ErrorHandler.getHelpForError(this.currentErrorType, errorMsg);
363
- }
364
- }
365
- if (reset) {
366
- this.currentErrorMsg = null;
367
- this.currentErrorType = null;
368
- }
369
- return errorHelp ?? errorMsg;
370
- }
371
- /**
372
- * Get the error message for the specified error type.
373
- *
374
- * @param errorType The error type for which the message may be returned
375
- * @param error optional, if provided may be used to get generate a more specific error message, or be included in the message
376
- * @returns The error message for the specified error type
377
- */
378
- static getErrorMsgFromType(errorType, error) {
379
- if (ERROR_TYPE[errorType]) {
380
- return ErrorHandler._errorMsg(error)[ERROR_TYPE[errorType]];
381
- }
382
- return undefined;
383
- }
384
- /**
385
- * Checks if there is an existing error.
386
- *
387
- * @param reset - resets the current error state
388
- * @returns true if there is an existing error
389
- */
390
- hasError(reset = false) {
391
- const hasError = !!this.currentErrorMsg;
392
- if (reset) {
393
- this.currentErrorMsg = null;
394
- this.currentErrorType = null;
395
- }
396
- return hasError;
397
- }
398
- /**
399
- * Sets the current error state.
400
- *
401
- * @param errorType - the error type
402
- * @param error - the original error, if any
403
- */
404
- setCurrentError(errorType, error) {
405
- this.currentErrorMsg = ErrorHandler._errorMsg(error)[ERROR_TYPE[errorType]];
406
- this.currentErrorType = errorType;
407
- }
408
- /**
409
- * Gets the current error type state.
410
- *
411
- * @param reset - resets the current error state
412
- * @returns The current error type
413
- */
414
- getCurrentErrorType(reset = false) {
415
- const currentErrorType = this.currentErrorType;
416
- if (reset) {
417
- this.currentErrorMsg = null;
418
- this.currentErrorType = null;
419
- }
420
- return currentErrorType;
421
- }
422
- /**
423
- * Maps an error type to a validation link if help (Guided Answers topic) is available for the specified error.
424
- * Otherwise the specified error message is returned. To retrieve the previous error state @see getValidationErrorHelp.
425
- * Use this (getHelpForError) if the error type is known.
426
- *
427
- * @param errorType - the error type to be mapped to help link
428
- * @param errorMsg - the message to appear with the help link
429
- * @returns A validation help link or help link message
430
- */
431
- static getHelpForError(errorType, errorMsg) {
432
- const helpNode = ErrorHandler.getHelpNode(errorType);
433
- const mappedErrorMsg = errorMsg ?? ErrorHandler.getErrorMsgFromType(errorType);
434
- if (helpNode) {
435
- const valLink = {
436
- message: mappedErrorMsg ?? '',
437
- link: {
438
- text: (0, i18n_1.t)('guidedAnswers.validationErrorHelpText'),
439
- icon: guided_answers_helper_1.GUIDED_ANSWERS_ICON,
440
- url: (0, guided_answers_helper_1.getHelpUrl)(guided_answers_helper_1.HELP_TREE.FIORI_TOOLS, [helpNode])
441
- }
442
- };
443
- if (this.guidedAnswersEnabled) {
444
- valLink.link.command = {
445
- id: guided_answers_helper_1.GUIDED_ANSWERS_LAUNCH_CMD_ID,
446
- params: {
447
- treeId: guided_answers_helper_1.HELP_TREE.FIORI_TOOLS,
448
- nodeIdPath: [helpNode],
449
- trigger: '@sap-ux/odata-service-inquirer'
450
- }
451
- };
452
- }
453
- // Report the GA link created event
454
- (0, utils_1.sendTelemetryEvent)(teleEventGALinkCreated, {
455
- errorType,
456
- isGuidedAnswersEnabled: this.guidedAnswersEnabled,
457
- nodeIdPath: `${helpNode}`
458
- });
459
- return new types_1.ValidationLink(valLink);
460
- }
461
- return mappedErrorMsg;
462
- }
463
- }
464
- exports.ErrorHandler = ErrorHandler;
465
- //# sourceMappingURL=error-handler.js.map
@@ -1,9 +0,0 @@
1
- import type { ServiceInstanceInfo } from '@sap/cf-tools';
2
- import type { ListChoiceOptions } from 'inquirer';
3
- /**
4
- * Get the name sorted list of ABAP instance choices from an active CF login. If not logged in, an error message is logged.
5
- *
6
- * @returns The list of ABAP instance choices
7
- */
8
- export declare function getABAPInstanceChoices(): Promise<ListChoiceOptions<ServiceInstanceInfo>[]>;
9
- //# sourceMappingURL=cf-helper.d.ts.map