@sap-ux/odata-service-inquirer 2.14.9 → 2.14.11

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.
package/dist/index.d.ts CHANGED
@@ -30,9 +30,10 @@ declare function getPrompts(promptOptions?: OdataServicePromptOptions, logger?:
30
30
  *
31
31
  * @param promptOptions - options that can control some of the prompt behavior. See {@link OdataServicePromptOptions} for details
32
32
  * @param isYUI - if true, the prompt is being called from the Yeoman UI extension host. PromptState.isYUI will be set to this value
33
+ * @param logger - set an externally configured logger
33
34
  * @returns the prompts used to provide input for system selection and a reference to the answers object which will be populated with the user's responses once `inquirer.prompt` returns
34
35
  */
35
- declare function getSystemSelectionQuestions(promptOptions?: OdataServicePromptOptions, isYUI?: boolean): Promise<{
36
+ declare function getSystemSelectionQuestions(promptOptions?: OdataServicePromptOptions, isYUI?: boolean, logger?: Logger): Promise<{
36
37
  prompts: Question<SystemSelectionAnswers & ServiceAnswer>[];
37
38
  answers: Partial<OdataServiceAnswers>;
38
39
  }>;
package/dist/index.js CHANGED
@@ -58,12 +58,16 @@ async function getPrompts(promptOptions, logger, enableGuidedAnswers = false, te
58
58
  *
59
59
  * @param promptOptions - options that can control some of the prompt behavior. See {@link OdataServicePromptOptions} for details
60
60
  * @param isYUI - if true, the prompt is being called from the Yeoman UI extension host. PromptState.isYUI will be set to this value
61
+ * @param logger - set an externally configured logger
61
62
  * @returns the prompts used to provide input for system selection and a reference to the answers object which will be populated with the user's responses once `inquirer.prompt` returns
62
63
  */
63
- async function getSystemSelectionQuestions(promptOptions, isYUI) {
64
+ async function getSystemSelectionQuestions(promptOptions, isYUI, logger) {
64
65
  if (isYUI !== undefined) {
65
66
  utils_1.PromptState.isYUI = isYUI;
66
67
  }
68
+ if (logger) {
69
+ logger_helper_1.default.logger = logger;
70
+ }
67
71
  return {
68
72
  prompts: await (0, system_selection_1.getSystemSelectionQuestions)(promptOptions),
69
73
  answers: utils_1.PromptState.odataService
@@ -15,6 +15,8 @@ const logger_helper_1 = __importDefault(require("../../../logger-helper"));
15
15
  const prompt_helpers_1 = require("../../../prompt-helpers");
16
16
  const service_helper_1 = require("../service-selection/service-helper");
17
17
  const value_help_download_1 = require("../external-services/value-help-download");
18
+ const isEqual_1 = __importDefault(require("lodash/isEqual"));
19
+ const sortBy_1 = __importDefault(require("lodash/sortBy"));
18
20
  const cliServicePromptName = 'cliServiceSelection';
19
21
  /**
20
22
  * Get the service selection prompt for an Abap system connection (on-prem or on-btp). The service selection prompt is used to select a service from the system catalog.
@@ -32,6 +34,7 @@ function getSystemServiceQuestion(connectValidator, promptNamespace, promptOptio
32
34
  let previousSystemUrl;
33
35
  let previousClient;
34
36
  let previousService;
37
+ let previousServiceFilter;
35
38
  // State shared across validate and additionalMessages functions
36
39
  let hasBackendAnnotations;
37
40
  // Wrap to allow pass by ref to nested prompts
@@ -55,12 +58,14 @@ function getSystemServiceQuestion(connectValidator, promptNamespace, promptOptio
55
58
  choices: async (answers) => {
56
59
  if (serviceChoices.length === 0 ||
57
60
  previousSystemUrl !== connectValidator.validatedUrl ||
58
- previousClient !== connectValidator.validatedClient) {
61
+ previousClient !== connectValidator.validatedClient ||
62
+ !(0, isEqual_1.default)((0, sortBy_1.default)(previousServiceFilter), (0, sortBy_1.default)(promptOptions?.serviceFilter))) {
59
63
  // if we have a catalog, use it to list services
60
64
  if (connectValidator.catalogs[odata_service_writer_1.OdataVersion.v2] || connectValidator.catalogs[odata_service_writer_1.OdataVersion.v4]) {
61
65
  serviceChoices = await createServiceChoicesFromCatalog(connectValidator.catalogs, requiredOdataVersion, promptOptions?.serviceFilter);
62
66
  previousSystemUrl = connectValidator.validatedUrl;
63
67
  previousClient = connectValidator.validatedClient;
68
+ previousServiceFilter = promptOptions?.serviceFilter ? [...promptOptions.serviceFilter] : undefined;
64
69
  // Telemetry event for successful service listing using a destination
65
70
  if (answers?.[`${types_1.promptNames.systemSelection}`]?.type === 'destination') {
66
71
  (0, service_helper_1.sendDestinationServiceSuccessTelemetryEvent)(answers?.[`${types_1.promptNames.systemSelection}`]?.system);
@@ -98,7 +103,8 @@ function getSystemServiceQuestion(connectValidator, promptNamespace, promptOptio
98
103
  showCollabDraftWarning: !!promptOptions?.showCollaborativeDraftWarning,
99
104
  edmx: convertedMetadataRef.convertedMetadata
100
105
  }
101
- : undefined
106
+ : undefined,
107
+ serviceFilter: promptOptions?.serviceFilter
102
108
  }),
103
109
  default: () => (0, utils_1.getDefaultChoiceIndex)(serviceChoices),
104
110
  // Warning: only executes in YUI and cli when automcomplete is used
@@ -73,12 +73,14 @@ type ShowCollabDraftWarnOptions = {
73
73
  * @param options.hasAnnotations used to determine whether to show a warning message that annotations could not be retrieved
74
74
  * @param options.showCollabDraftWarnOptions to show the collaborative draft warning, the option `showCollabDraftWarning` must be true
75
75
  * and the edmx metadata must be provided
76
+ * @param options.serviceFilter if a service filter has been specified this may alter the user messages when no services are listed
76
77
  * @returns the service selection prompt additional message
77
78
  */
78
- export declare function getSelectedServiceMessage(serviceChoices: ListChoiceOptions<ServiceAnswer>[], selectedService: ServiceAnswer | undefined, connectValidator: ConnectionValidator, { requiredOdataVersion, hasAnnotations, showCollabDraftWarnOptions }: {
79
+ export declare function getSelectedServiceMessage(serviceChoices: ListChoiceOptions<ServiceAnswer>[], selectedService: ServiceAnswer | undefined, connectValidator: ConnectionValidator, { requiredOdataVersion, hasAnnotations, showCollabDraftWarnOptions, serviceFilter }: {
79
80
  requiredOdataVersion?: OdataVersion;
80
81
  hasAnnotations?: boolean;
81
82
  showCollabDraftWarnOptions?: ShowCollabDraftWarnOptions;
83
+ serviceFilter?: string[];
82
84
  }): Promise<IMessageSeverity | undefined>;
83
85
  export {};
84
86
  //# sourceMappingURL=service-helper.d.ts.map
@@ -127,7 +127,7 @@ async function getServiceChoices(catalogs, serviceFilter) {
127
127
  logServiceCatalogErrorsForHelp(requestErrors, catalogs.length);
128
128
  }
129
129
  if (serviceFilter) {
130
- flatServices = flatServices.filter((service) => serviceFilter.includes(service.id));
130
+ flatServices = flatServices.filter((service) => serviceFilter.includes(service.id) || serviceFilter.includes(service.path));
131
131
  }
132
132
  return createServiceChoices(flatServices);
133
133
  }
@@ -295,10 +295,22 @@ function getSelectedServiceLabel(username) {
295
295
  * @param options.hasAnnotations used to determine whether to show a warning message that annotations could not be retrieved
296
296
  * @param options.showCollabDraftWarnOptions to show the collaborative draft warning, the option `showCollabDraftWarning` must be true
297
297
  * and the edmx metadata must be provided
298
+ * @param options.serviceFilter if a service filter has been specified this may alter the user messages when no services are listed
298
299
  * @returns the service selection prompt additional message
299
300
  */
300
- async function getSelectedServiceMessage(serviceChoices, selectedService, connectValidator, { requiredOdataVersion, hasAnnotations = true, showCollabDraftWarnOptions }) {
301
+ async function getSelectedServiceMessage(serviceChoices, selectedService, connectValidator, { requiredOdataVersion, hasAnnotations = true, showCollabDraftWarnOptions, serviceFilter }) {
302
+ // Note that the order of these conditions is critical
301
303
  if (serviceChoices?.length === 0) {
304
+ if (serviceFilter && serviceFilter.length > 0) {
305
+ return {
306
+ message: (0, i18n_1.t)('warnings.specifiedServicesNotAvailable', {
307
+ odataVersion: requiredOdataVersion ? `V${requiredOdataVersion} ` : undefined,
308
+ service: serviceFilter[0],
309
+ count: serviceFilter.length
310
+ }),
311
+ severity: yeoman_ui_types_1.Severity.warning
312
+ };
313
+ }
302
314
  if (requiredOdataVersion) {
303
315
  return {
304
316
  message: (0, i18n_1.t)('warnings.noServicesAvailableForOdataVersion', {
@@ -51,5 +51,7 @@ export declare function createSystemChoices(destinationFilters?: Partial<Destina
51
51
  * @param defaultChoice the default choice value
52
52
  * @returns the index of the default choice in the system choices list
53
53
  */
54
- export declare function findDefaultSystemSelectionIndex(systemChoices: ListChoiceOptions<SystemSelectionAnswerType>[], defaultChoice: string | undefined): number;
54
+ export declare function findDefaultSystemSelectionIndex(systemChoices: ListChoiceOptions<SystemSelectionAnswerType>[], defaultChoice: string | {
55
+ value?: string;
56
+ } | undefined): number;
55
57
  //# sourceMappingURL=prompt-helpers.d.ts.map
@@ -212,22 +212,23 @@ async function createSystemChoices(destinationFilters, includeCloudFoundryAbapEn
212
212
  * @returns the index of the default choice in the system choices list
213
213
  */
214
214
  function findDefaultSystemSelectionIndex(systemChoices, defaultChoice) {
215
- if (!defaultChoice) {
215
+ const choice = typeof defaultChoice === 'string' ? defaultChoice : defaultChoice?.value;
216
+ if (!choice) {
216
217
  return -1;
217
218
  }
218
- const defaultChoiceIndex = systemChoices.findIndex((choice) => {
219
- const { type: systemType, system } = choice.value;
219
+ const defaultChoiceIndex = systemChoices.findIndex((systemChoice) => {
220
+ const { type: systemType, system } = systemChoice.value;
220
221
  if (systemType === 'destination') {
221
- return system.Name === defaultChoice;
222
+ return system.Name === choice;
222
223
  }
223
224
  if (systemType === 'backendSystem') {
224
- return system.name === defaultChoice;
225
+ return system.name === choice;
225
226
  }
226
227
  if (systemType === 'newSystemChoice') {
227
- return defaultChoice === exports.NewSystemChoice;
228
+ return choice === exports.NewSystemChoice;
228
229
  }
229
230
  if (systemType === 'cfAbapEnvService') {
230
- return defaultChoice === exports.CfAbapEnvServiceChoice;
231
+ return choice === exports.CfAbapEnvServiceChoice;
231
232
  }
232
233
  });
233
234
  return defaultChoiceIndex;
@@ -100,7 +100,7 @@ async function getSystemConnectionQuestions(connectionValidator, promptOptions,
100
100
  const requiredOdataVersion = promptOptions?.serviceSelection?.requiredOdataVersion;
101
101
  const destinationFilters = promptOptions?.systemSelection?.destinationFilters;
102
102
  const systemChoices = await (0, prompt_helpers_1.createSystemChoices)(destinationFilters, promptOptions?.systemSelection?.includeCloudFoundryAbapEnvChoice, promptOptions?.systemSelection?.hideNewSystem);
103
- const defaultChoiceIndex = (0, prompt_helpers_1.findDefaultSystemSelectionIndex)(systemChoices, promptOptions?.systemSelection?.defaultChoice);
103
+ let defaultChoiceIndex = (0, prompt_helpers_1.findDefaultSystemSelectionIndex)(systemChoices, promptOptions?.systemSelection?.defaultChoice);
104
104
  const shouldOnlyShowDefaultChoice = promptOptions?.systemSelection?.onlyShowDefaultChoice && promptOptions?.systemSelection?.defaultChoice;
105
105
  const questions = [
106
106
  {
@@ -113,7 +113,13 @@ async function getSystemConnectionQuestions(connectionValidator, promptOptions,
113
113
  },
114
114
  source: (prevAnswers, input) => (0, inquirer_common_1.searchChoices)(input, systemChoices),
115
115
  choices: shouldOnlyShowDefaultChoice ? [systemChoices[defaultChoiceIndex]] : systemChoices,
116
- default: shouldOnlyShowDefaultChoice ? 0 : defaultChoiceIndex,
116
+ default: () => {
117
+ if (shouldOnlyShowDefaultChoice) {
118
+ return 0;
119
+ }
120
+ defaultChoiceIndex = (0, prompt_helpers_1.findDefaultSystemSelectionIndex)(systemChoices, promptOptions?.systemSelection?.defaultChoice); // Recalc to allow default choice to be bound to ref from another prompt
121
+ return defaultChoiceIndex;
122
+ },
117
123
  validate: async (selectedSystem) => {
118
124
  if (!selectedSystem) {
119
125
  return false;
@@ -261,8 +261,10 @@
261
261
  "certificateErrors": "A certificate error occurred when connecting to the host: {{-url}}. Certificate error: {{error}}.",
262
262
  "allowingUnauthorizedCertsNode": "Setting the `NODE_TLS_REJECT_UNAUTHORIZED` environment variable to `0` makes TLS connections and HTTPS requests insecure by disabling certificate verification. It is important to understand the security risks when using this setting.",
263
263
  "certErrorIgnoredByNodeSetting": "An SSL certificate error is being ignored by the 'NODE_TLS_REJECT_UNAUTHORIZED=0' Node.js setting. This makes TLS connections and HTTPS requests insecure by disabling certificate verification. For details of the certification error, see the logs.",
264
- "noExternalServiceMetdataFetched": "No external service metadata were fetched. $t(texts.seeLogForDetails).",
265
- "missingServices": "OData V{{odataVersion}} services are not available."
264
+ "noExternalServiceMetdataFetched": "No external service metadata was fetched. $t(texts.seeLogForDetails)",
265
+ "missingServices": "OData V{{odataVersion}} services are not available.",
266
+ "specifiedServicesNotAvailable_one": "The required OData service: {{-service}} is not available from the {{odataVersion}}services catalog. Please ensure the service is available.",
267
+ "specifiedServicesNotAvailable_other": "The required OData services are not available from the {{odataVersion}}services catalog. Please ensure the services are available. $t(texts.seeLogForDetails)"
266
268
  },
267
269
  "texts": {
268
270
  "suggestedSystemNameClient": ", client {{client}}",
package/dist/types.d.ts CHANGED
@@ -286,9 +286,12 @@ export type SystemSelectionPromptOptions = {
286
286
  * Provide a default choice for the system selection prompt, this is used to pre-select a system based on the system name.
287
287
  * Set as string literal types `NewSystemChoice` or `CfAbapEnvServiceChoice` to specify the default choice to create a new system connection config in VSCode
288
288
  * or to select the Cloud Foundry Abap environments service discovery choice in BAS respectively.
289
+ * Supported as object reference `{ value: }` to allow binding to runtime variables of other prompts or as string
289
290
  *
290
291
  */
291
- defaultChoice?: string;
292
+ defaultChoice?: string | {
293
+ value?: string;
294
+ };
292
295
  /**
293
296
  * Only show the default choice in the system selection prompt, this is used to skip the system selection prompt if the default choice is already known.
294
297
  * If the `defaultChoice` value is not found in the systems choices, or the `defaultChoice` option is not specified,
@@ -296,7 +299,7 @@ export type SystemSelectionPromptOptions = {
296
299
  */
297
300
  onlyShowDefaultChoice?: boolean;
298
301
  /**
299
- * If true, the 'New System' option is not added to the system selection list.
302
+ * If true, the 'New System' option is not added to the system selection list. Default is false - the 'New System' option will be available.
300
303
  */
301
304
  hideNewSystem?: boolean;
302
305
  };
@@ -327,7 +330,7 @@ export type ServiceSelectionPromptOptions = {
327
330
  */
328
331
  showCollaborativeDraftWarning?: boolean;
329
332
  /**
330
- * A list of service ids ({@link ODataServiceInfo.id}), used to filter the catalog results
333
+ * A list of service ids ({@link ODataServiceInfo.id}) or service paths ({@link ODataServiceInfo.path}), used to filter the service catalog results
331
334
  */
332
335
  serviceFilter?: string[];
333
336
  } & Pick<CommonPromptOptions, 'additionalMessages'>;
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": "2.14.9",
4
+ "version": "2.14.11",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -28,18 +28,19 @@
28
28
  "fast-xml-parser": "4.4.1",
29
29
  "i18next": "25.3.0",
30
30
  "inquirer-autocomplete-prompt": "2.0.1",
31
+ "lodash": "4.17.21",
31
32
  "os-name": "4.0.1",
32
33
  "@sap-ux/axios-extension": "1.25.6",
33
- "@sap-ux/btp-utils": "1.1.6",
34
+ "@sap-ux/guided-answers-helper": "0.4.2",
34
35
  "@sap-ux/telemetry": "0.6.56",
36
+ "@sap-ux/fiori-generator-shared": "0.13.54",
37
+ "@sap-ux/btp-utils": "1.1.6",
35
38
  "@sap-ux/inquirer-common": "0.10.14",
36
39
  "@sap-ux/logger": "0.8.0",
37
- "@sap-ux/fiori-generator-shared": "0.13.54",
38
40
  "@sap-ux/nodejs-utils": "0.2.11",
39
- "@sap-ux/guided-answers-helper": "0.4.2",
41
+ "@sap-ux/project-access": "1.34.2",
40
42
  "@sap-ux/project-input-validator": "0.6.45",
41
- "@sap-ux/store": "1.5.0",
42
- "@sap-ux/project-access": "1.34.2"
43
+ "@sap-ux/store": "1.5.0"
43
44
  },
44
45
  "devDependencies": {
45
46
  "@sap-ux/vocabularies-types": "0.14.5",
@@ -48,9 +49,9 @@
48
49
  "@types/inquirer": "8.2.6",
49
50
  "@types/lodash": "4.14.202",
50
51
  "jest-extended": "6.0.0",
51
- "@sap-ux/fiori-generator-shared": "0.13.54",
52
- "@sap-ux/fiori-elements-writer": "2.8.40",
52
+ "@sap-ux/fiori-elements-writer": "2.8.42",
53
53
  "@sap-ux/fiori-freestyle-writer": "2.5.29",
54
+ "@sap-ux/fiori-generator-shared": "0.13.54",
54
55
  "@sap-ux/feature-toggle": "0.3.5",
55
56
  "@sap-ux/odata-service-writer": "0.29.8",
56
57
  "@sap-ux/cap-config-writer": "0.12.45"