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

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 (31) hide show
  1. package/dist/i18n.js +0 -3
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +9 -6
  4. package/dist/prompts/connectionValidator.d.ts +3 -2
  5. package/dist/prompts/connectionValidator.js +27 -26
  6. package/dist/prompts/datasources/cap-project/questions.js +2 -1
  7. package/dist/prompts/datasources/sap-system/abap-on-btp/questions.d.ts +1 -1
  8. package/dist/prompts/datasources/sap-system/abap-on-btp/questions.js +8 -10
  9. package/dist/prompts/datasources/sap-system/credentials/questions.d.ts +2 -2
  10. package/dist/prompts/datasources/sap-system/credentials/questions.js +2 -2
  11. package/dist/prompts/datasources/sap-system/service-selection/questions.js +4 -4
  12. package/dist/prompts/datasources/sap-system/service-selection/service-helper.d.ts +1 -1
  13. package/dist/prompts/datasources/sap-system/service-selection/service-helper.js +5 -4
  14. package/dist/prompts/datasources/sap-system/system-selection/prompt-helpers.d.ts +2 -2
  15. package/dist/prompts/datasources/sap-system/system-selection/prompt-helpers.js +7 -7
  16. package/dist/prompts/datasources/sap-system/system-selection/questions.d.ts +1 -1
  17. package/dist/prompts/datasources/sap-system/system-selection/questions.js +6 -5
  18. package/dist/prompts/datasources/service-url/questions.js +2 -1
  19. package/dist/prompts/datasources/service-url/validators.js +3 -3
  20. package/dist/prompts/prompt-helpers.d.ts +1 -1
  21. package/dist/prompts/prompt-helpers.js +2 -2
  22. package/dist/translations/odata-service-inquirer.i18n.json +4 -37
  23. package/dist/types.d.ts +0 -35
  24. package/dist/types.js +1 -41
  25. package/dist/utils/index.d.ts +3 -25
  26. package/dist/utils/index.js +5 -72
  27. package/package.json +7 -6
  28. package/dist/error-handler/error-handler.d.ts +0 -206
  29. package/dist/error-handler/error-handler.js +0 -567
  30. package/dist/prompts/datasources/sap-system/abap-on-btp/cf-helper.d.ts +0 -9
  31. package/dist/prompts/datasources/sap-system/abap-on-btp/cf-helper.js +0 -54
@@ -128,35 +128,18 @@
128
128
  },
129
129
  "errors": {
130
130
  "destination": {
131
- "unavailable": "The selected destination references an instance that is not available. Please check your destination configuration and try again.",
132
- "notFound": "The destination is misconfigured, HTTP Error 404 returned, the requested resource could not be found.",
133
- "authError": "The selected system is returning an authentication error. System name: {{systemName}}, error: {{- error}}",
134
- "notReachable": "The selected system is not reachable. System name: {{systemName}}, error: {{- error}}",
135
- "misconfigured": "The destination is misconfigured. $t(errors.destination.missingPropMsg, {\"destinationProperty\": \"{{destinationProperty}}\" })",
136
- "missingPropMsg": "The property: `{{destinationProperty}}` is missing.",
137
- "httpConnectionError": "A connection error occurred with the selected destination. Http code: {{- code}}. See log for more details."
138
- },
139
- "cannotReadCapServiceMetadata": "An error occurred reading CAP service metadata: {{serviceName}}. See log for more details.",
131
+ "authError": "The selected system is returning an authentication error. System name: {{systemName}}, error: {{- error}}"
132
+ },
133
+ "cannotReadCapServiceMetadata": "An error occurred reading CAP service metadata: {{serviceName}}. $t(texts.seeLogForDetails)",
140
134
  "capModelAndServicesLoadError": "An error occurred loading the CAP model and services. {{- error}}",
141
135
  "capServiceUrlPathNotDefined": "An error occurred reading CAP service metadata: {{serviceName}}. CAP service property `urlPath` is not defined but is required.",
142
136
  "unknownError": "An error occurred{{- error, addMsgWithColonFormatter}}",
143
- "servicesUnavailable": "An error occurred retrieving service(s) for SAP System.",
144
- "certificateError": "A certificate error has occurred: {{- error}}",
145
- "urlCertValidationError": "The system URL is using {{certErrorReason}} security certificate.",
146
137
  "authenticationFailed": "Authentication incorrect. {{error}}",
147
- "authenticationTimeout": "Authorization was not verified within the allowed time. Please ensure you have authenticated using the associated browser window.",
148
138
  "invalidUrl": "Invalid URL{{-input, addMsgWithColonFormatter}}",
149
139
  "connectionError": "A connection error occurred, please ensure the target host is available on the network: {{- error}}",
150
- "timeout": "A connection timeout error occurred: {{- error}}",
151
- "serverReturnedAnError": "The server returned an error. {{errorDesc}}",
152
- "serverUnableToCompleteRequest": "The server was unable to complete the request",
153
- "catalogServiceNotActive": "Catalog service is not active",
154
140
  "urlNotFound": "URL not found",
155
- "odataServiceUrlNotFound": "The service URL you have provided is not a valid OData Service. Fiori applications require an OData service as the data source.",
156
141
  "noServicesAvailable": "There are no V{{version}} OData services available from the selected system and the template you have chosen supports V{{version}} OData services only",
157
- "redirectError": "A redirect response was received from the server",
158
142
  "abapEnvsUnavailable": "ABAP environments unavailable",
159
- "noSuchHostError": "No such host is known",
160
143
  "systemOrServiceUrlNotFound": "Please verify the url: {{- url}}, target system configuration and network connectivity",
161
144
  "urlRedirect": "The service URL is redirecting",
162
145
  "certValidationRequired": "Certificate validation is required to continue.",
@@ -165,34 +148,18 @@
165
148
  "serviceMetadataErrorUI": "$t(errors.serviceMetadataError, {\"servicePath\": \"{{- servicePath}}\" }). $t(texts.seeLogForDetails)",
166
149
  "serviceMetadataErrorLog": "$t(errors.serviceMetadataError, {\"servicePath\": \"{{- servicePath}}\" }). {{error}}",
167
150
  "serviceTypeRequestError": "Error retrieving service type: {{- error}}",
168
- "noAbapEnvsInCFSpace": "No ABAP environments in CF space found.",
169
- "abapEnvsCFDiscoveryFailed": "Discovering ABAP Environments failed. Please ensure you are logged into Cloud Foundry (see https://docs.cloudfoundry.org/cf-cli/getting-started.html#login).",
170
151
  "abapServiceAuthenticationFailed": "ABAP environment authentication using UAA failed.",
171
152
  "serviceCatalogRequest": "An error occurred requesting services from: {{- catalogRequestUri }} and entity set: {{entitySet}}. {{error}}",
172
153
  "storedSystemConnectionError": "An error occurred while validating the stored system connection info. System name: {{-systemName}}, error: {{- error}}",
173
154
  "noCatalogOrServiceAvailable": "No active system or OData service endpoint connection available to retrieve service(s).",
174
- "systemConnectionValidationFailed": "A connection to the selected system could not be established.",
175
- "allCatalogServiceRequestsFailed": "All catalog service requests failed for the selected system. OData version(s): V{{version}}.",
176
- "internalServerError": "Internal server error{{-errorMsg, addMsgWithColonFormatter}}",
177
- "badGateway": "Bad gateway{{- errorMsg, addMsgWithColonFormatter}}",
178
- "badRequest": "Bad request{{- errorMsg, addMsgWithColonFormatter}}"
155
+ "allCatalogServiceRequestsFailed": "All catalog service requests failed for the selected system. OData version(s): V{{version}}."
179
156
  },
180
157
  "texts": {
181
- "anExpiredCert": "an expired",
182
- "aSelfSignedCert": "a self-signed",
183
- "anUnknownOrInvalidCert": "an unknown or invalid",
184
- "anUntrustedRootCert": "an untrusted root",
185
158
  "suggestedSystemNameClient": ", client {{client}}",
186
159
  "seeLogForDetails": "See log for more details.",
187
160
  "forUserName": "(for user [{{username}}])",
188
161
  "systemTypeBTP": "BTP",
189
162
  "systemTypeS4HC": "S4HC",
190
163
  "httpStatus": "http status {{httpStatus}}"
191
- },
192
- "guidedAnswers": {
193
- "validationErrorHelpText": "Need help with this error?"
194
- },
195
- "telemetry": {
196
- "unknownOsText": "Unknown"
197
164
  }
198
165
  }
package/dist/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { IValidationLink } from '@sap-devx/yeoman-ui-types';
2
1
  import type { Annotations, ServiceProvider } from '@sap-ux/axios-extension';
3
2
  import type { Destination } from '@sap-ux/btp-utils';
4
3
  import type { CommonPromptOptions, YUIQuestion } from '@sap-ux/inquirer-common';
@@ -270,40 +269,6 @@ export type OdataServiceUrlPasswordOptions = Pick<CommonPromptOptions, 'addition
270
269
  type odataServiceInquirerPromptOptions = Record<promptNames.datasourceType, DatasourceTypePromptOptions> & Record<promptNames.metadataFilePath, MetadataPromptOptions> & Record<promptNames.capProject, CapProjectPromptOptions> & Record<promptNames.capService, CapServicePromptOptions> & Record<promptNames.serviceUrl, OdataServiceUrlPromptOptions> & Record<promptNames.serviceUrlPassword, OdataServiceUrlPasswordOptions> & Record<promptNames.serviceSelection, ServiceSelectionPromptOptions> & Record<promptNames.userSystemName, SystemNamePromptOptions> & Record<promptNames.systemSelection, SystemSelectionPromptOptions>;
271
270
  export type OdataServiceQuestion = YUIQuestion<OdataServiceAnswers>;
272
271
  export type OdataServicePromptOptions = Partial<odataServiceInquirerPromptOptions>;
273
- /**
274
- * Implementation of IValidationLink interface.
275
- * Provides a toString() for serialization on CLI since IValidationLink rendering is only supported by YeomanUI.
276
- */
277
- export declare class ValidationLink implements IValidationLink {
278
- message: IValidationLink['message'];
279
- link: IValidationLink['link'];
280
- /**
281
- * Constructor for ValidationLink.
282
- *
283
- * @param validationLink The validation link object to be used for serialization
284
- */
285
- constructor(validationLink: IValidationLink);
286
- /**
287
- * Serialize the validation link object to a string.
288
- *
289
- * @returns The validation link object as a string
290
- */
291
- toString(): string;
292
- }
293
- export declare const hostEnvironment: {
294
- vscode: {
295
- name: string;
296
- technical: string;
297
- };
298
- bas: {
299
- name: string;
300
- technical: string;
301
- };
302
- cli: {
303
- name: string;
304
- technical: string;
305
- };
306
- };
307
272
  export declare const SAP_CLIENT_KEY = "sap-client";
308
273
  export {};
309
274
  //# sourceMappingURL=types.d.ts.map
package/dist/types.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SAP_CLIENT_KEY = exports.hostEnvironment = exports.ValidationLink = exports.promptNames = exports.SapSystemTypes = exports.DatasourceType = void 0;
3
+ exports.SAP_CLIENT_KEY = exports.promptNames = exports.SapSystemTypes = exports.DatasourceType = void 0;
4
4
  /**
5
5
  * This file contains types that are exported by the module and are needed for consumers using the APIs `prompt` and `getPrompts`.
6
6
  */
@@ -62,45 +62,5 @@ var promptNames;
62
62
  */
63
63
  promptNames["systemSelection"] = "systemSelection";
64
64
  })(promptNames || (exports.promptNames = promptNames = {}));
65
- /**
66
- * Implementation of IValidationLink interface.
67
- * Provides a toString() for serialization on CLI since IValidationLink rendering is only supported by YeomanUI.
68
- */
69
- class ValidationLink {
70
- // Having to redeclare properties from an interface should not be required see: https://github.com/Microsoft/TypeScript/issues/5326
71
- message;
72
- link;
73
- /**
74
- * Constructor for ValidationLink.
75
- *
76
- * @param validationLink The validation link object to be used for serialization
77
- */
78
- constructor(validationLink) {
79
- Object.assign(this, validationLink);
80
- }
81
- /**
82
- * Serialize the validation link object to a string.
83
- *
84
- * @returns The validation link object as a string
85
- */
86
- toString() {
87
- return `${this.message} ${this.link.text}${this.link.url ? ' : ' + this.link.url : ''}`;
88
- }
89
- }
90
- exports.ValidationLink = ValidationLink;
91
- exports.hostEnvironment = {
92
- vscode: {
93
- name: 'Visual Studio Code',
94
- technical: 'VSCode'
95
- },
96
- bas: {
97
- name: 'SAP Business Application Studio',
98
- technical: 'SBAS'
99
- },
100
- cli: {
101
- name: 'CLI',
102
- technical: 'CLI'
103
- }
104
- };
105
65
  exports.SAP_CLIENT_KEY = 'sap-client';
106
66
  //# sourceMappingURL=types.js.map
@@ -1,39 +1,17 @@
1
1
  import { ODataVersion } from '@sap-ux/axios-extension';
2
- import { type Destination } from '@sap-ux/btp-utils';
3
2
  import { OdataVersion } from '@sap-ux/odata-service-writer';
4
- import type { TelemetryProperties, ToolsSuiteTelemetryClient } from '@sap-ux/telemetry';
5
3
  import type { ListChoiceOptions } from 'inquirer';
6
4
  import { PromptState } from './prompt-state';
7
- export type TelemPropertyDestinationType = 'AbapODataCatalogDest' | 'GenericODataFullUrlDest' | 'GenericODataPartialUrlDest' | 'Unknown';
5
+ import { type HostEnvironmentId } from '@sap-ux/fiori-generator-shared';
8
6
  /**
9
7
  * Determine if the current prompting environment is cli or a hosted extension (app studio or vscode).
10
8
  *
11
9
  * @returns the platform name and technical name
12
10
  */
13
- export declare function getHostEnvironment(): {
11
+ export declare function getPromptHostEnvironment(): {
14
12
  name: string;
15
- technical: string;
13
+ technical: HostEnvironmentId;
16
14
  };
17
- /**
18
- * Set the telemetry client.
19
- *
20
- * @param toolsSuiteTelemetryClient the telemetry client instance to use when sending telemetry events
21
- */
22
- export declare function setTelemetryClient(toolsSuiteTelemetryClient: ToolsSuiteTelemetryClient | undefined): void;
23
- /**
24
- * Send telemetry event.
25
- *
26
- * @param eventName the name of the telemetry event
27
- * @param telemetryData the telemetry values to report
28
- */
29
- export declare function sendTelemetryEvent(eventName: string, telemetryData: TelemetryProperties): void;
30
- /**
31
- * Used only to generate telemetry events in the case of destination errors.
32
- *
33
- * @param destination
34
- * @returns the telemetry property destination type
35
- */
36
- export declare function getTelemPropertyDestinationType(destination: Destination): TelemPropertyDestinationType;
37
15
  /**
38
16
  * Validate xml and parse the odata version from the metadata xml.
39
17
  *
@@ -4,10 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.PromptState = void 0;
7
- exports.getHostEnvironment = getHostEnvironment;
8
- exports.setTelemetryClient = setTelemetryClient;
9
- exports.sendTelemetryEvent = sendTelemetryEvent;
10
- exports.getTelemPropertyDestinationType = getTelemPropertyDestinationType;
7
+ exports.getPromptHostEnvironment = getPromptHostEnvironment;
11
8
  exports.parseOdataVersion = parseOdataVersion;
12
9
  exports.originToRelative = originToRelative;
13
10
  exports.convertODataVersionType = convertODataVersionType;
@@ -15,87 +12,23 @@ exports.getDefaultChoiceIndex = getDefaultChoiceIndex;
15
12
  const axios_extension_1 = require("@sap-ux/axios-extension");
16
13
  const btp_utils_1 = require("@sap-ux/btp-utils");
17
14
  const odata_service_writer_1 = require("@sap-ux/odata-service-writer");
18
- const telemetry_1 = require("@sap-ux/telemetry");
19
15
  const fast_xml_parser_1 = require("fast-xml-parser");
20
- const os_name_1 = __importDefault(require("os-name"));
21
16
  const i18n_1 = require("../i18n");
22
17
  const logger_helper_1 = __importDefault(require("../prompts/logger-helper"));
23
- const types_1 = require("../types");
24
18
  const prompt_state_1 = require("./prompt-state");
25
19
  Object.defineProperty(exports, "PromptState", { enumerable: true, get: function () { return prompt_state_1.PromptState; } });
26
- const osVersionName = (0, os_name_1.default)();
20
+ const fiori_generator_shared_1 = require("@sap-ux/fiori-generator-shared");
27
21
  /**
28
22
  * Determine if the current prompting environment is cli or a hosted extension (app studio or vscode).
29
23
  *
30
24
  * @returns the platform name and technical name
31
25
  */
32
- function getHostEnvironment() {
26
+ function getPromptHostEnvironment() {
33
27
  if (!prompt_state_1.PromptState.isYUI) {
34
- return types_1.hostEnvironment.cli;
28
+ return fiori_generator_shared_1.hostEnvironment.cli;
35
29
  }
36
30
  else {
37
- return (0, btp_utils_1.isAppStudio)() ? types_1.hostEnvironment.bas : types_1.hostEnvironment.vscode;
38
- }
39
- }
40
- let telemetryClient;
41
- /**
42
- * Set the telemetry client.
43
- *
44
- * @param toolsSuiteTelemetryClient the telemetry client instance to use when sending telemetry events
45
- */
46
- function setTelemetryClient(toolsSuiteTelemetryClient) {
47
- telemetryClient = toolsSuiteTelemetryClient;
48
- }
49
- /**
50
- * Send telemetry event.
51
- *
52
- * @param eventName the name of the telemetry event
53
- * @param telemetryData the telemetry values to report
54
- */
55
- function sendTelemetryEvent(eventName, telemetryData) {
56
- const telemetryEvent = createTelemetryEvent(eventName, telemetryData);
57
- if (telemetryClient) {
58
- // Do not wait for the telemetry event to be sent, it cannot be recovered if it fails, do not block the process
59
- /* eslint-disable @typescript-eslint/no-floating-promises */
60
- telemetryClient.reportEvent(telemetryEvent, telemetry_1.SampleRate.NoSampling);
61
- }
62
- }
63
- /**
64
- * Create telemetry event.
65
- *
66
- * @param eventName the name of the telemetry event
67
- * @param telemetryData the telemetry values to add to he returned telemetry event
68
- * @returns the telemetry event
69
- */
70
- function createTelemetryEvent(eventName, telemetryData) {
71
- const telemProps = Object.assign(telemetryData, {
72
- Platform: getHostEnvironment().technical,
73
- OperatingSystem: osVersionName
74
- });
75
- return {
76
- eventName,
77
- properties: telemProps,
78
- measurements: {}
79
- };
80
- }
81
- /**
82
- * Used only to generate telemetry events in the case of destination errors.
83
- *
84
- * @param destination
85
- * @returns the telemetry property destination type
86
- */
87
- function getTelemPropertyDestinationType(destination) {
88
- if ((0, btp_utils_1.isAbapODataDestination)(destination)) {
89
- return 'AbapODataCatalogDest';
90
- }
91
- else if ((0, btp_utils_1.isFullUrlDestination)(destination)) {
92
- return 'GenericODataFullUrlDest';
93
- }
94
- else if ((0, btp_utils_1.isPartialUrlDestination)(destination)) {
95
- return 'GenericODataPartialUrlDest';
96
- }
97
- else {
98
- return 'Unknown';
31
+ return (0, btp_utils_1.isAppStudio)() ? fiori_generator_shared_1.hostEnvironment.bas : fiori_generator_shared_1.hostEnvironment.vscode;
99
32
  }
100
33
  }
101
34
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sap-ux/odata-service-inquirer",
3
3
  "description": "Prompts module that can prompt users for inputs required for odata service writing",
4
- "version": "0.6.0",
4
+ "version": "0.6.2",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -28,14 +28,14 @@
28
28
  "os-name": "4.0.1",
29
29
  "@sap-ux/axios-extension": "1.17.2",
30
30
  "@sap-ux/btp-utils": "0.16.0",
31
- "@sap-ux/fiori-generator-shared": "0.7.6",
32
- "@sap-ux/guided-answers-helper": "0.1.0",
31
+ "@sap-ux/fiori-generator-shared": "0.7.7",
33
32
  "@sap-ux/telemetry": "0.5.42",
34
- "@sap-ux/inquirer-common": "0.4.10",
33
+ "@sap-ux/guided-answers-helper": "0.1.0",
34
+ "@sap-ux/inquirer-common": "0.5.0",
35
35
  "@sap-ux/logger": "0.6.0",
36
36
  "@sap-ux/project-access": "1.28.6",
37
- "@sap-ux/project-input-validator": "0.3.3",
38
- "@sap-ux/store": "0.9.3"
37
+ "@sap-ux/store": "0.9.3",
38
+ "@sap-ux/project-input-validator": "0.3.3"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@sap-devx/yeoman-ui-types": "1.14.4",
@@ -43,6 +43,7 @@
43
43
  "@types/inquirer": "8.2.6",
44
44
  "@types/lodash": "4.14.202",
45
45
  "jest-extended": "3.2.4",
46
+ "@sap-ux/fiori-generator-shared": "0.7.7",
46
47
  "@sap-ux/odata-service-writer": "0.23.1",
47
48
  "@sap-ux/feature-toggle": "0.2.2"
48
49
  },
@@ -1,206 +0,0 @@
1
- import type { Destination } from '@sap-ux/btp-utils';
2
- import { type Logger } from '@sap-ux/logger';
3
- import { ValidationLink } from '../types';
4
- /**
5
- * Constants specific to error handling
6
- */
7
- export declare enum ERROR_TYPE {
8
- AUTH = "AUTH",
9
- AUTH_TIMEOUT = "AUTH_TIMEOUT",
10
- REDIRECT = "REDIRECT",
11
- CERT = "CERT",// General cert error
12
- CERT_SELF_SIGNED = "CERT_SELF_SIGNED",
13
- CERT_UKNOWN_OR_INVALID = "CERT_UKNOWN_OR_INVALID",
14
- CERT_EXPIRED = "CERT_EXPIRED",
15
- CERT_SELF_SIGNED_CERT_IN_CHAIN = "CERT_SELF_SIGNED_CERT_IN_CHAIN",
16
- UNKNOWN = "UNKNOWN",
17
- INVALID_URL = "INVALID_URL",
18
- TIMEOUT = "TIMEOUT",
19
- CONNECTION = "CONNECTION",
20
- SERVICES_UNAVAILABLE = "SERVICES_UNAVAILABLE",// All services
21
- SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE",// HTTP 503 Not related to odata services
22
- NO_ABAP_ENVS = "NO_ABAP_ENVS",
23
- CATALOG_SERVICE_NOT_ACTIVE = "CATALOG_SERVICE_NOT_ACTIVE",
24
- NO_SUCH_HOST = "NO_SUCH_HOST",
25
- NOT_FOUND = "NOT_FOUND",
26
- ODATA_URL_NOT_FOUND = "ODATA_URL_NOT_FOUND",
27
- BAD_GATEWAY = "BAD_GATEWAY",// Can be caused by either local issue or endpoint configuration
28
- INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR",
29
- DESTINATION_BAD_GATEWAY_503 = "DESTINATION_BAD_GATEWAY_503",// Caused by endpoint using a firewall or proxy
30
- DESTINATION_UNAVAILABLE = "DESTINATION_UNAVAILABLE",
31
- DESTINATION_NOT_FOUND = "DESTINATION_NOT_FOUND",
32
- DESTINATION_MISCONFIGURED = "DESTINATION_MISCONFIGURED",
33
- NO_V2_SERVICES = "NO_V2_SERVICES",
34
- NO_V4_SERVICES = "NO_V4_SERVICES",
35
- BAD_REQUEST = "BAD_REQUEST",
36
- DESTINATION_CONNECTION_ERROR = "DESTINATION_CONNECTION_ERROR",// General destination connection error where a specific root cause cannot be determined e.g. In the case of an internal server error
37
- SERVER_HTTP_ERROR = "SERVER_HTTP_ERROR"
38
- }
39
- export declare const ERROR_MAP: Record<ERROR_TYPE, RegExp[]>;
40
- type ValidationLinkOrString = string | ValidationLink;
41
- /**
42
- * Maps errors to end-user messages using some basic root cause analysis based on regex matching.
43
- * This class will also log errors and provide help links for validation errors in some limited use cases.
44
- */
45
- export declare class ErrorHandler {
46
- /** The last error message generated */
47
- private currentErrorMsg;
48
- /** The last error message type generated if determined */
49
- private currentErrorType;
50
- private static _guidedAnswersEnabled;
51
- private static _logger;
52
- private static readonly getMessageFromError;
53
- private static readonly _errorTypeToMsg;
54
- /**
55
- *
56
- * @param errorType
57
- * @param error can be any object that will get stringified and passed to the specific error message for the error type entry, e.g. where the error message is parameterized
58
- * @returns an error message for the specified error type
59
- */
60
- private static readonly _errorMsg;
61
- /**
62
- * Get the Guided Answers (help) node for the specified error type.
63
- *
64
- * @param errorType The error type for which a help node (help content id) may be returned
65
- * @returns The Guided Answers node for the specified error type
66
- */
67
- private static readonly getHelpNode;
68
- /**
69
- * Find an error property for mapping to a general error type from most to least significant.
70
- *
71
- * @param error any type of error or object that has an error code, status, name or message
72
- * @returns a value that can be used to look up a general error type
73
- */
74
- private static findErrorValueForMapping;
75
- /**
76
- * Create an instance of the ErrorHandler.
77
- *
78
- * @param logger the logger instance to use
79
- * @param enableGuidedAnswers if true, the end user validation errors will include guided answers to provide help
80
- */
81
- constructor(logger?: Logger, enableGuidedAnswers?: boolean);
82
- /**
83
- * Get Guided Answers (context help) enabled value.
84
- *
85
- * @returns true if Guided Answers is enabled
86
- */
87
- static get guidedAnswersEnabled(): boolean;
88
- /**
89
- * Toggle Guided Answers (context help) for validation errors.
90
- */
91
- static set guidedAnswersEnabled(value: boolean);
92
- /**
93
- * Set the logger to be used for error messages.
94
- *
95
- * @param logger the logger instance to use
96
- */
97
- static set logger(logger: Logger);
98
- /**
99
- * Get the logger used for error messages.
100
- *
101
- * @returns the logger instance
102
- */
103
- static get logger(): Logger;
104
- /**
105
- * Tests if the error is a general certificate error.
106
- *
107
- * @param status the error type
108
- * @returns true if the error is a general certificate error
109
- */
110
- static isCertError(status: string | number): boolean;
111
- /**
112
- * Get the error type for the specified error, mapping status code, error code, error name, error message to a few general error types.
113
- *
114
- * @param error the error, string or status code to get the type for
115
- * @returns the error type
116
- */
117
- static getErrorType(error: string | number | Error): ERROR_TYPE;
118
- /**
119
- * Maps errors to a few generic types, log a detailed error.
120
- *
121
- * @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.
122
- * @param userMsg If provided this will be set as the userErrorMsg instead of an error to msg map
123
- * this allows a message more relevant to the context of where the error was generated to be used.
124
- * @param retainError Defaults to true to retain the error state.
125
- * @returns A user-friendly message for display in-line
126
- */
127
- logErrorMsgs(error: unknown, userMsg?: string, retainError?: boolean): string;
128
- /**
129
- * 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.
130
- *
131
- * @param error The error to map
132
- * @returns The mapped error message and error type
133
- */
134
- private static mapErrorToMsg;
135
- /**
136
- * Used by validate functions to report in-line user friendly errors.
137
- * Checks if there is an existing error.
138
- *
139
- * @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`.
140
- * @param reset optional, resets the previous error state if true, if error is omitted reset may be passed as the first argument
141
- * @param fallback optional, return the message of the specified ERROR_TYPE if no previous end user message and no error specified
142
- * @returns The error message
143
- */
144
- getErrorMsg(error?: any, reset?: boolean, fallback?: ERROR_TYPE): string | undefined;
145
- /**
146
- * Used by validate functions to report in-line user friendly errors messages with help links.
147
- * If the error type is unknown, this will find a mapped error type and return the help (ValidationLink) if it exists.
148
- * If an error is not provided the current error state will be used. This does not log the message to the console.
149
- * If a system is provided, the error type may be refined to provide a more specific error message for the system which generatd the error.
150
- *
151
- * @param error optional, if provided get the help link message that it maps to, otherwise get the previously logged error message help link
152
- * @param reset optional, resets the previous error state if true
153
- * @param destination optional, if provided the destination may be used to determine a more relevant error message, specific to the system properties
154
- * @returns An instance of @see {ValidationLink}
155
- */
156
- getValidationErrorHelp(error?: any, reset?: boolean, destination?: Destination): ValidationLinkOrString | undefined;
157
- /**
158
- * Get a more specific error type for the specified destination.
159
- *
160
- * @param errorType
161
- * @param destination
162
- * @returns
163
- */
164
- private static getDestinationSpecificError;
165
- /**
166
- * Get the error message for the specified error type.
167
- *
168
- * @param errorType The error type for which the message may be returned
169
- * @param error optional, if provided may be used to get generate a more specific error message, or be included in the message
170
- * @returns The error message for the specified error type
171
- */
172
- static getErrorMsgFromType(errorType: ERROR_TYPE, error?: any): string | undefined;
173
- /**
174
- * Checks if there is an existing error.
175
- *
176
- * @param reset - resets the current error state
177
- * @returns true if there is an existing error
178
- */
179
- hasError(reset?: boolean): boolean;
180
- /**
181
- * Sets the current error state.
182
- *
183
- * @param errorType - the error type
184
- * @param error - the original error, if any
185
- */
186
- setCurrentError(errorType: ERROR_TYPE, error?: any): void;
187
- /**
188
- * Gets the current error type state.
189
- *
190
- * @param reset - resets the current error state
191
- * @returns The current error type
192
- */
193
- getCurrentErrorType(reset?: boolean): ERROR_TYPE | null;
194
- /**
195
- * Maps an error type to a validation link if help (Guided Answers topic) is available for the specified error.
196
- * Otherwise the specified error message is returned. To retrieve the previous error state @see getValidationErrorHelp.
197
- * Use this (getHelpForError) if the error type is known.
198
- *
199
- * @param errorType - the error type to be mapped to help link
200
- * @param errorMsg - the message to appear with the help link
201
- * @returns A validation help link or help link message
202
- */
203
- static getHelpForError(errorType: ERROR_TYPE, errorMsg?: string): ValidationLinkOrString | undefined;
204
- }
205
- export {};
206
- //# sourceMappingURL=error-handler.d.ts.map