@sap-ux/odata-service-inquirer 2.2.33 → 2.2.34

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.
@@ -46,6 +46,11 @@ type ValidateServiceResult = {
46
46
  hasAnnotations?: boolean;
47
47
  convertedMetadata?: ConvertedMetadata;
48
48
  };
49
+ /**
50
+ * If we are validating a v2 service and do not have a catalog connection, we may still attempt to get the annotations but need a catalog.
51
+ * This scenario occurs for full/partial url destinations.
52
+ *
53
+ */
49
54
  /**
50
55
  * Requests and sets the service details to the PromptState.odataService properties.
51
56
  * If an error occurs, the error message is returned for use in validators.
@@ -135,16 +135,40 @@ function sendDestinationServiceSuccessTelemetryEvent(destination) {
135
135
  (0, inquirer_common_1.sendTelemetryEvent)(exports.telemEventBASServiceSuccess, telemetryData);
136
136
  }
137
137
  /**
138
- * Gets the service metadata and annotations for the specified service path.
138
+ * Gets the service metadata and annotations for the specified service path. Validate that the service metadata is of the required OData version.
139
+ * If a catalog service is provided, it will be used to get the annotations for the specified service path.
140
+ * If the catalog service is not provided and the metadata is OData version 2, a catalog service will be created using the axios config to get the annotations.
141
+ * Note this is a best effort attempt to get the annotations and may fail if the catalog service cannot be created.
139
142
  *
140
143
  * @param servicePath service path
141
144
  * @param odataService the odata service used to get the metadata for the specified service path
142
145
  * @param catalog the catalog service used to get the annotations for the specified service path
143
- * @returns Promise<string | boolean>, string error message or true if successful
146
+ * @param axiosConfig the axios config which may be used to create the catalog service, if not provided (for v2 services),
147
+ * @param requiredOdataVersion the required OData version used to validate the service
148
+ * @returns the service metadata and annotations
144
149
  */
145
- async function getServiceMetadata(servicePath, odataService, catalog) {
150
+ async function getServiceMetadataAndValidate(servicePath, odataService, catalog, axiosConfig, requiredOdataVersion) {
146
151
  let annotations = [];
147
152
  try {
153
+ const metadata = await odataService.metadata();
154
+ const { validationMsg, version, convertedMetadata } = (0, validators_1.validateODataVersion)(metadata, requiredOdataVersion);
155
+ if (validationMsg) {
156
+ return { validationMsg };
157
+ }
158
+ // For non `odata_abap` (full/partial v2 urls) destinations we wont have a catalog defined, but the annotations may be available so we need to try or warn.
159
+ // Creation of the catalog service is a best effort and makes no assumptions about the existence of a real catalog service. The annotation call does not rely on it.
160
+ if (!catalog && version === odata_service_writer_1.OdataVersion.v2 && axiosConfig) {
161
+ try {
162
+ // Create an abap provider instance to get the annotations using the same request config
163
+ logger_helper_1.default.logger.debug('Creating a catalog service object for v2 service path to request annotations.');
164
+ const abapProvider = (0, axios_extension_1.createForAbap)(axiosConfig);
165
+ catalog = abapProvider.catalog(axios_extension_1.ODataVersion.v2);
166
+ logger_helper_1.default.attachAxiosLogger(catalog.interceptors);
167
+ }
168
+ catch (err) {
169
+ logger_helper_1.default.logger.warn((0, i18n_1.t)('error.v2CatalogServiceNoAnnotations', err));
170
+ }
171
+ }
148
172
  if (catalog) {
149
173
  try {
150
174
  annotations = await catalog.getAnnotations({ path: servicePath });
@@ -153,15 +177,18 @@ async function getServiceMetadata(servicePath, odataService, catalog) {
153
177
  logger_helper_1.default.logger.info((0, i18n_1.t)('prompts.validationMessages.noAnnotations'));
154
178
  }
155
179
  }
156
- const metadata = await odataService.metadata();
157
180
  return {
158
181
  annotations,
159
- metadata
182
+ metadata,
183
+ version,
184
+ convertedMetadata
160
185
  };
161
186
  }
162
187
  catch (error) {
163
188
  logger_helper_1.default.logger.error((0, i18n_1.t)('errors.serviceMetadataErrorLog', { servicePath, error }));
164
- return (0, i18n_1.t)('errors.serviceMetadataErrorUI', { servicePath });
189
+ return {
190
+ validationMsg: (0, i18n_1.t)('errors.serviceMetadataErrorUI', { servicePath })
191
+ };
165
192
  }
166
193
  }
167
194
  /**
@@ -184,6 +211,11 @@ async function getServiceType(servicePath, serviceType, catalog) {
184
211
  }
185
212
  return resolvedServiceType ?? serviceType;
186
213
  }
214
+ /**
215
+ * If we are validating a v2 service and do not have a catalog connection, we may still attempt to get the annotations but need a catalog.
216
+ * This scenario occurs for full/partial url destinations.
217
+ *
218
+ */
187
219
  /**
188
220
  * Requests and sets the service details to the PromptState.odataService properties.
189
221
  * If an error occurs, the error message is returned for use in validators.
@@ -204,11 +236,7 @@ async function validateService(service, connectionValidator, requiredOdataVersio
204
236
  if (!odataService) {
205
237
  odataService = connectionValidator.serviceProvider.service(service.servicePath);
206
238
  }
207
- const serviceResult = await getServiceMetadata(service.servicePath, odataService, serviceCatalog);
208
- if (typeof serviceResult === 'string') {
209
- return { validationResult: serviceResult };
210
- }
211
- const { validationMsg, version, convertedMetadata } = (0, validators_1.validateODataVersion)(serviceResult.metadata, requiredOdataVersion);
239
+ const { validationMsg, version, convertedMetadata, annotations, metadata } = await getServiceMetadataAndValidate(service.servicePath, odataService, serviceCatalog, connectionValidator.axiosConfig, requiredOdataVersion);
212
240
  if (validationMsg) {
213
241
  return { validationResult: validationMsg };
214
242
  }
@@ -218,8 +246,8 @@ async function validateService(service, connectionValidator, requiredOdataVersio
218
246
  if (url) {
219
247
  origin = new URL(url).origin;
220
248
  }
221
- utils_1.PromptState.odataService.annotations = serviceResult?.annotations;
222
- utils_1.PromptState.odataService.metadata = serviceResult?.metadata;
249
+ utils_1.PromptState.odataService.annotations = annotations;
250
+ utils_1.PromptState.odataService.metadata = metadata;
223
251
  utils_1.PromptState.odataService.odataVersion =
224
252
  version ?? (service.serviceODataVersion === axios_extension_1.ODataVersion.v2 ? odata_service_writer_1.OdataVersion.v2 : odata_service_writer_1.OdataVersion.v4);
225
253
  utils_1.PromptState.odataService.servicePath = service.servicePath;
@@ -224,7 +224,8 @@
224
224
  "unparseableOdataVersion": "Unable to parse the odata version from the metadata.",
225
225
  "unparseableXML": "Unparseable XML was specified: {{-error}}",
226
226
  "noRelevantEntities": "The template and service selected have no relevant entities that you can use.",
227
- "cfInstanceCredentialsNotReturned": "Could not retrieve credentials to access: {{serviceInstanceName}}"
227
+ "cfInstanceCredentialsNotReturned": "Could not retrieve credentials to access: {{serviceInstanceName}}",
228
+ "v2CatalogServiceNoAnnotations": "Error creating v2 catalog service object, annotations will not be available: {{-error}}"
228
229
  },
229
230
  "warnings": {
230
231
  "largeMetadataDocument": "The metadata for this OData service is significantly large. It may take some time before this operation completes."
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.2.33",
4
+ "version": "2.2.34",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -47,7 +47,7 @@
47
47
  "@types/lodash": "4.14.202",
48
48
  "jest-extended": "3.2.4",
49
49
  "@sap-ux/fiori-generator-shared": "0.10.2",
50
- "@sap-ux/fiori-elements-writer": "2.1.38",
50
+ "@sap-ux/fiori-elements-writer": "2.1.40",
51
51
  "@sap-ux/fiori-freestyle-writer": "2.2.8",
52
52
  "@sap-ux/feature-toggle": "0.2.3",
53
53
  "@sap-ux/odata-service-writer": "0.26.13",