@sap-ux/odata-service-inquirer 0.6.0 → 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 (27) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +9 -6
  3. package/dist/prompts/connectionValidator.d.ts +1 -1
  4. package/dist/prompts/connectionValidator.js +25 -25
  5. package/dist/prompts/datasources/cap-project/questions.js +2 -1
  6. package/dist/prompts/datasources/sap-system/abap-on-btp/questions.d.ts +1 -1
  7. package/dist/prompts/datasources/sap-system/abap-on-btp/questions.js +8 -10
  8. package/dist/prompts/datasources/sap-system/credentials/questions.d.ts +2 -2
  9. package/dist/prompts/datasources/sap-system/credentials/questions.js +2 -2
  10. package/dist/prompts/datasources/sap-system/service-selection/questions.js +4 -4
  11. package/dist/prompts/datasources/sap-system/service-selection/service-helper.js +3 -2
  12. package/dist/prompts/datasources/sap-system/system-selection/prompt-helpers.js +3 -3
  13. package/dist/prompts/datasources/sap-system/system-selection/questions.js +2 -1
  14. package/dist/prompts/datasources/service-url/questions.js +2 -1
  15. package/dist/prompts/datasources/service-url/validators.js +3 -3
  16. package/dist/prompts/prompt-helpers.d.ts +1 -1
  17. package/dist/prompts/prompt-helpers.js +2 -2
  18. package/dist/translations/odata-service-inquirer.i18n.json +4 -37
  19. package/dist/types.d.ts +0 -35
  20. package/dist/types.js +1 -41
  21. package/dist/utils/index.d.ts +3 -25
  22. package/dist/utils/index.js +5 -72
  23. package/package.json +6 -5
  24. package/dist/error-handler/error-handler.d.ts +0 -206
  25. package/dist/error-handler/error-handler.js +0 -567
  26. package/dist/prompts/datasources/sap-system/abap-on-btp/cf-helper.d.ts +0 -9
  27. package/dist/prompts/datasources/sap-system/abap-on-btp/cf-helper.js +0 -54
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.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -28,10 +28,10 @@
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",
31
+ "@sap-ux/fiori-generator-shared": "0.7.7",
32
32
  "@sap-ux/guided-answers-helper": "0.1.0",
33
33
  "@sap-ux/telemetry": "0.5.42",
34
- "@sap-ux/inquirer-common": "0.4.10",
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
37
  "@sap-ux/project-input-validator": "0.3.3",
@@ -43,8 +43,9 @@
43
43
  "@types/inquirer": "8.2.6",
44
44
  "@types/lodash": "4.14.202",
45
45
  "jest-extended": "3.2.4",
46
- "@sap-ux/odata-service-writer": "0.23.1",
47
- "@sap-ux/feature-toggle": "0.2.2"
46
+ "@sap-ux/fiori-generator-shared": "0.7.7",
47
+ "@sap-ux/feature-toggle": "0.2.2",
48
+ "@sap-ux/odata-service-writer": "0.23.1"
48
49
  },
49
50
  "engines": {
50
51
  "node": ">=18.x"
@@ -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