@sap-ux/axios-extension 1.21.4 → 1.22.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.
@@ -6,6 +6,7 @@ import { ODataVersion } from '../base/odata-service';
6
6
  import { LayeredRepositoryService } from './lrep-service';
7
7
  import type { AbapCDSView, AtoSettings, BusinessObject } from './types';
8
8
  import { AdtService } from './adt-catalog/services';
9
+ import { ODataServiceGenerator } from './adt-catalog/generators/odata-service-generator';
9
10
  import { UiServiceGenerator } from './adt-catalog/generators/ui-service-generator';
10
11
  /**
11
12
  * Extension of the service provider for ABAP services.
@@ -104,6 +105,13 @@ export declare class AbapServiceProvider extends ServiceProvider {
104
105
  * @returns a UI Service generator
105
106
  */
106
107
  getUiServiceGenerator(referencedObject: BusinessObject | AbapCDSView): Promise<UiServiceGenerator>;
108
+ /**
109
+ * Gets an OData Service generator.
110
+ *
111
+ * @param packageName - Name of package to be used for generated artifacts in ABAP system
112
+ * @returns An OData Service generator
113
+ */
114
+ getODataServiceGenerator(packageName: string): Promise<ODataServiceGenerator>;
107
115
  /**
108
116
  * Get the service URL from the generator config.
109
117
  *
@@ -112,8 +120,6 @@ export declare class AbapServiceProvider extends ServiceProvider {
112
120
  */
113
121
  private getServiceUrlFromConfig;
114
122
  /**
115
- * Get the content type from the generator config.
116
- *
117
123
  * @param config - generator config
118
124
  * @returns the type of the content link from service generator config
119
125
  */
@@ -12,6 +12,7 @@ const types_1 = require("./types");
12
12
  // Can't use an `import type` here. We need the classname at runtime to create object instances:
13
13
  // eslint-disable-next-line @typescript-eslint/consistent-type-imports
14
14
  const services_1 = require("./adt-catalog/services");
15
+ const odata_service_generator_1 = require("./adt-catalog/generators/odata-service-generator");
15
16
  const ui_service_generator_1 = require("./adt-catalog/generators/ui-service-generator");
16
17
  /**
17
18
  * Extension of the service provider for ABAP services.
@@ -207,6 +208,23 @@ class AbapServiceProvider extends service_provider_1.ServiceProvider {
207
208
  gen.configure(config, referencedObject, this.getContentType(config));
208
209
  return gen;
209
210
  }
211
+ /**
212
+ * Gets an OData Service generator.
213
+ *
214
+ * @param packageName - Name of package to be used for generated artifacts in ABAP system
215
+ * @returns An OData Service generator
216
+ */
217
+ async getODataServiceGenerator(packageName) {
218
+ const generatorService = await this.getAdtService(services_1.RapGeneratorService);
219
+ if (!generatorService) {
220
+ throw new Error('RAP Generator are not support on this system');
221
+ }
222
+ const config = await generatorService.getRAPGeneratorConfig();
223
+ const generator = this.createService(this.getServiceUrlFromConfig(config), odata_service_generator_1.ODataServiceGenerator);
224
+ generator.setContentType(this.getContentType(config));
225
+ generator.configure(config, packageName || '$TMP');
226
+ return generator;
227
+ }
210
228
  /**
211
229
  * Get the service URL from the generator config.
212
230
  *
@@ -222,8 +240,6 @@ class AbapServiceProvider extends service_provider_1.ServiceProvider {
222
240
  return config.link[0].href.substring(0, endIndex);
223
241
  }
224
242
  /**
225
- * Get the content type from the generator config.
226
- *
227
243
  * @param config - generator config
228
244
  * @returns the type of the content link from service generator config
229
245
  */
@@ -1,2 +1,3 @@
1
1
  export { UiServiceGenerator } from './ui-service-generator';
2
+ export { ODataServiceGenerator } from './odata-service-generator';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UiServiceGenerator = void 0;
3
+ exports.ODataServiceGenerator = exports.UiServiceGenerator = void 0;
4
4
  var ui_service_generator_1 = require("./ui-service-generator");
5
5
  Object.defineProperty(exports, "UiServiceGenerator", { enumerable: true, get: function () { return ui_service_generator_1.UiServiceGenerator; } });
6
+ var odata_service_generator_1 = require("./odata-service-generator");
7
+ Object.defineProperty(exports, "ODataServiceGenerator", { enumerable: true, get: function () { return odata_service_generator_1.ODataServiceGenerator; } });
6
8
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,65 @@
1
+ import type { GeneratorEntry } from './types';
2
+ import type { ODataServiceTechnicalDetails, ValidationMessage } from '../../types';
3
+ import { AdtService } from '../services';
4
+ /**
5
+ * Extension of the Generator service to generate OData services
6
+ */
7
+ export declare class ODataServiceGenerator extends AdtService {
8
+ /**
9
+ * package to be used for generated objects
10
+ */
11
+ protected packageName: string;
12
+ protected contentType: string;
13
+ /**
14
+ * Configure the UI service generator.
15
+ *
16
+ * @param _config - The generator configuration.
17
+ * @param packageName - package to be used for generated objects
18
+ */
19
+ configure(_config: GeneratorEntry, packageName: string): void;
20
+ /**
21
+ * Set the content type to be used for post requests of genertor.
22
+ *
23
+ * @param contentType - content type to be used for generated objects
24
+ */
25
+ setContentType(contentType: string): void;
26
+ /**
27
+ * Validates input for OData Service generation.
28
+ *
29
+ * @param input - JSON string
30
+ * @returns messages
31
+ */
32
+ validate(input: string): Promise<ValidationMessage[]>;
33
+ /**
34
+ * Gets technical details of (to be generated) OData service.
35
+ * - this is a workaround for the missing service definition name in the generator response
36
+ * - actual name might be different e.g. because of name collisions at the time when the actual generation is called.
37
+ *
38
+ * @param input - JSON string
39
+ * @returns technical name of service definition
40
+ */
41
+ getTechnicalDetails(input: string): Promise<ODataServiceTechnicalDetails>;
42
+ /**
43
+ * Generates OData Service.
44
+ *
45
+ * @param input - JSON string
46
+ * @returns HTTP status code as number
47
+ * @throws Error if the generation fails
48
+ */
49
+ generate(input: string): Promise<number>;
50
+ /**
51
+ * Parse an xml document for validation messages.
52
+ *
53
+ * @param xml response for "validation" request
54
+ * @returns messages
55
+ */
56
+ private parseValidateResponse;
57
+ /**
58
+ * Parse an XML document to find the technical name of the service definition.
59
+ *
60
+ * @param xml response for "preview" request
61
+ * @returns technical details of service definition
62
+ */
63
+ private parsePreviewResponse;
64
+ }
65
+ //# sourceMappingURL=odata-service-generator.d.ts.map
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ODataServiceGenerator = void 0;
4
+ const services_1 = require("../services");
5
+ /**
6
+ * Extension of the Generator service to generate OData services
7
+ */
8
+ class ODataServiceGenerator extends services_1.AdtService {
9
+ /**
10
+ * package to be used for generated objects
11
+ */
12
+ packageName;
13
+ contentType;
14
+ /**
15
+ * Configure the UI service generator.
16
+ *
17
+ * @param _config - The generator configuration.
18
+ * @param packageName - package to be used for generated objects
19
+ */
20
+ configure(_config, packageName) {
21
+ this.packageName = packageName;
22
+ }
23
+ /**
24
+ * Set the content type to be used for post requests of genertor.
25
+ *
26
+ * @param contentType - content type to be used for generated objects
27
+ */
28
+ setContentType(contentType) {
29
+ this.contentType = contentType;
30
+ }
31
+ /**
32
+ * Validates input for OData Service generation.
33
+ *
34
+ * @param input - JSON string
35
+ * @returns messages
36
+ */
37
+ async validate(input) {
38
+ const response = await this.post(`/validation`, input, {
39
+ headers: {
40
+ 'Content-Type': this.contentType,
41
+ Accept: 'application/vnd.sap.adt.validationMessages.v1+xml, application/vnd.sap.as+xml;charset=UTF-8;dataname=com.sap.adt.StatusMessage'
42
+ },
43
+ params: {
44
+ package: this.packageName
45
+ }
46
+ });
47
+ return this.parseValidateResponse(response.data);
48
+ }
49
+ /**
50
+ * Gets technical details of (to be generated) OData service.
51
+ * - this is a workaround for the missing service definition name in the generator response
52
+ * - actual name might be different e.g. because of name collisions at the time when the actual generation is called.
53
+ *
54
+ * @param input - JSON string
55
+ * @returns technical name of service definition
56
+ */
57
+ async getTechnicalDetails(input) {
58
+ const response = await this.post(`/preview`, input, {
59
+ headers: {
60
+ 'Content-Type': this.contentType,
61
+ Accept: 'application/vnd.sap.adt.repository.objects.massoperation.v1+xml'
62
+ },
63
+ params: {
64
+ package: this.packageName
65
+ }
66
+ });
67
+ return this.parsePreviewResponse(response.data);
68
+ }
69
+ /**
70
+ * Generates OData Service.
71
+ *
72
+ * @param input - JSON string
73
+ * @returns HTTP status code as number
74
+ * @throws Error if the generation fails
75
+ */
76
+ async generate(input) {
77
+ const response = await this.post(``, input, {
78
+ headers: {
79
+ 'Content-Type': this.contentType,
80
+ 'Accept': 'application/vnd.sap.adt.repository.generator.v1+json'
81
+ },
82
+ params: {
83
+ package: this.packageName
84
+ }
85
+ });
86
+ // return http status code as number
87
+ return response.status;
88
+ }
89
+ /**
90
+ * Parse an xml document for validation messages.
91
+ *
92
+ * @param xml response for "validation" request
93
+ * @returns messages
94
+ */
95
+ parseValidateResponse(xml) {
96
+ const parsed = this.parseResponse(xml);
97
+ let validationMessages = parsed.validationMessages;
98
+ if (!Array.isArray(validationMessages)) {
99
+ validationMessages = [validationMessages];
100
+ }
101
+ return validationMessages.map((entry) => entry.validationMessage || {}) || [];
102
+ }
103
+ /**
104
+ * Parse an XML document to find the technical name of the service definition.
105
+ *
106
+ * @param xml response for "preview" request
107
+ * @returns technical details of service definition
108
+ */
109
+ parsePreviewResponse(xml) {
110
+ const parsed = this.parseResponse(xml);
111
+ const serviceLayerGroup = (parsed.group.group || []).find((entry) => entry.name === 'Business Service Layer');
112
+ if (!serviceLayerGroup) {
113
+ return;
114
+ }
115
+ const objects = !Array.isArray(serviceLayerGroup.object)
116
+ ? [serviceLayerGroup.object]
117
+ : serviceLayerGroup.object;
118
+ const serviceObject = objects.find((entry) => entry.objectReference?.type === 'SRVD/SRV');
119
+ const serviceBindingObject = objects.find((entry) => entry.objectReference?.type === 'SRVB/SVB');
120
+ if (!serviceObject || !serviceBindingObject) {
121
+ return;
122
+ }
123
+ return {
124
+ serviceName: serviceBindingObject.objectReference?.name || '',
125
+ serviceDefinitionName: serviceObject.objectReference?.name || '',
126
+ serviceVersion: '0001'
127
+ };
128
+ }
129
+ }
130
+ exports.ODataServiceGenerator = ODataServiceGenerator;
131
+ //# sourceMappingURL=odata-service-generator.js.map
@@ -5,7 +5,9 @@ export { TransportRequestService, NewUi5ObjectRequestParams } from './transportr
5
5
  export { ListPackageService } from './list-package-service';
6
6
  export { FileStoreService } from './filestore-service';
7
7
  export { GeneratorService } from './generator-service';
8
+ export { RapGeneratorService } from './rap-generator-service';
8
9
  export { BusinessObjectsService } from './businessobjects-service';
9
10
  export { UI5RtVersionService } from './ui5-rt-version-service';
10
11
  export { AbapCDSViewService } from './abapcdsview-service';
12
+ export { PublishService } from './publish-service';
11
13
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AbapCDSViewService = exports.UI5RtVersionService = exports.BusinessObjectsService = exports.GeneratorService = exports.FileStoreService = exports.ListPackageService = exports.TransportRequestService = exports.TransportChecksService = exports.AtoService = exports.AdtService = void 0;
3
+ exports.PublishService = exports.AbapCDSViewService = exports.UI5RtVersionService = exports.BusinessObjectsService = exports.RapGeneratorService = exports.GeneratorService = exports.FileStoreService = exports.ListPackageService = exports.TransportRequestService = exports.TransportChecksService = exports.AtoService = exports.AdtService = void 0;
4
4
  var adt_service_1 = require("./adt-service");
5
5
  Object.defineProperty(exports, "AdtService", { enumerable: true, get: function () { return adt_service_1.AdtService; } });
6
6
  var ato_service_1 = require("./ato-service");
@@ -15,10 +15,14 @@ var filestore_service_1 = require("./filestore-service");
15
15
  Object.defineProperty(exports, "FileStoreService", { enumerable: true, get: function () { return filestore_service_1.FileStoreService; } });
16
16
  var generator_service_1 = require("./generator-service");
17
17
  Object.defineProperty(exports, "GeneratorService", { enumerable: true, get: function () { return generator_service_1.GeneratorService; } });
18
+ var rap_generator_service_1 = require("./rap-generator-service");
19
+ Object.defineProperty(exports, "RapGeneratorService", { enumerable: true, get: function () { return rap_generator_service_1.RapGeneratorService; } });
18
20
  var businessobjects_service_1 = require("./businessobjects-service");
19
21
  Object.defineProperty(exports, "BusinessObjectsService", { enumerable: true, get: function () { return businessobjects_service_1.BusinessObjectsService; } });
20
22
  var ui5_rt_version_service_1 = require("./ui5-rt-version-service");
21
23
  Object.defineProperty(exports, "UI5RtVersionService", { enumerable: true, get: function () { return ui5_rt_version_service_1.UI5RtVersionService; } });
22
24
  var abapcdsview_service_1 = require("./abapcdsview-service");
23
25
  Object.defineProperty(exports, "AbapCDSViewService", { enumerable: true, get: function () { return abapcdsview_service_1.AbapCDSViewService; } });
26
+ var publish_service_1 = require("./publish-service");
27
+ Object.defineProperty(exports, "PublishService", { enumerable: true, get: function () { return publish_service_1.PublishService; } });
24
28
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,25 @@
1
+ import { AdtService } from './adt-service';
2
+ import type { AdtCategory, ODataServiceTechnicalDetails } from '../../types';
3
+ /**
4
+ *
5
+ */
6
+ export declare class PublishService extends AdtService {
7
+ /**
8
+ * @see AdtService.getAdtCatagory()
9
+ */
10
+ private static readonly adtCategory;
11
+ /**
12
+ * Get ADT scheme ID.
13
+ *
14
+ * @returns AdtCategory
15
+ */
16
+ static getAdtCatagory(): AdtCategory;
17
+ /**
18
+ * Get OData V4 service URI for the given business object.
19
+ *
20
+ * @param technicalDetails - technical name of OData service
21
+ * @returns service URI.
22
+ */
23
+ getODataV4ServiceUri(technicalDetails: ODataServiceTechnicalDetails): Promise<string>;
24
+ }
25
+ //# sourceMappingURL=publish-service.d.ts.map
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PublishService = void 0;
4
+ const adt_service_1 = require("./adt-service");
5
+ /**
6
+ *
7
+ */
8
+ class PublishService extends adt_service_1.AdtService {
9
+ /**
10
+ * @see AdtService.getAdtCatagory()
11
+ */
12
+ static adtCategory = {
13
+ scheme: 'http://www.sap.com/categories/servicebindings/bindingtypes',
14
+ term: 'ODataV4'
15
+ };
16
+ /**
17
+ * Get ADT scheme ID.
18
+ *
19
+ * @returns AdtCategory
20
+ */
21
+ static getAdtCatagory() {
22
+ return PublishService.adtCategory;
23
+ }
24
+ /**
25
+ * Get OData V4 service URI for the given business object.
26
+ *
27
+ * @param technicalDetails - technical name of OData service
28
+ * @returns service URI.
29
+ */
30
+ async getODataV4ServiceUri(technicalDetails) {
31
+ const { serviceDefinitionName, serviceName, serviceVersion } = technicalDetails;
32
+ const response = await this.get(`/${serviceName}`, {
33
+ headers: {
34
+ Accept: 'application/vnd.sap.adt.businessservices.odatav4.v2+xml'
35
+ },
36
+ params: {
37
+ servicename: serviceName,
38
+ serviceversion: serviceVersion,
39
+ srvdname: serviceDefinitionName
40
+ }
41
+ });
42
+ const data = this.parseResponse(response.data);
43
+ return String(data.serviceGroup.services.serviceUrl);
44
+ }
45
+ }
46
+ exports.PublishService = PublishService;
47
+ //# sourceMappingURL=publish-service.js.map
@@ -0,0 +1,27 @@
1
+ import { AdtService } from './adt-service';
2
+ import type { AdtCategory } from '../../types';
3
+ import type { GeneratorEntry } from '../generators/types';
4
+ /**
5
+ * RapGeneratorService implements ADT requests for generating an OData Service
6
+ * from ABAP backend system.
7
+ */
8
+ export declare class RapGeneratorService extends AdtService {
9
+ /**
10
+ * @see AdtService.getAdtCategory()
11
+ */
12
+ private static readonly adtCategory;
13
+ /**
14
+ * Get ADT scheme ID.
15
+ *
16
+ * @returns AdtCategory
17
+ */
18
+ static getAdtCatagory(): AdtCategory;
19
+ private readonly id;
20
+ /**
21
+ * Get the RAP Generator (published-x-ui-service).
22
+ *
23
+ * @returns Promise<GeneratorEntry>
24
+ */
25
+ getRAPGeneratorConfig(): Promise<GeneratorEntry>;
26
+ }
27
+ //# sourceMappingURL=rap-generator-service.d.ts.map
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RapGeneratorService = void 0;
4
+ const adt_service_1 = require("./adt-service");
5
+ /**
6
+ * RapGeneratorService implements ADT requests for generating an OData Service
7
+ * from ABAP backend system.
8
+ */
9
+ class RapGeneratorService extends adt_service_1.AdtService {
10
+ /**
11
+ * @see AdtService.getAdtCategory()
12
+ */
13
+ static adtCategory = {
14
+ scheme: 'http://www.sap.com/adt/categories/respository',
15
+ term: 'generators'
16
+ };
17
+ /**
18
+ * Get ADT scheme ID.
19
+ *
20
+ * @returns AdtCategory
21
+ */
22
+ static getAdtCatagory() {
23
+ return RapGeneratorService.adtCategory;
24
+ }
25
+ id;
26
+ /**
27
+ * Get the RAP Generator (published-x-ui-service).
28
+ *
29
+ * @returns Promise<GeneratorEntry>
30
+ */
31
+ async getRAPGeneratorConfig() {
32
+ const response = await this.get('', {
33
+ headers: {
34
+ Accept: 'application/atom+xml;type=feed'
35
+ },
36
+ params: {
37
+ type: 'webapi',
38
+ fetchAllGenerators: true
39
+ }
40
+ });
41
+ let generators = (this.parseResponse(response.data).feed?.entry ?? []);
42
+ if (generators && !Array.isArray(generators)) {
43
+ generators = [generators];
44
+ }
45
+ const data = generators.find((generator) => generator.id === 'published-x-ui-service');
46
+ if (data) {
47
+ return data;
48
+ }
49
+ else {
50
+ throw new Error('OData Service Generator not found');
51
+ }
52
+ }
53
+ }
54
+ exports.RapGeneratorService = RapGeneratorService;
55
+ //# sourceMappingURL=rap-generator-service.js.map
@@ -129,6 +129,15 @@ export type PublishResponse = {
129
129
  SHORT_TEXT: string;
130
130
  LONG_TEXT: string;
131
131
  };
132
+ export type ValidationMessage = {
133
+ severity?: string;
134
+ text?: string;
135
+ };
136
+ export type ODataServiceTechnicalDetails = {
137
+ serviceName: string;
138
+ serviceVersion: string;
139
+ serviceDefinitionName: string;
140
+ };
132
141
  export type ValidationResponse = {
133
142
  severity: string;
134
143
  short_text: string;
package/dist/factory.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { AxiosRequestConfig } from 'axios';
2
- import type { Destination } from '@sap-ux/btp-utils';
2
+ import { type Destination } from '@sap-ux/btp-utils';
3
3
  import type { ServiceInfo, RefreshTokenChanged } from './auth';
4
4
  import type { ProviderConfiguration } from './base/service-provider';
5
5
  import { ServiceProvider } from './base/service-provider';
package/dist/factory.js CHANGED
@@ -20,7 +20,6 @@ const patchTls_1 = require("./base/patchTls");
20
20
  const proxy_from_env_1 = require("proxy-from-env");
21
21
  const https_proxy_agent_1 = require("https-proxy-agent");
22
22
  const http_proxy_agent_1 = require("http-proxy-agent");
23
- const feature_toggle_1 = require("@sap-ux/feature-toggle");
24
23
  /**
25
24
  * PatchedHttpsProxyAgent is a custom implementation of HttpsProxyAgent that allows to pass additional options, currently not supported by the original implementation when calling tls.connect
26
25
  */
@@ -62,8 +61,7 @@ function createInstance(ProviderType, config) {
62
61
  rejectUnauthorized: !providerConfig.ignoreCertErrors
63
62
  };
64
63
  const localProxy = (0, proxy_from_env_1.getProxyForUrl)(config.baseURL);
65
- const isPatchProxyEnabled = (0, feature_toggle_1.isFeatureEnabled)('sap.ux.enablePatchProxy');
66
- if (isPatchProxyEnabled && localProxy) {
64
+ if (localProxy && !(0, btp_utils_1.isAppStudio)()) {
67
65
  // axios doesn't handle proxies correctly, instead use a custom agent with axios proxy disabled
68
66
  providerConfig.httpsAgent = new PatchedHttpsProxyAgent(localProxy, agentOptions);
69
67
  providerConfig.httpAgent = new http_proxy_agent_1.HttpProxyAgent(localProxy);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap-ux/axios-extension",
3
- "version": "1.21.4",
3
+ "version": "1.22.1",
4
4
  "description": "Extension of the Axios module adding convenience methods to interact with SAP systems especially with OData services.",
5
5
  "repository": {
6
6
  "type": "git",